Skip to content

Commit 0477714

Browse files
committed
LoadOp::DontCare
1 parent b599252 commit 0477714

File tree

14 files changed

+126
-33
lines changed

14 files changed

+126
-33
lines changed

wgpu-core/src/command/clear.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ fn clear_texture_via_render_passes(
498498
},
499499
depth_slice: None,
500500
resolve_target: None,
501-
ops: hal::AttachmentOps::STORE,
501+
ops: hal::AttachmentOps::STORE | hal::AttachmentOps::LOAD_CLEAR,
502502
clear_value: wgt::Color::TRANSPARENT,
503503
})];
504504
(&color_attachments_tmp[..], None)
@@ -515,8 +515,8 @@ fn clear_texture_via_render_passes(
515515
),
516516
usage: wgt::TextureUses::DEPTH_STENCIL_WRITE,
517517
},
518-
depth_ops: hal::AttachmentOps::STORE,
519-
stencil_ops: hal::AttachmentOps::STORE,
518+
depth_ops: hal::AttachmentOps::STORE | hal::AttachmentOps::LOAD_CLEAR,
519+
stencil_ops: hal::AttachmentOps::STORE | hal::AttachmentOps::LOAD_CLEAR,
520520
clear_value: (0.0, 0),
521521
}),
522522
)

wgpu-core/src/command/render.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ pub use wgt::{LoadOp, StoreOp};
6565
fn load_hal_ops<V>(load: LoadOp<V>) -> hal::AttachmentOps {
6666
match load {
6767
LoadOp::Load => hal::AttachmentOps::LOAD,
68-
LoadOp::Clear(_) => hal::AttachmentOps::empty(),
68+
LoadOp::Clear(_) => hal::AttachmentOps::LOAD_CLEAR,
69+
LoadOp::DontCare(_) => hal::AttachmentOps::LOAD_DONT_CARE,
6970
}
7071
}
7172

7273
fn store_hal_ops(store: StoreOp) -> hal::AttachmentOps {
7374
match store {
7475
StoreOp::Store => hal::AttachmentOps::STORE,
75-
StoreOp::Discard => hal::AttachmentOps::empty(),
76+
StoreOp::Discard => hal::AttachmentOps::STORE_DISCARD,
7677
}
7778
}
7879

@@ -115,6 +116,7 @@ impl<V: Copy + Default> PassChannel<Option<V>> {
115116
Ok(ResolvedPassChannel::Operational(wgt::Operations {
116117
load: match self.load_op.ok_or(AttachmentError::NoLoad)? {
117118
LoadOp::Clear(clear_value) => LoadOp::Clear(handle_clear(clear_value)?),
119+
LoadOp::DontCare(token) => LoadOp::DontCare(token),
118120
LoadOp::Load => LoadOp::Load,
119121
},
120122
store: self.store_op.ok_or(AttachmentError::NoStore)?,
@@ -204,7 +206,7 @@ impl ArcRenderPassColorAttachment {
204206
fn clear_value(&self) -> Color {
205207
match self.load_op {
206208
LoadOp::Clear(clear_value) => clear_value,
207-
LoadOp::Load => Color::default(),
209+
LoadOp::DontCare(_) | LoadOp::Load => Color::default(),
208210
}
209211
}
210212
}
@@ -1555,13 +1557,13 @@ impl RenderPassInfo {
15551557
if let Some((aspect, view)) = self.divergent_discarded_depth_stencil_aspect {
15561558
let (depth_ops, stencil_ops) = if aspect == wgt::TextureAspect::DepthOnly {
15571559
(
1558-
hal::AttachmentOps::STORE, // clear depth
1559-
hal::AttachmentOps::LOAD | hal::AttachmentOps::STORE, // unchanged stencil
1560+
hal::AttachmentOps::LOAD_CLEAR | hal::AttachmentOps::STORE, // clear depth
1561+
hal::AttachmentOps::LOAD | hal::AttachmentOps::STORE, // unchanged stencil
15601562
)
15611563
} else {
15621564
(
15631565
hal::AttachmentOps::LOAD | hal::AttachmentOps::STORE, // unchanged stencil
1564-
hal::AttachmentOps::STORE, // clear depth
1566+
hal::AttachmentOps::LOAD_CLEAR | hal::AttachmentOps::STORE, // clear depth
15651567
)
15661568
};
15671569
let desc = hal::RenderPassDescriptor::<'_, _, dyn hal::DynTextureView> {

wgpu-hal/examples/halmark/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ impl<A: hal::Api> Example<A> {
718718
},
719719
depth_slice: None,
720720
resolve_target: None,
721-
ops: hal::AttachmentOps::STORE,
721+
ops: hal::AttachmentOps::STORE | hal::AttachmentOps::LOAD_CLEAR,
722722
clear_value: wgpu_types::Color {
723723
r: 0.1,
724724
g: 0.2,

wgpu-hal/examples/raw-gles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn fill_screen(exposed: &hal::ExposedAdapter<hal::api::Gles>, width: u32, height
325325
},
326326
depth_slice: None,
327327
resolve_target: None,
328-
ops: hal::AttachmentOps::STORE,
328+
ops: hal::AttachmentOps::STORE | hal::AttachmentOps::LOAD_CLEAR,
329329
clear_value: wgpu_types::Color::BLUE,
330330
})],
331331
depth_stencil_attachment: None,

wgpu-hal/src/dx12/command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
964964
self.pass.resolves.clear();
965965
for (rtv, cat) in color_views.iter().zip(desc.color_attachments.iter()) {
966966
if let Some(cat) = cat.as_ref() {
967-
if !cat.ops.contains(crate::AttachmentOps::LOAD) {
967+
if cat.ops.contains(crate::AttachmentOps::LOAD_CLEAR) {
968968
let value = [
969969
cat.clear_value.r as f32,
970970
cat.clear_value.g as f32,
@@ -989,12 +989,12 @@ impl crate::CommandEncoder for super::CommandEncoder {
989989
if let Some(ref ds) = desc.depth_stencil_attachment {
990990
let mut flags = Direct3D12::D3D12_CLEAR_FLAGS::default();
991991
let aspects = ds.target.view.aspects;
992-
if !ds.depth_ops.contains(crate::AttachmentOps::LOAD)
992+
if ds.depth_ops.contains(crate::AttachmentOps::LOAD_CLEAR)
993993
&& aspects.contains(crate::FormatAspects::DEPTH)
994994
{
995995
flags |= Direct3D12::D3D12_CLEAR_FLAG_DEPTH;
996996
}
997-
if !ds.stencil_ops.contains(crate::AttachmentOps::LOAD)
997+
if ds.stencil_ops.contains(crate::AttachmentOps::LOAD_CLEAR)
998998
&& aspects.contains(crate::FormatAspects::STENCIL)
999999
{
10001000
flags |= Direct3D12::D3D12_CLEAR_FLAG_STENCIL;

wgpu-hal/src/gles/command.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
567567
.resolve_attachments
568568
.push((attachment, rat.view.clone()));
569569
}
570-
if !cat.ops.contains(crate::AttachmentOps::STORE) {
570+
if cat.ops.contains(crate::AttachmentOps::STORE_DISCARD) {
571571
self.state.invalidate_attachments.push(attachment);
572572
}
573573
}
@@ -585,14 +585,16 @@ impl crate::CommandEncoder for super::CommandEncoder {
585585
depth_slice: None,
586586
});
587587
if aspects.contains(crate::FormatAspects::DEPTH)
588-
&& !dsat.depth_ops.contains(crate::AttachmentOps::STORE)
588+
&& dsat.depth_ops.contains(crate::AttachmentOps::STORE_DISCARD)
589589
{
590590
self.state
591591
.invalidate_attachments
592592
.push(glow::DEPTH_ATTACHMENT);
593593
}
594594
if aspects.contains(crate::FormatAspects::STENCIL)
595-
&& !dsat.stencil_ops.contains(crate::AttachmentOps::STORE)
595+
&& dsat
596+
.stencil_ops
597+
.contains(crate::AttachmentOps::STORE_DISCARD)
596598
{
597599
self.state
598600
.invalidate_attachments
@@ -628,7 +630,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
628630
.filter_map(|at| at.as_ref())
629631
.enumerate()
630632
{
631-
if !cat.ops.contains(crate::AttachmentOps::LOAD) {
633+
if cat.ops.contains(crate::AttachmentOps::LOAD_CLEAR) {
632634
let c = &cat.clear_value;
633635
self.cmd_buffer.commands.push(
634636
match cat.target.view.format.sample_type(None, None).unwrap() {
@@ -652,8 +654,8 @@ impl crate::CommandEncoder for super::CommandEncoder {
652654
}
653655

654656
if let Some(ref dsat) = desc.depth_stencil_attachment {
655-
let clear_depth = !dsat.depth_ops.contains(crate::AttachmentOps::LOAD);
656-
let clear_stencil = !dsat.stencil_ops.contains(crate::AttachmentOps::LOAD);
657+
let clear_depth = dsat.depth_ops.contains(crate::AttachmentOps::LOAD_CLEAR);
658+
let clear_stencil = dsat.stencil_ops.contains(crate::AttachmentOps::LOAD_CLEAR);
657659

658660
if clear_depth && clear_stencil {
659661
self.cmd_buffer.commands.push(C::ClearDepthAndStencil(

wgpu-hal/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,10 @@ bitflags!(
17571757
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
17581758
pub struct AttachmentOps: u8 {
17591759
const LOAD = 1 << 0;
1760-
const STORE = 1 << 1;
1760+
const LOAD_CLEAR = 1 << 1;
1761+
const LOAD_DONT_CARE = 1 << 2;
1762+
const STORE = 1 << 3;
1763+
const STORE_DISCARD = 1 << 4;
17611764
}
17621765
);
17631766

wgpu-hal/src/metal/command.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,13 @@ impl crate::CommandEncoder for super::CommandEncoder {
670670
}
671671
let load_action = if at.ops.contains(crate::AttachmentOps::LOAD) {
672672
MTLLoadAction::Load
673-
} else {
673+
} else if at.ops.contains(crate::AttachmentOps::LOAD_DONT_CARE) {
674+
MTLLoadAction::DontCare
675+
} else if at.ops.contains(crate::AttachmentOps::LOAD_CLEAR) {
674676
at_descriptor.set_clear_color(conv::map_clear_color(&at.clear_value));
675677
MTLLoadAction::Clear
678+
} else {
679+
unreachable!()
676680
};
677681
let store_action = conv::map_store_action(
678682
at.ops.contains(crate::AttachmentOps::STORE),
@@ -690,9 +694,13 @@ impl crate::CommandEncoder for super::CommandEncoder {
690694

691695
let load_action = if at.depth_ops.contains(crate::AttachmentOps::LOAD) {
692696
MTLLoadAction::Load
693-
} else {
697+
} else if at.depth_ops.contains(crate::AttachmentOps::LOAD_DONT_CARE) {
698+
MTLLoadAction::DontCare
699+
} else if at.depth_ops.contains(crate::AttachmentOps::LOAD_CLEAR) {
694700
at_descriptor.set_clear_depth(at.clear_value.0 as f64);
695701
MTLLoadAction::Clear
702+
} else {
703+
unreachable!();
696704
};
697705
let store_action = if at.depth_ops.contains(crate::AttachmentOps::STORE) {
698706
MTLStoreAction::Store
@@ -713,9 +721,16 @@ impl crate::CommandEncoder for super::CommandEncoder {
713721

714722
let load_action = if at.stencil_ops.contains(crate::AttachmentOps::LOAD) {
715723
MTLLoadAction::Load
716-
} else {
724+
} else if at
725+
.stencil_ops
726+
.contains(crate::AttachmentOps::LOAD_DONT_CARE)
727+
{
728+
MTLLoadAction::DontCare
729+
} else if at.stencil_ops.contains(crate::AttachmentOps::LOAD_CLEAR) {
717730
at_descriptor.set_clear_stencil(at.clear_value.1);
718731
MTLLoadAction::Clear
732+
} else {
733+
unreachable!()
719734
};
720735
let store_action = if at.stencil_ops.contains(crate::AttachmentOps::STORE) {
721736
MTLStoreAction::Store

wgpu-hal/src/vulkan/command.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,11 @@ impl crate::CommandEncoder for super::CommandEncoder {
813813
});
814814
let color = super::ColorAttachmentKey {
815815
base: cat.target.make_attachment_key(cat.ops),
816-
resolve: cat
817-
.resolve_target
818-
.as_ref()
819-
.map(|target| target.make_attachment_key(crate::AttachmentOps::STORE)),
816+
resolve: cat.resolve_target.as_ref().map(|target| {
817+
target.make_attachment_key(
818+
crate::AttachmentOps::LOAD_CLEAR | crate::AttachmentOps::STORE,
819+
)
820+
}),
820821
};
821822

822823
rp_key.colors.push(Some(color));

wgpu-hal/src/vulkan/conv.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,19 @@ pub fn map_attachment_ops(
452452
) -> (vk::AttachmentLoadOp, vk::AttachmentStoreOp) {
453453
let load_op = if op.contains(crate::AttachmentOps::LOAD) {
454454
vk::AttachmentLoadOp::LOAD
455-
} else {
455+
} else if op.contains(crate::AttachmentOps::LOAD_DONT_CARE) {
456+
vk::AttachmentLoadOp::DONT_CARE
457+
} else if op.contains(crate::AttachmentOps::LOAD_CLEAR) {
456458
vk::AttachmentLoadOp::CLEAR
459+
} else {
460+
unreachable!()
457461
};
458462
let store_op = if op.contains(crate::AttachmentOps::STORE) {
459463
vk::AttachmentStoreOp::STORE
460-
} else {
464+
} else if op.contains(crate::AttachmentOps::STORE_DISCARD) {
461465
vk::AttachmentStoreOp::DONT_CARE
466+
} else {
467+
unreachable!()
462468
};
463469
(load_op, store_op)
464470
}

0 commit comments

Comments
 (0)