Skip to content

Commit 2dc2afe

Browse files
guptaniki5051Android (Google) Code Review
authored andcommitted
Merge changes from topic "vkjson_fix" into main
* changes: Fix nullpointer dereference at VKJson Update vkjson codegen
2 parents f113cae + 6616c48 commit 2dc2afe

File tree

4 files changed

+69
-9
lines changed

4 files changed

+69
-9
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("""\

vulkan/vkjson/vkjson.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include <type_traits>
3737
#include <utility>
3838

39+
/*
40+
* This file is autogenerated by vkjson_generator.py. Do not edit directly.
41+
*/
3942
namespace {
4043

4144
/*

vulkan/vkjson/vkjson.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#undef max
3434
#endif
3535

36+
/*
37+
* This file is autogenerated by vkjson_generator.py. Do not edit directly.
38+
*/
3639
struct VkJsonLayer {
3740
VkLayerProperties properties;
3841
std::vector<VkExtensionProperties> extensions;
@@ -263,23 +266,41 @@ struct VkJsonKHRDriverProperties {
263266
};
264267

265268
struct VkJsonCore11 {
269+
VkJsonCore11() {
270+
memset(&properties, 0, sizeof(VkPhysicalDeviceVulkan11Properties));
271+
memset(&features, 0, sizeof(VkPhysicalDeviceVulkan11Features));
272+
}
266273
VkPhysicalDeviceVulkan11Properties properties;
267274
VkPhysicalDeviceVulkan11Features features;
268275
};
269276

270277
struct VkJsonCore12 {
278+
VkJsonCore12() {
279+
memset(&properties, 0, sizeof(VkPhysicalDeviceVulkan12Properties));
280+
memset(&features, 0, sizeof(VkPhysicalDeviceVulkan12Features));
281+
}
271282
VkPhysicalDeviceVulkan12Properties properties;
272283
VkPhysicalDeviceVulkan12Features features;
273284
};
274285

275286
struct VkJsonCore13 {
287+
VkJsonCore13() {
288+
memset(&properties, 0, sizeof(VkPhysicalDeviceVulkan13Properties));
289+
memset(&features, 0, sizeof(VkPhysicalDeviceVulkan13Features));
290+
}
276291
VkPhysicalDeviceVulkan13Properties properties;
277292
VkPhysicalDeviceVulkan13Features features;
278293
};
279294

280295
struct VkJsonCore14 {
296+
VkJsonCore14() {
297+
memset(&properties, 0, sizeof(VkPhysicalDeviceVulkan14Properties));
298+
memset(&features, 0, sizeof(VkPhysicalDeviceVulkan14Features));
299+
}
281300
VkPhysicalDeviceVulkan14Properties properties;
282301
VkPhysicalDeviceVulkan14Features features;
302+
std::vector<VkImageLayout> copy_src_layouts;
303+
std::vector<VkImageLayout> copy_dst_layouts;
283304
};
284305

285306
struct VkJsonDevice {
@@ -306,10 +327,6 @@ struct VkJsonDevice {
306327
sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
307328
memset(&shader_draw_parameter_features, 0,
308329
sizeof(VkPhysicalDeviceShaderDrawParameterFeatures));
309-
memset(&core11, 0, sizeof(VkJsonCore11));
310-
memset(&core12, 0, sizeof(VkJsonCore12));
311-
memset(&core13, 0, sizeof(VkJsonCore13));
312-
memset(&core14, 0, sizeof(VkJsonCore14));
313330
}
314331
VkJsonKHRVariablePointers khr_variable_pointers;
315332
VkJsonKHRShaderFloat16Int8 khr_shader_float16_int8;

vulkan/vkjson/vkjson_instance.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <algorithm>
2828
#include <utility>
2929

30+
/*
31+
* This file is autogenerated by vkjson_generator.py. Do not edit directly.
32+
*/
3033
namespace {
3134

3235
bool EnumerateExtensions(const char* layer_name,
@@ -512,6 +515,23 @@ VkJsonDevice VkJsonGetDevice(VkPhysicalDevice physical_device) {
512515

513516
vkGetPhysicalDeviceProperties2(physical_device, &properties);
514517

518+
if (device.core14.properties.copySrcLayoutCount > 0 ||
519+
device.core14.properties.copyDstLayoutCount > 0) {
520+
if (device.core14.properties.copySrcLayoutCount > 0) {
521+
device.core14.copy_src_layouts.resize(
522+
device.core14.properties.copySrcLayoutCount);
523+
device.core14.properties.pCopySrcLayouts =
524+
device.core14.copy_src_layouts.data();
525+
}
526+
if (device.core14.properties.copyDstLayoutCount > 0) {
527+
device.core14.copy_dst_layouts.resize(
528+
device.core14.properties.copyDstLayoutCount);
529+
device.core14.properties.pCopyDstLayouts =
530+
device.core14.copy_dst_layouts.data();
531+
}
532+
vkGetPhysicalDeviceProperties2(physical_device, &properties);
533+
}
534+
515535
device.core14.features.sType =
516536
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES;
517537
device.core14.features.pNext = features.pNext;

0 commit comments

Comments
 (0)