[Bf-blender-cvs] [ad5a20efcef] blender2.8: Commit D3494 : Compiled shader lookup fix

Clément Foucault noreply at git.blender.org
Mon Jul 2 11:06:08 CEST 2018


Commit: ad5a20efcef8114b589ff66d09166eabdc8e67ad
Author: Clément Foucault
Date:   Mon Jul 2 11:03:14 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBad5a20efcef8114b589ff66d09166eabdc8e67ad

Commit D3494 : Compiled shader lookup fix

Authored by Pavel Rudko (PavelRudko) on Thu, Jun 21, 10:41 AM.

Original description:

I've encounterd into a problem with blender 2.8.
See the example screenshot (scene, shader setup). For some materials it's not enough to calculate hash based on fragment code and defines. In some cases attribute names may change. And if we change uv set name, for example, vertex shader is not recompiled, and another attribute name inside it is used.

===================================================================

M	source/blender/gpu/intern/gpu_codegen.c

===================================================================

diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 436f43d9c1e..a450b551d4a 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -80,11 +80,17 @@ static char *glsl_material_library = NULL;
 static GPUPass *pass_cache = NULL;
 static SpinLock pass_cache_spin;
 
-static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs)
+static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs, GPUVertexAttribs *attribs)
 {
 	BLI_HashMurmur2A hm2a;
 	BLI_hash_mm2a_init(&hm2a, 0);
 	BLI_hash_mm2a_add(&hm2a, (unsigned char *)frag_gen, strlen(frag_gen));
+	if (attribs) {
+		for (int att_idx = 0; att_idx < attribs->totlayer; att_idx++) {
+			char *name = attribs->layer[att_idx].name;
+			BLI_hash_mm2a_add(&hm2a, (unsigned char *)name, strlen(name));
+		}
+	}
 	if (defs)
 		BLI_hash_mm2a_add(&hm2a, (unsigned char *)defs, strlen(defs));
 
@@ -1885,7 +1891,7 @@ GPUPass *GPU_generate_pass_new(
 	char *fragmentgen = code_generate_fragment(material, nodes, frag_outlink->output);
 
 	/* Cache lookup: Reuse shaders already compiled */
-	uint32_t hash = gpu_pass_hash(fragmentgen, defines);
+	uint32_t hash = gpu_pass_hash(fragmentgen, defines, attribs);
 	pass_hash = gpu_pass_cache_lookup(hash);
 
 	if (pass_hash && (pass_hash->next == NULL || pass_hash->next->hash != hash)) {



More information about the Bf-blender-cvs mailing list