28 "VKImmediate::deinit must be called before destruction.");
30 "VKImmediate::deinit must be called before destruction");
35 while (!recycling_buffers_.is_empty()) {
36 std::unique_ptr<VKBuffer> buffer = recycling_buffers_.pop_last();
37 buffer->free_immediately(device);
40 while (!active_buffers_.is_empty()) {
41 std::unique_ptr<VKBuffer> buffer = active_buffers_.pop_last();
42 buffer->free_immediately(device);
51 const size_t bytes_needed =
vertex_buffer_size(&vertex_format_converter.device_format_get(),
53 VKBuffer &buffer = ensure_space(bytes_needed);
54 current_subbuffer_len_ = bytes_needed;
57 return data + buffer_offset_;
67 if (vertex_format_converter.needs_conversion()) {
71 uchar *
data =
static_cast<uchar *
>(active_buffers_.last()->mapped_memory_get()) +
79 vertex_attributes_.update_bindings(*
this);
80 context.active_framebuffer_get()->rendering_ensure(context);
84 draw.node_data.instance_count = 1;
85 draw.node_data.first_vertex = 0;
86 draw.node_data.first_instance = 0;
87 vertex_attributes_.bind(
draw.node_data.vertex_buffers);
88 context.update_pipeline_data(
prim_type, vertex_attributes_,
draw.node_data.pipeline_data);
90 context.render_graph.add_node(
draw);
92 buffer_offset_ += current_subbuffer_len_;
93 current_subbuffer_len_ = 0;
94 vertex_format_converter.reset();
103VkDeviceSize VKImmediate::buffer_bytes_free()
105 return active_buffers_.
last()->size_in_bytes() - buffer_offset_;
113VKBuffer &VKImmediate::ensure_space(
size_t bytes_needed)
116 if (!active_buffers_.
is_empty() && buffer_bytes_free() >= bytes_needed) {
117 return *active_buffers_.
last();
121 if (!recycling_buffers_.
is_empty() && recycling_buffers_.
last()->size_in_bytes() >= bytes_needed)
126 return *active_buffers_.
last();
130 CLOG_INFO(&
LOG, 2,
"Allocate buffer (size=%d)",
int(alloc_size));
132 active_buffers_.append(std::make_unique<VKBuffer>());
133 VKBuffer &
result = *active_buffers_.last();
136 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
144 if (!recycling_buffers_.is_empty()) {
145 CLOG_INFO(&
LOG, 2,
"Discarding %d unused buffers",
int(recycling_buffers_.size()));
147 recycling_buffers_.clear();
148 recycling_buffers_ = std::move(active_buffers_);
#define BLI_assert_msg(a, msg)
#define CLOG_INFO(clg_ref, level,...)
void append(const T &value)
const T & last(const int64_t n=0) const
void * mapped_memory_get() const
const VKWorkarounds & workarounds_get() const
VKDrawCreateInfo CreateInfo
MINLINE unsigned long long max_ulul(unsigned long long a, unsigned long long b)
void object_label(GLenum type, GLuint object, const char *name)
static Context * unwrap(GPUContext *ctx)
static VkDeviceSize new_buffer_size(size_t sub_buffer_size)
constexpr size_t DEFAULT_INTERNAL_BUFFER_SIZE