refactor: 将 tests/D3D12 的 CommandList 替换为 D3D12CommandList 类
- 将全局 ID3D12GraphicsCommandList 替换为 D3D12CommandList - 更新初始化、Reset、Close 调用 - 修复 Initialize 中不应调用 Close() 的问题 - 测试通过,截图与 GT.ppm 完全匹配
This commit is contained in:
@@ -1,2 +1,8 @@
|
|||||||
[2026-03-15 17:36:10] [DEBUG] [Rendering] [DEBUG] D3D12 Test Application Started
|
[2026-03-15 17:36:10] [DEBUG] [Rendering] [DEBUG] D3D12 Test Application Started
|
||||||
|
|
||||||
|
[2026-03-15 17:52:42] [DEBUG] [Rendering] [DEBUG] D3D12 Test Application Started
|
||||||
|
|
||||||
|
[2026-03-15 17:52:53] [DEBUG] [Rendering] [DEBUG] D3D12 Test Application Started
|
||||||
|
|
||||||
|
[2026-03-15 17:57:07] [DEBUG] [Rendering] [DEBUG] D3D12 Test Application Started
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
D3D12CommandList();
|
D3D12CommandList();
|
||||||
~D3D12CommandList();
|
~D3D12CommandList();
|
||||||
|
|
||||||
bool Initialize(ID3D12Device* device, CommandQueueType type = CommandQueueType::Direct);
|
bool Initialize(ID3D12Device* device, CommandQueueType type = CommandQueueType::Direct, ID3D12CommandAllocator* allocator = nullptr);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
void Reset(ID3D12CommandAllocator* allocator);
|
void Reset(ID3D12CommandAllocator* allocator);
|
||||||
|
|||||||
@@ -15,23 +15,13 @@ D3D12CommandList::~D3D12CommandList() {
|
|||||||
Shutdown();
|
Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool D3D12CommandList::Initialize(ID3D12Device* device, CommandQueueType type) {
|
bool D3D12CommandList::Initialize(ID3D12Device* device, CommandQueueType type, ID3D12CommandAllocator* allocator) {
|
||||||
D3D12_COMMAND_LIST_TYPE listType = ToD3D12(type);
|
D3D12_COMMAND_LIST_TYPE listType = ToD3D12(type);
|
||||||
|
|
||||||
ComPtr<ID3D12CommandAllocator> tempAllocator;
|
HRESULT hResult = device->CreateCommandList(
|
||||||
HRESULT hResult = device->CreateCommandAllocator(
|
|
||||||
listType,
|
|
||||||
IID_PPV_ARGS(&tempAllocator)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (FAILED(hResult)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
hResult = device->CreateCommandList(
|
|
||||||
0,
|
0,
|
||||||
listType,
|
listType,
|
||||||
tempAllocator.Get(),
|
allocator,
|
||||||
nullptr,
|
nullptr,
|
||||||
IID_PPV_ARGS(&m_commandList)
|
IID_PPV_ARGS(&m_commandList)
|
||||||
);
|
);
|
||||||
@@ -42,7 +32,6 @@ bool D3D12CommandList::Initialize(ID3D12Device* device, CommandQueueType type) {
|
|||||||
|
|
||||||
m_type = type;
|
m_type = type;
|
||||||
|
|
||||||
m_commandList->Close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "XCEngine/RHI/D3D12/D3D12Device.h"
|
#include "XCEngine/RHI/D3D12/D3D12Device.h"
|
||||||
#include "XCEngine/RHI/D3D12/D3D12CommandQueue.h"
|
#include "XCEngine/RHI/D3D12/D3D12CommandQueue.h"
|
||||||
#include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h"
|
#include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h"
|
||||||
|
#include "XCEngine/RHI/D3D12/D3D12CommandList.h"
|
||||||
#include "XCEngine/RHI/D3D12/D3D12Fence.h"
|
#include "XCEngine/RHI/D3D12/D3D12Fence.h"
|
||||||
#include "XCEngine/RHI/D3D12/D3D12Screenshot.h"
|
#include "XCEngine/RHI/D3D12/D3D12Screenshot.h"
|
||||||
#include "XCEngine/Debug/Logger.h"
|
#include "XCEngine/Debug/Logger.h"
|
||||||
@@ -61,7 +62,7 @@ UINT gDSVDescriptorSize = 0;
|
|||||||
|
|
||||||
// 命令相关
|
// 命令相关
|
||||||
XCEngine::RHI::D3D12CommandAllocator gCommandAllocator;
|
XCEngine::RHI::D3D12CommandAllocator gCommandAllocator;
|
||||||
ID3D12GraphicsCommandList* gCommandList = nullptr;
|
XCEngine::RHI::D3D12CommandList gCommandList;
|
||||||
|
|
||||||
// 同步对象
|
// 同步对象
|
||||||
XCEngine::RHI::D3D12Fence gFence;
|
XCEngine::RHI::D3D12Fence gFence;
|
||||||
@@ -660,7 +661,7 @@ bool InitD3D12(HWND inHWND, int inWidth, int inHeight) {
|
|||||||
device->CreateDepthStencilView(gDSRT, &d3dDSViewDesc, gSwapChainDSVHeap->GetCPUDescriptorHandleForHeapStart());
|
device->CreateDepthStencilView(gDSRT, &d3dDSViewDesc, gSwapChainDSVHeap->GetCPUDescriptorHandleForHeapStart());
|
||||||
|
|
||||||
gCommandAllocator.Initialize(device, XCEngine::RHI::CommandQueueType::Direct);
|
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);
|
gFence.Initialize(device, 0);
|
||||||
|
|
||||||
@@ -675,7 +676,7 @@ ID3D12CommandAllocator* GetCommandAllocator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ID3D12GraphicsCommandList* GetCommandList() {
|
ID3D12GraphicsCommandList* GetCommandList() {
|
||||||
return gCommandList;
|
return gCommandList.GetCommandList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitForCompletionOfCommandList() {
|
void WaitForCompletionOfCommandList() {
|
||||||
@@ -694,8 +695,8 @@ void WaitForCompletionOfCommandList() {
|
|||||||
// 关闭CommandList → ExecuteCommandLists → Signal Fence
|
// 关闭CommandList → ExecuteCommandLists → Signal Fence
|
||||||
//=================================================================================
|
//=================================================================================
|
||||||
void EndCommandList() {
|
void EndCommandList() {
|
||||||
gCommandList->Close();
|
gCommandList.Close();
|
||||||
ID3D12CommandList* ppCommandLists[] = { gCommandList };
|
ID3D12CommandList* ppCommandLists[] = { gCommandList.GetCommandList() };
|
||||||
gCommandQueue.ExecuteCommandLists(1, ppCommandLists);
|
gCommandQueue.ExecuteCommandLists(1, ppCommandLists);
|
||||||
gFenceValue += 1;
|
gFenceValue += 1;
|
||||||
gCommandQueue.Signal(gFence.GetFence(), gFenceValue);
|
gCommandQueue.Signal(gFence.GetFence(), gFenceValue);
|
||||||
@@ -942,7 +943,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
float timeSinceAppStartInSecond = float(timeSinceAppStartInMS) / 1000.0f;
|
float timeSinceAppStartInSecond = float(timeSinceAppStartInMS) / 1000.0f;
|
||||||
color[0] = timeSinceAppStartInSecond;
|
color[0] = timeSinceAppStartInSecond;
|
||||||
commandAllocator->Reset();
|
commandAllocator->Reset();
|
||||||
commandList->Reset(commandAllocator, nullptr);
|
gCommandList.Reset(gCommandAllocator.GetCommandAllocator());
|
||||||
BeginRenderToSwapChain(commandList);
|
BeginRenderToSwapChain(commandList);
|
||||||
commandList->SetPipelineState(pso);
|
commandList->SetPipelineState(pso);
|
||||||
commandList->SetGraphicsRootSignature(rootSignature);
|
commandList->SetGraphicsRootSignature(rootSignature);
|
||||||
|
|||||||
Reference in New Issue
Block a user