[Bf-blender-cvs] [bd8e67779ca] temp-viewport-compositor-compiler: Viewport Compositor: Allocate results on domains
Omar Emara
noreply at git.blender.org
Wed Mar 30 13:53:29 CEST 2022
Commit: bd8e67779ca776ec0552d11f67e5f28c655e4393
Author: Omar Emara
Date: Wed Mar 30 13:52:30 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBbd8e67779ca776ec0552d11f67e5f28c655e4393
Viewport Compositor: Allocate results on domains
Allocate results on domains directly to avoid having to propogate domain
transformation manually in all nodes.
===================================================================
M source/blender/nodes/NOD_compositor_execute.hh
M source/blender/nodes/composite/nodes/node_composite_image.cc
M source/blender/nodes/intern/node_compositor_execute.cc
===================================================================
diff --git a/source/blender/nodes/NOD_compositor_execute.hh b/source/blender/nodes/NOD_compositor_execute.hh
index 4148e60d3a4..8be94f59caa 100644
--- a/source/blender/nodes/NOD_compositor_execute.hh
+++ b/source/blender/nodes/NOD_compositor_execute.hh
@@ -194,6 +194,10 @@ class Domain {
Domain(int2 size, Transformation2D transformation);
+ /* Transform the domain by the given transformation. This effectively pre-multiply the given
+ * transformation by the current transformation of the domain. */
+ void transform(const Transformation2D &transformation);
+
/* Returns a domain of size 1x1 and an identity transformation. */
static Domain identity();
};
@@ -240,9 +244,9 @@ class Result {
* initialize the first three array elements. This member is uninitialized if the result is a
* texture. */
float value_[4];
- /* The transformation of the result. This only matters if the result was a texture. See the
- * Domain class. */
- Transformation2D transformation_ = Transformation2D::identity();
+ /* The domain of the result. This only matters if the result was a texture. See the Domain class
+ * for more information. */
+ Domain domain_ = Domain::identity();
/* If not nullptr, then this result wraps and uses the texture of another master result. In this
* case, calls to texture-related methods like increment_reference_count and release should
* operate on the master result as opposed to this result. This member is typically set upon
@@ -251,14 +255,18 @@ class Result {
Result *master_ = nullptr;
public:
+ /* Construct a result of the given type with the given texture pool that will be used to allocate
+ * and release the result's texture. */
Result(ResultType type, TexturePool &texture_pool);
- /* Declare the result to be a texture result and allocate a texture of an appropriate type with
- * the given size from the given texture pool. */
- void allocate_texture(int2 size);
+ /* Declare the result to be a texture result, allocate a texture of an appropriate type with
+ * the size of the given domain from the result's texture pool, and set the domain of the result
+ * to the given domain. */
+ void allocate_texture(Domain domain);
- /* Declare the result to be a single value result and allocate a texture of an appropriate
- * type with size 1x1 from the given texture pool. See class description for more information. */
+ /* Declare the result to be a single value result, allocate a texture of an appropriate
+ * type with size 1x1 from the result's texture pool, and set the domain to be an identity
+ * domain. See class description for more information. */
void allocate_single_value();
/* Bind the texture of the result to the texture image unit with the given name in the currently
@@ -283,13 +291,12 @@ class Result {
* incremented by the reference count of the target result. This is typically called in the
* allocate method of an operation whose input texture will not change and can be passed to the
* output directly. It should be noted that such operations can still adjust other properties of
- * the result, like its transformation. So for instance, the transform operation passes its input
- * through to its output because it will not change it, however, it may adjusts its
- * transformation. */
+ * the result, like its domain. So for instance, the transform operation passes its input through
+ * to its output because it will not change it, however, it may adjusts its domain. */
void pass_through(Result &target);
/* Transform the result by the given transformation. This effectively pre-multiply the given
- * transformation by the current transformation of the result. */
+ * transformation by the current transformation of the domain of the result. */
void transform(const Transformation2D &transformation);
/* If the result is a single value result of type float, return its float value. Otherwise, an
@@ -352,14 +359,8 @@ class Result {
* reference count of the master result is returned instead. */
int reference_count() const;
- /* Returns the size of the allocated texture. */
- int2 size() const;
-
- /* Returns the transformation of the result. */
- Transformation2D transformation() const;
-
/* Returns the domain of the result. See the Domain class. */
- Domain domain() const;
+ const Domain &domain() const;
};
/* --------------------------------------------------------------------
diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc
index 9e3674fec5e..f58f807bc0c 100644
--- a/source/blender/nodes/composite/nodes/node_composite_image.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_image.cc
@@ -487,7 +487,7 @@ class ImageOperation : public NodeOperation {
const int width = GPU_texture_width(image_texture);
const int height = GPU_texture_height(image_texture);
- result.allocate_texture(int2(width, height));
+ result.allocate_texture(Domain(int2(width, height)));
GPUShader *shader = GPU_shader_create_from_info_name(shader_name);
GPU_shader_bind(shader);
@@ -497,8 +497,7 @@ class ImageOperation : public NodeOperation {
result.bind_as_image(shader, "output_image");
- const int2 size = result.size();
- GPU_compute_dispatch(shader, size.x / 16 + 1, size.y / 16 + 1, 1);
+ GPU_compute_dispatch(shader, width / 16 + 1, height / 16 + 1, 1);
GPU_shader_unbind();
GPU_texture_unbind(image_texture);
@@ -696,7 +695,7 @@ class RenderLayerOperation : public NodeOperation {
const int height = GPU_texture_height(pass_texture);
Result &result = get_result("Image");
- result.allocate_texture(int2(width, height));
+ result.allocate_texture(Domain(int2(width, height)));
GPU_texture_copy(result.texture(), pass_texture);
}
};
diff --git a/source/blender/nodes/intern/node_compositor_execute.cc b/source/blender/nodes/intern/node_compositor_execute.cc
index cad58ced618..8e31b4c6264 100644
--- a/source/blender/nodes/intern/node_compositor_execute.cc
+++ b/source/blender/nodes/intern/node_compositor_execute.cc
@@ -130,6 +130,11 @@ Domain::Domain(int2 size, Transformation2D transformation)
{
}
+void Domain::transform(const Transformation2D &input_transformation)
+{
+ transformation = input_transformation * transformation;
+}
+
Domain Domain::identity()
{
return Domain(int2(1), Transformation2D::identity());
@@ -154,20 +159,21 @@ Result::Result(ResultType type, TexturePool &texture_pool)
{
}
-void Result::allocate_texture(int2 size)
+void Result::allocate_texture(Domain domain)
{
is_single_value_ = false;
switch (type_) {
case ResultType::Float:
- texture_ = texture_pool_->acquire_float(size);
- return;
+ texture_ = texture_pool_->acquire_float(domain.size);
+ break;
case ResultType::Vector:
- texture_ = texture_pool_->acquire_vector(size);
- return;
+ texture_ = texture_pool_->acquire_vector(domain.size);
+ break;
case ResultType::Color:
- texture_ = texture_pool_->acquire_color(size);
- return;
+ texture_ = texture_pool_->acquire_color(domain.size);
+ break;
}
+ domain_ = domain;
}
void Result::allocate_single_value()
@@ -178,14 +184,15 @@ void Result::allocate_single_value()
switch (type_) {
case ResultType::Float:
texture_ = texture_pool_->acquire_float(texture_size);
- return;
+ break;
case ResultType::Vector:
texture_ = texture_pool_->acquire_vector(texture_size);
- return;
+ break;
case ResultType::Color:
texture_ = texture_pool_->acquire_color(texture_size);
- return;
+ break;
}
+ domain_ = Domain::identity();
}
void Result::bind_as_texture(GPUShader *shader, const char *texture_name) const
@@ -224,7 +231,7 @@ void Result::pass_through(Result &target)
void Result::transform(const Transformation2D &transformation)
{
- transformation_ = transformation * transformation_;
+ domain_.transform(transformation);
}
float Result::get_float_value() const
@@ -340,19 +347,9 @@ int Result::reference_count() const
return reference_count_;
}
-int2 Result::size() const
+const Domain &Result::domain() const
{
- return int2{GPU_texture_width(texture_), GPU_texture_height(texture_)};
-}
-
-Transformation2D Result::transformation() const
-{
- return transformation_;
-}
-
-Domain Result::domain() const
-{
- return Domain(size(), transformation_);
+ return domain_;
}
/* --------------------------------------------------------------------
@@ -752,7 +749,7 @@ void ConversionProcessorOperation::execute()
return;
}
- result.allocate_texture(input.size());
+ result.allocate_texture(input.domain());
GPUShader *shader = get_conversion_shader();
GPU_shader_bind(shader);
@@ -760,7 +757,7 @@ void ConversionProcessorOperation::execute()
input.bind_as_texture(shader, shader_input_sampler_name);
result.bind_as_image(shader, shader_output_image_name);
- const int2 size = result.size();
+ const int2 size = result.domain().size;
GPU_compute_dispatch(shader, size.x / 16 + 1, size.y / 16 + 1, 1);
input.unbind_as_texture();
@@ -924,17 +921,17 @@ void RealizeOnDomainProcessorOperation::execute()
return;
}
- result.allocate_texture(domain_.size);
+ result.allocate_texture(domain_);
GPUShader *shader = get_realization_shader();
GPU_shader_bind(shader);
/* Transform the input space into the domain space. */
- const Transformation2D local_transformation = input.transformation() *
+ const Transformation2D local_transformation = input.domain().transformation *
domain_.transformation.inverted();
/* Set the pivot of the transformation to be the center of the domain. */
- const float2 pivot = float2(result.size()) / 2.0f;
+ const float2 pivot = float2(domain_.size) / 2.0f;
const Transformation2D pivoted_transformation = local_transformation.set_pivot(pivot);
/* Invert the transformation because the shader transforms the domain coordinates instead of the
@@ -950,7 +947,7 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list