spirv: handle UniformConstant for OpenCL kernels

The caller is responsible for setting up the ubo_addr_format value as
contrary to shared and global, it's not controlled by the spirv.

Right now clovers implementation of CL constant memory uses a 24/8 bit format
to encode the buffer index and offset, but that code is dead as all backends
treat constants as global memory to workaround annoying issues within OpenCL.

Maybe that will change, maybe not. But just in case somebody wants to look at
it, add a toggle for this inside vtn.

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Karol Herbst 2019-12-05 11:37:34 +01:00 committed by Karol Herbst
parent 123f90cf36
commit 2402232c90
3 changed files with 19 additions and 2 deletions

View File

@ -83,6 +83,12 @@ struct spirv_to_nir_options {
nir_address_format global_addr_format;
nir_address_format temp_addr_format;
/* Whether UniformConstant memory should be treated as normal global memory.
* This is usefull for CL 2.0 implementations with fine grain system SVM
* support.
*/
bool constant_as_global;
struct {
void (*func)(void *private_data,
enum nir_spirv_debug_level level,

View File

@ -1351,6 +1351,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
case SpvStorageClassFunction:
case SpvStorageClassWorkgroup:
case SpvStorageClassCrossWorkgroup:
case SpvStorageClassUniformConstant:
val->type->stride = align(glsl_get_cl_size(val->type->deref->type),
glsl_get_cl_alignment(val->type->deref->type));
break;

View File

@ -1816,8 +1816,18 @@ vtn_storage_class_to_mode(struct vtn_builder *b,
nir_mode = nir_var_mem_global;
break;
case SpvStorageClassUniformConstant:
mode = vtn_variable_mode_uniform;
nir_mode = nir_var_uniform;
if (b->shader->info.stage == MESA_SHADER_KERNEL) {
if (b->options->constant_as_global) {
mode = vtn_variable_mode_cross_workgroup;
nir_mode = nir_var_mem_global;
} else {
mode = vtn_variable_mode_ubo;
nir_mode = nir_var_mem_ubo;
}
} else {
mode = vtn_variable_mode_uniform;
nir_mode = nir_var_uniform;
}
break;
case SpvStorageClassPushConstant:
mode = vtn_variable_mode_push_constant;