mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 00:11:11 +01:00
Add Instance::wgsl_language_features (#6814)
* docs(naga): clarify desc. for `LanguageExtension`
* feat(naga): expose `{,Implemented,Unimplemented}LanguageExtension`
* feat(naga): expose `ImplementedLanguageExtension` as `WgslLanguageExtension`
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-Authored-By: Erich Gubler <erichdongubler@gmail.com>
* feat: add `Instance::wgsl_language_features`
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-Authored-By: Erich Gubler <erichdongubler@gmail.com>
* refactor: reimpl. `ImplementedLanguageExtension::all` w/ `strum::VariantArray`
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: Erich Gubler <erichdongubler@gmail.com>
This commit is contained in:
1 parent
98f1c728ed
commit
dc9b2eb718
10 files changed
+102
-7
No files matched your search
@@ -162,6 +162,7 @@ By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849).
|
||||
- Move raytracing alignments into HAL instead of in core. By @Vecvec in [#6563](https://github.com/gfx-rs/wgpu/pull/6563).
|
||||
- Allow for statically linking DXC rather than including separate `.dll` files. By @DouglasDwyer in [#6574](https://github.com/gfx-rs/wgpu/pull/6574).
|
||||
- `DeviceType` and `AdapterInfo` now impl `Hash` by @cwfitzgerald in [#6868](https://github.com/gfx-rs/wgpu/pull/6868)
|
||||
- Add `wgsl_language_features` for obtaining available WGSL language feature by @sagudev in [#6814](https://github.com/gfx-rs/wgpu/pull/6814)
|
||||
|
||||
##### Vulkan
|
||||
|
||||
|
||||
Generated
+1
@@ -3980,6 +3980,7 @@ name = "wgpu"
|
||||
version = "23.0.1"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags 2.6.0",
|
||||
"cfg_aliases 0.2.1",
|
||||
"document-features",
|
||||
"js-sys",
|
||||
|
||||
+1
-1
@@ -75,6 +75,7 @@ codespan-reporting = { version = "0.11.0" }
|
||||
rustc-hash.workspace = true
|
||||
indexmap.workspace = true
|
||||
log = "0.4"
|
||||
strum.workspace = true
|
||||
spirv = { version = "0.3", optional = true }
|
||||
thiserror.workspace = true
|
||||
serde = { version = "1.0.217", features = ["derive"], optional = true }
|
||||
@@ -102,4 +103,3 @@ ron = "0.8.0"
|
||||
rspirv = { version = "0.11", git = "https://github.com/gfx-rs/rspirv", rev = "b969f175d5663258b4891e44b76c1544da9661ab" }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
spirv = { version = "0.3", features = ["deserialize"] }
|
||||
strum.workspace = true
|
||||
@@ -20,6 +20,10 @@ pub use crate::front::wgsl::error::ParseError;
|
||||
use crate::front::wgsl::lower::Lowerer;
|
||||
use crate::Scalar;
|
||||
|
||||
pub use crate::front::wgsl::parse::directive::language_extension::{
|
||||
ImplementedLanguageExtension, LanguageExtension, UnimplementedLanguageExtension,
|
||||
};
|
||||
|
||||
pub struct Frontend {
|
||||
parser: Parser,
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
//!
|
||||
//! The focal point of this module is the [`LanguageExtension`] API.
|
||||
|
||||
/// A language extension not guaranteed to be present in all environments.
|
||||
use strum::VariantArray;
|
||||
|
||||
/// A language extension recognized by Naga, but not guaranteed to be present in all environments.
|
||||
///
|
||||
/// WGSL spec.: <https://www.w3.org/TR/WGSL/#language-extensions-sec>
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub(crate) enum LanguageExtension {
|
||||
pub enum LanguageExtension {
|
||||
#[allow(unused)]
|
||||
Implemented(ImplementedLanguageExtension),
|
||||
Unimplemented(UnimplementedLanguageExtension),
|
||||
@@ -41,7 +43,7 @@ impl LanguageExtension {
|
||||
/// Maps this [`LanguageExtension`] into the sentinel word associated with it in WGSL.
|
||||
pub const fn to_ident(self) -> &'static str {
|
||||
match self {
|
||||
Self::Implemented(kind) => match kind {},
|
||||
Self::Implemented(kind) => kind.to_ident(),
|
||||
Self::Unimplemented(kind) => match kind {
|
||||
UnimplementedLanguageExtension::ReadOnlyAndReadWriteStorageTextures => {
|
||||
Self::READONLY_AND_READWRITE_STORAGE_TEXTURES
|
||||
@@ -61,12 +63,24 @@ impl LanguageExtension {
|
||||
}
|
||||
|
||||
/// A variant of [`LanguageExtension::Implemented`].
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub(crate) enum ImplementedLanguageExtension {}
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, VariantArray)]
|
||||
pub enum ImplementedLanguageExtension {}
|
||||
|
||||
impl ImplementedLanguageExtension {
|
||||
/// Returns slice of all variants of [`ImplementedLanguageExtension`].
|
||||
pub const fn all() -> &'static [Self] {
|
||||
Self::VARIANTS
|
||||
}
|
||||
|
||||
/// Maps this [`ImplementedLanguageExtension`] into the sentinel word associated with it in WGSL.
|
||||
pub const fn to_ident(self) -> &'static str {
|
||||
match self {}
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of [`LanguageExtension::Unimplemented`].
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub(crate) enum UnimplementedLanguageExtension {
|
||||
pub enum UnimplementedLanguageExtension {
|
||||
ReadOnlyAndReadWriteStorageTextures,
|
||||
Packed4x8IntegerDotProduct,
|
||||
UnrestrictedPointerParameters,
|
||||
|
||||
@@ -187,6 +187,7 @@ optional = true
|
||||
|
||||
[dependencies]
|
||||
arrayvec.workspace = true
|
||||
bitflags.workspace = true
|
||||
document-features.workspace = true
|
||||
log.workspace = true
|
||||
parking_lot.workspace = true
|
||||
|
||||
@@ -4,6 +4,23 @@ use crate::{dispatch::InstanceInterface, *};
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
bitflags::bitflags! {
|
||||
/// WGSL language extensions.
|
||||
///
|
||||
/// WGSL spec.: <https://www.w3.org/TR/WGSL/#language-extensions-sec>
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq, Hash)]
|
||||
pub struct WgslLanguageFeatures: u32 {
|
||||
/// <https://www.w3.org/TR/WGSL/#language_extension-readonly_and_readwrite_storage_textures>
|
||||
const ReadOnlyAndReadWriteStorageTextures = 1 << 0;
|
||||
/// <https://www.w3.org/TR/WGSL/#language_extension-packed_4x8_integer_dot_product>
|
||||
const Packed4x8IntegerDotProduct = 1 << 1;
|
||||
/// <https://www.w3.org/TR/WGSL/#language_extension-unrestricted_pointer_parameters>
|
||||
const UnrestrictedPointerParameters = 1 << 2;
|
||||
/// <https://www.w3.org/TR/WGSL/#language_extension-pointer_composite_access>
|
||||
const PointerCompositeAccess = 1 << 3;
|
||||
}
|
||||
}
|
||||
|
||||
/// Context for all other wgpu objects. Instance of wgpu.
|
||||
///
|
||||
/// This is the first thing you create when using wgpu.
|
||||
@@ -385,4 +402,12 @@ impl Instance {
|
||||
pub fn generate_report(&self) -> Option<wgc::global::GlobalReport> {
|
||||
self.inner.as_core_opt().map(|ctx| ctx.generate_report())
|
||||
}
|
||||
|
||||
/// Returns set of supported WGSL language extensions supported by this instance.
|
||||
///
|
||||
/// <https://www.w3.org/TR/webgpu/#gpuwgsllanguagefeatures>
|
||||
#[cfg(feature = "wgsl")]
|
||||
pub fn wgsl_language_features(&self) -> WgslLanguageFeatures {
|
||||
self.inner.wgsl_language_features()
|
||||
}
|
||||
}
|
||||
@@ -1563,6 +1563,40 @@ impl dispatch::InstanceInterface for ContextWebGpu {
|
||||
// Devices are automatically polled.
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgsl")]
|
||||
fn wgsl_language_features(&self) -> crate::WgslLanguageFeatures {
|
||||
let mut wgsl_language_features = crate::WgslLanguageFeatures::empty();
|
||||
if let Some(gpu) = &self.gpu {
|
||||
gpu.wgsl_language_features()
|
||||
.keys()
|
||||
.into_iter()
|
||||
.map(|wlf| wlf.expect("`WgslLanguageFeatures` elements should be valid"))
|
||||
.map(|wlf| {
|
||||
wlf.as_string()
|
||||
.expect("`WgslLanguageFeatures` should be string set")
|
||||
})
|
||||
.filter_map(|wlf| match wlf.as_str() {
|
||||
"readonly_and_readwrite_storage_textures" => {
|
||||
Some(crate::WgslLanguageFeatures::ReadOnlyAndReadWriteStorageTextures)
|
||||
}
|
||||
"packed_4x8_integer_dot_product" => {
|
||||
Some(crate::WgslLanguageFeatures::Packed4x8IntegerDotProduct)
|
||||
}
|
||||
"unrestricted_pointer_parameters" => {
|
||||
Some(crate::WgslLanguageFeatures::UnrestrictedPointerParameters)
|
||||
}
|
||||
"pointer_composite_access" => {
|
||||
Some(crate::WgslLanguageFeatures::PointerCompositeAccess)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.for_each(|wlf| {
|
||||
wgsl_language_features |= wlf;
|
||||
})
|
||||
}
|
||||
wgsl_language_features
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ContextWebGpu {
|
||||
|
||||
@@ -851,6 +851,18 @@ impl dispatch::InstanceInterface for ContextWgpuCore {
|
||||
Err(err) => self.handle_error_fatal(err, "Instance::poll_all_devices"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgsl")]
|
||||
fn wgsl_language_features(&self) -> crate::WgslLanguageFeatures {
|
||||
wgc::naga::front::wgsl::ImplementedLanguageExtension::all()
|
||||
.iter()
|
||||
.copied()
|
||||
.fold(
|
||||
crate::WgslLanguageFeatures::empty(),
|
||||
#[allow(unreachable_code)]
|
||||
|acc, wle| acc | match wle {},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl dispatch::AdapterInterface for CoreAdapter {
|
||||
|
||||
@@ -100,6 +100,9 @@ pub trait InstanceInterface: CommonTraits {
|
||||
) -> Pin<Box<dyn RequestAdapterFuture>>;
|
||||
|
||||
fn poll_all_devices(&self, force_wait: bool) -> bool;
|
||||
|
||||
#[cfg(feature = "wgsl")]
|
||||
fn wgsl_language_features(&self) -> crate::WgslLanguageFeatures;
|
||||
}
|
||||
|
||||
pub trait AdapterInterface: CommonTraits {
|
||||
|
||||
Reference in new issue
Block a user