Skip to content

Commit

Permalink
vulkan/utils_gen: switch from mako to jinja2
Browse files Browse the repository at this point in the history
Since jinja2 is a necessary dependency of glad2, which we depend on for
OpenGL, it makes sense to re-use that to avoid pulling in *two* string
templaters.

Also, I think, vastly more likely to be pre-installed on the system in
some fashion or another.
  • Loading branch information
haasn committed Oct 14, 2022
1 parent 5bd9d91 commit 8ae448f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ A full list of optional dependencies each feature requires:
- **lcms**: `liblcms2`
- **opengl**: `glad2` (*)
- **shaderc**: `libshaderc`
- **vulkan**: `libvulkan`, `python3-mako` (*)
- **vulkan**: `libvulkan`, `python3-jinja2` (*)

(*) This dependency is bundled automatically when doing a recursive clone.

Expand Down
58 changes: 29 additions & 29 deletions src/vulkan/utils_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@
import xml.etree.ElementTree as ET

try:
from mako.template import Template
from jinja2 import Environment
except ModuleNotFoundError:
print('Module \'mako\' not found, please install \'python3-mako\' or '
print('Module \'jinja2\' not found, please install \'python3-Jinja2\' or '
'an equivalent package on your system! Alternatively, run '
'`git submodule update --init` followed by `meson --wipe`.',
file=sys.stderr)
sys.exit(1)

TEMPLATE = Template("""
TEMPLATE = Environment(trim_blocks=True).from_string("""
#define VK_ENABLE_BETA_EXTENSIONS
#include "vulkan/utils.h"
const char *vk_res_str(VkResult res)
{
switch (res) {
%for res in vkresults:
case ${res}: return "${res}";
%endfor
{% for res in vkresults %}
case {{ res }}: return "{{ res }}";
{% endfor %}
default: return "unknown error";
}
Expand All @@ -46,9 +46,9 @@
const char *vk_fmt_name(VkFormat fmt)
{
switch (fmt) {
%for fmt in vkformats:
case ${fmt}: return "${fmt}";
%endfor
{% for fmt in vkformats %}
case {{ fmt }}: return "{{ fmt }}";
{% endfor %}
default: return "unknown format";
}
Expand All @@ -57,9 +57,9 @@
const char *vk_csp_name(VkColorSpaceKHR csp)
{
switch (csp) {
%for csp in vkspaces:
case ${csp}: return "${csp}";
%endfor
{% for csp in vkspaces %}
case {{ csp }}: return "{{ csp }}";
{% endfor %}
default: return "unknown color space";
}
Expand All @@ -68,9 +68,9 @@
const char *vk_handle_name(VkExternalMemoryHandleTypeFlagBitsKHR handle)
{
switch (handle) {
%for handle in vkhandles:
case ${handle}: return "${handle}";
%endfor
{% for handle in vkhandles %}
case {{ handle }}: return "{{ handle }}";
{% endfor %}
default: return "unknown handle type";
}
Expand All @@ -79,9 +79,9 @@
const char *vk_alpha_mode(VkCompositeAlphaFlagsKHR alpha)
{
switch (alpha) {
%for mode in vkalphas:
case ${mode}: return "${mode}";
%endfor
{% for mode in vkalphas %}
case {{ mode }}: return "{{ mode }}";
{% endfor %}
default: return "unknown alpha mode";
}
Expand All @@ -90,9 +90,9 @@
const char *vk_surface_transform(VkSurfaceTransformFlagsKHR tf)
{
switch (tf) {
%for tf in vktransforms:
case ${tf}: return "${tf}";
%endfor
{% for tf in vktransforms %}
case {{ tf }}: return "{{ tf }}";
{% endfor %}
default: return "unknown surface transform";
}
Expand All @@ -102,9 +102,9 @@
const char *vk_obj_type(VkObjectType obj)
{
switch (obj) {
%for obj in vkobjects:
case ${obj.enum}: return "${obj.name}";
%endfor
{% for obj in vkobjects %}
case {{ obj.enum }}: return "{{ obj.name }}";
{% endfor %}
default: return "unknown object";
}
Expand All @@ -113,16 +113,16 @@
size_t vk_struct_size(VkStructureType stype)
{
switch (stype) {
%for struct in vkstructs:
case ${struct.stype}: return sizeof(${struct.name});
%endfor
{% for struct in vkstructs %}
case {{ struct.stype }}: return sizeof({{ struct.name }});
{% endfor %}
default: return 0;
}
}
const VkAccessFlags vk_access_read = ${hex(vkaccess.read)}LLU;
const VkAccessFlags vk_access_write = ${hex(vkaccess.write)}LLU;
const VkAccessFlags vk_access_read = {{ '0x%x' % vkaccess.read }}LLU;
const VkAccessFlags vk_access_write = {{ '0x%x' % vkaccess.write }}LLU;
""")

class Obj(object):
Expand Down

0 comments on commit 8ae448f

Please sign in to comment.