[Mesa-dev] [PATCH 31/70] st/mesa/glsl: add new is_arb_asm flag in gl_program

Timothy Arceri timothy.arceri at collabora.com
Tue Dec 20 10:37:41 UTC 2016


Set the flag via the _mesa_init_gl_program() and NewProgram()
helpers.

In i965 we currently check for the existance of gl_shader_program
to decide if this is an ARB assembly style program or not.

Adding a flag makes the code clearer and will help removes a
dependency on gl_shader_program in the i965 codegen functions.

Also this will allow use to skip initialising sampler units for
linked shaders, we currently memset it to zero again during linking.
---
 src/compiler/glsl/linker.cpp              |  2 +-
 src/compiler/glsl/standalone.cpp          |  7 ++++---
 src/mesa/drivers/dri/i915/i915_fragprog.c | 10 ++++++----
 src/mesa/drivers/dri/i965/brw_program.c   |  9 ++++-----
 src/mesa/drivers/dri/r200/r200_vertprog.c |  7 ++++---
 src/mesa/main/arbprogram.c                |  2 +-
 src/mesa/main/dd.h                        |  2 +-
 src/mesa/main/ffvertex_prog.c             |  2 +-
 src/mesa/main/mtypes.h                    |  2 ++
 src/mesa/main/shared.c                    |  4 ++--
 src/mesa/program/program.c                |  9 ++++++---
 src/mesa/program/program.h                |  6 ++++--
 src/mesa/state_tracker/st_cb_program.c    | 17 +++++++++--------
 13 files changed, 45 insertions(+), 34 deletions(-)

diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index b01ec6c..09cd076 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -2202,7 +2202,7 @@ link_intrastage_shaders(void *mem_ctx,
    struct gl_program *gl_prog =
       ctx->Driver.NewProgram(ctx,
                              _mesa_shader_stage_to_program(shader_list[0]->Stage),
-                             prog->Name);
+                             prog->Name, false);
    gl_prog->info.stage = shader_list[0]->Stage;
 
    if (!gl_prog) {
diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp
index 69d86c7..e93e9af 100644
--- a/src/compiler/glsl/standalone.cpp
+++ b/src/compiler/glsl/standalone.cpp
@@ -100,12 +100,13 @@ private:
 };
 
 void
-init_gl_program(struct gl_program *prog, GLenum target)
+init_gl_program(struct gl_program *prog, GLenum target, bool is_arb_asm)
 {
    mtx_init(&prog->Mutex, mtx_plain);
 
    prog->RefCount = 1;
    prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB;
+   prog->is_arb_asm = is_arb_asm;
 
    /* default mapping from samplers to texture units */
    for (int i = 0; i < MAX_SAMPLERS; i++)
@@ -113,7 +114,7 @@ init_gl_program(struct gl_program *prog, GLenum target)
 }
 
 struct gl_program *
-new_program(struct gl_context *ctx, GLenum target, GLuint id)
+new_program(struct gl_context *ctx, GLenum target, GLuint id, bool is_arb_asm)
 {
    switch (target) {
    case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
@@ -123,7 +124,7 @@ new_program(struct gl_context *ctx, GLenum target, GLuint id)
    case GL_FRAGMENT_PROGRAM_ARB:
    case GL_COMPUTE_PROGRAM_NV: {
       struct gl_program *prog = rzalloc(NULL, struct gl_program);
-      init_gl_program(prog, target);
+      init_gl_program(prog, target, is_arb_asm);
       return prog;
    }
    default:
diff --git a/src/mesa/drivers/dri/i915/i915_fragprog.c b/src/mesa/drivers/dri/i915/i915_fragprog.c
index c5a8ac5..fce649d 100644
--- a/src/mesa/drivers/dri/i915/i915_fragprog.c
+++ b/src/mesa/drivers/dri/i915/i915_fragprog.c
@@ -1144,12 +1144,13 @@ i915BindProgram(struct gl_context * ctx, GLenum target, struct gl_program *prog)
 }
 
 static struct gl_program *
-i915NewProgram(struct gl_context * ctx, GLenum target, GLuint id)
+i915NewProgram(struct gl_context * ctx, GLenum target, GLuint id,
+               bool is_arb_asm)
 {
    switch (target) {
    case GL_VERTEX_PROGRAM_ARB: {
       struct gl_program *prog = rzalloc(NULL, struct gl_program);
-      return _mesa_init_gl_program(prog, target, id);
+      return _mesa_init_gl_program(prog, target, id, is_arb_asm);
    }
 
    case GL_FRAGMENT_PROGRAM_ARB:{
@@ -1158,7 +1159,8 @@ i915NewProgram(struct gl_context * ctx, GLenum target, GLuint id)
          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, target, id,
+                                         is_arb_asm);
          }
          else
             return NULL;
@@ -1167,7 +1169,7 @@ i915NewProgram(struct gl_context * ctx, GLenum target, GLuint id)
    default:
       /* Just fallback:
        */
-      return _mesa_new_program(ctx, target, id);
+      return _mesa_new_program(ctx, target, id, is_arb_asm);
    }
 }
 
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c
index abdbf91..e7df6e7 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -125,9 +125,8 @@ get_new_program_id(struct intel_screen *screen)
    return id;
 }
 
-static struct gl_program *brwNewProgram( struct gl_context *ctx,
-				      GLenum target,
-				      GLuint id )
+static struct gl_program *brwNewProgram(struct gl_context *ctx, GLenum target,
+                                        GLuint id, bool is_arb_asm)
 {
    struct brw_context *brw = brw_context(ctx);
 
@@ -141,7 +140,7 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
       if (prog) {
 	 prog->id = get_new_program_id(brw->screen);
 
-	 return _mesa_init_gl_program(&prog->program, target, id);
+         return _mesa_init_gl_program(&prog->program, target, id, is_arb_asm);
       }
       else
 	 return NULL;
@@ -160,7 +159,7 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
       if (prog) {
 	 prog->id = get_new_program_id(brw->screen);
 
-	 return _mesa_init_gl_program(&prog->program, target, id);
+         return _mesa_init_gl_program(&prog->program, target, id, is_arb_asm);
       }
       else
 	 return NULL;
diff --git a/src/mesa/drivers/dri/r200/r200_vertprog.c b/src/mesa/drivers/dri/r200/r200_vertprog.c
index ded8e2a..0a3e984 100644
--- a/src/mesa/drivers/dri/r200/r200_vertprog.c
+++ b/src/mesa/drivers/dri/r200/r200_vertprog.c
@@ -1199,17 +1199,18 @@ r200BindProgram(struct gl_context *ctx, GLenum target, struct gl_program *prog)
 }
 
 static struct gl_program *
-r200NewProgram(struct gl_context *ctx, GLenum target, GLuint id)
+r200NewProgram(struct gl_context *ctx, GLenum target, GLuint id,
+               bool is_arb_asm)
 {
    switch(target){
    case GL_VERTEX_PROGRAM_ARB: {
       struct r200_vertex_program *vp = rzalloc(NULL,
                                                struct r200_vertex_program);
-      return _mesa_init_gl_program(&vp->mesa_program, target, id);
+      return _mesa_init_gl_program(&vp->mesa_program, target, id, is_arb_asm);
    }
    case GL_FRAGMENT_PROGRAM_ARB: {
       struct gl_program *prog = rzalloc(NULL, struct gl_program);
-      return _mesa_init_gl_program(prog, target, id);
+      return _mesa_init_gl_program(prog, target, id, is_arb_asm);
    }
    default:
       _mesa_problem(ctx, "Bad target in r200NewProgram");
diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c
index 70b40b3..2c60310 100644
--- a/src/mesa/main/arbprogram.c
+++ b/src/mesa/main/arbprogram.c
@@ -83,7 +83,7 @@ _mesa_BindProgramARB(GLenum target, GLuint id)
       newProg = _mesa_lookup_program(ctx, id);
       if (!newProg || newProg == &_mesa_DummyProgram) {
          /* allocate a new program now */
-         newProg = ctx->Driver.NewProgram(ctx, target, id);
+         newProg = ctx->Driver.NewProgram(ctx, target, id, true);
          if (!newProg) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramARB");
             return;
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 21e8260..7ebd084 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -474,7 +474,7 @@ struct dd_function_table {
                        struct gl_program *prog);
    /** Allocate a new program */
    struct gl_program * (*NewProgram)(struct gl_context *ctx, GLenum target,
-                                     GLuint id);
+                                     GLuint id, bool is_arb_asm);
    /** Delete a program */
    void (*DeleteProgram)(struct gl_context *ctx, struct gl_program *prog);   
    /**
diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c
index c917b41..85f8f24 100644
--- a/src/mesa/main/ffvertex_prog.c
+++ b/src/mesa/main/ffvertex_prog.c
@@ -1671,7 +1671,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);
+      prog = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0, true);
       if (!prog)
          return NULL;
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 3902653..f7ce6f6 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1925,6 +1925,8 @@ struct gl_program
 
    struct nir_shader *nir;
 
+   bool is_arb_asm; /** Is this an ARB assembly-style program */
+
    GLbitfield64 SecondaryOutputsWritten; /**< Subset of OutputsWritten outputs written with non-zero index. */
    GLbitfield TexturesUsed[MAX_COMBINED_TEXTURE_IMAGE_UNITS];  /**< TEXTURE_x_BIT bitmask */
    GLbitfield SamplersUsed;   /**< Bitfield of which samplers are used */
diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c
index 04e5443..5344812 100644
--- a/src/mesa/main/shared.c
+++ b/src/mesa/main/shared.c
@@ -70,9 +70,9 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
    shared->Programs = _mesa_NewHashTable();
 
    shared->DefaultVertexProgram =
-      ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
+      ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0, true);
    shared->DefaultFragmentProgram =
-      ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
+      ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0, true);
 
    shared->ATIShaders = _mesa_NewHashTable();
    shared->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);
diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c
index f1757ba..2b87a8b 100644
--- a/src/mesa/program/program.c
+++ b/src/mesa/program/program.c
@@ -178,7 +178,8 @@ _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)
+_mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id,
+                      bool is_arb_asm)
 {
    GLuint i;
 
@@ -191,6 +192,7 @@ _mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id)
    prog->Target = target;
    prog->RefCount = 1;
    prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB;
+   prog->is_arb_asm = is_arb_asm;
 
    /* default mapping from samplers to texture units */
    for (i = 0; i < MAX_SAMPLERS; i++)
@@ -213,7 +215,8 @@ _mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id)
  * \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, GLenum target, GLuint id,
+                  bool is_arb_asm)
 {
    switch (target) {
    case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
@@ -223,7 +226,7 @@ _mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id)
    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);
+      return _mesa_init_gl_program(prog, target, id, is_arb_asm);
    }
    default:
       _mesa_problem(ctx, "bad target in _mesa_new_program");
diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
index 18122f7..296fa40 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -64,10 +64,12 @@ 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);
+_mesa_init_gl_program(struct gl_program *prog, GLenum target, 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, GLenum target, GLuint id,
+                  bool is_arb_asm);
 
 extern void
 _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
index 77b7a26..b104649 100644
--- a/src/mesa/state_tracker/st_cb_program.c
+++ b/src/mesa/state_tracker/st_cb_program.c
@@ -54,38 +54,39 @@
  * fragment program.
  */
 static struct gl_program *
-st_new_program(struct gl_context *ctx, GLenum target, GLuint id)
+st_new_program(struct gl_context *ctx, GLenum target, 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, target, id);
+      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
    }
    case GL_FRAGMENT_PROGRAM_ARB: {
       struct st_fragment_program *prog = rzalloc(NULL,
                                                  struct st_fragment_program);
-      return _mesa_init_gl_program(&prog->Base, target, id);
+      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
    }
    case GL_GEOMETRY_PROGRAM_NV: {
       struct st_geometry_program *prog = rzalloc(NULL,
                                                  struct st_geometry_program);
-      return _mesa_init_gl_program(&prog->Base, target, id);
+      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
    }
    case GL_TESS_CONTROL_PROGRAM_NV: {
       struct st_tessctrl_program *prog = rzalloc(NULL,
                                                  struct st_tessctrl_program);
-      return _mesa_init_gl_program(&prog->Base, target, id);
+      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
    }
    case GL_TESS_EVALUATION_PROGRAM_NV: {
       struct st_tesseval_program *prog = rzalloc(NULL,
                                                  struct st_tesseval_program);
-      return _mesa_init_gl_program(&prog->Base, target, id);
+      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
    }
    case GL_COMPUTE_PROGRAM_NV: {
       struct st_compute_program *prog = rzalloc(NULL,
                                                 struct st_compute_program);
-      return _mesa_init_gl_program(&prog->Base, target, id);
+      return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
    }
    default:
       assert(0);
@@ -290,7 +291,7 @@ 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,
-         curProg->Id);
+         curProg->Id, true);
    struct st_fragment_program *stfp = (struct st_fragment_program *)prog;
    stfp->ati_fs = curProg;
    return prog;
-- 
2.9.3



More information about the mesa-dev mailing list