Skip to content

Commit

Permalink
Bump to 1.0.11 and fix some build tooling issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mellinoe committed Jul 12, 2019
1 parent dfa8728 commit 77c0cf6
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 24 deletions.
15 changes: 10 additions & 5 deletions build-full-package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,19 @@ Write-Host "- libveldrid-spirv.so (Android armeabi-v7a)"

Write-Host Generating NuGet package...

$env:VeldridSPIRVVersion = $version
$env:Configuration = $configuration
$env:NativeAssetsPath = "${PSScriptRoot}/download/"
$env:PublicRelease = ${public}

dotnet restore src\Veldrid.SPIRV\Veldrid.SPIRV.csproj

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

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

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

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

dotnet msbuild src\Veldrid.SPIRV.BuildTools\Veldrid.SPIRV.BuildTools.csproj /p:Configuration=$configuration /t:Pack /p:PublicRelease=$public /p:VeldridSPIRVVersion=$version
dotnet msbuild src\Veldrid.SPIRV.BuildTools\Veldrid.SPIRV.BuildTools.csproj /t:Pack
23 changes: 20 additions & 3 deletions src/Veldrid.SPIRV.BuildTools/Veldrid.SPIRV.BuildTools.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
<_VSPV_ToolExePath>$(MSBuildThisFileDirectory)Veldrid.SPIRV.VariantCompiler.dll</_VSPV_ToolExePath>
</PropertyGroup>

<Target Name="CompileShaderVariants" AfterTargets="ResolveReferences">
<Target Name="VSPV_CompileShaderVariants" AfterTargets="ResolveReferences">
<Message Text="Compiling shader variants..." />

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

<PropertyGroup>
<_VSPV_ToolArgs>$(_VSPV_ToolArgs) @(ShaderSourceDir->'--search-path %(Identity)')</_VSPV_ToolArgs>
<_VSPV_ToolArgs>$(_VSPV_ToolArgs) --output-path $(ShaderOutputPath)</_VSPV_ToolArgs>
<_VSPV_ToolArgs>$(_VSPV_ToolArgs) --output-path $(IntermediateOutputPath)\generated_shaders</_VSPV_ToolArgs>
<_VSPV_ToolArgs>$(_VSPV_ToolArgs) --set $(ShaderVariantDef)</_VSPV_ToolArgs>

<_VSPV_GeneratedFilesList>$(IntermediateOutputPath)\generated_shaders\vspv_generated_files.txt</_VSPV_GeneratedFilesList>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -26,6 +27,22 @@
WorkingDirectory="$(MSBuildProjectDirectory)"
StandardOutputImportance="high"
ContinueOnError="$(_VSPV_ContinueOnError)" />

<ReadLinesFromFile
File="$(_VSPV_GeneratedFilesList)"
ContinueOnError="$(_VSPV_ContinueOnError)">
<Output
TaskParameter="Lines"
ItemName="VSPV_GeneratedShader" />
</ReadLinesFromFile>
</Target>

<Target Name="VSPV_EmbedGeneratedShaders"
AfterTargets="AssignTargetPaths"
Condition="'$(EmbedGeneratedShaders)' == 'true'">
<ItemGroup>
<EmbeddedResource Include="@(VSPV_GeneratedShader)" LogicalName="%(FileName)%(Extension)" />
</ItemGroup>
</Target>

</Project>
42 changes: 29 additions & 13 deletions src/Veldrid.SPIRV.VariantCompiler/CompilationSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,12 @@ public VariantCompiler(List<string> shaderSearchPaths, string outputPath)
_outputPath = outputPath;
}

public void Compile(ShaderVariantDescription variant)
public string[] Compile(ShaderVariantDescription variant)
{
if (variant.Shaders.Length == 1)
{
if (variant.Shaders[0].Stage == ShaderStages.Vertex) { CompileVertexFragment(variant); }
if (variant.Shaders[0].Stage == ShaderStages.Compute) { CompileCompute(variant); }
else
{
throw new SpirvCompilationException(
$"Variant \"{variant.Name}\" has an unsupported set of shader stages.");
}
if (variant.Shaders[0].Stage == ShaderStages.Vertex) { return CompileVertexFragment(variant); }
if (variant.Shaders[0].Stage == ShaderStages.Compute) { return CompileCompute(variant); }
}
if (variant.Shaders.Length == 2)
{
Expand All @@ -82,12 +77,18 @@ public void Compile(ShaderVariantDescription variant)
throw new SpirvCompilationException($"Variant \"{variant.Name}\" is missing a fragment shader.");
}

CompileVertexFragment(variant);
return CompileVertexFragment(variant);
}
else
{
throw new SpirvCompilationException(
$"Variant \"{variant.Name}\" has an unsupported combination of shader stages.");
}
}

private void CompileVertexFragment(ShaderVariantDescription variant)
private string[] CompileVertexFragment(ShaderVariantDescription variant)
{
List<string> generatedFiles = new List<string>();
List<Exception> compilationExceptions = new List<Exception>();
byte[] vsBytes = null;
byte[] fsBytes = null;
Expand All @@ -98,6 +99,9 @@ private void CompileVertexFragment(ShaderVariantDescription variant)
try
{
vsBytes = CompileToSpirv(variant, vertexFileName, ShaderStages.Vertex);
string spvPath = Path.Combine(_outputPath, $"{variant.Name}_{ShaderStages.Vertex.ToString()}.spv");
File.WriteAllBytes(spvPath, vsBytes);
generatedFiles.Add(spvPath);
}
catch (Exception e)
{
Expand All @@ -111,6 +115,9 @@ private void CompileVertexFragment(ShaderVariantDescription variant)
try
{
fsBytes = CompileToSpirv(variant, fragmentFileName, ShaderStages.Fragment);
string spvPath = Path.Combine(_outputPath, $"{variant.Name}_{ShaderStages.Fragment.ToString()}.spv");
File.WriteAllBytes(spvPath, fsBytes);
generatedFiles.Add(spvPath);
}
catch (Exception e)
{
Expand Down Expand Up @@ -138,11 +145,13 @@ private void CompileVertexFragment(ShaderVariantDescription variant)
{
string vsPath = Path.Combine(_outputPath, $"{variant.Name}_Vertex.{GetExtension(target)}");
File.WriteAllText(vsPath, result.VertexShader);
generatedFiles.Add(vsPath);
}
if (result.FragmentShader != null)
{
string fsPath = Path.Combine(_outputPath, $"{variant.Name}_Fragment.{GetExtension(target)}");
File.WriteAllText(fsPath, result.FragmentShader);
generatedFiles.Add(fsPath);
}
}
catch (Exception e)
Expand All @@ -155,6 +164,8 @@ private void CompileVertexFragment(ShaderVariantDescription variant)
{
throw new AggregateException($"Errors were encountered when compiling shader variant(s).", compilationExceptions);
}

return generatedFiles.ToArray();
}

private string GetExtension(CrossCompileTarget target)
Expand Down Expand Up @@ -186,8 +197,6 @@ private byte[] CompileToSpirv(
fileName,
stage,
glslOptions);
string spvPath = Path.Combine(_outputPath, $"{variant.Name}_{stage.ToString()}.spv");
File.WriteAllBytes(spvPath, result.SpirvBytes);
return result.SpirvBytes;
}

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

private void CompileCompute(ShaderVariantDescription variant)
private string[] CompileCompute(ShaderVariantDescription variant)
{
List<string> generatedFiles = new List<string>();
byte[] csBytes = CompileToSpirv(variant, variant.Shaders[0].FileName, ShaderStages.Compute);
string spvPath = Path.Combine(_outputPath, $"{variant.Name}_{ShaderStages.Compute.ToString()}.spv");
File.WriteAllBytes(spvPath, csBytes);
generatedFiles.Add(spvPath);

List<Exception> compilationExceptions = new List<Exception>();
foreach (CrossCompileTarget target in variant.Targets)
Expand All @@ -224,6 +237,7 @@ private void CompileCompute(ShaderVariantDescription variant)
ComputeCompilationResult result = SpirvCompilation.CompileCompute(csBytes, target, variant.CrossCompileOptions);
string csPath = Path.Combine(_outputPath, $"{variant.Name}_Compute.{GetExtension(target)}");
File.WriteAllText(csPath, result.ComputeShader);
generatedFiles.Add(csPath);
}
catch (Exception e)
{
Expand All @@ -235,6 +249,8 @@ private void CompileCompute(ShaderVariantDescription variant)
{
throw new AggregateException($"Errors were encountered when compiling shader variant(s).", compilationExceptions);
}

return generatedFiles.ToArray();
}
}
}
12 changes: 11 additions & 1 deletion src/Veldrid.SPIRV.VariantCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,21 @@ public void OnExecute()
descs = serializer.Deserialize<ShaderVariantDescription[]>(jtr);
}

HashSet<string> generatedPaths = new HashSet<string>();

VariantCompiler compiler = new VariantCompiler(new List<string>(SearchPaths), OutputPath);
foreach (ShaderVariantDescription desc in descs)
{
compiler.Compile(desc);
string[] newPaths = compiler.Compile(desc);
foreach (string s in newPaths)
{
generatedPaths.Add(s);
}
}

string generatedFilesListText = string.Join(Environment.NewLine, generatedPaths);
string generatedFilesListPath = Path.Combine(OutputPath, "vspv_generated_files.txt");
File.WriteAllText(generatedFilesListPath, generatedFilesListText);
}
}
}
2 changes: 1 addition & 1 deletion src/Veldrid.SPIRV/GlslCompileOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public GlslCompileOptions()
public GlslCompileOptions(bool debug, params MacroDefinition[] macros)
{
Debug = debug;
Macros = macros;
Macros = macros ?? Array.Empty<MacroDefinition>();
}
}
}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.0.10",
"version": "1.0.11",
"publicReleaseRefSpec": [
"^refs/tags/v\\d+\\.\\d+" // we also release tags starting with vN.N
],
Expand Down

0 comments on commit 77c0cf6

Please sign in to comment.