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.
This commit is contained in:
Pierre-Loup A. Griffais 2019-12-11 01:14:13 +00:00
parent 30d8582b62
commit 0915d864c0

View file

@ -747,14 +747,18 @@ bool vulkan_composite( struct Composite_t *pComposite, struct VulkanPipeline_t *
// XXX maybe flush something? // XXX maybe flush something?
CVulkanTexture *pTex[ k_nMaxLayers ] = {}; CVulkanTexture *pTex[ k_nMaxLayers ] = {};
uint32_t texLayerIDs[ k_nMaxLayers ] = {};
uint32_t nTexCount = 0; uint32_t nTexCount = 0;
for ( uint32_t i = 0; i < k_nMaxLayers; i ++ ) for ( uint32_t i = 0; i < k_nMaxLayers; i ++ )
{ {
if ( pPipeline->layerBindings[ i ].tex != 0 ) if ( pPipeline->layerBindings[ i ].tex != 0 )
{ {
pTex[ i ] = g_mapVulkanTextures[ pPipeline->layerBindings[ i ].tex ]; pTex[ nTexCount ] = g_mapVulkanTextures[ pPipeline->layerBindings[ i ].tex ];
assert( pTex[ i ] ); assert( pTex[ nTexCount ] );
texLayerIDs[ nTexCount ] = i;
nTexCount++; nTexCount++;
} }
@ -908,11 +912,11 @@ bool vulkan_composite( struct Composite_t *pComposite, struct VulkanPipeline_t *
VkSamplerCreateInfo samplerCreateInfo = { VkSamplerCreateInfo samplerCreateInfo = {
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
.magFilter = 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[ 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, .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
.addressModeV = 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, .unnormalizedCoordinates = VK_TRUE,
}; };