]> O.S.I.I.S - jp/vke.net.git/commitdiff
SpirVTasks Optimisation attribute, DefineConstants attribute for passing macros to...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 7 Oct 2019 17:39:26 +0000 (19:39 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 7 Oct 2019 17:39:26 +0000 (19:39 +0200)
SpirVTasks/CompileGLSLTask.cs
SpirVTasks/SpirVTasks.csproj
SpirVTasks/SpirVTasks.targets
SpirVTasks/spirv.xml
addons/Directory.Build.props
samples/Directory.Build.props
samples/pbr/pbr.csproj
samples/pbr/shaders/pbr_khr.frag
vke/src/VkWindow.cs
vke/vke.csproj

index f66d9590238f9b8465e203525a125893b16f89d8..d978d624b8c91629bc6153a483d85f03d1fd20f4 100644 (file)
@@ -6,6 +6,7 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
+using System.Text;
 using Microsoft.Build.Framework;
 
 namespace SpirVTasks {
@@ -41,20 +42,32 @@ 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;
                }
@@ -113,7 +126,7 @@ namespace SpirVTasks {
                }
 
                /// <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)) {
@@ -177,6 +190,27 @@ namespace SpirVTasks {
 
                        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;
@@ -184,13 +218,15 @@ namespace SpirVTasks {
                        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 ();
index 171380dd8058b661c822c13f742b5c9cd7f7e40f..1727ee6ceec3bc648712f2c979544581c029428b 100644 (file)
@@ -1,7 +1,7 @@
 <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>
index 9138d21551fff5b20397700ac410f90f29367d67..6da971e98b422b82e5316abb9d98c6798d663d8b 100644 (file)
@@ -8,7 +8,8 @@
   </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)'!='' "
@@ -25,6 +26,6 @@
                                        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>
index 9635ad6731190bdd0ed9b8dc83c8de5dccd6c653..d22b7a80e2d02fe1a1bfd2e0dd8675438278f2c4 100644 (file)
@@ -6,4 +6,6 @@
   <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>
index a165eeeb1d693bf61618356c6717147cf96dc002..29b7f6f21f946af295706c8332a71b75ff05d34c 100644 (file)
@@ -34,7 +34,7 @@
        </ItemGroup>    
        
        <ItemGroup>
-               <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />         
+               <PackageReference Include="SpirVTasks" Version="0.1.15-beta" />         
        </ItemGroup>    
 
        <ItemGroup>
index cd8006047e1fb6ed76cbdfbb0651d9c941176904..f96af28181c5b685b5972dde4816b8fdcc09fbc4 100644 (file)
@@ -33,7 +33,7 @@
        </ItemGroup>
                        
        <ItemGroup>
-               <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />         
+               <PackageReference Include="SpirVTasks" Version="0.1.15-beta" />         
        </ItemGroup>    
 
        <ItemGroup>    
index 5a79334342823b00d6add3964f8063269c94c6ef..4a986e3c46e51d495b55d5e4ce2aaf89fd89d547 100644 (file)
@@ -20,7 +20,8 @@
   <ItemGroup>    
     <EmbeddedResource Include="ui\**\*.*">
       <LogicalName>deferred.%(Filename)%(Extension)</LogicalName>
-    </EmbeddedResource>                
+    </EmbeddedResource> 
+               <None Include="shaders\**\*.*"/>
   </ItemGroup>     
 
 </Project>
index 1f8e0567373225b223f00585efad7f08ddc10adb..6992f2666f2093923a822cedb1633a0b5ee6fe45 100644 (file)
@@ -7,7 +7,6 @@
 #extension GL_ARB_shading_language_420pack : enable
 
 #define MANUAL_SRGB 0
-#define DEBUG 1
 
 struct Material {
     vec4 baseColorFactor;
@@ -47,7 +46,7 @@ layout (set = 0, binding = 0) uniform UBO {
     float gamma;
     float prefilteredCubeMipLevels;
     float scaleIBLAmbient;
-#if DEBUG
+#ifdef DEBUG
     float debugViewInputs;
     float debugViewEquation;
 #endif
@@ -376,7 +375,7 @@ void main()
         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);
index f03f66b33d3db54b7ca0affce061c3e839a973fd..40aa3a8610d312d6c232c50825fc36c9875a7cbb 100644 (file)
@@ -198,8 +198,8 @@ namespace vke {
                                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:
@@ -305,15 +305,22 @@ namespace vke {
                                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;
index 538540e3f62457481ff5af1b818f2491e81f6f5e..1430087134a3745ed4c99c55ca1e83c79cd3298a 100644 (file)
@@ -48,7 +48,7 @@
        </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>