Skip to content

Commit 77c0cf6

Browse files
committed
Bump to 1.0.11 and fix some build tooling issues.
1 parent dfa8728 commit 77c0cf6

File tree

6 files changed

+72
-24
lines changed

6 files changed

+72
-24
lines changed

build-full-package.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,19 @@ Write-Host "- libveldrid-spirv.so (Android armeabi-v7a)"
111111

112112
Write-Host Generating NuGet package...
113113

114+
$env:VeldridSPIRVVersion = $version
115+
$env:Configuration = $configuration
116+
$env:NativeAssetsPath = "${PSScriptRoot}/download/"
117+
$env:PublicRelease = ${public}
118+
114119
dotnet restore src\Veldrid.SPIRV\Veldrid.SPIRV.csproj
115120

116-
dotnet msbuild src\Veldrid.SPIRV\Veldrid.SPIRV.csproj /p:Configuration=$configuration /t:Pack /p:NativeAssetsPath=$PSScriptRoot/download/ /p:PublicRelease=$public
121+
dotnet msbuild src\Veldrid.SPIRV\Veldrid.SPIRV.csproj /t:Pack
117122

118-
dotnet restore src\Veldrid.SPIRV.VariantCompiler\Veldrid.SPIRV.VariantCompiler.csproj --source bin\Packages\Release /p:VeldridSPIRVVersion=$version --no-cache
123+
dotnet restore src\Veldrid.SPIRV.VariantCompiler\Veldrid.SPIRV.VariantCompiler.csproj --source ${PSScriptRoot}\bin\Packages\Release --no-cache
119124

120-
dotnet msbuild src\Veldrid.SPIRV.VariantCompiler\Veldrid.SPIRV.VariantCompiler.csproj /p:Configuration=$configuration /p:PublicRelease=$public /p:VeldridSPIRVVersion=$version
125+
dotnet msbuild src\Veldrid.SPIRV.VariantCompiler\Veldrid.SPIRV.VariantCompiler.csproj
121126

122-
dotnet restore src\Veldrid.SPIRV.BuildTools\Veldrid.SPIRV.BuildTools.csproj --source bin\Packages\Release
127+
dotnet restore src\Veldrid.SPIRV.BuildTools\Veldrid.SPIRV.BuildTools.csproj --source ${PSScriptRoot}\bin\Packages\Release
123128

124-
dotnet msbuild src\Veldrid.SPIRV.BuildTools\Veldrid.SPIRV.BuildTools.csproj /p:Configuration=$configuration /t:Pack /p:PublicRelease=$public /p:VeldridSPIRVVersion=$version
129+
dotnet msbuild src\Veldrid.SPIRV.BuildTools\Veldrid.SPIRV.BuildTools.csproj /t:Pack

src/Veldrid.SPIRV.BuildTools/Veldrid.SPIRV.BuildTools.targets

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
<_VSPV_ToolExePath>$(MSBuildThisFileDirectory)Veldrid.SPIRV.VariantCompiler.dll</_VSPV_ToolExePath>
55
</PropertyGroup>
66

7-
<Target Name="CompileShaderVariants" AfterTargets="ResolveReferences">
7+
<Target Name="VSPV_CompileShaderVariants" AfterTargets="ResolveReferences">
88
<Message Text="Compiling shader variants..." />
99

1010
<Error Condition="'$(_VSPV_ToolExePath)' == ''" Text="The Veldrid.SPIRV variant compiler tool was not located or set." />
11-
<Error Condition="'$(ShaderOutputPath)' == ''" Text="ShaderOutputPath must be set." />
1211
<Error Condition="'$(ShaderVariantDef)' == ''" Text="ShaderVariantDef must be set to a JSON file defining shader variants." />
1312

1413
<PropertyGroup>
1514
<_VSPV_ToolArgs>$(_VSPV_ToolArgs) @(ShaderSourceDir->'--search-path %(Identity)')</_VSPV_ToolArgs>
16-
<_VSPV_ToolArgs>$(_VSPV_ToolArgs) --output-path $(ShaderOutputPath)</_VSPV_ToolArgs>
15+
<_VSPV_ToolArgs>$(_VSPV_ToolArgs) --output-path $(IntermediateOutputPath)\generated_shaders</_VSPV_ToolArgs>
1716
<_VSPV_ToolArgs>$(_VSPV_ToolArgs) --set $(ShaderVariantDef)</_VSPV_ToolArgs>
17+
18+
<_VSPV_GeneratedFilesList>$(IntermediateOutputPath)\generated_shaders\vspv_generated_files.txt</_VSPV_GeneratedFilesList>
1819
</PropertyGroup>
1920

2021
<PropertyGroup>
@@ -26,6 +27,22 @@
2627
WorkingDirectory="$(MSBuildProjectDirectory)"
2728
StandardOutputImportance="high"
2829
ContinueOnError="$(_VSPV_ContinueOnError)" />
30+
31+
<ReadLinesFromFile
32+
File="$(_VSPV_GeneratedFilesList)"
33+
ContinueOnError="$(_VSPV_ContinueOnError)">
34+
<Output
35+
TaskParameter="Lines"
36+
ItemName="VSPV_GeneratedShader" />
37+
</ReadLinesFromFile>
38+
</Target>
39+
40+
<Target Name="VSPV_EmbedGeneratedShaders"
41+
AfterTargets="AssignTargetPaths"
42+
Condition="'$(EmbedGeneratedShaders)' == 'true'">
43+
<ItemGroup>
44+
<EmbeddedResource Include="@(VSPV_GeneratedShader)" LogicalName="%(FileName)%(Extension)" />
45+
</ItemGroup>
2946
</Target>
3047

3148
</Project>

src/Veldrid.SPIRV.VariantCompiler/CompilationSet.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,12 @@ public VariantCompiler(List<string> shaderSearchPaths, string outputPath)
5151
_outputPath = outputPath;
5252
}
5353

54-
public void Compile(ShaderVariantDescription variant)
54+
public string[] Compile(ShaderVariantDescription variant)
5555
{
5656
if (variant.Shaders.Length == 1)
5757
{
58-
if (variant.Shaders[0].Stage == ShaderStages.Vertex) { CompileVertexFragment(variant); }
59-
if (variant.Shaders[0].Stage == ShaderStages.Compute) { CompileCompute(variant); }
60-
else
61-
{
62-
throw new SpirvCompilationException(
63-
$"Variant \"{variant.Name}\" has an unsupported set of shader stages.");
64-
}
58+
if (variant.Shaders[0].Stage == ShaderStages.Vertex) { return CompileVertexFragment(variant); }
59+
if (variant.Shaders[0].Stage == ShaderStages.Compute) { return CompileCompute(variant); }
6560
}
6661
if (variant.Shaders.Length == 2)
6762
{
@@ -82,12 +77,18 @@ public void Compile(ShaderVariantDescription variant)
8277
throw new SpirvCompilationException($"Variant \"{variant.Name}\" is missing a fragment shader.");
8378
}
8479

85-
CompileVertexFragment(variant);
80+
return CompileVertexFragment(variant);
81+
}
82+
else
83+
{
84+
throw new SpirvCompilationException(
85+
$"Variant \"{variant.Name}\" has an unsupported combination of shader stages.");
8686
}
8787
}
8888

89-
private void CompileVertexFragment(ShaderVariantDescription variant)
89+
private string[] CompileVertexFragment(ShaderVariantDescription variant)
9090
{
91+
List<string> generatedFiles = new List<string>();
9192
List<Exception> compilationExceptions = new List<Exception>();
9293
byte[] vsBytes = null;
9394
byte[] fsBytes = null;
@@ -98,6 +99,9 @@ private void CompileVertexFragment(ShaderVariantDescription variant)
9899
try
99100
{
100101
vsBytes = CompileToSpirv(variant, vertexFileName, ShaderStages.Vertex);
102+
string spvPath = Path.Combine(_outputPath, $"{variant.Name}_{ShaderStages.Vertex.ToString()}.spv");
103+
File.WriteAllBytes(spvPath, vsBytes);
104+
generatedFiles.Add(spvPath);
101105
}
102106
catch (Exception e)
103107
{
@@ -111,6 +115,9 @@ private void CompileVertexFragment(ShaderVariantDescription variant)
111115
try
112116
{
113117
fsBytes = CompileToSpirv(variant, fragmentFileName, ShaderStages.Fragment);
118+
string spvPath = Path.Combine(_outputPath, $"{variant.Name}_{ShaderStages.Fragment.ToString()}.spv");
119+
File.WriteAllBytes(spvPath, fsBytes);
120+
generatedFiles.Add(spvPath);
114121
}
115122
catch (Exception e)
116123
{
@@ -138,11 +145,13 @@ private void CompileVertexFragment(ShaderVariantDescription variant)
138145
{
139146
string vsPath = Path.Combine(_outputPath, $"{variant.Name}_Vertex.{GetExtension(target)}");
140147
File.WriteAllText(vsPath, result.VertexShader);
148+
generatedFiles.Add(vsPath);
141149
}
142150
if (result.FragmentShader != null)
143151
{
144152
string fsPath = Path.Combine(_outputPath, $"{variant.Name}_Fragment.{GetExtension(target)}");
145153
File.WriteAllText(fsPath, result.FragmentShader);
154+
generatedFiles.Add(fsPath);
146155
}
147156
}
148157
catch (Exception e)
@@ -155,6 +164,8 @@ private void CompileVertexFragment(ShaderVariantDescription variant)
155164
{
156165
throw new AggregateException($"Errors were encountered when compiling shader variant(s).", compilationExceptions);
157166
}
167+
168+
return generatedFiles.ToArray();
158169
}
159170

160171
private string GetExtension(CrossCompileTarget target)
@@ -186,8 +197,6 @@ private byte[] CompileToSpirv(
186197
fileName,
187198
stage,
188199
glslOptions);
189-
string spvPath = Path.Combine(_outputPath, $"{variant.Name}_{stage.ToString()}.spv");
190-
File.WriteAllBytes(spvPath, result.SpirvBytes);
191200
return result.SpirvBytes;
192201
}
193202

@@ -212,9 +221,13 @@ private string LoadGlsl(string fileName)
212221
throw new FileNotFoundException($"Unable to find shader file \"{fileName}\".");
213222
}
214223

215-
private void CompileCompute(ShaderVariantDescription variant)
224+
private string[] CompileCompute(ShaderVariantDescription variant)
216225
{
226+
List<string> generatedFiles = new List<string>();
217227
byte[] csBytes = CompileToSpirv(variant, variant.Shaders[0].FileName, ShaderStages.Compute);
228+
string spvPath = Path.Combine(_outputPath, $"{variant.Name}_{ShaderStages.Compute.ToString()}.spv");
229+
File.WriteAllBytes(spvPath, csBytes);
230+
generatedFiles.Add(spvPath);
218231

219232
List<Exception> compilationExceptions = new List<Exception>();
220233
foreach (CrossCompileTarget target in variant.Targets)
@@ -224,6 +237,7 @@ private void CompileCompute(ShaderVariantDescription variant)
224237
ComputeCompilationResult result = SpirvCompilation.CompileCompute(csBytes, target, variant.CrossCompileOptions);
225238
string csPath = Path.Combine(_outputPath, $"{variant.Name}_Compute.{GetExtension(target)}");
226239
File.WriteAllText(csPath, result.ComputeShader);
240+
generatedFiles.Add(csPath);
227241
}
228242
catch (Exception e)
229243
{
@@ -235,6 +249,8 @@ private void CompileCompute(ShaderVariantDescription variant)
235249
{
236250
throw new AggregateException($"Errors were encountered when compiling shader variant(s).", compilationExceptions);
237251
}
252+
253+
return generatedFiles.ToArray();
238254
}
239255
}
240256
}

src/Veldrid.SPIRV.VariantCompiler/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,21 @@ public void OnExecute()
4141
descs = serializer.Deserialize<ShaderVariantDescription[]>(jtr);
4242
}
4343

44+
HashSet<string> generatedPaths = new HashSet<string>();
45+
4446
VariantCompiler compiler = new VariantCompiler(new List<string>(SearchPaths), OutputPath);
4547
foreach (ShaderVariantDescription desc in descs)
4648
{
47-
compiler.Compile(desc);
49+
string[] newPaths = compiler.Compile(desc);
50+
foreach (string s in newPaths)
51+
{
52+
generatedPaths.Add(s);
53+
}
4854
}
55+
56+
string generatedFilesListText = string.Join(Environment.NewLine, generatedPaths);
57+
string generatedFilesListPath = Path.Combine(OutputPath, "vspv_generated_files.txt");
58+
File.WriteAllText(generatedFilesListPath, generatedFilesListText);
4959
}
5060
}
5161
}

src/Veldrid.SPIRV/GlslCompileOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public GlslCompileOptions()
4242
public GlslCompileOptions(bool debug, params MacroDefinition[] macros)
4343
{
4444
Debug = debug;
45-
Macros = macros;
45+
Macros = macros ?? Array.Empty<MacroDefinition>();
4646
}
4747
}
4848
}

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"publicReleaseRefSpec": [
55
"^refs/tags/v\\d+\\.\\d+" // we also release tags starting with vN.N
66
],

0 commit comments

Comments
 (0)