Add D3D12 view wrapper classes: RTV, DSV, SRV, CBV

This commit is contained in:
2026-03-15 19:10:32 +08:00
parent c62dc58157
commit 42c17ee106
9 changed files with 232 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
#include "XCEngine/RHI/D3D12/D3D12ConstantBufferView.h"
namespace XCEngine {
namespace RHI {
D3D12ConstantBufferView::D3D12ConstantBufferView()
: m_handle({0})
, m_resource(nullptr) {
}
D3D12ConstantBufferView::~D3D12ConstantBufferView() {
Shutdown();
}
void D3D12ConstantBufferView::Initialize(ID3D12Device* device, ID3D12Resource* buffer, const D3D12_CONSTANT_BUFFER_VIEW_DESC* desc) {
m_resource = buffer;
m_handle = {};
if (desc) {
device->CreateConstantBufferView(desc, m_handle);
} else {
D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {};
cbvDesc.BufferLocation = buffer->GetGPUVirtualAddress();
cbvDesc.SizeInBytes = static_cast<UINT>(buffer->GetDesc().Width);
device->CreateConstantBufferView(&cbvDesc, m_handle);
}
}
void D3D12ConstantBufferView::Shutdown() {
m_handle = {};
m_resource = nullptr;
}
} // namespace RHI
} // namespace XCEngine

View File

@@ -0,0 +1,27 @@
#include "XCEngine/RHI/D3D12/D3D12DepthStencilView.h"
namespace XCEngine {
namespace RHI {
D3D12DepthStencilView::D3D12DepthStencilView()
: m_handle({0})
, m_resource(nullptr) {
}
D3D12DepthStencilView::~D3D12DepthStencilView() {
Shutdown();
}
void D3D12DepthStencilView::Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_DEPTH_STENCIL_VIEW_DESC* desc) {
m_resource = resource;
m_handle = {};
device->CreateDepthStencilView(resource, desc, m_handle);
}
void D3D12DepthStencilView::Shutdown() {
m_handle = {};
m_resource = nullptr;
}
} // namespace RHI
} // namespace XCEngine

View File

@@ -0,0 +1,27 @@
#include "XCEngine/RHI/D3D12/D3D12RenderTargetView.h"
namespace XCEngine {
namespace RHI {
D3D12RenderTargetView::D3D12RenderTargetView()
: m_handle({0})
, m_resource(nullptr) {
}
D3D12RenderTargetView::~D3D12RenderTargetView() {
Shutdown();
}
void D3D12RenderTargetView::Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_RENDER_TARGET_VIEW_DESC* desc) {
m_resource = resource;
m_handle = {};
device->CreateRenderTargetView(resource, desc, m_handle);
}
void D3D12RenderTargetView::Shutdown() {
m_handle = {};
m_resource = nullptr;
}
} // namespace RHI
} // namespace XCEngine

View File

@@ -0,0 +1,27 @@
#include "XCEngine/RHI/D3D12/D3D12ShaderResourceView.h"
namespace XCEngine {
namespace RHI {
D3D12ShaderResourceView::D3D12ShaderResourceView()
: m_handle({0})
, m_resource(nullptr) {
}
D3D12ShaderResourceView::~D3D12ShaderResourceView() {
Shutdown();
}
void D3D12ShaderResourceView::Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_SHADER_RESOURCE_VIEW_DESC* desc) {
m_resource = resource;
m_handle = {};
device->CreateShaderResourceView(resource, desc, m_handle);
}
void D3D12ShaderResourceView::Shutdown() {
m_handle = {};
m_resource = nullptr;
}
} // namespace RHI
} // namespace XCEngine