From da184ddbe4eb1dfb83ff0b097b6b5c8f97ff111f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Fri, 24 Jan 2025 14:51:10 +0100 Subject: [PATCH] spirv: Always mark FS layer and viewport index inpus as flat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The spec requires these to be decorated as FLAT, but some apps forgot to set that, eg. old DXVK before d12a8e09a855 Let's unconditionally decorate these FS inputs as FLAT in spirv_to_nir, we can do that for free and prevent those apps from crashing RADV. Cc: mesa-stable Signed-off-by: Timur Kristóf Reviewed-by: Alyssa Rosenzweig Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/spirv/vtn_variables.c | 31 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index 6b00759bcc0..c109aac1da3 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -885,7 +885,8 @@ set_mode_system_value(struct vtn_builder *b, nir_variable_mode *mode) static void vtn_get_builtin_location(struct vtn_builder *b, SpvBuiltIn builtin, int *location, - nir_variable_mode *mode) + nir_variable_mode *mode, + enum glsl_interp_mode *interp_mode) { switch (builtin) { case SpvBuiltInPosition: @@ -940,31 +941,35 @@ vtn_get_builtin_location(struct vtn_builder *b, case SpvBuiltInLayer: case SpvBuiltInLayerPerViewNV: *location = VARYING_SLOT_LAYER; - if (b->shader->info.stage == MESA_SHADER_FRAGMENT) + if (b->shader->info.stage == MESA_SHADER_FRAGMENT) { *mode = nir_var_shader_in; - else if (b->shader->info.stage == MESA_SHADER_GEOMETRY) + *interp_mode = INTERP_MODE_FLAT; + } else if (b->shader->info.stage == MESA_SHADER_GEOMETRY) { *mode = nir_var_shader_out; - else if (b->supported_capabilities.ShaderViewportIndexLayerEXT && + } else if (b->supported_capabilities.ShaderViewportIndexLayerEXT && (b->shader->info.stage == MESA_SHADER_VERTEX || b->shader->info.stage == MESA_SHADER_TESS_EVAL || - b->shader->info.stage == MESA_SHADER_MESH)) + b->shader->info.stage == MESA_SHADER_MESH)) { *mode = nir_var_shader_out; - else + } else { vtn_fail("invalid stage for SpvBuiltInLayer"); + } break; case SpvBuiltInViewportIndex: *location = VARYING_SLOT_VIEWPORT; - if (b->shader->info.stage == MESA_SHADER_GEOMETRY) + if (b->shader->info.stage == MESA_SHADER_GEOMETRY) { *mode = nir_var_shader_out; - else if (b->supported_capabilities.ShaderViewportIndexLayerEXT && + } else if (b->supported_capabilities.ShaderViewportIndexLayerEXT && (b->shader->info.stage == MESA_SHADER_VERTEX || b->shader->info.stage == MESA_SHADER_TESS_EVAL || - b->shader->info.stage == MESA_SHADER_MESH)) + b->shader->info.stage == MESA_SHADER_MESH)) { *mode = nir_var_shader_out; - else if (b->shader->info.stage == MESA_SHADER_FRAGMENT) + } else if (b->shader->info.stage == MESA_SHADER_FRAGMENT) { *mode = nir_var_shader_in; - else + *interp_mode = INTERP_MODE_FLAT; + } else { vtn_fail("invalid stage for SpvBuiltInViewportIndex"); + } break; case SpvBuiltInViewportMaskNV: case SpvBuiltInViewportMaskPerViewNV: @@ -1402,8 +1407,10 @@ apply_var_decoration(struct vtn_builder *b, SpvBuiltIn builtin = dec->operands[0]; nir_variable_mode mode = var_data->mode; - vtn_get_builtin_location(b, builtin, &var_data->location, &mode); + enum glsl_interp_mode interpolation = var_data->interpolation; + vtn_get_builtin_location(b, builtin, &var_data->location, &mode, &interpolation); var_data->mode = mode; + var_data->interpolation = interpolation; switch (builtin) { case SpvBuiltInTessLevelOuter: