7becc38a3c introduced new text rendering.
In the refactoring the vertex buffer was replaced by a more shallow
storage buffer. However the refactoring removed one optimization that
the vulkan backend uses, namely the actual amount of bytes that is being
used by the draw call. This resulted in overly large data transfers.
For example in the text editor the texts are rendered one glyph at a
time. But the storage buffer would always upload the data for 1024
glyphs.
This PR allows the usage size of a storage buffer to be set to ensure
that the data transfers are limited.
The implementation wasn't added to OpenGL as it draws incorrectly.
Issue detected during the research of !146956 That PR will implement
better data streaming inside the Vulkan backend and also requires
to know the actual usage size of the buffer to detect what data can
be grouped together.
Pull Request: https://projects.blender.org/blender/blender/pulls/146958
59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
/* SPDX-FileCopyrightText: 2022 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "BLI_sys_types.h"
|
|
|
|
namespace blender::gpu {
|
|
|
|
class StorageBuf;
|
|
class VertBuf;
|
|
|
|
#ifndef NDEBUG
|
|
# define DEBUG_NAME_LEN 64
|
|
#else
|
|
# define DEBUG_NAME_LEN 8
|
|
#endif
|
|
|
|
/**
|
|
* Implementation of Storage Buffers.
|
|
* Base class which is then specialized for each implementation (GL, VK, ...).
|
|
*/
|
|
class StorageBuf {
|
|
protected:
|
|
/** Data size in bytes. Doesn't need to match actual allocation size due to alignment rules. */
|
|
size_t size_in_bytes_ = -1;
|
|
size_t usage_size_in_bytes_ = -1;
|
|
/** Continuous memory block to copy to GPU. This data is owned by the StorageBuf. */
|
|
void *data_ = nullptr;
|
|
/** Debugging name */
|
|
char name_[DEBUG_NAME_LEN] = {};
|
|
|
|
public:
|
|
StorageBuf(size_t size, const char *name);
|
|
virtual ~StorageBuf();
|
|
void usage_size_set(size_t size);
|
|
size_t usage_size_get() const
|
|
{
|
|
return usage_size_in_bytes_;
|
|
}
|
|
virtual void update(const void *data) = 0;
|
|
virtual void bind(int slot) = 0;
|
|
virtual void unbind() = 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;
|
|
virtual void async_flush_to_host() = 0;
|
|
virtual void sync_as_indirect_buffer() = 0;
|
|
};
|
|
|
|
#undef DEBUG_NAME_LEN
|
|
|
|
} // namespace blender::gpu
|