aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/shader/slang/slang_link.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
committermarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
commit29b86f9852b2b7ecc31cdfee56679537e40bc6e2 (patch)
tree1e6ec8ccf2dbf773260a1953b8e13c49f9b7c5f5 /mesalib/src/mesa/shader/slang/slang_link.c
parent529236591df7366479a6fac30b387667678fd1ba (diff)
downloadvcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.gz
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.bz2
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.zip
svn merge -r524:HEAD "^/branches/released" .
Diffstat (limited to 'mesalib/src/mesa/shader/slang/slang_link.c')
-rw-r--r--mesalib/src/mesa/shader/slang/slang_link.c88
1 files changed, 55 insertions, 33 deletions
diff --git a/mesalib/src/mesa/shader/slang/slang_link.c b/mesalib/src/mesa/shader/slang/slang_link.c
index 0a2bc4978..7c7bfbdbc 100644
--- a/mesalib/src/mesa/shader/slang/slang_link.c
+++ b/mesalib/src/mesa/shader/slang/slang_link.c
@@ -31,7 +31,6 @@
#include "main/imports.h"
#include "main/context.h"
-#include "main/hash.h"
#include "main/macros.h"
#include "shader/program.h"
#include "shader/prog_instruction.h"
@@ -69,7 +68,7 @@ static void
link_error(struct gl_shader_program *shProg, const char *msg)
{
if (shProg->InfoLog) {
- _mesa_free(shProg->InfoLog);
+ free(shProg->InfoLog);
}
shProg->InfoLog = _mesa_strdup(msg);
shProg->LinkStatus = GL_FALSE;
@@ -104,7 +103,7 @@ link_varying_vars(GLcontext *ctx,
GLuint *map, i, firstVarying, newFile;
GLbitfield *inOutFlags;
- map = (GLuint *) _mesa_malloc(prog->Varying->NumParameters * sizeof(GLuint));
+ map = (GLuint *) malloc(prog->Varying->NumParameters * sizeof(GLuint));
if (!map)
return GL_FALSE;
@@ -135,23 +134,23 @@ link_varying_vars(GLcontext *ctx,
&shProg->Varying->Parameters[j];
if (var->Size != v->Size) {
link_error(shProg, "mismatched varying variable types");
- _mesa_free(map);
+ free(map);
return GL_FALSE;
}
if (!bits_agree(var->Flags, v->Flags, PROG_PARAM_BIT_CENTROID)) {
char msg[100];
_mesa_snprintf(msg, sizeof(msg),
- "centroid modifier mismatch for '%s'", var->Name);
+ "centroid modifier mismatch for '%s'", var->Name);
link_error(shProg, msg);
- _mesa_free(map);
+ free(map);
return GL_FALSE;
}
if (!bits_agree(var->Flags, v->Flags, PROG_PARAM_BIT_INVARIANT)) {
char msg[100];
_mesa_snprintf(msg, sizeof(msg),
- "invariant modifier mismatch for '%s'", var->Name);
+ "invariant modifier mismatch for '%s'", var->Name);
link_error(shProg, msg);
- _mesa_free(map);
+ free(map);
return GL_FALSE;
}
}
@@ -163,7 +162,7 @@ link_varying_vars(GLcontext *ctx,
if (shProg->Varying->NumParameters > ctx->Const.MaxVarying) {
link_error(shProg, "Too many varying variables");
- _mesa_free(map);
+ free(map);
return GL_FALSE;
}
@@ -203,7 +202,7 @@ link_varying_vars(GLcontext *ctx,
}
}
- _mesa_free(map);
+ free(map);
/* these will get recomputed before linking is completed */
prog->InputsRead = 0x0;
@@ -270,8 +269,8 @@ link_uniform_vars(GLcontext *ctx,
GLuint newSampNum = *numSamplers;
if (newSampNum >= ctx->Const.MaxTextureImageUnits) {
char s[100];
- _mesa_sprintf(s, "Too many texture samplers (%u, max is %u)",
- newSampNum, ctx->Const.MaxTextureImageUnits);
+ sprintf(s, "Too many texture samplers (%u, max is %u)",
+ newSampNum, ctx->Const.MaxTextureImageUnits);
link_error(shProg, s);
return GL_FALSE;
}
@@ -564,7 +563,7 @@ remove_extra_version_directives(GLchar *source)
{
GLuint verCount = 0;
while (1) {
- char *ver = _mesa_strstr(source, "#version");
+ char *ver = strstr(source, "#version");
if (ver) {
verCount++;
if (verCount > 1) {
@@ -590,45 +589,61 @@ concat_shaders(struct gl_shader_program *shProg, GLenum shaderType)
{
struct gl_shader *newShader;
const struct gl_shader *firstShader = NULL;
- GLuint shaderLengths[100];
+ GLuint *shaderLengths;
GLchar *source;
GLuint totalLen = 0, len = 0;
GLuint i;
+ shaderLengths = (GLuint *)malloc(shProg->NumShaders * sizeof(GLuint));
+ if (!shaderLengths) {
+ return NULL;
+ }
+
/* compute total size of new shader source code */
for (i = 0; i < shProg->NumShaders; i++) {
const struct gl_shader *shader = shProg->Shaders[i];
if (shader->Type == shaderType) {
- shaderLengths[i] = _mesa_strlen(shader->Source);
+ shaderLengths[i] = strlen(shader->Source);
totalLen += shaderLengths[i];
if (!firstShader)
firstShader = shader;
}
}
- if (totalLen == 0)
+ if (totalLen == 0) {
+ free(shaderLengths);
return NULL;
+ }
- source = (GLchar *) _mesa_malloc(totalLen + 1);
- if (!source)
+ source = (GLchar *) malloc(totalLen + 1);
+ if (!source) {
+ free(shaderLengths);
return NULL;
+ }
/* concatenate shaders */
for (i = 0; i < shProg->NumShaders; i++) {
const struct gl_shader *shader = shProg->Shaders[i];
if (shader->Type == shaderType) {
- _mesa_memcpy(source + len, shader->Source, shaderLengths[i]);
+ memcpy(source + len, shader->Source, shaderLengths[i]);
len += shaderLengths[i];
}
}
source[len] = '\0';
/*
- _mesa_printf("---NEW CONCATENATED SHADER---:\n%s\n------------\n", source);
+ printf("---NEW CONCATENATED SHADER---:\n%s\n------------\n", source);
*/
+ free(shaderLengths);
+
remove_extra_version_directives(source);
newShader = CALLOC_STRUCT(gl_shader);
+ if (!newShader) {
+ free(source);
+ return NULL;
+ }
+
newShader->Type = shaderType;
newShader->Source = source;
newShader->Pragmas = firstShader->Pragmas;
@@ -704,6 +719,7 @@ _slang_link(GLcontext *ctx,
{
const struct gl_vertex_program *vertProg = NULL;
const struct gl_fragment_program *fragProg = NULL;
+ GLboolean vertNotify = GL_TRUE, fragNotify = GL_TRUE;
GLuint numSamplers = 0;
GLuint i;
@@ -757,7 +773,7 @@ _slang_link(GLcontext *ctx,
_mesa_reference_vertprog(ctx, &shProg->VertexProgram, NULL);
if (vertProg) {
struct gl_vertex_program *linked_vprog =
- vertex_program(_mesa_clone_program(ctx, &vertProg->Base));
+ _mesa_clone_vertex_program(ctx, vertProg);
shProg->VertexProgram = linked_vprog; /* refcount OK */
/* vertex program ID not significant; just set Id for debugging purposes */
shProg->VertexProgram->Base.Id = shProg->Name;
@@ -767,7 +783,7 @@ _slang_link(GLcontext *ctx,
_mesa_reference_fragprog(ctx, &shProg->FragmentProgram, NULL);
if (fragProg) {
struct gl_fragment_program *linked_fprog =
- fragment_program(_mesa_clone_program(ctx, &fragProg->Base));
+ _mesa_clone_fragment_program(ctx, fragProg);
shProg->FragmentProgram = linked_fprog; /* refcount OK */
/* vertex program ID not significant; just set Id for debugging purposes */
shProg->FragmentProgram->Base.Id = shProg->Name;
@@ -856,14 +872,14 @@ _slang_link(GLcontext *ctx,
_mesa_update_shader_textures_used(&shProg->FragmentProgram->Base);
/* notify driver that a new fragment program has been compiled/linked */
- ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_PROGRAM_ARB,
- &shProg->FragmentProgram->Base);
+ vertNotify = ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_PROGRAM_ARB,
+ &shProg->FragmentProgram->Base);
if (ctx->Shader.Flags & GLSL_DUMP) {
- _mesa_printf("Mesa pre-link fragment program:\n");
+ printf("Mesa pre-link fragment program:\n");
_mesa_print_program(&fragProg->Base);
_mesa_print_program_parameters(ctx, &fragProg->Base);
- _mesa_printf("Mesa post-link fragment program:\n");
+ printf("Mesa post-link fragment program:\n");
_mesa_print_program(&shProg->FragmentProgram->Base);
_mesa_print_program_parameters(ctx, &shProg->FragmentProgram->Base);
}
@@ -874,14 +890,14 @@ _slang_link(GLcontext *ctx,
_mesa_update_shader_textures_used(&shProg->VertexProgram->Base);
/* notify driver that a new vertex program has been compiled/linked */
- ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB,
- &shProg->VertexProgram->Base);
+ fragNotify = ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB,
+ &shProg->VertexProgram->Base);
if (ctx->Shader.Flags & GLSL_DUMP) {
- _mesa_printf("Mesa pre-link vertex program:\n");
+ printf("Mesa pre-link vertex program:\n");
_mesa_print_program(&vertProg->Base);
_mesa_print_program_parameters(ctx, &vertProg->Base);
- _mesa_printf("Mesa post-link vertex program:\n");
+ printf("Mesa post-link vertex program:\n");
_mesa_print_program(&shProg->VertexProgram->Base);
_mesa_print_program_parameters(ctx, &shProg->VertexProgram->Base);
}
@@ -896,13 +912,19 @@ _slang_link(GLcontext *ctx,
}
if (ctx->Shader.Flags & GLSL_DUMP) {
- _mesa_printf("Varying vars:\n");
+ printf("Varying vars:\n");
_mesa_print_parameter_list(shProg->Varying);
if (shProg->InfoLog) {
- _mesa_printf("Info Log: %s\n", shProg->InfoLog);
+ printf("Info Log: %s\n", shProg->InfoLog);
}
}
- shProg->LinkStatus = (shProg->VertexProgram || shProg->FragmentProgram);
+ if (!vertNotify || !fragNotify) {
+ /* driver rejected one/both of the vertex/fragment programs */
+ link_error(shProg, "Vertex and/or fragment program rejected by driver\n");
+ }
+ else {
+ shProg->LinkStatus = (shProg->VertexProgram || shProg->FragmentProgram);
+ }
}