mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 09:38:07 +02:00
zink: allow Extension/Version to be shared across files
Acked-by: Adam Jackson <ajax@redhat.com> Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7800>
This commit is contained in:
parent
4ad7541cf0
commit
2f58d933ea
2 changed files with 164 additions and 165 deletions
|
|
@ -26,6 +26,7 @@
|
|||
from mako.template import Template
|
||||
from mako.lookup import TemplateLookup
|
||||
from os import path
|
||||
from zink_extensions import Extension,Version
|
||||
import sys
|
||||
|
||||
# constructor:
|
||||
|
|
@ -57,83 +58,81 @@ import sys
|
|||
# given by vkEnumerateDeviceExtensionProperties() include the extension.
|
||||
#
|
||||
# - guard: adds a #if defined(`extension_name`)/#endif guard around the code generated for this Extension.
|
||||
def EXTENSIONS():
|
||||
return [
|
||||
Extension("VK_KHR_maintenance1",
|
||||
required=True),
|
||||
Extension("VK_KHR_external_memory"),
|
||||
Extension("VK_KHR_external_memory_fd"),
|
||||
Extension("VK_KHR_vulkan_memory_model"),
|
||||
Extension("VK_EXT_conditional_rendering",
|
||||
alias="cond_render",
|
||||
features=True,
|
||||
conditions=["$feats.conditionalRendering"]),
|
||||
Extension("VK_EXT_transform_feedback",
|
||||
alias="tf",
|
||||
properties=True,
|
||||
features=True,
|
||||
conditions=["$feats.transformFeedback"]),
|
||||
Extension("VK_EXT_index_type_uint8",
|
||||
alias="index_uint8",
|
||||
features=True,
|
||||
conditions=["$feats.indexTypeUint8"]),
|
||||
Extension("VK_EXT_robustness2",
|
||||
alias="rb2",
|
||||
properties=True,
|
||||
features=True,
|
||||
conditions=["$feats.nullDescriptor"]),
|
||||
Extension("VK_EXT_vertex_attribute_divisor",
|
||||
alias="vdiv",
|
||||
properties=True,
|
||||
features=True,
|
||||
conditions=["$feats.vertexAttributeInstanceRateDivisor"]),
|
||||
Extension("VK_EXT_calibrated_timestamps"),
|
||||
Extension("VK_EXT_custom_border_color",
|
||||
alias="border_color",
|
||||
properties=True,
|
||||
features=True,
|
||||
conditions=["$feats.customBorderColors"]),
|
||||
Extension("VK_EXT_blend_operation_advanced",
|
||||
alias="blend",
|
||||
properties=True,
|
||||
# TODO: we can probably support non-premul here with some work?
|
||||
conditions=["$props.advancedBlendNonPremultipliedSrcColor", "$props.advancedBlendNonPremultipliedDstColor"]),
|
||||
Extension("VK_EXT_extended_dynamic_state",
|
||||
alias="dynamic_state",
|
||||
features=True,
|
||||
conditions=["$feats.extendedDynamicState"]),
|
||||
Extension("VK_EXT_pipeline_creation_cache_control",
|
||||
alias="pipeline_cache_control",
|
||||
features=True,
|
||||
conditions=["$feats.pipelineCreationCacheControl"]),
|
||||
Extension("VK_EXT_shader_stencil_export",
|
||||
alias="stencil_export"),
|
||||
Extension("VK_EXTX_portability_subset",
|
||||
alias="portability_subset_extx",
|
||||
properties=True,
|
||||
features=True,
|
||||
guard=True),
|
||||
]
|
||||
EXTENSIONS = [
|
||||
Extension("VK_KHR_maintenance1",
|
||||
required=True),
|
||||
Extension("VK_KHR_external_memory"),
|
||||
Extension("VK_KHR_external_memory_fd"),
|
||||
Extension("VK_KHR_vulkan_memory_model"),
|
||||
Extension("VK_EXT_conditional_rendering",
|
||||
alias="cond_render",
|
||||
features=True,
|
||||
conditions=["$feats.conditionalRendering"]),
|
||||
Extension("VK_EXT_transform_feedback",
|
||||
alias="tf",
|
||||
properties=True,
|
||||
features=True,
|
||||
conditions=["$feats.transformFeedback"]),
|
||||
Extension("VK_EXT_index_type_uint8",
|
||||
alias="index_uint8",
|
||||
features=True,
|
||||
conditions=["$feats.indexTypeUint8"]),
|
||||
Extension("VK_EXT_robustness2",
|
||||
alias="rb2",
|
||||
properties=True,
|
||||
features=True,
|
||||
conditions=["$feats.nullDescriptor"]),
|
||||
Extension("VK_EXT_vertex_attribute_divisor",
|
||||
alias="vdiv",
|
||||
properties=True,
|
||||
features=True,
|
||||
conditions=["$feats.vertexAttributeInstanceRateDivisor"]),
|
||||
Extension("VK_EXT_calibrated_timestamps"),
|
||||
Extension("VK_EXT_custom_border_color",
|
||||
alias="border_color",
|
||||
properties=True,
|
||||
features=True,
|
||||
conditions=["$feats.customBorderColors"]),
|
||||
Extension("VK_EXT_blend_operation_advanced",
|
||||
alias="blend",
|
||||
properties=True,
|
||||
# TODO: we can probably support non-premul here with some work?
|
||||
conditions=["$props.advancedBlendNonPremultipliedSrcColor", "$props.advancedBlendNonPremultipliedDstColor"]),
|
||||
Extension("VK_EXT_extended_dynamic_state",
|
||||
alias="dynamic_state",
|
||||
features=True,
|
||||
conditions=["$feats.extendedDynamicState"]),
|
||||
Extension("VK_EXT_pipeline_creation_cache_control",
|
||||
alias="pipeline_cache_control",
|
||||
features=True,
|
||||
conditions=["$feats.pipelineCreationCacheControl"]),
|
||||
Extension("VK_EXT_shader_stencil_export",
|
||||
alias="stencil_export"),
|
||||
Extension("VK_EXTX_portability_subset",
|
||||
alias="portability_subset_extx",
|
||||
properties=True,
|
||||
features=True,
|
||||
guard=True),
|
||||
]
|
||||
|
||||
# constructor: Versions(device_version(major, minor, patch), struct_version(major, minor))
|
||||
# The attributes:
|
||||
# - device_version: Vulkan version, as tuple, to use with VK_MAKE_VERSION(version_major, version_minor, version_patch)
|
||||
# - device_version: Vulkan version, as tuple, to use with
|
||||
# VK_MAKE_VERSION(version_major, version_minor, version_patch)
|
||||
#
|
||||
# - struct_version: Vulkan version, as tuple, to use with structures and macros
|
||||
def VERSIONS():
|
||||
return [
|
||||
# VkPhysicalDeviceVulkan11Properties and VkPhysicalDeviceVulkan11Features is new from Vk 1.2, not Vk 1.1
|
||||
# https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#_new_structures
|
||||
Version((1,2,0), (1,1)),
|
||||
Version((1,2,0), (1,2)),
|
||||
]
|
||||
VERSIONS = [
|
||||
# VkPhysicalDeviceVulkan11Properties and VkPhysicalDeviceVulkan11Features is new from Vk 1.2, not Vk 1.1
|
||||
# https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#_new_structures
|
||||
Version((1,2,0), (1,1)),
|
||||
Version((1,2,0), (1,2)),
|
||||
]
|
||||
|
||||
# There exists some inconsistencies regarding the enum constants, fix them.
|
||||
# This is basically generated_code.replace(key, value).
|
||||
def REPLACEMENTS():
|
||||
return {
|
||||
"ROBUSTNESS2": "ROBUSTNESS_2"
|
||||
}
|
||||
REPLACEMENTS = {
|
||||
"ROBUSTNESS2": "ROBUSTNESS_2"
|
||||
}
|
||||
|
||||
|
||||
# This template provides helper functions for the other templates.
|
||||
|
|
@ -376,99 +375,6 @@ fail:
|
|||
}
|
||||
"""
|
||||
|
||||
class Version:
|
||||
driver_version : (1,0,0)
|
||||
struct_version : (1,0)
|
||||
|
||||
def __init__(self, version, struct):
|
||||
self.device_version = version
|
||||
self.struct_version = struct
|
||||
|
||||
# e.g. "VM_MAKE_VERSION(1,2,0)"
|
||||
def version(self):
|
||||
return ("VK_MAKE_VERSION("
|
||||
+ str(self.device_version[0])
|
||||
+ ","
|
||||
+ str(self.device_version[1])
|
||||
+ ","
|
||||
+ str(self.device_version[2])
|
||||
+ ")")
|
||||
|
||||
# e.g. "10"
|
||||
def struct(self):
|
||||
return (str(self.struct_version[0])+str(self.struct_version[1]))
|
||||
|
||||
# the sType of the extension's struct
|
||||
# e.g. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
|
||||
# for VK_EXT_transform_feedback and struct="FEATURES"
|
||||
def stype(self, struct: str):
|
||||
return ("VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_"
|
||||
+ str(self.struct_version[0]) + "_" + str(self.struct_version[1])
|
||||
+ '_' + struct)
|
||||
|
||||
class Extension:
|
||||
name : str = None
|
||||
alias : str = None
|
||||
is_required : bool = False
|
||||
has_properties : bool = False
|
||||
has_features : bool = False
|
||||
enable_conds : [str] = None
|
||||
guard : bool = False
|
||||
|
||||
def __init__(self, name, alias="", required=False, properties=False, features=False, conditions=None, guard=False):
|
||||
self.name = name
|
||||
self.alias = alias
|
||||
self.is_required = required
|
||||
self.has_properties = properties
|
||||
self.has_features = features
|
||||
self.enable_conds = conditions
|
||||
self.guard = guard
|
||||
|
||||
if alias == "" and (properties == True or features == True):
|
||||
raise RuntimeError("alias must be available when properties and/or features are used")
|
||||
|
||||
# e.g.: "VK_EXT_robustness2" -> "robustness2"
|
||||
def pure_name(self):
|
||||
return '_'.join(self.name.split('_')[2:])
|
||||
|
||||
# e.g.: "VK_EXT_robustness2" -> "EXT_robustness2"
|
||||
def name_with_vendor(self):
|
||||
return self.name[3:]
|
||||
|
||||
# e.g.: "VK_EXT_robustness2" -> "Robustness2"
|
||||
def name_in_camel_case(self):
|
||||
return "".join([x.title() for x in self.name.split('_')[2:]])
|
||||
|
||||
# e.g.: "VK_EXT_robustness2" -> "VK_EXT_ROBUSTNESS2_EXTENSION_NAME"
|
||||
# do note that inconsistencies exist, i.e. we have
|
||||
# VK_EXT_ROBUSTNESS_2_EXTENSION_NAME defined in the headers, but then
|
||||
# we also have VK_KHR_MAINTENANCE1_EXTENSION_NAME
|
||||
def extension_name(self):
|
||||
return self.name.upper() + "_EXTENSION_NAME"
|
||||
|
||||
# generate a C string literal for the extension
|
||||
def extension_name_literal(self):
|
||||
return '"' + self.name + '"'
|
||||
|
||||
# get the field in zink_device_info that refers to the extension's
|
||||
# feature/properties struct
|
||||
# e.g. rb2_<suffix> for VK_EXT_robustness2
|
||||
def field(self, suffix: str):
|
||||
return self.alias + '_' + suffix
|
||||
|
||||
# the sType of the extension's struct
|
||||
# e.g. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
|
||||
# for VK_EXT_transform_feedback and struct="FEATURES"
|
||||
def stype(self, struct: str):
|
||||
return ("VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_"
|
||||
+ self.pure_name().upper()
|
||||
+ '_' + struct + '_'
|
||||
+ self.vendor())
|
||||
|
||||
# e.g. EXT in VK_EXT_robustness2
|
||||
def vendor(self):
|
||||
return self.name.split('_')[1]
|
||||
|
||||
|
||||
def replace_code(code: str, replacement: dict):
|
||||
for (k, v) in replacement.items():
|
||||
|
|
@ -488,9 +394,9 @@ if __name__ == "__main__":
|
|||
print("usage: %s <path to .h> <path to .c>" % sys.argv[0])
|
||||
exit(1)
|
||||
|
||||
extensions = EXTENSIONS()
|
||||
versions = VERSIONS()
|
||||
replacement = REPLACEMENTS()
|
||||
extensions = EXTENSIONS
|
||||
versions = VERSIONS
|
||||
replacement = REPLACEMENTS
|
||||
|
||||
lookup = TemplateLookup()
|
||||
lookup.put_string("helpers", include_template)
|
||||
|
|
|
|||
93
src/gallium/drivers/zink/zink_extensions.py
Normal file
93
src/gallium/drivers/zink/zink_extensions.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
class Extension:
|
||||
name : str = None
|
||||
alias : str = None
|
||||
is_required : bool = False
|
||||
has_properties : bool = False
|
||||
has_features : bool = False
|
||||
enable_conds : [str] = None
|
||||
guard : bool = False
|
||||
|
||||
def __init__(self, name, alias="", required=False, properties=False, features=False, conditions=None, guard=False):
|
||||
self.name = name
|
||||
self.alias = alias
|
||||
self.is_required = required
|
||||
self.has_properties = properties
|
||||
self.has_features = features
|
||||
self.enable_conds = conditions
|
||||
self.guard = guard
|
||||
|
||||
if alias == "" and (properties == True or features == True):
|
||||
raise RuntimeError("alias must be available when properties and/or features are used")
|
||||
|
||||
# e.g.: "VK_EXT_robustness2" -> "robustness2"
|
||||
def pure_name(self):
|
||||
return '_'.join(self.name.split('_')[2:])
|
||||
|
||||
# e.g.: "VK_EXT_robustness2" -> "EXT_robustness2"
|
||||
def name_with_vendor(self):
|
||||
return self.name[3:]
|
||||
|
||||
# e.g.: "VK_EXT_robustness2" -> "Robustness2"
|
||||
def name_in_camel_case(self):
|
||||
return "".join([x.title() for x in self.name.split('_')[2:]])
|
||||
|
||||
# e.g.: "VK_EXT_robustness2" -> "VK_EXT_ROBUSTNESS2_EXTENSION_NAME"
|
||||
# do note that inconsistencies exist, i.e. we have
|
||||
# VK_EXT_ROBUSTNESS_2_EXTENSION_NAME defined in the headers, but then
|
||||
# we also have VK_KHR_MAINTENANCE1_EXTENSION_NAME
|
||||
def extension_name(self):
|
||||
return self.name.upper() + "_EXTENSION_NAME"
|
||||
|
||||
# generate a C string literal for the extension
|
||||
def extension_name_literal(self):
|
||||
return '"' + self.name + '"'
|
||||
|
||||
# get the field in zink_device_info that refers to the extension's
|
||||
# feature/properties struct
|
||||
# e.g. rb2_<suffix> for VK_EXT_robustness2
|
||||
def field(self, suffix: str):
|
||||
return self.alias + '_' + suffix
|
||||
|
||||
# the sType of the extension's struct
|
||||
# e.g. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
|
||||
# for VK_EXT_transform_feedback and struct="FEATURES"
|
||||
def stype(self, struct: str):
|
||||
return ("VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_"
|
||||
+ self.pure_name().upper()
|
||||
+ '_' + struct + '_'
|
||||
+ self.vendor())
|
||||
|
||||
# e.g. EXT in VK_EXT_robustness2
|
||||
def vendor(self):
|
||||
return self.name.split('_')[1]
|
||||
|
||||
|
||||
class Version:
|
||||
driver_version : (1,0,0)
|
||||
struct_version : (1,0)
|
||||
|
||||
def __init__(self, version, struct):
|
||||
self.device_version = version
|
||||
self.struct_version = struct
|
||||
|
||||
# e.g. "VM_MAKE_VERSION(1,2,0)"
|
||||
def version(self):
|
||||
return ("VK_MAKE_VERSION("
|
||||
+ str(self.device_version[0])
|
||||
+ ","
|
||||
+ str(self.device_version[1])
|
||||
+ ","
|
||||
+ str(self.device_version[2])
|
||||
+ ")")
|
||||
|
||||
# e.g. "10"
|
||||
def struct(self):
|
||||
return (str(self.struct_version[0])+str(self.struct_version[1]))
|
||||
|
||||
# the sType of the extension's struct
|
||||
# e.g. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
|
||||
# for VK_EXT_transform_feedback and struct="FEATURES"
|
||||
def stype(self, struct: str):
|
||||
return ("VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_"
|
||||
+ str(self.struct_version[0]) + "_" + str(self.struct_version[1])
|
||||
+ '_' + struct)
|
||||
Loading…
Add table
Reference in a new issue