Bladeren bron

gallivm/llvmpipe: add support for block size intrinsic

We have to pass the main block size into the coroutine
and into the shader.

Acked-by: Roland Scheidegger <sroland@vmware.com>
master
Dave Airlie 7 jaren geleden
bovenliggende
commit
9630c2ddd8

+ 1
- 0
src/gallium/auxiliary/gallivm/lp_bld_nir.c Bestand weergeven

case nir_intrinsic_load_invocation_id: case nir_intrinsic_load_invocation_id:
case nir_intrinsic_load_front_face: case nir_intrinsic_load_front_face:
case nir_intrinsic_load_draw_id: case nir_intrinsic_load_draw_id:
case nir_intrinsic_load_local_group_size:
case nir_intrinsic_load_work_dim: case nir_intrinsic_load_work_dim:
bld_base->sysval_intrin(bld_base, instr, result); bld_base->sysval_intrin(bld_base, instr, result);
break; break;

+ 4
- 0
src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c Bestand weergeven

break; break;
default: default:
break; break;
case nir_intrinsic_load_local_group_size:
for (unsigned i = 0; i < 3; i++)
result[i] = lp_build_broadcast_scalar(&bld_base->uint_bld, LLVMBuildExtractElement(gallivm->builder, bld->system_values.block_size, lp_build_const_int32(gallivm, i), ""));
break;
case nir_intrinsic_load_work_dim: case nir_intrinsic_load_work_dim:
result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.work_dim); result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.work_dim);
break; break;

+ 1
- 0
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h Bestand weergeven

LLVMValueRef grid_size; LLVMValueRef grid_size;
LLVMValueRef front_facing; LLVMValueRef front_facing;
LLVMValueRef work_dim; LLVMValueRef work_dim;
LLVMValueRef block_size;
}; };





+ 18
- 3
src/gallium/drivers/llvmpipe/lp_state_cs.c Bestand weergeven

struct gallivm_state *gallivm = variant->gallivm; struct gallivm_state *gallivm = variant->gallivm;
const struct lp_compute_shader_variant_key *key = &variant->key; const struct lp_compute_shader_variant_key *key = &variant->key;
char func_name[64], func_name_coro[64]; char func_name[64], func_name_coro[64];
LLVMTypeRef arg_types[14];
LLVMTypeRef arg_types[17];
LLVMTypeRef func_type, coro_func_type; LLVMTypeRef func_type, coro_func_type;
LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context); LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef context_ptr; LLVMValueRef context_ptr;
arg_types[11] = variant->jit_cs_thread_data_ptr_type; /* per thread data */ 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[12] = int32_type; /* coro only - num X loops */
arg_types[13] = int32_type; /* coro only - partials */ arg_types[13] = int32_type; /* coro only - partials */
arg_types[14] = int32_type; /* coro block_x_size */
arg_types[15] = int32_type; /* coro block_y_size */
arg_types[16] = int32_type; /* coro block_z_size */
func_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context), func_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context),
arg_types, ARRAY_SIZE(arg_types) - 5, 0); arg_types, ARRAY_SIZE(arg_types) - 5, 0);


lp_build_loop_begin(&loop_state[0], gallivm, lp_build_loop_begin(&loop_state[0], gallivm,
lp_build_const_int32(gallivm, 0)); /* x loop */ lp_build_const_int32(gallivm, 0)); /* x loop */
{ {
LLVMValueRef args[14];
LLVMValueRef args[17];
args[0] = context_ptr; args[0] = context_ptr;
args[1] = loop_state[0].counter; args[1] = loop_state[0].counter;
args[2] = loop_state[1].counter; args[2] = loop_state[1].counter;
args[11] = thread_data_ptr; args[11] = thread_data_ptr;
args[12] = num_x_loop; args[12] = num_x_loop;
args[13] = partials; args[13] = partials;
args[14] = x_size_arg;
args[15] = y_size_arg;
args[16] = z_size_arg;


/* idx = (z * (size_x * size_y) + y * size_x + x */ /* idx = (z * (size_x * size_y) + y * size_x + x */
LLVMValueRef coro_hdl_idx = LLVMBuildMul(gallivm->builder, loop_state[2].counter, LLVMValueRef coro_hdl_idx = LLVMBuildMul(gallivm->builder, loop_state[2].counter,
lp_build_const_int32(gallivm, 0), ""); lp_build_const_int32(gallivm, 0), "");
/* first time here - call the coroutine function entry point */ /* first time here - call the coroutine function entry point */
lp_build_if(&ifstate, gallivm, cmp); lp_build_if(&ifstate, gallivm, cmp);
LLVMValueRef coro_ret = LLVMBuildCall(gallivm->builder, coro, args, 14, "");
LLVMValueRef coro_ret = LLVMBuildCall(gallivm->builder, coro, args, 17, "");
LLVMBuildStore(gallivm->builder, coro_ret, coro_entry); LLVMBuildStore(gallivm->builder, coro_ret, coro_entry);
lp_build_else(&ifstate); lp_build_else(&ifstate);
/* subsequent calls for this invocation - check if done. */ /* subsequent calls for this invocation - check if done. */
LLVMBuildRetVoid(builder); LLVMBuildRetVoid(builder);


/* This is stage (b) - generate the compute shader code inside the coroutine. */ /* This is stage (b) - generate the compute shader code inside the coroutine. */
LLVMValueRef block_x_size_arg, block_y_size_arg, block_z_size_arg;
context_ptr = LLVMGetParam(coro, 0); context_ptr = LLVMGetParam(coro, 0);
x_size_arg = LLVMGetParam(coro, 1); x_size_arg = LLVMGetParam(coro, 1);
y_size_arg = LLVMGetParam(coro, 2); y_size_arg = LLVMGetParam(coro, 2);
thread_data_ptr = LLVMGetParam(coro, 11); thread_data_ptr = LLVMGetParam(coro, 11);
num_x_loop = LLVMGetParam(coro, 12); num_x_loop = LLVMGetParam(coro, 12);
partials = LLVMGetParam(coro, 13); partials = LLVMGetParam(coro, 13);
block_x_size_arg = LLVMGetParam(coro, 14);
block_y_size_arg = LLVMGetParam(coro, 15);
block_z_size_arg = LLVMGetParam(coro, 16);
block = LLVMAppendBasicBlockInContext(gallivm->context, coro, "entry"); block = LLVMAppendBasicBlockInContext(gallivm->context, coro, "entry");
LLVMPositionBuilderAtEnd(builder, block); LLVMPositionBuilderAtEnd(builder, block);
{ {


system_values.work_dim = work_dim_arg; system_values.work_dim = work_dim_arg;


LLVMValueRef bsize[3] = { block_x_size_arg, block_y_size_arg, block_z_size_arg };
system_values.block_size = LLVMGetUndef(LLVMVectorType(int32_type, 3));
for (i = 0; i < 3; i++)
system_values.block_size = LLVMBuildInsertElement(builder, system_values.block_size, bsize[i], lp_build_const_int32(gallivm, i), "");

LLVMValueRef last_x_loop = LLVMBuildICmp(gallivm->builder, LLVMIntEQ, x_size_arg, LLVMBuildSub(gallivm->builder, num_x_loop, lp_build_const_int32(gallivm, 1), ""), ""); 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, ""); LLVMValueRef use_partial_mask = LLVMBuildAnd(gallivm->builder, last_x_loop, has_partials, "");
struct lp_build_if_state if_state; struct lp_build_if_state if_state;

Laden…
Annuleren
Opslaan