diff options
Diffstat (limited to 'source/blender/viewport_compositor')
5 files changed, 33 insertions, 13 deletions
diff --git a/source/blender/viewport_compositor/VPC_context.hh b/source/blender/viewport_compositor/VPC_context.hh index 6d80510e48c..a6494936f4f 100644 --- a/source/blender/viewport_compositor/VPC_context.hh +++ b/source/blender/viewport_compositor/VPC_context.hh @@ -3,6 +3,8 @@ #pragma once +#include "BLI_math_vec_types.hh" + #include "DNA_scene_types.h" #include "GPU_texture.h" @@ -25,6 +27,9 @@ class Context { /* Get the active compositing scene. */ virtual const Scene *get_scene() = 0; + /* Get the dimensions of the viewport. */ + virtual int2 get_viewport_size() = 0; + /* Get the texture representing the viewport where the result of the compositor should be * written. This should be called by output nodes to get their target texture. */ virtual GPUTexture *get_viewport_texture() = 0; diff --git a/source/blender/viewport_compositor/VPC_texture_pool.hh b/source/blender/viewport_compositor/VPC_texture_pool.hh index bd762b3fa9c..cc5419c57aa 100644 --- a/source/blender/viewport_compositor/VPC_texture_pool.hh +++ b/source/blender/viewport_compositor/VPC_texture_pool.hh @@ -17,14 +17,17 @@ namespace blender::viewport_compositor { * Texture Pool Key. */ -/* A key structure used to identify a texture specification in a texture pool. Defines a hash and - * an equality operator for use in a hash map. */ +/* A key used to identify a texture specification in a texture pool. Defines a hash and an equality + * operator for use in a hash map. */ class TexturePoolKey { public: int2 size; eGPUTextureFormat format; + /* Construct a key from the given texture size and format. */ TexturePoolKey(int2 size, eGPUTextureFormat format); + + /* Construct a key from the size and format of the given texture. */ TexturePoolKey(const GPUTexture *texture); uint64_t hash() const; @@ -34,12 +37,12 @@ class TexturePoolKey { * Texture Pool. */ -/* A pool of textures that can be used to allocate textures and reused transparently throughout the - * evaluation of the compositor. This texture pool only pools textures throughout a single - * evaluation of the compositor and will reset after the evaluation without freeing any textures. - * Cross-evaluation pooling and freeing of unused textures is the responsibility of the back-end - * texture pool used by the allocate_texture method. In the case of the viewport compositor engine, - * this would be the global DRWTexturePool of the draw manager. */ +/* A pool of textures that can be used to allocate textures that can be reused transparently + * throughout the evaluation of the compositor. This texture pool only pools textures throughout a + * single evaluation of the compositor and will reset after the evaluation without freeing any + * textures. Cross-evaluation pooling and freeing of unused textures is the responsibility of the + * back-end texture pool used by the allocate_texture method. In the case of the viewport + * compositor engine, this would be the global DRWTexturePool of the draw manager. */ class TexturePool { private: /* The set of textures in the pool that are available to acquire for each distinct texture @@ -56,7 +59,7 @@ class TexturePool { GPUTexture *acquire_color(int2 size); /* Shorthand for acquire with GPU_RGBA16F format. Identical to acquire_color because vector - * textures are and should internally be stored in RGBA textures. */ + * are stored in RGBA textures because RGB texture have limited support. */ GPUTexture *acquire_vector(int2 size); /* Shorthand for acquire with GPU_R16F format. */ @@ -66,6 +69,11 @@ class TexturePool { * the texture to be one that was acquired using the same texture pool. */ void release(GPUTexture *texture); + /* Reset the texture pool by clearing all available textures. The textures are not freed. If they + * are not needed, they should be freed by the back-end texture pool used by the allocate_texture + * method. This should be called after the compositor is done evaluating. */ + void reset(); + private: /* Returns a newly allocated texture with the given specification. This method should be * implemented by the compositor engine and should use a global texture pool that is persistent diff --git a/source/blender/viewport_compositor/intern/evaluator.cc b/source/blender/viewport_compositor/intern/evaluator.cc index 14d3edc3b18..bc60a660f04 100644 --- a/source/blender/viewport_compositor/intern/evaluator.cc +++ b/source/blender/viewport_compositor/intern/evaluator.cc @@ -27,9 +27,13 @@ Evaluator::Evaluator(Context &context, bNodeTree &node_tree) void Evaluator::evaluate() { + /* Reset the texture pool that was potentially populated from a previous evaluation. */ + context_.texture_pool().reset(); + /* The node tree is not compiled yet, so compile and evaluate the node tree. */ if (!is_compiled_) { compile_and_evaluate(); + is_compiled_ = true; return; } @@ -80,9 +84,6 @@ void Evaluator::compile_and_evaluate() compile_and_evaluate_node(node, compile_state); } } - - /* Mark the node tree as compiled. */ - is_compiled_ = true; } void Evaluator::compile_and_evaluate_node(DNode node, CompileState &compile_state) diff --git a/source/blender/viewport_compositor/intern/operation.cc b/source/blender/viewport_compositor/intern/operation.cc index bd757af781b..7558fc9c51f 100644 --- a/source/blender/viewport_compositor/intern/operation.cc +++ b/source/blender/viewport_compositor/intern/operation.cc @@ -169,6 +169,7 @@ void Operation::evaluate_input_processors() /* The input processors are not added yet, so add and evaluate the input processors. */ if (!input_processors_added_) { add_and_evaluate_input_processors(); + input_processors_added_ = true; return; } diff --git a/source/blender/viewport_compositor/intern/texture_pool.cc b/source/blender/viewport_compositor/intern/texture_pool.cc index 2c08bf90335..7fcc5a4d010 100644 --- a/source/blender/viewport_compositor/intern/texture_pool.cc +++ b/source/blender/viewport_compositor/intern/texture_pool.cc @@ -61,9 +61,9 @@ GPUTexture *TexturePool::acquire_color(int2 size) return acquire(size, GPU_RGBA16F); } -/* Vectors are and should be stored in RGBA textures. */ GPUTexture *TexturePool::acquire_vector(int2 size) { + /* Vectors are stored in RGBA textures because RGB textures have limited support. */ return acquire(size, GPU_RGBA16F); } @@ -77,4 +77,9 @@ void TexturePool::release(GPUTexture *texture) textures_.lookup(TexturePoolKey(texture)).append(texture); } +void TexturePool::reset() +{ + textures_.clear(); +} + } // namespace blender::viewport_compositor |