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`.
This commit is contained in:
Jim Blandy 2022-06-22 22:30:06 -07:00
parent a3ed6e06ab
commit 36ae2ceda3
17 changed files with 29 additions and 30 deletions

View File

@ -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"))),
});

View File

@ -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"

View File

@ -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"))),
});

View File

@ -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"))),
});

View File

@ -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"))),
});

View File

@ -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"))),
});

View File

@ -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"))),
});
@ -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"))),
});

View File

@ -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"))),
});

View File

@ -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"))),
});

View File

@ -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"))),
});

View File

@ -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

View File

@ -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"))),
});

View File

@ -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;

View File

@ -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 {

View File

@ -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),

View File

@ -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

View File

@ -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