From: Marek Olšák Date: Tue, 31 Mar 2020 14:03:55 +0000 (-0400) Subject: mesa: replace GLenum target with gl_shader_stage in NewProgram X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ad5da3e63ee368e3fa420d4785c698273614683b;p=mesa.git mesa: replace GLenum target with gl_shader_stage in NewProgram So that the GLSL compiler doesn't have to use the GLenum conversion functions. Reviewed-by: Timothy Arceri Part-of: --- diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index 8a876fcecee..b3175090c71 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -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); diff --git a/src/compiler/glsl/serialize.cpp b/src/compiler/glsl/serialize.cpp index 11cae46dd8b..d4aacc1cb95 100644 --- a/src/compiler/glsl/serialize.cpp +++ b/src/compiler/glsl/serialize.cpp @@ -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; diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp index 4b473501622..9a7f7d58ed6 100644 --- a/src/compiler/glsl/standalone.cpp +++ b/src/compiler/glsl/standalone.cpp @@ -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; diff --git a/src/mesa/drivers/dri/i915/i915_fragprog.c b/src/mesa/drivers/dri/i915/i915_fragprog.c index 6493ab99b1e..95a60d1cce0 100644 --- a/src/mesa/drivers/dri/i915/i915_fragprog.c +++ b/src/mesa/drivers/dri/i915/i915_fragprog.c @@ -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); } } diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c index 412be5ec599..be4347881f2 100644 --- a/src/mesa/drivers/dri/i965/brw_program.c +++ b/src/mesa/drivers/dri/i965/brw_program.c @@ -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; diff --git a/src/mesa/drivers/dri/r200/r200_vertprog.c b/src/mesa/drivers/dri/r200/r200_vertprog.c index 7076ec0c7f3..0c51b191dfc 100644 --- a/src/mesa/drivers/dri/r200/r200_vertprog.c +++ b/src/mesa/drivers/dri/r200/r200_vertprog.c @@ -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"); diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c index 67162946015..e6fb7cac85b 100644 --- a/src/mesa/main/arbprogram.c +++ b/src/mesa/main/arbprogram.c @@ -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; diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index b7973e1c6ae..4a7d775db45 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -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); diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index 04126fe9b90..57026793ea1 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -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; diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c index 9a663074816..64daf54ec42 100644 --- a/src/mesa/main/glspirv.c +++ b/src/mesa/main/glspirv.c @@ -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); diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index 357368b38de..51e15178ce7 100644 --- a/src/mesa/main/shared.c +++ b/src/mesa/main/shared.c @@ -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); diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c index 754e3d480b8..e9a2c96bee5 100644 --- a/src/mesa/program/program.c +++ b/src/mesa/program/program.c @@ -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); } diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h index 49e888e57df..7de6804047a 100644 --- a/src/mesa/program/program.h +++ b/src/mesa/program/program.h @@ -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 diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 37674c3edea..f01e1374ebf 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -55,26 +55,21 @@ * 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;