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
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/blender/gpu/GPU_storage_buffer.h7
-rw-r--r--source/blender/gpu/intern/gpu_storage_buffer.cc5
-rw-r--r--source/blender/gpu/intern/gpu_storage_buffer_private.hh1
-rw-r--r--source/blender/gpu/opengl/gl_storage_buffer.cc17
-rw-r--r--source/blender/gpu/opengl/gl_storage_buffer.hh1
5 files changed, 31 insertions, 0 deletions
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);