diff options
| author | Yong He <yonghe@outlook.com> | 2024-02-23 19:05:23 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-23 19:05:23 -0800 |
| commit | a1827ee5e9b8088b23db3fa688b7bd62b7bbe9ac (patch) | |
| tree | eab251421b70f2ee64a0e420e270ed6295bd2987 /source | |
| parent | 401d8cdb12ae69aeb216c80c9bb90240d8359649 (diff) | |
SPIRV Fixes. (#3622)
* Use SpvSourceLanguageSlang enum.
* Fix spirv entrypoint interface.
* Cleanup.
* Add error on unknown spirv opcode.
* Fix CI.
* Fix.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/core.meta.slang | 2 | ||||
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 35 | ||||
| -rw-r--r-- | source/slang/slang-parser.cpp | 17 |
3 files changed, 32 insertions, 22 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index b02a44c5c..3131224b1 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -624,7 +624,7 @@ ${{{{ case BaseType::Float: case BaseType::Double: }}}} - [TreatAsDifferentiable] + [Differentiable] static $(kBaseTypes[tt].name) getPi() { return $(kBaseTypes[tt].name)(3.14159265358979323846264338328); } __intrinsic_op($(kIROp_Less)) bool lessThan(This other); 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 `<id>`) 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<IREntryPointDecoration>(decoration); auto entryPoint = as<IRFunc>(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<SpvBuiltIn, SpvInst*> 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) diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index f2aff32ea..7ce710469 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -7221,6 +7221,23 @@ namespace Slang break; } } + + if (ret.opcode.flavor == SPIRVAsmOperand::Flavor::NamedValue + && ret.opcode.knownValue == SpvOp(0xffffffff)) + { + if (ret.opcode.token.type == TokenType::IntegerLiteral) + { + Int intVal = -1; + StringUtil::parseInt(ret.opcode.token.getContent(), intVal); + ret.opcode.knownValue = (SpvWord)intVal; + } + else + { + parser->diagnose(ret.opcode.token, Diagnostics::unrecognizedSPIRVOpcode, ret.opcode.token); + return std::nullopt; + } + } + return ret; } |
