Skip to content

Commit

Permalink
Reworkd extension file generator to move extension structure allocati…
Browse files Browse the repository at this point in the history
…on to the heap

Some of the functions have become dangerously large and some compilers threw warnings with them getting too large for the stack
  • Loading branch information
SaschaWillems committed Oct 25, 2023
1 parent 23b3561 commit de8ec7a
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions tools/deviceExtensionsFileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ public function generateFeatures2CodeBlock($extension)
$sType = TypeContainer::getsType($extension->features2);
$res = "\tif (extensionSupported(\"{$extension->name}\")) {\n";
$res .= "\t\tconst char* extension(\"{$extension->name}\");\n";
$res .= "\t\t{$extension->features2['name']} extFeatures { $sType };\n";
$res .= "\t\tVkPhysicalDeviceFeatures2 deviceFeatures2(initDeviceFeatures2(&extFeatures));\n";
$res .= "\t\t{$extension->features2['name']}* extFeatures = new {$extension->features2['name']}{};\n";
$res .= "\t\textFeatures->sType = $sType;\n";
$res .= "\t\tdeviceFeatures2 = initDeviceFeatures2(extFeatures);\n";
$res .= "\t\tvulkanContext.vkGetPhysicalDeviceFeatures2KHR(device, &deviceFeatures2);\n";
foreach ($extension->features2->member as $member) {
// Skip types that are not related to feature details
Expand All @@ -177,8 +178,9 @@ public function generateFeatures2CodeBlock($extension)
continue;
}
$name = (string)$member->name;
$res .= "\t\tpushFeature2(extension, \"$name\", extFeatures.$name);\n";
$res .= "\t\tpushFeature2(extension, \"$name\", extFeatures->$name);\n";
}
$res .= "\t\tdelete extFeatures;\n";
$res .= "\t}\n";
return $res;
}
Expand All @@ -188,8 +190,9 @@ public function generateProperties2CodeBlock($extension)
$sType = TypeContainer::getsType($extension->properties2);
$res = "\tif (extensionSupported(\"{$extension->name}\")) {\n";
$res .= "\t\tconst char* extension(\"{$extension->name}\");\n";
$res .= "\t\t{$extension->properties2['name']} extProps { $sType };\n";
$res .= "\t\tVkPhysicalDeviceProperties2 deviceProps2(initDeviceProperties2(&extProps));\n";
$res .= "\t\t{$extension->properties2['name']}* extProps = new {$extension->properties2['name']}{};\n";
$res .= "\t\textProps->sType = $sType;\n";
$res .= "\t\tdeviceProps2 = initDeviceProperties2(extProps);\n";
$res .= "\t\tvulkanContext.vkGetPhysicalDeviceProperties2KHR(device, &deviceProps2);\n";
// @todo: QVariant vs. QVariant::fromValue
foreach ($extension->properties2->member as $member) {
Expand All @@ -201,11 +204,11 @@ public function generateProperties2CodeBlock($extension)
$name = (string)$member->name;
$vktype = (string)$member->type;
if ($type == "VkExtent2D") {
$res .= "\t\tpushProperty2(extension, \"$name\", QVariant::fromValue(QVariantList({ extProps.$name.width, extProps.$name.height })));\n";
$res .= "\t\tpushProperty2(extension, \"$name\", QVariant::fromValue(QVariantList({ extProps->$name.width, extProps->$name.height })));\n";
continue;
}
if ($type == "size_t") {
$res .= "\t\tpushProperty2(extension, \"$name\", QVariant::fromValue(extProps.$name));\n";
$res .= "\t\tpushProperty2(extension, \"$name\", QVariant::fromValue(extProps->$name));\n";
continue;
}
// Properties can be arrays
Expand All @@ -227,7 +230,7 @@ public function generateProperties2CodeBlock($extension)
break;
}
if ($enum_dim > 0) {
$res .= "\t\tpushProperty2(extension, \"$name\", QVariant::fromValue(arrayToQVariantList(extProps.$name, $enum_dim)));\n";
$res .= "\t\tpushProperty2(extension, \"$name\", QVariant::fromValue(arrayToQVariantList(extProps->$name, $enum_dim)));\n";
continue;
}
} else {
Expand All @@ -237,34 +240,35 @@ public function generateProperties2CodeBlock($extension)
if ($dim == 0) {
switch ($vktype) {
case 'VkBool32':
$qtype = "QVariant(bool(extProps.$name))";
$qtype = "QVariant(bool(extProps->$name))";
break;
case 'VkConformanceVersionKHR':
$qtype = "QString::fromStdString(vulkanResources::conformanceVersionKHRString(extProps.$name))";
$qtype = "QString::fromStdString(vulkanResources::conformanceVersionKHRString(extProps->$name))";
break;
case 'VkDeviceSize':
case 'int64_t':
case 'uint64_t':
case 'VkPhysicalDeviceSchedulingControlsFlagsARM':
case 'VkMemoryDecompressionMethodFlagsNV':
$qtype = "QVariant::fromValue(extProps.$name)";
$qtype = "QVariant::fromValue(extProps->$name)";
break;
case 'VkConformanceVersion':
$qtype = "QString::fromStdString(vulkanResources::conformanceVersionKHRString(extProps.$name))";
$qtype = "QString::fromStdString(vulkanResources::conformanceVersionKHRString(extProps->$name))";
break;
default:
$qtype = "QVariant(extProps.$name)";
$qtype = "QVariant(extProps->$name)";
}
$res .= "\t\tpushProperty2(extension, \"$name\", $qtype);\n";
} else {
$vars = [];
for ($i = 0; $i < $dim; $i++) {
$vars[] = "extProps." . $name . "[" . $i . "]";
$vars[] = "extProps->" . $name . "[" . $i . "]";
}
$qlist = implode(', ', $vars);
$res .= "\t\tpushProperty2(extension, \"$name\", QVariant::fromValue(QVariantList({ $qlist })));\n";
}
}
$res .= "\t\tdelete extProps;\n";
$res .= "\t}\n";
return $res;
}
Expand Down Expand Up @@ -330,6 +334,7 @@ public function writeImplementation(string $file_name, string $output_dir, $exte
});
if (count($ext_arr) > 0) {
$cpp_features_block .= "void VulkanDeviceInfoExtensions::readPhysicalFeatures_$ext_group() {\n";
$cpp_features_block .= "\tVkPhysicalDeviceFeatures2 deviceFeatures2{};\n";
if ($ext_group == 'QNX') {
$cpp_features_block .= "#if defined(VK_USE_PLATFORM_SCREEN_QNX)\n";
}
Expand All @@ -350,6 +355,7 @@ public function writeImplementation(string $file_name, string $output_dir, $exte
});
if (count($ext_arr) > 0) {
$cpp_properties_block .= "void VulkanDeviceInfoExtensions::readPhysicalProperties_$ext_group() {\n";
$cpp_properties_block .= "\tVkPhysicalDeviceProperties2 deviceProps2{};\n";
if ($ext_group == 'QNX') {
$cpp_properties_block .= "#if defined(VK_USE_PLATFORM_SCREEN_QNX)\n";
}
Expand Down

0 comments on commit de8ec7a

Please sign in to comment.