diff --git a/src/dxvk/dxvk_shader.cpp b/src/dxvk/dxvk_shader.cpp index bb5dcb8d..af45e2f4 100644 --- a/src/dxvk/dxvk_shader.cpp +++ b/src/dxvk/dxvk_shader.cpp @@ -223,6 +223,41 @@ namespace dxvk { } + DxvkShaderModule DxvkShader::createShaderModule( + const Rc& vkd, + const DxvkBindingLayoutObjects* layout, + const DxvkShaderModuleCreateInfo& info) { + SpirvCodeBuffer spirvCode = m_code.decompress(); + uint32_t* code = spirvCode.data(); + + // Remap resource binding IDs + for (const auto& info : m_bindingOffsets) { + auto mappedBinding = layout->lookupBinding(info.bindingId); + + if (mappedBinding) { + code[info.bindingOffset] = mappedBinding->binding; + + if (info.constIdOffset) + code[info.constIdOffset] = mappedBinding->constId; + + if (info.setOffset) + code[info.setOffset] = mappedBinding->set; + } + } + + // For dual-source blending we need to re-map + // location 1, index 0 to location 0, index 1 + if (info.fsDualSrcBlend && m_o1IdxOffset && m_o1LocOffset) + std::swap(code[m_o1IdxOffset], code[m_o1LocOffset]); + + // Replace undefined input variables with zero + for (uint32_t u : bit::BitMask(info.undefinedInputs)) + eliminateInput(spirvCode, u); + + return DxvkShaderModule(vkd, this, spirvCode); + } + + void DxvkShader::dump(std::ostream& outputStream) const { m_code.decompress().store(outputStream); } diff --git a/src/dxvk/dxvk_shader.h b/src/dxvk/dxvk_shader.h index 1f1ba19c..b2192840 100644 --- a/src/dxvk/dxvk_shader.h +++ b/src/dxvk/dxvk_shader.h @@ -150,7 +150,22 @@ namespace dxvk { const Rc& vkd, const DxvkDescriptorSlotMapping& mapping, const DxvkShaderModuleCreateInfo& info); - + + /** + * \brief Creates a shader module + * + * Remaps resource binding and descriptor set + * numbers to match the given binding layout. + * \param [in] vkd Vulkan device functions + * \param [in] layout Binding layout + * \param [in] info Module create info + * \returns The shader module + */ + DxvkShaderModule createShaderModule( + const Rc& vkd, + const DxvkBindingLayoutObjects* layout, + const DxvkShaderModuleCreateInfo& info); + /** * \brief Dumps SPIR-V shader *