Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-05-01 23:26:54 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-05-01 23:28:38 +0300
commit3f0c09f6ddde9ba0f995eb3d7e088bd650112891 (patch)
treec85cdbb894b0e6d9fee616e956590174cd057209 /source/blender/gpu/intern
parentfc872d738ef1526fd251f073c1a495344360a667 (diff)
GPUShaderCreateInfo: Add validation for overlapping vertex attribute
Those are usually not supported but some driver silently fix them and most just silently fail (rendering error).
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r--source/blender/gpu/intern/gpu_shader_create_info.cc46
-rw-r--r--source/blender/gpu/intern/gpu_shader_create_info.hh3
2 files changed, 44 insertions, 5 deletions
diff --git a/source/blender/gpu/intern/gpu_shader_create_info.cc b/source/blender/gpu/intern/gpu_shader_create_info.cc
index 6e82201b424..f5b90989481 100644
--- a/source/blender/gpu/intern/gpu_shader_create_info.cc
+++ b/source/blender/gpu/intern/gpu_shader_create_info.cc
@@ -41,6 +41,8 @@ void ShaderCreateInfo::finalize()
Set<StringRefNull> deps_merged;
+ validate_vertex_attributes();
+
for (auto &info_name : additional_infos_) {
const ShaderCreateInfo &info = *reinterpret_cast<const ShaderCreateInfo *>(
gpu_shader_create_info_get(info_name.c_str()));
@@ -55,6 +57,8 @@ void ShaderCreateInfo::finalize()
vertex_out_interfaces_.extend(info.vertex_out_interfaces_);
geometry_out_interfaces_.extend(info.geometry_out_interfaces_);
+ validate_vertex_attributes(&info);
+
push_constants_.extend(info.push_constants_);
defines_.extend(info.defines_);
@@ -69,7 +73,7 @@ void ShaderCreateInfo::finalize()
depth_write_ = info.depth_write_;
}
- validate(info);
+ validate_merge(info);
auto assert_no_overlap = [&](const bool test, const StringRefNull error) {
if (!test) {
@@ -164,7 +168,7 @@ std::string ShaderCreateInfo::check_error() const
return error;
}
-void ShaderCreateInfo::validate(const ShaderCreateInfo &other_info)
+void ShaderCreateInfo::validate_merge(const ShaderCreateInfo &other_info)
{
if (!auto_resource_location_) {
/* Check same bind-points usage in OGL. */
@@ -220,8 +224,42 @@ void ShaderCreateInfo::validate(const ShaderCreateInfo &other_info)
}
}
}
- {
- /* TODO(@fclem): Push constant validation. */
+}
+
+void ShaderCreateInfo::validate_vertex_attributes(const ShaderCreateInfo *other_info)
+{
+ uint32_t attr_bits = 0;
+ for (auto &attr : vertex_inputs_) {
+ if (attr.index >= 16 || attr.index < 0) {
+ std::cout << name_ << ": \"" << attr.name
+ << "\" : Type::MAT3 unsupported as vertex attribute." << std::endl;
+ BLI_assert(0);
+ }
+ if (attr.index >= 16 || attr.index < 0) {
+ std::cout << name_ << ": Invalid index for attribute \"" << attr.name << "\"" << std::endl;
+ BLI_assert(0);
+ }
+ uint32_t attr_new = 0;
+ if (attr.type == Type::MAT4) {
+ for (int i = 0; i < 4; i++) {
+ attr_new |= 1 << (attr.index + i);
+ }
+ }
+ else {
+ attr_new |= 1 << attr.index;
+ }
+
+ if ((attr_bits & attr_new) != 0) {
+ std::cout << name_ << ": Attribute \"" << attr.name
+ << "\" overlap one or more index from another attribute."
+ " Note that mat4 takes up 4 indices.";
+ if (other_info) {
+ std::cout << " While merging " << other_info->name_ << std::endl;
+ }
+ std::cout << std::endl;
+ BLI_assert(0);
+ }
+ attr_bits |= attr_new;
}
}
diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh
index 7c827e237eb..4927ef75a75 100644
--- a/source/blender/gpu/intern/gpu_shader_create_info.hh
+++ b/source/blender/gpu/intern/gpu_shader_create_info.hh
@@ -801,7 +801,8 @@ struct ShaderCreateInfo {
std::string check_error() const;
/** Error detection that some backend compilers do not complain about. */
- void validate(const ShaderCreateInfo &other_info);
+ void validate_merge(const ShaderCreateInfo &other_info);
+ void validate_vertex_attributes(const ShaderCreateInfo *other_info = nullptr);
/** \} */