From a1827ee5e9b8088b23db3fa688b7bd62b7bbe9ac Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 23 Feb 2024 19:05:23 -0800 Subject: SPIRV Fixes. (#3622) * Use SpvSourceLanguageSlang enum. * Fix spirv entrypoint interface. * Cleanup. * Add error on unknown spirv opcode. * Fix CI. * Fix. --- source/slang/slang-emit-spirv.cpp | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'source/slang/slang-emit-spirv.cpp') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index b9e868b89..5761d3ec4 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -2816,18 +2816,6 @@ struct SPIRVEmitContext case kIROp_EntryPointDecoration: { auto section = getSection(SpvLogicalSectionID::EntryPoints); - - // TODO: The `OpEntryPoint` is required to list an varying - // input or output parameters (by ``) used by the entry point, - // although these are encoded as global variables in the IR. - // - // Currently we have a pass that moves entry-point varying - // parameters to global scope for the benefit of GLSL output, - // but we do not maintain a connection between those parameters - // and the original entry point. That pass should be updated - // to attach a decoration linking the original entry point - // to the new globals, which would be used in the SPIR-V emit case. - auto entryPointDecor = cast(decoration); auto entryPoint = as(decoration->getParent()); auto spvStage = mapStageToExecutionModel(entryPointDecor->getProfile().getStage()); @@ -2842,6 +2830,7 @@ struct SPIRVEmitContext { case kIROp_GlobalVar: case kIROp_GlobalParam: + case kIROp_SPIRVAsmOperandBuiltinVar: { SpvInst* spvGlobalInst; if (m_mapIRInstToSpvInst.tryGetValue(globalInst, spvGlobalInst)) @@ -2861,13 +2850,6 @@ struct SPIRVEmitContext break; } } - // Add remaining builtin variables that does not have a corresponding IR global var/param. - // These variables could be added from SPIRV ASM blocks. - for (auto builtinVar : m_builtinGlobalVars) - { - if (paramsSet.add(builtinVar.second)) - params.add(builtinVar.second); - } emitOpEntryPoint( section, decoration, @@ -3283,6 +3265,7 @@ struct SPIRVEmitContext } Dictionary m_builtinGlobalVars; + SpvInst* getBuiltinGlobalVar(IRType* type, SpvBuiltIn builtinVal) { SpvInst* result = nullptr; @@ -5273,9 +5256,19 @@ SlangResult emitSPIRVFromIR( } // Emit source language info. + // By default we will use SpvSourceLanguageSlang. + // However this will cause problems when using swiftshader. + // To workaround this problem, we allow overriding this behavior with an + // environment variable that will be set in the software testing environment. + auto sourceLanguage = SpvSourceLanguageSlang; + StringBuilder noSlangEnv; + PlatformUtil::getEnvironmentVariable(toSlice("SLANG_USE_SPV_SOURCE_LANGUAGE_UNKNOWN"), noSlangEnv); + if (noSlangEnv.produceString() == "1") + { + sourceLanguage = SpvSourceLanguageUnknown; + } context.emitInst(context.getSection(SpvLogicalSectionID::DebugStringsAndSource), nullptr, SpvOpSource, - // TODO: update this to SpvSourceLanguageSlang when a new release of spirv-tools is available. - SpvLiteralInteger::from32(0), // language identifier, should be SpvSourceLanguageSlang. + SpvLiteralInteger::from32(sourceLanguage), // language identifier, should be SpvSourceLanguageSlang. SpvLiteralInteger::from32(1)); // language version. for (auto irEntryPoint : irEntryPoints) -- cgit v1.2.3