From f03be478a9cb81a800c719fc116c2b1b769170f5 Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Mon, 5 May 2025 14:32:50 +0200 Subject: [PATCH] tu/lrz: Add tu_ignore_frag_depth_direction driconf Will be useful if app doesn't specify depth direction correctly. E.g. the capture of "Sons of The Forest" I have has a shader where `gl_FragDepth` has `layout(depth_less)`, but the output for different fragments is actually sometimes less, sometimes more than the original depth by a tiny margin. Signed-off-by: Danylo Piliaiev Part-of: --- src/freedreno/vulkan/tu_device.cc | 3 +++ src/freedreno/vulkan/tu_device.h | 3 +++ src/freedreno/vulkan/tu_lrz.cc | 3 ++- src/util/00-mesa-defaults.conf | 3 +++ src/util/driconf.h | 4 ++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/freedreno/vulkan/tu_device.cc b/src/freedreno/vulkan/tu_device.cc index 7f537cc448b..0b9b66aee2d 100644 --- a/src/freedreno/vulkan/tu_device.cc +++ b/src/freedreno/vulkan/tu_device.cc @@ -1643,6 +1643,7 @@ static const driOptionDescription tu_dri_options[] = { DRI_CONF_TU_ALLOW_OOB_INDIRECT_UBO_LOADS(false) DRI_CONF_TU_DISABLE_D24S8_BORDER_COLOR_WORKAROUND(false) DRI_CONF_TU_USE_TEX_COORD_ROUND_NEAREST_EVEN_MODE(false) + DRI_CONF_TU_IGNORE_FRAG_DEPTH_DIRECTION(false) DRI_CONF_SECTION_END }; @@ -1667,6 +1668,8 @@ tu_init_dri_options(struct tu_instance *instance) driQueryOptionb(&instance->dri_options, "tu_disable_d24s8_border_color_workaround"); instance->use_tex_coord_round_nearest_even_mode = driQueryOptionb(&instance->dri_options, "tu_use_tex_coord_round_nearest_even_mode"); + instance->ignore_frag_depth_direction = + driQueryOptionb(&instance->dri_options, "tu_ignore_frag_depth_direction"); } static uint32_t instance_count = 0; diff --git a/src/freedreno/vulkan/tu_device.h b/src/freedreno/vulkan/tu_device.h index 58eae80f131..1c0509ff951 100644 --- a/src/freedreno/vulkan/tu_device.h +++ b/src/freedreno/vulkan/tu_device.h @@ -208,6 +208,9 @@ struct tu_instance /* D3D emulation requires texture coordinates to be rounded to nearest even value. */ bool use_tex_coord_round_nearest_even_mode; + + /* Apps may be accidentally incorrect */ + bool ignore_frag_depth_direction; }; VK_DEFINE_HANDLE_CASTS(tu_instance, vk.base, VkInstance, VK_OBJECT_TYPE_INSTANCE) diff --git a/src/freedreno/vulkan/tu_lrz.cc b/src/freedreno/vulkan/tu_lrz.cc index 61646ed079f..f32861632be 100644 --- a/src/freedreno/vulkan/tu_lrz.cc +++ b/src/freedreno/vulkan/tu_lrz.cc @@ -815,7 +815,8 @@ tu6_calculate_lrz_state(struct tu_cmd_buffer *cmd, * enable late Z test. */ if (!disable_lrz_due_to_fs && fs->variant->writes_pos && - !fs->variant->fs.early_fragment_tests) { + !fs->variant->fs.early_fragment_tests && + !cmd->device->instance->ignore_frag_depth_direction) { if (fs->variant->fs.depth_layout == FRAG_DEPTH_LAYOUT_NONE || fs->variant->fs.depth_layout == FRAG_DEPTH_LAYOUT_ANY) { disable_lrz_due_to_fs = true; diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf index d8cc6b63392..cdcf300c9d4 100644 --- a/src/util/00-mesa-defaults.conf +++ b/src/util/00-mesa-defaults.conf @@ -1262,6 +1262,9 @@ TODO: document the other workarounds. -->