From ae0e5bccdd22f3bcbcf542189a921a5458c48779 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 3 May 2018 20:26:55 +0200 Subject: [PATCH] [dxvk] Make shader accessible from shader module --- src/dxvk/dxvk_compute.cpp | 4 ++-- src/dxvk/dxvk_graphics.cpp | 10 ++++---- src/dxvk/dxvk_shader.cpp | 13 +++++------ src/dxvk/dxvk_shader.h | 48 +++++++++++++++++++++++++------------- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/dxvk/dxvk_compute.cpp b/src/dxvk/dxvk_compute.cpp index 80f5ac9a1..ee4f5daa1 100644 --- a/src/dxvk/dxvk_compute.cpp +++ b/src/dxvk/dxvk_compute.cpp @@ -96,7 +96,7 @@ namespace dxvk { if (Logger::logLevel() <= LogLevel::Debug) { Logger::debug("Compiling compute pipeline..."); - Logger::debug(str::format(" cs : ", m_cs ->debugName())); + Logger::debug(str::format(" cs : ", m_cs->shader()->debugName())); } std::array specData; @@ -131,7 +131,7 @@ namespace dxvk { if (m_vkd->vkCreateComputePipelines(m_vkd->device(), m_cache->handle(), 1, &info, nullptr, &pipeline) != VK_SUCCESS) { Logger::err("DxvkComputePipeline: Failed to compile pipeline"); - Logger::err(str::format(" cs : ", m_cs ->debugName())); + Logger::err(str::format(" cs : ", m_cs->shader()->debugName())); return VK_NULL_HANDLE; } diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index cc707beb2..0962d2f9d 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -363,11 +363,11 @@ namespace dxvk { void DxvkGraphicsPipeline::logPipelineState( LogLevel level, const DxvkGraphicsPipelineStateInfo& state) const { - if (m_vs != nullptr) Logger::log(level, str::format(" vs : ", m_vs ->debugName())); - if (m_tcs != nullptr) Logger::log(level, str::format(" tcs : ", m_tcs->debugName())); - if (m_tes != nullptr) Logger::log(level, str::format(" tes : ", m_tes->debugName())); - if (m_gs != nullptr) Logger::log(level, str::format(" gs : ", m_gs ->debugName())); - if (m_fs != nullptr) Logger::log(level, str::format(" fs : ", m_fs ->debugName())); + if (m_vs != nullptr) Logger::log(level, str::format(" vs : ", m_vs ->shader()->debugName())); + if (m_tcs != nullptr) Logger::log(level, str::format(" tcs : ", m_tcs->shader()->debugName())); + if (m_tes != nullptr) Logger::log(level, str::format(" tes : ", m_tes->shader()->debugName())); + if (m_gs != nullptr) Logger::log(level, str::format(" gs : ", m_gs ->shader()->debugName())); + if (m_fs != nullptr) Logger::log(level, str::format(" fs : ", m_fs ->shader()->debugName())); // TODO log more pipeline state } diff --git a/src/dxvk/dxvk_shader.cpp b/src/dxvk/dxvk_shader.cpp index 65b962fe9..b65ca2d3b 100644 --- a/src/dxvk/dxvk_shader.cpp +++ b/src/dxvk/dxvk_shader.cpp @@ -4,10 +4,9 @@ namespace dxvk { DxvkShaderModule::DxvkShaderModule( const Rc& vkd, - VkShaderStageFlagBits stage, - const SpirvCodeBuffer& code, - const std::string& name) - : m_vkd(vkd), m_stage(stage), m_debugName(name) { + const Rc& shader, + const SpirvCodeBuffer& code) + : m_vkd(vkd), m_shader(shader) { VkShaderModuleCreateInfo info; info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; info.pNext = nullptr; @@ -32,7 +31,7 @@ namespace dxvk { info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; info.pNext = nullptr; info.flags = 0; - info.stage = m_stage; + info.stage = m_shader->stage(); info.module = m_module; info.pName = "main"; info.pSpecializationInfo = specInfo; @@ -95,7 +94,7 @@ namespace dxvk { Rc DxvkShader::createShaderModule( const Rc& vkd, - const DxvkDescriptorSlotMapping& mapping) const { + const DxvkDescriptorSlotMapping& mapping) { SpirvCodeBuffer spirvCode = m_code; // Remap resource binding IDs @@ -103,7 +102,7 @@ namespace dxvk { for (uint32_t ofs : m_idOffsets) code[ofs] = mapping.getBindingId(code[ofs]); - return new DxvkShaderModule(vkd, m_stage, spirvCode, m_debugName); + return new DxvkShaderModule(vkd, this, spirvCode); } diff --git a/src/dxvk/dxvk_shader.h b/src/dxvk/dxvk_shader.h index 2387fe5c4..9c39ac1db 100644 --- a/src/dxvk/dxvk_shader.h +++ b/src/dxvk/dxvk_shader.h @@ -9,6 +9,8 @@ namespace dxvk { + class DxvkShader; + /** * \brief Shader interface slots * @@ -36,9 +38,8 @@ namespace dxvk { DxvkShaderModule( const Rc& vkd, - VkShaderStageFlagBits stage, - const SpirvCodeBuffer& code, - const std::string& name); + const Rc& shader, + const SpirvCodeBuffer& code); ~DxvkShaderModule(); @@ -60,19 +61,18 @@ namespace dxvk { const VkSpecializationInfo* specInfo) const; /** - * \brief The shader's debug name - * \returns Debug name + * \brief Shader object + * \returns The shader */ - const std::string& debugName() const { - return m_debugName; + Rc shader() const { + return m_shader; } private: Rc m_vkd; - VkShaderStageFlagBits m_stage; + Rc m_shader; VkShaderModule m_module; - std::string m_debugName; }; @@ -98,6 +98,14 @@ namespace dxvk { ~DxvkShader(); + /** + * \brief Shader stage + * \returns Shader stage + */ + VkShaderStageFlagBits stage() const { + return m_stage; + } + /** * \brief Checks whether a capability is enabled * @@ -130,7 +138,7 @@ namespace dxvk { */ Rc createShaderModule( const Rc& vkd, - const DxvkDescriptorSlotMapping& mapping) const; + const DxvkDescriptorSlotMapping& mapping); /** * \brief Inter-stage interface slots @@ -159,6 +167,16 @@ namespace dxvk { */ void read(std::istream& inputStream); + /** + * \brief Shader hash + * + * The SHA-1 hash of the generated SPIR-V shader. + * \returns SHA-1 hash of this shader + */ + Sha1Hash hash() const { + return m_hash; + } + /** * \brief Sets the shader's debug name * @@ -171,13 +189,11 @@ namespace dxvk { } /** - * \brief Shader hash - * - * The SHA-1 hash of the generated SPIR-V shader. - * \returns SHA-1 hash of this shader + * \brief Retrieves debug name + * \returns The shader's name */ - Sha1Hash hash() const { - return m_hash; + std::string debugName() const { + return m_debugName; } private: