device_removal.mm 1.1 KB

123456789101112131415161718192021222324252627282930
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/metal_util/device_removal.h"
  5. #include "base/process/process.h"
  6. #import <Metal/Metal.h>
  7. namespace metal {
  8. void RegisterGracefulExitOnDeviceRemoval() {
  9. id<NSObject> deviceObserver = nil;
  10. MTLCopyAllDevicesWithObserver(
  11. &deviceObserver, ^(id<MTLDevice> device, MTLDeviceNotificationName name) {
  12. if (name == MTLDeviceRemovalRequestedNotification ||
  13. name == MTLDeviceWasRemovedNotification) {
  14. // Exit the GPU process without error. The browser process sees
  15. // this error code as a graceful shutdown, so relaunches the GPU
  16. // process without incrementing the crash count.
  17. //
  18. // Note this wouldn't work nicely with in-process-gpu (it would
  19. // exit the browser), but we don't support that on macOS anyway.
  20. base::Process::TerminateCurrentProcessImmediately(0);
  21. }
  22. });
  23. }
  24. } // namespace metal