#include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h" #include "XCEngine/RHI/D3D12/D3D12Enums.h" #include namespace XCEngine { namespace RHI { D3D12CommandAllocator::D3D12CommandAllocator() : m_type(CommandQueueType::Direct) { } D3D12CommandAllocator::~D3D12CommandAllocator() { Shutdown(); } bool D3D12CommandAllocator::Initialize(ID3D12Device* device, CommandQueueType type) { m_type = type; HRESULT hResult = device->CreateCommandAllocator( ToD3D12(type), IID_PPV_ARGS(&m_commandAllocator)); if (FAILED(hResult)) { FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a"); if (f) { fprintf(f, "[D3D12CommandAllocator] CreateCommandAllocator failed: hr=0x%08X\n", hResult); fclose(f); } if (hResult == DXGI_ERROR_DEVICE_REMOVED) { FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a"); if (f2) { fprintf(f2, "[D3D12CommandAllocator] Device removed reason: %d\n", device->GetDeviceRemovedReason()); fclose(f2); } } } return SUCCEEDED(hResult); } void D3D12CommandAllocator::Shutdown() { m_commandAllocator.Reset(); } void D3D12CommandAllocator::Reset() { m_commandAllocator->Reset(); } bool D3D12CommandAllocator::IsReady() const { return m_commandAllocator != nullptr; } } // namespace RHI } // namespace XCEngine