broadcom/compiler: fix num_textures for precompiled shaders
Some shaders use N textures but not bind these in consecutive slots, so then we find texture accesses to indices that exceed the number of textures and we assert crash. This happens with various shaders from shader-db. Fix that by looking at the largest binding used in the shader and using that as the number of textures used. Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28978>
This commit is contained in:
@@ -602,12 +602,25 @@ v3d_setup_shared_precompile_key(struct v3d_uncompiled_shader *uncompiled,
|
||||
{
|
||||
nir_shader *s = uncompiled->base.ir.nir;
|
||||
|
||||
/* The shader may have gaps in the texture bindings, so figure out
|
||||
* the largest binding in use and setup the number of textures and
|
||||
* samplers from there instead of just the texture count from shader
|
||||
* info.
|
||||
*/
|
||||
key->num_tex_used = 0;
|
||||
key->num_samplers_used = 0;
|
||||
for (int i = V3D_MAX_TEXTURE_SAMPLERS - 1; i >= 0; i--) {
|
||||
if (s->info.textures_used[0] & (1 << i)) {
|
||||
key->num_tex_used = i + 1;
|
||||
key->num_samplers_used = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Note that below we access they key's texture and sampler fields
|
||||
* using the same index. On OpenGL they are the same (they are
|
||||
* combined)
|
||||
*/
|
||||
key->num_tex_used = s->info.num_textures;
|
||||
key->num_samplers_used = s->info.num_textures;
|
||||
for (int i = 0; i < s->info.num_textures; i++) {
|
||||
key->sampler[i].return_size = 16;
|
||||
key->sampler[i].return_channels = 2;
|
||||
|
||||
Reference in New Issue
Block a user