DirectX / HLSL Source Backend

DirectX HLSL source backend exports for CrossGL Translator.

DirectX/HLSL AST Node definitions

class crosstl.backend.DirectX.DirectxAst.CbufferNode(name, members)[source]

Bases: StructNode

HLSL constant-buffer declaration with named member variables.

class crosstl.backend.DirectX.DirectxAst.IncludeNode(path, is_system=False)[source]

Bases: ASTNode

HLSL include directive with system/local include metadata.

class crosstl.backend.DirectX.DirectxAst.PragmaNode(directive, value=None)[source]

Bases: ASTNode

Preprocessor pragma directive preserved in the HLSL AST.

class crosstl.backend.DirectX.DirectxAst.SwitchCaseNode(case_value, statements, is_default=False)[source]

Bases: ASTNode

Legacy switch case node with default-case tracking.

class crosstl.backend.DirectX.DirectxAst.SwitchStatementNode(expression, cases)[source]

Bases: ASTNode

Legacy switch statement node used by older HLSL parser paths.

Lexer for importing HLSL source into CrossGL Translator.

class crosstl.backend.DirectX.DirectxLexer.HLSLLexer(code, preprocess=True, file_path=None, include_paths=None, defines=None, strict_preprocessor=False)[source]

Bases: object

Tokenize High-Level Shading Language source for the DirectX parser.

classmethod from_file(filepath)[source]

Create a lexer instance from a source file.

Return type:

HLSLLexer

token_generator()[source]

Yield HLSL 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]]

class crosstl.backend.DirectX.DirectxLexer.Lexer(input_str)[source]

Bases: object

Compatibility wrapper around HLSLLexer for legacy code

next()[source]

Return the next token and advance the cursor.

Return type:

Tuple[str, str]

peek()[source]

Return the next token without advancing the cursor.

Return type:

Tuple[str, str]

reset()[source]

Reset the cursor to the beginning of the token stream.

class crosstl.backend.DirectX.DirectxLexer.Token(token_type, text)[source]

Bases: object

Simple typed token object used by DirectX compatibility paths.

class crosstl.backend.DirectX.DirectxLexer.TokenType(value)[source]

Bases: Enum

Token names emitted by the HLSL lexer.

Parser for DirectX HLSL source AST construction.

class crosstl.backend.DirectX.DirectxParser.HLSLParser(tokens)[source]

Bases: object

Parse HLSL tokens into the DirectX backend shader AST.

eat(expected_type)[source]

Consume and return the current token when it matches expected_type.

parse()[source]

Parse the complete token stream into a ShaderNode.

peek(offset=1)[source]

Return a lookahead token without advancing the parser.

Reverse code generator that emits CrossGL from HLSL AST nodes.

class crosstl.backend.DirectX.DirectxCrossGLCodeGen.HLSLToCrossGLConverter[source]

Bases: object

Serialize DirectX backend AST nodes back into CrossGL source.

generate(ast)[source]

Generate a complete CrossGL shader from a parsed HLSL AST.

generate_expression(expr, is_main=False)[source]

Render a DirectX backend expression node as CrossGL syntax.

generate_function(func, indent=1)[source]

Render one HLSL function node as a CrossGL function block.

generate_statement(node)[source]

Render one DirectX backend statement node as CrossGL source.

map_semantic(semantic)[source]

Map an HLSL semantic to CrossGL semantic annotation syntax.

map_type(hlsl_type)[source]

Map an HLSL type name to the closest CrossGL type name.

Preprocessor support for DirectX HLSL source imports.

class crosstl.backend.DirectX.preprocessor.HLSLPreprocessor(include_paths=None, defines=None, strict=False, max_expansion_depth=64)[source]

Bases: object

Small HLSL preprocessor used before lexing imported source files.

class crosstl.backend.DirectX.preprocessor.Macro(name, params=None, replacement='', is_variadic=False)[source]

Bases: object

Object-like or function-like HLSL preprocessor macro.