Skip to content

Commit

Permalink
Pass ShaderModuleDescriptor to create_shader_module by value.
Browse files Browse the repository at this point in the history
This will allow us to pass module representations that are neither
`Copy` nor `Clone`, like `naga::Module`.
  • Loading branch information
jimblandy authored and rttad committed Jun 23, 2022
1 parent fa6acdc commit dabdc6e
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions wgpu/examples/boids/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
});
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 7 additions & 8 deletions wgpu/examples/conservative-raster/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"))),
});
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
});
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/hello-compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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 {
let cs_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
});
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/hello-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
});
Expand Down
4 changes: 2 additions & 2 deletions wgpu/examples/mipmap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Example {
query_sets: &Option<QuerySets>,
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"))),
});
Expand Down Expand Up @@ -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"))),
});
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/msaa-line/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
});
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/shadow/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
});
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/skybox/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
});
Expand Down
4 changes: 2 additions & 2 deletions wgpu/examples/texture-arrays/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions wgpu/examples/water/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
});
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,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;
Expand Down
6 changes: 3 additions & 3 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -1958,7 +1958,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(
Expand All @@ -1982,7 +1982,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),
Expand Down
2 changes: 1 addition & 1 deletion wgpu/tests/shader_primitive_index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wgpu/tests/vertex_indices/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dabdc6e

Please sign in to comment.