Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Lab/Experiments/ImGuiVulkan/ImGuiVulkan.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<None Remove="shader.frag.spv" />
<EmbeddedResource Include="shader.frag.spv" />
Expand All @@ -15,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ImGui.NET" Version="1.86.0" />
<PackageReference Include="ImGui.NET" Version="1.89.2" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 23 additions & 9 deletions src/Lab/Experiments/ImGuiVulkan/ImGuiVulkanApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -75,8 +76,8 @@ public void Run()
private KhrSwapchain _vkSwapchain;
private ExtDebugUtils _debugUtils;
private string[] _validationLayers = { "VK_LAYER_KHRONOS_validation" };
private string[] _instanceExtensions = { ExtDebugUtils.ExtensionName };
private string[] _deviceExtensions = { KhrSwapchain.ExtensionName };
private List<string> _instanceExtensions = new () { ExtDebugUtils.ExtensionName };
private List<string> _deviceExtensions = new () { KhrSwapchain.ExtensionName };

private void InitWindow()
{
Expand Down Expand Up @@ -319,13 +320,21 @@ private unsafe void CleanupSwapchain()
private unsafe void CreateInstance()
{
_vk = Vk.GetApi();


var isMacOs = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);

if (isMacOs)
{
_instanceExtensions.Add("VK_KHR_portability_enumeration");
_deviceExtensions.Add("VK_KHR_portability_subset");
}

if (EnableValidationLayers && !CheckValidationLayerSupport())
{
throw new NotSupportedException("Validation layers requested, but not available!");
}

var appInfo = new ApplicationInfo
var appInfo = new ApplicationInfo
{
SType = StructureType.ApplicationInfo,
PApplicationName = (byte*)Marshal.StringToHGlobalAnsi("Hello Triangle"),
Expand All @@ -340,22 +349,27 @@ private unsafe void CreateInstance()
SType = StructureType.InstanceCreateInfo,
PApplicationInfo = &appInfo
};


if (isMacOs)
{
createInfo.Flags = InstanceCreateFlags.EnumeratePortabilityBitKhr;
}

var extensions = _window.VkSurface!.GetRequiredExtensions(out var extCount);
// TODO Review that this count doesn't realistically exceed 1k (recommended max for stackalloc)
// Should probably be allocated on heap anyway as this isn't super performance critical.
var newExtensions = stackalloc byte*[(int)(extCount + _instanceExtensions.Length)];
var newExtensions = stackalloc byte*[(int)(extCount + _instanceExtensions.Count)];
for (var i = 0; i < extCount; i++)
{
newExtensions[i] = extensions[i];
}

for (var i = 0; i < _instanceExtensions.Length; i++)
for (var i = 0; i < _instanceExtensions.Count; i++)
{
newExtensions[extCount + i] = (byte*)SilkMarshal.StringToPtr(_instanceExtensions[i]);
}

extCount += (uint)_instanceExtensions.Length;
extCount += (uint)_instanceExtensions.Count;
createInfo.EnabledExtensionCount = extCount;
createInfo.PpEnabledExtensionNames = newExtensions;

Expand Down Expand Up @@ -615,7 +629,7 @@ private unsafe void CreateLogicalDevice()
createInfo.QueueCreateInfoCount = (uint)uniqueQueueFamilies.Length;
createInfo.PQueueCreateInfos = queueCreateInfos;
createInfo.PEnabledFeatures = &deviceFeatures;
createInfo.EnabledExtensionCount = (uint)_deviceExtensions.Length;
createInfo.EnabledExtensionCount = (uint)_deviceExtensions.Count;

var enabledExtensionNames = SilkMarshal.StringArrayToPtr(_deviceExtensions);
createInfo.PpEnabledExtensionNames = (byte**)enabledExtensionNames;
Expand Down
2 changes: 1 addition & 1 deletion src/Vulkan/Silk.NET.Vulkan/VulkanLibraryNameContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class VulkanLibraryNameContainer : SearchPathContainer
public override string Linux => "libvulkan.so.1";

/// <inheritdoc />
public override string MacOS => "libMoltenVK.dylib";
public override string MacOS => "libvulkan.dylib";

/// <inheritdoc />
public override string Android => "libvulkan.so";
Expand Down