Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 76 additions & 2 deletions clang/test/CodeGenHLSL/cbuffer.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
// CHECK: %anon = type <{ float }>
// CHECK: %anon.0 = type <{ <2 x i32> }>

// CHECK: %__cblayout_CB_A = type <{ [2 x double], [3 x <3 x float>], float, [3 x double], half, [1 x <2 x double>], float, [2 x <3 x half>], <3 x half> }>
// CHECK: %__cblayout_CB_B = type <{ [3 x <3 x double>], <3 x half> }>
// CHECK: %__cblayout_CB_C = type <{ i32, target("dx.Layout", %F, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90), half, target("dx.Layout", %G, 258, 0, 48, 64, 256), double }>

// CHECK: %F = type <{ double, <3 x float>, float, <3 x double>, half, <2 x double>, float, <3 x half>, <3 x half> }>
// CHECK: %G = type <{ target("dx.Layout", %E, 36, 0, 8, 16, 20, 22, 24, 32), [1 x float], [2 x target("dx.Layout", %F, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90)], half }>
// CHECK: %E = type <{ float, double, float, half, i16, i64, i32 }>

cbuffer CBScalars : register(b1, space5) {
float a1;
double a2;
Expand Down Expand Up @@ -155,6 +163,64 @@ cbuffer CBMix {
uint16_t f9;
};

// CHECK: @CB_A.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB_A, 188, 0, 32, 76, 80, 120, 128, 144, 160, 182))

cbuffer CB_A {
double B0[2];
float3 B1[3];
float B2;
double B3[3];
half B4;
double2 B5[1];
float B6;
half3 B7[2];
half3 B8;
}

// CHECK: @CB_B.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB_B, 94, 0, 88))
cbuffer CB_B {
double3 B9[3];
half3 B10;
}

struct E {
float A0;
double A1;
float A2;
half A3;
int16_t A4;
int64_t A5;
int A6;
};

struct F {
double B0;
float3 B1;
float B2;
double3 B3;
half B4;
double2 B5;
float B6;
half3 B7;
half3 B8;
};

struct G {
E C0;
float C1[1];
F C2[2];
half C3;
};

// CHECK: @CB_C.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB_C, 400, 0, 16, 112, 128, 392))
cbuffer CB_C {
int D0;
F D1;
half D2;
G D3;
double D4;
}

// CHECK: define internal void @_init_resource_CBScalars.cb()
// CHECK-NEXT: entry:
// CHECK-NEXT: %[[HANDLE1:.*]] = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CBScalars, 56, 0, 8, 16, 24, 32, 36, 40, 48))
Expand All @@ -171,15 +237,16 @@ RWBuffer<float> Buf;

[numthreads(4,1,1)]
void main() {
Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1;
Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1 + B1[0].x + B10.z + D1.B2;
}

// CHECK: define internal void @_GLOBAL__sub_I_cbuffer.hlsl()
// CHECK-NEXT: entry:
// CHECK-NEXT: call void @_init_resource_CBScalars.cb()
// CHECK-NEXT: call void @_init_resource_CBArrays.cb()

// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], ![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]]}
// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], ![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]],
// CHECK-SAME: ![[CB_A:[0-9]+]], ![[CB_B:[0-9]+]], ![[CB_C:[0-9]+]]}

// CHECK: ![[CBSCALARS]] = !{ptr @CBScalars.cb, ptr addrspace(2) @a1, ptr addrspace(2) @a2, ptr addrspace(2) @a3, ptr addrspace(2) @a4,
// CHECK-SAME: ptr addrspace(2) @a5, ptr addrspace(2) @a6, ptr addrspace(2) @a7, ptr addrspace(2) @a8}
Expand All @@ -195,3 +262,10 @@ void main() {

// CHECK: ![[CBMIX]] = !{ptr @CBMix.cb, ptr addrspace(2) @test, ptr addrspace(2) @f1, ptr addrspace(2) @f2, ptr addrspace(2) @f3,
// CHECK-SAME: ptr addrspace(2) @f4, ptr addrspace(2) @f5, ptr addrspace(2) @f6, ptr addrspace(2) @f7, ptr addrspace(2) @f8, ptr addrspace(2) @f9}

// CHECK: ![[CB_A]] = !{ptr @CB_A.cb, ptr addrspace(2) @B0, ptr addrspace(2) @B1, ptr addrspace(2) @B2, ptr addrspace(2) @B3, ptr addrspace(2) @B4,
// CHECK-SAME: ptr addrspace(2) @B5, ptr addrspace(2) @B6, ptr addrspace(2) @B7, ptr addrspace(2) @B8}

// CHECK: ![[CB_B]] = !{ptr @CB_B.cb, ptr addrspace(2) @B9, ptr addrspace(2) @B10}

// CHECK: ![[CB_C]] = !{ptr @CB_C.cb, ptr addrspace(2) @D0, ptr addrspace(2) @D1, ptr addrspace(2) @D2, ptr addrspace(2) @D3, ptr addrspace(2) @D4}
2 changes: 0 additions & 2 deletions llvm/lib/Target/DirectX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ add_llvm_target(DirectXCodeGen
DXILOpLowering.cpp
DXILPrepare.cpp
DXILPrettyPrinter.cpp
DXILResource.cpp
DXILResourceAnalysis.cpp
DXILResourceAccess.cpp
DXILShaderFlags.cpp
DXILTranslateMetadata.cpp
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/DirectX/DXILDataScalarization.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef LLVM_TARGET_DIRECTX_DXILDATASCALARIZATION_H
#define LLVM_TARGET_DIRECTX_DXILDATASCALARIZATION_H

#include "DXILResource.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"

Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#ifndef LLVM_TARGET_DIRECTX_DXILINTRINSICEXPANSION_H
#define LLVM_TARGET_DIRECTX_DXILINTRINSICEXPANSION_H

#include "DXILResource.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"

Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/DirectX/DXILOpLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "DXILConstants.h"
#include "DXILIntrinsicExpansion.h"
#include "DXILOpBuilder.h"
#include "DXILResourceAnalysis.h"
#include "DXILShaderFlags.h"
#include "DirectX.h"
#include "llvm/ADT/SmallVector.h"
Expand Down Expand Up @@ -889,7 +888,6 @@ class DXILOpLoweringLegacy : public ModulePass {
AU.addRequired<DXILResourceTypeWrapperPass>();
AU.addRequired<DXILResourceBindingWrapperPass>();
AU.addPreserved<DXILResourceBindingWrapperPass>();
AU.addPreserved<DXILResourceMDWrapper>();
AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
AU.addPreserved<ShaderFlagsAnalysisWrapper>();
}
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/DirectX/DXILPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/// Language (DXIL).
//===----------------------------------------------------------------------===//

#include "DXILResourceAnalysis.h"
#include "DXILShaderFlags.h"
#include "DirectX.h"
#include "DirectXIRPasses/PointerTypeAnalysis.h"
Expand Down Expand Up @@ -248,7 +247,6 @@ class DXILPrepareModule : public ModulePass {
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<DXILMetadataAnalysisWrapperPass>();
AU.addPreserved<ShaderFlagsAnalysisWrapper>();
AU.addPreserved<DXILResourceMDWrapper>();
AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
AU.addPreserved<DXILResourceBindingWrapperPass>();
}
Expand Down
23 changes: 3 additions & 20 deletions llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//

#include "DXILPrettyPrinter.h"
#include "DXILResourceAnalysis.h"
#include "DirectX.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/DXILResource.h"
Expand Down Expand Up @@ -222,8 +221,7 @@ struct FormatBindingSize
} // namespace

static void prettyPrintResources(raw_ostream &OS, const DXILBindingMap &DBM,
DXILResourceTypeMap &DRTM,
const dxil::Resources &MDResources) {
DXILResourceTypeMap &DRTM) {
// Column widths are arbitrary but match the widths DXC uses.
OS << ";\n; Resource Bindings:\n;\n";
OS << formatv("; {0,-30} {1,10} {2,7} {3,11} {4,7} {5,14} {6,9}\n", "Name",
Expand All @@ -237,11 +235,6 @@ static void prettyPrintResources(raw_ostream &OS, const DXILBindingMap &DBM,
const dxil::ResourceTypeInfo &RTI = DRTM[RBI.getHandleTy()];

dxil::ResourceClass RC = RTI.getResourceClass();
assert((RC != dxil::ResourceClass::CBuffer || !MDResources.hasCBuffers()) &&
"Old and new cbuffer representations can't coexist");
assert((RC != dxil::ResourceClass::UAV || !MDResources.hasUAVs()) &&
"Old and new UAV representations can't coexist");

StringRef Name(RBI.getName());
StringRef Type(getRCName(RC));
StringRef Format(getFormatName(RTI));
Expand All @@ -252,21 +245,14 @@ static void prettyPrintResources(raw_ostream &OS, const DXILBindingMap &DBM,
OS << formatv("; {0,-30} {1,10} {2,7} {3,11} {4,7} {5,14} {6,9}\n", Name,
Type, Format, Dim, ID, Bind, Count);
}

if (MDResources.hasCBuffers())
MDResources.printCBuffers(OS);
if (MDResources.hasUAVs())
MDResources.printUAVs(OS);

OS << ";\n";
}

PreservedAnalyses DXILPrettyPrinterPass::run(Module &M,
ModuleAnalysisManager &MAM) {
const DXILBindingMap &DBM = MAM.getResult<DXILResourceBindingAnalysis>(M);
DXILResourceTypeMap &DRTM = MAM.getResult<DXILResourceTypeAnalysis>(M);
const dxil::Resources &MDResources = MAM.getResult<DXILResourceMDAnalysis>(M);
prettyPrintResources(OS, DBM, DRTM, MDResources);
prettyPrintResources(OS, DBM, DRTM);
return PreservedAnalyses::all();
}

Expand All @@ -293,7 +279,6 @@ class DXILPrettyPrinterLegacy : public llvm::ModulePass {
AU.setPreservesAll();
AU.addRequired<DXILResourceTypeWrapperPass>();
AU.addRequired<DXILResourceBindingWrapperPass>();
AU.addRequired<DXILResourceMDWrapper>();
}
};
} // namespace
Expand All @@ -303,7 +288,6 @@ INITIALIZE_PASS_BEGIN(DXILPrettyPrinterLegacy, "dxil-pretty-printer",
"DXIL Metadata Pretty Printer", true, true)
INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(DXILResourceBindingWrapperPass)
INITIALIZE_PASS_DEPENDENCY(DXILResourceMDWrapper)
INITIALIZE_PASS_END(DXILPrettyPrinterLegacy, "dxil-pretty-printer",
"DXIL Metadata Pretty Printer", true, true)

Expand All @@ -312,8 +296,7 @@ bool DXILPrettyPrinterLegacy::runOnModule(Module &M) {
getAnalysis<DXILResourceBindingWrapperPass>().getBindingMap();
DXILResourceTypeMap &DRTM =
getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
dxil::Resources &Res = getAnalysis<DXILResourceMDWrapper>().getDXILResource();
prettyPrintResources(OS, DBM, DRTM, Res);
prettyPrintResources(OS, DBM, DRTM);
return false;
}

Expand Down
Loading