From: Jason Ekstrand Date: Wed, 8 Jul 2015 21:24:56 +0000 (-0700) Subject: vk/vulkan.h: Update to the new UpdateDescriptorSets api X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d29ec8fa36dfa6565c7950dc53815a73217ae72f;p=mesa.git vk/vulkan.h: Update to the new UpdateDescriptorSets api --- diff --git a/include/vulkan/vulkan.h b/include/vulkan/vulkan.h index fd57e1ad22a..0faad2b51eb 100644 --- a/include/vulkan/vulkan.h +++ b/include/vulkan/vulkan.h @@ -211,13 +211,10 @@ typedef enum { VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER = 43, VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER = 44, VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO = 45, - VK_STRUCTURE_TYPE_UPDATE_SAMPLERS = 46, - VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES = 47, - VK_STRUCTURE_TYPE_UPDATE_IMAGES = 48, - VK_STRUCTURE_TYPE_UPDATE_BUFFERS = 49, - VK_STRUCTURE_TYPE_UPDATE_AS_COPY = 50, VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO = 51, VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO = 52, + VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, VK_ENUM_RANGE(STRUCTURE_TYPE, APPLICATION_INFO, PIPELINE_LAYOUT_CREATE_INFO) } VkStructureType; @@ -1584,6 +1581,36 @@ typedef struct { const VkDescriptorTypeCount* pTypeCount; } VkDescriptorPoolCreateInfo; +typedef struct { + VkBufferView bufferView; + VkSampler sampler; + VkImageView imageView; + VkImageLayout imageLayout; +} VkDescriptorInfo; + +typedef struct { + VkStructureType sType; + const void* pNext; + VkDescriptorSet destSet; + uint32_t destBinding; + uint32_t destArrayElement; + uint32_t count; + VkDescriptorType descriptorType; + const VkDescriptorInfo* pDescriptors; +} VkWriteDescriptorSet; + +typedef struct { + VkStructureType sType; + const void* pNext; + VkDescriptorSet srcSet; + uint32_t srcBinding; + uint32_t srcArrayElement; + VkDescriptorSet destSet; + uint32_t destBinding; + uint32_t destArrayElement; + uint32_t count; +} VkCopyDescriptorSet; + typedef struct { float originX; float originY; @@ -1814,72 +1841,6 @@ typedef struct { VkMemoryInputFlags inputMask; } VkMemoryBarrier; -typedef struct { - VkStructureType sType; - const void* pNext; - VkBufferView view; -} VkBufferViewAttachInfo; - -typedef struct { - VkStructureType sType; - const void* pNext; - VkImageView view; - VkImageLayout layout; -} VkImageViewAttachInfo; - -typedef struct { - VkStructureType sType; - const void* pNext; - uint32_t binding; - uint32_t arrayIndex; - uint32_t count; - const VkSampler* pSamplers; -} VkUpdateSamplers; - -typedef struct { - VkSampler sampler; - const VkImageViewAttachInfo* pImageView; -} VkSamplerImageViewInfo; - -typedef struct { - VkStructureType sType; - const void* pNext; - uint32_t binding; - uint32_t arrayIndex; - uint32_t count; - const VkSamplerImageViewInfo* pSamplerImageViews; -} VkUpdateSamplerTextures; - -typedef struct { - VkStructureType sType; - const void* pNext; - VkDescriptorType descriptorType; - uint32_t binding; - uint32_t arrayIndex; - uint32_t count; - const VkImageViewAttachInfo* pImageViews; -} VkUpdateImages; - -typedef struct { - VkStructureType sType; - const void* pNext; - VkDescriptorType descriptorType; - uint32_t binding; - uint32_t arrayIndex; - uint32_t count; - const VkBufferViewAttachInfo* pBufferViews; -} VkUpdateBuffers; - -typedef struct { - VkStructureType sType; - const void* pNext; - VkDescriptorType descriptorType; - VkDescriptorSet descriptorSet; - uint32_t binding; - uint32_t arrayElement; - uint32_t count; -} VkUpdateAsCopy; - typedef struct { VkStructureType sType; const void* pNext; @@ -1949,7 +1910,7 @@ typedef VkResult (VKAPI *PFN_vkCreateDescriptorSetLayout)(VkDevice device, const typedef VkResult (VKAPI *PFN_vkCreateDescriptorPool)(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool); typedef VkResult (VKAPI *PFN_vkResetDescriptorPool)(VkDevice device, VkDescriptorPool descriptorPool); typedef VkResult (VKAPI *PFN_vkAllocDescriptorSets)(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount); -typedef void (VKAPI *PFN_vkUpdateDescriptors)(VkDevice device, VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray); +typedef VkResult (VKAPI *PFN_vkUpdateDescriptorSets)(VkDevice device, uint32_t writeCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t copyCount, const VkCopyDescriptorSet* pDescriptorCopies); typedef VkResult (VKAPI *PFN_vkCreateDynamicViewportState)(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState); typedef VkResult (VKAPI *PFN_vkCreateDynamicRasterState)(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState); typedef VkResult (VKAPI *PFN_vkCreateDynamicColorBlendState)(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState); @@ -2319,11 +2280,12 @@ VkResult VKAPI vkAllocDescriptorSets( VkDescriptorSet* pDescriptorSets, uint32_t* pCount); -void VKAPI vkUpdateDescriptors( +VkResult VKAPI vkUpdateDescriptorSets( VkDevice device, - VkDescriptorSet descriptorSet, - uint32_t updateCount, - const void** ppUpdateArray); + uint32_t writeCount, + const VkWriteDescriptorSet* pDescriptorWrites, + uint32_t copyCount, + const VkCopyDescriptorSet* pDescriptorCopies); VkResult VKAPI vkCreateDynamicViewportState( VkDevice device, diff --git a/src/vulkan/device.c b/src/vulkan/device.c index f303878bc1e..379095c24da 100644 --- a/src/vulkan/device.c +++ b/src/vulkan/device.c @@ -1756,74 +1756,68 @@ VkResult anv_AllocDescriptorSets( return VK_SUCCESS; } -void anv_UpdateDescriptors( - VkDevice _device, - VkDescriptorSet descriptorSet, - uint32_t updateCount, - const void** ppUpdateArray) +VkResult anv_UpdateDescriptorSets( + VkDevice device, + uint32_t writeCount, + const VkWriteDescriptorSet* pDescriptorWrites, + uint32_t copyCount, + const VkCopyDescriptorSet* pDescriptorCopies) { - struct anv_descriptor_set *set = (struct anv_descriptor_set *) descriptorSet; - VkUpdateSamplers *update_samplers; - VkUpdateSamplerTextures *update_sampler_textures; - VkUpdateImages *update_images; - VkUpdateBuffers *update_buffers; - VkUpdateAsCopy *update_as_copy; - - for (uint32_t i = 0; i < updateCount; i++) { - const struct anv_common *common = ppUpdateArray[i]; - - switch (common->sType) { - case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS: - update_samplers = (VkUpdateSamplers *) common; + for (uint32_t i = 0; i < writeCount; i++) { + const VkWriteDescriptorSet *write = &pDescriptorWrites[i]; + ANV_FROM_HANDLE(anv_descriptor_set, set, write->destSet); - for (uint32_t j = 0; j < update_samplers->count; j++) { - set->descriptors[update_samplers->binding + j].sampler = - (struct anv_sampler *) update_samplers->pSamplers[j]; + switch (write->descriptorType) { + case VK_DESCRIPTOR_TYPE_SAMPLER: + case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: + for (uint32_t j = 0; j < write->count; j++) { + set->descriptors[write->destBinding + j].sampler = + (struct anv_sampler *) write->pDescriptors[j].sampler; } - break; - case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES: - /* FIXME: Shouldn't this be *_UPDATE_SAMPLER_IMAGES? */ - update_sampler_textures = (VkUpdateSamplerTextures *) common; - - for (uint32_t j = 0; j < update_sampler_textures->count; j++) { - set->descriptors[update_sampler_textures->binding + j].view = - (struct anv_surface_view *) - update_sampler_textures->pSamplerImageViews[j].pImageView->view; - set->descriptors[update_sampler_textures->binding + j].sampler = - (struct anv_sampler *) - update_sampler_textures->pSamplerImageViews[j].sampler; - } - break; + if (write->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) + break; - case VK_STRUCTURE_TYPE_UPDATE_IMAGES: - update_images = (VkUpdateImages *) common; + /* fallthrough */ - for (uint32_t j = 0; j < update_images->count; j++) { - set->descriptors[update_images->binding + j].view = - (struct anv_surface_view *) update_images->pImageViews[j].view; + case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: + case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: + for (uint32_t j = 0; j < write->count; j++) { + set->descriptors[write->destBinding + j].view = + (struct anv_surface_view *) write->pDescriptors[j].imageView; } break; - case VK_STRUCTURE_TYPE_UPDATE_BUFFERS: - update_buffers = (VkUpdateBuffers *) common; - - for (uint32_t j = 0; j < update_buffers->count; j++) { - set->descriptors[update_buffers->binding + j].view = - (struct anv_surface_view *) update_buffers->pBufferViews[j].view; - } - /* FIXME: descriptor arrays? */ + case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: + case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: + anv_finishme("texel buffers not implemented"); break; - case VK_STRUCTURE_TYPE_UPDATE_AS_COPY: - update_as_copy = (VkUpdateAsCopy *) common; - (void) update_as_copy; - break; + case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: + case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: + case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: + case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: + for (uint32_t j = 0; j < write->count; j++) { + set->descriptors[write->destBinding + j].view = + (struct anv_surface_view *) write->pDescriptors[j].bufferView; + } default: break; } } + + for (uint32_t i = 0; i < copyCount; i++) { + const VkCopyDescriptorSet *copy = &pDescriptorCopies[i]; + ANV_FROM_HANDLE(anv_descriptor_set, src, copy->destSet); + ANV_FROM_HANDLE(anv_descriptor_set, dest, copy->destSet); + for (uint32_t j = 0; j < copy->count; j++) { + dest->descriptors[copy->destBinding + j] = + src->descriptors[copy->srcBinding + j]; + } + } + + return VK_SUCCESS; } // State object functions diff --git a/src/vulkan/meta.c b/src/vulkan/meta.c index d28468ff173..60f263d3d8f 100644 --- a/src/vulkan/meta.c +++ b/src/vulkan/meta.c @@ -578,22 +578,24 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer, anv_AllocDescriptorSets((VkDevice) device, 0 /* pool */, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &device->meta_state.blit.ds_layout, &set, &count); - anv_UpdateDescriptors((VkDevice) device, set, 1, - (const void * []) { - &(VkUpdateImages) { - .sType = VK_STRUCTURE_TYPE_UPDATE_IMAGES, - .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - .binding = 0, + anv_UpdateDescriptorSets((VkDevice) device, + 1, /* writeCount */ + (VkWriteDescriptorSet[]) { + { + .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + .destSet = set, + .destBinding = 0, + .destArrayElement = 0, .count = 1, - .pImageViews = (VkImageViewAttachInfo[]) { + .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, + .pDescriptors = (VkDescriptorInfo[]) { { - .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO, - .view = (VkImageView) src, - .layout = VK_IMAGE_LAYOUT_GENERAL, - } + .imageView = (VkImageView) src, + .imageLayout = VK_IMAGE_LAYOUT_GENERAL + }, } } - }); + }, 0, NULL); struct anv_framebuffer *fb; anv_CreateFramebuffer((VkDevice) device,