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:42:12 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-03-18 22:59:20 +0300
commit7ee816e32f3655d4ca8abb555f885d8de9ba0520 (patch)
tree50190c369e80c20fadc1bc55d56f160188a1ff90 /source/blender/gpu/opengl
parent5bd38f3be8542f09ece0d936b04dba3f8854cb51 (diff)
GPU: StorageBuf: Add method to clear the buffer in place.
This is a faster way to clear a buffer instead of reuploading new data. It is equivalent to `memset` and runs directly on the GPU. This is better to clear huge buffers and to avoid the sync cost of data upload.
Diffstat (limited to 'source/blender/gpu/opengl')
-rw-r--r--source/blender/gpu/opengl/gl_storage_buffer.cc25
-rw-r--r--source/blender/gpu/opengl/gl_storage_buffer.hh1
2 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/gpu/opengl/gl_storage_buffer.cc b/source/blender/gpu/opengl/gl_storage_buffer.cc
index 12f942439ca..9cdde0b5734 100644
--- a/source/blender/gpu/opengl/gl_storage_buffer.cc
+++ b/source/blender/gpu/opengl/gl_storage_buffer.cc
@@ -112,6 +112,31 @@ void GLStorageBuf::unbind()
slot_ = 0;
}
+void GLStorageBuf::clear(eGPUTextureFormat internal_format, eGPUDataFormat data_format, void *data)
+{
+ if (ssbo_id_ == 0) {
+ this->init();
+ }
+
+ if (GLContext::direct_state_access_support) {
+ glClearNamedBufferData(ssbo_id_,
+ to_gl_internal_format(internal_format),
+ to_gl_data_format(internal_format),
+ to_gl(data_format),
+ data);
+ }
+ else {
+ /* WATCH(@fclem): This should be ok since we only use clear outside of drawing functions. */
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo_id_);
+ glClearBufferData(GL_SHADER_STORAGE_BUFFER,
+ to_gl_internal_format(internal_format),
+ to_gl_data_format(internal_format),
+ to_gl(data_format),
+ 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 106d2158273..d657a4de09c 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 update(const void *data) override;
void bind(int slot) override;
void unbind() override;
+ void clear(eGPUTextureFormat internal_format, eGPUDataFormat data_format, void *data) override;
private:
void init();