From ad6c45d6b10fd80535f5e7d6d8474eecfbbf1926 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 7 Feb 2018 16:44:30 +0100 Subject: [PATCH] [dxvk] Improve debuggability of shader compiler issues When using DXVK_LOG_LEVEL=debug, the graphics pipeline manager now prints the names of the shaders used by the pipeline. This shall help debug driver crashes in vkCreate*Pipelines. --- src/d3d11/d3d11_shader.cpp | 3 ++- src/dxvk/dxvk_graphics.cpp | 17 +++++++++++++++++ src/dxvk/dxvk_graphics.h | 3 +++ src/dxvk/dxvk_shader.cpp | 7 ++++--- src/dxvk/dxvk_shader.h | 24 +++++++++++++++++++++++- src/util/log/log.h | 4 ++++ 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/d3d11/d3d11_shader.cpp b/src/d3d11/d3d11_shader.cpp index f44f8536d..bb0380104 100644 --- a/src/d3d11/d3d11_shader.cpp +++ b/src/d3d11/d3d11_shader.cpp @@ -37,7 +37,8 @@ namespace dxvk { } m_shader = module.compile(*pDxbcOptions); - + m_shader->setDebugName(m_name); + if (dumpPath.size() != 0) { m_shader->dump(std::ofstream(str::format(dumpPath, "/", m_name, ".spv"), std::ios_base::binary | std::ios_base::trunc)); diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index 749c242c6..7c07db997 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -94,6 +94,9 @@ namespace dxvk { VkPipeline DxvkGraphicsPipeline::compilePipeline( const DxvkGraphicsPipelineStateInfo& state, VkPipeline baseHandle) const { + if (Logger::logLevel() <= LogLevel::Debug) + this->logPipelineState(state); + std::array dynamicStates = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, @@ -304,4 +307,18 @@ namespace dxvk { return VK_RASTERIZATION_ORDER_STRICT_AMD; } + + void DxvkGraphicsPipeline::logPipelineState( + const DxvkGraphicsPipelineStateInfo& state) const { + Logger::debug("Compiling graphics pipeline..."); + + if (m_vs != nullptr) Logger::debug(str::format(" vs : ", m_vs ->debugName())); + if (m_tcs != nullptr) Logger::debug(str::format(" tcs : ", m_tcs->debugName())); + if (m_tes != nullptr) Logger::debug(str::format(" tes : ", m_tes->debugName())); + if (m_gs != nullptr) Logger::debug(str::format(" gs : ", m_gs ->debugName())); + if (m_fs != nullptr) Logger::debug(str::format(" fs : ", m_fs ->debugName())); + + // TODO log more pipeline state + } + } \ No newline at end of file diff --git a/src/dxvk/dxvk_graphics.h b/src/dxvk/dxvk_graphics.h index 4c26dcf22..eed9da6a0 100644 --- a/src/dxvk/dxvk_graphics.h +++ b/src/dxvk/dxvk_graphics.h @@ -162,6 +162,9 @@ namespace dxvk { VkRasterizationOrderAMD pickRasterizationOrder( const DxvkGraphicsPipelineStateInfo& state) const; + void logPipelineState( + const DxvkGraphicsPipelineStateInfo& state) const; + }; } \ No newline at end of file diff --git a/src/dxvk/dxvk_shader.cpp b/src/dxvk/dxvk_shader.cpp index 91e1e683f..765597274 100644 --- a/src/dxvk/dxvk_shader.cpp +++ b/src/dxvk/dxvk_shader.cpp @@ -5,8 +5,9 @@ namespace dxvk { DxvkShaderModule::DxvkShaderModule( const Rc& vkd, VkShaderStageFlagBits stage, - const SpirvCodeBuffer& code) - : m_vkd(vkd), m_stage(stage) { + const SpirvCodeBuffer& code, + const std::string& name) + : m_vkd(vkd), m_stage(stage), m_debugName(name) { VkShaderModuleCreateInfo info; info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; info.pNext = nullptr; @@ -81,7 +82,7 @@ namespace dxvk { } } - return new DxvkShaderModule(vkd, m_stage, spirvCode); + return new DxvkShaderModule(vkd, m_stage, spirvCode, m_debugName); } diff --git a/src/dxvk/dxvk_shader.h b/src/dxvk/dxvk_shader.h index 561e8ff83..3ee179e93 100644 --- a/src/dxvk/dxvk_shader.h +++ b/src/dxvk/dxvk_shader.h @@ -37,7 +37,8 @@ namespace dxvk { DxvkShaderModule( const Rc& vkd, VkShaderStageFlagBits stage, - const SpirvCodeBuffer& code); + const SpirvCodeBuffer& code, + const std::string& name); ~DxvkShaderModule(); @@ -58,11 +59,20 @@ namespace dxvk { VkPipelineShaderStageCreateInfo stageInfo( const VkSpecializationInfo* specInfo) const; + /** + * \brief The shader's debug name + * \returns Debug name + */ + const std::string& debugName() const { + return m_debugName; + } + private: Rc m_vkd; VkShaderStageFlagBits m_stage; VkShaderModule m_module; + std::string m_debugName; }; @@ -137,6 +147,17 @@ namespace dxvk { */ void read(std::istream&& inputStream); + /** + * \brief Sets the shader's debug name + * + * Debug names may be used by the backend in + * order to help debug shader compiler issues. + * \param [in] name The shader's name + */ + void setDebugName(const std::string& name) { + m_debugName = name; + } + private: VkShaderStageFlagBits m_stage; @@ -144,6 +165,7 @@ namespace dxvk { std::vector m_slots; DxvkInterfaceSlots m_interface; + std::string m_debugName; }; diff --git a/src/util/log/log.h b/src/util/log/log.h index 09e003323..9d97ddad1 100644 --- a/src/util/log/log.h +++ b/src/util/log/log.h @@ -35,6 +35,10 @@ namespace dxvk { static void warn (const std::string& message); static void err (const std::string& message); + static LogLevel logLevel() { + return s_instance.m_minLevel; + } + private: static Logger s_instance;