spirv2dxil: Support dispatches with base group indices
authorJesse Natalie <jenatali@microsoft.com>
Wed, 11 Jan 2023 23:09:33 +0000 (15:09 -0800)
committerMarge Bot <emma+marge@anholt.net>
Tue, 24 Jan 2023 17:22:25 +0000 (17:22 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20823>

src/microsoft/spirv_to_dxil/dxil_spirv_nir.c
src/microsoft/spirv_to_dxil/spirv_to_dxil.h

index eed5b34..d98062e 100644 (file)
@@ -140,6 +140,10 @@ lower_shader_system_values(struct nir_builder *builder, nir_instr *instr,
       offset =
          offsetof(struct dxil_spirv_compute_runtime_data, group_count_x);
       break;
+   case nir_intrinsic_load_base_workgroup_id:
+      offset =
+         offsetof(struct dxil_spirv_compute_runtime_data, base_group_x);
+      break;
    case nir_intrinsic_load_first_vertex:
       offset = offsetof(struct dxil_spirv_vertex_runtime_data, first_vertex);
       break;
@@ -866,6 +870,10 @@ dxil_spirv_nir_passes(nir_shader *nir,
 
    NIR_PASS_V(nir, nir_lower_system_values);
 
+   nir_lower_compute_system_values_options compute_options = {
+      .has_base_workgroup_id = !conf->zero_based_compute_workgroup_id,
+   };
+   NIR_PASS_V(nir, nir_lower_compute_system_values, &compute_options);
    NIR_PASS_V(nir, dxil_nir_lower_subgroup_id);
    NIR_PASS_V(nir, dxil_nir_lower_num_subgroups);
 
index a95bffa..8b487fa 100644 (file)
@@ -90,6 +90,11 @@ struct dxil_spirv_compute_runtime_data {
    uint32_t group_count_x;
    uint32_t group_count_y;
    uint32_t group_count_z;
+   uint32_t padding0;
+   /* Base */
+   uint32_t base_group_x;
+   uint32_t base_group_y;
+   uint32_t base_group_z;
 };
 
 #define DXIL_SPIRV_Y_FLIP_MASK BITFIELD_MASK(DXIL_SPIRV_MAX_VIEWPORT)
@@ -146,6 +151,8 @@ struct dxil_spirv_runtime_conf {
    // Set true if vertex and instance ids have already been converted to
    // zero-based. Otherwise, runtime_data will be required to lower them.
    bool zero_based_vertex_instance_id;
+   // Set true if workgroup base is known to be zero
+   bool zero_based_compute_workgroup_id;
 
    struct {
       // mode != DXIL_SPIRV_YZ_FLIP_NONE only valid on vertex/geometry stages.