diff --git a/renderdoc/driver/d3d12/d3d12_command_list.h b/renderdoc/driver/d3d12/d3d12_command_list.h index ac3777365..e7266bb62 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list.h +++ b/renderdoc/driver/d3d12/d3d12_command_list.h @@ -600,6 +600,7 @@ public: bool ProcessASBuildAfterSubmission(ResourceId asbWrappedResourceId, D3D12BufferOffset asbWrappedResourceBufferOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, UINT64 byteSize, ASBuildData *buildData); IMPLEMENT_FUNCTION_SERIALISED( diff --git a/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp index 34d856c17..047afb5c0 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp @@ -727,10 +727,9 @@ void WrappedID3D12GraphicsCommandList::ExecuteMetaCommand( RDCERR("ExecuteMetaCommand called but no meta commands reported!"); } -bool WrappedID3D12GraphicsCommandList::ProcessASBuildAfterSubmission(ResourceId destASBId, - D3D12BufferOffset destASBOffset, - UINT64 byteSize, - ASBuildData *buildData) +bool WrappedID3D12GraphicsCommandList::ProcessASBuildAfterSubmission( + ResourceId destASBId, D3D12BufferOffset destASBOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, UINT64 byteSize, ASBuildData *buildData) { D3D12ResourceManager *rm = m_pDevice->GetResourceManager(); @@ -744,7 +743,7 @@ bool WrappedID3D12GraphicsCommandList::ProcessASBuildAfterSubmission(ResourceId // // CreateAccStruct deletes any previous overlapping ASs on the ASB D3D12AccelerationStructure *accStructAtDestOffset = NULL; - if(dstASB->CreateAccStruct(destASBOffset, byteSize, &accStructAtDestOffset)) + if(dstASB->CreateAccStruct(destASBOffset, type, byteSize, &accStructAtDestOffset)) { D3D12ResourceRecord *record = rm->AddResourceRecord(accStructAtDestOffset->GetResourceID()); record->type = Resource_AccelerationStructure; @@ -755,7 +754,7 @@ bool WrappedID3D12GraphicsCommandList::ProcessASBuildAfterSubmission(ResourceId record->AddParent(rm->GetResourceRecord(accStructAtDestOffset->GetBackingBufferResourceId())); // register this AS so its resource can be created during replay - m_pDevice->CreateAS(dstASB, destASBOffset, byteSize, accStructAtDestOffset); + m_pDevice->CreateAS(dstASB, destASBOffset, type, byteSize, accStructAtDestOffset); m_pDevice->AddForcedReference(record); // in case we're currently capturing, immediately consider the AS as referenced @@ -1196,11 +1195,13 @@ void WrappedID3D12GraphicsCommandList::BuildRaytracingAccelerationStructure( UINT64 byteSize = preBldInfo.ResultDataMaxSizeInBytes; + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type = pDesc->Inputs.Type; + AddSubmissionASBuildCallback( false, - [this, asbWrappedResourceId, asbWrappedResourceBufferOffset, byteSize, buildData]() { + [this, asbWrappedResourceId, asbWrappedResourceBufferOffset, type, byteSize, buildData]() { return ProcessASBuildAfterSubmission(asbWrappedResourceId, asbWrappedResourceBufferOffset, - byteSize, buildData); + type, byteSize, buildData); }, [buildData]() { if(buildData) @@ -1474,7 +1475,8 @@ void WrappedID3D12GraphicsCommandList::CopyRaytracingAccelerationStructure( &DestAccelerationStructureData); ASBuildData *buildData = NULL; - + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type = + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL; if(Mode == D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE_DESERIALIZE) { RDCERR( @@ -1505,15 +1507,16 @@ void WrappedID3D12GraphicsCommandList::CopyRaytracingAccelerationStructure( // likely to be deleted and release its own ref) SAFE_ADDREF(accStructAtSrcOffset->buildData); buildData = accStructAtSrcOffset->buildData; + type = accStructAtSrcOffset->Type(); } - auto PostBldExecute = [this, destASBId, destASBOffset, sizeBuffer, buildData]() -> bool { + auto PostBldExecute = [this, destASBId, destASBOffset, type, sizeBuffer, buildData]() -> bool { UINT64 *size = (UINT64 *)sizeBuffer->Map(); UINT64 destSize = *size; sizeBuffer->Unmap(); sizeBuffer->Release(); - return ProcessASBuildAfterSubmission(destASBId, destASBOffset, destSize, buildData); + return ProcessASBuildAfterSubmission(destASBId, destASBOffset, type, destSize, buildData); }; AddSubmissionASBuildCallback(true, PostBldExecute, [buildData]() { @@ -1554,9 +1557,9 @@ void WrappedID3D12GraphicsCommandList::CopyRaytracingAccelerationStructure( // get a new refcount for this build data, it will be shared by the new copy (the old AS // is likely to be deleted and release its own ref) SAFE_ADDREF(accStructAtSrcOffset->buildData); - return ProcessASBuildAfterSubmission(destASBId, destASBOffset, - accStructAtSrcOffset->Size(), - accStructAtSrcOffset->buildData); + return ProcessASBuildAfterSubmission( + destASBId, destASBOffset, accStructAtSrcOffset->Type(), + accStructAtSrcOffset->Size(), accStructAtSrcOffset->buildData); }, NULL); } diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index 4952e8119..edae1b2c7 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -3931,11 +3931,13 @@ void WrappedID3D12Device::SetName(ID3D12DeviceChild *pResource, const char *Name template bool WrappedID3D12Device::Serialise_CreateAS(SerialiserType &ser, ID3D12Resource *pResource, - UINT64 resourceOffset, UINT64 byteSize, - D3D12AccelerationStructure *as) + UINT64 resourceOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, + UINT64 byteSize, D3D12AccelerationStructure *as) { SERIALISE_ELEMENT(pResource); SERIALISE_ELEMENT(resourceOffset); + SERIALISE_ELEMENT(type); SERIALISE_ELEMENT(byteSize); SERIALISE_ELEMENT_LOCAL(asId, as->GetResourceID()); @@ -3945,7 +3947,7 @@ bool WrappedID3D12Device::Serialise_CreateAS(SerialiserType &ser, ID3D12Resource { WrappedID3D12Resource *asbWrappedResource = (WrappedID3D12Resource *)pResource; D3D12AccelerationStructure *accStructAtOffset = NULL; - if(asbWrappedResource->CreateAccStruct(resourceOffset, byteSize, &accStructAtOffset)) + if(asbWrappedResource->CreateAccStruct(resourceOffset, type, byteSize, &accStructAtOffset)) { GetResourceManager()->AddLiveResource(asId, accStructAtOffset); @@ -3964,14 +3966,17 @@ bool WrappedID3D12Device::Serialise_CreateAS(SerialiserType &ser, ID3D12Resource return true; } -template bool WrappedID3D12Device::Serialise_CreateAS(ReadSerialiser &ser, ID3D12Resource *pResource, - UINT64 resourceOffset, UINT64 byteSize, - D3D12AccelerationStructure *as); -template bool WrappedID3D12Device::Serialise_CreateAS(WriteSerialiser &ser, ID3D12Resource *pResource, - UINT64 resourceOffset, UINT64 byteSize, - D3D12AccelerationStructure *as); +template bool WrappedID3D12Device::Serialise_CreateAS( + ReadSerialiser &ser, ID3D12Resource *pResource, UINT64 resourceOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, UINT64 byteSize, + D3D12AccelerationStructure *as); +template bool WrappedID3D12Device::Serialise_CreateAS( + WriteSerialiser &ser, ID3D12Resource *pResource, UINT64 resourceOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, UINT64 byteSize, + D3D12AccelerationStructure *as); void WrappedID3D12Device::CreateAS(ID3D12Resource *pResource, UINT64 resourceOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, UINT64 byteSize, D3D12AccelerationStructure *as) { if(IsCaptureMode(m_State)) @@ -3983,7 +3988,7 @@ void WrappedID3D12Device::CreateAS(ID3D12Resource *pResource, UINT64 resourceOff { WriteSerialiser &ser = GetThreadSerialiser(); SCOPED_SERIALISE_CHUNK(D3D12Chunk::CreateAS); - Serialise_CreateAS(ser, pResource, resourceOffset, byteSize, as); + Serialise_CreateAS(ser, pResource, resourceOffset, type, byteSize, as); record->AddChunk(scope.Get()); } } @@ -4777,7 +4782,9 @@ 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); + case D3D12Chunk::CreateAS: + return Serialise_CreateAS(ser, NULL, 0, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL, 0, NULL); case D3D12Chunk::StateObject_SetPipelineStackSize: return Serialise_SetPipelineStackSize(ser, NULL, 0); case D3D12Chunk::Device_CreateRootSignatureFromSubobjectInLibrary: diff --git a/renderdoc/driver/d3d12/d3d12_device.h b/renderdoc/driver/d3d12/d3d12_device.h index 4af5e36fc..0d3cc322c 100644 --- a/renderdoc/driver/d3d12/d3d12_device.h +++ b/renderdoc/driver/d3d12/d3d12_device.h @@ -1334,8 +1334,9 @@ public: const char *Path); IMPLEMENT_FUNCTION_THREAD_SERIALISED(void, CreateAS, ID3D12Resource *pResource, - UINT64 resourceOffset, UINT64 byteSize, - D3D12AccelerationStructure *as); + UINT64 resourceOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, + UINT64 byteSize, D3D12AccelerationStructure *as); // IHV APIs IMPLEMENT_FUNCTION_SERIALISED(void, SetShaderExtUAV, GPUVendor vendor, uint32_t reg, diff --git a/renderdoc/driver/d3d12/d3d12_resources.cpp b/renderdoc/driver/d3d12/d3d12_resources.cpp index 698436bad..763a3a843 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.cpp +++ b/renderdoc/driver/d3d12/d3d12_resources.cpp @@ -141,13 +141,14 @@ ID3D12DeviceChild *Unwrap(ID3D12DeviceChild *ptr) WRAPPED_POOL_INST(D3D12AccelerationStructure); -D3D12AccelerationStructure::D3D12AccelerationStructure(WrappedID3D12Device *wrappedDevice, - WrappedID3D12Resource *bufferRes, - D3D12BufferOffset bufferOffset, - UINT64 byteSize) +D3D12AccelerationStructure::D3D12AccelerationStructure( + WrappedID3D12Device *wrappedDevice, WrappedID3D12Resource *bufferRes, + D3D12BufferOffset bufferOffset, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, + UINT64 byteSize) : WrappedDeviceChild12(NULL, wrappedDevice), m_asbWrappedResource(bufferRes), m_asbWrappedResourceBufferOffset(bufferOffset), + type(type), byteSize(byteSize) { } @@ -158,8 +159,9 @@ D3D12AccelerationStructure::~D3D12AccelerationStructure() Shutdown(); } -bool WrappedID3D12Resource::CreateAccStruct(D3D12BufferOffset bufferOffset, UINT64 byteSize, - D3D12AccelerationStructure **accStruct) +bool WrappedID3D12Resource::CreateAccStruct(D3D12BufferOffset bufferOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, + UINT64 byteSize, D3D12AccelerationStructure **accStruct) { SCOPED_LOCK(m_accStructResourcesCS); auto existing = m_accelerationStructMap.find(bufferOffset); @@ -171,7 +173,7 @@ bool WrappedID3D12Resource::CreateAccStruct(D3D12BufferOffset bufferOffset, UINT } m_accelerationStructMap[bufferOffset] = - new D3D12AccelerationStructure(m_pDevice, this, bufferOffset, byteSize); + new D3D12AccelerationStructure(m_pDevice, this, bufferOffset, type, byteSize); *accStruct = m_accelerationStructMap[bufferOffset]; diff --git a/renderdoc/driver/d3d12/d3d12_resources.h b/renderdoc/driver/d3d12/d3d12_resources.h index b6af58c82..e7ed38c84 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.h +++ b/renderdoc/driver/d3d12/d3d12_resources.h @@ -1332,7 +1332,8 @@ public: return this->GetResourceID(); } - bool CreateAccStruct(D3D12BufferOffset bufferOffset, UINT64 byteSize, + bool CreateAccStruct(D3D12BufferOffset bufferOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, UINT64 byteSize, D3D12AccelerationStructure **accStruct); bool GetAccStructIfExist(D3D12BufferOffset bufferOffset, @@ -1665,7 +1666,8 @@ public: ALLOCATE_WITH_WRAPPED_POOL(D3D12AccelerationStructure); D3D12AccelerationStructure(WrappedID3D12Device *wrappedDevice, WrappedID3D12Resource *bufferRes, - D3D12BufferOffset bufferOffset, UINT64 byteSize); + D3D12BufferOffset bufferOffset, + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, UINT64 byteSize); ~D3D12AccelerationStructure(); @@ -1675,12 +1677,14 @@ public: { return m_asbWrappedResource->GetGPUVirtualAddress() + m_asbWrappedResourceBufferOffset; } + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE Type() const { return type; } ASBuildData *buildData = NULL; private: WrappedID3D12Resource *m_asbWrappedResource; D3D12BufferOffset m_asbWrappedResourceBufferOffset; + D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type; UINT64 byteSize; };