From 7a464f4296a73df89755323e03646ccbf835d66c Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 11 Dec 2020 13:35:45 +0100 Subject: [PATCH] radv: track if VRS is enabled to apply a workaround on GFX10.3 On some chips, gl_FragCoord.z has to be adjusted. Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/amd/vulkan/radv_device.c | 14 ++++++++++++++ src/amd/vulkan/radv_private.h | 5 +++++ src/amd/vulkan/radv_shader.c | 1 + src/amd/vulkan/radv_shader.h | 1 + 4 files changed, 21 insertions(+) diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index d698e858ce7..b6e6f530d8e 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -2657,6 +2657,7 @@ VkResult radv_CreateDevice( bool robust_buffer_access = false; bool overallocation_disallowed = false; bool custom_border_colors = false; + bool vrs_enabled = false; /* Check enabled features */ if (pCreateInfo->pEnabledFeatures) { @@ -2693,6 +2694,13 @@ VkResult radv_CreateDevice( custom_border_colors = border_color_features->customBorderColors; break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR: { + const VkPhysicalDeviceFragmentShadingRateFeaturesKHR *vrs = (const void *)ext; + vrs_enabled = vrs->pipelineFragmentShadingRate || + vrs->primitiveFragmentShadingRate || + vrs->attachmentFragmentShadingRate; + break; + } default: break; } @@ -2738,6 +2746,12 @@ VkResult radv_CreateDevice( device->robust_buffer_access = robust_buffer_access; + device->adjust_frag_coord_z = (vrs_enabled || + device->enabled_extensions.KHR_fragment_shading_rate) && + (device->physical_device->rad_info.family == CHIP_SIENNA_CICHLID || + device->physical_device->rad_info.family == CHIP_NAVY_FLOUNDER || + device->physical_device->rad_info.family == CHIP_VANGOGH); + mtx_init(&device->shader_slab_mutex, mtx_plain); list_inithead(&device->shader_slabs); diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index c980727d9f0..695a971dac8 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -825,6 +825,11 @@ struct radv_device { /* Whether the app has enabled the robustBufferAccess feature. */ bool robust_buffer_access; + /* Whether gl_FragCoord.z should be adjusted for VRS due to a hw bug + * on some GFX10.3 chips. + */ + bool adjust_frag_coord_z; + /* Whether the driver uses a global BO list. */ bool use_global_bo_list; diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index cab4b1b5941..6646978435b 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -1293,6 +1293,7 @@ shader_variant_compile(struct radv_device *device, options->has_ls_vgpr_init_bug = device->physical_device->rad_info.has_ls_vgpr_init_bug; options->use_ngg_streamout = device->physical_device->use_ngg_streamout; options->enable_mrt_output_nan_fixup = device->instance->enable_mrt_output_nan_fixup; + options->adjust_frag_coord_z = device->adjust_frag_coord_z; options->debug.func = radv_compiler_debug; options->debug.private_data = &debug_data; diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h index 24778f5adf8..44f5a2785f0 100644 --- a/src/amd/vulkan/radv_shader.h +++ b/src/amd/vulkan/radv_shader.h @@ -135,6 +135,7 @@ struct radv_nir_compiler_options { bool explicit_scratch_args; bool clamp_shadow_reference; bool robust_buffer_access; + bool adjust_frag_coord_z; bool dump_shader; bool dump_preoptir; bool record_ir;