Skip to content

Commit

Permalink
Fixed some buffer data streaming issues causing out of sync buffer si…
Browse files Browse the repository at this point in the history
…zes.
  • Loading branch information
Koderz committed Jun 27, 2023
1 parent 3d71eb7 commit 2343686
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,18 @@ namespace RealtimeMesh
// If we have the stream already, just update it
if (const TSharedPtr<FRealtimeMeshGPUBuffer, ESPMode::ThreadSafe>* FoundBuffer = Streams.Find(StreamData->GetStreamKey()))
{
GPUBuffer = *FoundBuffer;
// We only stream in place if the existing buffer is zero or the same size as the new one
if (FoundBuffer->Get()->Num() == 0 || FoundBuffer->Get()->Num() == StreamData->GetNumElements())
{
GPUBuffer = *FoundBuffer;
}
else
{
(*FoundBuffer)->ReleaseUnderlyingResource();
}
}
else

if (!GPUBuffer)
{
GPUBuffer = StreamData->GetStreamKey().GetStreamType() == ERealtimeMeshStreamType::Vertex
? StaticCastSharedRef<FRealtimeMeshGPUBuffer>(MakeShared<FRealtimeMeshVertexBuffer>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ namespace RealtimeMesh
BatchElement.MinVertexIndex = StreamRange.GetMinVertex();
BatchElement.MaxVertexIndex = StreamRange.GetMaxVertex();

check(BatchElement.FirstIndex >= 0 && BatchElement.NumPrimitives <= (static_cast<const FRealtimeMeshIndexBuffer*>(BatchElement.IndexBuffer)->Num() - BatchElement.FirstIndex) / 3);
check(BatchElement.FirstIndex >= 0 && (int32)BatchElement.NumPrimitives <= StreamRange.NumPrimitives(REALTIME_MESH_NUM_INDICES_PER_PRIMITIVE))
check(BatchElement.MinVertexIndex >= 0 && (int32)BatchElement.MaxVertexIndex <= StreamRange.GetMaxVertex())

BatchElement.MinScreenSize = Params.ScreenSizeLimits.GetLowerBoundValue();
BatchElement.MaxScreenSize = Params.ScreenSizeLimits.GetUpperBoundValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ namespace RealtimeMesh
FRealtimeMeshGPUBuffer::ApplyBufferUpdate(Batcher, UpdateData);
{
Batcher.QueueUpdateRequest(VertexBufferRHI, UpdateData->GetBuffer());

if (ShaderResourceViewRHI)
{
if (UpdateData->GetBuffer().IsValid())
Expand Down

0 comments on commit 2343686

Please sign in to comment.