From 1e3d0c863c4dda57122a3e5ceecc705209e91d69 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 10 Nov 2022 22:54:22 +0100 Subject: [PATCH] winevulkan: Don't try to convert ignored VkWriteDescriptorSet members. Fixes crash in wined3d_unordered_access_view_vk_clear(). --- dlls/winevulkan/make_vulkan | 41 +++++++++++++++++++++++++-------- dlls/winevulkan/vulkan_thunks.c | 4 ++-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/dlls/winevulkan/make_vulkan b/dlls/winevulkan/make_vulkan index 75121c8eef6..45948088fec 100755 --- a/dlls/winevulkan/make_vulkan +++ b/dlls/winevulkan/make_vulkan @@ -267,6 +267,25 @@ STRUCT_CHAIN_CONVERSIONS = { "VkInstanceCreateInfo": ["VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO"], } +# Some struct members are conditionally ignored and callers are free to leave them uninitialized. +# We can't deduce that from XML, so we allow expressing it here. +MEMBER_LENGTH_EXPRESSIONS = { + "VkWriteDescriptorSet": { + "pImageInfo": + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER || " + + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER || " + + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE || " + + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE || " + + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT || " + + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM || " + + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM ? {len} : 0", + "pBufferInfo": + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || " + + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER || " + + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || " + + "{struct}descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC ? {len} : 0", + } +} class Direction(Enum): """ Parameter direction: input, output, input_output. """ @@ -1129,12 +1148,16 @@ class VkVariable(object): parent = var.struct.members len += len_str - if not len_str in parent: - return len + if len_str in parent: + var = parent[parent.index(len_str)] + if var.is_pointer(): + len = "*" + len + + if isinstance(self.parent, VkStruct) and self.parent.name in MEMBER_LENGTH_EXPRESSIONS: + exprs = MEMBER_LENGTH_EXPRESSIONS[self.parent.name] + if self.name in exprs: + len = exprs[self.name].format(struct=prefix, len=len) - var = parent[parent.index(len_str)] - if var.is_pointer(): - len = "*" + len return len def is_const(self): @@ -1786,12 +1809,12 @@ class VkStruct(Sequence): structextends = struct.attrib.get("structextends") structextends = structextends.split(",") if structextends else [] - members = [] + s = VkStruct(name, [], returnedonly, structextends, union=union) for member in struct.findall("member"): - vk_member = VkMember.from_xml(member, returnedonly, members) - members.append(vk_member) + vk_member = VkMember.from_xml(member, returnedonly, s) + s.members.append(vk_member) - return VkStruct(name, members, returnedonly, structextends, union=union) + return s @staticmethod def decouple_structs(structs): diff --git a/dlls/winevulkan/vulkan_thunks.c b/dlls/winevulkan/vulkan_thunks.c index 6b45146fb88..d853986c9d5 100644 --- a/dlls/winevulkan/vulkan_thunks.c +++ b/dlls/winevulkan/vulkan_thunks.c @@ -3327,8 +3327,8 @@ static inline void convert_VkWriteDescriptorSet_win32_to_host(struct conversion_ out->dstArrayElement = in->dstArrayElement; out->descriptorCount = in->descriptorCount; out->descriptorType = in->descriptorType; - out->pImageInfo = convert_VkDescriptorImageInfo_array_win32_to_host(ctx, in->pImageInfo, in->descriptorCount); - out->pBufferInfo = convert_VkDescriptorBufferInfo_array_win32_to_host(ctx, in->pBufferInfo, in->descriptorCount); + out->pImageInfo = convert_VkDescriptorImageInfo_array_win32_to_host(ctx, in->pImageInfo, in->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER || in->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER || in->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE || in->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE || in->descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT || in->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM || in->descriptorType == VK_DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM ? in->descriptorCount : 0); + out->pBufferInfo = convert_VkDescriptorBufferInfo_array_win32_to_host(ctx, in->pBufferInfo, in->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER || in->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER || in->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || in->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC ? in->descriptorCount : 0); out->pTexelBufferView = in->pTexelBufferView; } #endif /* USE_STRUCT_CONVERSION */