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
#[cfg(feature = "serde-support")]
use serde::{Deserialize, Serialize};
use crate::{RafxBuffer, RafxSampler, RafxTexture};
use rafx_base::DecimalF32;
use std::hash::{Hash, Hasher};
#[derive(Copy, Clone, Debug)]
pub enum RafxValidationMode {
Disabled,
EnabledIfAvailable,
Enabled,
}
impl Default for RafxValidationMode {
fn default() -> Self {
#[cfg(debug_assertions)]
let validation_mode = RafxValidationMode::EnabledIfAvailable;
#[cfg(not(debug_assertions))]
let validation_mode = RafxValidationMode::Disabled;
validation_mode
}
}
pub struct RafxDeviceInfo {
pub supports_multithreaded_usage: bool,
pub min_uniform_buffer_offset_alignment: u32,
pub min_storage_buffer_offset_alignment: u32,
pub upload_buffer_texture_alignment: u32,
pub upload_buffer_texture_row_alignment: u32,
pub supports_clamp_to_border_color: bool,
pub max_vertex_attribute_count: u32,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum RafxQueueType {
Graphics,
Compute,
Transfer,
}
#[derive(Copy, Clone, Debug)]
pub enum RafxColorType {
Linear,
Srgb,
}
bitflags::bitflags! {
pub struct RafxResourceState: u32 {
const UNDEFINED = 0;
const VERTEX_AND_CONSTANT_BUFFER = 0x1;
const INDEX_BUFFER = 0x2;
const RENDER_TARGET = 0x4;
const UNORDERED_ACCESS = 0x8;
const DEPTH_WRITE = 0x10;
const DEPTH_READ = 0x20;
const NON_PIXEL_SHADER_RESOURCE = 0x40;
const PIXEL_SHADER_RESOURCE = 0x80;
const SHADER_RESOURCE = 0x40 | 0x80;
const STREAM_OUT = 0x100;
const INDIRECT_ARGUMENT = 0x200;
const COPY_DST = 0x400;
const COPY_SRC = 0x800;
const GENERIC_READ = (((((0x1 | 0x2) | 0x40) | 0x80) | 0x200) | 0x800);
const PRESENT = 0x1000;
const COMMON = 0x2000;
}
}
#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct RafxExtents2D {
pub width: u32,
pub height: u32,
}
#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct RafxExtents3D {
pub width: u32,
pub height: u32,
pub depth: u32,
}
impl RafxExtents3D {
pub fn to_2d(self) -> RafxExtents2D {
RafxExtents2D {
width: self.width,
height: self.height,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxSampleCount {
SampleCount1,
SampleCount2,
SampleCount4,
SampleCount8,
SampleCount16,
}
impl Default for RafxSampleCount {
fn default() -> Self {
RafxSampleCount::SampleCount1
}
}
bitflags::bitflags! {
#[derive(Default)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub struct RafxResourceType: u32 {
const UNDEFINED = 0;
const SAMPLER = 1<<0;
const TEXTURE = 1<<1;
const TEXTURE_READ_WRITE = 1<<2;
const BUFFER = 1<<3;
const BUFFER_READ_WRITE = 1<<5;
const UNIFORM_BUFFER = 1<<7;
const ROOT_CONSTANT = 1<<8;
const VERTEX_BUFFER = 1<<9;
const INDEX_BUFFER = 1<<10;
const INDIRECT_BUFFER = 1<<11;
const TEXTURE_CUBE = 1<<12 | RafxResourceType::TEXTURE.bits();
const RENDER_TARGET_MIP_SLICES = 1<<13;
const RENDER_TARGET_ARRAY_SLICES = 1<<14;
const RENDER_TARGET_DEPTH_SLICES = 1<<15;
const INPUT_ATTACHMENT = 1<<16;
const TEXEL_BUFFER = 1<<17;
const TEXEL_BUFFER_READ_WRITE = 1<<18;
const COMBINED_IMAGE_SAMPLER = 1<<19;
const ARGUMENT_BUFFER = 1<<20;
const INDIRECT_COMMAND_BUFFER = 1<<21;
const RENDER_PIPELINE_STATE = 1<<22;
const RENDER_TARGET_COLOR = 1<<23;
const RENDER_TARGET_DEPTH_STENCIL = 1<<24;
}
}
impl RafxResourceType {
pub fn is_uniform_buffer(self) -> bool {
self.intersects(RafxResourceType::UNIFORM_BUFFER)
}
pub fn is_storage_buffer(self) -> bool {
self.intersects(RafxResourceType::BUFFER | RafxResourceType::BUFFER_READ_WRITE)
}
pub fn is_render_target(self) -> bool {
self.intersects(
RafxResourceType::RENDER_TARGET_COLOR | RafxResourceType::RENDER_TARGET_DEPTH_STENCIL,
)
}
pub fn is_texture(self) -> bool {
self.intersects(RafxResourceType::TEXTURE | RafxResourceType::TEXTURE_READ_WRITE)
}
}
bitflags::bitflags! {
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub struct RafxColorFlags: u8 {
const RED = 1;
const GREEN = 2;
const BLUE = 4;
const ALPHA = 8;
const ALL = 0x0F;
}
}
impl Default for RafxColorFlags {
fn default() -> Self {
RafxColorFlags::ALL
}
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum RafxMemoryUsage {
Unknown,
GpuOnly,
CpuOnly,
CpuToGpu,
GpuToCpu,
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum RafxPresentSuccessResult {
Success,
SuccessSuboptimal,
DeviceReset,
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum RafxFenceStatus {
Complete,
Incomplete,
Unsubmitted,
}
bitflags::bitflags! {
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub struct RafxBlendStateTargets : u8 {
const BLEND_STATE_TARGET_0 = 0x01;
const BLEND_STATE_TARGET_1 = 0x02;
const BLEND_STATE_TARGET_2 = 0x04;
const BLEND_STATE_TARGET_3 = 0x08;
const BLEND_STATE_TARGET_4 = 0x10;
const BLEND_STATE_TARGET_5 = 0x20;
const BLEND_STATE_TARGET_6 = 0x40;
const BLEND_STATE_TARGET_7 = 0x80;
const BLEND_STATE_TARGET_ALL = 0xFF;
}
}
bitflags::bitflags! {
#[derive(Default)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub struct RafxShaderStageFlags : u32 {
const NONE = 0;
const VERTEX = 1;
const TESSELLATION_CONTROL = 2;
const TESSELLATION_EVALUATION = 4;
const GEOMETRY = 8;
const FRAGMENT = 16;
const COMPUTE = 32;
const ALL_GRAPHICS = 0x1F;
const ALL = 0x7FFF_FFFF;
}
}
pub const ALL_SHADER_STAGE_FLAGS: [RafxShaderStageFlags; 6] = [
RafxShaderStageFlags::VERTEX,
RafxShaderStageFlags::TESSELLATION_CONTROL,
RafxShaderStageFlags::TESSELLATION_EVALUATION,
RafxShaderStageFlags::GEOMETRY,
RafxShaderStageFlags::FRAGMENT,
RafxShaderStageFlags::COMPUTE,
];
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum RafxPipelineType {
Graphics = 0,
Compute = 1,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RafxVertexAttributeRate {
Vertex,
Instance,
}
impl Default for RafxVertexAttributeRate {
fn default() -> Self {
RafxVertexAttributeRate::Vertex
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq)]
pub enum RafxLoadOp {
DontCare,
Load,
Clear,
}
impl Default for RafxLoadOp {
fn default() -> Self {
RafxLoadOp::DontCare
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq)]
pub enum RafxStoreOp {
DontCare,
Store,
}
impl Default for RafxStoreOp {
fn default() -> Self {
RafxStoreOp::Store
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxPrimitiveTopology {
PointList,
LineList,
LineStrip,
TriangleList,
TriangleStrip,
PatchList,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxIndexType {
Uint32,
Uint16,
}
impl Default for RafxIndexType {
fn default() -> Self {
RafxIndexType::Uint32
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxBlendFactor {
Zero,
One,
SrcColor,
OneMinusSrcColor,
DstColor,
OneMinusDstColor,
SrcAlpha,
OneMinusSrcAlpha,
DstAlpha,
OneMinusDstAlpha,
SrcAlphaSaturate,
ConstantColor,
OneMinusConstantColor,
}
impl Default for RafxBlendFactor {
fn default() -> Self {
RafxBlendFactor::Zero
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxBlendOp {
Add,
Subtract,
ReverseSubtract,
Min,
Max,
}
impl Default for RafxBlendOp {
fn default() -> Self {
RafxBlendOp::Add
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxCompareOp {
Never,
Less,
Equal,
LessOrEqual,
Greater,
NotEqual,
GreaterOrEqual,
Always,
}
impl Default for RafxCompareOp {
fn default() -> Self {
RafxCompareOp::Never
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxStencilOp {
Keep,
Zero,
Replace,
IncrementAndClamp,
DecrementAndClamp,
Invert,
IncrementAndWrap,
DecrementAndWrap,
}
impl Default for RafxStencilOp {
fn default() -> Self {
RafxStencilOp::Keep
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxCullMode {
None,
Back,
Front,
}
impl Default for RafxCullMode {
fn default() -> Self {
RafxCullMode::None
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxFrontFace {
CounterClockwise,
Clockwise,
}
impl Default for RafxFrontFace {
fn default() -> Self {
RafxFrontFace::CounterClockwise
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxFillMode {
Solid,
Wireframe,
}
impl Default for RafxFillMode {
fn default() -> Self {
RafxFillMode::Solid
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxFilterType {
Nearest,
Linear,
}
impl Default for RafxFilterType {
fn default() -> Self {
RafxFilterType::Nearest
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxAddressMode {
Mirror,
Repeat,
ClampToEdge,
ClampToBorder,
}
impl Default for RafxAddressMode {
fn default() -> Self {
RafxAddressMode::Mirror
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxMipMapMode {
Nearest,
Linear,
}
impl Default for RafxMipMapMode {
fn default() -> Self {
RafxMipMapMode::Nearest
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct RafxColorClearValue(pub [f32; 4]);
impl Hash for RafxColorClearValue {
fn hash<H: Hasher>(
&self,
mut state: &mut H,
) {
for &value in &self.0 {
DecimalF32(value).hash(&mut state);
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct RafxDepthStencilClearValue {
pub depth: f32,
pub stencil: u32,
}
impl Default for RafxDepthStencilClearValue {
fn default() -> Self {
RafxDepthStencilClearValue {
depth: 0.0,
stencil: 0,
}
}
}
impl Hash for RafxDepthStencilClearValue {
fn hash<H: Hasher>(
&self,
mut state: &mut H,
) {
DecimalF32(self.depth).hash(&mut state);
self.stencil.hash(&mut state);
}
}
pub enum RafxBarrierQueueTransition {
None,
ReleaseTo(RafxQueueType),
AcquireFrom(RafxQueueType),
}
impl Default for RafxBarrierQueueTransition {
fn default() -> Self {
RafxBarrierQueueTransition::None
}
}
pub struct RafxBufferBarrier<'a> {
pub buffer: &'a RafxBuffer,
pub src_state: RafxResourceState,
pub dst_state: RafxResourceState,
pub queue_transition: RafxBarrierQueueTransition,
}
pub struct RafxTextureBarrier<'a> {
pub texture: &'a RafxTexture,
pub src_state: RafxResourceState,
pub dst_state: RafxResourceState,
pub queue_transition: RafxBarrierQueueTransition,
pub array_slice: Option<u16>,
pub mip_slice: Option<u8>,
}
impl<'a> RafxTextureBarrier<'a> {
pub fn state_transition(
texture: &'a RafxTexture,
src_state: RafxResourceState,
dst_state: RafxResourceState,
) -> RafxTextureBarrier {
RafxTextureBarrier {
texture,
src_state,
dst_state,
queue_transition: RafxBarrierQueueTransition::None,
array_slice: None,
mip_slice: None,
}
}
}
#[derive(Clone)]
pub struct RafxSwapchainImage {
pub texture: RafxTexture,
pub swapchain_image_index: u32,
}
#[derive(Debug)]
pub struct RafxColorRenderTargetBinding<'a> {
pub texture: &'a RafxTexture,
pub load_op: RafxLoadOp,
pub store_op: RafxStoreOp,
pub mip_slice: Option<u8>,
pub array_slice: Option<u16>,
pub clear_value: RafxColorClearValue,
pub resolve_target: Option<&'a RafxTexture>,
pub resolve_store_op: RafxStoreOp,
pub resolve_mip_slice: Option<u8>,
pub resolve_array_slice: Option<u16>,
}
#[derive(Debug)]
pub struct RafxDepthStencilRenderTargetBinding<'a> {
pub texture: &'a RafxTexture,
pub depth_load_op: RafxLoadOp,
pub stencil_load_op: RafxLoadOp,
pub depth_store_op: RafxStoreOp,
pub stencil_store_op: RafxStoreOp,
pub mip_slice: Option<u8>,
pub array_slice: Option<u16>,
pub clear_value: RafxDepthStencilClearValue,
}
pub struct RafxVertexBufferBinding<'a> {
pub buffer: &'a RafxBuffer,
pub byte_offset: u64,
}
pub struct RafxIndexBufferBinding<'a> {
pub buffer: &'a RafxBuffer,
pub byte_offset: u64,
pub index_type: RafxIndexType,
}
#[derive(Default)]
pub struct RafxCmdCopyBufferToTextureParams {
pub buffer_offset: u64,
pub array_layer: u16,
pub mip_level: u8,
}
pub struct RafxCmdBlitParams {
pub src_state: RafxResourceState,
pub dst_state: RafxResourceState,
pub src_extents: [RafxExtents3D; 2],
pub dst_extents: [RafxExtents3D; 2],
pub src_mip_level: u8,
pub dst_mip_level: u8,
pub array_slices: Option<[u16; 2]>,
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct RafxDescriptorIndex(pub(crate) u32);
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub enum RafxDescriptorKey<'a> {
Undefined,
Name(&'a str),
Binding(u32),
DescriptorIndex(RafxDescriptorIndex),
}
impl<'a> Default for RafxDescriptorKey<'a> {
fn default() -> Self {
RafxDescriptorKey::Undefined
}
}
#[derive(Default, Clone, Copy, Debug)]
pub struct RafxOffsetSize {
pub byte_offset: u64,
pub size: u64,
}
#[derive(Default, Debug)]
pub struct RafxDescriptorElements<'a> {
pub textures: Option<&'a [&'a RafxTexture]>,
pub samplers: Option<&'a [&'a RafxSampler]>,
pub buffers: Option<&'a [&'a RafxBuffer]>,
pub buffer_offset_sizes: Option<&'a [RafxOffsetSize]>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum RafxTextureBindType {
Srv,
SrvStencil,
UavMipChain,
UavMipSlice(u32),
}
#[derive(Debug)]
pub struct RafxDescriptorUpdate<'a> {
pub array_index: u32,
pub descriptor_key: RafxDescriptorKey<'a>,
pub elements: RafxDescriptorElements<'a>,
pub dst_element_offset: u32,
pub texture_bind_type: Option<RafxTextureBindType>,
}
impl<'a> Default for RafxDescriptorUpdate<'a> {
fn default() -> Self {
RafxDescriptorUpdate {
array_index: 0,
descriptor_key: RafxDescriptorKey::Undefined,
elements: RafxDescriptorElements::default(),
dst_element_offset: 0,
texture_bind_type: None,
}
}
}