From a8d590ae80186548ff49ccb9d88d775eb22a046e Mon Sep 17 00:00:00 2001 From: GPUCode Date: Tue, 25 Jul 2023 14:10:34 +0300 Subject: [PATCH] vk_instance: Collect tooling info --- src/video_core/renderer_vulkan/pica_to_vk.h | 6 ++++++ .../renderer_vulkan/vk_instance.cpp | 19 +++++++++++++++-- src/video_core/renderer_vulkan/vk_instance.h | 21 +++++++++++++------ .../renderer_vulkan/vk_platform.cpp | 5 +++-- src/video_core/renderer_vulkan/vk_platform.h | 2 +- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/video_core/renderer_vulkan/pica_to_vk.h b/src/video_core/renderer_vulkan/pica_to_vk.h index a5546f1dd..cc0941db0 100644 --- a/src/video_core/renderer_vulkan/pica_to_vk.h +++ b/src/video_core/renderer_vulkan/pica_to_vk.h @@ -195,4 +195,10 @@ inline vk::FrontFace FrontFace(Pica::RasterizerRegs::CullMode mode) { } } +inline Common::Vec4f ColorRGBA8(const u32 color) { + const auto rgba = + Common::Vec4u{color >> 0 & 0xFF, color >> 8 & 0xFF, color >> 16 & 0xFF, color >> 24 & 0xFF}; + return rgba / 255.0f; +} + } // namespace PicaToVK diff --git a/src/video_core/renderer_vulkan/vk_instance.cpp b/src/video_core/renderer_vulkan/vk_instance.cpp index 9d1b1935e..817a1569a 100644 --- a/src/video_core/renderer_vulkan/vk_instance.cpp +++ b/src/video_core/renderer_vulkan/vk_instance.cpp @@ -134,8 +134,8 @@ Instance::Instance(Frontend::EmuWindow& window, u32 physical_device_index) *library, window.GetWindowInfo().type, Settings::values.renderer_debug.GetValue(), Settings::values.dump_command_buffers.GetValue())}, - debug_callback{CreateDebugCallback(*instance)}, physical_devices{ - instance->enumeratePhysicalDevices()} { + debug_callback{CreateDebugCallback(*instance, debug_utils_supported)}, + physical_devices{instance->enumeratePhysicalDevices()} { const std::size_t num_physical_devices = static_cast(physical_devices.size()); ASSERT_MSG(physical_device_index < num_physical_devices, "Invalid physical device index {} provided when only {} devices exist", @@ -146,6 +146,7 @@ Instance::Instance(Frontend::EmuWindow& window, u32 physical_device_index) CollectTelemetryParameters(); CreateDevice(); + CollectToolingInfo(); CreateFormatTable(); CreateCustomFormatTable(); CreateAttribTable(); @@ -403,6 +404,7 @@ bool Instance::CreateDevice() { add_extension(VK_KHR_SWAPCHAIN_EXTENSION_NAME); image_format_list = add_extension(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME); shader_stencil_export = add_extension(VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME); + tooling_info = add_extension(VK_EXT_TOOLING_INFO_EXTENSION_NAME); const bool has_timeline_semaphores = add_extension( VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME, is_qualcomm, "it is broken on Qualcomm drivers"); const bool has_portability_subset = add_extension(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME); @@ -580,4 +582,17 @@ void Instance::CollectTelemetryParameters() { vendor_name = driver.driverName.data(); } +void Instance::CollectToolingInfo() { + if (!tooling_info) { + return; + } + const auto tools = physical_device.getToolProperties(); + for (const vk::PhysicalDeviceToolProperties& tool : tools) { + const std::string_view name = tool.name; + LOG_INFO(Render_Vulkan, "Attached debugging tool: {}", name); + has_renderdoc = has_renderdoc || name == "RenderDoc"; + has_nsight_graphics = has_nsight_graphics || name == "NVIDIA Nsight Graphics"; + } +} + } // namespace Vulkan diff --git a/src/video_core/renderer_vulkan/vk_instance.h b/src/video_core/renderer_vulkan/vk_instance.h index b75bb1d3e..94e8f4a70 100644 --- a/src/video_core/renderer_vulkan/vk_instance.h +++ b/src/video_core/renderer_vulkan/vk_instance.h @@ -90,6 +90,16 @@ public: return present_queue; } + /// Returns true when a known debugging tool is attached. + bool HasDebuggingToolAttached() const { + return has_renderdoc || has_nsight_graphics; + } + + /// Returns true when VK_EXT_debug_utils is supported. + bool IsExtDebugUtilsSupported() const { + return debug_utils_supported; + } + /// Returns true if logic operations need shader emulation bool NeedsLogicOpEmulation() const { return !features.logicOp; @@ -145,11 +155,6 @@ public: return shader_stencil_export; } - /// Returns true if VK_EXT_debug_utils is supported - bool IsExtDebugUtilsSupported() const { - return debug_messenger_supported; - } - /// Returns the vendor ID of the physical device u32 GetVendorID() const { return properties.vendorID; @@ -249,6 +254,7 @@ private: /// Collects telemetry information from the device. void CollectTelemetryParameters(); + void CollectToolingInfo(); private: std::shared_ptr library; @@ -280,7 +286,10 @@ private: bool image_format_list{}; bool pipeline_creation_cache_control{}; bool shader_stencil_export{}; - bool debug_messenger_supported{}; + bool tooling_info{}; + bool debug_utils_supported{}; + bool has_nsight_graphics{}; + bool has_renderdoc{}; }; } // namespace Vulkan diff --git a/src/video_core/renderer_vulkan/vk_platform.cpp b/src/video_core/renderer_vulkan/vk_platform.cpp index 25beb60f9..a91914669 100644 --- a/src/video_core/renderer_vulkan/vk_platform.cpp +++ b/src/video_core/renderer_vulkan/vk_platform.cpp @@ -343,7 +343,7 @@ vk::UniqueDebugReportCallbackEXT CreateDebugReportCallback(vk::Instance instance return instance.createDebugReportCallbackEXTUnique(callback_ci); } -DebugCallback CreateDebugCallback(vk::Instance instance) { +DebugCallback CreateDebugCallback(vk::Instance instance, bool& debug_utils_supported) { if (!Settings::values.renderer_debug) { return {}; } @@ -356,7 +356,8 @@ DebugCallback CreateDebugCallback(vk::Instance instance) { return std::strcmp(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, prop.extensionName) == 0; }); // Prefer debug util messenger if available. - if (it != properties.end()) { + debug_utils_supported = it != properties.end(); + if (debug_utils_supported) { return CreateDebugMessenger(instance); } // Otherwise fallback to debug report callback. diff --git a/src/video_core/renderer_vulkan/vk_platform.h b/src/video_core/renderer_vulkan/vk_platform.h index f4b69e6c2..e80a0fb2d 100644 --- a/src/video_core/renderer_vulkan/vk_platform.h +++ b/src/video_core/renderer_vulkan/vk_platform.h @@ -29,6 +29,6 @@ vk::UniqueInstance CreateInstance(const Common::DynamicLibrary& library, Frontend::WindowSystemType window_type, bool enable_validation, bool dump_command_buffers); -DebugCallback CreateDebugCallback(vk::Instance instance); +DebugCallback CreateDebugCallback(vk::Instance instance, bool& debug_utils_supported); } // namespace Vulkan