It was caused by image threading safe commit and it was noticeable only on really multi-core CPU (like dual-socket Xeon stations), was not visible on core i7 machine. The reason of slowdown was spinlock around image buffer referencing, which lead to lots of cores waiting for single core and using image buffer after it was referenced was not so much longer than doing reference itself. The most clear solution here seemed to be introducing Image Pool which will contain list of loaded and referenced image buffers, so all threads could skip lock if the pool is used for reading only. Lock only needed in cases when buffer for requested image user is missing in the pool. This lock will happen only once per image so overall amount of locks is much less that it was before. To operate with pool: - BKE_image_pool_new() creates new pool - BKE_image_pool_free() destroys pool and dereferences all image buffers which were loaded to it - BKE_image_pool_acquire_ibuf() returns image buffer for given image and user. Pool could be NULL and in this case fallback to BKE_image_acquire_ibuf will happen. This helps to avoid lots to if(poll) checks in image sampling code. - BKE_image_pool_release_ibuf releases image buffer. In fact, it will only do something if pool is NULL, in all other case it'll equal to DoNothing operation.
84 lines
2.1 KiB
C++
84 lines
2.1 KiB
C++
/*
|
|
* 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_TextureOperation_h
|
|
#define _COM_TextureOperation_h
|
|
|
|
#include "COM_NodeOperation.h"
|
|
#include "DNA_texture_types.h"
|
|
#include "BLI_listbase.h"
|
|
extern "C" {
|
|
#include "RE_pipeline.h"
|
|
#include "RE_shader_ext.h"
|
|
#include "RE_render_ext.h"
|
|
#include "MEM_guardedalloc.h"
|
|
}
|
|
|
|
/**
|
|
* Base class for all renderlayeroperations
|
|
*
|
|
* @todo: rename to operation.
|
|
*/
|
|
class TextureBaseOperation : public NodeOperation {
|
|
private:
|
|
Tex *m_texture;
|
|
const RenderData *m_rd;
|
|
SocketReader *m_inputSize;
|
|
SocketReader *m_inputOffset;
|
|
struct ImagePool *m_pool;
|
|
|
|
protected:
|
|
|
|
/**
|
|
* Determine the output resolution. The resolution is retrieved from the Renderer
|
|
*/
|
|
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
TextureBaseOperation();
|
|
|
|
public:
|
|
void executePixel(float output[4], float x, float y, PixelSampler sampler);
|
|
|
|
void setTexture(Tex *texture) { this->m_texture = texture; }
|
|
void initExecution();
|
|
void deinitExecution();
|
|
void setRenderData(const RenderData *rd) { this->m_rd = rd; }
|
|
};
|
|
|
|
class TextureOperation : public TextureBaseOperation {
|
|
public:
|
|
TextureOperation();
|
|
|
|
};
|
|
class TextureAlphaOperation : public TextureBaseOperation {
|
|
public:
|
|
TextureAlphaOperation();
|
|
void executePixel(float output[4], float x, float y, PixelSampler sampler);
|
|
|
|
};
|
|
|
|
#endif
|