From 6437c38e0a3c2c1daf36cb5e543dc0b467fa4b15 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 23 Aug 2023 05:49:33 -0700 Subject: Lower all ByteAddressBuffer uses for SPIRV. (#3143) Co-authored-by: Yong He --- source/slang/slang-emit-spirv.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source/slang/slang-emit-spirv.cpp') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 9a7f5ad31..9d8c4d89a 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -1822,6 +1822,8 @@ struct SPIRVEmitContext return emitStore(parent, as(inst)); case kIROp_RWStructuredBufferGetElementPtr: return emitStructuredBufferGetElementPtr(parent, inst); + case kIROp_StructuredBufferGetDimensions: + return emitStructuredBufferGetDimensions(parent, inst); case kIROp_swizzle: return emitSwizzle(parent, as(inst)); case kIROp_IntCast: @@ -2915,6 +2917,21 @@ struct SPIRVEmitContext return addr; } + SpvInst* emitStructuredBufferGetDimensions(SpvInstParent* parent, IRInst* inst) + { + IRBuilder builder(inst); + auto arrayLength = emitInst(parent, nullptr, SpvOpArrayLength, builder.getUIntType(), kResultID, inst->getOperand(0), SpvLiteralInteger::from32(0)); + auto elementType = as(inst->getOperand(0)->getDataType())->getValueType(); + IRIntegerValue stride = 0; + if (auto sizeDecor = elementType->findDecoration()) + { + stride = align(sizeDecor->getSize(), (int)sizeDecor->getAlignment()); + } + auto strideOperand = emitIntConstant(stride, builder.getUIntType()); + auto result = emitOpCompositeConstruct(parent, inst, inst->getDataType(), arrayLength, strideOperand); + return result; + } + SpvInst* emitSwizzle(SpvInstParent* parent, IRSwizzle* inst) { if (inst->getElementCount() == 1) -- cgit v1.2.3