Skip to content

Commit bf1e7af

Browse files
[Rendering] Fixed corrupted renders;
1 parent d72aa89 commit bf1e7af

File tree

2 files changed

+22
-43
lines changed

2 files changed

+22
-43
lines changed

Engine/Staple.Core/Rendering/RenderSystem/Backend/Impls/SDLGPU/SDLGPURendererBackend.cs

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -384,18 +384,27 @@ internal class MemoryAllocator
384384
{
385385
private byte[] buffer = new byte[1024];
386386

387-
public int Position { get; private set; }
387+
internal int position;
388388

389389
public Span<byte> Allocate(int size)
390390
{
391-
if (Position + size >= buffer.Length)
391+
var targetSize = position + size;
392+
393+
if (targetSize >= buffer.Length)
392394
{
393-
Array.Resize(ref buffer, Position + size + 1024);
395+
var newSize = buffer.Length * 2;
396+
397+
while(newSize < targetSize)
398+
{
399+
newSize *= 2;
400+
}
401+
402+
Array.Resize(ref buffer, newSize);
394403
}
395404

396-
var p = Position;
405+
var p = position;
397406

398-
Position += size;
407+
position += size;
399408

400409
return new(buffer, p, size);
401410
}
@@ -412,7 +421,7 @@ public Span<byte> Get(int position, int size)
412421

413422
public void Clear()
414423
{
415-
Position = 0;
424+
position = 0;
416425
}
417426
}
418427

@@ -1486,14 +1495,9 @@ state.indexBuffer is not SDLGPUIndexBuffer index ||
14861495
}
14871496
}
14881497

1489-
if (shader.ShouldPushVertexUniform((byte)pair.Key.binding, pair.Value) == false)
1490-
{
1491-
continue;
1492-
}
1493-
14941498
unsafe
14951499
{
1496-
var position = frameAllocator.Position;
1500+
var position = frameAllocator.position;
14971501
var copy = frameAllocator.Allocate(pair.Value.Length);
14981502

14991503
fixed (void* source = pair.Value)
@@ -1539,14 +1543,9 @@ state.indexBuffer is not SDLGPUIndexBuffer index ||
15391543
}
15401544
}
15411545

1542-
if (shader.ShouldPushFragmentUniform((byte)pair.Key.binding, pair.Value) == false)
1543-
{
1544-
continue;
1545-
}
1546-
15471546
unsafe
15481547
{
1549-
var position = frameAllocator.Position;
1548+
var position = frameAllocator.position;
15501549
var copy = frameAllocator.Allocate(pair.Value.Length);
15511550

15521551
fixed (void* source = pair.Value)
@@ -1652,14 +1651,9 @@ public void RenderTransient<T>(Span<T> vertices, VertexLayout layout, Span<ushor
16521651
}
16531652
}
16541653

1655-
if(shader.ShouldPushVertexUniform((byte)pair.Key.binding, pair.Value) == false)
1656-
{
1657-
continue;
1658-
}
1659-
16601654
unsafe
16611655
{
1662-
var position = frameAllocator.Position;
1656+
var position = frameAllocator.position;
16631657
var copy = frameAllocator.Allocate(pair.Value.Length);
16641658

16651659
fixed (void* source = pair.Value)
@@ -1705,14 +1699,9 @@ public void RenderTransient<T>(Span<T> vertices, VertexLayout layout, Span<ushor
17051699
}
17061700
}
17071701

1708-
if (shader.ShouldPushFragmentUniform((byte)pair.Key.binding, pair.Value) == false)
1709-
{
1710-
continue;
1711-
}
1712-
17131702
unsafe
17141703
{
1715-
var position = frameAllocator.Position;
1704+
var position = frameAllocator.position;
17161705
var copy = frameAllocator.Allocate(pair.Value.Length);
17171706

17181707
fixed (void* source = pair.Value)
@@ -1819,14 +1808,9 @@ public void RenderTransient<T>(Span<T> vertices, VertexLayout layout, Span<uint>
18191808
}
18201809
}
18211810

1822-
if (shader.ShouldPushVertexUniform((byte)pair.Key.binding, pair.Value) == false)
1823-
{
1824-
continue;
1825-
}
1826-
18271811
unsafe
18281812
{
1829-
var position = frameAllocator.Position;
1813+
var position = frameAllocator.position;
18301814
var copy = frameAllocator.Allocate(pair.Value.Length);
18311815

18321816
fixed (void* source = pair.Value)
@@ -1872,14 +1856,9 @@ public void RenderTransient<T>(Span<T> vertices, VertexLayout layout, Span<uint>
18721856
}
18731857
}
18741858

1875-
if (shader.ShouldPushFragmentUniform((byte)pair.Key.binding, pair.Value) == false)
1876-
{
1877-
continue;
1878-
}
1879-
18801859
unsafe
18811860
{
1882-
var position = frameAllocator.Position;
1861+
var position = frameAllocator.position;
18831862
var copy = frameAllocator.Allocate(pair.Value.Length);
18841863

18851864
fixed (void *source = pair.Value)

Engine/Staple.Editor/StapleEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public void WorldChanged()
305305

306306
private Mesh gridMesh;
307307

308-
private readonly ComponentVersionTracker sceneTransformTracker = new();
308+
private readonly ComponentVersionTracker<Transform> sceneTransformTracker = new();
309309

310310
private readonly RenderQueue renderQueue = new();
311311
#endregion

0 commit comments

Comments
 (0)