From 36ae2ceda3e9d0bbd3dfff4c8a062e53d16fce2b Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Wed, 22 Jun 2022 22:30:06 -0700 Subject: [PATCH] Pass ShaderModuleDescriptor to create_shader_module by value. This will allow us to pass module representations that are neither `Copy` nor `Clone`, like `naga::Module`. --- wgpu/examples/boids/main.rs | 4 ++-- wgpu/examples/bunnymark/main.rs | 2 +- wgpu/examples/conservative-raster/main.rs | 15 +++++++-------- wgpu/examples/cube/main.rs | 2 +- wgpu/examples/hello-compute/main.rs | 2 +- wgpu/examples/hello-triangle/main.rs | 2 +- wgpu/examples/mipmap/main.rs | 4 ++-- wgpu/examples/msaa-line/main.rs | 2 +- wgpu/examples/shadow/main.rs | 2 +- wgpu/examples/skybox/main.rs | 2 +- wgpu/examples/texture-arrays/main.rs | 4 ++-- wgpu/examples/water/main.rs | 4 ++-- wgpu/src/backend/direct.rs | 2 +- wgpu/src/backend/web.rs | 2 +- wgpu/src/lib.rs | 6 +++--- wgpu/tests/shader_primitive_index/mod.rs | 2 +- wgpu/tests/vertex_indices/mod.rs | 2 +- 17 files changed, 29 insertions(+), 30 deletions(-) diff --git a/wgpu/examples/boids/main.rs b/wgpu/examples/boids/main.rs index bb19d5066a..229e096246 100644 --- a/wgpu/examples/boids/main.rs +++ b/wgpu/examples/boids/main.rs @@ -46,11 +46,11 @@ impl framework::Example for Example { device: &wgpu::Device, _queue: &wgpu::Queue, ) -> Self { - let compute_shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + 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 { + let draw_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("draw.wgsl"))), }); diff --git a/wgpu/examples/bunnymark/main.rs b/wgpu/examples/bunnymark/main.rs index 47fa1d92d3..aaf9f50c06 100644 --- a/wgpu/examples/bunnymark/main.rs +++ b/wgpu/examples/bunnymark/main.rs @@ -46,7 +46,7 @@ impl framework::Example for Example { device: &wgpu::Device, queue: &wgpu::Queue, ) -> Self { - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!( "../../../wgpu-hal/examples/halmark/shader.wgsl" diff --git a/wgpu/examples/conservative-raster/main.rs b/wgpu/examples/conservative-raster/main.rs index 20104e35c8..7617d508a3 100644 --- a/wgpu/examples/conservative-raster/main.rs +++ b/wgpu/examples/conservative-raster/main.rs @@ -85,13 +85,12 @@ impl 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::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!( + "triangle_and_lines.wgsl" + ))), + }); let pipeline_triangle_conservative = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { @@ -197,7 +196,7 @@ impl framework::Example for Example { bind_group_layouts: &[&bind_group_layout], push_constant_ranges: &[], }); - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("upscale.wgsl"))), }); diff --git a/wgpu/examples/cube/main.rs b/wgpu/examples/cube/main.rs index bc180acb1b..c03e3f200c 100644 --- a/wgpu/examples/cube/main.rs +++ b/wgpu/examples/cube/main.rs @@ -240,7 +240,7 @@ impl framework::Example for Example { label: None, }); - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), }); diff --git a/wgpu/examples/hello-compute/main.rs b/wgpu/examples/hello-compute/main.rs index df157cbfec..3e21ee11be 100644 --- a/wgpu/examples/hello-compute/main.rs +++ b/wgpu/examples/hello-compute/main.rs @@ -69,7 +69,7 @@ async fn execute_gpu_inner( numbers: &[u32], ) -> Option> { // Loads the shader from WGSL - let cs_module = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let cs_module = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), }); diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs index 1fc230f790..5fea4c4c0b 100644 --- a/wgpu/examples/hello-triangle/main.rs +++ b/wgpu/examples/hello-triangle/main.rs @@ -35,7 +35,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { .expect("Failed to create device"); // Load the shaders from disk - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), }); diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs index cd31863b80..634528e6e9 100644 --- a/wgpu/examples/mipmap/main.rs +++ b/wgpu/examples/mipmap/main.rs @@ -78,7 +78,7 @@ impl Example { query_sets: &Option, mip_count: u32, ) { - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("blit.wgsl"))), }); @@ -272,7 +272,7 @@ impl framework::Example for Example { }); // Create the render pipeline - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("draw.wgsl"))), }); diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs index 5178f32a27..8364286c1a 100644 --- a/wgpu/examples/msaa-line/main.rs +++ b/wgpu/examples/msaa-line/main.rs @@ -126,7 +126,7 @@ impl framework::Example for Example { log::info!("Press left/right arrow keys to change sample_count."); let sample_count = 4; - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), }); diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index f03af8e35e..bb8fec5acd 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -449,7 +449,7 @@ impl framework::Example for Example { attributes: &vertex_attr, }; - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), }); diff --git a/wgpu/examples/skybox/main.rs b/wgpu/examples/skybox/main.rs index 2b8f6d8f96..a44cb70448 100644 --- a/wgpu/examples/skybox/main.rs +++ b/wgpu/examples/skybox/main.rs @@ -170,7 +170,7 @@ impl framework::Example for Skybox { }); // Create the render pipeline - let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), }); diff --git a/wgpu/examples/texture-arrays/main.rs b/wgpu/examples/texture-arrays/main.rs index 8c68585cc4..d09c28b70b 100644 --- a/wgpu/examples/texture-arrays/main.rs +++ b/wgpu/examples/texture-arrays/main.rs @@ -87,7 +87,7 @@ impl framework::Example for Example { queue: &wgpu::Queue, ) -> Self { let mut uniform_workaround = false; - let base_shader_module = device.create_shader_module(&wgpu::include_wgsl!("indexing.wgsl")); + let base_shader_module = device.create_shader_module(wgpu::include_wgsl!("indexing.wgsl")); let env_override = match std::env::var("WGPU_TEXTURE_ARRAY_STYLE") { Ok(value) => match &*value.to_lowercase() { "nonuniform" | "non_uniform" => Some(true), @@ -119,7 +119,7 @@ impl framework::Example for Example { // capabilities even if we don't use it. So for now put it in a separate module. let fragment_shader_module = if !uniform_workaround { non_uniform_shader_module = - device.create_shader_module(&wgpu::include_wgsl!("non_uniform_indexing.wgsl")); + device.create_shader_module(wgpu::include_wgsl!("non_uniform_indexing.wgsl")); &non_uniform_shader_module } else { &base_shader_module diff --git a/wgpu/examples/water/main.rs b/wgpu/examples/water/main.rs index 5667d05674..1b6085144b 100644 --- a/wgpu/examples/water/main.rs +++ b/wgpu/examples/water/main.rs @@ -494,11 +494,11 @@ impl framework::Example for Example { }); // Upload/compile them to GPU code. - let terrain_module = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + 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 { + let water_module = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("water"), source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("water.wgsl"))), }); diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 1f46c461b5..eb0d755e1a 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -1070,7 +1070,7 @@ impl crate::Context for Context { fn device_create_shader_module( &self, device: &Self::DeviceId, - desc: &ShaderModuleDescriptor, + desc: ShaderModuleDescriptor, shader_bound_checks: wgt::ShaderBoundChecks, ) -> Self::ShaderModuleId { let global = &self.0; diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 6d3c1b2408..e65ee9b4a6 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1251,7 +1251,7 @@ impl crate::Context for Context { fn device_create_shader_module( &self, device: &Self::DeviceId, - desc: &crate::ShaderModuleDescriptor, + desc: crate::ShaderModuleDescriptor, _shader_bound_checks: wgt::ShaderBoundChecks, ) -> Self::ShaderModuleId { let mut descriptor = match desc.source { diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index b6303bf397..f14298c422 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -257,7 +257,7 @@ trait Context: Debug + Send + Sized + Sync { fn device_create_shader_module( &self, device: &Self::DeviceId, - desc: &ShaderModuleDescriptor, + desc: ShaderModuleDescriptor, shader_bound_checks: wgt::ShaderBoundChecks, ) -> Self::ShaderModuleId; unsafe fn device_create_shader_module_spirv( @@ -1971,7 +1971,7 @@ impl Device { } /// Creates a shader module from either SPIR-V or WGSL source code. - pub fn create_shader_module(&self, desc: &ShaderModuleDescriptor) -> ShaderModule { + pub fn create_shader_module(&self, desc: ShaderModuleDescriptor) -> ShaderModule { ShaderModule { context: Arc::clone(&self.context), id: Context::device_create_shader_module( @@ -1995,7 +1995,7 @@ impl Device { /// This has no effect on web. pub unsafe fn create_shader_module_unchecked( &self, - desc: &ShaderModuleDescriptor, + desc: ShaderModuleDescriptor, ) -> ShaderModule { ShaderModule { context: Arc::clone(&self.context), diff --git a/wgpu/tests/shader_primitive_index/mod.rs b/wgpu/tests/shader_primitive_index/mod.rs index a131dab8ab..921aa112ac 100644 --- a/wgpu/tests/shader_primitive_index/mod.rs +++ b/wgpu/tests/shader_primitive_index/mod.rs @@ -105,7 +105,7 @@ fn pulling_common( ) { let shader = ctx .device - .create_shader_module(&wgpu::include_wgsl!("primitive_index.wgsl")); + .create_shader_module(wgpu::include_wgsl!("primitive_index.wgsl")); let two_triangles_xy: [f32; 12] = [ -1.0, -1.0, 0.0, -1.0, -0.5, 0.0, // left triangle, negative x, negative y diff --git a/wgpu/tests/vertex_indices/mod.rs b/wgpu/tests/vertex_indices/mod.rs index 7c99ca1e25..d59c0a5199 100644 --- a/wgpu/tests/vertex_indices/mod.rs +++ b/wgpu/tests/vertex_indices/mod.rs @@ -11,7 +11,7 @@ fn pulling_common( ) { let shader = ctx .device - .create_shader_module(&wgpu::include_wgsl!("draw.vert.wgsl")); + .create_shader_module(wgpu::include_wgsl!("draw.vert.wgsl")); let bgl = ctx .device