@@ -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}
0 commit comments