feat(d3d12): 实现渲染目标纹理和深度缓冲区
核心变更: - 实现 d3d12_render_texture 类,支持多 Mip 级别 RTV - 实现 d3d12_depth_buffer 类,支持 DSV 和 SRV 双视图 - 为所有纹理类添加析构函数,确保资源自动释放 - 深度缓冲区格式转换处理(D32_FLOAT -> R32_TYPELESS) 文档完善: - 新增变更记录文档 - 更新 D3D12 学习 Wiki,添加渲染目标纹理和深度缓冲区章节
This commit is contained in:
@@ -435,6 +435,7 @@ public:
|
||||
constexpr static u32 max_mips{ 14 };
|
||||
d3d12_texture() = default;
|
||||
explicit d3d12_texture(d3d12_texture_init_info info);
|
||||
~d3d12_texture() { release(); }
|
||||
DISABLE_COPY(d3d12_texture);
|
||||
constexpr d3d12_texture(d3d12_texture&& o)
|
||||
: _resource(o._resource), _srv(o._srv) //这些值只是指针和句柄,不需要move
|
||||
@@ -475,6 +476,86 @@ private:
|
||||
descriptor_handle _srv;
|
||||
};
|
||||
|
||||
class d3d12_render_texture
|
||||
{
|
||||
public:
|
||||
d3d12_render_texture() = default;
|
||||
explicit d3d12_render_texture(d3d12_texture_init_info info);
|
||||
DISABLE_COPY(d3d12_render_texture);
|
||||
~d3d12_render_texture() { release(); }
|
||||
constexpr d3d12_render_texture(d3d12_render_texture&& o)
|
||||
: _texture{std::move(o._texture)}, _mip_count{o._mip_count}
|
||||
{
|
||||
for(u32 i = 0; i < o._mip_count; ++i) _rtv[i] = o._rtv[i];
|
||||
o.reset();
|
||||
}
|
||||
|
||||
constexpr d3d12_render_texture& operator=(d3d12_render_texture&& o)
|
||||
{
|
||||
assert(this != &o);
|
||||
if(this != &o)
|
||||
{
|
||||
reset();
|
||||
move(o);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void release();
|
||||
constexpr u32 mip_count() const { return _mip_count; }
|
||||
constexpr D3D12_CPU_DESCRIPTOR_HANDLE rtv(u32 mip) const { assert(mip < _mip_count); return _rtv[mip].cpu; }
|
||||
constexpr descriptor_handle srv() const { return _texture.srv(); }
|
||||
constexpr ID3D12Resource *const resource() const { return _texture.resource(); }
|
||||
private:
|
||||
constexpr void move(d3d12_render_texture& o)
|
||||
{
|
||||
_texture = std::move(o._texture);
|
||||
for(u32 i = 0; i < o._mip_count; ++i) _rtv[i] = o._rtv[i];
|
||||
o.reset();
|
||||
}
|
||||
|
||||
constexpr void reset()
|
||||
{
|
||||
for(u32 i = 0; i < _mip_count; ++i) _rtv[i] = {};
|
||||
_mip_count = 0;
|
||||
}
|
||||
|
||||
d3d12_texture _texture{};
|
||||
descriptor_handle _rtv[d3d12_texture::max_mips]{};
|
||||
u32 _mip_count{0};
|
||||
};
|
||||
|
||||
class d3d12_depth_buffer
|
||||
{
|
||||
public :
|
||||
d3d12_depth_buffer() = default;
|
||||
explicit d3d12_depth_buffer(d3d12_texture_init_info info);
|
||||
DISABLE_COPY(d3d12_depth_buffer);
|
||||
~d3d12_depth_buffer() { release(); }
|
||||
constexpr d3d12_depth_buffer(d3d12_depth_buffer&& o)
|
||||
: _texture{std::move(o._texture)}, _dsv(o._dsv)
|
||||
{
|
||||
o._dsv = {};
|
||||
}
|
||||
constexpr d3d12_depth_buffer& operator=(d3d12_depth_buffer&& o)
|
||||
{
|
||||
assert(this != &o);
|
||||
if(this != &o)
|
||||
{
|
||||
_texture = std::move(o._texture);
|
||||
_dsv = o._dsv;
|
||||
o._dsv = {};
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void release();
|
||||
constexpr D3D12_CPU_DESCRIPTOR_HANDLE dsv() const { return _dsv.cpu; }
|
||||
constexpr descriptor_handle srv() const { return _texture.srv(); }
|
||||
constexpr ID3D12Resource *const resource() const { return _texture.resource(); }
|
||||
private:
|
||||
d3d12_texture _texture{};
|
||||
descriptor_handle _dsv{};
|
||||
};
|
||||
|
||||
} // namespace XEngine::graphics::d3d12
|
||||
|
||||
Reference in New Issue
Block a user