From 7f840426fd4917f56e7bafcffffd51b93c1fc6f7 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 23 Aug 2019 14:36:22 +0200 Subject: GPU: add mechanism for splitting up big gpu_shader_material.glsl file Compiling this big file for every Eevee material is bad for performance, and now that we are adding more nodes it gets worse. This patch adds a simple mechanism to split up that file, and use only the parts used by shader nodes. When a function is used by GPU_link, we detect which GLSL file it came from and use it in GLSL code generation automatically. Dependencies between GLSL files are manually specified, and function names must be unique across all GLSL files. Most of the actual splitting up will be done in later commits. Differential Revision: https://developer.blender.org/D5569 --- source/blender/gpu/intern/gpu_material.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/blender/gpu/intern/gpu_material.c') diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 20b91c0c95d..05d991105c0 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -37,6 +37,7 @@ #include "BLI_utildefines.h" #include "BLI_string.h" #include "BLI_string_utils.h" +#include "BLI_ghash.h" #include "BKE_main.h" #include "BKE_node.h" @@ -102,6 +103,8 @@ struct GPUMaterial { GPUTexture *coba_tex; /* 1D Texture array containing all color bands. */ GPUColorBandBuilder *coba_builder; + GSet *used_libraries; + #ifndef NDEBUG char name[64]; #endif @@ -183,6 +186,8 @@ static void gpu_material_free_single(GPUMaterial *material) if (material->coba_tex != NULL) { GPU_texture_free(material->coba_tex); } + + BLI_gset_free(material->used_libraries, NULL); } void GPU_material_free(ListBase *gpumaterial) @@ -582,6 +587,11 @@ void gpu_material_add_node(GPUMaterial *material, GPUNode *node) BLI_addtail(&material->nodes, node); } +GSet *gpu_material_used_libraries(GPUMaterial *material) +{ + return material->used_libraries; +} + /* Return true if the material compilation has not yet begin or begin. */ eGPUMaterialStatus GPU_material_status(GPUMaterial *mat) { @@ -659,6 +669,9 @@ GPUMaterial *GPU_material_from_nodetree(Scene *scene, UNUSED_VARS(name); #endif + mat->used_libraries = BLI_gset_new( + BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "GPUMaterial.used_libraries"); + /* localize tree to create links for reroute and mute */ bNodeTree *localtree = ntreeLocalize(ntree); ntreeGPUMaterialNodes(localtree, mat, &has_surface_output, &has_volume_output); -- cgit v1.2.3