[Bf-blender-cvs] [2e9ea4e9d41] temp-viewport-compositor-compiler: Viewport Compositor: Refactor design

Omar Emara noreply at git.blender.org
Wed Mar 2 12:04:03 CET 2022


Commit: 2e9ea4e9d41affe619de51cf2f0793382f099ceb
Author: Omar Emara
Date:   Wed Mar 2 12:54:47 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rB2e9ea4e9d41affe619de51cf2f0793382f099ceb

Viewport Compositor: Refactor design

This patch refactors the design and architecture of the viewport
compositor.

There is now a clear separation between stages of evaluation of the
compositor setup. Construction, Compilation, Allocation, and Evaluation.
This will allow more granular caching and fit the engine API better.

Instead of dynamic insertion of operations in the operations stream,
operations now have "input processors" that prepares the inputs before
execution, this can be used to do implicit, transform realization, and
any other preprocessing operations that the operation doesn't want to
worry about in its execution method.

Most of the functionalities related to results were moved to that class
and it now does reference counting manually instead of delegating that
to the texture pool.

Other minor refactoring to allow for the above.

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

M	source/blender/draw/engines/compositor/compositor_engine.cc
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_texture.cc
R100	source/blender/gpu/shaders/compositor/sampler2D_to_RGBA16F_2D_image.glsl	source/blender/gpu/shaders/compositor/compositor_image.glsl
A	source/blender/gpu/shaders/compositor/compositor_image_alpha.glsl
A	source/blender/gpu/shaders/compositor/infos/compositor_image_alpha_info.hh
R090	source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh	source/blender/gpu/shaders/compositor/infos/compositor_image_info.hh
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/composite/nodes/node_composite_viewer.cc
M	source/blender/nodes/intern/node_compositor_execute.cc

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

diff --git a/source/blender/draw/engines/compositor/compositor_engine.cc b/source/blender/draw/engines/compositor/compositor_engine.cc
index f7b1ef1b150..231bd763e4a 100644
--- a/source/blender/draw/engines/compositor/compositor_engine.cc
+++ b/source/blender/draw/engines/compositor/compositor_engine.cc
@@ -16,6 +16,8 @@
  * Copyright 2021, Blender Foundation.
  */
 
+#include "BLI_math_vec_types.hh"
+
 #include "BLT_translation.h"
 
 #include "DNA_scene_types.h"
@@ -34,10 +36,10 @@ namespace blender::viewport_compositor {
 
 class DRWTexturePool : public TexturePool {
  public:
-  GPUTexture *allocate_texture(int width, int height, eGPUTextureFormat format) override
+  GPUTexture *allocate_texture(int2 size, eGPUTextureFormat format) override
   {
     DrawEngineType *owner = (DrawEngineType *)this;
-    return DRW_texture_pool_query_2d(width, height, format, owner);
+    return DRW_texture_pool_query_2d(size.x, size.y, format, owner);
   }
 };
 
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 48845ecbd77..69013660f23 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -311,7 +311,8 @@ set(GLSL_SRC
   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/compositor/compositor_image.glsl
+  shaders/compositor/compositor_image_alpha.glsl
 
   shaders/material/gpu_shader_material_add_shader.glsl
   shaders/material/gpu_shader_material_ambient_occlusion.glsl
@@ -496,7 +497,8 @@ set(SHADER_CREATE_INFOS
   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
+  shaders/compositor/infos/compositor_image_info.hh
+  shaders/compositor/infos/compositor_image_alpha_info.hh
 )
 
 set(SHADER_CREATE_INFOS_CONTENT "")
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 56f21d03ae0..e28b0f4c60a 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -281,8 +281,6 @@ void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *
 void GPU_texture_free(GPUTexture *tex);
 
 void GPU_texture_ref(GPUTexture *tex);
-void GPU_texture_set_reference_count(GPUTexture *texture, int count);
-int GPU_texture_get_reference_count(GPUTexture *texture);
 
 void GPU_texture_bind(GPUTexture *tex, int unit);
 void GPU_texture_bind_ex(GPUTexture *tex, eGPUSamplerState state, int unit, bool set_number);
diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc
index a20aa5bf6bb..1b8b28bf04c 100644
--- a/source/blender/gpu/intern/gpu_texture.cc
+++ b/source/blender/gpu/intern/gpu_texture.cc
@@ -523,16 +523,6 @@ void GPU_texture_ref(GPUTexture *tex)
   reinterpret_cast<Texture *>(tex)->refcount++;
 }
 
-void GPU_texture_set_reference_count(GPUTexture *texture, int count)
-{
-  reinterpret_cast<Texture *>(texture)->refcount = count;
-}
-
-int GPU_texture_get_reference_count(GPUTexture *texture)
-{
-  return reinterpret_cast<Texture *>(texture)->refcount;
-}
-
 int GPU_texture_width(const GPUTexture *tex)
 {
   return reinterpret_cast<const Texture *>(tex)->width_get();
diff --git a/source/blender/gpu/shaders/compositor/sampler2D_to_RGBA16F_2D_image.glsl b/source/blender/gpu/shaders/compositor/compositor_image.glsl
similarity index 100%
rename from source/blender/gpu/shaders/compositor/sampler2D_to_RGBA16F_2D_image.glsl
rename to source/blender/gpu/shaders/compositor/compositor_image.glsl
diff --git a/source/blender/gpu/shaders/compositor/compositor_image_alpha.glsl b/source/blender/gpu/shaders/compositor/compositor_image_alpha.glsl
new file mode 100644
index 00000000000..a4bce4a1d21
--- /dev/null
+++ b/source/blender/gpu/shaders/compositor/compositor_image_alpha.glsl
@@ -0,0 +1,7 @@
+/* Copy the alpha of the input float 2D sampler to the output R16F 2D image. */
+
+void main()
+{
+  ivec2 xy = ivec2(gl_GlobalInvocationID.xy);
+  imageStore(output_image, xy, texelFetch(input_sampler, xy, 0).aaaa);
+}
diff --git a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh b/source/blender/gpu/shaders/compositor/infos/compositor_image_alpha_info.hh
similarity index 83%
copy from source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
copy to source/blender/gpu/shaders/compositor/infos/compositor_image_alpha_info.hh
index e5a188b2e1b..aee521e01cf 100644
--- a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
+++ b/source/blender/gpu/shaders/compositor/infos/compositor_image_alpha_info.hh
@@ -19,9 +19,9 @@
 
 #include "gpu_shader_create_info.hh"
 
-GPU_SHADER_CREATE_INFO(sampler2D_to_RGBA16F_2D_image)
+GPU_SHADER_CREATE_INFO(compositor_image_alpha)
     .local_group_size(16, 16)
     .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")
+    .image(0, GPU_R16F, Qualifier::WRITE, ImageType::FLOAT_2D, "output_image")
+    .compute_source("compositor_image_alpha.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_image_info.hh
similarity index 90%
rename from source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
rename to source/blender/gpu/shaders/compositor/infos/compositor_image_info.hh
index e5a188b2e1b..9797065efb4 100644
--- a/source/blender/gpu/shaders/compositor/infos/sampler2D_to_RGBA16F_2D_image_info.hh
+++ b/source/blender/gpu/shaders/compositor/infos/compositor_image_info.hh
@@ -19,9 +19,9 @@
 
 #include "gpu_shader_create_info.hh"
 
-GPU_SHADER_CREATE_INFO(sampler2D_to_RGBA16F_2D_image)
+GPU_SHADER_CREATE_INFO(compositor_image)
     .local_group_size(16, 16)
     .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_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 26508fe674d..065e1b84c10 100644
--- a/source/blender/nodes/NOD_compositor_execute.hh
+++ b/source/blender/nodes/NOD_compositor_execute.hh
@@ -19,6 +19,7 @@
 #include <cstdint>
 
 #include "BLI_map.hh"
+#include "BLI_math_vec_types.hh"
 #include "BLI_vector.hh"
 #include "BLI_vector_set.hh"
 
@@ -32,18 +33,6 @@
 
 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.
  */
@@ -52,20 +41,18 @@ enum class ResultType : uint8_t {
  * an equality operator for use in a hash map. */
 class TexturePoolKey {
  public:
-  int width;
-  int height;
+  int2 size;
   eGPUTextureFormat format;
 
-  TexturePoolKey(int width, int height, eGPUTextureFormat format);
+  TexturePoolKey(int2 size, eGPUTextureFormat format);
   TexturePoolKey(const GPUTexture *texture);
 
   uint64_t hash() const;
 };
 
 /* A pool of textures that can be allocated and reused transparently throughout the evaluation of
- * the node tree. The textures can be reference counted and will only be effectively released back
- * into the pool when their reference count reaches one. Concrete derived classes are expected to
- * free the textures once the pool is no longer in use. */
+ * the node tree. Concrete derived classes are expected to free the textures once the pool is no
+ * longer in use. */
 class TexturePool {
  private:
   /* The set of textures in the pool that are available to acquire for each distinct texture
@@ -76,34 +63,27 @@ class TexturePool {
   /* Check if there is an available texture with the given specification in the pool, if such
    * texture exists, return it, otherwise, return a newly allocated texture. Expect the texture to
    * be uncleared and contains garbage data. */
-  GPUTexture *acquire(int width, int height, eGPUTextureFormat format);
+  GPUTexture *acquire(int2 size, eGPUTextureFormat format);
 
   /* Shorthand for acquire with GPU_RGBA16F format. */
-  GPUTexture *acquire_color(int width, int height);
+  GPUTexture *acquire_color(int2 size);
 
   /* 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);
+  GPUTexture *acquire_vector(int2 size);
 
   /* 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);
+  GPUTexture *acquire_float(int2 size);
 
-  /* 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
-   * itself considered a user of the texture. Expects the texture to be one that was acquired using
-   * the same texture pool. */
+  /* Put the texture back into the pool, potentially to be acquired later by another user. Expects
+   * the texture to be one that was acquired using the same texture pool. */
   void release(GPUTexture *texture);
 
  private:
   

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list