[Bf-blender-cvs] [d507c551428] temp-viewport-compositor-compiler: Viewport Compositor: Use bounded texture load

Omar Emara noreply at git.blender.org
Thu Mar 31 11:09:43 CEST 2022


Commit: d507c55142832148fcd8486575874e592788b4df
Author: Omar Emara
Date:   Thu Mar 31 11:06:01 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBd507c55142832148fcd8486575874e592788b4df

Viewport Compositor: Use bounded texture load

===================================================================

M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/shaders/compositor/compositor_convert.glsl
M	source/blender/gpu/shaders/compositor/compositor_realize_on_domain.glsl
M	source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_load_input.glsl
A	source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_texture_utils.glsl

===================================================================

diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 60b8b2adc0f..427f7449cde 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -306,6 +306,7 @@ set(GLSL_SRC
   shaders/compositor/material/gpu_shader_compositor_separate_combine.glsl
   shaders/compositor/material/gpu_shader_compositor_set_alpha.glsl
   shaders/compositor/material/gpu_shader_compositor_store_output.glsl
+  shaders/compositor/material/gpu_shader_compositor_texture_utils.glsl
   shaders/compositor/material/gpu_shader_compositor_type_conversion.glsl
 
   shaders/compositor/compositor_convert.glsl
diff --git a/source/blender/gpu/shaders/compositor/compositor_convert.glsl b/source/blender/gpu/shaders/compositor/compositor_convert.glsl
index 02ae9b91745..e2156ffac86 100644
--- a/source/blender/gpu/shaders/compositor/compositor_convert.glsl
+++ b/source/blender/gpu/shaders/compositor/compositor_convert.glsl
@@ -1,8 +1,8 @@
-/* The shader create info instance should define a CONVERT_EXPRESSION as well as an output_image
- * given the sampled texel. */
+#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utils.glsl)
+
 void main()
 {
   ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
-  vec4 texel = texelFetch(input_sampler, xy, 0);
+  vec4 texel = load_texture(input_sampler, xy);
   imageStore(output_image, xy, CONVERT_EXPRESSION);
 }
diff --git a/source/blender/gpu/shaders/compositor/compositor_realize_on_domain.glsl b/source/blender/gpu/shaders/compositor/compositor_realize_on_domain.glsl
index 89edd87f5fa..38fb8b31a32 100644
--- a/source/blender/gpu/shaders/compositor/compositor_realize_on_domain.glsl
+++ b/source/blender/gpu/shaders/compositor/compositor_realize_on_domain.glsl
@@ -1,3 +1,5 @@
+#pragma BLENDER_REQUIRE(gpu_shader_compositor_texture_utils.glsl)
+
 void main()
 {
   ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
@@ -12,7 +14,7 @@ void main()
    * is half the difference between their sizes, because the difference in size is on both sides of
    * the centered image. */
   ivec2 domain_size = imageSize(domain);
-  ivec2 input_size = textureSize(input_sampler, 0);
+  ivec2 input_size = texture_size(input_sampler);
   vec2 offset = (domain_size - input_size) / 2.0;
 
   /* Subtract the offset and divide by the input image size to get the relevant coordinates into
diff --git a/source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_load_input.glsl b/source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_load_input.glsl
index 109279ed47d..e3fa93c492b 100644
--- a/source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_load_input.glsl
+++ b/source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_load_input.glsl
@@ -1,20 +1,17 @@
 void load_input_float(sampler2D input_sampler, out float value)
 {
   ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
-  ivec2 texture_bounds = textureSize(input_sampler, 0) - ivec2(1);
-  value = texelFetch(input_sampler, min(xy, texture_bounds), 0).x;
+  value = load_texture(input_sampler, xy).x;
 }
 
 void load_input_vector(sampler2D input_sampler, out vec3 vector)
 {
   ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
-  ivec2 texture_bounds = textureSize(input_sampler, 0) - ivec2(1);
-  vector = texelFetch(input_sampler, min(xy, texture_bounds), 0).xyz;
+  vector = load_texture(input_sampler, xy).xyz;
 }
 
 void load_input_color(sampler2D input_sampler, out vec4 color)
 {
   ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
-  ivec2 texture_bounds = textureSize(input_sampler, 0) - ivec2(1);
-  color = texelFetch(input_sampler, min(xy, texture_bounds), 0);
+  color = load_texture(input_sampler, xy);
 }
diff --git a/source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_texture_utils.glsl b/source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_texture_utils.glsl
new file mode 100644
index 00000000000..3c7ef53618d
--- /dev/null
+++ b/source/blender/gpu/shaders/compositor/material/gpu_shader_compositor_texture_utils.glsl
@@ -0,0 +1,12 @@
+/* A shorthand for textureSize with a zero LOD. */
+ivec2 texture_size(sampler2D sampler)
+{
+  return textureSize(sampler, 0);
+}
+
+/* A shorthand for texelFetch with zero LOD and bounded access clamped to border. */
+vec4 load_texture(sampler2D sampler, ivec2 xy)
+{
+  ivec2 texture_bounds = texture_size(sampler) - ivec2(1);
+  return texelFetch(sampler, min(xy, texture_bounds), 0);
+}



More information about the Bf-blender-cvs mailing list