Skip to content

Commit 3e11f35

Browse files
committed
Output .air files and add metallib compiler
1 parent 0f11ed5 commit 3e11f35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+195
-115
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ Shader Playground is supported by these amazing people. Their sponsorship allows
6464

6565
* [Aras Pranckevičius](https://aras-p.info/)
6666
<!-- -->
67-
* [Rys Sommefeldt](https://rys.sommefeldt.com/)
6867
* [Neil Henning](http://www.duskborn.com)
6968
<!-- -->
70-
* [Dimitri Diakopoulos](http://www.dimitridiakopoulos.com/)
7169
* [Laura Reznikov](https://twitter.com/theanimator)
72-
* [Nathan Reed](http://reedbeta.com/)
7370
* [Aisha Brown](https://twitter.com/aishization)
7471
* [Sean Cooper](https://kornnerstudios.blogspot.com/)
7572
* [Ken Hu](https://silvesthu.github.io/)

src/ShaderPlayground.Core/Compiler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public static class Compiler
6060
new LzmaCompiler(),
6161
new MaliCompiler(),
6262
new MetalCompiler(),
63+
new MetalLibCompiler(),
6364
new MinizCompiler(),
6465
new NagaCompiler(),
6566
new PowerVRCompiler(),
@@ -105,6 +106,7 @@ public static IReadOnlyList<ShaderCompilerResult> Compile(
105106

106107
var eachShaderCode = shaderCode;
107108
var results = new List<ShaderCompilerResult>();
109+
var previousArguments = new List<ShaderCompilerArguments>();
108110

109111
var error = false;
110112

@@ -127,7 +129,9 @@ public static IReadOnlyList<ShaderCompilerResult> Compile(
127129
compiler,
128130
compilationStep.Arguments);
129131

130-
var result = compiler.Compile(eachShaderCode, arguments);
132+
var result = compiler.Compile(eachShaderCode, arguments, previousArguments);
133+
134+
previousArguments.Add(arguments);
131135

132136
if (!result.Success)
133137
{

src/ShaderPlayground.Core/CompilerNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static class CompilerNames
1010
public const string Glslang = "glslang";
1111
public const string IntelShaderAnalyzer = "intelshaderanalyzer";
1212
public const string Metal = "metal";
13+
public const string MetalLib = "metallib";
1314
public const string Naga = "naga";
1415
public const string PowerVR = "powervr";
1516
public const string Rga = "rga";

src/ShaderPlayground.Core/Compilers/Angle/AngleCompiler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using ShaderPlayground.Core.Util;
34

45
namespace ShaderPlayground.Core.Compilers.Angle
@@ -18,7 +19,7 @@ internal sealed class AngleCompiler : IShaderCompiler
1819
CommonParameters.CreateOutputParameter(new[] { LanguageNames.Glsl, LanguageNames.Hlsl })
1920
};
2021

21-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
22+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
2223
{
2324
var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);
2425

src/ShaderPlayground.Core/Compilers/Clspv/ClspvCompiler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using ShaderPlayground.Core.Util;
34

45
namespace ShaderPlayground.Core.Compilers.Clspv
@@ -19,7 +20,7 @@ internal sealed class ClspvCompiler : IShaderCompiler
1920
CommonParameters.CreateOutputParameter(new[] { LanguageNames.SpirV }),
2021
};
2122

22-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
23+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
2324
{
2425
using (var tempFile = TempFile.FromShaderCode(shaderCode))
2526
{

src/ShaderPlayground.Core/Compilers/Dxc/DxcCompiler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using ShaderPlayground.Core.Util;
45

@@ -123,7 +124,7 @@ internal sealed class DxcCompiler : IShaderCompiler
123124
"lib_6_4",
124125
};
125126

126-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
127+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
127128
{
128129
var entryPoint = arguments.GetString("EntryPoint");
129130
var targetProfile = arguments.GetString("TargetProfile");

src/ShaderPlayground.Core/Compilers/Fxc/FxcCompiler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using ShaderPlayground.Core.Util;
34

45
namespace ShaderPlayground.Core.Compilers.Fxc
@@ -71,7 +72,7 @@ public sealed class FxcCompiler : IShaderCompiler
7172
"3"
7273
};
7374

74-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
75+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
7576
{
7677
var entryPoint = arguments.GetString("EntryPoint");
7778
var targetProfile = arguments.GetString("TargetProfile");

src/ShaderPlayground.Core/Compilers/GlslOptimizer/GlslOptimizerCompiler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ShaderPlayground.Core.Util;
1+
using System.Collections.Generic;
2+
using ShaderPlayground.Core.Util;
23

34
namespace ShaderPlayground.Core.Compilers.GlslOptimizer
45
{
@@ -24,7 +25,7 @@ internal sealed class GlslOptimizerCompiler : IShaderCompiler
2425
"Fragment"
2526
};
2627

27-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
28+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
2829
{
2930
var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);
3031

src/ShaderPlayground.Core/Compilers/Glslang/GlslangCompiler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ShaderPlayground.Core.Util;
1+
using System.Collections.Generic;
2+
using ShaderPlayground.Core.Util;
23

34
namespace ShaderPlayground.Core.Compilers.Glslang
45
{
@@ -65,7 +66,7 @@ internal sealed class GlslangCompiler : IShaderCompiler
6566
TargetSpirV1_5,
6667
};
6768

68-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
69+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
6970
{
7071
var stage = arguments.GetString("ShaderStage");
7172

src/ShaderPlayground.Core/Compilers/Glslang/SpirvRemapCompiler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System.Collections.Generic;
2+
using System.IO;
23
using ShaderPlayground.Core.Util;
34

45
namespace ShaderPlayground.Core.Compilers.Glslang
@@ -43,7 +44,7 @@ internal sealed class SpirvRemapCompiler : IShaderCompiler
4344
"loadstore"
4445
};
4546

46-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
47+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
4748
{
4849
var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);
4950

src/ShaderPlayground.Core/Compilers/Hlsl2Glsl/Hlsl2GlslCompiler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using ShaderPlayground.Core.Util;
34

45
namespace ShaderPlayground.Core.Compilers.Hlsl2Glsl
@@ -36,7 +37,7 @@ internal sealed class Hlsl2GlslCompiler : IShaderCompiler
3637
"GLSL ES 300" // ETargetGLSL_ES_300
3738
};
3839

39-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
40+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
4041
{
4142
var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);
4243

src/ShaderPlayground.Core/Compilers/HlslCc/HlslCcCompiler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ShaderPlayground.Core.Util;
1+
using System.Collections.Generic;
2+
using ShaderPlayground.Core.Util;
23

34
namespace ShaderPlayground.Core.Compilers.HlslCc
45
{
@@ -17,7 +18,7 @@ internal sealed class HlslCcCompiler : IShaderCompiler
1718
CommonParameters.CreateOutputParameter(new[] { LanguageNames.Glsl, LanguageNames.Metal })
1819
};
1920

20-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
21+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
2122
{
2223
var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);
2324

src/ShaderPlayground.Core/Compilers/HlslParser/HlslParserCompiler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using ShaderPlayground.Core.Util;
34

45
namespace ShaderPlayground.Core.Compilers.HlslParser
@@ -26,7 +27,7 @@ internal sealed class HlslParserCompiler : IShaderCompiler
2627
"Fragment"
2728
};
2829

29-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
30+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
3031
{
3132
var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);
3233

src/ShaderPlayground.Core/Compilers/IntelShaderAnalyzer/IntelShaderAnalyzerCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal sealed class IntelShaderAnalyzerCompiler : IShaderCompiler
5959
"vs_5_1"
6060
};
6161

62-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
62+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
6363
{
6464
var args = string.Empty;
6565

src/ShaderPlayground.Core/Compilers/Lzma/LzmaCompiler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ShaderPlayground.Core.Util;
1+
using System.Collections.Generic;
2+
using ShaderPlayground.Core.Util;
23

34
namespace ShaderPlayground.Core.Compilers.Lzma
45
{
@@ -29,7 +30,7 @@ internal sealed class LzmaCompiler : IShaderCompiler
2930
"6"
3031
};
3132

32-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
33+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
3334
{
3435
var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);
3536

src/ShaderPlayground.Core/Compilers/Mali/MaliCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static MaliCompiler()
6868
"vulkan",
6969
};
7070

71-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
71+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
7272
{
7373
var stage = GetStageFlag(arguments.GetString("ShaderStage"));
7474
var core = arguments.GetString("Core");

src/ShaderPlayground.Core/Compilers/Metal/MetalCompiler.cs

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using ShaderPlayground.Core.Util;
45

@@ -20,7 +21,7 @@ internal sealed class MetalCompiler : IShaderCompiler
2021
CommonParameters.CreateOutputParameter(new[] { LanguageNames.MetalIR }),
2122
};
2223

23-
private static readonly string[] MetalVersions =
24+
internal static readonly string[] MetalVersions =
2425
{
2526
"macos-metal1.0",
2627
"macos-metal1.1",
@@ -40,42 +41,7 @@ internal sealed class MetalCompiler : IShaderCompiler
4041
"ios-metal2.4",
4142
};
4243

43-
// Corresponds to MetalVersions just above.
44-
private static readonly VersionMetadata[] PlatformVersions =
45-
{
46-
new VersionMetadata("10.11.0", "macosx", "macosx"),
47-
new VersionMetadata("10.11.0", "macosx", "macosx"),
48-
new VersionMetadata("10.12.0", "macosx", "macosx"),
49-
new VersionMetadata("10.13.0", "macosx", "macosx"),
50-
new VersionMetadata("10.14.0", "macosx", "macosx"),
51-
new VersionMetadata("10.15.0", "macosx", "macosx"),
52-
new VersionMetadata("11.0.0", "macosx", "macosx"),
53-
new VersionMetadata("12.0.0", "macosx", "macosx"),
54-
new VersionMetadata("8.0.0", "iphoneos", "ios"),
55-
new VersionMetadata("9.0.0", "iphoneos", "ios"),
56-
new VersionMetadata("10.0.0", "iphoneos", "ios"),
57-
new VersionMetadata("11.0.0", "iphoneos", "ios"),
58-
new VersionMetadata("12.0.0", "iphoneos", "ios"),
59-
new VersionMetadata("13.0.0", "iphoneos", "ios"),
60-
new VersionMetadata("14.0.0", "iphoneos", "ios"),
61-
new VersionMetadata("15.0.0", "iphoneos", "ios"),
62-
};
63-
64-
private readonly struct VersionMetadata
65-
{
66-
public readonly string VersionNumber;
67-
public readonly string PlatformShort;
68-
public readonly string PlatformFull;
69-
70-
public VersionMetadata(string versionNumber, string platformShort, string platformFull)
71-
{
72-
VersionNumber = versionNumber;
73-
PlatformShort = platformShort;
74-
PlatformFull = platformFull;
75-
}
76-
}
77-
78-
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
44+
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments, List<ShaderCompilerArguments> previousCompilerArguments)
7945
{
8046
using var tempFile = TempFile.FromShaderCode(shaderCode);
8147

@@ -102,29 +68,12 @@ public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArgumen
10268
{
10369
var binaryOutputPath = $"{tempFile.FilePath}.air";
10470

105-
// This is the command line we actually want to run:
106-
// $"metal.exe -std={arguments.GetString("MetalVersion")} -I \"{includePath}\" -o \"{binaryOutputPath}\" \"{tempFile.FilePath}\"",
107-
// But because that writes the .air file to a temp folder, it doesn't work on Azure. So I used "-v" to find out the "real"
108-
// command lines used internally by the front-end driver, and that's what we use here.
109-
110-
var intermediateOutputPath = $"{tempFile.FilePath}-intermediate.air";
111-
112-
var versionMetadata = PlatformVersions[Array.IndexOf(MetalVersions, metalVersion)];
113-
11471
ProcessHelper.Run(
11572
CommonParameters.GetBinaryPath("metal", arguments, "metal.exe"),
116-
$"-cc1 -triple air64-apple-{versionMetadata.PlatformShort}{versionMetadata.VersionNumber} -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -Wuninitialized -Wunused-variable -Wunused-value -Wunused-function -Wsign-compare -Wreturn-type -Wmissing-braces -finclude-default-header -emit-llvm-bc -disable-free -disable-llvm-verifier -discard-value-names -main-file-name {Path.GetFileName(tempFile.FilePath)} -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fno-strict-return -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fno-trapping-math -ffp-contract=fast -ffast-math -ffinite-math-only -no-integrated-as -faligned-alloc-unavailable -dwarf-column-info -debugger-tuning=lldb -v -I \"{includePath}\" -Wmtl-shader-return-type -Werror=mtl-shader-return-type -std={metalVersion} -fno-dwarf-directory-asm -fno-autolink -fdebug-compilation-dir \"{CommonParameters.GetBinaryPath("metal", arguments)}\" -ferror-limit 19 -fmessage-length 316 -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx -fdiagnostics-show-option -fcolor-diagnostics -o \"{intermediateOutputPath}\" -x metal \"{tempFile.FilePath}\"",
117-
out _,
118-
out _);
119-
120-
ProcessHelper.Run(
121-
CommonParameters.GetBinaryPath("metal", arguments, "air-lld.exe"),
122-
$"-arch air64 -{versionMetadata.PlatformFull}_version_min {versionMetadata.VersionNumber} -o \"{binaryOutputPath}\" \"{intermediateOutputPath}\"",
73+
$"-std={arguments.GetString("MetalVersion")} -I \"{includePath}\" -o \"{binaryOutputPath}\" -c \"{tempFile.FilePath}\"",
12374
out _,
12475
out _);
12576

126-
FileHelper.DeleteIfExists(intermediateOutputPath);
127-
12877
binaryOutput = FileHelper.ReadAllBytesIfExists(binaryOutputPath);
12978

13079
FileHelper.DeleteIfExists(binaryOutputPath);

0 commit comments

Comments
 (0)