Skip to content

Commit 83b8391

Browse files
committed
[Metal] Add support for -Fre for Metal
This updates the Metal support to enable generating the Metal Shader Converter's reflection JSON file. This is required to fix llvm/offload-test-suite#452
1 parent 37338c2 commit 83b8391

2 files changed

Lines changed: 14 additions & 1 deletion

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,16 @@ class DxcCompiler : public IDxcCompiler3,
11731173
std::unique_ptr<uint8_t[]>(new uint8_t[MetalLibSize]);
11741174
IRMetalLibGetBytecode(MetalLib, MetalLibBytes.get());
11751175

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

0 commit comments

Comments
 (0)