Skip to content

Commit

Permalink
vk start swapchains
Browse files Browse the repository at this point in the history
  • Loading branch information
aquagoose committed Jul 29, 2024
1 parent fed2ed0 commit 3002e6d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/grabs.Graphics.Vulkan/VkDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace grabs.Graphics.Vulkan;

public unsafe class VkDevice : Device
public sealed unsafe class VkDevice : Device
{
private readonly Vk _vk;

Expand All @@ -19,7 +19,12 @@ public unsafe class VkDevice : Device

public readonly VulkanDevice Device;

public VkDevice(Vk vk, PhysicalDevice pDevice, VkSurface surface)
public readonly KhrSwapchain KhrSwapchain;

public readonly Queue GraphicsQueue;
public readonly Queue PresentQueue;

public VkDevice(Vk vk, VulkanInstance instance, PhysicalDevice pDevice, VkSurface surface)
{
_vk = vk;

Expand Down Expand Up @@ -90,6 +95,12 @@ public VkDevice(Vk vk, PhysicalDevice pDevice, VkSurface surface)
};

CheckResult(_vk.CreateDevice(pDevice, &deviceCreateInfo, null, out Device), "Create device");

if (!_vk.TryGetDeviceExtension(instance, Device, out KhrSwapchain))
throw new Exception("Failed to get VK_KHR_swapchain device extension.");

_vk.GetDeviceQueue(Device, _graphicsQueueIndex, 0, out GraphicsQueue);
_vk.GetDeviceQueue(Device, _presentQueueIndex, 0, out PresentQueue);
}

public override Swapchain CreateSwapchain(in SwapchainDescription description)
Expand Down Expand Up @@ -175,6 +186,8 @@ public override void ExecuteCommandList(CommandList list)

public override void Dispose()
{
CheckResult(_vk.DeviceWaitIdle(Device));
KhrSwapchain.Dispose();
_vk.DestroyDevice(Device, null);
}
}
4 changes: 2 additions & 2 deletions src/grabs.Graphics.Vulkan/VkInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace grabs.Graphics.Vulkan;

public unsafe class VkInstance : Instance
public sealed unsafe class VkInstance : Instance
{
public readonly Vk Vk;

Expand Down Expand Up @@ -106,7 +106,7 @@ public override Device CreateDevice(Surface surface, Adapter? adapter = null)
else
device = pDevices[0];

return new VkDevice(Vk, device, (VkSurface) surface);
return new VkDevice(Vk, Instance, device, (VkSurface) surface);
}

public override Adapter[] EnumerateAdapters()
Expand Down
2 changes: 1 addition & 1 deletion src/grabs.Graphics.Vulkan/VkSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace grabs.Graphics.Vulkan;

public class VkSurface : Surface
public sealed class VkSurface : Surface
{
public readonly VkInstance Instance;
public readonly SurfaceKHR Surface;
Expand Down
46 changes: 46 additions & 0 deletions src/grabs.Graphics.Vulkan/VkSwapchain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Silk.NET.Vulkan;
using Silk.NET.Vulkan.Extensions.KHR;

namespace grabs.Graphics.Vulkan;

public sealed class VkSwapchain : Swapchain
{
private readonly Vk _vk;
private readonly KhrSwapchain _khrSwapchain;

public override PresentMode PresentMode { get; set; }

public VkSwapchain(Vk vk, KhrSwapchain khrSwapchain, SurfaceKHR surface, in SwapchainDescription description)
{
_vk = vk;
_khrSwapchain = khrSwapchain;

Extent2D swapchainSize = new Extent2D(description.Width, description.Width);

SwapchainCreateInfoKHR swapchainCreateInfo = new SwapchainCreateInfoKHR()
{
SType = StructureType.SwapchainCreateInfoKhr,

}

Check failure on line 24 in src/grabs.Graphics.Vulkan/VkSwapchain.cs

View workflow job for this annotation

GitHub Actions / build

; expected

Check failure on line 24 in src/grabs.Graphics.Vulkan/VkSwapchain.cs

View workflow job for this annotation

GitHub Actions / build

; expected
}

public override Texture GetSwapchainTexture()
{
throw new System.NotImplementedException();
}

public override void Resize(uint width, uint height)
{
throw new System.NotImplementedException();
}

public override void Present()
{
throw new System.NotImplementedException();
}

public override void Dispose()
{
throw new System.NotImplementedException();
}
}

0 comments on commit 3002e6d

Please sign in to comment.