diff options
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 1fc15f185..bfd6c20cf 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -2059,7 +2059,7 @@ namespace Slang UnownedStringSlice IRConstant::getStringSlice() { - assert(getOp() == kIROp_StringLit); + assert(getOp() == kIROp_StringLit || getOp() == kIROp_BlobLit); // If the transitory decoration is set, then this is uses the transitoryStringVal for the text storage. // This is typically used when we are using a transitory IRInst held on the stack (such that it can be looked up in cached), // that just points to a string elsewhere, and NOT the typical normal style, where the string is held after the instruction in memory. @@ -2133,6 +2133,7 @@ namespace Slang { return value.ptrVal == rhs->value.ptrVal; } + case kIROp_BlobLit: case kIROp_StringLit: { return getStringSlice() == rhs->getStringSlice(); @@ -2174,6 +2175,7 @@ namespace Slang { return combineHash(code, Slang::getHashCode(value.ptrVal)); } + case kIROp_BlobLit: case kIROp_StringLit: { const UnownedStringSlice slice = getStringSlice(); @@ -2264,6 +2266,7 @@ namespace Slang irValue->value.ptrVal = keyInst.value.ptrVal; break; } + case kIROp_BlobLit: case kIROp_StringLit: { const UnownedStringSlice slice = keyInst.getStringSlice(); @@ -2387,6 +2390,36 @@ namespace Slang return static_cast<IRStringLit*>(_findOrEmitConstant(keyInst)); } + IRBlobLit* IRBuilder::getBlobValue(ISlangBlob* blob) + { + IRConstant keyInst; + memset(&keyInst, 0, sizeof(keyInst)); + + char* buffer = (char*)(getModule()->getMemoryArena().allocate(blob->getBufferSize())); + if (!buffer) + { + return nullptr; + } + memcpy(buffer, blob->getBufferPointer(), blob->getBufferSize()); + + UnownedStringSlice inSlice(buffer, blob->getBufferSize()); + + // Mark that this is on the stack... + IRDecoration stackDecoration; + memset(&stackDecoration, 0, sizeof(stackDecoration)); + stackDecoration.m_op = kIROp_TransitoryDecoration; + stackDecoration.insertAtEnd(&keyInst); + + keyInst.m_op = kIROp_BlobLit; + keyInst.typeUse.usedValue = nullptr; // not used + + IRConstant::StringSliceValue& dstSlice = keyInst.value.transitoryStringVal; + dstSlice.chars = const_cast<char*>(inSlice.begin()); + dstSlice.numChars = uint32_t(inSlice.getLength()); + + return static_cast<IRBlobLit*>(_findOrEmitConstant(keyInst)); + } + IRPtrLit* IRBuilder::_getPtrValue(void* data) { auto type = getPtrType(getVoidType()); @@ -3800,6 +3833,13 @@ namespace Slang return nullptr; } + IRInst* IRBuilder::emitEmbeddedDXIL(ISlangBlob *blob) + { + IRInst* args[] = { getBlobValue(blob) }; + + return emitIntrinsicInst(getVoidType(), kIROp_EmbeddedDXIL, 1, args); + } + enum class TypeCastStyle { Unknown = -1, @@ -7098,6 +7138,10 @@ namespace Slang dump(context, irConst->value.intVal ? "true" : "false"); return; + case kIROp_BlobLit: + dump(context, "<binary blob>"); + return; + case kIROp_StringLit: dumpEncodeString(context, irConst->getStringSlice()); return; |
