Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "naga_oil"
version = "0.20.0"
version = "0.21.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "a crate for combining and manipulating shaders using naga IR"
Expand All @@ -16,9 +16,11 @@ glsl = ["naga/glsl-in", "naga/glsl-out"]
override_any = []
prune = []
allow_deprecated = []
# forces composable modules to include "enable wgpu_ray_query"
override_enable_ray_query = []

[dependencies]
naga = { version = "27", features = ["wgsl-in", "wgsl-out", "termcolor"] }
naga = { version = "28", features = ["wgsl-in", "wgsl-out", "termcolor"] }
tracing = "0.1"
regex = "1.8"
thiserror = "2.0"
Expand All @@ -29,6 +31,6 @@ unicode-ident = "1"
indexmap = "2"

[dev-dependencies]
wgpu = { version = "27", features = ["naga-ir"] }
wgpu = { version = "28", features = ["naga-ir"] }
futures-lite = "2"
tracing-subscriber = { version = "0.3", features = ["std", "fmt"] }
20 changes: 10 additions & 10 deletions examples/pbr_compose_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ fn test_compose_final_module(n: usize, composer: &mut Composer) {
// make shader module from string
fn test_wgsl_string_compile(n: usize) {
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());
let adapter = instance
.enumerate_adapters(wgpu::Backends::all())
.into_iter()
.next()
.unwrap();
let adapter =
futures_lite::future::block_on(instance.enumerate_adapters(wgpu::Backends::all()))
.into_iter()
.next()
.unwrap();
let device =
futures_lite::future::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default()))
.unwrap()
Expand All @@ -163,11 +163,11 @@ fn test_wgsl_string_compile(n: usize) {
// make shader module from composed naga
fn test_composer_compile(n: usize, composer: &mut Composer) {
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());
let adapter = instance
.enumerate_adapters(wgpu::Backends::all())
.into_iter()
.next()
.unwrap();
let adapter =
futures_lite::future::block_on(instance.enumerate_adapters(wgpu::Backends::all()))
.into_iter()
.next()
.unwrap();
let device =
futures_lite::future::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default()))
.unwrap()
Expand Down
16 changes: 15 additions & 1 deletion src/compose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ impl Composer {
early_depth_test: None,
workgroup_size: [0, 0, 0],
workgroup_size_overrides: None,
mesh_info: None,
task_payload: None,
};

naga_module.entry_points.push(ep);
Expand Down Expand Up @@ -1387,7 +1389,17 @@ impl Composer {
true,
&preprocessed_source,
imports,
None,
if cfg!(feature = "override_enable_ray_query") {
Some(WgslDirectives {
enables: vec![EnableDirective {
extensions: vec!["wgpu_ray_query".to_string()],
source_location: 0,
}],
..Default::default()
})
} else {
None
},
)
.map_err(|err| err.into())
}
Expand Down Expand Up @@ -1834,6 +1846,8 @@ impl Composer {
early_depth_test: ep.early_depth_test,
workgroup_size: ep.workgroup_size,
workgroup_size_overrides: ep.workgroup_size_overrides,
mesh_info: ep.mesh_info.clone(),
task_payload: ep.task_payload,
});
}
let mut naga_module = naga::Module {
Expand Down
13 changes: 7 additions & 6 deletions src/compose/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ mod test {
output_eq!(wgsl, "tests/expected/atomics.txt");
}

#[cfg(feature = "override_enable_ray_query")]
#[test]
fn test_raycasts() {
let mut composer =
Expand Down Expand Up @@ -1489,11 +1490,11 @@ mod test {
.unwrap();

let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());
let adapter = instance
.enumerate_adapters(wgpu::Backends::all())
.into_iter()
.next()
.unwrap();
let adapter =
futures_lite::future::block_on(instance.enumerate_adapters(wgpu::Backends::all()))
.into_iter()
.next()
.unwrap();
let (device, queue) =
futures_lite::future::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
required_features: Features::MAPPABLE_PRIMARY_BUFFERS,
Expand Down Expand Up @@ -1533,7 +1534,7 @@ mod test {
&device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: &[&layout],
push_constant_ranges: &[],
immediate_size: 0,
}),
),
module: &shader_module,
Expand Down
2 changes: 2 additions & 0 deletions src/compose/tests/raycast/top.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable wgpu_ray_query;

#import test_module

fn main() -> f32 {
Expand Down
2 changes: 2 additions & 0 deletions src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,8 @@ impl<'a> DerivedModule<'a> {
workgroup_size: ep.workgroup_size,
function: self.localize_function(&ep.function),
workgroup_size_overrides: ep.workgroup_size_overrides,
mesh_info: ep.mesh_info.clone(),
task_payload: ep.task_payload,
})
.collect();

Expand Down
32 changes: 30 additions & 2 deletions src/prune/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl FunctionReq {
expressions,
named_expressions,
body,
diagnostic_filter_leaf: func.diagnostic_filter_leaf,
}
}

Expand Down Expand Up @@ -149,6 +150,7 @@ impl FunctionReq {
offset,
level,
depth_ref,
clamp_to_edge,
} => Expression::ImageSample {
image: expr_map[image],
sampler: expr_map[sampler],
Expand All @@ -166,6 +168,7 @@ impl FunctionReq {
},
},
depth_ref: depth_ref.map(|e| expr_map[&e]),
clamp_to_edge: *clamp_to_edge,
},
Expression::ImageLoad {
image,
Expand Down Expand Up @@ -251,6 +254,7 @@ impl FunctionReq {
Expression::Override(_) => expr.clone(),
Expression::SubgroupBallotResult => expr.clone(),
Expression::SubgroupOperationResult { .. } => expr.clone(),
Expression::RayQueryVertexPositions { query, committed } => todo!(),
}
}

Expand Down Expand Up @@ -402,7 +406,18 @@ impl FunctionReq {
}
}
(Statement::Kill, _) => Some(Statement::Kill),
(Statement::Barrier(b), _) => Some(Statement::Barrier(*b)),
(Statement::ControlBarrier(b), _) => Some(Statement::ControlBarrier(*b)),
(Statement::MemoryBarrier(b), _) => Some(Statement::MemoryBarrier(*b)),
(
Statement::ImageAtomic {
image,
coordinate,
array_index,
fun,
value,
},
_,
) => todo!(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why todo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The tests for this module do not pass and have not passed since at least 0.14
  • It is undocumented according to the README
  • It is behind a non-default feature flag

As far as I'm aware, "todo" is the state of the module itself, not just these snippets.

(Statement::Store { pointer, value }, StatementReq::Store(b)) => {
if !b {
return None;
Expand Down Expand Up @@ -1271,6 +1286,7 @@ impl<'a> Pruner<'a> {
offset: _offset,
level,
depth_ref,
clamp_to_edge,
} => {
self.add_expression(function, func_req, context, *image, &PartReq::All);
self.add_expression(function, func_req, context, *sampler, &PartReq::All);
Expand Down Expand Up @@ -1384,6 +1400,7 @@ impl<'a> Pruner<'a> {
Expression::SubgroupOperationResult { .. } => {
// nothing, handled by the statement
}
Expression::RayQueryVertexPositions { query, committed } => todo!(),
}

func_req.exprs_required.insert(h_expr, part.clone());
Expand Down Expand Up @@ -1532,7 +1549,15 @@ impl<'a> Pruner<'a> {
Return(break_required)
}
Statement::Kill => Kill(),
Statement::Barrier(_) => Barrier(),
Statement::ControlBarrier(barrier) => Barrier(),
Statement::MemoryBarrier(barrier) => Barrier(),
Statement::ImageAtomic {
image,
coordinate,
array_index,
fun,
value,
} => todo!(),
Statement::Store { pointer, value } => {
let var_ref = Self::resolve_var(function, *pointer, Vec::default());
let required = self.store_required(context, &var_ref);
Expand Down Expand Up @@ -1892,6 +1917,9 @@ impl<'a> Pruner<'a> {
early_depth_test: ep.early_depth_test,
workgroup_size: ep.workgroup_size,
function: mapped_f,
mesh_info: None,
task_payload: None,
workgroup_size_overrides: None,
};
entry_points.push(new_ep);
}
Expand Down