"""The Vulkan specification's "Required Format Support" tables as typed requirements. The source is the specification's own AsciiDoc (`chapters/formats.txt` of a pinned Vulkan-Docs tag): `vk.xml` describes formats but not which features they must support. The text is evaluated for one core version with no extension attributes (`ifdef`/`ifndef`/`endif`, block and single-line forms), then every table anchored `formats-mandatory-features-*` in the `Required Format Support` section is laid out as a grid (column and row spans) and read cell by cell: * the header rows name each feature column (`N+>| ename:VK_FORMAT_FEATURE_*` spans the columns to the left of its `{downarrow}` cell); * `{sym1}` is an unconditional requirement; * every other symbol takes its meaning from a footnote row of the same table, which must match one of three footnote forms exactly (a feature condition, a choice between two formats, a choice between whole tables); anything else is an error, never a guess; * a footnote that states a prohibition rather than a requirement is kept as text in `not_represented`. Which bitmask a feature belongs to (`optimalTilingFeatures` or `bufferFeatures`) comes from the section's own "Feature bits in ..." tables, and the section's sentence that formats required to support `SAMPLED_IMAGE` also support `TRANSFER_SRC` and `TRANSFER_DST` adds those two bits wherever `SAMPLED_IMAGE` is required. The sentence is matched verbatim, so a source without it fails. The result is `{"tables", "unconditional", "conditional", "not_represented"}`. `unconditional` maps each format to `{member: [bits]}` (`VkFormatProperties` member names); each `conditional` requirement is `{"tables", "any_of": [table, ...]}` plus `"if_feature"` when it only binds a device supporting that `VkPhysicalDeviceFeatures` member: at least one table of `any_of` must hold in full. """ import re # Vulkan-Docs v1.2.203 (commit 30061d7ad920d8bcd0f936531abe9ca49d5eb22f) is the last revision of # the Vulkan 1.2 specification; v1.3.204 follows it. SPEC = { "url": ("https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/v1.2.203/" "chapters/formats.txt"), "sha256": "2031f11fe2b7269502eecab10f0c6f386e33c34fcc5be02f0c25fc8bb50badd5", "tag": "v1.2.203", } # The attributes the specification defines when it is built for core Vulkan 1.2 alone. VERSION_1_2 = ["VK_VERSION_1_0", "VK_VERSION_1_1", "VK_VERSION_1_2"] SECTION = "[[features-required-format-support]]" TABLE_ANCHOR = re.compile(r"^\[\[(formats-mandatory-features-[a-z0-9-]+)\]\]$") FIELDS = { "optimalTilingFeatures": "Feature bits in pname:optimalTilingFeatures", "bufferFeatures": "Feature bits in pname:bufferFeatures", } TRANSFER_RULE = ("Formats that are required to support ename:VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT " "must: also support ename:VK_FORMAT_FEATURE_TRANSFER_SRC_BIT and " "ename:VK_FORMAT_FEATURE_TRANSFER_DST_BIT.") SAMPLED = "VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT" TRANSFER = ["VK_FORMAT_FEATURE_TRANSFER_SRC_BIT", "VK_FORMAT_FEATURE_TRANSFER_DST_BIT"] MARKS = {"", "{sym1}", "{sym2}", "{sym3}", "{sym4}"} FEATURE_FOOTNOTE = re.compile( r"^Format features marked (?:with )?\{(sym\d)\} must: be supported for " r"pname:optimalTilingFeatures if the sname:VkPhysicalDevice supports the " r"<> feature\.$") FORMAT_CHOICE_FOOTNOTE = re.compile( r"^ename:(VK_FORMAT_FEATURE_\w+) feature must: be supported for at least one of " r"ename:(VK_FORMAT_\w+) and ename:(VK_FORMAT_\w+), and must: be supported for at least one " r"of ename:(VK_FORMAT_\w+) and ename:(VK_FORMAT_\w+)\.$") TABLE_CHOICE_FOOTNOTE = re.compile( r"^The ename:(VK_FORMAT_FEATURE_\w+), ename:(VK_FORMAT_FEATURE_\w+) and " r"ename:(VK_FORMAT_FEATURE_\w+) features must: be supported in pname:optimalTilingFeatures " r"for all the formats in at least one of: this table, <<([\w-]+)>>, or <<([\w-]+)>>\.$") PROHIBITION_FOOTNOTE = re.compile( r"^pname:bufferFeatures must: not support any features for these formats$") # An AsciiDoc cell spec directly before its `|`: [colspan][.rowspan]+, [n*], [halign][.valign], # [style]. It is preceded by whitespace or starts the text. CELL_SPEC = re.compile( r"(?:^|(?<=\s))(?P\d*(?:\.\d+)?\+)?(?P\d+\*)?(?P[<^>])?" r"(?P\.[<^>])?(?P