How wpmed92/shaderpulse works
Project Type and Purpose
• This is a compiler front end for translating GLSL code (with compute shaders and other shader features) into SPIR-V using MLIR as the code generation backend.
• The README clearly defines the role of each major compiler phase (lexing, parsing, analysis, and code generation) and demonstrates an end-to-end example where a compute shader is converted to MLIR SPIR-V code.
Key Components and Their Organization
a. Entry Point & Overall Pipeline:
• Compiler’s entry point (e.g., the “compiler/shaderpulse.cpp” file) that likely initializes the overall compilation process.
b. Modular Subsystems:
• Preprocessor: In “include/Preprocessor” and “lib/Preprocessor”, responsible for handling source text modifications (handling #defines, includes, etc.).
• Lexer: In “include/Lexer” and “lib/Lexer”, reads the source GLSL code and produces tokens.
• Parser: Found in “include/Parser” and “lib/Parser”, conducts a recursive descent parsing of tokens into an Abstract Syntax Tree (AST).
• AST & Visitors: The “include/AST” and “lib/AST” directories include definitions for the AST nodes and visitors (like PrinterASTVisitor) that are likely used for traversals.
• Semantic Analysis: In “include/Analysis” and “lib/Analysis”, performs type checking and scope analysis using the visitor pattern.
• Code Generation: In “include/CodeGen” and “lib/CodeGen”, traverses the AST and emits MLIR (which in turn becomes SPIR-V). The MLIRCodeGen module is a key element here.
c. Infrastructure and Testing:
• CMakeLists.txt and related configuration files to build the project.
• “test” directory, which splits tests into subdirectories (Lexer, Parser, Analysis, CodeGen) to verify each component.
• Example shaders in the “example” folder, which serve as demonstrations of the frontend in action.
• From the AST block, branch into two parallel processes (or a sequential pipeline):
• “Semantic Analyzer” – responsible for type-checking and validating constructs (using a visitor pattern).
• “Code Generator” – employing the visitor pattern to generate MLIR/SPIR-V code.
• That Code Generation is based on MLIR (reference “MLIRCodeGen”) and connects to the output module that produces the final SPIR-V dialect.
• Optionally, reference external dependencies (e.g., LLVM / MLIR if relevant, as seen in the “llvm-project” directory).
Architectural Patterns and Important Details
• Differentiate between “data transformation” components (lexer, parser, AST) and “analysis/transformation” components (semantic analysis and code generation).
• Clearly label external test frameworks, build configurations (CMake) and example projects that help in verifying each component.