From 5fb91750b8b11a310b09e30732f3e7b299a7d4cd Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Tue, 12 Feb 2019 19:58:39 +0100 Subject: [PATCH] shader: rework shader patching to be able to patch various IOs with the same sid With enhanced layouts and input arrays enabled it may happen that more then one shader IO variable have the same sid, and since the other parts of the glsl_name are not available at this point rewrite the patching routine to be able to patch more than one instance of a delaration with the same variable prefix. Signed-off-by: Gert Wollny Reviewed-By: Gurchetan Singh --- src/vrend_shader.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index fbdf8ab..c17d22c 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -6109,19 +6109,22 @@ static void replace_interp(struct vrend_strarray *program, const char *var_name, const char *pstring, const char *auxstring) { - char *ptr; - int mylen = strlen(INTERP_PREFIX) + strlen("out vec4 "); + int mylen = strlen(INTERP_PREFIX) + strlen("out float "); - ptr = strstr(program->strings[SHADER_STRING_HDR].buf, var_name); + char *ptr = program->strings[SHADER_STRING_HDR].buf; + do { + char *p = strstr(ptr, var_name); + if (!p) + break; - if (!ptr) - return; + ptr = p - mylen; - ptr -= mylen; + memset(ptr, ' ', strlen(INTERP_PREFIX)); + memcpy(ptr, pstring, strlen(pstring)); + memcpy(ptr + strlen(pstring), auxstring, strlen(auxstring)); - memset(ptr, ' ', strlen(INTERP_PREFIX)); - memcpy(ptr, pstring, strlen(pstring)); - memcpy(ptr + strlen(pstring), auxstring, strlen(auxstring)); + ptr = p + strlen(var_name); + } while (1); } static const char *gpu_shader5_string = "#extension GL_ARB_gpu_shader5 : require\n";