Skip to content

Commit

Permalink
Add Physical Device querying
Browse files Browse the repository at this point in the history
  • Loading branch information
SupinePandora43 committed Jul 18, 2023
1 parent bc0a2d4 commit 09fc4f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Examples/gpu/UltralightNet.Vulkan.TestApp/Startup/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static void Check(this Result result)
private static bool HasInstanceLayer(this Vk vk, ReadOnlySpan<byte> layer)
{
uint propertyCount = 0;
vk.EnumerateInstanceLayerProperties(ref propertyCount, null);
vk.EnumerateInstanceLayerProperties(ref propertyCount, null).Check();
var properties = stackalloc LayerProperties[(int)propertyCount];
vk.EnumerateInstanceLayerProperties(ref propertyCount, properties);
vk.EnumerateInstanceLayerProperties(ref propertyCount, properties).Check();
for (int i = 0; i < propertyCount; i++)
if (layer.SequenceEqual(MemoryMarshal.CreateReadOnlySpanFromNullTerminated(properties[i].LayerName))) return true;
return false;
Expand Down
11 changes: 10 additions & 1 deletion Examples/gpu/UltralightNet.Vulkan.TestApp/VulkanExample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//namespace VulkanExample;

using Silk.NET.Core.Native;
using Silk.NET.Vulkan;
using Silk.NET.Windowing;

Expand All @@ -14,6 +13,8 @@ internal unsafe partial class Application : IDisposable
readonly Vk vk = Vk.GetApi();
readonly Instance instance;

readonly PhysicalDevice physicalDevice;

public Application()
{
{ // Window
Expand All @@ -24,6 +25,14 @@ public Application()
var extensions = window.VkSurface.GetRequiredExtensions(out uint extensionCount);
Utils.CreateInstance(vk, extensionCount, extensions, out instance);
}
{ // Physical Device
uint deviceCount = 0;
vk.EnumeratePhysicalDevices(instance, ref deviceCount, null).Check();
if (deviceCount is 0) throw new Exception("Couldn't find physical vulkan device.");
var devices = stackalloc PhysicalDevice[(int)deviceCount];
vk.EnumeratePhysicalDevices(instance, ref deviceCount, devices).Check();
physicalDevice = devices[0]; // idc
}
Console.WriteLine();
}

Expand Down

0 comments on commit 09fc4f6

Please sign in to comment.