From 95003c99d90bb8d6a682cb11036fb943ba0f4e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Sun, 27 Nov 2022 23:22:32 +0100 Subject: [PATCH] GPU: Change inheritance of depth write and default values This new inheritance behavior is more beneficial for the metal Backend. Also change the default depth write behavior of shaders to be unchanged. This makes fragment shader depth amendment more explicit. This also add the missing depth_write for metal kernels. --- source/blender/gpu/intern/gpu_shader_create_info.cc | 4 +++- source/blender/gpu/intern/gpu_shader_create_info.hh | 7 ++++--- source/blender/gpu/metal/kernels/depth_2d_update_info.hh | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/blender/gpu/intern/gpu_shader_create_info.cc b/source/blender/gpu/intern/gpu_shader_create_info.cc index ebbddccbe47..ffbeedad285 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.cc +++ b/source/blender/gpu/intern/gpu_shader_create_info.cc @@ -68,7 +68,9 @@ void ShaderCreateInfo::finalize() if (info.early_fragment_test_) { early_fragment_test_ = true; } - if (info.depth_write_ != DepthWrite::ANY) { + /* Override depth-write with additional info if this specifies a writing mode + * other than the default. */ + if (info.depth_write_ != DepthWrite::UNCHANGED) { depth_write_ = info.depth_write_; } diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh index 25a79dd26ac..79164ca37f7 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.hh +++ b/source/blender/gpu/intern/gpu_shader_create_info.hh @@ -189,10 +189,11 @@ ENUM_OPERATORS(BuiltinBits, BuiltinBits::USE_DEBUG_PRINT); * https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_conservative_depth.txt */ enum class DepthWrite { - ANY = 0, + /* UNCHANGED specified as default to indicate gl_FragDepth is not used. */ + UNCHANGED = 0, + ANY, GREATER, LESS, - UNCHANGED, }; /* Samplers & images. */ @@ -343,7 +344,7 @@ struct ShaderCreateInfo { /** If true, force the use of the GL shader introspection for resource location. */ bool legacy_resource_location_ = false; /** Allow optimization when fragment shader writes to `gl_FragDepth`. */ - DepthWrite depth_write_ = DepthWrite::ANY; + DepthWrite depth_write_ = DepthWrite::UNCHANGED; /** * Maximum length of all the resource names including each null terminator. * Only for names used by #gpu::ShaderInterface. diff --git a/source/blender/gpu/metal/kernels/depth_2d_update_info.hh b/source/blender/gpu/metal/kernels/depth_2d_update_info.hh index 0a3281a98f2..4f8b15b9784 100644 --- a/source/blender/gpu/metal/kernels/depth_2d_update_info.hh +++ b/source/blender/gpu/metal/kernels/depth_2d_update_info.hh @@ -17,6 +17,7 @@ GPU_SHADER_CREATE_INFO(depth_2d_update_info_base) .push_constant(Type::VEC2, "size") .push_constant(Type::INT, "mip") .sampler(0, ImageType::FLOAT_2D, "source_data", Frequency::PASS) + .depth_write(DepthWrite::ANY) .vertex_source("depth_2d_update_vert.glsl"); GPU_SHADER_CREATE_INFO(depth_2d_update_float)