@@ -147,13 +147,7 @@ impl CommandPool {
147
147
dispatch_queue : match ONLINE_RECORDING {
148
148
OnlineRecording :: Immediate |
149
149
OnlineRecording :: Deferred => None ,
150
- OnlineRecording :: Remote ( priority) => Some (
151
- dispatch:: Queue :: with_target_queue (
152
- "gfx-metal" ,
153
- dispatch:: QueueAttribute :: Serial ,
154
- & dispatch:: Queue :: global ( priority) ,
155
- )
156
- ) ,
150
+ OnlineRecording :: Remote ( priority) => Some ( dispatch:: Queue :: global ( priority) ) ,
157
151
}
158
152
} ;
159
153
CommandPool {
@@ -639,6 +633,13 @@ impl StageResources {
639
633
}
640
634
641
635
636
+ #[ derive( Debug , Default ) ]
637
+ struct Capacity {
638
+ render : usize ,
639
+ compute : usize ,
640
+ blit : usize ,
641
+ }
642
+
642
643
//TODO: make sure to recycle the heap allocation of these commands.
643
644
enum EncodePass {
644
645
Render ( Vec < soft:: RenderCommand < soft:: Own > > , metal:: RenderPassDescriptor ) ,
@@ -677,6 +678,14 @@ impl EncodePass {
677
678
}
678
679
} ) ;
679
680
}
681
+
682
+ fn update ( & self , capacity : & mut Capacity ) {
683
+ match & self {
684
+ EncodePass :: Render ( ref list, _) => capacity. render = capacity. render . max ( list. len ( ) ) ,
685
+ EncodePass :: Compute ( ref list) => capacity. compute = capacity. compute . max ( list. len ( ) ) ,
686
+ EncodePass :: Blit ( ref list) => capacity. blit = capacity. blit . max ( list. len ( ) ) ,
687
+ }
688
+ }
680
689
}
681
690
682
691
@@ -757,6 +766,7 @@ enum CommandSink {
757
766
cmd_buffer : Arc < Mutex < metal:: CommandBuffer > > ,
758
767
token : Token ,
759
768
pass : Option < EncodePass > ,
769
+ capacity : Capacity ,
760
770
} ,
761
771
}
762
772
@@ -882,12 +892,14 @@ impl CommandSink {
882
892
CommandSink :: Remote { pass : Some ( EncodePass :: Blit ( ref mut list) ) , .. } => {
883
893
list. extend ( commands. into_iter ( ) . map ( soft:: BlitCommand :: own) ) ;
884
894
}
885
- CommandSink :: Remote { ref queue, ref cmd_buffer, ref mut pass, .. } => {
895
+ CommandSink :: Remote { ref queue, ref cmd_buffer, ref mut pass, ref mut capacity , .. } => {
886
896
if let Some ( pass) = pass. take ( ) {
897
+ pass. update ( capacity) ;
887
898
pass. schedule ( queue, cmd_buffer) ;
888
899
}
889
- let owned_commands = commands. into_iter ( ) . map ( soft:: BlitCommand :: own) . collect ( ) ;
890
- * pass = Some ( EncodePass :: Blit ( owned_commands) ) ;
900
+ let mut list = Vec :: with_capacity ( capacity. blit ) ;
901
+ list. extend ( commands. into_iter ( ) . map ( soft:: BlitCommand :: own) ) ;
902
+ * pass = Some ( EncodePass :: Blit ( list) ) ;
891
903
}
892
904
}
893
905
}
@@ -939,8 +951,9 @@ impl CommandSink {
939
951
* is_encoding = false ;
940
952
journal. stop ( ) ;
941
953
}
942
- CommandSink :: Remote { ref queue, ref cmd_buffer, ref mut pass, .. } => {
954
+ CommandSink :: Remote { ref queue, ref cmd_buffer, ref mut pass, ref mut capacity , .. } => {
943
955
if let Some ( pass) = pass. take ( ) {
956
+ pass. update ( capacity) ;
944
957
pass. schedule ( queue, cmd_buffer) ;
945
958
}
946
959
}
@@ -991,14 +1004,15 @@ impl CommandSink {
991
1004
}
992
1005
journal. passes . push ( ( pass, range) )
993
1006
}
994
- CommandSink :: Remote { ref queue, ref cmd_buffer, ref mut pass, .. } => {
1007
+ CommandSink :: Remote { ref queue, ref cmd_buffer, ref mut pass, ref capacity , .. } => {
995
1008
let desc = unsafe {
996
1009
let desc: metal:: RenderPassDescriptor = msg_send ! [ descriptor, copy] ;
997
1010
msg_send ! [ desc. as_ptr( ) , retain] ;
998
1011
desc
999
1012
} ;
1000
- let owned_commands = init_commands. map ( soft:: RenderCommand :: own) . collect ( ) ;
1001
- let new_pass = EncodePass :: Render ( owned_commands, desc) ;
1013
+ let mut list = Vec :: with_capacity ( capacity. render ) ;
1014
+ list. extend ( init_commands. map ( soft:: RenderCommand :: own) ) ;
1015
+ let new_pass = EncodePass :: Render ( list, desc) ;
1002
1016
match door {
1003
1017
PassDoor :: Open => * pass = Some ( new_pass) ,
1004
1018
PassDoor :: Closed { .. } => new_pass. schedule ( queue, cmd_buffer) ,
@@ -1043,9 +1057,10 @@ impl CommandSink {
1043
1057
} ;
1044
1058
journal. passes . push ( ( soft:: Pass :: Compute , range) )
1045
1059
}
1046
- CommandSink :: Remote { ref queue, ref cmd_buffer, ref mut pass, .. } => {
1047
- let owned_commands = init_commands. map ( soft:: ComputeCommand :: own) . collect ( ) ;
1048
- let new_pass = EncodePass :: Compute ( owned_commands) ;
1060
+ CommandSink :: Remote { ref queue, ref cmd_buffer, ref mut pass, ref capacity, .. } => {
1061
+ let mut list = Vec :: with_capacity ( capacity. compute ) ;
1062
+ list. extend ( init_commands. map ( soft:: ComputeCommand :: own) ) ;
1063
+ let new_pass = EncodePass :: Compute ( list) ;
1049
1064
match door {
1050
1065
PassDoor :: Open => * pass = Some ( new_pass) ,
1051
1066
PassDoor :: Closed { .. } => new_pass. schedule ( queue, cmd_buffer) ,
@@ -1065,6 +1080,7 @@ pub struct IndexBuffer<B> {
1065
1080
pub struct CommandBufferInner {
1066
1081
sink : Option < CommandSink > ,
1067
1082
backup_journal : Option < Journal > ,
1083
+ backup_capacity : Option < Capacity > ,
1068
1084
retained_buffers : Vec < metal:: Buffer > ,
1069
1085
retained_textures : Vec < metal:: Texture > ,
1070
1086
}
@@ -1090,8 +1106,11 @@ impl CommandBufferInner {
1090
1106
self . backup_journal = Some ( journal) ;
1091
1107
}
1092
1108
}
1093
- Some ( CommandSink :: Remote { token, .. } ) => {
1109
+ Some ( CommandSink :: Remote { token, capacity , .. } ) => {
1094
1110
shared. queue . lock ( ) . release ( token) ;
1111
+ if !release {
1112
+ self . backup_capacity = Some ( capacity) ;
1113
+ }
1095
1114
}
1096
1115
None => { }
1097
1116
} ;
@@ -1525,7 +1544,7 @@ impl RawCommandQueue<Backend> for CommandQueue {
1525
1544
trace ! ( "\t remote {:?}" , token) ;
1526
1545
cmd_buffer. lock ( ) . enqueue ( ) ;
1527
1546
let shared_cb = SharedCommandBuffer ( Arc :: clone ( cmd_buffer) ) ;
1528
- queue. async ( move || {
1547
+ queue. sync ( move || {
1529
1548
shared_cb. 0 . lock ( ) . commit ( ) ;
1530
1549
} ) ;
1531
1550
}
@@ -1669,6 +1688,7 @@ impl pool::RawCommandPool<Backend> for CommandPool {
1669
1688
inner : Arc :: new ( RefCell :: new ( CommandBufferInner {
1670
1689
sink : None ,
1671
1690
backup_journal : None ,
1691
+ backup_capacity : None ,
1672
1692
retained_buffers : Vec :: new ( ) ,
1673
1693
retained_textures : Vec :: new ( ) ,
1674
1694
} ) ) ,
@@ -1773,10 +1793,15 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1773
1793
OnlineRecording :: Remote ( _) if oneshot => {
1774
1794
let ( cmd_buffer, token) = self . shared . queue . lock ( ) . spawn ( ) ;
1775
1795
CommandSink :: Remote {
1776
- queue : self . pool_shared . borrow_mut ( ) . dispatch_queue . clone ( ) . unwrap ( ) ,
1796
+ queue : dispatch:: Queue :: with_target_queue (
1797
+ "gfx-metal" ,
1798
+ dispatch:: QueueAttribute :: Serial ,
1799
+ self . pool_shared . borrow_mut ( ) . dispatch_queue . as_ref ( ) . unwrap ( ) ,
1800
+ ) ,
1777
1801
cmd_buffer : Arc :: new ( Mutex :: new ( cmd_buffer) ) ,
1778
1802
token,
1779
1803
pass : None ,
1804
+ capacity : inner. backup_capacity . take ( ) . unwrap_or_default ( ) ,
1780
1805
}
1781
1806
}
1782
1807
_ => {
0 commit comments