diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2014-08-29 18:23:37 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2014-08-29 18:23:50 +0400 |
commit | 78b79a91f2aea012c6ba9181ac3c32aeb66d392c (patch) | |
tree | f36c857601f9b204feb5635b1405f6656faa18c9 | |
parent | c1ec73f52218900b1ce101b3154816205aa75d0d (diff) |
Fix T41596 GLSL error on ATIs after clipping workaround commit.
This was a little difficult to track down, basically it was a missing
escape sequence that only manifested itself when GPU did not support
bicubic filtering.
Extra:
* Fix memory leaks when an error occurs in shader compilation
* Display full shader when a compilation error occurs. Makes it easier
to diagnose if problem is caused by a syntax or compatibility error.
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_extensions.c | 44 |
2 files changed, 29 insertions, 19 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index d60525dd34a..6b46db89a93 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -1410,6 +1410,10 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, GPUVertexAttri /* failed? */ if (!shader) { + if (fragmentcode) + MEM_freeN(fragmentcode); + if (vertexcode) + MEM_freeN(vertexcode); memset(attribs, 0, sizeof(*attribs)); memset(builtins, 0, sizeof(*builtins)); GPU_nodes_free(nodes); diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 1b141d38bfe..17c495c82d6 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -1170,25 +1170,31 @@ struct GPUShader { int totattrib; /* total number of attributes */ }; -static void shader_print_errors(const char *task, char *log, const char *code) +static void shader_print_errors(const char *task, char *log, const char **code, int totcode) { - const char *c, *pos, *end = code + strlen(code); - int line = 1; + int i; fprintf(stderr, "GPUShader: %s error:\n", task); - if (G.debug & G_DEBUG) { - c = code; - while ((c < end) && (pos = strchr(c, '\n'))) { - fprintf(stderr, "%2d ", line); - fwrite(c, (pos+1)-c, 1, stderr); - c = pos+1; - line++; + for (i = 0; i < totcode; i++) { + const char *c, *pos, *end = code[i] + strlen(code[i]); + int line = 1; + + if (G.debug & G_DEBUG) { + fprintf(stderr, "===== shader string %d ====\n", i + 1); + + c = code[i]; + while ((c < end) && (pos = strchr(c, '\n'))) { + fprintf(stderr, "%2d ", line); + fwrite(c, (pos+1)-c, 1, stderr); + c = pos+1; + line++; + } + + fprintf(stderr, "%s", c); } - - fprintf(stderr, "%s", c); } - + fprintf(stderr, "%s\n", log); } @@ -1220,7 +1226,7 @@ static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH]) if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) { strcat(defines, "#define GPU_ATI\n"); if (GLEW_VERSION_3_0) - strcat(defines, "#define CLIP_WORKAROUND"); + strcat(defines, "#define CLIP_WORKAROUND\n"); } else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY)) strcat(defines, "#define GPU_NVIDIA\n"); @@ -1282,7 +1288,7 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const if (!status) { glGetInfoLogARB(shader->vertex, sizeof(log), &length, log); - shader_print_errors("compile", log, vertexcode); + shader_print_errors("compile", log, source, num_source); GPU_shader_free(shader); return NULL; @@ -1309,7 +1315,7 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const if (!status) { glGetInfoLogARB(shader->fragment, sizeof(log), &length, log); - shader_print_errors("compile", log, fragcode); + shader_print_errors("compile", log, source, num_source); GPU_shader_free(shader); return NULL; @@ -1325,9 +1331,9 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const glGetObjectParameterivARB(shader->object, GL_OBJECT_LINK_STATUS_ARB, &status); if (!status) { glGetInfoLogARB(shader->object, sizeof(log), &length, log); - if (fragcode) shader_print_errors("linking", log, fragcode); - else if (vertexcode) shader_print_errors("linking", log, vertexcode); - else if (libcode) shader_print_errors("linking", log, libcode); + if (fragcode) shader_print_errors("linking", log, &fragcode, 1); + else if (vertexcode) shader_print_errors("linking", log, &vertexcode, 1); + else if (libcode) shader_print_errors("linking", log, &libcode, 1); GPU_shader_free(shader); return NULL; |