diff --git a/include/dxc/HLSL/HLOperations.h b/include/dxc/HLSL/HLOperations.h index c75318da99..bc20d4e988 100644 --- a/include/dxc/HLSL/HLOperations.h +++ b/include/dxc/HLSL/HLOperations.h @@ -434,7 +434,7 @@ const unsigned kAnnotateNodeHandleNodePropIdx = 2; const unsigned kAnnotateNodeRecordHandleNodeRecordPropIdx = 2; // HitObject::MakeMiss -const unsigned kHitObjectMakeMiss_NumOp = 8; +const unsigned kHitObjectMakeMiss_NumOp = 5; const unsigned kHitObjectMakeMissRayDescOpIdx = 4; // HitObject::TraceRay diff --git a/lib/HLSL/HLOperationLower.cpp b/lib/HLSL/HLOperationLower.cpp index 18d003a764..3768985e12 100644 --- a/lib/HLSL/HLOperationLower.cpp +++ b/lib/HLSL/HLOperationLower.cpp @@ -6217,35 +6217,20 @@ Value *TranslateHitObjectMake(CallInst *CI, IntrinsicOp IOP, OP::OpCode Opcode, DXASSERT_NOMSG(CI->getNumArgOperands() == HLOperandIndex::kHitObjectMakeMiss_NumOp); - Value *RayFlags = CI->getArgOperand(SrcIdx++); - Value *MissShaderIdx = CI->getArgOperand(SrcIdx++); - DXASSERT_NOMSG(SrcIdx == HLOperandIndex::kHitObjectMakeMissRayDescOpIdx); - Value *RayDescOrigin = CI->getArgOperand(SrcIdx++); - Value *RayDescOriginX = - Builder.CreateExtractElement(RayDescOrigin, (uint64_t)0); - Value *RayDescOriginY = - Builder.CreateExtractElement(RayDescOrigin, (uint64_t)1); - Value *RayDescOriginZ = - Builder.CreateExtractElement(RayDescOrigin, (uint64_t)2); - - Value *RayDescTMin = CI->getArgOperand(SrcIdx++); - Value *RayDescDirection = CI->getArgOperand(SrcIdx++); - Value *RayDescDirectionX = - Builder.CreateExtractElement(RayDescDirection, (uint64_t)0); - Value *RayDescDirectionY = - Builder.CreateExtractElement(RayDescDirection, (uint64_t)1); - Value *RayDescDirectionZ = - Builder.CreateExtractElement(RayDescDirection, (uint64_t)2); - - Value *RayDescTMax = CI->getArgOperand(SrcIdx++); + const unsigned DxilNumArgs = DxilInst_HitObject_MakeMiss::arg_TMax + 1; + Value *Args[DxilNumArgs]; + Args[0] = nullptr; // Opcode + unsigned DestIdx = 1; + Args[DestIdx++] = CI->getArgOperand(SrcIdx++); // RayFlags + Args[DestIdx++] = CI->getArgOperand(SrcIdx++); // MissShaderIdx + Value *RayDescPtr = CI->getArgOperand(SrcIdx++); + DestIdx = LoadRayDescElementsIntoArgs(Args, &Helper.hlslOP, Builder, + RayDescPtr, DestIdx); DXASSERT_NOMSG(SrcIdx == CI->getNumArgOperands()); + DXASSERT_NOMSG(DestIdx == DxilNumArgs); - Value *OutHitObject = TrivialDxilOperation( - Opcode, - {nullptr, RayFlags, MissShaderIdx, RayDescOriginX, RayDescOriginY, - RayDescOriginZ, RayDescTMin, RayDescDirectionX, RayDescDirectionY, - RayDescDirectionZ, RayDescTMax}, - Helper.voidTy, CI, HlslOP); + Value *OutHitObject = + TrivialDxilOperation(Opcode, Args, Helper.voidTy, CI, HlslOP); Builder.CreateStore(OutHitObject, HitObjectPtr); return nullptr; } diff --git a/lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp b/lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp index 8bd78dd9a6..409c6f1943 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp @@ -1539,9 +1539,7 @@ void isSafeForScalarRepl(Instruction *I, uint64_t Offset, AllocaInfo &Info) { // TODO: should we check HL parameter type for UDT overload instead of // basing on IOP? IntrinsicOp opcode = static_cast(GetHLOpcode(CI)); - if (IntrinsicOp::IOP_TraceRay == opcode || - IntrinsicOp::MOP_DxHitObject_TraceRay == opcode || - IntrinsicOp::MOP_DxHitObject_Invoke == opcode || + if (IntrinsicOp::MOP_DxHitObject_Invoke == opcode || IntrinsicOp::IOP_ReportHit == opcode || IntrinsicOp::IOP_CallShader == opcode) { return MarkUnsafe(Info, User); @@ -2687,7 +2685,7 @@ void SROA_Helper::RewriteCallArg(CallInst *CI, unsigned ArgIdx, bool bIn, Builder.SetInsertPoint(CI->getNextNode()); MemCpyInst *cpy = cast(Builder.CreateMemCpy( userTyV, Alloca, DL.getTypeAllocSize(userTyElt), false)); - RewriteMemIntrin(cpy, cpy->getRawSource()); + RewriteMemIntrin(cpy, cpy->getRawDest()); } } @@ -2756,18 +2754,21 @@ void SROA_Helper::RewriteCall(CallInst *CI) { /*loadElts*/ false); DeadInsts.push_back(CI); } break; - case IntrinsicOp::IOP_TraceRay: { - if (OldVal == - CI->getArgOperand(HLOperandIndex::kTraceRayRayDescOpIdx)) { - RewriteCallArg(CI, HLOperandIndex::kTraceRayRayDescOpIdx, - /*bIn*/ true, /*bOut*/ false); - } else { - DXASSERT(OldVal == - CI->getArgOperand(HLOperandIndex::kTraceRayPayLoadOpIdx), - "else invalid TraceRay"); - RewriteCallArg(CI, HLOperandIndex::kTraceRayPayLoadOpIdx, - /*bIn*/ true, /*bOut*/ true); + case IntrinsicOp::IOP_TraceRay: + case IntrinsicOp::MOP_DxHitObject_TraceRay: { + const int RayDescIdx = + IOP == IntrinsicOp::IOP_TraceRay + ? HLOperandIndex::kTraceRayRayDescOpIdx + : HLOperandIndex::kHitObjectTraceRay_RayDescOpIdx; + if (OldVal == CI->getArgOperand(RayDescIdx)) { + RewriteCallArg(CI, RayDescIdx, /*bIn*/ true, /*bOut*/ false); + break; } + const int PayloadIdx = CI->getNumArgOperands() - 1; + DXASSERT(OldVal == CI->getArgOperand(PayloadIdx), + "else invalid TraceRay"); + RewriteCallArg(CI, PayloadIdx, + /*bIn*/ true, /*bOut*/ true); } break; case IntrinsicOp::IOP_ReportHit: { RewriteCallArg(CI, HLOperandIndex::kReportIntersectionAttributeOpIdx, @@ -2780,21 +2781,10 @@ void SROA_Helper::RewriteCall(CallInst *CI) { case IntrinsicOp::MOP_DxHitObject_MakeMiss: { if (OldVal == CI->getArgOperand(HLOperandIndex::kHitObjectMakeMissRayDescOpIdx)) { - RewriteWithFlattenedHLIntrinsicCall(CI, OldVal, NewElts, - /*loadElts*/ true); - DeadInsts.push_back(CI); + RewriteCallArg(CI, HLOperandIndex::kHitObjectMakeMissRayDescOpIdx, + /*bIn*/ true, /*bOut*/ false); } } break; - case IntrinsicOp::MOP_TraceRayInline: { - if (OldVal == - CI->getArgOperand(HLOperandIndex::kTraceRayInlineRayDescOpIdx)) { - RewriteWithFlattenedHLIntrinsicCall(CI, OldVal, NewElts, - /*loadElts*/ true); - DeadInsts.push_back(CI); - break; - } - } - LLVM_FALLTHROUGH; case IntrinsicOp::MOP_DxHitObject_FromRayQuery: { const bool IsWithAttrs = CI->getNumArgOperands() == @@ -2808,7 +2798,6 @@ void SROA_Helper::RewriteCall(CallInst *CI) { CI, HLOperandIndex::kHitObjectFromRayQuery_WithAttrs_AttributeOpIdx, /*bIn*/ true, /*bOut*/ false); - break; } // For RayQuery methods, we want to replace the RayQuery this pointer @@ -2817,8 +2806,17 @@ void SROA_Helper::RewriteCall(CallInst *CI) { RewriteWithFlattenedHLIntrinsicCall(CI, OldVal, NewElts, /*loadElts*/ true); DeadInsts.push_back(CI); - break; + } break; + case IntrinsicOp::MOP_TraceRayInline: { + if (OldVal == + CI->getArgOperand(HLOperandIndex::kTraceRayInlineRayDescOpIdx)) { + RewriteWithFlattenedHLIntrinsicCall(CI, OldVal, NewElts, + /*loadElts*/ true); + DeadInsts.push_back(CI); + break; + } } + LLVM_FALLTHROUGH; default: // RayQuery this pointer replacement. if (OldVal->getType()->isPointerTy() && diff --git a/tools/clang/test/CodeGenDXIL/hlsl/objects/HitObject/multi_raydesc.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/objects/HitObject/multi_raydesc.hlsl new file mode 100644 index 0000000000..9501414653 --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/objects/HitObject/multi_raydesc.hlsl @@ -0,0 +1,121 @@ +// RUN: %dxc %s -T lib_6_9 -DPRESET_LOCAL_RAYDESC=1 | FileCheck %s --check-prefix LOCAL +// RUN: %dxc %s -T lib_6_9 -DPRESET_CBUFFER_RAYDESC_NORQ=1 | FileCheck %s --check-prefix CBUFFER + +// cbank load lowering bug: +// COM: %dxc %s -T lib_6_9 -DPRESET_CBUFFER_RAYDESC=1 | FileCheck %s --check-prefix CBUFFER_RQ + +#if PRESET_LOCAL_RAYDESC +// Single local RayDesc with using ops + +#define RD0 1 +// #define RD1 1 +#define HIT1 1 +#define HIT2 1 +#define HIT3 1 +#define HIT4 1 + +// LOCAL: %{{[^ ]+}} = call %dx.types.HitObject @dx.op.hitObject_MakeMiss(i32 265, i32 0, i32 0, float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00) ; HitObject_MakeMiss(RayFlags,MissShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax) +// LOCAL: %{{[^ ]+}} = call %dx.types.HitObject @dx.op.hitObject_TraceRay.struct.PerRayData(i32 262, %dx.types.Handle %{{[^ ]+}}, i32 256, i32 255, i32 0, i32 0, i32 0, float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00, %struct.PerRayData* nonnull %{{[^ ]+}}) ; HitObject_TraceRay(accelerationStructure,rayFlags,instanceInclusionMask,rayContributionToHitGroupIndex,multiplierForGeometryContributionToHitGroupIndex,missShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax,payload) +// LOCAL: call void @dx.op.rayQuery_TraceRayInline(i32 179, i32 %{{[^ ]+}}, %dx.types.Handle %{{[^ ]+}}, i32 0, i32 255, float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00) ; RayQuery_TraceRayInline(rayQueryHandle,accelerationStructure,rayFlags,instanceInclusionMask,origin_X,origin_Y,origin_Z,tMin,direction_X,direction_Y,direction_Z,tMax) +// LOCAL: call void @dx.op.traceRay.struct.PerRayData(i32 157, %dx.types.Handle %{{[^ ]+}}, i32 256, i32 255, i32 0, i32 0, i32 0, float 0.000000e+00, float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00, float 6.000000e+00, float 7.000000e+00, %struct.PerRayData* nonnull %{{[^ ]+}}) ; TraceRay(AccelerationStructure,RayFlags,InstanceInclusionMask,RayContributionToHitGroupIndex,MultiplierForGeometryContributionToShaderIndex,MissShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax,payload) + +#endif + + +#if PRESET_CBUFFER_RAYDESC_NORQ +// RayDesc served from cbuffer + +// #define RD0 1 +#define RD1 1 +#define HIT1 1 +#define HIT2 1 +// #define HIT3 1 +#define HIT4 1 + +// CBUFFER: %[[LD00:[^ ]+]] = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %[[CBH:[^ ]+]], i32 0) ; CBufferLoadLegacy(handle,regIndex) +// CBUFFER: %[[RD0O0:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD00]], 0 +// CBUFFER: %[[RD0O1:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD00]], 1 +// CBUFFER: %[[RD0O2:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD00]], 2 +// CBUFFER: %[[RD0MIN:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD00]], 3 +// CBUFFER: %[[LD01:[^ ]+]] = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %[[CBH]], i32 1) ; CBufferLoadLegacy(handle,regIndex) +// CBUFFER: %[[RD0D0:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD01]], 0 +// CBUFFER: %[[RD0D1:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD01]], 1 +// CBUFFER: %[[RD0D2:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD01]], 2 +// CBUFFER: %[[RD0MAX:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD01]], 3 +// CBUFFER: %{{[^ ]+}} = call %dx.types.HitObject @dx.op.hitObject_MakeMiss(i32 265, i32 0, i32 0, float %[[RD0O0]], float %[[RD0O1]], float %[[RD0O2]], float %[[RD0MIN]], float %[[RD0D0]], float %[[RD0D1]], float %[[RD0D2]], float %[[RD0MAX]]) ; HitObject_MakeMiss(RayFlags,MissShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax) + +// CBUFFER: %[[LD10:[^ ]+]] = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %[[CBH]], i32 0) ; CBufferLoadLegacy(handle,regIndex) +// CBUFFER: %[[RD1O0:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD10]], 0 +// CBUFFER: %[[RD1O1:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD10]], 1 +// CBUFFER: %[[RD1O2:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD10]], 2 +// CBUFFER: %[[RD1MIN:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD10]], 3 +// CBUFFER: %[[LD11:[^ ]+]] = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %[[CBH]], i32 1) ; CBufferLoadLegacy(handle,regIndex) +// CBUFFER: %[[RD1D0:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD11]], 0 +// CBUFFER: %[[RD1D1:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD11]], 1 +// CBUFFER: %[[RD1D2:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD11]], 2 +// CBUFFER: %[[RD1MAX:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD11]], 3 +// CBUFFER: %{{[^ ]+}} = call %dx.types.HitObject @dx.op.hitObject_TraceRay.struct.PerRayData(i32 262, %dx.types.Handle %{{[^ ]+}}, i32 256, i32 255, i32 0, i32 0, i32 0, float %[[RD1O0]], float %[[RD1O1]], float %[[RD1O2]], float %[[RD1MIN]], float %[[RD1D0]], float %[[RD1D1]], float %[[RD1D2]], float %[[RD1MAX]], %struct.PerRayData* nonnull %{{[^ ]+}}) ; HitObject_TraceRay(accelerationStructure,rayFlags,instanceInclusionMask,rayContributionToHitGroupIndex,multiplierForGeometryContributionToHitGroupIndex,missShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax,payload) + +// CBUFFER: %[[LD20:[^ ]+]] = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %[[CBH]], i32 0) ; CBufferLoadLegacy(handle,regIndex) +// CBUFFER: %[[RD2O0:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD20]], 0 +// CBUFFER: %[[RD2O1:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD20]], 1 +// CBUFFER: %[[RD2O2:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD20]], 2 +// CBUFFER: %[[RD2MIN:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD20]], 3 +// CBUFFER: %[[LD21:[^ ]+]] = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %[[CBH]], i32 1) ; CBufferLoadLegacy(handle,regIndex) +// CBUFFER: %[[RD2D0:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD21]], 0 +// CBUFFER: %[[RD2D1:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD21]], 1 +// CBUFFER: %[[RD2D2:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD21]], 2 +// CBUFFER: %[[RD2MAX:[^ ]+]] = extractvalue %dx.types.CBufRet.f32 %[[LD21]], 3 +// CBUFFER: call void @dx.op.traceRay.struct.PerRayData(i32 157, %dx.types.Handle %{{[^ ]+}}, i32 256, i32 255, i32 0, i32 0, i32 0, float %[[RD2O0]], float %[[RD2O1]], float %[[RD2O2]], float %[[RD2MIN]], float %[[RD2D0]], float %[[RD2D1]], float %[[RD2D2]], float %[[RD2MAX]], %struct.PerRayData* nonnull %{{[^ ]+}}) ; TraceRay(AccelerationStructure,RayFlags,InstanceInclusionMask,RayContributionToHitGroupIndex,MultiplierForGeometryContributionToShaderIndex,MissShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax,payload) + +#endif + +#if PRESET_CBUFFER_RAYDESC +// TraceRayInline with RayDesc from cbuffer +// Lowering broken + +// #define RD0 1 +#define RD1 1 +// #define HIT1 1 +// #define HIT2 1 +#define HIT3 1 +// #define HIT4 1 +#endif + + +struct[raypayload] PerRayData +{ +}; + +RaytracingAccelerationStructure topObject : register(t0); + +#if RD1 +RayDesc ray; +#endif + +[shader("raygeneration")] +void raygen() +{ +#if RD0 + RayDesc ray = {{0, 1, 2}, 3, {4, 5, 6}, 7}; +#endif + + PerRayData payload; +#if HIT1 + dx::HitObject hit1 = dx::HitObject::MakeMiss(RAY_FLAG_NONE, 0, ray); + dx::MaybeReorderThread(hit1); +#endif +#if HIT2 + dx::HitObject hit2 = dx::HitObject::TraceRay(topObject, RAY_FLAG_SKIP_TRIANGLES, 0xFF, 0, 0, 0, ray, payload); + dx::MaybeReorderThread(hit2); +#endif +#if HIT3 + RayQuery rayQuery; + rayQuery.TraceRayInline(topObject, RAY_FLAG_NONE, 0xFF, ray); + dx::HitObject hit3 = dx::HitObject::FromRayQuery(rayQuery); + dx::MaybeReorderThread(hit3); +#endif +#if HIT4 + TraceRay(topObject, RAY_FLAG_SKIP_TRIANGLES, 0xFF, 0, 0, 0, ray, payload); +#endif +} diff --git a/tools/clang/test/DXC/Passes/ScalarReplHLSL/hitobject_make_scalarrepl.ll b/tools/clang/test/DXC/Passes/ScalarReplHLSL/hitobject_make_scalarrepl.ll index 89ee886c2e..adacb71ba7 100644 --- a/tools/clang/test/DXC/Passes/ScalarReplHLSL/hitobject_make_scalarrepl.ll +++ b/tools/clang/test/DXC/Passes/ScalarReplHLSL/hitobject_make_scalarrepl.ll @@ -33,11 +33,16 @@ entry: %hit = alloca %dx.types.HitObject, align 4 %tmp = alloca %dx.types.HitObject, align 4 %ray = alloca %struct.RayDesc, align 4 -; CHECK-NOT: %{{[^ ]+}} = alloca %struct.RayDesc +; CHECK: %[[RDA:[^ ]+]] = alloca %struct.RayDesc +; CHECK: %[[RDO:[^ ]+]] = alloca <3 x float> +; CHECK: %[[RDMIN:[^ ]+]] = alloca float +; CHECK: %[[RDD:[^ ]+]] = alloca <3 x float> +; CHECK: %[[RDTMAX:[^ ]+]] = alloca float %tmp2 = alloca %dx.types.HitObject, align 4 ; CHECK: %[[HIT0:[^ ]+]] = alloca %dx.types.HitObject, align 4 ; CHECK: %[[HIT1:[^ ]+]] = alloca %dx.types.HitObject, align 4 ; CHECK: %[[HIT2:[^ ]+]] = alloca %dx.types.HitObject, align 4 +; CHECK-NOT: alloca %0 = bitcast %dx.types.HitObject* %hit to i8*, !dbg !23 ; line:42 col:3 call void @llvm.lifetime.start(i64 4, i8* %0) #0, !dbg !23 ; line:42 col:3 ; CHECK: %[[THIS0:[^ ]+]] = call %dx.types.HitObject* @"dx.hl.op..%dx.types.HitObject* (i32, %dx.types.HitObject*)"(i32 358, %dx.types.HitObject* %[[HIT0]]) @@ -61,15 +66,20 @@ entry: store float 1.000000e+03, float* %8, !dbg !30 ; line:44 col:17 %9 = bitcast %dx.types.HitObject* %tmp2 to i8*, !dbg !31 ; line:45 col:3 call void @llvm.lifetime.start(i64 4, i8* %9) #0, !dbg !31 ; line:45 col:3 -; CHECK: store <3 x float> zeroinitializer, <3 x float>* %[[pRDO:[^ ]+]], -; CHECK: store float 0.000000e+00, float* %[[pRDTMIN:[^ ]+]], -; CHECK: store <3 x float> , <3 x float>* %[[pRDD:[^ ]+]], -; CHECK: store float 1.000000e+03, float* %[[pRDTMAX:[^ ]+]], -; CHECK-DAG: %[[RDO:[^ ]+]] = load <3 x float>, <3 x float>* %[[pRDO]], -; CHECK-DAG: %[[RDTMIN:[^ ]+]] = load float, float* %[[pRDTMIN]], -; CHECK-DAG: %[[RDD:[^ ]+]] = load <3 x float>, <3 x float>* %[[pRDD]], -; CHECK-DAG: %[[RDTMAX:[^ ]+]] = load float, float* %[[pRDTMAX]], -; CHECK: call void @"dx.hl.op..void (i32, %dx.types.HitObject*, i32, i32, <3 x float>, float, <3 x float>, float)"(i32 387, %dx.types.HitObject* %[[HIT2]], i32 0, i32 1, <3 x float> %[[RDO]], float %[[RDTMIN]], <3 x float> %[[RDD]], float %[[RDTMAX]]) +; CHECK: %[[OPTR:[^ ]+]] = getelementptr inbounds %struct.RayDesc, %struct.RayDesc* %[[RDA]], i32 0, i32 0 +; CHECK: %[[O:[^ ]+]] = load <3 x float>, <3 x float>* %[[RDO]] +; CHECK: store <3 x float> %[[O]], <3 x float>* %[[OPTR]] +; CHECK: %[[MINPTR:[^ ]+]] = getelementptr inbounds %struct.RayDesc, %struct.RayDesc* %[[RDA]], i32 0, i32 1 +; CHECK: %[[MIN:[^ ]+]] = load float, float* %[[RDMIN]] +; CHECK: store float %[[MIN]], float* %[[MINPTR]] +; CHECK: %[[DIRPTR:[^ ]+]] = getelementptr inbounds %struct.RayDesc, %struct.RayDesc* %[[RDA]], i32 0, i32 2 +; CHECK: %[[DIR:[^ ]+]] = load <3 x float>, <3 x float>* %[[RDD]] +; CHECK: store <3 x float> %[[DIR]], <3 x float>* %[[DIRPTR]] +; CHECK: %[[MAXPTR:[^ ]+]] = getelementptr inbounds %struct.RayDesc, %struct.RayDesc* %[[RDA]], i32 0, i32 3 +; CHECK: %[[MAX:[^ ]+]] = load float, float* %[[RDTMAX]] +; CHECK: store float %[[MAX]], float* %[[MAXPTR]] +; CHECK: call void @"dx.hl.op..void (i32, %dx.types.HitObject*, i32, i32, %struct.RayDesc*)"(i32 387, %dx.types.HitObject* %[[HIT2]], i32 0, i32 1, %struct.RayDesc* %[[RDA]]) + call void @"dx.hl.op..void (i32, %dx.types.HitObject*, i32, i32, %struct.RayDesc*)"(i32 387, %dx.types.HitObject* %tmp2, i32 0, i32 1, %struct.RayDesc* %ray), !dbg !31 ; line:45 col:3 %10 = bitcast %dx.types.HitObject* %tmp2 to i8*, !dbg !31 ; line:45 col:3 call void @llvm.lifetime.end(i64 4, i8* %10) #0, !dbg !31 ; line:45 col:3 diff --git a/tools/clang/test/HLSLFileCheck/pix/AnnotateVirtualRegs-Raygen.hlsl b/tools/clang/test/HLSLFileCheck/pix/AnnotateVirtualRegs-Raygen.hlsl deleted file mode 100644 index b9670bdaba..0000000000 --- a/tools/clang/test/HLSLFileCheck/pix/AnnotateVirtualRegs-Raygen.hlsl +++ /dev/null @@ -1,36 +0,0 @@ -// RUN: %dxc -Od -T lib_6_6 %s | %opt -S -dxil-annotate-with-virtual-regs | FileCheck %s - - -/* To run locally run: -%dxc -Od -T lib_6_6 %s -Fc %t.ll -%opt %t.ll -S -dxil-annotate-with-virtual-regs | FileCheck %s -*/ - -RaytracingAccelerationStructure scene : register(t0); - -struct RayPayload -{ - int3 color; -}; - -[shader("raygeneration")] -void ENTRY() -{ - RayDesc ray = {{0,0,0}, {0,0,1}, 0.05, 1000.0}; - RayPayload pld; - TraceRay(scene, 0 /*rayFlags*/, 0xFF /*rayMask*/, 0 /*sbtRecordOffset*/, 1 /*sbtRecordStride*/, 0 /*missIndex*/, ray, pld); -} - -// CHECK: {{.*}} = getelementptr inbounds %struct.RayDesc, %struct.RayDesc* {{.*}}, i32 0, i32 0, !pix-dxil-reg [[RDGEP:![0-9]+]], !pix-dxil-inst-num {{.*}} -// CHECK: {{.*}} = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @dx.nothing.a, i32 0, i32 0), !pix-dxil-reg [[NothGEP:![0-9]+]], !pix-dxil-inst-num {{.*}} -// CHECK: {{.*}} = getelementptr inbounds %struct.RayDesc, %struct.RayDesc* {{.*}}, i32 0, i32 1, !pix-dxil-reg [[RDGEP2:![0-9]+]], !pix-dxil-inst-num {{.*}} -// CHECK: {{.*}} = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @dx.nothing.a, i32 0, i32 0), !pix-dxil-reg [[NothGEP2:![0-9]+]], !pix-dxil-inst-num {{.*}} -// CHECK: {{.*}} = getelementptr inbounds %struct.RayDesc, %struct.RayDesc* {{.*}}, i32 0, i32 2, !pix-dxil-reg [[RDGEP3:![0-9]+]], !pix-dxil-inst-num {{.*}} -// CHECK: {{.*}} = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @dx.nothing.a, i32 0, i32 0), !pix-dxil-reg [[NothGEP3:![0-9]+]], !pix-dxil-inst-num {{.*}} - -// CHECK-DAG: [[RDGEP]] = !{i32 0, i32 0} -// CHECK-DAG: [[NothGEP]] = !{i32 0, i32 11} -// CHECK-DAG: [[RDGEP2]] = !{i32 0, i32 3} -// CHECK-DAG: [[NothGEP2]] = !{i32 0, i32 12} -// CHECK-DAG: [[RDGEP3]] = !{i32 0, i32 4} -// CHECK-DAG: [[NothGEP3]] = !{i32 0, i32 13} diff --git a/tools/clang/unittests/HLSL/PixTest.cpp b/tools/clang/unittests/HLSL/PixTest.cpp index e337d2951c..e6d8212928 100644 --- a/tools/clang/unittests/HLSL/PixTest.cpp +++ b/tools/clang/unittests/HLSL/PixTest.cpp @@ -119,7 +119,6 @@ class PixTest : public ::testing::Test { TEST_METHOD(AccessTracking_ModificationReport_SM66) TEST_METHOD(PixStructAnnotation_Lib_DualRaygen) - TEST_METHOD(PixStructAnnotation_Lib_RaygenAllocaStructAlignment) TEST_METHOD(PixStructAnnotation_Simple) TEST_METHOD(PixStructAnnotation_CopiedStruct) @@ -1455,100 +1454,6 @@ void Raygen1() } } -TEST_F(PixTest, PixStructAnnotation_Lib_RaygenAllocaStructAlignment) { - if (m_ver.SkipDxilVersion(1, 5)) - return; - - const char *hlsl = R"( - -RaytracingAccelerationStructure Scene : register(t0, space0); -RWTexture2D RenderTarget : register(u0); - -struct SceneConstantBuffer -{ - float4x4 projectionToWorld; - float4 cameraPosition; - float4 lightPosition; - float4 lightAmbientColor; - float4 lightDiffuseColor; -}; - -ConstantBuffer g_sceneCB : register(b0); - -struct RayPayload -{ - float4 color; -}; - -inline void GenerateCameraRay(uint2 index, out float3 origin, out float3 direction) -{ - float2 xy = index + 0.5f; // center in the middle of the pixel. - float2 screenPos = xy;// / DispatchRaysDimensions().xy * 2.0 - 1.0; - - // Invert Y for DirectX-style coordinates. - screenPos.y = -screenPos.y; - - // Unproject the pixel coordinate into a ray. - float4 world = /*mul(*/float4(screenPos, 0, 1)/*, g_sceneCB.projectionToWorld)*/; - - //world.xyz /= world.w; - origin = world.xyz; //g_sceneCB.cameraPosition.xyz; - direction = float3(1,0,0);//normalize(world.xyz - origin); -} - -void RaygenCommon() -{ - float3 rayDir; - float3 origin; - - // Generate a ray for a camera pixel corresponding to an index from the dispatched 2D grid. - GenerateCameraRay(DispatchRaysIndex().xy, origin, rayDir); - - // Trace the ray. - // Set the ray's extents. - RayDesc ray; - ray.Origin = origin; - ray.Direction = rayDir; - // Set TMin to a non-zero small value to avoid aliasing issues due to floating - point errors. - // TMin should be kept small to prevent missing geometry at close contact areas. - ray.TMin = 0.001; - ray.TMax = 10000.0; - RayPayload payload = { float4(0, 0, 0, 0) }; - TraceRay(Scene, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, ~0, 0, 1, 0, ray, payload); - - // Write the raytraced color to the output texture. - // RenderTarget[DispatchRaysIndex().xy] = payload.color; -} - -[shader("raygeneration")] -void Raygen() -{ - RaygenCommon(); -} -)"; - - auto Testables = TestStructAnnotationCase(hlsl, L"-Od", true, L"lib_6_6"); - - // Built-in type "RayDesc" has this structure: struct { float3 Origin; float - // TMin; float3 Direction; float TMax; } This is 8 floats, with members at - // offsets 0,3,4,7 respectively. - - auto FindAtLeastOneOf = [=](char const *name, uint32_t index) { - VERIFY_IS_TRUE(std::find_if(Testables.AllocaWrites.begin(), - Testables.AllocaWrites.end(), - [&name, &index](AllocaWrite const &aw) { - return 0 == strcmp(aw.memberName.c_str(), - name) && - aw.index == index; - }) != Testables.AllocaWrites.end()); - }; - - FindAtLeastOneOf("Origin.x", 0); - FindAtLeastOneOf("TMin", 3); - FindAtLeastOneOf("Direction.x", 4); - FindAtLeastOneOf("TMax", 7); -} - TEST_F(PixTest, PixStructAnnotation_Simple) { if (m_ver.SkipDxilVersion(1, 5)) return;