mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 03:08:05 +02:00
kk: Add env variables to enable Xcode GPU capture
To enable GPU capture set MESA_KK_GPU_CAPTURE to 1 To dump GPU capture to a directory set MESA_KK_GPU_CAPTURE_DIRECTORY Reviewed-by: Arcady Goldmints-Orlov <arcady@lunarg.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38068>
This commit is contained in:
parent
6aff9d0ae8
commit
8e47589da8
5 changed files with 19 additions and 63 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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<MTLDevice> mtl_dev = (id<MTLDevice>)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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue