refactor ResourceUploader to use SerialQueue
This commit is contained in:
parent
38246eb51c
commit
2157002570
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include "d3d12_platform.h"
|
||||
|
||||
#include "common/SerialQueue.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
|
@ -30,15 +32,12 @@ namespace d3d12 {
|
|||
ResourceUploader(Device* device);
|
||||
|
||||
void UploadToBuffer(ComPtr<ID3D12Resource> 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<ComPtr<ID3D12Resource>> pendingResources;
|
||||
std::vector<std::pair<uint64_t, std::vector<ComPtr<ID3D12Resource>>>> uploadingResources;
|
||||
|
||||
SerialQueue<ComPtr<ID3D12Resource>> uploadingResources;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue