66
77#include < Foundation/Foundation.h>
88
9- #include " flutter/fml/concurrent_message_loop.h"
109#include " flutter/fml/file.h"
1110#include " flutter/fml/logging.h"
1211#include " flutter/fml/paths.h"
13- #include " flutter/fml/synchronization/sync_switch.h"
1412#include " impeller/core/sampler_descriptor.h"
1513#include " impeller/renderer/backend/metal/sampler_library_mtl.h"
1614#include " impeller/renderer/capabilities.h"
@@ -69,12 +67,10 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
6967
7068ContextMTL::ContextMTL (
7169 id <MTLDevice > device,
72- id <MTLCommandQueue > command_queue,
7370 NSArray <id <MTLLibrary >>* shader_libraries,
7471 std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
7572 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
7673 : device_(device),
77- command_queue_ (command_queue),
7874 worker_task_runner_ (std::move(worker_task_runner)),
7975 is_gpu_disabled_sync_switch_(std::move(is_gpu_disabled_sync_switch)) {
8076 // Validate device.
@@ -100,6 +96,16 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
10096 shader_library_ = std::move (library);
10197 }
10298
99+ // Setup command queue.
100+ {
101+ command_queue_ = device_.newCommandQueue ;
102+ if (!command_queue_) {
103+ VALIDATION_LOG << " Could not setup the command queue." ;
104+ return ;
105+ }
106+ command_queue_.label = @" Impeller Command Queue" ;
107+ }
108+
103109 // Setup the pipeline library.
104110 {
105111 pipeline_library_ =
@@ -198,28 +204,13 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
198204 return ::MTLCreateSystemDefaultDevice ();
199205}
200206
201- static id <MTLCommandQueue > CreateMetalCommandQueue (id <MTLDevice > device) {
202- auto command_queue = device.newCommandQueue ;
203- if (!command_queue) {
204- VALIDATION_LOG << " Could not setup the command queue." ;
205- return nullptr ;
206- }
207- command_queue.label = @" Impeller Command Queue" ;
208- return command_queue;
209- }
210-
211207std::shared_ptr<ContextMTL> ContextMTL::Create (
212208 const std::vector<std::string>& shader_library_paths,
213209 std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
214210 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch) {
215211 auto device = CreateMetalDevice ();
216- auto command_queue = CreateMetalCommandQueue (device);
217- if (!command_queue) {
218- return nullptr ;
219- }
220212 auto context = std::shared_ptr<ContextMTL>(new ContextMTL (
221- device, command_queue,
222- MTLShaderLibraryFromFilePaths (device, shader_library_paths),
213+ device, MTLShaderLibraryFromFilePaths (device, shader_library_paths),
223214 std::move (worker_task_runner), std::move (is_gpu_disabled_sync_switch)));
224215 if (!context->IsValid ()) {
225216 FML_LOG (ERROR) << " Could not create Metal context." ;
@@ -232,35 +223,11 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
232223 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
233224 std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
234225 std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
235- const std::string& library_label ) {
226+ const std::string& label ) {
236227 auto device = CreateMetalDevice ();
237- auto command_queue = CreateMetalCommandQueue (device);
238- if (!command_queue) {
239- return nullptr ;
240- }
241- auto context = std::shared_ptr<ContextMTL>(new ContextMTL (
242- device, command_queue,
243- MTLShaderLibraryFromFileData (device, shader_libraries_data,
244- library_label),
245- std::move (worker_task_runner), std::move (is_gpu_disabled_sync_switch)));
246- if (!context->IsValid ()) {
247- FML_LOG (ERROR) << " Could not create Metal context." ;
248- return nullptr ;
249- }
250- return context;
251- }
252-
253- std::shared_ptr<ContextMTL> ContextMTL::Create (
254- id <MTLDevice > device,
255- id <MTLCommandQueue > command_queue,
256- const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
257- std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
258- std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
259- const std::string& library_label) {
260228 auto context = std::shared_ptr<ContextMTL>(new ContextMTL (
261- device, command_queue,
262- MTLShaderLibraryFromFileData (device, shader_libraries_data,
263- library_label),
229+ device,
230+ MTLShaderLibraryFromFileData (device, shader_libraries_data, label),
264231 std::move (worker_task_runner), std::move (is_gpu_disabled_sync_switch)));
265232 if (!context->IsValid ()) {
266233 FML_LOG (ERROR) << " Could not create Metal context." ;
0 commit comments