diff --git a/renderdoc/core/resource_manager.h b/renderdoc/core/resource_manager.h index 1e7626800..82a482f05 100644 --- a/renderdoc/core/resource_manager.h +++ b/renderdoc/core/resource_manager.h @@ -1392,7 +1392,7 @@ rdcarray ResourceManager::InitialContentResources() { ResourceId id = it->first; - if(HasLiveResource(id)) + if(IsCaptureMode(m_State) || HasLiveResource(id)) { resources.push_back(id); } @@ -1566,9 +1566,10 @@ void ResourceManager::InsertInitialContentsChunks(WriteSerialiser End_PrepareInitialBatch(); - for(auto it = m_InitialContents.begin(); it != m_InitialContents.end(); ++it) + rdcarray resources = InitialContentResources(); + for(auto it = resources.begin(); it != resources.end(); ++it) { - ResourceId id = it->first; + ResourceId id = *it; RenderDoc::Inst().SetProgress(CaptureProgress::SerialiseInitialStates, idx / num); idx += 1.0f; @@ -1607,32 +1608,34 @@ void ResourceManager::InsertInitialContentsChunks(WriteSerialiser dirty++; - if(!Need_InitialStateChunk(id, it->second.data)) + InitialContentStorage &data = m_InitialContents[id]; + + if(!Need_InitialStateChunk(id, data.data)) { // this was handled in ApplyInitialContentsNonChunks(), do nothing as there's no point copying // the data again (it's already been serialised). continue; } - if(it->second.chunk) + if(data.chunk) { - it->second.chunk->Write(ser); + data.chunk->Write(ser); } - else if(!it->second.filename.empty()) + else if(!data.filename.empty()) { - FILE *f = FileIO::fopen(it->second.filename, FileIO::ReadBinary); - FileIO::fseek64(f, it->second.fileStart, SEEK_SET); - StreamReader reader(f, it->second.fileEnd - it->second.fileStart, Ownership::Stream); + FILE *f = FileIO::fopen(data.filename, FileIO::ReadBinary); + FileIO::fseek64(f, data.fileStart, SEEK_SET); + StreamReader reader(f, data.fileEnd - data.fileStart, Ownership::Stream); StreamTransfer(ser.GetWriter(), &reader, NULL); } else { - uint64_t size = GetSize_InitialState(id, it->second.data); + uint64_t size = GetSize_InitialState(id, data.data); SCOPED_SERIALISE_CHUNK(SystemChunk::InitialContents, size); - Serialise_InitialState(ser, id, record, &it->second.data); + Serialise_InitialState(ser, id, record, &data.data); } // Reset back to empty contents, unloading the actual resource. diff --git a/renderdoc/driver/d3d12/d3d12_manager.cpp b/renderdoc/driver/d3d12/d3d12_manager.cpp index e698e3804..4cfe95d0c 100644 --- a/renderdoc/driver/d3d12/d3d12_manager.cpp +++ b/renderdoc/driver/d3d12/d3d12_manager.cpp @@ -3437,6 +3437,13 @@ rdcarray D3D12ResourceManager::InitialContentResources() if(aData.buildData && bData.buildData) return aData.buildData->Type > bData.buildData->Type; + // serialise ASs first to allow reallocation. + // since the enum is serialised we couldn't change the order so we do this by hand + int aASSort = aData.resourceType == Resource_AccelerationStructure ? 0 : 1; + int bASSort = bData.resourceType == Resource_AccelerationStructure ? 0 : 1; + if(aASSort != bASSort) + return aASSort < bASSort; + return aData.resourceType < bData.resourceType; }); return resources; diff --git a/renderdoc/driver/vulkan/vk_manager.cpp b/renderdoc/driver/vulkan/vk_manager.cpp index 3bb981ffc..4d57e8207 100644 --- a/renderdoc/driver/vulkan/vk_manager.cpp +++ b/renderdoc/driver/vulkan/vk_manager.cpp @@ -1054,6 +1054,13 @@ rdcarray VulkanResourceManager::InitialContentResources() return true; } + // serialise ASs first to allow reallocation. + // since the enum is serialised we couldn't change the order so we do this by hand + int aASSort = aData.type == eResAccelerationStructureKHR ? 0 : 1; + int bASSort = bData.type == eResAccelerationStructureKHR ? 0 : 1; + if(aASSort != bASSort) + return aASSort < bASSort; + return aData.type < bData.type; }); return resources;