diff --git a/src/d3d11/d3d11_shader.cpp b/src/d3d11/d3d11_shader.cpp index 3e172936c..98b9693f2 100644 --- a/src/d3d11/d3d11_shader.cpp +++ b/src/d3d11/d3d11_shader.cpp @@ -35,6 +35,22 @@ namespace dxvk { m_shader->dump(std::ofstream(str::format(baseName, ".spv"), std::ios_base::binary | std::ios_base::trunc)); } + + + // If requested by the user, replace + // the shader with another file. + const std::string readPath + = env::getEnvVar(L"DXVK_SHADER_READ_PATH"); + + if (readPath.size() != 0) { + const std::string baseName = str::format(readPath, "/", + ConstructFileName(ComputeShaderHash(pShaderBytecode, BytecodeLength), + module.version().type())); + + m_shader->read(std::ifstream( + str::format(baseName, ".spv"), + std::ios_base::binary)); + } } diff --git a/src/dxvk/dxvk_shader.cpp b/src/dxvk/dxvk_shader.cpp index 2f90dbdaa..74deb6ea3 100644 --- a/src/dxvk/dxvk_shader.cpp +++ b/src/dxvk/dxvk_shader.cpp @@ -88,4 +88,9 @@ namespace dxvk { m_code.store(std::move(outputStream)); } + + void DxvkShader::read(std::istream&& inputStream) { + m_code = SpirvCodeBuffer(std::move(inputStream)); + } + } \ No newline at end of file diff --git a/src/dxvk/dxvk_shader.h b/src/dxvk/dxvk_shader.h index d97e9511e..4f63e3997 100644 --- a/src/dxvk/dxvk_shader.h +++ b/src/dxvk/dxvk_shader.h @@ -105,6 +105,14 @@ namespace dxvk { */ void dump(std::ostream&& outputStream) const; + /** + * \brief Reads SPIR-V shader + * + * Can be used to replace the compiled SPIR-V code. + * \param [in] inputStream Stream to read from + */ + void read(std::istream&& inputStream); + private: VkShaderStageFlagBits m_stage;