#pragma once #ifndef NOMINMAX #define NOMINMAX #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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 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