From b5cf9b639eb1ed35fc1f6546ac014f8f0083d1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 8 Sep 2019 13:38:09 +0200 Subject: [PATCH] metal: Improve shader debugging Having the path to each shader is helpful when debugging the rendering pipeline. The render command encoder label is limited to just the filename of the shader, as the graphics debugging UI in Xcode doesn't handle long names very well. We don't encode the pass number into the string as the shaders can be organized in a graph, not just a linked list, so an indexed order can be misrepresenting the flow. --- gfx/common/metal_common.m | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gfx/common/metal_common.m b/gfx/common/metal_common.m index 4daa096397..3b25d30aa4 100644 --- a/gfx/common/metal_common.m +++ b/gfx/common/metal_common.m @@ -939,6 +939,7 @@ typedef struct MTLALIGN(16) } id cb = ctx.blitCommandBuffer; + [cb pushDebugGroup:@"shaders"]; MTLRenderPassDescriptor *rpd = [MTLRenderPassDescriptor new]; rpd.colorAttachments[0].loadAction = MTLLoadActionDontCare; @@ -960,12 +961,11 @@ typedef struct MTLALIGN(16) rce = [cb renderCommandEncoderWithDescriptor:rpd]; } -#if DEBUG && METAL_DEBUG - rce.label = [NSString stringWithFormat:@"pass %d", i]; -#endif - [rce setRenderPipelineState:_engine.pass[i]._state]; + NSURL *shaderPath = [NSURL fileURLWithPath:_engine.pass[i]._state.label]; + rce.label = shaderPath.lastPathComponent.stringByDeletingPathExtension; + _engine.pass[i].frame_count = (uint32_t)_frameCount; if (_shader->pass[i].frame_count_mod) _engine.pass[i].frame_count %= _shader->pass[i].frame_count_mod; @@ -1037,6 +1037,8 @@ typedef struct MTLALIGN(16) _drawState = ViewDrawStateContext; else _drawState = ViewDrawStateAll; + + [cb popDebugGroup]; } - (void)_updateRenderTargets @@ -1181,6 +1183,9 @@ typedef struct MTLALIGN(16) config_file_t *conf = video_shader_read_preset(path.UTF8String); struct video_shader *shader = (struct video_shader *)calloc(1, sizeof(*shader)); + settings_t *settings = config_get_ptr(); + NSString *shadersPath = [NSString stringWithFormat:@"%s/", settings->paths.directory_video_shader]; + @try { unsigned i; @@ -1256,7 +1261,9 @@ typedef struct MTLALIGN(16) vd.layouts[4].stepFunction = MTLVertexStepFunctionPerVertex; MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new]; - psd.label = [NSString stringWithFormat:@"pass %d", i]; + + psd.label = [[NSString stringWithUTF8String:shader->pass[i].source.path] + stringByReplacingOccurrencesOfString:shadersPath withString:@""]; MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0];