Cleanup: Replace is...Operation() methods with a flag.

This commit is contained in:
2021-03-29 16:54:02 +02:00
parent fe60062a99
commit 2db2b7de55
18 changed files with 46 additions and 90 deletions

View File

@@ -135,13 +135,13 @@ int DebugInfo::graphviz_operation(const ExecutionSystem *system,
else if (operation->isOutputOperation(system->getContext().isRendering())) {
fillcolor = "dodgerblue1";
}
else if (operation->isSetOperation()) {
else if (operation->get_flags().is_set_operation()) {
fillcolor = "khaki1";
}
else if (operation->isReadBufferOperation()) {
else if (operation->get_flags().is_read_buffer_operation) {
fillcolor = "darkolivegreen3";
}
else if (operation->isWriteBufferOperation()) {
else if (operation->get_flags().is_write_buffer_operation) {
fillcolor = "darkorange";
}
@@ -362,7 +362,7 @@ bool DebugInfo::graphviz_system(const ExecutionSystem *system, char *str, int ma
}
for (NodeOperation *operation : system->m_operations) {
if (operation->isReadBufferOperation()) {
if (operation->get_flags().is_read_buffer_operation) {
ReadBufferOperation *read = (ReadBufferOperation *)operation;
WriteBufferOperation *write = read->getMemoryProxy()->getWriteBufferOperation();
std::vector<std::string> &read_groups = op_groups[read];

View File

@@ -57,7 +57,6 @@ ExecutionGroup::ExecutionGroup()
this->m_x_chunks_len = 0;
this->m_y_chunks_len = 0;
this->m_chunks_len = 0;
this->m_initialized = false;
this->m_chunks_finished = 0;
BLI_rcti_init(&this->m_viewerBorder, 0, 0, 0, 0);
this->m_executionStartTime = 0;
@@ -70,17 +69,17 @@ CompositorPriority ExecutionGroup::getRenderPriority()
bool ExecutionGroup::can_contain(NodeOperation &operation)
{
if (!this->m_initialized) {
if (!m_flags.initialized) {
return true;
}
if (operation.isReadBufferOperation()) {
if (operation.get_flags().is_read_buffer_operation) {
return true;
}
if (operation.isWriteBufferOperation()) {
if (operation.get_flags().is_write_buffer_operation) {
return false;
}
if (operation.isSetOperation()) {
if (operation.get_flags().is_set_operation) {
return true;
}
@@ -103,11 +102,12 @@ bool ExecutionGroup::addOperation(NodeOperation *operation)
return false;
}
if (!operation->isReadBufferOperation() && !operation->isWriteBufferOperation()) {
if (!operation->get_flags().is_read_buffer_operation &&
!operation->get_flags().is_write_buffer_operation) {
m_flags.complex = operation->get_flags().complex;
m_flags.open_cl = operation->get_flags().open_cl;
m_flags.single_threaded = operation->isSingleThreaded();
m_initialized = true;
m_flags.initialized = true;
}
m_operations.append(operation);
@@ -134,7 +134,7 @@ void ExecutionGroup::initExecution()
unsigned int max_offset = 0;
for (NodeOperation *operation : m_operations) {
if (operation->isReadBufferOperation()) {
if (operation->get_flags().is_read_buffer_operation) {
ReadBufferOperation *readOperation = static_cast<ReadBufferOperation *>(operation);
this->m_read_operations.append(readOperation);
max_offset = MAX2(max_offset, readOperation->getOffset());
@@ -453,7 +453,7 @@ MemoryBuffer *ExecutionGroup::allocateOutputBuffer(rcti &rect)
{
// we assume that this method is only called from complex execution groups.
NodeOperation *operation = this->getOutputOperation();
if (operation->isWriteBufferOperation()) {
if (operation->get_flags().is_write_buffer_operation) {
WriteBufferOperation *writeOperation = (WriteBufferOperation *)operation;
MemoryBuffer *buffer = new MemoryBuffer(
writeOperation->getMemoryProxy(), rect, MemoryBufferState::Temporary);

View File

@@ -61,6 +61,7 @@ enum class eChunkExecutionState {
};
struct ExecutionGroupFlags {
bool initialized : 1;
/**
* Is this ExecutionGroup an output ExecutionGroup
* An OutputExecution group are groups containing a
@@ -82,6 +83,7 @@ struct ExecutionGroupFlags {
ExecutionGroupFlags()
{
initialized = false;
is_output = false;
complex = false;
open_cl = false;
@@ -168,18 +170,6 @@ class ExecutionGroup {
*/
blender::Vector<eChunkExecutionState> m_chunk_execution_states;
/**
* \brief indicator when this ExecutionGroup has valid Operations in its vector for Execution
* \note When building the ExecutionGroup Operations are added via recursion.
* First a WriteBufferOperations is added, then the.
* \note Operation containing the settings that is important for the ExecutiongGroup is added,
* \note When this occurs, these settings are copied over from the node to the ExecutionGroup
* \note and the Initialized flag is set to true.
* \see complex
* \see openCL
*/
bool m_initialized;
/**
* \brief denotes boundary for border compositing
* \note measured in pixel space

View File

@@ -130,7 +130,7 @@ static void update_read_buffer_offset(blender::Vector<NodeOperation *> &operatio
{
unsigned int order = 0;
for (NodeOperation *operation : operations) {
if (operation->isReadBufferOperation()) {
if (operation->get_flags().is_read_buffer_operation) {
ReadBufferOperation *readOperation = (ReadBufferOperation *)operation;
readOperation->setOffset(order);
order++;
@@ -142,7 +142,7 @@ static void init_write_operations_for_execution(blender::Vector<NodeOperation *>
const bNodeTree *bTree)
{
for (NodeOperation *operation : operations) {
if (operation->isWriteBufferOperation()) {
if (operation->get_flags().is_write_buffer_operation) {
operation->setbNodeTree(bTree);
operation->initExecution();
}
@@ -152,7 +152,7 @@ static void init_write_operations_for_execution(blender::Vector<NodeOperation *>
static void link_write_buffers(blender::Vector<NodeOperation *> &operations)
{
for (NodeOperation *operation : operations) {
if (operation->isReadBufferOperation()) {
if (operation->get_flags().is_read_buffer_operation) {
ReadBufferOperation *readOperation = static_cast<ReadBufferOperation *>(operation);
readOperation->updateMemoryBuffer();
}
@@ -163,7 +163,7 @@ static void init_non_write_operations_for_execution(blender::Vector<NodeOperatio
const bNodeTree *bTree)
{
for (NodeOperation *operation : operations) {
if (!operation->isWriteBufferOperation()) {
if (!operation->get_flags().is_write_buffer_operation) {
operation->setbNodeTree(bTree);
operation->initExecution();
}

View File

@@ -204,6 +204,13 @@ struct NodeOperationFlags {
*/
bool is_resolution_set : 1;
/**
* Is this a set operation (value, color, vector).
*/
bool is_set_operation : 1;
bool is_write_buffer_operation : 1;
bool is_read_buffer_operation : 1;
NodeOperationFlags()
{
complex = false;
@@ -211,6 +218,9 @@ struct NodeOperationFlags {
use_render_border = false;
use_viewer_border = false;
is_resolution_set = false;
is_set_operation = false;
is_read_buffer_operation = false;
is_write_buffer_operation = false;
}
};
@@ -301,11 +311,11 @@ class NodeOperation {
unsigned int preferredResolution[2]);
/**
* \brief isOutputOperation determines whether this operation is an output of the ExecutionSystem
* during rendering or editing.
* \brief isOutputOperation determines whether this operation is an output of the
* ExecutionSystem during rendering or editing.
*
* Default behavior if not overridden, this operation will not be evaluated as being an output of
* the ExecutionSystem.
* Default behavior if not overridden, this operation will not be evaluated as being an output
* of the ExecutionSystem.
*
* \see ExecutionSystem
* \ingroup check
@@ -400,31 +410,6 @@ class NodeOperation {
}
}
virtual bool isSetOperation() const
{
return false;
}
/**
* \brief is this operation of type ReadBufferOperation
* \return [true:false]
* \see ReadBufferOperation
*/
virtual bool isReadBufferOperation() const
{
return false;
}
/**
* \brief is this operation of type WriteBufferOperation
* \return [true:false]
* \see WriteBufferOperation
*/
virtual bool isWriteBufferOperation() const
{
return false;
}
/**
* \brief is this operation the active viewer output
* user can select an ViewerNode to be active
@@ -442,8 +427,8 @@ class NodeOperation {
rcti *output);
/**
* \brief set the index of the input socket that will determine the resolution of this operation
* \param index: the index to set
* \brief set the index of the input socket that will determine the resolution of this
* operation \param index: the index to set
*/
void setResolutionInputSocketIndex(unsigned int index);

View File

@@ -433,7 +433,7 @@ WriteBufferOperation *NodeOperationBuilder::find_attached_write_buffer_operation
for (const Link &link : m_links) {
if (link.from() == output) {
NodeOperation &op = link.to()->getOperation();
if (op.isWriteBufferOperation()) {
if (op.get_flags().is_write_buffer_operation) {
return (WriteBufferOperation *)(&op);
}
}
@@ -449,7 +449,7 @@ void NodeOperationBuilder::add_input_buffers(NodeOperation * /*operation*/,
}
NodeOperationOutput *output = input->getLink();
if (output->getOperation().isReadBufferOperation()) {
if (output->getOperation().get_flags().is_read_buffer_operation) {
/* input is already buffered, no need to add another */
return;
}
@@ -491,7 +491,7 @@ void NodeOperationBuilder::add_output_buffers(NodeOperation *operation,
WriteBufferOperation *writeOperation = nullptr;
for (NodeOperationInput *target : targets) {
/* try to find existing write buffer operation */
if (target->getOperation().isWriteBufferOperation()) {
if (target->getOperation().get_flags().is_write_buffer_operation) {
BLI_assert(writeOperation == nullptr); /* there should only be one write op connected */
writeOperation = (WriteBufferOperation *)(&target->getOperation());
}
@@ -571,7 +571,7 @@ static void find_reachable_operations_recursive(Tags &reachable, NodeOperation *
}
/* associated write-buffer operations are executed as well */
if (op->isReadBufferOperation()) {
if (op->get_flags().is_read_buffer_operation) {
ReadBufferOperation *read_op = (ReadBufferOperation *)op;
MemoryProxy *memproxy = read_op->getMemoryProxy();
find_reachable_operations_recursive(reachable, memproxy->getWriteBufferOperation());
@@ -675,7 +675,7 @@ void NodeOperationBuilder::group_operations()
}
/* add new groups for associated memory proxies where needed */
if (op->isReadBufferOperation()) {
if (op->get_flags().is_read_buffer_operation) {
ReadBufferOperation *read_op = (ReadBufferOperation *)op;
MemoryProxy *memproxy = read_op->getMemoryProxy();

View File

@@ -28,6 +28,7 @@ ReadBufferOperation::ReadBufferOperation(DataType datatype)
this->m_single_value = false;
this->m_offset = 0;
this->m_buffer = nullptr;
flags.is_read_buffer_operation = true;
}
void *ReadBufferOperation::initializeTileData(rcti * /*rect*/)

View File

@@ -53,10 +53,6 @@ class ReadBufferOperation : public NodeOperation {
MemoryBufferExtend extend_x,
MemoryBufferExtend extend_y);
void executePixelFiltered(float output[4], float x, float y, float dx[2], float dy[2]) override;
bool isReadBufferOperation() const override
{
return true;
}
void setOffset(unsigned int offset)
{
this->m_offset = offset;

View File

@@ -23,6 +23,7 @@ namespace blender::compositor {
SetColorOperation::SetColorOperation()
{
this->addOutputSocket(DataType::Color);
flags.is_set_operation = true;
}
void SetColorOperation::executePixelSampled(float output[4],

View File

@@ -80,10 +80,6 @@ class SetColorOperation : public NodeOperation {
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
bool isSetOperation() const override
{
return true;
}
};
} // namespace blender::compositor

View File

@@ -23,6 +23,7 @@ namespace blender::compositor {
SetValueOperation::SetValueOperation()
{
this->addOutputSocket(DataType::Value);
flags.is_set_operation = true;
}
void SetValueOperation::executePixelSampled(float output[4],

View File

@@ -52,10 +52,6 @@ class SetValueOperation : public NodeOperation {
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
bool isSetOperation() const override
{
return true;
}
};
} // namespace blender::compositor

View File

@@ -24,6 +24,7 @@ namespace blender::compositor {
SetVectorOperation::SetVectorOperation()
{
this->addOutputSocket(DataType::Vector);
flags.is_set_operation = true;
}
void SetVectorOperation::executePixelSampled(float output[4],

View File

@@ -79,10 +79,6 @@ class SetVectorOperation : public NodeOperation {
void determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2]) override;
bool isSetOperation() const override
{
return true;
}
void setVector(const float vector[3])
{

View File

@@ -41,6 +41,7 @@ TrackPositionOperation::TrackPositionOperation()
this->m_position = CMP_TRACKPOS_ABSOLUTE;
this->m_relativeFrame = 0;
this->m_speed_output = false;
flags.is_set_operation = true;
}
void TrackPositionOperation::initExecution()

View File

@@ -93,11 +93,6 @@ class TrackPositionOperation : public NodeOperation {
void initExecution() override;
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
bool isSetOperation() const override
{
return true;
}
};
} // namespace blender::compositor

View File

@@ -29,6 +29,7 @@ WriteBufferOperation::WriteBufferOperation(DataType datatype)
this->m_memoryProxy = new MemoryProxy(datatype);
this->m_memoryProxy->setWriteBufferOperation(this);
this->m_memoryProxy->setExecutor(nullptr);
flags.is_write_buffer_operation = true;
}
WriteBufferOperation::~WriteBufferOperation()
{

View File

@@ -43,10 +43,6 @@ class WriteBufferOperation : public NodeOperation {
return this->m_memoryProxy;
}
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override;
bool isWriteBufferOperation() const override
{
return true;
}
bool isSingleValue() const
{
return m_single_value;