From cfbf92373ac8ad1e3e44bd8163dea809f38da36e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Thu, 4 Nov 2021 09:52:14 +0100 Subject: [PATCH] netcoreapp3.0 support, update docs --- .vscode/launch.json | 11 ++++ .vscode/tasks.json | 14 +++++ README.md | 40 ++++---------- addons/Directory.Build.props | 2 +- samples/ClearScreen/README.md | 30 +++++------ samples/Triangle/README.md | 84 ++++++++++++++++++++++++++---- samples/Triangle/shaders/main.frag | 4 +- samples/Triangle/shaders/main.vert | 8 +-- samples/common/SampleBase.cs | 18 ------- vke/src/VkWindow.cs | 1 - vke/vke.csproj | 4 +- 11 files changed, 131 insertions(+), 85 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a933a89..ec51fd3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -59,6 +59,17 @@ "stopAtEntry": false, "console": "internalConsole" }, + { + "name": ".NET Core Launch (DistanceFieldFontTest)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build DistanceFieldFontTest", + "program": "${workspaceFolder}/build/Debug/netcoreapp3.1/DistanceFieldFontTest", + "args": [], + "cwd": "${workspaceFolder}/build/Debug/netcoreapp3.1/", + "console": "internalConsole", + "stopAtEntry": false + }, { "name": ".NET Core Launch (ImmutableSampler)", "type": "coreclr", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 8aa8d5a..95eda6a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -71,6 +71,20 @@ ], "problemMatcher": "$msCompile" }, + { + "label": "build DistanceFieldFontTest", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/samples/DistanceFieldFontTest/DistanceFieldFontTest.csproj", + "/property:GenerateFullPaths=true", + "/property:SolutionDir=${workspaceFolder}/", + "/property:Configuration=Debug", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, { "label": "build immutableSampler", "command": "dotnet", diff --git a/README.md b/README.md index 986c081..8808a45 100644 --- a/README.md +++ b/README.md @@ -24,47 +24,27 @@
adaptation of the gltf PBR sample from Sacha Willems

-### Presentation -**vke.net** (_vulkan engine for .net_) is a vulkan abstraction layer writen in **c#** composed of high level classes encapsulating [vulkan](https://www.khronos.org/vulkan/) objects and commands with `IDispose` model and **reference counting**. [GLFW](https://www.glfw.org/) handles the default windowing system. +# Presentation +`vke.net` (_vulkan engine for .net_) is a vulkan abstraction layer writen in **c#** composed of high level classes encapsulating [vulkan](https://www.khronos.org/vulkan/) objects and commands with `IDispose` model and **reference counting**. -vke aims to provide a simple api for all common vulkan tasks, ideal to quickly prototype vulkan applications, but fits also the needs to build complete application or game. +`vke.net` use autogenerated [vk.net](https://github.com/jpbruyere/vk.net) library for low level binding to vulkan and [GLFW](https://www.glfw.org/) handles the default windowing system. -To see **vke.net** in action check [vkChess.net](https://github.com/jpbruyere/vkChess.net). +`vke.net` aims to provide a simple api for all common vulkan tasks, ideal to quickly prototype vulkan applications, but fits also the needs to build complete application or game. -Vke use autogenerated [vk.net](https://github.com/jpbruyere/vk.net) library for low level binding to vulkan. +To see `vke.net` in action check [vkChess.net](https://github.com/jpbruyere/vkChess.net), and to start a vulkan application with an integrated [GUI](https://github.com/jpbruyere/Crow), start with [VkCrowWindow](https://github.com/jpbruyere/VkCrowWindow). Use the `download_datas.sh` script for downloading sample's datas. -vke is in early development stage. +vke is in beta development stage. -### Requirements +# Requirements - [GLFW](https://www.glfw.org/) if you use the `VkWindow` class. - [Vulkan Sdk](https://www.lunarg.com/vulkan-sdk/), **glslc** has to be in the path. -- optionaly for ui, you will need [vkvg](https://github.com/jpbruyere/vkvg). -### Quick Start +`vke.net` supports `netcoreapp3.0`. -Create a new dotnet console project, and add the [vke nuget package](https://www.nuget.org/packages/vke) to it. -```xml - - net472 - Exe - - - - - -``` -For automatic shader compilation to SpirV, add also the [SpirVTasks](SpirVTasks/README.md) nuget package. - -```xml - - - - -``` -### Samples +# Tutorials | Title | Screen shots | | :------------------------------------------: | :------------------------------------------------: | @@ -73,7 +53,7 @@ For automatic shader compilation to SpirV, add also the [SpirVTasks](SpirVTasks/ | [Textured](samples/Textured/README.md) | ![screenshot](samples/screenShots/Textured.png) | -### Features +# Features - physicaly based rendering, direct and deferred - glTF 2.0 diff --git a/addons/Directory.Build.props b/addons/Directory.Build.props index b0ee5f7..db6cad1 100644 --- a/addons/Directory.Build.props +++ b/addons/Directory.Build.props @@ -4,7 +4,7 @@ $(MSBuildThisFileDirectory)../ true - netstandard2.0 + netcoreapp3.0 https://github.com/jpbruyere/vke.net MIT diff --git a/samples/ClearScreen/README.md b/samples/ClearScreen/README.md index b9f623f..3eeab4d 100644 --- a/samples/ClearScreen/README.md +++ b/samples/ClearScreen/README.md @@ -1,34 +1,30 @@ -### The Project File. - -To build a minimal vulkan application, add the [vke](https://www.nuget.org/packages/vke/) nuget package, and to enable automatic shader compilation, add the [SpirVTasks](https://www.nuget.org/packages/SpirVTasks/) package and a generic **GLSLShader** item globing a full directory. +# The Project File. +Create a new dotnet console project, and add the [vke nuget package](https://www.nuget.org/packages/vke) to it. ```xml - - net472 - Exe - - - - + netcoreapp3.1 + Exe + - ``` - -### VkWindow class +# VkWindow class **vke** use [GLFW](https://www.glfw.org/) to interface with the windowing system of the OS. Derive your application from the `VkWindow` base class to start with a vulkan enabled window. **Validation** and **RenderDoc** layers loading may be control at startup with public static boolean properties from the `Instance`class. ```csharp class Program : VkWindow { - static void Main (string[] args) { - using (Program vke = new Program ()) { - vke.Run (); - } + static void Main (string[] args) { + + Instance.Validation = true; + + using (Program vke = new Program ()) { + vke.Run (); } + } } ``` diff --git a/samples/Triangle/README.md b/samples/Triangle/README.md index d9343df..d2bc07c 100644 --- a/samples/Triangle/README.md +++ b/samples/Triangle/README.md @@ -1,4 +1,20 @@ -### Creating buffers +# shaders +For this tutorials we'll need a `vertex` and a `fragment` shaders. Vulkan need them to be compiled into [SPIR-V](https://www.khronos.org/spir/). Install the [Vulkan Sdk](https://www.lunarg.com/vulkan-sdk/) and after building it, ensure the `VULKAN_SDK` environment variable points to its binary subdir. +```bash +export VULKAN_SDK=/VulkanSDK/1.2.176.1/x86_64 +``` +To enable automatic shader compilation during build, add the [SpirVTasks package](https://www.nuget.org/packages/SpirVTasks/) and a generic **GLSLShader** item globing a full directory. +```xml + + + + + + +``` +See [SpirVTasks documentation](https://github.com/jpbruyere/vke.net/tree/master/SpirVTasks) for more informations. + +# Creating buffers Vke has two classes to handle buffers. Mappable [`HostBuffer`](../../../../wiki/vke.HostBuffer) and device only [`GPUBuffer`](../../../../wiki/vke.GPUBuffer). For this first simple example, we will only use host mappable buffers. Those classes can handle a Generic argument of a blittable type to handle arrays. Resources like buffers or images are activated in constructor, and they need to be explicitly disposed on cleanup. Create them in the `initVulkan` override. @@ -16,7 +32,7 @@ To be able to access the mvp matrix in a shader, we need a descriptor. This impl ```csharp descriptorPool = new DescriptorPool (dev, 1, new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer)); ``` -### Creating pipelines +# Configuring pipelines Graphic pipeline configuration are predefined by the [`GraphicPipelineConfig`](../../../../wiki/vke.GraphicPipelineConfig) class, which ease sharing configs for several pipelines having lots in common. The pipeline layout will be automatically activated on pipeline creation, so that sharing layout among different pipelines will benefit from the reference counting to automatically dispose unused layout on pipeline clean up. It's the same for [`DescriptorSetLayout`](../../wiki/api/DescriptorSetLayout). ```csharp @@ -38,24 +54,72 @@ cfg.AddVertexBinding (0); cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, //position VkFormat.R32g32b32Sfloat);//color ``` -shader are automatically compiled by [`SpirVTasks`](../../SpirVTasks/README.md) if added to the project. The resulting shaders are automatically embedded in the assembly. To specifiy that the shader path is a resource name, put the **'#'** prefix. Else the path will be search on disk. +# Adding the shaders +Add both vertex and fragment shaders to the globbed directory of your `.csproj` + +##### triangle.vert +```glsl +#version 450 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inColor; + +layout (binding = 0) uniform UBO +{ + mat4 mvp; +}; + +layout (location = 0) out vec3 outColor; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() +{ + outColor = inColor; + gl_Position = mvp * vec4(inPos.xyz, 1.0); +} +``` +##### triangle.frag +```glsl +#version 450 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inColor; +layout (location = 0) out vec4 outFragColor; + +void main() +{ + outFragColor = vec4(inColor, 1.0); +} +``` + +Shaders will be compiled into spir-v automatically during build by the `SpirVTasks`. The resulting shaders will be embedded in the assembly. To specifiy that the shader path is a resource name, put the '**`#`**' prefix. Else the path will be search on disk. ```csharp -cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv"); -cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv"); +cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.triangle.vert.spv"); +cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.triangle.frag.spv"); ``` -Because native ShaderModule used during pipeline creation may be disposed once the pipeline is created, The PipelineConfig class implement the +Because native ShaderModule used during pipeline creation may be distroyed once the pipeline is created, The PipelineConfig class implement the 'IDisposable' interface to release those pointers automaticaly. -Once the pipeline configuration is complete, we use it to effectively create and activate a graphic pipeline. Activables used by the pipeline (like the RenderPass, or the PipelineLayout) are referenced in the newly created managed pipeline. So the Configuration object doesn't need cleanup. +# Creating the pipeline +Once the pipeline configuration is complete, we use it to effectively create and activate a new graphic pipeline. Activables used by the pipeline (like the RenderPass, or the PipelineLayout) are referenced in the newly created managed pipeline. So the Configuration object doesn't need cleanup. ```csharp pipeline = new GraphicPipeline (cfg); ``` +# Descriptor allocation Because descriptor layouts used for a pipeline are only activated on pipeline activation, descriptor sets must not be allocated before, except if the layout has been manually activated, but in this case, layouts will also need to be explicitly disposed. ```csharp descriptorSet = descriptorPool.Allocate (pipeline.Layout.DescriptorSetLayouts[0]); ``` - -### Descriptor update +# Descriptor update The descriptor update is a two step operation. First we create a [`DescriptorSetWrites`](../../../../wiki/vke.DescriptorSetWrites) object defining the layout(s), than we write the descriptor(s). The `Descriptor` property of the mvp HostBuffer will return a default descriptor with no offset of the full size of the buffer. @@ -67,7 +131,7 @@ DescriptorSetWrites uboUpdate = uboUpdate.Write (dev, uboMats.Descriptor); ``` -### Updating the view +# Updating the view Override the `UpdateView` method of the `VkWindow` class to update view related stuff like matrices. diff --git a/samples/Triangle/shaders/main.frag b/samples/Triangle/shaders/main.frag index a3cafac..85aeb08 100644 --- a/samples/Triangle/shaders/main.frag +++ b/samples/Triangle/shaders/main.frag @@ -6,7 +6,7 @@ layout (location = 0) in vec3 inColor; layout (location = 0) out vec4 outFragColor; -void main() +void main() { - outFragColor = vec4(inColor, 1.0); + outFragColor = vec4(inColor, 1.0); } \ No newline at end of file diff --git a/samples/Triangle/shaders/main.vert b/samples/Triangle/shaders/main.vert index 0997ca9..40a3796 100644 --- a/samples/Triangle/shaders/main.vert +++ b/samples/Triangle/shaders/main.vert @@ -6,20 +6,20 @@ layout (location = 0) in vec3 inPos; layout (location = 1) in vec3 inColor; -layout (binding = 0) uniform UBO +layout (binding = 0) uniform UBO { mat4 mvp; }; layout (location = 0) out vec3 outColor; -out gl_PerVertex +out gl_PerVertex { - vec4 gl_Position; + vec4 gl_Position; }; -void main() +void main() { outColor = inColor; gl_Position = mvp * vec4(inPos.xyz, 1.0); diff --git a/samples/common/SampleBase.cs b/samples/common/SampleBase.cs index 32120d9..76a85f3 100644 --- a/samples/common/SampleBase.cs +++ b/samples/common/SampleBase.cs @@ -7,24 +7,6 @@ using System.Runtime.InteropServices; namespace vke { public abstract class SampleBase : VkWindow { -#if NETCOREAPP - static IntPtr resolveUnmanaged (Assembly assembly, String libraryName) { - - switch (libraryName) - { - case "glfw3": - return NativeLibrary.Load("glfw", assembly, null); - case "rsvg-2.40": - return NativeLibrary.Load("rsvg-2", assembly, null); - } - Console.WriteLine ($"[UNRESOLVE] {assembly} {libraryName}"); - return IntPtr.Zero; - } - - static SampleBase () { - System.Runtime.Loader.AssemblyLoadContext.Default.ResolvingUnmanagedDll+=resolveUnmanaged; - } -#endif public SampleBase (string name = "VkWindow", uint _width = 800, uint _height = 600, bool vSync = true) : base (name, _width, _height, vSync){} } diff --git a/vke/src/VkWindow.cs b/vke/src/VkWindow.cs index bd92295..6071969 100644 --- a/vke/src/VkWindow.cs +++ b/vke/src/VkWindow.cs @@ -16,7 +16,6 @@ namespace vke { /// Provide default swapchain with its command pool and buffers per image and the main present queue /// public abstract class VkWindow : IDisposable { - /** GLFW callback may return a custom pointer, this list makes the link between the GLFW window pointer and the manage VkWindow instance. */ static Dictionary windows = new Dictionary(); diff --git a/vke/vke.csproj b/vke/vke.csproj index 19434e5..4b624b8 100644 --- a/vke/vke.csproj +++ b/vke/vke.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netcoreapp3.0 $(VkeReleaseVersion) @@ -50,7 +50,7 @@ - + -- 2.47.3