spirv: Always emit deref_buffer_array_length intrinsics
All the drivers have been converted to setting this option now except imagination and they don't support SSBOs yet. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3993 Reviewed-by: Caio Oliveira <caio.oliveira@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21446>
This commit is contained in:

committed by
Marge Bot

parent
fbeb81d812
commit
96c832c47e
@@ -65,11 +65,6 @@ struct spirv_to_nir_options {
|
||||
/* Create a nir library. */
|
||||
bool create_library;
|
||||
|
||||
/* Whether to use nir_intrinsic_deref_buffer_array_length intrinsic instead
|
||||
* of nir_intrinsic_get_ssbo_size to lower OpArrayLength.
|
||||
*/
|
||||
bool use_deref_buffer_array_length;
|
||||
|
||||
/* Initial value for shader_info::float_controls_execution_mode,
|
||||
* indicates hardware requirements rather than shader author intent
|
||||
*/
|
||||
|
@@ -162,7 +162,6 @@ int main(int argc, char **argv)
|
||||
|
||||
struct spirv_to_nir_options spirv_opts = {
|
||||
.environment = env,
|
||||
.use_deref_buffer_array_length = env == NIR_SPIRV_OPENGL,
|
||||
};
|
||||
|
||||
if (shader_stage == MESA_SHADER_KERNEL) {
|
||||
|
@@ -2646,46 +2646,20 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
||||
"OpArrayLength must reference the last memeber of the "
|
||||
"structure and that must be an array");
|
||||
|
||||
if (b->options->use_deref_buffer_array_length) {
|
||||
struct vtn_access_chain chain = {
|
||||
.length = 1,
|
||||
.link = {
|
||||
{ .mode = vtn_access_mode_literal, .id = field },
|
||||
}
|
||||
};
|
||||
struct vtn_pointer *array = vtn_pointer_dereference(b, ptr, &chain);
|
||||
|
||||
nir_ssa_def *array_length =
|
||||
nir_build_deref_buffer_array_length(&b->nb, 32,
|
||||
vtn_pointer_to_ssa(b, array),
|
||||
.access=ptr->access | ptr->type->access);
|
||||
|
||||
vtn_push_nir_ssa(b, w[2], array_length);
|
||||
} else {
|
||||
const uint32_t offset = ptr->type->offsets[field];
|
||||
const uint32_t stride = ptr->type->members[field]->stride;
|
||||
|
||||
if (!ptr->block_index) {
|
||||
struct vtn_access_chain chain = {
|
||||
.length = 0,
|
||||
};
|
||||
ptr = vtn_pointer_dereference(b, ptr, &chain);
|
||||
vtn_assert(ptr->block_index);
|
||||
struct vtn_access_chain chain = {
|
||||
.length = 1,
|
||||
.link = {
|
||||
{ .mode = vtn_access_mode_literal, .id = field },
|
||||
}
|
||||
};
|
||||
struct vtn_pointer *array = vtn_pointer_dereference(b, ptr, &chain);
|
||||
|
||||
nir_ssa_def *buf_size = nir_get_ssbo_size(&b->nb, ptr->block_index,
|
||||
.access=ptr->access | ptr->type->access);
|
||||
nir_ssa_def *array_length =
|
||||
nir_build_deref_buffer_array_length(&b->nb, 32,
|
||||
vtn_pointer_to_ssa(b, array),
|
||||
.access=ptr->access | ptr->type->access);
|
||||
|
||||
/* array_length = max(buffer_size - offset, 0) / stride */
|
||||
nir_ssa_def *array_length =
|
||||
nir_udiv_imm(&b->nb,
|
||||
nir_usub_sat(&b->nb,
|
||||
buf_size,
|
||||
nir_imm_int(&b->nb, offset)),
|
||||
stride);
|
||||
|
||||
vtn_push_nir_ssa(b, w[2], array_length);
|
||||
}
|
||||
vtn_push_nir_ssa(b, w[2], array_length);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user