1
1

Compare commits

...

33 Commits

Author SHA1 Message Date
7f4f588565 Fix for sunbeams operation 2014-09-22 21:20:03 +02:00
027640188a Merge remote-tracking branch 'blender-upstream/master' into blender-tiles 2014-09-22 20:12:21 +02:00
faf98bf3ab Cleaned up some code
- removed unneeded conversion to value buffer, the internal buffer now is a value buffer so no conversion needed.
 - removed ifdefs from deficus. the optimalization is not used for several years and no need to develop it any further
2014-09-22 20:05:58 +02:00
ef33f661d6 uhh.... missed some 2014-09-17 21:52:07 +02:00
d2e7d0435f Removed the virtual calls.
implemented the bicubic interpolation
2014-09-17 21:20:09 +02:00
3b61bdda6a Merge remote-tracking branch 'blender-upstream/master' into blender-tiles
Conflicts:
	source/blender/compositor/intern/COM_MemoryBuffer.cpp
2014-09-15 22:00:42 +02:00
483aea9a0e Merge remote-tracking branch 'blender-upstream/master' into blender-tiles 2014-08-05 19:10:55 +02:00
c95f31f831 Merge remote-tracking branch 'blender-upstream/master' into blender-tiles 2014-08-04 21:36:53 +02:00
a802c5370f Fix cycles render layers.
Cycles supports 3 channels and 4 channels colors, compositor only 4 channel.
compositor will use vector to store the 3 channel colors.
2014-08-01 21:46:34 +02:00
7997a36acf Modified NUMBER_OF_CHANNELS 2014-07-31 22:12:14 +02:00
5f7054817e Fixed comments sergey 2014-07-31 21:27:41 +02:00
f4b3c92716 Merge branch 'master' into blender-tiles 2014-07-29 22:29:23 +02:00
70a4977543 Merge remote-tracking branch 'blender-upstream/master' into blender-tiles 2014-07-15 20:26:48 +02:00
ba0fbba897 Defocus + VarSizedBokeh 2014-07-15 20:25:11 +02:00
2a87454903 Fix for bokeh blur 2014-07-15 20:03:52 +02:00
e5435b3d17 Added SAMPLING to the Bokeh blur. 2014-07-15 19:58:49 +02:00
5897c6799c First implementation of the samplers. Refactored the read methods from the buffers to wpecialized classes.
these classes can be optimized locally.

next step: remove the read methods from the buffer. they should al go through the samplers of the buffers
2014-07-14 23:01:35 +02:00
166c858313 linked history of workpackage to tile 2014-07-14 20:35:08 +02:00
9d0d803527 Merge remote-tracking branch 'blender-upstream/master' into blender-tiles 2014-07-14 20:02:17 +02:00
47c9aa158e Fix for bokeh blur - missed during migration 2014-07-09 21:51:00 +02:00
68824d5202 Allignment 2014-07-09 20:31:22 +02:00
970f24a156 Renamed no_channels to num_channels 2014-07-09 20:15:39 +02:00
a0ed9022e5 Merge remote-tracking branch 'blender-upstream/master' into blender-tiles 2014-07-09 18:36:29 +02:00
fcb04fe8e4 Removed unused code 2014-07-01 21:33:32 +02:00
70c27e0e44 Merge remote-tracking branch 'blender-upstream/master' into blender-tiles 2014-07-01 20:39:09 +02:00
c04e895e33 Updated to defaults 2014-07-01 20:38:16 +02:00
a84309e894 Merge remote-tracking branch 'blender-upstream/master' into blender-tiles
Conflicts:
	source/blender/compositor/intern/COM_MemoryBuffer.cpp
	source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
	source/blender/compositor/operations/COM_KeyingClipOperation.cpp
	source/blender/compositor/operations/COM_RenderLayersProg.cpp
2014-07-01 18:27:24 +02:00
1cb5c28653 TILES: started with the Tile class.
made sure that the tile class is used during scheduling and execution. For planning it is not used yet.
idea is to move the class creation to the front and make sure it stays correct
2014-05-26 22:17:08 +02:00
5fcc889baa Merge branch 'blender-tiles' of gitorious.org:blender-tiles/blender-tiles into blender-tiles
Conflicts:
	source/blender/blenlib/BLI_compiler_compat.h
	source/blender/compositor/CMakeLists.txt
	source/blender/compositor/intern/COM_ChannelInfo.h
	source/blender/compositor/intern/COM_ExecutionSystem.cpp
	source/blender/compositor/intern/COM_MemoryBuffer.cpp
	source/blender/compositor/intern/COM_OpenCLDevice.cpp
	source/blender/compositor/nodes/COM_SocketProxyNode.cpp
	source/blender/compositor/operations/COM_CompositorOperation.cpp
	source/blender/compositor/operations/COM_ReadBufferOperation.h
	source/blender/compositor/operations/COM_RenderLayersProg.cpp
2014-05-12 21:45:43 +02:00
3b691b54b1 Initialize colors, vectors and values in RenderLayersProg 2014-05-12 20:25:30 +02:00
948703b36d Tiles: synced with master 2014-05-12 20:22:40 +02:00
815c999382 Initialize colors, vectors and values in RenderLayersProg 2014-05-12 18:21:45 +02:00
0563280bff Compositor squashed patch reapplied
Started with the MemoryBufferValue
still a lot needs to be done
stopped at testing the dilate/erode

TILES: did some fixed for value buffer

Determine image format of OpenCL device

TILES: TextureNode fix

TILES: moved buffer sizes to constants for easy access.

TILES: fixed some nodes.
still working on the defocus node

TILES: fixed glare, keying, defocus, normalize, vector curves
2014-04-25 16:32:09 +02:00
71 changed files with 650 additions and 785 deletions

View File

@@ -76,8 +76,8 @@ set(SRC
intern/COM_MemoryBuffer.h
intern/COM_WorkScheduler.cpp
intern/COM_WorkScheduler.h
intern/COM_WorkPackage.cpp
intern/COM_WorkPackage.h
intern/COM_Tile.cpp
intern/COM_Tile.h
intern/COM_ChunkOrder.cpp
intern/COM_ChunkOrder.h
intern/COM_ChunkOrderHotspot.cpp
@@ -90,8 +90,6 @@ set(SRC
intern/COM_OpenCLDevice.h
intern/COM_CompositorContext.cpp
intern/COM_CompositorContext.h
intern/COM_ChannelInfo.cpp
intern/COM_ChannelInfo.h
intern/COM_SingleThreadedOperation.cpp
intern/COM_SingleThreadedOperation.h
intern/COM_Debug.cpp

View File

@@ -105,7 +105,9 @@ typedef enum OrderOfChunks {
#define COM_RULE_OF_THIRDS_DIVIDER 100.0f
#define COM_NUMBER_OF_CHANNELS 4
#define COM_NUM_CHANNELS_VALUE 1
#define COM_NUM_CHANNELS_VECTOR 3
#define COM_NUM_CHANNELS_COLOR 4
#define COM_BLUR_BOKEH_PIXELS 512

View File

@@ -22,16 +22,11 @@
#include "COM_CPUDevice.h"
void CPUDevice::execute(WorkPackage *work)
void CPUDevice::execute(Tile *tile)
{
const unsigned int chunkNumber = work->getChunkNumber();
ExecutionGroup *executionGroup = work->getExecutionGroup();
rcti rect;
executionGroup->determineChunkRect(&rect, chunkNumber);
executionGroup->getOutputOperation()->executeRegion(&rect, chunkNumber);
executionGroup->finalizeChunkExecution(chunkNumber, NULL);
ExecutionGroup *executionGroup = tile->getExecutionGroup();
NodeOperation * operation = executionGroup->getOutputOperation();
operation->executeRegion(tile);
executionGroup->finalizeChunkExecution(tile->get_tile_number(), NULL);
}

View File

@@ -35,7 +35,7 @@ public:
* @brief execute a WorkPackage
* @param work the WorkPackage to execute
*/
void execute(WorkPackage *work);
void execute(Tile *work);
};
#endif

View File

@@ -1,35 +0,0 @@
/*
* Copyright 2011, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
#include "COM_ChannelInfo.h"
#include "COM_defines.h"
#include <stdio.h>
/**
* @brief create new ChannelInfo instance and sets the defaults.
*/
ChannelInfo::ChannelInfo()
{
this->m_number = 0;
this->m_premultiplied = true;
this->m_type = COM_CT_UNUSED;
}

View File

@@ -1,121 +0,0 @@
/*
* Copyright 2011, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
#ifndef _COM_ChannelInfo_h
#define _COM_ChannelInfo_h
#include <vector>
#include "BKE_text.h"
#include <string>
#include "DNA_node_types.h"
#include "BLI_rect.h"
using namespace std;
/**
* @brief List of possible channel types
* @ingroup Model
*/
typedef enum ChannelType {
COM_CT_ColorComponent /** @brief this channel is contains color information. Specific used is determined by channelnumber, and in the future color space */,
COM_CT_Alpha /** @brief this channel is contains transparency value */,
COM_CT_Value /** @brief this channel is contains a value */,
COM_CT_X /** @brief this channel is contains a X value */,
COM_CT_Y /** @brief this channel is contains a Y value */,
COM_CT_Z /** @brief this channel is contains a Z value */,
COM_CT_W /** @brief this channel is contains a W value */,
COM_CT_UNUSED /** @brief this channel is unused */
} ChannelType;
/**
* @brief ChannelInfo holds information about a channel.
*
* Channels are transported from node to node via a NodeLink.
* ChannelInfo holds specific setting of these channels in order that the to-node of the link
* Can handle specific logic per channel setting.
*
* @note currently this is not used, but a future place to implement color spacing and other things.
* @ingroup Model
*/
class ChannelInfo {
private:
/**
* @brief the channel number, in the link. [0-3]
*/
int m_number;
/**
* @brief type of channel
*/
ChannelType m_type;
/**
* @brieg Is this value in this channel premultiplied with its alpha
* @note only valid if type = ColorComponent;
*/
bool m_premultiplied;
// /**
// * Color space of this value.
// * only valid when type = ColorComponent;
// */
// string colorspacename;
public:
/**
* @brief creates a new ChannelInfo and set default values
*/
ChannelInfo();
/**
* @brief set the index of this channel in the NodeLink
*/
void setNumber(const int number) { this->m_number = number; }
/**
* @brief get the index of this channel in the NodeLink
*/
const int getNumber() const { return this->m_number; }
/**
* @brief set the type of channel
*/
void setType(const ChannelType type) { this->m_type = type; }
/**
* @brief get the type of channel
*/
const ChannelType getType() const { return this->m_type; }
/**
* @brief set the premultiplicatioin of this channel
*/
void setPremultiplied(const bool premultiplied) { this->m_premultiplied = premultiplied; }
/**
* @brief is this channel premultiplied
*/
const bool isPremultiplied() const { return this->m_premultiplied; }
};
#endif

View File

@@ -23,7 +23,7 @@
#ifndef _COM_Device_h
#define _COM_Device_h
#include "COM_WorkPackage.h"
#include "COM_Tile.h"
/**
* @brief Abstract class for device implementations to be used by the Compositor.
@@ -53,7 +53,7 @@ public:
* @brief execute a WorkPackage
* @param work the WorkPackage to execute
*/
virtual void execute(WorkPackage *work) = 0;
virtual void execute(Tile *work) = 0;
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("COM:Device")

View File

@@ -510,7 +510,10 @@ bool ExecutionGroup::scheduleChunk(unsigned int chunkNumber)
{
if (this->m_chunkExecutionStates[chunkNumber] == COM_ES_NOT_SCHEDULED) {
this->m_chunkExecutionStates[chunkNumber] = COM_ES_SCHEDULED;
WorkScheduler::schedule(this, chunkNumber);
rcti *rect = new rcti();
this->determineChunkRect(rect, chunkNumber);
Tile * tile = new Tile(this, rect, chunkNumber);
WorkScheduler::schedule(tile);
return true;
}
return false;

View File

@@ -98,7 +98,7 @@ ExecutionSystem::ExecutionSystem(RenderData *rd, Scene *scene, bNodeTree *editin
}
}
// DebugInfo::graphviz(this);
// DebugInfo::graphviz(this);
}
ExecutionSystem::~ExecutionSystem()
@@ -137,11 +137,15 @@ void ExecutionSystem::execute()
}
unsigned int index;
// First allocale all write buffers
for (index = 0; index < this->m_operations.size(); index++) {
NodeOperation *operation = this->m_operations[index];
operation->setbNodeTree(this->m_context.getbNodeTree());
operation->initExecution();
if (operation->isWriteBufferOperation()) {
operation->setbNodeTree(this->m_context.getbNodeTree());
operation->initExecution();
}
}
// Connect read buffers to their write buffers
for (index = 0; index < this->m_operations.size(); index++) {
NodeOperation *operation = this->m_operations[index];
if (operation->isReadBufferOperation()) {
@@ -149,6 +153,14 @@ void ExecutionSystem::execute()
readOperation->updateMemoryBuffer();
}
}
// initialize other operations
for (index = 0; index < this->m_operations.size(); index++) {
NodeOperation *operation = this->m_operations[index];
if (!operation->isWriteBufferOperation()) {
operation->setbNodeTree(this->m_context.getbNodeTree());
operation->initExecution();
}
}
for (index = 0; index < this->m_groups.size(); index++) {
ExecutionGroup *executionGroup = this->m_groups[index];
executionGroup->setChunksize(this->m_context.getChunksize());

View File

@@ -27,6 +27,18 @@
using std::min;
using std::max;
static unsigned int determine_num_channels(DataType datatype) {
switch (datatype) {
case COM_DT_VALUE:
return COM_NUM_CHANNELS_VALUE;
case COM_DT_VECTOR:
return COM_NUM_CHANNELS_VECTOR;
case COM_DT_COLOR:
default:
return COM_NUM_CHANNELS_COLOR;
}
}
unsigned int MemoryBuffer::determineBufferSize()
{
return getWidth() * getHeight();
@@ -34,60 +46,62 @@ unsigned int MemoryBuffer::determineBufferSize()
int MemoryBuffer::getWidth() const
{
return this->m_rect.xmax - this->m_rect.xmin;
return this->m_width;
}
int MemoryBuffer::getHeight() const
{
return this->m_rect.ymax - this->m_rect.ymin;
return this->m_height;
}
MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, unsigned int chunkNumber, rcti *rect)
{
BLI_rcti_init(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
this->m_width = this->m_rect.xmax - this->m_rect.xmin;
this->m_height = this->m_rect.ymax - this->m_rect.ymin;
this->m_memoryProxy = memoryProxy;
this->m_chunkNumber = chunkNumber;
this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * COM_NUMBER_OF_CHANNELS, 16, "COM_MemoryBuffer");
this->m_num_channels = determine_num_channels(memoryProxy->getDataType());
this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * this->m_num_channels, 16, "COM_MemoryBuffer");
this->m_state = COM_MB_ALLOCATED;
this->m_datatype = COM_DT_COLOR;
this->m_datatype = memoryProxy->getDataType();
this->m_chunkWidth = this->m_rect.xmax - this->m_rect.xmin;
}
MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, rcti *rect)
{
BLI_rcti_init(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
this->m_width = this->m_rect.xmax - this->m_rect.xmin;
this->m_height = this->m_rect.ymax - this->m_rect.ymin;
this->m_memoryProxy = memoryProxy;
this->m_chunkNumber = -1;
this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * COM_NUMBER_OF_CHANNELS, 16, "COM_MemoryBuffer");
this->m_num_channels = determine_num_channels(memoryProxy->getDataType());
this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * this->m_num_channels, 16, "COM_MemoryBuffer");
this->m_state = COM_MB_TEMPORARILY;
this->m_datatype = COM_DT_COLOR;
this->m_datatype = memoryProxy->getDataType();
this->m_chunkWidth = this->m_rect.xmax - this->m_rect.xmin;
}
MemoryBuffer::MemoryBuffer(DataType dataType, rcti *rect)
{
BLI_rcti_init(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
this->m_width = this->m_rect.xmax - this->m_rect.xmin;
this->m_height = this->m_rect.ymax - this->m_rect.ymin;
this->m_memoryProxy = NULL;
this->m_chunkNumber = -1;
this->m_num_channels = determine_num_channels(dataType);
this->m_buffer = (float *)MEM_mallocN_aligned(sizeof(float) * determineBufferSize() * this->m_num_channels, 16, "COM_MemoryBuffer");
this->m_state = COM_MB_TEMPORARILY;
this->m_datatype = dataType;
this->m_chunkWidth = this->m_rect.xmax - this->m_rect.xmin;
}
MemoryBuffer *MemoryBuffer::duplicate()
{
MemoryBuffer *result = new MemoryBuffer(this->m_memoryProxy, &this->m_rect);
memcpy(result->m_buffer, this->m_buffer, this->determineBufferSize() * COM_NUMBER_OF_CHANNELS * sizeof(float));
memcpy(result->m_buffer, this->m_buffer, this->determineBufferSize() * this->m_num_channels * sizeof(float));
return result;
}
void MemoryBuffer::clear()
{
memset(this->m_buffer, 0, this->determineBufferSize() * COM_NUMBER_OF_CHANNELS * sizeof(float));
}
float *MemoryBuffer::convertToValueBuffer()
{
const unsigned int size = this->determineBufferSize();
unsigned int i;
float *result = (float *)MEM_mallocN(sizeof(float) * size, __func__);
const float *fp_src = this->m_buffer;
float *fp_dst = result;
for (i = 0; i < size; i++, fp_dst++, fp_src += COM_NUMBER_OF_CHANNELS) {
*fp_dst = *fp_src;
}
return result;
memset(this->m_buffer, 0, this->determineBufferSize() * this->m_num_channels * sizeof(float));
}
float MemoryBuffer::getMaximumValue()
@@ -98,7 +112,7 @@ float MemoryBuffer::getMaximumValue()
const float *fp_src = this->m_buffer;
for (i = 0; i < size; i++, fp_src += COM_NUMBER_OF_CHANNELS) {
for (i = 0; i < size; i++, fp_src += this->m_num_channels) {
float value = *fp_src;
if (value > result) {
result = value;
@@ -116,7 +130,7 @@ float MemoryBuffer::getMaximumValue(rcti *rect)
BLI_rcti_isect(rect, &this->m_rect, &rect_clamp);
if (!BLI_rcti_is_empty(&rect_clamp)) {
MemoryBuffer *temp = new MemoryBuffer(NULL, &rect_clamp);
MemoryBuffer *temp = new MemoryBuffer(this->m_datatype, &rect_clamp);
temp->copyContentFrom(this);
float result = temp->getMaximumValue();
delete temp;
@@ -152,9 +166,9 @@ void MemoryBuffer::copyContentFrom(MemoryBuffer *otherBuffer)
for (otherY = minY; otherY < maxY; otherY++) {
otherOffset = ((otherY - otherBuffer->m_rect.ymin) * otherBuffer->m_chunkWidth + minX - otherBuffer->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
offset = ((otherY - this->m_rect.ymin) * this->m_chunkWidth + minX - this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
memcpy(&this->m_buffer[offset], &otherBuffer->m_buffer[otherOffset], (maxX - minX) * COM_NUMBER_OF_CHANNELS * sizeof(float));
otherOffset = ((otherY - otherBuffer->m_rect.ymin) * otherBuffer->m_chunkWidth + minX - otherBuffer->m_rect.xmin) * this->m_num_channels;
offset = ((otherY - this->m_rect.ymin) * this->m_chunkWidth + minX - this->m_rect.xmin) * this->m_num_channels;
memcpy(&this->m_buffer[offset], &otherBuffer->m_buffer[otherOffset], (maxX - minX) * this->m_num_channels * sizeof(float));
}
}
@@ -163,8 +177,8 @@ void MemoryBuffer::writePixel(int x, int y, const float color[4])
if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
y >= this->m_rect.ymin && y < this->m_rect.ymax)
{
const int offset = (this->m_chunkWidth * (y - this->m_rect.ymin) + x - this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
copy_v4_v4(&this->m_buffer[offset], color);
const int offset = (this->m_chunkWidth * (y - this->m_rect.ymin) + x - this->m_rect.xmin) * this->m_num_channels;
memcpy(&this->m_buffer[offset], color, sizeof(float)*this->m_num_channels);
}
}
@@ -173,8 +187,12 @@ void MemoryBuffer::addPixel(int x, int y, const float color[4])
if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
y >= this->m_rect.ymin && y < this->m_rect.ymax)
{
const int offset = (this->m_chunkWidth * (y - this->m_rect.ymin) + x - this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
add_v4_v4(&this->m_buffer[offset], color);
const int offset = (this->m_chunkWidth * (y - this->m_rect.ymin) + x - this->m_rect.xmin) * this->m_num_channels;
float *dst = &this->m_buffer[offset];
const float *src = color;
for (int i = 0; i < this->m_num_channels ; i++, dst++, src++) {
*dst += *src;
}
}
}
@@ -197,18 +215,15 @@ static void read_ewa_pixel_sampled(void *userdata, int x, int y, float result[4]
(float)y + data->vfac);
break;
case COM_PS_BICUBIC:
/* TOOD(sergey): no readBicubic method yet */
data->buffer->readBilinear(result,
default:
data->buffer->readBicubic(result,
(float)x + data->ufac,
(float)y + data->vfac);
break;
default:
zero_v4(result);
break;
}
}
void MemoryBuffer::readEWA(float result[4], const float uv[2], const float derivatives[2][2], PixelSampler sampler)
void MemoryBuffer::readEWA(float *result, const float uv[2], const float derivatives[2][2], PixelSampler sampler)
{
ReadEWAData data;
data.buffer = this;

View File

@@ -97,6 +97,15 @@ private:
*/
float *m_buffer;
/**
* @brief the number of channels of a single value in the buffer.
* For value buffers this is 1, vector 3 and color 4
*/
unsigned int m_num_channels;
int m_width;
int m_height;
public:
/**
* @brief construct new MemoryBuffer for a chunk
@@ -107,6 +116,10 @@ public:
* @brief construct new temporarily MemoryBuffer for an area
*/
MemoryBuffer(MemoryProxy *memoryProxy, rcti *rect);
/**
* @brief construct new temporarily MemoryBuffer for an area
*/
MemoryBuffer(DataType datatype, rcti *rect);
/**
* @brief destructor
@@ -117,6 +130,8 @@ public:
* @brief read the ChunkNumber of this MemoryBuffer
*/
unsigned int getChunkNumber() { return this->m_chunkNumber; }
unsigned int get_num_channels() { return this->m_num_channels; }
/**
* @brief get the data of this MemoryBuffer
@@ -134,8 +149,8 @@ public:
inline void wrap_pixel(int &x, int &y, MemoryBufferExtend extend_x, MemoryBufferExtend extend_y)
{
int w = m_rect.xmax - m_rect.xmin;
int h = m_rect.ymax - m_rect.ymin;
int w = this->m_width;
int h = this->m_height;
x = x - m_rect.xmin;
y = y - m_rect.ymin;
@@ -163,8 +178,39 @@ public:
break;
}
}
inline void read(float result[4], int x, int y,
inline void wrap_pixel(float &x, float &y, MemoryBufferExtend extend_x, MemoryBufferExtend extend_y)
{
float w = (float)this->m_width;
float h = (float)this->m_height;
x = x - m_rect.xmin;
y = y - m_rect.ymin;
switch (extend_x) {
case COM_MB_CLIP:
break;
case COM_MB_EXTEND:
if (x < 0) x = 0.0f;
if (x >= w) x = w;
break;
case COM_MB_REPEAT:
x = fmodf(x, w);
break;
}
switch (extend_y) {
case COM_MB_CLIP:
break;
case COM_MB_EXTEND:
if (y < 0) y = 0.0f;
if (y >= h) y = h;
break;
case COM_MB_REPEAT:
y = fmodf(y, h);
break;
}
}
inline void read(float *result, int x, int y,
MemoryBufferExtend extend_x = COM_MB_CLIP,
MemoryBufferExtend extend_y = COM_MB_CLIP)
{
@@ -172,81 +218,66 @@ public:
bool clip_y = (extend_y == COM_MB_CLIP && (y < m_rect.ymin || y >= m_rect.ymax));
if (clip_x || clip_y) {
/* clip result outside rect is zero */
zero_v4(result);
for (int i = 0 ; i < this->m_num_channels ; i++, result++) {
*result = 0.0f;
}
}
else {
wrap_pixel(x, y, extend_x, extend_y);
const int offset = (this->m_chunkWidth * y + x) * COM_NUMBER_OF_CHANNELS;
copy_v4_v4(result, &this->m_buffer[offset]);
int u = x;
int v = y;
this->wrap_pixel(u, v, extend_x, extend_y);
const int offset = (this->m_chunkWidth * y + x) * this->m_num_channels;
float* buffer = &this->m_buffer[offset];
memcpy(result, buffer, sizeof(float)*this->m_num_channels);
}
}
inline void readNoCheck(float result[4], int x, int y,
inline void readNoCheck(float *result, int x, int y,
MemoryBufferExtend extend_x = COM_MB_CLIP,
MemoryBufferExtend extend_y = COM_MB_CLIP)
{
wrap_pixel(x, y, extend_x, extend_y);
const int offset = (this->m_chunkWidth * y + x) * COM_NUMBER_OF_CHANNELS;
int u = x;
int v = y;
this->wrap_pixel(u, v, extend_x, extend_y);
const int offset = (this->m_chunkWidth * v + u) * this->m_num_channels;
BLI_assert(offset >= 0);
BLI_assert(offset < this->determineBufferSize() * COM_NUMBER_OF_CHANNELS);
BLI_assert(!(extend_x == COM_MB_CLIP && (x < m_rect.xmin || x >= m_rect.xmax)) &&
!(extend_y == COM_MB_CLIP && (y < m_rect.ymin || y >= m_rect.ymax)));
BLI_assert(offset < this->determineBufferSize() * this->m_num_channels);
BLI_assert(!(extend_x == COM_MB_CLIP && (u < m_rect.xmin || u >= m_rect.xmax)) &&
!(extend_y == COM_MB_CLIP && (v < m_rect.ymin || v >= m_rect.ymax)));
#if 0
/* always true */
BLI_assert((int)(MEM_allocN_len(this->m_buffer) / sizeof(*this->m_buffer)) ==
(int)(this->determineBufferSize() * COM_NUMBER_OF_CHANNELS));
#endif
copy_v4_v4(result, &this->m_buffer[offset]);
float* buffer = &this->m_buffer[offset];
memcpy(result, buffer, sizeof(float)*this->m_num_channels);
}
void writePixel(int x, int y, const float color[4]);
void addPixel(int x, int y, const float color[4]);
inline void readBilinear(float result[4], float x, float y,
inline void readBilinear(float *result, float x, float y,
MemoryBufferExtend extend_x = COM_MB_CLIP,
MemoryBufferExtend extend_y = COM_MB_CLIP)
{
int x1 = floor(x);
int y1 = floor(y);
int x2 = x1 + 1;
int y2 = y1 + 1;
wrap_pixel(x1, y1, extend_x, extend_y);
wrap_pixel(x2, y2, extend_x, extend_y);
float valuex = x - x1;
float valuey = y - y1;
float mvaluex = 1.0f - valuex;
float mvaluey = 1.0f - valuey;
float color1[4];
float color2[4];
float color3[4];
float color4[4];
read(color1, x1, y1);
read(color2, x1, y2);
read(color3, x2, y1);
read(color4, x2, y2);
color1[0] = color1[0] * mvaluey + color2[0] * valuey;
color1[1] = color1[1] * mvaluey + color2[1] * valuey;
color1[2] = color1[2] * mvaluey + color2[2] * valuey;
color1[3] = color1[3] * mvaluey + color2[3] * valuey;
color3[0] = color3[0] * mvaluey + color4[0] * valuey;
color3[1] = color3[1] * mvaluey + color4[1] * valuey;
color3[2] = color3[2] * mvaluey + color4[2] * valuey;
color3[3] = color3[3] * mvaluey + color4[3] * valuey;
result[0] = color1[0] * mvaluex + color3[0] * valuex;
result[1] = color1[1] * mvaluex + color3[1] * valuex;
result[2] = color1[2] * mvaluex + color3[2] * valuex;
result[3] = color1[3] * mvaluex + color3[3] * valuex;
float u = x;
float v = y;
this->wrap_pixel(u, v, extend_x, extend_y);
BLI_bilinear_interpolation_fl(this->m_buffer, result, this->m_width, this->m_height, this->m_num_channels, u, v);
}
inline void readBicubic(float *result, float x, float y,
MemoryBufferExtend extend_x = COM_MB_CLIP,
MemoryBufferExtend extend_y = COM_MB_CLIP)
{
float u = x;
float v = y;
this->wrap_pixel(u, v, extend_x, extend_y);
BLI_bicubic_interpolation_fl(this->m_buffer, result, this->m_width, this->m_height, this->m_num_channels, u, v);
}
void readEWA(float result[4], const float uv[2], const float derivatives[2][2], PixelSampler sampler);
void readEWA(float *result, const float uv[2], const float derivatives[2][2], PixelSampler sampler);
/**
* @brief is this MemoryBuffer a temporarily buffer (based on an area, not on a chunk)
@@ -284,7 +315,6 @@ public:
MemoryBuffer *duplicate();
float *convertToValueBuffer();
float getMaximumValue();
float getMaximumValue(rcti *rect);
private:

View File

@@ -23,10 +23,11 @@
#include "COM_MemoryProxy.h"
MemoryProxy::MemoryProxy()
MemoryProxy::MemoryProxy(DataType type)
{
this->m_writeBufferOperation = NULL;
this->m_executor = NULL;
this->m_datatype = type;
}
void MemoryProxy::allocate(unsigned int width, unsigned int height)

View File

@@ -47,12 +47,7 @@ private:
* @brief reference to the executor. the Execution group that can fill a chunk
*/
ExecutionGroup *m_executor;
/**
* @brief datatype of this MemoryProxy
*/
/* DataType m_datatype; */ /* UNUSED */
/**
* @brief channel information of this buffer
*/
@@ -63,8 +58,13 @@ private:
*/
MemoryBuffer *m_buffer;
/**
* @brief datatype of this MemoryProxy
*/
DataType m_datatype;
public:
MemoryProxy();
MemoryProxy(DataType type);
/**
* @brief set the ExecutionGroup that can be scheduled to calculate a certain chunk.
@@ -104,6 +104,8 @@ public:
*/
inline MemoryBuffer *getBuffer() { return this->m_buffer; }
inline DataType getDataType() { return this->m_datatype; }
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("COM:MemoryProxy")
#endif

View File

@@ -188,9 +188,9 @@ void NodeInput::getEditorValueVector(float *value)
********************/
NodeOutput::NodeOutput(Node *node, bNodeSocket *b_socket, DataType datatype) :
m_node(node),
m_editorSocket(b_socket),
m_datatype(datatype)
m_node(node),
m_editorSocket(b_socket),
m_datatype(datatype)
{
}

View File

@@ -47,6 +47,7 @@ using std::max;
class OpenCLDevice;
class ReadBufferOperation;
class WriteBufferOperation;
class Tile;
class NodeOperationInput;
class NodeOperationOutput;
@@ -175,7 +176,7 @@ public:
* @param chunkNumber the chunkNumber to be calculated
* @param memoryBuffers all input MemoryBuffer's needed
*/
virtual void executeRegion(rcti *rect, unsigned int chunkNumber) {}
virtual void executeRegion(Tile* tile) {}
/**
* @brief when a chunk is executed by an OpenCLDevice, this method is called

View File

@@ -476,7 +476,7 @@ void NodeOperationBuilder::add_input_buffers(NodeOperation *operation, NodeOpera
/* check of other end already has write operation, otherwise add a new one */
WriteBufferOperation *writeoperation = find_attached_write_buffer_operation(output);
if (!writeoperation) {
writeoperation = new WriteBufferOperation();
writeoperation = new WriteBufferOperation(output->getDataType());
writeoperation->setbNodeTree(m_context->getbNodeTree());
addOperation(writeoperation);
@@ -486,7 +486,7 @@ void NodeOperationBuilder::add_input_buffers(NodeOperation *operation, NodeOpera
}
/* add readbuffer op for the input */
ReadBufferOperation *readoperation = new ReadBufferOperation();
ReadBufferOperation *readoperation = new ReadBufferOperation(output->getDataType());
readoperation->setMemoryProxy(writeoperation->getMemoryProxy());
this->addOperation(readoperation);
@@ -519,7 +519,7 @@ void NodeOperationBuilder::add_output_buffers(NodeOperation *operation, NodeOper
/* if no write buffer operation exists yet, create a new one */
if (!writeOperation) {
writeOperation = new WriteBufferOperation();
writeOperation = new WriteBufferOperation(operation->getOutputSocket()->getDataType());
writeOperation->setbNodeTree(m_context->getbNodeTree());
addOperation(writeOperation);
@@ -534,7 +534,7 @@ void NodeOperationBuilder::add_output_buffers(NodeOperation *operation, NodeOper
if (&target->getOperation() == writeOperation)
continue; /* skip existing write op links */
ReadBufferOperation *readoperation = new ReadBufferOperation();
ReadBufferOperation *readoperation = new ReadBufferOperation(operation->getOutputSocket()->getDataType());
readoperation->setMemoryProxy(writeOperation->getMemoryProxy());
addOperation(readoperation);

View File

@@ -24,6 +24,18 @@
#include "COM_WorkScheduler.h"
typedef enum COM_VendorID {NVIDIA = 0x10DE, AMD = 0x1002} COM_VendorID;
const cl_image_format IMAGE_FORMAT_COLOR = {
CL_RGBA,
CL_FLOAT
};
const cl_image_format IMAGE_FORMAT_VECTOR = {
CL_RGB,
CL_FLOAT
};
const cl_image_format IMAGE_FORMAT_VALUE = {
CL_R,
CL_FLOAT
};
OpenCLDevice::OpenCLDevice(cl_context context, cl_device_id device, cl_program program, cl_int vendorId)
{
@@ -48,21 +60,19 @@ void OpenCLDevice::deinitialize()
}
}
void OpenCLDevice::execute(WorkPackage *work)
void OpenCLDevice::execute(Tile *tile)
{
const unsigned int chunkNumber = work->getChunkNumber();
ExecutionGroup *executionGroup = work->getExecutionGroup();
rcti rect;
const unsigned int chunkNumber = tile->get_tile_number();
ExecutionGroup *executionGroup = tile->getExecutionGroup();
rcti *rect = tile->get_rect();
executionGroup->determineChunkRect(&rect, chunkNumber);
MemoryBuffer **inputBuffers = executionGroup->getInputBuffersOpenCL(chunkNumber);
MemoryBuffer *outputBuffer = executionGroup->allocateOutputBuffer(chunkNumber, &rect);
MemoryBuffer *outputBuffer = executionGroup->allocateOutputBuffer(chunkNumber, rect);
executionGroup->getOutputOperation()->executeOpenCLRegion(this, &rect,
executionGroup->getOutputOperation()->executeOpenCLRegion(this, rect,
chunkNumber, inputBuffers, outputBuffer);
delete outputBuffer;
executionGroup->finalizeChunkExecution(chunkNumber, inputBuffers);
}
cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex,
@@ -72,6 +82,21 @@ cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel,
return COM_clAttachMemoryBufferToKernelParameter(kernel, parameterIndex, offsetIndex, cleanup, inputMemoryBuffers, (ReadBufferOperation *)reader);
}
const cl_image_format* OpenCLDevice::determineImageFormat(MemoryBuffer *memoryBuffer)
{
const cl_image_format *imageFormat;
int num_channels = memoryBuffer->get_num_channels();
if (num_channels == 1) {
imageFormat = &IMAGE_FORMAT_VALUE;
} else if (num_channels == 3) {
imageFormat = &IMAGE_FORMAT_VECTOR;
} else {
imageFormat = &IMAGE_FORMAT_COLOR;
}
return imageFormat;
}
cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex,
list<cl_mem> *cleanup, MemoryBuffer **inputMemoryBuffers,
ReadBufferOperation *reader)
@@ -80,12 +105,9 @@ cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel,
MemoryBuffer *result = reader->getInputMemoryBuffer(inputMemoryBuffers);
const cl_image_format imageFormat = {
CL_RGBA,
CL_FLOAT
};
const cl_image_format *imageFormat = determineImageFormat(result);
cl_mem clBuffer = clCreateImage2D(this->m_context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, &imageFormat, result->getWidth(),
cl_mem clBuffer = clCreateImage2D(this->m_context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageFormat, result->getWidth(),
result->getHeight(), 0, result->getBuffer(), &error);
if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
@@ -192,5 +214,4 @@ cl_kernel OpenCLDevice::COM_clCreateKernel(const char *kernelname, list<cl_kerne
if (clKernelsToCleanUp) clKernelsToCleanUp->push_back(kernel);
}
return kernel;
}

View File

@@ -92,7 +92,14 @@ public:
* @brief execute a WorkPackage
* @param work the WorkPackage to execute
*/
void execute(WorkPackage *work);
void execute(Tile *work);
/**
* @brief determine an image format
* @param memorybuffer
*/
static const cl_image_format* determineImageFormat(MemoryBuffer *memoryBuffer);
cl_context getContext() { return this->m_context; }

View File

@@ -0,0 +1,83 @@
/*
* Copyright 2011, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
#ifndef _COM_OutputSocket_h
#define _COM_OutputSocket_h
#include <vector>
#include "COM_Socket.h"
using namespace std;
class SocketConnection;
class Node;
class InputSocket;
class WriteBufferOperation;
//#define COM_ST_INPUT 0
//#define COM_ST_OUTPUT 1
/**
* @brief OutputSocket are sockets that can send data/input
* @ingroup Model
*/
class OutputSocket : public Socket {
private:
vector<SocketConnection *> m_connections;
void removeFirstConnection();
public:
OutputSocket(DataType datatype);
OutputSocket(DataType datatype, int inputSocketDataTypeDeterminatorIndex);
OutputSocket(OutputSocket *from);
void addConnection(SocketConnection *connection);
void removeConnection(SocketConnection *connection);
SocketConnection *getConnection(unsigned int index) { return this->m_connections[index]; }
const int isConnected() const;
int isOutputSocket() const;
/**
* @brief determine the resolution of this socket
* @param resolution the result of this operation
* @param preferredResolution the preferable resolution as no resolution could be determined
*/
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
/**
* @brief determine the actual data type and channel info.
*/
void relinkConnections(OutputSocket *relinkToSocket) { this->relinkConnections(relinkToSocket, false); }
void relinkConnections(OutputSocket *relinkToSocket, bool single);
const int getNumberOfConnections() { return this->m_connections.size(); }
void clearConnections();
/**
* @brief find a connected write buffer operation to this OutputSocket
* @return WriteBufferOperation or NULL
*/
WriteBufferOperation *findAttachedWriteBufferOperation() const;
ChannelInfo *getChannelInfo(const int channelnumber);
private:
};
#endif

View File

@@ -20,10 +20,16 @@
* Monique Dewanchand
*/
#include "COM_WorkPackage.h"
#include "COM_Tile.h"
#include "COM_WorkScheduler.h"
WorkPackage::WorkPackage(ExecutionGroup *group, unsigned int chunkNumber)
Tile::Tile(ExecutionGroup *group, rcti *rect, unsigned int tile_number)
{
this->m_executionGroup = group;
this->m_chunkNumber = chunkNumber;
this->m_rect = rect;
this->m_tile_number = tile_number;
}
Tile::~Tile() {
delete this->m_rect;
}

View File

@@ -0,0 +1,97 @@
/*
* Copyright 2011, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
class Tile;
#ifndef _COM_Tile_h_
#define _COM_Tile_h_
class ExecutionGroup;
#include "COM_ExecutionGroup.h"
class WorkScheduler;
#include <vector>
/**
* @brief A tile is the work that can be scheduled.
*
* The scheduling is triggered in the ExecutionGroup and it will be executed by the CPUDevice or OpenCLDevice.
* The scheduling is implemented in the WorkScheduler
*
* @see ExecutionGroup
* @see WorkScheduler
* @see CPUDevice
* @see OpenCLDevice
*/
class Tile {
private:
/**
* @brief executionGroup with the operations-setup to be evaluated
*/
ExecutionGroup *m_executionGroup;
/**
* @brief rcti that this tile calculates from an ExecutionGroup
*/
rcti *m_rect;
/**
* @brief m_tile_number this is the tile number/chunk number of the old scheduling system.
* It is currently used as interface data towards the ExecutionGroup. This interface will be changed
* in the future and thereby will make this data unneeded.
*/
unsigned int m_tile_number;
public:
/**
* @brief constructor
*/
Tile(ExecutionGroup *group, rcti *rect, unsigned int tile_number);
/**
* @brief descructor
*/
~Tile();
/**
* @brief get the ExecutionGroup
*/
ExecutionGroup *getExecutionGroup() const { return this->m_executionGroup; }
/**
* @brief get_rect get the rectangle of this tile
* @return reference to the rcti
*/
rcti* get_rect() { return this->m_rect; }
/**
* @brief get_tile_number
* @return return the chunk number of this tile
*/
unsigned int get_tile_number() { return this->m_tile_number; }
private:
friend class ExecutionGroup;
friend class WorkScheduler;
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("COM:Tile")
#endif
};
#endif

View File

@@ -1,68 +0,0 @@
/*
* Copyright 2011, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
class WorkPackage;
#ifndef _COM_WorkPackage_h_
#define _COM_WorkPackage_h_
class ExecutionGroup;
#include "COM_ExecutionGroup.h"
/**
* @brief contains data about work that can be scheduled
* @see WorkScheduler
*/
class WorkPackage {
private:
/**
* @brief executionGroup with the operations-setup to be evaluated
*/
ExecutionGroup *m_executionGroup;
/**
* @brief number of the chunk to be executed
*/
unsigned int m_chunkNumber;
public:
/**
* constructor
* @param group the ExecutionGroup
* @param chunkNumber the number of the chunk
*/
WorkPackage(ExecutionGroup *group, unsigned int chunkNumber);
/**
* @brief get the ExecutionGroup
*/
ExecutionGroup *getExecutionGroup() const { return this->m_executionGroup; }
/**
* @brief get the number of the chunk
*/
unsigned int getChunkNumber() const { return this->m_chunkNumber; }
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("COM:WorkPackage")
#endif
};
#endif

View File

@@ -152,12 +152,12 @@ int COM_isHighlightedbNode(bNode *bnode)
void *WorkScheduler::thread_execute_cpu(void *data)
{
Device *device = (Device *)data;
WorkPackage *work;
Tile *tile;
while ((work = (WorkPackage *)BLI_thread_queue_pop(g_cpuqueue))) {
HIGHLIGHT(work);
device->execute(work);
delete work;
while ((tile = (Tile *)BLI_thread_queue_pop(g_cpuqueue))) {
HIGHLIGHT(tile);
device->execute(tile);
delete tile;
}
return NULL;
@@ -166,12 +166,12 @@ void *WorkScheduler::thread_execute_cpu(void *data)
void *WorkScheduler::thread_execute_gpu(void *data)
{
Device *device = (Device *)data;
WorkPackage *work;
Tile *tile;
while ((work = (WorkPackage *)BLI_thread_queue_pop(g_gpuqueue))) {
HIGHLIGHT(work);
device->execute(work);
delete work;
while ((tile = (Tile*)BLI_thread_queue_pop(g_gpuqueue))) {
HIGHLIGHT(tile);
device->execute(tile);
delete tile;
}
return NULL;
@@ -180,23 +180,22 @@ void *WorkScheduler::thread_execute_gpu(void *data)
void WorkScheduler::schedule(ExecutionGroup *group, int chunkNumber)
void WorkScheduler::schedule(Tile *tile)
{
WorkPackage *package = new WorkPackage(group, chunkNumber);
#if COM_CURRENT_THREADING_MODEL == COM_TM_NOTHREAD
CPUDevice device;
device.execute(package);
delete package;
device.execute(tile);
delete tile;
#elif COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
#ifdef COM_OPENCL_ENABLED
if (group->isOpenCL() && g_openclActive) {
BLI_thread_queue_push(g_gpuqueue, package);
if (tile->getExecutionGroup()->isOpenCL() && g_openclActive) {
BLI_thread_queue_push(g_gpuqueue, tile);
}
else {
BLI_thread_queue_push(g_cpuqueue, package);
BLI_thread_queue_push(g_cpuqueue, tile);
}
#else
BLI_thread_queue_push(cpuqueue, package);
BLI_thread_queue_push(g_cpuqueue, tile);
#endif
#endif
}
@@ -239,7 +238,7 @@ void WorkScheduler::finish()
BLI_thread_queue_wait_finish(g_cpuqueue);
}
#else
BLI_thread_queue_wait_finish(cpuqueue);
BLI_thread_queue_wait_finish(g_cpuqueue);
#endif
#endif
}

View File

@@ -27,7 +27,6 @@
extern "C" {
# include "BLI_threads.h"
}
#include "COM_WorkPackage.h"
#include "COM_defines.h"
#include "COM_Device.h"
@@ -64,7 +63,7 @@ public:
* @param group the execution group
* @param chunkNumber the number of the chunk in the group to be executed
*/
static void schedule(ExecutionGroup *group, int chunkNumber);
static void schedule(Tile* tile);
/**
* @brief initialize the WorkScheduler

View File

@@ -103,14 +103,6 @@ void DefocusNode::convertToOperations(NodeConverter &converter, const Compositor
bokeh->deleteDataOnFinish();
converter.addOperation(bokeh);
#ifdef COM_DEFOCUS_SEARCH
InverseSearchRadiusOperation *search = new InverseSearchRadiusOperation();
search->setMaxBlur(data->maxblur);
converter.addOperation(search);
converter.addLink(radiusOperation->getOutputSocket(0), search->getInputSocket(0));
#endif
VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation();
if (data->preview)
operation->setQuality(COM_QUALITY_LOW);
@@ -122,9 +114,6 @@ void DefocusNode::convertToOperations(NodeConverter &converter, const Compositor
converter.addLink(bokeh->getOutputSocket(), operation->getInputSocket(1));
converter.addLink(radiusOperation->getOutputSocket(), operation->getInputSocket(2));
#ifdef COM_DEFOCUS_SEARCH
converter.addLink(search->getOutputSocket(), operation->getInputSocket(3));
#endif
if (data->gamco) {
GammaCorrectOperation *correct = new GammaCorrectOperation();

View File

@@ -73,8 +73,9 @@ void SocketBufferNode::convertToOperations(NodeConverter &converter, const Compo
NodeOutput *output = this->getOutputSocket(0);
NodeInput *input = this->getInputSocket(0);
WriteBufferOperation *writeOperation = new WriteBufferOperation();
ReadBufferOperation *readOperation = new ReadBufferOperation();
DataType datatype = output->getDataType();
WriteBufferOperation *writeOperation = new WriteBufferOperation(datatype);
ReadBufferOperation *readOperation = new ReadBufferOperation(datatype);
readOperation->setMemoryProxy(writeOperation->getMemoryProxy());
converter.addOperation(writeOperation);
converter.addOperation(readOperation);

View File

@@ -57,8 +57,8 @@ void TranslateNode::convertToOperations(NodeConverter &converter, const Composit
converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
if (data->wrap_axis) {
WriteBufferOperation *writeOperation = new WriteBufferOperation();
WrapOperation *wrapOperation = new WrapOperation();
WriteBufferOperation *writeOperation = new WriteBufferOperation(COM_DT_COLOR);
WrapOperation *wrapOperation = new WrapOperation(COM_DT_COLOR);
wrapOperation->setMemoryProxy(writeOperation->getMemoryProxy());
wrapOperation->setWrapping(data->wrap_axis);

View File

@@ -95,7 +95,7 @@ void *AntiAliasOperation::initializeTileData(rcti *rect)
float *input = tile->getBuffer();
char *valuebuffer = (char *)MEM_mallocN(sizeof(char) * size, __func__);
for (int i = 0; i < size; i++) {
float in = input[i * COM_NUMBER_OF_CHANNELS];
float in = input[i];
valuebuffer[i] = FTOCHAR(in);
}
antialias_tagbuf(tile->getWidth(), tile->getHeight(), valuebuffer);

View File

@@ -110,11 +110,11 @@ void BokehBlurOperation::executePixel(float output[4], int x, int y, void *data)
int step = getStep();
int offsetadd = getOffsetAdd();
int offsetadd = getOffsetAdd() * COM_NUM_CHANNELS_COLOR;
float m = this->m_bokehDimension / pixelSize;
for (int ny = miny; ny < maxy; ny += step) {
int bufferindex = ((minx - bufferstartx) * 4) + ((ny - bufferstarty) * 4 * bufferwidth);
int bufferindex = ((minx - bufferstartx) * COM_NUM_CHANNELS_COLOR) + ((ny - bufferstarty) * COM_NUM_CHANNELS_COLOR * bufferwidth);
for (int nx = minx; nx < maxx; nx += step) {
float u = this->m_bokehMidX - (nx - x) * m;
float v = this->m_bokehMidY - (ny - y) * m;

View File

@@ -31,6 +31,7 @@ private:
SocketReader *m_inputProgram;
SocketReader *m_inputBokehProgram;
SocketReader *m_inputBoundingBoxReader;
void updateSize();
float m_size;
bool m_sizeavailable;

View File

@@ -125,12 +125,15 @@ void CompositorOperation::deinitExecution()
}
void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber)
void CompositorOperation::executeRegion(Tile* tile)
{
rcti * rect;
float color[8]; // 7 is enough
float *buffer = this->m_outputBuffer;
float *zbuffer = this->m_depthBuffer;
rect = tile->get_rect();
if (!buffer) return;
int x1 = rect->xmin;
int y1 = rect->ymin;
@@ -138,7 +141,7 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber)
int y2 = rect->ymax;
int offset = (y1 * this->getWidth() + x1);
int add = (this->getWidth() - (x2 - x1));
int offset4 = offset * COM_NUMBER_OF_CHANNELS;
int offset4 = offset * COM_NUM_CHANNELS_COLOR;
int x;
int y;
bool breaked = false;
@@ -187,7 +190,7 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber)
for (x = x1; x < x2 && (!breaked); x++) {
int input_x = x + dx, input_y = y + dy;
this->m_imageInput->readSampled(color, input_x, input_y, COM_PS_NEAREST);
this->m_imageInput->readSampled(color, input_x, input_y, COM_PS_NEAREST);
if (this->m_useAlphaInput) {
this->m_alphaInput->readSampled(&(color[3]), input_x, input_y, COM_PS_NEAREST);
}
@@ -196,14 +199,14 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber)
this->m_depthInput->readSampled(color, input_x, input_y, COM_PS_NEAREST);
zbuffer[offset] = color[0];
offset4 += COM_NUMBER_OF_CHANNELS;
offset4 += COM_NUM_CHANNELS_COLOR;
offset++;
if (isBreaked()) {
breaked = true;
}
}
offset += add;
offset4 += add * COM_NUMBER_OF_CHANNELS;
offset4 += add * COM_NUM_CHANNELS_COLOR;
}
}

View File

@@ -78,7 +78,7 @@ private:
public:
CompositorOperation();
const bool isActiveCompositorOutput() const { return this->m_active; }
void executeRegion(rcti *rect, unsigned int tileNumber);
void executeRegion(Tile* tile);
void setSceneName(const char *sceneName) { BLI_strncpy(this->m_sceneName, sceneName, sizeof(this->m_sceneName)); }
void setRenderData(const RenderData *rd) { this->m_rd = rd; }
bool isOutputOperation(bool rendering) const { return this->isActiveCompositorOutput(); }

View File

@@ -22,7 +22,6 @@
#include "COM_ConvertOperation.h"
ConvertBaseOperation::ConvertBaseOperation()
{
this->m_inputOperation = NULL;
@@ -49,9 +48,9 @@ ConvertValueToColorOperation::ConvertValueToColorOperation() : ConvertBaseOperat
void ConvertValueToColorOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float inputValue[4];
this->m_inputOperation->readSampled(inputValue, x, y, sampler);
output[0] = output[1] = output[2] = inputValue[0];
float value;
this->m_inputOperation->readSampled(&value, x, y, sampler);
output[0] = output[1] = output[2] = value;
output[3] = 1.0f;
}
@@ -98,7 +97,9 @@ ConvertColorToVectorOperation::ConvertColorToVectorOperation() : ConvertBaseOper
void ConvertColorToVectorOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
this->m_inputOperation->readSampled(output, x, y, sampler);
float color[4];
this->m_inputOperation->readSampled(color, x, y, sampler);
copy_v3_v3(output, color);
}
@@ -112,12 +113,9 @@ ConvertValueToVectorOperation::ConvertValueToVectorOperation() : ConvertBaseOper
void ConvertValueToVectorOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float input[4];
this->m_inputOperation->readSampled(input, x, y, sampler);
output[0] = input[0];
output[1] = input[0];
output[2] = input[0];
output[3] = 0.0f;
float value;
this->m_inputOperation->readSampled(&value, x, y, sampler);
output[0] = output[1] = output[2] = value;
}
@@ -131,7 +129,7 @@ ConvertVectorToColorOperation::ConvertVectorToColorOperation() : ConvertBaseOper
void ConvertVectorToColorOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
this->m_inputOperation->readSampled(output, x, y, sampler);
this->m_inputOperation->readSampled(output, x, y, sampler);
output[3] = 1.0f;
}

View File

@@ -72,7 +72,7 @@ void DilateErodeThresholdOperation::executePixel(float output[4], int x, int y,
const float inset = this->m_inset;
float mindist = rd * 2;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
MemoryBuffer *inputBuffer = (MemoryBuffer*)data;
float *buffer = inputBuffer->getBuffer();
rcti *rect = inputBuffer->getRect();
const int minx = max(x - this->m_scope, rect->xmin);
@@ -82,18 +82,18 @@ void DilateErodeThresholdOperation::executePixel(float output[4], int x, int y,
const int bufferWidth = BLI_rcti_size_x(rect);
int offset;
this->m_inputProgram->read(inputValue, x, y, NULL);
inputBuffer->read(inputValue, x, y);
if (inputValue[0] > sw) {
for (int yi = miny; yi < maxy; yi++) {
const float dy = yi - y;
offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin));
for (int xi = minx; xi < maxx; xi++) {
if (buffer[offset] < sw) {
const float dx = xi - x;
const float dis = dx * dx + dy * dy;
mindist = min(mindist, dis);
}
offset += 4;
offset ++;
}
}
pixelvalue = -sqrtf(mindist);
@@ -101,15 +101,14 @@ void DilateErodeThresholdOperation::executePixel(float output[4], int x, int y,
else {
for (int yi = miny; yi < maxy; yi++) {
const float dy = yi - y;
offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin));
for (int xi = minx; xi < maxx; xi++) {
if (buffer[offset] > sw) {
const float dx = xi - x;
const float dis = dx * dx + dy * dy;
mindist = min(mindist, dis);
}
offset += 4;
offset ++;
}
}
pixelvalue = sqrtf(mindist);
@@ -193,7 +192,7 @@ void DilateDistanceOperation::executePixel(float output[4], int x, int y, void *
const float mindist = distance * distance;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
float *buffer = inputBuffer->getBuffer();
rcti *rect = inputBuffer->getRect();
const int minx = max(x - this->m_scope, rect->xmin);
const int miny = max(y - this->m_scope, rect->ymin);
@@ -206,14 +205,14 @@ void DilateDistanceOperation::executePixel(float output[4], int x, int y, void *
for (int yi = miny; yi < maxy; yi++) {
const float dy = yi - y;
offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin));
for (int xi = minx; xi < maxx; xi++) {
const float dx = xi - x;
const float dis = dx * dx + dy * dy;
if (dis <= mindist) {
value = max(buffer[offset], value);
}
offset += 4;
offset ++;
}
}
output[0] = value;
@@ -280,14 +279,14 @@ void ErodeDistanceOperation::executePixel(float output[4], int x, int y, void *d
for (int yi = miny; yi < maxy; yi++) {
const float dy = yi - y;
offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin));
for (int xi = minx; xi < maxx; xi++) {
const float dx = xi - x;
const float dis = dx * dx + dy * dy;
if (dis <= mindist) {
value = min(buffer[offset], value);
}
offset += 4;
offset ++;
}
}
output[0] = value;
@@ -383,7 +382,7 @@ void *DilateStepOperation::initializeTileData(rcti *rect)
buf[x] = -FLT_MAX;
}
for (x = xmin; x < xmax; ++x) {
buf[x - rect->xmin + window - 1] = buffer[4 * (y * width + x)];
buf[x - rect->xmin + window - 1] = buffer[(y * width + x)];
}
for (i = 0; i < (bwidth + 3 * half_window) / window; i++) {
@@ -510,7 +509,7 @@ void *ErodeStepOperation::initializeTileData(rcti *rect)
buf[x] = FLT_MAX;
}
for (x = xmin; x < xmax; ++x) {
buf[x - rect->xmin + window - 1] = buffer[4 * (y * width + x)];
buf[x - rect->xmin + window - 1] = buffer[(y * width + x)];
}
for (i = 0; i < (bwidth + 3 * half_window) / window; i++) {

View File

@@ -1270,11 +1270,9 @@ void *DoubleEdgeMaskOperation::initializeTileData(rcti *rect)
MemoryBuffer *innerMask = (MemoryBuffer *)this->m_inputInnerMask->initializeTileData(rect);
MemoryBuffer *outerMask = (MemoryBuffer *)this->m_inputOuterMask->initializeTileData(rect);
float *data = (float *)MEM_mallocN(sizeof(float) * this->getWidth() * this->getHeight(), __func__);
float *imask = innerMask->convertToValueBuffer();
float *omask = outerMask->convertToValueBuffer();
float *imask = innerMask->getBuffer();
float *omask = outerMask->getBuffer();
doDoubleEdgeMask(imask, omask, data);
MEM_freeN(imask);
MEM_freeN(omask);
this->m_cachedInstance = data;
}
unlockMutex();

View File

@@ -92,16 +92,16 @@ void *FastGaussianBlurOperation::initializeTileData(rcti *rect)
this->m_sy = this->m_data.sizey * this->m_size / 2.0f;
if ((this->m_sx == this->m_sy) && (this->m_sx > 0.f)) {
for (c = 0; c < COM_NUMBER_OF_CHANNELS; ++c)
for (c = 0; c < COM_NUM_CHANNELS_COLOR; ++c)
IIR_gauss(copy, this->m_sx, c, 3);
}
else {
if (this->m_sx > 0.0f) {
for (c = 0; c < COM_NUMBER_OF_CHANNELS; ++c)
for (c = 0; c < COM_NUM_CHANNELS_COLOR; ++c)
IIR_gauss(copy, this->m_sx, c, 1);
}
if (this->m_sy > 0.0f) {
for (c = 0; c < COM_NUMBER_OF_CHANNELS; ++c)
for (c = 0; c < COM_NUM_CHANNELS_COLOR; ++c)
IIR_gauss(copy, this->m_sy, c, 2);
}
}
@@ -120,6 +120,7 @@ void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src, float sigma, unsign
unsigned int x, y, sz;
unsigned int i;
float *buffer = src->getBuffer();
const unsigned int num_channels = src->get_num_channels();
// <0.5 not valid, though can have a possibly useful sort of sharpening effect
if (sigma < 0.5f) return;
@@ -198,31 +199,31 @@ void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src, float sigma, unsign
int offset;
for (y = 0; y < src_height; ++y) {
const int yx = y * src_width;
offset = yx * COM_NUMBER_OF_CHANNELS + chan;
offset = yx * num_channels + chan;
for (x = 0; x < src_width; ++x) {
X[x] = buffer[offset];
offset += COM_NUMBER_OF_CHANNELS;
offset += num_channels;
}
YVV(src_width);
offset = yx * COM_NUMBER_OF_CHANNELS + chan;
offset = yx * num_channels + chan;
for (x = 0; x < src_width; ++x) {
buffer[offset] = Y[x];
offset += COM_NUMBER_OF_CHANNELS;
offset += num_channels;
}
}
}
if (xy & 2) { // V
int offset;
const int add = src_width * COM_NUMBER_OF_CHANNELS;
const int add = src_width * num_channels;
for (x = 0; x < src_width; ++x) {
offset = x * COM_NUMBER_OF_CHANNELS + chan;
offset = x * num_channels + chan;
for (y = 0; y < src_height; ++y) {
X[y] = buffer[offset];
offset += add;
}
YVV(src_height);
offset = x * COM_NUMBER_OF_CHANNELS + chan;
offset = x * num_channels + chan;
for (y = 0; y < src_height; ++y) {
buffer[offset] = Y[y];
offset += add;
@@ -298,7 +299,7 @@ void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect)
if (this->m_overlay == FAST_GAUSS_OVERLAY_MIN) {
float *src = newBuf->getBuffer();
float *dst = copy->getBuffer();
for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUMBER_OF_CHANNELS, dst += COM_NUMBER_OF_CHANNELS) {
for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUM_CHANNELS_VALUE, dst += COM_NUM_CHANNELS_VALUE) {
if (*src < *dst) {
*dst = *src;
}
@@ -307,15 +308,13 @@ void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect)
else if (this->m_overlay == FAST_GAUSS_OVERLAY_MAX) {
float *src = newBuf->getBuffer();
float *dst = copy->getBuffer();
for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUMBER_OF_CHANNELS, dst += COM_NUMBER_OF_CHANNELS) {
for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUM_CHANNELS_VALUE, dst += COM_NUM_CHANNELS_VALUE) {
if (*src > *dst) {
*dst = *src;
}
}
}
// newBuf->
this->m_iirgaus = copy;
}
unlockMutex();

View File

@@ -102,15 +102,14 @@ void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, vo
/* *** this is the main part which is different to 'GaussianXBlurOperation' *** */
int step = getStep();
int offsetadd = getOffsetAdd();
int bufferindex = ((xmin - bufferstartx) * 4) + ((ymin - bufferstarty) * 4 * bufferwidth);
int bufferindex = ((xmin - bufferstartx)) + ((ymin - bufferstarty) * bufferwidth);
/* gauss */
float alpha_accum = 0.0f;
float multiplier_accum = 0.0f;
/* dilate */
float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float value_max = finv_test(buffer[(x) + (y * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float distfacinv_max = 1.0f; /* 0 to 1 */
for (int nx = xmin; nx < xmax; nx += step) {
@@ -134,7 +133,7 @@ void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, vo
distfacinv_max = multiplier;
}
}
bufferindex += offsetadd;
bufferindex += step;
}
/* blend between the max value and gauss blue - gives nice feather */

View File

@@ -108,11 +108,11 @@ void GaussianAlphaYBlurOperation::executePixel(float output[4], int x, int y, vo
float multiplier_accum = 0.0f;
/* dilate */
float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float value_max = finv_test(buffer[(x) + (y * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float distfacinv_max = 1.0f; /* 0 to 1 */
for (int ny = ymin; ny < ymax; ny += step) {
int bufferindex = ((xmin - bufferstartx) * 4) + ((ny - bufferstarty) * 4 * bufferwidth);
int bufferindex = ((xmin - bufferstartx)) + ((ny - bufferstarty) * bufferwidth);
const int index = (ny - y) + this->m_filtersize;
float value = finv_test(buffer[bufferindex], do_invert);

View File

@@ -296,7 +296,7 @@ void GaussianBlurReferenceOperation::executePixel(float output[4], int x, int y,
int minyr = y - refrady < 0 ? -y : -refrady;
int maxyr = y + refrady > imgy ? imgy - y : refrady;
float *srcd = buffer + COM_NUMBER_OF_CHANNELS * ( (y + minyr) * imgx + x + minxr);
float *srcd = buffer + COM_NUM_CHANNELS_COLOR * ( (y + minyr) * imgx + x + minxr);
gausstabx = m_maintabs[refradx - 1];
gausstabcentx = gausstabx + refradx;
@@ -304,9 +304,9 @@ void GaussianBlurReferenceOperation::executePixel(float output[4], int x, int y,
gausstabcenty = gausstaby + refrady;
sum = gval = rval = bval = aval = 0.0f;
for (i = minyr; i < maxyr; i++, srcd += COM_NUMBER_OF_CHANNELS * imgx) {
for (i = minyr; i < maxyr; i++, srcd += COM_NUM_CHANNELS_COLOR * imgx) {
src = srcd;
for (j = minxr; j < maxxr; j++, src += COM_NUMBER_OF_CHANNELS) {
for (j = minxr; j < maxxr; j++, src += COM_NUM_CHANNELS_COLOR) {
val = gausstabcenty[i] * gausstabcentx[j];
sum += val;

View File

@@ -49,7 +49,7 @@ MemoryBuffer *GlareBaseOperation::createMemoryBuffer(rcti *rect2)
rect.ymin = 0;
rect.xmax = getWidth();
rect.ymax = getHeight();
MemoryBuffer *result = new MemoryBuffer(NULL, &rect);
MemoryBuffer *result = new MemoryBuffer(COM_DT_COLOR, &rect);
float *data = result->getBuffer();
this->generateGlare(data, tile, this->m_settings);
return result;

View File

@@ -259,8 +259,8 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
float *kernelBuffer = in2->getBuffer();
float *imageBuffer = in1->getBuffer();
MemoryBuffer *rdst = new MemoryBuffer(NULL, in1->getRect());
memset(rdst->getBuffer(), 0, rdst->getWidth() * rdst->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
MemoryBuffer *rdst = new MemoryBuffer(COM_DT_COLOR, in1->getRect());
memset(rdst->getBuffer(), 0, rdst->getWidth() * rdst->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float));
// convolution result width & height
w2 = 2 * kernelWidth - 1;
@@ -276,7 +276,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
// normalize convolutor
wt[0] = wt[1] = wt[2] = 0.f;
for (y = 0; y < kernelHeight; y++) {
colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUMBER_OF_CHANNELS];
colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < kernelWidth; x++)
add_v3_v3(wt, colp[x]);
}
@@ -284,7 +284,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
if (wt[1] != 0.f) wt[1] = 1.f / wt[1];
if (wt[2] != 0.f) wt[2] = 1.f / wt[2];
for (y = 0; y < kernelHeight; y++) {
colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUMBER_OF_CHANNELS];
colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < kernelWidth; x++)
mul_v3_v3(colp[x], wt);
}
@@ -313,7 +313,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
// in2, channel ch -> data1
for (y = 0; y < kernelHeight; y++) {
fp = &data1ch[y * w2];
colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUMBER_OF_CHANNELS];
colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < kernelWidth; x++)
fp[x] = colp[x][ch];
}
@@ -325,7 +325,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
int yy = ybl * ybsz + y;
if (yy >= imageHeight) continue;
fp = &data2[y * w2];
colp = (fRGB *)&imageBuffer[yy * imageWidth * COM_NUMBER_OF_CHANNELS];
colp = (fRGB *)&imageBuffer[yy * imageWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < xbsz; x++) {
int xx = xbl * xbsz + x;
if (xx >= imageWidth) continue;
@@ -349,7 +349,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
const int yy = ybl * ybsz + y - hh;
if ((yy < 0) || (yy >= imageHeight)) continue;
fp = &data2[y * w2];
colp = (fRGB *)&rdst->getBuffer()[yy * imageWidth * COM_NUMBER_OF_CHANNELS];
colp = (fRGB *)&rdst->getBuffer()[yy * imageWidth * COM_NUM_CHANNELS_COLOR];
for (x = 0; x < (int)w2; x++) {
const int xx = xbl * xbsz + x - hw;
if ((xx < 0) || (xx >= imageWidth)) continue;
@@ -364,7 +364,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2)
MEM_freeN(data2);
MEM_freeN(data1);
memcpy(dst, rdst->getBuffer(), sizeof(float) * imageWidth * imageHeight * COM_NUMBER_OF_CHANNELS);
memcpy(dst, rdst->getBuffer(), sizeof(float) * imageWidth * imageHeight * COM_NUM_CHANNELS_COLOR);
delete(rdst);
}
@@ -381,7 +381,7 @@ void GlareFogGlowOperation::generateGlare(float *data, MemoryBuffer *inputTile,
// make the convolution kernel
rcti kernelRect;
BLI_rcti_init(&kernelRect, 0, sz, 0, sz);
ckrn = new MemoryBuffer(NULL, &kernelRect);
ckrn = new MemoryBuffer(COM_DT_COLOR, &kernelRect);
scale = 0.25f * sqrtf((float)(sz * sz));

View File

@@ -97,7 +97,7 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No
}
memset(tbuf1->getBuffer(), 0, tbuf1->getWidth() * tbuf1->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
memset(tbuf1->getBuffer(), 0, tbuf1->getWidth() * tbuf1->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float));
for (n = 1; n < settings->iter && (!breaked); n++) {
for (y = 0; y < gbuf->getHeight() && (!breaked); y++) {
v = ((float)y + 0.5f) / (float)gbuf->getHeight();
@@ -117,9 +117,9 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No
}
if (isBreaked()) breaked = true;
}
memcpy(gbuf->getBuffer(), tbuf1->getBuffer(), tbuf1->getWidth() * tbuf1->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
memcpy(gbuf->getBuffer(), tbuf1->getBuffer(), tbuf1->getWidth() * tbuf1->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float));
}
memcpy(data, gbuf->getBuffer(), gbuf->getWidth() * gbuf->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float));
memcpy(data, gbuf->getBuffer(), gbuf->getWidth() * gbuf->getHeight() * COM_NUM_CHANNELS_COLOR * sizeof(float));
delete gbuf;
delete tbuf1;

View File

@@ -36,7 +36,7 @@ void GlareStreaksOperation::generateGlare(float *data, MemoryBuffer *inputTile,
bool breaked = false;
MemoryBuffer *tsrc = inputTile->duplicate();
MemoryBuffer *tdst = new MemoryBuffer(NULL, inputTile->getRect());
MemoryBuffer *tdst = new MemoryBuffer(COM_DT_COLOR, inputTile->getRect());
tdst->clear();
memset(data, 0, size4 * sizeof(float));

View File

@@ -83,8 +83,8 @@ float *InpaintSimpleOperation::get_pixel(int x, int y)
ASSERT_XY_RANGE(x, y);
return &this->m_cached_buffer[
y * width * COM_NUMBER_OF_CHANNELS +
x * COM_NUMBER_OF_CHANNELS];
y * width * COM_NUM_CHANNELS_COLOR +
x * COM_NUM_CHANNELS_COLOR];
}
int InpaintSimpleOperation::mdist(int x, int y)

View File

@@ -63,7 +63,7 @@ void KeyingBlurOperation::executePixel(float output[4], int x, int y, void *data
int cx = x + i;
if (cx >= 0 && cx < bufferWidth) {
int bufferIndex = (y * bufferWidth + cx) * 4;
int bufferIndex = (y * bufferWidth + cx);
average += buffer[bufferIndex];
count++;
@@ -75,7 +75,7 @@ void KeyingBlurOperation::executePixel(float output[4], int x, int y, void *data
int cy = y + i;
if (cy >= 0 && cy < bufferHeight) {
int bufferIndex = (cy * bufferWidth + x) * 4;
int bufferIndex = (cy * bufferWidth + x);
average += buffer[bufferIndex];
count++;

View File

@@ -62,7 +62,7 @@ void KeyingClipOperation::executePixel(float output[4], int x, int y, void *data
int bufferWidth = inputBuffer->getWidth();
int bufferHeight = inputBuffer->getHeight();
float value = buffer[(y * bufferWidth + x) * 4];
float value = buffer[(y * bufferWidth + x)];
bool ok = false;
int start_x = max_ff(0, x - delta + 1),
@@ -83,7 +83,7 @@ void KeyingClipOperation::executePixel(float output[4], int x, int y, void *data
continue;
}
int bufferIndex = (cy * bufferWidth + cx) * 4;
int bufferIndex = (cy * bufferWidth + cx);
float currentValue = buffer[bufferIndex];
if (fabsf(currentValue - value) < tolerance) {

View File

@@ -53,7 +53,7 @@ void MapUVOperation::executePixelSampled(float output[4], float x, float y, Pixe
}
/* EWA filtering */
this->m_inputColorProgram->readFiltered(output, uv[0], uv[1], deriv[0], deriv[1], COM_PS_BILINEAR);
this->m_inputColorProgram->readFiltered(output, uv[0], uv[1], deriv[0], deriv[1], COM_PS_BICUBIC);
/* UV to alpha threshold */
const float threshold = this->m_alpha * 0.05f;
@@ -83,11 +83,11 @@ bool MapUVOperation::read_uv(float x, float y, float &r_u, float &r_v, float &r_
return false;
}
else {
float col[4];
m_inputUVProgram->readSampled(col, x, y, COM_PS_BILINEAR);
r_u = col[0] * m_inputColorProgram->getWidth();
r_v = col[1] * m_inputColorProgram->getHeight();
r_alpha = col[2];
float vector[3];
m_inputUVProgram->readSampled(vector, x, y, COM_PS_BILINEAR);
r_u = vector[0] * m_inputColorProgram->getWidth();
r_v = vector[1] * m_inputColorProgram->getHeight();
r_alpha = vector[2];
return true;
}
}

View File

@@ -104,7 +104,7 @@ void *NormalizeOperation::initializeTileData(rcti *rect)
if ((value < minv) && (value >= -BLENDER_ZMAX)) {
minv = value;
}
bc += 4;
bc += COM_NUM_CHANNELS_VALUE;
}
minmult->x = minv;

View File

@@ -118,9 +118,9 @@ void OutputSingleLayerOperation::initExecution()
this->m_outputBuffer = init_buffer(this->getWidth(), this->getHeight(), this->m_datatype);
}
void OutputSingleLayerOperation::executeRegion(rcti *rect, unsigned int tileNumber)
void OutputSingleLayerOperation::executeRegion(Tile * tile)
{
write_buffer_rect(rect, this->m_tree, this->m_imageInput, this->m_outputBuffer, this->getWidth(), this->m_datatype);
write_buffer_rect(tile->get_rect(), this->m_tree, this->m_imageInput, this->m_outputBuffer, this->getWidth(), this->m_datatype);
}
void OutputSingleLayerOperation::deinitExecution()
@@ -193,8 +193,9 @@ void OutputOpenExrMultiLayerOperation::initExecution()
}
}
void OutputOpenExrMultiLayerOperation::executeRegion(rcti *rect, unsigned int tileNumber)
void OutputOpenExrMultiLayerOperation::executeRegion(Tile* tile)
{
rcti *rect = tile->get_rect();
for (unsigned int i = 0; i < this->m_layers.size(); ++i) {
OutputOpenExrLayer &layer = this->m_layers[i];
if (layer.imageInput)

View File

@@ -51,7 +51,7 @@ public:
OutputSingleLayerOperation(const RenderData *rd, const bNodeTree *tree, DataType datatype, ImageFormatData *format, const char *path,
const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings);
void executeRegion(rcti *rect, unsigned int tileNumber);
void executeRegion(Tile *tile);
bool isOutputOperation(bool rendering) const { return true; }
void initExecution();
void deinitExecution();
@@ -90,7 +90,7 @@ public:
void add_layer(const char *name, DataType datatype, bool use_layer);
void executeRegion(rcti *rect, unsigned int tileNumber);
void executeRegion(Tile* tile);
bool isOutputOperation(bool rendering) const { return true; }
void initExecution();
void deinitExecution();

View File

@@ -106,7 +106,7 @@ void PlaneDistortWarpImageOperation::executePixelSampled(float output[4], float
pixelTransform(xy, uv, deriv);
m_pixelReader->readFiltered(output, uv[0], uv[1], deriv[0], deriv[1], COM_PS_BILINEAR);
m_pixelReader->readFiltered(output, uv[0], uv[1], deriv[0], deriv[1], COM_PS_BICUBIC);
}
void PlaneDistortWarpImageOperation::pixelTransform(const float xy[2], float r_uv[2], float r_deriv[2][2])

View File

@@ -85,8 +85,9 @@ void PreviewOperation::deinitExecution()
this->m_input = NULL;
}
void PreviewOperation::executeRegion(rcti *rect, unsigned int tileNumber)
void PreviewOperation::executeRegion(Tile* tile)
{
rcti *rect = tile->get_rect();
int offset;
float color[4];
struct ColormanageProcessor *cm_processor;

View File

@@ -50,7 +50,7 @@ public:
void deinitExecution();
const CompositorPriority getRenderPriority() const;
void executeRegion(rcti *rect, unsigned int tileNumber);
void executeRegion(Tile* tile);
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
bool isPreviewOperation() const { return true; }

View File

@@ -26,7 +26,7 @@ QualityStepHelper::QualityStepHelper()
{
this->m_quality = COM_QUALITY_HIGH;
this->m_step = 1;
this->m_offsetadd = 4;
this->m_offsetadd = 4;
}
void QualityStepHelper::initExecution(QualityHelper helper)
@@ -37,16 +37,16 @@ void QualityStepHelper::initExecution(QualityHelper helper)
case COM_QUALITY_HIGH:
default:
this->m_step = 1;
this->m_offsetadd = 4;
break;
this->m_offsetadd = 1;
break;
case COM_QUALITY_MEDIUM:
this->m_step = 2;
this->m_offsetadd = 8;
break;
this->m_offsetadd = 2;
break;
case COM_QUALITY_LOW:
this->m_step = 3;
this->m_offsetadd = 12;
break;
this->m_offsetadd = 3;
break;
}
break;
case COM_QH_MULTIPLY:
@@ -54,16 +54,16 @@ void QualityStepHelper::initExecution(QualityHelper helper)
case COM_QUALITY_HIGH:
default:
this->m_step = 1;
this->m_offsetadd = 4;
break;
this->m_offsetadd = 4;
break;
case COM_QUALITY_MEDIUM:
this->m_step = 2;
this->m_offsetadd = 8;
break;
this->m_offsetadd = 8;
break;
case COM_QUALITY_LOW:
this->m_step = 4;
this->m_offsetadd = 16;
break;
this->m_offsetadd = 16;
break;
}
break;
}

View File

@@ -24,9 +24,9 @@
#include "COM_WriteBufferOperation.h"
#include "COM_defines.h"
ReadBufferOperation::ReadBufferOperation() : NodeOperation()
ReadBufferOperation::ReadBufferOperation(DataType type) : NodeOperation()
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(type);
this->m_single_value = false;
this->m_offset = 0;
this->m_buffer = NULL;
@@ -58,11 +58,19 @@ void ReadBufferOperation::executePixelSampled(float output[4], float x, float y,
/* write buffer has a single value stored at (0,0) */
m_buffer->read(output, 0, 0);
}
else if (sampler == COM_PS_NEAREST) {
m_buffer->read(output, x, y);
}
else {
m_buffer->readBilinear(output, x, y);
switch (sampler) {
case COM_PS_NEAREST:
m_buffer->read(output, x, y);
break;
case COM_PS_BICUBIC:
m_buffer->readBicubic(output, x, y);
break;
case COM_PS_BILINEAR:
default:
m_buffer->readBilinear(output, x, y);
break;
}
}
}

View File

@@ -25,6 +25,7 @@
#include "COM_NodeOperation.h"
#include "COM_MemoryProxy.h"
#include "COM_MemoryBuffer.h"
class ReadBufferOperation : public NodeOperation {
private:
@@ -33,7 +34,7 @@ private:
unsigned int m_offset;
MemoryBuffer *m_buffer;
public:
ReadBufferOperation();
ReadBufferOperation(DataType type);
void setMemoryProxy(MemoryProxy *memoryProxy) { this->m_memoryProxy = memoryProxy; }
MemoryProxy *getMemoryProxy() { return this->m_memoryProxy; }
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
@@ -50,6 +51,7 @@ public:
MemoryBuffer *getInputMemoryBuffer(MemoryBuffer **memoryBuffers) { return memoryBuffers[this->m_offset]; }
void readResolutionFromWriteBuffer();
void updateMemoryBuffer();
};
#endif

View File

@@ -89,7 +89,6 @@ void RenderLayersBaseProg::doInterpolation(float output[4], float x, float y, Pi
else
zero_v4(output);
break;
}
offset = (iy * width + ix) * this->m_elementsize;
@@ -111,15 +110,6 @@ void RenderLayersBaseProg::doInterpolation(float output[4], float x, float y, Pi
BLI_bicubic_interpolation_fl(this->m_inputBuffer, output, width, height, this->m_elementsize, x, y);
break;
}
if (this->m_elementsize == 1) {
output[1] = 0.0f;
output[2] = 0.0f;
output[3] = 0.0f;
}
else if (this->m_elementsize == 3) {
output[3] = 1.0f;
}
}
void RenderLayersBaseProg::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
@@ -145,7 +135,15 @@ void RenderLayersBaseProg::executePixelSampled(float output[4], float x, float y
#endif
if (this->m_inputBuffer == NULL) {
zero_v4(output);
int elemsize = this->m_elementsize;
if (elemsize == 1) {
output[0] = 0.0f;
}
else if (elemsize == 3) {
zero_v3(output);
} else {
zero_v4(output);
}
}
else {
doInterpolation(output, x, y, sampler);
@@ -204,15 +202,12 @@ void RenderLayersAlphaProg::executePixelSampled(float output[4], float x, float
float *inputBuffer = this->getInputBuffer();
if (inputBuffer == NULL) {
zero_v4(output);
output[0] = 0.0f;
}
else {
float temp[4];
doInterpolation(temp, x, y, sampler);
output[0] = temp[3];
output[1] = 0.0f;
output[2] = 0.0f;
output[3] = 0.0f;
}
}
@@ -227,7 +222,7 @@ RenderLayersColorOperation::RenderLayersColorOperation() : RenderLayersBaseProg(
RenderLayersCyclesOperation::RenderLayersCyclesOperation(int pass) : RenderLayersBaseProg(pass, 3)
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Depth Operation ******** */
@@ -245,16 +240,10 @@ void RenderLayersDepthProg::executePixelSampled(float output[4], float x, float
if (inputBuffer == NULL || ix < 0 || iy < 0 || ix >= (int)this->getWidth() || iy >= (int)this->getHeight() ) {
output[0] = 0.0f;
output[1] = 0.0f;
output[2] = 0.0f;
output[3] = 0.0f;
}
else {
unsigned int offset = (iy * this->getWidth() + ix);
output[0] = inputBuffer[offset];
output[1] = 0.0f;
output[2] = 0.0f;
output[3] = 0.0f;
}
}
@@ -262,21 +251,21 @@ void RenderLayersDepthProg::executePixelSampled(float output[4], float x, float
RenderLayersDiffuseOperation::RenderLayersDiffuseOperation() : RenderLayersBaseProg(SCE_PASS_DIFFUSE, 3)
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Emit Operation ******** */
RenderLayersEmitOperation::RenderLayersEmitOperation() : RenderLayersBaseProg(SCE_PASS_EMIT, 3)
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Environment Operation ******** */
RenderLayersEnvironmentOperation::RenderLayersEnvironmentOperation() : RenderLayersBaseProg(SCE_PASS_ENVIRONMENT, 3)
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Image Operation ******** */
@@ -290,7 +279,7 @@ RenderLayersColorProg::RenderLayersColorProg() : RenderLayersBaseProg(SCE_PASS_C
RenderLayersIndirectOperation::RenderLayersIndirectOperation() : RenderLayersBaseProg(SCE_PASS_INDIRECT, 3)
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Material Index Operation ******** */
@@ -325,28 +314,28 @@ RenderLayersObjectIndexOperation::RenderLayersObjectIndexOperation() : RenderLay
RenderLayersReflectionOperation::RenderLayersReflectionOperation() : RenderLayersBaseProg(SCE_PASS_REFLECT, 3)
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Refraction Operation ******** */
RenderLayersRefractionOperation::RenderLayersRefractionOperation() : RenderLayersBaseProg(SCE_PASS_REFRACT, 3)
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Shadow Operation ******** */
RenderLayersShadowOperation::RenderLayersShadowOperation() : RenderLayersBaseProg(SCE_PASS_SHADOW, 3)
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Specular Operation ******** */
RenderLayersSpecularOperation::RenderLayersSpecularOperation() : RenderLayersBaseProg(SCE_PASS_SPEC, 3)
{
this->addOutputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_VECTOR);
}
/* ******** Render Layers Speed Operation ******** */

View File

@@ -147,7 +147,7 @@ void ScreenLensDistortionOperation::accumulate(MemoryBuffer *buffer,
float xy[2];
distort_uv(uv, t, xy);
buffer->readBilinear(color, xy[0], xy[1]);
buffer->readBicubic(color, xy[0], xy[1]);
sum[a] += (1.0f - tz) * color[a], sum[b] += tz * color[b];
++count[a];

View File

@@ -33,7 +33,7 @@ void SetVectorOperation::executePixelSampled(float output[4], float x, float y,
output[0] = this->m_x;
output[1] = this->m_y;
output[2] = this->m_z;
output[3] = this->m_w;
// output[3] = this->m_w; not supported anymore?
}
void SetVectorOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])

View File

@@ -119,7 +119,7 @@ struct BufferLineAccumulator {
falloff_factor = dist_max > dist_min ? dr / (float)(dist_max - dist_min) : 0.0f;
float *iter = input->getBuffer() + COM_NUMBER_OF_CHANNELS * (x + input->getWidth() * y);
float *iter = input->getBuffer() + COM_NUM_CHANNELS_COLOR * (x + input->getWidth() * y);
return iter;
}
@@ -140,7 +140,7 @@ struct BufferLineAccumulator {
float falloff_factor;
if ((int)pt_ofs[0] == 0 && (int)pt_ofs[1] == 0) {
copy_v4_v4(output, input->getBuffer() + COM_NUMBER_OF_CHANNELS * ((int)source[0] + input->getWidth() * (int)source[1]));
copy_v4_v4(output, input->getBuffer() + COM_NUM_CHANNELS_COLOR * ((int)source[0] + input->getWidth() * (int)source[1]));
return;
}
@@ -173,7 +173,7 @@ struct BufferLineAccumulator {
/* decrement u */
x -= fxx;
y -= fyx;
buffer -= (fxx + fyx * buffer_width) * COM_NUMBER_OF_CHANNELS;
buffer -= (fxx + fyx * buffer_width) * COM_NUM_CHANNELS_COLOR;
/* decrement v (in steps of dv < 1) */
v_local -= dv;
@@ -182,7 +182,7 @@ struct BufferLineAccumulator {
x -= fxy;
y -= fyy;
buffer -= (fxy + fyy * buffer_width) * COM_NUMBER_OF_CHANNELS;
buffer -= (fxy + fyy * buffer_width) * COM_NUM_CHANNELS_COLOR;
}
}

View File

@@ -77,11 +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 +122,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);
}
}

View File

@@ -33,9 +33,6 @@ VariableSizeBokehBlurOperation::VariableSizeBokehBlurOperation() : NodeOperation
this->addInputSocket(COM_DT_COLOR);
this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE); // do not resize the bokeh image.
this->addInputSocket(COM_DT_VALUE); // radius
#ifdef COM_DEFOCUS_SEARCH
this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE); // inverse search radius optimization structure.
#endif
this->addOutputSocket(COM_DT_COLOR);
this->setComplex(true);
this->setOpenCL(true);
@@ -46,9 +43,6 @@ VariableSizeBokehBlurOperation::VariableSizeBokehBlurOperation() : NodeOperation
this->m_maxBlur = 32.0f;
this->m_threshold = 1.0f;
this->m_do_size_scale = false;
#ifdef COM_DEFOCUS_SEARCH
this->m_inputSearchProgram = NULL;
#endif
}
@@ -57,9 +51,6 @@ void VariableSizeBokehBlurOperation::initExecution()
this->m_inputProgram = getInputSocketReader(0);
this->m_inputBokehProgram = getInputSocketReader(1);
this->m_inputSizeProgram = getInputSocketReader(2);
#ifdef COM_DEFOCUS_SEARCH
this->m_inputSearchProgram = getInputSocketReader(3);
#endif
QualityStepHelper::initExecution(COM_QH_INCREASE);
}
struct VariableSizeBokehBlurTileData
@@ -73,9 +64,9 @@ struct VariableSizeBokehBlurTileData
void *VariableSizeBokehBlurOperation::initializeTileData(rcti *rect)
{
VariableSizeBokehBlurTileData *data = new VariableSizeBokehBlurTileData();
data->color = (MemoryBuffer *)this->m_inputProgram->initializeTileData(rect);
data->bokeh = (MemoryBuffer *)this->m_inputBokehProgram->initializeTileData(rect);
data->size = (MemoryBuffer *)this->m_inputSizeProgram->initializeTileData(rect);
data->color = (MemoryBuffer*)this->m_inputProgram->initializeTileData(rect);
data->bokeh = (MemoryBuffer*)this->m_inputBokehProgram->initializeTileData(rect);
data->size = (MemoryBuffer*)this->m_inputSizeProgram->initializeTileData(rect);
rcti rect2;
@@ -116,50 +107,45 @@ void VariableSizeBokehBlurOperation::executePixel(float output[4], int x, int y,
BLI_assert(inputBokehBuffer->getWidth() == COM_BLUR_BOKEH_PIXELS);
BLI_assert(inputBokehBuffer->getHeight() == COM_BLUR_BOKEH_PIXELS);
#ifdef COM_DEFOCUS_SEARCH
float search[4];
this->m_inputSearchProgram->read(search, x / InverseSearchRadiusOperation::DIVIDER, y / InverseSearchRadiusOperation::DIVIDER, NULL);
int minx = search[0];
int miny = search[1];
int maxx = search[2];
int maxy = search[3];
#else
int minx = max(x - maxBlurScalar, 0);
int miny = max(y - maxBlurScalar, 0);
int maxx = min(x + maxBlurScalar, (int)m_width);
int maxy = min(y + maxBlurScalar, (int)m_height);
#endif
{
inputSizeBuffer->readNoCheck(tempSize, x, y);
inputSizeBuffer->read(tempSize, x, y);
inputProgramBuffer->readNoCheck(readColor, x, y);
copy_v4_v4(color_accum, readColor);
copy_v4_fl(multiplier_accum, 1.0f);
float size_center = tempSize[0] * scalar;
const int addXStep = QualityStepHelper::getStep() * COM_NUMBER_OF_CHANNELS;
const int addXStepValue = QualityStepHelper::getStep();
const int addYStepValue = addXStepValue;
const int addXStepColor = addXStepValue * COM_NUM_CHANNELS_COLOR;
if (size_center > this->m_threshold) {
for (int ny = miny; ny < maxy; ny += QualityStepHelper::getStep()) {
for (int ny = miny; ny < maxy; ny += addYStepValue) {
float dy = ny - y;
int offsetNy = ny * inputSizeBuffer->getWidth() * COM_NUMBER_OF_CHANNELS;
int offsetNxNy = offsetNy + (minx * COM_NUMBER_OF_CHANNELS);
for (int nx = minx; nx < maxx; nx += QualityStepHelper::getStep()) {
int offsetValueNy = ny * inputSizeBuffer->getWidth();
int offsetValueNxNy = offsetValueNy + (minx);
int offsetColorNxNy = offsetValueNxNy * COM_NUM_CHANNELS_COLOR;
for (int nx = minx; nx < maxx; nx += addXStepValue) {
if (nx != x || ny != y) {
float size = min(inputSizeFloatBuffer[offsetNxNy] * scalar, size_center);
float size = min(inputSizeFloatBuffer[offsetValueNxNy] * scalar, size_center);
if (size > this->m_threshold) {
float dx = nx - x;
if (size > fabsf(dx) && size > fabsf(dy)) {
float uv[2] = {
(float)(COM_BLUR_BOKEH_PIXELS / 2) + (dx / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1),
(float)(COM_BLUR_BOKEH_PIXELS / 2) + (dy / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1)};
inputBokehBuffer->readNoCheck(bokeh, uv[0], uv[1]);
madd_v4_v4v4(color_accum, bokeh, &inputProgramFloatBuffer[offsetNxNy]);
(float)(COM_BLUR_BOKEH_PIXELS / 2) + (dx / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1),
(float)(COM_BLUR_BOKEH_PIXELS / 2) + (dy / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1)};
inputBokehBuffer->read(bokeh, uv[0], uv[1]);
madd_v4_v4v4(color_accum, bokeh, &inputProgramFloatBuffer[offsetColorNxNy]);
add_v4_v4(multiplier_accum, bokeh);
}
}
}
offsetNxNy += addXStep;
offsetColorNxNy += addXStepColor;
offsetValueNxNy += addXStepValue;
}
}
}
@@ -219,9 +205,6 @@ void VariableSizeBokehBlurOperation::deinitExecution()
this->m_inputProgram = NULL;
this->m_inputBokehProgram = NULL;
this->m_inputSizeProgram = NULL;
#ifdef COM_DEFOCUS_SEARCH
this->m_inputSearchProgram = NULL;
#endif
}
bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
@@ -251,17 +234,6 @@ bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *inpu
if (operation->determineDependingAreaOfInterest(&bokehInput, readOperation, output) ) {
return true;
}
#ifdef COM_DEFOCUS_SEARCH
rcti searchInput;
searchInput.xmax = (input->xmax / InverseSearchRadiusOperation::DIVIDER) + 1;
searchInput.xmin = (input->xmin / InverseSearchRadiusOperation::DIVIDER) - 1;
searchInput.ymax = (input->ymax / InverseSearchRadiusOperation::DIVIDER) + 1;
searchInput.ymin = (input->ymin / InverseSearchRadiusOperation::DIVIDER) - 1;
operation = getInputOperation(3);
if (operation->determineDependingAreaOfInterest(&searchInput, readOperation, output) ) {
return true;
}
#endif
operation = getInputOperation(0);
if (operation->determineDependingAreaOfInterest(&newInput, readOperation, output) ) {
return true;
@@ -269,108 +241,3 @@ bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *inpu
return false;
}
#ifdef COM_DEFOCUS_SEARCH
// InverseSearchRadiusOperation
InverseSearchRadiusOperation::InverseSearchRadiusOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_VALUE, COM_SC_NO_RESIZE); // radius
this->addOutputSocket(COM_DT_COLOR);
this->setComplex(true);
this->m_inputRadius = NULL;
}
void InverseSearchRadiusOperation::initExecution()
{
this->m_inputRadius = this->getInputSocketReader(0);
}
voi *InverseSearchRadiusOperation::initializeTileData(rcti *rect)
{
MemoryBuffer * data = new MemoryBuffer(NULL, rect);
float *buffer = data->getBuffer();
int x, y;
int width = this->m_inputRadius->getWidth();
int height = this->m_inputRadius->getHeight();
float temp[4];
int offset = 0;
for (y = rect->ymin; y < rect->ymax ; y++) {
for (x = rect->xmin; x < rect->xmax ; x++) {
int rx = x * DIVIDER;
int ry = y * DIVIDER;
buffer[offset] = MAX2(rx - m_maxBlur, 0);
buffer[offset + 1] = MAX2(ry - m_maxBlur, 0);
buffer[offset + 2] = MIN2(rx + DIVIDER + m_maxBlur, width);
buffer[offset + 3] = MIN2(ry + DIVIDER + m_maxBlur, height);
offset += 4;
}
}
// for (x = rect->xmin; x < rect->xmax ; x++) {
// for (y = rect->ymin; y < rect->ymax ; y++) {
// int rx = x * DIVIDER;
// int ry = y * DIVIDER;
// float radius = 0.0f;
// float maxx = x;
// float maxy = y;
// for (int x2 = 0 ; x2 < DIVIDER ; x2 ++) {
// for (int y2 = 0 ; y2 < DIVIDER ; y2 ++) {
// this->m_inputRadius->read(temp, rx+x2, ry+y2, COM_PS_NEAREST);
// if (radius < temp[0]) {
// radius = temp[0];
// maxx = x2;
// maxy = y2;
// }
// }
// }
// int impactRadius = ceil(radius / DIVIDER);
// for (int x2 = x - impactRadius ; x2 < x + impactRadius ; x2 ++) {
// for (int y2 = y - impactRadius ; y2 < y + impactRadius ; y2 ++) {
// data->read(temp, x2, y2);
// temp[0] = MIN2(temp[0], maxx);
// temp[1] = MIN2(temp[1], maxy);
// temp[2] = MAX2(temp[2], maxx);
// temp[3] = MAX2(temp[3], maxy);
// data->writePixel(x2, y2, temp);
// }
// }
// }
// }
return data;
}
void InverseSearchRadiusOperation::executePixelChunk(float output[4], int x, int y, void *data)
{
MemoryBuffer *buffer = (MemoryBuffer *)data;
buffer->readNoCheck(color, x, y);
}
void InverseSearchRadiusOperation::deinitializeTileData(rcti *rect, void *data)
{
if (data) {
MemoryBuffer *mb = (MemoryBuffer *)data;
delete mb;
}
}
void InverseSearchRadiusOperation::deinitExecution()
{
this->m_inputRadius = NULL;
}
void InverseSearchRadiusOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
{
NodeOperation::determineResolution(resolution, preferredResolution);
resolution[0] = resolution[0] / DIVIDER;
resolution[1] = resolution[1] / DIVIDER;
}
bool InverseSearchRadiusOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
{
rcti newRect;
newRect.ymin = input->ymin * DIVIDER - m_maxBlur;
newRect.ymax = input->ymax * DIVIDER + m_maxBlur;
newRect.xmin = input->xmin * DIVIDER - m_maxBlur;
newRect.xmax = input->xmax * DIVIDER + m_maxBlur;
return NodeOperation::determineDependingAreaOfInterest(&newRect, readOperation, output);
}
#endif

View File

@@ -25,7 +25,6 @@
#include "COM_NodeOperation.h"
#include "COM_QualityStepHelper.h"
//#define COM_DEFOCUS_SEARCH
class VariableSizeBokehBlurOperation : public NodeOperation, public QualityStepHelper {
private:
@@ -35,9 +34,6 @@ private:
SocketReader *m_inputProgram;
SocketReader *m_inputBokehProgram;
SocketReader *m_inputSizeProgram;
#ifdef COM_DEFOCUS_SEARCH
SocketReader *m_inputSearchProgram;
#endif
public:
VariableSizeBokehBlurOperation();
@@ -72,37 +68,4 @@ public:
void executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp);
};
#ifdef COM_DEFOCUS_SEARCH
class InverseSearchRadiusOperation : public NodeOperation {
private:
int m_maxBlur;
SocketReader *m_inputRadius;
public:
static const int DIVIDER = 4;
InverseSearchRadiusOperation();
/**
* the inner loop of this program
*/
void executePixelChunk(float output[4], int x, int y, void *data);
/**
* Initialize the execution
*/
void initExecution();
void *initializeTileData(rcti *rect);
void deinitializeTileData(rcti *rect, void *data);
/**
* Deinitialize the execution
*/
void deinitExecution();
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
void setMaxBlur(int maxRadius) { this->m_maxBlur = maxRadius; }
};
#endif
#endif

View File

@@ -57,7 +57,7 @@ void VectorBlurOperation::initExecution()
void VectorBlurOperation::executePixel(float output[4], int x, int y, void *data)
{
float *buffer = (float *) data;
int index = (y * this->getWidth() + x) * COM_NUMBER_OF_CHANNELS;
int index = (y * this->getWidth() + x) * COM_NUM_CHANNELS_COLOR;
copy_v4_v4(output, &buffer[index]);
}
@@ -108,14 +108,12 @@ bool VectorBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuff
void VectorBlurOperation::generateVectorBlur(float *data, MemoryBuffer *inputImage, MemoryBuffer *inputSpeed, MemoryBuffer *inputZ)
{
float *zbuf = inputZ->convertToValueBuffer();
NodeBlurData blurdata;
blurdata.samples = this->m_settings->samples / QualityStepHelper::getStep();
blurdata.maxspeed = this->m_settings->maxspeed;
blurdata.minspeed = this->m_settings->minspeed;
blurdata.curved = this->m_settings->curved;
blurdata.fac = this->m_settings->fac;
RE_zbuf_accumulate_vecblur(&blurdata, this->getWidth(), this->getHeight(), data, inputImage->getBuffer(), inputSpeed->getBuffer(), zbuf);
MEM_freeN((void *)zbuf);
RE_zbuf_accumulate_vecblur(&blurdata, this->getWidth(), this->getHeight(), data, inputImage->getBuffer(), inputSpeed->getBuffer(), inputZ->getBuffer());
return;
}

View File

@@ -51,7 +51,6 @@ void VectorCurveOperation::executePixelSampled(float output[4], float x, float y
this->m_inputProgram->readSampled(input, x, y, sampler);
curvemapping_evaluate_premulRGBF(this->m_curveMapping, output, input);
output[3] = input[3];
}
void VectorCurveOperation::deinitExecution()

View File

@@ -80,8 +80,9 @@ void ViewerOperation::deinitExecution()
this->m_outputBuffer = NULL;
}
void ViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber)
void ViewerOperation::executeRegion(Tile* tile)
{
rcti *rect = tile->get_rect();
float *buffer = this->m_outputBuffer;
float *depthbuffer = this->m_depthBuffer;
if (!buffer) return;

View File

@@ -52,7 +52,7 @@ public:
ViewerOperation();
void initExecution();
void deinitExecution();
void executeRegion(rcti *rect, unsigned int tileNumber);
void executeRegion(Tile* tile);
bool isOutputOperation(bool rendering) const { if (G.background) return false; return isActiveViewerOutput(); }
void setImage(Image *image) { this->m_image = image; }
void setImageUser(ImageUser *imageUser) { this->m_imageUser = imageUser; }

View File

@@ -23,7 +23,7 @@
#include "COM_WrapOperation.h"
WrapOperation::WrapOperation() : ReadBufferOperation()
WrapOperation::WrapOperation(DataType type) : ReadBufferOperation(type)
{
this->m_wrappingType = CMP_NODE_WRAP_NONE;
}

View File

@@ -29,7 +29,7 @@ class WrapOperation : public ReadBufferOperation {
private:
int m_wrappingType;
public:
WrapOperation();
WrapOperation(DataType type);
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);

View File

@@ -25,10 +25,10 @@
#include <stdio.h>
#include "COM_OpenCLDevice.h"
WriteBufferOperation::WriteBufferOperation() : NodeOperation()
WriteBufferOperation::WriteBufferOperation(DataType type) : NodeOperation()
{
this->addInputSocket(COM_DT_COLOR);
this->m_memoryProxy = new MemoryProxy();
this->addInputSocket(type);
this->m_memoryProxy = new MemoryProxy(type);
this->m_memoryProxy->setWriteBufferOperation(this);
this->m_memoryProxy->setExecutor(NULL);
}
@@ -57,10 +57,12 @@ void WriteBufferOperation::deinitExecution()
this->m_memoryProxy->free();
}
void WriteBufferOperation::executeRegion(rcti *rect, unsigned int tileNumber)
void WriteBufferOperation::executeRegion(Tile *tile)
{
rcti *rect = tile->get_rect();
MemoryBuffer *memoryBuffer = this->m_memoryProxy->getBuffer();
float *buffer = memoryBuffer->getBuffer();
const int num_channels = memoryBuffer->get_num_channels();
if (this->m_input->isComplex()) {
void *data = this->m_input->initializeTileData(rect);
int x1 = rect->xmin;
@@ -71,10 +73,10 @@ void WriteBufferOperation::executeRegion(rcti *rect, unsigned int tileNumber)
int y;
bool breaked = false;
for (y = y1; y < y2 && (!breaked); y++) {
int offset4 = (y * memoryBuffer->getWidth() + x1) * COM_NUMBER_OF_CHANNELS;
int offset4 = (y * memoryBuffer->getWidth() + x1) * num_channels;
for (x = x1; x < x2; x++) {
this->m_input->read(&(buffer[offset4]), x, y, data);
offset4 += COM_NUMBER_OF_CHANNELS;
offset4 += num_channels;
}
if (isBreaked()) {
breaked = true;
@@ -96,10 +98,10 @@ void WriteBufferOperation::executeRegion(rcti *rect, unsigned int tileNumber)
int y;
bool breaked = false;
for (y = y1; y < y2 && (!breaked); y++) {
int offset4 = (y * memoryBuffer->getWidth() + x1) * COM_NUMBER_OF_CHANNELS;
int offset4 = (y * memoryBuffer->getWidth() + x1) * num_channels;
for (x = x1; x < x2; x++) {
this->m_input->readSampled(&(buffer[offset4]), x, y, COM_PS_NEAREST);
offset4 += COM_NUMBER_OF_CHANNELS;
offset4 += num_channels;
}
if (isBreaked()) {
breaked = true;
@@ -126,12 +128,9 @@ void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice *device, rcti *rect,
const unsigned int outputBufferWidth = outputBuffer->getWidth();
const unsigned int outputBufferHeight = outputBuffer->getHeight();
const cl_image_format imageFormat = {
CL_RGBA,
CL_FLOAT
};
const cl_image_format *imageFormat = device->determineImageFormat(outputBuffer);
cl_mem clOutputBuffer = clCreateImage2D(device->getContext(), CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, &imageFormat, outputBufferWidth, outputBufferHeight, 0, outputFloatBuffer, &error);
cl_mem clOutputBuffer = clCreateImage2D(device->getContext(), CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, imageFormat, outputBufferWidth, outputBufferHeight, 0, outputFloatBuffer, &error);
if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
// STEP 2

View File

@@ -35,14 +35,14 @@ class WriteBufferOperation : public NodeOperation {
bool m_single_value; /* single value stored in buffer */
NodeOperation *m_input;
public:
WriteBufferOperation();
WriteBufferOperation(DataType type);
~WriteBufferOperation();
MemoryProxy *getMemoryProxy() { return this->m_memoryProxy; }
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
const bool isWriteBufferOperation() const { return true; }
bool isSingleValue() const { return m_single_value; }
void executeRegion(rcti *rect, unsigned int tileNumber);
void executeRegion(Tile * tile);
void initExecution();
void deinitExecution();
void executeOpenCLRegion(OpenCLDevice *device, rcti *rect, unsigned int chunkNumber, MemoryBuffer **memoryBuffers, MemoryBuffer *outputBuffer);