mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 05:51:03 +01:00
Gate @interpolate(linear) behind a downlevel flag (#9972)
This commit is contained in:
1 parent
b6db26411c
commit
a6caee7084
16 files changed
+132
-7
No files matched your search
@@ -75,9 +75,13 @@ Bottom level categories:
|
||||
- `TextureFormat::is_srgb()` has been renamed to `TextureFormat::has_srgb_suffix()` to clarify its function. By @kpreid in [#9758](https://github.com/gfx-rs/wgpu/pull/9758).
|
||||
- Remove the never-constructed `CreateBlasError::InvalidAabbStride` variant. `create_blas` takes no stride, so it could never be produced; AABB stride is validated at build time as `BuildAccelerationStructureError::InvalidAabbStride`. By @mstampfli in [#9935](https://github.com/gfx-rs/wgpu/pull/9935).
|
||||
|
||||
- Added `DownlevelFlags::LINEAR_INTERPOLATION`, indicating that the adapter supports `@interpolate(linear)`. It is absent on GLES/WebGL2, since GLSL ES has no `noperspective` qualifier. By @emilk in [#9972](https://github.com/gfx-rs/wgpu/pull/9972).
|
||||
|
||||
#### naga
|
||||
|
||||
- `naga::valid::ValidationError` is now always returned boxed, to avoid `clippy::large_result_err` warning. By @beicause in [#9612](https://github.com/gfx-rs/wgpu/pull/9612)
|
||||
- Added `naga::valid::Capabilities::LINEAR_INTERPOLATION`, which is now required in order to use `@interpolate(linear)`. By @emilk in [#9972](https://github.com/gfx-rs/wgpu/pull/9972).
|
||||
- The GLSL backend's `MissingFeatures` error now names the GLSL version that lacks the features, e.g. `GLSL 300 es doesn't support the required feature(s): NOPERSPECTIVE_QUALIFIER`. By @emilk in [#9972](https://github.com/gfx-rs/wgpu/pull/9972).
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@@ -124,6 +128,7 @@ Bottom level categories:
|
||||
#### GLES
|
||||
|
||||
- Avoid duplicate `EGL_SURFACE_TYPE` attributes when selecting an EGL framebuffer configuration, which caused Mesa to return no matching configurations. By @BlueJayLouche and @scroix in [#10048](https://github.com/gfx-rs/wgpu/pull/10048).
|
||||
- `@interpolate(linear)` is now rejected by `Device::create_shader_module` on adapters that lack `DownlevelFlags::LINEAR_INTERPOLATION` (GLES/WebGL2), with a shader label and a source span. Previously such a shader validated fine and then failed at pipeline creation with `The selected version doesn't support Features(NOPERSPECTIVE_QUALIFIER)`. By @emilk in [#9972](https://github.com/gfx-rs/wgpu/pull/9972).
|
||||
- Fixed signed integer `%` (and `%=`) returning the wrong result for negative operands in the GLSL (OpenGL/GLES) backend, e.g. `-1 % 768` yielding `255` instead of `-1`. GLSL's `%` is undefined when either operand is negative, so signed remainder is now lowered as `a - b * (a / b)`, matching the SPIR-V, HLSL, and Metal backends. By @mstampfli in [#9687](https://github.com/gfx-rs/wgpu/pull/9687).
|
||||
- Fix negative argument for `atomicSub` yielding incorrect GLSL. By @ErichDonGubler in [#9924](https://github.com/gfx-rs/wgpu/pull/9924).
|
||||
|
||||
|
||||
@@ -62,6 +62,13 @@ bitflags::bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Display for Features {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
// `Debug` would print this as `Features(A | B)`; we only want `A | B`.
|
||||
bitflags::parser::to_writer(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper structure used to store the required [`Features`] needed to output a
|
||||
/// [`Module`](crate::Module)
|
||||
///
|
||||
@@ -144,7 +151,7 @@ impl FeaturesManager {
|
||||
if missing.is_empty() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::MissingFeatures(missing))
|
||||
Err(Error::MissingFeatures(missing, version))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -416,9 +416,9 @@ pub enum Error {
|
||||
FmtError(#[from] FmtError),
|
||||
/// The specified [`Version`] doesn't have all required [`Features`].
|
||||
///
|
||||
/// Contains the missing [`Features`].
|
||||
#[error("The selected version doesn't support {0:?}")]
|
||||
MissingFeatures(Features),
|
||||
/// Contains the missing [`Features`], and the version that lacks them.
|
||||
#[error("GLSL {1} doesn't support the required feature(s): {0}")]
|
||||
MissingFeatures(Features, Version),
|
||||
/// [`AddressSpace::Immediate`](crate::AddressSpace::Immediate) was used more than
|
||||
/// once in the entry point, which isn't supported.
|
||||
#[error("Multiple immediates aren't supported")]
|
||||
@@ -506,4 +506,5 @@ pub fn supported_capabilities() -> valid::Capabilities {
|
||||
| Caps::MEMORY_DECORATION_COHERENT
|
||||
| Caps::MEMORY_DECORATION_VOLATILE
|
||||
| Caps::STORAGE_TEXTURE_16BIT_NORM_FORMATS
|
||||
| Caps::LINEAR_INTERPOLATION
|
||||
}
|
||||
@@ -830,4 +830,5 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
|
||||
// No DRAW_INDEX
|
||||
// No MEMORY_DECORATION_VOLATILE
|
||||
| Caps::MEMORY_DECORATION_COHERENT
|
||||
| Caps::LINEAR_INTERPOLATION
|
||||
}
|
||||
@@ -875,6 +875,7 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
|
||||
// No DRAW_INDEX
|
||||
// No MEMORY_DECORATION_VOLATILE
|
||||
| Caps::MEMORY_DECORATION_COHERENT
|
||||
| Caps::LINEAR_INTERPOLATION
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1226,4 +1226,5 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
|
||||
| Caps::DRAW_INDEX
|
||||
| Caps::MEMORY_DECORATION_COHERENT
|
||||
| Caps::MEMORY_DECORATION_VOLATILE
|
||||
| Caps::LINEAR_INTERPOLATION
|
||||
}
|
||||
@@ -785,12 +785,17 @@ impl VaryingContext<'_> {
|
||||
// qualifiers, so we won't complain about that here.
|
||||
let _ = sampling;
|
||||
|
||||
let required = match sampling {
|
||||
let mut required = match sampling {
|
||||
Some(crate::Sampling::Sample) => Capabilities::MULTISAMPLED_SHADING,
|
||||
_ => Capabilities::empty(),
|
||||
};
|
||||
if interpolation == Some(crate::Interpolation::Linear) {
|
||||
required |= Capabilities::LINEAR_INTERPOLATION;
|
||||
}
|
||||
if !self.capabilities.contains(required) {
|
||||
return Err(VaryingError::UnsupportedCapability(required));
|
||||
return Err(VaryingError::UnsupportedCapability(
|
||||
required - self.capabilities,
|
||||
));
|
||||
}
|
||||
|
||||
if interpolation != Some(crate::Interpolation::PerVertex) {
|
||||
|
||||
@@ -218,6 +218,12 @@ bitflags::bitflags! {
|
||||
const MEMORY_DECORATION_VOLATILE = 1 << 42;
|
||||
/// Support for 16-bit integer types.
|
||||
const SHADER_INT16 = 1 << 43;
|
||||
/// Support for [`Interpolation::Linear`] (`@interpolate(linear)` in WGSL).
|
||||
///
|
||||
/// This is core WebGPU, but GLSL ES (and thus WebGL) has no `noperspective` qualifier (unless enabled by extensions).
|
||||
///
|
||||
/// [`Interpolation::Linear`]: crate::Interpolation::Linear
|
||||
const LINEAR_INTERPOLATION = 1 << 44;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
targets = "SPIRV | METAL | HLSL | WGSL"
|
||||
capabilities = "MULTISAMPLED_SHADING | LINEAR_INTERPOLATION"
|
||||
|
||||
[glsl]
|
||||
version.Desktop = 400
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
capabilities = "MULTISAMPLED_SHADING | LINEAR_INTERPOLATION"
|
||||
|
||||
[glsl]
|
||||
version.Desktop = 400
|
||||
writer_flags = ""
|
||||
|
||||
@@ -538,6 +538,52 @@ fn no_flat_first_in_glsl() {
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_linear_interpolation_in_glsl_es() {
|
||||
use dummy_interpolation_shader::DummyInterpolationShader;
|
||||
|
||||
let DummyInterpolationShader {
|
||||
source: _,
|
||||
module,
|
||||
interpolate_attr,
|
||||
entry_point,
|
||||
} = DummyInterpolationShader::new(naga::Interpolation::Linear, None);
|
||||
|
||||
let mut validator = naga::valid::Validator::new(Default::default(), valid::Capabilities::all());
|
||||
let module_info = validator.validate(&module).unwrap();
|
||||
|
||||
let options = naga::back::glsl::Options {
|
||||
version: naga::back::glsl::Version::Embedded {
|
||||
version: 300,
|
||||
is_webgl: true,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let pipeline_options = naga::back::glsl::PipelineOptions {
|
||||
shader_stage: naga::ShaderStage::Fragment,
|
||||
entry_point: entry_point.to_owned(),
|
||||
multiview: None,
|
||||
};
|
||||
let err = naga::back::glsl::Writer::new(
|
||||
String::new(),
|
||||
&module,
|
||||
&module_info,
|
||||
&options,
|
||||
&pipeline_options,
|
||||
Default::default(),
|
||||
)
|
||||
.err()
|
||||
.unwrap_or_else(|| {
|
||||
panic!("`{interpolate_attr}` should fail backend validation on GLSL ES");
|
||||
});
|
||||
|
||||
// The message must name the version and the feature, so that it is actionable.
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
"GLSL 300 es doesn't support the required feature(s): NOPERSPECTIVE_QUALIFIER"
|
||||
);
|
||||
}
|
||||
|
||||
mod dummy_interpolation_shader {
|
||||
pub struct DummyInterpolationShader {
|
||||
pub source: String,
|
||||
|
||||
@@ -1288,6 +1288,36 @@ fn per_vertex_capability() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linear_interpolation_capability() {
|
||||
// Regression test for https://github.com/gfx-rs/wgpu/issues/9971: `@interpolate(linear)`
|
||||
// has no GLSL ES equivalent, so it must be rejected during validation rather than
|
||||
// silently passing and then failing in the GLSL backend at pipeline creation.
|
||||
let source = r#"
|
||||
@fragment
|
||||
fn fs_main(@location(0) @interpolate(linear) v: f32) -> @location(0) vec4<f32> {
|
||||
return vec4(v, 0.0, 0.0, 1.0);
|
||||
}
|
||||
"#;
|
||||
|
||||
check_one_validation! {
|
||||
source,
|
||||
Err(naga::valid::ValidationError::EntryPoint {
|
||||
stage: naga::ShaderStage::Fragment,
|
||||
source: valid::EntryPointError::Argument(
|
||||
0,
|
||||
valid::VaryingError::UnsupportedCapability(Capabilities::LINEAR_INTERPOLATION),
|
||||
),
|
||||
..
|
||||
})
|
||||
}
|
||||
|
||||
no_validation_error(
|
||||
source,
|
||||
Capabilities::default() | Capabilities::LINEAR_INTERPOLATION,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_enables_valid() {
|
||||
check_success(
|
||||
|
||||
@@ -439,6 +439,13 @@ impl super::Adapter {
|
||||
wgt::DownlevelFlags::MULTISAMPLED_SHADING,
|
||||
supported((3, 2), (4, 0)) || extensions.contains("OES_sample_variables"),
|
||||
);
|
||||
// GLSL ES has no `noperspective` qualifier, so `@interpolate(linear)` is only
|
||||
// expressible on desktop GLSL (where we require at least 330, well past the 130
|
||||
// that introduced `noperspective`).
|
||||
downlevel_flags.set(
|
||||
wgt::DownlevelFlags::LINEAR_INTERPOLATION,
|
||||
!shading_language_version.is_es(),
|
||||
);
|
||||
let query_buffers = extensions.contains("GL_ARB_query_buffer_object")
|
||||
|| extensions.contains("GL_AMD_query_buffer_object");
|
||||
if query_buffers {
|
||||
|
||||
@@ -696,7 +696,8 @@ impl PhysicalDeviceFeatures {
|
||||
| Df::UNRESTRICTED_EXTERNAL_TEXTURE_COPIES
|
||||
| Df::NONBLOCKING_QUERY_RESOLVE
|
||||
| Df::SHADER_F16_IN_F32
|
||||
| Df::MSL2_1;
|
||||
| Df::MSL2_1
|
||||
| Df::LINEAR_INTERPOLATION;
|
||||
|
||||
dl_flags.set(
|
||||
Df::SURFACE_VIEW_FORMATS,
|
||||
|
||||
@@ -183,6 +183,10 @@ pub fn features_to_naga_capabilities(
|
||||
Caps::RAY_TRACING_PIPELINE,
|
||||
features.intersects(wgt::Features::EXPERIMENTAL_RAY_TRACING_PIPELINES),
|
||||
);
|
||||
caps.set(
|
||||
Caps::LINEAR_INTERPOLATION,
|
||||
downlevel.contains(wgt::DownlevelFlags::LINEAR_INTERPOLATION),
|
||||
);
|
||||
caps
|
||||
}
|
||||
|
||||
|
||||
@@ -1236,6 +1236,13 @@ bitflags::bitflags! {
|
||||
///
|
||||
/// See <https://www.w3.org/TR/webgpu/#adapter-capability-guarantees>.
|
||||
const TEXTURE_COMPRESSION = 1 << 25;
|
||||
|
||||
/// Supports `@interpolate(linear)` (a.k.a. `noperspective`) on shader inter-stage
|
||||
/// variables.
|
||||
///
|
||||
/// GLSL ES has no `noperspective` qualifier, so the GLES backend only supports this
|
||||
/// on desktop OpenGL, not on GLES/WebGL2.
|
||||
const LINEAR_INTERPOLATION = 1 << 26;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user