-
Notifications
You must be signed in to change notification settings - Fork 1
/
struct_wrappers.rs
7525 lines (6331 loc) · 198 KB
/
struct_wrappers.rs
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
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use std::ffi::{CStr, CString, NulError};
use std::slice;
use std::str::Utf8Error;
use std::{convert::TryFrom, marker::PhantomData, mem::size_of};
use widestring::WideCStr;
use crate::utils::*;
use crate::{const_wrappers::*, PipelineState};
use crate::{enum_wrappers::*, RootSignature};
use crate::{raw_bindings::d3d12::*, DxError};
use crate::Resource;
// Only newtypes for data structs etc. live here;
// if a struct is not identical to the raw one,
// it should be placed directly in lib.rs
// ToDo: make namespaces for DXGI types and D3D12 since currently they're
// mixed up??
/// Wrapper around D3D12_GPU_VIRTUAL_ADDRESS structure
#[derive(Hash, PartialOrd, Ord, PartialEq, Eq, Debug, Clone, Copy)]
pub struct GpuVirtualAddress(pub D3D12_GPU_VIRTUAL_ADDRESS);
/// Wrapper around DXGI_SWAP_CHAIN_DESC1 structure
#[repr(transparent)]
#[derive(Hash, PartialOrd, Ord, PartialEq, Eq, Debug, Clone)]
pub struct SwapChainDesc(pub(crate) DXGI_SWAP_CHAIN_DESC1);
impl Default for SwapChainDesc {
fn default() -> Self {
SwapChainDesc(DXGI_SWAP_CHAIN_DESC1 {
Width: 0,
Height: 0,
Format: DXGI_FORMAT_DXGI_FORMAT_R8G8B8A8_UNORM,
Stereo: 0,
SampleDesc: SampleDesc::default().0,
BufferUsage: DXGI_USAGE_RENDER_TARGET_OUTPUT,
BufferCount: 2,
Scaling: DXGI_SCALING_DXGI_SCALING_STRETCH,
SwapEffect: DXGI_SWAP_EFFECT_DXGI_SWAP_EFFECT_FLIP_DISCARD,
AlphaMode: DXGI_ALPHA_MODE_DXGI_ALPHA_MODE_UNSPECIFIED,
Flags: DXGI_SWAP_CHAIN_FLAG_DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING
as u32,
})
}
}
impl SwapChainDesc {
pub fn set_width(&mut self, width: u32) -> &mut Self {
self.0.Width = width;
self
}
pub fn with_width(mut self, width: u32) -> Self {
self.set_width(width);
self
}
pub fn width(&self) -> u32 {
self.0.Width
}
pub fn set_height(&mut self, height: u32) -> &mut Self {
self.0.Height = height;
self
}
pub fn with_height(mut self, height: u32) -> Self {
self.set_height(height);
self
}
pub fn height(&self) -> u32 {
self.0.Height
}
pub fn set_format(&mut self, format: Format) -> &mut Self {
self.0.Format = format as i32;
self
}
pub fn with_format(mut self, format: Format) -> Self {
self.set_format(format);
self
}
pub fn format(&self) -> Format {
unsafe { std::mem::transmute(self.0.Format) }
}
pub fn set_stereo(&mut self, stereo: bool) -> &mut Self {
self.0.Stereo = stereo as i32;
self
}
pub fn with_stereo(mut self, stereo: bool) -> Self {
self.set_stereo(stereo);
self
}
pub fn stereo(&self) -> bool {
self.0.Stereo != 0
}
pub fn set_sample_desc(&mut self, sample_desc: SampleDesc) -> &mut Self {
self.0.SampleDesc = sample_desc.0;
self
}
pub fn with_sample_desc(mut self, sample_desc: SampleDesc) -> Self {
self.set_sample_desc(sample_desc);
self
}
pub fn sample_desc(&self) -> SampleDesc {
SampleDesc(self.0.SampleDesc)
}
pub fn set_buffer_usage(&mut self, buffer_usage: Usage) -> &mut Self {
self.0.BufferUsage = buffer_usage.bits();
self
}
pub fn with_buffer_usage(mut self, buffer_usage: Usage) -> Self {
self.set_buffer_usage(buffer_usage);
self
}
pub fn buffer_usage(&self) -> Usage {
unsafe { Usage::from_bits_unchecked(self.0.BufferUsage) }
}
pub fn set_buffer_count(&mut self, buffer_count: u32) -> &mut Self {
self.0.BufferCount = buffer_count;
self
}
pub fn with_buffer_count(mut self, buffer_count: u32) -> Self {
self.set_buffer_count(buffer_count);
self
}
pub fn buffer_count(&self) -> u32 {
self.0.BufferCount
}
pub fn set_scaling(&mut self, scaling: Scaling) -> &mut Self {
self.0.Scaling = scaling as i32;
self
}
pub fn with_scaling(mut self, scaling: Scaling) -> Self {
self.set_scaling(scaling);
self
}
pub fn scaling(&self) -> Scaling {
unsafe { std::mem::transmute(self.0.Scaling) }
}
pub fn set_swap_effect(&mut self, swap_effect: SwapEffect) -> &mut Self {
self.0.SwapEffect = swap_effect as i32;
self
}
pub fn with_swap_effect(mut self, swap_effect: SwapEffect) -> Self {
self.set_swap_effect(swap_effect);
self
}
pub fn swap_effect(&self) -> SwapEffect {
unsafe { std::mem::transmute(self.0.SwapEffect) }
}
pub fn set_alpha_mode(&mut self, alpha_mode: AlphaMode) -> &mut Self {
self.0.AlphaMode = alpha_mode as i32;
self
}
pub fn with_alpha_mode(mut self, alpha_mode: AlphaMode) -> Self {
self.set_alpha_mode(alpha_mode);
self
}
pub fn alpha_mode(&self) -> AlphaMode {
unsafe { std::mem::transmute(self.0.AlphaMode) }
}
pub fn set_flags(&mut self, flags: SwapChainFlags) -> &mut Self {
self.0.Flags = flags.bits() as u32;
self
}
pub fn with_flags(mut self, flags: SwapChainFlags) -> Self {
self.set_flags(flags);
self
}
pub fn flags(&self) -> SwapChainFlags {
unsafe { std::mem::transmute(self.0.Flags) }
}
}
/// Wrapper around DXGI_ADAPTER_DESC1 structure
#[derive(Hash, PartialOrd, Ord, PartialEq, Eq, Clone)]
#[repr(transparent)]
pub struct AdapterDesc(pub(crate) DXGI_ADAPTER_DESC1);
impl AdapterDesc {
pub fn is_software(&self) -> bool {
self.0.Flags & DXGI_ADAPTER_FLAG_DXGI_ADAPTER_FLAG_SOFTWARE as u32 != 0
}
// ToDo: clean up?
pub fn description(&self) -> Option<String> {
WideCStr::from_slice_with_nul(&self.0.Description)
.map(|wide_cstr| wide_cstr.to_string_lossy())
.ok()
}
pub fn set_vendor_id(&mut self, vendor_id: u32) -> &mut Self {
self.0.VendorId = vendor_id;
self
}
pub fn with_vendor_id(mut self, vendor_id: u32) -> Self {
self.set_vendor_id(vendor_id);
self
}
pub fn vendor_id(&self) -> u32 {
self.0.VendorId
}
pub fn set_device_id(&mut self, device_id: u32) -> &mut Self {
self.0.DeviceId = device_id;
self
}
pub fn with_device_id(mut self, device_id: u32) -> Self {
self.set_device_id(device_id);
self
}
pub fn device_id(&self) -> u32 {
self.0.DeviceId
}
pub fn set_sub_sys_id(&mut self, sub_sys_id: u32) -> &mut Self {
self.0.SubSysId = sub_sys_id;
self
}
pub fn with_sub_sys_id(mut self, sub_sys_id: u32) -> Self {
self.set_sub_sys_id(sub_sys_id);
self
}
pub fn sub_sys_id(&self) -> u32 {
self.0.SubSysId
}
pub fn set_revision(&mut self, revision: u32) -> &mut Self {
self.0.Revision = revision;
self
}
pub fn with_revision(mut self, revision: u32) -> Self {
self.set_revision(revision);
self
}
pub fn revision(&self) -> u32 {
self.0.Revision
}
pub fn set_dedicated_video_memory(
&mut self,
dedicated_video_memory: u64,
) -> &mut Self {
self.0.DedicatedVideoMemory = dedicated_video_memory;
self
}
pub fn with_dedicated_video_memory(
mut self,
dedicated_video_memory: u64,
) -> Self {
self.set_dedicated_video_memory(dedicated_video_memory);
self
}
pub fn dedicated_video_memory(&self) -> u64 {
self.0.DedicatedVideoMemory
}
pub fn set_dedicated_system_memory(
&mut self,
dedicated_system_memory: u64,
) -> &mut Self {
self.0.DedicatedSystemMemory = dedicated_system_memory;
self
}
pub fn with_dedicated_system_memory(
mut self,
dedicated_system_memory: u64,
) -> Self {
self.set_dedicated_system_memory(dedicated_system_memory);
self
}
pub fn dedicated_system_memory(&self) -> u64 {
self.0.DedicatedSystemMemory
}
pub fn set_shared_system_memory(
&mut self,
shared_system_memory: u64,
) -> &mut Self {
self.0.SharedSystemMemory = shared_system_memory;
self
}
pub fn with_shared_system_memory(
mut self,
shared_system_memory: u64,
) -> Self {
self.set_shared_system_memory(shared_system_memory);
self
}
pub fn shared_system_memory(&self) -> u64 {
self.0.SharedSystemMemory
}
pub fn set_flags(&mut self, flags: AdapterFlag) -> &mut Self {
self.0.Flags = flags as u32;
self
}
pub fn with_flags(mut self, flags: AdapterFlag) -> Self {
self.set_flags(flags);
self
}
pub fn flags(&self) -> AdapterFlag {
unsafe { std::mem::transmute(self.0.Flags) }
}
}
impl Default for AdapterDesc {
fn default() -> Self {
AdapterDesc(DXGI_ADAPTER_DESC1 {
Description: [0; 128],
VendorId: 0,
DeviceId: 0,
SubSysId: 0,
Revision: 0,
DedicatedVideoMemory: 0,
DedicatedSystemMemory: 0,
SharedSystemMemory: 0,
AdapterLuid: LUID {
LowPart: 0,
HighPart: 0,
},
Flags: 0,
})
}
}
impl std::fmt::Display for AdapterDesc {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
concat!(
"Description: {}, VendorId: {:x}, DeviceId: {:x}, ",
"SubSysId: {:x}, Revision: {:x}, DedicatedVideoMemory: {}, ",
"DedicatedSystemMemory: {}, SharedSystemMemory: {}, ",
"AdapterLuid.LowPart: {:x}, AdapterLuid.HighPart: {:x}, Flags: {:x}"
),
WideCStr::from_slice_with_nul(&self.0.Description)
.expect("Adapter desc is not valid utf-16")
.to_string_lossy(),
self.0.VendorId,
self.0.DeviceId,
self.0.SubSysId,
self.0.Revision,
self.0.DedicatedVideoMemory,
self.0.DedicatedSystemMemory,
self.0.SharedSystemMemory,
self.0.AdapterLuid.LowPart,
self.0.AdapterLuid.HighPart,
self.0.Flags
)
}
}
impl std::fmt::Debug for AdapterDesc {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self)
}
}
/// Wrapper around DXGI_SAMPLE_DESC structure
#[derive(Debug, Hash, PartialOrd, Ord, PartialEq, Eq, Clone, Copy)]
#[repr(transparent)]
pub struct SampleDesc(pub(crate) DXGI_SAMPLE_DESC);
impl Default for SampleDesc {
fn default() -> Self {
Self(DXGI_SAMPLE_DESC {
Count: 1,
Quality: 0,
})
}
}
impl SampleDesc {
pub fn set_count(&mut self, count: u32) -> &mut Self {
self.0.Count = count;
self
}
pub fn with_count(mut self, count: u32) -> Self {
self.set_count(count);
self
}
pub fn count(&self) -> u32 {
self.0.Count
}
pub fn set_quality(&mut self, quality: u32) -> &mut Self {
self.0.Quality = quality;
self
}
pub fn with_quality(mut self, quality: u32) -> Self {
self.set_quality(quality);
self
}
pub fn quality(&self) -> u32 {
self.0.Quality
}
}
/// Wrapper around D3D12_RESOURCE_DESC structure
#[repr(transparent)]
#[derive(Hash, PartialOrd, Ord, PartialEq, Eq, Copy, Clone, Debug)]
pub struct ResourceDesc(pub(crate) D3D12_RESOURCE_DESC);
impl Default for ResourceDesc {
fn default() -> Self {
ResourceDesc(D3D12_RESOURCE_DESC {
Dimension: ResourceDimension::Unknown as i32,
Alignment: D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT as u64,
Width: 0,
Height: 1,
DepthOrArraySize: 1,
MipLevels: 1,
Format: Format::Unknown as i32,
SampleDesc: SampleDesc::default().0,
Layout: TextureLayout::Unknown as i32,
Flags: ResourceFlags::None.bits(),
})
}
}
impl ResourceDesc {
pub fn set_dimension(&mut self, dimension: ResourceDimension) -> &mut Self {
self.0.Dimension = dimension as i32;
self
}
pub fn with_dimension(mut self, dimension: ResourceDimension) -> Self {
self.set_dimension(dimension);
self
}
pub fn dimension(&self) -> ResourceDimension {
unsafe { std::mem::transmute(self.0.Dimension) }
}
pub fn set_alignment(&mut self, alignment: u64) -> &mut Self {
self.0.Alignment = alignment;
self
}
pub fn with_alignment(mut self, alignment: u64) -> Self {
self.set_alignment(alignment);
self
}
pub fn alignment(&self) -> u64 {
self.0.Alignment
}
pub fn set_width(&mut self, width: u64) -> &mut Self {
self.0.Width = width;
self
}
pub fn with_width(mut self, width: u64) -> Self {
self.set_width(width);
self
}
pub fn width(&self) -> u64 {
self.0.Width
}
pub fn set_height(&mut self, height: u32) -> &mut Self {
self.0.Height = height;
self
}
pub fn with_height(mut self, height: u32) -> Self {
self.set_height(height);
self
}
pub fn height(&self) -> u32 {
self.0.Height
}
pub fn set_depth_or_array_size(
&mut self,
depth_or_array_size: u16,
) -> &mut Self {
self.0.DepthOrArraySize = depth_or_array_size;
self
}
pub fn with_depth_or_array_size(
mut self,
depth_or_array_size: u16,
) -> Self {
self.set_depth_or_array_size(depth_or_array_size);
self
}
pub fn depth_or_array_size(&self) -> u16 {
self.0.DepthOrArraySize
}
pub fn set_mip_levels(&mut self, mip_levels: u16) -> &mut Self {
self.0.MipLevels = mip_levels;
self
}
pub fn with_mip_levels(mut self, mip_levels: u16) -> Self {
self.set_mip_levels(mip_levels);
self
}
pub fn mip_levels(&self) -> u16 {
self.0.MipLevels
}
pub fn set_format(&mut self, format: Format) -> &mut Self {
self.0.Format = format as i32;
self
}
pub fn with_format(mut self, format: Format) -> Self {
self.set_format(format);
self
}
pub fn format(&self) -> Format {
unsafe { std::mem::transmute(self.0.Format) }
}
pub fn set_sample_desc(&mut self, sample_desc: SampleDesc) -> &mut Self {
self.0.SampleDesc = sample_desc.0;
self
}
pub fn with_sample_desc(mut self, sample_desc: SampleDesc) -> Self {
self.set_sample_desc(sample_desc);
self
}
pub fn sample_desc(&self) -> SampleDesc {
SampleDesc(self.0.SampleDesc)
}
pub fn set_layout(&mut self, layout: TextureLayout) -> &mut Self {
self.0.Layout = layout as i32;
self
}
pub fn with_layout(mut self, layout: TextureLayout) -> Self {
self.set_layout(layout);
self
}
pub fn layout(&self) -> TextureLayout {
unsafe { std::mem::transmute(self.0.Layout) }
}
pub fn set_flags(&mut self, flags: ResourceFlags) -> &mut Self {
self.0.Flags = flags.bits();
self
}
pub fn with_flags(mut self, flags: ResourceFlags) -> Self {
self.set_flags(flags);
self
}
pub fn flags(&self) -> ResourceFlags {
unsafe { ResourceFlags::from_bits_unchecked(self.0.Flags) }
}
}
/// Wrapper around D3D12_MESSAGE structure
#[repr(transparent)]
#[derive(Hash, PartialOrd, Ord, PartialEq, Eq, Debug, Clone)]
pub struct Message(pub(crate) D3D12_MESSAGE);
impl Default for Message {
fn default() -> Self {
Message(D3D12_MESSAGE {
Category:
D3D12_MESSAGE_CATEGORY_D3D12_MESSAGE_CATEGORY_MISCELLANEOUS,
Severity: D3D12_MESSAGE_SEVERITY_D3D12_MESSAGE_SEVERITY_MESSAGE,
ID: 0,
pDescription: std::ptr::null(),
DescriptionByteLength: 0,
})
}
}
/// Wrapper around D3D12_HEAP_PROPERTIES structure
#[derive(Default, Debug, Hash, PartialOrd, Ord, PartialEq, Eq, Clone)]
#[repr(transparent)]
pub struct HeapProperties(pub(crate) D3D12_HEAP_PROPERTIES);
impl HeapProperties {
pub fn set_heap_type(&mut self, heap_type: HeapType) -> &mut Self {
self.0.Type = heap_type as i32;
self
}
pub fn with_heap_type(mut self, heap_type: HeapType) -> Self {
self.set_heap_type(heap_type);
self
}
pub fn heap_type(&self) -> HeapType {
unsafe { std::mem::transmute(self.0.Type) }
}
pub fn set_cpu_page_property(
&mut self,
cpu_page_property: CpuPageProperty,
) -> &mut Self {
self.0.CPUPageProperty = cpu_page_property as i32;
self
}
pub fn with_cpu_page_property(
mut self,
cpu_page_property: CpuPageProperty,
) -> Self {
self.set_cpu_page_property(cpu_page_property);
self
}
pub fn cpu_page_property(&self) -> CpuPageProperty {
unsafe { std::mem::transmute(self.0.CPUPageProperty) }
}
pub fn set_memory_pool_preference(
&mut self,
memory_pool_preference: MemoryPool,
) -> &mut Self {
self.0.MemoryPoolPreference = memory_pool_preference as i32;
self
}
pub fn with_memory_pool_preference(
mut self,
memory_pool_preference: MemoryPool,
) -> Self {
self.set_memory_pool_preference(memory_pool_preference);
self
}
pub fn memory_pool_preference(&self) -> MemoryPool {
unsafe { std::mem::transmute(self.0.MemoryPoolPreference) }
}
pub fn set_creation_node_mask(
&mut self,
creation_node_mask: u32,
) -> &mut Self {
self.0.CreationNodeMask = creation_node_mask;
self
}
pub fn with_creation_node_mask(mut self, creation_node_mask: u32) -> Self {
self.set_creation_node_mask(creation_node_mask);
self
}
pub fn creation_node_mask(&self) -> u32 {
self.0.CreationNodeMask
}
pub fn set_visible_node_mask(
&mut self,
visible_node_mask: u32,
) -> &mut Self {
self.0.VisibleNodeMask = visible_node_mask;
self
}
pub fn with_visible_node_mask(mut self, visible_node_mask: u32) -> Self {
self.set_visible_node_mask(visible_node_mask);
self
}
pub fn visible_node_mask(&self) -> u32 {
self.0.VisibleNodeMask
}
}
/// Wrapper around D3D12_RANGE structure
#[derive(Default, Debug, Hash, PartialOrd, Ord, PartialEq, Eq, Clone)]
#[repr(transparent)]
pub struct Range(pub(crate) D3D12_RANGE);
impl Range {
pub fn set_begin(&mut self, begin: ByteCount) -> &mut Self {
self.0.Begin = begin.0;
self
}
pub fn with_begin(mut self, begin: ByteCount) -> Self {
self.set_begin(begin);
self
}
pub fn begin(&self) -> ByteCount {
ByteCount(self.0.Begin)
}
pub fn set_end(&mut self, end: ByteCount) -> &mut Self {
self.0.End = end.0;
self
}
pub fn with_end(mut self, end: ByteCount) -> Self {
self.set_end(end);
self
}
pub fn end(&self) -> ByteCount {
ByteCount(self.0.End)
}
}
// ToDo: impl Hash where it's needed but cannot be derived
/// Wrapper around D3D12_RESOURCE_BARRIER structure. Note this type is not Clone since it contains a raw pointer
#[repr(transparent)]
#[derive(Debug)]
pub struct ResourceBarrier(pub(crate) D3D12_RESOURCE_BARRIER);
impl ResourceBarrier {
pub fn barrier_type(&self) -> ResourceBarrierType {
unsafe { std::mem::transmute(self.0.Type) }
}
pub fn set_flags(&mut self, flags: ResourceBarrierFlags) -> &mut Self {
self.0.Flags = flags.bits();
self
}
pub fn with_flags(mut self, flags: ResourceBarrierFlags) -> Self {
self.set_flags(flags);
self
}
pub fn flags(&self) -> ResourceBarrierFlags {
unsafe { ResourceBarrierFlags::from_bits_unchecked(self.0.Flags) }
}
// ToDo: rename it??
pub fn new_transition(desc: &ResourceTransitionBarrier) -> Self {
Self(D3D12_RESOURCE_BARRIER {
Type: ResourceBarrierType::Transition as i32,
Flags: ResourceBarrierFlags::None.bits(),
__bindgen_anon_1: D3D12_RESOURCE_BARRIER__bindgen_ty_1 {
Transition: desc.0,
},
})
}
pub fn transition(&self) -> Option<ResourceTransitionBarrier> {
unsafe {
match self.barrier_type() {
ResourceBarrierType::Transition => {
Some(ResourceTransitionBarrier(
self.0.__bindgen_anon_1.Transition,
))
}
_ => None,
}
}
}
pub fn new_aliasing(desc: &ResourceAliasingBarrier) -> Self {
Self(D3D12_RESOURCE_BARRIER {
Type: ResourceBarrierType::Aliasing as i32,
Flags: ResourceBarrierFlags::None.bits(),
__bindgen_anon_1: D3D12_RESOURCE_BARRIER__bindgen_ty_1 {
Aliasing: desc.0,
},
})
}
pub fn aliasing(&self) -> Option<ResourceAliasingBarrier> {
unsafe {
match self.barrier_type() {
ResourceBarrierType::Aliasing => Some(ResourceAliasingBarrier(
self.0.__bindgen_anon_1.Aliasing,
)),
_ => None,
}
}
}
pub fn new_uav(desc: &ResourceUavBarrier) -> Self {
Self(D3D12_RESOURCE_BARRIER {
Type: ResourceBarrierType::Uav as i32,
Flags: ResourceBarrierFlags::None.bits(),
__bindgen_anon_1: D3D12_RESOURCE_BARRIER__bindgen_ty_1 {
UAV: desc.0,
},
})
}
pub fn uav(&self) -> Option<ResourceUavBarrier> {
unsafe {
match self.barrier_type() {
ResourceBarrierType::Uav => {
Some(ResourceUavBarrier(self.0.__bindgen_anon_1.UAV))
}
_ => None,
}
}
}
}
/// Wrapper around D3D12_RESOURCE_TRANSITION_BARRIER structure
#[derive(Hash, PartialOrd, Ord, PartialEq, Eq, Default, Debug)]
#[repr(transparent)]
pub struct ResourceTransitionBarrier(
pub(crate) D3D12_RESOURCE_TRANSITION_BARRIER,
);
impl ResourceTransitionBarrier {
pub fn set_resource(&mut self, resource: &Resource) -> &mut Self {
self.0.pResource = resource.this;
self
}
pub fn with_resource(mut self, resource: &Resource) -> Self {
self.set_resource(resource);
self
}
// ToDo: return reference?
pub fn resource(&self) -> Resource {
let resource = Resource {
this: self.0.pResource,
};
resource.add_ref();
resource
}
// None value means "all subresources"
pub fn set_subresource(&mut self, subresource: Option<u32>) -> &mut Self {
match subresource {
Some(index) => self.0.Subresource = index,
None => {
self.0.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES
}
}
self
}
pub fn with_subresource(mut self, subresource: Option<u32>) -> Self {
self.set_subresource(subresource);
self
}
pub fn subresource(&self) -> Option<u32> {
match self.0.Subresource {
D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES => None,
_ => Some(self.0.Subresource),
}
}
pub fn set_state_before(
&mut self,
state_before: ResourceStates,
) -> &mut Self {
self.0.StateBefore = state_before.bits();
self
}
pub fn with_state_before(mut self, state_before: ResourceStates) -> Self {
self.set_state_before(state_before);
self
}
pub fn state_before(&self) -> ResourceStates {
unsafe { ResourceStates::from_bits_unchecked(self.0.StateBefore) }
}
pub fn set_state_after(
&mut self,
state_after: ResourceStates,
) -> &mut Self {
self.0.StateAfter = state_after.bits();
self
}
pub fn with_state_after(mut self, state_after: ResourceStates) -> Self {
self.set_state_after(state_after);
self
}
pub fn state_after(&self) -> ResourceStates {
unsafe { ResourceStates::from_bits_unchecked(self.0.StateAfter) }
}
}
/// Wrapper around D3D12_RESOURCE_ALIASING_BARRIER structure
#[derive(Hash, PartialOrd, Ord, PartialEq, Eq, Default, Debug)]
#[repr(transparent)]
pub struct ResourceAliasingBarrier(pub(crate) D3D12_RESOURCE_ALIASING_BARRIER);
impl ResourceAliasingBarrier {
pub fn set_resource_before(
&mut self,
resource_before: &Resource,
) -> &mut Self {
self.0.pResourceBefore = resource_before.this;
self
}
pub fn with_resource_before(mut self, resource_before: &Resource) -> Self {
self.set_resource_before(resource_before);
self
}
pub fn resource_before(&self) -> Resource {
let resource = Resource {
this: self.0.pResourceBefore,
};
resource.add_ref();
resource
}
pub fn set_resource_after(
&mut self,
resource_after: &Resource,
) -> &mut Self {
self.0.pResourceAfter = resource_after.this;
self
}
pub fn with_resource_after(mut self, resource_after: &Resource) -> Self {
self.set_resource_after(resource_after);
self
}
pub fn resource_after(&self) -> Resource {
let resource = Resource {
this: self.0.pResourceAfter,
};
resource.add_ref();
resource
}
}
/// Wrapper around D3D12_RESOURCE_UAV_BARRIER structure
#[derive(Hash, PartialOrd, Ord, PartialEq, Eq, Default, Debug)]