diff options
| author | Courtney Goeltzenleuchter <courtney@LunarG.com> | 2015-10-23 13:38:14 -0600 |
|---|---|---|
| committer | Courtney Goeltzenleuchter <courtney@LunarG.com> | 2015-10-26 16:24:10 -0600 |
| commit | c3ad65e09812788360a97f48a66ede6c8daebe9f (patch) | |
| tree | ba8089c17d50ece15c157e35f49e638bb132b023 | |
| parent | bc17d24f11bb1ae3ec57335d11488be9e51a2eac (diff) | |
| download | usermoji-c3ad65e09812788360a97f48a66ede6c8daebe9f.tar.xz | |
bug-14827: Remove DescriptorInfo union
The DescriptorInfo union is invalid in C++
| -rw-r--r-- | demos/cube.c | 20 | ||||
| -rw-r--r-- | demos/tri.c | 10 | ||||
| -rw-r--r-- | include/vulkan.h | 14 | ||||
| -rwxr-xr-x | layers/draw_state.cpp | 59 | ||||
| -rw-r--r-- | layers/param_checker.cpp | 8 |
5 files changed, 70 insertions, 41 deletions
diff --git a/demos/cube.c b/demos/cube.c index 91fcd8eb..b9193cb2 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -367,7 +367,7 @@ struct demo { VkBuffer buf; VkMemoryAllocInfo mem_alloc; VkDeviceMemory mem; - VkDescriptorInfo desc; + VkDescriptorBufferInfo buffer_info; } uniform_data; VkCmdBuffer cmd; // Buffer for initialization commands @@ -1234,9 +1234,9 @@ void demo_prepare_cube_data_buffer(struct demo *demo) demo->uniform_data.mem, 0); assert(!err); - demo->uniform_data.desc.bufferInfo.buffer = demo->uniform_data.buf; - demo->uniform_data.desc.bufferInfo.offset = 0; - demo->uniform_data.desc.bufferInfo.range = sizeof(data); + demo->uniform_data.buffer_info.buffer = demo->uniform_data.buf; + demo->uniform_data.buffer_info.offset = 0; + demo->uniform_data.buffer_info.range = sizeof(data); } static void demo_prepare_descriptor_layout(struct demo *demo) @@ -1643,7 +1643,7 @@ static void demo_prepare_descriptor_pool(struct demo *demo) static void demo_prepare_descriptor_set(struct demo *demo) { - VkDescriptorInfo tex_descs[DEMO_TEXTURE_COUNT]; + VkDescriptorImageInfo tex_descs[DEMO_TEXTURE_COUNT]; VkWriteDescriptorSet writes[2]; VkResult U_ASSERT_ONLY err; uint32_t i; @@ -1660,9 +1660,9 @@ static void demo_prepare_descriptor_set(struct demo *demo) memset(&tex_descs, 0, sizeof(tex_descs)); for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { - tex_descs[i].imageInfo.sampler = demo->textures[i].sampler; - tex_descs[i].imageInfo.imageView = demo->textures[i].view; - tex_descs[i].imageInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL; + tex_descs[i].sampler = demo->textures[i].sampler; + tex_descs[i].imageView = demo->textures[i].view; + tex_descs[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; } memset(&writes, 0, sizeof(writes)); @@ -1671,14 +1671,14 @@ static void demo_prepare_descriptor_set(struct demo *demo) writes[0].destSet = demo->desc_set; writes[0].count = 1; writes[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - writes[0].pDescriptors = &demo->uniform_data.desc; + writes[0].pBufferInfo = &demo->uniform_data.buffer_info; writes[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writes[1].destSet = demo->desc_set; writes[1].destBinding = 1; writes[1].count = DEMO_TEXTURE_COUNT; writes[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - writes[1].pDescriptors = tex_descs; + writes[1].pImageInfo = tex_descs; vkUpdateDescriptorSets(demo->device, 2, writes, 0, NULL); } diff --git a/demos/tri.c b/demos/tri.c index cf5f9684..87205ea6 100644 --- a/demos/tri.c +++ b/demos/tri.c @@ -1399,7 +1399,7 @@ static void demo_prepare_descriptor_pool(struct demo *demo) static void demo_prepare_descriptor_set(struct demo *demo) { - VkDescriptorInfo tex_descs[DEMO_TEXTURE_COUNT]; + VkDescriptorImageInfo tex_descs[DEMO_TEXTURE_COUNT]; VkWriteDescriptorSet write; VkResult U_ASSERT_ONLY err; uint32_t i; @@ -1416,9 +1416,9 @@ static void demo_prepare_descriptor_set(struct demo *demo) memset(&tex_descs, 0, sizeof(tex_descs)); for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { - tex_descs[i].imageInfo.sampler = demo->textures[i].sampler; - tex_descs[i].imageInfo.imageView = demo->textures[i].view; - tex_descs[i].imageInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL; + tex_descs[i].sampler = demo->textures[i].sampler; + tex_descs[i].imageView = demo->textures[i].view; + tex_descs[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; } memset(&write, 0, sizeof(write)); @@ -1426,7 +1426,7 @@ static void demo_prepare_descriptor_set(struct demo *demo) write.destSet = demo->desc_set; write.count = DEMO_TEXTURE_COUNT; write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - write.pDescriptors = tex_descs; + write.pImageInfo = tex_descs; vkUpdateDescriptorSets(demo->device, 1, &write, 0, NULL); } diff --git a/include/vulkan.h b/include/vulkan.h index e4e56553..312ed70e 100644 --- a/include/vulkan.h +++ b/include/vulkan.h @@ -1823,16 +1823,6 @@ typedef struct { VkDeviceSize range; } VkDescriptorBufferInfo; -/* TODO: this should be union, except that causes a compiler error: - * error: member 'VkDescriptorImageInfo <anonymous union>::imageInfo' with constructor not allowed in union - * This issue should go away when the change to remove the constructor lands. - */ -typedef struct { - VkDescriptorImageInfo imageInfo; - VkDescriptorBufferInfo bufferInfo; - VkBufferView texelBufferView; -} VkDescriptorInfo; - typedef struct { VkStructureType sType; const void* pNext; @@ -1841,7 +1831,9 @@ typedef struct { uint32_t destArrayElement; uint32_t count; VkDescriptorType descriptorType; - const VkDescriptorInfo* pDescriptors; + const VkDescriptorImageInfo* pImageInfo; + const VkDescriptorBufferInfo* pBufferInfo; + const VkBufferView* pTexelBufferView; } VkWriteDescriptorSet; typedef struct { diff --git a/layers/draw_state.cpp b/layers/draw_state.cpp index f0d0d937..310821c9 100755 --- a/layers/draw_state.cpp +++ b/layers/draw_state.cpp @@ -830,11 +830,40 @@ static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GEN pWDS = new VkWriteDescriptorSet; *pNewNode = (GENERIC_HEADER*)pWDS; memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet)); - /* TODO: restore new once constructors have been removed from vulkan.h */ -// pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count]; - pWDS->pDescriptors = (VkDescriptorInfo *) malloc(sizeof(VkDescriptorInfo) * pWDS->count); - array_size = sizeof(VkDescriptorInfo) * pWDS->count; - memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size); + + switch (pWDS->descriptorType) { + case VK_DESCRIPTOR_TYPE_SAMPLER: + case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: + case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: + case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: + { + VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->count]; + memcpy(info, pWDS->pImageInfo, pWDS->count * sizeof(VkDescriptorImageInfo)); + pWDS->pImageInfo = info; + } + break; + case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: + case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: + { + VkBufferView *info = new VkBufferView[pWDS->count]; + memcpy(info, pWDS->pTexelBufferView, pWDS->count * sizeof(VkBufferView)); + pWDS->pTexelBufferView = info; + } + 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: + { + VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->count]; + memcpy(info, pWDS->pBufferInfo, pWDS->count * sizeof(VkDescriptorBufferInfo)); + pWDS->pBufferInfo = info; + } + break; + default: + return VK_ERROR_VALIDATION_FAILED; + break; + } break; case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET: pCDS = new VkCopyDescriptorSet; @@ -859,13 +888,13 @@ static VkBool32 validateDescriptorSetImageView(const layer_data* my_data, VkDevi // Check ImageAspects of each descriptorSet in each writeDescriptorSet array for (uint32_t i = 0; i < writeDsCount; i++) { for (uint32_t j = 0; j < pWDS[i].count; j++) { - const VkDescriptorInfo *dInfo = &pWDS[i].pDescriptors[j]; - auto imageViewItem = dev_data->imageViewMap.find(dInfo->imageInfo.imageView.handle); + const VkDescriptorImageInfo *dInfo = &pWDS[i].pImageInfo[j]; + auto imageViewItem = dev_data->imageViewMap.find(dInfo->imageView.handle); if (imageViewItem != dev_data->imageViewMap.end()) { VkImageAspectFlags flags = ((*imageViewItem).second)->subresourceRange.aspectMask; if ((flags & VK_IMAGE_ASPECT_DEPTH_BIT) && (flags & VK_IMAGE_ASPECT_STENCIL_BIT)) { - skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE_VIEW, dInfo->imageInfo.imageView.handle, 0, + skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE_VIEW, dInfo->imageView.handle, 0, DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: DesriptorSet[%d] in WriteDesriptorSet[%d] " "has ImageView with both STENCIL and DEPTH aspects set", j, i); } @@ -877,7 +906,8 @@ static VkBool32 validateDescriptorSetImageView(const layer_data* my_data, VkDevi // update DS mappings based on ppUpdateArray // TODO : copy updates are completely broken -// TODO : Validate that actual VkDescriptorInfo in pDescriptors matches type: +// TODO : Validate that actual VkDescriptorImageInfo, VkDescriptorBufferInfo +// and VkBufferView in VkWriteDescriptorSet matches type: // pImageInfo array should be used for each descriptor if type is: // VK_DESCRIPTOR_TYPE_SAMPLER: // - uses sampler field of VkDescriptorImageInfo, @@ -1017,9 +1047,14 @@ static void freeShadowUpdateTree(SET_NODE* pSet) { case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET: pWDS = (VkWriteDescriptorSet*)pFreeUpdate; - if (pWDS->pDescriptors) { -// delete[] pWDS->pDescriptors; - free((void *) pWDS->pDescriptors); + if (pWDS->pImageInfo) { + delete[] pWDS->pImageInfo; + } + if (pWDS->pBufferInfo) { + delete[] pWDS->pBufferInfo; + } + if (pWDS->pTexelBufferView) { + delete[] pWDS->pTexelBufferView; } break; case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET: diff --git a/layers/param_checker.cpp b/layers/param_checker.cpp index dc9f8da4..793a4239 100644 --- a/layers/param_checker.cpp +++ b/layers/param_checker.cpp @@ -4783,10 +4783,12 @@ bool PreUpdateDescriptorSets( "vkUpdateDescriptorSets parameter, VkDescriptorType pDescriptorWrites->descriptorType, is an unrecognized enumerator"); return false; } - if(pDescriptorWrites->pDescriptors != nullptr) + /* TODO: Validate other parts of pImageInfo, pBufferInfo, pTexelBufferView? */ + /* TODO: This test should probably only be done if descriptorType is correct type of descriptor */ + if(pDescriptorWrites->pImageInfo != nullptr) { - if(pDescriptorWrites->pDescriptors->imageInfo.imageLayout < VK_IMAGE_LAYOUT_BEGIN_RANGE || - pDescriptorWrites->pDescriptors->imageInfo.imageLayout > VK_IMAGE_LAYOUT_END_RANGE) + if(pDescriptorWrites->pImageInfo->imageLayout < VK_IMAGE_LAYOUT_BEGIN_RANGE || + pDescriptorWrites->pImageInfo->imageLayout > VK_IMAGE_LAYOUT_END_RANGE) { log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "PARAMCHECK", "vkUpdateDescriptorSets parameter, VkImageLayout pDescriptorWrites->pDescriptors->imageLayout, is an unrecognized enumerator"); |
