Vulkan SPIR-V Source Backend

Vulkan SPIR-V source backend exports for CrossGL Translator.

SPIR-V/Vulkan AST Node definitions

class crosstl.backend.SPIRV.VulkanAst.DefaultNode(statements)[source]

Bases: ASTNode

Node representing default case in switch

class crosstl.backend.SPIRV.VulkanAst.DescriptorSetNode(set_number, binding, descriptor_type, name)[source]

Bases: ASTNode

Node representing a descriptor set binding

class crosstl.backend.SPIRV.VulkanAst.LayoutNode(qualifiers, declaration=None, *, push_constant=False, layout_type=None, data_type=None, variable_name=None, struct_fields=None, block_name=None)[source]

Bases: ASTNode

Node representing layout qualifiers

class crosstl.backend.SPIRV.VulkanAst.PushConstantNode(members)[source]

Bases: ASTNode

Node representing push constant block

class crosstl.backend.SPIRV.VulkanAst.ShaderStageNode(stage)[source]

Bases: ASTNode

Node representing shader stage annotation

class crosstl.backend.SPIRV.VulkanAst.UniformNode(vtype, name)[source]

Bases: ASTNode

Node representing uniform variable

Lexer for importing Vulkan SPIR-V source into CrossGL Translator.

class crosstl.backend.SPIRV.VulkanLexer.VulkanLexer(code)[source]

Bases: object

Tokenize Vulkan/SPIR-V style source for the Vulkan backend parser.

classmethod from_file(filepath, chunk_size=8192)[source]

Create a lexer instance from a Vulkan/SPIR-V source file.

Return type:

VulkanLexer

token_generator()[source]

Yield Vulkan/SPIR-V tokens while skipping whitespace and comments.

Return type:

Iterator[Tuple[str, str]]

tokenize()[source]

Return the full token stream as (token_type, text) tuples.

Return type:

List[Tuple[str, str]]

Parser for Vulkan SPIR-V source AST construction.

class crosstl.backend.SPIRV.VulkanParser.VulkanParser(tokens)[source]

Bases: object

Parse Vulkan/SPIR-V style tokens into the Vulkan backend AST.

eat(token_type)[source]

Consume the current token when it matches token_type.

parse()[source]

Parse the complete token stream into a module AST.

parse_module()[source]

Parse top-level Vulkan/SPIR-V declarations and functions.

peek(offset)[source]

Look ahead by offset tokens without consuming them.

skip_comments()[source]

Advance past comment tokens before parsing syntax.

skip_until(token_type)[source]

Skip tokens until the specified token type is found

Reverse code generator that emits CrossGL from Vulkan SPIR-V AST nodes.

class crosstl.backend.SPIRV.VulkanCrossGLCodeGen.VulkanToCrossGLConverter[source]

Bases: object

Serialize Vulkan backend AST nodes back into CrossGL source.

generate(ast)[source]

Generate complete CrossGL source from a parsed Vulkan backend AST.

generate_expression(expr)[source]

Render a Vulkan backend expression node as CrossGL syntax.

generate_function(node, indent=1)[source]

Render one Vulkan backend function node as a CrossGL function.

get_indent()[source]

Return whitespace for the current indentation level.

is_position_assignment(stmt)[source]

Check if a statement is assigning to gl_Position

map_type(vulkan_type)[source]

Map a Vulkan/SPIR-V type name to the closest CrossGL type name.