glsl/nir/linker: update shader_storage_blocks_write_access for SPIR-V

Most of the code inside the "!prog->data->spirv" blocks shouldn't be
executed for SPIR-V except the part updating the writable mask.

See https://gitlab.freedesktop.org/mesa/mesa/-/issues/6184

Cc: mesa-stable
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15552>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2022-03-23 13:35:14 +01:00
parent 007cb02db9
commit 61ee560bc5

View file

@ -1669,7 +1669,8 @@ gl_nir_link_uniforms(const struct gl_constants *consts,
struct gl_uniform_block *blocks = NULL;
int num_blocks = 0;
int buffer_block_index = -1;
if (!prog->data->spirv && state.var_is_in_block) {
bool is_interface_array = false;
if (state.var_is_in_block) {
/* If the uniform is inside a uniform block determine its block index by
* comparing the bindings, we can not use names.
*/
@ -1678,14 +1679,14 @@ gl_nir_link_uniforms(const struct gl_constants *consts,
num_blocks = nir_variable_is_in_ssbo(state.current_var) ?
prog->data->NumShaderStorageBlocks : prog->data->NumUniformBlocks;
bool is_interface_array =
is_interface_array =
glsl_without_array(state.current_var->type) == state.current_var->interface_type &&
glsl_type_is_array(state.current_var->type);
const char *ifc_name =
glsl_get_type_name(state.current_var->interface_type);
if (is_interface_array) {
if (is_interface_array && !prog->data->spirv) {
unsigned l = strlen(ifc_name);
/* Even when a match is found, do not "break" here. As this is
@ -1711,36 +1712,44 @@ gl_nir_link_uniforms(const struct gl_constants *consts,
}
} else {
for (unsigned i = 0; i < num_blocks; i++) {
if (strcmp(ifc_name, blocks[i].name.string) == 0) {
bool match = false;
if (!prog->data->spirv) {
match = strcmp(ifc_name, blocks[i].name.string) == 0;
} else {
match = var->data.binding == blocks[i].Binding;
}
if (match) {
buffer_block_index = i;
struct hash_entry *entry =
_mesa_hash_table_search(state.referenced_uniforms[shader_type],
var->name);
if (entry)
blocks[i].stageref |= 1U << shader_type;
if (!prog->data->spirv) {
struct hash_entry *entry =
_mesa_hash_table_search(state.referenced_uniforms[shader_type],
var->name);
if (entry)
blocks[i].stageref |= 1U << shader_type;
}
break;
}
}
}
}
if (nir_variable_is_in_ssbo(var) &&
!(var->data.access & ACCESS_NON_WRITEABLE)) {
unsigned array_size = is_interface_array ?
glsl_get_length(var->type) : 1;
if (nir_variable_is_in_ssbo(var) &&
!(var->data.access & ACCESS_NON_WRITEABLE)) {
unsigned array_size = is_interface_array ?
glsl_get_length(var->type) : 1;
STATIC_ASSERT(MAX_SHADER_STORAGE_BUFFERS <= 32);
STATIC_ASSERT(MAX_SHADER_STORAGE_BUFFERS <= 32);
/* Shaders that use too many SSBOs will fail to compile, which
* we don't care about.
*
* This is true for shaders that do not use too many SSBOs:
*/
if (buffer_block_index + array_size <= 32) {
state.shader_storage_blocks_write_access |=
u_bit_consecutive(buffer_block_index, array_size);
}
/* Shaders that use too many SSBOs will fail to compile, which
* we don't care about.
*
* This is true for shaders that do not use too many SSBOs:
*/
if (buffer_block_index + array_size <= 32) {
state.shader_storage_blocks_write_access |=
u_bit_consecutive(buffer_block_index, array_size);
}
}