Skip to content

Commit e349f54

Browse files
naga 28 update (#132)
This is a working naga 28 update. I noticed some tests haven't passed (specifically cargo test --all-features) since before 0.14, so this PR doesn't attempt to make them pass. ## enumerate_adaptors `instance.enumerate_adapters` is async now (and available on webgpu): gfx-rs/wgpu#8230 . more details in the wgpu release notes. ## ControlBarrier & MemoryBarrier Barrier was split in two to support MemoryBarriers: gfx-rs/wgpu#7630 From the PR, it seems like falling back to ControlBarrier is fine so that's what I did. ## Ray Query enable ray queries require `enable wgpu_ray_query;`: gfx-rs/wgpu#8545 This doesn't currently seem to make it through, and the relevant test fails. ## ImageAtomic Image atomics were added in gfx-rs/wgpu#6706 ## Mesh Shaders Mesh shaders are a major feature of wgpu 28, ~~but I've set their fields to None here in the interest of doing an upgrade and not a feature add at the same time~~ https://github.com/gfx-rs/wgpu/releases/tag/v28.0.0 update: I found some time and built a wgpu mesh/task shader demo and used that to validate some of the mesh shader functionality. I've used this to successfully compile a task shader with naga-oil and run it, but there's still something missing from the mesh shader module output here. --------- Co-authored-by: robtfm <50659922+robtfm@users.noreply.github.com>
1 parent 064e92b commit e349f54

8 files changed

Lines changed: 67 additions & 32 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "naga_oil"
3-
version = "0.20.0"
3+
version = "0.21.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "a crate for combining and manipulating shaders using naga IR"
@@ -18,7 +18,7 @@ prune = []
1818
allow_deprecated = []
1919

2020
[dependencies]
21-
naga = { version = "27", features = ["wgsl-in", "wgsl-out", "termcolor"] }
21+
naga = { version = "28", features = ["wgsl-in", "wgsl-out", "termcolor"] }
2222
tracing = "0.1"
2323
regex = "1.8"
2424
thiserror = "2.0"
@@ -29,6 +29,6 @@ unicode-ident = "1"
2929
indexmap = "2"
3030

3131
[dev-dependencies]
32-
wgpu = { version = "27", features = ["naga-ir"] }
32+
wgpu = { version = "28", features = ["naga-ir"] }
3333
futures-lite = "2"
3434
tracing-subscriber = { version = "0.3", features = ["std", "fmt"] }

examples/pbr_compose_test.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ fn test_compose_final_module(n: usize, composer: &mut Composer) {
140140
// make shader module from string
141141
fn test_wgsl_string_compile(n: usize) {
142142
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());
143-
let adapter = instance
144-
.enumerate_adapters(wgpu::Backends::all())
145-
.into_iter()
146-
.next()
147-
.unwrap();
143+
let adapter =
144+
futures_lite::future::block_on(instance.enumerate_adapters(wgpu::Backends::all()))
145+
.into_iter()
146+
.next()
147+
.unwrap();
148148
let device =
149149
futures_lite::future::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default()))
150150
.unwrap()
@@ -163,11 +163,11 @@ fn test_wgsl_string_compile(n: usize) {
163163
// make shader module from composed naga
164164
fn test_composer_compile(n: usize, composer: &mut Composer) {
165165
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());
166-
let adapter = instance
167-
.enumerate_adapters(wgpu::Backends::all())
168-
.into_iter()
169-
.next()
170-
.unwrap();
166+
let adapter =
167+
futures_lite::future::block_on(instance.enumerate_adapters(wgpu::Backends::all()))
168+
.into_iter()
169+
.next()
170+
.unwrap();
171171
let device =
172172
futures_lite::future::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default()))
173173
.unwrap()

src/compose/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ pub struct ComposableModuleDefinition {
275275
modules: HashMap<ModuleKey, ComposableModule>,
276276
// used in spans when this module is included
277277
module_index: usize,
278+
// any directives used in this module
279+
wgsl_directives: WgslDirectives,
278280
}
279281

280282
impl ComposableModuleDefinition {
@@ -533,6 +535,8 @@ impl Composer {
533535
early_depth_test: None,
534536
workgroup_size: [0, 0, 0],
535537
workgroup_size_overrides: None,
538+
mesh_info: None,
539+
task_payload: None,
536540
};
537541

538542
naga_module.entry_points.push(ep);
@@ -583,17 +587,12 @@ impl Composer {
583587
language: ShaderLanguage,
584588
imports: &[ImportDefinition],
585589
shader_defs: &HashMap<String, ShaderDefValue>,
586-
wgsl_directives: Option<WgslDirectives>,
590+
wgsl_directives: &WgslDirectives,
587591
) -> Result<IrBuildResult, ComposerError> {
588592
debug!("creating IR for {} with defs: {:?}", name, shader_defs);
589593

590-
let mut wgsl_string = String::new();
591-
if let Some(wgsl_directives) = &wgsl_directives {
592-
trace!("adding WGSL directives for {}", name);
593-
wgsl_string = wgsl_directives.to_wgsl_string();
594-
}
595594
let mut module_string = match language {
596-
ShaderLanguage::Wgsl => wgsl_string,
595+
ShaderLanguage::Wgsl => wgsl_directives.to_wgsl_string(),
597596
#[cfg(feature = "glsl")]
598597
ShaderLanguage::Glsl => String::from("#version 450\n"),
599598
};
@@ -851,7 +850,6 @@ impl Composer {
851850
demote_entrypoints: bool,
852851
source: &str,
853852
imports: Vec<ImportDefWithOffset>,
854-
wgsl_directives: Option<WgslDirectives>,
855853
) -> Result<ComposableModule, ComposerError> {
856854
let mut imports: Vec<_> = imports
857855
.into_iter()
@@ -985,7 +983,7 @@ impl Composer {
985983
module_definition.language,
986984
&imports,
987985
shader_defs,
988-
wgsl_directives,
986+
&module_definition.wgsl_directives,
989987
)?;
990988

991989
// from here on errors need to be reported using the modified source with start_offset
@@ -1387,7 +1385,6 @@ impl Composer {
13871385
true,
13881386
&preprocessed_source,
13891387
imports,
1390-
None,
13911388
)
13921389
.map_err(|err| err.into())
13931390
}
@@ -1532,6 +1529,7 @@ impl Composer {
15321529
mut imports,
15331530
mut effective_defs,
15341531
cleaned_source,
1532+
wgsl_directives,
15351533
..
15361534
} = self
15371535
.preprocessor
@@ -1617,6 +1615,7 @@ impl Composer {
16171615
shader_defs,
16181616
module_index,
16191617
modules: Default::default(),
1618+
wgsl_directives,
16201619
};
16211620

16221621
// invalidate dependent modules if this module already exists
@@ -1763,6 +1762,7 @@ impl Composer {
17631762
all_imports: Default::default(),
17641763
shader_defs: Default::default(),
17651764
modules: Default::default(),
1765+
wgsl_directives,
17661766
};
17671767

17681768
let PreprocessOutput {
@@ -1789,7 +1789,6 @@ impl Composer {
17891789
false,
17901790
&preprocessed_source,
17911791
imports,
1792-
Some(wgsl_directives),
17931792
)
17941793
.map_err(|e| ComposerError {
17951794
inner: e.inner,
@@ -1834,6 +1833,8 @@ impl Composer {
18341833
early_depth_test: ep.early_depth_test,
18351834
workgroup_size: ep.workgroup_size,
18361835
workgroup_size_overrides: ep.workgroup_size_overrides,
1836+
mesh_info: ep.mesh_info.clone(),
1837+
task_payload: ep.task_payload,
18371838
});
18381839
}
18391840
let mut naga_module = naga::Module {

src/compose/test.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,11 +1489,11 @@ mod test {
14891489
.unwrap();
14901490

14911491
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());
1492-
let adapter = instance
1493-
.enumerate_adapters(wgpu::Backends::all())
1494-
.into_iter()
1495-
.next()
1496-
.unwrap();
1492+
let adapter =
1493+
futures_lite::future::block_on(instance.enumerate_adapters(wgpu::Backends::all()))
1494+
.into_iter()
1495+
.next()
1496+
.unwrap();
14971497
let (device, queue) =
14981498
futures_lite::future::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
14991499
required_features: Features::MAPPABLE_PRIMARY_BUFFERS,
@@ -1533,7 +1533,7 @@ mod test {
15331533
&device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
15341534
label: None,
15351535
bind_group_layouts: &[&layout],
1536-
push_constant_ranges: &[],
1536+
immediate_size: 0,
15371537
}),
15381538
),
15391539
module: &shader_module,

src/compose/tests/raycast/mod.wgsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
enable wgpu_ray_query;
2+
13
#define_import_path test_module
24

35
@group(0) @binding(0) var tlas: acceleration_structure;

src/compose/tests/raycast/top.wgsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
enable wgpu_ray_query;
2+
13
#import test_module
24

35
fn main() -> f32 {

src/derive.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,8 @@ impl<'a> DerivedModule<'a> {
908908
workgroup_size: ep.workgroup_size,
909909
function: self.localize_function(&ep.function),
910910
workgroup_size_overrides: ep.workgroup_size_overrides,
911+
mesh_info: ep.mesh_info.clone(),
912+
task_payload: ep.task_payload,
911913
})
912914
.collect();
913915

src/prune/mod.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl FunctionReq {
8383
expressions,
8484
named_expressions,
8585
body,
86+
diagnostic_filter_leaf: func.diagnostic_filter_leaf,
8687
}
8788
}
8889

@@ -149,6 +150,7 @@ impl FunctionReq {
149150
offset,
150151
level,
151152
depth_ref,
153+
clamp_to_edge,
152154
} => Expression::ImageSample {
153155
image: expr_map[image],
154156
sampler: expr_map[sampler],
@@ -166,6 +168,7 @@ impl FunctionReq {
166168
},
167169
},
168170
depth_ref: depth_ref.map(|e| expr_map[&e]),
171+
clamp_to_edge: *clamp_to_edge,
169172
},
170173
Expression::ImageLoad {
171174
image,
@@ -251,6 +254,7 @@ impl FunctionReq {
251254
Expression::Override(_) => expr.clone(),
252255
Expression::SubgroupBallotResult => expr.clone(),
253256
Expression::SubgroupOperationResult { .. } => expr.clone(),
257+
Expression::RayQueryVertexPositions { query, committed } => todo!(),
254258
}
255259
}
256260

@@ -402,7 +406,18 @@ impl FunctionReq {
402406
}
403407
}
404408
(Statement::Kill, _) => Some(Statement::Kill),
405-
(Statement::Barrier(b), _) => Some(Statement::Barrier(*b)),
409+
(Statement::ControlBarrier(b), _) => Some(Statement::ControlBarrier(*b)),
410+
(Statement::MemoryBarrier(b), _) => Some(Statement::MemoryBarrier(*b)),
411+
(
412+
Statement::ImageAtomic {
413+
image,
414+
coordinate,
415+
array_index,
416+
fun,
417+
value,
418+
},
419+
_,
420+
) => todo!(),
406421
(Statement::Store { pointer, value }, StatementReq::Store(b)) => {
407422
if !b {
408423
return None;
@@ -1271,6 +1286,7 @@ impl<'a> Pruner<'a> {
12711286
offset: _offset,
12721287
level,
12731288
depth_ref,
1289+
clamp_to_edge,
12741290
} => {
12751291
self.add_expression(function, func_req, context, *image, &PartReq::All);
12761292
self.add_expression(function, func_req, context, *sampler, &PartReq::All);
@@ -1384,6 +1400,7 @@ impl<'a> Pruner<'a> {
13841400
Expression::SubgroupOperationResult { .. } => {
13851401
// nothing, handled by the statement
13861402
}
1403+
Expression::RayQueryVertexPositions { query, committed } => todo!(),
13871404
}
13881405

13891406
func_req.exprs_required.insert(h_expr, part.clone());
@@ -1532,7 +1549,15 @@ impl<'a> Pruner<'a> {
15321549
Return(break_required)
15331550
}
15341551
Statement::Kill => Kill(),
1535-
Statement::Barrier(_) => Barrier(),
1552+
Statement::ControlBarrier(barrier) => Barrier(),
1553+
Statement::MemoryBarrier(barrier) => Barrier(),
1554+
Statement::ImageAtomic {
1555+
image,
1556+
coordinate,
1557+
array_index,
1558+
fun,
1559+
value,
1560+
} => todo!(),
15361561
Statement::Store { pointer, value } => {
15371562
let var_ref = Self::resolve_var(function, *pointer, Vec::default());
15381563
let required = self.store_required(context, &var_ref);
@@ -1892,6 +1917,9 @@ impl<'a> Pruner<'a> {
18921917
early_depth_test: ep.early_depth_test,
18931918
workgroup_size: ep.workgroup_size,
18941919
function: mapped_f,
1920+
mesh_info: None,
1921+
task_payload: None,
1922+
workgroup_size_overrides: None,
18951923
};
18961924
entry_points.push(new_ep);
18971925
}

0 commit comments

Comments
 (0)