From ba1bf87bd8f13fa2c67c435eb4a31a0c898d65ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Thu, 1 Sep 2022 13:35:04 +0200 Subject: GPUMaterial: Make uniform attrib precompute hash and attribute safe name This avoids redundant operation at draw time. The per attrib hash is to be used with the future implementation. --- source/blender/gpu/intern/gpu_material.c | 2 +- source/blender/gpu/intern/gpu_node_graph.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'source/blender/gpu/intern') diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index d9045a041b6..d0297127ffc 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -225,7 +225,7 @@ ListBase GPU_material_textures(GPUMaterial *material) return material->graph.textures; } -GPUUniformAttrList *GPU_material_uniform_attributes(GPUMaterial *material) +GPUUniformAttrList *GPU_material_uniform_attributes(const GPUMaterial *material) { GPUUniformAttrList *attrs = &material->graph.uniform_attrs; return attrs->count > 0 ? attrs : NULL; diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c index db8d55ec196..6d6fad4e80f 100644 --- a/source/blender/gpu/intern/gpu_node_graph.c +++ b/source/blender/gpu/intern/gpu_node_graph.c @@ -321,10 +321,18 @@ void gpu_node_graph_finalize_uniform_attrs(GPUNodeGraph *graph) LISTBASE_FOREACH (GPUUniformAttr *, attr, &attrs->list) { attr->id = next_id++; - attrs->hash_code ^= BLI_ghashutil_strhash_p(attr->name); + attr->hash_code = BLI_ghashutil_strhash_p(attr->name); if (attr->use_dupli) { - attrs->hash_code ^= BLI_ghashutil_uinthash(attr->id); + attr->hash_code ^= BLI_ghashutil_uinthash(attr->id); + } + + attrs->hash_code ^= attr->hash_code; + + { + char attr_name_esc[sizeof(attr->name) * 2]; + BLI_str_escape(attr_name_esc, attr->name, sizeof(attr_name_esc)); + SNPRINTF(attr->name_id_prop, "[\"%s\"]", attr_name_esc); } } } -- cgit v1.2.3