diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-08-24 17:05:32 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-08-24 17:05:32 +0300 |
commit | 1dfb40c67cf3e4b8766c1507a04788397382b603 (patch) | |
tree | 5cf42eb5281be88fd3850691b03f9535182b0393 | |
parent | 1bc2e9a6fcdcf58f6aec93f11d5d76c8e9773de2 (diff) |
GPUStorageBuf: Add GPU_storagebuf_read() for debugging purpose
-rw-r--r-- | source/blender/draw/intern/DRW_gpu_wrapper.hh | 5 | ||||
-rw-r--r-- | source/blender/gpu/GPU_storage_buffer.h | 7 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_storage_buffer.cc | 5 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_storage_buffer_private.hh | 1 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_storage_buffer.cc | 17 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_storage_buffer.hh | 1 |
6 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/draw/intern/DRW_gpu_wrapper.hh b/source/blender/draw/intern/DRW_gpu_wrapper.hh index 231368ecc13..d9122657144 100644 --- a/source/blender/draw/intern/DRW_gpu_wrapper.hh +++ b/source/blender/draw/intern/DRW_gpu_wrapper.hh @@ -238,6 +238,11 @@ class StorageCommon : public DataBuffer<T, len, false>, NonMovable, NonCopyable GPU_storagebuf_clear_to_zero(ssbo_); } + void read() + { + GPU_storagebuf_read(ssbo_, this->data_); + } + operator GPUStorageBuf *() const { return ssbo_; diff --git a/source/blender/gpu/GPU_storage_buffer.h b/source/blender/gpu/GPU_storage_buffer.h index ca6a848786b..8837a7c7647 100644 --- a/source/blender/gpu/GPU_storage_buffer.h +++ b/source/blender/gpu/GPU_storage_buffer.h @@ -48,6 +48,13 @@ void GPU_storagebuf_clear(GPUStorageBuf *ssbo, void GPU_storagebuf_clear_to_zero(GPUStorageBuf *ssbo); /** + * Read back content of the buffer to CPU for inspection. + * Slow! Only use for inspection / debugging. + * NOTE: Not synchronized. Use appropriate barrier before reading. + */ +void GPU_storagebuf_read(GPUStorageBuf *ssbo, void *data); + +/** * \brief Copy a part of a vertex buffer to a storage buffer. * * \param ssbo: destination storage buffer diff --git a/source/blender/gpu/intern/gpu_storage_buffer.cc b/source/blender/gpu/intern/gpu_storage_buffer.cc index afa27da9c85..460a643089c 100644 --- a/source/blender/gpu/intern/gpu_storage_buffer.cc +++ b/source/blender/gpu/intern/gpu_storage_buffer.cc @@ -109,4 +109,9 @@ void GPU_storagebuf_copy_sub_from_vertbuf( unwrap(ssbo)->copy_sub(unwrap(src), dst_offset, src_offset, copy_size); } +void GPU_storagebuf_read(GPUStorageBuf *ssbo, void *data) +{ + unwrap(ssbo)->read(data); +} + /** \} */ diff --git a/source/blender/gpu/intern/gpu_storage_buffer_private.hh b/source/blender/gpu/intern/gpu_storage_buffer_private.hh index 9baec0c2a77..0c96f97ad30 100644 --- a/source/blender/gpu/intern/gpu_storage_buffer_private.hh +++ b/source/blender/gpu/intern/gpu_storage_buffer_private.hh @@ -44,6 +44,7 @@ class StorageBuf { eGPUDataFormat data_format, void *data) = 0; virtual void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) = 0; + virtual void read(void *data) = 0; }; /* Syntactic sugar. */ diff --git a/source/blender/gpu/opengl/gl_storage_buffer.cc b/source/blender/gpu/opengl/gl_storage_buffer.cc index 83a56edcf04..5d876308b3c 100644 --- a/source/blender/gpu/opengl/gl_storage_buffer.cc +++ b/source/blender/gpu/opengl/gl_storage_buffer.cc @@ -166,6 +166,23 @@ void GLStorageBuf::copy_sub(VertBuf *src_, uint dst_offset, uint src_offset, uin } } +void GLStorageBuf::read(void *data) +{ + if (ssbo_id_ == 0) { + this->init(); + } + + if (GLContext::direct_state_access_support) { + glGetNamedBufferSubData(ssbo_id_, 0, size_in_bytes_, data); + } + else { + /* This binds the buffer to GL_ARRAY_BUFFER and upload the data if any. */ + glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo_id_); + glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, size_in_bytes_, data); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + } +} + /** \} */ } // namespace blender::gpu diff --git a/source/blender/gpu/opengl/gl_storage_buffer.hh b/source/blender/gpu/opengl/gl_storage_buffer.hh index ffe2de12451..680ce911bc7 100644 --- a/source/blender/gpu/opengl/gl_storage_buffer.hh +++ b/source/blender/gpu/opengl/gl_storage_buffer.hh @@ -35,6 +35,7 @@ class GLStorageBuf : public StorageBuf { void unbind() override; void clear(eGPUTextureFormat internal_format, eGPUDataFormat data_format, void *data) override; void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) override; + void read(void *data) override; /* Special internal function to bind SSBOs to indirect argument targets. */ void bind_as(GLenum target); |