void FD3D12DynamicRHI::UnlockBuffer(FRHICommandListImmediate* RHICmdList, BufferType* Buffer) { // Find the outstanding lock for this Buffer. FD3D12LockedKey LockedKey(Buffer); FD3D12LockedData* LockedData = FindInOutstandingLocks(LockedKey); check(LockedData); // Determine whether the buffer is dynamic or not. const bool bIsDynamic = (Buffer->GetUsage() & BUF_AnyDynamic) ? true : false; if (bIsDynamic) { // If the Buffer is dynamic, its upload heap memory can always stay mapped. Don't do anything. } else { // If the static Buffer lock involved a staging resource, it was locked for reading. if (LockedData->StagingResource) { // Unmap the staging buffer's memory. ID3D12Resource* StagingBuffer = LockedData->StagingResource.GetReference()->GetResource(); StagingBuffer->Unmap(0, nullptr); } else { // Copy the contents of the temporary memory buffer allocated for writing into the Buffer. FD3D12ResourceLocation* UploadHeapLocation = LockedData->UploadHeapLocation.GetReference(); // If we are on the render thread, queue up the copy on the RHIThread so it happens at the correct time. if (ShouldDeferBufferLockOperation(RHICmdList)) { new (RHICmdList->AllocCommand<FRHICommandUpdateBuffer>()) FRHICommandUpdateBuffer(Buffer->ResourceLocation, UploadHeapLocation, LockedData->Pitch); } else { UpdateBuffer(Buffer->ResourceLocation->GetResource(), Buffer->ResourceLocation->GetOffset(), UploadHeapLocation->GetResource(), UploadHeapLocation->GetOffset(), LockedData->Pitch); } } } // Remove the FD3D12LockedData from the lock map. // If the lock involved a staging resource, this releases it. RemoveFromOutstandingLocks(LockedKey); }
void Execute(FRHICommandListBase& CmdList) { FD3D12DynamicRHI::GetD3DRHI()->UpdateBuffer(Destination->GetResource(), Destination->GetOffsetFromBaseOfResource() + DestinationOffset, Source.GetResource(), Source.GetOffsetFromBaseOfResource(), NumBytes); }