mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Remove SPIRV entirely from wgpu-core
This commit is contained in:
parent
da38b8b077
commit
4c03d286c6
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1053,6 +1053,7 @@ dependencies = [
|
|||||||
"num-traits 0.2.14",
|
"num-traits 0.2.14",
|
||||||
"petgraph",
|
"petgraph",
|
||||||
"rose_tree",
|
"rose_tree",
|
||||||
|
"serde",
|
||||||
"spirv_headers",
|
"spirv_headers",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -29,7 +29,7 @@ features = ["replay"]
|
|||||||
[dependencies.wgc]
|
[dependencies.wgc]
|
||||||
path = "../wgpu-core"
|
path = "../wgpu-core"
|
||||||
package = "wgpu-core"
|
package = "wgpu-core"
|
||||||
features = ["spirv", "replay", "raw-window-handle"]
|
features = ["replay", "raw-window-handle"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = "1"
|
serde = "1"
|
||||||
|
|||||||
@ -239,17 +239,15 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
|
|||||||
self.bind_group_drop::<A>(id);
|
self.bind_group_drop::<A>(id);
|
||||||
}
|
}
|
||||||
Action::CreateShaderModule { id, desc, data } => {
|
Action::CreateShaderModule { id, desc, data } => {
|
||||||
|
log::info!("Creating shader from {}", data);
|
||||||
|
let code = fs::read_to_string(dir.join(&data)).unwrap();
|
||||||
let source = if data.ends_with(".wgsl") {
|
let source = if data.ends_with(".wgsl") {
|
||||||
let code = fs::read_to_string(dir.join(data)).unwrap();
|
|
||||||
wgc::pipeline::ShaderModuleSource::Wgsl(Cow::Owned(code))
|
wgc::pipeline::ShaderModuleSource::Wgsl(Cow::Owned(code))
|
||||||
|
} else if data.ends_with(".ron") {
|
||||||
|
let module = ron::de::from_str(&code).unwrap();
|
||||||
|
wgc::pipeline::ShaderModuleSource::Naga(module)
|
||||||
} else {
|
} else {
|
||||||
let byte_vec = fs::read(dir.join(&data))
|
panic!("Unknown shader {}", data);
|
||||||
.unwrap_or_else(|e| panic!("Unable to open '{}': {:?}", data, e));
|
|
||||||
let spv = byte_vec
|
|
||||||
.chunks(4)
|
|
||||||
.map(|c| u32::from_le_bytes([c[0], c[1], c[2], c[3]]))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
wgc::pipeline::ShaderModuleSource::SpirV(Cow::Owned(spv))
|
|
||||||
};
|
};
|
||||||
let (_, error) = self.device_create_shader_module::<A>(device, &desc, source, id);
|
let (_, error) = self.device_create_shader_module::<A>(device, &desc, source, id);
|
||||||
if let Some(e) = error {
|
if let Some(e) = error {
|
||||||
|
|||||||
@ -13,11 +13,10 @@ license = "MIT OR Apache-2.0"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
spirv = ["naga/spv-in"]
|
|
||||||
# Enable API tracing
|
# Enable API tracing
|
||||||
trace = ["ron", "serde", "wgt/trace", "arrayvec/serde"]
|
trace = ["ron", "serde", "wgt/trace", "arrayvec/serde", "naga/serialize"]
|
||||||
# Enable API replaying
|
# Enable API replaying
|
||||||
replay = ["serde", "wgt/replay", "arrayvec/serde"]
|
replay = ["serde", "wgt/replay", "arrayvec/serde", "naga/deserialize"]
|
||||||
# Enable serializable compute/render passes, and bundle encoders.
|
# Enable serializable compute/render passes, and bundle encoders.
|
||||||
serial-pass = ["serde", "wgt/serde", "arrayvec/serde"]
|
serial-pass = ["serde", "wgt/serde", "arrayvec/serde"]
|
||||||
|
|
||||||
|
|||||||
@ -838,28 +838,6 @@ impl<A: HalApi> Device<A> {
|
|||||||
source: pipeline::ShaderModuleSource<'a>,
|
source: pipeline::ShaderModuleSource<'a>,
|
||||||
) -> Result<pipeline::ShaderModule<A>, pipeline::CreateShaderModuleError> {
|
) -> Result<pipeline::ShaderModule<A>, pipeline::CreateShaderModuleError> {
|
||||||
let module = match source {
|
let module = match source {
|
||||||
#[cfg(feature = "spirv")]
|
|
||||||
pipeline::ShaderModuleSource::SpirV(spv) => {
|
|
||||||
profiling::scope!("naga::spv::parse");
|
|
||||||
// Parse the given shader code and store its representation.
|
|
||||||
let options = naga::front::spv::Options {
|
|
||||||
adjust_coordinate_space: false, // we require NDC_Y_UP feature
|
|
||||||
strict_capabilities: true,
|
|
||||||
flow_graph_dump_prefix: None,
|
|
||||||
};
|
|
||||||
let parser = naga::front::spv::Parser::new(spv.iter().cloned(), &options);
|
|
||||||
match parser.parse() {
|
|
||||||
Ok(module) => module,
|
|
||||||
Err(err) => {
|
|
||||||
log::warn!(
|
|
||||||
"Failed to parse shader SPIR-V code for {:?}: {:?}",
|
|
||||||
desc.label,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
return Err(pipeline::CreateShaderModuleError::Parsing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pipeline::ShaderModuleSource::Wgsl(code) => {
|
pipeline::ShaderModuleSource::Wgsl(code) => {
|
||||||
profiling::scope!("naga::wgsl::parse_str");
|
profiling::scope!("naga::wgsl::parse_str");
|
||||||
// TODO: refactor the corresponding Naga error to be owned, and then
|
// TODO: refactor the corresponding Naga error to be owned, and then
|
||||||
@ -3477,18 +3455,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
|||||||
if let Some(ref trace) = device.trace {
|
if let Some(ref trace) = device.trace {
|
||||||
let mut trace = trace.lock();
|
let mut trace = trace.lock();
|
||||||
let data = match source {
|
let data = match source {
|
||||||
#[cfg(feature = "spirv")]
|
|
||||||
pipeline::ShaderModuleSource::SpirV(ref spv) => {
|
|
||||||
trace.make_binary("spv", unsafe {
|
|
||||||
std::slice::from_raw_parts(spv.as_ptr() as *const u8, spv.len() * 4)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
pipeline::ShaderModuleSource::Wgsl(ref code) => {
|
pipeline::ShaderModuleSource::Wgsl(ref code) => {
|
||||||
trace.make_binary("wgsl", code.as_bytes())
|
trace.make_binary("wgsl", code.as_bytes())
|
||||||
}
|
}
|
||||||
pipeline::ShaderModuleSource::Naga(_) => {
|
pipeline::ShaderModuleSource::Naga(ref module) => {
|
||||||
// we don't want to enable Naga serialization just for this alone
|
let string =
|
||||||
trace.make_binary("ron", &[])
|
ron::ser::to_string_pretty(module, ron::ser::PrettyConfig::default())
|
||||||
|
.unwrap();
|
||||||
|
trace.make_binary("ron", string.as_bytes())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
trace.add(trace::Action::CreateShaderModule {
|
trace.add(trace::Action::CreateShaderModule {
|
||||||
|
|||||||
@ -9,8 +9,6 @@ use std::borrow::Cow;
|
|||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
pub enum ShaderModuleSource<'a> {
|
pub enum ShaderModuleSource<'a> {
|
||||||
#[cfg(feature = "spirv")]
|
|
||||||
SpirV(Cow<'a, [u32]>),
|
|
||||||
Wgsl(Cow<'a, str>),
|
Wgsl(Cow<'a, str>),
|
||||||
Naga(naga::Module),
|
Naga(naga::Module),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ all-features = true
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
spirv = ["wgc/spirv"]
|
spirv = ["naga/spv-in"]
|
||||||
trace = ["serde", "wgc/trace"]
|
trace = ["serde", "wgc/trace"]
|
||||||
replay = ["serde", "wgc/replay"]
|
replay = ["serde", "wgc/replay"]
|
||||||
webgl = ["wgc"]
|
webgl = ["wgc"]
|
||||||
@ -65,6 +65,11 @@ async-executor = "1.0"
|
|||||||
pollster = "0.2"
|
pollster = "0.2"
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
|
|
||||||
|
[dependencies.naga]
|
||||||
|
git = "https://github.com/gfx-rs/naga"
|
||||||
|
tag = "gfx-26"
|
||||||
|
optional = true
|
||||||
|
|
||||||
# used to test all the example shaders
|
# used to test all the example shaders
|
||||||
[dev-dependencies.naga]
|
[dev-dependencies.naga]
|
||||||
git = "https://github.com/gfx-rs/naga"
|
git = "https://github.com/gfx-rs/naga"
|
||||||
|
|||||||
@ -50,7 +50,6 @@ See [wiki article](https://github.com/gfx-rs/wgpu-rs/wiki/Running-on-the-Web-wit
|
|||||||
Users can run the [naga](https://github.com/gfx-rs/naga) binary in the following way to convert their SPIR-V shaders to WGSL:
|
Users can run the [naga](https://github.com/gfx-rs/naga) binary in the following way to convert their SPIR-V shaders to WGSL:
|
||||||
```bash
|
```bash
|
||||||
cargo run -- <input.spv> <output.wgsl>
|
cargo run -- <input.spv> <output.wgsl>
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
In addition, SPIR-V can be used by enabling the `spirv` feature, and the cost of slightly increased build times.
|
In addition, SPIR-V can be used by enabling the `spirv` feature, and the cost of slightly increased build times.
|
||||||
|
|||||||
@ -811,7 +811,18 @@ impl crate::Context for Context {
|
|||||||
};
|
};
|
||||||
let source = match desc.source {
|
let source = match desc.source {
|
||||||
#[cfg(feature = "spirv")]
|
#[cfg(feature = "spirv")]
|
||||||
ShaderSource::SpirV(ref spv) => wgc::pipeline::ShaderModuleSource::SpirV(Borrowed(spv)),
|
ShaderSource::SpirV(ref spv) => {
|
||||||
|
profiling::scope!("naga::spv::parse");
|
||||||
|
// Parse the given shader code and store its representation.
|
||||||
|
let options = naga::front::spv::Options {
|
||||||
|
adjust_coordinate_space: false, // we require NDC_Y_UP feature
|
||||||
|
strict_capabilities: true,
|
||||||
|
flow_graph_dump_prefix: None,
|
||||||
|
};
|
||||||
|
let parser = naga::front::spv::Parser::new(spv.iter().cloned(), &options);
|
||||||
|
let module = parser.parse().unwrap();
|
||||||
|
wgc::pipeline::ShaderModuleSource::Naga(module)
|
||||||
|
}
|
||||||
ShaderSource::Wgsl(ref code) => wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)),
|
ShaderSource::Wgsl(ref code) => wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)),
|
||||||
};
|
};
|
||||||
let (id, error) = wgc::gfx_select!(
|
let (id, error) = wgc::gfx_select!(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user