2023-02-21 15:03:12 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
2023-02-22 10:16:42 +01:00
|
|
|
* Copyright 2023 Blender Foundation */
|
2023-02-21 15:03:12 +01:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "vk_common.hh"
|
2023-03-24 07:47:50 +01:00
|
|
|
#include "vk_resource_tracker.hh"
|
2023-03-06 12:28:55 +01:00
|
|
|
|
|
|
|
|
#include "BLI_utility_mixins.hh"
|
2023-02-21 15:03:12 +01:00
|
|
|
|
|
|
|
|
namespace blender::gpu {
|
|
|
|
|
class VKBuffer;
|
2023-03-06 12:28:55 +01:00
|
|
|
class VKDescriptorSet;
|
2023-03-28 11:51:32 +02:00
|
|
|
class VKFrameBuffer;
|
|
|
|
|
class VKPipeline;
|
|
|
|
|
class VKPushConstants;
|
|
|
|
|
class VKTexture;
|
2023-02-21 15:03:12 +01:00
|
|
|
|
2023-02-27 21:44:59 +11:00
|
|
|
/** Command buffer to keep track of the life-time of a command buffer. */
|
2023-02-21 15:03:12 +01:00
|
|
|
class VKCommandBuffer : NonCopyable, NonMovable {
|
2023-02-27 21:44:59 +11:00
|
|
|
/** None owning handle to the command buffer and device. Handle is owned by `GHOST_ContextVK`. */
|
2023-02-21 15:03:12 +01:00
|
|
|
VkDevice vk_device_ = VK_NULL_HANDLE;
|
|
|
|
|
VkCommandBuffer vk_command_buffer_ = VK_NULL_HANDLE;
|
|
|
|
|
VkQueue vk_queue_ = VK_NULL_HANDLE;
|
|
|
|
|
|
|
|
|
|
/** Owning handles */
|
|
|
|
|
VkFence vk_fence_ = VK_NULL_HANDLE;
|
2023-03-24 07:47:50 +01:00
|
|
|
VKSubmissionID submission_id_;
|
2023-02-21 15:03:12 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual ~VKCommandBuffer();
|
|
|
|
|
void init(const VkDevice vk_device, const VkQueue vk_queue, VkCommandBuffer vk_command_buffer);
|
|
|
|
|
void begin_recording();
|
|
|
|
|
void end_recording();
|
|
|
|
|
void bind(const VKPipeline &vk_pipeline, VkPipelineBindPoint bind_point);
|
|
|
|
|
void bind(const VKDescriptorSet &descriptor_set,
|
|
|
|
|
const VkPipelineLayout vk_pipeline_layout,
|
|
|
|
|
VkPipelineBindPoint bind_point);
|
2023-03-28 11:51:32 +02:00
|
|
|
void begin_render_pass(const VKFrameBuffer &framebuffer);
|
|
|
|
|
void end_render_pass(const VKFrameBuffer &framebuffer);
|
|
|
|
|
|
2023-03-06 12:28:55 +01:00
|
|
|
/**
|
|
|
|
|
* Add a push constant command to the command buffer.
|
|
|
|
|
*
|
|
|
|
|
* Only valid when the storage type of push_constants is StorageType::PUSH_CONSTANTS.
|
|
|
|
|
*/
|
|
|
|
|
void push_constants(const VKPushConstants &push_constants,
|
|
|
|
|
const VkPipelineLayout vk_pipeline_layout,
|
|
|
|
|
const VkShaderStageFlags vk_shader_stages);
|
2023-02-21 15:03:12 +01:00
|
|
|
void dispatch(int groups_x_len, int groups_y_len, int groups_z_len);
|
2023-02-27 20:54:27 +11:00
|
|
|
/** Copy the contents of a texture MIP level to the dst buffer. */
|
2023-02-21 15:03:12 +01:00
|
|
|
void copy(VKBuffer &dst_buffer, VKTexture &src_texture, Span<VkBufferImageCopy> regions);
|
2023-03-24 08:09:19 +01:00
|
|
|
void copy(VKTexture &dst_texture, VKBuffer &src_buffer, Span<VkBufferImageCopy> regions);
|
2023-02-21 15:03:12 +01:00
|
|
|
void pipeline_barrier(VkPipelineStageFlags source_stages,
|
|
|
|
|
VkPipelineStageFlags destination_stages);
|
|
|
|
|
void pipeline_barrier(Span<VkImageMemoryBarrier> image_memory_barriers);
|
2023-03-24 08:09:19 +01:00
|
|
|
/**
|
|
|
|
|
* Clear color image resource.
|
|
|
|
|
*/
|
|
|
|
|
void clear(VkImage vk_image,
|
|
|
|
|
VkImageLayout vk_image_layout,
|
|
|
|
|
const VkClearColorValue &vk_clear_color,
|
|
|
|
|
Span<VkImageSubresourceRange> ranges);
|
2023-03-28 11:51:32 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear attachments of the active framebuffer.
|
|
|
|
|
*/
|
|
|
|
|
void clear(Span<VkClearAttachment> attachments, Span<VkClearRect> areas);
|
2023-03-17 13:48:39 +01:00
|
|
|
void fill(VKBuffer &buffer, uint32_t data);
|
2023-02-21 15:03:12 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stop recording commands, encode + send the recordings to Vulkan, wait for the until the
|
|
|
|
|
* commands have been executed and start the command buffer to accept recordings again.
|
|
|
|
|
*/
|
|
|
|
|
void submit();
|
|
|
|
|
|
2023-03-24 07:47:50 +01:00
|
|
|
const VKSubmissionID &submission_id_get() const
|
|
|
|
|
{
|
|
|
|
|
return submission_id_;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 15:03:12 +01:00
|
|
|
private:
|
|
|
|
|
void encode_recorded_commands();
|
|
|
|
|
void submit_encoded_commands();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace blender::gpu
|