intel: properly constify isl_format_layouts

Putting a const char * in the struct means it's a pointer that has to be
resolved at rtld time, which means it can be in .data.rel.ro but not
.rodata like you'd hope. Fix this with the usual string table trick.

Cuts about 20k (-80k read-write +60k read-only) and ~280 relocations
from the gallium driver.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11168>
This commit is contained in:
Adam Jackson 2021-06-03 11:36:00 -04:00 committed by Marge Bot
parent 8fb1300333
commit ed6e586562
3 changed files with 19 additions and 5 deletions

View File

@ -61,12 +61,23 @@ TEMPLATE = template.Template(future_imports=['division'],
#include "isl/isl.h"
const uint16_t isl_format_name_offsets[] = { <% offset = 0 %>
% for format in formats:
${offset}, <% offset += 11 + len(format.name) + 1 %>
% endfor
};
const char isl_format_names[] = {
% for format in formats:
"ISL_FORMAT_${format.name}\\0"
% endfor
};
const struct isl_format_layout
isl_format_layouts[] = {
% for format in formats:
[ISL_FORMAT_${format.name}] = {
.format = ISL_FORMAT_${format.name},
.name = "ISL_FORMAT_${format.name}",
.bpb = ${format.bpb},
.bw = ${format.bw},
.bh = ${format.bh},
@ -94,7 +105,7 @@ isl_format_is_valid(enum isl_format format)
{
if (format >= sizeof(isl_format_layouts) / sizeof(isl_format_layouts[0]))
return false;
return isl_format_layouts[format].name;
return true;
}
enum isl_format

View File

@ -1116,7 +1116,6 @@ struct isl_channel_layout {
*/
struct isl_format_layout {
enum isl_format format;
const char *name;
uint16_t bpb; /**< Bits per block */
uint8_t bw; /**< Block width, in pixels */
@ -1522,6 +1521,8 @@ struct isl_depth_stencil_hiz_emit_info {
};
extern const struct isl_format_layout isl_format_layouts[];
extern const char isl_format_names[];
extern const uint16_t isl_format_name_offsets[];
void
isl_device_init(struct isl_device *dev,
@ -1544,7 +1545,9 @@ bool isl_format_is_valid(enum isl_format);
static inline const char * ATTRIBUTE_CONST
isl_format_get_name(enum isl_format fmt)
{
return isl_format_get_layout(fmt)->name;
assert(fmt != ISL_FORMAT_UNSUPPORTED);
assert(fmt < ISL_NUM_FORMATS);
return isl_format_names + isl_format_name_offsets[fmt];
}
enum isl_format isl_format_for_pipe_format(enum pipe_format pf);

View File

@ -1896,7 +1896,7 @@ can_texture_with_ccs(struct brw_context *brw,
if (!format_ccs_e_compat_with_miptree(&brw->screen->devinfo,
mt, view_format)) {
perf_debug("Incompatible sampling format (%s) for rbc (%s)\n",
isl_format_get_layout(view_format)->name,
isl_format_get_name(view_format),
_mesa_get_format_name(mt->format));
return false;
}