diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-01-24 15:23:50 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-01-24 15:28:33 +0300 |
commit | e774f2c901f291c0cd721285a6e25052b0e9e5c2 (patch) | |
tree | c29e4824e7af93f07fbb42ded7cb3e54fddcd49e /source/blender/gpu | |
parent | 7708a848c96915425b37db937478b4ecd227fc0d (diff) |
GPUShaderCreateInfo: Add manual validation of bindpoints
Some drivers/glsl compilers will not warn about multiple resources using
the same binding, creating silent errors.
This patch checks for this case and outputs a descriptive error message if
a particular createInfo merge error is founds.
Other validation can be added later.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_create_info.cc | 63 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_create_info.hh | 3 |
2 files changed, 66 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 de0b7a0be6d..b8ae6bc3868 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.cc +++ b/source/blender/gpu/intern/gpu_shader_create_info.cc @@ -72,6 +72,8 @@ void ShaderCreateInfo::finalize() pass_resources_.extend(info.pass_resources_); typedef_sources_.extend(info.typedef_sources_); + validate(info); + if (info.local_group_size_[0] != 0) { BLI_assert(local_group_size_[0] == 0); for (int i = 0; i < 3; i++) { @@ -100,6 +102,67 @@ void ShaderCreateInfo::finalize() } } +void ShaderCreateInfo::validate(const ShaderCreateInfo &other_info) +{ + { + /* Check same bindpoints usage in OGL. */ + Set<int> images, samplers, ubos, ssbos; + + auto register_resource = [&](const Resource &res) -> bool { + switch (res.bind_type) { + case Resource::BindType::UNIFORM_BUFFER: + return images.add(res.slot); + case Resource::BindType::STORAGE_BUFFER: + return samplers.add(res.slot); + case Resource::BindType::SAMPLER: + return ubos.add(res.slot); + case Resource::BindType::IMAGE: + return ssbos.add(res.slot); + default: + return false; + } + }; + + auto print_error_msg = [&](const Resource &res) { + std::cerr << name_ << ": Validation failed : Overlapping "; + + switch (res.bind_type) { + case Resource::BindType::UNIFORM_BUFFER: + std::cerr << "Uniform Buffer " << res.uniformbuf.name; + break; + case Resource::BindType::STORAGE_BUFFER: + std::cerr << "Storage Buffer " << res.storagebuf.name; + break; + case Resource::BindType::SAMPLER: + std::cerr << "Sampler " << res.sampler.name; + break; + case Resource::BindType::IMAGE: + std::cerr << "Image " << res.image.name; + break; + default: + std::cerr << "Unknown Type"; + break; + } + std::cerr << " (" << res.slot << ") while merging " << other_info.name_ << std::endl; + }; + + for (auto &res : batch_resources_) { + if (register_resource(res) == false) { + print_error_msg(res); + } + } + + for (auto &res : pass_resources_) { + if (register_resource(res) == false) { + print_error_msg(res); + } + } + } + { + /* TODO(fclem) Push constant validation. */ + } +} + } // namespace blender::gpu::shader using namespace blender::gpu::shader; diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh index a1ebdb0ec51..c7b3ac5ca37 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.hh +++ b/source/blender/gpu/intern/gpu_shader_create_info.hh @@ -597,6 +597,9 @@ struct ShaderCreateInfo { /* WARNING: Recursive. */ void finalize(); + /** Error detection that some backend compilers do not complain about. */ + void validate(const ShaderCreateInfo &other_info); + /** \} */ }; |