compiler: add SYSTEM_VALUE_USER_DATA_AMD
authorMarek Olšák <marek.olsak@amd.com>
Thu, 1 Aug 2019 01:52:48 +0000 (21:52 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 12 Aug 2019 18:52:17 +0000 (14:52 -0400)
for internal radeonsi shaders

src/amd/common/ac_nir_to_llvm.c
src/amd/common/ac_shader_abi.h
src/compiler/nir/nir.c
src/compiler/nir/nir_intrinsics.py
src/compiler/shader_enums.h
src/gallium/auxiliary/nir/tgsi_to_nir.c
src/gallium/drivers/radeonsi/si_shader_nir.c

index 440d4ec9e5ebaee7fdfcd68924ad79babe2742b6..219aa5f95f00180e879357fa149e5adad33946bd 100644 (file)
@@ -3313,6 +3313,10 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
        case nir_intrinsic_load_color1:
                result = ctx->abi->color1;
                break;
+       case nir_intrinsic_load_user_data_amd:
+               assert(LLVMTypeOf(ctx->abi->user_data) == ctx->ac.v4i32);
+               result = ctx->abi->user_data;
+               break;
        case nir_intrinsic_load_instance_id:
                result = ctx->abi->instance_id;
                break;
index 3033ae0cac2a2778339a52a80c64f1645f9f8011..3a2b53223850ab0baea5c8d0d099453add8182c6 100644 (file)
@@ -65,6 +65,7 @@ struct ac_shader_abi {
        LLVMValueRef prim_mask;
        LLVMValueRef color0;
        LLVMValueRef color1;
+       LLVMValueRef user_data;
        /* CS */
        LLVMValueRef local_invocation_ids;
        LLVMValueRef num_work_groups;
index 822c6ab5d2763ccb7dce82fb1dfa99472cd20d79..1e6f15517f5342af5ab0d6bf0534ee456245fc4b 100644 (file)
@@ -2022,6 +2022,8 @@ nir_intrinsic_from_system_value(gl_system_value val)
       return nir_intrinsic_load_global_invocation_index;
    case SYSTEM_VALUE_WORK_DIM:
       return nir_intrinsic_load_work_dim;
+   case SYSTEM_VALUE_USER_DATA_AMD:
+      return nir_intrinsic_load_user_data_amd;
    default:
       unreachable("system value does not directly correspond to intrinsic");
    }
@@ -2109,6 +2111,8 @@ nir_system_value_from_intrinsic(nir_intrinsic_op intrin)
       return SYSTEM_VALUE_LOCAL_GROUP_SIZE;
    case nir_intrinsic_load_global_invocation_id:
       return SYSTEM_VALUE_GLOBAL_INVOCATION_ID;
+   case nir_intrinsic_load_user_data_amd:
+      return SYSTEM_VALUE_USER_DATA_AMD;
    default:
       unreachable("intrinsic doesn't produce a system value");
    }
index cbbf8fba89e1fc7fb3d1228ca6b2f2333776612c..f4ca623bb3d1dc1434c6363e4275f7e7e7269822 100644 (file)
@@ -614,6 +614,9 @@ system_value("blend_const_color_aaaa8888_unorm", 1)
 system_value("color0", 4)
 system_value("color1", 4)
 
+# System value for internal compute shaders in radeonsi.
+system_value("user_data_amd", 4)
+
 # Barycentric coordinate intrinsics.
 #
 # These set up the barycentric coordinates for a particular interpolation.
index d9eb290abf429a47a5757fbe5603ef96be09ee5d..20e62da5b11d220aee369a1ddc32c44a2657b1be 100644 (file)
@@ -609,6 +609,7 @@ typedef enum
    SYSTEM_VALUE_LOCAL_GROUP_SIZE,
    SYSTEM_VALUE_GLOBAL_GROUP_SIZE,
    SYSTEM_VALUE_WORK_DIM,
+   SYSTEM_VALUE_USER_DATA_AMD,
    /*@}*/
 
    /** Required for VK_KHR_device_group */
index a23ed4d685fccd76003174c875565d8d7ccf180d..0a2348084285ee6d9201e0cb5cb48df0df82bcff 100644 (file)
@@ -628,6 +628,10 @@ ttn_src_for_file_and_index(struct ttn_compile *c, unsigned file, unsigned index,
          op = nir_intrinsic_load_work_group_id;
          load = nir_load_work_group_id(b);
          break;
+      case TGSI_SEMANTIC_CS_USER_DATA_AMD:
+         op = nir_intrinsic_load_user_data_amd;
+         load = nir_load_user_data_amd(b);
+         break;
       default:
          unreachable("bad system value");
       }
index 524af0e0a193066d879985b9f29ee654bf31adc5..0aa17e7a37c465a61134cbd2392dc6ed7765d527 100644 (file)
@@ -1240,6 +1240,12 @@ bool si_nir_build_llvm(struct si_shader_context *ctx, struct nir_shader *nir)
 
                ctx->abi.interp_at_sample_force_center =
                        ctx->shader->key.mono.u.ps.interpolate_at_sample_force_center;
+       } else if (nir->info.stage == MESA_SHADER_COMPUTE) {
+               if (nir->info.cs.user_data_components_amd) {
+                       ctx->abi.user_data = LLVMGetParam(ctx->main_fn, ctx->param_cs_user_data);
+                       ctx->abi.user_data = ac_build_expand_to_vec4(&ctx->ac, ctx->abi.user_data,
+                                                                    nir->info.cs.user_data_components_amd);
+               }
        }
 
        ctx->abi.inputs = &ctx->inputs[0];