diff options
-rw-r--r-- | src/mesa/main/context.c | 3 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 25 | ||||
-rw-r--r-- | src/mesa/main/state.c | 9 | ||||
-rw-r--r-- | src/mesa/shader/shader_api.c | 385 | ||||
-rw-r--r-- | src/mesa/shader/shader_api.h | 16 | ||||
-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 |
9 files changed, 288 insertions, 257 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index c5220b5b2eb..2196591ba26 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -706,7 +706,6 @@ alloc_shared_state( GLcontext *ctx ) #if FEATURE_ARB_shader_objects ss->ShaderObjects = _mesa_NewHashTable(); - ss->ProgramObjects = _mesa_NewHashTable(); #endif ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D); @@ -785,8 +784,6 @@ alloc_shared_state( GLcontext *ctx ) #if FEATURE_ARB_shader_objects if (ss->ShaderObjects) _mesa_DeleteHashTable (ss->ShaderObjects); - if (ss->ProgramObjects) - _mesa_DeleteHashTable (ss->ProgramObjects); #endif #if FEATURE_EXT_framebuffer_object diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 4a8f7d22e30..57f174a7d47 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -45,6 +45,12 @@ /** + * Special, internal token + */ +#define GL_SHADER_PROGRAM 0x9999 + + +/** * Color channel data type. */ #if CHAN_BITS == 8 @@ -2044,13 +2050,13 @@ struct gl_query_state /** * A GLSL shader object - * A collection of one or more gl_programs... */ struct gl_shader { - GLenum Type; /**< GL_FRAGMENT_SHADER || GL_VERTEX_SHADER */ + GLenum Type; /**< GL_FRAGMENT_SHADER || GL_VERTEX_SHADER (first field!) */ GLuint Name; /**< AKA the handle */ - GLchar *Source; /**< Source code string */ + GLint RefCount; + const GLchar *Source; /**< Source code string */ GLboolean CompileStatus; GLboolean DeletePending; GLuint NumPrograms; /**< size of Programs[] array */ @@ -2061,15 +2067,14 @@ struct gl_shader /** * This corresponds to a GLSL "program" and is basically a linked collection - * of "shaders" (which are Mesa gl_programs). - * Yes, the terminology is a bit confusing. + * of "shaders". */ -struct gl_linked_program +struct gl_shader_program { - GLenum Type; + GLenum Type; /**< Always GL_SHADER_PROGRAM (internal token) */ GLuint Name; /**< aka handle or ID */ GLuint NumShaders; /**< total number of shaders in this program */ - struct gl_program **Shaders; /**< List of the shaders */ + struct gl_shader **Shaders; /**< List of the shaders */ struct gl_vertex_program *VertexProgram; /**< Linked vertex program */ struct gl_fragment_program *FragmentProgram; /**< Linked fragment prog */ struct gl_program_parameter_list *Uniforms; /**< Plus constants, etc */ @@ -2089,7 +2094,7 @@ struct gl_shader_state { GLboolean _VertexShaderPresent; GLboolean _FragmentShaderPresent; - struct gl_linked_program *CurrentProgram; + struct gl_shader_program *CurrentProgram; }; @@ -2150,8 +2155,8 @@ struct gl_shared_state #endif #if FEATURE_ARB_shader_objects + /** Table of both gl_shader and gl_shader_program objects */ struct _mesa_HashTable *ShaderObjects; - struct _mesa_HashTable *ProgramObjects; #endif #if FEATURE_EXT_framebuffer_object diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index 1d8666888ef..947d3136d5b 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -949,8 +949,7 @@ update_arrays( GLcontext *ctx ) static void update_program(GLcontext *ctx) { - const struct gl_linked_program *linked = ctx->Shader.CurrentProgram; - + const struct gl_shader_program *shProg = ctx->Shader.CurrentProgram; /* These _Enabled flags indicate if the program is enabled AND valid. */ ctx->VertexProgram._Enabled = ctx->VertexProgram.Enabled @@ -973,10 +972,10 @@ update_program(GLcontext *ctx) ctx->FragmentProgram._Current = NULL; - if (linked && linked->LinkStatus) { + if (shProg && shProg->LinkStatus) { /* Use shader programs */ - ctx->VertexProgram._Current = linked->VertexProgram; - ctx->FragmentProgram._Current = linked->FragmentProgram; + ctx->VertexProgram._Current = shProg->VertexProgram; + ctx->FragmentProgram._Current = shProg->FragmentProgram; } else { if (ctx->VertexProgram._Enabled) { diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index ab2fd438c8c..e49feea3d86 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -78,39 +78,39 @@ copy_string(GLchar *dst, GLsizei maxLength, GLsizei *length, const GLchar *src) void _mesa_attach_shader(GLcontext *ctx, GLuint program, GLuint shader) { - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); - struct gl_program *prog = _mesa_lookup_shader(ctx, shader); - const GLuint n = linked->NumShaders; + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); + struct gl_shader *sh = _mesa_lookup_shader(ctx, shader); + const GLuint n = shProg->NumShaders; GLuint i; - if (!linked || !prog) { + if (!shProg || !sh) { _mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader(bad program or shader name)"); return; } for (i = 0; i < n; i++) { - if (linked->Shaders[i] == prog) { + if (shProg->Shaders[i] == sh) { /* already attached */ return; } } /* grow list */ - linked->Shaders = (struct gl_program **) - _mesa_realloc(linked->Shaders, - n * sizeof(struct gl_program *), - (n + 1) * sizeof(struct gl_program *)); - if (!linked->Shaders) { + shProg->Shaders = (struct gl_shader **) + _mesa_realloc(shProg->Shaders, + n * sizeof(struct gl_shader *), + (n + 1) * sizeof(struct gl_shader *)); + if (!shProg->Shaders) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader"); return; } /* append */ - linked->Shaders[n] = prog; - prog->RefCount++; - linked->NumShaders++; + shProg->Shaders[n] = sh; + sh->RefCount++; + shProg->NumShaders++; } @@ -118,10 +118,10 @@ void _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index, const GLchar *name) { - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); - if (!linked) { + if (!shProg) { _mesa_error(ctx, GL_INVALID_OPERATION, "glBindAttribLocation(program)"); return; } @@ -141,26 +141,22 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index, GLuint _mesa_create_shader(GLcontext *ctx, GLenum type) { - struct gl_program *newProg; + struct gl_shader *sh; GLuint name; name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1); switch (type) { - case GL_FRAGMENT_SHADER_ARB: - /* alloc new gl_fragment_program */ - newProg = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, name); - break; - case GL_VERTEX_SHADER_ARB: - /* alloc new gl_vertex_program */ - newProg = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, name); + case GL_FRAGMENT_SHADER: + case GL_VERTEX_SHADER: + sh = _mesa_new_shader(ctx, name, type); break; default: _mesa_error(ctx, GL_INVALID_ENUM, "CreateShader(type)"); return 0; } - _mesa_HashInsert(ctx->Shared->ShaderObjects, name, newProg); + _mesa_HashInsert(ctx->Shared->ShaderObjects, name, sh); return name; } @@ -170,12 +166,12 @@ GLuint _mesa_create_program(GLcontext *ctx) { GLuint name; - struct gl_linked_program *linked; + struct gl_shader_program *shProg; - name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ProgramObjects, 1); - linked = _mesa_new_linked_program(ctx, name); + name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1); + shProg = _mesa_new_shader_program(ctx, name); - _mesa_HashInsert(ctx->Shared->ProgramObjects, name, linked); + _mesa_HashInsert(ctx->Shared->ShaderObjects, name, shProg); return name; } @@ -184,17 +180,17 @@ _mesa_create_program(GLcontext *ctx) void _mesa_delete_program2(GLcontext *ctx, GLuint name) { - struct gl_linked_program *linked; + struct gl_shader_program *shProg; - linked = _mesa_lookup_linked_program(ctx, name); - if (!linked) { + shProg = _mesa_lookup_shader_program(ctx, name); + if (!shProg) { _mesa_error(ctx, GL_INVALID_OPERATION, "glDeleteProgram(name)"); return; } /* XXX refcounting! */ - _mesa_HashRemove(ctx->Shared->ProgramObjects, name); - _mesa_delete_linked_program(ctx, linked); + _mesa_HashRemove(ctx->Shared->ShaderObjects, name); + _mesa_delete_shader_program(ctx, shProg); } @@ -212,38 +208,38 @@ _mesa_delete_shader(GLcontext *ctx, GLuint shader) void _mesa_detach_shader(GLcontext *ctx, GLuint program, GLuint shader) { - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); - const GLuint n = linked->NumShaders; + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); + const GLuint n = shProg->NumShaders; GLuint i, j; - if (!linked) { + if (!shProg) { _mesa_error(ctx, GL_INVALID_OPERATION, "glDetachShader(bad program or shader name)"); return; } for (i = 0; i < n; i++) { - if (linked->Shaders[i]->Id == shader) { - struct gl_program **newList; + if (shProg->Shaders[i]->Name == shader) { + struct gl_shader **newList; /* found it */ /* alloc new, smaller array */ - newList = (struct gl_program **) - _mesa_malloc((n - 1) * sizeof(struct gl_program *)); + newList = (struct gl_shader **) + _mesa_malloc((n - 1) * sizeof(struct gl_shader *)); if (!newList) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDetachShader"); return; } for (j = 0; j < i; j++) { - newList[j] = linked->Shaders[j]; + newList[j] = shProg->Shaders[j]; } while (++i < n) - newList[j++] = linked->Shaders[i]; - _mesa_free(linked->Shaders); + newList[j++] = shProg->Shaders[i]; + _mesa_free(shProg->Shaders); /* XXX refcounting! */ - linked->Shaders = newList; + shProg->Shaders = newList; return; } } @@ -262,23 +258,23 @@ _mesa_get_active_attrib(GLcontext *ctx, GLuint program, GLuint index, static const GLenum vec_types[] = { GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4 }; - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); GLint sz; - if (!linked) { + if (!shProg) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetActiveUniform"); return; } - if (!linked->Attributes || index >= linked->Attributes->NumParameters) { + if (!shProg->Attributes || index >= shProg->Attributes->NumParameters) { _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniform(index)"); return; } copy_string(nameOut, maxLength, length, - linked->Attributes->Parameters[index].Name); - sz = linked->Attributes->Parameters[index].Size; + shProg->Attributes->Parameters[index].Name); + sz = shProg->Attributes->Parameters[index].Size; if (size) *size = sz; if (type) @@ -297,23 +293,23 @@ _mesa_get_active_uniform(GLcontext *ctx, GLuint program, GLuint index, static const GLenum vec_types[] = { GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4 }; - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); GLint sz; - if (!linked) { + if (!shProg) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetActiveUniform"); return; } - if (!linked->Uniforms || index >= linked->Uniforms->NumParameters) { + if (!shProg->Uniforms || index >= shProg->Uniforms->NumParameters) { _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniform(index)"); return; } copy_string(nameOut, maxLength, length, - linked->Uniforms->Parameters[index].Name); - sz = linked->Uniforms->Parameters[index].Size; + shProg->Uniforms->Parameters[index].Name); + sz = shProg->Uniforms->Parameters[index].Size; if (size) *size = sz; if (type) @@ -328,12 +324,12 @@ void _mesa_get_attached_shaders(GLcontext *ctx, GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj) { - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); - if (linked) { + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); + if (shProg) { GLuint i; - for (i = 0; i < maxCount && i < linked->NumShaders; i++) { - obj[i] = linked->Shaders[i]->Id; + for (i = 0; i < maxCount && i < shProg->NumShaders; i++) { + obj[i] = shProg->Shaders[i]->Name; } if (count) *count = i; @@ -348,15 +344,15 @@ GLint _mesa_get_attrib_location(GLcontext *ctx, GLuint program, const GLchar *name) { - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); - if (!linked) { + if (!shProg) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetAttribLocation"); return -1; } - if (!linked->LinkStatus) { + if (!shProg->LinkStatus) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetAttribLocation(program not linked)"); return -1; @@ -365,10 +361,10 @@ _mesa_get_attrib_location(GLcontext *ctx, GLuint program, if (!name) return -1; - if (linked->Attributes) { + if (shProg->Attributes) { GLuint i; - for (i = 0; i < linked->Attributes->NumParameters; i++) { - if (!strcmp(linked->Attributes->Parameters[i].Name, name)) { + for (i = 0; i < shProg->Attributes->NumParameters; i++) { + if (!strcmp(shProg->Attributes->Parameters[i].Name, name)) { return i; } } @@ -405,41 +401,41 @@ void _mesa_get_programiv(GLcontext *ctx, GLuint program, GLenum pname, GLint *params) { - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); - if (!linked) { + if (!shProg) { _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramiv(program)"); return; } switch (pname) { case GL_DELETE_STATUS: - *params = linked->DeletePending; + *params = shProg->DeletePending; break; case GL_LINK_STATUS: - *params = linked->LinkStatus; + *params = shProg->LinkStatus; break; case GL_VALIDATE_STATUS: - *params = linked->Validated; + *params = shProg->Validated; break; case GL_INFO_LOG_LENGTH: - *params = linked->InfoLog ? strlen(linked->InfoLog) : 0; + *params = shProg->InfoLog ? strlen(shProg->InfoLog) : 0; break; case GL_ATTACHED_SHADERS: - *params = linked->NumShaders; + *params = shProg->NumShaders; break; case GL_ACTIVE_ATTRIBUTES: - *params = linked->Uniforms ? linked->Uniforms->NumParameters : 0; + *params = shProg->Uniforms ? shProg->Uniforms->NumParameters : 0; break; case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: - *params = _mesa_parameter_longest_name(linked->Attributes); + *params = _mesa_parameter_longest_name(shProg->Attributes); break; case GL_ACTIVE_UNIFORMS: - *params = linked->Uniforms ? linked->Uniforms->NumParameters : 0; + *params = shProg->Uniforms ? shProg->Uniforms->NumParameters : 0; break; case GL_ACTIVE_UNIFORM_MAX_LENGTH: - *params = _mesa_parameter_longest_name(linked->Uniforms); + *params = _mesa_parameter_longest_name(shProg->Uniforms); break; default: _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramiv(pname)"); @@ -451,16 +447,13 @@ _mesa_get_programiv(GLcontext *ctx, GLuint program, void _mesa_get_shaderiv(GLcontext *ctx, GLuint name, GLenum pname, GLint *params) { -#if 0 - struct gl_program *shader = _mesa_lookup_shader(ctx, name); + struct gl_shader *shader = _mesa_lookup_shader(ctx, name); if (!shader) { _mesa_error(ctx, GL_INVALID_VALUE, "glGetShaderiv(shader)"); return; } -#else - struct gl_shader *shader; -#endif + switch (pname) { case GL_SHADER_TYPE: *params = shader->Type; @@ -488,14 +481,13 @@ void _mesa_get_program_info_log(GLcontext *ctx, GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog) { - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); - if (!linked) { + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); + if (!shProg) { _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramInfoLog(program)"); return; } - /* XXX also test length, infoLog params for NULL? */ - copy_string(linked->InfoLog, bufSize, length, infoLog); + copy_string(infoLog, bufSize, length, shProg->InfoLog); } @@ -503,14 +495,12 @@ void _mesa_get_shader_info_log(GLcontext *ctx, GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) { - struct gl_program *shProg = _mesa_lookup_shader(ctx, shader); - if (!shProg) { + struct gl_shader *sh = _mesa_lookup_shader(ctx, shader); + if (!sh) { _mesa_error(ctx, GL_INVALID_VALUE, "glGetShaderInfoLog(shader)"); return; } - /* - copy_string(shProg->InfoLog, bufSize, length, infoLog); - */ + copy_string(infoLog, bufSize, length, sh->InfoLog); } @@ -521,12 +511,12 @@ void _mesa_get_shader_source(GLcontext *ctx, GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *sourceOut) { - struct gl_program *shProg = _mesa_lookup_shader(ctx, shader); - if (!shProg) { + struct gl_shader *sh = _mesa_lookup_shader(ctx, shader); + if (!sh) { _mesa_error(ctx, GL_INVALID_VALUE, "glGetShaderSource(shader)"); return; } - copy_string((GLchar *) shProg->String, maxLength, length, sourceOut); + copy_string(sourceOut, maxLength, length, sh->Source); } @@ -537,13 +527,13 @@ void _mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location, GLfloat *params) { - struct gl_linked_program *linked - = _mesa_lookup_linked_program(ctx, program); - if (linked) { + struct gl_shader_program *shProg + = _mesa_lookup_shader_program(ctx, program); + if (shProg) { GLuint i; - if (location >= 0 && location < linked->Uniforms->NumParameters) { - for (i = 0; i < linked->Uniforms->Parameters[location].Size; i++) { - params[i] = linked->Uniforms->ParameterValues[location][i]; + if (location >= 0 && location < shProg->Uniforms->NumParameters) { + for (i = 0; i < shProg->Uniforms->Parameters[location].Size; i++) { + params[i] = shProg->Uniforms->ParameterValues[location][i]; } } else { @@ -563,11 +553,11 @@ GLint _mesa_get_uniform_location(GLcontext *ctx, GLuint program, const GLchar *name) { if (ctx->Shader.CurrentProgram) { - const struct gl_linked_program *linked = ctx->Shader.CurrentProgram; + const struct gl_shader_program *shProg = ctx->Shader.CurrentProgram; GLuint loc; - for (loc = 0; loc < linked->Uniforms->NumParameters; loc++) { + for (loc = 0; loc < shProg->Uniforms->NumParameters; loc++) { const struct gl_program_parameter *u - = linked->Uniforms->Parameters + loc; + = shProg->Uniforms->Parameters + loc; if (u->Type == PROGRAM_UNIFORM && !strcmp(u->Name, name)) { return loc; } @@ -581,15 +571,15 @@ _mesa_get_uniform_location(GLcontext *ctx, GLuint program, const GLchar *name) GLboolean _mesa_is_program(GLcontext *ctx, GLuint name) { - struct gl_linked_program *linked = _mesa_lookup_linked_program(ctx, name); - return linked ? GL_TRUE : GL_FALSE; + struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, name); + return shProg ? GL_TRUE : GL_FALSE; } GLboolean _mesa_is_shader(GLcontext *ctx, GLuint name) { - struct gl_program *shader = _mesa_lookup_shader(ctx, name); + struct gl_shader *shader = _mesa_lookup_shader(ctx, name); return shader ? GL_TRUE : GL_FALSE; } @@ -601,17 +591,17 @@ _mesa_is_shader(GLcontext *ctx, GLuint name) void _mesa_shader_source(GLcontext *ctx, GLuint shader, const GLchar *source) { - struct gl_program *shProg = _mesa_lookup_shader(ctx, shader); - if (!shProg) { + struct gl_shader *sh = _mesa_lookup_shader(ctx, shader); + if (!sh) { _mesa_error(ctx, GL_INVALID_VALUE, "glShaderSource(shaderObj)"); return; } /* free old shader source string and install new one */ - if (shProg->String) { - _mesa_free(shProg->String); + if (sh->Source) { + _mesa_free((void *) sh->Source); } - shProg->String = (GLubyte *) source; + sh->Source = source; } @@ -621,12 +611,12 @@ _mesa_shader_source(GLcontext *ctx, GLuint shader, const GLchar *source) void _mesa_compile_shader(GLcontext *ctx, GLuint shaderObj) { - struct gl_program *prog = _mesa_lookup_shader(ctx, shaderObj); + struct gl_shader *sh = _mesa_lookup_shader(ctx, shaderObj); slang_info_log info_log; slang_code_object obj; slang_unit_type type; - if (!prog) { + if (!sh) { _mesa_error(ctx, GL_INVALID_VALUE, "glCompileShader(shaderObj)"); return; } @@ -634,24 +624,20 @@ _mesa_compile_shader(GLcontext *ctx, GLuint shaderObj) slang_info_log_construct(&info_log); _slang_code_object_ctr(&obj); - if (prog->Target == GL_VERTEX_PROGRAM_ARB) { + if (sh->Type == GL_VERTEX_SHADER) { type = slang_unit_vertex_shader; } else { - assert(prog->Target == GL_FRAGMENT_PROGRAM_ARB); + assert(sh->Type == GL_FRAGMENT_SHADER); type = slang_unit_fragment_shader; } - if (_slang_compile((const char*) prog->String, &obj, - type, &info_log, prog)) { - /* - prog->CompileStatus = GL_TRUE; - */ + if (_slang_compile(sh->Source, &obj, type, &info_log, sh)) { + sh->CompileStatus = GL_TRUE; } else { - /* - prog->CompileStatus = GL_FALSE; - */ + sh->CompileStatus = GL_FALSE; + /* XXX temporary */ _mesa_problem(ctx, "Program did not compile!"); } } @@ -663,15 +649,15 @@ _mesa_compile_shader(GLcontext *ctx, GLuint shaderObj) void _mesa_link_program(GLcontext *ctx, GLuint program) { - struct gl_linked_program *linked; + struct gl_shader_program *shProg; - linked = _mesa_lookup_linked_program(ctx, program); - if (!linked) { + shProg = _mesa_lookup_shader_program(ctx, program); + if (!shProg) { _mesa_error(ctx, GL_INVALID_OPERATION, "glLinkProgram(program)"); return; } - _slang_link2(ctx, program, linked); + _slang_link2(ctx, program, shProg); } @@ -683,14 +669,14 @@ _mesa_use_program(GLcontext *ctx, GLuint program) { /* XXXX need to handle reference counting here! */ if (program) { - struct gl_linked_program *linked; - linked = _mesa_lookup_linked_program(ctx, program); - if (!linked) { + struct gl_shader_program *shProg; + shProg = _mesa_lookup_shader_program(ctx, program); + if (!shProg) { _mesa_error(ctx, GL_INVALID_OPERATION, "glUseProgramObjectARB(programObj)"); return; } - ctx->Shader.CurrentProgram = linked; + ctx->Shader.CurrentProgram = shProg; } else { /* don't use a shader program */ @@ -707,9 +693,9 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count, const GLvoid *values, GLenum type) { if (ctx->Shader.CurrentProgram) { - struct gl_linked_program *linked = ctx->Shader.CurrentProgram; - if (location >= 0 && location < linked->Uniforms->NumParameters) { - GLfloat *v = linked->Uniforms->ParameterValues[location]; + struct gl_shader_program *shProg = ctx->Shader.CurrentProgram; + if (location >= 0 && location < shProg->Uniforms->NumParameters) { + GLfloat *v = shProg->Uniforms->ParameterValues[location]; const GLfloat *fValues = (const GLfloat *) values; /* XXX */ GLint i; if (type == GL_FLOAT_VEC4) @@ -791,14 +777,14 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows, void _mesa_validate_program(GLcontext *ctx, GLuint program) { - struct gl_linked_program *linked; - linked = _mesa_lookup_linked_program(ctx, program); - if (!linked) { + struct gl_shader_program *shProg; + shProg = _mesa_lookup_shader_program(ctx, program); + if (!shProg) { _mesa_error(ctx, GL_INVALID_OPERATION, "glValidateProgram(program)"); return; } /* XXX temporary */ - linked->Validated = GL_TRUE; + shProg->Validated = GL_TRUE; /* From the GL spec: any two active samplers in the current program object are of @@ -821,78 +807,93 @@ _mesa_validate_program(GLcontext *ctx, GLuint program) /** - * Create a new GLSL program object. + * Allocate a new gl_shader_program object, initialize it. */ -struct gl_linked_program * -_mesa_new_linked_program(GLcontext *ctx, GLuint name) +struct gl_shader_program * +_mesa_new_shader_program(GLcontext *ctx, GLuint name) { - struct gl_linked_program *linked; - linked = CALLOC_STRUCT(gl_linked_program); - if (linked) { - linked->Name = name; + struct gl_shader_program *shProg; + shProg = CALLOC_STRUCT(gl_shader_program); + if (shProg) { + shProg->Type = GL_SHADER_PROGRAM; + shProg->Name = name; } - return linked; + return shProg; } void -_mesa_free_linked_program_data(GLcontext *ctx, - struct gl_linked_program *linked) +_mesa_free_shader_program_data(GLcontext *ctx, + struct gl_shader_program *shProg) { - if (linked->VertexProgram) { - if (linked->VertexProgram->Base.Parameters == linked->Uniforms) { + assert(shProg->Type == GL_SHADER_PROGRAM); + + if (shProg->VertexProgram) { + if (shProg->VertexProgram->Base.Parameters == shProg->Uniforms) { /* to prevent a double-free in the next call */ - linked->VertexProgram->Base.Parameters = NULL; + shProg->VertexProgram->Base.Parameters = NULL; } - _mesa_delete_program(ctx, &linked->VertexProgram->Base); - linked->VertexProgram = NULL; + _mesa_delete_program(ctx, &shProg->VertexProgram->Base); + shProg->VertexProgram = NULL; } - if (linked->FragmentProgram) { - if (linked->FragmentProgram->Base.Parameters == linked->Uniforms) { + if (shProg->FragmentProgram) { + if (shProg->FragmentProgram->Base.Parameters == shProg->Uniforms) { /* to prevent a double-free in the next call */ - linked->FragmentProgram->Base.Parameters = NULL; + shProg->FragmentProgram->Base.Parameters = NULL; } - _mesa_delete_program(ctx, &linked->FragmentProgram->Base); - linked->FragmentProgram = NULL; + _mesa_delete_program(ctx, &shProg->FragmentProgram->Base); + shProg->FragmentProgram = NULL; } - if (linked->Uniforms) { - _mesa_free_parameter_list(linked->Uniforms); - linked->Uniforms = NULL; + if (shProg->Uniforms) { + _mesa_free_parameter_list(shProg->Uniforms); + shProg->Uniforms = NULL; } - if (linked->Varying) { - _mesa_free_parameter_list(linked->Varying); - linked->Varying = NULL; + if (shProg->Varying) { + _mesa_free_parameter_list(shProg->Varying); + shProg->Varying = NULL; } } void -_mesa_delete_linked_program(GLcontext *ctx, struct gl_linked_program *linked) +_mesa_delete_shader_program(GLcontext *ctx, struct gl_shader_program *shProg) { - _mesa_free_linked_program_data(ctx, linked); - _mesa_free(linked); + _mesa_free_shader_program_data(ctx, shProg); + _mesa_free(shProg); } /** * Lookup a GLSL program object. */ -struct gl_linked_program * -_mesa_lookup_linked_program(GLcontext *ctx, GLuint name) +struct gl_shader_program * +_mesa_lookup_shader_program(GLcontext *ctx, GLuint name) { - if (name) - return (struct gl_linked_program *) - _mesa_HashLookup(ctx->Shared->ProgramObjects, name); - else - return NULL; + struct gl_shader_program *shProg; + if (name) { + shProg = (struct gl_shader_program *) + _mesa_HashLookup(ctx->Shared->ShaderObjects, name); + /* Note that both gl_shader and gl_shader_program objects are kept + * in the same hash table. Check the object's type to be sure it's + * what we're expecting. + */ + if (shProg && shProg->Type != GL_SHADER_PROGRAM) { + return NULL; + } + return shProg; + } + return NULL; } +/** + * Allocate a new gl_shader object, initialize it. + */ struct gl_shader * _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type) { @@ -900,8 +901,8 @@ _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type) assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER); shader = CALLOC_STRUCT(gl_shader); if (shader) { - shader->Name = name; shader->Type = type; + shader->Name = name; } return shader; } @@ -910,14 +911,24 @@ _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type) /** * Lookup a GLSL shader object. */ -struct gl_program * +struct gl_shader * _mesa_lookup_shader(GLcontext *ctx, GLuint name) { - if (name) - return (struct gl_program *) + if (name) { + struct gl_shader *sh = (struct gl_shader *) _mesa_HashLookup(ctx->Shared->ShaderObjects, name); - else - return NULL; + /* Note that both gl_shader and gl_shader_program objects are kept + * in the same hash table. Check the object's type to be sure it's + * what we're expecting. + */ + if (sh && sh->Type == GL_SHADER_PROGRAM) { + assert(sh->Type == GL_VERTEX_SHADER || + sh->Type == GL_FRAGMENT_SHADER); + return NULL; + } + return sh; + } + return NULL; } diff --git a/src/mesa/shader/shader_api.h b/src/mesa/shader/shader_api.h index 723f92690d3..2f73bb88871 100644 --- a/src/mesa/shader/shader_api.h +++ b/src/mesa/shader/shader_api.h @@ -38,24 +38,24 @@ extern void _mesa_init_shader_state(GLcontext * ctx); -extern struct gl_linked_program * -_mesa_new_linked_program(GLcontext *ctx, GLuint name); +extern struct gl_shader_program * +_mesa_new_shader_program(GLcontext *ctx, GLuint name); extern void -_mesa_free_linked_program_data(GLcontext *ctx, - struct gl_linked_program *linked); +_mesa_free_shader_program_data(GLcontext *ctx, + struct gl_shader_program *shProg); extern void -_mesa_delete_linked_program(GLcontext *ctx, struct gl_linked_program *linked); +_mesa_delete_shader_program(GLcontext *ctx, struct gl_shader_program *shProg); -extern struct gl_linked_program * -_mesa_lookup_linked_program(GLcontext *ctx, GLuint name); +extern struct gl_shader_program * +_mesa_lookup_shader_program(GLcontext *ctx, GLuint name); extern struct gl_shader * _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type); -extern struct gl_program * +extern struct gl_shader * _mesa_lookup_shader(GLcontext *ctx, GLuint name); 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); } |