From bb3e669d06ec5aead740affe75ac0375110b4d7a Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sun, 4 Jun 2017 22:02:30 -0400 Subject: [PATCH] Gawain: faster lookup shader attribs by name Quick hash rejection instead of string comparison. Uniform lookups already work this way. I don't expect a major overall speedup since attributes are looked up less frequently than uniforms. --- intern/gawain/src/shader_interface.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/intern/gawain/src/shader_interface.c b/intern/gawain/src/shader_interface.c index f0da342f088..4c9f7fae67f 100644 --- a/intern/gawain/src/shader_interface.c +++ b/intern/gawain/src/shader_interface.c @@ -288,6 +288,7 @@ const ShaderInput* ShaderInterface_attrib(const ShaderInterface* shaderface, con { // attribs are stored after uniforms const uint32_t input_ct = shaderface->uniform_ct + shaderface->attrib_ct; + const unsigned name_hash = hash_string(name); for (uint32_t i = shaderface->uniform_ct; i < input_ct; ++i) { const ShaderInput* attrib = shaderface->inputs + i; @@ -296,6 +297,8 @@ const ShaderInput* ShaderInterface_attrib(const ShaderInterface* shaderface, con if (attrib->name == NULL) continue; #endif + if (attrib->name_hash != name_hash) continue; + if (match(attrib->name, name)) return attrib; }