[Bf-blender-cvs] [b705c4396d8] temp-viewport-compositor-compiler: Viewport Compositor: Delay memory barrier insertion
Omar Emara
noreply at git.blender.org
Wed Mar 30 13:53:29 CEST 2022
Commit: b705c4396d859d6ee3bfc814fb1161f50d2b2b0f
Author: Omar Emara
Date: Wed Mar 30 12:47:14 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBb705c4396d859d6ee3bfc814fb1161f50d2b2b0f
Viewport Compositor: Delay memory barrier insertion
Insert memory barriers just before reading from textures as opposed to
after writing to them.
===================================================================
M source/blender/nodes/NOD_compositor_execute.hh
M source/blender/nodes/composite/nodes/node_composite_composite.cc
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 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();
More information about the Bf-blender-cvs
mailing list