瀏覽代碼

Fix SROA on UDT passed to new intrinsics.

Tex Riddell 7 年之前
父節點
當前提交
7da55d9268

+ 11 - 2
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -1751,9 +1751,18 @@ void SROA_HLSL::isSafeForScalarRepl(Instruction *I, uint64_t Offset,
       isSafePHISelectUseForScalarRepl(User, Offset, Info);
     } else if (CallInst *CI = dyn_cast<CallInst>(User)) {
       HLOpcodeGroup group = GetHLOpcodeGroupByName(CI->getCalledFunction());
-      // HL functions are safe for scalar repl.
-      if (group == HLOpcodeGroup::NotHL)
+      // Most HL functions are safe for scalar repl.
+      if (HLOpcodeGroup::NotHL == group)
         return MarkUnsafe(Info, User);
+      else if (HLOpcodeGroup::HLIntrinsic == group) {
+        // TODO: should we check HL parameter type for UDT overload instead of basing on IOP?
+        IntrinsicOp opcode = static_cast<IntrinsicOp>(GetHLOpcode(CI));
+        if (IntrinsicOp::IOP_TraceRay == opcode ||
+            IntrinsicOp::IOP_ReportHit == opcode ||
+            IntrinsicOp::IOP_CallShader == opcode) {
+          return MarkUnsafe(Info, User);
+        }
+      }
     } else {
       return MarkUnsafe(Info, User);
     }

+ 35 - 0
tools/clang/test/CodeGenHLSL/quick-test/raytracing_traceray_readback.hlsl

@@ -0,0 +1,35 @@
+// RUN: %dxc -T lib_6_2 %s | FileCheck %s
+
+// Make sure we don't store the initial value (must load from payload after TraceRay)
+// CHECK-NOT: call void @dx.op.textureStore.f32(i32 67, %dx.types.Handle {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 undef, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, i8 15)
+
+struct Payload {
+   float4 abc;
+   float4 color;
+};
+
+RWTexture2D<float4> RTOutput : register(u0);
+RaytracingAccelerationStructure scene : register(t0);
+
+int2 viewportDims;
+float3 invView[4];
+float tanHalfFovY;
+
+[shader("raygeneration")]
+void RayGenTestMain()
+{
+    uint2 LaunchIndex = RayDispatchIndex();
+    float2 d = ((LaunchIndex.xy / (float2)viewportDims) * 2.f - 1.f);
+    float aspectRatio = (float)viewportDims.x / (float)viewportDims.y;
+
+    RayDesc ray;
+    ray.Origin = invView[3].xyz;
+    ray.Direction = normalize((d.x * invView[0].xyz * tanHalfFovY * aspectRatio) + (-d.y * invView[1].xyz * tanHalfFovY) - invView[2].xyz);
+    ray.TMin = 0;
+    ray.TMax = 100000;
+
+    Payload payload;
+    payload.color = float4(0.0f, 1.0f, 0.0f, 1.0f);
+    TraceRay(scene, 0 /*rayFlags*/, 0xFF /*rayMask*/, 0 /*sbtRecordOffset*/, 1 /*sbtRecordStride*/, 0 /*missIndex*/, ray, payload);
+    RTOutput[LaunchIndex.xy] = payload.color;
+}