From 4c78efd0c34442866f20e9d00bbb6908115c9a01 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 16 Nov 2023 14:32:33 -0800 Subject: Unify stdlib `Texture` types into one generic type. (#3327) * Unify Texture types in stdlib into 1 generic type. * Fixes. * Fix. * Fixes. * Fix reflection. * Fix binding reflection. * Add gather intrinsics. * Fix gather intrinsics. * Fix texture type toText. * Fix intrinsic. * fix cuda intrinsic. * Fix project files. * cleanup. * Fix. * Fix. * Fix sampler feedback test. * Fix getDimension intrinsics. * Fix spirv sample image intrinsics. * Fix test. * Fix GLSL intrinsic. * Cleanup. --------- Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 61 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index c40a62941..adac4cd10 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -2784,6 +2784,12 @@ namespace Slang return (IRPtrType*)getType(op, 2, operands); } + IRTextureTypeBase* IRBuilder::getTextureType(IRType* elementType, IRInst* shape, IRInst* isArray, IRInst* isMS, IRInst* sampleCount, IRInst* access, IRInst* isShadow, IRInst* isCombined, IRInst* format) + { + IRInst* args[] = {(IRInst*)elementType, shape, isArray, isMS, sampleCount, access, isShadow, isCombined, format}; + return as(emitIntrinsicInst(getTypeKind(), kIROp_TextureType, (UInt)(sizeof(args)/sizeof(IRInst*)), args)); + } + IRComPtrType* IRBuilder::getComPtrType(IRType* valueType) { return (IRComPtrType*)getType(kIROp_ComPtrType, valueType); @@ -5832,6 +5838,32 @@ namespace Slang return i; } + IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandImageType(IRInst* element) + { + SLANG_ASSERT(as(m_insertLoc.getParent())); + const auto i = createInst( + this, + kIROp_SPIRVAsmOperandImageType, + getTypeType(), + element + ); + addInst(i); + return i; + } + + IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandSampledImageType(IRInst* element) + { + SLANG_ASSERT(as(m_insertLoc.getParent())); + const auto i = createInst( + this, + kIROp_SPIRVAsmOperandSampledImageType, + getTypeType(), + element + ); + addInst(i); + return i; + } + IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandTruncate() { SLANG_ASSERT(as(m_insertLoc.getParent())); @@ -6723,6 +6755,16 @@ namespace Slang dumpInstExpr(context, inst->getOperand(0)); dump(context, ")"); return; + case kIROp_SPIRVAsmOperandImageType: + dump(context, "__imageType("); + dumpInstExpr(context, inst->getOperand(0)); + dump(context, ")"); + return; + case kIROp_SPIRVAsmOperandSampledImageType: + dump(context, "__sampledImageType("); + dumpInstExpr(context, inst->getOperand(0)); + dump(context, ")"); + return; } dump(context, opInfo.name); @@ -7011,13 +7053,6 @@ namespace Slang // // We may want to care about decorations. - // If it's a resource type - special case the handling of the resource flavor - if (IRResourceTypeBase::isaImpl(opA) && - static_cast(a)->getFlavor() != static_cast(b)->getFlavor()) - { - return false; - } - // TODO(JS): There is a question here about what to do about decorations. // For now we ignore decorations. Are two types potentially different if there decorations different? // If decorations play a part in difference in types - the order of decorations presumably is not important. @@ -7940,13 +7975,13 @@ namespace Slang auto func = as(callee); if (!func) return false; - auto block = func->getFirstBlock(); - if (!block) - return false; - if (auto genAsm = as(block->getTerminator())) + for (auto block : func->getBlocks()) { - outDefinition = genAsm->getAsm(); - return true; + if (auto genAsm = as(block->getTerminator())) + { + outDefinition = genAsm->getAsm(); + return true; + } } return false; } -- cgit v1.2.3