Updated the includer interface to allow relative includes.
This plumbs both the current file path and the include depth back up to the includer. This allows the includer to properly support relative paths. This also replaces the string copy that was done during include with a zero-copy method of accomplishing the same thing. This prevents extra copies of entire files.
This commit is contained in:
parent
f2d8a5c53f
commit
a132af5b78
7 changed files with 220 additions and 54 deletions
|
|
@ -131,7 +131,8 @@ bool InitializeSymbolTable(const TString& builtIns, int version, EProfile profil
|
|||
TIntermediate intermediate(language, version, profile);
|
||||
|
||||
TParseContext parseContext(symbolTable, intermediate, true, version, profile, spv, vulkan, language, infoSink);
|
||||
TPpContext ppContext(parseContext, TShader::ForbidInclude());
|
||||
TShader::ForbidInclude includer;
|
||||
TPpContext ppContext(parseContext, "", includer);
|
||||
TScanContext scanContext(parseContext);
|
||||
parseContext.setScanContext(&scanContext);
|
||||
parseContext.setPpContext(&ppContext);
|
||||
|
|
@ -482,7 +483,7 @@ bool ProcessDeferred(
|
|||
TIntermediate& intermediate, // returned tree, etc.
|
||||
ProcessingContext& processingContext,
|
||||
bool requireNonempty,
|
||||
const TShader::Includer& includer
|
||||
TShader::Includer& includer
|
||||
)
|
||||
{
|
||||
if (! InitThread())
|
||||
|
|
@ -550,7 +551,6 @@ bool ProcessDeferred(
|
|||
version = defaultVersion;
|
||||
profile = defaultProfile;
|
||||
}
|
||||
|
||||
int spv = (messages & EShMsgSpvRules) ? 100 : 0; // TODO find path to get real version number here, for now non-0 is what matters
|
||||
bool goodVersion = DeduceVersionProfile(compiler->infoSink, compiler->getLanguage(), versionNotFirst, defaultVersion, version, profile, spv);
|
||||
bool versionWillBeError = (versionNotFound || (profile == EEsProfile && version >= 300 && versionNotFirst));
|
||||
|
|
@ -590,7 +590,7 @@ bool ProcessDeferred(
|
|||
|
||||
TParseContext parseContext(symbolTable, intermediate, false, version, profile, spv, vulkan, compiler->getLanguage(), compiler->infoSink, forwardCompatible, messages);
|
||||
glslang::TScanContext scanContext(parseContext);
|
||||
TPpContext ppContext(parseContext, includer);
|
||||
TPpContext ppContext(parseContext, names[numPre]? names[numPre]: "", includer);
|
||||
parseContext.setScanContext(&scanContext);
|
||||
parseContext.setPpContext(&ppContext);
|
||||
parseContext.setLimits(*resources);
|
||||
|
|
@ -863,7 +863,7 @@ bool PreprocessDeferred(
|
|||
bool forceDefaultVersionAndProfile,
|
||||
bool forwardCompatible, // give errors for use of deprecated features
|
||||
EShMessages messages, // warnings/errors/AST; things to print out
|
||||
const TShader::Includer& includer,
|
||||
TShader::Includer& includer,
|
||||
TIntermediate& intermediate, // returned tree, etc.
|
||||
std::string* outputString)
|
||||
{
|
||||
|
|
@ -902,7 +902,7 @@ bool CompileDeferred(
|
|||
bool forwardCompatible, // give errors for use of deprecated features
|
||||
EShMessages messages, // warnings/errors/AST; things to print out
|
||||
TIntermediate& intermediate,// returned tree, etc.
|
||||
const TShader::Includer& includer)
|
||||
TShader::Includer& includer)
|
||||
{
|
||||
DoFullParse parser;
|
||||
return ProcessDeferred(compiler, shaderStrings, numStrings, inputLengths, stringNames,
|
||||
|
|
@ -1051,9 +1051,10 @@ int ShCompile(
|
|||
compiler->infoSink.debug.erase();
|
||||
|
||||
TIntermediate intermediate(compiler->getLanguage());
|
||||
TShader::ForbidInclude includer;
|
||||
bool success = CompileDeferred(compiler, shaderStrings, numStrings, inputLengths, nullptr,
|
||||
"", optLevel, resources, defaultVersion, ENoProfile, false,
|
||||
forwardCompatible, messages, intermediate, TShader::ForbidInclude());
|
||||
forwardCompatible, messages, intermediate, includer);
|
||||
|
||||
//
|
||||
// Call the machine dependent compiler
|
||||
|
|
@ -1361,7 +1362,7 @@ void TShader::setStringsWithLengthsAndNames(
|
|||
// Returns true for success.
|
||||
//
|
||||
bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||
bool forwardCompatible, EShMessages messages, const Includer& includer)
|
||||
bool forwardCompatible, EShMessages messages, Includer& includer)
|
||||
{
|
||||
if (! InitThread())
|
||||
return false;
|
||||
|
|
@ -1389,7 +1390,7 @@ bool TShader::preprocess(const TBuiltInResource* builtInResources,
|
|||
bool forceDefaultVersionAndProfile,
|
||||
bool forwardCompatible, EShMessages message,
|
||||
std::string* output_string,
|
||||
const TShader::Includer& includer)
|
||||
Includer& includer)
|
||||
{
|
||||
if (! InitThread())
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue