diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-03-03 23:10:55 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-03-18 22:53:52 +0300 |
commit | 3f484c502f3efe3f04b359a196034827d46fd9b9 (patch) | |
tree | de6de2102a8a542909bbe04d3c72595bfaa6a79f | |
parent | 0f08453ea9216c3cd957c17278a7158c98525219 (diff) |
GPUShaderCreateInfo: Add explicit early_fragment_test
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_create_info.cc | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_create_info.hh | 12 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_shader.cc | 3 |
3 files changed, 19 insertions, 0 deletions
diff --git a/source/blender/gpu/intern/gpu_shader_create_info.cc b/source/blender/gpu/intern/gpu_shader_create_info.cc index ec4ff7bc399..aef1984687d 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.cc +++ b/source/blender/gpu/intern/gpu_shader_create_info.cc @@ -62,6 +62,10 @@ void ShaderCreateInfo::finalize() pass_resources_.extend(info.pass_resources_); typedef_sources_.extend_non_duplicates(info.typedef_sources_); + if (info.early_fragment_test_) { + early_fragment_test_ = true; + } + validate(info); auto assert_no_overlap = [&](const bool test, const StringRefNull error) { diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh index da63d372669..9984295457c 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.hh +++ b/source/blender/gpu/intern/gpu_shader_create_info.hh @@ -271,6 +271,8 @@ struct ShaderCreateInfo { bool finalized_ = false; /** If true, all resources will have an automatic location assigned. */ bool auto_resource_location_ = false; + /** If true, force depth and stencil tests to always happen before fragment shader invocation. */ + bool early_fragment_test_ = false; /** * Maximum length of all the resource names including each null terminator. * Only for names used by gpu::ShaderInterface. @@ -522,6 +524,16 @@ struct ShaderCreateInfo { } /** + * Force fragment tests before fragment shader invocation. + * IMPORTANT: This is incompatible with using the gl_FragDepth output. + */ + Self &early_fragment_test(bool enable) + { + early_fragment_test_ = enable; + return *(Self *)this; + } + + /** * Only needed if geometry shader is enabled. * IMPORTANT: Input and output instance name will have respectively "_in" and "_out" suffix * appended in the geometry shader IF AND ONLY IF the vertex_out interface instance name matches diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index c5130628b84..518306905ee 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -576,6 +576,9 @@ std::string GLShader::fragment_interface_declare(const ShaderCreateInfo &info) c pre_main += " gpu_BaryCoordNoPersp = stable_bary_(gl_BaryCoordNoPerspAMD);\n"; } } + if (info.early_fragment_test_) { + ss << "layout(early_fragment_tests) in;\n"; + } ss << "\n/* Outputs. */\n"; for (const ShaderCreateInfo::FragOut &output : info.fragment_outputs_) { ss << "layout(location = " << output.index; |