diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2017-07-14 18:40:54 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2017-07-14 18:46:10 +0300 |
commit | 2a489273d7e2354a9f1afc3212863ff4b463cf86 (patch) | |
tree | a12701d9ca43b6ace0993cfc31bc278eed3cc4fb /source/blender/gpu/intern/gpu_material.c | |
parent | 73b142529705e75790a4b9279109763014ca63e6 (diff) |
Implement Uniformbuffer objects for nodetree parameters
For users that means you can tweak shaders in the nodetree and things
are way faster. This is a huge improvement, particularly in
systems that have no shader cache.
From the code perspective it means we are no longer re-compiling the
shader every time a value is tweaked in the UI. We are using uniforms
for those values.
It would be slow to add that many uniforms for all the shaders. So
instead we are using UBO (Uniform Buffer Objects).
This fixes the main issue of T51467. However GWN_shaderinterface_create() still
needs to be improvedi. When opening a .blend all shaders are compiled once, so
optimizing it will bring a measurable impact.
========================================================================
NOTE: This breaks update of Cycles material upon nodetree nodes
tweaking. It will be fixed separately by depsgraph, once tackling T51925
(Animated Eevee values slowdown).
The idea is to make Depsgraph update more granular. The XXX TODO in
rna_nodetree.c will be tackled at that time as well.
========================================================================
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D2739
Diffstat (limited to 'source/blender/gpu/intern/gpu_material.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index efe79c0386c..f62c599a9b6 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -64,6 +64,7 @@ #include "GPU_material.h" #include "GPU_shader.h" #include "GPU_texture.h" +#include "GPU_uniformbuffer.h" #include "gpu_codegen.h" #include "gpu_lamp_private.h" @@ -133,6 +134,7 @@ struct GPUMaterial { bool bound; bool is_opensubdiv; + GPUUniformBuffer *ubo; /* UBOs for shader uniforms. */ }; /* Forward declaration so shade_light_textures() can use this, while still keeping the code somewhat organized */ @@ -250,6 +252,10 @@ void GPU_material_free(ListBase *gpumaterial) if (material->pass) GPU_pass_free(material->pass); + if (material->ubo != NULL) { + GPU_uniformbuffer_free(material->ubo); + } + BLI_freelistN(&material->lamps); MEM_freeN(material); @@ -429,6 +435,30 @@ GPUPass *GPU_material_get_pass(GPUMaterial *material) return material->pass; } +GPUUniformBuffer *GPU_material_get_uniform_buffer(GPUMaterial *material) +{ + return material->ubo; +} + +/** + * Create dynamic UBO from parameters + * \param ListBase of BLI_genericNodeN(GPUInput) + */ +void GPU_material_create_uniform_buffer(GPUMaterial *material, ListBase *inputs) +{ + material->ubo = GPU_uniformbuffer_dynamic_create(inputs, NULL); +} + +void GPU_material_uniform_buffer_tag_dirty(ListBase *gpumaterials) +{ + for (LinkData *link = gpumaterials->first; link; link = link->next) { + GPUMaterial *material = link->data; + if (material->ubo != NULL) { + GPU_uniformbuffer_tag_dirty(material->ubo); + } + } +} + void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs) { *attribs = material->attribs; @@ -2130,7 +2160,7 @@ GPUMaterial *GPU_material_from_nodetree( if (mat->outlink) { outlink = mat->outlink; mat->pass = GPU_generate_pass_new( - &mat->nodes, outlink, &mat->attribs, vert_code, geom_code, frag_lib, defines); + mat, &mat->nodes, outlink, &mat->attribs, vert_code, geom_code, frag_lib, defines); } /* note that even if building the shader fails in some way, we still keep |