Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe45ac6d authored by Nikita Gupta's avatar Nikita Gupta
Browse files

Update vkjson codegen

Fixing vkJson null pointer dereference for Vulkan1.4 driver
by setting array values of VkPhysicalDeviceVulkan14Properties.

Test: adb shell cmd gpu vkjson
Bug: b/403413507
Flag: NONE infeasible
Change-Id: Ibc3f77ea4606c38da008a00294546a63c83889cb
parent 961b0183
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -184,12 +184,22 @@ def generate_vk_core_struct_definition(f):
    vkJson_core_entries.append(f"{struct_name} {version.lower()}")

    f.write(f"struct {struct_name} {{\n")
    f.write(f"  {struct_name}() {{\n") # Start of constructor
    for item in items:
      for struct_type, _ in item.items():
        field_name = "properties" if "Properties" in struct_type else "features"
        f.write(f" memset(&{field_name}, 0, sizeof({struct_type}));\n")
    f.write("  }\n")  # End of constructor

    for item in items:
      for struct_type, _ in item.items():
        field_name = "properties" if "Properties" in struct_type else "features"
        f.write(f"  {struct_type} {field_name};\n")

    if version == "Core14":
      f.write(f"std::vector<VkImageLayout> copy_src_layouts;\n")
      f.write(f"std::vector<VkImageLayout> copy_dst_layouts;\n")

    f.write("};\n\n")

  return vkJson_core_entries
@@ -212,11 +222,6 @@ def generate_memset_statements(f):
    f.write(f"memset(&{variable_name}, 0, sizeof({class_name}));\n")
    entries.append(f"{class_name} {variable_name}")

  # Process vulkan core structs
  for version in VK.VULKAN_CORES_AND_STRUCTS_MAPPING["versions"]:
    struct_name = f"VkJson{version}"
    f.write(f"memset(&{version.lower()}, 0, sizeof({struct_name}));\n")

  return entries


@@ -1757,6 +1762,21 @@ VkJsonDevice VkJsonGetDevice(VkPhysicalDevice physical_device) {
  if (device.properties.apiVersion >= VK_API_VERSION_1_4) {\n""")
    f.write(cc_code_properties_14)
    f.write(f"vkGetPhysicalDeviceProperties2(physical_device, &properties);\n\n")

    f.write("""\
if (device.core14.properties.copySrcLayoutCount > 0 || device.core14.properties.copyDstLayoutCount > 0 ) {
  if (device.core14.properties.copySrcLayoutCount > 0) {
    device.core14.copy_src_layouts.resize(device.core14.properties.copySrcLayoutCount);
    device.core14.properties.pCopySrcLayouts = device.core14.copy_src_layouts.data();
  }
  if (device.core14.properties.copyDstLayoutCount > 0) {
    device.core14.copy_dst_layouts.resize(device.core14.properties.copyDstLayoutCount);
    device.core14.properties.pCopyDstLayouts = device.core14.copy_dst_layouts.data();
  }
  vkGetPhysicalDeviceProperties2(physical_device, &properties);
}
    \n""")

    f.write(cc_code_features_14)
    f.write(f"vkGetPhysicalDeviceFeatures2(physical_device, &features);\n\n")
    f.write("""\