diff options
author | Brian <[email protected]> | 2006-12-19 18:46:56 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2006-12-19 18:46:56 -0700 |
commit | 65a18442e5d846940714bb662f5b1bb47ab60c29 (patch) | |
tree | db8554850401753e441a8c49b815f48f7df5a150 /src/mesa/shader/slang | |
parent | 0bf5dbe002a64e198f55724cc1542602c012490f (diff) |
Clean-up and re-org of the main GLSL object types.
Use the gl_shader struct as it should be.
Renamed gl_linked_program to gl_shader_program.
Store both shaders and programs in the same hash table and use the Type field
to distinguish them.
Diffstat (limited to 'src/mesa/shader/slang')
-rw-r--r-- | src/mesa/shader/slang/slang_compile.c | 23 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_compile.h | 2 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_link.h | 2 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_link2.c | 80 |
4 files changed, 63 insertions, 44 deletions
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 6aed167e3fd..286e25d54bd 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -2223,6 +2223,7 @@ compile_object(grammar * id, const char *source, slang_code_object * object, } +#if 0 static void slang_create_uniforms(const slang_export_data_table *exports, struct gl_program *program) @@ -2237,16 +2238,34 @@ slang_create_uniforms(const slang_export_data_table *exports, } } } +#endif GLboolean _slang_compile(const char *source, slang_code_object * object, slang_unit_type type, slang_info_log * infolog, - struct gl_program *program) + struct gl_shader *shader) { + GET_CURRENT_CONTEXT(ctx); + struct gl_program *program; GLboolean success; grammar id = 0; + /* XXX temporary hack */ + if (!shader->Programs) { + GLenum progTarget; + if (shader->Type == GL_VERTEX_SHADER) + progTarget = GL_VERTEX_PROGRAM_ARB; + else + progTarget = GL_FRAGMENT_PROGRAM_ARB; + shader->Programs + = (struct gl_program **) malloc(sizeof(struct gl_program*)); + shader->Programs[0] = _mesa_new_program(ctx, progTarget, 1); + shader->NumPrograms = 1; + } + program = shader->Programs[0]; + assert(program); + _slang_code_object_dtr(object); _slang_code_object_ctr(object); @@ -2265,7 +2284,7 @@ _slang_compile(const char *source, slang_code_object * object, #if NEW_SLANG { GET_CURRENT_CONTEXT(ctx); - slang_create_uniforms(&object->expdata, program); + slang_create_uniforms(&object->expdata, shader); _mesa_print_program(program); _mesa_print_program_parameters(ctx, program); } diff --git a/src/mesa/shader/slang/slang_compile.h b/src/mesa/shader/slang/slang_compile.h index a41c00a3f5e..8a72f43486a 100644 --- a/src/mesa/shader/slang/slang_compile.h +++ b/src/mesa/shader/slang/slang_compile.h @@ -109,7 +109,7 @@ int slang_info_log_warning (slang_info_log *, const char *, ...); void slang_info_log_memory (slang_info_log *); extern GLboolean -_slang_compile (const char *, slang_code_object *, slang_unit_type, slang_info_log *, struct gl_program *program); +_slang_compile (const char *, slang_code_object *, slang_unit_type, slang_info_log *, struct gl_shader *shader); #ifdef __cplusplus } diff --git a/src/mesa/shader/slang/slang_link.h b/src/mesa/shader/slang/slang_link.h index e96dd51ed47..f56d717873b 100644 --- a/src/mesa/shader/slang/slang_link.h +++ b/src/mesa/shader/slang/slang_link.h @@ -351,7 +351,7 @@ _slang_link (slang_program *, slang_code_object **, GLuint); extern void _slang_link2(GLcontext *ctx, GLhandleARB h, - struct gl_linked_program *linked); + struct gl_shader_program *shProg); #ifdef __cplusplus } diff --git a/src/mesa/shader/slang/slang_link2.c b/src/mesa/shader/slang/slang_link2.c index 425ad7a87c1..fa29e42706e 100644 --- a/src/mesa/shader/slang/slang_link2.c +++ b/src/mesa/shader/slang/slang_link2.c @@ -43,7 +43,7 @@ static GLboolean -link_varying_vars(struct gl_linked_program *linked, struct gl_program *prog) +link_varying_vars(struct gl_shader_program *shProg, struct gl_program *prog) { GLuint *map, i, firstVarying, newFile; GLbitfield varsWritten, varsRead; @@ -57,17 +57,17 @@ link_varying_vars(struct gl_linked_program *linked, struct gl_program *prog) const struct gl_program_parameter *var = prog->Varying->Parameters + i; - GLint j = _mesa_lookup_parameter_index(linked->Varying, -1, var->Name); + GLint j = _mesa_lookup_parameter_index(shProg->Varying, -1, var->Name); if (j >= 0) { /* already in list, check size */ - if (var->Size != linked->Varying->Parameters[j].Size) { + if (var->Size != shProg->Varying->Parameters[j].Size) { /* error */ return GL_FALSE; } } else { /* not already in linked list */ - j = _mesa_add_varying(linked->Varying, var->Name, var->Size); + j = _mesa_add_varying(shProg->Varying, var->Name, var->Size); } ASSERT(j >= 0); @@ -143,7 +143,7 @@ is_uniform(enum register_file file) static GLboolean -link_uniform_vars(struct gl_linked_program *linked, struct gl_program *prog) +link_uniform_vars(struct gl_shader_program *shProg, struct gl_program *prog) { GLuint *map, i; @@ -161,12 +161,12 @@ link_uniform_vars(struct gl_linked_program *linked, struct gl_program *prog) assert(is_uniform(p->Type)); if (p->Name) { - j = _mesa_lookup_parameter_index(linked->Uniforms, -1, p->Name); + j = _mesa_lookup_parameter_index(shProg->Uniforms, -1, p->Name); } else { GLuint swizzle; ASSERT(p->Type == PROGRAM_CONSTANT); - if (_mesa_lookup_parameter_constant(linked->Uniforms, pVals, + if (_mesa_lookup_parameter_constant(shProg->Uniforms, pVals, p->Size, &j, &swizzle)) { assert(j >= 0); } @@ -177,21 +177,21 @@ link_uniform_vars(struct gl_linked_program *linked, struct gl_program *prog) if (j >= 0) { /* already in list, check size XXX check this */ - assert(p->Size == linked->Uniforms->Parameters[j].Size); + assert(p->Size == shProg->Uniforms->Parameters[j].Size); } else { /* not already in linked list */ switch (p->Type) { case PROGRAM_ENV_PARAM: - j = _mesa_add_named_parameter(linked->Uniforms, p->Name, pVals); + j = _mesa_add_named_parameter(shProg->Uniforms, p->Name, pVals); case PROGRAM_CONSTANT: - j = _mesa_add_named_constant(linked->Uniforms, p->Name, pVals, p->Size); + j = _mesa_add_named_constant(shProg->Uniforms, p->Name, pVals, p->Size); break; case PROGRAM_STATE_VAR: - j = _mesa_add_state_reference(linked->Uniforms, (const GLint *) p->StateIndexes); + j = _mesa_add_state_reference(shProg->Uniforms, (const GLint *) p->StateIndexes); break; case PROGRAM_UNIFORM: - j = _mesa_add_uniform(linked->Uniforms, p->Name, p->Size); + j = _mesa_add_uniform(shProg->Uniforms, p->Name, p->Size); break; default: abort(); @@ -287,41 +287,41 @@ slang_resolve_branches(struct gl_program *prog) void _slang_link2(GLcontext *ctx, GLhandleARB programObj, - struct gl_linked_program *linked) + struct gl_shader_program *shProg) { struct gl_vertex_program *vertProg; struct gl_fragment_program *fragProg; GLuint i; - _mesa_free_linked_program_data(ctx, linked); + _mesa_free_shader_program_data(ctx, shProg); - linked->Uniforms = _mesa_new_parameter_list(); - linked->Varying = _mesa_new_parameter_list(); + shProg->Uniforms = _mesa_new_parameter_list(); + shProg->Varying = _mesa_new_parameter_list(); /** * Find attached vertex shader, fragment shader */ vertProg = NULL; fragProg = NULL; - for (i = 0; i < linked->NumShaders; i++) { - if (linked->Shaders[i]->Target == GL_VERTEX_PROGRAM_ARB) - vertProg = (struct gl_vertex_program *) linked->Shaders[i]; - else if (linked->Shaders[i]->Target == GL_FRAGMENT_PROGRAM_ARB) - fragProg = (struct gl_fragment_program *) linked->Shaders[i]; + for (i = 0; i < shProg->NumShaders; i++) { + if (shProg->Shaders[i]->Type == GL_VERTEX_SHADER) + vertProg = (struct gl_vertex_program *) shProg->Shaders[i]->Programs[0]; + else if (shProg->Shaders[i]->Type == GL_FRAGMENT_SHADER) + fragProg = (struct gl_fragment_program *) shProg->Shaders[i]->Programs[0]; else _mesa_problem(ctx, "unexpected shader target in slang_link2()"); } if (!vertProg || !fragProg) { /* XXX is it legal to have one but not the other?? */ /* XXX record error */ - linked->LinkStatus = GL_FALSE; + shProg->LinkStatus = GL_FALSE; return; } if (!vertProg->Base.Varying || !fragProg->Base.Varying) { /* temporary */ _mesa_problem(ctx, "vertex/fragment program lacks varying list!"); - linked->LinkStatus = GL_FALSE; + shProg->LinkStatus = GL_FALSE; return; } @@ -329,25 +329,25 @@ _slang_link2(GLcontext *ctx, * Make copies of the vertex/fragment programs now since we'll be * changing src/dst registers after merging the uniforms and varying vars. */ - linked->VertexProgram = (struct gl_vertex_program *) + shProg->VertexProgram = (struct gl_vertex_program *) _mesa_clone_program(ctx, &vertProg->Base); - linked->FragmentProgram = (struct gl_fragment_program *) + shProg->FragmentProgram = (struct gl_fragment_program *) _mesa_clone_program(ctx, &fragProg->Base); - link_varying_vars(linked, &linked->VertexProgram->Base); - link_varying_vars(linked, &linked->FragmentProgram->Base); + link_varying_vars(shProg, &shProg->VertexProgram->Base); + link_varying_vars(shProg, &shProg->FragmentProgram->Base); - link_uniform_vars(linked, &linked->VertexProgram->Base); - link_uniform_vars(linked, &linked->FragmentProgram->Base); + link_uniform_vars(shProg, &shProg->VertexProgram->Base); + link_uniform_vars(shProg, &shProg->FragmentProgram->Base); /* The vertex and fragment programs share a common set of uniforms now */ - _mesa_free_parameter_list(linked->VertexProgram->Base.Parameters); - _mesa_free_parameter_list(linked->FragmentProgram->Base.Parameters); - linked->VertexProgram->Base.Parameters = linked->Uniforms; - linked->FragmentProgram->Base.Parameters = linked->Uniforms; + _mesa_free_parameter_list(shProg->VertexProgram->Base.Parameters); + _mesa_free_parameter_list(shProg->FragmentProgram->Base.Parameters); + shProg->VertexProgram->Base.Parameters = shProg->Uniforms; + shProg->FragmentProgram->Base.Parameters = shProg->Uniforms; - slang_resolve_branches(&linked->VertexProgram->Base); - slang_resolve_branches(&linked->FragmentProgram->Base); + slang_resolve_branches(&shProg->VertexProgram->Base); + slang_resolve_branches(&shProg->FragmentProgram->Base); #if 1 printf("************** original fragment program\n"); @@ -356,8 +356,8 @@ _slang_link2(GLcontext *ctx, #endif #if 1 printf("************** linked fragment prog\n"); - _mesa_print_program(&linked->FragmentProgram->Base); - _mesa_print_program_parameters(ctx, &linked->FragmentProgram->Base); + _mesa_print_program(&shProg->FragmentProgram->Base); + _mesa_print_program_parameters(ctx, &shProg->FragmentProgram->Base); #endif #if 1 printf("************** original vertex program\n"); @@ -366,10 +366,10 @@ _slang_link2(GLcontext *ctx, #endif #if 1 printf("************** linked vertex prog\n"); - _mesa_print_program(&linked->VertexProgram->Base); - _mesa_print_program_parameters(ctx, &linked->VertexProgram->Base); + _mesa_print_program(&shProg->VertexProgram->Base); + _mesa_print_program_parameters(ctx, &shProg->VertexProgram->Base); #endif - linked->LinkStatus = (linked->VertexProgram && linked->FragmentProgram); + shProg->LinkStatus = (shProg->VertexProgram && shProg->FragmentProgram); } |