@@ -159,29 +159,27 @@ struct VideoMetal : VideoDriver, Metal {
159
159
}
160
160
161
161
auto setShader (string pathname) -> bool override {
162
- if (_filterChain != NULL ) {
163
- _libra.mtl_filter_chain_free (&_filterChain);
164
- }
165
-
166
- if (_preset != NULL ) {
167
- _libra.preset_free (&_preset);
168
- }
169
-
170
- if (file::exists (pathname)) {
171
- if (auto error = _libra.preset_create (pathname.data (), &_preset)) {
172
- print (string{" Metal: Failed to load shader: " , pathname, " \n " });
173
- _libra.error_print (error);
174
- return false ;
162
+ dispatch_async (_renderQueue, ^{
163
+ if (_filterChain != NULL ) {
164
+ _libra.mtl_filter_chain_free (&_filterChain);
175
165
}
176
-
177
- if (auto error = _libra.mtl_filter_chain_create (&_preset, _commandQueue, nil, &_filterChain)) {
178
- print (string{" Metal: Failed to create filter chain for: " , pathname, " \n " });
179
- _libra.error_print (error);
180
- return false ;
181
- };
182
- } else {
183
- return false ;
184
- }
166
+
167
+ if (_preset != NULL ) {
168
+ _libra.preset_free (&_preset);
169
+ }
170
+
171
+ if (file::exists (pathname)) {
172
+ if (auto error = _libra.preset_create (pathname.data (), &_preset)) {
173
+ print (string{" Metal: Failed to load shader: " , pathname, " \n " });
174
+ _libra.error_print (error);
175
+ }
176
+
177
+ if (auto error = _libra.mtl_filter_chain_create (&_preset, _commandQueue, nil, &_filterChain)) {
178
+ print (string{" Metal: Failed to create filter chain for: " , pathname, " \n " });
179
+ _libra.error_print (error);
180
+ };
181
+ }
182
+ });
185
183
return true ;
186
184
}
187
185
@@ -421,9 +419,11 @@ struct VideoMetal : VideoDriver, Metal {
421
419
422
420
id<CAMetalDrawable> drawable = view.currentDrawable ;
423
421
422
+ __block VideoMetal &strongSelf = self;
423
+
424
424
if (@available (macOS 10.15.4 , *)) {
425
425
[drawable addPresentedHandler:^(id<MTLDrawable> drawable) {
426
- self .drawableWasPresented (drawable);
426
+ strongSelf .drawableWasPresented (drawable);
427
427
depth--;
428
428
}];
429
429
}
@@ -599,31 +599,35 @@ struct VideoMetal : VideoDriver, Metal {
599
599
}
600
600
601
601
auto terminate () -> void {
602
- _ready = false ;
603
-
604
- _commandQueue = nullptr ;
605
- _library = nullptr ;
606
-
607
- _vertexBuffer = nullptr ;
608
- for (int i = 0 ; i < kMaxSourceBuffersInFlight ; i++) {
609
- _sourceTextures[i] = nullptr ;
610
- }
611
- _mtlVertexDescriptor = nullptr ;
612
-
613
- _renderToTextureRenderPassDescriptor = nullptr ;
614
- _renderTargetTexture = nullptr ;
615
- _renderToTextureRenderPipeline = nullptr ;
616
-
617
- _drawableRenderPipeline = nullptr ;
618
-
619
- if (_filterChain) {
620
- _libra.mtl_filter_chain_free (&_filterChain);
621
- }
622
- _device = nullptr ;
623
-
624
- if (view) {
625
- [view removeFromSuperview];
626
- view = nil;
602
+ if (_renderQueue) {
603
+ dispatch_sync (_renderQueue, ^{
604
+ _ready = false ;
605
+
606
+ _commandQueue = nullptr ;
607
+ _library = nullptr ;
608
+
609
+ _vertexBuffer = nullptr ;
610
+ for (int i = 0 ; i < kMaxSourceBuffersInFlight ; i++) {
611
+ _sourceTextures[i] = nullptr ;
612
+ }
613
+ _mtlVertexDescriptor = nullptr ;
614
+
615
+ _renderToTextureRenderPassDescriptor = nullptr ;
616
+ _renderTargetTexture = nullptr ;
617
+ _renderToTextureRenderPipeline = nullptr ;
618
+
619
+ _drawableRenderPipeline = nullptr ;
620
+
621
+ if (_filterChain) {
622
+ _libra.mtl_filter_chain_free (&_filterChain);
623
+ }
624
+ _device = nullptr ;
625
+
626
+ if (view) {
627
+ [view removeFromSuperview];
628
+ view = nil;
629
+ }
630
+ });
627
631
}
628
632
}
629
633
0 commit comments