Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-03-16 10:58:59 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-03-18 22:59:27 +0300
commitd7df0dcccb50bbbc1e14cbe49bb128fa108b8a3e (patch)
tree82a855df4e730f9ccc79935d4221a65d556c0059 /source/blender/gpu/opengl
parent7ee816e32f3655d4ca8abb555f885d8de9ba0520 (diff)
GPU: Add indirect dispatch support.
This uses a StorageBuf as the source of indirect dispatch argument. The user needs to make sure the parameters are in the right order. There is no support for argument offset for the moment as there is no need for it. But this might be added in the future. Note that the indirect buffer is synchronized at the backend level. This is done for practical reasons and because this feature is almost always used for GPU driven pipeline.
Diffstat (limited to 'source/blender/gpu/opengl')
-rw-r--r--source/blender/gpu/opengl/gl_backend.hh13
-rw-r--r--source/blender/gpu/opengl/gl_compute.cc2
-rw-r--r--source/blender/gpu/opengl/gl_storage_buffer.cc7
-rw-r--r--source/blender/gpu/opengl/gl_storage_buffer.hh3
4 files changed, 23 insertions, 2 deletions
diff --git a/source/blender/gpu/opengl/gl_backend.hh b/source/blender/gpu/opengl/gl_backend.hh
index d7edd162f33..e72726d9c7b 100644
--- a/source/blender/gpu/opengl/gl_backend.hh
+++ b/source/blender/gpu/opengl/gl_backend.hh
@@ -123,6 +123,19 @@ class GLBackend : public GPUBackend {
GLCompute::dispatch(groups_x_len, groups_y_len, groups_z_len);
}
+ void compute_dispatch_indirect(StorageBuf *indirect_buf) override
+ {
+ GLContext::get()->state_manager_active_get()->apply_state();
+
+ dynamic_cast<GLStorageBuf *>(indirect_buf)->bind_as(GL_DISPATCH_INDIRECT_BUFFER);
+ /* This barrier needs to be here as it only work on the currently bound indirect buffer. */
+ glMemoryBarrier(GL_DRAW_INDIRECT_BUFFER);
+
+ glDispatchComputeIndirect((GLintptr)0);
+ /* Unbind. */
+ glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
+ }
+
private:
static void platform_init();
static void platform_exit();
diff --git a/source/blender/gpu/opengl/gl_compute.cc b/source/blender/gpu/opengl/gl_compute.cc
index 1913174eaef..2fbf23c227d 100644
--- a/source/blender/gpu/opengl/gl_compute.cc
+++ b/source/blender/gpu/opengl/gl_compute.cc
@@ -16,8 +16,6 @@ void GLCompute::dispatch(int group_x_len, int group_y_len, int group_z_len)
{
GL_CHECK_RESOURCES("Compute");
- GLContext::get()->state_manager->apply_state();
-
glDispatchCompute(group_x_len, group_y_len, group_z_len);
}
diff --git a/source/blender/gpu/opengl/gl_storage_buffer.cc b/source/blender/gpu/opengl/gl_storage_buffer.cc
index 9cdde0b5734..a461d834790 100644
--- a/source/blender/gpu/opengl/gl_storage_buffer.cc
+++ b/source/blender/gpu/opengl/gl_storage_buffer.cc
@@ -100,6 +100,13 @@ void GLStorageBuf::bind(int slot)
#endif
}
+void GLStorageBuf::bind_as(GLenum target)
+{
+ BLI_assert_msg(ssbo_id_ != 0,
+ "Trying to use storage buf as indirect buffer but buffer was never filled.");
+ glBindBuffer(target, ssbo_id_);
+}
+
void GLStorageBuf::unbind()
{
#ifdef DEBUG
diff --git a/source/blender/gpu/opengl/gl_storage_buffer.hh b/source/blender/gpu/opengl/gl_storage_buffer.hh
index d657a4de09c..c808a0bdda1 100644
--- a/source/blender/gpu/opengl/gl_storage_buffer.hh
+++ b/source/blender/gpu/opengl/gl_storage_buffer.hh
@@ -37,6 +37,9 @@ class GLStorageBuf : public StorageBuf {
void unbind() override;
void clear(eGPUTextureFormat internal_format, eGPUDataFormat data_format, void *data) override;
+ /* Special internal function to bind SSBOs to indirect argument targets. */
+ void bind_as(GLenum target);
+
private:
void init();