using System.Diagnostics;
using System.IO;
using System.Linq;
+using System.Text;
using Microsoft.Build.Framework;
namespace SpirVTasks {
get;
set;
}
+ [Required]
+ [Output]
+ public ITaskItem DestinationFile {
+ get;
+ set;
+ }
+
public ITaskItem AdditionalIncludeDirectories {
get;
set;
}
/// <summary>
- /// Optional, Specify the comple glslc executable path.
+ /// Optional, set macros to be passed to the compiler, project 'DefineConstants' item is automatically added
/// </summary>
- public ITaskItem SpirVCompilerPath {
+ public ITaskItem[] DefineConstants {
get;
set;
}
- [Required]
- [Output]
- public ITaskItem DestinationFile {
+ public ITaskItem Optimisation {
+ get;
+ set;
+ }
+ /// <summary>
+ /// Optional, Specify the comple glslc executable path.
+ /// </summary>
+ public ITaskItem SpirVCompilerPath {
get;
set;
}
}
/// <summary>
- /// Use the SpirVCompilerPath element if present. if not search 'VULKAN_SDK' environment, then PATH.
+ /// Use the SpirVCompilerPath element if present. if not search 'VULKAN_SDK' environment, then PATH env variable.
/// </summary>
bool tryFindGlslcExecutable (out string glslcPath) {
if (!string.IsNullOrEmpty (SpirVCompilerPath?.ItemSpec)) {
Directory.CreateDirectory (Path.GetDirectoryName (DestinationFile.ItemSpec));
+ //build macros parameter
+ StringBuilder macros = new StringBuilder ();
+ if (DefineConstants != null) {
+ for (int i = 0; i < DefineConstants.Length; i++) {
+ if (!string.IsNullOrEmpty (DefineConstants[i]?.ItemSpec)) {
+ foreach (string macro in DefineConstants [i].ItemSpec.Split (new char[]{ ';'}, StringSplitOptions.RemoveEmptyEntries))
+ macros.Append ($"-D{macro} ");
+ }
+ }
+ }
+ string optimisationStr = "";
+ if (!string.IsNullOrEmpty (Optimisation?.ItemSpec)) {
+ if (string.Equals (Optimisation.ItemSpec, "perf", StringComparison.OrdinalIgnoreCase))
+ optimisationStr = "-O";
+ else if (string.Equals (Optimisation.ItemSpec, "size", StringComparison.OrdinalIgnoreCase))
+ optimisationStr = "-Os";
+ else if (string.Equals (Optimisation.ItemSpec, "none", StringComparison.OrdinalIgnoreCase))
+ optimisationStr = "-O0";
+ }else
+ optimisationStr = "-O";
+
Process glslc = new Process();
//glslc.StartInfo.StandardOutputEncoding = System.Text.Encoding.ASCII;
//glslc.StartInfo.StandardErrorEncoding = System.Text.Encoding.ASCII;
glslc.StartInfo.RedirectStandardOutput = true;
glslc.StartInfo.RedirectStandardError = true;
glslc.StartInfo.FileName = glslcPath;
- glslc.StartInfo.Arguments = $"{tempFile} -o {DestinationFile.ItemSpec}";
+ glslc.StartInfo.Arguments = $"{tempFile} -o {DestinationFile.ItemSpec} {macros.ToString()} {optimisationStr}";
glslc.StartInfo.CreateNoWindow = true;
glslc.EnableRaisingEvents = true;
glslc.OutputDataReceived += Glslc_OutputDataReceived;
glslc.ErrorDataReceived += Glslc_ErrorDataReceived;
+ Log.LogMessage (MessageImportance.High, $"-> glslc {glslc.StartInfo.Arguments}");
+
glslc.Start ();
glslc.BeginErrorReadLine ();
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
- <ReleaseVersion>0.1.11</ReleaseVersion>
+ <ReleaseVersion>0.1.15</ReleaseVersion>
<SynchReleaseVersion>false</SynchReleaseVersion>
<AssemblyVersion>$(ReleaseVersion)</AssemblyVersion>
<Description>MSBuild addon to compile and embed spirV shaders</Description>
</ItemGroup>
<Target Name="CompileShaders" BeforeTargets="BeforeBuild" Condition="'@(GLSLShader)'!=''" Outputs="@(CompiledShaders)">
<CompileGLSLTask SourceFile="%(GLSLShader.Identity)"
- AdditionalIncludeDirectories="$(SpirVAdditionalIncludeDirectories)"
+ AdditionalIncludeDirectories="%(GLSLShader.AdditionalIncludeDirectories);$(SpirVAdditionalIncludeDirectories)"
+ DefineConstants="%(GLSLShader.DefineConstants);$(DefineConstants)"
TempDirectory="$(IntermediateOutputPath)"
DestinationFile="$(IntermediateOutputPath)%(RelativeDir)%(Filename)%(Extension).spv" />
<CreateItem Condition=" '%(GLSLShader.LogicalName)'!='' "
TaskParameter="Include"
ItemName="EmbeddedResource"/>
</CreateItem>
- <Message Importance="High" Text="%(GLSLShader.Identity) -> $(AssemblyName).%(Filename)%(Extension).spv (Embedded Resource)" />
+ <Message Importance="High" Text="%(GLSLShader.Identity) -> $(AssemblyName).%(Filename)%(Extension).spv (Embedded Resource)" />
</Target>
</Project>
<FileExtension Name=".geom" ContentType="GLSLShader" />
<FileExtension Name=".frag" ContentType="GLSLShader" />
<FileExtension Name=".vert" ContentType="GLSLShader" />
+ <FileExtension Name=".tesc" ContentType="GLSLShader" />
+ <FileExtension Name=".tese" ContentType="GLSLShader" />
</ProjectSchemaDefinitions>
</ItemGroup>
<ItemGroup>
- <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />
+ <PackageReference Include="SpirVTasks" Version="0.1.15-beta" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
- <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />
+ <PackageReference Include="SpirVTasks" Version="0.1.15-beta" />
</ItemGroup>
<ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ui\**\*.*">
<LogicalName>deferred.%(Filename)%(Extension)</LogicalName>
- </EmbeddedResource>
+ </EmbeddedResource>
+ <None Include="shaders\**\*.*"/>
</ItemGroup>
</Project>
#extension GL_ARB_shading_language_420pack : enable
#define MANUAL_SRGB 0
-#define DEBUG 1
struct Material {
vec4 baseColorFactor;
float gamma;
float prefilteredCubeMipLevels;
float scaleIBLAmbient;
-#if DEBUG
+#ifdef DEBUG
float debugViewInputs;
float debugViewEquation;
#endif
color += SRGBtoLINEAR(texture(emissiveMap, inUV1)).rgb * u_EmissiveFactor;
outColor = vec4(color, baseColor.a);
-#if DEBUG
+#ifdef DEBUG
// Shader inputs debug visualization
if (ubo.debugViewInputs > 0.0) {
int index = int(ubo.debugViewInputs);
updateViewRequested = true;
}
}
- protected virtual void onMouseButtonDown (Glfw.MouseButton button) { }
- protected virtual void onMouseButtonUp (Glfw.MouseButton button) { }
+ protected virtual void onMouseButtonDown (MouseButton button) { }
+ protected virtual void onMouseButtonUp (MouseButton button) { }
protected virtual void onKeyDown (Key key, int scanCode, Modifier modifiers) {
switch (key) {
case Key.F4:
Glfw3.PollEvents ();
}
}
- public virtual void UpdateView () { }
/// <summary>
- /// custom update method called at UpdateFrequency
+ /// Suitable for updating the matrices, called at least once before the rendering loop just
+ /// after 'OnResize'. Then, triggered each time 'updateViewRequested' is true in the render loop, don't forget to
+ /// reset 'updateViewRequested' to 'false' or call the 'base.UpdateView()' which will reset this boolean.
+ /// </summary>
+ public virtual void UpdateView () {
+ updateViewRequested = false;
+ }
+ /// <summary>
+ /// custom update method called at UpdateFrequency, base method is empty.
/// </summary>
public virtual void Update () { }
/// <summary>
- /// called when swapchain has been resized, override this method to resize your framebuffers coupled to the swapchain.
- /// The base method will update Window width and height with new swapchain's dimensions.
+ /// Called when swapchain has been resized, override this method to resize your framebuffers coupled to the swapchain.
+ /// The base method will update Window 'Width' and 'Height' properties with new swapchain's dimensions.
/// </summary>
protected virtual void OnResize () {
Width = swapChain.Width;
</ItemGroup>
<ItemGroup>
- <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />
+ <PackageReference Include="SpirVTasks" Version="0.1.15-beta" />
<PackageReference Include="Vulkan" Version="0.1.7" />
</ItemGroup>
<ItemGroup>