Skip to content

Commit a275491

Browse files
committed
[mtl] cache attachments in clear_image
1 parent b2dc191 commit a275491

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

src/backend/metal/src/command.rs

+27-25
Original file line numberDiff line numberDiff line change
@@ -1690,51 +1690,63 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
16901690
&*image.raw
16911691
};
16921692

1693-
let clear_color_attachment = sub.aspects.contains(Aspects::COLOR);
1694-
if image.format_desc.aspects.contains(Aspects::COLOR) {
1693+
let color_attachment = if image.format_desc.aspects.contains(Aspects::COLOR) {
16951694
let attachment = descriptor
16961695
.color_attachments()
16971696
.object_at(0)
16981697
.unwrap();
16991698
attachment.set_texture(Some(texture));
17001699
attachment.set_store_action(metal::MTLStoreAction::Store);
1701-
if clear_color_attachment {
1700+
if sub.aspects.contains(Aspects::COLOR) {
17021701
attachment.set_load_action(metal::MTLLoadAction::Clear);
17031702
attachment.set_clear_color(clear_color.clone());
1703+
Some(attachment)
17041704
} else {
17051705
attachment.set_load_action(metal::MTLLoadAction::Load);
1706+
None
17061707
}
1707-
}
1708+
} else {
1709+
assert!(!sub.aspects.contains(Aspects::COLOR));
1710+
None
1711+
};
17081712

1709-
let clear_depth_attachment = sub.aspects.contains(Aspects::DEPTH);
1710-
if image.format_desc.aspects.contains(Aspects::DEPTH) {
1713+
let depth_attachment = if image.format_desc.aspects.contains(Aspects::DEPTH) {
17111714
let attachment = descriptor
17121715
.depth_attachment()
17131716
.unwrap();
17141717
attachment.set_texture(Some(texture));
17151718
attachment.set_store_action(metal::MTLStoreAction::Store);
1716-
if clear_depth_attachment {
1719+
if sub.aspects.contains(Aspects::DEPTH) {
17171720
attachment.set_load_action(metal::MTLLoadAction::Clear);
17181721
attachment.set_clear_depth(depth_stencil.depth as _);
1722+
Some(attachment)
17191723
} else {
17201724
attachment.set_load_action(metal::MTLLoadAction::Load);
1725+
None
17211726
}
1722-
}
1727+
} else {
1728+
assert!(!sub.aspects.contains(Aspects::DEPTH));
1729+
None
1730+
};
17231731

1724-
let clear_stencil_attachment = sub.aspects.contains(Aspects::STENCIL);
1725-
if image.format_desc.aspects.contains(Aspects::STENCIL) {
1732+
let stencil_attachment = if image.format_desc.aspects.contains(Aspects::STENCIL) {
17261733
let attachment = descriptor
17271734
.stencil_attachment()
17281735
.unwrap();
17291736
attachment.set_texture(Some(texture));
17301737
attachment.set_store_action(metal::MTLStoreAction::Store);
1731-
if clear_stencil_attachment {
1738+
if sub.aspects.contains(Aspects::STENCIL) {
17321739
attachment.set_load_action(metal::MTLLoadAction::Clear);
17331740
attachment.set_clear_stencil(depth_stencil.stencil);
1741+
Some(attachment)
17341742
} else {
17351743
attachment.set_load_action(metal::MTLLoadAction::Load);
1744+
None
17361745
}
1737-
}
1746+
} else {
1747+
assert!(!sub.aspects.contains(Aspects::STENCIL));
1748+
None
1749+
};
17381750

17391751
for layer in layers {
17401752
for level in sub.levels.clone() {
@@ -1746,29 +1758,19 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
17461758
descriptor.set_render_target_array_length(num_layers);
17471759
};
17481760

1749-
if clear_color_attachment {
1750-
let attachment = descriptor
1751-
.color_attachments()
1752-
.object_at(0)
1753-
.unwrap();
1761+
if let Some(attachment) = color_attachment {
17541762
attachment.set_level(level as _);
17551763
if !CLEAR_IMAGE_ARRAY {
17561764
attachment.set_slice(layer as _);
17571765
}
17581766
}
1759-
if clear_depth_attachment {
1760-
let attachment = descriptor
1761-
.depth_attachment()
1762-
.unwrap();
1767+
if let Some(attachment) = depth_attachment {
17631768
attachment.set_level(level as _);
17641769
if !CLEAR_IMAGE_ARRAY {
17651770
attachment.set_slice(layer as _);
17661771
}
17671772
}
1768-
if clear_stencil_attachment {
1769-
let attachment = descriptor
1770-
.stencil_attachment()
1771-
.unwrap();
1773+
if let Some(attachment) = stencil_attachment {
17721774
attachment.set_level(level as _);
17731775
if !CLEAR_IMAGE_ARRAY {
17741776
attachment.set_slice(layer as _);

0 commit comments

Comments
 (0)