spirv: handle UniformConstant for OpenCL kernels
authorKarol Herbst <kherbst@redhat.com>
Thu, 5 Dec 2019 10:37:34 +0000 (11:37 +0100)
committerKarol Herbst <karolherbst@gmail.com>
Wed, 11 Dec 2019 23:54:39 +0000 (23:54 +0000)
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>
src/compiler/spirv/nir_spirv.h
src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_variables.c

index d5978a81bb4104eb0d1a8e2fd49ebf5d39c6aa8c..81175ebf022365120718cbce23d46e609a9d1f58 100644 (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,
index 0c1813b139dce9df0f258e0f4f1eec0414f61812..aff11a2d57933a1f62a8ec9b69a2116f5f07605c 100644 (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;
index 755d85642a0afcce543748ec71ebbf35f002f892..d7edabb5656dec3b264353cb447a56c5bde6a9de 100644 (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;