From 9480ad2b1c69a7ddcac3a328580b017a07d51b18 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Tue, 27 Jul 2021 14:36:30 +0200 Subject: [PATCH] amd: update gfx10_format_table.py for gfx11 Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/amd/common/gfx10_format_table.h | 11 +++++++ src/amd/common/gfx10_format_table.py | 44 +++++++++++++++++-------- src/amd/common/meson.build | 2 +- src/gallium/drivers/radeonsi/si_state.c | 10 +++--- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/amd/common/gfx10_format_table.h b/src/amd/common/gfx10_format_table.h index 9eff1221192..9e88810d26a 100644 --- a/src/amd/common/gfx10_format_table.h +++ b/src/amd/common/gfx10_format_table.h @@ -28,6 +28,7 @@ #define GFX10_FORMAT_TABLE_H #include "pipe/p_format.h" +#include "ac_gpu_info.h" #include @@ -41,5 +42,15 @@ struct gfx10_format { }; extern const struct gfx10_format gfx10_format_table[PIPE_FORMAT_COUNT]; +extern const struct gfx10_format gfx11_format_table[PIPE_FORMAT_COUNT]; + +static inline +const struct gfx10_format* ac_get_gfx10_format_table(struct radeon_info *info) +{ + if (info->chip_class >= GFX11) + return gfx11_format_table; + else + return gfx10_format_table; +} #endif /* GFX10_FORMAT_TABLE_H */ diff --git a/src/amd/common/gfx10_format_table.py b/src/amd/common/gfx10_format_table.py index 9737c23280e..ea261292606 100644 --- a/src/amd/common/gfx10_format_table.py +++ b/src/amd/common/gfx10_format_table.py @@ -103,16 +103,19 @@ HARDCODED = { # Main script header_template = mako.template.Template("""\ +% if header: // DO NOT EDIT -- AUTOMATICALLY GENERATED #include "gfx10_format_table.h" #include "amdgfxregs.h" +% endif + #define FMT(_img_format, ...) \ - { .img_format = V_008F0C_GFX10_FORMAT_##_img_format, \ + { .img_format = V_008F0C_${gfx.upper()}_FORMAT_##_img_format, \ ##__VA_ARGS__ } -const struct gfx10_format gfx10_format_table[PIPE_FORMAT_COUNT] = { +const struct gfx10_format ${gfx}_format_table[PIPE_FORMAT_COUNT] = { % for pipe_format, args in formats: % if args is not None: [${pipe_format}] = FMT(${args}), @@ -120,6 +123,8 @@ const struct gfx10_format gfx10_format_table[PIPE_FORMAT_COUNT] = { /* ${pipe_format} is not supported */ % endif % endfor + +#undef FMT }; """) @@ -250,17 +255,7 @@ class Gfx10FormatMapping(object): return None - -if __name__ == '__main__': - pipe_formats = parse(sys.argv[1]) - - with open(sys.argv[2], 'r') as filp: - db = RegisterDatabase.from_json(json.load(filp)) - - gfx10_formats = [Gfx10Format(entry) for entry in db.enum('GFX10_FORMAT').entries] - - mapping = Gfx10FormatMapping(pipe_formats, gfx10_formats) - +def pipe_formats_to_formats(pipe_formats, mapping): formats = [] for fmt in pipe_formats: if fmt.name in HARDCODED: @@ -276,4 +271,25 @@ if __name__ == '__main__': args = None formats.append((fmt.name, args)) - print(header_template.render(formats=formats)) + return formats + +if __name__ == '__main__': + pipe_formats = parse(sys.argv[1]) + + # gfx10 + with open(sys.argv[2], 'r') as filp: + db = RegisterDatabase.from_json(json.load(filp)) + + gfx10_formats = [Gfx10Format(entry) for entry in db.enum('GFX10_FORMAT').entries] + mapping = Gfx10FormatMapping(pipe_formats, gfx10_formats) + formats = pipe_formats_to_formats(pipe_formats, mapping) + print(header_template.render(header=True, gfx='gfx10', formats=formats)) + + # gfx11 + with open(sys.argv[3], 'r') as filp: + db = RegisterDatabase.from_json(json.load(filp)) + + gfx11_formats = [Gfx10Format(entry) for entry in db.enum('GFX11_FORMAT').entries] + mapping = Gfx10FormatMapping(pipe_formats, gfx11_formats) + formats = pipe_formats_to_formats(pipe_formats, mapping) + print(header_template.render(header=False, gfx='gfx11', formats=formats)) diff --git a/src/amd/common/meson.build b/src/amd/common/meson.build index 1339748fce8..78c7b0a88db 100644 --- a/src/amd/common/meson.build +++ b/src/amd/common/meson.build @@ -56,7 +56,7 @@ gfx10_format_table_c = custom_target( 'gfx10_format_table.c', input : files( 'gfx10_format_table.py', - '../../util/format/u_format.csv', '../registers/gfx10-rsrc.json' + '../../util/format/u_format.csv', '../registers/gfx10-rsrc.json', '../registers/gfx11-rsrc.json' ), output : 'gfx10_format_table.c', command : [prog_python, '@INPUT@'], diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index f9e0a86fe10..6e60168560c 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -2125,7 +2125,7 @@ static bool si_is_sampler_format_supported(struct pipe_screen *screen, enum pipe return false; if (sscreen->info.chip_class >= GFX10) { - const struct gfx10_format *fmt = &gfx10_format_table[format]; + const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&sscreen->info)[format]; if (!fmt->img_format || fmt->buffers_only) return false; return true; @@ -2281,7 +2281,7 @@ static unsigned si_is_vertex_format_supported(struct pipe_screen *screen, enum p } if (sscreen->info.chip_class >= GFX10) { - const struct gfx10_format *fmt = &gfx10_format_table[format]; + const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&sscreen->info)[format]; if (!fmt->img_format || fmt->img_format >= 128) return 0; return usage; @@ -3806,7 +3806,7 @@ void si_make_buffer_descriptor(struct si_screen *screen, struct si_resource *buf S_008F0C_DST_SEL_W(si_map_swizzle(desc->swizzle[3])); if (screen->info.chip_class >= GFX10) { - const struct gfx10_format *fmt = &gfx10_format_table[format]; + const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&screen->info)[format]; /* OOB_SELECT chooses the out-of-bounds check: * - 0: (index >= NUM_RECORDS) || (offset >= STRIDE) @@ -3876,7 +3876,7 @@ static void gfx10_make_texture_descriptor( uint64_t va; desc = util_format_description(pipe_format); - img_format = gfx10_format_table[pipe_format].img_format; + img_format = ac_get_gfx10_format_table(&screen->info)[pipe_format].img_format; if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) { const unsigned char swizzle_xxxx[4] = {0, 0, 0, 0}; @@ -4898,7 +4898,7 @@ static void *si_create_vertex_elements(struct pipe_context *ctx, unsigned count, S_008F0C_DST_SEL_W(si_map_swizzle(desc->swizzle[3])); if (sscreen->info.chip_class >= GFX10) { - const struct gfx10_format *fmt = &gfx10_format_table[elements[i].src_format]; + const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&sscreen->info)[elements[i].src_format]; assert(fmt->img_format != 0 && fmt->img_format < 128); v->rsrc_word3[i] |= S_008F0C_FORMAT(fmt->img_format) | S_008F0C_RESOURCE_LEVEL(1); } else {