Skip to content

Commit

Permalink
swapchain framebuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
aquagoose committed Sep 2, 2024
1 parent aa61a5c commit eda44e9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/grabs.Graphics.Vulkan/VkDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public override ShaderModule CreateShaderModule(ShaderStage stage, byte[] spirv,

public override Framebuffer CreateFramebuffer(in ReadOnlySpan<Texture> colorTextures, Texture depthTexture = null)
{
if (colorTextures[0] is VkSwapchainTexture swapchainTexture)
return new VkSwapchainFramebuffer(swapchainTexture);

throw new NotImplementedException();
}

Expand Down
19 changes: 19 additions & 0 deletions src/grabs.Graphics.Vulkan/VkSwapchainFramebuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Silk.NET.Vulkan;

namespace grabs.Graphics.Vulkan;

public class VkSwapchainFramebuffer : Framebuffer
{
public ImageView[] Views;

public VkSwapchainFramebuffer(VkSwapchainTexture texture)
{
Views = texture.Views;
}

public override void Dispose()
{

}
}
2 changes: 1 addition & 1 deletion src/grabs.Graphics.Vulkan/VkSwapchainTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public VkSwapchainTexture(Vk vk, VulkanDevice device, in ReadOnlySpan<Image> ima

public override void Dispose()
{
for (int i = 0; i < Images.Length; i++)
for (int i = 0; i < Views.Length; i++)
_vk.DestroyImageView(_device, Views[i], null);

// Cannot destroy the actual images themselves as they are owned by the swapchain.
Expand Down
3 changes: 3 additions & 0 deletions tests/grabs.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Silk.NET.Vulkan;
using Device = grabs.Graphics.Device;
using Event = Silk.NET.SDL.Event;
using Framebuffer = grabs.Graphics.Framebuffer;
using Instance = grabs.Graphics.Instance;
using Surface = grabs.Graphics.Surface;
using Texture = grabs.Graphics.Texture;
Expand Down Expand Up @@ -124,6 +125,7 @@
device.CreateSwapchain(new SwapchainDescription(width, height, bufferCount: 4, presentMode: PresentMode.VerticalSync));

Texture swapchainTexture = swapchain.GetSwapchainTexture();
Framebuffer swapchainFramebuffer = device.CreateFramebuffer(swapchainTexture);

CommandList commandList = device.CreateCommandList();

Expand Down Expand Up @@ -153,6 +155,7 @@
}

commandList.Dispose();
swapchainFramebuffer.Dispose();
swapchainTexture.Dispose();
swapchain.Dispose();
device.Dispose();
Expand Down

0 comments on commit eda44e9

Please sign in to comment.