From 9d1d564993079ac516ca213e80cb09cf7a932afe Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Sat, 29 Oct 2022 21:24:57 -0700 Subject: [PATCH] Vulkan: Add `CommandBufferLabelScope` --- src/Ryujinx.Graphics.Vulkan/LabelScope.cs | 79 +++++++++++++++++++ .../VulkanDebugMessenger.cs | 6 ++ src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs | 5 ++ 3 files changed, 90 insertions(+) create mode 100644 src/Ryujinx.Graphics.Vulkan/LabelScope.cs diff --git a/src/Ryujinx.Graphics.Vulkan/LabelScope.cs b/src/Ryujinx.Graphics.Vulkan/LabelScope.cs new file mode 100644 index 000000000..ea9f02d1e --- /dev/null +++ b/src/Ryujinx.Graphics.Vulkan/LabelScope.cs @@ -0,0 +1,79 @@ +using Ryujinx.Graphics.GAL; +using Silk.NET.Vulkan; +using Silk.NET.Vulkan.Extensions.EXT; +using System; +using System.Runtime.InteropServices; + +namespace Ryujinx.Graphics.Vulkan +{ + public interface ILabelScope : IDisposable + { + void InsertLabel(string labelName, ColorF labelColor); + } + + interface ILabelScopePrivate : ILabelScope + { + void BeginLabel(string scopeName, ColorF scopeColor); + void EndLabel(); + } + + + class CommandBufferLabelScope : ILabelScopePrivate + { + private CommandBuffer _commandBuffer; + + private readonly ExtDebugUtils _debugUtils; + + public unsafe CommandBufferLabelScope(ExtDebugUtils debugUtils, CommandBuffer commandBuffer, string scopeName, ColorF scopeColor) + { + _debugUtils = debugUtils; + _commandBuffer = commandBuffer; + + BeginLabel(scopeName, scopeColor); + } + + public unsafe void InsertLabel(string labelName, ColorF labelColor) + { + IntPtr pLabelName = Marshal.StringToHGlobalAnsi(labelName); + + DebugUtilsLabelEXT label = CreateLabel(pLabelName, labelColor); + _debugUtils.CmdInsertDebugUtilsLabel(_commandBuffer, label); + + Marshal.FreeHGlobal(pLabelName); + } + + public unsafe void BeginLabel(string scopeName, ColorF scopeColor) + { + IntPtr pScopeName = Marshal.StringToHGlobalAnsi(scopeName); + + DebugUtilsLabelEXT label = CreateLabel(pScopeName, scopeColor); + _debugUtils.CmdBeginDebugUtilsLabel(_commandBuffer, label); + + Marshal.FreeHGlobal(pScopeName); + } + + public unsafe void EndLabel() + { + _debugUtils.CmdEndDebugUtilsLabel(_commandBuffer); + } + + private static unsafe DebugUtilsLabelEXT CreateLabel(IntPtr scopeName, ColorF scopeColor) + { + DebugUtilsLabelEXT label = new DebugUtilsLabelEXT + { + SType = StructureType.DebugUtilsLabelExt, + PLabelName = (byte*)scopeName + }; + label.Color[0] = scopeColor.Red; + label.Color[1] = scopeColor.Green; + label.Color[2] = scopeColor.Blue; + label.Color[3] = scopeColor.Alpha; + return label; + } + + public void Dispose() + { + EndLabel(); + } + } +} diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanDebugMessenger.cs b/src/Ryujinx.Graphics.Vulkan/VulkanDebugMessenger.cs index 496a90fbe..8d117714a 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanDebugMessenger.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanDebugMessenger.cs @@ -1,6 +1,7 @@ using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Common.Utilities; +using Ryujinx.Graphics.GAL; using Silk.NET.Vulkan; using Silk.NET.Vulkan.Extensions.EXT; using System; @@ -33,6 +34,11 @@ namespace Ryujinx.Graphics.Vulkan } } + public ILabelScope CreateLabelScope(CommandBuffer commandBuffer, string scopeName, ColorF scopeColor) + { + return new CommandBufferLabelScope(_debugUtils, commandBuffer, scopeName, scopeColor); + } + private Result TryInitialize(out DebugUtilsMessengerEXT? debugUtilsMessengerHandle) { debugUtilsMessengerHandle = null; diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs index 7b6b89a74..2db56348b 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs @@ -396,6 +396,11 @@ namespace Ryujinx.Graphics.Vulkan _initialized = true; } + public ILabelScope CreateLabelScope(CommandBuffer commandBuffer, string scopeName, ColorF scopeColor) + { + return _debugMessenger.CreateLabelScope(commandBuffer, scopeName, scopeColor); + } + public BufferHandle CreateBuffer(int size, BufferAccess access) { return BufferManager.CreateWithHandle(this, size, access.Convert(), default, access == BufferAccess.Stream);