@@ -821,11 +821,11 @@ impl CommandSink {
821821 ) where
822822 I : Iterator < Item = soft:: RenderCommand < & ' a soft:: Own > > ,
823823 {
824+ //assert!(AutoReleasePool::is_active());
824825 self . stop_encoding ( ) ;
825826
826827 match * self {
827828 CommandSink :: Immediate { ref cmd_buffer, ref mut encoder_state, .. } => {
828- let _ap = AutoreleasePool :: new ( ) ;
829829 let encoder = cmd_buffer. new_render_command_encoder ( descriptor) ;
830830 for command in init_commands {
831831 exec_render ( encoder, command) ;
@@ -1446,7 +1446,7 @@ impl pool::RawCommandPool<Backend> for CommandPool {
14461446 framebuffer_inner : native:: FramebufferInner {
14471447 extent : Extent :: default ( ) ,
14481448 aspects : Aspects :: empty ( ) ,
1449- colors : Vec :: new ( ) ,
1449+ colors : SmallVec :: new ( ) ,
14501450 depth_stencil : None ,
14511451 }
14521452 } ,
@@ -1653,6 +1653,8 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
16531653 T : IntoIterator ,
16541654 T :: Item : Borrow < SubresourceRange > ,
16551655 {
1656+ let _ap = AutoreleasePool :: new ( ) ;
1657+
16561658 let CommandBufferInner {
16571659 ref mut retained_textures,
16581660 ref mut sink,
@@ -1690,51 +1692,63 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
16901692 & * image. raw
16911693 } ;
16921694
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 ) {
16951696 let attachment = descriptor
16961697 . color_attachments ( )
16971698 . object_at ( 0 )
16981699 . unwrap ( ) ;
16991700 attachment. set_texture ( Some ( texture) ) ;
17001701 attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1701- if clear_color_attachment {
1702+ if sub . aspects . contains ( Aspects :: COLOR ) {
17021703 attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
17031704 attachment. set_clear_color ( clear_color. clone ( ) ) ;
1705+ Some ( attachment)
17041706 } else {
17051707 attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
1708+ None
17061709 }
1707- }
1710+ } else {
1711+ assert ! ( !sub. aspects. contains( Aspects :: COLOR ) ) ;
1712+ None
1713+ } ;
17081714
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 ) {
17111716 let attachment = descriptor
17121717 . depth_attachment ( )
17131718 . unwrap ( ) ;
17141719 attachment. set_texture ( Some ( texture) ) ;
17151720 attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1716- if clear_depth_attachment {
1721+ if sub . aspects . contains ( Aspects :: DEPTH ) {
17171722 attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
17181723 attachment. set_clear_depth ( depth_stencil. depth as _ ) ;
1724+ Some ( attachment)
17191725 } else {
17201726 attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
1727+ None
17211728 }
1722- }
1729+ } else {
1730+ assert ! ( !sub. aspects. contains( Aspects :: DEPTH ) ) ;
1731+ None
1732+ } ;
17231733
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 ) {
17261735 let attachment = descriptor
17271736 . stencil_attachment ( )
17281737 . unwrap ( ) ;
17291738 attachment. set_texture ( Some ( texture) ) ;
17301739 attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1731- if clear_stencil_attachment {
1740+ if sub . aspects . contains ( Aspects :: STENCIL ) {
17321741 attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
17331742 attachment. set_clear_stencil ( depth_stencil. stencil ) ;
1743+ Some ( attachment)
17341744 } else {
17351745 attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
1746+ None
17361747 }
1737- }
1748+ } else {
1749+ assert ! ( !sub. aspects. contains( Aspects :: STENCIL ) ) ;
1750+ None
1751+ } ;
17381752
17391753 for layer in layers {
17401754 for level in sub. levels . clone ( ) {
@@ -1746,29 +1760,19 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
17461760 descriptor. set_render_target_array_length ( num_layers) ;
17471761 } ;
17481762
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 {
17541764 attachment. set_level ( level as _ ) ;
17551765 if !CLEAR_IMAGE_ARRAY {
17561766 attachment. set_slice ( layer as _ ) ;
17571767 }
17581768 }
1759- if clear_depth_attachment {
1760- let attachment = descriptor
1761- . depth_attachment ( )
1762- . unwrap ( ) ;
1769+ if let Some ( attachment) = depth_attachment {
17631770 attachment. set_level ( level as _ ) ;
17641771 if !CLEAR_IMAGE_ARRAY {
17651772 attachment. set_slice ( layer as _ ) ;
17661773 }
17671774 }
1768- if clear_stencil_attachment {
1769- let attachment = descriptor
1770- . stencil_attachment ( )
1771- . unwrap ( ) ;
1775+ if let Some ( attachment) = stencil_attachment {
17721776 attachment. set_level ( level as _ ) ;
17731777 if !CLEAR_IMAGE_ARRAY {
17741778 attachment. set_slice ( layer as _ ) ;
@@ -2015,6 +2019,8 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
20152019 T : IntoIterator ,
20162020 T :: Item : Borrow < com:: ImageBlit >
20172021 {
2022+ let _ap = AutoreleasePool :: new ( ) ;
2023+
20182024 let vertices = & mut self . temp . blit_vertices ;
20192025 vertices. clear ( ) ;
20202026
@@ -2218,7 +2224,9 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
22182224 . chain ( & extra)
22192225 . cloned ( ) ;
22202226
2221- inner. sink ( ) . begin_render_pass ( false , & descriptor, commands) ;
2227+ inner
2228+ . sink ( )
2229+ . begin_render_pass ( false , & descriptor, commands) ;
22222230 }
22232231 }
22242232
@@ -2233,13 +2241,26 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
22332241 } ) ;
22342242 }
22352243
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+ }
22432264 }
22442265
22452266 let mask = self . state . set_vertex_buffers ( ) ;
0 commit comments