Skip to content

Commit c75c53d

Browse files
[Rendering] Reuse command buffer;
1 parent 67b87c8 commit c75c53d

File tree

11 files changed

+184
-299
lines changed

11 files changed

+184
-299
lines changed

Engine/Staple.Core/Rendering/RenderSystem/Backend/IRenderCommand.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

Engine/Staple.Core/Rendering/RenderSystem/Backend/IRendererBackend.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Numerics;
23

34
namespace Staple.Internal;
45

@@ -22,7 +23,8 @@ internal interface IRendererBackend
2223

2324
void UpdateViewport(int width, int height);
2425

25-
IRenderCommand BeginCommand();
26+
IRenderPass BeginRenderPass(RenderTarget target, CameraClearMode clear, Color clearColor, Vector4 viewport,
27+
Matrix4x4 view, Matrix4x4 projection);
2628

2729
VertexBuffer CreateVertexBuffer(Span<byte> data, VertexLayout layout, RenderBufferFlags flags);
2830

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

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ internal class SDLGPUIndexBuffer : IndexBuffer
1010

1111
private readonly nint device;
1212
private readonly RenderBufferFlags flags;
13-
private readonly Func<SDLGPURenderCommand> commandSupplier;
13+
private readonly SDLGPURendererBackend backend;
1414
private nint transferBuffer;
1515
private int length;
1616

1717
public bool Valid => buffer != nint.Zero && transferBuffer != nint.Zero;
1818

19-
public SDLGPUIndexBuffer(nint device, RenderBufferFlags flags, Func<SDLGPURenderCommand> commandSupplier)
19+
public SDLGPUIndexBuffer(nint device, RenderBufferFlags flags, SDLGPURendererBackend backend)
2020
{
2121
this.device = device;
2222
this.flags = flags;
23-
this.commandSupplier = commandSupplier;
23+
this.backend = backend;
2424

2525
ResourceManager.instance.userCreatedIndexBuffers.Add(new(this));
2626
}
@@ -130,14 +130,14 @@ public override void Update(Span<ushort> data)
130130

131131
ResizeIfNeeded(data.Length * byteSize);
132132

133-
if (Valid == false)
133+
if (Valid == false || backend.TryGetCommandBuffer(out var command) == false)
134134
{
135135
return;
136136
}
137137

138-
var command = commandSupplier();
138+
var copyPass = SDL.SDL_BeginGPUCopyPass(command);
139139

140-
if (command == null)
140+
if (copyPass == nint.Zero)
141141
{
142142
return;
143143
}
@@ -153,15 +153,6 @@ public override void Update(Span<ushort> data)
153153

154154
SDL.SDL_UnmapGPUTransferBuffer(device, transferBuffer);
155155

156-
var copyPass = SDL.SDL_BeginGPUCopyPass(command.commandBuffer);
157-
158-
if (copyPass == nint.Zero)
159-
{
160-
command.Discard();
161-
162-
return;
163-
}
164-
165156
var location = new SDL.SDL_GPUTransferBufferLocation()
166157
{
167158
transfer_buffer = transferBuffer,
@@ -178,8 +169,6 @@ public override void Update(Span<ushort> data)
178169

179170
SDL.SDL_EndGPUCopyPass(copyPass);
180171

181-
command.Submit();
182-
183172
Is32Bit = false;
184173
}
185174

@@ -197,14 +186,7 @@ public override void Update(Span<uint> data)
197186

198187
ResizeIfNeeded(byteSize);
199188

200-
if (Valid == false)
201-
{
202-
return;
203-
}
204-
205-
var command = commandSupplier();
206-
207-
if (command == null)
189+
if (Valid == false || backend.TryGetCommandBuffer(out var command) == false)
208190
{
209191
return;
210192
}
@@ -220,12 +202,10 @@ public override void Update(Span<uint> data)
220202

221203
SDL.SDL_UnmapGPUTransferBuffer(device, transferBuffer);
222204

223-
var copyPass = SDL.SDL_BeginGPUCopyPass(command.commandBuffer);
205+
var copyPass = SDL.SDL_BeginGPUCopyPass(command);
224206

225207
if (copyPass == nint.Zero)
226208
{
227-
command.Discard();
228-
229209
return;
230210
}
231211

@@ -245,8 +225,6 @@ public override void Update(Span<uint> data)
245225

246226
SDL.SDL_EndGPUCopyPass(copyPass);
247227

248-
command.Submit();
249-
250228
Is32Bit = true;
251229
}
252230
}

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

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)