feat(d3d12): 新增纹理资源类,修复 Surface 重复释放问题

核心变更:
- 新增 d3d12_texture 和 d3d12_render_texture 类
- 新增 d3d12_texture_init_info 结构,支持三种资源创建方式
- 新增 D3D12Helpers.h,提供堆属性辅助结构
- 改用 utl::free_list 管理 surface,解决重复释放问题
- 为 d3d12_surface 添加移动语义,支持撕裂检测

文档完善:
- 为 FreeList.h 和 Vector.h 添加完整 Doxygen 中文注释
- 更新 D3D12 学习 Wiki,添加 SRV、资源创建方式、纹理资源类章节
- 新增变更记录文档
This commit is contained in:
SpecialX
2026-04-01 16:15:12 +08:00
parent 95d8893182
commit 4d13d8df89
19 changed files with 1821 additions and 233 deletions

View File

@@ -1,10 +1,12 @@
#include "D3D12Core.h"
#include "D3D12CommonHeader.h"
#include "D3D12Resources.h"
#include "D3D12Surface.h"
using namespace Microsoft::WRL;
namespace XEngine::graphics::d3d12::core {
namespace {
using suface_collection = utl::free_list<d3d12_surface>;
/**
* @brief D3D12命令管理类设计说明
* @details 本类采用RAII设计模式封装Direct3D 12的命令队列和命令列表提供类型安全的GPU命令提交机制
@@ -249,6 +251,9 @@ IDXGIFactory7* dxgi_factory{ nullptr };
*/
d3d12_command gfx_command;
suface_collection surfaces;
/**
@@ -531,25 +536,6 @@ shutdown()
release(main_device);
}
void
render()
{
// 等待GPU完成命令列表,并重置命令分配器和命令列表
gfx_command.begin_frame();
ID3D12GraphicsCommandList6* cmd_list{ gfx_command.command_list() };
const u32 frame_index{ current_frame_index() };
if(deferred_release_flag[frame_index])
{
process_deferred_release(frame_index);
}
// 记录命令
//
// 完成命令记录,立即提交命令列表到命令队列执行
// 为下一帧标记并增加围栏值
gfx_command.end_frame();
}
ID3D12Device *const
device()
{
@@ -583,5 +569,65 @@ set_deferred_release_flag()
deferred_release_flag[current_frame_index()] = 1;
}
#pragma region surface
surface
create_surface(platform::window window)
{
surface_id id{ surfaces.add(window) };
surfaces[id].create_swap_chain(dxgi_factory,gfx_command.command_queue(),render_target_format);
return surface{id};
}
void
remove_surface(surface_id id)
{
gfx_command.flush();
surfaces.remove(id);
}
void
resize_surface(surface_id id, u32 width, u32 height)
{
gfx_command.flush();
surfaces[id].resize();
}
u32
surface_width(surface_id id)
{
return surfaces[id].width();
}
u32
surface_height(surface_id id)
{
return surfaces[id].height();
}
void
render_surface(surface_id id)
{
// 等待GPU完成命令列表,并重置命令分配器和命令列表
gfx_command.begin_frame();
ID3D12GraphicsCommandList6* cmd_list{ gfx_command.command_list() };
const u32 frame_index{ current_frame_index() };
if(deferred_release_flag[frame_index])
{
process_deferred_release(frame_index);
}
// 呈现交换链
surfaces[id].present();
// 记录命令
//
// 完成命令记录,立即提交命令列表到命令队列执行
// 为下一帧标记并增加围栏值
gfx_command.end_frame();
}
#pragma endregion
}// namespace XEngine::graphics::d3d12::core