refactor ResourceUploader to use SerialQueue
This commit is contained in:
parent
38246eb51c
commit
2157002570
|
@ -105,9 +105,6 @@ namespace d3d12 {
|
||||||
ID3D12CommandList* commandLists[] = { pendingCommandList.Get() };
|
ID3D12CommandList* commandLists[] = { pendingCommandList.Get() };
|
||||||
commandQueue->ExecuteCommandLists(_countof(commandLists), commandLists);
|
commandQueue->ExecuteCommandLists(_countof(commandLists), commandLists);
|
||||||
|
|
||||||
// Update state tracking for objects requiring the serial
|
|
||||||
resourceUploader.EnqueueUploadingResources(GetSerial() + 1);
|
|
||||||
|
|
||||||
IncrementSerial();
|
IncrementSerial();
|
||||||
|
|
||||||
// Signal when the pending commands have finished
|
// Signal when the pending commands have finished
|
||||||
|
|
|
@ -70,26 +70,11 @@ namespace d3d12 {
|
||||||
uploadResource->Unmap(0, &writeRange);
|
uploadResource->Unmap(0, &writeRange);
|
||||||
device->GetPendingCommandList()->CopyBufferRegion(resource.Get(), start, uploadResource.Get(), 0, count);
|
device->GetPendingCommandList()->CopyBufferRegion(resource.Get(), start, uploadResource.Get(), 0, count);
|
||||||
|
|
||||||
pendingResources.push_back(uploadResource);
|
uploadingResources.Enqueue(std::move(uploadResource), device->GetSerial() + 1);
|
||||||
}
|
|
||||||
|
|
||||||
void ResourceUploader::EnqueueUploadingResources(const uint64_t serial) {
|
|
||||||
if (pendingResources.size() > 0) {
|
|
||||||
uploadingResources.push_back(std::make_pair(serial, std::move(pendingResources)));
|
|
||||||
pendingResources.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceUploader::FreeCompletedResources(const uint64_t lastCompletedSerial) {
|
void ResourceUploader::FreeCompletedResources(const uint64_t lastCompletedSerial) {
|
||||||
auto it = uploadingResources.begin();
|
uploadingResources.ClearUpTo(lastCompletedSerial);
|
||||||
while (it != uploadingResources.end()) {
|
|
||||||
if (it->first < lastCompletedSerial) {
|
|
||||||
it++;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uploadingResources.erase(uploadingResources.begin(), it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#include "d3d12_platform.h"
|
#include "d3d12_platform.h"
|
||||||
|
|
||||||
|
#include "common/SerialQueue.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -30,15 +32,12 @@ namespace d3d12 {
|
||||||
ResourceUploader(Device* device);
|
ResourceUploader(Device* device);
|
||||||
|
|
||||||
void UploadToBuffer(ComPtr<ID3D12Resource> resource, uint32_t start, uint32_t count, const uint8_t* data);
|
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);
|
void FreeCompletedResources(const uint64_t lastCompletedSerial);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device* device;
|
Device* device;
|
||||||
|
|
||||||
std::vector<ComPtr<ID3D12Resource>> pendingResources;
|
SerialQueue<ComPtr<ID3D12Resource>> uploadingResources;
|
||||||
std::vector<std::pair<uint64_t, std::vector<ComPtr<ID3D12Resource>>>> uploadingResources;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue