2022-10-31 16:01:02 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
2023-02-22 10:16:42 +01:00
|
|
|
* Copyright 2022 Blender Foundation */
|
2022-10-31 16:01:02 +01:00
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup gpu
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "vk_batch.hh"
|
|
|
|
|
2023-05-11 13:01:56 +02:00
|
|
|
#include "vk_context.hh"
|
|
|
|
#include "vk_index_buffer.hh"
|
|
|
|
#include "vk_vertex_attribute_object.hh"
|
|
|
|
#include "vk_vertex_buffer.hh"
|
|
|
|
|
2022-10-31 16:01:02 +01:00
|
|
|
namespace blender::gpu {
|
|
|
|
|
2023-05-11 13:01:56 +02:00
|
|
|
void VKBatch::draw(int vertex_first, int vertex_count, int instance_first, int instance_count)
|
|
|
|
{
|
|
|
|
/* Currently the pipeline is rebuild on each draw command. Clearing the dirty flag for
|
|
|
|
* consistency with the internals of GPU module. */
|
|
|
|
flag &= ~GPU_BATCH_DIRTY;
|
|
|
|
|
|
|
|
/* Finalize graphics pipeline */
|
|
|
|
VKContext &context = *VKContext::get();
|
|
|
|
context.state_manager->apply_state();
|
|
|
|
VKVertexAttributeObject vao;
|
|
|
|
vao.update_bindings(context, *this);
|
|
|
|
context.bind_graphics_pipeline(prim_type, vao);
|
|
|
|
|
|
|
|
/* Bind geometry resources. */
|
|
|
|
vao.bind(context);
|
|
|
|
VKIndexBuffer *index_buffer = index_buffer_get();
|
|
|
|
const bool draw_indexed = index_buffer != nullptr;
|
|
|
|
if (draw_indexed) {
|
|
|
|
index_buffer->upload_data();
|
|
|
|
index_buffer->bind(context);
|
2023-05-12 01:00:26 +02:00
|
|
|
context.command_buffer_get().draw(index_buffer->index_len_get(),
|
|
|
|
instance_count,
|
|
|
|
index_buffer->index_start_get(),
|
|
|
|
vertex_first,
|
|
|
|
instance_first);
|
2023-05-11 13:01:56 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
context.command_buffer_get().draw(vertex_first, vertex_count, instance_first, instance_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.command_buffer_get().submit();
|
|
|
|
}
|
2022-10-31 16:01:02 +01:00
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
void VKBatch::draw_indirect(GPUStorageBuf * /*indirect_buf*/, intptr_t /*offset*/) {}
|
2022-10-31 16:01:02 +01:00
|
|
|
|
|
|
|
void VKBatch::multi_draw_indirect(GPUStorageBuf * /*indirect_buf*/,
|
|
|
|
int /*count*/,
|
|
|
|
intptr_t /*offset*/,
|
|
|
|
intptr_t /*stride*/)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-05-11 13:01:56 +02:00
|
|
|
VKVertexBuffer *VKBatch::vertex_buffer_get(int index)
|
|
|
|
{
|
|
|
|
return unwrap(verts_(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
VKVertexBuffer *VKBatch::instance_buffer_get(int index)
|
|
|
|
{
|
|
|
|
return unwrap(inst_(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
VKIndexBuffer *VKBatch::index_buffer_get()
|
|
|
|
{
|
|
|
|
return unwrap(unwrap(elem));
|
|
|
|
}
|
|
|
|
|
2023-01-31 05:49:04 +01:00
|
|
|
} // namespace blender::gpu
|