Skip to content

Commit fe45ac6

Browse files
committed
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
1 parent 961b018 commit fe45ac6

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

vulkan/scripts/vkjson_generator.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,22 @@ def generate_vk_core_struct_definition(f):
184184
vkJson_core_entries.append(f"{struct_name} {version.lower()}")
185185

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

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

199+
if version == "Core14":
200+
f.write(f"std::vector<VkImageLayout> copy_src_layouts;\n")
201+
f.write(f"std::vector<VkImageLayout> copy_dst_layouts;\n")
202+
193203
f.write("};\n\n")
194204

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

215-
# Process vulkan core structs
216-
for version in VK.VULKAN_CORES_AND_STRUCTS_MAPPING["versions"]:
217-
struct_name = f"VkJson{version}"
218-
f.write(f"memset(&{version.lower()}, 0, sizeof({struct_name}));\n")
219-
220225
return entries
221226

222227

@@ -1757,6 +1762,21 @@ def gen_instance_cc():
17571762
if (device.properties.apiVersion >= VK_API_VERSION_1_4) {\n""")
17581763
f.write(cc_code_properties_14)
17591764
f.write(f"vkGetPhysicalDeviceProperties2(physical_device, &properties);\n\n")
1765+
1766+
f.write("""\
1767+
if (device.core14.properties.copySrcLayoutCount > 0 || device.core14.properties.copyDstLayoutCount > 0 ) {
1768+
if (device.core14.properties.copySrcLayoutCount > 0) {
1769+
device.core14.copy_src_layouts.resize(device.core14.properties.copySrcLayoutCount);
1770+
device.core14.properties.pCopySrcLayouts = device.core14.copy_src_layouts.data();
1771+
}
1772+
if (device.core14.properties.copyDstLayoutCount > 0) {
1773+
device.core14.copy_dst_layouts.resize(device.core14.properties.copyDstLayoutCount);
1774+
device.core14.properties.pCopyDstLayouts = device.core14.copy_dst_layouts.data();
1775+
}
1776+
vkGetPhysicalDeviceProperties2(physical_device, &properties);
1777+
}
1778+
\n""")
1779+
17601780
f.write(cc_code_features_14)
17611781
f.write(f"vkGetPhysicalDeviceFeatures2(physical_device, &features);\n\n")
17621782
f.write("""\

0 commit comments

Comments
 (0)