i965: Implement ARB_compute_variable_group_size
[mesa.git] / src / mesa / drivers / dri / i965 / brw_cs.c
index cf9340f15b6aaf15cab18ffaada0f7fbe578d2f5..5b4ff456a0dc92d98b94853d3c271249d06abcd2 100644 (file)
 #include "brw_program.h"
 #include "compiler/glsl/ir_uniform.h"
 
+uint32_t
+brw_cs_group_size(const struct brw_context *brw)
+{
+   assert(brw->cs.base.prog_data);
+   struct brw_cs_prog_data *cs_prog_data =
+      brw_cs_prog_data(brw->cs.base.prog_data);
+
+   if (brw->compute.group_size) {
+      /* With ARB_compute_variable_group_size the group size is set at
+       * dispatch time, so we can't use the one provided by the compiler.
+       */
+      return brw->compute.group_size[0] *
+             brw->compute.group_size[1] *
+             brw->compute.group_size[2];
+   } else {
+      return cs_prog_data->local_size[0] *
+             cs_prog_data->local_size[1] *
+             cs_prog_data->local_size[2];
+   }
+}
+
 static void
 assign_cs_binding_table_offsets(const struct gen_device_info *devinfo,
                                 const struct gl_program *prog,
@@ -58,6 +79,7 @@ brw_codegen_cs_prog(struct brw_context *brw,
    struct brw_cs_prog_data prog_data;
    bool start_busy = false;
    double start_time = 0;
+   struct gl_context *gl_ctx = &brw->ctx;
    nir_shader *nir = nir_shader_clone(mem_ctx, cp->program.nir);
 
    memset(&prog_data, 0, sizeof(prog_data));
@@ -88,6 +110,17 @@ brw_codegen_cs_prog(struct brw_context *brw,
    if (INTEL_DEBUG & DEBUG_SHADER_TIME)
       st_index = brw_get_shader_time_index(brw, &cp->program, ST_CS, true);
 
+   /* If the work group size is variable we set it to the maximum here since
+    * the actual size is not known until the dispatch command is issued.
+    */
+   if (nir->info.cs.local_size_variable) {
+      prog_data.uses_variable_group_size = true;
+      nir->info.cs.max_variable_local_size =
+         gl_ctx->Const.MaxComputeWorkGroupSize[2];
+   } else {
+      prog_data.uses_variable_group_size = false;
+   }
+
    char *error_str;
    program = brw_compile_cs(brw->screen->compiler, brw, mem_ctx, key,
                             &prog_data, nir, st_index, NULL, &error_str);