[Bf-blender-cvs] [982e8ef6fdd] temp-gpu-compute-shaders: Use GPUBatch to handle compute pipeline.

Jeroen Bakker noreply at git.blender.org
Fri Apr 23 10:26:21 CEST 2021


Commit: 982e8ef6fdd811cda953cb2f20e7f4e565126f80
Author: Jeroen Bakker
Date:   Fri Apr 9 09:32:56 2021 +0200
Branches: temp-gpu-compute-shaders
https://developer.blender.org/rB982e8ef6fdd811cda953cb2f20e7f4e565126f80

Use GPUBatch to handle compute pipeline.

Will match better with vulkan.

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

M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_batch.h
M	source/blender/gpu/intern/gpu_backend.hh
M	source/blender/gpu/intern/gpu_batch.cc
M	source/blender/gpu/intern/gpu_batch_private.hh
D	source/blender/gpu/intern/gpu_compute.cc
M	source/blender/gpu/opengl/gl_backend.hh
M	source/blender/gpu/opengl/gl_batch.cc
M	source/blender/gpu/opengl/gl_batch.hh
D	source/blender/gpu/opengl/gl_compute.cc
D	source/blender/gpu/opengl/gl_compute.hh
M	source/blender/gpu/tests/gpu_shader_test.cc

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

diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index fda31441d2b..867483b0285 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -62,7 +62,6 @@ set(SRC
   intern/gpu_buffers.c
   intern/gpu_capabilities.cc
   intern/gpu_codegen.c
-  intern/gpu_compute.cc
   intern/gpu_context.cc
   intern/gpu_debug.cc
   intern/gpu_drawlist.cc
@@ -92,7 +91,6 @@ set(SRC
 
   opengl/gl_backend.cc
   opengl/gl_batch.cc
-  opengl/gl_compute.cc
   opengl/gl_context.cc
   opengl/gl_debug.cc
   opengl/gl_debug_layer.cc
@@ -115,7 +113,6 @@ set(SRC
   GPU_buffers.h
   GPU_capabilities.h
   GPU_common.h
-  GPU_compute.h
   GPU_context.h
   GPU_debug.h
   GPU_drawlist.h
@@ -166,7 +163,6 @@ set(SRC
 
   opengl/gl_backend.hh
   opengl/gl_batch.hh
-  opengl/gl_compute.hh
   opengl/gl_context.hh
   opengl/gl_debug.hh
   opengl/gl_drawlist.hh
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index 018e192bf37..da4214481d9 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -105,6 +105,8 @@ void GPU_batch_init_ex(GPUBatch *batch,
 void GPU_batch_copy(GPUBatch *batch_dst, GPUBatch *batch_src);
 
 #define GPU_batch_create(prim, verts, elem) GPU_batch_create_ex(prim, verts, elem, 0)
+#define GPU_batch_compute_create() \
+  GPU_batch_create_ex(GPU_PRIM_NONE, NULL, NULL, GPU_BATCH_OWNS_NONE)
 #define GPU_batch_init(batch, prim, verts, elem) GPU_batch_init_ex(batch, prim, verts, elem, 0)
 
 /* Same as discard but does not free. (does not call free callback). */
@@ -148,11 +150,15 @@ void GPU_batch_program_set_builtin_with_config(GPUBatch *batch,
   GPU_shader_uniform_mat4((batch)->shader, name, val);
 #define GPU_batch_texture_bind(batch, name, tex) \
   GPU_texture_bind(tex, GPU_shader_get_texture_binding((batch)->shader, name));
+#define GPU_batch_texture_image_bind(batch, name, tex) \
+  GPU_texture_image_bind(tex, GPU_shader_get_texture_binding((batch)->shader, name));
 
 void GPU_batch_draw(GPUBatch *batch);
 void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count);
 void GPU_batch_draw_instanced(GPUBatch *batch, int i_count);
 
+void GPU_batch_compute(GPUBatch *batch, uint group_x_len, uint group_y_len, uint group_z_len);
+
 /* This does not bind/unbind shader and does not call GPU_matrix_bind() */
 void GPU_batch_draw_advanced(GPUBatch *, int v_first, int v_count, int i_first, int i_count);
 
diff --git a/source/blender/gpu/intern/gpu_backend.hh b/source/blender/gpu/intern/gpu_backend.hh
index 73792215569..04ec82a9213 100644
--- a/source/blender/gpu/intern/gpu_backend.hh
+++ b/source/blender/gpu/intern/gpu_backend.hh
@@ -47,7 +47,6 @@ class GPUBackend {
   static GPUBackend *get(void);
 
   virtual void samplers_update(void) = 0;
-  virtual void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) = 0;
 
   virtual Context *context_alloc(void *ghost_window) = 0;
 
diff --git a/source/blender/gpu/intern/gpu_batch.cc b/source/blender/gpu/intern/gpu_batch.cc
index 9dc24c59e22..f0bcca7b07b 100644
--- a/source/blender/gpu/intern/gpu_batch.cc
+++ b/source/blender/gpu/intern/gpu_batch.cc
@@ -73,7 +73,7 @@ void GPU_batch_init_ex(GPUBatch *batch,
                        GPUIndexBuf *elem,
                        eGPUBatchFlag owns_flag)
 {
-  BLI_assert(verts != nullptr);
+  BLI_assert(verts != nullptr || prim_type == GPU_PRIM_NONE);
   /* Do not pass any other flag */
   BLI_assert((owns_flag & ~(GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX)) == 0);
 
@@ -284,6 +284,24 @@ void GPU_batch_draw_advanced(
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Drawing / Drawcall functions
+ * \{ */
+
+void GPU_batch_compute(GPUBatch *gpu_batch, uint group_x_len, uint group_y_len, uint group_z_len)
+{
+  BLI_assert(gpu_batch);
+  Batch *batch = static_cast<Batch *>(gpu_batch);
+
+  BLI_assert(batch->prim_type == GPU_PRIM_NONE);
+  BLI_assert(Context::get()->shader != nullptr);
+
+  GPU_shader_bind(batch->shader);
+  batch->compute(group_x_len, group_y_len, group_z_len);
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Utilities
  * \{ */
diff --git a/source/blender/gpu/intern/gpu_batch_private.hh b/source/blender/gpu/intern/gpu_batch_private.hh
index d0fbd1432b3..4b02477ee37 100644
--- a/source/blender/gpu/intern/gpu_batch_private.hh
+++ b/source/blender/gpu/intern/gpu_batch_private.hh
@@ -46,6 +46,7 @@ class Batch : public GPUBatch {
   virtual ~Batch(){};
 
   virtual void draw(int v_first, int v_count, int i_first, int i_count) = 0;
+  virtual void compute(uint group_x_len, uint group_y_len, uint group_z_len) = 0;
 
   /* Convenience casts. */
   IndexBuf *elem_(void) const
diff --git a/source/blender/gpu/intern/gpu_compute.cc b/source/blender/gpu/intern/gpu_compute.cc
deleted file mode 100644
index e07a17d14a4..00000000000
--- a/source/blender/gpu/intern/gpu_compute.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/** \file
- * \ingroup gpu
- */
-
-#include "GPU_compute.h"
-
-#include "gpu_backend.hh"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void GPU_compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len)
-{
-  blender::gpu::GPUBackend &gpu_backend = *blender::gpu::GPUBackend::get();
-  gpu_backend.compute_dispatch(groups_x_len, groups_y_len, groups_z_len);
-}
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/source/blender/gpu/opengl/gl_backend.hh b/source/blender/gpu/opengl/gl_backend.hh
index 7a11a11dd8f..231e5811b45 100644
--- a/source/blender/gpu/opengl/gl_backend.hh
+++ b/source/blender/gpu/opengl/gl_backend.hh
@@ -28,7 +28,6 @@
 #include "BLI_vector.hh"
 
 #include "gl_batch.hh"
-#include "gl_compute.hh"
 #include "gl_context.hh"
 #include "gl_drawlist.hh"
 #include "gl_framebuffer.hh"
@@ -127,11 +126,6 @@ class GLBackend : public GPUBackend {
     return shared_orphan_list_;
   };
 
-  void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
-  {
-    GLCompute::dispatch(groups_x_len, groups_y_len, groups_z_len);
-  }
-
  private:
   static void platform_init(void);
   static void platform_exit(void);
diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc
index 321d9552828..ae2172c3630 100644
--- a/source/blender/gpu/opengl/gl_batch.cc
+++ b/source/blender/gpu/opengl/gl_batch.cc
@@ -363,3 +363,16 @@ void GLBatch::draw(int v_first, int v_count, int i_first, int i_count)
 }
 
 /** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Compute
+ * \{ */
+
+void GLBatch::compute(uint group_x_len, uint group_y_len, uint group_z_len)
+{
+  GLContext::get()->state_manager->apply_state();
+  glDispatchCompute(group_x_len, group_y_len, group_z_len);
+  debug::check_gl_error("Dispatch Compute");
+}
+
+/** \} */
diff --git a/source/blender/gpu/opengl/gl_batch.hh b/source/blender/gpu/opengl/gl_batch.hh
index 218b9ffe4b7..557fa5b53d4 100644
--- a/source/blender/gpu/opengl/gl_batch.hh
+++ b/source/blender/gpu/opengl/gl_batch.hh
@@ -100,6 +100,7 @@ class GLBatch : public Batch {
   ~GLBatch();
 
   void draw(int v_first, int v_count, int i_first, int i_count) override;
+  void compute(uint group_x_len, uint group_y_len, uint group_z_len) override;
   void bind(int i_first);
 
   /* Convenience getters. */
diff --git a/source/blender/gpu/opengl/gl_compute.cc b/source/blender/gpu/opengl/gl_compute.cc
deleted file mode 100644
index fa8317dde4a..00000000000
--- a/source/blender/gpu/opengl/gl_compute.cc
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/** \file
- * \ingroup gpu
- */
-
-#include "gl_compute.hh"
-
-#include "gl_debug.hh"
-
-#include "glew-mx.h"
-
-namespace blender::gpu {
-
-void GLCompute::dispatch(int group_x_len, int group_y_len, int group_z_len)
-{
-  glDispatchCompute(group_x_len, group_y_len, group_z_len);
-  debug::check_gl_error("Dispatch Compute");
-}
-
-}  // namespace blender::gpu
diff --git a/source/blender/gpu/opengl/gl_compute.hh b/source/blender/gpu/opengl/gl_compute.hh
deleted file mode 100644
index 2fd918ddd10..00000000000
--- a/source/blender/gpu/opengl/gl_compute.hh
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Publ

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list