-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpipeline.rs
More file actions
758 lines (676 loc) · 20.7 KB
/
pipeline.rs
File metadata and controls
758 lines (676 loc) · 20.7 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
//! Pipeline and shader module wrappers/builders for the platform layer.
use std::ops::Range;
use wgpu;
pub use crate::wgpu::vertex::VertexStepMode;
use crate::wgpu::{
bind,
gpu::Gpu,
texture::{
DepthFormat,
TextureFormat,
},
vertex::ColorFormat,
};
/// Shader stage flags for visibility.
#[derive(Clone, Copy, Debug)]
///
/// This wrapper avoids exposing `wgpu` directly to higher layers while still
/// allowing flexible combinations when needed.
pub struct PipelineStage(wgpu::ShaderStages);
impl PipelineStage {
/// Vertex stage only.
pub const VERTEX: PipelineStage = PipelineStage(wgpu::ShaderStages::VERTEX);
/// Fragment stage only.
pub const FRAGMENT: PipelineStage =
PipelineStage(wgpu::ShaderStages::FRAGMENT);
/// Compute stage only.
pub const COMPUTE: PipelineStage = PipelineStage(wgpu::ShaderStages::COMPUTE);
/// Internal mapping to the underlying graphics API.
pub fn to_wgpu(self) -> wgpu::ShaderStages {
return self.0;
}
}
impl std::ops::BitOr for PipelineStage {
type Output = PipelineStage;
fn bitor(self, rhs: PipelineStage) -> PipelineStage {
return PipelineStage(self.0 | rhs.0);
}
}
impl std::ops::BitOrAssign for PipelineStage {
fn bitor_assign(&mut self, rhs: PipelineStage) {
self.0 |= rhs.0;
}
}
/// Immediate data declaration for a byte range.
#[derive(Clone, Debug)]
pub struct ImmediateDataRange {
pub range: Range<u32>,
}
/// Face culling mode for graphics pipelines.
#[derive(Clone, Copy, Debug)]
pub enum CullingMode {
None,
Front,
Back,
}
impl CullingMode {
fn to_wgpu(self) -> Option<wgpu::Face> {
return match self {
CullingMode::None => None,
CullingMode::Front => Some(wgpu::Face::Front),
CullingMode::Back => Some(wgpu::Face::Back),
};
}
}
/// Description of a single vertex attribute used by a pipeline.
#[derive(Clone, Copy, Debug)]
pub struct VertexAttributeDesc {
pub shader_location: u32,
pub offset: u64,
pub format: ColorFormat,
}
/// Description of a single vertex buffer layout used by a pipeline.
#[derive(Clone, Debug)]
struct VertexBufferLayoutDesc {
array_stride: u64,
step_mode: VertexStepMode,
attributes: Vec<VertexAttributeDesc>,
}
/// Compare function used for depth and stencil tests.
#[derive(Clone, Copy, Debug)]
pub enum CompareFunction {
Never,
Less,
LessEqual,
Greater,
GreaterEqual,
Equal,
NotEqual,
Always,
}
impl CompareFunction {
fn to_wgpu(self) -> wgpu::CompareFunction {
match self {
CompareFunction::Never => wgpu::CompareFunction::Never,
CompareFunction::Less => wgpu::CompareFunction::Less,
CompareFunction::LessEqual => wgpu::CompareFunction::LessEqual,
CompareFunction::Greater => wgpu::CompareFunction::Greater,
CompareFunction::GreaterEqual => wgpu::CompareFunction::GreaterEqual,
CompareFunction::Equal => wgpu::CompareFunction::Equal,
CompareFunction::NotEqual => wgpu::CompareFunction::NotEqual,
CompareFunction::Always => wgpu::CompareFunction::Always,
}
}
}
/// Stencil operation applied when the stencil test or depth test passes/fails.
#[derive(Clone, Copy, Debug)]
pub enum StencilOperation {
Keep,
Zero,
Replace,
Invert,
IncrementClamp,
DecrementClamp,
IncrementWrap,
DecrementWrap,
}
impl StencilOperation {
fn to_wgpu(self) -> wgpu::StencilOperation {
match self {
StencilOperation::Keep => wgpu::StencilOperation::Keep,
StencilOperation::Zero => wgpu::StencilOperation::Zero,
StencilOperation::Replace => wgpu::StencilOperation::Replace,
StencilOperation::Invert => wgpu::StencilOperation::Invert,
StencilOperation::IncrementClamp => {
wgpu::StencilOperation::IncrementClamp
}
StencilOperation::DecrementClamp => {
wgpu::StencilOperation::DecrementClamp
}
StencilOperation::IncrementWrap => wgpu::StencilOperation::IncrementWrap,
StencilOperation::DecrementWrap => wgpu::StencilOperation::DecrementWrap,
}
}
}
/// Per-face stencil state.
#[derive(Clone, Copy, Debug)]
pub struct StencilFaceState {
pub compare: CompareFunction,
pub fail_op: StencilOperation,
pub depth_fail_op: StencilOperation,
pub pass_op: StencilOperation,
}
impl StencilFaceState {
fn to_wgpu(self) -> wgpu::StencilFaceState {
wgpu::StencilFaceState {
compare: self.compare.to_wgpu(),
fail_op: self.fail_op.to_wgpu(),
depth_fail_op: self.depth_fail_op.to_wgpu(),
pass_op: self.pass_op.to_wgpu(),
}
}
}
/// Full stencil state (front/back + masks).
#[derive(Clone, Copy, Debug)]
pub struct StencilState {
pub front: StencilFaceState,
pub back: StencilFaceState,
pub read_mask: u32,
pub write_mask: u32,
}
/// Wrapper around `wgpu::ShaderModule` that preserves a label.
#[derive(Debug)]
pub struct ShaderModule {
raw: wgpu::ShaderModule,
label: Option<String>,
}
impl ShaderModule {
/// Create a shader module from SPIR-V words.
pub fn from_spirv(gpu: &Gpu, words: &[u32], label: Option<&str>) -> Self {
let raw = gpu
.device()
.create_shader_module(wgpu::ShaderModuleDescriptor {
label,
source: wgpu::ShaderSource::SpirV(std::borrow::Cow::Borrowed(words)),
});
return Self {
raw,
label: label.map(|s| s.to_string()),
};
}
/// Borrow the raw shader module.
pub fn raw(&self) -> &wgpu::ShaderModule {
&self.raw
}
/// Optional debug label used during creation.
pub fn label(&self) -> Option<&str> {
return self.label.as_deref();
}
}
/// Wrapper around `wgpu::PipelineLayout`.
#[derive(Debug)]
pub struct PipelineLayout {
raw: wgpu::PipelineLayout,
label: Option<String>,
}
impl PipelineLayout {
/// Borrow the raw pipeline layout.
pub fn raw(&self) -> &wgpu::PipelineLayout {
return &self.raw;
}
/// Optional debug label used during creation.
pub fn label(&self) -> Option<&str> {
return self.label.as_deref();
}
}
/// Builder for creating a `PipelineLayout`.
pub struct PipelineLayoutBuilder<'a> {
label: Option<String>,
layouts: Vec<&'a bind::BindGroupLayout>,
immediate_data_ranges: Vec<ImmediateDataRange>,
}
impl<'a> Default for PipelineLayoutBuilder<'a> {
fn default() -> Self {
return Self::new();
}
}
/// Align a `u32` value up to the provided power-of-two alignment.
fn align_up_u32(value: u32, alignment: u32) -> u32 {
if alignment == 0 {
return value;
}
let remainder = value % alignment;
if remainder == 0 {
return value;
}
return value + (alignment - remainder);
}
/// Validate immediate ranges and calculate the minimum allocation size.
///
/// wgpu v28 uses a single byte region of size `immediate_size`, addressed by
/// `set_immediates(offset, data)`. This function enforces that the provided
/// ranges:
/// - Start at byte offset 0 (as a union)
/// - Cover a contiguous span with no gaps (as a union)
/// - Are aligned to `wgpu::IMMEDIATE_DATA_ALIGNMENT`
fn validate_and_calculate_immediate_size(
immediate_data_ranges: &[ImmediateDataRange],
) -> Result<u32, String> {
if immediate_data_ranges.is_empty() {
return Ok(0);
}
let alignment = wgpu::IMMEDIATE_DATA_ALIGNMENT;
let mut sorted_ranges: Vec<Range<u32>> = immediate_data_ranges
.iter()
.map(|r| r.range.clone())
.collect();
sorted_ranges.sort_by_key(|range| (range.start, range.end));
for range in &sorted_ranges {
if range.start > range.end {
return Err(format!(
"Immediate data range start {} exceeds end {}.",
range.start, range.end
));
}
if range.start == range.end {
return Err(format!(
"Immediate data range {}..{} is empty.",
range.start, range.end
));
}
if range.start % alignment != 0 {
return Err(format!(
"Immediate data range start {} is not aligned to {} bytes.",
range.start, alignment
));
}
if range.end % alignment != 0 {
return Err(format!(
"Immediate data range end {} is not aligned to {} bytes.",
range.end, alignment
));
}
}
let mut current_end = 0;
for range in &sorted_ranges {
if range.start > current_end {
return Err(format!(
"Immediate data ranges must be contiguous starting at 0; found gap \
{}..{}.",
current_end, range.start
));
}
current_end = current_end.max(range.end);
}
if current_end % alignment != 0 {
return Err(format!(
"Immediate data size {} is not aligned to {} bytes.",
current_end, alignment
));
}
return Ok(current_end);
}
impl<'a> PipelineLayoutBuilder<'a> {
/// New builder with no layouts or immediate data.
pub fn new() -> Self {
return Self {
label: None,
layouts: Vec::new(),
immediate_data_ranges: Vec::new(),
};
}
/// Attach a label.
pub fn with_label(mut self, label: &str) -> Self {
self.label = Some(label.to_string());
return self;
}
/// Provide bind group layouts.
pub fn with_layouts(mut self, layouts: &'a [&bind::BindGroupLayout]) -> Self {
self.layouts = layouts.to_vec();
return self;
}
/// Provide immediate data byte ranges.
pub fn with_immediate_data_ranges(
mut self,
ranges: Vec<ImmediateDataRange>,
) -> Self {
self.immediate_data_ranges = ranges;
return self;
}
/// Build the layout.
pub fn build(self, gpu: &Gpu) -> PipelineLayout {
let layouts_raw: Vec<&wgpu::BindGroupLayout> =
self.layouts.iter().map(|l| l.raw()).collect();
// wgpu v28 allocates a single immediate byte region sized by
// `PipelineLayoutDescriptor::immediate_size`. If callers provide multiple
// ranges, they are treated as sub-ranges of the same contiguous allocation.
//
// Validate that the union of ranges starts at 0 and has no gaps so that the
// required allocation size is well-defined.
let (immediate_size, fallback_used) =
match validate_and_calculate_immediate_size(&self.immediate_data_ranges) {
Ok(size) => (size, false),
Err(message) => {
logging::error!(
"Invalid immediate data ranges for pipeline layout: {}",
message
);
debug_assert!(false, "{}", message);
let max_end = self
.immediate_data_ranges
.iter()
.map(|r| r.range.end)
.max()
.unwrap_or(0);
(align_up_u32(max_end, wgpu::IMMEDIATE_DATA_ALIGNMENT), true)
}
};
let raw =
gpu
.device()
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: self.label.as_deref(),
bind_group_layouts: &layouts_raw,
immediate_size,
});
if fallback_used {
logging::warn!(
"Pipeline layout immediate size computed using fallback; consider \
declaring immediate ranges as a single contiguous span starting at 0."
);
}
return PipelineLayout {
raw,
label: self.label,
};
}
}
#[cfg(test)]
mod immediate_size_tests {
use super::{
validate_and_calculate_immediate_size,
ImmediateDataRange,
};
#[test]
fn immediate_size_empty_ok() {
let size = validate_and_calculate_immediate_size(&[]).unwrap();
assert_eq!(size, 0);
}
#[test]
fn immediate_size_overlapping_ranges_ok() {
let ranges = vec![
ImmediateDataRange { range: 0..64 },
ImmediateDataRange { range: 0..32 },
];
let size = validate_and_calculate_immediate_size(&ranges).unwrap();
assert_eq!(size, 64);
}
#[test]
fn immediate_size_contiguous_ranges_ok() {
let ranges = vec![
ImmediateDataRange { range: 0..16 },
ImmediateDataRange { range: 16..32 },
];
let size = validate_and_calculate_immediate_size(&ranges).unwrap();
assert_eq!(size, 32);
}
#[test]
fn immediate_size_gap_is_error() {
let ranges = vec![
ImmediateDataRange { range: 0..16 },
ImmediateDataRange { range: 32..48 },
];
let err = validate_and_calculate_immediate_size(&ranges).unwrap_err();
assert!(err.contains("gap"));
}
#[test]
fn immediate_size_non_zero_start_is_error() {
let ranges = vec![ImmediateDataRange { range: 16..32 }];
let err = validate_and_calculate_immediate_size(&ranges).unwrap_err();
assert!(err.contains("gap"));
}
}
/// Wrapper around `wgpu::RenderPipeline`.
#[derive(Debug)]
pub struct RenderPipeline {
raw: wgpu::RenderPipeline,
label: Option<String>,
}
impl RenderPipeline {
/// Borrow the raw pipeline.
pub(crate) fn raw(&self) -> &wgpu::RenderPipeline {
return &self.raw;
}
/// Pipeline label if provided.
pub fn label(&self) -> Option<&str> {
return self.label.as_deref();
}
}
/// Builder for creating a graphics render pipeline.
pub struct RenderPipelineBuilder<'a> {
label: Option<String>,
layout: Option<&'a wgpu::PipelineLayout>,
vertex_buffers: Vec<VertexBufferLayoutDesc>,
cull_mode: CullingMode,
color_target_format: Option<wgpu::TextureFormat>,
depth_stencil: Option<wgpu::DepthStencilState>,
sample_count: u32,
}
impl<'a> Default for RenderPipelineBuilder<'a> {
fn default() -> Self {
return Self::new();
}
}
impl<'a> RenderPipelineBuilder<'a> {
/// New builder with defaults.
pub fn new() -> Self {
return Self {
label: None,
layout: None,
vertex_buffers: Vec::new(),
cull_mode: CullingMode::Back,
color_target_format: None,
depth_stencil: None,
sample_count: 1,
};
}
/// Attach a label.
pub fn with_label(mut self, label: &str) -> Self {
self.label = Some(label.to_string());
return self;
}
/// Use the provided pipeline layout.
pub fn with_layout(mut self, layout: &'a PipelineLayout) -> Self {
self.layout = Some(layout.raw());
return self;
}
/// Add a vertex buffer layout with attributes.
pub fn with_vertex_buffer(
mut self,
array_stride: u64,
attributes: Vec<VertexAttributeDesc>,
) -> Self {
self = self.with_vertex_buffer_step_mode(
array_stride,
VertexStepMode::Vertex,
attributes,
);
return self;
}
/// Add a vertex buffer layout with attributes and an explicit step mode.
pub fn with_vertex_buffer_step_mode(
mut self,
array_stride: u64,
step_mode: VertexStepMode,
attributes: Vec<VertexAttributeDesc>,
) -> Self {
self.vertex_buffers.push(VertexBufferLayoutDesc {
array_stride,
step_mode,
attributes,
});
return self;
}
/// Set cull mode (None disables culling).
pub fn with_cull_mode(mut self, mode: CullingMode) -> Self {
self.cull_mode = mode;
return self;
}
/// Set single color target for fragment stage from a texture format.
pub fn with_color_target(mut self, format: TextureFormat) -> Self {
self.color_target_format = Some(format.to_wgpu());
return self;
}
/// Enable depth testing/writes using the provided depth format and default compare/write settings.
///
/// Defaults: compare Less, depth writes enabled, no stencil.
pub fn with_depth_stencil(mut self, format: DepthFormat) -> Self {
self.depth_stencil = Some(wgpu::DepthStencilState {
format: format.to_wgpu(),
depth_write_enabled: true,
depth_compare: wgpu::CompareFunction::Less,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
});
return self;
}
/// Set the depth compare function. Requires depth to be enabled.
pub fn with_depth_compare(mut self, compare: CompareFunction) -> Self {
let ds = self.depth_stencil.get_or_insert(wgpu::DepthStencilState {
format: wgpu::TextureFormat::Depth32Float,
depth_write_enabled: true,
depth_compare: wgpu::CompareFunction::Less,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
});
ds.depth_compare = compare.to_wgpu();
return self;
}
/// Enable or disable depth writes. Requires depth-stencil enabled.
pub fn with_depth_write_enabled(mut self, enabled: bool) -> Self {
let ds = self.depth_stencil.get_or_insert(wgpu::DepthStencilState {
format: wgpu::TextureFormat::Depth32Float,
depth_write_enabled: true,
depth_compare: wgpu::CompareFunction::Less,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
});
ds.depth_write_enabled = enabled;
return self;
}
/// Configure stencil state (front/back ops and masks). Requires depth-stencil enabled.
pub fn with_stencil(mut self, stencil: StencilState) -> Self {
let ds = self.depth_stencil.get_or_insert(wgpu::DepthStencilState {
format: wgpu::TextureFormat::Depth24PlusStencil8,
depth_write_enabled: true,
depth_compare: wgpu::CompareFunction::Less,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
});
ds.stencil = wgpu::StencilState {
front: stencil.front.to_wgpu(),
back: stencil.back.to_wgpu(),
read_mask: stencil.read_mask,
write_mask: stencil.write_mask,
};
return self;
}
/// Configure multisampling. Count MUST be >= 1 and supported by the device.
pub fn with_sample_count(mut self, count: u32) -> Self {
self.sample_count = count.max(1);
return self;
}
/// Build the render pipeline from provided shader modules.
pub fn build(
self,
gpu: &Gpu,
vertex_shader: &ShaderModule,
fragment_shader: Option<&ShaderModule>,
) -> RenderPipeline {
// Convert vertex attributes into raw `wgpu` descriptors while keeping
// storage stable for layout lifetimes.
let mut attr_storage: Vec<Box<[wgpu::VertexAttribute]>> = Vec::new();
let mut strides: Vec<u64> = Vec::new();
let mut step_modes: Vec<VertexStepMode> = Vec::new();
for buffer_desc in &self.vertex_buffers {
let mut raw_attrs: Vec<wgpu::VertexAttribute> =
Vec::with_capacity(buffer_desc.attributes.len());
for attribute in buffer_desc.attributes.iter() {
raw_attrs.push(wgpu::VertexAttribute {
shader_location: attribute.shader_location,
offset: attribute.offset,
format: attribute.format.to_vertex_format(),
});
}
let boxed: Box<[wgpu::VertexAttribute]> = raw_attrs.into_boxed_slice();
attr_storage.push(boxed);
strides.push(buffer_desc.array_stride);
step_modes.push(buffer_desc.step_mode);
}
// Now build layouts referencing the stable storage in `attr_storage`.
let mut vbl: Vec<wgpu::VertexBufferLayout<'_>> = Vec::new();
for (i, boxed) in attr_storage.iter().enumerate() {
let slice = boxed.as_ref();
vbl.push(wgpu::VertexBufferLayout {
array_stride: strides[i],
step_mode: step_modes[i].to_wgpu(),
attributes: slice,
});
}
let color_targets: Vec<Option<wgpu::ColorTargetState>> =
match &self.color_target_format {
Some(fmt) => vec![Some(wgpu::ColorTargetState {
format: *fmt,
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
write_mask: wgpu::ColorWrites::ALL,
})],
None => Vec::new(),
};
let fragment = fragment_shader.map(|fs| wgpu::FragmentState {
module: fs.raw(),
entry_point: Some("main"),
compilation_options: wgpu::PipelineCompilationOptions::default(),
targets: color_targets.as_slice(),
});
let vertex_state = wgpu::VertexState {
module: vertex_shader.raw(),
entry_point: Some("main"),
compilation_options: wgpu::PipelineCompilationOptions::default(),
buffers: vbl.as_slice(),
};
let primitive_state = wgpu::PrimitiveState {
cull_mode: self.cull_mode.to_wgpu(),
..wgpu::PrimitiveState::default()
};
let layout_ref = self.layout;
let raw =
gpu
.device()
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: self.label.as_deref(),
layout: layout_ref,
vertex: vertex_state,
primitive: primitive_state,
depth_stencil: self.depth_stencil,
multisample: wgpu::MultisampleState {
count: self.sample_count,
..wgpu::MultisampleState::default()
},
fragment,
multiview_mask: None,
cache: None,
});
return RenderPipeline {
raw,
label: self.label,
};
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn vertex_step_mode_maps_to_wgpu() {
let vertex_mode = VertexStepMode::Vertex.to_wgpu();
let instance_mode = VertexStepMode::Instance.to_wgpu();
assert_eq!(vertex_mode, wgpu::VertexStepMode::Vertex);
assert_eq!(instance_mode, wgpu::VertexStepMode::Instance);
}
#[test]
fn with_vertex_buffer_defaults_to_per_vertex_step_mode() {
let builder = RenderPipelineBuilder::new().with_vertex_buffer(
16,
vec![VertexAttributeDesc {
shader_location: 0,
offset: 0,
format: ColorFormat::Rgb32Sfloat,
}],
);
let vertex_buffers = &builder.vertex_buffers;
assert_eq!(vertex_buffers.len(), 1);
assert!(matches!(
vertex_buffers[0].step_mode,
VertexStepMode::Vertex
));
}
}