mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Added GLSL to ShaderSource behind Feature lock (#2055)
* Added GLSL to ShaderSource behind Feature lock * Used full path for Naga's FastHashMap and ShaderStage rather than add them as a pub include * changed spirv and glsl web feature to web-shader-translation. Now requires glsl or spirv to be choosen along with the web-shader-translation to unlock their usage * Changed the Description of the Glsl enum * Added README update * Made With with * added catch all that panics if web-shader-translation is not enabled with spirv or glsl * added Compiler condition to prevent the catch all unless glsl or spirv exists without web-shader-translation * We decided to use [target.'cfg(target_arch = wasm32)'.dependencies.naga] within cargo to include wgsl-out in the Web backend unconditionally, which removed the need for a panic * Removed wasm targets section from readme as it is no longer needed * Named Glsl fields to make them more understandable as to what they are for * Fixed the enum usage for GLSL and Added documentation for the fields
This commit is contained in:
parent
5441556988
commit
1759722b69
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -996,6 +996,7 @@ dependencies = [
|
||||
"log",
|
||||
"num-traits 0.2.14",
|
||||
"petgraph",
|
||||
"pp-rs",
|
||||
"serde",
|
||||
"spirv",
|
||||
"thiserror",
|
||||
@ -1271,6 +1272,15 @@ version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb20dcc30536a1508e75d47dd0e399bb2fe7354dcf35cda9127f2bf1ed92e30e"
|
||||
|
||||
[[package]]
|
||||
name = "pp-rs"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb458bb7f6e250e6eb79d5026badc10a3ebb8f9a15d1fff0f13d17c71f4d6dee"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
|
@ -78,7 +78,7 @@ test = true
|
||||
[features]
|
||||
default = []
|
||||
spirv = ["naga/spv-in"]
|
||||
spirv-web = ["spirv", "naga/wgsl-out"]
|
||||
glsl = ["naga/glsl-in"]
|
||||
trace = ["serde", "wgc/trace"]
|
||||
replay = ["serde", "wgc/replay"]
|
||||
webgl = ["wgc"]
|
||||
@ -146,6 +146,10 @@ optional = true
|
||||
version = "0.7"
|
||||
features = ["wgsl-in"]
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies.naga]
|
||||
version = "0.7"
|
||||
features = ["wgsl-out"]
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
wasm-bindgen = "0.2.76" # remember to change version in wiki as well
|
||||
web-sys = { version = "0.3.53", features = [
|
||||
|
@ -56,4 +56,4 @@ Users can run the [naga](https://github.com/gfx-rs/naga) binary in the following
|
||||
cargo run -- <input.spv> <output.wgsl>
|
||||
```
|
||||
|
||||
In addition, SPIR-V can be used by enabling the `spirv` feature, or the `spirv-web` feature for wasm targets, at the cost of slightly increased build times.
|
||||
In addition, SPIR-V can be used by enabling the `spirv` feature and GLSL can be enabled by enabling the `glsl` feature at the cost of slightly increased build times.
|
||||
|
@ -1011,6 +1011,22 @@ impl crate::Context for Context {
|
||||
let module = parser.parse().unwrap();
|
||||
wgc::pipeline::ShaderModuleSource::Naga(module)
|
||||
}
|
||||
#[cfg(feature = "glsl")]
|
||||
ShaderSource::Glsl {
|
||||
ref shader,
|
||||
stage,
|
||||
ref defines,
|
||||
} => {
|
||||
// Parse the given shader code and store its representation.
|
||||
let options = naga::front::glsl::Options {
|
||||
stage,
|
||||
defines: defines.clone(),
|
||||
};
|
||||
let mut parser = naga::front::glsl::Parser::default();
|
||||
let module = parser.parse(&options, shader).unwrap();
|
||||
|
||||
wgc::pipeline::ShaderModuleSource::Naga(module)
|
||||
}
|
||||
ShaderSource::Wgsl(ref code) => wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)),
|
||||
};
|
||||
let (id, error) = wgc::gfx_select!(
|
||||
|
@ -1193,7 +1193,7 @@ impl crate::Context for Context {
|
||||
_shader_bound_checks: wgt::ShaderBoundChecks,
|
||||
) -> Self::ShaderModuleId {
|
||||
let mut descriptor = match desc.source {
|
||||
#[cfg(feature = "spirv-web")]
|
||||
#[cfg(feature = "spirv")]
|
||||
crate::ShaderSource::SpirV(ref spv) => {
|
||||
use naga::{back, front, valid};
|
||||
|
||||
@ -1214,6 +1214,29 @@ impl crate::Context for Context {
|
||||
let wgsl_text = back::wgsl::write_string(&spv_module, &spv_module_info).unwrap();
|
||||
web_sys::GpuShaderModuleDescriptor::new(wgsl_text.as_str())
|
||||
}
|
||||
#[cfg(feature = "glsl")]
|
||||
ShaderSource::Glsl {
|
||||
ref shader,
|
||||
stage,
|
||||
ref defines,
|
||||
} => {
|
||||
// Parse the given shader code and store its representation.
|
||||
let options = naga::front::glsl::Options {
|
||||
stage,
|
||||
defines: defines.clone(),
|
||||
};
|
||||
let mut parser = naga::front::glsl::Parser::default();
|
||||
let glsl_module = parser.parse(&options, shader).unwrap();
|
||||
|
||||
let mut validator = valid::Validator::new(
|
||||
valid::ValidationFlags::all(),
|
||||
valid::Capabilities::all(),
|
||||
);
|
||||
let glsl_module_info = validator.validate(&glsl_module).unwrap();
|
||||
|
||||
let wgsl_text = back::wgsl::write_string(&glsl_module, &glsl_module_info).unwrap();
|
||||
web_sys::GpuShaderModuleDescriptor::new(wgsl_text.as_str())
|
||||
}
|
||||
crate::ShaderSource::Wgsl(ref code) => web_sys::GpuShaderModuleDescriptor::new(code),
|
||||
};
|
||||
if let Some(label) = desc.label {
|
||||
|
@ -747,6 +747,21 @@ pub enum ShaderSource<'a> {
|
||||
/// is passed to `gfx-rs` and `spirv_cross` for translation.
|
||||
#[cfg(feature = "spirv")]
|
||||
SpirV(Cow<'a, [u32]>),
|
||||
/// GSLS module as a string slice.
|
||||
///
|
||||
/// wgpu will attempt to parse and validate it. The module will get
|
||||
/// passed to wgpu-core where it will translate it to the required languages.
|
||||
///
|
||||
/// Note: GLSL is not yet fully supported and must be a direct ShaderStage.
|
||||
#[cfg(feature = "glsl")]
|
||||
Glsl {
|
||||
/// The shaders code
|
||||
shader: Cow<'a, str>,
|
||||
/// Stage in which the GLSL shader is for example: naga::ShaderStage::Vertex
|
||||
stage: naga::ShaderStage,
|
||||
/// Defines to unlock configured shader features
|
||||
defines: naga::FastHashMap<String, String>,
|
||||
},
|
||||
/// WGSL module as a string slice.
|
||||
///
|
||||
/// wgpu-rs will parse it and use for validation. It will attempt
|
||||
|
Loading…
Reference in New Issue
Block a user