Replace depth buffer creation with D3D12Texture wrapper
This commit is contained in:
@@ -19,6 +19,7 @@ public:
|
|||||||
bool InitializeFromExisting(ID3D12Resource* resource);
|
bool InitializeFromExisting(ID3D12Resource* resource);
|
||||||
bool InitializeFromData(ID3D12Device* device, ID3D12GraphicsCommandList* commandList,
|
bool InitializeFromData(ID3D12Device* device, ID3D12GraphicsCommandList* commandList,
|
||||||
const void* pixelData, uint32_t width, uint32_t height, DXGI_FORMAT format);
|
const void* pixelData, uint32_t width, uint32_t height, DXGI_FORMAT format);
|
||||||
|
bool InitializeDepthStencil(ID3D12Device* device, uint32_t width, uint32_t height, DXGI_FORMAT format = DXGI_FORMAT_D24_UNORM_S8_UINT);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
ID3D12Resource* GetResource() const { return m_resource.Get(); }
|
ID3D12Resource* GetResource() const { return m_resource.Get(); }
|
||||||
|
|||||||
@@ -143,6 +143,40 @@ bool D3D12Texture::InitializeFromData(ID3D12Device* device, ID3D12GraphicsComman
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool D3D12Texture::InitializeDepthStencil(ID3D12Device* device, uint32_t width, uint32_t height, DXGI_FORMAT format) {
|
||||||
|
D3D12_RESOURCE_DESC desc = {};
|
||||||
|
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
||||||
|
desc.Alignment = 0;
|
||||||
|
desc.Width = width;
|
||||||
|
desc.Height = height;
|
||||||
|
desc.DepthOrArraySize = 1;
|
||||||
|
desc.MipLevels = 1;
|
||||||
|
desc.Format = format;
|
||||||
|
desc.SampleDesc.Count = 1;
|
||||||
|
desc.SampleDesc.Quality = 0;
|
||||||
|
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||||
|
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
|
||||||
|
|
||||||
|
D3D12_HEAP_PROPERTIES heapProperties = {};
|
||||||
|
heapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||||
|
|
||||||
|
D3D12_CLEAR_VALUE clearValue = {};
|
||||||
|
clearValue.Format = format;
|
||||||
|
clearValue.DepthStencil.Depth = 1.0f;
|
||||||
|
clearValue.DepthStencil.Stencil = 0;
|
||||||
|
|
||||||
|
HRESULT hResult = device->CreateCommittedResource(
|
||||||
|
&heapProperties,
|
||||||
|
D3D12_HEAP_FLAG_NONE,
|
||||||
|
&desc,
|
||||||
|
D3D12_RESOURCE_STATE_DEPTH_WRITE,
|
||||||
|
&clearValue,
|
||||||
|
IID_PPV_ARGS(&m_resource)
|
||||||
|
);
|
||||||
|
|
||||||
|
return SUCCEEDED(hResult);
|
||||||
|
}
|
||||||
|
|
||||||
void D3D12Texture::Shutdown() {
|
void D3D12Texture::Shutdown() {
|
||||||
m_resource.Reset();
|
m_resource.Reset();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ XCEngine::RHI::D3D12CommandQueue gCommandQueue;
|
|||||||
XCEngine::RHI::D3D12SwapChain gSwapChain;
|
XCEngine::RHI::D3D12SwapChain gSwapChain;
|
||||||
|
|
||||||
// 渲染目标 (SwapChain的后台Buffer)
|
// 渲染目标 (SwapChain的后台Buffer)
|
||||||
ID3D12Resource* gDSRT = nullptr; // 深度模板缓冲
|
|
||||||
ID3D12Resource* gColorRTs[2]; // 颜色缓冲 (双缓冲)
|
ID3D12Resource* gColorRTs[2]; // 颜色缓冲 (双缓冲)
|
||||||
int gCurrentRTIndex = 0;
|
int gCurrentRTIndex = 0;
|
||||||
|
|
||||||
@@ -84,6 +83,7 @@ XCEngine::RHI::D3D12Shader gPixelShader;
|
|||||||
XCEngine::RHI::D3D12Buffer gConstantBuffer; // matrices
|
XCEngine::RHI::D3D12Buffer gConstantBuffer; // matrices
|
||||||
XCEngine::RHI::D3D12Buffer gMaterialBuffer; // material data
|
XCEngine::RHI::D3D12Buffer gMaterialBuffer; // material data
|
||||||
XCEngine::RHI::D3D12Texture gTexture; // earth texture
|
XCEngine::RHI::D3D12Texture gTexture; // earth texture
|
||||||
|
XCEngine::RHI::D3D12Texture gDepthStencil; // depth stencil buffer
|
||||||
XCEngine::RHI::D3D12ShaderResourceView gTextureSRV; // texture SRV
|
XCEngine::RHI::D3D12ShaderResourceView gTextureSRV; // texture SRV
|
||||||
|
|
||||||
// 同步对象
|
// 同步对象
|
||||||
@@ -486,34 +486,8 @@ bool InitD3D12(HWND inHWND, int inWidth, int inHeight) {
|
|||||||
dxgiFactory->CreateSwapChain(gCommandQueue.GetCommandQueue(), &swapChainDesc, &swapChain);
|
dxgiFactory->CreateSwapChain(gCommandQueue.GetCommandQueue(), &swapChainDesc, &swapChain);
|
||||||
gSwapChain.Initialize(swapChain, inWidth, inHeight);
|
gSwapChain.Initialize(swapChain, inWidth, inHeight);
|
||||||
|
|
||||||
D3D12_HEAP_PROPERTIES d3dHeapProperties = {};
|
gDepthStencil.InitializeDepthStencil(device, inWidth, inHeight);
|
||||||
d3dHeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
ID3D12Resource* gDSRT = gDepthStencil.GetResource();
|
||||||
|
|
||||||
D3D12_RESOURCE_DESC d3d12ResourceDesc = {};
|
|
||||||
d3d12ResourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
|
||||||
d3d12ResourceDesc.Alignment = 0;
|
|
||||||
d3d12ResourceDesc.Width = inWidth;
|
|
||||||
d3d12ResourceDesc.Height = inHeight;
|
|
||||||
d3d12ResourceDesc.DepthOrArraySize = 1;
|
|
||||||
d3d12ResourceDesc.MipLevels = 1;
|
|
||||||
d3d12ResourceDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
|
||||||
d3d12ResourceDesc.SampleDesc.Count = 1;
|
|
||||||
d3d12ResourceDesc.SampleDesc.Quality = 0;
|
|
||||||
d3d12ResourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
|
||||||
d3d12ResourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
|
|
||||||
|
|
||||||
D3D12_CLEAR_VALUE dsClearValue = {};
|
|
||||||
dsClearValue.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
|
||||||
dsClearValue.DepthStencil.Depth = 1.0f;
|
|
||||||
dsClearValue.DepthStencil.Stencil = 0;
|
|
||||||
|
|
||||||
device->CreateCommittedResource(&d3dHeapProperties,
|
|
||||||
D3D12_HEAP_FLAG_NONE,
|
|
||||||
&d3d12ResourceDesc,
|
|
||||||
D3D12_RESOURCE_STATE_DEPTH_WRITE,
|
|
||||||
&dsClearValue,
|
|
||||||
IID_PPV_ARGS(&gDSRT)
|
|
||||||
);
|
|
||||||
|
|
||||||
D3D12_DESCRIPTOR_HEAP_DESC d3dDescriptorHeapDescRTV = {};
|
D3D12_DESCRIPTOR_HEAP_DESC d3dDescriptorHeapDescRTV = {};
|
||||||
d3dDescriptorHeapDescRTV.NumDescriptors = 2;
|
d3dDescriptorHeapDescRTV.NumDescriptors = 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user