From c3bede9c96e80b45397f893e5960ebf2de76159a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 9 Nov 2020 16:16:01 +1000 Subject: [PATCH] gallivm: don't lower local invocation index in frontend The frontend can't handle variable block sizes properly, so just lower it here in the backend. Fixes CTS basic local_linear_id + get_linear_ids Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir.c | 1 + src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 14 ++++++++++++++ src/gallium/drivers/llvmpipe/lp_screen.c | 1 - 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index 47466b6..5884f0a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -1695,6 +1695,7 @@ static void visit_intrinsic(struct lp_build_nir_context *bld_base, case nir_intrinsic_load_first_vertex: case nir_intrinsic_load_workgroup_id: case nir_intrinsic_load_local_invocation_id: + case nir_intrinsic_load_local_invocation_index: case nir_intrinsic_load_num_workgroups: case nir_intrinsic_load_invocation_id: case nir_intrinsic_load_front_face: diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 65c3422..eb4e0f4 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -1528,6 +1528,20 @@ static void emit_sysval_intrin(struct lp_build_nir_context *bld_base, for (unsigned i = 0; i < 3; i++) result[i] = LLVMBuildExtractValue(gallivm->builder, bld->system_values.thread_id, i, ""); break; + case nir_intrinsic_load_local_invocation_index: { + LLVMValueRef tmp, tmp2; + tmp = lp_build_broadcast_scalar(&bld_base->uint_bld, LLVMBuildExtractElement(gallivm->builder, bld->system_values.block_size, lp_build_const_int32(gallivm, 1), "")); + tmp2 = lp_build_broadcast_scalar(&bld_base->uint_bld, LLVMBuildExtractElement(gallivm->builder, bld->system_values.block_size, lp_build_const_int32(gallivm, 0), "")); + tmp = lp_build_mul(&bld_base->uint_bld, tmp, tmp2); + tmp = lp_build_mul(&bld_base->uint_bld, tmp, LLVMBuildExtractValue(gallivm->builder, bld->system_values.thread_id, 2, "")); + + tmp2 = lp_build_broadcast_scalar(&bld_base->uint_bld, LLVMBuildExtractElement(gallivm->builder, bld->system_values.block_size, lp_build_const_int32(gallivm, 0), "")); + tmp2 = lp_build_mul(&bld_base->uint_bld, tmp2, LLVMBuildExtractValue(gallivm->builder, bld->system_values.thread_id, 1, "")); + tmp = lp_build_add(&bld_base->uint_bld, tmp, tmp2); + tmp = lp_build_add(&bld_base->uint_bld, tmp, LLVMBuildExtractValue(gallivm->builder, bld->system_values.thread_id, 0, "")); + result[0] = tmp; + break; + } case nir_intrinsic_load_num_workgroups: { LLVMValueRef tmp[3]; for (unsigned i = 0; i < 3; i++) { diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index 0d55bb0..4e43f5a 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -595,7 +595,6 @@ static const struct nir_shader_compiler_options gallivm_nir_options = { .max_unroll_iterations = 32, .use_interpolated_input_intrinsics = true, .lower_to_scalar = true, - .lower_cs_local_index_from_id = true, .lower_uniforms_to_ubo = true, .lower_vector_cmp = true, .lower_device_index_to_zero = true, -- 2.7.4