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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user