mesa: replace #defines with new gl_shader_type enum
authorBrian Paul <brianp@vmware.com>
Tue, 23 Nov 2010 17:28:43 +0000 (10:28 -0700)
committerBrian Paul <brianp@vmware.com>
Tue, 23 Nov 2010 22:52:43 +0000 (15:52 -0700)
src/mesa/main/context.c
src/mesa/main/mtypes.h
src/mesa/main/shaderobj.c
src/mesa/main/shaderobj.h
src/mesa/program/program.c
src/mesa/program/program.h
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_extensions.c

index 4ed179a834c7be96a7675c5b2223935306a07840..e2c91c3e400fac4c817040fc86a7bcc9f2b40e36 100644 (file)
@@ -1829,7 +1829,7 @@ _mesa_valid_to_render(struct gl_context *ctx, const char *where)
 #ifdef DEBUG
    if (ctx->Shader.Flags & GLSL_LOG) {
       struct gl_shader_program *shProg[MESA_SHADER_TYPES];
-      unsigned i;
+      gl_shader_type i;
 
       shProg[MESA_SHADER_VERTEX] = ctx->Shader.CurrentVertexProgram;
       shProg[MESA_SHADER_GEOMETRY] = ctx->Shader.CurrentGeometryProgram;
index 87b96489dbfab5af88d8b558d81512f27207241d..80c20e09d9ae92ddb0dddc9f5347a3ef731cb36f 100644 (file)
 #include "math/m_matrix.h"     /* GLmatrix */
 #include "main/simple_list.h"  /* struct simple_node */
 
-/* Shader stages. Note that these will become 5 with tessellation.
- * These MUST have the same values as PIPE_SHADER_*
- */
-#define MESA_SHADER_VERTEX   0
-#define MESA_SHADER_FRAGMENT 1
-#define MESA_SHADER_GEOMETRY 2
-#define MESA_SHADER_TYPES    3
-
 
 /**
  * Color channel data type.
@@ -129,6 +121,20 @@ struct st_context;
 
 
 
+/**
+ * Shader stages. Note that these will become 5 with tessellation.
+ * These MUST have the same values as gallium's PIPE_SHADER_*
+ */
+typedef enum
+{
+   MESA_SHADER_VERTEX = 0,
+   MESA_SHADER_FRAGMENT = 1,
+   MESA_SHADER_GEOMETRY = 2,
+   MESA_SHADER_TYPES = 3
+} gl_shader_type;
+
+
+
 /**
  * Indexes for vertex program attributes.
  * GL_NV_vertex_program aliases generic attributes over the conventional
index b6594cbe6f0704ee8e4ec1928c807360f0df7442..216bbce003299a4501b0a259726f3606c2cf4d5e 100644 (file)
@@ -291,6 +291,7 @@ _mesa_free_shader_program_data(struct gl_context *ctx,
                                struct gl_shader_program *shProg)
 {
    GLuint i;
+   gl_shader_type sh;
 
    assert(shProg->Type == GL_SHADER_PROGRAM_MESA);
 
@@ -326,10 +327,10 @@ _mesa_free_shader_program_data(struct gl_context *ctx,
    shProg->TransformFeedback.NumVarying = 0;
 
 
-   for (i = 0; i < MESA_SHADER_TYPES; i++) {
-      if (shProg->_LinkedShaders[i] != NULL) {
-        ctx->Driver.DeleteShader(ctx, shProg->_LinkedShaders[i]);
-        shProg->_LinkedShaders[i] = NULL;
+   for (sh = 0; sh < MESA_SHADER_TYPES; sh++) {
+      if (shProg->_LinkedShaders[sh] != NULL) {
+        ctx->Driver.DeleteShader(ctx, shProg->_LinkedShaders[sh]);
+        shProg->_LinkedShaders[sh] = NULL;
       }
    }
 }
index 346a5b75175da10f34fc3bb73ee5568e356634ce..de7c998cf0e4b3543cab00e90fb04c4c7a0ec738 100644 (file)
@@ -98,7 +98,7 @@ extern void
 _mesa_free_shader_state(struct gl_context *ctx);
 
 
-static INLINE GLuint
+static INLINE gl_shader_type
 _mesa_shader_type_to_index(GLenum v)
 {
    switch (v) {
@@ -110,7 +110,7 @@ _mesa_shader_type_to_index(GLenum v)
       return MESA_SHADER_GEOMETRY;
    default:
       ASSERT(0 && "bad value in _mesa_shader_type_to_index()");
-      return ~0;
+      return MESA_SHADER_TYPES;
    }
 }
 
index 1e99e1e4c30451baeafdab0285d6f2beb5594697..9ffa49bb013cd81e2b63f5a2228e918d11865c15 100644 (file)
@@ -925,7 +925,7 @@ _mesa_find_free_register(const GLboolean used[],
  */
 GLboolean
 _mesa_valid_register_index(const struct gl_context *ctx,
-                           GLuint shaderType,
+                           gl_shader_type shaderType,
                            gl_register_file file, GLint index)
 {
    const struct gl_program_constants *c;
index 1f1d6140255e82d16b0b21f775d672aecec94c25..ce37b95bf82db8c0ac55f98575b7bd0f50922017 100644 (file)
@@ -168,7 +168,7 @@ _mesa_find_free_register(const GLboolean used[],
 
 extern GLboolean
 _mesa_valid_register_index(const struct gl_context *ctx,
-                           GLuint shaderType,
+                           gl_shader_type shaderType,
                            gl_register_file file, GLint index);
 
 extern void
index d0dcdd4e29bdce5ae3776fe3820ac61ffa2865e9..d6628b1bff00ac6fe415149d75040761b19caaf2 100644 (file)
@@ -170,6 +170,11 @@ struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
    struct gl_context *shareCtx = share ? share->ctx : NULL;
    struct dd_function_table funcs;
 
+   /* Sanity checks */
+   assert(MESA_SHADER_VERTEX == PIPE_SHADER_VERTEX);
+   assert(MESA_SHADER_FRAGMENT == PIPE_SHADER_FRAGMENT);
+   assert(MESA_SHADER_GEOMETRY == PIPE_SHADER_GEOMETRY);
+
    memset(&funcs, 0, sizeof(funcs));
    st_init_driver_functions(&funcs);
 
index e72caa3842c078dc765044ae25266412f1dd7a2c..930b60ade2da68f9f6a04ff71fcf795350f718e0 100644 (file)
@@ -67,7 +67,7 @@ void st_init_limits(struct st_context *st)
 {
    struct pipe_screen *screen = st->pipe->screen;
    struct gl_constants *c = &st->ctx->Const;
-   unsigned i;
+   gl_shader_type sh;
 
    c->MaxTextureLevels
       = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
@@ -137,11 +137,12 @@ void st_init_limits(struct st_context *st)
    /* Quads always follow GL provoking rules. */
    c->QuadsFollowProvokingVertexConvention = GL_FALSE;
 
-   for(i = 0; i < MESA_SHADER_TYPES; ++i) {
-      struct gl_shader_compiler_options *options = &st->ctx->ShaderCompilerOptions[i];
+   for (sh = 0; sh < MESA_SHADER_TYPES; ++sh) {
+      struct gl_shader_compiler_options *options =
+         &st->ctx->ShaderCompilerOptions[sh];
       struct gl_program_constants *pc;
-      switch(i)
-      {
+
+      switch (sh) {
       case PIPE_SHADER_FRAGMENT:
          pc = &c->FragmentProgram;
          break;
@@ -156,37 +157,37 @@ void st_init_limits(struct st_context *st)
          continue;
       }
 
-      pc->MaxNativeInstructions    = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
-      pc->MaxNativeAluInstructions = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS);
-      pc->MaxNativeTexInstructions = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS);
-      pc->MaxNativeTexIndirections = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
-      pc->MaxNativeAttribs         = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_INPUTS);
-      pc->MaxNativeTemps           = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_TEMPS);
-      pc->MaxNativeAddressRegs     = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_ADDRS);
-      pc->MaxNativeParameters      = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_CONSTS);
+      pc->MaxNativeInstructions    = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
+      pc->MaxNativeAluInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS);
+      pc->MaxNativeTexInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS);
+      pc->MaxNativeTexIndirections = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
+      pc->MaxNativeAttribs         = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS);
+      pc->MaxNativeTemps           = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
+      pc->MaxNativeAddressRegs     = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS);
+      pc->MaxNativeParameters      = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONSTS);
       pc->MaxUniformComponents     = 4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS);
 
       options->EmitNoNoise = TRUE;
 
       /* TODO: make these more fine-grained if anyone needs it */
-      options->EmitNoIfs = !screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
-      options->EmitNoLoops = !screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
-      options->EmitNoFunctions = !screen->get_shader_param(screen, i, PIPE_SHADER_CAP_SUBROUTINES);
-      options->EmitNoMainReturn = !screen->get_shader_param(screen, i, PIPE_SHADER_CAP_SUBROUTINES);
+      options->EmitNoIfs = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
+      options->EmitNoLoops = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
+      options->EmitNoFunctions = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
+      options->EmitNoMainReturn = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
 
-      options->EmitNoCont = !screen->get_shader_param(screen, i, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED);
+      options->EmitNoCont = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED);
 
-      options->EmitNoIndirectInput = !screen->get_shader_param(screen, i,
+      options->EmitNoIndirectInput = !screen->get_shader_param(screen, sh,
                                         PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR);
-      options->EmitNoIndirectOutput = !screen->get_shader_param(screen, i,
+      options->EmitNoIndirectOutput = !screen->get_shader_param(screen, sh,
                                         PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR);
-      options->EmitNoIndirectTemp = !screen->get_shader_param(screen, i,
+      options->EmitNoIndirectTemp = !screen->get_shader_param(screen, sh,
                                         PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR);
-      options->EmitNoIndirectUniform = !screen->get_shader_param(screen, i,
+      options->EmitNoIndirectUniform = !screen->get_shader_param(screen, sh,
                                         PIPE_SHADER_CAP_INDIRECT_CONST_ADDR);
 
       if(options->EmitNoLoops)
-         options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
+         options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
    }
 
    /* PIPE_CAP_MAX_FS_INPUTS specifies the number of COLORn + GENERICn inputs