mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
[core] Allow depthClearValue to be empty (#6753)
This commit is contained in:
parent
0d927c244f
commit
f6fec82853
@ -157,13 +157,13 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
|
|||||||
depth: wgpu_core::command::PassChannel {
|
depth: wgpu_core::command::PassChannel {
|
||||||
load_op: attachment.depth_load_op,
|
load_op: attachment.depth_load_op,
|
||||||
store_op: attachment.depth_store_op,
|
store_op: attachment.depth_store_op,
|
||||||
clear_value: attachment.depth_clear_value,
|
clear_value: Some(attachment.depth_clear_value),
|
||||||
read_only: attachment.depth_read_only,
|
read_only: attachment.depth_read_only,
|
||||||
},
|
},
|
||||||
stencil: wgpu_core::command::PassChannel {
|
stencil: wgpu_core::command::PassChannel {
|
||||||
load_op: attachment.stencil_load_op,
|
load_op: attachment.stencil_load_op,
|
||||||
store_op: attachment.stencil_store_op,
|
store_op: attachment.stencil_store_op,
|
||||||
clear_value: attachment.stencil_clear_value,
|
clear_value: Some(attachment.stencil_clear_value),
|
||||||
read_only: attachment.stencil_read_only,
|
read_only: attachment.stencil_read_only,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -137,7 +137,7 @@ impl<V: Default> Default for PassChannel<V, LoadOp, StoreOp> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: Copy> PassChannel<V, Option<LoadOp>, Option<StoreOp>> {
|
impl<V: Copy + Default> PassChannel<Option<V>, Option<LoadOp>, Option<StoreOp>> {
|
||||||
fn resolve(&self) -> Result<PassChannel<V, LoadOp, StoreOp>, AttachmentError> {
|
fn resolve(&self) -> Result<PassChannel<V, LoadOp, StoreOp>, AttachmentError> {
|
||||||
let load_op = if self.read_only {
|
let load_op = if self.read_only {
|
||||||
if self.load_op.is_some() {
|
if self.load_op.is_some() {
|
||||||
@ -160,7 +160,7 @@ impl<V: Copy> PassChannel<V, Option<LoadOp>, Option<StoreOp>> {
|
|||||||
Ok(PassChannel {
|
Ok(PassChannel {
|
||||||
load_op,
|
load_op,
|
||||||
store_op,
|
store_op,
|
||||||
clear_value: self.clear_value,
|
clear_value: self.clear_value.unwrap_or_default(),
|
||||||
read_only: self.read_only,
|
read_only: self.read_only,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -216,10 +216,11 @@ pub struct RenderPassDepthStencilAttachment {
|
|||||||
/// The view to use as an attachment.
|
/// The view to use as an attachment.
|
||||||
pub view: id::TextureViewId,
|
pub view: id::TextureViewId,
|
||||||
/// What operations will be performed on the depth part of the attachment.
|
/// What operations will be performed on the depth part of the attachment.
|
||||||
pub depth: PassChannel<f32, Option<LoadOp>, Option<StoreOp>>,
|
pub depth: PassChannel<Option<f32>, Option<LoadOp>, Option<StoreOp>>,
|
||||||
/// What operations will be performed on the stencil part of the attachment.
|
/// What operations will be performed on the stencil part of the attachment.
|
||||||
pub stencil: PassChannel<u32, Option<LoadOp>, Option<StoreOp>>,
|
pub stencil: PassChannel<Option<u32>, Option<LoadOp>, Option<StoreOp>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describes a depth/stencil attachment to a render pass.
|
/// Describes a depth/stencil attachment to a render pass.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ArcRenderPassDepthStencilAttachment {
|
pub struct ArcRenderPassDepthStencilAttachment {
|
||||||
@ -649,6 +650,10 @@ pub enum AttachmentError {
|
|||||||
NoLoad,
|
NoLoad,
|
||||||
#[error("Attachment without store")]
|
#[error("Attachment without store")]
|
||||||
NoStore,
|
NoStore,
|
||||||
|
#[error("LoadOp is `Clear` but no clear value was provided")]
|
||||||
|
NoClearValue,
|
||||||
|
#[error("Clear value ({0}) must be between 0.0 and 1.0, inclusive")]
|
||||||
|
ClearValueOutOfRange(f32),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error encountered when performing a render pass.
|
/// Error encountered when performing a render pass.
|
||||||
@ -1473,6 +1478,17 @@ impl Global {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this.depthLoadOp is "clear", this.depthClearValue must be provided and must be between 0.0 and 1.0, inclusive.
|
||||||
|
if depth_stencil_attachment.depth.load_op == Some(LoadOp::Clear) {
|
||||||
|
if let Some(clear_value) = depth_stencil_attachment.depth.clear_value {
|
||||||
|
if !(0.0..=1.0).contains(&clear_value) {
|
||||||
|
return Err(CommandEncoderError::InvalidAttachment(AttachmentError::ClearValueOutOfRange(clear_value)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(CommandEncoderError::InvalidAttachment(AttachmentError::NoClearValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Some(ArcRenderPassDepthStencilAttachment {
|
Some(ArcRenderPassDepthStencilAttachment {
|
||||||
view,
|
view,
|
||||||
depth: if format.has_depth_aspect() {
|
depth: if format.has_depth_aspect() {
|
||||||
|
|||||||
@ -404,16 +404,14 @@ fn map_store_op(op: StoreOp) -> wgc::command::StoreOp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_load_op<V: Default>(op: LoadOp<V>) -> (wgc::command::LoadOp, V) {
|
fn map_load_op<V>(op: LoadOp<V>) -> (wgc::command::LoadOp, Option<V>) {
|
||||||
match op {
|
match op {
|
||||||
LoadOp::Clear(v) => (wgc::command::LoadOp::Clear, v),
|
LoadOp::Clear(v) => (wgc::command::LoadOp::Clear, Some(v)),
|
||||||
LoadOp::Load => (wgc::command::LoadOp::Load, V::default()),
|
LoadOp::Load => (wgc::command::LoadOp::Load, None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_pass_channel<V: Copy + Default>(
|
fn map_pass_channel<V: Copy>(ops: Option<&Operations<V>>) -> wgc::command::PassChannel<Option<V>> {
|
||||||
ops: Option<&Operations<V>>,
|
|
||||||
) -> wgc::command::PassChannel<V> {
|
|
||||||
match ops {
|
match ops {
|
||||||
Some(&Operations { load, store }) => {
|
Some(&Operations { load, store }) => {
|
||||||
let (load_op, clear_value) = map_load_op(load);
|
let (load_op, clear_value) = map_load_op(load);
|
||||||
@ -427,7 +425,7 @@ fn map_pass_channel<V: Copy + Default>(
|
|||||||
None => wgc::command::PassChannel {
|
None => wgc::command::PassChannel {
|
||||||
load_op: None,
|
load_op: None,
|
||||||
store_op: None,
|
store_op: None,
|
||||||
clear_value: V::default(),
|
clear_value: None,
|
||||||
read_only: true,
|
read_only: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -2254,7 +2252,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder {
|
|||||||
resolve_target: at.resolve_target.map(|view| view.inner.as_core().id),
|
resolve_target: at.resolve_target.map(|view| view.inner.as_core().id),
|
||||||
load_op,
|
load_op,
|
||||||
store_op: map_store_op(at.ops.store),
|
store_op: map_store_op(at.ops.store),
|
||||||
clear_value,
|
clear_value: clear_value.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user