Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ray-tracing-new' into ray-tracin…
Browse files Browse the repository at this point in the history
…g-new
  • Loading branch information
Vecvec committed Sep 28, 2024
2 parents 62aa9e6 + 1504e78 commit 7662d99
Show file tree
Hide file tree
Showing 34 changed files with 207 additions and 125 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ By @bradwerth [#6216](https://github.com/gfx-rs/wgpu/pull/6216).
### Documentation

- Removed some OpenGL and Vulkan references from `wgpu-types` documentation. Fixed Storage texel types in examples. By @Nelarius in [#6271](https://github.com/gfx-rs/wgpu/pull/6271)
- Used `wgpu::include_wgsl!(…)` more in examples and tests. By @ErichDonGubler in [#6326](https://github.com/gfx-rs/wgpu/pull/6326).

### Dependency Updates

Expand Down
12 changes: 3 additions & 9 deletions examples/src/boids/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// adapted from https://github.com/austinEng/webgpu-samples/blob/master/src/examples/computeBoids.ts

use nanorand::{Rng, WyRand};
use std::{borrow::Cow, mem::size_of};
use std::mem::size_of;
use wgpu::util::DeviceExt;

// number of boid particles to simulate
Expand Down Expand Up @@ -43,14 +43,8 @@ impl crate::framework::Example for Example {
device: &wgpu::Device,
_queue: &wgpu::Queue,
) -> Self {
let compute_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("compute.wgsl"))),
});
let draw_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("draw.wgsl"))),
});
let compute_shader = device.create_shader_module(wgpu::include_wgsl!("compute.wgsl"));
let draw_shader = device.create_shader_module(wgpu::include_wgsl!("draw.wgsl"));

// buffer for simulation parameters uniform

Expand Down
15 changes: 3 additions & 12 deletions examples/src/conservative_raster/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::borrow::Cow;

const RENDER_TARGET_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;

struct Example {
Expand Down Expand Up @@ -83,12 +81,8 @@ impl crate::framework::Example for Example {
push_constant_ranges: &[],
});

let shader_triangle_and_lines = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!(
"triangle_and_lines.wgsl"
))),
});
let shader_triangle_and_lines =
device.create_shader_module(wgpu::include_wgsl!("triangle_and_lines.wgsl"));

let pipeline_triangle_conservative =
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
Expand Down Expand Up @@ -203,10 +197,7 @@ impl crate::framework::Example for Example {
bind_group_layouts: &[&bind_group_layout],
push_constant_ranges: &[],
});
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("upscale.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("upscale.wgsl"));
(
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("Upscale"),
Expand Down
7 changes: 2 additions & 5 deletions examples/src/cube/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, f32::consts, mem::size_of};
use std::{f32::consts, mem::size_of};
use wgpu::util::DeviceExt;

#[repr(C)]
Expand Down Expand Up @@ -216,10 +216,7 @@ impl crate::framework::Example for Example {
label: None,
});

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let vertex_buffers = [wgpu::VertexBufferLayout {
array_stride: vertex_size as wgpu::BufferAddress,
Expand Down
7 changes: 2 additions & 5 deletions examples/src/hello_compute/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, mem::size_of_val, str::FromStr};
use std::{mem::size_of_val, str::FromStr};
use wgpu::util::DeviceExt;

// Indicates a u32 overflow in an intermediate Collatz value
Expand Down Expand Up @@ -66,10 +66,7 @@ async fn execute_gpu_inner(
numbers: &[u32],
) -> Option<Vec<u32>> {
// Loads the shader from WGSL
let cs_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
});
let cs_module = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

// Gets the size in bytes of the buffer.
let size = size_of_val(numbers) as wgpu::BufferAddress;
Expand Down
5 changes: 1 addition & 4 deletions examples/src/hello_synchronization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ async fn execute(
let mut local_patient_workgroup_results = vec![0u32; result_vec_size];
let mut local_hasty_workgroup_results = local_patient_workgroup_results.clone();

let shaders_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!("shaders.wgsl"))),
});
let shaders_module = device.create_shader_module(wgpu::include_wgsl!("shaders.wgsl"));

let storage_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
Expand Down
5 changes: 1 addition & 4 deletions examples/src/hello_workgroups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ async fn run() {
.await
.unwrap();

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let storage_buffer_a = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: None,
Expand Down
12 changes: 3 additions & 9 deletions examples/src/mipmap/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, f32::consts, mem::size_of};
use std::{f32::consts, mem::size_of};
use wgpu::util::DeviceExt;

const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
Expand Down Expand Up @@ -81,10 +81,7 @@ impl Example {
query_sets: &Option<QuerySets>,
mip_count: u32,
) {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("blit.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("blit.wgsl"));

let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("blit"),
Expand Down Expand Up @@ -281,10 +278,7 @@ impl crate::framework::Example for Example {
});

// Create the render pipeline
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("draw.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("draw.wgsl"));

let draw_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("draw"),
Expand Down
7 changes: 2 additions & 5 deletions examples/src/msaa_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! * Set the primitive_topology to PrimitiveTopology::LineList.
//! * Vertices and Indices describe the two points that make up a line.

use std::{borrow::Cow, iter, mem::size_of};
use std::{iter, mem::size_of};

use bytemuck::{Pod, Zeroable};
use wgpu::util::DeviceExt;
Expand Down Expand Up @@ -156,10 +156,7 @@ impl crate::framework::Example for Example {

let sample_count = max_sample_count;

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
Expand Down
5 changes: 1 addition & 4 deletions examples/src/render_to_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ async fn run(_path: Option<String>) {
.await
.unwrap();

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let render_target = device.create_texture(&wgpu::TextureDescriptor {
label: None,
Expand Down
7 changes: 1 addition & 6 deletions examples/src/repeated_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,7 @@ impl WgpuContext {
.unwrap();

// Our shader, kindly compiled with Naga.
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!(
"shader.wgsl"
))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

// This is where the GPU will read from and write to.
let storage_buffer = device.create_buffer(&wgpu::BufferDescriptor {
Expand Down
7 changes: 2 additions & 5 deletions examples/src/shadow/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, f32::consts, iter, mem::size_of, ops::Range, sync::Arc};
use std::{f32::consts, iter, mem::size_of, ops::Range, sync::Arc};

use bytemuck::{Pod, Zeroable};
use wgpu::util::{align_to, DeviceExt};
Expand Down Expand Up @@ -447,10 +447,7 @@ impl crate::framework::Example for Example {
attributes: &vertex_attr,
};

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let shadow_pass = {
let uniform_size = size_of::<GlobalUniforms>() as wgpu::BufferAddress;
Expand Down
7 changes: 2 additions & 5 deletions examples/src/skybox/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, f32::consts, mem::size_of};
use std::{f32::consts, mem::size_of};
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};

const IMAGE_SIZE: u32 = 256;
Expand Down Expand Up @@ -168,10 +168,7 @@ impl crate::framework::Example for Example {
});

// Create the render pipeline
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let camera = Camera {
screen_size: (config.width, config.height),
Expand Down
7 changes: 2 additions & 5 deletions examples/src/srgb_blend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, mem};
use std::mem;
use wgpu::util::DeviceExt;

#[repr(C)]
Expand Down Expand Up @@ -103,10 +103,7 @@ impl<const SRGB: bool> crate::framework::Example for Example<SRGB> {
label: None,
});

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let vertex_buffers = [wgpu::VertexBufferLayout {
array_stride: vertex_size as wgpu::BufferAddress,
Expand Down
6 changes: 1 addition & 5 deletions examples/src/stencil_triangles/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use bytemuck::{Pod, Zeroable};
use std::borrow::Cow;
use std::mem::size_of;
use wgpu::util::DeviceExt;

Expand Down Expand Up @@ -53,10 +52,7 @@ impl crate::framework::Example for Example {
push_constant_ranges: &[],
});

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let vertex_buffers = [wgpu::VertexBufferLayout {
array_stride: vertex_size as wgpu::BufferAddress,
Expand Down
5 changes: 1 addition & 4 deletions examples/src/storage_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ async fn run(_path: Option<String>) {
.await
.unwrap();

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let storage_texture = device.create_texture(&wgpu::TextureDescriptor {
label: None,
Expand Down
5 changes: 1 addition & 4 deletions examples/src/timestamp_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,7 @@ fn submit_render_and_compute_pass_with_queries(
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });

let mut queries = Queries::new(device, QueryResults::NUM_QUERIES);
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!("shader.wgsl"))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

if device
.features()
Expand Down
7 changes: 1 addition & 6 deletions examples/src/uniform_values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ impl WgpuContext {
.await
.unwrap();

let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!(
"shader.wgsl"
))),
});
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

// (2)
let uniform_buffer = device.create_buffer(&wgpu::BufferDescriptor {
Expand Down
12 changes: 3 additions & 9 deletions examples/src/water/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod point_gen;
use bytemuck::{Pod, Zeroable};
use glam::Vec3;
use nanorand::{Rng, WyRand};
use std::{borrow::Cow, f32::consts, iter, mem::size_of};
use std::{f32::consts, iter, mem::size_of};
use wgpu::util::DeviceExt;

///
Expand Down Expand Up @@ -493,14 +493,8 @@ impl crate::framework::Example for Example {
});

// Upload/compile them to GPU code.
let terrain_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("terrain"),
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("terrain.wgsl"))),
});
let water_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("water"),
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("water.wgsl"))),
});
let terrain_module = device.create_shader_module(wgpu::include_wgsl!("terrain.wgsl"));
let water_module = device.create_shader_module(wgpu::include_wgsl!("water.wgsl"));

// Create the render pipelines. These describe how the data will flow through the GPU, and what
// constraints and modifiers it will have.
Expand Down
6 changes: 4 additions & 2 deletions naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1778,12 +1778,14 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {

return Ok(());
}
ast::StatementKind::Ignore(expr) => {
ast::StatementKind::Phony(expr) => {
let mut emitter = Emitter::default();
emitter.start(&ctx.function.expressions);

let _ = self.expression(expr, &mut ctx.as_expression(block, &mut emitter))?;
let value = self.expression(expr, &mut ctx.as_expression(block, &mut emitter))?;
block.extend(emitter.finish(&ctx.function.expressions));
ctx.named_expressions
.insert(value, ("phony".to_string(), stmt.span));
return Ok(());
}
};
Expand Down
2 changes: 1 addition & 1 deletion naga/src/front/wgsl/parse/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub enum StatementKind<'a> {
},
Increment(Handle<Expression<'a>>),
Decrement(Handle<Expression<'a>>),
Ignore(Handle<Expression<'a>>),
Phony(Handle<Expression<'a>>),
ConstAssert(Handle<Expression<'a>>),
}

Expand Down
2 changes: 1 addition & 1 deletion naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ impl Parser {
let expr = self.general_expression(lexer, ctx)?;
lexer.expect(Token::Separator(';'))?;

ast::StatementKind::Ignore(expr)
ast::StatementKind::Phony(expr)
}
"let" => {
let _ = lexer.next();
Expand Down
2 changes: 2 additions & 0 deletions naga/tests/in/phony_assignment.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(
)
Loading

0 comments on commit 7662d99

Please sign in to comment.