93 lines
3.4 KiB
C
93 lines
3.4 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#ifndef NOMINMAX
|
||
|
|
#define NOMINMAX
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#include <XCEngine/Rendering/RenderContext.h>
|
||
|
|
#include <XCEngine/Rendering/RenderSurface.h>
|
||
|
|
#include <XCEngine/RHI/D3D12/D3D12CommandList.h>
|
||
|
|
#include <XCEngine/RHI/D3D12/D3D12CommandQueue.h>
|
||
|
|
#include <XCEngine/RHI/D3D12/D3D12DescriptorHeap.h>
|
||
|
|
#include <XCEngine/RHI/D3D12/D3D12Device.h>
|
||
|
|
#include <XCEngine/RHI/D3D12/D3D12SwapChain.h>
|
||
|
|
#include <XCEngine/RHI/D3D12/D3D12Texture.h>
|
||
|
|
#include <XCEngine/RHI/RHICommandList.h>
|
||
|
|
#include <XCEngine/RHI/RHICommandQueue.h>
|
||
|
|
#include <XCEngine/RHI/RHIDescriptorPool.h>
|
||
|
|
#include <XCEngine/RHI/RHIDevice.h>
|
||
|
|
#include <XCEngine/RHI/RHIResourceView.h>
|
||
|
|
#include <XCEngine/RHI/RHITexture.h>
|
||
|
|
#include <XCEngine/RHI/RHISwapChain.h>
|
||
|
|
|
||
|
|
#include <d3d12.h>
|
||
|
|
#include <windows.h>
|
||
|
|
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
namespace XCEngine::UI::Editor::Host {
|
||
|
|
|
||
|
|
class D3D12WindowRenderer {
|
||
|
|
public:
|
||
|
|
static constexpr UINT kSrvDescriptorCount = 64;
|
||
|
|
static constexpr std::uint32_t kSwapChainBufferCount = 3;
|
||
|
|
|
||
|
|
bool Initialize(HWND hwnd, int width, int height);
|
||
|
|
void Shutdown();
|
||
|
|
void Resize(int width, int height);
|
||
|
|
bool BeginFrame();
|
||
|
|
|
||
|
|
ID3D12Device* GetDevice() const;
|
||
|
|
ID3D12DescriptorHeap* GetSrvHeap() const;
|
||
|
|
ID3D12CommandQueue* GetCommandQueue() const;
|
||
|
|
void AllocateShaderResourceDescriptor(
|
||
|
|
D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle,
|
||
|
|
D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle);
|
||
|
|
bool CreateShaderResourceTextureDescriptor(
|
||
|
|
::XCEngine::RHI::RHIDevice* device,
|
||
|
|
::XCEngine::RHI::RHITexture* texture,
|
||
|
|
D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle,
|
||
|
|
D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle);
|
||
|
|
void FreeShaderResourceDescriptor(
|
||
|
|
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle,
|
||
|
|
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle);
|
||
|
|
UINT GetSrvDescriptorSize() const;
|
||
|
|
UINT GetSrvDescriptorCount() const;
|
||
|
|
::XCEngine::RHI::RHIDevice* GetRHIDevice() const;
|
||
|
|
::XCEngine::RHI::RHISwapChain* GetSwapChain() const;
|
||
|
|
const ::XCEngine::Rendering::RenderSurface* GetCurrentRenderSurface() const;
|
||
|
|
::XCEngine::Rendering::RenderContext GetRenderContext() const;
|
||
|
|
|
||
|
|
private:
|
||
|
|
::XCEngine::RHI::D3D12Device* GetD3D12Device() const;
|
||
|
|
::XCEngine::RHI::D3D12CommandQueue* GetD3D12CommandQueue() const;
|
||
|
|
::XCEngine::RHI::D3D12CommandList* GetD3D12CommandList() const;
|
||
|
|
::XCEngine::RHI::D3D12SwapChain* GetD3D12SwapChain() const;
|
||
|
|
void AllocateShaderResourceDescriptorInternal(
|
||
|
|
D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle,
|
||
|
|
D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle);
|
||
|
|
void FreeShaderResourceDescriptorInternal(
|
||
|
|
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle,
|
||
|
|
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle);
|
||
|
|
void WaitForGpuIdle();
|
||
|
|
void ReleaseBackBufferViews();
|
||
|
|
bool RecreateBackBufferViews();
|
||
|
|
|
||
|
|
HWND m_hwnd = nullptr;
|
||
|
|
int m_width = 0;
|
||
|
|
int m_height = 0;
|
||
|
|
|
||
|
|
::XCEngine::RHI::RHIDevice* m_device = nullptr;
|
||
|
|
::XCEngine::RHI::RHICommandQueue* m_commandQueue = nullptr;
|
||
|
|
::XCEngine::RHI::RHICommandList* m_commandList = nullptr;
|
||
|
|
::XCEngine::RHI::RHISwapChain* m_swapChain = nullptr;
|
||
|
|
::XCEngine::RHI::RHIDescriptorPool* m_srvPool = nullptr;
|
||
|
|
::XCEngine::RHI::D3D12DescriptorHeap* m_srvHeap = nullptr;
|
||
|
|
std::vector<bool> m_srvUsage = {};
|
||
|
|
std::vector<::XCEngine::RHI::RHIResourceView*> m_backBufferViews = {};
|
||
|
|
std::vector<::XCEngine::Rendering::RenderSurface> m_backBufferSurfaces = {};
|
||
|
|
UINT m_srvDescriptorSize = 0;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace XCEngine::UI::Editor::Host
|