@@ -377,7 +377,6 @@ RaytracingContext::SetupModel(const Graphics::GraphicsEntityId id, CoreGraphics:
377377 state.objects .Extend ((SizeT)alloc.offset + numObjects);
378378
379379 // Create bogus constants
380- /*
381380 for (uint i = 0 ; i < numObjects; i++)
382381 {
383382 Raytracetest::TlasInstance constants;
@@ -387,9 +386,8 @@ RaytracingContext::SetupModel(const Graphics::GraphicsEntityId id, CoreGraphics:
387386 constants.Use16BitIndex = false ;
388387 constants.AttributeStride = 0 ;
389388 constants.VertexLayout = (uint)CoreGraphics::VertexLayoutType::Normal;
390- state.objects[alloc.offset + i] = constants;
389+ state.objects [(uint) alloc.offset + i] = constants;
391390 }
392- */
393391
394392 raytracingContextAllocator.Set <Raytracing_Allocation>(contextId.id , alloc);
395393 raytracingContextAllocator.Set <Raytracing_NumStructures>(contextId.id , numObjects);
@@ -848,7 +846,7 @@ RaytracingContext::Dealloc(Graphics::ContextEntityId id)
848846 // clean up old stuff, but don't deallocate entity
849847 Memory::RangeAllocation range = raytracingContextAllocator.Get <Raytracing_Allocation>(id.id );
850848 SizeT numAllocs = raytracingContextAllocator.Get <Raytracing_NumStructures>(id.id );
851- for (IndexT i = (uint)range.offset ; i < numAllocs; i++)
849+ for (IndexT i = (uint)range.offset ; i < range. offset + numAllocs; i++)
852850 {
853851 CoreGraphics::BlasInstanceIdLock _0 (state.blasInstances [i]);
854852 CoreGraphics::DestroyBlasInstance (state.blasInstances [i]);
@@ -861,6 +859,8 @@ RaytracingContext::Dealloc(Graphics::ContextEntityId id)
861859 if (index != InvalidIndex)
862860 {
863861 auto & [refCount, blases] = state.blasLookup .ValueAtIndex (mesh, index);
862+
863+ // If this is the last count, nuke the BLAS
864864 if (refCount == 1 )
865865 {
866866 for (auto blas : blases)
@@ -880,6 +880,10 @@ RaytracingContext::Dealloc(Graphics::ContextEntityId id)
880880 CoreGraphics::DestroyBlas (blases[j]);
881881 }
882882 }
883+ for (SizeT j = 0 ; j < state.blasInstanceBuffer .hostBuffers .buffers .Size (); j++)
884+ {
885+ CoreGraphics::BlasInstanceUpdate (state.blasInstances [(uint)i], state.blasInstanceBuffer .hostBuffers .buffers [j], i * CoreGraphics::BlasInstanceGetSize ());
886+ }
883887 state.blasInstances [i] = CoreGraphics::InvalidBlasInstanceId;
884888 }
885889
0 commit comments