diff --git a/src/d3d11/d3d11_shader.cpp b/src/d3d11/d3d11_shader.cpp index 3d6a0642d..3753c075e 100644 --- a/src/d3d11/d3d11_shader.cpp +++ b/src/d3d11/d3d11_shader.cpp @@ -20,8 +20,6 @@ namespace dxvk { reinterpret_cast(pShaderBytecode), BytecodeLength); - DxbcModule module(reader); - // If requested by the user, dump both the raw DXBC // shader and the compiled SPIR-V module to a file. const std::string& dumpPath = pDevice->GetOptions()->shaderDumpPath; @@ -30,14 +28,21 @@ namespace dxvk { reader.store(std::ofstream(str::topath(str::format(dumpPath, "/", name, ".dxbc").c_str()).c_str(), std::ios_base::binary | std::ios_base::trunc)); } - + + // Error out if the shader is invalid + DxbcModule module(reader); + auto programInfo = module.programInfo(); + + if (!programInfo) + throw DxvkError("Invalid shader binary."); + // Decide whether we need to create a pass-through // geometry shader for vertex shader stream output bool passthroughShader = pDxbcModuleInfo->xfb != nullptr - && (module.programInfo().type() == DxbcProgramType::VertexShader - || module.programInfo().type() == DxbcProgramType::DomainShader); + && (programInfo->type() == DxbcProgramType::VertexShader + || programInfo->type() == DxbcProgramType::DomainShader); - if (module.programInfo().shaderStage() != pShaderKey->type() && !passthroughShader) + if (programInfo->shaderStage() != pShaderKey->type() && !passthroughShader) throw DxvkError("Mismatching shader type."); m_shader = passthroughShader diff --git a/src/dxbc/dxbc_module.h b/src/dxbc/dxbc_module.h index d785d9599..7609e2322 100644 --- a/src/dxbc/dxbc_module.h +++ b/src/dxbc/dxbc_module.h @@ -35,7 +35,10 @@ namespace dxvk { * \brief Shader type * \returns Shader type */ - DxbcProgramInfo programInfo() const { + std::optional programInfo() const { + if (m_shexChunk == nullptr) + return std::nullopt; + return m_shexChunk->programInfo(); }