Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-03-12 01:43:09 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-03-12 01:44:10 +0300
commit765d7242d5a14551d0dc876f13bf6ee579b47b10 (patch)
treec18455eaabcad076fe98427d1a32d76d2c9c38f7 /source/blender/gpu/intern/gpu_codegen.h
parent7194259fb1a8b9ef84c0896130b92ff577fc76b1 (diff)
GPUMaterial: Add Material shader cache.
This is mostly to avoid re-compilation when using undo/redo operators. This also has the benefit to reuse the same GPUShader for multiple materials using the same nodetree configuration. The cache stores GPUPasses that already contains the shader code and a hash to test for matches. We use refcounts to know when a GPUPass is not used anymore. I had to move the GPUInput list from GPUPass to GPUMaterial because it's containing references to the material nodetree and cannot be reused. A garbage collection is hardcoded to run every 60 seconds to free every unused GPUPass.
Diffstat (limited to 'source/blender/gpu/intern/gpu_codegen.h')
-rw-r--r--source/blender/gpu/intern/gpu_codegen.h22
1 files changed, 13 insertions, 9 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h
index 0f8218c9c15..dab0bc3f8b1 100644
--- a/source/blender/gpu/intern/gpu_codegen.h
+++ b/source/blender/gpu/intern/gpu_codegen.h
@@ -157,25 +157,27 @@ typedef struct GPUInput {
} GPUInput;
struct GPUPass {
- ListBase inputs;
struct GPUShader *shader;
char *fragmentcode;
char *geometrycode;
char *vertexcode;
+ char *defines;
const char *libcode;
+ unsigned int refcount; /* Orphaned GPUPasses gets freed by the garbage collector. */
+ uint32_t hash; /* Identity hash generated from all GLSL code. */
};
typedef struct GPUPass GPUPass;
GPUPass *GPU_generate_pass_new(
- struct GPUMaterial *material,
- ListBase *nodes, struct GPUNodeLink *frag_outlink,
- struct GPUVertexAttribs *attribs,
+ GPUMaterial *material,
+ GPUNodeLink *frag_outlink, struct GPUVertexAttribs *attribs,
+ ListBase *nodes, ListBase *inputs,
const char *vert_code, const char *geom_code,
const char *frag_lib, const char *defines);
GPUPass *GPU_generate_pass(
- ListBase *nodes, struct GPUNodeLink *outlink,
+ ListBase *nodes, ListBase *inputs, struct GPUNodeLink *outlink,
struct GPUVertexAttribs *attribs, int *builtin,
const GPUMatType type, const char *name,
const bool use_opensubdiv,
@@ -186,13 +188,15 @@ struct GPUShader *GPU_pass_shader(GPUPass *pass);
void GPU_nodes_get_vertex_attributes(ListBase *nodes, struct GPUVertexAttribs *attribs);
void GPU_nodes_prune(ListBase *nodes, struct GPUNodeLink *outlink);
-void GPU_pass_bind(GPUPass *pass, double time, int mipmap);
-void GPU_pass_update_uniforms(GPUPass *pass);
-void GPU_pass_unbind(GPUPass *pass);
+void GPU_pass_bind(GPUPass *pass, ListBase *inputs, double time, int mipmap);
+void GPU_pass_update_uniforms(GPUPass *pass, ListBase *inputs);
+void GPU_pass_unbind(GPUPass *pass, ListBase *inputs);
-void GPU_pass_free(GPUPass *pass);
+void GPU_pass_release(GPUPass *pass);
void GPU_pass_free_nodes(ListBase *nodes);
+void GPU_inputs_free(ListBase *inputs);
+
void gpu_codegen_init(void);
void gpu_codegen_exit(void);