[Bf-blender-cvs] [48006f8b5f7] temp-viewport-compositor-merge: Viewport Compositor: Avoid using mat3 uniforms

Omar Emara noreply at git.blender.org
Fri May 20 13:49:12 CEST 2022


Commit: 48006f8b5f72b233986f83bbd20a4370c6afd89d
Author: Omar Emara
Date:   Fri May 20 13:00:43 2022 +0200
Branches: temp-viewport-compositor-merge
https://developer.blender.org/rB48006f8b5f72b233986f83bbd20a4370c6afd89d

Viewport Compositor: Avoid using mat3 uniforms

Mat3 uniforms suffer from alignment issues that are not easy to fix, so
just use mat4 uniforms for such matrices.

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

M	source/blender/gpu/GPU_shader.h
M	source/blender/gpu/intern/gpu_shader.cc
M	source/blender/gpu/shaders/compositor/compositor_realize_on_domain.glsl
M	source/blender/gpu/shaders/compositor/infos/compositor_filter_info.hh
M	source/blender/gpu/shaders/compositor/infos/compositor_realize_on_domain_info.hh
M	source/blender/nodes/composite/nodes/node_composite_filter.cc
M	source/blender/viewport_compositor/intern/realize_on_domain_processor_operation.cc

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

diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 461b0dbb8e4..c154f1adc8b 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -178,8 +178,8 @@ void GPU_shader_uniform_2fv(GPUShader *sh, const char *name, const float data[2]
 void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3]);
 void GPU_shader_uniform_4fv(GPUShader *sh, const char *name, const float data[4]);
 void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2]);
-void GPU_shader_uniform_mat3(GPUShader *sh, const char *name, const float data[3][3]);
 void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4]);
+void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3]);
 void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2]);
 void GPU_shader_uniform_4fv_array(GPUShader *sh, const char *name, int len, const float (*val)[4]);
 
diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc
index 5d5c9eac768..184e4f3e60c 100644
--- a/source/blender/gpu/intern/gpu_shader.cc
+++ b/source/blender/gpu/intern/gpu_shader.cc
@@ -7,6 +7,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_math_matrix.h"
 #include "BLI_string_utils.h"
 
 #include "GPU_capabilities.h"
@@ -711,16 +712,17 @@ void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2])
   GPU_shader_uniform_vector_int(sh, loc, 2, 1, data);
 }
 
-void GPU_shader_uniform_mat3(GPUShader *sh, const char *name, const float data[3][3])
+void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
 {
   const int loc = GPU_shader_get_uniform(sh, name);
-  GPU_shader_uniform_vector(sh, loc, 9, 1, (const float *)data);
+  GPU_shader_uniform_vector(sh, loc, 16, 1, (const float *)data);
 }
 
-void GPU_shader_uniform_mat4(GPUShader *sh, const char *name, const float data[4][4])
+void GPU_shader_uniform_mat3_as_mat4(GPUShader *sh, const char *name, const float data[3][3])
 {
-  const int loc = GPU_shader_get_uniform(sh, name);
-  GPU_shader_uniform_vector(sh, loc, 16, 1, (const float *)data);
+  float matrix[4][4];
+  copy_m4_m3(matrix, data);
+  GPU_shader_uniform_mat4(sh, name, matrix);
 }
 
 void GPU_shader_uniform_2fv_array(GPUShader *sh, const char *name, int len, const float (*val)[2])
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 9a74c7489c3..860571db025 100644
--- a/source/blender/gpu/shaders/compositor/compositor_realize_on_domain.glsl
+++ b/source/blender/gpu/shaders/compositor/compositor_realize_on_domain.glsl
@@ -7,7 +7,7 @@ void main()
   /* First, transform the input image by transforming the domain coordinates with the inverse of
    * input image's transformation. The inverse transformation is an affine matrix and thus the
    * coordinates should be in homogeneous coordinates.  */
-  vec2 coordinates = (inverse_transformation * vec3(xy, 1.0)).xy;
+  vec2 coordinates = (mat3(inverse_transformation) * vec3(xy, 1.0)).xy;
 
   /* Since an input image with an identity transformation is supposed to be centered in the domain,
    * we subtract the offset between the lower left corners of the input image and the domain, which
diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_filter_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_filter_info.hh
index 6d8cb5a842b..9c3e075c965 100644
--- a/source/blender/gpu/shaders/compositor/infos/compositor_filter_info.hh
+++ b/source/blender/gpu/shaders/compositor/infos/compositor_filter_info.hh
@@ -5,7 +5,7 @@
 
 GPU_SHADER_CREATE_INFO(compositor_filter)
     .local_group_size(16, 16)
-    .push_constant(Type::MAT3, "kernel")
+    .push_constant(Type::MAT4, "kernel")
     .sampler(0, ImageType::FLOAT_2D, "input_image")
     .sampler(1, ImageType::FLOAT_2D, "factor")
     .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
diff --git a/source/blender/gpu/shaders/compositor/infos/compositor_realize_on_domain_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_realize_on_domain_info.hh
index 92e74448fda..249a0cd974c 100644
--- a/source/blender/gpu/shaders/compositor/infos/compositor_realize_on_domain_info.hh
+++ b/source/blender/gpu/shaders/compositor/infos/compositor_realize_on_domain_info.hh
@@ -5,7 +5,7 @@
 
 GPU_SHADER_CREATE_INFO(compositor_realize_on_domain_shared)
     .local_group_size(16, 16)
-    .push_constant(Type::MAT3, "inverse_transformation")
+    .push_constant(Type::MAT4, "inverse_transformation")
     .sampler(0, ImageType::FLOAT_2D, "input_sampler")
     .compute_source("compositor_realize_on_domain.glsl");
 
diff --git a/source/blender/nodes/composite/nodes/node_composite_filter.cc b/source/blender/nodes/composite/nodes/node_composite_filter.cc
index 014684d2b63..695950102ef 100644
--- a/source/blender/nodes/composite/nodes/node_composite_filter.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_filter.cc
@@ -52,7 +52,7 @@ class FilterOperation : public NodeOperation {
 
     float kernel[3][3];
     get_filter_kernel(kernel);
-    GPU_shader_uniform_mat3(shader, "kernel", kernel);
+    GPU_shader_uniform_mat3_as_mat4(shader, "kernel", kernel);
 
     const Result &input_image = get_input("Image");
     input_image.bind_as_texture(shader, "input_image");
diff --git a/source/blender/viewport_compositor/intern/realize_on_domain_processor_operation.cc b/source/blender/viewport_compositor/intern/realize_on_domain_processor_operation.cc
index da4c29d1561..3d8182f8707 100644
--- a/source/blender/viewport_compositor/intern/realize_on_domain_processor_operation.cc
+++ b/source/blender/viewport_compositor/intern/realize_on_domain_processor_operation.cc
@@ -50,7 +50,7 @@ void RealizeOnDomainProcessorOperation::execute()
   const float3x3 inverse_transformation = transformation.inverted();
 
   /* Set the inverse of the transform to the shader. */
-  GPU_shader_uniform_mat3(shader, "inverse_transformation", inverse_transformation.ptr());
+  GPU_shader_uniform_mat3_as_mat4(shader, "inverse_transformation", inverse_transformation.ptr());
 
   /* The texture sampler should use bilinear interpolation for both the bilinear and bicubic
    * cases, as the logic used by the bicubic realization shader expects textures to use bilinear



More information about the Bf-blender-cvs mailing list