Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ By @SupaMaggie70Incorporated in [#8206](https://github.com/gfx-rs/wgpu/pull/8206

#### General

- Require new enable extensions when using ray queries and position fetch (`wgpu_ray_query`, `wgpu_ray_query_vertex_return`). By @Vecvec in [#8545](https://github.com/gfx-rs/wgpu/pull/8545).
Copy link
Member

Choose a reason for hiding this comment

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

thought: Would a BREAKING callout be helpful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, probably.

- Lower `max_blas_primitive_count` due to a bug in llvmpipe. By @Vecvec in [#8446](https://github.com/gfx-rs/wgpu/pull/8446).
- Texture now has `from_custom`. By @R-Cramer4 in [#8315](https://github.com/gfx-rs/wgpu/pull/8315).
- Using both the wgpu command encoding APIs and `CommandEncoder::as_hal_mut` on the same encoder will now result in a panic.
Expand Down
1 change: 1 addition & 0 deletions examples/features/src/ray_cube_compute/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct RayIntersection {
world_to_object: mat4x3<f32>,
}
*/
enable wgpu_ray_query;

struct Uniforms {
view_inv: mat4x4<f32>,
Expand Down
2 changes: 2 additions & 0 deletions examples/features/src/ray_cube_fragment/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable wgpu_ray_query;

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
Expand Down
2 changes: 2 additions & 0 deletions examples/features/src/ray_cube_normals/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct RayIntersection {
world_to_object: mat4x3<f32>,
}
*/
enable wgpu_ray_query;
enable wgpu_ray_query_vertex_return;

struct Uniforms {
view_inv: mat4x4<f32>,
Expand Down
2 changes: 2 additions & 0 deletions examples/features/src/ray_scene/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable wgpu_ray_query;

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
Expand Down
2 changes: 2 additions & 0 deletions examples/features/src/ray_shadows/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable wgpu_ray_query;

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
Expand Down
2 changes: 2 additions & 0 deletions examples/features/src/ray_traced_triangle/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// duplicate of hal's ray-traced triangle shader

enable wgpu_ray_query;

struct Uniforms {
view_inv: mat4x4<f32>,
proj_inv: mat4x4<f32>,
Expand Down
26 changes: 26 additions & 0 deletions naga/src/front/wgsl/parse/directive/enable_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use alloc::boxed::Box;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EnableExtensions {
wgpu_mesh_shader: bool,
wgpu_ray_query: bool,
wgpu_ray_query_vertex_return: bool,
dual_source_blending: bool,
/// Whether `enable f16;` was written earlier in the shader module.
f16: bool,
Expand All @@ -21,6 +23,8 @@ impl EnableExtensions {
pub(crate) const fn empty() -> Self {
Self {
wgpu_mesh_shader: false,
wgpu_ray_query: false,
wgpu_ray_query_vertex_return: false,
f16: false,
dual_source_blending: false,
clip_distances: false,
Expand All @@ -31,6 +35,10 @@ impl EnableExtensions {
pub(crate) fn add(&mut self, ext: ImplementedEnableExtension) {
let field = match ext {
ImplementedEnableExtension::WgpuMeshShader => &mut self.wgpu_mesh_shader,
ImplementedEnableExtension::WgpuRayQuery => &mut self.wgpu_ray_query,
ImplementedEnableExtension::WgpuRayQueryVertexReturn => {
&mut self.wgpu_ray_query_vertex_return
}
ImplementedEnableExtension::DualSourceBlending => &mut self.dual_source_blending,
ImplementedEnableExtension::F16 => &mut self.f16,
ImplementedEnableExtension::ClipDistances => &mut self.clip_distances,
Expand All @@ -42,6 +50,10 @@ impl EnableExtensions {
pub(crate) const fn contains(&self, ext: ImplementedEnableExtension) -> bool {
match ext {
ImplementedEnableExtension::WgpuMeshShader => self.wgpu_mesh_shader,
ImplementedEnableExtension::WgpuRayQuery => self.wgpu_ray_query,
ImplementedEnableExtension::WgpuRayQueryVertexReturn => {
self.wgpu_ray_query_vertex_return
}
ImplementedEnableExtension::DualSourceBlending => self.dual_source_blending,
ImplementedEnableExtension::F16 => self.f16,
ImplementedEnableExtension::ClipDistances => self.clip_distances,
Expand Down Expand Up @@ -75,6 +87,8 @@ impl EnableExtension {
const CLIP_DISTANCES: &'static str = "clip_distances";
const DUAL_SOURCE_BLENDING: &'static str = "dual_source_blending";
const MESH_SHADER: &'static str = "wgpu_mesh_shader";
const RAY_QUERY: &'static str = "wgpu_ray_query";
const RAY_QUERY_VERTEX_RETURN: &'static str = "wgpu_ray_query_vertex_return";
const SUBGROUPS: &'static str = "subgroups";
const PRIMITIVE_INDEX: &'static str = "primitive_index";

Expand All @@ -87,6 +101,10 @@ impl EnableExtension {
Self::Implemented(ImplementedEnableExtension::DualSourceBlending)
}
Self::MESH_SHADER => Self::Implemented(ImplementedEnableExtension::WgpuMeshShader),
Self::RAY_QUERY => Self::Implemented(ImplementedEnableExtension::WgpuRayQuery),
Self::RAY_QUERY_VERTEX_RETURN => {
Self::Implemented(ImplementedEnableExtension::WgpuRayQueryVertexReturn)
}
Self::SUBGROUPS => Self::Unimplemented(UnimplementedEnableExtension::Subgroups),
Self::PRIMITIVE_INDEX => {
Self::Unimplemented(UnimplementedEnableExtension::PrimitiveIndex)
Expand All @@ -100,6 +118,10 @@ impl EnableExtension {
match self {
Self::Implemented(kind) => match kind {
ImplementedEnableExtension::WgpuMeshShader => Self::MESH_SHADER,
ImplementedEnableExtension::WgpuRayQuery => Self::RAY_QUERY,
ImplementedEnableExtension::WgpuRayQueryVertexReturn => {
Self::RAY_QUERY_VERTEX_RETURN
}
ImplementedEnableExtension::DualSourceBlending => Self::DUAL_SOURCE_BLENDING,
ImplementedEnableExtension::F16 => Self::F16,
ImplementedEnableExtension::ClipDistances => Self::CLIP_DISTANCES,
Expand Down Expand Up @@ -135,6 +157,10 @@ pub enum ImplementedEnableExtension {
ClipDistances,
/// Enables the `wgpu_mesh_shader` extension, native only
WgpuMeshShader,
/// Enables the `wgpu_ray_query` extension, native only.
WgpuRayQuery,
/// Enables the `wgpu_ray_query_vertex_return` extension, native only.
WgpuRayQueryVertexReturn,
}

/// A variant of [`EnableExtension::Unimplemented`].
Expand Down
76 changes: 74 additions & 2 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1930,15 +1930,87 @@ impl Parser {
}
}
"acceleration_structure" => {
if !lexer
.enable_extensions
.contains(ImplementedEnableExtension::WgpuRayQuery)
{
return Err(Box::new(Error::EnableExtensionNotEnabled {
kind: EnableExtension::Implemented(
ImplementedEnableExtension::WgpuRayQuery,
),
span,
}));
}
let vertex_return = lexer.next_acceleration_structure_flags()?;
if !lexer
.enable_extensions
.contains(ImplementedEnableExtension::WgpuRayQueryVertexReturn)
&& vertex_return
{
return Err(Box::new(Error::EnableExtensionNotEnabled {
kind: EnableExtension::Implemented(
ImplementedEnableExtension::WgpuRayQueryVertexReturn,
),
span,
}));
}
ast::Type::AccelerationStructure { vertex_return }
}
"ray_query" => {
if !lexer
.enable_extensions
.contains(ImplementedEnableExtension::WgpuRayQuery)
{
return Err(Box::new(Error::EnableExtensionNotEnabled {
kind: EnableExtension::Implemented(
ImplementedEnableExtension::WgpuRayQuery,
),
span,
}));
}
let vertex_return = lexer.next_acceleration_structure_flags()?;
if !lexer
.enable_extensions
.contains(ImplementedEnableExtension::WgpuRayQueryVertexReturn)
&& vertex_return
{
return Err(Box::new(Error::EnableExtensionNotEnabled {
kind: EnableExtension::Implemented(
ImplementedEnableExtension::WgpuRayQueryVertexReturn,
),
span,
}));
}
ast::Type::RayQuery { vertex_return }
}
"RayDesc" => ast::Type::RayDesc,
"RayIntersection" => ast::Type::RayIntersection,
"RayDesc" => {
if !lexer
.enable_extensions
.contains(ImplementedEnableExtension::WgpuRayQuery)
{
return Err(Box::new(Error::EnableExtensionNotEnabled {
kind: EnableExtension::Implemented(
ImplementedEnableExtension::WgpuRayQuery,
),
span,
}));
}
ast::Type::RayDesc
}
"RayIntersection" => {
if !lexer
.enable_extensions
.contains(ImplementedEnableExtension::WgpuRayQuery)
{
return Err(Box::new(Error::EnableExtensionNotEnabled {
kind: EnableExtension::Implemented(
ImplementedEnableExtension::WgpuRayQuery,
),
span,
}));
}
ast::Type::RayIntersection
}
_ => return Ok(None),
}))
}
Expand Down
2 changes: 2 additions & 0 deletions naga/src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ impl Capabilities {
// NOTE: `SHADER_FLOAT16_IN_FLOAT32` _does not_ require the `f16` extension
Self::SHADER_FLOAT16 => Some(Ext::F16),
Self::CLIP_DISTANCE => Some(Ext::ClipDistances),
Self::RAY_QUERY => Some(Ext::WgpuRayQuery),
Self::RAY_HIT_VERTEX_POSITION => Some(Ext::WgpuRayQueryVertexReturn),
_ => None,
}
}
Expand Down
2 changes: 2 additions & 0 deletions naga/tests/in/wgsl/aliased-ray-query.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable wgpu_ray_query;

alias rq = ray_query;

@group(0) @binding(0)
Expand Down
2 changes: 2 additions & 0 deletions naga/tests/in/wgsl/overrides-ray-query.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable wgpu_ray_query;

override o: f32;

@group(0) @binding(0)
Expand Down
2 changes: 2 additions & 0 deletions naga/tests/in/wgsl/ray-query-no-init-tracking.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct RayIntersection {
}
*/

enable wgpu_ray_query;

fn query_loop(pos: vec3<f32>, dir: vec3<f32>, acs: acceleration_structure) -> RayIntersection {
var rq: ray_query;
rayQueryInitialize(&rq, acs, RayDesc(RAY_FLAG_TERMINATE_ON_FIRST_HIT, 0xFFu, 0.1, 100.0, pos, dir));
Expand Down
2 changes: 2 additions & 0 deletions naga/tests/in/wgsl/ray-query.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct RayIntersection {
}
*/

enable wgpu_ray_query;

fn query_loop(pos: vec3<f32>, dir: vec3<f32>, acs: acceleration_structure) -> RayIntersection {
var rq: ray_query;
rayQueryInitialize(&rq, acs, RayDesc(RAY_FLAG_TERMINATE_ON_FIRST_HIT, 0xFFu, 0.1, 100.0, pos, dir));
Expand Down
96 changes: 96 additions & 0 deletions naga/tests/naga/wgsl_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4283,3 +4283,99 @@ fn source_with_control_char() {
",
);
}

#[test]
fn ray_query_enable_extension() {
check_extension_validation!(
Capabilities::RAY_QUERY,
r#"fn foo() {
var a: ray_query;
}
"#,
r#"error: the `wgpu_ray_query` enable extension is not enabled
┌─ wgsl:2:20
2 │ var a: ray_query;
│ ^^^^^^^^^ the `wgpu_ray_query` "Enable Extension" is needed for this functionality, but it is not currently enabled.
= note: You can enable this extension by adding `enable wgpu_ray_query;` at the top of the shader, before any other items.

"#,
Err(naga::valid::ValidationError::Type {
source: naga::valid::TypeError::MissingCapability(Capabilities::RAY_QUERY),
..
})
);

check_extension_validation!(
Capabilities::RAY_QUERY,
r#"@group(0) @binding(0)
var acc_struct: acceleration_structure;
"#,
r#"error: the `wgpu_ray_query` enable extension is not enabled
┌─ wgsl:2:25
2 │ var acc_struct: acceleration_structure;
│ ^^^^^^^^^^^^^^^^^^^^^^ the `wgpu_ray_query` "Enable Extension" is needed for this functionality, but it is not currently enabled.
= note: You can enable this extension by adding `enable wgpu_ray_query;` at the top of the shader, before any other items.

"#,
Err(naga::valid::ValidationError::Type {
source: naga::valid::TypeError::MissingCapability(Capabilities::RAY_QUERY),
..
})
);
}

#[test]
fn ray_query_vertex_return_enable_extension() {
check_extension_validation!(
Capabilities::RAY_HIT_VERTEX_POSITION,
r#"enable wgpu_ray_query;

fn foo() {
var a: ray_query<vertex_return>;
}
"#,
r#"error: the `wgpu_ray_query_vertex_return` enable extension is not enabled
┌─ wgsl:4:20
4 │ var a: ray_query<vertex_return>;
│ ^^^^^^^^^ the `wgpu_ray_query_vertex_return` "Enable Extension" is needed for this functionality, but it is not currently enabled.
= note: You can enable this extension by adding `enable wgpu_ray_query_vertex_return;` at the top of the shader, before any other items.

"#,
Err(naga::valid::ValidationError::Type {
source: naga::valid::TypeError::MissingCapability(
Capabilities::RAY_HIT_VERTEX_POSITION
),
..
})
);

check_extension_validation!(
Capabilities::RAY_HIT_VERTEX_POSITION,
r#"enable wgpu_ray_query;

@group(0) @binding(0)
var acc_struct: acceleration_structure<vertex_return>;
"#,
r#"error: the `wgpu_ray_query_vertex_return` enable extension is not enabled
┌─ wgsl:4:25
4 │ var acc_struct: acceleration_structure<vertex_return>;
│ ^^^^^^^^^^^^^^^^^^^^^^ the `wgpu_ray_query_vertex_return` "Enable Extension" is needed for this functionality, but it is not currently enabled.
= note: You can enable this extension by adding `enable wgpu_ray_query_vertex_return;` at the top of the shader, before any other items.

"#,
Err(naga::valid::ValidationError::Type {
source: naga::valid::TypeError::MissingCapability(
Capabilities::RAY_HIT_VERTEX_POSITION
),
..
})
);
}
2 changes: 2 additions & 0 deletions tests/tests/wgpu-gpu/ray_tracing/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable wgpu_ray_query;

@group(0) @binding(0)
var acc_struct: acceleration_structure;

Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/examples/ray-traced-triangle/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enable wgpu_ray_query;

struct Uniforms {
view_inv: mat4x4<f32>,
proj_inv: mat4x4<f32>,
Expand Down
Loading