Skip to content

Commit

Permalink
Adjust swapchain image counts.
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Dec 28, 2024
1 parent 8a29251 commit 82ad0bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
@Value.Immutable
public interface JCSwapchainConfigurationType
{
/**
* @return The requested minimum number of swapchain images
*/

@Value.Default
default int requestedMinimumImages()
{
return 2;
}

/**
* @return The logical device.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,28 @@ private static VulkanSharingMode pickImageSharingMode(
* Select the minimum number of images required.
*/

private static int pickImageCount(
private int pickImageCount(
final VulkanSurfaceCapabilitiesKHR surfaceCaps)
{
final var minPossible =
surfaceCaps.minImageCount();
var maxPossible =
surfaceCaps.maxImageCount();

/*
* Oddly, many implementations will return a minimum image count of N,
* but then return an error unless N+1 is used.
* Implementations can state that they have no maximum number of images.
* For implementations that do this, we enforce our own maximum that's
* likely to be larger than any reasonable application could need.
*/

final var minPlus = surfaceCaps.minImageCount() + 1;
if (surfaceCaps.maxImageCount() == 0) {
return minPlus;
if (maxPossible == 0) {
maxPossible = 100;
}

return Math.clamp(
minPlus,
surfaceCaps.minImageCount(),
surfaceCaps.maxImageCount()
(long) this.configuration.requestedMinimumImages(),
minPossible,
maxPossible
);
}

Expand Down Expand Up @@ -359,7 +364,7 @@ private SwapchainHolder createNewSwapchain()
eventCreationFailed.width = eventCreated.width;
eventCreationFailed.height = eventCreated.height;

final var minImageCount = pickImageCount(caps);
final var minImageCount = this.pickImageCount(caps);
eventCreated.minimumImageCount = minImageCount;
eventCreationFailed.minimumImageCount = eventCreated.minimumImageCount;

Expand Down

0 comments on commit 82ad0bf

Please sign in to comment.