object不允许复制和移动
This commit is contained in:
@@ -186,87 +186,6 @@ batch_renderer::~batch_renderer() {
|
||||
destroy_resources();
|
||||
}
|
||||
|
||||
batch_renderer::batch_renderer(batch_renderer&& other) noexcept
|
||||
: device_(std::move(other.device_))
|
||||
, allocator_(other.allocator_)
|
||||
, config_(other.config_)
|
||||
, pipeline_layout_(std::move(other.pipeline_layout_))
|
||||
, pipeline_(std::move(other.pipeline_))
|
||||
, vertex_buffer_(other.vertex_buffer_)
|
||||
, vertex_allocation_(other.vertex_allocation_)
|
||||
, index_buffer_(other.index_buffer_)
|
||||
, index_allocation_(other.index_allocation_)
|
||||
, staging_buffer_(other.staging_buffer_)
|
||||
, staging_allocation_(other.staging_allocation_)
|
||||
, staging_mapped_data_(other.staging_mapped_data_)
|
||||
, vertices_(std::move(other.vertices_))
|
||||
, current_cmd_buffer_(other.current_cmd_buffer_)
|
||||
, current_descriptor_set_(other.current_descriptor_set_)
|
||||
, push_constants_(other.push_constants_)
|
||||
, statistics_(other.statistics_)
|
||||
, max_quads_(other.max_quads_)
|
||||
, max_texture_slots_(other.max_texture_slots_)
|
||||
, current_quad_count_(other.current_quad_count_)
|
||||
, initialized_(other.initialized_)
|
||||
, batching_(other.batching_)
|
||||
{
|
||||
other.allocator_ = nullptr;
|
||||
other.vertex_buffer_ = nullptr;
|
||||
other.vertex_allocation_ = nullptr;
|
||||
other.index_buffer_ = nullptr;
|
||||
other.index_allocation_ = nullptr;
|
||||
other.staging_buffer_ = nullptr;
|
||||
other.staging_allocation_ = nullptr;
|
||||
other.staging_mapped_data_ = nullptr;
|
||||
other.current_cmd_buffer_ = nullptr;
|
||||
other.current_descriptor_set_ = nullptr;
|
||||
other.initialized_ = false;
|
||||
other.batching_ = false;
|
||||
}
|
||||
|
||||
batch_renderer& batch_renderer::operator=(batch_renderer&& other) noexcept {
|
||||
if (this != &other) {
|
||||
destroy_resources();
|
||||
|
||||
device_ = std::move(other.device_);
|
||||
allocator_ = other.allocator_;
|
||||
config_ = other.config_;
|
||||
pipeline_layout_ = std::move(other.pipeline_layout_);
|
||||
pipeline_ = std::move(other.pipeline_);
|
||||
vertex_buffer_ = other.vertex_buffer_;
|
||||
vertex_allocation_ = other.vertex_allocation_;
|
||||
index_buffer_ = other.index_buffer_;
|
||||
index_allocation_ = other.index_allocation_;
|
||||
staging_buffer_ = other.staging_buffer_;
|
||||
staging_allocation_ = other.staging_allocation_;
|
||||
staging_mapped_data_ = other.staging_mapped_data_;
|
||||
vertices_ = std::move(other.vertices_);
|
||||
current_cmd_buffer_ = other.current_cmd_buffer_;
|
||||
current_descriptor_set_ = other.current_descriptor_set_;
|
||||
push_constants_ = other.push_constants_;
|
||||
statistics_ = other.statistics_;
|
||||
max_quads_ = other.max_quads_;
|
||||
max_texture_slots_ = other.max_texture_slots_;
|
||||
current_quad_count_ = other.current_quad_count_;
|
||||
initialized_ = other.initialized_;
|
||||
batching_ = other.batching_;
|
||||
|
||||
other.allocator_ = nullptr;
|
||||
other.vertex_buffer_ = nullptr;
|
||||
other.vertex_allocation_ = nullptr;
|
||||
other.index_buffer_ = nullptr;
|
||||
other.index_allocation_ = nullptr;
|
||||
other.staging_buffer_ = nullptr;
|
||||
other.staging_allocation_ = nullptr;
|
||||
other.staging_mapped_data_ = nullptr;
|
||||
other.current_cmd_buffer_ = nullptr;
|
||||
other.current_descriptor_set_ = nullptr;
|
||||
other.initialized_ = false;
|
||||
other.batching_ = false;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool batch_renderer::initialize(vk::Format color_format, vk::Format depth_format) {
|
||||
if (initialized_) {
|
||||
MIRAI_LOG_WARN("Batch renderer already initialized");
|
||||
|
||||
@@ -237,14 +237,6 @@ public:
|
||||
*/
|
||||
~batch_renderer() override;
|
||||
|
||||
/// 禁用拷贝
|
||||
batch_renderer(const batch_renderer&) = delete;
|
||||
batch_renderer& operator=(const batch_renderer&) = delete;
|
||||
|
||||
/// 允许移动
|
||||
batch_renderer(batch_renderer&& other) noexcept;
|
||||
batch_renderer& operator=(batch_renderer&& other) noexcept;
|
||||
|
||||
/**
|
||||
* @brief 初始化渲染器
|
||||
* @param color_format 颜色格式
|
||||
|
||||
@@ -185,39 +185,6 @@ command_buffer::~command_buffer() {
|
||||
}
|
||||
}
|
||||
|
||||
command_buffer::command_buffer(command_buffer&& other) noexcept
|
||||
: device_(std::move(other.device_))
|
||||
, pool_(other.pool_)
|
||||
, buffer_(other.buffer_)
|
||||
, level_(other.level_)
|
||||
, recording_(other.recording_)
|
||||
, owns_buffer_(other.owns_buffer_)
|
||||
{
|
||||
other.buffer_ = nullptr;
|
||||
other.pool_ = nullptr;
|
||||
other.recording_ = false;
|
||||
}
|
||||
|
||||
command_buffer& command_buffer::operator=(command_buffer&& other) noexcept {
|
||||
if (this != &other) {
|
||||
if (owns_buffer_ && buffer_ && pool_ != nullptr) {
|
||||
device_->get_device().freeCommandBuffers(pool_->get_vulkan_pool(), buffer_);
|
||||
}
|
||||
|
||||
device_ = std::move(other.device_);
|
||||
pool_ = other.pool_;
|
||||
buffer_ = other.buffer_;
|
||||
level_ = other.level_;
|
||||
recording_ = other.recording_;
|
||||
owns_buffer_ = other.owns_buffer_;
|
||||
|
||||
other.buffer_ = nullptr;
|
||||
other.pool_ = nullptr;
|
||||
other.recording_ = false;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void command_buffer::on_created() {
|
||||
MIRAI_LOG_DEBUG("Command buffer created");
|
||||
}
|
||||
|
||||
@@ -259,15 +259,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~command_buffer() override;
|
||||
|
||||
// 禁止拷贝
|
||||
command_buffer(const command_buffer&) = delete;
|
||||
command_buffer& operator=(const command_buffer&) = delete;
|
||||
|
||||
// 允许移动
|
||||
command_buffer(command_buffer&& other) noexcept;
|
||||
command_buffer& operator=(command_buffer&& other) noexcept;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 录制控制
|
||||
// ============================================================================================
|
||||
|
||||
@@ -60,56 +60,6 @@ frame_sync::~frame_sync() {
|
||||
}
|
||||
}
|
||||
|
||||
frame_sync::frame_sync(frame_sync&& other) noexcept
|
||||
: device_(std::move(other.device_))
|
||||
, swapchain_(std::move(other.swapchain_))
|
||||
, command_pool_(other.command_pool_)
|
||||
, frame_resources_(std::move(other.frame_resources_))
|
||||
, images_in_flight_(std::move(other.images_in_flight_))
|
||||
, frames_in_flight_(other.frames_in_flight_)
|
||||
, current_frame_(other.current_frame_)
|
||||
, current_image_index_(other.current_image_index_)
|
||||
, fence_timeout_(other.fence_timeout_)
|
||||
, on_frame_begin_(std::move(other.on_frame_begin_))
|
||||
, on_frame_end_(std::move(other.on_frame_end_))
|
||||
{
|
||||
other.command_pool_ = nullptr;
|
||||
other.frames_in_flight_ = 0;
|
||||
other.current_frame_ = 0;
|
||||
other.current_image_index_ = 0;
|
||||
}
|
||||
|
||||
frame_sync& frame_sync::operator=(frame_sync&& other) noexcept {
|
||||
if (this != &other) {
|
||||
// 清理现有资源
|
||||
if (device_ && device_->is_valid()) {
|
||||
device_->wait_idle();
|
||||
destroy_command_buffers();
|
||||
destroy_sync_objects();
|
||||
}
|
||||
|
||||
// 移动资源
|
||||
device_ = std::move(other.device_);
|
||||
swapchain_ = std::move(other.swapchain_);
|
||||
command_pool_ = other.command_pool_;
|
||||
frame_resources_ = std::move(other.frame_resources_);
|
||||
images_in_flight_ = std::move(other.images_in_flight_);
|
||||
frames_in_flight_ = other.frames_in_flight_;
|
||||
current_frame_ = other.current_frame_;
|
||||
current_image_index_ = other.current_image_index_;
|
||||
fence_timeout_ = other.fence_timeout_;
|
||||
on_frame_begin_ = std::move(other.on_frame_begin_);
|
||||
on_frame_end_ = std::move(other.on_frame_end_);
|
||||
|
||||
// 清空源对象
|
||||
other.command_pool_ = nullptr;
|
||||
other.frames_in_flight_ = 0;
|
||||
other.current_frame_ = 0;
|
||||
other.current_image_index_ = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::pair<frame_begin_result, u32> frame_sync::begin_frame() {
|
||||
if (!is_valid() || !swapchain_) {
|
||||
return {frame_begin_result::error, 0};
|
||||
|
||||
@@ -114,15 +114,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~frame_sync() override;
|
||||
|
||||
/// 禁用拷贝
|
||||
frame_sync(const frame_sync&) = delete;
|
||||
frame_sync& operator=(const frame_sync&) = delete;
|
||||
|
||||
/// 允许移动
|
||||
frame_sync(frame_sync&& other) noexcept;
|
||||
frame_sync& operator=(frame_sync&& other) noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 开始帧
|
||||
*
|
||||
|
||||
@@ -36,26 +36,6 @@ pipeline_layout::~pipeline_layout() {
|
||||
}
|
||||
}
|
||||
|
||||
pipeline_layout::pipeline_layout(pipeline_layout&& other) noexcept
|
||||
: device_(std::move(other.device_))
|
||||
, layout_(other.layout_)
|
||||
{
|
||||
other.layout_ = nullptr;
|
||||
}
|
||||
|
||||
pipeline_layout& pipeline_layout::operator=(pipeline_layout&& other) noexcept {
|
||||
if (this != &other) {
|
||||
if (layout_ && device_ && device_->is_valid()) {
|
||||
device_->get_device().destroyPipelineLayout(layout_);
|
||||
}
|
||||
|
||||
device_ = std::move(other.device_);
|
||||
layout_ = other.layout_;
|
||||
other.layout_ = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void pipeline_layout::on_created() {
|
||||
MIRAI_LOG_DEBUG("Pipeline layout created");
|
||||
}
|
||||
@@ -562,31 +542,6 @@ graphics_pipeline::~graphics_pipeline() {
|
||||
}
|
||||
}
|
||||
|
||||
graphics_pipeline::graphics_pipeline(graphics_pipeline&& other) noexcept
|
||||
: device_(std::move(other.device_))
|
||||
, pipeline_(other.pipeline_)
|
||||
, layout_(other.layout_)
|
||||
{
|
||||
other.pipeline_ = nullptr;
|
||||
other.layout_ = nullptr;
|
||||
}
|
||||
|
||||
graphics_pipeline& graphics_pipeline::operator=(graphics_pipeline&& other) noexcept {
|
||||
if (this != &other) {
|
||||
if (pipeline_ && device_ && device_->is_valid()) {
|
||||
device_->get_device().destroyPipeline(pipeline_);
|
||||
}
|
||||
|
||||
device_ = std::move(other.device_);
|
||||
pipeline_ = other.pipeline_;
|
||||
layout_ = other.layout_;
|
||||
|
||||
other.pipeline_ = nullptr;
|
||||
other.layout_ = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void graphics_pipeline::on_created() {
|
||||
MIRAI_LOG_DEBUG("Graphics pipeline created");
|
||||
}
|
||||
@@ -629,31 +584,6 @@ compute_pipeline::~compute_pipeline() {
|
||||
}
|
||||
}
|
||||
|
||||
compute_pipeline::compute_pipeline(compute_pipeline&& other) noexcept
|
||||
: device_(std::move(other.device_))
|
||||
, pipeline_(other.pipeline_)
|
||||
, layout_(other.layout_)
|
||||
{
|
||||
other.pipeline_ = nullptr;
|
||||
other.layout_ = nullptr;
|
||||
}
|
||||
|
||||
compute_pipeline& compute_pipeline::operator=(compute_pipeline&& other) noexcept {
|
||||
if (this != &other) {
|
||||
if (pipeline_ && device_ && device_->is_valid()) {
|
||||
device_->get_device().destroyPipeline(pipeline_);
|
||||
}
|
||||
|
||||
device_ = std::move(other.device_);
|
||||
pipeline_ = other.pipeline_;
|
||||
layout_ = other.layout_;
|
||||
|
||||
other.pipeline_ = nullptr;
|
||||
other.layout_ = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void compute_pipeline::on_created() {
|
||||
MIRAI_LOG_DEBUG("Compute pipeline created");
|
||||
}
|
||||
|
||||
@@ -96,15 +96,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~pipeline_layout() override;
|
||||
|
||||
// 禁止拷贝
|
||||
pipeline_layout(const pipeline_layout&) = delete;
|
||||
pipeline_layout& operator=(const pipeline_layout&) = delete;
|
||||
|
||||
// 允许移动
|
||||
pipeline_layout(pipeline_layout&& other) noexcept;
|
||||
pipeline_layout& operator=(pipeline_layout&& other) noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 获取管线布局句柄
|
||||
* @return vk::PipelineLayout 句柄
|
||||
@@ -699,15 +691,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~graphics_pipeline() override;
|
||||
|
||||
// 禁止拷贝
|
||||
graphics_pipeline(const graphics_pipeline&) = delete;
|
||||
graphics_pipeline& operator=(const graphics_pipeline&) = delete;
|
||||
|
||||
// 允许移动
|
||||
graphics_pipeline(graphics_pipeline&& other) noexcept;
|
||||
graphics_pipeline& operator=(graphics_pipeline&& other) noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 获取管线句柄
|
||||
* @return vk::Pipeline 句柄
|
||||
@@ -787,15 +771,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~compute_pipeline() override;
|
||||
|
||||
// 禁止拷贝
|
||||
compute_pipeline(const compute_pipeline&) = delete;
|
||||
compute_pipeline& operator=(const compute_pipeline&) = delete;
|
||||
|
||||
// 允许移动
|
||||
compute_pipeline(compute_pipeline&& other) noexcept;
|
||||
compute_pipeline& operator=(compute_pipeline&& other) noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 获取管线句柄
|
||||
* @return vk::Pipeline 句柄
|
||||
|
||||
@@ -22,83 +22,6 @@ renderer::~renderer() {
|
||||
shutdown();
|
||||
}
|
||||
|
||||
renderer::renderer(renderer&& other) noexcept
|
||||
: config_(std::move(other.config_))
|
||||
, state_(other.state_)
|
||||
, window_(other.window_)
|
||||
, instance_(std::move(other.instance_))
|
||||
, device_(std::move(other.device_))
|
||||
, surface_(other.surface_)
|
||||
, swapchain_(std::move(other.swapchain_))
|
||||
, allocator_(other.allocator_)
|
||||
, frame_sync_(std::move(other.frame_sync_))
|
||||
, command_pool_(std::move(other.command_pool_))
|
||||
, command_buffers_(std::move(other.command_buffers_))
|
||||
, batch_renderer_(std::move(other.batch_renderer_))
|
||||
, depth_image_(other.depth_image_)
|
||||
, depth_allocation_(other.depth_allocation_)
|
||||
, depth_image_view_(other.depth_image_view_)
|
||||
, depth_format_(other.depth_format_)
|
||||
, current_frame_index_(other.current_frame_index_)
|
||||
, current_image_index_(other.current_image_index_)
|
||||
, frame_count_(other.frame_count_)
|
||||
, frame_time_tracker_(std::move(other.frame_time_tracker_))
|
||||
, swapchain_needs_recreation_(other.swapchain_needs_recreation_)
|
||||
, window_minimized_(other.window_minimized_)
|
||||
, on_frame_begin_(std::move(other.on_frame_begin_))
|
||||
, on_frame_end_(std::move(other.on_frame_end_))
|
||||
, on_swapchain_recreated_(std::move(other.on_swapchain_recreated_))
|
||||
{
|
||||
other.state_ = render_state::uninitialized;
|
||||
other.window_ = nullptr;
|
||||
other.surface_ = nullptr;
|
||||
other.allocator_ = VK_NULL_HANDLE;
|
||||
other.depth_image_ = nullptr;
|
||||
other.depth_allocation_ = nullptr;
|
||||
other.depth_image_view_ = nullptr;
|
||||
}
|
||||
|
||||
renderer& renderer::operator=(renderer&& other) noexcept {
|
||||
if (this != &other) {
|
||||
shutdown();
|
||||
|
||||
config_ = std::move(other.config_);
|
||||
state_ = other.state_;
|
||||
window_ = other.window_;
|
||||
instance_ = std::move(other.instance_);
|
||||
device_ = std::move(other.device_);
|
||||
surface_ = other.surface_;
|
||||
swapchain_ = std::move(other.swapchain_);
|
||||
allocator_ = other.allocator_;
|
||||
frame_sync_ = std::move(other.frame_sync_);
|
||||
command_pool_ = std::move(other.command_pool_);
|
||||
command_buffers_ = std::move(other.command_buffers_);
|
||||
batch_renderer_ = std::move(other.batch_renderer_);
|
||||
depth_image_ = other.depth_image_;
|
||||
depth_allocation_ = other.depth_allocation_;
|
||||
depth_image_view_ = other.depth_image_view_;
|
||||
depth_format_ = other.depth_format_;
|
||||
current_frame_index_ = other.current_frame_index_;
|
||||
current_image_index_ = other.current_image_index_;
|
||||
frame_count_ = other.frame_count_;
|
||||
frame_time_tracker_ = std::move(other.frame_time_tracker_);
|
||||
swapchain_needs_recreation_ = other.swapchain_needs_recreation_;
|
||||
window_minimized_ = other.window_minimized_;
|
||||
on_frame_begin_ = std::move(other.on_frame_begin_);
|
||||
on_frame_end_ = std::move(other.on_frame_end_);
|
||||
on_swapchain_recreated_ = std::move(other.on_swapchain_recreated_);
|
||||
|
||||
other.state_ = render_state::uninitialized;
|
||||
other.window_ = nullptr;
|
||||
other.surface_ = nullptr;
|
||||
other.allocator_ = VK_NULL_HANDLE;
|
||||
other.depth_image_ = nullptr;
|
||||
other.depth_allocation_ = nullptr;
|
||||
other.depth_image_view_ = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool renderer::initialize(SDL_Window* window) {
|
||||
if (state_ != render_state::uninitialized) {
|
||||
MIRAI_LOG_WARN("Renderer already initialized");
|
||||
|
||||
@@ -99,15 +99,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~renderer() override;
|
||||
|
||||
/// 禁用拷贝
|
||||
renderer(const renderer&) = delete;
|
||||
renderer& operator=(const renderer&) = delete;
|
||||
|
||||
/// 允许移动
|
||||
renderer(renderer&& other) noexcept;
|
||||
renderer& operator=(renderer&& other) noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 初始化渲染器
|
||||
* @param window SDL 窗口
|
||||
|
||||
@@ -34,43 +34,6 @@ swapchain::~swapchain() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
swapchain::swapchain(swapchain&& other) noexcept
|
||||
: device_(std::move(other.device_))
|
||||
, surface_(other.surface_)
|
||||
, swapchain_(other.swapchain_)
|
||||
, images_(std::move(other.images_))
|
||||
, image_views_(std::move(other.image_views_))
|
||||
, format_(other.format_)
|
||||
, extent_(other.extent_)
|
||||
, present_mode_(other.present_mode_)
|
||||
, config_(other.config_)
|
||||
, needs_recreate_(other.needs_recreate_)
|
||||
{
|
||||
other.surface_ = nullptr;
|
||||
other.swapchain_ = nullptr;
|
||||
}
|
||||
|
||||
swapchain& swapchain::operator=(swapchain&& other) noexcept {
|
||||
if (this != &other) {
|
||||
cleanup();
|
||||
|
||||
device_ = std::move(other.device_);
|
||||
surface_ = other.surface_;
|
||||
swapchain_ = other.swapchain_;
|
||||
images_ = std::move(other.images_);
|
||||
image_views_ = std::move(other.image_views_);
|
||||
format_ = other.format_;
|
||||
extent_ = other.extent_;
|
||||
present_mode_ = other.present_mode_;
|
||||
config_ = other.config_;
|
||||
needs_recreate_ = other.needs_recreate_;
|
||||
|
||||
other.surface_ = nullptr;
|
||||
other.swapchain_ = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// 对象生命周期回调
|
||||
// ================================================================================================
|
||||
|
||||
@@ -150,15 +150,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~swapchain() override;
|
||||
|
||||
// 禁止拷贝
|
||||
swapchain(const swapchain&) = delete;
|
||||
swapchain& operator=(const swapchain&) = delete;
|
||||
|
||||
// 允许移动
|
||||
swapchain(swapchain&& other) noexcept;
|
||||
swapchain& operator=(swapchain&& other) noexcept;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 图像获取和呈现
|
||||
// ============================================================================================
|
||||
|
||||
@@ -121,13 +121,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~vulkan_device() override;
|
||||
|
||||
// 禁止拷贝和移动
|
||||
vulkan_device(const vulkan_device&) = delete;
|
||||
vulkan_device& operator=(const vulkan_device&) = delete;
|
||||
vulkan_device(vulkan_device&&) = delete;
|
||||
vulkan_device& operator=(vulkan_device&&) = delete;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 设备访问
|
||||
// ============================================================================================
|
||||
|
||||
@@ -142,15 +142,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~vulkan_instance() override;
|
||||
|
||||
// 禁止拷贝
|
||||
vulkan_instance(const vulkan_instance&) = delete;
|
||||
vulkan_instance& operator=(const vulkan_instance&) = delete;
|
||||
|
||||
// 禁止移动(Vulkan 实例通常是全局单例)
|
||||
vulkan_instance(vulkan_instance&&) = delete;
|
||||
vulkan_instance& operator=(vulkan_instance&&) = delete;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 实例访问
|
||||
// ============================================================================================
|
||||
|
||||
@@ -218,13 +218,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~gpu_allocator() override;
|
||||
|
||||
// 禁止拷贝和移动
|
||||
gpu_allocator(const gpu_allocator&) = delete;
|
||||
gpu_allocator& operator=(const gpu_allocator&) = delete;
|
||||
gpu_allocator(gpu_allocator&&) = delete;
|
||||
gpu_allocator& operator=(gpu_allocator&&) = delete;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// Buffer 分配
|
||||
// ============================================================================================
|
||||
|
||||
@@ -95,50 +95,6 @@ buffer::~buffer() {
|
||||
}
|
||||
}
|
||||
|
||||
buffer::buffer(buffer&& other) noexcept
|
||||
: allocator_(std::move(other.allocator_))
|
||||
, allocation_(other.allocation_)
|
||||
, size_(other.size_)
|
||||
, usage_(other.usage_)
|
||||
, mem_usage_(other.mem_usage_)
|
||||
, mapped_ptr_(other.mapped_ptr_)
|
||||
, persistent_mapped_(other.persistent_mapped_)
|
||||
, debug_name_(std::move(other.debug_name_)) {
|
||||
|
||||
// 清空源对象
|
||||
other.allocation_ = {};
|
||||
other.size_ = 0;
|
||||
other.mapped_ptr_ = nullptr;
|
||||
}
|
||||
|
||||
buffer& buffer::operator=(buffer&& other) noexcept {
|
||||
if (this != &other) {
|
||||
// 释放当前资源
|
||||
if (is_valid() && allocator_) {
|
||||
if (mapped_ptr_ != nullptr && !persistent_mapped_) {
|
||||
unmap();
|
||||
}
|
||||
allocator_->free(allocation_);
|
||||
}
|
||||
|
||||
// 移动资源
|
||||
allocator_ = std::move(other.allocator_);
|
||||
allocation_ = other.allocation_;
|
||||
size_ = other.size_;
|
||||
usage_ = other.usage_;
|
||||
mem_usage_ = other.mem_usage_;
|
||||
mapped_ptr_ = other.mapped_ptr_;
|
||||
persistent_mapped_ = other.persistent_mapped_;
|
||||
debug_name_ = std::move(other.debug_name_);
|
||||
|
||||
// 清空源对象
|
||||
other.allocation_ = {};
|
||||
other.size_ = 0;
|
||||
other.mapped_ptr_ = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// 内存映射
|
||||
// ================================================================================================
|
||||
@@ -408,35 +364,6 @@ staging_buffer::~staging_buffer() {
|
||||
}
|
||||
}
|
||||
|
||||
staging_buffer::staging_buffer(staging_buffer&& other) noexcept
|
||||
: allocator_(std::move(other.allocator_))
|
||||
, allocation_(other.allocation_)
|
||||
, size_(other.size_)
|
||||
, mapped_ptr_(other.mapped_ptr_) {
|
||||
|
||||
other.allocation_ = {};
|
||||
other.size_ = 0;
|
||||
other.mapped_ptr_ = nullptr;
|
||||
}
|
||||
|
||||
staging_buffer& staging_buffer::operator=(staging_buffer&& other) noexcept {
|
||||
if (this != &other) {
|
||||
if (is_valid() && allocator_) {
|
||||
allocator_->free(allocation_);
|
||||
}
|
||||
|
||||
allocator_ = std::move(other.allocator_);
|
||||
allocation_ = other.allocation_;
|
||||
size_ = other.size_;
|
||||
mapped_ptr_ = other.mapped_ptr_;
|
||||
|
||||
other.allocation_ = {};
|
||||
other.size_ = 0;
|
||||
other.mapped_ptr_ = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void_result staging_buffer::write(const void* data, u64 size, u64 offset) {
|
||||
if (!is_valid()) {
|
||||
return make_void_error(error_code::invalid_state, "Staging buffer is not valid");
|
||||
|
||||
@@ -107,15 +107,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~buffer() override;
|
||||
|
||||
// 禁止拷贝
|
||||
buffer(const buffer&) = delete;
|
||||
buffer& operator=(const buffer&) = delete;
|
||||
|
||||
// 允许移动
|
||||
buffer(buffer&& other) noexcept;
|
||||
buffer& operator=(buffer&& other) noexcept;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 属性访问
|
||||
// ============================================================================================
|
||||
@@ -425,15 +417,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~staging_buffer() override;
|
||||
|
||||
// 禁止拷贝
|
||||
staging_buffer(const staging_buffer&) = delete;
|
||||
staging_buffer& operator=(const staging_buffer&) = delete;
|
||||
|
||||
// 允许移动
|
||||
staging_buffer(staging_buffer&& other) noexcept;
|
||||
staging_buffer& operator=(staging_buffer&& other) noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 获取大小
|
||||
* @return Buffer 大小
|
||||
|
||||
@@ -42,42 +42,6 @@ descriptor_pool::~descriptor_pool() {
|
||||
pools_.clear();
|
||||
}
|
||||
|
||||
descriptor_pool::descriptor_pool(descriptor_pool&& other) noexcept
|
||||
: device_(other.device_)
|
||||
, pools_(std::move(other.pools_))
|
||||
, config_(std::move(other.config_))
|
||||
, current_frame_(other.current_frame_)
|
||||
, allocated_sets_(other.allocated_sets_) {
|
||||
|
||||
other.device_ = vk::Device{};
|
||||
other.current_frame_ = 0;
|
||||
other.allocated_sets_ = 0;
|
||||
}
|
||||
|
||||
descriptor_pool& descriptor_pool::operator=(descriptor_pool&& other) noexcept {
|
||||
if (this != &other) {
|
||||
// 释放当前资源
|
||||
for (auto pool : pools_) {
|
||||
if (pool) {
|
||||
device_.destroyDescriptorPool(pool);
|
||||
}
|
||||
}
|
||||
|
||||
// 移动资源
|
||||
device_ = other.device_;
|
||||
pools_ = std::move(other.pools_);
|
||||
config_ = std::move(other.config_);
|
||||
current_frame_ = other.current_frame_;
|
||||
allocated_sets_ = other.allocated_sets_;
|
||||
|
||||
// 清空源对象
|
||||
other.device_ = vk::Device{};
|
||||
other.current_frame_ = 0;
|
||||
other.allocated_sets_ = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// 池创建
|
||||
// ================================================================================================
|
||||
|
||||
@@ -189,15 +189,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~descriptor_pool() override;
|
||||
|
||||
// 禁止拷贝
|
||||
descriptor_pool(const descriptor_pool&) = delete;
|
||||
descriptor_pool& operator=(const descriptor_pool&) = delete;
|
||||
|
||||
// 允许移动
|
||||
descriptor_pool(descriptor_pool&& other) noexcept;
|
||||
descriptor_pool& operator=(descriptor_pool&& other) noexcept;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 描述符集操作
|
||||
// ============================================================================================
|
||||
@@ -357,13 +349,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~descriptor_set() override;
|
||||
|
||||
// 禁止拷贝和移动(描述符集的生命周期由池管理)
|
||||
descriptor_set(const descriptor_set&) = delete;
|
||||
descriptor_set& operator=(const descriptor_set&) = delete;
|
||||
descriptor_set(descriptor_set&&) = delete;
|
||||
descriptor_set& operator=(descriptor_set&&) = delete;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 资源绑定
|
||||
// ============================================================================================
|
||||
|
||||
@@ -306,13 +306,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~resource_loader() override;
|
||||
|
||||
// 禁止拷贝和移动
|
||||
resource_loader(const resource_loader&) = delete;
|
||||
resource_loader& operator=(const resource_loader&) = delete;
|
||||
resource_loader(resource_loader&&) = delete;
|
||||
resource_loader& operator=(resource_loader&&) = delete;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 异步加载
|
||||
// ============================================================================================
|
||||
|
||||
@@ -243,15 +243,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~resource_manager() override;
|
||||
|
||||
// 禁用拷贝
|
||||
resource_manager(const resource_manager&) = delete;
|
||||
resource_manager& operator=(const resource_manager&) = delete;
|
||||
|
||||
// 允许移动
|
||||
resource_manager(resource_manager&&) noexcept = default;
|
||||
resource_manager& operator=(resource_manager&&) noexcept = default;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 组件访问
|
||||
// ============================================================================================
|
||||
|
||||
@@ -37,32 +37,6 @@ sampler::~sampler() {
|
||||
}
|
||||
}
|
||||
|
||||
sampler::sampler(sampler&& other) noexcept
|
||||
: device_(other.device_)
|
||||
, sampler_(other.sampler_)
|
||||
, info_(std::move(other.info_)) {
|
||||
|
||||
other.sampler_ = vk::Sampler{};
|
||||
}
|
||||
|
||||
sampler& sampler::operator=(sampler&& other) noexcept {
|
||||
if (this != &other) {
|
||||
// 释放当前资源
|
||||
if (sampler_ && device_) {
|
||||
device_.destroySampler(sampler_);
|
||||
}
|
||||
|
||||
// 移动资源
|
||||
device_ = other.device_;
|
||||
sampler_ = other.sampler_;
|
||||
info_ = std::move(other.info_);
|
||||
|
||||
// 清空源对象
|
||||
other.sampler_ = vk::Sampler{};
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// 采样器创建
|
||||
// ================================================================================================
|
||||
|
||||
@@ -257,15 +257,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~sampler() override;
|
||||
|
||||
// 禁止拷贝
|
||||
sampler(const sampler&) = delete;
|
||||
sampler& operator=(const sampler&) = delete;
|
||||
|
||||
// 允许移动
|
||||
sampler(sampler&& other) noexcept;
|
||||
sampler& operator=(sampler&& other) noexcept;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 属性访问
|
||||
// ============================================================================================
|
||||
|
||||
@@ -65,42 +65,6 @@ texture::~texture() {
|
||||
}
|
||||
}
|
||||
|
||||
texture::texture(texture&& other) noexcept
|
||||
: allocator_(std::move(other.allocator_))
|
||||
, allocation_(other.allocation_)
|
||||
, image_(other.image_)
|
||||
, info_(std::move(other.info_))
|
||||
, owns_image_(other.owns_image_)
|
||||
, current_layout_(other.current_layout_) {
|
||||
|
||||
other.allocation_ = {};
|
||||
other.image_ = vk::Image{};
|
||||
other.owns_image_ = false;
|
||||
}
|
||||
|
||||
texture& texture::operator=(texture&& other) noexcept {
|
||||
if (this != &other) {
|
||||
// 释放当前资源
|
||||
if (owns_image_ && allocation_.is_valid() && allocator_) {
|
||||
allocator_->free(allocation_);
|
||||
}
|
||||
|
||||
// 移动资源
|
||||
allocator_ = std::move(other.allocator_);
|
||||
allocation_ = other.allocation_;
|
||||
image_ = other.image_;
|
||||
info_ = std::move(other.info_);
|
||||
owns_image_ = other.owns_image_;
|
||||
current_layout_ = other.current_layout_;
|
||||
|
||||
// 清空源对象
|
||||
other.allocation_ = {};
|
||||
other.image_ = vk::Image{};
|
||||
other.owns_image_ = false;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// 图像创建
|
||||
// ================================================================================================
|
||||
|
||||
@@ -236,15 +236,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~texture() override;
|
||||
|
||||
// 禁止拷贝
|
||||
texture(const texture&) = delete;
|
||||
texture& operator=(const texture&) = delete;
|
||||
|
||||
// 允许移动
|
||||
texture(texture&& other) noexcept;
|
||||
texture& operator=(texture&& other) noexcept;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 属性访问
|
||||
// ============================================================================================
|
||||
|
||||
@@ -66,32 +66,6 @@ texture_view::~texture_view() {
|
||||
}
|
||||
}
|
||||
|
||||
texture_view::texture_view(texture_view&& other) noexcept
|
||||
: texture_(std::move(other.texture_))
|
||||
, view_(other.view_)
|
||||
, info_(std::move(other.info_)) {
|
||||
|
||||
other.view_ = vk::ImageView{};
|
||||
}
|
||||
|
||||
texture_view& texture_view::operator=(texture_view&& other) noexcept {
|
||||
if (this != &other) {
|
||||
// 释放当前资源
|
||||
if (view_ && texture_ && texture_->get_allocator()) {
|
||||
texture_->get_allocator()->get_device().destroyImageView(view_);
|
||||
}
|
||||
|
||||
// 移动资源
|
||||
texture_ = std::move(other.texture_);
|
||||
view_ = other.view_;
|
||||
info_ = std::move(other.info_);
|
||||
|
||||
// 清空源对象
|
||||
other.view_ = vk::ImageView{};
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// 视图创建
|
||||
// ================================================================================================
|
||||
|
||||
@@ -103,15 +103,7 @@ public:
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~texture_view() override;
|
||||
|
||||
// 禁止拷贝
|
||||
texture_view(const texture_view&) = delete;
|
||||
texture_view& operator=(const texture_view&) = delete;
|
||||
|
||||
// 允许移动
|
||||
texture_view(texture_view&& other) noexcept;
|
||||
texture_view& operator=(texture_view&& other) noexcept;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// 属性访问
|
||||
// ============================================================================================
|
||||
|
||||
@@ -682,10 +682,7 @@ bool glyph_atlas::create_gpu_texture(atlas_page& page) {
|
||||
info.mem_usage = memory_usage::gpu_only;
|
||||
info.debug_name = "GlyphAtlasPage";
|
||||
|
||||
allocator_config alloc_cfg{};
|
||||
alloc_cfg.device = device->get_device();
|
||||
auto gpu_alloc= std::make_shared<gpu_allocator>(alloc_cfg);
|
||||
page.gpu_texture = make_obj<texture>(gpu_alloc, info);
|
||||
page.gpu_texture = make_obj<texture>(allocator, info);
|
||||
|
||||
if (!page.gpu_texture || !page.gpu_texture->is_valid()) {
|
||||
MIRAI_LOG_ERROR("Failed to create atlas texture");
|
||||
|
||||
@@ -89,14 +89,6 @@ public:
|
||||
*/
|
||||
~widget() override;
|
||||
|
||||
// 禁止拷贝
|
||||
widget(const widget&) = delete;
|
||||
widget& operator=(const widget&) = delete;
|
||||
|
||||
// 允许移动
|
||||
widget(widget&&) noexcept = default;
|
||||
widget& operator=(widget&&) noexcept = default;
|
||||
|
||||
// ============================================================================================
|
||||
// 生命周期
|
||||
// ============================================================================================
|
||||
|
||||
Reference in New Issue
Block a user