@@ -65,9 +65,14 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
6565 .Build ();
6666}
6767
68- ContextMTL::ContextMTL (id <MTLDevice > device,
69- NSArray <id <MTLLibrary >>* shader_libraries)
70- : device_(device) {
68+ ContextMTL::ContextMTL (
69+ id <MTLDevice > device,
70+ NSArray <id <MTLLibrary >>* shader_libraries,
71+ std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
72+ std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
73+ : device_(device),
74+ worker_task_runner_ (std::move(worker_task_runner)),
75+ is_gpu_disabled_sync_switch_(std::move(is_gpu_disabled_sync_switch)) {
7176 // Validate device.
7277 if (!device_) {
7378 VALIDATION_LOG << " Could not setup valid Metal device." ;
@@ -200,10 +205,13 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
200205}
201206
202207std::shared_ptr<ContextMTL> ContextMTL::Create (
203- const std::vector<std::string>& shader_library_paths) {
208+ const std::vector<std::string>& shader_library_paths,
209+ std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
210+ std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch) {
204211 auto device = CreateMetalDevice ();
205212 auto context = std::shared_ptr<ContextMTL>(new ContextMTL (
206- device, MTLShaderLibraryFromFilePaths (device, shader_library_paths)));
213+ device, MTLShaderLibraryFromFilePaths (device, shader_library_paths),
214+ std::move (worker_task_runner), std::move (is_gpu_disabled_sync_switch)));
207215 if (!context->IsValid ()) {
208216 FML_LOG (ERROR) << " Could not create Metal context." ;
209217 return nullptr ;
@@ -213,11 +221,14 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
213221
214222std::shared_ptr<ContextMTL> ContextMTL::Create (
215223 const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
224+ std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
225+ std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
216226 const std::string& label) {
217227 auto device = CreateMetalDevice ();
218228 auto context = std::shared_ptr<ContextMTL>(new ContextMTL (
219229 device,
220- MTLShaderLibraryFromFileData (device, shader_libraries_data, label)));
230+ MTLShaderLibraryFromFileData (device, shader_libraries_data, label),
231+ worker_task_runner, std::move (is_gpu_disabled_sync_switch)));
221232 if (!context->IsValid ()) {
222233 FML_LOG (ERROR) << " Could not create Metal context." ;
223234 return nullptr ;
@@ -257,6 +268,16 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
257268 return CreateCommandBufferInQueue (command_queue_);
258269}
259270
271+ const std::shared_ptr<fml::ConcurrentTaskRunner>&
272+ ContextMTL::GetWorkerTaskRunner () const {
273+ return worker_task_runner_;
274+ }
275+
276+ std::shared_ptr<const fml::SyncSwitch> ContextMTL::GetIsGpuDisabledSyncSwitch ()
277+ const {
278+ return is_gpu_disabled_sync_switch_;
279+ }
280+
260281std::shared_ptr<CommandBuffer> ContextMTL::CreateCommandBufferInQueue (
261282 id <MTLCommandQueue > queue) const {
262283 if (!IsValid ()) {
0 commit comments