mesa: replace GLenum target with gl_shader_stage in NewProgram
authorMarek Olšák <marek.olsak@amd.com>
Tue, 31 Mar 2020 14:03:55 +0000 (10:03 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 27 Apr 2020 12:49:53 +0000 (12:49 +0000)
So that the GLSL compiler doesn't have to use the GLenum conversion
functions.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4756>

14 files changed:
src/compiler/glsl/linker.cpp
src/compiler/glsl/serialize.cpp
src/compiler/glsl/standalone.cpp
src/mesa/drivers/dri/i915/i915_fragprog.c
src/mesa/drivers/dri/i965/brw_program.c
src/mesa/drivers/dri/r200/r200_vertprog.c
src/mesa/main/arbprogram.c
src/mesa/main/dd.h
src/mesa/main/ffvertex_prog.c
src/mesa/main/glspirv.c
src/mesa/main/shared.c
src/mesa/program/program.c
src/mesa/program/program.h
src/mesa/state_tracker/st_cb_program.c

index 8a876fcecee66354a71c70fdbc46e12b3bb4a62a..b3175090c717c3dc5199531b00cb34d413edd494 100644 (file)
@@ -2467,9 +2467,7 @@ link_intrastage_shaders(void *mem_ctx,
 
    /* Create program and attach it to the linked shader */
    struct gl_program *gl_prog =
-      ctx->Driver.NewProgram(ctx,
-                             _mesa_shader_stage_to_program(shader_list[0]->Stage),
-                             prog->Name, false);
+      ctx->Driver.NewProgram(ctx, shader_list[0]->Stage, prog->Name, false);
    if (!gl_prog) {
       prog->data->LinkStatus = LINKING_FAILURE;
       _mesa_delete_linked_shader(ctx, linked);
index 11cae46dd8b8cf186d363b3b50a9bf1e49503d15..d4aacc1cb95b40933a0cc3068626a40a3152f6c3 100644 (file)
@@ -1222,8 +1222,7 @@ create_linked_shader_and_program(struct gl_context *ctx,
    struct gl_linked_shader *linked = rzalloc(NULL, struct gl_linked_shader);
    linked->Stage = stage;
 
-   glprog = ctx->Driver.NewProgram(ctx, _mesa_shader_stage_to_program(stage),
-                                   prog->Name, false);
+   glprog = ctx->Driver.NewProgram(ctx, stage, prog->Name, false);
    glprog->info.stage = stage;
    linked->Program = glprog;
 
index 4b4735016227f8b9cf51ace2e2584b999a41a565..9a7f7d58ed6fcf4909d33a94a5a68732c133d984 100644 (file)
@@ -99,33 +99,21 @@ private:
 };
 
 static void
-init_gl_program(struct gl_program *prog, bool is_arb_asm, GLenum target)
+init_gl_program(struct gl_program *prog, bool is_arb_asm, gl_shader_stage stage)
 {
    prog->RefCount = 1;
    prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB;
    prog->is_arb_asm = is_arb_asm;
-   prog->info.stage = (gl_shader_stage)_mesa_program_enum_to_shader_stage(target);
+   prog->info.stage = stage;
 }
 
 static struct gl_program *
-new_program(UNUSED struct gl_context *ctx, GLenum target,
+new_program(UNUSED struct gl_context *ctx, gl_shader_stage stage,
             UNUSED GLuint id, bool is_arb_asm)
 {
-   switch (target) {
-   case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
-   case GL_GEOMETRY_PROGRAM_NV:
-   case GL_TESS_CONTROL_PROGRAM_NV:
-   case GL_TESS_EVALUATION_PROGRAM_NV:
-   case GL_FRAGMENT_PROGRAM_ARB:
-   case GL_COMPUTE_PROGRAM_NV: {
-      struct gl_program *prog = rzalloc(NULL, struct gl_program);
-      init_gl_program(prog, is_arb_asm, target);
-      return prog;
-   }
-   default:
-      printf("bad target in new_program\n");
-      return NULL;
-   }
+   struct gl_program *prog = rzalloc(NULL, struct gl_program);
+   init_gl_program(prog, is_arb_asm, stage);
+   return prog;
 }
 
 static const struct standalone_options *options;
index 6493ab99b1e4bd6972584fb1b37309f6e1058237..95a60d1cce0552c13cc94c3de41736a979a2db5b 100644 (file)
@@ -1121,22 +1121,22 @@ track_params(struct i915_fragment_program *p)
 }
 
 static struct gl_program *
-i915NewProgram(struct gl_context * ctx, GLenum target, GLuint id,
+i915NewProgram(struct gl_context * ctx, gl_shader_stage stage, GLuint id,
                bool is_arb_asm)
 {
-   switch (target) {
-   case GL_VERTEX_PROGRAM_ARB: {
+   switch (stage) {
+   case MESA_SHADER_VERTEX: {
       struct gl_program *prog = rzalloc(NULL, struct gl_program);
-      return _mesa_init_gl_program(prog, target, id, is_arb_asm);
+      return _mesa_init_gl_program(prog, stage, id, is_arb_asm);
    }
 
-   case GL_FRAGMENT_PROGRAM_ARB:{
+   case MESA_SHADER_FRAGMENT:{
          struct i915_fragment_program *prog =
             rzalloc(NULL, struct i915_fragment_program);
          if (prog) {
             i915_init_program(I915_CONTEXT(ctx), prog);
 
-            return _mesa_init_gl_program(&prog->FragProg, target, id,
+            return _mesa_init_gl_program(&prog->FragProg, stage, id,
                                          is_arb_asm);
          }
          else
@@ -1146,7 +1146,7 @@ i915NewProgram(struct gl_context * ctx, GLenum target, GLuint id,
    default:
       /* Just fallback:
        */
-      return _mesa_new_program(ctx, target, id, is_arb_asm);
+      return _mesa_new_program(ctx, stage, id, is_arb_asm);
    }
 }
 
index 412be5ec5991a7fe9b892c2c90d8a5912e9b30a3..be4347881f2f065cf2ef6c0145890b373bbc57d9 100644 (file)
@@ -72,7 +72,8 @@ brw_nir_lower_uniforms(nir_shader *nir, bool is_scalar)
    }
 }
 
-static struct gl_program *brwNewProgram(struct gl_context *ctx, GLenum target,
+static struct gl_program *brwNewProgram(struct gl_context *ctx,
+                                        gl_shader_stage stage,
                                         GLuint id, bool is_arb_asm);
 
 nir_shader *
@@ -219,7 +220,8 @@ get_new_program_id(struct intel_screen *screen)
    return p_atomic_inc_return(&screen->program_id);
 }
 
-static struct gl_program *brwNewProgram(struct gl_context *ctx, GLenum target,
+static struct gl_program *brwNewProgram(struct gl_context *ctx,
+                                        gl_shader_stage stage,
                                         GLuint id, bool is_arb_asm)
 {
    struct brw_context *brw = brw_context(ctx);
@@ -228,7 +230,7 @@ static struct gl_program *brwNewProgram(struct gl_context *ctx, GLenum target,
    if (prog) {
       prog->id = get_new_program_id(brw->screen);
 
-      return _mesa_init_gl_program(&prog->program, target, id, is_arb_asm);
+      return _mesa_init_gl_program(&prog->program, stage, id, is_arb_asm);
    }
 
    return NULL;
index 7076ec0c7f377356019c4a46573c1ad5ed0ffae1..0c51b191dfc2828def2ab446f3d6843707ac3ba7 100644 (file)
@@ -1183,18 +1183,18 @@ void r200SetupVertexProg( struct gl_context *ctx ) {
 
 
 static struct gl_program *
-r200NewProgram(struct gl_context *ctx, GLenum target, GLuint id,
+r200NewProgram(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
                bool is_arb_asm)
 {
-   switch(target){
-   case GL_VERTEX_PROGRAM_ARB: {
+   switch(stage){
+   case MESA_SHADER_VERTEX: {
       struct r200_vertex_program *vp = rzalloc(NULL,
                                                struct r200_vertex_program);
-      return _mesa_init_gl_program(&vp->mesa_program, target, id, is_arb_asm);
+      return _mesa_init_gl_program(&vp->mesa_program, stage, id, is_arb_asm);
    }
-   case GL_FRAGMENT_PROGRAM_ARB: {
+   case MESA_SHADER_FRAGMENT: {
       struct gl_program *prog = rzalloc(NULL, struct gl_program);
-      return _mesa_init_gl_program(prog, target, id, is_arb_asm);
+      return _mesa_init_gl_program(prog, stage, id, is_arb_asm);
    }
    default:
       _mesa_problem(ctx, "Bad target in r200NewProgram");
index 67162946015b903d132d4b19a915f32f9507220b..e6fb7cac85b2b8524212baea9802f0602f398369 100644 (file)
@@ -77,7 +77,8 @@ lookup_or_create_program(GLuint id, GLenum target, const char* caller)
       newProg = _mesa_lookup_program(ctx, id);
       if (!newProg || newProg == &_mesa_DummyProgram) {
          /* allocate a new program now */
-         newProg = ctx->Driver.NewProgram(ctx, target, id, true);
+         newProg = ctx->Driver.NewProgram(ctx, _mesa_program_enum_to_shader_stage(target),
+                                          id, true);
          if (!newProg) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
             return NULL;
index b7973e1c6aec9230de6ba5f4aa341da96e943d04..4a7d775db459c5dc8f000c0110ff3b6247446b66 100644 (file)
@@ -34,6 +34,7 @@
 #include "glheader.h"
 #include "formats.h"
 #include "menums.h"
+#include "compiler/shader_enums.h"
 
 struct gl_bitmap_atlas;
 struct gl_buffer_object;
@@ -453,7 +454,8 @@ struct dd_function_table {
     */
    /*@{*/
    /** Allocate a new program */
-   struct gl_program * (*NewProgram)(struct gl_context *ctx, GLenum target,
+   struct gl_program * (*NewProgram)(struct gl_context *ctx,
+                                     gl_shader_stage stage,
                                      GLuint id, bool is_arb_asm);
    /** Delete a program */
    void (*DeleteProgram)(struct gl_context *ctx, struct gl_program *prog);   
index 04126fe9b9034bb5f1e133e98efd4353ab93c736..57026793ea155ea3f13ee99a19b835d2daa1e257 100644 (file)
@@ -1667,7 +1667,7 @@ _mesa_get_fixed_func_vertex_program(struct gl_context *ctx)
       if (0)
          printf("Build new TNL program\n");
 
-      prog = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0, true);
+      prog = ctx->Driver.NewProgram(ctx, MESA_SHADER_VERTEX, 0, true);
       if (!prog)
          return NULL;
 
index 9a6630748167ac79e36a5bed882ce01d92efa414..64daf54ec422bfd0342f6f7550efa6a6b0a3d119 100644 (file)
@@ -148,9 +148,7 @@ _mesa_spirv_link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 
       /* Create program and attach it to the linked shader */
       struct gl_program *gl_prog =
-         ctx->Driver.NewProgram(ctx,
-                                _mesa_shader_stage_to_program(shader_type),
-                                prog->Name, false);
+         ctx->Driver.NewProgram(ctx, shader_type, prog->Name, false);
       if (!gl_prog) {
          prog->data->LinkStatus = LINKING_FAILURE;
          _mesa_delete_linked_shader(ctx, linked);
index 357368b38deb8bf221585adfe3a3280650cff5fa..51e15178ce7bd6a40de156869b8d96aa440408be 100644 (file)
@@ -75,9 +75,9 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
    shared->Programs = _mesa_NewHashTable();
 
    shared->DefaultVertexProgram =
-      ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0, true);
+      ctx->Driver.NewProgram(ctx, MESA_SHADER_VERTEX, 0, true);
    shared->DefaultFragmentProgram =
-      ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0, true);
+      ctx->Driver.NewProgram(ctx, MESA_SHADER_FRAGMENT, 0, true);
 
    shared->ATIShaders = _mesa_NewHashTable();
    shared->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);
index 754e3d480b81fec49fa7e53a6284fe4cd4fca9e8..e9a2c96bee551a6e2974f2d7b5d9e50ea235451b 100644 (file)
@@ -181,18 +181,18 @@ _mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string)
  * Initialize a new gl_program object.
  */
 struct gl_program *
-_mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id,
-                      bool is_arb_asm)
+_mesa_init_gl_program(struct gl_program *prog, gl_shader_stage stage,
+                      GLuint id, bool is_arb_asm)
 {
    if (!prog)
       return NULL;
 
    memset(prog, 0, sizeof(*prog));
    prog->Id = id;
-   prog->Target = target;
+   prog->Target = _mesa_shader_stage_to_program(stage);
    prog->RefCount = 1;
    prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB;
-   prog->info.stage = _mesa_program_enum_to_shader_stage(target);
+   prog->info.stage = stage;
    prog->is_arb_asm = is_arb_asm;
 
    /* Uniforms that lack an initializer in the shader code have an initial
@@ -225,27 +225,16 @@ _mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id,
  *
  * \param ctx  context
  * \param id   program id/number
- * \param target  program target/type
+ * \param stage  shader stage
  * \return  pointer to new program object
  */
 struct gl_program *
-_mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id,
+_mesa_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
                   bool is_arb_asm)
 {
-   switch (target) {
-   case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
-   case GL_GEOMETRY_PROGRAM_NV:
-   case GL_TESS_CONTROL_PROGRAM_NV:
-   case GL_TESS_EVALUATION_PROGRAM_NV:
-   case GL_FRAGMENT_PROGRAM_ARB:
-   case GL_COMPUTE_PROGRAM_NV: {
-      struct gl_program *prog = rzalloc(NULL, struct gl_program);
-      return _mesa_init_gl_program(prog, target, id, is_arb_asm);
-   }
-   default:
-      _mesa_problem(ctx, "bad target in _mesa_new_program");
-      return NULL;
-   }
+   struct gl_program *prog = rzalloc(NULL, struct gl_program);
+
+   return _mesa_init_gl_program(prog, stage, id, is_arb_asm);
 }
 
 
index 49e888e57df248e60ebff7921653c15e0e9934aa..7de6804047a22e48c761e2ac0e371f0bd5f6ddb3 100644 (file)
@@ -63,11 +63,11 @@ extern void
 _mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string);
 
 extern struct gl_program *
-_mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id,
-                      bool is_arb_asm);
+_mesa_init_gl_program(struct gl_program *prog, gl_shader_stage stage,
+                      GLuint id, bool is_arb_asm);
 
 extern struct gl_program *
-_mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id,
+_mesa_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
                   bool is_arb_asm);
 
 extern void
index 37674c3edeaf52692c9a13d80ea2f0e5b7aee4be..f01e1374ebf1ee31490ac739d766588f22fd183e 100644 (file)
  * fragment program.
  */
 static struct gl_program *
-st_new_program(struct gl_context *ctx, GLenum target, GLuint id,
+st_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
                bool is_arb_asm)
 {
-   switch (target) {
-   case GL_VERTEX_PROGRAM_ARB: {
-      struct st_vertex_program *prog = rzalloc(NULL, struct st_vertex_program);
-      return _mesa_init_gl_program(&prog->Base.Base, target, id, is_arb_asm);
-   }
-   case GL_TESS_CONTROL_PROGRAM_NV:
-   case GL_TESS_EVALUATION_PROGRAM_NV:
-   case GL_GEOMETRY_PROGRAM_NV:
-   case GL_FRAGMENT_PROGRAM_ARB:
-   case GL_COMPUTE_PROGRAM_NV: {
-      struct st_program *prog = rzalloc(NULL, struct st_program);
-      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
-   }
+   struct st_program *prog;
+
+   switch (stage) {
+   case MESA_SHADER_VERTEX:
+      prog = (struct st_program*)rzalloc(NULL, struct st_vertex_program);
+      break;
    default:
-      assert(0);
-      return NULL;
+      prog = rzalloc(NULL, struct st_program);
+      break;
    }
+
+   return _mesa_init_gl_program(&prog->Base, stage, id, is_arb_asm);
 }
 
 
@@ -146,7 +141,7 @@ st_program_string_notify( struct gl_context *ctx,
 static struct gl_program *
 st_new_ati_fs(struct gl_context *ctx, struct ati_fragment_shader *curProg)
 {
-   struct gl_program *prog = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB,
+   struct gl_program *prog = ctx->Driver.NewProgram(ctx, MESA_SHADER_FRAGMENT,
          curProg->Id, true);
    struct st_program *stfp = (struct st_program *)prog;
    stfp->ati_fs = curProg;