From: Jean-Philippe Bruyère Date: Thu, 12 Sep 2019 03:08:12 +0000 (+0200) Subject: debug X-Git-Tag: v0.1.21~36 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=27244847a54c21df19867f68b6c1c4abe8829061;p=jp%2Fvke.net.git debug --- diff --git a/Directory.Build.props b/Directory.Build.props deleted file mode 100644 index 449260d..0000000 --- a/Directory.Build.props +++ /dev/null @@ -1,14 +0,0 @@ - - - $(MSBuildThisFileDirectory) - true - - net471;netstandard2.0 - - https://github.com/jpbruyere/vke.net - MIT - Jean-Philippe Bruyère - - 7.2 - - diff --git a/README.md b/README.md index 26256a7..3f59e44 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ vke.net

+ + + + + + @@ -19,8 +25,8 @@ vke.net **vke.net** (_vulkan engine for .net_) is composed of high level classes encapsulating vulkan objects with `IDispose` model and **reference counting**. [GLFW](https://www.glfw.org/) handles the windowing system. ### Requirements -- [GLFW](https://www.glfw.org/) -- [libstb](https://github.com/nothings/stb), on debian install **libstb-dev**. +- [GLFW](https://www.glfw.org/) if you use the `VkWindow` class. +- If you want to use `jpg`, `jpeg`, `png` image [libstb](https://github.com/nothings/stb) (on debian install **libstb-dev**). Note that `ktx` image loading has no dependencies. - [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). diff --git a/SpirVTasks/README.md b/SpirVTasks/README.md index 226e438..e3659cd 100644 --- a/SpirVTasks/README.md +++ b/SpirVTasks/README.md @@ -11,8 +11,8 @@

-**SpirVTasks** package add **SpirV** compilation support to msbuild project. Error and warning -are routed to the **IDE**. +`SpirVTasks` package add `SpirV` compilation support to msbuild project. Error and warning +are routed to the `IDE`. #### Usage @@ -21,7 +21,7 @@ are routed to the **IDE**. ``` -Resulting `.spv` files are embedded with resource ID = **ProjectName.file.ext.spv**. You can override the default resource id by adding a custom LogicalName. +Resulting `.spv` files are embedded with resource ID = `ProjectName.file.ext.spv`. You can override the default resource id by adding a custom LogicalName. ```xml @@ -29,14 +29,13 @@ Resulting `.spv` files are embedded with resource ID = **ProjectName.file.ext.sp ``` -**VULKAN_SDK**/bin then **PATH** are searched for the **glslc** executable. You can also use **`SpirVglslcPath`** property. +`VULKAN_SDK`/bin then `PATH` are searched for the `glslc` executable. You can also use the `SpirVglslcPath` property. ```xml bin\glslc.exe ``` - #### Include in glsl ```glsl #include @@ -49,9 +48,7 @@ void main() outFragColor = vec4(inColor, 1.0); } ``` - -Included files are searched from the location of the current parsed file, then in the **``** directories if present. - +Included files are searched from the location of the current parsed file, then in the `SpirVAdditionalIncludeDirectories`directories if present. ```xml $(MSBuildThisFileDirectory)common;testdir;../anotherdir @@ -59,4 +56,5 @@ Included files are searched from the location of the current parsed file, then i ``` #### todo + - Error source file and line with included files. diff --git a/SpirVTasks/SpirVTasks.targets b/SpirVTasks/SpirVTasks.targets index 6825c47..690712f 100644 --- a/SpirVTasks/SpirVTasks.targets +++ b/SpirVTasks/SpirVTasks.targets @@ -13,17 +13,17 @@ DestinationFile="$(IntermediateOutputPath)%(RelativeDir)%(Filename)%(Extension).spv" /> + AdditionalMetadata="LogicalName=%(GLSLShader.LogicalName)"> + TaskParameter="Include" + ItemName="EmbeddedResource"/> + AdditionalMetadata="LogicalName=$(AssemblyName).%(GLSLShader.Filename)%(Extension).spv"> + TaskParameter="Include" + ItemName="EmbeddedResource"/> diff --git a/addons/Directory.Build.props b/addons/Directory.Build.props index bce5b09..224a27a 100644 --- a/addons/Directory.Build.props +++ b/addons/Directory.Build.props @@ -27,7 +27,8 @@ - + + diff --git a/addons/DistanceFieldFont/BMChar.cs b/addons/DistanceFieldFont/BMChar.cs index 0667fc3..4b9576e 100644 --- a/addons/DistanceFieldFont/BMChar.cs +++ b/addons/DistanceFieldFont/BMChar.cs @@ -2,7 +2,7 @@ // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; -namespace CVKL.DistanceFieldFont { +namespace vke.DistanceFieldFont { public struct BMChar { public enum Channel { Blue = 0x01, diff --git a/addons/DistanceFieldFont/BMFont.cs b/addons/DistanceFieldFont/BMFont.cs index e277517..824d265 100644 --- a/addons/DistanceFieldFont/BMFont.cs +++ b/addons/DistanceFieldFont/BMFont.cs @@ -7,7 +7,7 @@ using System.IO; using System.Reflection; using VK; -namespace CVKL.DistanceFieldFont { +namespace vke.DistanceFieldFont { /// /// BMF font. (http://www.angelcode.com/products/bmfont/doc/file_format.html) /// diff --git a/addons/VkvgPipeline/VkvgPipeline.cs b/addons/VkvgPipeline/VkvgPipeline.cs index 1d4ce02..62e852b 100644 --- a/addons/VkvgPipeline/VkvgPipeline.cs +++ b/addons/VkvgPipeline/VkvgPipeline.cs @@ -3,7 +3,7 @@ // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Numerics; -using CVKL; +using vke; using VK; namespace VkvgPipeline { @@ -104,7 +104,7 @@ namespace VkvgPipeline { if (img.CreateInfo.usage.HasFlag (VkImageUsageFlags.Sampled)) c.X += 0.3f; } else { - CVKL.Buffer buff = r as CVKL.Buffer; + vke.Buffer buff = r as vke.Buffer; c.X = 1f; if (buff.Infos.usage.HasFlag (VkBufferUsageFlags.IndexBuffer)) c.Y += 0.2f; diff --git a/addons/gltfLoader/PbrModel.cs b/addons/gltfLoader/PbrModel.cs index 396c42f..11f28b5 100644 --- a/addons/gltfLoader/PbrModel.cs +++ b/addons/gltfLoader/PbrModel.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; using VK; using System.Collections.Generic; -namespace CVKL.glTF { +namespace vke.glTF { //TODO:stride in buffer views? public abstract class PbrModel : Model { //public new struct Vertex { diff --git a/addons/gltfLoader/PbrModelSeparateTextures.cs b/addons/gltfLoader/PbrModelSeparateTextures.cs index c1a6ee9..de2f67a 100644 --- a/addons/gltfLoader/PbrModelSeparateTextures.cs +++ b/addons/gltfLoader/PbrModelSeparateTextures.cs @@ -7,7 +7,7 @@ using System.Numerics; using System.Runtime.InteropServices; using VK; -namespace CVKL.glTF { +namespace vke.glTF { /// /// Indexed pbr model whith one descriptorSet per material with separate textures attachments /// diff --git a/addons/gltfLoader/PbrModelTexArray.cs b/addons/gltfLoader/PbrModelTexArray.cs index 5943774..7c07de0 100644 --- a/addons/gltfLoader/PbrModelTexArray.cs +++ b/addons/gltfLoader/PbrModelTexArray.cs @@ -6,7 +6,7 @@ using System.Numerics; using System.Runtime.InteropServices; using VK; -namespace CVKL.glTF { +namespace vke.glTF { /// /// Indexed pbr model whith one descriptorSet per material with separate textures attachments /// diff --git a/addons/gltfLoader/glTFLoader.cs b/addons/gltfLoader/glTFLoader.cs index 06e8ad6..936db08 100644 --- a/addons/gltfLoader/glTFLoader.cs +++ b/addons/gltfLoader/glTFLoader.cs @@ -14,9 +14,9 @@ using System.IO; -namespace CVKL.glTF { +namespace vke.glTF { using static VK.Utils; - using static CVKL.Model; + using static vke.Model; /// /// Loading context with I as the vertex index type (uint16,uint32) diff --git a/datas/font.fnt b/datas/font.fnt new file mode 100644 index 0000000..81cb615 --- /dev/null +++ b/datas/font.fnt @@ -0,0 +1,343 @@ +info face="Arial Black Standard" size=32 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=4,4,4,4 spacing=-8,-8 +common lineHeight=46 base=36 scaleW=512 scaleH=512 pages=1 packed=0 +page id=0 file="font.ktx" +chars count=97 +char id=0 x=237 y=102 width=25 height=29 xoffset=-4 yoffset=11 xadvance=24 page=0 chnl=0 +char id=10 x=0 y=0 width=0 height=0 xoffset=-4 yoffset=0 xadvance=0 page=0 chnl=0 +char id=32 x=0 y=0 width=0 height=0 xoffset=-4 yoffset=0 xadvance=11 page=0 chnl=0 +char id=33 x=27 y=102 width=15 height=32 xoffset=-4 yoffset=8 xadvance=11 page=0 chnl=0 +char id=34 x=298 y=134 width=24 height=17 xoffset=-4 yoffset=8 xadvance=16 page=0 chnl=0 +char id=35 x=154 y=102 width=28 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=36 x=150 y=0 width=28 height=37 xoffset=-4 yoffset=6 xadvance=21 page=0 chnl=0 +char id=37 x=117 y=102 width=37 height=32 xoffset=-4 yoffset=8 xadvance=32 page=0 chnl=0 +char id=38 x=182 y=102 width=34 height=32 xoffset=-4 yoffset=8 xadvance=28 page=0 chnl=0 +char id=39 x=322 y=134 width=15 height=17 xoffset=-4 yoffset=8 xadvance=9 page=0 chnl=0 +char id=40 x=20 y=0 width=18 height=38 xoffset=-4 yoffset=8 xadvance=12 page=0 chnl=0 +char id=41 x=38 y=0 width=19 height=38 xoffset=-4 yoffset=8 xadvance=12 page=0 chnl=0 +char id=42 x=279 y=134 width=19 height=21 xoffset=-4 yoffset=8 xadvance=18 page=0 chnl=0 +char id=43 x=186 y=134 width=26 height=26 xoffset=-4 yoffset=11 xadvance=21 page=0 chnl=0 +char id=44 x=264 y=134 width=15 height=21 xoffset=-4 yoffset=25 xadvance=11 page=0 chnl=0 +char id=45 x=394 y=134 width=18 height=14 xoffset=-4 yoffset=20 xadvance=11 page=0 chnl=0 +char id=46 x=363 y=134 width=15 height=15 xoffset=-4 yoffset=25 xadvance=11 page=0 chnl=0 +char id=47 x=83 y=102 width=17 height=32 xoffset=-4 yoffset=8 xadvance=9 page=0 chnl=0 +char id=48 x=0 y=102 width=27 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=49 x=261 y=70 width=22 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=50 x=283 y=70 width=27 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=51 x=310 y=70 width=27 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=52 x=337 y=70 width=29 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=53 x=366 y=70 width=27 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=54 x=393 y=70 width=27 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=55 x=420 y=70 width=27 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=56 x=447 y=70 width=27 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=57 x=474 y=70 width=27 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=58 x=171 y=134 width=15 height=26 xoffset=-4 yoffset=14 xadvance=11 page=0 chnl=0 +char id=59 x=68 y=102 width=15 height=32 xoffset=-4 yoffset=14 xadvance=11 page=0 chnl=0 +char id=60 x=262 y=102 width=26 height=27 xoffset=-4 yoffset=11 xadvance=21 page=0 chnl=0 +char id=61 x=238 y=134 width=26 height=22 xoffset=-4 yoffset=13 xadvance=21 page=0 chnl=0 +char id=62 x=288 y=102 width=26 height=27 xoffset=-4 yoffset=11 xadvance=21 page=0 chnl=0 +char id=63 x=42 y=102 width=26 height=32 xoffset=-4 yoffset=8 xadvance=20 page=0 chnl=0 +char id=64 x=178 y=0 width=33 height=35 xoffset=-4 yoffset=8 xadvance=24 page=0 chnl=0 +char id=65 x=244 y=0 width=33 height=32 xoffset=-4 yoffset=8 xadvance=25 page=0 chnl=0 +char id=66 x=277 y=0 width=30 height=32 xoffset=-4 yoffset=8 xadvance=25 page=0 chnl=0 +char id=67 x=307 y=0 width=30 height=32 xoffset=-4 yoffset=8 xadvance=25 page=0 chnl=0 +char id=68 x=337 y=0 width=30 height=32 xoffset=-4 yoffset=8 xadvance=25 page=0 chnl=0 +char id=69 x=367 y=0 width=28 height=32 xoffset=-4 yoffset=8 xadvance=23 page=0 chnl=0 +char id=70 x=395 y=0 width=26 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=71 x=421 y=0 width=33 height=32 xoffset=-4 yoffset=8 xadvance=27 page=0 chnl=0 +char id=72 x=454 y=0 width=31 height=32 xoffset=-4 yoffset=8 xadvance=27 page=0 chnl=0 +char id=73 x=485 y=0 width=16 height=32 xoffset=-4 yoffset=8 xadvance=12 page=0 chnl=0 +char id=74 x=0 y=38 width=26 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=75 x=26 y=38 width=33 height=32 xoffset=-4 yoffset=8 xadvance=27 page=0 chnl=0 +char id=76 x=59 y=38 width=26 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=77 x=85 y=38 width=34 height=32 xoffset=-4 yoffset=8 xadvance=30 page=0 chnl=0 +char id=78 x=119 y=38 width=31 height=32 xoffset=-4 yoffset=8 xadvance=27 page=0 chnl=0 +char id=79 x=150 y=38 width=33 height=32 xoffset=-4 yoffset=8 xadvance=27 page=0 chnl=0 +char id=80 x=183 y=38 width=27 height=32 xoffset=-4 yoffset=8 xadvance=23 page=0 chnl=0 +char id=81 x=211 y=0 width=33 height=34 xoffset=-4 yoffset=8 xadvance=27 page=0 chnl=0 +char id=82 x=210 y=38 width=31 height=32 xoffset=-4 yoffset=8 xadvance=25 page=0 chnl=0 +char id=83 x=241 y=38 width=30 height=32 xoffset=-4 yoffset=8 xadvance=23 page=0 chnl=0 +char id=84 x=271 y=38 width=30 height=32 xoffset=-4 yoffset=8 xadvance=23 page=0 chnl=0 +char id=85 x=301 y=38 width=31 height=32 xoffset=-4 yoffset=8 xadvance=27 page=0 chnl=0 +char id=86 x=332 y=38 width=33 height=32 xoffset=-4 yoffset=8 xadvance=25 page=0 chnl=0 +char id=87 x=365 y=38 width=41 height=32 xoffset=-4 yoffset=8 xadvance=32 page=0 chnl=0 +char id=88 x=406 y=38 width=33 height=32 xoffset=-4 yoffset=8 xadvance=25 page=0 chnl=0 +char id=89 x=439 y=38 width=33 height=32 xoffset=-4 yoffset=8 xadvance=25 page=0 chnl=0 +char id=90 x=472 y=38 width=29 height=32 xoffset=-4 yoffset=8 xadvance=23 page=0 chnl=0 +char id=91 x=57 y=0 width=19 height=38 xoffset=-4 yoffset=8 xadvance=12 page=0 chnl=0 +char id=92 x=100 y=102 width=17 height=32 xoffset=-4 yoffset=8 xadvance=9 page=0 chnl=0 +char id=93 x=76 y=0 width=19 height=38 xoffset=-4 yoffset=8 xadvance=12 page=0 chnl=0 +char id=94 x=212 y=134 width=26 height=22 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=95 x=412 y=134 width=25 height=11 xoffset=-4 yoffset=33 xadvance=16 page=0 chnl=0 +char id=96 x=378 y=134 width=16 height=14 xoffset=-4 yoffset=8 xadvance=11 page=0 chnl=0 +char id=97 x=314 y=102 width=26 height=26 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=98 x=0 y=70 width=26 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=99 x=340 y=102 width=26 height=26 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=100 x=26 y=70 width=26 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=101 x=366 y=102 width=27 height=26 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=102 x=52 y=70 width=21 height=32 xoffset=-4 yoffset=8 xadvance=12 page=0 chnl=0 +char id=103 x=73 y=70 width=26 height=32 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=104 x=99 y=70 width=25 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=105 x=124 y=70 width=15 height=32 xoffset=-4 yoffset=8 xadvance=11 page=0 chnl=0 +char id=106 x=0 y=0 width=20 height=38 xoffset=-4 yoffset=8 xadvance=11 page=0 chnl=0 +char id=107 x=139 y=70 width=27 height=32 xoffset=-4 yoffset=8 xadvance=21 page=0 chnl=0 +char id=108 x=166 y=70 width=15 height=32 xoffset=-4 yoffset=8 xadvance=11 page=0 chnl=0 +char id=109 x=393 y=102 width=37 height=26 xoffset=-4 yoffset=14 xadvance=32 page=0 chnl=0 +char id=110 x=430 y=102 width=25 height=26 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=111 x=455 y=102 width=27 height=26 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=112 x=181 y=70 width=26 height=32 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=113 x=207 y=70 width=26 height=32 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=114 x=482 y=102 width=22 height=26 xoffset=-4 yoffset=14 xadvance=14 page=0 chnl=0 +char id=115 x=0 y=134 width=27 height=26 xoffset=-4 yoffset=14 xadvance=20 page=0 chnl=0 +char id=116 x=216 y=102 width=21 height=31 xoffset=-4 yoffset=9 xadvance=14 page=0 chnl=0 +char id=117 x=27 y=134 width=25 height=26 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=118 x=52 y=134 width=27 height=26 xoffset=-4 yoffset=14 xadvance=20 page=0 chnl=0 +char id=119 x=79 y=134 width=39 height=26 xoffset=-4 yoffset=14 xadvance=30 page=0 chnl=0 +char id=120 x=118 y=134 width=29 height=26 xoffset=-4 yoffset=14 xadvance=21 page=0 chnl=0 +char id=121 x=233 y=70 width=28 height=32 xoffset=-4 yoffset=14 xadvance=20 page=0 chnl=0 +char id=122 x=147 y=134 width=24 height=26 xoffset=-4 yoffset=14 xadvance=18 page=0 chnl=0 +char id=123 x=95 y=0 width=21 height=38 xoffset=-4 yoffset=8 xadvance=12 page=0 chnl=0 +char id=124 x=137 y=0 width=13 height=38 xoffset=-4 yoffset=8 xadvance=9 page=0 chnl=0 +char id=125 x=116 y=0 width=21 height=38 xoffset=-4 yoffset=8 xadvance=12 page=0 chnl=0 +char id=126 x=337 y=134 width=26 height=17 xoffset=-4 yoffset=15 xadvance=21 page=0 chnl=0 +kernings count=241 +kerning first=102 second=101 amount=-1 +kerning first=76 second=89 amount=-2 +kerning first=76 second=79 amount=-1 +kerning first=80 second=65 amount=-3 +kerning first=102 second=111 amount=-1 +kerning first=86 second=97 amount=-1 +kerning first=84 second=114 amount=-1 +kerning first=119 second=44 amount=-2 +kerning first=65 second=79 amount=-1 +kerning first=86 second=67 amount=-1 +kerning first=66 second=44 amount=1 +kerning first=84 second=45 amount=-2 +kerning first=80 second=46 amount=-6 +kerning first=65 second=89 amount=-3 +kerning first=67 second=46 amount=1 +kerning first=112 second=119 amount=-1 +kerning first=84 second=67 amount=-1 +kerning first=84 second=58 amount=-1 +kerning first=84 second=59 amount=-1 +kerning first=114 second=113 amount=1 +kerning first=102 second=63 amount=3 +kerning first=80 second=111 amount=-1 +kerning first=86 second=114 amount=-1 +kerning first=89 second=67 amount=-2 +kerning first=114 second=111 amount=1 +kerning first=88 second=71 amount=-1 +kerning first=80 second=101 amount=-1 +kerning first=87 second=46 amount=-2 +kerning first=75 second=117 amount=-1 +kerning first=114 second=100 amount=1 +kerning first=86 second=117 amount=-1 +kerning first=87 second=79 amount=-1 +kerning first=86 second=79 amount=-1 +kerning first=81 second=86 amount=-1 +kerning first=82 second=81 amount=-1 +kerning first=115 second=119 amount=-1 +kerning first=65 second=85 amount=-1 +kerning first=68 second=87 amount=1 +kerning first=112 second=46 amount=-1 +kerning first=81 second=89 amount=-2 +kerning first=114 second=97 amount=1 +kerning first=84 second=97 amount=-2 +kerning first=65 second=86 amount=-2 +kerning first=84 second=99 amount=-2 +kerning first=89 second=100 amount=-3 +kerning first=102 second=102 amount=1 +kerning first=114 second=103 amount=1 +kerning first=87 second=104 amount=1 +kerning first=86 second=105 amount=1 +kerning first=114 second=106 amount=1 +kerning first=74 second=111 amount=-1 +kerning first=99 second=108 amount=-1 +kerning first=84 second=109 amount=-1 +kerning first=114 second=110 amount=2 +kerning first=118 second=111 amount=-1 +kerning first=89 second=112 amount=-2 +kerning first=70 second=114 amount=-1 +kerning first=97 second=116 amount=-1 +kerning first=89 second=117 amount=-2 +kerning first=76 second=119 amount=-1 +kerning first=101 second=120 amount=-1 +kerning first=99 second=121 amount=-1 +kerning first=82 second=119 amount=1 +kerning first=66 second=65 amount=-1 +kerning first=81 second=84 amount=-1 +kerning first=80 second=44 amount=-6 +kerning first=97 second=103 amount=1 +kerning first=111 second=120 amount=-1 +kerning first=65 second=112 amount=1 +kerning first=84 second=46 amount=-5 +kerning first=86 second=101 amount=-2 +kerning first=119 second=104 amount=1 +kerning first=114 second=117 amount=1 +kerning first=121 second=44 amount=-3 +kerning first=121 second=46 amount=-3 +kerning first=89 second=97 amount=-3 +kerning first=75 second=101 amount=-1 +kerning first=65 second=118 amount=-1 +kerning first=70 second=97 amount=-1 +kerning first=119 second=113 amount=-1 +kerning first=75 second=111 amount=-1 +kerning first=75 second=71 amount=-1 +kerning first=87 second=97 amount=-1 +kerning first=101 second=103 amount=1 +kerning first=87 second=105 amount=1 +kerning first=81 second=46 amount=1 +kerning first=86 second=71 amount=-1 +kerning first=67 second=44 amount=1 +kerning first=114 second=99 amount=1 +kerning first=70 second=44 amount=-5 +kerning first=66 second=85 amount=-1 +kerning first=76 second=86 amount=-2 +kerning first=89 second=59 amount=-2 +kerning first=84 second=44 amount=-5 +kerning first=120 second=101 amount=-1 +kerning first=108 second=121 amount=1 +kerning first=89 second=101 amount=-3 +kerning first=114 second=46 amount=-2 +kerning first=121 second=99 amount=-1 +kerning first=114 second=101 amount=1 +kerning first=101 second=118 amount=-1 +kerning first=81 second=44 amount=1 +kerning first=74 second=121 amount=-1 +kerning first=82 second=79 amount=-1 +kerning first=89 second=113 amount=-3 +kerning first=119 second=46 amount=-3 +kerning first=68 second=89 amount=-1 +kerning first=119 second=111 amount=-1 +kerning first=102 second=46 amount=-2 +kerning first=86 second=44 amount=-4 +kerning first=114 second=109 amount=2 +kerning first=79 second=89 amount=-2 +kerning first=86 second=65 amount=-2 +kerning first=103 second=114 amount=1 +kerning first=102 second=33 amount=3 +kerning first=84 second=122 amount=-1 +kerning first=86 second=46 amount=-4 +kerning first=70 second=101 amount=-1 +kerning first=99 second=104 amount=-1 +kerning first=89 second=44 amount=-5 +kerning first=68 second=86 amount=-1 +kerning first=88 second=79 amount=-1 +kerning first=82 second=89 amount=-1 +kerning first=75 second=67 amount=-1 +kerning first=98 second=118 amount=-1 +kerning first=89 second=65 amount=-3 +kerning first=114 second=107 amount=1 +kerning first=84 second=101 amount=-2 +kerning first=89 second=79 amount=-2 +kerning first=114 second=118 amount=2 +kerning first=84 second=111 amount=-2 +kerning first=120 second=111 amount=-1 +kerning first=82 second=111 amount=-1 +kerning first=79 second=87 amount=-1 +kerning first=84 second=71 amount=-1 +kerning first=118 second=100 amount=-1 +kerning first=74 second=97 amount=-1 +kerning first=89 second=45 amount=-3 +kerning first=84 second=81 amount=-1 +kerning first=114 second=115 amount=1 +kerning first=68 second=46 amount=-1 +kerning first=79 second=44 amount=-1 +kerning first=121 second=100 amount=-1 +kerning first=114 second=112 amount=1 +kerning first=87 second=71 amount=-1 +kerning first=89 second=83 amount=-1 +kerning first=86 second=111 amount=-2 +kerning first=87 second=111 amount=-1 +kerning first=70 second=46 amount=-5 +kerning first=81 second=65 amount=1 +kerning first=114 second=58 amount=1 +kerning first=84 second=104 amount=1 +kerning first=114 second=116 amount=2 +kerning first=87 second=101 amount=-1 +kerning first=65 second=67 amount=-1 +kerning first=70 second=65 amount=-3 +kerning first=65 second=81 amount=-1 +kerning first=118 second=46 amount=-3 +kerning first=103 second=121 amount=1 +kerning first=87 second=67 amount=-1 +kerning first=74 second=46 amount=-1 +kerning first=76 second=67 amount=-1 +kerning first=75 second=79 amount=-1 +kerning first=87 second=44 amount=-1 +kerning first=89 second=58 amount=-2 +kerning first=86 second=59 amount=-1 +kerning first=114 second=121 amount=2 +kerning first=121 second=97 amount=-1 +kerning first=76 second=87 amount=-1 +kerning first=118 second=44 amount=-3 +kerning first=79 second=84 amount=-1 +kerning first=111 second=119 amount=-1 +kerning first=111 second=118 amount=-1 +kerning first=84 second=108 amount=1 +kerning first=82 second=117 amount=-1 +kerning first=89 second=46 amount=-5 +kerning first=111 second=122 amount=1 +kerning first=84 second=65 amount=-2 +kerning first=74 second=117 amount=-1 +kerning first=107 second=111 amount=-1 +kerning first=85 second=65 amount=-1 +kerning first=111 second=121 amount=-1 +kerning first=114 second=59 amount=1 +kerning first=65 second=84 amount=-2 +kerning first=89 second=118 amount=-1 +kerning first=86 second=58 amount=-1 +kerning first=87 second=100 amount=-1 +kerning first=76 second=84 amount=-2 +kerning first=102 second=32 amount=2 +kerning first=111 second=46 amount=-1 +kerning first=114 second=114 amount=1 +kerning first=82 second=86 amount=-1 +kerning first=74 second=44 amount=-1 +kerning first=118 second=99 amount=-1 +kerning first=86 second=81 amount=-1 +kerning first=79 second=88 amount=-2 +kerning first=85 second=44 amount=-1 +kerning first=118 second=101 amount=-1 +kerning first=88 second=67 amount=-1 +kerning first=79 second=86 amount=-1 +kerning first=75 second=118 amount=-1 +kerning first=76 second=85 amount=-1 +kerning first=107 second=101 amount=-1 +kerning first=84 second=117 amount=-1 +kerning first=120 second=99 amount=-1 +kerning first=75 second=121 amount=-1 +kerning first=84 second=115 amount=-2 +kerning first=114 second=44 amount=-2 +kerning first=82 second=71 amount=-1 +kerning first=85 second=46 amount=-1 +kerning first=70 second=111 amount=-1 +kerning first=97 second=118 amount=-1 +kerning first=121 second=111 amount=-1 +kerning first=79 second=65 amount=-1 +kerning first=82 second=101 amount=-1 +kerning first=65 second=71 amount=-1 +kerning first=102 second=44 amount=-2 +kerning first=112 second=121 amount=-1 +kerning first=74 second=101 amount=-1 +kerning first=86 second=45 amount=-1 +kerning first=121 second=101 amount=-1 +kerning first=84 second=79 amount=-1 +kerning first=89 second=111 amount=-3 +kerning first=118 second=113 amount=-1 +kerning first=74 second=65 amount=-1 +kerning first=76 second=71 amount=-1 +kerning first=79 second=46 amount=-1 +kerning first=68 second=65 amount=-1 +kerning first=114 second=108 amount=1 +kerning first=71 second=44 amount=1 +kerning first=110 second=118 amount=-1 +kerning first=82 second=85 amount=-1 +kerning first=87 second=117 amount=-1 +kerning first=120 second=100 amount=-1 +kerning first=80 second=97 amount=-1 +kerning first=99 second=107 amount=-1 +kerning first=66 second=46 amount=1 +kerning first=89 second=71 amount=-2 +kerning first=107 second=121 amount=1 +kerning first=82 second=67 amount=-1 +kerning first=84 second=121 amount=-1 diff --git a/datas/models/Box.gltf b/datas/models/Box.gltf new file mode 100644 index 0000000..8f9e0d3 --- /dev/null +++ b/datas/models/Box.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f98a369e29ffc754cc897f78d695754ac6812ba7ddcd23705dd8d4e258f5f13b +size 3791 diff --git a/datas/models/DamagedHelmet/glTF-Embedded/DamagedHelmet.gltf b/datas/models/DamagedHelmet/glTF-Embedded/DamagedHelmet.gltf new file mode 100644 index 0000000..0f51039 --- /dev/null +++ b/datas/models/DamagedHelmet/glTF-Embedded/DamagedHelmet.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0fa7be52a4c63e96af2be05735caba968b04a633a9c5eaf1b4c95fb25588003 +size 5033556 diff --git a/datas/models/DamagedHelmet/glTF/DamagedHelmet.bin b/datas/models/DamagedHelmet/glTF/DamagedHelmet.bin new file mode 100644 index 0000000..662eacc Binary files /dev/null and b/datas/models/DamagedHelmet/glTF/DamagedHelmet.bin differ diff --git a/datas/models/DamagedHelmet/glTF/DamagedHelmet.gltf b/datas/models/DamagedHelmet/glTF/DamagedHelmet.gltf new file mode 100644 index 0000000..d685d77 --- /dev/null +++ b/datas/models/DamagedHelmet/glTF/DamagedHelmet.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:efe99dfac198094a30c71dc02a4d3421f0eef6bf335aeb695daa4d62134cd93f +size 4537 diff --git a/datas/models/Sponza/README.md b/datas/models/Sponza/README.md new file mode 100644 index 0000000..89e3787 --- /dev/null +++ b/datas/models/Sponza/README.md @@ -0,0 +1,68 @@ +# Sponza + +## Screenshot + +Lights are shown here, they are not part of the model. + +![screenshot](screenshot/large.jpg) + +## Model notes + +Tangents have been computed using MikkTSpace, as the original OBJ model did not have them. +I have manually inspected the normals, and it looks correct to me. +Be aware that W is -1.0 for most of the tangent signs, you will need to handle tangent W for correct results. + + +## Sources + +### http://www.crytek.com/cryengine/cryengine3/downloads +- http://www.crytek.com/download/sponza\_obj.rar +- http://www.crytek.com/download/sponza\_textures.rar + +### http://www.alexandre-pestana.com/pbr-textures-sponza/ +- http://www.alexandre-pestana.com/downloads/SponzaPBR\_Textures.rar + +I needed to resize some of the alpha mask textures to the 1024x1024 resolution used by the new texture pack, +and merge in diffuse with alpha. +I also repacked the separate metallic/roughness textures into the glTF layout (G - roughness, B - metallic). +The images are also re-encoded as PNG instead of TGA. +All the materials also had a constant diffuse factor of about 0.58. I assume it was supposed to be there, so I kept it. +I also ran the vertices and indices through a mesh optimizer. + +## Licensing notes + +Taken from copyright.txt in SponzaPBR\_Textures.rar + +``` +PBR textures for the Sponza model. +For more informations: www.alexandre-pestana.com + + +Original copyright: + +July 14, 2011 Morgan McGuire modified the model from Crytek's OBJ +export to correct some small errors. He computed bump maps from the +normal maps using normal2bump.cpp (since +MTL files expect height bumps, not normals), put the "mask" textures +into the alpha channel of the associated diffuse texture, cleaned up +noise in the masks, created the missing gi_flag.tga texture, and +removed the long untextured banner floating in the middle of the +atrium that appears in the file but in none of the published images of +the model. The banner is in banner.obj. + + + +http://www.crytek.com/cryengine/cryengine3/downloads + + +Sponza Model +August 19, 2010 +The Atrium Sponza Palace, Dubrovnik, is an elegant and improved model created by Frank Meinl. The original Sponza model was created by Marko Dabrovic in early 2002. Over the years, the Sponza Atrium scene has become one of the most popular 3D scenes for testing global illumination and radiosity due to it's specific architectural structure which is particularly complex for global illumination light. + +However, nowadays it is considered as a simple model, thus it was decided to crate a new model with highly improved appearance and scene complexity. It is donated to the public for radiosity and is represented in several different formats (3ds, Obj) for use with various commercial 3D applications and renderers. + + +Screenshot from the I3D paper +http://crytek.com/sites/default/files/20100301_lpv.pdf +``` diff --git a/datas/models/Sponza/glTF/Sponza.bin b/datas/models/Sponza/glTF/Sponza.bin new file mode 100644 index 0000000..971accb Binary files /dev/null and b/datas/models/Sponza/glTF/Sponza.bin differ diff --git a/datas/models/Sponza/glTF/Sponza.gltf b/datas/models/Sponza/glTF/Sponza.gltf new file mode 100644 index 0000000..3168453 --- /dev/null +++ b/datas/models/Sponza/glTF/Sponza.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e17c14edbc06b757dafcfed99f8815af9c5f5d9f9de3f0bc7740c37e68e0d829 +size 212504 diff --git a/datas/models/chess.gltf b/datas/models/chess.gltf new file mode 100644 index 0000000..4f42cd5 --- /dev/null +++ b/datas/models/chess.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a021b7609d4fbc590c4ffe495e3496cd2204f2c226f7f4d5c9421d4a3f8d2eb5 +size 3407650 diff --git a/datas/models/cube.gltf b/datas/models/cube.gltf new file mode 100644 index 0000000..7d72524 --- /dev/null +++ b/datas/models/cube.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87aed37664ba8a792a79e0245c07ce34babcaa40abf94e469234e44cb8ecc9df +size 3663 diff --git a/datas/models/icosphere.gltf b/datas/models/icosphere.gltf new file mode 100644 index 0000000..ef72668 --- /dev/null +++ b/datas/models/icosphere.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3720ae8e6ce9ceb1669396453ea1107575146494588b2e52463020e7ca9cf4d4 +size 34170 diff --git a/datas/models/shadow.bin b/datas/models/shadow.bin new file mode 100644 index 0000000..b332f19 Binary files /dev/null and b/datas/models/shadow.bin differ diff --git a/datas/models/shadow.gltf b/datas/models/shadow.gltf new file mode 100644 index 0000000..62b6133 --- /dev/null +++ b/datas/models/shadow.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a516145efb32792dbf6422ef2f6e5cd0907765584ee083a1f47cf6a94c503fb6 +size 13832 diff --git a/datas/models/shadow2.gltf b/datas/models/shadow2.gltf new file mode 100644 index 0000000..82bf335 --- /dev/null +++ b/datas/models/shadow2.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e2e77f34b0c623f58d2e07eed7a03100f9d09034cc6bfa4ec907105137ee714 +size 11207 diff --git a/datas/models/untitled.bin b/datas/models/untitled.bin new file mode 100644 index 0000000..621d5e6 Binary files /dev/null and b/datas/models/untitled.bin differ diff --git a/datas/models/untitled.gltf b/datas/models/untitled.gltf new file mode 100644 index 0000000..31670a5 --- /dev/null +++ b/datas/models/untitled.gltf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac5f07807d147c9adee8898cac57b977c5130df73847b0fc0adafbb8d495e505 +size 9717 diff --git a/datas/textures/tex.astc b/datas/textures/tex.astc new file mode 100644 index 0000000..6756ffb Binary files /dev/null and b/datas/textures/tex.astc differ diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index b61e7bd..8c1d092 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -26,7 +26,8 @@ - + + diff --git a/samples/DistanceFieldFontTest/Program.cs b/samples/DistanceFieldFontTest/Program.cs index 5820a02..6ba6039 100644 --- a/samples/DistanceFieldFontTest/Program.cs +++ b/samples/DistanceFieldFontTest/Program.cs @@ -4,8 +4,8 @@ using System.Runtime.InteropServices; using Glfw; using VK; -using CVKL; -using CVKL.DistanceFieldFont; +using vke; +using vke.DistanceFieldFont; namespace DistanceFieldFontTest { @@ -46,7 +46,7 @@ namespace DistanceFieldFontTest { DescriptorSet descriptorSet; GraphicPipeline pipeline; - Framebuffer[] frameBuffers; + FrameBuffers frameBuffers; Image fontTexture; @@ -64,11 +64,12 @@ namespace DistanceFieldFontTest { Vector4 outlineColor = new Vector4 (1.0f, 0.0f, 0.0f, 0.6f);//alpha => 0:disabled 1:enabled Program () : base () { + cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); - font = new BMFont ("../data/font.fnt"); + font = new BMFont (Utils.DataDirectory + "font.fnt"); - vbo = new GPUBuffer (dev, VkBufferUsageFlags.VertexBuffer, 1024); - ibo = new GPUBuffer (dev, VkBufferUsageFlags.IndexBuffer, 2048); + vbo = new GPUBuffer (dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.TransferDst, 1024); + ibo = new GPUBuffer (dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.TransferDst, 2048); descriptorPool = new DescriptorPool (dev, 1, new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer), @@ -132,6 +133,8 @@ namespace DistanceFieldFontTest { List indices = new List (); ushort indexOffset = 0; + float charSize = 1.0f; + float w = fontTexture.Width; float posx = 0.0f; @@ -145,10 +148,10 @@ namespace DistanceFieldFontTest { charInfo.width = 36; float charw = ((float)(charInfo.width) / 36.0f); - float dimx = 1.0f * charw; + float dimx = charSize * charw; float charh = ((float)(charInfo.height) / 36.0f); - float dimy = 1.0f * charh; - posy = 1.0f - charh; + float dimy = charSize * charh; + posy = 1.0f - charh * charSize; float us = charInfo.x / w; float ue = (charInfo.x + charInfo.width) / w; @@ -166,7 +169,7 @@ namespace DistanceFieldFontTest { indices.AddRange (new ushort[] { indexOffset, (ushort)(indexOffset + 1), (ushort)(indexOffset + 2), (ushort)(indexOffset + 2), (ushort)(indexOffset + 3), indexOffset }); indexOffset += 4; - float advance = charInfo.xadvance / 36.0f; + float advance = charSize * charInfo.xadvance / 36.0f; posx += advance; } @@ -197,9 +200,11 @@ namespace DistanceFieldFontTest { } void buildCommandBuffers () { + + cmdPool.Reset(); + for (int i = 0; i < swapChain.ImageCount; ++i) { - cmds[i]?.Free (); - cmds[i] = cmdPool.AllocateAndStart (); + cmds[i].Start(); recordDraw (cmds[i], frameBuffers[i]); @@ -207,7 +212,7 @@ namespace DistanceFieldFontTest { } } - void recordDraw (CommandBuffer cmd, Framebuffer fb) { + void recordDraw (CommandBuffer cmd, FrameBuffer fb) { pipeline.RenderPass.Begin (cmd, fb); cmd.SetViewport (fb.Width, fb.Height); @@ -274,21 +279,8 @@ namespace DistanceFieldFontTest { updateViewRequested = true; - if (frameBuffers != null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) { - frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height, - (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - } : new Image[] { - null, - swapChain.images[i] - }); - } + frameBuffers?.Dispose(); + frameBuffers = pipeline.RenderPass.CreateFrameBuffers(swapChain); buildCommandBuffers (); } @@ -299,8 +291,7 @@ namespace DistanceFieldFontTest { dev.WaitIdle (); pipeline.Dispose (); dsLayout.Dispose (); - for (int i = 0; i < swapChain.ImageCount; i++) - frameBuffers[i].Dispose (); + frameBuffers?.Dispose(); descriptorPool.Dispose (); fontTexture?.Dispose (); vbo.Dispose (); diff --git a/samples/Model/data/DamagedHelmet.bin b/samples/Model/data/DamagedHelmet.bin deleted file mode 100644 index 662eacc..0000000 Binary files a/samples/Model/data/DamagedHelmet.bin and /dev/null differ diff --git a/samples/Model/data/DamagedHelmet.gltf b/samples/Model/data/DamagedHelmet.gltf deleted file mode 100644 index d685d77..0000000 --- a/samples/Model/data/DamagedHelmet.gltf +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:efe99dfac198094a30c71dc02a4d3421f0eef6bf335aeb695daa4d62134cd93f -size 4537 diff --git a/samples/Model/main.cs b/samples/Model/main.cs index e60810e..dbea068 100644 --- a/samples/Model/main.cs +++ b/samples/Model/main.cs @@ -1,11 +1,14 @@ -using System.Collections.Generic; +// Copyright (c) 2019 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System.Numerics; using System.Runtime.InteropServices; -using CVKL; -using CVKL.glTF; +using vke; +using vke.glTF; using VK; -namespace ModelSample { +namespace ModelSample +{ class Program : VkWindow { static void Main (string[] args) { #if DEBUG @@ -38,7 +41,7 @@ namespace ModelSample { DescriptorSetLayout descLayoutMatrix; DescriptorSetLayout descLayoutTextures; - Framebuffer[] frameBuffers; + FrameBuffers frameBuffers; GraphicPipeline pipeline; @@ -48,10 +51,10 @@ namespace ModelSample { float rotX, rotY, rotZ = 0f, zoom = 2f; SimpleModel helmet; - CVKL.DebugUtils.Messenger dbgmsg; + vke.DebugUtils.Messenger dbgmsg; Program () : base () { - + cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); descriptorPool = new DescriptorPool (dev, 2, new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer), @@ -90,15 +93,11 @@ namespace ModelSample { pipeline = new GraphicPipeline (cfg); helmet = new SimpleModel (presentQueue, Utils.DataDirectory + "models/DamagedHelmet/glTF/DamagedHelmet.gltf"); - //helmet = new SimpleModel (presentQueue, Utils.DataDirectory + "models/Hubble.glb"); - - //helmet = new SimpleModel (presentQueue, "/mnt/devel/vulkan/Lugdunum/resources/models/Box.gltf"); dsMatrices = descriptorPool.Allocate (descLayoutMatrix); dsTextures = descriptorPool.Allocate (descLayoutTextures); uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices); - //matrices.lightPos = new Vector4 (0.0f, 0.0f, -2.0f, 1.0f); DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsMatrices, descLayoutMatrix); uboUpdate.Write (dev, uboMats.Descriptor); @@ -138,10 +137,9 @@ namespace ModelSample { } void buildCommandBuffers () { cmdPool.Reset (VkCommandPoolResetFlags.ReleaseResources); - cmds = cmdPool.AllocateCommandBuffer (swapChain.ImageCount); for (int i = 0; i < swapChain.ImageCount; ++i) { - Framebuffer fb = frameBuffers[i]; + FrameBuffer fb = frameBuffers[i]; cmds[i].Start (); pipeline.RenderPass.Begin (cmds[i], fb); @@ -168,21 +166,8 @@ namespace ModelSample { protected override void OnResize () { base.OnResize(); - if (frameBuffers != null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height, - (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - null - } : new Image[] { - null, - null, - swapChain.images[i] - }); + frameBuffers?.Dispose(); + frameBuffers = pipeline.RenderPass.CreateFrameBuffers(swapChain); buildCommandBuffers (); } @@ -205,7 +190,7 @@ namespace ModelSample { dev = transferQ.Dev; using (CommandPool cmdPool = new CommandPool (dev, transferQ.index)) { - using (CVKL.glTF.glTFLoader ctx = new CVKL.glTF.glTFLoader(path, transferQ, cmdPool)) { + using (vke.glTF.glTFLoader ctx = new vke.glTF.glTFLoader(path, transferQ, cmdPool)) { loadSolids (ctx); textures = ctx.LoadImages (); } @@ -244,8 +229,7 @@ namespace ModelSample { pipeline.Dispose (); descLayoutMatrix.Dispose (); descLayoutTextures.Dispose (); - for (int i = 0; i < swapChain.ImageCount; i++) - frameBuffers[i]?.Dispose (); + frameBuffers?.Dispose(); descriptorPool.Dispose (); uboMats.Dispose (); dbgmsg?.Dispose (); diff --git a/samples/Textured/main.cs b/samples/Textured/main.cs index 390e217..41c3454 100644 --- a/samples/Textured/main.cs +++ b/samples/Textured/main.cs @@ -2,7 +2,7 @@ using System.Numerics; using System.Runtime.InteropServices; using Glfw; -using CVKL; +using vke; using VK; namespace Textured { @@ -47,7 +47,7 @@ namespace Textured { DescriptorSet descriptorSet; GraphicPipeline pipeline; - Framebuffer[] frameBuffers; + FrameBuffers frameBuffers; Image texture; Image nextTexture; @@ -70,7 +70,8 @@ namespace Textured { Utils.DataDirectory + "textures/tex256.jpg", }; - Program () : base () { + Program () : base () { + cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); loadTexture (imgPathes[currentImgIndex]); @@ -112,16 +113,14 @@ namespace Textured { } void buildCommandBuffers () { + cmdPool.Reset(); for (int i = 0; i < swapChain.ImageCount; ++i) { - cmds[i]?.Free (); - cmds[i] = cmdPool.AllocateAndStart (); - + cmds[i].Start(); recordDraw (cmds[i], frameBuffers[i]); - cmds[i].End (); } } - void recordDraw (CommandBuffer cmd, Framebuffer fb) { + void recordDraw (CommandBuffer cmd, FrameBuffer fb) { pipeline.RenderPass.Begin (cmd, fb); cmd.SetViewport (fb.Width, fb.Height); @@ -149,7 +148,7 @@ namespace Textured { nextTexture = KTX.KTX.Load (presentQueue, cmdPool, path, VkImageUsageFlags.Sampled, imgProp, genMipMaps, tiling); else - nextTexture = Image.Load (dev, presentQueue, cmdPool, path, VkFormat.R8g8b8a8Unorm, imgProp, tiling, genMipMaps); + nextTexture = Image.Load (dev, presentQueue, cmdPool, path, VkFormat.R8g8b8a8Unorm, imgProp, tiling, genMipMaps); updateViewRequested = true; } catch (Exception ex) { Console.WriteLine (ex); @@ -223,23 +222,8 @@ namespace Textured { updateMatrices (); - if (frameBuffers!=null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) { - frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height, - (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - null - } : new Image[] { - null, - null, - swapChain.images[i] - }); - } + frameBuffers?.Dispose(); + frameBuffers = pipeline.RenderPass.CreateFrameBuffers(swapChain); buildCommandBuffers (); } @@ -250,8 +234,7 @@ namespace Textured { dev.WaitIdle (); pipeline.Dispose (); dsLayout.Dispose (); - for (int i = 0; i < swapChain.ImageCount; i++) - frameBuffers[i].Dispose (); + frameBuffers.Dispose(); descriptorPool.Dispose (); texture?.Dispose (); nextTexture?.Dispose (); diff --git a/samples/TexturedCube/main.cs b/samples/TexturedCube/main.cs index 98fd5c3..88d409e 100644 --- a/samples/TexturedCube/main.cs +++ b/samples/TexturedCube/main.cs @@ -5,9 +5,9 @@ using System; using System.Numerics; using System.Runtime.InteropServices; using Glfw; -using CVKL; +using vke; using VK; -using Buffer = CVKL.Buffer; +using Buffer = vke.Buffer; namespace TextureCube { class Program : VkWindow { @@ -38,7 +38,7 @@ namespace TextureCube { DescriptorSetLayout dsLayout; DescriptorSet descriptorSet, dsVkvg; GraphicPipeline pipeline; - Framebuffer[] frameBuffers; + FrameBuffers frameBuffers; Image texture; Image nextTexture; @@ -112,9 +112,9 @@ namespace TextureCube { #endif - - Program () : base () { + cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); + vbo = new GPUBuffer (presentQueue, cmdPool, VkBufferUsageFlags.VertexBuffer, g_vertex_buffer_data); descriptorPool = new DescriptorPool (dev, 2, @@ -162,17 +162,14 @@ namespace TextureCube { } void buildCommandBuffers () { + cmdPool.Reset(); for (int i = 0; i < swapChain.ImageCount; ++i) { - cmds[i]?.Free (); - cmds[i] = cmdPool.AllocateCommandBuffer (); cmds[i].Start (); - recordDraw (cmds[i], frameBuffers[i]); - cmds[i].End (); } } - void recordDraw (CommandBuffer cmd, Framebuffer fb) { + void recordDraw (CommandBuffer cmd, FrameBuffer fb) { pipeline.RenderPass.Begin (cmd, fb); cmd.SetViewport (fb.Width, fb.Height); @@ -277,33 +274,18 @@ namespace TextureCube { protected override void OnResize () { base.OnResize (); + dev.WaitIdle(); + #if WITH_VKVG vkvgPipeline.Resize ((int)Width, (int)Height, new DescriptorSetWrites (dsVkvg, dsLayout.Bindings[1])); #endif updateMatrices (); - if (frameBuffers!=null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) { - frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height, - (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - null - } : new Image[] { - null, - null, - swapChain.images[i] - }); - } - - buildCommandBuffers (); + frameBuffers?.Dispose(); + frameBuffers = pipeline.RenderPass.CreateFrameBuffers(swapChain); - dev.WaitIdle (); + buildCommandBuffers(); } protected override void Dispose (bool disposing) { @@ -311,8 +293,7 @@ namespace TextureCube { if (!isDisposed) { dev.WaitIdle (); pipeline.Dispose (); - for (int i = 0; i < swapChain.ImageCount; i++) - frameBuffers[i].Dispose (); + frameBuffers?.Dispose(); descriptorPool.Dispose (); texture.Dispose (); uboMats.Dispose (); diff --git a/samples/Triangle/Triangle.csproj b/samples/Triangle/Triangle.csproj index dbb4bc8..25c90c0 100644 --- a/samples/Triangle/Triangle.csproj +++ b/samples/Triangle/Triangle.csproj @@ -2,5 +2,5 @@ false - + diff --git a/samples/Triangle/main.cs b/samples/Triangle/main.cs index 2dcb68f..cb9918e 100644 --- a/samples/Triangle/main.cs +++ b/samples/Triangle/main.cs @@ -3,7 +3,7 @@ // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System.Numerics; using System.Runtime.InteropServices; -using CVKL; +using vke; using VK; namespace Triangle { @@ -48,7 +48,7 @@ namespace Triangle { DescriptorSetLayout dsLayout; DescriptorSet descriptorSet; - Framebuffer[] frameBuffers; + FrameBuffers frameBuffers; GraphicPipeline pipeline; Vertex[] vertices = { @@ -59,6 +59,9 @@ namespace Triangle { ushort[] indices = new ushort[] { 0, 1, 2 }; Program () : base () { + + cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); + vbo = new HostBuffer (dev, VkBufferUsageFlags.VertexBuffer, vertices); ibo = new HostBuffer (dev, VkBufferUsageFlags.IndexBuffer, indices); uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices); @@ -115,10 +118,9 @@ namespace Triangle { } void buildCommandBuffers() { cmdPool.Reset (VkCommandPoolResetFlags.ReleaseResources); - cmds = cmdPool.AllocateCommandBuffer (swapChain.ImageCount); for (int i = 0; i < swapChain.ImageCount; ++i) { - Framebuffer fb = frameBuffers[i]; + FrameBuffer fb = frameBuffers[i]; cmds[i].Start (); pipeline.RenderPass.Begin (cmds[i], fb); @@ -143,19 +145,8 @@ namespace Triangle { protected override void OnResize () { base.OnResize (); - if (frameBuffers != null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height, - (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - } : new Image[] { - null, - swapChain.images[i] - }); + frameBuffers?.Dispose(); + frameBuffers = pipeline.RenderPass.CreateFrameBuffers(swapChain); buildCommandBuffers (); } @@ -165,8 +156,8 @@ namespace Triangle { if (disposing) { if (!isDisposed) { pipeline.Dispose (); - for (int i = 0; i < swapChain.ImageCount; i++) - frameBuffers[i].Dispose (); + + frameBuffers?.Dispose(); descriptorPool.Dispose (); vbo.Dispose (); ibo.Dispose (); diff --git a/samples/common/CrowWin.cs b/samples/common/CrowWin.cs index 0a9809e..d7d9f8a 100644 --- a/samples/common/CrowWin.cs +++ b/samples/common/CrowWin.cs @@ -4,7 +4,7 @@ using VK; using System.Threading; namespace Crow { - public class CrowWin : CVKL.VkWindow, IValueChange { + public class CrowWin : vke.VkWindow, IValueChange { #region IValueChange implementation public event EventHandler ValueChanged; public virtual void NotifyValueChanged (string MemberName, object _value) { @@ -13,16 +13,16 @@ namespace Crow { } #endregion - CVKL.DescriptorPool descriptorPool; - CVKL.DescriptorSetLayout descLayout; - CVKL.DescriptorSet dsCrow; + vke.DescriptorPool descriptorPool; + vke.DescriptorSetLayout descLayout; + vke.DescriptorSet dsCrow; - CVKL.GraphicPipeline uiPipeline; - CVKL.Framebuffer[] uiFrameBuffers; + vke.GraphicPipeline uiPipeline; + vke.FrameBuffer[] uiFrameBuffers; protected Interface crow; protected vkvg.Device vkvgDev; - protected CVKL.Image uiImage; + protected vke.Image uiImage; protected bool isRunning, rebuildBuffers; protected CrowWin (string name = "CrowWin", uint _width = 1024, uint _height = 768, bool vSync = false) : @@ -57,27 +57,27 @@ namespace Crow { } void initUIPipeline (VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1) { - descriptorPool = new CVKL.DescriptorPool (dev, 1, new VkDescriptorPoolSize (VkDescriptorType.CombinedImageSampler)); - descLayout = new CVKL.DescriptorSetLayout (dev, + descriptorPool = new vke.DescriptorPool (dev, 1, new VkDescriptorPoolSize (VkDescriptorType.CombinedImageSampler)); + descLayout = new vke.DescriptorSetLayout (dev, new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); - CVKL.GraphicPipelineConfig cfg = CVKL.GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, samples, false); - cfg.Layout = new CVKL.PipelineLayout (dev, descLayout); - cfg.RenderPass = new CVKL.RenderPass (dev, swapChain.ColorFormat, samples); + vke.GraphicPipelineConfig cfg = vke.GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, samples, false); + cfg.Layout = new vke.PipelineLayout (dev, descLayout); + cfg.RenderPass = new vke.RenderPass (dev, swapChain.ColorFormat, samples); cfg.AddShader (VkShaderStageFlags.Vertex, "#deferred.FullScreenQuad.vert.spv"); cfg.AddShader (VkShaderStageFlags.Fragment, "#deferred.simpletexture.frag.spv"); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState (true); - uiPipeline = new CVKL.GraphicPipeline (cfg); + uiPipeline = new vke.GraphicPipeline (cfg); dsCrow = descriptorPool.Allocate (descLayout); } void initUISurface () { lock (crow.UpdateMutex) { uiImage?.Dispose (); - uiImage = new CVKL.Image (dev, new VkImage ((ulong)crow.surf.VkImage.ToInt64 ()), VkFormat.B8g8r8a8Unorm, + uiImage = new vke.Image (dev, new VkImage ((ulong)crow.surf.VkImage.ToInt64 ()), VkFormat.B8g8r8a8Unorm, VkImageUsageFlags.Sampled, swapChain.Width, swapChain.Height); uiImage.SetName ("uiImage"); uiImage.CreateView (VkImageViewType.ImageView2D, VkImageAspectFlags.Color); @@ -119,14 +119,14 @@ namespace Crow { System.Diagnostics.Debug.WriteLine (ex.ToString ()); } } - protected virtual void recordDraw (CVKL.CommandBuffer cmd, int imageIndex) { } + protected virtual void recordDraw (vke.CommandBuffer cmd, int imageIndex) { } void buildCommandBuffers () { for (int i = 0; i < swapChain.ImageCount; ++i) { cmds[i]?.Free (); cmds[i] = cmdPool.AllocateAndStart (); - CVKL.CommandBuffer cmd = cmds[i]; + vke.CommandBuffer cmd = cmds[i]; recordDraw (cmd, i); @@ -166,20 +166,20 @@ namespace Crow { initUISurface (); - CVKL.DescriptorSetWrites uboUpdate = new CVKL.DescriptorSetWrites (dsCrow, descLayout); + vke.DescriptorSetWrites uboUpdate = new vke.DescriptorSetWrites (dsCrow, descLayout); uboUpdate.Write (dev, uiImage.Descriptor); if (uiFrameBuffers != null) for (int i = 0; i < swapChain.ImageCount; ++i) uiFrameBuffers[i]?.Dispose (); - uiFrameBuffers = new CVKL.Framebuffer[swapChain.ImageCount]; + uiFrameBuffers = new vke.FrameBuffer[swapChain.ImageCount]; for (int i = 0; i < swapChain.ImageCount; ++i) { - uiFrameBuffers[i] = new CVKL.Framebuffer (uiPipeline.RenderPass, swapChain.Width, swapChain.Height, - (uiPipeline.Samples == VkSampleCountFlags.SampleCount1) ? new CVKL.Image[] { + uiFrameBuffers[i] = new vke.FrameBuffer (uiPipeline.RenderPass, swapChain.Width, swapChain.Height, + (uiPipeline.Samples == VkSampleCountFlags.SampleCount1) ? new vke.Image[] { swapChain.images[i], - } : new CVKL.Image[] { + } : new vke.Image[] { null, swapChain.images[i] }); diff --git a/samples/compute/delaunay.cs b/samples/compute/delaunay.cs index a01cd85..aba1418 100644 --- a/samples/compute/delaunay.cs +++ b/samples/compute/delaunay.cs @@ -1,7 +1,7 @@ using System; using Glfw; using VK; -using CVKL; +using vke; namespace delaunay { class Program : VkWindow { @@ -16,7 +16,7 @@ namespace delaunay { } } - Framebuffer[] frameBuffers; + FrameBuffer[] frameBuffers; GraphicPipeline grPipeline; Image imgResult; @@ -136,10 +136,10 @@ namespace delaunay { if (frameBuffers != null) for (int i = 0; i < swapChain.ImageCount; ++i) frameBuffers[i]?.Dispose (); - frameBuffers = new Framebuffer[swapChain.ImageCount]; + frameBuffers = new FrameBuffer[swapChain.ImageCount]; for (int i = 0; i < swapChain.ImageCount; ++i) { - frameBuffers[i] = new Framebuffer (grPipeline.RenderPass, swapChain.Width, swapChain.Height, + frameBuffers[i] = new FrameBuffer (grPipeline.RenderPass, swapChain.Width, swapChain.Height, (grPipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { swapChain.images[i], null diff --git a/samples/deferred/DeferredPbrRenderer.cs b/samples/deferred/DeferredPbrRenderer.cs index 3dc8520..540de6a 100644 --- a/samples/deferred/DeferredPbrRenderer.cs +++ b/samples/deferred/DeferredPbrRenderer.cs @@ -1,8 +1,8 @@ using System; using System.Numerics; using System.Runtime.InteropServices; -using CVKL; -using CVKL.glTF; +using vke; +using vke.glTF; using VK; namespace deferred { @@ -66,7 +66,7 @@ namespace deferred { }*/ }; - Framebuffer frameBuffer; + FrameBuffer frameBuffer; public Image gbColorRough, gbEmitMetal, gbN_AO, gbPos, hdrImgResolved, hdrImgMS; DescriptorPool descriptorPool; @@ -484,9 +484,9 @@ namespace deferred { createGBuff (); frameBuffer = (NUM_SAMPLES == VkSampleCountFlags.SampleCount1) ? - new Framebuffer (renderPass, width, height, new Image[] { + new FrameBuffer (renderPass, width, height, new Image[] { hdrImgResolved, null, gbColorRough, gbEmitMetal, gbN_AO, gbPos}) : - new Framebuffer (renderPass, width, height, new Image[] { + new FrameBuffer (renderPass, width, height, new Image[] { hdrImgResolved, null, gbColorRough, gbEmitMetal, gbN_AO, gbPos, hdrImgMS}); } diff --git a/samples/deferred/EnvironmentPipeline.cs b/samples/deferred/EnvironmentPipeline.cs index 4e97a1c..0716c01 100644 --- a/samples/deferred/EnvironmentPipeline.cs +++ b/samples/deferred/EnvironmentPipeline.cs @@ -4,7 +4,7 @@ using System.Numerics; using System.Runtime.InteropServices; using VK; -namespace CVKL { +namespace vke { public class EnvironmentCube : GraphicPipeline { GPUBuffer vboSkybox; @@ -123,7 +123,7 @@ namespace CVKL { cfg.AddShader (VkShaderStageFlags.Fragment, "#deferred.genbrdflut.frag.spv"); using (GraphicPipeline pl = new GraphicPipeline (cfg)) { - using (Framebuffer fb = new Framebuffer (cfg.RenderPass, dim, dim, lutBrdf)) { + using (FrameBuffer fb = new FrameBuffer (cfg.RenderPass, dim, dim, lutBrdf)) { CommandBuffer cmd = cmdPool.AllocateCommandBuffer (); cmd.Start (VkCommandBufferUsageFlags.OneTimeSubmit); pl.RenderPass.Begin (cmd, fb); @@ -223,7 +223,7 @@ namespace CVKL { dsUpdate.Write (Dev, dset, cubemap.Descriptor); Dev.WaitIdle (); - using (Framebuffer fb = new Framebuffer (pl.RenderPass, dim, dim, imgFbOffscreen)) { + using (FrameBuffer fb = new FrameBuffer (pl.RenderPass, dim, dim, imgFbOffscreen)) { CommandBuffer cmd = cmdPool.AllocateCommandBuffer (); cmd.Start (VkCommandBufferUsageFlags.OneTimeSubmit); diff --git a/samples/deferred/main-crow.cs b/samples/deferred/main-crow.cs index e5c5598..2a2301b 100644 --- a/samples/deferred/main-crow.cs +++ b/samples/deferred/main-crow.cs @@ -2,7 +2,7 @@ using System.Numerics; using Glfw; using VK; -using CVKL; +using vke; using System.Collections.Generic; using System.Linq; diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs index 8ad5dbe..4638661 100644 --- a/samples/deferred/main.cs +++ b/samples/deferred/main.cs @@ -1,8 +1,8 @@ using System; using System.Numerics; using System.Runtime.InteropServices; -using CVKL; -using CVKL.glTF; +using vke; +using vke.glTF; using Glfw; using VK; @@ -71,7 +71,7 @@ namespace deferred { GraphicPipeline plToneMap; - Framebuffer[] frameBuffers; + FrameBuffers frameBuffers; DescriptorPool descriptorPool; DescriptorSet descriptorSet; @@ -203,8 +203,8 @@ namespace deferred { } - CommandBuffer cmdPbr; - CommandBuffer cmdBlur; + //CommandBuffer cmdPbr; + //CommandBuffer cmdBlur; VkSemaphore blurComplete; const uint downSizing = 1; float finalDebug = -1.0f; @@ -322,21 +322,8 @@ namespace deferred { pcBloom.texSize.X = downSamp.Width; pcBloom.texSize.Y = downSamp.Height; - if (frameBuffers != null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) { - frameBuffers[i] = new Framebuffer (plToneMap.RenderPass, swapChain.Width, swapChain.Height, - (plToneMap.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - } : new Image[] { - null, - swapChain.images[i] - }); - } + frameBuffers?.Dispose(); + frameBuffers = plToneMap.RenderPass.CreateFrameBuffers(swapChain); DescriptorSetWrites dsUpdate = new DescriptorSetWrites (plToneMap.Layout.DescriptorSetLayouts[0]); dsUpdate.Write (dev, descriptorSet, renderer.hdrImgResolved.Descriptor, downSamp.Descriptor); @@ -530,9 +517,7 @@ namespace deferred { computeCmdPool.Dispose (); downSamp?.Dispose (); downSamp2?.Dispose (); - if (frameBuffers != null) - foreach (Framebuffer fb in frameBuffers) - fb.Dispose (); + frameBuffers?.Dispose(); renderer.Dispose (); plBlur.Dispose (); plToneMap.Dispose (); diff --git a/samples/deferred/shadowMapRenderer.cs b/samples/deferred/shadowMapRenderer.cs index a4684ec..60da378 100644 --- a/samples/deferred/shadowMapRenderer.cs +++ b/samples/deferred/shadowMapRenderer.cs @@ -6,8 +6,8 @@ using System; using System.Numerics; using System.Runtime.InteropServices; -using CVKL; -using CVKL.glTF; +using vke; +using vke.glTF; using VK; using static deferred.DeferredPbrRenderer; @@ -29,7 +29,7 @@ namespace deferred { RenderPass shadowPass; - Framebuffer fbShadowMap; + FrameBuffer fbShadowMap; public Image shadowMap { get; private set; } Pipeline shadowPipeline; DescriptorPool descriptorPool; @@ -99,7 +99,7 @@ namespace deferred { shadowMap.CreateSampler (VkSamplerAddressMode.ClampToBorder); shadowMap.Descriptor.imageLayout = VkImageLayout.DepthStencilReadOnlyOptimal; - fbShadowMap = new Framebuffer (shadowPass, SHADOWMAP_SIZE, SHADOWMAP_SIZE, (uint)renderer.lights.Length); + fbShadowMap = new FrameBuffer (shadowPass, SHADOWMAP_SIZE, SHADOWMAP_SIZE, (uint)renderer.lights.Length); fbShadowMap.attachments.Add (shadowMap); fbShadowMap.Activate (); diff --git a/samples/pbr/EnvironmentPipeline.cs b/samples/pbr/EnvironmentPipeline.cs index 7b5428e..06636f7 100644 --- a/samples/pbr/EnvironmentPipeline.cs +++ b/samples/pbr/EnvironmentPipeline.cs @@ -4,7 +4,7 @@ using System.Numerics; using System.Runtime.InteropServices; using VK; -namespace CVKL { +namespace vke { class EnvironmentCube : GraphicPipeline { GPUBuffer vboSkybox; @@ -138,7 +138,7 @@ namespace CVKL { cfg.AddShader (VkShaderStageFlags.Fragment, "#pbr.genbrdflut.frag.spv"); using (GraphicPipeline pl = new GraphicPipeline (cfg)) { - using (Framebuffer fb = new Framebuffer (cfg.RenderPass, dim, dim, lutBrdf)) { + using (FrameBuffer fb = new FrameBuffer (cfg.RenderPass, dim, dim, lutBrdf)) { CommandBuffer cmd = cmdPool.AllocateCommandBuffer (); cmd.Start (VkCommandBufferUsageFlags.OneTimeSubmit); pl.RenderPass.Begin (cmd, fb); @@ -237,7 +237,7 @@ namespace CVKL { DescriptorSetWrites dsUpdate = new DescriptorSetWrites (dsLayout); dsUpdate.Write (Dev, dset, cubemap.Descriptor); - using (Framebuffer fb = new Framebuffer (pl.RenderPass, dim, dim, imgFbOffscreen)) { + using (FrameBuffer fb = new FrameBuffer (pl.RenderPass, dim, dim, imgFbOffscreen)) { CommandBuffer cmd = cmdPool.AllocateCommandBuffer (); cmd.Start (VkCommandBufferUsageFlags.OneTimeSubmit); diff --git a/samples/pbr/PbrModel.cs b/samples/pbr/PbrModel.cs index a48fe11..e4a516d 100644 --- a/samples/pbr/PbrModel.cs +++ b/samples/pbr/PbrModel.cs @@ -6,8 +6,8 @@ using System.Runtime.InteropServices; using VK; -namespace CVKL { - using CVKL.glTF; +namespace vke { + using vke.glTF; //TODO:stride in buffer views? diff --git a/samples/pbr/PbrPipeline.cs b/samples/pbr/PbrPipeline.cs index a8d3fae..94abe09 100644 --- a/samples/pbr/PbrPipeline.cs +++ b/samples/pbr/PbrPipeline.cs @@ -7,7 +7,7 @@ using System.Numerics; using System.Runtime.InteropServices; using VK; -namespace CVKL { +namespace vke { class PBRPipeline : GraphicPipeline { public struct Matrices { diff --git a/samples/pbr/main.cs b/samples/pbr/main.cs index 0a0cd35..35d9db7 100644 --- a/samples/pbr/main.cs +++ b/samples/pbr/main.cs @@ -10,7 +10,7 @@ using System.Numerics; using System.Runtime.InteropServices; using Glfw; using VK; -using CVKL; +using vke; namespace pbrSample { class Program : VkWindow{ @@ -35,7 +35,7 @@ namespace pbrSample { VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1; - Framebuffer[] frameBuffers; + FrameBuffers frameBuffers; PBRPipeline pbrPipeline; enum DebugView { @@ -193,7 +193,7 @@ namespace pbrSample { cmds[i].End (); } } - void recordDraw (CommandBuffer cmd, Framebuffer fb) { + void recordDraw (CommandBuffer cmd, FrameBuffer fb) { pbrPipeline.RenderPass.Begin (cmd, fb); cmd.SetViewport (fb.Width, fb.Height); @@ -257,23 +257,8 @@ namespace pbrSample { UpdateView (); - if (frameBuffers != null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) { - frameBuffers[i] = new Framebuffer (pbrPipeline.RenderPass, swapChain.Width, swapChain.Height, - (pbrPipeline.RenderPass.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - null - } : new Image[] { - null, - null, - swapChain.images[i] - }); - } + frameBuffers?.Dispose(); + frameBuffers = pbrPipeline.RenderPass.CreateFrameBuffers(swapChain); buildCommandBuffers (); dev.WaitIdle (); @@ -411,9 +396,7 @@ namespace pbrSample { if (disposing) { if (!isDisposed) { dev.WaitIdle (); - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - + frameBuffers?.Dispose(); pbrPipeline.Dispose (); #if WITH_VKVG vkvgPipeline.Dispose (); diff --git a/samples/pbr/pbr.csproj b/samples/pbr/pbr.csproj index acc948d..c3fa145 100644 --- a/samples/pbr/pbr.csproj +++ b/samples/pbr/pbr.csproj @@ -6,8 +6,8 @@ - vke.simpletexture.frag.spv - + vke.simpletexture.frag.spv + diff --git a/vke.net.sln b/vke.net.sln index 815782b..2193466 100644 --- a/vke.net.sln +++ b/vke.net.sln @@ -29,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TexturedCube", "samples\Tex EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Triangle", "samples\Triangle\Triangle.csproj", "{A30AEC45-54A3-4120-B341-B3299CC1B00E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpirVTasks", "SpirVTasks\SpirVTasks.csproj", "{7B05B5A7-49E2-4D05-BEF8-734F70CDBF17}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -108,6 +110,12 @@ Global {A30AEC45-54A3-4120-B341-B3299CC1B00E}.Release|Any CPU.Build.0 = Release|Any CPU {A30AEC45-54A3-4120-B341-B3299CC1B00E}.DebugCrow|Any CPU.ActiveCfg = Debug|Any CPU {A30AEC45-54A3-4120-B341-B3299CC1B00E}.DebugCrow|Any CPU.Build.0 = Debug|Any CPU + {7B05B5A7-49E2-4D05-BEF8-734F70CDBF17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B05B5A7-49E2-4D05-BEF8-734F70CDBF17}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7B05B5A7-49E2-4D05-BEF8-734F70CDBF17}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7B05B5A7-49E2-4D05-BEF8-734F70CDBF17}.Release|Any CPU.Build.0 = Release|Any CPU + {7B05B5A7-49E2-4D05-BEF8-734F70CDBF17}.DebugCrow|Any CPU.ActiveCfg = Debug|Any CPU + {7B05B5A7-49E2-4D05-BEF8-734F70CDBF17}.DebugCrow|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {FEF3AF30-5B88-4D3C-8BD7-8734200E0D1E} = {4AA67AB0-C331-4CB2-9C00-B74F5DE31658} @@ -122,4 +130,10 @@ Global {8185163E-A67C-4C0E-8548-67E2A9F16309} = {16439374-B8DB-4643-8116-EB3358B49A12} {A30AEC45-54A3-4120-B341-B3299CC1B00E} = {16439374-B8DB-4643-8116-EB3358B49A12} EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + Policies = $0 + $0.TextStylePolicy = $1 + $1.FileWidth = 80 + $1.scope = text/x-cgsrc + EndGlobalSection EndGlobal diff --git a/vke/src/Camera.cs b/vke/src/Camera.cs index 0410e0e..ac6aa29 100644 --- a/vke/src/Camera.cs +++ b/vke/src/Camera.cs @@ -3,7 +3,7 @@ // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System.Numerics; -namespace CVKL { +namespace vke { public class Camera { /// Corection matrix for vulkan projection public static readonly Matrix4x4 VKProjectionCorrection = diff --git a/vke/src/ExtensionMethods.cs b/vke/src/ExtensionMethods.cs index 287e887..34c1740 100644 --- a/vke/src/ExtensionMethods.cs +++ b/vke/src/ExtensionMethods.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public static class ExtensionMethods { /// /// Extensions method to check byte array equality. diff --git a/vke/src/FrameBuffers.cs b/vke/src/FrameBuffers.cs new file mode 100644 index 0000000..7b5a567 --- /dev/null +++ b/vke/src/FrameBuffers.cs @@ -0,0 +1,20 @@ +// Copyright (c) 2019 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +using System; +using System.Collections.ObjectModel; + +namespace vke +{ + public class FrameBuffers : Collection, IDisposable + { + //public Framebuffer this[int index] => Items[index]; + + public void Dispose() + { + foreach (FrameBuffer fb in Items) + fb.Dispose(); + ClearItems(); + } + } +} diff --git a/vke/src/MarshaledObject.cs b/vke/src/MarshaledObject.cs index 231e69a..f6dd178 100644 --- a/vke/src/MarshaledObject.cs +++ b/vke/src/MarshaledObject.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.InteropServices; -namespace CVKL { +namespace vke { public class MarshaledObject : IDisposable where T : struct { GCHandle handle; diff --git a/vke/src/MemoryPool.cs b/vke/src/MemoryPool.cs index 2fbc8d8..6706c49 100644 --- a/vke/src/MemoryPool.cs +++ b/vke/src/MemoryPool.cs @@ -6,7 +6,7 @@ using VK; using static VK.Vk; -namespace CVKL { +namespace vke { #if MEMORY_POOLS public enum MemoryPoolType { Random, @@ -57,7 +57,11 @@ namespace CVKL { if (previous != null) { do { offset = previous.poolOffset + previous.AllocatedDeviceMemorySize; - offset += resource.MemoryAlignment - (offset % resource.MemoryAlignment); + + if (previous.IsLinar != resource.IsLinar && offset % dev.BufferImageGranularity > 0) + offset += dev.BufferImageGranularity - (offset % dev.BufferImageGranularity); + if (offset % resource.MemoryAlignment > 0) + offset += resource.MemoryAlignment - (offset % resource.MemoryAlignment); if (previous.next == null) { if (offset + resource.AllocatedDeviceMemorySize >= limit) { diff --git a/vke/src/ResourceManager.cs b/vke/src/ResourceManager.cs index c6bbd22..c01afda 100644 --- a/vke/src/ResourceManager.cs +++ b/vke/src/ResourceManager.cs @@ -1,7 +1,7 @@ using System; using VK; -namespace CVKL { +namespace vke { #if MEMORY_POOLS /// /// Resource manager is responsible for the memory allocations. It holds one pool for each memory type diff --git a/vke/src/ShaderInfo.cs b/vke/src/ShaderInfo.cs index 1058830..0762801 100644 --- a/vke/src/ShaderInfo.cs +++ b/vke/src/ShaderInfo.cs @@ -4,7 +4,7 @@ using System; using VK; -namespace CVKL { +namespace vke { /// /// This class is a helper class for VkPipelineShaderStageCreateInfo creation. /// diff --git a/vke/src/SpecializationConstant.cs b/vke/src/SpecializationConstant.cs index b455cca..91d4356 100644 --- a/vke/src/SpecializationConstant.cs +++ b/vke/src/SpecializationConstant.cs @@ -28,7 +28,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using VK; -namespace CVKL { +namespace vke { /// /// Hold shader specialization constant value and type /// diff --git a/vke/src/StbImage.cs b/vke/src/StbImage.cs index 3ea1d7f..208b4a5 100644 --- a/vke/src/StbImage.cs +++ b/vke/src/StbImage.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.InteropServices; -namespace CVKL { +namespace vke { public class StbImage : IDisposable { const string stblib = "stb"; diff --git a/vke/src/Utils.cs b/vke/src/Utils.cs index 9205b97..3ac8928 100644 --- a/vke/src/Utils.cs +++ b/vke/src/Utils.cs @@ -285,5 +285,58 @@ namespace VK { break; } } - } + public static bool TryGetCompressedFormatBlockSize (this VkFormat format, out uint width, out uint height) + { + width = height = 1; + if (format < VkFormat.Bc1RgbUnormBlock || format > (VkFormat)1000066013) //VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK_EXT) + return false; + if (format < VkFormat.Astc5x4UnormBlock) + width = height = 4; + else { + string str = format.ToString (); + if (str.StartsWith ("Astc", StringComparison.OrdinalIgnoreCase)) { + width = uint.Parse (str.Substring (4, 1)); + height = uint.Parse (str.Substring (6, 1)); + } + } + + return true; + } + //TODO:quick done list, refine needed + public static VkPipelineStageFlags GetDefaultStage (this VkImageLayout layout) { + switch (layout) { + case VkImageLayout.Preinitialized: + case VkImageLayout.Undefined: + return VkPipelineStageFlags.AllCommands; + + case VkImageLayout.General: + return VkPipelineStageFlags.ComputeShader; + + case VkImageLayout.ColorAttachmentOptimal: + case VkImageLayout.DepthStencilAttachmentOptimal: + return VkPipelineStageFlags.ColorAttachmentOutput; + + case VkImageLayout.DepthStencilReadOnlyOptimal: + case VkImageLayout.DepthReadOnlyStencilAttachmentOptimalKHR: + case VkImageLayout.DepthAttachmentStencilReadOnlyOptimalKHR: + return VkPipelineStageFlags.EarlyFragmentTests; + + case VkImageLayout.ShaderReadOnlyOptimal: + return VkPipelineStageFlags.FragmentShader; + + case VkImageLayout.TransferSrcOptimal: + case VkImageLayout.TransferDstOptimal: + return VkPipelineStageFlags.Transfer; + + case VkImageLayout.PresentSrcKHR: + case VkImageLayout.SharedPresentKHR: + return VkPipelineStageFlags.ColorAttachmentOutput; + + //case VkImageLayout.ShadingRateOptimalNV: + //case VkImageLayout.FragmentDensityMapOptimalEXT: + default: + return VkPipelineStageFlags.AllCommands; + } + } + } } diff --git a/vke/src/VkWindow.cs b/vke/src/VkWindow.cs index 3207574..1258208 100644 --- a/vke/src/VkWindow.cs +++ b/vke/src/VkWindow.cs @@ -9,7 +9,7 @@ using Glfw; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Base class to build vulkan application. /// Provide default swapchain with its command pool and buffers per image and the main present queue diff --git a/vke/src/base/Activable.cs b/vke/src/base/Activable.cs index b77443c..28a82ee 100644 --- a/vke/src/base/Activable.cs +++ b/vke/src/base/Activable.cs @@ -1,33 +1,11 @@ -// -// Activable.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// 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 VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Tristate status of activables, reflecting vulkan openrations /// diff --git a/vke/src/base/Buffer.cs b/vke/src/base/Buffer.cs index 254d547..8af3517 100644 --- a/vke/src/base/Buffer.cs +++ b/vke/src/base/Buffer.cs @@ -5,7 +5,7 @@ using System; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Base class for HostBuffer and GPUBuffer @@ -17,7 +17,8 @@ namespace CVKL { public VkDescriptorBufferInfo Descriptor; public VkBuffer Handle => handle; public VkBufferCreateInfo Infos => createInfo; - + public override bool IsLinar => true; + protected override VkDebugMarkerObjectNameInfoEXT DebugMarkerInfo => new VkDebugMarkerObjectNameInfoEXT(VkDebugReportObjectTypeEXT.BufferEXT, handle.Handle); @@ -67,9 +68,7 @@ namespace CVKL { } public void CopyTo (CommandBuffer cmd, Image img, VkImageLayout finalLayout = VkImageLayout.ShaderReadOnlyOptimal) { - img.SetLayout (cmd, VkImageAspectFlags.Color, - VkImageLayout.Undefined, VkImageLayout.TransferDstOptimal, - VkPipelineStageFlags.AllCommands, VkPipelineStageFlags.Transfer); + img.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.TransferDstOptimal); VkBufferImageCopy bufferCopyRegion = new VkBufferImageCopy { imageExtent = img.CreateInfo.extent, @@ -78,10 +77,8 @@ namespace CVKL { vkCmdCopyBufferToImage (cmd.Handle, handle, img.handle, VkImageLayout.TransferDstOptimal, 1, ref bufferCopyRegion); - img.SetLayout (cmd, VkImageAspectFlags.Color, - VkImageLayout.TransferDstOptimal, finalLayout, - VkPipelineStageFlags.Transfer, VkPipelineStageFlags.Transfer); - } + img.SetLayout (cmd, VkImageAspectFlags.Color, finalLayout); + } public void CopyTo (CommandBuffer cmd, Buffer buff, ulong size = 0, ulong srcOffset = 0, ulong dstOffset = 0) { VkBufferCopy bufferCopy = new VkBufferCopy { size = (size == 0) ? AllocatedDeviceMemorySize : size, diff --git a/vke/src/base/CommandBuffer.cs b/vke/src/base/CommandBuffer.cs index 0c381a7..9a22158 100644 --- a/vke/src/base/CommandBuffer.cs +++ b/vke/src/base/CommandBuffer.cs @@ -8,7 +8,7 @@ using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Command buffers are objects used to record commands which can be subsequently submitted to a device queue for execution. /// There are two levels of command buffers @@ -92,7 +92,13 @@ namespace CVKL { VkRect2D scissor = new VkRect2D (offsetX, offsetY, width, height); vkCmdSetScissor (handle, 0, 1, ref scissor); } - public void BindPipeline (Pipeline pipeline, VkPipelineBindPoint bindPoint) { + //TODO:update generator to handle float array in this command + public void SetBlendConstants (float r, float g, float b, float a) + { + throw new NotImplementedException(); + //vkCmdSetBlendConstants(handle, ); + } + public void BindPipeline (Pipeline pipeline, VkPipelineBindPoint bindPoint) { vkCmdBindPipeline (handle, bindPoint, pipeline.Handle); } public void Dispatch (uint groupCountX, uint groupCountY = 1, uint groupCountZ = 1) { diff --git a/vke/src/base/CommandPool.cs b/vke/src/base/CommandPool.cs index 3317733..6be3e0a 100644 --- a/vke/src/base/CommandPool.cs +++ b/vke/src/base/CommandPool.cs @@ -7,7 +7,7 @@ using System.Runtime.InteropServices; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Command pools are opaque objects that command buffer memory is allocated from, and which allow the implementation /// to amortize the cost of resource creation across multiple command buffers. diff --git a/vke/src/base/ComputePipeline.cs b/vke/src/base/ComputePipeline.cs index e57a7d0..c8d9f13 100644 --- a/vke/src/base/ComputePipeline.cs +++ b/vke/src/base/ComputePipeline.cs @@ -27,7 +27,7 @@ using System; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public sealed class ComputePipeline : Pipeline { public string SpirVPath; diff --git a/vke/src/base/DebuDrawPipeline.cs b/vke/src/base/DebuDrawPipeline.cs index c974416..43aae95 100644 --- a/vke/src/base/DebuDrawPipeline.cs +++ b/vke/src/base/DebuDrawPipeline.cs @@ -3,7 +3,7 @@ using System.Numerics; using System.Runtime.InteropServices; using VK; -namespace CVKL { +namespace vke { public class DebugDrawPipeline : GraphicPipeline { public HostBuffer Vertices; uint vertexCount; @@ -54,7 +54,7 @@ namespace CVKL { Vertices.Update (data, 12 * sizeof (float), (lineNum-1) * 2 * 6 * sizeof (float)); } - public void RecordDraw (CommandBuffer cmd, Framebuffer fb, Matrix4x4 projection, Matrix4x4 view) { + public void RecordDraw (CommandBuffer cmd, FrameBuffer fb, Matrix4x4 projection, Matrix4x4 view) { //cmd.SetViewport (fb.Width/ratio, fb.Height/ratio, (ratio-1) * (int)fb.Width / ratio, (ratio-1) * (int)fb.Height / ratio); //cmd.SetViewport (200, 200,100,100,-10,10);//, 4 * (int)fb.Width / 5, 4 * (int)fb.Height / 5); diff --git a/vke/src/base/DebugReport.cs b/vke/src/base/DebugReport.cs index 3bda80b..d1ce888 100644 --- a/vke/src/base/DebugReport.cs +++ b/vke/src/base/DebugReport.cs @@ -28,7 +28,7 @@ using System.Runtime.InteropServices; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public class DebugReport : IDisposable { VkDebugReportCallbackEXT handle; diff --git a/vke/src/base/DebugUtilsMessenger.cs b/vke/src/base/DebugUtilsMessenger.cs index b048c36..58c8187 100644 --- a/vke/src/base/DebugUtilsMessenger.cs +++ b/vke/src/base/DebugUtilsMessenger.cs @@ -3,7 +3,7 @@ using System.Runtime.InteropServices; using VK; using static VK.Vk; -namespace CVKL.DebugUtils { +namespace vke.DebugUtils { public class Messenger : IDisposable { Instance inst; diff --git a/vke/src/base/DescriptorPool.cs b/vke/src/base/DescriptorPool.cs index 6c9f9c4..7f0cde2 100644 --- a/vke/src/base/DescriptorPool.cs +++ b/vke/src/base/DescriptorPool.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public sealed class DescriptorPool : Activable { internal VkDescriptorPool handle; public readonly uint MaxSets; diff --git a/vke/src/base/DescriptorSet.cs b/vke/src/base/DescriptorSet.cs index 19b231c..3048228 100644 --- a/vke/src/base/DescriptorSet.cs +++ b/vke/src/base/DescriptorSet.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using VK; -namespace CVKL { +namespace vke { public class DescriptorSet { internal VkDescriptorSet handle; public VkDescriptorSet Handle => handle; diff --git a/vke/src/base/DescriptorSetLayout.cs b/vke/src/base/DescriptorSetLayout.cs index f63e5e2..1113adc 100644 --- a/vke/src/base/DescriptorSetLayout.cs +++ b/vke/src/base/DescriptorSetLayout.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Descriptor set layout, automatically activated when used in pipeline creation, so don't allocate descriptor sets using /// this layout unless it has been activated. diff --git a/vke/src/base/DescriptorSetWrites.cs b/vke/src/base/DescriptorSetWrites.cs index b47d7d0..cbacae6 100644 --- a/vke/src/base/DescriptorSetWrites.cs +++ b/vke/src/base/DescriptorSetWrites.cs @@ -29,7 +29,7 @@ using System.Runtime.InteropServices; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Descriptor set writes is defined once, then update affect descriptors to write array /// diff --git a/vke/src/base/Device.cs b/vke/src/base/Device.cs index 299b288..fcb8734 100644 --- a/vke/src/base/Device.cs +++ b/vke/src/base/Device.cs @@ -33,7 +33,7 @@ using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Logical device encapsulating vulkan logical device handle. Implements only IDisposable an do not derive from /// Activable, so it may be activated only once and no reference counting on it is handled, and no reactivation is posible @@ -45,6 +45,7 @@ namespace CVKL { VkDevice dev; public VkDevice VkDev => dev; public IntPtr Handle => dev.Handle; + public readonly ulong BufferImageGranularity; internal List queues = new List (); internal bool debugMarkersEnabled; @@ -55,6 +56,7 @@ namespace CVKL { public Device (PhysicalDevice _phy) { phy = _phy; + BufferImageGranularity = phy.Limits.bufferImageGranularity; } public void Activate (VkPhysicalDeviceFeatures enabledFeatures, params string[] extensions) { diff --git a/vke/src/base/FrameBuffer.cs b/vke/src/base/FrameBuffer.cs index 2f668e0..2b73e7f 100644 --- a/vke/src/base/FrameBuffer.cs +++ b/vke/src/base/FrameBuffer.cs @@ -30,9 +30,9 @@ using VK; using static VK.Vk; -namespace CVKL { +namespace vke { - public class Framebuffer : Activable { + public class FrameBuffer : Activable { internal VkFramebuffer handle; RenderPass renderPass; @@ -47,15 +47,21 @@ namespace CVKL { => new VkDebugMarkerObjectNameInfoEXT(VkDebugReportObjectTypeEXT.FramebufferEXT, handle.Handle); #region CTORS - public Framebuffer (RenderPass _renderPass, uint _width, uint _height, uint _layers = 1) : base(_renderPass.Dev) { + public FrameBuffer (RenderPass _renderPass, uint _width, uint _height, uint _layers = 1) : base(_renderPass.Dev) { renderPass = _renderPass; createInfo.width = _width; createInfo.height = _height; createInfo.layers = _layers; createInfo.renderPass = renderPass.handle; } - - public Framebuffer (RenderPass _renderPass, uint _width, uint _height, params Image[] views) + /// + /// Create and Activate a new frabuffer for the supplied RenderPass. + /// + /// Render pass. + /// Width. + /// Height. + /// Views. + public FrameBuffer (RenderPass _renderPass, uint _width, uint _height, params Image[] views) : this (_renderPass, _width, _height) { for (int i = 0; i < views.Length; i++) { Image v = views[i]; diff --git a/vke/src/base/GPUBuffer.cs b/vke/src/base/GPUBuffer.cs index 61504fd..b670812 100644 --- a/vke/src/base/GPUBuffer.cs +++ b/vke/src/base/GPUBuffer.cs @@ -27,7 +27,7 @@ using System; using System.Runtime.InteropServices; using VK; -namespace CVKL { +namespace vke { /// /// Device local Buffer diff --git a/vke/src/base/GraphicPipeline.cs b/vke/src/base/GraphicPipeline.cs index 562e4fa..5d16b2c 100644 --- a/vke/src/base/GraphicPipeline.cs +++ b/vke/src/base/GraphicPipeline.cs @@ -28,7 +28,7 @@ using System.Collections.Generic; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public class GraphicPipeline : Pipeline { public readonly RenderPass RenderPass; @@ -64,6 +64,15 @@ namespace CVKL { shaderStages.Add (shader.GetStageCreateInfo (Dev)); VkPipelineColorBlendStateCreateInfo colorBlendInfo = VkPipelineColorBlendStateCreateInfo.New (); + colorBlendInfo.logicOpEnable = cfg.ColorBlendLogicOpEnable; + colorBlendInfo.logicOp = cfg.ColorBlendLogicOp; + unsafe + { + colorBlendInfo.blendConstants[0] = cfg.ColorBlendConstants.X; + colorBlendInfo.blendConstants[1] = cfg.ColorBlendConstants.Y; + colorBlendInfo.blendConstants[2] = cfg.ColorBlendConstants.Z; + colorBlendInfo.blendConstants[3] = cfg.ColorBlendConstants.W; + } colorBlendInfo.attachmentCount = (uint)cfg.blendAttachments.Count; colorBlendInfo.pAttachments = cfg.blendAttachments.Pin (); diff --git a/vke/src/base/GraphicPipelineConfig.cs b/vke/src/base/GraphicPipelineConfig.cs index 56b74ca..697e623 100644 --- a/vke/src/base/GraphicPipelineConfig.cs +++ b/vke/src/base/GraphicPipelineConfig.cs @@ -25,12 +25,13 @@ // THE SOFTWARE. using System; using System.Collections.Generic; +using System.Numerics; using System.Reflection; using System.Runtime.InteropServices; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public class GraphicPipelineConfig { public uint SubpassIndex; public PipelineLayout Layout; @@ -47,7 +48,10 @@ namespace CVKL { public List vertexBindings = new List (); public List vertexAttributes = new List (); public readonly List shaders = new List(); - + public VkBool32 ColorBlendLogicOpEnable = false; + public VkLogicOp ColorBlendLogicOp; + public Vector4 ColorBlendConstants; + public VkSampleCountFlags Samples { get { return multisampleState.rasterizationSamples; } } diff --git a/vke/src/base/HostBuffer.cs b/vke/src/base/HostBuffer.cs index 20734c8..9465614 100644 --- a/vke/src/base/HostBuffer.cs +++ b/vke/src/base/HostBuffer.cs @@ -29,7 +29,7 @@ using System.Runtime.InteropServices; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public class HostBuffer : HostBuffer { int TSize; diff --git a/vke/src/base/Image.cs b/vke/src/base/Image.cs index 3787e3c..96ab24a 100644 --- a/vke/src/base/Image.cs +++ b/vke/src/base/Image.cs @@ -29,7 +29,7 @@ using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Combined Image/Descriptor class. Optional Sampler and View are disposed with the vkImage. If multiple view/sampler have to be /// created for the same vkImage, you may call the constructor accepting a vkImage as parameter to import an existing one. vkImage handle of @@ -53,6 +53,9 @@ namespace CVKL { public VkImage Handle => handle; public uint Width => CreateInfo.extent.width; public uint Height => CreateInfo.extent.height; + public override bool IsLinar => CreateInfo.tiling == VkImageTiling.Linear; + + VkImageLayout lastKnownLayout; protected override VkDebugMarkerObjectNameInfoEXT DebugMarkerInfo => new VkDebugMarkerObjectNameInfoEXT(VkDebugReportObjectTypeEXT.ImageEXT, handle.Handle); @@ -79,6 +82,8 @@ namespace CVKL { info.sharingMode = VkSharingMode.Exclusive; info.flags = createFlags; + lastKnownLayout = info.initialLayout; + Activate ();//DONT OVERRIDE Activate in derived classes!!!! } @@ -397,13 +402,24 @@ namespace CVKL { Descriptor.sampler = sampler; } - public void SetLayout ( + public void SetLayout (CommandBuffer cmdbuffer, + VkImageAspectFlags aspectMask, + VkImageLayout newImageLayout) { + SetLayout (cmdbuffer, aspectMask, lastKnownLayout, newImageLayout, lastKnownLayout.GetDefaultStage (), newImageLayout.GetDefaultStage ()); + } + public void SetLayout (CommandBuffer cmdbuffer, + VkImageAspectFlags aspectMask, + VkImageLayout oldImageLayout, + VkImageLayout newImageLayout) { + SetLayout (cmdbuffer, aspectMask, oldImageLayout, newImageLayout, oldImageLayout.GetDefaultStage (), newImageLayout.GetDefaultStage ()); + } + public void SetLayout ( CommandBuffer cmdbuffer, VkImageAspectFlags aspectMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, - VkPipelineStageFlags srcStageMask = VkPipelineStageFlags.AllCommands, - VkPipelineStageFlags dstStageMask = VkPipelineStageFlags.AllCommands) { + VkPipelineStageFlags srcStageMask, + VkPipelineStageFlags dstStageMask) { VkImageSubresourceRange subresourceRange = new VkImageSubresourceRange { aspectMask = aspectMask, baseMipLevel = 0, @@ -539,7 +555,7 @@ namespace CVKL { case VkImageLayout.TransferSrcOptimal: // Image will be used as a transfer source // Make sure any reads from and writes to the image have been finished - imageMemoryBarrier.srcAccessMask = imageMemoryBarrier.srcAccessMask | VkAccessFlags.TransferRead; + imageMemoryBarrier.srcAccessMask |= VkAccessFlags.TransferRead; imageMemoryBarrier.dstAccessMask = VkAccessFlags.TransferRead; break; @@ -575,6 +591,8 @@ namespace CVKL { 0,IntPtr.Zero, 0, IntPtr.Zero, 1, ref imageMemoryBarrier); + + lastKnownLayout = newImageLayout; } public void BuildMipmaps (Queue copyQ, CommandPool copyCmdPool) { @@ -594,7 +612,9 @@ namespace CVKL { cmd.Free (); } public void BuildMipmaps (CommandBuffer cmd) { + VkImageSubresourceRange mipSubRange = new VkImageSubresourceRange (VkImageAspectFlags.Color, 0, 1, 0, info.arrayLayers); + SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.TransferDstOptimal); for (int i = 1; i < info.mipLevels; i++) { VkImageBlit imageBlit = new VkImageBlit { @@ -609,6 +629,8 @@ namespace CVKL { vkCmdBlitImage (cmd.Handle, handle, VkImageLayout.TransferSrcOptimal, handle, VkImageLayout.TransferDstOptimal, 1, ref imageBlit, VkFilter.Linear); mipSubRange.baseMipLevel = (uint)i; } + SetLayout (cmd, VkImageLayout.TransferDstOptimal, VkImageLayout.TransferSrcOptimal, mipSubRange, + VkPipelineStageFlags.Transfer, VkPipelineStageFlags.Transfer); SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.TransferSrcOptimal, VkImageLayout.ShaderReadOnlyOptimal, VkPipelineStageFlags.Transfer, VkPipelineStageFlags.FragmentShader); } diff --git a/vke/src/base/Instance.cs b/vke/src/base/Instance.cs index d8a06d3..2807ed2 100644 --- a/vke/src/base/Instance.cs +++ b/vke/src/base/Instance.cs @@ -29,7 +29,7 @@ using System.Runtime.InteropServices; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Vulkan Instance disposable class /// diff --git a/vke/src/base/PhysicalDevice.cs b/vke/src/base/PhysicalDevice.cs index 265c6fa..289a629 100644 --- a/vke/src/base/PhysicalDevice.cs +++ b/vke/src/base/PhysicalDevice.cs @@ -31,7 +31,7 @@ using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; -namespace CVKL { +namespace vke { public class PhysicalDeviceCollection : IEnumerable { VkInstance inst; PhysicalDevice[] phys; diff --git a/vke/src/base/Pipeline.cs b/vke/src/base/Pipeline.cs index 3e6eac3..bb67cbc 100644 --- a/vke/src/base/Pipeline.cs +++ b/vke/src/base/Pipeline.cs @@ -27,7 +27,7 @@ using System; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public abstract class Pipeline : Activable { protected VkPipeline handle; protected PipelineLayout layout; diff --git a/vke/src/base/PipelineCache.cs b/vke/src/base/PipelineCache.cs index c139696..40fae4e 100644 --- a/vke/src/base/PipelineCache.cs +++ b/vke/src/base/PipelineCache.cs @@ -32,7 +32,7 @@ using VK; using static VK.Vk; -namespace CVKL { +namespace vke { /// /// Activable holding the pipeline cache handle. Activation is triggered by usage, so disposing pipelines that use this /// cache is enough to have the cache disposed correctly. diff --git a/vke/src/base/PipelineLayout.cs b/vke/src/base/PipelineLayout.cs index 1c59f90..f864a1b 100644 --- a/vke/src/base/PipelineLayout.cs +++ b/vke/src/base/PipelineLayout.cs @@ -29,7 +29,7 @@ using System.Linq; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public sealed class PipelineLayout : Activable { internal VkPipelineLayout handle; public VkPipelineLayout Handle => handle; diff --git a/vke/src/base/QueryPool.cs b/vke/src/base/QueryPool.cs index 1d95174..256e780 100644 --- a/vke/src/base/QueryPool.cs +++ b/vke/src/base/QueryPool.cs @@ -28,7 +28,7 @@ using System.Collections.Generic; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public class TimestampQueryPool : QueryPool { public readonly float Period; diff --git a/vke/src/base/Queue.cs b/vke/src/base/Queue.cs index 93444ae..a3a3fd2 100644 --- a/vke/src/base/Queue.cs +++ b/vke/src/base/Queue.cs @@ -29,7 +29,7 @@ using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public class PresentQueue : Queue { public readonly VkSurfaceKHR Surface; diff --git a/vke/src/base/RenderPass.cs b/vke/src/base/RenderPass.cs index c5662f9..48c3278 100644 --- a/vke/src/base/RenderPass.cs +++ b/vke/src/base/RenderPass.cs @@ -25,11 +25,12 @@ // THE SOFTWARE. using System; using System.Collections.Generic; +using System.Linq; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public class RenderPass : Activable { internal VkRenderPass handle; @@ -208,13 +209,13 @@ namespace CVKL { /// /// Begin Render pass with framebuffer extent dimensions /// - public void Begin (CommandBuffer cmd, Framebuffer frameBuffer) { + public void Begin (CommandBuffer cmd, FrameBuffer frameBuffer) { Begin (cmd, frameBuffer, frameBuffer.Width, frameBuffer.Height); } /// /// Begin Render pass with custom render area /// - public void Begin (CommandBuffer cmd, Framebuffer frameBuffer, uint width, uint height) { + public void Begin (CommandBuffer cmd, FrameBuffer frameBuffer, uint width, uint height) { VkRenderPassBeginInfo info = VkRenderPassBeginInfo.New(); info.renderPass = handle; @@ -238,6 +239,24 @@ namespace CVKL { vkCmdEndRenderPass (cmd.Handle); } + public FrameBuffers CreateFrameBuffers (SwapChain swapChain) { + FrameBuffers fbs = new FrameBuffers(); + Image[] images = new Image[attachments.Count]; + + int presentableImgIdx = attachments.IndexOf(attachments.FirstOrDefault(a => a.finalLayout == VkImageLayout.PresentSrcKHR || a.finalLayout == VkImageLayout.SharedPresentKHR)); + + if (presentableImgIdx<0) + throw new Exception("RenderPass used in Pipeline has no presentable attachment"); + + for (int i = 0; i < swapChain.ImageCount; ++i) + { + images[presentableImgIdx] = swapChain.images[i]; + fbs.Add(new FrameBuffer(this, swapChain.Width, swapChain.Height, images)); + } + return fbs; + } + + public override string ToString () { return string.Format ($"{base.ToString ()}[0x{handle.Handle.ToString("x")}]"); } diff --git a/vke/src/base/Resource.cs b/vke/src/base/Resource.cs index f5b4c87..89552ee 100644 --- a/vke/src/base/Resource.cs +++ b/vke/src/base/Resource.cs @@ -6,7 +6,7 @@ using VK; using static VK.Vk; -namespace CVKL { +namespace vke { [DebuggerDisplay ("{previous.name} <- {name} -> {next.name}")] public abstract class Resource : Activable { protected VkMemoryRequirements memReqs; @@ -24,6 +24,7 @@ namespace CVKL { public ulong AllocatedDeviceMemorySize => memReqs.size; public uint TypeBits => memReqs.memoryTypeBits; public ulong MemoryAlignment => memReqs.alignment; + public abstract bool IsLinar { get; } protected IntPtr mappedData; public IntPtr MappedData => mappedData; diff --git a/vke/src/base/SubPass.cs b/vke/src/base/SubPass.cs index 2396cdb..4a490e0 100644 --- a/vke/src/base/SubPass.cs +++ b/vke/src/base/SubPass.cs @@ -26,7 +26,7 @@ using System.Collections.Generic; using VK; -namespace CVKL { +namespace vke { public class SubPass { public uint Index { get; internal set; } List colorRefs = new List(); diff --git a/vke/src/base/SwapChain.cs b/vke/src/base/SwapChain.cs index f519055..9c2bea7 100644 --- a/vke/src/base/SwapChain.cs +++ b/vke/src/base/SwapChain.cs @@ -27,7 +27,7 @@ using System; using VK; using static VK.Vk; -namespace CVKL { +namespace vke { public class SwapChain : Activable { /// /// Set the default swapchain image format. @@ -158,7 +158,7 @@ namespace CVKL { return (int)currentImageIndex; } - void _destroy () { + void _destroy () { for (int i = 0; i < ImageCount; i++) images[i].Dispose (); diff --git a/vke/src/ktx.cs b/vke/src/ktx.cs index 4ea7c41..2d6271c 100644 --- a/vke/src/ktx.cs +++ b/vke/src/ktx.cs @@ -5,7 +5,7 @@ using System; using System.IO; using VK; -using CVKL; +using vke; using System.Runtime.InteropServices; using System.Collections.Generic; @@ -93,9 +93,13 @@ namespace KTX { byte[] keyValueDatas = br.ReadBytes ((int)bytesOfKeyValueData); + uint blockW, blockH; + bool isCompressed = vkFormat.TryGetCompressedFormatBlockSize (out blockW, out blockH); + uint blockSize = blockW * blockH; if (memoryProperty.HasFlag (VkMemoryPropertyFlags.DeviceLocal)) { - ulong staggingSize = (ulong)ktxStream.Length;//img.AllocatedDeviceMemorySize; + ulong staggingSize = (ulong)ktxStream.Length + 256;//img.AllocatedDeviceMemorySize; + Console.WriteLine ($"KtxStream size = {ktxStream.Length}, img Allocation = {img.AllocatedDeviceMemorySize}"); using (HostBuffer stagging = new HostBuffer (staggingQ.Dev, VkBufferUsageFlags.TransferSrc, staggingSize)) { stagging.Map (); @@ -119,14 +123,20 @@ namespace KTX { for (int mips = 0; mips < numberOfMipmapLevels; mips++) { UInt32 imgSize = br.ReadUInt32 (); - bufferCopyRegion.bufferImageHeight = imgHeight; bufferCopyRegion.bufferRowLength = imgWidth; + bufferCopyRegion.bufferImageHeight = imgHeight; + + if (isCompressed && (imgWidth % blockW > 0 || imgHeight % blockH > 0)) { + bufferCopyRegion.bufferRowLength += blockW - imgWidth % blockW; + bufferCopyRegion.bufferImageHeight += blockH - imgHeight % blockH; + } bufferCopyRegion.bufferOffset = bufferOffset; bufferCopyRegion.imageSubresource.mipLevel = (uint)mips; bufferCopyRegion.imageExtent.width = imgWidth; bufferCopyRegion.imageExtent.height = imgHeight; if (createFlags.HasFlag (VkImageCreateFlags.CubeCompatible)) { + //TODO:handle compressed formats for (uint face = 0; face < numberOfFaces; face++) { Marshal.Copy (br.ReadBytes ((int)imgSize), 0, stagging.MappedData + (int)bufferOffset, (int)imgSize); uint faceOffset = imgSize + (imgSize % 4);//cube padding @@ -134,12 +144,22 @@ namespace KTX { } buffCopies.Add (bufferCopyRegion); bufferCopyRegion.bufferOffset = bufferOffset; + } else if (isCompressed && (imgWidth % blockW > 0 || imgHeight % blockH > 0)) { + for (int line = 0; line < imgHeight; line++) { + Marshal.Copy (br.ReadBytes ((int)imgWidth), 0, stagging.MappedData + (int)bufferOffset, (int)imgWidth); + bufferOffset += bufferCopyRegion.bufferRowLength; + } + buffCopies.Add (bufferCopyRegion); } else { + Marshal.Copy (br.ReadBytes ((int)imgSize), 0, stagging.MappedData + (int)bufferOffset, (int)imgSize); buffCopies.Add (bufferCopyRegion); bufferOffset += imgSize; } + if (isCompressed && bufferOffset % blockSize > 0) + bufferOffset += blockSize - bufferOffset % blockSize; + imgWidth /= 2; imgHeight /= 2; } diff --git a/vke/src/model/BoundingBox.cs b/vke/src/model/BoundingBox.cs index 07747c8..a03eb4d 100644 --- a/vke/src/model/BoundingBox.cs +++ b/vke/src/model/BoundingBox.cs @@ -26,7 +26,7 @@ // THE SOFTWARE. using System.Numerics; /* code derived from https://github.com/mellinoe*/ -namespace CVKL { +namespace vke { public struct BoundingBox { public Vector3 min; public Vector3 max; diff --git a/vke/src/model/Model.cs b/vke/src/model/Model.cs index 0bc56e8..6b7d0f1 100644 --- a/vke/src/model/Model.cs +++ b/vke/src/model/Model.cs @@ -28,7 +28,7 @@ using System.Collections.Generic; using System.Numerics; using VK; -namespace CVKL { +namespace vke { public enum AlphaMode : UInt32 { Opaque, diff --git a/vke/vke.csproj b/vke/vke.csproj index 8c4ca40..d4b6563 100644 --- a/vke/vke.csproj +++ b/vke/vke.csproj @@ -1,17 +1,20 @@ + net471;netstandard2.0 + 0.1.7 $(ReleaseVersion) C# vulkan library with IDispose model and references counting + https://github.com/jpbruyere/vke.net vulkan game engine compute glfw c# - $(AssemblyVersion)-beta + $(AssemblyVersion) True False https://github.com/jpbruyere/vke.net/blob/master/README.md MIT - - + Jean-Philippe Bruyère + false @@ -22,6 +25,7 @@ true false + 7.2 @@ -49,6 +53,6 @@ testRsID - +