diff --git a/deno_webgpu/src/bundle.rs b/deno_webgpu/src/bundle.rs index d75d0c57104..b1c5b056174 100644 --- a/deno_webgpu/src/bundle.rs +++ b/deno_webgpu/src/bundle.rs @@ -32,7 +32,7 @@ impl Resource for WebGpuRenderBundle { pub struct CreateRenderBundleEncoderArgs { device_rid: ResourceId, label: Option, - color_formats: Vec, + color_formats: Vec>, depth_stencil_format: Option, sample_count: u32, depth_read_only: bool, diff --git a/deno_webgpu/src/command_encoder.rs b/deno_webgpu/src/command_encoder.rs index 3064f5c2973..75dfbfa25e9 100644 --- a/deno_webgpu/src/command_encoder.rs +++ b/deno_webgpu/src/command_encoder.rs @@ -78,7 +78,7 @@ pub fn op_webgpu_command_encoder_begin_render_pass( state: &mut OpState, command_encoder_rid: ResourceId, label: Option, - color_attachments: Vec, + color_attachments: Vec>, depth_stencil_attachment: Option, _occlusion_query_set: Option, // not yet implemented ) -> Result { @@ -89,30 +89,35 @@ pub fn op_webgpu_command_encoder_begin_render_pass( let color_attachments = color_attachments .into_iter() .map(|color_attachment| { - let texture_view_resource = state - .resource_table - .get::(color_attachment.view)?; - - let resolve_target = color_attachment - .resolve_target - .map(|rid| { - state - .resource_table - .get::(rid) + let rp_at = if let Some(at) = color_attachment.as_ref() { + let texture_view_resource = state + .resource_table + .get::(at.view)?; + + let resolve_target = at + .resolve_target + .map(|rid| { + state + .resource_table + .get::(rid) + }) + .transpose()? + .map(|texture| texture.0); + + Some(wgpu_core::command::RenderPassColorAttachment { + view: texture_view_resource.0, + resolve_target, + channel: wgpu_core::command::PassChannel { + load_op: at.load_op, + store_op: at.store_op, + clear_value: at.clear_value.unwrap_or_default(), + read_only: false, + }, }) - .transpose()? - .map(|texture| texture.0); - - Ok(wgpu_core::command::RenderPassColorAttachment { - view: texture_view_resource.0, - resolve_target, - channel: wgpu_core::command::PassChannel { - load_op: color_attachment.load_op, - store_op: color_attachment.store_op, - clear_value: color_attachment.clear_value.unwrap_or_default(), - read_only: false, - }, - }) + } else { + None + }; + Ok(rp_at) }) .collect::, AnyError>>()?; diff --git a/deno_webgpu/src/pipeline.rs b/deno_webgpu/src/pipeline.rs index 63958ac7edc..9b135f5d443 100644 --- a/deno_webgpu/src/pipeline.rs +++ b/deno_webgpu/src/pipeline.rs @@ -260,7 +260,7 @@ impl From for wgpu_types::MultisampleState { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] struct GpuFragmentState { - targets: Vec, + targets: Vec>, module: u32, entry_point: String, // TODO(lucacasonato): constants diff --git a/player/tests/data/quad.ron b/player/tests/data/quad.ron index b6153b2f621..11b63783000 100644 --- a/player/tests/data/quad.ron +++ b/player/tests/data/quad.ron @@ -66,9 +66,9 @@ entry_point: "fs_main", ), targets: [ - ( + Some(( format: rgba8unorm, - ), + )), ], )), ), @@ -90,7 +90,7 @@ push_constant_data: [], ), target_colors: [ - ( + Some(( view: Id(0, 1, Empty), resolve_target: None, channel: ( @@ -104,7 +104,7 @@ ), read_only: false, ), - ), + )), ], target_depth_stencil: None, ), diff --git a/player/tests/data/zero-init-texture-rendertarget.ron b/player/tests/data/zero-init-texture-rendertarget.ron index 836198d790c..4239acc6aa1 100644 --- a/player/tests/data/zero-init-texture-rendertarget.ron +++ b/player/tests/data/zero-init-texture-rendertarget.ron @@ -46,7 +46,7 @@ push_constant_data: [], ), target_colors: [ - ( + Some(( view: Id(0, 1, Empty), resolve_target: None, channel: ( @@ -57,7 +57,7 @@ ), read_only: false, ), - ), + )), ], target_depth_stencil: None, ), diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 029d1d0fb23..148b2854c21 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -2760,30 +2760,23 @@ impl Device { if validated_stages.contains(wgt::ShaderStages::FRAGMENT) { for (i, output) in io.iter() { - match color_targets.get(*i as usize) { - Some(state) => { - let format = if let Some(st) = state.as_ref() { - st.format - } else { - return Err( - pipeline::CreateRenderPipelineError::InvalidFragmentOutputLocation( - *i, - ), - ); - }; - validation::check_texture_format(format, &output.ty).map_err( - |pipeline| { - pipeline::CreateRenderPipelineError::ColorState( - *i as u8, - pipeline::ColorStateError::IncompatibleFormat { - pipeline, - shader: output.ty, - }, - ) + if let Some(state) = color_targets.get(*i as usize) { + let format = if let Some(st) = state.as_ref() { + st.format + } else { + return Err( + pipeline::CreateRenderPipelineError::InvalidFragmentOutputLocation(*i), + ); + }; + validation::check_texture_format(format, &output.ty).map_err(|pipeline| { + pipeline::CreateRenderPipelineError::ColorState( + *i as u8, + pipeline::ColorStateError::IncompatibleFormat { + pipeline, + shader: output.ty, }, - )?; - } - None => (), + ) + })?; } } } diff --git a/wgpu-hal/src/metal/command.rs b/wgpu-hal/src/metal/command.rs index 589c60cc6ae..9231df93039 100644 --- a/wgpu-hal/src/metal/command.rs +++ b/wgpu-hal/src/metal/command.rs @@ -353,7 +353,7 @@ impl crate::CommandEncoder for super::CommandEncoder { //TODO: set visibility results buffer for (i, at) in desc.color_attachments.iter().enumerate() { - if let Some(at) = at { + if let Some(at) = at.as_ref() { let at_descriptor = descriptor.color_attachments().object_at(i as u64).unwrap(); at_descriptor.set_texture(Some(&at.target.view.raw)); if let Some(ref resolve) = at.resolve_target { diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 0a15e7b07b4..82567e67c00 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -108,11 +108,11 @@ impl super::DeviceShared { .build(); vk_attachments.push(vk_attachment); } else { - resolve_refs.push(unused.clone()); + resolve_refs.push(unused); }; } else { - color_refs.push(unused.clone()); - resolve_refs.push(unused.clone()); + color_refs.push(unused); + resolve_refs.push(unused); } }