Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderer_vulkan: Simplify debug marker settings. #2159

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ static u32 vblankDivider = 1;
static bool vkValidation = false;
static bool vkValidationSync = false;
static bool vkValidationGpu = false;
static bool rdocEnable = false;
static bool vkMarkers = false;
static bool vkCrashDiagnostic = false;
static bool vkHostMarkers = false;
static bool vkGuestMarkers = false;
static bool rdocEnable = false;
static s16 cursorState = HideCursorState::Idle;
static int cursorHideTimeout = 5; // 5 seconds (default)
static bool separateupdatefolder = false;
Expand Down Expand Up @@ -227,10 +228,6 @@ bool isRdocEnabled() {
return rdocEnable;
}

bool isMarkersEnabled() {
return vkMarkers;
}

u32 vblankDiv() {
return vblankDivider;
}
Expand All @@ -247,14 +244,20 @@ bool vkValidationGpuEnabled() {
return vkValidationGpu;
}

bool vkMarkersEnabled() {
return vkMarkers || vkCrashDiagnostic; // Crash diagnostic forces markers on
}

bool vkCrashDiagnosticEnabled() {
return vkCrashDiagnostic;
}

bool vkHostMarkersEnabled() {
// Forced on when crash diagnostic enabled.
return vkHostMarkers || vkCrashDiagnostic;
}

bool vkGuestMarkersEnabled() {
// Forced on when crash diagnostic enabled.
return vkGuestMarkers || vkCrashDiagnostic;
}

bool getSeparateUpdateEnabled() {
return separateupdatefolder;
}
Expand Down Expand Up @@ -644,9 +647,10 @@ void load(const std::filesystem::path& path) {
vkValidation = toml::find_or<bool>(vk, "validation", false);
vkValidationSync = toml::find_or<bool>(vk, "validation_sync", false);
vkValidationGpu = toml::find_or<bool>(vk, "validation_gpu", true);
rdocEnable = toml::find_or<bool>(vk, "rdocEnable", false);
vkMarkers = toml::find_or<bool>(vk, "rdocMarkersEnable", false);
vkCrashDiagnostic = toml::find_or<bool>(vk, "crashDiagnostic", false);
vkHostMarkers = toml::find_or<bool>(vk, "hostMarkers", false);
vkGuestMarkers = toml::find_or<bool>(vk, "guestMarkers", false);
rdocEnable = toml::find_or<bool>(vk, "rdocEnable", false);
}

if (data.contains("Debug")) {
Expand Down Expand Up @@ -752,9 +756,10 @@ void save(const std::filesystem::path& path) {
data["Vulkan"]["validation"] = vkValidation;
data["Vulkan"]["validation_sync"] = vkValidationSync;
data["Vulkan"]["validation_gpu"] = vkValidationGpu;
data["Vulkan"]["rdocEnable"] = rdocEnable;
data["Vulkan"]["rdocMarkersEnable"] = vkMarkers;
data["Vulkan"]["crashDiagnostic"] = vkCrashDiagnostic;
data["Vulkan"]["hostMarkers"] = vkHostMarkers;
data["Vulkan"]["guestMarkers"] = vkGuestMarkers;
data["Vulkan"]["rdocEnable"] = rdocEnable;
data["Debug"]["DebugDump"] = isDebugDump;
data["Debug"]["CollectShader"] = isShaderDebug;

Expand Down Expand Up @@ -852,9 +857,10 @@ void setDefaultValues() {
vkValidation = false;
vkValidationSync = false;
vkValidationGpu = false;
rdocEnable = false;
vkMarkers = false;
vkCrashDiagnostic = false;
vkHostMarkers = false;
vkGuestMarkers = false;
rdocEnable = false;
emulator_language = "en";
m_language = 1;
gpuId = -1;
Expand Down
3 changes: 2 additions & 1 deletion src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ void setRdocEnabled(bool enable);
bool vkValidationEnabled();
bool vkValidationSyncEnabled();
bool vkValidationGpuEnabled();
bool vkMarkersEnabled();
bool vkCrashDiagnosticEnabled();
bool vkHostMarkersEnabled();
bool vkGuestMarkersEnabled();

// Gui
void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h);
Expand Down
5 changes: 3 additions & 2 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ Emulator::Emulator() {
LOG_INFO(Config, "Vulkan vkValidation: {}", Config::vkValidationEnabled());
LOG_INFO(Config, "Vulkan vkValidationSync: {}", Config::vkValidationSyncEnabled());
LOG_INFO(Config, "Vulkan vkValidationGpu: {}", Config::vkValidationGpuEnabled());
LOG_INFO(Config, "Vulkan rdocEnable: {}", Config::isRdocEnabled());
LOG_INFO(Config, "Vulkan rdocMarkersEnable: {}", Config::vkMarkersEnabled());
LOG_INFO(Config, "Vulkan crashDiagnostics: {}", Config::vkCrashDiagnosticEnabled());
LOG_INFO(Config, "Vulkan hostMarkers: {}", Config::vkHostMarkersEnabled());
LOG_INFO(Config, "Vulkan guestMarkers: {}", Config::vkGuestMarkersEnabled());
LOG_INFO(Config, "Vulkan rdocEnable: {}", Config::isRdocEnabled());

// Create stdin/stdout/stderr
Common::Singleton<FileSys::HandleTable>::Instance()->CreateStdHandles();
Expand Down
4 changes: 2 additions & 2 deletions src/imgui/renderer/imgui_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void Render(const vk::CommandBuffer& cmdbuf, ::Vulkan::Frame* frame) {
return;
}

if (Config::vkMarkersEnabled()) {
if (Config::vkHostMarkersEnabled()) {
cmdbuf.beginDebugUtilsLabelEXT(vk::DebugUtilsLabelEXT{
.pLabelName = "ImGui Render",
});
Expand All @@ -224,7 +224,7 @@ void Render(const vk::CommandBuffer& cmdbuf, ::Vulkan::Frame* frame) {
cmdbuf.beginRendering(render_info);
Vulkan::RenderDrawData(*draw_data, cmdbuf);
cmdbuf.endRendering();
if (Config::vkMarkersEnabled()) {
if (Config::vkHostMarkersEnabled()) {
cmdbuf.endDebugUtilsLabelEXT();
}
}
Expand Down
46 changes: 29 additions & 17 deletions src/video_core/amdgpu/liverpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
RESUME_GFX(ce_task);
}

if (rasterizer) {
rasterizer->ScopeMarkerBegin("gfx");
}

const auto base_addr = reinterpret_cast<uintptr_t>(dcb.data());
while (!dcb.empty()) {
const auto* header = reinterpret_cast<const PM4Header*>(dcb.data());
Expand Down Expand Up @@ -260,7 +264,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
const std::string_view label{reinterpret_cast<const char*>(&nop->data_block[1]),
marker_sz};
if (rasterizer) {
rasterizer->ScopeMarkerBegin(label);
rasterizer->ScopeMarkerBegin(label, true);
}
break;
}
Expand All @@ -271,13 +275,13 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
const u32 color = *reinterpret_cast<const u32*>(
reinterpret_cast<const u8*>(&nop->data_block[1]) + marker_sz);
if (rasterizer) {
rasterizer->ScopedMarkerInsertColor(label, color);
rasterizer->ScopedMarkerInsertColor(label, color, true);
}
break;
}
case PM4CmdNop::PayloadType::DebugMarkerPop: {
if (rasterizer) {
rasterizer->ScopeMarkerEnd();
rasterizer->ScopeMarkerEnd(true);
}
break;
}
Expand Down Expand Up @@ -412,7 +416,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}
if (rasterizer) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:DrawIndex2", cmd_address));
rasterizer->ScopeMarkerBegin(fmt::format("{}:DrawIndex2", cmd_address));
rasterizer->Draw(true);
rasterizer->ScopeMarkerEnd();
}
Expand All @@ -429,8 +433,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}
if (rasterizer) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(
fmt::format("dcb:{}:DrawIndexOffset2", cmd_address));
rasterizer->ScopeMarkerBegin(fmt::format("{}:DrawIndexOffset2", cmd_address));
rasterizer->Draw(true, draw_index_off->index_offset);
rasterizer->ScopeMarkerEnd();
}
Expand All @@ -445,7 +448,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}
if (rasterizer) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:DrawIndexAuto", cmd_address));
rasterizer->ScopeMarkerBegin(fmt::format("{}:DrawIndexAuto", cmd_address));
rasterizer->Draw(false);
rasterizer->ScopeMarkerEnd();
}
Expand All @@ -460,7 +463,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}
if (rasterizer) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:DrawIndirect", cmd_address));
rasterizer->ScopeMarkerBegin(fmt::format("{}:DrawIndirect", cmd_address));
rasterizer->DrawIndirect(false, indirect_args_addr, offset, size, 1, 0);
rasterizer->ScopeMarkerEnd();
}
Expand All @@ -476,8 +479,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}
if (rasterizer) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(
fmt::format("dcb:{}:DrawIndexIndirect", cmd_address));
rasterizer->ScopeMarkerBegin(fmt::format("{}:DrawIndexIndirect", cmd_address));
rasterizer->DrawIndirect(true, indirect_args_addr, offset, size, 1, 0);
rasterizer->ScopeMarkerEnd();
}
Expand All @@ -493,7 +495,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
if (rasterizer) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(
fmt::format("dcb:{}:DrawIndexIndirectCountMulti", cmd_address));
fmt::format("{}:DrawIndexIndirectCountMulti", cmd_address));
rasterizer->DrawIndirect(
true, indirect_args_addr, offset, draw_index_indirect->stride,
draw_index_indirect->count, draw_index_indirect->countAddr);
Expand All @@ -514,7 +516,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}
if (rasterizer && (cs_program.dispatch_initiator & 1)) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:Dispatch", cmd_address));
rasterizer->ScopeMarkerBegin(fmt::format("{}:DispatchDirect", cmd_address));
rasterizer->DispatchDirect();
rasterizer->ScopeMarkerEnd();
}
Expand All @@ -532,8 +534,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}
if (rasterizer && (cs_program.dispatch_initiator & 1)) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(
fmt::format("dcb:{}:DispatchIndirect", cmd_address));
rasterizer->ScopeMarkerBegin(fmt::format("{}:DispatchIndirect", cmd_address));
rasterizer->DispatchIndirect(indirect_args_addr, offset, size);
rasterizer->ScopeMarkerEnd();
}
Expand Down Expand Up @@ -701,6 +702,10 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}
}

if (rasterizer) {
rasterizer->ScopeMarkerEnd();
}

if (ce_task.handle) {
ASSERT_MSG(ce_task.handle.done(), "Partially processed CCB");
ce_task.handle.destroy();
Expand All @@ -714,6 +719,10 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, u32 vqid) {
FIBER_ENTER(acb_task_name[vqid]);
const auto& queue = asc_queues[{vqid}];

if (rasterizer) {
rasterizer->ScopeMarkerBegin(fmt::format("asc[{}]", vqid));
}

auto base_addr = reinterpret_cast<uintptr_t>(acb.data());
while (!acb.empty()) {
const auto* header = reinterpret_cast<const PM4Header*>(acb.data());
Expand Down Expand Up @@ -811,8 +820,7 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, u32 vqid) {
}
if (rasterizer && (cs_program.dispatch_initiator & 1)) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(
fmt::format("acb[{}]:{}:DispatchIndirect", vqid, cmd_address));
rasterizer->ScopeMarkerBegin(fmt::format("{}:DispatchDirect", cmd_address));
rasterizer->DispatchDirect();
rasterizer->ScopeMarkerEnd();
}
Expand All @@ -830,7 +838,7 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, u32 vqid) {
}
if (rasterizer && (cs_program.dispatch_initiator & 1)) {
const auto cmd_address = reinterpret_cast<const void*>(header);
rasterizer->ScopeMarkerBegin(fmt::format("acb[{}]:{}:Dispatch", vqid, cmd_address));
rasterizer->ScopeMarkerBegin(fmt::format("{}:DispatchIndirect", cmd_address));
rasterizer->DispatchIndirect(ib_address, 0, size);
rasterizer->ScopeMarkerEnd();
}
Expand Down Expand Up @@ -878,6 +886,10 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, u32 vqid) {
}
}

if (rasterizer) {
rasterizer->ScopeMarkerEnd();
}

FIBER_EXIT;
}

Expand Down
2 changes: 2 additions & 0 deletions src/video_core/buffer_cache/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ vk::BufferView Buffer::View(u32 offset, u32 size, bool is_written, AmdGpu::DataF
vk::to_string(view_result));
scheduler->DeferOperation(
[view, device = instance->GetDevice()] { device.destroyBufferView(view); });
Vulkan::SetObjectName(instance->GetDevice(), view, "BufferView {:#x}:{:#x}", cpu_addr + offset,
size);
return view;
}

Expand Down
11 changes: 3 additions & 8 deletions src/video_core/renderer_vulkan/vk_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ std::string GetReadableVersion(u32 version) {
Instance::Instance(bool enable_validation, bool enable_crash_diagnostic)
: instance{CreateInstance(Frontend::WindowSystemType::Headless, enable_validation,
enable_crash_diagnostic)},
physical_devices{EnumeratePhysicalDevices(instance)},
crash_diagnostic{enable_crash_diagnostic} {}
physical_devices{EnumeratePhysicalDevices(instance)} {}

Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index,
bool enable_validation /*= false*/, bool enable_crash_diagnostic /*= false*/)
: instance{CreateInstance(window.GetWindowInfo().type, enable_validation,
enable_crash_diagnostic)},
physical_devices{EnumeratePhysicalDevices(instance)},
crash_diagnostic{enable_crash_diagnostic} {
physical_devices{EnumeratePhysicalDevices(instance)} {
if (enable_validation) {
debug_callback = CreateDebugCallback(*instance);
}
Expand Down Expand Up @@ -562,10 +560,7 @@ void Instance::CollectToolingInfo() {
return;
}
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";
LOG_INFO(Render_Vulkan, "Attached debugging tool: {}", tool.name);
}
}

Expand Down
11 changes: 1 addition & 10 deletions src/video_core/renderer_vulkan/vk_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ class Instance {
return profiler_context;
}

/// Returns true when a known debugging tool is attached.
bool HasDebuggingToolAttached() const {
return crash_diagnostic || has_renderdoc || has_nsight_graphics;
}

/// Returns true if anisotropic filtering is supported
bool IsAnisotropicFilteringSupported() const {
return features.samplerAnisotropy;
Expand Down Expand Up @@ -340,13 +335,9 @@ class Instance {
bool legacy_vertex_attributes{};
bool image_load_store_lod{};
bool amd_gcn_shader{};
bool tooling_info{};
u64 min_imported_host_pointer_alignment{};
u32 subgroup_size{};
bool tooling_info{};
bool debug_utils_supported{};
bool crash_diagnostic{};
bool has_nsight_graphics{};
bool has_renderdoc{};
};

} // namespace Vulkan
7 changes: 7 additions & 0 deletions src/video_core/renderer_vulkan/vk_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <variant>
#include <fmt/format.h>

#include "common/config.h"
#include "common/logging/log.h"
#include "common/types.h"
#include "video_core/renderer_vulkan/vk_common.h"
Expand All @@ -32,6 +33,9 @@ concept VulkanHandleType = vk::isVulkanHandleType<T>::value;

template <VulkanHandleType HandleType>
void SetObjectName(vk::Device device, const HandleType& handle, std::string_view debug_name) {
if (!Config::vkHostMarkersEnabled()) {
return;
}
const vk::DebugUtilsObjectNameInfoEXT name_info = {
.objectType = HandleType::objectType,
.objectHandle = reinterpret_cast<u64>(static_cast<typename HandleType::NativeType>(handle)),
Expand All @@ -46,6 +50,9 @@ void SetObjectName(vk::Device device, const HandleType& handle, std::string_view
template <VulkanHandleType HandleType, typename... Args>
void SetObjectName(vk::Device device, const HandleType& handle, const char* format,
const Args&... args) {
if (!Config::vkHostMarkersEnabled()) {
return;
}
const std::string debug_name = fmt::vformat(format, fmt::make_format_args(args...));
SetObjectName(device, handle, debug_name);
}
Expand Down
Loading