From 911a8261419f48dcd756f78832fa5a5f4c5b8d93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timur=20Krist=C3=B3f?= Date: Wed, 6 Nov 2019 13:29:26 +0100 Subject: [PATCH] ac: Handle invalid GFX10 format correctly in ac_get_tbuffer_format. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It happens that some games try to access a vertex buffer without a valid format. This case was incorrectly handled by ac_get_tbuffer_format which made ACO emit an invalid instruction. Signed-off-by: Timur Kristóf Cc: 19.3 Reviewed-by: Samuel Pitoiset --- src/amd/common/ac_shader_util.c | 5 +++++ src/amd/compiler/aco_assembler.cpp | 1 + 2 files changed, 6 insertions(+) diff --git a/src/amd/common/ac_shader_util.c b/src/amd/common/ac_shader_util.c index 78b5006e0a1..eb6b88bd570 100644 --- a/src/amd/common/ac_shader_util.c +++ b/src/amd/common/ac_shader_util.c @@ -114,6 +114,11 @@ unsigned ac_get_tbuffer_format(enum chip_class chip_class, unsigned dfmt, unsigned nfmt) { + // Some games try to access vertex buffers without a valid format. + // This is a game bug, but we should still handle it gracefully. + if (dfmt == V_008F0C_IMG_FORMAT_INVALID) + return V_008F0C_IMG_FORMAT_INVALID; + if (chip_class >= GFX10) { unsigned format; switch (dfmt) { diff --git a/src/amd/compiler/aco_assembler.cpp b/src/amd/compiler/aco_assembler.cpp index 08debb25ad6..ee575e882c9 100644 --- a/src/amd/compiler/aco_assembler.cpp +++ b/src/amd/compiler/aco_assembler.cpp @@ -317,6 +317,7 @@ void emit_instruction(asm_context& ctx, std::vector& out, Instruction* uint32_t img_format = ac_get_tbuffer_format(ctx.chip_class, mtbuf->dfmt, mtbuf->nfmt); uint32_t encoding = (0b111010 << 26); + assert(img_format <= 0x7F); assert(!mtbuf->dlc || ctx.chip_class >= GFX10); encoding |= (mtbuf->dlc ? 1 : 0) << 15; /* DLC bit replaces one bit of the OPCODE on GFX10 */ encoding |= (mtbuf->glc ? 1 : 0) << 14; -- 2.30.2