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:
@@ -1,8 +1,11 @@
|
||||
#include "D3D12Resources.h"
|
||||
#include "D3D12Core.h"
|
||||
#include "D3D12Helpers.h"
|
||||
|
||||
namespace XEngine::graphics::d3d12{
|
||||
//////////// DESCRIPTOR HEAP ////////////
|
||||
|
||||
|
||||
// 该类将被多个线程并发访问:资源创建(如纹理)与资源销毁/释放可能发生在不同线程,
|
||||
// 因此需要同步机制保护内部数据结构
|
||||
bool
|
||||
@@ -134,4 +137,63 @@ descriptor_heap::free(descriptor_handle handle)
|
||||
handle = {};
|
||||
}
|
||||
|
||||
//////////// D3D12 TEXTURE ////////////
|
||||
|
||||
d3d12_texture::d3d12_texture( d3d12_texture_init_info info)
|
||||
{
|
||||
auto *const device {core::device()};
|
||||
assert(device);
|
||||
|
||||
D3D12_CLEAR_VALUE *const clear_value{
|
||||
(info.desc &&
|
||||
(info.desc->Flags &D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET ||
|
||||
info.desc && info.desc->Flags &D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL))
|
||||
? &info.clear_value : nullptr
|
||||
};
|
||||
|
||||
if(info.resource)
|
||||
{
|
||||
_resource = info.resource;
|
||||
}
|
||||
else if(info.heap && info.desc)
|
||||
{
|
||||
assert(!info.resource);
|
||||
DXCall(device->CreatePlacedResource(
|
||||
info.heap,
|
||||
info.allocation_info.Offset,
|
||||
info.desc,
|
||||
info.initial_state,
|
||||
clear_value,
|
||||
IID_PPV_ARGS(&_resource)
|
||||
));
|
||||
}
|
||||
else if (info.desc)
|
||||
{
|
||||
assert(!info.srv_desc);
|
||||
|
||||
DXCall(device->CreateCommittedResource(
|
||||
&d3dx::heap_properties.default_heap,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
info.desc,
|
||||
info.initial_state,
|
||||
clear_value,
|
||||
IID_PPV_ARGS(&_resource)
|
||||
));
|
||||
}
|
||||
|
||||
assert(_resource);
|
||||
_srv = core::srv_heap().allocate();
|
||||
device->CreateShaderResourceView(_resource, info.srv_desc, _srv.cpu);
|
||||
}
|
||||
|
||||
void
|
||||
d3d12_texture::release()
|
||||
{
|
||||
core::srv_heap().free(_srv);
|
||||
core::deferred_release(_resource);
|
||||
}
|
||||
|
||||
//////////// D3D12 RENDER TEXTURE ////////////
|
||||
|
||||
|
||||
} //XEngine::graphics::d3d12
|
||||
Reference in New Issue
Block a user