diff --git a/src/kosmickrisp/bridge/mtl_device.h b/src/kosmickrisp/bridge/mtl_device.h index 30ee1b0967e..1b8e127c11a 100644 --- a/src/kosmickrisp/bridge/mtl_device.h +++ b/src/kosmickrisp/bridge/mtl_device.h @@ -18,7 +18,7 @@ struct kk_image_layout; mtl_device *mtl_device_create(void); /* Device operations */ -void mtl_start_gpu_capture(mtl_device *mtl_dev_handle); +void mtl_start_gpu_capture(mtl_device *mtl_dev_handle, const char *directory); void mtl_stop_gpu_capture(void); /* Device feature query */ diff --git a/src/kosmickrisp/bridge/mtl_device.m b/src/kosmickrisp/bridge/mtl_device.m index aab0e735ff6..7427e4061e1 100644 --- a/src/kosmickrisp/bridge/mtl_device.m +++ b/src/kosmickrisp/bridge/mtl_device.m @@ -38,41 +38,29 @@ mtl_device_create() /* Device operations */ void -mtl_start_gpu_capture(mtl_device *mtl_dev_handle) +mtl_start_gpu_capture(mtl_device *mtl_dev_handle, const char *directory) { @autoreleasepool { id mtl_dev = (id)mtl_dev_handle; MTLCaptureManager *captureMgr = [MTLCaptureManager sharedCaptureManager]; - // Before macOS 10.15 and iOS 13.0, captureDesc will just be nil MTLCaptureDescriptor *captureDesc = [[MTLCaptureDescriptor new] autorelease]; captureDesc.captureObject = mtl_dev; captureDesc.destination = MTLCaptureDestinationDeveloperTools; - // TODO_KOSMICKRISP Support dumping a trace to a file? - // NSString *tmp_dir = NSTemporaryDirectory(); - // NSString *pname = [[NSProcessInfo processInfo] processName]; - // NSString *capture_path = [NSString stringWithFormat:@"%@/%@.gputrace", tmp_dir, pname]; - // if ([captureMgr supportsDestination: MTLCaptureDestinationGPUTraceDocument] ) { - // captureDesc.destination = MTLCaptureDestinationGPUTraceDocument; - // captureDesc.outputURL = [NSURL fileURLWithPath: capture_path]; - //} + if (directory && [captureMgr supportsDestination: MTLCaptureDestinationGPUTraceDocument]) { + NSString *dir = [NSString stringWithUTF8String:directory]; + NSString *pname = [[NSProcessInfo processInfo] processName]; + NSString *capture_path = [NSString stringWithFormat:@"%@/%@.gputrace", dir, pname]; + captureDesc.destination = MTLCaptureDestinationGPUTraceDocument; + captureDesc.outputURL = [NSURL fileURLWithPath: capture_path]; + } NSError *err = nil; if (![captureMgr startCaptureWithDescriptor:captureDesc error:&err]) { - // fprintf(stderr, "Failed to automatically start GPU capture session (Error code %li) using startCaptureWithDescriptor: %s\n", - // (long)err.code, err.localizedDescription.UTF8String); - // fprintf(stderr, "Using startCaptureWithDevice\n"); - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - [captureMgr startCaptureWithDevice:mtl_dev]; -#pragma clang diagnostic pop + fprintf(stderr, "Failed to automatically start GPU capture session (Error code %li) using startCaptureWithDescriptor: %s\n", + (long)err.code, err.localizedDescription.UTF8String); } - - //[tmp_dir release]; - //[pname release]; - //[capture_path release]; } } diff --git a/src/kosmickrisp/bridge/stubs/mtl_device.c b/src/kosmickrisp/bridge/stubs/mtl_device.c index 78e22e30c12..dfda0e905d9 100644 --- a/src/kosmickrisp/bridge/stubs/mtl_device.c +++ b/src/kosmickrisp/bridge/stubs/mtl_device.c @@ -15,7 +15,7 @@ mtl_device_create(void) /* Device operations */ void -mtl_start_gpu_capture(mtl_device *mtl_dev_handle) +mtl_start_gpu_capture(mtl_device *mtl_dev_handle, const char *directory) { } diff --git a/src/kosmickrisp/vulkan/kk_device.c b/src/kosmickrisp/vulkan/kk_device.c index 72b4fcc5603..6bf89bcfb59 100644 --- a/src/kosmickrisp/vulkan/kk_device.c +++ b/src/kosmickrisp/vulkan/kk_device.c @@ -213,8 +213,13 @@ kk_CreateDevice(VkPhysicalDevice physicalDevice, *pDevice = kk_device_to_handle(dev); - dev->gpu_capture_enabled = kk_get_environment_boolean(KK_ENABLE_GPU_CAPTURE); - mtl_start_gpu_capture(dev->mtl_handle); + dev->gpu_capture_enabled = + debug_get_bool_option("MESA_KK_GPU_CAPTURE", false); + if (dev->gpu_capture_enabled) { + const char *capture_directory = + debug_get_option("MESA_KK_GPU_CAPTURE_DIRECTORY", NULL); + mtl_start_gpu_capture(dev->mtl_handle, capture_directory); + } return VK_SUCCESS; diff --git a/src/kosmickrisp/vulkan/kk_private.h b/src/kosmickrisp/vulkan/kk_private.h index d50481f6f8a..1a1a2dcd2dd 100644 --- a/src/kosmickrisp/vulkan/kk_private.h +++ b/src/kosmickrisp/vulkan/kk_private.h @@ -55,41 +55,4 @@ struct kk_addr_range { uint64_t range; }; -typedef enum kk_env_option_t { - KK_ENABLE_GPU_CAPTURE = 0, - KK_MAX_ENV_OPTIONS, -} kk_env_option_t; - -struct kk_env_option { - const char *name; - bool value; -}; - -static struct kk_env_option KK_ENV_OPTIONS[KK_MAX_ENV_OPTIONS] = { - [KK_ENABLE_GPU_CAPTURE] = - { - .name = "MESA_KOSMICKRISP_ENABLE_GPU_CAPTURE", - .value = false, - }, -}; - -static inline bool -kk_get_environment_boolean(kk_env_option_t option) -{ - assert(option >= 0 && option < KK_MAX_ENV_OPTIONS); - struct kk_env_option *opt = &KK_ENV_OPTIONS[option]; - const char *env_str = getenv(opt->name); - if (env_str) { - if (strncmp(env_str, "0", 1) != 0) { - opt->value = true; - } else { - opt->value = false; - } - } - return opt->value; -} - -#define kk_debug_ignored_stype(sType) \ - mesa_logd("%s: ignored VkStructureType %u\n", __func__, (sType)) - #endif