summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2016-06-05 13:17:51 +1000
committerTimothy Arceri <[email protected]>2016-06-16 10:45:35 +1000
commit31dee99e052902bc08ddbb1009748dc982ac3211 (patch)
tree47e631d7bcd04cc59429b971ce8d685b6cce787b /src/mesa
parentbb1292e2261fa591cf66de443a1b0d4eb7f65cb2 (diff)
mesa/glsl: stop using GL shader type internally
Instead use the internal gl_shader_stage enum everywhere. This makes things more consistent and gets rid of unnecessary conversions. Ideally it would be nice to remove the Type field from gl_shader altogether but currently it is used to differentiate between gl_shader and gl_shader_program in the ShaderObjects hash table. Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/drivers/common/meta.c12
-rw-r--r--src/mesa/drivers/common/meta.h5
-rw-r--r--src/mesa/drivers/dri/i965/brw_link.cpp5
-rw-r--r--src/mesa/drivers/dri/i965/brw_shader.h3
-rw-r--r--src/mesa/main/dd.h2
-rw-r--r--src/mesa/main/ff_fragment_shader.cpp2
-rw-r--r--src/mesa/main/shaderapi.c20
-rw-r--r--src/mesa/main/shaderobj.c6
-rw-r--r--src/mesa/state_tracker/st_glsl_to_nir.cpp6
-rw-r--r--src/mesa/state_tracker/st_glsl_to_tgsi.cpp30
10 files changed, 43 insertions, 48 deletions
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 6dcbc8bdfd8..3c86305d77f 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -121,14 +121,14 @@ _mesa_meta_framebuffer_texture_image(struct gl_context *ctx,
level, layer, false, __func__);
}
-struct gl_shader *
-_mesa_meta_compile_shader_with_debug(struct gl_context *ctx, GLenum target,
- const GLcharARB *source)
+static struct gl_shader *
+meta_compile_shader_with_debug(struct gl_context *ctx, gl_shader_stage stage,
+ const GLcharARB *source)
{
const GLuint name = ~0;
struct gl_shader *sh;
- sh = ctx->Driver.NewShader(ctx, name, target);
+ sh = ctx->Driver.NewShader(ctx, name, stage);
sh->Source = strdup(source);
sh->CompileStatus = false;
_mesa_compile_shader(ctx, sh);
@@ -183,9 +183,9 @@ _mesa_meta_compile_and_link_program(struct gl_context *ctx,
sh_prog->NumShaders = 2;
sh_prog->Shaders = malloc(2 * sizeof(struct gl_shader *));
sh_prog->Shaders[0] =
- _mesa_meta_compile_shader_with_debug(ctx, GL_VERTEX_SHADER, vs_source);
+ meta_compile_shader_with_debug(ctx, MESA_SHADER_VERTEX, vs_source);
sh_prog->Shaders[1] =
- _mesa_meta_compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER, fs_source);
+ meta_compile_shader_with_debug(ctx, MESA_SHADER_FRAGMENT, fs_source);
_mesa_meta_link_program_with_debug(ctx, sh_prog);
diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
index 0a7321c9d88..ba83a6dc21b 100644
--- a/src/mesa/drivers/common/meta.h
+++ b/src/mesa/drivers/common/meta.h
@@ -577,11 +577,6 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
void
_mesa_meta_drawbuffers_from_bitfield(GLbitfield bits);
-struct gl_shader *
-_mesa_meta_compile_shader_with_debug(struct gl_context *ctx, GLenum target,
- const GLcharARB *source);
-
-
void
_mesa_meta_link_program_with_debug(struct gl_context *ctx,
struct gl_shader_program *sh_prog);
diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp b/src/mesa/drivers/dri/i965/brw_link.cpp
index 16bfbaa8d7e..43b61328d6f 100644
--- a/src/mesa/drivers/dri/i965/brw_link.cpp
+++ b/src/mesa/drivers/dri/i965/brw_link.cpp
@@ -185,14 +185,13 @@ process_glsl_ir(gl_shader_stage stage,
}
extern "C" struct gl_shader *
-brw_new_shader(struct gl_context *ctx, GLuint name, GLuint type)
+brw_new_shader(struct gl_context *ctx, GLuint name, gl_shader_stage stage)
{
struct brw_shader *shader;
shader = rzalloc(NULL, struct brw_shader);
if (shader) {
- shader->base.Type = type;
- shader->base.Stage = _mesa_shader_enum_to_shader_stage(type);
+ shader->base.Stage = stage;
shader->base.Name = name;
_mesa_init_shader(ctx, &shader->base);
}
diff --git a/src/mesa/drivers/dri/i965/brw_shader.h b/src/mesa/drivers/dri/i965/brw_shader.h
index 9300f20b253..d74c6d6af9a 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.h
+++ b/src/mesa/drivers/dri/i965/brw_shader.h
@@ -289,7 +289,8 @@ bool brw_cs_precompile(struct gl_context *ctx,
struct gl_program *prog);
GLboolean brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog);
-struct gl_shader *brw_new_shader(struct gl_context *ctx, GLuint name, GLuint type);
+struct gl_shader *brw_new_shader(struct gl_context *ctx, GLuint name,
+ gl_shader_stage stage);
int type_size_scalar(const struct glsl_type *type);
int type_size_vec4(const struct glsl_type *type);
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index de149431572..f918bb6f717 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -784,7 +784,7 @@ struct dd_function_table {
*/
/*@{*/
struct gl_shader *(*NewShader)(struct gl_context *ctx,
- GLuint name, GLenum type);
+ GLuint name, gl_shader_stage stage);
void (*UseProgram)(struct gl_context *ctx, struct gl_shader_program *shProg);
/*@}*/
diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index 26bf1625878..4977225220a 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -1199,7 +1199,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key)
_mesa_glsl_parse_state *state;
p.mem_ctx = ralloc_context(NULL);
- p.shader = ctx->Driver.NewShader(ctx, 0, GL_FRAGMENT_SHADER);
+ p.shader = ctx->Driver.NewShader(ctx, 0, MESA_SHADER_FRAGMENT);
p.shader->ir = new(p.shader) exec_list;
state = new(p.shader) _mesa_glsl_parse_state(ctx, MESA_SHADER_FRAGMENT,
p.shader);
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 9d440a0fd03..00caa1b4459 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -291,7 +291,7 @@ attach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
_mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader");
return;
} else if (same_type_disallowed &&
- shProg->Shaders[i]->Type == sh->Type) {
+ shProg->Shaders[i]->Stage == sh->Stage) {
/* Shader with the same type is already attached to this program,
* OpenGL ES 2.0 and 3.0 specs say:
*
@@ -334,7 +334,9 @@ create_shader(struct gl_context *ctx, GLenum type)
_mesa_HashLockMutex(ctx->Shared->ShaderObjects);
name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
- sh = ctx->Driver.NewShader(ctx, name, type);
+ sh = ctx->Driver.NewShader(ctx, name,
+ _mesa_shader_enum_to_shader_stage(type));
+ sh->Type = type;
_mesa_HashInsertLocked(ctx->Shared->ShaderObjects, name, sh);
_mesa_HashUnlockMutex(ctx->Shared->ShaderObjects);
@@ -456,11 +458,11 @@ detach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
#ifdef DEBUG
/* sanity check - make sure the new list's entries are sensible */
for (j = 0; j < shProg->NumShaders; j++) {
- assert(shProg->Shaders[j]->Type == GL_VERTEX_SHADER ||
- shProg->Shaders[j]->Type == GL_TESS_CONTROL_SHADER ||
- shProg->Shaders[j]->Type == GL_TESS_EVALUATION_SHADER ||
- shProg->Shaders[j]->Type == GL_GEOMETRY_SHADER ||
- shProg->Shaders[j]->Type == GL_FRAGMENT_SHADER);
+ assert(shProg->Shaders[j]->Stage == MESA_SHADER_VERTEX ||
+ shProg->Shaders[j]->Stage == MESA_SHADER_TESS_CTRL ||
+ shProg->Shaders[j]->Stage == MESA_SHADER_TESS_EVAL ||
+ shProg->Shaders[j]->Stage == MESA_SHADER_GEOMETRY ||
+ shProg->Shaders[j]->Stage == MESA_SHADER_FRAGMENT);
assert(shProg->Shaders[j]->RefCount > 0);
}
#endif
@@ -1117,9 +1119,9 @@ _mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg)
shProg->LinkStatus ? "Success" : "Failed");
for (i = 0; i < shProg->NumShaders; i++) {
- printf(" shader %u, type 0x%x\n",
+ printf(" shader %u, stage %u\n",
shProg->Shaders[i]->Name,
- shProg->Shaders[i]->Type);
+ shProg->Shaders[i]->Stage);
}
}
}
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index 189317c3a46..8283555740b 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -99,14 +99,12 @@ _mesa_init_shader(struct gl_context *ctx, struct gl_shader *shader)
* Called via ctx->Driver.NewShader()
*/
struct gl_shader *
-_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type)
+_mesa_new_shader(struct gl_context *ctx, GLuint name, gl_shader_stage stage)
{
struct gl_shader *shader;
- assert(_mesa_validate_shader_target(ctx, type));
shader = rzalloc(NULL, struct gl_shader);
if (shader) {
- shader->Type = type;
- shader->Stage = _mesa_shader_enum_to_shader_stage(type);
+ shader->Stage = stage;
shader->Name = name;
_mesa_init_shader(ctx, shader);
}
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index 98c075fcb2c..a8805645b6e 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -422,12 +422,12 @@ st_nir_get_mesa_program(struct gl_context *ctx,
struct st_vertex_program *stvp;
struct st_fragment_program *stfp;
- switch (shader->Type) {
- case GL_VERTEX_SHADER:
+ switch (shader->Stage) {
+ case MESA_SHADER_VERTEX:
stvp = (struct st_vertex_program *)prog;
stvp->shader_program = shader_program;
break;
- case GL_FRAGMENT_SHADER:
+ case MESA_SHADER_FRAGMENT:
stfp = (struct st_fragment_program *)prog;
stfp->shader_program = shader_program;
break;
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 8c6fe79d832..9de603c042f 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -6459,7 +6459,7 @@ get_mesa_program_tgsi(struct gl_context *ctx,
GLenum target = _mesa_shader_stage_to_program(shader->Stage);
bool progress;
struct gl_shader_compiler_options *options =
- &ctx->Const.ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(shader->Type)];
+ &ctx->Const.ShaderCompilerOptions[shader->Stage];
struct pipe_screen *pscreen = ctx->st->pipe->screen;
unsigned ptarget = st_shader_stage_to_ptarget(shader->Stage);
@@ -6554,8 +6554,8 @@ get_mesa_program_tgsi(struct gl_context *ctx,
/* Perform optimizations on the instructions in the glsl_to_tgsi_visitor. */
v->simplify_cmp();
- if (shader->Type != GL_TESS_CONTROL_SHADER &&
- shader->Type != GL_TESS_EVALUATION_SHADER)
+ if (shader->Stage != MESA_SHADER_TESS_CTRL &&
+ shader->Stage != MESA_SHADER_TESS_EVAL)
v->copy_propagate();
while (v->eliminate_dead_code());
@@ -6591,7 +6591,7 @@ get_mesa_program_tgsi(struct gl_context *ctx,
shader->ir = NULL;
/* This must be done before the uniform storage is associated. */
- if (shader->Type == GL_FRAGMENT_SHADER &&
+ if (shader->Stage == MESA_SHADER_FRAGMENT &&
(prog->InputsRead & VARYING_BIT_POS ||
prog->SystemValuesRead & (1 << SYSTEM_VALUE_FRAG_COORD))) {
static const gl_state_index wposTransformState[STATE_LENGTH] = {
@@ -6627,28 +6627,28 @@ get_mesa_program_tgsi(struct gl_context *ctx,
struct st_tesseval_program *sttep;
struct st_compute_program *stcp;
- switch (shader->Type) {
- case GL_VERTEX_SHADER:
+ switch (shader->Stage) {
+ case MESA_SHADER_VERTEX:
stvp = (struct st_vertex_program *)prog;
stvp->glsl_to_tgsi = v;
break;
- case GL_FRAGMENT_SHADER:
+ case MESA_SHADER_FRAGMENT:
stfp = (struct st_fragment_program *)prog;
stfp->glsl_to_tgsi = v;
break;
- case GL_GEOMETRY_SHADER:
+ case MESA_SHADER_GEOMETRY:
stgp = (struct st_geometry_program *)prog;
stgp->glsl_to_tgsi = v;
break;
- case GL_TESS_CONTROL_SHADER:
+ case MESA_SHADER_TESS_CTRL:
sttcp = (struct st_tessctrl_program *)prog;
sttcp->glsl_to_tgsi = v;
break;
- case GL_TESS_EVALUATION_SHADER:
+ case MESA_SHADER_TESS_EVAL:
sttep = (struct st_tesseval_program *)prog;
sttep->glsl_to_tgsi = v;
break;
- case GL_COMPUTE_SHADER:
+ case MESA_SHADER_COMPUTE:
stcp = (struct st_compute_program *)prog;
stcp->glsl_to_tgsi = v;
break;
@@ -6671,9 +6671,9 @@ get_mesa_program(struct gl_context *ctx,
pscreen->get_shader_param(pscreen, ptarget, PIPE_SHADER_CAP_PREFERRED_IR);
if (preferred_ir == PIPE_SHADER_IR_NIR) {
/* TODO only for GLSL VS/FS for now: */
- switch (shader->Type) {
- case GL_VERTEX_SHADER:
- case GL_FRAGMENT_SHADER:
+ switch (shader->Stage) {
+ case MESA_SHADER_VERTEX:
+ case MESA_SHADER_FRAGMENT:
return st_nir_get_mesa_program(ctx, shader_program, shader);
default:
break;
@@ -6768,7 +6768,7 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
bool progress;
exec_list *ir = prog->_LinkedShaders[i]->ir;
- gl_shader_stage stage = _mesa_shader_enum_to_shader_stage(prog->_LinkedShaders[i]->Type);
+ gl_shader_stage stage = prog->_LinkedShaders[i]->Stage;
const struct gl_shader_compiler_options *options =
&ctx->Const.ShaderCompilerOptions[stage];
unsigned ptarget = st_shader_stage_to_ptarget(stage);