Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Emara <mail@OmarEmara.dev>2022-03-30 13:47:14 +0300
committerOmar Emara <mail@OmarEmara.dev>2022-03-30 13:47:14 +0300
commitb705c4396d859d6ee3bfc814fb1161f50d2b2b0f (patch)
tree5391313076bec8c8e6f9491c06f8df837263962b
parentd2a2c45f6b3d7663f5ddc5764994c230596a3473 (diff)
Viewport Compositor: Delay memory barrier insertion
Insert memory barriers just before reading from textures as opposed to after writing to them.
-rw-r--r--source/blender/nodes/NOD_compositor_execute.hh3
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_composite.cc10
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_image.cc2
-rw-r--r--source/blender/nodes/intern/node_compositor_execute.cc9
4 files changed, 13 insertions, 11 deletions
diff --git a/source/blender/nodes/NOD_compositor_execute.hh b/source/blender/nodes/NOD_compositor_execute.hh
index 6171f859c33..4148e60d3a4 100644
--- a/source/blender/nodes/NOD_compositor_execute.hh
+++ b/source/blender/nodes/NOD_compositor_execute.hh
@@ -262,7 +262,8 @@ class Result {
void allocate_single_value();
/* Bind the texture of the result to the texture image unit with the given name in the currently
- * bound given shader. */
+ * bound given shader. This also inserts a memory barrier for texture fetches to ensure any prior
+ * writes to the texture are reflected before reading from it. */
void bind_as_texture(GPUShader *shader, const char *texture_name) const;
/* Bind the texture of the result to the image unit with the given name in the currently bound
diff --git a/source/blender/nodes/composite/nodes/node_composite_composite.cc b/source/blender/nodes/composite/nodes/node_composite_composite.cc
index 990f113b02b..5bbeee24978 100644
--- a/source/blender/nodes/composite/nodes/node_composite_composite.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_composite.cc
@@ -58,16 +58,22 @@ class CompositeOperation : public NodeOperation {
{
const Result &input_image = get_input("Image");
GPUTexture *viewport_texture = context().get_viewport_texture();
+
+ /* If the input image is a texture, copy the input texture to the viewport texture. */
if (get_input("Image").is_texture()) {
- /* If the input image is a texture, copy the input texture to the viewport texture. */
+ /* Make sure any prior writes to the texture are reflected before copying it. */
+ GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE);
+
GPU_texture_copy(viewport_texture, input_image.texture());
}
else {
- /* If the input image is a single color value, clear the viewport texture to that color. */
+ /* Otherwise, if the input image is a single color value, clear the viewport texture to that
+ * color. */
GPU_texture_clear(viewport_texture, GPU_DATA_FLOAT, input_image.get_color_value());
}
}
+ /* The operation domain have the same dimensions of the viewport without any transformations. */
Domain compute_domain() override
{
GPUTexture *viewport_texture = context().get_viewport_texture();
diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc
index e0f4c330c52..9e3674fec5e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_image.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_image.cc
@@ -500,8 +500,6 @@ class ImageOperation : public NodeOperation {
const int2 size = result.size();
GPU_compute_dispatch(shader, size.x / 16 + 1, size.y / 16 + 1, 1);
- GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
-
GPU_shader_unbind();
GPU_texture_unbind(image_texture);
result.unbind_as_image();
diff --git a/source/blender/nodes/intern/node_compositor_execute.cc b/source/blender/nodes/intern/node_compositor_execute.cc
index 35def625f64..cad58ced618 100644
--- a/source/blender/nodes/intern/node_compositor_execute.cc
+++ b/source/blender/nodes/intern/node_compositor_execute.cc
@@ -190,6 +190,9 @@ void Result::allocate_single_value()
void Result::bind_as_texture(GPUShader *shader, const char *texture_name) const
{
+ /* Make sure any prior writes to the texture are reflected before reading from it. */
+ GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
+
const int texture_image_unit = GPU_shader_get_texture_binding(shader, texture_name);
GPU_texture_bind(texture_, texture_image_unit);
}
@@ -760,8 +763,6 @@ void ConversionProcessorOperation::execute()
const int2 size = result.size();
GPU_compute_dispatch(shader, size.x / 16 + 1, size.y / 16 + 1, 1);
- GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
-
input.unbind_as_texture();
result.unbind_as_image();
GPU_shader_unbind();
@@ -952,8 +953,6 @@ void RealizeOnDomainProcessorOperation::execute()
const int2 size = result.size();
GPU_compute_dispatch(shader, size.x / 16 + 1, size.y / 16 + 1, 1);
- GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
-
input.unbind_as_texture();
result.unbind_as_image();
GPU_shader_unbind();
@@ -1128,8 +1127,6 @@ void GPUMaterialOperation::execute()
GPU_compute_dispatch(shader, size.x / 16 + 1, size.y / 16 + 1, 1);
- GPU_memory_barrier(GPU_BARRIER_TEXTURE_FETCH);
-
GPU_texture_unbind_all();
GPU_texture_image_unbind_all();
GPU_uniformbuf_unbind_all();