From: Jean-Philippe Bruyère Date: Mon, 31 Oct 2022 17:24:20 +0000 (+0100) Subject: first working triangle (rdna2, mesa-trunk, VK_EXT_mesh_shader X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=0fbf2e86b2448e503e56d4438493716b01358db1;p=jp%2Fvke.net.git first working triangle (rdna2, mesa-trunk, VK_EXT_mesh_shader --- diff --git a/.vscode/launch.json b/.vscode/launch.json index 541a0b7..038b2cd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -43,6 +43,21 @@ "stopAtEntry": false, "console": "internalConsole" }, + { + "name": ".NET Core Launch (MeshShader)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build MeshShader", + "program": "${workspaceFolder}/build/Debug/netcoreapp3.1/MeshShader", + "args": [], + "cwd": "${workspaceFolder}/build/Debug/netcoreapp3.1/", + "stopAtEntry": false, + "console": "internalConsole", + "env": { + "VK_ICD_FILENAMES": "/usr/local/share/vulkan/icd.d/radeon_icd.x86_64.json", + "RADV_PERFTEST": "rt,ext_ms" + } + }, { "name": ".NET Core Launch (Compute)", "type": "coreclr", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 504ba80..e1657dd 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,6 +1,20 @@ { "version": "2.0.0", "tasks": [ + { + "label": "build SpirVTasks", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/SpirVTasks/SpirVTasks.csproj", + "/property:GenerateFullPaths=true", + "/property:SolutionDir=${workspaceFolder}/", + "/property:Configuration=Debug", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, { "label": "build ExternalMemmories", "command": "dotnet", @@ -43,6 +57,20 @@ ], "problemMatcher": "$msCompile" }, + { + "label": "build MeshShader", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/samples/MeshShader/MeshShader.csproj", + "/property:GenerateFullPaths=true", + "/property:SolutionDir=${workspaceFolder}/", + "/property:Configuration=Debug", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, { "label": "build Compute", "command": "dotnet", diff --git a/Directory.Build.props b/Directory.Build.props index 022e6ea..7efe3e3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,9 +2,9 @@ $(MSBuildThisFileDirectory) $(SolutionDir)build\$(Configuration)\ - 0.1.45 + 0.2.0 $(SpirVTasksReleaseVersion) - 0.2.7 + 0.3.0 $(VkeReleaseVersion)-beta true false diff --git a/SpirVTasks/spirv.xml b/SpirVTasks/spirv.xml index d22b7a8..7f89d71 100644 --- a/SpirVTasks/spirv.xml +++ b/SpirVTasks/spirv.xml @@ -8,4 +8,6 @@ + + diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index c2598c2..87424d2 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -33,7 +33,7 @@ - + shaders.%(Filename)%(Extension).spv diff --git a/samples/MeshShader/MeshShader.csproj b/samples/MeshShader/MeshShader.csproj new file mode 100644 index 0000000..672fb5a --- /dev/null +++ b/samples/MeshShader/MeshShader.csproj @@ -0,0 +1,5 @@ + + + false + + diff --git a/samples/MeshShader/main.cs b/samples/MeshShader/main.cs new file mode 100644 index 0000000..5406f85 --- /dev/null +++ b/samples/MeshShader/main.cs @@ -0,0 +1,211 @@ +// 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.Numerics; +using System.Runtime.InteropServices; +using vke; +using Vulkan; +using Glfw; +using System.Linq; +using System.Collections.Generic; + +namespace MeshShader { + class Program : SampleBase { +#if DEBUG + /*public override string[] EnabledLayers => + new string[] { + "VK_LAYER_KHRONOS_validation" + };*/ + +#endif + public override string[] EnabledInstanceExtensions => new string[] { + Ext.I.VK_KHR_get_physical_device_properties2, + Ext.I.VK_EXT_debug_utils, + }; + public override string[] EnabledDeviceExtensions => new string[] { + Ext.D.VK_KHR_swapchain, + Ext.D.VK_KHR_spirv_1_4, + Ext.D.VK_EXT_mesh_shader + //"VK_NV_mesh_shader" + }; + protected override void configureEnabledFeatures(VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures enabled_features) + { + base.configureEnabledFeatures(available_features, ref enabled_features); + + + } + vke.DebugUtils.Messenger dbgmsg; + protected override void selectPhysicalDevice () { + PhysicalDeviceCollection phys = instance.GetAvailablePhysicalDevice (); + phy = instance.GetAvailablePhysicalDevice ().FirstOrDefault (p => p.Properties.deviceType == VkPhysicalDeviceType.DiscreteGpu && p.HasSwapChainSupport); + Console.WriteLine($"Using gpu: {phy.Properties.deviceName}"); + + dbgmsg = new vke.DebugUtils.Messenger (instance, + VkDebugUtilsMessageTypeFlagsEXT.PerformanceEXT | VkDebugUtilsMessageTypeFlagsEXT.ValidationEXT | VkDebugUtilsMessageTypeFlagsEXT.GeneralEXT, + VkDebugUtilsMessageSeverityFlagsEXT.InfoEXT | + VkDebugUtilsMessageSeverityFlagsEXT.WarningEXT | + VkDebugUtilsMessageSeverityFlagsEXT.ErrorEXT | + VkDebugUtilsMessageSeverityFlagsEXT.VerboseEXT); + + VkPhysicalDeviceFeatures2 phyFeat2 = VkPhysicalDeviceFeatures2.New; + VkPhysicalDeviceMeshShaderFeaturesEXT meshFeat = VkPhysicalDeviceMeshShaderFeaturesEXT.New; + + IntPtr pPhyFeat2 = Marshal.AllocHGlobal(Marshal.SizeOf()); + IntPtr pMeshFeat = Marshal.AllocHGlobal(Marshal.SizeOf()); + + Marshal.StructureToPtr(meshFeat, pMeshFeat,false); + phyFeat2.pNext = pMeshFeat; + Marshal.StructureToPtr(phyFeat2, pPhyFeat2,false); + + Vk.vkGetPhysicalDeviceFeatures2(phy.Handle, pPhyFeat2); + + phyFeat2 = Marshal.PtrToStructure(pPhyFeat2); + meshFeat = Marshal.PtrToStructure(pMeshFeat); + Marshal.FreeHGlobal(pPhyFeat2); + Marshal.FreeHGlobal(pMeshFeat); + + Console.WriteLine($"Mesh Shader Support:\t{meshFeat.meshShader}"); + Console.WriteLine($"Task Shader Support:\t{meshFeat.taskShader}"); + + if (!(meshFeat.meshShader && meshFeat.taskShader)) { + phy = null; + } + } + + static void Main (string[] args) { + Instance.VK_MINOR = 3; + using (Program vke = new Program ()) { + vke.Run (); + } + } + + const float rotSpeed = 0.01f, zoomSpeed = 0.01f; + float rotX, rotY, zoom = 1f; + + HostBuffer uboMVPmatrix; //a host mappable buffer for mvp matrice. + + DescriptorPool descriptorPool; + DescriptorSet descriptorSet;//descriptor set for the mvp matrice. + + FrameBuffers frameBuffers; //the frame buffer collection coupled to the swapchain images + GraphicPipeline pipeline; + + protected override void initVulkan () { + base.initVulkan (); + + + descriptorPool = new DescriptorPool (dev, 1, new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer)); + using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false)) { + //Create the pipeline layout, it will be automatically activated on pipeline creation, so that sharing layout among different pipelines will benefit + //from the reference counting to automatically dispose unused layout on pipeline clean up. It's the same for DescriptorSetLayout. + /*cfg.Layout = new PipelineLayout (dev, + new DescriptorSetLayout (dev, new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer)));*/ + cfg.Layout = new PipelineLayout (dev); + //create a default renderpass with just a color attachment for the swapchain image, a default subpass is automatically created and the renderpass activation + //will follow the pipeline life cicle and will be automatically disposed when no longuer used. + cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, cfg.Samples); + //configuration of vertex bindings and attributes + + //shader are automatically compiled by SpirVTasks if added to the project. The resulting shaders are automatically embedded in the assembly. + //To specifiy that the shader path is a resource name, put the '#' prefix. Else the path will be search on disk. + cfg.AddShaders ( + new ShaderInfo (dev, VkShaderStageFlags.MeshEXT, "#shaders.main.mesh.spv"), + new ShaderInfo (dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv") + ); + + //create and activate the pipeline with the configuration we've just done. + pipeline = new GraphicPipeline (cfg); + } + + //because descriptor layout used for a pipeline are only activated on pipeline activation, descriptor set must not be allocated before, except if the layout has been manually activated, + //but in this case, layout will need also to be explicitly disposed. + //descriptorSet = descriptorPool.Allocate (pipeline.Layout.DescriptorSetLayouts[0]); + + //Write the content of the descriptor, the mvp matrice. + //DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descriptorSet, pipeline.Layout.DescriptorSetLayouts[0]); + //Descriptor property of the mvp buffer will return a default descriptor with no offset of the full size of the buffer. + //uboUpdate.Write (dev, uboMVPmatrix.Descriptor); + + //allocate the default VkWindow buffers, one per swapchain image. Their will be only reset when rebuilding and not reallocated. + cmds = cmdPool.AllocateCommandBuffer (swapChain.ImageCount); + } + + //view update override, see base method for more informations. + public override void UpdateView () { + /*uboMVPmatrix.AsSpan()[0] = + Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotY) * + Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotX) * + Matrix4x4.CreateTranslation (0, 0, -3f * zoom) * + Helpers.CreatePerspectiveFieldOfView (Helpers.DegreesToRadians (45f), (float)swapChain.Width / (float)swapChain.Height, 0.1f, 256.0f); + + base.UpdateView ();*/ + } + protected override void onMouseMove (double xPos, double yPos) { + double diffX = lastMouseX - xPos; + double diffY = lastMouseY - yPos; + if (GetButton (MouseButton.Left) == InputAction.Press) { + rotY -= rotSpeed * (float)diffX; + rotX += rotSpeed * (float)diffY; + updateViewRequested = true; + } else if (GetButton (MouseButton.Right) == InputAction.Press) { + zoom += zoomSpeed * (float)diffY; + updateViewRequested = true; + } + } + + void buildCommandBuffers() { + cmdPool.Reset (VkCommandPoolResetFlags.ReleaseResources); + + for (int i = 0; i < swapChain.ImageCount; ++i) { + FrameBuffer fb = frameBuffers[i]; + cmds[i].Start (); + + pipeline.RenderPass.Begin (cmds[i], fb); + + cmds[i].SetViewport (swapChain.Width, swapChain.Height); + cmds[i].SetScissor (swapChain.Width, swapChain.Height); + + //cmds[i].BindDescriptorSet (pipeline.Layout, descriptorSet); + + cmds[i].BindPipeline (pipeline); + + Vk.vkCmdDrawMeshTasksEXT(cmds[i].Handle, 1, 1, 1); + + pipeline.RenderPass.End (cmds[i]); + + cmds[i].End (); + } + } + + protected override void OnResize () { + base.OnResize (); + + updateViewRequested = true; + + frameBuffers?.Dispose(); + frameBuffers = pipeline.RenderPass.CreateFrameBuffers(swapChain); + + buildCommandBuffers (); + } + //clean up + protected override void Dispose (bool disposing) { + dev.WaitIdle (); + if (disposing) { + if (!isDisposed) { + //pipeline clean up will dispose PipelineLayout, DescriptorSet layouts and render pass automatically. If their reference count is zero, their handles will be destroyed. + pipeline.Dispose (); + //frame buffers are automatically activated on creation as for resources, so it requests an explicit call to dispose. + frameBuffers?.Dispose(); + //the descriptor pool + descriptorPool.Dispose (); + //resources have to be explicityly disposed. + //uboMVPmatrix.Dispose (); + dbgmsg?.Dispose (); + } + } + + base.Dispose (disposing); + } + } +} diff --git a/samples/MeshShader/shaders/main.frag b/samples/MeshShader/shaders/main.frag new file mode 100644 index 0000000..9f807c4 --- /dev/null +++ b/samples/MeshShader/shaders/main.frag @@ -0,0 +1,13 @@ +#version 450 + +layout (location = 0) in PerVertexData +{ + vec4 color; +} fragIn; + +layout (location = 0) out vec4 FragColor; + +void main() +{ + FragColor = fragIn.color; +} \ No newline at end of file diff --git a/samples/MeshShader/shaders/main.mesh b/samples/MeshShader/shaders/main.mesh new file mode 100644 index 0000000..ebe1be2 --- /dev/null +++ b/samples/MeshShader/shaders/main.mesh @@ -0,0 +1,47 @@ + +#extension GL_EXT_mesh_shader : require + +layout(local_size_x = 1) in; +layout(triangles, max_vertices = 3, max_primitives = 1) out; + +// Custom vertex output block +layout (location = 0) out PerVertexData +{ + vec4 color; +} v_out[]; // [max_vertices] + + +float scale = 0.95; +const vec3 vertices[3] = {vec3(-1,-1,0), vec3(0,1,0), vec3(1,-1,0)}; +const vec3 colors[3] = {vec3(1.0,0.0,0.0), vec3(0.0,1.0,0.0), vec3(0.0,0.0,1.0)}; + + +void main() +{ + vec4 pos = vec4(vertices[0] * scale, 1.0); + // GL->VK conventions... + pos.y = -pos.y; pos.z = (pos.z + pos.w) / 2.0; + gl_MeshVerticesEXT[0].gl_Position = pos; + + pos = vec4(vertices[1] * scale, 1.0); + pos.y = -pos.y; pos.z = (pos.z + pos.w) / 2.0; + gl_MeshVerticesEXT[1].gl_Position = pos; + + pos = vec4(vertices[2] * scale, 1.0); + pos.y = -pos.y; pos.z = (pos.z + pos.w) / 2.0; + gl_MeshVerticesEXT[2].gl_Position = pos; + + + v_out[0].color = vec4(colors[0], 1.0); + v_out[1].color = vec4(colors[1], 1.0); + v_out[2].color = vec4(colors[2], 1.0); + + + gl_PrimitiveIndicesEXT[0] = 0; + gl_PrimitiveIndicesEXT[1] = 1; + gl_PrimitiveIndicesEXT[2] = 2; + + gl_PrimitiveCountEXT = 1; + + SetMeshOutputsEXT(3,1); +} \ No newline at end of file diff --git a/samples/common/SampleBase.cs b/samples/common/SampleBase.cs index 2104a69..d6a3a64 100644 --- a/samples/common/SampleBase.cs +++ b/samples/common/SampleBase.cs @@ -10,7 +10,7 @@ namespace vke { base.initVulkan(); #if DEBUG - foreach (VkPhysicalDeviceToolPropertiesEXT toolProp in phy.GetToolProperties()) { + foreach (VkPhysicalDeviceToolProperties toolProp in phy.GetToolProperties()) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine ($"Enabled Tool: {toolProp.name}({toolProp.version})"); Console.ResetColor (); diff --git a/vke.net.sln b/vke.net.sln index 0e5ac98..a366bba 100644 --- a/vke.net.sln +++ b/vke.net.sln @@ -44,9 +44,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "deferred", "samples\deferre EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "pbr", "samples\pbr\pbr.csproj", "{7EB2430B-6BC0-4AE9-B1FA-57C3DB2AE1C5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExternalMemmories", "samples\ExternalMemmories\ExternalMemmories.csproj", "{85CD9813-E182-4ED1-8D2C-38467657BEF3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExternalMemmories", "samples\ExternalMemmories\ExternalMemmories.csproj", "{85CD9813-E182-4ED1-8D2C-38467657BEF3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VulkanContext", "samples\VulkanContext\VulkanContext.csproj", "{CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VulkanContext", "samples\VulkanContext\VulkanContext.csproj", "{CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MeshShader", "samples\MeshShader\MeshShader.csproj", "{5787D082-7E4E-4B18-9C69-529CBC4F105E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -70,93 +72,68 @@ Global {642726F4-0592-4846-8EAF-A5D1964C85A7}.Debug|Any CPU.Build.0 = Debug|Any CPU {642726F4-0592-4846-8EAF-A5D1964C85A7}.Release|Any CPU.ActiveCfg = Release|Any CPU {642726F4-0592-4846-8EAF-A5D1964C85A7}.Release|Any CPU.Build.0 = Release|Any CPU - {642726F4-0592-4846-8EAF-A5D1964C85A7}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU {F04C3F79-2E08-4D35-A804-43039DCB7F5E}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {F04C3F79-2E08-4D35-A804-43039DCB7F5E}.BuildPackages|Any CPU.Build.0 = Release|Any CPU {F04C3F79-2E08-4D35-A804-43039DCB7F5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F04C3F79-2E08-4D35-A804-43039DCB7F5E}.Debug|Any CPU.Build.0 = Debug|Any CPU {F04C3F79-2E08-4D35-A804-43039DCB7F5E}.Release|Any CPU.ActiveCfg = Release|Any CPU {F04C3F79-2E08-4D35-A804-43039DCB7F5E}.Release|Any CPU.Build.0 = Release|Any CPU - {F04C3F79-2E08-4D35-A804-43039DCB7F5E}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU {FEF3AF30-5B88-4D3C-8BD7-8734200E0D1E}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {FEF3AF30-5B88-4D3C-8BD7-8734200E0D1E}.BuildPackages|Any CPU.Build.0 = Release|Any CPU {FEF3AF30-5B88-4D3C-8BD7-8734200E0D1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FEF3AF30-5B88-4D3C-8BD7-8734200E0D1E}.Debug|Any CPU.Build.0 = Debug|Any CPU {FEF3AF30-5B88-4D3C-8BD7-8734200E0D1E}.Release|Any CPU.ActiveCfg = Release|Any CPU {FEF3AF30-5B88-4D3C-8BD7-8734200E0D1E}.Release|Any CPU.Build.0 = Release|Any CPU - {FEF3AF30-5B88-4D3C-8BD7-8734200E0D1E}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU {F3BBF67D-7E63-48F3-8156-ADC014D268BB}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {F3BBF67D-7E63-48F3-8156-ADC014D268BB}.BuildPackages|Any CPU.Build.0 = Release|Any CPU {F3BBF67D-7E63-48F3-8156-ADC014D268BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F3BBF67D-7E63-48F3-8156-ADC014D268BB}.Debug|Any CPU.Build.0 = Debug|Any CPU {F3BBF67D-7E63-48F3-8156-ADC014D268BB}.Release|Any CPU.ActiveCfg = Release|Any CPU {F3BBF67D-7E63-48F3-8156-ADC014D268BB}.Release|Any CPU.Build.0 = Release|Any CPU - {F3BBF67D-7E63-48F3-8156-ADC014D268BB}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU - {1D2A1968-8F04-4BE0-B03A-573F1F68AB66}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU - {1D2A1968-8F04-4BE0-B03A-573F1F68AB66}.BuildPackages|Any CPU.Build.0 = Release|Any CPU {1D2A1968-8F04-4BE0-B03A-573F1F68AB66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1D2A1968-8F04-4BE0-B03A-573F1F68AB66}.Debug|Any CPU.Build.0 = Debug|Any CPU {1D2A1968-8F04-4BE0-B03A-573F1F68AB66}.Release|Any CPU.ActiveCfg = Release|Any CPU {1D2A1968-8F04-4BE0-B03A-573F1F68AB66}.Release|Any CPU.Build.0 = Release|Any CPU - {1D2A1968-8F04-4BE0-B03A-573F1F68AB66}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Debug|Any CPU - {124152F8-FAE6-4D4B-87B9-6074DD365E9B}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {124152F8-FAE6-4D4B-87B9-6074DD365E9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {124152F8-FAE6-4D4B-87B9-6074DD365E9B}.Debug|Any CPU.Build.0 = Debug|Any CPU {124152F8-FAE6-4D4B-87B9-6074DD365E9B}.Release|Any CPU.ActiveCfg = Release|Any CPU {124152F8-FAE6-4D4B-87B9-6074DD365E9B}.Release|Any CPU.Build.0 = Release|Any CPU - {124152F8-FAE6-4D4B-87B9-6074DD365E9B}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU - {1B2DF710-E500-49E5-8802-EBA71A05E827}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {1B2DF710-E500-49E5-8802-EBA71A05E827}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1B2DF710-E500-49E5-8802-EBA71A05E827}.Debug|Any CPU.Build.0 = Debug|Any CPU {1B2DF710-E500-49E5-8802-EBA71A05E827}.Release|Any CPU.ActiveCfg = Release|Any CPU {1B2DF710-E500-49E5-8802-EBA71A05E827}.Release|Any CPU.Build.0 = Release|Any CPU - {1B2DF710-E500-49E5-8802-EBA71A05E827}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU - {5000CDE2-99B9-47EA-B4D9-EA1631F0E14A}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {5000CDE2-99B9-47EA-B4D9-EA1631F0E14A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5000CDE2-99B9-47EA-B4D9-EA1631F0E14A}.Debug|Any CPU.Build.0 = Debug|Any CPU {5000CDE2-99B9-47EA-B4D9-EA1631F0E14A}.Release|Any CPU.ActiveCfg = Release|Any CPU {5000CDE2-99B9-47EA-B4D9-EA1631F0E14A}.Release|Any CPU.Build.0 = Release|Any CPU - {5000CDE2-99B9-47EA-B4D9-EA1631F0E14A}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU - {77437C6D-28B5-4798-96CA-68F987770D65}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {77437C6D-28B5-4798-96CA-68F987770D65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {77437C6D-28B5-4798-96CA-68F987770D65}.Debug|Any CPU.Build.0 = Debug|Any CPU {77437C6D-28B5-4798-96CA-68F987770D65}.Release|Any CPU.ActiveCfg = Release|Any CPU {77437C6D-28B5-4798-96CA-68F987770D65}.Release|Any CPU.Build.0 = Release|Any CPU - {77437C6D-28B5-4798-96CA-68F987770D65}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU - {8185163E-A67C-4C0E-8548-67E2A9F16309}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {8185163E-A67C-4C0E-8548-67E2A9F16309}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8185163E-A67C-4C0E-8548-67E2A9F16309}.Debug|Any CPU.Build.0 = Debug|Any CPU {8185163E-A67C-4C0E-8548-67E2A9F16309}.Release|Any CPU.ActiveCfg = Release|Any CPU {8185163E-A67C-4C0E-8548-67E2A9F16309}.Release|Any CPU.Build.0 = Release|Any CPU - {8185163E-A67C-4C0E-8548-67E2A9F16309}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU - {D9A41382-444E-44ED-B638-3D8F06F2FBC2}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {D9A41382-444E-44ED-B638-3D8F06F2FBC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D9A41382-444E-44ED-B638-3D8F06F2FBC2}.Debug|Any CPU.Build.0 = Debug|Any CPU {D9A41382-444E-44ED-B638-3D8F06F2FBC2}.Release|Any CPU.ActiveCfg = Release|Any CPU {D9A41382-444E-44ED-B638-3D8F06F2FBC2}.Release|Any CPU.Build.0 = Release|Any CPU - {D9A41382-444E-44ED-B638-3D8F06F2FBC2}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU - {7EB2430B-6BC0-4AE9-B1FA-57C3DB2AE1C5}.BuildPackages|Any CPU.ActiveCfg = Release|Any CPU {7EB2430B-6BC0-4AE9-B1FA-57C3DB2AE1C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7EB2430B-6BC0-4AE9-B1FA-57C3DB2AE1C5}.Debug|Any CPU.Build.0 = Debug|Any CPU {7EB2430B-6BC0-4AE9-B1FA-57C3DB2AE1C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {7EB2430B-6BC0-4AE9-B1FA-57C3DB2AE1C5}.Release|Any CPU.Build.0 = Release|Any CPU - {7EB2430B-6BC0-4AE9-B1FA-57C3DB2AE1C5}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Release|Any CPU - {85CD9813-E182-4ED1-8D2C-38467657BEF3}.BuildPackages|Any CPU.ActiveCfg = Debug|Any CPU - {85CD9813-E182-4ED1-8D2C-38467657BEF3}.BuildPackages|Any CPU.Build.0 = Debug|Any CPU {85CD9813-E182-4ED1-8D2C-38467657BEF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {85CD9813-E182-4ED1-8D2C-38467657BEF3}.Debug|Any CPU.Build.0 = Debug|Any CPU {85CD9813-E182-4ED1-8D2C-38467657BEF3}.Release|Any CPU.ActiveCfg = Release|Any CPU {85CD9813-E182-4ED1-8D2C-38467657BEF3}.Release|Any CPU.Build.0 = Release|Any CPU - {85CD9813-E182-4ED1-8D2C-38467657BEF3}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Debug|Any CPU - {85CD9813-E182-4ED1-8D2C-38467657BEF3}.ReleaseSpirVTasks|Any CPU.Build.0 = Debug|Any CPU - {CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}.BuildPackages|Any CPU.ActiveCfg = Debug|Any CPU - {CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}.BuildPackages|Any CPU.Build.0 = Debug|Any CPU {CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}.Debug|Any CPU.Build.0 = Debug|Any CPU {CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}.Release|Any CPU.ActiveCfg = Release|Any CPU {CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}.Release|Any CPU.Build.0 = Release|Any CPU - {CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}.ReleaseSpirVTasks|Any CPU.ActiveCfg = Debug|Any CPU - {CF8755E1-9E8B-4AD2-A7D1-D66D797004AD}.ReleaseSpirVTasks|Any CPU.Build.0 = Debug|Any CPU + {5787D082-7E4E-4B18-9C69-529CBC4F105E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5787D082-7E4E-4B18-9C69-529CBC4F105E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5787D082-7E4E-4B18-9C69-529CBC4F105E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5787D082-7E4E-4B18-9C69-529CBC4F105E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -175,6 +152,7 @@ Global {7EB2430B-6BC0-4AE9-B1FA-57C3DB2AE1C5} = {16439374-B8DB-4643-8116-EB3358B49A12} {85CD9813-E182-4ED1-8D2C-38467657BEF3} = {16439374-B8DB-4643-8116-EB3358B49A12} {CF8755E1-9E8B-4AD2-A7D1-D66D797004AD} = {16439374-B8DB-4643-8116-EB3358B49A12} + {5787D082-7E4E-4B18-9C69-529CBC4F105E} = {16439374-B8DB-4643-8116-EB3358B49A12} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1360F94D-CF3C-4121-A8D7-E227F41668F1} diff --git a/vke/src/VkWindow.cs b/vke/src/VkWindow.cs index e208a33..d527880 100644 --- a/vke/src/VkWindow.cs +++ b/vke/src/VkWindow.cs @@ -153,10 +153,16 @@ namespace vke { instance = new Instance (EnabledLayers, instExts.ToArray()); - hSurf = instance.CreateSurface (hWin); - selectPhysicalDevice (); + if (phy == null) { + instance.Dispose(); + terminateGLFW(); + throw new Exception("Required physical device not found."); + } + + hSurf = instance.CreateSurface (hWin); + VkPhysicalDeviceFeatures enabledFeatures = default; configureEnabledFeatures (phy.Features, ref enabledFeatures); @@ -392,6 +398,15 @@ namespace vke { #region IDisposable Support protected bool isDisposed; + void terminateGLFW() { + if (currentCursor != IntPtr.Zero) + Glfw3.DestroyCursor (currentCursor); + if (hWin != IntPtr.Zero) { + windows.Remove (hWin); + Glfw3.DestroyWindow (hWin); + } + Glfw3.Terminate (); + } protected virtual void Dispose (bool disposing) { if (!isDisposed) { @@ -413,15 +428,7 @@ namespace vke { } else Debug.WriteLine ("a VkWindow has not been correctly disposed"); - if (currentCursor != IntPtr.Zero) - Glfw3.DestroyCursor (currentCursor); - - windows.Remove (hWin); - - Glfw3.DestroyWindow (hWin); - Glfw3.Terminate (); - - + terminateGLFW(); isDisposed = true; } } diff --git a/vke/src/base/PhysicalDevice.cs b/vke/src/base/PhysicalDevice.cs index 859f129..3ef8269 100644 --- a/vke/src/base/PhysicalDevice.cs +++ b/vke/src/base/PhysicalDevice.cs @@ -166,16 +166,16 @@ namespace vke { tiling, usage, flags, out properties); return result == VkResult.Success; } - public VkPhysicalDeviceToolPropertiesEXT[] GetToolProperties () { - CheckResult (vkGetPhysicalDeviceToolPropertiesEXT (phy , out uint count, IntPtr.Zero)); - int sizeStruct = Marshal.SizeOf (); + public VkPhysicalDeviceToolProperties[] GetToolProperties () { + CheckResult (vkGetPhysicalDeviceToolProperties (phy , out uint count, IntPtr.Zero)); + int sizeStruct = Marshal.SizeOf (); IntPtr ptrTools = Marshal.AllocHGlobal (sizeStruct * (int)count); - CheckResult (vkGetPhysicalDeviceToolPropertiesEXT (phy , out count, ptrTools)); + CheckResult (vkGetPhysicalDeviceToolProperties (phy , out count, ptrTools)); - VkPhysicalDeviceToolPropertiesEXT[] result = new VkPhysicalDeviceToolPropertiesEXT[count]; + VkPhysicalDeviceToolProperties[] result = new VkPhysicalDeviceToolProperties[count]; IntPtr tmp = ptrTools; for (int i = 0; i < count; i++) { - result[i] = Marshal.PtrToStructure (tmp); + result[i] = Marshal.PtrToStructure (tmp); tmp += sizeStruct; } diff --git a/vke/vke.csproj b/vke/vke.csproj index d1d163c..9ecb0ab 100644 --- a/vke/vke.csproj +++ b/vke/vke.csproj @@ -48,7 +48,7 @@ - +