[Bf-blender-cvs] [b3e38cfc6b6] blender2.8: Gawain: look up uniforms by name quicker

Mike Erwin noreply at git.blender.org
Mon Apr 17 07:20:14 CEST 2017


Commit: b3e38cfc6b6320c702b93fe179323ed79583abd9
Author: Mike Erwin
Date:   Mon Apr 17 01:19:28 2017 -0400
Branches: blender2.8
https://developer.blender.org/rBb3e38cfc6b6320c702b93fe179323ed79583abd9

Gawain: look up uniforms by name quicker

ShaderInterface_uniform searches custom uniforms first, then builtin uniforms if needed.

This reduces the amount of string matching since you're almost certainly looking for one of those custom uniforms. Otherwise you would've called ShaderInterface_**builtin**_uniform.

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

M	intern/gawain/src/shader_interface.c

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

diff --git a/intern/gawain/src/shader_interface.c b/intern/gawain/src/shader_interface.c
index 7af26a2585e..b7a30f24c38 100644
--- a/intern/gawain/src/shader_interface.c
+++ b/intern/gawain/src/shader_interface.c
@@ -211,17 +211,34 @@ void ShaderInterface_discard(ShaderInterface* shaderface)
 
 const ShaderInput* ShaderInterface_uniform(const ShaderInterface* shaderface, const char* name)
 	{
+	// search through custom uniforms first
 	for (uint32_t i = 0; i < shaderface->uniform_ct; ++i)
 		{
 		const ShaderInput* uniform = shaderface->inputs + i;
 
+		if (uniform->builtin_type == UNIFORM_CUSTOM)
+			{
 #if SUPPORT_LEGACY_GLSL
-		if (uniform->name == NULL) continue;
+			if (uniform->name == NULL) continue;
 #endif
 
-		if (match(uniform->name, name))
-			return uniform;
+			if (match(uniform->name, name))
+				return uniform;
+			}
 		}
+
+	// search through builtin uniforms next
+	for (uint32_t i = 0; i < shaderface->uniform_ct; ++i)
+		{
+		const ShaderInput* uniform = shaderface->inputs + i;
+
+		if (uniform->builtin_type != UNIFORM_CUSTOM)
+			if (match(uniform->name, name))
+				return uniform;
+
+		// TODO: warn if we find a matching builtin, since these can be looked up much quicker --v
+		}
+
 	return NULL; // not found
 	}




More information about the Bf-blender-cvs mailing list