]> O.S.I.I.S - jp/vke.net.git/commitdiff
handle includes in SpirVTasks for emiting line of error
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 27 Sep 2019 01:11:40 +0000 (03:11 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 27 Sep 2019 01:11:40 +0000 (03:11 +0200)
39 files changed:
SpirVTasks/CompileGLSLTask.cs
SpirVTasks/SpirVTasks.csproj
addons/Directory.Build.props
addons/gltfLoader/PbrModel.cs
samples/Directory.Build.props
samples/compute/delaunay.cs
vke/src/Camera.cs
vke/src/FixedUtf8String.cs
vke/src/ResourceManager.cs
vke/src/SpecializationConstant.cs
vke/src/StbImage.cs
vke/src/Utils.cs
vke/src/VkWindow.cs
vke/src/base/CommandBuffer.cs
vke/src/base/CommandPool.cs
vke/src/base/ComputePipeline.cs
vke/src/base/DebuDrawPipeline.cs
vke/src/base/DebugUtilsMessenger.cs
vke/src/base/DescriptorPool.cs
vke/src/base/DescriptorSetWrites.cs
vke/src/base/Device.cs
vke/src/base/FrameBuffer.cs
vke/src/base/GPUBuffer.cs
vke/src/base/GraphicPipeline.cs
vke/src/base/GraphicPipelineConfig.cs
vke/src/base/HostBuffer.cs
vke/src/base/Image.cs
vke/src/base/Instance.cs
vke/src/base/Pipeline.cs
vke/src/base/PipelineCache.cs
vke/src/base/PipelineLayout.cs
vke/src/base/QueryPool.cs
vke/src/base/RenderPass.cs
vke/src/base/Resource.cs
vke/src/base/SubPass.cs
vke/src/base/SwapChain.cs
vke/src/model/Model.cs
vke/src/model/ObjMesh.cs [new file with mode: 0644]
vke/vke.csproj

index d6f074151d1c4aa7066268e81982e7da001a3335..f66d9590238f9b8465e203525a125893b16f89d8 100644 (file)
@@ -1,13 +1,21 @@
 // Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
 using System;
+using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
+using System.Linq;
 using Microsoft.Build.Framework;
 
 namespace SpirVTasks {
+       /// <summary>
+       /// Record include position and path in produced glsl file before compilation
+       /// </summary>
+       internal class IncludePosition {
+               public int line;                //include position in final glsl file
+               public string path;             //path to the included file
+       }
 
        public class IncludeFileNotFound : FileNotFoundException {
                public string SourceFile;
@@ -37,6 +45,9 @@ namespace SpirVTasks {
                        get;
                        set;
                }
+               /// <summary>
+               /// Optional, Specify the comple glslc executable path.
+               /// </summary>
                public ITaskItem SpirVCompilerPath {
                        get;
                        set;
@@ -49,6 +60,10 @@ namespace SpirVTasks {
                }
 
                volatile bool success;
+               //due to includes mechanic, file inclusion position has to be recorded
+               int currentCompiledLine = -1;//current line produced of the unified glsl file with all includes
+               List<IncludePosition> includesPositions = new List<IncludePosition>();  //each included file has en entry in this list
+                                                                                                                                                               //to emit correct error location for logger.
 
                bool tryFindInclude (string include, out string incFile) {
                        if (!string.IsNullOrEmpty (AdditionalIncludeDirectories?.ItemSpec)) {
@@ -61,8 +76,10 @@ namespace SpirVTasks {
                        incFile = "";
                        return false;
                }
-
-               void build_source (string src, StreamWriter temp) {
+               /// <summary>
+               /// produce a single glsl file with main glsl and all its includes in the temp directory
+               /// </summary>
+               void concatenate_sources (string src, StreamWriter temp) {
                        using (StreamReader sr = new StreamReader (File.OpenRead (src))) {
                                int srcLine = 0;
                                while (!sr.EndOfStream) {
@@ -74,14 +91,30 @@ namespace SpirVTasks {
                                                        if (!tryFindInclude(include, out incFile))
                                                                throw new IncludeFileNotFound (src, srcLine, include);
                                                }
-                                               build_source (incFile, temp);
+                                               //store position when entering an included file
+                                               includesPositions.Add(new IncludePosition {
+                                                       line = currentCompiledLine,
+                                                       path = incFile
+                                               });
+
+                                               concatenate_sources (incFile, temp);
+
+                                               //store current position when include parsing is finished
+                                               includesPositions.Add(new IncludePosition {
+                                                       line = currentCompiledLine,
+                                                       path = src
+                                               });
                                        } else
                                                temp.WriteLine (line);
+                                       currentCompiledLine++;
                                        srcLine++;
                                }
                        }
                }
 
+               /// <summary>
+               /// Use the SpirVCompilerPath element if present. if not search 'VULKAN_SDK' environment, then PATH.
+               /// </summary>
                bool tryFindGlslcExecutable (out string glslcPath) {
                        if (!string.IsNullOrEmpty (SpirVCompilerPath?.ItemSpec)) {
                                glslcPath = SpirVCompilerPath.ItemSpec;
@@ -114,6 +147,9 @@ namespace SpirVTasks {
 
                        success = true;
 
+                       includesPositions.Clear();
+                       currentCompiledLine = 0;
+
                        if (!tryFindGlslcExecutable(out string glslcPath)) {
                                BuildErrorEventArgs err = new BuildErrorEventArgs ("execute", "VK001", BuildEngine.ProjectFileOfTaskNode, 0, 0, 0, 0, $"glslc command not found: {glslcPath}", "Set 'VULKAN_SDK' environment variable", "SpirVTasks");
                                BuildEngine.LogErrorEvent (err);
@@ -127,7 +163,7 @@ namespace SpirVTasks {
                                Directory.CreateDirectory (Path.GetDirectoryName (tempFile));
                                using (StreamWriter sw = new StreamWriter (File.OpenWrite(tempFile))) {
                                        string src = SourceFile.ItemSpec;
-                                       build_source (SourceFile.ItemSpec, sw);
+                                       concatenate_sources (SourceFile.ItemSpec, sw);
                                }
                        } catch (IncludeFileNotFound ex) {
                                BuildErrorEventArgs err = new BuildErrorEventArgs ("include", "VK002", ex.SourceFile, ex.SourceLine, 0, 0, 0, $"include file not found: {ex.FileName}", "", "SpirVTasks");
@@ -180,7 +216,13 @@ namespace SpirVTasks {
 
                        if (tmp.Length == 5) {
                                string srcFile = SourceFile.ItemSpec;
-                               int line = Math.Max (0, int.Parse (tmp[1]) - 1);
+                               int line = Math.Max (0, int.Parse (tmp[1]));
+
+                               IncludePosition ip = includesPositions.LastOrDefault(p => p.line < line);
+                               if (ip != null) {
+                                       line -= ip.line;
+                                       srcFile = ip.path;
+                               }
 
                                BuildErrorEventArgs err = new BuildErrorEventArgs ("compile", tmp[2], srcFile, line, 0, 0, 0, $"{tmp[3]} {tmp[4]}", "no help", "SpirVTasks");
                                BuildEngine.LogErrorEvent (err);
index 2c6a7f5771d6fe52af35e8addf3142e77992523e..171380dd8058b661c822c13f742b5c9cd7f7e40f 100644 (file)
@@ -1,12 +1,14 @@
 <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
         <TargetFrameworks>netstandard2.0</TargetFrameworks>
-        <AssemblyVersion>0.1.10</AssemblyVersion>
+        <ReleaseVersion>0.1.11</ReleaseVersion>
+        <SynchReleaseVersion>false</SynchReleaseVersion>
+        <AssemblyVersion>$(ReleaseVersion)</AssemblyVersion>
         <Description>MSBuild addon to compile and embed spirV shaders</Description>
 
         <PackageId>SpirVTasks</PackageId>
         <PackageTags>vulkan msbuild spirv glsl addons</PackageTags>    
-        <PackageVersion>$(AssemblyVersion)-beta</PackageVersion>
+        <PackageVersion>$(ReleaseVersion)-beta</PackageVersion>
         <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
         <PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
         <PackageProjectUrl>https://github.com/jpbruyere/vk.net/blob/master/SpirVTasks/README.md</PackageProjectUrl>
index 20d44d44f82fba74e09a6be696ab7726312b09fa..c86d07ccb44dd58b058489824eca1948d19ea76c 100644 (file)
@@ -29,8 +29,7 @@
        <ItemGroup>
                                <!--<PackageReference Include="vke" Version="0.1.8-beta" />-->
     <ProjectReference Include="..\..\vke\vke.csproj" />
-               <PackageReference Include="SpirVTasks" Version="0.1.10-beta" />        
-               <!--<PackageReference Include="Vulkan" Version="0.1.4" />-->
+               <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />         
        </ItemGroup>    
 
        <ItemGroup>
index 7fe2d84f1d692f6e1c439b2443854a81b0034946..d5e04a8cc1bbdbfeaa135293c3baf4a5409cf0ba 100644 (file)
@@ -10,21 +10,7 @@ using System.Collections.Generic;
 
 namespace vke.glTF {
        //TODO:stride in buffer views?
-       public abstract class PbrModel : Model {        
-               //public new struct Vertex {
-               //      [VertexAttribute (VertexAttributeType.Position, VkFormat.R32g32b32Sfloat)]
-               //      public Vector3 pos;
-               //      [VertexAttribute (VertexAttributeType.Normal, VkFormat.R32g32b32Sfloat)]
-               //      public Vector3 normal;
-               //      [VertexAttribute (VertexAttributeType.UVs, VkFormat.R32g32Sfloat)]
-               //      public Vector2 uv0;
-               //      [VertexAttribute (VertexAttributeType.UVs, VkFormat.R32g32Sfloat)]
-               //      public Vector2 uv1;
-               //      public override string ToString () {
-               //              return pos.ToString () + ";" + normal.ToString () + ";" + uv0.ToString () + ";" + uv1.ToString ();
-               //      }
-               //};
-
+       public abstract class PbrModel : Model {
                protected DescriptorPool descriptorPool;
                public GPUBuffer vbo;
                public GPUBuffer ibo;
index 31d7523af807f70fa5a61d6f67a469db81f911ef..3648b3c401f0ca038615a1ebd840be428c0e3888 100644 (file)
@@ -28,7 +28,7 @@
        <ItemGroup>
                <!--<PackageReference Include="vke" Version="0.1.8-beta" />-->
     <ProjectReference Include="..\..\vke\vke.csproj" />
-               <PackageReference Include="SpirVTasks" Version="0.1.10-beta" />     
+               <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />
                <!--<PackageReference Include="Vulkan" Version="0.1.4" />        -->
        </ItemGroup>    
 
index 88673020758193824b631e56696c3678d6c15238..7b90ca81801d9c8c4c80230766254c993b594200 100644 (file)
@@ -8,7 +8,6 @@ namespace delaunay {
                static void Main (string[] args) {
 #if DEBUG
                        Instance.VALIDATION = true;
-                       Instance.DEBUG_UTILS = true;
                        Instance.RENDER_DOC_CAPTURE = false;
 #endif
                        using (Program vke = new Program ()) {
@@ -54,14 +53,6 @@ namespace delaunay {
 
 
                public Program () : base () {
-                       if (Instance.DEBUG_UTILS)
-                               dbgReport = new DebugReport (instance,
-                                       VkDebugReportFlagsEXT.ErrorEXT
-                                       | VkDebugReportFlagsEXT.DebugEXT
-                                       | VkDebugReportFlagsEXT.WarningEXT
-                                       | VkDebugReportFlagsEXT.PerformanceWarningEXT
-                               
-                               );
                        imgResult = new Image (dev, VkFormat.R32g32b32a32Sfloat, VkImageUsageFlags.TransferDst | VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal,
                                imgDim, imgDim);
                        imgResult.CreateView ();
index ac6aa2917b5839695eadd2e1bc58ea2417928dea..c897cf2b68f1041ada53ca83cde216eddce745de 100644 (file)
@@ -59,7 +59,7 @@ namespace vke {
                public void Rotate (float x, float y, float z = 0) {
                        rotation.Y += rotSpeed * x;
                        rotation.X += rotSpeed * y;
-                       //Update ();
+                       Update ();
                }
                public float Zoom {
                        get { return zoom; }
index e8d9bb7de1cfc9e03f578a871396d160ae17e5a1..bdf657450ff4991937793d04c49db902966b1ab6 100644 (file)
@@ -1,4 +1,7 @@
-using System;
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
 using System.Runtime.InteropServices;
 using System.Text;
 
index c8b2028b3e7f67f27026d3e6453dbca1a680d957..5f059b2bc0026ba550bb91aee46063339ea95319 100644 (file)
@@ -1,4 +1,7 @@
-using System;
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
 using Vulkan;
 
 namespace vke {
index aca290fb3cfc5ffc1ac0645e9ca622c75ff530cb..b434bcb76b3f8ad51eedaa1a1898ff1350c65f1e 100644 (file)
@@ -1,28 +1,6 @@
-//
-// SpecializationConstant.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
index 208b4a5994acf27e14d2c103100def9c666200a4..1ae1e423dea1b025f2e3692d820fd5a24036f6f0 100644 (file)
@@ -1,7 +1,6 @@
 // Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
 using System;
 using System.Runtime.InteropServices;
 
index 3cbd0395de51bb3909aac5858debfe73e2d54023..3a8d34e92aa19f264488a735eb9eb0fe7f263e71 100644 (file)
@@ -2,7 +2,10 @@
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
+using System.IO;
+using System.Linq;
 using System.Numerics;
+using System.Reflection;
 
 namespace Vulkan {
        public static partial class Utils {
@@ -12,6 +15,35 @@ namespace Vulkan {
             if (result != VkResult.Success)
                 throw new InvalidOperationException (errorString + ": " + result.ToString ());
         }
+               /// <summary>
+               /// Return a file or embedded resource stream.
+               /// </summary>
+               /// <returns>The stream from path.</returns>
+               /// <param name="path">The file or stream path. Embedded resource path starts with '#'.</param>
+               public static Stream GetStreamFromPath (string path) {
+                       Stream stream = null;
+
+                       if (path.StartsWith ("#", StringComparison.Ordinal)) {
+                               string resId = path.Substring (1);
+                               //first search entry assembly
+                               stream = Assembly.GetEntryAssembly ().GetManifestResourceStream (resId);
+                               if (stream != null)
+                                       return stream;
+                               //if not found, search assembly named with the 1st element of the resId
+                               string assemblyName = resId.Split ('.')[0];
+                               Assembly a = AppDomain.CurrentDomain.GetAssemblies ().FirstOrDefault (aa => aa.GetName ().Name == assemblyName);
+                               if (a == null)
+                                       throw new Exception ($"Assembly '{assemblyName}' not found for ressource '{path}'.");
+                               stream = a.GetManifestResourceStream (resId);
+                               if (stream == null)
+                                       throw new Exception ("Resource not found: " + path);
+                       } else {
+                               if (!File.Exists (path))
+                                       throw new FileNotFoundException ("File not found: ", path);
+                               stream = new FileStream (path, FileMode.Open, FileAccess.Read);
+                       }
+                       return stream;
+               }
                /// <summary>Convert angle from degree to radian.</summary>
                public static float DegreesToRadians (float degrees) {
             return degrees * (float)Math.PI / 180f;
index fc40cb477cecc76c4785065bdf5c9d8e44fdb3da..5a8b76171e57e172111075c91573160206fa3520 100644 (file)
@@ -185,13 +185,14 @@ namespace vke {
                protected virtual void onMouseMove (double xPos, double yPos) {
                        double diffX = lastMouseX - xPos;
                        double diffY = lastMouseY - yPos;
-                       if (MouseButton[0]) {
+                       if (MouseButton[(int)Glfw.MouseButton.Left]) {
                                camera.Rotate ((float)-diffX, (float)-diffY);
-                       } else if (MouseButton[1]) {
-                               camera.Move (0, 0, (float)diffY);
+                               updateViewRequested = true;
+                       } else if (MouseButton[(int)Glfw.MouseButton.Right]) {
+                               camera.Move ((float)diffX,0,0);
+                               camera.Move (0, 0, (float)-diffY);
+                               updateViewRequested = true;
                        }
-
-                       updateViewRequested = true;
                }
                protected virtual void onMouseButtonDown (Glfw.MouseButton button) { }
                protected virtual void onMouseButtonUp (Glfw.MouseButton button) { }
index 83e2f9bd1e22625adf034efdfa8ae950a8985baa..3066f812792f8962ec801253d28723660947f12f 100644 (file)
@@ -1,7 +1,6 @@
 // Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
 using System;
 using System.Runtime.InteropServices;
 using Vulkan;
index d31605a0666ed39c1ff981043ca22458af66294c..01888e6a1fd8eb4f12104e0a54eafe3bdd709030 100644 (file)
@@ -1,7 +1,6 @@
 // Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
 using System;
 using System.Runtime.InteropServices;
 using Vulkan;
index 3aeca895aace7a2c0114adad2b820b20af4d8fae..876aee666ccac2496b74b8491a78635d4c1e8415 100644 (file)
@@ -1,28 +1,7 @@
 //
-// ComputePipeline.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using Vulkan;
 using static Vulkan.Vk;
index 60eda5bbacf7734eac23b3f251fbaec38b512543..3ebc71a6f15081d792db989f355bdcb694777bb3 100644 (file)
@@ -1,4 +1,7 @@
-using System;
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
 using System.Numerics;
 using System.Runtime.InteropServices;
 using Vulkan;
index 419e14056f0f260a7f7d4739fd1adfbcdc1a72ad..eb042d1acaa0fd458957dd6d13e13b4421769cd5 100644 (file)
@@ -1,4 +1,7 @@
-using System;
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
 using System.Runtime.InteropServices;
 using Vulkan;
 using static Vulkan.Vk;
index ad8dba769c07380500637740da00c911e6bc0049..38fba546f51ce21b3c619fab4ece2f9b5fdd01c6 100644 (file)
@@ -1,7 +1,6 @@
 // Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
 using System;
 using System.Collections.Generic;
 using Vulkan;
index 227ea0d6b58cdedb751f008e355e318b683ab4a1..058dfc7ce1c3b1ad3a86b5d8e6b19ecb7f6c371c 100644 (file)
@@ -1,28 +1,7 @@
 //
-// DescriptorSetWrites.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
index a9256250313c0239fee17968482407c6044bfb50..2e287e4c5a1f3beae5fa5fa43d3c075dac08bffe 100644 (file)
@@ -228,7 +228,7 @@ namespace vke {
 
         public VkShaderModule LoadSPIRVShader (string filename) {
                        VkShaderModule shaderModule;
-                       using (Stream stream = StaticGetStreamFromPath (filename)) {
+                       using (Stream stream = Utils.GetStreamFromPath (filename)) {
                                using (BinaryReader br = new BinaryReader (stream)) {
                                        byte[] shaderCode = br.ReadBytes ((int)stream.Length);
                                        ulong shaderSize = (ulong)shaderCode.Length;
@@ -246,32 +246,7 @@ namespace vke {
                        }
                        return shaderModule;            
 
-        }
-
-               public static Stream StaticGetStreamFromPath (string path) {
-                       Stream stream = null;
-
-                       if (path.StartsWith ("#", StringComparison.Ordinal)) {
-                               string resId = path.Substring (1);
-                               //first search entry assembly
-                               stream = Assembly.GetEntryAssembly ().GetManifestResourceStream (resId);
-                               if (stream != null)
-                                       return stream;
-                               //if not found, search assembly named with the 1st element of the resId
-                               string assemblyName = resId.Split ('.')[0];
-                               Assembly a = AppDomain.CurrentDomain.GetAssemblies ().FirstOrDefault (aa => aa.GetName ().Name == assemblyName);
-                               if (a == null)
-                                       throw new Exception ($"Assembly '{assemblyName}' not found for ressource '{path}'.");
-                               stream = a.GetManifestResourceStream (resId);
-                               if (stream == null)
-                                       throw new Exception ("Resource not found: " + path);
-                       } else {
-                               if (!File.Exists (path))
-                                       throw new FileNotFoundException ("File not found: ", path);
-                               stream = new FileStream (path, FileMode.Open, FileAccess.Read);
-                       }
-                       return stream;
-               }
+        }        
 
 #region IDisposable Support
                private bool disposedValue = false; // Pour détecter les appels redondants
index 3260e1504e7a5c72aab4c69c65c8efaadeed2b05..7ba3d004b8a6d09151f64f7ec829580b249caaa6 100644 (file)
@@ -1,28 +1,6 @@
-//
-// FrameBuffer.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using System.Linq;
index bebc21b823c4fe950566b931677755dd67813acc..50280bad5f22e37f19b022beb4a346885f39fa71 100644 (file)
@@ -1,28 +1,6 @@
-//
-// GPUBuffer.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Runtime.InteropServices;
 using Vulkan;
index 7f94316219be56cb1c952b2fb9901cd276eb7105..1c0c877e6c5e30818fef2f85b2c0aa1ec521b8b4 100644 (file)
@@ -1,28 +1,6 @@
-//
-// FrameBuffer.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using Vulkan;
index 848a378d86d3fb123ecb531d8750d1358a830f8a..f1e38751ebba1ab76cb38913e1c18dbdaac9791e 100644 (file)
@@ -1,28 +1,6 @@
-//
-// PipelineConfig.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using System.Numerics;
@@ -32,22 +10,22 @@ using Vulkan;
 using static Vulkan.Vk;
 
 namespace vke {
-    public class GraphicPipelineConfig {
+       public class GraphicPipelineConfig {
                public uint SubpassIndex;
-        public PipelineLayout Layout;
+               public PipelineLayout Layout;
                public RenderPass RenderPass;
                public PipelineCache Cache;
                public VkPipelineBindPoint bindPoint = VkPipelineBindPoint.Graphics;
-        public VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = VkPipelineInputAssemblyStateCreateInfo.New();
-        public VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo.New();
-        public VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.New();
-        public VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo.New();
-        public VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo.New();
-        public List<VkPipelineColorBlendAttachmentState> blendAttachments = new List<VkPipelineColorBlendAttachmentState>();
-        public List<VkDynamicState> dynamicStates = new List<VkDynamicState> ();
-        public List<VkVertexInputBindingDescription> vertexBindings = new List<VkVertexInputBindingDescription> ();
-        public List<VkVertexInputAttributeDescription> vertexAttributes = new List<VkVertexInputAttributeDescription> ();
-        public readonly List<ShaderInfo> shaders = new List<ShaderInfo>();
+               public VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = VkPipelineInputAssemblyStateCreateInfo.New ();
+               public VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo.New ();
+               public VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.New ();
+               public VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo.New ();
+               public VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo.New ();
+               public List<VkPipelineColorBlendAttachmentState> blendAttachments = new List<VkPipelineColorBlendAttachmentState> ();
+               public List<VkDynamicState> dynamicStates = new List<VkDynamicState> ();
+               public List<VkVertexInputBindingDescription> vertexBindings = new List<VkVertexInputBindingDescription> ();
+               public List<VkVertexInputAttributeDescription> vertexAttributes = new List<VkVertexInputAttributeDescription> ();
+               public readonly List<ShaderInfo> shaders = new List<ShaderInfo> ();
                public VkBool32 ColorBlendLogicOpEnable = false;
                public VkLogicOp ColorBlendLogicOp;
                public Vector4 ColorBlendConstants;
@@ -65,28 +43,27 @@ namespace vke {
                /// added automatically with blending disabled. (cfg.blendAttachments[0])
                /// </summary>
                public static GraphicPipelineConfig CreateDefault (VkPrimitiveTopology topology = VkPrimitiveTopology.TriangleList,
-                       VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1, bool depthTestEnabled = true)
-               {
+                       VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1, bool depthTestEnabled = true) {
                        GraphicPipelineConfig cfg = new GraphicPipelineConfig ();
 
                        cfg.inputAssemblyState.topology = topology;
-            cfg.multisampleState.rasterizationSamples = samples;
+                       cfg.multisampleState.rasterizationSamples = samples;
 
-            cfg.rasterizationState.polygonMode = VkPolygonMode.Fill;
-            cfg.rasterizationState.cullMode = (uint)VkCullModeFlags.None;
-            cfg.rasterizationState.frontFace = VkFrontFace.CounterClockwise;
-            cfg.rasterizationState.depthClampEnable = False;
-            cfg.rasterizationState.rasterizerDiscardEnable = False;
-            cfg.rasterizationState.depthBiasEnable = False;
-            cfg.rasterizationState.lineWidth = 1.0f;
+                       cfg.rasterizationState.polygonMode = VkPolygonMode.Fill;
+                       cfg.rasterizationState.cullMode = (uint)VkCullModeFlags.None;
+                       cfg.rasterizationState.frontFace = VkFrontFace.CounterClockwise;
+                       cfg.rasterizationState.depthClampEnable = False;
+                       cfg.rasterizationState.rasterizerDiscardEnable = False;
+                       cfg.rasterizationState.depthBiasEnable = False;
+                       cfg.rasterizationState.lineWidth = 1.0f;
 
-            cfg.viewportState.viewportCount = 1;
-            cfg.viewportState.scissorCount = 1;
+                       cfg.viewportState.viewportCount = 1;
+                       cfg.viewportState.scissorCount = 1;
 
-            cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
+                       cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
 
-            cfg.dynamicStates.Add (VkDynamicState.Viewport);
-            cfg.dynamicStates.Add (VkDynamicState.Scissor);
+                       cfg.dynamicStates.Add (VkDynamicState.Viewport);
+                       cfg.dynamicStates.Add (VkDynamicState.Scissor);
 
                        if (depthTestEnabled) {
                                cfg.depthStencilState.depthTestEnable = True;
@@ -103,21 +80,21 @@ namespace vke {
                        return cfg;
                }
 
-        uint currentAttributeIndex = 0;
-        public void AddVertexAttributes (uint binding, params VkFormat[] attribsDesc) {
-            uint currentAttributeoffset = 0;
-            for (uint i = 0; i < attribsDesc.Length; i++) {
+               uint currentAttributeIndex = 0;
+               public void AddVertexAttributes (uint binding, params VkFormat[] attribsDesc) {
+                       uint currentAttributeoffset = 0;
+                       for (uint i = 0; i < attribsDesc.Length; i++) {
                                vertexAttributes.Add (new VkVertexInputAttributeDescription (binding, i + currentAttributeIndex, attribsDesc[i], currentAttributeoffset));
                                VkFormatSize fs;
                                Utils.vkGetFormatSize (attribsDesc[i], out fs);
-                               currentAttributeoffset += fs.blockSizeInBits/8;
+                               currentAttributeoffset += fs.blockSizeInBits / 8;
                        }
-            currentAttributeIndex += (uint)attribsDesc.Length;
+                       currentAttributeIndex += (uint)attribsDesc.Length;
                }
-               public void AddVertexBinding (uint binding, uint stride, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) { 
+               public void AddVertexBinding (uint binding, uint stride, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) {
                        vertexBindings.Add (new VkVertexInputBindingDescription (binding, stride, inputRate));
                }
-               public void AddVertexBinding<T> (uint binding = 0, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) { 
+               public void AddVertexBinding<T> (uint binding = 0, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) {
                        vertexBindings.Add (new VkVertexInputBindingDescription (binding, (uint)Marshal.SizeOf<T> (), inputRate));
                }
                /// <summary>
@@ -127,7 +104,7 @@ namespace vke {
                        vertexBindings.Add (new VkVertexInputBindingDescription (binding, (uint)Marshal.SizeOf<T> (), inputRate));
                        FieldInfo[] fields = typeof (T).GetFields ();
                        VkFormat[] attribs = new VkFormat[fields.Length];
-                       for (int i = 0; i < fields.Length; i++) 
+                       for (int i = 0; i < fields.Length; i++)
                                attribs[i] = fields[i].GetCustomAttribute<VertexAttributeAttribute> ().Format;
                        AddVertexAttributes (binding, attribs);
                }
@@ -136,11 +113,14 @@ namespace vke {
                }
 
                public void ResetShadersAndVerticesInfos () {
-                       foreach (ShaderInfo shader in shaders) 
-                               shader.Dispose ();
-            currentAttributeIndex = 0;
-            vertexBindings.Clear ();
+                       currentAttributeIndex = 0;
+                       vertexBindings.Clear ();
                        vertexAttributes.Clear ();
+                       ResetShaders ();
+               }
+               public void ResetShaders () {
+                       foreach (ShaderInfo shader in shaders)
+                               shader.Dispose ();
                        shaders.Clear ();
                }
        }
index 65dc53eb56238420deed15725f8780dd5c0f8376..2ce0094d9c52af60eeb42f10364ee326cca1195b 100644 (file)
@@ -1,28 +1,6 @@
-//
-// HostBuffer.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
index 5238fa7dff957e7095afe3a01c23f4a59959193d..c84fadb61e0f1ea643d965170f33ce42ed0d4519 100644 (file)
@@ -1,28 +1,6 @@
-//
-// Buffer.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Diagnostics;
 using Vulkan;
index 71e9c9d417c8c58377d2cbd1831c73e1dd72ffa8..dbc9673af7f539fc971fd3f46bb9819679d5acef 100644 (file)
@@ -1,28 +1,6 @@
-//
-// Instance.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using System.Linq;
index 19c62dee072a44d05d7b18e22fb63c438125685a..329e555ec9584d010b8332feb84aa5680ab774a0 100644 (file)
@@ -1,28 +1,6 @@
-//
-// Pipeline.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using Vulkan;
 using static Vulkan.Vk;
index 0129cacb34925e9e4058771350ce1db874cbc33d..f38764dd5dcd60b4556c03cb34de722b76dd23bc 100644 (file)
@@ -1,28 +1,6 @@
-//
-// SpecializationConstant.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using System.IO;
index ba5c257c52ceba2c243805220577a2409676964d..2f932e7f84f6aa3330d5aa6efd668f706f633962 100644 (file)
@@ -1,28 +1,6 @@
-//
-// PipelineLayout.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using System.Linq;
index 6dfad4417bf5fe94b92cc88bf79f46a7b1369848..7a5edd35b182b27493f9fde183f278ff62d7f2a0 100644 (file)
@@ -1,28 +1,6 @@
-//
-// CommandPool.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using Vulkan;
index f93ddcdca7217fdfaebc5eab9c0f85fed340f9fb..95c0baf13afd86a2358729d89dd4f04adbaffdb9 100644 (file)
@@ -1,28 +1,6 @@
-//
-// RenderPass.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using System.Collections.Generic;
 using System.Linq;
index 1b559edbe55fd60357bd6dba987aab78a7dc4d5a..e489e350c58e0f7bcc9156ed1cae1ef05264973c 100644 (file)
@@ -1,4 +1,7 @@
-using System;
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
 using System.Diagnostics;
 using System.IO;
 using System.Runtime.InteropServices;
index ca914244755ffa24c9c914206dbbc4537105a674..9a7fbb6e7a1f608540ac2891971ff62f98bd496b 100644 (file)
@@ -1,28 +1,6 @@
-//
-// SubPass.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System.Collections.Generic;
 using Vulkan;
 
index d49dd547b60ed613178b83dc07bc62010d29b1a7..c752696614a11a112a8bcd47492a3870a9e0533d 100644 (file)
@@ -1,28 +1,7 @@
 //
-// SwapChain.cs
+// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2019 jp
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using System;
 using Vulkan;
 using static Vulkan.Vk;
index 52fbbe9f9449cdb57cff2a2360b837c3744c6fbe..c66601bf3456e9494bfd51b34c64570a8ed881ce 100644 (file)
@@ -70,12 +70,24 @@ namespace vke {
         
         public class Primitive {
                        public string name;
-                       public UInt32 indexBase;
-                       public Int32 vertexBase;
-                       public UInt32 vertexCount;
-                       public UInt32 indexCount;
-                       public UInt32 material;
+                       public uint indexBase;
+                       public int vertexBase;
+                       public uint vertexCount;
+                       public uint indexCount;
+                       public uint material;
                        public BoundingBox bb;
+
+                       public Primitive () { }
+                       public Primitive (uint vertexCount, uint indexCount, int vertexBase = 0, uint indexBase = 0) {
+                               this.vertexCount = vertexCount;
+                               this.indexCount = indexCount;
+                               this.vertexBase = vertexBase;
+                               this.indexBase = indexBase;
+                       }
+
+                       public void Draw (CommandBuffer cmd, uint instanceCount = 1, uint firstInstance = 0) {
+                               cmd.DrawIndexed (indexCount, instanceCount, indexBase, vertexBase, firstInstance);
+                       }
                }
 
                public class Mesh {
diff --git a/vke/src/model/ObjMesh.cs b/vke/src/model/ObjMesh.cs
new file mode 100644 (file)
index 0000000..c2944c3
--- /dev/null
@@ -0,0 +1,162 @@
+//
+//  Mesh.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2015 jp
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using System.Collections.Generic;
+using System.IO;
+using System.Numerics;
+using System.Threading;
+
+namespace vke
+{
+       public class ObjMesh {
+               public Model.Vertex[] vertices;
+               public ushort[] indices;
+
+               public ObjMesh(string path) {
+                       OBJMeshLoader<ushort> loader = new OBJMeshLoader<ushort> (path);
+                       vertices = new Model.Vertex[loader.VertexCount];
+                       for (int i = 0; i < loader.VertexCount; i++) {
+                               vertices[i] = new Model.Vertex {
+                                       pos = loader.lPositions[i],
+                                       normal = loader.lNormals[i],
+                                       uv = loader.lTexCoords[i]
+                               };
+                       }
+                       indices = loader.lIndices.ToArray ();
+               }
+
+               #region .OBJ Loading
+               class OBJMeshLoader<TIdx> {
+                       public int VertexCount => objPositions.Count;
+
+                       public List<Vector3> objPositions = new List<Vector3> ();
+                       public List<Vector3> objNormals = new List<Vector3> ();
+                       public List<Vector2> objTexCoords = new List<Vector2> ();
+                       public List<Vector3> lPositions = new List<Vector3> ();
+                       public List<Vector3> lNormals = new List<Vector3> ();
+                       public List<Vector2> lTexCoords = new List<Vector2> ();
+                       public List<TIdx> lIndices = new List<TIdx> ();
+
+                       public OBJMeshLoader (string fileName) {
+                               string name = "unamed";
+                               using (Stream stream = new FileStream (fileName, FileMode.Open, FileAccess.Read)) {
+                                       using (StreamReader Reader = new StreamReader (stream)) {
+                                               System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture;
+                                               Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
+
+                                               string line;
+                                               while ((line = Reader.ReadLine ()) != null) {
+                                                       line = line.Trim (' ');
+                                                       line = line.Replace ("  ", " ");
+
+                                                       string[] parameters = line.Split (' ');
+
+                                                       switch (parameters[0]) {
+                                                       case "o":
+                                                               name = parameters[1];
+                                                               break;
+                                                       case "p": // Point
+                                                               break;
+                                                       case "v": // Vertex
+                                                               float x = float.Parse (parameters[1]);
+                                                               float y = float.Parse (parameters[2]);
+                                                               float z = float.Parse (parameters[3]);
+
+                                                               objPositions.Add (new Vector3 (x, y, z));
+                                                               break;
+                                                       case "vt": // TexCoord
+                                                               float u = float.Parse (parameters[1]);
+                                                               float v = float.Parse (parameters[2]);
+                                                               objTexCoords.Add (new Vector2 (u, v));
+                                                               break;
+
+                                                       case "vn": // Normal
+                                                               float nx = float.Parse (parameters[1]);
+                                                               float ny = float.Parse (parameters[2]);
+                                                               float nz = float.Parse (parameters[3]);
+                                                               objNormals.Add (new Vector3 (nx, ny, nz));
+                                                               break;
+
+                                                       case "f":
+                                                               switch (parameters.Length) {
+                                                               case 4:
+
+                                                                       lIndices.Add (ParseFaceParameter (parameters[1]));
+                                                                       lIndices.Add (ParseFaceParameter (parameters[2]));
+                                                                       lIndices.Add (ParseFaceParameter (parameters[3]));
+                                                                       break;
+
+                                                               case 5:
+                                                                       lIndices.Add (ParseFaceParameter (parameters[1]));
+                                                                       lIndices.Add (ParseFaceParameter (parameters[2]));
+                                                                       lIndices.Add (ParseFaceParameter (parameters[3]));
+                                                                       lIndices.Add (ParseFaceParameter (parameters[4]));
+                                                                       break;
+                                                               }
+                                                               break;
+                                                       }
+                                               }
+                                               Thread.CurrentThread.CurrentCulture = savedCulture;
+                                       }
+                               }
+                       }
+
+                       TIdx ParseFaceParameter (string faceParameter) {
+                               Vector3 vertex = new Vector3 ();
+                               Vector2 texCoord = new Vector2 ();
+                               Vector3 normal = new Vector3 ();
+
+                               string[] parameters = faceParameter.Split ('/');
+
+                               int vertexIndex = int.Parse (parameters[0]);
+                               if (vertexIndex < 0) vertexIndex = objPositions.Count + vertexIndex;
+                               else vertexIndex = vertexIndex - 1;
+                               vertex = objPositions[vertexIndex];
+
+                               if (parameters.Length > 1) {
+                                       int texCoordIndex;
+                                       if (int.TryParse (parameters[1], out texCoordIndex)) {
+                                               if (texCoordIndex < 0) texCoordIndex = objTexCoords.Count + texCoordIndex;
+                                               else texCoordIndex = texCoordIndex - 1;
+                                               texCoord = objTexCoords[texCoordIndex];
+                                       }
+                               }
+
+                               if (parameters.Length > 2) {
+                                       int normalIndex;
+                                       if (int.TryParse (parameters[2], out normalIndex)) {
+                                               if (normalIndex < 0) normalIndex = objNormals.Count + normalIndex;
+                                               else normalIndex = normalIndex - 1;
+                                               normal = objNormals[normalIndex];
+                                       }
+                               }
+
+                               lPositions.Add (vertex);
+                               lTexCoords.Add (texCoord);
+                               lNormals.Add (normal);
+
+                               TIdx index = (TIdx)(object)(lPositions.Count - 1);
+                               return index;
+                       }
+               }
+               #endregion
+       }
+}
+
index 7e4158a4c96c293b35b07f3fc5f18eefb0121ab0..538540e3f62457481ff5af1b818f2491e81f6f5e 100644 (file)
@@ -48,7 +48,7 @@
        </ItemGroup>
                
        <ItemGroup>
-               <PackageReference Include="SpirVTasks" Version="0.1.10-beta" />
+               <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />
                <PackageReference Include="Vulkan" Version="0.1.7" />
        </ItemGroup>
        <ItemGroup>