From 35d3b6316b21ad9ae7eb96a7a541c4051eae3441 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Mon, 19 Jan 2015 18:13:26 +0100 Subject: D627: Memory usage optimization for the compositor. The compostor used a fixed size of 4 floats to hold pixel data. this patch will select size of a pixel based on its type. It uses 1 float for Value, 3 float for vector and 4 floats for color data types. When benchmarking on shots (opening shot of caminandes) we get a reduction of memory of 30% and a tiny speedup as less data transformations needs to take place (but these are negligable. More information of the patch can be found on https://developer.blender.org/D627 and http://wiki.blender.org/index.php/Dev:Ref/Proposals/Compositor2014_p1.1_TD Developers: jbakker & mdewanchand Thanks for Sergey for his indept review. --- .../compositor/operations/COM_TextureOperation.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source/blender/compositor/operations/COM_TextureOperation.cpp') diff --git a/source/blender/compositor/operations/COM_TextureOperation.cpp b/source/blender/compositor/operations/COM_TextureOperation.cpp index ede767cbff7..da01aa3b7ca 100644 --- a/source/blender/compositor/operations/COM_TextureOperation.cpp +++ b/source/blender/compositor/operations/COM_TextureOperation.cpp @@ -77,12 +77,9 @@ void TextureBaseOperation::determineResolution(unsigned int resolution[2], unsig void TextureAlphaOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler) { - TextureBaseOperation::executePixelSampled(output, x, y, sampler); - output[0] = output[3]; - output[1] = 0.0f; - output[2] = 0.0f; - output[3] = 0.0f; -} + float color[4]; + TextureBaseOperation::executePixelSampled(color, x, y, sampler); + output[0] = color[3];} void TextureBaseOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler) { @@ -124,18 +121,23 @@ MemoryBuffer *TextureBaseOperation::createMemoryBuffer(rcti *rect2) { int height = getHeight(); int width = getWidth(); + DataType datatype = this->getOutputSocket()->getDataType(); + int add = 4; + if (datatype == COM_DT_VALUE) { + add = 1; + } rcti rect; rect.xmin = 0; rect.ymin = 0; rect.xmax = width; rect.ymax = height; - MemoryBuffer *result = new MemoryBuffer(NULL, &rect); + MemoryBuffer *result = new MemoryBuffer(datatype, &rect); float *data = result->getBuffer(); for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++, data += 4) { + for (int x = 0; x < width; x++, data += add) { this->executePixelSampled(data, x, y, COM_PS_NEAREST); } } -- cgit v1.2.3