@@ -821,11 +821,11 @@ impl CommandSink {
821
821
) where
822
822
I : Iterator < Item = soft:: RenderCommand < & ' a soft:: Own > > ,
823
823
{
824
+ //assert!(AutoReleasePool::is_active());
824
825
self . stop_encoding ( ) ;
825
826
826
827
match * self {
827
828
CommandSink :: Immediate { ref cmd_buffer, ref mut encoder_state, .. } => {
828
- let _ap = AutoreleasePool :: new ( ) ;
829
829
let encoder = cmd_buffer. new_render_command_encoder ( descriptor) ;
830
830
for command in init_commands {
831
831
exec_render ( encoder, command) ;
@@ -1446,7 +1446,7 @@ impl pool::RawCommandPool<Backend> for CommandPool {
1446
1446
framebuffer_inner : native:: FramebufferInner {
1447
1447
extent : Extent :: default ( ) ,
1448
1448
aspects : Aspects :: empty ( ) ,
1449
- colors : Vec :: new ( ) ,
1449
+ colors : SmallVec :: new ( ) ,
1450
1450
depth_stencil : None ,
1451
1451
}
1452
1452
} ,
@@ -1653,6 +1653,8 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1653
1653
T : IntoIterator ,
1654
1654
T :: Item : Borrow < SubresourceRange > ,
1655
1655
{
1656
+ let _ap = AutoreleasePool :: new ( ) ;
1657
+
1656
1658
let CommandBufferInner {
1657
1659
ref mut retained_textures,
1658
1660
ref mut sink,
@@ -1690,51 +1692,63 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1690
1692
& * image. raw
1691
1693
} ;
1692
1694
1693
- let clear_color_attachment = sub. aspects . contains ( Aspects :: COLOR ) ;
1694
- if image. format_desc . aspects . contains ( Aspects :: COLOR ) {
1695
+ let color_attachment = if image. format_desc . aspects . contains ( Aspects :: COLOR ) {
1695
1696
let attachment = descriptor
1696
1697
. color_attachments ( )
1697
1698
. object_at ( 0 )
1698
1699
. unwrap ( ) ;
1699
1700
attachment. set_texture ( Some ( texture) ) ;
1700
1701
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1701
- if clear_color_attachment {
1702
+ if sub . aspects . contains ( Aspects :: COLOR ) {
1702
1703
attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
1703
1704
attachment. set_clear_color ( clear_color. clone ( ) ) ;
1705
+ Some ( attachment)
1704
1706
} else {
1705
1707
attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
1708
+ None
1706
1709
}
1707
- }
1710
+ } else {
1711
+ assert ! ( !sub. aspects. contains( Aspects :: COLOR ) ) ;
1712
+ None
1713
+ } ;
1708
1714
1709
- let clear_depth_attachment = sub. aspects . contains ( Aspects :: DEPTH ) ;
1710
- if image. format_desc . aspects . contains ( Aspects :: DEPTH ) {
1715
+ let depth_attachment = if image. format_desc . aspects . contains ( Aspects :: DEPTH ) {
1711
1716
let attachment = descriptor
1712
1717
. depth_attachment ( )
1713
1718
. unwrap ( ) ;
1714
1719
attachment. set_texture ( Some ( texture) ) ;
1715
1720
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1716
- if clear_depth_attachment {
1721
+ if sub . aspects . contains ( Aspects :: DEPTH ) {
1717
1722
attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
1718
1723
attachment. set_clear_depth ( depth_stencil. depth as _ ) ;
1724
+ Some ( attachment)
1719
1725
} else {
1720
1726
attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
1727
+ None
1721
1728
}
1722
- }
1729
+ } else {
1730
+ assert ! ( !sub. aspects. contains( Aspects :: DEPTH ) ) ;
1731
+ None
1732
+ } ;
1723
1733
1724
- let clear_stencil_attachment = sub. aspects . contains ( Aspects :: STENCIL ) ;
1725
- if image. format_desc . aspects . contains ( Aspects :: STENCIL ) {
1734
+ let stencil_attachment = if image. format_desc . aspects . contains ( Aspects :: STENCIL ) {
1726
1735
let attachment = descriptor
1727
1736
. stencil_attachment ( )
1728
1737
. unwrap ( ) ;
1729
1738
attachment. set_texture ( Some ( texture) ) ;
1730
1739
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1731
- if clear_stencil_attachment {
1740
+ if sub . aspects . contains ( Aspects :: STENCIL ) {
1732
1741
attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
1733
1742
attachment. set_clear_stencil ( depth_stencil. stencil ) ;
1743
+ Some ( attachment)
1734
1744
} else {
1735
1745
attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
1746
+ None
1736
1747
}
1737
- }
1748
+ } else {
1749
+ assert ! ( !sub. aspects. contains( Aspects :: STENCIL ) ) ;
1750
+ None
1751
+ } ;
1738
1752
1739
1753
for layer in layers {
1740
1754
for level in sub. levels . clone ( ) {
@@ -1746,29 +1760,19 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1746
1760
descriptor. set_render_target_array_length ( num_layers) ;
1747
1761
} ;
1748
1762
1749
- if clear_color_attachment {
1750
- let attachment = descriptor
1751
- . color_attachments ( )
1752
- . object_at ( 0 )
1753
- . unwrap ( ) ;
1763
+ if let Some ( attachment) = color_attachment {
1754
1764
attachment. set_level ( level as _ ) ;
1755
1765
if !CLEAR_IMAGE_ARRAY {
1756
1766
attachment. set_slice ( layer as _ ) ;
1757
1767
}
1758
1768
}
1759
- if clear_depth_attachment {
1760
- let attachment = descriptor
1761
- . depth_attachment ( )
1762
- . unwrap ( ) ;
1769
+ if let Some ( attachment) = depth_attachment {
1763
1770
attachment. set_level ( level as _ ) ;
1764
1771
if !CLEAR_IMAGE_ARRAY {
1765
1772
attachment. set_slice ( layer as _ ) ;
1766
1773
}
1767
1774
}
1768
- if clear_stencil_attachment {
1769
- let attachment = descriptor
1770
- . stencil_attachment ( )
1771
- . unwrap ( ) ;
1775
+ if let Some ( attachment) = stencil_attachment {
1772
1776
attachment. set_level ( level as _ ) ;
1773
1777
if !CLEAR_IMAGE_ARRAY {
1774
1778
attachment. set_slice ( layer as _ ) ;
@@ -2015,6 +2019,8 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2015
2019
T : IntoIterator ,
2016
2020
T :: Item : Borrow < com:: ImageBlit >
2017
2021
{
2022
+ let _ap = AutoreleasePool :: new ( ) ;
2023
+
2018
2024
let vertices = & mut self . temp . blit_vertices ;
2019
2025
vertices. clear ( ) ;
2020
2026
@@ -2218,7 +2224,9 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2218
2224
. chain ( & extra)
2219
2225
. cloned ( ) ;
2220
2226
2221
- inner. sink ( ) . begin_render_pass ( false , & descriptor, commands) ;
2227
+ inner
2228
+ . sink ( )
2229
+ . begin_render_pass ( false , & descriptor, commands) ;
2222
2230
}
2223
2231
}
2224
2232
@@ -2233,13 +2241,26 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2233
2241
} ) ;
2234
2242
}
2235
2243
2236
- fn bind_vertex_buffers ( & mut self , first_binding : u32 , buffer_set : pso:: VertexBufferSet < Backend > ) {
2237
- while self . state . vertex_buffers . len ( ) < first_binding as usize + buffer_set. 0 . len ( ) {
2238
- self . state . vertex_buffers . push ( None ) ;
2239
- }
2240
- for ( i, & ( buffer, offset) ) in buffer_set. 0 . iter ( ) . enumerate ( ) {
2241
- let buffer_ptr = BufferPtr ( buffer. raw . as_ptr ( ) ) ;
2242
- self . state . vertex_buffers [ first_binding as usize + i] = Some ( ( buffer_ptr, buffer. range . start + offset) ) ;
2244
+
2245
+ fn bind_vertex_buffers < I , T > ( & mut self , first_binding : u32 , buffers : I )
2246
+ where
2247
+ I : IntoIterator < Item = ( T , buffer:: Offset ) > ,
2248
+ T : Borrow < native:: Buffer > ,
2249
+ {
2250
+ if self . state . vertex_buffers . len ( ) <= first_binding as usize {
2251
+ self . state . vertex_buffers . resize ( first_binding as usize + 1 , None ) ;
2252
+ }
2253
+ for ( i, ( buffer, offset) ) in buffers. into_iter ( ) . enumerate ( ) {
2254
+ let b = buffer. borrow ( ) ;
2255
+ let buffer_ptr = BufferPtr ( b. raw . as_ptr ( ) ) ;
2256
+ let index = first_binding as usize + i;
2257
+ let value = Some ( ( buffer_ptr, b. range . start + offset) ) ;
2258
+ if index >= self . state . vertex_buffers . len ( ) {
2259
+ debug_assert_eq ! ( index, self . state. vertex_buffers. len( ) ) ;
2260
+ self . state . vertex_buffers . push ( value) ;
2261
+ } else {
2262
+ self . state . vertex_buffers [ index] = value;
2263
+ }
2243
2264
}
2244
2265
2245
2266
let mask = self . state . set_vertex_buffers ( ) ;
0 commit comments