forked from FNA-XNA/FNA3D
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFNA3D_Driver_SDL.c
More file actions
4533 lines (3909 loc) · 123 KB
/
FNA3D_Driver_SDL.c
File metadata and controls
4533 lines (3909 loc) · 123 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* FNA3D - 3D Graphics Library for FNA
*
* Copyright (c) 2020-2024 Ethan Lee
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
* Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
*
*/
#if FNA3D_DRIVER_SDL
#include <SDL3/SDL.h>
#include "FNA3D_Driver.h"
#include "FNA3D_PipelineCache.h"
#define MAX_FRAMES_IN_FLIGHT 3
#define MAX_UPLOAD_CYCLE_COUNT 4
#define TRANSFER_BUFFER_SIZE 16777216 /* 16 MiB */
static inline SDL_GPUSampleCount XNAToSDL_SampleCount(int32_t sampleCount)
{
if (sampleCount <= 1)
{
return SDL_GPU_SAMPLECOUNT_1;
}
else if (sampleCount == 2)
{
return SDL_GPU_SAMPLECOUNT_2;
}
else if (sampleCount <= 4)
{
return SDL_GPU_SAMPLECOUNT_4;
}
else if (sampleCount <= 8)
{
return SDL_GPU_SAMPLECOUNT_8;
}
else
{
FNA3D_LogWarn("Unexpected sample count: %d", sampleCount);
return SDL_GPU_SAMPLECOUNT_1;
}
}
static inline float XNAToSDL_DepthBiasScale(SDL_GPUTextureFormat format)
{
switch (format)
{
case SDL_GPU_TEXTUREFORMAT_D16_UNORM:
return (float) ((1 << 16) - 1);
case SDL_GPU_TEXTUREFORMAT_D32_FLOAT:
case SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT:
return (float) ((1 << 23) - 1);
case SDL_GPU_TEXTUREFORMAT_D24_UNORM:
case SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT:
return (float) ((1 << 24) - 1);
default:
return 0.0f;
}
}
static inline uint32_t SDLGPU_INTERNAL_RoundToAlignment(
uint32_t value,
uint32_t alignment
) {
return alignment * ((value + alignment - 1) / alignment);
}
static SDL_GPUTextureFormat XNAToSDL_SurfaceFormat[] =
{
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, /* SurfaceFormat.Color */
SDL_GPU_TEXTUREFORMAT_B5G6R5_UNORM, /* SurfaceFormat.Bgr565 */
SDL_GPU_TEXTUREFORMAT_B5G5R5A1_UNORM, /* SurfaceFormat.Bgra5551 */
SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM, /* SurfaceFormat.Bgra4444 */
SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM, /* SurfaceFormat.Dxt1 */
SDL_GPU_TEXTUREFORMAT_BC2_RGBA_UNORM, /* SurfaceFormat.Dxt3 */
SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM, /* SurfaceFormat.Dxt5 */
SDL_GPU_TEXTUREFORMAT_R8G8_SNORM, /* SurfaceFormat.NormalizedByte2 */
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_SNORM, /* SurfaceFormat.NormalizedByte4 */
SDL_GPU_TEXTUREFORMAT_R10G10B10A2_UNORM, /* SurfaceFormat.Rgba1010102 */
SDL_GPU_TEXTUREFORMAT_R16G16_UNORM, /* SurfaceFormat.Rg32 */
SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UNORM, /* SurfaceFormat.Rgba64 */
SDL_GPU_TEXTUREFORMAT_A8_UNORM, /* SurfaceFormat.Alpha8 */
SDL_GPU_TEXTUREFORMAT_R32_FLOAT, /* SurfaceFormat.Single */
SDL_GPU_TEXTUREFORMAT_R32G32_FLOAT, /* SurfaceFormat.Vector2 */
SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT, /* SurfaceFormat.Vector4 */
SDL_GPU_TEXTUREFORMAT_R16_FLOAT, /* SurfaceFormat.HalfSingle */
SDL_GPU_TEXTUREFORMAT_R16G16_FLOAT, /* SurfaceFormat.HalfVector2 */
SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT, /* SurfaceFormat.HalfVector4 */
SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT, /* SurfaceFormat.HdrBlendable */
SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM, /* SurfaceFormat.ColorBgraEXT */
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB, /* SurfaceFormat.ColorSrgbEXT */
SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM_SRGB, /* SurfaceFormat.Dxt5SrgbEXT */
SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM, /* SurfaceFormat.Bc7EXT */
SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM_SRGB, /* SurfaceFormat.Bc7SrgbEXT */
SDL_GPU_TEXTUREFORMAT_R8_UNORM, /* SurfaceFormat.NormalizedByteEXT */
SDL_GPU_TEXTUREFORMAT_R16_UNORM, /* SurfaceFormat.NormalizedUShortEXT */
};
static SDL_GPUPrimitiveType XNAToSDL_PrimitiveType[] =
{
SDL_GPU_PRIMITIVETYPE_TRIANGLELIST, /* FNA3D_PRIMITIVETYPE_TRIANGLELIST */
SDL_GPU_PRIMITIVETYPE_TRIANGLESTRIP, /* FNA3D_PRIMITIVETYPE_TRIANGLESTRIP */
SDL_GPU_PRIMITIVETYPE_LINELIST, /* FNA3D_PRIMITIVETYPE_LINELIST */
SDL_GPU_PRIMITIVETYPE_LINESTRIP, /* FNA3D_PRIMITIVETYPE_LINESTRIP */
SDL_GPU_PRIMITIVETYPE_POINTLIST /* FNA3D_PRIMITIVETYPE_POINTLIST_EXT */
};
static SDL_GPUIndexElementSize XNAToSDL_IndexElementSize[] =
{
SDL_GPU_INDEXELEMENTSIZE_16BIT, /* FNA3D_INDEXELEMENTSIZE_16BIT */
SDL_GPU_INDEXELEMENTSIZE_32BIT /* FNA3D_INDEXELEMENTSIZE_32BIT */
};
static SDL_GPUBlendFactor XNAToSDL_BlendFactor[] =
{
SDL_GPU_BLENDFACTOR_ONE, /* FNA3D_BLEND_ONE */
SDL_GPU_BLENDFACTOR_ZERO, /* FNA3D_BLEND_ZERO */
SDL_GPU_BLENDFACTOR_SRC_COLOR, /* FNA3D_BLEND_SOURCECOLOR */
SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_COLOR, /* FNA3D_BLEND_INVERSESOURCECOLOR */
SDL_GPU_BLENDFACTOR_SRC_ALPHA, /* FNA3D_BLEND_SOURCEALPHA */
SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, /* FNA3D_BLEND_INVERSESOURCEALPHA */
SDL_GPU_BLENDFACTOR_DST_COLOR, /* FNA3D_BLEND_DESTINATIONCOLOR */
SDL_GPU_BLENDFACTOR_ONE_MINUS_DST_COLOR, /* FNA3D_BLEND_INVERSEDESTINATIONCOLOR */
SDL_GPU_BLENDFACTOR_DST_ALPHA, /* FNA3D_BLEND_DESTINATIONALPHA */
SDL_GPU_BLENDFACTOR_ONE_MINUS_DST_ALPHA, /* FNA3D_BLEND_INVERSEDESTINATIONALPHA */
SDL_GPU_BLENDFACTOR_CONSTANT_COLOR, /* FNA3D_BLEND_BLENDFACTOR */
SDL_GPU_BLENDFACTOR_ONE_MINUS_CONSTANT_COLOR, /* FNA3D_BLEND_INVERSEBLENDFACTOR */
SDL_GPU_BLENDFACTOR_SRC_ALPHA_SATURATE /* FNA3D_BLEND_SOURCEALPHASATURATION */
};
static SDL_GPUBlendOp XNAToSDL_BlendOp[] =
{
SDL_GPU_BLENDOP_ADD, /* FNA3D_BLENDFUNCTION_ADD */
SDL_GPU_BLENDOP_SUBTRACT, /* FNA3D_BLENDFUNCTION_SUBTRACT */
SDL_GPU_BLENDOP_REVERSE_SUBTRACT, /* FNA3D_BLENDFUNCTION_REVERSESUBTRACT */
SDL_GPU_BLENDOP_MAX, /* FNA3D_BLENDFUNCTION_MAX */
SDL_GPU_BLENDOP_MIN /* FNA3D_BLENDFUNCTION_MIN */
};
static SDL_GPUFilter XNAToSDL_MagFilter[] =
{
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_LINEAR */
SDL_GPU_FILTER_NEAREST, /* FNA3D_TEXTUREFILTER_POINT */
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_ANISOTROPIC */
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_LINEAR_MIPPOINT */
SDL_GPU_FILTER_NEAREST, /* FNA3D_TEXTUREFILTER_POINT_MIPLINEAR */
SDL_GPU_FILTER_NEAREST, /* FNA3D_TEXTUREFILTER_MINLINEAR_MAGPOINT_MIPLINEAR */
SDL_GPU_FILTER_NEAREST, /* FNA3D_TEXTUREFILTER_MINLINEAR_MAGPOINT_MIPPOINT */
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_MINPOINT_MAGLINEAR_MIPLINEAR */
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_MINPOINT_MAGLINEAR_MIPPOINT */
};
static SDL_GPUFilter XNAToSDL_MinFilter[] =
{
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_LINEAR */
SDL_GPU_FILTER_NEAREST, /* FNA3D_TEXTUREFILTER_POINT */
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_ANISOTROPIC */
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_LINEAR_MIPPOINT */
SDL_GPU_FILTER_NEAREST, /* FNA3D_TEXTUREFILTER_POINT_MIPLINEAR */
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_MINLINEAR_MAGPOINT_MIPLINEAR */
SDL_GPU_FILTER_LINEAR, /* FNA3D_TEXTUREFILTER_MINLINEAR_MAGPOINT_MIPPOINT */
SDL_GPU_FILTER_NEAREST, /* FNA3D_TEXTUREFILTER_MINPOINT_MAGLINEAR_MIPLINEAR */
SDL_GPU_FILTER_NEAREST, /* FNA3D_TEXTUREFILTER_MINPOINT_MAGLINEAR_MIPPOINT */
};
static SDL_GPUSamplerMipmapMode XNAToSDL_MipFilter[] =
{
SDL_GPU_SAMPLERMIPMAPMODE_LINEAR, /* FNA3D_TEXTUREFILTER_LINEAR */
SDL_GPU_SAMPLERMIPMAPMODE_NEAREST, /* FNA3D_TEXTUREFILTER_POINT */
SDL_GPU_SAMPLERMIPMAPMODE_LINEAR, /* FNA3D_TEXTUREFILTER_ANISOTROPIC */
SDL_GPU_SAMPLERMIPMAPMODE_NEAREST, /* FNA3D_TEXTUREFILTER_LINEAR_MIPPOINT */
SDL_GPU_SAMPLERMIPMAPMODE_LINEAR, /* FNA3D_TEXTUREFILTER_POINT_MIPLINEAR */
SDL_GPU_SAMPLERMIPMAPMODE_LINEAR, /* FNA3D_TEXTUREFILTER_MINLINEAR_MAGPOINT_MIPLINEAR */
SDL_GPU_SAMPLERMIPMAPMODE_NEAREST, /* FNA3D_TEXTUREFILTER_MINLINEAR_MAGPOINT_MIPPOINT */
SDL_GPU_SAMPLERMIPMAPMODE_LINEAR, /* FNA3D_TEXTUREFILTER_MINPOINT_MAGLINEAR_MIPLINEAR */
SDL_GPU_SAMPLERMIPMAPMODE_NEAREST, /* FNA3D_TEXTUREFILTER_MINPOINT_MAGLINEAR_MIPPOINT */
};
static SDL_GPUSamplerAddressMode XNAToSDL_SamplerAddressMode[] =
{
SDL_GPU_SAMPLERADDRESSMODE_REPEAT, /* FNA3D_TEXTUREADDRESSMODE_WRAP */
SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE, /* FNA3D_TEXTUREADDRESSMODE_CLAMP */
SDL_GPU_SAMPLERADDRESSMODE_MIRRORED_REPEAT /* FNA3D_TEXTUREADDRESSMODE_MIRROR */
};
static SDL_GPUVertexElementFormat XNAToSDL_VertexAttribType[] =
{
SDL_GPU_VERTEXELEMENTFORMAT_FLOAT, /* FNA3D_VERTEXELEMENTFORMAT_SINGLE */
SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2, /* FNA3D_VERTEXELEMENTFORMAT_VECTOR2 */
SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, /* FNA3D_VERTEXELEMENTFORMAT_VECTOR3 */
SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4, /* FNA3D_VERTEXELEMENTFORMAT_VECTOR4 */
SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM, /* FNA3D_VERTEXELEMENTFORMAT_COLOR */
SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4, /* FNA3D_VERTEXELEMENTFORMAT_BYTE4 */
SDL_GPU_VERTEXELEMENTFORMAT_SHORT2, /* FNA3D_VERTEXELEMENTFORMAT_SHORT2 */
SDL_GPU_VERTEXELEMENTFORMAT_SHORT4, /* FNA3D_VERTEXELEMENTFORMAT_SHORT4 */
SDL_GPU_VERTEXELEMENTFORMAT_SHORT2_NORM, /* FNA3D_VERTEXELEMENTFORMAT_NORMALIZEDSHORT2 */
SDL_GPU_VERTEXELEMENTFORMAT_SHORT4_NORM, /* FNA3D_VERTEXELEMENTFORMAT_NORMALIZEDSHORT4 */
SDL_GPU_VERTEXELEMENTFORMAT_HALF2, /* FNA3D_VERTEXELEMENTFORMAT_HALFVECTOR2 */
SDL_GPU_VERTEXELEMENTFORMAT_HALF4 /* FNA3D_VERTEXELEMENTFORMAT_HALFVECTOR4 */
};
static SDL_GPUFillMode XNAToSDL_FillMode[] =
{
SDL_GPU_FILLMODE_FILL, /* FNA3D_FILLMODE_SOLID */
SDL_GPU_FILLMODE_LINE /* FNA3D_FILLMODE_WIREFRAME */
};
static SDL_GPUCullMode XNAToSDL_CullMode[] =
{
SDL_GPU_CULLMODE_NONE, /* FNA3D_CULLMODE_NONE */
SDL_GPU_CULLMODE_FRONT, /* FNA3D_CULLMODE_CULLCLOCKWISEFACE */
SDL_GPU_CULLMODE_BACK /* FNA3D_CULLMODE_CULLCOUNTERCLOCKWISEFACE */
};
static SDL_GPUCompareOp XNAToSDL_CompareOp[] =
{
SDL_GPU_COMPAREOP_ALWAYS, /* FNA3D_COMPAREFUNCTION_ALWAYS */
SDL_GPU_COMPAREOP_NEVER, /* FNA3D_COMPAREFUNCTION_NEVER */
SDL_GPU_COMPAREOP_LESS, /* FNA3D_COMPAREFUNCTION_LESS */
SDL_GPU_COMPAREOP_LESS_OR_EQUAL, /* FNA3D_COMPAREFUNCTION_LESSEQUAL */
SDL_GPU_COMPAREOP_EQUAL, /* FNA3D_COMPAREFUNCTION_EQUAL */
SDL_GPU_COMPAREOP_GREATER_OR_EQUAL, /* FNA3D_COMPAREFUNCTION_GREATEREQUAL */
SDL_GPU_COMPAREOP_GREATER, /* FNA3D_COMPAREFUNCTION_GREATER */
SDL_GPU_COMPAREOP_NOT_EQUAL /* FNA3D_COMPAREFUNCTION_NOTEQUAL */
};
static SDL_GPUStencilOp XNAToSDL_StencilOp[] =
{
SDL_GPU_STENCILOP_KEEP, /* FNA3D_STENCILOPERATION_KEEP */
SDL_GPU_STENCILOP_ZERO, /* FNA3D_STENCILOPERATION_ZERO */
SDL_GPU_STENCILOP_REPLACE, /* FNA3D_STENCILOPERATION_REPLACE */
SDL_GPU_STENCILOP_INCREMENT_AND_WRAP, /* FNA3D_STENCILOPERATION_INCREMENT */
SDL_GPU_STENCILOP_DECREMENT_AND_WRAP, /* FNA3D_STENCILOPERATION_DECREMENT */
SDL_GPU_STENCILOP_INCREMENT_AND_CLAMP, /* FNA3D_STENCILOPERATION_INCREMENTSATURATION */
SDL_GPU_STENCILOP_DECREMENT_AND_CLAMP, /* FNA3D_STENCILOPERATION_DECREMENTSATURATION */
SDL_GPU_STENCILOP_INVERT /* FNA3D_STENCILOPERATION_INVERT */
};
static inline bool XNAToSDL_PresentMode(
SDL_GPUDevice *device,
SDL_Window *window,
FNA3D_PresentInterval interval,
SDL_GPUPresentMode *presentMode
) {
if (
interval == FNA3D_PRESENTINTERVAL_DEFAULT ||
interval == FNA3D_PRESENTINTERVAL_ONE )
{
if (SDL_GetHintBoolean("FNA3D_VULKAN_FORCE_MAILBOX_VSYNC", 0))
{
*presentMode = SDL_GPU_PRESENTMODE_MAILBOX;
if (!SDL_WindowSupportsGPUPresentMode(device, window, *presentMode))
{
*presentMode = SDL_GPU_PRESENTMODE_VSYNC;
}
}
else
{
*presentMode = SDL_GPU_PRESENTMODE_VSYNC;
}
return true;
}
else if (interval == FNA3D_PRESENTINTERVAL_IMMEDIATE)
{
*presentMode = SDL_GPU_PRESENTMODE_IMMEDIATE;
if (!SDL_WindowSupportsGPUPresentMode(device, window, *presentMode))
{
*presentMode = SDL_GPU_PRESENTMODE_VSYNC;
}
return true;
}
else if (interval == FNA3D_PRESENTINTERVAL_TWO)
{
FNA3D_LogError("FNA3D_PRESENTINTERVAL_TWO not supported by SDL GPU backend!");
return false;
}
else
{
FNA3D_LogError("Unrecognized presentation interval!");
return false;
}
}
/* Indirection to cleanly handle Renderbuffers */
typedef struct SDLGPU_TextureHandle /* Cast from FNA3D_Texture* */
{
SDL_GPUTexture *texture;
SDL_GPUTextureCreateInfo createInfo;
uint8_t boundAsRenderTarget;
} SDLGPU_TextureHandle;
typedef struct SDLGPU_Renderbuffer /* Cast from FNA3D_Renderbuffer* */
{
SDLGPU_TextureHandle *textureHandle;
SDL_GPUTextureFormat format;
SDL_GPUSampleCount sampleCount;
} SDLGPU_Renderbuffer;
typedef struct SDLGPU_Effect /* Cast from FNA3D_Effect* */
{
MOJOSHADER_effect *effect;
} SDLGPU_Effect;
typedef struct SDLGPU_BufferHandle /* Cast from FNA3D_Buffer* */
{
SDL_GPUBuffer *buffer;
uint32_t size;
} SDLGPU_BufferHandle;
typedef struct SamplerStateHashMap
{
PackedState key;
SDL_GPUSampler *value;
} SamplerStateHashMap;
typedef struct SamplerStateHashArray
{
SamplerStateHashMap *elements;
int32_t count;
int32_t capacity;
} SamplerStateHashArray;
static inline SDL_GPUSampler* SamplerStateHashArray_Fetch(
SamplerStateHashArray *arr,
PackedState key
) {
int32_t i;
for (i = 0; i < arr->count; i += 1)
{
if ( key.a == arr->elements[i].key.a &&
key.b == arr->elements[i].key.b )
{
return arr->elements[i].value;
}
}
return NULL;
}
static inline void SamplerStateHashArray_Insert(
SamplerStateHashArray *arr,
PackedState key,
SDL_GPUSampler *value
) {
SamplerStateHashMap map;
map.key.a = key.a;
map.key.b = key.b;
map.value = value;
EXPAND_ARRAY_IF_NEEDED(arr, 4, SamplerStateHashMap)
arr->elements[arr->count] = map;
arr->count += 1;
}
/* FIXME: This could be packed better */
typedef struct GraphicsPipelineHash
{
PackedState blendState;
PackedState rasterizerState;
PackedState depthStencilState;
uint32_t vertexBufferBindingsIndex;
FNA3D_PrimitiveType primitiveType;
SDL_GPUSampleCount sampleCount;
uint32_t sampleMask;
SDL_GPUShader *vertShader;
SDL_GPUShader *fragShader;
SDL_GPUTextureFormat colorFormats[MAX_RENDERTARGET_BINDINGS];
uint32_t colorFormatCount;
bool hasDepthStencilAttachment;
SDL_GPUTextureFormat depthStencilFormat;
} GraphicsPipelineHash;
typedef struct GraphicsPipelineHashMap
{
GraphicsPipelineHash key;
SDL_GPUGraphicsPipeline *value;
} GraphicsPipelineHashMap;
typedef struct GraphicsPipelineHashArray
{
GraphicsPipelineHashMap *elements;
int32_t count;
int32_t capacity;
} GraphicsPipelineHashArray;
#define NUM_PIPELINE_HASH_BUCKETS 1031
typedef struct GraphicsPipelineHashTable
{
GraphicsPipelineHashArray buckets[NUM_PIPELINE_HASH_BUCKETS];
} GraphicsPipelineHashTable;
static inline uint64_t GraphicsPipelineHashTable_GetHashCode(GraphicsPipelineHash hash)
{
/* The algorithm for this hashing function
* is taken from Josh Bloch's "Effective Java".
* (https://stackoverflow.com/a/113600/12492383)
*/
const uint64_t HASH_FACTOR = 97;
uint32_t i;
uint64_t result = 1;
result = result * HASH_FACTOR + hash.blendState.a;
result = result * HASH_FACTOR + hash.blendState.b;
result = result * HASH_FACTOR + hash.rasterizerState.a;
result = result * HASH_FACTOR + hash.rasterizerState.b;
result = result * HASH_FACTOR + hash.depthStencilState.a;
result = result * HASH_FACTOR + hash.depthStencilState.b;
result = result * HASH_FACTOR + hash.vertexBufferBindingsIndex;
result = result * HASH_FACTOR + hash.primitiveType;
result = result * HASH_FACTOR + hash.sampleCount;
result = result * HASH_FACTOR + hash.sampleMask;
result = result * HASH_FACTOR + (uint64_t) (size_t) hash.vertShader;
result = result * HASH_FACTOR + (uint64_t) (size_t) hash.fragShader;
result = result * HASH_FACTOR + hash.colorFormatCount;
for (i = 0; i < MAX_RENDERTARGET_BINDINGS; i += 1)
{
result = result * HASH_FACTOR + hash.colorFormats[i];
}
result = result * HASH_FACTOR + hash.hasDepthStencilAttachment;
result = result * HASH_FACTOR + hash.depthStencilFormat;
return result;
}
static inline SDL_GPUGraphicsPipeline *GraphicsPipelineHashTable_Fetch(
GraphicsPipelineHashTable *table,
GraphicsPipelineHash key
) {
int32_t i;
uint64_t hashcode = GraphicsPipelineHashTable_GetHashCode(key);
GraphicsPipelineHashArray *arr = &table->buckets[hashcode % NUM_PIPELINE_HASH_BUCKETS];
for (i = 0; i < arr->count; i += 1)
{
const GraphicsPipelineHash *e = &arr->elements[i].key;
if ( key.blendState.a == e->blendState.a &&
key.blendState.b == e->blendState.b &&
key.rasterizerState.a == e->rasterizerState.a &&
key.rasterizerState.b == e->rasterizerState.b &&
key.depthStencilState.a == e->depthStencilState.a &&
key.depthStencilState.b == e->depthStencilState.b &&
key.vertexBufferBindingsIndex == e->vertexBufferBindingsIndex &&
key.primitiveType == e->primitiveType &&
key.sampleMask == e->sampleMask &&
key.vertShader == e->vertShader &&
key.fragShader == e->fragShader &&
key.colorFormatCount == e->colorFormatCount &&
key.colorFormats[0] == e->colorFormats[0] &&
key.colorFormats[1] == e->colorFormats[1] &&
key.colorFormats[2] == e->colorFormats[2] &&
key.colorFormats[3] == e->colorFormats[3] &&
key.hasDepthStencilAttachment == e->hasDepthStencilAttachment &&
key.depthStencilFormat == e->depthStencilFormat )
{
return arr->elements[i].value;
}
}
return NULL;
}
static inline void GraphicsPipelineHashTable_Insert(
GraphicsPipelineHashTable *table,
GraphicsPipelineHash key,
SDL_GPUGraphicsPipeline *value
) {
uint64_t hashcode = GraphicsPipelineHashTable_GetHashCode(key);
GraphicsPipelineHashArray *arr = &table->buckets[hashcode % NUM_PIPELINE_HASH_BUCKETS];
GraphicsPipelineHashMap map;
map.key = key;
map.value = value;
EXPAND_ARRAY_IF_NEEDED(arr, 2, GraphicsPipelineHashMap)
arr->elements[arr->count] = map;
arr->count += 1;
}
typedef struct SDLGPU_Renderer
{
SDL_GPUDevice *device;
SDL_GPUCommandBuffer *renderCommandBuffer;
SDL_GPUCommandBuffer *uploadCommandBuffer;
SDL_GPURenderPass *renderPass;
uint8_t needNewRenderPass;
SDL_GPUCopyPass *copyPass;
SDL_Mutex *copyPassMutex;
uint8_t shouldClearColorOnBeginPass;
uint8_t shouldClearDepthOnBeginPass;
uint8_t shouldClearStencilOnBeginPass;
SDL_FColor clearColorValue;
float clearDepthValue;
Uint8 clearStencilValue;
/* Defer render pass settings */
SDLGPU_TextureHandle *nextRenderPassColorAttachments[MAX_RENDERTARGET_BINDINGS];
SDLGPU_TextureHandle *nextRenderPassColorResolves[MAX_RENDERTARGET_BINDINGS];
SDL_GPUCubeMapFace nextRenderPassColorAttachmentCubeFace[MAX_RENDERTARGET_BINDINGS];
uint32_t nextRenderPassColorAttachmentCount;
SDL_GPUSampleCount nextRenderPassMultisampleCount;
SDLGPU_TextureHandle *nextRenderPassDepthStencilAttachment; /* may be NULL */
uint8_t renderTargetInUse;
uint8_t needNewGraphicsPipeline;
int32_t currentVertexBufferBindingsIndex;
SDL_GPUGraphicsPipeline *currentGraphicsPipeline;
MOJOSHADER_sdlShaderData *currentVertexShader;
MOJOSHADER_sdlShaderData *currentFragmentShader;
PackedVertexBufferBindingsArray vertexBufferBindingsCache;
FNA3D_Viewport viewport;
/* Vertex buffer bind settings */
uint32_t numVertexBindings;
FNA3D_VertexBufferBinding vertexBindings[MAX_BOUND_VERTEX_BUFFERS];
FNA3D_VertexElement vertexElements[MAX_BOUND_VERTEX_BUFFERS][MAX_VERTEX_ATTRIBUTES];
SDL_GPUBufferBinding vertexBufferBindings[MAX_BOUND_VERTEX_BUFFERS];
uint8_t needVertexBufferBind;
/* Index buffer state shadowing */
SDL_GPUBufferBinding indexBufferBinding;
/* Sampler bind settings */
SDL_GPUTextureSamplerBinding vertexTextureSamplerBindings[MAX_VERTEXTEXTURE_SAMPLERS];
uint8_t needVertexSamplerBind;
SDL_GPUTextureSamplerBinding fragmentTextureSamplerBindings[MAX_TEXTURE_SAMPLERS];
uint8_t needFragmentSamplerBind;
/* Pipeline state */
FNA3D_BlendState fnaBlendState;
FNA3D_RasterizerState fnaRasterizerState;
FNA3D_DepthStencilState fnaDepthStencilState;
FNA3D_PrimitiveType fnaPrimitiveType;
float blendConstants[4];
SDL_FColor currentBlendConstants;
uint32_t stencilReference;
uint32_t currentStencilReference;
uint32_t multisampleMask;
SDL_Rect scissorRect;
/* Presentation structure */
void *mainWindowHandle;
SDLGPU_TextureHandle *fauxBackbufferColorTexture;
SDLGPU_TextureHandle *fauxBackbufferColorRenderbuffer;
SDLGPU_TextureHandle *fauxBackbufferDepthStencil; /* may be NULL */
/* Transfer structure */
SDL_GPUTransferBuffer *textureDownloadBuffer;
uint32_t textureDownloadBufferSize;
SDL_GPUTransferBuffer *bufferDownloadBuffer;
uint32_t bufferDownloadBufferSize;
SDL_GPUTransferBuffer *textureUploadBuffer;
uint32_t textureUploadBufferOffset;
uint32_t textureUploadCycleCount;
SDL_GPUTransferBuffer *bufferUploadBuffer;
uint32_t bufferUploadBufferOffset;
uint32_t bufferUploadCycleCount;
/* Synchronization */
SDL_GPUFence **fenceGroups[MAX_FRAMES_IN_FLIGHT];
uint8_t frameCounter;
/* RT tracking to reduce unnecessary cycling */
SDLGPU_TextureHandle **boundRenderTargets;
uint32_t boundRenderTargetCount;
uint32_t boundRenderTargetCapacity;
/* Hashing */
GraphicsPipelineHashTable graphicsPipelineHashTable;
SamplerStateHashArray samplerStateArray;
/* MOJOSHADER */
MOJOSHADER_sdlContext *mojoshaderContext;
MOJOSHADER_effect *currentEffect;
const MOJOSHADER_effectTechnique *currentTechnique;
uint32_t currentPass;
/* Dummy Samplers */
SDL_GPUTexture *dummyTexture2D;
SDL_GPUTexture *dummyTexture3D;
SDL_GPUTexture *dummyTextureCube;
SDL_GPUSampler *dummySampler;
/* Backbuffer parameter cache */
FNA3D_SurfaceFormat readbackBackbufferSurfaceFormat;
FNA3D_DepthFormat readbackBackbufferDepthFormat;
int32_t readbackBackbufferMultiSampleCount;
/* Capabilities */
uint8_t supportsBaseVertex;
uint8_t supportsDXT1;
uint8_t supportsBC2;
uint8_t supportsBC3;
uint8_t supportsBC7;
uint8_t supportsSRGB;
uint8_t supportsD24;
uint8_t supportsD24S8;
} SDLGPU_Renderer;
/* Format Conversion */
static inline SDL_GPUTextureFormat XNAToSDL_DepthFormat(
SDLGPU_Renderer* renderer,
FNA3D_DepthFormat format
) {
switch (format)
{
case FNA3D_DEPTHFORMAT_D16:
return SDL_GPU_TEXTUREFORMAT_D16_UNORM;
case FNA3D_DEPTHFORMAT_D24:
return (renderer->supportsD24) ?
SDL_GPU_TEXTUREFORMAT_D24_UNORM :
SDL_GPU_TEXTUREFORMAT_D32_FLOAT;
case FNA3D_DEPTHFORMAT_D24S8:
return (renderer->supportsD24S8) ?
SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT :
SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
default:
FNA3D_LogError("Unrecognized depth format!");
return 0;
}
}
/* Statics */
static FNA3D_PresentationParameters requestedPresentationParameters;
/* Submission / Presentation */
static void SDLGPU_INTERNAL_BeginCopyPass(
SDLGPU_Renderer *renderer
) {
if (renderer->copyPass == NULL)
{
renderer->copyPass = SDL_BeginGPUCopyPass(
renderer->uploadCommandBuffer
);
}
}
static void SDLGPU_INTERNAL_EndCopyPass(
SDLGPU_Renderer *renderer
) {
if (renderer->copyPass != NULL)
{
SDL_EndGPUCopyPass(
renderer->copyPass
);
renderer->copyPass = NULL;
}
}
static void SDLGPU_INTERNAL_BindRenderTarget(
SDLGPU_Renderer *renderer,
SDLGPU_TextureHandle *textureHandle
) {
uint32_t i;
for (i = 0; i < renderer->boundRenderTargetCount; i += 1)
{
if (renderer->boundRenderTargets[i] == textureHandle)
{
return;
}
}
if (renderer->boundRenderTargetCount >= renderer->boundRenderTargetCapacity)
{
renderer->boundRenderTargetCapacity *= 2;
renderer->boundRenderTargets = SDL_realloc(
renderer->boundRenderTargets,
renderer->boundRenderTargetCapacity * sizeof(SDLGPU_TextureHandle*)
);
}
renderer->boundRenderTargets[renderer->boundRenderTargetCount] =
textureHandle;
renderer->boundRenderTargetCount += 1;
textureHandle->boundAsRenderTarget = 1;
}
static void SDLGPU_INTERNAL_BeginRenderPass(
SDLGPU_Renderer* renderer
);
static void SDLGPU_INTERNAL_EndRenderPass(
SDLGPU_Renderer *renderer
) {
/* If we got to EndRenderPass without actually making a new render pass,
* we're looking at a clear-only pass, so just forcibly start it so we
* can have the clear execute instead of silently discarding it.
* -flibit
*/
if (renderer->needNewRenderPass)
{
SDLGPU_INTERNAL_BeginRenderPass(renderer);
}
if (renderer->renderPass != NULL)
{
SDL_EndGPURenderPass(
renderer->renderPass
);
renderer->renderPass = NULL;
}
renderer->needNewRenderPass = 1;
renderer->currentGraphicsPipeline = NULL;
renderer->needNewGraphicsPipeline = 1;
SDL_zero(renderer->currentBlendConstants);
renderer->currentStencilReference = 0;
}
static void SDLGPU_INTERNAL_BeginRenderPass(
SDLGPU_Renderer *renderer
) {
SDL_GPUColorTargetInfo colorAttachmentInfos[MAX_RENDERTARGET_BINDINGS];
SDL_GPUDepthStencilTargetInfo depthStencilAttachmentInfo;
SDL_GPUViewport gpuViewport;
SDL_Rect scissorRect;
uint32_t i;
if (!renderer->needNewRenderPass)
{
return;
}
renderer->needNewRenderPass = 0;
SDLGPU_INTERNAL_EndRenderPass(renderer);
/* Set up the next render pass */
for (i = 0; i < renderer->nextRenderPassColorAttachmentCount; i += 1)
{
colorAttachmentInfos[i].texture = renderer->nextRenderPassColorAttachments[i]->texture;
colorAttachmentInfos[i].layer_or_depth_plane = renderer->nextRenderPassColorAttachmentCubeFace[i];
colorAttachmentInfos[i].mip_level = 0;
colorAttachmentInfos[i].load_op =
renderer->shouldClearColorOnBeginPass ?
SDL_GPU_LOADOP_CLEAR :
SDL_GPU_LOADOP_LOAD;
/* We always have to store just in case changing render state breaks the render pass. */
/* FIXME: perhaps there is a way around this? */
if (renderer->nextRenderPassColorResolves[i] != NULL)
{
colorAttachmentInfos[i].store_op = SDL_GPU_STOREOP_RESOLVE_AND_STORE;
}
else
{
colorAttachmentInfos[i].store_op = SDL_GPU_STOREOP_STORE;
}
colorAttachmentInfos[i].cycle =
renderer->nextRenderPassColorAttachments[i]->boundAsRenderTarget || colorAttachmentInfos[i].load_op == SDL_GPU_LOADOP_LOAD ?
false :
true; /* cycle if we can, it's fast! */
if (renderer->nextRenderPassColorResolves[i] != NULL)
{
colorAttachmentInfos[i].resolve_texture = renderer->nextRenderPassColorResolves[i]->texture;
}
else
{
colorAttachmentInfos[i].resolve_texture = NULL;
}
colorAttachmentInfos[i].resolve_mip_level = 0;
colorAttachmentInfos[i].resolve_layer = 0;
colorAttachmentInfos[i].cycle_resolve_texture = colorAttachmentInfos[i].cycle;
if (renderer->shouldClearColorOnBeginPass)
{
colorAttachmentInfos[i].clear_color = renderer->clearColorValue;
}
else
{
colorAttachmentInfos[i].clear_color.r = 0;
colorAttachmentInfos[i].clear_color.g = 0;
colorAttachmentInfos[i].clear_color.b = 0;
colorAttachmentInfos[i].clear_color.a = 0;
}
SDLGPU_INTERNAL_BindRenderTarget(renderer, renderer->nextRenderPassColorAttachments[i]);
}
if (renderer->nextRenderPassDepthStencilAttachment != NULL)
{
depthStencilAttachmentInfo.texture = renderer->nextRenderPassDepthStencilAttachment->texture;
depthStencilAttachmentInfo.load_op =
renderer->shouldClearDepthOnBeginPass ?
SDL_GPU_LOADOP_CLEAR :
SDL_GPU_LOADOP_DONT_CARE;
if (renderer->shouldClearDepthOnBeginPass)
{
depthStencilAttachmentInfo.load_op = SDL_GPU_LOADOP_CLEAR;
}
else
{
/* FIXME: is there a way to safely get rid of this load op? */
depthStencilAttachmentInfo.load_op = SDL_GPU_LOADOP_LOAD;
}
if (renderer->shouldClearStencilOnBeginPass)
{
depthStencilAttachmentInfo.stencil_load_op = SDL_GPU_LOADOP_CLEAR;
}
else
{
/* FIXME: is there a way to safely get rid of this load op? */
depthStencilAttachmentInfo.stencil_load_op = SDL_GPU_LOADOP_LOAD;
}
/* We always have to store just in case changing render state breaks the render pass. */
/* FIXME: perhaps there is a way around this? */
depthStencilAttachmentInfo.store_op = SDL_GPU_STOREOP_STORE;
depthStencilAttachmentInfo.stencil_store_op = SDL_GPU_STOREOP_STORE;
depthStencilAttachmentInfo.cycle =
renderer->nextRenderPassDepthStencilAttachment->boundAsRenderTarget || depthStencilAttachmentInfo.load_op == SDL_GPU_LOADOP_LOAD || depthStencilAttachmentInfo.stencil_load_op == SDL_GPU_LOADOP_LOAD ?
false :
true; /* Cycle if we can! */
if (renderer->shouldClearDepthOnBeginPass || renderer->shouldClearStencilOnBeginPass)
{
depthStencilAttachmentInfo.clear_depth = renderer->clearDepthValue;
depthStencilAttachmentInfo.clear_stencil = renderer->clearStencilValue;
}
SDLGPU_INTERNAL_BindRenderTarget(renderer, renderer->nextRenderPassDepthStencilAttachment);
}
renderer->renderPass = SDL_BeginGPURenderPass(
renderer->renderCommandBuffer,
colorAttachmentInfos,
renderer->nextRenderPassColorAttachmentCount,
renderer->nextRenderPassDepthStencilAttachment != NULL ? &depthStencilAttachmentInfo : NULL
);
gpuViewport.x = (float) renderer->viewport.x;
gpuViewport.y = (float) renderer->viewport.y;
gpuViewport.w = (float) renderer->viewport.w;
gpuViewport.h = (float) renderer->viewport.h;
gpuViewport.min_depth = renderer->viewport.minDepth;
gpuViewport.max_depth = renderer->viewport.maxDepth;
SDL_SetGPUViewport(
renderer->renderPass,
&gpuViewport
);
if (renderer->fnaRasterizerState.scissorTestEnable)
{
scissorRect = renderer->scissorRect;
}
else
{
scissorRect.x = gpuViewport.x;
scissorRect.y = gpuViewport.y;
scissorRect.w = gpuViewport.w;
scissorRect.h = gpuViewport.h;
}
SDL_SetGPUScissor(
renderer->renderPass,
&scissorRect
);
renderer->shouldClearColorOnBeginPass = 0;
renderer->shouldClearDepthOnBeginPass = 0;
renderer->shouldClearStencilOnBeginPass = 0;
renderer->needNewGraphicsPipeline = 1;
}
static void SDLGPU_INTERNAL_ResetUploadCommandBufferState(
SDLGPU_Renderer *renderer
) {
renderer->uploadCommandBuffer = SDL_AcquireGPUCommandBuffer(renderer->device);
SDLGPU_INTERNAL_BeginCopyPass(renderer);
/* Reset state */
renderer->textureUploadCycleCount = 0;
renderer->bufferUploadCycleCount = 0;
renderer->textureUploadBufferOffset = 0;
renderer->bufferUploadBufferOffset = 0;
}
static void SDLGPU_INTERNAL_ResetRenderCommandBufferState(
SDLGPU_Renderer *renderer
) {
renderer->renderCommandBuffer = SDL_AcquireGPUCommandBuffer(renderer->device);
/* Reset state */
renderer->needNewRenderPass = 1;
renderer->needNewGraphicsPipeline = 1;
renderer->needVertexBufferBind = 1;
renderer->needVertexSamplerBind = 1;
renderer->needFragmentSamplerBind = 1;
}
static void SDLGPU_ResetCommandBufferState(
SDLGPU_Renderer *renderer
) {
SDLGPU_INTERNAL_ResetUploadCommandBufferState(renderer);
SDLGPU_INTERNAL_ResetRenderCommandBufferState(renderer);
}
static void SDLGPU_INTERNAL_FlushUploadCommandsAndAcquireFence(
SDLGPU_Renderer *renderer,
SDL_GPUFence **uploadFence
) {
SDL_LockMutex(renderer->copyPassMutex);
SDLGPU_INTERNAL_EndCopyPass(renderer);
*uploadFence = SDL_SubmitGPUCommandBufferAndAcquireFence(
renderer->uploadCommandBuffer
);
SDLGPU_INTERNAL_ResetUploadCommandBufferState(renderer);
SDL_UnlockMutex(renderer->copyPassMutex);
}
static void SDLGPU_INTERNAL_FlushCommandsAndAcquireFence(
SDLGPU_Renderer *renderer,
SDL_GPUFence **uploadFence,
SDL_GPUFence **renderFence
) {
SDLGPU_INTERNAL_FlushUploadCommandsAndAcquireFence(renderer, uploadFence);
SDLGPU_INTERNAL_EndRenderPass(renderer);
*renderFence = SDL_SubmitGPUCommandBufferAndAcquireFence(
renderer->renderCommandBuffer
);
SDLGPU_INTERNAL_ResetRenderCommandBufferState(renderer);
}
static void SDLGPU_INTERNAL_FlushUploadCommands(
SDLGPU_Renderer *renderer
) {
SDL_LockMutex(renderer->copyPassMutex);
SDLGPU_INTERNAL_EndCopyPass(renderer);
SDL_SubmitGPUCommandBuffer(renderer->uploadCommandBuffer);
SDLGPU_INTERNAL_ResetUploadCommandBufferState(renderer);
SDL_UnlockMutex(renderer->copyPassMutex);
}