Skip to content
Draft
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
4 changes: 3 additions & 1 deletion Source/VK/SwapChainVK.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ struct SwapChainVK final : public DisplayDescHelper, DebugNameBase {
uint64_t m_PresentId = 0;
uint32_t m_TextureIndex = 0;
SwapChainBits m_Flags = SwapChainBits::NONE;
uint32_t m_Width = 0;
uint32_t m_Height = 0;
};

} // namespace nri
} // namespace nri
29 changes: 20 additions & 9 deletions Source/VK/SwapChainVK.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,24 @@ Result SwapChainVK::Create(const SwapChainDesc& swapChainDesc) {
vkResult = vk.GetPhysicalDeviceSurfaceCapabilities2KHR(m_Device, &surfaceInfo, &caps2);
NRI_RETURN_ON_BAD_VKRESULT(&m_Device, vkResult, "vkGetPhysicalDeviceSurfaceCapabilities2KHR");

bool isWidthValid = swapChainDesc.width >= surfaceCaps.minImageExtent.width && swapChainDesc.width <= surfaceCaps.maxImageExtent.width;
NRI_RETURN_ON_FAILURE(&m_Device, isWidthValid, Result::INVALID_ARGUMENT, "swapChainDesc.width is out of [%u, %u] range", surfaceCaps.minImageExtent.width,
surfaceCaps.maxImageExtent.width);
uint32_t width = swapChainDesc.width;
uint32_t height = swapChainDesc.height;

bool isHeightValid = swapChainDesc.height >= surfaceCaps.minImageExtent.height && swapChainDesc.height <= surfaceCaps.maxImageExtent.height;
NRI_RETURN_ON_FAILURE(&m_Device, isHeightValid, Result::INVALID_ARGUMENT, "swapChainDesc.height is out of [%u, %u] range", surfaceCaps.minImageExtent.height,
surfaceCaps.maxImageExtent.height);
if (width < surfaceCaps.minImageExtent.width)
width = surfaceCaps.minImageExtent.width;
if (width > surfaceCaps.maxImageExtent.width)
width = surfaceCaps.maxImageExtent.width;

if (height < surfaceCaps.minImageExtent.height)
height = surfaceCaps.minImageExtent.height;
if (height > surfaceCaps.maxImageExtent.height)
height = surfaceCaps.maxImageExtent.height;

if (width != swapChainDesc.width || height != swapChainDesc.height)
NRI_REPORT_WARNING(&m_Device, "swapChainDesc dimensions clamped to [%u, %u]", width, height);

m_Width = (uint16_t)width;
m_Height = (uint16_t)height;

// Silently clamp "textureNum" to the supported range
if (textureNum < surfaceCaps.minImageCount)
Expand Down Expand Up @@ -290,7 +301,7 @@ Result SwapChainVK::Create(const SwapChainDesc& swapChainDesc) {
swapchainInfo.minImageCount = textureNum;
swapchainInfo.imageFormat = surfaceFormat.surfaceFormat.format;
swapchainInfo.imageColorSpace = surfaceFormat.surfaceFormat.colorSpace;
swapchainInfo.imageExtent = {swapChainDesc.width, swapChainDesc.height};
swapchainInfo.imageExtent = {m_Width, m_Height};
swapchainInfo.imageArrayLayers = 1;
swapchainInfo.imageUsage = swapchainImageUsageFlags;
swapchainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
Expand Down Expand Up @@ -367,8 +378,8 @@ Result SwapChainVK::Create(const SwapChainDesc& swapChainDesc) {
desc.vkFormat = surfaceFormat.surfaceFormat.format;
desc.vkImageType = VK_IMAGE_TYPE_2D;
desc.vkImageUsageFlags = swapchainImageUsageFlags;
desc.width = swapChainDesc.width;
desc.height = swapChainDesc.height;
desc.width = m_Width;
desc.height = m_Height;
desc.depth = 1;
desc.mipNum = 1;
desc.layerNum = 1;
Expand Down