From 0915d864c0995ce8ed912977be310b25744b74e9 Mon Sep 17 00:00:00 2001 From: "Pierre-Loup A. Griffais" Date: Wed, 11 Dec 2019 01:14:13 +0000 Subject: [PATCH] Vulkan: compress layer slots into contiguous texture slots. Otherwise we can crash if what we get passed has holes, like when the main layer loses its texture abruptly but overlays are still on top of it. --- src/rendervulkan.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index b5d93c6..e51d8a0 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -747,14 +747,18 @@ bool vulkan_composite( struct Composite_t *pComposite, struct VulkanPipeline_t * // XXX maybe flush something? CVulkanTexture *pTex[ k_nMaxLayers ] = {}; + uint32_t texLayerIDs[ k_nMaxLayers ] = {}; + uint32_t nTexCount = 0; for ( uint32_t i = 0; i < k_nMaxLayers; i ++ ) { if ( pPipeline->layerBindings[ i ].tex != 0 ) { - pTex[ i ] = g_mapVulkanTextures[ pPipeline->layerBindings[ i ].tex ]; - assert( pTex[ i ] ); + pTex[ nTexCount ] = g_mapVulkanTextures[ pPipeline->layerBindings[ i ].tex ]; + assert( pTex[ nTexCount ] ); + + texLayerIDs[ nTexCount ] = i; nTexCount++; } @@ -908,11 +912,11 @@ bool vulkan_composite( struct Composite_t *pComposite, struct VulkanPipeline_t * VkSamplerCreateInfo samplerCreateInfo = { .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .pNext = nullptr, - .magFilter = pPipeline->layerBindings[ i ].bFilter ? VK_FILTER_LINEAR : VK_FILTER_NEAREST, - .minFilter = pPipeline->layerBindings[ i ].bFilter ? VK_FILTER_LINEAR : VK_FILTER_NEAREST, + .magFilter = pPipeline->layerBindings[ texLayerIDs[ i ] ].bFilter ? VK_FILTER_LINEAR : VK_FILTER_NEAREST, + .minFilter = pPipeline->layerBindings[ texLayerIDs[ i ] ].bFilter ? VK_FILTER_LINEAR : VK_FILTER_NEAREST, .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, - .borderColor = pPipeline->layerBindings[ i ].bBlackBorder ? VK_BORDER_COLOR_INT_OPAQUE_BLACK : VK_BORDER_COLOR_INT_TRANSPARENT_BLACK, + .borderColor = pPipeline->layerBindings[ texLayerIDs[ i ] ].bBlackBorder ? VK_BORDER_COLOR_INT_OPAQUE_BLACK : VK_BORDER_COLOR_INT_TRANSPARENT_BLACK, .unnormalizedCoordinates = VK_TRUE, };