diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-glsl.cpp | 3 | ||||
| -rw-r--r-- | source/slang/slang-intrinsic-expand.cpp | 9 | ||||
| -rw-r--r-- | source/slang/slang-ir-util.cpp | 14 | ||||
| -rw-r--r-- | source/slang/slang-ir-util.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir.h | 1 |
5 files changed, 30 insertions, 0 deletions
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 64afb7ff1..853ef69ae 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -4,6 +4,7 @@ #include "../core/slang-writer.h" #include "slang-emit-source-writer.h" +#include "slang-ir-util.h" #include "slang-mangled-lexer.h" #include "slang-legalize-types.h" @@ -691,6 +692,8 @@ void GLSLSourceEmitter::_emitGLSLTextureOrTextureSamplerType(IRTextureTypeBase* void GLSLSourceEmitter::_emitGLSLTypePrefix(IRType* type, bool promoteHalfToFloat) { + type = dropNormAttributes(type); + switch (type->getOp()) { case kIROp_FloatType: diff --git a/source/slang/slang-intrinsic-expand.cpp b/source/slang/slang-intrinsic-expand.cpp index 53f113962..fd1a4e4d5 100644 --- a/source/slang/slang-intrinsic-expand.cpp +++ b/source/slang/slang-intrinsic-expand.cpp @@ -2,6 +2,7 @@ #include "slang-intrinsic-expand.h" #include "slang-emit-cuda.h" +#include "slang-ir-util.h" namespace Slang { @@ -512,6 +513,10 @@ const char* IntrinsicExpandContext::_emitSpecial(const char* cursor) SLANG_UNEXPECTED("bad format in intrinsic definition"); } + // unorm and snorm attributes are currently ignored by glslang + // https://github.com/KhronosGroup/glslang/blob/main/glslang/HLSL/hlslGrammar.cpp#L1476 + elementType = dropNormAttributes(elementType); + SLANG_ASSERT(elementType); if (const auto basicType = as<IRBasicType>(elementType)) { @@ -529,6 +534,10 @@ const char* IntrinsicExpandContext::_emitSpecial(const char* cursor) m_writer->emit(swiz[elementCount]); } } + else if (const auto attrType = as<IRAttributedType>(elementType)) + { + SLANG_UNEXPECTED("unhandled attributed type in intrinsic definition"); + } else { // What other cases are possible? diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index d2bf928a4..6b94711e0 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -1074,4 +1074,18 @@ IRInst* GenericChildrenMigrationContext::cloneInst(IRBuilder* builder, IRInst* s return impl->cloneInst(builder, src); } +IRType* dropNormAttributes(IRType* const t) +{ + if(const auto a = as<IRAttributedType>(t)) + { + switch(a->getAttr()->getOp()) + { + case kIROp_UNormAttr: + case kIROp_SNormAttr: + return dropNormAttributes(a->getBaseType()); + } + } + return t; +} + } diff --git a/source/slang/slang-ir-util.h b/source/slang/slang-ir-util.h index 65d081f42..c12f0b62b 100644 --- a/source/slang/slang-ir-util.h +++ b/source/slang/slang-ir-util.h @@ -160,6 +160,9 @@ inline IRInst* unwrapAttributedType(IRInst* type) return type; } +// Remove hlsl's 'unorm' and 'snorm' modifiers +IRType* dropNormAttributes(IRType* const t); + void getTypeNameHint(StringBuilder& sb, IRInst* type); void copyNameHintDecoration(IRInst* dest, IRInst* src); IRInst* getRootAddr(IRInst* addrInst); diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h index 75ce44862..44dc585ab 100644 --- a/source/slang/slang-ir.h +++ b/source/slang/slang-ir.h @@ -1742,6 +1742,7 @@ struct IRAttributedType : IRType IR_LEAF_ISA(AttributedType) IRType* getBaseType() { return (IRType*) getOperand(0); } + IRInst* getAttr() { return getOperand(1); } }; /// Represents a tuple. Tuples are created by `IRMakeTuple` and its elements |
