GLSL: Promote HLSL entry-point renaming code to be used by GLSL as well.
Fixes #1045.
This commit is contained in:
parent
4f4683d251
commit
9855bdad00
16 changed files with 1066 additions and 957 deletions
|
|
@ -49,9 +49,10 @@ namespace glslang {
|
|||
|
||||
TParseContext::TParseContext(TSymbolTable& symbolTable, TIntermediate& interm, bool parsingBuiltins,
|
||||
int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language,
|
||||
TInfoSink& infoSink, bool forwardCompatible, EShMessages messages) :
|
||||
TInfoSink& infoSink, bool forwardCompatible, EShMessages messages,
|
||||
const TString* entryPoint) :
|
||||
TParseContextBase(symbolTable, interm, parsingBuiltins, version, profile, spvVersion, language,
|
||||
infoSink, forwardCompatible, messages),
|
||||
infoSink, forwardCompatible, messages, entryPoint),
|
||||
inMain(false),
|
||||
blockName(nullptr),
|
||||
limits(resources.limits),
|
||||
|
|
@ -88,6 +89,9 @@ TParseContext::TParseContext(TSymbolTable& symbolTable, TIntermediate& interm, b
|
|||
|
||||
if (language == EShLangGeometry)
|
||||
globalOutputDefaults.layoutStream = 0;
|
||||
|
||||
if (entryPoint != nullptr && entryPoint->size() > 0 && *entryPoint != "main")
|
||||
infoSink.info.message(EPrefixError, "Source entry point must be \"main\"");
|
||||
}
|
||||
|
||||
TParseContext::~TParseContext()
|
||||
|
|
|
|||
|
|
@ -74,7 +74,8 @@ class TParseContextBase : public TParseVersions {
|
|||
public:
|
||||
TParseContextBase(TSymbolTable& symbolTable, TIntermediate& interm, bool parsingBuiltins, int version,
|
||||
EProfile profile, const SpvVersion& spvVersion, EShLanguage language,
|
||||
TInfoSink& infoSink, bool forwardCompatible, EShMessages messages)
|
||||
TInfoSink& infoSink, bool forwardCompatible, EShMessages messages,
|
||||
const TString* entryPoint = nullptr)
|
||||
: TParseVersions(interm, version, profile, spvVersion, language, infoSink, forwardCompatible, messages),
|
||||
scopeMangler("::"),
|
||||
symbolTable(symbolTable),
|
||||
|
|
@ -84,7 +85,10 @@ public:
|
|||
parsingBuiltins(parsingBuiltins), scanContext(nullptr), ppContext(nullptr),
|
||||
limits(resources.limits),
|
||||
globalUniformBlock(nullptr)
|
||||
{ }
|
||||
{
|
||||
if (entryPoint != nullptr)
|
||||
sourceEntryPointName = *entryPoint;
|
||||
}
|
||||
virtual ~TParseContextBase() { }
|
||||
|
||||
virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
|
|
@ -141,6 +145,15 @@ public:
|
|||
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
|
||||
virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr);
|
||||
|
||||
// Potentially rename shader entry point function
|
||||
void renameShaderFunction(TString*& name) const
|
||||
{
|
||||
// Replace the entry point name given in the shader with the real entry point name,
|
||||
// if there is a substitution.
|
||||
if (name != nullptr && *name == sourceEntryPointName)
|
||||
name = NewPoolTString(intermediate.getEntryPointName().c_str());
|
||||
}
|
||||
|
||||
virtual bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*);
|
||||
virtual void rValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*);
|
||||
|
||||
|
|
@ -173,6 +186,7 @@ protected:
|
|||
TPpContext* ppContext;
|
||||
TBuiltInResource resources;
|
||||
TLimits& limits;
|
||||
TString sourceEntryPointName;
|
||||
|
||||
// These, if set, will be called when a line, pragma ... is preprocessed.
|
||||
// They will be called with any parameters to the original directive.
|
||||
|
|
@ -249,7 +263,8 @@ protected:
|
|||
class TParseContext : public TParseContextBase {
|
||||
public:
|
||||
TParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins, int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&,
|
||||
bool forwardCompatible = false, EShMessages messages = EShMsgDefault);
|
||||
bool forwardCompatible = false, EShMessages messages = EShMsgDefault,
|
||||
const TString* entryPoint = nullptr);
|
||||
virtual ~TParseContext();
|
||||
|
||||
bool obeyPrecisionQualifiers() const { return precisionManager.respectingPrecisionQualifiers(); };
|
||||
|
|
|
|||
|
|
@ -91,18 +91,16 @@ TParseContextBase* CreateParseContext(TSymbolTable& symbolTable, TIntermediate&
|
|||
int version, EProfile profile, EShSource source,
|
||||
EShLanguage language, TInfoSink& infoSink,
|
||||
SpvVersion spvVersion, bool forwardCompatible, EShMessages messages,
|
||||
bool parsingBuiltIns, const std::string sourceEntryPointName = "")
|
||||
bool parsingBuiltIns, std::string sourceEntryPointName = "")
|
||||
{
|
||||
#ifndef ENABLE_HLSL
|
||||
(void)sourceEntryPointName; // Unused argument.
|
||||
#endif
|
||||
|
||||
switch (source) {
|
||||
case EShSourceGlsl:
|
||||
intermediate.setEntryPointName("main");
|
||||
case EShSourceGlsl: {
|
||||
if (sourceEntryPointName.size() == 0)
|
||||
intermediate.setEntryPointName("main");
|
||||
TString entryPoint = sourceEntryPointName.c_str();
|
||||
return new TParseContext(symbolTable, intermediate, parsingBuiltIns, version, profile, spvVersion,
|
||||
language, infoSink, forwardCompatible, messages);
|
||||
|
||||
language, infoSink, forwardCompatible, messages, &entryPoint);
|
||||
}
|
||||
#ifdef ENABLE_HLSL
|
||||
case EShSourceHlsl:
|
||||
return new HlslParseContext(symbolTable, intermediate, parsingBuiltIns, version, profile, spvVersion,
|
||||
|
|
|
|||
|
|
@ -860,6 +860,11 @@ function_header
|
|||
// Add the function as a prototype after parsing it (we do not support recursion)
|
||||
TFunction *function;
|
||||
TType type($1);
|
||||
|
||||
// Potentially rename shader entry point function. No-op most of the time.
|
||||
parseContext.renameShaderFunction($2.string);
|
||||
|
||||
// Make the function
|
||||
function = new TFunction($2.string, type);
|
||||
$$ = function;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,8 +1,8 @@
|
|||
/* A Bison parser, made by GNU Bison 3.0.4. */
|
||||
/* A Bison parser, made by GNU Bison 3.0. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
|
||||
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -345,7 +345,7 @@ extern int yydebug;
|
|||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
union YYSTYPE
|
||||
{
|
||||
#line 68 "MachineIndependent/glslang.y" /* yacc.c:1909 */
|
||||
|
|
@ -384,8 +384,6 @@ union YYSTYPE
|
|||
|
||||
#line 386 "MachineIndependent/glslang_tab.cpp.h" /* yacc.c:1909 */
|
||||
};
|
||||
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue