Просмотр исходного кода

DxilConv: Fix interface translation regression (uses space != 0) (#3437)

Tex Riddell 4 лет назад
Родитель
Сommit
694e5657c3

+ 7 - 7
projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp

@@ -4568,22 +4568,18 @@ void DxbcConverter::InsertSM50ResourceHandles() {
   if (!IsSM51Plus()) {
   if (!IsSM51Plus()) {
     for (size_t i = 0; i < m_pPR->GetSRVs().size(); ++i) {
     for (size_t i = 0; i < m_pPR->GetSRVs().size(); ++i) {
       DxilResource &R = m_pPR->GetSRV(i);
       DxilResource &R = m_pPR->GetSRV(i);
-      DXASSERT(R.GetSpaceID() == 0, "In SM5.0, all resources should be in space 0");
       SetCachedHandle(R);
       SetCachedHandle(R);
     }
     }
     for (size_t i = 0; i < m_pPR->GetUAVs().size(); ++i) {
     for (size_t i = 0; i < m_pPR->GetUAVs().size(); ++i) {
       DxilResource &R = m_pPR->GetUAV(i);
       DxilResource &R = m_pPR->GetUAV(i);
-      DXASSERT(R.GetSpaceID() == 0, "In SM5.0, all resources should be in space 0");
       SetCachedHandle(R);
       SetCachedHandle(R);
     }
     }
     for (size_t i = 0; i < m_pPR->GetCBuffers().size(); ++i) {
     for (size_t i = 0; i < m_pPR->GetCBuffers().size(); ++i) {
       DxilCBuffer &R = m_pPR->GetCBuffer(i);
       DxilCBuffer &R = m_pPR->GetCBuffer(i);
-      DXASSERT(R.GetSpaceID() == 0, "In SM5.0, all resources should be in space 0");
       SetCachedHandle(R);
       SetCachedHandle(R);
     }
     }
     for (size_t i = 0; i < m_pPR->GetSamplers().size(); ++i) {
     for (size_t i = 0; i < m_pPR->GetSamplers().size(); ++i) {
       DxilSampler &R = m_pPR->GetSampler(i);
       DxilSampler &R = m_pPR->GetSampler(i);
-      DXASSERT(R.GetSpaceID() == 0, "In SM5.0, all resources should be in space 0");
       SetCachedHandle(R);
       SetCachedHandle(R);
     }
     }
   }
   }
@@ -5702,11 +5698,15 @@ Value *DxbcConverter::CreateHandle(DxilResourceBase::Class Class, unsigned Range
 }
 }
 void DxbcConverter::SetCachedHandle(const DxilResourceBase &R) {
 void DxbcConverter::SetCachedHandle(const DxilResourceBase &R) {
   DXASSERT(!IsSM51Plus(), "must not cache handles on SM 5.1");
   DXASSERT(!IsSM51Plus(), "must not cache handles on SM 5.1");
-  m_HandleMap[std::make_pair((unsigned)R.GetClass(), (unsigned)R.GetLowerBound())] =
-    CreateHandle(R.GetClass(), R.GetID(), m_pOP->GetU32Const(R.GetLowerBound()), false);
+  if (R.GetSpaceID() == 0) {
+    // Note: Even though space should normally be 0 for SM 5.0 and below,
+    // the interfaces implementation uses non-zero space when converting from SM 5.0.
+    m_HandleMap[std::make_pair((unsigned)R.GetClass(), (unsigned)R.GetLowerBound())] =
+      CreateHandle(R.GetClass(), R.GetID(), m_pOP->GetU32Const(R.GetLowerBound()), false);
+  }
 }
 }
 Value *DxbcConverter::GetCachedHandle(const DxilResourceBase &R) {
 Value *DxbcConverter::GetCachedHandle(const DxilResourceBase &R) {
-  if (IsSM51Plus())
+  if (IsSM51Plus() || R.GetSpaceID() != 0)
     return nullptr;
     return nullptr;
   auto it = m_HandleMap.find(std::make_pair((unsigned)R.GetClass(), (unsigned)R.GetLowerBound()));
   auto it = m_HandleMap.find(std::make_pair((unsigned)R.GetClass(), (unsigned)R.GetLowerBound()));
   if (it != m_HandleMap.end())
   if (it != m_HandleMap.end())

+ 43 - 0
projects/dxilconv/test/dxbc2dxil/interface1.hlsl

@@ -0,0 +1,43 @@
+// RUN: %fxc /T ps_5_0 %s /Fo %t.dxbc
+// RUN: %dxbc2dxil %t.dxbc /emit-llvm /o %t.ll.converted
+// RUN: fc %b.ref %t.ll.converted
+
+
+
+
+interface IFace
+{
+  float foo();
+};
+
+class First : IFace
+{
+  float f;
+  SamplerState samp;
+  Texture2D<float4> tex;
+  //RWStructuredBuffer<float4> rwbuf; // not allowed
+  float foo() {
+    float4 result = tex.Sample(samp, float2(0.25, 0.75));
+    //rwbuf[1] = result;
+    return result.x * f;
+  }
+};
+
+class Second : IFace
+{
+  float f;
+  SamplerState samp;
+  Texture2D<float4> tex;
+  float foo() {
+    float4 result = tex.Sample(samp, float2(0.125, 0.875));
+    return result.x + f;
+  }
+};
+
+interface IFace I[253];
+uint i;
+
+float main() : SV_TARGET
+{
+  return I[i].foo();
+}

+ 191 - 0
projects/dxilconv/test/dxbc2dxil/interface1.ref

@@ -0,0 +1,191 @@
+
+%dx.types.Handle = type { i8* }
+%dx.types.CBufRet.i32 = type { i32, i32, i32, i32 }
+%dx.types.ResRet.f32 = type { float, float, float, float, i32 }
+%dx.types.CBufRet.f32 = type { float, float, float, float }
+%dx.types.f32 = type { float }
+%dx.types.i8x16 = type { [16 x i8] }
+%dx.types.i8x8096 = type { [8096 x i8] }
+%dx.types.i8x65536 = type { [65536 x i8] }
+%dx.types.Sampler = type opaque
+
[email protected] = internal global i32 undef, align 4
[email protected] = internal global float undef, align 4
[email protected] = internal global i32 undef, align 4
[email protected] = internal global float undef, align 4
+
+define internal void @dx.fb.0() {
+entry:
+  %0 = load i32, i32* @dx.v32.r0
+  %1 = add i32 253, %0
+  %2 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 1, i32 14, i1 false)
+  %3 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %2, i32 %1)
+  %4 = extractvalue %dx.types.CBufRet.i32 %3, 2
+  %5 = call float @dx.op.bitcastI32toF32(i32 126, i32 %4)
+  %6 = extractvalue %dx.types.CBufRet.i32 %3, 3
+  store float %5, float* @dx.v32.r2
+  store i32 %6, i32* @dx.v32.r3
+  %7 = load float, float* @dx.v32.r2
+  %8 = call i32 @dx.op.bitcastF32toI32(i32 127, float %7)
+  %9 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 0, i32 %8, i1 false)
+  %10 = load i32, i32* @dx.v32.r3
+  %11 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 3, i32 0, i32 %10, i1 false)
+  %12 = call %dx.types.ResRet.f32 @dx.op.sample.f32(i32 60, %dx.types.Handle %9, %dx.types.Handle %11, float 1.250000e-01, float 8.750000e-01, float undef, float undef, i32 0, i32 0, i32 undef, float 0.000000e+00)
+  %13 = extractvalue %dx.types.ResRet.f32 %12, 0
+  store float %13, float* @dx.v32.r2
+  %14 = load i32, i32* @dx.v32.r0
+  %15 = add i32 253, %14
+  %16 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 1, i32 14, i1 false)
+  %17 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %16, i32 %15)
+  %18 = extractvalue %dx.types.CBufRet.i32 %17, 1
+  store i32 %18, i32* @dx.v32.r3
+  %19 = load i32, i32* @dx.v32.r0
+  %20 = add i32 253, %19
+  %21 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 1, i32 14, i1 false)
+  %22 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %21, i32 %20)
+  %23 = extractvalue %dx.types.CBufRet.i32 %22, 0
+  %24 = load float, float* @dx.v32.r2
+  %25 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 2, i32 %23, i1 false)
+  %26 = load i32, i32* @dx.v32.r3
+  %27 = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %25, i32 %26)
+  %28 = extractvalue %dx.types.CBufRet.f32 %27, 0
+  %29 = fadd fast float %24, %28
+  store float %29, float* @dx.v32.r1
+  ret void
+}
+
+define internal void @dx.fb.1() {
+entry:
+  %0 = load i32, i32* @dx.v32.r0
+  %1 = add i32 253, %0
+  %2 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 1, i32 14, i1 false)
+  %3 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %2, i32 %1)
+  %4 = extractvalue %dx.types.CBufRet.i32 %3, 2
+  %5 = call float @dx.op.bitcastI32toF32(i32 126, i32 %4)
+  %6 = extractvalue %dx.types.CBufRet.i32 %3, 3
+  store float %5, float* @dx.v32.r2
+  store i32 %6, i32* @dx.v32.r3
+  %7 = load float, float* @dx.v32.r2
+  %8 = call i32 @dx.op.bitcastF32toI32(i32 127, float %7)
+  %9 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 0, i32 %8, i1 false)
+  %10 = load i32, i32* @dx.v32.r3
+  %11 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 3, i32 0, i32 %10, i1 false)
+  %12 = call %dx.types.ResRet.f32 @dx.op.sample.f32(i32 60, %dx.types.Handle %9, %dx.types.Handle %11, float 2.500000e-01, float 7.500000e-01, float undef, float undef, i32 0, i32 0, i32 undef, float 0.000000e+00)
+  %13 = extractvalue %dx.types.ResRet.f32 %12, 0
+  store float %13, float* @dx.v32.r2
+  %14 = load i32, i32* @dx.v32.r0
+  %15 = add i32 253, %14
+  %16 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 1, i32 14, i1 false)
+  %17 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %16, i32 %15)
+  %18 = extractvalue %dx.types.CBufRet.i32 %17, 1
+  store i32 %18, i32* @dx.v32.r3
+  %19 = load i32, i32* @dx.v32.r0
+  %20 = add i32 253, %19
+  %21 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 1, i32 14, i1 false)
+  %22 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %21, i32 %20)
+  %23 = extractvalue %dx.types.CBufRet.i32 %22, 0
+  store i32 %23, i32* @dx.v32.r0
+  %24 = load float, float* @dx.v32.r2
+  %25 = load i32, i32* @dx.v32.r0
+  %26 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 2, i32 %25, i1 false)
+  %27 = load i32, i32* @dx.v32.r3
+  %28 = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %26, i32 %27)
+  %29 = extractvalue %dx.types.CBufRet.f32 %28, 0
+  %30 = fmul fast float %24, %29
+  store float %30, float* @dx.v32.r1
+  ret void
+}
+
+define void @main() {
+entry:
+  %0 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 0, i32 0, i1 false)
+  %1 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %0, i32 0)
+  %2 = extractvalue %dx.types.CBufRet.i32 %1, 0
+  store i32 %2, i32* @dx.v32.r0
+  %3 = load i32, i32* @dx.v32.r0
+  %4 = add i32 0, %3
+  %5 = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 2, i32 1, i32 14, i1 false)
+  %6 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %5, i32 %4)
+  %7 = extractvalue %dx.types.CBufRet.i32 %6, 0
+  switch i32 %7, label %fcall0.end [
+    i32 0, label %fcall0.case0
+    i32 1, label %fcall0.case1
+  ]
+
+fcall0.case0:                                     ; preds = %entry
+  call void @dx.fb.0()
+  br label %fcall0.end
+
+fcall0.case1:                                     ; preds = %entry
+  call void @dx.fb.1()
+  br label %fcall0.end
+
+fcall0.end:                                       ; preds = %fcall0.case1, %fcall0.case0, %entry
+  %8 = load float, float* @dx.v32.r1
+  call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 0, float %8)
+  ret void
+}
+
+; Function Attrs: nounwind readonly
+declare %dx.types.Handle @dx.op.createHandle(i32, i8, i32, i32, i1) #0
+
+; Function Attrs: nounwind readonly
+declare %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32, %dx.types.Handle, i32) #0
+
+; Function Attrs: nounwind
+declare void @dx.op.tempRegStore.i32(i32, i32, i32) #1
+
+; Function Attrs: nounwind readonly
+declare i32 @dx.op.tempRegLoad.i32(i32, i32) #0
+
+; Function Attrs: nounwind readonly
+declare float @dx.op.tempRegLoad.f32(i32, i32) #0
+
+; Function Attrs: nounwind
+declare void @dx.op.storeOutput.f32(i32, i32, i32, i8, float) #1
+
+; Function Attrs: nounwind readonly
+declare %dx.types.ResRet.f32 @dx.op.sample.f32(i32, %dx.types.Handle, %dx.types.Handle, float, float, float, float, i32, i32, i32, float) #0
+
+; Function Attrs: nounwind
+declare void @dx.op.tempRegStore.f32(i32, i32, float) #1
+
+; Function Attrs: nounwind readonly
+declare %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32, %dx.types.Handle, i32) #0
+
+; Function Attrs: nounwind readnone
+declare float @dx.op.bitcastI32toF32(i32, i32) #2
+
+; Function Attrs: nounwind readnone
+declare i32 @dx.op.bitcastF32toI32(i32, float) #2
+
+attributes #0 = { nounwind readonly }
+attributes #1 = { nounwind }
+attributes #2 = { nounwind readnone }
+
+!dx.version = !{!0}
+!dx.valver = !{!0}
+!dx.shaderModel = !{!1}
+!dx.resources = !{!2}
+!dx.entryPoints = !{!13}
+!llvm.ident = !{!18}
+
+!0 = !{i32 1, i32 0}
+!1 = !{!"ps", i32 6, i32 0}
+!2 = !{!3, null, !6, !10}
+!3 = !{!4}
+!4 = !{i32 0, %dx.types.f32 addrspace(1)* undef, !"T0", i32 1, i32 0, i32 128, i32 2, i32 0, !5}
+!5 = !{i32 0, i32 9}
+!6 = !{!7, !8, !9}
+!7 = !{i32 0, %dx.types.i8x16 addrspace(2)* undef, !"CB0", i32 0, i32 0, i32 1, i32 16, null}
+!8 = !{i32 1, %dx.types.i8x8096 addrspace(2)* undef, !"CB1", i32 0, i32 14, i32 1, i32 8096, null}
+!9 = !{i32 2, %dx.types.i8x65536 addrspace(2)* undef, !"CB2", i32 1, i32 0, i32 14, i32 65536, null}
+!10 = !{!11, !12}
+!11 = !{i32 0, %dx.types.Sampler addrspace(1)* undef, !"S0", i32 1, i32 0, i32 16, i32 0, null}
+!12 = !{i32 1, %dx.types.Sampler addrspace(1)* undef, !"S1", i32 2, i32 0, i32 16, i32 1, null}
+!13 = !{void ()* @main, !"main", !14, !2, null}
+!14 = !{null, !15, null}
+!15 = !{!16}
+!16 = !{i32 0, !"SV_Target", i8 9, i8 16, !17, i8 0, i32 1, i8 1, i32 0, i8 0, null}
+!17 = !{i32 0}
+!18 = !{!"dxbc2dxil 1.2"}