diff options
author | Manuel Castilla <manzanillawork@gmail.com> | 2021-06-23 18:21:17 +0300 |
---|---|---|
committer | Manuel Castilla <manzanillawork@gmail.com> | 2021-06-23 18:46:53 +0300 |
commit | 35db01325f41da34e5a71d2b28cc717cddbdb996 (patch) | |
tree | 923bfa9c71e1eda1f1fc25c01a7ebbd0382f0d49 /source/blender/compositor/operations | |
parent | 8f4d99159404621a9063f4bd155a519baf51f313 (diff) |
Compositor: Full frame Image node
Adds full frame implementation to Image node operations.
Mostly refactored into buffer utility methods for reuse in other
operations.
No functional changes.
1.8x faster than tiled fallback.
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D11559
Diffstat (limited to 'source/blender/compositor/operations')
4 files changed, 62 insertions, 2 deletions
diff --git a/source/blender/compositor/operations/COM_ImageOperation.cc b/source/blender/compositor/operations/COM_ImageOperation.cc index a1d401d4499..e78d389410f 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.cc +++ b/source/blender/compositor/operations/COM_ImageOperation.cc @@ -44,6 +44,7 @@ BaseImageOperation::BaseImageOperation() this->m_imageheight = 0; this->m_framenumber = 0; this->m_depthBuffer = nullptr; + depth_buffer_ = nullptr; this->m_numberOfChannels = 0; this->m_rd = nullptr; this->m_viewName = nullptr; @@ -91,6 +92,9 @@ void BaseImageOperation::initExecution() this->m_imageFloatBuffer = stackbuf->rect_float; this->m_imageByteBuffer = stackbuf->rect; this->m_depthBuffer = stackbuf->zbuf_float; + if (stackbuf->zbuf_float) { + depth_buffer_ = new MemoryBuffer(stackbuf->zbuf_float, 1, stackbuf->x, stackbuf->y); + } this->m_imagewidth = stackbuf->x; this->m_imageheight = stackbuf->y; this->m_numberOfChannels = stackbuf->channels; @@ -102,6 +106,10 @@ void BaseImageOperation::deinitExecution() this->m_imageFloatBuffer = nullptr; this->m_imageByteBuffer = nullptr; BKE_image_release_ibuf(this->m_image, this->m_buffer, nullptr); + if (depth_buffer_) { + delete depth_buffer_; + depth_buffer_ = nullptr; + } } void BaseImageOperation::determineResolution(unsigned int resolution[2], @@ -170,6 +178,13 @@ void ImageOperation::executePixelSampled(float output[4], float x, float y, Pixe } } +void ImageOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> UNUSED(inputs)) +{ + output->copy_from(m_buffer, area, true); +} + void ImageAlphaOperation::executePixelSampled(float output[4], float x, float y, @@ -187,6 +202,13 @@ void ImageAlphaOperation::executePixelSampled(float output[4], } } +void ImageAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> UNUSED(inputs)) +{ + output->copy_from(m_buffer, area, 3, COM_DATA_TYPE_VALUE_CHANNELS, 0); +} + void ImageDepthOperation::executePixelSampled(float output[4], float x, float y, @@ -206,4 +228,16 @@ void ImageDepthOperation::executePixelSampled(float output[4], } } +void ImageDepthOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> UNUSED(inputs)) +{ + if (depth_buffer_) { + output->copy_from(depth_buffer_, area); + } + else { + output->fill(area, COM_VALUE_ZERO); + } +} + } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_ImageOperation.h b/source/blender/compositor/operations/COM_ImageOperation.h index 58373663db5..f8b4239c9f8 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.h +++ b/source/blender/compositor/operations/COM_ImageOperation.h @@ -21,7 +21,7 @@ #include "BKE_image.h" #include "BLI_listbase.h" #include "BLI_utildefines.h" -#include "COM_NodeOperation.h" +#include "COM_MultiThreadedOperation.h" #include "MEM_guardedalloc.h" #include "RE_pipeline.h" @@ -32,14 +32,17 @@ namespace blender::compositor { /** * \brief Base class for all image operations */ -class BaseImageOperation : public NodeOperation { +class BaseImageOperation : public MultiThreadedOperation { protected: ImBuf *m_buffer; Image *m_image; ImageUser *m_imageUser; + /* TODO: Remove raw buffers when removing Tiled implementation. */ float *m_imageFloatBuffer; unsigned int *m_imageByteBuffer; float *m_depthBuffer; + + MemoryBuffer *depth_buffer_; int m_imageheight; int m_imagewidth; int m_framenumber; @@ -87,6 +90,10 @@ class ImageOperation : public BaseImageOperation { */ ImageOperation(); void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override; + + void update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) override; }; class ImageAlphaOperation : public BaseImageOperation { public: @@ -95,6 +102,10 @@ class ImageAlphaOperation : public BaseImageOperation { */ ImageAlphaOperation(); void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override; + + void update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) override; }; class ImageDepthOperation : public BaseImageOperation { public: @@ -103,6 +114,10 @@ class ImageDepthOperation : public BaseImageOperation { */ ImageDepthOperation(); void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override; + + void update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) override; }; } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_MultilayerImageOperation.cc b/source/blender/compositor/operations/COM_MultilayerImageOperation.cc index 647e93225e5..3a5de944a00 100644 --- a/source/blender/compositor/operations/COM_MultilayerImageOperation.cc +++ b/source/blender/compositor/operations/COM_MultilayerImageOperation.cc @@ -51,6 +51,13 @@ ImBuf *MultilayerBaseOperation::getImBuf() return nullptr; } +void MultilayerBaseOperation::update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> UNUSED(inputs)) +{ + output->copy_from(m_buffer, area); +} + std::unique_ptr<MetaData> MultilayerColorOperation::getMetaData() { BLI_assert(this->m_buffer); diff --git a/source/blender/compositor/operations/COM_MultilayerImageOperation.h b/source/blender/compositor/operations/COM_MultilayerImageOperation.h index 6e6062cf854..a682ca1941c 100644 --- a/source/blender/compositor/operations/COM_MultilayerImageOperation.h +++ b/source/blender/compositor/operations/COM_MultilayerImageOperation.h @@ -37,6 +37,10 @@ class MultilayerBaseOperation : public BaseImageOperation { * Constructor */ MultilayerBaseOperation(RenderLayer *render_layer, RenderPass *render_pass, int view); + + void update_memory_buffer_partial(MemoryBuffer *output, + const rcti &area, + Span<MemoryBuffer *> inputs) override; }; class MultilayerColorOperation : public MultilayerBaseOperation { |