diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-05-10 13:05:18 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-10 13:05:18 -0400 |
| commit | 8a02d1302264f37394736f953d318b431f64005e (patch) | |
| tree | 438374f864113ad7b0b65f45ef2f31e621d0f524 | |
| parent | 8c540f216f9fe9366bbe57732063607b41344b9f (diff) | |
Add support for `spirv_literal` (#2227)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Add SPIRVLiteralType, to mark types that have spirv_literal in function parameter output.
* Update test result.
Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com>
| -rw-r--r-- | source/slang/slang-emit-glsl.cpp | 9 | ||||
| -rw-r--r-- | source/slang/slang-ir-glsl-liveness.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-ir-inst-defs.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir-insts.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-ir.h | 7 | ||||
| -rw-r--r-- | tests/experimental/liveness/liveness.slang.expected | 4 |
7 files changed, 33 insertions, 5 deletions
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 5b2ae6d19..7578a2dd5 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -1845,10 +1845,15 @@ void GLSLSourceEmitter::emitParamTypeImpl(IRType* type, String const& name) { if (auto refType = as<IRRefType>(type)) { - // - m_writer->emit("spirv_by_reference "); + m_writer->emit("spirv_by_reference "); type = refType->getValueType(); } + else if (auto spirvLiteralType = as<IRSPIRVLiteralType>(type)) + { + m_writer->emit("spirv_literal "); + type = spirvLiteralType->getValueType(); + } + Super::emitParamTypeImpl(type, name); } diff --git a/source/slang/slang-ir-glsl-liveness.cpp b/source/slang/slang-ir-glsl-liveness.cpp index d7a3e0395..3cfde0246 100644 --- a/source/slang/slang-ir-glsl-liveness.cpp +++ b/source/slang/slang-ir-glsl-liveness.cpp @@ -62,6 +62,7 @@ struct GLSLLivenessContext IRStringLit* m_extensionStringLiteral = nullptr; ///< The string literal holding the SPIR-V extension needed IRInst* m_zeroIntLiteral = nullptr; ///< Zero value literal + IRType* m_spirvIntLiteralType = nullptr; ///< Int type that emits as `spirv_literal` IRModule* m_module; SharedIRBuilder m_sharedBuilder; @@ -138,7 +139,7 @@ void GLSLLivenessContext::_replaceMarker(IRLiveRangeMarker* markerInst) IRType* paramTypes[] = { m_builder.getRefType(referencedType), ///< Use a reference to the referenced type - m_builder.getIntType(), ///< The size type + m_spirvIntLiteralType, ///< The size type }; func = m_builder.createFunc(); @@ -200,6 +201,9 @@ void GLSLLivenessContext::processModule() return; } + // Int type that is SPIRV Literal (ie prefixed with spirv_literal) + m_spirvIntLiteralType = m_builder.getSPIRVLiteralType(m_builder.getIntType()); + // Zero value literal m_zeroIntLiteral = m_builder.getIntValue(m_builder.getIntType(), 0); diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h index c09af19fe..267f9ab43 100644 --- a/source/slang/slang-ir-inst-defs.h +++ b/source/slang/slang-ir-inst-defs.h @@ -195,6 +195,9 @@ INST(RTTIType, rtti_type, 0, 0) INST(RTTIHandleType, rtti_handle_type, 0, 0) INST(TupleType, tuple_type, 0, 0) +// A type that identifies it's contained type as being emittable as `spirv_literal. +INST(SPIRVLiteralType, spirvLiteralType, 1, 0) + // A TypeType-typed IRValue represents a IRType. // It is used to represent a type parameter/argument in a generics. INST(TypeType, type_t, 0, 0) diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index a3b11ea80..3fc71b195 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -2110,6 +2110,9 @@ public: IRPtrTypeBase* getPtrType(IROp op, IRType* valueType); IRPtrType* getPtrType(IROp op, IRType* valueType, IRIntegerValue addressSpace); + /// Get a 'SPIRV literal' + IRSPIRVLiteralType* getSPIRVLiteralType(IRType* type); + IRArrayTypeBase* getArrayTypeBase( IROp op, IRType* elementType, diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index b3c19d419..84af6459e 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -2616,6 +2616,12 @@ namespace Slang return (IRRefType*) getPtrType(kIROp_RefType, valueType); } + IRSPIRVLiteralType* IRBuilder::getSPIRVLiteralType(IRType* type) + { + IRInst* operands[] = { type }; + return (IRSPIRVLiteralType*)getType(kIROp_SPIRVLiteralType, 1, operands); + } + IRPtrTypeBase* IRBuilder::getPtrType(IROp op, IRType* valueType) { IRInst* operands[] = { valueType }; diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h index 04fd6b1c9..c125e7d2c 100644 --- a/source/slang/slang-ir.h +++ b/source/slang/slang-ir.h @@ -1260,6 +1260,13 @@ struct IRMatrixType : IRType IR_LEAF_ISA(MatrixType) }; +struct IRSPIRVLiteralType : IRType +{ + IR_LEAF_ISA(SPIRVLiteralType) + + IRType* getValueType() { return static_cast<IRType*>(getOperand(0)); } +}; + struct IRPtrTypeBase : IRType { IRType* getValueType() { return (IRType*)getOperand(0); } diff --git a/tests/experimental/liveness/liveness.slang.expected b/tests/experimental/liveness/liveness.slang.expected index ce0298799..d8dcc1f62 100644 --- a/tests/experimental/liveness/liveness.slang.expected +++ b/tests/experimental/liveness/liveness.slang.expected @@ -102,12 +102,12 @@ layout(std430, binding = 0) buffer _S5 { #line 4 spirv_instruction(id = 256) -void livenessStart_0(spirv_by_reference SomeStruct_0 _0, int _1); +void livenessStart_0(spirv_by_reference SomeStruct_0 _0, spirv_literal int _1); #line 62 spirv_instruction(id = 257) -void livenessEnd_0(spirv_by_reference SomeStruct_0 _0, int _1); +void livenessEnd_0(spirv_by_reference SomeStruct_0 _0, spirv_literal int _1); #line 46 |
