From 1eb13dfa5e143745b857fb5bc5b8f01571153bbc Mon Sep 17 00:00:00 2001 From: nmzik Date: Sun, 6 Sep 2026 04:11:46 +0400 Subject: [PATCH] render: call Vulkan diagnostics and capability checks directly --- src/graphics/host_gpu/graphicContext.h | 5 ++++- .../host_gpu/renderer/commandScheduler.cpp | 4 ++-- .../host_gpu/renderer/depthRenderTarget.cpp | 2 +- .../renderer/pipeline/pipelineCache.cpp | 8 ++++---- .../host_gpu/renderer/pipeline/shaders.cpp | 16 ++++++++-------- src/graphics/host_gpu/renderer/renderDraw.cpp | 2 +- src/graphics/host_gpu/vma.cpp | 2 +- src/graphics/host_gpu/vulkanCommon.cpp | 18 +----------------- src/graphics/host_gpu/vulkanCommon.h | 4 ---- src/graphics/presentation/window/swapchain.cpp | 4 ++-- .../presentation/window/vulkanWindow.cpp | 10 ++++------ tests/ShaderRecompilerComputeTests.cpp | 2 +- 12 files changed, 29 insertions(+), 48 deletions(-) diff --git a/src/graphics/host_gpu/graphicContext.h b/src/graphics/host_gpu/graphicContext.h index 4e156792a..6631d3cfc 100644 --- a/src/graphics/host_gpu/graphicContext.h +++ b/src/graphics/host_gpu/graphicContext.h @@ -31,7 +31,6 @@ struct GraphicContext { bool memory_budget_ext_enabled = false; bool rt_extensions_enabled = false; bool compute_subgroup_size_control_enabled = false; - bool compute_wave64_supported = false; bool sample_rate_shading_enabled = false; bool mesh_shader_enabled = false; vk::PhysicalDeviceMeshShaderPropertiesEXT mesh_shader_properties = {}; @@ -82,6 +81,10 @@ struct GraphicContext { return it->second.first; } + [[nodiscard]] bool SupportsComputeWave64() const noexcept { + return subgroup_size == 64u || compute_subgroup_size_control_enabled; + } + [[nodiscard]] vk::DeviceSize StorageMinAlignment() const { const auto alignment = physical_device_properties.limits.minStorageBufferOffsetAlignment; return alignment != 0 ? alignment : 1; diff --git a/src/graphics/host_gpu/renderer/commandScheduler.cpp b/src/graphics/host_gpu/renderer/commandScheduler.cpp index 231948d86..773736003 100644 --- a/src/graphics/host_gpu/renderer/commandScheduler.cpp +++ b/src/graphics/host_gpu/renderer/commandScheduler.cpp @@ -19,11 +19,11 @@ void ReportVulkanFatal(const char* what, vk::Result result, uint64_t tick, uint3 uint32_t arg3, uint64_t arg4) { LOGF("%s failed: %s (%d), tick=%" PRIu64 " debug_op=%u debug_submit=%" PRIu64 " args=%u,%u,%u,%u,0x%016" PRIx64 "\n", - what, VulkanToString(result).c_str(), static_cast(result), tick, debug_op, + what, vk::to_string(result).c_str(), static_cast(result), tick, debug_op, debug_submit, arg0, arg1, arg2, arg3, arg4); std::printf("%s failed: %s (%d), tick=%" PRIu64 " debug_op=%u debug_submit=%" PRIu64 " args=%u,%u,%u,%u,0x%016" PRIx64 "\n", - what, VulkanToString(result).c_str(), static_cast(result), tick, debug_op, + what, vk::to_string(result).c_str(), static_cast(result), tick, debug_op, debug_submit, arg0, arg1, arg2, arg3, arg4); std::fflush(stdout); } diff --git a/src/graphics/host_gpu/renderer/depthRenderTarget.cpp b/src/graphics/host_gpu/renderer/depthRenderTarget.cpp index 810b379e8..ecbb23790 100644 --- a/src/graphics/host_gpu/renderer/depthRenderTarget.cpp +++ b/src/graphics/host_gpu/renderer/depthRenderTarget.cpp @@ -206,7 +206,7 @@ void RenderExecutor::ResolveRenderDepthTarget(uint64_t submit_id, CommandBuffer& const auto format = ResolveHostDepthAttachmentFormat(buffer, *policy, has_stencil, samples); if (format == vk::Format::eUndefined) { DepthFatal("no host depth/stencil format supports required usage for %s", - VulkanToString(ideal_format).c_str()); + vk::to_string(ideal_format).c_str()); } const auto guest_format = policy->guest_format; const uint32_t bytes = policy->bytes_per_element; diff --git a/src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp b/src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp index 167848e83..c2bffcabe 100644 --- a/src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp +++ b/src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp @@ -455,14 +455,14 @@ void PipelineCache::InitializeDriverCache() { auto result = m_graphics.device.createPipelineCache(&create, nullptr, &m_driver_cache); if (result != vk::Result::eSuccess && !initial_data.empty()) { PipelineCacheLog("Vulkan pipeline cache: driver rejected {} ({}); starting empty", path, - VulkanToString(result)); + vk::to_string(result)); initial_data.clear(); create.initialDataSize = 0; create.pInitialData = nullptr; result = m_graphics.device.createPipelineCache(&create, nullptr, &m_driver_cache); } if (result != vk::Result::eSuccess) { - PipelineCacheLog("Vulkan pipeline cache: disabled ({})", VulkanToString(result)); + PipelineCacheLog("Vulkan pipeline cache: disabled ({})", vk::to_string(result)); m_driver_cache = nullptr; return; } @@ -499,7 +499,7 @@ void PipelineCache::Save() { if (result != vk::Result::eSuccess || size == 0 || size > std::numeric_limits::max()) { PipelineCacheLog("Vulkan pipeline cache: save failed ({}, {} bytes)", - VulkanToString(result), size); + vk::to_string(result), size); return; } payload.resize(size); @@ -590,7 +590,7 @@ PipelineCache::GraphicsPrograms PipelineCache::GetGraphicsPrograms( ShaderProgram PipelineCache::GetComputeProgram(const HW::ComputeShaderInfo& regs, const HW::ShaderRegisters& sh, ShaderComputeInputInfo& input_info) { - input_info.host_subgroup_size = m_graphics.compute_wave64_supported ? 64u : 32u; + input_info.host_subgroup_size = m_graphics.SupportsComputeWave64() ? 64u : 32u; const auto params = PrepareProgram(regs, sh, input_info); Common::LockGuard lock(m_mutex); uint32_t push_data_cursor = 0; diff --git a/src/graphics/host_gpu/renderer/pipeline/shaders.cpp b/src/graphics/host_gpu/renderer/pipeline/shaders.cpp index 1be8d558d..7f99b00d6 100644 --- a/src/graphics/host_gpu/renderer/pipeline/shaders.cpp +++ b/src/graphics/host_gpu/renderer/pipeline/shaders.cpp @@ -103,7 +103,7 @@ static void GetInputFormat(const ShaderBufferResource& res, vk::Format& format, size = 4; if (NarrowInputFormat(format, size, used_components)) { LOGF("InputFormat: narrowing fmt=%u to %s for used_components=%u\n", raw_format, - VulkanToString(format).c_str(), used_components); + vk::to_string(format).c_str(), used_components); } return; } @@ -117,7 +117,7 @@ static void GetInputFormat(const ShaderBufferResource& res, vk::Format& format, size = 2; if (NarrowInputFormat(format, size, used_components)) { LOGF("InputFormat: narrowing fmt=%u to %s for used_components=%u\n", raw_format, - VulkanToString(format).c_str(), used_components); + vk::to_string(format).c_str(), used_components); } return; } @@ -450,7 +450,7 @@ void CreatePipelineInternal( graphics.device.createShaderModule(&create_info, nullptr, &tess_control_shader_module); if (graphics_debug_dump_enabled()) { LOGF("PipelineTrace: vkCreateShaderModule RectList TCS done result=%s module=%p\n", - VulkanToString(result).c_str(), static_cast(tess_control_shader_module)); + vk::to_string(result).c_str(), static_cast(tess_control_shader_module)); } EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); @@ -460,7 +460,7 @@ void CreatePipelineInternal( graphics.device.createShaderModule(&create_info, nullptr, &tess_eval_shader_module); if (graphics_debug_dump_enabled()) { LOGF("PipelineTrace: vkCreateShaderModule RectList TES done result=%s module=%p\n", - VulkanToString(result).c_str(), static_cast(tess_eval_shader_module)); + vk::to_string(result).c_str(), static_cast(tess_eval_shader_module)); } EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); } @@ -678,7 +678,7 @@ void CreatePipelineInternal( &pipeline.pipeline_layout); if (graphics_debug_dump_enabled()) { LOGF("PipelineTrace: vkCreatePipelineLayout done result=%s layout=%p\n", - VulkanToString(result).c_str(), static_cast(pipeline.pipeline_layout)); + vk::to_string(result).c_str(), static_cast(pipeline.pipeline_layout)); } EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); @@ -771,7 +771,7 @@ void CreatePipelineInternal( &pipeline.pipeline); if (graphics_debug_dump_enabled()) { LOGF("PipelineTrace: vkCreateGraphicsPipelines done result=%s pipeline=%p\n", - VulkanToString(result).c_str(), static_cast(pipeline.pipeline)); + vk::to_string(result).c_str(), static_cast(pipeline.pipeline)); } EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); @@ -824,7 +824,7 @@ void CreatePipelineInternal(GraphicContext& graphics, PipelineCache::Pipeline& p auto result = graphics.device.createPipelineLayout(&pipeline_layout_info, nullptr, &pipeline.pipeline_layout); LOGF("PipelineTrace: vkCreatePipelineLayout CS done result=%s layout=%p\n", - VulkanToString(result).c_str(), static_cast(pipeline.pipeline_layout)); + vk::to_string(result).c_str(), static_cast(pipeline.pipeline_layout)); EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); EXIT_NOT_IMPLEMENTED(pipeline.pipeline_layout == nullptr); @@ -841,7 +841,7 @@ void CreatePipelineInternal(GraphicContext& graphics, PipelineCache::Pipeline& p result = graphics.device.createComputePipelines(driver_cache, 1, &info, nullptr, &pipeline.pipeline); LOGF("PipelineTrace: vkCreateComputePipelines done result=%s pipeline=%p\n", - VulkanToString(result).c_str(), static_cast(pipeline.pipeline)); + vk::to_string(result).c_str(), static_cast(pipeline.pipeline)); EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess); EXIT_NOT_IMPLEMENTED(pipeline.pipeline == nullptr); diff --git a/src/graphics/host_gpu/renderer/renderDraw.cpp b/src/graphics/host_gpu/renderer/renderDraw.cpp index 34ce276b9..17d0e3231 100644 --- a/src/graphics/host_gpu/renderer/renderDraw.cpp +++ b/src/graphics/host_gpu/renderer/renderDraw.cpp @@ -133,7 +133,7 @@ static void LogFramebufferSkip(const char* draw_name, const RenderColorInfo& col " prim=%u index_count=%u flags=0x%08" PRIx32 "\n", log_id, draw_name, RenderColorTypeName(color), color.desc.info.data.address, color.desc.info.data.size, color.image_id ? "yes" : "no", - VulkanToString(depth.desc.view_info.format).c_str(), depth.image_id ? "yes" : "no", + vk::to_string(depth.desc.view_info.format).c_str(), depth.image_id ? "yes" : "no", static_cast(!depth.desc.info.data.Empty()) + static_cast(depth.desc.info.HasStencil()), ctx.GetRenderTargetMask(), static_cast(ucfg.GetPrimType()), index_count, flags); diff --git a/src/graphics/host_gpu/vma.cpp b/src/graphics/host_gpu/vma.cpp index baba436e0..70035bca6 100644 --- a/src/graphics/host_gpu/vma.cpp +++ b/src/graphics/host_gpu/vma.cpp @@ -71,7 +71,7 @@ bool GraphicContext::CreateAllocator() { const auto result = static_cast(vmaCreateAllocator(&info, &allocator)); if (result != vk::Result::eSuccess) { - LOGF("vmaCreateAllocator failed: %s\n", VulkanToString(result).c_str()); + LOGF("vmaCreateAllocator failed: %s\n", vk::to_string(result).c_str()); return false; } return true; diff --git a/src/graphics/host_gpu/vulkanCommon.cpp b/src/graphics/host_gpu/vulkanCommon.cpp index 91b5c7335..f7e6e0b8d 100644 --- a/src/graphics/host_gpu/vulkanCommon.cpp +++ b/src/graphics/host_gpu/vulkanCommon.cpp @@ -96,22 +96,6 @@ constexpr auto kFormatLookup = MakeFormatLookup(); } // namespace -std::string VulkanToString(vk::Result value) { - return vk::to_string(value); -} - -std::string VulkanToString(vk::Format value) { - return vk::to_string(value); -} - -std::string VulkanToString(vk::ImageLayout value) { - return vk::to_string(value); -} - -std::string VulkanToString(vk::QueueFlags value) { - return vk::to_string(value); -} - vk::Format VulkanFormat(Prospero::BufferFormat guest_format) { const auto index = static_cast(guest_format); return index < kFormatLookup.size() ? kFormatLookup[index] : vk::Format::eUndefined; @@ -119,7 +103,7 @@ vk::Format VulkanFormat(Prospero::BufferFormat guest_format) { void RequireVulkanSuccess(vk::Result result, const char* operation) { if (result != vk::Result::eSuccess) { - EXIT("%s failed: %s (%d)\n", operation, VulkanToString(result).c_str(), + EXIT("%s failed: %s (%d)\n", operation, vk::to_string(result).c_str(), static_cast(result)); } } diff --git a/src/graphics/host_gpu/vulkanCommon.h b/src/graphics/host_gpu/vulkanCommon.h index bc0fe9227..6c8998a42 100644 --- a/src/graphics/host_gpu/vulkanCommon.h +++ b/src/graphics/host_gpu/vulkanCommon.h @@ -25,10 +25,6 @@ namespace Libs::Graphics { using VulkanMemoryBarrier = vk::MemoryBarrier; -std::string VulkanToString(vk::Result value); -std::string VulkanToString(vk::Format value); -std::string VulkanToString(vk::ImageLayout value); -std::string VulkanToString(vk::QueueFlags value); vk::Format VulkanFormat(Prospero::BufferFormat guest_format); void RequireVulkanSuccess(vk::Result result, const char* operation); diff --git a/src/graphics/presentation/window/swapchain.cpp b/src/graphics/presentation/window/swapchain.cpp index 6d3906ff7..ce54cf4f1 100644 --- a/src/graphics/presentation/window/swapchain.cpp +++ b/src/graphics/presentation/window/swapchain.cpp @@ -573,7 +573,7 @@ Swapchain::Status Swapchain::AcquireNextImage() { case vk::Result::eErrorSurfaceLostKHR: LOGF("vkAcquireNextImageKHR returned vk::Result::eErrorSurfaceLostKHR\n"); return Status::SurfaceLost; - default: EXIT("vkAcquireNextImageKHR failed: %s\n", VulkanToString(result).c_str()); + default: EXIT("vkAcquireNextImageKHR failed: %s\n", vk::to_string(result).c_str()); } EXIT_IF(m_image_index >= m_images.size()); return Status::Success; @@ -702,7 +702,7 @@ Swapchain::Status Swapchain::Present() { case vk::Result::eErrorSurfaceLostKHR: LOGF("vkQueuePresentKHR returned vk::Result::eErrorSurfaceLostKHR\n"); return Status::SurfaceLost; - default: EXIT("vkQueuePresentKHR failed: %s\n", VulkanToString(result).c_str()); + default: EXIT("vkQueuePresentKHR failed: %s\n", vk::to_string(result).c_str()); } m_frame_index = (m_frame_index + 1u) % static_cast(m_images.size()); return Status::Success; diff --git a/src/graphics/presentation/window/vulkanWindow.cpp b/src/graphics/presentation/window/vulkanWindow.cpp index 77ebbd597..b05b4c576 100644 --- a/src/graphics/presentation/window/vulkanWindow.cpp +++ b/src/graphics/presentation/window/vulkanWindow.cpp @@ -143,7 +143,7 @@ static uint32_t VulkanFindQueueFamily(vk::PhysicalDevice device, vk::SurfaceKHR "vkGetPhysicalDeviceSurfaceSupportKHR"); LOGF("\tqueue family: %s [count = %u], [present = %s]\n", - VulkanToString(properties.queueFlags).c_str(), properties.queueCount, + vk::to_string(properties.queueFlags).c_str(), properties.queueCount, (presentation_supported == VK_TRUE ? "true" : "false")); if (properties.queueCount != 0 && (properties.queueFlags & required) == required && presentation_supported == VK_TRUE) { @@ -525,14 +525,12 @@ static void VulkanInitSubgroupSizeControl(vk::PhysicalDevice physical_device, (graphics.required_subgroup_size_stages & vk::ShaderStageFlagBits::eCompute) && subgroup_size_control.minSubgroupSize <= 64 && subgroup_size_control.maxSubgroupSize >= 64; - graphics.compute_wave64_supported = - graphics.subgroup_size == 64u || graphics.compute_subgroup_size_control_enabled; LOGF("Vulkan subgroup: default=%u min=%u max=%u stages=0x%08x size_control=%s wave64=%s\n", graphics.subgroup_size, graphics.min_subgroup_size, graphics.max_subgroup_size, static_cast(graphics.required_subgroup_size_stages), graphics.compute_subgroup_size_control_enabled ? "true" : "false", - graphics.compute_wave64_supported ? "true" : "false"); + graphics.SupportsComputeWave64() ? "true" : "false"); } static vk::Device VulkanCreateDevice(vk::PhysicalDevice physical_device, const VulkanExtensions& r, @@ -724,7 +722,7 @@ static vk::Device VulkanCreateDevice(vk::PhysicalDevice physical_device, const V auto result = physical_device.createDevice(&create_info, nullptr, &device); if (result != vk::Result::eSuccess) { - LOGF("vkCreateDevice failed: %s\n", VulkanToString(result).c_str()); + LOGF("vkCreateDevice failed: %s\n", vk::to_string(result).c_str()); return nullptr; } @@ -903,7 +901,7 @@ static void VulkanCheckInstanceVersion() { if (VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion != nullptr) { auto result = vk::enumerateInstanceVersion(&version); if (result != vk::Result::eSuccess) { - EXIT("Could not query Vulkan loader version: %s\n", VulkanToString(result).c_str()); + EXIT("Could not query Vulkan loader version: %s\n", vk::to_string(result).c_str()); } } diff --git a/tests/ShaderRecompilerComputeTests.cpp b/tests/ShaderRecompilerComputeTests.cpp index a9d335d93..8443763ef 100644 --- a/tests/ShaderRecompilerComputeTests.cpp +++ b/tests/ShaderRecompilerComputeTests.cpp @@ -892,7 +892,7 @@ std::string Hex(u32 value) { } std::string VulkanResultName(vk::Result result) { - return VulkanToString(result); + return vk::to_string(result); } [[noreturn]] void Fail(const char *shader_name, const char *stage,