GPU: Refactor API for Clearing Storage Buffers
The previous API for clearing storage buffers was following the OpenGL api. OpenGL has many options to support for data conversions, striding and sizzling. Metal and Vulkan don't have these features and we have to deal it ourselves. Blender internally only uses a tiny subset for what is possible in OpenGL. Making the current API to difficult to implement on our future platforms as we had to implement all cases, most even not used at all. By changing the API we make future development easier as we only need to implement what we are actually using. **New API** `GPU_storagebuf_clear(GPUStorageBuf* ssbo, uint32_t clear_value)` Related issue: #105492 Pull Request: blender/blender#105521
This commit is contained in:
@@ -117,27 +117,20 @@ void GLStorageBuf::unbind()
|
||||
slot_ = 0;
|
||||
}
|
||||
|
||||
void GLStorageBuf::clear(eGPUTextureFormat internal_format, eGPUDataFormat data_format, void *data)
|
||||
void GLStorageBuf::clear(uint32_t clear_value)
|
||||
{
|
||||
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);
|
||||
glClearNamedBufferData(ssbo_id_, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, &clear_value);
|
||||
}
|
||||
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);
|
||||
glClearBufferData(
|
||||
GL_SHADER_STORAGE_BUFFER, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, &clear_value);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,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;
|
||||
void clear(uint32_t clear_value) override;
|
||||
void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) override;
|
||||
void read(void *data) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user