winevulkan: Avoid unneeded copies in struct conversion functions.

This commit is contained in:
Jacek Caban 2022-11-06 18:48:11 +01:00 committed by Alexandre Julliard
parent e3999da6d7
commit 121ca10f5d
2 changed files with 45 additions and 54 deletions

View file

@ -1190,15 +1190,16 @@ class VkVariable(object):
# those functions will be defined prior to usage by the
# 'parent' param requiring conversion.
if self.is_struct():
struct = self.struct
is_const = self.is_const() if self.is_pointer() else parent_const
conversions.extend(self.struct.get_conversions(unwrap, is_const))
conversions.extend(struct.get_conversions(unwrap, is_const))
for conv in [False, True]:
if self.needs_conversion(conv, unwrap, Direction.INPUT, parent_const):
conversions.append(StructConversionFunction(self.struct, Direction.INPUT, conv, unwrap))
if self.needs_conversion(conv, unwrap, Direction.OUTPUT, parent_const):
conversions.append(StructConversionFunction(self.struct, Direction.OUTPUT, conv, unwrap))
if struct.needs_conversion(conv, unwrap, Direction.INPUT, is_const):
conversions.append(StructConversionFunction(struct, Direction.INPUT, conv, unwrap, is_const))
if struct.needs_conversion(conv, unwrap, Direction.OUTPUT, is_const):
conversions.append(StructConversionFunction(struct, Direction.OUTPUT, conv, unwrap, is_const))
if self.is_static_array() or self.is_dynamic_array():
for conv in [False, True]:
@ -1613,13 +1614,7 @@ class VkParam(VkVariable):
""" Check if param needs conversion. """
if self.is_struct():
if self.struct.needs_conversion(conv, unwrap, direction, self.is_const()):
return True
# we needs input conversion of structs containing struct chain even if it's returnedonly
if direction == Direction.INPUT and ("pNext" in self.struct) and \
self.struct.needs_conversion(conv, unwrap, Direction.OUTPUT, self.is_const()):
return True
return False
return self.struct.needs_conversion(conv, unwrap, direction, self.is_const())
if self.is_handle():
# non-array handles are handled inline in thunks
@ -1922,6 +1917,10 @@ class VkStruct(Sequence):
continue
if m.name == "pNext":
# we need input conversion of structs containing struct chain even if it's returnedonly
if direction == Direction.INPUT and \
self.needs_conversion(conv, unwrap, Direction.OUTPUT, is_const):
return True
continue
# for non-pointer members, check for returnedonly and const attributes
@ -2014,12 +2013,13 @@ class VkStruct(Sequence):
class StructConversionFunction(object):
def __init__(self, struct, direction, conv, unwrap):
def __init__(self, struct, direction, conv, unwrap, const):
self.direction = direction
self.operand = struct
self.type = struct.name
self.conv = conv
self.unwrap = unwrap or not self.operand.needs_unwrapping()
self.const = const
name = "convert_{0}_".format(self.type)
win_type = "win32" if self.conv else "win64"
@ -2033,6 +2033,22 @@ class StructConversionFunction(object):
def __eq__(self, other):
return self.name == other.name
def member_needs_copy(self, struct, m):
if self.direction == Direction.OUTPUT:
if m.name in ["sType", "pNext"]:
return False
if self.const and not m.is_pointer():
return False
if m.is_const() and not m.needs_conversion(self.conv, self.unwrap, Direction.OUTPUT, self.const):
return False
else:
if m.name == "pNext":
return True
if m.name != "sType" and struct.returnedonly and not m.needs_conversion(
self.conv, self.unwrap, Direction.INPUT, self.const):
return False
return True
def definition(self):
""" Helper function for generating a struct conversion function. """
@ -2084,21 +2100,14 @@ class StructConversionFunction(object):
body += " if (!in) return;\n\n"
if self.direction == Direction.INPUT and "pNext" in self.operand and self.operand.returnedonly:
# We are dealing with an input_output parameter. For these we only need to copy
# pNext and sType as the other fields are filled in by the host. We do potentially
# have to iterate over pNext and perform conversions based on switch(sType)!
# Luckily though no extension structs at this point need conversion.
# TODO: support copying of pNext extension structures!
body += " out->pNext = in->pNext;\n"
body += " out->sType = in->sType;\n"
else:
for m in self.operand:
if m.name == "pNext" and needs_extensions:
body += " out->pNext = NULL;\n"
continue
for m in self.operand:
if not self.member_needs_copy(self.operand, m):
continue
if m.name == "pNext" and needs_extensions:
body += " out->pNext = NULL;\n"
continue
body += " " + m.copy("in->", "out->", self.direction, self.conv, self.unwrap)
body += " " + m.copy("in->", "out->", self.direction, self.conv, self.unwrap)
if needs_extensions:
if self.conv and self.direction == Direction.INPUT:
@ -2142,6 +2151,8 @@ class StructConversionFunction(object):
if m.name == "sType":
body += ident + "out_ext->sType = {0};\n".format(stype)
continue
if not self.member_needs_copy(ext, m):
continue
if m.name == "pNext":
body += ident + "out_ext->pNext = NULL;\n"
continue

View file

@ -5626,8 +5626,6 @@ static inline void convert_VkAccelerationStructureBuildSizesInfoKHR_host_to_win3
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
out->accelerationStructureSize = in->accelerationStructureSize;
out->updateScratchSize = in->updateScratchSize;
out->buildScratchSize = in->buildScratchSize;
@ -5673,8 +5671,8 @@ static inline void convert_VkMemoryRequirements2KHR_win32_to_host(const VkMemory
{
if (!in) return;
out->pNext = in->pNext;
out->sType = in->sType;
out->pNext = in->pNext;
}
#endif /* USE_STRUCT_CONVERSION */
@ -5683,8 +5681,6 @@ static inline void convert_VkMemoryRequirements2KHR_host_to_win32(const VkMemory
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
convert_VkMemoryRequirements_host_to_win32(&in->memoryRequirements, &out->memoryRequirements);
}
#endif /* USE_STRUCT_CONVERSION */
@ -5716,8 +5712,8 @@ static inline void convert_VkMemoryRequirements2_win32_to_host(const VkMemoryReq
{
if (!in) return;
out->pNext = in->pNext;
out->sType = in->sType;
out->pNext = in->pNext;
}
#endif /* USE_STRUCT_CONVERSION */
@ -5726,8 +5722,6 @@ static inline void convert_VkMemoryRequirements2_host_to_win32(const VkMemoryReq
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
convert_VkMemoryRequirements_host_to_win32(&in->memoryRequirements, &out->memoryRequirements);
}
#endif /* USE_STRUCT_CONVERSION */
@ -5791,8 +5785,6 @@ static inline void convert_VkDeviceFaultCountsEXT_host_to_win32(const VkDeviceFa
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
out->addressInfoCount = in->addressInfoCount;
out->vendorInfoCount = in->vendorInfoCount;
out->vendorBinarySize = in->vendorBinarySize;
@ -5936,8 +5928,8 @@ static inline void convert_VkSubresourceLayout2EXT_win32_to_host(const VkSubreso
{
if (!in) return;
out->pNext = in->pNext;
out->sType = in->sType;
out->pNext = in->pNext;
}
#endif /* USE_STRUCT_CONVERSION */
@ -5946,8 +5938,6 @@ static inline void convert_VkSubresourceLayout2EXT_host_to_win32(const VkSubreso
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
convert_VkSubresourceLayout_host_to_win32(&in->subresourceLayout, &out->subresourceLayout);
}
#endif /* USE_STRUCT_CONVERSION */
@ -5957,8 +5947,8 @@ static inline void convert_VkImageViewAddressPropertiesNVX_win32_to_host(const V
{
if (!in) return;
out->pNext = in->pNext;
out->sType = in->sType;
out->pNext = in->pNext;
}
#endif /* USE_STRUCT_CONVERSION */
@ -5967,8 +5957,6 @@ static inline void convert_VkImageViewAddressPropertiesNVX_host_to_win32(const V
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
out->deviceAddress = in->deviceAddress;
out->size = in->size;
}
@ -6005,8 +5993,6 @@ static inline void convert_VkMicromapBuildSizesInfoEXT_host_to_win32(const VkMic
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
out->micromapSize = in->micromapSize;
out->buildScratchSize = in->buildScratchSize;
out->discardable = in->discardable;
@ -6031,8 +6017,8 @@ static inline void convert_VkImageFormatProperties2_win32_to_host(const VkImageF
{
if (!in) return;
out->pNext = in->pNext;
out->sType = in->sType;
out->pNext = in->pNext;
}
#endif /* USE_STRUCT_CONVERSION */
@ -6041,8 +6027,6 @@ static inline void convert_VkImageFormatProperties2_host_to_win32(const VkImageF
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
convert_VkImageFormatProperties_host_to_win32(&in->imageFormatProperties, &out->imageFormatProperties);
}
#endif /* USE_STRUCT_CONVERSION */
@ -6088,8 +6072,8 @@ static inline void convert_VkPhysicalDeviceMemoryProperties2_win32_to_host(const
{
if (!in) return;
out->pNext = in->pNext;
out->sType = in->sType;
out->pNext = in->pNext;
}
#endif /* USE_STRUCT_CONVERSION */
@ -6098,8 +6082,6 @@ static inline void convert_VkPhysicalDeviceMemoryProperties2_host_to_win32(const
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
convert_VkPhysicalDeviceMemoryProperties_host_to_win32(&in->memoryProperties, &out->memoryProperties);
}
#endif /* USE_STRUCT_CONVERSION */
@ -6240,8 +6222,8 @@ static inline void convert_VkPhysicalDeviceProperties2_win32_to_host(const VkPhy
{
if (!in) return;
out->pNext = in->pNext;
out->sType = in->sType;
out->pNext = in->pNext;
}
#endif /* USE_STRUCT_CONVERSION */
@ -6250,8 +6232,6 @@ static inline void convert_VkPhysicalDeviceProperties2_host_to_win32(const VkPhy
{
if (!in) return;
out->sType = in->sType;
out->pNext = in->pNext;
convert_VkPhysicalDeviceProperties_host_to_win32(&in->properties, &out->properties);
}
#endif /* USE_STRUCT_CONVERSION */