Fix #137429: GPU: Allow missing attribute in pygpu_shader_attrs_info_get
In `pygpu_shader_attrs_info_get`, it tries to check information for all vertex attributes that are added via `VERTEX_IN`, however some drivers will optimize compiled shaders so some vertex attributes that are not used will be removed. This fix makes sure that the input length that is used in `GPU_shader_get_attribute_len` does not exceed actual max binding number. Pull Request: https://projects.blender.org/blender/blender/pulls/137584
This commit is contained in:
@@ -605,7 +605,7 @@ int GPU_shader_get_sampler_binding(GPUShader *shader, const char *name)
|
||||
uint GPU_shader_get_attribute_len(const GPUShader *shader)
|
||||
{
|
||||
const ShaderInterface *interface = unwrap(shader)->interface;
|
||||
return interface->attr_len_;
|
||||
return interface->valid_bindings_get(interface->inputs_, interface->attr_len_);
|
||||
}
|
||||
|
||||
uint GPU_shader_get_ssbo_input_len(const GPUShader *shader)
|
||||
|
||||
@@ -144,6 +144,8 @@ class ShaderInterface {
|
||||
return builtin_blocks_[builtin];
|
||||
}
|
||||
|
||||
inline uint valid_bindings_get(const ShaderInput *const inputs, const uint inputs_len) const;
|
||||
|
||||
protected:
|
||||
static inline const char *builtin_uniform_name(GPUUniformBuiltin u);
|
||||
static inline const char *builtin_uniform_block_name(GPUUniformBlockBuiltin u);
|
||||
@@ -312,4 +314,17 @@ inline const ShaderInput *ShaderInterface::input_lookup(const ShaderInput *const
|
||||
return nullptr; /* not found */
|
||||
}
|
||||
|
||||
inline uint ShaderInterface::valid_bindings_get(const ShaderInput *const inputs,
|
||||
const uint inputs_len) const
|
||||
{
|
||||
/* Simple linear search for now. */
|
||||
int valid_bindings = 0;
|
||||
for (int i = inputs_len - 1; i >= 0; i--) {
|
||||
if (inputs[i].binding > -1) {
|
||||
valid_bindings++;
|
||||
}
|
||||
}
|
||||
return valid_bindings;
|
||||
}
|
||||
|
||||
} // namespace blender::gpu
|
||||
|
||||
Reference in New Issue
Block a user