CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
GLSLConverter.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
13
15
16#include <functional>
17
19
23 class GLSLConverter : public Converter {
24 private:
27
29 bool mAutoBinding = false;
32 bool mSeparateSamplers = true;
33
37
38 public:
39 static bool convertVarDeclarationType(VarDeclaration& varDeclaration);
40 static bool convertVarDeclarationBaseTypeDenoter(VarDeclaration& varDeclaration, const DataType dataType);
41
42 private:
43 void convertASTPrimary(Program& program, const ShaderInput& inputDesc, const ShaderOutput& outputDesc) override;
44
45 // Returns true if the output shader version is VKSL (GLSL for Vulkan).
46 [[nodiscard]] bool isVKSL() const;
47
48 // Returns true if separate objects for samplers & textures should be used.
50
51 private: // Visitor implementation
56
61
66
75
79
80 private: // Scope functions
81 // Renames the identifier of the specified declaration object (if required) and registers its identifier.
82 void registerDeclarationIdent(Declaration* obj, bool global = false);
83
84 // Registers the identifiers of all specified variables (see RegisterDeclIdent).
86
87 private: // Helper functions for conversion
88 // Returns true if the specified variable declaration must be renamed.
90
91 // Removes all variable declarations which have a sampler state type.
93
94 // Renames the specified identifier if it equals a reserved GLSL intrinsic or function name.
96
97 private: // Function declaration
101
102 private: // Call expressions
114
115 private: // Entry point
124
125 //TODO: this should be replaced by the code-injection functionality.
127
129
130 private: // Object expressions
140
142
143 private: // Unrolling
147
148 private:
150 };
151
152} // namespace CeresEngine::ShaderCompiler
#define DECLARATION_VISIT_PROC(CLASS_NAME)
Definition Visitor.hpp:88
GLSL AST converter.
Definition Converter.hpp:26
GLSL AST converter.
Definition GLSLConverter.hpp:23
void convertIntrinsicCallGather(CallExpression *ast)
Int32 mAutoBindingStartSlot
Definition GLSLConverter.hpp:30
void convertObjectPrefixStructMember(ExpressionPtr &prefixExpression, const StructDeclaration *ownerStructDeclaration, const StructDeclaration *callerStructDeclaration, bool useSelfParam)
void registerGlobalDeclarationIdents(const Vector< VarDeclaration * > &varDeclarations)
void convertEntryPointReturnStatementToCodeBlock(StatementPtr &statement)
void convertIntrinsicCallImageAtomic(CallExpression *ast)
void convertEntryPointStructPrefix(ExpressionPtr &expression, ObjectExpression *objectExpression)
void convertSlotRegisters(const Statement *ast, Vector< RegisterPtr > &slotRegisters)
void convertIntrinsicCallTextureLod(CallExpression *ast)
static bool convertVarDeclarationBaseTypeDenoter(VarDeclaration &varDeclaration, const DataType dataType)
void convertEntryPointStructPrefixArray(ExpressionPtr &expression, const ArrayExpression *prefixExpression, ObjectExpression *objectExpression)
void convertFunctionDeclarationEntryPoint(FunctionDeclaration *ast)
void unrollStatementsVarDeclaration(Vector< StatementPtr > &unrolledStatements, const VarDeclarationStatement *ast)
void convertEntryPointReturnStatementCommonExpression(ReturnStatement &ast, StructDeclaration *structDeclaration, const TypeDenoterPtr &typeDen, const ExpressionPtr &typeConstructor)
static bool convertVarDeclarationType(VarDeclaration &varDeclaration)
void addMissingInterpModifiers(const Vector< VarDeclaration * > &varDeclarations)
void convertObjectPrefixNamespaceStruct(ObjectExpression *prefixObjectExpression, ObjectExpression *objectExpression, const StructDeclaration *baseStructDeclaration, const StructDeclaration *activeStructDeclaration)
void convertFunctionCall(CallExpression *ast)
void convertIntrinsicCall(CallExpression *ast)
void convertObjectExpressionStaticVar(ObjectExpression *objectExpression)
OutputShaderVersion mOutputVersion
Definition GLSLConverter.hpp:26
void convertFunctionDeclaration(FunctionDeclaration *ast)
void convertEntryPointReturnStatementSequenceExpression(ReturnStatement &ast, StructDeclaration *structDeclaration, const TypeDenoterPtr &typeDen, const SequenceExpression &typeConstructor)
void convertIntrisicCallF32toF16(CallExpression *ast)
void convertObjectExpressionDefault(ObjectExpression *objectExpression)
void registerDeclarationIdent(Declaration *obj, bool global=false)
void convertASTPrimary(Program &program, const ShaderInput &inputDesc, const ShaderOutput &outputDesc) override
void convertObjectPrefixNamespace(const ExpressionPtr &prefixExpression, ObjectExpression *objectExpression)
void convertEntryPointStructPrefixObject(ExpressionPtr &expression, const ObjectExpression *prefixExpression, ObjectExpression *objectExpression)
void convertIntrinsicCallTextureSample(CallExpression *ast)
void convertIntrinsicCallSampleCmp(CallExpression *ast)
void convertObjectPrefixSelfParam(ExpressionPtr &prefixExpression, const ObjectExpression *objectExpression)
bool renameReservedKeyword(Identifier &ident)
Vector< const Declaration * > mGlobalReservedDeclarations
List of all variables with reserved identifiers that come from a structure that must be normalize.
Definition GLSLConverter.hpp:36
void removeSamplerStateVarDeclarationStatements(Vector< VarDeclarationStatementPtr > &statements)
void convertObjectExpression(ObjectExpression *objectExpression)
void convertObjectPrefixBaseStruct(ExpressionPtr &prefixExpression, const ObjectExpression *objectExpression)
ShaderTarget mShaderTarget
Definition GLSLConverter.hpp:25
void unrollStatementsVarDeclarationInitializer(Vector< StatementPtr > &unrolledStatements, VarDeclaration *varDeclaration)
void convertEntryPointReturnStatement(ReturnStatement &ast, StructDeclaration *structDeclaration, const TypeDenoterPtr &typeDen, const ExpressionPtr &typeConstructor)
Options mOptions
Definition GLSLConverter.hpp:28
void convertFunctionDeclarationDefault(FunctionDeclaration *ast)
Map< UInt32, Int32 > mAutoBindingSlotPerSet
Definition GLSLConverter.hpp:31
bool mAutoBinding
Definition GLSLConverter.hpp:29
void convertIntrinsicCallTextureLoad(CallExpression *ast)
bool mustRenameDeclarationIdent(const Declaration *obj) const
void unrollStatements(Vector< StatementPtr > &statements)
bool mSeparateSamplers
Definition GLSLConverter.hpp:32
void convertIntrinsicCallTextureSampleLevel(CallExpression *ast)
void convertIntrinsicCallSaturate(CallExpression *ast)
void insertBaseMemberPrefixes(ExpressionPtr &prefixExpression, const StructDeclaration *ownerStructDeclaration, const StructDeclaration *callerStructDeclaration)
Class to manage identifiers that can be renamed (maybe several times), to keep track of the original ...
Definition Identifier.hpp:18
Definition AST.hpp:33
SPtr< Expression > ExpressionPtr
Definition Visitor.hpp:26
ShaderTarget
Shader target enumeration.
Definition Targets.hpp:16
SPtr< Statement > StatementPtr
Definition Visitor.hpp:25
OutputShaderVersion
Output shader version enumeration.
Definition Targets.hpp:67
@ GLSL
Auto-detect minimal required GLSL version (for OpenGL 2+).
SPtr< TypeDenoter > TypeDenoterPtr
Definition TypeDenoter.hpp:29
DataType
Definition ASTEnums.hpp:159
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
std::int32_t Int32
Definition DataTypes.hpp:21
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::map< Key, T, Compare, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > Map
Map is a sorted associative container that contains key-value pairs with unique keys.
Definition Map.hpp:24
Structure for additional translation options.
Definition ShaderCompiler.hpp:115
Shader input descriptor structure.
Definition ShaderCompiler.hpp:223
Shader output descriptor structure.
Definition ShaderCompiler.hpp:293