Vulkan: Clearing Storage Buffers #105487
|
@ -832,8 +832,7 @@ void ShadowModule::end_sync()
|
|||
tilemap_pool.tiles_data.clear_to_zero();
|
||||
|
||||
/* Clear cached page buffer. */
|
||||
int2 data = {-1, -1};
|
||||
GPU_storagebuf_clear_int(pages_cached_data_, data, 2);
|
||||
GPU_storagebuf_clear(pages_cached_data_, -1);
|
||||
|
||||
/* Reset info to match new state. */
|
||||
pages_infos_data_.page_free_count = shadow_page_len_;
|
||||
|
|
|
@ -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_uint(pass_visibility_buf_, &data, 1);
|
||||
GPU_storagebuf_clear(pass_visibility_buf_, data);
|
||||
fail_visibility_buf_.resize(words_len);
|
||||
GPU_storagebuf_clear_uint(fail_visibility_buf_, &data, 1);
|
||||
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_uint(visibility_buf_, &data, 1);
|
||||
GPU_storagebuf_clear(visibility_buf_, data);
|
||||
}
|
||||
|
||||
if (do_visibility_) {
|
||||
|
|
|
@ -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_uint(visibility_buf_, &data, 1);
|
||||
const uint32_t data = 0xFFFFFFFFu;
|
||||
GPU_storagebuf_clear(visibility_buf_, data);
|
||||
|
||||
if (do_visibility_) {
|
||||
GPUShader *shader = DRW_shader_draw_visibility_compute_get();
|
||||
|
|
|
@ -42,20 +42,10 @@ void GPU_storagebuf_unbind_all(void);
|
|||
void GPU_storagebuf_clear_to_zero(GPUStorageBuf *ssbo);
|
||||
|
||||
/**
|
||||
* Clear the content of the buffer using the given #clear_data. #clear_data will be used as a
|
||||
* repeatable pattern.
|
||||
*
|
||||
* NOTE: clear_data_len must be in range 1 to 4 (inclusive).
|
||||
* 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_uint(GPUStorageBuf *ssbo, uint32_t *clear_data, int clear_data_len);
|
||||
|
||||
/**
|
||||
* Clear the content of the buffer using the given #clear_data. #clear_data will be used as a
|
||||
* repeatable pattern.
|
||||
*
|
||||
* NOTE: clear_data_len must be in range 1 to 4 (inclusive).
|
||||
*/
|
||||
void GPU_storagebuf_clear_int(GPUStorageBuf *ssbo, int32_t *clear_data, int clear_data_len);
|
||||
void GPU_storagebuf_clear(GPUStorageBuf *ssbo, uint32_t clear_value);
|
||||
|
||||
/**
|
||||
* Read back content of the buffer to CPU for inspection.
|
||||
|
|
|
@ -91,20 +91,12 @@ void GPU_storagebuf_unbind_all()
|
|||
|
||||
void GPU_storagebuf_clear_to_zero(GPUStorageBuf *ssbo)
|
||||
{
|
||||
uint32_t data = 0u;
|
||||
GPU_storagebuf_clear_uint(ssbo, &data, 1);
|
||||
GPU_storagebuf_clear(ssbo, 0);
|
||||
}
|
||||
|
||||
void GPU_storagebuf_clear_int(GPUStorageBuf *ssbo, int32_t *clear_data, int clear_data_len)
|
||||
void GPU_storagebuf_clear(GPUStorageBuf *ssbo, uint32_t clear_value)
|
||||
{
|
||||
uint32_t *clear_data_uint = static_cast<uint32_t *>(static_cast<void *>(clear_data));
|
||||
GPU_storagebuf_clear_uint(ssbo, clear_data_uint, clear_data_len);
|
||||
}
|
||||
|
||||
void GPU_storagebuf_clear_uint(GPUStorageBuf *ssbo, uint32_t *clear_data, int clear_data_len)
|
||||
{
|
||||
BLI_assert(clear_data_len >= 1 && clear_data_len <= 4);
|
||||
unwrap(ssbo)->clear(blender::Span<uint32_t>(clear_data, clear_data_len));
|
||||
unwrap(ssbo)->clear(clear_value);
|
||||
}
|
||||
|
||||
void GPU_storagebuf_copy_sub_from_vertbuf(
|
||||
|
|
|
@ -43,7 +43,7 @@ class StorageBuf {
|
|||
virtual void update(const void *data) = 0;
|
||||
virtual void bind(int slot) = 0;
|
||||
virtual void unbind() = 0;
|
||||
virtual void clear(Span<uint32_t> 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;
|
||||
};
|
||||
|
|
|
@ -117,39 +117,20 @@ void GLStorageBuf::unbind()
|
|||
slot_ = 0;
|
||||
}
|
||||
|
||||
void GLStorageBuf::clear(Span<uint32_t> data)
|
||||
void GLStorageBuf::clear(uint32_t clear_value)
|
||||
{
|
||||
if (ssbo_id_ == 0) {
|
||||
this->init();
|
||||
}
|
||||
|
||||
GLenum internal_format = GL_R32UI;
|
||||
GLenum format = GL_RED_INTEGER;
|
||||
if (data.size() == 1) {
|
||||
internal_format = GL_R32UI;
|
||||
format = GL_RED_INTEGER;
|
||||
}
|
||||
else if (data.size() == 2) {
|
||||
internal_format = GL_RG32UI;
|
||||
format = GL_RG_INTEGER;
|
||||
}
|
||||
else if (data.size() == 3) {
|
||||
internal_format = GL_RGB32UI;
|
||||
format = GL_RGB_INTEGER;
|
||||
}
|
||||
else if (data.size() == 4) {
|
||||
internal_format = GL_RGBA32UI;
|
||||
format = GL_RGBA_INTEGER;
|
||||
}
|
||||
|
||||
if (GLContext::direct_state_access_support) {
|
||||
glClearNamedBufferData(ssbo_id_, internal_format, format, GL_UNSIGNED_INT, data.data());
|
||||
glClearNamedBufferData(ssbo_id_, GL_RGBA32UI, GL_RGBA_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, internal_format, format, GL_UNSIGNED_INT, data.data());
|
||||
GL_SHADER_STORAGE_BUFFER, GL_RGBA32UI, GL_RGBA_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(Span<uint32_t> 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;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ void VKStorageBuffer::unbind()
|
|||
{
|
||||
}
|
||||
|
||||
void VKStorageBuffer::clear(Span<uint32_t> /*data*/)
|
||||
void VKStorageBuffer::clear(uint32_t /*clear_value*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class VKStorageBuffer : public StorageBuf {
|
|||
void update(const void *data) override;
|
||||
void bind(int slot) override;
|
||||
void unbind() override;
|
||||
void clear(Span<uint32_t> 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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue