diff --git a/tools/clang/lib/SPIRV/SpirvEmitter.cpp b/tools/clang/lib/SPIRV/SpirvEmitter.cpp index 7178b9b9b..d892fa0f5 100644 --- a/tools/clang/lib/SPIRV/SpirvEmitter.cpp +++ b/tools/clang/lib/SPIRV/SpirvEmitter.cpp @@ -12133,9 +12133,7 @@ SpirvEmitter::processGetAttributeAtVertex(const CallExpr *expr) { const auto exprRange = expr->getSourceRange(); // arg1 : vertexId - const auto *arg1BaseExpr = doExpr(expr->getArg(1)->IgnoreParenLValueCasts()); - const auto *arg1ConstExpr = dyn_cast(arg1BaseExpr); - const auto vertexId = arg1ConstExpr->getValue(); + auto *arg1BaseExpr = doExpr(expr->getArg(1)->IgnoreParenLValueCasts()); // arg0 : decorated input // Tip : for input with boolean type, we need to ignore implicit cast first, @@ -12152,14 +12150,12 @@ SpirvEmitter::processGetAttributeAtVertex(const CallExpr *expr) { } // Change to access chain instr SpirvInstruction *accessChainPtr = paramDeclInstr; - SpirvConstant *vtxId = spvBuilder.getConstantInt( - astContext.UnsignedIntTy, llvm::APInt(32, *(vertexId.getRawData()))); if (isa(accessChainPtr)) { auto *accessInstr = dyn_cast(accessChainPtr); - accessInstr->insertIndex(vtxId, accessInstr->getIndexes().size()); + accessInstr->insertIndex(arg1BaseExpr, accessInstr->getIndexes().size()); } else - accessChainPtr = spvBuilder.createAccessChain(elementType, accessChainPtr, - vtxId, exprLoc, exprRange); + accessChainPtr = spvBuilder.createAccessChain( + elementType, accessChainPtr, arg1BaseExpr, exprLoc, exprRange); dyn_cast(accessChainPtr)->setNoninterpolated(false); auto *loadPtr = spvBuilder.createLoad(elementType, accessChainPtr, exprLoc, exprRange); diff --git a/tools/clang/test/CodeGenSPIRV/intrinsics.get-attribute-at-vertex.var.idx.hlsl b/tools/clang/test/CodeGenSPIRV/intrinsics.get-attribute-at-vertex.var.idx.hlsl new file mode 100644 index 000000000..51dfb3357 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/intrinsics.get-attribute-at-vertex.var.idx.hlsl @@ -0,0 +1,15 @@ +// RUN: %dxc -T ps_6_0 -E main %s -spirv | FileCheck %s + +struct PSInput { + int idx: INPUT0; + nointerpolation float4 fp_h: FPH; +}; + +float4 main(PSInput input) : SV_Target { +// CHECK: [[idx:%[0-9]+]] = OpLoad %int %in_var_INPUT0 +// CHECK: [[bc:%[0-9]+]] = OpBitcast %uint [[idx]] +// CHECK: [[ac:%[0-9]+]] = OpAccessChain %_ptr_Input_v4float %in_var_FPH [[bc]] +// CHECK: [[ld:%[0-9]+]] = OpLoad %v4float [[ac]] +// CHECK: OpStore %out_var_SV_Target [[ld]] + return GetAttributeAtVertex(input.fp_h, input.idx); +} \ No newline at end of file