[Mesa-dev] [PATCH 16/30] mesa/cs: Add a MESA_SHADER_COMPUTE stage and update switch statements.

Paul Berry stereotype441 at gmail.com
Thu Jan 9 18:19:17 PST 2014


This patch adds MESA_SHADER_COMPUTE to the gl_shader_stage enum.
Also, where it is trivial to do so, it adds a compute shader case to
switch statements that switch based on the type of shader.  This
avoids "unhandled switch case" compiler warnings.
---
 src/glsl/ast_to_hir.cpp           |  9 +++++++++
 src/glsl/builtin_variables.cpp    | 17 +++++++++++++++++
 src/glsl/standalone_scaffolding.h |  2 ++
 src/mesa/main/context.c           |  8 ++++++++
 src/mesa/main/mtypes.h            |  3 ++-
 src/mesa/main/shaderapi.c         |  5 +++++
 src/mesa/main/shaderobj.h         |  2 ++
 src/mesa/program/prog_print.c     |  3 +++
 src/mesa/program/program.h        |  4 ++++
 9 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index ef8e699..a26745d 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2093,6 +2093,12 @@ validate_explicit_location(const struct ast_type_qualifier *qual,
 
       fail = true;
       break;
+
+   case MESA_SHADER_COMPUTE:
+      _mesa_glsl_error(loc, state,
+                       "compute shader variables cannot be given "
+                       "explicit locations");
+      return;
    };
 
    if (fail) {
@@ -2275,6 +2281,9 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
 	 if (var->data.mode == ir_var_shader_in)
 	    var->data.invariant = true;
 	 break;
+      case MESA_SHADER_COMPUTE:
+         /* Invariance isn't meaningful in compute shaders. */
+         break;
       }
    }
 
diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
index f630923..17ae087 100644
--- a/src/glsl/builtin_variables.cpp
+++ b/src/glsl/builtin_variables.cpp
@@ -356,6 +356,7 @@ public:
    void generate_vs_special_vars();
    void generate_gs_special_vars();
    void generate_fs_special_vars();
+   void generate_cs_special_vars();
    void generate_varyings();
 
 private:
@@ -866,6 +867,16 @@ builtin_variable_generator::generate_fs_special_vars()
 
 
 /**
+ * Generate variables which only exist in compute shaders.
+ */
+void
+builtin_variable_generator::generate_cs_special_vars()
+{
+   /* TODO: finish this. */
+}
+
+
+/**
  * Add a single "varying" variable.  The variable's type and direction (input
  * or output) are adjusted as appropriate for the type of shader being
  * compiled.  For geometry shaders using {ARB,EXT}_geometry_shader4,
@@ -886,6 +897,9 @@ builtin_variable_generator::add_varying(int slot, const glsl_type *type,
    case MESA_SHADER_FRAGMENT:
       add_input(slot, type, name);
       break;
+   case MESA_SHADER_COMPUTE:
+      /* Compute shaders don't have varyings. */
+      break;
    }
 }
 
@@ -973,5 +987,8 @@ _mesa_glsl_initialize_variables(exec_list *instructions,
    case MESA_SHADER_FRAGMENT:
       gen.generate_fs_special_vars();
       break;
+   case MESA_SHADER_COMPUTE:
+      gen.generate_cs_special_vars();
+      break;
    }
 }
diff --git a/src/glsl/standalone_scaffolding.h b/src/glsl/standalone_scaffolding.h
index 327fef2..df783af 100644
--- a/src/glsl/standalone_scaffolding.h
+++ b/src/glsl/standalone_scaffolding.h
@@ -58,6 +58,8 @@ _mesa_shader_enum_to_shader_stage(GLenum v)
       return MESA_SHADER_FRAGMENT;
    case GL_GEOMETRY_SHADER:
       return MESA_SHADER_GEOMETRY;
+   case GL_COMPUTE_SHADER:
+      return MESA_SHADER_COMPUTE;
    default:
       assert(!"bad value in _mesa_shader_enum_to_shader_stage()");
       return MESA_SHADER_VERTEX;
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 5855f15..b0cf5da 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -498,6 +498,14 @@ init_program_limits(struct gl_context *ctx, gl_shader_stage stage,
       prog->MaxInputComponents = 16 * 4; /* old limit not to break tnl and swrast */
       prog->MaxOutputComponents = 16 * 4; /* old limit not to break tnl and swrast */
       break;
+   case MESA_SHADER_COMPUTE:
+      prog->MaxParameters = 0; /* not meaningful for compute shaders */
+      prog->MaxAttribs = 0; /* not meaningful for compute shaders */
+      prog->MaxAddressRegs = 0; /* not meaningful for compute shaders */
+      prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
+      prog->MaxInputComponents = 0; /* not meaningful for compute shaders */
+      prog->MaxOutputComponents = 0; /* not meaningful for compute shaders */
+      break;
    default:
       assert(0 && "Bad shader stage in init_program_limits()");
    }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 7ba7b10..8b88d75 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -404,9 +404,10 @@ typedef enum
    MESA_SHADER_VERTEX = 0,
    MESA_SHADER_GEOMETRY = 1,
    MESA_SHADER_FRAGMENT = 2,
+   MESA_SHADER_COMPUTE = 3,
 } gl_shader_stage;
 
-#define MESA_SHADER_STAGES (MESA_SHADER_FRAGMENT + 1)
+#define MESA_SHADER_STAGES (MESA_SHADER_COMPUTE + 1)
 
 
 /**
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 61ac0e3..519b200 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -188,6 +188,8 @@ _mesa_validate_shader_target(const struct gl_context *ctx, GLenum type)
       return ctx == NULL || ctx->Extensions.ARB_vertex_shader;
    case GL_GEOMETRY_SHADER_ARB:
       return ctx == NULL || _mesa_has_geometry_shaders(ctx);
+   case GL_COMPUTE_SHADER:
+      return ctx == NULL || ctx->Extensions.ARB_compute_shader;
    default:
       return false;
    }
@@ -966,6 +968,9 @@ use_shader_program(struct gl_context *ctx, GLenum type,
       case GL_GEOMETRY_SHADER_ARB:
 	 /* Empty for now. */
 	 break;
+      case GL_COMPUTE_SHADER:
+         /* Empty for now. */
+         break;
       case GL_FRAGMENT_SHADER:
 	 if (*target == ctx->Shader._CurrentFragmentProgram) {
 	    _mesa_reference_shader_program(ctx,
diff --git a/src/mesa/main/shaderobj.h b/src/mesa/main/shaderobj.h
index 5175570..fae8be8 100644
--- a/src/mesa/main/shaderobj.h
+++ b/src/mesa/main/shaderobj.h
@@ -111,6 +111,8 @@ _mesa_shader_enum_to_shader_stage(GLenum v)
       return MESA_SHADER_FRAGMENT;
    case GL_GEOMETRY_SHADER:
       return MESA_SHADER_GEOMETRY;
+   case GL_COMPUTE_SHADER:
+      return MESA_SHADER_COMPUTE;
    default:
       ASSERT(0 && "bad value in _mesa_shader_enum_to_shader_stage()");
       return MESA_SHADER_VERTEX;
diff --git a/src/mesa/program/prog_print.c b/src/mesa/program/prog_print.c
index 9391e99..f97a83c 100644
--- a/src/mesa/program/prog_print.c
+++ b/src/mesa/program/prog_print.c
@@ -1019,6 +1019,9 @@ _mesa_write_shader_to_file(const struct gl_shader *shader)
    case MESA_SHADER_GEOMETRY:
       type = "geom";
       break;
+   case MESA_SHADER_COMPUTE:
+      type = "comp";
+      break;
    }
 
    _mesa_snprintf(filename, sizeof(filename), "shader_%u.%s", shader->Name, type);
diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
index f666e30..84aa8cb 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -201,6 +201,8 @@ _mesa_program_enum_to_shader_stage(GLenum v)
       return MESA_SHADER_FRAGMENT;
    case GL_GEOMETRY_PROGRAM_NV:
       return MESA_SHADER_GEOMETRY;
+   case GL_COMPUTE_PROGRAM_NV:
+      return MESA_SHADER_COMPUTE;
    default:
       ASSERT(0);
       return ~0;
@@ -218,6 +220,8 @@ _mesa_shader_stage_to_program(unsigned stage)
       return GL_FRAGMENT_PROGRAM_ARB;
    case MESA_SHADER_GEOMETRY:
       return GL_GEOMETRY_PROGRAM_NV;
+   case MESA_SHADER_COMPUTE:
+      return GL_COMPUTE_PROGRAM_NV;
    }
 
    assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
-- 
1.8.5.2



More information about the mesa-dev mailing list