Commit: babd96b67768cc775ceca8868e02bae82ad8b419
Author: Omar Emara
Date:   Fri Feb 18 22:11:23 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBbabd96b67768cc775ceca8868e02bae82ad8b419

Viewport Compositor: Add type implicit conversion

This patch adds support for implicit conversion between types. This is
done by emitting a meta operation that performs the conversion
transparently before the node operation gets its input results.

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

M       source/blender/gpu/CMakeLists.txt
A       
source/blender/gpu/shaders/compositor/compositor_convert_color_to_float.glsl
A       
source/blender/gpu/shaders/compositor/compositor_convert_float_to_color.glsl
A       
source/blender/gpu/shaders/compositor/compositor_convert_vector_to_color.glsl
A       
source/blender/gpu/shaders/compositor/infos/compositor_convert_color_to_float_info.hh
A       
source/blender/gpu/shaders/compositor/infos/compositor_convert_float_to_color_info.hh
A       
source/blender/gpu/shaders/compositor/infos/compositor_convert_vector_to_color_info.hh
M       
source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
M       source/blender/nodes/NOD_compositor_execute.hh
M       source/blender/nodes/intern/node_compositor_execute.cc

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

diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index 669657c3b9e..48845ecbd77 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -308,6 +308,9 @@ set(GLSL_SRC
   shaders/compositor/material/gpu_shader_compositor_set_alpha.glsl
   shaders/compositor/material/gpu_shader_compositor_split_viewer.glsl
 
+  shaders/compositor/compositor_convert_color_to_float.glsl
+  shaders/compositor/compositor_convert_float_to_color.glsl
+  shaders/compositor/compositor_convert_vector_to_color.glsl
   shaders/compositor/sampler2D_to_RGBA16F_2D_image.glsl
 
   shaders/material/gpu_shader_material_add_shader.glsl
@@ -490,6 +493,9 @@ set(SHADER_CREATE_INFOS
   shaders/infos/gpu_shader_text_info.hh
   shaders/infos/gpu_srgb_to_framebuffer_space_info.hh
 
+  shaders/compositor/infos/compositor_convert_color_to_float_info.hh
+  shaders/compositor/infos/compositor_convert_float_to_color_info.hh
+  shaders/compositor/infos/compositor_convert_vector_to_color_info.hh
   shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
 )
 
diff --git 
a/source/blender/gpu/shaders/compositor/compositor_convert_color_to_float.glsl 
b/source/blender/gpu/shaders/compositor/compositor_convert_color_to_float.glsl
new file mode 100644
index 00000000000..27b0b9a231c
--- /dev/null
+++ 
b/source/blender/gpu/shaders/compositor/compositor_convert_color_to_float.glsl
@@ -0,0 +1,9 @@
+/* Store the average of the input's three color channels in the output, the 
alpha channel is
+ * ignored. */
+
+void main()
+{
+  ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
+  vec4 color = texelFetch(input_sampler, xy, 0);
+  imageStore(output_image, xy, vec4((color.r + color.g + color.b) / 3.0));
+}
diff --git 
a/source/blender/gpu/shaders/compositor/compositor_convert_float_to_color.glsl 
b/source/blender/gpu/shaders/compositor/compositor_convert_float_to_color.glsl
new file mode 100644
index 00000000000..2983a8abadd
--- /dev/null
+++ 
b/source/blender/gpu/shaders/compositor/compositor_convert_float_to_color.glsl
@@ -0,0 +1,7 @@
+/* Fill all three color channels of the output with the input and set the 
alpha channel to 1. */
+
+void main()
+{
+  ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
+  imageStore(output_image, xy, vec4(texelFetch(input_sampler, xy, 0).xxx, 
1.0));
+}
diff --git 
a/source/blender/gpu/shaders/compositor/compositor_convert_vector_to_color.glsl 
b/source/blender/gpu/shaders/compositor/compositor_convert_vector_to_color.glsl
new file mode 100644
index 00000000000..bcfad9f3e67
--- /dev/null
+++ 
b/source/blender/gpu/shaders/compositor/compositor_convert_vector_to_color.glsl
@@ -0,0 +1,8 @@
+/* Copy the three vector components of the input to the three color channels 
of the output and set
+ * the alpha channel to 1. */
+
+void main()
+{
+  ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
+  imageStore(output_image, xy, vec4(texelFetch(input_sampler, xy, 0).xyz, 
1.0));
+}
diff --git 
a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
 
b/source/blender/gpu/shaders/compositor/infos/compositor_convert_color_to_float_info.hh
similarity index 75%
copy from 
source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
copy to 
source/blender/gpu/shaders/compositor/infos/compositor_convert_color_to_float_info.hh
index b1ef8432801..89c921896bb 100644
--- 
a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
+++ 
b/source/blender/gpu/shaders/compositor/infos/compositor_convert_color_to_float_info.hh
@@ -17,15 +17,11 @@
  * All rights reserved.
  */
 
-/** \file
- * \ingroup gpu
- */
-
 #include "gpu_shader_create_info.hh"
 
-GPU_SHADER_CREATE_INFO(sampler2D_to_RGBA16F_2D_image)
+GPU_SHADER_CREATE_INFO(compositor_convert_color_to_float)
     .local_group_size(16, 16)
-    .sampler(0, ImageType::FLOAT_2D, "input_sampler", Frequency::PASS)
-    .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, 
"output_image")
-    .compute_source("sampler2D_to_RGBA16F_2D_image.glsl")
+    .sampler(0, ImageType::FLOAT_2D, "input_sampler")
+    .image(0, GPU_R16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
+    .compute_source("compositor_convert_color_to_float.glsl")
     .do_static_compilation(true);
diff --git 
a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
 
b/source/blender/gpu/shaders/compositor/infos/compositor_convert_float_to_color_info.hh
similarity index 82%
copy from 
source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
copy to 
source/blender/gpu/shaders/compositor/infos/compositor_convert_float_to_color_info.hh
index b1ef8432801..62bf2be1493 100644
--- 
a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
+++ 
b/source/blender/gpu/shaders/compositor/infos/compositor_convert_float_to_color_info.hh
@@ -17,15 +17,11 @@
  * All rights reserved.
  */
 
-/** \file
- * \ingroup gpu
- */
-
 #include "gpu_shader_create_info.hh"
 
-GPU_SHADER_CREATE_INFO(sampler2D_to_RGBA16F_2D_image)
+GPU_SHADER_CREATE_INFO(compositor_convert_float_to_color)
     .local_group_size(16, 16)
-    .sampler(0, ImageType::FLOAT_2D, "input_sampler", Frequency::PASS)
+    .sampler(0, ImageType::FLOAT_2D, "input_sampler")
     .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, 
"output_image")
-    .compute_source("sampler2D_to_RGBA16F_2D_image.glsl")
+    .compute_source("compositor_convert_float_to_color.glsl")
     .do_static_compilation(true);
diff --git 
a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
 
b/source/blender/gpu/shaders/compositor/infos/compositor_convert_vector_to_color_info.hh
similarity index 82%
copy from 
source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
copy to 
source/blender/gpu/shaders/compositor/infos/compositor_convert_vector_to_color_info.hh
index b1ef8432801..25b53b4cc64 100644
--- 
a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
+++ 
b/source/blender/gpu/shaders/compositor/infos/compositor_convert_vector_to_color_info.hh
@@ -17,15 +17,11 @@
  * All rights reserved.
  */
 
-/** \file
- * \ingroup gpu
- */
-
 #include "gpu_shader_create_info.hh"
 
-GPU_SHADER_CREATE_INFO(sampler2D_to_RGBA16F_2D_image)
+GPU_SHADER_CREATE_INFO(compositor_convert_vector_to_color)
     .local_group_size(16, 16)
-    .sampler(0, ImageType::FLOAT_2D, "input_sampler", Frequency::PASS)
+    .sampler(0, ImageType::FLOAT_2D, "input_sampler")
     .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, 
"output_image")
-    .compute_source("sampler2D_to_RGBA16F_2D_image.glsl")
+    .compute_source("compositor_convert_vector_to_color.glsl")
     .do_static_compilation(true);
diff --git 
a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
 
b/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
index b1ef8432801..e5a188b2e1b 100644
--- 
a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
+++ 
b/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
@@ -17,15 +17,11 @@
  * All rights reserved.
  */
 
-/** \file
- * \ingroup gpu
- */
-
 #include "gpu_shader_create_info.hh"
 
 GPU_SHADER_CREATE_INFO(sampler2D_to_RGBA16F_2D_image)
     .local_group_size(16, 16)
-    .sampler(0, ImageType::FLOAT_2D, "input_sampler", Frequency::PASS)
+    .sampler(0, ImageType::FLOAT_2D, "input_sampler")
     .image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, 
"output_image")
     .compute_source("sampler2D_to_RGBA16F_2D_image.glsl")
     .do_static_compilation(true);
diff --git a/source/blender/nodes/NOD_compositor_execute.hh 
b/source/blender/nodes/NOD_compositor_execute.hh
index 0757a815e41..26508fe674d 100644
--- a/source/blender/nodes/NOD_compositor_execute.hh
+++ b/source/blender/nodes/NOD_compositor_execute.hh
@@ -25,12 +25,25 @@
 #include "DNA_node_types.h"
 #include "DNA_scene_types.h"
 
+#include "GPU_shader.h"
 #include "GPU_texture.h"
 
 #include "NOD_derived_node_tree.hh"
 
 namespace blender::viewport_compositor {
 
+/* --------------------------------------------------------------------
+ * Result Type.
+ */
+
+/* Possible data types that operations can operate on. They either represent 
the base type of the
+ * result texture or a single value result. */
+enum class ResultType : uint8_t {
+  Float,
+  Vector,
+  Color,
+};
+
 /* --------------------------------------------------------------------
  * Texture Pool.
  */
@@ -68,12 +81,17 @@ class TexturePool {
   /* Shorthand for acquire with GPU_RGBA16F format. */
   GPUTexture *acquire_color(int width, int height);
 
-  /* Shorthand for acquire with GPU_RGB16F format. */
+  /* Shorthand for acquire with GPU_RGBA16F format. Identical to acquire_color 
because vector
+   * textures are and should internally be stored in RGBA textures. */
   GPUTexture *acquire_vector(int width, int height);
 
   /* Shorthand for acquire with GPU_R16F format. */
   GPUTexture *acquire_float(int width, int height);
 
+  /* Shorthand for acquire_[color|vector|float], whichever is appropriate for 
the given result
+   * type. */
+  GPUTexture *acquire(int width, int height, ResultType type);
+
   /* Decrement the reference count of the texture and put it back into the 
pool if its reference
    * count reaches one, potentially to be acquired later by another user. 
Notice that the texture
    * is release when the texture reference count reaches one, not zero, 
because the texture pool is
@@ -118,14 +136,6 @@ class Context {
  * Result.
  */
 
-/* Possible data types that operations can operate on. They either represent 
the base type of the
- * result texture or a single value result. */
-enum class ResultType : uint8_t {
-  Float,
-  Vector,
-  Color,
-};
-
 /* A class that describes the result of an operation. An operator can have 
multiple results
  * corresponding to multiple outputs. A result either represents a single 
value or a texture. */
 class Result {
@@ -260,7 +270,7 @@ class NodeOperation : public Operation {
  * example. */
 class MetaOperation : public Operation {
  public:
-  MetaOperation(Context &context);
+  using Operation::Operati

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to