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: 6 additions & 0 deletions src/Veldrid/Vk/VkGraphicsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ internal unsafe class VkGraphicsDevice : GraphicsDevice

public override bool IsClipSpaceYInverted => !standardClipYDirection;

public override bool AllowTearing
{
get => mainSwapchain.AllowTearing;
set => mainSwapchain.AllowTearing = value;
}

public override Swapchain MainSwapchain => mainSwapchain;

public override GraphicsDeviceFeatures Features { get; }
Expand Down
31 changes: 24 additions & 7 deletions src/Veldrid/Vk/VkSwapchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ public override bool SyncToVerticalBlank
}
}

private bool allowTearing;

public bool AllowTearing
{
get => allowTearing;
set
{
if (allowTearing == value)
return;

allowTearing = value;

recreateAndReacquire(framebuffer.Width, framebuffer.Height);
}
}

private readonly VkGraphicsDevice gd;
private readonly VkSwapchainFramebuffer framebuffer;
private readonly uint presentQueueIndex;
Expand Down Expand Up @@ -203,14 +219,15 @@ private bool createSwapchain(uint width, uint height)

if (syncToVBlank)
{
if (presentModes.Contains(VkPresentModeKHR.FifoRelaxedKHR)) presentMode = VkPresentModeKHR.FifoRelaxedKHR;
}
else
{
if (presentModes.Contains(VkPresentModeKHR.MailboxKHR))
presentMode = VkPresentModeKHR.MailboxKHR;
else if (presentModes.Contains(VkPresentModeKHR.ImmediateKHR)) presentMode = VkPresentModeKHR.ImmediateKHR;
if (presentModes.Contains(VkPresentModeKHR.FifoRelaxedKHR))
presentMode = VkPresentModeKHR.FifoRelaxedKHR;
}
else if (allowTearing && presentModes.Contains(VkPresentModeKHR.ImmediateKHR))
presentMode = VkPresentModeKHR.ImmediateKHR;
else if (presentModes.Contains(VkPresentModeKHR.MailboxKHR))
presentMode = VkPresentModeKHR.MailboxKHR;
else if (presentModes.Contains(VkPresentModeKHR.ImmediateKHR))
presentMode = VkPresentModeKHR.ImmediateKHR;

uint maxImageCount = surfaceCapabilities.maxImageCount == 0 ? uint.MaxValue : surfaceCapabilities.maxImageCount;
uint imageCount = Math.Min(maxImageCount, surfaceCapabilities.minImageCount + 1);
Expand Down
Loading