diff options
-rw-r--r-- | source/blender/gpu/GPU_compute.h | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_backend.hh | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_compute.cc | 15 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_backend.hh | 13 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_compute.cc | 2 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_storage_buffer.cc | 7 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_storage_buffer.hh | 3 |
7 files changed, 36 insertions, 8 deletions
diff --git a/source/blender/gpu/GPU_compute.h b/source/blender/gpu/GPU_compute.h index 437b0223303..6dfd6f73ae8 100644 --- a/source/blender/gpu/GPU_compute.h +++ b/source/blender/gpu/GPU_compute.h @@ -9,6 +9,7 @@ #include "BLI_sys_types.h" #include "GPU_shader.h" +#include "GPU_storage_buffer.h" #ifdef __cplusplus extern "C" { @@ -19,6 +20,8 @@ void GPU_compute_dispatch(GPUShader *shader, uint groups_y_len, uint groups_z_len); +void GPU_compute_dispatch_indirect(GPUShader *shader, GPUStorageBuf *indirect_buf); + #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/intern/gpu_backend.hh b/source/blender/gpu/intern/gpu_backend.hh index 56d7c3b4e46..ad906c74980 100644 --- a/source/blender/gpu/intern/gpu_backend.hh +++ b/source/blender/gpu/intern/gpu_backend.hh @@ -35,6 +35,7 @@ class GPUBackend { virtual void samplers_update() = 0; virtual void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) = 0; + virtual void compute_dispatch_indirect(StorageBuf *indirect_buf) = 0; virtual Context *context_alloc(void *ghost_window) = 0; diff --git a/source/blender/gpu/intern/gpu_compute.cc b/source/blender/gpu/intern/gpu_compute.cc index e99455b756a..b45cf8211cb 100644 --- a/source/blender/gpu/intern/gpu_compute.cc +++ b/source/blender/gpu/intern/gpu_compute.cc @@ -7,10 +7,7 @@ #include "GPU_compute.h" #include "gpu_backend.hh" - -#ifdef __cplusplus -extern "C" { -#endif +#include "gpu_storage_buffer_private.hh" void GPU_compute_dispatch(GPUShader *shader, uint groups_x_len, @@ -22,6 +19,12 @@ void GPU_compute_dispatch(GPUShader *shader, gpu_backend.compute_dispatch(groups_x_len, groups_y_len, groups_z_len); } -#ifdef __cplusplus +void GPU_compute_dispatch_indirect(GPUShader *shader, GPUStorageBuf *indirect_buf_) +{ + blender::gpu::GPUBackend &gpu_backend = *blender::gpu::GPUBackend::get(); + blender::gpu::StorageBuf *indirect_buf = reinterpret_cast<blender::gpu::StorageBuf *>( + indirect_buf_); + + GPU_shader_bind(shader); + gpu_backend.compute_dispatch_indirect(indirect_buf); } -#endif 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(); |