@@ -1690,51 +1690,63 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1690
1690
& * image. raw
1691
1691
} ;
1692
1692
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 ) {
1695
1694
let attachment = descriptor
1696
1695
. color_attachments ( )
1697
1696
. object_at ( 0 )
1698
1697
. unwrap ( ) ;
1699
1698
attachment. set_texture ( Some ( texture) ) ;
1700
1699
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1701
- if clear_color_attachment {
1700
+ if sub . aspects . contains ( Aspects :: COLOR ) {
1702
1701
attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
1703
1702
attachment. set_clear_color ( clear_color. clone ( ) ) ;
1703
+ Some ( attachment)
1704
1704
} else {
1705
1705
attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
1706
+ None
1706
1707
}
1707
- }
1708
+ } else {
1709
+ assert ! ( !sub. aspects. contains( Aspects :: COLOR ) ) ;
1710
+ None
1711
+ } ;
1708
1712
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 ) {
1711
1714
let attachment = descriptor
1712
1715
. depth_attachment ( )
1713
1716
. unwrap ( ) ;
1714
1717
attachment. set_texture ( Some ( texture) ) ;
1715
1718
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1716
- if clear_depth_attachment {
1719
+ if sub . aspects . contains ( Aspects :: DEPTH ) {
1717
1720
attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
1718
1721
attachment. set_clear_depth ( depth_stencil. depth as _ ) ;
1722
+ Some ( attachment)
1719
1723
} else {
1720
1724
attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
1725
+ None
1721
1726
}
1722
- }
1727
+ } else {
1728
+ assert ! ( !sub. aspects. contains( Aspects :: DEPTH ) ) ;
1729
+ None
1730
+ } ;
1723
1731
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 ) {
1726
1733
let attachment = descriptor
1727
1734
. stencil_attachment ( )
1728
1735
. unwrap ( ) ;
1729
1736
attachment. set_texture ( Some ( texture) ) ;
1730
1737
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1731
- if clear_stencil_attachment {
1738
+ if sub . aspects . contains ( Aspects :: STENCIL ) {
1732
1739
attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
1733
1740
attachment. set_clear_stencil ( depth_stencil. stencil ) ;
1741
+ Some ( attachment)
1734
1742
} else {
1735
1743
attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
1744
+ None
1736
1745
}
1737
- }
1746
+ } else {
1747
+ assert ! ( !sub. aspects. contains( Aspects :: STENCIL ) ) ;
1748
+ None
1749
+ } ;
1738
1750
1739
1751
for layer in layers {
1740
1752
for level in sub. levels . clone ( ) {
@@ -1746,29 +1758,19 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1746
1758
descriptor. set_render_target_array_length ( num_layers) ;
1747
1759
} ;
1748
1760
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 {
1754
1762
attachment. set_level ( level as _ ) ;
1755
1763
if !CLEAR_IMAGE_ARRAY {
1756
1764
attachment. set_slice ( layer as _ ) ;
1757
1765
}
1758
1766
}
1759
- if clear_depth_attachment {
1760
- let attachment = descriptor
1761
- . depth_attachment ( )
1762
- . unwrap ( ) ;
1767
+ if let Some ( attachment) = depth_attachment {
1763
1768
attachment. set_level ( level as _ ) ;
1764
1769
if !CLEAR_IMAGE_ARRAY {
1765
1770
attachment. set_slice ( layer as _ ) ;
1766
1771
}
1767
1772
}
1768
- if clear_stencil_attachment {
1769
- let attachment = descriptor
1770
- . stencil_attachment ( )
1771
- . unwrap ( ) ;
1773
+ if let Some ( attachment) = stencil_attachment {
1772
1774
attachment. set_level ( level as _ ) ;
1773
1775
if !CLEAR_IMAGE_ARRAY {
1774
1776
attachment. set_slice ( layer as _ ) ;
0 commit comments