Implement IShader and ISwapChain interfaces for D3D12 backend
- D3D12Shader now implements IShader interface with GetBytecode, GetBytecodeSize, GetType, GetInputLayout - D3D12SwapChain now implements ISwapChain interface with GetBackBuffer returning IResource* - Added D3D12Texture back buffer storage to SwapChain - Fixed ISwapChain const correctness (GetCurrentBackBufferIndex, GetBackBuffer) - main.cpp: use GetD3D12Bytecode() instead of GetBytecode() for PSO creation
This commit is contained in:
@@ -38,18 +38,6 @@ void D3D12DescriptorHeap::Shutdown() {
|
||||
m_descriptorHeap.Reset();
|
||||
}
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE D3D12DescriptorHeap::GetCPUDescriptorHandle(uint32_t index) const {
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle = m_descriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
handle.ptr += index * m_descriptorSize;
|
||||
return handle;
|
||||
}
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE D3D12DescriptorHeap::GetGPUDescriptorHandle(uint32_t index) const {
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE handle = m_descriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
||||
handle.ptr += index * m_descriptorSize;
|
||||
return handle;
|
||||
}
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE D3D12DescriptorHeap::GetCPUDescriptorHandleForHeapStart() const {
|
||||
return m_descriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
}
|
||||
@@ -59,15 +47,19 @@ D3D12_GPU_DESCRIPTOR_HANDLE D3D12DescriptorHeap::GetGPUDescriptorHandleForHeapSt
|
||||
}
|
||||
|
||||
CPUDescriptorHandle D3D12DescriptorHeap::GetCPUDescriptorHandle(uint32_t index) {
|
||||
CPUDescriptorHandle handle;
|
||||
handle.ptr = GetCPUDescriptorHandle(index).ptr;
|
||||
return handle;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle = m_descriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
handle.ptr += index * m_descriptorSize;
|
||||
CPUDescriptorHandle result;
|
||||
result.ptr = handle.ptr;
|
||||
return result;
|
||||
}
|
||||
|
||||
GPUDescriptorHandle D3D12DescriptorHeap::GetGPUDescriptorHandle(uint32_t index) {
|
||||
GPUDescriptorHandle handle;
|
||||
handle.ptr = GetGPUDescriptorHandle(index).ptr;
|
||||
return handle;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE handle = m_descriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
||||
handle.ptr += index * m_descriptorSize;
|
||||
GPUDescriptorHandle result;
|
||||
result.ptr = handle.ptr;
|
||||
return result;
|
||||
}
|
||||
|
||||
DescriptorType D3D12DescriptorHeap::GetType() const {
|
||||
|
||||
@@ -57,7 +57,7 @@ void D3D12Shader::Shutdown() {
|
||||
m_error.Reset();
|
||||
}
|
||||
|
||||
const D3D12_SHADER_BYTECODE D3D12Shader::GetBytecode() const {
|
||||
const D3D12_SHADER_BYTECODE D3D12Shader::GetD3D12Bytecode() const {
|
||||
D3D12_SHADER_BYTECODE bytecode = {};
|
||||
if (m_bytecode) {
|
||||
bytecode.pShaderBytecode = m_bytecode->GetBufferPointer();
|
||||
@@ -66,5 +66,27 @@ const D3D12_SHADER_BYTECODE D3D12Shader::GetBytecode() const {
|
||||
return bytecode;
|
||||
}
|
||||
|
||||
const void* D3D12Shader::GetBytecode() const {
|
||||
if (m_bytecode) {
|
||||
return m_bytecode->GetBufferPointer();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t D3D12Shader::GetBytecodeSize() const {
|
||||
if (m_bytecode) {
|
||||
return m_bytecode->GetBufferSize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const InputLayoutDesc& D3D12Shader::GetInputLayout() const {
|
||||
return m_inputLayout;
|
||||
}
|
||||
|
||||
ShaderType D3D12Shader::GetType() const {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
|
||||
@@ -56,6 +56,13 @@ bool D3D12SwapChain::Initialize(IDXGISwapChain* swapChain, uint32_t width, uint3
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
m_backBuffers.resize(m_bufferCount);
|
||||
for (uint32_t i = 0; i < m_bufferCount; ++i) {
|
||||
ID3D12Resource* resource = nullptr;
|
||||
m_swapChain->GetBuffer(i, IID_PPV_ARGS(&resource));
|
||||
m_backBuffers[i].InitializeFromExisting(resource);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -67,10 +74,11 @@ uint32_t D3D12SwapChain::GetCurrentBackBufferIndex() const {
|
||||
return m_swapChain->GetCurrentBackBufferIndex();
|
||||
}
|
||||
|
||||
ID3D12Resource* D3D12SwapChain::GetBackBuffer(uint32_t index) const {
|
||||
ID3D12Resource* resource = nullptr;
|
||||
m_swapChain->GetBuffer(index, IID_PPV_ARGS(&resource));
|
||||
return resource;
|
||||
IResource* D3D12SwapChain::GetBackBuffer(uint32_t index) const {
|
||||
if (index < m_backBuffers.size()) {
|
||||
return const_cast<D3D12Texture*>(&m_backBuffers[index]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void D3D12SwapChain::Present(uint32_t syncInterval, uint32_t flags) {
|
||||
@@ -83,5 +91,19 @@ void D3D12SwapChain::Resize(uint32_t width, uint32_t height) {
|
||||
m_height = height;
|
||||
}
|
||||
|
||||
void D3D12SwapChain::SetFullscreen(bool fullscreen) {
|
||||
m_swapChain->SetFullscreenState(fullscreen, nullptr);
|
||||
}
|
||||
|
||||
bool D3D12SwapChain::IsFullscreen() const {
|
||||
BOOL fullscreen = FALSE;
|
||||
m_swapChain->GetFullscreenState(&fullscreen, nullptr);
|
||||
return fullscreen != FALSE;
|
||||
}
|
||||
|
||||
void* D3D12SwapChain::GetNativeHandle() const {
|
||||
return reinterpret_cast<void*>(m_swapChain.Get());
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
|
||||
Reference in New Issue
Block a user