Parcourir la source

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 <sroland@vmware.com>
master
Dave Airlie il y a 7 ans
Parent
révision
336954f7e7

+ 1
- 0
src/gallium/auxiliary/gallivm/lp_bld_nir.c Voir le fichier

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_work_dim:
bld_base->sysval_intrin(bld_base, instr, result); bld_base->sysval_intrin(bld_base, instr, result);
break; break;
case nir_intrinsic_discard_if: case nir_intrinsic_discard_if:

+ 3
- 0
src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c Voir le fichier

break; break;
default: default:
break; break;
case nir_intrinsic_load_work_dim:
result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.work_dim);
break;
} }
} }



+ 1
- 0
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h Voir le fichier

LLVMValueRef block_id; LLVMValueRef block_id;
LLVMValueRef grid_size; LLVMValueRef grid_size;
LLVMValueRef front_facing; LLVMValueRef front_facing;
LLVMValueRef work_dim;
}; };





+ 1
- 0
src/gallium/drivers/llvmpipe/lp_jit.h Voir le fichier

uint32_t grid_size_x, uint32_t grid_size_x,
uint32_t grid_size_y, uint32_t grid_size_y,
uint32_t grid_size_z, uint32_t grid_size_z,
uint32_t work_dim,
struct lp_jit_cs_thread_data *thread_data); struct lp_jit_cs_thread_data *thread_data);


void void

+ 25
- 16
src/gallium/drivers/llvmpipe/lp_state_cs.c Voir le fichier

unsigned grid_size[3]; unsigned grid_size[3];
unsigned block_size[3]; unsigned block_size[3];
unsigned req_local_mem; unsigned req_local_mem;
unsigned work_dim;
struct lp_cs_exec *current; struct lp_cs_exec *current;
}; };


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[13];
LLVMTypeRef arg_types[14];
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;
LLVMValueRef x_size_arg, y_size_arg, z_size_arg; LLVMValueRef x_size_arg, y_size_arg, z_size_arg;
LLVMValueRef grid_x_arg, grid_y_arg, grid_z_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 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; LLVMBasicBlockRef block;
LLVMBuilderRef builder; LLVMBuilderRef builder;
struct lp_build_sampler_soa *sampler; struct lp_build_sampler_soa *sampler;
arg_types[7] = int32_type; /* grid_size_x */ arg_types[7] = int32_type; /* grid_size_x */
arg_types[8] = int32_type; /* grid_size_y */ arg_types[8] = int32_type; /* grid_size_y */
arg_types[9] = int32_type; /* grid_size_z */ 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), 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), coro_func_type = LLVMFunctionType(LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0),
arg_types, ARRAY_SIZE(arg_types), 0); arg_types, ARRAY_SIZE(arg_types), 0);
grid_size_x_arg = LLVMGetParam(function, 7); grid_size_x_arg = LLVMGetParam(function, 7);
grid_size_y_arg = LLVMGetParam(function, 8); grid_size_y_arg = LLVMGetParam(function, 8);
grid_size_z_arg = LLVMGetParam(function, 9); 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(context_ptr, "context");
lp_build_name(x_size_arg, "x_size"); lp_build_name(x_size_arg, "x_size");
lp_build_name(grid_size_x_arg, "grid_size_x"); 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_y_arg, "grid_size_y");
lp_build_name(grid_size_z_arg, "grid_size_z"); 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"); lp_build_name(thread_data_ptr, "thread_data");


block = LLVMAppendBasicBlockInContext(gallivm->context, function, "entry"); block = LLVMAppendBasicBlockInContext(gallivm->context, function, "entry");
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[13];
LLVMValueRef args[14];
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[7] = grid_size_x_arg; args[7] = grid_size_x_arg;
args[8] = grid_size_y_arg; args[8] = grid_size_y_arg;
args[9] = grid_size_z_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 */ /* 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, 13, "");
LLVMValueRef coro_ret = LLVMBuildCall(gallivm->builder, coro, args, 14, "");
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. */
grid_size_x_arg = LLVMGetParam(coro, 7); grid_size_x_arg = LLVMGetParam(coro, 7);
grid_size_y_arg = LLVMGetParam(coro, 8); grid_size_y_arg = LLVMGetParam(coro, 8);
grid_size_z_arg = LLVMGetParam(coro, 9); 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"); block = LLVMAppendBasicBlockInContext(gallivm->context, coro, "entry");
LLVMPositionBuilderAtEnd(builder, block); LLVMPositionBuilderAtEnd(builder, block);
{ {
for (i = 0; i < 3; i++) 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.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 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;
variant->jit_function(&job_info->current->jit_context, variant->jit_function(&job_info->current->jit_context,
job_info->block_size[0], job_info->block_size[1], job_info->block_size[2], job_info->block_size[0], job_info->block_size[1], job_info->block_size[2],
grid_x, grid_y, grid_z, 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); &thread_data);
} }


job_info.block_size[0] = info->block[0]; job_info.block_size[0] = info->block[0];
job_info.block_size[1] = info->block[1]; job_info.block_size[1] = info->block[1];
job_info.block_size[2] = info->block[2]; 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.req_local_mem = llvmpipe->cs->req_local_mem;
job_info.current = &llvmpipe->csctx->cs.current; job_info.current = &llvmpipe->csctx->cs.current;



Chargement…
Annuler
Enregistrer