diff --git a/src/backend/d3d12/D3D12Backend.cpp b/src/backend/d3d12/D3D12Backend.cpp index 847f759dc4..6da88a5249 100644 --- a/src/backend/d3d12/D3D12Backend.cpp +++ b/src/backend/d3d12/D3D12Backend.cpp @@ -105,9 +105,6 @@ namespace d3d12 { ID3D12CommandList* commandLists[] = { pendingCommandList.Get() }; commandQueue->ExecuteCommandLists(_countof(commandLists), commandLists); - // Update state tracking for objects requiring the serial - resourceUploader.EnqueueUploadingResources(GetSerial() + 1); - IncrementSerial(); // Signal when the pending commands have finished diff --git a/src/backend/d3d12/ResourceUploader.cpp b/src/backend/d3d12/ResourceUploader.cpp index 0bf8ac4e8b..1f379a191b 100644 --- a/src/backend/d3d12/ResourceUploader.cpp +++ b/src/backend/d3d12/ResourceUploader.cpp @@ -70,26 +70,11 @@ namespace d3d12 { uploadResource->Unmap(0, &writeRange); device->GetPendingCommandList()->CopyBufferRegion(resource.Get(), start, uploadResource.Get(), 0, count); - pendingResources.push_back(uploadResource); - } - - void ResourceUploader::EnqueueUploadingResources(const uint64_t serial) { - if (pendingResources.size() > 0) { - uploadingResources.push_back(std::make_pair(serial, std::move(pendingResources))); - pendingResources.clear(); - } + uploadingResources.Enqueue(std::move(uploadResource), device->GetSerial() + 1); } void ResourceUploader::FreeCompletedResources(const uint64_t lastCompletedSerial) { - auto it = uploadingResources.begin(); - while (it != uploadingResources.end()) { - if (it->first < lastCompletedSerial) { - it++; - } else { - break; - } - } - uploadingResources.erase(uploadingResources.begin(), it); + uploadingResources.ClearUpTo(lastCompletedSerial); } } diff --git a/src/backend/d3d12/ResourceUploader.h b/src/backend/d3d12/ResourceUploader.h index c6783bdec2..83f4a33e0e 100644 --- a/src/backend/d3d12/ResourceUploader.h +++ b/src/backend/d3d12/ResourceUploader.h @@ -17,6 +17,8 @@ #include "d3d12_platform.h" +#include "common/SerialQueue.h" + #include #include @@ -30,15 +32,12 @@ namespace d3d12 { ResourceUploader(Device* device); void UploadToBuffer(ComPtr resource, uint32_t start, uint32_t count, const uint8_t* data); - void EnqueueUploadingResources(const uint64_t serial); void FreeCompletedResources(const uint64_t lastCompletedSerial); private: Device* device; - std::vector> pendingResources; - std::vector>>> uploadingResources; - + SerialQueue> uploadingResources; }; }