diff --git a/source/blender/draw/engines/eevee_next/eevee_shadow.cc b/source/blender/draw/engines/eevee_next/eevee_shadow.cc index 05942d7a131..81e84d12961 100644 --- a/source/blender/draw/engines/eevee_next/eevee_shadow.cc +++ b/source/blender/draw/engines/eevee_next/eevee_shadow.cc @@ -836,8 +836,7 @@ void ShadowModule::end_sync() tilemap_pool.tiles_data.clear_to_zero(); /* Clear cached page buffer. */ - int2 data = {-1, -1}; - GPU_storagebuf_clear(pages_cached_data_, GPU_RG32I, GPU_DATA_INT, &data); + GPU_storagebuf_clear(pages_cached_data_, -1); /* Reset info to match new state. */ pages_infos_data_.page_free_count = shadow_page_len_; diff --git a/source/blender/draw/engines/workbench/workbench_shadow.cc b/source/blender/draw/engines/workbench/workbench_shadow.cc index ff50fd3732c..bf3abdd5b82 100644 --- a/source/blender/draw/engines/workbench/workbench_shadow.cc +++ b/source/blender/draw/engines/workbench/workbench_shadow.cc @@ -220,14 +220,14 @@ void ShadowPass::ShadowView::compute_visibility(ObjectBoundsBuf &bounds, uint words_len = (view_len_ == 1) ? divide_ceil_u(resource_len, 32) : resource_len * word_per_draw; words_len = ceil_to_multiple_u(max_ii(1, words_len), 4); - uint32_t data = 0xFFFFFFFFu; + const uint32_t data = 0xFFFFFFFFu; if (current_pass_type_ == ShadowPass::PASS) { /* TODO(fclem): Resize to nearest pow2 to reduce fragmentation. */ pass_visibility_buf_.resize(words_len); - GPU_storagebuf_clear(pass_visibility_buf_, GPU_R32UI, GPU_DATA_UINT, &data); + GPU_storagebuf_clear(pass_visibility_buf_, data); fail_visibility_buf_.resize(words_len); - GPU_storagebuf_clear(fail_visibility_buf_, GPU_R32UI, GPU_DATA_UINT, &data); + GPU_storagebuf_clear(fail_visibility_buf_, data); } else if (current_pass_type_ == ShadowPass::FAIL) { /* Already computed in the ShadowPass::PASS */ @@ -236,7 +236,7 @@ void ShadowPass::ShadowView::compute_visibility(ObjectBoundsBuf &bounds, } else { visibility_buf_.resize(words_len); - GPU_storagebuf_clear(visibility_buf_, GPU_R32UI, GPU_DATA_UINT, &data); + GPU_storagebuf_clear(visibility_buf_, data); } if (do_visibility_) { diff --git a/source/blender/draw/intern/draw_view.cc b/source/blender/draw/intern/draw_view.cc index 46fd82a239e..30417ff6420 100644 --- a/source/blender/draw/intern/draw_view.cc +++ b/source/blender/draw/intern/draw_view.cc @@ -280,8 +280,8 @@ void View::compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool d /* TODO(fclem): Resize to nearest pow2 to reduce fragmentation. */ visibility_buf_.resize(words_len); - uint32_t data = 0xFFFFFFFFu; - GPU_storagebuf_clear(visibility_buf_, GPU_R32UI, GPU_DATA_UINT, &data); + const uint32_t data = 0xFFFFFFFFu; + GPU_storagebuf_clear(visibility_buf_, data); if (do_visibility_) { GPUShader *shader = DRW_shader_draw_visibility_compute_get(); diff --git a/source/blender/gpu/GPU_storage_buffer.h b/source/blender/gpu/GPU_storage_buffer.h index 8ed60d9000a..1399353b085 100644 --- a/source/blender/gpu/GPU_storage_buffer.h +++ b/source/blender/gpu/GPU_storage_buffer.h @@ -39,12 +39,14 @@ void GPU_storagebuf_bind(GPUStorageBuf *ssbo, int slot); void GPU_storagebuf_unbind(GPUStorageBuf *ssbo); void GPU_storagebuf_unbind_all(void); -void GPU_storagebuf_clear(GPUStorageBuf *ssbo, - eGPUTextureFormat internal_format, - eGPUDataFormat data_format, - void *data); void GPU_storagebuf_clear_to_zero(GPUStorageBuf *ssbo); +/** + * Clear the content of the buffer using the given #clear_value. #clear_value will be used as a + * repeatable pattern of 32bits. + */ +void GPU_storagebuf_clear(GPUStorageBuf *ssbo, uint32_t clear_value); + /** * Read back content of the buffer to CPU for inspection. * Slow! Only use for inspection / debugging. diff --git a/source/blender/gpu/intern/gpu_storage_buffer.cc b/source/blender/gpu/intern/gpu_storage_buffer.cc index 460a643089c..d82f6fa6237 100644 --- a/source/blender/gpu/intern/gpu_storage_buffer.cc +++ b/source/blender/gpu/intern/gpu_storage_buffer.cc @@ -89,18 +89,14 @@ void GPU_storagebuf_unbind_all() /* FIXME */ } -void GPU_storagebuf_clear(GPUStorageBuf *ssbo, - eGPUTextureFormat internal_format, - eGPUDataFormat data_format, - void *data) -{ - unwrap(ssbo)->clear(internal_format, data_format, data); -} - void GPU_storagebuf_clear_to_zero(GPUStorageBuf *ssbo) { - uint32_t data = 0u; - GPU_storagebuf_clear(ssbo, GPU_R32UI, GPU_DATA_UINT, &data); + GPU_storagebuf_clear(ssbo, 0); +} + +void GPU_storagebuf_clear(GPUStorageBuf *ssbo, uint32_t clear_value) +{ + unwrap(ssbo)->clear(clear_value); } void GPU_storagebuf_copy_sub_from_vertbuf( diff --git a/source/blender/gpu/intern/gpu_storage_buffer_private.hh b/source/blender/gpu/intern/gpu_storage_buffer_private.hh index c05d8dc5b98..6f0a97117ef 100644 --- a/source/blender/gpu/intern/gpu_storage_buffer_private.hh +++ b/source/blender/gpu/intern/gpu_storage_buffer_private.hh @@ -7,6 +7,7 @@ #pragma once +#include "BLI_span.hh" #include "BLI_sys_types.h" struct GPUStorageBuf; @@ -42,9 +43,7 @@ class StorageBuf { virtual void update(const void *data) = 0; virtual void bind(int slot) = 0; virtual void unbind() = 0; - virtual void clear(eGPUTextureFormat internal_format, - eGPUDataFormat data_format, - void *data) = 0; + virtual void clear(uint32_t clear_value) = 0; virtual void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) = 0; virtual void read(void *data) = 0; }; diff --git a/source/blender/gpu/opengl/gl_storage_buffer.cc b/source/blender/gpu/opengl/gl_storage_buffer.cc index 5d876308b3c..5ad2ef00bd4 100644 --- a/source/blender/gpu/opengl/gl_storage_buffer.cc +++ b/source/blender/gpu/opengl/gl_storage_buffer.cc @@ -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); } } diff --git a/source/blender/gpu/opengl/gl_storage_buffer.hh b/source/blender/gpu/opengl/gl_storage_buffer.hh index 680ce911bc7..3932698ea2d 100644 --- a/source/blender/gpu/opengl/gl_storage_buffer.hh +++ b/source/blender/gpu/opengl/gl_storage_buffer.hh @@ -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; diff --git a/source/blender/gpu/vulkan/vk_storage_buffer.cc b/source/blender/gpu/vulkan/vk_storage_buffer.cc index e1c503a4032..5ab293bef6a 100644 --- a/source/blender/gpu/vulkan/vk_storage_buffer.cc +++ b/source/blender/gpu/vulkan/vk_storage_buffer.cc @@ -43,11 +43,10 @@ void VKStorageBuffer::unbind() { } -void VKStorageBuffer::clear(eGPUTextureFormat /*internal_format*/, - eGPUDataFormat /*data_format*/, - void * /*data*/) +void VKStorageBuffer::clear(uint32_t /*clear_value*/) { } + void VKStorageBuffer::copy_sub(VertBuf * /*src*/, uint /*dst_offset*/, uint /*src_offset*/, diff --git a/source/blender/gpu/vulkan/vk_storage_buffer.hh b/source/blender/gpu/vulkan/vk_storage_buffer.hh index a9ee1a6256b..b35e9d990c3 100644 --- a/source/blender/gpu/vulkan/vk_storage_buffer.hh +++ b/source/blender/gpu/vulkan/vk_storage_buffer.hh @@ -30,7 +30,7 @@ class VKStorageBuffer : 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;