zink/codegen: add indentation to the mako templates

This regains us some much needed sanity

And it actually uncovered a bug in zink_instance.py:L306 (misplaced
%endif)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35389>
This commit is contained in:
Hoe Hao Cheng 2025-06-11 18:27:23 +08:00 committed by Marge Bot
parent a5e114ce97
commit 4eb50771e4
2 changed files with 278 additions and 280 deletions

View file

@ -360,13 +360,13 @@ REPLACEMENTS = {
# `ext.extension_name()` if `ext.guard` is True.
include_template = """
<%def name="guard_(ext, body)">
%if ext.guard:
#ifdef ${ext.extension_name()}
%endif
${capture(body)|trim}
%if ext.guard:
#endif
%endif
%if ext.guard:
#ifdef ${ext.extension_name()}
%endif
${capture(body)|trim}
%if ext.guard:
#endif
%endif
</%def>
## This ugliness is here to prevent mako from adding tons of excessive whitespace
@ -398,9 +398,9 @@ struct zink_device_info {
uint32_t device_version;
%for ext in extensions:
<%helpers:guard ext="${ext}">
bool have_${ext.name_with_vendor()};
</%helpers:guard>
<%helpers:guard ext="${ext}">
bool have_${ext.name_with_vendor()};
</%helpers:guard>
%endfor
%for version in versions:
bool have_vulkan${version.struct()};
@ -424,14 +424,14 @@ struct zink_device_info {
VkPhysicalDeviceIDProperties deviceid_props;
%for ext in extensions:
<%helpers:guard ext="${ext}">
%if ext.has_features:
${ext.physical_device_struct("Features")} ${ext.field("feats")};
%endif
%if ext.has_properties:
${ext.physical_device_struct("Properties")} ${ext.field("props")};
%endif
</%helpers:guard>
<%helpers:guard ext="${ext}">
%if ext.has_features:
${ext.physical_device_struct("Features")} ${ext.field("feats")};
%endif
%if ext.has_properties:
${ext.physical_device_struct("Properties")} ${ext.field("props")};
%endif
</%helpers:guard>
%endfor
const char *extensions[${len(extensions)}];
@ -448,11 +448,11 @@ zink_verify_device_extensions(struct zink_screen *screen);
* properly loaded.
*/
%for ext in extensions:
%if registry.in_registry(ext.name):
%for cmd in registry.get_registry_entry(ext.name).device_commands:
void VKAPI_PTR zink_stub_${cmd.name()}(void);
%endfor
%endif
%if registry.in_registry(ext.name):
%for cmd in registry.get_registry_entry(ext.name).device_commands:
void VKAPI_PTR zink_stub_${cmd.name()}(void);
%endfor
%endif
%endfor
#endif
@ -471,12 +471,12 @@ zink_get_physical_device_info(struct zink_screen *screen)
{
struct zink_device_info *info = &screen->info;
%for ext in extensions:
<%helpers:guard ext="${ext}">
bool support_${ext.name_with_vendor()} = false;
%if ext.is_promoted_to_khr:
bool support_${ext.name_with_vendor("KHR")} = false; /* promoted from EXT */
%endif
</%helpers:guard>
<%helpers:guard ext="${ext}">
bool support_${ext.name_with_vendor()} = false;
%if ext.is_promoted_to_khr:
bool support_${ext.name_with_vendor("KHR")} = false; /* promoted from EXT */
%endif
</%helpers:guard>
%endfor
uint32_t num_extensions = 0;
@ -500,25 +500,25 @@ zink_get_physical_device_info(struct zink_screen *screen)
for (uint32_t i = 0; i < num_extensions; ++i) {
%for ext in extensions:
<%helpers:guard ext="${ext}">
%if ext.is_promoted_to_khr:
bool promoted_${ext.pure_name()} = !strcmp(extensions[i].extensionName, "${ext.with_vendor("KHR")}");
if (!strcmp(extensions[i].extensionName, "${ext.name}") || promoted_${ext.pure_name()}) {
%else:
if (!strcmp(extensions[i].extensionName, "${ext.name}")) {
%endif
%if not (ext.has_features or ext.has_properties):
info->have_${ext.name_with_vendor()} = true;
%else:
support_${ext.name_with_vendor()} = true;
%endif
%if ext.is_promoted_to_khr:
if (promoted_${ext.pure_name()}) {
support_${ext.name_with_vendor("KHR")} = true;
}
%endif
}
</%helpers:guard>
<%helpers:guard ext="${ext}">
%if ext.is_promoted_to_khr:
bool promoted_${ext.pure_name()} = !strcmp(extensions[i].extensionName, "${ext.with_vendor("KHR")}");
if (!strcmp(extensions[i].extensionName, "${ext.name}") || promoted_${ext.pure_name()}) {
%else:
if (!strcmp(extensions[i].extensionName, "${ext.name}")) {
%endif
%if not (ext.has_features or ext.has_properties):
info->have_${ext.name_with_vendor()} = true;
%else:
support_${ext.name_with_vendor()} = true;
%endif
%if ext.is_promoted_to_khr:
if (promoted_${ext.pure_name()}) {
support_${ext.name_with_vendor("KHR")} = true;
}
%endif
}
</%helpers:guard>
%endfor
}
@ -532,33 +532,33 @@ zink_get_physical_device_info(struct zink_screen *screen)
info->feats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
%for version in versions:
%if version.device_version < (1,2,0):
if (VK_MAKE_VERSION(1,2,0) <= screen->vk_version) {
/* VkPhysicalDeviceVulkan11Features was added in 1.2, not 1.1 as one would think */
%else:
if (${version.version()} <= screen->vk_version) {
%endif
info->feats${version.struct()}.sType = ${version.stype("FEATURES")};
info->feats${version.struct()}.pNext = info->feats.pNext;
info->feats.pNext = &info->feats${version.struct()};
info->have_vulkan${version.struct()} = true;
}
%if version.device_version < (1,2,0):
if (VK_MAKE_VERSION(1,2,0) <= screen->vk_version) {
/* VkPhysicalDeviceVulkan11Features was added in 1.2, not 1.1 as one would think */
%else:
if (${version.version()} <= screen->vk_version) {
%endif
info->feats${version.struct()}.sType = ${version.stype("FEATURES")};
info->feats${version.struct()}.pNext = info->feats.pNext;
info->feats.pNext = &info->feats${version.struct()};
info->have_vulkan${version.struct()} = true;
}
%endfor
%for ext in extensions:
%if ext.has_features:
<%helpers:guard ext="${ext}">
%if ext.features_promoted:
if (support_${ext.name_with_vendor()} && !info->have_vulkan${ext.core_since.struct()}) {
%else:
if (support_${ext.name_with_vendor()}) {
%endif
info->${ext.field("feats")}.sType = ${ext.stype("FEATURES")};
info->${ext.field("feats")}.pNext = info->feats.pNext;
info->feats.pNext = &info->${ext.field("feats")};
}
</%helpers:guard>
%endif
%if ext.has_features:
<%helpers:guard ext="${ext}">
%if ext.features_promoted:
if (support_${ext.name_with_vendor()} && !info->have_vulkan${ext.core_since.struct()}) {
%else:
if (support_${ext.name_with_vendor()}) {
%endif
info->${ext.field("feats")}.sType = ${ext.stype("FEATURES")};
info->${ext.field("feats")}.pNext = info->feats.pNext;
info->feats.pNext = &info->${ext.field("feats")};
}
</%helpers:guard>
%endif
%endfor
screen->vk.GetPhysicalDeviceFeatures2(screen->pdev, &info->feats);
@ -573,32 +573,32 @@ zink_get_physical_device_info(struct zink_screen *screen)
props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
%for version in versions:
%if version.device_version < (1,2,0):
if (VK_MAKE_VERSION(1,2,0) <= screen->vk_version) {
/* VkPhysicalDeviceVulkan11Properties was added in 1.2, not 1.1 as one would think */
%else:
if (${version.version()} <= screen->vk_version) {
%endif
info->props${version.struct()}.sType = ${version.stype("PROPERTIES")};
info->props${version.struct()}.pNext = props.pNext;
props.pNext = &info->props${version.struct()};
}
%if version.device_version < (1,2,0):
if (VK_MAKE_VERSION(1,2,0) <= screen->vk_version) {
/* VkPhysicalDeviceVulkan11Properties was added in 1.2, not 1.1 as one would think */
%else:
if (${version.version()} <= screen->vk_version) {
%endif
info->props${version.struct()}.sType = ${version.stype("PROPERTIES")};
info->props${version.struct()}.pNext = props.pNext;
props.pNext = &info->props${version.struct()};
}
%endfor
%for ext in extensions:
%if ext.has_properties:
<%helpers:guard ext="${ext}">
%if ext.properties_promoted:
if (support_${ext.name_with_vendor()} && !info->have_vulkan${ext.core_since.struct()}) {
%else:
if (support_${ext.name_with_vendor()}) {
%endif
info->${ext.field("props")}.sType = ${ext.stype("PROPERTIES")};
info->${ext.field("props")}.pNext = props.pNext;
props.pNext = &info->${ext.field("props")};
}
</%helpers:guard>
%endif
%if ext.has_properties:
<%helpers:guard ext="${ext}">
%if ext.properties_promoted:
if (support_${ext.name_with_vendor()} && !info->have_vulkan${ext.core_since.struct()}) {
%else:
if (support_${ext.name_with_vendor()}) {
%endif
info->${ext.field("props")}.sType = ${ext.stype("PROPERTIES")};
info->${ext.field("props")}.pNext = props.pNext;
props.pNext = &info->${ext.field("props")};
}
</%helpers:guard>
%endif
%endfor
if (screen->vk_version < VK_MAKE_VERSION(1,2,0) && screen->instance_info->have_KHR_external_memory_capabilities) {
@ -653,13 +653,13 @@ zink_get_physical_device_info(struct zink_screen *screen)
* time is prohibited when using vkGetPhysicalDeviceFeatures2.
*/
%for ext in extensions:
%if ext.features_promoted:
if (info->have_vulkan${ext.core_since.struct()}) {
%for field in registry.get_registry_entry(ext.name).features_fields:
info->${ext.field("feats")}.${field} = info->feats${ext.core_since.struct()}.${field};
%endfor
}
%endif
%if ext.features_promoted:
if (info->have_vulkan${ext.core_since.struct()}) {
%for field in registry.get_registry_entry(ext.name).features_fields:
info->${ext.field("feats")}.${field} = info->feats${ext.core_since.struct()}.${field};
%endfor
}
%endif
%endfor
/* See above, but for VulkanXYProperties.
@ -668,15 +668,15 @@ zink_get_physical_device_info(struct zink_screen *screen)
* when we assign an array to another array, therefore we use an memcpy here.
*/
%for ext in extensions:
%if ext.properties_promoted:
if (info->have_vulkan${ext.core_since.struct()}) {
%for field in registry.get_registry_entry(ext.name).properties_fields:
memcpy(&info->${ext.field("props")}.${field},
&info->props${ext.core_since.struct()}.${field},
sizeof(info->${ext.field("props")}.${field}));
%endfor
}
%endif
%if ext.properties_promoted:
if (info->have_vulkan${ext.core_since.struct()}) {
%for field in registry.get_registry_entry(ext.name).properties_fields:
memcpy(&info->${ext.field("props")}.${field},
&info->props${ext.core_since.struct()}.${field},
sizeof(info->${ext.field("props")}.${field}));
%endfor
}
%endif
%endfor
if (copy_layered_props)
@ -705,23 +705,23 @@ zink_get_physical_device_info(struct zink_screen *screen)
num_extensions = 0;
%for ext in extensions:
<%helpers:guard ext="${ext}">
if (info->have_${ext.name_with_vendor()}) {
%if ext.is_promoted_to_khr:
if (support_${ext.name_with_vendor("KHR")})
info->extensions[num_extensions++] = "${ext.with_vendor("KHR")}";
else
info->extensions[num_extensions++] = "${ext.name}";
%else:
info->extensions[num_extensions++] = "${ext.name}";
%endif
%if ext.is_required:
} else {
debug_printf("ZINK: ${ext.name} required!\\n");
goto fail;
%endif
}
</%helpers:guard>
<%helpers:guard ext="${ext}">
if (info->have_${ext.name_with_vendor()}) {
%if ext.is_promoted_to_khr:
if (support_${ext.name_with_vendor("KHR")})
info->extensions[num_extensions++] = "${ext.with_vendor("KHR")}";
else
info->extensions[num_extensions++] = "${ext.name}";
%else:
info->extensions[num_extensions++] = "${ext.name}";
%endif
%if ext.is_required:
} else {
debug_printf("ZINK: ${ext.name} required!\\n");
goto fail;
%endif
}
</%helpers:guard>
%endfor
info->num_extensions = num_extensions;
@ -729,31 +729,31 @@ zink_get_physical_device_info(struct zink_screen *screen)
info->feats.pNext = NULL;
%for version in versions:
%if version.device_version < (1,2,0):
if (VK_MAKE_VERSION(1,2,0) <= screen->vk_version) {
/* VkPhysicalDeviceVulkan11Features was added in 1.2, not 1.1 as one would think */
%else:
if (${version.version()} <= screen->vk_version) {
%endif
info->feats${version.struct()}.pNext = info->feats.pNext;
info->feats.pNext = &info->feats${version.struct()};
}
%if version.device_version < (1,2,0):
if (VK_MAKE_VERSION(1,2,0) <= screen->vk_version) {
/* VkPhysicalDeviceVulkan11Features was added in 1.2, not 1.1 as one would think */
%else:
if (${version.version()} <= screen->vk_version) {
%endif
info->feats${version.struct()}.pNext = info->feats.pNext;
info->feats.pNext = &info->feats${version.struct()};
}
%endfor
%for ext in extensions:
%if ext.has_features:
<%helpers:guard ext="${ext}">
%if ext.features_promoted:
if (info->have_${ext.name_with_vendor()} && !info->have_vulkan${ext.core_since.struct()}) {
%else:
if (info->have_${ext.name_with_vendor()}) {
%endif
info->${ext.field("feats")}.sType = ${ext.stype("FEATURES")};
info->${ext.field("feats")}.pNext = info->feats.pNext;
info->feats.pNext = &info->${ext.field("feats")};
}
</%helpers:guard>
%endif
%if ext.has_features:
<%helpers:guard ext="${ext}">
%if ext.features_promoted:
if (info->have_${ext.name_with_vendor()} && !info->have_vulkan${ext.core_since.struct()}) {
%else:
if (info->have_${ext.name_with_vendor()}) {
%endif
info->${ext.field("feats")}.sType = ${ext.stype("FEATURES")};
info->${ext.field("feats")}.pNext = info->feats.pNext;
info->feats.pNext = &info->${ext.field("feats")};
}
</%helpers:guard>
%endif
%endfor
return true;
@ -766,60 +766,58 @@ void
zink_verify_device_extensions(struct zink_screen *screen)
{
%for ext in extensions:
%if registry.in_registry(ext.name):
<%helpers:guard ext="${ext}">
if (screen->info.have_${ext.name_with_vendor()}) {
%for cmd in registry.get_registry_entry(ext.name).device_commands:
%if cmd.name().find("Win32") != -1:
#ifdef _WIN32
%endif
%if ext.is_promoted_to_khr:
if (!screen->vk.${cmd.name()}) {
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})screen->vk.${cmd.name().replace("EXT", "KHR")}; /* promoted from EXT */
}
%endif
%if ext.core_since:
%if not cmd.not_promoted:
if (!screen->vk.${cmd.name().rstrip(ext.vendor())}) {
screen->vk.${cmd.name().rstrip(ext.vendor())} = screen->vk.${cmd.name()}; /* promoted to core */
}
%else:
/* ${cmd.full_name} is not promoted */
%endif
%endif
if (!screen->vk.${cmd.name()}) {
#ifndef NDEBUG
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_${cmd.name()};
#else
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_function_not_loaded;
#endif
}
%if cmd.name().find("Win32") != -1:
#endif
%endif
%endfor
}
%if ext.core_since:
else if (screen->info.have_vulkan${ext.core_since.struct()}) {
%for cmd in registry.get_registry_entry(ext.name).device_commands:
%if cmd.name().find("Win32") != -1:
#ifdef _WIN32
%endif
%if not cmd.not_promoted:
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})screen->vk.${cmd.name().rstrip(ext.vendor())};
%else:
/* ${cmd.full_name} is not promoted */
%endif
%if cmd.name().find("Win32") != -1:
#endif
%endif
%endfor
}
%endif
</%helpers:guard>
%endif
%if registry.in_registry(ext.name):
<%helpers:guard ext="${ext}">
if (screen->info.have_${ext.name_with_vendor()}) {
%for cmd in registry.get_registry_entry(ext.name).device_commands:
%if cmd.name().find("Win32") != -1:
#ifdef _WIN32
%endif
%if ext.is_promoted_to_khr:
if (!screen->vk.${cmd.name()}) {
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})screen->vk.${cmd.name().replace("EXT", "KHR")}; /* promoted from EXT */
}
%endif
%if ext.core_since:
%if not cmd.not_promoted:
if (!screen->vk.${cmd.name().rstrip(ext.vendor())}) {
screen->vk.${cmd.name().rstrip(ext.vendor())} = screen->vk.${cmd.name()}; /* promoted to core */
}
%else:
/* ${cmd.full_name} is not promoted */
%endif
%endif
if (!screen->vk.${cmd.name()}) {
#ifndef NDEBUG
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_${cmd.name()};
#else
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_function_not_loaded;
#endif
}
%if cmd.name().find("Win32") != -1:
#endif
%endif
%endfor
}
%if ext.core_since:
else if (screen->info.have_vulkan${ext.core_since.struct()}) {
%for cmd in registry.get_registry_entry(ext.name).device_commands:
%if cmd.name().find("Win32") != -1:
#ifdef _WIN32
%endif
%if not cmd.not_promoted:
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})screen->vk.${cmd.name().rstrip(ext.vendor())};
%else:
/* ${cmd.full_name} is not promoted */
%endif
%if cmd.name().find("Win32") != -1:
#endif
%endif
%endfor
}
%endif
</%helpers:guard>
%endif
%endfor
}
@ -829,25 +827,25 @@ zink_verify_device_extensions(struct zink_screen *screen)
<% generated_funcs = set() %>
%for ext in extensions:
%if registry.in_registry(ext.name):
%for cmd in registry.get_registry_entry(ext.name).device_commands:
##
## some functions are added by multiple extensions, which creates duplication
## and thus redefinition of stubs (eg. vkCmdPushDescriptorSetWithTemplateKHR)
##
%if cmd.name() in generated_funcs:
<% continue %>
%else:
<% generated_funcs.add(cmd.name()) %>
%endif
void VKAPI_PTR
zink_stub_${cmd.name()}()
{
mesa_loge("ZINK: ${cmd.full_name} is not loaded properly!");
abort();
}
%endfor
%endif
%if registry.in_registry(ext.name):
%for cmd in registry.get_registry_entry(ext.name).device_commands:
##
## some functions are added by multiple extensions, which creates duplication
## and thus redefinition of stubs (eg. vkCmdPushDescriptorSetWithTemplateKHR)
##
%if cmd.name() in generated_funcs:
<% continue %>
%else:
<% generated_funcs.add(cmd.name()) %>
%endif
void VKAPI_PTR
zink_stub_${cmd.name()}()
{
mesa_loge("ZINK: ${cmd.full_name} is not loaded properly!");
abort();
}
%endfor
%endif
%endfor
#endif
"""

View file

@ -107,14 +107,14 @@ zink_verify_instance_extensions(struct zink_screen *screen);
* properly loaded.
*/
%for ext in extensions:
%if registry.in_registry(ext.name):
%for cmd in registry.get_registry_entry(ext.name).instance_commands:
void VKAPI_PTR zink_stub_${cmd.name()}(void);
%endfor
%for cmd in registry.get_registry_entry(ext.name).pdevice_commands:
void VKAPI_PTR zink_stub_${cmd.name()}(void);
%endfor
%endif
%if registry.in_registry(ext.name):
%for cmd in registry.get_registry_entry(ext.name).instance_commands:
void VKAPI_PTR zink_stub_${cmd.name()}(void);
%endfor
%for cmd in registry.get_registry_entry(ext.name).pdevice_commands:
void VKAPI_PTR zink_stub_${cmd.name()}(void);
%endfor
%endif
%endfor
struct pipe_screen;
@ -278,34 +278,34 @@ void
zink_verify_instance_extensions(struct zink_screen *screen)
{
%for ext in extensions:
%if registry.in_registry(ext.name):
%if ext.platform_guard:
#ifdef ${ext.platform_guard}
%endif
if (screen->instance_info->have_${ext.name_with_vendor()}) {
%for cmd in registry.get_registry_entry(ext.name).instance_commands:
if (!screen->vk.${cmd.name()}) {
#ifndef NDEBUG
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_${cmd.name()};
#else
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_function_not_loaded;
#endif
}
%endfor
%for cmd in registry.get_registry_entry(ext.name).pdevice_commands:
if (!screen->vk.${cmd.name()}) {
#ifndef NDEBUG
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_${cmd.name()};
#else
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_function_not_loaded;
#endif
}
%endfor
}
%endif
%if ext.platform_guard:
#endif
%endif
%if registry.in_registry(ext.name):
%if ext.platform_guard:
#ifdef ${ext.platform_guard}
%endif
if (screen->instance_info->have_${ext.name_with_vendor()}) {
%for cmd in registry.get_registry_entry(ext.name).instance_commands:
if (!screen->vk.${cmd.name()}) {
#ifndef NDEBUG
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_${cmd.name()};
#else
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_function_not_loaded;
#endif
}
%endfor
%for cmd in registry.get_registry_entry(ext.name).pdevice_commands:
if (!screen->vk.${cmd.name()}) {
#ifndef NDEBUG
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_${cmd.name()};
#else
screen->vk.${cmd.name()} = (PFN_${cmd.full_name})zink_stub_function_not_loaded;
#endif
}
%endfor
}
%if ext.platform_guard:
#endif
%endif
%endif
%endfor
}
@ -315,27 +315,27 @@ zink_verify_instance_extensions(struct zink_screen *screen)
<% generated_funcs = set() %>
%for ext in extensions:
%if registry.in_registry(ext.name):
%for cmd in registry.get_registry_entry(ext.name).instance_commands + registry.get_registry_entry(ext.name).pdevice_commands:
%if cmd.full_name in generated_funcs:
<% continue %>
%else:
<% generated_funcs.add(cmd.full_name) %>
%endif
%if ext.platform_guard:
#ifdef ${ext.platform_guard}
%endif
void VKAPI_PTR
zink_stub_${cmd.name()}()
{
mesa_loge("ZINK: ${cmd.full_name} is not loaded properly!");
abort();
}
%if ext.platform_guard:
#endif
%endif
%endfor
%endif
%if registry.in_registry(ext.name):
%for cmd in registry.get_registry_entry(ext.name).instance_commands + registry.get_registry_entry(ext.name).pdevice_commands:
%if cmd.name in generated_funcs:
<% continue %>
%else:
<% generated_funcs.add(cmd.full_name) %>
%endif
%if ext.platform_guard:
#ifdef ${ext.platform_guard}
%endif
void VKAPI_PTR
zink_stub_${cmd.name()}()
{
mesa_loge("ZINK: ${cmd.full_name} is not loaded properly!");
abort();
}
%if ext.platform_guard:
#endif
%endif
%endfor
%endif
%endfor
#endif