generalized image descriptor set cache

pull/8/head
cosmonaut 2020-12-29 16:19:19 -08:00 committed by thatcosmonaut
parent 234048d366
commit 223d053274
1 changed files with 110 additions and 110 deletions

View File

@ -677,15 +677,15 @@ typedef struct SwapChainSupportDetails
uint32_t presentModesLength; uint32_t presentModesLength;
} SwapChainSupportDetails; } SwapChainSupportDetails;
typedef struct SamplerDescriptorSetCache SamplerDescriptorSetCache; typedef struct ImageDescriptorSetCache ImageDescriptorSetCache;
typedef struct ComputeBufferDescriptorSetCache ComputeBufferDescriptorSetCache; typedef struct ComputeBufferDescriptorSetCache ComputeBufferDescriptorSetCache;
typedef struct ComputeImageDescriptorSetCache ComputeImageDescriptorSetCache; typedef struct ComputeImageDescriptorSetCache ComputeImageDescriptorSetCache;
typedef struct VulkanGraphicsPipelineLayout typedef struct VulkanGraphicsPipelineLayout
{ {
VkPipelineLayout pipelineLayout; VkPipelineLayout pipelineLayout;
SamplerDescriptorSetCache *vertexSamplerDescriptorSetCache; ImageDescriptorSetCache *vertexSamplerDescriptorSetCache;
SamplerDescriptorSetCache *fragmentSamplerDescriptorSetCache; ImageDescriptorSetCache *fragmentSamplerDescriptorSetCache;
} VulkanGraphicsPipelineLayout; } VulkanGraphicsPipelineLayout;
typedef struct VulkanGraphicsPipeline typedef struct VulkanGraphicsPipeline
@ -706,7 +706,7 @@ typedef struct VulkanComputePipelineLayout
{ {
VkPipelineLayout pipelineLayout; VkPipelineLayout pipelineLayout;
ComputeBufferDescriptorSetCache *bufferDescriptorSetCache; ComputeBufferDescriptorSetCache *bufferDescriptorSetCache;
ComputeImageDescriptorSetCache *imageDescriptorSetCache; ImageDescriptorSetCache *imageDescriptorSetCache;
} VulkanComputePipelineLayout; } VulkanComputePipelineLayout;
typedef struct VulkanComputePipeline typedef struct VulkanComputePipeline
@ -846,30 +846,30 @@ static inline void DescriptorSetLayoutHashTable_Insert(
/* Descriptor Set Caches */ /* Descriptor Set Caches */
typedef struct SamplerDescriptorSetData typedef struct ImageDescriptorSetData
{ {
VkDescriptorImageInfo descriptorImageInfo[MAX_TEXTURE_SAMPLERS]; /* used for vertex samplers as well */ VkDescriptorImageInfo descriptorImageInfo[MAX_TEXTURE_SAMPLERS]; /* used for vertex samplers as well */
} SamplerDescriptorSetData; } ImageDescriptorSetData;
typedef struct SamplerDescriptorSetHashMap typedef struct ImageDescriptorSetHashMap
{ {
uint64_t key; uint64_t key;
SamplerDescriptorSetData descriptorSetData; ImageDescriptorSetData descriptorSetData;
VkDescriptorSet descriptorSet; VkDescriptorSet descriptorSet;
uint8_t inactiveFrameCount; uint8_t inactiveFrameCount;
} SamplerDescriptorSetHashMap; } ImageDescriptorSetHashMap;
typedef struct SamplerDescriptorSetHashArray typedef struct ImageDescriptorSetHashArray
{ {
uint32_t *elements; uint32_t *elements;
int32_t count; int32_t count;
int32_t capacity; int32_t capacity;
} SamplerDescriptorSetHashArray; } ImageDescriptorSetHashArray;
#define NUM_DESCRIPTOR_SET_HASH_BUCKETS 1031 #define NUM_DESCRIPTOR_SET_HASH_BUCKETS 1031
static inline uint64_t SamplerDescriptorSetHashTable_GetHashCode( static inline uint64_t ImageDescriptorSetHashTable_GetHashCode(
SamplerDescriptorSetData *descriptorSetData, ImageDescriptorSetData *descriptorSetData,
uint32_t samplerCount uint32_t samplerCount
) { ) {
const uint64_t HASH_FACTOR = 97; const uint64_t HASH_FACTOR = 97;
@ -885,18 +885,18 @@ static inline uint64_t SamplerDescriptorSetHashTable_GetHashCode(
return result; return result;
} }
struct SamplerDescriptorSetCache struct ImageDescriptorSetCache
{ {
VkDescriptorSetLayout descriptorSetLayout; VkDescriptorSetLayout descriptorSetLayout;
uint32_t samplerBindingCount; uint32_t bindingCount;
SamplerDescriptorSetHashArray buckets[NUM_DESCRIPTOR_SET_HASH_BUCKETS]; /* these buckets store indices */ ImageDescriptorSetHashArray buckets[NUM_DESCRIPTOR_SET_HASH_BUCKETS]; /* these buckets store indices */
SamplerDescriptorSetHashMap *elements; /* where the hash map elements are stored */ ImageDescriptorSetHashMap *elements; /* where the hash map elements are stored */
uint32_t count; uint32_t count;
uint32_t capacity; uint32_t capacity;
VkDescriptorPool *samplerDescriptorPools; VkDescriptorPool *imageDescriptorPools;
uint32_t samplerDescriptorPoolCount; uint32_t imageDescriptorPoolCount;
uint32_t nextPoolSize; uint32_t nextPoolSize;
VkDescriptorSet *inactiveDescriptorSets; VkDescriptorSet *inactiveDescriptorSets;
@ -2217,7 +2217,7 @@ static void VULKAN_INTERNAL_DestroyTextureStagingBuffer(
static void VULKAN_INTERNAL_DestroySamplerDescriptorSetCache( static void VULKAN_INTERNAL_DestroySamplerDescriptorSetCache(
VulkanRenderer* renderer, VulkanRenderer* renderer,
SamplerDescriptorSetCache* cache ImageDescriptorSetCache* cache
) { ) {
uint32_t i; uint32_t i;
@ -2226,16 +2226,16 @@ static void VULKAN_INTERNAL_DestroySamplerDescriptorSetCache(
return; return;
} }
for (i = 0; i < cache->samplerDescriptorPoolCount; i += 1) for (i = 0; i < cache->imageDescriptorPoolCount; i += 1)
{ {
renderer->vkDestroyDescriptorPool( renderer->vkDestroyDescriptorPool(
renderer->logicalDevice, renderer->logicalDevice,
cache->samplerDescriptorPools[i], cache->imageDescriptorPools[i],
NULL NULL
); );
} }
SDL_free(cache->samplerDescriptorPools); SDL_free(cache->imageDescriptorPools);
SDL_free(cache->inactiveDescriptorSets); SDL_free(cache->inactiveDescriptorSets);
SDL_free(cache->elements); SDL_free(cache->elements);
@ -3868,57 +3868,57 @@ static uint8_t VULKAN_INTERNAL_AllocateSamplerDescriptorSets(
return 1; return 1;
} }
static SamplerDescriptorSetCache* VULKAN_INTERNAL_CreateSamplerDescriptorSetCache( static ImageDescriptorSetCache* VULKAN_INTERNAL_CreateImageDescriptorSetCache(
VulkanRenderer *renderer, VulkanRenderer *renderer,
VkDescriptorSetLayout descriptorSetLayout, VkDescriptorSetLayout descriptorSetLayout,
uint32_t samplerBindingCount uint32_t bindingCount
) { ) {
uint32_t i; uint32_t i;
SamplerDescriptorSetCache *samplerDescriptorSetCache = SDL_malloc(sizeof(SamplerDescriptorSetCache)); ImageDescriptorSetCache *imageDescriptorSetCache = SDL_malloc(sizeof(ImageDescriptorSetCache));
samplerDescriptorSetCache->elements = SDL_malloc(sizeof(SamplerDescriptorSetHashMap) * 16); imageDescriptorSetCache->elements = SDL_malloc(sizeof(ImageDescriptorSetHashMap) * 16);
samplerDescriptorSetCache->count = 0; imageDescriptorSetCache->count = 0;
samplerDescriptorSetCache->capacity = 16; imageDescriptorSetCache->capacity = 16;
for (i = 0; i < NUM_DESCRIPTOR_SET_HASH_BUCKETS; i += 1) for (i = 0; i < NUM_DESCRIPTOR_SET_HASH_BUCKETS; i += 1)
{ {
samplerDescriptorSetCache->buckets[i].elements = NULL; imageDescriptorSetCache->buckets[i].elements = NULL;
samplerDescriptorSetCache->buckets[i].count = 0; imageDescriptorSetCache->buckets[i].count = 0;
samplerDescriptorSetCache->buckets[i].capacity = 0; imageDescriptorSetCache->buckets[i].capacity = 0;
} }
samplerDescriptorSetCache->descriptorSetLayout = descriptorSetLayout; imageDescriptorSetCache->descriptorSetLayout = descriptorSetLayout;
samplerDescriptorSetCache->samplerBindingCount = samplerBindingCount; imageDescriptorSetCache->bindingCount = bindingCount;
samplerDescriptorSetCache->samplerDescriptorPools = SDL_malloc(sizeof(VkDescriptorPool)); imageDescriptorSetCache->imageDescriptorPools = SDL_malloc(sizeof(VkDescriptorPool));
samplerDescriptorSetCache->samplerDescriptorPoolCount = 1; imageDescriptorSetCache->imageDescriptorPoolCount = 1;
VULKAN_INTERNAL_CreateSamplerDescriptorPool( VULKAN_INTERNAL_CreateSamplerDescriptorPool(
renderer, renderer,
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
SAMPLER_POOL_STARTING_SIZE, SAMPLER_POOL_STARTING_SIZE,
SAMPLER_POOL_STARTING_SIZE * samplerBindingCount, SAMPLER_POOL_STARTING_SIZE * bindingCount,
&samplerDescriptorSetCache->samplerDescriptorPools[0] &imageDescriptorSetCache->imageDescriptorPools[0]
); );
samplerDescriptorSetCache->samplerDescriptorPoolCount = 1; imageDescriptorSetCache->imageDescriptorPoolCount = 1;
samplerDescriptorSetCache->nextPoolSize = SAMPLER_POOL_STARTING_SIZE * 2; imageDescriptorSetCache->nextPoolSize = SAMPLER_POOL_STARTING_SIZE * 2;
samplerDescriptorSetCache->inactiveDescriptorSetCapacity = SAMPLER_POOL_STARTING_SIZE; imageDescriptorSetCache->inactiveDescriptorSetCapacity = SAMPLER_POOL_STARTING_SIZE;
samplerDescriptorSetCache->inactiveDescriptorSetCount = SAMPLER_POOL_STARTING_SIZE; imageDescriptorSetCache->inactiveDescriptorSetCount = SAMPLER_POOL_STARTING_SIZE;
samplerDescriptorSetCache->inactiveDescriptorSets = SDL_malloc( imageDescriptorSetCache->inactiveDescriptorSets = SDL_malloc(
sizeof(VkDescriptorSet) * SAMPLER_POOL_STARTING_SIZE sizeof(VkDescriptorSet) * SAMPLER_POOL_STARTING_SIZE
); );
VULKAN_INTERNAL_AllocateSamplerDescriptorSets( VULKAN_INTERNAL_AllocateSamplerDescriptorSets(
renderer, renderer,
samplerDescriptorSetCache->samplerDescriptorPools[0], imageDescriptorSetCache->imageDescriptorPools[0],
samplerDescriptorSetCache->descriptorSetLayout, imageDescriptorSetCache->descriptorSetLayout,
SAMPLER_POOL_STARTING_SIZE, SAMPLER_POOL_STARTING_SIZE,
samplerDescriptorSetCache->inactiveDescriptorSets imageDescriptorSetCache->inactiveDescriptorSets
); );
return samplerDescriptorSetCache; return imageDescriptorSetCache;
} }
static VkDescriptorSetLayout VULKAN_INTERNAL_FetchDescriptorSetLayout( static VkDescriptorSetLayout VULKAN_INTERNAL_FetchDescriptorSetLayout(
@ -4094,7 +4094,7 @@ static VulkanGraphicsPipelineLayout* VULKAN_INTERNAL_FetchGraphicsPipelineLayout
else else
{ {
vulkanGraphicsPipelineLayout->vertexSamplerDescriptorSetCache = vulkanGraphicsPipelineLayout->vertexSamplerDescriptorSetCache =
VULKAN_INTERNAL_CreateSamplerDescriptorSetCache( VULKAN_INTERNAL_CreateImageDescriptorSetCache(
renderer, renderer,
pipelineLayoutHash.vertexSamplerLayout, pipelineLayoutHash.vertexSamplerLayout,
vertexSamplerBindingCount vertexSamplerBindingCount
@ -4108,7 +4108,7 @@ static VulkanGraphicsPipelineLayout* VULKAN_INTERNAL_FetchGraphicsPipelineLayout
else else
{ {
vulkanGraphicsPipelineLayout->fragmentSamplerDescriptorSetCache = vulkanGraphicsPipelineLayout->fragmentSamplerDescriptorSetCache =
VULKAN_INTERNAL_CreateSamplerDescriptorSetCache( VULKAN_INTERNAL_CreateImageDescriptorSetCache(
renderer, renderer,
pipelineLayoutHash.fragmentSamplerLayout, pipelineLayoutHash.fragmentSamplerLayout,
fragmentSamplerBindingCount fragmentSamplerBindingCount
@ -4579,7 +4579,7 @@ static VulkanComputePipelineLayout* VULKAN_INTERNAL_FetchComputePipelineLayout(
pipelineLayoutHash.imageLayout = VULKAN_INTERNAL_FetchDescriptorSetLayout( pipelineLayoutHash.imageLayout = VULKAN_INTERNAL_FetchDescriptorSetLayout(
renderer, renderer,
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
imageBindingCount, imageBindingCount,
VK_SHADER_STAGE_COMPUTE_BIT VK_SHADER_STAGE_COMPUTE_BIT
); );
@ -4652,7 +4652,7 @@ static VulkanComputePipelineLayout* VULKAN_INTERNAL_FetchComputePipelineLayout(
else else
{ {
vulkanComputePipelineLayout->imageDescriptorSetCache = vulkanComputePipelineLayout->imageDescriptorSetCache =
VULKAN_INTERNAL_CreateComputeImageDescriptorSetSetCache( VULKAN_INTERNAL_CreateImageDescriptorSetCache(
renderer, renderer,
pipelineLayoutHash.imageLayout, pipelineLayoutHash.imageLayout,
imageBindingCount imageBindingCount
@ -6009,8 +6009,8 @@ static uint32_t VULKAN_PushFragmentShaderParams(
} }
static inline uint8_t SamplerDescriptorSetDataEqual( static inline uint8_t SamplerDescriptorSetDataEqual(
SamplerDescriptorSetData *a, ImageDescriptorSetData *a,
SamplerDescriptorSetData *b, ImageDescriptorSetData *b,
uint8_t samplerCount uint8_t samplerCount
) { ) {
uint32_t i; uint32_t i;
@ -6030,29 +6030,29 @@ static inline uint8_t SamplerDescriptorSetDataEqual(
static VkDescriptorSet VULKAN_INTERNAL_FetchSamplerDescriptorSet( static VkDescriptorSet VULKAN_INTERNAL_FetchSamplerDescriptorSet(
VulkanRenderer *renderer, VulkanRenderer *renderer,
SamplerDescriptorSetCache *samplerDescriptorSetCache, ImageDescriptorSetCache *imageDescriptorSetCache,
SamplerDescriptorSetData *samplerDescriptorSetData ImageDescriptorSetData *samplerDescriptorSetData
) { ) {
uint32_t i; uint32_t i;
uint64_t hashcode; uint64_t hashcode;
SamplerDescriptorSetHashArray *arr; ImageDescriptorSetHashArray *arr;
VkDescriptorSet newDescriptorSet; VkDescriptorSet newDescriptorSet;
VkWriteDescriptorSet writeDescriptorSets[MAX_TEXTURE_SAMPLERS]; VkWriteDescriptorSet writeDescriptorSets[MAX_TEXTURE_SAMPLERS];
SamplerDescriptorSetHashMap *map; ImageDescriptorSetHashMap *map;
hashcode = SamplerDescriptorSetHashTable_GetHashCode( hashcode = ImageDescriptorSetHashTable_GetHashCode(
samplerDescriptorSetData, samplerDescriptorSetData,
samplerDescriptorSetCache->samplerBindingCount imageDescriptorSetCache->bindingCount
); );
arr = &samplerDescriptorSetCache->buckets[hashcode % NUM_DESCRIPTOR_SET_HASH_BUCKETS]; arr = &imageDescriptorSetCache->buckets[hashcode % NUM_DESCRIPTOR_SET_HASH_BUCKETS];
for (i = 0; i < arr->count; i += 1) for (i = 0; i < arr->count; i += 1)
{ {
SamplerDescriptorSetHashMap *e = &samplerDescriptorSetCache->elements[arr->elements[i]]; ImageDescriptorSetHashMap *e = &imageDescriptorSetCache->elements[arr->elements[i]];
if (SamplerDescriptorSetDataEqual( if (SamplerDescriptorSetDataEqual(
samplerDescriptorSetData, samplerDescriptorSetData,
&e->descriptorSetData, &e->descriptorSetData,
samplerDescriptorSetCache->samplerBindingCount imageDescriptorSetCache->bindingCount
)) { )) {
e->inactiveFrameCount = 0; e->inactiveFrameCount = 0;
return e->descriptorSet; return e->descriptorSet;
@ -6062,46 +6062,46 @@ static VkDescriptorSet VULKAN_INTERNAL_FetchSamplerDescriptorSet(
/* If no match exists, assign a new descriptor set and prepare it for update */ /* If no match exists, assign a new descriptor set and prepare it for update */
/* If no inactive descriptor sets remain, create a new pool and allocate new inactive sets */ /* If no inactive descriptor sets remain, create a new pool and allocate new inactive sets */
if (samplerDescriptorSetCache->inactiveDescriptorSetCount == 0) if (imageDescriptorSetCache->inactiveDescriptorSetCount == 0)
{ {
samplerDescriptorSetCache->samplerDescriptorPoolCount += 1; imageDescriptorSetCache->imageDescriptorPoolCount += 1;
samplerDescriptorSetCache->samplerDescriptorPools = SDL_realloc( imageDescriptorSetCache->imageDescriptorPools = SDL_realloc(
samplerDescriptorSetCache->samplerDescriptorPools, imageDescriptorSetCache->imageDescriptorPools,
sizeof(VkDescriptorPool) * samplerDescriptorSetCache->samplerDescriptorPoolCount sizeof(VkDescriptorPool) * imageDescriptorSetCache->imageDescriptorPoolCount
); );
VULKAN_INTERNAL_CreateSamplerDescriptorPool( VULKAN_INTERNAL_CreateSamplerDescriptorPool(
renderer, renderer,
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
samplerDescriptorSetCache->nextPoolSize, imageDescriptorSetCache->nextPoolSize,
samplerDescriptorSetCache->nextPoolSize * samplerDescriptorSetCache->samplerBindingCount, imageDescriptorSetCache->nextPoolSize * imageDescriptorSetCache->bindingCount,
&samplerDescriptorSetCache->samplerDescriptorPools[samplerDescriptorSetCache->samplerDescriptorPoolCount - 1] &imageDescriptorSetCache->imageDescriptorPools[imageDescriptorSetCache->imageDescriptorPoolCount - 1]
); );
samplerDescriptorSetCache->inactiveDescriptorSetCapacity += samplerDescriptorSetCache->nextPoolSize; imageDescriptorSetCache->inactiveDescriptorSetCapacity += imageDescriptorSetCache->nextPoolSize;
samplerDescriptorSetCache->inactiveDescriptorSets = SDL_realloc( imageDescriptorSetCache->inactiveDescriptorSets = SDL_realloc(
samplerDescriptorSetCache->inactiveDescriptorSets, imageDescriptorSetCache->inactiveDescriptorSets,
sizeof(VkDescriptorSet) * samplerDescriptorSetCache->inactiveDescriptorSetCapacity sizeof(VkDescriptorSet) * imageDescriptorSetCache->inactiveDescriptorSetCapacity
); );
VULKAN_INTERNAL_AllocateSamplerDescriptorSets( VULKAN_INTERNAL_AllocateSamplerDescriptorSets(
renderer, renderer,
samplerDescriptorSetCache->samplerDescriptorPools[samplerDescriptorSetCache->samplerDescriptorPoolCount - 1], imageDescriptorSetCache->imageDescriptorPools[imageDescriptorSetCache->imageDescriptorPoolCount - 1],
samplerDescriptorSetCache->descriptorSetLayout, imageDescriptorSetCache->descriptorSetLayout,
samplerDescriptorSetCache->nextPoolSize, imageDescriptorSetCache->nextPoolSize,
samplerDescriptorSetCache->inactiveDescriptorSets imageDescriptorSetCache->inactiveDescriptorSets
); );
samplerDescriptorSetCache->inactiveDescriptorSetCount = samplerDescriptorSetCache->nextPoolSize; imageDescriptorSetCache->inactiveDescriptorSetCount = imageDescriptorSetCache->nextPoolSize;
samplerDescriptorSetCache->nextPoolSize *= 2; imageDescriptorSetCache->nextPoolSize *= 2;
} }
newDescriptorSet = samplerDescriptorSetCache->inactiveDescriptorSets[samplerDescriptorSetCache->inactiveDescriptorSetCount - 1]; newDescriptorSet = imageDescriptorSetCache->inactiveDescriptorSets[imageDescriptorSetCache->inactiveDescriptorSetCount - 1];
samplerDescriptorSetCache->inactiveDescriptorSetCount -= 1; imageDescriptorSetCache->inactiveDescriptorSetCount -= 1;
for (i = 0; i < samplerDescriptorSetCache->samplerBindingCount; i += 1) for (i = 0; i < imageDescriptorSetCache->bindingCount; i += 1)
{ {
writeDescriptorSets[i].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeDescriptorSets[i].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeDescriptorSets[i].pNext = NULL; writeDescriptorSets[i].pNext = NULL;
@ -6116,30 +6116,30 @@ static VkDescriptorSet VULKAN_INTERNAL_FetchSamplerDescriptorSet(
renderer->vkUpdateDescriptorSets( renderer->vkUpdateDescriptorSets(
renderer->logicalDevice, renderer->logicalDevice,
samplerDescriptorSetCache->samplerBindingCount, imageDescriptorSetCache->bindingCount,
writeDescriptorSets, writeDescriptorSets,
0, 0,
NULL NULL
); );
EXPAND_ELEMENTS_IF_NEEDED(arr, 2, uint32_t) EXPAND_ELEMENTS_IF_NEEDED(arr, 2, uint32_t)
arr->elements[arr->count] = samplerDescriptorSetCache->count; arr->elements[arr->count] = imageDescriptorSetCache->count;
arr->count += 1; arr->count += 1;
if (samplerDescriptorSetCache->count == samplerDescriptorSetCache->capacity) if (imageDescriptorSetCache->count == imageDescriptorSetCache->capacity)
{ {
samplerDescriptorSetCache->capacity *= 2; imageDescriptorSetCache->capacity *= 2;
samplerDescriptorSetCache->elements = SDL_realloc( imageDescriptorSetCache->elements = SDL_realloc(
samplerDescriptorSetCache->elements, imageDescriptorSetCache->elements,
sizeof(SamplerDescriptorSetHashMap) * samplerDescriptorSetCache->capacity sizeof(ImageDescriptorSetHashMap) * imageDescriptorSetCache->capacity
); );
} }
map = &samplerDescriptorSetCache->elements[samplerDescriptorSetCache->count]; map = &imageDescriptorSetCache->elements[imageDescriptorSetCache->count];
map->key = hashcode; map->key = hashcode;
for (i = 0; i < samplerDescriptorSetCache->samplerBindingCount; i += 1) for (i = 0; i < imageDescriptorSetCache->bindingCount; i += 1)
{ {
map->descriptorSetData.descriptorImageInfo[i].imageLayout = map->descriptorSetData.descriptorImageInfo[i].imageLayout =
samplerDescriptorSetData->descriptorImageInfo[i].imageLayout; samplerDescriptorSetData->descriptorImageInfo[i].imageLayout;
@ -6151,7 +6151,7 @@ static VkDescriptorSet VULKAN_INTERNAL_FetchSamplerDescriptorSet(
map->descriptorSet = newDescriptorSet; map->descriptorSet = newDescriptorSet;
map->inactiveFrameCount = 0; map->inactiveFrameCount = 0;
samplerDescriptorSetCache->count += 1; imageDescriptorSetCache->count += 1;
return newDescriptorSet; return newDescriptorSet;
} }
@ -6166,14 +6166,14 @@ static void VULKAN_SetVertexSamplers(
VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanRenderer* renderer = (VulkanRenderer*) driverData;
VulkanGraphicsPipeline *graphicsPipeline = renderer->currentGraphicsPipeline; VulkanGraphicsPipeline *graphicsPipeline = renderer->currentGraphicsPipeline;
SamplerDescriptorSetData vertexSamplerDescriptorSetData; ImageDescriptorSetData vertexSamplerDescriptorSetData;
if (graphicsPipeline->pipelineLayout->vertexSamplerDescriptorSetCache == NULL) if (graphicsPipeline->pipelineLayout->vertexSamplerDescriptorSetCache == NULL)
{ {
return; return;
} }
samplerCount = graphicsPipeline->pipelineLayout->vertexSamplerDescriptorSetCache->samplerBindingCount; samplerCount = graphicsPipeline->pipelineLayout->vertexSamplerDescriptorSetCache->bindingCount;
for (i = 0; i < samplerCount; i += 1) for (i = 0; i < samplerCount; i += 1)
{ {
@ -6200,14 +6200,14 @@ static void VULKAN_SetFragmentSamplers(
VulkanRenderer* renderer = (VulkanRenderer*) driverData; VulkanRenderer* renderer = (VulkanRenderer*) driverData;
VulkanGraphicsPipeline *graphicsPipeline = renderer->currentGraphicsPipeline; VulkanGraphicsPipeline *graphicsPipeline = renderer->currentGraphicsPipeline;
SamplerDescriptorSetData fragmentSamplerDescriptorSetData; ImageDescriptorSetData fragmentSamplerDescriptorSetData;
if (graphicsPipeline->pipelineLayout->fragmentSamplerDescriptorSetCache == NULL) if (graphicsPipeline->pipelineLayout->fragmentSamplerDescriptorSetCache == NULL)
{ {
return; return;
} }
samplerCount = graphicsPipeline->pipelineLayout->fragmentSamplerDescriptorSetCache->samplerBindingCount; samplerCount = graphicsPipeline->pipelineLayout->fragmentSamplerDescriptorSetCache->bindingCount;
for (i = 0; i < samplerCount; i += 1) for (i = 0; i < samplerCount; i += 1)
{ {
@ -6989,18 +6989,18 @@ static void VULKAN_QueuePresent(
} }
static void VULKAN_INTERNAL_DeactivateUnusedDescriptorSets( static void VULKAN_INTERNAL_DeactivateUnusedDescriptorSets(
SamplerDescriptorSetCache *samplerDescriptorSetCache ImageDescriptorSetCache *imageDescriptorSetCache
) { ) {
int32_t i, j; int32_t i, j;
SamplerDescriptorSetHashArray *arr; ImageDescriptorSetHashArray *arr;
for (i = samplerDescriptorSetCache->count - 1; i >= 0; i -= 1) for (i = imageDescriptorSetCache->count - 1; i >= 0; i -= 1)
{ {
samplerDescriptorSetCache->elements[i].inactiveFrameCount += 1; imageDescriptorSetCache->elements[i].inactiveFrameCount += 1;
if (samplerDescriptorSetCache->elements[i].inactiveFrameCount + 1 > DESCRIPTOR_SET_DEACTIVATE_FRAMES) if (imageDescriptorSetCache->elements[i].inactiveFrameCount + 1 > DESCRIPTOR_SET_DEACTIVATE_FRAMES)
{ {
arr = &samplerDescriptorSetCache->buckets[samplerDescriptorSetCache->elements[i].key % NUM_DESCRIPTOR_SET_HASH_BUCKETS]; arr = &imageDescriptorSetCache->buckets[imageDescriptorSetCache->elements[i].key % NUM_DESCRIPTOR_SET_HASH_BUCKETS];
/* remove index from bucket */ /* remove index from bucket */
for (j = 0; j < arr->count; j += 1) for (j = 0; j < arr->count; j += 1)
@ -7019,20 +7019,20 @@ static void VULKAN_INTERNAL_DeactivateUnusedDescriptorSets(
/* remove element from table and place in inactive sets */ /* remove element from table and place in inactive sets */
samplerDescriptorSetCache->inactiveDescriptorSets[samplerDescriptorSetCache->inactiveDescriptorSetCount] = samplerDescriptorSetCache->elements[i].descriptorSet; imageDescriptorSetCache->inactiveDescriptorSets[imageDescriptorSetCache->inactiveDescriptorSetCount] = imageDescriptorSetCache->elements[i].descriptorSet;
samplerDescriptorSetCache->inactiveDescriptorSetCount += 1; imageDescriptorSetCache->inactiveDescriptorSetCount += 1;
/* move another descriptor set to fill the hole */ /* move another descriptor set to fill the hole */
if (i < samplerDescriptorSetCache->count - 1) if (i < imageDescriptorSetCache->count - 1)
{ {
samplerDescriptorSetCache->elements[i] = samplerDescriptorSetCache->elements[samplerDescriptorSetCache->count - 1]; imageDescriptorSetCache->elements[i] = imageDescriptorSetCache->elements[imageDescriptorSetCache->count - 1];
/* update index in bucket */ /* update index in bucket */
arr = &samplerDescriptorSetCache->buckets[samplerDescriptorSetCache->elements[i].key % NUM_DESCRIPTOR_SET_HASH_BUCKETS]; arr = &imageDescriptorSetCache->buckets[imageDescriptorSetCache->elements[i].key % NUM_DESCRIPTOR_SET_HASH_BUCKETS];
for (j = 0; j < arr->count; j += 1) for (j = 0; j < arr->count; j += 1)
{ {
if (arr->elements[j] == samplerDescriptorSetCache->count - 1) if (arr->elements[j] == imageDescriptorSetCache->count - 1)
{ {
arr->elements[j] = i; arr->elements[j] = i;
break; break;
@ -7040,7 +7040,7 @@ static void VULKAN_INTERNAL_DeactivateUnusedDescriptorSets(
} }
} }
samplerDescriptorSetCache->count -= 1; imageDescriptorSetCache->count -= 1;
} }
} }
} }