refactor: 将 tests/D3D12 的 CommandList 替换为 D3D12CommandList 类
- 将全局 ID3D12GraphicsCommandList 替换为 D3D12CommandList - 更新初始化、Reset、Close 调用 - 修复 Initialize 中不应调用 Close() 的问题 - 测试通过,截图与 GT.ppm 完全匹配
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12Device.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandQueue.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandList.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Fence.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Screenshot.h"
|
||||
#include "XCEngine/Debug/Logger.h"
|
||||
@@ -61,7 +62,7 @@ UINT gDSVDescriptorSize = 0;
|
||||
|
||||
// 命令相关
|
||||
XCEngine::RHI::D3D12CommandAllocator gCommandAllocator;
|
||||
ID3D12GraphicsCommandList* gCommandList = nullptr;
|
||||
XCEngine::RHI::D3D12CommandList gCommandList;
|
||||
|
||||
// 同步对象
|
||||
XCEngine::RHI::D3D12Fence gFence;
|
||||
@@ -660,7 +661,7 @@ bool InitD3D12(HWND inHWND, int inWidth, int inHeight) {
|
||||
device->CreateDepthStencilView(gDSRT, &d3dDSViewDesc, gSwapChainDSVHeap->GetCPUDescriptorHandleForHeapStart());
|
||||
|
||||
gCommandAllocator.Initialize(device, XCEngine::RHI::CommandQueueType::Direct);
|
||||
device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, gCommandAllocator.GetCommandAllocator(), nullptr, IID_PPV_ARGS(&gCommandList));
|
||||
gCommandList.Initialize(device, XCEngine::RHI::CommandQueueType::Direct, gCommandAllocator.GetCommandAllocator());
|
||||
|
||||
gFence.Initialize(device, 0);
|
||||
|
||||
@@ -675,7 +676,7 @@ ID3D12CommandAllocator* GetCommandAllocator() {
|
||||
}
|
||||
|
||||
ID3D12GraphicsCommandList* GetCommandList() {
|
||||
return gCommandList;
|
||||
return gCommandList.GetCommandList();
|
||||
}
|
||||
|
||||
void WaitForCompletionOfCommandList() {
|
||||
@@ -694,8 +695,8 @@ void WaitForCompletionOfCommandList() {
|
||||
// 关闭CommandList → ExecuteCommandLists → Signal Fence
|
||||
//=================================================================================
|
||||
void EndCommandList() {
|
||||
gCommandList->Close();
|
||||
ID3D12CommandList* ppCommandLists[] = { gCommandList };
|
||||
gCommandList.Close();
|
||||
ID3D12CommandList* ppCommandLists[] = { gCommandList.GetCommandList() };
|
||||
gCommandQueue.ExecuteCommandLists(1, ppCommandLists);
|
||||
gFenceValue += 1;
|
||||
gCommandQueue.Signal(gFence.GetFence(), gFenceValue);
|
||||
@@ -942,7 +943,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
float timeSinceAppStartInSecond = float(timeSinceAppStartInMS) / 1000.0f;
|
||||
color[0] = timeSinceAppStartInSecond;
|
||||
commandAllocator->Reset();
|
||||
commandList->Reset(commandAllocator, nullptr);
|
||||
gCommandList.Reset(gCommandAllocator.GetCommandAllocator());
|
||||
BeginRenderToSwapChain(commandList);
|
||||
commandList->SetPipelineState(pso);
|
||||
commandList->SetGraphicsRootSignature(rootSignature);
|
||||
|
||||
Reference in New Issue
Block a user