Vulkan: Remove render graph switch
As render graph is now the default, we can remove the render graph switch. This allows us to cleanup unused functions and classes. Pull Request: https://projects.blender.org/blender/blender/pulls/123219
This commit is contained in:
@@ -140,22 +140,13 @@ void VKBackend::samplers_update()
|
||||
void VKBackend::compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len)
|
||||
{
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
render_graph::VKResourceAccessInfo &resources = context.update_and_get_access_info();
|
||||
render_graph::VKDispatchNode::CreateInfo dispatch_info(resources);
|
||||
context.update_pipeline_data(dispatch_info.dispatch_node.pipeline_data);
|
||||
dispatch_info.dispatch_node.group_count_x = groups_x_len;
|
||||
dispatch_info.dispatch_node.group_count_y = groups_y_len;
|
||||
dispatch_info.dispatch_node.group_count_z = groups_z_len;
|
||||
context.render_graph.add_node(dispatch_info);
|
||||
}
|
||||
else {
|
||||
render_graph::VKResourceAccessInfo resource_access_info = {};
|
||||
context.state_manager_get().apply_bindings(context, resource_access_info);
|
||||
context.bind_compute_pipeline();
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.dispatch(groups_x_len, groups_y_len, groups_z_len);
|
||||
}
|
||||
render_graph::VKResourceAccessInfo &resources = context.update_and_get_access_info();
|
||||
render_graph::VKDispatchNode::CreateInfo dispatch_info(resources);
|
||||
context.update_pipeline_data(dispatch_info.dispatch_node.pipeline_data);
|
||||
dispatch_info.dispatch_node.group_count_x = groups_x_len;
|
||||
dispatch_info.dispatch_node.group_count_y = groups_y_len;
|
||||
dispatch_info.dispatch_node.group_count_z = groups_z_len;
|
||||
context.render_graph.add_node(dispatch_info);
|
||||
}
|
||||
|
||||
void VKBackend::compute_dispatch_indirect(StorageBuf *indirect_buf)
|
||||
@@ -163,21 +154,12 @@ void VKBackend::compute_dispatch_indirect(StorageBuf *indirect_buf)
|
||||
BLI_assert(indirect_buf);
|
||||
VKContext &context = *VKContext::get();
|
||||
VKStorageBuffer &indirect_buffer = *unwrap(indirect_buf);
|
||||
if (use_render_graph) {
|
||||
render_graph::VKResourceAccessInfo &resources = context.update_and_get_access_info();
|
||||
render_graph::VKDispatchIndirectNode::CreateInfo dispatch_indirect_info(resources);
|
||||
context.update_pipeline_data(dispatch_indirect_info.dispatch_indirect_node.pipeline_data);
|
||||
dispatch_indirect_info.dispatch_indirect_node.buffer = indirect_buffer.vk_handle();
|
||||
dispatch_indirect_info.dispatch_indirect_node.offset = 0;
|
||||
context.render_graph.add_node(dispatch_indirect_info);
|
||||
}
|
||||
else {
|
||||
render_graph::VKResourceAccessInfo resource_access_info = {};
|
||||
context.state_manager_get().apply_bindings(context, resource_access_info);
|
||||
context.bind_compute_pipeline();
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.dispatch(indirect_buffer);
|
||||
}
|
||||
render_graph::VKResourceAccessInfo &resources = context.update_and_get_access_info();
|
||||
render_graph::VKDispatchIndirectNode::CreateInfo dispatch_indirect_info(resources);
|
||||
context.update_pipeline_data(dispatch_indirect_info.dispatch_indirect_node.pipeline_data);
|
||||
dispatch_indirect_info.dispatch_indirect_node.buffer = indirect_buffer.vk_handle();
|
||||
dispatch_indirect_info.dispatch_indirect_node.offset = 0;
|
||||
context.render_graph.add_node(dispatch_indirect_info);
|
||||
}
|
||||
|
||||
Context *VKBackend::context_alloc(void *ghost_window, void *ghost_context)
|
||||
|
||||
@@ -51,70 +51,48 @@ void VKBatch::draw_setup()
|
||||
void VKBatch::draw(int vertex_first, int vertex_count, int instance_first, int instance_count)
|
||||
{
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
render_graph::VKResourceAccessInfo &resource_access_info =
|
||||
context.update_and_get_access_info();
|
||||
VKStateManager &state_manager = context.state_manager_get();
|
||||
state_manager.apply_state();
|
||||
render_graph::VKResourceAccessInfo &resource_access_info = context.update_and_get_access_info();
|
||||
VKStateManager &state_manager = context.state_manager_get();
|
||||
state_manager.apply_state();
|
||||
|
||||
VKVertexAttributeObject vao;
|
||||
vao.update_bindings(context, *this);
|
||||
VKVertexAttributeObject vao;
|
||||
vao.update_bindings(context, *this);
|
||||
|
||||
VKIndexBuffer *index_buffer = index_buffer_get();
|
||||
const bool draw_indexed = index_buffer != nullptr;
|
||||
VKIndexBuffer *index_buffer = index_buffer_get();
|
||||
const bool draw_indexed = index_buffer != nullptr;
|
||||
|
||||
/* Upload geometry */
|
||||
vao.ensure_vbos_uploaded();
|
||||
if (draw_indexed) {
|
||||
index_buffer->upload_data();
|
||||
}
|
||||
context.active_framebuffer_get()->rendering_ensure(context);
|
||||
/* Upload geometry */
|
||||
vao.ensure_vbos_uploaded();
|
||||
if (draw_indexed) {
|
||||
index_buffer->upload_data();
|
||||
}
|
||||
context.active_framebuffer_get()->rendering_ensure(context);
|
||||
|
||||
if (draw_indexed) {
|
||||
render_graph::VKDrawIndexedNode::CreateInfo draw_indexed(resource_access_info);
|
||||
draw_indexed.node_data.index_count = vertex_count;
|
||||
draw_indexed.node_data.instance_count = instance_count;
|
||||
draw_indexed.node_data.first_index = vertex_first;
|
||||
draw_indexed.node_data.vertex_offset = index_buffer->index_start_get();
|
||||
draw_indexed.node_data.first_instance = instance_first;
|
||||
if (draw_indexed) {
|
||||
render_graph::VKDrawIndexedNode::CreateInfo draw_indexed(resource_access_info);
|
||||
draw_indexed.node_data.index_count = vertex_count;
|
||||
draw_indexed.node_data.instance_count = instance_count;
|
||||
draw_indexed.node_data.first_index = vertex_first;
|
||||
draw_indexed.node_data.vertex_offset = index_buffer->index_start_get();
|
||||
draw_indexed.node_data.first_instance = instance_first;
|
||||
|
||||
draw_indexed.node_data.index_buffer.buffer = index_buffer->vk_handle();
|
||||
draw_indexed.node_data.index_buffer.index_type = index_buffer->vk_index_type();
|
||||
vao.bind(draw_indexed.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vao, draw_indexed.node_data.pipeline_data);
|
||||
draw_indexed.node_data.index_buffer.buffer = index_buffer->vk_handle();
|
||||
draw_indexed.node_data.index_buffer.index_type = index_buffer->vk_index_type();
|
||||
vao.bind(draw_indexed.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vao, draw_indexed.node_data.pipeline_data);
|
||||
|
||||
context.render_graph.add_node(draw_indexed);
|
||||
}
|
||||
else {
|
||||
render_graph::VKDrawNode::CreateInfo draw(resource_access_info);
|
||||
draw.node_data.vertex_count = vertex_count;
|
||||
draw.node_data.instance_count = instance_count;
|
||||
draw.node_data.first_vertex = vertex_first;
|
||||
draw.node_data.first_instance = instance_first;
|
||||
vao.bind(draw.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vao, draw.node_data.pipeline_data);
|
||||
|
||||
context.render_graph.add_node(draw);
|
||||
}
|
||||
context.render_graph.add_node(draw_indexed);
|
||||
}
|
||||
else {
|
||||
draw_setup();
|
||||
render_graph::VKDrawNode::CreateInfo draw(resource_access_info);
|
||||
draw.node_data.vertex_count = vertex_count;
|
||||
draw.node_data.instance_count = instance_count;
|
||||
draw.node_data.first_vertex = vertex_first;
|
||||
draw.node_data.first_instance = instance_first;
|
||||
vao.bind(draw.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vao, draw.node_data.pipeline_data);
|
||||
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
VKIndexBuffer *index_buffer = index_buffer_get();
|
||||
const bool draw_indexed = index_buffer != nullptr;
|
||||
if (draw_indexed) {
|
||||
command_buffers.draw_indexed(vertex_count,
|
||||
instance_count,
|
||||
vertex_first,
|
||||
index_buffer->index_start_get(),
|
||||
instance_first);
|
||||
}
|
||||
else {
|
||||
command_buffers.draw(vertex_first, vertex_count, instance_first, instance_count);
|
||||
}
|
||||
|
||||
command_buffers.submit();
|
||||
context.render_graph.add_node(draw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,66 +116,48 @@ void VKBatch::multi_draw_indirect(const VkBuffer indirect_buffer,
|
||||
const intptr_t stride)
|
||||
{
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
render_graph::VKResourceAccessInfo &resource_access_info =
|
||||
context.update_and_get_access_info();
|
||||
VKStateManager &state_manager = context.state_manager_get();
|
||||
state_manager.apply_state();
|
||||
render_graph::VKResourceAccessInfo &resource_access_info = context.update_and_get_access_info();
|
||||
VKStateManager &state_manager = context.state_manager_get();
|
||||
state_manager.apply_state();
|
||||
|
||||
VKVertexAttributeObject vao;
|
||||
vao.update_bindings(context, *this);
|
||||
VKVertexAttributeObject vao;
|
||||
vao.update_bindings(context, *this);
|
||||
|
||||
VKIndexBuffer *index_buffer = index_buffer_get();
|
||||
const bool draw_indexed = index_buffer != nullptr;
|
||||
VKIndexBuffer *index_buffer = index_buffer_get();
|
||||
const bool draw_indexed = index_buffer != nullptr;
|
||||
|
||||
/* Upload geometry */
|
||||
vao.ensure_vbos_uploaded();
|
||||
if (draw_indexed) {
|
||||
index_buffer->upload_data();
|
||||
}
|
||||
context.active_framebuffer_get()->rendering_ensure(context);
|
||||
/* Upload geometry */
|
||||
vao.ensure_vbos_uploaded();
|
||||
if (draw_indexed) {
|
||||
index_buffer->upload_data();
|
||||
}
|
||||
context.active_framebuffer_get()->rendering_ensure(context);
|
||||
|
||||
if (draw_indexed) {
|
||||
render_graph::VKDrawIndexedIndirectNode::CreateInfo draw_indexed_indirect(
|
||||
resource_access_info);
|
||||
draw_indexed_indirect.node_data.indirect_buffer = indirect_buffer;
|
||||
draw_indexed_indirect.node_data.offset = offset;
|
||||
draw_indexed_indirect.node_data.draw_count = count;
|
||||
draw_indexed_indirect.node_data.stride = stride;
|
||||
if (draw_indexed) {
|
||||
render_graph::VKDrawIndexedIndirectNode::CreateInfo draw_indexed_indirect(
|
||||
resource_access_info);
|
||||
draw_indexed_indirect.node_data.indirect_buffer = indirect_buffer;
|
||||
draw_indexed_indirect.node_data.offset = offset;
|
||||
draw_indexed_indirect.node_data.draw_count = count;
|
||||
draw_indexed_indirect.node_data.stride = stride;
|
||||
|
||||
draw_indexed_indirect.node_data.index_buffer.buffer = index_buffer->vk_handle();
|
||||
draw_indexed_indirect.node_data.index_buffer.index_type = index_buffer->vk_index_type();
|
||||
vao.bind(draw_indexed_indirect.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vao, draw_indexed_indirect.node_data.pipeline_data);
|
||||
draw_indexed_indirect.node_data.index_buffer.buffer = index_buffer->vk_handle();
|
||||
draw_indexed_indirect.node_data.index_buffer.index_type = index_buffer->vk_index_type();
|
||||
vao.bind(draw_indexed_indirect.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vao, draw_indexed_indirect.node_data.pipeline_data);
|
||||
|
||||
context.render_graph.add_node(draw_indexed_indirect);
|
||||
}
|
||||
else {
|
||||
render_graph::VKDrawIndirectNode::CreateInfo draw(resource_access_info);
|
||||
draw.node_data.indirect_buffer = indirect_buffer;
|
||||
draw.node_data.offset = offset;
|
||||
draw.node_data.draw_count = count;
|
||||
draw.node_data.stride = stride;
|
||||
vao.bind(draw.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vao, draw.node_data.pipeline_data);
|
||||
|
||||
context.render_graph.add_node(draw);
|
||||
}
|
||||
context.render_graph.add_node(draw_indexed_indirect);
|
||||
}
|
||||
else {
|
||||
draw_setup();
|
||||
render_graph::VKDrawIndirectNode::CreateInfo draw(resource_access_info);
|
||||
draw.node_data.indirect_buffer = indirect_buffer;
|
||||
draw.node_data.offset = offset;
|
||||
draw.node_data.draw_count = count;
|
||||
draw.node_data.stride = stride;
|
||||
vao.bind(draw.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vao, draw.node_data.pipeline_data);
|
||||
|
||||
VKIndexBuffer *index_buffer = index_buffer_get();
|
||||
const bool draw_indexed = index_buffer != nullptr;
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
if (draw_indexed) {
|
||||
command_buffers.draw_indexed_indirect(indirect_buffer, offset, count, stride);
|
||||
}
|
||||
else {
|
||||
command_buffers.draw_indirect(indirect_buffer, offset, count, stride);
|
||||
}
|
||||
|
||||
command_buffers.submit();
|
||||
context.render_graph.add_node(draw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,9 +92,7 @@ bool VKBuffer::create(int64_t size_in_bytes,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (use_render_graph) {
|
||||
device.resources.add_buffer(vk_buffer_);
|
||||
}
|
||||
device.resources.add_buffer(vk_buffer_);
|
||||
|
||||
if (is_host_visible) {
|
||||
return map();
|
||||
@@ -122,22 +120,13 @@ void VKBuffer::clear(VKContext &context, uint32_t clear_value)
|
||||
fill_buffer.vk_buffer = vk_buffer_;
|
||||
fill_buffer.data = clear_value;
|
||||
fill_buffer.size = size_in_bytes_;
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(fill_buffer);
|
||||
}
|
||||
else {
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.fill(*this, fill_buffer.data);
|
||||
}
|
||||
context.render_graph.add_node(fill_buffer);
|
||||
}
|
||||
|
||||
void VKBuffer::read(VKContext &context, void *data) const
|
||||
{
|
||||
BLI_assert_msg(is_mapped(), "Cannot read a non-mapped buffer.");
|
||||
if (use_render_graph) {
|
||||
context.render_graph.submit_buffer_for_read(vk_buffer_);
|
||||
}
|
||||
|
||||
context.render_graph.submit_buffer_for_read(vk_buffer_);
|
||||
memcpy(data, mapped_memory_, size_in_bytes_);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,15 +24,6 @@
|
||||
|
||||
namespace blender::gpu {
|
||||
|
||||
/**
|
||||
* The Vulkan backend is currently migrating to a render graph approach. This requires commands to
|
||||
* be recorded in a different way. During the migration the backend will mist likely crash. With
|
||||
* the `use_render_graph` constant we can switch back to the not render graph implementation.
|
||||
* During development of the render graph this is set to true. But when committing to main this
|
||||
* must be set to false.
|
||||
*/
|
||||
static constexpr bool use_render_graph = true;
|
||||
|
||||
/**
|
||||
* Based on the usage of an Image View a different image view type should be created.
|
||||
*
|
||||
|
||||
@@ -46,9 +46,7 @@ VKContext::~VKContext()
|
||||
GPU_texture_free(surface_texture_);
|
||||
surface_texture_ = nullptr;
|
||||
}
|
||||
if (use_render_graph) {
|
||||
render_graph.free_data();
|
||||
}
|
||||
render_graph.free_data();
|
||||
VKBackend::get().device_.context_unregister(*this);
|
||||
|
||||
delete imm;
|
||||
@@ -118,36 +116,21 @@ void VKContext::activate()
|
||||
|
||||
void VKContext::deactivate()
|
||||
{
|
||||
if (use_render_graph) {
|
||||
/* Draw manager draws in a different context than the rest of the UI. Although run from the
|
||||
* same thread. Commands inside the rendergraph need to be submitted into the device queue. */
|
||||
flush_render_graph();
|
||||
}
|
||||
/* Draw manager draws in a different context than the rest of the UI. Although run from the
|
||||
* same thread. Commands inside the rendergraph need to be submitted into the device queue. */
|
||||
flush_render_graph();
|
||||
immDeactivate();
|
||||
is_active_ = false;
|
||||
}
|
||||
|
||||
void VKContext::begin_frame() {}
|
||||
|
||||
void VKContext::end_frame()
|
||||
{
|
||||
if (!use_render_graph) {
|
||||
VKDevice &device = VKBackend::get().device_get();
|
||||
device.destroy_discarded_resources();
|
||||
}
|
||||
}
|
||||
void VKContext::end_frame() {}
|
||||
|
||||
void VKContext::flush() {}
|
||||
|
||||
void VKContext::flush()
|
||||
{
|
||||
if (use_render_graph) {
|
||||
}
|
||||
else {
|
||||
command_buffers_.submit();
|
||||
}
|
||||
}
|
||||
void VKContext::flush_render_graph()
|
||||
{
|
||||
BLI_assert(use_render_graph);
|
||||
if (has_active_framebuffer()) {
|
||||
VKFrameBuffer &framebuffer = *active_framebuffer_get();
|
||||
if (framebuffer.is_rendering()) {
|
||||
@@ -157,14 +140,7 @@ void VKContext::flush_render_graph()
|
||||
render_graph.submit();
|
||||
}
|
||||
|
||||
void VKContext::finish()
|
||||
{
|
||||
if (use_render_graph) {
|
||||
}
|
||||
else {
|
||||
command_buffers_.finish();
|
||||
}
|
||||
}
|
||||
void VKContext::finish() {}
|
||||
|
||||
void VKContext::memory_statistics_get(int *r_total_mem_kb, int *r_free_mem_kb)
|
||||
{
|
||||
@@ -207,12 +183,7 @@ void VKContext::activate_framebuffer(VKFrameBuffer &framebuffer)
|
||||
active_fb = &framebuffer;
|
||||
framebuffer.update_size();
|
||||
framebuffer.update_srgb();
|
||||
if (use_render_graph) {
|
||||
framebuffer.rendering_reset();
|
||||
}
|
||||
else {
|
||||
command_buffers_get().begin_render_pass(framebuffer);
|
||||
}
|
||||
framebuffer.rendering_reset();
|
||||
}
|
||||
|
||||
VKFrameBuffer *VKContext::active_framebuffer_get() const
|
||||
@@ -229,12 +200,7 @@ void VKContext::deactivate_framebuffer()
|
||||
{
|
||||
VKFrameBuffer *framebuffer = active_framebuffer_get();
|
||||
BLI_assert(framebuffer != nullptr);
|
||||
if (use_render_graph) {
|
||||
framebuffer->rendering_end(*this);
|
||||
}
|
||||
else {
|
||||
command_buffers_get().end_render_pass(*framebuffer);
|
||||
}
|
||||
framebuffer->rendering_end(*this);
|
||||
active_fb = nullptr;
|
||||
}
|
||||
|
||||
@@ -396,44 +362,20 @@ void VKContext::swap_buffers_pre_handler(const GHOST_VulkanSwapChainData &swap_c
|
||||
region.dstSubresource.baseArrayLayer = 0;
|
||||
region.dstSubresource.layerCount = 1;
|
||||
|
||||
if (use_render_graph) {
|
||||
/* Swap chain commands are CPU synchronized at this moment, allowing to temporary add the swap
|
||||
* chain image as device resources. When we move towards GPU swap chain synchronization we need
|
||||
* to keep track of the swap chain image between frames. */
|
||||
VKDevice &device = VKBackend::get().device_get();
|
||||
device.resources.add_image(swap_chain_data.image,
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||
render_graph::ResourceOwner::SWAP_CHAIN);
|
||||
/* Swap chain commands are CPU synchronized at this moment, allowing to temporary add the swap
|
||||
* chain image as device resources. When we move towards GPU swap chain synchronization we need
|
||||
* to keep track of the swap chain image between frames. */
|
||||
VKDevice &device = VKBackend::get().device_get();
|
||||
device.resources.add_image(swap_chain_data.image,
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||
render_graph::ResourceOwner::SWAP_CHAIN);
|
||||
|
||||
framebuffer.rendering_end(*this);
|
||||
render_graph.add_node(blit_image);
|
||||
render_graph.submit_for_present(swap_chain_data.image);
|
||||
framebuffer.rendering_end(*this);
|
||||
render_graph.add_node(blit_image);
|
||||
render_graph.submit_for_present(swap_chain_data.image);
|
||||
|
||||
device.resources.remove_image(swap_chain_data.image);
|
||||
device.destroy_discarded_resources();
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* Ensure no graphics/compute commands are scheduled. They could use the back buffer, which
|
||||
* layout is altered here.
|
||||
*/
|
||||
command_buffers_get().submit();
|
||||
|
||||
VKTexture wrapper("display_texture");
|
||||
wrapper.init(swap_chain_data.image,
|
||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||
to_gpu_format(swap_chain_data.format));
|
||||
wrapper.layout_ensure(*this, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
framebuffer.color_attachment_layout_ensure(*this, 0, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
|
||||
command_buffers_get().blit(wrapper,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
*color_attachment,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
Span<VkImageBlit>(®ion, 1));
|
||||
wrapper.layout_ensure(*this, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||
command_buffers_get().submit();
|
||||
}
|
||||
device.resources.remove_image(swap_chain_data.image);
|
||||
device.destroy_discarded_resources();
|
||||
}
|
||||
|
||||
void VKContext::swap_buffers_post_handler()
|
||||
|
||||
@@ -21,31 +21,17 @@ static CLG_LogRef LOG = {"gpu.vulkan"};
|
||||
namespace blender::gpu {
|
||||
void VKContext::debug_group_begin(const char *name, int)
|
||||
{
|
||||
if (use_render_graph) {
|
||||
render_graph.debug_group_begin(name);
|
||||
}
|
||||
else {
|
||||
const VKDevice &device = VKBackend::get().device_get();
|
||||
debug::push_marker(device, name);
|
||||
}
|
||||
render_graph.debug_group_begin(name);
|
||||
}
|
||||
|
||||
void VKContext::debug_group_end()
|
||||
{
|
||||
if (use_render_graph) {
|
||||
render_graph.debug_group_end();
|
||||
}
|
||||
else {
|
||||
const VKDevice &device = VKBackend::get().device_get();
|
||||
debug::pop_marker(device);
|
||||
}
|
||||
render_graph.debug_group_end();
|
||||
}
|
||||
|
||||
bool VKContext::debug_capture_begin(const char *title)
|
||||
{
|
||||
if (use_render_graph) {
|
||||
flush_render_graph();
|
||||
}
|
||||
flush_render_graph();
|
||||
return VKBackend::get().debug_capture_begin(title);
|
||||
}
|
||||
|
||||
@@ -65,9 +51,7 @@ bool VKBackend::debug_capture_begin(const char *title)
|
||||
|
||||
void VKContext::debug_capture_end()
|
||||
{
|
||||
if (use_render_graph) {
|
||||
flush_render_graph();
|
||||
}
|
||||
flush_render_graph();
|
||||
VKBackend::get().debug_capture_end();
|
||||
}
|
||||
|
||||
|
||||
@@ -182,25 +182,13 @@ void VKDescriptorSetTracker::update(VKContext &context)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (use_render_graph) {
|
||||
/* TODO: Based on the actual usage we should use
|
||||
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL. */
|
||||
VkDescriptorImageInfo image_info = {};
|
||||
image_info.sampler = binding.vk_sampler;
|
||||
image_info.imageView = binding.texture->image_view_get().vk_handle();
|
||||
image_info.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
image_infos.append(image_info);
|
||||
}
|
||||
else {
|
||||
/* TODO: Based on the actual usage we should use
|
||||
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL/VK_IMAGE_LAYOUT_GENERAL. */
|
||||
binding.texture->layout_ensure(context, VK_IMAGE_LAYOUT_GENERAL);
|
||||
VkDescriptorImageInfo image_info = {};
|
||||
image_info.sampler = binding.vk_sampler;
|
||||
image_info.imageView = binding.texture->image_view_get().vk_handle();
|
||||
image_info.imageLayout = binding.texture->current_layout_get();
|
||||
image_infos.append(image_info);
|
||||
}
|
||||
/* TODO: Based on the actual usage we should use
|
||||
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL. */
|
||||
VkDescriptorImageInfo image_info = {};
|
||||
image_info.sampler = binding.vk_sampler;
|
||||
image_info.imageView = binding.texture->image_view_get().vk_handle();
|
||||
image_info.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
image_infos.append(image_info);
|
||||
|
||||
VkWriteDescriptorSet write_descriptor = {};
|
||||
write_descriptor.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
|
||||
@@ -386,17 +386,13 @@ void VKDevice::destroy_discarded_resources()
|
||||
|
||||
while (!discarded_images_.is_empty()) {
|
||||
std::pair<VkImage, VmaAllocation> image_allocation = discarded_images_.pop_last();
|
||||
if (use_render_graph) {
|
||||
resources.remove_image(image_allocation.first);
|
||||
}
|
||||
resources.remove_image(image_allocation.first);
|
||||
vmaDestroyImage(mem_allocator_get(), image_allocation.first, image_allocation.second);
|
||||
}
|
||||
|
||||
while (!discarded_buffers_.is_empty()) {
|
||||
std::pair<VkBuffer, VmaAllocation> buffer_allocation = discarded_buffers_.pop_last();
|
||||
if (use_render_graph) {
|
||||
resources.remove_buffer(buffer_allocation.first);
|
||||
}
|
||||
resources.remove_buffer(buffer_allocation.first);
|
||||
vmaDestroyBuffer(mem_allocator_get(), buffer_allocation.first, buffer_allocation.second);
|
||||
}
|
||||
|
||||
|
||||
@@ -155,16 +155,8 @@ void VKFrameBuffer::build_clear_attachments_color(
|
||||
void VKFrameBuffer::clear(render_graph::VKClearAttachmentsNode::CreateInfo &clear_attachments)
|
||||
{
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
rendering_ensure(context);
|
||||
context.render_graph.add_node(clear_attachments);
|
||||
}
|
||||
else {
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.clear(
|
||||
Span<VkClearAttachment>(clear_attachments.attachments, clear_attachments.attachment_count),
|
||||
Span<VkClearRect>(&clear_attachments.vk_clear_rect, 1));
|
||||
}
|
||||
rendering_ensure(context);
|
||||
context.render_graph.add_node(clear_attachments);
|
||||
}
|
||||
|
||||
void VKFrameBuffer::clear(const eGPUFrameBufferBits buffers,
|
||||
@@ -422,12 +414,7 @@ static void blit_aspect(VKContext &context,
|
||||
dst_texture.height_get());
|
||||
region.dstOffsets[1].z = 1;
|
||||
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(blit_image);
|
||||
}
|
||||
else {
|
||||
context.command_buffers_get().blit(dst_texture, src_texture, Span<VkImageBlit>(®ion, 1));
|
||||
}
|
||||
context.render_graph.add_node(blit_image);
|
||||
}
|
||||
|
||||
void VKFrameBuffer::blit_to(eGPUFrameBufferBits planes,
|
||||
@@ -456,12 +443,6 @@ void VKFrameBuffer::blit_to(eGPUFrameBufferBits planes,
|
||||
if (src_attachment.tex && dst_attachment.tex) {
|
||||
VKTexture &src_texture = *unwrap(unwrap(src_attachment.tex));
|
||||
VKTexture &dst_texture = *unwrap(unwrap(dst_attachment.tex));
|
||||
if (!use_render_graph) {
|
||||
color_attachment_layout_ensure(context, src_slot, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
dst_framebuffer.color_attachment_layout_ensure(
|
||||
context, dst_slot, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
}
|
||||
|
||||
blit_aspect(context,
|
||||
dst_texture,
|
||||
src_texture,
|
||||
@@ -483,12 +464,6 @@ void VKFrameBuffer::blit_to(eGPUFrameBufferBits planes,
|
||||
if (src_attachment.tex && dst_attachment.tex) {
|
||||
VKTexture &src_texture = *unwrap(unwrap(src_attachment.tex));
|
||||
VKTexture &dst_texture = *unwrap(unwrap(dst_attachment.tex));
|
||||
if (!use_render_graph) {
|
||||
depth_attachment_layout_ensure(context, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
dst_framebuffer.depth_attachment_layout_ensure(context,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
}
|
||||
|
||||
blit_aspect(context,
|
||||
dst_texture,
|
||||
src_texture,
|
||||
|
||||
@@ -53,36 +53,22 @@ void VKImmediate::end()
|
||||
|
||||
VKContext &context = *VKContext::get();
|
||||
BLI_assert(context.shader == unwrap(shader));
|
||||
if (use_render_graph) {
|
||||
render_graph::VKResourceAccessInfo &resource_access_info =
|
||||
context.update_and_get_access_info();
|
||||
VKStateManager &state_manager = context.state_manager_get();
|
||||
state_manager.apply_state();
|
||||
vertex_attributes_.update_bindings(*this);
|
||||
vertex_attributes_.ensure_vbos_uploaded();
|
||||
context.active_framebuffer_get()->rendering_ensure(context);
|
||||
render_graph::VKResourceAccessInfo &resource_access_info = context.update_and_get_access_info();
|
||||
VKStateManager &state_manager = context.state_manager_get();
|
||||
state_manager.apply_state();
|
||||
vertex_attributes_.update_bindings(*this);
|
||||
vertex_attributes_.ensure_vbos_uploaded();
|
||||
context.active_framebuffer_get()->rendering_ensure(context);
|
||||
|
||||
render_graph::VKDrawNode::CreateInfo draw(resource_access_info);
|
||||
draw.node_data.vertex_count = vertex_idx;
|
||||
draw.node_data.instance_count = 1;
|
||||
draw.node_data.first_vertex = 0;
|
||||
draw.node_data.first_instance = 0;
|
||||
vertex_attributes_.bind(draw.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vertex_attributes_, draw.node_data.pipeline_data);
|
||||
render_graph::VKDrawNode::CreateInfo draw(resource_access_info);
|
||||
draw.node_data.vertex_count = vertex_idx;
|
||||
draw.node_data.instance_count = 1;
|
||||
draw.node_data.first_vertex = 0;
|
||||
draw.node_data.first_instance = 0;
|
||||
vertex_attributes_.bind(draw.node_data.vertex_buffers);
|
||||
context.update_pipeline_data(prim_type, vertex_attributes_, draw.node_data.pipeline_data);
|
||||
|
||||
context.render_graph.add_node(draw);
|
||||
}
|
||||
else {
|
||||
VKStateManager &state_manager = context.state_manager_get();
|
||||
state_manager.apply_state();
|
||||
render_graph::VKResourceAccessInfo resource_access_info = {};
|
||||
state_manager.apply_bindings(context, resource_access_info);
|
||||
vertex_attributes_.update_bindings(*this);
|
||||
context.bind_graphics_pipeline(prim_type, vertex_attributes_);
|
||||
vertex_attributes_.bind(context);
|
||||
|
||||
context.command_buffers_get().draw(0, vertex_idx, 0, 1);
|
||||
}
|
||||
context.render_graph.add_node(draw);
|
||||
|
||||
buffer_offset_ += current_subbuffer_len_;
|
||||
current_subbuffer_len_ = 0;
|
||||
|
||||
@@ -146,7 +146,6 @@ VKPushConstants &VKPushConstants::operator=(VKPushConstants &&other)
|
||||
|
||||
void VKPushConstants::update(VKContext &context)
|
||||
{
|
||||
VKShader *shader = static_cast<VKShader *>(context.shader);
|
||||
VKDescriptorSetTracker &descriptor_set = context.descriptor_set_get();
|
||||
|
||||
switch (layout_get().storage_type_get()) {
|
||||
@@ -154,14 +153,6 @@ void VKPushConstants::update(VKContext &context)
|
||||
break;
|
||||
|
||||
case VKPushConstants::StorageType::PUSH_CONSTANTS:
|
||||
if (!use_render_graph) {
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.push_constants(*this,
|
||||
shader->vk_pipeline_layout,
|
||||
shader->is_graphics_shader() ?
|
||||
VK_SHADER_STAGE_ALL_GRAPHICS :
|
||||
VK_SHADER_STAGE_COMPUTE_BIT);
|
||||
}
|
||||
break;
|
||||
|
||||
case VKPushConstants::StorageType::UNIFORM_BUFFER:
|
||||
|
||||
@@ -672,29 +672,7 @@ bool VKShader::finalize(const shader::ShaderCreateInfo *info)
|
||||
|
||||
push_constants = VKPushConstants(&vk_interface.push_constants_layout_get());
|
||||
|
||||
bool result;
|
||||
if (use_render_graph) {
|
||||
result = true;
|
||||
}
|
||||
else {
|
||||
if (is_graphics_shader()) {
|
||||
BLI_assert((fragment_module_ != VK_NULL_HANDLE && info->tf_type_ == GPU_SHADER_TFB_NONE) ||
|
||||
(fragment_module_ == VK_NULL_HANDLE && info->tf_type_ != GPU_SHADER_TFB_NONE));
|
||||
BLI_assert(compute_module_ == VK_NULL_HANDLE);
|
||||
pipeline_ = VKPipeline::create_graphics_pipeline();
|
||||
result = true;
|
||||
}
|
||||
else {
|
||||
BLI_assert(vertex_module_ == VK_NULL_HANDLE);
|
||||
BLI_assert(geometry_module_ == VK_NULL_HANDLE);
|
||||
BLI_assert(fragment_module_ == VK_NULL_HANDLE);
|
||||
BLI_assert(compute_module_ != VK_NULL_HANDLE);
|
||||
pipeline_ = VKPipeline::create_compute_pipeline(compute_module_, vk_pipeline_layout);
|
||||
result = pipeline_.is_valid();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VKShader::finalize_pipeline_layout(VkDevice vk_device,
|
||||
|
||||
@@ -36,15 +36,7 @@ void VKStagingBuffer::copy_to_device(VKContext &context)
|
||||
copy_buffer.dst_buffer = device_buffer_.vk_handle();
|
||||
copy_buffer.region.size = device_buffer_.size_in_bytes();
|
||||
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(copy_buffer);
|
||||
}
|
||||
else {
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.copy(
|
||||
device_buffer_, copy_buffer.src_buffer, Span<VkBufferCopy>(©_buffer.region, 1));
|
||||
command_buffers.submit();
|
||||
}
|
||||
context.render_graph.add_node(copy_buffer);
|
||||
}
|
||||
|
||||
void VKStagingBuffer::copy_from_device(VKContext &context)
|
||||
@@ -55,15 +47,7 @@ void VKStagingBuffer::copy_from_device(VKContext &context)
|
||||
copy_buffer.dst_buffer = host_buffer_.vk_handle();
|
||||
copy_buffer.region.size = device_buffer_.size_in_bytes();
|
||||
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(copy_buffer);
|
||||
}
|
||||
else {
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.copy(
|
||||
host_buffer_, copy_buffer.src_buffer, Span<VkBufferCopy>(©_buffer.region, 1));
|
||||
command_buffers.submit();
|
||||
}
|
||||
context.render_graph.add_node(copy_buffer);
|
||||
}
|
||||
|
||||
void VKStagingBuffer::free()
|
||||
|
||||
@@ -53,15 +53,7 @@ void VKStateManager::force_state()
|
||||
pipeline.state_manager_get().force_state(state, mutable_state);
|
||||
}
|
||||
|
||||
void VKStateManager::issue_barrier(eGPUBarrier /*barrier_bits*/)
|
||||
{
|
||||
VKContext &context = *VKContext::get();
|
||||
if (!use_render_graph) {
|
||||
/* TODO: Pipeline barriers should be added. We might be able to extract it from
|
||||
* the actual pipeline, later on, but for now we submit the work as barrier. */
|
||||
context.flush();
|
||||
}
|
||||
}
|
||||
void VKStateManager::issue_barrier(eGPUBarrier /*barrier_bits*/) {}
|
||||
|
||||
void VKStateManager::texture_bind(Texture *tex, GPUSamplerState sampler, int unit)
|
||||
{
|
||||
|
||||
@@ -97,15 +97,7 @@ void VKStorageBuffer::copy_sub(VertBuf *src, uint dst_offset, uint src_offset, u
|
||||
copy_buffer.region.size = copy_size;
|
||||
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(copy_buffer);
|
||||
}
|
||||
else {
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.copy(
|
||||
buffer_, copy_buffer.src_buffer, Span<VkBufferCopy>(©_buffer.region, 1));
|
||||
context.flush();
|
||||
}
|
||||
context.render_graph.add_node(copy_buffer);
|
||||
}
|
||||
|
||||
void VKStorageBuffer::async_flush_to_host()
|
||||
@@ -117,10 +109,6 @@ void VKStorageBuffer::read(void *data)
|
||||
{
|
||||
ensure_allocated();
|
||||
VKContext &context = *VKContext::get();
|
||||
if (!use_render_graph) {
|
||||
context.flush();
|
||||
}
|
||||
|
||||
VKStagingBuffer staging_buffer(buffer_, VKStagingBuffer::Direction::DeviceToHost);
|
||||
staging_buffer.copy_from_device(context);
|
||||
staging_buffer.host_buffer_get().read(context, data);
|
||||
|
||||
@@ -68,96 +68,21 @@ void VKTexture::generate_mipmap()
|
||||
}
|
||||
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
render_graph::VKUpdateMipmapsNode::Data update_mipmaps = {};
|
||||
update_mipmaps.vk_image = vk_image_handle();
|
||||
update_mipmaps.l0_size = int3(1);
|
||||
mip_size_get(0, update_mipmaps.l0_size);
|
||||
if (ELEM(this->type_get(), GPU_TEXTURE_1D_ARRAY)) {
|
||||
update_mipmaps.l0_size.y = 1;
|
||||
update_mipmaps.l0_size.z = 1;
|
||||
}
|
||||
else if (ELEM(this->type_get(), GPU_TEXTURE_2D_ARRAY)) {
|
||||
update_mipmaps.l0_size.z = 1;
|
||||
}
|
||||
update_mipmaps.vk_image_aspect = to_vk_image_aspect_flag_bits(device_format_);
|
||||
update_mipmaps.mipmaps = mipmaps_;
|
||||
update_mipmaps.layer_count = vk_layer_count(1);
|
||||
context.render_graph.add_node(update_mipmaps);
|
||||
render_graph::VKUpdateMipmapsNode::Data update_mipmaps = {};
|
||||
update_mipmaps.vk_image = vk_image_handle();
|
||||
update_mipmaps.l0_size = int3(1);
|
||||
mip_size_get(0, update_mipmaps.l0_size);
|
||||
if (ELEM(this->type_get(), GPU_TEXTURE_1D_ARRAY)) {
|
||||
update_mipmaps.l0_size.y = 1;
|
||||
update_mipmaps.l0_size.z = 1;
|
||||
}
|
||||
else {
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.submit();
|
||||
|
||||
layout_ensure(context,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_ACCESS_TRANSFER_READ_BIT);
|
||||
|
||||
for (int src_mipmap : IndexRange(mipmaps_ - 1)) {
|
||||
int dst_mipmap = src_mipmap + 1;
|
||||
int3 src_size(1);
|
||||
int3 dst_size(1);
|
||||
mip_size_get(src_mipmap, src_size);
|
||||
mip_size_get(dst_mipmap, dst_size);
|
||||
|
||||
/* GPU Texture stores the array length in the first unused dimension size.
|
||||
* Vulkan uses layers and the array length should be removed from the dimensions. */
|
||||
if (ELEM(this->type_get(), GPU_TEXTURE_1D_ARRAY)) {
|
||||
src_size.y = 1;
|
||||
src_size.z = 1;
|
||||
dst_size.y = 1;
|
||||
dst_size.z = 1;
|
||||
}
|
||||
if (ELEM(this->type_get(), GPU_TEXTURE_2D_ARRAY)) {
|
||||
src_size.z = 1;
|
||||
dst_size.z = 1;
|
||||
}
|
||||
|
||||
layout_ensure(context,
|
||||
IndexRange(src_mipmap, 1),
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_ACCESS_TRANSFER_READ_BIT);
|
||||
|
||||
VkImageBlit image_blit = {};
|
||||
image_blit.srcOffsets[0] = {0, 0, 0};
|
||||
image_blit.srcOffsets[1] = {src_size.x, src_size.y, src_size.z};
|
||||
image_blit.srcSubresource.aspectMask = to_vk_image_aspect_flag_bits(device_format_);
|
||||
image_blit.srcSubresource.mipLevel = src_mipmap;
|
||||
image_blit.srcSubresource.baseArrayLayer = 0;
|
||||
image_blit.srcSubresource.layerCount = vk_layer_count(1);
|
||||
|
||||
image_blit.dstOffsets[0] = {0, 0, 0};
|
||||
image_blit.dstOffsets[1] = {dst_size.x, dst_size.y, dst_size.z};
|
||||
image_blit.dstSubresource.aspectMask = to_vk_image_aspect_flag_bits(device_format_);
|
||||
image_blit.dstSubresource.mipLevel = dst_mipmap;
|
||||
image_blit.dstSubresource.baseArrayLayer = 0;
|
||||
image_blit.dstSubresource.layerCount = vk_layer_count(1);
|
||||
|
||||
command_buffers.blit(*this,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
*this,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
Span<VkImageBlit>(&image_blit, 1));
|
||||
}
|
||||
|
||||
/* Ensure that all mipmap levels are in `VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL`. */
|
||||
layout_ensure(context,
|
||||
IndexRange(mipmaps_ - 1, 1),
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_ACCESS_MEMORY_READ_BIT);
|
||||
current_layout_set(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
else if (ELEM(this->type_get(), GPU_TEXTURE_2D_ARRAY)) {
|
||||
update_mipmaps.l0_size.z = 1;
|
||||
}
|
||||
update_mipmaps.vk_image_aspect = to_vk_image_aspect_flag_bits(device_format_);
|
||||
update_mipmaps.mipmaps = mipmaps_;
|
||||
update_mipmaps.layer_count = vk_layer_count(1);
|
||||
context.render_graph.add_node(update_mipmaps);
|
||||
}
|
||||
|
||||
void VKTexture::copy_to(VKTexture &dst_texture, VkImageAspectFlags vk_image_aspect)
|
||||
@@ -174,17 +99,7 @@ void VKTexture::copy_to(VKTexture &dst_texture, VkImageAspectFlags vk_image_aspe
|
||||
copy_image.region.extent = vk_extent_3d(0);
|
||||
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(copy_image);
|
||||
}
|
||||
else {
|
||||
layout_ensure(context, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
dst_texture.layout_ensure(context, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.copy(dst_texture, *this, Span<VkImageCopy>(©_image.region, 1));
|
||||
context.flush();
|
||||
}
|
||||
context.render_graph.add_node(copy_image);
|
||||
}
|
||||
|
||||
void VKTexture::copy_to(Texture *tex)
|
||||
@@ -217,18 +132,7 @@ void VKTexture::clear(eGPUDataFormat format, const void *data)
|
||||
|
||||
VKContext &context = *VKContext::get();
|
||||
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(clear_color_image);
|
||||
}
|
||||
else {
|
||||
layout_ensure(context, VK_IMAGE_LAYOUT_GENERAL);
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.clear(
|
||||
clear_color_image.vk_image,
|
||||
current_layout_get(),
|
||||
clear_color_image.vk_clear_color_value,
|
||||
Span<VkImageSubresourceRange>(&clear_color_image.vk_image_subresource_range, 1));
|
||||
}
|
||||
context.render_graph.add_node(clear_color_image);
|
||||
}
|
||||
|
||||
void VKTexture::clear_depth_stencil(const eGPUFrameBufferBits buffers,
|
||||
@@ -250,18 +154,7 @@ void VKTexture::clear_depth_stencil(const eGPUFrameBufferBits buffers,
|
||||
VK_REMAINING_MIP_LEVELS;
|
||||
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(clear_depth_stencil_image);
|
||||
}
|
||||
else {
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
layout_ensure(context, VK_IMAGE_LAYOUT_GENERAL);
|
||||
command_buffers.clear(clear_depth_stencil_image.node_data.vk_image,
|
||||
current_layout_get(),
|
||||
clear_depth_stencil_image.node_data.vk_clear_depth_stencil_value,
|
||||
Span<VkImageSubresourceRange>(
|
||||
&clear_depth_stencil_image.node_data.vk_image_subresource_range, 1));
|
||||
}
|
||||
context.render_graph.add_node(clear_depth_stencil_image);
|
||||
}
|
||||
|
||||
void VKTexture::swizzle_set(const char swizzle_mask[4])
|
||||
@@ -303,18 +196,9 @@ void VKTexture::read_sub(
|
||||
copy_image_to_buffer.region.imageSubresource.layerCount = layers.size();
|
||||
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
context.rendering_end();
|
||||
context.render_graph.add_node(copy_image_to_buffer);
|
||||
context.render_graph.submit_buffer_for_read(staging_buffer.vk_handle());
|
||||
}
|
||||
else {
|
||||
layout_ensure(context, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.copy(
|
||||
staging_buffer, *this, Span<VkBufferImageCopy>(©_image_to_buffer.region, 1));
|
||||
context.flush();
|
||||
}
|
||||
context.rendering_end();
|
||||
context.render_graph.add_node(copy_image_to_buffer);
|
||||
context.render_graph.submit_buffer_for_read(staging_buffer.vk_handle());
|
||||
|
||||
convert_device_to_host(
|
||||
r_data, staging_buffer.mapped_memory_get(), sample_len, format, format_, device_format_);
|
||||
@@ -407,16 +291,7 @@ void VKTexture::update_sub(
|
||||
copy_buffer_to_image.region.imageSubresource.mipLevel = mip;
|
||||
copy_buffer_to_image.region.imageSubresource.layerCount = layers;
|
||||
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(copy_buffer_to_image);
|
||||
}
|
||||
else {
|
||||
layout_ensure(context, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.copy(
|
||||
*this, staging_buffer, Span<VkBufferImageCopy>(©_buffer_to_image.region, 1));
|
||||
context.flush();
|
||||
}
|
||||
context.render_graph.add_node(copy_buffer_to_image);
|
||||
}
|
||||
|
||||
void VKTexture::update_sub(int /*offset*/[3],
|
||||
@@ -482,16 +357,7 @@ bool VKTexture::init_internal(VertBuf *vbo)
|
||||
copy_buffer_to_image.region.imageSubresource.layerCount = 1;
|
||||
|
||||
VKContext &context = *VKContext::get();
|
||||
if (use_render_graph) {
|
||||
context.render_graph.add_node(copy_buffer_to_image);
|
||||
}
|
||||
else {
|
||||
layout_ensure(context, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
VKCommandBuffers &command_buffers = context.command_buffers_get();
|
||||
command_buffers.copy(
|
||||
*this, vertex_buffer->buffer_, Span<VkBufferImageCopy>(©_buffer_to_image.region, 1));
|
||||
context.flush();
|
||||
}
|
||||
context.render_graph.add_node(copy_buffer_to_image);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -582,7 +448,6 @@ bool VKTexture::allocate()
|
||||
BLI_assert(vk_image_ == VK_NULL_HANDLE);
|
||||
BLI_assert(!is_texture_view());
|
||||
|
||||
VKContext &context = *VKContext::get();
|
||||
VKDevice &device = VKBackend::get().device_get();
|
||||
VkImageCreateInfo image_info = {};
|
||||
image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
@@ -632,14 +497,8 @@ bool VKTexture::allocate()
|
||||
}
|
||||
debug::object_label(vk_image_, name_);
|
||||
|
||||
if (use_render_graph) {
|
||||
device.resources.add_image(
|
||||
vk_image_, VK_IMAGE_LAYOUT_UNDEFINED, render_graph::ResourceOwner::APPLICATION);
|
||||
}
|
||||
else {
|
||||
/* Promote image to the correct layout. */
|
||||
layout_ensure(context, VK_IMAGE_LAYOUT_GENERAL);
|
||||
}
|
||||
device.resources.add_image(
|
||||
vk_image_, VK_IMAGE_LAYOUT_UNDEFINED, render_graph::ResourceOwner::APPLICATION);
|
||||
|
||||
return result == VK_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -33,17 +33,11 @@ void VKUniformBuffer::update(const void *data)
|
||||
|
||||
void VKUniformBuffer::allocate()
|
||||
{
|
||||
/*
|
||||
* TODO: make uniform buffers device local. In order to do that we should remove the upload
|
||||
* during binding, as that will reset the graphics pipeline and already attached resources would
|
||||
* not be bound anymore.
|
||||
*/
|
||||
const bool is_host_visible = !use_render_graph;
|
||||
buffer_.create(size_in_bytes_,
|
||||
GPU_USAGE_STATIC,
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
||||
is_host_visible);
|
||||
false);
|
||||
debug::object_label(buffer_.vk_handle(), name_);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,9 +93,6 @@ void VKVertexBuffer::update_sub(uint /*start*/, uint /*len*/, const void * /*dat
|
||||
void VKVertexBuffer::read(void *data) const
|
||||
{
|
||||
VKContext &context = *VKContext::get();
|
||||
if (!use_render_graph) {
|
||||
context.flush();
|
||||
}
|
||||
if (buffer_.is_mapped()) {
|
||||
buffer_.read(context, data);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user