From 336954f7e740006591cfa523018e4a83143e8281 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 10 Dec 2019 14:51:57 +1000 Subject: [PATCH] gallivm/llvmpipe: add support for work dimension intrinsic. We have to pass the work_dim given by the user into the shader. Acked-by: Roland Scheidegger --- src/gallium/auxiliary/gallivm/lp_bld_nir.c | 1 + .../auxiliary/gallivm/lp_bld_nir_soa.c | 3 ++ src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 1 + src/gallium/drivers/llvmpipe/lp_jit.h | 1 + src/gallium/drivers/llvmpipe/lp_state_cs.c | 41 +++++++++++-------- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index 85bb5f55ce7..82b847d05c9 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -1246,6 +1246,7 @@ static void visit_intrinsic(struct lp_build_nir_context *bld_base, case nir_intrinsic_load_invocation_id: case nir_intrinsic_load_front_face: case nir_intrinsic_load_draw_id: + case nir_intrinsic_load_work_dim: bld_base->sysval_intrin(bld_base, instr, result); break; case nir_intrinsic_discard_if: diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index f31561f2b9e..26183dba723 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -996,6 +996,9 @@ static void emit_sysval_intrin(struct lp_build_nir_context *bld_base, break; default: break; + case nir_intrinsic_load_work_dim: + result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.work_dim); + break; } } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index 63a5bc3d621..3be44018383 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -176,6 +176,7 @@ struct lp_bld_tgsi_system_values { LLVMValueRef block_id; LLVMValueRef grid_size; LLVMValueRef front_facing; + LLVMValueRef work_dim; }; diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index 0e549a05c0a..71931e15eb7 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -385,6 +385,7 @@ typedef void uint32_t grid_size_x, uint32_t grid_size_y, uint32_t grid_size_z, + uint32_t work_dim, struct lp_jit_cs_thread_data *thread_data); void diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c index f4f021742d6..f40336adecb 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_cs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c @@ -51,6 +51,7 @@ struct lp_cs_job_info { unsigned grid_size[3]; unsigned block_size[3]; unsigned req_local_mem; + unsigned work_dim; struct lp_cs_exec *current; }; @@ -62,14 +63,14 @@ generate_compute(struct llvmpipe_context *lp, struct gallivm_state *gallivm = variant->gallivm; const struct lp_compute_shader_variant_key *key = &variant->key; char func_name[64], func_name_coro[64]; - LLVMTypeRef arg_types[13]; + LLVMTypeRef arg_types[14]; LLVMTypeRef func_type, coro_func_type; LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context); LLVMValueRef context_ptr; LLVMValueRef x_size_arg, y_size_arg, z_size_arg; LLVMValueRef grid_x_arg, grid_y_arg, grid_z_arg; LLVMValueRef grid_size_x_arg, grid_size_y_arg, grid_size_z_arg; - LLVMValueRef thread_data_ptr; + LLVMValueRef work_dim_arg, thread_data_ptr; LLVMBasicBlockRef block; LLVMBuilderRef builder; struct lp_build_sampler_soa *sampler; @@ -107,11 +108,12 @@ generate_compute(struct llvmpipe_context *lp, arg_types[7] = int32_type; /* grid_size_x */ arg_types[8] = int32_type; /* grid_size_y */ arg_types[9] = int32_type; /* grid_size_z */ - arg_types[10] = variant->jit_cs_thread_data_ptr_type; /* per thread data */ - arg_types[11] = int32_type; - arg_types[12] = int32_type; + arg_types[10] = int32_type; /* work dim */ + arg_types[11] = variant->jit_cs_thread_data_ptr_type; /* per thread data */ + arg_types[12] = int32_type; /* coro only - num X loops */ + arg_types[13] = int32_type; /* coro only - partials */ func_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context), - arg_types, ARRAY_SIZE(arg_types) - 2, 0); + arg_types, ARRAY_SIZE(arg_types) - 5, 0); coro_func_type = LLVMFunctionType(LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0), arg_types, ARRAY_SIZE(arg_types), 0); @@ -141,7 +143,8 @@ generate_compute(struct llvmpipe_context *lp, grid_size_x_arg = LLVMGetParam(function, 7); grid_size_y_arg = LLVMGetParam(function, 8); grid_size_z_arg = LLVMGetParam(function, 9); - thread_data_ptr = LLVMGetParam(function, 10); + work_dim_arg = LLVMGetParam(function, 10); + thread_data_ptr = LLVMGetParam(function, 11); lp_build_name(context_ptr, "context"); lp_build_name(x_size_arg, "x_size"); @@ -153,6 +156,7 @@ generate_compute(struct llvmpipe_context *lp, lp_build_name(grid_size_x_arg, "grid_size_x"); lp_build_name(grid_size_y_arg, "grid_size_y"); lp_build_name(grid_size_z_arg, "grid_size_z"); + lp_build_name(work_dim_arg, "work_dim"); lp_build_name(thread_data_ptr, "thread_data"); block = LLVMAppendBasicBlockInContext(gallivm->context, function, "entry"); @@ -193,7 +197,7 @@ generate_compute(struct llvmpipe_context *lp, lp_build_loop_begin(&loop_state[0], gallivm, lp_build_const_int32(gallivm, 0)); /* x loop */ { - LLVMValueRef args[13]; + LLVMValueRef args[14]; args[0] = context_ptr; args[1] = loop_state[0].counter; args[2] = loop_state[1].counter; @@ -204,9 +208,10 @@ generate_compute(struct llvmpipe_context *lp, args[7] = grid_size_x_arg; args[8] = grid_size_y_arg; args[9] = grid_size_z_arg; - args[10] = thread_data_ptr; - args[11] = num_x_loop; - args[12] = partials; + args[10] = work_dim_arg; + args[11] = thread_data_ptr; + args[12] = num_x_loop; + args[13] = partials; /* idx = (z * (size_x * size_y) + y * size_x + x */ LLVMValueRef coro_hdl_idx = LLVMBuildMul(gallivm->builder, loop_state[2].counter, @@ -226,7 +231,7 @@ generate_compute(struct llvmpipe_context *lp, lp_build_const_int32(gallivm, 0), ""); /* first time here - call the coroutine function entry point */ lp_build_if(&ifstate, gallivm, cmp); - LLVMValueRef coro_ret = LLVMBuildCall(gallivm->builder, coro, args, 13, ""); + LLVMValueRef coro_ret = LLVMBuildCall(gallivm->builder, coro, args, 14, ""); LLVMBuildStore(gallivm->builder, coro_ret, coro_entry); lp_build_else(&ifstate); /* subsequent calls for this invocation - check if done. */ @@ -268,9 +273,10 @@ generate_compute(struct llvmpipe_context *lp, grid_size_x_arg = LLVMGetParam(coro, 7); grid_size_y_arg = LLVMGetParam(coro, 8); grid_size_z_arg = LLVMGetParam(coro, 9); - thread_data_ptr = LLVMGetParam(coro, 10); - num_x_loop = LLVMGetParam(coro, 11); - partials = LLVMGetParam(coro, 12); + work_dim_arg = LLVMGetParam(coro, 10); + thread_data_ptr = LLVMGetParam(coro, 11); + num_x_loop = LLVMGetParam(coro, 12); + partials = LLVMGetParam(coro, 13); block = LLVMAppendBasicBlockInContext(gallivm->context, coro, "entry"); LLVMPositionBuilderAtEnd(builder, block); { @@ -320,6 +326,8 @@ generate_compute(struct llvmpipe_context *lp, for (i = 0; i < 3; i++) system_values.grid_size = LLVMBuildInsertElement(builder, system_values.grid_size, gstids[i], lp_build_const_int32(gallivm, i), ""); + system_values.work_dim = work_dim_arg; + LLVMValueRef last_x_loop = LLVMBuildICmp(gallivm->builder, LLVMIntEQ, x_size_arg, LLVMBuildSub(gallivm->builder, num_x_loop, lp_build_const_int32(gallivm, 1), ""), ""); LLVMValueRef use_partial_mask = LLVMBuildAnd(gallivm->builder, last_x_loop, has_partials, ""); struct lp_build_if_state if_state; @@ -1162,7 +1170,7 @@ cs_exec_fn(void *init_data, int iter_idx, struct lp_cs_local_mem *lmem) variant->jit_function(&job_info->current->jit_context, job_info->block_size[0], job_info->block_size[1], job_info->block_size[2], grid_x, grid_y, grid_z, - job_info->grid_size[0], job_info->grid_size[1], job_info->grid_size[2], + job_info->grid_size[0], job_info->grid_size[1], job_info->grid_size[2], job_info->work_dim, &thread_data); } @@ -1210,6 +1218,7 @@ static void llvmpipe_launch_grid(struct pipe_context *pipe, job_info.block_size[0] = info->block[0]; job_info.block_size[1] = info->block[1]; job_info.block_size[2] = info->block[2]; + job_info.work_dim = info->work_dim; job_info.req_local_mem = llvmpipe->cs->req_local_mem; job_info.current = &llvmpipe->csctx->cs.current; -- 2.30.2