Skip to content

Commit 70ebb47

Browse files
authored
[Metal] Add support for -Fre for Metal (microsoft#8159)
This updates the Metal support to enable generating the Metal Shader Converter's reflection JSON file. Required to fix llvm/offload-test-suite#452.
1 parent 2888a87 commit 70ebb47

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

tools/clang/test/DXC/metal.test

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
// Metal libraries are LLVM bitcode. This check inspects the magic number from
44
// the metal library output.
5-
// RUN: %dxc %S/Inputs/smoke.hlsl /T ps_6_0 -metal -Fo Tmp.metal
5+
// RUN: %dxc %S/Inputs/smoke.hlsl /T ps_6_0 -metal -Fo Tmp.metal -Fre Tmp.json
66
// RUN: head -c 4 Tmp.metal | FileCheck -check-prefix=MTL %s
77
// MTL: {{^MTLB}}
8+
9+
// RUN: cat Tmp.json | FileCheck --check-prefix=FRE %s
10+
// FRE: "EntryPoint":"main"

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,10 @@ class DxcCompiler : public IDxcCompiler3,
10851085
}
10861086
}
10871087

1088-
if (pReflectionStream && pReflectionStream->GetPtrSize()) {
1088+
// Skip reflection generation here when targeting metal, this is
1089+
// handled below.
1090+
if (!opts.GenMetal && pReflectionStream &&
1091+
pReflectionStream->GetPtrSize()) {
10891092
CComPtr<IDxcBlob> pReflection;
10901093
IFT(pReflectionStream->QueryInterface(&pReflection));
10911094
IFT(pResult->SetOutputObject(DXC_OUT_REFLECTION, pReflection));
@@ -1173,6 +1176,16 @@ class DxcCompiler : public IDxcCompiler3,
11731176
std::unique_ptr<uint8_t[]>(new uint8_t[MetalLibSize]);
11741177
IRMetalLibGetBytecode(MetalLib, MetalLibBytes.get());
11751178

1179+
if (!opts.OutputReflectionFile.empty()) {
1180+
IRShaderReflection *Reflection = IRShaderReflectionCreate();
1181+
IRObjectGetReflection(AIR, Stage, Reflection);
1182+
const char *RawJSON =
1183+
IRShaderReflectionCopyJSONString(Reflection);
1184+
IFT(pResult->SetOutputString(DXC_OUT_REFLECTION, RawJSON,
1185+
strlen(RawJSON)));
1186+
IRShaderReflectionDestroy(Reflection);
1187+
}
1188+
11761189
// Store the metallib to custom format or disk, or use to create a
11771190
// MTLLibrary.
11781191

0 commit comments

Comments
 (0)