-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmango.zig
More file actions
1674 lines (1442 loc) · 50.1 KB
/
mango.zig
File metadata and controls
1674 lines (1442 loc) · 50.1 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
//! mango is a Vulkan-like abstraction around the PICA200.
//!
//! It is designed to be as lightweight as possible while abstracting all possibly useful hardware features, it means:
//! - No state caching, static pipeline state is pre-encoded in a hardware command buffer.
//!
//! This also implies that the application is responsible for proper pipeline usage by minimizing binds and
//! using dynamic state when possible (which is also NOT cached) thus making the driver as lightweight
//! as possible.
//!
//!
//! It has a **Zig** and a **C** API, to make the **C** API as painless as possible,
//! structs and enums must be extern-compatible.
//!
//! For more info see the top-level comments of each resource.
// TODO: Have validation-layer behaviour with a toggle at the expense of more checks and more memory usage.
pub const DeviceSize = enum(u32) {
whole = std.math.maxInt(u32),
_,
pub fn size(value: u32) DeviceSize {
return @enumFromInt(value);
}
};
pub const ImageArrayLayer = enum(u8) {
// zig fmt: off
@"0", @"1", @"2", @"3", @"4", @"5", @"6", @"7",
// zig fmt: on
pub fn layer(index: u3) ImageArrayLayer {
return @enumFromInt(index);
}
};
pub const ImageArrayLayers = enum(u8) {
remaining = std.math.maxInt(u8),
// zig fmt: off
@"1" = 1, @"2", @"3", @"4", @"5", @"6", @"7", @"8",
// zig fmt: on
pub fn layers(amount: u3) ImageArrayLayers {
return @enumFromInt(amount);
}
};
pub const ImageMipLevel = enum(u8) {
// zig fmt: off
@"0", @"1", @"2", @"3", @"4", @"5", @"6", @"7",
// zig fmt: on
pub fn level(index: u3) ImageMipLevel {
return @enumFromInt(index);
}
};
pub const ImageMipLevels = enum(u8) {
remaining = std.math.maxInt(u8),
// zig fmt: off
@"1" = 1, @"2", @"3", @"4", @"5", @"6", @"7", @"8",
// zig fmt: on
pub fn levels(amount: u3) ImageArrayLayers {
return @enumFromInt(amount);
}
};
pub const Offset2D = extern struct { x: u16, y: u16 };
pub const Extent2D = extern struct { width: u16, height: u16 };
pub const Rect2D = extern struct { offset: Offset2D, extent: Extent2D };
pub const ColorComponentFlags = packed struct(u8) {
pub const rgba: ColorComponentFlags = .{ .r_enable = true, .g_enable = true, .b_enable = true, .a_enable = true };
pub const rgb: ColorComponentFlags = .{ .r_enable = true, .g_enable = true, .b_enable = true };
pub const rg: ColorComponentFlags = .{ .r_enable = true, .g_enable = true };
pub const r: ColorComponentFlags = .{ .r_enable = true };
r_enable: bool = false,
g_enable: bool = false,
b_enable: bool = false,
a_enable: bool = false,
_: u4 = 0,
};
pub const PresentMode = enum(u8) {
mailbox,
fifo,
};
pub const QueueFamily = enum(u8) {
fill,
transfer,
submit,
present,
};
/// The 3DS always has 3 heaps.
/// - FCRAM
/// - VRAM (A, 3MiB always)
/// - VRAM (B, 3MiB always)
pub const MemoryHeap = extern struct {
pub const Flags = packed struct(u8) {
/// Access of this memory by the GPU *will* be faster
device_local: bool,
_: u7 = false,
};
size: DeviceSize,
flags: Flags,
};
pub const MemoryHeapIndex = enum(u8) {
fcram,
vram_a,
vram_b,
};
pub const KnownMemoryType = enum(u8) {
fcram_cached,
vram_a,
vram_b,
};
pub const MemoryType = extern struct {
pub const Flags = packed struct(u8) {
/// The memory is the most efficient to be accessed by the GPU. Set if and only if the heap is `device_local`.
device_local: bool,
/// The memory can be accessed by the host via `mapMemory` and `unmapMemory`.
host_visible: bool,
/// The memory must be flushed and invalidated via `flushMappedMemoryRanges` and `invalidateMappedMemoryRanges`.
host_cached: bool,
/// NOTE: Seems it's not supported by the Horizon kernel unless specified in the exheader, see https://github.com/LumaTeam/Luma3DS/issues/2166.
/// 3DSX homebrew loaded by Luma will have RO (coherent it seems?) VRAM access
host_coherent: bool,
_: u4 = 0,
};
heap_index: MemoryHeapIndex,
flags: Flags,
};
pub const MemoryAllocateInfo = extern struct {
allocation_size: DeviceSize,
memory_type: KnownMemoryType,
};
pub const MappedMemoryRange = extern struct {
memory: DeviceMemory,
offset: DeviceSize,
size: DeviceSize,
};
// Don't overlap ImageView formats with AttributeBuffer ones!
// They're used for space optimization.
pub const Format = enum(u8) {
undefined,
// ImageView Supported Formats. Could be unsupported depending on usage.
r5g6b5_unorm_pack16,
r5g5b5a1_unorm_pack16,
r4g4b4a4_unorm_pack16,
g8r8_unorm,
b8g8r8_unorm,
a8b8g8r8_unorm,
d16_unorm,
d24_unorm,
d24_unorm_s8_uint,
d24_unorm_i8_unorm,
i4_unorm,
a4_unorm,
i4a4_unorm,
i8_unorm,
a8_unorm,
i8a8_unorm,
etc1_unorm,
etc1a4_unorm,
// Attribute Input Supported Formats
r8_uscaled,
r8_sscaled,
r16_sscaled,
r32_sfloat,
r8g8_uscaled,
r8g8_sscaled,
r16g16_sscaled,
r32g32_sfloat,
r8g8b8_uscaled,
r8g8b8_sscaled,
r16g16b16_sscaled,
r32g32b32_sfloat,
r8g8b8a8_uscaled,
r8g8b8a8_sscaled,
r16g16b16a16_sscaled,
r32g32b32a32_sfloat,
pub fn scale(format: Format, size: usize) usize {
return switch (format) {
.r5g6b5_unorm_pack16,
.r5g5b5a1_unorm_pack16,
.r4g4b4a4_unorm_pack16,
.g8r8_unorm,
.d16_unorm,
.i8a8_unorm,
=> size << 1,
.b8g8r8_unorm,
.d24_unorm,
=> size * 3,
.a8b8g8r8_unorm,
.d24_unorm_s8_uint,
.d24_unorm_i8_unorm,
=> size << 2,
.i4a4_unorm,
.i8_unorm,
.a8_unorm,
.etc1a4_unorm,
=> size,
.i4_unorm,
.a4_unorm,
.etc1_unorm,
=> size >> 1,
.undefined,
.r8_uscaled,
.r8_sscaled,
.r16_sscaled,
.r32_sfloat,
.r8g8_uscaled,
.r8g8_sscaled,
.r16g16_sscaled,
.r32g32_sfloat,
.r8g8b8_uscaled,
.r8g8b8_sscaled,
.r16g16b16_sscaled,
.r32g32b32_sfloat,
.r8g8b8a8_uscaled,
.r8g8b8a8_sscaled,
.r16g16b16a16_sscaled,
.r32g32b32a32_sfloat,
=> unreachable,
};
}
pub fn nativeColorFormat(fmt: Format) pica.ColorFormat {
return switch (fmt) {
.a8b8g8r8_unorm => .abgr8888,
.b8g8r8_unorm => .bgr888,
.r5g6b5_unorm_pack16 => .rgb565,
.r5g5b5a1_unorm_pack16 => .rgba5551,
.r4g4b4a4_unorm_pack16 => .rgba4444,
else => unreachable,
};
}
pub fn nativeDepthStencilFormat(fmt: Format) pica.DepthStencilFormat {
return switch (fmt) {
.d16_unorm => .d16,
.d24_unorm => .d24,
.d24_unorm_s8_uint => .d24_s8,
else => unreachable,
};
}
pub fn nativeVertexFormat(fmt: Format) pica.AttributeFormat {
return switch (fmt) {
.r8_sscaled => .{ .type = .i8, .size = .x },
.r8_uscaled => .{ .type = .u8, .size = .x },
.r16_sscaled => .{ .type = .i16, .size = .x },
.r32_sfloat => .{ .type = .f32, .size = .x },
.r8g8_sscaled => .{ .type = .i8, .size = .xy },
.r8g8_uscaled => .{ .type = .u8, .size = .xy },
.r16g16_sscaled => .{ .type = .i16, .size = .xy },
.r32g32_sfloat => .{ .type = .f32, .size = .xy },
.r8g8b8_sscaled => .{ .type = .i8, .size = .xyz },
.r8g8b8_uscaled => .{ .type = .u8, .size = .xyz },
.r16g16b16_sscaled => .{ .type = .i16, .size = .xyz },
.r32g32b32_sfloat => .{ .type = .f32, .size = .xyz },
.r8g8b8a8_sscaled => .{ .type = .i8, .size = .xyzw },
.r8g8b8a8_uscaled => .{ .type = .u8, .size = .xyzw },
.r16g16b16a16_sscaled => .{ .type = .i16, .size = .xyzw },
.r32g32b32a32_sfloat => .{ .type = .f32, .size = .xyzw },
else => unreachable,
};
}
pub fn nativeTextureUnitFormat(fmt: Format) pica.TextureUnitFormat {
return switch (fmt) {
.g8r8_unorm => .hilo88,
.a8b8g8r8_unorm => .abgr8888,
.b8g8r8_unorm => .bgr888,
.r5g6b5_unorm_pack16 => .rgb565,
.r5g5b5a1_unorm_pack16 => .rgba5551,
.r4g4b4a4_unorm_pack16 => .rgba4444,
.i4_unorm => .i4,
.a4_unorm => .a4,
.i4a4_unorm => .ia44,
.i8_unorm => .i8,
.a8_unorm => .a8,
.i8a8_unorm => .ia88,
.etc1_unorm => .etc1,
.etc1a4_unorm => .etc1a4,
else => unreachable,
};
}
comptime {
std.debug.assert(@intFromEnum(Format.undefined) == 0);
}
};
pub const PrimitiveTopology = enum(u8) {
/// Specifies a series of separate triangle primitives.
/// The number of primitives generated is `(vertexCount / 3)`
triangle_list,
/// Specifies a series of connected triangle primitives with consecutive triangles sharing an edge.
/// The number of primitives generated is `max(0, vertexCount - 2)`
triangle_strip,
/// Specifies a series of connected triangle primitives with all triangles sharing a common vertex.
/// The number of primitives generated is `max(0, vertexCount - 2)`
triangle_fan,
/// Specifies a series of triangle primitives which are to be defined by the geometry shader.
/// The number of primitives generated depends on the shader implementation.
geometry,
pub fn native(topology: PrimitiveTopology) pica.PrimitiveTopology {
return switch (topology) {
.triangle_list => .triangle_list,
.triangle_strip => .triangle_strip,
.triangle_fan => .triangle_fan,
.geometry => .geometry,
};
}
};
pub const IndexType = enum(u8) {
/// Specifies that indices are unsigned 8-bit numbers.
u8,
/// Specifies that indices are unsigned 16-bit numbers.
u16,
pub fn native(fmt: IndexType) pica.IndexFormat {
return switch (fmt) {
.u8 => .u8,
.u16 => .u16,
};
}
};
pub const CompareOperation = enum(u8) {
never,
always,
eq,
neq,
lt,
le,
gt,
ge,
pub fn nativeEarlyDepth(op: CompareOperation) pica.EarlyDepthCompareOperation {
return switch (op) {
.ge => .ge,
.gt => .gt,
.le => .le,
.lt => .lt,
else => unreachable,
};
}
pub fn native(op: CompareOperation) pica.CompareOperation {
return switch (op) {
.never => .never,
.always => .always,
.eq => .eq,
.neq => .neq,
.lt => .lt,
.le => .le,
.gt => .gt,
.ge => .ge,
};
}
};
pub const StencilOperation = enum(u8) {
/// Keep the current value.
keep,
/// Sets the value to `0`.
zero,
/// Sets the value to `reference`.
replace,
/// Increments the current value and clamps to the maximum representable unsigned value.
increment,
/// Decrements the current value and clamps to `0`.
decrement,
/// Bitwise-inverts the current value.
invert,
/// Increments the current value and clamps to `0` when the maximum value would have exceeded.
increment_wrap,
/// Decrements the current value and clamps to the maximum possible value when the value would go below `0`.
decrement_wrap,
pub fn native(op: StencilOperation) pica.StencilOperation {
return switch (op) {
.keep => .keep,
.zero => .zero,
.replace => .replace,
.increment => .increment,
.decrement => .decrement,
.invert => .invert,
.increment_wrap => .increment_wrap,
.decrement_wrap => .decrement_wrap,
};
}
};
pub const LogicOperation = enum(u8) {
clear,
@"and",
reverse_and,
copy,
set,
copy_inverted,
nop,
invert,
nand,
@"or",
nor,
xor,
equivalent,
and_inverted,
or_reverse,
or_inverted,
pub fn native(op: LogicOperation) pica.LogicOperation {
return switch (op) {
.clear => .clear,
.@"and" => .@"and",
.reverse_and => .reverse_and,
.copy => .copy,
.set => .set,
.copy_inverted => .copy_inverted,
.nop => .nop,
.invert => .invert,
.nand => .nand,
.@"or" => .@"or",
.nor => .nor,
.xor => .xor,
.equivalent => .equivalent,
.and_inverted => .and_inverted,
.or_reverse => .or_reverse,
.or_inverted => .or_inverted,
};
}
};
pub const DepthMode = enum(u8) {
/// Precision is evenly distributed.
w_buffer,
/// Precision is higher close to the near plane.
z_buffer,
pub fn native(mode: DepthMode) Graphics.Rasterizer.DepthMap.Mode {
return switch (mode) {
.w_buffer => .w,
.z_buffer => .z,
};
}
};
pub const BlendOperation = enum(u8) {
/// `src_factor * src + dst_factor * dst`
add,
/// `src_factor * src - dst_factor * dst`
sub,
/// `dst_factor * dst - src_factor * src`
reverse_sub,
/// `min(src_factor * src, dst_factor * dst)`
min,
/// `max(src_factor * src, dst_factor * dst)`
max,
pub fn native(op: BlendOperation) pica.BlendOperation {
return switch (op) {
.add => .add,
.sub => .sub,
.reverse_sub => .reverse_sub,
.min => .min,
.max => .max,
};
}
};
pub const BlendFactor = enum(u8) {
zero,
one,
src_color,
one_minus_src_color,
dst_color,
one_minus_dst_color,
src_alpha,
one_minus_src_alpha,
dst_alpha,
one_minus_dst_alpha,
constant_color,
one_minus_constant_color,
constant_alpha,
one_minus_constant_alpha,
src_alpha_saturate,
pub fn native(factor: BlendFactor) pica.BlendFactor {
return switch (factor) {
.zero => .zero,
.one => .one,
.src_color => .src_color,
.one_minus_src_color => .one_minus_src_color,
.dst_color => .dst_color,
.one_minus_dst_color => .one_minus_dst_color,
.src_alpha => .src_alpha,
.one_minus_src_alpha => .one_minus_src_alpha,
.dst_alpha => .dst_alpha,
.one_minus_dst_alpha => .one_minus_dst_alpha,
.constant_color => .constant_color,
.one_minus_constant_color => .one_minus_constant_color,
.constant_alpha => .constant_alpha,
.one_minus_constant_alpha => .one_minus_constant_alpha,
.src_alpha_saturate => .src_alpha_saturate,
};
}
};
pub const ColorBlendEquation = extern struct {
src_color_factor: BlendFactor,
dst_color_factor: BlendFactor,
color_op: BlendOperation,
src_alpha_factor: BlendFactor,
dst_alpha_factor: BlendFactor,
alpha_op: BlendOperation,
pub fn native(equation: ColorBlendEquation) Graphics.OutputMerger.BlendConfig {
return .{
.color_op = equation.color_op.native(),
.alpha_op = equation.alpha_op.native(),
.src_color_factor = equation.src_color_factor.native(),
.dst_color_factor = equation.dst_color_factor.native(),
.src_alpha_factor = equation.src_alpha_factor.native(),
.dst_alpha_factor = equation.dst_alpha_factor.native(),
};
}
};
pub const TextureCombinerSource = enum(u8) {
primary_color,
fragment_primary_color,
fragment_secondary_color,
texture_0,
texture_1,
texture_2,
texture_3,
previous_buffer = 0xD,
constant,
previous,
pub fn native(src: TextureCombinerSource) pica.Graphics.TextureCombiners.Source {
return switch (src) {
.primary_color => .primary_color,
.fragment_primary_color => .fragment_primary_color,
.fragment_secondary_color => .fragment_secondary_color,
.texture_0 => .texture_0,
.texture_1 => .texture_1,
.texture_2 => .texture_2,
.texture_3 => .texture_3,
.previous_buffer => .previous_buffer,
.constant => .constant,
.previous => .previous,
};
}
};
pub const TextureCombinerColorFactor = enum(u8) {
src_color,
one_minus_src_color,
src_alpha,
one_minus_src_alpha,
src_red,
one_minus_src_red,
src_green = 8,
one_minus_src_green,
src_blue = 12,
one_minus_src_blue,
pub fn native(factor: TextureCombinerColorFactor) pica.Graphics.TextureCombiners.ColorFactor {
return switch (factor) {
.src_color => .src_color,
.one_minus_src_color => .one_minus_src_color,
.src_alpha => .src_alpha,
.one_minus_src_alpha => .one_minus_src_alpha,
.src_red => .src_red,
.one_minus_src_red => .one_minus_src_red,
.src_green => .src_green,
.one_minus_src_green => .one_minus_src_green,
.src_blue => .src_blue,
.one_minus_src_blue => .one_minus_src_blue,
};
}
};
pub const TextureCombinerAlphaFactor = enum(u8) {
src_alpha,
one_minus_src_alpha,
src_red,
one_minus_src_red,
src_green,
one_minus_src_green,
src_blue,
one_minus_src_blue,
pub fn native(factor: TextureCombinerAlphaFactor) pica.Graphics.TextureCombiners.AlphaFactor {
return switch (factor) {
.src_alpha => .src_alpha,
.one_minus_src_alpha => .one_minus_src_alpha,
.src_red => .src_red,
.one_minus_src_red => .one_minus_src_red,
.src_green => .src_green,
.one_minus_src_green => .one_minus_src_green,
.src_blue => .src_blue,
.one_minus_src_blue => .one_minus_src_blue,
};
}
};
pub const TextureCombinerOperation = enum(u8) {
/// `src0`
replace,
/// `src0 * src1`
modulate,
/// `src0 + src1`
add,
/// `src0 + src1 - 0.5`
add_signed,
/// `src0 * src2 + src1 * (1 - src2)`
interpolate,
/// `src0 - src1`
subtract,
/// `4 * ((src0r − 0.5) * (src1r − 0.5) + (src0g − 0.5) * (src1g − 0.5) + (src0b − 0.5) * (src1b − 0.5))`
dot3_rgb,
/// `4 * ((src0r − 0.5) * (src1r − 0.5) + (src0g − 0.5) * (src1g − 0.5) + (src0b − 0.5) * (src1b − 0.5))`
dot3_rgba,
/// `src0 * src1 + src2` (?)
multiply_add,
/// `src0 + src1 * src2` (?)
add_multiply,
pub fn native(op: TextureCombinerOperation) pica.Graphics.TextureCombiners.Operation {
return switch (op) {
.replace => .replace,
.modulate => .modulate,
.add => .add,
.add_signed => .add_signed,
.interpolate => .interpolate,
.subtract => .subtract,
.dot3_rgb => .dot3_rgb,
.dot3_rgba => .dot3_rgba,
.multiply_add => .multiply_add,
.add_multiply => .add_multiply,
};
}
};
pub const Multiplier = enum(u8) {
// zig fmt: off
@"1x", @"2x", @"4x", @"8x", @"0.25x", @"0.5x",
// zig fmt: on
pub fn nativeTextureCombinerMultiplier(multiplier: Multiplier) pica.Graphics.TextureCombiners.Multiplier {
return switch (multiplier) {
.@"1x" => .@"1x",
.@"2x" => .@"2x",
.@"4x" => .@"4x",
else => unreachable,
};
}
pub fn nativeLightLookupMultiplier(multiplier: Multiplier) Graphics.FragmentLighting.LookupTable.Multiplier {
return switch (multiplier) {
.@"1x" => .@"1x",
.@"2x" => .@"2x",
.@"4x" => .@"4x",
.@"8x" => .@"8x",
.@"0.5x" => .@"0.5x",
.@"0.25x" => .@"0.25x",
};
}
};
pub const TextureCombinerBufferSource = enum(u8) {
/// Use previous combiner buffer output as this combiner's buffer input
previous_buffer,
/// Use previous combiner output as this combiner's buffer input
previous,
pub fn native(buffer_source: TextureCombinerBufferSource) pica.Graphics.TextureCombiners.BufferSource {
return switch (buffer_source) {
.previous_buffer => .previous_buffer,
.previous => .previous,
};
}
};
pub const FrontFace = enum(u8) {
/// Triangles with a positive area are considered to be front-facing.
ccw,
/// Triangles with a negative area are considered to be front-facing.
cw,
};
pub const CullMode = enum(u8) {
/// No triangles are discarded.
none,
/// The front-facing triangles are culled.
front,
/// The back-facing triangles are culled.
back,
pub fn native(mode: CullMode, front: FrontFace) pica.CullMode {
return switch (mode) {
.none => .none,
.front => switch (front) {
.ccw => .ccw,
.cw => .cw,
},
.back => switch (front) {
.ccw => .cw,
.cw => .ccw,
},
};
}
};
pub const PipelineBindPoint = enum(u8) {
graphics,
};
pub const SwapchainCreateInfo = extern struct {
pub const ImageMemoryInfo = extern struct {
memory: DeviceMemory,
memory_offset: DeviceSize,
};
surface: Surface,
present_mode: PresentMode,
image_usage: ImageCreateInfo.Usage,
image_format: Format,
image_array_layers: ImageArrayLayers,
image_count: u8,
image_memory_info: [*]const ImageMemoryInfo,
};
pub const SemaphoreCreateInfo = extern struct {
/// Create a semaphore with an initial value of `0`
pub const initial_zero: SemaphoreCreateInfo = .{};
/// The initial value the semaphore will have.
initial_value: u64 = 0,
};
pub const CommandPoolCreateInfo = extern struct {
/// Create a command pool without preheating it.
pub const no_preheat: CommandPoolCreateInfo = .{};
/// Amount of command buffers to preallocate internally.
initial_command_buffers: u32 = 0,
};
pub const CommandBufferAllocateInfo = extern struct {
pool: CommandPool,
command_buffer_count: u32,
};
pub const CommandBufferResetFlags = packed struct(u8) {
pub const none: CommandBufferResetFlags = .{};
/// Release underlying native memory resources to the pool.
/// If not set the command buffer may hold onto resources
/// and reuse them after being reset.
release_resources: bool = false,
_: u7 = 0,
};
pub const BufferCreateInfo = extern struct {
pub const Usage = packed struct(u8) {
/// Specifies that the buffer can be used as the source of a transfer operation.
transfer_src: bool = false,
/// Specifies that the buffer can be used as the destination of a transfer operation.
transfer_dst: bool = false,
/// Specifies that the buffer can be used as an index buffer.
index_buffer: bool = false,
/// Specifies that the buffer can be used as a vertex buffer.
vertex_buffer: bool = false,
_: u4 = 0,
};
size: DeviceSize,
usage: Usage,
};
pub const ImageCreateInfo = extern struct {
pub const Type = enum(u8) {
@"2d",
};
pub const Tiling = enum(u8) {
/// The images are tiled in a PICA200 specific format (8x8 or 32x32 tiles).
optimal,
/// The images are linearly stored.
linear,
};
pub const Usage = packed struct(u8) {
/// Specifies that the image can be used as the source of a transfer operation.
transfer_src: bool = false,
/// Specifies that the image can be used as the destination of a transfer operation.
transfer_dst: bool = false,
/// Specifies that the image can be used to create an ImageView suitable for binding with a sampler.
sampled: bool = false,
/// Specifies that the image can be used to create an ImageView suitable for use as a color attachment.
color_attachment: bool = false,
/// Specifies that the image can be used to create an ImageView suitable for use as a depth-stencil attachment.
depth_stencil_attachment: bool = false,
/// Specifies that the image can be used to create an ImageView suitable for use as a shadow attachment.
shadow_attachment: bool = false,
_: u2 = 0,
};
pub const Flags = packed struct(u8) {
/// Specifies that the image can be used to create an ImageView with a different format from the image.
mutable_format: bool = false,
/// Specifies that the image can be used to create an ImageView of type `cube`
cube_compatible: bool = false,
_: u6 = 0,
};
flags: Flags,
type: Type,
tiling: Tiling,
usage: Usage,
extent: Extent2D,
format: Format,
mip_levels: ImageMipLevels,
array_layers: ImageArrayLayers,
};
pub const ImageViewCreateInfo = extern struct {
pub const Type = enum(u8) {
@"2d",
cube,
};
type: Type,
format: Format,
image: Image,
subresource_range: ImageSubresourceRange,
};
pub const AddressMode = enum(u8) {
clamp_to_edge,
clamp_to_border,
repeat,
mirrored_repeat,
pub fn native(address_mode: AddressMode) pica.TextureUnitAddressMode {
return switch (address_mode) {
.clamp_to_edge => .clamp_to_edge,
.clamp_to_border => .clamp_to_border,
.repeat => .repeat,
.mirrored_repeat => .mirrored_repeat,
};
}
};
pub const Filter = enum(u8) {
nearest,
linear,
pub fn native(filter: Filter) pica.TextureUnitFilter {
return switch (filter) {
.nearest => .nearest,
.linear => .linear,
};
}
};
pub const SamplerCreateInfo = extern struct {
mag_filter: Filter,
min_filter: Filter,
mip_filter: Filter,
address_mode_u: AddressMode,
address_mode_v: AddressMode,
lod_bias: f32,
min_lod: u8,
max_lod: u8,
border_color: [4]u8,
};
pub const GraphicsPipelineCreateInfo = extern struct {
pub const FormatRenderingInfo = extern struct {
color_attachment_format: Format,
depth_stencil_attachment_format: Format,
};
pub const VertexInputState = extern struct {
bindings: [*]const VertexInputBindingDescription,
attributes: [*]const VertexInputAttributeDescription,
fixed_attributes: [*]const VertexInputFixedAttributeDescription,
bindings_len: u32,
attributes_len: u32,
fixed_attributes_len: u32,
pub fn init(bindings: []const VertexInputBindingDescription, attributes: []const VertexInputAttributeDescription, fixed_attributes: []const VertexInputFixedAttributeDescription) VertexInputState {
return .{
.bindings = bindings.ptr,
.attributes = attributes.ptr,
.fixed_attributes = fixed_attributes.ptr,
.bindings_len = bindings.len,
.attributes_len = attributes.len,
.fixed_attributes_len = fixed_attributes.len,
};
}
};
pub const ShaderStageState = extern struct {
code: [*]const u8,
code_len: u32,
name: [*]const u8,
name_len: u32,
pub fn init(code: []const u8, name: []const u8) ShaderStageState {
return .{
.code = code.ptr,
.code_len = code.len,
.name = name.ptr,
.name_len = name.len,
};
}
};
pub const InputAssemblyState = extern struct {
topology: PrimitiveTopology,
};
pub const ViewportState = extern struct {
scissor: ?*const Scissor,
viewport: ?*const Viewport,
};
pub const RasterizationState = extern struct {
front_face: FrontFace = .ccw,
cull_mode: CullMode = .none,
depth_mode: DepthMode = .z_buffer,
depth_bias_constant: f32 = 0.0,
};
pub const TextureSamplingState = extern struct {
/// Only texture coordinates 2 and 1 are supported
texture_2_coordinates: TextureCoordinateSource,
texture_3_coordinates: TextureCoordinateSource,
};
pub const LightingState = extern struct {
enable: bool = false,
environment: ?*const LightEnvironment = null,
};
pub const TextureCombinerState = extern struct {
texture_combiners: [*]const TextureCombinerUnit,
texture_combiners_len: usize,
texture_combiner_buffer_sources: [*]const TextureCombinerUnit.BufferSources,
texture_combiner_buffer_sources_len: usize,
pub fn init(texture_combiners: []const TextureCombinerUnit, texture_combiner_buffer_sources: []const TextureCombinerUnit.BufferSources) TextureCombinerState {
return .{