[Mesa-dev] [PATCH 01/12] mesa: add MESA_SHADER_KERNEL

Karol Herbst kherbst at redhat.com
Tue Dec 4 18:26:39 UTC 2018


used for CL kernels

Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
 src/amd/common/ac_nir_to_llvm.c                |  4 ++--
 src/compiler/nir/nir.c                         |  2 +-
 src/compiler/nir/nir_print.c                   |  7 ++-----
 src/compiler/shader_enums.c                    |  5 ++++-
 src/compiler/shader_enums.h                    | 18 ++++++++++++++++++
 src/compiler/spirv/spirv_to_nir.c              |  2 +-
 src/freedreno/ir3/ir3_compiler_nir.c           |  3 ++-
 src/gallium/drivers/freedreno/a6xx/fd6_emit.c  |  1 +
 src/gallium/drivers/freedreno/a6xx/fd6_emit.h  |  1 +
 .../drivers/freedreno/a6xx/fd6_program.c       |  1 +
 src/gallium/drivers/freedreno/freedreno_util.h |  1 +
 .../drivers/freedreno/ir3/ir3_cmdline.c        |  1 +
 .../drivers/freedreno/ir3/ir3_gallium.c        |  2 +-
 src/gallium/drivers/radeonsi/si_shader_nir.c   |  4 ++--
 src/mesa/main/shaderobj.h                      |  6 ++++++
 15 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index a109f5a8156..18e9b69f3c0 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -4012,13 +4012,13 @@ void ac_nir_translate(struct ac_llvm_context *ac, struct ac_shader_abi *abi,
 
 	setup_locals(&ctx, func);
 
-	if (nir->info.stage == MESA_SHADER_COMPUTE)
+	if (gl_shader_stage_is_compute(nir->info.stage))
 		setup_shared(&ctx, nir);
 
 	visit_cf_list(&ctx, &func->impl->body);
 	phi_post_pass(&ctx);
 
-	if (nir->info.stage != MESA_SHADER_COMPUTE)
+	if (!gl_shader_stage_is_compute(nir->info.stage))
 		ctx.abi->emit_outputs(ctx.abi, AC_LLVM_MAX_OUTPUTS,
 				      ctx.abi->outputs);
 
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 249b9357c3f..03199856cc2 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -147,7 +147,7 @@ nir_shader_add_variable(nir_shader *shader, nir_variable *var)
       break;
 
    case nir_var_shared:
-      assert(shader->info.stage == MESA_SHADER_COMPUTE);
+      assert(gl_shader_stage_is_compute(shader->info.stage));
       exec_list_push_tail(&shader->shared, &var->node);
       break;
 
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index 7124ff09e82..b8549f56eb8 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -472,6 +472,7 @@ print_var_decl(nir_variable *var, print_state *state)
       case MESA_SHADER_TESS_CTRL:
       case MESA_SHADER_TESS_EVAL:
       case MESA_SHADER_COMPUTE:
+      case MESA_SHADER_KERNEL:
       default:
          /* TODO */
          break;
@@ -1255,17 +1256,13 @@ nir_print_shader_annotated(nir_shader *shader, FILE *fp,
    if (shader->info.label)
       fprintf(fp, "label: %s\n", shader->info.label);
 
-   switch (shader->info.stage) {
-   case MESA_SHADER_COMPUTE:
+   if (gl_shader_stage_is_compute(shader->info.stage)) {
       fprintf(fp, "local-size: %u, %u, %u%s\n",
               shader->info.cs.local_size[0],
               shader->info.cs.local_size[1],
               shader->info.cs.local_size[2],
               shader->info.cs.local_size_variable ? " (variable)" : "");
       fprintf(fp, "shared-size: %u\n", shader->info.cs.shared_size);
-      break;
-   default:
-      break;
    }
 
    fprintf(fp, "inputs: %u\n", shader->num_inputs);
diff --git a/src/compiler/shader_enums.c b/src/compiler/shader_enums.c
index 0210b503d3f..15ab6d81dae 100644
--- a/src/compiler/shader_enums.c
+++ b/src/compiler/shader_enums.c
@@ -43,8 +43,9 @@ gl_shader_stage_name(gl_shader_stage stage)
       ENUM(MESA_SHADER_GEOMETRY),
       ENUM(MESA_SHADER_FRAGMENT),
       ENUM(MESA_SHADER_COMPUTE),
+      ENUM(MESA_SHADER_KERNEL),
    };
-   STATIC_ASSERT(ARRAY_SIZE(names) == MESA_SHADER_STAGES);
+   STATIC_ASSERT(ARRAY_SIZE(names) == MESA_ALL_SHADER_STAGES);
    return NAME(stage);
 }
 
@@ -60,6 +61,7 @@ _mesa_shader_stage_to_string(unsigned stage)
    case MESA_SHADER_FRAGMENT: return "fragment";
    case MESA_SHADER_GEOMETRY: return "geometry";
    case MESA_SHADER_COMPUTE:  return "compute";
+   case MESA_SHADER_KERNEL:   return "kernel";
    case MESA_SHADER_TESS_CTRL: return "tessellation control";
    case MESA_SHADER_TESS_EVAL: return "tessellation evaluation";
    }
@@ -79,6 +81,7 @@ _mesa_shader_stage_to_abbrev(unsigned stage)
    case MESA_SHADER_FRAGMENT: return "FS";
    case MESA_SHADER_GEOMETRY: return "GS";
    case MESA_SHADER_COMPUTE:  return "CS";
+   case MESA_SHADER_KERNEL:   return "CL";
    case MESA_SHADER_TESS_CTRL: return "TCS";
    case MESA_SHADER_TESS_EVAL: return "TES";
    }
diff --git a/src/compiler/shader_enums.h b/src/compiler/shader_enums.h
index f023b48cbb3..1dff01484b5 100644
--- a/src/compiler/shader_enums.h
+++ b/src/compiler/shader_enums.h
@@ -26,6 +26,8 @@
 #ifndef SHADER_ENUMS_H
 #define SHADER_ENUMS_H
 
+#include <stdbool.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -46,8 +48,16 @@ typedef enum
    MESA_SHADER_GEOMETRY = 3,
    MESA_SHADER_FRAGMENT = 4,
    MESA_SHADER_COMPUTE = 5,
+   /* must be last so it doesn't affect the GL pipeline */
+   MESA_SHADER_KERNEL = 6,
 } gl_shader_stage;
 
+static inline bool
+gl_shader_stage_is_compute(gl_shader_stage stage)
+{
+   return stage == MESA_SHADER_COMPUTE || stage == MESA_SHADER_KERNEL;
+}
+
 /**
  * Number of STATE_* values we need to address any GL state.
  * Used to dimension arrays.
@@ -70,8 +80,16 @@ const char *_mesa_shader_stage_to_string(unsigned stage);
  */
 const char *_mesa_shader_stage_to_abbrev(unsigned stage);
 
+/**
+ * GL related stages (not including CL)
+ */
 #define MESA_SHADER_STAGES (MESA_SHADER_COMPUTE + 1)
 
+/**
+ * All stages
+ */
+#define MESA_ALL_SHADER_STAGES (MESA_SHADER_KERNEL + 1)
+
 
 /**
  * Indexes for vertex program attributes.
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index a05c4d236ca..f6a7cd6c4fd 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -3654,7 +3654,7 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,
       break;
 
    case SpvExecutionModeLocalSize:
-      vtn_assert(b->shader->info.stage == MESA_SHADER_COMPUTE);
+      vtn_assert(gl_shader_stage_is_compute(b->shader->info.stage));
       b->shader->info.cs.local_size[0] = mode->literals[0];
       b->shader->info.cs.local_size[1] = mode->literals[1];
       b->shader->info.cs.local_size[2] = mode->literals[2];
diff --git a/src/freedreno/ir3/ir3_compiler_nir.c b/src/freedreno/ir3/ir3_compiler_nir.c
index 445a2b291e9..fd7b21e2f14 100644
--- a/src/freedreno/ir3/ir3_compiler_nir.c
+++ b/src/freedreno/ir3/ir3_compiler_nir.c
@@ -243,7 +243,7 @@ compile_init(struct ir3_compiler *compiler,
 	unsigned num_driver_params = 0;
 	if (so->type == MESA_SHADER_VERTEX) {
 		num_driver_params = IR3_DP_VS_COUNT;
-	} else if (so->type == MESA_SHADER_COMPUTE) {
+	} else if (gl_shader_stage_is_compute(so->type)) {
 		num_driver_params = IR3_DP_CS_COUNT;
 	}
 
@@ -3449,6 +3449,7 @@ static const unsigned max_sysvals[] = {
 	[MESA_SHADER_FRAGMENT] = 24,  // TODO
 	[MESA_SHADER_VERTEX]  = 16,
 	[MESA_SHADER_COMPUTE] = 16, // TODO how many do we actually need?
+	[MESA_SHADER_KERNEL]  = 16, // TODO how many do we actually need?
 };
 
 static void
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_emit.c b/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
index 70b93340e77..b87bb2d5b04 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
@@ -56,6 +56,7 @@ shader_t_to_opcode(gl_shader_stage type)
 		return CP_LOAD_STATE6_GEOM;
 	case MESA_SHADER_FRAGMENT:
 	case MESA_SHADER_COMPUTE:
+	case MESA_SHADER_KERNEL:
 		return CP_LOAD_STATE6_FRAG;
 	default:
 		unreachable("bad shader type");
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_emit.h b/src/gallium/drivers/freedreno/a6xx/fd6_emit.h
index 289e4877418..9e578844741 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_emit.h
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_emit.h
@@ -163,6 +163,7 @@ fd6_stage2shadersb(gl_shader_stage type)
 	case MESA_SHADER_FRAGMENT:
 		return SB6_FS_SHADER;
 	case MESA_SHADER_COMPUTE:
+	case MESA_SHADER_KERNEL:
 		return SB6_CS_SHADER;
 	default:
 		unreachable("bad shader type");
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_program.c b/src/gallium/drivers/freedreno/a6xx/fd6_program.c
index 71dadef97e2..b59f466016d 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_program.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_program.c
@@ -105,6 +105,7 @@ fd6_emit_shader(struct fd_ringbuffer *ring, const struct ir3_shader_variant *so)
 		break;
 	case MESA_SHADER_FRAGMENT:
 	case MESA_SHADER_COMPUTE:
+	case MESA_SHADER_KERNEL:
 		opcode = CP_LOAD_STATE6_FRAG;
 		break;
 	default:
diff --git a/src/gallium/drivers/freedreno/freedreno_util.h b/src/gallium/drivers/freedreno/freedreno_util.h
index b0ed3fa8e4f..44097f2fc73 100644
--- a/src/gallium/drivers/freedreno/freedreno_util.h
+++ b/src/gallium/drivers/freedreno/freedreno_util.h
@@ -476,6 +476,7 @@ fd4_stage2shadersb(gl_shader_stage type)
 	case MESA_SHADER_FRAGMENT:
 		return SB4_FS_SHADER;
 	case MESA_SHADER_COMPUTE:
+	case MESA_SHADER_KERNEL:
 		return SB4_CS_SHADER;
 	default:
 		unreachable("bad shader type");
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c b/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c
index 47fd5dfd012..7cd03d0b021 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_cmdline.c
@@ -165,6 +165,7 @@ load_glsl(unsigned num_files, char* const* files, gl_shader_stage stage)
 				ir3_glsl_type_size);
 		break;
 	case MESA_SHADER_COMPUTE:
+	case MESA_SHADER_KERNEL:
 		break;
 	default:
 		errx(1, "unhandled shader stage: %d", stage);
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
index cc6efa1ca17..7e7b699678f 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
@@ -588,7 +588,7 @@ void
 ir3_emit_cs_consts(const struct ir3_shader_variant *v, struct fd_ringbuffer *ring,
 		struct fd_context *ctx, const struct pipe_grid_info *info)
 {
-	debug_assert(v->type == MESA_SHADER_COMPUTE);
+	debug_assert(gl_shader_stage_is_compute(v->type));
 
 	emit_common_consts(v, ring, ctx, PIPE_SHADER_COMPUTE);
 
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c
index e7ba282b075..16a77b41c94 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -368,7 +368,7 @@ void si_nir_scan_shader(const struct nir_shader *nir,
 		}
 	}
 
-	if (nir->info.stage == MESA_SHADER_COMPUTE) {
+	if (gl_shader_stage_is_compute(nir->info.stage)) {
 		info->properties[TGSI_PROPERTY_CS_FIXED_BLOCK_WIDTH] = nir->info.cs.local_size[0];
 		info->properties[TGSI_PROPERTY_CS_FIXED_BLOCK_HEIGHT] = nir->info.cs.local_size[1];
 		info->properties[TGSI_PROPERTY_CS_FIXED_BLOCK_DEPTH] = nir->info.cs.local_size[2];
@@ -1053,7 +1053,7 @@ bool si_nir_build_llvm(struct si_shader_context *ctx, struct nir_shader *nir)
 	ctx->num_images = util_last_bit(info->images_declared);
 
 	if (ctx->shader->selector->info.properties[TGSI_PROPERTY_CS_LOCAL_SIZE]) {
-		assert(nir->info.stage == MESA_SHADER_COMPUTE);
+		assert(gl_shader_stage_is_compute(nir->info.stage));
 		si_declare_compute_memory(ctx);
 	}
 	ac_nir_translate(&ctx->ac, &ctx->abi, nir);
diff --git a/src/mesa/main/shaderobj.h b/src/mesa/main/shaderobj.h
index c7ccc54afe4..a08669d30f7 100644
--- a/src/mesa/main/shaderobj.h
+++ b/src/mesa/main/shaderobj.h
@@ -225,6 +225,9 @@ _mesa_shader_stage_to_subroutine(gl_shader_stage stage)
       return GL_TESS_EVALUATION_SUBROUTINE;
    case MESA_SHADER_NONE:
       break;
+   case MESA_SHADER_KERNEL:
+      unreachable("not reached");
+      break;
    }
    unreachable("not reached");
 }
@@ -247,6 +250,9 @@ _mesa_shader_stage_to_subroutine_uniform(gl_shader_stage stage)
       return GL_TESS_EVALUATION_SUBROUTINE_UNIFORM;
    case MESA_SHADER_NONE:
       break;
+   case MESA_SHADER_KERNEL:
+      unreachable("not reached");
+      break;
    }
    unreachable("not reached");
 }
-- 
2.19.2



More information about the mesa-dev mailing list