DXR suggests to rebuild the TLAS every frame instead of updating it
| 172 | |
| 173 | // DXR suggests to rebuild the TLAS every frame instead of updating it |
| 174 | ALResult Tr2RtTopLevelAccelerationStructureAL::Update( const size_t count, const Tr2RtInstanceAL* instances, Tr2RenderContextAL& renderContext ) |
| 175 | { |
| 176 | if( !IsValid() ) |
| 177 | { |
| 178 | return E_INVALIDCALL; |
| 179 | } |
| 180 | if( !renderContext.IsValid() ) |
| 181 | { |
| 182 | return E_INVALIDARG; |
| 183 | } |
| 184 | if( m_capacity < count ) |
| 185 | { |
| 186 | return E_INVALIDARG; |
| 187 | } |
| 188 | if( !renderContext.m_commandList4 ) |
| 189 | { |
| 190 | return E_INVALIDCALL; |
| 191 | } |
| 192 | |
| 193 | //if this causes problems then create an array of all the instances.blas buffers fill the uav barrier with that |
| 194 | D3D12_RESOURCE_BARRIER uavBarrier; |
| 195 | uavBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; |
| 196 | uavBarrier.UAV.pResource = nullptr; |
| 197 | uavBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; |
| 198 | renderContext.m_commandList->ResourceBarrier( 1, &uavBarrier ); |
| 199 | |
| 200 | CComPtr<ID3D12Resource> uploadBuffer; |
| 201 | auto completed = m_owner->GetRenderedFrameNumber(); |
| 202 | for( auto it = begin( m_uploadBuffers ); it != end( m_uploadBuffers ); ++it ) |
| 203 | { |
| 204 | if( completed >= it->frameIndex ) |
| 205 | { |
| 206 | uploadBuffer = it->uploadBuffer; |
| 207 | it->frameIndex = m_owner->GetRecordingFrameNumber(); |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | if( !uploadBuffer ) |
| 212 | { |
| 213 | auto uploadHeap = TrinityALImpl::HeapDesc( D3D12_HEAP_TYPE_UPLOAD ); |
| 214 | auto uploadDesc = TrinityALImpl::BufferDesc( sizeof( D3D12_RAYTRACING_INSTANCE_DESC ) * m_capacity, D3D12_RESOURCE_FLAG_NONE ); |
| 215 | CR_RETURN_HR( m_owner->m_device->CreateCommittedResource( |
| 216 | &uploadHeap, |
| 217 | D3D12_HEAP_FLAG_NONE, |
| 218 | &uploadDesc, |
| 219 | D3D12_RESOURCE_STATE_GENERIC_READ, |
| 220 | nullptr, |
| 221 | IID_PPV_ARGS( &uploadBuffer ) ) ); |
| 222 | |
| 223 | UploadBuffer ub = { uploadBuffer, m_owner->GetRecordingFrameNumber() }; |
| 224 | m_uploadBuffers.push_back( ub ); |
| 225 | } |
| 226 | |
| 227 | CR_RETURN_HR( UploadInstanceData( uploadBuffer, count, instances ) ); |
| 228 | |
| 229 | D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS ASInputs = {}; |
| 230 | ASInputs.Type = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL; |
| 231 | ASInputs.DescsLayout = D3D12_ELEMENTS_LAYOUT_ARRAY; |
nothing calls this directly
no test coverage detected