From: Jean-Philippe Bruyère Date: Thu, 3 Dec 2020 15:00:12 +0000 (+0100) Subject: debug X-Git-Tag: v0.2.0-beta~2 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=6749bc850e0f779e3790130c41649869b10c021d;p=jp%2Fvke.net.git debug --- diff --git a/Directory.Build.props b/Directory.Build.props index b09b8f8..2f2d567 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -13,7 +13,7 @@ - $(DefineConstants);_MEMORY_POOLS + $(DefineConstants);MEMORY_POOLS $(DefineConstants);STB_SHARP diff --git a/SpirVTasks/SpirVTasks.csproj b/SpirVTasks/SpirVTasks.csproj index bbdf737..042c055 100644 --- a/SpirVTasks/SpirVTasks.csproj +++ b/SpirVTasks/SpirVTasks.csproj @@ -15,6 +15,7 @@ False https://github.com/jpbruyere/vk.net/blob/master/SpirVTasks/README.md MIT + icon.png MIT Jean-Philippe Bruyère $(SolutionDir)build\$(Configuration)\ @@ -40,5 +41,7 @@ true build + + \ No newline at end of file diff --git a/addons/gltfLoader/PbrModelTexArray.cs b/addons/gltfLoader/PbrModelTexArray.cs index abde06a..a91e099 100644 --- a/addons/gltfLoader/PbrModelTexArray.cs +++ b/addons/gltfLoader/PbrModelTexArray.cs @@ -68,13 +68,21 @@ namespace vke.glTF { VkSampleCountFlags.SampleCount1, VkImageTiling.Optimal, Image.ComputeMipLevels (TEXTURE_DIM), ctx.ImageCount); ctx.BuildTexArray (ref texArray, 0); - - texArray.CreateView (VkImageViewType.ImageView2DArray, VkImageAspectFlags.Color, texArray.CreateInfo.arrayLayers); - texArray.CreateSampler (); - texArray.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; - texArray.SetName ("model texArray"); + } else { + texArray = new Image (dev, Image.DefaultTextureFormat, VkImageUsageFlags.Sampled | VkImageUsageFlags.TransferDst | VkImageUsageFlags.TransferSrc, + VkMemoryPropertyFlags.DeviceLocal, TEXTURE_DIM, TEXTURE_DIM, VkImageType.Image2D, + VkSampleCountFlags.SampleCount1, VkImageTiling.Optimal, Image.ComputeMipLevels (TEXTURE_DIM), 1); + PrimaryCommandBuffer cmd = cmdPool.AllocateAndStart (VkCommandBufferUsageFlags.OneTimeSubmit); + texArray.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.ShaderReadOnlyOptimal); + transferQ.EndSubmitAndWait (cmd, true); } + texArray.CreateView (VkImageViewType.ImageView2DArray, VkImageAspectFlags.Color, texArray.CreateInfo.arrayLayers); + texArray.CreateSampler (); + texArray.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; + texArray.SetName ("model texArray"); + + loadMaterials (ctx); materialUBO = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, materials); } diff --git a/addons/gltfLoader/glTFLoader.cs b/addons/gltfLoader/glTFLoader.cs index cce4019..5942dea 100644 --- a/addons/gltfLoader/glTFLoader.cs +++ b/addons/gltfLoader/glTFLoader.cs @@ -420,11 +420,8 @@ namespace vke.glTF { PrimaryCommandBuffer cmd = cmdPool.AllocateAndStart (VkCommandBufferUsageFlags.OneTimeSubmit); texArray.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.Undefined, VkImageLayout.TransferDstOptimal, VkPipelineStageFlags.BottomOfPipe, VkPipelineStageFlags.Transfer); - cmd.End (); - transferQ.Submit (cmd); - transferQ.WaitIdle (); - cmd.Free (); - + transferQ.EndSubmitAndWait (cmd, true); + VkImageBlit imageBlit = new VkImageBlit { srcSubresource = new VkImageSubresourceLayers (VkImageAspectFlags.Color, 1, 0), dstOffsets_1 = new VkOffset3D (texDim, texDim, 1) @@ -458,11 +455,8 @@ namespace vke.glTF { Vk.vkCmdBlitImage (cmd.Handle, vkimg.Handle, VkImageLayout.TransferSrcOptimal, texArray.Handle, VkImageLayout.TransferDstOptimal, 1, ref imageBlit, VkFilter.Linear); - - cmd.End (); - transferQ.Submit (cmd); - transferQ.WaitIdle (); - cmd.Free (); + + transferQ.EndSubmitAndWait (cmd, true); vkimg.Dispose (); } diff --git a/addons/gltfLoader/gltfLoader.csproj b/addons/gltfLoader/gltfLoader.csproj index 9c83a86..da9a963 100644 --- a/addons/gltfLoader/gltfLoader.csproj +++ b/addons/gltfLoader/gltfLoader.csproj @@ -5,8 +5,8 @@ vke.gltfLoader $(VkeReleaseVersion) vke.net glTF addons - vulkan C# gltf - $(AssemblyVersion) + vulkan C# gltf + $(VkePackageVersion) True False https://github.com/jpbruyere/vke.net/blob/master/README.md diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index 03a8c6b..131cba2 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -31,7 +31,8 @@ - + + shaders.%(Filename)%(Extension).spv diff --git a/samples/DistanceFieldFontTest/Program.cs b/samples/DistanceFieldFontTest/Program.cs index feea78f..e54f569 100644 --- a/samples/DistanceFieldFontTest/Program.cs +++ b/samples/DistanceFieldFontTest/Program.cs @@ -68,7 +68,7 @@ namespace DistanceFieldFontTest { cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); - font = new BMFont (Utils.DataDirectory + "font.fnt"); + font = new BMFont (vke.samples.Utils.GetDataFile ("font.fnt")); vbo = new GPUBuffer (dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.TransferDst, 1024); ibo = new GPUBuffer (dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.TransferDst, 2048); diff --git a/samples/Textured/main.cs b/samples/Textured/main.cs index a123759..17cb1ca 100644 --- a/samples/Textured/main.cs +++ b/samples/Textured/main.cs @@ -59,11 +59,11 @@ namespace Textured { ushort[] indices = { 0, 1, 2, 2, 0, 3 }; int currentImgIndex = 0; string[] imgPathes = { - Utils.DataDirectory + "models/Bricks16_col.jpg", - Utils.DataDirectory + "textures/texturearray_rocks_bc3_unorm.ktx", - Utils.DataDirectory + "textures/texture.jpg", - Utils.DataDirectory + "textures/tex256.jpg", - Utils.DataDirectory + "font.ktx", + vke.samples.Utils.GetDataFile ("models/Bricks16_col.jpg"), + vke.samples.Utils.GetDataFile ("textures/texturearray_rocks_bc3_unorm.ktx"), + vke.samples.Utils.GetDataFile ("textures/texture.jpg"), + vke.samples.Utils.GetDataFile ("textures/tex256.jpg"), + vke.samples.Utils.GetDataFile ("font.ktx"), }; protected override void initVulkan () { @@ -98,6 +98,8 @@ namespace Textured { pipeline = new GraphicPipeline (cfg); + cfg.DisposeShaders (); + uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices); uboMats.Map ();//permanent map diff --git a/samples/TexturedCube/main.cs b/samples/TexturedCube/main.cs index b962e7e..df79043 100644 --- a/samples/TexturedCube/main.cs +++ b/samples/TexturedCube/main.cs @@ -95,13 +95,6 @@ namespace TextureCube { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, }; int currentImgIndex = 4; - string[] imgPathes = { - Utils.DataDirectory + "textures/uffizi_cube.ktx", - Utils.DataDirectory + "textures/papermill.ktx", - Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx", - Utils.DataDirectory + "textures/gcanyon_cube.ktx", - Utils.DataDirectory + "textures/pisa_cube.ktx", - }; VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1; @@ -143,7 +136,7 @@ namespace TextureCube { DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descriptorSet, dsLayout.Bindings[0]); uboUpdate.Write (dev, uboMats.Descriptor); - loadTexture (imgPathes[currentImgIndex]); + loadTexture (vke.samples.Utils.CubeMaps [currentImgIndex]); if (nextTexture != null) updateTextureSet (); } @@ -243,9 +236,9 @@ namespace TextureCube { switch (key) { case Key.Space: currentImgIndex++; - if (currentImgIndex == imgPathes.Length) + if (currentImgIndex == vke.samples.Utils.CubeMaps.Length) currentImgIndex = 0; - loadTexture (imgPathes[currentImgIndex]); + loadTexture (vke.samples.Utils.CubeMaps[currentImgIndex]); break; default: base.onKeyDown (key, scanCode, modifiers); diff --git a/samples/common/Utils.cs b/samples/common/Utils.cs new file mode 100644 index 0000000..80854e9 --- /dev/null +++ b/samples/common/Utils.cs @@ -0,0 +1,27 @@ +using System.IO; +using System.Linq; + +namespace vke.samples { + public static class Utils { + static string dataDir = "../../../datas/".Replace ('/', Path.DirectorySeparatorChar); + public static string DataDirectory => dataDir; + static string[] gltfExtensions = new[] { ".gltf", ".glb"}; + + public static string[] GltfFiles => + Directory + .GetFiles (Path.Combine (DataDirectory, "models"), "*", SearchOption.AllDirectories) + .Where (file => gltfExtensions.Any (file.ToLower ().EndsWith)) + .ToArray (); + + public static string[] CubeMaps = { + GetDataFile ("textures/papermill.ktx"), + GetDataFile ("textures/cubemap_yokohama_bc3_unorm.ktx"), + GetDataFile ("textures/gcanyon_cube.ktx"), + GetDataFile ("textures/pisa_cube.ktx"), + GetDataFile ("textures/uffizi_cube.ktx"), + }; + + public static string GetDataFile (string relativePath) => + Path.Combine (DataDirectory, relativePath); + } +} diff --git a/samples/deferred/DeferredPbrRenderer.cs b/samples/deferred/DeferredPbrRenderer.cs index 5f94db9..891a890 100644 --- a/samples/deferred/DeferredPbrRenderer.cs +++ b/samples/deferred/DeferredPbrRenderer.cs @@ -330,11 +330,10 @@ namespace deferred { model?.Dispose (); if (TEXTURE_ARRAY) { - PbrModelTexArray mod = new PbrModelTexArray (transferQ, path); - if (mod.texArray != null) { - DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsMain, descLayoutMain.Bindings[5], descLayoutMain.Bindings[7]); - uboUpdate.Write (dev, mod.materialUBO.Descriptor, mod.texArray.Descriptor); - } + PbrModelTexArray mod = new PbrModelTexArray (transferQ, path); + DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsMain, descLayoutMain.Bindings[5], descLayoutMain.Bindings[7]); + uboUpdate.Write (dev, mod.materialUBO.Descriptor, mod.texArray.Descriptor); + model = mod; } else { model = new PbrModelSeparatedTextures (transferQ, path, diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs index ff5e440..bc52420 100644 --- a/samples/deferred/main.cs +++ b/samples/deferred/main.cs @@ -32,8 +32,10 @@ namespace deferred { vke.Run (); } } + Deferred (string name = "VkCrowWindow", uint _width = 800, uint _height = 600, bool vSync = false) + : base (name, _width, _height, vSync) { } - public override string[] EnabledInstanceExtensions => new string[] { + public override string[] EnabledInstanceExtensions => new string[] { Ext.I.VK_EXT_debug_utils, }; @@ -53,28 +55,8 @@ namespace deferred { transferQ = new Queue (dev, VkQueueFlags.Transfer); computeQ = new Queue (dev, VkQueueFlags.Compute); } - string[] cubemapPathes = { - Utils.DataDirectory + "textures/papermill.ktx", - Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx", - Utils.DataDirectory + "textures/gcanyon_cube.ktx", - Utils.DataDirectory + "textures/pisa_cube.ktx", - Utils.DataDirectory + "textures/uffizi_cube.ktx", - }; - string[] modelPathes = { - //"/mnt/devel/vkPinball/data/models/pinball.gltf", - //"/mnt/devel/pinball.net/data/test.glb", - //Utils.DataDirectory + "models/Box.gltf", - //Utils.DataDirectory + "models/cubeOnPlane.glb", - //Utils.DataDirectory + "models/shadow.glb", - //Utils.DataDirectory + "models/cube.gltf", - Utils.DataDirectory + "models/DamagedHelmet/glTF/DamagedHelmet.gltf", - //Utils.DataDirectory + "models/shadow.glb", - Utils.DataDirectory + "models/Hubble.glb", - Utils.DataDirectory + "models/MER_static.glb", - Utils.DataDirectory + "models/ISS_stationary.glb", - }; - - int curModelIndex = 0; + + int curModelIndex = 13; bool reloadModel; bool rebuildBuffers; @@ -104,8 +86,8 @@ namespace deferred { camera.SetPosition (0, 0, -2); //renderer = new DeferredPbrRenderer (presentQueue, cubemapPathes[2], swapChain.Width, swapChain.Height, camera.NearPlane, camera.FarPlane); - renderer = new DeferredPbrRenderer (presentQueue, cubemapPathes[2], swapChain.Width, swapChain.Height, camera.NearPlane, camera.FarPlane); - renderer.LoadModel (transferQ, modelPathes[curModelIndex]); + renderer = new DeferredPbrRenderer (presentQueue, vke.samples.Utils.CubeMaps[2], swapChain.Width, swapChain.Height, camera.NearPlane, camera.FarPlane); + renderer.LoadModel (transferQ, vke.samples.Utils.GltfFiles [curModelIndex]); camera.Model = Matrix4x4.CreateScale (1f / Math.Max (Math.Max (renderer.modelAABB.Width, renderer.modelAABB.Height), renderer.modelAABB.Depth)); init_final_pl (); @@ -142,6 +124,7 @@ namespace deferred { } void buildCommandBuffers () { + dev.WaitIdle (); for (int i = 0; i < swapChain.ImageCount; ++i) { cmds[i]?.Free (); cmds[i] = cmdPool.AllocateAndStart (); @@ -179,7 +162,7 @@ namespace deferred { public override void Update () { if (reloadModel) { - renderer.LoadModel (transferQ, modelPathes[curModelIndex]); + renderer.LoadModel (transferQ, vke.samples.Utils.GltfFiles[curModelIndex]); reloadModel = false; camera.Model = Matrix4x4.CreateScale (1f / Math.Max (Math.Max (renderer.modelAABB.Width, renderer.modelAABB.Height), renderer.modelAABB.Depth)); updateViewRequested = true; @@ -346,16 +329,16 @@ namespace deferred { break; case Key.KeypadAdd: curModelIndex++; - if (curModelIndex >= modelPathes.Length) + if (curModelIndex >= vke.samples.Utils.GltfFiles.Length) curModelIndex = 0; reloadModel = true; - break; + return; case Key.KeypadSubtract: curModelIndex--; if (curModelIndex < 0) - curModelIndex = modelPathes.Length -1; + curModelIndex = vke.samples.Utils.GltfFiles.Length -1; reloadModel = true; - break; + return; default: base.onKeyDown (key, scanCode, modifiers); return; diff --git a/samples/pbr/main.cs b/samples/pbr/main.cs index 81eec97..034736c 100644 --- a/samples/pbr/main.cs +++ b/samples/pbr/main.cs @@ -41,22 +41,6 @@ namespace pbrSample { roughness } - string[] modelPathes = { - Utils.DataDirectory + "models/DamagedHelmet/glTF/DamagedHelmet.gltf", - Utils.DataDirectory + "models/Hubble.glb", - Utils.DataDirectory + "models/ISS_stationary.glb", - Utils.DataDirectory + "models/MER_static.glb", - Utils.DataDirectory + "models/Box.gltf", - }; - string[] cubemapPathes = { - Utils.DataDirectory + "textures/papermill.ktx", - Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx", - Utils.DataDirectory + "textures/gcanyon_cube.ktx", - Utils.DataDirectory + "textures/pisa_cube.ktx", - Utils.DataDirectory + "textures/uffizi_cube.ktx", - }; - - DebugView currentDebugView = DebugView.none; bool queryUpdatePrefilCube, showDebugImg; @@ -72,7 +56,7 @@ namespace pbrSample { camera.SetPosition (0, 0, -2); pbrPipeline = new PBRPipeline (presentQueue, - new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples), cubemapPathes[0]); + new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples), vke.samples.Utils.CubeMaps[0]); loadCurrentModel (); } @@ -99,7 +83,7 @@ namespace pbrSample { void loadCurrentModel () { dev.WaitIdle (); - pbrPipeline.LoadModel (presentQueue, modelPathes[curModelIndex]); + pbrPipeline.LoadModel (presentQueue, vke.samples.Utils.GltfFiles[curModelIndex]); BoundingBox modelAABB = pbrPipeline.model.DefaultScene.AABB; camera.Model = Matrix4x4.CreateScale (1f / Math.Max (Math.Max (modelAABB.max.X, modelAABB.max.Y), modelAABB.max.Z)); updateViewRequested = true; @@ -168,9 +152,9 @@ namespace pbrSample { switch (key) { case Key.Space: if (modifiers.HasFlag (Modifier.Shift)) - curModelIndex = curModelIndex == 0 ? (uint)modelPathes.Length - 1 : curModelIndex - 1; + curModelIndex = curModelIndex == 0 ? (uint)vke.samples.Utils.GltfFiles.Length - 1 : curModelIndex - 1; else - curModelIndex = curModelIndex < (uint)modelPathes.Length - 1 ? curModelIndex + 1 : 0; + curModelIndex = curModelIndex < (uint)vke.samples.Utils.GltfFiles.Length - 1 ? curModelIndex + 1 : 0; reloadModel = true; break; case Key.P: diff --git a/vke/src/Utils.cs b/vke/src/Utils.cs index 0a18818..7e1303a 100644 --- a/vke/src/Utils.cs +++ b/vke/src/Utils.cs @@ -9,8 +9,7 @@ using System.Reflection; using System.Xml.Serialization; namespace Vulkan { - public static partial class Utils { - public static string DataDirectory => "../../../datas/"; + public static partial class Utils { /// Throw an erro if VkResult != Success. public static void CheckResult (VkResult result, string errorString = "Call failed") { if (result != VkResult.Success) diff --git a/vke/src/VkWindow.cs b/vke/src/VkWindow.cs index fbfbedb..0c165e0 100644 --- a/vke/src/VkWindow.cs +++ b/vke/src/VkWindow.cs @@ -163,7 +163,7 @@ namespace vke { dev.Activate (enabledFeatures, EnabledDeviceExtensions); swapChain = new SwapChain (presentQueue as PresentQueue, Width, Height, SwapChain.PREFERED_FORMAT, - VSync ? VkPresentModeKHR.FifoKHR : VkPresentModeKHR.MailboxKHR); + VSync ? VkPresentModeKHR.FifoKHR : VkPresentModeKHR.ImmediateKHR); swapChain.Activate (); Width = swapChain.Width;