diff --git a/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp index 32e6fa565..b497e03b8 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp @@ -1063,6 +1063,10 @@ void WrappedID3D12GraphicsCommandList::BuildRaytracingAccelerationStructure( record->AddParent( resManager->GetResourceRecord(accStructAtOffset->GetBackingBufferResourceId())); + + // register this AS so its resource can be created during replay + m_pDevice->CreateAS(asbWrappedResource, asbWrappedResourceBufferOffset, preBldInfo, + accStructAtOffset); } else { diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index a187b2c08..e55e7c3a5 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -985,6 +985,7 @@ bool WrappedID3D12CommandQueue::ProcessChunk(ReadSerialiser &ser, D3D12Chunk chu case D3D12Chunk::Device_CreateReservedResource2: case D3D12Chunk::Device_CreateStateObject: case D3D12Chunk::Device_AddToStateObject: + case D3D12Chunk::CreateAS: RDCERR("Unexpected chunk while processing frame: %s", ToStr(chunk).c_str()); return false; diff --git a/renderdoc/driver/d3d12/d3d12_common.h b/renderdoc/driver/d3d12/d3d12_common.h index 8a32d11ba..2b5842073 100644 --- a/renderdoc/driver/d3d12/d3d12_common.h +++ b/renderdoc/driver/d3d12/d3d12_common.h @@ -944,6 +944,7 @@ DECLARE_REFLECTION_STRUCT(D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS); DECLARE_REFLECTION_STRUCT(D3D12_RAYTRACING_GEOMETRY_DESC); DECLARE_REFLECTION_STRUCT(D3D12_RAYTRACING_GEOMETRY_TRIANGLES_DESC); DECLARE_REFLECTION_STRUCT(D3D12_RAYTRACING_GEOMETRY_AABBS_DESC); +DECLARE_REFLECTION_STRUCT(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO); DECLARE_REFLECTION_STRUCT(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC); DECLARE_REFLECTION_STRUCT(D3D12_GPU_VIRTUAL_ADDRESS_AND_STRIDE); DECLARE_REFLECTION_STRUCT(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_SERIALIZATION_DESC); @@ -1114,5 +1115,6 @@ enum class D3D12Chunk : uint32_t List_EmitRaytracingAccelerationStructurePostbuildInfo, List_DispatchRays, List_SetPipelineState1, + CreateAS, Max, }; diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index a7fb4a8d7..2dfd36195 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -3616,6 +3616,68 @@ void WrappedID3D12Device::SetName(ID3D12DeviceChild *pResource, const char *Name } } +template +bool WrappedID3D12Device::Serialise_CreateAS( + SerialiserType &ser, ID3D12Resource *pResource, UINT64 resourceOffset, + const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO &preBldInfo, + D3D12AccelerationStructure *as) +{ + SERIALISE_ELEMENT(pResource); + SERIALISE_ELEMENT(resourceOffset); + SERIALISE_ELEMENT(preBldInfo); + SERIALISE_ELEMENT_LOCAL(asId, as->GetResourceID()); + + SERIALISE_CHECK_READ_ERRORS(); + + if(IsReplayingAndReading() && pResource) + { + WrappedID3D12Resource *asbWrappedResource = (WrappedID3D12Resource *)pResource; + D3D12AccelerationStructure *accStructAtOffset = NULL; + if(asbWrappedResource->CreateAccStruct(resourceOffset, preBldInfo, &accStructAtOffset)) + { + GetResourceManager()->AddLiveResource(asId, accStructAtOffset); + + AddResource(asId, ResourceType::AccelerationStructure, "Acceleration Structure"); + // ignored if there's no heap + DerivedResource(pResource, asId); + } + else + { + SET_ERROR_RESULT(m_FailedReplayResult, ResultCode::APIReplayFailed, + "Couldn't recreate acceleration structure object"); + return false; + } + } + + return true; +} + +template bool WrappedID3D12Device::Serialise_CreateAS( + ReadSerialiser &ser, ID3D12Resource *pResource, UINT64 resourceOffset, + const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO &preBldInfo, + D3D12AccelerationStructure *as); +template bool WrappedID3D12Device::Serialise_CreateAS( + WriteSerialiser &ser, ID3D12Resource *pResource, UINT64 resourceOffset, + const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO &preBldInfo, + D3D12AccelerationStructure *as); + +void WrappedID3D12Device::CreateAS(ID3D12Resource *pResource, UINT64 resourceOffset, + const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO &preBldInfo, + D3D12AccelerationStructure *as) +{ + if(IsCaptureMode(m_State)) + { + D3D12ResourceRecord *record = as->GetResourceRecord(); + + { + WriteSerialiser &ser = GetThreadSerialiser(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::CreateAS); + Serialise_CreateAS(ser, pResource, resourceOffset, preBldInfo, as); + record->AddChunk(scope.Get()); + } + } +} + template bool WrappedID3D12Device::Serialise_SetShaderExtUAV(SerialiserType &ser, GPUVendor vendor, uint32_t reg, uint32_t space, bool global) @@ -4346,6 +4408,7 @@ bool WrappedID3D12Device::ProcessChunk(ReadSerialiser &ser, D3D12Chunk context) return Serialise_CreateStateObject(ser, NULL, IID(), NULL); case D3D12Chunk::Device_AddToStateObject: return Serialise_AddToStateObject(ser, NULL, NULL, IID(), NULL); + case D3D12Chunk::CreateAS: return Serialise_CreateAS(ser, NULL, 0, {}, NULL); // in order to get a warning if we miss a case, we explicitly handle the list/queue chunks here. // If we actually encounter one it's an error (we should hit CaptureBegin first and switch to diff --git a/renderdoc/driver/d3d12/d3d12_device.h b/renderdoc/driver/d3d12/d3d12_device.h index ca59d51bd..4e14e7596 100644 --- a/renderdoc/driver/d3d12/d3d12_device.h +++ b/renderdoc/driver/d3d12/d3d12_device.h @@ -81,6 +81,7 @@ struct QueueReadbackData class WrappedID3D12Device; class WrappedID3D12Resource; class WrappedID3D12PipelineState; +class D3D12AccelerationStructure; class D3D12Replay; class D3D12TextRenderer; @@ -1251,6 +1252,11 @@ public: IMPLEMENT_FUNCTION_THREAD_SERIALISED(HRESULT, SetShaderDebugPath, ID3D12DeviceChild *pResource, const char *Path); + IMPLEMENT_FUNCTION_THREAD_SERIALISED( + void, CreateAS, ID3D12Resource *pResource, UINT64 resourceOffset, + const D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO &preBldInfo, + D3D12AccelerationStructure *as); + // IHV APIs IMPLEMENT_FUNCTION_SERIALISED(void, SetShaderExtUAV, GPUVendor vendor, uint32_t reg, uint32_t space, bool global); diff --git a/renderdoc/driver/d3d12/d3d12_device_rescreate_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_rescreate_wrap.cpp index 2bc5542b6..ba6588ea1 100644 --- a/renderdoc/driver/d3d12/d3d12_device_rescreate_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_rescreate_wrap.cpp @@ -276,7 +276,7 @@ bool WrappedID3D12Device::Serialise_CreateResource( type = ResourceType::Buffer; if(InitialLayout.ToStates() == D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE) { - prefix = "Acceleration Structure"; + prefix = "AS Buffer"; ((WrappedID3D12Resource *)ret)->MarkAsAccelerationStructureResource(); } else diff --git a/renderdoc/driver/d3d12/d3d12_serialise.cpp b/renderdoc/driver/d3d12/d3d12_serialise.cpp index 602e7bac8..78b21b76f 100644 --- a/renderdoc/driver/d3d12/d3d12_serialise.cpp +++ b/renderdoc/driver/d3d12/d3d12_serialise.cpp @@ -1965,6 +1965,14 @@ void DoSerialise(SerialiserType &ser, D3D12_RAYTRACING_GEOMETRY_AABBS_DESC &el) SERIALISE_MEMBER(AABBs); } +template +void DoSerialise(SerialiserType &ser, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO &el) +{ + SERIALISE_MEMBER(ResultDataMaxSizeInBytes); + SERIALISE_MEMBER(ScratchDataSizeInBytes); + SERIALISE_MEMBER(UpdateScratchDataSizeInBytes); +} + template void DoSerialise(SerialiserType &ser, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC &el) { @@ -2456,6 +2464,7 @@ INSTANTIATE_SERIALISE_TYPE(D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS) INSTANTIATE_SERIALISE_TYPE(D3D12_RAYTRACING_GEOMETRY_DESC); INSTANTIATE_SERIALISE_TYPE(D3D12_RAYTRACING_GEOMETRY_TRIANGLES_DESC); INSTANTIATE_SERIALISE_TYPE(D3D12_RAYTRACING_GEOMETRY_AABBS_DESC); +INSTANTIATE_SERIALISE_TYPE(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO); INSTANTIATE_SERIALISE_TYPE(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC); INSTANTIATE_SERIALISE_TYPE(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_SERIALIZATION_DESC); INSTANTIATE_SERIALISE_TYPE(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_SRV); diff --git a/renderdoc/driver/d3d12/d3d12_stringise.cpp b/renderdoc/driver/d3d12/d3d12_stringise.cpp index d219284ba..637db5257 100644 --- a/renderdoc/driver/d3d12/d3d12_stringise.cpp +++ b/renderdoc/driver/d3d12/d3d12_stringise.cpp @@ -28,7 +28,7 @@ template <> rdcstr DoStringise(const D3D12Chunk &el) { - RDCCOMPILE_ASSERT((uint32_t)D3D12Chunk::Max == 1131, "Chunks changed without updating names"); + RDCCOMPILE_ASSERT((uint32_t)D3D12Chunk::Max == 1132, "Chunks changed without updating names"); BEGIN_ENUM_STRINGISE(D3D12Chunk) { @@ -233,6 +233,7 @@ rdcstr DoStringise(const D3D12Chunk &el) STRINGISE_ENUM_CLASS_NAMED(List_DispatchRays, "ID3D12GraphicsCommandList4::DispatchRays"); STRINGISE_ENUM_CLASS_NAMED(List_SetPipelineState1, "ID3D12GraphicsCommandList4::SetPipelineState1"); + STRINGISE_ENUM_CLASS_NAMED(CreateAS, "Internal::Acceleration Structure Create"); STRINGISE_ENUM_CLASS_NAMED(Max, "Max Chunk"); } END_ENUM_STRINGISE() @@ -276,6 +277,7 @@ rdcstr DoStringise(const D3D12ResourceType &el) STRINGISE_ENUM_NAMED(Resource_RootSignature, "Root Signature"); STRINGISE_ENUM_NAMED(Resource_PipelineLibrary, "Pipeline Library"); STRINGISE_ENUM_NAMED(Resource_ProtectedResourceSession, "Protected Resource Session"); + STRINGISE_ENUM_NAMED(Resource_AccelerationStructure, "Acceleration Structure"); } END_ENUM_STRINGISE(); } @@ -1654,4 +1656,4 @@ rdcstr DoStringise(const D3D12_STATE_OBJECT_TYPE &el) STRINGISE_ENUM(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE); } END_ENUM_STRINGISE(); -} \ No newline at end of file +}