Checkpoint current new editor host iteration

This commit is contained in:
2026-04-13 18:52:30 +08:00
parent a0d5e84516
commit d2140bf5cc
11 changed files with 243 additions and 184 deletions

View File

@@ -22,7 +22,10 @@
#include <d3d12.h>
#include <windows.h>
#include <wrl/client.h>
#include <array>
#include <string>
#include <vector>
namespace XCEngine::UI::Editor::Host {
@@ -34,13 +37,17 @@ public:
bool Initialize(HWND hwnd, int width, int height);
void Shutdown();
void Resize(int width, int height);
bool Resize(int width, int height);
bool BeginFrame();
bool PreparePresentSurface();
bool SubmitFrame(bool presentSwapChain);
bool SignalFrameCompletion();
bool PresentFrame();
ID3D12Device* GetDevice() const;
ID3D12DescriptorHeap* GetSrvHeap() const;
ID3D12CommandQueue* GetCommandQueue() const;
const std::string& GetLastError() const;
void AllocateShaderResourceDescriptor(
D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle,
D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle);
@@ -57,6 +64,9 @@ public:
::XCEngine::RHI::RHIDevice* GetRHIDevice() const;
::XCEngine::RHI::RHISwapChain* GetSwapChain() const;
const ::XCEngine::Rendering::RenderSurface* GetCurrentRenderSurface() const;
const ::XCEngine::RHI::D3D12Texture* GetCurrentBackBufferTexture() const;
const ::XCEngine::RHI::D3D12Texture* GetBackBufferTexture(std::uint32_t index) const;
std::uint32_t GetBackBufferCount() const;
::XCEngine::Rendering::RenderContext GetRenderContext() const;
private:
@@ -64,13 +74,18 @@ private:
::XCEngine::RHI::D3D12CommandQueue* GetD3D12CommandQueue() const;
::XCEngine::RHI::D3D12CommandList* GetD3D12CommandList() const;
::XCEngine::RHI::D3D12SwapChain* GetD3D12SwapChain() const;
::XCEngine::RHI::RHICommandList* GetCurrentCommandList() 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);
bool InitializeFrameCompletionFence();
void ReleaseFrameCompletionFence();
void WaitForBackBufferFrame(std::uint32_t backBufferIndex);
void WaitForGpuIdle();
void ReleaseBackBufferCommandReferences();
void ReleaseBackBufferViews();
bool RecreateBackBufferViews();
@@ -80,13 +95,19 @@ private:
::XCEngine::RHI::RHIDevice* m_device = nullptr;
::XCEngine::RHI::RHICommandQueue* m_commandQueue = nullptr;
::XCEngine::RHI::RHICommandList* m_commandList = nullptr;
std::array<::XCEngine::RHI::RHICommandList*, kSwapChainBufferCount> m_commandLists = {};
::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 = {};
Microsoft::WRL::ComPtr<ID3D12Fence> m_frameCompletionFence = {};
HANDLE m_frameCompletionEvent = nullptr;
std::array<std::uint64_t, kSwapChainBufferCount> m_backBufferFenceValues = {};
std::uint32_t m_activeBackBufferIndex = 0u;
std::uint64_t m_lastSubmittedFrameValue = 0;
std::string m_lastError = {};
UINT m_srvDescriptorSize = 0;
};