Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/ScanContext.h | //
// Copyright (C) 2013 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// This holds context specific to the GLSL scanner, which
// sits between the preprocessor scanner and parser.
//
#pragma once
#include "ParseHelper.h"
namespace glslang {
class TPpContext;
class TPpToken;
class TParserToken;
class TScanContext {
public:
explicit TScanContext(TParseContextBase& pc) :
parseContext(pc),
afterType(false), afterStruct(false),
field(false), afterBuffer(false) { }
virtual ~TScanContext() { }
static void fillInKeywordMap();
static void deleteKeywordMap();
int tokenize(TPpContext*, TParserToken&);
protected:
TScanContext(TScanContext&);
TScanContext& operator=(TScanContext&);
int tokenizeIdentifier();
int identifierOrType();
int reservedWord();
int identifierOrReserved(bool reserved);
int es30ReservedFromGLSL(int version);
int nonreservedKeyword(int esVersion, int nonEsVersion);
int precisionKeyword();
int matNxM();
int dMat();
int firstGenerationImage(bool inEs310);
int secondGenerationImage();
TParseContextBase& parseContext;
bool afterType; // true if we've recognized a type, so can only be looking for an identifier
bool afterStruct; // true if we've recognized the STRUCT keyword, so can only be looking for an identifier
bool field; // true if we're on a field, right after a '.'
bool afterBuffer; // true if we've recognized the BUFFER keyword
TSourceLoc loc;
TParserToken* parserToken;
TPpToken* ppToken;
const char* tokenText;
int keyword;
};
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/iomapper.cpp | //
// Copyright (C) 2016-2017 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "../Include/Common.h"
#include "../Include/InfoSink.h"
#include "../Include/Types.h"
#include "gl_types.h"
#include "iomapper.h"
#include "SymbolTable.h"
//
// Map IO bindings.
//
// High-level algorithm for one stage:
//
// 1. Traverse all code (live+dead) to find the explicitly provided bindings.
//
// 2. Traverse (just) the live code to determine which non-provided bindings
// require auto-numbering. We do not auto-number dead ones.
//
// 3. Traverse all the code to apply the bindings:
// a. explicitly given bindings are offset according to their type
// b. implicit live bindings are auto-numbered into the holes, using
// any open binding slot.
// c. implicit dead bindings are left un-bound.
//
namespace glslang {
class TVarGatherTraverser : public TLiveTraverser {
public:
TVarGatherTraverser(const TIntermediate& i, bool traverseDeadCode, TVarLiveMap& inList, TVarLiveMap& outList, TVarLiveMap& uniformList)
: TLiveTraverser(i, traverseDeadCode, true, true, false)
, inputList(inList)
, outputList(outList)
, uniformList(uniformList)
{
}
virtual void visitSymbol(TIntermSymbol* base)
{
TVarLiveMap* target = nullptr;
if (base->getQualifier().storage == EvqVaryingIn)
target = &inputList;
else if (base->getQualifier().storage == EvqVaryingOut)
target = &outputList;
else if (base->getQualifier().isUniformOrBuffer() && !base->getQualifier().isPushConstant() && !base->getQualifier().isShaderRecord())
target = &uniformList;
// If a global is being visited, then we should also traverse it incase it's evaluation
// ends up visiting inputs we want to tag as live
else if (base->getQualifier().storage == EvqGlobal)
addGlobalReference(base->getAccessName());
if (target) {
TVarEntryInfo ent = {base->getId(), base, ! traverseAll, {}, {}, {}, {}, {}, {}, {}};
ent.stage = intermediate.getStage();
TVarLiveMap::iterator at = target->find(
ent.symbol->getAccessName()); // std::lower_bound(target->begin(), target->end(), ent, TVarEntryInfo::TOrderById());
if (at != target->end() && at->second.id == ent.id)
at->second.live = at->second.live || ! traverseAll; // update live state
else
(*target)[ent.symbol->getAccessName()] = ent;
}
}
private:
TVarLiveMap& inputList;
TVarLiveMap& outputList;
TVarLiveMap& uniformList;
};
class TVarSetTraverser : public TLiveTraverser
{
public:
TVarSetTraverser(const TIntermediate& i, const TVarLiveMap& inList, const TVarLiveMap& outList, const TVarLiveMap& uniformList)
: TLiveTraverser(i, true, true, true, false)
, inputList(inList)
, outputList(outList)
, uniformList(uniformList)
{
}
virtual void visitSymbol(TIntermSymbol* base) {
const TVarLiveMap* source;
if (base->getQualifier().storage == EvqVaryingIn)
source = &inputList;
else if (base->getQualifier().storage == EvqVaryingOut)
source = &outputList;
else if (base->getQualifier().isUniformOrBuffer())
source = &uniformList;
else
return;
TVarEntryInfo ent = { base->getId(), {}, {}, {}, {}, {}, {}, {}, {}, {} };
// Fix a defect, when block has no instance name, we need to find its block name
TVarLiveMap::const_iterator at = source->find(base->getAccessName());
if (at == source->end())
return;
if (at->second.id != ent.id)
return;
if (at->second.newBinding != -1)
base->getWritableType().getQualifier().layoutBinding = at->second.newBinding;
if (at->second.newSet != -1)
base->getWritableType().getQualifier().layoutSet = at->second.newSet;
if (at->second.newLocation != -1)
base->getWritableType().getQualifier().layoutLocation = at->second.newLocation;
if (at->second.newComponent != -1)
base->getWritableType().getQualifier().layoutComponent = at->second.newComponent;
if (at->second.newIndex != -1)
base->getWritableType().getQualifier().layoutIndex = at->second.newIndex;
if (at->second.upgradedToPushConstant)
base->getWritableType().getQualifier().layoutPushConstant = true;
}
private:
const TVarLiveMap& inputList;
const TVarLiveMap& outputList;
const TVarLiveMap& uniformList;
};
struct TNotifyUniformAdaptor
{
EShLanguage stage;
TIoMapResolver& resolver;
inline TNotifyUniformAdaptor(EShLanguage s, TIoMapResolver& r)
: stage(s)
, resolver(r)
{
}
inline void operator()(std::pair<const TString, TVarEntryInfo>& entKey)
{
resolver.notifyBinding(stage, entKey.second);
}
private:
TNotifyUniformAdaptor& operator=(TNotifyUniformAdaptor&) = delete;
};
struct TNotifyInOutAdaptor
{
EShLanguage stage;
TIoMapResolver& resolver;
inline TNotifyInOutAdaptor(EShLanguage s, TIoMapResolver& r)
: stage(s)
, resolver(r)
{
}
inline void operator()(std::pair<const TString, TVarEntryInfo>& entKey)
{
resolver.notifyInOut(entKey.second.stage, entKey.second);
}
private:
TNotifyInOutAdaptor& operator=(TNotifyInOutAdaptor&) = delete;
};
struct TResolverUniformAdaptor {
TResolverUniformAdaptor(EShLanguage s, TIoMapResolver& r, TVarLiveMap* uniform[EShLangCount], TInfoSink& i, bool& e)
: stage(s)
, resolver(r)
, infoSink(i)
, error(e)
{
memcpy(uniformVarMap, uniform, EShLangCount * (sizeof(TVarLiveMap*)));
}
inline void operator()(std::pair<const TString, TVarEntryInfo>& entKey) {
TVarEntryInfo& ent = entKey.second;
ent.clearNewAssignments();
const bool isValid = resolver.validateBinding(stage, ent);
if (isValid) {
resolver.resolveSet(ent.stage, ent);
resolver.resolveBinding(ent.stage, ent);
resolver.resolveUniformLocation(ent.stage, ent);
if (ent.newBinding != -1) {
if (ent.newBinding >= int(TQualifier::layoutBindingEnd)) {
TString err = "mapped binding out of range: " + entKey.first;
infoSink.info.message(EPrefixInternalError, err.c_str());
error = true;
}
if (ent.symbol->getQualifier().hasBinding()) {
for (uint32_t idx = EShLangVertex; idx < EShLangCount; ++idx) {
if (idx == ent.stage || uniformVarMap[idx] == nullptr)
continue;
auto entKey2 = uniformVarMap[idx]->find(entKey.first);
if (entKey2 != uniformVarMap[idx]->end()) {
entKey2->second.newBinding = ent.newBinding;
}
}
}
}
if (ent.newSet != -1) {
if (ent.newSet >= int(TQualifier::layoutSetEnd)) {
TString err = "mapped set out of range: " + entKey.first;
infoSink.info.message(EPrefixInternalError, err.c_str());
error = true;
}
if (ent.symbol->getQualifier().hasSet()) {
for (uint32_t idx = EShLangVertex; idx < EShLangCount; ++idx) {
if ((idx == stage) || (uniformVarMap[idx] == nullptr))
continue;
auto entKey2 = uniformVarMap[idx]->find(entKey.first);
if (entKey2 != uniformVarMap[idx]->end()) {
entKey2->second.newSet = ent.newSet;
}
}
}
}
} else {
TString errorMsg = "Invalid binding: " + entKey.first;
infoSink.info.message(EPrefixInternalError, errorMsg.c_str());
error = true;
}
}
inline void setStage(EShLanguage s) { stage = s; }
EShLanguage stage;
TIoMapResolver& resolver;
TInfoSink& infoSink;
bool& error;
TVarLiveMap* uniformVarMap[EShLangCount];
private:
TResolverUniformAdaptor& operator=(TResolverUniformAdaptor&) = delete;
};
struct TResolverInOutAdaptor {
TResolverInOutAdaptor(EShLanguage s, TIoMapResolver& r, TInfoSink& i, bool& e)
: stage(s)
, resolver(r)
, infoSink(i)
, error(e)
{
}
inline void operator()(std::pair<const TString, TVarEntryInfo>& entKey)
{
TVarEntryInfo& ent = entKey.second;
ent.clearNewAssignments();
const bool isValid = resolver.validateInOut(ent.stage, ent);
if (isValid) {
resolver.resolveInOutLocation(stage, ent);
resolver.resolveInOutComponent(stage, ent);
resolver.resolveInOutIndex(stage, ent);
} else {
TString errorMsg;
if (ent.symbol->getType().getQualifier().semanticName != nullptr) {
errorMsg = "Invalid shader In/Out variable semantic: ";
errorMsg += ent.symbol->getType().getQualifier().semanticName;
} else {
errorMsg = "Invalid shader In/Out variable: ";
errorMsg += ent.symbol->getName();
}
infoSink.info.message(EPrefixInternalError, errorMsg.c_str());
error = true;
}
}
inline void setStage(EShLanguage s) { stage = s; }
EShLanguage stage;
TIoMapResolver& resolver;
TInfoSink& infoSink;
bool& error;
private:
TResolverInOutAdaptor& operator=(TResolverInOutAdaptor&) = delete;
};
// The class is used for reserving explicit uniform locations and ubo/ssbo/opaque bindings
// xxTODO: maybe this logic should be moved into the resolver's "validateInOut" and "validateUniform"
struct TSymbolValidater
{
TSymbolValidater(TIoMapResolver& r, TInfoSink& i, TVarLiveMap* in[EShLangCount], TVarLiveMap* out[EShLangCount],
TVarLiveMap* uniform[EShLangCount], bool& hadError, EProfile profile, int version)
: resolver(r)
, infoSink(i)
, hadError(hadError)
, profile(profile)
, version(version)
{
memcpy(inVarMaps, in, EShLangCount * (sizeof(TVarLiveMap*)));
memcpy(outVarMaps, out, EShLangCount * (sizeof(TVarLiveMap*)));
memcpy(uniformVarMap, uniform, EShLangCount * (sizeof(TVarLiveMap*)));
std::map<TString, TString> anonymousMemberMap;
std::vector<TRange> usedUniformLocation;
std::vector<TString> usedUniformName;
usedUniformLocation.clear();
usedUniformName.clear();
for (int i = 0; i < EShLangCount; i++) {
if (uniformVarMap[i]) {
for (auto uniformVar : *uniformVarMap[i])
{
TIntermSymbol* pSymbol = uniformVar.second.symbol;
TQualifier qualifier = uniformVar.second.symbol->getQualifier();
TString symbolName = pSymbol->getAccessName();
// All the uniform needs multi-stage location check (block/default)
int uniformLocation = qualifier.layoutLocation;
if (uniformLocation != TQualifier::layoutLocationEnd) {
// Total size of current uniform, could be block, struct or other types.
int size = TIntermediate::computeTypeUniformLocationSize(pSymbol->getType());
TRange locationRange(uniformLocation, uniformLocation + size - 1);
// Combine location and component ranges
int overlapLocation = -1;
bool diffLocation = false;
// Check for collisions, except for vertex inputs on desktop targeting OpenGL
overlapLocation = checkLocationOverlap(locationRange, usedUniformLocation, symbolName, usedUniformName, diffLocation);
// Overlap locations of uniforms, regardless of components (multi stages)
if (overlapLocation == -1) {
usedUniformLocation.push_back(locationRange);
usedUniformName.push_back(symbolName);
}
else if (overlapLocation >= 0) {
if (diffLocation == true) {
TString err = ("Uniform location should be equal for same uniforms: " +std::to_string(overlapLocation)).c_str();
infoSink.info.message(EPrefixInternalError, err.c_str());
hadError = true;
break;
}
else {
TString err = ("Uniform location overlaps across stages: " + std::to_string(overlapLocation)).c_str();
infoSink.info.message(EPrefixInternalError, err.c_str());
hadError = true;
break;
}
}
}
if ((uniformVar.second.symbol->getBasicType() == EbtBlock) &&
IsAnonymous(uniformVar.second.symbol->getName()))
{
auto blockType = uniformVar.second.symbol->getType().getStruct();
for (size_t memberIdx = 0; memberIdx < blockType->size(); ++memberIdx) {
auto memberName = (*blockType)[memberIdx].type->getFieldName();
if (anonymousMemberMap.find(memberName) != anonymousMemberMap.end())
{
if (anonymousMemberMap[memberName] != uniformVar.second.symbol->getType().getTypeName())
{
TString err = "Invalid block member name: " + memberName;
infoSink.info.message(EPrefixInternalError, err.c_str());
hadError = true;
break;
}
}
else
{
anonymousMemberMap[memberName] = uniformVar.second.symbol->getType().getTypeName();
}
}
}
if (hadError)
break;
}
}
}
}
// In case we need to new an intermediate, which costs too much
int checkLocationOverlap(const TRange& locationRange, std::vector<TRange>& usedUniformLocation, const TString symbolName, std::vector<TString>& usedUniformName, bool& diffLocation)
{
for (size_t r = 0; r < usedUniformLocation.size(); ++r) {
if (usedUniformName[r] == symbolName) {
diffLocation = true;
return (usedUniformLocation[r].start == locationRange.start &&
usedUniformLocation[r].last == locationRange.last)
? -2 : std::max(locationRange.start, usedUniformLocation[r].start);
}
if (locationRange.overlap(usedUniformLocation[r])) {
// there is a collision; pick one
return std::max(locationRange.start, usedUniformLocation[r].start);
}
}
return -1; // no collision
}
inline void operator()(std::pair<const TString, TVarEntryInfo>& entKey) {
TVarEntryInfo& ent1 = entKey.second;
TIntermSymbol* base = ent1.symbol;
const TType& type = ent1.symbol->getType();
const TString& name = entKey.first;
TString mangleName1, mangleName2;
EShLanguage stage = ent1.stage;
EShLanguage preStage, currentStage, nextStage;
preStage = EShLangCount;
for (int i = stage - 1; i >= 0; i--) {
if (inVarMaps[i] != nullptr) {
preStage = static_cast<EShLanguage>(i);
break;
}
}
currentStage = stage;
nextStage = EShLangCount;
for (int i = stage + 1; i < EShLangCount; i++) {
if (inVarMaps[i] != nullptr) {
nextStage = static_cast<EShLanguage>(i);
break;
}
}
if (type.getQualifier().isArrayedIo(stage)) {
TType subType(type, 0);
subType.appendMangledName(mangleName1);
} else {
type.appendMangledName(mangleName1);
}
// basic checking that symbols match
// more extensive checking in the link stage
if (base->getQualifier().storage == EvqVaryingIn) {
// validate stage in;
if (preStage == EShLangCount)
return;
if (TSymbolTable::isBuiltInSymbol(base->getId()))
return;
if (outVarMaps[preStage] != nullptr) {
auto ent2 = outVarMaps[preStage]->find(name);
uint32_t location = base->getType().getQualifier().layoutLocation;
if (ent2 == outVarMaps[preStage]->end() &&
location != glslang::TQualifier::layoutLocationEnd) {
for (auto var = outVarMaps[preStage]->begin(); var != ent2; var++) {
if (var->second.symbol->getType().getQualifier().layoutLocation == location) {
ent2 = var;
break;
}
}
}
if (ent2 != outVarMaps[preStage]->end()) {
auto& type1 = base->getType();
auto& type2 = ent2->second.symbol->getType();
hadError = hadError || typeCheck(&type1, &type2, name.c_str(), false);
if (ent2->second.symbol->getType().getQualifier().isArrayedIo(preStage)) {
TType subType(ent2->second.symbol->getType(), 0);
subType.appendMangledName(mangleName2);
} else {
ent2->second.symbol->getType().appendMangledName(mangleName2);
}
if (mangleName1 == mangleName2) {
// For ES 3.0 only, other versions have no such restrictions
// According to ES 3.0 spec: The type and presence of the interpolation qualifiers and
// storage qualifiers of variables with the same name declared in all linked shaders must
// match, otherwise the link command will fail.
if (profile == EEsProfile && version == 300) {
// Don't need to check smooth qualifier, as it uses the default interpolation mode
if (ent1.stage == EShLangFragment && type1.isBuiltIn() == false) {
if (type1.getQualifier().flat != type2.getQualifier().flat ||
type1.getQualifier().nopersp != type2.getQualifier().nopersp) {
TString err = "Interpolation qualifier mismatch : " + entKey.first;
infoSink.info.message(EPrefixInternalError, err.c_str());
hadError = true;
}
}
}
return;
}
else {
// Deal with input/output pairs where one is a block member but the other is loose,
// e.g. with ARB_separate_shader_objects
if (type1.getBasicType() == EbtBlock &&
type1.isStruct() && !type2.isStruct()) {
// Iterate through block members tracking layout
glslang::TString name;
type1.getStruct()->begin()->type->appendMangledName(name);
if (name == mangleName2
&& type1.getQualifier().layoutLocation == type2.getQualifier().layoutLocation) return;
}
if (type2.getBasicType() == EbtBlock &&
type2.isStruct() && !type1.isStruct()) {
// Iterate through block members tracking layout
glslang::TString name;
type2.getStruct()->begin()->type->appendMangledName(name);
if (name == mangleName1
&& type1.getQualifier().layoutLocation == type2.getQualifier().layoutLocation) return;
}
TString err = "Invalid In/Out variable type : " + entKey.first;
infoSink.info.message(EPrefixInternalError, err.c_str());
hadError = true;
}
}
else if (!base->getType().isBuiltIn()) {
// According to spec: A link error is generated if any statically referenced input variable
// or block does not have a matching output
if (profile == EEsProfile && ent1.live) {
hadError = true;
TString errorStr = name + ": not been declare as a output variable in pre shader stage.";
infoSink.info.message(EPrefixError, errorStr.c_str());
}
}
return;
}
} else if (base->getQualifier().storage == EvqVaryingOut) {
// validate stage out;
if (nextStage == EShLangCount)
return;
if (TSymbolTable::isBuiltInSymbol(base->getId()))
return;
if (inVarMaps[nextStage] != nullptr) {
auto ent2 = inVarMaps[nextStage]->find(name);
if (ent2 != inVarMaps[nextStage]->end()) {
if (ent2->second.symbol->getType().getQualifier().isArrayedIo(nextStage)) {
TType subType(ent2->second.symbol->getType(), 0);
subType.appendMangledName(mangleName2);
} else {
ent2->second.symbol->getType().appendMangledName(mangleName2);
}
if (mangleName1 == mangleName2)
return;
else {
TString err = "Invalid In/Out variable type : " + entKey.first;
infoSink.info.message(EPrefixInternalError, err.c_str());
hadError = true;
}
}
return;
}
} else if (base->getQualifier().isUniformOrBuffer() && !base->getQualifier().isPushConstant()) {
// validate uniform type;
for (int i = 0; i < EShLangCount; i++) {
if (i != currentStage && outVarMaps[i] != nullptr) {
auto ent2 = uniformVarMap[i]->find(name);
if (ent2 != uniformVarMap[i]->end()) {
ent2->second.symbol->getType().appendMangledName(mangleName2);
if (mangleName1 != mangleName2) {
ent2->second.symbol->getType().sameElementType(type);
TString err = "Invalid Uniform variable type : " + entKey.first;
infoSink.info.message(EPrefixInternalError, err.c_str());
hadError = true;
}
mangleName2.clear();
// validate instance name of blocks
if (hadError == false &&
base->getType().getBasicType() == EbtBlock &&
IsAnonymous(base->getName()) != IsAnonymous(ent2->second.symbol->getName())) {
TString err = "Matched uniform block names must also either all be lacking "
"an instance name or all having an instance name: " + entKey.first;
infoSink.info.message(EPrefixInternalError, err.c_str());
hadError = true;
}
// validate uniform block member qualifier and member names
auto& type1 = base->getType();
auto& type2 = ent2->second.symbol->getType();
if (hadError == false && base->getType().getBasicType() == EbtBlock) {
hadError = hadError || typeCheck(&type1, &type2, name.c_str(), true);
}
else {
hadError = hadError || typeCheck(&type1, &type2, name.c_str(), false);
}
}
else if (base->getBasicType() == EbtBlock)
{
if (IsAnonymous(base->getName()))
{
// The name of anonymous block member can't same with default uniform variable.
auto blockType1 = base->getType().getStruct();
for (size_t memberIdx = 0; memberIdx < blockType1->size(); ++memberIdx) {
auto memberName = (*blockType1)[memberIdx].type->getFieldName();
if (uniformVarMap[i]->find(memberName) != uniformVarMap[i]->end())
{
TString err = "Invalid Uniform variable name : " + memberName;
infoSink.info.message(EPrefixInternalError, err.c_str());
hadError = true;
break;
}
}
}
}
}
}
}
}
TVarLiveMap *inVarMaps[EShLangCount], *outVarMaps[EShLangCount], *uniformVarMap[EShLangCount];
// Use for mark current shader stage for resolver
TIoMapResolver& resolver;
TInfoSink& infoSink;
bool& hadError;
EProfile profile;
int version;
private:
TSymbolValidater& operator=(TSymbolValidater&) = delete;
bool qualifierCheck(const TType* const type1, const TType* const type2, const std::string& name, bool isBlock)
{
bool hasError = false;
const TQualifier& qualifier1 = type1->getQualifier();
const TQualifier& qualifier2 = type2->getQualifier();
if (((isBlock == false) &&
(type1->getQualifier().storage == EvqUniform && type2->getQualifier().storage == EvqUniform)) ||
(type1->getQualifier().storage == EvqGlobal && type2->getQualifier().storage == EvqGlobal)) {
if (qualifier1.precision != qualifier2.precision) {
hasError = true;
std::string errorStr = name + ": have precision conflict cross stage.";
infoSink.info.message(EPrefixError, errorStr.c_str());
}
if (qualifier1.hasFormat() && qualifier2.hasFormat()) {
if (qualifier1.layoutFormat != qualifier2.layoutFormat) {
hasError = true;
std::string errorStr = name + ": have layout format conflict cross stage.";
infoSink.info.message(EPrefixError, errorStr.c_str());
}
}
}
if (isBlock == true) {
if (qualifier1.layoutPacking != qualifier2.layoutPacking) {
hasError = true;
std::string errorStr = name + ": have layoutPacking conflict cross stage.";
infoSink.info.message(EPrefixError, errorStr.c_str());
}
if (qualifier1.layoutMatrix != qualifier2.layoutMatrix) {
hasError = true;
std::string errorStr = name + ": have layoutMatrix conflict cross stage.";
infoSink.info.message(EPrefixError, errorStr.c_str());
}
if (qualifier1.layoutOffset != qualifier2.layoutOffset) {
hasError = true;
std::string errorStr = name + ": have layoutOffset conflict cross stage.";
infoSink.info.message(EPrefixError, errorStr.c_str());
}
if (qualifier1.layoutAlign != qualifier2.layoutAlign) {
hasError = true;
std::string errorStr = name + ": have layoutAlign conflict cross stage.";
infoSink.info.message(EPrefixError, errorStr.c_str());
}
}
return hasError;
}
bool typeCheck(const TType* const type1, const TType* const type2, const std::string& name, bool isBlock)
{
bool hasError = false;
if (!(type1->isStruct() && type2->isStruct())) {
hasError = hasError || qualifierCheck(type1, type2, name, isBlock);
}
else {
if (type1->getBasicType() == EbtBlock && type2->getBasicType() == EbtBlock)
isBlock = true;
const TTypeList* typeList1 = type1->getStruct();
const TTypeList* typeList2 = type2->getStruct();
std::string newName = name;
size_t memberCount = typeList1->size();
size_t index2 = 0;
for (size_t index = 0; index < memberCount; index++, index2++) {
// Skip inactive member
if (typeList1->at(index).type->getBasicType() == EbtVoid)
continue;
while (index2 < typeList2->size() && typeList2->at(index2).type->getBasicType() == EbtVoid) {
++index2;
}
// TypeList1 has more members in list
if (index2 == typeList2->size()) {
std::string errorStr = name + ": struct mismatch.";
infoSink.info.message(EPrefixError, errorStr.c_str());
hasError = true;
break;
}
if (typeList1->at(index).type->getFieldName() != typeList2->at(index2).type->getFieldName()) {
std::string errorStr = name + ": member name mismatch.";
infoSink.info.message(EPrefixError, errorStr.c_str());
hasError = true;
}
else {
newName = typeList1->at(index).type->getFieldName().c_str();
}
hasError = hasError || typeCheck(typeList1->at(index).type, typeList2->at(index2).type, newName, isBlock);
}
while (index2 < typeList2->size())
{
// TypeList2 has more members
if (typeList2->at(index2).type->getBasicType() != EbtVoid) {
std::string errorStr = name + ": struct mismatch.";
infoSink.info.message(EPrefixError, errorStr.c_str());
hasError = true;
break;
}
++index2;
}
}
return hasError;
}
};
struct TSlotCollector {
TSlotCollector(TIoMapResolver& r, TInfoSink& i) : resolver(r), infoSink(i) { }
inline void operator()(std::pair<const TString, TVarEntryInfo>& entKey) {
resolver.reserverStorageSlot(entKey.second, infoSink);
resolver.reserverResourceSlot(entKey.second, infoSink);
}
TIoMapResolver& resolver;
TInfoSink& infoSink;
private:
TSlotCollector& operator=(TSlotCollector&) = delete;
};
TDefaultIoResolverBase::TDefaultIoResolverBase(const TIntermediate& intermediate)
: referenceIntermediate(intermediate)
, nextUniformLocation(intermediate.getUniformLocationBase())
, nextInputLocation(0)
, nextOutputLocation(0)
{
memset(stageMask, false, sizeof(bool) * (EShLangCount + 1));
memset(stageIntermediates, 0, sizeof(TIntermediate*) * (EShLangCount));
stageIntermediates[intermediate.getStage()] = &intermediate;
}
int TDefaultIoResolverBase::getBaseBinding(EShLanguage stage, TResourceType res, unsigned int set) const {
return stageIntermediates[stage] ? selectBaseBinding(stageIntermediates[stage]->getShiftBinding(res), stageIntermediates[stage]->getShiftBindingForSet(res, set))
: selectBaseBinding(referenceIntermediate.getShiftBinding(res), referenceIntermediate.getShiftBindingForSet(res, set));
}
const std::vector<std::string>& TDefaultIoResolverBase::getResourceSetBinding(EShLanguage stage) const {
return stageIntermediates[stage] ? stageIntermediates[stage]->getResourceSetBinding()
: referenceIntermediate.getResourceSetBinding();
}
bool TDefaultIoResolverBase::doAutoBindingMapping() const { return referenceIntermediate.getAutoMapBindings(); }
bool TDefaultIoResolverBase::doAutoLocationMapping() const { return referenceIntermediate.getAutoMapLocations(); }
TDefaultIoResolverBase::TSlotSet::iterator TDefaultIoResolverBase::findSlot(int set, int slot) {
return std::lower_bound(slots[set].begin(), slots[set].end(), slot);
}
bool TDefaultIoResolverBase::checkEmpty(int set, int slot) {
TSlotSet::iterator at = findSlot(set, slot);
return ! (at != slots[set].end() && *at == slot);
}
int TDefaultIoResolverBase::reserveSlot(int set, int slot, int size) {
TSlotSet::iterator at = findSlot(set, slot);
// tolerate aliasing, by not double-recording aliases
// (policy about appropriateness of the alias is higher up)
for (int i = 0; i < size; i++) {
if (at == slots[set].end() || *at != slot + i)
at = slots[set].insert(at, slot + i);
++at;
}
return slot;
}
int TDefaultIoResolverBase::getFreeSlot(int set, int base, int size) {
TSlotSet::iterator at = findSlot(set, base);
if (at == slots[set].end())
return reserveSlot(set, base, size);
// look for a big enough gap
for (; at != slots[set].end(); ++at) {
if (*at - base >= size)
break;
base = *at + 1;
}
return reserveSlot(set, base, size);
}
int TDefaultIoResolverBase::resolveSet(EShLanguage stage, TVarEntryInfo& ent) {
const TType& type = ent.symbol->getType();
if (type.getQualifier().hasSet()) {
return ent.newSet = type.getQualifier().layoutSet;
}
// If a command line or API option requested a single descriptor set, use that (if not overrided by spaceN)
if (getResourceSetBinding(stage).size() == 1) {
return ent.newSet = atoi(getResourceSetBinding(stage)[0].c_str());
}
return ent.newSet = 0;
}
int TDefaultIoResolverBase::resolveUniformLocation(EShLanguage /*stage*/, TVarEntryInfo& ent) {
const TType& type = ent.symbol->getType();
const char* name = ent.symbol->getAccessName().c_str();
// kick out of not doing this
if (! doAutoLocationMapping()) {
return ent.newLocation = -1;
}
// no locations added if already present, a built-in variable, a block, or an opaque
if (type.getQualifier().hasLocation() || type.isBuiltIn() || type.getBasicType() == EbtBlock ||
type.isAtomic() || type.isSpirvType() || (type.containsOpaque() && referenceIntermediate.getSpv().openGl == 0)) {
return ent.newLocation = -1;
}
// no locations on blocks of built-in variables
if (type.isStruct()) {
if (type.getStruct()->size() < 1) {
return ent.newLocation = -1;
}
if ((*type.getStruct())[0].type->isBuiltIn()) {
return ent.newLocation = -1;
}
}
int location = referenceIntermediate.getUniformLocationOverride(name);
if (location != -1) {
return ent.newLocation = location;
}
location = nextUniformLocation;
nextUniformLocation += TIntermediate::computeTypeUniformLocationSize(type);
return ent.newLocation = location;
}
int TDefaultIoResolverBase::resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) {
const TType& type = ent.symbol->getType();
// kick out of not doing this
if (! doAutoLocationMapping()) {
return ent.newLocation = -1;
}
// no locations added if already present, a built-in variable, or a variable with SPIR-V decorate
if (type.getQualifier().hasLocation() || type.isBuiltIn() || type.getQualifier().hasSpirvDecorate()) {
return ent.newLocation = -1;
}
// no locations on blocks of built-in variables
if (type.isStruct()) {
if (type.getStruct()->size() < 1) {
return ent.newLocation = -1;
}
if ((*type.getStruct())[0].type->isBuiltIn()) {
return ent.newLocation = -1;
}
}
// point to the right input or output location counter
int& nextLocation = type.getQualifier().isPipeInput() ? nextInputLocation : nextOutputLocation;
// Placeholder. This does not do proper cross-stage lining up, nor
// work with mixed location/no-location declarations.
int location = nextLocation;
int typeLocationSize;
// Don’t take into account the outer-most array if the stage’s
// interface is automatically an array.
typeLocationSize = computeTypeLocationSize(type, stage);
nextLocation += typeLocationSize;
return ent.newLocation = location;
}
int TDefaultIoResolverBase::resolveInOutComponent(EShLanguage /*stage*/, TVarEntryInfo& ent) {
return ent.newComponent = -1;
}
int TDefaultIoResolverBase::resolveInOutIndex(EShLanguage /*stage*/, TVarEntryInfo& ent) { return ent.newIndex = -1; }
uint32_t TDefaultIoResolverBase::computeTypeLocationSize(const TType& type, EShLanguage stage) {
int typeLocationSize;
// Don’t take into account the outer-most array if the stage’s
// interface is automatically an array.
if (type.getQualifier().isArrayedIo(stage)) {
TType elementType(type, 0);
typeLocationSize = TIntermediate::computeTypeLocationSize(elementType, stage);
} else {
typeLocationSize = TIntermediate::computeTypeLocationSize(type, stage);
}
return typeLocationSize;
}
//TDefaultGlslIoResolver
TResourceType TDefaultGlslIoResolver::getResourceType(const glslang::TType& type) {
if (isImageType(type)) {
return EResImage;
}
if (isTextureType(type)) {
return EResTexture;
}
if (isSsboType(type)) {
return EResSsbo;
}
if (isSamplerType(type)) {
return EResSampler;
}
if (isUboType(type)) {
return EResUbo;
}
return EResCount;
}
TDefaultGlslIoResolver::TDefaultGlslIoResolver(const TIntermediate& intermediate)
: TDefaultIoResolverBase(intermediate)
, preStage(EShLangCount)
, currentStage(EShLangCount)
{ }
int TDefaultGlslIoResolver::resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) {
const TType& type = ent.symbol->getType();
const TString& name = ent.symbol->getAccessName();
if (currentStage != stage) {
preStage = currentStage;
currentStage = stage;
}
// kick out if not doing this
if (! doAutoLocationMapping()) {
return ent.newLocation = -1;
}
// expand the location to each element if the symbol is a struct or array
if (type.getQualifier().hasLocation()) {
return ent.newLocation = type.getQualifier().layoutLocation;
}
// no locations added if already present, a built-in variable, or a variable with SPIR-V decorate
if (type.isBuiltIn() || type.getQualifier().hasSpirvDecorate()) {
return ent.newLocation = -1;
}
// no locations on blocks of built-in variables
if (type.isStruct()) {
if (type.getStruct()->size() < 1) {
return ent.newLocation = -1;
}
if ((*type.getStruct())[0].type->isBuiltIn()) {
return ent.newLocation = -1;
}
}
int typeLocationSize = computeTypeLocationSize(type, stage);
int location = type.getQualifier().layoutLocation;
bool hasLocation = false;
EShLanguage keyStage(EShLangCount);
TStorageQualifier storage;
storage = EvqInOut;
if (type.getQualifier().isPipeInput()) {
// If this symbol is a input, search pre stage's out
keyStage = preStage;
}
if (type.getQualifier().isPipeOutput()) {
// If this symbol is a output, search next stage's in
keyStage = currentStage;
}
// The in/out in current stage is not declared with location, but it is possible declared
// with explicit location in other stages, find the storageSlotMap firstly to check whether
// the in/out has location
int resourceKey = buildStorageKey(keyStage, storage);
if (! storageSlotMap[resourceKey].empty()) {
TVarSlotMap::iterator iter = storageSlotMap[resourceKey].find(name);
if (iter != storageSlotMap[resourceKey].end()) {
// If interface resource be found, set it has location and this symbol's new location
// equal the symbol's explicit location declaration in pre or next stage.
//
// vs: out vec4 a;
// fs: layout(..., location = 3,...) in vec4 a;
hasLocation = true;
location = iter->second;
// if we want deal like that:
// vs: layout(location=4) out vec4 a;
// out vec4 b;
//
// fs: in vec4 a;
// layout(location = 4) in vec4 b;
// we need retraverse the map.
}
if (! hasLocation) {
// If interface resource note found, It's mean the location in two stage are both implicit declarat.
// So we should find a new slot for this interface.
//
// vs: out vec4 a;
// fs: in vec4 a;
location = getFreeSlot(resourceKey, 0, typeLocationSize);
storageSlotMap[resourceKey][name] = location;
}
} else {
// the first interface declarated in a program.
TVarSlotMap varSlotMap;
location = getFreeSlot(resourceKey, 0, typeLocationSize);
varSlotMap[name] = location;
storageSlotMap[resourceKey] = varSlotMap;
}
//Update location
return ent.newLocation = location;
}
int TDefaultGlslIoResolver::resolveUniformLocation(EShLanguage /*stage*/, TVarEntryInfo& ent) {
const TType& type = ent.symbol->getType();
const TString& name = ent.symbol->getAccessName();
// kick out of not doing this
if (! doAutoLocationMapping()) {
return ent.newLocation = -1;
}
// expand the location to each element if the symbol is a struct or array
if (type.getQualifier().hasLocation() && (type.isStruct() || type.isArray())) {
return ent.newLocation = type.getQualifier().layoutLocation;
} else {
// no locations added if already present, a built-in variable, a block, or an opaque
if (type.getQualifier().hasLocation() || type.isBuiltIn() || type.getBasicType() == EbtBlock ||
type.isAtomic() || type.isSpirvType() ||
(type.containsOpaque() && referenceIntermediate.getSpv().openGl == 0)) {
return ent.newLocation = -1;
}
// no locations on blocks of built-in variables
if (type.isStruct()) {
if (type.getStruct()->size() < 1) {
return ent.newLocation = -1;
}
if ((*type.getStruct())[0].type->isBuiltIn()) {
return ent.newLocation = -1;
}
}
}
int location = referenceIntermediate.getUniformLocationOverride(name.c_str());
if (location != -1) {
return ent.newLocation = location;
}
int size = TIntermediate::computeTypeUniformLocationSize(type);
// The uniform in current stage is not declared with location, but it is possible declared
// with explicit location in other stages, find the storageSlotMap firstly to check whether
// the uniform has location
bool hasLocation = false;
int resourceKey = buildStorageKey(EShLangCount, EvqUniform);
TVarSlotMap& slotMap = storageSlotMap[resourceKey];
// Check dose shader program has uniform resource
if (! slotMap.empty()) {
// If uniform resource not empty, try find a same name uniform
TVarSlotMap::iterator iter = slotMap.find(name);
if (iter != slotMap.end()) {
// If uniform resource be found, set it has location and this symbol's new location
// equal the uniform's explicit location declaration in other stage.
//
// vs: uniform vec4 a;
// fs: layout(..., location = 3,...) uniform vec4 a;
hasLocation = true;
location = iter->second;
}
if (! hasLocation) {
// No explicit location declaration in other stage.
// So we should find a new slot for this uniform.
//
// vs: uniform vec4 a;
// fs: uniform vec4 a;
location = getFreeSlot(resourceKey, 0, computeTypeLocationSize(type, currentStage));
storageSlotMap[resourceKey][name] = location;
}
} else {
// the first uniform declaration in a program.
TVarSlotMap varSlotMap;
location = getFreeSlot(resourceKey, 0, size);
varSlotMap[name] = location;
storageSlotMap[resourceKey] = varSlotMap;
}
return ent.newLocation = location;
}
int TDefaultGlslIoResolver::resolveBinding(EShLanguage stage, TVarEntryInfo& ent) {
const TType& type = ent.symbol->getType();
const TString& name = ent.symbol->getAccessName();
// On OpenGL arrays of opaque types take a separate binding for each element
int numBindings = referenceIntermediate.getSpv().openGl != 0 && type.isSizedArray() ? type.getCumulativeArraySize() : 1;
TResourceType resource = getResourceType(type);
// don't need to handle uniform symbol, it will be handled in resolveUniformLocation
if (resource == EResUbo && type.getBasicType() != EbtBlock) {
return ent.newBinding = -1;
}
// There is no 'set' qualifier in OpenGL shading language, each resource has its own
// binding name space, so remap the 'set' to resource type which make each resource
// binding is valid from 0 to MAX_XXRESOURCE_BINDINGS
int set = referenceIntermediate.getSpv().openGl != 0 ? resource : ent.newSet;
int resourceKey = set;
if (resource < EResCount) {
if (type.getQualifier().hasBinding()) {
int newBinding = reserveSlot(resourceKey, getBaseBinding(stage, resource, set) + type.getQualifier().layoutBinding, numBindings);
return ent.newBinding = newBinding;
} else {
// The resource in current stage is not declared with binding, but it is possible declared
// with explicit binding in other stages, find the resourceSlotMap firstly to check whether
// the resource has binding, don't need to allocate if it already has a binding
bool hasBinding = false;
ent.newBinding = -1; // leave as -1 if it isn't set below
if (! resourceSlotMap[resourceKey].empty()) {
TVarSlotMap::iterator iter = resourceSlotMap[resourceKey].find(name);
if (iter != resourceSlotMap[resourceKey].end()) {
hasBinding = true;
ent.newBinding = iter->second;
}
}
if (!hasBinding && (ent.live && doAutoBindingMapping())) {
// find free slot, the caller did make sure it passes all vars with binding
// first and now all are passed that do not have a binding and needs one
int binding = getFreeSlot(resourceKey, getBaseBinding(stage, resource, set), numBindings);
resourceSlotMap[resourceKey][name] = binding;
ent.newBinding = binding;
}
return ent.newBinding;
}
}
return ent.newBinding = -1;
}
void TDefaultGlslIoResolver::beginResolve(EShLanguage stage) {
// reset stage state
if (stage == EShLangCount)
preStage = currentStage = stage;
// update stage state
else if (currentStage != stage) {
preStage = currentStage;
currentStage = stage;
}
}
void TDefaultGlslIoResolver::endResolve(EShLanguage /*stage*/) {
// TODO nothing
}
void TDefaultGlslIoResolver::beginCollect(EShLanguage stage) {
// reset stage state
if (stage == EShLangCount)
preStage = currentStage = stage;
// update stage state
else if (currentStage != stage) {
preStage = currentStage;
currentStage = stage;
}
}
void TDefaultGlslIoResolver::endCollect(EShLanguage /*stage*/) {
// TODO nothing
}
void TDefaultGlslIoResolver::reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) {
const TType& type = ent.symbol->getType();
const TString& name = ent.symbol->getAccessName();
TStorageQualifier storage = type.getQualifier().storage;
EShLanguage stage(EShLangCount);
switch (storage) {
case EvqUniform:
if (type.getBasicType() != EbtBlock && type.getQualifier().hasLocation()) {
//
// Reserve the slots for the uniforms who has explicit location
int storageKey = buildStorageKey(EShLangCount, EvqUniform);
int location = type.getQualifier().layoutLocation;
TVarSlotMap& varSlotMap = storageSlotMap[storageKey];
TVarSlotMap::iterator iter = varSlotMap.find(name);
if (iter == varSlotMap.end()) {
int numLocations = TIntermediate::computeTypeUniformLocationSize(type);
reserveSlot(storageKey, location, numLocations);
varSlotMap[name] = location;
} else {
// Allocate location by name for OpenGL driver, so the uniform in different
// stages should be declared with the same location
if (iter->second != location) {
TString errorMsg = "Invalid location: " + name;
infoSink.info.message(EPrefixInternalError, errorMsg.c_str());
hasError = true;
}
}
}
break;
case EvqVaryingIn:
case EvqVaryingOut:
//
// Reserve the slots for the inout who has explicit location
if (type.getQualifier().hasLocation()) {
stage = storage == EvqVaryingIn ? preStage : stage;
stage = storage == EvqVaryingOut ? currentStage : stage;
int storageKey = buildStorageKey(stage, EvqInOut);
int location = type.getQualifier().layoutLocation;
TVarSlotMap& varSlotMap = storageSlotMap[storageKey];
TVarSlotMap::iterator iter = varSlotMap.find(name);
if (iter == varSlotMap.end()) {
int numLocations = TIntermediate::computeTypeUniformLocationSize(type);
reserveSlot(storageKey, location, numLocations);
varSlotMap[name] = location;
} else {
// Allocate location by name for OpenGL driver, so the uniform in different
// stages should be declared with the same location
if (iter->second != location) {
TString errorMsg = "Invalid location: " + name;
infoSink.info.message(EPrefixInternalError, errorMsg.c_str());
hasError = true;
}
}
}
break;
default:
break;
}
}
void TDefaultGlslIoResolver::reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) {
const TType& type = ent.symbol->getType();
const TString& name = ent.symbol->getAccessName();
TResourceType resource = getResourceType(type);
int set = referenceIntermediate.getSpv().openGl != 0 ? resource : resolveSet(ent.stage, ent);
int resourceKey = set;
if (type.getQualifier().hasBinding()) {
TVarSlotMap& varSlotMap = resourceSlotMap[resourceKey];
TVarSlotMap::iterator iter = varSlotMap.find(name);
int binding = type.getQualifier().layoutBinding + getBaseBinding(ent.stage, resource, set);
if (iter == varSlotMap.end()) {
// Reserve the slots for the ubo, ssbo and opaques who has explicit binding
int numBindings = referenceIntermediate.getSpv().openGl != 0 && type.isSizedArray() ? type.getCumulativeArraySize() : 1;
varSlotMap[name] = binding;
reserveSlot(resourceKey, binding, numBindings);
} else {
// Allocate binding by name for OpenGL driver, so the resource in different
// stages should be declared with the same binding
if (iter->second != binding) {
TString errorMsg = "Invalid binding: " + name;
infoSink.info.message(EPrefixInternalError, errorMsg.c_str());
hasError = true;
}
}
}
}
//TDefaultGlslIoResolver end
/*
* Basic implementation of glslang::TIoMapResolver that replaces the
* previous offset behavior.
* It does the same, uses the offsets for the corresponding uniform
* types. Also respects the EOptionAutoMapBindings flag and binds
* them if needed.
*/
/*
* Default resolver
*/
struct TDefaultIoResolver : public TDefaultIoResolverBase {
TDefaultIoResolver(const TIntermediate& intermediate) : TDefaultIoResolverBase(intermediate) { }
bool validateBinding(EShLanguage /*stage*/, TVarEntryInfo& /*ent*/) override { return true; }
TResourceType getResourceType(const glslang::TType& type) override {
if (isImageType(type)) {
return EResImage;
}
if (isTextureType(type)) {
return EResTexture;
}
if (isSsboType(type)) {
return EResSsbo;
}
if (isSamplerType(type)) {
return EResSampler;
}
if (isUboType(type)) {
return EResUbo;
}
return EResCount;
}
int resolveBinding(EShLanguage stage, TVarEntryInfo& ent) override {
const TType& type = ent.symbol->getType();
const int set = getLayoutSet(type);
// On OpenGL arrays of opaque types take a seperate binding for each element
int numBindings = referenceIntermediate.getSpv().openGl != 0 && type.isSizedArray() ? type.getCumulativeArraySize() : 1;
TResourceType resource = getResourceType(type);
if (resource < EResCount) {
if (type.getQualifier().hasBinding()) {
return ent.newBinding = reserveSlot(
set, getBaseBinding(stage, resource, set) + type.getQualifier().layoutBinding, numBindings);
} else if (ent.live && doAutoBindingMapping()) {
// find free slot, the caller did make sure it passes all vars with binding
// first and now all are passed that do not have a binding and needs one
return ent.newBinding = getFreeSlot(set, getBaseBinding(stage, resource, set), numBindings);
}
}
return ent.newBinding = -1;
}
};
#ifdef ENABLE_HLSL
/********************************************************************************
The following IO resolver maps types in HLSL register space, as follows:
t - for shader resource views (SRV)
TEXTURE1D
TEXTURE1DARRAY
TEXTURE2D
TEXTURE2DARRAY
TEXTURE3D
TEXTURECUBE
TEXTURECUBEARRAY
TEXTURE2DMS
TEXTURE2DMSARRAY
STRUCTUREDBUFFER
BYTEADDRESSBUFFER
BUFFER
TBUFFER
s - for samplers
SAMPLER
SAMPLER1D
SAMPLER2D
SAMPLER3D
SAMPLERCUBE
SAMPLERSTATE
SAMPLERCOMPARISONSTATE
u - for unordered access views (UAV)
RWBYTEADDRESSBUFFER
RWSTRUCTUREDBUFFER
APPENDSTRUCTUREDBUFFER
CONSUMESTRUCTUREDBUFFER
RWBUFFER
RWTEXTURE1D
RWTEXTURE1DARRAY
RWTEXTURE2D
RWTEXTURE2DARRAY
RWTEXTURE3D
b - for constant buffer views (CBV)
CBUFFER
CONSTANTBUFFER
********************************************************************************/
struct TDefaultHlslIoResolver : public TDefaultIoResolverBase {
TDefaultHlslIoResolver(const TIntermediate& intermediate) : TDefaultIoResolverBase(intermediate) { }
bool validateBinding(EShLanguage /*stage*/, TVarEntryInfo& /*ent*/) override { return true; }
TResourceType getResourceType(const glslang::TType& type) override {
if (isUavType(type)) {
return EResUav;
}
if (isSrvType(type)) {
return EResTexture;
}
if (isSamplerType(type)) {
return EResSampler;
}
if (isUboType(type)) {
return EResUbo;
}
return EResCount;
}
int resolveBinding(EShLanguage stage, TVarEntryInfo& ent) override {
const TType& type = ent.symbol->getType();
const int set = getLayoutSet(type);
TResourceType resource = getResourceType(type);
if (resource < EResCount) {
if (type.getQualifier().hasBinding()) {
return ent.newBinding = reserveSlot(set, getBaseBinding(stage, resource, set) + type.getQualifier().layoutBinding);
} else if (ent.live && doAutoBindingMapping()) {
// find free slot, the caller did make sure it passes all vars with binding
// first and now all are passed that do not have a binding and needs one
return ent.newBinding = getFreeSlot(set, getBaseBinding(stage, resource, set));
}
}
return ent.newBinding = -1;
}
};
#endif
// Map I/O variables to provided offsets, and make bindings for
// unbound but live variables.
//
// Returns false if the input is too malformed to do this.
bool TIoMapper::addStage(EShLanguage stage, TIntermediate& intermediate, TInfoSink& infoSink, TIoMapResolver* resolver) {
bool somethingToDo = ! intermediate.getResourceSetBinding().empty() || intermediate.getAutoMapBindings() ||
intermediate.getAutoMapLocations();
// Restrict the stricter condition to further check 'somethingToDo' only if 'somethingToDo' has not been set, reduce
// unnecessary or insignificant for-loop operation after 'somethingToDo' have been true.
for (int res = 0; (res < EResCount && !somethingToDo); ++res) {
somethingToDo = somethingToDo || (intermediate.getShiftBinding(TResourceType(res)) != 0) ||
intermediate.hasShiftBindingForSet(TResourceType(res));
}
if (! somethingToDo && resolver == nullptr)
return true;
if (intermediate.getNumEntryPoints() != 1 || intermediate.isRecursive())
return false;
TIntermNode* root = intermediate.getTreeRoot();
if (root == nullptr)
return false;
// if no resolver is provided, use the default resolver with the given shifts and auto map settings
TDefaultIoResolver defaultResolver(intermediate);
#ifdef ENABLE_HLSL
TDefaultHlslIoResolver defaultHlslResolver(intermediate);
if (resolver == nullptr) {
// TODO: use a passed in IO mapper for this
if (intermediate.usingHlslIoMapping())
resolver = &defaultHlslResolver;
else
resolver = &defaultResolver;
}
#else
resolver = &defaultResolver;
#endif
resolver->addStage(stage, intermediate);
TVarLiveMap inVarMap, outVarMap, uniformVarMap;
TVarLiveVector inVector, outVector, uniformVector;
TVarGatherTraverser iter_binding_all(intermediate, true, inVarMap, outVarMap, uniformVarMap);
TVarGatherTraverser iter_binding_live(intermediate, false, inVarMap, outVarMap, uniformVarMap);
root->traverse(&iter_binding_all);
iter_binding_live.pushFunction(intermediate.getEntryPointMangledName().c_str());
while (! iter_binding_live.destinations.empty()) {
TIntermNode* destination = iter_binding_live.destinations.back();
iter_binding_live.destinations.pop_back();
destination->traverse(&iter_binding_live);
}
// sort entries by priority. see TVarEntryInfo::TOrderByPriority for info.
for (auto& var : inVarMap) { inVector.push_back(var); }
std::sort(inVector.begin(), inVector.end(), [](const TVarLivePair& p1, const TVarLivePair& p2) -> bool {
return TVarEntryInfo::TOrderByPriority()(p1.second, p2.second);
});
for (auto& var : outVarMap) { outVector.push_back(var); }
std::sort(outVector.begin(), outVector.end(), [](const TVarLivePair& p1, const TVarLivePair& p2) -> bool {
return TVarEntryInfo::TOrderByPriority()(p1.second, p2.second);
});
for (auto& var : uniformVarMap) { uniformVector.push_back(var); }
std::sort(uniformVector.begin(), uniformVector.end(), [](const TVarLivePair& p1, const TVarLivePair& p2) -> bool {
return TVarEntryInfo::TOrderByPriority()(p1.second, p2.second);
});
bool hadError = false;
TVarLiveMap* dummyUniformVarMap[EShLangCount] = {};
TNotifyInOutAdaptor inOutNotify(stage, *resolver);
TNotifyUniformAdaptor uniformNotify(stage, *resolver);
TResolverUniformAdaptor uniformResolve(stage, *resolver, dummyUniformVarMap, infoSink, hadError);
TResolverInOutAdaptor inOutResolve(stage, *resolver, infoSink, hadError);
resolver->beginNotifications(stage);
std::for_each(inVector.begin(), inVector.end(), inOutNotify);
std::for_each(outVector.begin(), outVector.end(), inOutNotify);
std::for_each(uniformVector.begin(), uniformVector.end(), uniformNotify);
resolver->endNotifications(stage);
resolver->beginResolve(stage);
for (auto& var : inVector) { inOutResolve(var); }
std::for_each(inVector.begin(), inVector.end(), [&inVarMap](TVarLivePair p) {
auto at = inVarMap.find(p.second.symbol->getAccessName());
if (at != inVarMap.end() && p.second.id == at->second.id)
at->second = p.second;
});
for (auto& var : outVector) { inOutResolve(var); }
std::for_each(outVector.begin(), outVector.end(), [&outVarMap](TVarLivePair p) {
auto at = outVarMap.find(p.second.symbol->getAccessName());
if (at != outVarMap.end() && p.second.id == at->second.id)
at->second = p.second;
});
std::for_each(uniformVector.begin(), uniformVector.end(), uniformResolve);
std::for_each(uniformVector.begin(), uniformVector.end(), [&uniformVarMap](TVarLivePair p) {
auto at = uniformVarMap.find(p.second.symbol->getAccessName());
if (at != uniformVarMap.end() && p.second.id == at->second.id)
at->second = p.second;
});
resolver->endResolve(stage);
if (!hadError) {
TVarSetTraverser iter_iomap(intermediate, inVarMap, outVarMap, uniformVarMap);
root->traverse(&iter_iomap);
}
return !hadError;
}
// Map I/O variables to provided offsets, and make bindings for
// unbound but live variables.
//
// Returns false if the input is too malformed to do this.
bool TGlslIoMapper::addStage(EShLanguage stage, TIntermediate& intermediate, TInfoSink& infoSink, TIoMapResolver* resolver) {
bool somethingToDo = !intermediate.getResourceSetBinding().empty() ||
intermediate.getAutoMapBindings() ||
intermediate.getAutoMapLocations();
// Profile and version are use for symbol validate.
profile = intermediate.getProfile();
version = intermediate.getVersion();
// Restrict the stricter condition to further check 'somethingToDo' only if 'somethingToDo' has not been set, reduce
// unnecessary or insignificant for-loop operation after 'somethingToDo' have been true.
for (int res = 0; (res < EResCount && !somethingToDo); ++res) {
somethingToDo = somethingToDo || (intermediate.getShiftBinding(TResourceType(res)) != 0) ||
intermediate.hasShiftBindingForSet(TResourceType(res));
}
if (! somethingToDo && resolver == nullptr) {
return true;
}
if (intermediate.getNumEntryPoints() != 1 || intermediate.isRecursive()) {
return false;
}
TIntermNode* root = intermediate.getTreeRoot();
if (root == nullptr) {
return false;
}
// if no resolver is provided, use the default resolver with the given shifts and auto map settings
TDefaultGlslIoResolver defaultResolver(intermediate);
#ifdef ENABLE_HLSL
TDefaultHlslIoResolver defaultHlslResolver(intermediate);
if (resolver == nullptr) {
// TODO: use a passed in IO mapper for this
if (intermediate.usingHlslIoMapping())
resolver = &defaultHlslResolver;
else
resolver = &defaultResolver;
}
#else
if (resolver == nullptr) {
resolver = &defaultResolver;
}
#endif
resolver->addStage(stage, intermediate);
inVarMaps[stage] = new TVarLiveMap(); outVarMaps[stage] = new TVarLiveMap(); uniformVarMap[stage] = new TVarLiveMap();
TVarGatherTraverser iter_binding_all(intermediate, true, *inVarMaps[stage], *outVarMaps[stage],
*uniformVarMap[stage]);
TVarGatherTraverser iter_binding_live(intermediate, false, *inVarMaps[stage], *outVarMaps[stage],
*uniformVarMap[stage]);
root->traverse(&iter_binding_all);
iter_binding_live.pushFunction(intermediate.getEntryPointMangledName().c_str());
while (! iter_binding_live.destinations.empty()) {
TIntermNode* destination = iter_binding_live.destinations.back();
iter_binding_live.destinations.pop_back();
destination->traverse(&iter_binding_live);
}
TNotifyInOutAdaptor inOutNotify(stage, *resolver);
TNotifyUniformAdaptor uniformNotify(stage, *resolver);
// Resolve current stage input symbol location with previous stage output here,
// uniform symbol, ubo, ssbo and opaque symbols are per-program resource,
// will resolve uniform symbol location and ubo/ssbo/opaque binding in doMap()
resolver->beginNotifications(stage);
std::for_each(inVarMaps[stage]->begin(), inVarMaps[stage]->end(), inOutNotify);
std::for_each(outVarMaps[stage]->begin(), outVarMaps[stage]->end(), inOutNotify);
std::for_each(uniformVarMap[stage]->begin(), uniformVarMap[stage]->end(), uniformNotify);
resolver->endNotifications(stage);
TSlotCollector slotCollector(*resolver, infoSink);
resolver->beginCollect(stage);
std::for_each(inVarMaps[stage]->begin(), inVarMaps[stage]->end(), slotCollector);
std::for_each(outVarMaps[stage]->begin(), outVarMaps[stage]->end(), slotCollector);
std::for_each(uniformVarMap[stage]->begin(), uniformVarMap[stage]->end(), slotCollector);
resolver->endCollect(stage);
intermediates[stage] = &intermediate;
return !hadError;
}
bool TGlslIoMapper::doMap(TIoMapResolver* resolver, TInfoSink& infoSink) {
resolver->endResolve(EShLangCount);
if (!hadError) {
//Resolve uniform location, ubo/ssbo/opaque bindings across stages
TResolverUniformAdaptor uniformResolve(EShLangCount, *resolver, uniformVarMap, infoSink, hadError);
TResolverInOutAdaptor inOutResolve(EShLangCount, *resolver, infoSink, hadError);
TSymbolValidater symbolValidater(*resolver, infoSink, inVarMaps,
outVarMaps, uniformVarMap, hadError, profile, version);
TVarLiveVector inVectors[EShLangCount];
TVarLiveVector outVectors[EShLangCount];
TVarLiveVector uniformVector;
resolver->beginResolve(EShLangCount);
for (int stage = EShLangVertex; stage < EShLangCount; stage++) {
if (inVarMaps[stage] != nullptr) {
inOutResolve.setStage(EShLanguage(stage));
// copy vars into a sorted list
std::for_each(inVarMaps[stage]->begin(), inVarMaps[stage]->end(),
[&inVectors, stage](TVarLivePair p) { inVectors[stage].push_back(p); });
std::sort(inVectors[stage].begin(), inVectors[stage].end(),
[](const TVarLivePair& p1, const TVarLivePair& p2) -> bool {
return TVarEntryInfo::TOrderByPriority()(p1.second, p2.second);
});
std::for_each(outVarMaps[stage]->begin(), outVarMaps[stage]->end(),
[&outVectors, stage](TVarLivePair p) { outVectors[stage].push_back(p); });
std::sort(outVectors[stage].begin(), outVectors[stage].end(),
[](const TVarLivePair& p1, const TVarLivePair& p2) -> bool {
return TVarEntryInfo::TOrderByPriority()(p1.second, p2.second);
});
for (auto& var : inVectors[stage]) { symbolValidater(var); }
for (auto& var : inVectors[stage]) { inOutResolve(var); }
for (auto& var : outVectors[stage]) { symbolValidater(var); }
for (auto& var : outVectors[stage]) { inOutResolve(var); }
// copy results back into maps
std::for_each(inVectors[stage].begin(), inVectors[stage].end(),
[this, stage](TVarLivePair p) {
auto at = inVarMaps[stage]->find(p.first);
if (at != inVarMaps[stage]->end())
at->second = p.second;
});
std::for_each(outVectors[stage].begin(), outVectors[stage].end(),
[this, stage](TVarLivePair p) {
auto at = outVarMaps[stage]->find(p.first);
if (at != outVarMaps[stage]->end())
at->second = p.second;
});
}
if (uniformVarMap[stage] != nullptr) {
uniformResolve.setStage(EShLanguage(stage));
for (auto& var : *(uniformVarMap[stage])) { uniformVector.push_back(var); }
}
}
std::sort(uniformVector.begin(), uniformVector.end(), [](const TVarLivePair& p1, const TVarLivePair& p2) -> bool {
return TVarEntryInfo::TOrderByPriorityAndLive()(p1.second, p2.second);
});
for (auto& var : uniformVector) { symbolValidater(var); }
for (auto& var : uniformVector) { uniformResolve(var); }
std::sort(uniformVector.begin(), uniformVector.end(), [](const TVarLivePair& p1, const TVarLivePair& p2) -> bool {
return TVarEntryInfo::TOrderByPriority()(p1.second, p2.second);
});
resolver->endResolve(EShLangCount);
if (autoPushConstantBlockName.length()) {
bool upgraded = false;
for (size_t stage = 0; stage < EShLangCount; stage++) {
if (intermediates[stage] != nullptr) {
TVarLiveMap** pUniformVarMap = uniformResolve.uniformVarMap;
auto at = pUniformVarMap[stage]->find(autoPushConstantBlockName);
if (at == pUniformVarMap[stage]->end())
continue;
TQualifier& qualifier = at->second.symbol->getQualifier();
if (!qualifier.isUniform())
continue;
TType& t = at->second.symbol->getWritableType();
int size, stride;
TIntermediate::getBaseAlignment(t, size, stride, autoPushConstantBlockPacking,
qualifier.layoutMatrix == ElmRowMajor);
if (size <= int(autoPushConstantMaxSize)) {
qualifier.setBlockStorage(EbsPushConstant);
qualifier.layoutPacking = autoPushConstantBlockPacking;
// Push constants don't have set/binding etc. decorations, remove those.
qualifier.layoutSet = TQualifier::layoutSetEnd;
at->second.clearNewAssignments();
upgraded = true;
}
}
}
// If it's been upgraded to push_constant, then set the flag so when its traversed
// in the next for loop, all references to this symbol will get their flag changed.
// so it doesn't get a set/binding assigned to it.
if (upgraded) {
std::for_each(uniformVector.begin(), uniformVector.end(),
[this](TVarLivePair& p) {
if (p.first == autoPushConstantBlockName) {
p.second.upgradedToPushConstant = true;
}
});
}
}
for (size_t stage = 0; stage < EShLangCount; stage++) {
if (intermediates[stage] != nullptr) {
// traverse each stage, set new location to each input/output and unifom symbol, set new binding to
// ubo, ssbo and opaque symbols. Assign push_constant upgrades as well.
TVarLiveMap** pUniformVarMap = uniformResolve.uniformVarMap;
std::for_each(uniformVector.begin(), uniformVector.end(), [pUniformVarMap, stage](TVarLivePair p) {
auto at = pUniformVarMap[stage]->find(p.second.symbol->getAccessName());
if (at != pUniformVarMap[stage]->end() && at->second.id == p.second.id){
if (p.second.upgradedToPushConstant) {
at->second.upgradedToPushConstant = true;
} else {
int resolvedBinding = at->second.newBinding;
at->second = p.second;
if (resolvedBinding > 0)
at->second.newBinding = resolvedBinding;
}
}
});
TVarSetTraverser iter_iomap(*intermediates[stage], *inVarMaps[stage], *outVarMaps[stage],
*uniformResolve.uniformVarMap[stage]);
intermediates[stage]->getTreeRoot()->traverse(&iter_iomap);
}
}
return !hadError;
} else {
return false;
}
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/RemoveTree.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "../Include/intermediate.h"
#include "RemoveTree.h"
namespace glslang {
//
// Code to recursively delete the intermediate tree.
//
struct TRemoveTraverser : TIntermTraverser {
TRemoveTraverser() : TIntermTraverser(false, false, true, false) {}
virtual void visitSymbol(TIntermSymbol* node)
{
delete node;
}
virtual bool visitBinary(TVisit /* visit*/ , TIntermBinary* node)
{
delete node;
return true;
}
virtual bool visitUnary(TVisit /* visit */, TIntermUnary* node)
{
delete node;
return true;
}
virtual bool visitAggregate(TVisit /* visit*/ , TIntermAggregate* node)
{
delete node;
return true;
}
virtual bool visitSelection(TVisit /* visit*/ , TIntermSelection* node)
{
delete node;
return true;
}
virtual bool visitSwitch(TVisit /* visit*/ , TIntermSwitch* node)
{
delete node;
return true;
}
virtual void visitConstantUnion(TIntermConstantUnion* node)
{
delete node;
}
virtual bool visitLoop(TVisit /* visit*/ , TIntermLoop* node)
{
delete node;
return true;
}
virtual bool visitBranch(TVisit /* visit*/ , TIntermBranch* node)
{
delete node;
return true;
}
};
//
// Entry point.
//
void RemoveAllTreeNodes(TIntermNode* root)
{
TRemoveTraverser it;
root->traverse(&it);
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/attribute.h | //
// Copyright (C) 2017 LunarG, Inc.
// Copyright (C) 2018 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _ATTRIBUTE_INCLUDED_
#define _ATTRIBUTE_INCLUDED_
#include "../Include/Common.h"
#include "../Include/ConstantUnion.h"
namespace glslang {
enum TAttributeType {
EatNone,
EatAllow_uav_condition,
EatBranch,
EatCall,
EatDomain,
EatEarlyDepthStencil,
EatFastOpt,
EatFlatten,
EatForceCase,
EatInstance,
EatMaxTessFactor,
EatNumThreads,
EatMaxVertexCount,
EatOutputControlPoints,
EatOutputTopology,
EatPartitioning,
EatPatchConstantFunc,
EatPatchSize,
EatUnroll,
EatLoop,
EatBinding,
EatGlobalBinding,
EatLocation,
EatInputAttachment,
EatBuiltIn,
EatPushConstant,
EatConstantId,
EatDependencyInfinite,
EatDependencyLength,
EatMinIterations,
EatMaxIterations,
EatIterationMultiple,
EatPeelCount,
EatPartialCount,
EatFormatRgba32f,
EatFormatRgba16f,
EatFormatR32f,
EatFormatRgba8,
EatFormatRgba8Snorm,
EatFormatRg32f,
EatFormatRg16f,
EatFormatR11fG11fB10f,
EatFormatR16f,
EatFormatRgba16,
EatFormatRgb10A2,
EatFormatRg16,
EatFormatRg8,
EatFormatR16,
EatFormatR8,
EatFormatRgba16Snorm,
EatFormatRg16Snorm,
EatFormatRg8Snorm,
EatFormatR16Snorm,
EatFormatR8Snorm,
EatFormatRgba32i,
EatFormatRgba16i,
EatFormatRgba8i,
EatFormatR32i,
EatFormatRg32i,
EatFormatRg16i,
EatFormatRg8i,
EatFormatR16i,
EatFormatR8i,
EatFormatRgba32ui,
EatFormatRgba16ui,
EatFormatRgba8ui,
EatFormatR32ui,
EatFormatRgb10a2ui,
EatFormatRg32ui,
EatFormatRg16ui,
EatFormatRg8ui,
EatFormatR16ui,
EatFormatR8ui,
EatFormatUnknown,
EatNonWritable,
EatNonReadable,
EatSubgroupUniformControlFlow,
EatExport,
EatMaximallyReconverges,
};
class TIntermAggregate;
struct TAttributeArgs {
TAttributeType name;
const TIntermAggregate* args;
// Obtain attribute as integer
// Return false if it cannot be obtained
bool getInt(int& value, int argNum = 0) const;
// Obtain attribute as string, with optional to-lower transform
// Return false if it cannot be obtained
bool getString(TString& value, int argNum = 0, bool convertToLower = true) const;
// How many arguments were provided to the attribute?
int size() const;
protected:
const TConstUnion* getConstUnion(TBasicType basicType, int argNum) const;
};
typedef TList<TAttributeArgs> TAttributes;
} // end namespace glslang
#endif // _ATTRIBUTE_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/SymbolTable.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
// Copyright (C) 2015-2018 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _SYMBOL_TABLE_INCLUDED_
#define _SYMBOL_TABLE_INCLUDED_
//
// Symbol table for parsing. Has these design characteristics:
//
// * Same symbol table can be used to compile many shaders, to preserve
// effort of creating and loading with the large numbers of built-in
// symbols.
//
// --> This requires a copy mechanism, so initial pools used to create
// the shared information can be popped. Done through "clone"
// methods.
//
// * Name mangling will be used to give each function a unique name
// so that symbol table lookups are never ambiguous. This allows
// a simpler symbol table structure.
//
// * Pushing and popping of scope, so symbol table will really be a stack
// of symbol tables. Searched from the top, with new inserts going into
// the top.
//
// * Constants: Compile time constant symbols will keep their values
// in the symbol table. The parser can substitute constants at parse
// time, including doing constant folding and constant propagation.
//
// * No temporaries: Temporaries made from operations (+, --, .xy, etc.)
// are tracked in the intermediate representation, not the symbol table.
//
#include "../Include/Common.h"
#include "../Include/intermediate.h"
#include "../Include/InfoSink.h"
namespace glslang {
//
// Symbol base class. (Can build functions or variables out of these...)
//
class TVariable;
class TFunction;
class TAnonMember;
typedef TVector<const char*> TExtensionList;
class TSymbol {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
explicit TSymbol(const TString *n) : name(n), uniqueId(0), extensions(nullptr), writable(true) { }
virtual TSymbol* clone() const = 0;
virtual ~TSymbol() { } // rely on all symbol owned memory coming from the pool
virtual const TString& getName() const { return *name; }
virtual void changeName(const TString* newName) { name = newName; }
virtual void addPrefix(const char* prefix)
{
TString newName(prefix);
newName.append(*name);
changeName(NewPoolTString(newName.c_str()));
}
virtual const TString& getMangledName() const { return getName(); }
virtual TFunction* getAsFunction() { return nullptr; }
virtual const TFunction* getAsFunction() const { return nullptr; }
virtual TVariable* getAsVariable() { return nullptr; }
virtual const TVariable* getAsVariable() const { return nullptr; }
virtual const TAnonMember* getAsAnonMember() const { return nullptr; }
virtual const TType& getType() const = 0;
virtual TType& getWritableType() = 0;
virtual void setUniqueId(long long id) { uniqueId = id; }
virtual long long getUniqueId() const { return uniqueId; }
virtual void setExtensions(int numExts, const char* const exts[])
{
assert(extensions == nullptr);
assert(numExts > 0);
extensions = NewPoolObject(extensions);
for (int e = 0; e < numExts; ++e)
extensions->push_back(exts[e]);
}
virtual int getNumExtensions() const { return extensions == nullptr ? 0 : (int)extensions->size(); }
virtual const char** getExtensions() const { return extensions->data(); }
virtual void dump(TInfoSink& infoSink, bool complete = false) const = 0;
void dumpExtensions(TInfoSink& infoSink) const;
virtual bool isReadOnly() const { return ! writable; }
virtual void makeReadOnly() { writable = false; }
protected:
explicit TSymbol(const TSymbol&);
TSymbol& operator=(const TSymbol&);
const TString *name;
unsigned long long uniqueId; // For cross-scope comparing during code generation
// For tracking what extensions must be present
// (don't use if correct version/profile is present).
TExtensionList* extensions; // an array of pointers to existing constant char strings
//
// N.B.: Non-const functions that will be generally used should assert on this,
// to avoid overwriting shared symbol-table information.
//
bool writable;
};
//
// Variable class, meaning a symbol that's not a function.
//
// There could be a separate class hierarchy for Constant variables;
// Only one of int, bool, or float, (or none) is correct for
// any particular use, but it's easy to do this way, and doesn't
// seem worth having separate classes, and "getConst" can't simply return
// different values for different types polymorphically, so this is
// just simple and pragmatic.
//
class TVariable : public TSymbol {
public:
TVariable(const TString *name, const TType& t, bool uT = false )
: TSymbol(name),
userType(uT),
constSubtree(nullptr),
memberExtensions(nullptr),
anonId(-1)
{ type.shallowCopy(t); }
virtual TVariable* clone() const;
virtual ~TVariable() { }
virtual TVariable* getAsVariable() { return this; }
virtual const TVariable* getAsVariable() const { return this; }
virtual const TType& getType() const { return type; }
virtual TType& getWritableType() { assert(writable); return type; }
virtual bool isUserType() const { return userType; }
virtual const TConstUnionArray& getConstArray() const { return constArray; }
virtual TConstUnionArray& getWritableConstArray() { assert(writable); return constArray; }
virtual void setConstArray(const TConstUnionArray& array) { constArray = array; }
virtual void setConstSubtree(TIntermTyped* subtree) { constSubtree = subtree; }
virtual TIntermTyped* getConstSubtree() const { return constSubtree; }
virtual void setAnonId(int i) { anonId = i; }
virtual int getAnonId() const { return anonId; }
virtual void setMemberExtensions(int member, int numExts, const char* const exts[])
{
assert(type.isStruct());
assert(numExts > 0);
if (memberExtensions == nullptr) {
memberExtensions = NewPoolObject(memberExtensions);
memberExtensions->resize(type.getStruct()->size());
}
for (int e = 0; e < numExts; ++e)
(*memberExtensions)[member].push_back(exts[e]);
}
virtual bool hasMemberExtensions() const { return memberExtensions != nullptr; }
virtual int getNumMemberExtensions(int member) const
{
return memberExtensions == nullptr ? 0 : (int)(*memberExtensions)[member].size();
}
virtual const char** getMemberExtensions(int member) const { return (*memberExtensions)[member].data(); }
virtual void dump(TInfoSink& infoSink, bool complete = false) const;
protected:
explicit TVariable(const TVariable&);
TVariable& operator=(const TVariable&);
TType type;
bool userType;
// we are assuming that Pool Allocator will free the memory allocated to unionArray
// when this object is destroyed
TConstUnionArray constArray; // for compile-time constant value
TIntermTyped* constSubtree; // for specialization constant computation
TVector<TExtensionList>* memberExtensions; // per-member extension list, allocated only when needed
int anonId; // the ID used for anonymous blocks: TODO: see if uniqueId could serve a dual purpose
};
//
// The function sub-class of symbols and the parser will need to
// share this definition of a function parameter.
//
struct TParameter {
TString *name;
TType* type;
TIntermTyped* defaultValue;
TParameter& copyParam(const TParameter& param)
{
if (param.name)
name = NewPoolTString(param.name->c_str());
else
name = nullptr;
type = param.type->clone();
defaultValue = param.defaultValue;
return *this;
}
TBuiltInVariable getDeclaredBuiltIn() const { return type->getQualifier().declaredBuiltIn; }
};
//
// The function sub-class of a symbol.
//
class TFunction : public TSymbol {
public:
explicit TFunction(TOperator o) :
TSymbol(nullptr),
op(o),
defined(false), prototyped(false), implicitThis(false), illegalImplicitThis(false), defaultParamCount(0) { }
TFunction(const TString *name, const TType& retType, TOperator tOp = EOpNull) :
TSymbol(name),
mangledName(*name + '('),
op(tOp),
defined(false), prototyped(false), implicitThis(false), illegalImplicitThis(false), defaultParamCount(0),
linkType(ELinkNone)
{
returnType.shallowCopy(retType);
declaredBuiltIn = retType.getQualifier().builtIn;
}
virtual TFunction* clone() const override;
virtual ~TFunction();
virtual TFunction* getAsFunction() override { return this; }
virtual const TFunction* getAsFunction() const override { return this; }
// Install 'p' as the (non-'this') last parameter.
// Non-'this' parameters are reflected in both the list of parameters and the
// mangled name.
virtual void addParameter(TParameter& p)
{
assert(writable);
parameters.push_back(p);
p.type->appendMangledName(mangledName);
if (p.defaultValue != nullptr)
defaultParamCount++;
}
// Install 'this' as the first parameter.
// 'this' is reflected in the list of parameters, but not the mangled name.
virtual void addThisParameter(TType& type, const char* name)
{
TParameter p = { NewPoolTString(name), new TType, nullptr };
p.type->shallowCopy(type);
parameters.insert(parameters.begin(), p);
}
virtual void addPrefix(const char* prefix) override
{
TSymbol::addPrefix(prefix);
mangledName.insert(0, prefix);
}
virtual void removePrefix(const TString& prefix)
{
assert(mangledName.compare(0, prefix.size(), prefix) == 0);
mangledName.erase(0, prefix.size());
}
virtual const TString& getMangledName() const override { return mangledName; }
virtual const TType& getType() const override { return returnType; }
virtual TBuiltInVariable getDeclaredBuiltInType() const { return declaredBuiltIn; }
virtual TType& getWritableType() override { return returnType; }
virtual void relateToOperator(TOperator o) { assert(writable); op = o; }
virtual TOperator getBuiltInOp() const { return op; }
virtual void setDefined() { assert(writable); defined = true; }
virtual bool isDefined() const { return defined; }
virtual void setPrototyped() { assert(writable); prototyped = true; }
virtual bool isPrototyped() const { return prototyped; }
virtual void setImplicitThis() { assert(writable); implicitThis = true; }
virtual bool hasImplicitThis() const { return implicitThis; }
virtual void setIllegalImplicitThis() { assert(writable); illegalImplicitThis = true; }
virtual bool hasIllegalImplicitThis() const { return illegalImplicitThis; }
// Return total number of parameters
virtual int getParamCount() const { return static_cast<int>(parameters.size()); }
// Return number of parameters with default values.
virtual int getDefaultParamCount() const { return defaultParamCount; }
// Return number of fixed parameters (without default values)
virtual int getFixedParamCount() const { return getParamCount() - getDefaultParamCount(); }
virtual TParameter& operator[](int i) { assert(writable); return parameters[i]; }
virtual const TParameter& operator[](int i) const { return parameters[i]; }
const TQualifier& getQualifier() const { return returnType.getQualifier(); }
virtual void setSpirvInstruction(const TSpirvInstruction& inst)
{
relateToOperator(EOpSpirvInst);
spirvInst = inst;
}
virtual const TSpirvInstruction& getSpirvInstruction() const { return spirvInst; }
virtual void dump(TInfoSink& infoSink, bool complete = false) const override;
void setExport() { linkType = ELinkExport; }
TLinkType getLinkType() const { return linkType; }
protected:
explicit TFunction(const TFunction&);
TFunction& operator=(const TFunction&);
typedef TVector<TParameter> TParamList;
TParamList parameters;
TType returnType;
TBuiltInVariable declaredBuiltIn;
TString mangledName;
TOperator op;
bool defined;
bool prototyped;
bool implicitThis; // True if this function is allowed to see all members of 'this'
bool illegalImplicitThis; // True if this function is not supposed to have access to dynamic members of 'this',
// even if it finds member variables in the symbol table.
// This is important for a static member function that has member variables in scope,
// but is not allowed to use them, or see hidden symbols instead.
int defaultParamCount;
TSpirvInstruction spirvInst; // SPIR-V instruction qualifiers
TLinkType linkType;
};
//
// Members of anonymous blocks are a kind of TSymbol. They are not hidden in
// the symbol table behind a container; rather they are visible and point to
// their anonymous container. (The anonymous container is found through the
// member, not the other way around.)
//
class TAnonMember : public TSymbol {
public:
TAnonMember(const TString* n, unsigned int m, TVariable& a, int an) : TSymbol(n), anonContainer(a), memberNumber(m), anonId(an) { }
virtual TAnonMember* clone() const override;
virtual ~TAnonMember() { }
virtual const TAnonMember* getAsAnonMember() const override { return this; }
virtual const TVariable& getAnonContainer() const { return anonContainer; }
virtual unsigned int getMemberNumber() const { return memberNumber; }
virtual const TType& getType() const override
{
const TTypeList& types = *anonContainer.getType().getStruct();
return *types[memberNumber].type;
}
virtual TType& getWritableType() override
{
assert(writable);
const TTypeList& types = *anonContainer.getType().getStruct();
return *types[memberNumber].type;
}
virtual void setExtensions(int numExts, const char* const exts[]) override
{
anonContainer.setMemberExtensions(memberNumber, numExts, exts);
}
virtual int getNumExtensions() const override { return anonContainer.getNumMemberExtensions(memberNumber); }
virtual const char** getExtensions() const override { return anonContainer.getMemberExtensions(memberNumber); }
virtual int getAnonId() const { return anonId; }
virtual void dump(TInfoSink& infoSink, bool complete = false) const override;
protected:
explicit TAnonMember(const TAnonMember&);
TAnonMember& operator=(const TAnonMember&);
TVariable& anonContainer;
unsigned int memberNumber;
int anonId;
};
class TSymbolTableLevel {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TSymbolTableLevel() : defaultPrecision(nullptr), anonId(0), thisLevel(false) { }
~TSymbolTableLevel();
bool insert(const TString& name, TSymbol* symbol) {
return level.insert(tLevelPair(name, symbol)).second;
}
bool insert(TSymbol& symbol, bool separateNameSpaces, const TString& forcedKeyName = TString())
{
//
// returning true means symbol was added to the table with no semantic errors
//
const TString& name = symbol.getName();
if (forcedKeyName.length()) {
return level.insert(tLevelPair(forcedKeyName, &symbol)).second;
}
else if (name == "") {
symbol.getAsVariable()->setAnonId(anonId++);
// An empty name means an anonymous container, exposing its members to the external scope.
// Give it a name and insert its members in the symbol table, pointing to the container.
char buf[20];
snprintf(buf, 20, "%s%d", AnonymousPrefix, symbol.getAsVariable()->getAnonId());
symbol.changeName(NewPoolTString(buf));
return insertAnonymousMembers(symbol, 0);
} else {
// Check for redefinition errors:
// - STL itself will tell us if there is a direct name collision, with name mangling, at this level
// - additionally, check for function-redefining-variable name collisions
const TString& insertName = symbol.getMangledName();
if (symbol.getAsFunction()) {
// make sure there isn't a variable of this name
if (! separateNameSpaces && level.find(name) != level.end())
return false;
// insert, and whatever happens is okay
level.insert(tLevelPair(insertName, &symbol));
return true;
} else
return level.insert(tLevelPair(insertName, &symbol)).second;
}
}
// Add more members to an already inserted aggregate object
bool amend(TSymbol& symbol, int firstNewMember)
{
// See insert() for comments on basic explanation of insert.
// This operates similarly, but more simply.
// Only supporting amend of anonymous blocks so far.
if (IsAnonymous(symbol.getName()))
return insertAnonymousMembers(symbol, firstNewMember);
else
return false;
}
bool insertAnonymousMembers(TSymbol& symbol, int firstMember)
{
const TTypeList& types = *symbol.getAsVariable()->getType().getStruct();
for (unsigned int m = firstMember; m < types.size(); ++m) {
TAnonMember* member = new TAnonMember(&types[m].type->getFieldName(), m, *symbol.getAsVariable(), symbol.getAsVariable()->getAnonId());
if (! level.insert(tLevelPair(member->getMangledName(), member)).second)
return false;
}
return true;
}
void retargetSymbol(const TString& from, const TString& to) {
tLevel::const_iterator fromIt = level.find(from);
tLevel::const_iterator toIt = level.find(to);
if (fromIt == level.end() || toIt == level.end())
return;
delete fromIt->second;
level[from] = toIt->second;
retargetedSymbols.push_back({from, to});
}
TSymbol* find(const TString& name) const
{
tLevel::const_iterator it = level.find(name);
if (it == level.end())
return nullptr;
else
return (*it).second;
}
void findFunctionNameList(const TString& name, TVector<const TFunction*>& list)
{
size_t parenAt = name.find_first_of('(');
TString base(name, 0, parenAt + 1);
tLevel::const_iterator begin = level.lower_bound(base);
base[parenAt] = ')'; // assume ')' is lexically after '('
tLevel::const_iterator end = level.upper_bound(base);
for (tLevel::const_iterator it = begin; it != end; ++it)
list.push_back(it->second->getAsFunction());
}
// See if there is already a function in the table having the given non-function-style name.
bool hasFunctionName(const TString& name) const
{
tLevel::const_iterator candidate = level.lower_bound(name);
if (candidate != level.end()) {
const TString& candidateName = (*candidate).first;
TString::size_type parenAt = candidateName.find_first_of('(');
if (parenAt != candidateName.npos && candidateName.compare(0, parenAt, name) == 0)
return true;
}
return false;
}
// See if there is a variable at this level having the given non-function-style name.
// Return true if name is found, and set variable to true if the name was a variable.
bool findFunctionVariableName(const TString& name, bool& variable) const
{
tLevel::const_iterator candidate = level.lower_bound(name);
if (candidate != level.end()) {
const TString& candidateName = (*candidate).first;
TString::size_type parenAt = candidateName.find_first_of('(');
if (parenAt == candidateName.npos) {
// not a mangled name
if (candidateName == name) {
// found a variable name match
variable = true;
return true;
}
} else {
// a mangled name
if (candidateName.compare(0, parenAt, name) == 0) {
// found a function name match
variable = false;
return true;
}
}
}
return false;
}
// Use this to do a lazy 'push' of precision defaults the first time
// a precision statement is seen in a new scope. Leave it at 0 for
// when no push was needed. Thus, it is not the current defaults,
// it is what to restore the defaults to when popping a level.
void setPreviousDefaultPrecisions(const TPrecisionQualifier *p)
{
// can call multiple times at one scope, will only latch on first call,
// as we're tracking the previous scope's values, not the current values
if (defaultPrecision != nullptr)
return;
defaultPrecision = new TPrecisionQualifier[EbtNumTypes];
for (int t = 0; t < EbtNumTypes; ++t)
defaultPrecision[t] = p[t];
}
void getPreviousDefaultPrecisions(TPrecisionQualifier *p)
{
// can be called for table level pops that didn't set the
// defaults
if (defaultPrecision == nullptr || p == nullptr)
return;
for (int t = 0; t < EbtNumTypes; ++t)
p[t] = defaultPrecision[t];
}
void relateToOperator(const char* name, TOperator op);
void setFunctionExtensions(const char* name, int num, const char* const extensions[]);
void setSingleFunctionExtensions(const char* name, int num, const char* const extensions[]);
void dump(TInfoSink& infoSink, bool complete = false) const;
TSymbolTableLevel* clone() const;
void readOnly();
void setThisLevel() { thisLevel = true; }
bool isThisLevel() const { return thisLevel; }
protected:
explicit TSymbolTableLevel(TSymbolTableLevel&);
TSymbolTableLevel& operator=(TSymbolTableLevel&);
typedef std::map<TString, TSymbol*, std::less<TString>, pool_allocator<std::pair<const TString, TSymbol*> > > tLevel;
typedef const tLevel::value_type tLevelPair;
typedef std::pair<tLevel::iterator, bool> tInsertResult;
tLevel level; // named mappings
TPrecisionQualifier *defaultPrecision;
// pair<FromName, ToName>
TVector<std::pair<TString, TString>> retargetedSymbols;
int anonId;
bool thisLevel; // True if this level of the symbol table is a structure scope containing member function
// that are supposed to see anonymous access to member variables.
};
class TSymbolTable {
public:
TSymbolTable() : uniqueId(0), noBuiltInRedeclarations(false), separateNameSpaces(false), adoptedLevels(0)
{
//
// This symbol table cannot be used until push() is called.
//
}
~TSymbolTable()
{
// this can be called explicitly; safest to code it so it can be called multiple times
// don't deallocate levels passed in from elsewhere
while (table.size() > adoptedLevels)
pop(nullptr);
}
void adoptLevels(TSymbolTable& symTable)
{
for (unsigned int level = 0; level < symTable.table.size(); ++level) {
table.push_back(symTable.table[level]);
++adoptedLevels;
}
uniqueId = symTable.uniqueId;
noBuiltInRedeclarations = symTable.noBuiltInRedeclarations;
separateNameSpaces = symTable.separateNameSpaces;
}
//
// While level adopting is generic, the methods below enact a the following
// convention for levels:
// 0: common built-ins shared across all stages, all compiles, only one copy for all symbol tables
// 1: per-stage built-ins, shared across all compiles, but a different copy per stage
// 2: built-ins specific to a compile, like resources that are context-dependent, or redeclared built-ins
// 3: user-shader globals
//
protected:
static const uint32_t LevelFlagBitOffset = 56;
static const int globalLevel = 3;
static bool isSharedLevel(int level) { return level <= 1; } // exclude all per-compile levels
static bool isBuiltInLevel(int level) { return level <= 2; } // exclude user globals
static bool isGlobalLevel(int level) { return level <= globalLevel; } // include user globals
public:
bool isEmpty() { return table.size() == 0; }
bool atBuiltInLevel() { return isBuiltInLevel(currentLevel()); }
bool atGlobalLevel() { return isGlobalLevel(currentLevel()); }
static bool isBuiltInSymbol(long long uniqueId) {
int level = static_cast<int>(uniqueId >> LevelFlagBitOffset);
return isBuiltInLevel(level);
}
static constexpr uint64_t uniqueIdMask = (1LL << LevelFlagBitOffset) - 1;
static const uint32_t MaxLevelInUniqueID = 127;
void setNoBuiltInRedeclarations() { noBuiltInRedeclarations = true; }
void setSeparateNameSpaces() { separateNameSpaces = true; }
void push()
{
table.push_back(new TSymbolTableLevel);
updateUniqueIdLevelFlag();
}
// Make a new symbol-table level to represent the scope introduced by a structure
// containing member functions, such that the member functions can find anonymous
// references to member variables.
//
// 'thisSymbol' should have a name of "" to trigger anonymous structure-member
// symbol finds.
void pushThis(TSymbol& thisSymbol)
{
assert(thisSymbol.getName().size() == 0);
table.push_back(new TSymbolTableLevel);
updateUniqueIdLevelFlag();
table.back()->setThisLevel();
insert(thisSymbol);
}
void pop(TPrecisionQualifier *p)
{
table[currentLevel()]->getPreviousDefaultPrecisions(p);
delete table.back();
table.pop_back();
updateUniqueIdLevelFlag();
}
//
// Insert a visible symbol into the symbol table so it can
// be found later by name.
//
// Returns false if the was a name collision.
//
bool insert(TSymbol& symbol)
{
symbol.setUniqueId(++uniqueId);
// make sure there isn't a function of this variable name
if (! separateNameSpaces && ! symbol.getAsFunction() && table[currentLevel()]->hasFunctionName(symbol.getName()))
return false;
// check for not overloading or redefining a built-in function
if (noBuiltInRedeclarations) {
if (atGlobalLevel() && currentLevel() > 0) {
if (table[0]->hasFunctionName(symbol.getName()))
return false;
if (currentLevel() > 1 && table[1]->hasFunctionName(symbol.getName()))
return false;
}
}
return table[currentLevel()]->insert(symbol, separateNameSpaces);
}
// Add more members to an already inserted aggregate object
bool amend(TSymbol& symbol, int firstNewMember)
{
// See insert() for comments on basic explanation of insert.
// This operates similarly, but more simply.
return table[currentLevel()]->amend(symbol, firstNewMember);
}
// Update the level info in symbol's unique ID to current level
void amendSymbolIdLevel(TSymbol& symbol)
{
// clamp level to avoid overflow
uint64_t level = (uint32_t)currentLevel() > MaxLevelInUniqueID ? MaxLevelInUniqueID : currentLevel();
uint64_t symbolId = symbol.getUniqueId();
symbolId &= uniqueIdMask;
symbolId |= (level << LevelFlagBitOffset);
symbol.setUniqueId(symbolId);
}
//
// To allocate an internal temporary, which will need to be uniquely
// identified by the consumer of the AST, but never need to
// found by doing a symbol table search by name, hence allowed an
// arbitrary name in the symbol with no worry of collision.
//
void makeInternalVariable(TSymbol& symbol)
{
symbol.setUniqueId(++uniqueId);
}
//
// Copy a variable or anonymous member's structure from a shared level so that
// it can be added (soon after return) to the symbol table where it can be
// modified without impacting other users of the shared table.
//
TSymbol* copyUpDeferredInsert(TSymbol* shared)
{
if (shared->getAsVariable()) {
TSymbol* copy = shared->clone();
copy->setUniqueId(shared->getUniqueId());
return copy;
} else {
const TAnonMember* anon = shared->getAsAnonMember();
assert(anon);
TVariable* container = anon->getAnonContainer().clone();
container->changeName(NewPoolTString(""));
container->setUniqueId(anon->getAnonContainer().getUniqueId());
return container;
}
}
TSymbol* copyUp(TSymbol* shared)
{
TSymbol* copy = copyUpDeferredInsert(shared);
table[globalLevel]->insert(*copy, separateNameSpaces);
if (shared->getAsVariable())
return copy;
else {
// return the copy of the anonymous member
return table[globalLevel]->find(shared->getName());
}
}
// Normal find of a symbol, that can optionally say whether the symbol was found
// at a built-in level or the current top-scope level.
TSymbol* find(const TString& name, bool* builtIn = nullptr, bool* currentScope = nullptr, int* thisDepthP = nullptr)
{
int level = currentLevel();
TSymbol* symbol;
int thisDepth = 0;
do {
if (table[level]->isThisLevel())
++thisDepth;
symbol = table[level]->find(name);
--level;
} while (symbol == nullptr && level >= 0);
level++;
if (builtIn)
*builtIn = isBuiltInLevel(level);
if (currentScope)
*currentScope = isGlobalLevel(currentLevel()) || level == currentLevel(); // consider shared levels as "current scope" WRT user globals
if (thisDepthP != nullptr) {
if (! table[level]->isThisLevel())
thisDepth = 0;
*thisDepthP = thisDepth;
}
return symbol;
}
void retargetSymbol(const TString& from, const TString& to) {
int level = currentLevel();
table[level]->retargetSymbol(from, to);
}
// Find of a symbol that returns how many layers deep of nested
// structures-with-member-functions ('this' scopes) deep the symbol was
// found in.
TSymbol* find(const TString& name, int& thisDepth)
{
int level = currentLevel();
TSymbol* symbol;
thisDepth = 0;
do {
if (table[level]->isThisLevel())
++thisDepth;
symbol = table[level]->find(name);
--level;
} while (symbol == nullptr && level >= 0);
if (! table[level + 1]->isThisLevel())
thisDepth = 0;
return symbol;
}
bool isFunctionNameVariable(const TString& name) const
{
if (separateNameSpaces)
return false;
int level = currentLevel();
do {
bool variable;
bool found = table[level]->findFunctionVariableName(name, variable);
if (found)
return variable;
--level;
} while (level >= 0);
return false;
}
void findFunctionNameList(const TString& name, TVector<const TFunction*>& list, bool& builtIn)
{
// For user levels, return the set found in the first scope with a match
builtIn = false;
int level = currentLevel();
do {
table[level]->findFunctionNameList(name, list);
--level;
} while (list.empty() && level >= globalLevel);
if (! list.empty())
return;
// Gather across all built-in levels; they don't hide each other
builtIn = true;
do {
table[level]->findFunctionNameList(name, list);
--level;
} while (level >= 0);
}
void relateToOperator(const char* name, TOperator op)
{
for (unsigned int level = 0; level < table.size(); ++level)
table[level]->relateToOperator(name, op);
}
void setFunctionExtensions(const char* name, int num, const char* const extensions[])
{
for (unsigned int level = 0; level < table.size(); ++level)
table[level]->setFunctionExtensions(name, num, extensions);
}
void setSingleFunctionExtensions(const char* name, int num, const char* const extensions[])
{
for (unsigned int level = 0; level < table.size(); ++level)
table[level]->setSingleFunctionExtensions(name, num, extensions);
}
void setVariableExtensions(const char* name, int numExts, const char* const extensions[])
{
TSymbol* symbol = find(TString(name));
if (symbol == nullptr)
return;
symbol->setExtensions(numExts, extensions);
}
void setVariableExtensions(const char* blockName, const char* name, int numExts, const char* const extensions[])
{
TSymbol* symbol = find(TString(blockName));
if (symbol == nullptr)
return;
TVariable* variable = symbol->getAsVariable();
assert(variable != nullptr);
const TTypeList& structure = *variable->getAsVariable()->getType().getStruct();
for (int member = 0; member < (int)structure.size(); ++member) {
if (structure[member].type->getFieldName().compare(name) == 0) {
variable->setMemberExtensions(member, numExts, extensions);
return;
}
}
}
long long getMaxSymbolId() { return uniqueId; }
void dump(TInfoSink& infoSink, bool complete = false) const;
void copyTable(const TSymbolTable& copyOf);
void setPreviousDefaultPrecisions(TPrecisionQualifier *p) { table[currentLevel()]->setPreviousDefaultPrecisions(p); }
void readOnly()
{
for (unsigned int level = 0; level < table.size(); ++level)
table[level]->readOnly();
}
// Add current level in the high-bits of unique id
void updateUniqueIdLevelFlag() {
// clamp level to avoid overflow
uint64_t level = (uint32_t)currentLevel() > MaxLevelInUniqueID ? MaxLevelInUniqueID : currentLevel();
uniqueId &= uniqueIdMask;
uniqueId |= (level << LevelFlagBitOffset);
}
void overwriteUniqueId(long long id)
{
uniqueId = id;
updateUniqueIdLevelFlag();
}
protected:
TSymbolTable(TSymbolTable&);
TSymbolTable& operator=(TSymbolTableLevel&);
int currentLevel() const { return static_cast<int>(table.size()) - 1; }
std::vector<TSymbolTableLevel*> table;
long long uniqueId; // for unique identification in code generation
bool noBuiltInRedeclarations;
bool separateNameSpaces;
unsigned int adoptedLevels;
};
} // end namespace glslang
#endif // _SYMBOL_TABLE_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/RemoveTree.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#pragma once
namespace glslang {
void RemoveAllTreeNodes(TIntermNode*);
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/Versions.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
// Copyright (C) 2017, 2022-2024 Arm Limited.
// Copyright (C) 2015-2018 Google, Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _VERSIONS_INCLUDED_
#define _VERSIONS_INCLUDED_
#define LAST_ELEMENT_MARKER(x) x
//
// Help manage multiple profiles, versions, extensions etc.
//
//
// Profiles are set up for masking operations, so queries can be done on multiple
// profiles at the same time.
//
// Don't maintain an ordinal set of enums (0,1,2,3...) to avoid all possible
// defects from mixing the two different forms.
//
typedef enum : unsigned {
EBadProfile = 0,
ENoProfile = (1 << 0), // only for desktop, before profiles showed up
ECoreProfile = (1 << 1),
ECompatibilityProfile = (1 << 2),
EEsProfile = (1 << 3),
LAST_ELEMENT_MARKER(EProfileCount),
} EProfile;
namespace glslang {
//
// Map from profile enum to externally readable text name.
//
inline const char* ProfileName(EProfile profile)
{
switch (profile) {
case ENoProfile: return "none";
case ECoreProfile: return "core";
case ECompatibilityProfile: return "compatibility";
case EEsProfile: return "es";
default: return "unknown profile";
}
}
//
// What source rules, validation rules, target language, etc. are needed or
// desired for SPIR-V?
//
// 0 means a target or rule set is not enabled (ignore rules from that entity).
// Non-0 means to apply semantic rules arising from that version of its rule set.
// The union of all requested rule sets will be applied.
//
struct SpvVersion {
SpvVersion() : spv(0), vulkanGlsl(0), vulkan(0), openGl(0), vulkanRelaxed(false) {}
unsigned int spv; // the version of SPIR-V to target, as defined by "word 1" of the SPIR-V binary header
int vulkanGlsl; // the version of GLSL semantics for Vulkan, from GL_KHR_vulkan_glsl, for "#define VULKAN XXX"
int vulkan; // the version of Vulkan, for which SPIR-V execution environment rules to use
int openGl; // the version of GLSL semantics for OpenGL, from GL_ARB_gl_spirv, for "#define GL_SPIRV XXX"
bool vulkanRelaxed; // relax changes to GLSL for Vulkan, allowing some GL-specific to be compiled to Vulkan SPIR-V target
};
//
// The behaviors from the GLSL "#extension extension_name : behavior"
//
typedef enum {
EBhMissing = 0,
EBhRequire,
EBhEnable,
EBhWarn,
EBhDisable,
EBhDisablePartial // use as initial state of an extension that is only partially implemented
} TExtensionBehavior;
//
// Symbolic names for extensions. Strings may be directly used when calling the
// functions, but better to have the compiler do spelling checks.
//
const char* const E_GL_OES_texture_3D = "GL_OES_texture_3D";
const char* const E_GL_OES_standard_derivatives = "GL_OES_standard_derivatives";
const char* const E_GL_EXT_frag_depth = "GL_EXT_frag_depth";
const char* const E_GL_OES_EGL_image_external = "GL_OES_EGL_image_external";
const char* const E_GL_OES_EGL_image_external_essl3 = "GL_OES_EGL_image_external_essl3";
const char* const E_GL_EXT_YUV_target = "GL_EXT_YUV_target";
const char* const E_GL_EXT_shader_texture_lod = "GL_EXT_shader_texture_lod";
const char* const E_GL_EXT_shadow_samplers = "GL_EXT_shadow_samplers";
const char* const E_GL_ARB_texture_rectangle = "GL_ARB_texture_rectangle";
const char* const E_GL_3DL_array_objects = "GL_3DL_array_objects";
const char* const E_GL_ARB_shading_language_420pack = "GL_ARB_shading_language_420pack";
const char* const E_GL_ARB_texture_gather = "GL_ARB_texture_gather";
const char* const E_GL_ARB_gpu_shader5 = "GL_ARB_gpu_shader5";
const char* const E_GL_ARB_separate_shader_objects = "GL_ARB_separate_shader_objects";
const char* const E_GL_ARB_compute_shader = "GL_ARB_compute_shader";
const char* const E_GL_ARB_tessellation_shader = "GL_ARB_tessellation_shader";
const char* const E_GL_ARB_enhanced_layouts = "GL_ARB_enhanced_layouts";
const char* const E_GL_ARB_texture_cube_map_array = "GL_ARB_texture_cube_map_array";
const char* const E_GL_ARB_texture_multisample = "GL_ARB_texture_multisample";
const char* const E_GL_ARB_shader_texture_lod = "GL_ARB_shader_texture_lod";
const char* const E_GL_ARB_explicit_attrib_location = "GL_ARB_explicit_attrib_location";
const char* const E_GL_ARB_explicit_uniform_location = "GL_ARB_explicit_uniform_location";
const char* const E_GL_ARB_shader_image_load_store = "GL_ARB_shader_image_load_store";
const char* const E_GL_ARB_shader_atomic_counters = "GL_ARB_shader_atomic_counters";
const char* const E_GL_ARB_shader_atomic_counter_ops = "GL_ARB_shader_atomic_counter_ops";
const char* const E_GL_ARB_shader_draw_parameters = "GL_ARB_shader_draw_parameters";
const char* const E_GL_ARB_shader_group_vote = "GL_ARB_shader_group_vote";
const char* const E_GL_ARB_derivative_control = "GL_ARB_derivative_control";
const char* const E_GL_ARB_shader_texture_image_samples = "GL_ARB_shader_texture_image_samples";
const char* const E_GL_ARB_viewport_array = "GL_ARB_viewport_array";
const char* const E_GL_ARB_gpu_shader_int64 = "GL_ARB_gpu_shader_int64";
const char* const E_GL_ARB_gpu_shader_fp64 = "GL_ARB_gpu_shader_fp64";
const char* const E_GL_ARB_shader_ballot = "GL_ARB_shader_ballot";
const char* const E_GL_ARB_sparse_texture2 = "GL_ARB_sparse_texture2";
const char* const E_GL_ARB_sparse_texture_clamp = "GL_ARB_sparse_texture_clamp";
const char* const E_GL_ARB_shader_stencil_export = "GL_ARB_shader_stencil_export";
// const char* const E_GL_ARB_cull_distance = "GL_ARB_cull_distance"; // present for 4.5, but need extension control over block members
const char* const E_GL_ARB_post_depth_coverage = "GL_ARB_post_depth_coverage";
const char* const E_GL_ARB_shader_viewport_layer_array = "GL_ARB_shader_viewport_layer_array";
const char* const E_GL_ARB_fragment_shader_interlock = "GL_ARB_fragment_shader_interlock";
const char* const E_GL_ARB_shader_clock = "GL_ARB_shader_clock";
const char* const E_GL_ARB_uniform_buffer_object = "GL_ARB_uniform_buffer_object";
const char* const E_GL_ARB_sample_shading = "GL_ARB_sample_shading";
const char* const E_GL_ARB_shader_bit_encoding = "GL_ARB_shader_bit_encoding";
const char* const E_GL_ARB_shader_image_size = "GL_ARB_shader_image_size";
const char* const E_GL_ARB_shader_storage_buffer_object = "GL_ARB_shader_storage_buffer_object";
const char* const E_GL_ARB_shading_language_packing = "GL_ARB_shading_language_packing";
const char* const E_GL_ARB_texture_query_lod = "GL_ARB_texture_query_lod";
const char* const E_GL_ARB_vertex_attrib_64bit = "GL_ARB_vertex_attrib_64bit";
const char* const E_GL_ARB_draw_instanced = "GL_ARB_draw_instanced";
const char* const E_GL_ARB_fragment_coord_conventions = "GL_ARB_fragment_coord_conventions";
const char* const E_GL_ARB_bindless_texture = "GL_ARB_bindless_texture";
const char* const E_GL_KHR_shader_subgroup_basic = "GL_KHR_shader_subgroup_basic";
const char* const E_GL_KHR_shader_subgroup_vote = "GL_KHR_shader_subgroup_vote";
const char* const E_GL_KHR_shader_subgroup_arithmetic = "GL_KHR_shader_subgroup_arithmetic";
const char* const E_GL_KHR_shader_subgroup_ballot = "GL_KHR_shader_subgroup_ballot";
const char* const E_GL_KHR_shader_subgroup_shuffle = "GL_KHR_shader_subgroup_shuffle";
const char* const E_GL_KHR_shader_subgroup_shuffle_relative = "GL_KHR_shader_subgroup_shuffle_relative";
const char* const E_GL_KHR_shader_subgroup_rotate = "GL_KHR_shader_subgroup_rotate";
const char* const E_GL_KHR_shader_subgroup_clustered = "GL_KHR_shader_subgroup_clustered";
const char* const E_GL_KHR_shader_subgroup_quad = "GL_KHR_shader_subgroup_quad";
const char* const E_GL_KHR_memory_scope_semantics = "GL_KHR_memory_scope_semantics";
const char* const E_GL_KHR_cooperative_matrix = "GL_KHR_cooperative_matrix";
const char* const E_GL_EXT_shader_atomic_int64 = "GL_EXT_shader_atomic_int64";
const char* const E_GL_EXT_shader_non_constant_global_initializers = "GL_EXT_shader_non_constant_global_initializers";
const char* const E_GL_EXT_shader_image_load_formatted = "GL_EXT_shader_image_load_formatted";
const char* const E_GL_EXT_shader_16bit_storage = "GL_EXT_shader_16bit_storage";
const char* const E_GL_EXT_shader_8bit_storage = "GL_EXT_shader_8bit_storage";
// EXT extensions
const char* const E_GL_EXT_device_group = "GL_EXT_device_group";
const char* const E_GL_EXT_multiview = "GL_EXT_multiview";
const char* const E_GL_EXT_post_depth_coverage = "GL_EXT_post_depth_coverage";
const char* const E_GL_EXT_control_flow_attributes = "GL_EXT_control_flow_attributes";
const char* const E_GL_EXT_nonuniform_qualifier = "GL_EXT_nonuniform_qualifier";
const char* const E_GL_EXT_samplerless_texture_functions = "GL_EXT_samplerless_texture_functions";
const char* const E_GL_EXT_scalar_block_layout = "GL_EXT_scalar_block_layout";
const char* const E_GL_EXT_fragment_invocation_density = "GL_EXT_fragment_invocation_density";
const char* const E_GL_EXT_buffer_reference = "GL_EXT_buffer_reference";
const char* const E_GL_EXT_buffer_reference2 = "GL_EXT_buffer_reference2";
const char* const E_GL_EXT_buffer_reference_uvec2 = "GL_EXT_buffer_reference_uvec2";
const char* const E_GL_EXT_demote_to_helper_invocation = "GL_EXT_demote_to_helper_invocation";
const char* const E_GL_EXT_shader_realtime_clock = "GL_EXT_shader_realtime_clock";
const char* const E_GL_EXT_debug_printf = "GL_EXT_debug_printf";
const char* const E_GL_EXT_ray_tracing = "GL_EXT_ray_tracing";
const char* const E_GL_EXT_ray_query = "GL_EXT_ray_query";
const char* const E_GL_EXT_ray_flags_primitive_culling = "GL_EXT_ray_flags_primitive_culling";
const char* const E_GL_EXT_ray_cull_mask = "GL_EXT_ray_cull_mask";
const char* const E_GL_EXT_blend_func_extended = "GL_EXT_blend_func_extended";
const char* const E_GL_EXT_shader_implicit_conversions = "GL_EXT_shader_implicit_conversions";
const char* const E_GL_EXT_fragment_shading_rate = "GL_EXT_fragment_shading_rate";
const char* const E_GL_EXT_shader_image_int64 = "GL_EXT_shader_image_int64";
const char* const E_GL_EXT_null_initializer = "GL_EXT_null_initializer";
const char* const E_GL_EXT_shared_memory_block = "GL_EXT_shared_memory_block";
const char* const E_GL_EXT_subgroup_uniform_control_flow = "GL_EXT_subgroup_uniform_control_flow";
const char* const E_GL_EXT_spirv_intrinsics = "GL_EXT_spirv_intrinsics";
const char* const E_GL_EXT_fragment_shader_barycentric = "GL_EXT_fragment_shader_barycentric";
const char* const E_GL_EXT_mesh_shader = "GL_EXT_mesh_shader";
const char* const E_GL_EXT_opacity_micromap = "GL_EXT_opacity_micromap";
const char* const E_GL_EXT_shader_quad_control = "GL_EXT_shader_quad_control";
const char* const E_GL_EXT_draw_instanced = "GL_EXT_draw_instanced";
const char* const E_GL_EXT_texture_array = "GL_EXT_texture_array";
const char* const E_GL_EXT_maximal_reconvergence = "GL_EXT_maximal_reconvergence";
const char* const E_GL_EXT_expect_assume = "GL_EXT_expect_assume";
const char* const E_GL_EXT_control_flow_attributes2 = "GL_EXT_control_flow_attributes2";
const char* const E_GL_EXT_spec_constant_composites = "GL_EXT_spec_constant_composites";
// Arrays of extensions for the above viewportEXTs duplications
const char* const post_depth_coverageEXTs[] = { E_GL_ARB_post_depth_coverage, E_GL_EXT_post_depth_coverage };
const int Num_post_depth_coverageEXTs = sizeof(post_depth_coverageEXTs) / sizeof(post_depth_coverageEXTs[0]);
// Array of extensions to cover both extensions providing ray tracing capabilities.
const char* const ray_tracing_EXTs[] = { E_GL_EXT_ray_query, E_GL_EXT_ray_tracing };
const int Num_ray_tracing_EXTs = sizeof(ray_tracing_EXTs) / sizeof(ray_tracing_EXTs[0]);
// OVR extensions
const char* const E_GL_OVR_multiview = "GL_OVR_multiview";
const char* const E_GL_OVR_multiview2 = "GL_OVR_multiview2";
const char* const OVR_multiview_EXTs[] = { E_GL_OVR_multiview, E_GL_OVR_multiview2 };
const int Num_OVR_multiview_EXTs = sizeof(OVR_multiview_EXTs) / sizeof(OVR_multiview_EXTs[0]);
// #line and #include
const char* const E_GL_GOOGLE_cpp_style_line_directive = "GL_GOOGLE_cpp_style_line_directive";
const char* const E_GL_GOOGLE_include_directive = "GL_GOOGLE_include_directive";
const char* const E_GL_ARB_shading_language_include = "GL_ARB_shading_language_include";
const char* const E_GL_AMD_shader_ballot = "GL_AMD_shader_ballot";
const char* const E_GL_AMD_shader_trinary_minmax = "GL_AMD_shader_trinary_minmax";
const char* const E_GL_AMD_shader_explicit_vertex_parameter = "GL_AMD_shader_explicit_vertex_parameter";
const char* const E_GL_AMD_gcn_shader = "GL_AMD_gcn_shader";
const char* const E_GL_AMD_gpu_shader_half_float = "GL_AMD_gpu_shader_half_float";
const char* const E_GL_AMD_texture_gather_bias_lod = "GL_AMD_texture_gather_bias_lod";
const char* const E_GL_AMD_gpu_shader_int16 = "GL_AMD_gpu_shader_int16";
const char* const E_GL_AMD_shader_image_load_store_lod = "GL_AMD_shader_image_load_store_lod";
const char* const E_GL_AMD_shader_fragment_mask = "GL_AMD_shader_fragment_mask";
const char* const E_GL_AMD_gpu_shader_half_float_fetch = "GL_AMD_gpu_shader_half_float_fetch";
const char* const E_GL_AMD_shader_early_and_late_fragment_tests = "GL_AMD_shader_early_and_late_fragment_tests";
const char* const E_GL_INTEL_shader_integer_functions2 = "GL_INTEL_shader_integer_functions2";
const char* const E_GL_NV_sample_mask_override_coverage = "GL_NV_sample_mask_override_coverage";
const char* const E_SPV_NV_geometry_shader_passthrough = "GL_NV_geometry_shader_passthrough";
const char* const E_GL_NV_viewport_array2 = "GL_NV_viewport_array2";
const char* const E_GL_NV_stereo_view_rendering = "GL_NV_stereo_view_rendering";
const char* const E_GL_NVX_multiview_per_view_attributes = "GL_NVX_multiview_per_view_attributes";
const char* const E_GL_NV_shader_atomic_int64 = "GL_NV_shader_atomic_int64";
const char* const E_GL_NV_conservative_raster_underestimation = "GL_NV_conservative_raster_underestimation";
const char* const E_GL_NV_shader_noperspective_interpolation = "GL_NV_shader_noperspective_interpolation";
const char* const E_GL_NV_shader_subgroup_partitioned = "GL_NV_shader_subgroup_partitioned";
const char* const E_GL_NV_shading_rate_image = "GL_NV_shading_rate_image";
const char* const E_GL_NV_ray_tracing = "GL_NV_ray_tracing";
const char* const E_GL_NV_ray_tracing_motion_blur = "GL_NV_ray_tracing_motion_blur";
const char* const E_GL_NV_fragment_shader_barycentric = "GL_NV_fragment_shader_barycentric";
const char* const E_GL_NV_compute_shader_derivatives = "GL_NV_compute_shader_derivatives";
const char* const E_GL_NV_shader_texture_footprint = "GL_NV_shader_texture_footprint";
const char* const E_GL_NV_mesh_shader = "GL_NV_mesh_shader";
const char* const E_GL_NV_cooperative_matrix = "GL_NV_cooperative_matrix";
const char* const E_GL_NV_shader_sm_builtins = "GL_NV_shader_sm_builtins";
const char* const E_GL_NV_integer_cooperative_matrix = "GL_NV_integer_cooperative_matrix";
const char* const E_GL_NV_shader_invocation_reorder = "GL_NV_shader_invocation_reorder";
const char* const E_GL_EXT_ray_tracing_position_fetch = "GL_EXT_ray_tracing_position_fetch";
const char* const E_GL_NV_displacement_micromap = "GL_NV_displacement_micromap";
const char* const E_GL_NV_shader_atomic_fp16_vector = "GL_NV_shader_atomic_fp16_vector";
// ARM
const char* const E_GL_ARM_shader_core_builtins = "GL_ARM_shader_core_builtins";
// Arrays of extensions for the above viewportEXTs duplications
const char* const viewportEXTs[] = { E_GL_ARB_shader_viewport_layer_array, E_GL_NV_viewport_array2 };
const int Num_viewportEXTs = sizeof(viewportEXTs) / sizeof(viewportEXTs[0]);
const char* const E_GL_QCOM_image_processing = "GL_QCOM_image_processing";
const char* const E_GL_QCOM_image_processing2 = "GL_QCOM_image_processing2";
// AEP
const char* const E_GL_ANDROID_extension_pack_es31a = "GL_ANDROID_extension_pack_es31a";
const char* const E_GL_KHR_blend_equation_advanced = "GL_KHR_blend_equation_advanced";
const char* const E_GL_OES_sample_variables = "GL_OES_sample_variables";
const char* const E_GL_OES_shader_image_atomic = "GL_OES_shader_image_atomic";
const char* const E_GL_OES_shader_multisample_interpolation = "GL_OES_shader_multisample_interpolation";
const char* const E_GL_OES_texture_storage_multisample_2d_array = "GL_OES_texture_storage_multisample_2d_array";
const char* const E_GL_EXT_geometry_shader = "GL_EXT_geometry_shader";
const char* const E_GL_EXT_geometry_point_size = "GL_EXT_geometry_point_size";
const char* const E_GL_EXT_gpu_shader5 = "GL_EXT_gpu_shader5";
const char* const E_GL_EXT_primitive_bounding_box = "GL_EXT_primitive_bounding_box";
const char* const E_GL_EXT_shader_io_blocks = "GL_EXT_shader_io_blocks";
const char* const E_GL_EXT_tessellation_shader = "GL_EXT_tessellation_shader";
const char* const E_GL_EXT_tessellation_point_size = "GL_EXT_tessellation_point_size";
const char* const E_GL_EXT_texture_buffer = "GL_EXT_texture_buffer";
const char* const E_GL_EXT_texture_cube_map_array = "GL_EXT_texture_cube_map_array";
const char* const E_GL_EXT_shader_integer_mix = "GL_EXT_shader_integer_mix";
// OES matching AEP
const char* const E_GL_OES_geometry_shader = "GL_OES_geometry_shader";
const char* const E_GL_OES_geometry_point_size = "GL_OES_geometry_point_size";
const char* const E_GL_OES_gpu_shader5 = "GL_OES_gpu_shader5";
const char* const E_GL_OES_primitive_bounding_box = "GL_OES_primitive_bounding_box";
const char* const E_GL_OES_shader_io_blocks = "GL_OES_shader_io_blocks";
const char* const E_GL_OES_tessellation_shader = "GL_OES_tessellation_shader";
const char* const E_GL_OES_tessellation_point_size = "GL_OES_tessellation_point_size";
const char* const E_GL_OES_texture_buffer = "GL_OES_texture_buffer";
const char* const E_GL_OES_texture_cube_map_array = "GL_OES_texture_cube_map_array";
// EXT
const char* const E_GL_EXT_shader_explicit_arithmetic_types = "GL_EXT_shader_explicit_arithmetic_types";
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int8 = "GL_EXT_shader_explicit_arithmetic_types_int8";
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int16 = "GL_EXT_shader_explicit_arithmetic_types_int16";
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int32 = "GL_EXT_shader_explicit_arithmetic_types_int32";
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int64 = "GL_EXT_shader_explicit_arithmetic_types_int64";
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float16 = "GL_EXT_shader_explicit_arithmetic_types_float16";
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float32 = "GL_EXT_shader_explicit_arithmetic_types_float32";
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float64 = "GL_EXT_shader_explicit_arithmetic_types_float64";
const char* const E_GL_EXT_shader_subgroup_extended_types_int8 = "GL_EXT_shader_subgroup_extended_types_int8";
const char* const E_GL_EXT_shader_subgroup_extended_types_int16 = "GL_EXT_shader_subgroup_extended_types_int16";
const char* const E_GL_EXT_shader_subgroup_extended_types_int64 = "GL_EXT_shader_subgroup_extended_types_int64";
const char* const E_GL_EXT_shader_subgroup_extended_types_float16 = "GL_EXT_shader_subgroup_extended_types_float16";
const char* const E_GL_EXT_terminate_invocation = "GL_EXT_terminate_invocation";
const char* const E_GL_EXT_shader_atomic_float = "GL_EXT_shader_atomic_float";
const char* const E_GL_EXT_shader_atomic_float2 = "GL_EXT_shader_atomic_float2";
const char* const E_GL_EXT_shader_tile_image = "GL_EXT_shader_tile_image";
const char* const E_GL_EXT_texture_shadow_lod = "GL_EXT_texture_shadow_lod";
// Arrays of extensions for the above AEP duplications
const char* const AEP_geometry_shader[] = { E_GL_EXT_geometry_shader, E_GL_OES_geometry_shader };
const int Num_AEP_geometry_shader = sizeof(AEP_geometry_shader)/sizeof(AEP_geometry_shader[0]);
const char* const AEP_geometry_point_size[] = { E_GL_EXT_geometry_point_size, E_GL_OES_geometry_point_size };
const int Num_AEP_geometry_point_size = sizeof(AEP_geometry_point_size)/sizeof(AEP_geometry_point_size[0]);
const char* const AEP_gpu_shader5[] = { E_GL_EXT_gpu_shader5, E_GL_OES_gpu_shader5 };
const int Num_AEP_gpu_shader5 = sizeof(AEP_gpu_shader5)/sizeof(AEP_gpu_shader5[0]);
const char* const AEP_primitive_bounding_box[] = { E_GL_EXT_primitive_bounding_box, E_GL_OES_primitive_bounding_box };
const int Num_AEP_primitive_bounding_box = sizeof(AEP_primitive_bounding_box)/sizeof(AEP_primitive_bounding_box[0]);
const char* const AEP_shader_io_blocks[] = { E_GL_EXT_shader_io_blocks, E_GL_OES_shader_io_blocks };
const int Num_AEP_shader_io_blocks = sizeof(AEP_shader_io_blocks)/sizeof(AEP_shader_io_blocks[0]);
const char* const AEP_tessellation_shader[] = { E_GL_EXT_tessellation_shader, E_GL_OES_tessellation_shader };
const int Num_AEP_tessellation_shader = sizeof(AEP_tessellation_shader)/sizeof(AEP_tessellation_shader[0]);
const char* const AEP_tessellation_point_size[] = { E_GL_EXT_tessellation_point_size, E_GL_OES_tessellation_point_size };
const int Num_AEP_tessellation_point_size = sizeof(AEP_tessellation_point_size)/sizeof(AEP_tessellation_point_size[0]);
const char* const AEP_texture_buffer[] = { E_GL_EXT_texture_buffer, E_GL_OES_texture_buffer };
const int Num_AEP_texture_buffer = sizeof(AEP_texture_buffer)/sizeof(AEP_texture_buffer[0]);
const char* const AEP_texture_cube_map_array[] = { E_GL_EXT_texture_cube_map_array, E_GL_OES_texture_cube_map_array };
const int Num_AEP_texture_cube_map_array = sizeof(AEP_texture_cube_map_array)/sizeof(AEP_texture_cube_map_array[0]);
const char* const AEP_mesh_shader[] = { E_GL_NV_mesh_shader, E_GL_EXT_mesh_shader };
const int Num_AEP_mesh_shader = sizeof(AEP_mesh_shader)/sizeof(AEP_mesh_shader[0]);
} // end namespace glslang
#endif // _VERSIONS_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/parseConst.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Traverse a tree of constants to create a single folded constant.
// It should only be used when the whole tree is known to be constant.
//
#include "ParseHelper.h"
namespace glslang {
class TConstTraverser : public TIntermTraverser {
public:
TConstTraverser(const TConstUnionArray& cUnion, bool singleConstParam, TOperator constructType, const TType& t)
: unionArray(cUnion), type(t),
constructorType(constructType), singleConstantParam(singleConstParam), error(false), isMatrix(false),
matrixCols(0), matrixRows(0) { index = 0; tOp = EOpNull; }
virtual void visitConstantUnion(TIntermConstantUnion* node);
virtual bool visitAggregate(TVisit, TIntermAggregate* node);
int index;
TConstUnionArray unionArray;
TOperator tOp;
const TType& type;
TOperator constructorType;
bool singleConstantParam;
bool error;
int size; // size of the constructor ( 4 for vec4)
bool isMatrix;
int matrixCols;
int matrixRows;
protected:
TConstTraverser(TConstTraverser&);
TConstTraverser& operator=(TConstTraverser&);
};
bool TConstTraverser::visitAggregate(TVisit /* visit */, TIntermAggregate* node)
{
if (! node->isConstructor() && node->getOp() != EOpComma) {
error = true;
return false;
}
bool flag = node->getSequence().size() == 1 && node->getSequence()[0]->getAsTyped()->getAsConstantUnion();
if (flag) {
singleConstantParam = true;
constructorType = node->getOp();
size = node->getType().computeNumComponents();
if (node->getType().isMatrix()) {
isMatrix = true;
matrixCols = node->getType().getMatrixCols();
matrixRows = node->getType().getMatrixRows();
}
}
for (TIntermSequence::iterator p = node->getSequence().begin();
p != node->getSequence().end(); p++) {
if (node->getOp() == EOpComma)
index = 0;
(*p)->traverse(this);
}
if (flag)
{
singleConstantParam = false;
constructorType = EOpNull;
size = 0;
isMatrix = false;
matrixCols = 0;
matrixRows = 0;
}
return false;
}
void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
{
TConstUnionArray leftUnionArray(unionArray);
int instanceSize = type.computeNumComponents();
if (index >= instanceSize)
return;
if (! singleConstantParam) {
int rightUnionSize = node->getType().computeNumComponents();
const TConstUnionArray& rightUnionArray = node->getConstArray();
for (int i = 0; i < rightUnionSize; i++) {
if (index >= instanceSize)
return;
leftUnionArray[index] = rightUnionArray[i];
index++;
}
} else {
int endIndex = index + size;
const TConstUnionArray& rightUnionArray = node->getConstArray();
if (! isMatrix) {
int count = 0;
int nodeComps = node->getType().computeNumComponents();
for (int i = index; i < endIndex; i++) {
if (i >= instanceSize)
return;
leftUnionArray[i] = rightUnionArray[count];
(index)++;
if (nodeComps > 1)
count++;
}
} else {
// constructing a matrix, but from what?
if (node->isMatrix()) {
// Matrix from a matrix; this has the outer matrix, node is the argument matrix.
// Traverse the outer, potentially bigger matrix, fill in missing pieces with the
// identity matrix.
for (int c = 0; c < matrixCols; ++c) {
for (int r = 0; r < matrixRows; ++r) {
int targetOffset = index + c * matrixRows + r;
if (r < node->getType().getMatrixRows() && c < node->getType().getMatrixCols()) {
int srcOffset = c * node->getType().getMatrixRows() + r;
leftUnionArray[targetOffset] = rightUnionArray[srcOffset];
} else if (r == c)
leftUnionArray[targetOffset].setDConst(1.0);
else
leftUnionArray[targetOffset].setDConst(0.0);
}
}
} else {
// matrix from vector or scalar
int nodeComps = node->getType().computeNumComponents();
if (nodeComps == 1) {
for (int c = 0; c < matrixCols; ++c) {
for (int r = 0; r < matrixRows; ++r) {
if (r == c)
leftUnionArray[index] = rightUnionArray[0];
else
leftUnionArray[index].setDConst(0.0);
index++;
}
}
} else {
int count = 0;
for (int i = index; i < endIndex; i++) {
if (i >= instanceSize)
return;
// construct the matrix in column-major order, from
// the components provided, in order
leftUnionArray[i] = rightUnionArray[count];
index++;
count++;
}
}
}
}
}
}
bool TIntermediate::parseConstTree(TIntermNode* root, TConstUnionArray unionArray, TOperator constructorType, const TType& t, bool singleConstantParam)
{
if (root == nullptr)
return false;
TConstTraverser it(unionArray, singleConstantParam, constructorType, t);
root->traverse(&it);
if (it.error)
return true;
else
return false;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/glslang_tab.cpp | /* A Bison parser, made by GNU Bison 3.8.2. */
/* Bison implementation for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* C LALR(1) parser skeleton written by Richard Stallman, by
simplifying the original so-called "semantic" parser. */
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
/* All symbols defined below should begin with yy or YY, to avoid
infringing on user name space. This should be done even for local
variables, as they might otherwise be expanded by user macros.
There are some unavoidable exceptions within include files to
define necessary library symbols; they are noted "INFRINGES ON
USER NAME SPACE" below. */
/* Identify Bison output, and Bison version. */
#define YYBISON 30802
/* Bison version string. */
#define YYBISON_VERSION "3.8.2"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
/* Pure parsers. */
#define YYPURE 1
/* Push parsers. */
#define YYPUSH 0
/* Pull parsers. */
#define YYPULL 1
/* First part of user prologue. */
#line 44 "MachineIndependent/glslang.y"
/* Based on:
ANSI C Yacc grammar
In 1985, Jeff Lee published his Yacc grammar (which is accompanied by a
matching Lex specification) for the April 30, 1985 draft version of the
ANSI C standard. Tom Stockfisch reposted it to net.sources in 1987; that
original, as mentioned in the answer to question 17.25 of the comp.lang.c
FAQ, can be ftp'ed from ftp.uu.net, file usenet/net.sources/ansi.c.grammar.Z.
I intend to keep this version as close to the current C Standard grammar as
possible; please let me know if you discover discrepancies.
Jutta Degener, 1995
*/
#include "SymbolTable.h"
#include "ParseHelper.h"
#include "../Public/ShaderLang.h"
#include "attribute.h"
using namespace glslang;
#line 97 "MachineIndependent/glslang_tab.cpp"
# ifndef YY_CAST
# ifdef __cplusplus
# define YY_CAST(Type, Val) static_cast<Type> (Val)
# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
# else
# define YY_CAST(Type, Val) ((Type) (Val))
# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
# endif
# endif
# ifndef YY_NULLPTR
# if defined __cplusplus
# if 201103L <= __cplusplus
# define YY_NULLPTR nullptr
# else
# define YY_NULLPTR 0
# endif
# else
# define YY_NULLPTR ((void*)0)
# endif
# endif
#include "glslang_tab.cpp.h"
/* Symbol kind. */
enum yysymbol_kind_t
{
YYSYMBOL_YYEMPTY = -2,
YYSYMBOL_YYEOF = 0, /* "end of file" */
YYSYMBOL_YYerror = 1, /* error */
YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
YYSYMBOL_CONST = 3, /* CONST */
YYSYMBOL_BOOL = 4, /* BOOL */
YYSYMBOL_INT = 5, /* INT */
YYSYMBOL_UINT = 6, /* UINT */
YYSYMBOL_FLOAT = 7, /* FLOAT */
YYSYMBOL_BVEC2 = 8, /* BVEC2 */
YYSYMBOL_BVEC3 = 9, /* BVEC3 */
YYSYMBOL_BVEC4 = 10, /* BVEC4 */
YYSYMBOL_IVEC2 = 11, /* IVEC2 */
YYSYMBOL_IVEC3 = 12, /* IVEC3 */
YYSYMBOL_IVEC4 = 13, /* IVEC4 */
YYSYMBOL_UVEC2 = 14, /* UVEC2 */
YYSYMBOL_UVEC3 = 15, /* UVEC3 */
YYSYMBOL_UVEC4 = 16, /* UVEC4 */
YYSYMBOL_VEC2 = 17, /* VEC2 */
YYSYMBOL_VEC3 = 18, /* VEC3 */
YYSYMBOL_VEC4 = 19, /* VEC4 */
YYSYMBOL_MAT2 = 20, /* MAT2 */
YYSYMBOL_MAT3 = 21, /* MAT3 */
YYSYMBOL_MAT4 = 22, /* MAT4 */
YYSYMBOL_MAT2X2 = 23, /* MAT2X2 */
YYSYMBOL_MAT2X3 = 24, /* MAT2X3 */
YYSYMBOL_MAT2X4 = 25, /* MAT2X4 */
YYSYMBOL_MAT3X2 = 26, /* MAT3X2 */
YYSYMBOL_MAT3X3 = 27, /* MAT3X3 */
YYSYMBOL_MAT3X4 = 28, /* MAT3X4 */
YYSYMBOL_MAT4X2 = 29, /* MAT4X2 */
YYSYMBOL_MAT4X3 = 30, /* MAT4X3 */
YYSYMBOL_MAT4X4 = 31, /* MAT4X4 */
YYSYMBOL_SAMPLER2D = 32, /* SAMPLER2D */
YYSYMBOL_SAMPLER3D = 33, /* SAMPLER3D */
YYSYMBOL_SAMPLERCUBE = 34, /* SAMPLERCUBE */
YYSYMBOL_SAMPLER2DSHADOW = 35, /* SAMPLER2DSHADOW */
YYSYMBOL_SAMPLERCUBESHADOW = 36, /* SAMPLERCUBESHADOW */
YYSYMBOL_SAMPLER2DARRAY = 37, /* SAMPLER2DARRAY */
YYSYMBOL_SAMPLER2DARRAYSHADOW = 38, /* SAMPLER2DARRAYSHADOW */
YYSYMBOL_ISAMPLER2D = 39, /* ISAMPLER2D */
YYSYMBOL_ISAMPLER3D = 40, /* ISAMPLER3D */
YYSYMBOL_ISAMPLERCUBE = 41, /* ISAMPLERCUBE */
YYSYMBOL_ISAMPLER2DARRAY = 42, /* ISAMPLER2DARRAY */
YYSYMBOL_USAMPLER2D = 43, /* USAMPLER2D */
YYSYMBOL_USAMPLER3D = 44, /* USAMPLER3D */
YYSYMBOL_USAMPLERCUBE = 45, /* USAMPLERCUBE */
YYSYMBOL_USAMPLER2DARRAY = 46, /* USAMPLER2DARRAY */
YYSYMBOL_SAMPLER = 47, /* SAMPLER */
YYSYMBOL_SAMPLERSHADOW = 48, /* SAMPLERSHADOW */
YYSYMBOL_TEXTURE2D = 49, /* TEXTURE2D */
YYSYMBOL_TEXTURE3D = 50, /* TEXTURE3D */
YYSYMBOL_TEXTURECUBE = 51, /* TEXTURECUBE */
YYSYMBOL_TEXTURE2DARRAY = 52, /* TEXTURE2DARRAY */
YYSYMBOL_ITEXTURE2D = 53, /* ITEXTURE2D */
YYSYMBOL_ITEXTURE3D = 54, /* ITEXTURE3D */
YYSYMBOL_ITEXTURECUBE = 55, /* ITEXTURECUBE */
YYSYMBOL_ITEXTURE2DARRAY = 56, /* ITEXTURE2DARRAY */
YYSYMBOL_UTEXTURE2D = 57, /* UTEXTURE2D */
YYSYMBOL_UTEXTURE3D = 58, /* UTEXTURE3D */
YYSYMBOL_UTEXTURECUBE = 59, /* UTEXTURECUBE */
YYSYMBOL_UTEXTURE2DARRAY = 60, /* UTEXTURE2DARRAY */
YYSYMBOL_ATTRIBUTE = 61, /* ATTRIBUTE */
YYSYMBOL_VARYING = 62, /* VARYING */
YYSYMBOL_FLOAT16_T = 63, /* FLOAT16_T */
YYSYMBOL_FLOAT32_T = 64, /* FLOAT32_T */
YYSYMBOL_DOUBLE = 65, /* DOUBLE */
YYSYMBOL_FLOAT64_T = 66, /* FLOAT64_T */
YYSYMBOL_INT64_T = 67, /* INT64_T */
YYSYMBOL_UINT64_T = 68, /* UINT64_T */
YYSYMBOL_INT32_T = 69, /* INT32_T */
YYSYMBOL_UINT32_T = 70, /* UINT32_T */
YYSYMBOL_INT16_T = 71, /* INT16_T */
YYSYMBOL_UINT16_T = 72, /* UINT16_T */
YYSYMBOL_INT8_T = 73, /* INT8_T */
YYSYMBOL_UINT8_T = 74, /* UINT8_T */
YYSYMBOL_I64VEC2 = 75, /* I64VEC2 */
YYSYMBOL_I64VEC3 = 76, /* I64VEC3 */
YYSYMBOL_I64VEC4 = 77, /* I64VEC4 */
YYSYMBOL_U64VEC2 = 78, /* U64VEC2 */
YYSYMBOL_U64VEC3 = 79, /* U64VEC3 */
YYSYMBOL_U64VEC4 = 80, /* U64VEC4 */
YYSYMBOL_I32VEC2 = 81, /* I32VEC2 */
YYSYMBOL_I32VEC3 = 82, /* I32VEC3 */
YYSYMBOL_I32VEC4 = 83, /* I32VEC4 */
YYSYMBOL_U32VEC2 = 84, /* U32VEC2 */
YYSYMBOL_U32VEC3 = 85, /* U32VEC3 */
YYSYMBOL_U32VEC4 = 86, /* U32VEC4 */
YYSYMBOL_I16VEC2 = 87, /* I16VEC2 */
YYSYMBOL_I16VEC3 = 88, /* I16VEC3 */
YYSYMBOL_I16VEC4 = 89, /* I16VEC4 */
YYSYMBOL_U16VEC2 = 90, /* U16VEC2 */
YYSYMBOL_U16VEC3 = 91, /* U16VEC3 */
YYSYMBOL_U16VEC4 = 92, /* U16VEC4 */
YYSYMBOL_I8VEC2 = 93, /* I8VEC2 */
YYSYMBOL_I8VEC3 = 94, /* I8VEC3 */
YYSYMBOL_I8VEC4 = 95, /* I8VEC4 */
YYSYMBOL_U8VEC2 = 96, /* U8VEC2 */
YYSYMBOL_U8VEC3 = 97, /* U8VEC3 */
YYSYMBOL_U8VEC4 = 98, /* U8VEC4 */
YYSYMBOL_DVEC2 = 99, /* DVEC2 */
YYSYMBOL_DVEC3 = 100, /* DVEC3 */
YYSYMBOL_DVEC4 = 101, /* DVEC4 */
YYSYMBOL_DMAT2 = 102, /* DMAT2 */
YYSYMBOL_DMAT3 = 103, /* DMAT3 */
YYSYMBOL_DMAT4 = 104, /* DMAT4 */
YYSYMBOL_F16VEC2 = 105, /* F16VEC2 */
YYSYMBOL_F16VEC3 = 106, /* F16VEC3 */
YYSYMBOL_F16VEC4 = 107, /* F16VEC4 */
YYSYMBOL_F16MAT2 = 108, /* F16MAT2 */
YYSYMBOL_F16MAT3 = 109, /* F16MAT3 */
YYSYMBOL_F16MAT4 = 110, /* F16MAT4 */
YYSYMBOL_F32VEC2 = 111, /* F32VEC2 */
YYSYMBOL_F32VEC3 = 112, /* F32VEC3 */
YYSYMBOL_F32VEC4 = 113, /* F32VEC4 */
YYSYMBOL_F32MAT2 = 114, /* F32MAT2 */
YYSYMBOL_F32MAT3 = 115, /* F32MAT3 */
YYSYMBOL_F32MAT4 = 116, /* F32MAT4 */
YYSYMBOL_F64VEC2 = 117, /* F64VEC2 */
YYSYMBOL_F64VEC3 = 118, /* F64VEC3 */
YYSYMBOL_F64VEC4 = 119, /* F64VEC4 */
YYSYMBOL_F64MAT2 = 120, /* F64MAT2 */
YYSYMBOL_F64MAT3 = 121, /* F64MAT3 */
YYSYMBOL_F64MAT4 = 122, /* F64MAT4 */
YYSYMBOL_DMAT2X2 = 123, /* DMAT2X2 */
YYSYMBOL_DMAT2X3 = 124, /* DMAT2X3 */
YYSYMBOL_DMAT2X4 = 125, /* DMAT2X4 */
YYSYMBOL_DMAT3X2 = 126, /* DMAT3X2 */
YYSYMBOL_DMAT3X3 = 127, /* DMAT3X3 */
YYSYMBOL_DMAT3X4 = 128, /* DMAT3X4 */
YYSYMBOL_DMAT4X2 = 129, /* DMAT4X2 */
YYSYMBOL_DMAT4X3 = 130, /* DMAT4X3 */
YYSYMBOL_DMAT4X4 = 131, /* DMAT4X4 */
YYSYMBOL_F16MAT2X2 = 132, /* F16MAT2X2 */
YYSYMBOL_F16MAT2X3 = 133, /* F16MAT2X3 */
YYSYMBOL_F16MAT2X4 = 134, /* F16MAT2X4 */
YYSYMBOL_F16MAT3X2 = 135, /* F16MAT3X2 */
YYSYMBOL_F16MAT3X3 = 136, /* F16MAT3X3 */
YYSYMBOL_F16MAT3X4 = 137, /* F16MAT3X4 */
YYSYMBOL_F16MAT4X2 = 138, /* F16MAT4X2 */
YYSYMBOL_F16MAT4X3 = 139, /* F16MAT4X3 */
YYSYMBOL_F16MAT4X4 = 140, /* F16MAT4X4 */
YYSYMBOL_F32MAT2X2 = 141, /* F32MAT2X2 */
YYSYMBOL_F32MAT2X3 = 142, /* F32MAT2X3 */
YYSYMBOL_F32MAT2X4 = 143, /* F32MAT2X4 */
YYSYMBOL_F32MAT3X2 = 144, /* F32MAT3X2 */
YYSYMBOL_F32MAT3X3 = 145, /* F32MAT3X3 */
YYSYMBOL_F32MAT3X4 = 146, /* F32MAT3X4 */
YYSYMBOL_F32MAT4X2 = 147, /* F32MAT4X2 */
YYSYMBOL_F32MAT4X3 = 148, /* F32MAT4X3 */
YYSYMBOL_F32MAT4X4 = 149, /* F32MAT4X4 */
YYSYMBOL_F64MAT2X2 = 150, /* F64MAT2X2 */
YYSYMBOL_F64MAT2X3 = 151, /* F64MAT2X3 */
YYSYMBOL_F64MAT2X4 = 152, /* F64MAT2X4 */
YYSYMBOL_F64MAT3X2 = 153, /* F64MAT3X2 */
YYSYMBOL_F64MAT3X3 = 154, /* F64MAT3X3 */
YYSYMBOL_F64MAT3X4 = 155, /* F64MAT3X4 */
YYSYMBOL_F64MAT4X2 = 156, /* F64MAT4X2 */
YYSYMBOL_F64MAT4X3 = 157, /* F64MAT4X3 */
YYSYMBOL_F64MAT4X4 = 158, /* F64MAT4X4 */
YYSYMBOL_ATOMIC_UINT = 159, /* ATOMIC_UINT */
YYSYMBOL_ACCSTRUCTNV = 160, /* ACCSTRUCTNV */
YYSYMBOL_ACCSTRUCTEXT = 161, /* ACCSTRUCTEXT */
YYSYMBOL_RAYQUERYEXT = 162, /* RAYQUERYEXT */
YYSYMBOL_FCOOPMATNV = 163, /* FCOOPMATNV */
YYSYMBOL_ICOOPMATNV = 164, /* ICOOPMATNV */
YYSYMBOL_UCOOPMATNV = 165, /* UCOOPMATNV */
YYSYMBOL_COOPMAT = 166, /* COOPMAT */
YYSYMBOL_HITOBJECTNV = 167, /* HITOBJECTNV */
YYSYMBOL_HITOBJECTATTRNV = 168, /* HITOBJECTATTRNV */
YYSYMBOL_SAMPLERCUBEARRAY = 169, /* SAMPLERCUBEARRAY */
YYSYMBOL_SAMPLERCUBEARRAYSHADOW = 170, /* SAMPLERCUBEARRAYSHADOW */
YYSYMBOL_ISAMPLERCUBEARRAY = 171, /* ISAMPLERCUBEARRAY */
YYSYMBOL_USAMPLERCUBEARRAY = 172, /* USAMPLERCUBEARRAY */
YYSYMBOL_SAMPLER1D = 173, /* SAMPLER1D */
YYSYMBOL_SAMPLER1DARRAY = 174, /* SAMPLER1DARRAY */
YYSYMBOL_SAMPLER1DARRAYSHADOW = 175, /* SAMPLER1DARRAYSHADOW */
YYSYMBOL_ISAMPLER1D = 176, /* ISAMPLER1D */
YYSYMBOL_SAMPLER1DSHADOW = 177, /* SAMPLER1DSHADOW */
YYSYMBOL_SAMPLER2DRECT = 178, /* SAMPLER2DRECT */
YYSYMBOL_SAMPLER2DRECTSHADOW = 179, /* SAMPLER2DRECTSHADOW */
YYSYMBOL_ISAMPLER2DRECT = 180, /* ISAMPLER2DRECT */
YYSYMBOL_USAMPLER2DRECT = 181, /* USAMPLER2DRECT */
YYSYMBOL_SAMPLERBUFFER = 182, /* SAMPLERBUFFER */
YYSYMBOL_ISAMPLERBUFFER = 183, /* ISAMPLERBUFFER */
YYSYMBOL_USAMPLERBUFFER = 184, /* USAMPLERBUFFER */
YYSYMBOL_SAMPLER2DMS = 185, /* SAMPLER2DMS */
YYSYMBOL_ISAMPLER2DMS = 186, /* ISAMPLER2DMS */
YYSYMBOL_USAMPLER2DMS = 187, /* USAMPLER2DMS */
YYSYMBOL_SAMPLER2DMSARRAY = 188, /* SAMPLER2DMSARRAY */
YYSYMBOL_ISAMPLER2DMSARRAY = 189, /* ISAMPLER2DMSARRAY */
YYSYMBOL_USAMPLER2DMSARRAY = 190, /* USAMPLER2DMSARRAY */
YYSYMBOL_SAMPLEREXTERNALOES = 191, /* SAMPLEREXTERNALOES */
YYSYMBOL_SAMPLEREXTERNAL2DY2YEXT = 192, /* SAMPLEREXTERNAL2DY2YEXT */
YYSYMBOL_ISAMPLER1DARRAY = 193, /* ISAMPLER1DARRAY */
YYSYMBOL_USAMPLER1D = 194, /* USAMPLER1D */
YYSYMBOL_USAMPLER1DARRAY = 195, /* USAMPLER1DARRAY */
YYSYMBOL_F16SAMPLER1D = 196, /* F16SAMPLER1D */
YYSYMBOL_F16SAMPLER2D = 197, /* F16SAMPLER2D */
YYSYMBOL_F16SAMPLER3D = 198, /* F16SAMPLER3D */
YYSYMBOL_F16SAMPLER2DRECT = 199, /* F16SAMPLER2DRECT */
YYSYMBOL_F16SAMPLERCUBE = 200, /* F16SAMPLERCUBE */
YYSYMBOL_F16SAMPLER1DARRAY = 201, /* F16SAMPLER1DARRAY */
YYSYMBOL_F16SAMPLER2DARRAY = 202, /* F16SAMPLER2DARRAY */
YYSYMBOL_F16SAMPLERCUBEARRAY = 203, /* F16SAMPLERCUBEARRAY */
YYSYMBOL_F16SAMPLERBUFFER = 204, /* F16SAMPLERBUFFER */
YYSYMBOL_F16SAMPLER2DMS = 205, /* F16SAMPLER2DMS */
YYSYMBOL_F16SAMPLER2DMSARRAY = 206, /* F16SAMPLER2DMSARRAY */
YYSYMBOL_F16SAMPLER1DSHADOW = 207, /* F16SAMPLER1DSHADOW */
YYSYMBOL_F16SAMPLER2DSHADOW = 208, /* F16SAMPLER2DSHADOW */
YYSYMBOL_F16SAMPLER1DARRAYSHADOW = 209, /* F16SAMPLER1DARRAYSHADOW */
YYSYMBOL_F16SAMPLER2DARRAYSHADOW = 210, /* F16SAMPLER2DARRAYSHADOW */
YYSYMBOL_F16SAMPLER2DRECTSHADOW = 211, /* F16SAMPLER2DRECTSHADOW */
YYSYMBOL_F16SAMPLERCUBESHADOW = 212, /* F16SAMPLERCUBESHADOW */
YYSYMBOL_F16SAMPLERCUBEARRAYSHADOW = 213, /* F16SAMPLERCUBEARRAYSHADOW */
YYSYMBOL_IMAGE1D = 214, /* IMAGE1D */
YYSYMBOL_IIMAGE1D = 215, /* IIMAGE1D */
YYSYMBOL_UIMAGE1D = 216, /* UIMAGE1D */
YYSYMBOL_IMAGE2D = 217, /* IMAGE2D */
YYSYMBOL_IIMAGE2D = 218, /* IIMAGE2D */
YYSYMBOL_UIMAGE2D = 219, /* UIMAGE2D */
YYSYMBOL_IMAGE3D = 220, /* IMAGE3D */
YYSYMBOL_IIMAGE3D = 221, /* IIMAGE3D */
YYSYMBOL_UIMAGE3D = 222, /* UIMAGE3D */
YYSYMBOL_IMAGE2DRECT = 223, /* IMAGE2DRECT */
YYSYMBOL_IIMAGE2DRECT = 224, /* IIMAGE2DRECT */
YYSYMBOL_UIMAGE2DRECT = 225, /* UIMAGE2DRECT */
YYSYMBOL_IMAGECUBE = 226, /* IMAGECUBE */
YYSYMBOL_IIMAGECUBE = 227, /* IIMAGECUBE */
YYSYMBOL_UIMAGECUBE = 228, /* UIMAGECUBE */
YYSYMBOL_IMAGEBUFFER = 229, /* IMAGEBUFFER */
YYSYMBOL_IIMAGEBUFFER = 230, /* IIMAGEBUFFER */
YYSYMBOL_UIMAGEBUFFER = 231, /* UIMAGEBUFFER */
YYSYMBOL_IMAGE1DARRAY = 232, /* IMAGE1DARRAY */
YYSYMBOL_IIMAGE1DARRAY = 233, /* IIMAGE1DARRAY */
YYSYMBOL_UIMAGE1DARRAY = 234, /* UIMAGE1DARRAY */
YYSYMBOL_IMAGE2DARRAY = 235, /* IMAGE2DARRAY */
YYSYMBOL_IIMAGE2DARRAY = 236, /* IIMAGE2DARRAY */
YYSYMBOL_UIMAGE2DARRAY = 237, /* UIMAGE2DARRAY */
YYSYMBOL_IMAGECUBEARRAY = 238, /* IMAGECUBEARRAY */
YYSYMBOL_IIMAGECUBEARRAY = 239, /* IIMAGECUBEARRAY */
YYSYMBOL_UIMAGECUBEARRAY = 240, /* UIMAGECUBEARRAY */
YYSYMBOL_IMAGE2DMS = 241, /* IMAGE2DMS */
YYSYMBOL_IIMAGE2DMS = 242, /* IIMAGE2DMS */
YYSYMBOL_UIMAGE2DMS = 243, /* UIMAGE2DMS */
YYSYMBOL_IMAGE2DMSARRAY = 244, /* IMAGE2DMSARRAY */
YYSYMBOL_IIMAGE2DMSARRAY = 245, /* IIMAGE2DMSARRAY */
YYSYMBOL_UIMAGE2DMSARRAY = 246, /* UIMAGE2DMSARRAY */
YYSYMBOL_F16IMAGE1D = 247, /* F16IMAGE1D */
YYSYMBOL_F16IMAGE2D = 248, /* F16IMAGE2D */
YYSYMBOL_F16IMAGE3D = 249, /* F16IMAGE3D */
YYSYMBOL_F16IMAGE2DRECT = 250, /* F16IMAGE2DRECT */
YYSYMBOL_F16IMAGECUBE = 251, /* F16IMAGECUBE */
YYSYMBOL_F16IMAGE1DARRAY = 252, /* F16IMAGE1DARRAY */
YYSYMBOL_F16IMAGE2DARRAY = 253, /* F16IMAGE2DARRAY */
YYSYMBOL_F16IMAGECUBEARRAY = 254, /* F16IMAGECUBEARRAY */
YYSYMBOL_F16IMAGEBUFFER = 255, /* F16IMAGEBUFFER */
YYSYMBOL_F16IMAGE2DMS = 256, /* F16IMAGE2DMS */
YYSYMBOL_F16IMAGE2DMSARRAY = 257, /* F16IMAGE2DMSARRAY */
YYSYMBOL_I64IMAGE1D = 258, /* I64IMAGE1D */
YYSYMBOL_U64IMAGE1D = 259, /* U64IMAGE1D */
YYSYMBOL_I64IMAGE2D = 260, /* I64IMAGE2D */
YYSYMBOL_U64IMAGE2D = 261, /* U64IMAGE2D */
YYSYMBOL_I64IMAGE3D = 262, /* I64IMAGE3D */
YYSYMBOL_U64IMAGE3D = 263, /* U64IMAGE3D */
YYSYMBOL_I64IMAGE2DRECT = 264, /* I64IMAGE2DRECT */
YYSYMBOL_U64IMAGE2DRECT = 265, /* U64IMAGE2DRECT */
YYSYMBOL_I64IMAGECUBE = 266, /* I64IMAGECUBE */
YYSYMBOL_U64IMAGECUBE = 267, /* U64IMAGECUBE */
YYSYMBOL_I64IMAGEBUFFER = 268, /* I64IMAGEBUFFER */
YYSYMBOL_U64IMAGEBUFFER = 269, /* U64IMAGEBUFFER */
YYSYMBOL_I64IMAGE1DARRAY = 270, /* I64IMAGE1DARRAY */
YYSYMBOL_U64IMAGE1DARRAY = 271, /* U64IMAGE1DARRAY */
YYSYMBOL_I64IMAGE2DARRAY = 272, /* I64IMAGE2DARRAY */
YYSYMBOL_U64IMAGE2DARRAY = 273, /* U64IMAGE2DARRAY */
YYSYMBOL_I64IMAGECUBEARRAY = 274, /* I64IMAGECUBEARRAY */
YYSYMBOL_U64IMAGECUBEARRAY = 275, /* U64IMAGECUBEARRAY */
YYSYMBOL_I64IMAGE2DMS = 276, /* I64IMAGE2DMS */
YYSYMBOL_U64IMAGE2DMS = 277, /* U64IMAGE2DMS */
YYSYMBOL_I64IMAGE2DMSARRAY = 278, /* I64IMAGE2DMSARRAY */
YYSYMBOL_U64IMAGE2DMSARRAY = 279, /* U64IMAGE2DMSARRAY */
YYSYMBOL_TEXTURECUBEARRAY = 280, /* TEXTURECUBEARRAY */
YYSYMBOL_ITEXTURECUBEARRAY = 281, /* ITEXTURECUBEARRAY */
YYSYMBOL_UTEXTURECUBEARRAY = 282, /* UTEXTURECUBEARRAY */
YYSYMBOL_TEXTURE1D = 283, /* TEXTURE1D */
YYSYMBOL_ITEXTURE1D = 284, /* ITEXTURE1D */
YYSYMBOL_UTEXTURE1D = 285, /* UTEXTURE1D */
YYSYMBOL_TEXTURE1DARRAY = 286, /* TEXTURE1DARRAY */
YYSYMBOL_ITEXTURE1DARRAY = 287, /* ITEXTURE1DARRAY */
YYSYMBOL_UTEXTURE1DARRAY = 288, /* UTEXTURE1DARRAY */
YYSYMBOL_TEXTURE2DRECT = 289, /* TEXTURE2DRECT */
YYSYMBOL_ITEXTURE2DRECT = 290, /* ITEXTURE2DRECT */
YYSYMBOL_UTEXTURE2DRECT = 291, /* UTEXTURE2DRECT */
YYSYMBOL_TEXTUREBUFFER = 292, /* TEXTUREBUFFER */
YYSYMBOL_ITEXTUREBUFFER = 293, /* ITEXTUREBUFFER */
YYSYMBOL_UTEXTUREBUFFER = 294, /* UTEXTUREBUFFER */
YYSYMBOL_TEXTURE2DMS = 295, /* TEXTURE2DMS */
YYSYMBOL_ITEXTURE2DMS = 296, /* ITEXTURE2DMS */
YYSYMBOL_UTEXTURE2DMS = 297, /* UTEXTURE2DMS */
YYSYMBOL_TEXTURE2DMSARRAY = 298, /* TEXTURE2DMSARRAY */
YYSYMBOL_ITEXTURE2DMSARRAY = 299, /* ITEXTURE2DMSARRAY */
YYSYMBOL_UTEXTURE2DMSARRAY = 300, /* UTEXTURE2DMSARRAY */
YYSYMBOL_F16TEXTURE1D = 301, /* F16TEXTURE1D */
YYSYMBOL_F16TEXTURE2D = 302, /* F16TEXTURE2D */
YYSYMBOL_F16TEXTURE3D = 303, /* F16TEXTURE3D */
YYSYMBOL_F16TEXTURE2DRECT = 304, /* F16TEXTURE2DRECT */
YYSYMBOL_F16TEXTURECUBE = 305, /* F16TEXTURECUBE */
YYSYMBOL_F16TEXTURE1DARRAY = 306, /* F16TEXTURE1DARRAY */
YYSYMBOL_F16TEXTURE2DARRAY = 307, /* F16TEXTURE2DARRAY */
YYSYMBOL_F16TEXTURECUBEARRAY = 308, /* F16TEXTURECUBEARRAY */
YYSYMBOL_F16TEXTUREBUFFER = 309, /* F16TEXTUREBUFFER */
YYSYMBOL_F16TEXTURE2DMS = 310, /* F16TEXTURE2DMS */
YYSYMBOL_F16TEXTURE2DMSARRAY = 311, /* F16TEXTURE2DMSARRAY */
YYSYMBOL_SUBPASSINPUT = 312, /* SUBPASSINPUT */
YYSYMBOL_SUBPASSINPUTMS = 313, /* SUBPASSINPUTMS */
YYSYMBOL_ISUBPASSINPUT = 314, /* ISUBPASSINPUT */
YYSYMBOL_ISUBPASSINPUTMS = 315, /* ISUBPASSINPUTMS */
YYSYMBOL_USUBPASSINPUT = 316, /* USUBPASSINPUT */
YYSYMBOL_USUBPASSINPUTMS = 317, /* USUBPASSINPUTMS */
YYSYMBOL_F16SUBPASSINPUT = 318, /* F16SUBPASSINPUT */
YYSYMBOL_F16SUBPASSINPUTMS = 319, /* F16SUBPASSINPUTMS */
YYSYMBOL_SPIRV_INSTRUCTION = 320, /* SPIRV_INSTRUCTION */
YYSYMBOL_SPIRV_EXECUTION_MODE = 321, /* SPIRV_EXECUTION_MODE */
YYSYMBOL_SPIRV_EXECUTION_MODE_ID = 322, /* SPIRV_EXECUTION_MODE_ID */
YYSYMBOL_SPIRV_DECORATE = 323, /* SPIRV_DECORATE */
YYSYMBOL_SPIRV_DECORATE_ID = 324, /* SPIRV_DECORATE_ID */
YYSYMBOL_SPIRV_DECORATE_STRING = 325, /* SPIRV_DECORATE_STRING */
YYSYMBOL_SPIRV_TYPE = 326, /* SPIRV_TYPE */
YYSYMBOL_SPIRV_STORAGE_CLASS = 327, /* SPIRV_STORAGE_CLASS */
YYSYMBOL_SPIRV_BY_REFERENCE = 328, /* SPIRV_BY_REFERENCE */
YYSYMBOL_SPIRV_LITERAL = 329, /* SPIRV_LITERAL */
YYSYMBOL_ATTACHMENTEXT = 330, /* ATTACHMENTEXT */
YYSYMBOL_IATTACHMENTEXT = 331, /* IATTACHMENTEXT */
YYSYMBOL_UATTACHMENTEXT = 332, /* UATTACHMENTEXT */
YYSYMBOL_LEFT_OP = 333, /* LEFT_OP */
YYSYMBOL_RIGHT_OP = 334, /* RIGHT_OP */
YYSYMBOL_INC_OP = 335, /* INC_OP */
YYSYMBOL_DEC_OP = 336, /* DEC_OP */
YYSYMBOL_LE_OP = 337, /* LE_OP */
YYSYMBOL_GE_OP = 338, /* GE_OP */
YYSYMBOL_EQ_OP = 339, /* EQ_OP */
YYSYMBOL_NE_OP = 340, /* NE_OP */
YYSYMBOL_AND_OP = 341, /* AND_OP */
YYSYMBOL_OR_OP = 342, /* OR_OP */
YYSYMBOL_XOR_OP = 343, /* XOR_OP */
YYSYMBOL_MUL_ASSIGN = 344, /* MUL_ASSIGN */
YYSYMBOL_DIV_ASSIGN = 345, /* DIV_ASSIGN */
YYSYMBOL_ADD_ASSIGN = 346, /* ADD_ASSIGN */
YYSYMBOL_MOD_ASSIGN = 347, /* MOD_ASSIGN */
YYSYMBOL_LEFT_ASSIGN = 348, /* LEFT_ASSIGN */
YYSYMBOL_RIGHT_ASSIGN = 349, /* RIGHT_ASSIGN */
YYSYMBOL_AND_ASSIGN = 350, /* AND_ASSIGN */
YYSYMBOL_XOR_ASSIGN = 351, /* XOR_ASSIGN */
YYSYMBOL_OR_ASSIGN = 352, /* OR_ASSIGN */
YYSYMBOL_SUB_ASSIGN = 353, /* SUB_ASSIGN */
YYSYMBOL_STRING_LITERAL = 354, /* STRING_LITERAL */
YYSYMBOL_LEFT_PAREN = 355, /* LEFT_PAREN */
YYSYMBOL_RIGHT_PAREN = 356, /* RIGHT_PAREN */
YYSYMBOL_LEFT_BRACKET = 357, /* LEFT_BRACKET */
YYSYMBOL_RIGHT_BRACKET = 358, /* RIGHT_BRACKET */
YYSYMBOL_LEFT_BRACE = 359, /* LEFT_BRACE */
YYSYMBOL_RIGHT_BRACE = 360, /* RIGHT_BRACE */
YYSYMBOL_DOT = 361, /* DOT */
YYSYMBOL_COMMA = 362, /* COMMA */
YYSYMBOL_COLON = 363, /* COLON */
YYSYMBOL_EQUAL = 364, /* EQUAL */
YYSYMBOL_SEMICOLON = 365, /* SEMICOLON */
YYSYMBOL_BANG = 366, /* BANG */
YYSYMBOL_DASH = 367, /* DASH */
YYSYMBOL_TILDE = 368, /* TILDE */
YYSYMBOL_PLUS = 369, /* PLUS */
YYSYMBOL_STAR = 370, /* STAR */
YYSYMBOL_SLASH = 371, /* SLASH */
YYSYMBOL_PERCENT = 372, /* PERCENT */
YYSYMBOL_LEFT_ANGLE = 373, /* LEFT_ANGLE */
YYSYMBOL_RIGHT_ANGLE = 374, /* RIGHT_ANGLE */
YYSYMBOL_VERTICAL_BAR = 375, /* VERTICAL_BAR */
YYSYMBOL_CARET = 376, /* CARET */
YYSYMBOL_AMPERSAND = 377, /* AMPERSAND */
YYSYMBOL_QUESTION = 378, /* QUESTION */
YYSYMBOL_INVARIANT = 379, /* INVARIANT */
YYSYMBOL_HIGH_PRECISION = 380, /* HIGH_PRECISION */
YYSYMBOL_MEDIUM_PRECISION = 381, /* MEDIUM_PRECISION */
YYSYMBOL_LOW_PRECISION = 382, /* LOW_PRECISION */
YYSYMBOL_PRECISION = 383, /* PRECISION */
YYSYMBOL_PACKED = 384, /* PACKED */
YYSYMBOL_RESOURCE = 385, /* RESOURCE */
YYSYMBOL_SUPERP = 386, /* SUPERP */
YYSYMBOL_FLOATCONSTANT = 387, /* FLOATCONSTANT */
YYSYMBOL_INTCONSTANT = 388, /* INTCONSTANT */
YYSYMBOL_UINTCONSTANT = 389, /* UINTCONSTANT */
YYSYMBOL_BOOLCONSTANT = 390, /* BOOLCONSTANT */
YYSYMBOL_IDENTIFIER = 391, /* IDENTIFIER */
YYSYMBOL_TYPE_NAME = 392, /* TYPE_NAME */
YYSYMBOL_CENTROID = 393, /* CENTROID */
YYSYMBOL_IN = 394, /* IN */
YYSYMBOL_OUT = 395, /* OUT */
YYSYMBOL_INOUT = 396, /* INOUT */
YYSYMBOL_STRUCT = 397, /* STRUCT */
YYSYMBOL_VOID = 398, /* VOID */
YYSYMBOL_WHILE = 399, /* WHILE */
YYSYMBOL_BREAK = 400, /* BREAK */
YYSYMBOL_CONTINUE = 401, /* CONTINUE */
YYSYMBOL_DO = 402, /* DO */
YYSYMBOL_ELSE = 403, /* ELSE */
YYSYMBOL_FOR = 404, /* FOR */
YYSYMBOL_IF = 405, /* IF */
YYSYMBOL_DISCARD = 406, /* DISCARD */
YYSYMBOL_RETURN = 407, /* RETURN */
YYSYMBOL_SWITCH = 408, /* SWITCH */
YYSYMBOL_CASE = 409, /* CASE */
YYSYMBOL_DEFAULT = 410, /* DEFAULT */
YYSYMBOL_TERMINATE_INVOCATION = 411, /* TERMINATE_INVOCATION */
YYSYMBOL_TERMINATE_RAY = 412, /* TERMINATE_RAY */
YYSYMBOL_IGNORE_INTERSECTION = 413, /* IGNORE_INTERSECTION */
YYSYMBOL_UNIFORM = 414, /* UNIFORM */
YYSYMBOL_SHARED = 415, /* SHARED */
YYSYMBOL_BUFFER = 416, /* BUFFER */
YYSYMBOL_TILEIMAGEEXT = 417, /* TILEIMAGEEXT */
YYSYMBOL_FLAT = 418, /* FLAT */
YYSYMBOL_SMOOTH = 419, /* SMOOTH */
YYSYMBOL_LAYOUT = 420, /* LAYOUT */
YYSYMBOL_DOUBLECONSTANT = 421, /* DOUBLECONSTANT */
YYSYMBOL_INT16CONSTANT = 422, /* INT16CONSTANT */
YYSYMBOL_UINT16CONSTANT = 423, /* UINT16CONSTANT */
YYSYMBOL_FLOAT16CONSTANT = 424, /* FLOAT16CONSTANT */
YYSYMBOL_INT32CONSTANT = 425, /* INT32CONSTANT */
YYSYMBOL_UINT32CONSTANT = 426, /* UINT32CONSTANT */
YYSYMBOL_INT64CONSTANT = 427, /* INT64CONSTANT */
YYSYMBOL_UINT64CONSTANT = 428, /* UINT64CONSTANT */
YYSYMBOL_SUBROUTINE = 429, /* SUBROUTINE */
YYSYMBOL_DEMOTE = 430, /* DEMOTE */
YYSYMBOL_PAYLOADNV = 431, /* PAYLOADNV */
YYSYMBOL_PAYLOADINNV = 432, /* PAYLOADINNV */
YYSYMBOL_HITATTRNV = 433, /* HITATTRNV */
YYSYMBOL_CALLDATANV = 434, /* CALLDATANV */
YYSYMBOL_CALLDATAINNV = 435, /* CALLDATAINNV */
YYSYMBOL_PAYLOADEXT = 436, /* PAYLOADEXT */
YYSYMBOL_PAYLOADINEXT = 437, /* PAYLOADINEXT */
YYSYMBOL_HITATTREXT = 438, /* HITATTREXT */
YYSYMBOL_CALLDATAEXT = 439, /* CALLDATAEXT */
YYSYMBOL_CALLDATAINEXT = 440, /* CALLDATAINEXT */
YYSYMBOL_PATCH = 441, /* PATCH */
YYSYMBOL_SAMPLE = 442, /* SAMPLE */
YYSYMBOL_NONUNIFORM = 443, /* NONUNIFORM */
YYSYMBOL_COHERENT = 444, /* COHERENT */
YYSYMBOL_VOLATILE = 445, /* VOLATILE */
YYSYMBOL_RESTRICT = 446, /* RESTRICT */
YYSYMBOL_READONLY = 447, /* READONLY */
YYSYMBOL_WRITEONLY = 448, /* WRITEONLY */
YYSYMBOL_DEVICECOHERENT = 449, /* DEVICECOHERENT */
YYSYMBOL_QUEUEFAMILYCOHERENT = 450, /* QUEUEFAMILYCOHERENT */
YYSYMBOL_WORKGROUPCOHERENT = 451, /* WORKGROUPCOHERENT */
YYSYMBOL_SUBGROUPCOHERENT = 452, /* SUBGROUPCOHERENT */
YYSYMBOL_NONPRIVATE = 453, /* NONPRIVATE */
YYSYMBOL_SHADERCALLCOHERENT = 454, /* SHADERCALLCOHERENT */
YYSYMBOL_NOPERSPECTIVE = 455, /* NOPERSPECTIVE */
YYSYMBOL_EXPLICITINTERPAMD = 456, /* EXPLICITINTERPAMD */
YYSYMBOL_PERVERTEXEXT = 457, /* PERVERTEXEXT */
YYSYMBOL_PERVERTEXNV = 458, /* PERVERTEXNV */
YYSYMBOL_PERPRIMITIVENV = 459, /* PERPRIMITIVENV */
YYSYMBOL_PERVIEWNV = 460, /* PERVIEWNV */
YYSYMBOL_PERTASKNV = 461, /* PERTASKNV */
YYSYMBOL_PERPRIMITIVEEXT = 462, /* PERPRIMITIVEEXT */
YYSYMBOL_TASKPAYLOADWORKGROUPEXT = 463, /* TASKPAYLOADWORKGROUPEXT */
YYSYMBOL_PRECISE = 464, /* PRECISE */
YYSYMBOL_YYACCEPT = 465, /* $accept */
YYSYMBOL_variable_identifier = 466, /* variable_identifier */
YYSYMBOL_primary_expression = 467, /* primary_expression */
YYSYMBOL_postfix_expression = 468, /* postfix_expression */
YYSYMBOL_integer_expression = 469, /* integer_expression */
YYSYMBOL_function_call = 470, /* function_call */
YYSYMBOL_function_call_or_method = 471, /* function_call_or_method */
YYSYMBOL_function_call_generic = 472, /* function_call_generic */
YYSYMBOL_function_call_header_no_parameters = 473, /* function_call_header_no_parameters */
YYSYMBOL_function_call_header_with_parameters = 474, /* function_call_header_with_parameters */
YYSYMBOL_function_call_header = 475, /* function_call_header */
YYSYMBOL_function_identifier = 476, /* function_identifier */
YYSYMBOL_unary_expression = 477, /* unary_expression */
YYSYMBOL_unary_operator = 478, /* unary_operator */
YYSYMBOL_multiplicative_expression = 479, /* multiplicative_expression */
YYSYMBOL_additive_expression = 480, /* additive_expression */
YYSYMBOL_shift_expression = 481, /* shift_expression */
YYSYMBOL_relational_expression = 482, /* relational_expression */
YYSYMBOL_equality_expression = 483, /* equality_expression */
YYSYMBOL_and_expression = 484, /* and_expression */
YYSYMBOL_exclusive_or_expression = 485, /* exclusive_or_expression */
YYSYMBOL_inclusive_or_expression = 486, /* inclusive_or_expression */
YYSYMBOL_logical_and_expression = 487, /* logical_and_expression */
YYSYMBOL_logical_xor_expression = 488, /* logical_xor_expression */
YYSYMBOL_logical_or_expression = 489, /* logical_or_expression */
YYSYMBOL_conditional_expression = 490, /* conditional_expression */
YYSYMBOL_491_1 = 491, /* $@1 */
YYSYMBOL_assignment_expression = 492, /* assignment_expression */
YYSYMBOL_assignment_operator = 493, /* assignment_operator */
YYSYMBOL_expression = 494, /* expression */
YYSYMBOL_constant_expression = 495, /* constant_expression */
YYSYMBOL_declaration = 496, /* declaration */
YYSYMBOL_block_structure = 497, /* block_structure */
YYSYMBOL_498_2 = 498, /* $@2 */
YYSYMBOL_identifier_list = 499, /* identifier_list */
YYSYMBOL_function_prototype = 500, /* function_prototype */
YYSYMBOL_function_declarator = 501, /* function_declarator */
YYSYMBOL_function_header_with_parameters = 502, /* function_header_with_parameters */
YYSYMBOL_function_header = 503, /* function_header */
YYSYMBOL_parameter_declarator = 504, /* parameter_declarator */
YYSYMBOL_parameter_declaration = 505, /* parameter_declaration */
YYSYMBOL_parameter_type_specifier = 506, /* parameter_type_specifier */
YYSYMBOL_init_declarator_list = 507, /* init_declarator_list */
YYSYMBOL_single_declaration = 508, /* single_declaration */
YYSYMBOL_fully_specified_type = 509, /* fully_specified_type */
YYSYMBOL_invariant_qualifier = 510, /* invariant_qualifier */
YYSYMBOL_interpolation_qualifier = 511, /* interpolation_qualifier */
YYSYMBOL_layout_qualifier = 512, /* layout_qualifier */
YYSYMBOL_layout_qualifier_id_list = 513, /* layout_qualifier_id_list */
YYSYMBOL_layout_qualifier_id = 514, /* layout_qualifier_id */
YYSYMBOL_precise_qualifier = 515, /* precise_qualifier */
YYSYMBOL_type_qualifier = 516, /* type_qualifier */
YYSYMBOL_single_type_qualifier = 517, /* single_type_qualifier */
YYSYMBOL_storage_qualifier = 518, /* storage_qualifier */
YYSYMBOL_non_uniform_qualifier = 519, /* non_uniform_qualifier */
YYSYMBOL_type_name_list = 520, /* type_name_list */
YYSYMBOL_type_specifier = 521, /* type_specifier */
YYSYMBOL_array_specifier = 522, /* array_specifier */
YYSYMBOL_type_parameter_specifier_opt = 523, /* type_parameter_specifier_opt */
YYSYMBOL_type_parameter_specifier = 524, /* type_parameter_specifier */
YYSYMBOL_type_parameter_specifier_list = 525, /* type_parameter_specifier_list */
YYSYMBOL_type_specifier_nonarray = 526, /* type_specifier_nonarray */
YYSYMBOL_precision_qualifier = 527, /* precision_qualifier */
YYSYMBOL_struct_specifier = 528, /* struct_specifier */
YYSYMBOL_529_3 = 529, /* $@3 */
YYSYMBOL_530_4 = 530, /* $@4 */
YYSYMBOL_struct_declaration_list = 531, /* struct_declaration_list */
YYSYMBOL_struct_declaration = 532, /* struct_declaration */
YYSYMBOL_struct_declarator_list = 533, /* struct_declarator_list */
YYSYMBOL_struct_declarator = 534, /* struct_declarator */
YYSYMBOL_initializer = 535, /* initializer */
YYSYMBOL_initializer_list = 536, /* initializer_list */
YYSYMBOL_declaration_statement = 537, /* declaration_statement */
YYSYMBOL_statement = 538, /* statement */
YYSYMBOL_simple_statement = 539, /* simple_statement */
YYSYMBOL_demote_statement = 540, /* demote_statement */
YYSYMBOL_compound_statement = 541, /* compound_statement */
YYSYMBOL_542_5 = 542, /* $@5 */
YYSYMBOL_543_6 = 543, /* $@6 */
YYSYMBOL_statement_no_new_scope = 544, /* statement_no_new_scope */
YYSYMBOL_statement_scoped = 545, /* statement_scoped */
YYSYMBOL_546_7 = 546, /* $@7 */
YYSYMBOL_547_8 = 547, /* $@8 */
YYSYMBOL_compound_statement_no_new_scope = 548, /* compound_statement_no_new_scope */
YYSYMBOL_statement_list = 549, /* statement_list */
YYSYMBOL_expression_statement = 550, /* expression_statement */
YYSYMBOL_selection_statement = 551, /* selection_statement */
YYSYMBOL_selection_statement_nonattributed = 552, /* selection_statement_nonattributed */
YYSYMBOL_selection_rest_statement = 553, /* selection_rest_statement */
YYSYMBOL_condition = 554, /* condition */
YYSYMBOL_switch_statement = 555, /* switch_statement */
YYSYMBOL_switch_statement_nonattributed = 556, /* switch_statement_nonattributed */
YYSYMBOL_557_9 = 557, /* $@9 */
YYSYMBOL_switch_statement_list = 558, /* switch_statement_list */
YYSYMBOL_case_label = 559, /* case_label */
YYSYMBOL_iteration_statement = 560, /* iteration_statement */
YYSYMBOL_iteration_statement_nonattributed = 561, /* iteration_statement_nonattributed */
YYSYMBOL_562_10 = 562, /* $@10 */
YYSYMBOL_563_11 = 563, /* $@11 */
YYSYMBOL_564_12 = 564, /* $@12 */
YYSYMBOL_for_init_statement = 565, /* for_init_statement */
YYSYMBOL_conditionopt = 566, /* conditionopt */
YYSYMBOL_for_rest_statement = 567, /* for_rest_statement */
YYSYMBOL_jump_statement = 568, /* jump_statement */
YYSYMBOL_translation_unit = 569, /* translation_unit */
YYSYMBOL_external_declaration = 570, /* external_declaration */
YYSYMBOL_function_definition = 571, /* function_definition */
YYSYMBOL_572_13 = 572, /* $@13 */
YYSYMBOL_attribute = 573, /* attribute */
YYSYMBOL_attribute_list = 574, /* attribute_list */
YYSYMBOL_single_attribute = 575, /* single_attribute */
YYSYMBOL_spirv_requirements_list = 576, /* spirv_requirements_list */
YYSYMBOL_spirv_requirements_parameter = 577, /* spirv_requirements_parameter */
YYSYMBOL_spirv_extension_list = 578, /* spirv_extension_list */
YYSYMBOL_spirv_capability_list = 579, /* spirv_capability_list */
YYSYMBOL_spirv_execution_mode_qualifier = 580, /* spirv_execution_mode_qualifier */
YYSYMBOL_spirv_execution_mode_parameter_list = 581, /* spirv_execution_mode_parameter_list */
YYSYMBOL_spirv_execution_mode_parameter = 582, /* spirv_execution_mode_parameter */
YYSYMBOL_spirv_execution_mode_id_parameter_list = 583, /* spirv_execution_mode_id_parameter_list */
YYSYMBOL_spirv_storage_class_qualifier = 584, /* spirv_storage_class_qualifier */
YYSYMBOL_spirv_decorate_qualifier = 585, /* spirv_decorate_qualifier */
YYSYMBOL_spirv_decorate_parameter_list = 586, /* spirv_decorate_parameter_list */
YYSYMBOL_spirv_decorate_parameter = 587, /* spirv_decorate_parameter */
YYSYMBOL_spirv_decorate_id_parameter_list = 588, /* spirv_decorate_id_parameter_list */
YYSYMBOL_spirv_decorate_id_parameter = 589, /* spirv_decorate_id_parameter */
YYSYMBOL_spirv_decorate_string_parameter_list = 590, /* spirv_decorate_string_parameter_list */
YYSYMBOL_spirv_type_specifier = 591, /* spirv_type_specifier */
YYSYMBOL_spirv_type_parameter_list = 592, /* spirv_type_parameter_list */
YYSYMBOL_spirv_type_parameter = 593, /* spirv_type_parameter */
YYSYMBOL_spirv_instruction_qualifier = 594, /* spirv_instruction_qualifier */
YYSYMBOL_spirv_instruction_qualifier_list = 595, /* spirv_instruction_qualifier_list */
YYSYMBOL_spirv_instruction_qualifier_id = 596 /* spirv_instruction_qualifier_id */
};
typedef enum yysymbol_kind_t yysymbol_kind_t;
/* Second part of user prologue. */
#line 111 "MachineIndependent/glslang.y"
#define parseContext (*pParseContext)
#define yyerror(context, msg) context->parserError(msg)
extern int yylex(YYSTYPE*, TParseContext&);
#line 736 "MachineIndependent/glslang_tab.cpp"
#ifdef short
# undef short
#endif
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
<limits.h> and (if available) <stdint.h> are included
so that the code can choose integer types of a good width. */
#ifndef __PTRDIFF_MAX__
# include <limits.h> /* INFRINGES ON USER NAME SPACE */
# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stdint.h> /* INFRINGES ON USER NAME SPACE */
# define YY_STDINT_H
# endif
#endif
/* Narrow types that promote to a signed type and that can represent a
signed or unsigned integer of at least N bits. In tables they can
save space and decrease cache pressure. Promoting to a signed type
helps avoid bugs in integer arithmetic. */
#ifdef __INT_LEAST8_MAX__
typedef __INT_LEAST8_TYPE__ yytype_int8;
#elif defined YY_STDINT_H
typedef int_least8_t yytype_int8;
#else
typedef signed char yytype_int8;
#endif
#ifdef __INT_LEAST16_MAX__
typedef __INT_LEAST16_TYPE__ yytype_int16;
#elif defined YY_STDINT_H
typedef int_least16_t yytype_int16;
#else
typedef short yytype_int16;
#endif
/* Work around bug in HP-UX 11.23, which defines these macros
incorrectly for preprocessor constants. This workaround can likely
be removed in 2023, as HPE has promised support for HP-UX 11.23
(aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
<https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
#ifdef __hpux
# undef UINT_LEAST8_MAX
# undef UINT_LEAST16_MAX
# define UINT_LEAST8_MAX 255
# define UINT_LEAST16_MAX 65535
#endif
#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
&& UINT_LEAST8_MAX <= INT_MAX)
typedef uint_least8_t yytype_uint8;
#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
typedef unsigned char yytype_uint8;
#else
typedef short yytype_uint8;
#endif
#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
typedef __UINT_LEAST16_TYPE__ yytype_uint16;
#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
&& UINT_LEAST16_MAX <= INT_MAX)
typedef uint_least16_t yytype_uint16;
#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
typedef unsigned short yytype_uint16;
#else
typedef int yytype_uint16;
#endif
#ifndef YYPTRDIFF_T
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
# define YYPTRDIFF_T __PTRDIFF_TYPE__
# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
# elif defined PTRDIFF_MAX
# ifndef ptrdiff_t
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# endif
# define YYPTRDIFF_T ptrdiff_t
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else
# define YYPTRDIFF_T long
# define YYPTRDIFF_MAXIMUM LONG_MAX
# endif
#endif
#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned
# endif
#endif
#define YYSIZE_MAXIMUM \
YY_CAST (YYPTRDIFF_T, \
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
? YYPTRDIFF_MAXIMUM \
: YY_CAST (YYSIZE_T, -1)))
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
/* Stored state numbers (used for stacks). */
typedef yytype_int16 yy_state_t;
/* State numbers in computations. */
typedef int yy_state_fast_t;
#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
# endif
# endif
# ifndef YY_
# define YY_(Msgid) Msgid
# endif
#endif
#ifndef YY_ATTRIBUTE_PURE
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
# else
# define YY_ATTRIBUTE_PURE
# endif
#endif
#ifndef YY_ATTRIBUTE_UNUSED
# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
# else
# define YY_ATTRIBUTE_UNUSED
# endif
#endif
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
# define YY_USE(E) ((void) (E))
#else
# define YY_USE(E) /* empty */
#endif
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
# if __GNUC__ * 100 + __GNUC_MINOR__ < 407
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
# else
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# endif
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop")
#else
# define YY_INITIAL_VALUE(Value) Value
#endif
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
#endif
#ifndef YY_INITIAL_VALUE
# define YY_INITIAL_VALUE(Value) /* Nothing. */
#endif
#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
# define YY_IGNORE_USELESS_CAST_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
# define YY_IGNORE_USELESS_CAST_END \
_Pragma ("GCC diagnostic pop")
#endif
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_END
#endif
#define YY_ASSERT(E) ((void) (0 && (E)))
#if 1
/* The parser invokes alloca or malloc; define the necessary symbols. */
# ifdef YYSTACK_USE_ALLOCA
# if YYSTACK_USE_ALLOCA
# ifdef __GNUC__
# define YYSTACK_ALLOC __builtin_alloca
# elif defined __BUILTIN_VA_ARG_INCR
# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
# elif defined _AIX
# define YYSTACK_ALLOC __alloca
# elif defined _MSC_VER
# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
# define alloca _alloca
# else
# define YYSTACK_ALLOC alloca
# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
/* Use EXIT_SUCCESS as a witness for stdlib.h. */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# endif
# endif
# endif
# ifdef YYSTACK_ALLOC
/* Pacify GCC's 'empty if-body' warning. */
# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
# ifndef YYSTACK_ALLOC_MAXIMUM
/* The OS might guarantee only one guard page at the bottom of the stack,
and a page size can be as small as 4096 bytes. So we cannot safely
invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
to allow for a few compiler-allocated temporary stack slots. */
# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
# endif
# else
# define YYSTACK_ALLOC YYMALLOC
# define YYSTACK_FREE YYFREE
# ifndef YYSTACK_ALLOC_MAXIMUM
# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
# endif
# if (defined __cplusplus && ! defined EXIT_SUCCESS \
&& ! ((defined YYMALLOC || defined malloc) \
&& (defined YYFREE || defined free)))
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# ifndef YYMALLOC
# define YYMALLOC malloc
# if ! defined malloc && ! defined EXIT_SUCCESS
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# ifndef YYFREE
# define YYFREE free
# if ! defined free && ! defined EXIT_SUCCESS
void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# endif
#endif /* 1 */
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
union yyalloc
{
yy_state_t yyss_alloc;
YYSTYPE yyvs_alloc;
};
/* The size of the maximum gap between one aligned stack and the next. */
# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
/* The size of an array large to enough to hold all stacks, each with
N elements. */
# define YYSTACK_BYTES(N) \
((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
+ YYSTACK_GAP_MAXIMUM)
# define YYCOPY_NEEDED 1
/* Relocate STACK from its old location to the new one. The
local variables YYSIZE and YYSTACKSIZE give the old and new number of
elements in the stack, and YYPTR gives the new location of the
stack. Advance YYPTR to a properly aligned location for the next
stack. */
# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
do \
{ \
YYPTRDIFF_T yynewbytes; \
YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
Stack = &yyptr->Stack_alloc; \
yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
yyptr += yynewbytes / YYSIZEOF (*yyptr); \
} \
while (0)
#endif
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
/* Copy COUNT objects from SRC to DST. The source and destination do
not overlap. */
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(Dst, Src, Count) \
__builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
# else
# define YYCOPY(Dst, Src, Count) \
do \
{ \
YYPTRDIFF_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(Dst)[yyi] = (Src)[yyi]; \
} \
while (0)
# endif
# endif
#endif /* !YYCOPY_NEEDED */
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 452
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 12701
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 465
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 132
/* YYNRULES -- Number of rules. */
#define YYNRULES 700
/* YYNSTATES -- Number of states. */
#define YYNSTATES 946
/* YYMAXUTOK -- Last valid token kind. */
#define YYMAXUTOK 719
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
as returned by yylex, with out-of-bounds checking. */
#define YYTRANSLATE(YYX) \
(0 <= (YYX) && (YYX) <= YYMAXUTOK \
? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
: YYSYMBOL_YYUNDEF)
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
as returned by yylex. */
static const yytype_int16 yytranslate[] =
{
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
395, 396, 397, 398, 399, 400, 401, 402, 403, 404,
405, 406, 407, 408, 409, 410, 411, 412, 413, 414,
415, 416, 417, 418, 419, 420, 421, 422, 423, 424,
425, 426, 427, 428, 429, 430, 431, 432, 433, 434,
435, 436, 437, 438, 439, 440, 441, 442, 443, 444,
445, 446, 447, 448, 449, 450, 451, 452, 453, 454,
455, 456, 457, 458, 459, 460, 461, 462, 463, 464
};
#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_int16 yyrline[] =
{
0, 355, 355, 361, 364, 369, 372, 375, 379, 382,
385, 389, 393, 397, 401, 405, 409, 415, 422, 425,
428, 431, 434, 439, 447, 454, 461, 467, 471, 478,
481, 487, 505, 530, 538, 543, 570, 578, 584, 588,
592, 612, 613, 614, 615, 621, 622, 627, 632, 641,
642, 647, 655, 656, 662, 671, 672, 677, 682, 687,
695, 696, 705, 717, 718, 727, 728, 737, 738, 747,
748, 756, 757, 765, 766, 774, 775, 775, 793, 794,
810, 814, 818, 822, 827, 831, 835, 839, 843, 847,
851, 858, 861, 872, 879, 884, 891, 896, 901, 908,
912, 916, 920, 925, 930, 939, 939, 950, 954, 961,
966, 974, 982, 994, 997, 1004, 1017, 1040, 1063, 1078,
1103, 1114, 1124, 1134, 1144, 1153, 1156, 1160, 1164, 1169,
1177, 1182, 1187, 1192, 1197, 1206, 1216, 1243, 1252, 1259,
1266, 1273, 1280, 1288, 1296, 1306, 1316, 1323, 1333, 1339,
1342, 1349, 1353, 1357, 1365, 1374, 1377, 1388, 1391, 1394,
1398, 1402, 1406, 1410, 1413, 1418, 1422, 1427, 1435, 1439,
1444, 1450, 1456, 1463, 1468, 1473, 1481, 1486, 1498, 1512,
1518, 1523, 1531, 1539, 1547, 1555, 1563, 1571, 1579, 1587,
1595, 1602, 1609, 1613, 1618, 1623, 1628, 1633, 1638, 1643,
1647, 1651, 1655, 1659, 1665, 1671, 1681, 1688, 1691, 1699,
1706, 1717, 1722, 1730, 1734, 1744, 1747, 1753, 1759, 1765,
1773, 1783, 1787, 1791, 1795, 1800, 1804, 1809, 1814, 1819,
1824, 1829, 1834, 1839, 1844, 1849, 1855, 1861, 1867, 1872,
1877, 1882, 1887, 1892, 1897, 1902, 1907, 1912, 1917, 1922,
1927, 1934, 1939, 1944, 1949, 1954, 1959, 1964, 1969, 1974,
1979, 1984, 1989, 1997, 2005, 2013, 2019, 2025, 2031, 2037,
2043, 2049, 2055, 2061, 2067, 2073, 2079, 2085, 2091, 2097,
2103, 2109, 2115, 2121, 2127, 2133, 2139, 2145, 2151, 2157,
2163, 2169, 2175, 2181, 2187, 2193, 2199, 2205, 2211, 2219,
2227, 2235, 2243, 2251, 2259, 2267, 2275, 2283, 2291, 2299,
2307, 2313, 2319, 2325, 2331, 2337, 2343, 2349, 2355, 2361,
2367, 2373, 2379, 2385, 2391, 2397, 2403, 2409, 2415, 2421,
2427, 2433, 2439, 2445, 2451, 2457, 2463, 2469, 2475, 2481,
2487, 2493, 2499, 2505, 2511, 2517, 2523, 2527, 2531, 2535,
2540, 2545, 2550, 2555, 2560, 2565, 2570, 2575, 2580, 2585,
2590, 2595, 2600, 2605, 2611, 2617, 2623, 2629, 2635, 2641,
2647, 2653, 2659, 2665, 2671, 2677, 2683, 2688, 2693, 2698,
2703, 2708, 2713, 2718, 2723, 2728, 2733, 2738, 2743, 2748,
2753, 2758, 2763, 2768, 2773, 2778, 2783, 2788, 2793, 2798,
2803, 2808, 2813, 2818, 2823, 2828, 2833, 2838, 2843, 2848,
2854, 2860, 2865, 2870, 2875, 2881, 2886, 2891, 2896, 2902,
2907, 2912, 2917, 2923, 2928, 2933, 2938, 2944, 2950, 2956,
2962, 2967, 2973, 2979, 2985, 2990, 2995, 3000, 3005, 3010,
3016, 3021, 3026, 3031, 3037, 3042, 3047, 3052, 3058, 3063,
3068, 3073, 3079, 3084, 3089, 3094, 3100, 3105, 3110, 3115,
3121, 3126, 3131, 3136, 3142, 3147, 3152, 3157, 3163, 3168,
3173, 3178, 3184, 3189, 3194, 3199, 3205, 3210, 3215, 3220,
3226, 3231, 3236, 3241, 3247, 3252, 3257, 3262, 3268, 3273,
3278, 3283, 3289, 3294, 3299, 3304, 3310, 3315, 3320, 3325,
3330, 3335, 3340, 3345, 3350, 3355, 3360, 3365, 3370, 3375,
3380, 3385, 3390, 3395, 3400, 3405, 3410, 3415, 3420, 3425,
3430, 3436, 3442, 3448, 3454, 3460, 3466, 3472, 3479, 3486,
3492, 3498, 3504, 3510, 3517, 3524, 3531, 3538, 3542, 3546,
3551, 3567, 3572, 3577, 3585, 3585, 3602, 3602, 3612, 3615,
3628, 3650, 3677, 3681, 3687, 3692, 3703, 3706, 3712, 3718,
3727, 3730, 3736, 3740, 3741, 3747, 3748, 3749, 3750, 3751,
3752, 3753, 3754, 3758, 3766, 3767, 3771, 3767, 3783, 3784,
3788, 3788, 3795, 3795, 3809, 3812, 3820, 3828, 3839, 3840,
3844, 3847, 3854, 3861, 3865, 3873, 3877, 3890, 3893, 3900,
3900, 3920, 3923, 3929, 3941, 3953, 3956, 3964, 3964, 3979,
3979, 3997, 3997, 4018, 4021, 4027, 4030, 4036, 4040, 4047,
4052, 4057, 4064, 4067, 4071, 4075, 4079, 4088, 4092, 4101,
4104, 4107, 4115, 4115, 4157, 4162, 4165, 4170, 4173, 4178,
4181, 4186, 4189, 4194, 4197, 4202, 4205, 4210, 4214, 4219,
4223, 4228, 4232, 4239, 4242, 4247, 4250, 4253, 4256, 4259,
4264, 4273, 4284, 4289, 4297, 4301, 4306, 4310, 4315, 4319,
4324, 4328, 4335, 4338, 4343, 4346, 4349, 4352, 4357, 4360,
4365, 4371, 4374, 4377, 4380, 4385, 4389, 4394, 4398, 4403,
4407, 4414, 4417, 4422, 4425, 4430, 4433, 4439, 4442, 4447,
4450
};
#endif
/** Accessing symbol of state STATE. */
#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
#if 1
/* The user-facing name of the symbol whose (internal) number is
YYSYMBOL. No bounds checking. */
static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
"\"end of file\"", "error", "\"invalid token\"", "CONST", "BOOL", "INT",
"UINT", "FLOAT", "BVEC2", "BVEC3", "BVEC4", "IVEC2", "IVEC3", "IVEC4",
"UVEC2", "UVEC3", "UVEC4", "VEC2", "VEC3", "VEC4", "MAT2", "MAT3",
"MAT4", "MAT2X2", "MAT2X3", "MAT2X4", "MAT3X2", "MAT3X3", "MAT3X4",
"MAT4X2", "MAT4X3", "MAT4X4", "SAMPLER2D", "SAMPLER3D", "SAMPLERCUBE",
"SAMPLER2DSHADOW", "SAMPLERCUBESHADOW", "SAMPLER2DARRAY",
"SAMPLER2DARRAYSHADOW", "ISAMPLER2D", "ISAMPLER3D", "ISAMPLERCUBE",
"ISAMPLER2DARRAY", "USAMPLER2D", "USAMPLER3D", "USAMPLERCUBE",
"USAMPLER2DARRAY", "SAMPLER", "SAMPLERSHADOW", "TEXTURE2D", "TEXTURE3D",
"TEXTURECUBE", "TEXTURE2DARRAY", "ITEXTURE2D", "ITEXTURE3D",
"ITEXTURECUBE", "ITEXTURE2DARRAY", "UTEXTURE2D", "UTEXTURE3D",
"UTEXTURECUBE", "UTEXTURE2DARRAY", "ATTRIBUTE", "VARYING", "FLOAT16_T",
"FLOAT32_T", "DOUBLE", "FLOAT64_T", "INT64_T", "UINT64_T", "INT32_T",
"UINT32_T", "INT16_T", "UINT16_T", "INT8_T", "UINT8_T", "I64VEC2",
"I64VEC3", "I64VEC4", "U64VEC2", "U64VEC3", "U64VEC4", "I32VEC2",
"I32VEC3", "I32VEC4", "U32VEC2", "U32VEC3", "U32VEC4", "I16VEC2",
"I16VEC3", "I16VEC4", "U16VEC2", "U16VEC3", "U16VEC4", "I8VEC2",
"I8VEC3", "I8VEC4", "U8VEC2", "U8VEC3", "U8VEC4", "DVEC2", "DVEC3",
"DVEC4", "DMAT2", "DMAT3", "DMAT4", "F16VEC2", "F16VEC3", "F16VEC4",
"F16MAT2", "F16MAT3", "F16MAT4", "F32VEC2", "F32VEC3", "F32VEC4",
"F32MAT2", "F32MAT3", "F32MAT4", "F64VEC2", "F64VEC3", "F64VEC4",
"F64MAT2", "F64MAT3", "F64MAT4", "DMAT2X2", "DMAT2X3", "DMAT2X4",
"DMAT3X2", "DMAT3X3", "DMAT3X4", "DMAT4X2", "DMAT4X3", "DMAT4X4",
"F16MAT2X2", "F16MAT2X3", "F16MAT2X4", "F16MAT3X2", "F16MAT3X3",
"F16MAT3X4", "F16MAT4X2", "F16MAT4X3", "F16MAT4X4", "F32MAT2X2",
"F32MAT2X3", "F32MAT2X4", "F32MAT3X2", "F32MAT3X3", "F32MAT3X4",
"F32MAT4X2", "F32MAT4X3", "F32MAT4X4", "F64MAT2X2", "F64MAT2X3",
"F64MAT2X4", "F64MAT3X2", "F64MAT3X3", "F64MAT3X4", "F64MAT4X2",
"F64MAT4X3", "F64MAT4X4", "ATOMIC_UINT", "ACCSTRUCTNV", "ACCSTRUCTEXT",
"RAYQUERYEXT", "FCOOPMATNV", "ICOOPMATNV", "UCOOPMATNV", "COOPMAT",
"HITOBJECTNV", "HITOBJECTATTRNV", "SAMPLERCUBEARRAY",
"SAMPLERCUBEARRAYSHADOW", "ISAMPLERCUBEARRAY", "USAMPLERCUBEARRAY",
"SAMPLER1D", "SAMPLER1DARRAY", "SAMPLER1DARRAYSHADOW", "ISAMPLER1D",
"SAMPLER1DSHADOW", "SAMPLER2DRECT", "SAMPLER2DRECTSHADOW",
"ISAMPLER2DRECT", "USAMPLER2DRECT", "SAMPLERBUFFER", "ISAMPLERBUFFER",
"USAMPLERBUFFER", "SAMPLER2DMS", "ISAMPLER2DMS", "USAMPLER2DMS",
"SAMPLER2DMSARRAY", "ISAMPLER2DMSARRAY", "USAMPLER2DMSARRAY",
"SAMPLEREXTERNALOES", "SAMPLEREXTERNAL2DY2YEXT", "ISAMPLER1DARRAY",
"USAMPLER1D", "USAMPLER1DARRAY", "F16SAMPLER1D", "F16SAMPLER2D",
"F16SAMPLER3D", "F16SAMPLER2DRECT", "F16SAMPLERCUBE",
"F16SAMPLER1DARRAY", "F16SAMPLER2DARRAY", "F16SAMPLERCUBEARRAY",
"F16SAMPLERBUFFER", "F16SAMPLER2DMS", "F16SAMPLER2DMSARRAY",
"F16SAMPLER1DSHADOW", "F16SAMPLER2DSHADOW", "F16SAMPLER1DARRAYSHADOW",
"F16SAMPLER2DARRAYSHADOW", "F16SAMPLER2DRECTSHADOW",
"F16SAMPLERCUBESHADOW", "F16SAMPLERCUBEARRAYSHADOW", "IMAGE1D",
"IIMAGE1D", "UIMAGE1D", "IMAGE2D", "IIMAGE2D", "UIMAGE2D", "IMAGE3D",
"IIMAGE3D", "UIMAGE3D", "IMAGE2DRECT", "IIMAGE2DRECT", "UIMAGE2DRECT",
"IMAGECUBE", "IIMAGECUBE", "UIMAGECUBE", "IMAGEBUFFER", "IIMAGEBUFFER",
"UIMAGEBUFFER", "IMAGE1DARRAY", "IIMAGE1DARRAY", "UIMAGE1DARRAY",
"IMAGE2DARRAY", "IIMAGE2DARRAY", "UIMAGE2DARRAY", "IMAGECUBEARRAY",
"IIMAGECUBEARRAY", "UIMAGECUBEARRAY", "IMAGE2DMS", "IIMAGE2DMS",
"UIMAGE2DMS", "IMAGE2DMSARRAY", "IIMAGE2DMSARRAY", "UIMAGE2DMSARRAY",
"F16IMAGE1D", "F16IMAGE2D", "F16IMAGE3D", "F16IMAGE2DRECT",
"F16IMAGECUBE", "F16IMAGE1DARRAY", "F16IMAGE2DARRAY",
"F16IMAGECUBEARRAY", "F16IMAGEBUFFER", "F16IMAGE2DMS",
"F16IMAGE2DMSARRAY", "I64IMAGE1D", "U64IMAGE1D", "I64IMAGE2D",
"U64IMAGE2D", "I64IMAGE3D", "U64IMAGE3D", "I64IMAGE2DRECT",
"U64IMAGE2DRECT", "I64IMAGECUBE", "U64IMAGECUBE", "I64IMAGEBUFFER",
"U64IMAGEBUFFER", "I64IMAGE1DARRAY", "U64IMAGE1DARRAY",
"I64IMAGE2DARRAY", "U64IMAGE2DARRAY", "I64IMAGECUBEARRAY",
"U64IMAGECUBEARRAY", "I64IMAGE2DMS", "U64IMAGE2DMS", "I64IMAGE2DMSARRAY",
"U64IMAGE2DMSARRAY", "TEXTURECUBEARRAY", "ITEXTURECUBEARRAY",
"UTEXTURECUBEARRAY", "TEXTURE1D", "ITEXTURE1D", "UTEXTURE1D",
"TEXTURE1DARRAY", "ITEXTURE1DARRAY", "UTEXTURE1DARRAY", "TEXTURE2DRECT",
"ITEXTURE2DRECT", "UTEXTURE2DRECT", "TEXTUREBUFFER", "ITEXTUREBUFFER",
"UTEXTUREBUFFER", "TEXTURE2DMS", "ITEXTURE2DMS", "UTEXTURE2DMS",
"TEXTURE2DMSARRAY", "ITEXTURE2DMSARRAY", "UTEXTURE2DMSARRAY",
"F16TEXTURE1D", "F16TEXTURE2D", "F16TEXTURE3D", "F16TEXTURE2DRECT",
"F16TEXTURECUBE", "F16TEXTURE1DARRAY", "F16TEXTURE2DARRAY",
"F16TEXTURECUBEARRAY", "F16TEXTUREBUFFER", "F16TEXTURE2DMS",
"F16TEXTURE2DMSARRAY", "SUBPASSINPUT", "SUBPASSINPUTMS", "ISUBPASSINPUT",
"ISUBPASSINPUTMS", "USUBPASSINPUT", "USUBPASSINPUTMS", "F16SUBPASSINPUT",
"F16SUBPASSINPUTMS", "SPIRV_INSTRUCTION", "SPIRV_EXECUTION_MODE",
"SPIRV_EXECUTION_MODE_ID", "SPIRV_DECORATE", "SPIRV_DECORATE_ID",
"SPIRV_DECORATE_STRING", "SPIRV_TYPE", "SPIRV_STORAGE_CLASS",
"SPIRV_BY_REFERENCE", "SPIRV_LITERAL", "ATTACHMENTEXT", "IATTACHMENTEXT",
"UATTACHMENTEXT", "LEFT_OP", "RIGHT_OP", "INC_OP", "DEC_OP", "LE_OP",
"GE_OP", "EQ_OP", "NE_OP", "AND_OP", "OR_OP", "XOR_OP", "MUL_ASSIGN",
"DIV_ASSIGN", "ADD_ASSIGN", "MOD_ASSIGN", "LEFT_ASSIGN", "RIGHT_ASSIGN",
"AND_ASSIGN", "XOR_ASSIGN", "OR_ASSIGN", "SUB_ASSIGN", "STRING_LITERAL",
"LEFT_PAREN", "RIGHT_PAREN", "LEFT_BRACKET", "RIGHT_BRACKET",
"LEFT_BRACE", "RIGHT_BRACE", "DOT", "COMMA", "COLON", "EQUAL",
"SEMICOLON", "BANG", "DASH", "TILDE", "PLUS", "STAR", "SLASH", "PERCENT",
"LEFT_ANGLE", "RIGHT_ANGLE", "VERTICAL_BAR", "CARET", "AMPERSAND",
"QUESTION", "INVARIANT", "HIGH_PRECISION", "MEDIUM_PRECISION",
"LOW_PRECISION", "PRECISION", "PACKED", "RESOURCE", "SUPERP",
"FLOATCONSTANT", "INTCONSTANT", "UINTCONSTANT", "BOOLCONSTANT",
"IDENTIFIER", "TYPE_NAME", "CENTROID", "IN", "OUT", "INOUT", "STRUCT",
"VOID", "WHILE", "BREAK", "CONTINUE", "DO", "ELSE", "FOR", "IF",
"DISCARD", "RETURN", "SWITCH", "CASE", "DEFAULT", "TERMINATE_INVOCATION",
"TERMINATE_RAY", "IGNORE_INTERSECTION", "UNIFORM", "SHARED", "BUFFER",
"TILEIMAGEEXT", "FLAT", "SMOOTH", "LAYOUT", "DOUBLECONSTANT",
"INT16CONSTANT", "UINT16CONSTANT", "FLOAT16CONSTANT", "INT32CONSTANT",
"UINT32CONSTANT", "INT64CONSTANT", "UINT64CONSTANT", "SUBROUTINE",
"DEMOTE", "PAYLOADNV", "PAYLOADINNV", "HITATTRNV", "CALLDATANV",
"CALLDATAINNV", "PAYLOADEXT", "PAYLOADINEXT", "HITATTREXT",
"CALLDATAEXT", "CALLDATAINEXT", "PATCH", "SAMPLE", "NONUNIFORM",
"COHERENT", "VOLATILE", "RESTRICT", "READONLY", "WRITEONLY",
"DEVICECOHERENT", "QUEUEFAMILYCOHERENT", "WORKGROUPCOHERENT",
"SUBGROUPCOHERENT", "NONPRIVATE", "SHADERCALLCOHERENT", "NOPERSPECTIVE",
"EXPLICITINTERPAMD", "PERVERTEXEXT", "PERVERTEXNV", "PERPRIMITIVENV",
"PERVIEWNV", "PERTASKNV", "PERPRIMITIVEEXT", "TASKPAYLOADWORKGROUPEXT",
"PRECISE", "$accept", "variable_identifier", "primary_expression",
"postfix_expression", "integer_expression", "function_call",
"function_call_or_method", "function_call_generic",
"function_call_header_no_parameters",
"function_call_header_with_parameters", "function_call_header",
"function_identifier", "unary_expression", "unary_operator",
"multiplicative_expression", "additive_expression", "shift_expression",
"relational_expression", "equality_expression", "and_expression",
"exclusive_or_expression", "inclusive_or_expression",
"logical_and_expression", "logical_xor_expression",
"logical_or_expression", "conditional_expression", "$@1",
"assignment_expression", "assignment_operator", "expression",
"constant_expression", "declaration", "block_structure", "$@2",
"identifier_list", "function_prototype", "function_declarator",
"function_header_with_parameters", "function_header",
"parameter_declarator", "parameter_declaration",
"parameter_type_specifier", "init_declarator_list", "single_declaration",
"fully_specified_type", "invariant_qualifier", "interpolation_qualifier",
"layout_qualifier", "layout_qualifier_id_list", "layout_qualifier_id",
"precise_qualifier", "type_qualifier", "single_type_qualifier",
"storage_qualifier", "non_uniform_qualifier", "type_name_list",
"type_specifier", "array_specifier", "type_parameter_specifier_opt",
"type_parameter_specifier", "type_parameter_specifier_list",
"type_specifier_nonarray", "precision_qualifier", "struct_specifier",
"$@3", "$@4", "struct_declaration_list", "struct_declaration",
"struct_declarator_list", "struct_declarator", "initializer",
"initializer_list", "declaration_statement", "statement",
"simple_statement", "demote_statement", "compound_statement", "$@5",
"$@6", "statement_no_new_scope", "statement_scoped", "$@7", "$@8",
"compound_statement_no_new_scope", "statement_list",
"expression_statement", "selection_statement",
"selection_statement_nonattributed", "selection_rest_statement",
"condition", "switch_statement", "switch_statement_nonattributed", "$@9",
"switch_statement_list", "case_label", "iteration_statement",
"iteration_statement_nonattributed", "$@10", "$@11", "$@12",
"for_init_statement", "conditionopt", "for_rest_statement",
"jump_statement", "translation_unit", "external_declaration",
"function_definition", "$@13", "attribute", "attribute_list",
"single_attribute", "spirv_requirements_list",
"spirv_requirements_parameter", "spirv_extension_list",
"spirv_capability_list", "spirv_execution_mode_qualifier",
"spirv_execution_mode_parameter_list", "spirv_execution_mode_parameter",
"spirv_execution_mode_id_parameter_list",
"spirv_storage_class_qualifier", "spirv_decorate_qualifier",
"spirv_decorate_parameter_list", "spirv_decorate_parameter",
"spirv_decorate_id_parameter_list", "spirv_decorate_id_parameter",
"spirv_decorate_string_parameter_list", "spirv_type_specifier",
"spirv_type_parameter_list", "spirv_type_parameter",
"spirv_instruction_qualifier", "spirv_instruction_qualifier_list",
"spirv_instruction_qualifier_id", YY_NULLPTR
};
static const char *
yysymbol_name (yysymbol_kind_t yysymbol)
{
return yytname[yysymbol];
}
#endif
#define YYPACT_NINF (-872)
#define yypact_value_is_default(Yyn) \
((Yyn) == YYPACT_NINF)
#define YYTABLE_NINF (-695)
#define yytable_value_is_error(Yyn) \
0
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
static const yytype_int16 yypact[] =
{
4648, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -305, -301,
-289, -276, -246, -238, -227, -182, -872, -872, -872, -872,
-872, -168, -872, -872, -872, -872, -872, -55, -872, -872,
-872, -872, -872, -319, -872, -872, -872, -872, -872, -872,
-872, -135, -120, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -327, -114,
-81, -124, 7882, -313, -872, -101, -872, -872, -872, -872,
5572, -872, -872, -872, -872, -94, -872, -872, 952, -872,
-872, 7882, -73, -872, -872, -872, 6034, -78, -252, -250,
-216, -197, -136, -78, -127, -49, 12303, -872, -13, -346,
-39, -872, -309, -872, -10, -9, 7882, -872, -872, -872,
7882, -38, -37, -872, -267, -872, -236, -872, -872, 10983,
-2, -872, -872, -872, 3, -35, 7882, -872, -8, -6,
-1, -872, -256, -872, -255, -4, 4, 7, 8, -237,
10, 11, 13, 14, 15, 18, -232, 9, 19, 27,
-188, -872, -3, 7882, -872, 20, -872, -229, -872, -872,
-219, 9223, -872, -272, 1414, -872, -872, -872, -872, -872,
-2, -277, -872, 9663, -265, -872, -23, -872, -112, 10983,
10983, -872, 10983, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -253, -872, -872, -872, 29, -204, 11423, 28,
-872, 10983, -872, 31, -321, 17, -9, 32, -872, -325,
-78, -872, 5, -872, -330, 33, -125, 10983, -123, -872,
-130, -119, -146, -118, 34, -103, -78, -872, 11863, -872,
-74, 10983, 36, -49, -872, 7882, 24, 6496, -872, 7882,
10983, -872, -346, -872, 30, -872, -872, -33, -133, -105,
-303, -11, -14, 21, 23, 48, 52, -316, 41, -872,
10103, -872, 42, -872, -872, 46, 38, 40, -872, 64,
67, 60, 10543, 74, 10983, 68, 65, 69, 70, 73,
-167, -872, -872, -47, -872, -114, 77, 31, -872, -872,
-872, -872, -872, 1876, -872, -872, -872, -872, -872, -872,
-872, -872, -872, 5110, 17, 9663, -261, 8343, -872, -872,
9663, 7882, -872, 50, -872, -872, -872, -203, -872, -872,
10983, 51, -872, -872, 10983, 87, -872, -872, -872, 10983,
-872, -872, -872, -312, -872, -872, -200, 80, -872, -872,
-872, -872, -872, -872, -199, -872, -196, -872, -872, -195,
71, -872, -872, -872, -872, -169, -872, -164, -872, -872,
-872, -872, -872, -161, -872, 83, -872, -160, 84, -153,
80, -872, -278, -152, -872, 91, 94, -872, -872, 24,
-2, -43, -872, -872, -872, 6958, -872, -872, -872, 10983,
10983, 10983, 10983, 10983, 10983, 10983, 10983, 10983, 10983, 10983,
10983, 10983, 10983, 10983, 10983, 10983, 10983, 10983, -872, -872,
-872, 93, -872, 2338, -872, -872, -872, 2338, -872, 10983,
-872, -872, -42, 10983, -32, -872, -872, -872, -872, -872,
-872, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, 10983, 10983, -872, -872, -872, -872, -872, -872, -872,
9663, -872, -872, -76, -872, 7420, -872, -872, 96, 95,
-872, -872, -872, -872, -872, -132, -131, -872, -311, -872,
-330, -872, -330, -872, 10983, 10983, -872, -130, -872, -130,
-872, -146, -146, -872, 101, 34, -872, 11863, -872, 10983,
-872, -872, -41, 17, 24, -872, -872, -872, -872, -872,
-33, -33, -133, -133, -105, -105, -105, -105, -303, -303,
-11, -14, 21, 23, 48, 52, 10983, -872, 2338, 4186,
59, 3724, -151, -872, -150, -872, -872, -872, -872, -872,
8783, -872, -872, -872, 105, -872, 72, -872, -149, -872,
-148, -872, -141, -872, -140, -872, -139, -138, -872, -872,
-872, -28, 102, 95, 75, 107, 106, -872, -872, 4186,
108, -872, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, 10983, -872, 100, 2800, 10983, -872, 104, 109,
76, 112, 3262, -872, 113, -872, 9663, -872, -872, -872,
-137, 10983, 2800, 108, -872, -872, 2338, -872, 110, 95,
-872, -872, 2338, 114, -872, -872
};
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
Performed when YYTABLE does not specify something else to do. Zero
means the default is an error. */
static const yytype_int16 yydefact[] =
{
0, 168, 225, 223, 224, 222, 229, 230, 231, 232,
233, 234, 235, 236, 237, 226, 227, 228, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
351, 352, 353, 354, 355, 356, 357, 377, 378, 379,
380, 381, 382, 383, 392, 405, 406, 393, 394, 396,
395, 397, 398, 399, 400, 401, 402, 403, 404, 177,
178, 251, 252, 250, 253, 260, 261, 258, 259, 256,
257, 254, 255, 283, 284, 285, 295, 296, 297, 280,
281, 282, 292, 293, 294, 277, 278, 279, 289, 290,
291, 274, 275, 276, 286, 287, 288, 262, 263, 264,
298, 299, 300, 265, 266, 267, 310, 311, 312, 268,
269, 270, 322, 323, 324, 271, 272, 273, 334, 335,
336, 301, 302, 303, 304, 305, 306, 307, 308, 309,
313, 314, 315, 316, 317, 318, 319, 320, 321, 325,
326, 327, 328, 329, 330, 331, 332, 333, 337, 338,
339, 340, 341, 342, 343, 344, 345, 349, 346, 347,
348, 533, 534, 535, 536, 538, 182, 361, 362, 385,
388, 350, 359, 360, 376, 358, 407, 408, 411, 412,
413, 415, 416, 417, 419, 420, 421, 423, 424, 520,
521, 384, 386, 387, 363, 364, 365, 409, 366, 370,
371, 374, 414, 418, 422, 367, 368, 372, 373, 410,
369, 375, 454, 456, 457, 458, 460, 461, 462, 464,
465, 466, 468, 469, 470, 472, 473, 474, 476, 477,
478, 480, 481, 482, 484, 485, 486, 488, 489, 490,
492, 493, 494, 496, 497, 455, 459, 463, 467, 471,
479, 483, 487, 475, 491, 495, 498, 499, 500, 501,
502, 503, 504, 505, 506, 507, 508, 509, 510, 511,
512, 513, 514, 515, 516, 517, 518, 519, 389, 390,
391, 425, 434, 436, 430, 435, 437, 438, 440, 441,
442, 444, 445, 446, 448, 449, 450, 452, 453, 426,
427, 428, 439, 429, 431, 432, 433, 443, 447, 451,
525, 526, 529, 530, 531, 532, 527, 528, 0, 0,
0, 0, 0, 0, 0, 0, 166, 167, 522, 523,
524, 0, 631, 137, 541, 542, 543, 0, 540, 172,
170, 171, 169, 0, 221, 173, 175, 176, 174, 139,
138, 0, 203, 184, 186, 181, 188, 190, 185, 187,
183, 189, 191, 179, 180, 206, 192, 199, 200, 201,
202, 193, 194, 195, 196, 197, 198, 140, 141, 143,
142, 144, 146, 147, 145, 205, 154, 630, 0, 632,
0, 114, 113, 0, 125, 130, 161, 160, 158, 162,
0, 155, 157, 163, 135, 216, 159, 539, 0, 627,
629, 0, 0, 164, 165, 537, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 546, 0, 0,
0, 99, 0, 94, 0, 109, 0, 121, 115, 123,
0, 124, 0, 97, 131, 102, 0, 156, 136, 0,
209, 215, 1, 628, 0, 0, 0, 96, 0, 0,
0, 639, 0, 697, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 637,
0, 635, 0, 0, 544, 151, 153, 0, 149, 207,
0, 0, 100, 0, 0, 633, 110, 116, 120, 122,
118, 126, 117, 0, 132, 105, 0, 103, 0, 0,
0, 9, 0, 43, 42, 44, 41, 5, 6, 7,
8, 2, 16, 14, 15, 17, 10, 11, 12, 13,
3, 18, 37, 20, 25, 26, 0, 0, 30, 0,
219, 0, 36, 218, 0, 210, 111, 0, 95, 0,
0, 695, 0, 647, 0, 0, 0, 0, 0, 664,
0, 0, 0, 0, 0, 0, 0, 689, 0, 662,
0, 0, 0, 0, 98, 0, 0, 0, 548, 0,
0, 148, 0, 204, 0, 211, 45, 49, 52, 55,
60, 63, 65, 67, 69, 71, 73, 75, 0, 34,
0, 101, 575, 584, 588, 0, 0, 0, 609, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45, 78, 91, 0, 562, 0, 163, 135, 565, 586,
564, 572, 563, 0, 566, 567, 590, 568, 597, 569,
570, 605, 571, 0, 119, 0, 127, 0, 556, 134,
0, 0, 107, 0, 104, 38, 39, 0, 22, 23,
0, 0, 28, 27, 0, 221, 31, 33, 40, 0,
217, 112, 699, 0, 700, 640, 0, 0, 698, 659,
655, 656, 657, 658, 0, 653, 0, 93, 660, 0,
0, 674, 675, 676, 677, 0, 672, 0, 681, 682,
683, 684, 680, 0, 678, 0, 685, 0, 0, 0,
2, 693, 216, 0, 691, 0, 0, 634, 636, 0,
554, 0, 552, 547, 549, 0, 152, 150, 208, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 76, 212,
213, 0, 574, 0, 607, 620, 619, 0, 611, 0,
623, 621, 0, 0, 0, 604, 624, 625, 626, 573,
81, 82, 84, 83, 86, 87, 88, 89, 90, 85,
80, 0, 0, 589, 585, 587, 591, 598, 606, 129,
0, 559, 560, 0, 133, 0, 108, 4, 0, 24,
21, 32, 220, 643, 645, 0, 0, 696, 0, 649,
0, 648, 0, 651, 0, 0, 666, 0, 665, 0,
668, 0, 0, 670, 0, 0, 690, 0, 687, 0,
663, 638, 0, 555, 0, 550, 545, 46, 47, 48,
51, 50, 53, 54, 58, 59, 56, 57, 61, 62,
64, 66, 68, 70, 72, 74, 0, 214, 576, 0,
0, 0, 0, 622, 0, 603, 79, 92, 128, 557,
0, 106, 19, 641, 0, 642, 0, 654, 0, 661,
0, 673, 0, 679, 0, 686, 0, 0, 692, 551,
553, 0, 0, 595, 0, 0, 0, 614, 613, 616,
582, 599, 558, 561, 644, 646, 650, 652, 667, 669,
671, 688, 0, 577, 0, 0, 0, 615, 0, 0,
594, 0, 0, 592, 0, 77, 0, 579, 608, 578,
0, 617, 0, 582, 581, 583, 601, 596, 0, 618,
612, 593, 602, 0, 610, 600
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int16 yypgoto[] =
{
-872, -544, -872, -872, -872, -872, -872, -872, -872, -872,
-872, -872, -436, -872, -392, -391, -490, -390, -269, -266,
-268, -264, -262, -260, -872, -482, -872, -499, -872, -492,
-534, 6, -872, -872, -872, 1, -403, -872, -872, 45,
44, 49, -872, -872, -406, -872, -872, -872, -872, -104,
-872, -389, -375, -872, 12, -872, 0, -433, -872, -872,
-872, -553, 145, -872, -872, -872, -560, -556, -233, -344,
-614, -872, -373, -626, -871, -872, -430, -872, -872, -440,
-437, -872, -872, 63, -737, -363, -872, -144, -872, -399,
-872, -142, -872, -872, -872, -872, -134, -872, -872, -872,
-872, -872, -872, -872, -872, 97, -872, -872, 2, -872,
-71, -308, -416, -872, -872, -872, -304, -307, -302, -872,
-872, -315, -310, -306, -300, -314, -872, -299, -317, -872,
-395, -538
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int16 yydefgoto[] =
{
0, 530, 531, 532, 798, 533, 534, 535, 536, 537,
538, 539, 620, 541, 587, 588, 589, 590, 591, 592,
593, 594, 595, 596, 597, 621, 856, 622, 781, 623,
711, 624, 388, 651, 508, 625, 390, 391, 392, 437,
438, 439, 393, 394, 395, 396, 397, 398, 487, 488,
399, 400, 401, 402, 542, 490, 599, 493, 450, 451,
544, 405, 406, 407, 579, 483, 577, 578, 721, 722,
649, 793, 628, 629, 630, 631, 632, 753, 892, 928,
920, 921, 922, 929, 633, 634, 635, 636, 923, 895,
637, 638, 924, 943, 639, 640, 641, 859, 757, 861,
899, 918, 919, 642, 408, 409, 410, 434, 643, 480,
481, 460, 461, 805, 806, 412, 684, 685, 689, 413,
414, 695, 696, 703, 704, 707, 415, 713, 714, 416,
462, 463
};
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule whose
number is the opposite. If YYTABLE_NINF, syntax error. */
static const yytype_int16 yytable[] =
{
404, 389, 411, 440, 648, 455, 387, 785, 454, 598,
455, 504, 403, 540, 678, 712, 858, 545, 702, 725,
657, 724, 456, 688, 679, 447, 747, 456, 476, 672,
678, 789, 673, 792, 736, 737, 794, 716, 431, 666,
427, 669, 803, 672, 927, 485, 726, 440, 491, 442,
417, 935, 443, 670, 418, 586, 492, 680, 681, 682,
683, 927, 748, 674, 432, 447, 419, 644, 646, 486,
738, 739, 428, 655, 656, 687, 804, 674, -694, 420,
491, 447, 658, 659, -694, 600, 687, 645, 502, 687,
491, 795, 600, 601, 575, 449, 600, 503, 687, 650,
551, 553, -35, 790, 660, 668, 552, 554, 661, 421,
466, 468, 470, 472, 474, 475, 478, 422, 751, 559,
762, 586, 764, 505, 567, 560, 506, 581, 423, 507,
568, 860, 586, 582, 675, 586, 464, 583, 467, 465,
675, 465, 675, 584, 586, 675, 648, 675, 648, 675,
675, 648, 663, 797, 675, 676, 807, 809, 664, 782,
811, 813, 552, 810, 586, 801, 812, 814, 799, 724,
572, 709, 469, 424, 573, 465, 868, 770, 771, 772,
773, 774, 775, 776, 777, 778, 779, 816, 575, 425,
575, 471, 818, 817, 465, 820, 823, 780, 819, 942,
447, 821, 824, 826, 828, 900, 901, 906, 907, 827,
829, 782, 782, 810, 814, 908, 909, 910, 911, 938,
429, 817, 821, 824, 829, 782, 873, 875, 734, 735,
874, 876, 785, 802, 732, 430, 733, 455, 436, 724,
454, 698, 699, 700, 701, 521, 844, 845, 846, 847,
653, 433, 473, 654, 456, 465, 903, 691, 692, 693,
694, 477, 575, 686, 465, 690, 465, 862, 465, 697,
705, 864, 465, 465, 712, 435, 712, 702, 702, 449,
879, 688, 866, 867, 869, 708, 870, 833, 465, 678,
444, 648, 457, 837, 838, 839, 586, 586, 586, 586,
586, 586, 586, 586, 586, 586, 586, 586, 586, 586,
586, 586, 937, 459, 715, 782, 785, 465, 783, 834,
782, 834, 835, 863, 889, 334, 335, 336, 740, 741,
782, 865, 687, 687, 782, 912, 575, 729, 730, 731,
840, 841, 479, 842, 843, 687, 484, 687, 331, 494,
848, 849, 489, 500, 501, 491, 547, 548, 549, 546,
555, 550, 574, 742, 891, 569, 556, 893, 652, 557,
558, 648, 561, 562, 600, 563, 564, 565, 586, 586,
566, 570, 571, 667, 580, 662, -34, 502, 706, 745,
673, 586, 441, 586, 717, 746, 677, 743, 744, 749,
448, 754, 752, 755, 403, 756, 575, 893, 404, 389,
411, 404, 403, 925, 387, 720, 404, 458, 411, 758,
403, 728, 759, 403, 930, 760, 482, 648, 403, 763,
766, 765, -36, 815, 767, 768, 441, 496, 769, 939,
441, 796, 800, -29, 808, 822, 825, 830, 403, 543,
831, 857, 403, 894, 872, 885, 448, 782, 896, 904,
905, 916, 913, 915, 926, 932, 914, -580, 403, 931,
456, 602, 936, 850, 945, 944, 852, 851, 727, 933,
497, 853, 426, 576, 854, 498, 832, 855, 897, 499,
890, 934, 940, 894, 627, 403, 941, 495, 898, 786,
917, 787, 718, 877, 882, 453, 626, 881, 878, 788,
456, 886, 888, 880, 0, 0, 884, 0, 0, 0,
0, 883, 0, 0, 0, 0, 0, 0, 887, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 671, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 719, 0, 576, 0, 576,
0, 0, 0, 0, 0, 0, 0, 403, 0, 403,
0, 403, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 627, 0, 0, 0, 0, 0, 0,
0, 0, 0, 404, 0, 626, 0, 0, 0, 0,
0, 576, 0, 0, 0, 403, 0, 0, 0, 0,
0, 0, 0, 403, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 576, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 403, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 627, 0, 0, 0, 627, 0, 0,
0, 0, 0, 0, 0, 626, 0, 0, 0, 626,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 576, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 403, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 627, 627,
0, 627, 0, 411, 0, 0, 0, 0, 0, 0,
626, 626, 0, 626, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 627,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 626, 0, 0, 0, 627, 0, 0, 0, 0,
0, 0, 627, 0, 0, 0, 0, 626, 0, 0,
0, 0, 627, 0, 626, 0, 627, 0, 0, 0,
0, 0, 627, 0, 626, 0, 0, 0, 626, 0,
0, 0, 452, 0, 626, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165,
166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
196, 197, 198, 199, 200, 201, 202, 203, 204, 205,
206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
216, 217, 218, 219, 220, 221, 222, 223, 224, 225,
226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
256, 257, 258, 259, 260, 261, 262, 263, 264, 265,
266, 267, 268, 269, 270, 271, 272, 273, 274, 275,
276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295,
296, 297, 298, 299, 300, 301, 302, 303, 304, 305,
306, 307, 308, 309, 310, 311, 312, 313, 314, 315,
316, 317, 318, 319, 320, 321, 322, 323, 324, 325,
326, 327, 328, 329, 330, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 331,
0, 0, 0, 0, 0, 0, 0, 332, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 333, 334, 335, 336, 337, 0, 0, 0, 0,
0, 0, 0, 0, 338, 339, 340, 341, 342, 343,
344, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 345, 346, 347, 348,
349, 350, 351, 0, 0, 0, 0, 0, 0, 0,
0, 352, 0, 353, 354, 355, 356, 357, 358, 359,
360, 361, 362, 363, 364, 365, 366, 367, 368, 369,
370, 371, 372, 373, 374, 375, 376, 377, 378, 379,
380, 381, 382, 383, 384, 385, 386, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
234, 235, 236, 237, 238, 239, 240, 241, 242, 243,
244, 245, 246, 247, 248, 249, 250, 251, 252, 253,
254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273,
274, 275, 276, 277, 278, 279, 280, 281, 282, 283,
284, 285, 286, 287, 288, 289, 290, 291, 292, 293,
294, 295, 296, 297, 298, 299, 300, 301, 302, 303,
304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
314, 315, 316, 317, 318, 319, 320, 321, 322, 323,
324, 325, 326, 327, 328, 329, 330, 0, 0, 509,
510, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 511, 512,
0, 331, 0, 602, 603, 0, 0, 0, 0, 604,
513, 514, 515, 516, 0, 0, 0, 0, 0, 0,
0, 0, 0, 333, 334, 335, 336, 337, 0, 0,
0, 517, 518, 519, 520, 521, 338, 339, 340, 341,
342, 343, 344, 605, 606, 607, 608, 0, 609, 610,
611, 612, 613, 614, 615, 616, 617, 618, 345, 346,
347, 348, 349, 350, 351, 522, 523, 524, 525, 526,
527, 528, 529, 352, 619, 353, 354, 355, 356, 357,
358, 359, 360, 361, 362, 363, 364, 365, 366, 367,
368, 369, 370, 371, 372, 373, 374, 375, 376, 377,
378, 379, 380, 381, 382, 383, 384, 385, 386, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 160, 161,
162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
202, 203, 204, 205, 206, 207, 208, 209, 210, 211,
212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
252, 253, 254, 255, 256, 257, 258, 259, 260, 261,
262, 263, 264, 265, 266, 267, 268, 269, 270, 271,
272, 273, 274, 275, 276, 277, 278, 279, 280, 281,
282, 283, 284, 285, 286, 287, 288, 289, 290, 291,
292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
302, 303, 304, 305, 306, 307, 308, 309, 310, 311,
312, 313, 314, 315, 316, 317, 318, 319, 320, 321,
322, 323, 324, 325, 326, 327, 328, 329, 330, 0,
0, 509, 510, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
511, 512, 0, 331, 0, 602, 784, 0, 0, 0,
0, 604, 513, 514, 515, 516, 0, 0, 0, 0,
0, 0, 0, 0, 0, 333, 334, 335, 336, 337,
0, 0, 0, 517, 518, 519, 520, 521, 338, 339,
340, 341, 342, 343, 344, 605, 606, 607, 608, 0,
609, 610, 611, 612, 613, 614, 615, 616, 617, 618,
345, 346, 347, 348, 349, 350, 351, 522, 523, 524,
525, 526, 527, 528, 529, 352, 619, 353, 354, 355,
356, 357, 358, 359, 360, 361, 362, 363, 364, 365,
366, 367, 368, 369, 370, 371, 372, 373, 374, 375,
376, 377, 378, 379, 380, 381, 382, 383, 384, 385,
386, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
250, 251, 252, 253, 254, 255, 256, 257, 258, 259,
260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
270, 271, 272, 273, 274, 275, 276, 277, 278, 279,
280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
300, 301, 302, 303, 304, 305, 306, 307, 308, 309,
310, 311, 312, 313, 314, 315, 316, 317, 318, 319,
320, 321, 322, 323, 324, 325, 326, 327, 328, 329,
330, 0, 0, 509, 510, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 511, 512, 0, 331, 0, 602, 0, 0,
0, 0, 0, 604, 513, 514, 515, 516, 0, 0,
0, 0, 0, 0, 0, 0, 0, 333, 334, 335,
336, 337, 0, 0, 0, 517, 518, 519, 520, 521,
338, 339, 340, 341, 342, 343, 344, 605, 606, 607,
608, 0, 609, 610, 611, 612, 613, 614, 615, 616,
617, 618, 345, 346, 347, 348, 349, 350, 351, 522,
523, 524, 525, 526, 527, 528, 529, 352, 619, 353,
354, 355, 356, 357, 358, 359, 360, 361, 362, 363,
364, 365, 366, 367, 368, 369, 370, 371, 372, 373,
374, 375, 376, 377, 378, 379, 380, 381, 382, 383,
384, 385, 386, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
278, 279, 280, 281, 282, 283, 284, 285, 286, 287,
288, 289, 290, 291, 292, 293, 294, 295, 296, 297,
298, 299, 300, 301, 302, 303, 304, 305, 306, 307,
308, 309, 310, 311, 312, 313, 314, 315, 316, 317,
318, 319, 320, 321, 322, 323, 324, 325, 326, 327,
328, 329, 330, 0, 0, 509, 510, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 511, 512, 0, 331, 0, 494,
0, 0, 0, 0, 0, 604, 513, 514, 515, 516,
0, 0, 0, 0, 0, 0, 0, 0, 0, 333,
334, 335, 336, 337, 0, 0, 0, 517, 518, 519,
520, 521, 338, 339, 340, 341, 342, 343, 344, 605,
606, 607, 608, 0, 609, 610, 611, 612, 613, 614,
615, 616, 617, 618, 345, 346, 347, 348, 349, 350,
351, 522, 523, 524, 525, 526, 527, 528, 529, 352,
619, 353, 354, 355, 356, 357, 358, 359, 360, 361,
362, 363, 364, 365, 366, 367, 368, 369, 370, 371,
372, 373, 374, 375, 376, 377, 378, 379, 380, 381,
382, 383, 384, 385, 386, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165,
166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
196, 197, 198, 199, 200, 201, 202, 203, 204, 205,
206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
216, 217, 218, 219, 220, 221, 222, 223, 224, 225,
226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
256, 257, 258, 259, 260, 261, 262, 263, 264, 265,
266, 267, 268, 269, 270, 271, 272, 273, 274, 275,
276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295,
296, 297, 298, 299, 300, 301, 302, 303, 304, 305,
306, 307, 308, 309, 310, 311, 312, 313, 314, 315,
316, 317, 318, 319, 320, 321, 322, 323, 324, 325,
326, 327, 328, 329, 330, 0, 0, 509, 510, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 511, 512, 0, 331,
0, 0, 0, 0, 0, 0, 0, 604, 513, 514,
515, 516, 0, 0, 0, 0, 0, 0, 0, 0,
0, 333, 334, 335, 336, 337, 0, 0, 0, 517,
518, 519, 520, 521, 338, 339, 340, 341, 342, 343,
344, 605, 606, 607, 608, 0, 609, 610, 611, 612,
613, 614, 615, 616, 617, 618, 345, 346, 347, 348,
349, 350, 351, 522, 523, 524, 525, 526, 527, 528,
529, 352, 619, 353, 354, 355, 356, 357, 358, 359,
360, 361, 362, 363, 364, 365, 366, 367, 368, 369,
370, 371, 372, 373, 374, 375, 376, 377, 378, 379,
380, 381, 382, 383, 384, 385, 386, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
234, 235, 236, 237, 238, 239, 240, 241, 242, 243,
244, 245, 246, 247, 248, 249, 250, 251, 252, 253,
254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273,
274, 275, 276, 277, 278, 279, 280, 281, 282, 283,
284, 285, 286, 287, 288, 289, 290, 291, 292, 293,
294, 295, 296, 297, 298, 299, 300, 301, 302, 303,
304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
314, 315, 316, 317, 318, 319, 320, 321, 322, 323,
324, 325, 326, 327, 328, 329, 330, 0, 0, 509,
510, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 511, 512,
0, 331, 0, 0, 0, 0, 0, 0, 0, 604,
513, 514, 515, 516, 0, 0, 0, 0, 0, 0,
0, 0, 0, 333, 334, 335, 336, 337, 0, 0,
0, 517, 518, 519, 520, 521, 338, 339, 340, 341,
342, 343, 344, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 345, 346,
347, 348, 349, 350, 351, 522, 523, 524, 525, 526,
527, 528, 529, 352, 0, 353, 354, 355, 356, 357,
358, 359, 360, 361, 362, 363, 364, 365, 366, 367,
368, 369, 370, 371, 372, 373, 374, 375, 376, 377,
378, 379, 380, 381, 382, 383, 384, 385, 386, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 160, 161,
162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
202, 203, 204, 205, 206, 207, 208, 209, 210, 211,
212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
252, 253, 254, 255, 256, 257, 258, 259, 260, 261,
262, 263, 264, 265, 266, 267, 268, 269, 270, 271,
272, 273, 274, 275, 276, 277, 278, 279, 280, 281,
282, 283, 284, 285, 286, 287, 288, 289, 290, 291,
292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
302, 303, 304, 305, 306, 307, 308, 309, 310, 311,
312, 313, 314, 315, 316, 317, 0, 0, 0, 321,
322, 323, 324, 325, 326, 327, 328, 329, 330, 0,
0, 509, 510, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
511, 512, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 513, 514, 515, 516, 0, 0, 0, 0,
0, 0, 0, 0, 0, 333, 334, 335, 336, 0,
0, 0, 0, 517, 518, 519, 520, 521, 338, 339,
340, 341, 342, 343, 344, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
345, 346, 347, 348, 349, 350, 351, 522, 523, 524,
525, 526, 527, 528, 529, 352, 0, 353, 354, 355,
356, 357, 358, 359, 360, 361, 362, 363, 364, 365,
366, 367, 368, 369, 370, 371, 372, 373, 374, 375,
376, 377, 378, 379, 380, 381, 382, 383, 384, 385,
386, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
250, 251, 252, 253, 254, 255, 256, 257, 258, 259,
260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
270, 271, 272, 273, 274, 275, 276, 277, 278, 279,
280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
300, 301, 302, 303, 304, 305, 306, 307, 308, 309,
310, 311, 312, 313, 314, 315, 316, 317, 318, 319,
320, 321, 322, 323, 324, 325, 326, 327, 328, 329,
330, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 331, 0, 0, 0, 0,
0, 0, 0, 332, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 333, 334, 335,
336, 337, 0, 0, 0, 0, 0, 0, 0, 0,
338, 339, 340, 341, 342, 343, 344, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 345, 346, 347, 348, 349, 350, 351, 0,
0, 0, 0, 0, 0, 0, 0, 352, 0, 353,
354, 355, 356, 357, 358, 359, 360, 361, 362, 363,
364, 365, 366, 367, 368, 369, 370, 371, 372, 373,
374, 375, 376, 377, 378, 379, 380, 381, 382, 383,
384, 385, 386, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
278, 279, 280, 281, 282, 283, 284, 285, 286, 287,
288, 289, 290, 291, 292, 293, 294, 295, 296, 297,
298, 299, 300, 301, 302, 303, 304, 305, 306, 307,
308, 309, 310, 311, 312, 313, 314, 315, 316, 317,
0, 0, 0, 321, 322, 323, 324, 325, 326, 327,
328, 329, 330, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 333,
334, 335, 336, 0, 0, 0, 0, 0, 0, 0,
0, 0, 338, 339, 340, 341, 342, 343, 344, 605,
0, 0, 608, 0, 609, 610, 0, 0, 613, 0,
0, 0, 0, 0, 345, 346, 347, 348, 349, 350,
351, 0, 0, 0, 0, 0, 0, 0, 0, 352,
0, 353, 354, 355, 356, 357, 358, 359, 360, 361,
362, 363, 364, 365, 366, 367, 368, 369, 370, 371,
372, 373, 374, 375, 376, 377, 378, 379, 380, 381,
382, 383, 384, 385, 386, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165,
166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
196, 197, 198, 199, 200, 201, 202, 203, 204, 205,
206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
216, 217, 218, 219, 220, 221, 222, 223, 224, 225,
226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
256, 257, 258, 259, 260, 261, 262, 263, 264, 265,
266, 267, 268, 269, 270, 271, 272, 273, 274, 275,
276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295,
296, 297, 298, 299, 300, 301, 302, 303, 304, 305,
306, 307, 308, 309, 310, 311, 312, 313, 314, 315,
316, 317, 0, 0, 0, 321, 322, 323, 324, 325,
326, 327, 328, 329, 330, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 445, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 333, 334, 335, 336, 0, 0, 0, 0, 0,
0, 0, 0, 446, 338, 339, 340, 341, 342, 343,
344, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 345, 346, 347, 348,
349, 350, 351, 0, 0, 0, 0, 0, 0, 0,
0, 352, 0, 353, 354, 355, 356, 357, 358, 359,
360, 361, 362, 363, 364, 365, 366, 367, 368, 369,
370, 371, 372, 373, 374, 375, 376, 377, 378, 379,
380, 381, 382, 383, 384, 385, 386, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
234, 235, 236, 237, 238, 239, 240, 241, 242, 243,
244, 245, 246, 247, 248, 249, 250, 251, 252, 253,
254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273,
274, 275, 276, 277, 278, 279, 280, 281, 282, 283,
284, 285, 286, 287, 288, 289, 290, 291, 292, 293,
294, 295, 296, 297, 298, 299, 300, 301, 302, 303,
304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
314, 315, 316, 317, 0, 0, 0, 321, 322, 323,
324, 325, 326, 327, 328, 329, 330, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 331, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 333, 334, 335, 336, 0, 0, 0,
0, 0, 0, 0, 0, 0, 338, 339, 340, 341,
342, 343, 344, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 345, 346,
347, 348, 349, 350, 351, 0, 0, 0, 0, 0,
0, 0, 0, 352, 0, 353, 354, 355, 356, 357,
358, 359, 360, 361, 362, 363, 364, 365, 366, 367,
368, 369, 370, 371, 372, 373, 374, 375, 376, 377,
378, 379, 380, 381, 382, 383, 384, 385, 386, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 160, 161,
162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
202, 203, 204, 205, 206, 207, 208, 209, 210, 211,
212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
252, 253, 254, 255, 256, 257, 258, 259, 260, 261,
262, 263, 264, 265, 266, 267, 268, 269, 270, 271,
272, 273, 274, 275, 276, 277, 278, 279, 280, 281,
282, 283, 284, 285, 286, 287, 288, 289, 290, 291,
292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
302, 303, 304, 305, 306, 307, 308, 309, 310, 311,
312, 313, 314, 315, 316, 317, 0, 0, 0, 321,
322, 323, 324, 325, 326, 327, 328, 329, 330, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 723, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 333, 334, 335, 336, 0,
0, 0, 0, 0, 0, 0, 0, 0, 338, 339,
340, 341, 342, 343, 344, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
345, 346, 347, 348, 349, 350, 351, 0, 0, 0,
0, 0, 0, 0, 0, 352, 0, 353, 354, 355,
356, 357, 358, 359, 360, 361, 362, 363, 364, 365,
366, 367, 368, 369, 370, 371, 372, 373, 374, 375,
376, 377, 378, 379, 380, 381, 382, 383, 384, 385,
386, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
250, 251, 252, 253, 254, 255, 256, 257, 258, 259,
260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
270, 271, 272, 273, 274, 275, 276, 277, 278, 279,
280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
300, 301, 302, 303, 304, 305, 306, 307, 308, 309,
310, 311, 312, 313, 314, 315, 316, 317, 0, 0,
0, 321, 322, 323, 324, 325, 326, 327, 328, 329,
330, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 836, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 333, 334, 335,
336, 0, 0, 0, 0, 0, 0, 0, 0, 0,
338, 339, 340, 341, 342, 343, 344, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 345, 346, 347, 348, 349, 350, 351, 0,
0, 0, 0, 0, 0, 0, 0, 352, 0, 353,
354, 355, 356, 357, 358, 359, 360, 361, 362, 363,
364, 365, 366, 367, 368, 369, 370, 371, 372, 373,
374, 375, 376, 377, 378, 379, 380, 381, 382, 383,
384, 385, 386, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
278, 279, 280, 281, 282, 283, 284, 285, 286, 287,
288, 289, 290, 291, 292, 293, 294, 295, 296, 297,
298, 299, 300, 301, 302, 303, 304, 305, 306, 307,
308, 309, 310, 311, 312, 313, 314, 315, 316, 317,
0, 0, 0, 321, 322, 323, 324, 325, 326, 327,
328, 329, 330, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
871, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 333,
334, 335, 336, 0, 0, 0, 0, 0, 0, 0,
0, 0, 338, 339, 340, 341, 342, 343, 344, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 345, 346, 347, 348, 349, 350,
351, 0, 0, 0, 0, 0, 0, 0, 0, 352,
0, 353, 354, 355, 356, 357, 358, 359, 360, 361,
362, 363, 364, 365, 366, 367, 368, 369, 370, 371,
372, 373, 374, 375, 376, 377, 378, 379, 380, 381,
382, 383, 384, 385, 386, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165,
166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
196, 197, 198, 199, 200, 201, 202, 203, 204, 205,
206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
216, 217, 218, 219, 220, 221, 222, 223, 224, 225,
226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
256, 257, 258, 259, 260, 261, 262, 263, 264, 265,
266, 267, 268, 269, 270, 271, 272, 273, 274, 275,
276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295,
296, 297, 298, 299, 300, 301, 302, 303, 304, 305,
306, 307, 308, 309, 310, 311, 312, 313, 314, 315,
316, 317, 0, 0, 0, 321, 322, 323, 324, 325,
326, 327, 328, 329, 330, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 333, 334, 335, 336, 0, 0, 0, 0, 0,
0, 0, 0, 0, 338, 339, 340, 341, 342, 343,
344, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 345, 346, 347, 348,
349, 350, 351, 0, 0, 0, 0, 0, 0, 0,
0, 352, 0, 353, 354, 355, 356, 357, 358, 359,
360, 361, 362, 363, 364, 365, 366, 367, 368, 369,
370, 371, 372, 373, 374, 375, 376, 377, 378, 379,
380, 381, 382, 383, 384, 385, 386, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 509, 510,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 511, 512, 0,
0, 0, 647, 791, 0, 0, 0, 0, 0, 513,
514, 515, 516, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
517, 518, 519, 520, 521, 338, 0, 0, 0, 0,
343, 344, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 522, 523, 524, 525, 526, 527,
528, 529, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 365, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 509, 510,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 511, 512, 0,
0, 0, 647, 902, 0, 0, 0, 0, 0, 513,
514, 515, 516, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
517, 518, 519, 520, 521, 338, 0, 0, 0, 0,
343, 344, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 522, 523, 524, 525, 526, 527,
528, 529, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 365, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 509, 510,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 511, 512, 0,
0, 585, 0, 0, 0, 0, 0, 0, 0, 513,
514, 515, 516, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
517, 518, 519, 520, 521, 338, 0, 0, 0, 0,
343, 344, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 522, 523, 524, 525, 526, 527,
528, 529, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 365, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 509, 510,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 511, 512, 0,
0, 0, 647, 0, 0, 0, 0, 0, 0, 513,
514, 515, 516, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
517, 518, 519, 520, 521, 338, 0, 0, 0, 0,
343, 344, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 522, 523, 524, 525, 526, 527,
528, 529, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 365, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 509, 510,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 511, 512, 0,
0, 750, 0, 0, 0, 0, 0, 0, 0, 513,
514, 515, 516, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
517, 518, 519, 520, 521, 338, 0, 0, 0, 0,
343, 344, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 522, 523, 524, 525, 526, 527,
528, 529, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 365, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 509, 510,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 511, 512, 0,
0, 0, 0, 0, 0, 0, 0, 0, 761, 513,
514, 515, 516, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
517, 518, 519, 520, 521, 338, 0, 0, 0, 0,
343, 344, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 522, 523, 524, 525, 526, 527,
528, 529, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 365, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 509, 510,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 511, 512, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 513,
514, 515, 516, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
517, 518, 519, 520, 521, 338, 0, 0, 0, 0,
343, 344, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 522, 523, 524, 525, 526, 527,
528, 529, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 365, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 509, 510,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 511, 512, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 513,
514, 515, 516, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
517, 518, 519, 520, 521, 338, 0, 0, 0, 0,
343, 665, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 522, 523, 524, 525, 526, 527,
528, 529, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 365, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 509, 510,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 511, 512, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 513,
514, 515, 516, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
517, 518, 519, 520, 710, 338, 0, 0, 0, 0,
343, 344, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 522, 523, 524, 525, 526, 527,
528, 529, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 365, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 0, 0, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
165, 0, 167, 168, 169, 170, 171, 172, 173, 174,
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
255, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
315, 316, 317, 0, 0, 0, 0, 0, 0, 324,
0, 0, 0, 328, 329, 330, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 338, 0, 0, 0, 0,
343, 344
};
static const yytype_int16 yycheck[] =
{
0, 0, 0, 392, 503, 411, 0, 633, 411, 491,
416, 444, 0, 449, 552, 568, 753, 450, 562, 579,
512, 577, 411, 557, 354, 400, 342, 416, 423, 354,
568, 645, 357, 647, 337, 338, 650, 571, 365, 538,
359, 362, 354, 354, 915, 391, 580, 436, 357, 362,
355, 922, 365, 374, 355, 491, 365, 387, 388, 389,
390, 932, 378, 388, 391, 440, 355, 500, 501, 415,
373, 374, 391, 509, 510, 557, 388, 388, 356, 355,
357, 456, 335, 336, 362, 357, 568, 364, 355, 571,
357, 651, 357, 365, 483, 373, 357, 364, 580, 364,
356, 356, 355, 364, 357, 541, 362, 362, 361, 355,
418, 419, 420, 421, 422, 423, 424, 355, 600, 356,
612, 557, 614, 359, 356, 362, 362, 356, 355, 365,
362, 757, 568, 362, 550, 571, 388, 356, 388, 391,
556, 391, 558, 362, 580, 561, 645, 563, 647, 565,
566, 650, 356, 356, 570, 550, 356, 356, 362, 362,
356, 356, 362, 362, 600, 664, 362, 362, 660, 725,
358, 566, 388, 355, 362, 391, 790, 344, 345, 346,
347, 348, 349, 350, 351, 352, 353, 356, 577, 357,
579, 388, 356, 362, 391, 356, 356, 364, 362, 936,
575, 362, 362, 356, 356, 356, 356, 356, 356, 362,
362, 362, 362, 362, 362, 356, 356, 356, 356, 356,
355, 362, 362, 362, 362, 362, 358, 358, 333, 334,
362, 362, 858, 669, 367, 355, 369, 643, 362, 795,
643, 387, 388, 389, 390, 391, 736, 737, 738, 739,
362, 365, 388, 365, 643, 391, 870, 387, 388, 389,
390, 388, 651, 388, 391, 388, 391, 759, 391, 388,
388, 763, 391, 391, 827, 356, 829, 821, 822, 373,
814, 815, 781, 782, 360, 388, 362, 720, 391, 827,
391, 790, 365, 729, 730, 731, 732, 733, 734, 735,
736, 737, 738, 739, 740, 741, 742, 743, 744, 745,
746, 747, 926, 391, 388, 362, 942, 391, 365, 362,
362, 362, 365, 365, 365, 380, 381, 382, 339, 340,
362, 363, 814, 815, 362, 363, 725, 370, 371, 372,
732, 733, 391, 734, 735, 827, 359, 829, 357, 359,
740, 741, 391, 391, 391, 357, 391, 365, 364, 356,
364, 362, 365, 377, 856, 356, 362, 859, 391, 362,
362, 870, 362, 362, 357, 362, 362, 362, 814, 815,
362, 362, 355, 355, 364, 356, 355, 355, 354, 341,
357, 827, 392, 829, 358, 343, 391, 376, 375, 358,
400, 355, 360, 365, 392, 365, 795, 899, 408, 408,
408, 411, 400, 912, 408, 391, 416, 416, 416, 355,
408, 391, 355, 411, 916, 365, 426, 926, 416, 355,
365, 363, 355, 362, 365, 365, 436, 435, 365, 931,
440, 391, 391, 356, 364, 362, 362, 356, 436, 449,
356, 358, 440, 859, 358, 354, 456, 362, 399, 354,
388, 355, 360, 356, 364, 356, 391, 359, 456, 365,
859, 359, 359, 742, 360, 365, 744, 743, 582, 403,
436, 745, 337, 483, 746, 440, 719, 747, 861, 440,
834, 921, 932, 899, 494, 483, 933, 434, 861, 643,
899, 643, 573, 810, 819, 408, 494, 817, 812, 643,
899, 825, 829, 815, -1, -1, 822, -1, -1, -1,
-1, 821, -1, -1, -1, -1, -1, -1, 827, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 546, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 575, -1, 577, -1, 579,
-1, -1, -1, -1, -1, -1, -1, 575, -1, 577,
-1, 579, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 633, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 643, -1, 633, -1, -1, -1, -1,
-1, 651, -1, -1, -1, 643, -1, -1, -1, -1,
-1, -1, -1, 651, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 725, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 725, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 753, -1, -1, -1, 757, -1, -1,
-1, -1, -1, -1, -1, 753, -1, -1, -1, 757,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 795, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 795, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 858, 859,
-1, 861, -1, 861, -1, -1, -1, -1, -1, -1,
858, 859, -1, 861, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 899,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 899, -1, -1, -1, 915, -1, -1, -1, -1,
-1, -1, 922, -1, -1, -1, -1, 915, -1, -1,
-1, -1, 932, -1, 922, -1, 936, -1, -1, -1,
-1, -1, 942, -1, 932, -1, -1, -1, 936, -1,
-1, -1, 0, -1, 942, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
278, 279, 280, 281, 282, 283, 284, 285, 286, 287,
288, 289, 290, 291, 292, 293, 294, 295, 296, 297,
298, 299, 300, 301, 302, 303, 304, 305, 306, 307,
308, 309, 310, 311, 312, 313, 314, 315, 316, 317,
318, 319, 320, 321, 322, 323, 324, 325, 326, 327,
328, 329, 330, 331, 332, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 357,
-1, -1, -1, -1, -1, -1, -1, 365, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 379, 380, 381, 382, 383, -1, -1, -1, -1,
-1, -1, -1, -1, 392, 393, 394, 395, 396, 397,
398, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 414, 415, 416, 417,
418, 419, 420, -1, -1, -1, -1, -1, -1, -1,
-1, 429, -1, 431, 432, 433, 434, 435, 436, 437,
438, 439, 440, 441, 442, 443, 444, 445, 446, 447,
448, 449, 450, 451, 452, 453, 454, 455, 456, 457,
458, 459, 460, 461, 462, 463, 464, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165,
166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
196, 197, 198, 199, 200, 201, 202, 203, 204, 205,
206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
216, 217, 218, 219, 220, 221, 222, 223, 224, 225,
226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
256, 257, 258, 259, 260, 261, 262, 263, 264, 265,
266, 267, 268, 269, 270, 271, 272, 273, 274, 275,
276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295,
296, 297, 298, 299, 300, 301, 302, 303, 304, 305,
306, 307, 308, 309, 310, 311, 312, 313, 314, 315,
316, 317, 318, 319, 320, 321, 322, 323, 324, 325,
326, 327, 328, 329, 330, 331, 332, -1, -1, 335,
336, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 354, 355,
-1, 357, -1, 359, 360, -1, -1, -1, -1, 365,
366, 367, 368, 369, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 379, 380, 381, 382, 383, -1, -1,
-1, 387, 388, 389, 390, 391, 392, 393, 394, 395,
396, 397, 398, 399, 400, 401, 402, -1, 404, 405,
406, 407, 408, 409, 410, 411, 412, 413, 414, 415,
416, 417, 418, 419, 420, 421, 422, 423, 424, 425,
426, 427, 428, 429, 430, 431, 432, 433, 434, 435,
436, 437, 438, 439, 440, 441, 442, 443, 444, 445,
446, 447, 448, 449, 450, 451, 452, 453, 454, 455,
456, 457, 458, 459, 460, 461, 462, 463, 464, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
234, 235, 236, 237, 238, 239, 240, 241, 242, 243,
244, 245, 246, 247, 248, 249, 250, 251, 252, 253,
254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273,
274, 275, 276, 277, 278, 279, 280, 281, 282, 283,
284, 285, 286, 287, 288, 289, 290, 291, 292, 293,
294, 295, 296, 297, 298, 299, 300, 301, 302, 303,
304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
314, 315, 316, 317, 318, 319, 320, 321, 322, 323,
324, 325, 326, 327, 328, 329, 330, 331, 332, -1,
-1, 335, 336, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
354, 355, -1, 357, -1, 359, 360, -1, -1, -1,
-1, 365, 366, 367, 368, 369, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 379, 380, 381, 382, 383,
-1, -1, -1, 387, 388, 389, 390, 391, 392, 393,
394, 395, 396, 397, 398, 399, 400, 401, 402, -1,
404, 405, 406, 407, 408, 409, 410, 411, 412, 413,
414, 415, 416, 417, 418, 419, 420, 421, 422, 423,
424, 425, 426, 427, 428, 429, 430, 431, 432, 433,
434, 435, 436, 437, 438, 439, 440, 441, 442, 443,
444, 445, 446, 447, 448, 449, 450, 451, 452, 453,
454, 455, 456, 457, 458, 459, 460, 461, 462, 463,
464, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 160, 161,
162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
202, 203, 204, 205, 206, 207, 208, 209, 210, 211,
212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
252, 253, 254, 255, 256, 257, 258, 259, 260, 261,
262, 263, 264, 265, 266, 267, 268, 269, 270, 271,
272, 273, 274, 275, 276, 277, 278, 279, 280, 281,
282, 283, 284, 285, 286, 287, 288, 289, 290, 291,
292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
302, 303, 304, 305, 306, 307, 308, 309, 310, 311,
312, 313, 314, 315, 316, 317, 318, 319, 320, 321,
322, 323, 324, 325, 326, 327, 328, 329, 330, 331,
332, -1, -1, 335, 336, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 354, 355, -1, 357, -1, 359, -1, -1,
-1, -1, -1, 365, 366, 367, 368, 369, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 379, 380, 381,
382, 383, -1, -1, -1, 387, 388, 389, 390, 391,
392, 393, 394, 395, 396, 397, 398, 399, 400, 401,
402, -1, 404, 405, 406, 407, 408, 409, 410, 411,
412, 413, 414, 415, 416, 417, 418, 419, 420, 421,
422, 423, 424, 425, 426, 427, 428, 429, 430, 431,
432, 433, 434, 435, 436, 437, 438, 439, 440, 441,
442, 443, 444, 445, 446, 447, 448, 449, 450, 451,
452, 453, 454, 455, 456, 457, 458, 459, 460, 461,
462, 463, 464, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
250, 251, 252, 253, 254, 255, 256, 257, 258, 259,
260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
270, 271, 272, 273, 274, 275, 276, 277, 278, 279,
280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
300, 301, 302, 303, 304, 305, 306, 307, 308, 309,
310, 311, 312, 313, 314, 315, 316, 317, 318, 319,
320, 321, 322, 323, 324, 325, 326, 327, 328, 329,
330, 331, 332, -1, -1, 335, 336, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 354, 355, -1, 357, -1, 359,
-1, -1, -1, -1, -1, 365, 366, 367, 368, 369,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 379,
380, 381, 382, 383, -1, -1, -1, 387, 388, 389,
390, 391, 392, 393, 394, 395, 396, 397, 398, 399,
400, 401, 402, -1, 404, 405, 406, 407, 408, 409,
410, 411, 412, 413, 414, 415, 416, 417, 418, 419,
420, 421, 422, 423, 424, 425, 426, 427, 428, 429,
430, 431, 432, 433, 434, 435, 436, 437, 438, 439,
440, 441, 442, 443, 444, 445, 446, 447, 448, 449,
450, 451, 452, 453, 454, 455, 456, 457, 458, 459,
460, 461, 462, 463, 464, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
278, 279, 280, 281, 282, 283, 284, 285, 286, 287,
288, 289, 290, 291, 292, 293, 294, 295, 296, 297,
298, 299, 300, 301, 302, 303, 304, 305, 306, 307,
308, 309, 310, 311, 312, 313, 314, 315, 316, 317,
318, 319, 320, 321, 322, 323, 324, 325, 326, 327,
328, 329, 330, 331, 332, -1, -1, 335, 336, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 354, 355, -1, 357,
-1, -1, -1, -1, -1, -1, -1, 365, 366, 367,
368, 369, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 379, 380, 381, 382, 383, -1, -1, -1, 387,
388, 389, 390, 391, 392, 393, 394, 395, 396, 397,
398, 399, 400, 401, 402, -1, 404, 405, 406, 407,
408, 409, 410, 411, 412, 413, 414, 415, 416, 417,
418, 419, 420, 421, 422, 423, 424, 425, 426, 427,
428, 429, 430, 431, 432, 433, 434, 435, 436, 437,
438, 439, 440, 441, 442, 443, 444, 445, 446, 447,
448, 449, 450, 451, 452, 453, 454, 455, 456, 457,
458, 459, 460, 461, 462, 463, 464, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165,
166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
196, 197, 198, 199, 200, 201, 202, 203, 204, 205,
206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
216, 217, 218, 219, 220, 221, 222, 223, 224, 225,
226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
256, 257, 258, 259, 260, 261, 262, 263, 264, 265,
266, 267, 268, 269, 270, 271, 272, 273, 274, 275,
276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295,
296, 297, 298, 299, 300, 301, 302, 303, 304, 305,
306, 307, 308, 309, 310, 311, 312, 313, 314, 315,
316, 317, 318, 319, 320, 321, 322, 323, 324, 325,
326, 327, 328, 329, 330, 331, 332, -1, -1, 335,
336, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 354, 355,
-1, 357, -1, -1, -1, -1, -1, -1, -1, 365,
366, 367, 368, 369, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 379, 380, 381, 382, 383, -1, -1,
-1, 387, 388, 389, 390, 391, 392, 393, 394, 395,
396, 397, 398, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 414, 415,
416, 417, 418, 419, 420, 421, 422, 423, 424, 425,
426, 427, 428, 429, -1, 431, 432, 433, 434, 435,
436, 437, 438, 439, 440, 441, 442, 443, 444, 445,
446, 447, 448, 449, 450, 451, 452, 453, 454, 455,
456, 457, 458, 459, 460, 461, 462, 463, 464, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
234, 235, 236, 237, 238, 239, 240, 241, 242, 243,
244, 245, 246, 247, 248, 249, 250, 251, 252, 253,
254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273,
274, 275, 276, 277, 278, 279, 280, 281, 282, 283,
284, 285, 286, 287, 288, 289, 290, 291, 292, 293,
294, 295, 296, 297, 298, 299, 300, 301, 302, 303,
304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
314, 315, 316, 317, 318, 319, -1, -1, -1, 323,
324, 325, 326, 327, 328, 329, 330, 331, 332, -1,
-1, 335, 336, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
354, 355, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 366, 367, 368, 369, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 379, 380, 381, 382, -1,
-1, -1, -1, 387, 388, 389, 390, 391, 392, 393,
394, 395, 396, 397, 398, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
414, 415, 416, 417, 418, 419, 420, 421, 422, 423,
424, 425, 426, 427, 428, 429, -1, 431, 432, 433,
434, 435, 436, 437, 438, 439, 440, 441, 442, 443,
444, 445, 446, 447, 448, 449, 450, 451, 452, 453,
454, 455, 456, 457, 458, 459, 460, 461, 462, 463,
464, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 160, 161,
162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
202, 203, 204, 205, 206, 207, 208, 209, 210, 211,
212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
252, 253, 254, 255, 256, 257, 258, 259, 260, 261,
262, 263, 264, 265, 266, 267, 268, 269, 270, 271,
272, 273, 274, 275, 276, 277, 278, 279, 280, 281,
282, 283, 284, 285, 286, 287, 288, 289, 290, 291,
292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
302, 303, 304, 305, 306, 307, 308, 309, 310, 311,
312, 313, 314, 315, 316, 317, 318, 319, 320, 321,
322, 323, 324, 325, 326, 327, 328, 329, 330, 331,
332, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 357, -1, -1, -1, -1,
-1, -1, -1, 365, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 379, 380, 381,
382, 383, -1, -1, -1, -1, -1, -1, -1, -1,
392, 393, 394, 395, 396, 397, 398, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 414, 415, 416, 417, 418, 419, 420, -1,
-1, -1, -1, -1, -1, -1, -1, 429, -1, 431,
432, 433, 434, 435, 436, 437, 438, 439, 440, 441,
442, 443, 444, 445, 446, 447, 448, 449, 450, 451,
452, 453, 454, 455, 456, 457, 458, 459, 460, 461,
462, 463, 464, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
250, 251, 252, 253, 254, 255, 256, 257, 258, 259,
260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
270, 271, 272, 273, 274, 275, 276, 277, 278, 279,
280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
300, 301, 302, 303, 304, 305, 306, 307, 308, 309,
310, 311, 312, 313, 314, 315, 316, 317, 318, 319,
-1, -1, -1, 323, 324, 325, 326, 327, 328, 329,
330, 331, 332, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 379,
380, 381, 382, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 392, 393, 394, 395, 396, 397, 398, 399,
-1, -1, 402, -1, 404, 405, -1, -1, 408, -1,
-1, -1, -1, -1, 414, 415, 416, 417, 418, 419,
420, -1, -1, -1, -1, -1, -1, -1, -1, 429,
-1, 431, 432, 433, 434, 435, 436, 437, 438, 439,
440, 441, 442, 443, 444, 445, 446, 447, 448, 449,
450, 451, 452, 453, 454, 455, 456, 457, 458, 459,
460, 461, 462, 463, 464, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
278, 279, 280, 281, 282, 283, 284, 285, 286, 287,
288, 289, 290, 291, 292, 293, 294, 295, 296, 297,
298, 299, 300, 301, 302, 303, 304, 305, 306, 307,
308, 309, 310, 311, 312, 313, 314, 315, 316, 317,
318, 319, -1, -1, -1, 323, 324, 325, 326, 327,
328, 329, 330, 331, 332, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 365, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 379, 380, 381, 382, -1, -1, -1, -1, -1,
-1, -1, -1, 391, 392, 393, 394, 395, 396, 397,
398, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 414, 415, 416, 417,
418, 419, 420, -1, -1, -1, -1, -1, -1, -1,
-1, 429, -1, 431, 432, 433, 434, 435, 436, 437,
438, 439, 440, 441, 442, 443, 444, 445, 446, 447,
448, 449, 450, 451, 452, 453, 454, 455, 456, 457,
458, 459, 460, 461, 462, 463, 464, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165,
166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
196, 197, 198, 199, 200, 201, 202, 203, 204, 205,
206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
216, 217, 218, 219, 220, 221, 222, 223, 224, 225,
226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
256, 257, 258, 259, 260, 261, 262, 263, 264, 265,
266, 267, 268, 269, 270, 271, 272, 273, 274, 275,
276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
286, 287, 288, 289, 290, 291, 292, 293, 294, 295,
296, 297, 298, 299, 300, 301, 302, 303, 304, 305,
306, 307, 308, 309, 310, 311, 312, 313, 314, 315,
316, 317, 318, 319, -1, -1, -1, 323, 324, 325,
326, 327, 328, 329, 330, 331, 332, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 357, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 379, 380, 381, 382, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 392, 393, 394, 395,
396, 397, 398, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 414, 415,
416, 417, 418, 419, 420, -1, -1, -1, -1, -1,
-1, -1, -1, 429, -1, 431, 432, 433, 434, 435,
436, 437, 438, 439, 440, 441, 442, 443, 444, 445,
446, 447, 448, 449, 450, 451, 452, 453, 454, 455,
456, 457, 458, 459, 460, 461, 462, 463, 464, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
234, 235, 236, 237, 238, 239, 240, 241, 242, 243,
244, 245, 246, 247, 248, 249, 250, 251, 252, 253,
254, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273,
274, 275, 276, 277, 278, 279, 280, 281, 282, 283,
284, 285, 286, 287, 288, 289, 290, 291, 292, 293,
294, 295, 296, 297, 298, 299, 300, 301, 302, 303,
304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
314, 315, 316, 317, 318, 319, -1, -1, -1, 323,
324, 325, 326, 327, 328, 329, 330, 331, 332, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 360, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 379, 380, 381, 382, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 392, 393,
394, 395, 396, 397, 398, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
414, 415, 416, 417, 418, 419, 420, -1, -1, -1,
-1, -1, -1, -1, -1, 429, -1, 431, 432, 433,
434, 435, 436, 437, 438, 439, 440, 441, 442, 443,
444, 445, 446, 447, 448, 449, 450, 451, 452, 453,
454, 455, 456, 457, 458, 459, 460, 461, 462, 463,
464, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 160, 161,
162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
202, 203, 204, 205, 206, 207, 208, 209, 210, 211,
212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
252, 253, 254, 255, 256, 257, 258, 259, 260, 261,
262, 263, 264, 265, 266, 267, 268, 269, 270, 271,
272, 273, 274, 275, 276, 277, 278, 279, 280, 281,
282, 283, 284, 285, 286, 287, 288, 289, 290, 291,
292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
302, 303, 304, 305, 306, 307, 308, 309, 310, 311,
312, 313, 314, 315, 316, 317, 318, 319, -1, -1,
-1, 323, 324, 325, 326, 327, 328, 329, 330, 331,
332, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 360, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 379, 380, 381,
382, -1, -1, -1, -1, -1, -1, -1, -1, -1,
392, 393, 394, 395, 396, 397, 398, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 414, 415, 416, 417, 418, 419, 420, -1,
-1, -1, -1, -1, -1, -1, -1, 429, -1, 431,
432, 433, 434, 435, 436, 437, 438, 439, 440, 441,
442, 443, 444, 445, 446, 447, 448, 449, 450, 451,
452, 453, 454, 455, 456, 457, 458, 459, 460, 461,
462, 463, 464, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
250, 251, 252, 253, 254, 255, 256, 257, 258, 259,
260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
270, 271, 272, 273, 274, 275, 276, 277, 278, 279,
280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
300, 301, 302, 303, 304, 305, 306, 307, 308, 309,
310, 311, 312, 313, 314, 315, 316, 317, 318, 319,
-1, -1, -1, 323, 324, 325, 326, 327, 328, 329,
330, 331, 332, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
360, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 379,
380, 381, 382, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 392, 393, 394, 395, 396, 397, 398, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 414, 415, 416, 417, 418, 419,
420, -1, -1, -1, -1, -1, -1, -1, -1, 429,
-1, 431, 432, 433, 434, 435, 436, 437, 438, 439,
440, 441, 442, 443, 444, 445, 446, 447, 448, 449,
450, 451, 452, 453, 454, 455, 456, 457, 458, 459,
460, 461, 462, 463, 464, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
258, 259, 260, 261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
278, 279, 280, 281, 282, 283, 284, 285, 286, 287,
288, 289, 290, 291, 292, 293, 294, 295, 296, 297,
298, 299, 300, 301, 302, 303, 304, 305, 306, 307,
308, 309, 310, 311, 312, 313, 314, 315, 316, 317,
318, 319, -1, -1, -1, 323, 324, 325, 326, 327,
328, 329, 330, 331, 332, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 379, 380, 381, 382, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 392, 393, 394, 395, 396, 397,
398, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 414, 415, 416, 417,
418, 419, 420, -1, -1, -1, -1, -1, -1, -1,
-1, 429, -1, 431, 432, 433, 434, 435, 436, 437,
438, 439, 440, 441, 442, 443, 444, 445, 446, 447,
448, 449, 450, 451, 452, 453, 454, 455, 456, 457,
458, 459, 460, 461, 462, 463, 464, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, 335, 336,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 354, 355, -1,
-1, -1, 359, 360, -1, -1, -1, -1, -1, 366,
367, 368, 369, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387, 388, 389, 390, 391, 392, -1, -1, -1, -1,
397, 398, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 421, 422, 423, 424, 425, 426,
427, 428, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 443, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, 335, 336,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 354, 355, -1,
-1, -1, 359, 360, -1, -1, -1, -1, -1, 366,
367, 368, 369, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387, 388, 389, 390, 391, 392, -1, -1, -1, -1,
397, 398, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 421, 422, 423, 424, 425, 426,
427, 428, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 443, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, 335, 336,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 354, 355, -1,
-1, 358, -1, -1, -1, -1, -1, -1, -1, 366,
367, 368, 369, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387, 388, 389, 390, 391, 392, -1, -1, -1, -1,
397, 398, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 421, 422, 423, 424, 425, 426,
427, 428, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 443, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, 335, 336,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 354, 355, -1,
-1, -1, 359, -1, -1, -1, -1, -1, -1, 366,
367, 368, 369, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387, 388, 389, 390, 391, 392, -1, -1, -1, -1,
397, 398, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 421, 422, 423, 424, 425, 426,
427, 428, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 443, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, 335, 336,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 354, 355, -1,
-1, 358, -1, -1, -1, -1, -1, -1, -1, 366,
367, 368, 369, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387, 388, 389, 390, 391, 392, -1, -1, -1, -1,
397, 398, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 421, 422, 423, 424, 425, 426,
427, 428, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 443, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, 335, 336,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 354, 355, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 365, 366,
367, 368, 369, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387, 388, 389, 390, 391, 392, -1, -1, -1, -1,
397, 398, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 421, 422, 423, 424, 425, 426,
427, 428, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 443, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, 335, 336,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 354, 355, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 366,
367, 368, 369, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387, 388, 389, 390, 391, 392, -1, -1, -1, -1,
397, 398, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 421, 422, 423, 424, 425, 426,
427, 428, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 443, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, 335, 336,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 354, 355, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 366,
367, 368, 369, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387, 388, 389, 390, 391, 392, -1, -1, -1, -1,
397, 398, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 421, 422, 423, 424, 425, 426,
427, 428, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 443, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, 335, 336,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 354, 355, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, 366,
367, 368, 369, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
387, 388, 389, 390, 391, 392, -1, -1, -1, -1,
397, 398, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 421, 422, 423, 424, 425, 426,
427, 428, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 443, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, -1, -1, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, -1, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286,
287, 288, 289, 290, 291, 292, 293, 294, 295, 296,
297, 298, 299, 300, 301, 302, 303, 304, 305, 306,
307, 308, 309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, -1, -1, -1, -1, -1, -1, 326,
-1, -1, -1, 330, 331, 332, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, 392, -1, -1, -1, -1,
397, 398
};
/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
state STATE-NUM. */
static const yytype_int16 yystos[] =
{
0, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154, 155, 156, 157, 158, 159, 160, 161,
162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
202, 203, 204, 205, 206, 207, 208, 209, 210, 211,
212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
252, 253, 254, 255, 256, 257, 258, 259, 260, 261,
262, 263, 264, 265, 266, 267, 268, 269, 270, 271,
272, 273, 274, 275, 276, 277, 278, 279, 280, 281,
282, 283, 284, 285, 286, 287, 288, 289, 290, 291,
292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
302, 303, 304, 305, 306, 307, 308, 309, 310, 311,
312, 313, 314, 315, 316, 317, 318, 319, 320, 321,
322, 323, 324, 325, 326, 327, 328, 329, 330, 331,
332, 357, 365, 379, 380, 381, 382, 383, 392, 393,
394, 395, 396, 397, 398, 414, 415, 416, 417, 418,
419, 420, 429, 431, 432, 433, 434, 435, 436, 437,
438, 439, 440, 441, 442, 443, 444, 445, 446, 447,
448, 449, 450, 451, 452, 453, 454, 455, 456, 457,
458, 459, 460, 461, 462, 463, 464, 496, 497, 500,
501, 502, 503, 507, 508, 509, 510, 511, 512, 515,
516, 517, 518, 519, 521, 526, 527, 528, 569, 570,
571, 573, 580, 584, 585, 591, 594, 355, 355, 355,
355, 355, 355, 355, 355, 357, 527, 359, 391, 355,
355, 365, 391, 365, 572, 356, 362, 504, 505, 506,
516, 521, 362, 365, 391, 365, 391, 517, 521, 373,
523, 524, 0, 570, 501, 509, 516, 365, 500, 391,
576, 577, 595, 596, 388, 391, 576, 388, 576, 388,
576, 388, 576, 388, 576, 576, 595, 388, 576, 391,
574, 575, 521, 530, 359, 391, 415, 513, 514, 391,
520, 357, 365, 522, 359, 548, 573, 505, 504, 506,
391, 391, 355, 364, 522, 359, 362, 365, 499, 335,
336, 354, 355, 366, 367, 368, 369, 387, 388, 389,
390, 391, 421, 422, 423, 424, 425, 426, 427, 428,
466, 467, 468, 470, 471, 472, 473, 474, 475, 476,
477, 478, 519, 521, 525, 522, 356, 391, 365, 364,
362, 356, 362, 356, 362, 364, 362, 362, 362, 356,
362, 362, 362, 362, 362, 362, 362, 356, 362, 356,
362, 355, 358, 362, 365, 516, 521, 531, 532, 529,
364, 356, 362, 356, 362, 358, 477, 479, 480, 481,
482, 483, 484, 485, 486, 487, 488, 489, 490, 521,
357, 365, 359, 360, 365, 399, 400, 401, 402, 404,
405, 406, 407, 408, 409, 410, 411, 412, 413, 430,
477, 490, 492, 494, 496, 500, 519, 521, 537, 538,
539, 540, 541, 549, 550, 551, 552, 555, 556, 559,
560, 561, 568, 573, 522, 364, 522, 359, 492, 535,
364, 498, 391, 362, 365, 477, 477, 494, 335, 336,
357, 361, 356, 356, 362, 398, 492, 355, 477, 362,
374, 573, 354, 357, 388, 577, 595, 391, 596, 354,
387, 388, 389, 390, 581, 582, 388, 490, 495, 583,
388, 387, 388, 389, 390, 586, 587, 388, 387, 388,
389, 390, 466, 588, 589, 388, 354, 590, 388, 595,
391, 495, 526, 592, 593, 388, 495, 358, 575, 521,
391, 533, 534, 360, 532, 531, 495, 514, 391, 370,
371, 372, 367, 369, 333, 334, 337, 338, 373, 374,
339, 340, 377, 376, 375, 341, 343, 342, 378, 358,
358, 490, 360, 542, 355, 365, 365, 563, 355, 355,
365, 365, 494, 355, 494, 363, 365, 365, 365, 365,
344, 345, 346, 347, 348, 349, 350, 351, 352, 353,
364, 493, 362, 365, 360, 538, 552, 556, 561, 535,
364, 360, 535, 536, 535, 531, 391, 356, 469, 494,
391, 492, 477, 354, 388, 578, 579, 356, 364, 356,
362, 356, 362, 356, 362, 362, 356, 362, 356, 362,
356, 362, 362, 356, 362, 362, 356, 362, 356, 362,
356, 356, 533, 522, 362, 365, 360, 477, 477, 477,
479, 479, 480, 480, 481, 481, 481, 481, 482, 482,
483, 484, 485, 486, 487, 488, 491, 358, 549, 562,
538, 564, 494, 365, 494, 363, 492, 492, 535, 360,
362, 360, 358, 358, 362, 358, 362, 582, 581, 495,
583, 587, 586, 589, 588, 354, 590, 592, 593, 365,
534, 494, 543, 494, 509, 554, 399, 537, 550, 565,
356, 356, 360, 535, 354, 388, 356, 356, 356, 356,
356, 356, 363, 360, 391, 356, 355, 554, 566, 567,
545, 546, 547, 553, 557, 492, 364, 539, 544, 548,
494, 365, 356, 403, 541, 539, 359, 535, 356, 494,
544, 545, 549, 558, 365, 360
};
/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
static const yytype_int16 yyr1[] =
{
0, 465, 466, 467, 467, 467, 467, 467, 467, 467,
467, 467, 467, 467, 467, 467, 467, 467, 468, 468,
468, 468, 468, 468, 469, 470, 471, 472, 472, 473,
473, 474, 474, 475, 476, 476, 476, 477, 477, 477,
477, 478, 478, 478, 478, 479, 479, 479, 479, 480,
480, 480, 481, 481, 481, 482, 482, 482, 482, 482,
483, 483, 483, 484, 484, 485, 485, 486, 486, 487,
487, 488, 488, 489, 489, 490, 491, 490, 492, 492,
493, 493, 493, 493, 493, 493, 493, 493, 493, 493,
493, 494, 494, 495, 496, 496, 496, 496, 496, 496,
496, 496, 496, 496, 496, 498, 497, 499, 499, 500,
500, 500, 500, 501, 501, 502, 502, 503, 504, 504,
505, 505, 505, 505, 506, 507, 507, 507, 507, 507,
508, 508, 508, 508, 508, 509, 509, 510, 511, 511,
511, 511, 511, 511, 511, 511, 511, 511, 512, 513,
513, 514, 514, 514, 515, 516, 516, 517, 517, 517,
517, 517, 517, 517, 517, 517, 517, 517, 518, 518,
518, 518, 518, 518, 518, 518, 518, 518, 518, 518,
518, 518, 518, 518, 518, 518, 518, 518, 518, 518,
518, 518, 518, 518, 518, 518, 518, 518, 518, 518,
518, 518, 518, 518, 518, 518, 519, 520, 520, 521,
521, 522, 522, 522, 522, 523, 523, 524, 525, 525,
525, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 526, 526, 526, 526, 526, 526, 526, 526, 526,
526, 527, 527, 527, 529, 528, 530, 528, 531, 531,
532, 532, 533, 533, 534, 534, 535, 535, 535, 535,
536, 536, 537, 538, 538, 539, 539, 539, 539, 539,
539, 539, 539, 540, 541, 542, 543, 541, 544, 544,
546, 545, 547, 545, 548, 548, 549, 549, 550, 550,
551, 551, 552, 553, 553, 554, 554, 555, 555, 557,
556, 558, 558, 559, 559, 560, 560, 562, 561, 563,
561, 564, 561, 565, 565, 566, 566, 567, 567, 568,
568, 568, 568, 568, 568, 568, 568, 569, 569, 570,
570, 570, 572, 571, 573, 574, 574, 575, 575, 576,
576, 577, 577, 578, 578, 579, 579, 580, 580, 580,
580, 580, 580, 581, 581, 582, 582, 582, 582, 582,
583, 583, 584, 584, 585, 585, 585, 585, 585, 585,
585, 585, 586, 586, 587, 587, 587, 587, 588, 588,
589, 589, 589, 589, 589, 590, 590, 591, 591, 591,
591, 592, 592, 593, 593, 594, 594, 595, 595, 596,
596
};
/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
static const yytype_int8 yyr2[] =
{
0, 2, 1, 1, 3, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 4,
1, 3, 2, 2, 1, 1, 1, 2, 2, 2,
1, 2, 3, 2, 1, 1, 1, 1, 2, 2,
2, 1, 1, 1, 1, 1, 3, 3, 3, 1,
3, 3, 1, 3, 3, 1, 3, 3, 3, 3,
1, 3, 3, 1, 3, 1, 3, 1, 3, 1,
3, 1, 3, 1, 3, 1, 0, 6, 1, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 3, 1, 2, 3, 2, 2, 4, 2,
3, 4, 2, 3, 4, 0, 6, 2, 3, 2,
3, 3, 4, 1, 1, 2, 3, 3, 2, 3,
2, 1, 2, 1, 1, 1, 3, 4, 6, 5,
1, 2, 3, 5, 4, 1, 2, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 4, 1,
3, 1, 3, 1, 1, 1, 2, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 4, 1, 1, 1, 3, 2,
3, 2, 3, 3, 4, 1, 0, 3, 1, 1,
3, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 6, 0, 5, 1, 2,
3, 4, 1, 3, 1, 2, 1, 3, 4, 2,
1, 3, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 2, 0, 0, 5, 1, 1,
0, 2, 0, 2, 2, 3, 1, 2, 1, 2,
1, 2, 5, 3, 1, 1, 4, 1, 2, 0,
8, 0, 1, 3, 2, 1, 2, 0, 6, 0,
8, 0, 7, 1, 1, 1, 0, 2, 3, 2,
2, 2, 3, 2, 2, 2, 2, 1, 2, 1,
1, 1, 0, 3, 5, 1, 3, 1, 4, 1,
3, 5, 5, 1, 3, 1, 3, 4, 6, 6,
8, 6, 8, 1, 3, 1, 1, 1, 1, 1,
1, 3, 4, 6, 4, 6, 6, 8, 6, 8,
6, 8, 1, 3, 1, 1, 1, 1, 1, 3,
1, 1, 1, 1, 1, 1, 3, 6, 8, 4,
6, 1, 3, 1, 1, 4, 6, 1, 3, 3,
3
};
enum { YYENOMEM = -2 };
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY)
#define YYACCEPT goto yyacceptlab
#define YYABORT goto yyabortlab
#define YYERROR goto yyerrorlab
#define YYNOMEM goto yyexhaustedlab
#define YYRECOVERING() (!!yyerrstatus)
#define YYBACKUP(Token, Value) \
do \
if (yychar == YYEMPTY) \
{ \
yychar = (Token); \
yylval = (Value); \
YYPOPSTACK (yylen); \
yystate = *yyssp; \
goto yybackup; \
} \
else \
{ \
yyerror (pParseContext, YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (0)
/* Backward compatibility with an undocumented macro.
Use YYerror or YYUNDEF. */
#define YYERRCODE YYUNDEF
/* Enable debugging if requested. */
#if YYDEBUG
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
# define YYFPRINTF fprintf
# endif
# define YYDPRINTF(Args) \
do { \
if (yydebug) \
YYFPRINTF Args; \
} while (0)
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
do { \
if (yydebug) \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Kind, Value, pParseContext); \
YYFPRINTF (stderr, "\n"); \
} \
} while (0)
/*-----------------------------------.
| Print this symbol's value on YYO. |
`-----------------------------------*/
static void
yy_symbol_value_print (FILE *yyo,
yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, glslang::TParseContext* pParseContext)
{
FILE *yyoutput = yyo;
YY_USE (yyoutput);
YY_USE (pParseContext);
if (!yyvaluep)
return;
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
YY_USE (yykind);
YY_IGNORE_MAYBE_UNINITIALIZED_END
}
/*---------------------------.
| Print this symbol on YYO. |
`---------------------------*/
static void
yy_symbol_print (FILE *yyo,
yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, glslang::TParseContext* pParseContext)
{
YYFPRINTF (yyo, "%s %s (",
yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
yy_symbol_value_print (yyo, yykind, yyvaluep, pParseContext);
YYFPRINTF (yyo, ")");
}
/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included). |
`------------------------------------------------------------------*/
static void
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
{
YYFPRINTF (stderr, "Stack now");
for (; yybottom <= yytop; yybottom++)
{
int yybot = *yybottom;
YYFPRINTF (stderr, " %d", yybot);
}
YYFPRINTF (stderr, "\n");
}
# define YY_STACK_PRINT(Bottom, Top) \
do { \
if (yydebug) \
yy_stack_print ((Bottom), (Top)); \
} while (0)
/*------------------------------------------------.
| Report that the YYRULE is going to be reduced. |
`------------------------------------------------*/
static void
yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
int yyrule, glslang::TParseContext* pParseContext)
{
int yylno = yyrline[yyrule];
int yynrhs = yyr2[yyrule];
int yyi;
YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
yyrule - 1, yylno);
/* The symbols being reduced. */
for (yyi = 0; yyi < yynrhs; yyi++)
{
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr,
YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
&yyvsp[(yyi + 1) - (yynrhs)], pParseContext);
YYFPRINTF (stderr, "\n");
}
}
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
yy_reduce_print (yyssp, yyvsp, Rule, pParseContext); \
} while (0)
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args) ((void) 0)
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
if the built-in stack extension method is used).
Do not make this value too large; the results are undefined if
YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
evaluated with infinite-precision integer arithmetic. */
#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif
/* Context of a parse error. */
typedef struct
{
yy_state_t *yyssp;
yysymbol_kind_t yytoken;
} yypcontext_t;
/* Put in YYARG at most YYARGN of the expected tokens given the
current YYCTX, and return the number of tokens stored in YYARG. If
YYARG is null, return the number of expected tokens (guaranteed to
be less than YYNTOKENS). Return YYENOMEM on memory exhaustion.
Return 0 if there are more than YYARGN expected tokens, yet fill
YYARG up to YYARGN. */
static int
yypcontext_expected_tokens (const yypcontext_t *yyctx,
yysymbol_kind_t yyarg[], int yyargn)
{
/* Actual size of YYARG. */
int yycount = 0;
int yyn = yypact[+*yyctx->yyssp];
if (!yypact_value_is_default (yyn))
{
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. In other words, skip the first -YYN actions for
this state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = YYLAST - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yyx;
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_YYerror
&& !yytable_value_is_error (yytable[yyx + yyn]))
{
if (!yyarg)
++yycount;
else if (yycount == yyargn)
return 0;
else
yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx);
}
}
if (yyarg && yycount == 0 && 0 < yyargn)
yyarg[0] = YYSYMBOL_YYEMPTY;
return yycount;
}
#ifndef yystrlen
# if defined __GLIBC__ && defined _STRING_H
# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
# else
/* Return the length of YYSTR. */
static YYPTRDIFF_T
yystrlen (const char *yystr)
{
YYPTRDIFF_T yylen;
for (yylen = 0; yystr[yylen]; yylen++)
continue;
return yylen;
}
# endif
#endif
#ifndef yystpcpy
# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
# define yystpcpy stpcpy
# else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
YYDEST. */
static char *
yystpcpy (char *yydest, const char *yysrc)
{
char *yyd = yydest;
const char *yys = yysrc;
while ((*yyd++ = *yys++) != '\0')
continue;
return yyd - 1;
}
# endif
#endif
#ifndef yytnamerr
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
quotes and backslashes, so that it's suitable for yyerror. The
heuristic is that double-quoting is unnecessary unless the string
contains an apostrophe, a comma, or backslash (other than
backslash-backslash). YYSTR is taken from yytname. If YYRES is
null, do not copy; instead, return the length of what the result
would have been. */
static YYPTRDIFF_T
yytnamerr (char *yyres, const char *yystr)
{
if (*yystr == '"')
{
YYPTRDIFF_T yyn = 0;
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
else
goto append;
append:
default:
if (yyres)
yyres[yyn] = *yyp;
yyn++;
break;
case '"':
if (yyres)
yyres[yyn] = '\0';
return yyn;
}
do_not_strip_quotes: ;
}
if (yyres)
return yystpcpy (yyres, yystr) - yyres;
else
return yystrlen (yystr);
}
#endif
static int
yy_syntax_error_arguments (const yypcontext_t *yyctx,
yysymbol_kind_t yyarg[], int yyargn)
{
/* Actual size of YYARG. */
int yycount = 0;
/* There are many possibilities here to consider:
- If this state is a consistent state with a default action, then
the only way this function was invoked is if the default action
is an error action. In that case, don't check for expected
tokens because there are none.
- The only way there can be no lookahead present (in yychar) is if
this state is a consistent state with a default action. Thus,
detecting the absence of a lookahead is sufficient to determine
that there is no unexpected or expected token to report. In that
case, just report a simple "syntax error".
- Don't assume there isn't a lookahead just because this state is a
consistent state with a default action. There might have been a
previous inconsistent state, consistent state with a non-default
action, or user semantic action that manipulated yychar.
- Of course, the expected token list depends on states to have
correct lookahead information, and it depends on the parser not
to perform extra reductions after fetching a lookahead from the
scanner and before detecting a syntax error. Thus, state merging
(from LALR or IELR) and default reductions corrupt the expected
token list. However, the list is correct for canonical LR with
one exception: it will still contain any token that will not be
accepted due to an error action in a later state.
*/
if (yyctx->yytoken != YYSYMBOL_YYEMPTY)
{
int yyn;
if (yyarg)
yyarg[yycount] = yyctx->yytoken;
++yycount;
yyn = yypcontext_expected_tokens (yyctx,
yyarg ? yyarg + 1 : yyarg, yyargn - 1);
if (yyn == YYENOMEM)
return YYENOMEM;
else
yycount += yyn;
}
return yycount;
}
/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
about the unexpected token YYTOKEN for the state stack whose top is
YYSSP.
Return 0 if *YYMSG was successfully written. Return -1 if *YYMSG is
not large enough to hold the message. In that case, also set
*YYMSG_ALLOC to the required number of bytes. Return YYENOMEM if the
required number of bytes is too large to store. */
static int
yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
const yypcontext_t *yyctx)
{
enum { YYARGS_MAX = 5 };
/* Internationalized format string. */
const char *yyformat = YY_NULLPTR;
/* Arguments of yyformat: reported tokens (one for the "unexpected",
one per "expected"). */
yysymbol_kind_t yyarg[YYARGS_MAX];
/* Cumulated lengths of YYARG. */
YYPTRDIFF_T yysize = 0;
/* Actual size of YYARG. */
int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX);
if (yycount == YYENOMEM)
return YYENOMEM;
switch (yycount)
{
#define YYCASE_(N, S) \
case N: \
yyformat = S; \
break
default: /* Avoid compiler warnings. */
YYCASE_(0, YY_("syntax error"));
YYCASE_(1, YY_("syntax error, unexpected %s"));
YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
#undef YYCASE_
}
/* Compute error message size. Don't count the "%s"s, but reserve
room for the terminator. */
yysize = yystrlen (yyformat) - 2 * yycount + 1;
{
int yyi;
for (yyi = 0; yyi < yycount; ++yyi)
{
YYPTRDIFF_T yysize1
= yysize + yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]]);
if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
yysize = yysize1;
else
return YYENOMEM;
}
}
if (*yymsg_alloc < yysize)
{
*yymsg_alloc = 2 * yysize;
if (! (yysize <= *yymsg_alloc
&& *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
*yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
return -1;
}
/* Avoid sprintf, as that infringes on the user's name space.
Don't have undefined behavior even if the translation
produced a string with the wrong number of "%s"s. */
{
char *yyp = *yymsg;
int yyi = 0;
while ((*yyp = *yyformat) != '\0')
if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
{
yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);
yyformat += 2;
}
else
{
++yyp;
++yyformat;
}
}
return 0;
}
/*-----------------------------------------------.
| Release the memory associated to this symbol. |
`-----------------------------------------------*/
static void
yydestruct (const char *yymsg,
yysymbol_kind_t yykind, YYSTYPE *yyvaluep, glslang::TParseContext* pParseContext)
{
YY_USE (yyvaluep);
YY_USE (pParseContext);
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
YY_USE (yykind);
YY_IGNORE_MAYBE_UNINITIALIZED_END
}
/*----------.
| yyparse. |
`----------*/
int
yyparse (glslang::TParseContext* pParseContext)
{
/* Lookahead token kind. */
int yychar;
/* The semantic value of the lookahead symbol. */
/* Default value used for initialization, for pacifying older GCCs
or non-GCC compilers. */
YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
/* Number of syntax errors so far. */
int yynerrs = 0;
yy_state_fast_t yystate = 0;
/* Number of tokens to shift before error messages enabled. */
int yyerrstatus = 0;
/* Refer to the stacks through separate pointers, to allow yyoverflow
to reallocate them elsewhere. */
/* Their size. */
YYPTRDIFF_T yystacksize = YYINITDEPTH;
/* The state stack: array, bottom, top. */
yy_state_t yyssa[YYINITDEPTH];
yy_state_t *yyss = yyssa;
yy_state_t *yyssp = yyss;
/* The semantic value stack: array, bottom, top. */
YYSTYPE yyvsa[YYINITDEPTH];
YYSTYPE *yyvs = yyvsa;
YYSTYPE *yyvsp = yyvs;
int yyn;
/* The return value of yyparse. */
int yyresult;
/* Lookahead symbol kind. */
yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
/* Buffer for error messages, and its allocated size. */
char yymsgbuf[128];
char *yymsg = yymsgbuf;
YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
/* The number of symbols on the RHS of the reduced rule.
Keep to zero when no symbol should be popped. */
int yylen = 0;
YYDPRINTF ((stderr, "Starting parse\n"));
yychar = YYEMPTY; /* Cause a token to be read. */
goto yysetstate;
/*------------------------------------------------------------.
| yynewstate -- push a new state, which is found in yystate. |
`------------------------------------------------------------*/
yynewstate:
/* In all cases, when you get here, the value and location stacks
have just been pushed. So pushing a state here evens the stacks. */
yyssp++;
/*--------------------------------------------------------------------.
| yysetstate -- set current state (the top of the stack) to yystate. |
`--------------------------------------------------------------------*/
yysetstate:
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
YY_IGNORE_USELESS_CAST_BEGIN
*yyssp = YY_CAST (yy_state_t, yystate);
YY_IGNORE_USELESS_CAST_END
YY_STACK_PRINT (yyss, yyssp);
if (yyss + yystacksize - 1 <= yyssp)
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
YYNOMEM;
#else
{
/* Get the current used size of the three stacks, in elements. */
YYPTRDIFF_T yysize = yyssp - yyss + 1;
# if defined yyoverflow
{
/* Give user a chance to reallocate the stack. Use copies of
these so that the &'s don't force the real ones into
memory. */
yy_state_t *yyss1 = yyss;
YYSTYPE *yyvs1 = yyvs;
/* Each stack pointer address is followed by the size of the
data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might
be undefined if yyoverflow is a macro. */
yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * YYSIZEOF (*yyssp),
&yyvs1, yysize * YYSIZEOF (*yyvsp),
&yystacksize);
yyss = yyss1;
yyvs = yyvs1;
}
# else /* defined YYSTACK_RELOCATE */
/* Extend the stack our own way. */
if (YYMAXDEPTH <= yystacksize)
YYNOMEM;
yystacksize *= 2;
if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
{
yy_state_t *yyss1 = yyss;
union yyalloc *yyptr =
YY_CAST (union yyalloc *,
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
if (! yyptr)
YYNOMEM;
YYSTACK_RELOCATE (yyss_alloc, yyss);
YYSTACK_RELOCATE (yyvs_alloc, yyvs);
# undef YYSTACK_RELOCATE
if (yyss1 != yyssa)
YYSTACK_FREE (yyss1);
}
# endif
yyssp = yyss + yysize - 1;
yyvsp = yyvs + yysize - 1;
YY_IGNORE_USELESS_CAST_BEGIN
YYDPRINTF ((stderr, "Stack size increased to %ld\n",
YY_CAST (long, yystacksize)));
YY_IGNORE_USELESS_CAST_END
if (yyss + yystacksize - 1 <= yyssp)
YYABORT;
}
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
if (yystate == YYFINAL)
YYACCEPT;
goto yybackup;
/*-----------.
| yybackup. |
`-----------*/
yybackup:
/* Do appropriate processing given the current state. Read a
lookahead token if we need one and don't already have one. */
/* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate];
if (yypact_value_is_default (yyn))
goto yydefault;
/* Not known => get a lookahead token if don't already have one. */
/* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
if (yychar == YYEMPTY)
{
YYDPRINTF ((stderr, "Reading a token\n"));
yychar = yylex (&yylval, parseContext);
}
if (yychar <= YYEOF)
{
yychar = YYEOF;
yytoken = YYSYMBOL_YYEOF;
YYDPRINTF ((stderr, "Now at end of input.\n"));
}
else if (yychar == YYerror)
{
/* The scanner already issued an error message, process directly
to error recovery. But do not keep the error token as
lookahead, it is too special and may lead us to an endless
loop in error recovery. */
yychar = YYUNDEF;
yytoken = YYSYMBOL_YYerror;
goto yyerrlab1;
}
else
{
yytoken = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
}
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken;
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
goto yydefault;
yyn = yytable[yyn];
if (yyn <= 0)
{
if (yytable_value_is_error (yyn))
goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
/* Count tokens shifted since error; after three, turn off error
status. */
if (yyerrstatus)
yyerrstatus--;
/* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
yystate = yyn;
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
/* Discard the shifted token. */
yychar = YYEMPTY;
goto yynewstate;
/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state. |
`-----------------------------------------------------------*/
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
goto yyreduce;
/*-----------------------------.
| yyreduce -- do a reduction. |
`-----------------------------*/
yyreduce:
/* yyn is the number of a rule to reduce with. */
yylen = yyr2[yyn];
/* If YYLEN is nonzero, implement the default value of the action:
'$$ = $1'.
Otherwise, the following line sets YYVAL to garbage.
This behavior is undocumented and Bison
users should not rely upon it. Assigning to YYVAL
unconditionally makes the parser a bit smaller, and it avoids a
GCC warning that YYVAL may be used uninitialized. */
yyval = yyvsp[1-yylen];
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
case 2: /* variable_identifier: IDENTIFIER */
#line 355 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleVariable((yyvsp[0].lex).loc, (yyvsp[0].lex).symbol, (yyvsp[0].lex).string);
}
#line 5211 "MachineIndependent/glslang_tab.cpp"
break;
case 3: /* primary_expression: variable_identifier */
#line 361 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
#line 5219 "MachineIndependent/glslang_tab.cpp"
break;
case 4: /* primary_expression: LEFT_PAREN expression RIGHT_PAREN */
#line 364 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = (yyvsp[-1].interm.intermTypedNode);
if ((yyval.interm.intermTypedNode)->getAsConstantUnion())
(yyval.interm.intermTypedNode)->getAsConstantUnion()->setExpression();
}
#line 5229 "MachineIndependent/glslang_tab.cpp"
break;
case 5: /* primary_expression: FLOATCONSTANT */
#line 369 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).d, EbtFloat, (yyvsp[0].lex).loc, true);
}
#line 5237 "MachineIndependent/glslang_tab.cpp"
break;
case 6: /* primary_expression: INTCONSTANT */
#line 372 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).i, (yyvsp[0].lex).loc, true);
}
#line 5245 "MachineIndependent/glslang_tab.cpp"
break;
case 7: /* primary_expression: UINTCONSTANT */
#line 375 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "unsigned literal");
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).u, (yyvsp[0].lex).loc, true);
}
#line 5254 "MachineIndependent/glslang_tab.cpp"
break;
case 8: /* primary_expression: BOOLCONSTANT */
#line 379 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).b, (yyvsp[0].lex).loc, true);
}
#line 5262 "MachineIndependent/glslang_tab.cpp"
break;
case 9: /* primary_expression: STRING_LITERAL */
#line 382 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).string, (yyvsp[0].lex).loc, true);
}
#line 5270 "MachineIndependent/glslang_tab.cpp"
break;
case 10: /* primary_expression: INT32CONSTANT */
#line 385 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit signed literal");
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).i, (yyvsp[0].lex).loc, true);
}
#line 5279 "MachineIndependent/glslang_tab.cpp"
break;
case 11: /* primary_expression: UINT32CONSTANT */
#line 389 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit signed literal");
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).u, (yyvsp[0].lex).loc, true);
}
#line 5288 "MachineIndependent/glslang_tab.cpp"
break;
case 12: /* primary_expression: INT64CONSTANT */
#line 393 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit integer literal");
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).i64, (yyvsp[0].lex).loc, true);
}
#line 5297 "MachineIndependent/glslang_tab.cpp"
break;
case 13: /* primary_expression: UINT64CONSTANT */
#line 397 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit unsigned integer literal");
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).u64, (yyvsp[0].lex).loc, true);
}
#line 5306 "MachineIndependent/glslang_tab.cpp"
break;
case 14: /* primary_expression: INT16CONSTANT */
#line 401 "MachineIndependent/glslang.y"
{
parseContext.explicitInt16Check((yyvsp[0].lex).loc, "16-bit integer literal");
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((short)(yyvsp[0].lex).i, (yyvsp[0].lex).loc, true);
}
#line 5315 "MachineIndependent/glslang_tab.cpp"
break;
case 15: /* primary_expression: UINT16CONSTANT */
#line 405 "MachineIndependent/glslang.y"
{
parseContext.explicitInt16Check((yyvsp[0].lex).loc, "16-bit unsigned integer literal");
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((unsigned short)(yyvsp[0].lex).u, (yyvsp[0].lex).loc, true);
}
#line 5324 "MachineIndependent/glslang_tab.cpp"
break;
case 16: /* primary_expression: DOUBLECONSTANT */
#line 409 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double literal");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double literal");
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).d, EbtDouble, (yyvsp[0].lex).loc, true);
}
#line 5335 "MachineIndependent/glslang_tab.cpp"
break;
case 17: /* primary_expression: FLOAT16CONSTANT */
#line 415 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float literal");
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).d, EbtFloat16, (yyvsp[0].lex).loc, true);
}
#line 5344 "MachineIndependent/glslang_tab.cpp"
break;
case 18: /* postfix_expression: primary_expression */
#line 422 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
#line 5352 "MachineIndependent/glslang_tab.cpp"
break;
case 19: /* postfix_expression: postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET */
#line 425 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBracketDereference((yyvsp[-2].lex).loc, (yyvsp[-3].interm.intermTypedNode), (yyvsp[-1].interm.intermTypedNode));
}
#line 5360 "MachineIndependent/glslang_tab.cpp"
break;
case 20: /* postfix_expression: function_call */
#line 428 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
#line 5368 "MachineIndependent/glslang_tab.cpp"
break;
case 21: /* postfix_expression: postfix_expression DOT IDENTIFIER */
#line 431 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleDotDereference((yyvsp[0].lex).loc, (yyvsp[-2].interm.intermTypedNode), *(yyvsp[0].lex).string);
}
#line 5376 "MachineIndependent/glslang_tab.cpp"
break;
case 22: /* postfix_expression: postfix_expression INC_OP */
#line 434 "MachineIndependent/glslang.y"
{
parseContext.variableCheck((yyvsp[-1].interm.intermTypedNode));
parseContext.lValueErrorCheck((yyvsp[0].lex).loc, "++", (yyvsp[-1].interm.intermTypedNode));
(yyval.interm.intermTypedNode) = parseContext.handleUnaryMath((yyvsp[0].lex).loc, "++", EOpPostIncrement, (yyvsp[-1].interm.intermTypedNode));
}
#line 5386 "MachineIndependent/glslang_tab.cpp"
break;
case 23: /* postfix_expression: postfix_expression DEC_OP */
#line 439 "MachineIndependent/glslang.y"
{
parseContext.variableCheck((yyvsp[-1].interm.intermTypedNode));
parseContext.lValueErrorCheck((yyvsp[0].lex).loc, "--", (yyvsp[-1].interm.intermTypedNode));
(yyval.interm.intermTypedNode) = parseContext.handleUnaryMath((yyvsp[0].lex).loc, "--", EOpPostDecrement, (yyvsp[-1].interm.intermTypedNode));
}
#line 5396 "MachineIndependent/glslang_tab.cpp"
break;
case 24: /* integer_expression: expression */
#line 447 "MachineIndependent/glslang.y"
{
parseContext.integerCheck((yyvsp[0].interm.intermTypedNode), "[]");
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
#line 5405 "MachineIndependent/glslang_tab.cpp"
break;
case 25: /* function_call: function_call_or_method */
#line 454 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleFunctionCall((yyvsp[0].interm).loc, (yyvsp[0].interm).function, (yyvsp[0].interm).intermNode);
delete (yyvsp[0].interm).function;
}
#line 5414 "MachineIndependent/glslang_tab.cpp"
break;
case 26: /* function_call_or_method: function_call_generic */
#line 461 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[0].interm);
}
#line 5422 "MachineIndependent/glslang_tab.cpp"
break;
case 27: /* function_call_generic: function_call_header_with_parameters RIGHT_PAREN */
#line 467 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[-1].interm);
(yyval.interm).loc = (yyvsp[0].lex).loc;
}
#line 5431 "MachineIndependent/glslang_tab.cpp"
break;
case 28: /* function_call_generic: function_call_header_no_parameters RIGHT_PAREN */
#line 471 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[-1].interm);
(yyval.interm).loc = (yyvsp[0].lex).loc;
}
#line 5440 "MachineIndependent/glslang_tab.cpp"
break;
case 29: /* function_call_header_no_parameters: function_call_header VOID */
#line 478 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[-1].interm);
}
#line 5448 "MachineIndependent/glslang_tab.cpp"
break;
case 30: /* function_call_header_no_parameters: function_call_header */
#line 481 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[0].interm);
}
#line 5456 "MachineIndependent/glslang_tab.cpp"
break;
case 31: /* function_call_header_with_parameters: function_call_header assignment_expression */
#line 487 "MachineIndependent/glslang.y"
{
if (parseContext.spvVersion.vulkan > 0
&& parseContext.spvVersion.vulkanRelaxed
&& (yyvsp[0].interm.intermTypedNode)->getType().containsOpaque())
{
(yyval.interm).intermNode = parseContext.vkRelaxedRemapFunctionArgument((yyval.interm).loc, (yyvsp[-1].interm).function, (yyvsp[0].interm.intermTypedNode));
(yyval.interm).function = (yyvsp[-1].interm).function;
}
else
{
TParameter param = { 0, new TType, {} };
param.type->shallowCopy((yyvsp[0].interm.intermTypedNode)->getType());
(yyvsp[-1].interm).function->addParameter(param);
(yyval.interm).function = (yyvsp[-1].interm).function;
(yyval.interm).intermNode = (yyvsp[0].interm.intermTypedNode);
}
}
#line 5479 "MachineIndependent/glslang_tab.cpp"
break;
case 32: /* function_call_header_with_parameters: function_call_header_with_parameters COMMA assignment_expression */
#line 505 "MachineIndependent/glslang.y"
{
if (parseContext.spvVersion.vulkan > 0
&& parseContext.spvVersion.vulkanRelaxed
&& (yyvsp[0].interm.intermTypedNode)->getType().containsOpaque())
{
TIntermNode* remappedNode = parseContext.vkRelaxedRemapFunctionArgument((yyvsp[-1].lex).loc, (yyvsp[-2].interm).function, (yyvsp[0].interm.intermTypedNode));
if (remappedNode == (yyvsp[0].interm.intermTypedNode))
(yyval.interm).intermNode = parseContext.intermediate.growAggregate((yyvsp[-2].interm).intermNode, (yyvsp[0].interm.intermTypedNode), (yyvsp[-1].lex).loc);
else
(yyval.interm).intermNode = parseContext.intermediate.mergeAggregate((yyvsp[-2].interm).intermNode, remappedNode, (yyvsp[-1].lex).loc);
(yyval.interm).function = (yyvsp[-2].interm).function;
}
else
{
TParameter param = { 0, new TType, {} };
param.type->shallowCopy((yyvsp[0].interm.intermTypedNode)->getType());
(yyvsp[-2].interm).function->addParameter(param);
(yyval.interm).function = (yyvsp[-2].interm).function;
(yyval.interm).intermNode = parseContext.intermediate.growAggregate((yyvsp[-2].interm).intermNode, (yyvsp[0].interm.intermTypedNode), (yyvsp[-1].lex).loc);
}
}
#line 5506 "MachineIndependent/glslang_tab.cpp"
break;
case 33: /* function_call_header: function_identifier LEFT_PAREN */
#line 530 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[-1].interm);
}
#line 5514 "MachineIndependent/glslang_tab.cpp"
break;
case 34: /* function_identifier: type_specifier */
#line 538 "MachineIndependent/glslang.y"
{
// Constructor
(yyval.interm).intermNode = 0;
(yyval.interm).function = parseContext.handleConstructorCall((yyvsp[0].interm.type).loc, (yyvsp[0].interm.type));
}
#line 5524 "MachineIndependent/glslang_tab.cpp"
break;
case 35: /* function_identifier: postfix_expression */
#line 543 "MachineIndependent/glslang.y"
{
//
// Should be a method or subroutine call, but we haven't recognized the arguments yet.
//
(yyval.interm).function = 0;
(yyval.interm).intermNode = 0;
TIntermMethod* method = (yyvsp[0].interm.intermTypedNode)->getAsMethodNode();
if (method) {
(yyval.interm).function = new TFunction(&method->getMethodName(), TType(EbtInt), EOpArrayLength);
(yyval.interm).intermNode = method->getObject();
} else {
TIntermSymbol* symbol = (yyvsp[0].interm.intermTypedNode)->getAsSymbolNode();
if (symbol) {
parseContext.reservedErrorCheck(symbol->getLoc(), symbol->getName());
TFunction *function = new TFunction(&symbol->getName(), TType(EbtVoid));
(yyval.interm).function = function;
} else
parseContext.error((yyvsp[0].interm.intermTypedNode)->getLoc(), "function call, method, or subroutine call expected", "", "");
}
if ((yyval.interm).function == 0) {
// error recover
TString* empty = NewPoolTString("");
(yyval.interm).function = new TFunction(empty, TType(EbtVoid), EOpNull);
}
}
#line 5556 "MachineIndependent/glslang_tab.cpp"
break;
case 36: /* function_identifier: non_uniform_qualifier */
#line 570 "MachineIndependent/glslang.y"
{
// Constructor
(yyval.interm).intermNode = 0;
(yyval.interm).function = parseContext.handleConstructorCall((yyvsp[0].interm.type).loc, (yyvsp[0].interm.type));
}
#line 5566 "MachineIndependent/glslang_tab.cpp"
break;
case 37: /* unary_expression: postfix_expression */
#line 578 "MachineIndependent/glslang.y"
{
parseContext.variableCheck((yyvsp[0].interm.intermTypedNode));
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
if (TIntermMethod* method = (yyvsp[0].interm.intermTypedNode)->getAsMethodNode())
parseContext.error((yyvsp[0].interm.intermTypedNode)->getLoc(), "incomplete method syntax", method->getMethodName().c_str(), "");
}
#line 5577 "MachineIndependent/glslang_tab.cpp"
break;
case 38: /* unary_expression: INC_OP unary_expression */
#line 584 "MachineIndependent/glslang.y"
{
parseContext.lValueErrorCheck((yyvsp[-1].lex).loc, "++", (yyvsp[0].interm.intermTypedNode));
(yyval.interm.intermTypedNode) = parseContext.handleUnaryMath((yyvsp[-1].lex).loc, "++", EOpPreIncrement, (yyvsp[0].interm.intermTypedNode));
}
#line 5586 "MachineIndependent/glslang_tab.cpp"
break;
case 39: /* unary_expression: DEC_OP unary_expression */
#line 588 "MachineIndependent/glslang.y"
{
parseContext.lValueErrorCheck((yyvsp[-1].lex).loc, "--", (yyvsp[0].interm.intermTypedNode));
(yyval.interm.intermTypedNode) = parseContext.handleUnaryMath((yyvsp[-1].lex).loc, "--", EOpPreDecrement, (yyvsp[0].interm.intermTypedNode));
}
#line 5595 "MachineIndependent/glslang_tab.cpp"
break;
case 40: /* unary_expression: unary_operator unary_expression */
#line 592 "MachineIndependent/glslang.y"
{
if ((yyvsp[-1].interm).op != EOpNull) {
char errorOp[2] = {0, 0};
switch((yyvsp[-1].interm).op) {
case EOpNegative: errorOp[0] = '-'; break;
case EOpLogicalNot: errorOp[0] = '!'; break;
case EOpBitwiseNot: errorOp[0] = '~'; break;
default: break; // some compilers want this
}
(yyval.interm.intermTypedNode) = parseContext.handleUnaryMath((yyvsp[-1].interm).loc, errorOp, (yyvsp[-1].interm).op, (yyvsp[0].interm.intermTypedNode));
} else {
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
if ((yyval.interm.intermTypedNode)->getAsConstantUnion())
(yyval.interm.intermTypedNode)->getAsConstantUnion()->setExpression();
}
}
#line 5616 "MachineIndependent/glslang_tab.cpp"
break;
case 41: /* unary_operator: PLUS */
#line 612 "MachineIndependent/glslang.y"
{ (yyval.interm).loc = (yyvsp[0].lex).loc; (yyval.interm).op = EOpNull; }
#line 5622 "MachineIndependent/glslang_tab.cpp"
break;
case 42: /* unary_operator: DASH */
#line 613 "MachineIndependent/glslang.y"
{ (yyval.interm).loc = (yyvsp[0].lex).loc; (yyval.interm).op = EOpNegative; }
#line 5628 "MachineIndependent/glslang_tab.cpp"
break;
case 43: /* unary_operator: BANG */
#line 614 "MachineIndependent/glslang.y"
{ (yyval.interm).loc = (yyvsp[0].lex).loc; (yyval.interm).op = EOpLogicalNot; }
#line 5634 "MachineIndependent/glslang_tab.cpp"
break;
case 44: /* unary_operator: TILDE */
#line 615 "MachineIndependent/glslang.y"
{ (yyval.interm).loc = (yyvsp[0].lex).loc; (yyval.interm).op = EOpBitwiseNot;
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "bitwise not"); }
#line 5641 "MachineIndependent/glslang_tab.cpp"
break;
case 45: /* multiplicative_expression: unary_expression */
#line 621 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5647 "MachineIndependent/glslang_tab.cpp"
break;
case 46: /* multiplicative_expression: multiplicative_expression STAR unary_expression */
#line 622 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "*", EOpMul, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5657 "MachineIndependent/glslang_tab.cpp"
break;
case 47: /* multiplicative_expression: multiplicative_expression SLASH unary_expression */
#line 627 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "/", EOpDiv, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5667 "MachineIndependent/glslang_tab.cpp"
break;
case 48: /* multiplicative_expression: multiplicative_expression PERCENT unary_expression */
#line 632 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[-1].lex).loc, "%");
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "%", EOpMod, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5678 "MachineIndependent/glslang_tab.cpp"
break;
case 49: /* additive_expression: multiplicative_expression */
#line 641 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5684 "MachineIndependent/glslang_tab.cpp"
break;
case 50: /* additive_expression: additive_expression PLUS multiplicative_expression */
#line 642 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "+", EOpAdd, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5694 "MachineIndependent/glslang_tab.cpp"
break;
case 51: /* additive_expression: additive_expression DASH multiplicative_expression */
#line 647 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "-", EOpSub, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5704 "MachineIndependent/glslang_tab.cpp"
break;
case 52: /* shift_expression: additive_expression */
#line 655 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5710 "MachineIndependent/glslang_tab.cpp"
break;
case 53: /* shift_expression: shift_expression LEFT_OP additive_expression */
#line 656 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[-1].lex).loc, "bit shift left");
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "<<", EOpLeftShift, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5721 "MachineIndependent/glslang_tab.cpp"
break;
case 54: /* shift_expression: shift_expression RIGHT_OP additive_expression */
#line 662 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[-1].lex).loc, "bit shift right");
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, ">>", EOpRightShift, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5732 "MachineIndependent/glslang_tab.cpp"
break;
case 55: /* relational_expression: shift_expression */
#line 671 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5738 "MachineIndependent/glslang_tab.cpp"
break;
case 56: /* relational_expression: relational_expression LEFT_ANGLE shift_expression */
#line 672 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "<", EOpLessThan, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion(false, (yyvsp[-1].lex).loc);
}
#line 5748 "MachineIndependent/glslang_tab.cpp"
break;
case 57: /* relational_expression: relational_expression RIGHT_ANGLE shift_expression */
#line 677 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, ">", EOpGreaterThan, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion(false, (yyvsp[-1].lex).loc);
}
#line 5758 "MachineIndependent/glslang_tab.cpp"
break;
case 58: /* relational_expression: relational_expression LE_OP shift_expression */
#line 682 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "<=", EOpLessThanEqual, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion(false, (yyvsp[-1].lex).loc);
}
#line 5768 "MachineIndependent/glslang_tab.cpp"
break;
case 59: /* relational_expression: relational_expression GE_OP shift_expression */
#line 687 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, ">=", EOpGreaterThanEqual, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion(false, (yyvsp[-1].lex).loc);
}
#line 5778 "MachineIndependent/glslang_tab.cpp"
break;
case 60: /* equality_expression: relational_expression */
#line 695 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5784 "MachineIndependent/glslang_tab.cpp"
break;
case 61: /* equality_expression: equality_expression EQ_OP relational_expression */
#line 696 "MachineIndependent/glslang.y"
{
parseContext.arrayObjectCheck((yyvsp[-1].lex).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "array comparison");
parseContext.opaqueCheck((yyvsp[-1].lex).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "==");
parseContext.specializationCheck((yyvsp[-1].lex).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "==");
parseContext.referenceCheck((yyvsp[-1].lex).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "==");
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "==", EOpEqual, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion(false, (yyvsp[-1].lex).loc);
}
#line 5798 "MachineIndependent/glslang_tab.cpp"
break;
case 62: /* equality_expression: equality_expression NE_OP relational_expression */
#line 705 "MachineIndependent/glslang.y"
{
parseContext.arrayObjectCheck((yyvsp[-1].lex).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "array comparison");
parseContext.opaqueCheck((yyvsp[-1].lex).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "!=");
parseContext.specializationCheck((yyvsp[-1].lex).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "!=");
parseContext.referenceCheck((yyvsp[-1].lex).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "!=");
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "!=", EOpNotEqual, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion(false, (yyvsp[-1].lex).loc);
}
#line 5812 "MachineIndependent/glslang_tab.cpp"
break;
case 63: /* and_expression: equality_expression */
#line 717 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5818 "MachineIndependent/glslang_tab.cpp"
break;
case 64: /* and_expression: and_expression AMPERSAND equality_expression */
#line 718 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[-1].lex).loc, "bitwise and");
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "&", EOpAnd, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5829 "MachineIndependent/glslang_tab.cpp"
break;
case 65: /* exclusive_or_expression: and_expression */
#line 727 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5835 "MachineIndependent/glslang_tab.cpp"
break;
case 66: /* exclusive_or_expression: exclusive_or_expression CARET and_expression */
#line 728 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[-1].lex).loc, "bitwise exclusive or");
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "^", EOpExclusiveOr, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5846 "MachineIndependent/glslang_tab.cpp"
break;
case 67: /* inclusive_or_expression: exclusive_or_expression */
#line 737 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5852 "MachineIndependent/glslang_tab.cpp"
break;
case 68: /* inclusive_or_expression: inclusive_or_expression VERTICAL_BAR exclusive_or_expression */
#line 738 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[-1].lex).loc, "bitwise inclusive or");
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "|", EOpInclusiveOr, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 5863 "MachineIndependent/glslang_tab.cpp"
break;
case 69: /* logical_and_expression: inclusive_or_expression */
#line 747 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5869 "MachineIndependent/glslang_tab.cpp"
break;
case 70: /* logical_and_expression: logical_and_expression AND_OP inclusive_or_expression */
#line 748 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "&&", EOpLogicalAnd, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion(false, (yyvsp[-1].lex).loc);
}
#line 5879 "MachineIndependent/glslang_tab.cpp"
break;
case 71: /* logical_xor_expression: logical_and_expression */
#line 756 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5885 "MachineIndependent/glslang_tab.cpp"
break;
case 72: /* logical_xor_expression: logical_xor_expression XOR_OP logical_and_expression */
#line 757 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "^^", EOpLogicalXor, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion(false, (yyvsp[-1].lex).loc);
}
#line 5895 "MachineIndependent/glslang_tab.cpp"
break;
case 73: /* logical_or_expression: logical_xor_expression */
#line 765 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5901 "MachineIndependent/glslang_tab.cpp"
break;
case 74: /* logical_or_expression: logical_or_expression OR_OP logical_xor_expression */
#line 766 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.handleBinaryMath((yyvsp[-1].lex).loc, "||", EOpLogicalOr, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0)
(yyval.interm.intermTypedNode) = parseContext.intermediate.addConstantUnion(false, (yyvsp[-1].lex).loc);
}
#line 5911 "MachineIndependent/glslang_tab.cpp"
break;
case 75: /* conditional_expression: logical_or_expression */
#line 774 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5917 "MachineIndependent/glslang_tab.cpp"
break;
case 76: /* $@1: %empty */
#line 775 "MachineIndependent/glslang.y"
{
++parseContext.controlFlowNestingLevel;
}
#line 5925 "MachineIndependent/glslang_tab.cpp"
break;
case 77: /* conditional_expression: logical_or_expression QUESTION $@1 expression COLON assignment_expression */
#line 778 "MachineIndependent/glslang.y"
{
--parseContext.controlFlowNestingLevel;
parseContext.boolCheck((yyvsp[-4].lex).loc, (yyvsp[-5].interm.intermTypedNode));
parseContext.rValueErrorCheck((yyvsp[-4].lex).loc, "?", (yyvsp[-5].interm.intermTypedNode));
parseContext.rValueErrorCheck((yyvsp[-1].lex).loc, ":", (yyvsp[-2].interm.intermTypedNode));
parseContext.rValueErrorCheck((yyvsp[-1].lex).loc, ":", (yyvsp[0].interm.intermTypedNode));
(yyval.interm.intermTypedNode) = parseContext.intermediate.addSelection((yyvsp[-5].interm.intermTypedNode), (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yyvsp[-4].lex).loc);
if ((yyval.interm.intermTypedNode) == 0) {
parseContext.binaryOpError((yyvsp[-4].lex).loc, ":", (yyvsp[-2].interm.intermTypedNode)->getCompleteString(parseContext.intermediate.getEnhancedMsgs()), (yyvsp[0].interm.intermTypedNode)->getCompleteString(parseContext.intermediate.getEnhancedMsgs()));
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
}
#line 5942 "MachineIndependent/glslang_tab.cpp"
break;
case 78: /* assignment_expression: conditional_expression */
#line 793 "MachineIndependent/glslang.y"
{ (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); }
#line 5948 "MachineIndependent/glslang_tab.cpp"
break;
case 79: /* assignment_expression: unary_expression assignment_operator assignment_expression */
#line 794 "MachineIndependent/glslang.y"
{
parseContext.arrayObjectCheck((yyvsp[-1].interm).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "array assignment");
parseContext.opaqueCheck((yyvsp[-1].interm).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "=");
parseContext.storage16BitAssignmentCheck((yyvsp[-1].interm).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "=");
parseContext.specializationCheck((yyvsp[-1].interm).loc, (yyvsp[-2].interm.intermTypedNode)->getType(), "=");
parseContext.lValueErrorCheck((yyvsp[-1].interm).loc, "assign", (yyvsp[-2].interm.intermTypedNode));
parseContext.rValueErrorCheck((yyvsp[-1].interm).loc, "assign", (yyvsp[0].interm.intermTypedNode));
(yyval.interm.intermTypedNode) = parseContext.addAssign((yyvsp[-1].interm).loc, (yyvsp[-1].interm).op, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
if ((yyval.interm.intermTypedNode) == 0) {
parseContext.assignError((yyvsp[-1].interm).loc, "assign", (yyvsp[-2].interm.intermTypedNode)->getCompleteString(parseContext.intermediate.getEnhancedMsgs()), (yyvsp[0].interm.intermTypedNode)->getCompleteString(parseContext.intermediate.getEnhancedMsgs()));
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
}
#line 5966 "MachineIndependent/glslang_tab.cpp"
break;
case 80: /* assignment_operator: EQUAL */
#line 810 "MachineIndependent/glslang.y"
{
(yyval.interm).loc = (yyvsp[0].lex).loc;
(yyval.interm).op = EOpAssign;
}
#line 5975 "MachineIndependent/glslang_tab.cpp"
break;
case 81: /* assignment_operator: MUL_ASSIGN */
#line 814 "MachineIndependent/glslang.y"
{
(yyval.interm).loc = (yyvsp[0].lex).loc;
(yyval.interm).op = EOpMulAssign;
}
#line 5984 "MachineIndependent/glslang_tab.cpp"
break;
case 82: /* assignment_operator: DIV_ASSIGN */
#line 818 "MachineIndependent/glslang.y"
{
(yyval.interm).loc = (yyvsp[0].lex).loc;
(yyval.interm).op = EOpDivAssign;
}
#line 5993 "MachineIndependent/glslang_tab.cpp"
break;
case 83: /* assignment_operator: MOD_ASSIGN */
#line 822 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "%=");
(yyval.interm).loc = (yyvsp[0].lex).loc;
(yyval.interm).op = EOpModAssign;
}
#line 6003 "MachineIndependent/glslang_tab.cpp"
break;
case 84: /* assignment_operator: ADD_ASSIGN */
#line 827 "MachineIndependent/glslang.y"
{
(yyval.interm).loc = (yyvsp[0].lex).loc;
(yyval.interm).op = EOpAddAssign;
}
#line 6012 "MachineIndependent/glslang_tab.cpp"
break;
case 85: /* assignment_operator: SUB_ASSIGN */
#line 831 "MachineIndependent/glslang.y"
{
(yyval.interm).loc = (yyvsp[0].lex).loc;
(yyval.interm).op = EOpSubAssign;
}
#line 6021 "MachineIndependent/glslang_tab.cpp"
break;
case 86: /* assignment_operator: LEFT_ASSIGN */
#line 835 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "bit-shift left assign");
(yyval.interm).loc = (yyvsp[0].lex).loc; (yyval.interm).op = EOpLeftShiftAssign;
}
#line 6030 "MachineIndependent/glslang_tab.cpp"
break;
case 87: /* assignment_operator: RIGHT_ASSIGN */
#line 839 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "bit-shift right assign");
(yyval.interm).loc = (yyvsp[0].lex).loc; (yyval.interm).op = EOpRightShiftAssign;
}
#line 6039 "MachineIndependent/glslang_tab.cpp"
break;
case 88: /* assignment_operator: AND_ASSIGN */
#line 843 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "bitwise-and assign");
(yyval.interm).loc = (yyvsp[0].lex).loc; (yyval.interm).op = EOpAndAssign;
}
#line 6048 "MachineIndependent/glslang_tab.cpp"
break;
case 89: /* assignment_operator: XOR_ASSIGN */
#line 847 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "bitwise-xor assign");
(yyval.interm).loc = (yyvsp[0].lex).loc; (yyval.interm).op = EOpExclusiveOrAssign;
}
#line 6057 "MachineIndependent/glslang_tab.cpp"
break;
case 90: /* assignment_operator: OR_ASSIGN */
#line 851 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "bitwise-or assign");
(yyval.interm).loc = (yyvsp[0].lex).loc; (yyval.interm).op = EOpInclusiveOrAssign;
}
#line 6066 "MachineIndependent/glslang_tab.cpp"
break;
case 91: /* expression: assignment_expression */
#line 858 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
#line 6074 "MachineIndependent/glslang_tab.cpp"
break;
case 92: /* expression: expression COMMA assignment_expression */
#line 861 "MachineIndependent/glslang.y"
{
parseContext.samplerConstructorLocationCheck((yyvsp[-1].lex).loc, ",", (yyvsp[0].interm.intermTypedNode));
(yyval.interm.intermTypedNode) = parseContext.intermediate.addComma((yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yyvsp[-1].lex).loc);
if ((yyval.interm.intermTypedNode) == 0) {
parseContext.binaryOpError((yyvsp[-1].lex).loc, ",", (yyvsp[-2].interm.intermTypedNode)->getCompleteString(parseContext.intermediate.getEnhancedMsgs()), (yyvsp[0].interm.intermTypedNode)->getCompleteString(parseContext.intermediate.getEnhancedMsgs()));
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
}
#line 6087 "MachineIndependent/glslang_tab.cpp"
break;
case 93: /* constant_expression: conditional_expression */
#line 872 "MachineIndependent/glslang.y"
{
parseContext.constantValueCheck((yyvsp[0].interm.intermTypedNode), "");
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
#line 6096 "MachineIndependent/glslang_tab.cpp"
break;
case 94: /* declaration: function_prototype SEMICOLON */
#line 879 "MachineIndependent/glslang.y"
{
parseContext.handleFunctionDeclarator((yyvsp[-1].interm).loc, *(yyvsp[-1].interm).function, true /* prototype */);
(yyval.interm.intermNode) = 0;
// TODO: 4.0 functionality: subroutines: make the identifier a user type for this signature
}
#line 6106 "MachineIndependent/glslang_tab.cpp"
break;
case 95: /* declaration: spirv_instruction_qualifier function_prototype SEMICOLON */
#line 884 "MachineIndependent/glslang.y"
{
parseContext.requireExtensions((yyvsp[-1].interm).loc, 1, &E_GL_EXT_spirv_intrinsics, "SPIR-V instruction qualifier");
(yyvsp[-1].interm).function->setSpirvInstruction(*(yyvsp[-2].interm.spirvInst)); // Attach SPIR-V intruction qualifier
parseContext.handleFunctionDeclarator((yyvsp[-1].interm).loc, *(yyvsp[-1].interm).function, true /* prototype */);
(yyval.interm.intermNode) = 0;
// TODO: 4.0 functionality: subroutines: make the identifier a user type for this signature
}
#line 6118 "MachineIndependent/glslang_tab.cpp"
break;
case 96: /* declaration: spirv_execution_mode_qualifier SEMICOLON */
#line 891 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "SPIR-V execution mode qualifier");
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_EXT_spirv_intrinsics, "SPIR-V execution mode qualifier");
(yyval.interm.intermNode) = 0;
}
#line 6128 "MachineIndependent/glslang_tab.cpp"
break;
case 97: /* declaration: init_declarator_list SEMICOLON */
#line 896 "MachineIndependent/glslang.y"
{
if ((yyvsp[-1].interm).intermNode && (yyvsp[-1].interm).intermNode->getAsAggregate())
(yyvsp[-1].interm).intermNode->getAsAggregate()->setOperator(EOpSequence);
(yyval.interm.intermNode) = (yyvsp[-1].interm).intermNode;
}
#line 6138 "MachineIndependent/glslang_tab.cpp"
break;
case 98: /* declaration: PRECISION precision_qualifier type_specifier SEMICOLON */
#line 901 "MachineIndependent/glslang.y"
{
parseContext.profileRequires((yyvsp[-3].lex).loc, ENoProfile, 130, 0, "precision statement");
// lazy setting of the previous scope's defaults, has effect only the first time it is called in a particular scope
parseContext.symbolTable.setPreviousDefaultPrecisions(&parseContext.defaultPrecision[0]);
parseContext.setDefaultPrecision((yyvsp[-3].lex).loc, (yyvsp[-1].interm.type), (yyvsp[-2].interm.type).qualifier.precision);
(yyval.interm.intermNode) = 0;
}
#line 6150 "MachineIndependent/glslang_tab.cpp"
break;
case 99: /* declaration: block_structure SEMICOLON */
#line 908 "MachineIndependent/glslang.y"
{
parseContext.declareBlock((yyvsp[-1].interm).loc, *(yyvsp[-1].interm).typeList);
(yyval.interm.intermNode) = 0;
}
#line 6159 "MachineIndependent/glslang_tab.cpp"
break;
case 100: /* declaration: block_structure IDENTIFIER SEMICOLON */
#line 912 "MachineIndependent/glslang.y"
{
parseContext.declareBlock((yyvsp[-2].interm).loc, *(yyvsp[-2].interm).typeList, (yyvsp[-1].lex).string);
(yyval.interm.intermNode) = 0;
}
#line 6168 "MachineIndependent/glslang_tab.cpp"
break;
case 101: /* declaration: block_structure IDENTIFIER array_specifier SEMICOLON */
#line 916 "MachineIndependent/glslang.y"
{
parseContext.declareBlock((yyvsp[-3].interm).loc, *(yyvsp[-3].interm).typeList, (yyvsp[-2].lex).string, (yyvsp[-1].interm).arraySizes);
(yyval.interm.intermNode) = 0;
}
#line 6177 "MachineIndependent/glslang_tab.cpp"
break;
case 102: /* declaration: type_qualifier SEMICOLON */
#line 920 "MachineIndependent/glslang.y"
{
parseContext.globalQualifierFixCheck((yyvsp[-1].interm.type).loc, (yyvsp[-1].interm.type).qualifier);
parseContext.updateStandaloneQualifierDefaults((yyvsp[-1].interm.type).loc, (yyvsp[-1].interm.type));
(yyval.interm.intermNode) = 0;
}
#line 6187 "MachineIndependent/glslang_tab.cpp"
break;
case 103: /* declaration: type_qualifier IDENTIFIER SEMICOLON */
#line 925 "MachineIndependent/glslang.y"
{
parseContext.checkNoShaderLayouts((yyvsp[-2].interm.type).loc, (yyvsp[-2].interm.type).shaderQualifiers);
parseContext.addQualifierToExisting((yyvsp[-2].interm.type).loc, (yyvsp[-2].interm.type).qualifier, *(yyvsp[-1].lex).string);
(yyval.interm.intermNode) = 0;
}
#line 6197 "MachineIndependent/glslang_tab.cpp"
break;
case 104: /* declaration: type_qualifier IDENTIFIER identifier_list SEMICOLON */
#line 930 "MachineIndependent/glslang.y"
{
parseContext.checkNoShaderLayouts((yyvsp[-3].interm.type).loc, (yyvsp[-3].interm.type).shaderQualifiers);
(yyvsp[-1].interm.identifierList)->push_back((yyvsp[-2].lex).string);
parseContext.addQualifierToExisting((yyvsp[-3].interm.type).loc, (yyvsp[-3].interm.type).qualifier, *(yyvsp[-1].interm.identifierList));
(yyval.interm.intermNode) = 0;
}
#line 6208 "MachineIndependent/glslang_tab.cpp"
break;
case 105: /* $@2: %empty */
#line 939 "MachineIndependent/glslang.y"
{ parseContext.nestedBlockCheck((yyvsp[-2].interm.type).loc); }
#line 6214 "MachineIndependent/glslang_tab.cpp"
break;
case 106: /* block_structure: type_qualifier IDENTIFIER LEFT_BRACE $@2 struct_declaration_list RIGHT_BRACE */
#line 939 "MachineIndependent/glslang.y"
{
--parseContext.blockNestingLevel;
parseContext.blockName = (yyvsp[-4].lex).string;
parseContext.globalQualifierFixCheck((yyvsp[-5].interm.type).loc, (yyvsp[-5].interm.type).qualifier);
parseContext.checkNoShaderLayouts((yyvsp[-5].interm.type).loc, (yyvsp[-5].interm.type).shaderQualifiers);
parseContext.currentBlockQualifier = (yyvsp[-5].interm.type).qualifier;
(yyval.interm).loc = (yyvsp[-5].interm.type).loc;
(yyval.interm).typeList = (yyvsp[-1].interm.typeList);
}
#line 6228 "MachineIndependent/glslang_tab.cpp"
break;
case 107: /* identifier_list: COMMA IDENTIFIER */
#line 950 "MachineIndependent/glslang.y"
{
(yyval.interm.identifierList) = new TIdentifierList;
(yyval.interm.identifierList)->push_back((yyvsp[0].lex).string);
}
#line 6237 "MachineIndependent/glslang_tab.cpp"
break;
case 108: /* identifier_list: identifier_list COMMA IDENTIFIER */
#line 954 "MachineIndependent/glslang.y"
{
(yyval.interm.identifierList) = (yyvsp[-2].interm.identifierList);
(yyval.interm.identifierList)->push_back((yyvsp[0].lex).string);
}
#line 6246 "MachineIndependent/glslang_tab.cpp"
break;
case 109: /* function_prototype: function_declarator RIGHT_PAREN */
#line 961 "MachineIndependent/glslang.y"
{
(yyval.interm).function = (yyvsp[-1].interm.function);
if (parseContext.compileOnly) (yyval.interm).function->setExport();
(yyval.interm).loc = (yyvsp[0].lex).loc;
}
#line 6256 "MachineIndependent/glslang_tab.cpp"
break;
case 110: /* function_prototype: function_declarator RIGHT_PAREN attribute */
#line 966 "MachineIndependent/glslang.y"
{
(yyval.interm).function = (yyvsp[-2].interm.function);
if (parseContext.compileOnly) (yyval.interm).function->setExport();
(yyval.interm).loc = (yyvsp[-1].lex).loc;
const char * extensions[2] = { E_GL_EXT_subgroup_uniform_control_flow, E_GL_EXT_maximal_reconvergence };
parseContext.requireExtensions((yyvsp[-1].lex).loc, 2, extensions, "attribute");
parseContext.handleFunctionAttributes((yyvsp[-1].lex).loc, *(yyvsp[0].interm.attributes));
}
#line 6269 "MachineIndependent/glslang_tab.cpp"
break;
case 111: /* function_prototype: attribute function_declarator RIGHT_PAREN */
#line 974 "MachineIndependent/glslang.y"
{
(yyval.interm).function = (yyvsp[-1].interm.function);
if (parseContext.compileOnly) (yyval.interm).function->setExport();
(yyval.interm).loc = (yyvsp[0].lex).loc;
const char * extensions[2] = { E_GL_EXT_subgroup_uniform_control_flow, E_GL_EXT_maximal_reconvergence };
parseContext.requireExtensions((yyvsp[0].lex).loc, 2, extensions, "attribute");
parseContext.handleFunctionAttributes((yyvsp[0].lex).loc, *(yyvsp[-2].interm.attributes));
}
#line 6282 "MachineIndependent/glslang_tab.cpp"
break;
case 112: /* function_prototype: attribute function_declarator RIGHT_PAREN attribute */
#line 982 "MachineIndependent/glslang.y"
{
(yyval.interm).function = (yyvsp[-2].interm.function);
if (parseContext.compileOnly) (yyval.interm).function->setExport();
(yyval.interm).loc = (yyvsp[-1].lex).loc;
const char * extensions[2] = { E_GL_EXT_subgroup_uniform_control_flow, E_GL_EXT_maximal_reconvergence };
parseContext.requireExtensions((yyvsp[-1].lex).loc, 2, extensions, "attribute");
parseContext.handleFunctionAttributes((yyvsp[-1].lex).loc, *(yyvsp[-3].interm.attributes));
parseContext.handleFunctionAttributes((yyvsp[-1].lex).loc, *(yyvsp[0].interm.attributes));
}
#line 6296 "MachineIndependent/glslang_tab.cpp"
break;
case 113: /* function_declarator: function_header */
#line 994 "MachineIndependent/glslang.y"
{
(yyval.interm.function) = (yyvsp[0].interm.function);
}
#line 6304 "MachineIndependent/glslang_tab.cpp"
break;
case 114: /* function_declarator: function_header_with_parameters */
#line 997 "MachineIndependent/glslang.y"
{
(yyval.interm.function) = (yyvsp[0].interm.function);
}
#line 6312 "MachineIndependent/glslang_tab.cpp"
break;
case 115: /* function_header_with_parameters: function_header parameter_declaration */
#line 1004 "MachineIndependent/glslang.y"
{
// Add the parameter
(yyval.interm.function) = (yyvsp[-1].interm.function);
if ((yyvsp[0].interm).param.type->getBasicType() != EbtVoid)
{
if (!(parseContext.spvVersion.vulkan > 0 && parseContext.spvVersion.vulkanRelaxed))
(yyvsp[-1].interm.function)->addParameter((yyvsp[0].interm).param);
else
parseContext.vkRelaxedRemapFunctionParameter((yyvsp[-1].interm.function), (yyvsp[0].interm).param);
}
else
delete (yyvsp[0].interm).param.type;
}
#line 6330 "MachineIndependent/glslang_tab.cpp"
break;
case 116: /* function_header_with_parameters: function_header_with_parameters COMMA parameter_declaration */
#line 1017 "MachineIndependent/glslang.y"
{
//
// Only first parameter of one-parameter functions can be void
// The check for named parameters not being void is done in parameter_declarator
//
if ((yyvsp[0].interm).param.type->getBasicType() == EbtVoid) {
//
// This parameter > first is void
//
parseContext.error((yyvsp[-1].lex).loc, "cannot be an argument type except for '(void)'", "void", "");
delete (yyvsp[0].interm).param.type;
} else {
// Add the parameter
(yyval.interm.function) = (yyvsp[-2].interm.function);
if (!(parseContext.spvVersion.vulkan > 0 && parseContext.spvVersion.vulkanRelaxed))
(yyvsp[-2].interm.function)->addParameter((yyvsp[0].interm).param);
else
parseContext.vkRelaxedRemapFunctionParameter((yyvsp[-2].interm.function), (yyvsp[0].interm).param);
}
}
#line 6355 "MachineIndependent/glslang_tab.cpp"
break;
case 117: /* function_header: fully_specified_type IDENTIFIER LEFT_PAREN */
#line 1040 "MachineIndependent/glslang.y"
{
if ((yyvsp[-2].interm.type).qualifier.storage != EvqGlobal && (yyvsp[-2].interm.type).qualifier.storage != EvqTemporary) {
parseContext.error((yyvsp[-1].lex).loc, "no qualifiers allowed for function return",
GetStorageQualifierString((yyvsp[-2].interm.type).qualifier.storage), "");
}
if ((yyvsp[-2].interm.type).arraySizes)
parseContext.arraySizeRequiredCheck((yyvsp[-2].interm.type).loc, *(yyvsp[-2].interm.type).arraySizes);
// Add the function as a prototype after parsing it (we do not support recursion)
TFunction *function;
TType type((yyvsp[-2].interm.type));
// Potentially rename shader entry point function. No-op most of the time.
parseContext.renameShaderFunction((yyvsp[-1].lex).string);
// Make the function
function = new TFunction((yyvsp[-1].lex).string, type);
(yyval.interm.function) = function;
}
#line 6379 "MachineIndependent/glslang_tab.cpp"
break;
case 118: /* parameter_declarator: type_specifier IDENTIFIER */
#line 1063 "MachineIndependent/glslang.y"
{
if ((yyvsp[-1].interm.type).arraySizes) {
parseContext.profileRequires((yyvsp[-1].interm.type).loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
parseContext.profileRequires((yyvsp[-1].interm.type).loc, EEsProfile, 300, 0, "arrayed type");
parseContext.arraySizeRequiredCheck((yyvsp[-1].interm.type).loc, *(yyvsp[-1].interm.type).arraySizes);
}
if ((yyvsp[-1].interm.type).basicType == EbtVoid) {
parseContext.error((yyvsp[0].lex).loc, "illegal use of type 'void'", (yyvsp[0].lex).string->c_str(), "");
}
parseContext.reservedErrorCheck((yyvsp[0].lex).loc, *(yyvsp[0].lex).string);
TParameter param = {(yyvsp[0].lex).string, new TType((yyvsp[-1].interm.type)), {}};
(yyval.interm).loc = (yyvsp[0].lex).loc;
(yyval.interm).param = param;
}
#line 6399 "MachineIndependent/glslang_tab.cpp"
break;
case 119: /* parameter_declarator: type_specifier IDENTIFIER array_specifier */
#line 1078 "MachineIndependent/glslang.y"
{
if ((yyvsp[-2].interm.type).arraySizes) {
parseContext.profileRequires((yyvsp[-2].interm.type).loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
parseContext.profileRequires((yyvsp[-2].interm.type).loc, EEsProfile, 300, 0, "arrayed type");
parseContext.arraySizeRequiredCheck((yyvsp[-2].interm.type).loc, *(yyvsp[-2].interm.type).arraySizes);
}
TType* type = new TType((yyvsp[-2].interm.type));
type->transferArraySizes((yyvsp[0].interm).arraySizes);
type->copyArrayInnerSizes((yyvsp[-2].interm.type).arraySizes);
parseContext.arrayOfArrayVersionCheck((yyvsp[-1].lex).loc, type->getArraySizes());
parseContext.arraySizeRequiredCheck((yyvsp[0].interm).loc, *(yyvsp[0].interm).arraySizes);
parseContext.reservedErrorCheck((yyvsp[-1].lex).loc, *(yyvsp[-1].lex).string);
TParameter param = { (yyvsp[-1].lex).string, type, {} };
(yyval.interm).loc = (yyvsp[-1].lex).loc;
(yyval.interm).param = param;
}
#line 6423 "MachineIndependent/glslang_tab.cpp"
break;
case 120: /* parameter_declaration: type_qualifier parameter_declarator */
#line 1103 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[0].interm);
if ((yyvsp[-1].interm.type).qualifier.precision != EpqNone)
(yyval.interm).param.type->getQualifier().precision = (yyvsp[-1].interm.type).qualifier.precision;
parseContext.precisionQualifierCheck((yyval.interm).loc, (yyval.interm).param.type->getBasicType(), (yyval.interm).param.type->getQualifier(), (yyval.interm).param.type->isCoopMat());
parseContext.checkNoShaderLayouts((yyvsp[-1].interm.type).loc, (yyvsp[-1].interm.type).shaderQualifiers);
parseContext.parameterTypeCheck((yyvsp[0].interm).loc, (yyvsp[-1].interm.type).qualifier.storage, *(yyval.interm).param.type);
parseContext.paramCheckFix((yyvsp[-1].interm.type).loc, (yyvsp[-1].interm.type).qualifier, *(yyval.interm).param.type);
}
#line 6439 "MachineIndependent/glslang_tab.cpp"
break;
case 121: /* parameter_declaration: parameter_declarator */
#line 1114 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[0].interm);
parseContext.parameterTypeCheck((yyvsp[0].interm).loc, EvqIn, *(yyvsp[0].interm).param.type);
parseContext.paramCheckFixStorage((yyvsp[0].interm).loc, EvqTemporary, *(yyval.interm).param.type);
parseContext.precisionQualifierCheck((yyval.interm).loc, (yyval.interm).param.type->getBasicType(), (yyval.interm).param.type->getQualifier(), (yyval.interm).param.type->isCoopMat());
}
#line 6451 "MachineIndependent/glslang_tab.cpp"
break;
case 122: /* parameter_declaration: type_qualifier parameter_type_specifier */
#line 1124 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[0].interm);
if ((yyvsp[-1].interm.type).qualifier.precision != EpqNone)
(yyval.interm).param.type->getQualifier().precision = (yyvsp[-1].interm.type).qualifier.precision;
parseContext.precisionQualifierCheck((yyvsp[-1].interm.type).loc, (yyval.interm).param.type->getBasicType(), (yyval.interm).param.type->getQualifier(), (yyval.interm).param.type->isCoopMat());
parseContext.checkNoShaderLayouts((yyvsp[-1].interm.type).loc, (yyvsp[-1].interm.type).shaderQualifiers);
parseContext.parameterTypeCheck((yyvsp[0].interm).loc, (yyvsp[-1].interm.type).qualifier.storage, *(yyval.interm).param.type);
parseContext.paramCheckFix((yyvsp[-1].interm.type).loc, (yyvsp[-1].interm.type).qualifier, *(yyval.interm).param.type);
}
#line 6466 "MachineIndependent/glslang_tab.cpp"
break;
case 123: /* parameter_declaration: parameter_type_specifier */
#line 1134 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[0].interm);
parseContext.parameterTypeCheck((yyvsp[0].interm).loc, EvqIn, *(yyvsp[0].interm).param.type);
parseContext.paramCheckFixStorage((yyvsp[0].interm).loc, EvqTemporary, *(yyval.interm).param.type);
parseContext.precisionQualifierCheck((yyval.interm).loc, (yyval.interm).param.type->getBasicType(), (yyval.interm).param.type->getQualifier(), (yyval.interm).param.type->isCoopMat());
}
#line 6478 "MachineIndependent/glslang_tab.cpp"
break;
case 124: /* parameter_type_specifier: type_specifier */
#line 1144 "MachineIndependent/glslang.y"
{
TParameter param = { 0, new TType((yyvsp[0].interm.type)), {} };
(yyval.interm).param = param;
if ((yyvsp[0].interm.type).arraySizes)
parseContext.arraySizeRequiredCheck((yyvsp[0].interm.type).loc, *(yyvsp[0].interm.type).arraySizes);
}
#line 6489 "MachineIndependent/glslang_tab.cpp"
break;
case 125: /* init_declarator_list: single_declaration */
#line 1153 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[0].interm);
}
#line 6497 "MachineIndependent/glslang_tab.cpp"
break;
case 126: /* init_declarator_list: init_declarator_list COMMA IDENTIFIER */
#line 1156 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[-2].interm);
parseContext.declareVariable((yyvsp[0].lex).loc, *(yyvsp[0].lex).string, (yyvsp[-2].interm).type);
}
#line 6506 "MachineIndependent/glslang_tab.cpp"
break;
case 127: /* init_declarator_list: init_declarator_list COMMA IDENTIFIER array_specifier */
#line 1160 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[-3].interm);
parseContext.declareVariable((yyvsp[-1].lex).loc, *(yyvsp[-1].lex).string, (yyvsp[-3].interm).type, (yyvsp[0].interm).arraySizes);
}
#line 6515 "MachineIndependent/glslang_tab.cpp"
break;
case 128: /* init_declarator_list: init_declarator_list COMMA IDENTIFIER array_specifier EQUAL initializer */
#line 1164 "MachineIndependent/glslang.y"
{
(yyval.interm).type = (yyvsp[-5].interm).type;
TIntermNode* initNode = parseContext.declareVariable((yyvsp[-3].lex).loc, *(yyvsp[-3].lex).string, (yyvsp[-5].interm).type, (yyvsp[-2].interm).arraySizes, (yyvsp[0].interm.intermTypedNode));
(yyval.interm).intermNode = parseContext.intermediate.growAggregate((yyvsp[-5].interm).intermNode, initNode, (yyvsp[-1].lex).loc);
}
#line 6525 "MachineIndependent/glslang_tab.cpp"
break;
case 129: /* init_declarator_list: init_declarator_list COMMA IDENTIFIER EQUAL initializer */
#line 1169 "MachineIndependent/glslang.y"
{
(yyval.interm).type = (yyvsp[-4].interm).type;
TIntermNode* initNode = parseContext.declareVariable((yyvsp[-2].lex).loc, *(yyvsp[-2].lex).string, (yyvsp[-4].interm).type, 0, (yyvsp[0].interm.intermTypedNode));
(yyval.interm).intermNode = parseContext.intermediate.growAggregate((yyvsp[-4].interm).intermNode, initNode, (yyvsp[-1].lex).loc);
}
#line 6535 "MachineIndependent/glslang_tab.cpp"
break;
case 130: /* single_declaration: fully_specified_type */
#line 1177 "MachineIndependent/glslang.y"
{
(yyval.interm).type = (yyvsp[0].interm.type);
(yyval.interm).intermNode = 0;
parseContext.declareTypeDefaults((yyval.interm).loc, (yyval.interm).type);
}
#line 6545 "MachineIndependent/glslang_tab.cpp"
break;
case 131: /* single_declaration: fully_specified_type IDENTIFIER */
#line 1182 "MachineIndependent/glslang.y"
{
(yyval.interm).type = (yyvsp[-1].interm.type);
(yyval.interm).intermNode = 0;
parseContext.declareVariable((yyvsp[0].lex).loc, *(yyvsp[0].lex).string, (yyvsp[-1].interm.type));
}
#line 6555 "MachineIndependent/glslang_tab.cpp"
break;
case 132: /* single_declaration: fully_specified_type IDENTIFIER array_specifier */
#line 1187 "MachineIndependent/glslang.y"
{
(yyval.interm).type = (yyvsp[-2].interm.type);
(yyval.interm).intermNode = 0;
parseContext.declareVariable((yyvsp[-1].lex).loc, *(yyvsp[-1].lex).string, (yyvsp[-2].interm.type), (yyvsp[0].interm).arraySizes);
}
#line 6565 "MachineIndependent/glslang_tab.cpp"
break;
case 133: /* single_declaration: fully_specified_type IDENTIFIER array_specifier EQUAL initializer */
#line 1192 "MachineIndependent/glslang.y"
{
(yyval.interm).type = (yyvsp[-4].interm.type);
TIntermNode* initNode = parseContext.declareVariable((yyvsp[-3].lex).loc, *(yyvsp[-3].lex).string, (yyvsp[-4].interm.type), (yyvsp[-2].interm).arraySizes, (yyvsp[0].interm.intermTypedNode));
(yyval.interm).intermNode = parseContext.intermediate.growAggregate(0, initNode, (yyvsp[-1].lex).loc);
}
#line 6575 "MachineIndependent/glslang_tab.cpp"
break;
case 134: /* single_declaration: fully_specified_type IDENTIFIER EQUAL initializer */
#line 1197 "MachineIndependent/glslang.y"
{
(yyval.interm).type = (yyvsp[-3].interm.type);
TIntermNode* initNode = parseContext.declareVariable((yyvsp[-2].lex).loc, *(yyvsp[-2].lex).string, (yyvsp[-3].interm.type), 0, (yyvsp[0].interm.intermTypedNode));
(yyval.interm).intermNode = parseContext.intermediate.growAggregate(0, initNode, (yyvsp[-1].lex).loc);
}
#line 6585 "MachineIndependent/glslang_tab.cpp"
break;
case 135: /* fully_specified_type: type_specifier */
#line 1206 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[0].interm.type);
parseContext.globalQualifierTypeCheck((yyvsp[0].interm.type).loc, (yyvsp[0].interm.type).qualifier, (yyval.interm.type));
if ((yyvsp[0].interm.type).arraySizes) {
parseContext.profileRequires((yyvsp[0].interm.type).loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
parseContext.profileRequires((yyvsp[0].interm.type).loc, EEsProfile, 300, 0, "arrayed type");
}
parseContext.precisionQualifierCheck((yyval.interm.type).loc, (yyval.interm.type).basicType, (yyval.interm.type).qualifier, (yyval.interm.type).isCoopmat());
}
#line 6600 "MachineIndependent/glslang_tab.cpp"
break;
case 136: /* fully_specified_type: type_qualifier type_specifier */
#line 1216 "MachineIndependent/glslang.y"
{
parseContext.globalQualifierFixCheck((yyvsp[-1].interm.type).loc, (yyvsp[-1].interm.type).qualifier, false, &(yyvsp[0].interm.type));
parseContext.globalQualifierTypeCheck((yyvsp[-1].interm.type).loc, (yyvsp[-1].interm.type).qualifier, (yyvsp[0].interm.type));
if ((yyvsp[0].interm.type).arraySizes) {
parseContext.profileRequires((yyvsp[0].interm.type).loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
parseContext.profileRequires((yyvsp[0].interm.type).loc, EEsProfile, 300, 0, "arrayed type");
}
if ((yyvsp[0].interm.type).arraySizes && parseContext.arrayQualifierError((yyvsp[0].interm.type).loc, (yyvsp[-1].interm.type).qualifier))
(yyvsp[0].interm.type).arraySizes = nullptr;
parseContext.checkNoShaderLayouts((yyvsp[0].interm.type).loc, (yyvsp[-1].interm.type).shaderQualifiers);
(yyvsp[0].interm.type).shaderQualifiers.merge((yyvsp[-1].interm.type).shaderQualifiers);
parseContext.mergeQualifiers((yyvsp[0].interm.type).loc, (yyvsp[0].interm.type).qualifier, (yyvsp[-1].interm.type).qualifier, true);
parseContext.precisionQualifierCheck((yyvsp[0].interm.type).loc, (yyvsp[0].interm.type).basicType, (yyvsp[0].interm.type).qualifier, (yyvsp[0].interm.type).isCoopmat());
(yyval.interm.type) = (yyvsp[0].interm.type);
if (! (yyval.interm.type).qualifier.isInterpolation() &&
((parseContext.language == EShLangVertex && (yyval.interm.type).qualifier.storage == EvqVaryingOut) ||
(parseContext.language == EShLangFragment && (yyval.interm.type).qualifier.storage == EvqVaryingIn)))
(yyval.interm.type).qualifier.smooth = true;
}
#line 6629 "MachineIndependent/glslang_tab.cpp"
break;
case 137: /* invariant_qualifier: INVARIANT */
#line 1243 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "invariant");
parseContext.profileRequires((yyval.interm.type).loc, ENoProfile, 120, 0, "invariant");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.invariant = true;
}
#line 6640 "MachineIndependent/glslang_tab.cpp"
break;
case 138: /* interpolation_qualifier: SMOOTH */
#line 1252 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "smooth");
parseContext.profileRequires((yyvsp[0].lex).loc, ENoProfile, 130, 0, "smooth");
parseContext.profileRequires((yyvsp[0].lex).loc, EEsProfile, 300, 0, "smooth");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.smooth = true;
}
#line 6652 "MachineIndependent/glslang_tab.cpp"
break;
case 139: /* interpolation_qualifier: FLAT */
#line 1259 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "flat");
parseContext.profileRequires((yyvsp[0].lex).loc, ENoProfile, 130, 0, "flat");
parseContext.profileRequires((yyvsp[0].lex).loc, EEsProfile, 300, 0, "flat");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.flat = true;
}
#line 6664 "MachineIndependent/glslang_tab.cpp"
break;
case 140: /* interpolation_qualifier: NOPERSPECTIVE */
#line 1266 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "noperspective");
parseContext.profileRequires((yyvsp[0].lex).loc, EEsProfile, 0, E_GL_NV_shader_noperspective_interpolation, "noperspective");
parseContext.profileRequires((yyvsp[0].lex).loc, ENoProfile, 130, 0, "noperspective");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.nopersp = true;
}
#line 6676 "MachineIndependent/glslang_tab.cpp"
break;
case 141: /* interpolation_qualifier: EXPLICITINTERPAMD */
#line 1273 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "__explicitInterpAMD");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 450, E_GL_AMD_shader_explicit_vertex_parameter, "explicit interpolation");
parseContext.profileRequires((yyvsp[0].lex).loc, ECompatibilityProfile, 450, E_GL_AMD_shader_explicit_vertex_parameter, "explicit interpolation");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.explicitInterp = true;
}
#line 6688 "MachineIndependent/glslang_tab.cpp"
break;
case 142: /* interpolation_qualifier: PERVERTEXNV */
#line 1280 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "pervertexNV");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 0, E_GL_NV_fragment_shader_barycentric, "fragment shader barycentric");
parseContext.profileRequires((yyvsp[0].lex).loc, ECompatibilityProfile, 0, E_GL_NV_fragment_shader_barycentric, "fragment shader barycentric");
parseContext.profileRequires((yyvsp[0].lex).loc, EEsProfile, 0, E_GL_NV_fragment_shader_barycentric, "fragment shader barycentric");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.pervertexNV = true;
}
#line 6701 "MachineIndependent/glslang_tab.cpp"
break;
case 143: /* interpolation_qualifier: PERVERTEXEXT */
#line 1288 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "pervertexEXT");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 0, E_GL_EXT_fragment_shader_barycentric, "fragment shader barycentric");
parseContext.profileRequires((yyvsp[0].lex).loc, ECompatibilityProfile, 0, E_GL_EXT_fragment_shader_barycentric, "fragment shader barycentric");
parseContext.profileRequires((yyvsp[0].lex).loc, EEsProfile, 0, E_GL_EXT_fragment_shader_barycentric, "fragment shader barycentric");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.pervertexEXT = true;
}
#line 6714 "MachineIndependent/glslang_tab.cpp"
break;
case 144: /* interpolation_qualifier: PERPRIMITIVENV */
#line 1296 "MachineIndependent/glslang.y"
{
// No need for profile version or extension check. Shader stage already checks both.
parseContext.globalCheck((yyvsp[0].lex).loc, "perprimitiveNV");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangFragmentMask | EShLangMeshMask), "perprimitiveNV");
// Fragment shader stage doesn't check for extension. So we explicitly add below extension check.
if (parseContext.language == EShLangFragment)
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_NV_mesh_shader, "perprimitiveNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.perPrimitiveNV = true;
}
#line 6729 "MachineIndependent/glslang_tab.cpp"
break;
case 145: /* interpolation_qualifier: PERPRIMITIVEEXT */
#line 1306 "MachineIndependent/glslang.y"
{
// No need for profile version or extension check. Shader stage already checks both.
parseContext.globalCheck((yyvsp[0].lex).loc, "perprimitiveEXT");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangFragmentMask | EShLangMeshMask), "perprimitiveEXT");
// Fragment shader stage doesn't check for extension. So we explicitly add below extension check.
if (parseContext.language == EShLangFragment)
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_EXT_mesh_shader, "perprimitiveEXT");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.perPrimitiveNV = true;
}
#line 6744 "MachineIndependent/glslang_tab.cpp"
break;
case 146: /* interpolation_qualifier: PERVIEWNV */
#line 1316 "MachineIndependent/glslang.y"
{
// No need for profile version or extension check. Shader stage already checks both.
parseContext.globalCheck((yyvsp[0].lex).loc, "perviewNV");
parseContext.requireStage((yyvsp[0].lex).loc, EShLangMesh, "perviewNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.perViewNV = true;
}
#line 6756 "MachineIndependent/glslang_tab.cpp"
break;
case 147: /* interpolation_qualifier: PERTASKNV */
#line 1323 "MachineIndependent/glslang.y"
{
// No need for profile version or extension check. Shader stage already checks both.
parseContext.globalCheck((yyvsp[0].lex).loc, "taskNV");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangTaskMask | EShLangMeshMask), "taskNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.perTaskNV = true;
}
#line 6768 "MachineIndependent/glslang_tab.cpp"
break;
case 148: /* layout_qualifier: LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN */
#line 1333 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[-1].interm.type);
}
#line 6776 "MachineIndependent/glslang_tab.cpp"
break;
case 149: /* layout_qualifier_id_list: layout_qualifier_id */
#line 1339 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6784 "MachineIndependent/glslang_tab.cpp"
break;
case 150: /* layout_qualifier_id_list: layout_qualifier_id_list COMMA layout_qualifier_id */
#line 1342 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[-2].interm.type);
(yyval.interm.type).shaderQualifiers.merge((yyvsp[0].interm.type).shaderQualifiers);
parseContext.mergeObjectLayoutQualifiers((yyval.interm.type).qualifier, (yyvsp[0].interm.type).qualifier, false);
}
#line 6794 "MachineIndependent/glslang_tab.cpp"
break;
case 151: /* layout_qualifier_id: IDENTIFIER */
#line 1349 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
parseContext.setLayoutQualifier((yyvsp[0].lex).loc, (yyval.interm.type), *(yyvsp[0].lex).string);
}
#line 6803 "MachineIndependent/glslang_tab.cpp"
break;
case 152: /* layout_qualifier_id: IDENTIFIER EQUAL constant_expression */
#line 1353 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-2].lex).loc);
parseContext.setLayoutQualifier((yyvsp[-2].lex).loc, (yyval.interm.type), *(yyvsp[-2].lex).string, (yyvsp[0].interm.intermTypedNode));
}
#line 6812 "MachineIndependent/glslang_tab.cpp"
break;
case 153: /* layout_qualifier_id: SHARED */
#line 1357 "MachineIndependent/glslang.y"
{ // because "shared" is both an identifier and a keyword
(yyval.interm.type).init((yyvsp[0].lex).loc);
TString strShared("shared");
parseContext.setLayoutQualifier((yyvsp[0].lex).loc, (yyval.interm.type), strShared);
}
#line 6822 "MachineIndependent/glslang_tab.cpp"
break;
case 154: /* precise_qualifier: PRECISE */
#line 1365 "MachineIndependent/glslang.y"
{
parseContext.profileRequires((yyval.interm.type).loc, ECoreProfile | ECompatibilityProfile, 400, E_GL_ARB_gpu_shader5, "precise");
parseContext.profileRequires((yyvsp[0].lex).loc, EEsProfile, 320, Num_AEP_gpu_shader5, AEP_gpu_shader5, "precise");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.noContraction = true;
}
#line 6833 "MachineIndependent/glslang_tab.cpp"
break;
case 155: /* type_qualifier: single_type_qualifier */
#line 1374 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6841 "MachineIndependent/glslang_tab.cpp"
break;
case 156: /* type_qualifier: type_qualifier single_type_qualifier */
#line 1377 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[-1].interm.type);
if ((yyval.interm.type).basicType == EbtVoid)
(yyval.interm.type).basicType = (yyvsp[0].interm.type).basicType;
(yyval.interm.type).shaderQualifiers.merge((yyvsp[0].interm.type).shaderQualifiers);
parseContext.mergeQualifiers((yyval.interm.type).loc, (yyval.interm.type).qualifier, (yyvsp[0].interm.type).qualifier, false);
}
#line 6854 "MachineIndependent/glslang_tab.cpp"
break;
case 157: /* single_type_qualifier: storage_qualifier */
#line 1388 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6862 "MachineIndependent/glslang_tab.cpp"
break;
case 158: /* single_type_qualifier: layout_qualifier */
#line 1391 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6870 "MachineIndependent/glslang_tab.cpp"
break;
case 159: /* single_type_qualifier: precision_qualifier */
#line 1394 "MachineIndependent/glslang.y"
{
parseContext.checkPrecisionQualifier((yyvsp[0].interm.type).loc, (yyvsp[0].interm.type).qualifier.precision);
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6879 "MachineIndependent/glslang_tab.cpp"
break;
case 160: /* single_type_qualifier: interpolation_qualifier */
#line 1398 "MachineIndependent/glslang.y"
{
// allow inheritance of storage qualifier from block declaration
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6888 "MachineIndependent/glslang_tab.cpp"
break;
case 161: /* single_type_qualifier: invariant_qualifier */
#line 1402 "MachineIndependent/glslang.y"
{
// allow inheritance of storage qualifier from block declaration
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6897 "MachineIndependent/glslang_tab.cpp"
break;
case 162: /* single_type_qualifier: precise_qualifier */
#line 1406 "MachineIndependent/glslang.y"
{
// allow inheritance of storage qualifier from block declaration
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6906 "MachineIndependent/glslang_tab.cpp"
break;
case 163: /* single_type_qualifier: non_uniform_qualifier */
#line 1410 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6914 "MachineIndependent/glslang_tab.cpp"
break;
case 164: /* single_type_qualifier: spirv_storage_class_qualifier */
#line 1413 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].interm.type).loc, "spirv_storage_class");
parseContext.requireExtensions((yyvsp[0].interm.type).loc, 1, &E_GL_EXT_spirv_intrinsics, "SPIR-V storage class qualifier");
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6924 "MachineIndependent/glslang_tab.cpp"
break;
case 165: /* single_type_qualifier: spirv_decorate_qualifier */
#line 1418 "MachineIndependent/glslang.y"
{
parseContext.requireExtensions((yyvsp[0].interm.type).loc, 1, &E_GL_EXT_spirv_intrinsics, "SPIR-V decorate qualifier");
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 6933 "MachineIndependent/glslang_tab.cpp"
break;
case 166: /* single_type_qualifier: SPIRV_BY_REFERENCE */
#line 1422 "MachineIndependent/glslang.y"
{
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_EXT_spirv_intrinsics, "spirv_by_reference");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.setSpirvByReference();
}
#line 6943 "MachineIndependent/glslang_tab.cpp"
break;
case 167: /* single_type_qualifier: SPIRV_LITERAL */
#line 1427 "MachineIndependent/glslang.y"
{
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_EXT_spirv_intrinsics, "spirv_by_literal");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.setSpirvLiteral();
}
#line 6953 "MachineIndependent/glslang_tab.cpp"
break;
case 168: /* storage_qualifier: CONST */
#line 1435 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqConst; // will later turn into EvqConstReadOnly, if the initializer is not constant
}
#line 6962 "MachineIndependent/glslang_tab.cpp"
break;
case 169: /* storage_qualifier: INOUT */
#line 1439 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "inout");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqInOut;
}
#line 6972 "MachineIndependent/glslang_tab.cpp"
break;
case 170: /* storage_qualifier: IN */
#line 1444 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "in");
(yyval.interm.type).init((yyvsp[0].lex).loc);
// whether this is a parameter "in" or a pipeline "in" will get sorted out a bit later
(yyval.interm.type).qualifier.storage = EvqIn;
}
#line 6983 "MachineIndependent/glslang_tab.cpp"
break;
case 171: /* storage_qualifier: OUT */
#line 1450 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "out");
(yyval.interm.type).init((yyvsp[0].lex).loc);
// whether this is a parameter "out" or a pipeline "out" will get sorted out a bit later
(yyval.interm.type).qualifier.storage = EvqOut;
}
#line 6994 "MachineIndependent/glslang_tab.cpp"
break;
case 172: /* storage_qualifier: CENTROID */
#line 1456 "MachineIndependent/glslang.y"
{
parseContext.profileRequires((yyvsp[0].lex).loc, ENoProfile, 120, 0, "centroid");
parseContext.profileRequires((yyvsp[0].lex).loc, EEsProfile, 300, 0, "centroid");
parseContext.globalCheck((yyvsp[0].lex).loc, "centroid");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.centroid = true;
}
#line 7006 "MachineIndependent/glslang_tab.cpp"
break;
case 173: /* storage_qualifier: UNIFORM */
#line 1463 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "uniform");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqUniform;
}
#line 7016 "MachineIndependent/glslang_tab.cpp"
break;
case 174: /* storage_qualifier: TILEIMAGEEXT */
#line 1468 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "tileImageEXT");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqTileImageEXT;
}
#line 7026 "MachineIndependent/glslang_tab.cpp"
break;
case 175: /* storage_qualifier: SHARED */
#line 1473 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "shared");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, 430, E_GL_ARB_compute_shader, "shared");
parseContext.profileRequires((yyvsp[0].lex).loc, EEsProfile, 310, 0, "shared");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangComputeMask | EShLangMeshMask | EShLangTaskMask), "shared");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqShared;
}
#line 7039 "MachineIndependent/glslang_tab.cpp"
break;
case 176: /* storage_qualifier: BUFFER */
#line 1481 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "buffer");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqBuffer;
}
#line 7049 "MachineIndependent/glslang_tab.cpp"
break;
case 177: /* storage_qualifier: ATTRIBUTE */
#line 1486 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangVertex, "attribute");
parseContext.checkDeprecated((yyvsp[0].lex).loc, ECoreProfile, 130, "attribute");
parseContext.checkDeprecated((yyvsp[0].lex).loc, ENoProfile, 130, "attribute");
parseContext.requireNotRemoved((yyvsp[0].lex).loc, ECoreProfile, 420, "attribute");
parseContext.requireNotRemoved((yyvsp[0].lex).loc, EEsProfile, 300, "attribute");
parseContext.globalCheck((yyvsp[0].lex).loc, "attribute");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqVaryingIn;
}
#line 7066 "MachineIndependent/glslang_tab.cpp"
break;
case 178: /* storage_qualifier: VARYING */
#line 1498 "MachineIndependent/glslang.y"
{
parseContext.checkDeprecated((yyvsp[0].lex).loc, ENoProfile, 130, "varying");
parseContext.checkDeprecated((yyvsp[0].lex).loc, ECoreProfile, 130, "varying");
parseContext.requireNotRemoved((yyvsp[0].lex).loc, ECoreProfile, 420, "varying");
parseContext.requireNotRemoved((yyvsp[0].lex).loc, EEsProfile, 300, "varying");
parseContext.globalCheck((yyvsp[0].lex).loc, "varying");
(yyval.interm.type).init((yyvsp[0].lex).loc);
if (parseContext.language == EShLangVertex)
(yyval.interm.type).qualifier.storage = EvqVaryingOut;
else
(yyval.interm.type).qualifier.storage = EvqVaryingIn;
}
#line 7085 "MachineIndependent/glslang_tab.cpp"
break;
case 179: /* storage_qualifier: PATCH */
#line 1512 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "patch");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangTessControlMask | EShLangTessEvaluationMask), "patch");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.patch = true;
}
#line 7096 "MachineIndependent/glslang_tab.cpp"
break;
case 180: /* storage_qualifier: SAMPLE */
#line 1518 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "sample");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.sample = true;
}
#line 7106 "MachineIndependent/glslang_tab.cpp"
break;
case 181: /* storage_qualifier: HITATTRNV */
#line 1523 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "hitAttributeNV");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangIntersectMask | EShLangClosestHitMask
| EShLangAnyHitMask), "hitAttributeNV");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_NV_ray_tracing, "hitAttributeNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqHitAttr;
}
#line 7119 "MachineIndependent/glslang_tab.cpp"
break;
case 182: /* storage_qualifier: HITOBJECTATTRNV */
#line 1531 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "hitAttributeNV");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangRayGenMask | EShLangClosestHitMask
| EShLangMissMask), "hitObjectAttributeNV");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_NV_shader_invocation_reorder, "hitObjectAttributeNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqHitObjectAttrNV;
}
#line 7132 "MachineIndependent/glslang_tab.cpp"
break;
case 183: /* storage_qualifier: HITATTREXT */
#line 1539 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "hitAttributeEXT");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangIntersectMask | EShLangClosestHitMask
| EShLangAnyHitMask), "hitAttributeEXT");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_EXT_ray_tracing, "hitAttributeNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqHitAttr;
}
#line 7145 "MachineIndependent/glslang_tab.cpp"
break;
case 184: /* storage_qualifier: PAYLOADNV */
#line 1547 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "rayPayloadNV");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangRayGenMask | EShLangClosestHitMask |
EShLangAnyHitMask | EShLangMissMask), "rayPayloadNV");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_NV_ray_tracing, "rayPayloadNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqPayload;
}
#line 7158 "MachineIndependent/glslang_tab.cpp"
break;
case 185: /* storage_qualifier: PAYLOADEXT */
#line 1555 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "rayPayloadEXT");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangRayGenMask | EShLangClosestHitMask |
EShLangAnyHitMask | EShLangMissMask), "rayPayloadEXT");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_EXT_ray_tracing, "rayPayloadEXT");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqPayload;
}
#line 7171 "MachineIndependent/glslang_tab.cpp"
break;
case 186: /* storage_qualifier: PAYLOADINNV */
#line 1563 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "rayPayloadInNV");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangClosestHitMask |
EShLangAnyHitMask | EShLangMissMask), "rayPayloadInNV");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_NV_ray_tracing, "rayPayloadInNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqPayloadIn;
}
#line 7184 "MachineIndependent/glslang_tab.cpp"
break;
case 187: /* storage_qualifier: PAYLOADINEXT */
#line 1571 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "rayPayloadInEXT");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangClosestHitMask |
EShLangAnyHitMask | EShLangMissMask), "rayPayloadInEXT");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_EXT_ray_tracing, "rayPayloadInEXT");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqPayloadIn;
}
#line 7197 "MachineIndependent/glslang_tab.cpp"
break;
case 188: /* storage_qualifier: CALLDATANV */
#line 1579 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "callableDataNV");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangRayGenMask |
EShLangClosestHitMask | EShLangMissMask | EShLangCallableMask), "callableDataNV");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_NV_ray_tracing, "callableDataNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqCallableData;
}
#line 7210 "MachineIndependent/glslang_tab.cpp"
break;
case 189: /* storage_qualifier: CALLDATAEXT */
#line 1587 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "callableDataEXT");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangRayGenMask |
EShLangClosestHitMask | EShLangMissMask | EShLangCallableMask), "callableDataEXT");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_EXT_ray_tracing, "callableDataEXT");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqCallableData;
}
#line 7223 "MachineIndependent/glslang_tab.cpp"
break;
case 190: /* storage_qualifier: CALLDATAINNV */
#line 1595 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "callableDataInNV");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangCallableMask), "callableDataInNV");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_NV_ray_tracing, "callableDataInNV");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqCallableDataIn;
}
#line 7235 "MachineIndependent/glslang_tab.cpp"
break;
case 191: /* storage_qualifier: CALLDATAINEXT */
#line 1602 "MachineIndependent/glslang.y"
{
parseContext.globalCheck((yyvsp[0].lex).loc, "callableDataInEXT");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangCallableMask), "callableDataInEXT");
parseContext.profileRequires((yyvsp[0].lex).loc, ECoreProfile, 460, E_GL_EXT_ray_tracing, "callableDataInEXT");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqCallableDataIn;
}
#line 7247 "MachineIndependent/glslang_tab.cpp"
break;
case 192: /* storage_qualifier: COHERENT */
#line 1609 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.coherent = true;
}
#line 7256 "MachineIndependent/glslang_tab.cpp"
break;
case 193: /* storage_qualifier: DEVICECOHERENT */
#line 1613 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_KHR_memory_scope_semantics, "devicecoherent");
(yyval.interm.type).qualifier.devicecoherent = true;
}
#line 7266 "MachineIndependent/glslang_tab.cpp"
break;
case 194: /* storage_qualifier: QUEUEFAMILYCOHERENT */
#line 1618 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_KHR_memory_scope_semantics, "queuefamilycoherent");
(yyval.interm.type).qualifier.queuefamilycoherent = true;
}
#line 7276 "MachineIndependent/glslang_tab.cpp"
break;
case 195: /* storage_qualifier: WORKGROUPCOHERENT */
#line 1623 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_KHR_memory_scope_semantics, "workgroupcoherent");
(yyval.interm.type).qualifier.workgroupcoherent = true;
}
#line 7286 "MachineIndependent/glslang_tab.cpp"
break;
case 196: /* storage_qualifier: SUBGROUPCOHERENT */
#line 1628 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_KHR_memory_scope_semantics, "subgroupcoherent");
(yyval.interm.type).qualifier.subgroupcoherent = true;
}
#line 7296 "MachineIndependent/glslang_tab.cpp"
break;
case 197: /* storage_qualifier: NONPRIVATE */
#line 1633 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_KHR_memory_scope_semantics, "nonprivate");
(yyval.interm.type).qualifier.nonprivate = true;
}
#line 7306 "MachineIndependent/glslang_tab.cpp"
break;
case 198: /* storage_qualifier: SHADERCALLCOHERENT */
#line 1638 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
parseContext.requireExtensions((yyvsp[0].lex).loc, 1, &E_GL_EXT_ray_tracing, "shadercallcoherent");
(yyval.interm.type).qualifier.shadercallcoherent = true;
}
#line 7316 "MachineIndependent/glslang_tab.cpp"
break;
case 199: /* storage_qualifier: VOLATILE */
#line 1643 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.volatil = true;
}
#line 7325 "MachineIndependent/glslang_tab.cpp"
break;
case 200: /* storage_qualifier: RESTRICT */
#line 1647 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.restrict = true;
}
#line 7334 "MachineIndependent/glslang_tab.cpp"
break;
case 201: /* storage_qualifier: READONLY */
#line 1651 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.readonly = true;
}
#line 7343 "MachineIndependent/glslang_tab.cpp"
break;
case 202: /* storage_qualifier: WRITEONLY */
#line 1655 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.writeonly = true;
}
#line 7352 "MachineIndependent/glslang_tab.cpp"
break;
case 203: /* storage_qualifier: SUBROUTINE */
#line 1659 "MachineIndependent/glslang.y"
{
parseContext.spvRemoved((yyvsp[0].lex).loc, "subroutine");
parseContext.globalCheck((yyvsp[0].lex).loc, "subroutine");
parseContext.unimplemented((yyvsp[0].lex).loc, "subroutine");
(yyval.interm.type).init((yyvsp[0].lex).loc);
}
#line 7363 "MachineIndependent/glslang_tab.cpp"
break;
case 204: /* storage_qualifier: SUBROUTINE LEFT_PAREN type_name_list RIGHT_PAREN */
#line 1665 "MachineIndependent/glslang.y"
{
parseContext.spvRemoved((yyvsp[-3].lex).loc, "subroutine");
parseContext.globalCheck((yyvsp[-3].lex).loc, "subroutine");
parseContext.unimplemented((yyvsp[-3].lex).loc, "subroutine");
(yyval.interm.type).init((yyvsp[-3].lex).loc);
}
#line 7374 "MachineIndependent/glslang_tab.cpp"
break;
case 205: /* storage_qualifier: TASKPAYLOADWORKGROUPEXT */
#line 1671 "MachineIndependent/glslang.y"
{
// No need for profile version or extension check. Shader stage already checks both.
parseContext.globalCheck((yyvsp[0].lex).loc, "taskPayloadSharedEXT");
parseContext.requireStage((yyvsp[0].lex).loc, (EShLanguageMask)(EShLangTaskMask | EShLangMeshMask), "taskPayloadSharedEXT ");
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.storage = EvqtaskPayloadSharedEXT;
}
#line 7386 "MachineIndependent/glslang_tab.cpp"
break;
case 206: /* non_uniform_qualifier: NONUNIFORM */
#line 1681 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc);
(yyval.interm.type).qualifier.nonUniform = true;
}
#line 7395 "MachineIndependent/glslang_tab.cpp"
break;
case 207: /* type_name_list: IDENTIFIER */
#line 1688 "MachineIndependent/glslang.y"
{
// TODO
}
#line 7403 "MachineIndependent/glslang_tab.cpp"
break;
case 208: /* type_name_list: type_name_list COMMA IDENTIFIER */
#line 1691 "MachineIndependent/glslang.y"
{
// TODO: 4.0 semantics: subroutines
// 1) make sure each identifier is a type declared earlier with SUBROUTINE
// 2) save all of the identifiers for future comparison with the declared function
}
#line 7413 "MachineIndependent/glslang_tab.cpp"
break;
case 209: /* type_specifier: type_specifier_nonarray type_parameter_specifier_opt */
#line 1699 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[-1].interm.type);
(yyval.interm.type).qualifier.precision = parseContext.getDefaultPrecision((yyval.interm.type));
(yyval.interm.type).typeParameters = (yyvsp[0].interm.typeParameters);
parseContext.coopMatTypeParametersCheck((yyvsp[-1].interm.type).loc, (yyval.interm.type));
}
#line 7425 "MachineIndependent/glslang_tab.cpp"
break;
case 210: /* type_specifier: type_specifier_nonarray type_parameter_specifier_opt array_specifier */
#line 1706 "MachineIndependent/glslang.y"
{
parseContext.arrayOfArrayVersionCheck((yyvsp[0].interm).loc, (yyvsp[0].interm).arraySizes);
(yyval.interm.type) = (yyvsp[-2].interm.type);
(yyval.interm.type).qualifier.precision = parseContext.getDefaultPrecision((yyval.interm.type));
(yyval.interm.type).typeParameters = (yyvsp[-1].interm.typeParameters);
(yyval.interm.type).arraySizes = (yyvsp[0].interm).arraySizes;
parseContext.coopMatTypeParametersCheck((yyvsp[-2].interm.type).loc, (yyval.interm.type));
}
#line 7438 "MachineIndependent/glslang_tab.cpp"
break;
case 211: /* array_specifier: LEFT_BRACKET RIGHT_BRACKET */
#line 1717 "MachineIndependent/glslang.y"
{
(yyval.interm).loc = (yyvsp[-1].lex).loc;
(yyval.interm).arraySizes = new TArraySizes;
(yyval.interm).arraySizes->addInnerSize();
}
#line 7448 "MachineIndependent/glslang_tab.cpp"
break;
case 212: /* array_specifier: LEFT_BRACKET conditional_expression RIGHT_BRACKET */
#line 1722 "MachineIndependent/glslang.y"
{
(yyval.interm).loc = (yyvsp[-2].lex).loc;
(yyval.interm).arraySizes = new TArraySizes;
TArraySize size;
parseContext.arraySizeCheck((yyvsp[-1].interm.intermTypedNode)->getLoc(), (yyvsp[-1].interm.intermTypedNode), size, "array size");
(yyval.interm).arraySizes->addInnerSize(size);
}
#line 7461 "MachineIndependent/glslang_tab.cpp"
break;
case 213: /* array_specifier: array_specifier LEFT_BRACKET RIGHT_BRACKET */
#line 1730 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[-2].interm);
(yyval.interm).arraySizes->addInnerSize();
}
#line 7470 "MachineIndependent/glslang_tab.cpp"
break;
case 214: /* array_specifier: array_specifier LEFT_BRACKET conditional_expression RIGHT_BRACKET */
#line 1734 "MachineIndependent/glslang.y"
{
(yyval.interm) = (yyvsp[-3].interm);
TArraySize size;
parseContext.arraySizeCheck((yyvsp[-1].interm.intermTypedNode)->getLoc(), (yyvsp[-1].interm.intermTypedNode), size, "array size");
(yyval.interm).arraySizes->addInnerSize(size);
}
#line 7482 "MachineIndependent/glslang_tab.cpp"
break;
case 215: /* type_parameter_specifier_opt: type_parameter_specifier */
#line 1744 "MachineIndependent/glslang.y"
{
(yyval.interm.typeParameters) = (yyvsp[0].interm.typeParameters);
}
#line 7490 "MachineIndependent/glslang_tab.cpp"
break;
case 216: /* type_parameter_specifier_opt: %empty */
#line 1747 "MachineIndependent/glslang.y"
{
(yyval.interm.typeParameters) = 0;
}
#line 7498 "MachineIndependent/glslang_tab.cpp"
break;
case 217: /* type_parameter_specifier: LEFT_ANGLE type_parameter_specifier_list RIGHT_ANGLE */
#line 1753 "MachineIndependent/glslang.y"
{
(yyval.interm.typeParameters) = (yyvsp[-1].interm.typeParameters);
}
#line 7506 "MachineIndependent/glslang_tab.cpp"
break;
case 218: /* type_parameter_specifier_list: type_specifier */
#line 1759 "MachineIndependent/glslang.y"
{
(yyval.interm.typeParameters) = new TTypeParameters;
(yyval.interm.typeParameters)->arraySizes = new TArraySizes;
(yyval.interm.typeParameters)->spirvType = (yyvsp[0].interm.type).spirvType;
(yyval.interm.typeParameters)->basicType = (yyvsp[0].interm.type).basicType;
}
#line 7517 "MachineIndependent/glslang_tab.cpp"
break;
case 219: /* type_parameter_specifier_list: unary_expression */
#line 1765 "MachineIndependent/glslang.y"
{
(yyval.interm.typeParameters) = new TTypeParameters;
(yyval.interm.typeParameters)->arraySizes = new TArraySizes;
TArraySize size;
parseContext.arraySizeCheck((yyvsp[0].interm.intermTypedNode)->getLoc(), (yyvsp[0].interm.intermTypedNode), size, "type parameter", true);
(yyval.interm.typeParameters)->arraySizes->addInnerSize(size);
}
#line 7530 "MachineIndependent/glslang_tab.cpp"
break;
case 220: /* type_parameter_specifier_list: type_parameter_specifier_list COMMA unary_expression */
#line 1773 "MachineIndependent/glslang.y"
{
(yyval.interm.typeParameters) = (yyvsp[-2].interm.typeParameters);
TArraySize size;
parseContext.arraySizeCheck((yyvsp[0].interm.intermTypedNode)->getLoc(), (yyvsp[0].interm.intermTypedNode), size, "type parameter", true);
(yyval.interm.typeParameters)->arraySizes->addInnerSize(size);
}
#line 7542 "MachineIndependent/glslang_tab.cpp"
break;
case 221: /* type_specifier_nonarray: VOID */
#line 1783 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtVoid;
}
#line 7551 "MachineIndependent/glslang_tab.cpp"
break;
case 222: /* type_specifier_nonarray: FLOAT */
#line 1787 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
}
#line 7560 "MachineIndependent/glslang_tab.cpp"
break;
case 223: /* type_specifier_nonarray: INT */
#line 1791 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt;
}
#line 7569 "MachineIndependent/glslang_tab.cpp"
break;
case 224: /* type_specifier_nonarray: UINT */
#line 1795 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "unsigned integer");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint;
}
#line 7579 "MachineIndependent/glslang_tab.cpp"
break;
case 225: /* type_specifier_nonarray: BOOL */
#line 1800 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtBool;
}
#line 7588 "MachineIndependent/glslang_tab.cpp"
break;
case 226: /* type_specifier_nonarray: VEC2 */
#line 1804 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setVector(2);
}
#line 7598 "MachineIndependent/glslang_tab.cpp"
break;
case 227: /* type_specifier_nonarray: VEC3 */
#line 1809 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setVector(3);
}
#line 7608 "MachineIndependent/glslang_tab.cpp"
break;
case 228: /* type_specifier_nonarray: VEC4 */
#line 1814 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setVector(4);
}
#line 7618 "MachineIndependent/glslang_tab.cpp"
break;
case 229: /* type_specifier_nonarray: BVEC2 */
#line 1819 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtBool;
(yyval.interm.type).setVector(2);
}
#line 7628 "MachineIndependent/glslang_tab.cpp"
break;
case 230: /* type_specifier_nonarray: BVEC3 */
#line 1824 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtBool;
(yyval.interm.type).setVector(3);
}
#line 7638 "MachineIndependent/glslang_tab.cpp"
break;
case 231: /* type_specifier_nonarray: BVEC4 */
#line 1829 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtBool;
(yyval.interm.type).setVector(4);
}
#line 7648 "MachineIndependent/glslang_tab.cpp"
break;
case 232: /* type_specifier_nonarray: IVEC2 */
#line 1834 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt;
(yyval.interm.type).setVector(2);
}
#line 7658 "MachineIndependent/glslang_tab.cpp"
break;
case 233: /* type_specifier_nonarray: IVEC3 */
#line 1839 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt;
(yyval.interm.type).setVector(3);
}
#line 7668 "MachineIndependent/glslang_tab.cpp"
break;
case 234: /* type_specifier_nonarray: IVEC4 */
#line 1844 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt;
(yyval.interm.type).setVector(4);
}
#line 7678 "MachineIndependent/glslang_tab.cpp"
break;
case 235: /* type_specifier_nonarray: UVEC2 */
#line 1849 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "unsigned integer vector");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint;
(yyval.interm.type).setVector(2);
}
#line 7689 "MachineIndependent/glslang_tab.cpp"
break;
case 236: /* type_specifier_nonarray: UVEC3 */
#line 1855 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "unsigned integer vector");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint;
(yyval.interm.type).setVector(3);
}
#line 7700 "MachineIndependent/glslang_tab.cpp"
break;
case 237: /* type_specifier_nonarray: UVEC4 */
#line 1861 "MachineIndependent/glslang.y"
{
parseContext.fullIntegerCheck((yyvsp[0].lex).loc, "unsigned integer vector");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint;
(yyval.interm.type).setVector(4);
}
#line 7711 "MachineIndependent/glslang_tab.cpp"
break;
case 238: /* type_specifier_nonarray: MAT2 */
#line 1867 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(2, 2);
}
#line 7721 "MachineIndependent/glslang_tab.cpp"
break;
case 239: /* type_specifier_nonarray: MAT3 */
#line 1872 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(3, 3);
}
#line 7731 "MachineIndependent/glslang_tab.cpp"
break;
case 240: /* type_specifier_nonarray: MAT4 */
#line 1877 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(4, 4);
}
#line 7741 "MachineIndependent/glslang_tab.cpp"
break;
case 241: /* type_specifier_nonarray: MAT2X2 */
#line 1882 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(2, 2);
}
#line 7751 "MachineIndependent/glslang_tab.cpp"
break;
case 242: /* type_specifier_nonarray: MAT2X3 */
#line 1887 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(2, 3);
}
#line 7761 "MachineIndependent/glslang_tab.cpp"
break;
case 243: /* type_specifier_nonarray: MAT2X4 */
#line 1892 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(2, 4);
}
#line 7771 "MachineIndependent/glslang_tab.cpp"
break;
case 244: /* type_specifier_nonarray: MAT3X2 */
#line 1897 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(3, 2);
}
#line 7781 "MachineIndependent/glslang_tab.cpp"
break;
case 245: /* type_specifier_nonarray: MAT3X3 */
#line 1902 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(3, 3);
}
#line 7791 "MachineIndependent/glslang_tab.cpp"
break;
case 246: /* type_specifier_nonarray: MAT3X4 */
#line 1907 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(3, 4);
}
#line 7801 "MachineIndependent/glslang_tab.cpp"
break;
case 247: /* type_specifier_nonarray: MAT4X2 */
#line 1912 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(4, 2);
}
#line 7811 "MachineIndependent/glslang_tab.cpp"
break;
case 248: /* type_specifier_nonarray: MAT4X3 */
#line 1917 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(4, 3);
}
#line 7821 "MachineIndependent/glslang_tab.cpp"
break;
case 249: /* type_specifier_nonarray: MAT4X4 */
#line 1922 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(4, 4);
}
#line 7831 "MachineIndependent/glslang_tab.cpp"
break;
case 250: /* type_specifier_nonarray: DOUBLE */
#line 1927 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
}
#line 7843 "MachineIndependent/glslang_tab.cpp"
break;
case 251: /* type_specifier_nonarray: FLOAT16_T */
#line 1934 "MachineIndependent/glslang.y"
{
parseContext.float16ScalarVectorCheck((yyvsp[0].lex).loc, "float16_t", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
}
#line 7853 "MachineIndependent/glslang_tab.cpp"
break;
case 252: /* type_specifier_nonarray: FLOAT32_T */
#line 1939 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
}
#line 7863 "MachineIndependent/glslang_tab.cpp"
break;
case 253: /* type_specifier_nonarray: FLOAT64_T */
#line 1944 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
}
#line 7873 "MachineIndependent/glslang_tab.cpp"
break;
case 254: /* type_specifier_nonarray: INT8_T */
#line 1949 "MachineIndependent/glslang.y"
{
parseContext.int8ScalarVectorCheck((yyvsp[0].lex).loc, "8-bit signed integer", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt8;
}
#line 7883 "MachineIndependent/glslang_tab.cpp"
break;
case 255: /* type_specifier_nonarray: UINT8_T */
#line 1954 "MachineIndependent/glslang.y"
{
parseContext.int8ScalarVectorCheck((yyvsp[0].lex).loc, "8-bit unsigned integer", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint8;
}
#line 7893 "MachineIndependent/glslang_tab.cpp"
break;
case 256: /* type_specifier_nonarray: INT16_T */
#line 1959 "MachineIndependent/glslang.y"
{
parseContext.int16ScalarVectorCheck((yyvsp[0].lex).loc, "16-bit signed integer", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt16;
}
#line 7903 "MachineIndependent/glslang_tab.cpp"
break;
case 257: /* type_specifier_nonarray: UINT16_T */
#line 1964 "MachineIndependent/glslang.y"
{
parseContext.int16ScalarVectorCheck((yyvsp[0].lex).loc, "16-bit unsigned integer", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint16;
}
#line 7913 "MachineIndependent/glslang_tab.cpp"
break;
case 258: /* type_specifier_nonarray: INT32_T */
#line 1969 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit signed integer", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt;
}
#line 7923 "MachineIndependent/glslang_tab.cpp"
break;
case 259: /* type_specifier_nonarray: UINT32_T */
#line 1974 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit unsigned integer", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint;
}
#line 7933 "MachineIndependent/glslang_tab.cpp"
break;
case 260: /* type_specifier_nonarray: INT64_T */
#line 1979 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit integer", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt64;
}
#line 7943 "MachineIndependent/glslang_tab.cpp"
break;
case 261: /* type_specifier_nonarray: UINT64_T */
#line 1984 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit unsigned integer", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint64;
}
#line 7953 "MachineIndependent/glslang_tab.cpp"
break;
case 262: /* type_specifier_nonarray: DVEC2 */
#line 1989 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double vector");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double vector");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setVector(2);
}
#line 7966 "MachineIndependent/glslang_tab.cpp"
break;
case 263: /* type_specifier_nonarray: DVEC3 */
#line 1997 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double vector");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double vector");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setVector(3);
}
#line 7979 "MachineIndependent/glslang_tab.cpp"
break;
case 264: /* type_specifier_nonarray: DVEC4 */
#line 2005 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double vector");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double vector");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setVector(4);
}
#line 7992 "MachineIndependent/glslang_tab.cpp"
break;
case 265: /* type_specifier_nonarray: F16VEC2 */
#line 2013 "MachineIndependent/glslang.y"
{
parseContext.float16ScalarVectorCheck((yyvsp[0].lex).loc, "half float vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setVector(2);
}
#line 8003 "MachineIndependent/glslang_tab.cpp"
break;
case 266: /* type_specifier_nonarray: F16VEC3 */
#line 2019 "MachineIndependent/glslang.y"
{
parseContext.float16ScalarVectorCheck((yyvsp[0].lex).loc, "half float vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setVector(3);
}
#line 8014 "MachineIndependent/glslang_tab.cpp"
break;
case 267: /* type_specifier_nonarray: F16VEC4 */
#line 2025 "MachineIndependent/glslang.y"
{
parseContext.float16ScalarVectorCheck((yyvsp[0].lex).loc, "half float vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setVector(4);
}
#line 8025 "MachineIndependent/glslang_tab.cpp"
break;
case 268: /* type_specifier_nonarray: F32VEC2 */
#line 2031 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setVector(2);
}
#line 8036 "MachineIndependent/glslang_tab.cpp"
break;
case 269: /* type_specifier_nonarray: F32VEC3 */
#line 2037 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setVector(3);
}
#line 8047 "MachineIndependent/glslang_tab.cpp"
break;
case 270: /* type_specifier_nonarray: F32VEC4 */
#line 2043 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setVector(4);
}
#line 8058 "MachineIndependent/glslang_tab.cpp"
break;
case 271: /* type_specifier_nonarray: F64VEC2 */
#line 2049 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setVector(2);
}
#line 8069 "MachineIndependent/glslang_tab.cpp"
break;
case 272: /* type_specifier_nonarray: F64VEC3 */
#line 2055 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setVector(3);
}
#line 8080 "MachineIndependent/glslang_tab.cpp"
break;
case 273: /* type_specifier_nonarray: F64VEC4 */
#line 2061 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setVector(4);
}
#line 8091 "MachineIndependent/glslang_tab.cpp"
break;
case 274: /* type_specifier_nonarray: I8VEC2 */
#line 2067 "MachineIndependent/glslang.y"
{
parseContext.int8ScalarVectorCheck((yyvsp[0].lex).loc, "8-bit signed integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt8;
(yyval.interm.type).setVector(2);
}
#line 8102 "MachineIndependent/glslang_tab.cpp"
break;
case 275: /* type_specifier_nonarray: I8VEC3 */
#line 2073 "MachineIndependent/glslang.y"
{
parseContext.int8ScalarVectorCheck((yyvsp[0].lex).loc, "8-bit signed integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt8;
(yyval.interm.type).setVector(3);
}
#line 8113 "MachineIndependent/glslang_tab.cpp"
break;
case 276: /* type_specifier_nonarray: I8VEC4 */
#line 2079 "MachineIndependent/glslang.y"
{
parseContext.int8ScalarVectorCheck((yyvsp[0].lex).loc, "8-bit signed integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt8;
(yyval.interm.type).setVector(4);
}
#line 8124 "MachineIndependent/glslang_tab.cpp"
break;
case 277: /* type_specifier_nonarray: I16VEC2 */
#line 2085 "MachineIndependent/glslang.y"
{
parseContext.int16ScalarVectorCheck((yyvsp[0].lex).loc, "16-bit signed integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt16;
(yyval.interm.type).setVector(2);
}
#line 8135 "MachineIndependent/glslang_tab.cpp"
break;
case 278: /* type_specifier_nonarray: I16VEC3 */
#line 2091 "MachineIndependent/glslang.y"
{
parseContext.int16ScalarVectorCheck((yyvsp[0].lex).loc, "16-bit signed integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt16;
(yyval.interm.type).setVector(3);
}
#line 8146 "MachineIndependent/glslang_tab.cpp"
break;
case 279: /* type_specifier_nonarray: I16VEC4 */
#line 2097 "MachineIndependent/glslang.y"
{
parseContext.int16ScalarVectorCheck((yyvsp[0].lex).loc, "16-bit signed integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt16;
(yyval.interm.type).setVector(4);
}
#line 8157 "MachineIndependent/glslang_tab.cpp"
break;
case 280: /* type_specifier_nonarray: I32VEC2 */
#line 2103 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit signed integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt;
(yyval.interm.type).setVector(2);
}
#line 8168 "MachineIndependent/glslang_tab.cpp"
break;
case 281: /* type_specifier_nonarray: I32VEC3 */
#line 2109 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit signed integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt;
(yyval.interm.type).setVector(3);
}
#line 8179 "MachineIndependent/glslang_tab.cpp"
break;
case 282: /* type_specifier_nonarray: I32VEC4 */
#line 2115 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit signed integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt;
(yyval.interm.type).setVector(4);
}
#line 8190 "MachineIndependent/glslang_tab.cpp"
break;
case 283: /* type_specifier_nonarray: I64VEC2 */
#line 2121 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt64;
(yyval.interm.type).setVector(2);
}
#line 8201 "MachineIndependent/glslang_tab.cpp"
break;
case 284: /* type_specifier_nonarray: I64VEC3 */
#line 2127 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt64;
(yyval.interm.type).setVector(3);
}
#line 8212 "MachineIndependent/glslang_tab.cpp"
break;
case 285: /* type_specifier_nonarray: I64VEC4 */
#line 2133 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt64;
(yyval.interm.type).setVector(4);
}
#line 8223 "MachineIndependent/glslang_tab.cpp"
break;
case 286: /* type_specifier_nonarray: U8VEC2 */
#line 2139 "MachineIndependent/glslang.y"
{
parseContext.int8ScalarVectorCheck((yyvsp[0].lex).loc, "8-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint8;
(yyval.interm.type).setVector(2);
}
#line 8234 "MachineIndependent/glslang_tab.cpp"
break;
case 287: /* type_specifier_nonarray: U8VEC3 */
#line 2145 "MachineIndependent/glslang.y"
{
parseContext.int8ScalarVectorCheck((yyvsp[0].lex).loc, "8-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint8;
(yyval.interm.type).setVector(3);
}
#line 8245 "MachineIndependent/glslang_tab.cpp"
break;
case 288: /* type_specifier_nonarray: U8VEC4 */
#line 2151 "MachineIndependent/glslang.y"
{
parseContext.int8ScalarVectorCheck((yyvsp[0].lex).loc, "8-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint8;
(yyval.interm.type).setVector(4);
}
#line 8256 "MachineIndependent/glslang_tab.cpp"
break;
case 289: /* type_specifier_nonarray: U16VEC2 */
#line 2157 "MachineIndependent/glslang.y"
{
parseContext.int16ScalarVectorCheck((yyvsp[0].lex).loc, "16-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint16;
(yyval.interm.type).setVector(2);
}
#line 8267 "MachineIndependent/glslang_tab.cpp"
break;
case 290: /* type_specifier_nonarray: U16VEC3 */
#line 2163 "MachineIndependent/glslang.y"
{
parseContext.int16ScalarVectorCheck((yyvsp[0].lex).loc, "16-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint16;
(yyval.interm.type).setVector(3);
}
#line 8278 "MachineIndependent/glslang_tab.cpp"
break;
case 291: /* type_specifier_nonarray: U16VEC4 */
#line 2169 "MachineIndependent/glslang.y"
{
parseContext.int16ScalarVectorCheck((yyvsp[0].lex).loc, "16-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint16;
(yyval.interm.type).setVector(4);
}
#line 8289 "MachineIndependent/glslang_tab.cpp"
break;
case 292: /* type_specifier_nonarray: U32VEC2 */
#line 2175 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint;
(yyval.interm.type).setVector(2);
}
#line 8300 "MachineIndependent/glslang_tab.cpp"
break;
case 293: /* type_specifier_nonarray: U32VEC3 */
#line 2181 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint;
(yyval.interm.type).setVector(3);
}
#line 8311 "MachineIndependent/glslang_tab.cpp"
break;
case 294: /* type_specifier_nonarray: U32VEC4 */
#line 2187 "MachineIndependent/glslang.y"
{
parseContext.explicitInt32Check((yyvsp[0].lex).loc, "32-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint;
(yyval.interm.type).setVector(4);
}
#line 8322 "MachineIndependent/glslang_tab.cpp"
break;
case 295: /* type_specifier_nonarray: U64VEC2 */
#line 2193 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint64;
(yyval.interm.type).setVector(2);
}
#line 8333 "MachineIndependent/glslang_tab.cpp"
break;
case 296: /* type_specifier_nonarray: U64VEC3 */
#line 2199 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint64;
(yyval.interm.type).setVector(3);
}
#line 8344 "MachineIndependent/glslang_tab.cpp"
break;
case 297: /* type_specifier_nonarray: U64VEC4 */
#line 2205 "MachineIndependent/glslang.y"
{
parseContext.int64Check((yyvsp[0].lex).loc, "64-bit unsigned integer vector", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint64;
(yyval.interm.type).setVector(4);
}
#line 8355 "MachineIndependent/glslang_tab.cpp"
break;
case 298: /* type_specifier_nonarray: DMAT2 */
#line 2211 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(2, 2);
}
#line 8368 "MachineIndependent/glslang_tab.cpp"
break;
case 299: /* type_specifier_nonarray: DMAT3 */
#line 2219 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(3, 3);
}
#line 8381 "MachineIndependent/glslang_tab.cpp"
break;
case 300: /* type_specifier_nonarray: DMAT4 */
#line 2227 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(4, 4);
}
#line 8394 "MachineIndependent/glslang_tab.cpp"
break;
case 301: /* type_specifier_nonarray: DMAT2X2 */
#line 2235 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(2, 2);
}
#line 8407 "MachineIndependent/glslang_tab.cpp"
break;
case 302: /* type_specifier_nonarray: DMAT2X3 */
#line 2243 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(2, 3);
}
#line 8420 "MachineIndependent/glslang_tab.cpp"
break;
case 303: /* type_specifier_nonarray: DMAT2X4 */
#line 2251 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(2, 4);
}
#line 8433 "MachineIndependent/glslang_tab.cpp"
break;
case 304: /* type_specifier_nonarray: DMAT3X2 */
#line 2259 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(3, 2);
}
#line 8446 "MachineIndependent/glslang_tab.cpp"
break;
case 305: /* type_specifier_nonarray: DMAT3X3 */
#line 2267 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(3, 3);
}
#line 8459 "MachineIndependent/glslang_tab.cpp"
break;
case 306: /* type_specifier_nonarray: DMAT3X4 */
#line 2275 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(3, 4);
}
#line 8472 "MachineIndependent/glslang_tab.cpp"
break;
case 307: /* type_specifier_nonarray: DMAT4X2 */
#line 2283 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(4, 2);
}
#line 8485 "MachineIndependent/glslang_tab.cpp"
break;
case 308: /* type_specifier_nonarray: DMAT4X3 */
#line 2291 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(4, 3);
}
#line 8498 "MachineIndependent/glslang_tab.cpp"
break;
case 309: /* type_specifier_nonarray: DMAT4X4 */
#line 2299 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ECoreProfile | ECompatibilityProfile, "double matrix");
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.doubleCheck((yyvsp[0].lex).loc, "double matrix");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(4, 4);
}
#line 8511 "MachineIndependent/glslang_tab.cpp"
break;
case 310: /* type_specifier_nonarray: F16MAT2 */
#line 2307 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(2, 2);
}
#line 8522 "MachineIndependent/glslang_tab.cpp"
break;
case 311: /* type_specifier_nonarray: F16MAT3 */
#line 2313 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(3, 3);
}
#line 8533 "MachineIndependent/glslang_tab.cpp"
break;
case 312: /* type_specifier_nonarray: F16MAT4 */
#line 2319 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(4, 4);
}
#line 8544 "MachineIndependent/glslang_tab.cpp"
break;
case 313: /* type_specifier_nonarray: F16MAT2X2 */
#line 2325 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(2, 2);
}
#line 8555 "MachineIndependent/glslang_tab.cpp"
break;
case 314: /* type_specifier_nonarray: F16MAT2X3 */
#line 2331 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(2, 3);
}
#line 8566 "MachineIndependent/glslang_tab.cpp"
break;
case 315: /* type_specifier_nonarray: F16MAT2X4 */
#line 2337 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(2, 4);
}
#line 8577 "MachineIndependent/glslang_tab.cpp"
break;
case 316: /* type_specifier_nonarray: F16MAT3X2 */
#line 2343 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(3, 2);
}
#line 8588 "MachineIndependent/glslang_tab.cpp"
break;
case 317: /* type_specifier_nonarray: F16MAT3X3 */
#line 2349 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(3, 3);
}
#line 8599 "MachineIndependent/glslang_tab.cpp"
break;
case 318: /* type_specifier_nonarray: F16MAT3X4 */
#line 2355 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(3, 4);
}
#line 8610 "MachineIndependent/glslang_tab.cpp"
break;
case 319: /* type_specifier_nonarray: F16MAT4X2 */
#line 2361 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(4, 2);
}
#line 8621 "MachineIndependent/glslang_tab.cpp"
break;
case 320: /* type_specifier_nonarray: F16MAT4X3 */
#line 2367 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(4, 3);
}
#line 8632 "MachineIndependent/glslang_tab.cpp"
break;
case 321: /* type_specifier_nonarray: F16MAT4X4 */
#line 2373 "MachineIndependent/glslang.y"
{
parseContext.float16Check((yyvsp[0].lex).loc, "half float matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat16;
(yyval.interm.type).setMatrix(4, 4);
}
#line 8643 "MachineIndependent/glslang_tab.cpp"
break;
case 322: /* type_specifier_nonarray: F32MAT2 */
#line 2379 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(2, 2);
}
#line 8654 "MachineIndependent/glslang_tab.cpp"
break;
case 323: /* type_specifier_nonarray: F32MAT3 */
#line 2385 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(3, 3);
}
#line 8665 "MachineIndependent/glslang_tab.cpp"
break;
case 324: /* type_specifier_nonarray: F32MAT4 */
#line 2391 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(4, 4);
}
#line 8676 "MachineIndependent/glslang_tab.cpp"
break;
case 325: /* type_specifier_nonarray: F32MAT2X2 */
#line 2397 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(2, 2);
}
#line 8687 "MachineIndependent/glslang_tab.cpp"
break;
case 326: /* type_specifier_nonarray: F32MAT2X3 */
#line 2403 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(2, 3);
}
#line 8698 "MachineIndependent/glslang_tab.cpp"
break;
case 327: /* type_specifier_nonarray: F32MAT2X4 */
#line 2409 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(2, 4);
}
#line 8709 "MachineIndependent/glslang_tab.cpp"
break;
case 328: /* type_specifier_nonarray: F32MAT3X2 */
#line 2415 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(3, 2);
}
#line 8720 "MachineIndependent/glslang_tab.cpp"
break;
case 329: /* type_specifier_nonarray: F32MAT3X3 */
#line 2421 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(3, 3);
}
#line 8731 "MachineIndependent/glslang_tab.cpp"
break;
case 330: /* type_specifier_nonarray: F32MAT3X4 */
#line 2427 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(3, 4);
}
#line 8742 "MachineIndependent/glslang_tab.cpp"
break;
case 331: /* type_specifier_nonarray: F32MAT4X2 */
#line 2433 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(4, 2);
}
#line 8753 "MachineIndependent/glslang_tab.cpp"
break;
case 332: /* type_specifier_nonarray: F32MAT4X3 */
#line 2439 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(4, 3);
}
#line 8764 "MachineIndependent/glslang_tab.cpp"
break;
case 333: /* type_specifier_nonarray: F32MAT4X4 */
#line 2445 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat32Check((yyvsp[0].lex).loc, "float32_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).setMatrix(4, 4);
}
#line 8775 "MachineIndependent/glslang_tab.cpp"
break;
case 334: /* type_specifier_nonarray: F64MAT2 */
#line 2451 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(2, 2);
}
#line 8786 "MachineIndependent/glslang_tab.cpp"
break;
case 335: /* type_specifier_nonarray: F64MAT3 */
#line 2457 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(3, 3);
}
#line 8797 "MachineIndependent/glslang_tab.cpp"
break;
case 336: /* type_specifier_nonarray: F64MAT4 */
#line 2463 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(4, 4);
}
#line 8808 "MachineIndependent/glslang_tab.cpp"
break;
case 337: /* type_specifier_nonarray: F64MAT2X2 */
#line 2469 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(2, 2);
}
#line 8819 "MachineIndependent/glslang_tab.cpp"
break;
case 338: /* type_specifier_nonarray: F64MAT2X3 */
#line 2475 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(2, 3);
}
#line 8830 "MachineIndependent/glslang_tab.cpp"
break;
case 339: /* type_specifier_nonarray: F64MAT2X4 */
#line 2481 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(2, 4);
}
#line 8841 "MachineIndependent/glslang_tab.cpp"
break;
case 340: /* type_specifier_nonarray: F64MAT3X2 */
#line 2487 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(3, 2);
}
#line 8852 "MachineIndependent/glslang_tab.cpp"
break;
case 341: /* type_specifier_nonarray: F64MAT3X3 */
#line 2493 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(3, 3);
}
#line 8863 "MachineIndependent/glslang_tab.cpp"
break;
case 342: /* type_specifier_nonarray: F64MAT3X4 */
#line 2499 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(3, 4);
}
#line 8874 "MachineIndependent/glslang_tab.cpp"
break;
case 343: /* type_specifier_nonarray: F64MAT4X2 */
#line 2505 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(4, 2);
}
#line 8885 "MachineIndependent/glslang_tab.cpp"
break;
case 344: /* type_specifier_nonarray: F64MAT4X3 */
#line 2511 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(4, 3);
}
#line 8896 "MachineIndependent/glslang_tab.cpp"
break;
case 345: /* type_specifier_nonarray: F64MAT4X4 */
#line 2517 "MachineIndependent/glslang.y"
{
parseContext.explicitFloat64Check((yyvsp[0].lex).loc, "float64_t matrix", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtDouble;
(yyval.interm.type).setMatrix(4, 4);
}
#line 8907 "MachineIndependent/glslang_tab.cpp"
break;
case 346: /* type_specifier_nonarray: ACCSTRUCTNV */
#line 2523 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtAccStruct;
}
#line 8916 "MachineIndependent/glslang_tab.cpp"
break;
case 347: /* type_specifier_nonarray: ACCSTRUCTEXT */
#line 2527 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtAccStruct;
}
#line 8925 "MachineIndependent/glslang_tab.cpp"
break;
case 348: /* type_specifier_nonarray: RAYQUERYEXT */
#line 2531 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtRayQuery;
}
#line 8934 "MachineIndependent/glslang_tab.cpp"
break;
case 349: /* type_specifier_nonarray: ATOMIC_UINT */
#line 2535 "MachineIndependent/glslang.y"
{
parseContext.vulkanRemoved((yyvsp[0].lex).loc, "atomic counter types");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtAtomicUint;
}
#line 8944 "MachineIndependent/glslang_tab.cpp"
break;
case 350: /* type_specifier_nonarray: SAMPLER1D */
#line 2540 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd1D);
}
#line 8954 "MachineIndependent/glslang_tab.cpp"
break;
case 351: /* type_specifier_nonarray: SAMPLER2D */
#line 2545 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd2D);
}
#line 8964 "MachineIndependent/glslang_tab.cpp"
break;
case 352: /* type_specifier_nonarray: SAMPLER3D */
#line 2550 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd3D);
}
#line 8974 "MachineIndependent/glslang_tab.cpp"
break;
case 353: /* type_specifier_nonarray: SAMPLERCUBE */
#line 2555 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, EsdCube);
}
#line 8984 "MachineIndependent/glslang_tab.cpp"
break;
case 354: /* type_specifier_nonarray: SAMPLER2DSHADOW */
#line 2560 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd2D, false, true);
}
#line 8994 "MachineIndependent/glslang_tab.cpp"
break;
case 355: /* type_specifier_nonarray: SAMPLERCUBESHADOW */
#line 2565 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, EsdCube, false, true);
}
#line 9004 "MachineIndependent/glslang_tab.cpp"
break;
case 356: /* type_specifier_nonarray: SAMPLER2DARRAY */
#line 2570 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd2D, true);
}
#line 9014 "MachineIndependent/glslang_tab.cpp"
break;
case 357: /* type_specifier_nonarray: SAMPLER2DARRAYSHADOW */
#line 2575 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd2D, true, true);
}
#line 9024 "MachineIndependent/glslang_tab.cpp"
break;
case 358: /* type_specifier_nonarray: SAMPLER1DSHADOW */
#line 2580 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd1D, false, true);
}
#line 9034 "MachineIndependent/glslang_tab.cpp"
break;
case 359: /* type_specifier_nonarray: SAMPLER1DARRAY */
#line 2585 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd1D, true);
}
#line 9044 "MachineIndependent/glslang_tab.cpp"
break;
case 360: /* type_specifier_nonarray: SAMPLER1DARRAYSHADOW */
#line 2590 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd1D, true, true);
}
#line 9054 "MachineIndependent/glslang_tab.cpp"
break;
case 361: /* type_specifier_nonarray: SAMPLERCUBEARRAY */
#line 2595 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, EsdCube, true);
}
#line 9064 "MachineIndependent/glslang_tab.cpp"
break;
case 362: /* type_specifier_nonarray: SAMPLERCUBEARRAYSHADOW */
#line 2600 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, EsdCube, true, true);
}
#line 9074 "MachineIndependent/glslang_tab.cpp"
break;
case 363: /* type_specifier_nonarray: F16SAMPLER1D */
#line 2605 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd1D);
}
#line 9085 "MachineIndependent/glslang_tab.cpp"
break;
case 364: /* type_specifier_nonarray: F16SAMPLER2D */
#line 2611 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd2D);
}
#line 9096 "MachineIndependent/glslang_tab.cpp"
break;
case 365: /* type_specifier_nonarray: F16SAMPLER3D */
#line 2617 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd3D);
}
#line 9107 "MachineIndependent/glslang_tab.cpp"
break;
case 366: /* type_specifier_nonarray: F16SAMPLERCUBE */
#line 2623 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, EsdCube);
}
#line 9118 "MachineIndependent/glslang_tab.cpp"
break;
case 367: /* type_specifier_nonarray: F16SAMPLER1DSHADOW */
#line 2629 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd1D, false, true);
}
#line 9129 "MachineIndependent/glslang_tab.cpp"
break;
case 368: /* type_specifier_nonarray: F16SAMPLER2DSHADOW */
#line 2635 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd2D, false, true);
}
#line 9140 "MachineIndependent/glslang_tab.cpp"
break;
case 369: /* type_specifier_nonarray: F16SAMPLERCUBESHADOW */
#line 2641 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, EsdCube, false, true);
}
#line 9151 "MachineIndependent/glslang_tab.cpp"
break;
case 370: /* type_specifier_nonarray: F16SAMPLER1DARRAY */
#line 2647 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd1D, true);
}
#line 9162 "MachineIndependent/glslang_tab.cpp"
break;
case 371: /* type_specifier_nonarray: F16SAMPLER2DARRAY */
#line 2653 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd2D, true);
}
#line 9173 "MachineIndependent/glslang_tab.cpp"
break;
case 372: /* type_specifier_nonarray: F16SAMPLER1DARRAYSHADOW */
#line 2659 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd1D, true, true);
}
#line 9184 "MachineIndependent/glslang_tab.cpp"
break;
case 373: /* type_specifier_nonarray: F16SAMPLER2DARRAYSHADOW */
#line 2665 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd2D, true, true);
}
#line 9195 "MachineIndependent/glslang_tab.cpp"
break;
case 374: /* type_specifier_nonarray: F16SAMPLERCUBEARRAY */
#line 2671 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, EsdCube, true);
}
#line 9206 "MachineIndependent/glslang_tab.cpp"
break;
case 375: /* type_specifier_nonarray: F16SAMPLERCUBEARRAYSHADOW */
#line 2677 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, EsdCube, true, true);
}
#line 9217 "MachineIndependent/glslang_tab.cpp"
break;
case 376: /* type_specifier_nonarray: ISAMPLER1D */
#line 2683 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, Esd1D);
}
#line 9227 "MachineIndependent/glslang_tab.cpp"
break;
case 377: /* type_specifier_nonarray: ISAMPLER2D */
#line 2688 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, Esd2D);
}
#line 9237 "MachineIndependent/glslang_tab.cpp"
break;
case 378: /* type_specifier_nonarray: ISAMPLER3D */
#line 2693 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, Esd3D);
}
#line 9247 "MachineIndependent/glslang_tab.cpp"
break;
case 379: /* type_specifier_nonarray: ISAMPLERCUBE */
#line 2698 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, EsdCube);
}
#line 9257 "MachineIndependent/glslang_tab.cpp"
break;
case 380: /* type_specifier_nonarray: ISAMPLER2DARRAY */
#line 2703 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, Esd2D, true);
}
#line 9267 "MachineIndependent/glslang_tab.cpp"
break;
case 381: /* type_specifier_nonarray: USAMPLER2D */
#line 2708 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, Esd2D);
}
#line 9277 "MachineIndependent/glslang_tab.cpp"
break;
case 382: /* type_specifier_nonarray: USAMPLER3D */
#line 2713 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, Esd3D);
}
#line 9287 "MachineIndependent/glslang_tab.cpp"
break;
case 383: /* type_specifier_nonarray: USAMPLERCUBE */
#line 2718 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, EsdCube);
}
#line 9297 "MachineIndependent/glslang_tab.cpp"
break;
case 384: /* type_specifier_nonarray: ISAMPLER1DARRAY */
#line 2723 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, Esd1D, true);
}
#line 9307 "MachineIndependent/glslang_tab.cpp"
break;
case 385: /* type_specifier_nonarray: ISAMPLERCUBEARRAY */
#line 2728 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, EsdCube, true);
}
#line 9317 "MachineIndependent/glslang_tab.cpp"
break;
case 386: /* type_specifier_nonarray: USAMPLER1D */
#line 2733 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, Esd1D);
}
#line 9327 "MachineIndependent/glslang_tab.cpp"
break;
case 387: /* type_specifier_nonarray: USAMPLER1DARRAY */
#line 2738 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, Esd1D, true);
}
#line 9337 "MachineIndependent/glslang_tab.cpp"
break;
case 388: /* type_specifier_nonarray: USAMPLERCUBEARRAY */
#line 2743 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, EsdCube, true);
}
#line 9347 "MachineIndependent/glslang_tab.cpp"
break;
case 389: /* type_specifier_nonarray: TEXTURECUBEARRAY */
#line 2748 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, EsdCube, true);
}
#line 9357 "MachineIndependent/glslang_tab.cpp"
break;
case 390: /* type_specifier_nonarray: ITEXTURECUBEARRAY */
#line 2753 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, EsdCube, true);
}
#line 9367 "MachineIndependent/glslang_tab.cpp"
break;
case 391: /* type_specifier_nonarray: UTEXTURECUBEARRAY */
#line 2758 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, EsdCube, true);
}
#line 9377 "MachineIndependent/glslang_tab.cpp"
break;
case 392: /* type_specifier_nonarray: USAMPLER2DARRAY */
#line 2763 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, Esd2D, true);
}
#line 9387 "MachineIndependent/glslang_tab.cpp"
break;
case 393: /* type_specifier_nonarray: TEXTURE2D */
#line 2768 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, Esd2D);
}
#line 9397 "MachineIndependent/glslang_tab.cpp"
break;
case 394: /* type_specifier_nonarray: TEXTURE3D */
#line 2773 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, Esd3D);
}
#line 9407 "MachineIndependent/glslang_tab.cpp"
break;
case 395: /* type_specifier_nonarray: TEXTURE2DARRAY */
#line 2778 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, Esd2D, true);
}
#line 9417 "MachineIndependent/glslang_tab.cpp"
break;
case 396: /* type_specifier_nonarray: TEXTURECUBE */
#line 2783 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, EsdCube);
}
#line 9427 "MachineIndependent/glslang_tab.cpp"
break;
case 397: /* type_specifier_nonarray: ITEXTURE2D */
#line 2788 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, Esd2D);
}
#line 9437 "MachineIndependent/glslang_tab.cpp"
break;
case 398: /* type_specifier_nonarray: ITEXTURE3D */
#line 2793 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, Esd3D);
}
#line 9447 "MachineIndependent/glslang_tab.cpp"
break;
case 399: /* type_specifier_nonarray: ITEXTURECUBE */
#line 2798 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, EsdCube);
}
#line 9457 "MachineIndependent/glslang_tab.cpp"
break;
case 400: /* type_specifier_nonarray: ITEXTURE2DARRAY */
#line 2803 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, Esd2D, true);
}
#line 9467 "MachineIndependent/glslang_tab.cpp"
break;
case 401: /* type_specifier_nonarray: UTEXTURE2D */
#line 2808 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, Esd2D);
}
#line 9477 "MachineIndependent/glslang_tab.cpp"
break;
case 402: /* type_specifier_nonarray: UTEXTURE3D */
#line 2813 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, Esd3D);
}
#line 9487 "MachineIndependent/glslang_tab.cpp"
break;
case 403: /* type_specifier_nonarray: UTEXTURECUBE */
#line 2818 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, EsdCube);
}
#line 9497 "MachineIndependent/glslang_tab.cpp"
break;
case 404: /* type_specifier_nonarray: UTEXTURE2DARRAY */
#line 2823 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, Esd2D, true);
}
#line 9507 "MachineIndependent/glslang_tab.cpp"
break;
case 405: /* type_specifier_nonarray: SAMPLER */
#line 2828 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setPureSampler(false);
}
#line 9517 "MachineIndependent/glslang_tab.cpp"
break;
case 406: /* type_specifier_nonarray: SAMPLERSHADOW */
#line 2833 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setPureSampler(true);
}
#line 9527 "MachineIndependent/glslang_tab.cpp"
break;
case 407: /* type_specifier_nonarray: SAMPLER2DRECT */
#line 2838 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, EsdRect);
}
#line 9537 "MachineIndependent/glslang_tab.cpp"
break;
case 408: /* type_specifier_nonarray: SAMPLER2DRECTSHADOW */
#line 2843 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, EsdRect, false, true);
}
#line 9547 "MachineIndependent/glslang_tab.cpp"
break;
case 409: /* type_specifier_nonarray: F16SAMPLER2DRECT */
#line 2848 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, EsdRect);
}
#line 9558 "MachineIndependent/glslang_tab.cpp"
break;
case 410: /* type_specifier_nonarray: F16SAMPLER2DRECTSHADOW */
#line 2854 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, EsdRect, false, true);
}
#line 9569 "MachineIndependent/glslang_tab.cpp"
break;
case 411: /* type_specifier_nonarray: ISAMPLER2DRECT */
#line 2860 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, EsdRect);
}
#line 9579 "MachineIndependent/glslang_tab.cpp"
break;
case 412: /* type_specifier_nonarray: USAMPLER2DRECT */
#line 2865 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, EsdRect);
}
#line 9589 "MachineIndependent/glslang_tab.cpp"
break;
case 413: /* type_specifier_nonarray: SAMPLERBUFFER */
#line 2870 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, EsdBuffer);
}
#line 9599 "MachineIndependent/glslang_tab.cpp"
break;
case 414: /* type_specifier_nonarray: F16SAMPLERBUFFER */
#line 2875 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, EsdBuffer);
}
#line 9610 "MachineIndependent/glslang_tab.cpp"
break;
case 415: /* type_specifier_nonarray: ISAMPLERBUFFER */
#line 2881 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, EsdBuffer);
}
#line 9620 "MachineIndependent/glslang_tab.cpp"
break;
case 416: /* type_specifier_nonarray: USAMPLERBUFFER */
#line 2886 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, EsdBuffer);
}
#line 9630 "MachineIndependent/glslang_tab.cpp"
break;
case 417: /* type_specifier_nonarray: SAMPLER2DMS */
#line 2891 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd2D, false, false, true);
}
#line 9640 "MachineIndependent/glslang_tab.cpp"
break;
case 418: /* type_specifier_nonarray: F16SAMPLER2DMS */
#line 2896 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd2D, false, false, true);
}
#line 9651 "MachineIndependent/glslang_tab.cpp"
break;
case 419: /* type_specifier_nonarray: ISAMPLER2DMS */
#line 2902 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, Esd2D, false, false, true);
}
#line 9661 "MachineIndependent/glslang_tab.cpp"
break;
case 420: /* type_specifier_nonarray: USAMPLER2DMS */
#line 2907 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, Esd2D, false, false, true);
}
#line 9671 "MachineIndependent/glslang_tab.cpp"
break;
case 421: /* type_specifier_nonarray: SAMPLER2DMSARRAY */
#line 2912 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd2D, true, false, true);
}
#line 9681 "MachineIndependent/glslang_tab.cpp"
break;
case 422: /* type_specifier_nonarray: F16SAMPLER2DMSARRAY */
#line 2917 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float sampler", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat16, Esd2D, true, false, true);
}
#line 9692 "MachineIndependent/glslang_tab.cpp"
break;
case 423: /* type_specifier_nonarray: ISAMPLER2DMSARRAY */
#line 2923 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtInt, Esd2D, true, false, true);
}
#line 9702 "MachineIndependent/glslang_tab.cpp"
break;
case 424: /* type_specifier_nonarray: USAMPLER2DMSARRAY */
#line 2928 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtUint, Esd2D, true, false, true);
}
#line 9712 "MachineIndependent/glslang_tab.cpp"
break;
case 425: /* type_specifier_nonarray: TEXTURE1D */
#line 2933 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, Esd1D);
}
#line 9722 "MachineIndependent/glslang_tab.cpp"
break;
case 426: /* type_specifier_nonarray: F16TEXTURE1D */
#line 2938 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, Esd1D);
}
#line 9733 "MachineIndependent/glslang_tab.cpp"
break;
case 427: /* type_specifier_nonarray: F16TEXTURE2D */
#line 2944 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, Esd2D);
}
#line 9744 "MachineIndependent/glslang_tab.cpp"
break;
case 428: /* type_specifier_nonarray: F16TEXTURE3D */
#line 2950 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, Esd3D);
}
#line 9755 "MachineIndependent/glslang_tab.cpp"
break;
case 429: /* type_specifier_nonarray: F16TEXTURECUBE */
#line 2956 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, EsdCube);
}
#line 9766 "MachineIndependent/glslang_tab.cpp"
break;
case 430: /* type_specifier_nonarray: TEXTURE1DARRAY */
#line 2962 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, Esd1D, true);
}
#line 9776 "MachineIndependent/glslang_tab.cpp"
break;
case 431: /* type_specifier_nonarray: F16TEXTURE1DARRAY */
#line 2967 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, Esd1D, true);
}
#line 9787 "MachineIndependent/glslang_tab.cpp"
break;
case 432: /* type_specifier_nonarray: F16TEXTURE2DARRAY */
#line 2973 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, Esd2D, true);
}
#line 9798 "MachineIndependent/glslang_tab.cpp"
break;
case 433: /* type_specifier_nonarray: F16TEXTURECUBEARRAY */
#line 2979 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, EsdCube, true);
}
#line 9809 "MachineIndependent/glslang_tab.cpp"
break;
case 434: /* type_specifier_nonarray: ITEXTURE1D */
#line 2985 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, Esd1D);
}
#line 9819 "MachineIndependent/glslang_tab.cpp"
break;
case 435: /* type_specifier_nonarray: ITEXTURE1DARRAY */
#line 2990 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, Esd1D, true);
}
#line 9829 "MachineIndependent/glslang_tab.cpp"
break;
case 436: /* type_specifier_nonarray: UTEXTURE1D */
#line 2995 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, Esd1D);
}
#line 9839 "MachineIndependent/glslang_tab.cpp"
break;
case 437: /* type_specifier_nonarray: UTEXTURE1DARRAY */
#line 3000 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, Esd1D, true);
}
#line 9849 "MachineIndependent/glslang_tab.cpp"
break;
case 438: /* type_specifier_nonarray: TEXTURE2DRECT */
#line 3005 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, EsdRect);
}
#line 9859 "MachineIndependent/glslang_tab.cpp"
break;
case 439: /* type_specifier_nonarray: F16TEXTURE2DRECT */
#line 3010 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, EsdRect);
}
#line 9870 "MachineIndependent/glslang_tab.cpp"
break;
case 440: /* type_specifier_nonarray: ITEXTURE2DRECT */
#line 3016 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, EsdRect);
}
#line 9880 "MachineIndependent/glslang_tab.cpp"
break;
case 441: /* type_specifier_nonarray: UTEXTURE2DRECT */
#line 3021 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, EsdRect);
}
#line 9890 "MachineIndependent/glslang_tab.cpp"
break;
case 442: /* type_specifier_nonarray: TEXTUREBUFFER */
#line 3026 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, EsdBuffer);
}
#line 9900 "MachineIndependent/glslang_tab.cpp"
break;
case 443: /* type_specifier_nonarray: F16TEXTUREBUFFER */
#line 3031 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, EsdBuffer);
}
#line 9911 "MachineIndependent/glslang_tab.cpp"
break;
case 444: /* type_specifier_nonarray: ITEXTUREBUFFER */
#line 3037 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, EsdBuffer);
}
#line 9921 "MachineIndependent/glslang_tab.cpp"
break;
case 445: /* type_specifier_nonarray: UTEXTUREBUFFER */
#line 3042 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, EsdBuffer);
}
#line 9931 "MachineIndependent/glslang_tab.cpp"
break;
case 446: /* type_specifier_nonarray: TEXTURE2DMS */
#line 3047 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, Esd2D, false, false, true);
}
#line 9941 "MachineIndependent/glslang_tab.cpp"
break;
case 447: /* type_specifier_nonarray: F16TEXTURE2DMS */
#line 3052 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, Esd2D, false, false, true);
}
#line 9952 "MachineIndependent/glslang_tab.cpp"
break;
case 448: /* type_specifier_nonarray: ITEXTURE2DMS */
#line 3058 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, Esd2D, false, false, true);
}
#line 9962 "MachineIndependent/glslang_tab.cpp"
break;
case 449: /* type_specifier_nonarray: UTEXTURE2DMS */
#line 3063 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, Esd2D, false, false, true);
}
#line 9972 "MachineIndependent/glslang_tab.cpp"
break;
case 450: /* type_specifier_nonarray: TEXTURE2DMSARRAY */
#line 3068 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat, Esd2D, true, false, true);
}
#line 9982 "MachineIndependent/glslang_tab.cpp"
break;
case 451: /* type_specifier_nonarray: F16TEXTURE2DMSARRAY */
#line 3073 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float texture", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtFloat16, Esd2D, true, false, true);
}
#line 9993 "MachineIndependent/glslang_tab.cpp"
break;
case 452: /* type_specifier_nonarray: ITEXTURE2DMSARRAY */
#line 3079 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtInt, Esd2D, true, false, true);
}
#line 10003 "MachineIndependent/glslang_tab.cpp"
break;
case 453: /* type_specifier_nonarray: UTEXTURE2DMSARRAY */
#line 3084 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setTexture(EbtUint, Esd2D, true, false, true);
}
#line 10013 "MachineIndependent/glslang_tab.cpp"
break;
case 454: /* type_specifier_nonarray: IMAGE1D */
#line 3089 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, Esd1D);
}
#line 10023 "MachineIndependent/glslang_tab.cpp"
break;
case 455: /* type_specifier_nonarray: F16IMAGE1D */
#line 3094 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, Esd1D);
}
#line 10034 "MachineIndependent/glslang_tab.cpp"
break;
case 456: /* type_specifier_nonarray: IIMAGE1D */
#line 3100 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, Esd1D);
}
#line 10044 "MachineIndependent/glslang_tab.cpp"
break;
case 457: /* type_specifier_nonarray: UIMAGE1D */
#line 3105 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, Esd1D);
}
#line 10054 "MachineIndependent/glslang_tab.cpp"
break;
case 458: /* type_specifier_nonarray: IMAGE2D */
#line 3110 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, Esd2D);
}
#line 10064 "MachineIndependent/glslang_tab.cpp"
break;
case 459: /* type_specifier_nonarray: F16IMAGE2D */
#line 3115 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, Esd2D);
}
#line 10075 "MachineIndependent/glslang_tab.cpp"
break;
case 460: /* type_specifier_nonarray: IIMAGE2D */
#line 3121 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, Esd2D);
}
#line 10085 "MachineIndependent/glslang_tab.cpp"
break;
case 461: /* type_specifier_nonarray: UIMAGE2D */
#line 3126 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, Esd2D);
}
#line 10095 "MachineIndependent/glslang_tab.cpp"
break;
case 462: /* type_specifier_nonarray: IMAGE3D */
#line 3131 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, Esd3D);
}
#line 10105 "MachineIndependent/glslang_tab.cpp"
break;
case 463: /* type_specifier_nonarray: F16IMAGE3D */
#line 3136 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, Esd3D);
}
#line 10116 "MachineIndependent/glslang_tab.cpp"
break;
case 464: /* type_specifier_nonarray: IIMAGE3D */
#line 3142 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, Esd3D);
}
#line 10126 "MachineIndependent/glslang_tab.cpp"
break;
case 465: /* type_specifier_nonarray: UIMAGE3D */
#line 3147 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, Esd3D);
}
#line 10136 "MachineIndependent/glslang_tab.cpp"
break;
case 466: /* type_specifier_nonarray: IMAGE2DRECT */
#line 3152 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, EsdRect);
}
#line 10146 "MachineIndependent/glslang_tab.cpp"
break;
case 467: /* type_specifier_nonarray: F16IMAGE2DRECT */
#line 3157 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, EsdRect);
}
#line 10157 "MachineIndependent/glslang_tab.cpp"
break;
case 468: /* type_specifier_nonarray: IIMAGE2DRECT */
#line 3163 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, EsdRect);
}
#line 10167 "MachineIndependent/glslang_tab.cpp"
break;
case 469: /* type_specifier_nonarray: UIMAGE2DRECT */
#line 3168 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, EsdRect);
}
#line 10177 "MachineIndependent/glslang_tab.cpp"
break;
case 470: /* type_specifier_nonarray: IMAGECUBE */
#line 3173 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, EsdCube);
}
#line 10187 "MachineIndependent/glslang_tab.cpp"
break;
case 471: /* type_specifier_nonarray: F16IMAGECUBE */
#line 3178 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, EsdCube);
}
#line 10198 "MachineIndependent/glslang_tab.cpp"
break;
case 472: /* type_specifier_nonarray: IIMAGECUBE */
#line 3184 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, EsdCube);
}
#line 10208 "MachineIndependent/glslang_tab.cpp"
break;
case 473: /* type_specifier_nonarray: UIMAGECUBE */
#line 3189 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, EsdCube);
}
#line 10218 "MachineIndependent/glslang_tab.cpp"
break;
case 474: /* type_specifier_nonarray: IMAGEBUFFER */
#line 3194 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, EsdBuffer);
}
#line 10228 "MachineIndependent/glslang_tab.cpp"
break;
case 475: /* type_specifier_nonarray: F16IMAGEBUFFER */
#line 3199 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, EsdBuffer);
}
#line 10239 "MachineIndependent/glslang_tab.cpp"
break;
case 476: /* type_specifier_nonarray: IIMAGEBUFFER */
#line 3205 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, EsdBuffer);
}
#line 10249 "MachineIndependent/glslang_tab.cpp"
break;
case 477: /* type_specifier_nonarray: UIMAGEBUFFER */
#line 3210 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, EsdBuffer);
}
#line 10259 "MachineIndependent/glslang_tab.cpp"
break;
case 478: /* type_specifier_nonarray: IMAGE1DARRAY */
#line 3215 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, Esd1D, true);
}
#line 10269 "MachineIndependent/glslang_tab.cpp"
break;
case 479: /* type_specifier_nonarray: F16IMAGE1DARRAY */
#line 3220 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, Esd1D, true);
}
#line 10280 "MachineIndependent/glslang_tab.cpp"
break;
case 480: /* type_specifier_nonarray: IIMAGE1DARRAY */
#line 3226 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, Esd1D, true);
}
#line 10290 "MachineIndependent/glslang_tab.cpp"
break;
case 481: /* type_specifier_nonarray: UIMAGE1DARRAY */
#line 3231 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, Esd1D, true);
}
#line 10300 "MachineIndependent/glslang_tab.cpp"
break;
case 482: /* type_specifier_nonarray: IMAGE2DARRAY */
#line 3236 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, Esd2D, true);
}
#line 10310 "MachineIndependent/glslang_tab.cpp"
break;
case 483: /* type_specifier_nonarray: F16IMAGE2DARRAY */
#line 3241 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, Esd2D, true);
}
#line 10321 "MachineIndependent/glslang_tab.cpp"
break;
case 484: /* type_specifier_nonarray: IIMAGE2DARRAY */
#line 3247 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, Esd2D, true);
}
#line 10331 "MachineIndependent/glslang_tab.cpp"
break;
case 485: /* type_specifier_nonarray: UIMAGE2DARRAY */
#line 3252 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, Esd2D, true);
}
#line 10341 "MachineIndependent/glslang_tab.cpp"
break;
case 486: /* type_specifier_nonarray: IMAGECUBEARRAY */
#line 3257 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, EsdCube, true);
}
#line 10351 "MachineIndependent/glslang_tab.cpp"
break;
case 487: /* type_specifier_nonarray: F16IMAGECUBEARRAY */
#line 3262 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, EsdCube, true);
}
#line 10362 "MachineIndependent/glslang_tab.cpp"
break;
case 488: /* type_specifier_nonarray: IIMAGECUBEARRAY */
#line 3268 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, EsdCube, true);
}
#line 10372 "MachineIndependent/glslang_tab.cpp"
break;
case 489: /* type_specifier_nonarray: UIMAGECUBEARRAY */
#line 3273 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, EsdCube, true);
}
#line 10382 "MachineIndependent/glslang_tab.cpp"
break;
case 490: /* type_specifier_nonarray: IMAGE2DMS */
#line 3278 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, Esd2D, false, false, true);
}
#line 10392 "MachineIndependent/glslang_tab.cpp"
break;
case 491: /* type_specifier_nonarray: F16IMAGE2DMS */
#line 3283 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, Esd2D, false, false, true);
}
#line 10403 "MachineIndependent/glslang_tab.cpp"
break;
case 492: /* type_specifier_nonarray: IIMAGE2DMS */
#line 3289 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, Esd2D, false, false, true);
}
#line 10413 "MachineIndependent/glslang_tab.cpp"
break;
case 493: /* type_specifier_nonarray: UIMAGE2DMS */
#line 3294 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, Esd2D, false, false, true);
}
#line 10423 "MachineIndependent/glslang_tab.cpp"
break;
case 494: /* type_specifier_nonarray: IMAGE2DMSARRAY */
#line 3299 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat, Esd2D, true, false, true);
}
#line 10433 "MachineIndependent/glslang_tab.cpp"
break;
case 495: /* type_specifier_nonarray: F16IMAGE2DMSARRAY */
#line 3304 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float image", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtFloat16, Esd2D, true, false, true);
}
#line 10444 "MachineIndependent/glslang_tab.cpp"
break;
case 496: /* type_specifier_nonarray: IIMAGE2DMSARRAY */
#line 3310 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt, Esd2D, true, false, true);
}
#line 10454 "MachineIndependent/glslang_tab.cpp"
break;
case 497: /* type_specifier_nonarray: UIMAGE2DMSARRAY */
#line 3315 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint, Esd2D, true, false, true);
}
#line 10464 "MachineIndependent/glslang_tab.cpp"
break;
case 498: /* type_specifier_nonarray: I64IMAGE1D */
#line 3320 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, Esd1D);
}
#line 10474 "MachineIndependent/glslang_tab.cpp"
break;
case 499: /* type_specifier_nonarray: U64IMAGE1D */
#line 3325 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, Esd1D);
}
#line 10484 "MachineIndependent/glslang_tab.cpp"
break;
case 500: /* type_specifier_nonarray: I64IMAGE2D */
#line 3330 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, Esd2D);
}
#line 10494 "MachineIndependent/glslang_tab.cpp"
break;
case 501: /* type_specifier_nonarray: U64IMAGE2D */
#line 3335 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, Esd2D);
}
#line 10504 "MachineIndependent/glslang_tab.cpp"
break;
case 502: /* type_specifier_nonarray: I64IMAGE3D */
#line 3340 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, Esd3D);
}
#line 10514 "MachineIndependent/glslang_tab.cpp"
break;
case 503: /* type_specifier_nonarray: U64IMAGE3D */
#line 3345 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, Esd3D);
}
#line 10524 "MachineIndependent/glslang_tab.cpp"
break;
case 504: /* type_specifier_nonarray: I64IMAGE2DRECT */
#line 3350 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, EsdRect);
}
#line 10534 "MachineIndependent/glslang_tab.cpp"
break;
case 505: /* type_specifier_nonarray: U64IMAGE2DRECT */
#line 3355 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, EsdRect);
}
#line 10544 "MachineIndependent/glslang_tab.cpp"
break;
case 506: /* type_specifier_nonarray: I64IMAGECUBE */
#line 3360 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, EsdCube);
}
#line 10554 "MachineIndependent/glslang_tab.cpp"
break;
case 507: /* type_specifier_nonarray: U64IMAGECUBE */
#line 3365 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, EsdCube);
}
#line 10564 "MachineIndependent/glslang_tab.cpp"
break;
case 508: /* type_specifier_nonarray: I64IMAGEBUFFER */
#line 3370 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, EsdBuffer);
}
#line 10574 "MachineIndependent/glslang_tab.cpp"
break;
case 509: /* type_specifier_nonarray: U64IMAGEBUFFER */
#line 3375 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, EsdBuffer);
}
#line 10584 "MachineIndependent/glslang_tab.cpp"
break;
case 510: /* type_specifier_nonarray: I64IMAGE1DARRAY */
#line 3380 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, Esd1D, true);
}
#line 10594 "MachineIndependent/glslang_tab.cpp"
break;
case 511: /* type_specifier_nonarray: U64IMAGE1DARRAY */
#line 3385 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, Esd1D, true);
}
#line 10604 "MachineIndependent/glslang_tab.cpp"
break;
case 512: /* type_specifier_nonarray: I64IMAGE2DARRAY */
#line 3390 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, Esd2D, true);
}
#line 10614 "MachineIndependent/glslang_tab.cpp"
break;
case 513: /* type_specifier_nonarray: U64IMAGE2DARRAY */
#line 3395 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, Esd2D, true);
}
#line 10624 "MachineIndependent/glslang_tab.cpp"
break;
case 514: /* type_specifier_nonarray: I64IMAGECUBEARRAY */
#line 3400 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, EsdCube, true);
}
#line 10634 "MachineIndependent/glslang_tab.cpp"
break;
case 515: /* type_specifier_nonarray: U64IMAGECUBEARRAY */
#line 3405 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, EsdCube, true);
}
#line 10644 "MachineIndependent/glslang_tab.cpp"
break;
case 516: /* type_specifier_nonarray: I64IMAGE2DMS */
#line 3410 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, Esd2D, false, false, true);
}
#line 10654 "MachineIndependent/glslang_tab.cpp"
break;
case 517: /* type_specifier_nonarray: U64IMAGE2DMS */
#line 3415 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, Esd2D, false, false, true);
}
#line 10664 "MachineIndependent/glslang_tab.cpp"
break;
case 518: /* type_specifier_nonarray: I64IMAGE2DMSARRAY */
#line 3420 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtInt64, Esd2D, true, false, true);
}
#line 10674 "MachineIndependent/glslang_tab.cpp"
break;
case 519: /* type_specifier_nonarray: U64IMAGE2DMSARRAY */
#line 3425 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setImage(EbtUint64, Esd2D, true, false, true);
}
#line 10684 "MachineIndependent/glslang_tab.cpp"
break;
case 520: /* type_specifier_nonarray: SAMPLEREXTERNALOES */
#line 3430 "MachineIndependent/glslang.y"
{ // GL_OES_EGL_image_external
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd2D);
(yyval.interm.type).sampler.external = true;
}
#line 10695 "MachineIndependent/glslang_tab.cpp"
break;
case 521: /* type_specifier_nonarray: SAMPLEREXTERNAL2DY2YEXT */
#line 3436 "MachineIndependent/glslang.y"
{ // GL_EXT_YUV_target
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.set(EbtFloat, Esd2D);
(yyval.interm.type).sampler.yuv = true;
}
#line 10706 "MachineIndependent/glslang_tab.cpp"
break;
case 522: /* type_specifier_nonarray: ATTACHMENTEXT */
#line 3442 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "attachmentEXT input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setAttachmentEXT(EbtFloat);
}
#line 10717 "MachineIndependent/glslang_tab.cpp"
break;
case 523: /* type_specifier_nonarray: IATTACHMENTEXT */
#line 3448 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "attachmentEXT input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setAttachmentEXT(EbtInt);
}
#line 10728 "MachineIndependent/glslang_tab.cpp"
break;
case 524: /* type_specifier_nonarray: UATTACHMENTEXT */
#line 3454 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "attachmentEXT input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setAttachmentEXT(EbtUint);
}
#line 10739 "MachineIndependent/glslang_tab.cpp"
break;
case 525: /* type_specifier_nonarray: SUBPASSINPUT */
#line 3460 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "subpass input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setSubpass(EbtFloat);
}
#line 10750 "MachineIndependent/glslang_tab.cpp"
break;
case 526: /* type_specifier_nonarray: SUBPASSINPUTMS */
#line 3466 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "subpass input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setSubpass(EbtFloat, true);
}
#line 10761 "MachineIndependent/glslang_tab.cpp"
break;
case 527: /* type_specifier_nonarray: F16SUBPASSINPUT */
#line 3472 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float subpass input", parseContext.symbolTable.atBuiltInLevel());
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "subpass input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setSubpass(EbtFloat16);
}
#line 10773 "MachineIndependent/glslang_tab.cpp"
break;
case 528: /* type_specifier_nonarray: F16SUBPASSINPUTMS */
#line 3479 "MachineIndependent/glslang.y"
{
parseContext.float16OpaqueCheck((yyvsp[0].lex).loc, "half float subpass input", parseContext.symbolTable.atBuiltInLevel());
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "subpass input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setSubpass(EbtFloat16, true);
}
#line 10785 "MachineIndependent/glslang_tab.cpp"
break;
case 529: /* type_specifier_nonarray: ISUBPASSINPUT */
#line 3486 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "subpass input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setSubpass(EbtInt);
}
#line 10796 "MachineIndependent/glslang_tab.cpp"
break;
case 530: /* type_specifier_nonarray: ISUBPASSINPUTMS */
#line 3492 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "subpass input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setSubpass(EbtInt, true);
}
#line 10807 "MachineIndependent/glslang_tab.cpp"
break;
case 531: /* type_specifier_nonarray: USUBPASSINPUT */
#line 3498 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "subpass input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setSubpass(EbtUint);
}
#line 10818 "MachineIndependent/glslang_tab.cpp"
break;
case 532: /* type_specifier_nonarray: USUBPASSINPUTMS */
#line 3504 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[0].lex).loc, EShLangFragment, "subpass input");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtSampler;
(yyval.interm.type).sampler.setSubpass(EbtUint, true);
}
#line 10829 "MachineIndependent/glslang_tab.cpp"
break;
case 533: /* type_specifier_nonarray: FCOOPMATNV */
#line 3510 "MachineIndependent/glslang.y"
{
parseContext.fcoopmatCheckNV((yyvsp[0].lex).loc, "fcoopmatNV", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtFloat;
(yyval.interm.type).coopmatNV = true;
(yyval.interm.type).coopmatKHR = false;
}
#line 10841 "MachineIndependent/glslang_tab.cpp"
break;
case 534: /* type_specifier_nonarray: ICOOPMATNV */
#line 3517 "MachineIndependent/glslang.y"
{
parseContext.intcoopmatCheckNV((yyvsp[0].lex).loc, "icoopmatNV", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtInt;
(yyval.interm.type).coopmatNV = true;
(yyval.interm.type).coopmatKHR = false;
}
#line 10853 "MachineIndependent/glslang_tab.cpp"
break;
case 535: /* type_specifier_nonarray: UCOOPMATNV */
#line 3524 "MachineIndependent/glslang.y"
{
parseContext.intcoopmatCheckNV((yyvsp[0].lex).loc, "ucoopmatNV", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtUint;
(yyval.interm.type).coopmatNV = true;
(yyval.interm.type).coopmatKHR = false;
}
#line 10865 "MachineIndependent/glslang_tab.cpp"
break;
case 536: /* type_specifier_nonarray: COOPMAT */
#line 3531 "MachineIndependent/glslang.y"
{
parseContext.coopmatCheck((yyvsp[0].lex).loc, "coopmat", parseContext.symbolTable.atBuiltInLevel());
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtCoopmat;
(yyval.interm.type).coopmatNV = false;
(yyval.interm.type).coopmatKHR = true;
}
#line 10877 "MachineIndependent/glslang_tab.cpp"
break;
case 537: /* type_specifier_nonarray: spirv_type_specifier */
#line 3538 "MachineIndependent/glslang.y"
{
parseContext.requireExtensions((yyvsp[0].interm.type).loc, 1, &E_GL_EXT_spirv_intrinsics, "SPIR-V type specifier");
(yyval.interm.type) = (yyvsp[0].interm.type);
}
#line 10886 "MachineIndependent/glslang_tab.cpp"
break;
case 538: /* type_specifier_nonarray: HITOBJECTNV */
#line 3542 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtHitObjectNV;
}
#line 10895 "MachineIndependent/glslang_tab.cpp"
break;
case 539: /* type_specifier_nonarray: struct_specifier */
#line 3546 "MachineIndependent/glslang.y"
{
(yyval.interm.type) = (yyvsp[0].interm.type);
(yyval.interm.type).qualifier.storage = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
parseContext.structTypeCheck((yyval.interm.type).loc, (yyval.interm.type));
}
#line 10905 "MachineIndependent/glslang_tab.cpp"
break;
case 540: /* type_specifier_nonarray: TYPE_NAME */
#line 3551 "MachineIndependent/glslang.y"
{
//
// This is for user defined type names. The lexical phase looked up the
// type.
//
if (const TVariable* variable = ((yyvsp[0].lex).symbol)->getAsVariable()) {
const TType& structure = variable->getType();
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).basicType = EbtStruct;
(yyval.interm.type).userDef = &structure;
} else
parseContext.error((yyvsp[0].lex).loc, "expected type name", (yyvsp[0].lex).string->c_str(), "");
}
#line 10923 "MachineIndependent/glslang_tab.cpp"
break;
case 541: /* precision_qualifier: HIGH_PRECISION */
#line 3567 "MachineIndependent/glslang.y"
{
parseContext.profileRequires((yyvsp[0].lex).loc, ENoProfile, 130, 0, "highp precision qualifier");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
parseContext.handlePrecisionQualifier((yyvsp[0].lex).loc, (yyval.interm.type).qualifier, EpqHigh);
}
#line 10933 "MachineIndependent/glslang_tab.cpp"
break;
case 542: /* precision_qualifier: MEDIUM_PRECISION */
#line 3572 "MachineIndependent/glslang.y"
{
parseContext.profileRequires((yyvsp[0].lex).loc, ENoProfile, 130, 0, "mediump precision qualifier");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
parseContext.handlePrecisionQualifier((yyvsp[0].lex).loc, (yyval.interm.type).qualifier, EpqMedium);
}
#line 10943 "MachineIndependent/glslang_tab.cpp"
break;
case 543: /* precision_qualifier: LOW_PRECISION */
#line 3577 "MachineIndependent/glslang.y"
{
parseContext.profileRequires((yyvsp[0].lex).loc, ENoProfile, 130, 0, "lowp precision qualifier");
(yyval.interm.type).init((yyvsp[0].lex).loc, parseContext.symbolTable.atGlobalLevel());
parseContext.handlePrecisionQualifier((yyvsp[0].lex).loc, (yyval.interm.type).qualifier, EpqLow);
}
#line 10953 "MachineIndependent/glslang_tab.cpp"
break;
case 544: /* $@3: %empty */
#line 3585 "MachineIndependent/glslang.y"
{ parseContext.nestedStructCheck((yyvsp[-2].lex).loc); }
#line 10959 "MachineIndependent/glslang_tab.cpp"
break;
case 545: /* struct_specifier: STRUCT IDENTIFIER LEFT_BRACE $@3 struct_declaration_list RIGHT_BRACE */
#line 3585 "MachineIndependent/glslang.y"
{
TType* structure = new TType((yyvsp[-1].interm.typeList), *(yyvsp[-4].lex).string);
parseContext.structArrayCheck((yyvsp[-4].lex).loc, *structure);
TVariable* userTypeDef = new TVariable((yyvsp[-4].lex).string, *structure, true);
if (! parseContext.symbolTable.insert(*userTypeDef))
parseContext.error((yyvsp[-4].lex).loc, "redefinition", (yyvsp[-4].lex).string->c_str(), "struct");
else if (parseContext.spvVersion.vulkanRelaxed
&& structure->containsOpaque())
parseContext.relaxedSymbols.push_back(structure->getTypeName());
(yyval.interm.type).init((yyvsp[-5].lex).loc);
(yyval.interm.type).basicType = EbtStruct;
(yyval.interm.type).userDef = structure;
--parseContext.structNestingLevel;
}
#line 10981 "MachineIndependent/glslang_tab.cpp"
break;
case 546: /* $@4: %empty */
#line 3602 "MachineIndependent/glslang.y"
{ parseContext.nestedStructCheck((yyvsp[-1].lex).loc); }
#line 10987 "MachineIndependent/glslang_tab.cpp"
break;
case 547: /* struct_specifier: STRUCT LEFT_BRACE $@4 struct_declaration_list RIGHT_BRACE */
#line 3602 "MachineIndependent/glslang.y"
{
TType* structure = new TType((yyvsp[-1].interm.typeList), TString(""));
(yyval.interm.type).init((yyvsp[-4].lex).loc);
(yyval.interm.type).basicType = EbtStruct;
(yyval.interm.type).userDef = structure;
--parseContext.structNestingLevel;
}
#line 10999 "MachineIndependent/glslang_tab.cpp"
break;
case 548: /* struct_declaration_list: struct_declaration */
#line 3612 "MachineIndependent/glslang.y"
{
(yyval.interm.typeList) = (yyvsp[0].interm.typeList);
}
#line 11007 "MachineIndependent/glslang_tab.cpp"
break;
case 549: /* struct_declaration_list: struct_declaration_list struct_declaration */
#line 3615 "MachineIndependent/glslang.y"
{
(yyval.interm.typeList) = (yyvsp[-1].interm.typeList);
for (unsigned int i = 0; i < (yyvsp[0].interm.typeList)->size(); ++i) {
for (unsigned int j = 0; j < (yyval.interm.typeList)->size(); ++j) {
if ((*(yyval.interm.typeList))[j].type->getFieldName() == (*(yyvsp[0].interm.typeList))[i].type->getFieldName())
parseContext.error((*(yyvsp[0].interm.typeList))[i].loc, "duplicate member name:", "", (*(yyvsp[0].interm.typeList))[i].type->getFieldName().c_str());
}
(yyval.interm.typeList)->push_back((*(yyvsp[0].interm.typeList))[i]);
}
}
#line 11022 "MachineIndependent/glslang_tab.cpp"
break;
case 550: /* struct_declaration: type_specifier struct_declarator_list SEMICOLON */
#line 3628 "MachineIndependent/glslang.y"
{
if ((yyvsp[-2].interm.type).arraySizes) {
parseContext.profileRequires((yyvsp[-2].interm.type).loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
parseContext.profileRequires((yyvsp[-2].interm.type).loc, EEsProfile, 300, 0, "arrayed type");
if (parseContext.isEsProfile())
parseContext.arraySizeRequiredCheck((yyvsp[-2].interm.type).loc, *(yyvsp[-2].interm.type).arraySizes);
}
(yyval.interm.typeList) = (yyvsp[-1].interm.typeList);
parseContext.voidErrorCheck((yyvsp[-2].interm.type).loc, (*(yyvsp[-1].interm.typeList))[0].type->getFieldName(), (yyvsp[-2].interm.type).basicType);
parseContext.precisionQualifierCheck((yyvsp[-2].interm.type).loc, (yyvsp[-2].interm.type).basicType, (yyvsp[-2].interm.type).qualifier, (yyvsp[-2].interm.type).isCoopmat());
for (unsigned int i = 0; i < (yyval.interm.typeList)->size(); ++i) {
TType type((yyvsp[-2].interm.type));
type.setFieldName((*(yyval.interm.typeList))[i].type->getFieldName());
type.transferArraySizes((*(yyval.interm.typeList))[i].type->getArraySizes());
type.copyArrayInnerSizes((yyvsp[-2].interm.type).arraySizes);
parseContext.arrayOfArrayVersionCheck((*(yyval.interm.typeList))[i].loc, type.getArraySizes());
(*(yyval.interm.typeList))[i].type->shallowCopy(type);
}
}
#line 11049 "MachineIndependent/glslang_tab.cpp"
break;
case 551: /* struct_declaration: type_qualifier type_specifier struct_declarator_list SEMICOLON */
#line 3650 "MachineIndependent/glslang.y"
{
if ((yyvsp[-2].interm.type).arraySizes) {
parseContext.profileRequires((yyvsp[-2].interm.type).loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
parseContext.profileRequires((yyvsp[-2].interm.type).loc, EEsProfile, 300, 0, "arrayed type");
if (parseContext.isEsProfile())
parseContext.arraySizeRequiredCheck((yyvsp[-2].interm.type).loc, *(yyvsp[-2].interm.type).arraySizes);
}
(yyval.interm.typeList) = (yyvsp[-1].interm.typeList);
parseContext.memberQualifierCheck((yyvsp[-3].interm.type));
parseContext.voidErrorCheck((yyvsp[-2].interm.type).loc, (*(yyvsp[-1].interm.typeList))[0].type->getFieldName(), (yyvsp[-2].interm.type).basicType);
parseContext.mergeQualifiers((yyvsp[-2].interm.type).loc, (yyvsp[-2].interm.type).qualifier, (yyvsp[-3].interm.type).qualifier, true);
parseContext.precisionQualifierCheck((yyvsp[-2].interm.type).loc, (yyvsp[-2].interm.type).basicType, (yyvsp[-2].interm.type).qualifier, (yyvsp[-2].interm.type).isCoopmat());
for (unsigned int i = 0; i < (yyval.interm.typeList)->size(); ++i) {
TType type((yyvsp[-2].interm.type));
type.setFieldName((*(yyval.interm.typeList))[i].type->getFieldName());
type.transferArraySizes((*(yyval.interm.typeList))[i].type->getArraySizes());
type.copyArrayInnerSizes((yyvsp[-2].interm.type).arraySizes);
parseContext.arrayOfArrayVersionCheck((*(yyval.interm.typeList))[i].loc, type.getArraySizes());
(*(yyval.interm.typeList))[i].type->shallowCopy(type);
}
}
#line 11078 "MachineIndependent/glslang_tab.cpp"
break;
case 552: /* struct_declarator_list: struct_declarator */
#line 3677 "MachineIndependent/glslang.y"
{
(yyval.interm.typeList) = new TTypeList;
(yyval.interm.typeList)->push_back((yyvsp[0].interm.typeLine));
}
#line 11087 "MachineIndependent/glslang_tab.cpp"
break;
case 553: /* struct_declarator_list: struct_declarator_list COMMA struct_declarator */
#line 3681 "MachineIndependent/glslang.y"
{
(yyval.interm.typeList)->push_back((yyvsp[0].interm.typeLine));
}
#line 11095 "MachineIndependent/glslang_tab.cpp"
break;
case 554: /* struct_declarator: IDENTIFIER */
#line 3687 "MachineIndependent/glslang.y"
{
(yyval.interm.typeLine).type = new TType(EbtVoid);
(yyval.interm.typeLine).loc = (yyvsp[0].lex).loc;
(yyval.interm.typeLine).type->setFieldName(*(yyvsp[0].lex).string);
}
#line 11105 "MachineIndependent/glslang_tab.cpp"
break;
case 555: /* struct_declarator: IDENTIFIER array_specifier */
#line 3692 "MachineIndependent/glslang.y"
{
parseContext.arrayOfArrayVersionCheck((yyvsp[-1].lex).loc, (yyvsp[0].interm).arraySizes);
(yyval.interm.typeLine).type = new TType(EbtVoid);
(yyval.interm.typeLine).loc = (yyvsp[-1].lex).loc;
(yyval.interm.typeLine).type->setFieldName(*(yyvsp[-1].lex).string);
(yyval.interm.typeLine).type->transferArraySizes((yyvsp[0].interm).arraySizes);
}
#line 11118 "MachineIndependent/glslang_tab.cpp"
break;
case 556: /* initializer: assignment_expression */
#line 3703 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
#line 11126 "MachineIndependent/glslang_tab.cpp"
break;
case 557: /* initializer: LEFT_BRACE initializer_list RIGHT_BRACE */
#line 3706 "MachineIndependent/glslang.y"
{
const char* initFeature = "{ } style initializers";
parseContext.requireProfile((yyvsp[-2].lex).loc, ~EEsProfile, initFeature);
parseContext.profileRequires((yyvsp[-2].lex).loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature);
(yyval.interm.intermTypedNode) = (yyvsp[-1].interm.intermTypedNode);
}
#line 11137 "MachineIndependent/glslang_tab.cpp"
break;
case 558: /* initializer: LEFT_BRACE initializer_list COMMA RIGHT_BRACE */
#line 3712 "MachineIndependent/glslang.y"
{
const char* initFeature = "{ } style initializers";
parseContext.requireProfile((yyvsp[-3].lex).loc, ~EEsProfile, initFeature);
parseContext.profileRequires((yyvsp[-3].lex).loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature);
(yyval.interm.intermTypedNode) = (yyvsp[-2].interm.intermTypedNode);
}
#line 11148 "MachineIndependent/glslang_tab.cpp"
break;
case 559: /* initializer: LEFT_BRACE RIGHT_BRACE */
#line 3718 "MachineIndependent/glslang.y"
{
const char* initFeature = "empty { } initializer";
parseContext.profileRequires((yyvsp[-1].lex).loc, EEsProfile, 0, E_GL_EXT_null_initializer, initFeature);
parseContext.profileRequires((yyvsp[-1].lex).loc, ~EEsProfile, 0, E_GL_EXT_null_initializer, initFeature);
(yyval.interm.intermTypedNode) = parseContext.intermediate.makeAggregate((yyvsp[-1].lex).loc);
}
#line 11159 "MachineIndependent/glslang_tab.cpp"
break;
case 560: /* initializer_list: initializer */
#line 3727 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.intermediate.growAggregate(0, (yyvsp[0].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode)->getLoc());
}
#line 11167 "MachineIndependent/glslang_tab.cpp"
break;
case 561: /* initializer_list: initializer_list COMMA initializer */
#line 3730 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = parseContext.intermediate.growAggregate((yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode));
}
#line 11175 "MachineIndependent/glslang_tab.cpp"
break;
case 562: /* declaration_statement: declaration */
#line 3736 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11181 "MachineIndependent/glslang_tab.cpp"
break;
case 563: /* statement: compound_statement */
#line 3740 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11187 "MachineIndependent/glslang_tab.cpp"
break;
case 564: /* statement: simple_statement */
#line 3741 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11193 "MachineIndependent/glslang_tab.cpp"
break;
case 565: /* simple_statement: declaration_statement */
#line 3747 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11199 "MachineIndependent/glslang_tab.cpp"
break;
case 566: /* simple_statement: expression_statement */
#line 3748 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11205 "MachineIndependent/glslang_tab.cpp"
break;
case 567: /* simple_statement: selection_statement */
#line 3749 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11211 "MachineIndependent/glslang_tab.cpp"
break;
case 568: /* simple_statement: switch_statement */
#line 3750 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11217 "MachineIndependent/glslang_tab.cpp"
break;
case 569: /* simple_statement: case_label */
#line 3751 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11223 "MachineIndependent/glslang_tab.cpp"
break;
case 570: /* simple_statement: iteration_statement */
#line 3752 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11229 "MachineIndependent/glslang_tab.cpp"
break;
case 571: /* simple_statement: jump_statement */
#line 3753 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11235 "MachineIndependent/glslang_tab.cpp"
break;
case 572: /* simple_statement: demote_statement */
#line 3754 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11241 "MachineIndependent/glslang_tab.cpp"
break;
case 573: /* demote_statement: DEMOTE SEMICOLON */
#line 3758 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[-1].lex).loc, EShLangFragment, "demote");
parseContext.requireExtensions((yyvsp[-1].lex).loc, 1, &E_GL_EXT_demote_to_helper_invocation, "demote");
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpDemote, (yyvsp[-1].lex).loc);
}
#line 11251 "MachineIndependent/glslang_tab.cpp"
break;
case 574: /* compound_statement: LEFT_BRACE RIGHT_BRACE */
#line 3766 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = 0; }
#line 11257 "MachineIndependent/glslang_tab.cpp"
break;
case 575: /* $@5: %empty */
#line 3767 "MachineIndependent/glslang.y"
{
parseContext.symbolTable.push();
++parseContext.statementNestingLevel;
}
#line 11266 "MachineIndependent/glslang_tab.cpp"
break;
case 576: /* $@6: %empty */
#line 3771 "MachineIndependent/glslang.y"
{
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
--parseContext.statementNestingLevel;
}
#line 11275 "MachineIndependent/glslang_tab.cpp"
break;
case 577: /* compound_statement: LEFT_BRACE $@5 statement_list $@6 RIGHT_BRACE */
#line 3775 "MachineIndependent/glslang.y"
{
if ((yyvsp[-2].interm.intermNode) && (yyvsp[-2].interm.intermNode)->getAsAggregate())
(yyvsp[-2].interm.intermNode)->getAsAggregate()->setOperator(parseContext.intermediate.getDebugInfo() ? EOpScope : EOpSequence);
(yyval.interm.intermNode) = (yyvsp[-2].interm.intermNode);
}
#line 11285 "MachineIndependent/glslang_tab.cpp"
break;
case 578: /* statement_no_new_scope: compound_statement_no_new_scope */
#line 3783 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11291 "MachineIndependent/glslang_tab.cpp"
break;
case 579: /* statement_no_new_scope: simple_statement */
#line 3784 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); }
#line 11297 "MachineIndependent/glslang_tab.cpp"
break;
case 580: /* $@7: %empty */
#line 3788 "MachineIndependent/glslang.y"
{
++parseContext.controlFlowNestingLevel;
}
#line 11305 "MachineIndependent/glslang_tab.cpp"
break;
case 581: /* statement_scoped: $@7 compound_statement */
#line 3791 "MachineIndependent/glslang.y"
{
--parseContext.controlFlowNestingLevel;
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11314 "MachineIndependent/glslang_tab.cpp"
break;
case 582: /* $@8: %empty */
#line 3795 "MachineIndependent/glslang.y"
{
parseContext.symbolTable.push();
++parseContext.statementNestingLevel;
++parseContext.controlFlowNestingLevel;
}
#line 11324 "MachineIndependent/glslang_tab.cpp"
break;
case 583: /* statement_scoped: $@8 simple_statement */
#line 3800 "MachineIndependent/glslang.y"
{
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
--parseContext.statementNestingLevel;
--parseContext.controlFlowNestingLevel;
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11335 "MachineIndependent/glslang_tab.cpp"
break;
case 584: /* compound_statement_no_new_scope: LEFT_BRACE RIGHT_BRACE */
#line 3809 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = 0;
}
#line 11343 "MachineIndependent/glslang_tab.cpp"
break;
case 585: /* compound_statement_no_new_scope: LEFT_BRACE statement_list RIGHT_BRACE */
#line 3812 "MachineIndependent/glslang.y"
{
if ((yyvsp[-1].interm.intermNode) && (yyvsp[-1].interm.intermNode)->getAsAggregate())
(yyvsp[-1].interm.intermNode)->getAsAggregate()->setOperator(EOpSequence);
(yyval.interm.intermNode) = (yyvsp[-1].interm.intermNode);
}
#line 11353 "MachineIndependent/glslang_tab.cpp"
break;
case 586: /* statement_list: statement */
#line 3820 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.makeAggregate((yyvsp[0].interm.intermNode));
if ((yyvsp[0].interm.intermNode) && (yyvsp[0].interm.intermNode)->getAsBranchNode() && ((yyvsp[0].interm.intermNode)->getAsBranchNode()->getFlowOp() == EOpCase ||
(yyvsp[0].interm.intermNode)->getAsBranchNode()->getFlowOp() == EOpDefault)) {
parseContext.wrapupSwitchSubsequence(0, (yyvsp[0].interm.intermNode));
(yyval.interm.intermNode) = 0; // start a fresh subsequence for what's after this case
}
}
#line 11366 "MachineIndependent/glslang_tab.cpp"
break;
case 587: /* statement_list: statement_list statement */
#line 3828 "MachineIndependent/glslang.y"
{
if ((yyvsp[0].interm.intermNode) && (yyvsp[0].interm.intermNode)->getAsBranchNode() && ((yyvsp[0].interm.intermNode)->getAsBranchNode()->getFlowOp() == EOpCase ||
(yyvsp[0].interm.intermNode)->getAsBranchNode()->getFlowOp() == EOpDefault)) {
parseContext.wrapupSwitchSubsequence((yyvsp[-1].interm.intermNode) ? (yyvsp[-1].interm.intermNode)->getAsAggregate() : 0, (yyvsp[0].interm.intermNode));
(yyval.interm.intermNode) = 0; // start a fresh subsequence for what's after this case
} else
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-1].interm.intermNode), (yyvsp[0].interm.intermNode));
}
#line 11379 "MachineIndependent/glslang_tab.cpp"
break;
case 588: /* expression_statement: SEMICOLON */
#line 3839 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = 0; }
#line 11385 "MachineIndependent/glslang_tab.cpp"
break;
case 589: /* expression_statement: expression SEMICOLON */
#line 3840 "MachineIndependent/glslang.y"
{ (yyval.interm.intermNode) = static_cast<TIntermNode*>((yyvsp[-1].interm.intermTypedNode)); }
#line 11391 "MachineIndependent/glslang_tab.cpp"
break;
case 590: /* selection_statement: selection_statement_nonattributed */
#line 3844 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11399 "MachineIndependent/glslang_tab.cpp"
break;
case 591: /* selection_statement: attribute selection_statement_nonattributed */
#line 3847 "MachineIndependent/glslang.y"
{
parseContext.requireExtensions((yyvsp[0].interm.intermNode)->getLoc(), 1, &E_GL_EXT_control_flow_attributes, "attribute");
parseContext.handleSelectionAttributes(*(yyvsp[-1].interm.attributes), (yyvsp[0].interm.intermNode));
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11409 "MachineIndependent/glslang_tab.cpp"
break;
case 592: /* selection_statement_nonattributed: IF LEFT_PAREN expression RIGHT_PAREN selection_rest_statement */
#line 3854 "MachineIndependent/glslang.y"
{
parseContext.boolCheck((yyvsp[-4].lex).loc, (yyvsp[-2].interm.intermTypedNode));
(yyval.interm.intermNode) = parseContext.intermediate.addSelection((yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.nodePair), (yyvsp[-4].lex).loc);
}
#line 11418 "MachineIndependent/glslang_tab.cpp"
break;
case 593: /* selection_rest_statement: statement_scoped ELSE statement_scoped */
#line 3861 "MachineIndependent/glslang.y"
{
(yyval.interm.nodePair).node1 = (yyvsp[-2].interm.intermNode);
(yyval.interm.nodePair).node2 = (yyvsp[0].interm.intermNode);
}
#line 11427 "MachineIndependent/glslang_tab.cpp"
break;
case 594: /* selection_rest_statement: statement_scoped */
#line 3865 "MachineIndependent/glslang.y"
{
(yyval.interm.nodePair).node1 = (yyvsp[0].interm.intermNode);
(yyval.interm.nodePair).node2 = 0;
}
#line 11436 "MachineIndependent/glslang_tab.cpp"
break;
case 595: /* condition: expression */
#line 3873 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
parseContext.boolCheck((yyvsp[0].interm.intermTypedNode)->getLoc(), (yyvsp[0].interm.intermTypedNode));
}
#line 11445 "MachineIndependent/glslang_tab.cpp"
break;
case 596: /* condition: fully_specified_type IDENTIFIER EQUAL initializer */
#line 3877 "MachineIndependent/glslang.y"
{
parseContext.boolCheck((yyvsp[-2].lex).loc, (yyvsp[-3].interm.type));
TType type((yyvsp[-3].interm.type));
TIntermNode* initNode = parseContext.declareVariable((yyvsp[-2].lex).loc, *(yyvsp[-2].lex).string, (yyvsp[-3].interm.type), 0, (yyvsp[0].interm.intermTypedNode));
if (initNode)
(yyval.interm.intermTypedNode) = initNode->getAsTyped();
else
(yyval.interm.intermTypedNode) = 0;
}
#line 11460 "MachineIndependent/glslang_tab.cpp"
break;
case 597: /* switch_statement: switch_statement_nonattributed */
#line 3890 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11468 "MachineIndependent/glslang_tab.cpp"
break;
case 598: /* switch_statement: attribute switch_statement_nonattributed */
#line 3893 "MachineIndependent/glslang.y"
{
parseContext.requireExtensions((yyvsp[0].interm.intermNode)->getLoc(), 1, &E_GL_EXT_control_flow_attributes, "attribute");
parseContext.handleSwitchAttributes(*(yyvsp[-1].interm.attributes), (yyvsp[0].interm.intermNode));
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11478 "MachineIndependent/glslang_tab.cpp"
break;
case 599: /* $@9: %empty */
#line 3900 "MachineIndependent/glslang.y"
{
// start new switch sequence on the switch stack
++parseContext.controlFlowNestingLevel;
++parseContext.statementNestingLevel;
parseContext.switchSequenceStack.push_back(new TIntermSequence);
parseContext.switchLevel.push_back(parseContext.statementNestingLevel);
parseContext.symbolTable.push();
}
#line 11491 "MachineIndependent/glslang_tab.cpp"
break;
case 600: /* switch_statement_nonattributed: SWITCH LEFT_PAREN expression RIGHT_PAREN $@9 LEFT_BRACE switch_statement_list RIGHT_BRACE */
#line 3908 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.addSwitch((yyvsp[-7].lex).loc, (yyvsp[-5].interm.intermTypedNode), (yyvsp[-1].interm.intermNode) ? (yyvsp[-1].interm.intermNode)->getAsAggregate() : 0);
delete parseContext.switchSequenceStack.back();
parseContext.switchSequenceStack.pop_back();
parseContext.switchLevel.pop_back();
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
--parseContext.statementNestingLevel;
--parseContext.controlFlowNestingLevel;
}
#line 11505 "MachineIndependent/glslang_tab.cpp"
break;
case 601: /* switch_statement_list: %empty */
#line 3920 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = 0;
}
#line 11513 "MachineIndependent/glslang_tab.cpp"
break;
case 602: /* switch_statement_list: statement_list */
#line 3923 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11521 "MachineIndependent/glslang_tab.cpp"
break;
case 603: /* case_label: CASE expression COLON */
#line 3929 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = 0;
if (parseContext.switchLevel.size() == 0)
parseContext.error((yyvsp[-2].lex).loc, "cannot appear outside switch statement", "case", "");
else if (parseContext.switchLevel.back() != parseContext.statementNestingLevel)
parseContext.error((yyvsp[-2].lex).loc, "cannot be nested inside control flow", "case", "");
else {
parseContext.constantValueCheck((yyvsp[-1].interm.intermTypedNode), "case");
parseContext.integerCheck((yyvsp[-1].interm.intermTypedNode), "case");
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpCase, (yyvsp[-1].interm.intermTypedNode), (yyvsp[-2].lex).loc);
}
}
#line 11538 "MachineIndependent/glslang_tab.cpp"
break;
case 604: /* case_label: DEFAULT COLON */
#line 3941 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = 0;
if (parseContext.switchLevel.size() == 0)
parseContext.error((yyvsp[-1].lex).loc, "cannot appear outside switch statement", "default", "");
else if (parseContext.switchLevel.back() != parseContext.statementNestingLevel)
parseContext.error((yyvsp[-1].lex).loc, "cannot be nested inside control flow", "default", "");
else
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpDefault, (yyvsp[-1].lex).loc);
}
#line 11552 "MachineIndependent/glslang_tab.cpp"
break;
case 605: /* iteration_statement: iteration_statement_nonattributed */
#line 3953 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11560 "MachineIndependent/glslang_tab.cpp"
break;
case 606: /* iteration_statement: attribute iteration_statement_nonattributed */
#line 3956 "MachineIndependent/glslang.y"
{
const char * extensions[2] = { E_GL_EXT_control_flow_attributes, E_GL_EXT_control_flow_attributes2 };
parseContext.requireExtensions((yyvsp[0].interm.intermNode)->getLoc(), 2, extensions, "attribute");
parseContext.handleLoopAttributes(*(yyvsp[-1].interm.attributes), (yyvsp[0].interm.intermNode));
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11571 "MachineIndependent/glslang_tab.cpp"
break;
case 607: /* $@10: %empty */
#line 3964 "MachineIndependent/glslang.y"
{
if (! parseContext.limits.whileLoops)
parseContext.error((yyvsp[-1].lex).loc, "while loops not available", "limitation", "");
parseContext.symbolTable.push();
++parseContext.loopNestingLevel;
++parseContext.statementNestingLevel;
++parseContext.controlFlowNestingLevel;
}
#line 11584 "MachineIndependent/glslang_tab.cpp"
break;
case 608: /* iteration_statement_nonattributed: WHILE LEFT_PAREN $@10 condition RIGHT_PAREN statement_no_new_scope */
#line 3972 "MachineIndependent/glslang.y"
{
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
(yyval.interm.intermNode) = parseContext.intermediate.addLoop((yyvsp[0].interm.intermNode), (yyvsp[-2].interm.intermTypedNode), 0, true, (yyvsp[-5].lex).loc);
--parseContext.loopNestingLevel;
--parseContext.statementNestingLevel;
--parseContext.controlFlowNestingLevel;
}
#line 11596 "MachineIndependent/glslang_tab.cpp"
break;
case 609: /* $@11: %empty */
#line 3979 "MachineIndependent/glslang.y"
{
parseContext.symbolTable.push();
++parseContext.loopNestingLevel;
++parseContext.statementNestingLevel;
++parseContext.controlFlowNestingLevel;
}
#line 11607 "MachineIndependent/glslang_tab.cpp"
break;
case 610: /* iteration_statement_nonattributed: DO $@11 statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON */
#line 3985 "MachineIndependent/glslang.y"
{
if (! parseContext.limits.whileLoops)
parseContext.error((yyvsp[-7].lex).loc, "do-while loops not available", "limitation", "");
parseContext.boolCheck((yyvsp[0].lex).loc, (yyvsp[-2].interm.intermTypedNode));
(yyval.interm.intermNode) = parseContext.intermediate.addLoop((yyvsp[-5].interm.intermNode), (yyvsp[-2].interm.intermTypedNode), 0, false, (yyvsp[-4].lex).loc);
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
--parseContext.loopNestingLevel;
--parseContext.statementNestingLevel;
--parseContext.controlFlowNestingLevel;
}
#line 11624 "MachineIndependent/glslang_tab.cpp"
break;
case 611: /* $@12: %empty */
#line 3997 "MachineIndependent/glslang.y"
{
parseContext.symbolTable.push();
++parseContext.loopNestingLevel;
++parseContext.statementNestingLevel;
++parseContext.controlFlowNestingLevel;
}
#line 11635 "MachineIndependent/glslang_tab.cpp"
break;
case 612: /* iteration_statement_nonattributed: FOR LEFT_PAREN $@12 for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope */
#line 4003 "MachineIndependent/glslang.y"
{
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
(yyval.interm.intermNode) = parseContext.intermediate.makeAggregate((yyvsp[-3].interm.intermNode), (yyvsp[-5].lex).loc);
TIntermLoop* forLoop = parseContext.intermediate.addLoop((yyvsp[0].interm.intermNode), reinterpret_cast<TIntermTyped*>((yyvsp[-2].interm.nodePair).node1), reinterpret_cast<TIntermTyped*>((yyvsp[-2].interm.nodePair).node2), true, (yyvsp[-6].lex).loc);
if (! parseContext.limits.nonInductiveForLoops)
parseContext.inductiveLoopCheck((yyvsp[-6].lex).loc, (yyvsp[-3].interm.intermNode), forLoop);
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyval.interm.intermNode), forLoop, (yyvsp[-6].lex).loc);
(yyval.interm.intermNode)->getAsAggregate()->setOperator(EOpSequence);
--parseContext.loopNestingLevel;
--parseContext.statementNestingLevel;
--parseContext.controlFlowNestingLevel;
}
#line 11652 "MachineIndependent/glslang_tab.cpp"
break;
case 613: /* for_init_statement: expression_statement */
#line 4018 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11660 "MachineIndependent/glslang_tab.cpp"
break;
case 614: /* for_init_statement: declaration_statement */
#line 4021 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11668 "MachineIndependent/glslang_tab.cpp"
break;
case 615: /* conditionopt: condition */
#line 4027 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
}
#line 11676 "MachineIndependent/glslang_tab.cpp"
break;
case 616: /* conditionopt: %empty */
#line 4030 "MachineIndependent/glslang.y"
{
(yyval.interm.intermTypedNode) = 0;
}
#line 11684 "MachineIndependent/glslang_tab.cpp"
break;
case 617: /* for_rest_statement: conditionopt SEMICOLON */
#line 4036 "MachineIndependent/glslang.y"
{
(yyval.interm.nodePair).node1 = (yyvsp[-1].interm.intermTypedNode);
(yyval.interm.nodePair).node2 = 0;
}
#line 11693 "MachineIndependent/glslang_tab.cpp"
break;
case 618: /* for_rest_statement: conditionopt SEMICOLON expression */
#line 4040 "MachineIndependent/glslang.y"
{
(yyval.interm.nodePair).node1 = (yyvsp[-2].interm.intermTypedNode);
(yyval.interm.nodePair).node2 = (yyvsp[0].interm.intermTypedNode);
}
#line 11702 "MachineIndependent/glslang_tab.cpp"
break;
case 619: /* jump_statement: CONTINUE SEMICOLON */
#line 4047 "MachineIndependent/glslang.y"
{
if (parseContext.loopNestingLevel <= 0)
parseContext.error((yyvsp[-1].lex).loc, "continue statement only allowed in loops", "", "");
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpContinue, (yyvsp[-1].lex).loc);
}
#line 11712 "MachineIndependent/glslang_tab.cpp"
break;
case 620: /* jump_statement: BREAK SEMICOLON */
#line 4052 "MachineIndependent/glslang.y"
{
if (parseContext.loopNestingLevel + parseContext.switchSequenceStack.size() <= 0)
parseContext.error((yyvsp[-1].lex).loc, "break statement only allowed in switch and loops", "", "");
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpBreak, (yyvsp[-1].lex).loc);
}
#line 11722 "MachineIndependent/glslang_tab.cpp"
break;
case 621: /* jump_statement: RETURN SEMICOLON */
#line 4057 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpReturn, (yyvsp[-1].lex).loc);
if (parseContext.currentFunctionType->getBasicType() != EbtVoid)
parseContext.error((yyvsp[-1].lex).loc, "non-void function must return a value", "return", "");
if (parseContext.inMain)
parseContext.postEntryPointReturn = true;
}
#line 11734 "MachineIndependent/glslang_tab.cpp"
break;
case 622: /* jump_statement: RETURN expression SEMICOLON */
#line 4064 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.handleReturnValue((yyvsp[-2].lex).loc, (yyvsp[-1].interm.intermTypedNode));
}
#line 11742 "MachineIndependent/glslang_tab.cpp"
break;
case 623: /* jump_statement: DISCARD SEMICOLON */
#line 4067 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[-1].lex).loc, EShLangFragment, "discard");
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpKill, (yyvsp[-1].lex).loc);
}
#line 11751 "MachineIndependent/glslang_tab.cpp"
break;
case 624: /* jump_statement: TERMINATE_INVOCATION SEMICOLON */
#line 4071 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[-1].lex).loc, EShLangFragment, "terminateInvocation");
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpTerminateInvocation, (yyvsp[-1].lex).loc);
}
#line 11760 "MachineIndependent/glslang_tab.cpp"
break;
case 625: /* jump_statement: TERMINATE_RAY SEMICOLON */
#line 4075 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[-1].lex).loc, EShLangAnyHit, "terminateRayEXT");
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpTerminateRayKHR, (yyvsp[-1].lex).loc);
}
#line 11769 "MachineIndependent/glslang_tab.cpp"
break;
case 626: /* jump_statement: IGNORE_INTERSECTION SEMICOLON */
#line 4079 "MachineIndependent/glslang.y"
{
parseContext.requireStage((yyvsp[-1].lex).loc, EShLangAnyHit, "ignoreIntersectionEXT");
(yyval.interm.intermNode) = parseContext.intermediate.addBranch(EOpIgnoreIntersectionKHR, (yyvsp[-1].lex).loc);
}
#line 11778 "MachineIndependent/glslang_tab.cpp"
break;
case 627: /* translation_unit: external_declaration */
#line 4088 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
parseContext.intermediate.setTreeRoot((yyval.interm.intermNode));
}
#line 11787 "MachineIndependent/glslang_tab.cpp"
break;
case 628: /* translation_unit: translation_unit external_declaration */
#line 4092 "MachineIndependent/glslang.y"
{
if ((yyvsp[0].interm.intermNode) != nullptr) {
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-1].interm.intermNode), (yyvsp[0].interm.intermNode));
parseContext.intermediate.setTreeRoot((yyval.interm.intermNode));
}
}
#line 11798 "MachineIndependent/glslang_tab.cpp"
break;
case 629: /* external_declaration: function_definition */
#line 4101 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11806 "MachineIndependent/glslang_tab.cpp"
break;
case 630: /* external_declaration: declaration */
#line 4104 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = (yyvsp[0].interm.intermNode);
}
#line 11814 "MachineIndependent/glslang_tab.cpp"
break;
case 631: /* external_declaration: SEMICOLON */
#line 4107 "MachineIndependent/glslang.y"
{
parseContext.requireProfile((yyvsp[0].lex).loc, ~EEsProfile, "extraneous semicolon");
parseContext.profileRequires((yyvsp[0].lex).loc, ~EEsProfile, 460, nullptr, "extraneous semicolon");
(yyval.interm.intermNode) = nullptr;
}
#line 11824 "MachineIndependent/glslang_tab.cpp"
break;
case 632: /* $@13: %empty */
#line 4115 "MachineIndependent/glslang.y"
{
(yyvsp[0].interm).function = parseContext.handleFunctionDeclarator((yyvsp[0].interm).loc, *(yyvsp[0].interm).function, false /* not prototype */);
(yyvsp[0].interm).intermNode = parseContext.handleFunctionDefinition((yyvsp[0].interm).loc, *(yyvsp[0].interm).function);
// For ES 100 only, according to ES shading language 100 spec: A function
// body has a scope nested inside the function's definition.
if (parseContext.profile == EEsProfile && parseContext.version == 100)
{
parseContext.symbolTable.push();
++parseContext.statementNestingLevel;
}
}
#line 11841 "MachineIndependent/glslang_tab.cpp"
break;
case 633: /* function_definition: function_prototype $@13 compound_statement_no_new_scope */
#line 4127 "MachineIndependent/glslang.y"
{
// May be best done as post process phase on intermediate code
if (parseContext.currentFunctionType->getBasicType() != EbtVoid && ! parseContext.functionReturnsValue)
parseContext.error((yyvsp[-2].interm).loc, "function does not return a value:", "", (yyvsp[-2].interm).function->getName().c_str());
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-2].interm).intermNode, (yyvsp[0].interm.intermNode));
(yyval.interm.intermNode)->getAsAggregate()->setLinkType((yyvsp[-2].interm).function->getLinkType());
parseContext.intermediate.setAggregateOperator((yyval.interm.intermNode), EOpFunction, (yyvsp[-2].interm).function->getType(), (yyvsp[-2].interm).loc);
(yyval.interm.intermNode)->getAsAggregate()->setName((yyvsp[-2].interm).function->getMangledName().c_str());
// store the pragma information for debug and optimize and other vendor specific
// information. This information can be queried from the parse tree
(yyval.interm.intermNode)->getAsAggregate()->setOptimize(parseContext.contextPragma.optimize);
(yyval.interm.intermNode)->getAsAggregate()->setDebug(parseContext.contextPragma.debug);
(yyval.interm.intermNode)->getAsAggregate()->setPragmaTable(parseContext.contextPragma.pragmaTable);
// Set currentFunctionType to empty pointer when goes outside of the function
parseContext.currentFunctionType = nullptr;
// For ES 100 only, according to ES shading language 100 spec: A function
// body has a scope nested inside the function's definition.
if (parseContext.profile == EEsProfile && parseContext.version == 100)
{
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
--parseContext.statementNestingLevel;
}
}
#line 11873 "MachineIndependent/glslang_tab.cpp"
break;
case 634: /* attribute: LEFT_BRACKET LEFT_BRACKET attribute_list RIGHT_BRACKET RIGHT_BRACKET */
#line 4157 "MachineIndependent/glslang.y"
{
(yyval.interm.attributes) = (yyvsp[-2].interm.attributes);
}
#line 11881 "MachineIndependent/glslang_tab.cpp"
break;
case 635: /* attribute_list: single_attribute */
#line 4162 "MachineIndependent/glslang.y"
{
(yyval.interm.attributes) = (yyvsp[0].interm.attributes);
}
#line 11889 "MachineIndependent/glslang_tab.cpp"
break;
case 636: /* attribute_list: attribute_list COMMA single_attribute */
#line 4165 "MachineIndependent/glslang.y"
{
(yyval.interm.attributes) = parseContext.mergeAttributes((yyvsp[-2].interm.attributes), (yyvsp[0].interm.attributes));
}
#line 11897 "MachineIndependent/glslang_tab.cpp"
break;
case 637: /* single_attribute: IDENTIFIER */
#line 4170 "MachineIndependent/glslang.y"
{
(yyval.interm.attributes) = parseContext.makeAttributes(*(yyvsp[0].lex).string);
}
#line 11905 "MachineIndependent/glslang_tab.cpp"
break;
case 638: /* single_attribute: IDENTIFIER LEFT_PAREN constant_expression RIGHT_PAREN */
#line 4173 "MachineIndependent/glslang.y"
{
(yyval.interm.attributes) = parseContext.makeAttributes(*(yyvsp[-3].lex).string, (yyvsp[-1].interm.intermTypedNode));
}
#line 11913 "MachineIndependent/glslang_tab.cpp"
break;
case 639: /* spirv_requirements_list: spirv_requirements_parameter */
#line 4178 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvReq) = (yyvsp[0].interm.spirvReq);
}
#line 11921 "MachineIndependent/glslang_tab.cpp"
break;
case 640: /* spirv_requirements_list: spirv_requirements_list COMMA spirv_requirements_parameter */
#line 4181 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvReq) = parseContext.mergeSpirvRequirements((yyvsp[-1].lex).loc, (yyvsp[-2].interm.spirvReq), (yyvsp[0].interm.spirvReq));
}
#line 11929 "MachineIndependent/glslang_tab.cpp"
break;
case 641: /* spirv_requirements_parameter: IDENTIFIER EQUAL LEFT_BRACKET spirv_extension_list RIGHT_BRACKET */
#line 4186 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvReq) = parseContext.makeSpirvRequirement((yyvsp[-3].lex).loc, *(yyvsp[-4].lex).string, (yyvsp[-1].interm.intermNode)->getAsAggregate(), nullptr);
}
#line 11937 "MachineIndependent/glslang_tab.cpp"
break;
case 642: /* spirv_requirements_parameter: IDENTIFIER EQUAL LEFT_BRACKET spirv_capability_list RIGHT_BRACKET */
#line 4189 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvReq) = parseContext.makeSpirvRequirement((yyvsp[-3].lex).loc, *(yyvsp[-4].lex).string, nullptr, (yyvsp[-1].interm.intermNode)->getAsAggregate());
}
#line 11945 "MachineIndependent/glslang_tab.cpp"
break;
case 643: /* spirv_extension_list: STRING_LITERAL */
#line 4194 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.makeAggregate(parseContext.intermediate.addConstantUnion((yyvsp[0].lex).string, (yyvsp[0].lex).loc, true));
}
#line 11953 "MachineIndependent/glslang_tab.cpp"
break;
case 644: /* spirv_extension_list: spirv_extension_list COMMA STRING_LITERAL */
#line 4197 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-2].interm.intermNode), parseContext.intermediate.addConstantUnion((yyvsp[0].lex).string, (yyvsp[0].lex).loc, true));
}
#line 11961 "MachineIndependent/glslang_tab.cpp"
break;
case 645: /* spirv_capability_list: INTCONSTANT */
#line 4202 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.makeAggregate(parseContext.intermediate.addConstantUnion((yyvsp[0].lex).i, (yyvsp[0].lex).loc, true));
}
#line 11969 "MachineIndependent/glslang_tab.cpp"
break;
case 646: /* spirv_capability_list: spirv_capability_list COMMA INTCONSTANT */
#line 4205 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-2].interm.intermNode), parseContext.intermediate.addConstantUnion((yyvsp[0].lex).i, (yyvsp[0].lex).loc, true));
}
#line 11977 "MachineIndependent/glslang_tab.cpp"
break;
case 647: /* spirv_execution_mode_qualifier: SPIRV_EXECUTION_MODE LEFT_PAREN INTCONSTANT RIGHT_PAREN */
#line 4210 "MachineIndependent/glslang.y"
{
parseContext.intermediate.insertSpirvExecutionMode((yyvsp[-1].lex).i);
(yyval.interm.intermNode) = 0;
}
#line 11986 "MachineIndependent/glslang_tab.cpp"
break;
case 648: /* spirv_execution_mode_qualifier: SPIRV_EXECUTION_MODE LEFT_PAREN spirv_requirements_list COMMA INTCONSTANT RIGHT_PAREN */
#line 4214 "MachineIndependent/glslang.y"
{
parseContext.intermediate.insertSpirvRequirement((yyvsp[-3].interm.spirvReq));
parseContext.intermediate.insertSpirvExecutionMode((yyvsp[-1].lex).i);
(yyval.interm.intermNode) = 0;
}
#line 11996 "MachineIndependent/glslang_tab.cpp"
break;
case 649: /* spirv_execution_mode_qualifier: SPIRV_EXECUTION_MODE LEFT_PAREN INTCONSTANT COMMA spirv_execution_mode_parameter_list RIGHT_PAREN */
#line 4219 "MachineIndependent/glslang.y"
{
parseContext.intermediate.insertSpirvExecutionMode((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
(yyval.interm.intermNode) = 0;
}
#line 12005 "MachineIndependent/glslang_tab.cpp"
break;
case 650: /* spirv_execution_mode_qualifier: SPIRV_EXECUTION_MODE LEFT_PAREN spirv_requirements_list COMMA INTCONSTANT COMMA spirv_execution_mode_parameter_list RIGHT_PAREN */
#line 4223 "MachineIndependent/glslang.y"
{
parseContext.intermediate.insertSpirvRequirement((yyvsp[-5].interm.spirvReq));
parseContext.intermediate.insertSpirvExecutionMode((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
(yyval.interm.intermNode) = 0;
}
#line 12015 "MachineIndependent/glslang_tab.cpp"
break;
case 651: /* spirv_execution_mode_qualifier: SPIRV_EXECUTION_MODE_ID LEFT_PAREN INTCONSTANT COMMA spirv_execution_mode_id_parameter_list RIGHT_PAREN */
#line 4228 "MachineIndependent/glslang.y"
{
parseContext.intermediate.insertSpirvExecutionModeId((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
(yyval.interm.intermNode) = 0;
}
#line 12024 "MachineIndependent/glslang_tab.cpp"
break;
case 652: /* spirv_execution_mode_qualifier: SPIRV_EXECUTION_MODE_ID LEFT_PAREN spirv_requirements_list COMMA INTCONSTANT COMMA spirv_execution_mode_id_parameter_list RIGHT_PAREN */
#line 4232 "MachineIndependent/glslang.y"
{
parseContext.intermediate.insertSpirvRequirement((yyvsp[-5].interm.spirvReq));
parseContext.intermediate.insertSpirvExecutionModeId((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
(yyval.interm.intermNode) = 0;
}
#line 12034 "MachineIndependent/glslang_tab.cpp"
break;
case 653: /* spirv_execution_mode_parameter_list: spirv_execution_mode_parameter */
#line 4239 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.makeAggregate((yyvsp[0].interm.intermNode));
}
#line 12042 "MachineIndependent/glslang_tab.cpp"
break;
case 654: /* spirv_execution_mode_parameter_list: spirv_execution_mode_parameter_list COMMA spirv_execution_mode_parameter */
#line 4242 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-2].interm.intermNode), (yyvsp[0].interm.intermNode));
}
#line 12050 "MachineIndependent/glslang_tab.cpp"
break;
case 655: /* spirv_execution_mode_parameter: FLOATCONSTANT */
#line 4247 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).d, EbtFloat, (yyvsp[0].lex).loc, true);
}
#line 12058 "MachineIndependent/glslang_tab.cpp"
break;
case 656: /* spirv_execution_mode_parameter: INTCONSTANT */
#line 4250 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).i, (yyvsp[0].lex).loc, true);
}
#line 12066 "MachineIndependent/glslang_tab.cpp"
break;
case 657: /* spirv_execution_mode_parameter: UINTCONSTANT */
#line 4253 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).u, (yyvsp[0].lex).loc, true);
}
#line 12074 "MachineIndependent/glslang_tab.cpp"
break;
case 658: /* spirv_execution_mode_parameter: BOOLCONSTANT */
#line 4256 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).b, (yyvsp[0].lex).loc, true);
}
#line 12082 "MachineIndependent/glslang_tab.cpp"
break;
case 659: /* spirv_execution_mode_parameter: STRING_LITERAL */
#line 4259 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).string, (yyvsp[0].lex).loc, true);
}
#line 12090 "MachineIndependent/glslang_tab.cpp"
break;
case 660: /* spirv_execution_mode_id_parameter_list: constant_expression */
#line 4264 "MachineIndependent/glslang.y"
{
if ((yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtFloat &&
(yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtInt &&
(yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtUint &&
(yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtBool &&
(yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtString)
parseContext.error((yyvsp[0].interm.intermTypedNode)->getLoc(), "this type not allowed", (yyvsp[0].interm.intermTypedNode)->getType().getBasicString(), "");
(yyval.interm.intermNode) = parseContext.intermediate.makeAggregate((yyvsp[0].interm.intermTypedNode));
}
#line 12104 "MachineIndependent/glslang_tab.cpp"
break;
case 661: /* spirv_execution_mode_id_parameter_list: spirv_execution_mode_id_parameter_list COMMA constant_expression */
#line 4273 "MachineIndependent/glslang.y"
{
if ((yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtFloat &&
(yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtInt &&
(yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtUint &&
(yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtBool &&
(yyvsp[0].interm.intermTypedNode)->getBasicType() != EbtString)
parseContext.error((yyvsp[0].interm.intermTypedNode)->getLoc(), "this type not allowed", (yyvsp[0].interm.intermTypedNode)->getType().getBasicString(), "");
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-2].interm.intermNode), (yyvsp[0].interm.intermTypedNode));
}
#line 12118 "MachineIndependent/glslang_tab.cpp"
break;
case 662: /* spirv_storage_class_qualifier: SPIRV_STORAGE_CLASS LEFT_PAREN INTCONSTANT RIGHT_PAREN */
#line 4284 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-3].lex).loc);
(yyval.interm.type).qualifier.storage = EvqSpirvStorageClass;
(yyval.interm.type).qualifier.spirvStorageClass = (yyvsp[-1].lex).i;
}
#line 12128 "MachineIndependent/glslang_tab.cpp"
break;
case 663: /* spirv_storage_class_qualifier: SPIRV_STORAGE_CLASS LEFT_PAREN spirv_requirements_list COMMA INTCONSTANT RIGHT_PAREN */
#line 4289 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-5].lex).loc);
parseContext.intermediate.insertSpirvRequirement((yyvsp[-3].interm.spirvReq));
(yyval.interm.type).qualifier.storage = EvqSpirvStorageClass;
(yyval.interm.type).qualifier.spirvStorageClass = (yyvsp[-1].lex).i;
}
#line 12139 "MachineIndependent/glslang_tab.cpp"
break;
case 664: /* spirv_decorate_qualifier: SPIRV_DECORATE LEFT_PAREN INTCONSTANT RIGHT_PAREN */
#line 4297 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-3].lex).loc);
(yyval.interm.type).qualifier.setSpirvDecorate((yyvsp[-1].lex).i);
}
#line 12148 "MachineIndependent/glslang_tab.cpp"
break;
case 665: /* spirv_decorate_qualifier: SPIRV_DECORATE LEFT_PAREN spirv_requirements_list COMMA INTCONSTANT RIGHT_PAREN */
#line 4301 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-5].lex).loc);
parseContext.intermediate.insertSpirvRequirement((yyvsp[-3].interm.spirvReq));
(yyval.interm.type).qualifier.setSpirvDecorate((yyvsp[-1].lex).i);
}
#line 12158 "MachineIndependent/glslang_tab.cpp"
break;
case 666: /* spirv_decorate_qualifier: SPIRV_DECORATE LEFT_PAREN INTCONSTANT COMMA spirv_decorate_parameter_list RIGHT_PAREN */
#line 4306 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-5].lex).loc);
(yyval.interm.type).qualifier.setSpirvDecorate((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
}
#line 12167 "MachineIndependent/glslang_tab.cpp"
break;
case 667: /* spirv_decorate_qualifier: SPIRV_DECORATE LEFT_PAREN spirv_requirements_list COMMA INTCONSTANT COMMA spirv_decorate_parameter_list RIGHT_PAREN */
#line 4310 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-7].lex).loc);
parseContext.intermediate.insertSpirvRequirement((yyvsp[-5].interm.spirvReq));
(yyval.interm.type).qualifier.setSpirvDecorate((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
}
#line 12177 "MachineIndependent/glslang_tab.cpp"
break;
case 668: /* spirv_decorate_qualifier: SPIRV_DECORATE_ID LEFT_PAREN INTCONSTANT COMMA spirv_decorate_id_parameter_list RIGHT_PAREN */
#line 4315 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-5].lex).loc);
(yyval.interm.type).qualifier.setSpirvDecorateId((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
}
#line 12186 "MachineIndependent/glslang_tab.cpp"
break;
case 669: /* spirv_decorate_qualifier: SPIRV_DECORATE_ID LEFT_PAREN spirv_requirements_list COMMA INTCONSTANT COMMA spirv_decorate_id_parameter_list RIGHT_PAREN */
#line 4319 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-7].lex).loc);
parseContext.intermediate.insertSpirvRequirement((yyvsp[-5].interm.spirvReq));
(yyval.interm.type).qualifier.setSpirvDecorateId((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
}
#line 12196 "MachineIndependent/glslang_tab.cpp"
break;
case 670: /* spirv_decorate_qualifier: SPIRV_DECORATE_STRING LEFT_PAREN INTCONSTANT COMMA spirv_decorate_string_parameter_list RIGHT_PAREN */
#line 4324 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-5].lex).loc);
(yyval.interm.type).qualifier.setSpirvDecorateString((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
}
#line 12205 "MachineIndependent/glslang_tab.cpp"
break;
case 671: /* spirv_decorate_qualifier: SPIRV_DECORATE_STRING LEFT_PAREN spirv_requirements_list COMMA INTCONSTANT COMMA spirv_decorate_string_parameter_list RIGHT_PAREN */
#line 4328 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-7].lex).loc);
parseContext.intermediate.insertSpirvRequirement((yyvsp[-5].interm.spirvReq));
(yyval.interm.type).qualifier.setSpirvDecorateString((yyvsp[-3].lex).i, (yyvsp[-1].interm.intermNode)->getAsAggregate());
}
#line 12215 "MachineIndependent/glslang_tab.cpp"
break;
case 672: /* spirv_decorate_parameter_list: spirv_decorate_parameter */
#line 4335 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.makeAggregate((yyvsp[0].interm.intermNode));
}
#line 12223 "MachineIndependent/glslang_tab.cpp"
break;
case 673: /* spirv_decorate_parameter_list: spirv_decorate_parameter_list COMMA spirv_decorate_parameter */
#line 4338 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-2].interm.intermNode), (yyvsp[0].interm.intermNode));
}
#line 12231 "MachineIndependent/glslang_tab.cpp"
break;
case 674: /* spirv_decorate_parameter: FLOATCONSTANT */
#line 4343 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).d, EbtFloat, (yyvsp[0].lex).loc, true);
}
#line 12239 "MachineIndependent/glslang_tab.cpp"
break;
case 675: /* spirv_decorate_parameter: INTCONSTANT */
#line 4346 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).i, (yyvsp[0].lex).loc, true);
}
#line 12247 "MachineIndependent/glslang_tab.cpp"
break;
case 676: /* spirv_decorate_parameter: UINTCONSTANT */
#line 4349 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).u, (yyvsp[0].lex).loc, true);
}
#line 12255 "MachineIndependent/glslang_tab.cpp"
break;
case 677: /* spirv_decorate_parameter: BOOLCONSTANT */
#line 4352 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).b, (yyvsp[0].lex).loc, true);
}
#line 12263 "MachineIndependent/glslang_tab.cpp"
break;
case 678: /* spirv_decorate_id_parameter_list: spirv_decorate_id_parameter */
#line 4357 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.makeAggregate((yyvsp[0].interm.intermNode));
}
#line 12271 "MachineIndependent/glslang_tab.cpp"
break;
case 679: /* spirv_decorate_id_parameter_list: spirv_decorate_id_parameter_list COMMA spirv_decorate_id_parameter */
#line 4360 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-2].interm.intermNode), (yyvsp[0].interm.intermNode));
}
#line 12279 "MachineIndependent/glslang_tab.cpp"
break;
case 680: /* spirv_decorate_id_parameter: variable_identifier */
#line 4365 "MachineIndependent/glslang.y"
{
if ((yyvsp[0].interm.intermTypedNode)->getAsConstantUnion() || (yyvsp[0].interm.intermTypedNode)->getAsSymbolNode())
(yyval.interm.intermNode) = (yyvsp[0].interm.intermTypedNode);
else
parseContext.error((yyvsp[0].interm.intermTypedNode)->getLoc(), "only allow constants or variables which are not elements of a composite", "", "");
}
#line 12290 "MachineIndependent/glslang_tab.cpp"
break;
case 681: /* spirv_decorate_id_parameter: FLOATCONSTANT */
#line 4371 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).d, EbtFloat, (yyvsp[0].lex).loc, true);
}
#line 12298 "MachineIndependent/glslang_tab.cpp"
break;
case 682: /* spirv_decorate_id_parameter: INTCONSTANT */
#line 4374 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).i, (yyvsp[0].lex).loc, true);
}
#line 12306 "MachineIndependent/glslang_tab.cpp"
break;
case 683: /* spirv_decorate_id_parameter: UINTCONSTANT */
#line 4377 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).u, (yyvsp[0].lex).loc, true);
}
#line 12314 "MachineIndependent/glslang_tab.cpp"
break;
case 684: /* spirv_decorate_id_parameter: BOOLCONSTANT */
#line 4380 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.addConstantUnion((yyvsp[0].lex).b, (yyvsp[0].lex).loc, true);
}
#line 12322 "MachineIndependent/glslang_tab.cpp"
break;
case 685: /* spirv_decorate_string_parameter_list: STRING_LITERAL */
#line 4385 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.makeAggregate(
parseContext.intermediate.addConstantUnion((yyvsp[0].lex).string, (yyvsp[0].lex).loc, true));
}
#line 12331 "MachineIndependent/glslang_tab.cpp"
break;
case 686: /* spirv_decorate_string_parameter_list: spirv_decorate_string_parameter_list COMMA STRING_LITERAL */
#line 4389 "MachineIndependent/glslang.y"
{
(yyval.interm.intermNode) = parseContext.intermediate.growAggregate((yyvsp[-2].interm.intermNode), parseContext.intermediate.addConstantUnion((yyvsp[0].lex).string, (yyvsp[0].lex).loc, true));
}
#line 12339 "MachineIndependent/glslang_tab.cpp"
break;
case 687: /* spirv_type_specifier: SPIRV_TYPE LEFT_PAREN spirv_instruction_qualifier_list COMMA spirv_type_parameter_list RIGHT_PAREN */
#line 4394 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-5].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).setSpirvType(*(yyvsp[-3].interm.spirvInst), (yyvsp[-1].interm.spirvTypeParams));
}
#line 12348 "MachineIndependent/glslang_tab.cpp"
break;
case 688: /* spirv_type_specifier: SPIRV_TYPE LEFT_PAREN spirv_requirements_list COMMA spirv_instruction_qualifier_list COMMA spirv_type_parameter_list RIGHT_PAREN */
#line 4398 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-7].lex).loc, parseContext.symbolTable.atGlobalLevel());
parseContext.intermediate.insertSpirvRequirement((yyvsp[-5].interm.spirvReq));
(yyval.interm.type).setSpirvType(*(yyvsp[-3].interm.spirvInst), (yyvsp[-1].interm.spirvTypeParams));
}
#line 12358 "MachineIndependent/glslang_tab.cpp"
break;
case 689: /* spirv_type_specifier: SPIRV_TYPE LEFT_PAREN spirv_instruction_qualifier_list RIGHT_PAREN */
#line 4403 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-3].lex).loc, parseContext.symbolTable.atGlobalLevel());
(yyval.interm.type).setSpirvType(*(yyvsp[-1].interm.spirvInst));
}
#line 12367 "MachineIndependent/glslang_tab.cpp"
break;
case 690: /* spirv_type_specifier: SPIRV_TYPE LEFT_PAREN spirv_requirements_list COMMA spirv_instruction_qualifier_list RIGHT_PAREN */
#line 4407 "MachineIndependent/glslang.y"
{
(yyval.interm.type).init((yyvsp[-5].lex).loc, parseContext.symbolTable.atGlobalLevel());
parseContext.intermediate.insertSpirvRequirement((yyvsp[-3].interm.spirvReq));
(yyval.interm.type).setSpirvType(*(yyvsp[-1].interm.spirvInst));
}
#line 12377 "MachineIndependent/glslang_tab.cpp"
break;
case 691: /* spirv_type_parameter_list: spirv_type_parameter */
#line 4414 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvTypeParams) = (yyvsp[0].interm.spirvTypeParams);
}
#line 12385 "MachineIndependent/glslang_tab.cpp"
break;
case 692: /* spirv_type_parameter_list: spirv_type_parameter_list COMMA spirv_type_parameter */
#line 4417 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvTypeParams) = parseContext.mergeSpirvTypeParameters((yyvsp[-2].interm.spirvTypeParams), (yyvsp[0].interm.spirvTypeParams));
}
#line 12393 "MachineIndependent/glslang_tab.cpp"
break;
case 693: /* spirv_type_parameter: constant_expression */
#line 4422 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvTypeParams) = parseContext.makeSpirvTypeParameters((yyvsp[0].interm.intermTypedNode)->getLoc(), (yyvsp[0].interm.intermTypedNode)->getAsConstantUnion());
}
#line 12401 "MachineIndependent/glslang_tab.cpp"
break;
case 694: /* spirv_type_parameter: type_specifier_nonarray */
#line 4425 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvTypeParams) = parseContext.makeSpirvTypeParameters((yyvsp[0].interm.type).loc, (yyvsp[0].interm.type));
}
#line 12409 "MachineIndependent/glslang_tab.cpp"
break;
case 695: /* spirv_instruction_qualifier: SPIRV_INSTRUCTION LEFT_PAREN spirv_instruction_qualifier_list RIGHT_PAREN */
#line 4430 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvInst) = (yyvsp[-1].interm.spirvInst);
}
#line 12417 "MachineIndependent/glslang_tab.cpp"
break;
case 696: /* spirv_instruction_qualifier: SPIRV_INSTRUCTION LEFT_PAREN spirv_requirements_list COMMA spirv_instruction_qualifier_list RIGHT_PAREN */
#line 4433 "MachineIndependent/glslang.y"
{
parseContext.intermediate.insertSpirvRequirement((yyvsp[-3].interm.spirvReq));
(yyval.interm.spirvInst) = (yyvsp[-1].interm.spirvInst);
}
#line 12426 "MachineIndependent/glslang_tab.cpp"
break;
case 697: /* spirv_instruction_qualifier_list: spirv_instruction_qualifier_id */
#line 4439 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvInst) = (yyvsp[0].interm.spirvInst);
}
#line 12434 "MachineIndependent/glslang_tab.cpp"
break;
case 698: /* spirv_instruction_qualifier_list: spirv_instruction_qualifier_list COMMA spirv_instruction_qualifier_id */
#line 4442 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvInst) = parseContext.mergeSpirvInstruction((yyvsp[-1].lex).loc, (yyvsp[-2].interm.spirvInst), (yyvsp[0].interm.spirvInst));
}
#line 12442 "MachineIndependent/glslang_tab.cpp"
break;
case 699: /* spirv_instruction_qualifier_id: IDENTIFIER EQUAL STRING_LITERAL */
#line 4447 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvInst) = parseContext.makeSpirvInstruction((yyvsp[-1].lex).loc, *(yyvsp[-2].lex).string, *(yyvsp[0].lex).string);
}
#line 12450 "MachineIndependent/glslang_tab.cpp"
break;
case 700: /* spirv_instruction_qualifier_id: IDENTIFIER EQUAL INTCONSTANT */
#line 4450 "MachineIndependent/glslang.y"
{
(yyval.interm.spirvInst) = parseContext.makeSpirvInstruction((yyvsp[-1].lex).loc, *(yyvsp[-2].lex).string, (yyvsp[0].lex).i);
}
#line 12458 "MachineIndependent/glslang_tab.cpp"
break;
#line 12462 "MachineIndependent/glslang_tab.cpp"
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
that yytoken be updated with the new translation. We take the
approach of translating immediately before every use of yytoken.
One alternative is translating here after every semantic action,
but that translation would be missed if the semantic action invokes
YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
incorrect destructor might then be invoked immediately. In the
case of YYERROR or YYBACKUP, subsequent parser actions might lead
to an incorrect destructor call or verbose syntax error message
before the lookahead is translated. */
YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
YYPOPSTACK (yylen);
yylen = 0;
*++yyvsp = yyval;
/* Now 'shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule
number reduced by. */
{
const int yylhs = yyr1[yyn] - YYNTOKENS;
const int yyi = yypgoto[yylhs] + *yyssp;
yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
? yytable[yyi]
: yydefgoto[yylhs]);
}
goto yynewstate;
/*--------------------------------------.
| yyerrlab -- here on detecting error. |
`--------------------------------------*/
yyerrlab:
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
/* If not already recovering from an error, report this error. */
if (!yyerrstatus)
{
++yynerrs;
{
yypcontext_t yyctx
= {yyssp, yytoken};
char const *yymsgp = YY_("syntax error");
int yysyntax_error_status;
yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
if (yysyntax_error_status == 0)
yymsgp = yymsg;
else if (yysyntax_error_status == -1)
{
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
yymsg = YY_CAST (char *,
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
if (yymsg)
{
yysyntax_error_status
= yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
yymsgp = yymsg;
}
else
{
yymsg = yymsgbuf;
yymsg_alloc = sizeof yymsgbuf;
yysyntax_error_status = YYENOMEM;
}
}
yyerror (pParseContext, yymsgp);
if (yysyntax_error_status == YYENOMEM)
YYNOMEM;
}
}
if (yyerrstatus == 3)
{
/* If just tried and failed to reuse lookahead token after an
error, discard it. */
if (yychar <= YYEOF)
{
/* Return failure if at end of input. */
if (yychar == YYEOF)
YYABORT;
}
else
{
yydestruct ("Error: discarding",
yytoken, &yylval, pParseContext);
yychar = YYEMPTY;
}
}
/* Else will try to reuse lookahead token after shifting the error
token. */
goto yyerrlab1;
/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR. |
`---------------------------------------------------*/
yyerrorlab:
/* Pacify compilers when the user code never invokes YYERROR and the
label yyerrorlab therefore never appears in user code. */
if (0)
YYERROR;
++yynerrs;
/* Do not reclaim the symbols of the rule whose action triggered
this YYERROR. */
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
yystate = *yyssp;
goto yyerrlab1;
/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
yyerrlab1:
yyerrstatus = 3; /* Each real token shifted decrements this. */
/* Pop stack until we find a state that shifts the error token. */
for (;;)
{
yyn = yypact[yystate];
if (!yypact_value_is_default (yyn))
{
yyn += YYSYMBOL_YYerror;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
{
yyn = yytable[yyn];
if (0 < yyn)
break;
}
}
/* Pop the current state because it cannot handle the error token. */
if (yyssp == yyss)
YYABORT;
yydestruct ("Error: popping",
YY_ACCESSING_SYMBOL (yystate), yyvsp, pParseContext);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
}
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
/* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
yystate = yyn;
goto yynewstate;
/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here. |
`-------------------------------------*/
yyacceptlab:
yyresult = 0;
goto yyreturnlab;
/*-----------------------------------.
| yyabortlab -- YYABORT comes here. |
`-----------------------------------*/
yyabortlab:
yyresult = 1;
goto yyreturnlab;
/*-----------------------------------------------------------.
| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
`-----------------------------------------------------------*/
yyexhaustedlab:
yyerror (pParseContext, YY_("memory exhausted"));
yyresult = 2;
goto yyreturnlab;
/*----------------------------------------------------------.
| yyreturnlab -- parsing is finished, clean up and return. |
`----------------------------------------------------------*/
yyreturnlab:
if (yychar != YYEMPTY)
{
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = YYTRANSLATE (yychar);
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, pParseContext);
}
/* Do not reclaim the symbols of the rule whose action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
YY_STACK_PRINT (yyss, yyssp);
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, pParseContext);
YYPOPSTACK (1);
}
#ifndef yyoverflow
if (yyss != yyssa)
YYSTACK_FREE (yyss);
#endif
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
return yyresult;
}
#line 4454 "MachineIndependent/glslang.y"
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/ParseHelper.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
// Copyright (C) 2015-2018 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// This header defines a two-level parse-helper hierarchy, derived from
// TParseVersions:
// - TParseContextBase: sharable across multiple parsers
// - TParseContext: GLSL specific helper
//
#ifndef _PARSER_HELPER_INCLUDED_
#define _PARSER_HELPER_INCLUDED_
#include <cstdarg>
#include <functional>
#include "parseVersions.h"
#include "../Include/ShHandle.h"
#include "SymbolTable.h"
#include "localintermediate.h"
#include "Scan.h"
#include "attribute.h"
namespace glslang {
struct TPragma {
TPragma(bool o, bool d) : optimize(o), debug(d) { }
bool optimize;
bool debug;
TPragmaTable pragmaTable;
};
class TScanContext;
class TPpContext;
typedef std::set<long long> TIdSetType;
typedef std::map<const TTypeList*, std::map<size_t, const TTypeList*>> TStructRecord;
//
// Sharable code (as well as what's in TParseVersions) across
// parse helpers.
//
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,
const TString* entryPoint = nullptr)
: TParseVersions(interm, version, profile, spvVersion, language, infoSink, forwardCompatible, messages),
scopeMangler("::"),
symbolTable(symbolTable),
statementNestingLevel(0), loopNestingLevel(0), structNestingLevel(0), blockNestingLevel(0), controlFlowNestingLevel(0),
currentFunctionType(nullptr),
postEntryPointReturn(false),
contextPragma(true, false),
beginInvocationInterlockCount(0), endInvocationInterlockCount(0),
parsingBuiltins(parsingBuiltins), scanContext(nullptr), ppContext(nullptr),
limits(resources.limits),
globalUniformBlock(nullptr),
globalUniformBinding(TQualifier::layoutBindingEnd),
globalUniformSet(TQualifier::layoutSetEnd),
atomicCounterBlockSet(TQualifier::layoutSetEnd)
{
// use storage buffer on SPIR-V 1.3 and up
if (spvVersion.spv >= EShTargetSpv_1_3)
intermediate.setUseStorageBuffer();
if (entryPoint != nullptr)
sourceEntryPointName = *entryPoint;
}
virtual ~TParseContextBase() { }
virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...);
virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...);
virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...);
virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...);
virtual void setLimits(const TBuiltInResource&) = 0;
void checkIndex(const TSourceLoc&, const TType&, int& index);
EShLanguage getLanguage() const { return language; }
void setScanContext(TScanContext* c) { scanContext = c; }
TScanContext* getScanContext() const { return scanContext; }
void setPpContext(TPpContext* c) { ppContext = c; }
TPpContext* getPpContext() const { return ppContext; }
virtual void setLineCallback(const std::function<void(int, int, bool, int, const char*)>& func) { lineCallback = func; }
virtual void setExtensionCallback(const std::function<void(int, const char*, const char*)>& func) { extensionCallback = func; }
virtual void setVersionCallback(const std::function<void(int, int, const char*)>& func) { versionCallback = func; }
virtual void setPragmaCallback(const std::function<void(int, const TVector<TString>&)>& func) { pragmaCallback = func; }
virtual void setErrorCallback(const std::function<void(int, const char*)>& func) { errorCallback = func; }
virtual void reservedPpErrorCheck(const TSourceLoc&, const char* name, const char* op) = 0;
virtual bool lineContinuationCheck(const TSourceLoc&, bool endOfComment) = 0;
virtual bool lineDirectiveShouldSetNextLine() const = 0;
virtual void handlePragma(const TSourceLoc&, const TVector<TString>&) = 0;
virtual bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) = 0;
virtual void notifyVersion(int line, int version, const char* type_string)
{
if (versionCallback)
versionCallback(line, version, type_string);
}
virtual void notifyErrorDirective(int line, const char* error_message)
{
if (errorCallback)
errorCallback(line, error_message);
}
virtual void notifyLineDirective(int curLineNo, int newLineNo, bool hasSource, int sourceNum, const char* sourceName)
{
if (lineCallback)
lineCallback(curLineNo, newLineNo, hasSource, sourceNum, sourceName);
}
virtual void notifyExtensionDirective(int line, const char* extension, const char* behavior)
{
if (extensionCallback)
extensionCallback(line, extension, behavior);
}
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr);
// Manage global buffer (used for backing atomic counters in GLSL when using relaxed Vulkan semantics)
virtual void growAtomicCounterBlock(int binding, 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 && intermediate.getEntryPointName().size() > 0)
name = NewPoolTString(intermediate.getEntryPointName().c_str());
}
virtual bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*);
virtual void rValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*);
const char* const scopeMangler;
// Basic parsing state, easily accessible to the grammar
TSymbolTable& symbolTable; // symbol table that goes with the current language, version, and profile
TVector<TString> relaxedSymbols;
int statementNestingLevel; // 0 if outside all flow control or compound statements
int loopNestingLevel; // 0 if outside all loops
int structNestingLevel; // 0 if outside structures
int blockNestingLevel; // 0 if outside blocks
int controlFlowNestingLevel; // 0 if outside all flow control
const TType* currentFunctionType; // the return type of the function that's currently being parsed
bool functionReturnsValue; // true if a non-void function has a return
// if inside a function, true if the function is the entry point and this is after a return statement
bool postEntryPointReturn;
// case, node, case, case, node, ...; ensure only one node between cases; stack of them for nesting
TList<TIntermSequence*> switchSequenceStack;
// the statementNestingLevel the current switch statement is at, which must match the level of its case statements
TList<int> switchLevel;
struct TPragma contextPragma;
int beginInvocationInterlockCount;
int endInvocationInterlockCount;
bool compileOnly = false;
protected:
TParseContextBase(TParseContextBase&);
TParseContextBase& operator=(TParseContextBase&);
const bool parsingBuiltins; // true if parsing built-in symbols/functions
TVector<TSymbol*> linkageSymbols; // will be transferred to 'linkage', after all editing is done, order preserving
TScanContext* scanContext;
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.
std::function<void(int, int, bool, int, const char*)> lineCallback;
std::function<void(int, const TVector<TString>&)> pragmaCallback;
std::function<void(int, int, const char*)> versionCallback;
std::function<void(int, const char*, const char*)> extensionCallback;
std::function<void(int, const char*)> errorCallback;
// see implementation for detail
const TFunction* selectFunction(const TVector<const TFunction*>, const TFunction&,
std::function<bool(const TType&, const TType&, TOperator, int arg)>,
std::function<bool(const TType&, const TType&, const TType&)>,
/* output */ bool& tie);
virtual void parseSwizzleSelector(const TSourceLoc&, const TString&, int size,
TSwizzleSelectors<TVectorSelector>&);
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
TVariable* globalUniformBlock; // the actual block, inserted into the symbol table
unsigned int globalUniformBinding; // the block's binding number
unsigned int globalUniformSet; // the block's set number
int firstNewMember; // the index of the first member not yet inserted into the symbol table
// override this to set the language-specific name
virtual const char* getGlobalUniformBlockName() const { return ""; }
virtual void setUniformBlockDefaults(TType&) const { }
virtual void finalizeGlobalUniformBlockLayout(TVariable&) {}
// Manage the atomic counter block (used for atomic_uints with Vulkan-Relaxed)
TMap<int, TVariable*> atomicCounterBuffers;
unsigned int atomicCounterBlockSet;
TMap<int, int> atomicCounterBlockFirstNewMember;
// override this to set the language-specific name
virtual const char* getAtomicCounterBlockName() const { return ""; }
virtual void setAtomicCounterBlockDefaults(TType&) const {}
virtual void setInvariant(const TSourceLoc&, const char*) {}
virtual void finalizeAtomicCounterBlockLayout(TVariable&) {}
bool isAtomicCounterBlock(const TSymbol& symbol) {
const TVariable* var = symbol.getAsVariable();
if (!var)
return false;
const auto& at = atomicCounterBuffers.find(var->getType().getQualifier().layoutBinding);
return (at != atomicCounterBuffers.end() && (*at).second->getType() == var->getType());
}
virtual void outputMessage(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, TPrefixType prefix,
va_list args);
virtual void trackLinkage(TSymbol& symbol);
virtual void makeEditable(TSymbol*&);
virtual TVariable* getEditableVariable(const char* name);
virtual void finish();
};
//
// Manage the state for when to respect precision qualifiers and when to warn about
// the defaults being different than might be expected.
//
class TPrecisionManager {
public:
TPrecisionManager() : obey(false), warn(false), explicitIntDefault(false), explicitFloatDefault(false){ }
virtual ~TPrecisionManager() {}
void respectPrecisionQualifiers() { obey = true; }
bool respectingPrecisionQualifiers() const { return obey; }
bool shouldWarnAboutDefaults() const { return warn; }
void defaultWarningGiven() { warn = false; }
void warnAboutDefaults() { warn = true; }
void explicitIntDefaultSeen()
{
explicitIntDefault = true;
if (explicitFloatDefault)
warn = false;
}
void explicitFloatDefaultSeen()
{
explicitFloatDefault = true;
if (explicitIntDefault)
warn = false;
}
protected:
bool obey; // respect precision qualifiers
bool warn; // need to give a warning about the defaults
bool explicitIntDefault; // user set the default for int/uint
bool explicitFloatDefault; // user set the default for float
};
//
// GLSL-specific parse helper. Should have GLSL in the name, but that's
// too big of a change for comparing branches at the moment, and perhaps
// impacts downstream consumers as well.
//
class TParseContext : public TParseContextBase {
public:
TParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins, int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&,
bool forwardCompatible = false, EShMessages messages = EShMsgDefault,
const TString* entryPoint = nullptr);
virtual ~TParseContext();
bool obeyPrecisionQualifiers() const { return precisionManager.respectingPrecisionQualifiers(); }
void setPrecisionDefaults();
void setLimits(const TBuiltInResource&) override;
bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) override;
void parserError(const char* s); // for bison's yyerror
virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr) override;
virtual void growAtomicCounterBlock(int binding, const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr) override;
void reservedErrorCheck(const TSourceLoc&, const TString&);
void reservedPpErrorCheck(const TSourceLoc&, const char* name, const char* op) override;
bool lineContinuationCheck(const TSourceLoc&, bool endOfComment) override;
bool lineDirectiveShouldSetNextLine() const override;
bool builtInName(const TString&);
void handlePragma(const TSourceLoc&, const TVector<TString>&) override;
TIntermTyped* handleVariable(const TSourceLoc&, TSymbol* symbol, const TString* string);
TIntermTyped* handleBracketDereference(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
void handleIndexLimits(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
void makeEditable(TSymbol*&) override;
void ioArrayCheck(const TSourceLoc&, const TType&, const TString& identifier);
bool isIoResizeArray(const TType&) const;
void fixIoArraySize(const TSourceLoc&, TType&);
void handleIoResizeArrayAccess(const TSourceLoc&, TIntermTyped* base);
void checkIoArraysConsistency(const TSourceLoc&, bool tailOnly = false);
int getIoArrayImplicitSize(const TQualifier&, TString* featureString = nullptr) const;
void checkIoArrayConsistency(const TSourceLoc&, int requiredSize, const char* feature, TType&, const TString&);
TIntermTyped* handleBinaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* left, TIntermTyped* right);
TIntermTyped* handleUnaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* childNode);
TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field);
TIntermTyped* handleDotSwizzle(const TSourceLoc&, TIntermTyped* base, const TString& field);
void blockMemberExtensionCheck(const TSourceLoc&, const TIntermTyped* base, int member, const TString& memberName);
TFunction* handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&);
TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermNode*);
TIntermTyped* handleBuiltInFunctionCall(TSourceLoc, TIntermNode* arguments, const TFunction& function);
void computeBuiltinPrecisions(TIntermTyped&, const TFunction&);
TIntermNode* handleReturnValue(const TSourceLoc&, TIntermTyped*);
void checkLocation(const TSourceLoc&, TOperator);
TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*);
void addInputArgumentConversions(const TFunction&, TIntermNode*&) const;
TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&) const;
TIntermTyped* addAssign(const TSourceLoc&, TOperator op, TIntermTyped* left, TIntermTyped* right);
void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
void nonOpBuiltInCheck(const TSourceLoc&, const TFunction&, TIntermAggregate&);
void userFunctionCallCheck(const TSourceLoc&, TIntermAggregate&);
void samplerConstructorLocationCheck(const TSourceLoc&, const char* token, TIntermNode*);
TFunction* handleConstructorCall(const TSourceLoc&, const TPublicType&);
void handlePrecisionQualifier(const TSourceLoc&, TQualifier&, TPrecisionQualifier);
void checkPrecisionQualifier(const TSourceLoc&, TPrecisionQualifier);
void memorySemanticsCheck(const TSourceLoc&, const TFunction&, const TIntermOperator& callNode);
TIntermTyped* vkRelaxedRemapFunctionCall(const TSourceLoc&, TFunction*, TIntermNode*);
// returns true if the variable was remapped to something else
bool vkRelaxedRemapUniformVariable(const TSourceLoc&, TString&, const TPublicType&, TArraySizes*, TIntermTyped*, TType&);
void vkRelaxedRemapUniformMembers(const TSourceLoc&, const TPublicType&, const TType&, const TString&);
void vkRelaxedRemapFunctionParameter(TFunction*, TParameter&, std::vector<int>* newParams = nullptr);
TIntermNode* vkRelaxedRemapFunctionArgument(const TSourceLoc&, TFunction*, TIntermTyped*);
TIntermTyped* vkRelaxedRemapDotDereference(const TSourceLoc&, TIntermTyped&, const TType&, const TString&);
void assignError(const TSourceLoc&, const char* op, TString left, TString right);
void unaryOpError(const TSourceLoc&, const char* op, TString operand);
void binaryOpError(const TSourceLoc&, const char* op, TString left, TString right);
void variableCheck(TIntermTyped*& nodePtr);
bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
void rValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
void constantValueCheck(TIntermTyped* node, const char* token);
void integerCheck(const TIntermTyped* node, const char* token);
void globalCheck(const TSourceLoc&, const char* token);
bool constructorError(const TSourceLoc&, TIntermNode*, TFunction&, TOperator, TType&);
bool constructorTextureSamplerError(const TSourceLoc&, const TFunction&);
void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&, const char *sizeType, const bool allowZero = false);
bool arrayQualifierError(const TSourceLoc&, const TQualifier&);
bool arrayError(const TSourceLoc&, const TType&);
void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&);
void structArrayCheck(const TSourceLoc&, const TType& structure);
void arraySizesCheck(const TSourceLoc&, const TQualifier&, TArraySizes*, const TIntermTyped* initializer, bool lastMember);
void arrayOfArrayVersionCheck(const TSourceLoc&, const TArraySizes*);
bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType);
void boolCheck(const TSourceLoc&, const TIntermTyped*);
void boolCheck(const TSourceLoc&, const TPublicType&);
void samplerCheck(const TSourceLoc&, const TType&, const TString& identifier, TIntermTyped* initializer);
void atomicUintCheck(const TSourceLoc&, const TType&, const TString& identifier);
void accStructCheck(const TSourceLoc & loc, const TType & type, const TString & identifier);
void transparentOpaqueCheck(const TSourceLoc&, const TType&, const TString& identifier);
void memberQualifierCheck(glslang::TPublicType&);
void globalQualifierFixCheck(const TSourceLoc&, TQualifier&, bool isMemberCheck = false, const TPublicType* publicType = nullptr);
void globalQualifierTypeCheck(const TSourceLoc&, const TQualifier&, const TPublicType&);
bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType);
void mergeQualifiers(const TSourceLoc&, TQualifier& dst, const TQualifier& src, bool force);
void setDefaultPrecision(const TSourceLoc&, TPublicType&, TPrecisionQualifier);
int computeSamplerTypeIndex(TSampler&);
TPrecisionQualifier getDefaultPrecision(TPublicType&);
void precisionQualifierCheck(const TSourceLoc&, TBasicType, TQualifier&, bool isCoopMat);
void parameterTypeCheck(const TSourceLoc&, TStorageQualifier qualifier, const TType& type);
bool containsFieldWithBasicType(const TType& type ,TBasicType basicType);
TSymbol* redeclareBuiltinVariable(const TSourceLoc&, const TString&, const TQualifier&, const TShaderQualifiers&);
void redeclareBuiltinBlock(const TSourceLoc&, TTypeList& typeList, const TString& blockName, const TString* instanceName, TArraySizes* arraySizes);
void paramCheckFixStorage(const TSourceLoc&, const TStorageQualifier&, TType& type);
void paramCheckFix(const TSourceLoc&, const TQualifier&, TType& type);
void nestedBlockCheck(const TSourceLoc&);
void nestedStructCheck(const TSourceLoc&);
void arrayObjectCheck(const TSourceLoc&, const TType&, const char* op);
void opaqueCheck(const TSourceLoc&, const TType&, const char* op);
void referenceCheck(const TSourceLoc&, const TType&, const char* op);
void storage16BitAssignmentCheck(const TSourceLoc&, const TType&, const char* op);
void specializationCheck(const TSourceLoc&, const TType&, const char* op);
void structTypeCheck(const TSourceLoc&, TPublicType&);
void inductiveLoopCheck(const TSourceLoc&, TIntermNode* init, TIntermLoop* loop);
void arrayLimitCheck(const TSourceLoc&, const TString&, int size);
void limitCheck(const TSourceLoc&, int value, const char* limit, const char* feature);
void coopMatTypeParametersCheck(const TSourceLoc&, const TPublicType&);
void inductiveLoopBodyCheck(TIntermNode*, long long loopIndexId, TSymbolTable&);
void constantIndexExpressionCheck(TIntermNode*);
void setLayoutQualifier(const TSourceLoc&, TPublicType&, TString&);
void setLayoutQualifier(const TSourceLoc&, TPublicType&, TString&, const TIntermTyped*);
void mergeObjectLayoutQualifiers(TQualifier& dest, const TQualifier& src, bool inheritOnly);
void layoutObjectCheck(const TSourceLoc&, const TSymbol&);
void layoutMemberLocationArrayCheck(const TSourceLoc&, bool memberWithLocation, TArraySizes* arraySizes);
void layoutTypeCheck(const TSourceLoc&, const TType&);
void layoutQualifierCheck(const TSourceLoc&, const TQualifier&);
void checkNoShaderLayouts(const TSourceLoc&, const TShaderQualifiers&);
void fixOffset(const TSourceLoc&, TSymbol&);
const TFunction* findFunction(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
const TFunction* findFunctionExact(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
const TFunction* findFunction120(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
const TFunction* findFunction400(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
const TFunction* findFunctionExplicitTypes(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
void declareTypeDefaults(const TSourceLoc&, const TPublicType&);
TIntermNode* declareVariable(const TSourceLoc&, TString& identifier, const TPublicType&, TArraySizes* typeArray = nullptr, TIntermTyped* initializer = nullptr);
TIntermTyped* addConstructor(const TSourceLoc&, TIntermNode*, const TType&);
TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&);
TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset);
void inheritMemoryQualifiers(const TQualifier& from, TQualifier& to);
void declareBlock(const TSourceLoc&, TTypeList& typeList, const TString* instanceName = nullptr, TArraySizes* arraySizes = nullptr);
void blockStorageRemap(const TSourceLoc&, const TString*, TQualifier&);
void blockStageIoCheck(const TSourceLoc&, const TQualifier&);
void blockQualifierCheck(const TSourceLoc&, const TQualifier&, bool instanceName);
void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation);
void fixXfbOffsets(TQualifier&, TTypeList&);
void fixBlockUniformOffsets(TQualifier&, TTypeList&);
void fixBlockUniformLayoutMatrix(TQualifier&, TTypeList*, TTypeList*);
void fixBlockUniformLayoutPacking(TQualifier&, TTypeList*, TTypeList*);
void addQualifierToExisting(const TSourceLoc&, TQualifier, const TString& identifier);
void addQualifierToExisting(const TSourceLoc&, TQualifier, TIdentifierList&);
void invariantCheck(const TSourceLoc&, const TQualifier&);
void updateStandaloneQualifierDefaults(const TSourceLoc&, const TPublicType&);
void updateBindlessQualifier(TType& memberType);
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body);
const TTypeList* recordStructCopy(TStructRecord&, const TType*, const TType*);
TLayoutFormat mapLegacyLayoutFormat(TLayoutFormat legacyLayoutFormat, TBasicType imageType);
TAttributeType attributeFromName(const TString& name) const;
TAttributes* makeAttributes(const TString& identifier) const;
TAttributes* makeAttributes(const TString& identifier, TIntermNode* node) const;
TAttributes* mergeAttributes(TAttributes*, TAttributes*) const;
// Determine selection control from attributes
void handleSelectionAttributes(const TAttributes& attributes, TIntermNode*);
void handleSwitchAttributes(const TAttributes& attributes, TIntermNode*);
// Determine loop control from attributes
void handleLoopAttributes(const TAttributes& attributes, TIntermNode*);
// Function attributes
void handleFunctionAttributes(const TSourceLoc&, const TAttributes&);
// GL_EXT_spirv_intrinsics
TSpirvRequirement* makeSpirvRequirement(const TSourceLoc& loc, const TString& name,
const TIntermAggregate* extensions, const TIntermAggregate* capabilities);
TSpirvRequirement* mergeSpirvRequirements(const TSourceLoc& loc, TSpirvRequirement* spirvReq1,
TSpirvRequirement* spirvReq2);
TSpirvTypeParameters* makeSpirvTypeParameters(const TSourceLoc& loc, const TIntermConstantUnion* constant);
TSpirvTypeParameters* makeSpirvTypeParameters(const TSourceLoc& loc, const TPublicType& type);
TSpirvTypeParameters* mergeSpirvTypeParameters(TSpirvTypeParameters* spirvTypeParams1,
TSpirvTypeParameters* spirvTypeParams2);
TSpirvInstruction* makeSpirvInstruction(const TSourceLoc& loc, const TString& name, const TString& value);
TSpirvInstruction* makeSpirvInstruction(const TSourceLoc& loc, const TString& name, int value);
TSpirvInstruction* mergeSpirvInstruction(const TSourceLoc& loc, TSpirvInstruction* spirvInst1,
TSpirvInstruction* spirvInst2);
void checkAndResizeMeshViewDim(const TSourceLoc&, TType&, bool isBlockMember);
protected:
void nonInitConstCheck(const TSourceLoc&, TString& identifier, TType& type);
void inheritGlobalDefaults(TQualifier& dst) const;
TVariable* makeInternalVariable(const char* name, const TType&) const;
TVariable* declareNonArray(const TSourceLoc&, const TString& identifier, const TType&);
void declareArray(const TSourceLoc&, const TString& identifier, const TType&, TSymbol*&);
void checkRuntimeSizable(const TSourceLoc&, const TIntermTyped&);
bool isRuntimeLength(const TIntermTyped&) const;
TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer);
void finish() override;
virtual const char* getGlobalUniformBlockName() const override;
virtual void finalizeGlobalUniformBlockLayout(TVariable&) override;
virtual void setUniformBlockDefaults(TType& block) const override;
virtual const char* getAtomicCounterBlockName() const override;
virtual void finalizeAtomicCounterBlockLayout(TVariable&) override;
virtual void setAtomicCounterBlockDefaults(TType& block) const override;
virtual void setInvariant(const TSourceLoc& loc, const char* builtin) override;
public:
//
// Generally, bison productions, the scanner, and the PP need read/write access to these; just give them direct access
//
// Current state of parsing
bool inMain; // if inside a function, true if the function is main
const TString* blockName;
TQualifier currentBlockQualifier;
TPrecisionQualifier defaultPrecision[EbtNumTypes];
TBuiltInResource resources;
TLimits& limits;
protected:
TParseContext(TParseContext&);
TParseContext& operator=(TParseContext&);
static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2 * 2 * 2)); // see computeSamplerTypeIndex()
TPrecisionQualifier defaultSamplerPrecision[maxSamplerIndex];
TPrecisionManager precisionManager;
TQualifier globalBufferDefaults;
TQualifier globalUniformDefaults;
TQualifier globalInputDefaults;
TQualifier globalOutputDefaults;
TQualifier globalSharedDefaults;
TString currentCaller; // name of last function body entered (not valid when at global scope)
int* atomicUintOffsets; // to become an array of the right size to hold an offset per binding point
bool anyIndexLimits;
TIdSetType inductiveLoopIds;
TVector<TIntermTyped*> needsIndexLimitationChecking;
TStructRecord matrixFixRecord;
TStructRecord packingFixRecord;
//
// Geometry shader input arrays:
// - array sizing is based on input primitive and/or explicit size
//
// Tessellation control output arrays:
// - array sizing is based on output layout(vertices=...) and/or explicit size
//
// Both:
// - array sizing is retroactive
// - built-in block redeclarations interact with this
//
// Design:
// - use a per-context "resize-list", a list of symbols whose array sizes
// can be fixed
//
// - the resize-list starts empty at beginning of user-shader compilation, it does
// not have built-ins in it
//
// - on built-in array use: copyUp() symbol and add it to the resize-list
//
// - on user array declaration: add it to the resize-list
//
// - on block redeclaration: copyUp() symbol and add it to the resize-list
// * note, that appropriately gives an error if redeclaring a block that
// was already used and hence already copied-up
//
// - on seeing a layout declaration that sizes the array, fix everything in the
// resize-list, giving errors for mismatch
//
// - on seeing an array size declaration, give errors on mismatch between it and previous
// array-sizing declarations
//
TVector<TSymbol*> ioArraySymbolResizeList;
};
} // end namespace glslang
#endif // _PARSER_HELPER_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/reflection.cpp | //
// Copyright (C) 2013-2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "../Include/Common.h"
#include "reflection.h"
#include "LiveTraverser.h"
#include "localintermediate.h"
#include "gl_types.h"
//
// Grow the reflection database through a friend traverser class of TReflection and a
// collection of functions to do a liveness traversal that note what uniforms are used
// in semantically non-dead code.
//
// Can be used multiple times, once per stage, to grow a program reflection.
//
// High-level algorithm for one stage:
//
// 1. Put the entry point on the list of live functions.
//
// 2. Traverse any live function, while skipping if-tests with a compile-time constant
// condition of false, and while adding any encountered function calls to the live
// function list.
//
// Repeat until the live function list is empty.
//
// 3. Add any encountered uniform variables and blocks to the reflection database.
//
// Can be attempted with a failed link, but will return false if recursion had been detected, or
// there wasn't exactly one entry point.
//
namespace glslang {
//
// The traverser: mostly pass through, except
// - processing binary nodes to see if they are dereferences of an aggregates to track
// - processing symbol nodes to see if they are non-aggregate objects to track
//
// This ignores semantically dead code by using TLiveTraverser.
//
// This is in the glslang namespace directly so it can be a friend of TReflection.
//
class TReflectionTraverser : public TIntermTraverser {
public:
TReflectionTraverser(const TIntermediate& i, TReflection& r) :
TIntermTraverser(), intermediate(i), reflection(r), updateStageMasks(true) { }
virtual bool visitBinary(TVisit, TIntermBinary* node);
virtual void visitSymbol(TIntermSymbol* base);
// Add a simple reference to a uniform variable to the uniform database, no dereference involved.
// However, no dereference doesn't mean simple... it could be a complex aggregate.
void addUniform(const TIntermSymbol& base)
{
if (processedDerefs.find(&base) == processedDerefs.end()) {
processedDerefs.insert(&base);
int blockIndex = -1;
int offset = -1;
TList<TIntermBinary*> derefs;
TString baseName = base.getName();
if (base.getType().getBasicType() == EbtBlock) {
offset = 0;
bool anonymous = IsAnonymous(baseName);
const TString& blockName = base.getType().getTypeName();
if (!anonymous)
baseName = blockName;
else
baseName = "";
blockIndex = addBlockName(blockName, base.getType(), intermediate.getBlockSize(base.getType()));
}
// Use a degenerate (empty) set of dereferences to immediately put as at the end of
// the dereference change expected by blowUpActiveAggregate.
blowUpActiveAggregate(base.getType(), baseName, derefs, derefs.end(), offset, blockIndex, 0, -1, 0,
base.getQualifier().storage, updateStageMasks);
}
}
void addPipeIOVariable(const TIntermSymbol& base)
{
if (processedDerefs.find(&base) == processedDerefs.end()) {
processedDerefs.insert(&base);
const TString &name = base.getName();
const TType &type = base.getType();
const bool input = base.getQualifier().isPipeInput();
TReflection::TMapIndexToReflection &ioItems =
input ? reflection.indexToPipeInput : reflection.indexToPipeOutput;
TReflection::TNameToIndex &ioMapper =
input ? reflection.pipeInNameToIndex : reflection.pipeOutNameToIndex;
if (reflection.options & EShReflectionUnwrapIOBlocks) {
bool anonymous = IsAnonymous(name);
TString baseName;
if (type.getBasicType() == EbtBlock) {
baseName = anonymous ? TString() : type.getTypeName();
} else {
baseName = anonymous ? TString() : name;
}
// by convention if this is an arrayed block we ignore the array in the reflection
if (type.isArray() && type.getBasicType() == EbtBlock) {
blowUpIOAggregate(input, baseName, TType(type, 0));
} else {
blowUpIOAggregate(input, baseName, type);
}
} else {
TReflection::TNameToIndex::const_iterator it = ioMapper.find(name.c_str());
if (it == ioMapper.end()) {
// seperate pipe i/o params from uniforms and blocks
// in is only for input in first stage as out is only for last stage. check traverse in call stack.
ioMapper[name.c_str()] = static_cast<int>(ioItems.size());
ioItems.push_back(
TObjectReflection(name.c_str(), type, 0, mapToGlType(type), mapToGlArraySize(type), 0));
EShLanguageMask& stages = ioItems.back().stages;
stages = static_cast<EShLanguageMask>(stages | 1 << intermediate.getStage());
} else {
EShLanguageMask& stages = ioItems[it->second].stages;
stages = static_cast<EShLanguageMask>(stages | 1 << intermediate.getStage());
}
}
}
}
// Lookup or calculate the offset of all block members at once, using the recursively
// defined block offset rules.
void getOffsets(const TType& type, TVector<int>& offsets)
{
const TTypeList& memberList = *type.getStruct();
int memberSize = 0;
int offset = 0;
for (size_t m = 0; m < offsets.size(); ++m) {
// if the user supplied an offset, snap to it now
if (memberList[m].type->getQualifier().hasOffset())
offset = memberList[m].type->getQualifier().layoutOffset;
// calculate the offset of the next member and align the current offset to this member
intermediate.updateOffset(type, *memberList[m].type, offset, memberSize);
// save the offset of this member
offsets[m] = offset;
// update for the next member
offset += memberSize;
}
}
// Calculate the stride of an array type
int getArrayStride(const TType& baseType, const TType& type)
{
int dummySize;
int stride;
// consider blocks to have 0 stride, so that all offsets are relative to the start of their block
if (type.getBasicType() == EbtBlock)
return 0;
TLayoutMatrix subMatrixLayout = type.getQualifier().layoutMatrix;
intermediate.getMemberAlignment(type, dummySize, stride,
baseType.getQualifier().layoutPacking,
subMatrixLayout != ElmNone
? subMatrixLayout == ElmRowMajor
: baseType.getQualifier().layoutMatrix == ElmRowMajor);
return stride;
}
// count the total number of leaf members from iterating out of a block type
int countAggregateMembers(const TType& parentType)
{
if (! parentType.isStruct())
return 1;
const bool strictArraySuffix = (reflection.options & EShReflectionStrictArraySuffix);
bool blockParent = (parentType.getBasicType() == EbtBlock && parentType.getQualifier().storage == EvqBuffer);
const TTypeList &memberList = *parentType.getStruct();
int ret = 0;
for (size_t i = 0; i < memberList.size(); i++)
{
const TType &memberType = *memberList[i].type;
int numMembers = countAggregateMembers(memberType);
// for sized arrays of structs, apply logic to expand out the same as we would below in
// blowUpActiveAggregate
if (memberType.isArray() && ! memberType.getArraySizes()->hasUnsized() && memberType.isStruct()) {
if (! strictArraySuffix || ! blockParent)
numMembers *= memberType.getArraySizes()->getCumulativeSize();
}
ret += numMembers;
}
return ret;
}
// Traverse the provided deref chain, including the base, and
// - build a full reflection-granularity name, array size, etc. entry out of it, if it goes down to that granularity
// - recursively expand any variable array index in the middle of that traversal
// - recursively expand what's left at the end if the deref chain did not reach down to reflection granularity
//
// arraySize tracks, just for the final dereference in the chain, if there was a specific known size.
// A value of 0 for arraySize will mean to use the full array's size.
void blowUpActiveAggregate(const TType& baseType, const TString& baseName, const TList<TIntermBinary*>& derefs,
TList<TIntermBinary*>::const_iterator deref, int offset, int blockIndex, int arraySize,
int topLevelArraySize, int topLevelArrayStride, TStorageQualifier baseStorage, bool active)
{
// when strictArraySuffix is enabled, we closely follow the rules from ARB_program_interface_query.
// Broadly:
// * arrays-of-structs always have a [x] suffix.
// * with array-of-struct variables in the root of a buffer block, only ever return [0].
// * otherwise, array suffixes are added whenever we iterate, even if that means expanding out an array.
const bool strictArraySuffix = (reflection.options & EShReflectionStrictArraySuffix);
// is this variable inside a buffer block. This flag is set back to false after we iterate inside the first array element.
bool blockParent = (baseType.getBasicType() == EbtBlock && baseType.getQualifier().storage == EvqBuffer);
// process the part of the dereference chain that was explicit in the shader
TString name = baseName;
const TType* terminalType = &baseType;
for (; deref != derefs.end(); ++deref) {
TIntermBinary* visitNode = *deref;
terminalType = &visitNode->getType();
int index;
switch (visitNode->getOp()) {
case EOpIndexIndirect: {
int stride = getArrayStride(baseType, visitNode->getLeft()->getType());
if (topLevelArrayStride == 0)
topLevelArrayStride = stride;
// Visit all the indices of this array, and for each one add on the remaining dereferencing
for (int i = 0; i < std::max(visitNode->getLeft()->getType().getOuterArraySize(), 1); ++i) {
TString newBaseName = name;
if (terminalType->getBasicType() == EbtBlock) {}
else if (strictArraySuffix && blockParent)
newBaseName.append(TString("[0]"));
else if (strictArraySuffix || baseType.getBasicType() != EbtBlock)
newBaseName.append(TString("[") + String(i) + "]");
TList<TIntermBinary*>::const_iterator nextDeref = deref;
++nextDeref;
blowUpActiveAggregate(*terminalType, newBaseName, derefs, nextDeref, offset, blockIndex, arraySize,
topLevelArraySize, topLevelArrayStride, baseStorage, active);
if (offset >= 0)
offset += stride;
}
// it was all completed in the recursive calls above
return;
}
case EOpIndexDirect: {
int stride = getArrayStride(baseType, visitNode->getLeft()->getType());
index = visitNode->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst();
if (terminalType->getBasicType() == EbtBlock) {}
else if (strictArraySuffix && blockParent)
name.append(TString("[0]"));
else if (strictArraySuffix || baseType.getBasicType() != EbtBlock) {
name.append(TString("[") + String(index) + "]");
if (offset >= 0)
offset += stride * index;
}
if (topLevelArrayStride == 0)
topLevelArrayStride = stride;
// expand top-level arrays in blocks with [0] suffix
if (topLevelArrayStride != 0 && visitNode->getLeft()->getType().isArray()) {
blockParent = false;
}
break;
}
case EOpIndexDirectStruct:
index = visitNode->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst();
if (offset >= 0)
offset += intermediate.getOffset(visitNode->getLeft()->getType(), index);
if (name.size() > 0)
name.append(".");
name.append((*visitNode->getLeft()->getType().getStruct())[index].type->getFieldName());
// expand non top-level arrays with [x] suffix
if (visitNode->getLeft()->getType().getBasicType() != EbtBlock && terminalType->isArray())
{
blockParent = false;
}
break;
default:
break;
}
}
// if the terminalType is still too coarse a granularity, this is still an aggregate to expand, expand it...
if (! isReflectionGranularity(*terminalType)) {
// the base offset of this node, that children are relative to
int baseOffset = offset;
if (terminalType->isArray()) {
// Visit all the indices of this array, and for each one,
// fully explode the remaining aggregate to dereference
int stride = 0;
if (offset >= 0)
stride = getArrayStride(baseType, *terminalType);
int arrayIterateSize = std::max(terminalType->getOuterArraySize(), 1);
// for top-level arrays in blocks, only expand [0] to avoid explosion of items
if ((strictArraySuffix && blockParent) ||
((topLevelArraySize == arrayIterateSize) && (topLevelArrayStride == 0))) {
arrayIterateSize = 1;
}
if (topLevelArrayStride == 0)
topLevelArrayStride = stride;
for (int i = 0; i < arrayIterateSize; ++i) {
TString newBaseName = name;
if (terminalType->getBasicType() != EbtBlock)
newBaseName.append(TString("[") + String(i) + "]");
TType derefType(*terminalType, 0);
if (offset >= 0)
offset = baseOffset + stride * i;
blowUpActiveAggregate(derefType, newBaseName, derefs, derefs.end(), offset, blockIndex, 0,
topLevelArraySize, topLevelArrayStride, baseStorage, active);
}
} else {
// Visit all members of this aggregate, and for each one,
// fully explode the remaining aggregate to dereference
const TTypeList& typeList = *terminalType->getStruct();
TVector<int> memberOffsets;
if (baseOffset >= 0) {
memberOffsets.resize(typeList.size());
getOffsets(*terminalType, memberOffsets);
}
for (int i = 0; i < (int)typeList.size(); ++i) {
TString newBaseName = name;
if (newBaseName.size() > 0)
newBaseName.append(".");
newBaseName.append(typeList[i].type->getFieldName());
TType derefType(*terminalType, i);
if (offset >= 0)
offset = baseOffset + memberOffsets[i];
int arrayStride = topLevelArrayStride;
if (terminalType->getBasicType() == EbtBlock && terminalType->getQualifier().storage == EvqBuffer &&
derefType.isArray()) {
arrayStride = getArrayStride(baseType, derefType);
}
if (topLevelArraySize == -1 && arrayStride == 0 && blockParent)
topLevelArraySize = 1;
if (strictArraySuffix && blockParent) {
// if this member is an array, store the top-level array stride but start the explosion from
// the inner struct type.
if (derefType.isArray() && derefType.isStruct()) {
newBaseName.append("[0]");
auto dimSize = derefType.isUnsizedArray() ? 0 : derefType.getArraySizes()->getDimSize(0);
blowUpActiveAggregate(TType(derefType, 0), newBaseName, derefs, derefs.end(), memberOffsets[i],
blockIndex, 0, dimSize, arrayStride, terminalType->getQualifier().storage, false);
}
else if (derefType.isArray()) {
auto dimSize = derefType.isUnsizedArray() ? 0 : derefType.getArraySizes()->getDimSize(0);
blowUpActiveAggregate(derefType, newBaseName, derefs, derefs.end(), memberOffsets[i], blockIndex,
0, dimSize, 0, terminalType->getQualifier().storage, false);
}
else {
blowUpActiveAggregate(derefType, newBaseName, derefs, derefs.end(), memberOffsets[i], blockIndex,
0, 1, 0, terminalType->getQualifier().storage, false);
}
} else {
blowUpActiveAggregate(derefType, newBaseName, derefs, derefs.end(), offset, blockIndex, 0,
topLevelArraySize, arrayStride, baseStorage, active);
}
}
}
// it was all completed in the recursive calls above
return;
}
if ((reflection.options & EShReflectionBasicArraySuffix) && terminalType->isArray()) {
name.append(TString("[0]"));
}
// Finally, add a full string to the reflection database, and update the array size if necessary.
// If the dereferenced entity to record is an array, compute the size and update the maximum size.
// there might not be a final array dereference, it could have been copied as an array object
if (arraySize == 0)
arraySize = mapToGlArraySize(*terminalType);
TReflection::TMapIndexToReflection& variables = reflection.GetVariableMapForStorage(baseStorage);
TReflection::TNameToIndex::const_iterator it = reflection.nameToIndex.find(name.c_str());
if (it == reflection.nameToIndex.end()) {
int uniformIndex = (int)variables.size();
reflection.nameToIndex[name.c_str()] = uniformIndex;
variables.push_back(TObjectReflection(name.c_str(), *terminalType, offset, mapToGlType(*terminalType),
arraySize, blockIndex));
if (terminalType->isArray()) {
variables.back().arrayStride = getArrayStride(baseType, *terminalType);
if (topLevelArrayStride == 0)
topLevelArrayStride = variables.back().arrayStride;
}
if ((reflection.options & EShReflectionSeparateBuffers) && terminalType->isAtomic())
reflection.atomicCounterUniformIndices.push_back(uniformIndex);
variables.back().topLevelArraySize = topLevelArraySize;
variables.back().topLevelArrayStride = topLevelArrayStride;
if ((reflection.options & EShReflectionAllBlockVariables) && active) {
EShLanguageMask& stages = variables.back().stages;
stages = static_cast<EShLanguageMask>(stages | 1 << intermediate.getStage());
}
} else {
if (arraySize > 1) {
int& reflectedArraySize = variables[it->second].size;
reflectedArraySize = std::max(arraySize, reflectedArraySize);
}
if ((reflection.options & EShReflectionAllBlockVariables) && active) {
EShLanguageMask& stages = variables[it->second].stages;
stages = static_cast<EShLanguageMask>(stages | 1 << intermediate.getStage());
}
}
}
// similar to blowUpActiveAggregate, but with simpler rules and no dereferences to follow.
void blowUpIOAggregate(bool input, const TString &baseName, const TType &type)
{
TString name = baseName;
// if the type is still too coarse a granularity, this is still an aggregate to expand, expand it...
if (! isReflectionGranularity(type)) {
if (type.isArray()) {
// Visit all the indices of this array, and for each one,
// fully explode the remaining aggregate to dereference
for (int i = 0; i < std::max(type.getOuterArraySize(), 1); ++i) {
TString newBaseName = name;
newBaseName.append(TString("[") + String(i) + "]");
TType derefType(type, 0);
blowUpIOAggregate(input, newBaseName, derefType);
}
} else {
// Visit all members of this aggregate, and for each one,
// fully explode the remaining aggregate to dereference
const TTypeList& typeList = *type.getStruct();
for (int i = 0; i < (int)typeList.size(); ++i) {
TString newBaseName = name;
if (newBaseName.size() > 0)
newBaseName.append(".");
newBaseName.append(typeList[i].type->getFieldName());
TType derefType(type, i);
blowUpIOAggregate(input, newBaseName, derefType);
}
}
// it was all completed in the recursive calls above
return;
}
if ((reflection.options & EShReflectionBasicArraySuffix) && type.isArray()) {
name.append(TString("[0]"));
}
TReflection::TMapIndexToReflection &ioItems =
input ? reflection.indexToPipeInput : reflection.indexToPipeOutput;
std::string namespacedName = input ? "in " : "out ";
namespacedName += name.c_str();
TReflection::TNameToIndex::const_iterator it = reflection.nameToIndex.find(namespacedName);
if (it == reflection.nameToIndex.end()) {
reflection.nameToIndex[namespacedName] = (int)ioItems.size();
ioItems.push_back(
TObjectReflection(name.c_str(), type, 0, mapToGlType(type), mapToGlArraySize(type), 0));
EShLanguageMask& stages = ioItems.back().stages;
stages = static_cast<EShLanguageMask>(stages | 1 << intermediate.getStage());
} else {
EShLanguageMask& stages = ioItems[it->second].stages;
stages = static_cast<EShLanguageMask>(stages | 1 << intermediate.getStage());
}
}
// Add a uniform dereference where blocks/struct/arrays are involved in the access.
// Handles the situation where the left node is at the correct or too coarse a
// granularity for reflection. (That is, further dereferences up the tree will be
// skipped.) Earlier dereferences, down the tree, will be handled
// at the same time, and logged to prevent reprocessing as the tree is traversed.
//
// Note: Other things like the following must be caught elsewhere:
// - a simple non-array, non-struct variable (no dereference even conceivable)
// - an aggregrate consumed en masse, without a dereference
//
// So, this code is for cases like
// - a struct/block dereferencing a member (whether the member is array or not)
// - an array of struct
// - structs/arrays containing the above
//
void addDereferencedUniform(TIntermBinary* topNode)
{
// See if too fine-grained to process (wait to get further down the tree)
const TType& leftType = topNode->getLeft()->getType();
if ((leftType.isVector() || leftType.isMatrix()) && ! leftType.isArray())
return;
// We have an array or structure or block dereference, see if it's a uniform
// based dereference (if not, skip it).
TIntermSymbol* base = findBase(topNode);
if (! base || ! base->getQualifier().isUniformOrBuffer())
return;
// See if we've already processed this (e.g., in the middle of something
// we did earlier), and if so skip it
if (processedDerefs.find(topNode) != processedDerefs.end())
return;
// Process this uniform dereference
int offset = -1;
int blockIndex = -1;
bool anonymous = false;
// See if we need to record the block itself
bool block = base->getBasicType() == EbtBlock;
if (block) {
offset = 0;
anonymous = IsAnonymous(base->getName());
const TString& blockName = base->getType().getTypeName();
TString baseName;
if (! anonymous)
baseName = blockName;
blockIndex = addBlockName(blockName, base->getType(), intermediate.getBlockSize(base->getType()));
if (reflection.options & EShReflectionAllBlockVariables) {
// Use a degenerate (empty) set of dereferences to immediately put as at the end of
// the dereference change expected by blowUpActiveAggregate.
TList<TIntermBinary*> derefs;
// otherwise - if we're not using strict array suffix rules, or this isn't a block so we are
// expanding root arrays anyway, just start the iteration from the base block type.
blowUpActiveAggregate(base->getType(), baseName, derefs, derefs.end(), 0, blockIndex, 0, -1, 0,
base->getQualifier().storage, false);
}
}
// Process the dereference chain, backward, accumulating the pieces for later forward traversal.
// If the topNode is a reflection-granularity-array dereference, don't include that last dereference.
TList<TIntermBinary*> derefs;
for (TIntermBinary* visitNode = topNode; visitNode; visitNode = visitNode->getLeft()->getAsBinaryNode()) {
if (isReflectionGranularity(visitNode->getLeft()->getType()))
continue;
derefs.push_front(visitNode);
processedDerefs.insert(visitNode);
}
processedDerefs.insert(base);
// See if we have a specific array size to stick to while enumerating the explosion of the aggregate
int arraySize = 0;
if (isReflectionGranularity(topNode->getLeft()->getType()) && topNode->getLeft()->isArray()) {
if (topNode->getOp() == EOpIndexDirect)
arraySize = topNode->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst() + 1;
}
// Put the dereference chain together, forward
TString baseName;
if (! anonymous) {
if (block)
baseName = base->getType().getTypeName();
else
baseName = base->getName();
}
blowUpActiveAggregate(base->getType(), baseName, derefs, derefs.begin(), offset, blockIndex, arraySize, -1, 0,
base->getQualifier().storage, true);
}
int addBlockName(const TString& name, const TType& type, int size)
{
int blockIndex = 0;
if (type.isArray()) {
TType derefType(type, 0);
for (int e = 0; e < type.getOuterArraySize(); ++e) {
int memberBlockIndex = addBlockName(name + "[" + String(e) + "]", derefType, size);
if (e == 0)
blockIndex = memberBlockIndex;
}
} else {
TReflection::TMapIndexToReflection& blocks = reflection.GetBlockMapForStorage(type.getQualifier().storage);
TReflection::TNameToIndex::const_iterator it = reflection.nameToIndex.find(name.c_str());
if (reflection.nameToIndex.find(name.c_str()) == reflection.nameToIndex.end()) {
blockIndex = (int)blocks.size();
reflection.nameToIndex[name.c_str()] = blockIndex;
blocks.push_back(TObjectReflection(name.c_str(), type, -1, -1, size, blockIndex));
blocks.back().numMembers = countAggregateMembers(type);
if (updateStageMasks) {
EShLanguageMask& stages = blocks.back().stages;
stages = static_cast<EShLanguageMask>(stages | 1 << intermediate.getStage());
}
}
else {
blockIndex = it->second;
if (updateStageMasks) {
EShLanguageMask& stages = blocks[blockIndex].stages;
stages = static_cast<EShLanguageMask>(stages | 1 << intermediate.getStage());
}
}
}
return blockIndex;
}
// Are we at a level in a dereference chain at which individual active uniform queries are made?
bool isReflectionGranularity(const TType& type)
{
return type.getBasicType() != EbtBlock && type.getBasicType() != EbtStruct && !type.isArrayOfArrays();
}
// For a binary operation indexing into an aggregate, chase down the base of the aggregate.
// Return nullptr if the topology does not fit this situation.
TIntermSymbol* findBase(const TIntermBinary* node)
{
TIntermSymbol *base = node->getLeft()->getAsSymbolNode();
if (base)
return base;
TIntermBinary* left = node->getLeft()->getAsBinaryNode();
if (! left)
return nullptr;
return findBase(left);
}
//
// Translate a glslang sampler type into the GL API #define number.
//
int mapSamplerToGlType(TSampler sampler)
{
if (! sampler.image) {
// a sampler...
switch (sampler.type) {
case EbtFloat:
switch ((int)sampler.dim) {
case Esd1D:
if (sampler.shadow)
return sampler.arrayed ? GL_SAMPLER_1D_ARRAY_SHADOW : GL_SAMPLER_1D_SHADOW;
else
return sampler.arrayed ? GL_SAMPLER_1D_ARRAY : GL_SAMPLER_1D;
case Esd2D:
if (sampler.ms) {
return sampler.arrayed ? GL_SAMPLER_2D_MULTISAMPLE_ARRAY : GL_SAMPLER_2D_MULTISAMPLE;
} else {
if (sampler.shadow)
return sampler.arrayed ? GL_SAMPLER_2D_ARRAY_SHADOW : GL_SAMPLER_2D_SHADOW;
else
return sampler.arrayed ? GL_SAMPLER_2D_ARRAY : GL_SAMPLER_2D;
}
case Esd3D:
return GL_SAMPLER_3D;
case EsdCube:
if (sampler.shadow)
return sampler.arrayed ? GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW : GL_SAMPLER_CUBE_SHADOW;
else
return sampler.arrayed ? GL_SAMPLER_CUBE_MAP_ARRAY : GL_SAMPLER_CUBE;
case EsdRect:
return sampler.shadow ? GL_SAMPLER_2D_RECT_SHADOW : GL_SAMPLER_2D_RECT;
case EsdBuffer:
return GL_SAMPLER_BUFFER;
default:
return 0;
}
case EbtFloat16:
switch ((int)sampler.dim) {
case Esd1D:
if (sampler.shadow)
return sampler.arrayed ? GL_FLOAT16_SAMPLER_1D_ARRAY_SHADOW_AMD : GL_FLOAT16_SAMPLER_1D_SHADOW_AMD;
else
return sampler.arrayed ? GL_FLOAT16_SAMPLER_1D_ARRAY_AMD : GL_FLOAT16_SAMPLER_1D_AMD;
case Esd2D:
if (sampler.ms) {
return sampler.arrayed ? GL_FLOAT16_SAMPLER_2D_MULTISAMPLE_ARRAY_AMD : GL_FLOAT16_SAMPLER_2D_MULTISAMPLE_AMD;
} else {
if (sampler.shadow)
return sampler.arrayed ? GL_FLOAT16_SAMPLER_2D_ARRAY_SHADOW_AMD : GL_FLOAT16_SAMPLER_2D_SHADOW_AMD;
else
return sampler.arrayed ? GL_FLOAT16_SAMPLER_2D_ARRAY_AMD : GL_FLOAT16_SAMPLER_2D_AMD;
}
case Esd3D:
return GL_FLOAT16_SAMPLER_3D_AMD;
case EsdCube:
if (sampler.shadow)
return sampler.arrayed ? GL_FLOAT16_SAMPLER_CUBE_MAP_ARRAY_SHADOW_AMD : GL_FLOAT16_SAMPLER_CUBE_SHADOW_AMD;
else
return sampler.arrayed ? GL_FLOAT16_SAMPLER_CUBE_MAP_ARRAY_AMD : GL_FLOAT16_SAMPLER_CUBE_AMD;
case EsdRect:
return sampler.shadow ? GL_FLOAT16_SAMPLER_2D_RECT_SHADOW_AMD : GL_FLOAT16_SAMPLER_2D_RECT_AMD;
case EsdBuffer:
return GL_FLOAT16_SAMPLER_BUFFER_AMD;
default:
return 0;
}
case EbtInt:
switch ((int)sampler.dim) {
case Esd1D:
return sampler.arrayed ? GL_INT_SAMPLER_1D_ARRAY : GL_INT_SAMPLER_1D;
case Esd2D:
if (sampler.ms)
return sampler.arrayed ? GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY
: GL_INT_SAMPLER_2D_MULTISAMPLE;
else
return sampler.arrayed ? GL_INT_SAMPLER_2D_ARRAY : GL_INT_SAMPLER_2D;
case Esd3D:
return GL_INT_SAMPLER_3D;
case EsdCube:
return sampler.arrayed ? GL_INT_SAMPLER_CUBE_MAP_ARRAY : GL_INT_SAMPLER_CUBE;
case EsdRect:
return GL_INT_SAMPLER_2D_RECT;
case EsdBuffer:
return GL_INT_SAMPLER_BUFFER;
default:
return 0;
}
case EbtUint:
switch ((int)sampler.dim) {
case Esd1D:
return sampler.arrayed ? GL_UNSIGNED_INT_SAMPLER_1D_ARRAY : GL_UNSIGNED_INT_SAMPLER_1D;
case Esd2D:
if (sampler.ms)
return sampler.arrayed ? GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY
: GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE;
else
return sampler.arrayed ? GL_UNSIGNED_INT_SAMPLER_2D_ARRAY : GL_UNSIGNED_INT_SAMPLER_2D;
case Esd3D:
return GL_UNSIGNED_INT_SAMPLER_3D;
case EsdCube:
return sampler.arrayed ? GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY : GL_UNSIGNED_INT_SAMPLER_CUBE;
case EsdRect:
return GL_UNSIGNED_INT_SAMPLER_2D_RECT;
case EsdBuffer:
return GL_UNSIGNED_INT_SAMPLER_BUFFER;
default:
return 0;
}
default:
return 0;
}
} else {
// an image...
switch (sampler.type) {
case EbtFloat:
switch ((int)sampler.dim) {
case Esd1D:
return sampler.arrayed ? GL_IMAGE_1D_ARRAY : GL_IMAGE_1D;
case Esd2D:
if (sampler.ms)
return sampler.arrayed ? GL_IMAGE_2D_MULTISAMPLE_ARRAY : GL_IMAGE_2D_MULTISAMPLE;
else
return sampler.arrayed ? GL_IMAGE_2D_ARRAY : GL_IMAGE_2D;
case Esd3D:
return GL_IMAGE_3D;
case EsdCube:
return sampler.arrayed ? GL_IMAGE_CUBE_MAP_ARRAY : GL_IMAGE_CUBE;
case EsdRect:
return GL_IMAGE_2D_RECT;
case EsdBuffer:
return GL_IMAGE_BUFFER;
default:
return 0;
}
case EbtFloat16:
switch ((int)sampler.dim) {
case Esd1D:
return sampler.arrayed ? GL_FLOAT16_IMAGE_1D_ARRAY_AMD : GL_FLOAT16_IMAGE_1D_AMD;
case Esd2D:
if (sampler.ms)
return sampler.arrayed ? GL_FLOAT16_IMAGE_2D_MULTISAMPLE_ARRAY_AMD : GL_FLOAT16_IMAGE_2D_MULTISAMPLE_AMD;
else
return sampler.arrayed ? GL_FLOAT16_IMAGE_2D_ARRAY_AMD : GL_FLOAT16_IMAGE_2D_AMD;
case Esd3D:
return GL_FLOAT16_IMAGE_3D_AMD;
case EsdCube:
return sampler.arrayed ? GL_FLOAT16_IMAGE_CUBE_MAP_ARRAY_AMD : GL_FLOAT16_IMAGE_CUBE_AMD;
case EsdRect:
return GL_FLOAT16_IMAGE_2D_RECT_AMD;
case EsdBuffer:
return GL_FLOAT16_IMAGE_BUFFER_AMD;
default:
return 0;
}
case EbtInt:
switch ((int)sampler.dim) {
case Esd1D:
return sampler.arrayed ? GL_INT_IMAGE_1D_ARRAY : GL_INT_IMAGE_1D;
case Esd2D:
if (sampler.ms)
return sampler.arrayed ? GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY : GL_INT_IMAGE_2D_MULTISAMPLE;
else
return sampler.arrayed ? GL_INT_IMAGE_2D_ARRAY : GL_INT_IMAGE_2D;
case Esd3D:
return GL_INT_IMAGE_3D;
case EsdCube:
return sampler.arrayed ? GL_INT_IMAGE_CUBE_MAP_ARRAY : GL_INT_IMAGE_CUBE;
case EsdRect:
return GL_INT_IMAGE_2D_RECT;
case EsdBuffer:
return GL_INT_IMAGE_BUFFER;
default:
return 0;
}
case EbtUint:
switch ((int)sampler.dim) {
case Esd1D:
return sampler.arrayed ? GL_UNSIGNED_INT_IMAGE_1D_ARRAY : GL_UNSIGNED_INT_IMAGE_1D;
case Esd2D:
if (sampler.ms)
return sampler.arrayed ? GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY
: GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE;
else
return sampler.arrayed ? GL_UNSIGNED_INT_IMAGE_2D_ARRAY : GL_UNSIGNED_INT_IMAGE_2D;
case Esd3D:
return GL_UNSIGNED_INT_IMAGE_3D;
case EsdCube:
return sampler.arrayed ? GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY : GL_UNSIGNED_INT_IMAGE_CUBE;
case EsdRect:
return GL_UNSIGNED_INT_IMAGE_2D_RECT;
case EsdBuffer:
return GL_UNSIGNED_INT_IMAGE_BUFFER;
default:
return 0;
}
default:
return 0;
}
}
}
//
// Translate a glslang type into the GL API #define number.
// Ignores arrayness.
//
int mapToGlType(const TType& type)
{
switch (type.getBasicType()) {
case EbtSampler:
return mapSamplerToGlType(type.getSampler());
case EbtStruct:
case EbtBlock:
case EbtVoid:
return 0;
default:
break;
}
if (type.isVector()) {
int offset = type.getVectorSize() - 2;
switch (type.getBasicType()) {
case EbtFloat: return GL_FLOAT_VEC2 + offset;
case EbtDouble: return GL_DOUBLE_VEC2 + offset;
case EbtFloat16: return GL_FLOAT16_VEC2_NV + offset;
case EbtInt: return GL_INT_VEC2 + offset;
case EbtUint: return GL_UNSIGNED_INT_VEC2 + offset;
case EbtInt64: return GL_INT64_VEC2_ARB + offset;
case EbtUint64: return GL_UNSIGNED_INT64_VEC2_ARB + offset;
case EbtBool: return GL_BOOL_VEC2 + offset;
case EbtAtomicUint: return GL_UNSIGNED_INT_ATOMIC_COUNTER + offset;
default: return 0;
}
}
if (type.isMatrix()) {
switch (type.getBasicType()) {
case EbtFloat:
switch (type.getMatrixCols()) {
case 2:
switch (type.getMatrixRows()) {
case 2: return GL_FLOAT_MAT2;
case 3: return GL_FLOAT_MAT2x3;
case 4: return GL_FLOAT_MAT2x4;
default: return 0;
}
case 3:
switch (type.getMatrixRows()) {
case 2: return GL_FLOAT_MAT3x2;
case 3: return GL_FLOAT_MAT3;
case 4: return GL_FLOAT_MAT3x4;
default: return 0;
}
case 4:
switch (type.getMatrixRows()) {
case 2: return GL_FLOAT_MAT4x2;
case 3: return GL_FLOAT_MAT4x3;
case 4: return GL_FLOAT_MAT4;
default: return 0;
}
default: return 0;
}
case EbtDouble:
switch (type.getMatrixCols()) {
case 2:
switch (type.getMatrixRows()) {
case 2: return GL_DOUBLE_MAT2;
case 3: return GL_DOUBLE_MAT2x3;
case 4: return GL_DOUBLE_MAT2x4;
default: return 0;
}
case 3:
switch (type.getMatrixRows()) {
case 2: return GL_DOUBLE_MAT3x2;
case 3: return GL_DOUBLE_MAT3;
case 4: return GL_DOUBLE_MAT3x4;
default: return 0;
}
case 4:
switch (type.getMatrixRows()) {
case 2: return GL_DOUBLE_MAT4x2;
case 3: return GL_DOUBLE_MAT4x3;
case 4: return GL_DOUBLE_MAT4;
default: return 0;
}
default: return 0;
}
case EbtFloat16:
switch (type.getMatrixCols()) {
case 2:
switch (type.getMatrixRows()) {
case 2: return GL_FLOAT16_MAT2_AMD;
case 3: return GL_FLOAT16_MAT2x3_AMD;
case 4: return GL_FLOAT16_MAT2x4_AMD;
default: return 0;
}
case 3:
switch (type.getMatrixRows()) {
case 2: return GL_FLOAT16_MAT3x2_AMD;
case 3: return GL_FLOAT16_MAT3_AMD;
case 4: return GL_FLOAT16_MAT3x4_AMD;
default: return 0;
}
case 4:
switch (type.getMatrixRows()) {
case 2: return GL_FLOAT16_MAT4x2_AMD;
case 3: return GL_FLOAT16_MAT4x3_AMD;
case 4: return GL_FLOAT16_MAT4_AMD;
default: return 0;
}
default: return 0;
}
default:
return 0;
}
}
if (type.getVectorSize() == 1) {
switch (type.getBasicType()) {
case EbtFloat: return GL_FLOAT;
case EbtDouble: return GL_DOUBLE;
case EbtFloat16: return GL_FLOAT16_NV;
case EbtInt: return GL_INT;
case EbtUint: return GL_UNSIGNED_INT;
case EbtInt64: return GL_INT64_ARB;
case EbtUint64: return GL_UNSIGNED_INT64_ARB;
case EbtBool: return GL_BOOL;
case EbtAtomicUint: return GL_UNSIGNED_INT_ATOMIC_COUNTER;
default: return 0;
}
}
return 0;
}
int mapToGlArraySize(const TType& type)
{
return type.isArray() ? type.getOuterArraySize() : 1;
}
const TIntermediate& intermediate;
TReflection& reflection;
std::set<const TIntermNode*> processedDerefs;
bool updateStageMasks;
protected:
TReflectionTraverser(TReflectionTraverser&);
TReflectionTraverser& operator=(TReflectionTraverser&);
};
//
// Implement the traversal functions of interest.
//
// To catch dereferenced aggregates that must be reflected.
// This catches them at the highest level possible in the tree.
bool TReflectionTraverser::visitBinary(TVisit /* visit */, TIntermBinary* node)
{
switch (node->getOp()) {
case EOpIndexDirect:
case EOpIndexIndirect:
case EOpIndexDirectStruct:
addDereferencedUniform(node);
break;
default:
break;
}
// still need to visit everything below, which could contain sub-expressions
// containing different uniforms
return true;
}
// To reflect non-dereferenced objects.
void TReflectionTraverser::visitSymbol(TIntermSymbol* base)
{
if (base->getQualifier().storage == EvqUniform) {
if (base->getBasicType() == EbtBlock) {
if (reflection.options & EShReflectionSharedStd140UBO) {
addUniform(*base);
}
} else {
addUniform(*base);
}
}
// #TODO add std140/layout active rules for ssbo, same with ubo.
// Storage buffer blocks will be collected and expanding in this part.
if((reflection.options & EShReflectionSharedStd140SSBO) &&
(base->getQualifier().storage == EvqBuffer && base->getBasicType() == EbtBlock &&
(base->getQualifier().layoutPacking == ElpStd140 || base->getQualifier().layoutPacking == ElpShared)))
addUniform(*base);
if ((intermediate.getStage() == reflection.firstStage && base->getQualifier().isPipeInput()) ||
(intermediate.getStage() == reflection.lastStage && base->getQualifier().isPipeOutput()))
addPipeIOVariable(*base);
}
//
// Implement TObjectReflection methods.
//
TObjectReflection::TObjectReflection(const std::string &pName, const TType &pType, int pOffset, int pGLDefineType,
int pSize, int pIndex)
: name(pName), offset(pOffset), glDefineType(pGLDefineType), size(pSize), index(pIndex), counterIndex(-1),
numMembers(-1), arrayStride(0), topLevelArrayStride(0), stages(EShLanguageMask(0)), type(pType.clone())
{
}
int TObjectReflection::getBinding() const
{
if (type == nullptr || !type->getQualifier().hasBinding())
return -1;
return type->getQualifier().layoutBinding;
}
void TObjectReflection::dump() const
{
printf("%s: offset %d, type %x, size %d, index %d, binding %d, stages %d", name.c_str(), offset, glDefineType, size,
index, getBinding(), stages);
if (counterIndex != -1)
printf(", counter %d", counterIndex);
if (numMembers != -1)
printf(", numMembers %d", numMembers);
if (arrayStride != 0)
printf(", arrayStride %d", arrayStride);
if (topLevelArrayStride != 0)
printf(", topLevelArrayStride %d", topLevelArrayStride);
printf("\n");
}
//
// Implement TReflection methods.
//
// Track any required attribute reflection, such as compute shader numthreads.
//
void TReflection::buildAttributeReflection(EShLanguage stage, const TIntermediate& intermediate)
{
if (stage == EShLangCompute) {
// Remember thread dimensions
for (int dim=0; dim<3; ++dim)
localSize[dim] = intermediate.getLocalSize(dim);
}
}
// build counter block index associations for buffers
void TReflection::buildCounterIndices(const TIntermediate& intermediate)
{
#ifdef ENABLE_HLSL
// search for ones that have counters
for (int i = 0; i < int(indexToUniformBlock.size()); ++i) {
const TString counterName(intermediate.addCounterBufferName(indexToUniformBlock[i].name).c_str());
const int index = getIndex(counterName);
if (index >= 0)
indexToUniformBlock[i].counterIndex = index;
}
#else
(void)intermediate;
#endif
}
// build Shader Stages mask for all uniforms
void TReflection::buildUniformStageMask(const TIntermediate& intermediate)
{
if (options & EShReflectionAllBlockVariables)
return;
for (int i = 0; i < int(indexToUniform.size()); ++i) {
indexToUniform[i].stages = static_cast<EShLanguageMask>(indexToUniform[i].stages | 1 << intermediate.getStage());
}
for (int i = 0; i < int(indexToBufferVariable.size()); ++i) {
indexToBufferVariable[i].stages =
static_cast<EShLanguageMask>(indexToBufferVariable[i].stages | 1 << intermediate.getStage());
}
}
// Merge live symbols from 'intermediate' into the existing reflection database.
//
// Returns false if the input is too malformed to do this.
bool TReflection::addStage(EShLanguage stage, const TIntermediate& intermediate)
{
if (intermediate.getTreeRoot() == nullptr ||
intermediate.getNumEntryPoints() != 1 ||
intermediate.isRecursive())
return false;
buildAttributeReflection(stage, intermediate);
TReflectionTraverser it(intermediate, *this);
for (auto& sequnence : intermediate.getTreeRoot()->getAsAggregate()->getSequence()) {
if (sequnence->getAsAggregate() != nullptr) {
if (sequnence->getAsAggregate()->getOp() == glslang::EOpLinkerObjects) {
it.updateStageMasks = false;
TIntermAggregate* linkerObjects = sequnence->getAsAggregate();
for (auto& sequnence : linkerObjects->getSequence()) {
auto pNode = sequnence->getAsSymbolNode();
if (pNode != nullptr) {
if ((pNode->getQualifier().storage == EvqUniform &&
(options & EShReflectionSharedStd140UBO)) ||
(pNode->getQualifier().storage == EvqBuffer &&
(options & EShReflectionSharedStd140SSBO))) {
// collect std140 and shared uniform block form AST
if ((pNode->getBasicType() == EbtBlock) &&
((pNode->getQualifier().layoutPacking == ElpStd140) ||
(pNode->getQualifier().layoutPacking == ElpShared))) {
pNode->traverse(&it);
}
}
else if ((options & EShReflectionAllIOVariables) &&
(pNode->getQualifier().isPipeInput() || pNode->getQualifier().isPipeOutput()))
{
pNode->traverse(&it);
}
}
}
} else {
// This traverser will travers all function in AST.
// If we want reflect uncalled function, we need set linke message EShMsgKeepUncalled.
// When EShMsgKeepUncalled been set to true, all function will be keep in AST, even it is a uncalled function.
// This will keep some uniform variables in reflection, if those uniform variables is used in these uncalled function.
//
// If we just want reflect only live node, we can use a default link message or set EShMsgKeepUncalled false.
// When linke message not been set EShMsgKeepUncalled, linker won't keep uncalled function in AST.
// So, travers all function node can equivalent to travers live function.
it.updateStageMasks = true;
sequnence->getAsAggregate()->traverse(&it);
}
}
}
it.updateStageMasks = true;
buildCounterIndices(intermediate);
buildUniformStageMask(intermediate);
return true;
}
void TReflection::dump()
{
printf("Uniform reflection:\n");
for (size_t i = 0; i < indexToUniform.size(); ++i)
indexToUniform[i].dump();
printf("\n");
printf("Uniform block reflection:\n");
for (size_t i = 0; i < indexToUniformBlock.size(); ++i)
indexToUniformBlock[i].dump();
printf("\n");
printf("Buffer variable reflection:\n");
for (size_t i = 0; i < indexToBufferVariable.size(); ++i)
indexToBufferVariable[i].dump();
printf("\n");
printf("Buffer block reflection:\n");
for (size_t i = 0; i < indexToBufferBlock.size(); ++i)
indexToBufferBlock[i].dump();
printf("\n");
printf("Pipeline input reflection:\n");
for (size_t i = 0; i < indexToPipeInput.size(); ++i)
indexToPipeInput[i].dump();
printf("\n");
printf("Pipeline output reflection:\n");
for (size_t i = 0; i < indexToPipeOutput.size(); ++i)
indexToPipeOutput[i].dump();
printf("\n");
if (getLocalSize(0) > 1) {
static const char* axis[] = { "X", "Y", "Z" };
for (int dim=0; dim<3; ++dim)
if (getLocalSize(dim) > 1)
printf("Local size %s: %u\n", axis[dim], getLocalSize(dim));
printf("\n");
}
// printf("Live names\n");
// for (TNameToIndex::const_iterator it = nameToIndex.begin(); it != nameToIndex.end(); ++it)
// printf("%s: %d\n", it->first.c_str(), it->second);
// printf("\n");
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/InfoSink.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "../Include/InfoSink.h"
#include <cstring>
namespace glslang {
void TInfoSinkBase::append(const char* s)
{
if (outputStream & EString) {
if (s == nullptr)
sink.append("(null)");
else {
checkMem(strlen(s));
sink.append(s);
}
}
//#ifdef _WIN32
// if (outputStream & EDebugger)
// OutputDebugString(s);
//#endif
if (outputStream & EStdOut)
fprintf(stdout, "%s", s);
}
void TInfoSinkBase::append(int count, char c)
{
if (outputStream & EString) {
checkMem(count);
sink.append(count, c);
}
//#ifdef _WIN32
// if (outputStream & EDebugger) {
// char str[2];
// str[0] = c;
// str[1] = '\0';
// OutputDebugString(str);
// }
//#endif
if (outputStream & EStdOut)
fprintf(stdout, "%c", c);
}
void TInfoSinkBase::append(const TPersistString& t)
{
if (outputStream & EString) {
checkMem(t.size());
sink.append(t);
}
//#ifdef _WIN32
// if (outputStream & EDebugger)
// OutputDebugString(t.c_str());
//#endif
if (outputStream & EStdOut)
fprintf(stdout, "%s", t.c_str());
}
void TInfoSinkBase::append(const TString& t)
{
if (outputStream & EString) {
checkMem(t.size());
sink.append(t.c_str());
}
//#ifdef _WIN32
// if (outputStream & EDebugger)
// OutputDebugString(t.c_str());
//#endif
if (outputStream & EStdOut)
fprintf(stdout, "%s", t.c_str());
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/parseVersions.h | //
// Copyright (C) 2015-2018 Google, Inc.
// Copyright (C) 2017 ARM Limited.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// This is implemented in Versions.cpp
#ifndef _PARSE_VERSIONS_INCLUDED_
#define _PARSE_VERSIONS_INCLUDED_
#include "../Public/ShaderLang.h"
#include "../Include/InfoSink.h"
#include "Scan.h"
#include <map>
namespace glslang {
//
// Base class for parse helpers.
// This just has version-related information and checking.
// This class should be sufficient for preprocessing.
//
class TParseVersions {
public:
TParseVersions(TIntermediate& interm, int version, EProfile profile,
const SpvVersion& spvVersion, EShLanguage language, TInfoSink& infoSink,
bool forwardCompatible, EShMessages messages)
:
forwardCompatible(forwardCompatible),
profile(profile),
infoSink(infoSink), version(version),
language(language),
spvVersion(spvVersion),
intermediate(interm), messages(messages), numErrors(0), currentScanner(nullptr) { }
virtual ~TParseVersions() { }
void requireStage(const TSourceLoc&, EShLanguageMask, const char* featureDesc);
void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc);
bool forwardCompatible; // true if errors are to be given for use of deprecated features
EProfile profile; // the declared profile in the shader (core by default)
bool isEsProfile() const { return profile == EEsProfile; }
void requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc);
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions,
const char* const extensions[], const char* featureDesc);
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension,
const char* featureDesc);
virtual void initializeExtensionBehavior();
virtual void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc);
virtual void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc);
virtual void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
const char* featureDesc);
virtual void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
const char* featureDesc);
template<typename Container>
constexpr void ppRequireExtensions(const TSourceLoc& loc, Container extensions, const char* featureDesc) {
ppRequireExtensions(loc, static_cast<int>(extensions.size()), extensions.data(), featureDesc);
}
virtual TExtensionBehavior getExtensionBehavior(const char*);
virtual bool extensionTurnedOn(const char* const extension);
virtual bool extensionsTurnedOn(int numExtensions, const char* const extensions[]);
virtual void updateExtensionBehavior(int line, const char* const extension, const char* behavior);
virtual void updateExtensionBehavior(const char* const extension, TExtensionBehavior);
virtual bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[],
const char* featureDesc);
virtual void checkExtensionStage(const TSourceLoc&, const char* const extension);
virtual void extensionRequires(const TSourceLoc&, const char* const extension, const char* behavior);
virtual void fullIntegerCheck(const TSourceLoc&, const char* op);
virtual void unimplemented(const TSourceLoc&, const char* featureDesc);
virtual void doubleCheck(const TSourceLoc&, const char* op);
virtual void float16Check(const TSourceLoc&, const char* op, bool builtIn = false);
virtual void float16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false);
virtual bool float16Arithmetic();
virtual void requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc);
virtual void int16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false);
virtual bool int16Arithmetic();
virtual void requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc);
virtual void int8ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false);
virtual bool int8Arithmetic();
virtual void requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc);
virtual void float16OpaqueCheck(const TSourceLoc&, const char* op, bool builtIn = false);
virtual void int64Check(const TSourceLoc&, const char* op, bool builtIn = false);
virtual void explicitInt8Check(const TSourceLoc&, const char* op, bool builtIn = false);
virtual void explicitInt16Check(const TSourceLoc&, const char* op, bool builtIn = false);
virtual void explicitInt32Check(const TSourceLoc&, const char* op, bool builtIn = false);
virtual void explicitFloat32Check(const TSourceLoc&, const char* op, bool builtIn = false);
virtual void explicitFloat64Check(const TSourceLoc&, const char* op, bool builtIn = false);
virtual void fcoopmatCheckNV(const TSourceLoc&, const char* op, bool builtIn = false);
virtual void intcoopmatCheckNV(const TSourceLoc&, const char *op, bool builtIn = false);
virtual void coopmatCheck(const TSourceLoc&, const char* op, bool builtIn = false);
bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; }
bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; }
bool isForwardCompatible() const { return forwardCompatible; }
virtual void spvRemoved(const TSourceLoc&, const char* op);
virtual void vulkanRemoved(const TSourceLoc&, const char* op);
virtual void requireVulkan(const TSourceLoc&, const char* op);
virtual void requireSpv(const TSourceLoc&, const char* op);
virtual void requireSpv(const TSourceLoc&, const char *op, unsigned int version);
virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) = 0;
virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) = 0;
virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) = 0;
virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) = 0;
void addError() { ++numErrors; }
int getNumErrors() const { return numErrors; }
void setScanner(TInputScanner* scanner) { currentScanner = scanner; }
TInputScanner* getScanner() const { return currentScanner; }
const TSourceLoc& getCurrentLoc() const { return currentScanner->getSourceLoc(); }
void setCurrentLine(int line) { currentScanner->setLine(line); }
void setCurrentColumn(int col) { currentScanner->setColumn(col); }
void setCurrentSourceName(const char* name) { currentScanner->setFile(name); }
void setCurrentString(int string) { currentScanner->setString(string); }
void getPreamble(std::string&);
#ifdef ENABLE_HLSL
bool isReadingHLSL() const { return (messages & EShMsgReadHlsl) == EShMsgReadHlsl; }
bool hlslEnable16BitTypes() const { return (messages & EShMsgHlslEnable16BitTypes) != 0; }
bool hlslDX9Compatible() const { return (messages & EShMsgHlslDX9Compatible) != 0; }
#else
bool isReadingHLSL() const { return false; }
#endif
TInfoSink& infoSink;
// compilation mode
int version; // version, updated by #version in the shader
EShLanguage language; // really the stage
SpvVersion spvVersion;
TIntermediate& intermediate; // helper for making and hooking up pieces of the parse tree
protected:
TMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is
TMap<TString, unsigned int> extensionMinSpv; // for each extension string, store minimum spirv required
TVector<TString> spvUnsupportedExt; // for extensions reserved for spv usage.
EShMessages messages; // errors/warnings/rule-sets
int numErrors; // number of compile-time errors encountered
TInputScanner* currentScanner;
private:
explicit TParseVersions(const TParseVersions&);
TParseVersions& operator=(const TParseVersions&);
};
} // end namespace glslang
#endif // _PARSE_VERSIONS_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/SpirvIntrinsics.cpp | //
// Copyright(C) 2021 Advanced Micro Devices, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// GL_EXT_spirv_intrinsics
//
#include "../Include/intermediate.h"
#include "../Include/SpirvIntrinsics.h"
#include "../Include/Types.h"
#include "ParseHelper.h"
namespace glslang {
bool TSpirvTypeParameter::operator==(const TSpirvTypeParameter& rhs) const
{
if (getAsConstant() != nullptr)
return getAsConstant()->getConstArray() == rhs.getAsConstant()->getConstArray();
assert(getAsType() != nullptr);
return *getAsType() == *rhs.getAsType();
}
//
// Handle SPIR-V requirements
//
TSpirvRequirement* TParseContext::makeSpirvRequirement(const TSourceLoc& loc, const TString& name,
const TIntermAggregate* extensions,
const TIntermAggregate* capabilities)
{
TSpirvRequirement* spirvReq = new TSpirvRequirement;
if (name == "extensions") {
assert(extensions);
for (auto extension : extensions->getSequence()) {
assert(extension->getAsConstantUnion());
spirvReq->extensions.insert(*extension->getAsConstantUnion()->getConstArray()[0].getSConst());
}
} else if (name == "capabilities") {
assert(capabilities);
for (auto capability : capabilities->getSequence()) {
assert(capability->getAsConstantUnion());
spirvReq->capabilities.insert(capability->getAsConstantUnion()->getConstArray()[0].getIConst());
}
} else
error(loc, "unknown SPIR-V requirement", name.c_str(), "");
return spirvReq;
}
TSpirvRequirement* TParseContext::mergeSpirvRequirements(const TSourceLoc& loc, TSpirvRequirement* spirvReq1,
TSpirvRequirement* spirvReq2)
{
// Merge the second SPIR-V requirement to the first one
if (!spirvReq2->extensions.empty()) {
if (spirvReq1->extensions.empty())
spirvReq1->extensions = spirvReq2->extensions;
else
error(loc, "too many SPIR-V requirements", "extensions", "");
}
if (!spirvReq2->capabilities.empty()) {
if (spirvReq1->capabilities.empty())
spirvReq1->capabilities = spirvReq2->capabilities;
else
error(loc, "too many SPIR-V requirements", "capabilities", "");
}
return spirvReq1;
}
void TIntermediate::insertSpirvRequirement(const TSpirvRequirement* spirvReq)
{
if (!spirvRequirement)
spirvRequirement = new TSpirvRequirement;
for (auto extension : spirvReq->extensions)
spirvRequirement->extensions.insert(extension);
for (auto capability : spirvReq->capabilities)
spirvRequirement->capabilities.insert(capability);
}
//
// Handle SPIR-V execution modes
//
void TIntermediate::insertSpirvExecutionMode(int executionMode, const TIntermAggregate* args)
{
if (!spirvExecutionMode)
spirvExecutionMode = new TSpirvExecutionMode;
TVector<const TIntermConstantUnion*> extraOperands;
if (args) {
for (auto arg : args->getSequence()) {
auto extraOperand = arg->getAsConstantUnion();
assert(extraOperand != nullptr);
extraOperands.push_back(extraOperand);
}
}
spirvExecutionMode->modes[executionMode] = extraOperands;
}
void TIntermediate::insertSpirvExecutionModeId(int executionMode, const TIntermAggregate* args)
{
if (!spirvExecutionMode)
spirvExecutionMode = new TSpirvExecutionMode;
assert(args);
TVector<const TIntermTyped*> extraOperands;
for (auto arg : args->getSequence()) {
auto extraOperand = arg->getAsTyped();
assert(extraOperand != nullptr && extraOperand->getQualifier().isConstant());
extraOperands.push_back(extraOperand);
}
spirvExecutionMode->modeIds[executionMode] = extraOperands;
}
//
// Handle SPIR-V decorate qualifiers
//
void TQualifier::setSpirvDecorate(int decoration, const TIntermAggregate* args)
{
if (!spirvDecorate)
spirvDecorate = new TSpirvDecorate;
TVector<const TIntermConstantUnion*> extraOperands;
if (args) {
for (auto arg : args->getSequence()) {
auto extraOperand = arg->getAsConstantUnion();
assert(extraOperand != nullptr);
extraOperands.push_back(extraOperand);
}
}
spirvDecorate->decorates[decoration] = extraOperands;
}
void TQualifier::setSpirvDecorateId(int decoration, const TIntermAggregate* args)
{
if (!spirvDecorate)
spirvDecorate = new TSpirvDecorate;
assert(args);
TVector<const TIntermTyped*> extraOperands;
for (auto arg : args->getSequence()) {
auto extraOperand = arg->getAsTyped();
assert(extraOperand != nullptr);
extraOperands.push_back(extraOperand);
}
spirvDecorate->decorateIds[decoration] = extraOperands;
}
void TQualifier::setSpirvDecorateString(int decoration, const TIntermAggregate* args)
{
if (!spirvDecorate)
spirvDecorate = new TSpirvDecorate;
assert(args);
TVector<const TIntermConstantUnion*> extraOperands;
for (auto arg : args->getSequence()) {
auto extraOperand = arg->getAsConstantUnion();
assert(extraOperand != nullptr);
extraOperands.push_back(extraOperand);
}
spirvDecorate->decorateStrings[decoration] = extraOperands;
}
TString TQualifier::getSpirvDecorateQualifierString() const
{
assert(spirvDecorate);
TString qualifierString;
const auto appendFloat = [&](float f) { qualifierString.append(std::to_string(f).c_str()); };
const auto appendInt = [&](int i) { qualifierString.append(std::to_string(i).c_str()); };
const auto appendUint = [&](unsigned int u) { qualifierString.append(std::to_string(u).c_str()); };
const auto appendBool = [&](bool b) { qualifierString.append(std::to_string(b).c_str()); };
const auto appendStr = [&](const char* s) { qualifierString.append(s); };
const auto appendDecorate = [&](const TIntermTyped* constant) {
if (constant->getAsConstantUnion()) {
auto& constArray = constant->getAsConstantUnion()->getConstArray();
if (constant->getBasicType() == EbtFloat) {
float value = static_cast<float>(constArray[0].getDConst());
appendFloat(value);
} else if (constant->getBasicType() == EbtInt) {
int value = constArray[0].getIConst();
appendInt(value);
} else if (constant->getBasicType() == EbtUint) {
unsigned value = constArray[0].getUConst();
appendUint(value);
} else if (constant->getBasicType() == EbtBool) {
bool value = constArray[0].getBConst();
appendBool(value);
} else if (constant->getBasicType() == EbtString) {
const TString* value = constArray[0].getSConst();
appendStr(value->c_str());
} else
assert(0);
} else {
assert(constant->getAsSymbolNode());
appendStr(constant->getAsSymbolNode()->getName().c_str());
}
};
for (auto& decorate : spirvDecorate->decorates) {
appendStr("spirv_decorate(");
appendInt(decorate.first);
for (auto extraOperand : decorate.second) {
appendStr(", ");
appendDecorate(extraOperand);
}
appendStr(") ");
}
for (auto& decorateId : spirvDecorate->decorateIds) {
appendStr("spirv_decorate_id(");
appendInt(decorateId.first);
for (auto extraOperand : decorateId.second) {
appendStr(", ");
appendDecorate(extraOperand);
}
appendStr(") ");
}
for (auto& decorateString : spirvDecorate->decorateStrings) {
appendStr("spirv_decorate_string(");
appendInt(decorateString.first);
for (auto extraOperand : decorateString.second) {
appendStr(", ");
appendDecorate(extraOperand);
}
appendStr(") ");
}
return qualifierString;
}
//
// Handle SPIR-V type specifiers
//
void TPublicType::setSpirvType(const TSpirvInstruction& spirvInst, const TSpirvTypeParameters* typeParams)
{
if (!spirvType)
spirvType = new TSpirvType;
basicType = EbtSpirvType;
spirvType->spirvInst = spirvInst;
if (typeParams)
spirvType->typeParams = *typeParams;
}
TSpirvTypeParameters* TParseContext::makeSpirvTypeParameters(const TSourceLoc& loc, const TIntermConstantUnion* constant)
{
TSpirvTypeParameters* spirvTypeParams = new TSpirvTypeParameters;
if (constant->getBasicType() != EbtFloat &&
constant->getBasicType() != EbtInt &&
constant->getBasicType() != EbtUint &&
constant->getBasicType() != EbtBool &&
constant->getBasicType() != EbtString)
error(loc, "this type not allowed", constant->getType().getBasicString(), "");
else
spirvTypeParams->push_back(TSpirvTypeParameter(constant));
return spirvTypeParams;
}
TSpirvTypeParameters* TParseContext::makeSpirvTypeParameters(const TSourceLoc& /* loc */,
const TPublicType& type)
{
TSpirvTypeParameters* spirvTypeParams = new TSpirvTypeParameters;
spirvTypeParams->push_back(TSpirvTypeParameter(new TType(type)));
return spirvTypeParams;
}
TSpirvTypeParameters* TParseContext::mergeSpirvTypeParameters(TSpirvTypeParameters* spirvTypeParams1, TSpirvTypeParameters* spirvTypeParams2)
{
// Merge SPIR-V type parameters of the second one to the first one
for (const auto& spirvTypeParam : *spirvTypeParams2)
spirvTypeParams1->push_back(spirvTypeParam);
return spirvTypeParams1;
}
//
// Handle SPIR-V instruction qualifiers
//
TSpirvInstruction* TParseContext::makeSpirvInstruction(const TSourceLoc& loc, const TString& name, const TString& value)
{
TSpirvInstruction* spirvInst = new TSpirvInstruction;
if (name == "set")
spirvInst->set = value;
else
error(loc, "unknown SPIR-V instruction qualifier", name.c_str(), "");
return spirvInst;
}
TSpirvInstruction* TParseContext::makeSpirvInstruction(const TSourceLoc& loc, const TString& name, int value)
{
TSpirvInstruction* spirvInstuction = new TSpirvInstruction;
if (name == "id")
spirvInstuction->id = value;
else
error(loc, "unknown SPIR-V instruction qualifier", name.c_str(), "");
return spirvInstuction;
}
TSpirvInstruction* TParseContext::mergeSpirvInstruction(const TSourceLoc& loc, TSpirvInstruction* spirvInst1, TSpirvInstruction* spirvInst2)
{
// Merge qualifiers of the second SPIR-V instruction to those of the first one
if (!spirvInst2->set.empty()) {
if (spirvInst1->set.empty())
spirvInst1->set = spirvInst2->set;
else
error(loc, "too many SPIR-V instruction qualifiers", "spirv_instruction", "(set)");
}
if (spirvInst2->id != -1) {
if (spirvInst1->id == -1)
spirvInst1->id = spirvInst2->id;
else
error(loc, "too many SPIR-V instruction qualifiers", "spirv_instruction", "(id)");
}
return spirvInst1;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/IntermTraverse.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
// Copyright (c) 2002-2010 The ANGLE Project Authors.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "../Include/intermediate.h"
namespace glslang {
//
// Traverse the intermediate representation tree, and
// call a node type specific function for each node.
// Done recursively through the member function Traverse().
// Node types can be skipped if their function to call is 0,
// but their subtree will still be traversed.
// Nodes with children can have their whole subtree skipped
// if preVisit is turned on and the type specific function
// returns false.
//
// preVisit, postVisit, and rightToLeft control what order
// nodes are visited in.
//
//
// Traversal functions for terminals are straightforward....
//
void TIntermMethod::traverse(TIntermTraverser*)
{
// Tree should always resolve all methods as a non-method.
}
void TIntermSymbol::traverse(TIntermTraverser *it)
{
it->visitSymbol(this);
}
void TIntermConstantUnion::traverse(TIntermTraverser *it)
{
it->visitConstantUnion(this);
}
const TString& TIntermSymbol::getAccessName() const {
if (getBasicType() == EbtBlock)
return getType().getTypeName();
else
return getName();
}
//
// Traverse a binary node.
//
void TIntermBinary::traverse(TIntermTraverser *it)
{
bool visit = true;
//
// visit the node before children if pre-visiting.
//
if (it->preVisit)
visit = it->visitBinary(EvPreVisit, this);
//
// Visit the children, in the right order.
//
if (visit) {
it->incrementDepth(this);
if (it->rightToLeft) {
if (right)
right->traverse(it);
if (it->inVisit)
visit = it->visitBinary(EvInVisit, this);
if (visit && left)
left->traverse(it);
} else {
if (left)
left->traverse(it);
if (it->inVisit)
visit = it->visitBinary(EvInVisit, this);
if (visit && right)
right->traverse(it);
}
it->decrementDepth();
}
//
// Visit the node after the children, if requested and the traversal
// hasn't been canceled yet.
//
if (visit && it->postVisit)
it->visitBinary(EvPostVisit, this);
}
//
// Traverse a unary node. Same comments in binary node apply here.
//
void TIntermUnary::traverse(TIntermTraverser *it)
{
bool visit = true;
if (it->preVisit)
visit = it->visitUnary(EvPreVisit, this);
if (visit) {
it->incrementDepth(this);
operand->traverse(it);
it->decrementDepth();
}
if (visit && it->postVisit)
it->visitUnary(EvPostVisit, this);
}
//
// Traverse an aggregate node. Same comments in binary node apply here.
//
void TIntermAggregate::traverse(TIntermTraverser *it)
{
bool visit = true;
if (it->preVisit)
visit = it->visitAggregate(EvPreVisit, this);
if (visit) {
it->incrementDepth(this);
if (it->rightToLeft) {
for (TIntermSequence::reverse_iterator sit = sequence.rbegin(); sit != sequence.rend(); sit++) {
(*sit)->traverse(it);
if (visit && it->inVisit) {
if (*sit != sequence.front())
visit = it->visitAggregate(EvInVisit, this);
}
}
} else {
for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++) {
(*sit)->traverse(it);
if (visit && it->inVisit) {
if (*sit != sequence.back())
visit = it->visitAggregate(EvInVisit, this);
}
}
}
it->decrementDepth();
}
if (visit && it->postVisit)
it->visitAggregate(EvPostVisit, this);
}
//
// Traverse a selection node. Same comments in binary node apply here.
//
void TIntermSelection::traverse(TIntermTraverser *it)
{
bool visit = true;
if (it->preVisit)
visit = it->visitSelection(EvPreVisit, this);
if (visit) {
it->incrementDepth(this);
if (it->rightToLeft) {
if (falseBlock)
falseBlock->traverse(it);
if (trueBlock)
trueBlock->traverse(it);
condition->traverse(it);
} else {
condition->traverse(it);
if (trueBlock)
trueBlock->traverse(it);
if (falseBlock)
falseBlock->traverse(it);
}
it->decrementDepth();
}
if (visit && it->postVisit)
it->visitSelection(EvPostVisit, this);
}
//
// Traverse a loop node. Same comments in binary node apply here.
//
void TIntermLoop::traverse(TIntermTraverser *it)
{
bool visit = true;
if (it->preVisit)
visit = it->visitLoop(EvPreVisit, this);
if (visit) {
it->incrementDepth(this);
if (it->rightToLeft) {
if (terminal)
terminal->traverse(it);
if (body)
body->traverse(it);
if (test)
test->traverse(it);
} else {
if (test)
test->traverse(it);
if (body)
body->traverse(it);
if (terminal)
terminal->traverse(it);
}
it->decrementDepth();
}
if (visit && it->postVisit)
it->visitLoop(EvPostVisit, this);
}
//
// Traverse a branch node. Same comments in binary node apply here.
//
void TIntermBranch::traverse(TIntermTraverser *it)
{
bool visit = true;
if (it->preVisit)
visit = it->visitBranch(EvPreVisit, this);
if (visit && expression) {
it->incrementDepth(this);
expression->traverse(it);
it->decrementDepth();
}
if (visit && it->postVisit)
it->visitBranch(EvPostVisit, this);
}
//
// Traverse a switch node.
//
void TIntermSwitch::traverse(TIntermTraverser* it)
{
bool visit = true;
if (it->preVisit)
visit = it->visitSwitch(EvPreVisit, this);
if (visit) {
it->incrementDepth(this);
if (it->rightToLeft) {
body->traverse(it);
condition->traverse(it);
} else {
condition->traverse(it);
body->traverse(it);
}
it->decrementDepth();
}
if (visit && it->postVisit)
it->visitSwitch(EvPostVisit, this);
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/Scan.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
// Copyright (C) 2017 ARM Limited.
// Copyright (C) 2020 Google, Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// GLSL scanning, leveraging the scanning done by the preprocessor.
//
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include "../Include/Types.h"
#include "SymbolTable.h"
#include "ParseHelper.h"
#include "attribute.h"
#include "glslang_tab.cpp.h"
#include "ScanContext.h"
#include "Scan.h"
// preprocessor includes
#include "preprocessor/PpContext.h"
#include "preprocessor/PpTokens.h"
// Required to avoid missing prototype warnings for some compilers
int yylex(YYSTYPE*, glslang::TParseContext&);
namespace glslang {
// read past any white space
void TInputScanner::consumeWhiteSpace(bool& foundNonSpaceTab)
{
int c = peek(); // don't accidentally consume anything other than whitespace
while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
if (c == '\r' || c == '\n')
foundNonSpaceTab = true;
get();
c = peek();
}
}
// return true if a comment was actually consumed
bool TInputScanner::consumeComment()
{
if (peek() != '/')
return false;
get(); // consume the '/'
int c = peek();
if (c == '/') {
// a '//' style comment
get(); // consume the second '/'
c = get();
do {
while (c != EndOfInput && c != '\\' && c != '\r' && c != '\n')
c = get();
if (c == EndOfInput || c == '\r' || c == '\n') {
while (c == '\r' || c == '\n')
c = get();
// we reached the end of the comment
break;
} else {
// it's a '\', so we need to keep going, after skipping what's escaped
// read the skipped character
c = get();
// if it's a two-character newline, skip both characters
if (c == '\r' && peek() == '\n')
get();
c = get();
}
} while (true);
// put back the last non-comment character
if (c != EndOfInput)
unget();
return true;
} else if (c == '*') {
// a '/*' style comment
get(); // consume the '*'
c = get();
do {
while (c != EndOfInput && c != '*')
c = get();
if (c == '*') {
c = get();
if (c == '/')
break; // end of comment
// not end of comment
} else // end of input
break;
} while (true);
return true;
} else {
// it's not a comment, put the '/' back
unget();
return false;
}
}
// skip whitespace, then skip a comment, rinse, repeat
void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab)
{
do {
consumeWhiteSpace(foundNonSpaceTab);
// if not starting a comment now, then done
int c = peek();
if (c != '/' || c == EndOfInput)
return;
// skip potential comment
foundNonSpaceTab = true;
if (! consumeComment())
return;
} while (true);
}
// Returns true if there was non-white space (e.g., a comment, newline) before the #version
// or no #version was found; otherwise, returns false. There is no error case, it always
// succeeds, but will leave version == 0 if no #version was found.
//
// Sets notFirstToken based on whether tokens (beyond white space and comments)
// appeared before the #version.
//
// N.B. does not attempt to leave input in any particular known state. The assumption
// is that scanning will start anew, following the rules for the chosen version/profile,
// and with a corresponding parsing context.
//
bool TInputScanner::scanVersion(int& version, EProfile& profile, bool& notFirstToken)
{
// This function doesn't have to get all the semantics correct,
// just find the #version if there is a correct one present.
// The preprocessor will have the responsibility of getting all the semantics right.
bool versionNotFirst = false; // means not first WRT comments and white space, nothing more
notFirstToken = false; // means not first WRT to real tokens
version = 0; // means not found
profile = ENoProfile;
bool foundNonSpaceTab = false;
bool lookingInMiddle = false;
int c;
do {
if (lookingInMiddle) {
notFirstToken = true;
// make forward progress by finishing off the current line plus extra new lines
if (peek() != '\n' && peek() != '\r') {
do {
c = get();
} while (c != EndOfInput && c != '\n' && c != '\r');
}
while (peek() == '\n' || peek() == '\r')
get();
if (peek() == EndOfInput)
return true;
}
lookingInMiddle = true;
// Nominal start, skipping the desktop allowed comments and white space, but tracking if
// something else was found for ES:
consumeWhitespaceComment(foundNonSpaceTab);
if (foundNonSpaceTab)
versionNotFirst = true;
// "#"
if (get() != '#') {
versionNotFirst = true;
continue;
}
// whitespace
do {
c = get();
} while (c == ' ' || c == '\t');
// "version"
if ( c != 'v' ||
get() != 'e' ||
get() != 'r' ||
get() != 's' ||
get() != 'i' ||
get() != 'o' ||
get() != 'n') {
versionNotFirst = true;
continue;
}
// whitespace
do {
c = get();
} while (c == ' ' || c == '\t');
// version number
while (c >= '0' && c <= '9') {
version = 10 * version + (c - '0');
c = get();
}
if (version == 0) {
versionNotFirst = true;
continue;
}
// whitespace
while (c == ' ' || c == '\t')
c = get();
// profile
const int maxProfileLength = 13; // not including any 0
char profileString[maxProfileLength];
int profileLength;
for (profileLength = 0; profileLength < maxProfileLength; ++profileLength) {
if (c == EndOfInput || c == ' ' || c == '\t' || c == '\n' || c == '\r')
break;
profileString[profileLength] = (char)c;
c = get();
}
if (c != EndOfInput && c != ' ' && c != '\t' && c != '\n' && c != '\r') {
versionNotFirst = true;
continue;
}
if (profileLength == 2 && strncmp(profileString, "es", profileLength) == 0)
profile = EEsProfile;
else if (profileLength == 4 && strncmp(profileString, "core", profileLength) == 0)
profile = ECoreProfile;
else if (profileLength == 13 && strncmp(profileString, "compatibility", profileLength) == 0)
profile = ECompatibilityProfile;
return versionNotFirst;
} while (true);
}
// Fill this in when doing glslang-level scanning, to hand back to the parser.
class TParserToken {
public:
explicit TParserToken(YYSTYPE& b) : sType(b) { }
YYSTYPE& sType;
protected:
TParserToken(TParserToken&);
TParserToken& operator=(TParserToken&);
};
} // end namespace glslang
// This is the function the glslang parser (i.e., bison) calls to get its next token
int yylex(YYSTYPE* glslangTokenDesc, glslang::TParseContext& parseContext)
{
glslang::TParserToken token(*glslangTokenDesc);
return parseContext.getScanContext()->tokenize(parseContext.getPpContext(), token);
}
namespace {
struct str_eq
{
bool operator()(const char* lhs, const char* rhs) const
{
return strcmp(lhs, rhs) == 0;
}
};
struct str_hash
{
size_t operator()(const char* str) const
{
// djb2
unsigned long hash = 5381;
int c;
while ((c = *str++) != 0)
hash = ((hash << 5) + hash) + c;
return hash;
}
};
// A single global usable by all threads, by all versions, by all languages.
// After a single process-level initialization, this is read only and thread safe
std::unordered_map<const char*, int, str_hash, str_eq>* KeywordMap = nullptr;
std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = nullptr;
}
namespace glslang {
void TScanContext::fillInKeywordMap()
{
if (KeywordMap != nullptr) {
// this is really an error, as this should called only once per process
// but, the only risk is if two threads called simultaneously
return;
}
KeywordMap = new std::unordered_map<const char*, int, str_hash, str_eq>;
(*KeywordMap)["const"] = CONST;
(*KeywordMap)["uniform"] = UNIFORM;
(*KeywordMap)["tileImageEXT"] = TILEIMAGEEXT;
(*KeywordMap)["buffer"] = BUFFER;
(*KeywordMap)["in"] = IN;
(*KeywordMap)["out"] = OUT;
(*KeywordMap)["smooth"] = SMOOTH;
(*KeywordMap)["flat"] = FLAT;
(*KeywordMap)["centroid"] = CENTROID;
(*KeywordMap)["invariant"] = INVARIANT;
(*KeywordMap)["packed"] = PACKED;
(*KeywordMap)["resource"] = RESOURCE;
(*KeywordMap)["inout"] = INOUT;
(*KeywordMap)["struct"] = STRUCT;
(*KeywordMap)["break"] = BREAK;
(*KeywordMap)["continue"] = CONTINUE;
(*KeywordMap)["do"] = DO;
(*KeywordMap)["for"] = FOR;
(*KeywordMap)["while"] = WHILE;
(*KeywordMap)["switch"] = SWITCH;
(*KeywordMap)["case"] = CASE;
(*KeywordMap)["default"] = DEFAULT;
(*KeywordMap)["if"] = IF;
(*KeywordMap)["else"] = ELSE;
(*KeywordMap)["discard"] = DISCARD;
(*KeywordMap)["terminateInvocation"] = TERMINATE_INVOCATION;
(*KeywordMap)["terminateRayEXT"] = TERMINATE_RAY;
(*KeywordMap)["ignoreIntersectionEXT"] = IGNORE_INTERSECTION;
(*KeywordMap)["return"] = RETURN;
(*KeywordMap)["void"] = VOID;
(*KeywordMap)["bool"] = BOOL;
(*KeywordMap)["float"] = FLOAT;
(*KeywordMap)["int"] = INT;
(*KeywordMap)["bvec2"] = BVEC2;
(*KeywordMap)["bvec3"] = BVEC3;
(*KeywordMap)["bvec4"] = BVEC4;
(*KeywordMap)["vec2"] = VEC2;
(*KeywordMap)["vec3"] = VEC3;
(*KeywordMap)["vec4"] = VEC4;
(*KeywordMap)["ivec2"] = IVEC2;
(*KeywordMap)["ivec3"] = IVEC3;
(*KeywordMap)["ivec4"] = IVEC4;
(*KeywordMap)["mat2"] = MAT2;
(*KeywordMap)["mat3"] = MAT3;
(*KeywordMap)["mat4"] = MAT4;
(*KeywordMap)["true"] = BOOLCONSTANT;
(*KeywordMap)["false"] = BOOLCONSTANT;
(*KeywordMap)["layout"] = LAYOUT;
(*KeywordMap)["shared"] = SHARED;
(*KeywordMap)["highp"] = HIGH_PRECISION;
(*KeywordMap)["mediump"] = MEDIUM_PRECISION;
(*KeywordMap)["lowp"] = LOW_PRECISION;
(*KeywordMap)["superp"] = SUPERP;
(*KeywordMap)["precision"] = PRECISION;
(*KeywordMap)["mat2x2"] = MAT2X2;
(*KeywordMap)["mat2x3"] = MAT2X3;
(*KeywordMap)["mat2x4"] = MAT2X4;
(*KeywordMap)["mat3x2"] = MAT3X2;
(*KeywordMap)["mat3x3"] = MAT3X3;
(*KeywordMap)["mat3x4"] = MAT3X4;
(*KeywordMap)["mat4x2"] = MAT4X2;
(*KeywordMap)["mat4x3"] = MAT4X3;
(*KeywordMap)["mat4x4"] = MAT4X4;
(*KeywordMap)["uint"] = UINT;
(*KeywordMap)["uvec2"] = UVEC2;
(*KeywordMap)["uvec3"] = UVEC3;
(*KeywordMap)["uvec4"] = UVEC4;
(*KeywordMap)["nonuniformEXT"] = NONUNIFORM;
(*KeywordMap)["demote"] = DEMOTE;
(*KeywordMap)["attribute"] = ATTRIBUTE;
(*KeywordMap)["varying"] = VARYING;
(*KeywordMap)["noperspective"] = NOPERSPECTIVE;
(*KeywordMap)["coherent"] = COHERENT;
(*KeywordMap)["devicecoherent"] = DEVICECOHERENT;
(*KeywordMap)["queuefamilycoherent"] = QUEUEFAMILYCOHERENT;
(*KeywordMap)["workgroupcoherent"] = WORKGROUPCOHERENT;
(*KeywordMap)["subgroupcoherent"] = SUBGROUPCOHERENT;
(*KeywordMap)["shadercallcoherent"] = SHADERCALLCOHERENT;
(*KeywordMap)["nonprivate"] = NONPRIVATE;
(*KeywordMap)["restrict"] = RESTRICT;
(*KeywordMap)["readonly"] = READONLY;
(*KeywordMap)["writeonly"] = WRITEONLY;
(*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
(*KeywordMap)["volatile"] = VOLATILE;
(*KeywordMap)["patch"] = PATCH;
(*KeywordMap)["sample"] = SAMPLE;
(*KeywordMap)["subroutine"] = SUBROUTINE;
(*KeywordMap)["dmat2"] = DMAT2;
(*KeywordMap)["dmat3"] = DMAT3;
(*KeywordMap)["dmat4"] = DMAT4;
(*KeywordMap)["dmat2x2"] = DMAT2X2;
(*KeywordMap)["dmat2x3"] = DMAT2X3;
(*KeywordMap)["dmat2x4"] = DMAT2X4;
(*KeywordMap)["dmat3x2"] = DMAT3X2;
(*KeywordMap)["dmat3x3"] = DMAT3X3;
(*KeywordMap)["dmat3x4"] = DMAT3X4;
(*KeywordMap)["dmat4x2"] = DMAT4X2;
(*KeywordMap)["dmat4x3"] = DMAT4X3;
(*KeywordMap)["dmat4x4"] = DMAT4X4;
(*KeywordMap)["image1D"] = IMAGE1D;
(*KeywordMap)["iimage1D"] = IIMAGE1D;
(*KeywordMap)["uimage1D"] = UIMAGE1D;
(*KeywordMap)["image2D"] = IMAGE2D;
(*KeywordMap)["iimage2D"] = IIMAGE2D;
(*KeywordMap)["uimage2D"] = UIMAGE2D;
(*KeywordMap)["image3D"] = IMAGE3D;
(*KeywordMap)["iimage3D"] = IIMAGE3D;
(*KeywordMap)["uimage3D"] = UIMAGE3D;
(*KeywordMap)["image2DRect"] = IMAGE2DRECT;
(*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
(*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
(*KeywordMap)["imageCube"] = IMAGECUBE;
(*KeywordMap)["iimageCube"] = IIMAGECUBE;
(*KeywordMap)["uimageCube"] = UIMAGECUBE;
(*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
(*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
(*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
(*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
(*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
(*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
(*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
(*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
(*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
(*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
(*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
(*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
(*KeywordMap)["image2DMS"] = IMAGE2DMS;
(*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
(*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
(*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
(*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
(*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
(*KeywordMap)["i64image1D"] = I64IMAGE1D;
(*KeywordMap)["u64image1D"] = U64IMAGE1D;
(*KeywordMap)["i64image2D"] = I64IMAGE2D;
(*KeywordMap)["u64image2D"] = U64IMAGE2D;
(*KeywordMap)["i64image3D"] = I64IMAGE3D;
(*KeywordMap)["u64image3D"] = U64IMAGE3D;
(*KeywordMap)["i64image2DRect"] = I64IMAGE2DRECT;
(*KeywordMap)["u64image2DRect"] = U64IMAGE2DRECT;
(*KeywordMap)["i64imageCube"] = I64IMAGECUBE;
(*KeywordMap)["u64imageCube"] = U64IMAGECUBE;
(*KeywordMap)["i64imageBuffer"] = I64IMAGEBUFFER;
(*KeywordMap)["u64imageBuffer"] = U64IMAGEBUFFER;
(*KeywordMap)["i64image1DArray"] = I64IMAGE1DARRAY;
(*KeywordMap)["u64image1DArray"] = U64IMAGE1DARRAY;
(*KeywordMap)["i64image2DArray"] = I64IMAGE2DARRAY;
(*KeywordMap)["u64image2DArray"] = U64IMAGE2DARRAY;
(*KeywordMap)["i64imageCubeArray"] = I64IMAGECUBEARRAY;
(*KeywordMap)["u64imageCubeArray"] = U64IMAGECUBEARRAY;
(*KeywordMap)["i64image2DMS"] = I64IMAGE2DMS;
(*KeywordMap)["u64image2DMS"] = U64IMAGE2DMS;
(*KeywordMap)["i64image2DMSArray"] = I64IMAGE2DMSARRAY;
(*KeywordMap)["u64image2DMSArray"] = U64IMAGE2DMSARRAY;
(*KeywordMap)["double"] = DOUBLE;
(*KeywordMap)["dvec2"] = DVEC2;
(*KeywordMap)["dvec3"] = DVEC3;
(*KeywordMap)["dvec4"] = DVEC4;
(*KeywordMap)["int64_t"] = INT64_T;
(*KeywordMap)["uint64_t"] = UINT64_T;
(*KeywordMap)["i64vec2"] = I64VEC2;
(*KeywordMap)["i64vec3"] = I64VEC3;
(*KeywordMap)["i64vec4"] = I64VEC4;
(*KeywordMap)["u64vec2"] = U64VEC2;
(*KeywordMap)["u64vec3"] = U64VEC3;
(*KeywordMap)["u64vec4"] = U64VEC4;
// GL_EXT_shader_explicit_arithmetic_types
(*KeywordMap)["int8_t"] = INT8_T;
(*KeywordMap)["i8vec2"] = I8VEC2;
(*KeywordMap)["i8vec3"] = I8VEC3;
(*KeywordMap)["i8vec4"] = I8VEC4;
(*KeywordMap)["uint8_t"] = UINT8_T;
(*KeywordMap)["u8vec2"] = U8VEC2;
(*KeywordMap)["u8vec3"] = U8VEC3;
(*KeywordMap)["u8vec4"] = U8VEC4;
(*KeywordMap)["int16_t"] = INT16_T;
(*KeywordMap)["i16vec2"] = I16VEC2;
(*KeywordMap)["i16vec3"] = I16VEC3;
(*KeywordMap)["i16vec4"] = I16VEC4;
(*KeywordMap)["uint16_t"] = UINT16_T;
(*KeywordMap)["u16vec2"] = U16VEC2;
(*KeywordMap)["u16vec3"] = U16VEC3;
(*KeywordMap)["u16vec4"] = U16VEC4;
(*KeywordMap)["int32_t"] = INT32_T;
(*KeywordMap)["i32vec2"] = I32VEC2;
(*KeywordMap)["i32vec3"] = I32VEC3;
(*KeywordMap)["i32vec4"] = I32VEC4;
(*KeywordMap)["uint32_t"] = UINT32_T;
(*KeywordMap)["u32vec2"] = U32VEC2;
(*KeywordMap)["u32vec3"] = U32VEC3;
(*KeywordMap)["u32vec4"] = U32VEC4;
(*KeywordMap)["float16_t"] = FLOAT16_T;
(*KeywordMap)["f16vec2"] = F16VEC2;
(*KeywordMap)["f16vec3"] = F16VEC3;
(*KeywordMap)["f16vec4"] = F16VEC4;
(*KeywordMap)["f16mat2"] = F16MAT2;
(*KeywordMap)["f16mat3"] = F16MAT3;
(*KeywordMap)["f16mat4"] = F16MAT4;
(*KeywordMap)["f16mat2x2"] = F16MAT2X2;
(*KeywordMap)["f16mat2x3"] = F16MAT2X3;
(*KeywordMap)["f16mat2x4"] = F16MAT2X4;
(*KeywordMap)["f16mat3x2"] = F16MAT3X2;
(*KeywordMap)["f16mat3x3"] = F16MAT3X3;
(*KeywordMap)["f16mat3x4"] = F16MAT3X4;
(*KeywordMap)["f16mat4x2"] = F16MAT4X2;
(*KeywordMap)["f16mat4x3"] = F16MAT4X3;
(*KeywordMap)["f16mat4x4"] = F16MAT4X4;
(*KeywordMap)["float32_t"] = FLOAT32_T;
(*KeywordMap)["f32vec2"] = F32VEC2;
(*KeywordMap)["f32vec3"] = F32VEC3;
(*KeywordMap)["f32vec4"] = F32VEC4;
(*KeywordMap)["f32mat2"] = F32MAT2;
(*KeywordMap)["f32mat3"] = F32MAT3;
(*KeywordMap)["f32mat4"] = F32MAT4;
(*KeywordMap)["f32mat2x2"] = F32MAT2X2;
(*KeywordMap)["f32mat2x3"] = F32MAT2X3;
(*KeywordMap)["f32mat2x4"] = F32MAT2X4;
(*KeywordMap)["f32mat3x2"] = F32MAT3X2;
(*KeywordMap)["f32mat3x3"] = F32MAT3X3;
(*KeywordMap)["f32mat3x4"] = F32MAT3X4;
(*KeywordMap)["f32mat4x2"] = F32MAT4X2;
(*KeywordMap)["f32mat4x3"] = F32MAT4X3;
(*KeywordMap)["f32mat4x4"] = F32MAT4X4;
(*KeywordMap)["float64_t"] = FLOAT64_T;
(*KeywordMap)["f64vec2"] = F64VEC2;
(*KeywordMap)["f64vec3"] = F64VEC3;
(*KeywordMap)["f64vec4"] = F64VEC4;
(*KeywordMap)["f64mat2"] = F64MAT2;
(*KeywordMap)["f64mat3"] = F64MAT3;
(*KeywordMap)["f64mat4"] = F64MAT4;
(*KeywordMap)["f64mat2x2"] = F64MAT2X2;
(*KeywordMap)["f64mat2x3"] = F64MAT2X3;
(*KeywordMap)["f64mat2x4"] = F64MAT2X4;
(*KeywordMap)["f64mat3x2"] = F64MAT3X2;
(*KeywordMap)["f64mat3x3"] = F64MAT3X3;
(*KeywordMap)["f64mat3x4"] = F64MAT3X4;
(*KeywordMap)["f64mat4x2"] = F64MAT4X2;
(*KeywordMap)["f64mat4x3"] = F64MAT4X3;
(*KeywordMap)["f64mat4x4"] = F64MAT4X4;
// GL_EXT_spirv_intrinsics
(*KeywordMap)["spirv_instruction"] = SPIRV_INSTRUCTION;
(*KeywordMap)["spirv_execution_mode"] = SPIRV_EXECUTION_MODE;
(*KeywordMap)["spirv_execution_mode_id"] = SPIRV_EXECUTION_MODE_ID;
(*KeywordMap)["spirv_decorate"] = SPIRV_DECORATE;
(*KeywordMap)["spirv_decorate_id"] = SPIRV_DECORATE_ID;
(*KeywordMap)["spirv_decorate_string"] = SPIRV_DECORATE_STRING;
(*KeywordMap)["spirv_type"] = SPIRV_TYPE;
(*KeywordMap)["spirv_storage_class"] = SPIRV_STORAGE_CLASS;
(*KeywordMap)["spirv_by_reference"] = SPIRV_BY_REFERENCE;
(*KeywordMap)["spirv_literal"] = SPIRV_LITERAL;
(*KeywordMap)["sampler2D"] = SAMPLER2D;
(*KeywordMap)["samplerCube"] = SAMPLERCUBE;
(*KeywordMap)["samplerCubeShadow"] = SAMPLERCUBESHADOW;
(*KeywordMap)["sampler2DArray"] = SAMPLER2DARRAY;
(*KeywordMap)["sampler2DArrayShadow"] = SAMPLER2DARRAYSHADOW;
(*KeywordMap)["isampler2D"] = ISAMPLER2D;
(*KeywordMap)["isampler3D"] = ISAMPLER3D;
(*KeywordMap)["isamplerCube"] = ISAMPLERCUBE;
(*KeywordMap)["isampler2DArray"] = ISAMPLER2DARRAY;
(*KeywordMap)["usampler2D"] = USAMPLER2D;
(*KeywordMap)["usampler3D"] = USAMPLER3D;
(*KeywordMap)["usamplerCube"] = USAMPLERCUBE;
(*KeywordMap)["usampler2DArray"] = USAMPLER2DARRAY;
(*KeywordMap)["sampler3D"] = SAMPLER3D;
(*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
(*KeywordMap)["texture2D"] = TEXTURE2D;
(*KeywordMap)["textureCube"] = TEXTURECUBE;
(*KeywordMap)["texture2DArray"] = TEXTURE2DARRAY;
(*KeywordMap)["itexture2D"] = ITEXTURE2D;
(*KeywordMap)["itexture3D"] = ITEXTURE3D;
(*KeywordMap)["itextureCube"] = ITEXTURECUBE;
(*KeywordMap)["itexture2DArray"] = ITEXTURE2DARRAY;
(*KeywordMap)["utexture2D"] = UTEXTURE2D;
(*KeywordMap)["utexture3D"] = UTEXTURE3D;
(*KeywordMap)["utextureCube"] = UTEXTURECUBE;
(*KeywordMap)["utexture2DArray"] = UTEXTURE2DARRAY;
(*KeywordMap)["texture3D"] = TEXTURE3D;
(*KeywordMap)["sampler"] = SAMPLER;
(*KeywordMap)["samplerShadow"] = SAMPLERSHADOW;
(*KeywordMap)["textureCubeArray"] = TEXTURECUBEARRAY;
(*KeywordMap)["itextureCubeArray"] = ITEXTURECUBEARRAY;
(*KeywordMap)["utextureCubeArray"] = UTEXTURECUBEARRAY;
(*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
(*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
(*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
(*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
(*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
(*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
(*KeywordMap)["usampler1D"] = USAMPLER1D;
(*KeywordMap)["isampler1D"] = ISAMPLER1D;
(*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
(*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
(*KeywordMap)["isampler2DRect"] = ISAMPLER2DRECT;
(*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
(*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
(*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
(*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
(*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
(*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
(*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
(*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
(*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
(*KeywordMap)["sampler1D"] = SAMPLER1D;
(*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
(*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
(*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
(*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
(*KeywordMap)["samplerExternalOES"] = SAMPLEREXTERNALOES; // GL_OES_EGL_image_external
(*KeywordMap)["__samplerExternal2DY2YEXT"] = SAMPLEREXTERNAL2DY2YEXT; // GL_EXT_YUV_target
(*KeywordMap)["itexture1DArray"] = ITEXTURE1DARRAY;
(*KeywordMap)["utexture1D"] = UTEXTURE1D;
(*KeywordMap)["itexture1D"] = ITEXTURE1D;
(*KeywordMap)["utexture1DArray"] = UTEXTURE1DARRAY;
(*KeywordMap)["textureBuffer"] = TEXTUREBUFFER;
(*KeywordMap)["itexture2DRect"] = ITEXTURE2DRECT;
(*KeywordMap)["utexture2DRect"] = UTEXTURE2DRECT;
(*KeywordMap)["itextureBuffer"] = ITEXTUREBUFFER;
(*KeywordMap)["utextureBuffer"] = UTEXTUREBUFFER;
(*KeywordMap)["texture2DMS"] = TEXTURE2DMS;
(*KeywordMap)["itexture2DMS"] = ITEXTURE2DMS;
(*KeywordMap)["utexture2DMS"] = UTEXTURE2DMS;
(*KeywordMap)["texture2DMSArray"] = TEXTURE2DMSARRAY;
(*KeywordMap)["itexture2DMSArray"] = ITEXTURE2DMSARRAY;
(*KeywordMap)["utexture2DMSArray"] = UTEXTURE2DMSARRAY;
(*KeywordMap)["texture1D"] = TEXTURE1D;
(*KeywordMap)["texture2DRect"] = TEXTURE2DRECT;
(*KeywordMap)["texture1DArray"] = TEXTURE1DARRAY;
(*KeywordMap)["attachmentEXT"] = ATTACHMENTEXT;
(*KeywordMap)["iattachmentEXT"] = IATTACHMENTEXT;
(*KeywordMap)["uattachmentEXT"] = UATTACHMENTEXT;
(*KeywordMap)["subpassInput"] = SUBPASSINPUT;
(*KeywordMap)["subpassInputMS"] = SUBPASSINPUTMS;
(*KeywordMap)["isubpassInput"] = ISUBPASSINPUT;
(*KeywordMap)["isubpassInputMS"] = ISUBPASSINPUTMS;
(*KeywordMap)["usubpassInput"] = USUBPASSINPUT;
(*KeywordMap)["usubpassInputMS"] = USUBPASSINPUTMS;
(*KeywordMap)["f16sampler1D"] = F16SAMPLER1D;
(*KeywordMap)["f16sampler2D"] = F16SAMPLER2D;
(*KeywordMap)["f16sampler3D"] = F16SAMPLER3D;
(*KeywordMap)["f16sampler2DRect"] = F16SAMPLER2DRECT;
(*KeywordMap)["f16samplerCube"] = F16SAMPLERCUBE;
(*KeywordMap)["f16sampler1DArray"] = F16SAMPLER1DARRAY;
(*KeywordMap)["f16sampler2DArray"] = F16SAMPLER2DARRAY;
(*KeywordMap)["f16samplerCubeArray"] = F16SAMPLERCUBEARRAY;
(*KeywordMap)["f16samplerBuffer"] = F16SAMPLERBUFFER;
(*KeywordMap)["f16sampler2DMS"] = F16SAMPLER2DMS;
(*KeywordMap)["f16sampler2DMSArray"] = F16SAMPLER2DMSARRAY;
(*KeywordMap)["f16sampler1DShadow"] = F16SAMPLER1DSHADOW;
(*KeywordMap)["f16sampler2DShadow"] = F16SAMPLER2DSHADOW;
(*KeywordMap)["f16sampler2DRectShadow"] = F16SAMPLER2DRECTSHADOW;
(*KeywordMap)["f16samplerCubeShadow"] = F16SAMPLERCUBESHADOW;
(*KeywordMap)["f16sampler1DArrayShadow"] = F16SAMPLER1DARRAYSHADOW;
(*KeywordMap)["f16sampler2DArrayShadow"] = F16SAMPLER2DARRAYSHADOW;
(*KeywordMap)["f16samplerCubeArrayShadow"] = F16SAMPLERCUBEARRAYSHADOW;
(*KeywordMap)["f16image1D"] = F16IMAGE1D;
(*KeywordMap)["f16image2D"] = F16IMAGE2D;
(*KeywordMap)["f16image3D"] = F16IMAGE3D;
(*KeywordMap)["f16image2DRect"] = F16IMAGE2DRECT;
(*KeywordMap)["f16imageCube"] = F16IMAGECUBE;
(*KeywordMap)["f16image1DArray"] = F16IMAGE1DARRAY;
(*KeywordMap)["f16image2DArray"] = F16IMAGE2DARRAY;
(*KeywordMap)["f16imageCubeArray"] = F16IMAGECUBEARRAY;
(*KeywordMap)["f16imageBuffer"] = F16IMAGEBUFFER;
(*KeywordMap)["f16image2DMS"] = F16IMAGE2DMS;
(*KeywordMap)["f16image2DMSArray"] = F16IMAGE2DMSARRAY;
(*KeywordMap)["f16texture1D"] = F16TEXTURE1D;
(*KeywordMap)["f16texture2D"] = F16TEXTURE2D;
(*KeywordMap)["f16texture3D"] = F16TEXTURE3D;
(*KeywordMap)["f16texture2DRect"] = F16TEXTURE2DRECT;
(*KeywordMap)["f16textureCube"] = F16TEXTURECUBE;
(*KeywordMap)["f16texture1DArray"] = F16TEXTURE1DARRAY;
(*KeywordMap)["f16texture2DArray"] = F16TEXTURE2DARRAY;
(*KeywordMap)["f16textureCubeArray"] = F16TEXTURECUBEARRAY;
(*KeywordMap)["f16textureBuffer"] = F16TEXTUREBUFFER;
(*KeywordMap)["f16texture2DMS"] = F16TEXTURE2DMS;
(*KeywordMap)["f16texture2DMSArray"] = F16TEXTURE2DMSARRAY;
(*KeywordMap)["f16subpassInput"] = F16SUBPASSINPUT;
(*KeywordMap)["f16subpassInputMS"] = F16SUBPASSINPUTMS;
(*KeywordMap)["__explicitInterpAMD"] = EXPLICITINTERPAMD;
(*KeywordMap)["pervertexNV"] = PERVERTEXNV;
(*KeywordMap)["pervertexEXT"] = PERVERTEXEXT;
(*KeywordMap)["precise"] = PRECISE;
(*KeywordMap)["rayPayloadNV"] = PAYLOADNV;
(*KeywordMap)["rayPayloadEXT"] = PAYLOADEXT;
(*KeywordMap)["rayPayloadInNV"] = PAYLOADINNV;
(*KeywordMap)["rayPayloadInEXT"] = PAYLOADINEXT;
(*KeywordMap)["hitAttributeNV"] = HITATTRNV;
(*KeywordMap)["hitAttributeEXT"] = HITATTREXT;
(*KeywordMap)["callableDataNV"] = CALLDATANV;
(*KeywordMap)["callableDataEXT"] = CALLDATAEXT;
(*KeywordMap)["callableDataInNV"] = CALLDATAINNV;
(*KeywordMap)["callableDataInEXT"] = CALLDATAINEXT;
(*KeywordMap)["accelerationStructureNV"] = ACCSTRUCTNV;
(*KeywordMap)["accelerationStructureEXT"] = ACCSTRUCTEXT;
(*KeywordMap)["rayQueryEXT"] = RAYQUERYEXT;
(*KeywordMap)["perprimitiveNV"] = PERPRIMITIVENV;
(*KeywordMap)["perviewNV"] = PERVIEWNV;
(*KeywordMap)["taskNV"] = PERTASKNV;
(*KeywordMap)["perprimitiveEXT"] = PERPRIMITIVEEXT;
(*KeywordMap)["taskPayloadSharedEXT"] = TASKPAYLOADWORKGROUPEXT;
(*KeywordMap)["fcoopmatNV"] = FCOOPMATNV;
(*KeywordMap)["icoopmatNV"] = ICOOPMATNV;
(*KeywordMap)["ucoopmatNV"] = UCOOPMATNV;
(*KeywordMap)["coopmat"] = COOPMAT;
(*KeywordMap)["hitObjectNV"] = HITOBJECTNV;
(*KeywordMap)["hitObjectAttributeNV"] = HITOBJECTATTRNV;
ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
ReservedSet->insert("common");
ReservedSet->insert("partition");
ReservedSet->insert("active");
ReservedSet->insert("asm");
ReservedSet->insert("class");
ReservedSet->insert("union");
ReservedSet->insert("enum");
ReservedSet->insert("typedef");
ReservedSet->insert("template");
ReservedSet->insert("this");
ReservedSet->insert("goto");
ReservedSet->insert("inline");
ReservedSet->insert("noinline");
ReservedSet->insert("public");
ReservedSet->insert("static");
ReservedSet->insert("extern");
ReservedSet->insert("external");
ReservedSet->insert("interface");
ReservedSet->insert("long");
ReservedSet->insert("short");
ReservedSet->insert("half");
ReservedSet->insert("fixed");
ReservedSet->insert("unsigned");
ReservedSet->insert("input");
ReservedSet->insert("output");
ReservedSet->insert("hvec2");
ReservedSet->insert("hvec3");
ReservedSet->insert("hvec4");
ReservedSet->insert("fvec2");
ReservedSet->insert("fvec3");
ReservedSet->insert("fvec4");
ReservedSet->insert("sampler3DRect");
ReservedSet->insert("filter");
ReservedSet->insert("sizeof");
ReservedSet->insert("cast");
ReservedSet->insert("namespace");
ReservedSet->insert("using");
}
void TScanContext::deleteKeywordMap()
{
delete KeywordMap;
KeywordMap = nullptr;
delete ReservedSet;
ReservedSet = nullptr;
}
// Called by yylex to get the next token.
// Returning 0 implies end of input.
int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
{
do {
parserToken = &token;
TPpToken ppToken;
int token = pp->tokenize(ppToken);
if (token == EndOfInput)
return 0;
tokenText = ppToken.name;
loc = ppToken.loc;
parserToken->sType.lex.loc = loc;
switch (token) {
case ';': afterType = false; afterBuffer = false; return SEMICOLON;
case ',': afterType = false; return COMMA;
case ':': return COLON;
case '=': afterType = false; return EQUAL;
case '(': afterType = false; return LEFT_PAREN;
case ')': afterType = false; return RIGHT_PAREN;
case '.': field = true; return DOT;
case '!': return BANG;
case '-': return DASH;
case '~': return TILDE;
case '+': return PLUS;
case '*': return STAR;
case '/': return SLASH;
case '%': return PERCENT;
case '<': return LEFT_ANGLE;
case '>': return RIGHT_ANGLE;
case '|': return VERTICAL_BAR;
case '^': return CARET;
case '&': return AMPERSAND;
case '?': return QUESTION;
case '[': return LEFT_BRACKET;
case ']': return RIGHT_BRACKET;
case '{': afterStruct = false; afterBuffer = false; return LEFT_BRACE;
case '}': return RIGHT_BRACE;
case '\\':
parseContext.error(loc, "illegal use of escape character", "\\", "");
break;
case PPAtomAddAssign: return ADD_ASSIGN;
case PPAtomSubAssign: return SUB_ASSIGN;
case PPAtomMulAssign: return MUL_ASSIGN;
case PPAtomDivAssign: return DIV_ASSIGN;
case PPAtomModAssign: return MOD_ASSIGN;
case PpAtomRight: return RIGHT_OP;
case PpAtomLeft: return LEFT_OP;
case PpAtomRightAssign: return RIGHT_ASSIGN;
case PpAtomLeftAssign: return LEFT_ASSIGN;
case PpAtomAndAssign: return AND_ASSIGN;
case PpAtomOrAssign: return OR_ASSIGN;
case PpAtomXorAssign: return XOR_ASSIGN;
case PpAtomAnd: return AND_OP;
case PpAtomOr: return OR_OP;
case PpAtomXor: return XOR_OP;
case PpAtomEQ: return EQ_OP;
case PpAtomGE: return GE_OP;
case PpAtomNE: return NE_OP;
case PpAtomLE: return LE_OP;
case PpAtomDecrement: return DEC_OP;
case PpAtomIncrement: return INC_OP;
case PpAtomColonColon:
parseContext.error(loc, "not supported", "::", "");
break;
case PpAtomConstString: parserToken->sType.lex.string = NewPoolTString(tokenText); return STRING_LITERAL;
case PpAtomConstInt: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
case PpAtomConstUint: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
case PpAtomConstFloat: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
case PpAtomConstInt16: parserToken->sType.lex.i = ppToken.ival; return INT16CONSTANT;
case PpAtomConstUint16: parserToken->sType.lex.i = ppToken.ival; return UINT16CONSTANT;
case PpAtomConstInt64: parserToken->sType.lex.i64 = ppToken.i64val; return INT64CONSTANT;
case PpAtomConstUint64: parserToken->sType.lex.i64 = ppToken.i64val; return UINT64CONSTANT;
case PpAtomConstDouble: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
case PpAtomConstFloat16: parserToken->sType.lex.d = ppToken.dval; return FLOAT16CONSTANT;
case PpAtomIdentifier:
{
int token = tokenizeIdentifier();
field = false;
return token;
}
case EndOfInput: return 0;
default:
char buf[2];
buf[0] = (char)token;
buf[1] = 0;
parseContext.error(loc, "unexpected token", buf, "");
break;
}
} while (true);
}
int TScanContext::tokenizeIdentifier()
{
if (ReservedSet->find(tokenText) != ReservedSet->end())
return reservedWord();
auto it = KeywordMap->find(tokenText);
if (it == KeywordMap->end()) {
// Should have an identifier of some sort
return identifierOrType();
}
keyword = it->second;
switch (keyword) {
case CONST:
case UNIFORM:
case TILEIMAGEEXT:
case IN:
case OUT:
case INOUT:
case BREAK:
case CONTINUE:
case DO:
case FOR:
case WHILE:
case IF:
case ELSE:
case DISCARD:
case RETURN:
case CASE:
return keyword;
case TERMINATE_INVOCATION:
if (!parseContext.extensionTurnedOn(E_GL_EXT_terminate_invocation))
return identifierOrType();
return keyword;
case TERMINATE_RAY:
case IGNORE_INTERSECTION:
if (!parseContext.extensionTurnedOn(E_GL_EXT_ray_tracing))
return identifierOrType();
return keyword;
case BUFFER:
afterBuffer = true;
if ((parseContext.isEsProfile() && parseContext.version < 310) ||
(!parseContext.isEsProfile() && (parseContext.version < 430 &&
!parseContext.extensionTurnedOn(E_GL_ARB_shader_storage_buffer_object))))
return identifierOrType();
return keyword;
case STRUCT:
afterStruct = true;
return keyword;
case SWITCH:
case DEFAULT:
if ((parseContext.isEsProfile() && parseContext.version < 300) ||
(!parseContext.isEsProfile() && parseContext.version < 130))
reservedWord();
return keyword;
case VOID:
case BOOL:
case FLOAT:
case INT:
case BVEC2:
case BVEC3:
case BVEC4:
case VEC2:
case VEC3:
case VEC4:
case IVEC2:
case IVEC3:
case IVEC4:
case MAT2:
case MAT3:
case MAT4:
case SAMPLER2D:
case SAMPLERCUBE:
afterType = true;
return keyword;
case BOOLCONSTANT:
if (strcmp("true", tokenText) == 0)
parserToken->sType.lex.b = true;
else
parserToken->sType.lex.b = false;
return keyword;
case SMOOTH:
if ((parseContext.isEsProfile() && parseContext.version < 300) ||
(!parseContext.isEsProfile() && parseContext.version < 130))
return identifierOrType();
return keyword;
case FLAT:
if (parseContext.isEsProfile() && parseContext.version < 300)
reservedWord();
else if (!parseContext.isEsProfile() && parseContext.version < 130)
return identifierOrType();
return keyword;
case CENTROID:
if (parseContext.version < 120)
return identifierOrType();
return keyword;
case INVARIANT:
if (!parseContext.isEsProfile() && parseContext.version < 120)
return identifierOrType();
return keyword;
case PACKED:
if ((parseContext.isEsProfile() && parseContext.version < 300) ||
(!parseContext.isEsProfile() && parseContext.version < 140))
return reservedWord();
return identifierOrType();
case RESOURCE:
{
bool reserved = (parseContext.isEsProfile() && parseContext.version >= 300) ||
(!parseContext.isEsProfile() && parseContext.version >= 420);
return identifierOrReserved(reserved);
}
case SUPERP:
{
bool reserved = parseContext.isEsProfile() || parseContext.version >= 130;
return identifierOrReserved(reserved);
}
case NOPERSPECTIVE:
if (parseContext.extensionTurnedOn(E_GL_NV_shader_noperspective_interpolation))
return keyword;
return es30ReservedFromGLSL(130);
case NONUNIFORM:
if (parseContext.extensionTurnedOn(E_GL_EXT_nonuniform_qualifier))
return keyword;
else
return identifierOrType();
case ATTRIBUTE:
case VARYING:
if (parseContext.isEsProfile() && parseContext.version >= 300)
reservedWord();
return keyword;
case PAYLOADNV:
case PAYLOADINNV:
case HITATTRNV:
case CALLDATANV:
case CALLDATAINNV:
case ACCSTRUCTNV:
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_NV_ray_tracing))
return keyword;
return identifierOrType();
case ACCSTRUCTEXT:
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_ray_tracing) ||
parseContext.extensionTurnedOn(E_GL_EXT_ray_query) ||
parseContext.extensionTurnedOn(E_GL_NV_displacement_micromap))
return keyword;
return identifierOrType();
case PAYLOADEXT:
case PAYLOADINEXT:
case HITATTREXT:
case CALLDATAEXT:
case CALLDATAINEXT:
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_ray_tracing) ||
parseContext.extensionTurnedOn(E_GL_EXT_ray_query))
return keyword;
return identifierOrType();
case RAYQUERYEXT:
if (parseContext.symbolTable.atBuiltInLevel() ||
(!parseContext.isEsProfile() && parseContext.version >= 460
&& parseContext.extensionTurnedOn(E_GL_EXT_ray_query)))
return keyword;
return identifierOrType();
case ATOMIC_UINT:
if ((parseContext.isEsProfile() && parseContext.version >= 310) ||
parseContext.extensionTurnedOn(E_GL_ARB_shader_atomic_counters))
return keyword;
return es30ReservedFromGLSL(420);
case COHERENT:
case DEVICECOHERENT:
case QUEUEFAMILYCOHERENT:
case WORKGROUPCOHERENT:
case SUBGROUPCOHERENT:
case SHADERCALLCOHERENT:
case NONPRIVATE:
case RESTRICT:
case READONLY:
case WRITEONLY:
if (parseContext.isEsProfile() && parseContext.version >= 310)
return keyword;
return es30ReservedFromGLSL(parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store) ? 130 : 420);
case VOLATILE:
if (parseContext.isEsProfile() && parseContext.version >= 310)
return keyword;
if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.isEsProfile() ||
(parseContext.version < 420 && ! parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
reservedWord();
return keyword;
case PATCH:
if (parseContext.symbolTable.atBuiltInLevel() ||
(parseContext.isEsProfile() &&
(parseContext.version >= 320 ||
parseContext.extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))) ||
(!parseContext.isEsProfile() && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader)))
return keyword;
return es30ReservedFromGLSL(400);
case SAMPLE:
if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
parseContext.extensionsTurnedOn(1, &E_GL_OES_shader_multisample_interpolation))
return keyword;
return es30ReservedFromGLSL(400);
case SUBROUTINE:
return es30ReservedFromGLSL(400);
case SHARED:
if ((parseContext.isEsProfile() && parseContext.version < 300) ||
(!parseContext.isEsProfile() && parseContext.version < 140))
return identifierOrType();
return keyword;
case LAYOUT:
{
const int numLayoutExts = 2;
const char* layoutExts[numLayoutExts] = { E_GL_ARB_shading_language_420pack,
E_GL_ARB_explicit_attrib_location };
if ((parseContext.isEsProfile() && parseContext.version < 300) ||
(!parseContext.isEsProfile() && parseContext.version < 140 &&
! parseContext.extensionsTurnedOn(numLayoutExts, layoutExts)))
return identifierOrType();
return keyword;
}
case HIGH_PRECISION:
case MEDIUM_PRECISION:
case LOW_PRECISION:
case PRECISION:
return precisionKeyword();
case MAT2X2:
case MAT2X3:
case MAT2X4:
case MAT3X2:
case MAT3X3:
case MAT3X4:
case MAT4X2:
case MAT4X3:
case MAT4X4:
return matNxM();
case DMAT2:
case DMAT3:
case DMAT4:
case DMAT2X2:
case DMAT2X3:
case DMAT2X4:
case DMAT3X2:
case DMAT3X3:
case DMAT3X4:
case DMAT4X2:
case DMAT4X3:
case DMAT4X4:
return dMat();
case IMAGE1D:
case IIMAGE1D:
case UIMAGE1D:
case IMAGE1DARRAY:
case IIMAGE1DARRAY:
case UIMAGE1DARRAY:
case IMAGE2DRECT:
case IIMAGE2DRECT:
case UIMAGE2DRECT:
afterType = true;
return firstGenerationImage(false);
case I64IMAGE1D:
case U64IMAGE1D:
case I64IMAGE1DARRAY:
case U64IMAGE1DARRAY:
case I64IMAGE2DRECT:
case U64IMAGE2DRECT:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64)) {
return firstGenerationImage(false);
}
return identifierOrType();
case IMAGEBUFFER:
case IIMAGEBUFFER:
case UIMAGEBUFFER:
afterType = true;
if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
return keyword;
return firstGenerationImage(false);
case I64IMAGEBUFFER:
case U64IMAGEBUFFER:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64)) {
if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
return keyword;
return firstGenerationImage(false);
}
return identifierOrType();
case IMAGE2D:
case IIMAGE2D:
case UIMAGE2D:
case IMAGE3D:
case IIMAGE3D:
case UIMAGE3D:
case IMAGECUBE:
case IIMAGECUBE:
case UIMAGECUBE:
case IMAGE2DARRAY:
case IIMAGE2DARRAY:
case UIMAGE2DARRAY:
afterType = true;
return firstGenerationImage(true);
case I64IMAGE2D:
case U64IMAGE2D:
case I64IMAGE3D:
case U64IMAGE3D:
case I64IMAGECUBE:
case U64IMAGECUBE:
case I64IMAGE2DARRAY:
case U64IMAGE2DARRAY:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64))
return firstGenerationImage(true);
return identifierOrType();
case IMAGECUBEARRAY:
case IIMAGECUBEARRAY:
case UIMAGECUBEARRAY:
afterType = true;
if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
return keyword;
return secondGenerationImage();
case I64IMAGECUBEARRAY:
case U64IMAGECUBEARRAY:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64)) {
if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
return keyword;
return secondGenerationImage();
}
return identifierOrType();
case IMAGE2DMS:
case IIMAGE2DMS:
case UIMAGE2DMS:
case IMAGE2DMSARRAY:
case IIMAGE2DMSARRAY:
case UIMAGE2DMSARRAY:
afterType = true;
return secondGenerationImage();
case I64IMAGE2DMS:
case U64IMAGE2DMS:
case I64IMAGE2DMSARRAY:
case U64IMAGE2DMSARRAY:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64)) {
return secondGenerationImage();
}
return identifierOrType();
case DOUBLE:
case DVEC2:
case DVEC3:
case DVEC4:
afterType = true;
if (parseContext.isEsProfile() || parseContext.version < 150 ||
(!parseContext.symbolTable.atBuiltInLevel() &&
(parseContext.version < 400 && !parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64) &&
(parseContext.version < 410 && !parseContext.extensionTurnedOn(E_GL_ARB_vertex_attrib_64bit)))))
reservedWord();
return keyword;
case INT64_T:
case UINT64_T:
case I64VEC2:
case I64VEC3:
case I64VEC4:
case U64VEC2:
case U64VEC3:
case U64VEC4:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64))
return keyword;
return identifierOrType();
case INT8_T:
case UINT8_T:
case I8VEC2:
case I8VEC3:
case I8VEC4:
case U8VEC2:
case U8VEC3:
case U8VEC4:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_8bit_storage) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8))
return keyword;
return identifierOrType();
case INT16_T:
case UINT16_T:
case I16VEC2:
case I16VEC3:
case I16VEC4:
case U16VEC2:
case U16VEC3:
case U16VEC4:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_int16) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int16))
return keyword;
return identifierOrType();
case INT32_T:
case UINT32_T:
case I32VEC2:
case I32VEC3:
case I32VEC4:
case U32VEC2:
case U32VEC3:
case U32VEC4:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32))
return keyword;
return identifierOrType();
case FLOAT32_T:
case F32VEC2:
case F32VEC3:
case F32VEC4:
case F32MAT2:
case F32MAT3:
case F32MAT4:
case F32MAT2X2:
case F32MAT2X3:
case F32MAT2X4:
case F32MAT3X2:
case F32MAT3X3:
case F32MAT3X4:
case F32MAT4X2:
case F32MAT4X3:
case F32MAT4X4:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32))
return keyword;
return identifierOrType();
case FLOAT64_T:
case F64VEC2:
case F64VEC3:
case F64VEC4:
case F64MAT2:
case F64MAT3:
case F64MAT4:
case F64MAT2X2:
case F64MAT2X3:
case F64MAT2X4:
case F64MAT3X2:
case F64MAT3X3:
case F64MAT3X4:
case F64MAT4X2:
case F64MAT4X3:
case F64MAT4X4:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64))
return keyword;
return identifierOrType();
case FLOAT16_T:
case F16VEC2:
case F16VEC3:
case F16VEC4:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
return keyword;
return identifierOrType();
case F16MAT2:
case F16MAT3:
case F16MAT4:
case F16MAT2X2:
case F16MAT2X3:
case F16MAT2X4:
case F16MAT3X2:
case F16MAT3X3:
case F16MAT3X4:
case F16MAT4X2:
case F16MAT4X3:
case F16MAT4X4:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
return keyword;
return identifierOrType();
case SAMPLERCUBEARRAY:
case SAMPLERCUBEARRAYSHADOW:
case ISAMPLERCUBEARRAY:
case USAMPLERCUBEARRAY:
afterType = true;
if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
return keyword;
if (parseContext.isEsProfile() || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array)))
reservedWord();
return keyword;
case TEXTURECUBEARRAY:
case ITEXTURECUBEARRAY:
case UTEXTURECUBEARRAY:
if (parseContext.spvVersion.vulkan > 0)
return keyword;
else
return identifierOrType();
case UINT:
case UVEC2:
case UVEC3:
case UVEC4:
case SAMPLERCUBESHADOW:
case SAMPLER2DARRAY:
case SAMPLER2DARRAYSHADOW:
case ISAMPLER2D:
case ISAMPLER3D:
case ISAMPLERCUBE:
case ISAMPLER2DARRAY:
case USAMPLER2D:
case USAMPLER3D:
case USAMPLERCUBE:
case USAMPLER2DARRAY:
afterType = true;
if (keyword == SAMPLER2DARRAY || keyword == SAMPLER2DARRAYSHADOW) {
if (!parseContext.isEsProfile() &&
(parseContext.extensionTurnedOn(E_GL_EXT_texture_array) || parseContext.symbolTable.atBuiltInLevel())) {
return keyword;
}
}
return nonreservedKeyword(300, 130);
case SAMPLER3D:
afterType = true;
if (parseContext.isEsProfile() && parseContext.version < 300) {
if (!parseContext.extensionTurnedOn(E_GL_OES_texture_3D))
reservedWord();
}
return keyword;
case SAMPLER2DSHADOW:
afterType = true;
if (parseContext.isEsProfile() && parseContext.version < 300) {
if (!parseContext.extensionTurnedOn(E_GL_EXT_shadow_samplers))
reservedWord();
}
return keyword;
case TEXTURE2D:
case TEXTURECUBE:
case TEXTURE2DARRAY:
case ITEXTURE2D:
case ITEXTURE3D:
case ITEXTURECUBE:
case ITEXTURE2DARRAY:
case UTEXTURE2D:
case UTEXTURE3D:
case UTEXTURECUBE:
case UTEXTURE2DARRAY:
case TEXTURE3D:
case SAMPLER:
case SAMPLERSHADOW:
if (parseContext.spvVersion.vulkan > 0)
return keyword;
else
return identifierOrType();
case ISAMPLER1D:
case ISAMPLER1DARRAY:
case SAMPLER1DARRAYSHADOW:
case USAMPLER1D:
case USAMPLER1DARRAY:
afterType = true;
if (keyword == SAMPLER1DARRAYSHADOW) {
if (!parseContext.isEsProfile() &&
(parseContext.extensionTurnedOn(E_GL_EXT_texture_array) || parseContext.symbolTable.atBuiltInLevel())) {
return keyword;
}
}
return es30ReservedFromGLSL(130);
case ISAMPLER2DRECT:
case USAMPLER2DRECT:
afterType = true;
return es30ReservedFromGLSL(140);
case SAMPLERBUFFER:
afterType = true;
if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
return keyword;
return es30ReservedFromGLSL(130);
case ISAMPLERBUFFER:
case USAMPLERBUFFER:
afterType = true;
if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
return keyword;
return es30ReservedFromGLSL(140);
case SAMPLER2DMS:
case ISAMPLER2DMS:
case USAMPLER2DMS:
afterType = true;
if (parseContext.isEsProfile() && parseContext.version >= 310)
return keyword;
if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
(parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
return keyword;
return es30ReservedFromGLSL(150);
case SAMPLER2DMSARRAY:
case ISAMPLER2DMSARRAY:
case USAMPLER2DMSARRAY:
afterType = true;
if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
parseContext.extensionsTurnedOn(1, &E_GL_OES_texture_storage_multisample_2d_array))
return keyword;
if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
(parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
return keyword;
return es30ReservedFromGLSL(150);
case SAMPLER1D:
case SAMPLER1DSHADOW:
afterType = true;
if (parseContext.isEsProfile())
reservedWord();
return keyword;
case SAMPLER2DRECT:
case SAMPLER2DRECTSHADOW:
afterType = true;
if (parseContext.isEsProfile())
reservedWord();
else if (parseContext.version < 140 && ! parseContext.symbolTable.atBuiltInLevel() && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_rectangle)) {
if (parseContext.relaxedErrors())
parseContext.requireExtensions(loc, 1, &E_GL_ARB_texture_rectangle, "texture-rectangle sampler keyword");
else
reservedWord();
}
return keyword;
case SAMPLER1DARRAY:
afterType = true;
if (parseContext.isEsProfile() && parseContext.version == 300)
reservedWord();
else if ((parseContext.isEsProfile() && parseContext.version < 300) ||
((!parseContext.isEsProfile() && parseContext.version < 130) &&
!parseContext.symbolTable.atBuiltInLevel() &&
!parseContext.extensionTurnedOn(E_GL_EXT_texture_array)))
return identifierOrType();
return keyword;
case SAMPLEREXTERNALOES:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external) ||
parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external_essl3))
return keyword;
return identifierOrType();
case SAMPLEREXTERNAL2DY2YEXT:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_YUV_target))
return keyword;
return identifierOrType();
case ITEXTURE1DARRAY:
case UTEXTURE1D:
case ITEXTURE1D:
case UTEXTURE1DARRAY:
case TEXTUREBUFFER:
case ITEXTURE2DRECT:
case UTEXTURE2DRECT:
case ITEXTUREBUFFER:
case UTEXTUREBUFFER:
case TEXTURE2DMS:
case ITEXTURE2DMS:
case UTEXTURE2DMS:
case TEXTURE2DMSARRAY:
case ITEXTURE2DMSARRAY:
case UTEXTURE2DMSARRAY:
case TEXTURE1D:
case TEXTURE2DRECT:
case TEXTURE1DARRAY:
if (parseContext.spvVersion.vulkan > 0)
return keyword;
else
return identifierOrType();
case SUBPASSINPUT:
case SUBPASSINPUTMS:
case ISUBPASSINPUT:
case ISUBPASSINPUTMS:
case USUBPASSINPUT:
case USUBPASSINPUTMS:
case ATTACHMENTEXT:
case IATTACHMENTEXT:
case UATTACHMENTEXT:
if (parseContext.spvVersion.vulkan > 0)
return keyword;
else
return identifierOrType();
case F16SAMPLER1D:
case F16SAMPLER2D:
case F16SAMPLER3D:
case F16SAMPLER2DRECT:
case F16SAMPLERCUBE:
case F16SAMPLER1DARRAY:
case F16SAMPLER2DARRAY:
case F16SAMPLERCUBEARRAY:
case F16SAMPLERBUFFER:
case F16SAMPLER2DMS:
case F16SAMPLER2DMSARRAY:
case F16SAMPLER1DSHADOW:
case F16SAMPLER2DSHADOW:
case F16SAMPLER1DARRAYSHADOW:
case F16SAMPLER2DARRAYSHADOW:
case F16SAMPLER2DRECTSHADOW:
case F16SAMPLERCUBESHADOW:
case F16SAMPLERCUBEARRAYSHADOW:
case F16IMAGE1D:
case F16IMAGE2D:
case F16IMAGE3D:
case F16IMAGE2DRECT:
case F16IMAGECUBE:
case F16IMAGE1DARRAY:
case F16IMAGE2DARRAY:
case F16IMAGECUBEARRAY:
case F16IMAGEBUFFER:
case F16IMAGE2DMS:
case F16IMAGE2DMSARRAY:
case F16TEXTURE1D:
case F16TEXTURE2D:
case F16TEXTURE3D:
case F16TEXTURE2DRECT:
case F16TEXTURECUBE:
case F16TEXTURE1DARRAY:
case F16TEXTURE2DARRAY:
case F16TEXTURECUBEARRAY:
case F16TEXTUREBUFFER:
case F16TEXTURE2DMS:
case F16TEXTURE2DMSARRAY:
case F16SUBPASSINPUT:
case F16SUBPASSINPUTMS:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float_fetch))
return keyword;
return identifierOrType();
case EXPLICITINTERPAMD:
if (parseContext.extensionTurnedOn(E_GL_AMD_shader_explicit_vertex_parameter))
return keyword;
return identifierOrType();
case PERVERTEXNV:
if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
parseContext.extensionTurnedOn(E_GL_NV_fragment_shader_barycentric))
return keyword;
return identifierOrType();
case PERVERTEXEXT:
if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
parseContext.extensionTurnedOn(E_GL_EXT_fragment_shader_barycentric))
return keyword;
return identifierOrType();
case PRECISE:
if ((parseContext.isEsProfile() &&
(parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_gpu_shader5, AEP_gpu_shader5))) ||
(!parseContext.isEsProfile() && parseContext.version >= 400))
return keyword;
if (parseContext.isEsProfile() && parseContext.version == 310) {
reservedWord();
return keyword;
}
return identifierOrType();
case PERPRIMITIVENV:
case PERVIEWNV:
case PERTASKNV:
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_NV_mesh_shader))
return keyword;
return identifierOrType();
case PERPRIMITIVEEXT:
case TASKPAYLOADWORKGROUPEXT:
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_mesh_shader))
return keyword;
return identifierOrType();
case FCOOPMATNV:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_NV_cooperative_matrix))
return keyword;
return identifierOrType();
case UCOOPMATNV:
case ICOOPMATNV:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_NV_integer_cooperative_matrix))
return keyword;
return identifierOrType();
case COOPMAT:
afterType = true;
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_KHR_cooperative_matrix))
return keyword;
return identifierOrType();
case DEMOTE:
if (parseContext.extensionTurnedOn(E_GL_EXT_demote_to_helper_invocation))
return keyword;
else
return identifierOrType();
case SPIRV_INSTRUCTION:
case SPIRV_EXECUTION_MODE:
case SPIRV_EXECUTION_MODE_ID:
case SPIRV_DECORATE:
case SPIRV_DECORATE_ID:
case SPIRV_DECORATE_STRING:
case SPIRV_TYPE:
case SPIRV_STORAGE_CLASS:
case SPIRV_BY_REFERENCE:
case SPIRV_LITERAL:
if (parseContext.symbolTable.atBuiltInLevel() ||
parseContext.extensionTurnedOn(E_GL_EXT_spirv_intrinsics))
return keyword;
return identifierOrType();
case HITOBJECTNV:
if (parseContext.symbolTable.atBuiltInLevel() ||
(!parseContext.isEsProfile() && parseContext.version >= 460
&& parseContext.extensionTurnedOn(E_GL_NV_shader_invocation_reorder)))
return keyword;
return identifierOrType();
case HITOBJECTATTRNV:
if (parseContext.symbolTable.atBuiltInLevel() ||
(!parseContext.isEsProfile() && parseContext.version >= 460
&& parseContext.extensionTurnedOn(E_GL_NV_shader_invocation_reorder)))
return keyword;
return identifierOrType();
default:
parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
return 0;
}
}
int TScanContext::identifierOrType()
{
parserToken->sType.lex.string = NewPoolTString(tokenText);
if (field)
return IDENTIFIER;
parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
if ((afterType == false && afterStruct == false) && parserToken->sType.lex.symbol != nullptr) {
if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
if (variable->isUserType() &&
// treat redeclaration of forward-declared buffer/uniform reference as an identifier
!(variable->getType().isReference() && afterBuffer)) {
afterType = true;
return TYPE_NAME;
}
}
}
return IDENTIFIER;
}
// Give an error for use of a reserved symbol.
// However, allow built-in declarations to use reserved words, to allow
// extension support before the extension is enabled.
int TScanContext::reservedWord()
{
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.error(loc, "Reserved word.", tokenText, "", "");
return 0;
}
int TScanContext::identifierOrReserved(bool reserved)
{
if (reserved) {
reservedWord();
return 0;
}
if (parseContext.isForwardCompatible())
parseContext.warn(loc, "using future reserved keyword", tokenText, "");
return identifierOrType();
}
// For keywords that suddenly showed up on non-ES (not previously reserved)
// but then got reserved by ES 3.0.
int TScanContext::es30ReservedFromGLSL(int version)
{
if (parseContext.symbolTable.atBuiltInLevel())
return keyword;
if ((parseContext.isEsProfile() && parseContext.version < 300) ||
(!parseContext.isEsProfile() && parseContext.version < version)) {
if (parseContext.isForwardCompatible())
parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
return identifierOrType();
} else if (parseContext.isEsProfile() && parseContext.version >= 300)
reservedWord();
return keyword;
}
// For a keyword that was never reserved, until it suddenly
// showed up, both in an es version and a non-ES version.
int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
{
if ((parseContext.isEsProfile() && parseContext.version < esVersion) ||
(!parseContext.isEsProfile() && parseContext.version < nonEsVersion)) {
if (parseContext.isForwardCompatible())
parseContext.warn(loc, "using future keyword", tokenText, "");
return identifierOrType();
}
return keyword;
}
int TScanContext::precisionKeyword()
{
if (parseContext.isEsProfile() || parseContext.version >= 130)
return keyword;
if (parseContext.isForwardCompatible())
parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
return identifierOrType();
}
int TScanContext::matNxM()
{
afterType = true;
if (parseContext.version > 110)
return keyword;
if (parseContext.isForwardCompatible())
parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
return identifierOrType();
}
int TScanContext::dMat()
{
afterType = true;
if (parseContext.isEsProfile() && parseContext.version >= 300) {
reservedWord();
return keyword;
}
if (!parseContext.isEsProfile() && (parseContext.version >= 400 ||
parseContext.symbolTable.atBuiltInLevel() ||
(parseContext.version >= 150 && parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64)) ||
(parseContext.version >= 150 && parseContext.extensionTurnedOn(E_GL_ARB_vertex_attrib_64bit)
&& parseContext.language == EShLangVertex)))
return keyword;
if (parseContext.isForwardCompatible())
parseContext.warn(loc, "using future type keyword", tokenText, "");
return identifierOrType();
}
int TScanContext::firstGenerationImage(bool inEs310)
{
if (parseContext.symbolTable.atBuiltInLevel() ||
(!parseContext.isEsProfile() && (parseContext.version >= 420 ||
parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))) ||
(inEs310 && parseContext.isEsProfile() && parseContext.version >= 310))
return keyword;
if ((parseContext.isEsProfile() && parseContext.version >= 300) ||
(!parseContext.isEsProfile() && parseContext.version >= 130)) {
reservedWord();
return keyword;
}
if (parseContext.isForwardCompatible())
parseContext.warn(loc, "using future type keyword", tokenText, "");
return identifierOrType();
}
int TScanContext::secondGenerationImage()
{
if (parseContext.isEsProfile() && parseContext.version >= 310) {
reservedWord();
return keyword;
}
if (parseContext.symbolTable.atBuiltInLevel() ||
(!parseContext.isEsProfile() &&
(parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
return keyword;
if (parseContext.isForwardCompatible())
parseContext.warn(loc, "using future type keyword", tokenText, "");
return identifierOrType();
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/gl_types.h | /*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
#pragma once
#define GL_FLOAT 0x1406
#define GL_FLOAT_VEC2 0x8B50
#define GL_FLOAT_VEC3 0x8B51
#define GL_FLOAT_VEC4 0x8B52
#define GL_DOUBLE 0x140A
#define GL_DOUBLE_VEC2 0x8FFC
#define GL_DOUBLE_VEC3 0x8FFD
#define GL_DOUBLE_VEC4 0x8FFE
#define GL_INT 0x1404
#define GL_INT_VEC2 0x8B53
#define GL_INT_VEC3 0x8B54
#define GL_INT_VEC4 0x8B55
#define GL_UNSIGNED_INT 0x1405
#define GL_UNSIGNED_INT_VEC2 0x8DC6
#define GL_UNSIGNED_INT_VEC3 0x8DC7
#define GL_UNSIGNED_INT_VEC4 0x8DC8
#define GL_INT64_ARB 0x140E
#define GL_INT64_VEC2_ARB 0x8FE9
#define GL_INT64_VEC3_ARB 0x8FEA
#define GL_INT64_VEC4_ARB 0x8FEB
#define GL_UNSIGNED_INT64_ARB 0x140F
#define GL_UNSIGNED_INT64_VEC2_ARB 0x8FF5
#define GL_UNSIGNED_INT64_VEC3_ARB 0x8FF6
#define GL_UNSIGNED_INT64_VEC4_ARB 0x8FF7
#define GL_UNSIGNED_INT16_VEC2_NV 0x8FF1
#define GL_UNSIGNED_INT16_VEC3_NV 0x8FF2
#define GL_UNSIGNED_INT16_VEC4_NV 0x8FF3
#define GL_INT16_NV 0x8FE4
#define GL_INT16_VEC2_NV 0x8FE5
#define GL_INT16_VEC3_NV 0x8FE6
#define GL_INT16_VEC4_NV 0x8FE7
#define GL_BOOL 0x8B56
#define GL_BOOL_VEC2 0x8B57
#define GL_BOOL_VEC3 0x8B58
#define GL_BOOL_VEC4 0x8B59
#define GL_FLOAT_MAT2 0x8B5A
#define GL_FLOAT_MAT3 0x8B5B
#define GL_FLOAT_MAT4 0x8B5C
#define GL_FLOAT_MAT2x3 0x8B65
#define GL_FLOAT_MAT2x4 0x8B66
#define GL_FLOAT_MAT3x2 0x8B67
#define GL_FLOAT_MAT3x4 0x8B68
#define GL_FLOAT_MAT4x2 0x8B69
#define GL_FLOAT_MAT4x3 0x8B6A
#define GL_DOUBLE_MAT2 0x8F46
#define GL_DOUBLE_MAT3 0x8F47
#define GL_DOUBLE_MAT4 0x8F48
#define GL_DOUBLE_MAT2x3 0x8F49
#define GL_DOUBLE_MAT2x4 0x8F4A
#define GL_DOUBLE_MAT3x2 0x8F4B
#define GL_DOUBLE_MAT3x4 0x8F4C
#define GL_DOUBLE_MAT4x2 0x8F4D
#define GL_DOUBLE_MAT4x3 0x8F4E
// Those constants are borrowed from extension NV_gpu_shader5
#define GL_FLOAT16_NV 0x8FF8
#define GL_FLOAT16_VEC2_NV 0x8FF9
#define GL_FLOAT16_VEC3_NV 0x8FFA
#define GL_FLOAT16_VEC4_NV 0x8FFB
#define GL_FLOAT16_MAT2_AMD 0x91C5
#define GL_FLOAT16_MAT3_AMD 0x91C6
#define GL_FLOAT16_MAT4_AMD 0x91C7
#define GL_FLOAT16_MAT2x3_AMD 0x91C8
#define GL_FLOAT16_MAT2x4_AMD 0x91C9
#define GL_FLOAT16_MAT3x2_AMD 0x91CA
#define GL_FLOAT16_MAT3x4_AMD 0x91CB
#define GL_FLOAT16_MAT4x2_AMD 0x91CC
#define GL_FLOAT16_MAT4x3_AMD 0x91CD
#define GL_SAMPLER_1D 0x8B5D
#define GL_SAMPLER_2D 0x8B5E
#define GL_SAMPLER_3D 0x8B5F
#define GL_SAMPLER_CUBE 0x8B60
#define GL_SAMPLER_BUFFER 0x8DC2
#define GL_SAMPLER_1D_ARRAY 0x8DC0
#define GL_SAMPLER_2D_ARRAY 0x8DC1
#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3
#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4
#define GL_SAMPLER_CUBE_SHADOW 0x8DC5
#define GL_SAMPLER_1D_SHADOW 0x8B61
#define GL_SAMPLER_2D_SHADOW 0x8B62
#define GL_SAMPLER_2D_RECT 0x8B63
#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64
#define GL_SAMPLER_2D_MULTISAMPLE 0x9108
#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B
#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C
#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D
#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C
#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D
#define GL_FLOAT16_SAMPLER_1D_AMD 0x91CE
#define GL_FLOAT16_SAMPLER_2D_AMD 0x91CF
#define GL_FLOAT16_SAMPLER_3D_AMD 0x91D0
#define GL_FLOAT16_SAMPLER_CUBE_AMD 0x91D1
#define GL_FLOAT16_SAMPLER_2D_RECT_AMD 0x91D2
#define GL_FLOAT16_SAMPLER_1D_ARRAY_AMD 0x91D3
#define GL_FLOAT16_SAMPLER_2D_ARRAY_AMD 0x91D4
#define GL_FLOAT16_SAMPLER_CUBE_MAP_ARRAY_AMD 0x91D5
#define GL_FLOAT16_SAMPLER_BUFFER_AMD 0x91D6
#define GL_FLOAT16_SAMPLER_2D_MULTISAMPLE_AMD 0x91D7
#define GL_FLOAT16_SAMPLER_2D_MULTISAMPLE_ARRAY_AMD 0x91D8
#define GL_FLOAT16_SAMPLER_1D_SHADOW_AMD 0x91D9
#define GL_FLOAT16_SAMPLER_2D_SHADOW_AMD 0x91DA
#define GL_FLOAT16_SAMPLER_2D_RECT_SHADOW_AMD 0x91DB
#define GL_FLOAT16_SAMPLER_1D_ARRAY_SHADOW_AMD 0x91DC
#define GL_FLOAT16_SAMPLER_2D_ARRAY_SHADOW_AMD 0x91DD
#define GL_FLOAT16_SAMPLER_CUBE_SHADOW_AMD 0x91DE
#define GL_FLOAT16_SAMPLER_CUBE_MAP_ARRAY_SHADOW_AMD 0x91DF
#define GL_FLOAT16_IMAGE_1D_AMD 0x91E0
#define GL_FLOAT16_IMAGE_2D_AMD 0x91E1
#define GL_FLOAT16_IMAGE_3D_AMD 0x91E2
#define GL_FLOAT16_IMAGE_2D_RECT_AMD 0x91E3
#define GL_FLOAT16_IMAGE_CUBE_AMD 0x91E4
#define GL_FLOAT16_IMAGE_1D_ARRAY_AMD 0x91E5
#define GL_FLOAT16_IMAGE_2D_ARRAY_AMD 0x91E6
#define GL_FLOAT16_IMAGE_CUBE_MAP_ARRAY_AMD 0x91E7
#define GL_FLOAT16_IMAGE_BUFFER_AMD 0x91E8
#define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_AMD 0x91E9
#define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_ARRAY_AMD 0x91EA
#define GL_INT_SAMPLER_1D 0x8DC9
#define GL_INT_SAMPLER_2D 0x8DCA
#define GL_INT_SAMPLER_3D 0x8DCB
#define GL_INT_SAMPLER_CUBE 0x8DCC
#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE
#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF
#define GL_INT_SAMPLER_2D_RECT 0x8DCD
#define GL_INT_SAMPLER_BUFFER 0x8DD0
#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109
#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C
#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E
#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E
#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1
#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2
#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3
#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4
#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6
#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7
#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5
#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8
#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D
#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F
#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F
#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A
#define GL_IMAGE_1D 0x904C
#define GL_IMAGE_2D 0x904D
#define GL_IMAGE_3D 0x904E
#define GL_IMAGE_2D_RECT 0x904F
#define GL_IMAGE_CUBE 0x9050
#define GL_IMAGE_BUFFER 0x9051
#define GL_IMAGE_1D_ARRAY 0x9052
#define GL_IMAGE_2D_ARRAY 0x9053
#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054
#define GL_IMAGE_2D_MULTISAMPLE 0x9055
#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056
#define GL_INT_IMAGE_1D 0x9057
#define GL_INT_IMAGE_2D 0x9058
#define GL_INT_IMAGE_3D 0x9059
#define GL_INT_IMAGE_2D_RECT 0x905A
#define GL_INT_IMAGE_CUBE 0x905B
#define GL_INT_IMAGE_BUFFER 0x905C
#define GL_INT_IMAGE_1D_ARRAY 0x905D
#define GL_INT_IMAGE_2D_ARRAY 0x905E
#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F
#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060
#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061
#define GL_UNSIGNED_INT_IMAGE_1D 0x9062
#define GL_UNSIGNED_INT_IMAGE_2D 0x9063
#define GL_UNSIGNED_INT_IMAGE_3D 0x9064
#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065
#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066
#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067
#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068
#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069
#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A
#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B
#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C
#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/linkValidate.cpp | //
// Copyright (C) 2013 LunarG, Inc.
// Copyright (C) 2017 ARM Limited.
// Copyright (C) 2015-2018 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Do link-time merging and validation of intermediate representations.
//
// Basic model is that during compilation, each compilation unit (shader) is
// compiled into one TIntermediate instance. Then, at link time, multiple
// units for the same stage can be merged together, which can generate errors.
// Then, after all merging, a single instance of TIntermediate represents
// the whole stage. A final error check can be done on the resulting stage,
// even if no merging was done (i.e., the stage was only one compilation unit).
//
#include "localintermediate.h"
#include "../Include/InfoSink.h"
#include "SymbolTable.h"
namespace glslang {
//
// Link-time error emitter.
//
void TIntermediate::error(TInfoSink& infoSink, const char* message, EShLanguage unitStage)
{
infoSink.info.prefix(EPrefixError);
if (unitStage < EShLangCount)
infoSink.info << "Linking " << StageName(getStage()) << " and " << StageName(unitStage) << " stages: " << message << "\n";
else
infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n";
++numErrors;
}
// Link-time warning.
void TIntermediate::warn(TInfoSink& infoSink, const char* message, EShLanguage unitStage)
{
infoSink.info.prefix(EPrefixWarning);
if (unitStage < EShLangCount)
infoSink.info << "Linking " << StageName(language) << " and " << StageName(unitStage) << " stages: " << message << "\n";
else
infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n";
}
// TODO: 4.4 offset/align: "Two blocks linked together in the same program with the same block
// name must have the exact same set of members qualified with offset and their integral-constant
// expression values must be the same, or a link-time error results."
//
// Merge the information from 'unit' into 'this'
//
void TIntermediate::merge(TInfoSink& infoSink, TIntermediate& unit)
{
mergeCallGraphs(infoSink, unit);
mergeModes(infoSink, unit);
mergeTrees(infoSink, unit);
}
//
// check that link objects between stages
//
void TIntermediate::mergeUniformObjects(TInfoSink& infoSink, TIntermediate& unit) {
if (unit.treeRoot == nullptr || treeRoot == nullptr)
return;
// Get the linker-object lists
TIntermSequence& linkerObjects = findLinkerObjects()->getSequence();
TIntermSequence unitLinkerObjects = unit.findLinkerObjects()->getSequence();
// filter unitLinkerObjects to only contain uniforms
auto end = std::remove_if(unitLinkerObjects.begin(), unitLinkerObjects.end(),
[](TIntermNode* node) {return node->getAsSymbolNode()->getQualifier().storage != EvqUniform &&
node->getAsSymbolNode()->getQualifier().storage != EvqBuffer; });
unitLinkerObjects.resize(end - unitLinkerObjects.begin());
// merge uniforms and do error checking
bool mergeExistingOnly = false;
mergeGlobalUniformBlocks(infoSink, unit, mergeExistingOnly);
mergeLinkerObjects(infoSink, linkerObjects, unitLinkerObjects, unit.getStage());
}
//
// do error checking on the shader boundary in / out vars
//
void TIntermediate::checkStageIO(TInfoSink& infoSink, TIntermediate& unit) {
if (unit.treeRoot == nullptr || treeRoot == nullptr)
return;
// Get copies of the linker-object lists
TIntermSequence linkerObjects = findLinkerObjects()->getSequence();
TIntermSequence unitLinkerObjects = unit.findLinkerObjects()->getSequence();
// filter linkerObjects to only contain out variables
auto end = std::remove_if(linkerObjects.begin(), linkerObjects.end(),
[](TIntermNode* node) {return node->getAsSymbolNode()->getQualifier().storage != EvqVaryingOut; });
linkerObjects.resize(end - linkerObjects.begin());
// filter unitLinkerObjects to only contain in variables
auto unitEnd = std::remove_if(unitLinkerObjects.begin(), unitLinkerObjects.end(),
[](TIntermNode* node) {return node->getAsSymbolNode()->getQualifier().storage != EvqVaryingIn; });
unitLinkerObjects.resize(unitEnd - unitLinkerObjects.begin());
// do matching and error checking
mergeLinkerObjects(infoSink, linkerObjects, unitLinkerObjects, unit.getStage());
// TODO: final check; make sure that any statically used `in` have matching `out` written to
}
void TIntermediate::mergeCallGraphs(TInfoSink& infoSink, TIntermediate& unit)
{
if (unit.getNumEntryPoints() > 0) {
if (getNumEntryPoints() > 0)
error(infoSink, "can't handle multiple entry points per stage");
else {
entryPointName = unit.getEntryPointName();
entryPointMangledName = unit.getEntryPointMangledName();
}
}
numEntryPoints += unit.getNumEntryPoints();
callGraph.insert(callGraph.end(), unit.callGraph.begin(), unit.callGraph.end());
}
#define MERGE_MAX(member) member = std::max(member, unit.member)
#define MERGE_TRUE(member) if (unit.member) member = unit.member;
void TIntermediate::mergeModes(TInfoSink& infoSink, TIntermediate& unit)
{
if (language != unit.language)
error(infoSink, "stages must match when linking into a single stage");
if (getSource() == EShSourceNone)
setSource(unit.getSource());
if (getSource() != unit.getSource())
error(infoSink, "can't link compilation units from different source languages");
if (treeRoot == nullptr) {
profile = unit.profile;
version = unit.version;
requestedExtensions = unit.requestedExtensions;
} else {
if ((isEsProfile()) != (unit.isEsProfile()))
error(infoSink, "Cannot cross link ES and desktop profiles");
else if (unit.profile == ECompatibilityProfile)
profile = ECompatibilityProfile;
version = std::max(version, unit.version);
requestedExtensions.insert(unit.requestedExtensions.begin(), unit.requestedExtensions.end());
}
MERGE_MAX(spvVersion.spv);
MERGE_MAX(spvVersion.vulkanGlsl);
MERGE_MAX(spvVersion.vulkan);
MERGE_MAX(spvVersion.openGl);
MERGE_TRUE(spvVersion.vulkanRelaxed);
numErrors += unit.getNumErrors();
// Only one push_constant is allowed, mergeLinkerObjects() will ensure the push_constant
// is the same for all units.
if (numPushConstants > 1 || unit.numPushConstants > 1)
error(infoSink, "Only one push_constant block is allowed per stage");
numPushConstants = std::min(numPushConstants + unit.numPushConstants, 1);
if (unit.invocations != TQualifier::layoutNotSet) {
if (invocations == TQualifier::layoutNotSet)
invocations = unit.invocations;
else if (invocations != unit.invocations)
error(infoSink, "number of invocations must match between compilation units");
}
if (vertices == TQualifier::layoutNotSet)
vertices = unit.vertices;
else if (unit.vertices != TQualifier::layoutNotSet && vertices != unit.vertices) {
if (language == EShLangGeometry || language == EShLangMesh)
error(infoSink, "Contradictory layout max_vertices values");
else if (language == EShLangTessControl)
error(infoSink, "Contradictory layout vertices values");
else
assert(0);
}
if (primitives == TQualifier::layoutNotSet)
primitives = unit.primitives;
else if (primitives != unit.primitives) {
if (language == EShLangMesh)
error(infoSink, "Contradictory layout max_primitives values");
else
assert(0);
}
if (inputPrimitive == ElgNone)
inputPrimitive = unit.inputPrimitive;
else if (unit.inputPrimitive != ElgNone && inputPrimitive != unit.inputPrimitive)
error(infoSink, "Contradictory input layout primitives");
if (outputPrimitive == ElgNone)
outputPrimitive = unit.outputPrimitive;
else if (unit.outputPrimitive != ElgNone && outputPrimitive != unit.outputPrimitive)
error(infoSink, "Contradictory output layout primitives");
if (originUpperLeft != unit.originUpperLeft || pixelCenterInteger != unit.pixelCenterInteger)
error(infoSink, "gl_FragCoord redeclarations must match across shaders");
if (vertexSpacing == EvsNone)
vertexSpacing = unit.vertexSpacing;
else if (vertexSpacing != unit.vertexSpacing)
error(infoSink, "Contradictory input vertex spacing");
if (vertexOrder == EvoNone)
vertexOrder = unit.vertexOrder;
else if (vertexOrder != unit.vertexOrder)
error(infoSink, "Contradictory triangle ordering");
MERGE_TRUE(pointMode);
for (int i = 0; i < 3; ++i) {
if (unit.localSizeNotDefault[i]) {
if (!localSizeNotDefault[i]) {
localSize[i] = unit.localSize[i];
localSizeNotDefault[i] = true;
}
else if (localSize[i] != unit.localSize[i])
error(infoSink, "Contradictory local size");
}
if (localSizeSpecId[i] == TQualifier::layoutNotSet)
localSizeSpecId[i] = unit.localSizeSpecId[i];
else if (localSizeSpecId[i] != unit.localSizeSpecId[i])
error(infoSink, "Contradictory local size specialization ids");
}
MERGE_TRUE(earlyFragmentTests);
MERGE_TRUE(postDepthCoverage);
MERGE_TRUE(nonCoherentColorAttachmentReadEXT);
MERGE_TRUE(nonCoherentDepthAttachmentReadEXT);
MERGE_TRUE(nonCoherentStencilAttachmentReadEXT);
if (depthLayout == EldNone)
depthLayout = unit.depthLayout;
else if (depthLayout != unit.depthLayout)
error(infoSink, "Contradictory depth layouts");
MERGE_TRUE(depthReplacing);
MERGE_TRUE(hlslFunctionality1);
blendEquations |= unit.blendEquations;
MERGE_TRUE(xfbMode);
for (size_t b = 0; b < xfbBuffers.size(); ++b) {
if (xfbBuffers[b].stride == TQualifier::layoutXfbStrideEnd)
xfbBuffers[b].stride = unit.xfbBuffers[b].stride;
else if (xfbBuffers[b].stride != unit.xfbBuffers[b].stride)
error(infoSink, "Contradictory xfb_stride");
xfbBuffers[b].implicitStride = std::max(xfbBuffers[b].implicitStride, unit.xfbBuffers[b].implicitStride);
if (unit.xfbBuffers[b].contains64BitType)
xfbBuffers[b].contains64BitType = true;
if (unit.xfbBuffers[b].contains32BitType)
xfbBuffers[b].contains32BitType = true;
if (unit.xfbBuffers[b].contains16BitType)
xfbBuffers[b].contains16BitType = true;
// TODO: 4.4 link: enhanced layouts: compare ranges
}
MERGE_TRUE(multiStream);
MERGE_TRUE(layoutOverrideCoverage);
MERGE_TRUE(geoPassthroughEXT);
for (unsigned int i = 0; i < unit.shiftBinding.size(); ++i) {
if (unit.shiftBinding[i] > 0)
setShiftBinding((TResourceType)i, unit.shiftBinding[i]);
}
for (unsigned int i = 0; i < unit.shiftBindingForSet.size(); ++i) {
for (auto it = unit.shiftBindingForSet[i].begin(); it != unit.shiftBindingForSet[i].end(); ++it)
setShiftBindingForSet((TResourceType)i, it->second, it->first);
}
resourceSetBinding.insert(resourceSetBinding.end(), unit.resourceSetBinding.begin(), unit.resourceSetBinding.end());
MERGE_TRUE(autoMapBindings);
MERGE_TRUE(autoMapLocations);
MERGE_TRUE(invertY);
MERGE_TRUE(dxPositionW);
MERGE_TRUE(debugInfo);
MERGE_TRUE(flattenUniformArrays);
MERGE_TRUE(useUnknownFormat);
MERGE_TRUE(hlslOffsets);
MERGE_TRUE(useStorageBuffer);
MERGE_TRUE(invariantAll);
MERGE_TRUE(hlslIoMapping);
// TODO: sourceFile
// TODO: sourceText
// TODO: processes
MERGE_TRUE(needToLegalize);
MERGE_TRUE(binaryDoubleOutput);
MERGE_TRUE(usePhysicalStorageBuffer);
}
//
// Merge the 'unit' AST into 'this' AST.
// That includes rationalizing the unique IDs, which were set up independently,
// and might have overlaps that are not the same symbol, or might have different
// IDs for what should be the same shared symbol.
//
void TIntermediate::mergeTrees(TInfoSink& infoSink, TIntermediate& unit)
{
if (unit.treeRoot == nullptr)
return;
if (treeRoot == nullptr) {
treeRoot = unit.treeRoot;
return;
}
// Getting this far means we have two existing trees to merge...
numShaderRecordBlocks += unit.numShaderRecordBlocks;
numTaskNVBlocks += unit.numTaskNVBlocks;
// Get the top-level globals of each unit
TIntermSequence& globals = treeRoot->getAsAggregate()->getSequence();
TIntermSequence& unitGlobals = unit.treeRoot->getAsAggregate()->getSequence();
// Get the linker-object lists
TIntermSequence& linkerObjects = findLinkerObjects()->getSequence();
const TIntermSequence& unitLinkerObjects = unit.findLinkerObjects()->getSequence();
// Map by global name to unique ID to rationalize the same object having
// differing IDs in different trees.
TIdMaps idMaps;
long long idShift;
seedIdMap(idMaps, idShift);
remapIds(idMaps, idShift + 1, unit);
mergeBodies(infoSink, globals, unitGlobals);
bool mergeExistingOnly = false;
mergeGlobalUniformBlocks(infoSink, unit, mergeExistingOnly);
mergeLinkerObjects(infoSink, linkerObjects, unitLinkerObjects, unit.getStage());
ioAccessed.insert(unit.ioAccessed.begin(), unit.ioAccessed.end());
}
static const TString& getNameForIdMap(TIntermSymbol* symbol)
{
TShaderInterface si = symbol->getType().getShaderInterface();
if (si == EsiNone)
return symbol->getName();
else
return symbol->getType().getTypeName();
}
// Traverser that seeds an ID map with all built-ins, and tracks the
// maximum ID used, currently using (maximum ID + 1) as new symbol id shift seed.
// Level id will keep same after shifting.
// (It would be nice to put this in a function, but that causes warnings
// on having no bodies for the copy-constructor/operator=.)
class TBuiltInIdTraverser : public TIntermTraverser {
public:
TBuiltInIdTraverser(TIdMaps& idMaps) : idMaps(idMaps), idShift(0) { }
// If it's a built in, add it to the map.
virtual void visitSymbol(TIntermSymbol* symbol)
{
const TQualifier& qualifier = symbol->getType().getQualifier();
if (qualifier.builtIn != EbvNone) {
TShaderInterface si = symbol->getType().getShaderInterface();
idMaps[si][getNameForIdMap(symbol)] = symbol->getId();
}
idShift = (symbol->getId() & ~TSymbolTable::uniqueIdMask) |
std::max(idShift & TSymbolTable::uniqueIdMask,
symbol->getId() & TSymbolTable::uniqueIdMask);
}
long long getIdShift() const { return idShift; }
protected:
TBuiltInIdTraverser(TBuiltInIdTraverser&);
TBuiltInIdTraverser& operator=(TBuiltInIdTraverser&);
TIdMaps& idMaps;
long long idShift;
};
// Traverser that seeds an ID map with non-builtins.
// (It would be nice to put this in a function, but that causes warnings
// on having no bodies for the copy-constructor/operator=.)
class TUserIdTraverser : public TIntermTraverser {
public:
TUserIdTraverser(TIdMaps& idMaps) : idMaps(idMaps) { }
// If its a non-built-in global, add it to the map.
virtual void visitSymbol(TIntermSymbol* symbol)
{
const TQualifier& qualifier = symbol->getType().getQualifier();
if (qualifier.builtIn == EbvNone) {
TShaderInterface si = symbol->getType().getShaderInterface();
idMaps[si][getNameForIdMap(symbol)] = symbol->getId();
}
}
protected:
TUserIdTraverser(TUserIdTraverser&);
TUserIdTraverser& operator=(TUserIdTraverser&);
TIdMaps& idMaps; // over biggest id
};
// Initialize the the ID map with what we know of 'this' AST.
void TIntermediate::seedIdMap(TIdMaps& idMaps, long long& idShift)
{
// all built-ins everywhere need to align on IDs and contribute to the max ID
TBuiltInIdTraverser builtInIdTraverser(idMaps);
treeRoot->traverse(&builtInIdTraverser);
idShift = builtInIdTraverser.getIdShift() & TSymbolTable::uniqueIdMask;
// user variables in the linker object list need to align on ids
TUserIdTraverser userIdTraverser(idMaps);
findLinkerObjects()->traverse(&userIdTraverser);
}
// Traverser to map an AST ID to what was known from the seeding AST.
// (It would be nice to put this in a function, but that causes warnings
// on having no bodies for the copy-constructor/operator=.)
class TRemapIdTraverser : public TIntermTraverser {
public:
TRemapIdTraverser(const TIdMaps& idMaps, long long idShift) : idMaps(idMaps), idShift(idShift) { }
// Do the mapping:
// - if the same symbol, adopt the 'this' ID
// - otherwise, ensure a unique ID by shifting to a new space
virtual void visitSymbol(TIntermSymbol* symbol)
{
const TQualifier& qualifier = symbol->getType().getQualifier();
bool remapped = false;
if (qualifier.isLinkable() || qualifier.builtIn != EbvNone) {
TShaderInterface si = symbol->getType().getShaderInterface();
auto it = idMaps[si].find(getNameForIdMap(symbol));
if (it != idMaps[si].end()) {
uint64_t id = (symbol->getId() & ~TSymbolTable::uniqueIdMask) |
(it->second & TSymbolTable::uniqueIdMask);
symbol->changeId(id);
remapped = true;
}
}
if (!remapped)
symbol->changeId(symbol->getId() + idShift);
}
protected:
TRemapIdTraverser(TRemapIdTraverser&);
TRemapIdTraverser& operator=(TRemapIdTraverser&);
const TIdMaps& idMaps;
long long idShift;
};
void TIntermediate::remapIds(const TIdMaps& idMaps, long long idShift, TIntermediate& unit)
{
// Remap all IDs to either share or be unique, as dictated by the idMap and idShift.
TRemapIdTraverser idTraverser(idMaps, idShift);
unit.getTreeRoot()->traverse(&idTraverser);
}
//
// Merge the function bodies and global-level initializers from unitGlobals into globals.
// Will error check duplication of function bodies for the same signature.
//
void TIntermediate::mergeBodies(TInfoSink& infoSink, TIntermSequence& globals, const TIntermSequence& unitGlobals)
{
// TODO: link-time performance: Processing in alphabetical order will be faster
// Error check the global objects, not including the linker objects
for (unsigned int child = 0; child < globals.size() - 1; ++child) {
for (unsigned int unitChild = 0; unitChild < unitGlobals.size() - 1; ++unitChild) {
TIntermAggregate* body = globals[child]->getAsAggregate();
TIntermAggregate* unitBody = unitGlobals[unitChild]->getAsAggregate();
if (body && unitBody && body->getOp() == EOpFunction && unitBody->getOp() == EOpFunction && body->getName() == unitBody->getName()) {
error(infoSink, "Multiple function bodies in multiple compilation units for the same signature in the same stage:");
infoSink.info << " " << globals[child]->getAsAggregate()->getName() << "\n";
}
}
}
// Merge the global objects, just in front of the linker objects
globals.insert(globals.end() - 1, unitGlobals.begin(), unitGlobals.end() - 1);
}
static inline bool isSameInterface(TIntermSymbol* symbol, EShLanguage stage, TIntermSymbol* unitSymbol, EShLanguage unitStage) {
return // 1) same stage and same shader interface
(stage == unitStage && symbol->getType().getShaderInterface() == unitSymbol->getType().getShaderInterface()) ||
// 2) accross stages and both are uniform or buffer
(symbol->getQualifier().storage == EvqUniform && unitSymbol->getQualifier().storage == EvqUniform) ||
(symbol->getQualifier().storage == EvqBuffer && unitSymbol->getQualifier().storage == EvqBuffer) ||
// 3) in/out matched across stage boundary
(stage < unitStage && symbol->getQualifier().storage == EvqVaryingOut && unitSymbol->getQualifier().storage == EvqVaryingIn) ||
(unitStage < stage && symbol->getQualifier().storage == EvqVaryingIn && unitSymbol->getQualifier().storage == EvqVaryingOut);
}
//
// Global Unfiform block stores any default uniforms (i.e. uniforms without a block)
// If two linked stages declare the same member, they are meant to be the same uniform
// and need to be in the same block
// merge the members of different stages to allow them to be linked properly
// as a single block
//
void TIntermediate::mergeGlobalUniformBlocks(TInfoSink& infoSink, TIntermediate& unit, bool mergeExistingOnly)
{
TIntermSequence& linkerObjects = findLinkerObjects()->getSequence();
TIntermSequence& unitLinkerObjects = unit.findLinkerObjects()->getSequence();
// build lists of default blocks from the intermediates
TIntermSequence defaultBlocks;
TIntermSequence unitDefaultBlocks;
auto filter = [](TIntermSequence& list, TIntermNode* node) {
if (node->getAsSymbolNode()->getQualifier().defaultBlock) {
list.push_back(node);
}
};
std::for_each(linkerObjects.begin(), linkerObjects.end(),
[&defaultBlocks, &filter](TIntermNode* node) {
filter(defaultBlocks, node);
});
std::for_each(unitLinkerObjects.begin(), unitLinkerObjects.end(),
[&unitDefaultBlocks, &filter](TIntermNode* node) {
filter(unitDefaultBlocks, node);
});
auto itUnitBlock = unitDefaultBlocks.begin();
for (; itUnitBlock != unitDefaultBlocks.end(); itUnitBlock++) {
bool add = !mergeExistingOnly;
auto itBlock = defaultBlocks.begin();
for (; itBlock != defaultBlocks.end(); itBlock++) {
TIntermSymbol* block = (*itBlock)->getAsSymbolNode();
TIntermSymbol* unitBlock = (*itUnitBlock)->getAsSymbolNode();
assert(block && unitBlock);
// if the two default blocks match, then merge their definitions
if (block->getType().getTypeName() == unitBlock->getType().getTypeName() &&
block->getQualifier().storage == unitBlock->getQualifier().storage) {
add = false;
mergeBlockDefinitions(infoSink, block, unitBlock, &unit);
}
}
if (add) {
// push back on original list; won't change the size of the list we're iterating over
linkerObjects.push_back(*itUnitBlock);
}
}
}
void TIntermediate::mergeBlockDefinitions(TInfoSink& infoSink, TIntermSymbol* block, TIntermSymbol* unitBlock, TIntermediate* unit) {
if (block->getType().getTypeName() != unitBlock->getType().getTypeName() ||
block->getType().getBasicType() != unitBlock->getType().getBasicType() ||
block->getQualifier().storage != unitBlock->getQualifier().storage ||
block->getQualifier().layoutSet != unitBlock->getQualifier().layoutSet) {
// different block names likely means different blocks
return;
}
// merge the struct
// order of declarations doesn't matter and they matched based on member name
TTypeList* memberList = block->getType().getWritableStruct();
TTypeList* unitMemberList = unitBlock->getType().getWritableStruct();
// keep track of which members have changed position
// so we don't have to search the array again
std::map<unsigned int, unsigned int> memberIndexUpdates;
size_t memberListStartSize = memberList->size();
for (unsigned int i = 0; i < unitMemberList->size(); ++i) {
bool merge = true;
for (unsigned int j = 0; j < memberListStartSize; ++j) {
if ((*memberList)[j].type->getFieldName() == (*unitMemberList)[i].type->getFieldName()) {
merge = false;
const TType* memberType = (*memberList)[j].type;
const TType* unitMemberType = (*unitMemberList)[i].type;
// compare types
// don't need as many checks as when merging symbols, since
// initializers and most qualifiers are stripped when the member is moved into the block
if ((*memberType) != (*unitMemberType)) {
error(infoSink, "Types must match:");
infoSink.info << " " << memberType->getFieldName() << ": ";
infoSink.info << "\"" << memberType->getCompleteString() << "\" versus ";
infoSink.info << "\"" << unitMemberType->getCompleteString() << "\"\n";
}
memberIndexUpdates[i] = j;
}
}
if (merge) {
memberList->push_back((*unitMemberList)[i]);
memberIndexUpdates[i] = (unsigned int)memberList->size() - 1;
}
}
// update symbol node in unit tree,
// and other nodes that may reference it
class TMergeBlockTraverser : public TIntermTraverser {
public:
TMergeBlockTraverser(const TIntermSymbol* newSym)
: newSymbol(newSym), newType(nullptr), unit(nullptr), memberIndexUpdates(nullptr)
{
}
TMergeBlockTraverser(const TIntermSymbol* newSym, const glslang::TType* unitType, glslang::TIntermediate* unit,
const std::map<unsigned int, unsigned int>* memberIdxUpdates)
: TIntermTraverser(false, true), newSymbol(newSym), newType(unitType), unit(unit), memberIndexUpdates(memberIdxUpdates)
{
}
virtual ~TMergeBlockTraverser() {}
const TIntermSymbol* newSymbol;
const glslang::TType* newType; // shallow copy of the new type
glslang::TIntermediate* unit; // intermediate that is being updated
const std::map<unsigned int, unsigned int>* memberIndexUpdates;
virtual void visitSymbol(TIntermSymbol* symbol)
{
if (newSymbol->getAccessName() == symbol->getAccessName() &&
newSymbol->getQualifier().getBlockStorage() == symbol->getQualifier().getBlockStorage()) {
// Each symbol node may have a local copy of the block structure.
// Update those structures to match the new one post-merge
*(symbol->getWritableType().getWritableStruct()) = *(newSymbol->getType().getStruct());
}
}
virtual bool visitBinary(TVisit, glslang::TIntermBinary* node)
{
if (!unit || !newType || !memberIndexUpdates || memberIndexUpdates->empty())
return true;
if (node->getOp() == EOpIndexDirectStruct && node->getLeft()->getType() == *newType) {
// this is a dereference to a member of the block since the
// member list changed, need to update this to point to the
// right index
assert(node->getRight()->getAsConstantUnion());
glslang::TIntermConstantUnion* constNode = node->getRight()->getAsConstantUnion();
unsigned int memberIdx = constNode->getConstArray()[0].getUConst();
unsigned int newIdx = memberIndexUpdates->at(memberIdx);
TIntermTyped* newConstNode = unit->addConstantUnion(newIdx, node->getRight()->getLoc());
node->setRight(newConstNode);
delete constNode;
return true;
}
return true;
}
};
// 'this' may have symbols that are using the old block structure, so traverse the tree to update those
// in 'visitSymbol'
TMergeBlockTraverser finalLinkTraverser(block);
getTreeRoot()->traverse(&finalLinkTraverser);
// The 'unit' intermediate needs the block structures update, but also structure entry indices
// may have changed from the old block to the new one that it was merged into, so update those
// in 'visitBinary'
TType newType;
newType.shallowCopy(block->getType());
TMergeBlockTraverser unitFinalLinkTraverser(block, &newType, unit, &memberIndexUpdates);
unit->getTreeRoot()->traverse(&unitFinalLinkTraverser);
// update the member list
(*unitMemberList) = (*memberList);
}
//
// Merge the linker objects from unitLinkerObjects into linkerObjects.
// Duplication is expected and filtered out, but contradictions are an error.
//
void TIntermediate::mergeLinkerObjects(TInfoSink& infoSink, TIntermSequence& linkerObjects, const TIntermSequence& unitLinkerObjects, EShLanguage unitStage)
{
// Error check and merge the linker objects (duplicates should not be created)
std::size_t initialNumLinkerObjects = linkerObjects.size();
for (unsigned int unitLinkObj = 0; unitLinkObj < unitLinkerObjects.size(); ++unitLinkObj) {
bool merge = true;
for (std::size_t linkObj = 0; linkObj < initialNumLinkerObjects; ++linkObj) {
TIntermSymbol* symbol = linkerObjects[linkObj]->getAsSymbolNode();
TIntermSymbol* unitSymbol = unitLinkerObjects[unitLinkObj]->getAsSymbolNode();
assert(symbol && unitSymbol);
bool isSameSymbol = false;
// If they are both blocks in the same shader interface,
// match by the block-name, not the identifier name.
if (symbol->getType().getBasicType() == EbtBlock && unitSymbol->getType().getBasicType() == EbtBlock) {
if (isSameInterface(symbol, getStage(), unitSymbol, unitStage)) {
isSameSymbol = symbol->getType().getTypeName() == unitSymbol->getType().getTypeName();
}
}
else if (symbol->getName() == unitSymbol->getName())
isSameSymbol = true;
if (isSameSymbol) {
// filter out copy
merge = false;
// but if one has an initializer and the other does not, update
// the initializer
if (symbol->getConstArray().empty() && ! unitSymbol->getConstArray().empty())
symbol->setConstArray(unitSymbol->getConstArray());
// Similarly for binding
if (! symbol->getQualifier().hasBinding() && unitSymbol->getQualifier().hasBinding())
symbol->getQualifier().layoutBinding = unitSymbol->getQualifier().layoutBinding;
// Similarly for location
if (!symbol->getQualifier().hasLocation() && unitSymbol->getQualifier().hasLocation()) {
symbol->getQualifier().layoutLocation = unitSymbol->getQualifier().layoutLocation;
}
// Update implicit array sizes
if (symbol->getWritableType().isImplicitlySizedArray() && unitSymbol->getType().isImplicitlySizedArray()) {
if (unitSymbol->getType().getImplicitArraySize() > symbol->getType().getImplicitArraySize()){
symbol->getWritableType().updateImplicitArraySize(unitSymbol->getType().getImplicitArraySize());
}
}
else if (symbol->getWritableType().isImplicitlySizedArray() && unitSymbol->getType().isSizedArray()) {
if (symbol->getWritableType().getImplicitArraySize() > unitSymbol->getType().getOuterArraySize())
error(infoSink, "Implicit size of unsized array doesn't match same symbol among multiple shaders.");
}
else if (unitSymbol->getType().isImplicitlySizedArray() && symbol->getWritableType().isSizedArray()) {
if (unitSymbol->getType().getImplicitArraySize() > symbol->getWritableType().getOuterArraySize())
error(infoSink, "Implicit size of unsized array doesn't match same symbol among multiple shaders.");
}
// Update implicit array sizes
mergeImplicitArraySizes(symbol->getWritableType(), unitSymbol->getType());
// Check for consistent types/qualification/initializers etc.
mergeErrorCheck(infoSink, *symbol, *unitSymbol, unitStage);
}
// If different symbols, verify they arn't push_constant since there can only be one per stage
else if (symbol->getQualifier().isPushConstant() && unitSymbol->getQualifier().isPushConstant() && getStage() == unitStage)
error(infoSink, "Only one push_constant block is allowed per stage");
}
// Check conflicts between preset primitives and sizes of I/O variables among multiple geometry shaders
if (language == EShLangGeometry && unitStage == EShLangGeometry)
{
TIntermSymbol* unitSymbol = unitLinkerObjects[unitLinkObj]->getAsSymbolNode();
if (unitSymbol->isArray() && unitSymbol->getQualifier().storage == EvqVaryingIn && unitSymbol->getQualifier().builtIn == EbvNone)
if ((unitSymbol->getArraySizes()->isImplicitlySized() &&
unitSymbol->getArraySizes()->getImplicitSize() != TQualifier::mapGeometryToSize(getInputPrimitive())) ||
(! unitSymbol->getArraySizes()->isImplicitlySized() &&
unitSymbol->getArraySizes()->getDimSize(0) != TQualifier::mapGeometryToSize(getInputPrimitive())))
error(infoSink, "Not all array sizes match across all geometry shaders in the program");
}
if (merge) {
linkerObjects.push_back(unitLinkerObjects[unitLinkObj]);
// for anonymous blocks, check that their members don't conflict with other names
if (unitLinkerObjects[unitLinkObj]->getAsSymbolNode()->getBasicType() == EbtBlock &&
IsAnonymous(unitLinkerObjects[unitLinkObj]->getAsSymbolNode()->getName())) {
for (std::size_t linkObj = 0; linkObj < initialNumLinkerObjects; ++linkObj) {
TIntermSymbol* symbol = linkerObjects[linkObj]->getAsSymbolNode();
TIntermSymbol* unitSymbol = unitLinkerObjects[unitLinkObj]->getAsSymbolNode();
assert(symbol && unitSymbol);
auto checkName = [this, unitSymbol, &infoSink](const TString& name) {
for (unsigned int i = 0; i < unitSymbol->getType().getStruct()->size(); ++i) {
if (name == (*unitSymbol->getType().getStruct())[i].type->getFieldName()
&& !((*unitSymbol->getType().getStruct())[i].type->getQualifier().hasLocation()
|| unitSymbol->getType().getQualifier().hasLocation())
) {
error(infoSink, "Anonymous member name used for global variable or other anonymous member: ");
infoSink.info << (*unitSymbol->getType().getStruct())[i].type->getCompleteString() << "\n";
}
}
};
if (isSameInterface(symbol, getStage(), unitSymbol, unitStage)) {
checkName(symbol->getName());
// check members of other anonymous blocks
if (symbol->getBasicType() == EbtBlock && IsAnonymous(symbol->getName())) {
for (unsigned int i = 0; i < symbol->getType().getStruct()->size(); ++i) {
checkName((*symbol->getType().getStruct())[i].type->getFieldName());
}
}
}
}
}
}
}
}
// TODO 4.5 link functionality: cull distance array size checking
// Recursively merge the implicit array sizes through the objects' respective type trees.
void TIntermediate::mergeImplicitArraySizes(TType& type, const TType& unitType)
{
if (type.isUnsizedArray()) {
if (unitType.isUnsizedArray()) {
type.updateImplicitArraySize(unitType.getImplicitArraySize());
if (unitType.isArrayVariablyIndexed())
type.setArrayVariablyIndexed();
} else if (unitType.isSizedArray())
type.changeOuterArraySize(unitType.getOuterArraySize());
}
// Type mismatches are caught and reported after this, just be careful for now.
if (! type.isStruct() || ! unitType.isStruct() || type.getStruct()->size() != unitType.getStruct()->size())
return;
for (int i = 0; i < (int)type.getStruct()->size(); ++i)
mergeImplicitArraySizes(*(*type.getStruct())[i].type, *(*unitType.getStruct())[i].type);
}
//
// Compare two global objects from two compilation units and see if they match
// well enough. Rules can be different for intra- vs. cross-stage matching.
//
// This function only does one of intra- or cross-stage matching per call.
//
void TIntermediate::mergeErrorCheck(TInfoSink& infoSink, const TIntermSymbol& symbol, const TIntermSymbol& unitSymbol, EShLanguage unitStage)
{
bool crossStage = getStage() != unitStage;
bool writeTypeComparison = false;
bool errorReported = false;
bool printQualifiers = false;
bool printPrecision = false;
bool printType = false;
// Types have to match
{
// but, we make an exception if one is an implicit array and the other is sized
// or if the array sizes differ because of the extra array dimension on some in/out boundaries
bool arraysMatch = false;
if (isIoResizeArray(symbol.getType(), getStage()) || isIoResizeArray(unitSymbol.getType(), unitStage)) {
// if the arrays have an extra dimension because of the stage.
// compare dimensions while ignoring the outer dimension
unsigned int firstDim = isIoResizeArray(symbol.getType(), getStage()) ? 1 : 0;
unsigned int numDim = symbol.getArraySizes()
? symbol.getArraySizes()->getNumDims() : 0;
unsigned int unitFirstDim = isIoResizeArray(unitSymbol.getType(), unitStage) ? 1 : 0;
unsigned int unitNumDim = unitSymbol.getArraySizes()
? unitSymbol.getArraySizes()->getNumDims() : 0;
arraysMatch = (numDim - firstDim) == (unitNumDim - unitFirstDim);
// check that array sizes match as well
for (unsigned int i = 0; i < (numDim - firstDim) && arraysMatch; i++) {
if (symbol.getArraySizes()->getDimSize(firstDim + i) !=
unitSymbol.getArraySizes()->getDimSize(unitFirstDim + i)) {
arraysMatch = false;
break;
}
}
}
else {
arraysMatch = symbol.getType().sameArrayness(unitSymbol.getType()) ||
(symbol.getType().isArray() && unitSymbol.getType().isArray() &&
(symbol.getType().isImplicitlySizedArray() || unitSymbol.getType().isImplicitlySizedArray() ||
symbol.getType().isUnsizedArray() || unitSymbol.getType().isUnsizedArray()));
}
int lpidx = -1;
int rpidx = -1;
if (!symbol.getType().sameElementType(unitSymbol.getType(), &lpidx, &rpidx)) {
if (lpidx >= 0 && rpidx >= 0) {
error(infoSink, "Member names and types must match:", unitStage);
infoSink.info << " Block: " << symbol.getType().getTypeName() << "\n";
infoSink.info << " " << StageName(getStage()) << " stage: \""
<< (*symbol.getType().getStruct())[lpidx].type->getCompleteString(true, false, false, true,
(*symbol.getType().getStruct())[lpidx].type->getFieldName()) << "\"\n";
infoSink.info << " " << StageName(unitStage) << " stage: \""
<< (*unitSymbol.getType().getStruct())[rpidx].type->getCompleteString(true, false, false, true,
(*unitSymbol.getType().getStruct())[rpidx].type->getFieldName()) << "\"\n";
errorReported = true;
} else if (lpidx >= 0 && rpidx == -1) {
TString errmsg = StageName(getStage());
errmsg.append(" block member has no corresponding member in ").append(StageName(unitStage)).append(" block:");
error(infoSink, errmsg.c_str(), unitStage);
infoSink.info << " " << StageName(getStage()) << " stage: Block: " << symbol.getType().getTypeName() << ", Member: "
<< (*symbol.getType().getStruct())[lpidx].type->getFieldName() << "\n";
infoSink.info << " " << StageName(unitStage) << " stage: Block: " << unitSymbol.getType().getTypeName() << ", Member: n/a \n";
errorReported = true;
} else if (lpidx == -1 && rpidx >= 0) {
TString errmsg = StageName(unitStage);
errmsg.append(" block member has no corresponding member in ").append(StageName(getStage())).append(" block:");
error(infoSink, errmsg.c_str(), unitStage);
infoSink.info << " " << StageName(unitStage) << " stage: Block: " << unitSymbol.getType().getTypeName() << ", Member: "
<< (*unitSymbol.getType().getStruct())[rpidx].type->getFieldName() << "\n";
infoSink.info << " " << StageName(getStage()) << " stage: Block: " << symbol.getType().getTypeName() << ", Member: n/a \n";
errorReported = true;
} else {
error(infoSink, "Types must match:", unitStage);
writeTypeComparison = true;
printType = true;
}
} else if (!arraysMatch) {
error(infoSink, "Array sizes must be compatible:", unitStage);
writeTypeComparison = true;
printType = true;
} else if (!symbol.getType().sameTypeParameters(unitSymbol.getType())) {
error(infoSink, "Type parameters must match:", unitStage);
writeTypeComparison = true;
printType = true;
}
}
// Interface block member-wise layout qualifiers have to match
if (symbol.getType().getBasicType() == EbtBlock && unitSymbol.getType().getBasicType() == EbtBlock &&
symbol.getType().getStruct() && unitSymbol.getType().getStruct() &&
symbol.getType().sameStructType(unitSymbol.getType())) {
unsigned int li = 0;
unsigned int ri = 0;
while (li < symbol.getType().getStruct()->size() && ri < unitSymbol.getType().getStruct()->size()) {
if ((*symbol.getType().getStruct())[li].type->hiddenMember()) {
++li;
continue;
}
if ((*unitSymbol.getType().getStruct())[ri].type->hiddenMember()) {
++ri;
continue;
}
const TQualifier& qualifier = (*symbol.getType().getStruct())[li].type->getQualifier();
const TQualifier & unitQualifier = (*unitSymbol.getType().getStruct())[ri].type->getQualifier();
bool layoutQualifierError = false;
if (qualifier.layoutMatrix != unitQualifier.layoutMatrix) {
error(infoSink, "Interface block member layout matrix qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (qualifier.layoutOffset != unitQualifier.layoutOffset) {
error(infoSink, "Interface block member layout offset qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (qualifier.layoutAlign != unitQualifier.layoutAlign) {
error(infoSink, "Interface block member layout align qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (qualifier.layoutLocation != unitQualifier.layoutLocation) {
error(infoSink, "Interface block member layout location qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (qualifier.layoutComponent != unitQualifier.layoutComponent) {
error(infoSink, "Interface block member layout component qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (layoutQualifierError) {
infoSink.info << " " << StageName(getStage()) << " stage: Block: " << symbol.getType().getTypeName() << ", Member: "
<< (*symbol.getType().getStruct())[li].type->getFieldName() << " \""
<< (*symbol.getType().getStruct())[li].type->getCompleteString(true, true, false, false) << "\"\n";
infoSink.info << " " << StageName(unitStage) << " stage: Block: " << unitSymbol.getType().getTypeName() << ", Member: "
<< (*unitSymbol.getType().getStruct())[ri].type->getFieldName() << " \""
<< (*unitSymbol.getType().getStruct())[ri].type->getCompleteString(true, true, false, false) << "\"\n";
errorReported = true;
}
++li;
++ri;
}
}
bool isInOut = crossStage &&
((symbol.getQualifier().storage == EvqVaryingIn && unitSymbol.getQualifier().storage == EvqVaryingOut) ||
(symbol.getQualifier().storage == EvqVaryingOut && unitSymbol.getQualifier().storage == EvqVaryingIn));
// Qualifiers have to (almost) match
// Storage...
if (!isInOut && symbol.getQualifier().storage != unitSymbol.getQualifier().storage) {
error(infoSink, "Storage qualifiers must match:", unitStage);
writeTypeComparison = true;
printQualifiers = true;
}
// Uniform and buffer blocks must either both have an instance name, or
// must both be anonymous. The names don't need to match though.
if (symbol.getQualifier().isUniformOrBuffer() &&
(IsAnonymous(symbol.getName()) != IsAnonymous(unitSymbol.getName()))) {
error(infoSink, "Matched Uniform or Storage blocks must all be anonymous,"
" or all be named:", unitStage);
writeTypeComparison = true;
}
if (symbol.getQualifier().storage == unitSymbol.getQualifier().storage &&
(IsAnonymous(symbol.getName()) != IsAnonymous(unitSymbol.getName()) ||
(!IsAnonymous(symbol.getName()) && symbol.getName() != unitSymbol.getName()))) {
warn(infoSink, "Matched shader interfaces are using different instance names.", unitStage);
writeTypeComparison = true;
}
// Precision...
if (!isInOut && symbol.getQualifier().precision != unitSymbol.getQualifier().precision) {
error(infoSink, "Precision qualifiers must match:", unitStage);
writeTypeComparison = true;
printPrecision = true;
}
// Invariance...
if (! crossStage && symbol.getQualifier().invariant != unitSymbol.getQualifier().invariant) {
error(infoSink, "Presence of invariant qualifier must match:", unitStage);
writeTypeComparison = true;
printQualifiers = true;
}
// Precise...
if (! crossStage && symbol.getQualifier().isNoContraction() != unitSymbol.getQualifier().isNoContraction()) {
error(infoSink, "Presence of precise qualifier must match:", unitStage);
writeTypeComparison = true;
printPrecision = true;
}
// Auxiliary and interpolation...
// "interpolation qualification (e.g., flat) and auxiliary qualification (e.g. centroid) may differ.
// These mismatches are allowed between any pair of stages ...
// those provided in the fragment shader supersede those provided in previous stages."
if (!crossStage &&
(symbol.getQualifier().centroid != unitSymbol.getQualifier().centroid ||
symbol.getQualifier().smooth != unitSymbol.getQualifier().smooth ||
symbol.getQualifier().flat != unitSymbol.getQualifier().flat ||
symbol.getQualifier().isSample()!= unitSymbol.getQualifier().isSample() ||
symbol.getQualifier().isPatch() != unitSymbol.getQualifier().isPatch() ||
symbol.getQualifier().isNonPerspective() != unitSymbol.getQualifier().isNonPerspective())) {
error(infoSink, "Interpolation and auxiliary storage qualifiers must match:", unitStage);
writeTypeComparison = true;
printQualifiers = true;
}
// Memory...
bool memoryQualifierError = false;
if (symbol.getQualifier().coherent != unitSymbol.getQualifier().coherent) {
error(infoSink, "Memory coherent qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().devicecoherent != unitSymbol.getQualifier().devicecoherent) {
error(infoSink, "Memory devicecoherent qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().queuefamilycoherent != unitSymbol.getQualifier().queuefamilycoherent) {
error(infoSink, "Memory queuefamilycoherent qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().workgroupcoherent != unitSymbol.getQualifier().workgroupcoherent) {
error(infoSink, "Memory workgroupcoherent qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().subgroupcoherent != unitSymbol.getQualifier().subgroupcoherent) {
error(infoSink, "Memory subgroupcoherent qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().shadercallcoherent != unitSymbol.getQualifier().shadercallcoherent) {
error(infoSink, "Memory shadercallcoherent qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().nonprivate != unitSymbol.getQualifier().nonprivate) {
error(infoSink, "Memory nonprivate qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().volatil != unitSymbol.getQualifier().volatil) {
error(infoSink, "Memory volatil qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().restrict != unitSymbol.getQualifier().restrict) {
error(infoSink, "Memory restrict qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().readonly != unitSymbol.getQualifier().readonly) {
error(infoSink, "Memory readonly qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (symbol.getQualifier().writeonly != unitSymbol.getQualifier().writeonly) {
error(infoSink, "Memory writeonly qualifier must match:", unitStage);
memoryQualifierError = true;
}
if (memoryQualifierError) {
writeTypeComparison = true;
printQualifiers = true;
}
// Layouts...
// TODO: 4.4 enhanced layouts: Generalize to include offset/align: current spec
// requires separate user-supplied offset from actual computed offset, but
// current implementation only has one offset.
bool layoutQualifierError = false;
if (symbol.getQualifier().layoutMatrix != unitSymbol.getQualifier().layoutMatrix) {
error(infoSink, "Layout matrix qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (symbol.getQualifier().layoutPacking != unitSymbol.getQualifier().layoutPacking) {
error(infoSink, "Layout packing qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (symbol.getQualifier().hasLocation() && unitSymbol.getQualifier().hasLocation() && symbol.getQualifier().layoutLocation != unitSymbol.getQualifier().layoutLocation) {
error(infoSink, "Layout location qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (symbol.getQualifier().layoutComponent != unitSymbol.getQualifier().layoutComponent) {
error(infoSink, "Layout component qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (symbol.getQualifier().layoutIndex != unitSymbol.getQualifier().layoutIndex) {
error(infoSink, "Layout index qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (symbol.getQualifier().hasBinding() && unitSymbol.getQualifier().hasBinding() && symbol.getQualifier().layoutBinding != unitSymbol.getQualifier().layoutBinding) {
error(infoSink, "Layout binding qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (symbol.getQualifier().hasBinding() && (symbol.getQualifier().layoutOffset != unitSymbol.getQualifier().layoutOffset)) {
error(infoSink, "Layout offset qualifier must match:", unitStage);
layoutQualifierError = true;
}
if (layoutQualifierError) {
writeTypeComparison = true;
printQualifiers = true;
}
// Initializers have to match, if both are present, and if we don't already know the types don't match
if (! writeTypeComparison && ! errorReported) {
if (! symbol.getConstArray().empty() && ! unitSymbol.getConstArray().empty()) {
if (symbol.getConstArray() != unitSymbol.getConstArray()) {
error(infoSink, "Initializers must match:", unitStage);
infoSink.info << " " << symbol.getName() << "\n";
}
}
}
if (writeTypeComparison) {
if (symbol.getType().getBasicType() == EbtBlock && unitSymbol.getType().getBasicType() == EbtBlock &&
symbol.getType().getStruct() && unitSymbol.getType().getStruct()) {
if (printType) {
infoSink.info << " " << StageName(getStage()) << " stage: \"" << symbol.getType().getCompleteString(true, printQualifiers, printPrecision,
printType, symbol.getName(), symbol.getType().getTypeName()) << "\"\n";
infoSink.info << " " << StageName(unitStage) << " stage: \"" << unitSymbol.getType().getCompleteString(true, printQualifiers, printPrecision,
printType, unitSymbol.getName(), unitSymbol.getType().getTypeName()) << "\"\n";
} else {
infoSink.info << " " << StageName(getStage()) << " stage: Block: " << symbol.getType().getTypeName() << " Instance: " << symbol.getName()
<< ": \"" << symbol.getType().getCompleteString(true, printQualifiers, printPrecision, printType) << "\"\n";
infoSink.info << " " << StageName(unitStage) << " stage: Block: " << unitSymbol.getType().getTypeName() << " Instance: " << unitSymbol.getName()
<< ": \"" << unitSymbol.getType().getCompleteString(true, printQualifiers, printPrecision, printType) << "\"\n";
}
} else {
if (printType) {
infoSink.info << " " << StageName(getStage()) << " stage: \""
<< symbol.getType().getCompleteString(true, printQualifiers, printPrecision, printType, symbol.getName()) << "\"\n";
infoSink.info << " " << StageName(unitStage) << " stage: \""
<< unitSymbol.getType().getCompleteString(true, printQualifiers, printPrecision, printType, unitSymbol.getName()) << "\"\n";
} else {
infoSink.info << " " << StageName(getStage()) << " stage: " << symbol.getName() << " \""
<< symbol.getType().getCompleteString(true, printQualifiers, printPrecision, printType) << "\"\n";
infoSink.info << " " << StageName(unitStage) << " stage: " << unitSymbol.getName() << " \""
<< unitSymbol.getType().getCompleteString(true, printQualifiers, printPrecision, printType) << "\"\n";
}
}
}
}
void TIntermediate::sharedBlockCheck(TInfoSink& infoSink)
{
bool has_shared_block = false;
bool has_shared_non_block = false;
TIntermSequence& linkObjects = findLinkerObjects()->getSequence();
for (size_t i = 0; i < linkObjects.size(); ++i) {
const TType& type = linkObjects[i]->getAsTyped()->getType();
const TQualifier& qualifier = type.getQualifier();
if (qualifier.storage == glslang::EvqShared) {
if (type.getBasicType() == glslang::EbtBlock)
has_shared_block = true;
else
has_shared_non_block = true;
}
}
if (has_shared_block && has_shared_non_block)
error(infoSink, "cannot mix use of shared variables inside and outside blocks");
}
//
// Do final link-time error checking of a complete (merged) intermediate representation.
// (Much error checking was done during merging).
//
// Also, lock in defaults of things not set, including array sizes.
//
void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
{
if (getTreeRoot() == nullptr)
return;
if (numEntryPoints < 1) {
if (getSource() == EShSourceGlsl)
error(infoSink, "Missing entry point: Each stage requires one entry point");
else
warn(infoSink, "Entry point not found");
}
// recursion and missing body checking
checkCallGraphCycles(infoSink);
checkCallGraphBodies(infoSink, keepUncalled);
// overlap/alias/missing I/O, etc.
inOutLocationCheck(infoSink);
if (getNumPushConstants() > 1)
error(infoSink, "Only one push_constant block is allowed per stage");
// invocations
if (invocations == TQualifier::layoutNotSet)
invocations = 1;
if (inIoAccessed("gl_ClipDistance") && inIoAccessed("gl_ClipVertex"))
error(infoSink, "Can only use one of gl_ClipDistance or gl_ClipVertex (gl_ClipDistance is preferred)");
if (inIoAccessed("gl_CullDistance") && inIoAccessed("gl_ClipVertex"))
error(infoSink, "Can only use one of gl_CullDistance or gl_ClipVertex (gl_ClipDistance is preferred)");
if (userOutputUsed() && (inIoAccessed("gl_FragColor") || inIoAccessed("gl_FragData")))
error(infoSink, "Cannot use gl_FragColor or gl_FragData when using user-defined outputs");
if (inIoAccessed("gl_FragColor") && inIoAccessed("gl_FragData"))
error(infoSink, "Cannot use both gl_FragColor and gl_FragData");
for (size_t b = 0; b < xfbBuffers.size(); ++b) {
if (xfbBuffers[b].contains64BitType)
RoundToPow2(xfbBuffers[b].implicitStride, 8);
else if (xfbBuffers[b].contains32BitType)
RoundToPow2(xfbBuffers[b].implicitStride, 4);
else if (xfbBuffers[b].contains16BitType)
RoundToPow2(xfbBuffers[b].implicitStride, 2);
// "It is a compile-time or link-time error to have
// any xfb_offset that overflows xfb_stride, whether stated on declarations before or after the xfb_stride, or
// in different compilation units. While xfb_stride can be declared multiple times for the same buffer, it is a
// compile-time or link-time error to have different values specified for the stride for the same buffer."
if (xfbBuffers[b].stride != TQualifier::layoutXfbStrideEnd && xfbBuffers[b].implicitStride > xfbBuffers[b].stride) {
error(infoSink, "xfb_stride is too small to hold all buffer entries:");
infoSink.info.prefix(EPrefixError);
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << ", minimum stride needed: " << xfbBuffers[b].implicitStride << "\n";
}
if (xfbBuffers[b].stride == TQualifier::layoutXfbStrideEnd)
xfbBuffers[b].stride = xfbBuffers[b].implicitStride;
// "If the buffer is capturing any
// outputs with double-precision or 64-bit integer components, the stride must be a multiple of 8, otherwise it must be a
// multiple of 4, or a compile-time or link-time error results."
if (xfbBuffers[b].contains64BitType && ! IsMultipleOfPow2(xfbBuffers[b].stride, 8)) {
error(infoSink, "xfb_stride must be multiple of 8 for buffer holding a double or 64-bit integer:");
infoSink.info.prefix(EPrefixError);
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
} else if (xfbBuffers[b].contains32BitType && ! IsMultipleOfPow2(xfbBuffers[b].stride, 4)) {
error(infoSink, "xfb_stride must be multiple of 4:");
infoSink.info.prefix(EPrefixError);
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
}
// "If the buffer is capturing any
// outputs with half-precision or 16-bit integer components, the stride must be a multiple of 2"
else if (xfbBuffers[b].contains16BitType && ! IsMultipleOfPow2(xfbBuffers[b].stride, 2)) {
error(infoSink, "xfb_stride must be multiple of 2 for buffer holding a half float or 16-bit integer:");
infoSink.info.prefix(EPrefixError);
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
}
// "The resulting stride (implicit or explicit), when divided by 4, must be less than or equal to the
// implementation-dependent constant gl_MaxTransformFeedbackInterleavedComponents."
if (xfbBuffers[b].stride > (unsigned int)(4 * resources->maxTransformFeedbackInterleavedComponents)) {
error(infoSink, "xfb_stride is too large:");
infoSink.info.prefix(EPrefixError);
infoSink.info << " xfb_buffer " << (unsigned int)b << ", components (1/4 stride) needed are " << xfbBuffers[b].stride/4 << ", gl_MaxTransformFeedbackInterleavedComponents is " << resources->maxTransformFeedbackInterleavedComponents << "\n";
}
}
switch (language) {
case EShLangVertex:
break;
case EShLangTessControl:
if (vertices == TQualifier::layoutNotSet)
error(infoSink, "At least one shader must specify an output layout(vertices=...)");
break;
case EShLangTessEvaluation:
if (getSource() == EShSourceGlsl) {
if (inputPrimitive == ElgNone)
error(infoSink, "At least one shader must specify an input layout primitive");
if (vertexSpacing == EvsNone)
vertexSpacing = EvsEqual;
if (vertexOrder == EvoNone)
vertexOrder = EvoCcw;
}
break;
case EShLangGeometry:
if (inputPrimitive == ElgNone)
error(infoSink, "At least one shader must specify an input layout primitive");
if (outputPrimitive == ElgNone)
error(infoSink, "At least one shader must specify an output layout primitive");
if (vertices == TQualifier::layoutNotSet)
error(infoSink, "At least one shader must specify a layout(max_vertices = value)");
break;
case EShLangFragment:
// for GL_ARB_post_depth_coverage, EarlyFragmentTest is set automatically in
// ParseHelper.cpp. So if we reach here, this must be GL_EXT_post_depth_coverage
// requiring explicit early_fragment_tests
if (getPostDepthCoverage() && !getEarlyFragmentTests())
error(infoSink, "post_depth_coverage requires early_fragment_tests");
break;
case EShLangCompute:
sharedBlockCheck(infoSink);
break;
case EShLangRayGen:
case EShLangIntersect:
case EShLangAnyHit:
case EShLangClosestHit:
case EShLangMiss:
case EShLangCallable:
if (numShaderRecordBlocks > 1)
error(infoSink, "Only one shaderRecordNV buffer block is allowed per stage");
break;
case EShLangMesh:
// NV_mesh_shader doesn't allow use of both single-view and per-view builtins.
if (inIoAccessed("gl_Position") && inIoAccessed("gl_PositionPerViewNV"))
error(infoSink, "Can only use one of gl_Position or gl_PositionPerViewNV");
if (inIoAccessed("gl_ClipDistance") && inIoAccessed("gl_ClipDistancePerViewNV"))
error(infoSink, "Can only use one of gl_ClipDistance or gl_ClipDistancePerViewNV");
if (inIoAccessed("gl_CullDistance") && inIoAccessed("gl_CullDistancePerViewNV"))
error(infoSink, "Can only use one of gl_CullDistance or gl_CullDistancePerViewNV");
if (inIoAccessed("gl_Layer") && inIoAccessed("gl_LayerPerViewNV"))
error(infoSink, "Can only use one of gl_Layer or gl_LayerPerViewNV");
if (inIoAccessed("gl_ViewportMask") && inIoAccessed("gl_ViewportMaskPerViewNV"))
error(infoSink, "Can only use one of gl_ViewportMask or gl_ViewportMaskPerViewNV");
if (outputPrimitive == ElgNone)
error(infoSink, "At least one shader must specify an output layout primitive");
if (vertices == TQualifier::layoutNotSet)
error(infoSink, "At least one shader must specify a layout(max_vertices = value)");
if (primitives == TQualifier::layoutNotSet)
error(infoSink, "At least one shader must specify a layout(max_primitives = value)");
[[fallthrough]];
case EShLangTask:
if (numTaskNVBlocks > 1)
error(infoSink, "Only one taskNV interface block is allowed per shader");
if (numTaskEXTPayloads > 1)
error(infoSink, "Only single variable of type taskPayloadSharedEXT is allowed per shader");
sharedBlockCheck(infoSink);
break;
default:
error(infoSink, "Unknown Stage.");
break;
}
// Process the tree for any node-specific work.
class TFinalLinkTraverser : public TIntermTraverser {
public:
TFinalLinkTraverser() { }
virtual ~TFinalLinkTraverser() { }
virtual void visitSymbol(TIntermSymbol* symbol)
{
// Implicitly size arrays.
// If an unsized array is left as unsized, it effectively
// becomes run-time sized.
symbol->getWritableType().adoptImplicitArraySizes(false);
}
} finalLinkTraverser;
treeRoot->traverse(&finalLinkTraverser);
}
//
// See if the call graph contains any static recursion, which is disallowed
// by the specification.
//
void TIntermediate::checkCallGraphCycles(TInfoSink& infoSink)
{
// Clear fields we'll use for this.
for (TGraph::iterator call = callGraph.begin(); call != callGraph.end(); ++call) {
call->visited = false;
call->currentPath = false;
call->errorGiven = false;
}
//
// Loop, looking for a new connected subgraph. One subgraph is handled per loop iteration.
//
TCall* newRoot;
do {
// See if we have unvisited parts of the graph.
newRoot = nullptr;
for (TGraph::iterator call = callGraph.begin(); call != callGraph.end(); ++call) {
if (! call->visited) {
newRoot = &(*call);
break;
}
}
// If not, we are done.
if (! newRoot)
break;
// Otherwise, we found a new subgraph, process it:
// See what all can be reached by this new root, and if any of
// that is recursive. This is done by depth-first traversals, seeing
// if a new call is found that was already in the currentPath (a back edge),
// thereby detecting recursion.
std::list<TCall*> stack;
newRoot->currentPath = true; // currentPath will be true iff it is on the stack
stack.push_back(newRoot);
while (! stack.empty()) {
// get a caller
TCall* call = stack.back();
// Add to the stack just one callee.
// This algorithm always terminates, because only !visited and !currentPath causes a push
// and all pushes change currentPath to true, and all pops change visited to true.
TGraph::iterator child = callGraph.begin();
for (; child != callGraph.end(); ++child) {
// If we already visited this node, its whole subgraph has already been processed, so skip it.
if (child->visited)
continue;
if (call->callee == child->caller) {
if (child->currentPath) {
// Then, we found a back edge
if (! child->errorGiven) {
error(infoSink, "Recursion detected:");
infoSink.info << " " << call->callee << " calling " << child->callee << "\n";
child->errorGiven = true;
recursive = true;
}
} else {
child->currentPath = true;
stack.push_back(&(*child));
break;
}
}
}
if (child == callGraph.end()) {
// no more callees, we bottomed out, never look at this node again
stack.back()->currentPath = false;
stack.back()->visited = true;
stack.pop_back();
}
} // end while, meaning nothing left to process in this subtree
} while (newRoot); // redundant loop check; should always exit via the 'break' above
}
//
// See which functions are reachable from the entry point and which have bodies.
// Reachable ones with missing bodies are errors.
// Unreachable bodies are dead code.
//
void TIntermediate::checkCallGraphBodies(TInfoSink& infoSink, bool keepUncalled)
{
// Clear fields we'll use for this.
for (TGraph::iterator call = callGraph.begin(); call != callGraph.end(); ++call) {
call->visited = false;
call->calleeBodyPosition = -1;
}
// The top level of the AST includes function definitions (bodies).
// Compare these to function calls in the call graph.
// We'll end up knowing which have bodies, and if so,
// how to map the call-graph node to the location in the AST.
TIntermSequence &functionSequence = getTreeRoot()->getAsAggregate()->getSequence();
std::vector<bool> reachable(functionSequence.size(), true); // so that non-functions are reachable
for (int f = 0; f < (int)functionSequence.size(); ++f) {
glslang::TIntermAggregate* node = functionSequence[f]->getAsAggregate();
if (node && (node->getOp() == glslang::EOpFunction)) {
if (node->getName().compare(getEntryPointMangledName().c_str()) != 0)
reachable[f] = false; // so that function bodies are unreachable, until proven otherwise
for (TGraph::iterator call = callGraph.begin(); call != callGraph.end(); ++call) {
if (call->callee == node->getName())
call->calleeBodyPosition = f;
}
}
}
// Start call-graph traversal by visiting the entry point nodes.
for (TGraph::iterator call = callGraph.begin(); call != callGraph.end(); ++call) {
if (call->caller.compare(getEntryPointMangledName().c_str()) == 0)
call->visited = true;
}
// Propagate 'visited' through the call-graph to every part of the graph it
// can reach (seeded with the entry-point setting above).
bool changed;
do {
changed = false;
for (auto call1 = callGraph.begin(); call1 != callGraph.end(); ++call1) {
if (call1->visited) {
for (TGraph::iterator call2 = callGraph.begin(); call2 != callGraph.end(); ++call2) {
if (! call2->visited) {
if (call1->callee == call2->caller) {
changed = true;
call2->visited = true;
}
}
}
}
}
} while (changed);
// Any call-graph node set to visited but without a callee body is an error.
for (TGraph::iterator call = callGraph.begin(); call != callGraph.end(); ++call) {
if (call->visited) {
if (call->calleeBodyPosition == -1) {
error(infoSink, "No function definition (body) found: ");
infoSink.info << " " << call->callee << "\n";
} else
reachable[call->calleeBodyPosition] = true;
}
}
// Bodies in the AST not reached by the call graph are dead;
// clear them out, since they can't be reached and also can't
// be translated further due to possibility of being ill defined.
if (! keepUncalled) {
for (int f = 0; f < (int)functionSequence.size(); ++f) {
if (! reachable[f])
{
resetTopLevelUncalledStatus(functionSequence[f]->getAsAggregate()->getName());
functionSequence[f] = nullptr;
}
}
functionSequence.erase(std::remove(functionSequence.begin(), functionSequence.end(), nullptr), functionSequence.end());
}
}
//
// Satisfy rules for location qualifiers on inputs and outputs
//
void TIntermediate::inOutLocationCheck(TInfoSink& infoSink)
{
// ES 3.0 requires all outputs to have location qualifiers if there is more than one output
bool fragOutWithNoLocation = false;
int numFragOut = 0;
// TODO: linker functionality: location collision checking
TIntermSequence& linkObjects = findLinkerObjects()->getSequence();
for (size_t i = 0; i < linkObjects.size(); ++i) {
const TType& type = linkObjects[i]->getAsTyped()->getType();
const TQualifier& qualifier = type.getQualifier();
if (language == EShLangFragment) {
if (qualifier.storage == EvqVaryingOut && qualifier.builtIn == EbvNone) {
++numFragOut;
if (!qualifier.hasAnyLocation())
fragOutWithNoLocation = true;
}
}
}
if (isEsProfile()) {
if (numFragOut > 1 && fragOutWithNoLocation)
error(infoSink, "when more than one fragment shader output, all must have location qualifiers");
}
}
TIntermAggregate* TIntermediate::findLinkerObjects() const
{
// Get the top-level globals
TIntermSequence& globals = treeRoot->getAsAggregate()->getSequence();
// Get the last member of the sequences, expected to be the linker-object lists
assert(globals.back()->getAsAggregate()->getOp() == EOpLinkerObjects);
return globals.back()->getAsAggregate();
}
// See if a variable was both a user-declared output and used.
// Note: the spec discusses writing to one, but this looks at read or write, which
// is more useful, and perhaps the spec should be changed to reflect that.
bool TIntermediate::userOutputUsed() const
{
const TIntermSequence& linkerObjects = findLinkerObjects()->getSequence();
bool found = false;
for (size_t i = 0; i < linkerObjects.size(); ++i) {
const TIntermSymbol& symbolNode = *linkerObjects[i]->getAsSymbolNode();
if (symbolNode.getQualifier().storage == EvqVaryingOut &&
symbolNode.getName().compare(0, 3, "gl_") != 0 &&
inIoAccessed(symbolNode.getName())) {
found = true;
break;
}
}
return found;
}
// Accumulate locations used for inputs, outputs, and uniforms, payload, callable data, and tileImageEXT
// and check for collisions as the accumulation is done.
//
// Returns < 0 if no collision, >= 0 if collision and the value returned is a colliding value.
//
// typeCollision is set to true if there is no direct collision, but the types in the same location
// are different.
//
int TIntermediate::addUsedLocation(const TQualifier& qualifier, const TType& type, bool& typeCollision)
{
typeCollision = false;
int set;
if (qualifier.isPipeInput())
set = 0;
else if (qualifier.isPipeOutput())
set = 1;
else if (qualifier.storage == EvqUniform)
set = 2;
else if (qualifier.storage == EvqBuffer)
set = 3;
else if (qualifier.storage == EvqTileImageEXT)
set = 4;
else if (qualifier.isAnyPayload())
set = 0;
else if (qualifier.isAnyCallable())
set = 1;
else if (qualifier.isHitObjectAttrNV())
set = 2;
else
return -1;
int size;
if (qualifier.isAnyPayload() || qualifier.isAnyCallable()) {
size = 1;
} else if (qualifier.isUniformOrBuffer() || qualifier.isTaskMemory()) {
if (type.isSizedArray())
size = type.getCumulativeArraySize();
else
size = 1;
} else {
// Strip off the outer array dimension for those having an extra one.
if (type.isArray() && qualifier.isArrayedIo(language)) {
TType elementType(type, 0);
size = computeTypeLocationSize(elementType, language);
} else
size = computeTypeLocationSize(type, language);
}
// Locations, and components within locations.
//
// Almost always, dealing with components means a single location is involved.
// The exception is a dvec3. From the spec:
//
// "A dvec3 will consume all four components of the first location and components 0 and 1 of
// the second location. This leaves components 2 and 3 available for other component-qualified
// declarations."
//
// That means, without ever mentioning a component, a component range
// for a different location gets specified, if it's not a vertex shader input. (!)
// (A vertex shader input will show using only one location, even for a dvec3/4.)
//
// So, for the case of dvec3, we need two independent ioRanges.
//
// For raytracing IO (payloads and callabledata) each declaration occupies a single
// slot irrespective of type.
int collision = -1; // no collision
if (qualifier.isAnyPayload() || qualifier.isAnyCallable() || qualifier.isHitObjectAttrNV()) {
TRange range(qualifier.layoutLocation, qualifier.layoutLocation);
collision = checkLocationRT(set, qualifier.layoutLocation);
if (collision < 0)
usedIoRT[set].push_back(range);
return collision;
}
if (size == 2 && type.getBasicType() == EbtDouble && type.getVectorSize() == 3 &&
(qualifier.isPipeInput() || qualifier.isPipeOutput())) {
// Dealing with dvec3 in/out split across two locations.
// Need two io-ranges.
// The case where the dvec3 doesn't start at component 0 was previously caught as overflow.
// First range:
TRange locationRange(qualifier.layoutLocation, qualifier.layoutLocation);
TRange componentRange(0, 3);
TIoRange range(locationRange, componentRange, type.getBasicType(), 0, qualifier.centroid, qualifier.smooth, qualifier.flat);
// check for collisions
collision = checkLocationRange(set, range, type, typeCollision);
if (collision < 0) {
usedIo[set].push_back(range);
// Second range:
TRange locationRange2(qualifier.layoutLocation + 1, qualifier.layoutLocation + 1);
TRange componentRange2(0, 1);
TIoRange range2(locationRange2, componentRange2, type.getBasicType(), 0, qualifier.centroid, qualifier.smooth, qualifier.flat);
// check for collisions
collision = checkLocationRange(set, range2, type, typeCollision);
if (collision < 0)
usedIo[set].push_back(range2);
}
return collision;
}
// Not a dvec3 in/out split across two locations, generic path.
// Need a single IO-range block.
TRange locationRange(qualifier.layoutLocation, qualifier.layoutLocation + size - 1);
TRange componentRange(0, 3);
if (qualifier.hasComponent() || type.getVectorSize() > 0) {
int consumedComponents = type.getVectorSize() * (type.getBasicType() == EbtDouble ? 2 : 1);
if (qualifier.hasComponent())
componentRange.start = qualifier.layoutComponent;
componentRange.last = componentRange.start + consumedComponents - 1;
}
// combine location and component ranges
TBasicType basicTy = type.getBasicType();
if (basicTy == EbtSampler && type.getSampler().isAttachmentEXT())
basicTy = type.getSampler().type;
TIoRange range(locationRange, componentRange, basicTy, qualifier.hasIndex() ? qualifier.getIndex() : 0, qualifier.centroid, qualifier.smooth, qualifier.flat);
// check for collisions, except for vertex inputs on desktop targeting OpenGL
if (! (!isEsProfile() && language == EShLangVertex && qualifier.isPipeInput()) || spvVersion.vulkan > 0)
collision = checkLocationRange(set, range, type, typeCollision);
if (collision < 0)
usedIo[set].push_back(range);
return collision;
}
// Compare a new (the passed in) 'range' against the existing set, and see
// if there are any collisions.
//
// Returns < 0 if no collision, >= 0 if collision and the value returned is a colliding value.
//
int TIntermediate::checkLocationRange(int set, const TIoRange& range, const TType& type, bool& typeCollision)
{
for (size_t r = 0; r < usedIo[set].size(); ++r) {
if (range.overlap(usedIo[set][r])) {
// there is a collision; pick one
return std::max(range.location.start, usedIo[set][r].location.start);
} else if (range.location.overlap(usedIo[set][r].location) &&
(type.getBasicType() != usedIo[set][r].basicType ||
type.getQualifier().centroid != usedIo[set][r].centroid ||
type.getQualifier().smooth != usedIo[set][r].smooth ||
type.getQualifier().flat != usedIo[set][r].flat)) {
// aliased-type mismatch
typeCollision = true;
return std::max(range.location.start, usedIo[set][r].location.start);
}
}
// check typeCollision between tileImageEXT and out
if (set == 4 || set == 1) {
// if the set is "tileImageEXT", check against "out" and vice versa
int againstSet = (set == 4) ? 1 : 4;
for (size_t r = 0; r < usedIo[againstSet].size(); ++r) {
if (range.location.overlap(usedIo[againstSet][r].location) && type.getBasicType() != usedIo[againstSet][r].basicType) {
// aliased-type mismatch
typeCollision = true;
return std::max(range.location.start, usedIo[againstSet][r].location.start);
}
}
}
return -1; // no collision
}
int TIntermediate::checkLocationRT(int set, int location) {
TRange range(location, location);
for (size_t r = 0; r < usedIoRT[set].size(); ++r) {
if (range.overlap(usedIoRT[set][r])) {
return range.start;
}
}
return -1; // no collision
}
// Accumulate bindings and offsets, and check for collisions
// as the accumulation is done.
//
// Returns < 0 if no collision, >= 0 if collision and the value returned is a colliding value.
//
int TIntermediate::addUsedOffsets(int binding, int offset, int numOffsets)
{
TRange bindingRange(binding, binding);
TRange offsetRange(offset, offset + numOffsets - 1);
TOffsetRange range(bindingRange, offsetRange);
// check for collisions, except for vertex inputs on desktop
for (size_t r = 0; r < usedAtomics.size(); ++r) {
if (range.overlap(usedAtomics[r])) {
// there is a collision; pick one
return std::max(offset, usedAtomics[r].offset.start);
}
}
usedAtomics.push_back(range);
return -1; // no collision
}
// Accumulate used constant_id values.
//
// Return false is one was already used.
bool TIntermediate::addUsedConstantId(int id)
{
if (usedConstantId.find(id) != usedConstantId.end())
return false;
usedConstantId.insert(id);
return true;
}
// Recursively figure out how many locations are used up by an input or output type.
// Return the size of type, as measured by "locations".
int TIntermediate::computeTypeLocationSize(const TType& type, EShLanguage stage)
{
// "If the declared input is an array of size n and each element takes m locations, it will be assigned m * n
// consecutive locations..."
if (type.isArray()) {
// TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
// TODO: are there valid cases of having an unsized array with a location? If so, running this code too early.
TType elementType(type, 0);
if (type.isSizedArray() && !type.getQualifier().isPerView())
return type.getOuterArraySize() * computeTypeLocationSize(elementType, stage);
else {
// unset perViewNV attributes for arrayed per-view outputs: "perviewNV vec4 v[MAX_VIEWS][3];"
elementType.getQualifier().perViewNV = false;
return computeTypeLocationSize(elementType, stage);
}
}
// "The locations consumed by block and structure members are determined by applying the rules above
// recursively..."
if (type.isStruct()) {
int size = 0;
for (int member = 0; member < (int)type.getStruct()->size(); ++member) {
TType memberType(type, member);
size += computeTypeLocationSize(memberType, stage);
}
return size;
}
// ES: "If a shader input is any scalar or vector type, it will consume a single location."
// Desktop: "If a vertex shader input is any scalar or vector type, it will consume a single location. If a non-vertex
// shader input is a scalar or vector type other than dvec3 or dvec4, it will consume a single location, while
// types dvec3 or dvec4 will consume two consecutive locations. Inputs of type double and dvec2 will
// consume only a single location, in all stages."
if (type.isScalar())
return 1;
if (type.isVector()) {
if (stage == EShLangVertex && type.getQualifier().isPipeInput())
return 1;
if (type.getBasicType() == EbtDouble && type.getVectorSize() > 2)
return 2;
else
return 1;
}
// "If the declared input is an n x m single- or double-precision matrix, ...
// The number of locations assigned for each matrix will be the same as
// for an n-element array of m-component vectors..."
if (type.isMatrix()) {
TType columnType(type, 0);
return type.getMatrixCols() * computeTypeLocationSize(columnType, stage);
}
assert(0);
return 1;
}
// Same as computeTypeLocationSize but for uniforms
int TIntermediate::computeTypeUniformLocationSize(const TType& type)
{
// "Individual elements of a uniform array are assigned
// consecutive locations with the first element taking location
// location."
if (type.isArray()) {
// TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
TType elementType(type, 0);
if (type.isSizedArray()) {
return type.getOuterArraySize() * computeTypeUniformLocationSize(elementType);
} else {
// TODO: are there valid cases of having an implicitly-sized array with a location? If so, running this code too early.
return computeTypeUniformLocationSize(elementType);
}
}
// "Each subsequent inner-most member or element gets incremental
// locations for the entire structure or array."
if (type.isStruct()) {
int size = 0;
for (int member = 0; member < (int)type.getStruct()->size(); ++member) {
TType memberType(type, member);
size += computeTypeUniformLocationSize(memberType);
}
return size;
}
return 1;
}
// Accumulate xfb buffer ranges and check for collisions as the accumulation is done.
//
// Returns < 0 if no collision, >= 0 if collision and the value returned is a colliding value.
//
int TIntermediate::addXfbBufferOffset(const TType& type)
{
const TQualifier& qualifier = type.getQualifier();
assert(qualifier.hasXfbOffset() && qualifier.hasXfbBuffer());
TXfbBuffer& buffer = xfbBuffers[qualifier.layoutXfbBuffer];
// compute the range
unsigned int size = computeTypeXfbSize(type, buffer.contains64BitType, buffer.contains32BitType, buffer.contains16BitType);
buffer.implicitStride = std::max(buffer.implicitStride, qualifier.layoutXfbOffset + size);
TRange range(qualifier.layoutXfbOffset, qualifier.layoutXfbOffset + size - 1);
// check for collisions
for (size_t r = 0; r < buffer.ranges.size(); ++r) {
if (range.overlap(buffer.ranges[r])) {
// there is a collision; pick an example to return
return std::max(range.start, buffer.ranges[r].start);
}
}
buffer.ranges.push_back(range);
return -1; // no collision
}
// Recursively figure out how many bytes of xfb buffer are used by the given type.
// Return the size of type, in bytes.
// Sets contains64BitType to true if the type contains a 64-bit data type.
// Sets contains32BitType to true if the type contains a 32-bit data type.
// Sets contains16BitType to true if the type contains a 16-bit data type.
// N.B. Caller must set contains64BitType, contains32BitType, and contains16BitType to false before calling.
unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains64BitType, bool& contains32BitType, bool& contains16BitType) const
{
// "...if applied to an aggregate containing a double or 64-bit integer, the offset must also be a multiple of 8,
// and the space taken in the buffer will be a multiple of 8.
// ...within the qualified entity, subsequent components are each
// assigned, in order, to the next available offset aligned to a multiple of
// that component's size. Aggregate types are flattened down to the component
// level to get this sequence of components."
if (type.isSizedArray()) {
// TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
// Unsized array use to xfb should be a compile error.
TType elementType(type, 0);
return type.getOuterArraySize() * computeTypeXfbSize(elementType, contains64BitType, contains16BitType, contains16BitType);
}
if (type.isStruct()) {
unsigned int size = 0;
bool structContains64BitType = false;
bool structContains32BitType = false;
bool structContains16BitType = false;
for (int member = 0; member < (int)type.getStruct()->size(); ++member) {
TType memberType(type, member);
// "... if applied to
// an aggregate containing a double or 64-bit integer, the offset must also be a multiple of 8,
// and the space taken in the buffer will be a multiple of 8."
bool memberContains64BitType = false;
bool memberContains32BitType = false;
bool memberContains16BitType = false;
int memberSize = computeTypeXfbSize(memberType, memberContains64BitType, memberContains32BitType, memberContains16BitType);
if (memberContains64BitType) {
structContains64BitType = true;
RoundToPow2(size, 8);
} else if (memberContains32BitType) {
structContains32BitType = true;
RoundToPow2(size, 4);
} else if (memberContains16BitType) {
structContains16BitType = true;
RoundToPow2(size, 2);
}
size += memberSize;
}
if (structContains64BitType) {
contains64BitType = true;
RoundToPow2(size, 8);
} else if (structContains32BitType) {
contains32BitType = true;
RoundToPow2(size, 4);
} else if (structContains16BitType) {
contains16BitType = true;
RoundToPow2(size, 2);
}
return size;
}
int numComponents {0};
if (type.isScalar())
numComponents = 1;
else if (type.isVector())
numComponents = type.getVectorSize();
else if (type.isMatrix())
numComponents = type.getMatrixCols() * type.getMatrixRows();
else {
assert(0);
numComponents = 1;
}
if (type.getBasicType() == EbtDouble || type.getBasicType() == EbtInt64 || type.getBasicType() == EbtUint64) {
contains64BitType = true;
return 8 * numComponents;
} else if (type.getBasicType() == EbtFloat16 || type.getBasicType() == EbtInt16 || type.getBasicType() == EbtUint16) {
contains16BitType = true;
return 2 * numComponents;
} else if (type.getBasicType() == EbtInt8 || type.getBasicType() == EbtUint8)
return numComponents;
else {
contains32BitType = true;
return 4 * numComponents;
}
}
const int baseAlignmentVec4Std140 = 16;
// Return the size and alignment of a component of the given type.
// The size is returned in the 'size' parameter
// Return value is the alignment..
int TIntermediate::getBaseAlignmentScalar(const TType& type, int& size)
{
switch (type.getBasicType()) {
case EbtInt64:
case EbtUint64:
case EbtDouble: size = 8; return 8;
case EbtFloat16: size = 2; return 2;
case EbtInt8:
case EbtUint8: size = 1; return 1;
case EbtInt16:
case EbtUint16: size = 2; return 2;
case EbtReference: size = 8; return 8;
case EbtSampler:
{
if (type.isBindlessImage() || type.isBindlessTexture()) {
size = 8; return 8;
}
else {
size = 4; return 4;
}
}
default: size = 4; return 4;
}
}
// Implement base-alignment and size rules from section 7.6.2.2 Standard Uniform Block Layout
// Operates recursively.
//
// If std140 is true, it does the rounding up to vec4 size required by std140,
// otherwise it does not, yielding std430 rules.
//
// The size is returned in the 'size' parameter
//
// The stride is only non-0 for arrays or matrices, and is the stride of the
// top-level object nested within the type. E.g., for an array of matrices,
// it is the distances needed between matrices, despite the rules saying the
// stride comes from the flattening down to vectors.
//
// Return value is the alignment of the type.
int TIntermediate::getBaseAlignment(const TType& type, int& size, int& stride, TLayoutPacking layoutPacking, bool rowMajor)
{
int alignment;
bool std140 = layoutPacking == glslang::ElpStd140;
// When using the std140 storage layout, structures will be laid out in buffer
// storage with its members stored in monotonically increasing order based on their
// location in the declaration. A structure and each structure member have a base
// offset and a base alignment, from which an aligned offset is computed by rounding
// the base offset up to a multiple of the base alignment. The base offset of the first
// member of a structure is taken from the aligned offset of the structure itself. The
// base offset of all other structure members is derived by taking the offset of the
// last basic machine unit consumed by the previous member and adding one. Each
// structure member is stored in memory at its aligned offset. The members of a top-
// level uniform block are laid out in buffer storage by treating the uniform block as
// a structure with a base offset of zero.
//
// 1. If the member is a scalar consuming N basic machine units, the base alignment is N.
//
// 2. If the member is a two- or four-component vector with components consuming N basic
// machine units, the base alignment is 2N or 4N, respectively.
//
// 3. If the member is a three-component vector with components consuming N
// basic machine units, the base alignment is 4N.
//
// 4. If the member is an array of scalars or vectors, the base alignment and array
// stride are set to match the base alignment of a single array element, according
// to rules (1), (2), and (3), and rounded up to the base alignment of a vec4. The
// array may have padding at the end; the base offset of the member following
// the array is rounded up to the next multiple of the base alignment.
//
// 5. If the member is a column-major matrix with C columns and R rows, the
// matrix is stored identically to an array of C column vectors with R
// components each, according to rule (4).
//
// 6. If the member is an array of S column-major matrices with C columns and
// R rows, the matrix is stored identically to a row of S X C column vectors
// with R components each, according to rule (4).
//
// 7. If the member is a row-major matrix with C columns and R rows, the matrix
// is stored identically to an array of R row vectors with C components each,
// according to rule (4).
//
// 8. If the member is an array of S row-major matrices with C columns and R
// rows, the matrix is stored identically to a row of S X R row vectors with C
// components each, according to rule (4).
//
// 9. If the member is a structure, the base alignment of the structure is N , where
// N is the largest base alignment value of any of its members, and rounded
// up to the base alignment of a vec4. The individual members of this substructure
// are then assigned offsets by applying this set of rules recursively,
// where the base offset of the first member of the sub-structure is equal to the
// aligned offset of the structure. The structure may have padding at the end;
// the base offset of the member following the sub-structure is rounded up to
// the next multiple of the base alignment of the structure.
//
// 10. If the member is an array of S structures, the S elements of the array are laid
// out in order, according to rule (9).
//
// Assuming, for rule 10: The stride is the same as the size of an element.
stride = 0;
int dummyStride;
// rules 4, 6, 8, and 10
if (type.isArray()) {
// TODO: perf: this might be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
TType derefType(type, 0);
alignment = getBaseAlignment(derefType, size, dummyStride, layoutPacking, rowMajor);
if (std140)
alignment = std::max(baseAlignmentVec4Std140, alignment);
RoundToPow2(size, alignment);
stride = size; // uses full matrix size for stride of an array of matrices (not quite what rule 6/8, but what's expected)
// uses the assumption for rule 10 in the comment above
// use one element to represent the last member of SSBO which is unsized array
int arraySize = (type.isUnsizedArray() && (type.getOuterArraySize() == 0)) ? 1 : type.getOuterArraySize();
size = stride * arraySize;
return alignment;
}
// rule 9
if (type.getBasicType() == EbtStruct || type.getBasicType() == EbtBlock) {
const TTypeList& memberList = *type.getStruct();
size = 0;
int maxAlignment = std140 ? baseAlignmentVec4Std140 : 0;
for (size_t m = 0; m < memberList.size(); ++m) {
int memberSize;
// modify just the children's view of matrix layout, if there is one for this member
TLayoutMatrix subMatrixLayout = memberList[m].type->getQualifier().layoutMatrix;
int memberAlignment = getBaseAlignment(*memberList[m].type, memberSize, dummyStride, layoutPacking,
(subMatrixLayout != ElmNone) ? (subMatrixLayout == ElmRowMajor) : rowMajor);
maxAlignment = std::max(maxAlignment, memberAlignment);
RoundToPow2(size, memberAlignment);
size += memberSize;
}
// The structure may have padding at the end; the base offset of
// the member following the sub-structure is rounded up to the next
// multiple of the base alignment of the structure.
RoundToPow2(size, maxAlignment);
return maxAlignment;
}
// rule 1
if (type.isScalar())
return getBaseAlignmentScalar(type, size);
// rules 2 and 3
if (type.isVector()) {
int scalarAlign = getBaseAlignmentScalar(type, size);
switch (type.getVectorSize()) {
case 1: // HLSL has this, GLSL does not
return scalarAlign;
case 2:
size *= 2;
return 2 * scalarAlign;
default:
size *= type.getVectorSize();
return 4 * scalarAlign;
}
}
// rules 5 and 7
if (type.isMatrix()) {
// rule 5: deref to row, not to column, meaning the size of vector is num columns instead of num rows
TType derefType(type, 0, rowMajor);
alignment = getBaseAlignment(derefType, size, dummyStride, layoutPacking, rowMajor);
if (std140)
alignment = std::max(baseAlignmentVec4Std140, alignment);
RoundToPow2(size, alignment);
stride = size; // use intra-matrix stride for stride of a just a matrix
if (rowMajor)
size = stride * type.getMatrixRows();
else
size = stride * type.getMatrixCols();
return alignment;
}
assert(0); // all cases should be covered above
size = baseAlignmentVec4Std140;
return baseAlignmentVec4Std140;
}
// To aid the basic HLSL rule about crossing vec4 boundaries.
bool TIntermediate::improperStraddle(const TType& type, int size, int offset, bool vectorLike)
{
if (! vectorLike || type.isArray())
return false;
return size <= 16 ? offset / 16 != (offset + size - 1) / 16
: offset % 16 != 0;
}
int TIntermediate::getScalarAlignment(const TType& type, int& size, int& stride, bool rowMajor)
{
int alignment;
stride = 0;
int dummyStride;
if (type.isArray()) {
TType derefType(type, 0);
alignment = getScalarAlignment(derefType, size, dummyStride, rowMajor);
stride = size;
RoundToPow2(stride, alignment);
size = stride * (type.getOuterArraySize() - 1) + size;
return alignment;
}
if (type.getBasicType() == EbtStruct) {
const TTypeList& memberList = *type.getStruct();
size = 0;
int maxAlignment = 0;
for (size_t m = 0; m < memberList.size(); ++m) {
int memberSize;
// modify just the children's view of matrix layout, if there is one for this member
TLayoutMatrix subMatrixLayout = memberList[m].type->getQualifier().layoutMatrix;
int memberAlignment = getScalarAlignment(*memberList[m].type, memberSize, dummyStride,
(subMatrixLayout != ElmNone) ? (subMatrixLayout == ElmRowMajor) : rowMajor);
maxAlignment = std::max(maxAlignment, memberAlignment);
RoundToPow2(size, memberAlignment);
size += memberSize;
}
return maxAlignment;
}
if (type.isScalar())
return getBaseAlignmentScalar(type, size);
if (type.isVector()) {
int scalarAlign = getBaseAlignmentScalar(type, size);
size *= type.getVectorSize();
return scalarAlign;
}
if (type.isMatrix()) {
TType derefType(type, 0, rowMajor);
alignment = getScalarAlignment(derefType, size, dummyStride, rowMajor);
stride = size; // use intra-matrix stride for stride of a just a matrix
if (rowMajor)
size = stride * type.getMatrixRows();
else
size = stride * type.getMatrixCols();
return alignment;
}
assert(0); // all cases should be covered above
size = 1;
return 1;
}
int TIntermediate::getMemberAlignment(const TType& type, int& size, int& stride, TLayoutPacking layoutPacking, bool rowMajor)
{
if (layoutPacking == glslang::ElpScalar) {
return getScalarAlignment(type, size, stride, rowMajor);
} else {
return getBaseAlignment(type, size, stride, layoutPacking, rowMajor);
}
}
// shared calculation by getOffset and getOffsets
void TIntermediate::updateOffset(const TType& parentType, const TType& memberType, int& offset, int& memberSize)
{
int dummyStride;
// modify just the children's view of matrix layout, if there is one for this member
TLayoutMatrix subMatrixLayout = memberType.getQualifier().layoutMatrix;
int memberAlignment = getMemberAlignment(memberType, memberSize, dummyStride,
parentType.getQualifier().layoutPacking,
subMatrixLayout != ElmNone
? subMatrixLayout == ElmRowMajor
: parentType.getQualifier().layoutMatrix == ElmRowMajor);
RoundToPow2(offset, memberAlignment);
}
// Lookup or calculate the offset of a block member, using the recursively
// defined block offset rules.
int TIntermediate::getOffset(const TType& type, int index)
{
const TTypeList& memberList = *type.getStruct();
// Don't calculate offset if one is present, it could be user supplied
// and different than what would be calculated. That is, this is faster,
// but not just an optimization.
if (memberList[index].type->getQualifier().hasOffset())
return memberList[index].type->getQualifier().layoutOffset;
int memberSize = 0;
int offset = 0;
for (int m = 0; m <= index; ++m) {
updateOffset(type, *memberList[m].type, offset, memberSize);
if (m < index)
offset += memberSize;
}
return offset;
}
// Calculate the block data size.
// Block arrayness is not taken into account, each element is backed by a separate buffer.
int TIntermediate::getBlockSize(const TType& blockType)
{
const TTypeList& memberList = *blockType.getStruct();
int lastIndex = (int)memberList.size() - 1;
int lastOffset = getOffset(blockType, lastIndex);
int lastMemberSize;
int dummyStride;
getMemberAlignment(*memberList[lastIndex].type, lastMemberSize, dummyStride,
blockType.getQualifier().layoutPacking,
blockType.getQualifier().layoutMatrix == ElmRowMajor);
return lastOffset + lastMemberSize;
}
int TIntermediate::computeBufferReferenceTypeSize(const TType& type)
{
assert(type.isReference());
int size = getBlockSize(*type.getReferentType());
int align = type.getBufferReferenceAlignment();
if (align) {
size = (size + align - 1) & ~(align-1);
}
return size;
}
bool TIntermediate::isIoResizeArray(const TType& type, EShLanguage language) {
return type.isArray() &&
((language == EShLangGeometry && type.getQualifier().storage == EvqVaryingIn) ||
(language == EShLangTessControl && (type.getQualifier().storage == EvqVaryingIn || type.getQualifier().storage == EvqVaryingOut) &&
! type.getQualifier().patch) ||
(language == EShLangTessEvaluation && type.getQualifier().storage == EvqVaryingIn) ||
(language == EShLangFragment && type.getQualifier().storage == EvqVaryingIn &&
(type.getQualifier().pervertexNV || type.getQualifier().pervertexEXT)) ||
(language == EShLangMesh && type.getQualifier().storage == EvqVaryingOut &&
!type.getQualifier().perTaskNV));
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/reflection.h | //
// Copyright (C) 2013-2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _REFLECTION_INCLUDED
#define _REFLECTION_INCLUDED
#include "../Public/ShaderLang.h"
#include "../Include/Types.h"
#include <list>
#include <set>
//
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
//
namespace glslang {
class TIntermediate;
class TIntermAggregate;
class TReflectionTraverser;
// The full reflection database
class TReflection {
public:
TReflection(EShReflectionOptions opts, EShLanguage first, EShLanguage last)
: options(opts), firstStage(first), lastStage(last), badReflection(TObjectReflection::badReflection())
{
for (int dim=0; dim<3; ++dim)
localSize[dim] = 0;
}
virtual ~TReflection() {}
// grow the reflection stage by stage
bool addStage(EShLanguage, const TIntermediate&);
// for mapping a uniform index to a uniform object's description
int getNumUniforms() { return (int)indexToUniform.size(); }
const TObjectReflection& getUniform(int i) const
{
if (i >= 0 && i < (int)indexToUniform.size())
return indexToUniform[i];
else
return badReflection;
}
// for mapping a block index to the block's description
int getNumUniformBlocks() const { return (int)indexToUniformBlock.size(); }
const TObjectReflection& getUniformBlock(int i) const
{
if (i >= 0 && i < (int)indexToUniformBlock.size())
return indexToUniformBlock[i];
else
return badReflection;
}
// for mapping an pipeline input index to the input's description
int getNumPipeInputs() { return (int)indexToPipeInput.size(); }
const TObjectReflection& getPipeInput(int i) const
{
if (i >= 0 && i < (int)indexToPipeInput.size())
return indexToPipeInput[i];
else
return badReflection;
}
// for mapping an pipeline output index to the output's description
int getNumPipeOutputs() { return (int)indexToPipeOutput.size(); }
const TObjectReflection& getPipeOutput(int i) const
{
if (i >= 0 && i < (int)indexToPipeOutput.size())
return indexToPipeOutput[i];
else
return badReflection;
}
// for mapping from an atomic counter to the uniform index
int getNumAtomicCounters() const { return (int)atomicCounterUniformIndices.size(); }
const TObjectReflection& getAtomicCounter(int i) const
{
if (i >= 0 && i < (int)atomicCounterUniformIndices.size())
return getUniform(atomicCounterUniformIndices[i]);
else
return badReflection;
}
// for mapping a buffer variable index to a buffer variable object's description
int getNumBufferVariables() { return (int)indexToBufferVariable.size(); }
const TObjectReflection& getBufferVariable(int i) const
{
if (i >= 0 && i < (int)indexToBufferVariable.size())
return indexToBufferVariable[i];
else
return badReflection;
}
// for mapping a storage block index to the storage block's description
int getNumStorageBuffers() const { return (int)indexToBufferBlock.size(); }
const TObjectReflection& getStorageBufferBlock(int i) const
{
if (i >= 0 && i < (int)indexToBufferBlock.size())
return indexToBufferBlock[i];
else
return badReflection;
}
// for mapping any name to its index (block names, uniform names and input/output names)
int getIndex(const char* name) const
{
TNameToIndex::const_iterator it = nameToIndex.find(name);
if (it == nameToIndex.end())
return -1;
else
return it->second;
}
// see getIndex(const char*)
int getIndex(const TString& name) const { return getIndex(name.c_str()); }
// for mapping any name to its index (only pipe input/output names)
int getPipeIOIndex(const char* name, const bool inOrOut) const
{
TNameToIndex::const_iterator it = inOrOut ? pipeInNameToIndex.find(name) : pipeOutNameToIndex.find(name);
if (it == (inOrOut ? pipeInNameToIndex.end() : pipeOutNameToIndex.end()))
return -1;
else
return it->second;
}
// see gePipeIOIndex(const char*, const bool)
int getPipeIOIndex(const TString& name, const bool inOrOut) const { return getPipeIOIndex(name.c_str(), inOrOut); }
// Thread local size
unsigned getLocalSize(int dim) const { return dim <= 2 ? localSize[dim] : 0; }
void dump();
protected:
friend class glslang::TReflectionTraverser;
void buildCounterIndices(const TIntermediate&);
void buildUniformStageMask(const TIntermediate& intermediate);
void buildAttributeReflection(EShLanguage, const TIntermediate&);
// Need a TString hash: typedef std::unordered_map<TString, int> TNameToIndex;
typedef std::map<std::string, int> TNameToIndex;
typedef std::vector<TObjectReflection> TMapIndexToReflection;
typedef std::vector<int> TIndices;
TMapIndexToReflection& GetBlockMapForStorage(TStorageQualifier storage)
{
if ((options & EShReflectionSeparateBuffers) && storage == EvqBuffer)
return indexToBufferBlock;
return indexToUniformBlock;
}
TMapIndexToReflection& GetVariableMapForStorage(TStorageQualifier storage)
{
if ((options & EShReflectionSeparateBuffers) && storage == EvqBuffer)
return indexToBufferVariable;
return indexToUniform;
}
EShReflectionOptions options;
EShLanguage firstStage;
EShLanguage lastStage;
TObjectReflection badReflection; // return for queries of -1 or generally out of range; has expected descriptions with in it for this
TNameToIndex nameToIndex; // maps names to indexes; can hold all types of data: uniform/buffer and which function names have been processed
TNameToIndex pipeInNameToIndex; // maps pipe in names to indexes, this is a fix to seperate pipe I/O from uniforms and buffers.
TNameToIndex pipeOutNameToIndex; // maps pipe out names to indexes, this is a fix to seperate pipe I/O from uniforms and buffers.
TMapIndexToReflection indexToUniform;
TMapIndexToReflection indexToUniformBlock;
TMapIndexToReflection indexToBufferVariable;
TMapIndexToReflection indexToBufferBlock;
TMapIndexToReflection indexToPipeInput;
TMapIndexToReflection indexToPipeOutput;
TIndices atomicCounterUniformIndices;
unsigned int localSize[3];
};
} // end namespace glslang
#endif // _REFLECTION_INCLUDED
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/pch.h | #ifndef _PCH_H
#define _PCH_H
//
// Copyright (C) 2018 The Khronos Group Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <climits>
#include <iostream>
#include <sstream>
#include <memory>
#include "SymbolTable.h"
#include "ParseHelper.h"
#include "Scan.h"
#include "ScanContext.h"
#endif /* _PCH_H */
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/glslang_tab.cpp.h | /* A Bison parser, made by GNU Bison 3.8.2. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
#ifndef YY_YY_MACHINEINDEPENDENT_GLSLANG_TAB_CPP_H_INCLUDED
# define YY_YY_MACHINEINDEPENDENT_GLSLANG_TAB_CPP_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token kinds. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
YYEMPTY = -2,
YYEOF = 0, /* "end of file" */
YYerror = 256, /* error */
YYUNDEF = 257, /* "invalid token" */
CONST = 258, /* CONST */
BOOL = 259, /* BOOL */
INT = 260, /* INT */
UINT = 261, /* UINT */
FLOAT = 262, /* FLOAT */
BVEC2 = 263, /* BVEC2 */
BVEC3 = 264, /* BVEC3 */
BVEC4 = 265, /* BVEC4 */
IVEC2 = 266, /* IVEC2 */
IVEC3 = 267, /* IVEC3 */
IVEC4 = 268, /* IVEC4 */
UVEC2 = 269, /* UVEC2 */
UVEC3 = 270, /* UVEC3 */
UVEC4 = 271, /* UVEC4 */
VEC2 = 272, /* VEC2 */
VEC3 = 273, /* VEC3 */
VEC4 = 274, /* VEC4 */
MAT2 = 275, /* MAT2 */
MAT3 = 276, /* MAT3 */
MAT4 = 277, /* MAT4 */
MAT2X2 = 278, /* MAT2X2 */
MAT2X3 = 279, /* MAT2X3 */
MAT2X4 = 280, /* MAT2X4 */
MAT3X2 = 281, /* MAT3X2 */
MAT3X3 = 282, /* MAT3X3 */
MAT3X4 = 283, /* MAT3X4 */
MAT4X2 = 284, /* MAT4X2 */
MAT4X3 = 285, /* MAT4X3 */
MAT4X4 = 286, /* MAT4X4 */
SAMPLER2D = 287, /* SAMPLER2D */
SAMPLER3D = 288, /* SAMPLER3D */
SAMPLERCUBE = 289, /* SAMPLERCUBE */
SAMPLER2DSHADOW = 290, /* SAMPLER2DSHADOW */
SAMPLERCUBESHADOW = 291, /* SAMPLERCUBESHADOW */
SAMPLER2DARRAY = 292, /* SAMPLER2DARRAY */
SAMPLER2DARRAYSHADOW = 293, /* SAMPLER2DARRAYSHADOW */
ISAMPLER2D = 294, /* ISAMPLER2D */
ISAMPLER3D = 295, /* ISAMPLER3D */
ISAMPLERCUBE = 296, /* ISAMPLERCUBE */
ISAMPLER2DARRAY = 297, /* ISAMPLER2DARRAY */
USAMPLER2D = 298, /* USAMPLER2D */
USAMPLER3D = 299, /* USAMPLER3D */
USAMPLERCUBE = 300, /* USAMPLERCUBE */
USAMPLER2DARRAY = 301, /* USAMPLER2DARRAY */
SAMPLER = 302, /* SAMPLER */
SAMPLERSHADOW = 303, /* SAMPLERSHADOW */
TEXTURE2D = 304, /* TEXTURE2D */
TEXTURE3D = 305, /* TEXTURE3D */
TEXTURECUBE = 306, /* TEXTURECUBE */
TEXTURE2DARRAY = 307, /* TEXTURE2DARRAY */
ITEXTURE2D = 308, /* ITEXTURE2D */
ITEXTURE3D = 309, /* ITEXTURE3D */
ITEXTURECUBE = 310, /* ITEXTURECUBE */
ITEXTURE2DARRAY = 311, /* ITEXTURE2DARRAY */
UTEXTURE2D = 312, /* UTEXTURE2D */
UTEXTURE3D = 313, /* UTEXTURE3D */
UTEXTURECUBE = 314, /* UTEXTURECUBE */
UTEXTURE2DARRAY = 315, /* UTEXTURE2DARRAY */
ATTRIBUTE = 316, /* ATTRIBUTE */
VARYING = 317, /* VARYING */
FLOAT16_T = 318, /* FLOAT16_T */
FLOAT32_T = 319, /* FLOAT32_T */
DOUBLE = 320, /* DOUBLE */
FLOAT64_T = 321, /* FLOAT64_T */
INT64_T = 322, /* INT64_T */
UINT64_T = 323, /* UINT64_T */
INT32_T = 324, /* INT32_T */
UINT32_T = 325, /* UINT32_T */
INT16_T = 326, /* INT16_T */
UINT16_T = 327, /* UINT16_T */
INT8_T = 328, /* INT8_T */
UINT8_T = 329, /* UINT8_T */
I64VEC2 = 330, /* I64VEC2 */
I64VEC3 = 331, /* I64VEC3 */
I64VEC4 = 332, /* I64VEC4 */
U64VEC2 = 333, /* U64VEC2 */
U64VEC3 = 334, /* U64VEC3 */
U64VEC4 = 335, /* U64VEC4 */
I32VEC2 = 336, /* I32VEC2 */
I32VEC3 = 337, /* I32VEC3 */
I32VEC4 = 338, /* I32VEC4 */
U32VEC2 = 339, /* U32VEC2 */
U32VEC3 = 340, /* U32VEC3 */
U32VEC4 = 341, /* U32VEC4 */
I16VEC2 = 342, /* I16VEC2 */
I16VEC3 = 343, /* I16VEC3 */
I16VEC4 = 344, /* I16VEC4 */
U16VEC2 = 345, /* U16VEC2 */
U16VEC3 = 346, /* U16VEC3 */
U16VEC4 = 347, /* U16VEC4 */
I8VEC2 = 348, /* I8VEC2 */
I8VEC3 = 349, /* I8VEC3 */
I8VEC4 = 350, /* I8VEC4 */
U8VEC2 = 351, /* U8VEC2 */
U8VEC3 = 352, /* U8VEC3 */
U8VEC4 = 353, /* U8VEC4 */
DVEC2 = 354, /* DVEC2 */
DVEC3 = 355, /* DVEC3 */
DVEC4 = 356, /* DVEC4 */
DMAT2 = 357, /* DMAT2 */
DMAT3 = 358, /* DMAT3 */
DMAT4 = 359, /* DMAT4 */
F16VEC2 = 360, /* F16VEC2 */
F16VEC3 = 361, /* F16VEC3 */
F16VEC4 = 362, /* F16VEC4 */
F16MAT2 = 363, /* F16MAT2 */
F16MAT3 = 364, /* F16MAT3 */
F16MAT4 = 365, /* F16MAT4 */
F32VEC2 = 366, /* F32VEC2 */
F32VEC3 = 367, /* F32VEC3 */
F32VEC4 = 368, /* F32VEC4 */
F32MAT2 = 369, /* F32MAT2 */
F32MAT3 = 370, /* F32MAT3 */
F32MAT4 = 371, /* F32MAT4 */
F64VEC2 = 372, /* F64VEC2 */
F64VEC3 = 373, /* F64VEC3 */
F64VEC4 = 374, /* F64VEC4 */
F64MAT2 = 375, /* F64MAT2 */
F64MAT3 = 376, /* F64MAT3 */
F64MAT4 = 377, /* F64MAT4 */
DMAT2X2 = 378, /* DMAT2X2 */
DMAT2X3 = 379, /* DMAT2X3 */
DMAT2X4 = 380, /* DMAT2X4 */
DMAT3X2 = 381, /* DMAT3X2 */
DMAT3X3 = 382, /* DMAT3X3 */
DMAT3X4 = 383, /* DMAT3X4 */
DMAT4X2 = 384, /* DMAT4X2 */
DMAT4X3 = 385, /* DMAT4X3 */
DMAT4X4 = 386, /* DMAT4X4 */
F16MAT2X2 = 387, /* F16MAT2X2 */
F16MAT2X3 = 388, /* F16MAT2X3 */
F16MAT2X4 = 389, /* F16MAT2X4 */
F16MAT3X2 = 390, /* F16MAT3X2 */
F16MAT3X3 = 391, /* F16MAT3X3 */
F16MAT3X4 = 392, /* F16MAT3X4 */
F16MAT4X2 = 393, /* F16MAT4X2 */
F16MAT4X3 = 394, /* F16MAT4X3 */
F16MAT4X4 = 395, /* F16MAT4X4 */
F32MAT2X2 = 396, /* F32MAT2X2 */
F32MAT2X3 = 397, /* F32MAT2X3 */
F32MAT2X4 = 398, /* F32MAT2X4 */
F32MAT3X2 = 399, /* F32MAT3X2 */
F32MAT3X3 = 400, /* F32MAT3X3 */
F32MAT3X4 = 401, /* F32MAT3X4 */
F32MAT4X2 = 402, /* F32MAT4X2 */
F32MAT4X3 = 403, /* F32MAT4X3 */
F32MAT4X4 = 404, /* F32MAT4X4 */
F64MAT2X2 = 405, /* F64MAT2X2 */
F64MAT2X3 = 406, /* F64MAT2X3 */
F64MAT2X4 = 407, /* F64MAT2X4 */
F64MAT3X2 = 408, /* F64MAT3X2 */
F64MAT3X3 = 409, /* F64MAT3X3 */
F64MAT3X4 = 410, /* F64MAT3X4 */
F64MAT4X2 = 411, /* F64MAT4X2 */
F64MAT4X3 = 412, /* F64MAT4X3 */
F64MAT4X4 = 413, /* F64MAT4X4 */
ATOMIC_UINT = 414, /* ATOMIC_UINT */
ACCSTRUCTNV = 415, /* ACCSTRUCTNV */
ACCSTRUCTEXT = 416, /* ACCSTRUCTEXT */
RAYQUERYEXT = 417, /* RAYQUERYEXT */
FCOOPMATNV = 418, /* FCOOPMATNV */
ICOOPMATNV = 419, /* ICOOPMATNV */
UCOOPMATNV = 420, /* UCOOPMATNV */
COOPMAT = 421, /* COOPMAT */
HITOBJECTNV = 422, /* HITOBJECTNV */
HITOBJECTATTRNV = 423, /* HITOBJECTATTRNV */
SAMPLERCUBEARRAY = 424, /* SAMPLERCUBEARRAY */
SAMPLERCUBEARRAYSHADOW = 425, /* SAMPLERCUBEARRAYSHADOW */
ISAMPLERCUBEARRAY = 426, /* ISAMPLERCUBEARRAY */
USAMPLERCUBEARRAY = 427, /* USAMPLERCUBEARRAY */
SAMPLER1D = 428, /* SAMPLER1D */
SAMPLER1DARRAY = 429, /* SAMPLER1DARRAY */
SAMPLER1DARRAYSHADOW = 430, /* SAMPLER1DARRAYSHADOW */
ISAMPLER1D = 431, /* ISAMPLER1D */
SAMPLER1DSHADOW = 432, /* SAMPLER1DSHADOW */
SAMPLER2DRECT = 433, /* SAMPLER2DRECT */
SAMPLER2DRECTSHADOW = 434, /* SAMPLER2DRECTSHADOW */
ISAMPLER2DRECT = 435, /* ISAMPLER2DRECT */
USAMPLER2DRECT = 436, /* USAMPLER2DRECT */
SAMPLERBUFFER = 437, /* SAMPLERBUFFER */
ISAMPLERBUFFER = 438, /* ISAMPLERBUFFER */
USAMPLERBUFFER = 439, /* USAMPLERBUFFER */
SAMPLER2DMS = 440, /* SAMPLER2DMS */
ISAMPLER2DMS = 441, /* ISAMPLER2DMS */
USAMPLER2DMS = 442, /* USAMPLER2DMS */
SAMPLER2DMSARRAY = 443, /* SAMPLER2DMSARRAY */
ISAMPLER2DMSARRAY = 444, /* ISAMPLER2DMSARRAY */
USAMPLER2DMSARRAY = 445, /* USAMPLER2DMSARRAY */
SAMPLEREXTERNALOES = 446, /* SAMPLEREXTERNALOES */
SAMPLEREXTERNAL2DY2YEXT = 447, /* SAMPLEREXTERNAL2DY2YEXT */
ISAMPLER1DARRAY = 448, /* ISAMPLER1DARRAY */
USAMPLER1D = 449, /* USAMPLER1D */
USAMPLER1DARRAY = 450, /* USAMPLER1DARRAY */
F16SAMPLER1D = 451, /* F16SAMPLER1D */
F16SAMPLER2D = 452, /* F16SAMPLER2D */
F16SAMPLER3D = 453, /* F16SAMPLER3D */
F16SAMPLER2DRECT = 454, /* F16SAMPLER2DRECT */
F16SAMPLERCUBE = 455, /* F16SAMPLERCUBE */
F16SAMPLER1DARRAY = 456, /* F16SAMPLER1DARRAY */
F16SAMPLER2DARRAY = 457, /* F16SAMPLER2DARRAY */
F16SAMPLERCUBEARRAY = 458, /* F16SAMPLERCUBEARRAY */
F16SAMPLERBUFFER = 459, /* F16SAMPLERBUFFER */
F16SAMPLER2DMS = 460, /* F16SAMPLER2DMS */
F16SAMPLER2DMSARRAY = 461, /* F16SAMPLER2DMSARRAY */
F16SAMPLER1DSHADOW = 462, /* F16SAMPLER1DSHADOW */
F16SAMPLER2DSHADOW = 463, /* F16SAMPLER2DSHADOW */
F16SAMPLER1DARRAYSHADOW = 464, /* F16SAMPLER1DARRAYSHADOW */
F16SAMPLER2DARRAYSHADOW = 465, /* F16SAMPLER2DARRAYSHADOW */
F16SAMPLER2DRECTSHADOW = 466, /* F16SAMPLER2DRECTSHADOW */
F16SAMPLERCUBESHADOW = 467, /* F16SAMPLERCUBESHADOW */
F16SAMPLERCUBEARRAYSHADOW = 468, /* F16SAMPLERCUBEARRAYSHADOW */
IMAGE1D = 469, /* IMAGE1D */
IIMAGE1D = 470, /* IIMAGE1D */
UIMAGE1D = 471, /* UIMAGE1D */
IMAGE2D = 472, /* IMAGE2D */
IIMAGE2D = 473, /* IIMAGE2D */
UIMAGE2D = 474, /* UIMAGE2D */
IMAGE3D = 475, /* IMAGE3D */
IIMAGE3D = 476, /* IIMAGE3D */
UIMAGE3D = 477, /* UIMAGE3D */
IMAGE2DRECT = 478, /* IMAGE2DRECT */
IIMAGE2DRECT = 479, /* IIMAGE2DRECT */
UIMAGE2DRECT = 480, /* UIMAGE2DRECT */
IMAGECUBE = 481, /* IMAGECUBE */
IIMAGECUBE = 482, /* IIMAGECUBE */
UIMAGECUBE = 483, /* UIMAGECUBE */
IMAGEBUFFER = 484, /* IMAGEBUFFER */
IIMAGEBUFFER = 485, /* IIMAGEBUFFER */
UIMAGEBUFFER = 486, /* UIMAGEBUFFER */
IMAGE1DARRAY = 487, /* IMAGE1DARRAY */
IIMAGE1DARRAY = 488, /* IIMAGE1DARRAY */
UIMAGE1DARRAY = 489, /* UIMAGE1DARRAY */
IMAGE2DARRAY = 490, /* IMAGE2DARRAY */
IIMAGE2DARRAY = 491, /* IIMAGE2DARRAY */
UIMAGE2DARRAY = 492, /* UIMAGE2DARRAY */
IMAGECUBEARRAY = 493, /* IMAGECUBEARRAY */
IIMAGECUBEARRAY = 494, /* IIMAGECUBEARRAY */
UIMAGECUBEARRAY = 495, /* UIMAGECUBEARRAY */
IMAGE2DMS = 496, /* IMAGE2DMS */
IIMAGE2DMS = 497, /* IIMAGE2DMS */
UIMAGE2DMS = 498, /* UIMAGE2DMS */
IMAGE2DMSARRAY = 499, /* IMAGE2DMSARRAY */
IIMAGE2DMSARRAY = 500, /* IIMAGE2DMSARRAY */
UIMAGE2DMSARRAY = 501, /* UIMAGE2DMSARRAY */
F16IMAGE1D = 502, /* F16IMAGE1D */
F16IMAGE2D = 503, /* F16IMAGE2D */
F16IMAGE3D = 504, /* F16IMAGE3D */
F16IMAGE2DRECT = 505, /* F16IMAGE2DRECT */
F16IMAGECUBE = 506, /* F16IMAGECUBE */
F16IMAGE1DARRAY = 507, /* F16IMAGE1DARRAY */
F16IMAGE2DARRAY = 508, /* F16IMAGE2DARRAY */
F16IMAGECUBEARRAY = 509, /* F16IMAGECUBEARRAY */
F16IMAGEBUFFER = 510, /* F16IMAGEBUFFER */
F16IMAGE2DMS = 511, /* F16IMAGE2DMS */
F16IMAGE2DMSARRAY = 512, /* F16IMAGE2DMSARRAY */
I64IMAGE1D = 513, /* I64IMAGE1D */
U64IMAGE1D = 514, /* U64IMAGE1D */
I64IMAGE2D = 515, /* I64IMAGE2D */
U64IMAGE2D = 516, /* U64IMAGE2D */
I64IMAGE3D = 517, /* I64IMAGE3D */
U64IMAGE3D = 518, /* U64IMAGE3D */
I64IMAGE2DRECT = 519, /* I64IMAGE2DRECT */
U64IMAGE2DRECT = 520, /* U64IMAGE2DRECT */
I64IMAGECUBE = 521, /* I64IMAGECUBE */
U64IMAGECUBE = 522, /* U64IMAGECUBE */
I64IMAGEBUFFER = 523, /* I64IMAGEBUFFER */
U64IMAGEBUFFER = 524, /* U64IMAGEBUFFER */
I64IMAGE1DARRAY = 525, /* I64IMAGE1DARRAY */
U64IMAGE1DARRAY = 526, /* U64IMAGE1DARRAY */
I64IMAGE2DARRAY = 527, /* I64IMAGE2DARRAY */
U64IMAGE2DARRAY = 528, /* U64IMAGE2DARRAY */
I64IMAGECUBEARRAY = 529, /* I64IMAGECUBEARRAY */
U64IMAGECUBEARRAY = 530, /* U64IMAGECUBEARRAY */
I64IMAGE2DMS = 531, /* I64IMAGE2DMS */
U64IMAGE2DMS = 532, /* U64IMAGE2DMS */
I64IMAGE2DMSARRAY = 533, /* I64IMAGE2DMSARRAY */
U64IMAGE2DMSARRAY = 534, /* U64IMAGE2DMSARRAY */
TEXTURECUBEARRAY = 535, /* TEXTURECUBEARRAY */
ITEXTURECUBEARRAY = 536, /* ITEXTURECUBEARRAY */
UTEXTURECUBEARRAY = 537, /* UTEXTURECUBEARRAY */
TEXTURE1D = 538, /* TEXTURE1D */
ITEXTURE1D = 539, /* ITEXTURE1D */
UTEXTURE1D = 540, /* UTEXTURE1D */
TEXTURE1DARRAY = 541, /* TEXTURE1DARRAY */
ITEXTURE1DARRAY = 542, /* ITEXTURE1DARRAY */
UTEXTURE1DARRAY = 543, /* UTEXTURE1DARRAY */
TEXTURE2DRECT = 544, /* TEXTURE2DRECT */
ITEXTURE2DRECT = 545, /* ITEXTURE2DRECT */
UTEXTURE2DRECT = 546, /* UTEXTURE2DRECT */
TEXTUREBUFFER = 547, /* TEXTUREBUFFER */
ITEXTUREBUFFER = 548, /* ITEXTUREBUFFER */
UTEXTUREBUFFER = 549, /* UTEXTUREBUFFER */
TEXTURE2DMS = 550, /* TEXTURE2DMS */
ITEXTURE2DMS = 551, /* ITEXTURE2DMS */
UTEXTURE2DMS = 552, /* UTEXTURE2DMS */
TEXTURE2DMSARRAY = 553, /* TEXTURE2DMSARRAY */
ITEXTURE2DMSARRAY = 554, /* ITEXTURE2DMSARRAY */
UTEXTURE2DMSARRAY = 555, /* UTEXTURE2DMSARRAY */
F16TEXTURE1D = 556, /* F16TEXTURE1D */
F16TEXTURE2D = 557, /* F16TEXTURE2D */
F16TEXTURE3D = 558, /* F16TEXTURE3D */
F16TEXTURE2DRECT = 559, /* F16TEXTURE2DRECT */
F16TEXTURECUBE = 560, /* F16TEXTURECUBE */
F16TEXTURE1DARRAY = 561, /* F16TEXTURE1DARRAY */
F16TEXTURE2DARRAY = 562, /* F16TEXTURE2DARRAY */
F16TEXTURECUBEARRAY = 563, /* F16TEXTURECUBEARRAY */
F16TEXTUREBUFFER = 564, /* F16TEXTUREBUFFER */
F16TEXTURE2DMS = 565, /* F16TEXTURE2DMS */
F16TEXTURE2DMSARRAY = 566, /* F16TEXTURE2DMSARRAY */
SUBPASSINPUT = 567, /* SUBPASSINPUT */
SUBPASSINPUTMS = 568, /* SUBPASSINPUTMS */
ISUBPASSINPUT = 569, /* ISUBPASSINPUT */
ISUBPASSINPUTMS = 570, /* ISUBPASSINPUTMS */
USUBPASSINPUT = 571, /* USUBPASSINPUT */
USUBPASSINPUTMS = 572, /* USUBPASSINPUTMS */
F16SUBPASSINPUT = 573, /* F16SUBPASSINPUT */
F16SUBPASSINPUTMS = 574, /* F16SUBPASSINPUTMS */
SPIRV_INSTRUCTION = 575, /* SPIRV_INSTRUCTION */
SPIRV_EXECUTION_MODE = 576, /* SPIRV_EXECUTION_MODE */
SPIRV_EXECUTION_MODE_ID = 577, /* SPIRV_EXECUTION_MODE_ID */
SPIRV_DECORATE = 578, /* SPIRV_DECORATE */
SPIRV_DECORATE_ID = 579, /* SPIRV_DECORATE_ID */
SPIRV_DECORATE_STRING = 580, /* SPIRV_DECORATE_STRING */
SPIRV_TYPE = 581, /* SPIRV_TYPE */
SPIRV_STORAGE_CLASS = 582, /* SPIRV_STORAGE_CLASS */
SPIRV_BY_REFERENCE = 583, /* SPIRV_BY_REFERENCE */
SPIRV_LITERAL = 584, /* SPIRV_LITERAL */
ATTACHMENTEXT = 585, /* ATTACHMENTEXT */
IATTACHMENTEXT = 586, /* IATTACHMENTEXT */
UATTACHMENTEXT = 587, /* UATTACHMENTEXT */
LEFT_OP = 588, /* LEFT_OP */
RIGHT_OP = 589, /* RIGHT_OP */
INC_OP = 590, /* INC_OP */
DEC_OP = 591, /* DEC_OP */
LE_OP = 592, /* LE_OP */
GE_OP = 593, /* GE_OP */
EQ_OP = 594, /* EQ_OP */
NE_OP = 595, /* NE_OP */
AND_OP = 596, /* AND_OP */
OR_OP = 597, /* OR_OP */
XOR_OP = 598, /* XOR_OP */
MUL_ASSIGN = 599, /* MUL_ASSIGN */
DIV_ASSIGN = 600, /* DIV_ASSIGN */
ADD_ASSIGN = 601, /* ADD_ASSIGN */
MOD_ASSIGN = 602, /* MOD_ASSIGN */
LEFT_ASSIGN = 603, /* LEFT_ASSIGN */
RIGHT_ASSIGN = 604, /* RIGHT_ASSIGN */
AND_ASSIGN = 605, /* AND_ASSIGN */
XOR_ASSIGN = 606, /* XOR_ASSIGN */
OR_ASSIGN = 607, /* OR_ASSIGN */
SUB_ASSIGN = 608, /* SUB_ASSIGN */
STRING_LITERAL = 609, /* STRING_LITERAL */
LEFT_PAREN = 610, /* LEFT_PAREN */
RIGHT_PAREN = 611, /* RIGHT_PAREN */
LEFT_BRACKET = 612, /* LEFT_BRACKET */
RIGHT_BRACKET = 613, /* RIGHT_BRACKET */
LEFT_BRACE = 614, /* LEFT_BRACE */
RIGHT_BRACE = 615, /* RIGHT_BRACE */
DOT = 616, /* DOT */
COMMA = 617, /* COMMA */
COLON = 618, /* COLON */
EQUAL = 619, /* EQUAL */
SEMICOLON = 620, /* SEMICOLON */
BANG = 621, /* BANG */
DASH = 622, /* DASH */
TILDE = 623, /* TILDE */
PLUS = 624, /* PLUS */
STAR = 625, /* STAR */
SLASH = 626, /* SLASH */
PERCENT = 627, /* PERCENT */
LEFT_ANGLE = 628, /* LEFT_ANGLE */
RIGHT_ANGLE = 629, /* RIGHT_ANGLE */
VERTICAL_BAR = 630, /* VERTICAL_BAR */
CARET = 631, /* CARET */
AMPERSAND = 632, /* AMPERSAND */
QUESTION = 633, /* QUESTION */
INVARIANT = 634, /* INVARIANT */
HIGH_PRECISION = 635, /* HIGH_PRECISION */
MEDIUM_PRECISION = 636, /* MEDIUM_PRECISION */
LOW_PRECISION = 637, /* LOW_PRECISION */
PRECISION = 638, /* PRECISION */
PACKED = 639, /* PACKED */
RESOURCE = 640, /* RESOURCE */
SUPERP = 641, /* SUPERP */
FLOATCONSTANT = 642, /* FLOATCONSTANT */
INTCONSTANT = 643, /* INTCONSTANT */
UINTCONSTANT = 644, /* UINTCONSTANT */
BOOLCONSTANT = 645, /* BOOLCONSTANT */
IDENTIFIER = 646, /* IDENTIFIER */
TYPE_NAME = 647, /* TYPE_NAME */
CENTROID = 648, /* CENTROID */
IN = 649, /* IN */
OUT = 650, /* OUT */
INOUT = 651, /* INOUT */
STRUCT = 652, /* STRUCT */
VOID = 653, /* VOID */
WHILE = 654, /* WHILE */
BREAK = 655, /* BREAK */
CONTINUE = 656, /* CONTINUE */
DO = 657, /* DO */
ELSE = 658, /* ELSE */
FOR = 659, /* FOR */
IF = 660, /* IF */
DISCARD = 661, /* DISCARD */
RETURN = 662, /* RETURN */
SWITCH = 663, /* SWITCH */
CASE = 664, /* CASE */
DEFAULT = 665, /* DEFAULT */
TERMINATE_INVOCATION = 666, /* TERMINATE_INVOCATION */
TERMINATE_RAY = 667, /* TERMINATE_RAY */
IGNORE_INTERSECTION = 668, /* IGNORE_INTERSECTION */
UNIFORM = 669, /* UNIFORM */
SHARED = 670, /* SHARED */
BUFFER = 671, /* BUFFER */
TILEIMAGEEXT = 672, /* TILEIMAGEEXT */
FLAT = 673, /* FLAT */
SMOOTH = 674, /* SMOOTH */
LAYOUT = 675, /* LAYOUT */
DOUBLECONSTANT = 676, /* DOUBLECONSTANT */
INT16CONSTANT = 677, /* INT16CONSTANT */
UINT16CONSTANT = 678, /* UINT16CONSTANT */
FLOAT16CONSTANT = 679, /* FLOAT16CONSTANT */
INT32CONSTANT = 680, /* INT32CONSTANT */
UINT32CONSTANT = 681, /* UINT32CONSTANT */
INT64CONSTANT = 682, /* INT64CONSTANT */
UINT64CONSTANT = 683, /* UINT64CONSTANT */
SUBROUTINE = 684, /* SUBROUTINE */
DEMOTE = 685, /* DEMOTE */
PAYLOADNV = 686, /* PAYLOADNV */
PAYLOADINNV = 687, /* PAYLOADINNV */
HITATTRNV = 688, /* HITATTRNV */
CALLDATANV = 689, /* CALLDATANV */
CALLDATAINNV = 690, /* CALLDATAINNV */
PAYLOADEXT = 691, /* PAYLOADEXT */
PAYLOADINEXT = 692, /* PAYLOADINEXT */
HITATTREXT = 693, /* HITATTREXT */
CALLDATAEXT = 694, /* CALLDATAEXT */
CALLDATAINEXT = 695, /* CALLDATAINEXT */
PATCH = 696, /* PATCH */
SAMPLE = 697, /* SAMPLE */
NONUNIFORM = 698, /* NONUNIFORM */
COHERENT = 699, /* COHERENT */
VOLATILE = 700, /* VOLATILE */
RESTRICT = 701, /* RESTRICT */
READONLY = 702, /* READONLY */
WRITEONLY = 703, /* WRITEONLY */
DEVICECOHERENT = 704, /* DEVICECOHERENT */
QUEUEFAMILYCOHERENT = 705, /* QUEUEFAMILYCOHERENT */
WORKGROUPCOHERENT = 706, /* WORKGROUPCOHERENT */
SUBGROUPCOHERENT = 707, /* SUBGROUPCOHERENT */
NONPRIVATE = 708, /* NONPRIVATE */
SHADERCALLCOHERENT = 709, /* SHADERCALLCOHERENT */
NOPERSPECTIVE = 710, /* NOPERSPECTIVE */
EXPLICITINTERPAMD = 711, /* EXPLICITINTERPAMD */
PERVERTEXEXT = 712, /* PERVERTEXEXT */
PERVERTEXNV = 713, /* PERVERTEXNV */
PERPRIMITIVENV = 714, /* PERPRIMITIVENV */
PERVIEWNV = 715, /* PERVIEWNV */
PERTASKNV = 716, /* PERTASKNV */
PERPRIMITIVEEXT = 717, /* PERPRIMITIVEEXT */
TASKPAYLOADWORKGROUPEXT = 718, /* TASKPAYLOADWORKGROUPEXT */
PRECISE = 719 /* PRECISE */
};
typedef enum yytokentype yytoken_kind_t;
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 72 "MachineIndependent/glslang.y"
struct {
glslang::TSourceLoc loc;
union {
glslang::TString *string;
int i;
unsigned int u;
long long i64;
unsigned long long u64;
bool b;
double d;
};
glslang::TSymbol* symbol;
} lex;
struct {
glslang::TSourceLoc loc;
glslang::TOperator op;
union {
TIntermNode* intermNode;
glslang::TIntermNodePair nodePair;
glslang::TIntermTyped* intermTypedNode;
glslang::TAttributes* attributes;
glslang::TSpirvRequirement* spirvReq;
glslang::TSpirvInstruction* spirvInst;
glslang::TSpirvTypeParameters* spirvTypeParams;
};
union {
glslang::TPublicType type;
glslang::TFunction* function;
glslang::TParameter param;
glslang::TTypeLoc typeLine;
glslang::TTypeList* typeList;
glslang::TArraySizes* arraySizes;
glslang::TIdentifierList* identifierList;
};
glslang::TTypeParameters* typeParameters;
} interm;
#line 567 "MachineIndependent/glslang_tab.cpp.h"
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
int yyparse (glslang::TParseContext* pParseContext);
#endif /* !YY_YY_MACHINEINDEPENDENT_GLSLANG_TAB_CPP_H_INCLUDED */
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/span.h | #pragma once
//
// Copyright (C) 2023 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Partial implementation of std::span for C++11
// Replace with std::span if repo standard is bumped to C++20
//
// This code was copied from https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/main/layers/containers/custom_containers.h
template <typename T>
class span {
public:
using pointer = T *;
using const_pointer = T const *;
using iterator = pointer;
using const_iterator = const_pointer;
span() = default;
span(pointer start, size_t n) : data_(start), count_(n) {}
template <typename Iterator>
span(Iterator start, Iterator end) : data_(&(*start)), count_(end - start) {}
template <typename Container>
span(Container &c) : data_(c.data()), count_(c.size()) {}
iterator begin() { return data_; }
const_iterator begin() const { return data_; }
iterator end() { return data_ + count_; }
const_iterator end() const { return data_ + count_; }
T &operator[](int i) { return data_[i]; }
const T &operator[](int i) const { return data_[i]; }
T &front() { return *data_; }
const T &front() const { return *data_; }
T &back() { return *(data_ + (count_ - 1)); }
const T &back() const { return *(data_ + (count_ - 1)); }
size_t size() const { return count_; }
bool empty() const { return count_ == 0; }
pointer data() { return data_; }
const_pointer data() const { return data_; }
private:
pointer data_ = {};
size_t count_ = 0;
};
//
// Allow type inference that using the constructor doesn't allow in C++11
template <typename T>
span<T> make_span(T *begin, size_t count) {
return span<T>(begin, count);
}
template <typename T>
span<T> make_span(T *begin, T *end) {
return make_span<T>(begin, end);
}
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/ParseHelper.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2015 LunarG, Inc.
// Copyright (C) 2015-2018 Google, Inc.
// Copyright (C) 2017, 2019 ARM Limited.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
// Modifications Copyright (C) 2024 Ravi Prakash Singh.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "ParseHelper.h"
#include "Initialize.h"
#include "Scan.h"
#include "../OSDependent/osinclude.h"
#include <algorithm>
#include "preprocessor/PpContext.h"
extern int yyparse(glslang::TParseContext*);
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,
const TString* entryPoint) :
TParseContextBase(symbolTable, interm, parsingBuiltins, version, profile, spvVersion, language,
infoSink, forwardCompatible, messages, entryPoint),
inMain(false),
blockName(nullptr),
limits(resources.limits),
atomicUintOffsets(nullptr), anyIndexLimits(false)
{
// decide whether precision qualifiers should be ignored or respected
if (isEsProfile() || spvVersion.vulkan > 0) {
precisionManager.respectPrecisionQualifiers();
if (! parsingBuiltins && language == EShLangFragment && !isEsProfile() && spvVersion.vulkan > 0)
precisionManager.warnAboutDefaults();
}
setPrecisionDefaults();
globalUniformDefaults.clear();
globalUniformDefaults.layoutMatrix = ElmColumnMajor;
globalUniformDefaults.layoutPacking = spvVersion.spv != 0 ? ElpStd140 : ElpShared;
globalBufferDefaults.clear();
globalBufferDefaults.layoutMatrix = ElmColumnMajor;
globalBufferDefaults.layoutPacking = spvVersion.spv != 0 ? ElpStd430 : ElpShared;
globalInputDefaults.clear();
globalOutputDefaults.clear();
globalSharedDefaults.clear();
globalSharedDefaults.layoutMatrix = ElmColumnMajor;
globalSharedDefaults.layoutPacking = ElpStd430;
// "Shaders in the transform
// feedback capturing mode have an initial global default of
// layout(xfb_buffer = 0) out;"
if (language == EShLangVertex ||
language == EShLangTessControl ||
language == EShLangTessEvaluation ||
language == EShLangGeometry)
globalOutputDefaults.layoutXfbBuffer = 0;
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()
{
delete [] atomicUintOffsets;
}
// Set up all default precisions as needed by the current environment.
// Intended just as a TParseContext constructor helper.
void TParseContext::setPrecisionDefaults()
{
// Set all precision defaults to EpqNone, which is correct for all types
// when not obeying precision qualifiers, and correct for types that don't
// have defaults (thus getting an error on use) when obeying precision
// qualifiers.
for (int type = 0; type < EbtNumTypes; ++type)
defaultPrecision[type] = EpqNone;
for (int type = 0; type < maxSamplerIndex; ++type)
defaultSamplerPrecision[type] = EpqNone;
// replace with real precision defaults for those that have them
if (obeyPrecisionQualifiers()) {
if (isEsProfile()) {
// Most don't have defaults, a few default to lowp.
TSampler sampler;
sampler.set(EbtFloat, Esd2D);
defaultSamplerPrecision[computeSamplerTypeIndex(sampler)] = EpqLow;
sampler.set(EbtFloat, EsdCube);
defaultSamplerPrecision[computeSamplerTypeIndex(sampler)] = EpqLow;
sampler.set(EbtFloat, Esd2D);
sampler.setExternal(true);
defaultSamplerPrecision[computeSamplerTypeIndex(sampler)] = EpqLow;
}
// If we are parsing built-in computational variables/functions, it is meaningful to record
// whether the built-in has no precision qualifier, as that ambiguity
// is used to resolve the precision from the supplied arguments/operands instead.
// So, we don't actually want to replace EpqNone with a default precision for built-ins.
if (! parsingBuiltins) {
if (isEsProfile() && language == EShLangFragment) {
defaultPrecision[EbtInt] = EpqMedium;
defaultPrecision[EbtUint] = EpqMedium;
} else {
defaultPrecision[EbtInt] = EpqHigh;
defaultPrecision[EbtUint] = EpqHigh;
defaultPrecision[EbtFloat] = EpqHigh;
}
if (!isEsProfile()) {
// Non-ES profile
// All sampler precisions default to highp.
for (int type = 0; type < maxSamplerIndex; ++type)
defaultSamplerPrecision[type] = EpqHigh;
}
}
defaultPrecision[EbtSampler] = EpqLow;
defaultPrecision[EbtAtomicUint] = EpqHigh;
}
}
void TParseContext::setLimits(const TBuiltInResource& r)
{
resources = r;
intermediate.setLimits(r);
anyIndexLimits = ! limits.generalAttributeMatrixVectorIndexing ||
! limits.generalConstantMatrixVectorIndexing ||
! limits.generalSamplerIndexing ||
! limits.generalUniformIndexing ||
! limits.generalVariableIndexing ||
! limits.generalVaryingIndexing;
// "Each binding point tracks its own current default offset for
// inheritance of subsequent variables using the same binding. The initial state of compilation is that all
// binding points have an offset of 0."
atomicUintOffsets = new int[resources.maxAtomicCounterBindings];
for (int b = 0; b < resources.maxAtomicCounterBindings; ++b)
atomicUintOffsets[b] = 0;
}
//
// Parse an array of strings using yyparse, going through the
// preprocessor to tokenize the shader strings, then through
// the GLSL scanner.
//
// Returns true for successful acceptance of the shader, false if any errors.
//
bool TParseContext::parseShaderStrings(TPpContext& ppContext, TInputScanner& input, bool versionWillBeError)
{
currentScanner = &input;
ppContext.setInput(input, versionWillBeError);
yyparse(this);
finish();
return numErrors == 0;
}
// This is called from bison when it has a parse (syntax) error
// Note though that to stop cascading errors, we set EOF, which
// will usually cause a syntax error, so be more accurate that
// compilation is terminating.
void TParseContext::parserError(const char* s)
{
if (! getScanner()->atEndOfInput() || numErrors == 0)
error(getCurrentLoc(), "", "", s, "");
else
error(getCurrentLoc(), "compilation terminated", "", "");
}
void TParseContext::growGlobalUniformBlock(const TSourceLoc& loc, TType& memberType, const TString& memberName, TTypeList* typeList)
{
bool createBlock = globalUniformBlock == nullptr;
if (createBlock) {
globalUniformBinding = intermediate.getGlobalUniformBinding();
globalUniformSet = intermediate.getGlobalUniformSet();
}
// use base class function to create/expand block
TParseContextBase::growGlobalUniformBlock(loc, memberType, memberName, typeList);
if (spvVersion.vulkan > 0 && spvVersion.vulkanRelaxed) {
// check for a block storage override
TBlockStorageClass storageOverride = intermediate.getBlockStorageOverride(getGlobalUniformBlockName());
TQualifier& qualifier = globalUniformBlock->getWritableType().getQualifier();
qualifier.defaultBlock = true;
if (storageOverride != EbsNone) {
if (createBlock) {
// Remap block storage
qualifier.setBlockStorage(storageOverride);
// check that the change didn't create errors
blockQualifierCheck(loc, qualifier, false);
}
// remap meber storage as well
memberType.getQualifier().setBlockStorage(storageOverride);
}
}
}
void TParseContext::growAtomicCounterBlock(int binding, const TSourceLoc& loc, TType& memberType, const TString& memberName, TTypeList* typeList)
{
bool createBlock = atomicCounterBuffers.find(binding) == atomicCounterBuffers.end();
if (createBlock) {
atomicCounterBlockSet = intermediate.getAtomicCounterBlockSet();
}
// use base class function to create/expand block
TParseContextBase::growAtomicCounterBlock(binding, loc, memberType, memberName, typeList);
TQualifier& qualifier = atomicCounterBuffers[binding]->getWritableType().getQualifier();
qualifier.defaultBlock = true;
if (spvVersion.vulkan > 0 && spvVersion.vulkanRelaxed) {
// check for a Block storage override
TBlockStorageClass storageOverride = intermediate.getBlockStorageOverride(getAtomicCounterBlockName());
if (storageOverride != EbsNone) {
if (createBlock) {
// Remap block storage
qualifier.setBlockStorage(storageOverride);
// check that the change didn't create errors
blockQualifierCheck(loc, qualifier, false);
}
// remap meber storage as well
memberType.getQualifier().setBlockStorage(storageOverride);
}
}
}
const char* TParseContext::getGlobalUniformBlockName() const
{
const char* name = intermediate.getGlobalUniformBlockName();
if (std::string(name) == "")
return "gl_DefaultUniformBlock";
else
return name;
}
void TParseContext::finalizeGlobalUniformBlockLayout(TVariable&)
{
}
void TParseContext::setUniformBlockDefaults(TType& block) const
{
block.getQualifier().layoutPacking = ElpStd140;
block.getQualifier().layoutMatrix = ElmColumnMajor;
}
const char* TParseContext::getAtomicCounterBlockName() const
{
const char* name = intermediate.getAtomicCounterBlockName();
if (std::string(name) == "")
return "gl_AtomicCounterBlock";
else
return name;
}
void TParseContext::finalizeAtomicCounterBlockLayout(TVariable&)
{
}
void TParseContext::setAtomicCounterBlockDefaults(TType& block) const
{
block.getQualifier().layoutPacking = ElpStd430;
block.getQualifier().layoutMatrix = ElmRowMajor;
}
void TParseContext::setInvariant(const TSourceLoc& loc, const char* builtin) {
TSymbol* symbol = symbolTable.find(builtin);
if (symbol && symbol->getType().getQualifier().isPipeOutput()) {
if (intermediate.inIoAccessed(builtin))
warn(loc, "changing qualification after use", "invariant", builtin);
TSymbol* csymbol = symbolTable.copyUp(symbol);
csymbol->getWritableType().getQualifier().invariant = true;
}
}
void TParseContext::handlePragma(const TSourceLoc& loc, const TVector<TString>& tokens)
{
if (pragmaCallback)
pragmaCallback(loc.line, tokens);
if (tokens.size() == 0)
return;
if (tokens[0].compare("optimize") == 0) {
if (tokens.size() != 4) {
error(loc, "optimize pragma syntax is incorrect", "#pragma", "");
return;
}
if (tokens[1].compare("(") != 0) {
error(loc, "\"(\" expected after 'optimize' keyword", "#pragma", "");
return;
}
if (tokens[2].compare("on") == 0)
contextPragma.optimize = true;
else if (tokens[2].compare("off") == 0)
contextPragma.optimize = false;
else {
if(relaxedErrors())
// If an implementation does not recognize the tokens following #pragma, then it will ignore that pragma.
warn(loc, "\"on\" or \"off\" expected after '(' for 'optimize' pragma", "#pragma", "");
return;
}
if (tokens[3].compare(")") != 0) {
error(loc, "\")\" expected to end 'optimize' pragma", "#pragma", "");
return;
}
} else if (tokens[0].compare("debug") == 0) {
if (tokens.size() != 4) {
error(loc, "debug pragma syntax is incorrect", "#pragma", "");
return;
}
if (tokens[1].compare("(") != 0) {
error(loc, "\"(\" expected after 'debug' keyword", "#pragma", "");
return;
}
if (tokens[2].compare("on") == 0)
contextPragma.debug = true;
else if (tokens[2].compare("off") == 0)
contextPragma.debug = false;
else {
if(relaxedErrors())
// If an implementation does not recognize the tokens following #pragma, then it will ignore that pragma.
warn(loc, "\"on\" or \"off\" expected after '(' for 'debug' pragma", "#pragma", "");
return;
}
if (tokens[3].compare(")") != 0) {
error(loc, "\")\" expected to end 'debug' pragma", "#pragma", "");
return;
}
} else if (spvVersion.spv > 0 && tokens[0].compare("use_storage_buffer") == 0) {
if (tokens.size() != 1)
error(loc, "extra tokens", "#pragma", "");
intermediate.setUseStorageBuffer();
} else if (spvVersion.spv > 0 && tokens[0].compare("use_vulkan_memory_model") == 0) {
if (tokens.size() != 1)
error(loc, "extra tokens", "#pragma", "");
intermediate.setUseVulkanMemoryModel();
} else if (spvVersion.spv > 0 && tokens[0].compare("use_variable_pointers") == 0) {
if (tokens.size() != 1)
error(loc, "extra tokens", "#pragma", "");
if (spvVersion.spv < glslang::EShTargetSpv_1_3)
error(loc, "requires SPIR-V 1.3", "#pragma use_variable_pointers", "");
intermediate.setUseVariablePointers();
} else if (spvVersion.spv > 0 && tokens[0].compare("use_replicated_composites") == 0) {
if (tokens.size() != 1)
error(loc, "extra tokens", "#pragma", "");
intermediate.setReplicatedComposites();
} else if (tokens[0].compare("once") == 0) {
warn(loc, "not implemented", "#pragma once", "");
} else if (tokens[0].compare("glslang_binary_double_output") == 0) {
intermediate.setBinaryDoubleOutput();
} else if (spvVersion.spv > 0 && tokens[0].compare("STDGL") == 0 &&
tokens[1].compare("invariant") == 0 && tokens[3].compare("all") == 0) {
intermediate.setInvariantAll();
// Set all builtin out variables invariant if declared
setInvariant(loc, "gl_Position");
setInvariant(loc, "gl_PointSize");
setInvariant(loc, "gl_ClipDistance");
setInvariant(loc, "gl_CullDistance");
setInvariant(loc, "gl_TessLevelOuter");
setInvariant(loc, "gl_TessLevelInner");
setInvariant(loc, "gl_PrimitiveID");
setInvariant(loc, "gl_Layer");
setInvariant(loc, "gl_ViewportIndex");
setInvariant(loc, "gl_FragDepth");
setInvariant(loc, "gl_SampleMask");
setInvariant(loc, "gl_ClipVertex");
setInvariant(loc, "gl_FrontColor");
setInvariant(loc, "gl_BackColor");
setInvariant(loc, "gl_FrontSecondaryColor");
setInvariant(loc, "gl_BackSecondaryColor");
setInvariant(loc, "gl_TexCoord");
setInvariant(loc, "gl_FogFragCoord");
setInvariant(loc, "gl_FragColor");
setInvariant(loc, "gl_FragData");
}
}
//
// Handle seeing a variable identifier in the grammar.
//
TIntermTyped* TParseContext::handleVariable(const TSourceLoc& loc, TSymbol* symbol, const TString* string)
{
TIntermTyped* node = nullptr;
// Error check for requiring specific extensions present.
if (symbol && symbol->getNumExtensions())
requireExtensions(loc, symbol->getNumExtensions(), symbol->getExtensions(), symbol->getName().c_str());
if (symbol && symbol->isReadOnly()) {
// All shared things containing an unsized array must be copied up
// on first use, so that all future references will share its array structure,
// so that editing the implicit size will effect all nodes consuming it,
// and so that editing the implicit size won't change the shared one.
//
// If this is a variable or a block, check it and all it contains, but if this
// is a member of an anonymous block, check the whole block, as the whole block
// will need to be copied up if it contains an unsized array.
//
// This check is being done before the block-name check further down, so guard
// for that too.
if (!symbol->getType().isUnusableName()) {
if (symbol->getType().containsUnsizedArray() ||
(symbol->getAsAnonMember() &&
symbol->getAsAnonMember()->getAnonContainer().getType().containsUnsizedArray()))
makeEditable(symbol);
}
}
const TVariable* variable;
const TAnonMember* anon = symbol ? symbol->getAsAnonMember() : nullptr;
if (anon) {
// It was a member of an anonymous container.
// Create a subtree for its dereference.
variable = anon->getAnonContainer().getAsVariable();
TIntermTyped* container = intermediate.addSymbol(*variable, loc);
TIntermTyped* constNode = intermediate.addConstantUnion(anon->getMemberNumber(), loc);
node = intermediate.addIndex(EOpIndexDirectStruct, container, constNode, loc);
node->setType(*(*variable->getType().getStruct())[anon->getMemberNumber()].type);
if (node->getType().hiddenMember())
error(loc, "member of nameless block was not redeclared", string->c_str(), "");
} else {
// Not a member of an anonymous container.
// The symbol table search was done in the lexical phase.
// See if it was a variable.
variable = symbol ? symbol->getAsVariable() : nullptr;
if (variable) {
if (variable->getType().isUnusableName()) {
error(loc, "cannot be used (maybe an instance name is needed)", string->c_str(), "");
variable = nullptr;
}
if (language == EShLangMesh && variable) {
TLayoutGeometry primitiveType = intermediate.getOutputPrimitive();
if ((variable->getMangledName() == "gl_PrimitiveTriangleIndicesEXT" && primitiveType != ElgTriangles) ||
(variable->getMangledName() == "gl_PrimitiveLineIndicesEXT" && primitiveType != ElgLines) ||
(variable->getMangledName() == "gl_PrimitivePointIndicesEXT" && primitiveType != ElgPoints)) {
error(loc, "cannot be used (output primitive type mismatch)", string->c_str(), "");
variable = nullptr;
}
}
} else {
if (symbol)
error(loc, "variable name expected", string->c_str(), "");
}
// Recovery, if it wasn't found or was not a variable.
if (! variable)
variable = new TVariable(string, TType(EbtVoid));
if (variable->getType().getQualifier().isFrontEndConstant())
node = intermediate.addConstantUnion(variable->getConstArray(), variable->getType(), loc);
else
node = intermediate.addSymbol(*variable, loc);
}
if (variable->getType().getQualifier().isIo())
intermediate.addIoAccessed(*string);
if (variable->getType().isReference() &&
variable->getType().getQualifier().bufferReferenceNeedsVulkanMemoryModel()) {
intermediate.setUseVulkanMemoryModel();
}
return node;
}
//
// Handle seeing a base[index] dereference in the grammar.
//
TIntermTyped* TParseContext::handleBracketDereference(const TSourceLoc& loc, TIntermTyped* base, TIntermTyped* index)
{
int indexValue = 0;
if (index->getQualifier().isFrontEndConstant())
indexValue = index->getAsConstantUnion()->getConstArray()[0].getIConst();
// basic type checks...
variableCheck(base);
if (! base->isArray() && ! base->isMatrix() && ! base->isVector() && ! base->getType().isCoopMat() &&
! base->isReference()) {
if (base->getAsSymbolNode())
error(loc, " left of '[' is not of type array, matrix, or vector ", base->getAsSymbolNode()->getName().c_str(), "");
else
error(loc, " left of '[' is not of type array, matrix, or vector ", "expression", "");
// Insert dummy error-recovery result
return intermediate.addConstantUnion(0.0, EbtFloat, loc);
}
if (!base->isArray() && base->isVector()) {
if (base->getType().contains16BitFloat())
requireFloat16Arithmetic(loc, "[", "does not operate on types containing float16");
if (base->getType().contains16BitInt())
requireInt16Arithmetic(loc, "[", "does not operate on types containing (u)int16");
if (base->getType().contains8BitInt())
requireInt8Arithmetic(loc, "[", "does not operate on types containing (u)int8");
}
// check for constant folding
if (base->getType().getQualifier().isFrontEndConstant() && index->getQualifier().isFrontEndConstant()) {
// both base and index are front-end constants
checkIndex(loc, base->getType(), indexValue);
return intermediate.foldDereference(base, indexValue, loc);
}
// at least one of base and index is not a front-end constant variable...
TIntermTyped* result = nullptr;
if (base->isReference() && ! base->isArray()) {
requireExtensions(loc, 1, &E_GL_EXT_buffer_reference2, "buffer reference indexing");
if (base->getType().getReferentType()->containsUnsizedArray()) {
error(loc, "cannot index reference to buffer containing an unsized array", "", "");
result = nullptr;
} else {
result = intermediate.addBinaryMath(EOpAdd, base, index, loc);
if (result != nullptr)
result->setType(base->getType());
}
if (result == nullptr) {
error(loc, "cannot index buffer reference", "", "");
result = intermediate.addConstantUnion(0.0, EbtFloat, loc);
}
return result;
}
if (base->getAsSymbolNode() && isIoResizeArray(base->getType()))
handleIoResizeArrayAccess(loc, base);
if (index->getQualifier().isFrontEndConstant())
checkIndex(loc, base->getType(), indexValue);
if (index->getQualifier().isFrontEndConstant()) {
if (base->getType().isUnsizedArray()) {
base->getWritableType().updateImplicitArraySize(indexValue + 1);
base->getWritableType().setImplicitlySized(true);
if (base->getQualifier().builtIn == EbvClipDistance &&
indexValue >= resources.maxClipDistances) {
error(loc, "gl_ClipDistance", "[", "array index out of range '%d'", indexValue);
}
else if (base->getQualifier().builtIn == EbvCullDistance &&
indexValue >= resources.maxCullDistances) {
error(loc, "gl_CullDistance", "[", "array index out of range '%d'", indexValue);
}
else if (base->getQualifier().builtIn == EbvSampleMask &&
indexValue >= (resources.maxSamples + 31) / 32) {
error(loc, "gl_SampleMask", "[", "array index out of range '%d'", indexValue);
}
// For 2D per-view builtin arrays, update the inner dimension size in parent type
if (base->getQualifier().isPerView() && base->getQualifier().builtIn != EbvNone) {
TIntermBinary* binaryNode = base->getAsBinaryNode();
if (binaryNode) {
TType& leftType = binaryNode->getLeft()->getWritableType();
TArraySizes& arraySizes = *leftType.getArraySizes();
assert(arraySizes.getNumDims() == 2);
arraySizes.setDimSize(1, std::max(arraySizes.getDimSize(1), indexValue + 1));
}
}
} else
checkIndex(loc, base->getType(), indexValue);
result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
} else {
if (base->getType().isUnsizedArray()) {
// we have a variable index into an unsized array, which is okay,
// depending on the situation
if (base->getAsSymbolNode() && isIoResizeArray(base->getType()))
error(loc, "", "[", "array must be sized by a redeclaration or layout qualifier before being indexed with a variable");
else {
// it is okay for a run-time sized array
checkRuntimeSizable(loc, *base);
}
base->getWritableType().setArrayVariablyIndexed();
}
if (base->getBasicType() == EbtBlock) {
if (base->getQualifier().storage == EvqBuffer)
requireProfile(base->getLoc(), ~EEsProfile, "variable indexing buffer block array");
else if (base->getQualifier().storage == EvqUniform)
profileRequires(base->getLoc(), EEsProfile, 320, Num_AEP_gpu_shader5, AEP_gpu_shader5,
"variable indexing uniform block array");
else {
// input/output blocks either don't exist or can't be variably indexed
}
} else if (language == EShLangFragment && base->getQualifier().isPipeOutput() && base->getQualifier().builtIn != EbvSampleMask)
requireProfile(base->getLoc(), ~EEsProfile, "variable indexing fragment shader output array");
else if (base->getBasicType() == EbtSampler && version >= 130) {
const char* explanation = "variable indexing sampler array";
requireProfile(base->getLoc(), EEsProfile | ECoreProfile | ECompatibilityProfile, explanation);
profileRequires(base->getLoc(), EEsProfile, 320, Num_AEP_gpu_shader5, AEP_gpu_shader5, explanation);
profileRequires(base->getLoc(), ECoreProfile | ECompatibilityProfile, 400, nullptr, explanation);
}
result = intermediate.addIndex(EOpIndexIndirect, base, index, loc);
}
// Insert valid dereferenced result type
TType newType(base->getType(), 0);
if (base->getType().getQualifier().isConstant() && index->getQualifier().isConstant()) {
newType.getQualifier().storage = EvqConst;
// If base or index is a specialization constant, the result should also be a specialization constant.
if (base->getType().getQualifier().isSpecConstant() || index->getQualifier().isSpecConstant()) {
newType.getQualifier().makeSpecConstant();
}
} else {
newType.getQualifier().storage = EvqTemporary;
newType.getQualifier().specConstant = false;
}
result->setType(newType);
inheritMemoryQualifiers(base->getQualifier(), result->getWritableType().getQualifier());
// Propagate nonuniform
if (base->getQualifier().isNonUniform() || index->getQualifier().isNonUniform())
result->getWritableType().getQualifier().nonUniform = true;
if (anyIndexLimits)
handleIndexLimits(loc, base, index);
return result;
}
// for ES 2.0 (version 100) limitations for almost all index operations except vertex-shader uniforms
void TParseContext::handleIndexLimits(const TSourceLoc& /*loc*/, TIntermTyped* base, TIntermTyped* index)
{
if ((! limits.generalSamplerIndexing && base->getBasicType() == EbtSampler) ||
(! limits.generalUniformIndexing && base->getQualifier().isUniformOrBuffer() && language != EShLangVertex) ||
(! limits.generalAttributeMatrixVectorIndexing && base->getQualifier().isPipeInput() && language == EShLangVertex && (base->getType().isMatrix() || base->getType().isVector())) ||
(! limits.generalConstantMatrixVectorIndexing && base->getAsConstantUnion()) ||
(! limits.generalVariableIndexing && ! base->getType().getQualifier().isUniformOrBuffer() &&
! base->getType().getQualifier().isPipeInput() &&
! base->getType().getQualifier().isPipeOutput() &&
! base->getType().getQualifier().isConstant()) ||
(! limits.generalVaryingIndexing && (base->getType().getQualifier().isPipeInput() ||
base->getType().getQualifier().isPipeOutput()))) {
// it's too early to know what the inductive variables are, save it for post processing
needsIndexLimitationChecking.push_back(index);
}
}
// Make a shared symbol have a non-shared version that can be edited by the current
// compile, such that editing its type will not change the shared version and will
// effect all nodes sharing it.
void TParseContext::makeEditable(TSymbol*& symbol)
{
TParseContextBase::makeEditable(symbol);
// See if it's tied to IO resizing
if (isIoResizeArray(symbol->getType()))
ioArraySymbolResizeList.push_back(symbol);
}
// Return true if this is a geometry shader input array or tessellation control output array
// or mesh shader output array.
bool TParseContext::isIoResizeArray(const TType& type) const
{
return type.isArray() &&
((language == EShLangGeometry && type.getQualifier().storage == EvqVaryingIn) ||
(language == EShLangTessControl && type.getQualifier().storage == EvqVaryingOut &&
! type.getQualifier().patch) ||
(language == EShLangFragment && type.getQualifier().storage == EvqVaryingIn &&
(type.getQualifier().pervertexNV || type.getQualifier().pervertexEXT)) ||
(language == EShLangMesh && type.getQualifier().storage == EvqVaryingOut &&
!type.getQualifier().perTaskNV));
}
// If an array is not isIoResizeArray() but is an io array, make sure it has the right size
void TParseContext::fixIoArraySize(const TSourceLoc& loc, TType& type)
{
if (! type.isArray() || type.getQualifier().patch || symbolTable.atBuiltInLevel())
return;
assert(! isIoResizeArray(type));
if (type.getQualifier().storage != EvqVaryingIn || type.getQualifier().patch)
return;
if (language == EShLangTessControl || language == EShLangTessEvaluation) {
if (type.getOuterArraySize() != resources.maxPatchVertices) {
if (type.isSizedArray())
error(loc, "tessellation input array size must be gl_MaxPatchVertices or implicitly sized", "[]", "");
type.changeOuterArraySize(resources.maxPatchVertices);
}
}
}
// Issue any errors if the non-array object is missing arrayness WRT
// shader I/O that has array requirements.
// All arrayness checking is handled in array paths, this is for
void TParseContext::ioArrayCheck(const TSourceLoc& loc, const TType& type, const TString& identifier)
{
if (! type.isArray() && ! symbolTable.atBuiltInLevel()) {
if (type.getQualifier().isArrayedIo(language) && !type.getQualifier().layoutPassthrough)
error(loc, "type must be an array:", type.getStorageQualifierString(), identifier.c_str());
}
}
// Handle a dereference of a geometry shader input array or tessellation control output array.
// See ioArraySymbolResizeList comment in ParseHelper.h.
//
void TParseContext::handleIoResizeArrayAccess(const TSourceLoc& /*loc*/, TIntermTyped* base)
{
TIntermSymbol* symbolNode = base->getAsSymbolNode();
assert(symbolNode);
if (! symbolNode)
return;
// fix array size, if it can be fixed and needs to be fixed (will allow variable indexing)
if (symbolNode->getType().isUnsizedArray()) {
int newSize = getIoArrayImplicitSize(symbolNode->getType().getQualifier());
if (newSize > 0)
symbolNode->getWritableType().changeOuterArraySize(newSize);
}
}
// If there has been an input primitive declaration (geometry shader) or an output
// number of vertices declaration(tessellation shader), make sure all input array types
// match it in size. Types come either from nodes in the AST or symbols in the
// symbol table.
//
// Types without an array size will be given one.
// Types already having a size that is wrong will get an error.
//
void TParseContext::checkIoArraysConsistency(const TSourceLoc &loc, bool tailOnly)
{
int requiredSize = 0;
TString featureString;
size_t listSize = ioArraySymbolResizeList.size();
size_t i = 0;
// If tailOnly = true, only check the last array symbol in the list.
if (tailOnly) {
i = listSize - 1;
}
for (bool firstIteration = true; i < listSize; ++i) {
TType &type = ioArraySymbolResizeList[i]->getWritableType();
// As I/O array sizes don't change, fetch requiredSize only once,
// except for mesh shaders which could have different I/O array sizes based on type qualifiers.
if (firstIteration || (language == EShLangMesh)) {
requiredSize = getIoArrayImplicitSize(type.getQualifier(), &featureString);
if (requiredSize == 0)
break;
firstIteration = false;
}
checkIoArrayConsistency(loc, requiredSize, featureString.c_str(), type,
ioArraySymbolResizeList[i]->getName());
}
}
int TParseContext::getIoArrayImplicitSize(const TQualifier &qualifier, TString *featureString) const
{
int expectedSize = 0;
TString str = "unknown";
unsigned int maxVertices = intermediate.getVertices() != TQualifier::layoutNotSet ? intermediate.getVertices() : 0;
if (language == EShLangGeometry) {
expectedSize = TQualifier::mapGeometryToSize(intermediate.getInputPrimitive());
str = TQualifier::getGeometryString(intermediate.getInputPrimitive());
}
else if (language == EShLangTessControl) {
expectedSize = maxVertices;
str = "vertices";
} else if (language == EShLangFragment) {
// Number of vertices for Fragment shader is always three.
expectedSize = 3;
str = "vertices";
} else if (language == EShLangMesh) {
unsigned int maxPrimitives =
intermediate.getPrimitives() != TQualifier::layoutNotSet ? intermediate.getPrimitives() : 0;
if (qualifier.builtIn == EbvPrimitiveIndicesNV) {
expectedSize = maxPrimitives * TQualifier::mapGeometryToSize(intermediate.getOutputPrimitive());
str = "max_primitives*";
str += TQualifier::getGeometryString(intermediate.getOutputPrimitive());
}
else if (qualifier.builtIn == EbvPrimitiveTriangleIndicesEXT || qualifier.builtIn == EbvPrimitiveLineIndicesEXT ||
qualifier.builtIn == EbvPrimitivePointIndicesEXT) {
expectedSize = maxPrimitives;
str = "max_primitives";
}
else if (qualifier.isPerPrimitive()) {
expectedSize = maxPrimitives;
str = "max_primitives";
}
else {
expectedSize = maxVertices;
str = "max_vertices";
}
}
if (featureString)
*featureString = str;
return expectedSize;
}
void TParseContext::checkIoArrayConsistency(const TSourceLoc& loc, int requiredSize, const char* feature, TType& type, const TString& name)
{
if (type.isUnsizedArray())
type.changeOuterArraySize(requiredSize);
else if (type.getOuterArraySize() != requiredSize) {
if (language == EShLangGeometry)
error(loc, "inconsistent input primitive for array size of", feature, name.c_str());
else if (language == EShLangTessControl)
error(loc, "inconsistent output number of vertices for array size of", feature, name.c_str());
else if (language == EShLangFragment) {
if (type.getOuterArraySize() > requiredSize)
error(loc, " cannot be greater than 3 for pervertexEXT", feature, name.c_str());
}
else if (language == EShLangMesh)
error(loc, "inconsistent output array size of", feature, name.c_str());
else
assert(0);
}
}
// Handle seeing a binary node with a math operation.
// Returns nullptr if not semantically allowed.
TIntermTyped* TParseContext::handleBinaryMath(const TSourceLoc& loc, const char* str, TOperator op, TIntermTyped* left, TIntermTyped* right)
{
rValueErrorCheck(loc, str, left->getAsTyped());
rValueErrorCheck(loc, str, right->getAsTyped());
bool allowed = true;
switch (op) {
// TODO: Bring more source language-specific checks up from intermediate.cpp
// to the specific parse helpers for that source language.
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
if (! left->isScalar() || ! right->isScalar())
allowed = false;
break;
default:
break;
}
if (((left->getType().contains16BitFloat() || right->getType().contains16BitFloat()) && !float16Arithmetic()) ||
((left->getType().contains16BitInt() || right->getType().contains16BitInt()) && !int16Arithmetic()) ||
((left->getType().contains8BitInt() || right->getType().contains8BitInt()) && !int8Arithmetic())) {
allowed = false;
}
TIntermTyped* result = nullptr;
if (allowed) {
if ((left->isReference() || right->isReference()))
requireExtensions(loc, 1, &E_GL_EXT_buffer_reference2, "buffer reference math");
result = intermediate.addBinaryMath(op, left, right, loc);
}
if (result == nullptr) {
bool enhanced = intermediate.getEnhancedMsgs();
binaryOpError(loc, str, left->getCompleteString(enhanced), right->getCompleteString(enhanced));
}
return result;
}
// Handle seeing a unary node with a math operation.
TIntermTyped* TParseContext::handleUnaryMath(const TSourceLoc& loc, const char* str, TOperator op, TIntermTyped* childNode)
{
rValueErrorCheck(loc, str, childNode);
bool allowed = true;
if ((childNode->getType().contains16BitFloat() && !float16Arithmetic()) ||
(childNode->getType().contains16BitInt() && !int16Arithmetic()) ||
(childNode->getType().contains8BitInt() && !int8Arithmetic())) {
allowed = false;
}
TIntermTyped* result = nullptr;
if (allowed)
result = intermediate.addUnaryMath(op, childNode, loc);
if (result)
return result;
else {
bool enhanced = intermediate.getEnhancedMsgs();
unaryOpError(loc, str, childNode->getCompleteString(enhanced));
}
return childNode;
}
//
// Handle seeing a base.field dereference in the grammar.
//
TIntermTyped* TParseContext::handleDotDereference(const TSourceLoc& loc, TIntermTyped* base, const TString& field)
{
variableCheck(base);
//
// .length() can't be resolved until we later see the function-calling syntax.
// Save away the name in the AST for now. Processing is completed in
// handleLengthMethod().
//
if (field == "length") {
if (base->isArray()) {
profileRequires(loc, ENoProfile, 120, E_GL_3DL_array_objects, ".length");
profileRequires(loc, EEsProfile, 300, nullptr, ".length");
} else if (base->isVector() || base->isMatrix()) {
const char* feature = ".length() on vectors and matrices";
requireProfile(loc, ~EEsProfile, feature);
profileRequires(loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, feature);
} else if (!base->getType().isCoopMat()) {
bool enhanced = intermediate.getEnhancedMsgs();
error(loc, "does not operate on this type:", field.c_str(), base->getType().getCompleteString(enhanced).c_str());
return base;
}
return intermediate.addMethod(base, TType(EbtInt), &field, loc);
}
// It's not .length() if we get to here.
if (base->isArray()) {
error(loc, "cannot apply to an array:", ".", field.c_str());
return base;
}
if (base->getType().isCoopMat()) {
error(loc, "cannot apply to a cooperative matrix type:", ".", field.c_str());
return base;
}
// It's neither an array nor .length() if we get here,
// leaving swizzles and struct/block dereferences.
TIntermTyped* result = base;
if ((base->isVector() || base->isScalar()) &&
(base->isFloatingDomain() || base->isIntegerDomain() || base->getBasicType() == EbtBool)) {
result = handleDotSwizzle(loc, base, field);
} else if (base->isStruct() || base->isReference()) {
const TTypeList* fields = base->isReference() ?
base->getType().getReferentType()->getStruct() :
base->getType().getStruct();
bool fieldFound = false;
int member;
for (member = 0; member < (int)fields->size(); ++member) {
if ((*fields)[member].type->getFieldName() == field) {
fieldFound = true;
break;
}
}
if (fieldFound) {
if (spvVersion.vulkan != 0 && spvVersion.vulkanRelaxed)
result = vkRelaxedRemapDotDereference(loc, *base, *(*fields)[member].type, field);
if (result == base)
{
if (base->getType().getQualifier().isFrontEndConstant())
result = intermediate.foldDereference(base, member, loc);
else {
blockMemberExtensionCheck(loc, base, member, field);
TIntermTyped* index = intermediate.addConstantUnion(member, loc);
result = intermediate.addIndex(EOpIndexDirectStruct, base, index, loc);
result->setType(*(*fields)[member].type);
if ((*fields)[member].type->getQualifier().isIo())
intermediate.addIoAccessed(field);
}
}
inheritMemoryQualifiers(base->getQualifier(), result->getWritableType().getQualifier());
} else {
auto baseSymbol = base;
while (baseSymbol->getAsSymbolNode() == nullptr) {
auto binaryNode = baseSymbol->getAsBinaryNode();
if (binaryNode == nullptr) break;
baseSymbol = binaryNode->getLeft();
}
if (baseSymbol->getAsSymbolNode() != nullptr) {
TString structName;
structName.append("\'").append(baseSymbol->getAsSymbolNode()->getName().c_str()).append("\'");
error(loc, "no such field in structure", field.c_str(), structName.c_str());
} else {
error(loc, "no such field in structure", field.c_str(), "");
}
}
} else
error(loc, "does not apply to this type:", field.c_str(),
base->getType().getCompleteString(intermediate.getEnhancedMsgs()).c_str());
// Propagate noContraction up the dereference chain
if (base->getQualifier().isNoContraction())
result->getWritableType().getQualifier().setNoContraction();
// Propagate nonuniform
if (base->getQualifier().isNonUniform())
result->getWritableType().getQualifier().nonUniform = true;
return result;
}
//
// Handle seeing a base.swizzle, a subset of base.identifier in the grammar.
//
TIntermTyped* TParseContext::handleDotSwizzle(const TSourceLoc& loc, TIntermTyped* base, const TString& field)
{
TIntermTyped* result = base;
if (base->isScalar()) {
const char* dotFeature = "scalar swizzle";
requireProfile(loc, ~EEsProfile, dotFeature);
profileRequires(loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, dotFeature);
}
TSwizzleSelectors<TVectorSelector> selectors;
parseSwizzleSelector(loc, field, base->getVectorSize(), selectors);
if (base->isVector() && selectors.size() != 1 && base->getType().contains16BitFloat())
requireFloat16Arithmetic(loc, ".", "can't swizzle types containing float16");
if (base->isVector() && selectors.size() != 1 && base->getType().contains16BitInt())
requireInt16Arithmetic(loc, ".", "can't swizzle types containing (u)int16");
if (base->isVector() && selectors.size() != 1 && base->getType().contains8BitInt())
requireInt8Arithmetic(loc, ".", "can't swizzle types containing (u)int8");
if (base->isScalar()) {
if (selectors.size() == 1)
return result;
else {
TType type(base->getBasicType(), EvqTemporary, selectors.size());
// Swizzle operations propagate specialization-constantness
if (base->getQualifier().isSpecConstant())
type.getQualifier().makeSpecConstant();
return addConstructor(loc, base, type);
}
}
if (base->getType().getQualifier().isFrontEndConstant())
result = intermediate.foldSwizzle(base, selectors, loc);
else {
if (selectors.size() == 1) {
TIntermTyped* index = intermediate.addConstantUnion(selectors[0], loc);
result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
result->setType(TType(base->getBasicType(), EvqTemporary, base->getType().getQualifier().precision));
} else {
TIntermTyped* index = intermediate.addSwizzle(selectors, loc);
result = intermediate.addIndex(EOpVectorSwizzle, base, index, loc);
result->setType(TType(base->getBasicType(), EvqTemporary, base->getType().getQualifier().precision, selectors.size()));
}
// Swizzle operations propagate specialization-constantness
if (base->getType().getQualifier().isSpecConstant())
result->getWritableType().getQualifier().makeSpecConstant();
}
return result;
}
void TParseContext::blockMemberExtensionCheck(const TSourceLoc& loc, const TIntermTyped* base, int member, const TString& memberName)
{
// a block that needs extension checking is either 'base', or if arrayed,
// one level removed to the left
const TIntermSymbol* baseSymbol = nullptr;
if (base->getAsBinaryNode() == nullptr)
baseSymbol = base->getAsSymbolNode();
else
baseSymbol = base->getAsBinaryNode()->getLeft()->getAsSymbolNode();
if (baseSymbol == nullptr)
return;
const TSymbol* symbol = symbolTable.find(baseSymbol->getName());
if (symbol == nullptr)
return;
const TVariable* variable = symbol->getAsVariable();
if (variable == nullptr)
return;
if (!variable->hasMemberExtensions())
return;
// We now have a variable that is the base of a dot reference
// with members that need extension checking.
if (variable->getNumMemberExtensions(member) > 0)
requireExtensions(loc, variable->getNumMemberExtensions(member), variable->getMemberExtensions(member), memberName.c_str());
}
//
// Handle seeing a function declarator in the grammar. This is the precursor
// to recognizing a function prototype or function definition.
//
TFunction* TParseContext::handleFunctionDeclarator(const TSourceLoc& loc, TFunction& function, bool prototype)
{
// ES can't declare prototypes inside functions
if (! symbolTable.atGlobalLevel())
requireProfile(loc, ~EEsProfile, "local function declaration");
//
// Multiple declarations of the same function name are allowed.
//
// If this is a definition, the definition production code will check for redefinitions
// (we don't know at this point if it's a definition or not).
//
// Redeclarations (full signature match) are allowed. But, return types and parameter qualifiers must also match.
// - except ES 100, which only allows a single prototype
//
// ES 100 does not allow redefining, but does allow overloading of built-in functions.
// ES 300 does not allow redefining or overloading of built-in functions.
//
bool builtIn;
TSymbol* symbol = symbolTable.find(function.getMangledName(), &builtIn);
if (symbol && symbol->getAsFunction() && builtIn)
requireProfile(loc, ~EEsProfile, "redefinition of built-in function");
// Check the validity of using spirv_literal qualifier
for (int i = 0; i < function.getParamCount(); ++i) {
if (function[i].type->getQualifier().isSpirvLiteral() && function.getBuiltInOp() != EOpSpirvInst)
error(loc, "'spirv_literal' can only be used on functions defined with 'spirv_instruction' for argument",
function.getName().c_str(), "%d", i + 1);
}
// For function declaration with SPIR-V instruction qualifier, always ignore the built-in function and
// respect this redeclared one.
if (symbol && builtIn && function.getBuiltInOp() == EOpSpirvInst)
symbol = nullptr;
const TFunction* prevDec = symbol ? symbol->getAsFunction() : nullptr;
if (prevDec) {
if (prevDec->isPrototyped() && prototype)
profileRequires(loc, EEsProfile, 300, nullptr, "multiple prototypes for same function");
if (prevDec->getType() != function.getType())
error(loc, "overloaded functions must have the same return type", function.getName().c_str(), "");
if (prevDec->getSpirvInstruction() != function.getSpirvInstruction()) {
error(loc, "overloaded functions must have the same qualifiers", function.getName().c_str(),
"spirv_instruction");
}
for (int i = 0; i < prevDec->getParamCount(); ++i) {
if ((*prevDec)[i].type->getQualifier().storage != function[i].type->getQualifier().storage)
error(loc, "overloaded functions must have the same parameter storage qualifiers for argument", function[i].type->getStorageQualifierString(), "%d", i+1);
if ((*prevDec)[i].type->getQualifier().precision != function[i].type->getQualifier().precision)
error(loc, "overloaded functions must have the same parameter precision qualifiers for argument", function[i].type->getPrecisionQualifierString(), "%d", i+1);
}
}
arrayObjectCheck(loc, function.getType(), "array in function return type");
if (prototype) {
// All built-in functions are defined, even though they don't have a body.
// Count their prototype as a definition instead.
if (symbolTable.atBuiltInLevel())
function.setDefined();
else {
if (prevDec && ! builtIn)
symbol->getAsFunction()->setPrototyped(); // need a writable one, but like having prevDec as a const
function.setPrototyped();
}
}
// This insert won't actually insert it if it's a duplicate signature, but it will still check for
// other forms of name collisions.
if (! symbolTable.insert(function))
error(loc, "function name is redeclaration of existing name", function.getName().c_str(), "");
//
// If this is a redeclaration, it could also be a definition,
// in which case, we need to use the parameter names from this one, and not the one that's
// being redeclared. So, pass back this declaration, not the one in the symbol table.
//
return &function;
}
//
// Handle seeing the function prototype in front of a function definition in the grammar.
// The body is handled after this function returns.
//
TIntermAggregate* TParseContext::handleFunctionDefinition(const TSourceLoc& loc, TFunction& function)
{
currentCaller = function.getMangledName();
TSymbol* symbol = symbolTable.find(function.getMangledName());
TFunction* prevDec = symbol ? symbol->getAsFunction() : nullptr;
if (! prevDec)
error(loc, "can't find function", function.getName().c_str(), "");
// Note: 'prevDec' could be 'function' if this is the first time we've seen function
// as it would have just been put in the symbol table. Otherwise, we're looking up
// an earlier occurrence.
if (prevDec && prevDec->isDefined()) {
// Then this function already has a body.
error(loc, "function already has a body", function.getName().c_str(), "");
}
if (prevDec && ! prevDec->isDefined()) {
prevDec->setDefined();
// Remember the return type for later checking for RETURN statements.
currentFunctionType = &(prevDec->getType());
} else
currentFunctionType = new TType(EbtVoid);
functionReturnsValue = false;
// Check for entry point
if (function.getName().compare(intermediate.getEntryPointName().c_str()) == 0) {
intermediate.setEntryPointMangledName(function.getMangledName().c_str());
intermediate.incrementEntryPointCount();
inMain = true;
} else
inMain = false;
//
// Raise error message if main function takes any parameters or returns anything other than void
//
if (inMain) {
if (function.getParamCount() > 0)
error(loc, "function cannot take any parameter(s)", function.getName().c_str(), "");
if (function.getType().getBasicType() != EbtVoid)
error(loc, "", function.getType().getBasicTypeString().c_str(), "entry point cannot return a value");
if (function.getLinkType() != ELinkNone)
error(loc, "main function cannot be exported", "", "");
}
//
// New symbol table scope for body of function plus its arguments
//
symbolTable.push();
//
// Insert parameters into the symbol table.
// If the parameter has no name, it's not an error, just don't insert it
// (could be used for unused args).
//
// Also, accumulate the list of parameters into the HIL, so lower level code
// knows where to find parameters.
//
TIntermAggregate* paramNodes = new TIntermAggregate;
for (int i = 0; i < function.getParamCount(); i++) {
TParameter& param = function[i];
if (param.name != nullptr) {
TVariable *variable = new TVariable(param.name, *param.type);
// Insert the parameters with name in the symbol table.
if (! symbolTable.insert(*variable))
error(loc, "redefinition", variable->getName().c_str(), "");
else {
// Transfer ownership of name pointer to symbol table.
param.name = nullptr;
// Add the parameter to the HIL
paramNodes = intermediate.growAggregate(paramNodes,
intermediate.addSymbol(*variable, loc),
loc);
}
} else
paramNodes = intermediate.growAggregate(paramNodes, intermediate.addSymbol(*param.type, loc), loc);
}
paramNodes->setLinkType(function.getLinkType());
intermediate.setAggregateOperator(paramNodes, EOpParameters, TType(EbtVoid), loc);
loopNestingLevel = 0;
statementNestingLevel = 0;
controlFlowNestingLevel = 0;
postEntryPointReturn = false;
return paramNodes;
}
//
// Handle seeing function call syntax in the grammar, which could be any of
// - .length() method
// - constructor
// - a call to a built-in function mapped to an operator
// - a call to a built-in function that will remain a function call (e.g., texturing)
// - user function
// - subroutine call (not implemented yet)
//
TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction* function, TIntermNode* arguments)
{
TIntermTyped* result = nullptr;
if (spvVersion.vulkan != 0 && spvVersion.vulkanRelaxed) {
// allow calls that are invalid in Vulkan Semantics to be invisibily
// remapped to equivalent valid functions
result = vkRelaxedRemapFunctionCall(loc, function, arguments);
if (result)
return result;
}
if (function->getBuiltInOp() == EOpArrayLength)
result = handleLengthMethod(loc, function, arguments);
else if (function->getBuiltInOp() != EOpNull) {
//
// Then this should be a constructor.
// Don't go through the symbol table for constructors.
// Their parameters will be verified algorithmically.
//
TType type(EbtVoid); // use this to get the type back
if (! constructorError(loc, arguments, *function, function->getBuiltInOp(), type)) {
//
// It's a constructor, of type 'type'.
//
result = addConstructor(loc, arguments, type);
if (result == nullptr)
error(loc, "cannot construct with these arguments", type.getCompleteString(intermediate.getEnhancedMsgs()).c_str(), "");
}
} else {
//
// Find it in the symbol table.
//
const TFunction* fnCandidate;
bool builtIn {false};
fnCandidate = findFunction(loc, *function, builtIn);
if (fnCandidate) {
// This is a declared function that might map to
// - a built-in operator,
// - a built-in function not mapped to an operator, or
// - a user function.
// Error check for a function requiring specific extensions present.
if (builtIn &&
(fnCandidate->getBuiltInOp() == EOpSubgroupQuadAll || fnCandidate->getBuiltInOp() == EOpSubgroupQuadAny))
requireExtensions(loc, 1, &E_GL_EXT_shader_quad_control, fnCandidate->getName().c_str());
if (builtIn && fnCandidate->getNumExtensions())
requireExtensions(loc, fnCandidate->getNumExtensions(), fnCandidate->getExtensions(), fnCandidate->getName().c_str());
if (builtIn && fnCandidate->getType().contains16BitFloat())
requireFloat16Arithmetic(loc, "built-in function", "float16 types can only be in uniform block or buffer storage");
if (builtIn && fnCandidate->getType().contains16BitInt())
requireInt16Arithmetic(loc, "built-in function", "(u)int16 types can only be in uniform block or buffer storage");
if (builtIn && fnCandidate->getType().contains8BitInt())
requireInt8Arithmetic(loc, "built-in function", "(u)int8 types can only be in uniform block or buffer storage");
if (builtIn && (fnCandidate->getBuiltInOp() == EOpTextureFetch || fnCandidate->getBuiltInOp() == EOpTextureQuerySize)) {
if ((*fnCandidate)[0].type->getSampler().isMultiSample() && version <= 140)
requireExtensions(loc, 1, &E_GL_ARB_texture_multisample, fnCandidate->getName().c_str());
}
if (arguments != nullptr) {
// Make sure qualifications work for these arguments.
TIntermAggregate* aggregate = arguments->getAsAggregate();
for (int i = 0; i < fnCandidate->getParamCount(); ++i) {
// At this early point there is a slight ambiguity between whether an aggregate 'arguments'
// is the single argument itself or its children are the arguments. Only one argument
// means take 'arguments' itself as the one argument.
TIntermNode* arg = fnCandidate->getParamCount() == 1 ? arguments : (aggregate ? aggregate->getSequence()[i] : arguments);
TQualifier& formalQualifier = (*fnCandidate)[i].type->getQualifier();
if (formalQualifier.isParamOutput()) {
if (lValueErrorCheck(arguments->getLoc(), "assign", arg->getAsTyped()))
error(arguments->getLoc(), "Non-L-value cannot be passed for 'out' or 'inout' parameters.", "out", "");
}
if (formalQualifier.isSpirvLiteral()) {
if (!arg->getAsTyped()->getQualifier().isFrontEndConstant()) {
error(arguments->getLoc(),
"Non front-end constant expressions cannot be passed for 'spirv_literal' parameters.",
"spirv_literal", "");
}
}
const TType& argType = arg->getAsTyped()->getType();
const TQualifier& argQualifier = argType.getQualifier();
bool containsBindlessSampler = intermediate.getBindlessMode() && argType.containsSampler();
if (argQualifier.isMemory() && !containsBindlessSampler && (argType.containsOpaque() || argType.isReference())) {
const char* message = "argument cannot drop memory qualifier when passed to formal parameter";
if (argQualifier.volatil && ! formalQualifier.volatil)
error(arguments->getLoc(), message, "volatile", "");
if (argQualifier.coherent && ! (formalQualifier.devicecoherent || formalQualifier.coherent))
error(arguments->getLoc(), message, "coherent", "");
if (argQualifier.devicecoherent && ! (formalQualifier.devicecoherent || formalQualifier.coherent))
error(arguments->getLoc(), message, "devicecoherent", "");
if (argQualifier.queuefamilycoherent && ! (formalQualifier.queuefamilycoherent || formalQualifier.devicecoherent || formalQualifier.coherent))
error(arguments->getLoc(), message, "queuefamilycoherent", "");
if (argQualifier.workgroupcoherent && ! (formalQualifier.workgroupcoherent || formalQualifier.queuefamilycoherent || formalQualifier.devicecoherent || formalQualifier.coherent))
error(arguments->getLoc(), message, "workgroupcoherent", "");
if (argQualifier.subgroupcoherent && ! (formalQualifier.subgroupcoherent || formalQualifier.workgroupcoherent || formalQualifier.queuefamilycoherent || formalQualifier.devicecoherent || formalQualifier.coherent))
error(arguments->getLoc(), message, "subgroupcoherent", "");
if (argQualifier.readonly && ! formalQualifier.readonly)
error(arguments->getLoc(), message, "readonly", "");
if (argQualifier.writeonly && ! formalQualifier.writeonly)
error(arguments->getLoc(), message, "writeonly", "");
// Don't check 'restrict', it is different than the rest:
// "...but only restrict can be taken away from a calling argument, by a formal parameter that
// lacks the restrict qualifier..."
}
if (!builtIn && argQualifier.getFormat() != formalQualifier.getFormat()) {
// we have mismatched formats, which should only be allowed if writeonly
// and at least one format is unknown
if (!formalQualifier.isWriteOnly() || (formalQualifier.getFormat() != ElfNone &&
argQualifier.getFormat() != ElfNone))
error(arguments->getLoc(), "image formats must match", "format", "");
}
if (builtIn && arg->getAsTyped()->getType().contains16BitFloat())
requireFloat16Arithmetic(arguments->getLoc(), "built-in function", "float16 types can only be in uniform block or buffer storage");
if (builtIn && arg->getAsTyped()->getType().contains16BitInt())
requireInt16Arithmetic(arguments->getLoc(), "built-in function", "(u)int16 types can only be in uniform block or buffer storage");
if (builtIn && arg->getAsTyped()->getType().contains8BitInt())
requireInt8Arithmetic(arguments->getLoc(), "built-in function", "(u)int8 types can only be in uniform block or buffer storage");
// TODO 4.5 functionality: A shader will fail to compile
// if the value passed to the memargument of an atomic memory function does not correspond to a buffer or
// shared variable. It is acceptable to pass an element of an array or a single component of a vector to the
// memargument of an atomic memory function, as long as the underlying array or vector is a buffer or
// shared variable.
}
// Convert 'in' arguments
addInputArgumentConversions(*fnCandidate, arguments); // arguments may be modified if it's just a single argument node
}
if (builtIn && fnCandidate->getBuiltInOp() != EOpNull) {
// A function call mapped to a built-in operation.
result = handleBuiltInFunctionCall(loc, arguments, *fnCandidate);
} else if (fnCandidate->getBuiltInOp() == EOpSpirvInst) {
// When SPIR-V instruction qualifier is specified, the function call is still mapped to a built-in operation.
result = handleBuiltInFunctionCall(loc, arguments, *fnCandidate);
} else {
// This is a function call not mapped to built-in operator.
// It could still be a built-in function, but only if PureOperatorBuiltins == false.
result = intermediate.setAggregateOperator(arguments, EOpFunctionCall, fnCandidate->getType(), loc);
TIntermAggregate* call = result->getAsAggregate();
call->setName(fnCandidate->getMangledName());
// this is how we know whether the given function is a built-in function or a user-defined function
// if builtIn == false, it's a userDefined -> could be an overloaded built-in function also
// if builtIn == true, it's definitely a built-in function with EOpNull
if (! builtIn) {
call->setUserDefined();
if (symbolTable.atGlobalLevel()) {
requireProfile(loc, ~EEsProfile, "calling user function from global scope");
intermediate.addToCallGraph(infoSink, "main(", fnCandidate->getMangledName());
} else
intermediate.addToCallGraph(infoSink, currentCaller, fnCandidate->getMangledName());
}
if (builtIn)
nonOpBuiltInCheck(loc, *fnCandidate, *call);
else
userFunctionCallCheck(loc, *call);
}
// Convert 'out' arguments. If it was a constant folded built-in, it won't be an aggregate anymore.
// Built-ins with a single argument aren't called with an aggregate, but they also don't have an output.
// Also, build the qualifier list for user function calls, which are always called with an aggregate.
if (result->getAsAggregate()) {
TQualifierList& qualifierList = result->getAsAggregate()->getQualifierList();
for (int i = 0; i < fnCandidate->getParamCount(); ++i) {
TStorageQualifier qual = (*fnCandidate)[i].type->getQualifier().storage;
qualifierList.push_back(qual);
}
result = addOutputArgumentConversions(*fnCandidate, *result->getAsAggregate());
}
if (result->getAsTyped()->getType().isCoopMat() &&
!result->getAsTyped()->getType().isParameterized()) {
assert(fnCandidate->getBuiltInOp() == EOpCooperativeMatrixMulAdd ||
fnCandidate->getBuiltInOp() == EOpCooperativeMatrixMulAddNV);
result->setType(result->getAsAggregate()->getSequence()[2]->getAsTyped()->getType());
}
}
}
// generic error recovery
// TODO: simplification: localize all the error recoveries that look like this, and taking type into account to reduce cascades
if (result == nullptr)
result = intermediate.addConstantUnion(0.0, EbtFloat, loc);
return result;
}
TIntermTyped* TParseContext::handleBuiltInFunctionCall(TSourceLoc loc, TIntermNode* arguments,
const TFunction& function)
{
checkLocation(loc, function.getBuiltInOp());
TIntermTyped *result = intermediate.addBuiltInFunctionCall(loc, function.getBuiltInOp(),
function.getParamCount() == 1,
arguments, function.getType());
if (result != nullptr && obeyPrecisionQualifiers())
computeBuiltinPrecisions(*result, function);
if (result == nullptr) {
if (arguments == nullptr)
error(loc, " wrong operand type", "Internal Error",
"built in unary operator function. Type: %s", "");
else
error(arguments->getLoc(), " wrong operand type", "Internal Error",
"built in unary operator function. Type: %s",
static_cast<TIntermTyped*>(arguments)->getCompleteString(intermediate.getEnhancedMsgs()).c_str());
} else if (result->getAsOperator())
builtInOpCheck(loc, function, *result->getAsOperator());
// Special handling for function call with SPIR-V instruction qualifier specified
if (function.getBuiltInOp() == EOpSpirvInst) {
if (auto agg = result->getAsAggregate()) {
// Propogate spirv_by_reference/spirv_literal from parameters to arguments
auto& sequence = agg->getSequence();
for (unsigned i = 0; i < sequence.size(); ++i) {
if (function[i].type->getQualifier().isSpirvByReference())
sequence[i]->getAsTyped()->getQualifier().setSpirvByReference();
if (function[i].type->getQualifier().isSpirvLiteral())
sequence[i]->getAsTyped()->getQualifier().setSpirvLiteral();
}
// Attach the function call to SPIR-V intruction
agg->setSpirvInstruction(function.getSpirvInstruction());
} else if (auto unaryNode = result->getAsUnaryNode()) {
// Propogate spirv_by_reference/spirv_literal from parameters to arguments
if (function[0].type->getQualifier().isSpirvByReference())
unaryNode->getOperand()->getQualifier().setSpirvByReference();
if (function[0].type->getQualifier().isSpirvLiteral())
unaryNode->getOperand()->getQualifier().setSpirvLiteral();
// Attach the function call to SPIR-V intruction
unaryNode->setSpirvInstruction(function.getSpirvInstruction());
} else
assert(0);
}
return result;
}
// "The operation of a built-in function can have a different precision
// qualification than the precision qualification of the resulting value.
// These two precision qualifications are established as follows.
//
// The precision qualification of the operation of a built-in function is
// based on the precision qualification of its input arguments and formal
// parameters: When a formal parameter specifies a precision qualifier,
// that is used, otherwise, the precision qualification of the calling
// argument is used. The highest precision of these will be the precision
// qualification of the operation of the built-in function. Generally,
// this is applied across all arguments to a built-in function, with the
// exceptions being:
// - bitfieldExtract and bitfieldInsert ignore the 'offset' and 'bits'
// arguments.
// - interpolateAt* functions only look at the 'interpolant' argument.
//
// The precision qualification of the result of a built-in function is
// determined in one of the following ways:
//
// - For the texture sampling, image load, and image store functions,
// the precision of the return type matches the precision of the
// sampler type
//
// Otherwise:
//
// - For prototypes that do not specify a resulting precision qualifier,
// the precision will be the same as the precision of the operation.
//
// - For prototypes that do specify a resulting precision qualifier,
// the specified precision qualifier is the precision qualification of
// the result."
//
void TParseContext::computeBuiltinPrecisions(TIntermTyped& node, const TFunction& function)
{
TPrecisionQualifier operationPrecision = EpqNone;
TPrecisionQualifier resultPrecision = EpqNone;
TIntermOperator* opNode = node.getAsOperator();
if (opNode == nullptr)
return;
if (TIntermUnary* unaryNode = node.getAsUnaryNode()) {
operationPrecision = std::max(function[0].type->getQualifier().precision,
unaryNode->getOperand()->getType().getQualifier().precision);
if (function.getType().getBasicType() != EbtBool)
resultPrecision = function.getType().getQualifier().precision == EpqNone ?
operationPrecision :
function.getType().getQualifier().precision;
} else if (TIntermAggregate* agg = node.getAsAggregate()) {
TIntermSequence& sequence = agg->getSequence();
unsigned int numArgs = (unsigned int)sequence.size();
switch (agg->getOp()) {
case EOpBitfieldExtract:
numArgs = 1;
break;
case EOpBitfieldInsert:
numArgs = 2;
break;
case EOpInterpolateAtCentroid:
case EOpInterpolateAtOffset:
case EOpInterpolateAtSample:
numArgs = 1;
break;
case EOpDebugPrintf:
numArgs = 0;
break;
default:
break;
}
// find the maximum precision from the arguments and parameters
for (unsigned int arg = 0; arg < numArgs; ++arg) {
operationPrecision = std::max(operationPrecision, sequence[arg]->getAsTyped()->getQualifier().precision);
operationPrecision = std::max(operationPrecision, function[arg].type->getQualifier().precision);
}
// compute the result precision
if (agg->isSampling() ||
agg->getOp() == EOpImageLoad || agg->getOp() == EOpImageStore ||
agg->getOp() == EOpImageLoadLod || agg->getOp() == EOpImageStoreLod)
resultPrecision = sequence[0]->getAsTyped()->getQualifier().precision;
else if (function.getType().getBasicType() != EbtBool)
resultPrecision = function.getType().getQualifier().precision == EpqNone ?
operationPrecision :
function.getType().getQualifier().precision;
}
// Propagate precision through this node and its children. That algorithm stops
// when a precision is found, so start by clearing this subroot precision
opNode->getQualifier().precision = EpqNone;
if (operationPrecision != EpqNone) {
opNode->propagatePrecision(operationPrecision);
opNode->setOperationPrecision(operationPrecision);
}
// Now, set the result precision, which might not match
opNode->getQualifier().precision = resultPrecision;
}
TIntermNode* TParseContext::handleReturnValue(const TSourceLoc& loc, TIntermTyped* value)
{
storage16BitAssignmentCheck(loc, value->getType(), "return");
functionReturnsValue = true;
TIntermBranch* branch = nullptr;
if (currentFunctionType->getBasicType() == EbtVoid) {
error(loc, "void function cannot return a value", "return", "");
branch = intermediate.addBranch(EOpReturn, loc);
} else if (*currentFunctionType != value->getType()) {
TIntermTyped* converted = intermediate.addConversion(EOpReturn, *currentFunctionType, value);
if (converted) {
if (*currentFunctionType != converted->getType())
error(loc, "cannot convert return value to function return type", "return", "");
if (version < 420)
warn(loc, "type conversion on return values was not explicitly allowed until version 420",
"return", "");
branch = intermediate.addBranch(EOpReturn, converted, loc);
} else {
error(loc, "type does not match, or is not convertible to, the function's return type", "return", "");
branch = intermediate.addBranch(EOpReturn, value, loc);
}
} else {
if (value->getType().isTexture() || value->getType().isImage()) {
if (spvVersion.spv != 0)
error(loc, "sampler or image cannot be used as return type when generating SPIR-V", "return", "");
else if (!extensionTurnedOn(E_GL_ARB_bindless_texture))
error(loc, "sampler or image can be used as return type only when the extension GL_ARB_bindless_texture enabled", "return", "");
}
branch = intermediate.addBranch(EOpReturn, value, loc);
}
branch->updatePrecision(currentFunctionType->getQualifier().precision);
return branch;
}
// See if the operation is being done in an illegal location.
void TParseContext::checkLocation(const TSourceLoc& loc, TOperator op)
{
switch (op) {
case EOpBarrier:
if (language == EShLangTessControl) {
if (controlFlowNestingLevel > 0)
error(loc, "tessellation control barrier() cannot be placed within flow control", "", "");
if (! inMain)
error(loc, "tessellation control barrier() must be in main()", "", "");
else if (postEntryPointReturn)
error(loc, "tessellation control barrier() cannot be placed after a return from main()", "", "");
}
break;
case EOpBeginInvocationInterlock:
if (language != EShLangFragment)
error(loc, "beginInvocationInterlockARB() must be in a fragment shader", "", "");
if (! inMain)
error(loc, "beginInvocationInterlockARB() must be in main()", "", "");
else if (postEntryPointReturn)
error(loc, "beginInvocationInterlockARB() cannot be placed after a return from main()", "", "");
if (controlFlowNestingLevel > 0)
error(loc, "beginInvocationInterlockARB() cannot be placed within flow control", "", "");
if (beginInvocationInterlockCount > 0)
error(loc, "beginInvocationInterlockARB() must only be called once", "", "");
if (endInvocationInterlockCount > 0)
error(loc, "beginInvocationInterlockARB() must be called before endInvocationInterlockARB()", "", "");
beginInvocationInterlockCount++;
// default to pixel_interlock_ordered
if (intermediate.getInterlockOrdering() == EioNone)
intermediate.setInterlockOrdering(EioPixelInterlockOrdered);
break;
case EOpEndInvocationInterlock:
if (language != EShLangFragment)
error(loc, "endInvocationInterlockARB() must be in a fragment shader", "", "");
if (! inMain)
error(loc, "endInvocationInterlockARB() must be in main()", "", "");
else if (postEntryPointReturn)
error(loc, "endInvocationInterlockARB() cannot be placed after a return from main()", "", "");
if (controlFlowNestingLevel > 0)
error(loc, "endInvocationInterlockARB() cannot be placed within flow control", "", "");
if (endInvocationInterlockCount > 0)
error(loc, "endInvocationInterlockARB() must only be called once", "", "");
if (beginInvocationInterlockCount == 0)
error(loc, "beginInvocationInterlockARB() must be called before endInvocationInterlockARB()", "", "");
endInvocationInterlockCount++;
break;
default:
break;
}
}
// Finish processing object.length(). This started earlier in handleDotDereference(), where
// the ".length" part was recognized and semantically checked, and finished here where the
// function syntax "()" is recognized.
//
// Return resulting tree node.
TIntermTyped* TParseContext::handleLengthMethod(const TSourceLoc& loc, TFunction* function, TIntermNode* intermNode)
{
int length = 0;
if (function->getParamCount() > 0)
error(loc, "method does not accept any arguments", function->getName().c_str(), "");
else {
const TType& type = intermNode->getAsTyped()->getType();
if (type.isArray()) {
if (type.isUnsizedArray()) {
if (intermNode->getAsSymbolNode() && isIoResizeArray(type)) {
// We could be between a layout declaration that gives a built-in io array implicit size and
// a user redeclaration of that array, meaning we have to substitute its implicit size here
// without actually redeclaring the array. (It is an error to use a member before the
// redeclaration, but not an error to use the array name itself.)
const TString& name = intermNode->getAsSymbolNode()->getName();
if (name == "gl_in" || name == "gl_out" || name == "gl_MeshVerticesNV" ||
name == "gl_MeshPrimitivesNV") {
length = getIoArrayImplicitSize(type.getQualifier());
}
} else if (const auto typed = intermNode->getAsTyped()) {
if (typed->getQualifier().builtIn == EbvSampleMask) {
requireProfile(loc, EEsProfile, "the array size of gl_SampleMask and gl_SampleMaskIn is ceil(gl_MaxSamples/32)");
length = (resources.maxSamples + 31) / 32;
}
}
if (length == 0) {
if (intermNode->getAsSymbolNode() && isIoResizeArray(type))
error(loc, "", function->getName().c_str(), "array must first be sized by a redeclaration or layout qualifier");
else if (isRuntimeLength(*intermNode->getAsTyped())) {
// Create a unary op and let the back end handle it
return intermediate.addBuiltInFunctionCall(loc, EOpArrayLength, true, intermNode, TType(EbtInt));
} else
error(loc, "", function->getName().c_str(), "array must be declared with a size before using this method");
}
} else if (type.getOuterArrayNode()) {
// If the array's outer size is specified by an intermediate node, it means the array's length
// was specified by a specialization constant. In such a case, we should return the node of the
// specialization constants to represent the length.
return type.getOuterArrayNode();
} else
length = type.getOuterArraySize();
} else if (type.isMatrix())
length = type.getMatrixCols();
else if (type.isVector())
length = type.getVectorSize();
else if (type.isCoopMat())
return intermediate.addBuiltInFunctionCall(loc, EOpArrayLength, true, intermNode, TType(EbtInt));
else {
// we should not get here, because earlier semantic checking should have prevented this path
error(loc, ".length()", "unexpected use of .length()", "");
}
}
if (length == 0)
length = 1;
return intermediate.addConstantUnion(length, loc);
}
//
// Add any needed implicit conversions for function-call arguments to input parameters.
//
void TParseContext::addInputArgumentConversions(const TFunction& function, TIntermNode*& arguments) const
{
TIntermAggregate* aggregate = arguments->getAsAggregate();
// Process each argument's conversion
for (int i = 0; i < function.getParamCount(); ++i) {
// At this early point there is a slight ambiguity between whether an aggregate 'arguments'
// is the single argument itself or its children are the arguments. Only one argument
// means take 'arguments' itself as the one argument.
TIntermTyped* arg = function.getParamCount() == 1 ? arguments->getAsTyped() : (aggregate ? aggregate->getSequence()[i]->getAsTyped() : arguments->getAsTyped());
if (*function[i].type != arg->getType()) {
if (function[i].type->getQualifier().isParamInput() &&
!function[i].type->isCoopMat()) {
// In-qualified arguments just need an extra node added above the argument to
// convert to the correct type.
arg = intermediate.addConversion(EOpFunctionCall, *function[i].type, arg);
if (arg) {
if (function.getParamCount() == 1)
arguments = arg;
else {
if (aggregate)
aggregate->getSequence()[i] = arg;
else
arguments = arg;
}
}
}
}
}
}
//
// Add any needed implicit output conversions for function-call arguments. This
// can require a new tree topology, complicated further by whether the function
// has a return value.
//
// Returns a node of a subtree that evaluates to the return value of the function.
//
TIntermTyped* TParseContext::addOutputArgumentConversions(const TFunction& function, TIntermAggregate& intermNode) const
{
TIntermSequence& arguments = intermNode.getSequence();
// Will there be any output conversions?
bool outputConversions = false;
for (int i = 0; i < function.getParamCount(); ++i) {
if (*function[i].type != arguments[i]->getAsTyped()->getType() && function[i].type->getQualifier().isParamOutput()) {
outputConversions = true;
break;
}
}
if (! outputConversions)
return &intermNode;
// Setup for the new tree, if needed:
//
// Output conversions need a different tree topology.
// Out-qualified arguments need a temporary of the correct type, with the call
// followed by an assignment of the temporary to the original argument:
// void: function(arg, ...) -> ( function(tempArg, ...), arg = tempArg, ...)
// ret = function(arg, ...) -> ret = (tempRet = function(tempArg, ...), arg = tempArg, ..., tempRet)
// Where the "tempArg" type needs no conversion as an argument, but will convert on assignment.
TIntermTyped* conversionTree = nullptr;
TVariable* tempRet = nullptr;
if (intermNode.getBasicType() != EbtVoid) {
// do the "tempRet = function(...), " bit from above
tempRet = makeInternalVariable("tempReturn", intermNode.getType());
TIntermSymbol* tempRetNode = intermediate.addSymbol(*tempRet, intermNode.getLoc());
conversionTree = intermediate.addAssign(EOpAssign, tempRetNode, &intermNode, intermNode.getLoc());
} else
conversionTree = &intermNode;
conversionTree = intermediate.makeAggregate(conversionTree);
// Process each argument's conversion
for (int i = 0; i < function.getParamCount(); ++i) {
if (*function[i].type != arguments[i]->getAsTyped()->getType()) {
if (function[i].type->getQualifier().isParamOutput()) {
// Out-qualified arguments need to use the topology set up above.
// do the " ...(tempArg, ...), arg = tempArg" bit from above
TType paramType;
paramType.shallowCopy(*function[i].type);
if (arguments[i]->getAsTyped()->getType().isParameterized() &&
!paramType.isParameterized()) {
paramType.shallowCopy(arguments[i]->getAsTyped()->getType());
paramType.copyTypeParameters(*arguments[i]->getAsTyped()->getType().getTypeParameters());
}
TVariable* tempArg = makeInternalVariable("tempArg", paramType);
tempArg->getWritableType().getQualifier().makeTemporary();
TIntermSymbol* tempArgNode = intermediate.addSymbol(*tempArg, intermNode.getLoc());
TIntermTyped* tempAssign = intermediate.addAssign(EOpAssign, arguments[i]->getAsTyped(), tempArgNode, arguments[i]->getLoc());
conversionTree = intermediate.growAggregate(conversionTree, tempAssign, arguments[i]->getLoc());
// replace the argument with another node for the same tempArg variable
arguments[i] = intermediate.addSymbol(*tempArg, intermNode.getLoc());
}
}
}
// Finalize the tree topology (see bigger comment above).
if (tempRet) {
// do the "..., tempRet" bit from above
TIntermSymbol* tempRetNode = intermediate.addSymbol(*tempRet, intermNode.getLoc());
conversionTree = intermediate.growAggregate(conversionTree, tempRetNode, intermNode.getLoc());
}
conversionTree = intermediate.setAggregateOperator(conversionTree, EOpComma, intermNode.getType(), intermNode.getLoc());
return conversionTree;
}
TIntermTyped* TParseContext::addAssign(const TSourceLoc& loc, TOperator op, TIntermTyped* left, TIntermTyped* right)
{
if ((op == EOpAddAssign || op == EOpSubAssign) && left->isReference())
requireExtensions(loc, 1, &E_GL_EXT_buffer_reference2, "+= and -= on a buffer reference");
if (op == EOpAssign && left->getBasicType() == EbtSampler && right->getBasicType() == EbtSampler)
requireExtensions(loc, 1, &E_GL_ARB_bindless_texture, "sampler assignment for bindless texture");
return intermediate.addAssign(op, left, right, loc);
}
void TParseContext::memorySemanticsCheck(const TSourceLoc& loc, const TFunction& fnCandidate, const TIntermOperator& callNode)
{
const TIntermSequence* argp = &callNode.getAsAggregate()->getSequence();
//const int gl_SemanticsRelaxed = 0x0;
const int gl_SemanticsAcquire = 0x2;
const int gl_SemanticsRelease = 0x4;
const int gl_SemanticsAcquireRelease = 0x8;
const int gl_SemanticsMakeAvailable = 0x2000;
const int gl_SemanticsMakeVisible = 0x4000;
const int gl_SemanticsVolatile = 0x8000;
//const int gl_StorageSemanticsNone = 0x0;
const int gl_StorageSemanticsBuffer = 0x40;
const int gl_StorageSemanticsShared = 0x100;
const int gl_StorageSemanticsImage = 0x800;
const int gl_StorageSemanticsOutput = 0x1000;
unsigned int semantics = 0, storageClassSemantics = 0;
unsigned int semantics2 = 0, storageClassSemantics2 = 0;
const TIntermTyped* arg0 = (*argp)[0]->getAsTyped();
const bool isMS = arg0->getBasicType() == EbtSampler && arg0->getType().getSampler().isMultiSample();
// Grab the semantics and storage class semantics from the operands, based on opcode
switch (callNode.getOp()) {
case EOpAtomicAdd:
case EOpAtomicSubtract:
case EOpAtomicMin:
case EOpAtomicMax:
case EOpAtomicAnd:
case EOpAtomicOr:
case EOpAtomicXor:
case EOpAtomicExchange:
case EOpAtomicStore:
storageClassSemantics = (*argp)[3]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics = (*argp)[4]->getAsConstantUnion()->getConstArray()[0].getIConst();
break;
case EOpAtomicLoad:
storageClassSemantics = (*argp)[2]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics = (*argp)[3]->getAsConstantUnion()->getConstArray()[0].getIConst();
break;
case EOpAtomicCompSwap:
storageClassSemantics = (*argp)[4]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics = (*argp)[5]->getAsConstantUnion()->getConstArray()[0].getIConst();
storageClassSemantics2 = (*argp)[6]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics2 = (*argp)[7]->getAsConstantUnion()->getConstArray()[0].getIConst();
break;
case EOpImageAtomicAdd:
case EOpImageAtomicMin:
case EOpImageAtomicMax:
case EOpImageAtomicAnd:
case EOpImageAtomicOr:
case EOpImageAtomicXor:
case EOpImageAtomicExchange:
case EOpImageAtomicStore:
storageClassSemantics = (*argp)[isMS ? 5 : 4]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics = (*argp)[isMS ? 6 : 5]->getAsConstantUnion()->getConstArray()[0].getIConst();
break;
case EOpImageAtomicLoad:
storageClassSemantics = (*argp)[isMS ? 4 : 3]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics = (*argp)[isMS ? 5 : 4]->getAsConstantUnion()->getConstArray()[0].getIConst();
break;
case EOpImageAtomicCompSwap:
storageClassSemantics = (*argp)[isMS ? 6 : 5]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics = (*argp)[isMS ? 7 : 6]->getAsConstantUnion()->getConstArray()[0].getIConst();
storageClassSemantics2 = (*argp)[isMS ? 8 : 7]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics2 = (*argp)[isMS ? 9 : 8]->getAsConstantUnion()->getConstArray()[0].getIConst();
break;
case EOpBarrier:
storageClassSemantics = (*argp)[2]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics = (*argp)[3]->getAsConstantUnion()->getConstArray()[0].getIConst();
break;
case EOpMemoryBarrier:
storageClassSemantics = (*argp)[1]->getAsConstantUnion()->getConstArray()[0].getIConst();
semantics = (*argp)[2]->getAsConstantUnion()->getConstArray()[0].getIConst();
break;
default:
break;
}
if ((semantics & gl_SemanticsAcquire) &&
(callNode.getOp() == EOpAtomicStore || callNode.getOp() == EOpImageAtomicStore)) {
error(loc, "gl_SemanticsAcquire must not be used with (image) atomic store",
fnCandidate.getName().c_str(), "");
}
if ((semantics & gl_SemanticsRelease) &&
(callNode.getOp() == EOpAtomicLoad || callNode.getOp() == EOpImageAtomicLoad)) {
error(loc, "gl_SemanticsRelease must not be used with (image) atomic load",
fnCandidate.getName().c_str(), "");
}
if ((semantics & gl_SemanticsAcquireRelease) &&
(callNode.getOp() == EOpAtomicStore || callNode.getOp() == EOpImageAtomicStore ||
callNode.getOp() == EOpAtomicLoad || callNode.getOp() == EOpImageAtomicLoad)) {
error(loc, "gl_SemanticsAcquireRelease must not be used with (image) atomic load/store",
fnCandidate.getName().c_str(), "");
}
if (((semantics | semantics2) & ~(gl_SemanticsAcquire |
gl_SemanticsRelease |
gl_SemanticsAcquireRelease |
gl_SemanticsMakeAvailable |
gl_SemanticsMakeVisible |
gl_SemanticsVolatile))) {
error(loc, "Invalid semantics value", fnCandidate.getName().c_str(), "");
}
if (((storageClassSemantics | storageClassSemantics2) & ~(gl_StorageSemanticsBuffer |
gl_StorageSemanticsShared |
gl_StorageSemanticsImage |
gl_StorageSemanticsOutput))) {
error(loc, "Invalid storage class semantics value", fnCandidate.getName().c_str(), "");
}
if (callNode.getOp() == EOpMemoryBarrier) {
if (!IsPow2(semantics & (gl_SemanticsAcquire | gl_SemanticsRelease | gl_SemanticsAcquireRelease))) {
error(loc, "Semantics must include exactly one of gl_SemanticsRelease, gl_SemanticsAcquire, or "
"gl_SemanticsAcquireRelease", fnCandidate.getName().c_str(), "");
}
} else {
if (semantics & (gl_SemanticsAcquire | gl_SemanticsRelease | gl_SemanticsAcquireRelease)) {
if (!IsPow2(semantics & (gl_SemanticsAcquire | gl_SemanticsRelease | gl_SemanticsAcquireRelease))) {
error(loc, "Semantics must not include multiple of gl_SemanticsRelease, gl_SemanticsAcquire, or "
"gl_SemanticsAcquireRelease", fnCandidate.getName().c_str(), "");
}
}
if (semantics2 & (gl_SemanticsAcquire | gl_SemanticsRelease | gl_SemanticsAcquireRelease)) {
if (!IsPow2(semantics2 & (gl_SemanticsAcquire | gl_SemanticsRelease | gl_SemanticsAcquireRelease))) {
error(loc, "semUnequal must not include multiple of gl_SemanticsRelease, gl_SemanticsAcquire, or "
"gl_SemanticsAcquireRelease", fnCandidate.getName().c_str(), "");
}
}
}
if (callNode.getOp() == EOpMemoryBarrier) {
if (storageClassSemantics == 0) {
error(loc, "Storage class semantics must not be zero", fnCandidate.getName().c_str(), "");
}
}
if (callNode.getOp() == EOpBarrier && semantics != 0 && storageClassSemantics == 0) {
error(loc, "Storage class semantics must not be zero", fnCandidate.getName().c_str(), "");
}
if ((callNode.getOp() == EOpAtomicCompSwap || callNode.getOp() == EOpImageAtomicCompSwap) &&
(semantics2 & (gl_SemanticsRelease | gl_SemanticsAcquireRelease))) {
error(loc, "semUnequal must not be gl_SemanticsRelease or gl_SemanticsAcquireRelease",
fnCandidate.getName().c_str(), "");
}
if ((semantics & gl_SemanticsMakeAvailable) &&
!(semantics & (gl_SemanticsRelease | gl_SemanticsAcquireRelease))) {
error(loc, "gl_SemanticsMakeAvailable requires gl_SemanticsRelease or gl_SemanticsAcquireRelease",
fnCandidate.getName().c_str(), "");
}
if ((semantics & gl_SemanticsMakeVisible) &&
!(semantics & (gl_SemanticsAcquire | gl_SemanticsAcquireRelease))) {
error(loc, "gl_SemanticsMakeVisible requires gl_SemanticsAcquire or gl_SemanticsAcquireRelease",
fnCandidate.getName().c_str(), "");
}
if ((semantics & gl_SemanticsVolatile) &&
(callNode.getOp() == EOpMemoryBarrier || callNode.getOp() == EOpBarrier)) {
error(loc, "gl_SemanticsVolatile must not be used with memoryBarrier or controlBarrier",
fnCandidate.getName().c_str(), "");
}
if ((callNode.getOp() == EOpAtomicCompSwap || callNode.getOp() == EOpImageAtomicCompSwap) &&
((semantics ^ semantics2) & gl_SemanticsVolatile)) {
error(loc, "semEqual and semUnequal must either both include gl_SemanticsVolatile or neither",
fnCandidate.getName().c_str(), "");
}
}
//
// Do additional checking of built-in function calls that is not caught
// by normal semantic checks on argument type, extension tagging, etc.
//
// Assumes there has been a semantically correct match to a built-in function prototype.
//
void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCandidate, TIntermOperator& callNode)
{
// Set up convenience accessors to the argument(s). There is almost always
// multiple arguments for the cases below, but when there might be one,
// check the unaryArg first.
const TIntermSequence* argp = nullptr; // confusing to use [] syntax on a pointer, so this is to help get a reference
const TIntermTyped* unaryArg = nullptr;
const TIntermTyped* arg0 = nullptr;
if (callNode.getAsAggregate()) {
argp = &callNode.getAsAggregate()->getSequence();
if (argp->size() > 0)
arg0 = (*argp)[0]->getAsTyped();
} else {
assert(callNode.getAsUnaryNode());
unaryArg = callNode.getAsUnaryNode()->getOperand();
arg0 = unaryArg;
}
TString featureString;
const char* feature = nullptr;
switch (callNode.getOp()) {
case EOpTextureGather:
case EOpTextureGatherOffset:
case EOpTextureGatherOffsets:
{
// Figure out which variants are allowed by what extensions,
// and what arguments must be constant for which situations.
featureString = fnCandidate.getName();
featureString += "(...)";
feature = featureString.c_str();
profileRequires(loc, EEsProfile, 310, nullptr, feature);
int compArg = -1; // track which argument, if any, is the constant component argument
switch (callNode.getOp()) {
case EOpTextureGather:
// More than two arguments needs gpu_shader5, and rectangular or shadow needs gpu_shader5,
// otherwise, need GL_ARB_texture_gather.
if (fnCandidate.getParamCount() > 2 || fnCandidate[0].type->getSampler().dim == EsdRect || fnCandidate[0].type->getSampler().shadow) {
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_gpu_shader5, feature);
if (! fnCandidate[0].type->getSampler().shadow)
compArg = 2;
} else
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_texture_gather, feature);
break;
case EOpTextureGatherOffset:
// GL_ARB_texture_gather is good enough for 2D non-shadow textures with no component argument
if (fnCandidate[0].type->getSampler().dim == Esd2D && ! fnCandidate[0].type->getSampler().shadow && fnCandidate.getParamCount() == 3)
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_texture_gather, feature);
else
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_gpu_shader5, feature);
if (! (*argp)[fnCandidate[0].type->getSampler().shadow ? 3 : 2]->getAsConstantUnion())
profileRequires(loc, EEsProfile, 320, Num_AEP_gpu_shader5, AEP_gpu_shader5,
"non-constant offset argument");
if (! fnCandidate[0].type->getSampler().shadow)
compArg = 3;
break;
case EOpTextureGatherOffsets:
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_gpu_shader5, feature);
if (! fnCandidate[0].type->getSampler().shadow)
compArg = 3;
// check for constant offsets
if (! (*argp)[fnCandidate[0].type->getSampler().shadow ? 3 : 2]->getAsConstantUnion())
error(loc, "must be a compile-time constant:", feature, "offsets argument");
break;
default:
break;
}
if (compArg > 0 && compArg < fnCandidate.getParamCount()) {
if ((*argp)[compArg]->getAsConstantUnion()) {
int value = (*argp)[compArg]->getAsConstantUnion()->getConstArray()[0].getIConst();
if (value < 0 || value > 3)
error(loc, "must be 0, 1, 2, or 3:", feature, "component argument");
} else
error(loc, "must be a compile-time constant:", feature, "component argument");
}
bool bias = false;
if (callNode.getOp() == EOpTextureGather)
bias = fnCandidate.getParamCount() > 3;
else if (callNode.getOp() == EOpTextureGatherOffset ||
callNode.getOp() == EOpTextureGatherOffsets)
bias = fnCandidate.getParamCount() > 4;
if (bias) {
featureString = fnCandidate.getName();
featureString += "with bias argument";
feature = featureString.c_str();
profileRequires(loc, ~EEsProfile, 450, nullptr, feature);
requireExtensions(loc, 1, &E_GL_AMD_texture_gather_bias_lod, feature);
}
break;
}
case EOpTexture:
case EOpTextureLod:
{
if ((fnCandidate.getParamCount() > 2) && ((*argp)[1]->getAsTyped()->getType().getBasicType() == EbtFloat) &&
((*argp)[1]->getAsTyped()->getType().getVectorSize() == 4) && fnCandidate[0].type->getSampler().shadow) {
featureString = fnCandidate.getName();
if (callNode.getOp() == EOpTexture)
featureString += "(..., float bias)";
else
featureString += "(..., float lod)";
feature = featureString.c_str();
if ((fnCandidate[0].type->getSampler().dim == Esd2D && fnCandidate[0].type->getSampler().arrayed) || //2D Array Shadow
(fnCandidate[0].type->getSampler().dim == EsdCube && fnCandidate[0].type->getSampler().arrayed && fnCandidate.getParamCount() > 3) || // Cube Array Shadow
(fnCandidate[0].type->getSampler().dim == EsdCube && callNode.getOp() == EOpTextureLod)) { // Cube Shadow
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
if (isEsProfile()) {
if (version < 320 &&
!extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
error(loc, "GL_EXT_texture_shadow_lod not supported for this ES version", feature, "");
else
profileRequires(loc, EEsProfile, 320, nullptr, feature);
} else { // Desktop
profileRequires(loc, ~EEsProfile, 130, nullptr, feature);
}
}
}
break;
}
case EOpSparseTextureGather:
case EOpSparseTextureGatherOffset:
case EOpSparseTextureGatherOffsets:
{
bool bias = false;
if (callNode.getOp() == EOpSparseTextureGather)
bias = fnCandidate.getParamCount() > 4;
else if (callNode.getOp() == EOpSparseTextureGatherOffset ||
callNode.getOp() == EOpSparseTextureGatherOffsets)
bias = fnCandidate.getParamCount() > 5;
if (bias) {
featureString = fnCandidate.getName();
featureString += "with bias argument";
feature = featureString.c_str();
profileRequires(loc, ~EEsProfile, 450, nullptr, feature);
requireExtensions(loc, 1, &E_GL_AMD_texture_gather_bias_lod, feature);
}
// As per GL_ARB_sparse_texture2 extension "Offsets" parameter must be constant integral expression
// for sparseTextureGatherOffsetsARB just as textureGatherOffsets
if (callNode.getOp() == EOpSparseTextureGatherOffsets) {
int offsetsArg = arg0->getType().getSampler().shadow ? 3 : 2;
if (!(*argp)[offsetsArg]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "offsets", "");
}
break;
}
case EOpSparseTextureGatherLod:
case EOpSparseTextureGatherLodOffset:
case EOpSparseTextureGatherLodOffsets:
{
requireExtensions(loc, 1, &E_GL_ARB_sparse_texture2, fnCandidate.getName().c_str());
break;
}
case EOpSwizzleInvocations:
{
if (! (*argp)[1]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "offset", "");
else {
unsigned offset[4] = {};
offset[0] = (*argp)[1]->getAsConstantUnion()->getConstArray()[0].getUConst();
offset[1] = (*argp)[1]->getAsConstantUnion()->getConstArray()[1].getUConst();
offset[2] = (*argp)[1]->getAsConstantUnion()->getConstArray()[2].getUConst();
offset[3] = (*argp)[1]->getAsConstantUnion()->getConstArray()[3].getUConst();
if (offset[0] > 3 || offset[1] > 3 || offset[2] > 3 || offset[3] > 3)
error(loc, "components must be in the range [0, 3]", "offset", "");
}
break;
}
case EOpSwizzleInvocationsMasked:
{
if (! (*argp)[1]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "mask", "");
else {
unsigned mask[3] = {};
mask[0] = (*argp)[1]->getAsConstantUnion()->getConstArray()[0].getUConst();
mask[1] = (*argp)[1]->getAsConstantUnion()->getConstArray()[1].getUConst();
mask[2] = (*argp)[1]->getAsConstantUnion()->getConstArray()[2].getUConst();
if (mask[0] > 31 || mask[1] > 31 || mask[2] > 31)
error(loc, "components must be in the range [0, 31]", "mask", "");
}
break;
}
case EOpTextureOffset:
case EOpTextureFetchOffset:
case EOpTextureProjOffset:
case EOpTextureLodOffset:
case EOpTextureProjLodOffset:
case EOpTextureGradOffset:
case EOpTextureProjGradOffset:
{
// Handle texture-offset limits checking
// Pick which argument has to hold constant offsets
int arg = -1;
switch (callNode.getOp()) {
case EOpTextureOffset: arg = 2; break;
case EOpTextureFetchOffset: arg = (arg0->getType().getSampler().isRect()) ? 2 : 3; break;
case EOpTextureProjOffset: arg = 2; break;
case EOpTextureLodOffset: arg = 3; break;
case EOpTextureProjLodOffset: arg = 3; break;
case EOpTextureGradOffset: arg = 4; break;
case EOpTextureProjGradOffset: arg = 4; break;
default:
assert(0);
break;
}
if (arg > 0) {
bool f16ShadowCompare = (*argp)[1]->getAsTyped()->getBasicType() == EbtFloat16 &&
arg0->getType().getSampler().shadow;
if (f16ShadowCompare)
++arg;
if (! (*argp)[arg]->getAsTyped()->getQualifier().isConstant())
error(loc, "argument must be compile-time constant", "texel offset", "");
else if ((*argp)[arg]->getAsConstantUnion()) {
const TType& type = (*argp)[arg]->getAsTyped()->getType();
for (int c = 0; c < type.getVectorSize(); ++c) {
int offset = (*argp)[arg]->getAsConstantUnion()->getConstArray()[c].getIConst();
if (offset > resources.maxProgramTexelOffset || offset < resources.minProgramTexelOffset)
error(loc, "value is out of range:", "texel offset",
"[gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]");
}
}
if (callNode.getOp() == EOpTextureOffset) {
TSampler s = arg0->getType().getSampler();
if (s.is2D() && s.isArrayed() && s.isShadow()) {
if (
((*argp)[1]->getAsTyped()->getType().getBasicType() == EbtFloat) &&
((*argp)[1]->getAsTyped()->getType().getVectorSize() == 4) &&
(fnCandidate.getParamCount() == 4)) {
featureString = fnCandidate.getName() + " for sampler2DArrayShadow";
feature = featureString.c_str();
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
profileRequires(loc, EEsProfile, 300, nullptr, feature);
profileRequires(loc, ~EEsProfile, 130, nullptr, feature);
}
else if (isEsProfile())
error(loc, "TextureOffset does not support sampler2DArrayShadow : ", "sampler", "ES Profile");
else if (version <= 420)
error(loc, "TextureOffset does not support sampler2DArrayShadow : ", "sampler", "version <= 420");
}
}
if (callNode.getOp() == EOpTextureLodOffset) {
TSampler s = arg0->getType().getSampler();
if (s.is2D() && s.isArrayed() && s.isShadow() &&
((*argp)[1]->getAsTyped()->getType().getBasicType() == EbtFloat) &&
((*argp)[1]->getAsTyped()->getType().getVectorSize() == 4) &&
(fnCandidate.getParamCount() == 4)) {
featureString = fnCandidate.getName() + " for sampler2DArrayShadow";
feature = featureString.c_str();
profileRequires(loc, EEsProfile, 300, nullptr, feature);
profileRequires(loc, ~EEsProfile, 130, nullptr, feature);
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
}
}
}
break;
}
case EOpTraceNV:
if (!(*argp)[10]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "payload number", "a");
break;
case EOpTraceRayMotionNV:
if (!(*argp)[11]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "payload number", "a");
break;
case EOpTraceKHR:
if (!(*argp)[10]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "payload number", "a");
else {
unsigned int location = (*argp)[10]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(0, location) < 0)
error(loc, "with layout(location =", "no rayPayloadEXT/rayPayloadInEXT declared", "%d)", location);
}
break;
case EOpExecuteCallableNV:
if (!(*argp)[1]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "callable data number", "");
break;
case EOpExecuteCallableKHR:
if (!(*argp)[1]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "callable data number", "");
else {
unsigned int location = (*argp)[1]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(1, location) < 0)
error(loc, "with layout(location =", "no callableDataEXT/callableDataInEXT declared", "%d)", location);
}
break;
case EOpHitObjectTraceRayNV:
if (!(*argp)[11]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "payload number", "");
else {
unsigned int location = (*argp)[11]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(0, location) < 0)
error(loc, "with layout(location =", "no rayPayloadEXT/rayPayloadInEXT declared", "%d)", location);
}
break;
case EOpHitObjectTraceRayMotionNV:
if (!(*argp)[12]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "payload number", "");
else {
unsigned int location = (*argp)[12]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(0, location) < 0)
error(loc, "with layout(location =", "no rayPayloadEXT/rayPayloadInEXT declared", "%d)", location);
}
break;
case EOpHitObjectExecuteShaderNV:
if (!(*argp)[1]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "payload number", "");
else {
unsigned int location = (*argp)[1]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(0, location) < 0)
error(loc, "with layout(location =", "no rayPayloadEXT/rayPayloadInEXT declared", "%d)", location);
}
break;
case EOpHitObjectRecordHitNV:
if (!(*argp)[12]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "hitobjectattribute number", "");
else {
unsigned int location = (*argp)[12]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(2, location) < 0)
error(loc, "with layout(location =", "no hitObjectAttributeNV declared", "%d)", location);
}
break;
case EOpHitObjectRecordHitMotionNV:
if (!(*argp)[13]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "hitobjectattribute number", "");
else {
unsigned int location = (*argp)[13]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(2, location) < 0)
error(loc, "with layout(location =", "no hitObjectAttributeNV declared", "%d)", location);
}
break;
case EOpHitObjectRecordHitWithIndexNV:
if (!(*argp)[11]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "hitobjectattribute number", "");
else {
unsigned int location = (*argp)[11]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(2, location) < 0)
error(loc, "with layout(location =", "no hitObjectAttributeNV declared", "%d)", location);
}
break;
case EOpHitObjectRecordHitWithIndexMotionNV:
if (!(*argp)[12]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "hitobjectattribute number", "");
else {
unsigned int location = (*argp)[12]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(2, location) < 0)
error(loc, "with layout(location =", "no hitObjectAttributeNV declared", "%d)", location);
}
break;
case EOpHitObjectGetAttributesNV:
if (!(*argp)[1]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "hitobjectattribute number", "");
else {
unsigned int location = (*argp)[1]->getAsConstantUnion()->getAsConstantUnion()->getConstArray()[0].getUConst();
if (!extensionTurnedOn(E_GL_EXT_spirv_intrinsics) && intermediate.checkLocationRT(2, location) < 0)
error(loc, "with layout(location =", "no hitObjectAttributeNV declared", "%d)", location);
}
break;
case EOpRayQueryGetIntersectionType:
case EOpRayQueryGetIntersectionT:
case EOpRayQueryGetIntersectionInstanceCustomIndex:
case EOpRayQueryGetIntersectionInstanceId:
case EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset:
case EOpRayQueryGetIntersectionGeometryIndex:
case EOpRayQueryGetIntersectionPrimitiveIndex:
case EOpRayQueryGetIntersectionBarycentrics:
case EOpRayQueryGetIntersectionFrontFace:
case EOpRayQueryGetIntersectionObjectRayDirection:
case EOpRayQueryGetIntersectionObjectRayOrigin:
case EOpRayQueryGetIntersectionObjectToWorld:
case EOpRayQueryGetIntersectionWorldToObject:
case EOpRayQueryGetIntersectionTriangleVertexPositionsEXT:
if (!(*argp)[1]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "committed", "");
break;
case EOpTextureQuerySamples:
case EOpImageQuerySamples:
// GL_ARB_shader_texture_image_samples
profileRequires(loc, ~EEsProfile, 450, E_GL_ARB_shader_texture_image_samples, "textureSamples and imageSamples");
break;
case EOpImageAtomicAdd:
case EOpImageAtomicMin:
case EOpImageAtomicMax:
case EOpImageAtomicAnd:
case EOpImageAtomicOr:
case EOpImageAtomicXor:
case EOpImageAtomicExchange:
case EOpImageAtomicCompSwap:
case EOpImageAtomicLoad:
case EOpImageAtomicStore:
{
// Make sure the image types have the correct layout() format and correct argument types
const TType& imageType = arg0->getType();
if (imageType.getSampler().type == EbtInt || imageType.getSampler().type == EbtUint ||
imageType.getSampler().type == EbtInt64 || imageType.getSampler().type == EbtUint64) {
if (imageType.getQualifier().getFormat() != ElfR32i && imageType.getQualifier().getFormat() != ElfR32ui &&
imageType.getQualifier().getFormat() != ElfR64i && imageType.getQualifier().getFormat() != ElfR64ui)
error(loc, "only supported on image with format r32i or r32ui", fnCandidate.getName().c_str(), "");
if (callNode.getType().getBasicType() == EbtInt64 && imageType.getQualifier().getFormat() != ElfR64i)
error(loc, "only supported on image with format r64i", fnCandidate.getName().c_str(), "");
else if (callNode.getType().getBasicType() == EbtUint64 && imageType.getQualifier().getFormat() != ElfR64ui)
error(loc, "only supported on image with format r64ui", fnCandidate.getName().c_str(), "");
} else if(callNode.getType().getBasicType() == EbtFloat16 &&
((callNode.getType().getVectorSize() == 2 && arg0->getType().getQualifier().getFormat() == ElfRg16f) ||
(callNode.getType().getVectorSize() == 4 && arg0->getType().getQualifier().getFormat() == ElfRgba16f))) {
if (StartsWith(fnCandidate.getName(), "imageAtomicAdd") ||
StartsWith(fnCandidate.getName(), "imageAtomicExchange") ||
StartsWith(fnCandidate.getName(), "imageAtomicMin") ||
StartsWith(fnCandidate.getName(), "imageAtomicMax")) {
requireExtensions(loc, 1, &E_GL_NV_shader_atomic_fp16_vector, fnCandidate.getName().c_str());
} else {
error(loc, "f16vec2/4 operation not supported on: ", fnCandidate.getName().c_str(), "");
}
} else if (imageType.getSampler().type == EbtFloat) {
if (StartsWith(fnCandidate.getName(), "imageAtomicExchange")) {
// imageAtomicExchange doesn't require an extension
} else if (StartsWith(fnCandidate.getName(), "imageAtomicAdd") ||
StartsWith(fnCandidate.getName(), "imageAtomicLoad") ||
StartsWith(fnCandidate.getName(), "imageAtomicStore")) {
requireExtensions(loc, 1, &E_GL_EXT_shader_atomic_float, fnCandidate.getName().c_str());
} else if (StartsWith(fnCandidate.getName(), "imageAtomicMin") ||
StartsWith(fnCandidate.getName(), "imageAtomicMax")) {
requireExtensions(loc, 1, &E_GL_EXT_shader_atomic_float2, fnCandidate.getName().c_str());
} else {
error(loc, "only supported on integer images", fnCandidate.getName().c_str(), "");
}
if (imageType.getQualifier().getFormat() != ElfR32f && isEsProfile())
error(loc, "only supported on image with format r32f", fnCandidate.getName().c_str(), "");
} else {
error(loc, "not supported on this image type", fnCandidate.getName().c_str(), "");
}
const size_t maxArgs = imageType.getSampler().isMultiSample() ? 5 : 4;
if (argp->size() > maxArgs) {
requireExtensions(loc, 1, &E_GL_KHR_memory_scope_semantics, fnCandidate.getName().c_str());
memorySemanticsCheck(loc, fnCandidate, callNode);
}
break;
}
case EOpAtomicAdd:
case EOpAtomicSubtract:
case EOpAtomicMin:
case EOpAtomicMax:
case EOpAtomicAnd:
case EOpAtomicOr:
case EOpAtomicXor:
case EOpAtomicExchange:
case EOpAtomicCompSwap:
case EOpAtomicLoad:
case EOpAtomicStore:
{
if (argp->size() > 3) {
requireExtensions(loc, 1, &E_GL_KHR_memory_scope_semantics, fnCandidate.getName().c_str());
memorySemanticsCheck(loc, fnCandidate, callNode);
if ((callNode.getOp() == EOpAtomicAdd || callNode.getOp() == EOpAtomicExchange ||
callNode.getOp() == EOpAtomicLoad || callNode.getOp() == EOpAtomicStore) &&
(arg0->getType().getBasicType() == EbtFloat ||
arg0->getType().getBasicType() == EbtDouble)) {
requireExtensions(loc, 1, &E_GL_EXT_shader_atomic_float, fnCandidate.getName().c_str());
} else if ((callNode.getOp() == EOpAtomicAdd || callNode.getOp() == EOpAtomicExchange ||
callNode.getOp() == EOpAtomicLoad || callNode.getOp() == EOpAtomicStore ||
callNode.getOp() == EOpAtomicMin || callNode.getOp() == EOpAtomicMax) &&
arg0->getType().isFloatingDomain()) {
requireExtensions(loc, 1, &E_GL_EXT_shader_atomic_float2, fnCandidate.getName().c_str());
}
} else if (arg0->getType().getBasicType() == EbtInt64 || arg0->getType().getBasicType() == EbtUint64) {
const char* const extensions[2] = { E_GL_NV_shader_atomic_int64,
E_GL_EXT_shader_atomic_int64 };
requireExtensions(loc, 2, extensions, fnCandidate.getName().c_str());
} else if ((callNode.getOp() == EOpAtomicAdd || callNode.getOp() == EOpAtomicExchange ||
callNode.getOp() == EOpAtomicMin || callNode.getOp() == EOpAtomicMax) &&
arg0->getType().getBasicType() == EbtFloat16 &&
(arg0->getType().getVectorSize() == 2 || arg0->getType().getVectorSize() == 4 )) {
requireExtensions(loc, 1, &E_GL_NV_shader_atomic_fp16_vector, fnCandidate.getName().c_str());
} else if ((callNode.getOp() == EOpAtomicAdd || callNode.getOp() == EOpAtomicExchange) &&
(arg0->getType().getBasicType() == EbtFloat ||
arg0->getType().getBasicType() == EbtDouble)) {
requireExtensions(loc, 1, &E_GL_EXT_shader_atomic_float, fnCandidate.getName().c_str());
} else if ((callNode.getOp() == EOpAtomicAdd || callNode.getOp() == EOpAtomicExchange ||
callNode.getOp() == EOpAtomicLoad || callNode.getOp() == EOpAtomicStore ||
callNode.getOp() == EOpAtomicMin || callNode.getOp() == EOpAtomicMax) &&
arg0->getType().isFloatingDomain()) {
requireExtensions(loc, 1, &E_GL_EXT_shader_atomic_float2, fnCandidate.getName().c_str());
}
const TIntermTyped* base = TIntermediate::traverseLValueBase(arg0, true, true);
const char* errMsg = "Only l-values corresponding to shader block storage or shared variables can be used with "
"atomic memory functions.";
if (base) {
const TType* refType = (base->getType().isReference()) ? base->getType().getReferentType() : nullptr;
const TQualifier& qualifier =
(refType != nullptr) ? refType->getQualifier() : base->getType().getQualifier();
if (qualifier.storage != EvqShared && qualifier.storage != EvqBuffer &&
qualifier.storage != EvqtaskPayloadSharedEXT)
error(loc, errMsg, fnCandidate.getName().c_str(), "");
} else {
error(loc, errMsg, fnCandidate.getName().c_str(), "");
}
break;
}
case EOpInterpolateAtCentroid:
case EOpInterpolateAtSample:
case EOpInterpolateAtOffset:
case EOpInterpolateAtVertex: {
if (arg0->getType().getQualifier().storage != EvqVaryingIn) {
// Traverse down the left branch of arg0 to ensure this argument is a valid interpolant.
//
// For desktop GL >4.3 we effectively only need to ensure that arg0 represents an l-value from an
// input declaration.
//
// For desktop GL <= 4.3 and ES, we must also ensure that swizzling is not used
//
// For ES, we must also ensure that a field selection operator (i.e., '.') is not used on a named
// struct.
const bool esProfile = isEsProfile();
const bool swizzleOkay = !esProfile && (version >= 440);
std::string interpolantErrorMsg = "first argument must be an interpolant, or interpolant-array element";
bool isValid = true; // Assume that the interpolant is valid until we find a condition making it invalid
bool isIn = false; // Checks whether or not the interpolant is a shader input
bool structAccessOp = false; // Whether or not the previous node in the chain is a struct accessor
TIntermediate::traverseLValueBase(
arg0, swizzleOkay, false,
[&isValid, &isIn, &interpolantErrorMsg, esProfile, &structAccessOp](const TIntermNode& n) -> bool {
auto* type = n.getAsTyped();
if (type) {
if (type->getType().getQualifier().storage == EvqVaryingIn) {
isIn = true;
}
// If a field accessor was used, it can only be used to access a field with an input block, not a struct.
if (structAccessOp && (type->getType().getBasicType() != EbtBlock)) {
interpolantErrorMsg +=
". Using the field of a named struct as an interpolant argument is not "
"allowed (ES-only).";
isValid = false;
}
}
// ES has different requirements for interpolants than GL
if (esProfile) {
// Swizzling will be taken care of by the 'swizzleOkay' argument passsed to traverseLValueBase,
// so we only ned to check whether or not a field accessor has been used with a named struct.
auto* binary = n.getAsBinaryNode();
if (binary && (binary->getOp() == EOpIndexDirectStruct)) {
structAccessOp = true;
}
}
// Don't continue traversing if we know we have an invalid interpolant at this point.
return isValid;
});
if (!isIn || !isValid) {
error(loc, interpolantErrorMsg.c_str(), fnCandidate.getName().c_str(), "");
}
}
if (callNode.getOp() == EOpInterpolateAtVertex) {
if (!arg0->getType().getQualifier().isExplicitInterpolation())
error(loc, "argument must be qualified as __explicitInterpAMD in", "interpolant", "");
else {
if (! (*argp)[1]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "vertex index", "");
else {
unsigned vertexIdx = (*argp)[1]->getAsConstantUnion()->getConstArray()[0].getUConst();
if (vertexIdx > 2)
error(loc, "must be in the range [0, 2]", "vertex index", "");
}
}
}
} break;
case EOpEmitStreamVertex:
case EOpEndStreamPrimitive:
if (version == 150)
requireExtensions(loc, 1, &E_GL_ARB_gpu_shader5, "if the version is 150 , the EmitStreamVertex and EndStreamPrimitive only support at extension GL_ARB_gpu_shader5");
intermediate.setMultiStream();
break;
case EOpSubgroupClusteredAdd:
case EOpSubgroupClusteredMul:
case EOpSubgroupClusteredMin:
case EOpSubgroupClusteredMax:
case EOpSubgroupClusteredAnd:
case EOpSubgroupClusteredOr:
case EOpSubgroupClusteredXor:
// The <clusterSize> as used in the subgroupClustered<op>() operations must be:
// - An integral constant expression.
// - At least 1.
// - A power of 2.
if ((*argp)[1]->getAsConstantUnion() == nullptr)
error(loc, "argument must be compile-time constant", "cluster size", "");
else {
int size = (*argp)[1]->getAsConstantUnion()->getConstArray()[0].getIConst();
if (size < 1)
error(loc, "argument must be at least 1", "cluster size", "");
else if (!IsPow2(size))
error(loc, "argument must be a power of 2", "cluster size", "");
}
break;
case EOpSubgroupBroadcast:
case EOpSubgroupQuadBroadcast:
if (spvVersion.spv < EShTargetSpv_1_5) {
// <id> must be an integral constant expression.
if ((*argp)[1]->getAsConstantUnion() == nullptr)
error(loc, "argument must be compile-time constant", "id", "");
}
break;
case EOpBarrier:
case EOpMemoryBarrier:
if (argp->size() > 0) {
requireExtensions(loc, 1, &E_GL_KHR_memory_scope_semantics, fnCandidate.getName().c_str());
memorySemanticsCheck(loc, fnCandidate, callNode);
}
break;
case EOpMix:
if (profile == EEsProfile && version < 310) {
// Look for specific signatures
if ((*argp)[0]->getAsTyped()->getBasicType() != EbtFloat &&
(*argp)[1]->getAsTyped()->getBasicType() != EbtFloat &&
(*argp)[2]->getAsTyped()->getBasicType() == EbtBool) {
requireExtensions(loc, 1, &E_GL_EXT_shader_integer_mix, "specific signature of builtin mix");
}
}
if (profile != EEsProfile && version < 450) {
if ((*argp)[0]->getAsTyped()->getBasicType() != EbtFloat &&
(*argp)[0]->getAsTyped()->getBasicType() != EbtDouble &&
(*argp)[1]->getAsTyped()->getBasicType() != EbtFloat &&
(*argp)[1]->getAsTyped()->getBasicType() != EbtDouble &&
(*argp)[2]->getAsTyped()->getBasicType() == EbtBool) {
requireExtensions(loc, 1, &E_GL_EXT_shader_integer_mix, fnCandidate.getName().c_str());
}
}
break;
default:
break;
}
// Texture operations on texture objects (aside from texelFetch on a
// textureBuffer) require EXT_samplerless_texture_functions.
switch (callNode.getOp()) {
case EOpTextureQuerySize:
case EOpTextureQueryLevels:
case EOpTextureQuerySamples:
case EOpTextureFetch:
case EOpTextureFetchOffset:
{
const TSampler& sampler = fnCandidate[0].type->getSampler();
const bool isTexture = sampler.isTexture() && !sampler.isCombined();
const bool isBuffer = sampler.isBuffer();
const bool isFetch = callNode.getOp() == EOpTextureFetch || callNode.getOp() == EOpTextureFetchOffset;
if (isTexture && (!isBuffer || !isFetch))
requireExtensions(loc, 1, &E_GL_EXT_samplerless_texture_functions, fnCandidate.getName().c_str());
break;
}
default:
break;
}
if (callNode.isSubgroup()) {
// these require SPIR-V 1.3
if (spvVersion.spv > 0 && spvVersion.spv < EShTargetSpv_1_3)
error(loc, "requires SPIR-V 1.3", "subgroup op", "");
// Check that if extended types are being used that the correct extensions are enabled.
if (arg0 != nullptr) {
const TType& type = arg0->getType();
bool enhanced = intermediate.getEnhancedMsgs();
switch (type.getBasicType()) {
default:
break;
case EbtInt8:
case EbtUint8:
requireExtensions(loc, 1, &E_GL_EXT_shader_subgroup_extended_types_int8, type.getCompleteString(enhanced).c_str());
break;
case EbtInt16:
case EbtUint16:
requireExtensions(loc, 1, &E_GL_EXT_shader_subgroup_extended_types_int16, type.getCompleteString(enhanced).c_str());
break;
case EbtInt64:
case EbtUint64:
requireExtensions(loc, 1, &E_GL_EXT_shader_subgroup_extended_types_int64, type.getCompleteString(enhanced).c_str());
break;
case EbtFloat16:
requireExtensions(loc, 1, &E_GL_EXT_shader_subgroup_extended_types_float16, type.getCompleteString(enhanced).c_str());
break;
}
}
}
}
// Deprecated! Use PureOperatorBuiltins == true instead, in which case this
// functionality is handled in builtInOpCheck() instead of here.
//
// Do additional checking of built-in function calls that were not mapped
// to built-in operations (e.g., texturing functions).
//
// Assumes there has been a semantically correct match to a built-in function.
//
void TParseContext::nonOpBuiltInCheck(const TSourceLoc& loc, const TFunction& fnCandidate, TIntermAggregate& callNode)
{
// Further maintenance of this function is deprecated, because the "correct"
// future-oriented design is to not have to do string compares on function names.
// If PureOperatorBuiltins == true, then all built-ins should be mapped
// to a TOperator, and this function would then never get called.
assert(PureOperatorBuiltins == false);
// built-in texturing functions get their return value precision from the precision of the sampler
if (fnCandidate.getType().getQualifier().precision == EpqNone &&
fnCandidate.getParamCount() > 0 && fnCandidate[0].type->getBasicType() == EbtSampler)
callNode.getQualifier().precision = callNode.getSequence()[0]->getAsTyped()->getQualifier().precision;
if (fnCandidate.getName().compare(0, 7, "texture") == 0) {
if (fnCandidate.getName().compare(0, 13, "textureGather") == 0) {
TString featureString = fnCandidate.getName() + "(...)";
const char* feature = featureString.c_str();
profileRequires(loc, EEsProfile, 310, nullptr, feature);
int compArg = -1; // track which argument, if any, is the constant component argument
if (fnCandidate.getName().compare("textureGatherOffset") == 0) {
// GL_ARB_texture_gather is good enough for 2D non-shadow textures with no component argument
if (fnCandidate[0].type->getSampler().dim == Esd2D && ! fnCandidate[0].type->getSampler().shadow && fnCandidate.getParamCount() == 3)
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_texture_gather, feature);
else
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_gpu_shader5, feature);
int offsetArg = fnCandidate[0].type->getSampler().shadow ? 3 : 2;
if (! callNode.getSequence()[offsetArg]->getAsConstantUnion())
profileRequires(loc, EEsProfile, 320, Num_AEP_gpu_shader5, AEP_gpu_shader5,
"non-constant offset argument");
if (! fnCandidate[0].type->getSampler().shadow)
compArg = 3;
} else if (fnCandidate.getName().compare("textureGatherOffsets") == 0) {
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_gpu_shader5, feature);
if (! fnCandidate[0].type->getSampler().shadow)
compArg = 3;
// check for constant offsets
int offsetArg = fnCandidate[0].type->getSampler().shadow ? 3 : 2;
if (! callNode.getSequence()[offsetArg]->getAsConstantUnion())
error(loc, "must be a compile-time constant:", feature, "offsets argument");
} else if (fnCandidate.getName().compare("textureGather") == 0) {
// More than two arguments needs gpu_shader5, and rectangular or shadow needs gpu_shader5,
// otherwise, need GL_ARB_texture_gather.
if (fnCandidate.getParamCount() > 2 || fnCandidate[0].type->getSampler().dim == EsdRect || fnCandidate[0].type->getSampler().shadow) {
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_gpu_shader5, feature);
if (! fnCandidate[0].type->getSampler().shadow)
compArg = 2;
} else
profileRequires(loc, ~EEsProfile, 400, E_GL_ARB_texture_gather, feature);
}
if (compArg > 0 && compArg < fnCandidate.getParamCount()) {
if (callNode.getSequence()[compArg]->getAsConstantUnion()) {
int value = callNode.getSequence()[compArg]->getAsConstantUnion()->getConstArray()[0].getIConst();
if (value < 0 || value > 3)
error(loc, "must be 0, 1, 2, or 3:", feature, "component argument");
} else
error(loc, "must be a compile-time constant:", feature, "component argument");
}
} else {
// this is only for functions not starting "textureGather"...
if (fnCandidate.getName().find("Offset") != TString::npos) {
// Handle texture-offset limits checking
int arg = -1;
if (fnCandidate.getName().compare("textureOffset") == 0)
arg = 2;
else if (fnCandidate.getName().compare("texelFetchOffset") == 0)
arg = 3;
else if (fnCandidate.getName().compare("textureProjOffset") == 0)
arg = 2;
else if (fnCandidate.getName().compare("textureLodOffset") == 0)
arg = 3;
else if (fnCandidate.getName().compare("textureProjLodOffset") == 0)
arg = 3;
else if (fnCandidate.getName().compare("textureGradOffset") == 0)
arg = 4;
else if (fnCandidate.getName().compare("textureProjGradOffset") == 0)
arg = 4;
if (arg > 0) {
if (! callNode.getSequence()[arg]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "texel offset", "");
else {
const TType& type = callNode.getSequence()[arg]->getAsTyped()->getType();
for (int c = 0; c < type.getVectorSize(); ++c) {
int offset = callNode.getSequence()[arg]->getAsConstantUnion()->getConstArray()[c].getIConst();
if (offset > resources.maxProgramTexelOffset || offset < resources.minProgramTexelOffset)
error(loc, "value is out of range:", "texel offset", "[gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]");
}
}
}
}
}
}
// GL_ARB_shader_texture_image_samples
if (fnCandidate.getName().compare(0, 14, "textureSamples") == 0 || fnCandidate.getName().compare(0, 12, "imageSamples") == 0)
profileRequires(loc, ~EEsProfile, 450, E_GL_ARB_shader_texture_image_samples, "textureSamples and imageSamples");
if (fnCandidate.getName().compare(0, 11, "imageAtomic") == 0) {
const TType& imageType = callNode.getSequence()[0]->getAsTyped()->getType();
if (imageType.getSampler().type == EbtInt || imageType.getSampler().type == EbtUint) {
if (imageType.getQualifier().getFormat() != ElfR32i && imageType.getQualifier().getFormat() != ElfR32ui)
error(loc, "only supported on image with format r32i or r32ui", fnCandidate.getName().c_str(), "");
} else {
if (fnCandidate.getName().compare(0, 19, "imageAtomicExchange") != 0)
error(loc, "only supported on integer images", fnCandidate.getName().c_str(), "");
else if (imageType.getQualifier().getFormat() != ElfR32f && isEsProfile())
error(loc, "only supported on image with format r32f", fnCandidate.getName().c_str(), "");
}
}
}
//
// Do any extra checking for a user function call.
//
void TParseContext::userFunctionCallCheck(const TSourceLoc& loc, TIntermAggregate& callNode)
{
TIntermSequence& arguments = callNode.getSequence();
for (int i = 0; i < (int)arguments.size(); ++i)
samplerConstructorLocationCheck(loc, "call argument", arguments[i]);
}
//
// Emit an error if this is a sampler constructor
//
void TParseContext::samplerConstructorLocationCheck(const TSourceLoc& loc, const char* token, TIntermNode* node)
{
if (node->getAsOperator() && node->getAsOperator()->getOp() == EOpConstructTextureSampler)
error(loc, "sampler constructor must appear at point of use", token, "");
}
//
// Handle seeing a built-in constructor in a grammar production.
//
TFunction* TParseContext::handleConstructorCall(const TSourceLoc& loc, const TPublicType& publicType)
{
TType type(publicType);
type.getQualifier().precision = EpqNone;
if (type.isArray()) {
profileRequires(loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed constructor");
profileRequires(loc, EEsProfile, 300, nullptr, "arrayed constructor");
}
// Reuse EOpConstructTextureSampler for bindless image constructor
// uvec2 imgHandle;
// imageLoad(image1D(imgHandle), 0);
if (type.isImage() && extensionTurnedOn(E_GL_ARB_bindless_texture))
{
intermediate.setBindlessImageMode(currentCaller, AstRefTypeFunc);
}
TOperator op = intermediate.mapTypeToConstructorOp(type);
if (op == EOpNull) {
if (intermediate.getEnhancedMsgs() && type.getBasicType() == EbtSampler)
error(loc, "function not supported in this version; use texture() instead", "texture*D*", "");
else
error(loc, "cannot construct this type", type.getBasicString(), "");
op = EOpConstructFloat;
TType errorType(EbtFloat);
type.shallowCopy(errorType);
}
TString empty("");
return new TFunction(&empty, type, op);
}
// Handle seeing a precision qualifier in the grammar.
void TParseContext::handlePrecisionQualifier(const TSourceLoc& /*loc*/, TQualifier& qualifier, TPrecisionQualifier precision)
{
if (obeyPrecisionQualifiers())
qualifier.precision = precision;
}
// Check for messages to give on seeing a precision qualifier used in a
// declaration in the grammar.
void TParseContext::checkPrecisionQualifier(const TSourceLoc& loc, TPrecisionQualifier)
{
if (precisionManager.shouldWarnAboutDefaults()) {
warn(loc, "all default precisions are highp; use precision statements to quiet warning, e.g.:\n"
" \"precision mediump int; precision highp float;\"", "", "");
precisionManager.defaultWarningGiven();
}
}
//
// Same error message for all places assignments don't work.
//
void TParseContext::assignError(const TSourceLoc& loc, const char* op, TString left, TString right)
{
error(loc, "", op, "cannot convert from '%s' to '%s'",
right.c_str(), left.c_str());
}
//
// Same error message for all places unary operations don't work.
//
void TParseContext::unaryOpError(const TSourceLoc& loc, const char* op, TString operand)
{
error(loc, " wrong operand type", op,
"no operation '%s' exists that takes an operand of type %s (or there is no acceptable conversion)",
op, operand.c_str());
}
//
// Same error message for all binary operations don't work.
//
void TParseContext::binaryOpError(const TSourceLoc& loc, const char* op, TString left, TString right)
{
error(loc, " wrong operand types:", op,
"no operation '%s' exists that takes a left-hand operand of type '%s' and "
"a right operand of type '%s' (or there is no acceptable conversion)",
op, left.c_str(), right.c_str());
}
//
// A basic type of EbtVoid is a key that the name string was seen in the source, but
// it was not found as a variable in the symbol table. If so, give the error
// message and insert a dummy variable in the symbol table to prevent future errors.
//
void TParseContext::variableCheck(TIntermTyped*& nodePtr)
{
TIntermSymbol* symbol = nodePtr->getAsSymbolNode();
if (! symbol)
return;
if (symbol->getType().getBasicType() == EbtVoid) {
const char *extraInfoFormat = "";
if (spvVersion.vulkan != 0 && symbol->getName() == "gl_VertexID") {
extraInfoFormat = "(Did you mean gl_VertexIndex?)";
} else if (spvVersion.vulkan != 0 && symbol->getName() == "gl_InstanceID") {
extraInfoFormat = "(Did you mean gl_InstanceIndex?)";
}
error(symbol->getLoc(), "undeclared identifier", symbol->getName().c_str(), extraInfoFormat);
// Add to symbol table to prevent future error messages on the same name
if (symbol->getName().size() > 0) {
TVariable* fakeVariable = new TVariable(&symbol->getName(), TType(EbtFloat));
symbolTable.insert(*fakeVariable);
// substitute a symbol node for this new variable
nodePtr = intermediate.addSymbol(*fakeVariable, symbol->getLoc());
}
} else {
switch (symbol->getQualifier().storage) {
case EvqPointCoord:
profileRequires(symbol->getLoc(), ENoProfile, 120, nullptr, "gl_PointCoord");
break;
default: break; // some compilers want this
}
}
}
//
// Both test and if necessary, spit out an error, to see if the node is really
// an l-value that can be operated on this way.
//
// Returns true if there was an error.
//
bool TParseContext::lValueErrorCheck(const TSourceLoc& loc, const char* op, TIntermTyped* node)
{
TIntermBinary* binaryNode = node->getAsBinaryNode();
if (binaryNode) {
bool errorReturn = false;
switch(binaryNode->getOp()) {
case EOpIndexDirect:
case EOpIndexIndirect:
// ... tessellation control shader ...
// If a per-vertex output variable is used as an l-value, it is a
// compile-time or link-time error if the expression indicating the
// vertex index is not the identifier gl_InvocationID.
if (language == EShLangTessControl) {
const TType& leftType = binaryNode->getLeft()->getType();
if (leftType.getQualifier().storage == EvqVaryingOut && ! leftType.getQualifier().patch && binaryNode->getLeft()->getAsSymbolNode()) {
// we have a per-vertex output
const TIntermSymbol* rightSymbol = binaryNode->getRight()->getAsSymbolNode();
if (! rightSymbol || rightSymbol->getQualifier().builtIn != EbvInvocationId)
error(loc, "tessellation-control per-vertex output l-value must be indexed with gl_InvocationID", "[]", "");
}
}
break; // left node is checked by base class
case EOpVectorSwizzle:
errorReturn = lValueErrorCheck(loc, op, binaryNode->getLeft());
if (!errorReturn) {
int offset[4] = {0,0,0,0};
TIntermTyped* rightNode = binaryNode->getRight();
TIntermAggregate *aggrNode = rightNode->getAsAggregate();
for (TIntermSequence::iterator p = aggrNode->getSequence().begin();
p != aggrNode->getSequence().end(); p++) {
int value = (*p)->getAsTyped()->getAsConstantUnion()->getConstArray()[0].getIConst();
offset[value]++;
if (offset[value] > 1) {
error(loc, " l-value of swizzle cannot have duplicate components", op, "", "");
return true;
}
}
}
return errorReturn;
default:
break;
}
if (errorReturn) {
error(loc, " l-value required", op, "", "");
return true;
}
}
if (binaryNode && binaryNode->getOp() == EOpIndexDirectStruct && binaryNode->getLeft()->isReference())
return false;
// Let the base class check errors
if (TParseContextBase::lValueErrorCheck(loc, op, node))
return true;
const char* symbol = nullptr;
TIntermSymbol* symNode = node->getAsSymbolNode();
if (symNode != nullptr)
symbol = symNode->getName().c_str();
const char* message = nullptr;
switch (node->getQualifier().storage) {
case EvqVaryingIn: message = "can't modify shader input"; break;
case EvqInstanceId: message = "can't modify gl_InstanceID"; break;
case EvqVertexId: message = "can't modify gl_VertexID"; break;
case EvqFace: message = "can't modify gl_FrontFace"; break;
case EvqFragCoord: message = "can't modify gl_FragCoord"; break;
case EvqPointCoord: message = "can't modify gl_PointCoord"; break;
case EvqFragDepth:
intermediate.setDepthReplacing();
// "In addition, it is an error to statically write to gl_FragDepth in the fragment shader."
if (isEsProfile() && intermediate.getEarlyFragmentTests())
message = "can't modify gl_FragDepth if using early_fragment_tests";
break;
case EvqFragStencil:
intermediate.setStencilReplacing();
// "In addition, it is an error to statically write to gl_FragDepth in the fragment shader."
if (isEsProfile() && intermediate.getEarlyFragmentTests())
message = "can't modify EvqFragStencil if using early_fragment_tests";
break;
case EvqtaskPayloadSharedEXT:
if (language == EShLangMesh)
message = "can't modify variable with storage qualifier taskPayloadSharedEXT in mesh shaders";
break;
default:
break;
}
if (message == nullptr && binaryNode == nullptr && symNode == nullptr) {
error(loc, " l-value required", op, "", "");
return true;
}
//
// Everything else is okay, no error.
//
if (message == nullptr)
return false;
//
// If we get here, we have an error and a message.
//
if (symNode)
error(loc, " l-value required", op, "\"%s\" (%s)", symbol, message);
else
error(loc, " l-value required", op, "(%s)", message);
return true;
}
// Test for and give an error if the node can't be read from.
void TParseContext::rValueErrorCheck(const TSourceLoc& loc, const char* op, TIntermTyped* node)
{
// Let the base class check errors
TParseContextBase::rValueErrorCheck(loc, op, node);
TIntermSymbol* symNode = node->getAsSymbolNode();
if (!(symNode && symNode->getQualifier().isWriteOnly())) // base class checks
if (symNode && symNode->getQualifier().isExplicitInterpolation())
error(loc, "can't read from explicitly-interpolated object: ", op, symNode->getName().c_str());
// local_size_{xyz} must be assigned or specialized before gl_WorkGroupSize can be assigned.
if(node->getQualifier().builtIn == EbvWorkGroupSize &&
!(intermediate.isLocalSizeSet() || intermediate.isLocalSizeSpecialized()))
error(loc, "can't read from gl_WorkGroupSize before a fixed workgroup size has been declared", op, "");
}
//
// Both test, and if necessary spit out an error, to see if the node is really
// a constant.
//
void TParseContext::constantValueCheck(TIntermTyped* node, const char* token)
{
if (! node->getQualifier().isConstant())
error(node->getLoc(), "constant expression required", token, "");
}
//
// Both test, and if necessary spit out an error, to see if the node is really
// a 32-bit integer or can implicitly convert to one.
//
void TParseContext::integerCheck(const TIntermTyped* node, const char* token)
{
auto from_type = node->getBasicType();
if ((from_type == EbtInt || from_type == EbtUint ||
intermediate.canImplicitlyPromote(from_type, EbtInt, EOpNull) ||
intermediate.canImplicitlyPromote(from_type, EbtUint, EOpNull)) && node->isScalar())
return;
error(node->getLoc(), "scalar integer expression required", token, "");
}
//
// Both test, and if necessary spit out an error, to see if we are currently
// globally scoped.
//
void TParseContext::globalCheck(const TSourceLoc& loc, const char* token)
{
if (! symbolTable.atGlobalLevel())
error(loc, "not allowed in nested scope", token, "");
}
//
// Reserved errors for GLSL.
//
void TParseContext::reservedErrorCheck(const TSourceLoc& loc, const TString& identifier)
{
// "Identifiers starting with "gl_" are reserved for use by OpenGL, and may not be
// declared in a shader; this results in a compile-time error."
if (! symbolTable.atBuiltInLevel()) {
if (builtInName(identifier) && !extensionTurnedOn(E_GL_EXT_spirv_intrinsics))
// The extension GL_EXT_spirv_intrinsics allows us to declare identifiers starting with "gl_".
error(loc, "identifiers starting with \"gl_\" are reserved", identifier.c_str(), "");
// "__" are not supposed to be an error. ES 300 (and desktop) added the clarification:
// "In addition, all identifiers containing two consecutive underscores (__) are
// reserved; using such a name does not itself result in an error, but may result
// in undefined behavior."
// however, before that, ES tests required an error.
if (identifier.find("__") != TString::npos && !extensionTurnedOn(E_GL_EXT_spirv_intrinsics)) {
// The extension GL_EXT_spirv_intrinsics allows us to declare identifiers starting with "__".
if (isEsProfile() && version < 300)
error(loc, "identifiers containing consecutive underscores (\"__\") are reserved, and an error if version < 300", identifier.c_str(), "");
else
warn(loc, "identifiers containing consecutive underscores (\"__\") are reserved", identifier.c_str(), "");
}
}
}
//
// Reserved errors for the preprocessor.
//
void TParseContext::reservedPpErrorCheck(const TSourceLoc& loc, const char* identifier, const char* op)
{
// "__" are not supposed to be an error. ES 300 (and desktop) added the clarification:
// "All macro names containing two consecutive underscores ( __ ) are reserved;
// defining such a name does not itself result in an error, but may result in
// undefined behavior. All macro names prefixed with "GL_" ("GL" followed by a
// single underscore) are also reserved, and defining such a name results in a
// compile-time error."
// however, before that, ES tests required an error.
if (strncmp(identifier, "GL_", 3) == 0 && !extensionTurnedOn(E_GL_EXT_spirv_intrinsics))
// The extension GL_EXT_spirv_intrinsics allows us to declare macros prefixed with "GL_".
ppError(loc, "names beginning with \"GL_\" can't be (un)defined:", op, identifier);
else if (strncmp(identifier, "defined", 8) == 0)
if (relaxedErrors())
ppWarn(loc, "\"defined\" is (un)defined:", op, identifier);
else
ppError(loc, "\"defined\" can't be (un)defined:", op, identifier);
else if (strstr(identifier, "__") != nullptr && !extensionTurnedOn(E_GL_EXT_spirv_intrinsics)) {
// The extension GL_EXT_spirv_intrinsics allows us to declare macros prefixed with "__".
if (isEsProfile() && version >= 300 &&
(strcmp(identifier, "__LINE__") == 0 ||
strcmp(identifier, "__FILE__") == 0 ||
strcmp(identifier, "__VERSION__") == 0))
ppError(loc, "predefined names can't be (un)defined:", op, identifier);
else {
if (isEsProfile() && version < 300 && !relaxedErrors())
ppError(loc, "names containing consecutive underscores are reserved, and an error if version < 300:", op, identifier);
else
ppWarn(loc, "names containing consecutive underscores are reserved:", op, identifier);
}
}
}
//
// See if this version/profile allows use of the line-continuation character '\'.
//
// Returns true if a line continuation should be done.
//
bool TParseContext::lineContinuationCheck(const TSourceLoc& loc, bool endOfComment)
{
const char* message = "line continuation";
bool lineContinuationAllowed = (isEsProfile() && version >= 300) ||
(!isEsProfile() && (version >= 420 || extensionTurnedOn(E_GL_ARB_shading_language_420pack)));
if (endOfComment) {
if (lineContinuationAllowed)
warn(loc, "used at end of comment; the following line is still part of the comment", message, "");
else
warn(loc, "used at end of comment, but this version does not provide line continuation", message, "");
return lineContinuationAllowed;
}
if (relaxedErrors()) {
if (! lineContinuationAllowed)
warn(loc, "not allowed in this version", message, "");
return true;
} else {
profileRequires(loc, EEsProfile, 300, nullptr, message);
profileRequires(loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, message);
}
return lineContinuationAllowed;
}
bool TParseContext::builtInName(const TString& identifier)
{
return identifier.compare(0, 3, "gl_") == 0;
}
//
// Make sure there is enough data and not too many arguments provided to the
// constructor to build something of the type of the constructor. Also returns
// the type of the constructor.
//
// Part of establishing type is establishing specialization-constness.
// We don't yet know "top down" whether type is a specialization constant,
// but a const constructor can becomes a specialization constant if any of
// its children are, subject to KHR_vulkan_glsl rules:
//
// - int(), uint(), and bool() constructors for type conversions
// from any of the following types to any of the following types:
// * int
// * uint
// * bool
// - vector versions of the above conversion constructors
//
// Returns true if there was an error in construction.
//
bool TParseContext::constructorError(const TSourceLoc& loc, TIntermNode* node, TFunction& function, TOperator op, TType& type)
{
// See if the constructor does not establish the main type, only requalifies
// it, in which case the type comes from the argument instead of from the
// constructor function.
switch (op) {
case EOpConstructNonuniform:
if (node != nullptr && node->getAsTyped() != nullptr) {
type.shallowCopy(node->getAsTyped()->getType());
type.getQualifier().makeTemporary();
type.getQualifier().nonUniform = true;
}
break;
default:
type.shallowCopy(function.getType());
break;
}
TString constructorString;
if (intermediate.getEnhancedMsgs())
constructorString.append(type.getCompleteString(true, false, false, true)).append(" constructor");
else
constructorString.append("constructor");
// See if it's a matrix
bool constructingMatrix = false;
switch (op) {
case EOpConstructTextureSampler:
return constructorTextureSamplerError(loc, function);
case EOpConstructMat2x2:
case EOpConstructMat2x3:
case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3x3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4x4:
case EOpConstructDMat2x2:
case EOpConstructDMat2x3:
case EOpConstructDMat2x4:
case EOpConstructDMat3x2:
case EOpConstructDMat3x3:
case EOpConstructDMat3x4:
case EOpConstructDMat4x2:
case EOpConstructDMat4x3:
case EOpConstructDMat4x4:
case EOpConstructF16Mat2x2:
case EOpConstructF16Mat2x3:
case EOpConstructF16Mat2x4:
case EOpConstructF16Mat3x2:
case EOpConstructF16Mat3x3:
case EOpConstructF16Mat3x4:
case EOpConstructF16Mat4x2:
case EOpConstructF16Mat4x3:
case EOpConstructF16Mat4x4:
constructingMatrix = true;
break;
default:
break;
}
//
// Walk the arguments for first-pass checks and collection of information.
//
int size = 0;
bool constType = true;
bool specConstType = false; // value is only valid if constType is true
bool full = false;
bool overFull = false;
bool matrixInMatrix = false;
bool arrayArg = false;
bool floatArgument = false;
bool intArgument = false;
for (int arg = 0; arg < function.getParamCount(); ++arg) {
if (function[arg].type->isArray()) {
if (function[arg].type->isUnsizedArray()) {
// Can't construct from an unsized array.
error(loc, "array argument must be sized", constructorString.c_str(), "");
return true;
}
arrayArg = true;
}
if (constructingMatrix && function[arg].type->isMatrix())
matrixInMatrix = true;
// 'full' will go to true when enough args have been seen. If we loop
// again, there is an extra argument.
if (full) {
// For vectors and matrices, it's okay to have too many components
// available, but not okay to have unused arguments.
overFull = true;
}
size += function[arg].type->computeNumComponents();
if (op != EOpConstructStruct && ! type.isArray() && size >= type.computeNumComponents())
full = true;
if (! function[arg].type->getQualifier().isConstant())
constType = false;
if (function[arg].type->getQualifier().isSpecConstant())
specConstType = true;
if (function[arg].type->isFloatingDomain())
floatArgument = true;
if (function[arg].type->isIntegerDomain())
intArgument = true;
if (type.isStruct()) {
if (function[arg].type->contains16BitFloat()) {
requireFloat16Arithmetic(loc, constructorString.c_str(), "can't construct structure containing 16-bit type");
}
if (function[arg].type->contains16BitInt()) {
requireInt16Arithmetic(loc, constructorString.c_str(), "can't construct structure containing 16-bit type");
}
if (function[arg].type->contains8BitInt()) {
requireInt8Arithmetic(loc, constructorString.c_str(), "can't construct structure containing 8-bit type");
}
}
}
if (op == EOpConstructNonuniform)
constType = false;
switch (op) {
case EOpConstructFloat16:
case EOpConstructF16Vec2:
case EOpConstructF16Vec3:
case EOpConstructF16Vec4:
if (type.isArray())
requireFloat16Arithmetic(loc, constructorString.c_str(), "16-bit arrays not supported");
if (type.isVector() && function.getParamCount() != 1)
requireFloat16Arithmetic(loc, constructorString.c_str(), "16-bit vectors only take vector types");
break;
case EOpConstructUint16:
case EOpConstructU16Vec2:
case EOpConstructU16Vec3:
case EOpConstructU16Vec4:
case EOpConstructInt16:
case EOpConstructI16Vec2:
case EOpConstructI16Vec3:
case EOpConstructI16Vec4:
if (type.isArray())
requireInt16Arithmetic(loc, constructorString.c_str(), "16-bit arrays not supported");
if (type.isVector() && function.getParamCount() != 1)
requireInt16Arithmetic(loc, constructorString.c_str(), "16-bit vectors only take vector types");
break;
case EOpConstructUint8:
case EOpConstructU8Vec2:
case EOpConstructU8Vec3:
case EOpConstructU8Vec4:
case EOpConstructInt8:
case EOpConstructI8Vec2:
case EOpConstructI8Vec3:
case EOpConstructI8Vec4:
if (type.isArray())
requireInt8Arithmetic(loc, constructorString.c_str(), "8-bit arrays not supported");
if (type.isVector() && function.getParamCount() != 1)
requireInt8Arithmetic(loc, constructorString.c_str(), "8-bit vectors only take vector types");
break;
default:
break;
}
// inherit constness from children
if (constType) {
bool makeSpecConst;
// Finish pinning down spec-const semantics
if (specConstType) {
switch (op) {
case EOpConstructInt8:
case EOpConstructInt:
case EOpConstructUint:
case EOpConstructBool:
case EOpConstructBVec2:
case EOpConstructBVec3:
case EOpConstructBVec4:
case EOpConstructIVec2:
case EOpConstructIVec3:
case EOpConstructIVec4:
case EOpConstructUVec2:
case EOpConstructUVec3:
case EOpConstructUVec4:
case EOpConstructUint8:
case EOpConstructInt16:
case EOpConstructUint16:
case EOpConstructInt64:
case EOpConstructUint64:
case EOpConstructI8Vec2:
case EOpConstructI8Vec3:
case EOpConstructI8Vec4:
case EOpConstructU8Vec2:
case EOpConstructU8Vec3:
case EOpConstructU8Vec4:
case EOpConstructI16Vec2:
case EOpConstructI16Vec3:
case EOpConstructI16Vec4:
case EOpConstructU16Vec2:
case EOpConstructU16Vec3:
case EOpConstructU16Vec4:
case EOpConstructI64Vec2:
case EOpConstructI64Vec3:
case EOpConstructI64Vec4:
case EOpConstructU64Vec2:
case EOpConstructU64Vec3:
case EOpConstructU64Vec4:
// This was the list of valid ones, if they aren't converting from float
// and aren't making an array.
makeSpecConst = ! floatArgument && ! type.isArray();
break;
case EOpConstructVec2:
case EOpConstructVec3:
case EOpConstructVec4:
// This was the list of valid ones, if they aren't converting from int
// and aren't making an array.
makeSpecConst = ! intArgument && !type.isArray();
break;
case EOpConstructCooperativeMatrixNV:
case EOpConstructCooperativeMatrixKHR:
case EOpConstructStruct:
{
const char *specConstantCompositeExt[] = { E_GL_EXT_spec_constant_composites };
if (checkExtensionsRequested(loc, 1, specConstantCompositeExt, "spec constant aggregate constructor")) {
makeSpecConst = true;
} else {
makeSpecConst = false;
}
}
break;
default:
// anything else wasn't white-listed in the spec as a conversion
makeSpecConst = false;
break;
}
} else
makeSpecConst = false;
if (makeSpecConst)
type.getQualifier().makeSpecConstant();
else if (specConstType)
type.getQualifier().makeTemporary();
else
type.getQualifier().storage = EvqConst;
}
if (type.isArray()) {
if (function.getParamCount() == 0) {
error(loc, "array constructor must have at least one argument", constructorString.c_str(), "");
return true;
}
if (type.isUnsizedArray()) {
// auto adapt the constructor type to the number of arguments
type.changeOuterArraySize(function.getParamCount());
} else if (type.getOuterArraySize() != function.getParamCount()) {
error(loc, "array constructor needs one argument per array element", constructorString.c_str(), "");
return true;
}
if (type.isArrayOfArrays()) {
// Types have to match, but we're still making the type.
// Finish making the type, and the comparison is done later
// when checking for conversion.
TArraySizes& arraySizes = *type.getArraySizes();
// At least the dimensionalities have to match.
if (! function[0].type->isArray() ||
arraySizes.getNumDims() != function[0].type->getArraySizes()->getNumDims() + 1) {
error(loc, "array constructor argument not correct type to construct array element", constructorString.c_str(), "");
return true;
}
if (arraySizes.isInnerUnsized()) {
// "Arrays of arrays ..., and the size for any dimension is optional"
// That means we need to adopt (from the first argument) the other array sizes into the type.
for (int d = 1; d < arraySizes.getNumDims(); ++d) {
if (arraySizes.getDimSize(d) == UnsizedArraySize) {
arraySizes.setDimSize(d, function[0].type->getArraySizes()->getDimSize(d - 1));
}
}
}
}
}
if (arrayArg && op != EOpConstructStruct && ! type.isArrayOfArrays()) {
error(loc, "constructing non-array constituent from array argument", constructorString.c_str(), "");
return true;
}
if (matrixInMatrix && ! type.isArray()) {
profileRequires(loc, ENoProfile, 120, nullptr, "constructing matrix from matrix");
// "If a matrix argument is given to a matrix constructor,
// it is a compile-time error to have any other arguments."
if (function.getParamCount() != 1)
error(loc, "matrix constructed from matrix can only have one argument", constructorString.c_str(), "");
return false;
}
if (overFull) {
error(loc, "too many arguments", constructorString.c_str(), "");
return true;
}
if (op == EOpConstructStruct && ! type.isArray() && (int)type.getStruct()->size() != function.getParamCount()) {
error(loc, "Number of constructor parameters does not match the number of structure fields", constructorString.c_str(), "");
return true;
}
if ((op != EOpConstructStruct && size != 1 && size < type.computeNumComponents()) ||
(op == EOpConstructStruct && size < type.computeNumComponents())) {
error(loc, "not enough data provided for construction", constructorString.c_str(), "");
return true;
}
if (type.isCoopMat() && function.getParamCount() != 1) {
error(loc, "wrong number of arguments", constructorString.c_str(), "");
return true;
}
if (type.isCoopMat() &&
!(function[0].type->isScalar() || function[0].type->isCoopMat())) {
error(loc, "Cooperative matrix constructor argument must be scalar or cooperative matrix", constructorString.c_str(), "");
return true;
}
TIntermTyped* typed = node->getAsTyped();
if (type.isCoopMat() && typed->getType().isCoopMat() &&
!type.sameCoopMatShapeAndUse(typed->getType())) {
error(loc, "Cooperative matrix type parameters mismatch", constructorString.c_str(), "");
return true;
}
if (typed == nullptr) {
error(loc, "constructor argument does not have a type", constructorString.c_str(), "");
return true;
}
if (op != EOpConstructStruct && op != EOpConstructNonuniform && typed->getBasicType() == EbtSampler) {
if (op == EOpConstructUVec2 && extensionTurnedOn(E_GL_ARB_bindless_texture)) {
intermediate.setBindlessTextureMode(currentCaller, AstRefTypeFunc);
}
else {
error(loc, "cannot convert a sampler", constructorString.c_str(), "");
return true;
}
}
if (op != EOpConstructStruct && typed->isAtomic()) {
error(loc, "cannot convert an atomic_uint", constructorString.c_str(), "");
return true;
}
if (typed->getBasicType() == EbtVoid) {
error(loc, "cannot convert a void", constructorString.c_str(), "");
return true;
}
return false;
}
// Verify all the correct semantics for constructing a combined texture/sampler.
// Return true if the semantics are incorrect.
bool TParseContext::constructorTextureSamplerError(const TSourceLoc& loc, const TFunction& function)
{
TString constructorName = function.getType().getBasicTypeString(); // TODO: performance: should not be making copy; interface needs to change
const char* token = constructorName.c_str();
// verify the constructor for bindless texture, the input must be ivec2 or uvec2
if (function.getParamCount() == 1) {
TType* pType = function[0].type;
TBasicType basicType = pType->getBasicType();
bool isIntegerVec2 = ((basicType == EbtUint || basicType == EbtInt) && pType->getVectorSize() == 2);
bool bindlessMode = extensionTurnedOn(E_GL_ARB_bindless_texture);
if (isIntegerVec2 && bindlessMode) {
if (pType->getSampler().isImage())
intermediate.setBindlessImageMode(currentCaller, AstRefTypeFunc);
else
intermediate.setBindlessTextureMode(currentCaller, AstRefTypeFunc);
return false;
} else {
if (!bindlessMode)
error(loc, "sampler-constructor requires the extension GL_ARB_bindless_texture enabled", token, "");
else
error(loc, "sampler-constructor requires the input to be ivec2 or uvec2", token, "");
return true;
}
}
// exactly two arguments needed
if (function.getParamCount() != 2) {
error(loc, "sampler-constructor requires two arguments", token, "");
return true;
}
// For now, not allowing arrayed constructors, the rest of this function
// is set up to allow them, if this test is removed:
if (function.getType().isArray()) {
error(loc, "sampler-constructor cannot make an array of samplers", token, "");
return true;
}
// first argument
// * the constructor's first argument must be a texture type
// * the dimensionality (1D, 2D, 3D, Cube, Rect, Buffer, MS, and Array)
// of the texture type must match that of the constructed sampler type
// (that is, the suffixes of the type of the first argument and the
// type of the constructor will be spelled the same way)
if (function[0].type->getBasicType() != EbtSampler ||
! function[0].type->getSampler().isTexture() ||
function[0].type->isArray()) {
error(loc, "sampler-constructor first argument must be a scalar *texture* type", token, "");
return true;
}
// simulate the first argument's impact on the result type, so it can be compared with the encapsulated operator!=()
TSampler texture = function.getType().getSampler();
texture.setCombined(false);
texture.shadow = false;
if (texture != function[0].type->getSampler()) {
error(loc, "sampler-constructor first argument must be a *texture* type"
" matching the dimensionality and sampled type of the constructor", token, "");
return true;
}
// second argument
// * the constructor's second argument must be a scalar of type
// *sampler* or *samplerShadow*
if ( function[1].type->getBasicType() != EbtSampler ||
! function[1].type->getSampler().isPureSampler() ||
function[1].type->isArray()) {
error(loc, "sampler-constructor second argument must be a scalar sampler or samplerShadow", token, "");
return true;
}
return false;
}
// Checks to see if a void variable has been declared and raise an error message for such a case
//
// returns true in case of an error
//
bool TParseContext::voidErrorCheck(const TSourceLoc& loc, const TString& identifier, const TBasicType basicType)
{
if (basicType == EbtVoid) {
error(loc, "illegal use of type 'void'", identifier.c_str(), "");
return true;
}
return false;
}
// Checks to see if the node (for the expression) contains a scalar boolean expression or not
void TParseContext::boolCheck(const TSourceLoc& loc, const TIntermTyped* type)
{
if (type->getBasicType() != EbtBool || type->isArray() || type->isMatrix() || type->isVector())
error(loc, "boolean expression expected", "", "");
}
// This function checks to see if the node (for the expression) contains a scalar boolean expression or not
void TParseContext::boolCheck(const TSourceLoc& loc, const TPublicType& pType)
{
if (pType.basicType != EbtBool || pType.arraySizes || pType.matrixCols > 1 || (pType.vectorSize > 1))
error(loc, "boolean expression expected", "", "");
}
void TParseContext::samplerCheck(const TSourceLoc& loc, const TType& type, const TString& identifier, TIntermTyped* /*initializer*/)
{
// Check that the appropriate extension is enabled if external sampler is used.
// There are two extensions. The correct one must be used based on GLSL version.
if (type.getBasicType() == EbtSampler && type.getSampler().isExternal()) {
if (version < 300) {
requireExtensions(loc, 1, &E_GL_OES_EGL_image_external, "samplerExternalOES");
} else {
requireExtensions(loc, 1, &E_GL_OES_EGL_image_external_essl3, "samplerExternalOES");
}
}
if (type.getSampler().isYuv()) {
requireExtensions(loc, 1, &E_GL_EXT_YUV_target, "__samplerExternal2DY2YEXT");
}
if (type.getQualifier().storage == EvqUniform)
return;
if (type.getBasicType() == EbtStruct && containsFieldWithBasicType(type, EbtSampler)) {
// For bindless texture, sampler can be declared as an struct member
if (extensionTurnedOn(E_GL_ARB_bindless_texture)) {
if (type.getSampler().isImage())
intermediate.setBindlessImageMode(currentCaller, AstRefTypeVar);
else
intermediate.setBindlessTextureMode(currentCaller, AstRefTypeVar);
}
else {
error(loc, "non-uniform struct contains a sampler or image:", type.getBasicTypeString().c_str(), identifier.c_str());
}
}
else if (type.getBasicType() == EbtSampler && type.getQualifier().storage != EvqUniform) {
// For bindless texture, sampler can be declared as an input/output/block member
if (extensionTurnedOn(E_GL_ARB_bindless_texture)) {
if (type.getSampler().isImage())
intermediate.setBindlessImageMode(currentCaller, AstRefTypeVar);
else
intermediate.setBindlessTextureMode(currentCaller, AstRefTypeVar);
}
else {
// non-uniform sampler
// not yet: okay if it has an initializer
// if (! initializer)
if (type.getSampler().isAttachmentEXT() && type.getQualifier().storage != EvqTileImageEXT)
error(loc, "can only be used in tileImageEXT variables or function parameters:", type.getBasicTypeString().c_str(), identifier.c_str());
else if (type.getQualifier().storage != EvqTileImageEXT)
error(loc, "sampler/image types can only be used in uniform variables or function parameters:", type.getBasicTypeString().c_str(), identifier.c_str());
}
}
}
void TParseContext::atomicUintCheck(const TSourceLoc& loc, const TType& type, const TString& identifier)
{
if (type.getQualifier().storage == EvqUniform)
return;
if (type.getBasicType() == EbtStruct && containsFieldWithBasicType(type, EbtAtomicUint))
error(loc, "non-uniform struct contains an atomic_uint:", type.getBasicTypeString().c_str(), identifier.c_str());
else if (type.getBasicType() == EbtAtomicUint && type.getQualifier().storage != EvqUniform)
error(loc, "atomic_uints can only be used in uniform variables or function parameters:", type.getBasicTypeString().c_str(), identifier.c_str());
}
void TParseContext::accStructCheck(const TSourceLoc& loc, const TType& type, const TString& identifier)
{
if (type.getQualifier().storage == EvqUniform)
return;
if (type.getBasicType() == EbtStruct && containsFieldWithBasicType(type, EbtAccStruct))
error(loc, "non-uniform struct contains an accelerationStructureNV:", type.getBasicTypeString().c_str(), identifier.c_str());
else if (type.getBasicType() == EbtAccStruct && type.getQualifier().storage != EvqUniform)
error(loc, "accelerationStructureNV can only be used in uniform variables or function parameters:",
type.getBasicTypeString().c_str(), identifier.c_str());
}
void TParseContext::transparentOpaqueCheck(const TSourceLoc& loc, const TType& type, const TString& identifier)
{
if (parsingBuiltins)
return;
if (type.getQualifier().storage != EvqUniform)
return;
if (type.containsNonOpaque()) {
// Vulkan doesn't allow transparent uniforms outside of blocks
if (spvVersion.vulkan > 0 && !spvVersion.vulkanRelaxed)
vulkanRemoved(loc, "non-opaque uniforms outside a block");
// OpenGL wants locations on these (unless they are getting automapped)
if (spvVersion.openGl > 0 && !type.getQualifier().hasLocation() && !intermediate.getAutoMapLocations())
error(loc, "non-opaque uniform variables need a layout(location=L)", identifier.c_str(), "");
}
}
//
// Qualifier checks knowing the qualifier and that it is a member of a struct/block.
//
void TParseContext::memberQualifierCheck(glslang::TPublicType& publicType)
{
globalQualifierFixCheck(publicType.loc, publicType.qualifier, true);
checkNoShaderLayouts(publicType.loc, publicType.shaderQualifiers);
if (publicType.qualifier.isNonUniform()) {
error(publicType.loc, "not allowed on block or structure members", "nonuniformEXT", "");
publicType.qualifier.nonUniform = false;
}
}
//
// Check/fix just a full qualifier (no variables or types yet, but qualifier is complete) at global level.
//
void TParseContext::globalQualifierFixCheck(const TSourceLoc& loc, TQualifier& qualifier, bool isMemberCheck, const TPublicType* publicType)
{
bool nonuniformOkay = false;
// move from parameter/unknown qualifiers to pipeline in/out qualifiers
switch (qualifier.storage) {
case EvqIn:
profileRequires(loc, ENoProfile, 130, nullptr, "in for stage inputs");
profileRequires(loc, EEsProfile, 300, nullptr, "in for stage inputs");
qualifier.storage = EvqVaryingIn;
nonuniformOkay = true;
break;
case EvqOut:
profileRequires(loc, ENoProfile, 130, nullptr, "out for stage outputs");
profileRequires(loc, EEsProfile, 300, nullptr, "out for stage outputs");
qualifier.storage = EvqVaryingOut;
if (intermediate.isInvariantAll())
qualifier.invariant = true;
break;
case EvqInOut:
qualifier.storage = EvqVaryingIn;
error(loc, "cannot use 'inout' at global scope", "", "");
break;
case EvqGlobal:
case EvqTemporary:
nonuniformOkay = true;
break;
case EvqUniform:
// According to GLSL spec: The std430 qualifier is supported only for shader storage blocks; a shader using
// the std430 qualifier on a uniform block will fail to compile.
// Only check the global declaration: layout(std430) uniform;
if (blockName == nullptr &&
qualifier.layoutPacking == ElpStd430)
{
requireExtensions(loc, 1, &E_GL_EXT_scalar_block_layout, "default std430 layout for uniform");
}
if (publicType != nullptr && publicType->isImage() &&
(qualifier.layoutFormat > ElfExtSizeGuard && qualifier.layoutFormat < ElfCount))
qualifier.layoutFormat = mapLegacyLayoutFormat(qualifier.layoutFormat, publicType->sampler.getBasicType());
break;
default:
break;
}
if (!nonuniformOkay && qualifier.isNonUniform())
error(loc, "for non-parameter, can only apply to 'in' or no storage qualifier", "nonuniformEXT", "");
if (qualifier.isSpirvByReference())
error(loc, "can only apply to parameter", "spirv_by_reference", "");
if (qualifier.isSpirvLiteral())
error(loc, "can only apply to parameter", "spirv_literal", "");
// Storage qualifier isn't ready for memberQualifierCheck, we should skip invariantCheck for it.
if (!isMemberCheck || structNestingLevel > 0)
invariantCheck(loc, qualifier);
if (qualifier.isFullQuads()) {
if (qualifier.storage != EvqVaryingIn)
error(loc, "can only apply to input layout", "full_quads ", "");
intermediate.setReqFullQuadsMode();
}
if (qualifier.isQuadDeriv()) {
if (qualifier.storage != EvqVaryingIn)
error(loc, "can only apply to input layout", "quad_derivatives", "");
intermediate.setQuadDerivMode();
}
}
//
// Check a full qualifier and type (no variable yet) at global level.
//
void TParseContext::globalQualifierTypeCheck(const TSourceLoc& loc, const TQualifier& qualifier, const TPublicType& publicType)
{
if (! symbolTable.atGlobalLevel())
return;
if (!(publicType.userDef && publicType.userDef->isReference()) && !parsingBuiltins) {
if (qualifier.isMemoryQualifierImageAndSSBOOnly() && ! publicType.isImage() && publicType.qualifier.storage != EvqBuffer) {
error(loc, "memory qualifiers cannot be used on this type", "", "");
} else if (qualifier.isMemory() && (publicType.basicType != EbtSampler) && !publicType.qualifier.isUniformOrBuffer()) {
error(loc, "memory qualifiers cannot be used on this type", "", "");
}
}
if (qualifier.storage == EvqBuffer &&
publicType.basicType != EbtBlock &&
!qualifier.hasBufferReference())
error(loc, "buffers can be declared only as blocks", "buffer", "");
if (qualifier.storage != EvqVaryingIn && publicType.basicType == EbtDouble &&
extensionTurnedOn(E_GL_ARB_vertex_attrib_64bit) && language == EShLangVertex &&
version < 400) {
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 410, E_GL_ARB_gpu_shader_fp64, "vertex-shader `double` type");
}
if (qualifier.storage != EvqVaryingIn && qualifier.storage != EvqVaryingOut)
return;
if (publicType.shaderQualifiers.hasBlendEquation())
error(loc, "can only be applied to a standalone 'out'", "blend equation", "");
// now, knowing it is a shader in/out, do all the in/out semantic checks
if (publicType.basicType == EbtBool && !parsingBuiltins) {
error(loc, "cannot be bool", GetStorageQualifierString(qualifier.storage), "");
return;
}
if (isTypeInt(publicType.basicType) || publicType.basicType == EbtDouble) {
profileRequires(loc, EEsProfile, 300, nullptr, "non-float shader input/output");
profileRequires(loc, ~EEsProfile, 130, nullptr, "non-float shader input/output");
}
if (!qualifier.flat && !qualifier.isExplicitInterpolation() && !qualifier.isPervertexNV() && !qualifier.isPervertexEXT()) {
if (isTypeInt(publicType.basicType) ||
publicType.basicType == EbtDouble ||
(publicType.userDef && ( publicType.userDef->containsBasicType(EbtInt)
|| publicType.userDef->containsBasicType(EbtUint)
|| publicType.userDef->contains16BitInt()
|| publicType.userDef->contains8BitInt()
|| publicType.userDef->contains64BitInt()
|| publicType.userDef->containsDouble()))) {
if (qualifier.storage == EvqVaryingIn && language == EShLangFragment)
error(loc, "must be qualified as flat", TType::getBasicString(publicType.basicType), GetStorageQualifierString(qualifier.storage));
else if (qualifier.storage == EvqVaryingOut && language == EShLangVertex && version == 300)
error(loc, "must be qualified as flat", TType::getBasicString(publicType.basicType), GetStorageQualifierString(qualifier.storage));
}
}
if (qualifier.isPatch() && qualifier.isInterpolation())
error(loc, "cannot use interpolation qualifiers with patch", "patch", "");
if (qualifier.isTaskPayload() && publicType.basicType == EbtBlock)
error(loc, "taskPayloadSharedEXT variables should not be declared as interface blocks", "taskPayloadSharedEXT", "");
if (qualifier.isTaskMemory() && publicType.basicType != EbtBlock)
error(loc, "taskNV variables can be declared only as blocks", "taskNV", "");
if (qualifier.storage == EvqVaryingIn) {
switch (language) {
case EShLangVertex:
if (publicType.basicType == EbtStruct) {
error(loc, "cannot be a structure", GetStorageQualifierString(qualifier.storage), "");
return;
}
if (publicType.arraySizes) {
requireProfile(loc, ~EEsProfile, "vertex input arrays");
profileRequires(loc, ENoProfile, 150, nullptr, "vertex input arrays");
}
if (publicType.basicType == EbtDouble)
profileRequires(loc, ~EEsProfile, 410, E_GL_ARB_vertex_attrib_64bit, "vertex-shader `double` type input");
if (qualifier.isAuxiliary() || qualifier.isInterpolation() || qualifier.isMemory() || qualifier.invariant)
error(loc, "vertex input cannot be further qualified", "", "");
break;
case EShLangFragment:
if (publicType.userDef) {
profileRequires(loc, EEsProfile, 300, nullptr, "fragment-shader struct input");
profileRequires(loc, ~EEsProfile, 150, nullptr, "fragment-shader struct input");
if (publicType.userDef->containsStructure())
requireProfile(loc, ~EEsProfile, "fragment-shader struct input containing structure");
if (publicType.userDef->containsArray())
requireProfile(loc, ~EEsProfile, "fragment-shader struct input containing an array");
}
break;
case EShLangCompute:
if (! symbolTable.atBuiltInLevel())
error(loc, "global storage input qualifier cannot be used in a compute shader", "in", "");
break;
case EShLangTessControl:
if (qualifier.patch)
error(loc, "can only use on output in tessellation-control shader", "patch", "");
break;
default:
break;
}
} else {
// qualifier.storage == EvqVaryingOut
switch (language) {
case EShLangVertex:
if (publicType.userDef) {
profileRequires(loc, EEsProfile, 300, nullptr, "vertex-shader struct output");
profileRequires(loc, ~EEsProfile, 150, nullptr, "vertex-shader struct output");
if (publicType.userDef->containsStructure())
requireProfile(loc, ~EEsProfile, "vertex-shader struct output containing structure");
if (publicType.userDef->containsArray())
requireProfile(loc, ~EEsProfile, "vertex-shader struct output containing an array");
}
break;
case EShLangFragment:
profileRequires(loc, EEsProfile, 300, nullptr, "fragment shader output");
if (publicType.basicType == EbtStruct) {
error(loc, "cannot be a structure", GetStorageQualifierString(qualifier.storage), "");
return;
}
if (publicType.matrixRows > 0) {
error(loc, "cannot be a matrix", GetStorageQualifierString(qualifier.storage), "");
return;
}
if (qualifier.isAuxiliary())
error(loc, "can't use auxiliary qualifier on a fragment output", "centroid/sample/patch", "");
if (qualifier.isInterpolation())
error(loc, "can't use interpolation qualifier on a fragment output", "flat/smooth/noperspective", "");
if (publicType.basicType == EbtDouble || publicType.basicType == EbtInt64 || publicType.basicType == EbtUint64)
error(loc, "cannot contain a double, int64, or uint64", GetStorageQualifierString(qualifier.storage), "");
break;
case EShLangCompute:
error(loc, "global storage output qualifier cannot be used in a compute shader", "out", "");
break;
case EShLangTessEvaluation:
if (qualifier.patch)
error(loc, "can only use on input in tessellation-evaluation shader", "patch", "");
break;
default:
break;
}
}
}
//
// Merge characteristics of the 'src' qualifier into the 'dst'.
// If there is duplication, issue error messages, unless 'force'
// is specified, which means to just override default settings.
//
// Also, when force is false, it will be assumed that 'src' follows
// 'dst', for the purpose of error checking order for versions
// that require specific orderings of qualifiers.
//
void TParseContext::mergeQualifiers(const TSourceLoc& loc, TQualifier& dst, const TQualifier& src, bool force)
{
// Multiple auxiliary qualifiers (mostly done later by 'individual qualifiers')
if (src.isAuxiliary() && dst.isAuxiliary())
error(loc, "can only have one auxiliary qualifier (centroid, patch, and sample)", "", "");
// Multiple interpolation qualifiers (mostly done later by 'individual qualifiers')
if (src.isInterpolation() && dst.isInterpolation())
error(loc, "can only have one interpolation qualifier (flat, smooth, noperspective, __explicitInterpAMD)", "", "");
// Ordering
if (! force && ((!isEsProfile() && version < 420) ||
(isEsProfile() && version < 310))
&& ! extensionTurnedOn(E_GL_ARB_shading_language_420pack)) {
// non-function parameters
if (src.isNoContraction() && (dst.invariant || dst.isInterpolation() || dst.isAuxiliary() || dst.storage != EvqTemporary || dst.precision != EpqNone))
error(loc, "precise qualifier must appear first", "", "");
if (src.invariant && (dst.isInterpolation() || dst.isAuxiliary() || dst.storage != EvqTemporary || dst.precision != EpqNone))
error(loc, "invariant qualifier must appear before interpolation, storage, and precision qualifiers ", "", "");
else if (src.isInterpolation() && (dst.isAuxiliary() || dst.storage != EvqTemporary || dst.precision != EpqNone))
error(loc, "interpolation qualifiers must appear before storage and precision qualifiers", "", "");
else if (src.isAuxiliary() && (dst.storage != EvqTemporary || dst.precision != EpqNone))
error(loc, "Auxiliary qualifiers (centroid, patch, and sample) must appear before storage and precision qualifiers", "", "");
else if (src.storage != EvqTemporary && (dst.precision != EpqNone))
error(loc, "precision qualifier must appear as last qualifier", "", "");
// function parameters
if (src.isNoContraction() && (dst.storage == EvqConst || dst.storage == EvqIn || dst.storage == EvqOut))
error(loc, "precise qualifier must appear first", "", "");
if (src.storage == EvqConst && (dst.storage == EvqIn || dst.storage == EvqOut))
error(loc, "in/out must appear before const", "", "");
}
// Storage qualification
if (dst.storage == EvqTemporary || dst.storage == EvqGlobal)
dst.storage = src.storage;
else if ((dst.storage == EvqIn && src.storage == EvqOut) ||
(dst.storage == EvqOut && src.storage == EvqIn))
dst.storage = EvqInOut;
else if ((dst.storage == EvqIn && src.storage == EvqConst) ||
(dst.storage == EvqConst && src.storage == EvqIn))
dst.storage = EvqConstReadOnly;
else if (src.storage != EvqTemporary &&
src.storage != EvqGlobal)
error(loc, "too many storage qualifiers", GetStorageQualifierString(src.storage), "");
// Precision qualifiers
if (! force && src.precision != EpqNone && dst.precision != EpqNone)
error(loc, "only one precision qualifier allowed", GetPrecisionQualifierString(src.precision), "");
if (dst.precision == EpqNone || (force && src.precision != EpqNone))
dst.precision = src.precision;
if (!force && ((src.coherent && (dst.devicecoherent || dst.queuefamilycoherent || dst.workgroupcoherent || dst.subgroupcoherent || dst.shadercallcoherent)) ||
(src.devicecoherent && (dst.coherent || dst.queuefamilycoherent || dst.workgroupcoherent || dst.subgroupcoherent || dst.shadercallcoherent)) ||
(src.queuefamilycoherent && (dst.coherent || dst.devicecoherent || dst.workgroupcoherent || dst.subgroupcoherent || dst.shadercallcoherent)) ||
(src.workgroupcoherent && (dst.coherent || dst.devicecoherent || dst.queuefamilycoherent || dst.subgroupcoherent || dst.shadercallcoherent)) ||
(src.subgroupcoherent && (dst.coherent || dst.devicecoherent || dst.queuefamilycoherent || dst.workgroupcoherent || dst.shadercallcoherent)) ||
(src.shadercallcoherent && (dst.coherent || dst.devicecoherent || dst.queuefamilycoherent || dst.workgroupcoherent || dst.subgroupcoherent)))) {
error(loc, "only one coherent/devicecoherent/queuefamilycoherent/workgroupcoherent/subgroupcoherent/shadercallcoherent qualifier allowed",
GetPrecisionQualifierString(src.precision), "");
}
// Layout qualifiers
mergeObjectLayoutQualifiers(dst, src, false);
// individual qualifiers
bool repeated = false;
#define MERGE_SINGLETON(field) repeated |= dst.field && src.field; dst.field |= src.field;
MERGE_SINGLETON(invariant);
MERGE_SINGLETON(centroid);
MERGE_SINGLETON(smooth);
MERGE_SINGLETON(flat);
MERGE_SINGLETON(specConstant);
MERGE_SINGLETON(noContraction);
MERGE_SINGLETON(nopersp);
MERGE_SINGLETON(explicitInterp);
MERGE_SINGLETON(perPrimitiveNV);
MERGE_SINGLETON(perViewNV);
MERGE_SINGLETON(perTaskNV);
MERGE_SINGLETON(patch);
MERGE_SINGLETON(sample);
MERGE_SINGLETON(coherent);
MERGE_SINGLETON(devicecoherent);
MERGE_SINGLETON(queuefamilycoherent);
MERGE_SINGLETON(workgroupcoherent);
MERGE_SINGLETON(subgroupcoherent);
MERGE_SINGLETON(shadercallcoherent);
MERGE_SINGLETON(nonprivate);
MERGE_SINGLETON(volatil);
MERGE_SINGLETON(restrict);
MERGE_SINGLETON(readonly);
MERGE_SINGLETON(writeonly);
MERGE_SINGLETON(nonUniform);
// SPIR-V storage class qualifier (GL_EXT_spirv_intrinsics)
dst.spirvStorageClass = src.spirvStorageClass;
// SPIR-V decorate qualifiers (GL_EXT_spirv_intrinsics)
if (src.hasSpirvDecorate()) {
if (dst.hasSpirvDecorate()) {
const TSpirvDecorate& srcSpirvDecorate = src.getSpirvDecorate();
TSpirvDecorate& dstSpirvDecorate = dst.getSpirvDecorate();
for (auto& decorate : srcSpirvDecorate.decorates) {
if (dstSpirvDecorate.decorates.find(decorate.first) != dstSpirvDecorate.decorates.end())
error(loc, "too many SPIR-V decorate qualifiers", "spirv_decorate", "(decoration=%u)", decorate.first);
else
dstSpirvDecorate.decorates.insert(decorate);
}
for (auto& decorateId : srcSpirvDecorate.decorateIds) {
if (dstSpirvDecorate.decorateIds.find(decorateId.first) != dstSpirvDecorate.decorateIds.end())
error(loc, "too many SPIR-V decorate qualifiers", "spirv_decorate_id", "(decoration=%u)", decorateId.first);
else
dstSpirvDecorate.decorateIds.insert(decorateId);
}
for (auto& decorateString : srcSpirvDecorate.decorateStrings) {
if (dstSpirvDecorate.decorates.find(decorateString.first) != dstSpirvDecorate.decorates.end())
error(loc, "too many SPIR-V decorate qualifiers", "spirv_decorate_string", "(decoration=%u)", decorateString.first);
else
dstSpirvDecorate.decorateStrings.insert(decorateString);
}
} else {
dst.spirvDecorate = src.spirvDecorate;
}
}
if (repeated)
error(loc, "replicated qualifiers", "", "");
}
void TParseContext::setDefaultPrecision(const TSourceLoc& loc, TPublicType& publicType, TPrecisionQualifier qualifier)
{
TBasicType basicType = publicType.basicType;
if (basicType == EbtSampler) {
defaultSamplerPrecision[computeSamplerTypeIndex(publicType.sampler)] = qualifier;
return; // all is well
}
if (basicType == EbtInt || basicType == EbtFloat) {
if (publicType.isScalar()) {
defaultPrecision[basicType] = qualifier;
if (basicType == EbtInt) {
defaultPrecision[EbtUint] = qualifier;
precisionManager.explicitIntDefaultSeen();
} else
precisionManager.explicitFloatDefaultSeen();
return; // all is well
}
}
if (basicType == EbtAtomicUint) {
if (qualifier != EpqHigh)
error(loc, "can only apply highp to atomic_uint", "precision", "");
return;
}
error(loc, "cannot apply precision statement to this type; use 'float', 'int' or a sampler type", TType::getBasicString(basicType), "");
}
// used to flatten the sampler type space into a single dimension
// correlates with the declaration of defaultSamplerPrecision[]
int TParseContext::computeSamplerTypeIndex(TSampler& sampler)
{
int arrayIndex = sampler.arrayed ? 1 : 0;
int shadowIndex = sampler.shadow ? 1 : 0;
int externalIndex = sampler.isExternal() ? 1 : 0;
int imageIndex = sampler.isImageClass() ? 1 : 0;
int msIndex = sampler.isMultiSample() ? 1 : 0;
int flattened = EsdNumDims * (EbtNumTypes * (2 * (2 * (2 * (2 * arrayIndex + msIndex) + imageIndex) + shadowIndex) +
externalIndex) + sampler.type) + sampler.dim;
assert(flattened < maxSamplerIndex);
return flattened;
}
TPrecisionQualifier TParseContext::getDefaultPrecision(TPublicType& publicType)
{
if (publicType.basicType == EbtSampler)
return defaultSamplerPrecision[computeSamplerTypeIndex(publicType.sampler)];
else
return defaultPrecision[publicType.basicType];
}
void TParseContext::precisionQualifierCheck(const TSourceLoc& loc, TBasicType baseType, TQualifier& qualifier, bool isCoopMat)
{
// Built-in symbols are allowed some ambiguous precisions, to be pinned down
// later by context.
if (! obeyPrecisionQualifiers() || parsingBuiltins)
return;
if (baseType == EbtAtomicUint && qualifier.precision != EpqNone && qualifier.precision != EpqHigh)
error(loc, "atomic counters can only be highp", "atomic_uint", "");
if (isCoopMat)
return;
if (baseType == EbtFloat || baseType == EbtUint || baseType == EbtInt || baseType == EbtSampler || baseType == EbtAtomicUint) {
if (qualifier.precision == EpqNone) {
if (relaxedErrors())
warn(loc, "type requires declaration of default precision qualifier", TType::getBasicString(baseType), "substituting 'mediump'");
else
error(loc, "type requires declaration of default precision qualifier", TType::getBasicString(baseType), "");
qualifier.precision = EpqMedium;
defaultPrecision[baseType] = EpqMedium;
}
} else if (qualifier.precision != EpqNone)
error(loc, "type cannot have precision qualifier", TType::getBasicString(baseType), "");
}
void TParseContext::parameterTypeCheck(const TSourceLoc& loc, TStorageQualifier qualifier, const TType& type)
{
if ((qualifier == EvqOut || qualifier == EvqInOut) && type.isOpaque() && !intermediate.getBindlessMode())
error(loc, "samplers and atomic_uints cannot be output parameters", type.getBasicTypeString().c_str(), "");
if (!parsingBuiltins && type.contains16BitFloat())
requireFloat16Arithmetic(loc, type.getBasicTypeString().c_str(), "float16 types can only be in uniform block or buffer storage");
if (!parsingBuiltins && type.contains16BitInt())
requireInt16Arithmetic(loc, type.getBasicTypeString().c_str(), "(u)int16 types can only be in uniform block or buffer storage");
if (!parsingBuiltins && type.contains8BitInt())
requireInt8Arithmetic(loc, type.getBasicTypeString().c_str(), "(u)int8 types can only be in uniform block or buffer storage");
}
bool TParseContext::containsFieldWithBasicType(const TType& type, TBasicType basicType)
{
if (type.getBasicType() == basicType)
return true;
if (type.getBasicType() == EbtStruct) {
const TTypeList& structure = *type.getStruct();
for (unsigned int i = 0; i < structure.size(); ++i) {
if (containsFieldWithBasicType(*structure[i].type, basicType))
return true;
}
}
return false;
}
//
// Do size checking for an array type's size.
//
void TParseContext::arraySizeCheck(const TSourceLoc& loc, TIntermTyped* expr, TArraySize& sizePair,
const char* sizeType, const bool allowZero)
{
bool isConst = false;
sizePair.node = nullptr;
int size = 1;
TIntermConstantUnion* constant = expr->getAsConstantUnion();
if (constant) {
// handle true (non-specialization) constant
size = constant->getConstArray()[0].getIConst();
isConst = true;
} else {
// see if it's a specialization constant instead
if (expr->getQualifier().isSpecConstant()) {
isConst = true;
sizePair.node = expr;
TIntermSymbol* symbol = expr->getAsSymbolNode();
if (symbol && symbol->getConstArray().size() > 0)
size = symbol->getConstArray()[0].getIConst();
} else if (expr->getAsUnaryNode() && expr->getAsUnaryNode()->getOp() == glslang::EOpArrayLength &&
expr->getAsUnaryNode()->getOperand()->getType().isCoopMatNV()) {
isConst = true;
size = 1;
sizePair.node = expr->getAsUnaryNode();
}
}
sizePair.size = size;
if (! isConst || (expr->getBasicType() != EbtInt && expr->getBasicType() != EbtUint)) {
error(loc, sizeType, "", "must be a constant integer expression");
return;
}
if (allowZero) {
if (size < 0) {
error(loc, sizeType, "", "must be a non-negative integer");
return;
}
} else {
if (size <= 0) {
error(loc, sizeType, "", "must be a positive integer");
return;
}
}
}
//
// See if this qualifier can be an array.
//
// Returns true if there is an error.
//
bool TParseContext::arrayQualifierError(const TSourceLoc& loc, const TQualifier& qualifier)
{
if (qualifier.storage == EvqConst) {
profileRequires(loc, ENoProfile, 120, E_GL_3DL_array_objects, "const array");
profileRequires(loc, EEsProfile, 300, nullptr, "const array");
}
if (qualifier.storage == EvqVaryingIn && language == EShLangVertex) {
requireProfile(loc, ~EEsProfile, "vertex input arrays");
profileRequires(loc, ENoProfile, 150, nullptr, "vertex input arrays");
}
return false;
}
//
// See if this qualifier and type combination can be an array.
// Assumes arrayQualifierError() was also called to catch the type-invariant tests.
//
// Returns true if there is an error.
//
bool TParseContext::arrayError(const TSourceLoc& loc, const TType& type)
{
if (type.getQualifier().storage == EvqVaryingOut && language == EShLangVertex) {
if (type.isArrayOfArrays())
requireProfile(loc, ~EEsProfile, "vertex-shader array-of-array output");
else if (type.isStruct())
requireProfile(loc, ~EEsProfile, "vertex-shader array-of-struct output");
}
if (type.getQualifier().storage == EvqVaryingIn && language == EShLangFragment) {
if (type.isArrayOfArrays())
requireProfile(loc, ~EEsProfile, "fragment-shader array-of-array input");
else if (type.isStruct())
requireProfile(loc, ~EEsProfile, "fragment-shader array-of-struct input");
}
if (type.getQualifier().storage == EvqVaryingOut && language == EShLangFragment) {
if (type.isArrayOfArrays())
requireProfile(loc, ~EEsProfile, "fragment-shader array-of-array output");
}
return false;
}
//
// Require array to be completely sized
//
void TParseContext::arraySizeRequiredCheck(const TSourceLoc& loc, const TArraySizes& arraySizes)
{
if (!parsingBuiltins && arraySizes.hasUnsized())
error(loc, "array size required", "", "");
}
void TParseContext::structArrayCheck(const TSourceLoc& /*loc*/, const TType& type)
{
const TTypeList& structure = *type.getStruct();
for (int m = 0; m < (int)structure.size(); ++m) {
const TType& member = *structure[m].type;
if (member.isArray())
arraySizeRequiredCheck(structure[m].loc, *member.getArraySizes());
}
}
void TParseContext::arraySizesCheck(const TSourceLoc& loc, const TQualifier& qualifier, TArraySizes* arraySizes,
const TIntermTyped* initializer, bool lastMember)
{
assert(arraySizes);
// always allow special built-in ins/outs sized to topologies
if (parsingBuiltins)
return;
// initializer must be a sized array, in which case
// allow the initializer to set any unknown array sizes
if (initializer != nullptr) {
if (initializer->getType().isUnsizedArray())
error(loc, "array initializer must be sized", "[]", "");
return;
}
// No environment allows any non-outer-dimension to be implicitly sized
if (arraySizes->isInnerUnsized()) {
error(loc, "only outermost dimension of an array of arrays can be implicitly sized", "[]", "");
arraySizes->clearInnerUnsized();
}
if (arraySizes->isInnerSpecialization() &&
(qualifier.storage != EvqTemporary && qualifier.storage != EvqGlobal && qualifier.storage != EvqShared && qualifier.storage != EvqConst))
error(loc, "only outermost dimension of an array of arrays can be a specialization constant", "[]", "");
// desktop always allows outer-dimension-unsized variable arrays,
if (!isEsProfile())
return;
// for ES, if size isn't coming from an initializer, it has to be explicitly declared now,
// with very few exceptions
// implicitly-sized io exceptions:
switch (language) {
case EShLangGeometry:
if (qualifier.storage == EvqVaryingIn)
if ((isEsProfile() && version >= 320) ||
extensionsTurnedOn(Num_AEP_geometry_shader, AEP_geometry_shader))
return;
break;
case EShLangTessControl:
if ( qualifier.storage == EvqVaryingIn ||
(qualifier.storage == EvqVaryingOut && ! qualifier.isPatch()))
if ((isEsProfile() && version >= 320) ||
extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))
return;
break;
case EShLangTessEvaluation:
if ((qualifier.storage == EvqVaryingIn && ! qualifier.isPatch()) ||
qualifier.storage == EvqVaryingOut)
if ((isEsProfile() && version >= 320) ||
extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))
return;
break;
case EShLangMesh:
if (qualifier.storage == EvqVaryingOut)
if ((isEsProfile() && version >= 320) ||
extensionsTurnedOn(Num_AEP_mesh_shader, AEP_mesh_shader))
return;
break;
default:
break;
}
// last member of ssbo block exception:
if (qualifier.storage == EvqBuffer && lastMember)
return;
arraySizeRequiredCheck(loc, *arraySizes);
}
void TParseContext::arrayOfArrayVersionCheck(const TSourceLoc& loc, const TArraySizes* sizes)
{
if (sizes == nullptr || sizes->getNumDims() == 1)
return;
const char* feature = "arrays of arrays";
requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, feature);
profileRequires(loc, EEsProfile, 310, nullptr, feature);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 430, nullptr, feature);
}
//
// Do all the semantic checking for declaring or redeclaring an array, with and
// without a size, and make the right changes to the symbol table.
//
void TParseContext::declareArray(const TSourceLoc& loc, const TString& identifier, const TType& type, TSymbol*& symbol)
{
if (symbol == nullptr) {
bool currentScope;
symbol = symbolTable.find(identifier, nullptr, ¤tScope);
if (symbol && builtInName(identifier) && ! symbolTable.atBuiltInLevel()) {
// bad shader (errors already reported) trying to redeclare a built-in name as an array
symbol = nullptr;
return;
}
if (symbol == nullptr || ! currentScope) {
//
// Successfully process a new definition.
// (Redeclarations have to take place at the same scope; otherwise they are hiding declarations)
//
symbol = new TVariable(&identifier, type);
symbolTable.insert(*symbol);
if (symbolTable.atGlobalLevel())
trackLinkage(*symbol);
if (! symbolTable.atBuiltInLevel()) {
if (isIoResizeArray(type)) {
ioArraySymbolResizeList.push_back(symbol);
checkIoArraysConsistency(loc, true);
} else
fixIoArraySize(loc, symbol->getWritableType());
}
return;
}
if (symbol->getAsAnonMember()) {
error(loc, "cannot redeclare a user-block member array", identifier.c_str(), "");
symbol = nullptr;
return;
}
}
//
// Process a redeclaration.
//
if (symbol == nullptr) {
error(loc, "array variable name expected", identifier.c_str(), "");
return;
}
// redeclareBuiltinVariable() should have already done the copyUp()
TType& existingType = symbol->getWritableType();
if (! existingType.isArray()) {
error(loc, "redeclaring non-array as array", identifier.c_str(), "");
return;
}
if (! existingType.sameElementType(type)) {
error(loc, "redeclaration of array with a different element type", identifier.c_str(), "");
return;
}
if (! existingType.sameInnerArrayness(type)) {
error(loc, "redeclaration of array with a different array dimensions or sizes", identifier.c_str(), "");
return;
}
if (existingType.isSizedArray()) {
// be more leniant for input arrays to geometry shaders and tessellation control outputs, where the redeclaration is the same size
if (! (isIoResizeArray(type) && existingType.getOuterArraySize() == type.getOuterArraySize()))
error(loc, "redeclaration of array with size", identifier.c_str(), "");
return;
}
arrayLimitCheck(loc, identifier, type.getOuterArraySize());
existingType.updateArraySizes(type);
if (isIoResizeArray(type))
checkIoArraysConsistency(loc);
}
// Policy and error check for needing a runtime sized array.
void TParseContext::checkRuntimeSizable(const TSourceLoc& loc, const TIntermTyped& base)
{
// runtime length implies runtime sizeable, so no problem
if (isRuntimeLength(base))
return;
if (base.getType().getQualifier().builtIn == EbvSampleMask)
return;
// Check for last member of a bufferreference type, which is runtime sizeable
// but doesn't support runtime length
if (base.getType().getQualifier().storage == EvqBuffer) {
const TIntermBinary* binary = base.getAsBinaryNode();
if (binary != nullptr &&
binary->getOp() == EOpIndexDirectStruct &&
binary->getLeft()->isReference()) {
const int index = binary->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst();
const int memberCount = (int)binary->getLeft()->getType().getReferentType()->getStruct()->size();
if (index == memberCount - 1)
return;
}
}
// check for additional things allowed by GL_EXT_nonuniform_qualifier
if (base.getBasicType() == EbtSampler || base.getBasicType() == EbtAccStruct || base.getBasicType() == EbtRayQuery ||
base.getBasicType() == EbtHitObjectNV || (base.getBasicType() == EbtBlock && base.getType().getQualifier().isUniformOrBuffer()))
requireExtensions(loc, 1, &E_GL_EXT_nonuniform_qualifier, "variable index");
else
error(loc, "", "[", "array must be redeclared with a size before being indexed with a variable");
}
// Policy decision for whether a run-time .length() is allowed.
bool TParseContext::isRuntimeLength(const TIntermTyped& base) const
{
if (base.getType().getQualifier().storage == EvqBuffer) {
// in a buffer block
const TIntermBinary* binary = base.getAsBinaryNode();
if (binary != nullptr && binary->getOp() == EOpIndexDirectStruct) {
// is it the last member?
const int index = binary->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst();
if (binary->getLeft()->isReference())
return false;
const int memberCount = (int)binary->getLeft()->getType().getStruct()->size();
if (index == memberCount - 1)
return true;
}
}
return false;
}
// Check if mesh perviewNV attributes have a view dimension
// and resize it to gl_MaxMeshViewCountNV when implicitly sized.
void TParseContext::checkAndResizeMeshViewDim(const TSourceLoc& loc, TType& type, bool isBlockMember)
{
// see if member is a per-view attribute
if (!type.getQualifier().isPerView())
return;
if ((isBlockMember && type.isArray()) || (!isBlockMember && type.isArrayOfArrays())) {
// since we don't have the maxMeshViewCountNV set during parsing builtins, we hardcode the value.
int maxViewCount = parsingBuiltins ? 4 : resources.maxMeshViewCountNV;
// For block members, outermost array dimension is the view dimension.
// For non-block members, outermost array dimension is the vertex/primitive dimension
// and 2nd outermost is the view dimension.
int viewDim = isBlockMember ? 0 : 1;
int viewDimSize = type.getArraySizes()->getDimSize(viewDim);
if (viewDimSize != UnsizedArraySize && viewDimSize != maxViewCount)
error(loc, "mesh view output array size must be gl_MaxMeshViewCountNV or implicitly sized", "[]", "");
else if (viewDimSize == UnsizedArraySize)
type.getArraySizes()->setDimSize(viewDim, maxViewCount);
}
else {
error(loc, "requires a view array dimension", "perviewNV", "");
}
}
// Returns true if the first argument to the #line directive is the line number for the next line.
//
// Desktop, pre-version 3.30: "After processing this directive
// (including its new-line), the implementation will behave as if it is compiling at line number line+1 and
// source string number source-string-number."
//
// Desktop, version 3.30 and later, and ES: "After processing this directive
// (including its new-line), the implementation will behave as if it is compiling at line number line and
// source string number source-string-number.
bool TParseContext::lineDirectiveShouldSetNextLine() const
{
return isEsProfile() || version >= 330;
}
//
// Enforce non-initializer type/qualifier rules.
//
void TParseContext::nonInitConstCheck(const TSourceLoc& loc, TString& identifier, TType& type)
{
//
// Make the qualifier make sense, given that there is not an initializer.
//
if (type.getQualifier().storage == EvqConst ||
type.getQualifier().storage == EvqConstReadOnly) {
type.getQualifier().makeTemporary();
error(loc, "variables with qualifier 'const' must be initialized", identifier.c_str(), "");
}
}
//
// See if the identifier is a built-in symbol that can be redeclared, and if so,
// copy the symbol table's read-only built-in variable to the current
// global level, where it can be modified based on the passed in type.
//
// Returns nullptr if no redeclaration took place; meaning a normal declaration still
// needs to occur for it, not necessarily an error.
//
// Returns a redeclared and type-modified variable if a redeclarated occurred.
//
TSymbol* TParseContext::redeclareBuiltinVariable(const TSourceLoc& loc, const TString& identifier,
const TQualifier& qualifier, const TShaderQualifiers& publicType)
{
if (! builtInName(identifier) || symbolTable.atBuiltInLevel() || ! symbolTable.atGlobalLevel())
return nullptr;
bool nonEsRedecls = (!isEsProfile() && (version >= 130 || identifier == "gl_TexCoord"));
bool esRedecls = (isEsProfile() &&
(version >= 320 || extensionsTurnedOn(Num_AEP_shader_io_blocks, AEP_shader_io_blocks)));
if (! esRedecls && ! nonEsRedecls)
return nullptr;
// Special case when using GL_ARB_separate_shader_objects
bool ssoPre150 = false; // means the only reason this variable is redeclared is due to this combination
if (!isEsProfile() && version <= 140 && extensionTurnedOn(E_GL_ARB_separate_shader_objects)) {
if (identifier == "gl_Position" ||
identifier == "gl_PointSize" ||
identifier == "gl_ClipVertex" ||
identifier == "gl_FogFragCoord")
ssoPre150 = true;
}
// Potentially redeclaring a built-in variable...
if (ssoPre150 ||
(identifier == "gl_FragDepth" && ((nonEsRedecls && version >= 420) || esRedecls)) ||
(identifier == "gl_FragCoord" && ((nonEsRedecls && version >= 140) || esRedecls)) ||
identifier == "gl_ClipDistance" ||
identifier == "gl_CullDistance" ||
identifier == "gl_ShadingRateEXT" ||
identifier == "gl_PrimitiveShadingRateEXT" ||
identifier == "gl_FrontColor" ||
identifier == "gl_BackColor" ||
identifier == "gl_FrontSecondaryColor" ||
identifier == "gl_BackSecondaryColor" ||
identifier == "gl_SecondaryColor" ||
(identifier == "gl_Color" && language == EShLangFragment) ||
(identifier == "gl_FragStencilRefARB" && (nonEsRedecls && version >= 140)
&& language == EShLangFragment) ||
identifier == "gl_SampleMask" ||
identifier == "gl_Layer" ||
identifier == "gl_PrimitiveIndicesNV" ||
identifier == "gl_PrimitivePointIndicesEXT" ||
identifier == "gl_PrimitiveLineIndicesEXT" ||
identifier == "gl_PrimitiveTriangleIndicesEXT" ||
identifier == "gl_TexCoord") {
// Find the existing symbol, if any.
bool builtIn;
TSymbol* symbol = symbolTable.find(identifier, &builtIn);
// If the symbol was not found, this must be a version/profile/stage
// that doesn't have it.
if (! symbol)
return nullptr;
// If it wasn't at a built-in level, then it's already been redeclared;
// that is, this is a redeclaration of a redeclaration; reuse that initial
// redeclaration. Otherwise, make the new one.
if (builtIn) {
makeEditable(symbol);
symbolTable.amendSymbolIdLevel(*symbol);
}
// Now, modify the type of the copy, as per the type of the current redeclaration.
TQualifier& symbolQualifier = symbol->getWritableType().getQualifier();
if (ssoPre150) {
if (intermediate.inIoAccessed(identifier))
error(loc, "cannot redeclare after use", identifier.c_str(), "");
if (qualifier.hasLayout())
error(loc, "cannot apply layout qualifier to", "redeclaration", symbol->getName().c_str());
if (qualifier.isMemory() || qualifier.isAuxiliary() || (language == EShLangVertex && qualifier.storage != EvqVaryingOut) ||
(language == EShLangFragment && qualifier.storage != EvqVaryingIn))
error(loc, "cannot change storage, memory, or auxiliary qualification of", "redeclaration", symbol->getName().c_str());
if (! qualifier.smooth)
error(loc, "cannot change interpolation qualification of", "redeclaration", symbol->getName().c_str());
} else if (identifier == "gl_FrontColor" ||
identifier == "gl_BackColor" ||
identifier == "gl_FrontSecondaryColor" ||
identifier == "gl_BackSecondaryColor" ||
identifier == "gl_SecondaryColor" ||
identifier == "gl_Color") {
symbolQualifier.flat = qualifier.flat;
symbolQualifier.smooth = qualifier.smooth;
symbolQualifier.nopersp = qualifier.nopersp;
if (qualifier.hasLayout())
error(loc, "cannot apply layout qualifier to", "redeclaration", symbol->getName().c_str());
if (qualifier.isMemory() || qualifier.isAuxiliary() || symbol->getType().getQualifier().storage != qualifier.storage)
error(loc, "cannot change storage, memory, or auxiliary qualification of", "redeclaration", symbol->getName().c_str());
} else if (identifier == "gl_TexCoord" ||
identifier == "gl_ClipDistance" ||
identifier == "gl_CullDistance") {
if (qualifier.hasLayout() || qualifier.isMemory() || qualifier.isAuxiliary() ||
qualifier.nopersp != symbolQualifier.nopersp || qualifier.flat != symbolQualifier.flat ||
symbolQualifier.storage != qualifier.storage)
error(loc, "cannot change qualification of", "redeclaration", symbol->getName().c_str());
} else if (identifier == "gl_FragCoord") {
if (!intermediate.getTexCoordRedeclared() && intermediate.inIoAccessed("gl_FragCoord"))
error(loc, "cannot redeclare after use", "gl_FragCoord", "");
if (qualifier.nopersp != symbolQualifier.nopersp || qualifier.flat != symbolQualifier.flat ||
qualifier.isMemory() || qualifier.isAuxiliary())
error(loc, "can only change layout qualification of", "redeclaration", symbol->getName().c_str());
if (qualifier.storage != EvqVaryingIn)
error(loc, "cannot change input storage qualification of", "redeclaration", symbol->getName().c_str());
if (! builtIn && (publicType.pixelCenterInteger != intermediate.getPixelCenterInteger() ||
publicType.originUpperLeft != intermediate.getOriginUpperLeft()))
error(loc, "cannot redeclare with different qualification:", "redeclaration", symbol->getName().c_str());
intermediate.setTexCoordRedeclared();
if (publicType.pixelCenterInteger)
intermediate.setPixelCenterInteger();
if (publicType.originUpperLeft)
intermediate.setOriginUpperLeft();
} else if (identifier == "gl_FragDepth") {
if (qualifier.nopersp != symbolQualifier.nopersp || qualifier.flat != symbolQualifier.flat ||
qualifier.isMemory() || qualifier.isAuxiliary())
error(loc, "can only change layout qualification of", "redeclaration", symbol->getName().c_str());
if (qualifier.storage != EvqVaryingOut)
error(loc, "cannot change output storage qualification of", "redeclaration", symbol->getName().c_str());
if (publicType.layoutDepth != EldNone) {
if (intermediate.inIoAccessed("gl_FragDepth"))
error(loc, "cannot redeclare after use", "gl_FragDepth", "");
if (! intermediate.setDepth(publicType.layoutDepth))
error(loc, "all redeclarations must use the same depth layout on", "redeclaration", symbol->getName().c_str());
}
} else if (identifier == "gl_FragStencilRefARB") {
if (qualifier.nopersp != symbolQualifier.nopersp || qualifier.flat != symbolQualifier.flat ||
qualifier.isMemory() || qualifier.isAuxiliary())
error(loc, "can only change layout qualification of", "redeclaration", symbol->getName().c_str());
if (qualifier.storage != EvqVaryingOut)
error(loc, "cannot change output storage qualification of", "redeclaration", symbol->getName().c_str());
if (publicType.layoutStencil != ElsNone) {
if (intermediate.inIoAccessed("gl_FragStencilRefARB"))
error(loc, "cannot redeclare after use", "gl_FragStencilRefARB", "");
if (!intermediate.setStencil(publicType.layoutStencil))
error(loc, "all redeclarations must use the same stencil layout on", "redeclaration",
symbol->getName().c_str());
}
}
else if (
identifier == "gl_PrimitiveIndicesNV") {
if (qualifier.hasLayout())
error(loc, "cannot apply layout qualifier to", "redeclaration", symbol->getName().c_str());
if (qualifier.storage != EvqVaryingOut)
error(loc, "cannot change output storage qualification of", "redeclaration", symbol->getName().c_str());
}
else if (identifier == "gl_SampleMask") {
if (!publicType.layoutOverrideCoverage) {
error(loc, "redeclaration only allowed for override_coverage layout", "redeclaration", symbol->getName().c_str());
}
intermediate.setLayoutOverrideCoverage();
}
else if (identifier == "gl_Layer") {
if (!qualifier.layoutViewportRelative && qualifier.layoutSecondaryViewportRelativeOffset == -2048)
error(loc, "redeclaration only allowed for viewport_relative or secondary_view_offset layout", "redeclaration", symbol->getName().c_str());
symbolQualifier.layoutViewportRelative = qualifier.layoutViewportRelative;
symbolQualifier.layoutSecondaryViewportRelativeOffset = qualifier.layoutSecondaryViewportRelativeOffset;
}
// TODO: semantics quality: separate smooth from nothing declared, then use IsInterpolation for several tests above
return symbol;
}
return nullptr;
}
//
// Either redeclare the requested block, or give an error message why it can't be done.
//
// TODO: functionality: explicitly sizing members of redeclared blocks is not giving them an explicit size
void TParseContext::redeclareBuiltinBlock(const TSourceLoc& loc, TTypeList& newTypeList, const TString& blockName,
const TString* instanceName, TArraySizes* arraySizes)
{
const char* feature = "built-in block redeclaration";
profileRequires(loc, EEsProfile, 320, Num_AEP_shader_io_blocks, AEP_shader_io_blocks, feature);
profileRequires(loc, ~EEsProfile, 410, E_GL_ARB_separate_shader_objects, feature);
if (blockName != "gl_PerVertex" && blockName != "gl_PerFragment" &&
blockName != "gl_MeshPerVertexNV" && blockName != "gl_MeshPerPrimitiveNV" &&
blockName != "gl_MeshPerVertexEXT" && blockName != "gl_MeshPerPrimitiveEXT") {
error(loc, "cannot redeclare block: ", "block declaration", blockName.c_str());
return;
}
// Redeclaring a built-in block...
if (instanceName && ! builtInName(*instanceName)) {
error(loc, "cannot redeclare a built-in block with a user name", instanceName->c_str(), "");
return;
}
// Blocks with instance names are easy to find, lookup the instance name,
// Anonymous blocks need to be found via a member.
bool builtIn;
TSymbol* block;
if (instanceName)
block = symbolTable.find(*instanceName, &builtIn);
else
block = symbolTable.find(newTypeList.front().type->getFieldName(), &builtIn);
// If the block was not found, this must be a version/profile/stage
// that doesn't have it, or the instance name is wrong.
const char* errorName = instanceName ? instanceName->c_str() : newTypeList.front().type->getFieldName().c_str();
if (! block) {
error(loc, "no declaration found for redeclaration", errorName, "");
return;
}
// Built-in blocks cannot be redeclared more than once, which if happened,
// we'd be finding the already redeclared one here, rather than the built in.
if (! builtIn) {
error(loc, "can only redeclare a built-in block once, and before any use", blockName.c_str(), "");
return;
}
// Copy the block to make a writable version, to insert into the block table after editing.
block = symbolTable.copyUpDeferredInsert(block);
if (block->getType().getBasicType() != EbtBlock) {
error(loc, "cannot redeclare a non block as a block", errorName, "");
return;
}
// Fix XFB stuff up, it applies to the order of the redeclaration, not
// the order of the original members.
if (currentBlockQualifier.storage == EvqVaryingOut && globalOutputDefaults.hasXfbBuffer()) {
if (!currentBlockQualifier.hasXfbBuffer())
currentBlockQualifier.layoutXfbBuffer = globalOutputDefaults.layoutXfbBuffer;
if (!currentBlockQualifier.hasStream())
currentBlockQualifier.layoutStream = globalOutputDefaults.layoutStream;
fixXfbOffsets(currentBlockQualifier, newTypeList);
}
// Edit and error check the container against the redeclaration
// - remove unused members
// - ensure remaining qualifiers/types match
TType& type = block->getWritableType();
// if gl_PerVertex is redeclared for the purpose of passing through "gl_Position"
// for passthrough purpose, the redeclared block should have the same qualifers as
// the current one
if (currentBlockQualifier.layoutPassthrough) {
type.getQualifier().layoutPassthrough = currentBlockQualifier.layoutPassthrough;
type.getQualifier().storage = currentBlockQualifier.storage;
type.getQualifier().layoutStream = currentBlockQualifier.layoutStream;
type.getQualifier().layoutXfbBuffer = currentBlockQualifier.layoutXfbBuffer;
}
TTypeList::iterator member = type.getWritableStruct()->begin();
size_t numOriginalMembersFound = 0;
while (member != type.getStruct()->end()) {
// look for match
bool found = false;
TTypeList::const_iterator newMember;
TSourceLoc memberLoc;
memberLoc.init();
for (newMember = newTypeList.begin(); newMember != newTypeList.end(); ++newMember) {
if (member->type->getFieldName() == newMember->type->getFieldName()) {
found = true;
memberLoc = newMember->loc;
break;
}
}
if (found) {
++numOriginalMembersFound;
// - ensure match between redeclared members' types
// - check for things that can't be changed
// - update things that can be changed
TType& oldType = *member->type;
const TType& newType = *newMember->type;
if (! newType.sameElementType(oldType))
error(memberLoc, "cannot redeclare block member with a different type", member->type->getFieldName().c_str(), "");
if (oldType.isArray() != newType.isArray())
error(memberLoc, "cannot change arrayness of redeclared block member", member->type->getFieldName().c_str(), "");
else if (! oldType.getQualifier().isPerView() && ! oldType.sameArrayness(newType) && oldType.isSizedArray())
error(memberLoc, "cannot change array size of redeclared block member", member->type->getFieldName().c_str(), "");
else if (! oldType.getQualifier().isPerView() && newType.isArray())
arrayLimitCheck(loc, member->type->getFieldName(), newType.getOuterArraySize());
if (oldType.getQualifier().isPerView() && ! newType.getQualifier().isPerView())
error(memberLoc, "missing perviewNV qualifier to redeclared block member", member->type->getFieldName().c_str(), "");
else if (! oldType.getQualifier().isPerView() && newType.getQualifier().isPerView())
error(memberLoc, "cannot add perviewNV qualifier to redeclared block member", member->type->getFieldName().c_str(), "");
else if (newType.getQualifier().isPerView()) {
if (oldType.getArraySizes()->getNumDims() != newType.getArraySizes()->getNumDims())
error(memberLoc, "cannot change arrayness of redeclared block member", member->type->getFieldName().c_str(), "");
else if (! newType.isUnsizedArray() && newType.getOuterArraySize() != resources.maxMeshViewCountNV)
error(loc, "mesh view output array size must be gl_MaxMeshViewCountNV or implicitly sized", "[]", "");
else if (newType.getArraySizes()->getNumDims() == 2) {
int innerDimSize = newType.getArraySizes()->getDimSize(1);
arrayLimitCheck(memberLoc, member->type->getFieldName(), innerDimSize);
oldType.getArraySizes()->setDimSize(1, innerDimSize);
}
}
if (oldType.getQualifier().isPerPrimitive() && ! newType.getQualifier().isPerPrimitive())
error(memberLoc, "missing perprimitiveNV qualifier to redeclared block member", member->type->getFieldName().c_str(), "");
else if (! oldType.getQualifier().isPerPrimitive() && newType.getQualifier().isPerPrimitive())
error(memberLoc, "cannot add perprimitiveNV qualifier to redeclared block member", member->type->getFieldName().c_str(), "");
if (newType.getQualifier().isMemory())
error(memberLoc, "cannot add memory qualifier to redeclared block member", member->type->getFieldName().c_str(), "");
if (newType.getQualifier().hasNonXfbLayout())
error(memberLoc, "cannot add non-XFB layout to redeclared block member", member->type->getFieldName().c_str(), "");
if (newType.getQualifier().patch)
error(memberLoc, "cannot add patch to redeclared block member", member->type->getFieldName().c_str(), "");
if (newType.getQualifier().hasXfbBuffer() &&
newType.getQualifier().layoutXfbBuffer != currentBlockQualifier.layoutXfbBuffer)
error(memberLoc, "member cannot contradict block (or what block inherited from global)", "xfb_buffer", "");
if (newType.getQualifier().hasStream() &&
newType.getQualifier().layoutStream != currentBlockQualifier.layoutStream)
error(memberLoc, "member cannot contradict block (or what block inherited from global)", "xfb_stream", "");
oldType.getQualifier().centroid = newType.getQualifier().centroid;
oldType.getQualifier().sample = newType.getQualifier().sample;
oldType.getQualifier().invariant = newType.getQualifier().invariant;
oldType.getQualifier().noContraction = newType.getQualifier().noContraction;
oldType.getQualifier().smooth = newType.getQualifier().smooth;
oldType.getQualifier().flat = newType.getQualifier().flat;
oldType.getQualifier().nopersp = newType.getQualifier().nopersp;
oldType.getQualifier().layoutXfbOffset = newType.getQualifier().layoutXfbOffset;
oldType.getQualifier().layoutXfbBuffer = newType.getQualifier().layoutXfbBuffer;
oldType.getQualifier().layoutXfbStride = newType.getQualifier().layoutXfbStride;
if (oldType.getQualifier().layoutXfbOffset != TQualifier::layoutXfbBufferEnd) {
// If any member has an xfb_offset, then the block's xfb_buffer inherents current xfb_buffer,
// and for xfb processing, the member needs it as well, along with xfb_stride.
type.getQualifier().layoutXfbBuffer = currentBlockQualifier.layoutXfbBuffer;
oldType.getQualifier().layoutXfbBuffer = currentBlockQualifier.layoutXfbBuffer;
}
if (oldType.isUnsizedArray() && newType.isSizedArray())
oldType.changeOuterArraySize(newType.getOuterArraySize());
// check and process the member's type, which will include managing xfb information
layoutTypeCheck(loc, oldType);
// go to next member
++member;
} else {
// For missing members of anonymous blocks that have been redeclared,
// hide the original (shared) declaration.
// Instance-named blocks can just have the member removed.
if (instanceName)
member = type.getWritableStruct()->erase(member);
else {
member->type->hideMember();
++member;
}
}
}
if (spvVersion.vulkan > 0) {
// ...then streams apply to built-in blocks, instead of them being only on stream 0
type.getQualifier().layoutStream = currentBlockQualifier.layoutStream;
}
if (numOriginalMembersFound < newTypeList.size())
error(loc, "block redeclaration has extra members", blockName.c_str(), "");
if (type.isArray() != (arraySizes != nullptr) ||
(type.isArray() && arraySizes != nullptr && type.getArraySizes()->getNumDims() != arraySizes->getNumDims()))
error(loc, "cannot change arrayness of redeclared block", blockName.c_str(), "");
else if (type.isArray()) {
// At this point, we know both are arrays and both have the same number of dimensions.
// It is okay for a built-in block redeclaration to be unsized, and keep the size of the
// original block declaration.
if (!arraySizes->isSized() && type.isSizedArray())
arraySizes->changeOuterSize(type.getOuterArraySize());
// And, okay to be giving a size to the array, by the redeclaration
if (!type.isSizedArray() && arraySizes->isSized())
type.changeOuterArraySize(arraySizes->getOuterSize());
// Now, they must match in all dimensions.
if (type.isSizedArray() && *type.getArraySizes() != *arraySizes)
error(loc, "cannot change array size of redeclared block", blockName.c_str(), "");
}
symbolTable.insert(*block);
// Check for general layout qualifier errors
layoutObjectCheck(loc, *block);
// Tracking for implicit sizing of array
if (isIoResizeArray(block->getType())) {
ioArraySymbolResizeList.push_back(block);
checkIoArraysConsistency(loc, true);
} else if (block->getType().isArray())
fixIoArraySize(loc, block->getWritableType());
// Save it in the AST for linker use.
trackLinkage(*block);
}
void TParseContext::paramCheckFixStorage(const TSourceLoc& loc, const TStorageQualifier& qualifier, TType& type)
{
switch (qualifier) {
case EvqConst:
case EvqConstReadOnly:
type.getQualifier().storage = EvqConstReadOnly;
break;
case EvqIn:
case EvqOut:
case EvqInOut:
case EvqTileImageEXT:
type.getQualifier().storage = qualifier;
break;
case EvqGlobal:
case EvqTemporary:
type.getQualifier().storage = EvqIn;
break;
default:
type.getQualifier().storage = EvqIn;
error(loc, "storage qualifier not allowed on function parameter", GetStorageQualifierString(qualifier), "");
break;
}
}
void TParseContext::paramCheckFix(const TSourceLoc& loc, const TQualifier& qualifier, TType& type)
{
if (qualifier.isMemory()) {
type.getQualifier().volatil = qualifier.volatil;
type.getQualifier().coherent = qualifier.coherent;
type.getQualifier().devicecoherent = qualifier.devicecoherent ;
type.getQualifier().queuefamilycoherent = qualifier.queuefamilycoherent;
type.getQualifier().workgroupcoherent = qualifier.workgroupcoherent;
type.getQualifier().subgroupcoherent = qualifier.subgroupcoherent;
type.getQualifier().shadercallcoherent = qualifier.shadercallcoherent;
type.getQualifier().nonprivate = qualifier.nonprivate;
type.getQualifier().readonly = qualifier.readonly;
type.getQualifier().writeonly = qualifier.writeonly;
type.getQualifier().restrict = qualifier.restrict;
}
if (qualifier.isAuxiliary() ||
qualifier.isInterpolation())
error(loc, "cannot use auxiliary or interpolation qualifiers on a function parameter", "", "");
if (qualifier.hasLayout())
error(loc, "cannot use layout qualifiers on a function parameter", "", "");
if (qualifier.invariant)
error(loc, "cannot use invariant qualifier on a function parameter", "", "");
if (qualifier.isNoContraction()) {
if (qualifier.isParamOutput())
type.getQualifier().setNoContraction();
else
warn(loc, "qualifier has no effect on non-output parameters", "precise", "");
}
if (qualifier.isNonUniform())
type.getQualifier().nonUniform = qualifier.nonUniform;
if (qualifier.isSpirvByReference())
type.getQualifier().setSpirvByReference();
if (qualifier.isSpirvLiteral()) {
if (type.getBasicType() == EbtFloat || type.getBasicType() == EbtInt || type.getBasicType() == EbtUint ||
type.getBasicType() == EbtBool)
type.getQualifier().setSpirvLiteral();
else
error(loc, "cannot use spirv_literal qualifier", type.getBasicTypeString().c_str(), "");
}
paramCheckFixStorage(loc, qualifier.storage, type);
}
void TParseContext::nestedBlockCheck(const TSourceLoc& loc)
{
if (structNestingLevel > 0 || blockNestingLevel > 0)
error(loc, "cannot nest a block definition inside a structure or block", "", "");
++blockNestingLevel;
}
void TParseContext::nestedStructCheck(const TSourceLoc& loc)
{
if (structNestingLevel > 0 || blockNestingLevel > 0)
error(loc, "cannot nest a structure definition inside a structure or block", "", "");
++structNestingLevel;
}
void TParseContext::arrayObjectCheck(const TSourceLoc& loc, const TType& type, const char* op)
{
// Some versions don't allow comparing arrays or structures containing arrays
if (type.containsArray()) {
profileRequires(loc, ENoProfile, 120, E_GL_3DL_array_objects, op);
profileRequires(loc, EEsProfile, 300, nullptr, op);
}
}
void TParseContext::opaqueCheck(const TSourceLoc& loc, const TType& type, const char* op)
{
if (containsFieldWithBasicType(type, EbtSampler) && !extensionTurnedOn(E_GL_ARB_bindless_texture))
error(loc, "can't use with samplers or structs containing samplers", op, "");
}
void TParseContext::referenceCheck(const TSourceLoc& loc, const TType& type, const char* op)
{
if (containsFieldWithBasicType(type, EbtReference))
error(loc, "can't use with reference types", op, "");
}
void TParseContext::storage16BitAssignmentCheck(const TSourceLoc& loc, const TType& type, const char* op)
{
if (type.getBasicType() == EbtStruct && containsFieldWithBasicType(type, EbtFloat16))
requireFloat16Arithmetic(loc, op, "can't use with structs containing float16");
if (type.isArray() && type.getBasicType() == EbtFloat16)
requireFloat16Arithmetic(loc, op, "can't use with arrays containing float16");
if (type.getBasicType() == EbtStruct && containsFieldWithBasicType(type, EbtInt16))
requireInt16Arithmetic(loc, op, "can't use with structs containing int16");
if (type.isArray() && type.getBasicType() == EbtInt16)
requireInt16Arithmetic(loc, op, "can't use with arrays containing int16");
if (type.getBasicType() == EbtStruct && containsFieldWithBasicType(type, EbtUint16))
requireInt16Arithmetic(loc, op, "can't use with structs containing uint16");
if (type.isArray() && type.getBasicType() == EbtUint16)
requireInt16Arithmetic(loc, op, "can't use with arrays containing uint16");
if (type.getBasicType() == EbtStruct && containsFieldWithBasicType(type, EbtInt8))
requireInt8Arithmetic(loc, op, "can't use with structs containing int8");
if (type.isArray() && type.getBasicType() == EbtInt8)
requireInt8Arithmetic(loc, op, "can't use with arrays containing int8");
if (type.getBasicType() == EbtStruct && containsFieldWithBasicType(type, EbtUint8))
requireInt8Arithmetic(loc, op, "can't use with structs containing uint8");
if (type.isArray() && type.getBasicType() == EbtUint8)
requireInt8Arithmetic(loc, op, "can't use with arrays containing uint8");
}
void TParseContext::specializationCheck(const TSourceLoc& loc, const TType& type, const char* op)
{
if (type.containsSpecializationSize())
error(loc, "can't use with types containing arrays sized with a specialization constant", op, "");
}
void TParseContext::structTypeCheck(const TSourceLoc& /*loc*/, TPublicType& publicType)
{
const TTypeList& typeList = *publicType.userDef->getStruct();
// fix and check for member storage qualifiers and types that don't belong within a structure
for (unsigned int member = 0; member < typeList.size(); ++member) {
TQualifier& memberQualifier = typeList[member].type->getQualifier();
const TSourceLoc& memberLoc = typeList[member].loc;
if (memberQualifier.isAuxiliary() ||
memberQualifier.isInterpolation() ||
(memberQualifier.storage != EvqTemporary && memberQualifier.storage != EvqGlobal))
error(memberLoc, "cannot use storage or interpolation qualifiers on structure members", typeList[member].type->getFieldName().c_str(), "");
if (memberQualifier.isMemory())
error(memberLoc, "cannot use memory qualifiers on structure members", typeList[member].type->getFieldName().c_str(), "");
if (memberQualifier.hasLayout()) {
error(memberLoc, "cannot use layout qualifiers on structure members", typeList[member].type->getFieldName().c_str(), "");
memberQualifier.clearLayout();
}
if (memberQualifier.invariant)
error(memberLoc, "cannot use invariant qualifier on structure members", typeList[member].type->getFieldName().c_str(), "");
}
}
//
// See if this loop satisfies the limitations for ES 2.0 (version 100) for loops in Appendex A:
//
// "The loop index has type int or float.
//
// "The for statement has the form:
// for ( init-declaration ; condition ; expression )
// init-declaration has the form: type-specifier identifier = constant-expression
// condition has the form: loop-index relational_operator constant-expression
// where relational_operator is one of: > >= < <= == or !=
// expression [sic] has one of the following forms:
// loop-index++
// loop-index--
// loop-index += constant-expression
// loop-index -= constant-expression
//
// The body is handled in an AST traversal.
//
void TParseContext::inductiveLoopCheck(const TSourceLoc& loc, TIntermNode* init, TIntermLoop* loop)
{
// loop index init must exist and be a declaration, which shows up in the AST as an aggregate of size 1 of the declaration
bool badInit = false;
if (! init || ! init->getAsAggregate() || init->getAsAggregate()->getSequence().size() != 1)
badInit = true;
TIntermBinary* binaryInit = nullptr;
if (! badInit) {
// get the declaration assignment
binaryInit = init->getAsAggregate()->getSequence()[0]->getAsBinaryNode();
if (! binaryInit)
badInit = true;
}
if (badInit) {
error(loc, "inductive-loop init-declaration requires the form \"type-specifier loop-index = constant-expression\"", "limitations", "");
return;
}
// loop index must be type int or float
if (! binaryInit->getType().isScalar() || (binaryInit->getBasicType() != EbtInt && binaryInit->getBasicType() != EbtFloat)) {
error(loc, "inductive loop requires a scalar 'int' or 'float' loop index", "limitations", "");
return;
}
// init is the form "loop-index = constant"
if (binaryInit->getOp() != EOpAssign || ! binaryInit->getLeft()->getAsSymbolNode() || ! binaryInit->getRight()->getAsConstantUnion()) {
error(loc, "inductive-loop init-declaration requires the form \"type-specifier loop-index = constant-expression\"", "limitations", "");
return;
}
// get the unique id of the loop index
long long loopIndex = binaryInit->getLeft()->getAsSymbolNode()->getId();
inductiveLoopIds.insert(loopIndex);
// condition's form must be "loop-index relational-operator constant-expression"
bool badCond = ! loop->getTest();
if (! badCond) {
TIntermBinary* binaryCond = loop->getTest()->getAsBinaryNode();
badCond = ! binaryCond;
if (! badCond) {
switch (binaryCond->getOp()) {
case EOpGreaterThan:
case EOpGreaterThanEqual:
case EOpLessThan:
case EOpLessThanEqual:
case EOpEqual:
case EOpNotEqual:
break;
default:
badCond = true;
}
}
if (binaryCond && (! binaryCond->getLeft()->getAsSymbolNode() ||
binaryCond->getLeft()->getAsSymbolNode()->getId() != loopIndex ||
! binaryCond->getRight()->getAsConstantUnion()))
badCond = true;
}
if (badCond) {
error(loc, "inductive-loop condition requires the form \"loop-index <comparison-op> constant-expression\"", "limitations", "");
return;
}
// loop-index++
// loop-index--
// loop-index += constant-expression
// loop-index -= constant-expression
bool badTerminal = ! loop->getTerminal();
if (! badTerminal) {
TIntermUnary* unaryTerminal = loop->getTerminal()->getAsUnaryNode();
TIntermBinary* binaryTerminal = loop->getTerminal()->getAsBinaryNode();
if (unaryTerminal || binaryTerminal) {
switch(loop->getTerminal()->getAsOperator()->getOp()) {
case EOpPostDecrement:
case EOpPostIncrement:
case EOpAddAssign:
case EOpSubAssign:
break;
default:
badTerminal = true;
}
} else
badTerminal = true;
if (binaryTerminal && (! binaryTerminal->getLeft()->getAsSymbolNode() ||
binaryTerminal->getLeft()->getAsSymbolNode()->getId() != loopIndex ||
! binaryTerminal->getRight()->getAsConstantUnion()))
badTerminal = true;
if (unaryTerminal && (! unaryTerminal->getOperand()->getAsSymbolNode() ||
unaryTerminal->getOperand()->getAsSymbolNode()->getId() != loopIndex))
badTerminal = true;
}
if (badTerminal) {
error(loc, "inductive-loop termination requires the form \"loop-index++, loop-index--, loop-index += constant-expression, or loop-index -= constant-expression\"", "limitations", "");
return;
}
// the body
inductiveLoopBodyCheck(loop->getBody(), loopIndex, symbolTable);
}
// Do limit checks for built-in arrays.
void TParseContext::arrayLimitCheck(const TSourceLoc& loc, const TString& identifier, int size)
{
if (identifier.compare("gl_TexCoord") == 0)
limitCheck(loc, size, "gl_MaxTextureCoords", "gl_TexCoord array size");
else if (identifier.compare("gl_ClipDistance") == 0)
limitCheck(loc, size, "gl_MaxClipDistances", "gl_ClipDistance array size");
else if (identifier.compare("gl_CullDistance") == 0)
limitCheck(loc, size, "gl_MaxCullDistances", "gl_CullDistance array size");
else if (identifier.compare("gl_ClipDistancePerViewNV") == 0)
limitCheck(loc, size, "gl_MaxClipDistances", "gl_ClipDistancePerViewNV array size");
else if (identifier.compare("gl_CullDistancePerViewNV") == 0)
limitCheck(loc, size, "gl_MaxCullDistances", "gl_CullDistancePerViewNV array size");
}
// See if the provided value is less than or equal to the symbol indicated by limit,
// which should be a constant in the symbol table.
void TParseContext::limitCheck(const TSourceLoc& loc, int value, const char* limit, const char* feature)
{
TSymbol* symbol = symbolTable.find(limit);
assert(symbol->getAsVariable());
const TConstUnionArray& constArray = symbol->getAsVariable()->getConstArray();
assert(! constArray.empty());
if (value > constArray[0].getIConst())
error(loc, "must be less than or equal to", feature, "%s (%d)", limit, constArray[0].getIConst());
}
//
// Do any additional error checking, etc., once we know the parsing is done.
//
void TParseContext::finish()
{
TParseContextBase::finish();
if (parsingBuiltins)
return;
// Check on array indexes for ES 2.0 (version 100) limitations.
for (size_t i = 0; i < needsIndexLimitationChecking.size(); ++i)
constantIndexExpressionCheck(needsIndexLimitationChecking[i]);
// Check for stages that are enabled by extension.
// Can't do this at the beginning, it is chicken and egg to add a stage by
// extension.
// Stage-specific features were correctly tested for already, this is just
// about the stage itself.
switch (language) {
case EShLangGeometry:
if (isEsProfile() && version == 310)
requireExtensions(getCurrentLoc(), Num_AEP_geometry_shader, AEP_geometry_shader, "geometry shaders");
break;
case EShLangTessControl:
case EShLangTessEvaluation:
if (isEsProfile() && version == 310)
requireExtensions(getCurrentLoc(), Num_AEP_tessellation_shader, AEP_tessellation_shader, "tessellation shaders");
else if (!isEsProfile() && version < 400)
requireExtensions(getCurrentLoc(), 1, &E_GL_ARB_tessellation_shader, "tessellation shaders");
break;
case EShLangCompute:
if (!isEsProfile() && version < 430)
requireExtensions(getCurrentLoc(), 1, &E_GL_ARB_compute_shader, "compute shaders");
break;
case EShLangTask:
requireExtensions(getCurrentLoc(), Num_AEP_mesh_shader, AEP_mesh_shader, "task shaders");
break;
case EShLangMesh:
requireExtensions(getCurrentLoc(), Num_AEP_mesh_shader, AEP_mesh_shader, "mesh shaders");
break;
default:
break;
}
// Set default outputs for GL_NV_geometry_shader_passthrough
if (language == EShLangGeometry && extensionTurnedOn(E_SPV_NV_geometry_shader_passthrough)) {
if (intermediate.getOutputPrimitive() == ElgNone) {
switch (intermediate.getInputPrimitive()) {
case ElgPoints: intermediate.setOutputPrimitive(ElgPoints); break;
case ElgLines: intermediate.setOutputPrimitive(ElgLineStrip); break;
case ElgTriangles: intermediate.setOutputPrimitive(ElgTriangleStrip); break;
default: break;
}
}
if (intermediate.getVertices() == TQualifier::layoutNotSet) {
switch (intermediate.getInputPrimitive()) {
case ElgPoints: intermediate.setVertices(1); break;
case ElgLines: intermediate.setVertices(2); break;
case ElgTriangles: intermediate.setVertices(3); break;
default: break;
}
}
}
}
//
// Layout qualifier stuff.
//
// Put the id's layout qualification into the public type, for qualifiers not having a number set.
// This is before we know any type information for error checking.
void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publicType, TString& id)
{
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
if (id == TQualifier::getLayoutMatrixString(ElmColumnMajor)) {
publicType.qualifier.layoutMatrix = ElmColumnMajor;
return;
}
if (id == TQualifier::getLayoutMatrixString(ElmRowMajor)) {
publicType.qualifier.layoutMatrix = ElmRowMajor;
return;
}
if (id == TQualifier::getLayoutPackingString(ElpPacked)) {
if (spvVersion.spv != 0) {
if (spvVersion.vulkanRelaxed)
return; // silently ignore qualifier
else
spvRemoved(loc, "packed");
}
publicType.qualifier.layoutPacking = ElpPacked;
return;
}
if (id == TQualifier::getLayoutPackingString(ElpShared)) {
if (spvVersion.spv != 0) {
if (spvVersion.vulkanRelaxed)
return; // silently ignore qualifier
else
spvRemoved(loc, "shared");
}
publicType.qualifier.layoutPacking = ElpShared;
return;
}
if (id == TQualifier::getLayoutPackingString(ElpStd140)) {
publicType.qualifier.layoutPacking = ElpStd140;
return;
}
if (id == TQualifier::getLayoutPackingString(ElpStd430)) {
requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, "std430");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 430, E_GL_ARB_shader_storage_buffer_object, "std430");
profileRequires(loc, EEsProfile, 310, nullptr, "std430");
publicType.qualifier.layoutPacking = ElpStd430;
return;
}
if (id == TQualifier::getLayoutPackingString(ElpScalar)) {
requireVulkan(loc, "scalar");
requireExtensions(loc, 1, &E_GL_EXT_scalar_block_layout, "scalar block layout");
publicType.qualifier.layoutPacking = ElpScalar;
return;
}
// TODO: compile-time performance: may need to stop doing linear searches
for (TLayoutFormat format = (TLayoutFormat)(ElfNone + 1); format < ElfCount; format = (TLayoutFormat)(format + 1)) {
if (id == TQualifier::getLayoutFormatString(format)) {
if ((format > ElfEsFloatGuard && format < ElfFloatGuard) ||
(format > ElfEsIntGuard && format < ElfIntGuard) ||
(format > ElfEsUintGuard && format < ElfCount))
requireProfile(loc, ENoProfile | ECoreProfile | ECompatibilityProfile, "image load-store format");
profileRequires(loc, ENoProfile | ECoreProfile | ECompatibilityProfile, 420, E_GL_ARB_shader_image_load_store, "image load store");
profileRequires(loc, EEsProfile, 310, E_GL_ARB_shader_image_load_store, "image load store");
publicType.qualifier.layoutFormat = format;
return;
}
}
if (id == "push_constant") {
requireVulkan(loc, "push_constant");
publicType.qualifier.layoutPushConstant = true;
return;
}
if (id == "buffer_reference") {
requireVulkan(loc, "buffer_reference");
requireExtensions(loc, 1, &E_GL_EXT_buffer_reference, "buffer_reference");
publicType.qualifier.layoutBufferReference = true;
intermediate.setUseStorageBuffer();
intermediate.setUsePhysicalStorageBuffer();
return;
}
if (id == "bindless_sampler") {
requireExtensions(loc, 1, &E_GL_ARB_bindless_texture, "bindless_sampler");
publicType.qualifier.layoutBindlessSampler = true;
intermediate.setBindlessTextureMode(currentCaller, AstRefTypeLayout);
return;
}
if (id == "bindless_image") {
requireExtensions(loc, 1, &E_GL_ARB_bindless_texture, "bindless_image");
publicType.qualifier.layoutBindlessImage = true;
intermediate.setBindlessImageMode(currentCaller, AstRefTypeLayout);
return;
}
if (id == "bound_sampler") {
requireExtensions(loc, 1, &E_GL_ARB_bindless_texture, "bound_sampler");
publicType.qualifier.layoutBindlessSampler = false;
return;
}
if (id == "bound_image") {
requireExtensions(loc, 1, &E_GL_ARB_bindless_texture, "bound_image");
publicType.qualifier.layoutBindlessImage = false;
return;
}
if (language == EShLangGeometry || language == EShLangTessEvaluation || language == EShLangMesh) {
if (id == TQualifier::getGeometryString(ElgTriangles)) {
publicType.shaderQualifiers.geometry = ElgTriangles;
return;
}
if (language == EShLangGeometry || language == EShLangMesh) {
if (id == TQualifier::getGeometryString(ElgPoints)) {
publicType.shaderQualifiers.geometry = ElgPoints;
return;
}
if (id == TQualifier::getGeometryString(ElgLines)) {
publicType.shaderQualifiers.geometry = ElgLines;
return;
}
if (language == EShLangGeometry) {
if (id == TQualifier::getGeometryString(ElgLineStrip)) {
publicType.shaderQualifiers.geometry = ElgLineStrip;
return;
}
if (id == TQualifier::getGeometryString(ElgLinesAdjacency)) {
publicType.shaderQualifiers.geometry = ElgLinesAdjacency;
return;
}
if (id == TQualifier::getGeometryString(ElgTrianglesAdjacency)) {
publicType.shaderQualifiers.geometry = ElgTrianglesAdjacency;
return;
}
if (id == TQualifier::getGeometryString(ElgTriangleStrip)) {
publicType.shaderQualifiers.geometry = ElgTriangleStrip;
return;
}
if (id == "passthrough") {
requireExtensions(loc, 1, &E_SPV_NV_geometry_shader_passthrough, "geometry shader passthrough");
publicType.qualifier.layoutPassthrough = true;
intermediate.setGeoPassthroughEXT();
return;
}
}
} else {
assert(language == EShLangTessEvaluation);
// input primitive
if (id == TQualifier::getGeometryString(ElgTriangles)) {
publicType.shaderQualifiers.geometry = ElgTriangles;
return;
}
if (id == TQualifier::getGeometryString(ElgQuads)) {
publicType.shaderQualifiers.geometry = ElgQuads;
return;
}
if (id == TQualifier::getGeometryString(ElgIsolines)) {
publicType.shaderQualifiers.geometry = ElgIsolines;
return;
}
// vertex spacing
if (id == TQualifier::getVertexSpacingString(EvsEqual)) {
publicType.shaderQualifiers.spacing = EvsEqual;
return;
}
if (id == TQualifier::getVertexSpacingString(EvsFractionalEven)) {
publicType.shaderQualifiers.spacing = EvsFractionalEven;
return;
}
if (id == TQualifier::getVertexSpacingString(EvsFractionalOdd)) {
publicType.shaderQualifiers.spacing = EvsFractionalOdd;
return;
}
// triangle order
if (id == TQualifier::getVertexOrderString(EvoCw)) {
publicType.shaderQualifiers.order = EvoCw;
return;
}
if (id == TQualifier::getVertexOrderString(EvoCcw)) {
publicType.shaderQualifiers.order = EvoCcw;
return;
}
// point mode
if (id == "point_mode") {
publicType.shaderQualifiers.pointMode = true;
return;
}
}
}
if (language == EShLangFragment) {
if (id == "origin_upper_left") {
requireProfile(loc, ECoreProfile | ECompatibilityProfile | ENoProfile, "origin_upper_left");
if (profile == ENoProfile) {
profileRequires(loc,ECoreProfile | ECompatibilityProfile, 140, E_GL_ARB_fragment_coord_conventions, "origin_upper_left");
}
publicType.shaderQualifiers.originUpperLeft = true;
return;
}
if (id == "pixel_center_integer") {
requireProfile(loc, ECoreProfile | ECompatibilityProfile | ENoProfile, "pixel_center_integer");
if (profile == ENoProfile) {
profileRequires(loc,ECoreProfile | ECompatibilityProfile, 140, E_GL_ARB_fragment_coord_conventions, "pixel_center_integer");
}
publicType.shaderQualifiers.pixelCenterInteger = true;
return;
}
if (id == "early_fragment_tests") {
profileRequires(loc, ENoProfile | ECoreProfile | ECompatibilityProfile, 420, E_GL_ARB_shader_image_load_store, "early_fragment_tests");
profileRequires(loc, EEsProfile, 310, nullptr, "early_fragment_tests");
publicType.shaderQualifiers.earlyFragmentTests = true;
return;
}
if (id == "early_and_late_fragment_tests_amd") {
profileRequires(loc, ENoProfile | ECoreProfile | ECompatibilityProfile, 420, E_GL_AMD_shader_early_and_late_fragment_tests, "early_and_late_fragment_tests_amd");
profileRequires(loc, EEsProfile, 310, nullptr, "early_and_late_fragment_tests_amd");
publicType.shaderQualifiers.earlyAndLateFragmentTestsAMD = true;
return;
}
if (id == "post_depth_coverage") {
requireExtensions(loc, Num_post_depth_coverageEXTs, post_depth_coverageEXTs, "post depth coverage");
if (extensionTurnedOn(E_GL_ARB_post_depth_coverage)) {
publicType.shaderQualifiers.earlyFragmentTests = true;
}
publicType.shaderQualifiers.postDepthCoverage = true;
return;
}
/* id is transformed into lower case in the beginning of this function. */
if (id == "non_coherent_color_attachment_readext") {
requireExtensions(loc, 1, &E_GL_EXT_shader_tile_image, "non_coherent_color_attachment_readEXT");
publicType.shaderQualifiers.nonCoherentColorAttachmentReadEXT = true;
return;
}
if (id == "non_coherent_depth_attachment_readext") {
requireExtensions(loc, 1, &E_GL_EXT_shader_tile_image, "non_coherent_depth_attachment_readEXT");
publicType.shaderQualifiers.nonCoherentDepthAttachmentReadEXT = true;
return;
}
if (id == "non_coherent_stencil_attachment_readext") {
requireExtensions(loc, 1, &E_GL_EXT_shader_tile_image, "non_coherent_stencil_attachment_readEXT");
publicType.shaderQualifiers.nonCoherentStencilAttachmentReadEXT = true;
return;
}
for (TLayoutDepth depth = (TLayoutDepth)(EldNone + 1); depth < EldCount; depth = (TLayoutDepth)(depth+1)) {
if (id == TQualifier::getLayoutDepthString(depth)) {
requireProfile(loc, ECoreProfile | ECompatibilityProfile, "depth layout qualifier");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 420, nullptr, "depth layout qualifier");
publicType.shaderQualifiers.layoutDepth = depth;
return;
}
}
for (TLayoutStencil stencil = (TLayoutStencil)(ElsNone + 1); stencil < ElsCount; stencil = (TLayoutStencil)(stencil+1)) {
if (id == TQualifier::getLayoutStencilString(stencil)) {
requireProfile(loc, ECoreProfile | ECompatibilityProfile, "stencil layout qualifier");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 420, nullptr, "stencil layout qualifier");
publicType.shaderQualifiers.layoutStencil = stencil;
return;
}
}
for (TInterlockOrdering order = (TInterlockOrdering)(EioNone + 1); order < EioCount; order = (TInterlockOrdering)(order+1)) {
if (id == TQualifier::getInterlockOrderingString(order)) {
requireProfile(loc, ECoreProfile | ECompatibilityProfile, "fragment shader interlock layout qualifier");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 450, nullptr, "fragment shader interlock layout qualifier");
requireExtensions(loc, 1, &E_GL_ARB_fragment_shader_interlock, TQualifier::getInterlockOrderingString(order));
if (order == EioShadingRateInterlockOrdered || order == EioShadingRateInterlockUnordered)
requireExtensions(loc, 1, &E_GL_NV_shading_rate_image, TQualifier::getInterlockOrderingString(order));
publicType.shaderQualifiers.interlockOrdering = order;
return;
}
}
if (id.compare(0, 13, "blend_support") == 0) {
bool found = false;
for (TBlendEquationShift be = (TBlendEquationShift)0; be < EBlendCount; be = (TBlendEquationShift)(be + 1)) {
if (id == TQualifier::getBlendEquationString(be)) {
profileRequires(loc, EEsProfile, 320, E_GL_KHR_blend_equation_advanced, "blend equation");
profileRequires(loc, ~EEsProfile, 0, E_GL_KHR_blend_equation_advanced, "blend equation");
intermediate.addBlendEquation(be);
publicType.shaderQualifiers.blendEquation = true;
found = true;
break;
}
}
if (! found)
error(loc, "unknown blend equation", "blend_support", "");
return;
}
if (id == "override_coverage") {
requireExtensions(loc, 1, &E_GL_NV_sample_mask_override_coverage, "sample mask override coverage");
publicType.shaderQualifiers.layoutOverrideCoverage = true;
return;
}
if (id == "full_quads")
{
const char* feature = "full_quads qualifier";
requireProfile(loc, ECompatibilityProfile | ECoreProfile | EEsProfile, feature);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 140, E_GL_EXT_shader_quad_control, feature);
profileRequires(loc, EEsProfile, 310, E_GL_EXT_shader_quad_control, feature);
publicType.qualifier.layoutFullQuads = true;
return;
}
}
if (language == EShLangVertex ||
language == EShLangTessControl ||
language == EShLangTessEvaluation ||
language == EShLangGeometry ) {
if (id == "viewport_relative") {
requireExtensions(loc, 1, &E_GL_NV_viewport_array2, "view port array2");
publicType.qualifier.layoutViewportRelative = true;
return;
}
} else {
if (language == EShLangRayGen || language == EShLangIntersect ||
language == EShLangAnyHit || language == EShLangClosestHit ||
language == EShLangMiss || language == EShLangCallable) {
if (id == "shaderrecordnv" || id == "shaderrecordext") {
if (id == "shaderrecordnv") {
requireExtensions(loc, 1, &E_GL_NV_ray_tracing, "shader record NV");
} else {
requireExtensions(loc, 1, &E_GL_EXT_ray_tracing, "shader record EXT");
}
publicType.qualifier.layoutShaderRecord = true;
return;
} else if (id == "hitobjectshaderrecordnv") {
requireExtensions(loc, 1, &E_GL_NV_shader_invocation_reorder, "hitobject shader record NV");
publicType.qualifier.layoutHitObjectShaderRecordNV = true;
return;
}
}
}
if (language == EShLangCompute) {
if (id.compare(0, 17, "derivative_group_") == 0) {
requireExtensions(loc, 1, &E_GL_NV_compute_shader_derivatives, "compute shader derivatives");
if (id == "derivative_group_quadsnv") {
publicType.shaderQualifiers.layoutDerivativeGroupQuads = true;
return;
} else if (id == "derivative_group_linearnv") {
publicType.shaderQualifiers.layoutDerivativeGroupLinear = true;
return;
}
}
}
if (id == "primitive_culling") {
requireExtensions(loc, 1, &E_GL_EXT_ray_flags_primitive_culling, "primitive culling");
publicType.shaderQualifiers.layoutPrimitiveCulling = true;
return;
}
if (id == "quad_derivatives")
{
const char* feature = "quad_derivatives qualifier";
requireProfile(loc, ECompatibilityProfile | ECoreProfile | EEsProfile, feature);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 140, E_GL_EXT_shader_quad_control, feature);
profileRequires(loc, EEsProfile, 310, E_GL_EXT_shader_quad_control, feature);
publicType.qualifier.layoutQuadDeriv = true;
return;
}
error(loc, "unrecognized layout identifier, or qualifier requires assignment (e.g., binding = 4)", id.c_str(), "");
}
// Put the id's layout qualifier value into the public type, for qualifiers having a number set.
// This is before we know any type information for error checking.
void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publicType, TString& id, const TIntermTyped* node)
{
const char* feature = "layout-id value";
const char* nonLiteralFeature = "non-literal layout-id value";
integerCheck(node, feature);
const TIntermConstantUnion* constUnion = node->getAsConstantUnion();
int value;
bool nonLiteral = false;
if (constUnion) {
value = constUnion->getConstArray()[0].getIConst();
if (! constUnion->isLiteral()) {
requireProfile(loc, ECoreProfile | ECompatibilityProfile, nonLiteralFeature);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, E_GL_ARB_enhanced_layouts, nonLiteralFeature);
}
} else {
// grammar should have give out the error message
value = 0;
nonLiteral = true;
}
if (value < 0) {
error(loc, "cannot be negative", feature, "");
return;
}
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
if (id == "offset") {
// "offset" can be for either
// - uniform offsets
// - atomic_uint offsets
const char* feature = "offset";
if (spvVersion.spv == 0) {
requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, feature);
const char* exts[2] = { E_GL_ARB_enhanced_layouts, E_GL_ARB_shader_atomic_counters };
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 420, 2, exts, feature);
profileRequires(loc, EEsProfile, 310, nullptr, feature);
}
publicType.qualifier.layoutOffset = value;
publicType.qualifier.explicitOffset = true;
if (nonLiteral)
error(loc, "needs a literal integer", "offset", "");
return;
} else if (id == "align") {
const char* feature = "uniform buffer-member align";
if (spvVersion.spv == 0) {
requireProfile(loc, ECoreProfile | ECompatibilityProfile, feature);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, E_GL_ARB_enhanced_layouts, feature);
}
// "The specified alignment must be a power of 2, or a compile-time error results."
if (! IsPow2(value))
error(loc, "must be a power of 2", "align", "");
else
publicType.qualifier.layoutAlign = value;
if (nonLiteral)
error(loc, "needs a literal integer", "align", "");
return;
} else if (id == "location") {
profileRequires(loc, EEsProfile, 300, nullptr, "location");
const char* exts[2] = { E_GL_ARB_separate_shader_objects, E_GL_ARB_explicit_attrib_location };
// GL_ARB_explicit_uniform_location requires 330 or GL_ARB_explicit_attrib_location we do not need to add it here
profileRequires(loc, ~EEsProfile, 330, 2, exts, "location");
if ((unsigned int)value >= TQualifier::layoutLocationEnd)
error(loc, "location is too large", id.c_str(), "");
else
publicType.qualifier.layoutLocation = value;
if (nonLiteral)
error(loc, "needs a literal integer", "location", "");
return;
} else if (id == "set") {
if ((unsigned int)value >= TQualifier::layoutSetEnd)
error(loc, "set is too large", id.c_str(), "");
else
publicType.qualifier.layoutSet = value;
if (value != 0)
requireVulkan(loc, "descriptor set");
if (nonLiteral)
error(loc, "needs a literal integer", "set", "");
return;
} else if (id == "binding") {
profileRequires(loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, "binding");
profileRequires(loc, EEsProfile, 310, nullptr, "binding");
if ((unsigned int)value >= TQualifier::layoutBindingEnd)
error(loc, "binding is too large", id.c_str(), "");
else
publicType.qualifier.layoutBinding = value;
if (nonLiteral)
error(loc, "needs a literal integer", "binding", "");
return;
}
if (id == "constant_id") {
requireSpv(loc, "constant_id");
if (value >= (int)TQualifier::layoutSpecConstantIdEnd) {
error(loc, "specialization-constant id is too large", id.c_str(), "");
} else {
publicType.qualifier.layoutSpecConstantId = value;
publicType.qualifier.specConstant = true;
if (! intermediate.addUsedConstantId(value))
error(loc, "specialization-constant id already used", id.c_str(), "");
}
if (nonLiteral)
error(loc, "needs a literal integer", "constant_id", "");
return;
}
if (id == "component") {
requireProfile(loc, ECoreProfile | ECompatibilityProfile, "component");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, E_GL_ARB_enhanced_layouts, "component");
if ((unsigned)value >= TQualifier::layoutComponentEnd)
error(loc, "component is too large", id.c_str(), "");
else
publicType.qualifier.layoutComponent = value;
if (nonLiteral)
error(loc, "needs a literal integer", "component", "");
return;
}
if (id.compare(0, 4, "xfb_") == 0) {
// "Any shader making any static use (after preprocessing) of any of these
// *xfb_* qualifiers will cause the shader to be in a transform feedback
// capturing mode and hence responsible for describing the transform feedback
// setup."
intermediate.setXfbMode();
const char* feature = "transform feedback qualifier";
requireStage(loc, (EShLanguageMask)(EShLangVertexMask | EShLangGeometryMask | EShLangTessControlMask | EShLangTessEvaluationMask), feature);
requireProfile(loc, ECoreProfile | ECompatibilityProfile, feature);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, E_GL_ARB_enhanced_layouts, feature);
if (id == "xfb_buffer") {
// "It is a compile-time error to specify an *xfb_buffer* that is greater than
// the implementation-dependent constant gl_MaxTransformFeedbackBuffers."
if (value >= resources.maxTransformFeedbackBuffers)
error(loc, "buffer is too large:", id.c_str(), "gl_MaxTransformFeedbackBuffers is %d", resources.maxTransformFeedbackBuffers);
if (value >= (int)TQualifier::layoutXfbBufferEnd)
error(loc, "buffer is too large:", id.c_str(), "internal max is %d", TQualifier::layoutXfbBufferEnd-1);
else
publicType.qualifier.layoutXfbBuffer = value;
if (nonLiteral)
error(loc, "needs a literal integer", "xfb_buffer", "");
return;
} else if (id == "xfb_offset") {
if (value >= (int)TQualifier::layoutXfbOffsetEnd)
error(loc, "offset is too large:", id.c_str(), "internal max is %d", TQualifier::layoutXfbOffsetEnd-1);
else
publicType.qualifier.layoutXfbOffset = value;
if (nonLiteral)
error(loc, "needs a literal integer", "xfb_offset", "");
return;
} else if (id == "xfb_stride") {
// "The resulting stride (implicit or explicit), when divided by 4, must be less than or equal to the
// implementation-dependent constant gl_MaxTransformFeedbackInterleavedComponents."
if (value > 4 * resources.maxTransformFeedbackInterleavedComponents) {
error(loc, "1/4 stride is too large:", id.c_str(), "gl_MaxTransformFeedbackInterleavedComponents is %d",
resources.maxTransformFeedbackInterleavedComponents);
}
if (value >= (int)TQualifier::layoutXfbStrideEnd)
error(loc, "stride is too large:", id.c_str(), "internal max is %d", TQualifier::layoutXfbStrideEnd-1);
else
publicType.qualifier.layoutXfbStride = value;
if (nonLiteral)
error(loc, "needs a literal integer", "xfb_stride", "");
return;
}
}
if (id == "input_attachment_index") {
requireVulkan(loc, "input_attachment_index");
if (value >= (int)TQualifier::layoutAttachmentEnd)
error(loc, "attachment index is too large", id.c_str(), "");
else
publicType.qualifier.layoutAttachment = value;
if (nonLiteral)
error(loc, "needs a literal integer", "input_attachment_index", "");
return;
}
if (id == "num_views") {
requireExtensions(loc, Num_OVR_multiview_EXTs, OVR_multiview_EXTs, "num_views");
publicType.shaderQualifiers.numViews = value;
if (nonLiteral)
error(loc, "needs a literal integer", "num_views", "");
return;
}
if (language == EShLangVertex ||
language == EShLangTessControl ||
language == EShLangTessEvaluation ||
language == EShLangGeometry) {
if (id == "secondary_view_offset") {
requireExtensions(loc, 1, &E_GL_NV_stereo_view_rendering, "stereo view rendering");
publicType.qualifier.layoutSecondaryViewportRelativeOffset = value;
if (nonLiteral)
error(loc, "needs a literal integer", "secondary_view_offset", "");
return;
}
}
if (id == "buffer_reference_align") {
requireExtensions(loc, 1, &E_GL_EXT_buffer_reference, "buffer_reference_align");
if (! IsPow2(value))
error(loc, "must be a power of 2", "buffer_reference_align", "");
else
publicType.qualifier.layoutBufferReferenceAlign = IntLog2(value);
if (nonLiteral)
error(loc, "needs a literal integer", "buffer_reference_align", "");
return;
}
switch (language) {
case EShLangTessControl:
if (id == "vertices") {
if (value == 0)
error(loc, "must be greater than 0", "vertices", "");
else
publicType.shaderQualifiers.vertices = value;
if (nonLiteral)
error(loc, "needs a literal integer", "vertices", "");
return;
}
break;
case EShLangGeometry:
if (id == "invocations") {
profileRequires(loc, ECompatibilityProfile | ECoreProfile, 400, nullptr, "invocations");
if (value == 0)
error(loc, "must be at least 1", "invocations", "");
else
publicType.shaderQualifiers.invocations = value;
if (nonLiteral)
error(loc, "needs a literal integer", "invocations", "");
return;
}
if (id == "max_vertices") {
publicType.shaderQualifiers.vertices = value;
if (value > resources.maxGeometryOutputVertices)
error(loc, "too large, must be less than gl_MaxGeometryOutputVertices", "max_vertices", "");
if (nonLiteral)
error(loc, "needs a literal integer", "max_vertices", "");
return;
}
if (id == "stream") {
requireProfile(loc, ~EEsProfile, "selecting output stream");
publicType.qualifier.layoutStream = value;
if (value > 0)
intermediate.setMultiStream();
if (nonLiteral)
error(loc, "needs a literal integer", "stream", "");
return;
}
break;
case EShLangFragment:
if (id == "index") {
requireProfile(loc, ECompatibilityProfile | ECoreProfile | EEsProfile, "index layout qualifier on fragment output");
const char* exts[2] = { E_GL_ARB_separate_shader_objects, E_GL_ARB_explicit_attrib_location };
profileRequires(loc, ECompatibilityProfile | ECoreProfile, 330, 2, exts, "index layout qualifier on fragment output");
profileRequires(loc, EEsProfile ,310, E_GL_EXT_blend_func_extended, "index layout qualifier on fragment output");
// "It is also a compile-time error if a fragment shader sets a layout index to less than 0 or greater than 1."
if (value < 0 || value > 1) {
value = 0;
error(loc, "value must be 0 or 1", "index", "");
}
publicType.qualifier.layoutIndex = value;
if (nonLiteral)
error(loc, "needs a literal integer", "index", "");
return;
}
break;
case EShLangMesh:
if (id == "max_vertices") {
requireExtensions(loc, Num_AEP_mesh_shader, AEP_mesh_shader, "max_vertices");
publicType.shaderQualifiers.vertices = value;
int max = extensionTurnedOn(E_GL_EXT_mesh_shader) ? resources.maxMeshOutputVerticesEXT
: resources.maxMeshOutputVerticesNV;
if (value > max) {
TString maxsErrtring = "too large, must be less than ";
maxsErrtring.append(extensionTurnedOn(E_GL_EXT_mesh_shader) ? "gl_MaxMeshOutputVerticesEXT"
: "gl_MaxMeshOutputVerticesNV");
error(loc, maxsErrtring.c_str(), "max_vertices", "");
}
if (nonLiteral)
error(loc, "needs a literal integer", "max_vertices", "");
return;
}
if (id == "max_primitives") {
requireExtensions(loc, Num_AEP_mesh_shader, AEP_mesh_shader, "max_primitives");
publicType.shaderQualifiers.primitives = value;
int max = extensionTurnedOn(E_GL_EXT_mesh_shader) ? resources.maxMeshOutputPrimitivesEXT
: resources.maxMeshOutputPrimitivesNV;
if (value > max) {
TString maxsErrtring = "too large, must be less than ";
maxsErrtring.append(extensionTurnedOn(E_GL_EXT_mesh_shader) ? "gl_MaxMeshOutputPrimitivesEXT"
: "gl_MaxMeshOutputPrimitivesNV");
error(loc, maxsErrtring.c_str(), "max_primitives", "");
}
if (nonLiteral)
error(loc, "needs a literal integer", "max_primitives", "");
return;
}
[[fallthrough]];
case EShLangTask:
// Fall through
case EShLangCompute:
if (id.compare(0, 11, "local_size_") == 0) {
if (language == EShLangMesh || language == EShLangTask) {
requireExtensions(loc, Num_AEP_mesh_shader, AEP_mesh_shader, "gl_WorkGroupSize");
} else {
profileRequires(loc, EEsProfile, 310, nullptr, "gl_WorkGroupSize");
profileRequires(loc, ~EEsProfile, 430, E_GL_ARB_compute_shader, "gl_WorkGroupSize");
}
if (nonLiteral)
error(loc, "needs a literal integer", "local_size", "");
if (id.size() == 12 && value == 0) {
error(loc, "must be at least 1", id.c_str(), "");
return;
}
if (id == "local_size_x") {
publicType.shaderQualifiers.localSize[0] = value;
publicType.shaderQualifiers.localSizeNotDefault[0] = true;
return;
}
if (id == "local_size_y") {
publicType.shaderQualifiers.localSize[1] = value;
publicType.shaderQualifiers.localSizeNotDefault[1] = true;
return;
}
if (id == "local_size_z") {
publicType.shaderQualifiers.localSize[2] = value;
publicType.shaderQualifiers.localSizeNotDefault[2] = true;
return;
}
if (spvVersion.spv != 0) {
if (id == "local_size_x_id") {
publicType.shaderQualifiers.localSizeSpecId[0] = value;
return;
}
if (id == "local_size_y_id") {
publicType.shaderQualifiers.localSizeSpecId[1] = value;
return;
}
if (id == "local_size_z_id") {
publicType.shaderQualifiers.localSizeSpecId[2] = value;
return;
}
}
}
break;
default:
break;
}
error(loc, "there is no such layout identifier for this stage taking an assigned value", id.c_str(), "");
}
// Merge any layout qualifier information from src into dst, leaving everything else in dst alone
//
// "More than one layout qualifier may appear in a single declaration.
// Additionally, the same layout-qualifier-name can occur multiple times
// within a layout qualifier or across multiple layout qualifiers in the
// same declaration. When the same layout-qualifier-name occurs
// multiple times, in a single declaration, the last occurrence overrides
// the former occurrence(s). Further, if such a layout-qualifier-name
// will effect subsequent declarations or other observable behavior, it
// is only the last occurrence that will have any effect, behaving as if
// the earlier occurrence(s) within the declaration are not present.
// This is also true for overriding layout-qualifier-names, where one
// overrides the other (e.g., row_major vs. column_major); only the last
// occurrence has any effect."
void TParseContext::mergeObjectLayoutQualifiers(TQualifier& dst, const TQualifier& src, bool inheritOnly)
{
if (src.hasMatrix())
dst.layoutMatrix = src.layoutMatrix;
if (src.hasPacking())
dst.layoutPacking = src.layoutPacking;
if (src.hasStream())
dst.layoutStream = src.layoutStream;
if (src.hasFormat())
dst.layoutFormat = src.layoutFormat;
if (src.hasXfbBuffer())
dst.layoutXfbBuffer = src.layoutXfbBuffer;
if (src.hasBufferReferenceAlign())
dst.layoutBufferReferenceAlign = src.layoutBufferReferenceAlign;
if (src.hasAlign())
dst.layoutAlign = src.layoutAlign;
if (! inheritOnly) {
if (src.hasLocation())
dst.layoutLocation = src.layoutLocation;
if (src.hasOffset())
dst.layoutOffset = src.layoutOffset;
if (src.hasSet())
dst.layoutSet = src.layoutSet;
if (src.layoutBinding != TQualifier::layoutBindingEnd)
dst.layoutBinding = src.layoutBinding;
if (src.hasSpecConstantId())
dst.layoutSpecConstantId = src.layoutSpecConstantId;
if (src.hasComponent())
dst.layoutComponent = src.layoutComponent;
if (src.hasIndex())
dst.layoutIndex = src.layoutIndex;
if (src.hasXfbStride())
dst.layoutXfbStride = src.layoutXfbStride;
if (src.hasXfbOffset())
dst.layoutXfbOffset = src.layoutXfbOffset;
if (src.hasAttachment())
dst.layoutAttachment = src.layoutAttachment;
if (src.layoutPushConstant)
dst.layoutPushConstant = true;
if (src.layoutBufferReference)
dst.layoutBufferReference = true;
if (src.layoutPassthrough)
dst.layoutPassthrough = true;
if (src.layoutViewportRelative)
dst.layoutViewportRelative = true;
if (src.layoutSecondaryViewportRelativeOffset != -2048)
dst.layoutSecondaryViewportRelativeOffset = src.layoutSecondaryViewportRelativeOffset;
if (src.layoutShaderRecord)
dst.layoutShaderRecord = true;
if (src.layoutFullQuads)
dst.layoutFullQuads = true;
if (src.layoutQuadDeriv)
dst.layoutQuadDeriv = true;
if (src.layoutBindlessSampler)
dst.layoutBindlessSampler = true;
if (src.layoutBindlessImage)
dst.layoutBindlessImage = true;
if (src.pervertexNV)
dst.pervertexNV = true;
if (src.pervertexEXT)
dst.pervertexEXT = true;
if (src.layoutHitObjectShaderRecordNV)
dst.layoutHitObjectShaderRecordNV = true;
}
}
// Do error layout error checking given a full variable/block declaration.
void TParseContext::layoutObjectCheck(const TSourceLoc& loc, const TSymbol& symbol)
{
const TType& type = symbol.getType();
const TQualifier& qualifier = type.getQualifier();
// first, cross check WRT to just the type
layoutTypeCheck(loc, type);
// now, any remaining error checking based on the object itself
if (qualifier.hasAnyLocation()) {
switch (qualifier.storage) {
case EvqUniform:
case EvqBuffer:
if (symbol.getAsVariable() == nullptr)
error(loc, "can only be used on variable declaration", "location", "");
break;
default:
break;
}
}
// user-variable location check, which are required for SPIR-V in/out:
// - variables have it directly,
// - blocks have it on each member (already enforced), so check first one
if (spvVersion.spv > 0 && !parsingBuiltins && qualifier.builtIn == EbvNone &&
!qualifier.hasLocation() && !intermediate.getAutoMapLocations()) {
switch (qualifier.storage) {
case EvqVaryingIn:
case EvqVaryingOut:
if (!type.getQualifier().isTaskMemory() && !type.getQualifier().hasSpirvDecorate() &&
(type.getBasicType() != EbtBlock ||
(!(*type.getStruct())[0].type->getQualifier().hasLocation() &&
(*type.getStruct())[0].type->getQualifier().builtIn == EbvNone)))
error(loc, "SPIR-V requires location for user input/output", "location", "");
break;
default:
break;
}
}
// Check packing and matrix
if (qualifier.hasUniformLayout()) {
switch (qualifier.storage) {
case EvqUniform:
case EvqBuffer:
if (type.getBasicType() != EbtBlock) {
if (qualifier.hasMatrix())
error(loc, "cannot specify matrix layout on a variable declaration", "layout", "");
if (qualifier.hasPacking())
error(loc, "cannot specify packing on a variable declaration", "layout", "");
// "The offset qualifier can only be used on block members of blocks..."
if (qualifier.hasOffset() && !type.isAtomic())
error(loc, "cannot specify on a variable declaration", "offset", "");
// "The align qualifier can only be used on blocks or block members..."
if (qualifier.hasAlign())
error(loc, "cannot specify on a variable declaration", "align", "");
if (qualifier.isPushConstant())
error(loc, "can only specify on a uniform block", "push_constant", "");
if (qualifier.isShaderRecord())
error(loc, "can only specify on a buffer block", "shaderRecordNV", "");
if (qualifier.hasLocation() && type.isAtomic())
error(loc, "cannot specify on atomic counter", "location", "");
}
break;
default:
// these were already filtered by layoutTypeCheck() (or its callees)
break;
}
}
}
// "For some blocks declared as arrays, the location can only be applied at the block level:
// When a block is declared as an array where additional locations are needed for each member
// for each block array element, it is a compile-time error to specify locations on the block
// members. That is, when locations would be under specified by applying them on block members,
// they are not allowed on block members. For arrayed interfaces (those generally having an
// extra level of arrayness due to interface expansion), the outer array is stripped before
// applying this rule."
void TParseContext::layoutMemberLocationArrayCheck(const TSourceLoc& loc, bool memberWithLocation,
TArraySizes* arraySizes)
{
if (memberWithLocation && arraySizes != nullptr) {
if (arraySizes->getNumDims() > (currentBlockQualifier.isArrayedIo(language) ? 1 : 0))
error(loc, "cannot use in a block array where new locations are needed for each block element",
"location", "");
}
}
// Do layout error checking with respect to a type.
void TParseContext::layoutTypeCheck(const TSourceLoc& loc, const TType& type)
{
const TQualifier& qualifier = type.getQualifier();
// first, intra-layout qualifier-only error checking
layoutQualifierCheck(loc, qualifier);
// now, error checking combining type and qualifier
if (qualifier.hasAnyLocation()) {
if (qualifier.hasLocation()) {
if (qualifier.storage == EvqVaryingOut && language == EShLangFragment) {
if (qualifier.layoutLocation >= (unsigned int)resources.maxDrawBuffers)
error(loc, "too large for fragment output", "location", "");
}
}
if (qualifier.hasComponent()) {
// "It is a compile-time error if this sequence of components gets larger than 3."
if (qualifier.layoutComponent + type.getVectorSize() * (type.getBasicType() == EbtDouble ? 2 : 1) > 4)
error(loc, "type overflows the available 4 components", "component", "");
// "It is a compile-time error to apply the component qualifier to a matrix, a structure, a block, or an array containing any of these."
if (type.isMatrix() || type.getBasicType() == EbtBlock || type.getBasicType() == EbtStruct)
error(loc, "cannot apply to a matrix, structure, or block", "component", "");
// " It is a compile-time error to use component 1 or 3 as the beginning of a double or dvec2."
if (type.getBasicType() == EbtDouble)
if (qualifier.layoutComponent & 1)
error(loc, "doubles cannot start on an odd-numbered component", "component", "");
}
switch (qualifier.storage) {
case EvqVaryingIn:
case EvqVaryingOut:
if (type.getBasicType() == EbtBlock)
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, E_GL_ARB_enhanced_layouts, "location qualifier on in/out block");
if (type.getQualifier().isTaskMemory())
error(loc, "cannot apply to taskNV in/out blocks", "location", "");
break;
case EvqUniform:
case EvqBuffer:
if (type.getBasicType() == EbtBlock)
error(loc, "cannot apply to uniform or buffer block", "location", "");
else if (type.getBasicType() == EbtSampler && type.getSampler().isAttachmentEXT())
error(loc, "only applies to", "location", "%s with storage tileImageEXT", type.getBasicTypeString().c_str());
break;
case EvqtaskPayloadSharedEXT:
error(loc, "cannot apply to taskPayloadSharedEXT", "location", "");
break;
case EvqPayload:
case EvqPayloadIn:
case EvqHitAttr:
case EvqCallableData:
case EvqCallableDataIn:
case EvqHitObjectAttrNV:
case EvqSpirvStorageClass:
break;
case EvqTileImageEXT:
break;
default:
error(loc, "can only apply to uniform, buffer, in, or out storage qualifiers", "location", "");
break;
}
bool typeCollision;
int repeated = intermediate.addUsedLocation(qualifier, type, typeCollision);
if (repeated >= 0 && ! typeCollision)
error(loc, "overlapping use of location", "location", "%d", repeated);
// When location aliasing, the aliases sharing the location must have the same underlying numerical type and bit width(
// floating - point or integer, 32 - bit versus 64 - bit,etc.)
if (typeCollision && (qualifier.isPipeInput() || qualifier.isPipeOutput() || qualifier.storage == EvqTileImageEXT))
error(loc, "the aliases sharing the location", "location", "%d must be the same basic type and interpolation qualification", repeated);
}
if (qualifier.hasXfbOffset() && qualifier.hasXfbBuffer()) {
if (type.isUnsizedArray()) {
error(loc, "unsized array", "xfb_offset", "in buffer %d", qualifier.layoutXfbBuffer);
} else {
int repeated = intermediate.addXfbBufferOffset(type);
if (repeated >= 0)
error(loc, "overlapping offsets at", "xfb_offset", "offset %d in buffer %d", repeated, qualifier.layoutXfbBuffer);
}
// "The offset must be a multiple of the size of the first component of the first
// qualified variable or block member, or a compile-time error results. Further, if applied to an aggregate
// containing a double or 64-bit integer, the offset must also be a multiple of 8..."
if ((type.containsBasicType(EbtDouble) || type.containsBasicType(EbtInt64) || type.containsBasicType(EbtUint64)) &&
! IsMultipleOfPow2(qualifier.layoutXfbOffset, 8))
error(loc, "type contains double or 64-bit integer; xfb_offset must be a multiple of 8", "xfb_offset", "");
else if ((type.containsBasicType(EbtBool) || type.containsBasicType(EbtFloat) ||
type.containsBasicType(EbtInt) || type.containsBasicType(EbtUint)) &&
! IsMultipleOfPow2(qualifier.layoutXfbOffset, 4))
error(loc, "must be a multiple of size of first component", "xfb_offset", "");
// ..., if applied to an aggregate containing a half float or 16-bit integer, the offset must also be a multiple of 2..."
else if ((type.contains16BitFloat() || type.containsBasicType(EbtInt16) || type.containsBasicType(EbtUint16)) &&
!IsMultipleOfPow2(qualifier.layoutXfbOffset, 2))
error(loc, "type contains half float or 16-bit integer; xfb_offset must be a multiple of 2", "xfb_offset", "");
}
if (qualifier.hasXfbStride() && qualifier.hasXfbBuffer()) {
if (! intermediate.setXfbBufferStride(qualifier.layoutXfbBuffer, qualifier.layoutXfbStride))
error(loc, "all stride settings must match for xfb buffer", "xfb_stride", "%d", qualifier.layoutXfbBuffer);
}
if (qualifier.hasBinding()) {
// Binding checking, from the spec:
//
// "If the binding point for any uniform or shader storage block instance is less than zero, or greater than or
// equal to the implementation-dependent maximum number of uniform buffer bindings, a compile-time
// error will occur. When the binding identifier is used with a uniform or shader storage block instanced as
// an array of size N, all elements of the array from binding through binding + N - 1 must be within this
// range."
//
if (!type.isOpaque() && type.getBasicType() != EbtBlock && type.getBasicType() != EbtSpirvType)
error(loc, "requires block, or sampler/image, or atomic-counter type", "binding", "");
if (type.getBasicType() == EbtSampler) {
int lastBinding = qualifier.layoutBinding;
if (type.isArray()) {
if (spvVersion.vulkan == 0) {
if (type.isSizedArray())
lastBinding += (type.getCumulativeArraySize() - 1);
else {
warn(loc, "assuming binding count of one for compile-time checking of binding numbers for unsized array", "[]", "");
}
}
}
if (spvVersion.vulkan == 0 && lastBinding >= resources.maxCombinedTextureImageUnits)
error(loc, "sampler binding not less than gl_MaxCombinedTextureImageUnits", "binding", type.isArray() ? "(using array)" : "");
}
if (type.isAtomic() && !spvVersion.vulkanRelaxed) {
if (qualifier.layoutBinding >= (unsigned int)resources.maxAtomicCounterBindings) {
error(loc, "atomic_uint binding is too large; see gl_MaxAtomicCounterBindings", "binding", "");
return;
}
}
} else if (!intermediate.getAutoMapBindings()) {
// some types require bindings
// atomic_uint
if (type.isAtomic())
error(loc, "layout(binding=X) is required", "atomic_uint", "");
// SPIR-V
if (spvVersion.spv > 0) {
if (qualifier.isUniformOrBuffer()) {
if (type.getBasicType() == EbtBlock && !qualifier.isPushConstant() &&
!qualifier.isShaderRecord() &&
!qualifier.hasAttachment() &&
!qualifier.hasBufferReference())
error(loc, "uniform/buffer blocks require layout(binding=X)", "binding", "");
else if (spvVersion.vulkan > 0 && type.getBasicType() == EbtSampler && !type.getSampler().isAttachmentEXT())
error(loc, "sampler/texture/image requires layout(binding=X)", "binding", "");
}
}
}
// some things can't have arrays of arrays
if (type.isArrayOfArrays()) {
if (spvVersion.vulkan > 0) {
if (type.isOpaque() || (type.getQualifier().isUniformOrBuffer() && type.getBasicType() == EbtBlock))
warn(loc, "Generating SPIR-V array-of-arrays, but Vulkan only supports single array level for this resource", "[][]", "");
}
}
// "The offset qualifier can only be used on block members of blocks..."
if (qualifier.hasOffset()) {
if (type.getBasicType() == EbtBlock)
error(loc, "only applies to block members, not blocks", "offset", "");
}
// Image format
if (qualifier.hasFormat()) {
if (! type.isImage() && !intermediate.getBindlessImageMode())
error(loc, "only apply to images", TQualifier::getLayoutFormatString(qualifier.getFormat()), "");
else {
if (type.getSampler().type == EbtFloat && qualifier.getFormat() > ElfFloatGuard)
error(loc, "does not apply to floating point images", TQualifier::getLayoutFormatString(qualifier.getFormat()), "");
if (type.getSampler().type == EbtInt && (qualifier.getFormat() < ElfFloatGuard || qualifier.getFormat() > ElfIntGuard))
error(loc, "does not apply to signed integer images", TQualifier::getLayoutFormatString(qualifier.getFormat()), "");
if (type.getSampler().type == EbtUint && qualifier.getFormat() < ElfIntGuard)
error(loc, "does not apply to unsigned integer images", TQualifier::getLayoutFormatString(qualifier.getFormat()), "");
if (isEsProfile()) {
// "Except for image variables qualified with the format qualifiers r32f, r32i, and r32ui, image variables must
// specify either memory qualifier readonly or the memory qualifier writeonly."
if (! (qualifier.getFormat() == ElfR32f || qualifier.getFormat() == ElfR32i || qualifier.getFormat() == ElfR32ui)) {
if (! qualifier.isReadOnly() && ! qualifier.isWriteOnly())
error(loc, "format requires readonly or writeonly memory qualifier", TQualifier::getLayoutFormatString(qualifier.getFormat()), "");
}
}
}
} else if (type.isImage() && ! qualifier.isWriteOnly() && !intermediate.getBindlessImageMode()) {
const char *explanation = "image variables not declared 'writeonly' and without a format layout qualifier";
requireProfile(loc, ECoreProfile | ECompatibilityProfile, explanation);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 0, E_GL_EXT_shader_image_load_formatted, explanation);
}
if (qualifier.isPushConstant()) {
if (type.getBasicType() != EbtBlock)
error(loc, "can only be used with a block", "push_constant", "");
if (type.isArray())
error(loc, "Push constants blocks can't be an array", "push_constant", "");
}
if (qualifier.hasBufferReference() && type.getBasicType() != EbtBlock)
error(loc, "can only be used with a block", "buffer_reference", "");
if (qualifier.isShaderRecord() && type.getBasicType() != EbtBlock)
error(loc, "can only be used with a block", "shaderRecordNV", "");
// input attachment
if (type.isSubpass()) {
if (extensionTurnedOn(E_GL_EXT_shader_tile_image))
error(loc, "can not be used with GL_EXT_shader_tile_image enabled", type.getSampler().getString().c_str(), "");
if (! qualifier.hasAttachment())
error(loc, "requires an input_attachment_index layout qualifier", "subpass", "");
} else {
if (qualifier.hasAttachment())
error(loc, "can only be used with a subpass", "input_attachment_index", "");
}
// specialization-constant id
if (qualifier.hasSpecConstantId()) {
if (type.getQualifier().storage != EvqConst)
error(loc, "can only be applied to 'const'-qualified scalar", "constant_id", "");
if (! type.isScalar())
error(loc, "can only be applied to a scalar", "constant_id", "");
switch (type.getBasicType())
{
case EbtInt8:
case EbtUint8:
case EbtInt16:
case EbtUint16:
case EbtInt:
case EbtUint:
case EbtInt64:
case EbtUint64:
case EbtBool:
case EbtFloat:
case EbtDouble:
case EbtFloat16:
break;
default:
error(loc, "cannot be applied to this type", "constant_id", "");
break;
}
}
}
static bool storageCanHaveLayoutInBlock(const enum TStorageQualifier storage)
{
switch (storage) {
case EvqUniform:
case EvqBuffer:
case EvqShared:
return true;
default:
return false;
}
}
// Do layout error checking that can be done within a layout qualifier proper, not needing to know
// if there are blocks, atomic counters, variables, etc.
void TParseContext::layoutQualifierCheck(const TSourceLoc& loc, const TQualifier& qualifier)
{
if (qualifier.storage == EvqShared && qualifier.hasLayout()) {
if (spvVersion.spv > 0 && spvVersion.spv < EShTargetSpv_1_4) {
error(loc, "shared block requires at least SPIR-V 1.4", "shared block", "");
}
profileRequires(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, 0, E_GL_EXT_shared_memory_block, "shared block");
}
// "It is a compile-time error to use *component* without also specifying the location qualifier (order does not matter)."
if (qualifier.hasComponent() && ! qualifier.hasLocation())
error(loc, "must specify 'location' to use 'component'", "component", "");
if (qualifier.hasAnyLocation()) {
// "As with input layout qualifiers, all shaders except compute shaders
// allow *location* layout qualifiers on output variable declarations,
// output block declarations, and output block member declarations."
switch (qualifier.storage) {
case EvqVaryingIn:
{
const char* feature = "location qualifier on input";
if (isEsProfile() && version < 310)
requireStage(loc, EShLangVertex, feature);
else
requireStage(loc, (EShLanguageMask)~EShLangComputeMask, feature);
if (language == EShLangVertex) {
const char* exts[2] = { E_GL_ARB_separate_shader_objects, E_GL_ARB_explicit_attrib_location };
profileRequires(loc, ~EEsProfile, 330, 2, exts, feature);
profileRequires(loc, EEsProfile, 300, nullptr, feature);
} else {
profileRequires(loc, ~EEsProfile, 410, E_GL_ARB_separate_shader_objects, feature);
profileRequires(loc, EEsProfile, 310, nullptr, feature);
}
break;
}
case EvqVaryingOut:
{
const char* feature = "location qualifier on output";
if (isEsProfile() && version < 310)
requireStage(loc, EShLangFragment, feature);
else
requireStage(loc, (EShLanguageMask)~EShLangComputeMask, feature);
if (language == EShLangFragment) {
const char* exts[2] = { E_GL_ARB_separate_shader_objects, E_GL_ARB_explicit_attrib_location };
profileRequires(loc, ~EEsProfile, 330, 2, exts, feature);
profileRequires(loc, EEsProfile, 300, nullptr, feature);
} else {
profileRequires(loc, ~EEsProfile, 410, E_GL_ARB_separate_shader_objects, feature);
profileRequires(loc, EEsProfile, 310, nullptr, feature);
}
break;
}
case EvqUniform:
case EvqBuffer:
{
const char* feature = "location qualifier on uniform or buffer";
requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile | ENoProfile, feature);
profileRequires(loc, ~EEsProfile, 330, E_GL_ARB_explicit_attrib_location, feature);
profileRequires(loc, ~EEsProfile, 430, E_GL_ARB_explicit_uniform_location, feature);
profileRequires(loc, EEsProfile, 310, nullptr, feature);
break;
}
default:
break;
}
if (qualifier.hasIndex()) {
if (qualifier.storage != EvqVaryingOut)
error(loc, "can only be used on an output", "index", "");
if (! qualifier.hasLocation())
error(loc, "can only be used with an explicit location", "index", "");
}
}
if (qualifier.hasBinding()) {
if (! qualifier.isUniformOrBuffer() && !qualifier.isTaskMemory())
error(loc, "requires uniform or buffer storage qualifier", "binding", "");
}
if (qualifier.hasStream()) {
if (!qualifier.isPipeOutput())
error(loc, "can only be used on an output", "stream", "");
}
if (qualifier.hasXfb()) {
if (!qualifier.isPipeOutput())
error(loc, "can only be used on an output", "xfb layout qualifier", "");
}
if (qualifier.hasUniformLayout()) {
if (!storageCanHaveLayoutInBlock(qualifier.storage) && !qualifier.isTaskMemory()) {
if (qualifier.hasMatrix() || qualifier.hasPacking())
error(loc, "matrix or packing qualifiers can only be used on a uniform or buffer", "layout", "");
if (qualifier.hasOffset() || qualifier.hasAlign())
error(loc, "offset/align can only be used on a uniform or buffer", "layout", "");
}
}
if (qualifier.isPushConstant()) {
if (qualifier.storage != EvqUniform)
error(loc, "can only be used with a uniform", "push_constant", "");
if (qualifier.hasSet())
error(loc, "cannot be used with push_constant", "set", "");
if (qualifier.hasBinding())
error(loc, "cannot be used with push_constant", "binding", "");
}
if (qualifier.hasBufferReference()) {
if (qualifier.storage != EvqBuffer)
error(loc, "can only be used with buffer", "buffer_reference", "");
}
if (qualifier.isShaderRecord()) {
if (qualifier.storage != EvqBuffer)
error(loc, "can only be used with a buffer", "shaderRecordNV", "");
if (qualifier.hasBinding())
error(loc, "cannot be used with shaderRecordNV", "binding", "");
if (qualifier.hasSet())
error(loc, "cannot be used with shaderRecordNV", "set", "");
}
if (qualifier.storage == EvqTileImageEXT) {
if (qualifier.hasSet())
error(loc, "cannot be used with tileImageEXT", "set", "");
if (!qualifier.hasLocation())
error(loc, "can only be used with an explicit location", "tileImageEXT", "");
}
if (qualifier.storage == EvqHitAttr && qualifier.hasLayout()) {
error(loc, "cannot apply layout qualifiers to hitAttributeNV variable", "hitAttributeNV", "");
}
}
// For places that can't have shader-level layout qualifiers
void TParseContext::checkNoShaderLayouts(const TSourceLoc& loc, const TShaderQualifiers& shaderQualifiers)
{
const char* message = "can only apply to a standalone qualifier";
if (shaderQualifiers.geometry != ElgNone)
error(loc, message, TQualifier::getGeometryString(shaderQualifiers.geometry), "");
if (shaderQualifiers.spacing != EvsNone)
error(loc, message, TQualifier::getVertexSpacingString(shaderQualifiers.spacing), "");
if (shaderQualifiers.order != EvoNone)
error(loc, message, TQualifier::getVertexOrderString(shaderQualifiers.order), "");
if (shaderQualifiers.pointMode)
error(loc, message, "point_mode", "");
if (shaderQualifiers.invocations != TQualifier::layoutNotSet)
error(loc, message, "invocations", "");
for (int i = 0; i < 3; ++i) {
if (shaderQualifiers.localSize[i] > 1)
error(loc, message, "local_size", "");
if (shaderQualifiers.localSizeSpecId[i] != TQualifier::layoutNotSet)
error(loc, message, "local_size id", "");
}
if (shaderQualifiers.vertices != TQualifier::layoutNotSet) {
if (language == EShLangGeometry || language == EShLangMesh)
error(loc, message, "max_vertices", "");
else if (language == EShLangTessControl)
error(loc, message, "vertices", "");
else
assert(0);
}
if (shaderQualifiers.earlyFragmentTests)
error(loc, message, "early_fragment_tests", "");
if (shaderQualifiers.postDepthCoverage)
error(loc, message, "post_depth_coverage", "");
if (shaderQualifiers.nonCoherentColorAttachmentReadEXT)
error(loc, message, "non_coherent_color_attachment_readEXT", "");
if (shaderQualifiers.nonCoherentDepthAttachmentReadEXT)
error(loc, message, "non_coherent_depth_attachment_readEXT", "");
if (shaderQualifiers.nonCoherentStencilAttachmentReadEXT)
error(loc, message, "non_coherent_stencil_attachment_readEXT", "");
if (shaderQualifiers.primitives != TQualifier::layoutNotSet) {
if (language == EShLangMesh)
error(loc, message, "max_primitives", "");
else
assert(0);
}
if (shaderQualifiers.hasBlendEquation())
error(loc, message, "blend equation", "");
if (shaderQualifiers.numViews != TQualifier::layoutNotSet)
error(loc, message, "num_views", "");
if (shaderQualifiers.interlockOrdering != EioNone)
error(loc, message, TQualifier::getInterlockOrderingString(shaderQualifiers.interlockOrdering), "");
if (shaderQualifiers.layoutPrimitiveCulling)
error(loc, "can only be applied as standalone", "primitive_culling", "");
}
// Correct and/or advance an object's offset layout qualifier.
void TParseContext::fixOffset(const TSourceLoc& loc, TSymbol& symbol)
{
const TQualifier& qualifier = symbol.getType().getQualifier();
if (symbol.getType().isAtomic()) {
if (qualifier.hasBinding() && (int)qualifier.layoutBinding < resources.maxAtomicCounterBindings) {
// Set the offset
int offset;
if (qualifier.hasOffset())
offset = qualifier.layoutOffset;
else
offset = atomicUintOffsets[qualifier.layoutBinding];
if (offset % 4 != 0)
error(loc, "atomic counters offset should align based on 4:", "offset", "%d", offset);
symbol.getWritableType().getQualifier().layoutOffset = offset;
// Check for overlap
int numOffsets = 4;
if (symbol.getType().isArray()) {
if (symbol.getType().isSizedArray() && !symbol.getType().getArraySizes()->isInnerUnsized())
numOffsets *= symbol.getType().getCumulativeArraySize();
else {
// "It is a compile-time error to declare an unsized array of atomic_uint."
error(loc, "array must be explicitly sized", "atomic_uint", "");
}
}
int repeated = intermediate.addUsedOffsets(qualifier.layoutBinding, offset, numOffsets);
if (repeated >= 0)
error(loc, "atomic counters sharing the same offset:", "offset", "%d", repeated);
// Bump the default offset
atomicUintOffsets[qualifier.layoutBinding] = offset + numOffsets;
}
}
}
//
// Look up a function name in the symbol table, and make sure it is a function.
//
// Return the function symbol if found, otherwise nullptr.
//
const TFunction* TParseContext::findFunction(const TSourceLoc& loc, const TFunction& call, bool& builtIn)
{
if (symbolTable.isFunctionNameVariable(call.getName())) {
error(loc, "can't use function syntax on variable", call.getName().c_str(), "");
return nullptr;
}
const TFunction* function = nullptr;
// debugPrintfEXT has var args and is in the symbol table as "debugPrintfEXT()",
// mangled to "debugPrintfEXT("
if (call.getName() == "debugPrintfEXT") {
TSymbol* symbol = symbolTable.find("debugPrintfEXT(", &builtIn);
if (symbol)
return symbol->getAsFunction();
}
bool explicitTypesEnabled = extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8) ||
extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int16) ||
extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32) ||
extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64) ||
extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16) ||
extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32) ||
extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64);
if (isEsProfile())
function = (explicitTypesEnabled && version >= 310)
? findFunctionExplicitTypes(loc, call, builtIn)
: ((extensionTurnedOn(E_GL_EXT_shader_implicit_conversions) && version >= 310)
? findFunction120(loc, call, builtIn)
: findFunctionExact(loc, call, builtIn));
else if (version < 120)
function = findFunctionExact(loc, call, builtIn);
else if (version < 400) {
bool needfindFunction400 = extensionTurnedOn(E_GL_ARB_gpu_shader_fp64) || extensionTurnedOn(E_GL_ARB_gpu_shader5);
function = needfindFunction400 ? findFunction400(loc, call, builtIn) : findFunction120(loc, call, builtIn);
}
else if (explicitTypesEnabled)
function = findFunctionExplicitTypes(loc, call, builtIn);
else
function = findFunction400(loc, call, builtIn);
return function;
}
// Function finding algorithm for ES and desktop 110.
const TFunction* TParseContext::findFunctionExact(const TSourceLoc& loc, const TFunction& call, bool& builtIn)
{
TSymbol* symbol = symbolTable.find(call.getMangledName(), &builtIn);
if (symbol == nullptr) {
error(loc, "no matching overloaded function found", call.getName().c_str(), "");
return nullptr;
}
return symbol->getAsFunction();
}
// Function finding algorithm for desktop versions 120 through 330.
const TFunction* TParseContext::findFunction120(const TSourceLoc& loc, const TFunction& call, bool& builtIn)
{
// first, look for an exact match
TSymbol* symbol = symbolTable.find(call.getMangledName(), &builtIn);
if (symbol)
return symbol->getAsFunction();
// exact match not found, look through a list of overloaded functions of the same name
// "If no exact match is found, then [implicit conversions] will be applied to find a match. Mismatched types
// on input parameters (in or inout or default) must have a conversion from the calling argument type to the
// formal parameter type. Mismatched types on output parameters (out or inout) must have a conversion
// from the formal parameter type to the calling argument type. When argument conversions are used to find
// a match, it is a semantic error if there are multiple ways to apply these conversions to make the call match
// more than one function."
const TFunction* candidate = nullptr;
TVector<const TFunction*> candidateList;
symbolTable.findFunctionNameList(call.getMangledName(), candidateList, builtIn);
for (auto it = candidateList.begin(); it != candidateList.end(); ++it) {
const TFunction& function = *(*it);
// to even be a potential match, number of arguments has to match
if (call.getParamCount() != function.getParamCount())
continue;
bool possibleMatch = true;
for (int i = 0; i < function.getParamCount(); ++i) {
// same types is easy
if (*function[i].type == *call[i].type)
continue;
// We have a mismatch in type, see if it is implicitly convertible
if (function[i].type->isArray() || call[i].type->isArray() ||
! function[i].type->sameElementShape(*call[i].type))
possibleMatch = false;
else {
// do direction-specific checks for conversion of basic type
if (function[i].type->getQualifier().isParamInput()) {
if (! intermediate.canImplicitlyPromote(call[i].type->getBasicType(), function[i].type->getBasicType()))
possibleMatch = false;
}
if (function[i].type->getQualifier().isParamOutput()) {
if (! intermediate.canImplicitlyPromote(function[i].type->getBasicType(), call[i].type->getBasicType()))
possibleMatch = false;
}
}
if (! possibleMatch)
break;
}
if (possibleMatch) {
if (candidate) {
// our second match, meaning ambiguity
error(loc, "ambiguous function signature match: multiple signatures match under implicit type conversion", call.getName().c_str(), "");
} else
candidate = &function;
}
}
if (candidate == nullptr)
error(loc, "no matching overloaded function found", call.getName().c_str(), "");
return candidate;
}
// Function finding algorithm for desktop version 400 and above.
//
// "When function calls are resolved, an exact type match for all the arguments
// is sought. If an exact match is found, all other functions are ignored, and
// the exact match is used. If no exact match is found, then the implicit
// conversions in section 4.1.10 Implicit Conversions will be applied to find
// a match. Mismatched types on input parameters (in or inout or default) must
// have a conversion from the calling argument type to the formal parameter type.
// Mismatched types on output parameters (out or inout) must have a conversion
// from the formal parameter type to the calling argument type.
//
// "If implicit conversions can be used to find more than one matching function,
// a single best-matching function is sought. To determine a best match, the
// conversions between calling argument and formal parameter types are compared
// for each function argument and pair of matching functions. After these
// comparisons are performed, each pair of matching functions are compared.
// A function declaration A is considered a better match than function
// declaration B if
//
// * for at least one function argument, the conversion for that argument in A
// is better than the corresponding conversion in B; and
// * there is no function argument for which the conversion in B is better than
// the corresponding conversion in A.
//
// "If a single function declaration is considered a better match than every
// other matching function declaration, it will be used. Otherwise, a
// compile-time semantic error for an ambiguous overloaded function call occurs.
//
// "To determine whether the conversion for a single argument in one match is
// better than that for another match, the following rules are applied, in order:
//
// 1. An exact match is better than a match involving any implicit conversion.
// 2. A match involving an implicit conversion from float to double is better
// than a match involving any other implicit conversion.
// 3. A match involving an implicit conversion from either int or uint to float
// is better than a match involving an implicit conversion from either int
// or uint to double.
//
// "If none of the rules above apply to a particular pair of conversions, neither
// conversion is considered better than the other."
//
const TFunction* TParseContext::findFunction400(const TSourceLoc& loc, const TFunction& call, bool& builtIn)
{
// first, look for an exact match
TSymbol* symbol = symbolTable.find(call.getMangledName(), &builtIn);
if (symbol)
return symbol->getAsFunction();
// no exact match, use the generic selector, parameterized by the GLSL rules
// create list of candidates to send
TVector<const TFunction*> candidateList;
symbolTable.findFunctionNameList(call.getMangledName(), candidateList, builtIn);
// can 'from' convert to 'to'?
const auto convertible = [this,builtIn](const TType& from, const TType& to, TOperator, int) -> bool {
if (from == to)
return true;
if (from.coopMatParameterOK(to))
return true;
// Allow a sized array to be passed through an unsized array parameter, for coopMatLoad/Store functions
if (builtIn && from.isArray() && to.isUnsizedArray()) {
TType fromElementType(from, 0);
TType toElementType(to, 0);
if (fromElementType == toElementType)
return true;
}
if (from.isArray() || to.isArray() || ! from.sameElementShape(to))
return false;
if (from.isCoopMat() && to.isCoopMat())
return from.sameCoopMatBaseType(to);
return intermediate.canImplicitlyPromote(from.getBasicType(), to.getBasicType());
};
// Is 'to2' a better conversion than 'to1'?
// Ties should not be considered as better.
// Assumes 'convertible' already said true.
const auto better = [](const TType& from, const TType& to1, const TType& to2) -> bool {
// 1. exact match
if (from == to2)
return from != to1;
if (from == to1)
return false;
// 2. float -> double is better
if (from.getBasicType() == EbtFloat) {
if (to2.getBasicType() == EbtDouble && to1.getBasicType() != EbtDouble)
return true;
}
// 3. -> float is better than -> double
return to2.getBasicType() == EbtFloat && to1.getBasicType() == EbtDouble;
};
// for ambiguity reporting
bool tie = false;
// send to the generic selector
const TFunction* bestMatch = selectFunction(candidateList, call, convertible, better, tie);
if (bestMatch == nullptr)
error(loc, "no matching overloaded function found", call.getName().c_str(), "");
else if (tie)
error(loc, "ambiguous best function under implicit type conversion", call.getName().c_str(), "");
return bestMatch;
}
// "To determine whether the conversion for a single argument in one match
// is better than that for another match, the conversion is assigned of the
// three ranks ordered from best to worst:
// 1. Exact match: no conversion.
// 2. Promotion: integral or floating-point promotion.
// 3. Conversion: integral conversion, floating-point conversion,
// floating-integral conversion.
// A conversion C1 is better than a conversion C2 if the rank of C1 is
// better than the rank of C2."
const TFunction* TParseContext::findFunctionExplicitTypes(const TSourceLoc& loc, const TFunction& call, bool& builtIn)
{
// first, look for an exact match
TSymbol* symbol = symbolTable.find(call.getMangledName(), &builtIn);
if (symbol)
return symbol->getAsFunction();
// no exact match, use the generic selector, parameterized by the GLSL rules
// create list of candidates to send
TVector<const TFunction*> candidateList;
symbolTable.findFunctionNameList(call.getMangledName(), candidateList, builtIn);
// can 'from' convert to 'to'?
const auto convertible = [this,builtIn](const TType& from, const TType& to, TOperator, int) -> bool {
if (from == to)
return true;
if (from.coopMatParameterOK(to))
return true;
// Allow a sized array to be passed through an unsized array parameter, for coopMatLoad/Store functions
if (builtIn && from.isArray() && to.isUnsizedArray()) {
TType fromElementType(from, 0);
TType toElementType(to, 0);
if (fromElementType == toElementType)
return true;
}
if (from.isArray() || to.isArray() || ! from.sameElementShape(to))
return false;
if (from.isCoopMat() && to.isCoopMat())
return from.sameCoopMatBaseType(to);
return intermediate.canImplicitlyPromote(from.getBasicType(), to.getBasicType());
};
// Is 'to2' a better conversion than 'to1'?
// Ties should not be considered as better.
// Assumes 'convertible' already said true.
const auto better = [this](const TType& from, const TType& to1, const TType& to2) -> bool {
// 1. exact match
if (from == to2)
return from != to1;
if (from == to1)
return false;
// 2. Promotion (integral, floating-point) is better
TBasicType from_type = from.getBasicType();
TBasicType to1_type = to1.getBasicType();
TBasicType to2_type = to2.getBasicType();
bool isPromotion1 = (intermediate.isIntegralPromotion(from_type, to1_type) ||
intermediate.isFPPromotion(from_type, to1_type));
bool isPromotion2 = (intermediate.isIntegralPromotion(from_type, to2_type) ||
intermediate.isFPPromotion(from_type, to2_type));
if (isPromotion2)
return !isPromotion1;
if(isPromotion1)
return false;
// 3. Conversion (integral, floating-point , floating-integral)
bool isConversion1 = (intermediate.isIntegralConversion(from_type, to1_type) ||
intermediate.isFPConversion(from_type, to1_type) ||
intermediate.isFPIntegralConversion(from_type, to1_type));
bool isConversion2 = (intermediate.isIntegralConversion(from_type, to2_type) ||
intermediate.isFPConversion(from_type, to2_type) ||
intermediate.isFPIntegralConversion(from_type, to2_type));
return isConversion2 && !isConversion1;
};
// for ambiguity reporting
bool tie = false;
// send to the generic selector
const TFunction* bestMatch = selectFunction(candidateList, call, convertible, better, tie);
if (bestMatch == nullptr)
error(loc, "no matching overloaded function found", call.getName().c_str(), "");
else if (tie)
error(loc, "ambiguous best function under implicit type conversion", call.getName().c_str(), "");
return bestMatch;
}
//
// Adjust function calls that aren't declared in Vulkan to a
// calls with equivalent effects
//
TIntermTyped* TParseContext::vkRelaxedRemapFunctionCall(const TSourceLoc& loc, TFunction* function, TIntermNode* arguments)
{
TIntermTyped* result = nullptr;
if (function->getBuiltInOp() != EOpNull) {
return nullptr;
}
if (function->getName() == "atomicCounterIncrement") {
// change atomicCounterIncrement into an atomicAdd of 1
TString name("atomicAdd");
TType uintType(EbtUint);
TFunction realFunc(&name, function->getType());
// Use copyParam to avoid shared ownership of the 'type' field
// of the parameter.
for (int i = 0; i < function->getParamCount(); ++i) {
realFunc.addParameter(TParameter().copyParam((*function)[i]));
}
TParameter tmpP = { nullptr, &uintType, {} };
realFunc.addParameter(TParameter().copyParam(tmpP));
arguments = intermediate.growAggregate(arguments, intermediate.addConstantUnion(1, loc, true));
result = handleFunctionCall(loc, &realFunc, arguments);
} else if (function->getName() == "atomicCounterDecrement") {
// change atomicCounterDecrement into an atomicAdd with -1
// and subtract 1 from result, to return post-decrement value
TString name("atomicAdd");
TType uintType(EbtUint);
TFunction realFunc(&name, function->getType());
for (int i = 0; i < function->getParamCount(); ++i) {
realFunc.addParameter(TParameter().copyParam((*function)[i]));
}
TParameter tmpP = { nullptr, &uintType, {} };
realFunc.addParameter(TParameter().copyParam(tmpP));
arguments = intermediate.growAggregate(arguments, intermediate.addConstantUnion(-1, loc, true));
result = handleFunctionCall(loc, &realFunc, arguments);
// post decrement, so that it matches AtomicCounterDecrement semantics
if (result) {
result = handleBinaryMath(loc, "-", EOpSub, result, intermediate.addConstantUnion(1, loc, true));
}
} else if (function->getName() == "atomicCounter") {
// change atomicCounter into a direct read of the variable
if (arguments->getAsTyped()) {
result = arguments->getAsTyped();
}
}
return result;
}
// When a declaration includes a type, but not a variable name, it can be used
// to establish defaults.
void TParseContext::declareTypeDefaults(const TSourceLoc& loc, const TPublicType& publicType)
{
if (publicType.basicType == EbtAtomicUint && publicType.qualifier.hasBinding()) {
if (publicType.qualifier.layoutBinding >= (unsigned int)resources.maxAtomicCounterBindings) {
error(loc, "atomic_uint binding is too large", "binding", "");
return;
}
if (publicType.qualifier.hasOffset())
atomicUintOffsets[publicType.qualifier.layoutBinding] = publicType.qualifier.layoutOffset;
return;
}
if (publicType.arraySizes) {
error(loc, "expect an array name", "", "");
}
if (publicType.qualifier.hasLayout() && !publicType.qualifier.hasBufferReference())
warn(loc, "useless application of layout qualifier", "layout", "");
}
void TParseContext::coopMatTypeParametersCheck(const TSourceLoc& loc, const TPublicType& publicType)
{
if (parsingBuiltins)
return;
if (publicType.isCoopmatKHR()) {
if (publicType.typeParameters == nullptr) {
error(loc, "coopmat missing type parameters", "", "");
return;
}
switch (publicType.typeParameters->basicType) {
case EbtFloat:
case EbtFloat16:
case EbtInt:
case EbtInt8:
case EbtInt16:
case EbtUint:
case EbtUint8:
case EbtUint16:
case EbtSpirvType:
break;
default:
error(loc, "coopmat invalid basic type", TType::getBasicString(publicType.typeParameters->basicType), "");
break;
}
if (publicType.typeParameters->arraySizes->getNumDims() != 4) {
error(loc, "coopmat incorrect number of type parameters", "", "");
return;
}
int use = publicType.typeParameters->arraySizes->getDimSize(3);
if (use < 0 || use > 2) {
error(loc, "coopmat invalid matrix Use", "", "");
return;
}
}
}
bool TParseContext::vkRelaxedRemapUniformVariable(const TSourceLoc& loc, TString& identifier, const TPublicType& publicType,
TArraySizes*, TIntermTyped* initializer, TType& type)
{
vkRelaxedRemapUniformMembers(loc, publicType, type, identifier);
if (parsingBuiltins || symbolTable.atBuiltInLevel() || !symbolTable.atGlobalLevel() ||
type.getQualifier().storage != EvqUniform ||
!(type.containsNonOpaque() || type.getBasicType() == EbtAtomicUint || (type.containsSampler() && type.isStruct()))) {
return false;
}
if (type.getQualifier().hasLocation()) {
warn(loc, "ignoring layout qualifier for uniform", identifier.c_str(), "location");
type.getQualifier().layoutLocation = TQualifier::layoutLocationEnd;
}
if (initializer) {
warn(loc, "Ignoring initializer for uniform", identifier.c_str(), "");
initializer = nullptr;
}
if (type.isArray()) {
// do array size checks here
arraySizesCheck(loc, type.getQualifier(), type.getArraySizes(), initializer, false);
if (arrayQualifierError(loc, type.getQualifier()) || arrayError(loc, type)) {
error(loc, "array param error", identifier.c_str(), "");
}
}
// do some checking on the type as it was declared
layoutTypeCheck(loc, type);
int bufferBinding = TQualifier::layoutBindingEnd;
TVariable* updatedBlock = nullptr;
// Convert atomic_uint into members of a buffer block
if (type.isAtomic()) {
type.setBasicType(EbtUint);
type.getQualifier().storage = EvqBuffer;
type.getQualifier().volatil = true;
type.getQualifier().coherent = true;
// xxTODO: use logic from fixOffset() to apply explicit member offset
bufferBinding = type.getQualifier().layoutBinding;
type.getQualifier().layoutBinding = TQualifier::layoutBindingEnd;
type.getQualifier().explicitOffset = false;
growAtomicCounterBlock(bufferBinding, loc, type, identifier, nullptr);
updatedBlock = atomicCounterBuffers[bufferBinding];
}
if (!updatedBlock) {
growGlobalUniformBlock(loc, type, identifier, nullptr);
updatedBlock = globalUniformBlock;
}
//
// don't assign explicit member offsets here
// if any are assigned, need to be updated here and in the merge/link step
// fixBlockUniformOffsets(updatedBlock->getWritableType().getQualifier(), *updatedBlock->getWritableType().getWritableStruct());
// checks on update buffer object
layoutObjectCheck(loc, *updatedBlock);
TSymbol* symbol = symbolTable.find(identifier);
if (!symbol) {
if (updatedBlock == globalUniformBlock)
error(loc, "error adding uniform to default uniform block", identifier.c_str(), "");
else
error(loc, "error adding atomic counter to atomic counter block", identifier.c_str(), "");
return false;
}
// merge qualifiers
mergeObjectLayoutQualifiers(updatedBlock->getWritableType().getQualifier(), type.getQualifier(), true);
return true;
}
template <typename Function>
static void ForEachOpaque(const TType& type, const TString& path, Function callback)
{
auto recursion = [&callback](const TType& type, const TString& path, bool skipArray, auto& recursion) -> void {
if (!skipArray && type.isArray())
{
std::vector<int> indices(type.getArraySizes()->getNumDims());
for (int flatIndex = 0;
flatIndex < type.getArraySizes()->getCumulativeSize();
++flatIndex)
{
TString subscriptPath = path;
for (size_t dimIndex = 0; dimIndex < indices.size(); ++dimIndex)
{
int index = indices[dimIndex];
subscriptPath.append("[");
subscriptPath.append(String(index));
subscriptPath.append("]");
}
recursion(type, subscriptPath, true, recursion);
for (size_t dimIndex = 0; dimIndex < indices.size(); ++dimIndex)
{
++indices[dimIndex];
if (indices[dimIndex] < type.getArraySizes()->getDimSize(dimIndex))
break;
else
indices[dimIndex] = 0;
}
}
}
else if (type.isStruct() && type.containsOpaque())
{
const TTypeList& types = *type.getStruct();
for (const TTypeLoc& typeLoc : types)
{
TString nextPath = path;
nextPath.append(".");
nextPath.append(typeLoc.type->getFieldName());
recursion(*(typeLoc.type), nextPath, false, recursion);
}
}
else if (type.isOpaque())
{
callback(type, path);
}
};
recursion(type, path, false, recursion);
}
void TParseContext::vkRelaxedRemapUniformMembers(const TSourceLoc& loc, const TPublicType& publicType, const TType& type,
const TString& identifier)
{
if (!type.isStruct() || !type.containsOpaque())
return;
ForEachOpaque(type, identifier,
[&publicType, &loc, this](const TType& type, const TString& path) {
TArraySizes arraySizes = {};
if (type.getArraySizes()) arraySizes = *type.getArraySizes();
TTypeParameters typeParameters = {};
if (type.getTypeParameters()) typeParameters = *type.getTypeParameters();
TPublicType memberType{};
memberType.basicType = type.getBasicType();
memberType.sampler = type.getSampler();
memberType.qualifier = type.getQualifier();
memberType.vectorSize = type.getVectorSize();
memberType.matrixCols = type.getMatrixCols();
memberType.matrixRows = type.getMatrixRows();
memberType.coopmatNV = type.isCoopMatNV();
memberType.coopmatKHR = type.isCoopMatKHR();
memberType.arraySizes = nullptr;
memberType.userDef = nullptr;
memberType.loc = loc;
memberType.typeParameters = (type.getTypeParameters() ? &typeParameters : nullptr);
memberType.spirvType = nullptr;
memberType.qualifier.storage = publicType.qualifier.storage;
memberType.shaderQualifiers = publicType.shaderQualifiers;
TString& structMemberName = *NewPoolTString(path.c_str()); // A copy is required due to declareVariable() signature.
declareVariable(loc, structMemberName, memberType, nullptr, nullptr);
});
}
void TParseContext::vkRelaxedRemapFunctionParameter(TFunction* function, TParameter& param, std::vector<int>* newParams)
{
function->addParameter(param);
if (!param.type->isStruct() || !param.type->containsOpaque())
return;
ForEachOpaque(*param.type, (param.name ? *param.name : param.type->getFieldName()),
[function, param, newParams](const TType& type, const TString& path) {
TString* memberName = NewPoolTString(path.c_str());
TType* memberType = new TType();
memberType->shallowCopy(type);
memberType->getQualifier().storage = param.type->getQualifier().storage;
memberType->clearArraySizes();
TParameter memberParam = {};
memberParam.name = memberName;
memberParam.type = memberType;
memberParam.defaultValue = nullptr;
function->addParameter(memberParam);
if (newParams)
newParams->push_back(function->getParamCount()-1);
});
}
//
// Generates a valid GLSL dereferencing string for the input TIntermNode
//
struct AccessChainTraverser : public TIntermTraverser {
AccessChainTraverser() : TIntermTraverser(false, false, true)
{}
TString path = "";
TStorageQualifier topLevelStorageQualifier = TStorageQualifier::EvqLast;
bool visitBinary(TVisit, TIntermBinary* binary) override {
if (binary->getOp() == EOpIndexDirectStruct)
{
const TTypeList& members = *binary->getLeft()->getType().getStruct();
const TTypeLoc& member =
members[binary->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst()];
TString memberName = member.type->getFieldName();
if (path != "")
path.append(".");
path.append(memberName);
}
if (binary->getOp() == EOpIndexDirect)
{
const TConstUnionArray& indices = binary->getRight()->getAsConstantUnion()->getConstArray();
for (int index = 0; index < indices.size(); ++index)
{
path.append("[");
path.append(String(indices[index].getIConst()));
path.append("]");
}
}
return true;
}
void visitSymbol(TIntermSymbol* symbol) override {
if (symbol->getType().isOpaque())
topLevelStorageQualifier = symbol->getQualifier().storage;
if (!IsAnonymous(symbol->getName()))
path.append(symbol->getName());
}
};
TIntermNode* TParseContext::vkRelaxedRemapFunctionArgument(const TSourceLoc& loc, TFunction* function, TIntermTyped* intermTyped)
{
AccessChainTraverser accessChainTraverser{};
intermTyped->traverse(&accessChainTraverser);
if (accessChainTraverser.topLevelStorageQualifier == TStorageQualifier::EvqUniform)
{
TParameter param = { 0, new TType, {} };
param.type->shallowCopy(intermTyped->getType());
function->addParameter(param);
return intermTyped;
}
TParameter param = { NewPoolTString(accessChainTraverser.path.c_str()), new TType, {} };
param.type->shallowCopy(intermTyped->getType());
std::vector<int> newParams = {};
vkRelaxedRemapFunctionParameter(function, param, &newParams);
if (intermTyped->getType().isOpaque())
{
TIntermNode* remappedArgument = intermTyped;
{
TIntermSymbol* intermSymbol = nullptr;
TSymbol* symbol = symbolTable.find(*param.name);
if (symbol && symbol->getAsVariable())
intermSymbol = intermediate.addSymbol(*symbol->getAsVariable(), loc);
else
{
TVariable* variable = new TVariable(param.name, *param.type);
intermSymbol = intermediate.addSymbol(*variable, loc);
}
remappedArgument = intermSymbol;
}
return remappedArgument;
}
else if (!(intermTyped->isStruct() && intermTyped->getType().containsOpaque()))
return intermTyped;
else
{
TIntermNode* remappedArgument = intermTyped;
{
TSymbol* symbol = symbolTable.find(*param.name);
if (symbol && symbol->getAsVariable())
remappedArgument = intermediate.addSymbol(*symbol->getAsVariable(), loc);
}
if (!newParams.empty())
remappedArgument = intermediate.makeAggregate(remappedArgument, loc);
for (int paramIndex : newParams)
{
TParameter& newParam = function->operator[](paramIndex);
TIntermSymbol* intermSymbol = nullptr;
TSymbol* symbol = symbolTable.find(*newParam.name);
if (symbol && symbol->getAsVariable())
intermSymbol = intermediate.addSymbol(*symbol->getAsVariable(), loc);
else
{
TVariable* variable = new TVariable(newParam.name, *newParam.type);
intermSymbol = intermediate.addSymbol(*variable, loc);
}
remappedArgument = intermediate.growAggregate(remappedArgument, intermSymbol);
}
return remappedArgument;
}
}
TIntermTyped* TParseContext::vkRelaxedRemapDotDereference(const TSourceLoc&, TIntermTyped& base, const TType& member,
const TString& identifier)
{
if (!member.isOpaque())
return &base;
AccessChainTraverser traverser{};
base.traverse(&traverser);
if (!traverser.path.empty())
traverser.path.append(".");
traverser.path.append(identifier);
const TSymbol* symbol = symbolTable.find(traverser.path);
if (!symbol)
return &base;
TIntermTyped* result = intermediate.addSymbol(*symbol->getAsVariable());
result->setType(symbol->getType());
return result;
}
//
// Do everything necessary to handle a variable (non-block) declaration.
// Either redeclaring a variable, or making a new one, updating the symbol
// table, and all error checking.
//
// Returns a subtree node that computes an initializer, if needed.
// Returns nullptr if there is no code to execute for initialization.
//
// 'publicType' is the type part of the declaration (to the left)
// 'arraySizes' is the arrayness tagged on the identifier (to the right)
//
TIntermNode* TParseContext::declareVariable(const TSourceLoc& loc, TString& identifier, const TPublicType& publicType,
TArraySizes* arraySizes, TIntermTyped* initializer)
{
// Make a fresh type that combines the characteristics from the individual
// identifier syntax and the declaration-type syntax.
TType type(publicType);
type.transferArraySizes(arraySizes);
type.copyArrayInnerSizes(publicType.arraySizes);
arrayOfArrayVersionCheck(loc, type.getArraySizes());
if (initializer) {
if (type.getBasicType() == EbtRayQuery) {
error(loc, "ray queries can only be initialized by using the rayQueryInitializeEXT intrinsic:", "=", identifier.c_str());
} else if (type.getBasicType() == EbtHitObjectNV) {
error(loc, "hit objects cannot be initialized using initializers", "=", identifier.c_str());
}
}
if (type.isCoopMatKHR()) {
intermediate.setUseVulkanMemoryModel();
intermediate.setUseStorageBuffer();
if (!publicType.typeParameters || !publicType.typeParameters->arraySizes ||
publicType.typeParameters->arraySizes->getNumDims() != 3) {
error(loc, "unexpected number type parameters", identifier.c_str(), "");
}
if (publicType.typeParameters) {
if (!isTypeFloat(publicType.typeParameters->basicType) &&
!isTypeInt(publicType.typeParameters->basicType) && publicType.typeParameters->basicType != EbtSpirvType) {
error(loc, "expected 8, 16, 32, or 64 bit signed or unsigned integer or 16, 32, or 64 bit float type", identifier.c_str(), "");
}
}
}
else if (type.isCoopMatNV()) {
intermediate.setUseVulkanMemoryModel();
intermediate.setUseStorageBuffer();
if (!publicType.typeParameters || publicType.typeParameters->arraySizes->getNumDims() != 4) {
error(loc, "expected four type parameters", identifier.c_str(), "");
}
if (publicType.typeParameters) {
if (isTypeFloat(publicType.basicType) &&
publicType.typeParameters->arraySizes->getDimSize(0) != 16 &&
publicType.typeParameters->arraySizes->getDimSize(0) != 32 &&
publicType.typeParameters->arraySizes->getDimSize(0) != 64) {
error(loc, "expected 16, 32, or 64 bits for first type parameter", identifier.c_str(), "");
}
if (isTypeInt(publicType.basicType) &&
publicType.typeParameters->arraySizes->getDimSize(0) != 8 &&
publicType.typeParameters->arraySizes->getDimSize(0) != 16 &&
publicType.typeParameters->arraySizes->getDimSize(0) != 32) {
error(loc, "expected 8, 16, or 32 bits for first type parameter", identifier.c_str(), "");
}
}
} else {
if (publicType.typeParameters && publicType.typeParameters->arraySizes->getNumDims() != 0) {
error(loc, "unexpected type parameters", identifier.c_str(), "");
}
}
if (voidErrorCheck(loc, identifier, type.getBasicType()))
return nullptr;
if (initializer)
rValueErrorCheck(loc, "initializer", initializer);
else
nonInitConstCheck(loc, identifier, type);
samplerCheck(loc, type, identifier, initializer);
transparentOpaqueCheck(loc, type, identifier);
atomicUintCheck(loc, type, identifier);
accStructCheck(loc, type, identifier);
checkAndResizeMeshViewDim(loc, type, /*isBlockMember*/ false);
if (type.getQualifier().storage == EvqConst && type.containsReference()) {
error(loc, "variables with reference type can't have qualifier 'const'", "qualifier", "");
}
if (type.getQualifier().storage != EvqUniform && type.getQualifier().storage != EvqBuffer) {
if (type.contains16BitFloat())
requireFloat16Arithmetic(loc, "qualifier", "float16 types can only be in uniform block or buffer storage");
if (type.contains16BitInt())
requireInt16Arithmetic(loc, "qualifier", "(u)int16 types can only be in uniform block or buffer storage");
if (type.contains8BitInt())
requireInt8Arithmetic(loc, "qualifier", "(u)int8 types can only be in uniform block or buffer storage");
}
if (type.getQualifier().storage == EvqtaskPayloadSharedEXT)
intermediate.addTaskPayloadEXTCount();
if (type.getQualifier().storage == EvqShared && type.containsCoopMat())
error(loc, "qualifier", "Cooperative matrix types must not be used in shared memory", "");
if (profile == EEsProfile) {
if (type.getQualifier().isPipeInput() && type.getBasicType() == EbtStruct) {
if (type.getQualifier().isArrayedIo(language)) {
TType perVertexType(type, 0);
if (perVertexType.containsArray() && perVertexType.containsBuiltIn() == false) {
error(loc, "A per vertex structure containing an array is not allowed as input in ES", type.getTypeName().c_str(), "");
}
}
else if (type.containsArray() && type.containsBuiltIn() == false) {
error(loc, "A structure containing an array is not allowed as input in ES", type.getTypeName().c_str(), "");
}
if (type.containsStructure())
error(loc, "A structure containing an struct is not allowed as input in ES", type.getTypeName().c_str(), "");
}
}
if (identifier != "gl_FragCoord" && (publicType.shaderQualifiers.originUpperLeft || publicType.shaderQualifiers.pixelCenterInteger))
error(loc, "can only apply origin_upper_left and pixel_center_origin to gl_FragCoord", "layout qualifier", "");
if (identifier != "gl_FragDepth" && publicType.shaderQualifiers.getDepth() != EldNone)
error(loc, "can only apply depth layout to gl_FragDepth", "layout qualifier", "");
if (identifier != "gl_FragStencilRefARB" && publicType.shaderQualifiers.getStencil() != ElsNone)
error(loc, "can only apply depth layout to gl_FragStencilRefARB", "layout qualifier", "");
// Check for redeclaration of built-ins and/or attempting to declare a reserved name
TSymbol* symbol = redeclareBuiltinVariable(loc, identifier, type.getQualifier(), publicType.shaderQualifiers);
if (symbol == nullptr)
reservedErrorCheck(loc, identifier);
if (symbol == nullptr && spvVersion.vulkan > 0 && spvVersion.vulkanRelaxed) {
bool remapped = vkRelaxedRemapUniformVariable(loc, identifier, publicType, arraySizes, initializer, type);
if (remapped) {
return nullptr;
}
}
inheritGlobalDefaults(type.getQualifier());
// Declare the variable
if (type.isArray()) {
// Check that implicit sizing is only where allowed.
arraySizesCheck(loc, type.getQualifier(), type.getArraySizes(), initializer, false);
if (! arrayQualifierError(loc, type.getQualifier()) && ! arrayError(loc, type))
declareArray(loc, identifier, type, symbol);
if (initializer) {
profileRequires(loc, ENoProfile, 120, E_GL_3DL_array_objects, "initializer");
profileRequires(loc, EEsProfile, 300, nullptr, "initializer");
}
} else {
// non-array case
if (symbol == nullptr)
symbol = declareNonArray(loc, identifier, type);
else if (type != symbol->getType())
error(loc, "cannot change the type of", "redeclaration", symbol->getName().c_str());
}
if (symbol == nullptr)
return nullptr;
// Deal with initializer
TIntermNode* initNode = nullptr;
if (symbol != nullptr && initializer) {
TVariable* variable = symbol->getAsVariable();
if (! variable) {
error(loc, "initializer requires a variable, not a member", identifier.c_str(), "");
return nullptr;
}
initNode = executeInitializer(loc, initializer, variable);
}
// look for errors in layout qualifier use
layoutObjectCheck(loc, *symbol);
// fix up
fixOffset(loc, *symbol);
return initNode;
}
// Pick up global defaults from the provide global defaults into dst.
void TParseContext::inheritGlobalDefaults(TQualifier& dst) const
{
if (dst.storage == EvqVaryingOut) {
if (! dst.hasStream() && language == EShLangGeometry)
dst.layoutStream = globalOutputDefaults.layoutStream;
if (! dst.hasXfbBuffer())
dst.layoutXfbBuffer = globalOutputDefaults.layoutXfbBuffer;
}
}
//
// Make an internal-only variable whose name is for debug purposes only
// and won't be searched for. Callers will only use the return value to use
// the variable, not the name to look it up. It is okay if the name
// is the same as other names; there won't be any conflict.
//
TVariable* TParseContext::makeInternalVariable(const char* name, const TType& type) const
{
TString* nameString = NewPoolTString(name);
TVariable* variable = new TVariable(nameString, type);
symbolTable.makeInternalVariable(*variable);
return variable;
}
//
// Declare a non-array variable, the main point being there is no redeclaration
// for resizing allowed.
//
// Return the successfully declared variable.
//
TVariable* TParseContext::declareNonArray(const TSourceLoc& loc, const TString& identifier, const TType& type)
{
// make a new variable
TVariable* variable = new TVariable(&identifier, type);
ioArrayCheck(loc, type, identifier);
// add variable to symbol table
if (symbolTable.insert(*variable)) {
if (symbolTable.atGlobalLevel())
trackLinkage(*variable);
return variable;
}
error(loc, "redefinition", variable->getName().c_str(), "");
return nullptr;
}
//
// Handle all types of initializers from the grammar.
//
// Returning nullptr just means there is no code to execute to handle the
// initializer, which will, for example, be the case for constant initializers.
//
TIntermNode* TParseContext::executeInitializer(const TSourceLoc& loc, TIntermTyped* initializer, TVariable* variable)
{
// A null initializer is an aggregate that hasn't had an op assigned yet
// (still EOpNull, no relation to nullInit), and has no children.
bool nullInit = initializer->getAsAggregate() && initializer->getAsAggregate()->getOp() == EOpNull &&
initializer->getAsAggregate()->getSequence().size() == 0;
//
// Identifier must be of type constant, a global, or a temporary, and
// starting at version 120, desktop allows uniforms to have initializers.
//
TStorageQualifier qualifier = variable->getType().getQualifier().storage;
if (! (qualifier == EvqTemporary || qualifier == EvqGlobal || qualifier == EvqConst ||
(qualifier == EvqUniform && !isEsProfile() && version >= 120))) {
if (qualifier == EvqShared) {
// GL_EXT_null_initializer allows this for shared, if it's a null initializer
if (nullInit) {
const char* feature = "initialization with shared qualifier";
profileRequires(loc, EEsProfile, 0, E_GL_EXT_null_initializer, feature);
profileRequires(loc, ~EEsProfile, 0, E_GL_EXT_null_initializer, feature);
} else {
error(loc, "initializer can only be a null initializer ('{}')", "shared", "");
}
} else {
error(loc, " cannot initialize this type of qualifier ",
variable->getType().getStorageQualifierString(), "");
return nullptr;
}
}
if (nullInit) {
// only some types can be null initialized
if (variable->getType().containsUnsizedArray()) {
error(loc, "null initializers can't size unsized arrays", "{}", "");
return nullptr;
}
if (variable->getType().containsOpaque()) {
error(loc, "null initializers can't be used on opaque values", "{}", "");
return nullptr;
}
variable->getWritableType().getQualifier().setNullInit();
return nullptr;
}
arrayObjectCheck(loc, variable->getType(), "array initializer");
//
// If the initializer was from braces { ... }, we convert the whole subtree to a
// constructor-style subtree, allowing the rest of the code to operate
// identically for both kinds of initializers.
//
// Type can't be deduced from the initializer list, so a skeletal type to
// follow has to be passed in. Constness and specialization-constness
// should be deduced bottom up, not dictated by the skeletal type.
//
TType skeletalType;
skeletalType.shallowCopy(variable->getType());
skeletalType.getQualifier().makeTemporary();
initializer = convertInitializerList(loc, skeletalType, initializer);
if (! initializer) {
// error recovery; don't leave const without constant values
if (qualifier == EvqConst)
variable->getWritableType().getQualifier().makeTemporary();
return nullptr;
}
// Fix outer arrayness if variable is unsized, getting size from the initializer
if (initializer->getType().isSizedArray() && variable->getType().isUnsizedArray())
variable->getWritableType().changeOuterArraySize(initializer->getType().getOuterArraySize());
// Inner arrayness can also get set by an initializer
if (initializer->getType().isArrayOfArrays() && variable->getType().isArrayOfArrays() &&
initializer->getType().getArraySizes()->getNumDims() ==
variable->getType().getArraySizes()->getNumDims()) {
// adopt unsized sizes from the initializer's sizes
for (int d = 1; d < variable->getType().getArraySizes()->getNumDims(); ++d) {
if (variable->getType().getArraySizes()->getDimSize(d) == UnsizedArraySize) {
variable->getWritableType().getArraySizes()->setDimSize(d,
initializer->getType().getArraySizes()->getDimSize(d));
}
}
}
// Uniforms require a compile-time constant initializer
if (qualifier == EvqUniform && ! initializer->getType().getQualifier().isFrontEndConstant()) {
error(loc, "uniform initializers must be constant", "=", "'%s'",
variable->getType().getCompleteString(intermediate.getEnhancedMsgs()).c_str());
variable->getWritableType().getQualifier().makeTemporary();
return nullptr;
}
// Global consts require a constant initializer (specialization constant is okay)
if (qualifier == EvqConst && symbolTable.atGlobalLevel() && ! initializer->getType().getQualifier().isConstant()) {
error(loc, "global const initializers must be constant", "=", "'%s'",
variable->getType().getCompleteString(intermediate.getEnhancedMsgs()).c_str());
variable->getWritableType().getQualifier().makeTemporary();
return nullptr;
}
// Const variables require a constant initializer, depending on version
if (qualifier == EvqConst) {
if (! initializer->getType().getQualifier().isConstant()) {
const char* initFeature = "non-constant initializer";
requireProfile(loc, ~EEsProfile, initFeature);
profileRequires(loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature);
variable->getWritableType().getQualifier().storage = EvqConstReadOnly;
qualifier = EvqConstReadOnly;
}
} else {
// Non-const global variables in ES need a const initializer.
//
// "In declarations of global variables with no storage qualifier or with a const
// qualifier any initializer must be a constant expression."
if (symbolTable.atGlobalLevel() && ! initializer->getType().getQualifier().isConstant()) {
const char* initFeature =
"non-constant global initializer (needs GL_EXT_shader_non_constant_global_initializers)";
if (isEsProfile()) {
if (relaxedErrors() && ! extensionTurnedOn(E_GL_EXT_shader_non_constant_global_initializers))
warn(loc, "not allowed in this version", initFeature, "");
else
profileRequires(loc, EEsProfile, 0, E_GL_EXT_shader_non_constant_global_initializers, initFeature);
}
}
}
if (qualifier == EvqConst || qualifier == EvqUniform) {
// Compile-time tagging of the variable with its constant value...
initializer = intermediate.addConversion(EOpAssign, variable->getType(), initializer);
if (! initializer || ! initializer->getType().getQualifier().isConstant() ||
variable->getType() != initializer->getType()) {
error(loc, "non-matching or non-convertible constant type for const initializer",
variable->getType().getStorageQualifierString(), "");
variable->getWritableType().getQualifier().makeTemporary();
return nullptr;
}
// We either have a folded constant in getAsConstantUnion, or we have to use
// the initializer's subtree in the AST to represent the computation of a
// specialization constant.
assert(initializer->getAsConstantUnion() || initializer->getType().getQualifier().isSpecConstant());
if (initializer->getAsConstantUnion())
variable->setConstArray(initializer->getAsConstantUnion()->getConstArray());
else {
// It's a specialization constant.
variable->getWritableType().getQualifier().makeSpecConstant();
// Keep the subtree that computes the specialization constant with the variable.
// Later, a symbol node will adopt the subtree from the variable.
variable->setConstSubtree(initializer);
}
} else {
// normal assigning of a value to a variable...
specializationCheck(loc, initializer->getType(), "initializer");
TIntermSymbol* intermSymbol = intermediate.addSymbol(*variable, loc);
TIntermTyped* initNode = intermediate.addAssign(EOpAssign, intermSymbol, initializer, loc);
if (! initNode)
assignError(loc, "=", intermSymbol->getCompleteString(intermediate.getEnhancedMsgs()), initializer->getCompleteString(intermediate.getEnhancedMsgs()));
return initNode;
}
return nullptr;
}
//
// Reprocess any initializer-list (the "{ ... }" syntax) parts of the
// initializer.
//
// Need to hierarchically assign correct types and implicit
// conversions. Will do this mimicking the same process used for
// creating a constructor-style initializer, ensuring we get the
// same form. However, it has to in parallel walk the 'type'
// passed in, as type cannot be deduced from an initializer list.
//
TIntermTyped* TParseContext::convertInitializerList(const TSourceLoc& loc, const TType& type, TIntermTyped* initializer)
{
// Will operate recursively. Once a subtree is found that is constructor style,
// everything below it is already good: Only the "top part" of the initializer
// can be an initializer list, where "top part" can extend for several (or all) levels.
// see if we have bottomed out in the tree within the initializer-list part
TIntermAggregate* initList = initializer->getAsAggregate();
if (! initList || initList->getOp() != EOpNull)
return initializer;
// Of the initializer-list set of nodes, need to process bottom up,
// so recurse deep, then process on the way up.
// Go down the tree here...
if (type.isArray()) {
// The type's array might be unsized, which could be okay, so base sizes on the size of the aggregate.
// Later on, initializer execution code will deal with array size logic.
TType arrayType;
arrayType.shallowCopy(type); // sharing struct stuff is fine
arrayType.copyArraySizes(*type.getArraySizes()); // but get a fresh copy of the array information, to edit below
// edit array sizes to fill in unsized dimensions
arrayType.changeOuterArraySize((int)initList->getSequence().size());
TIntermTyped* firstInit = initList->getSequence()[0]->getAsTyped();
if (arrayType.isArrayOfArrays() && firstInit->getType().isArray() &&
arrayType.getArraySizes()->getNumDims() == firstInit->getType().getArraySizes()->getNumDims() + 1) {
for (int d = 1; d < arrayType.getArraySizes()->getNumDims(); ++d) {
if (arrayType.getArraySizes()->getDimSize(d) == UnsizedArraySize)
arrayType.getArraySizes()->setDimSize(d, firstInit->getType().getArraySizes()->getDimSize(d - 1));
}
}
TType elementType(arrayType, 0); // dereferenced type
for (size_t i = 0; i < initList->getSequence().size(); ++i) {
initList->getSequence()[i] = convertInitializerList(loc, elementType, initList->getSequence()[i]->getAsTyped());
if (initList->getSequence()[i] == nullptr)
return nullptr;
}
return addConstructor(loc, initList, arrayType);
} else if (type.isStruct()) {
if (type.getStruct()->size() != initList->getSequence().size()) {
error(loc, "wrong number of structure members", "initializer list", "");
return nullptr;
}
for (size_t i = 0; i < type.getStruct()->size(); ++i) {
initList->getSequence()[i] = convertInitializerList(loc, *(*type.getStruct())[i].type, initList->getSequence()[i]->getAsTyped());
if (initList->getSequence()[i] == nullptr)
return nullptr;
}
} else if (type.isMatrix()) {
if (type.getMatrixCols() != (int)initList->getSequence().size()) {
error(loc, "wrong number of matrix columns:", "initializer list", type.getCompleteString(intermediate.getEnhancedMsgs()).c_str());
return nullptr;
}
TType vectorType(type, 0); // dereferenced type
for (int i = 0; i < type.getMatrixCols(); ++i) {
initList->getSequence()[i] = convertInitializerList(loc, vectorType, initList->getSequence()[i]->getAsTyped());
if (initList->getSequence()[i] == nullptr)
return nullptr;
}
} else if (type.isVector()) {
if (type.getVectorSize() != (int)initList->getSequence().size()) {
error(loc, "wrong vector size (or rows in a matrix column):", "initializer list", type.getCompleteString(intermediate.getEnhancedMsgs()).c_str());
return nullptr;
}
TBasicType destType = type.getBasicType();
for (int i = 0; i < type.getVectorSize(); ++i) {
TBasicType initType = initList->getSequence()[i]->getAsTyped()->getBasicType();
if (destType != initType && !intermediate.canImplicitlyPromote(initType, destType)) {
error(loc, "type mismatch in initializer list", "initializer list", type.getCompleteString(intermediate.getEnhancedMsgs()).c_str());
return nullptr;
}
}
} else {
error(loc, "unexpected initializer-list type:", "initializer list", type.getCompleteString(intermediate.getEnhancedMsgs()).c_str());
return nullptr;
}
// Now that the subtree is processed, process this node as if the
// initializer list is a set of arguments to a constructor.
TIntermNode* emulatedConstructorArguments;
if (initList->getSequence().size() == 1)
emulatedConstructorArguments = initList->getSequence()[0];
else
emulatedConstructorArguments = initList;
return addConstructor(loc, emulatedConstructorArguments, type);
}
//
// Test for the correctness of the parameters passed to various constructor functions
// and also convert them to the right data type, if allowed and required.
//
// 'node' is what to construct from.
// 'type' is what type to construct.
//
// Returns nullptr for an error or the constructed node (aggregate or typed) for no error.
//
TIntermTyped* TParseContext::addConstructor(const TSourceLoc& loc, TIntermNode* node, const TType& type)
{
if (node == nullptr || node->getAsTyped() == nullptr)
return nullptr;
rValueErrorCheck(loc, "constructor", node->getAsTyped());
TIntermAggregate* aggrNode = node->getAsAggregate();
TOperator op = intermediate.mapTypeToConstructorOp(type);
// Combined texture-sampler constructors are completely semantic checked
// in constructorTextureSamplerError()
if (op == EOpConstructTextureSampler) {
if (aggrNode != nullptr) {
if (aggrNode->getSequence()[1]->getAsTyped()->getType().getSampler().shadow) {
// Transfer depth into the texture (SPIR-V image) type, as a hint
// for tools to know this texture/image is a depth image.
aggrNode->getSequence()[0]->getAsTyped()->getWritableType().getSampler().shadow = true;
}
return intermediate.setAggregateOperator(aggrNode, op, type, loc);
}
}
TTypeList::const_iterator memberTypes;
if (op == EOpConstructStruct)
memberTypes = type.getStruct()->begin();
TType elementType;
if (type.isArray()) {
TType dereferenced(type, 0);
elementType.shallowCopy(dereferenced);
} else
elementType.shallowCopy(type);
bool singleArg;
if (aggrNode) {
if (aggrNode->getOp() != EOpNull)
singleArg = true;
else
singleArg = false;
} else
singleArg = true;
TIntermTyped *newNode;
if (singleArg) {
// If structure constructor or array constructor is being called
// for only one parameter inside the structure, we need to call constructAggregate function once.
if (type.isArray())
newNode = constructAggregate(node, elementType, 1, node->getLoc());
else if (op == EOpConstructStruct)
newNode = constructAggregate(node, *(*memberTypes).type, 1, node->getLoc());
else
newNode = constructBuiltIn(type, op, node->getAsTyped(), node->getLoc(), false);
if (newNode && (type.isArray() || op == EOpConstructStruct))
newNode = intermediate.setAggregateOperator(newNode, EOpConstructStruct, type, loc);
return newNode;
}
//
// Handle list of arguments.
//
TIntermSequence &sequenceVector = aggrNode->getSequence(); // Stores the information about the parameter to the constructor
// if the structure constructor contains more than one parameter, then construct
// each parameter
int paramCount = 0; // keeps track of the constructor parameter number being checked
// We don't know "top down" whether type is a specialization constant,
// but a const becomes a specialization constant if any of its children are.
bool hasSpecConst = false;
bool isConstConstructor = true;
// for each parameter to the constructor call, check to see if the right type is passed or convert them
// to the right type if possible (and allowed).
// for structure constructors, just check if the right type is passed, no conversion is allowed.
for (TIntermSequence::iterator p = sequenceVector.begin();
p != sequenceVector.end(); p++, paramCount++) {
if (type.isArray())
newNode = constructAggregate(*p, elementType, paramCount+1, node->getLoc());
else if (op == EOpConstructStruct)
newNode = constructAggregate(*p, *(memberTypes[paramCount]).type, paramCount+1, node->getLoc());
else
newNode = constructBuiltIn(type, op, (*p)->getAsTyped(), node->getLoc(), true);
if (newNode) {
*p = newNode;
if (!newNode->getType().getQualifier().isConstant())
isConstConstructor = false;
if (newNode->getType().getQualifier().isSpecConstant())
hasSpecConst = true;
} else
return nullptr;
}
TIntermTyped* ret_node = intermediate.setAggregateOperator(aggrNode, op, type, loc);
const char *specConstantCompositeExt[] = { E_GL_EXT_spec_constant_composites };
if (checkExtensionsRequested(loc, 1, specConstantCompositeExt, "spec constant aggregate constructor")) {
if (isConstConstructor && hasSpecConst) {
ret_node->getWritableType().getQualifier().makeSpecConstant();
}
}
TIntermAggregate *agg_node = ret_node->getAsAggregate();
if (agg_node && (agg_node->isVector() || agg_node->isArray() || agg_node->isMatrix()))
agg_node->updatePrecision();
return ret_node;
}
// Function for constructor implementation. Calls addUnaryMath with appropriate EOp value
// for the parameter to the constructor (passed to this function). Essentially, it converts
// the parameter types correctly. If a constructor expects an int (like ivec2) and is passed a
// float, then float is converted to int.
//
// Returns nullptr for an error or the constructed node.
//
TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, TIntermTyped* node, const TSourceLoc& loc,
bool subset)
{
// If we are changing a matrix in both domain of basic type and to a non matrix,
// do the shape change first (by default, below, basic type is changed before shape).
// This avoids requesting a matrix of a new type that is going to be discarded anyway.
// TODO: This could be generalized to more type combinations, but that would require
// more extensive testing and full algorithm rework. For now, the need to do two changes makes
// the recursive call work, and avoids the most egregious case of creating integer matrices.
if (node->getType().isMatrix() && (type.isScalar() || type.isVector()) &&
type.isFloatingDomain() != node->getType().isFloatingDomain()) {
TType transitionType(node->getBasicType(), glslang::EvqTemporary, type.getVectorSize(), 0, 0, node->isVector());
TOperator transitionOp = intermediate.mapTypeToConstructorOp(transitionType);
node = constructBuiltIn(transitionType, transitionOp, node, loc, false);
}
TIntermTyped* newNode;
TOperator basicOp;
//
// First, convert types as needed.
//
switch (op) {
case EOpConstructVec2:
case EOpConstructVec3:
case EOpConstructVec4:
case EOpConstructMat2x2:
case EOpConstructMat2x3:
case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3x3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4x4:
case EOpConstructFloat:
basicOp = EOpConstructFloat;
break;
case EOpConstructIVec2:
case EOpConstructIVec3:
case EOpConstructIVec4:
case EOpConstructInt:
basicOp = EOpConstructInt;
break;
case EOpConstructUVec2:
if (node->getType().getBasicType() == EbtReference) {
requireExtensions(loc, 1, &E_GL_EXT_buffer_reference_uvec2, "reference conversion to uvec2");
TIntermTyped* newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConvPtrToUvec2, true, node,
type);
return newNode;
} else if (node->getType().getBasicType() == EbtSampler) {
requireExtensions(loc, 1, &E_GL_ARB_bindless_texture, "sampler conversion to uvec2");
// force the basic type of the constructor param to uvec2, otherwise spv builder will
// report some errors
TIntermTyped* newSrcNode = intermediate.createConversion(EbtUint, node);
newSrcNode->getAsTyped()->getWritableType().setVectorSize(2);
TIntermTyped* newNode =
intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConstructUVec2, false, newSrcNode, type);
return newNode;
}
[[fallthrough]];
case EOpConstructUVec3:
case EOpConstructUVec4:
case EOpConstructUint:
basicOp = EOpConstructUint;
break;
case EOpConstructBVec2:
case EOpConstructBVec3:
case EOpConstructBVec4:
case EOpConstructBool:
basicOp = EOpConstructBool;
break;
case EOpConstructTextureSampler:
if ((node->getType().getBasicType() == EbtUint || node->getType().getBasicType() == EbtInt) &&
node->getType().getVectorSize() == 2) {
requireExtensions(loc, 1, &E_GL_ARB_bindless_texture, "ivec2/uvec2 convert to texture handle");
// No matter ivec2 or uvec2, Set EOpPackUint2x32 just to generate an opBitcast op code
TIntermTyped* newNode =
intermediate.addBuiltInFunctionCall(node->getLoc(), EOpPackUint2x32, true, node, type);
return newNode;
}
[[fallthrough]];
case EOpConstructDVec2:
case EOpConstructDVec3:
case EOpConstructDVec4:
case EOpConstructDMat2x2:
case EOpConstructDMat2x3:
case EOpConstructDMat2x4:
case EOpConstructDMat3x2:
case EOpConstructDMat3x3:
case EOpConstructDMat3x4:
case EOpConstructDMat4x2:
case EOpConstructDMat4x3:
case EOpConstructDMat4x4:
case EOpConstructDouble:
basicOp = EOpConstructDouble;
break;
case EOpConstructF16Vec2:
case EOpConstructF16Vec3:
case EOpConstructF16Vec4:
case EOpConstructF16Mat2x2:
case EOpConstructF16Mat2x3:
case EOpConstructF16Mat2x4:
case EOpConstructF16Mat3x2:
case EOpConstructF16Mat3x3:
case EOpConstructF16Mat3x4:
case EOpConstructF16Mat4x2:
case EOpConstructF16Mat4x3:
case EOpConstructF16Mat4x4:
case EOpConstructFloat16:
basicOp = EOpConstructFloat16;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
// and do not generate any conversion if it is an identity conversion, i.e. float16_t(<float16_t> var)
if (!intermediate.getArithemeticFloat16Enabled() && (node->getBasicType() != EbtFloat16)) {
TType tempType(EbtFloat, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType()) {
TOperator aggregateOp;
if (op == EOpConstructFloat16)
aggregateOp = EOpConstructFloat;
else
aggregateOp = (TOperator)(EOpConstructVec2 + op - EOpConstructF16Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
}
newNode = intermediate.addConversion(EbtFloat16, newNode);
return newNode;
}
break;
case EOpConstructI8Vec2:
case EOpConstructI8Vec3:
case EOpConstructI8Vec4:
case EOpConstructInt8:
basicOp = EOpConstructInt8;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
// and do not generate any conversion if it is an identity conversion, i.e. int8_t(<int8_t> var)
if (!intermediate.getArithemeticInt8Enabled() && (node->getBasicType() != EbtInt8)) {
TType tempType(EbtInt, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType()) {
TOperator aggregateOp;
if (op == EOpConstructInt8)
aggregateOp = EOpConstructInt;
else
aggregateOp = (TOperator)(EOpConstructIVec2 + op - EOpConstructI8Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
}
newNode = intermediate.addConversion(EbtInt8, newNode);
return newNode;
}
break;
case EOpConstructU8Vec2:
case EOpConstructU8Vec3:
case EOpConstructU8Vec4:
case EOpConstructUint8:
basicOp = EOpConstructUint8;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
// and do not generate any conversion if it is an identity conversion, i.e. uint8_t(<uint8_t> var)
if (!intermediate.getArithemeticInt8Enabled() && (node->getBasicType() != EbtUint8)) {
TType tempType(EbtUint, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType()) {
TOperator aggregateOp;
if (op == EOpConstructUint8)
aggregateOp = EOpConstructUint;
else
aggregateOp = (TOperator)(EOpConstructUVec2 + op - EOpConstructU8Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
}
newNode = intermediate.addConversion(EbtUint8, newNode);
return newNode;
}
break;
case EOpConstructI16Vec2:
case EOpConstructI16Vec3:
case EOpConstructI16Vec4:
case EOpConstructInt16:
basicOp = EOpConstructInt16;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
// and do not generate any conversion if it is an identity conversion, i.e. int16_t(<int16_t> var)
if (!intermediate.getArithemeticInt16Enabled() && (node->getBasicType() != EbtInt16)) {
TType tempType(EbtInt, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType()) {
TOperator aggregateOp;
if (op == EOpConstructInt16)
aggregateOp = EOpConstructInt;
else
aggregateOp = (TOperator)(EOpConstructIVec2 + op - EOpConstructI16Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
}
newNode = intermediate.addConversion(EbtInt16, newNode);
return newNode;
}
break;
case EOpConstructU16Vec2:
case EOpConstructU16Vec3:
case EOpConstructU16Vec4:
case EOpConstructUint16:
basicOp = EOpConstructUint16;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
// and do not generate any conversion if it is an identity conversion, i.e. uint16_t(<uint16_t> var)
if (!intermediate.getArithemeticInt16Enabled() && (node->getBasicType() != EbtUint16)) {
TType tempType(EbtUint, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType()) {
TOperator aggregateOp;
if (op == EOpConstructUint16)
aggregateOp = EOpConstructUint;
else
aggregateOp = (TOperator)(EOpConstructUVec2 + op - EOpConstructU16Vec2);
newNode = intermediate.setAggregateOperator(newNode, aggregateOp, tempType, node->getLoc());
}
newNode = intermediate.addConversion(EbtUint16, newNode);
return newNode;
}
break;
case EOpConstructI64Vec2:
case EOpConstructI64Vec3:
case EOpConstructI64Vec4:
case EOpConstructInt64:
basicOp = EOpConstructInt64;
break;
case EOpConstructUint64:
if (type.isScalar() && node->getType().isReference()) {
TIntermTyped* newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConvPtrToUint64, true, node, type);
return newNode;
}
[[fallthrough]];
case EOpConstructU64Vec2:
case EOpConstructU64Vec3:
case EOpConstructU64Vec4:
basicOp = EOpConstructUint64;
break;
case EOpConstructNonuniform:
// Make a nonuniform copy of node
newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpCopyObject, true, node, type);
return newNode;
case EOpConstructReference:
// construct reference from reference
if (node->getType().isReference()) {
newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConstructReference, true, node, type);
return newNode;
// construct reference from uint64
} else if (node->getType().isScalar() && node->getType().getBasicType() == EbtUint64) {
TIntermTyped* newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConvUint64ToPtr, true, node,
type);
return newNode;
// construct reference from uvec2
} else if (node->getType().isVector() && node->getType().getBasicType() == EbtUint &&
node->getVectorSize() == 2) {
requireExtensions(loc, 1, &E_GL_EXT_buffer_reference_uvec2, "uvec2 conversion to reference");
TIntermTyped* newNode = intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConvUvec2ToPtr, true, node,
type);
return newNode;
} else {
return nullptr;
}
case EOpConstructCooperativeMatrixNV:
case EOpConstructCooperativeMatrixKHR:
if (node->getType() == type) {
return node;
}
if (!node->getType().isCoopMat()) {
if (type.getBasicType() != node->getType().getBasicType()) {
node = intermediate.addConversion(type.getBasicType(), node);
if (node == nullptr)
return nullptr;
}
node = intermediate.setAggregateOperator(node, op, type, node->getLoc());
} else {
TOperator op = EOpNull;
switch (type.getBasicType()) {
default:
assert(0);
break;
case EbtInt:
switch (node->getType().getBasicType()) {
case EbtFloat: op = EOpConvFloatToInt; break;
case EbtFloat16: op = EOpConvFloat16ToInt; break;
case EbtUint8: op = EOpConvUint8ToInt; break;
case EbtInt8: op = EOpConvInt8ToInt; break;
case EbtUint16: op = EOpConvUint16ToInt; break;
case EbtInt16: op = EOpConvInt16ToInt; break;
case EbtUint: op = EOpConvUintToInt; break;
default: assert(0);
}
break;
case EbtUint:
switch (node->getType().getBasicType()) {
case EbtFloat: op = EOpConvFloatToUint; break;
case EbtFloat16: op = EOpConvFloat16ToUint; break;
case EbtUint8: op = EOpConvUint8ToUint; break;
case EbtInt8: op = EOpConvInt8ToUint; break;
case EbtUint16: op = EOpConvUint16ToUint; break;
case EbtInt16: op = EOpConvInt16ToUint; break;
case EbtInt: op = EOpConvIntToUint; break;
default: assert(0);
}
break;
case EbtInt16:
switch (node->getType().getBasicType()) {
case EbtFloat: op = EOpConvFloatToInt16; break;
case EbtFloat16: op = EOpConvFloat16ToInt16; break;
case EbtUint8: op = EOpConvUint8ToInt16; break;
case EbtInt8: op = EOpConvInt8ToInt16; break;
case EbtUint16: op = EOpConvUint16ToInt16; break;
case EbtInt: op = EOpConvIntToInt16; break;
case EbtUint: op = EOpConvUintToInt16; break;
default: assert(0);
}
break;
case EbtUint16:
switch (node->getType().getBasicType()) {
case EbtFloat: op = EOpConvFloatToUint16; break;
case EbtFloat16: op = EOpConvFloat16ToUint16; break;
case EbtUint8: op = EOpConvUint8ToUint16; break;
case EbtInt8: op = EOpConvInt8ToUint16; break;
case EbtInt16: op = EOpConvInt16ToUint16; break;
case EbtInt: op = EOpConvIntToUint16; break;
case EbtUint: op = EOpConvUintToUint16; break;
default: assert(0);
}
break;
case EbtInt8:
switch (node->getType().getBasicType()) {
case EbtFloat: op = EOpConvFloatToInt8; break;
case EbtFloat16: op = EOpConvFloat16ToInt8; break;
case EbtUint8: op = EOpConvUint8ToInt8; break;
case EbtInt16: op = EOpConvInt16ToInt8; break;
case EbtUint16: op = EOpConvUint16ToInt8; break;
case EbtInt: op = EOpConvIntToInt8; break;
case EbtUint: op = EOpConvUintToInt8; break;
default: assert(0);
}
break;
case EbtUint8:
switch (node->getType().getBasicType()) {
case EbtFloat: op = EOpConvFloatToUint8; break;
case EbtFloat16: op = EOpConvFloat16ToUint8; break;
case EbtInt8: op = EOpConvInt8ToUint8; break;
case EbtInt16: op = EOpConvInt16ToUint8; break;
case EbtUint16: op = EOpConvUint16ToUint8; break;
case EbtInt: op = EOpConvIntToUint8; break;
case EbtUint: op = EOpConvUintToUint8; break;
default: assert(0);
}
break;
case EbtFloat:
switch (node->getType().getBasicType()) {
case EbtFloat16: op = EOpConvFloat16ToFloat; break;
case EbtInt8: op = EOpConvInt8ToFloat; break;
case EbtUint8: op = EOpConvUint8ToFloat; break;
case EbtInt16: op = EOpConvInt16ToFloat; break;
case EbtUint16: op = EOpConvUint16ToFloat; break;
case EbtInt: op = EOpConvIntToFloat; break;
case EbtUint: op = EOpConvUintToFloat; break;
default: assert(0);
}
break;
case EbtFloat16:
switch (node->getType().getBasicType()) {
case EbtFloat: op = EOpConvFloatToFloat16; break;
case EbtInt8: op = EOpConvInt8ToFloat16; break;
case EbtUint8: op = EOpConvUint8ToFloat16; break;
case EbtInt16: op = EOpConvInt16ToFloat16; break;
case EbtUint16: op = EOpConvUint16ToFloat16; break;
case EbtInt: op = EOpConvIntToFloat16; break;
case EbtUint: op = EOpConvUintToFloat16; break;
default: assert(0);
}
break;
}
node = intermediate.addUnaryNode(op, node, node->getLoc(), type);
// If it's a (non-specialization) constant, it must be folded.
if (node->getAsUnaryNode()->getOperand()->getAsConstantUnion())
return node->getAsUnaryNode()->getOperand()->getAsConstantUnion()->fold(op, node->getType());
}
return node;
case EOpConstructAccStruct:
if ((node->getType().isScalar() && node->getType().getBasicType() == EbtUint64)) {
// construct acceleration structure from uint64
requireExtensions(loc, Num_ray_tracing_EXTs, ray_tracing_EXTs, "uint64_t conversion to acclerationStructureEXT");
return intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConvUint64ToAccStruct, true, node,
type);
} else if (node->getType().isVector() && node->getType().getBasicType() == EbtUint && node->getVectorSize() == 2) {
// construct acceleration structure from uint64
requireExtensions(loc, Num_ray_tracing_EXTs, ray_tracing_EXTs, "uvec2 conversion to accelerationStructureEXT");
return intermediate.addBuiltInFunctionCall(node->getLoc(), EOpConvUvec2ToAccStruct, true, node,
type);
} else
return nullptr;
default:
error(loc, "unsupported construction", "", "");
return nullptr;
}
newNode = intermediate.addUnaryMath(basicOp, node, node->getLoc());
if (newNode == nullptr) {
error(loc, "can't convert", "constructor", "");
return nullptr;
}
//
// Now, if there still isn't an operation to do the construction, and we need one, add one.
//
// Otherwise, skip out early.
if (subset || (newNode != node && newNode->getType() == type))
return newNode;
// setAggregateOperator will insert a new node for the constructor, as needed.
return intermediate.setAggregateOperator(newNode, op, type, loc);
}
// This function tests for the type of the parameters to the structure or array constructor. Raises
// an error message if the expected type does not match the parameter passed to the constructor.
//
// Returns nullptr for an error or the input node itself if the expected and the given parameter types match.
//
TIntermTyped* TParseContext::constructAggregate(TIntermNode* node, const TType& type, int paramCount, const TSourceLoc& loc)
{
TIntermTyped* converted = intermediate.addConversion(EOpConstructStruct, type, node->getAsTyped());
if (! converted || converted->getType() != type) {
bool enhanced = intermediate.getEnhancedMsgs();
error(loc, "", "constructor", "cannot convert parameter %d from '%s' to '%s'", paramCount,
node->getAsTyped()->getType().getCompleteString(enhanced).c_str(), type.getCompleteString(enhanced).c_str());
return nullptr;
}
return converted;
}
// If a memory qualifier is present in 'to', also make it present in 'from'.
void TParseContext::inheritMemoryQualifiers(const TQualifier& from, TQualifier& to)
{
if (from.isReadOnly())
to.readonly = from.readonly;
if (from.isWriteOnly())
to.writeonly = from.writeonly;
if (from.coherent)
to.coherent = from.coherent;
if (from.volatil)
to.volatil = from.volatil;
if (from.restrict)
to.restrict = from.restrict;
}
//
// Update qualifier layoutBindlessImage & layoutBindlessSampler on block member
//
void TParseContext::updateBindlessQualifier(TType& memberType)
{
if (memberType.containsSampler()) {
if (memberType.isStruct()) {
TTypeList* typeList = memberType.getWritableStruct();
for (unsigned int member = 0; member < typeList->size(); ++member) {
TType* subMemberType = (*typeList)[member].type;
updateBindlessQualifier(*subMemberType);
}
}
else if (memberType.getSampler().isImage()) {
intermediate.setBindlessImageMode(currentCaller, AstRefTypeLayout);
memberType.getQualifier().layoutBindlessImage = true;
}
else {
intermediate.setBindlessTextureMode(currentCaller, AstRefTypeLayout);
memberType.getQualifier().layoutBindlessSampler = true;
}
}
}
//
// Do everything needed to add an interface block.
//
void TParseContext::declareBlock(const TSourceLoc& loc, TTypeList& typeList, const TString* instanceName,
TArraySizes* arraySizes)
{
if (spvVersion.vulkan > 0 && spvVersion.vulkanRelaxed)
blockStorageRemap(loc, blockName, currentBlockQualifier);
blockStageIoCheck(loc, currentBlockQualifier);
blockQualifierCheck(loc, currentBlockQualifier, instanceName != nullptr);
if (arraySizes != nullptr) {
arraySizesCheck(loc, currentBlockQualifier, arraySizes, nullptr, false);
arrayOfArrayVersionCheck(loc, arraySizes);
if (arraySizes->getNumDims() > 1)
requireProfile(loc, ~EEsProfile, "array-of-array of block");
}
// Inherit and check member storage qualifiers WRT to the block-level qualifier.
for (unsigned int member = 0; member < typeList.size(); ++member) {
TType& memberType = *typeList[member].type;
TQualifier& memberQualifier = memberType.getQualifier();
const TSourceLoc& memberLoc = typeList[member].loc;
if (memberQualifier.storage != EvqTemporary && memberQualifier.storage != EvqGlobal && memberQualifier.storage != currentBlockQualifier.storage)
error(memberLoc, "member storage qualifier cannot contradict block storage qualifier", memberType.getFieldName().c_str(), "");
memberQualifier.storage = currentBlockQualifier.storage;
globalQualifierFixCheck(memberLoc, memberQualifier);
inheritMemoryQualifiers(currentBlockQualifier, memberQualifier);
if (currentBlockQualifier.perPrimitiveNV)
memberQualifier.perPrimitiveNV = currentBlockQualifier.perPrimitiveNV;
if (currentBlockQualifier.perViewNV)
memberQualifier.perViewNV = currentBlockQualifier.perViewNV;
if (currentBlockQualifier.perTaskNV)
memberQualifier.perTaskNV = currentBlockQualifier.perTaskNV;
if (currentBlockQualifier.storage == EvqtaskPayloadSharedEXT)
memberQualifier.storage = EvqtaskPayloadSharedEXT;
if (memberQualifier.storage == EvqSpirvStorageClass)
error(memberLoc, "member cannot have a spirv_storage_class qualifier", memberType.getFieldName().c_str(), "");
if (memberQualifier.hasSpirvDecorate() && !memberQualifier.getSpirvDecorate().decorateIds.empty())
error(memberLoc, "member cannot have a spirv_decorate_id qualifier", memberType.getFieldName().c_str(), "");
if ((currentBlockQualifier.storage == EvqUniform || currentBlockQualifier.storage == EvqBuffer) && (memberQualifier.isInterpolation() || memberQualifier.isAuxiliary()))
error(memberLoc, "member of uniform or buffer block cannot have an auxiliary or interpolation qualifier", memberType.getFieldName().c_str(), "");
if (memberType.isArray())
arraySizesCheck(memberLoc, currentBlockQualifier, memberType.getArraySizes(), nullptr, member == typeList.size() - 1);
if (memberQualifier.hasOffset()) {
if (spvVersion.spv == 0) {
profileRequires(memberLoc, ~EEsProfile, 440, E_GL_ARB_enhanced_layouts, "\"offset\" on block member");
profileRequires(memberLoc, EEsProfile, 300, E_GL_ARB_enhanced_layouts, "\"offset\" on block member");
}
}
// For bindless texture, sampler can be declared as uniform/storage block member,
if (memberType.containsOpaque()) {
if (memberType.containsSampler() && extensionTurnedOn(E_GL_ARB_bindless_texture))
updateBindlessQualifier(memberType);
else
error(memberLoc, "member of block cannot be or contain a sampler, image, or atomic_uint type", typeList[member].type->getFieldName().c_str(), "");
}
if (memberType.containsCoopMat())
error(memberLoc, "member of block cannot be or contain a cooperative matrix type", typeList[member].type->getFieldName().c_str(), "");
}
// This might be a redeclaration of a built-in block. If so, redeclareBuiltinBlock() will
// do all the rest.
if (! symbolTable.atBuiltInLevel() && builtInName(*blockName)) {
redeclareBuiltinBlock(loc, typeList, *blockName, instanceName, arraySizes);
return;
}
// Not a redeclaration of a built-in; check that all names are user names.
reservedErrorCheck(loc, *blockName);
if (instanceName)
reservedErrorCheck(loc, *instanceName);
for (unsigned int member = 0; member < typeList.size(); ++member)
reservedErrorCheck(typeList[member].loc, typeList[member].type->getFieldName());
// Make default block qualification, and adjust the member qualifications
TQualifier defaultQualification;
switch (currentBlockQualifier.storage) {
case EvqUniform: defaultQualification = globalUniformDefaults; break;
case EvqBuffer: defaultQualification = globalBufferDefaults; break;
case EvqVaryingIn: defaultQualification = globalInputDefaults; break;
case EvqVaryingOut: defaultQualification = globalOutputDefaults; break;
case EvqShared: defaultQualification = globalSharedDefaults; break;
default: defaultQualification.clear(); break;
}
// Special case for "push_constant uniform", which has a default of std430,
// contrary to normal uniform defaults, and can't have a default tracked for it.
if ((currentBlockQualifier.isPushConstant() && !currentBlockQualifier.hasPacking()) ||
(currentBlockQualifier.isShaderRecord() && !currentBlockQualifier.hasPacking()))
currentBlockQualifier.layoutPacking = ElpStd430;
// Special case for "taskNV in/out", which has a default of std430,
if (currentBlockQualifier.isTaskMemory() && !currentBlockQualifier.hasPacking())
currentBlockQualifier.layoutPacking = ElpStd430;
// fix and check for member layout qualifiers
mergeObjectLayoutQualifiers(defaultQualification, currentBlockQualifier, true);
// "The align qualifier can only be used on blocks or block members, and only for blocks declared with std140 or std430 layouts."
if (currentBlockQualifier.hasAlign()) {
if (defaultQualification.layoutPacking != ElpStd140 &&
defaultQualification.layoutPacking != ElpStd430 &&
defaultQualification.layoutPacking != ElpScalar) {
error(loc, "can only be used with std140, std430, or scalar layout packing", "align", "");
defaultQualification.layoutAlign = -1;
}
}
bool memberWithLocation = false;
bool memberWithoutLocation = false;
bool memberWithPerViewQualifier = false;
for (unsigned int member = 0; member < typeList.size(); ++member) {
TQualifier& memberQualifier = typeList[member].type->getQualifier();
const TSourceLoc& memberLoc = typeList[member].loc;
if (memberQualifier.hasStream()) {
if (defaultQualification.layoutStream != memberQualifier.layoutStream)
error(memberLoc, "member cannot contradict block", "stream", "");
}
// "This includes a block's inheritance of the
// current global default buffer, a block member's inheritance of the block's
// buffer, and the requirement that any *xfb_buffer* declared on a block
// member must match the buffer inherited from the block."
if (memberQualifier.hasXfbBuffer()) {
if (defaultQualification.layoutXfbBuffer != memberQualifier.layoutXfbBuffer)
error(memberLoc, "member cannot contradict block (or what block inherited from global)", "xfb_buffer", "");
}
if (memberQualifier.hasPacking())
error(memberLoc, "member of block cannot have a packing layout qualifier", typeList[member].type->getFieldName().c_str(), "");
if (memberQualifier.hasLocation()) {
const char* feature = "location on block member";
switch (currentBlockQualifier.storage) {
case EvqVaryingIn:
case EvqVaryingOut:
requireProfile(memberLoc, ECoreProfile | ECompatibilityProfile | EEsProfile, feature);
profileRequires(memberLoc, ECoreProfile | ECompatibilityProfile, 440, E_GL_ARB_enhanced_layouts, feature);
profileRequires(memberLoc, EEsProfile, 320, Num_AEP_shader_io_blocks, AEP_shader_io_blocks, feature);
memberWithLocation = true;
break;
default:
error(memberLoc, "can only use in an in/out block", feature, "");
break;
}
} else
memberWithoutLocation = true;
// "The offset qualifier can only be used on block members of blocks declared with std140 or std430 layouts."
// "The align qualifier can only be used on blocks or block members, and only for blocks declared with std140 or std430 layouts."
if (memberQualifier.hasAlign() || memberQualifier.hasOffset()) {
if (defaultQualification.layoutPacking != ElpStd140 &&
defaultQualification.layoutPacking != ElpStd430 &&
defaultQualification.layoutPacking != ElpScalar)
error(memberLoc, "can only be used with std140, std430, or scalar layout packing", "offset/align", "");
}
if (memberQualifier.isPerView()) {
memberWithPerViewQualifier = true;
}
TQualifier newMemberQualification = defaultQualification;
mergeQualifiers(memberLoc, newMemberQualification, memberQualifier, false);
memberQualifier = newMemberQualification;
}
layoutMemberLocationArrayCheck(loc, memberWithLocation, arraySizes);
// Ensure that the block has an XfbBuffer assigned. This is needed
// because if the block has a XfbOffset assigned, then it is
// assumed that it has implicitly assigned the current global
// XfbBuffer, and because it's members need to be assigned a
// XfbOffset if they lack it.
if (currentBlockQualifier.storage == EvqVaryingOut && globalOutputDefaults.hasXfbBuffer()) {
if (!currentBlockQualifier.hasXfbBuffer() && currentBlockQualifier.hasXfbOffset())
currentBlockQualifier.layoutXfbBuffer = globalOutputDefaults.layoutXfbBuffer;
}
// Process the members
fixBlockLocations(loc, currentBlockQualifier, typeList, memberWithLocation, memberWithoutLocation);
fixXfbOffsets(currentBlockQualifier, typeList);
fixBlockUniformOffsets(currentBlockQualifier, typeList);
fixBlockUniformLayoutMatrix(currentBlockQualifier, &typeList, nullptr);
fixBlockUniformLayoutPacking(currentBlockQualifier, &typeList, nullptr);
for (unsigned int member = 0; member < typeList.size(); ++member)
layoutTypeCheck(typeList[member].loc, *typeList[member].type);
if (memberWithPerViewQualifier) {
for (unsigned int member = 0; member < typeList.size(); ++member) {
checkAndResizeMeshViewDim(typeList[member].loc, *typeList[member].type, /*isBlockMember*/ true);
}
}
// reverse merge, so that currentBlockQualifier now has all layout information
// (can't use defaultQualification directly, it's missing other non-layout-default-class qualifiers)
mergeObjectLayoutQualifiers(currentBlockQualifier, defaultQualification, true);
//
// Build and add the interface block as a new type named 'blockName'
//
TType blockType(&typeList, *blockName, currentBlockQualifier);
if (arraySizes != nullptr)
blockType.transferArraySizes(arraySizes);
if (arraySizes == nullptr)
ioArrayCheck(loc, blockType, instanceName ? *instanceName : *blockName);
if (currentBlockQualifier.hasBufferReference()) {
if (currentBlockQualifier.storage != EvqBuffer)
error(loc, "can only be used with buffer", "buffer_reference", "");
// Create the block reference type. If it was forward-declared, detect that
// as a referent struct type with no members. Replace the referent type with
// blockType.
TType blockNameType(EbtReference, blockType, *blockName);
TVariable* blockNameVar = new TVariable(blockName, blockNameType, true);
if (! symbolTable.insert(*blockNameVar)) {
TSymbol* existingName = symbolTable.find(*blockName);
if (existingName->getType().isReference() &&
existingName->getType().getReferentType()->getStruct() &&
existingName->getType().getReferentType()->getStruct()->size() == 0 &&
existingName->getType().getQualifier().storage == blockType.getQualifier().storage) {
existingName->getType().getReferentType()->deepCopy(blockType);
} else {
error(loc, "block name cannot be redefined", blockName->c_str(), "");
}
}
if (!instanceName) {
return;
}
} else {
//
// Don't make a user-defined type out of block name; that will cause an error
// if the same block name gets reused in a different interface.
//
// "Block names have no other use within a shader
// beyond interface matching; it is a compile-time error to use a block name at global scope for anything
// other than as a block name (e.g., use of a block name for a global variable name or function name is
// currently reserved)."
//
// Use the symbol table to prevent normal reuse of the block's name, as a variable entry,
// whose type is EbtBlock, but without all the structure; that will come from the type
// the instances point to.
//
TType blockNameType(EbtBlock, blockType.getQualifier().storage);
TVariable* blockNameVar = new TVariable(blockName, blockNameType);
if (! symbolTable.insert(*blockNameVar)) {
TSymbol* existingName = symbolTable.find(*blockName);
if (existingName->getType().getBasicType() == EbtBlock) {
if (existingName->getType().getQualifier().storage == blockType.getQualifier().storage) {
error(loc, "Cannot reuse block name within the same interface:", blockName->c_str(), blockType.getStorageQualifierString());
return;
}
} else {
error(loc, "block name cannot redefine a non-block name", blockName->c_str(), "");
return;
}
}
}
// Add the variable, as anonymous or named instanceName.
// Make an anonymous variable if no name was provided.
if (! instanceName)
instanceName = NewPoolTString("");
TVariable& variable = *new TVariable(instanceName, blockType);
if (! symbolTable.insert(variable)) {
if (*instanceName == "")
error(loc, "nameless block contains a member that already has a name at global scope", blockName->c_str(), "");
else
error(loc, "block instance name redefinition", variable.getName().c_str(), "");
return;
}
// Check for general layout qualifier errors
layoutObjectCheck(loc, variable);
// fix up
if (isIoResizeArray(blockType)) {
ioArraySymbolResizeList.push_back(&variable);
checkIoArraysConsistency(loc, true);
} else
fixIoArraySize(loc, variable.getWritableType());
// Save it in the AST for linker use.
trackLinkage(variable);
}
//
// allow storage type of block to be remapped at compile time
//
void TParseContext::blockStorageRemap(const TSourceLoc&, const TString* instanceName, TQualifier& qualifier)
{
TBlockStorageClass type = intermediate.getBlockStorageOverride(instanceName->c_str());
if (type != EbsNone) {
qualifier.setBlockStorage(type);
}
}
// Do all block-declaration checking regarding the combination of in/out/uniform/buffer
// with a particular stage.
void TParseContext::blockStageIoCheck(const TSourceLoc& loc, const TQualifier& qualifier)
{
const char *extsrt[2] = { E_GL_NV_ray_tracing, E_GL_EXT_ray_tracing };
switch (qualifier.storage) {
case EvqUniform:
profileRequires(loc, EEsProfile, 300, nullptr, "uniform block");
profileRequires(loc, ENoProfile, 140, E_GL_ARB_uniform_buffer_object, "uniform block");
if (currentBlockQualifier.layoutPacking == ElpStd430 && ! currentBlockQualifier.isPushConstant())
requireExtensions(loc, 1, &E_GL_EXT_scalar_block_layout, "std430 requires the buffer storage qualifier");
break;
case EvqBuffer:
requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, "buffer block");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 430, E_GL_ARB_shader_storage_buffer_object, "buffer block");
profileRequires(loc, EEsProfile, 310, nullptr, "buffer block");
break;
case EvqVaryingIn:
profileRequires(loc, ~EEsProfile, 150, E_GL_ARB_separate_shader_objects, "input block");
// It is a compile-time error to have an input block in a vertex shader or an output block in a fragment shader
// "Compute shaders do not permit user-defined input variables..."
requireStage(loc, (EShLanguageMask)(EShLangTessControlMask|EShLangTessEvaluationMask|EShLangGeometryMask|
EShLangFragmentMask|EShLangMeshMask), "input block");
if (language == EShLangFragment) {
profileRequires(loc, EEsProfile, 320, Num_AEP_shader_io_blocks, AEP_shader_io_blocks, "fragment input block");
} else if (language == EShLangMesh && ! qualifier.isTaskMemory()) {
error(loc, "input blocks cannot be used in a mesh shader", "out", "");
}
break;
case EvqVaryingOut:
profileRequires(loc, ~EEsProfile, 150, E_GL_ARB_separate_shader_objects, "output block");
requireStage(loc, (EShLanguageMask)(EShLangVertexMask|EShLangTessControlMask|EShLangTessEvaluationMask|
EShLangGeometryMask|EShLangMeshMask|EShLangTaskMask), "output block");
// ES 310 can have a block before shader_io is turned on, so skip this test for built-ins
if (language == EShLangVertex && ! parsingBuiltins) {
profileRequires(loc, EEsProfile, 320, Num_AEP_shader_io_blocks, AEP_shader_io_blocks, "vertex output block");
} else if (language == EShLangMesh && qualifier.isTaskMemory()) {
error(loc, "can only use on input blocks in mesh shader", "taskNV", "");
} else if (language == EShLangTask && ! qualifier.isTaskMemory()) {
error(loc, "output blocks cannot be used in a task shader", "out", "");
}
break;
case EvqShared:
if (spvVersion.spv > 0 && spvVersion.spv < EShTargetSpv_1_4) {
error(loc, "shared block requires at least SPIR-V 1.4", "shared block", "");
}
profileRequires(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, 0, E_GL_EXT_shared_memory_block, "shared block");
break;
case EvqPayload:
profileRequires(loc, ~EEsProfile, 460, 2, extsrt, "rayPayloadNV block");
requireStage(loc, (EShLanguageMask)(EShLangRayGenMask | EShLangAnyHitMask | EShLangClosestHitMask | EShLangMissMask),
"rayPayloadNV block");
break;
case EvqPayloadIn:
profileRequires(loc, ~EEsProfile, 460, 2, extsrt, "rayPayloadInNV block");
requireStage(loc, (EShLanguageMask)(EShLangAnyHitMask | EShLangClosestHitMask | EShLangMissMask),
"rayPayloadInNV block");
break;
case EvqHitAttr:
profileRequires(loc, ~EEsProfile, 460, 2, extsrt, "hitAttributeNV block");
requireStage(loc, (EShLanguageMask)(EShLangIntersectMask | EShLangAnyHitMask | EShLangClosestHitMask), "hitAttributeNV block");
break;
case EvqCallableData:
profileRequires(loc, ~EEsProfile, 460, 2, extsrt, "callableDataNV block");
requireStage(loc, (EShLanguageMask)(EShLangRayGenMask | EShLangClosestHitMask | EShLangMissMask | EShLangCallableMask),
"callableDataNV block");
break;
case EvqCallableDataIn:
profileRequires(loc, ~EEsProfile, 460, 2, extsrt, "callableDataInNV block");
requireStage(loc, (EShLanguageMask)(EShLangCallableMask), "callableDataInNV block");
break;
case EvqHitObjectAttrNV:
profileRequires(loc, ~EEsProfile, 460, E_GL_NV_shader_invocation_reorder, "hitObjectAttributeNV block");
requireStage(loc, (EShLanguageMask)(EShLangRayGenMask | EShLangClosestHitMask | EShLangMissMask), "hitObjectAttributeNV block");
break;
default:
error(loc, "only uniform, buffer, in, or out blocks are supported", blockName->c_str(), "");
break;
}
}
// Do all block-declaration checking regarding its qualifiers.
void TParseContext::blockQualifierCheck(const TSourceLoc& loc, const TQualifier& qualifier, bool /*instanceName*/)
{
// The 4.5 specification says:
//
// interface-block :
// layout-qualifieropt interface-qualifier block-name { member-list } instance-nameopt ;
//
// interface-qualifier :
// in
// out
// patch in
// patch out
// uniform
// buffer
//
// Note however memory qualifiers aren't included, yet the specification also says
//
// "...memory qualifiers may also be used in the declaration of shader storage blocks..."
if (qualifier.isInterpolation())
error(loc, "cannot use interpolation qualifiers on an interface block", "flat/smooth/noperspective", "");
if (qualifier.centroid)
error(loc, "cannot use centroid qualifier on an interface block", "centroid", "");
if (qualifier.isSample())
error(loc, "cannot use sample qualifier on an interface block", "sample", "");
if (qualifier.invariant)
error(loc, "cannot use invariant qualifier on an interface block", "invariant", "");
if (qualifier.isPushConstant())
intermediate.addPushConstantCount();
if (qualifier.isShaderRecord())
intermediate.addShaderRecordCount();
if (qualifier.isTaskMemory())
intermediate.addTaskNVCount();
}
//
// "For a block, this process applies to the entire block, or until the first member
// is reached that has a location layout qualifier. When a block member is declared with a location
// qualifier, its location comes from that qualifier: The member's location qualifier overrides the block-level
// declaration. Subsequent members are again assigned consecutive locations, based on the newest location,
// until the next member declared with a location qualifier. The values used for locations do not have to be
// declared in increasing order."
void TParseContext::fixBlockLocations(const TSourceLoc& loc, TQualifier& qualifier, TTypeList& typeList, bool memberWithLocation, bool memberWithoutLocation)
{
// "If a block has no block-level location layout qualifier, it is required that either all or none of its members
// have a location layout qualifier, or a compile-time error results."
if (! qualifier.hasLocation() && memberWithLocation && memberWithoutLocation)
error(loc, "either the block needs a location, or all members need a location, or no members have a location", "location", "");
else {
if (memberWithLocation) {
// remove any block-level location and make it per *every* member
int nextLocation = 0; // by the rule above, initial value is not relevant
if (qualifier.hasAnyLocation()) {
nextLocation = qualifier.layoutLocation;
qualifier.layoutLocation = TQualifier::layoutLocationEnd;
if (qualifier.hasComponent()) {
// "It is a compile-time error to apply the *component* qualifier to a ... block"
error(loc, "cannot apply to a block", "component", "");
}
if (qualifier.hasIndex()) {
error(loc, "cannot apply to a block", "index", "");
}
}
for (unsigned int member = 0; member < typeList.size(); ++member) {
TQualifier& memberQualifier = typeList[member].type->getQualifier();
const TSourceLoc& memberLoc = typeList[member].loc;
if (! memberQualifier.hasLocation()) {
if (nextLocation >= (int)TQualifier::layoutLocationEnd)
error(memberLoc, "location is too large", "location", "");
memberQualifier.layoutLocation = nextLocation;
memberQualifier.layoutComponent = TQualifier::layoutComponentEnd;
}
nextLocation = memberQualifier.layoutLocation + intermediate.computeTypeLocationSize(
*typeList[member].type, language);
}
}
}
}
void TParseContext::fixXfbOffsets(TQualifier& qualifier, TTypeList& typeList)
{
// "If a block is qualified with xfb_offset, all its
// members are assigned transform feedback buffer offsets. If a block is not qualified with xfb_offset, any
// members of that block not qualified with an xfb_offset will not be assigned transform feedback buffer
// offsets."
if (! qualifier.hasXfbBuffer() || ! qualifier.hasXfbOffset())
return;
int nextOffset = qualifier.layoutXfbOffset;
for (unsigned int member = 0; member < typeList.size(); ++member) {
TQualifier& memberQualifier = typeList[member].type->getQualifier();
bool contains64BitType = false;
bool contains32BitType = false;
bool contains16BitType = false;
int memberSize = intermediate.computeTypeXfbSize(*typeList[member].type, contains64BitType, contains32BitType, contains16BitType);
// see if we need to auto-assign an offset to this member
if (! memberQualifier.hasXfbOffset()) {
// "if applied to an aggregate containing a double or 64-bit integer, the offset must also be a multiple of 8"
if (contains64BitType)
RoundToPow2(nextOffset, 8);
else if (contains32BitType)
RoundToPow2(nextOffset, 4);
else if (contains16BitType)
RoundToPow2(nextOffset, 2);
memberQualifier.layoutXfbOffset = nextOffset;
} else
nextOffset = memberQualifier.layoutXfbOffset;
nextOffset += memberSize;
}
// The above gave all block members an offset, so we can take it off the block now,
// which will avoid double counting the offset usage.
qualifier.layoutXfbOffset = TQualifier::layoutXfbOffsetEnd;
}
// Calculate and save the offset of each block member, using the recursively
// defined block offset rules and the user-provided offset and align.
//
// Also, compute and save the total size of the block. For the block's size, arrayness
// is not taken into account, as each element is backed by a separate buffer.
//
void TParseContext::fixBlockUniformOffsets(TQualifier& qualifier, TTypeList& typeList)
{
if (!storageCanHaveLayoutInBlock(qualifier.storage) && !qualifier.isTaskMemory())
return;
if (qualifier.layoutPacking != ElpStd140 && qualifier.layoutPacking != ElpStd430 && qualifier.layoutPacking != ElpScalar)
return;
int offset = 0;
int memberSize;
for (unsigned int member = 0; member < typeList.size(); ++member) {
TQualifier& memberQualifier = typeList[member].type->getQualifier();
const TSourceLoc& memberLoc = typeList[member].loc;
// "When align is applied to an array, it effects only the start of the array, not the array's internal stride."
// modify just the children's view of matrix layout, if there is one for this member
TLayoutMatrix subMatrixLayout = typeList[member].type->getQualifier().layoutMatrix;
int dummyStride;
int memberAlignment = intermediate.getMemberAlignment(*typeList[member].type, memberSize, dummyStride, qualifier.layoutPacking,
subMatrixLayout != ElmNone ? subMatrixLayout == ElmRowMajor : qualifier.layoutMatrix == ElmRowMajor);
if (memberQualifier.hasOffset()) {
// "The specified offset must be a multiple
// of the base alignment of the type of the block member it qualifies, or a compile-time error results."
if (! IsMultipleOfPow2(memberQualifier.layoutOffset, memberAlignment))
error(memberLoc, "must be a multiple of the member's alignment", "offset",
"(layout offset = %d | member alignment = %d)", memberQualifier.layoutOffset, memberAlignment);
// GLSL: "It is a compile-time error to specify an offset that is smaller than the offset of the previous
// member in the block or that lies within the previous member of the block"
if (spvVersion.spv == 0) {
if (memberQualifier.layoutOffset < offset)
error(memberLoc, "cannot lie in previous members", "offset", "");
// "The offset qualifier forces the qualified member to start at or after the specified
// integral-constant expression, which will be its byte offset from the beginning of the buffer.
// "The actual offset of a member is computed as
// follows: If offset was declared, start with that offset, otherwise start with the next available offset."
offset = std::max(offset, memberQualifier.layoutOffset);
} else {
// TODO: Vulkan: "It is a compile-time error to have any offset, explicit or assigned,
// that lies within another member of the block."
offset = memberQualifier.layoutOffset;
}
}
// "The actual alignment of a member will be the greater of the specified align alignment and the standard
// (e.g., std140) base alignment for the member's type."
if (memberQualifier.hasAlign())
memberAlignment = std::max(memberAlignment, memberQualifier.layoutAlign);
// "If the resulting offset is not a multiple of the actual alignment,
// increase it to the first offset that is a multiple of
// the actual alignment."
RoundToPow2(offset, memberAlignment);
typeList[member].type->getQualifier().layoutOffset = offset;
offset += memberSize;
}
}
//
// Spread LayoutMatrix to uniform block member, if a uniform block member is a struct,
// we need spread LayoutMatrix to this struct member too. and keep this rule for recursive.
//
void TParseContext::fixBlockUniformLayoutMatrix(TQualifier& qualifier, TTypeList* originTypeList,
TTypeList* tmpTypeList)
{
assert(tmpTypeList == nullptr || originTypeList->size() == tmpTypeList->size());
for (unsigned int member = 0; member < originTypeList->size(); ++member) {
if (qualifier.layoutPacking != ElpNone) {
if (tmpTypeList == nullptr) {
if (((*originTypeList)[member].type->isMatrix() ||
(*originTypeList)[member].type->getBasicType() == EbtStruct) &&
(*originTypeList)[member].type->getQualifier().layoutMatrix == ElmNone) {
(*originTypeList)[member].type->getQualifier().layoutMatrix = qualifier.layoutMatrix;
}
} else {
if (((*tmpTypeList)[member].type->isMatrix() ||
(*tmpTypeList)[member].type->getBasicType() == EbtStruct) &&
(*tmpTypeList)[member].type->getQualifier().layoutMatrix == ElmNone) {
(*tmpTypeList)[member].type->getQualifier().layoutMatrix = qualifier.layoutMatrix;
}
}
}
if ((*originTypeList)[member].type->getBasicType() == EbtStruct) {
TQualifier* memberQualifier = nullptr;
// block member can be declare a matrix style, so it should be update to the member's style
if ((*originTypeList)[member].type->getQualifier().layoutMatrix == ElmNone) {
memberQualifier = &qualifier;
} else {
memberQualifier = &((*originTypeList)[member].type->getQualifier());
}
const TType* tmpType = tmpTypeList == nullptr ?
(*originTypeList)[member].type->clone() : (*tmpTypeList)[member].type;
fixBlockUniformLayoutMatrix(*memberQualifier, (*originTypeList)[member].type->getWritableStruct(),
tmpType->getWritableStruct());
const TTypeList* structure = recordStructCopy(matrixFixRecord, (*originTypeList)[member].type, tmpType);
if (tmpTypeList == nullptr) {
(*originTypeList)[member].type->setStruct(const_cast<TTypeList*>(structure));
}
if (tmpTypeList != nullptr) {
(*tmpTypeList)[member].type->setStruct(const_cast<TTypeList*>(structure));
}
}
}
}
//
// Spread LayoutPacking to matrix or aggregate block members. If a block member is a struct or
// array of struct, spread LayoutPacking recursively to its matrix or aggregate members.
//
void TParseContext::fixBlockUniformLayoutPacking(TQualifier& qualifier, TTypeList* originTypeList,
TTypeList* tmpTypeList)
{
assert(tmpTypeList == nullptr || originTypeList->size() == tmpTypeList->size());
for (unsigned int member = 0; member < originTypeList->size(); ++member) {
if (qualifier.layoutPacking != ElpNone) {
if (tmpTypeList == nullptr) {
if ((*originTypeList)[member].type->getQualifier().layoutPacking == ElpNone &&
!(*originTypeList)[member].type->isScalarOrVector()) {
(*originTypeList)[member].type->getQualifier().layoutPacking = qualifier.layoutPacking;
}
} else {
if ((*tmpTypeList)[member].type->getQualifier().layoutPacking == ElpNone &&
!(*tmpTypeList)[member].type->isScalarOrVector()) {
(*tmpTypeList)[member].type->getQualifier().layoutPacking = qualifier.layoutPacking;
}
}
}
if ((*originTypeList)[member].type->getBasicType() == EbtStruct) {
// Deep copy the type in pool.
// Because, struct use in different block may have different layout qualifier.
// We have to new a object to distinguish between them.
const TType* tmpType = tmpTypeList == nullptr ?
(*originTypeList)[member].type->clone() : (*tmpTypeList)[member].type;
fixBlockUniformLayoutPacking(qualifier, (*originTypeList)[member].type->getWritableStruct(),
tmpType->getWritableStruct());
const TTypeList* structure = recordStructCopy(packingFixRecord, (*originTypeList)[member].type, tmpType);
if (tmpTypeList == nullptr) {
(*originTypeList)[member].type->setStruct(const_cast<TTypeList*>(structure));
}
if (tmpTypeList != nullptr) {
(*tmpTypeList)[member].type->setStruct(const_cast<TTypeList*>(structure));
}
}
}
}
// For an identifier that is already declared, add more qualification to it.
void TParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier qualifier, const TString& identifier)
{
TSymbol* symbol = symbolTable.find(identifier);
// A forward declaration of a block reference looks to the grammar like adding
// a qualifier to an existing symbol. Detect this and create the block reference
// type with an empty type list, which will be filled in later in
// TParseContext::declareBlock.
if (!symbol && qualifier.hasBufferReference()) {
TTypeList typeList;
TType blockType(&typeList, identifier, qualifier);
TType blockNameType(EbtReference, blockType, identifier);
TVariable* blockNameVar = new TVariable(&identifier, blockNameType, true);
if (! symbolTable.insert(*blockNameVar)) {
error(loc, "block name cannot redefine a non-block name", blockName->c_str(), "");
}
return;
}
if (! symbol) {
error(loc, "identifier not previously declared", identifier.c_str(), "");
return;
}
if (symbol->getAsFunction()) {
error(loc, "cannot re-qualify a function name", identifier.c_str(), "");
return;
}
if (qualifier.isAuxiliary() ||
qualifier.isMemory() ||
qualifier.isInterpolation() ||
qualifier.hasLayout() ||
qualifier.storage != EvqTemporary ||
qualifier.precision != EpqNone) {
error(loc, "cannot add storage, auxiliary, memory, interpolation, layout, or precision qualifier to an existing variable", identifier.c_str(), "");
return;
}
// For read-only built-ins, add a new symbol for holding the modified qualifier.
// This will bring up an entire block, if a block type has to be modified (e.g., gl_Position inside a block)
if (symbol->isReadOnly())
symbol = symbolTable.copyUp(symbol);
if (qualifier.invariant) {
if (intermediate.inIoAccessed(identifier))
error(loc, "cannot change qualification after use", "invariant", "");
symbol->getWritableType().getQualifier().invariant = true;
invariantCheck(loc, symbol->getType().getQualifier());
} else if (qualifier.isNoContraction()) {
if (intermediate.inIoAccessed(identifier))
error(loc, "cannot change qualification after use", "precise", "");
symbol->getWritableType().getQualifier().setNoContraction();
} else if (qualifier.specConstant) {
symbol->getWritableType().getQualifier().makeSpecConstant();
if (qualifier.hasSpecConstantId())
symbol->getWritableType().getQualifier().layoutSpecConstantId = qualifier.layoutSpecConstantId;
} else
warn(loc, "unknown requalification", "", "");
}
void TParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier qualifier, TIdentifierList& identifiers)
{
for (unsigned int i = 0; i < identifiers.size(); ++i)
addQualifierToExisting(loc, qualifier, *identifiers[i]);
}
// Make sure 'invariant' isn't being applied to a non-allowed object.
void TParseContext::invariantCheck(const TSourceLoc& loc, const TQualifier& qualifier)
{
if (! qualifier.invariant)
return;
bool pipeOut = qualifier.isPipeOutput();
bool pipeIn = qualifier.isPipeInput();
if ((version >= 300 && isEsProfile()) || (!isEsProfile() && version >= 420)) {
if (! pipeOut)
error(loc, "can only apply to an output", "invariant", "");
} else {
if ((language == EShLangVertex && pipeIn) || (! pipeOut && ! pipeIn))
error(loc, "can only apply to an output, or to an input in a non-vertex stage\n", "invariant", "");
}
}
//
// Updating default qualifier for the case of a declaration with just a qualifier,
// no type, block, or identifier.
//
void TParseContext::updateStandaloneQualifierDefaults(const TSourceLoc& loc, const TPublicType& publicType)
{
if (publicType.shaderQualifiers.vertices != TQualifier::layoutNotSet) {
assert(language == EShLangTessControl || language == EShLangGeometry || language == EShLangMesh);
const char* id = (language == EShLangTessControl) ? "vertices" : "max_vertices";
if (publicType.qualifier.storage != EvqVaryingOut)
error(loc, "can only apply to 'out'", id, "");
if (! intermediate.setVertices(publicType.shaderQualifiers.vertices))
error(loc, "cannot change previously set layout value", id, "");
if (language == EShLangTessControl)
checkIoArraysConsistency(loc);
}
if (publicType.shaderQualifiers.primitives != TQualifier::layoutNotSet) {
assert(language == EShLangMesh);
const char* id = "max_primitives";
if (publicType.qualifier.storage != EvqVaryingOut)
error(loc, "can only apply to 'out'", id, "");
if (! intermediate.setPrimitives(publicType.shaderQualifiers.primitives))
error(loc, "cannot change previously set layout value", id, "");
}
if (publicType.shaderQualifiers.invocations != TQualifier::layoutNotSet) {
if (publicType.qualifier.storage != EvqVaryingIn)
error(loc, "can only apply to 'in'", "invocations", "");
if (! intermediate.setInvocations(publicType.shaderQualifiers.invocations))
error(loc, "cannot change previously set layout value", "invocations", "");
}
if (publicType.shaderQualifiers.geometry != ElgNone) {
if (publicType.qualifier.storage == EvqVaryingIn) {
switch (publicType.shaderQualifiers.geometry) {
case ElgPoints:
case ElgLines:
case ElgLinesAdjacency:
case ElgTriangles:
case ElgTrianglesAdjacency:
case ElgQuads:
case ElgIsolines:
if (language == EShLangMesh) {
error(loc, "cannot apply to input", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry), "");
break;
}
if (intermediate.setInputPrimitive(publicType.shaderQualifiers.geometry)) {
if (language == EShLangGeometry)
checkIoArraysConsistency(loc);
} else
error(loc, "cannot change previously set input primitive", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry), "");
break;
default:
error(loc, "cannot apply to input", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry), "");
}
} else if (publicType.qualifier.storage == EvqVaryingOut) {
switch (publicType.shaderQualifiers.geometry) {
case ElgLines:
case ElgTriangles:
if (language != EShLangMesh) {
error(loc, "cannot apply to 'out'", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry), "");
break;
}
[[fallthrough]];
case ElgPoints:
case ElgLineStrip:
case ElgTriangleStrip:
if (! intermediate.setOutputPrimitive(publicType.shaderQualifiers.geometry))
error(loc, "cannot change previously set output primitive", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry), "");
break;
default:
error(loc, "cannot apply to 'out'", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry), "");
}
} else
error(loc, "cannot apply to:", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry), GetStorageQualifierString(publicType.qualifier.storage));
}
if (publicType.shaderQualifiers.spacing != EvsNone) {
if (publicType.qualifier.storage == EvqVaryingIn) {
if (! intermediate.setVertexSpacing(publicType.shaderQualifiers.spacing))
error(loc, "cannot change previously set vertex spacing", TQualifier::getVertexSpacingString(publicType.shaderQualifiers.spacing), "");
} else
error(loc, "can only apply to 'in'", TQualifier::getVertexSpacingString(publicType.shaderQualifiers.spacing), "");
}
if (publicType.shaderQualifiers.order != EvoNone) {
if (publicType.qualifier.storage == EvqVaryingIn) {
if (! intermediate.setVertexOrder(publicType.shaderQualifiers.order))
error(loc, "cannot change previously set vertex order", TQualifier::getVertexOrderString(publicType.shaderQualifiers.order), "");
} else
error(loc, "can only apply to 'in'", TQualifier::getVertexOrderString(publicType.shaderQualifiers.order), "");
}
if (publicType.shaderQualifiers.pointMode) {
if (publicType.qualifier.storage == EvqVaryingIn)
intermediate.setPointMode();
else
error(loc, "can only apply to 'in'", "point_mode", "");
}
for (int i = 0; i < 3; ++i) {
if (publicType.shaderQualifiers.localSizeNotDefault[i]) {
if (publicType.qualifier.storage == EvqVaryingIn) {
if (! intermediate.setLocalSize(i, publicType.shaderQualifiers.localSize[i]))
error(loc, "cannot change previously set size", "local_size", "");
else {
int max = 0;
if (language == EShLangCompute) {
switch (i) {
case 0: max = resources.maxComputeWorkGroupSizeX; break;
case 1: max = resources.maxComputeWorkGroupSizeY; break;
case 2: max = resources.maxComputeWorkGroupSizeZ; break;
default: break;
}
if (intermediate.getLocalSize(i) > (unsigned int)max)
error(loc, "too large; see gl_MaxComputeWorkGroupSize", "local_size", "");
} else if (language == EShLangMesh) {
switch (i) {
case 0:
max = extensionTurnedOn(E_GL_EXT_mesh_shader) ?
resources.maxMeshWorkGroupSizeX_EXT :
resources.maxMeshWorkGroupSizeX_NV;
break;
case 1:
max = extensionTurnedOn(E_GL_EXT_mesh_shader) ?
resources.maxMeshWorkGroupSizeY_EXT :
resources.maxMeshWorkGroupSizeY_NV ;
break;
case 2:
max = extensionTurnedOn(E_GL_EXT_mesh_shader) ?
resources.maxMeshWorkGroupSizeZ_EXT :
resources.maxMeshWorkGroupSizeZ_NV ;
break;
default: break;
}
if (intermediate.getLocalSize(i) > (unsigned int)max) {
TString maxsErrtring = "too large, see ";
maxsErrtring.append(extensionTurnedOn(E_GL_EXT_mesh_shader) ?
"gl_MaxMeshWorkGroupSizeEXT" : "gl_MaxMeshWorkGroupSizeNV");
error(loc, maxsErrtring.c_str(), "local_size", "");
}
} else if (language == EShLangTask) {
switch (i) {
case 0:
max = extensionTurnedOn(E_GL_EXT_mesh_shader) ?
resources.maxTaskWorkGroupSizeX_EXT :
resources.maxTaskWorkGroupSizeX_NV;
break;
case 1:
max = extensionTurnedOn(E_GL_EXT_mesh_shader) ?
resources.maxTaskWorkGroupSizeY_EXT:
resources.maxTaskWorkGroupSizeY_NV;
break;
case 2:
max = extensionTurnedOn(E_GL_EXT_mesh_shader) ?
resources.maxTaskWorkGroupSizeZ_EXT:
resources.maxTaskWorkGroupSizeZ_NV;
break;
default: break;
}
if (intermediate.getLocalSize(i) > (unsigned int)max) {
TString maxsErrtring = "too large, see ";
maxsErrtring.append(extensionTurnedOn(E_GL_EXT_mesh_shader) ?
"gl_MaxTaskWorkGroupSizeEXT" : "gl_MaxTaskWorkGroupSizeNV");
error(loc, maxsErrtring.c_str(), "local_size", "");
}
} else {
assert(0);
}
// Fix the existing constant gl_WorkGroupSize with this new information.
TVariable* workGroupSize = getEditableVariable("gl_WorkGroupSize");
if (workGroupSize != nullptr)
workGroupSize->getWritableConstArray()[i].setUConst(intermediate.getLocalSize(i));
}
} else
error(loc, "can only apply to 'in'", "local_size", "");
}
if (publicType.shaderQualifiers.localSizeSpecId[i] != TQualifier::layoutNotSet) {
if (publicType.qualifier.storage == EvqVaryingIn) {
if (! intermediate.setLocalSizeSpecId(i, publicType.shaderQualifiers.localSizeSpecId[i]))
error(loc, "cannot change previously set size", "local_size", "");
} else
error(loc, "can only apply to 'in'", "local_size id", "");
// Set the workgroup built-in variable as a specialization constant
TVariable* workGroupSize = getEditableVariable("gl_WorkGroupSize");
if (workGroupSize != nullptr)
workGroupSize->getWritableType().getQualifier().specConstant = true;
}
}
if (publicType.shaderQualifiers.earlyFragmentTests) {
if (publicType.qualifier.storage == EvqVaryingIn)
intermediate.setEarlyFragmentTests();
else
error(loc, "can only apply to 'in'", "early_fragment_tests", "");
}
if (publicType.shaderQualifiers.earlyAndLateFragmentTestsAMD) {
if (publicType.qualifier.storage == EvqVaryingIn)
intermediate.setEarlyAndLateFragmentTestsAMD();
else
error(loc, "can only apply to 'in'", "early_and_late_fragment_tests_amd", "");
}
if (publicType.shaderQualifiers.postDepthCoverage) {
if (publicType.qualifier.storage == EvqVaryingIn)
intermediate.setPostDepthCoverage();
else
error(loc, "can only apply to 'in'", "post_coverage_coverage", "");
}
if (publicType.shaderQualifiers.nonCoherentColorAttachmentReadEXT) {
if (publicType.qualifier.storage == EvqVaryingIn)
intermediate.setNonCoherentColorAttachmentReadEXT();
else
error(loc, "can only apply to 'in'", "non_coherent_color_attachment_readEXT", "");
}
if (publicType.shaderQualifiers.nonCoherentDepthAttachmentReadEXT) {
if (publicType.qualifier.storage == EvqVaryingIn)
intermediate.setNonCoherentDepthAttachmentReadEXT();
else
error(loc, "can only apply to 'in'", "non_coherent_depth_attachment_readEXT", "");
}
if (publicType.shaderQualifiers.nonCoherentStencilAttachmentReadEXT) {
if (publicType.qualifier.storage == EvqVaryingIn)
intermediate.setNonCoherentStencilAttachmentReadEXT();
else
error(loc, "can only apply to 'in'", "non_coherent_stencil_attachment_readEXT", "");
}
if (publicType.shaderQualifiers.hasBlendEquation()) {
if (publicType.qualifier.storage != EvqVaryingOut)
error(loc, "can only apply to 'out'", "blend equation", "");
}
if (publicType.shaderQualifiers.interlockOrdering) {
if (publicType.qualifier.storage == EvqVaryingIn) {
if (!intermediate.setInterlockOrdering(publicType.shaderQualifiers.interlockOrdering))
error(loc, "cannot change previously set fragment shader interlock ordering", TQualifier::getInterlockOrderingString(publicType.shaderQualifiers.interlockOrdering), "");
}
else
error(loc, "can only apply to 'in'", TQualifier::getInterlockOrderingString(publicType.shaderQualifiers.interlockOrdering), "");
}
if (publicType.shaderQualifiers.layoutDerivativeGroupQuads &&
publicType.shaderQualifiers.layoutDerivativeGroupLinear) {
error(loc, "cannot be both specified", "derivative_group_quadsNV and derivative_group_linearNV", "");
}
if (publicType.shaderQualifiers.layoutDerivativeGroupQuads) {
if (publicType.qualifier.storage == EvqVaryingIn) {
if ((intermediate.getLocalSize(0) & 1) ||
(intermediate.getLocalSize(1) & 1))
error(loc, "requires local_size_x and local_size_y to be multiple of two", "derivative_group_quadsNV", "");
else
intermediate.setLayoutDerivativeMode(LayoutDerivativeGroupQuads);
}
else
error(loc, "can only apply to 'in'", "derivative_group_quadsNV", "");
}
if (publicType.shaderQualifiers.layoutDerivativeGroupLinear) {
if (publicType.qualifier.storage == EvqVaryingIn) {
if((intermediate.getLocalSize(0) *
intermediate.getLocalSize(1) *
intermediate.getLocalSize(2)) % 4 != 0)
error(loc, "requires total group size to be multiple of four", "derivative_group_linearNV", "");
else
intermediate.setLayoutDerivativeMode(LayoutDerivativeGroupLinear);
}
else
error(loc, "can only apply to 'in'", "derivative_group_linearNV", "");
}
// Check mesh out array sizes, once all the necessary out qualifiers are defined.
if ((language == EShLangMesh) &&
(intermediate.getVertices() != TQualifier::layoutNotSet) &&
(intermediate.getPrimitives() != TQualifier::layoutNotSet) &&
(intermediate.getOutputPrimitive() != ElgNone))
{
checkIoArraysConsistency(loc);
}
if (publicType.shaderQualifiers.layoutPrimitiveCulling) {
if (publicType.qualifier.storage != EvqTemporary)
error(loc, "layout qualifier can not have storage qualifiers", "primitive_culling","", "");
else {
intermediate.setLayoutPrimitiveCulling();
}
// Exit early as further checks are not valid
return;
}
const TQualifier& qualifier = publicType.qualifier;
if (qualifier.isAuxiliary() ||
qualifier.isMemory() ||
qualifier.isInterpolation() ||
qualifier.precision != EpqNone)
error(loc, "cannot use auxiliary, memory, interpolation, or precision qualifier in a default qualifier declaration (declaration with no type)", "qualifier", "");
// "The offset qualifier can only be used on block members of blocks..."
// "The align qualifier can only be used on blocks or block members..."
if (qualifier.hasOffset() ||
qualifier.hasAlign())
error(loc, "cannot use offset or align qualifiers in a default qualifier declaration (declaration with no type)", "layout qualifier", "");
layoutQualifierCheck(loc, qualifier);
switch (qualifier.storage) {
case EvqUniform:
if (qualifier.hasMatrix())
globalUniformDefaults.layoutMatrix = qualifier.layoutMatrix;
if (qualifier.hasPacking())
globalUniformDefaults.layoutPacking = qualifier.layoutPacking;
break;
case EvqBuffer:
if (qualifier.hasMatrix())
globalBufferDefaults.layoutMatrix = qualifier.layoutMatrix;
if (qualifier.hasPacking())
globalBufferDefaults.layoutPacking = qualifier.layoutPacking;
break;
case EvqVaryingIn:
break;
case EvqVaryingOut:
if (qualifier.hasStream())
globalOutputDefaults.layoutStream = qualifier.layoutStream;
if (qualifier.hasXfbBuffer())
globalOutputDefaults.layoutXfbBuffer = qualifier.layoutXfbBuffer;
if (globalOutputDefaults.hasXfbBuffer() && qualifier.hasXfbStride()) {
if (! intermediate.setXfbBufferStride(globalOutputDefaults.layoutXfbBuffer, qualifier.layoutXfbStride))
error(loc, "all stride settings must match for xfb buffer", "xfb_stride", "%d", qualifier.layoutXfbBuffer);
}
break;
case EvqShared:
if (qualifier.hasMatrix())
globalSharedDefaults.layoutMatrix = qualifier.layoutMatrix;
if (qualifier.hasPacking())
globalSharedDefaults.layoutPacking = qualifier.layoutPacking;
break;
default:
error(loc, "default qualifier requires 'uniform', 'buffer', 'in', 'out' or 'shared' storage qualification", "", "");
return;
}
if (qualifier.hasBinding())
error(loc, "cannot declare a default, include a type or full declaration", "binding", "");
if (qualifier.hasAnyLocation())
error(loc, "cannot declare a default, use a full declaration", "location/component/index", "");
if (qualifier.hasXfbOffset())
error(loc, "cannot declare a default, use a full declaration", "xfb_offset", "");
if (qualifier.isPushConstant())
error(loc, "cannot declare a default, can only be used on a block", "push_constant", "");
if (qualifier.hasBufferReference())
error(loc, "cannot declare a default, can only be used on a block", "buffer_reference", "");
if (qualifier.hasSpecConstantId())
error(loc, "cannot declare a default, can only be used on a scalar", "constant_id", "");
if (qualifier.isShaderRecord())
error(loc, "cannot declare a default, can only be used on a block", "shaderRecordNV", "");
}
//
// Take the sequence of statements that has been built up since the last case/default,
// put it on the list of top-level nodes for the current (inner-most) switch statement,
// and follow that by the case/default we are on now. (See switch topology comment on
// TIntermSwitch.)
//
void TParseContext::wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode)
{
TIntermSequence* switchSequence = switchSequenceStack.back();
if (statements) {
if (switchSequence->size() == 0)
error(statements->getLoc(), "cannot have statements before first case/default label", "switch", "");
statements->setOperator(EOpSequence);
switchSequence->push_back(statements);
}
if (branchNode) {
// check all previous cases for the same label (or both are 'default')
for (unsigned int s = 0; s < switchSequence->size(); ++s) {
TIntermBranch* prevBranch = (*switchSequence)[s]->getAsBranchNode();
if (prevBranch) {
TIntermTyped* prevExpression = prevBranch->getExpression();
TIntermTyped* newExpression = branchNode->getAsBranchNode()->getExpression();
if (prevExpression == nullptr && newExpression == nullptr)
error(branchNode->getLoc(), "duplicate label", "default", "");
else if (prevExpression != nullptr &&
newExpression != nullptr &&
prevExpression->getAsConstantUnion() &&
newExpression->getAsConstantUnion() &&
prevExpression->getAsConstantUnion()->getConstArray()[0].getIConst() ==
newExpression->getAsConstantUnion()->getConstArray()[0].getIConst())
error(branchNode->getLoc(), "duplicated value", "case", "");
}
}
switchSequence->push_back(branchNode);
}
}
//
// Turn the top-level node sequence built up of wrapupSwitchSubsequence9)
// into a switch node.
//
TIntermNode* TParseContext::addSwitch(const TSourceLoc& loc, TIntermTyped* expression, TIntermAggregate* lastStatements)
{
profileRequires(loc, EEsProfile, 300, nullptr, "switch statements");
profileRequires(loc, ENoProfile, 130, nullptr, "switch statements");
wrapupSwitchSubsequence(lastStatements, nullptr);
if (expression == nullptr ||
(expression->getBasicType() != EbtInt && expression->getBasicType() != EbtUint) ||
expression->getType().isArray() || expression->getType().isMatrix() || expression->getType().isVector())
error(loc, "condition must be a scalar integer expression", "switch", "");
// If there is nothing to do, drop the switch but still execute the expression
TIntermSequence* switchSequence = switchSequenceStack.back();
if (switchSequence->size() == 0)
return expression;
if (lastStatements == nullptr) {
// This was originally an ERRROR, because early versions of the specification said
// "it is an error to have no statement between a label and the end of the switch statement."
// The specifications were updated to remove this (being ill-defined what a "statement" was),
// so, this became a warning. However, 3.0 tests still check for the error.
if (isEsProfile() && (version <= 300 || version >= 320) && ! relaxedErrors())
error(loc, "last case/default label not followed by statements", "switch", "");
else if (!isEsProfile() && (version <= 430 || version >= 460))
error(loc, "last case/default label not followed by statements", "switch", "");
else
warn(loc, "last case/default label not followed by statements", "switch", "");
// emulate a break for error recovery
lastStatements = intermediate.makeAggregate(intermediate.addBranch(EOpBreak, loc));
lastStatements->setOperator(EOpSequence);
switchSequence->push_back(lastStatements);
}
TIntermAggregate* body = new TIntermAggregate(EOpSequence);
body->getSequence() = *switchSequenceStack.back();
body->setLoc(loc);
TIntermSwitch* switchNode = new TIntermSwitch(expression, body);
switchNode->setLoc(loc);
return switchNode;
}
//
// When a struct used in block, and has it's own layout packing, layout matrix,
// record the origin structure of a struct to map, and Record the structure copy to the copy table,
//
const TTypeList* TParseContext::recordStructCopy(TStructRecord& record, const TType* originType, const TType* tmpType)
{
size_t memberCount = tmpType->getStruct()->size();
size_t originHash = 0, tmpHash = 0;
std::hash<size_t> hasher;
for (size_t i = 0; i < memberCount; i++) {
size_t originMemberHash = hasher(originType->getStruct()->at(i).type->getQualifier().layoutPacking +
originType->getStruct()->at(i).type->getQualifier().layoutMatrix);
size_t tmpMemberHash = hasher(tmpType->getStruct()->at(i).type->getQualifier().layoutPacking +
tmpType->getStruct()->at(i).type->getQualifier().layoutMatrix);
originHash = hasher((originHash ^ originMemberHash) << 1);
tmpHash = hasher((tmpHash ^ tmpMemberHash) << 1);
}
const TTypeList* originStruct = originType->getStruct();
const TTypeList* tmpStruct = tmpType->getStruct();
if (originHash != tmpHash) {
auto fixRecords = record.find(originStruct);
if (fixRecords != record.end()) {
auto fixRecord = fixRecords->second.find(tmpHash);
if (fixRecord != fixRecords->second.end()) {
return fixRecord->second;
} else {
record[originStruct][tmpHash] = tmpStruct;
return tmpStruct;
}
} else {
record[originStruct] = std::map<size_t, const TTypeList*>();
record[originStruct][tmpHash] = tmpStruct;
return tmpStruct;
}
}
return originStruct;
}
TLayoutFormat TParseContext::mapLegacyLayoutFormat(TLayoutFormat legacyLayoutFormat, TBasicType imageType)
{
TLayoutFormat layoutFormat = ElfNone;
if (imageType == EbtFloat) {
switch (legacyLayoutFormat) {
case ElfSize1x16: layoutFormat = ElfR16f; break;
case ElfSize1x32: layoutFormat = ElfR32f; break;
case ElfSize2x32: layoutFormat = ElfRg32f; break;
case ElfSize4x32: layoutFormat = ElfRgba32f; break;
default: break;
}
} else if (imageType == EbtUint) {
switch (legacyLayoutFormat) {
case ElfSize1x8: layoutFormat = ElfR8ui; break;
case ElfSize1x16: layoutFormat = ElfR16ui; break;
case ElfSize1x32: layoutFormat = ElfR32ui; break;
case ElfSize2x32: layoutFormat = ElfRg32ui; break;
case ElfSize4x32: layoutFormat = ElfRgba32ui; break;
default: break;
}
} else if (imageType == EbtInt) {
switch (legacyLayoutFormat) {
case ElfSize1x8: layoutFormat = ElfR8i; break;
case ElfSize1x16: layoutFormat = ElfR16i; break;
case ElfSize1x32: layoutFormat = ElfR32i; break;
case ElfSize2x32: layoutFormat = ElfRg32i; break;
case ElfSize4x32: layoutFormat = ElfRgba32i; break;
default: break;
}
}
return layoutFormat;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/Initialize.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2016 LunarG, Inc.
// Copyright (C) 2015-2020 Google, Inc.
// Copyright (C) 2017, 2022-2024 Arm Limited.
// Modifications Copyright (C) 2020-2021 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Create strings that declare built-in definitions, add built-ins programmatically
// that cannot be expressed in the strings, and establish mappings between
// built-in functions and operators.
//
// Where to put a built-in:
// TBuiltIns::initialize(version,profile) context-independent textual built-ins; add them to the right string
// TBuiltIns::initialize(resources,...) context-dependent textual built-ins; add them to the right string
// TBuiltIns::identifyBuiltIns(...,symbolTable) context-independent programmatic additions/mappings to the symbol table,
// including identifying what extensions are needed if a version does not allow a symbol
// TBuiltIns::identifyBuiltIns(...,symbolTable, resources) context-dependent programmatic additions/mappings to the symbol table,
// including identifying what extensions are needed if a version does not allow a symbol
//
#include <array>
#include "Initialize.h"
#include "span.h"
namespace glslang {
// TODO: ARB_Compatability: do full extension support
const bool ARBCompatibility = true;
const bool ForwardCompatibility = false;
namespace {
//
// A set of definitions for tabling of the built-in functions.
//
// Order matters here, as does correlation with the subsequent
// "const int ..." declarations and the ArgType enumerants.
const char* TypeString[] = {
"bool", "bvec2", "bvec3", "bvec4",
"float", "vec2", "vec3", "vec4",
"int", "ivec2", "ivec3", "ivec4",
"uint", "uvec2", "uvec3", "uvec4",
};
const int TypeStringCount = sizeof(TypeString) / sizeof(char*); // number of entries in 'TypeString'
const int TypeStringRowShift = 2; // shift amount to go downe one row in 'TypeString'
const int TypeStringColumnMask = (1 << TypeStringRowShift) - 1; // reduce type to its column number in 'TypeString'
const int TypeStringScalarMask = ~TypeStringColumnMask; // take type to its scalar column in 'TypeString'
enum ArgType {
// numbers hardcoded to correspond to 'TypeString'; order and value matter
TypeB = 1 << 0, // Boolean
TypeF = 1 << 1, // float 32
TypeI = 1 << 2, // int 32
TypeU = 1 << 3, // uint 32
TypeF16 = 1 << 4, // float 16
TypeF64 = 1 << 5, // float 64
TypeI8 = 1 << 6, // int 8
TypeI16 = 1 << 7, // int 16
TypeI64 = 1 << 8, // int 64
TypeU8 = 1 << 9, // uint 8
TypeU16 = 1 << 10, // uint 16
TypeU64 = 1 << 11, // uint 64
};
// Mixtures of the above, to help the function tables
const ArgType TypeFI = static_cast<ArgType>(TypeF | TypeI);
const ArgType TypeFIB = static_cast<ArgType>(TypeF | TypeI | TypeB);
const ArgType TypeIU = static_cast<ArgType>(TypeI | TypeU);
// The relationships between arguments and return type, whether anything is
// output, or other unusual situations.
enum ArgClass {
ClassRegular = 0, // nothing special, just all vector widths with matching return type; traditional arithmetic
ClassLS = 1 << 0, // the last argument is also held fixed as a (type-matched) scalar while the others cycle
ClassXLS = 1 << 1, // the last argument is exclusively a (type-matched) scalar while the others cycle
ClassLS2 = 1 << 2, // the last two arguments are held fixed as a (type-matched) scalar while the others cycle
ClassFS = 1 << 3, // the first argument is held fixed as a (type-matched) scalar while the others cycle
ClassFS2 = 1 << 4, // the first two arguments are held fixed as a (type-matched) scalar while the others cycle
ClassLO = 1 << 5, // the last argument is an output
ClassB = 1 << 6, // return type cycles through only bool/bvec, matching vector width of args
ClassLB = 1 << 7, // last argument cycles through only bool/bvec, matching vector width of args
ClassV1 = 1 << 8, // scalar only
ClassFIO = 1 << 9, // first argument is inout
ClassRS = 1 << 10, // the return is held scalar as the arguments cycle
ClassNS = 1 << 11, // no scalar prototype
ClassCV = 1 << 12, // first argument is 'coherent volatile'
ClassFO = 1 << 13, // first argument is output
ClassV3 = 1 << 14, // vec3 only
};
// Mixtures of the above, to help the function tables
const ArgClass ClassV1FIOCV = (ArgClass)(ClassV1 | ClassFIO | ClassCV);
const ArgClass ClassBNS = (ArgClass)(ClassB | ClassNS);
const ArgClass ClassRSNS = (ArgClass)(ClassRS | ClassNS);
// A descriptor, for a single profile, of when something is available.
// If the current profile does not match 'profile' mask below, the other fields
// do not apply (nor validate).
// profiles == EBadProfile is the end of an array of these
struct Versioning {
EProfile profiles; // the profile(s) (mask) that the following fields are valid for
int minExtendedVersion; // earliest version when extensions are enabled; ignored if numExtensions is 0
int minCoreVersion; // earliest version function is in core; 0 means never
int numExtensions; // how many extensions are in the 'extensions' list
const char** extensions; // list of extension names enabling the function
};
EProfile EDesktopProfile = static_cast<EProfile>(ENoProfile | ECoreProfile | ECompatibilityProfile);
// Declare pointers to put into the table for versioning.
const std::array Es300Desktop130Version = { Versioning{ EEsProfile, 0, 300, 0, nullptr },
Versioning{ EDesktopProfile, 0, 130, 0, nullptr },
};
const std::array Es310Desktop400Version = { Versioning{ EEsProfile, 0, 310, 0, nullptr },
Versioning{ EDesktopProfile, 0, 400, 0, nullptr },
};
const std::array Es310Desktop450Version = { Versioning{ EEsProfile, 0, 310, 0, nullptr },
Versioning{ EDesktopProfile, 0, 450, 0, nullptr },
};
// The main descriptor of what a set of function prototypes can look like, and
// a pointer to extra versioning information, when needed.
struct BuiltInFunction {
TOperator op; // operator to map the name to
const char* name; // function name
int numArguments; // number of arguments (overloads with varying arguments need different entries)
ArgType types; // ArgType mask
ArgClass classes; // the ways this particular function entry manifests
const span<const Versioning> versioning; // An empty span means always a valid version
};
// The tables can have the same built-in function name more than one time,
// but the exact same prototype must be indicated at most once.
// The prototypes that get declared are the union of all those indicated.
// This is important when different releases add new prototypes for the same name.
// It also also congnitively simpler tiling of the prototype space.
// In practice, most names can be fully represented with one entry.
//
// Table is terminated by an OpNull TOperator.
const std::array BaseFunctions = {
// TOperator, name, arg-count, ArgType, ArgClass, versioning
// --------- ---- --------- ------- -------- ----------
BuiltInFunction{ EOpRadians, "radians", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpDegrees, "degrees", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpSin, "sin", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpCos, "cos", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpTan, "tan", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpAsin, "asin", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpAcos, "acos", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpAtan, "atan", 2, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpAtan, "atan", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpPow, "pow", 2, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpExp, "exp", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpLog, "log", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpExp2, "exp2", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpLog2, "log2", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpSqrt, "sqrt", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpInverseSqrt, "inversesqrt", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpAbs, "abs", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpSign, "sign", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpFloor, "floor", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpCeil, "ceil", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpFract, "fract", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpMod, "mod", 2, TypeF, ClassLS, {} },
BuiltInFunction{ EOpMin, "min", 2, TypeF, ClassLS, {} },
BuiltInFunction{ EOpMax, "max", 2, TypeF, ClassLS, {} },
BuiltInFunction{ EOpClamp, "clamp", 3, TypeF, ClassLS2, {} },
BuiltInFunction{ EOpMix, "mix", 3, TypeF, ClassLS, {} },
BuiltInFunction{ EOpStep, "step", 2, TypeF, ClassFS, {} },
BuiltInFunction{ EOpSmoothStep, "smoothstep", 3, TypeF, ClassFS2, {} },
BuiltInFunction{ EOpNormalize, "normalize", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpFaceForward, "faceforward", 3, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpReflect, "reflect", 2, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpRefract, "refract", 3, TypeF, ClassXLS, {} },
BuiltInFunction{ EOpLength, "length", 1, TypeF, ClassRS, {} },
BuiltInFunction{ EOpDistance, "distance", 2, TypeF, ClassRS, {} },
BuiltInFunction{ EOpDot, "dot", 2, TypeF, ClassRS, {} },
BuiltInFunction{ EOpCross, "cross", 2, TypeF, ClassV3, {} },
BuiltInFunction{ EOpLessThan, "lessThan", 2, TypeFI, ClassBNS, {} },
BuiltInFunction{ EOpLessThanEqual, "lessThanEqual", 2, TypeFI, ClassBNS, {} },
BuiltInFunction{ EOpGreaterThan, "greaterThan", 2, TypeFI, ClassBNS, {} },
BuiltInFunction{ EOpGreaterThanEqual, "greaterThanEqual", 2, TypeFI, ClassBNS, {} },
BuiltInFunction{ EOpVectorEqual, "equal", 2, TypeFIB, ClassBNS, {} },
BuiltInFunction{ EOpVectorNotEqual, "notEqual", 2, TypeFIB, ClassBNS, {} },
BuiltInFunction{ EOpAny, "any", 1, TypeB, ClassRSNS, {} },
BuiltInFunction{ EOpAll, "all", 1, TypeB, ClassRSNS, {} },
BuiltInFunction{ EOpVectorLogicalNot, "not", 1, TypeB, ClassNS, {} },
BuiltInFunction{ EOpSinh, "sinh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpCosh, "cosh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpTanh, "tanh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpAsinh, "asinh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpAcosh, "acosh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpAtanh, "atanh", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpAbs, "abs", 1, TypeI, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpSign, "sign", 1, TypeI, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpTrunc, "trunc", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpRound, "round", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpRoundEven, "roundEven", 1, TypeF, ClassRegular, {Es300Desktop130Version} },
BuiltInFunction{ EOpModf, "modf", 2, TypeF, ClassLO, {Es300Desktop130Version} },
BuiltInFunction{ EOpMin, "min", 2, TypeIU, ClassLS, {Es300Desktop130Version} },
BuiltInFunction{ EOpMax, "max", 2, TypeIU, ClassLS, {Es300Desktop130Version} },
BuiltInFunction{ EOpClamp, "clamp", 3, TypeIU, ClassLS2, {Es300Desktop130Version} },
BuiltInFunction{ EOpMix, "mix", 3, TypeF, ClassLB, {Es300Desktop130Version} },
BuiltInFunction{ EOpIsInf, "isinf", 1, TypeF, ClassB, {Es300Desktop130Version} },
BuiltInFunction{ EOpIsNan, "isnan", 1, TypeF, ClassB, {Es300Desktop130Version} },
BuiltInFunction{ EOpLessThan, "lessThan", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
BuiltInFunction{ EOpLessThanEqual, "lessThanEqual", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
BuiltInFunction{ EOpGreaterThan, "greaterThan", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
BuiltInFunction{ EOpGreaterThanEqual, "greaterThanEqual", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
BuiltInFunction{ EOpVectorEqual, "equal", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
BuiltInFunction{ EOpVectorNotEqual, "notEqual", 2, TypeU, ClassBNS, {Es300Desktop130Version} },
BuiltInFunction{ EOpAtomicAdd, "atomicAdd", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
BuiltInFunction{ EOpAtomicMin, "atomicMin", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
BuiltInFunction{ EOpAtomicMax, "atomicMax", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
BuiltInFunction{ EOpAtomicAnd, "atomicAnd", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
BuiltInFunction{ EOpAtomicOr, "atomicOr", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
BuiltInFunction{ EOpAtomicXor, "atomicXor", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
BuiltInFunction{ EOpAtomicExchange, "atomicExchange", 2, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
BuiltInFunction{ EOpAtomicCompSwap, "atomicCompSwap", 3, TypeIU, ClassV1FIOCV, {Es310Desktop400Version} },
BuiltInFunction{ EOpMix, "mix", 3, TypeB, ClassRegular, {Es310Desktop450Version} },
BuiltInFunction{ EOpMix, "mix", 3, TypeIU, ClassLB, {Es310Desktop450Version} },
};
const std::array DerivativeFunctions = {
BuiltInFunction{ EOpDPdx, "dFdx", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpDPdy, "dFdy", 1, TypeF, ClassRegular, {} },
BuiltInFunction{ EOpFwidth, "fwidth", 1, TypeF, ClassRegular, {} },
};
// For functions declared some other way, but still use the table to relate to operator.
struct CustomFunction {
TOperator op; // operator to map the name to
const char* name; // function name
const span<const Versioning> versioning; // An empty span means always a valid version
};
const CustomFunction CustomFunctions[] = {
{ EOpBarrier, "barrier", {} },
{ EOpMemoryBarrierShared, "memoryBarrierShared", {} },
{ EOpGroupMemoryBarrier, "groupMemoryBarrier", {} },
{ EOpMemoryBarrier, "memoryBarrier", {} },
{ EOpMemoryBarrierBuffer, "memoryBarrierBuffer", {} },
{ EOpPackSnorm2x16, "packSnorm2x16", {} },
{ EOpUnpackSnorm2x16, "unpackSnorm2x16", {} },
{ EOpPackUnorm2x16, "packUnorm2x16", {} },
{ EOpUnpackUnorm2x16, "unpackUnorm2x16", {} },
{ EOpPackHalf2x16, "packHalf2x16", {} },
{ EOpUnpackHalf2x16, "unpackHalf2x16", {} },
{ EOpMul, "matrixCompMult", {} },
{ EOpOuterProduct, "outerProduct", {} },
{ EOpTranspose, "transpose", {} },
{ EOpDeterminant, "determinant", {} },
{ EOpMatrixInverse, "inverse", {} },
{ EOpFloatBitsToInt, "floatBitsToInt", {} },
{ EOpFloatBitsToUint, "floatBitsToUint", {} },
{ EOpIntBitsToFloat, "intBitsToFloat", {} },
{ EOpUintBitsToFloat, "uintBitsToFloat", {} },
{ EOpTextureQuerySize, "textureSize", {} },
{ EOpTextureQueryLod, "textureQueryLod", {} },
{ EOpTextureQueryLod, "textureQueryLOD", {} }, // extension GL_ARB_texture_query_lod
{ EOpTextureQueryLevels, "textureQueryLevels", {} },
{ EOpTextureQuerySamples, "textureSamples", {} },
{ EOpTexture, "texture", {} },
{ EOpTextureProj, "textureProj", {} },
{ EOpTextureLod, "textureLod", {} },
{ EOpTextureOffset, "textureOffset", {} },
{ EOpTextureFetch, "texelFetch", {} },
{ EOpTextureFetchOffset, "texelFetchOffset", {} },
{ EOpTextureProjOffset, "textureProjOffset", {} },
{ EOpTextureLodOffset, "textureLodOffset", {} },
{ EOpTextureProjLod, "textureProjLod", {} },
{ EOpTextureProjLodOffset, "textureProjLodOffset", {} },
{ EOpTextureGrad, "textureGrad", {} },
{ EOpTextureGradOffset, "textureGradOffset", {} },
{ EOpTextureProjGrad, "textureProjGrad", {} },
{ EOpTextureProjGradOffset, "textureProjGradOffset", {} },
};
// For the given table of functions, add all the indicated prototypes for each
// one, to be returned in the passed in decls.
void AddTabledBuiltin(TString& decls, const BuiltInFunction& function)
{
const auto isScalarType = [](int type) { return (type & TypeStringColumnMask) == 0; };
// loop across these two:
// 0: the varying arg set, and
// 1: the fixed scalar args
const ArgClass ClassFixed = (ArgClass)(ClassLS | ClassXLS | ClassLS2 | ClassFS | ClassFS2);
for (int fixed = 0; fixed < ((function.classes & ClassFixed) > 0 ? 2 : 1); ++fixed) {
if (fixed == 0 && (function.classes & ClassXLS))
continue;
// walk the type strings in TypeString[]
for (int type = 0; type < TypeStringCount; ++type) {
// skip types not selected: go from type to row number to type bit
if ((function.types & (1 << (type >> TypeStringRowShift))) == 0)
continue;
// if we aren't on a scalar, and should be, skip
if ((function.classes & ClassV1) && !isScalarType(type))
continue;
// if we aren't on a 3-vector, and should be, skip
if ((function.classes & ClassV3) && (type & TypeStringColumnMask) != 2)
continue;
// skip replication of all arg scalars between the varying arg set and the fixed args
if (fixed == 1 && type == (type & TypeStringScalarMask) && (function.classes & ClassXLS) == 0)
continue;
// skip scalars when we are told to
if ((function.classes & ClassNS) && isScalarType(type))
continue;
// return type
if (function.classes & ClassB)
decls.append(TypeString[type & TypeStringColumnMask]);
else if (function.classes & ClassRS)
decls.append(TypeString[type & TypeStringScalarMask]);
else
decls.append(TypeString[type]);
decls.append(" ");
decls.append(function.name);
decls.append("(");
// arguments
for (int arg = 0; arg < function.numArguments; ++arg) {
if (arg == function.numArguments - 1 && (function.classes & ClassLO))
decls.append("out ");
if (arg == 0) {
if (function.classes & ClassCV)
decls.append("coherent volatile ");
if (function.classes & ClassFIO)
decls.append("inout ");
if (function.classes & ClassFO)
decls.append("out ");
}
if ((function.classes & ClassLB) && arg == function.numArguments - 1)
decls.append(TypeString[type & TypeStringColumnMask]);
else if (fixed && ((arg == function.numArguments - 1 && (function.classes & (ClassLS | ClassXLS |
ClassLS2))) ||
(arg == function.numArguments - 2 && (function.classes & ClassLS2)) ||
(arg == 0 && (function.classes & (ClassFS | ClassFS2))) ||
(arg == 1 && (function.classes & ClassFS2))))
decls.append(TypeString[type & TypeStringScalarMask]);
else
decls.append(TypeString[type]);
if (arg < function.numArguments - 1)
decls.append(",");
}
decls.append(");\n");
}
}
}
// See if the tabled versioning information allows the current version.
bool ValidVersion(const BuiltInFunction& function, int version, EProfile profile, const SpvVersion& /* spVersion */)
{
// nullptr means always valid
if (function.versioning.empty())
return true;
// check for what is said about our current profile
for (const auto& v : function.versioning) {
if ((v.profiles & profile) != 0) {
if (v.minCoreVersion <= version || (v.numExtensions > 0 && v.minExtendedVersion <= version))
return true;
}
}
return false;
}
// Relate a single table of built-ins to their AST operator.
// This can get called redundantly (especially for the common built-ins, when
// called once per stage). This is a performance issue only, not a correctness
// concern. It is done for quality arising from simplicity, as there are subtleties
// to get correct if instead trying to do it surgically.
template<class FunctionContainer>
void RelateTabledBuiltins(const FunctionContainer& functions, TSymbolTable& symbolTable)
{
for (const auto& fn : functions) {
symbolTable.relateToOperator(fn.name, fn.op);
}
}
} // end anonymous namespace
// Add declarations for all tables of built-in functions.
void TBuiltIns::addTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion)
{
const auto forEachFunction = [&](TString& decls, const span<const BuiltInFunction>& functions) {
for (const auto& fn : functions) {
if (ValidVersion(fn, version, profile, spvVersion))
AddTabledBuiltin(decls, fn);
}
};
forEachFunction(commonBuiltins, BaseFunctions);
forEachFunction(stageBuiltins[EShLangFragment], DerivativeFunctions);
if ((profile == EEsProfile && version >= 320) || (profile != EEsProfile && version >= 450))
forEachFunction(stageBuiltins[EShLangCompute], DerivativeFunctions);
}
// Relate all tables of built-ins to the AST operators.
void TBuiltIns::relateTabledBuiltins(int /* version */, EProfile /* profile */, const SpvVersion& /* spvVersion */, EShLanguage /* stage */, TSymbolTable& symbolTable)
{
RelateTabledBuiltins(BaseFunctions, symbolTable);
RelateTabledBuiltins(DerivativeFunctions, symbolTable);
RelateTabledBuiltins(CustomFunctions, symbolTable);
}
inline bool IncludeLegacy(int version, EProfile profile, const SpvVersion& spvVersion)
{
return profile != EEsProfile && (version <= 130 || (spvVersion.spv == 0 && version == 140 && ARBCompatibility) ||
profile == ECompatibilityProfile);
}
// Construct TBuiltInParseables base class. This can be used for language-common constructs.
TBuiltInParseables::TBuiltInParseables()
{
}
// Destroy TBuiltInParseables.
TBuiltInParseables::~TBuiltInParseables()
{
}
TBuiltIns::TBuiltIns()
{
// Set up textual representations for making all the permutations
// of texturing/imaging functions.
prefixes[EbtFloat] = "";
prefixes[EbtInt] = "i";
prefixes[EbtUint] = "u";
prefixes[EbtFloat16] = "f16";
prefixes[EbtInt8] = "i8";
prefixes[EbtUint8] = "u8";
prefixes[EbtInt16] = "i16";
prefixes[EbtUint16] = "u16";
prefixes[EbtInt64] = "i64";
prefixes[EbtUint64] = "u64";
postfixes[2] = "2";
postfixes[3] = "3";
postfixes[4] = "4";
// Map from symbolic class of texturing dimension to numeric dimensions.
dimMap[Esd2D] = 2;
dimMap[Esd3D] = 3;
dimMap[EsdCube] = 3;
dimMap[Esd1D] = 1;
dimMap[EsdRect] = 2;
dimMap[EsdBuffer] = 1;
dimMap[EsdSubpass] = 2; // potentially unused for now
dimMap[EsdAttachmentEXT] = 2; // potentially unused for now
}
TBuiltIns::~TBuiltIns()
{
}
//
// Add all context-independent built-in functions and variables that are present
// for the given version and profile. Share common ones across stages, otherwise
// make stage-specific entries.
//
// Most built-ins variables can be added as simple text strings. Some need to
// be added programmatically, which is done later in IdentifyBuiltIns() below.
//
void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvVersion)
{
addTabledBuiltins(version, profile, spvVersion);
//============================================================================
//
// Prototypes for built-in functions used repeatly by different shaders
//
//============================================================================
//
// Derivatives Functions.
//
TString derivativeControls (
"float dFdxFine(float p);"
"vec2 dFdxFine(vec2 p);"
"vec3 dFdxFine(vec3 p);"
"vec4 dFdxFine(vec4 p);"
"float dFdyFine(float p);"
"vec2 dFdyFine(vec2 p);"
"vec3 dFdyFine(vec3 p);"
"vec4 dFdyFine(vec4 p);"
"float fwidthFine(float p);"
"vec2 fwidthFine(vec2 p);"
"vec3 fwidthFine(vec3 p);"
"vec4 fwidthFine(vec4 p);"
"float dFdxCoarse(float p);"
"vec2 dFdxCoarse(vec2 p);"
"vec3 dFdxCoarse(vec3 p);"
"vec4 dFdxCoarse(vec4 p);"
"float dFdyCoarse(float p);"
"vec2 dFdyCoarse(vec2 p);"
"vec3 dFdyCoarse(vec3 p);"
"vec4 dFdyCoarse(vec4 p);"
"float fwidthCoarse(float p);"
"vec2 fwidthCoarse(vec2 p);"
"vec3 fwidthCoarse(vec3 p);"
"vec4 fwidthCoarse(vec4 p);"
);
TString derivativesAndControl16bits (
"float16_t dFdx(float16_t);"
"f16vec2 dFdx(f16vec2);"
"f16vec3 dFdx(f16vec3);"
"f16vec4 dFdx(f16vec4);"
"float16_t dFdy(float16_t);"
"f16vec2 dFdy(f16vec2);"
"f16vec3 dFdy(f16vec3);"
"f16vec4 dFdy(f16vec4);"
"float16_t dFdxFine(float16_t);"
"f16vec2 dFdxFine(f16vec2);"
"f16vec3 dFdxFine(f16vec3);"
"f16vec4 dFdxFine(f16vec4);"
"float16_t dFdyFine(float16_t);"
"f16vec2 dFdyFine(f16vec2);"
"f16vec3 dFdyFine(f16vec3);"
"f16vec4 dFdyFine(f16vec4);"
"float16_t dFdxCoarse(float16_t);"
"f16vec2 dFdxCoarse(f16vec2);"
"f16vec3 dFdxCoarse(f16vec3);"
"f16vec4 dFdxCoarse(f16vec4);"
"float16_t dFdyCoarse(float16_t);"
"f16vec2 dFdyCoarse(f16vec2);"
"f16vec3 dFdyCoarse(f16vec3);"
"f16vec4 dFdyCoarse(f16vec4);"
"float16_t fwidth(float16_t);"
"f16vec2 fwidth(f16vec2);"
"f16vec3 fwidth(f16vec3);"
"f16vec4 fwidth(f16vec4);"
"float16_t fwidthFine(float16_t);"
"f16vec2 fwidthFine(f16vec2);"
"f16vec3 fwidthFine(f16vec3);"
"f16vec4 fwidthFine(f16vec4);"
"float16_t fwidthCoarse(float16_t);"
"f16vec2 fwidthCoarse(f16vec2);"
"f16vec3 fwidthCoarse(f16vec3);"
"f16vec4 fwidthCoarse(f16vec4);"
);
TString derivativesAndControl64bits (
"float64_t dFdx(float64_t);"
"f64vec2 dFdx(f64vec2);"
"f64vec3 dFdx(f64vec3);"
"f64vec4 dFdx(f64vec4);"
"float64_t dFdy(float64_t);"
"f64vec2 dFdy(f64vec2);"
"f64vec3 dFdy(f64vec3);"
"f64vec4 dFdy(f64vec4);"
"float64_t dFdxFine(float64_t);"
"f64vec2 dFdxFine(f64vec2);"
"f64vec3 dFdxFine(f64vec3);"
"f64vec4 dFdxFine(f64vec4);"
"float64_t dFdyFine(float64_t);"
"f64vec2 dFdyFine(f64vec2);"
"f64vec3 dFdyFine(f64vec3);"
"f64vec4 dFdyFine(f64vec4);"
"float64_t dFdxCoarse(float64_t);"
"f64vec2 dFdxCoarse(f64vec2);"
"f64vec3 dFdxCoarse(f64vec3);"
"f64vec4 dFdxCoarse(f64vec4);"
"float64_t dFdyCoarse(float64_t);"
"f64vec2 dFdyCoarse(f64vec2);"
"f64vec3 dFdyCoarse(f64vec3);"
"f64vec4 dFdyCoarse(f64vec4);"
"float64_t fwidth(float64_t);"
"f64vec2 fwidth(f64vec2);"
"f64vec3 fwidth(f64vec3);"
"f64vec4 fwidth(f64vec4);"
"float64_t fwidthFine(float64_t);"
"f64vec2 fwidthFine(f64vec2);"
"f64vec3 fwidthFine(f64vec3);"
"f64vec4 fwidthFine(f64vec4);"
"float64_t fwidthCoarse(float64_t);"
"f64vec2 fwidthCoarse(f64vec2);"
"f64vec3 fwidthCoarse(f64vec3);"
"f64vec4 fwidthCoarse(f64vec4);"
);
//============================================================================
//
// Prototypes for built-in functions seen by both vertex and fragment shaders.
//
//============================================================================
//
// double functions added to desktop 4.00, but not fma, frexp, ldexp, or pack/unpack
//
if (profile != EEsProfile && version >= 150) { // ARB_gpu_shader_fp64
commonBuiltins.append(
"double sqrt(double);"
"dvec2 sqrt(dvec2);"
"dvec3 sqrt(dvec3);"
"dvec4 sqrt(dvec4);"
"double inversesqrt(double);"
"dvec2 inversesqrt(dvec2);"
"dvec3 inversesqrt(dvec3);"
"dvec4 inversesqrt(dvec4);"
"double abs(double);"
"dvec2 abs(dvec2);"
"dvec3 abs(dvec3);"
"dvec4 abs(dvec4);"
"double sign(double);"
"dvec2 sign(dvec2);"
"dvec3 sign(dvec3);"
"dvec4 sign(dvec4);"
"double floor(double);"
"dvec2 floor(dvec2);"
"dvec3 floor(dvec3);"
"dvec4 floor(dvec4);"
"double trunc(double);"
"dvec2 trunc(dvec2);"
"dvec3 trunc(dvec3);"
"dvec4 trunc(dvec4);"
"double round(double);"
"dvec2 round(dvec2);"
"dvec3 round(dvec3);"
"dvec4 round(dvec4);"
"double roundEven(double);"
"dvec2 roundEven(dvec2);"
"dvec3 roundEven(dvec3);"
"dvec4 roundEven(dvec4);"
"double ceil(double);"
"dvec2 ceil(dvec2);"
"dvec3 ceil(dvec3);"
"dvec4 ceil(dvec4);"
"double fract(double);"
"dvec2 fract(dvec2);"
"dvec3 fract(dvec3);"
"dvec4 fract(dvec4);"
"double mod(double, double);"
"dvec2 mod(dvec2 , double);"
"dvec3 mod(dvec3 , double);"
"dvec4 mod(dvec4 , double);"
"dvec2 mod(dvec2 , dvec2);"
"dvec3 mod(dvec3 , dvec3);"
"dvec4 mod(dvec4 , dvec4);"
"double modf(double, out double);"
"dvec2 modf(dvec2, out dvec2);"
"dvec3 modf(dvec3, out dvec3);"
"dvec4 modf(dvec4, out dvec4);"
"double min(double, double);"
"dvec2 min(dvec2, double);"
"dvec3 min(dvec3, double);"
"dvec4 min(dvec4, double);"
"dvec2 min(dvec2, dvec2);"
"dvec3 min(dvec3, dvec3);"
"dvec4 min(dvec4, dvec4);"
"double max(double, double);"
"dvec2 max(dvec2 , double);"
"dvec3 max(dvec3 , double);"
"dvec4 max(dvec4 , double);"
"dvec2 max(dvec2 , dvec2);"
"dvec3 max(dvec3 , dvec3);"
"dvec4 max(dvec4 , dvec4);"
"double clamp(double, double, double);"
"dvec2 clamp(dvec2 , double, double);"
"dvec3 clamp(dvec3 , double, double);"
"dvec4 clamp(dvec4 , double, double);"
"dvec2 clamp(dvec2 , dvec2 , dvec2);"
"dvec3 clamp(dvec3 , dvec3 , dvec3);"
"dvec4 clamp(dvec4 , dvec4 , dvec4);"
"double mix(double, double, double);"
"dvec2 mix(dvec2, dvec2, double);"
"dvec3 mix(dvec3, dvec3, double);"
"dvec4 mix(dvec4, dvec4, double);"
"dvec2 mix(dvec2, dvec2, dvec2);"
"dvec3 mix(dvec3, dvec3, dvec3);"
"dvec4 mix(dvec4, dvec4, dvec4);"
"double mix(double, double, bool);"
"dvec2 mix(dvec2, dvec2, bvec2);"
"dvec3 mix(dvec3, dvec3, bvec3);"
"dvec4 mix(dvec4, dvec4, bvec4);"
"double step(double, double);"
"dvec2 step(dvec2 , dvec2);"
"dvec3 step(dvec3 , dvec3);"
"dvec4 step(dvec4 , dvec4);"
"dvec2 step(double, dvec2);"
"dvec3 step(double, dvec3);"
"dvec4 step(double, dvec4);"
"double smoothstep(double, double, double);"
"dvec2 smoothstep(dvec2 , dvec2 , dvec2);"
"dvec3 smoothstep(dvec3 , dvec3 , dvec3);"
"dvec4 smoothstep(dvec4 , dvec4 , dvec4);"
"dvec2 smoothstep(double, double, dvec2);"
"dvec3 smoothstep(double, double, dvec3);"
"dvec4 smoothstep(double, double, dvec4);"
"bool isnan(double);"
"bvec2 isnan(dvec2);"
"bvec3 isnan(dvec3);"
"bvec4 isnan(dvec4);"
"bool isinf(double);"
"bvec2 isinf(dvec2);"
"bvec3 isinf(dvec3);"
"bvec4 isinf(dvec4);"
"double length(double);"
"double length(dvec2);"
"double length(dvec3);"
"double length(dvec4);"
"double distance(double, double);"
"double distance(dvec2 , dvec2);"
"double distance(dvec3 , dvec3);"
"double distance(dvec4 , dvec4);"
"double dot(double, double);"
"double dot(dvec2 , dvec2);"
"double dot(dvec3 , dvec3);"
"double dot(dvec4 , dvec4);"
"dvec3 cross(dvec3, dvec3);"
"double normalize(double);"
"dvec2 normalize(dvec2);"
"dvec3 normalize(dvec3);"
"dvec4 normalize(dvec4);"
"double faceforward(double, double, double);"
"dvec2 faceforward(dvec2, dvec2, dvec2);"
"dvec3 faceforward(dvec3, dvec3, dvec3);"
"dvec4 faceforward(dvec4, dvec4, dvec4);"
"double reflect(double, double);"
"dvec2 reflect(dvec2 , dvec2 );"
"dvec3 reflect(dvec3 , dvec3 );"
"dvec4 reflect(dvec4 , dvec4 );"
"double refract(double, double, double);"
"dvec2 refract(dvec2 , dvec2 , double);"
"dvec3 refract(dvec3 , dvec3 , double);"
"dvec4 refract(dvec4 , dvec4 , double);"
"dmat2 matrixCompMult(dmat2, dmat2);"
"dmat3 matrixCompMult(dmat3, dmat3);"
"dmat4 matrixCompMult(dmat4, dmat4);"
"dmat2x3 matrixCompMult(dmat2x3, dmat2x3);"
"dmat2x4 matrixCompMult(dmat2x4, dmat2x4);"
"dmat3x2 matrixCompMult(dmat3x2, dmat3x2);"
"dmat3x4 matrixCompMult(dmat3x4, dmat3x4);"
"dmat4x2 matrixCompMult(dmat4x2, dmat4x2);"
"dmat4x3 matrixCompMult(dmat4x3, dmat4x3);"
"dmat2 outerProduct(dvec2, dvec2);"
"dmat3 outerProduct(dvec3, dvec3);"
"dmat4 outerProduct(dvec4, dvec4);"
"dmat2x3 outerProduct(dvec3, dvec2);"
"dmat3x2 outerProduct(dvec2, dvec3);"
"dmat2x4 outerProduct(dvec4, dvec2);"
"dmat4x2 outerProduct(dvec2, dvec4);"
"dmat3x4 outerProduct(dvec4, dvec3);"
"dmat4x3 outerProduct(dvec3, dvec4);"
"dmat2 transpose(dmat2);"
"dmat3 transpose(dmat3);"
"dmat4 transpose(dmat4);"
"dmat2x3 transpose(dmat3x2);"
"dmat3x2 transpose(dmat2x3);"
"dmat2x4 transpose(dmat4x2);"
"dmat4x2 transpose(dmat2x4);"
"dmat3x4 transpose(dmat4x3);"
"dmat4x3 transpose(dmat3x4);"
"double determinant(dmat2);"
"double determinant(dmat3);"
"double determinant(dmat4);"
"dmat2 inverse(dmat2);"
"dmat3 inverse(dmat3);"
"dmat4 inverse(dmat4);"
"bvec2 lessThan(dvec2, dvec2);"
"bvec3 lessThan(dvec3, dvec3);"
"bvec4 lessThan(dvec4, dvec4);"
"bvec2 lessThanEqual(dvec2, dvec2);"
"bvec3 lessThanEqual(dvec3, dvec3);"
"bvec4 lessThanEqual(dvec4, dvec4);"
"bvec2 greaterThan(dvec2, dvec2);"
"bvec3 greaterThan(dvec3, dvec3);"
"bvec4 greaterThan(dvec4, dvec4);"
"bvec2 greaterThanEqual(dvec2, dvec2);"
"bvec3 greaterThanEqual(dvec3, dvec3);"
"bvec4 greaterThanEqual(dvec4, dvec4);"
"bvec2 equal(dvec2, dvec2);"
"bvec3 equal(dvec3, dvec3);"
"bvec4 equal(dvec4, dvec4);"
"bvec2 notEqual(dvec2, dvec2);"
"bvec3 notEqual(dvec3, dvec3);"
"bvec4 notEqual(dvec4, dvec4);"
"\n");
}
if (profile == EEsProfile && version >= 310) { // Explicit Types
commonBuiltins.append(
"float64_t sqrt(float64_t);"
"f64vec2 sqrt(f64vec2);"
"f64vec3 sqrt(f64vec3);"
"f64vec4 sqrt(f64vec4);"
"float64_t inversesqrt(float64_t);"
"f64vec2 inversesqrt(f64vec2);"
"f64vec3 inversesqrt(f64vec3);"
"f64vec4 inversesqrt(f64vec4);"
"float64_t abs(float64_t);"
"f64vec2 abs(f64vec2);"
"f64vec3 abs(f64vec3);"
"f64vec4 abs(f64vec4);"
"float64_t sign(float64_t);"
"f64vec2 sign(f64vec2);"
"f64vec3 sign(f64vec3);"
"f64vec4 sign(f64vec4);"
"float64_t floor(float64_t);"
"f64vec2 floor(f64vec2);"
"f64vec3 floor(f64vec3);"
"f64vec4 floor(f64vec4);"
"float64_t trunc(float64_t);"
"f64vec2 trunc(f64vec2);"
"f64vec3 trunc(f64vec3);"
"f64vec4 trunc(f64vec4);"
"float64_t round(float64_t);"
"f64vec2 round(f64vec2);"
"f64vec3 round(f64vec3);"
"f64vec4 round(f64vec4);"
"float64_t roundEven(float64_t);"
"f64vec2 roundEven(f64vec2);"
"f64vec3 roundEven(f64vec3);"
"f64vec4 roundEven(f64vec4);"
"float64_t ceil(float64_t);"
"f64vec2 ceil(f64vec2);"
"f64vec3 ceil(f64vec3);"
"f64vec4 ceil(f64vec4);"
"float64_t fract(float64_t);"
"f64vec2 fract(f64vec2);"
"f64vec3 fract(f64vec3);"
"f64vec4 fract(f64vec4);"
"float64_t mod(float64_t, float64_t);"
"f64vec2 mod(f64vec2 , float64_t);"
"f64vec3 mod(f64vec3 , float64_t);"
"f64vec4 mod(f64vec4 , float64_t);"
"f64vec2 mod(f64vec2 , f64vec2);"
"f64vec3 mod(f64vec3 , f64vec3);"
"f64vec4 mod(f64vec4 , f64vec4);"
"float64_t modf(float64_t, out float64_t);"
"f64vec2 modf(f64vec2, out f64vec2);"
"f64vec3 modf(f64vec3, out f64vec3);"
"f64vec4 modf(f64vec4, out f64vec4);"
"float64_t min(float64_t, float64_t);"
"f64vec2 min(f64vec2, float64_t);"
"f64vec3 min(f64vec3, float64_t);"
"f64vec4 min(f64vec4, float64_t);"
"f64vec2 min(f64vec2, f64vec2);"
"f64vec3 min(f64vec3, f64vec3);"
"f64vec4 min(f64vec4, f64vec4);"
"float64_t max(float64_t, float64_t);"
"f64vec2 max(f64vec2 , float64_t);"
"f64vec3 max(f64vec3 , float64_t);"
"f64vec4 max(f64vec4 , float64_t);"
"f64vec2 max(f64vec2 , f64vec2);"
"f64vec3 max(f64vec3 , f64vec3);"
"f64vec4 max(f64vec4 , f64vec4);"
"float64_t clamp(float64_t, float64_t, float64_t);"
"f64vec2 clamp(f64vec2 , float64_t, float64_t);"
"f64vec3 clamp(f64vec3 , float64_t, float64_t);"
"f64vec4 clamp(f64vec4 , float64_t, float64_t);"
"f64vec2 clamp(f64vec2 , f64vec2 , f64vec2);"
"f64vec3 clamp(f64vec3 , f64vec3 , f64vec3);"
"f64vec4 clamp(f64vec4 , f64vec4 , f64vec4);"
"float64_t mix(float64_t, float64_t, float64_t);"
"f64vec2 mix(f64vec2, f64vec2, float64_t);"
"f64vec3 mix(f64vec3, f64vec3, float64_t);"
"f64vec4 mix(f64vec4, f64vec4, float64_t);"
"f64vec2 mix(f64vec2, f64vec2, f64vec2);"
"f64vec3 mix(f64vec3, f64vec3, f64vec3);"
"f64vec4 mix(f64vec4, f64vec4, f64vec4);"
"float64_t mix(float64_t, float64_t, bool);"
"f64vec2 mix(f64vec2, f64vec2, bvec2);"
"f64vec3 mix(f64vec3, f64vec3, bvec3);"
"f64vec4 mix(f64vec4, f64vec4, bvec4);"
"float64_t step(float64_t, float64_t);"
"f64vec2 step(f64vec2 , f64vec2);"
"f64vec3 step(f64vec3 , f64vec3);"
"f64vec4 step(f64vec4 , f64vec4);"
"f64vec2 step(float64_t, f64vec2);"
"f64vec3 step(float64_t, f64vec3);"
"f64vec4 step(float64_t, f64vec4);"
"float64_t smoothstep(float64_t, float64_t, float64_t);"
"f64vec2 smoothstep(f64vec2 , f64vec2 , f64vec2);"
"f64vec3 smoothstep(f64vec3 , f64vec3 , f64vec3);"
"f64vec4 smoothstep(f64vec4 , f64vec4 , f64vec4);"
"f64vec2 smoothstep(float64_t, float64_t, f64vec2);"
"f64vec3 smoothstep(float64_t, float64_t, f64vec3);"
"f64vec4 smoothstep(float64_t, float64_t, f64vec4);"
"float64_t length(float64_t);"
"float64_t length(f64vec2);"
"float64_t length(f64vec3);"
"float64_t length(f64vec4);"
"float64_t distance(float64_t, float64_t);"
"float64_t distance(f64vec2 , f64vec2);"
"float64_t distance(f64vec3 , f64vec3);"
"float64_t distance(f64vec4 , f64vec4);"
"float64_t dot(float64_t, float64_t);"
"float64_t dot(f64vec2 , f64vec2);"
"float64_t dot(f64vec3 , f64vec3);"
"float64_t dot(f64vec4 , f64vec4);"
"f64vec3 cross(f64vec3, f64vec3);"
"float64_t normalize(float64_t);"
"f64vec2 normalize(f64vec2);"
"f64vec3 normalize(f64vec3);"
"f64vec4 normalize(f64vec4);"
"float64_t faceforward(float64_t, float64_t, float64_t);"
"f64vec2 faceforward(f64vec2, f64vec2, f64vec2);"
"f64vec3 faceforward(f64vec3, f64vec3, f64vec3);"
"f64vec4 faceforward(f64vec4, f64vec4, f64vec4);"
"float64_t reflect(float64_t, float64_t);"
"f64vec2 reflect(f64vec2 , f64vec2 );"
"f64vec3 reflect(f64vec3 , f64vec3 );"
"f64vec4 reflect(f64vec4 , f64vec4 );"
"float64_t refract(float64_t, float64_t, float64_t);"
"f64vec2 refract(f64vec2 , f64vec2 , float64_t);"
"f64vec3 refract(f64vec3 , f64vec3 , float64_t);"
"f64vec4 refract(f64vec4 , f64vec4 , float64_t);"
"f64mat2 matrixCompMult(f64mat2, f64mat2);"
"f64mat3 matrixCompMult(f64mat3, f64mat3);"
"f64mat4 matrixCompMult(f64mat4, f64mat4);"
"f64mat2x3 matrixCompMult(f64mat2x3, f64mat2x3);"
"f64mat2x4 matrixCompMult(f64mat2x4, f64mat2x4);"
"f64mat3x2 matrixCompMult(f64mat3x2, f64mat3x2);"
"f64mat3x4 matrixCompMult(f64mat3x4, f64mat3x4);"
"f64mat4x2 matrixCompMult(f64mat4x2, f64mat4x2);"
"f64mat4x3 matrixCompMult(f64mat4x3, f64mat4x3);"
"f64mat2 outerProduct(f64vec2, f64vec2);"
"f64mat3 outerProduct(f64vec3, f64vec3);"
"f64mat4 outerProduct(f64vec4, f64vec4);"
"f64mat2x3 outerProduct(f64vec3, f64vec2);"
"f64mat3x2 outerProduct(f64vec2, f64vec3);"
"f64mat2x4 outerProduct(f64vec4, f64vec2);"
"f64mat4x2 outerProduct(f64vec2, f64vec4);"
"f64mat3x4 outerProduct(f64vec4, f64vec3);"
"f64mat4x3 outerProduct(f64vec3, f64vec4);"
"f64mat2 transpose(f64mat2);"
"f64mat3 transpose(f64mat3);"
"f64mat4 transpose(f64mat4);"
"f64mat2x3 transpose(f64mat3x2);"
"f64mat3x2 transpose(f64mat2x3);"
"f64mat2x4 transpose(f64mat4x2);"
"f64mat4x2 transpose(f64mat2x4);"
"f64mat3x4 transpose(f64mat4x3);"
"f64mat4x3 transpose(f64mat3x4);"
"float64_t determinant(f64mat2);"
"float64_t determinant(f64mat3);"
"float64_t determinant(f64mat4);"
"f64mat2 inverse(f64mat2);"
"f64mat3 inverse(f64mat3);"
"f64mat4 inverse(f64mat4);"
"\n");
}
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
commonBuiltins.append(
"int64_t abs(int64_t);"
"i64vec2 abs(i64vec2);"
"i64vec3 abs(i64vec3);"
"i64vec4 abs(i64vec4);"
"int64_t sign(int64_t);"
"i64vec2 sign(i64vec2);"
"i64vec3 sign(i64vec3);"
"i64vec4 sign(i64vec4);"
"int64_t min(int64_t, int64_t);"
"i64vec2 min(i64vec2, int64_t);"
"i64vec3 min(i64vec3, int64_t);"
"i64vec4 min(i64vec4, int64_t);"
"i64vec2 min(i64vec2, i64vec2);"
"i64vec3 min(i64vec3, i64vec3);"
"i64vec4 min(i64vec4, i64vec4);"
"uint64_t min(uint64_t, uint64_t);"
"u64vec2 min(u64vec2, uint64_t);"
"u64vec3 min(u64vec3, uint64_t);"
"u64vec4 min(u64vec4, uint64_t);"
"u64vec2 min(u64vec2, u64vec2);"
"u64vec3 min(u64vec3, u64vec3);"
"u64vec4 min(u64vec4, u64vec4);"
"int64_t max(int64_t, int64_t);"
"i64vec2 max(i64vec2, int64_t);"
"i64vec3 max(i64vec3, int64_t);"
"i64vec4 max(i64vec4, int64_t);"
"i64vec2 max(i64vec2, i64vec2);"
"i64vec3 max(i64vec3, i64vec3);"
"i64vec4 max(i64vec4, i64vec4);"
"uint64_t max(uint64_t, uint64_t);"
"u64vec2 max(u64vec2, uint64_t);"
"u64vec3 max(u64vec3, uint64_t);"
"u64vec4 max(u64vec4, uint64_t);"
"u64vec2 max(u64vec2, u64vec2);"
"u64vec3 max(u64vec3, u64vec3);"
"u64vec4 max(u64vec4, u64vec4);"
"int64_t clamp(int64_t, int64_t, int64_t);"
"i64vec2 clamp(i64vec2, int64_t, int64_t);"
"i64vec3 clamp(i64vec3, int64_t, int64_t);"
"i64vec4 clamp(i64vec4, int64_t, int64_t);"
"i64vec2 clamp(i64vec2, i64vec2, i64vec2);"
"i64vec3 clamp(i64vec3, i64vec3, i64vec3);"
"i64vec4 clamp(i64vec4, i64vec4, i64vec4);"
"uint64_t clamp(uint64_t, uint64_t, uint64_t);"
"u64vec2 clamp(u64vec2, uint64_t, uint64_t);"
"u64vec3 clamp(u64vec3, uint64_t, uint64_t);"
"u64vec4 clamp(u64vec4, uint64_t, uint64_t);"
"u64vec2 clamp(u64vec2, u64vec2, u64vec2);"
"u64vec3 clamp(u64vec3, u64vec3, u64vec3);"
"u64vec4 clamp(u64vec4, u64vec4, u64vec4);"
"int64_t mix(int64_t, int64_t, bool);"
"i64vec2 mix(i64vec2, i64vec2, bvec2);"
"i64vec3 mix(i64vec3, i64vec3, bvec3);"
"i64vec4 mix(i64vec4, i64vec4, bvec4);"
"uint64_t mix(uint64_t, uint64_t, bool);"
"u64vec2 mix(u64vec2, u64vec2, bvec2);"
"u64vec3 mix(u64vec3, u64vec3, bvec3);"
"u64vec4 mix(u64vec4, u64vec4, bvec4);"
"int64_t doubleBitsToInt64(float64_t);"
"i64vec2 doubleBitsToInt64(f64vec2);"
"i64vec3 doubleBitsToInt64(f64vec3);"
"i64vec4 doubleBitsToInt64(f64vec4);"
"uint64_t doubleBitsToUint64(float64_t);"
"u64vec2 doubleBitsToUint64(f64vec2);"
"u64vec3 doubleBitsToUint64(f64vec3);"
"u64vec4 doubleBitsToUint64(f64vec4);"
"float64_t int64BitsToDouble(int64_t);"
"f64vec2 int64BitsToDouble(i64vec2);"
"f64vec3 int64BitsToDouble(i64vec3);"
"f64vec4 int64BitsToDouble(i64vec4);"
"float64_t uint64BitsToDouble(uint64_t);"
"f64vec2 uint64BitsToDouble(u64vec2);"
"f64vec3 uint64BitsToDouble(u64vec3);"
"f64vec4 uint64BitsToDouble(u64vec4);"
"int64_t packInt2x32(ivec2);"
"uint64_t packUint2x32(uvec2);"
"ivec2 unpackInt2x32(int64_t);"
"uvec2 unpackUint2x32(uint64_t);"
"bvec2 lessThan(i64vec2, i64vec2);"
"bvec3 lessThan(i64vec3, i64vec3);"
"bvec4 lessThan(i64vec4, i64vec4);"
"bvec2 lessThan(u64vec2, u64vec2);"
"bvec3 lessThan(u64vec3, u64vec3);"
"bvec4 lessThan(u64vec4, u64vec4);"
"bvec2 lessThanEqual(i64vec2, i64vec2);"
"bvec3 lessThanEqual(i64vec3, i64vec3);"
"bvec4 lessThanEqual(i64vec4, i64vec4);"
"bvec2 lessThanEqual(u64vec2, u64vec2);"
"bvec3 lessThanEqual(u64vec3, u64vec3);"
"bvec4 lessThanEqual(u64vec4, u64vec4);"
"bvec2 greaterThan(i64vec2, i64vec2);"
"bvec3 greaterThan(i64vec3, i64vec3);"
"bvec4 greaterThan(i64vec4, i64vec4);"
"bvec2 greaterThan(u64vec2, u64vec2);"
"bvec3 greaterThan(u64vec3, u64vec3);"
"bvec4 greaterThan(u64vec4, u64vec4);"
"bvec2 greaterThanEqual(i64vec2, i64vec2);"
"bvec3 greaterThanEqual(i64vec3, i64vec3);"
"bvec4 greaterThanEqual(i64vec4, i64vec4);"
"bvec2 greaterThanEqual(u64vec2, u64vec2);"
"bvec3 greaterThanEqual(u64vec3, u64vec3);"
"bvec4 greaterThanEqual(u64vec4, u64vec4);"
"bvec2 equal(i64vec2, i64vec2);"
"bvec3 equal(i64vec3, i64vec3);"
"bvec4 equal(i64vec4, i64vec4);"
"bvec2 equal(u64vec2, u64vec2);"
"bvec3 equal(u64vec3, u64vec3);"
"bvec4 equal(u64vec4, u64vec4);"
"bvec2 notEqual(i64vec2, i64vec2);"
"bvec3 notEqual(i64vec3, i64vec3);"
"bvec4 notEqual(i64vec4, i64vec4);"
"bvec2 notEqual(u64vec2, u64vec2);"
"bvec3 notEqual(u64vec3, u64vec3);"
"bvec4 notEqual(u64vec4, u64vec4);"
"int64_t bitCount(int64_t);"
"i64vec2 bitCount(i64vec2);"
"i64vec3 bitCount(i64vec3);"
"i64vec4 bitCount(i64vec4);"
"int64_t bitCount(uint64_t);"
"i64vec2 bitCount(u64vec2);"
"i64vec3 bitCount(u64vec3);"
"i64vec4 bitCount(u64vec4);"
"int64_t findLSB(int64_t);"
"i64vec2 findLSB(i64vec2);"
"i64vec3 findLSB(i64vec3);"
"i64vec4 findLSB(i64vec4);"
"int64_t findLSB(uint64_t);"
"i64vec2 findLSB(u64vec2);"
"i64vec3 findLSB(u64vec3);"
"i64vec4 findLSB(u64vec4);"
"int64_t findMSB(int64_t);"
"i64vec2 findMSB(i64vec2);"
"i64vec3 findMSB(i64vec3);"
"i64vec4 findMSB(i64vec4);"
"int64_t findMSB(uint64_t);"
"i64vec2 findMSB(u64vec2);"
"i64vec3 findMSB(u64vec3);"
"i64vec4 findMSB(u64vec4);"
"\n"
);
}
// GL_AMD_shader_trinary_minmax
if (profile != EEsProfile && version >= 430) {
commonBuiltins.append(
"float min3(float, float, float);"
"vec2 min3(vec2, vec2, vec2);"
"vec3 min3(vec3, vec3, vec3);"
"vec4 min3(vec4, vec4, vec4);"
"int min3(int, int, int);"
"ivec2 min3(ivec2, ivec2, ivec2);"
"ivec3 min3(ivec3, ivec3, ivec3);"
"ivec4 min3(ivec4, ivec4, ivec4);"
"uint min3(uint, uint, uint);"
"uvec2 min3(uvec2, uvec2, uvec2);"
"uvec3 min3(uvec3, uvec3, uvec3);"
"uvec4 min3(uvec4, uvec4, uvec4);"
"float max3(float, float, float);"
"vec2 max3(vec2, vec2, vec2);"
"vec3 max3(vec3, vec3, vec3);"
"vec4 max3(vec4, vec4, vec4);"
"int max3(int, int, int);"
"ivec2 max3(ivec2, ivec2, ivec2);"
"ivec3 max3(ivec3, ivec3, ivec3);"
"ivec4 max3(ivec4, ivec4, ivec4);"
"uint max3(uint, uint, uint);"
"uvec2 max3(uvec2, uvec2, uvec2);"
"uvec3 max3(uvec3, uvec3, uvec3);"
"uvec4 max3(uvec4, uvec4, uvec4);"
"float mid3(float, float, float);"
"vec2 mid3(vec2, vec2, vec2);"
"vec3 mid3(vec3, vec3, vec3);"
"vec4 mid3(vec4, vec4, vec4);"
"int mid3(int, int, int);"
"ivec2 mid3(ivec2, ivec2, ivec2);"
"ivec3 mid3(ivec3, ivec3, ivec3);"
"ivec4 mid3(ivec4, ivec4, ivec4);"
"uint mid3(uint, uint, uint);"
"uvec2 mid3(uvec2, uvec2, uvec2);"
"uvec3 mid3(uvec3, uvec3, uvec3);"
"uvec4 mid3(uvec4, uvec4, uvec4);"
"float16_t min3(float16_t, float16_t, float16_t);"
"f16vec2 min3(f16vec2, f16vec2, f16vec2);"
"f16vec3 min3(f16vec3, f16vec3, f16vec3);"
"f16vec4 min3(f16vec4, f16vec4, f16vec4);"
"float16_t max3(float16_t, float16_t, float16_t);"
"f16vec2 max3(f16vec2, f16vec2, f16vec2);"
"f16vec3 max3(f16vec3, f16vec3, f16vec3);"
"f16vec4 max3(f16vec4, f16vec4, f16vec4);"
"float16_t mid3(float16_t, float16_t, float16_t);"
"f16vec2 mid3(f16vec2, f16vec2, f16vec2);"
"f16vec3 mid3(f16vec3, f16vec3, f16vec3);"
"f16vec4 mid3(f16vec4, f16vec4, f16vec4);"
"int16_t min3(int16_t, int16_t, int16_t);"
"i16vec2 min3(i16vec2, i16vec2, i16vec2);"
"i16vec3 min3(i16vec3, i16vec3, i16vec3);"
"i16vec4 min3(i16vec4, i16vec4, i16vec4);"
"int16_t max3(int16_t, int16_t, int16_t);"
"i16vec2 max3(i16vec2, i16vec2, i16vec2);"
"i16vec3 max3(i16vec3, i16vec3, i16vec3);"
"i16vec4 max3(i16vec4, i16vec4, i16vec4);"
"int16_t mid3(int16_t, int16_t, int16_t);"
"i16vec2 mid3(i16vec2, i16vec2, i16vec2);"
"i16vec3 mid3(i16vec3, i16vec3, i16vec3);"
"i16vec4 mid3(i16vec4, i16vec4, i16vec4);"
"uint16_t min3(uint16_t, uint16_t, uint16_t);"
"u16vec2 min3(u16vec2, u16vec2, u16vec2);"
"u16vec3 min3(u16vec3, u16vec3, u16vec3);"
"u16vec4 min3(u16vec4, u16vec4, u16vec4);"
"uint16_t max3(uint16_t, uint16_t, uint16_t);"
"u16vec2 max3(u16vec2, u16vec2, u16vec2);"
"u16vec3 max3(u16vec3, u16vec3, u16vec3);"
"u16vec4 max3(u16vec4, u16vec4, u16vec4);"
"uint16_t mid3(uint16_t, uint16_t, uint16_t);"
"u16vec2 mid3(u16vec2, u16vec2, u16vec2);"
"u16vec3 mid3(u16vec3, u16vec3, u16vec3);"
"u16vec4 mid3(u16vec4, u16vec4, u16vec4);"
"\n"
);
}
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 430)) {
commonBuiltins.append(
"uint atomicAdd(coherent volatile inout uint, uint, int, int, int);"
" int atomicAdd(coherent volatile inout int, int, int, int, int);"
"uint atomicMin(coherent volatile inout uint, uint, int, int, int);"
" int atomicMin(coherent volatile inout int, int, int, int, int);"
"uint atomicMax(coherent volatile inout uint, uint, int, int, int);"
" int atomicMax(coherent volatile inout int, int, int, int, int);"
"uint atomicAnd(coherent volatile inout uint, uint, int, int, int);"
" int atomicAnd(coherent volatile inout int, int, int, int, int);"
"uint atomicOr (coherent volatile inout uint, uint, int, int, int);"
" int atomicOr (coherent volatile inout int, int, int, int, int);"
"uint atomicXor(coherent volatile inout uint, uint, int, int, int);"
" int atomicXor(coherent volatile inout int, int, int, int, int);"
"uint atomicExchange(coherent volatile inout uint, uint, int, int, int);"
" int atomicExchange(coherent volatile inout int, int, int, int, int);"
"uint atomicCompSwap(coherent volatile inout uint, uint, uint, int, int, int, int, int);"
" int atomicCompSwap(coherent volatile inout int, int, int, int, int, int, int, int);"
"uint atomicLoad(coherent volatile in uint, int, int, int);"
" int atomicLoad(coherent volatile in int, int, int, int);"
"void atomicStore(coherent volatile out uint, uint, int, int, int);"
"void atomicStore(coherent volatile out int, int, int, int, int);"
"\n");
}
if (profile != EEsProfile && version >= 440) {
commonBuiltins.append(
"uint64_t atomicMin(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicMin(coherent volatile inout int64_t, int64_t);"
"uint64_t atomicMin(coherent volatile inout uint64_t, uint64_t, int, int, int);"
" int64_t atomicMin(coherent volatile inout int64_t, int64_t, int, int, int);"
"float16_t atomicMin(coherent volatile inout float16_t, float16_t);"
"float16_t atomicMin(coherent volatile inout float16_t, float16_t, int, int, int);"
" float atomicMin(coherent volatile inout float, float);"
" float atomicMin(coherent volatile inout float, float, int, int, int);"
" double atomicMin(coherent volatile inout double, double);"
" double atomicMin(coherent volatile inout double, double, int, int, int);"
"uint64_t atomicMax(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicMax(coherent volatile inout int64_t, int64_t);"
"uint64_t atomicMax(coherent volatile inout uint64_t, uint64_t, int, int, int);"
" int64_t atomicMax(coherent volatile inout int64_t, int64_t, int, int, int);"
"float16_t atomicMax(coherent volatile inout float16_t, float16_t);"
"float16_t atomicMax(coherent volatile inout float16_t, float16_t, int, int, int);"
" float atomicMax(coherent volatile inout float, float);"
" float atomicMax(coherent volatile inout float, float, int, int, int);"
" double atomicMax(coherent volatile inout double, double);"
" double atomicMax(coherent volatile inout double, double, int, int, int);"
"uint64_t atomicAnd(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicAnd(coherent volatile inout int64_t, int64_t);"
"uint64_t atomicAnd(coherent volatile inout uint64_t, uint64_t, int, int, int);"
" int64_t atomicAnd(coherent volatile inout int64_t, int64_t, int, int, int);"
"uint64_t atomicOr (coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicOr (coherent volatile inout int64_t, int64_t);"
"uint64_t atomicOr (coherent volatile inout uint64_t, uint64_t, int, int, int);"
" int64_t atomicOr (coherent volatile inout int64_t, int64_t, int, int, int);"
"uint64_t atomicXor(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicXor(coherent volatile inout int64_t, int64_t);"
"uint64_t atomicXor(coherent volatile inout uint64_t, uint64_t, int, int, int);"
" int64_t atomicXor(coherent volatile inout int64_t, int64_t, int, int, int);"
"uint64_t atomicAdd(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicAdd(coherent volatile inout int64_t, int64_t);"
"uint64_t atomicAdd(coherent volatile inout uint64_t, uint64_t, int, int, int);"
" int64_t atomicAdd(coherent volatile inout int64_t, int64_t, int, int, int);"
"float16_t atomicAdd(coherent volatile inout float16_t, float16_t);"
"float16_t atomicAdd(coherent volatile inout float16_t, float16_t, int, int, int);"
" float atomicAdd(coherent volatile inout float, float);"
" float atomicAdd(coherent volatile inout float, float, int, int, int);"
" double atomicAdd(coherent volatile inout double, double);"
" double atomicAdd(coherent volatile inout double, double, int, int, int);"
"uint64_t atomicExchange(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicExchange(coherent volatile inout int64_t, int64_t);"
"uint64_t atomicExchange(coherent volatile inout uint64_t, uint64_t, int, int, int);"
" int64_t atomicExchange(coherent volatile inout int64_t, int64_t, int, int, int);"
"float16_t atomicExchange(coherent volatile inout float16_t, float16_t);"
"float16_t atomicExchange(coherent volatile inout float16_t, float16_t, int, int, int);"
" float atomicExchange(coherent volatile inout float, float);"
" float atomicExchange(coherent volatile inout float, float, int, int, int);"
" double atomicExchange(coherent volatile inout double, double);"
" double atomicExchange(coherent volatile inout double, double, int, int, int);"
"uint64_t atomicCompSwap(coherent volatile inout uint64_t, uint64_t, uint64_t);"
" int64_t atomicCompSwap(coherent volatile inout int64_t, int64_t, int64_t);"
"uint64_t atomicCompSwap(coherent volatile inout uint64_t, uint64_t, uint64_t, int, int, int, int, int);"
" int64_t atomicCompSwap(coherent volatile inout int64_t, int64_t, int64_t, int, int, int, int, int);"
"uint64_t atomicLoad(coherent volatile in uint64_t, int, int, int);"
" int64_t atomicLoad(coherent volatile in int64_t, int, int, int);"
"float16_t atomicLoad(coherent volatile in float16_t, int, int, int);"
" float atomicLoad(coherent volatile in float, int, int, int);"
" double atomicLoad(coherent volatile in double, int, int, int);"
"void atomicStore(coherent volatile out uint64_t, uint64_t, int, int, int);"
"void atomicStore(coherent volatile out int64_t, int64_t, int, int, int);"
"void atomicStore(coherent volatile out float16_t, float16_t, int, int, int);"
"void atomicStore(coherent volatile out float, float, int, int, int);"
"void atomicStore(coherent volatile out double, double, int, int, int);"
"\n");
}
// NV_shader_atomic_fp16_vector
if (profile != EEsProfile && version >= 430) {
commonBuiltins.append(
"f16vec2 atomicAdd(coherent volatile inout f16vec2, f16vec2);"
"f16vec4 atomicAdd(coherent volatile inout f16vec4, f16vec4);"
"f16vec2 atomicMin(coherent volatile inout f16vec2, f16vec2);"
"f16vec4 atomicMin(coherent volatile inout f16vec4, f16vec4);"
"f16vec2 atomicMax(coherent volatile inout f16vec2, f16vec2);"
"f16vec4 atomicMax(coherent volatile inout f16vec4, f16vec4);"
"f16vec2 atomicExchange(coherent volatile inout f16vec2, f16vec2);"
"f16vec4 atomicExchange(coherent volatile inout f16vec4, f16vec4);"
"\n");
}
if ((profile == EEsProfile && version >= 300) ||
(profile != EEsProfile && version >= 150)) { // GL_ARB_shader_bit_encoding
commonBuiltins.append(
"int floatBitsToInt(highp float value);"
"ivec2 floatBitsToInt(highp vec2 value);"
"ivec3 floatBitsToInt(highp vec3 value);"
"ivec4 floatBitsToInt(highp vec4 value);"
"uint floatBitsToUint(highp float value);"
"uvec2 floatBitsToUint(highp vec2 value);"
"uvec3 floatBitsToUint(highp vec3 value);"
"uvec4 floatBitsToUint(highp vec4 value);"
"float intBitsToFloat(highp int value);"
"vec2 intBitsToFloat(highp ivec2 value);"
"vec3 intBitsToFloat(highp ivec3 value);"
"vec4 intBitsToFloat(highp ivec4 value);"
"float uintBitsToFloat(highp uint value);"
"vec2 uintBitsToFloat(highp uvec2 value);"
"vec3 uintBitsToFloat(highp uvec3 value);"
"vec4 uintBitsToFloat(highp uvec4 value);"
"\n");
}
if ((profile != EEsProfile && version >= 400) ||
(profile == EEsProfile && version >= 310)) { // GL_OES_gpu_shader5
commonBuiltins.append(
"float fma(float, float, float );"
"vec2 fma(vec2, vec2, vec2 );"
"vec3 fma(vec3, vec3, vec3 );"
"vec4 fma(vec4, vec4, vec4 );"
"\n");
}
if (profile != EEsProfile && version >= 150) { // ARB_gpu_shader_fp64
commonBuiltins.append(
"double fma(double, double, double);"
"dvec2 fma(dvec2, dvec2, dvec2 );"
"dvec3 fma(dvec3, dvec3, dvec3 );"
"dvec4 fma(dvec4, dvec4, dvec4 );"
"\n");
}
if (profile == EEsProfile && version >= 310) { // ARB_gpu_shader_fp64
commonBuiltins.append(
"float64_t fma(float64_t, float64_t, float64_t);"
"f64vec2 fma(f64vec2, f64vec2, f64vec2 );"
"f64vec3 fma(f64vec3, f64vec3, f64vec3 );"
"f64vec4 fma(f64vec4, f64vec4, f64vec4 );"
"\n");
}
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 400)) {
commonBuiltins.append(
"float frexp(highp float, out highp int);"
"vec2 frexp(highp vec2, out highp ivec2);"
"vec3 frexp(highp vec3, out highp ivec3);"
"vec4 frexp(highp vec4, out highp ivec4);"
"float ldexp(highp float, highp int);"
"vec2 ldexp(highp vec2, highp ivec2);"
"vec3 ldexp(highp vec3, highp ivec3);"
"vec4 ldexp(highp vec4, highp ivec4);"
"\n");
}
if (profile != EEsProfile && version >= 150) { // ARB_gpu_shader_fp64
commonBuiltins.append(
"double frexp(double, out int);"
"dvec2 frexp( dvec2, out ivec2);"
"dvec3 frexp( dvec3, out ivec3);"
"dvec4 frexp( dvec4, out ivec4);"
"double ldexp(double, int);"
"dvec2 ldexp( dvec2, ivec2);"
"dvec3 ldexp( dvec3, ivec3);"
"dvec4 ldexp( dvec4, ivec4);"
"double packDouble2x32(uvec2);"
"uvec2 unpackDouble2x32(double);"
"\n");
}
if (profile == EEsProfile && version >= 310) { // ARB_gpu_shader_fp64
commonBuiltins.append(
"float64_t frexp(float64_t, out int);"
"f64vec2 frexp( f64vec2, out ivec2);"
"f64vec3 frexp( f64vec3, out ivec3);"
"f64vec4 frexp( f64vec4, out ivec4);"
"float64_t ldexp(float64_t, int);"
"f64vec2 ldexp( f64vec2, ivec2);"
"f64vec3 ldexp( f64vec3, ivec3);"
"f64vec4 ldexp( f64vec4, ivec4);"
"\n");
}
if ((profile == EEsProfile && version >= 300) ||
(profile != EEsProfile && version >= 150)) {
commonBuiltins.append(
"highp uint packUnorm2x16(vec2);"
"vec2 unpackUnorm2x16(highp uint);"
"\n");
}
if ((profile == EEsProfile && version >= 300) ||
(profile != EEsProfile && version >= 150)) {
commonBuiltins.append(
"highp uint packSnorm2x16(vec2);"
" vec2 unpackSnorm2x16(highp uint);"
"highp uint packHalf2x16(vec2);"
"\n");
}
if (profile == EEsProfile && version >= 300) {
commonBuiltins.append(
"mediump vec2 unpackHalf2x16(highp uint);"
"\n");
} else if (profile != EEsProfile && version >= 150) {
commonBuiltins.append(
" vec2 unpackHalf2x16(highp uint);"
"\n");
}
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 150)) {
commonBuiltins.append(
"highp uint packSnorm4x8(vec4);"
"highp uint packUnorm4x8(vec4);"
"\n");
}
if (profile == EEsProfile && version >= 310) {
commonBuiltins.append(
"mediump vec4 unpackSnorm4x8(highp uint);"
"mediump vec4 unpackUnorm4x8(highp uint);"
"\n");
} else if (profile != EEsProfile && version >= 150) {
commonBuiltins.append(
"vec4 unpackSnorm4x8(highp uint);"
"vec4 unpackUnorm4x8(highp uint);"
"\n");
}
//
// Matrix Functions.
//
commonBuiltins.append(
"mat2 matrixCompMult(mat2 x, mat2 y);"
"mat3 matrixCompMult(mat3 x, mat3 y);"
"mat4 matrixCompMult(mat4 x, mat4 y);"
"\n");
// 120 is correct for both ES and desktop
if (version >= 120) {
commonBuiltins.append(
"mat2 outerProduct(vec2 c, vec2 r);"
"mat3 outerProduct(vec3 c, vec3 r);"
"mat4 outerProduct(vec4 c, vec4 r);"
"mat2x3 outerProduct(vec3 c, vec2 r);"
"mat3x2 outerProduct(vec2 c, vec3 r);"
"mat2x4 outerProduct(vec4 c, vec2 r);"
"mat4x2 outerProduct(vec2 c, vec4 r);"
"mat3x4 outerProduct(vec4 c, vec3 r);"
"mat4x3 outerProduct(vec3 c, vec4 r);"
"mat2 transpose(mat2 m);"
"mat3 transpose(mat3 m);"
"mat4 transpose(mat4 m);"
"mat2x3 transpose(mat3x2 m);"
"mat3x2 transpose(mat2x3 m);"
"mat2x4 transpose(mat4x2 m);"
"mat4x2 transpose(mat2x4 m);"
"mat3x4 transpose(mat4x3 m);"
"mat4x3 transpose(mat3x4 m);"
"mat2x3 matrixCompMult(mat2x3, mat2x3);"
"mat2x4 matrixCompMult(mat2x4, mat2x4);"
"mat3x2 matrixCompMult(mat3x2, mat3x2);"
"mat3x4 matrixCompMult(mat3x4, mat3x4);"
"mat4x2 matrixCompMult(mat4x2, mat4x2);"
"mat4x3 matrixCompMult(mat4x3, mat4x3);"
"\n");
// 150 is correct for both ES and desktop
if (version >= 150) {
commonBuiltins.append(
"float determinant(mat2 m);"
"float determinant(mat3 m);"
"float determinant(mat4 m);"
"mat2 inverse(mat2 m);"
"mat3 inverse(mat3 m);"
"mat4 inverse(mat4 m);"
"\n");
}
}
//
// Original-style texture functions existing in all stages.
// (Per-stage functions below.)
//
if ((profile == EEsProfile && version == 100) ||
profile == ECompatibilityProfile ||
(profile == ECoreProfile && version < 420) ||
profile == ENoProfile) {
if (spvVersion.spv == 0) {
commonBuiltins.append(
"vec4 texture2D(sampler2D, vec2);"
"vec4 texture2DProj(sampler2D, vec3);"
"vec4 texture2DProj(sampler2D, vec4);"
"vec4 texture3D(sampler3D, vec3);" // OES_texture_3D, but caught by keyword check
"vec4 texture3DProj(sampler3D, vec4);" // OES_texture_3D, but caught by keyword check
"vec4 textureCube(samplerCube, vec3);"
"\n");
}
}
if ( profile == ECompatibilityProfile ||
(profile == ECoreProfile && version < 420) ||
profile == ENoProfile) {
if (spvVersion.spv == 0) {
commonBuiltins.append(
"vec4 texture1D(sampler1D, float);"
"vec4 texture1DProj(sampler1D, vec2);"
"vec4 texture1DProj(sampler1D, vec4);"
"vec4 shadow1D(sampler1DShadow, vec3);"
"vec4 shadow2D(sampler2DShadow, vec3);"
"vec4 shadow1DProj(sampler1DShadow, vec4);"
"vec4 shadow2DProj(sampler2DShadow, vec4);"
"vec4 texture2DRect(sampler2DRect, vec2);" // GL_ARB_texture_rectangle, caught by keyword check
"vec4 texture2DRectProj(sampler2DRect, vec3);" // GL_ARB_texture_rectangle, caught by keyword check
"vec4 texture2DRectProj(sampler2DRect, vec4);" // GL_ARB_texture_rectangle, caught by keyword check
"vec4 shadow2DRect(sampler2DRectShadow, vec3);" // GL_ARB_texture_rectangle, caught by keyword check
"vec4 shadow2DRectProj(sampler2DRectShadow, vec4);" // GL_ARB_texture_rectangle, caught by keyword check
"vec4 texture1DArray(sampler1DArray, vec2);" // GL_EXT_texture_array
"vec4 texture2DArray(sampler2DArray, vec3);" // GL_EXT_texture_array
"vec4 shadow1DArray(sampler1DArrayShadow, vec3);" // GL_EXT_texture_array
"vec4 shadow2DArray(sampler2DArrayShadow, vec4);" // GL_EXT_texture_array
"vec4 texture1DArray(sampler1DArray, vec2, float);" // GL_EXT_texture_array
"vec4 texture2DArray(sampler2DArray, vec3, float);" // GL_EXT_texture_array
"vec4 shadow1DArray(sampler1DArrayShadow, vec3, float);" // GL_EXT_texture_array
"vec4 texture1DArrayLod(sampler1DArray, vec2, float);" // GL_EXT_texture_array
"vec4 texture2DArrayLod(sampler2DArray, vec3, float);" // GL_EXT_texture_array
"vec4 shadow1DArrayLod(sampler1DArrayShadow, vec3, float);" // GL_EXT_texture_array
"\n");
}
}
if (profile == EEsProfile) {
if (spvVersion.spv == 0) {
if (version < 300) {
commonBuiltins.append(
"vec4 texture2D(samplerExternalOES, vec2 coord);" // GL_OES_EGL_image_external
"vec4 texture2DProj(samplerExternalOES, vec3);" // GL_OES_EGL_image_external
"vec4 texture2DProj(samplerExternalOES, vec4);" // GL_OES_EGL_image_external
"\n");
} else {
commonBuiltins.append(
"highp ivec2 textureSize(samplerExternalOES, int lod);" // GL_OES_EGL_image_external_essl3
"vec4 texture(samplerExternalOES, vec2);" // GL_OES_EGL_image_external_essl3
"vec4 texture(samplerExternalOES, vec2, float bias);" // GL_OES_EGL_image_external_essl3
"vec4 textureProj(samplerExternalOES, vec3);" // GL_OES_EGL_image_external_essl3
"vec4 textureProj(samplerExternalOES, vec3, float bias);" // GL_OES_EGL_image_external_essl3
"vec4 textureProj(samplerExternalOES, vec4);" // GL_OES_EGL_image_external_essl3
"vec4 textureProj(samplerExternalOES, vec4, float bias);" // GL_OES_EGL_image_external_essl3
"vec4 texelFetch(samplerExternalOES, ivec2, int lod);" // GL_OES_EGL_image_external_essl3
"\n");
}
commonBuiltins.append(
"highp ivec2 textureSize(__samplerExternal2DY2YEXT, int lod);" // GL_EXT_YUV_target
"vec4 texture(__samplerExternal2DY2YEXT, vec2);" // GL_EXT_YUV_target
"vec4 texture(__samplerExternal2DY2YEXT, vec2, float bias);" // GL_EXT_YUV_target
"vec4 textureProj(__samplerExternal2DY2YEXT, vec3);" // GL_EXT_YUV_target
"vec4 textureProj(__samplerExternal2DY2YEXT, vec3, float bias);" // GL_EXT_YUV_target
"vec4 textureProj(__samplerExternal2DY2YEXT, vec4);" // GL_EXT_YUV_target
"vec4 textureProj(__samplerExternal2DY2YEXT, vec4, float bias);" // GL_EXT_YUV_target
"vec4 texelFetch(__samplerExternal2DY2YEXT sampler, ivec2, int lod);" // GL_EXT_YUV_target
"\n");
commonBuiltins.append(
"vec4 texture2DGradEXT(sampler2D, vec2, vec2, vec2);" // GL_EXT_shader_texture_lod
"vec4 texture2DProjGradEXT(sampler2D, vec3, vec2, vec2);" // GL_EXT_shader_texture_lod
"vec4 texture2DProjGradEXT(sampler2D, vec4, vec2, vec2);" // GL_EXT_shader_texture_lod
"vec4 textureCubeGradEXT(samplerCube, vec3, vec3, vec3);" // GL_EXT_shader_texture_lod
"float shadow2DEXT(sampler2DShadow, vec3);" // GL_EXT_shadow_samplers
"float shadow2DProjEXT(sampler2DShadow, vec4);" // GL_EXT_shadow_samplers
"\n");
}
}
//
// Noise functions.
//
if (spvVersion.spv == 0 && profile != EEsProfile) {
commonBuiltins.append(
"float noise1(float x);"
"float noise1(vec2 x);"
"float noise1(vec3 x);"
"float noise1(vec4 x);"
"vec2 noise2(float x);"
"vec2 noise2(vec2 x);"
"vec2 noise2(vec3 x);"
"vec2 noise2(vec4 x);"
"vec3 noise3(float x);"
"vec3 noise3(vec2 x);"
"vec3 noise3(vec3 x);"
"vec3 noise3(vec4 x);"
"vec4 noise4(float x);"
"vec4 noise4(vec2 x);"
"vec4 noise4(vec3 x);"
"vec4 noise4(vec4 x);"
"\n");
}
if (spvVersion.vulkan == 0) {
//
// Atomic counter functions.
//
if ((profile != EEsProfile && version >= 300) ||
(profile == EEsProfile && version >= 310)) {
commonBuiltins.append(
"uint atomicCounterIncrement(atomic_uint);"
"uint atomicCounterDecrement(atomic_uint);"
"uint atomicCounter(atomic_uint);"
"\n");
}
if (profile != EEsProfile && version == 450) {
commonBuiltins.append(
"uint atomicCounterAddARB(atomic_uint, uint);"
"uint atomicCounterSubtractARB(atomic_uint, uint);"
"uint atomicCounterMinARB(atomic_uint, uint);"
"uint atomicCounterMaxARB(atomic_uint, uint);"
"uint atomicCounterAndARB(atomic_uint, uint);"
"uint atomicCounterOrARB(atomic_uint, uint);"
"uint atomicCounterXorARB(atomic_uint, uint);"
"uint atomicCounterExchangeARB(atomic_uint, uint);"
"uint atomicCounterCompSwapARB(atomic_uint, uint, uint);"
"\n");
}
if (profile != EEsProfile && version >= 460) {
commonBuiltins.append(
"uint atomicCounterAdd(atomic_uint, uint);"
"uint atomicCounterSubtract(atomic_uint, uint);"
"uint atomicCounterMin(atomic_uint, uint);"
"uint atomicCounterMax(atomic_uint, uint);"
"uint atomicCounterAnd(atomic_uint, uint);"
"uint atomicCounterOr(atomic_uint, uint);"
"uint atomicCounterXor(atomic_uint, uint);"
"uint atomicCounterExchange(atomic_uint, uint);"
"uint atomicCounterCompSwap(atomic_uint, uint, uint);"
"\n");
}
}
else if (spvVersion.vulkanRelaxed) {
//
// Atomic counter functions act as aliases to normal atomic functions.
// replace definitions to take 'volatile coherent uint' instead of 'atomic_uint'
// and map to equivalent non-counter atomic op
//
if ((profile != EEsProfile && version >= 300) ||
(profile == EEsProfile && version >= 310)) {
commonBuiltins.append(
"uint atomicCounterIncrement(volatile coherent uint);"
"uint atomicCounterDecrement(volatile coherent uint);"
"uint atomicCounter(volatile coherent uint);"
"\n");
}
if (profile != EEsProfile && version >= 460) {
commonBuiltins.append(
"uint atomicCounterAdd(volatile coherent uint, uint);"
"uint atomicCounterSubtract(volatile coherent uint, uint);"
"uint atomicCounterMin(volatile coherent uint, uint);"
"uint atomicCounterMax(volatile coherent uint, uint);"
"uint atomicCounterAnd(volatile coherent uint, uint);"
"uint atomicCounterOr(volatile coherent uint, uint);"
"uint atomicCounterXor(volatile coherent uint, uint);"
"uint atomicCounterExchange(volatile coherent uint, uint);"
"uint atomicCounterCompSwap(volatile coherent uint, uint, uint);"
"\n");
}
}
// Bitfield
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 400)) {
commonBuiltins.append(
" int bitfieldExtract( int, int, int);"
"ivec2 bitfieldExtract(ivec2, int, int);"
"ivec3 bitfieldExtract(ivec3, int, int);"
"ivec4 bitfieldExtract(ivec4, int, int);"
" uint bitfieldExtract( uint, int, int);"
"uvec2 bitfieldExtract(uvec2, int, int);"
"uvec3 bitfieldExtract(uvec3, int, int);"
"uvec4 bitfieldExtract(uvec4, int, int);"
" int bitfieldInsert( int base, int, int, int);"
"ivec2 bitfieldInsert(ivec2 base, ivec2, int, int);"
"ivec3 bitfieldInsert(ivec3 base, ivec3, int, int);"
"ivec4 bitfieldInsert(ivec4 base, ivec4, int, int);"
" uint bitfieldInsert( uint base, uint, int, int);"
"uvec2 bitfieldInsert(uvec2 base, uvec2, int, int);"
"uvec3 bitfieldInsert(uvec3 base, uvec3, int, int);"
"uvec4 bitfieldInsert(uvec4 base, uvec4, int, int);"
"\n");
}
if (profile != EEsProfile && version >= 400) {
commonBuiltins.append(
" int findLSB( int);"
"ivec2 findLSB(ivec2);"
"ivec3 findLSB(ivec3);"
"ivec4 findLSB(ivec4);"
" int findLSB( uint);"
"ivec2 findLSB(uvec2);"
"ivec3 findLSB(uvec3);"
"ivec4 findLSB(uvec4);"
"\n");
} else if (profile == EEsProfile && version >= 310) {
commonBuiltins.append(
"lowp int findLSB( int);"
"lowp ivec2 findLSB(ivec2);"
"lowp ivec3 findLSB(ivec3);"
"lowp ivec4 findLSB(ivec4);"
"lowp int findLSB( uint);"
"lowp ivec2 findLSB(uvec2);"
"lowp ivec3 findLSB(uvec3);"
"lowp ivec4 findLSB(uvec4);"
"\n");
}
if (profile != EEsProfile && version >= 400) {
commonBuiltins.append(
" int bitCount( int);"
"ivec2 bitCount(ivec2);"
"ivec3 bitCount(ivec3);"
"ivec4 bitCount(ivec4);"
" int bitCount( uint);"
"ivec2 bitCount(uvec2);"
"ivec3 bitCount(uvec3);"
"ivec4 bitCount(uvec4);"
" int findMSB(highp int);"
"ivec2 findMSB(highp ivec2);"
"ivec3 findMSB(highp ivec3);"
"ivec4 findMSB(highp ivec4);"
" int findMSB(highp uint);"
"ivec2 findMSB(highp uvec2);"
"ivec3 findMSB(highp uvec3);"
"ivec4 findMSB(highp uvec4);"
"\n");
}
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 400)) {
commonBuiltins.append(
" uint uaddCarry(highp uint, highp uint, out lowp uint carry);"
"uvec2 uaddCarry(highp uvec2, highp uvec2, out lowp uvec2 carry);"
"uvec3 uaddCarry(highp uvec3, highp uvec3, out lowp uvec3 carry);"
"uvec4 uaddCarry(highp uvec4, highp uvec4, out lowp uvec4 carry);"
" uint usubBorrow(highp uint, highp uint, out lowp uint borrow);"
"uvec2 usubBorrow(highp uvec2, highp uvec2, out lowp uvec2 borrow);"
"uvec3 usubBorrow(highp uvec3, highp uvec3, out lowp uvec3 borrow);"
"uvec4 usubBorrow(highp uvec4, highp uvec4, out lowp uvec4 borrow);"
"void umulExtended(highp uint, highp uint, out highp uint, out highp uint lsb);"
"void umulExtended(highp uvec2, highp uvec2, out highp uvec2, out highp uvec2 lsb);"
"void umulExtended(highp uvec3, highp uvec3, out highp uvec3, out highp uvec3 lsb);"
"void umulExtended(highp uvec4, highp uvec4, out highp uvec4, out highp uvec4 lsb);"
"void imulExtended(highp int, highp int, out highp int, out highp int lsb);"
"void imulExtended(highp ivec2, highp ivec2, out highp ivec2, out highp ivec2 lsb);"
"void imulExtended(highp ivec3, highp ivec3, out highp ivec3, out highp ivec3 lsb);"
"void imulExtended(highp ivec4, highp ivec4, out highp ivec4, out highp ivec4 lsb);"
" int bitfieldReverse(highp int);"
"ivec2 bitfieldReverse(highp ivec2);"
"ivec3 bitfieldReverse(highp ivec3);"
"ivec4 bitfieldReverse(highp ivec4);"
" uint bitfieldReverse(highp uint);"
"uvec2 bitfieldReverse(highp uvec2);"
"uvec3 bitfieldReverse(highp uvec3);"
"uvec4 bitfieldReverse(highp uvec4);"
"\n");
}
if (profile == EEsProfile && version >= 310) {
commonBuiltins.append(
"lowp int bitCount( int);"
"lowp ivec2 bitCount(ivec2);"
"lowp ivec3 bitCount(ivec3);"
"lowp ivec4 bitCount(ivec4);"
"lowp int bitCount( uint);"
"lowp ivec2 bitCount(uvec2);"
"lowp ivec3 bitCount(uvec3);"
"lowp ivec4 bitCount(uvec4);"
"lowp int findMSB(highp int);"
"lowp ivec2 findMSB(highp ivec2);"
"lowp ivec3 findMSB(highp ivec3);"
"lowp ivec4 findMSB(highp ivec4);"
"lowp int findMSB(highp uint);"
"lowp ivec2 findMSB(highp uvec2);"
"lowp ivec3 findMSB(highp uvec3);"
"lowp ivec4 findMSB(highp uvec4);"
"\n");
}
// GL_ARB_shader_ballot
if (profile != EEsProfile && version >= 450) {
commonBuiltins.append(
"uint64_t ballotARB(bool);"
"float readInvocationARB(float, uint);"
"vec2 readInvocationARB(vec2, uint);"
"vec3 readInvocationARB(vec3, uint);"
"vec4 readInvocationARB(vec4, uint);"
"int readInvocationARB(int, uint);"
"ivec2 readInvocationARB(ivec2, uint);"
"ivec3 readInvocationARB(ivec3, uint);"
"ivec4 readInvocationARB(ivec4, uint);"
"uint readInvocationARB(uint, uint);"
"uvec2 readInvocationARB(uvec2, uint);"
"uvec3 readInvocationARB(uvec3, uint);"
"uvec4 readInvocationARB(uvec4, uint);"
"float readFirstInvocationARB(float);"
"vec2 readFirstInvocationARB(vec2);"
"vec3 readFirstInvocationARB(vec3);"
"vec4 readFirstInvocationARB(vec4);"
"int readFirstInvocationARB(int);"
"ivec2 readFirstInvocationARB(ivec2);"
"ivec3 readFirstInvocationARB(ivec3);"
"ivec4 readFirstInvocationARB(ivec4);"
"uint readFirstInvocationARB(uint);"
"uvec2 readFirstInvocationARB(uvec2);"
"uvec3 readFirstInvocationARB(uvec3);"
"uvec4 readFirstInvocationARB(uvec4);"
"\n");
}
// GL_ARB_shader_group_vote
if (profile != EEsProfile && version >= 430) {
commonBuiltins.append(
"bool anyInvocationARB(bool);"
"bool allInvocationsARB(bool);"
"bool allInvocationsEqualARB(bool);"
"\n");
}
// GL_KHR_shader_subgroup
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
commonBuiltins.append(
"void subgroupBarrier();"
"void subgroupMemoryBarrier();"
"void subgroupMemoryBarrierBuffer();"
"void subgroupMemoryBarrierImage();"
"bool subgroupElect();"
"bool subgroupAll(bool);\n"
"bool subgroupAny(bool);\n"
"uvec4 subgroupBallot(bool);\n"
"bool subgroupInverseBallot(uvec4);\n"
"bool subgroupBallotBitExtract(uvec4, uint);\n"
"uint subgroupBallotBitCount(uvec4);\n"
"uint subgroupBallotInclusiveBitCount(uvec4);\n"
"uint subgroupBallotExclusiveBitCount(uvec4);\n"
"uint subgroupBallotFindLSB(uvec4);\n"
"uint subgroupBallotFindMSB(uvec4);\n"
);
// Generate all flavors of subgroup ops.
static const char *subgroupOps[] =
{
"bool subgroupAllEqual(%s);\n",
"%s subgroupBroadcast(%s, uint);\n",
"%s subgroupBroadcastFirst(%s);\n",
"%s subgroupShuffle(%s, uint);\n",
"%s subgroupShuffleXor(%s, uint);\n",
"%s subgroupShuffleUp(%s, uint delta);\n",
"%s subgroupShuffleDown(%s, uint delta);\n",
"%s subgroupRotate(%s, uint);\n",
"%s subgroupClusteredRotate(%s, uint, uint);\n",
"%s subgroupAdd(%s);\n",
"%s subgroupMul(%s);\n",
"%s subgroupMin(%s);\n",
"%s subgroupMax(%s);\n",
"%s subgroupAnd(%s);\n",
"%s subgroupOr(%s);\n",
"%s subgroupXor(%s);\n",
"%s subgroupInclusiveAdd(%s);\n",
"%s subgroupInclusiveMul(%s);\n",
"%s subgroupInclusiveMin(%s);\n",
"%s subgroupInclusiveMax(%s);\n",
"%s subgroupInclusiveAnd(%s);\n",
"%s subgroupInclusiveOr(%s);\n",
"%s subgroupInclusiveXor(%s);\n",
"%s subgroupExclusiveAdd(%s);\n",
"%s subgroupExclusiveMul(%s);\n",
"%s subgroupExclusiveMin(%s);\n",
"%s subgroupExclusiveMax(%s);\n",
"%s subgroupExclusiveAnd(%s);\n",
"%s subgroupExclusiveOr(%s);\n",
"%s subgroupExclusiveXor(%s);\n",
"%s subgroupClusteredAdd(%s, uint);\n",
"%s subgroupClusteredMul(%s, uint);\n",
"%s subgroupClusteredMin(%s, uint);\n",
"%s subgroupClusteredMax(%s, uint);\n",
"%s subgroupClusteredAnd(%s, uint);\n",
"%s subgroupClusteredOr(%s, uint);\n",
"%s subgroupClusteredXor(%s, uint);\n",
"%s subgroupQuadBroadcast(%s, uint);\n",
"%s subgroupQuadSwapHorizontal(%s);\n",
"%s subgroupQuadSwapVertical(%s);\n",
"%s subgroupQuadSwapDiagonal(%s);\n",
"uvec4 subgroupPartitionNV(%s);\n",
"%s subgroupPartitionedAddNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedMulNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedMinNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedMaxNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedAndNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedOrNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedXorNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedInclusiveAddNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedInclusiveMulNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedInclusiveMinNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedInclusiveMaxNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedInclusiveAndNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedInclusiveOrNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedInclusiveXorNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedExclusiveAddNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedExclusiveMulNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedExclusiveMinNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedExclusiveMaxNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedExclusiveAndNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedExclusiveOrNV(%s, uvec4 ballot);\n",
"%s subgroupPartitionedExclusiveXorNV(%s, uvec4 ballot);\n",
};
static const char *floatTypes[] = {
"float", "vec2", "vec3", "vec4",
"float16_t", "f16vec2", "f16vec3", "f16vec4",
};
static const char *doubleTypes[] = {
"double", "dvec2", "dvec3", "dvec4",
};
static const char *intTypes[] = {
"int8_t", "i8vec2", "i8vec3", "i8vec4",
"int16_t", "i16vec2", "i16vec3", "i16vec4",
"int", "ivec2", "ivec3", "ivec4",
"int64_t", "i64vec2", "i64vec3", "i64vec4",
"uint8_t", "u8vec2", "u8vec3", "u8vec4",
"uint16_t", "u16vec2", "u16vec3", "u16vec4",
"uint", "uvec2", "uvec3", "uvec4",
"uint64_t", "u64vec2", "u64vec3", "u64vec4",
};
static const char *boolTypes[] = {
"bool", "bvec2", "bvec3", "bvec4",
};
for (size_t i = 0; i < sizeof(subgroupOps)/sizeof(subgroupOps[0]); ++i) {
const char *op = subgroupOps[i];
// Logical operations don't support float
bool logicalOp = strstr(op, "Or") || strstr(op, "And") ||
(strstr(op, "Xor") && !strstr(op, "ShuffleXor"));
// Math operations don't support bool
bool mathOp = strstr(op, "Add") || strstr(op, "Mul") || strstr(op, "Min") || strstr(op, "Max");
const int bufSize = 256;
char buf[bufSize];
if (!logicalOp) {
for (size_t j = 0; j < sizeof(floatTypes)/sizeof(floatTypes[0]); ++j) {
snprintf(buf, bufSize, op, floatTypes[j], floatTypes[j]);
commonBuiltins.append(buf);
}
if (profile != EEsProfile && version >= 400) {
for (size_t j = 0; j < sizeof(doubleTypes)/sizeof(doubleTypes[0]); ++j) {
snprintf(buf, bufSize, op, doubleTypes[j], doubleTypes[j]);
commonBuiltins.append(buf);
}
}
}
if (!mathOp) {
for (size_t j = 0; j < sizeof(boolTypes)/sizeof(boolTypes[0]); ++j) {
snprintf(buf, bufSize, op, boolTypes[j], boolTypes[j]);
commonBuiltins.append(buf);
}
}
for (size_t j = 0; j < sizeof(intTypes)/sizeof(intTypes[0]); ++j) {
snprintf(buf, bufSize, op, intTypes[j], intTypes[j]);
commonBuiltins.append(buf);
}
}
stageBuiltins[EShLangCompute].append(
"void subgroupMemoryBarrierShared();"
"\n"
);
stageBuiltins[EShLangMesh].append(
"void subgroupMemoryBarrierShared();"
"\n"
);
stageBuiltins[EShLangTask].append(
"void subgroupMemoryBarrierShared();"
"\n"
);
}
// GL_EXT_shader_quad_control
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
commonBuiltins.append(
"bool subgroupQuadAll(bool);\n"
"bool subgroupQuadAny(bool);\n"
);
}
if (profile != EEsProfile && version >= 460) {
commonBuiltins.append(
"bool anyInvocation(bool);"
"bool allInvocations(bool);"
"bool allInvocationsEqual(bool);"
"\n");
}
// GL_AMD_shader_ballot
if (profile != EEsProfile && version >= 450) {
commonBuiltins.append(
"float minInvocationsAMD(float);"
"vec2 minInvocationsAMD(vec2);"
"vec3 minInvocationsAMD(vec3);"
"vec4 minInvocationsAMD(vec4);"
"int minInvocationsAMD(int);"
"ivec2 minInvocationsAMD(ivec2);"
"ivec3 minInvocationsAMD(ivec3);"
"ivec4 minInvocationsAMD(ivec4);"
"uint minInvocationsAMD(uint);"
"uvec2 minInvocationsAMD(uvec2);"
"uvec3 minInvocationsAMD(uvec3);"
"uvec4 minInvocationsAMD(uvec4);"
"double minInvocationsAMD(double);"
"dvec2 minInvocationsAMD(dvec2);"
"dvec3 minInvocationsAMD(dvec3);"
"dvec4 minInvocationsAMD(dvec4);"
"int64_t minInvocationsAMD(int64_t);"
"i64vec2 minInvocationsAMD(i64vec2);"
"i64vec3 minInvocationsAMD(i64vec3);"
"i64vec4 minInvocationsAMD(i64vec4);"
"uint64_t minInvocationsAMD(uint64_t);"
"u64vec2 minInvocationsAMD(u64vec2);"
"u64vec3 minInvocationsAMD(u64vec3);"
"u64vec4 minInvocationsAMD(u64vec4);"
"float16_t minInvocationsAMD(float16_t);"
"f16vec2 minInvocationsAMD(f16vec2);"
"f16vec3 minInvocationsAMD(f16vec3);"
"f16vec4 minInvocationsAMD(f16vec4);"
"int16_t minInvocationsAMD(int16_t);"
"i16vec2 minInvocationsAMD(i16vec2);"
"i16vec3 minInvocationsAMD(i16vec3);"
"i16vec4 minInvocationsAMD(i16vec4);"
"uint16_t minInvocationsAMD(uint16_t);"
"u16vec2 minInvocationsAMD(u16vec2);"
"u16vec3 minInvocationsAMD(u16vec3);"
"u16vec4 minInvocationsAMD(u16vec4);"
"float minInvocationsInclusiveScanAMD(float);"
"vec2 minInvocationsInclusiveScanAMD(vec2);"
"vec3 minInvocationsInclusiveScanAMD(vec3);"
"vec4 minInvocationsInclusiveScanAMD(vec4);"
"int minInvocationsInclusiveScanAMD(int);"
"ivec2 minInvocationsInclusiveScanAMD(ivec2);"
"ivec3 minInvocationsInclusiveScanAMD(ivec3);"
"ivec4 minInvocationsInclusiveScanAMD(ivec4);"
"uint minInvocationsInclusiveScanAMD(uint);"
"uvec2 minInvocationsInclusiveScanAMD(uvec2);"
"uvec3 minInvocationsInclusiveScanAMD(uvec3);"
"uvec4 minInvocationsInclusiveScanAMD(uvec4);"
"double minInvocationsInclusiveScanAMD(double);"
"dvec2 minInvocationsInclusiveScanAMD(dvec2);"
"dvec3 minInvocationsInclusiveScanAMD(dvec3);"
"dvec4 minInvocationsInclusiveScanAMD(dvec4);"
"int64_t minInvocationsInclusiveScanAMD(int64_t);"
"i64vec2 minInvocationsInclusiveScanAMD(i64vec2);"
"i64vec3 minInvocationsInclusiveScanAMD(i64vec3);"
"i64vec4 minInvocationsInclusiveScanAMD(i64vec4);"
"uint64_t minInvocationsInclusiveScanAMD(uint64_t);"
"u64vec2 minInvocationsInclusiveScanAMD(u64vec2);"
"u64vec3 minInvocationsInclusiveScanAMD(u64vec3);"
"u64vec4 minInvocationsInclusiveScanAMD(u64vec4);"
"float16_t minInvocationsInclusiveScanAMD(float16_t);"
"f16vec2 minInvocationsInclusiveScanAMD(f16vec2);"
"f16vec3 minInvocationsInclusiveScanAMD(f16vec3);"
"f16vec4 minInvocationsInclusiveScanAMD(f16vec4);"
"int16_t minInvocationsInclusiveScanAMD(int16_t);"
"i16vec2 minInvocationsInclusiveScanAMD(i16vec2);"
"i16vec3 minInvocationsInclusiveScanAMD(i16vec3);"
"i16vec4 minInvocationsInclusiveScanAMD(i16vec4);"
"uint16_t minInvocationsInclusiveScanAMD(uint16_t);"
"u16vec2 minInvocationsInclusiveScanAMD(u16vec2);"
"u16vec3 minInvocationsInclusiveScanAMD(u16vec3);"
"u16vec4 minInvocationsInclusiveScanAMD(u16vec4);"
"float minInvocationsExclusiveScanAMD(float);"
"vec2 minInvocationsExclusiveScanAMD(vec2);"
"vec3 minInvocationsExclusiveScanAMD(vec3);"
"vec4 minInvocationsExclusiveScanAMD(vec4);"
"int minInvocationsExclusiveScanAMD(int);"
"ivec2 minInvocationsExclusiveScanAMD(ivec2);"
"ivec3 minInvocationsExclusiveScanAMD(ivec3);"
"ivec4 minInvocationsExclusiveScanAMD(ivec4);"
"uint minInvocationsExclusiveScanAMD(uint);"
"uvec2 minInvocationsExclusiveScanAMD(uvec2);"
"uvec3 minInvocationsExclusiveScanAMD(uvec3);"
"uvec4 minInvocationsExclusiveScanAMD(uvec4);"
"double minInvocationsExclusiveScanAMD(double);"
"dvec2 minInvocationsExclusiveScanAMD(dvec2);"
"dvec3 minInvocationsExclusiveScanAMD(dvec3);"
"dvec4 minInvocationsExclusiveScanAMD(dvec4);"
"int64_t minInvocationsExclusiveScanAMD(int64_t);"
"i64vec2 minInvocationsExclusiveScanAMD(i64vec2);"
"i64vec3 minInvocationsExclusiveScanAMD(i64vec3);"
"i64vec4 minInvocationsExclusiveScanAMD(i64vec4);"
"uint64_t minInvocationsExclusiveScanAMD(uint64_t);"
"u64vec2 minInvocationsExclusiveScanAMD(u64vec2);"
"u64vec3 minInvocationsExclusiveScanAMD(u64vec3);"
"u64vec4 minInvocationsExclusiveScanAMD(u64vec4);"
"float16_t minInvocationsExclusiveScanAMD(float16_t);"
"f16vec2 minInvocationsExclusiveScanAMD(f16vec2);"
"f16vec3 minInvocationsExclusiveScanAMD(f16vec3);"
"f16vec4 minInvocationsExclusiveScanAMD(f16vec4);"
"int16_t minInvocationsExclusiveScanAMD(int16_t);"
"i16vec2 minInvocationsExclusiveScanAMD(i16vec2);"
"i16vec3 minInvocationsExclusiveScanAMD(i16vec3);"
"i16vec4 minInvocationsExclusiveScanAMD(i16vec4);"
"uint16_t minInvocationsExclusiveScanAMD(uint16_t);"
"u16vec2 minInvocationsExclusiveScanAMD(u16vec2);"
"u16vec3 minInvocationsExclusiveScanAMD(u16vec3);"
"u16vec4 minInvocationsExclusiveScanAMD(u16vec4);"
"float maxInvocationsAMD(float);"
"vec2 maxInvocationsAMD(vec2);"
"vec3 maxInvocationsAMD(vec3);"
"vec4 maxInvocationsAMD(vec4);"
"int maxInvocationsAMD(int);"
"ivec2 maxInvocationsAMD(ivec2);"
"ivec3 maxInvocationsAMD(ivec3);"
"ivec4 maxInvocationsAMD(ivec4);"
"uint maxInvocationsAMD(uint);"
"uvec2 maxInvocationsAMD(uvec2);"
"uvec3 maxInvocationsAMD(uvec3);"
"uvec4 maxInvocationsAMD(uvec4);"
"double maxInvocationsAMD(double);"
"dvec2 maxInvocationsAMD(dvec2);"
"dvec3 maxInvocationsAMD(dvec3);"
"dvec4 maxInvocationsAMD(dvec4);"
"int64_t maxInvocationsAMD(int64_t);"
"i64vec2 maxInvocationsAMD(i64vec2);"
"i64vec3 maxInvocationsAMD(i64vec3);"
"i64vec4 maxInvocationsAMD(i64vec4);"
"uint64_t maxInvocationsAMD(uint64_t);"
"u64vec2 maxInvocationsAMD(u64vec2);"
"u64vec3 maxInvocationsAMD(u64vec3);"
"u64vec4 maxInvocationsAMD(u64vec4);"
"float16_t maxInvocationsAMD(float16_t);"
"f16vec2 maxInvocationsAMD(f16vec2);"
"f16vec3 maxInvocationsAMD(f16vec3);"
"f16vec4 maxInvocationsAMD(f16vec4);"
"int16_t maxInvocationsAMD(int16_t);"
"i16vec2 maxInvocationsAMD(i16vec2);"
"i16vec3 maxInvocationsAMD(i16vec3);"
"i16vec4 maxInvocationsAMD(i16vec4);"
"uint16_t maxInvocationsAMD(uint16_t);"
"u16vec2 maxInvocationsAMD(u16vec2);"
"u16vec3 maxInvocationsAMD(u16vec3);"
"u16vec4 maxInvocationsAMD(u16vec4);"
"float maxInvocationsInclusiveScanAMD(float);"
"vec2 maxInvocationsInclusiveScanAMD(vec2);"
"vec3 maxInvocationsInclusiveScanAMD(vec3);"
"vec4 maxInvocationsInclusiveScanAMD(vec4);"
"int maxInvocationsInclusiveScanAMD(int);"
"ivec2 maxInvocationsInclusiveScanAMD(ivec2);"
"ivec3 maxInvocationsInclusiveScanAMD(ivec3);"
"ivec4 maxInvocationsInclusiveScanAMD(ivec4);"
"uint maxInvocationsInclusiveScanAMD(uint);"
"uvec2 maxInvocationsInclusiveScanAMD(uvec2);"
"uvec3 maxInvocationsInclusiveScanAMD(uvec3);"
"uvec4 maxInvocationsInclusiveScanAMD(uvec4);"
"double maxInvocationsInclusiveScanAMD(double);"
"dvec2 maxInvocationsInclusiveScanAMD(dvec2);"
"dvec3 maxInvocationsInclusiveScanAMD(dvec3);"
"dvec4 maxInvocationsInclusiveScanAMD(dvec4);"
"int64_t maxInvocationsInclusiveScanAMD(int64_t);"
"i64vec2 maxInvocationsInclusiveScanAMD(i64vec2);"
"i64vec3 maxInvocationsInclusiveScanAMD(i64vec3);"
"i64vec4 maxInvocationsInclusiveScanAMD(i64vec4);"
"uint64_t maxInvocationsInclusiveScanAMD(uint64_t);"
"u64vec2 maxInvocationsInclusiveScanAMD(u64vec2);"
"u64vec3 maxInvocationsInclusiveScanAMD(u64vec3);"
"u64vec4 maxInvocationsInclusiveScanAMD(u64vec4);"
"float16_t maxInvocationsInclusiveScanAMD(float16_t);"
"f16vec2 maxInvocationsInclusiveScanAMD(f16vec2);"
"f16vec3 maxInvocationsInclusiveScanAMD(f16vec3);"
"f16vec4 maxInvocationsInclusiveScanAMD(f16vec4);"
"int16_t maxInvocationsInclusiveScanAMD(int16_t);"
"i16vec2 maxInvocationsInclusiveScanAMD(i16vec2);"
"i16vec3 maxInvocationsInclusiveScanAMD(i16vec3);"
"i16vec4 maxInvocationsInclusiveScanAMD(i16vec4);"
"uint16_t maxInvocationsInclusiveScanAMD(uint16_t);"
"u16vec2 maxInvocationsInclusiveScanAMD(u16vec2);"
"u16vec3 maxInvocationsInclusiveScanAMD(u16vec3);"
"u16vec4 maxInvocationsInclusiveScanAMD(u16vec4);"
"float maxInvocationsExclusiveScanAMD(float);"
"vec2 maxInvocationsExclusiveScanAMD(vec2);"
"vec3 maxInvocationsExclusiveScanAMD(vec3);"
"vec4 maxInvocationsExclusiveScanAMD(vec4);"
"int maxInvocationsExclusiveScanAMD(int);"
"ivec2 maxInvocationsExclusiveScanAMD(ivec2);"
"ivec3 maxInvocationsExclusiveScanAMD(ivec3);"
"ivec4 maxInvocationsExclusiveScanAMD(ivec4);"
"uint maxInvocationsExclusiveScanAMD(uint);"
"uvec2 maxInvocationsExclusiveScanAMD(uvec2);"
"uvec3 maxInvocationsExclusiveScanAMD(uvec3);"
"uvec4 maxInvocationsExclusiveScanAMD(uvec4);"
"double maxInvocationsExclusiveScanAMD(double);"
"dvec2 maxInvocationsExclusiveScanAMD(dvec2);"
"dvec3 maxInvocationsExclusiveScanAMD(dvec3);"
"dvec4 maxInvocationsExclusiveScanAMD(dvec4);"
"int64_t maxInvocationsExclusiveScanAMD(int64_t);"
"i64vec2 maxInvocationsExclusiveScanAMD(i64vec2);"
"i64vec3 maxInvocationsExclusiveScanAMD(i64vec3);"
"i64vec4 maxInvocationsExclusiveScanAMD(i64vec4);"
"uint64_t maxInvocationsExclusiveScanAMD(uint64_t);"
"u64vec2 maxInvocationsExclusiveScanAMD(u64vec2);"
"u64vec3 maxInvocationsExclusiveScanAMD(u64vec3);"
"u64vec4 maxInvocationsExclusiveScanAMD(u64vec4);"
"float16_t maxInvocationsExclusiveScanAMD(float16_t);"
"f16vec2 maxInvocationsExclusiveScanAMD(f16vec2);"
"f16vec3 maxInvocationsExclusiveScanAMD(f16vec3);"
"f16vec4 maxInvocationsExclusiveScanAMD(f16vec4);"
"int16_t maxInvocationsExclusiveScanAMD(int16_t);"
"i16vec2 maxInvocationsExclusiveScanAMD(i16vec2);"
"i16vec3 maxInvocationsExclusiveScanAMD(i16vec3);"
"i16vec4 maxInvocationsExclusiveScanAMD(i16vec4);"
"uint16_t maxInvocationsExclusiveScanAMD(uint16_t);"
"u16vec2 maxInvocationsExclusiveScanAMD(u16vec2);"
"u16vec3 maxInvocationsExclusiveScanAMD(u16vec3);"
"u16vec4 maxInvocationsExclusiveScanAMD(u16vec4);"
"float addInvocationsAMD(float);"
"vec2 addInvocationsAMD(vec2);"
"vec3 addInvocationsAMD(vec3);"
"vec4 addInvocationsAMD(vec4);"
"int addInvocationsAMD(int);"
"ivec2 addInvocationsAMD(ivec2);"
"ivec3 addInvocationsAMD(ivec3);"
"ivec4 addInvocationsAMD(ivec4);"
"uint addInvocationsAMD(uint);"
"uvec2 addInvocationsAMD(uvec2);"
"uvec3 addInvocationsAMD(uvec3);"
"uvec4 addInvocationsAMD(uvec4);"
"double addInvocationsAMD(double);"
"dvec2 addInvocationsAMD(dvec2);"
"dvec3 addInvocationsAMD(dvec3);"
"dvec4 addInvocationsAMD(dvec4);"
"int64_t addInvocationsAMD(int64_t);"
"i64vec2 addInvocationsAMD(i64vec2);"
"i64vec3 addInvocationsAMD(i64vec3);"
"i64vec4 addInvocationsAMD(i64vec4);"
"uint64_t addInvocationsAMD(uint64_t);"
"u64vec2 addInvocationsAMD(u64vec2);"
"u64vec3 addInvocationsAMD(u64vec3);"
"u64vec4 addInvocationsAMD(u64vec4);"
"float16_t addInvocationsAMD(float16_t);"
"f16vec2 addInvocationsAMD(f16vec2);"
"f16vec3 addInvocationsAMD(f16vec3);"
"f16vec4 addInvocationsAMD(f16vec4);"
"int16_t addInvocationsAMD(int16_t);"
"i16vec2 addInvocationsAMD(i16vec2);"
"i16vec3 addInvocationsAMD(i16vec3);"
"i16vec4 addInvocationsAMD(i16vec4);"
"uint16_t addInvocationsAMD(uint16_t);"
"u16vec2 addInvocationsAMD(u16vec2);"
"u16vec3 addInvocationsAMD(u16vec3);"
"u16vec4 addInvocationsAMD(u16vec4);"
"float addInvocationsInclusiveScanAMD(float);"
"vec2 addInvocationsInclusiveScanAMD(vec2);"
"vec3 addInvocationsInclusiveScanAMD(vec3);"
"vec4 addInvocationsInclusiveScanAMD(vec4);"
"int addInvocationsInclusiveScanAMD(int);"
"ivec2 addInvocationsInclusiveScanAMD(ivec2);"
"ivec3 addInvocationsInclusiveScanAMD(ivec3);"
"ivec4 addInvocationsInclusiveScanAMD(ivec4);"
"uint addInvocationsInclusiveScanAMD(uint);"
"uvec2 addInvocationsInclusiveScanAMD(uvec2);"
"uvec3 addInvocationsInclusiveScanAMD(uvec3);"
"uvec4 addInvocationsInclusiveScanAMD(uvec4);"
"double addInvocationsInclusiveScanAMD(double);"
"dvec2 addInvocationsInclusiveScanAMD(dvec2);"
"dvec3 addInvocationsInclusiveScanAMD(dvec3);"
"dvec4 addInvocationsInclusiveScanAMD(dvec4);"
"int64_t addInvocationsInclusiveScanAMD(int64_t);"
"i64vec2 addInvocationsInclusiveScanAMD(i64vec2);"
"i64vec3 addInvocationsInclusiveScanAMD(i64vec3);"
"i64vec4 addInvocationsInclusiveScanAMD(i64vec4);"
"uint64_t addInvocationsInclusiveScanAMD(uint64_t);"
"u64vec2 addInvocationsInclusiveScanAMD(u64vec2);"
"u64vec3 addInvocationsInclusiveScanAMD(u64vec3);"
"u64vec4 addInvocationsInclusiveScanAMD(u64vec4);"
"float16_t addInvocationsInclusiveScanAMD(float16_t);"
"f16vec2 addInvocationsInclusiveScanAMD(f16vec2);"
"f16vec3 addInvocationsInclusiveScanAMD(f16vec3);"
"f16vec4 addInvocationsInclusiveScanAMD(f16vec4);"
"int16_t addInvocationsInclusiveScanAMD(int16_t);"
"i16vec2 addInvocationsInclusiveScanAMD(i16vec2);"
"i16vec3 addInvocationsInclusiveScanAMD(i16vec3);"
"i16vec4 addInvocationsInclusiveScanAMD(i16vec4);"
"uint16_t addInvocationsInclusiveScanAMD(uint16_t);"
"u16vec2 addInvocationsInclusiveScanAMD(u16vec2);"
"u16vec3 addInvocationsInclusiveScanAMD(u16vec3);"
"u16vec4 addInvocationsInclusiveScanAMD(u16vec4);"
"float addInvocationsExclusiveScanAMD(float);"
"vec2 addInvocationsExclusiveScanAMD(vec2);"
"vec3 addInvocationsExclusiveScanAMD(vec3);"
"vec4 addInvocationsExclusiveScanAMD(vec4);"
"int addInvocationsExclusiveScanAMD(int);"
"ivec2 addInvocationsExclusiveScanAMD(ivec2);"
"ivec3 addInvocationsExclusiveScanAMD(ivec3);"
"ivec4 addInvocationsExclusiveScanAMD(ivec4);"
"uint addInvocationsExclusiveScanAMD(uint);"
"uvec2 addInvocationsExclusiveScanAMD(uvec2);"
"uvec3 addInvocationsExclusiveScanAMD(uvec3);"
"uvec4 addInvocationsExclusiveScanAMD(uvec4);"
"double addInvocationsExclusiveScanAMD(double);"
"dvec2 addInvocationsExclusiveScanAMD(dvec2);"
"dvec3 addInvocationsExclusiveScanAMD(dvec3);"
"dvec4 addInvocationsExclusiveScanAMD(dvec4);"
"int64_t addInvocationsExclusiveScanAMD(int64_t);"
"i64vec2 addInvocationsExclusiveScanAMD(i64vec2);"
"i64vec3 addInvocationsExclusiveScanAMD(i64vec3);"
"i64vec4 addInvocationsExclusiveScanAMD(i64vec4);"
"uint64_t addInvocationsExclusiveScanAMD(uint64_t);"
"u64vec2 addInvocationsExclusiveScanAMD(u64vec2);"
"u64vec3 addInvocationsExclusiveScanAMD(u64vec3);"
"u64vec4 addInvocationsExclusiveScanAMD(u64vec4);"
"float16_t addInvocationsExclusiveScanAMD(float16_t);"
"f16vec2 addInvocationsExclusiveScanAMD(f16vec2);"
"f16vec3 addInvocationsExclusiveScanAMD(f16vec3);"
"f16vec4 addInvocationsExclusiveScanAMD(f16vec4);"
"int16_t addInvocationsExclusiveScanAMD(int16_t);"
"i16vec2 addInvocationsExclusiveScanAMD(i16vec2);"
"i16vec3 addInvocationsExclusiveScanAMD(i16vec3);"
"i16vec4 addInvocationsExclusiveScanAMD(i16vec4);"
"uint16_t addInvocationsExclusiveScanAMD(uint16_t);"
"u16vec2 addInvocationsExclusiveScanAMD(u16vec2);"
"u16vec3 addInvocationsExclusiveScanAMD(u16vec3);"
"u16vec4 addInvocationsExclusiveScanAMD(u16vec4);"
"float minInvocationsNonUniformAMD(float);"
"vec2 minInvocationsNonUniformAMD(vec2);"
"vec3 minInvocationsNonUniformAMD(vec3);"
"vec4 minInvocationsNonUniformAMD(vec4);"
"int minInvocationsNonUniformAMD(int);"
"ivec2 minInvocationsNonUniformAMD(ivec2);"
"ivec3 minInvocationsNonUniformAMD(ivec3);"
"ivec4 minInvocationsNonUniformAMD(ivec4);"
"uint minInvocationsNonUniformAMD(uint);"
"uvec2 minInvocationsNonUniformAMD(uvec2);"
"uvec3 minInvocationsNonUniformAMD(uvec3);"
"uvec4 minInvocationsNonUniformAMD(uvec4);"
"double minInvocationsNonUniformAMD(double);"
"dvec2 minInvocationsNonUniformAMD(dvec2);"
"dvec3 minInvocationsNonUniformAMD(dvec3);"
"dvec4 minInvocationsNonUniformAMD(dvec4);"
"int64_t minInvocationsNonUniformAMD(int64_t);"
"i64vec2 minInvocationsNonUniformAMD(i64vec2);"
"i64vec3 minInvocationsNonUniformAMD(i64vec3);"
"i64vec4 minInvocationsNonUniformAMD(i64vec4);"
"uint64_t minInvocationsNonUniformAMD(uint64_t);"
"u64vec2 minInvocationsNonUniformAMD(u64vec2);"
"u64vec3 minInvocationsNonUniformAMD(u64vec3);"
"u64vec4 minInvocationsNonUniformAMD(u64vec4);"
"float16_t minInvocationsNonUniformAMD(float16_t);"
"f16vec2 minInvocationsNonUniformAMD(f16vec2);"
"f16vec3 minInvocationsNonUniformAMD(f16vec3);"
"f16vec4 minInvocationsNonUniformAMD(f16vec4);"
"int16_t minInvocationsNonUniformAMD(int16_t);"
"i16vec2 minInvocationsNonUniformAMD(i16vec2);"
"i16vec3 minInvocationsNonUniformAMD(i16vec3);"
"i16vec4 minInvocationsNonUniformAMD(i16vec4);"
"uint16_t minInvocationsNonUniformAMD(uint16_t);"
"u16vec2 minInvocationsNonUniformAMD(u16vec2);"
"u16vec3 minInvocationsNonUniformAMD(u16vec3);"
"u16vec4 minInvocationsNonUniformAMD(u16vec4);"
"float minInvocationsInclusiveScanNonUniformAMD(float);"
"vec2 minInvocationsInclusiveScanNonUniformAMD(vec2);"
"vec3 minInvocationsInclusiveScanNonUniformAMD(vec3);"
"vec4 minInvocationsInclusiveScanNonUniformAMD(vec4);"
"int minInvocationsInclusiveScanNonUniformAMD(int);"
"ivec2 minInvocationsInclusiveScanNonUniformAMD(ivec2);"
"ivec3 minInvocationsInclusiveScanNonUniformAMD(ivec3);"
"ivec4 minInvocationsInclusiveScanNonUniformAMD(ivec4);"
"uint minInvocationsInclusiveScanNonUniformAMD(uint);"
"uvec2 minInvocationsInclusiveScanNonUniformAMD(uvec2);"
"uvec3 minInvocationsInclusiveScanNonUniformAMD(uvec3);"
"uvec4 minInvocationsInclusiveScanNonUniformAMD(uvec4);"
"double minInvocationsInclusiveScanNonUniformAMD(double);"
"dvec2 minInvocationsInclusiveScanNonUniformAMD(dvec2);"
"dvec3 minInvocationsInclusiveScanNonUniformAMD(dvec3);"
"dvec4 minInvocationsInclusiveScanNonUniformAMD(dvec4);"
"int64_t minInvocationsInclusiveScanNonUniformAMD(int64_t);"
"i64vec2 minInvocationsInclusiveScanNonUniformAMD(i64vec2);"
"i64vec3 minInvocationsInclusiveScanNonUniformAMD(i64vec3);"
"i64vec4 minInvocationsInclusiveScanNonUniformAMD(i64vec4);"
"uint64_t minInvocationsInclusiveScanNonUniformAMD(uint64_t);"
"u64vec2 minInvocationsInclusiveScanNonUniformAMD(u64vec2);"
"u64vec3 minInvocationsInclusiveScanNonUniformAMD(u64vec3);"
"u64vec4 minInvocationsInclusiveScanNonUniformAMD(u64vec4);"
"float16_t minInvocationsInclusiveScanNonUniformAMD(float16_t);"
"f16vec2 minInvocationsInclusiveScanNonUniformAMD(f16vec2);"
"f16vec3 minInvocationsInclusiveScanNonUniformAMD(f16vec3);"
"f16vec4 minInvocationsInclusiveScanNonUniformAMD(f16vec4);"
"int16_t minInvocationsInclusiveScanNonUniformAMD(int16_t);"
"i16vec2 minInvocationsInclusiveScanNonUniformAMD(i16vec2);"
"i16vec3 minInvocationsInclusiveScanNonUniformAMD(i16vec3);"
"i16vec4 minInvocationsInclusiveScanNonUniformAMD(i16vec4);"
"uint16_t minInvocationsInclusiveScanNonUniformAMD(uint16_t);"
"u16vec2 minInvocationsInclusiveScanNonUniformAMD(u16vec2);"
"u16vec3 minInvocationsInclusiveScanNonUniformAMD(u16vec3);"
"u16vec4 minInvocationsInclusiveScanNonUniformAMD(u16vec4);"
"float minInvocationsExclusiveScanNonUniformAMD(float);"
"vec2 minInvocationsExclusiveScanNonUniformAMD(vec2);"
"vec3 minInvocationsExclusiveScanNonUniformAMD(vec3);"
"vec4 minInvocationsExclusiveScanNonUniformAMD(vec4);"
"int minInvocationsExclusiveScanNonUniformAMD(int);"
"ivec2 minInvocationsExclusiveScanNonUniformAMD(ivec2);"
"ivec3 minInvocationsExclusiveScanNonUniformAMD(ivec3);"
"ivec4 minInvocationsExclusiveScanNonUniformAMD(ivec4);"
"uint minInvocationsExclusiveScanNonUniformAMD(uint);"
"uvec2 minInvocationsExclusiveScanNonUniformAMD(uvec2);"
"uvec3 minInvocationsExclusiveScanNonUniformAMD(uvec3);"
"uvec4 minInvocationsExclusiveScanNonUniformAMD(uvec4);"
"double minInvocationsExclusiveScanNonUniformAMD(double);"
"dvec2 minInvocationsExclusiveScanNonUniformAMD(dvec2);"
"dvec3 minInvocationsExclusiveScanNonUniformAMD(dvec3);"
"dvec4 minInvocationsExclusiveScanNonUniformAMD(dvec4);"
"int64_t minInvocationsExclusiveScanNonUniformAMD(int64_t);"
"i64vec2 minInvocationsExclusiveScanNonUniformAMD(i64vec2);"
"i64vec3 minInvocationsExclusiveScanNonUniformAMD(i64vec3);"
"i64vec4 minInvocationsExclusiveScanNonUniformAMD(i64vec4);"
"uint64_t minInvocationsExclusiveScanNonUniformAMD(uint64_t);"
"u64vec2 minInvocationsExclusiveScanNonUniformAMD(u64vec2);"
"u64vec3 minInvocationsExclusiveScanNonUniformAMD(u64vec3);"
"u64vec4 minInvocationsExclusiveScanNonUniformAMD(u64vec4);"
"float16_t minInvocationsExclusiveScanNonUniformAMD(float16_t);"
"f16vec2 minInvocationsExclusiveScanNonUniformAMD(f16vec2);"
"f16vec3 minInvocationsExclusiveScanNonUniformAMD(f16vec3);"
"f16vec4 minInvocationsExclusiveScanNonUniformAMD(f16vec4);"
"int16_t minInvocationsExclusiveScanNonUniformAMD(int16_t);"
"i16vec2 minInvocationsExclusiveScanNonUniformAMD(i16vec2);"
"i16vec3 minInvocationsExclusiveScanNonUniformAMD(i16vec3);"
"i16vec4 minInvocationsExclusiveScanNonUniformAMD(i16vec4);"
"uint16_t minInvocationsExclusiveScanNonUniformAMD(uint16_t);"
"u16vec2 minInvocationsExclusiveScanNonUniformAMD(u16vec2);"
"u16vec3 minInvocationsExclusiveScanNonUniformAMD(u16vec3);"
"u16vec4 minInvocationsExclusiveScanNonUniformAMD(u16vec4);"
"float maxInvocationsNonUniformAMD(float);"
"vec2 maxInvocationsNonUniformAMD(vec2);"
"vec3 maxInvocationsNonUniformAMD(vec3);"
"vec4 maxInvocationsNonUniformAMD(vec4);"
"int maxInvocationsNonUniformAMD(int);"
"ivec2 maxInvocationsNonUniformAMD(ivec2);"
"ivec3 maxInvocationsNonUniformAMD(ivec3);"
"ivec4 maxInvocationsNonUniformAMD(ivec4);"
"uint maxInvocationsNonUniformAMD(uint);"
"uvec2 maxInvocationsNonUniformAMD(uvec2);"
"uvec3 maxInvocationsNonUniformAMD(uvec3);"
"uvec4 maxInvocationsNonUniformAMD(uvec4);"
"double maxInvocationsNonUniformAMD(double);"
"dvec2 maxInvocationsNonUniformAMD(dvec2);"
"dvec3 maxInvocationsNonUniformAMD(dvec3);"
"dvec4 maxInvocationsNonUniformAMD(dvec4);"
"int64_t maxInvocationsNonUniformAMD(int64_t);"
"i64vec2 maxInvocationsNonUniformAMD(i64vec2);"
"i64vec3 maxInvocationsNonUniformAMD(i64vec3);"
"i64vec4 maxInvocationsNonUniformAMD(i64vec4);"
"uint64_t maxInvocationsNonUniformAMD(uint64_t);"
"u64vec2 maxInvocationsNonUniformAMD(u64vec2);"
"u64vec3 maxInvocationsNonUniformAMD(u64vec3);"
"u64vec4 maxInvocationsNonUniformAMD(u64vec4);"
"float16_t maxInvocationsNonUniformAMD(float16_t);"
"f16vec2 maxInvocationsNonUniformAMD(f16vec2);"
"f16vec3 maxInvocationsNonUniformAMD(f16vec3);"
"f16vec4 maxInvocationsNonUniformAMD(f16vec4);"
"int16_t maxInvocationsNonUniformAMD(int16_t);"
"i16vec2 maxInvocationsNonUniformAMD(i16vec2);"
"i16vec3 maxInvocationsNonUniformAMD(i16vec3);"
"i16vec4 maxInvocationsNonUniformAMD(i16vec4);"
"uint16_t maxInvocationsNonUniformAMD(uint16_t);"
"u16vec2 maxInvocationsNonUniformAMD(u16vec2);"
"u16vec3 maxInvocationsNonUniformAMD(u16vec3);"
"u16vec4 maxInvocationsNonUniformAMD(u16vec4);"
"float maxInvocationsInclusiveScanNonUniformAMD(float);"
"vec2 maxInvocationsInclusiveScanNonUniformAMD(vec2);"
"vec3 maxInvocationsInclusiveScanNonUniformAMD(vec3);"
"vec4 maxInvocationsInclusiveScanNonUniformAMD(vec4);"
"int maxInvocationsInclusiveScanNonUniformAMD(int);"
"ivec2 maxInvocationsInclusiveScanNonUniformAMD(ivec2);"
"ivec3 maxInvocationsInclusiveScanNonUniformAMD(ivec3);"
"ivec4 maxInvocationsInclusiveScanNonUniformAMD(ivec4);"
"uint maxInvocationsInclusiveScanNonUniformAMD(uint);"
"uvec2 maxInvocationsInclusiveScanNonUniformAMD(uvec2);"
"uvec3 maxInvocationsInclusiveScanNonUniformAMD(uvec3);"
"uvec4 maxInvocationsInclusiveScanNonUniformAMD(uvec4);"
"double maxInvocationsInclusiveScanNonUniformAMD(double);"
"dvec2 maxInvocationsInclusiveScanNonUniformAMD(dvec2);"
"dvec3 maxInvocationsInclusiveScanNonUniformAMD(dvec3);"
"dvec4 maxInvocationsInclusiveScanNonUniformAMD(dvec4);"
"int64_t maxInvocationsInclusiveScanNonUniformAMD(int64_t);"
"i64vec2 maxInvocationsInclusiveScanNonUniformAMD(i64vec2);"
"i64vec3 maxInvocationsInclusiveScanNonUniformAMD(i64vec3);"
"i64vec4 maxInvocationsInclusiveScanNonUniformAMD(i64vec4);"
"uint64_t maxInvocationsInclusiveScanNonUniformAMD(uint64_t);"
"u64vec2 maxInvocationsInclusiveScanNonUniformAMD(u64vec2);"
"u64vec3 maxInvocationsInclusiveScanNonUniformAMD(u64vec3);"
"u64vec4 maxInvocationsInclusiveScanNonUniformAMD(u64vec4);"
"float16_t maxInvocationsInclusiveScanNonUniformAMD(float16_t);"
"f16vec2 maxInvocationsInclusiveScanNonUniformAMD(f16vec2);"
"f16vec3 maxInvocationsInclusiveScanNonUniformAMD(f16vec3);"
"f16vec4 maxInvocationsInclusiveScanNonUniformAMD(f16vec4);"
"int16_t maxInvocationsInclusiveScanNonUniformAMD(int16_t);"
"i16vec2 maxInvocationsInclusiveScanNonUniformAMD(i16vec2);"
"i16vec3 maxInvocationsInclusiveScanNonUniformAMD(i16vec3);"
"i16vec4 maxInvocationsInclusiveScanNonUniformAMD(i16vec4);"
"uint16_t maxInvocationsInclusiveScanNonUniformAMD(uint16_t);"
"u16vec2 maxInvocationsInclusiveScanNonUniformAMD(u16vec2);"
"u16vec3 maxInvocationsInclusiveScanNonUniformAMD(u16vec3);"
"u16vec4 maxInvocationsInclusiveScanNonUniformAMD(u16vec4);"
"float maxInvocationsExclusiveScanNonUniformAMD(float);"
"vec2 maxInvocationsExclusiveScanNonUniformAMD(vec2);"
"vec3 maxInvocationsExclusiveScanNonUniformAMD(vec3);"
"vec4 maxInvocationsExclusiveScanNonUniformAMD(vec4);"
"int maxInvocationsExclusiveScanNonUniformAMD(int);"
"ivec2 maxInvocationsExclusiveScanNonUniformAMD(ivec2);"
"ivec3 maxInvocationsExclusiveScanNonUniformAMD(ivec3);"
"ivec4 maxInvocationsExclusiveScanNonUniformAMD(ivec4);"
"uint maxInvocationsExclusiveScanNonUniformAMD(uint);"
"uvec2 maxInvocationsExclusiveScanNonUniformAMD(uvec2);"
"uvec3 maxInvocationsExclusiveScanNonUniformAMD(uvec3);"
"uvec4 maxInvocationsExclusiveScanNonUniformAMD(uvec4);"
"double maxInvocationsExclusiveScanNonUniformAMD(double);"
"dvec2 maxInvocationsExclusiveScanNonUniformAMD(dvec2);"
"dvec3 maxInvocationsExclusiveScanNonUniformAMD(dvec3);"
"dvec4 maxInvocationsExclusiveScanNonUniformAMD(dvec4);"
"int64_t maxInvocationsExclusiveScanNonUniformAMD(int64_t);"
"i64vec2 maxInvocationsExclusiveScanNonUniformAMD(i64vec2);"
"i64vec3 maxInvocationsExclusiveScanNonUniformAMD(i64vec3);"
"i64vec4 maxInvocationsExclusiveScanNonUniformAMD(i64vec4);"
"uint64_t maxInvocationsExclusiveScanNonUniformAMD(uint64_t);"
"u64vec2 maxInvocationsExclusiveScanNonUniformAMD(u64vec2);"
"u64vec3 maxInvocationsExclusiveScanNonUniformAMD(u64vec3);"
"u64vec4 maxInvocationsExclusiveScanNonUniformAMD(u64vec4);"
"float16_t maxInvocationsExclusiveScanNonUniformAMD(float16_t);"
"f16vec2 maxInvocationsExclusiveScanNonUniformAMD(f16vec2);"
"f16vec3 maxInvocationsExclusiveScanNonUniformAMD(f16vec3);"
"f16vec4 maxInvocationsExclusiveScanNonUniformAMD(f16vec4);"
"int16_t maxInvocationsExclusiveScanNonUniformAMD(int16_t);"
"i16vec2 maxInvocationsExclusiveScanNonUniformAMD(i16vec2);"
"i16vec3 maxInvocationsExclusiveScanNonUniformAMD(i16vec3);"
"i16vec4 maxInvocationsExclusiveScanNonUniformAMD(i16vec4);"
"uint16_t maxInvocationsExclusiveScanNonUniformAMD(uint16_t);"
"u16vec2 maxInvocationsExclusiveScanNonUniformAMD(u16vec2);"
"u16vec3 maxInvocationsExclusiveScanNonUniformAMD(u16vec3);"
"u16vec4 maxInvocationsExclusiveScanNonUniformAMD(u16vec4);"
"float addInvocationsNonUniformAMD(float);"
"vec2 addInvocationsNonUniformAMD(vec2);"
"vec3 addInvocationsNonUniformAMD(vec3);"
"vec4 addInvocationsNonUniformAMD(vec4);"
"int addInvocationsNonUniformAMD(int);"
"ivec2 addInvocationsNonUniformAMD(ivec2);"
"ivec3 addInvocationsNonUniformAMD(ivec3);"
"ivec4 addInvocationsNonUniformAMD(ivec4);"
"uint addInvocationsNonUniformAMD(uint);"
"uvec2 addInvocationsNonUniformAMD(uvec2);"
"uvec3 addInvocationsNonUniformAMD(uvec3);"
"uvec4 addInvocationsNonUniformAMD(uvec4);"
"double addInvocationsNonUniformAMD(double);"
"dvec2 addInvocationsNonUniformAMD(dvec2);"
"dvec3 addInvocationsNonUniformAMD(dvec3);"
"dvec4 addInvocationsNonUniformAMD(dvec4);"
"int64_t addInvocationsNonUniformAMD(int64_t);"
"i64vec2 addInvocationsNonUniformAMD(i64vec2);"
"i64vec3 addInvocationsNonUniformAMD(i64vec3);"
"i64vec4 addInvocationsNonUniformAMD(i64vec4);"
"uint64_t addInvocationsNonUniformAMD(uint64_t);"
"u64vec2 addInvocationsNonUniformAMD(u64vec2);"
"u64vec3 addInvocationsNonUniformAMD(u64vec3);"
"u64vec4 addInvocationsNonUniformAMD(u64vec4);"
"float16_t addInvocationsNonUniformAMD(float16_t);"
"f16vec2 addInvocationsNonUniformAMD(f16vec2);"
"f16vec3 addInvocationsNonUniformAMD(f16vec3);"
"f16vec4 addInvocationsNonUniformAMD(f16vec4);"
"int16_t addInvocationsNonUniformAMD(int16_t);"
"i16vec2 addInvocationsNonUniformAMD(i16vec2);"
"i16vec3 addInvocationsNonUniformAMD(i16vec3);"
"i16vec4 addInvocationsNonUniformAMD(i16vec4);"
"uint16_t addInvocationsNonUniformAMD(uint16_t);"
"u16vec2 addInvocationsNonUniformAMD(u16vec2);"
"u16vec3 addInvocationsNonUniformAMD(u16vec3);"
"u16vec4 addInvocationsNonUniformAMD(u16vec4);"
"float addInvocationsInclusiveScanNonUniformAMD(float);"
"vec2 addInvocationsInclusiveScanNonUniformAMD(vec2);"
"vec3 addInvocationsInclusiveScanNonUniformAMD(vec3);"
"vec4 addInvocationsInclusiveScanNonUniformAMD(vec4);"
"int addInvocationsInclusiveScanNonUniformAMD(int);"
"ivec2 addInvocationsInclusiveScanNonUniformAMD(ivec2);"
"ivec3 addInvocationsInclusiveScanNonUniformAMD(ivec3);"
"ivec4 addInvocationsInclusiveScanNonUniformAMD(ivec4);"
"uint addInvocationsInclusiveScanNonUniformAMD(uint);"
"uvec2 addInvocationsInclusiveScanNonUniformAMD(uvec2);"
"uvec3 addInvocationsInclusiveScanNonUniformAMD(uvec3);"
"uvec4 addInvocationsInclusiveScanNonUniformAMD(uvec4);"
"double addInvocationsInclusiveScanNonUniformAMD(double);"
"dvec2 addInvocationsInclusiveScanNonUniformAMD(dvec2);"
"dvec3 addInvocationsInclusiveScanNonUniformAMD(dvec3);"
"dvec4 addInvocationsInclusiveScanNonUniformAMD(dvec4);"
"int64_t addInvocationsInclusiveScanNonUniformAMD(int64_t);"
"i64vec2 addInvocationsInclusiveScanNonUniformAMD(i64vec2);"
"i64vec3 addInvocationsInclusiveScanNonUniformAMD(i64vec3);"
"i64vec4 addInvocationsInclusiveScanNonUniformAMD(i64vec4);"
"uint64_t addInvocationsInclusiveScanNonUniformAMD(uint64_t);"
"u64vec2 addInvocationsInclusiveScanNonUniformAMD(u64vec2);"
"u64vec3 addInvocationsInclusiveScanNonUniformAMD(u64vec3);"
"u64vec4 addInvocationsInclusiveScanNonUniformAMD(u64vec4);"
"float16_t addInvocationsInclusiveScanNonUniformAMD(float16_t);"
"f16vec2 addInvocationsInclusiveScanNonUniformAMD(f16vec2);"
"f16vec3 addInvocationsInclusiveScanNonUniformAMD(f16vec3);"
"f16vec4 addInvocationsInclusiveScanNonUniformAMD(f16vec4);"
"int16_t addInvocationsInclusiveScanNonUniformAMD(int16_t);"
"i16vec2 addInvocationsInclusiveScanNonUniformAMD(i16vec2);"
"i16vec3 addInvocationsInclusiveScanNonUniformAMD(i16vec3);"
"i16vec4 addInvocationsInclusiveScanNonUniformAMD(i16vec4);"
"uint16_t addInvocationsInclusiveScanNonUniformAMD(uint16_t);"
"u16vec2 addInvocationsInclusiveScanNonUniformAMD(u16vec2);"
"u16vec3 addInvocationsInclusiveScanNonUniformAMD(u16vec3);"
"u16vec4 addInvocationsInclusiveScanNonUniformAMD(u16vec4);"
"float addInvocationsExclusiveScanNonUniformAMD(float);"
"vec2 addInvocationsExclusiveScanNonUniformAMD(vec2);"
"vec3 addInvocationsExclusiveScanNonUniformAMD(vec3);"
"vec4 addInvocationsExclusiveScanNonUniformAMD(vec4);"
"int addInvocationsExclusiveScanNonUniformAMD(int);"
"ivec2 addInvocationsExclusiveScanNonUniformAMD(ivec2);"
"ivec3 addInvocationsExclusiveScanNonUniformAMD(ivec3);"
"ivec4 addInvocationsExclusiveScanNonUniformAMD(ivec4);"
"uint addInvocationsExclusiveScanNonUniformAMD(uint);"
"uvec2 addInvocationsExclusiveScanNonUniformAMD(uvec2);"
"uvec3 addInvocationsExclusiveScanNonUniformAMD(uvec3);"
"uvec4 addInvocationsExclusiveScanNonUniformAMD(uvec4);"
"double addInvocationsExclusiveScanNonUniformAMD(double);"
"dvec2 addInvocationsExclusiveScanNonUniformAMD(dvec2);"
"dvec3 addInvocationsExclusiveScanNonUniformAMD(dvec3);"
"dvec4 addInvocationsExclusiveScanNonUniformAMD(dvec4);"
"int64_t addInvocationsExclusiveScanNonUniformAMD(int64_t);"
"i64vec2 addInvocationsExclusiveScanNonUniformAMD(i64vec2);"
"i64vec3 addInvocationsExclusiveScanNonUniformAMD(i64vec3);"
"i64vec4 addInvocationsExclusiveScanNonUniformAMD(i64vec4);"
"uint64_t addInvocationsExclusiveScanNonUniformAMD(uint64_t);"
"u64vec2 addInvocationsExclusiveScanNonUniformAMD(u64vec2);"
"u64vec3 addInvocationsExclusiveScanNonUniformAMD(u64vec3);"
"u64vec4 addInvocationsExclusiveScanNonUniformAMD(u64vec4);"
"float16_t addInvocationsExclusiveScanNonUniformAMD(float16_t);"
"f16vec2 addInvocationsExclusiveScanNonUniformAMD(f16vec2);"
"f16vec3 addInvocationsExclusiveScanNonUniformAMD(f16vec3);"
"f16vec4 addInvocationsExclusiveScanNonUniformAMD(f16vec4);"
"int16_t addInvocationsExclusiveScanNonUniformAMD(int16_t);"
"i16vec2 addInvocationsExclusiveScanNonUniformAMD(i16vec2);"
"i16vec3 addInvocationsExclusiveScanNonUniformAMD(i16vec3);"
"i16vec4 addInvocationsExclusiveScanNonUniformAMD(i16vec4);"
"uint16_t addInvocationsExclusiveScanNonUniformAMD(uint16_t);"
"u16vec2 addInvocationsExclusiveScanNonUniformAMD(u16vec2);"
"u16vec3 addInvocationsExclusiveScanNonUniformAMD(u16vec3);"
"u16vec4 addInvocationsExclusiveScanNonUniformAMD(u16vec4);"
"float swizzleInvocationsAMD(float, uvec4);"
"vec2 swizzleInvocationsAMD(vec2, uvec4);"
"vec3 swizzleInvocationsAMD(vec3, uvec4);"
"vec4 swizzleInvocationsAMD(vec4, uvec4);"
"int swizzleInvocationsAMD(int, uvec4);"
"ivec2 swizzleInvocationsAMD(ivec2, uvec4);"
"ivec3 swizzleInvocationsAMD(ivec3, uvec4);"
"ivec4 swizzleInvocationsAMD(ivec4, uvec4);"
"uint swizzleInvocationsAMD(uint, uvec4);"
"uvec2 swizzleInvocationsAMD(uvec2, uvec4);"
"uvec3 swizzleInvocationsAMD(uvec3, uvec4);"
"uvec4 swizzleInvocationsAMD(uvec4, uvec4);"
"float swizzleInvocationsMaskedAMD(float, uvec3);"
"vec2 swizzleInvocationsMaskedAMD(vec2, uvec3);"
"vec3 swizzleInvocationsMaskedAMD(vec3, uvec3);"
"vec4 swizzleInvocationsMaskedAMD(vec4, uvec3);"
"int swizzleInvocationsMaskedAMD(int, uvec3);"
"ivec2 swizzleInvocationsMaskedAMD(ivec2, uvec3);"
"ivec3 swizzleInvocationsMaskedAMD(ivec3, uvec3);"
"ivec4 swizzleInvocationsMaskedAMD(ivec4, uvec3);"
"uint swizzleInvocationsMaskedAMD(uint, uvec3);"
"uvec2 swizzleInvocationsMaskedAMD(uvec2, uvec3);"
"uvec3 swizzleInvocationsMaskedAMD(uvec3, uvec3);"
"uvec4 swizzleInvocationsMaskedAMD(uvec4, uvec3);"
"float writeInvocationAMD(float, float, uint);"
"vec2 writeInvocationAMD(vec2, vec2, uint);"
"vec3 writeInvocationAMD(vec3, vec3, uint);"
"vec4 writeInvocationAMD(vec4, vec4, uint);"
"int writeInvocationAMD(int, int, uint);"
"ivec2 writeInvocationAMD(ivec2, ivec2, uint);"
"ivec3 writeInvocationAMD(ivec3, ivec3, uint);"
"ivec4 writeInvocationAMD(ivec4, ivec4, uint);"
"uint writeInvocationAMD(uint, uint, uint);"
"uvec2 writeInvocationAMD(uvec2, uvec2, uint);"
"uvec3 writeInvocationAMD(uvec3, uvec3, uint);"
"uvec4 writeInvocationAMD(uvec4, uvec4, uint);"
"uint mbcntAMD(uint64_t);"
"\n");
}
// GL_AMD_gcn_shader
if (profile != EEsProfile && version >= 440) {
commonBuiltins.append(
"float cubeFaceIndexAMD(vec3);"
"vec2 cubeFaceCoordAMD(vec3);"
"uint64_t timeAMD();"
"in int gl_SIMDGroupSizeAMD;"
"\n");
}
// GL_AMD_shader_fragment_mask
if (profile != EEsProfile && version >= 450) {
commonBuiltins.append(
"uint fragmentMaskFetchAMD(sampler2DMS, ivec2);"
"uint fragmentMaskFetchAMD(isampler2DMS, ivec2);"
"uint fragmentMaskFetchAMD(usampler2DMS, ivec2);"
"uint fragmentMaskFetchAMD(sampler2DMSArray, ivec3);"
"uint fragmentMaskFetchAMD(isampler2DMSArray, ivec3);"
"uint fragmentMaskFetchAMD(usampler2DMSArray, ivec3);"
"vec4 fragmentFetchAMD(sampler2DMS, ivec2, uint);"
"ivec4 fragmentFetchAMD(isampler2DMS, ivec2, uint);"
"uvec4 fragmentFetchAMD(usampler2DMS, ivec2, uint);"
"vec4 fragmentFetchAMD(sampler2DMSArray, ivec3, uint);"
"ivec4 fragmentFetchAMD(isampler2DMSArray, ivec3, uint);"
"uvec4 fragmentFetchAMD(usampler2DMSArray, ivec3, uint);"
"\n");
}
if ((profile != EEsProfile && version >= 130) ||
(profile == EEsProfile && version >= 300)) {
commonBuiltins.append(
"uint countLeadingZeros(uint);"
"uvec2 countLeadingZeros(uvec2);"
"uvec3 countLeadingZeros(uvec3);"
"uvec4 countLeadingZeros(uvec4);"
"uint countTrailingZeros(uint);"
"uvec2 countTrailingZeros(uvec2);"
"uvec3 countTrailingZeros(uvec3);"
"uvec4 countTrailingZeros(uvec4);"
"uint absoluteDifference(int, int);"
"uvec2 absoluteDifference(ivec2, ivec2);"
"uvec3 absoluteDifference(ivec3, ivec3);"
"uvec4 absoluteDifference(ivec4, ivec4);"
"uint16_t absoluteDifference(int16_t, int16_t);"
"u16vec2 absoluteDifference(i16vec2, i16vec2);"
"u16vec3 absoluteDifference(i16vec3, i16vec3);"
"u16vec4 absoluteDifference(i16vec4, i16vec4);"
"uint64_t absoluteDifference(int64_t, int64_t);"
"u64vec2 absoluteDifference(i64vec2, i64vec2);"
"u64vec3 absoluteDifference(i64vec3, i64vec3);"
"u64vec4 absoluteDifference(i64vec4, i64vec4);"
"uint absoluteDifference(uint, uint);"
"uvec2 absoluteDifference(uvec2, uvec2);"
"uvec3 absoluteDifference(uvec3, uvec3);"
"uvec4 absoluteDifference(uvec4, uvec4);"
"uint16_t absoluteDifference(uint16_t, uint16_t);"
"u16vec2 absoluteDifference(u16vec2, u16vec2);"
"u16vec3 absoluteDifference(u16vec3, u16vec3);"
"u16vec4 absoluteDifference(u16vec4, u16vec4);"
"uint64_t absoluteDifference(uint64_t, uint64_t);"
"u64vec2 absoluteDifference(u64vec2, u64vec2);"
"u64vec3 absoluteDifference(u64vec3, u64vec3);"
"u64vec4 absoluteDifference(u64vec4, u64vec4);"
"int addSaturate(int, int);"
"ivec2 addSaturate(ivec2, ivec2);"
"ivec3 addSaturate(ivec3, ivec3);"
"ivec4 addSaturate(ivec4, ivec4);"
"int16_t addSaturate(int16_t, int16_t);"
"i16vec2 addSaturate(i16vec2, i16vec2);"
"i16vec3 addSaturate(i16vec3, i16vec3);"
"i16vec4 addSaturate(i16vec4, i16vec4);"
"int64_t addSaturate(int64_t, int64_t);"
"i64vec2 addSaturate(i64vec2, i64vec2);"
"i64vec3 addSaturate(i64vec3, i64vec3);"
"i64vec4 addSaturate(i64vec4, i64vec4);"
"uint addSaturate(uint, uint);"
"uvec2 addSaturate(uvec2, uvec2);"
"uvec3 addSaturate(uvec3, uvec3);"
"uvec4 addSaturate(uvec4, uvec4);"
"uint16_t addSaturate(uint16_t, uint16_t);"
"u16vec2 addSaturate(u16vec2, u16vec2);"
"u16vec3 addSaturate(u16vec3, u16vec3);"
"u16vec4 addSaturate(u16vec4, u16vec4);"
"uint64_t addSaturate(uint64_t, uint64_t);"
"u64vec2 addSaturate(u64vec2, u64vec2);"
"u64vec3 addSaturate(u64vec3, u64vec3);"
"u64vec4 addSaturate(u64vec4, u64vec4);"
"int subtractSaturate(int, int);"
"ivec2 subtractSaturate(ivec2, ivec2);"
"ivec3 subtractSaturate(ivec3, ivec3);"
"ivec4 subtractSaturate(ivec4, ivec4);"
"int16_t subtractSaturate(int16_t, int16_t);"
"i16vec2 subtractSaturate(i16vec2, i16vec2);"
"i16vec3 subtractSaturate(i16vec3, i16vec3);"
"i16vec4 subtractSaturate(i16vec4, i16vec4);"
"int64_t subtractSaturate(int64_t, int64_t);"
"i64vec2 subtractSaturate(i64vec2, i64vec2);"
"i64vec3 subtractSaturate(i64vec3, i64vec3);"
"i64vec4 subtractSaturate(i64vec4, i64vec4);"
"uint subtractSaturate(uint, uint);"
"uvec2 subtractSaturate(uvec2, uvec2);"
"uvec3 subtractSaturate(uvec3, uvec3);"
"uvec4 subtractSaturate(uvec4, uvec4);"
"uint16_t subtractSaturate(uint16_t, uint16_t);"
"u16vec2 subtractSaturate(u16vec2, u16vec2);"
"u16vec3 subtractSaturate(u16vec3, u16vec3);"
"u16vec4 subtractSaturate(u16vec4, u16vec4);"
"uint64_t subtractSaturate(uint64_t, uint64_t);"
"u64vec2 subtractSaturate(u64vec2, u64vec2);"
"u64vec3 subtractSaturate(u64vec3, u64vec3);"
"u64vec4 subtractSaturate(u64vec4, u64vec4);"
"int average(int, int);"
"ivec2 average(ivec2, ivec2);"
"ivec3 average(ivec3, ivec3);"
"ivec4 average(ivec4, ivec4);"
"int16_t average(int16_t, int16_t);"
"i16vec2 average(i16vec2, i16vec2);"
"i16vec3 average(i16vec3, i16vec3);"
"i16vec4 average(i16vec4, i16vec4);"
"int64_t average(int64_t, int64_t);"
"i64vec2 average(i64vec2, i64vec2);"
"i64vec3 average(i64vec3, i64vec3);"
"i64vec4 average(i64vec4, i64vec4);"
"uint average(uint, uint);"
"uvec2 average(uvec2, uvec2);"
"uvec3 average(uvec3, uvec3);"
"uvec4 average(uvec4, uvec4);"
"uint16_t average(uint16_t, uint16_t);"
"u16vec2 average(u16vec2, u16vec2);"
"u16vec3 average(u16vec3, u16vec3);"
"u16vec4 average(u16vec4, u16vec4);"
"uint64_t average(uint64_t, uint64_t);"
"u64vec2 average(u64vec2, u64vec2);"
"u64vec3 average(u64vec3, u64vec3);"
"u64vec4 average(u64vec4, u64vec4);"
"int averageRounded(int, int);"
"ivec2 averageRounded(ivec2, ivec2);"
"ivec3 averageRounded(ivec3, ivec3);"
"ivec4 averageRounded(ivec4, ivec4);"
"int16_t averageRounded(int16_t, int16_t);"
"i16vec2 averageRounded(i16vec2, i16vec2);"
"i16vec3 averageRounded(i16vec3, i16vec3);"
"i16vec4 averageRounded(i16vec4, i16vec4);"
"int64_t averageRounded(int64_t, int64_t);"
"i64vec2 averageRounded(i64vec2, i64vec2);"
"i64vec3 averageRounded(i64vec3, i64vec3);"
"i64vec4 averageRounded(i64vec4, i64vec4);"
"uint averageRounded(uint, uint);"
"uvec2 averageRounded(uvec2, uvec2);"
"uvec3 averageRounded(uvec3, uvec3);"
"uvec4 averageRounded(uvec4, uvec4);"
"uint16_t averageRounded(uint16_t, uint16_t);"
"u16vec2 averageRounded(u16vec2, u16vec2);"
"u16vec3 averageRounded(u16vec3, u16vec3);"
"u16vec4 averageRounded(u16vec4, u16vec4);"
"uint64_t averageRounded(uint64_t, uint64_t);"
"u64vec2 averageRounded(u64vec2, u64vec2);"
"u64vec3 averageRounded(u64vec3, u64vec3);"
"u64vec4 averageRounded(u64vec4, u64vec4);"
"int multiply32x16(int, int);"
"ivec2 multiply32x16(ivec2, ivec2);"
"ivec3 multiply32x16(ivec3, ivec3);"
"ivec4 multiply32x16(ivec4, ivec4);"
"uint multiply32x16(uint, uint);"
"uvec2 multiply32x16(uvec2, uvec2);"
"uvec3 multiply32x16(uvec3, uvec3);"
"uvec4 multiply32x16(uvec4, uvec4);"
"\n");
}
if ((profile != EEsProfile && version >= 450) ||
(profile == EEsProfile && version >= 320)) {
commonBuiltins.append(
"struct gl_TextureFootprint2DNV {"
"uvec2 anchor;"
"uvec2 offset;"
"uvec2 mask;"
"uint lod;"
"uint granularity;"
"};"
"struct gl_TextureFootprint3DNV {"
"uvec3 anchor;"
"uvec3 offset;"
"uvec2 mask;"
"uint lod;"
"uint granularity;"
"};"
"bool textureFootprintNV(sampler2D, vec2, int, bool, out gl_TextureFootprint2DNV);"
"bool textureFootprintNV(sampler3D, vec3, int, bool, out gl_TextureFootprint3DNV);"
"bool textureFootprintNV(sampler2D, vec2, int, bool, out gl_TextureFootprint2DNV, float);"
"bool textureFootprintNV(sampler3D, vec3, int, bool, out gl_TextureFootprint3DNV, float);"
"bool textureFootprintClampNV(sampler2D, vec2, float, int, bool, out gl_TextureFootprint2DNV);"
"bool textureFootprintClampNV(sampler3D, vec3, float, int, bool, out gl_TextureFootprint3DNV);"
"bool textureFootprintClampNV(sampler2D, vec2, float, int, bool, out gl_TextureFootprint2DNV, float);"
"bool textureFootprintClampNV(sampler3D, vec3, float, int, bool, out gl_TextureFootprint3DNV, float);"
"bool textureFootprintLodNV(sampler2D, vec2, float, int, bool, out gl_TextureFootprint2DNV);"
"bool textureFootprintLodNV(sampler3D, vec3, float, int, bool, out gl_TextureFootprint3DNV);"
"bool textureFootprintGradNV(sampler2D, vec2, vec2, vec2, int, bool, out gl_TextureFootprint2DNV);"
"bool textureFootprintGradClampNV(sampler2D, vec2, vec2, vec2, float, int, bool, out gl_TextureFootprint2DNV);"
"\n");
}
if ((profile == EEsProfile && version >= 300 && version < 310) ||
(profile != EEsProfile && version >= 150 && version < 450)) { // GL_EXT_shader_integer_mix
commonBuiltins.append("int mix(int, int, bool);"
"ivec2 mix(ivec2, ivec2, bvec2);"
"ivec3 mix(ivec3, ivec3, bvec3);"
"ivec4 mix(ivec4, ivec4, bvec4);"
"uint mix(uint, uint, bool );"
"uvec2 mix(uvec2, uvec2, bvec2);"
"uvec3 mix(uvec3, uvec3, bvec3);"
"uvec4 mix(uvec4, uvec4, bvec4);"
"bool mix(bool, bool, bool );"
"bvec2 mix(bvec2, bvec2, bvec2);"
"bvec3 mix(bvec3, bvec3, bvec3);"
"bvec4 mix(bvec4, bvec4, bvec4);"
"\n");
}
// GL_AMD_gpu_shader_half_float/Explicit types
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
commonBuiltins.append(
"float16_t radians(float16_t);"
"f16vec2 radians(f16vec2);"
"f16vec3 radians(f16vec3);"
"f16vec4 radians(f16vec4);"
"float16_t degrees(float16_t);"
"f16vec2 degrees(f16vec2);"
"f16vec3 degrees(f16vec3);"
"f16vec4 degrees(f16vec4);"
"float16_t sin(float16_t);"
"f16vec2 sin(f16vec2);"
"f16vec3 sin(f16vec3);"
"f16vec4 sin(f16vec4);"
"float16_t cos(float16_t);"
"f16vec2 cos(f16vec2);"
"f16vec3 cos(f16vec3);"
"f16vec4 cos(f16vec4);"
"float16_t tan(float16_t);"
"f16vec2 tan(f16vec2);"
"f16vec3 tan(f16vec3);"
"f16vec4 tan(f16vec4);"
"float16_t asin(float16_t);"
"f16vec2 asin(f16vec2);"
"f16vec3 asin(f16vec3);"
"f16vec4 asin(f16vec4);"
"float16_t acos(float16_t);"
"f16vec2 acos(f16vec2);"
"f16vec3 acos(f16vec3);"
"f16vec4 acos(f16vec4);"
"float16_t atan(float16_t, float16_t);"
"f16vec2 atan(f16vec2, f16vec2);"
"f16vec3 atan(f16vec3, f16vec3);"
"f16vec4 atan(f16vec4, f16vec4);"
"float16_t atan(float16_t);"
"f16vec2 atan(f16vec2);"
"f16vec3 atan(f16vec3);"
"f16vec4 atan(f16vec4);"
"float16_t sinh(float16_t);"
"f16vec2 sinh(f16vec2);"
"f16vec3 sinh(f16vec3);"
"f16vec4 sinh(f16vec4);"
"float16_t cosh(float16_t);"
"f16vec2 cosh(f16vec2);"
"f16vec3 cosh(f16vec3);"
"f16vec4 cosh(f16vec4);"
"float16_t tanh(float16_t);"
"f16vec2 tanh(f16vec2);"
"f16vec3 tanh(f16vec3);"
"f16vec4 tanh(f16vec4);"
"float16_t asinh(float16_t);"
"f16vec2 asinh(f16vec2);"
"f16vec3 asinh(f16vec3);"
"f16vec4 asinh(f16vec4);"
"float16_t acosh(float16_t);"
"f16vec2 acosh(f16vec2);"
"f16vec3 acosh(f16vec3);"
"f16vec4 acosh(f16vec4);"
"float16_t atanh(float16_t);"
"f16vec2 atanh(f16vec2);"
"f16vec3 atanh(f16vec3);"
"f16vec4 atanh(f16vec4);"
"float16_t pow(float16_t, float16_t);"
"f16vec2 pow(f16vec2, f16vec2);"
"f16vec3 pow(f16vec3, f16vec3);"
"f16vec4 pow(f16vec4, f16vec4);"
"float16_t exp(float16_t);"
"f16vec2 exp(f16vec2);"
"f16vec3 exp(f16vec3);"
"f16vec4 exp(f16vec4);"
"float16_t log(float16_t);"
"f16vec2 log(f16vec2);"
"f16vec3 log(f16vec3);"
"f16vec4 log(f16vec4);"
"float16_t exp2(float16_t);"
"f16vec2 exp2(f16vec2);"
"f16vec3 exp2(f16vec3);"
"f16vec4 exp2(f16vec4);"
"float16_t log2(float16_t);"
"f16vec2 log2(f16vec2);"
"f16vec3 log2(f16vec3);"
"f16vec4 log2(f16vec4);"
"float16_t sqrt(float16_t);"
"f16vec2 sqrt(f16vec2);"
"f16vec3 sqrt(f16vec3);"
"f16vec4 sqrt(f16vec4);"
"float16_t inversesqrt(float16_t);"
"f16vec2 inversesqrt(f16vec2);"
"f16vec3 inversesqrt(f16vec3);"
"f16vec4 inversesqrt(f16vec4);"
"float16_t abs(float16_t);"
"f16vec2 abs(f16vec2);"
"f16vec3 abs(f16vec3);"
"f16vec4 abs(f16vec4);"
"float16_t sign(float16_t);"
"f16vec2 sign(f16vec2);"
"f16vec3 sign(f16vec3);"
"f16vec4 sign(f16vec4);"
"float16_t floor(float16_t);"
"f16vec2 floor(f16vec2);"
"f16vec3 floor(f16vec3);"
"f16vec4 floor(f16vec4);"
"float16_t trunc(float16_t);"
"f16vec2 trunc(f16vec2);"
"f16vec3 trunc(f16vec3);"
"f16vec4 trunc(f16vec4);"
"float16_t round(float16_t);"
"f16vec2 round(f16vec2);"
"f16vec3 round(f16vec3);"
"f16vec4 round(f16vec4);"
"float16_t roundEven(float16_t);"
"f16vec2 roundEven(f16vec2);"
"f16vec3 roundEven(f16vec3);"
"f16vec4 roundEven(f16vec4);"
"float16_t ceil(float16_t);"
"f16vec2 ceil(f16vec2);"
"f16vec3 ceil(f16vec3);"
"f16vec4 ceil(f16vec4);"
"float16_t fract(float16_t);"
"f16vec2 fract(f16vec2);"
"f16vec3 fract(f16vec3);"
"f16vec4 fract(f16vec4);"
"float16_t mod(float16_t, float16_t);"
"f16vec2 mod(f16vec2, float16_t);"
"f16vec3 mod(f16vec3, float16_t);"
"f16vec4 mod(f16vec4, float16_t);"
"f16vec2 mod(f16vec2, f16vec2);"
"f16vec3 mod(f16vec3, f16vec3);"
"f16vec4 mod(f16vec4, f16vec4);"
"float16_t modf(float16_t, out float16_t);"
"f16vec2 modf(f16vec2, out f16vec2);"
"f16vec3 modf(f16vec3, out f16vec3);"
"f16vec4 modf(f16vec4, out f16vec4);"
"float16_t min(float16_t, float16_t);"
"f16vec2 min(f16vec2, float16_t);"
"f16vec3 min(f16vec3, float16_t);"
"f16vec4 min(f16vec4, float16_t);"
"f16vec2 min(f16vec2, f16vec2);"
"f16vec3 min(f16vec3, f16vec3);"
"f16vec4 min(f16vec4, f16vec4);"
"float16_t max(float16_t, float16_t);"
"f16vec2 max(f16vec2, float16_t);"
"f16vec3 max(f16vec3, float16_t);"
"f16vec4 max(f16vec4, float16_t);"
"f16vec2 max(f16vec2, f16vec2);"
"f16vec3 max(f16vec3, f16vec3);"
"f16vec4 max(f16vec4, f16vec4);"
"float16_t clamp(float16_t, float16_t, float16_t);"
"f16vec2 clamp(f16vec2, float16_t, float16_t);"
"f16vec3 clamp(f16vec3, float16_t, float16_t);"
"f16vec4 clamp(f16vec4, float16_t, float16_t);"
"f16vec2 clamp(f16vec2, f16vec2, f16vec2);"
"f16vec3 clamp(f16vec3, f16vec3, f16vec3);"
"f16vec4 clamp(f16vec4, f16vec4, f16vec4);"
"float16_t mix(float16_t, float16_t, float16_t);"
"f16vec2 mix(f16vec2, f16vec2, float16_t);"
"f16vec3 mix(f16vec3, f16vec3, float16_t);"
"f16vec4 mix(f16vec4, f16vec4, float16_t);"
"f16vec2 mix(f16vec2, f16vec2, f16vec2);"
"f16vec3 mix(f16vec3, f16vec3, f16vec3);"
"f16vec4 mix(f16vec4, f16vec4, f16vec4);"
"float16_t mix(float16_t, float16_t, bool);"
"f16vec2 mix(f16vec2, f16vec2, bvec2);"
"f16vec3 mix(f16vec3, f16vec3, bvec3);"
"f16vec4 mix(f16vec4, f16vec4, bvec4);"
"float16_t step(float16_t, float16_t);"
"f16vec2 step(f16vec2, f16vec2);"
"f16vec3 step(f16vec3, f16vec3);"
"f16vec4 step(f16vec4, f16vec4);"
"f16vec2 step(float16_t, f16vec2);"
"f16vec3 step(float16_t, f16vec3);"
"f16vec4 step(float16_t, f16vec4);"
"float16_t smoothstep(float16_t, float16_t, float16_t);"
"f16vec2 smoothstep(f16vec2, f16vec2, f16vec2);"
"f16vec3 smoothstep(f16vec3, f16vec3, f16vec3);"
"f16vec4 smoothstep(f16vec4, f16vec4, f16vec4);"
"f16vec2 smoothstep(float16_t, float16_t, f16vec2);"
"f16vec3 smoothstep(float16_t, float16_t, f16vec3);"
"f16vec4 smoothstep(float16_t, float16_t, f16vec4);"
"bool isnan(float16_t);"
"bvec2 isnan(f16vec2);"
"bvec3 isnan(f16vec3);"
"bvec4 isnan(f16vec4);"
"bool isinf(float16_t);"
"bvec2 isinf(f16vec2);"
"bvec3 isinf(f16vec3);"
"bvec4 isinf(f16vec4);"
"float16_t fma(float16_t, float16_t, float16_t);"
"f16vec2 fma(f16vec2, f16vec2, f16vec2);"
"f16vec3 fma(f16vec3, f16vec3, f16vec3);"
"f16vec4 fma(f16vec4, f16vec4, f16vec4);"
"float16_t frexp(float16_t, out int);"
"f16vec2 frexp(f16vec2, out ivec2);"
"f16vec3 frexp(f16vec3, out ivec3);"
"f16vec4 frexp(f16vec4, out ivec4);"
"float16_t ldexp(float16_t, in int);"
"f16vec2 ldexp(f16vec2, in ivec2);"
"f16vec3 ldexp(f16vec3, in ivec3);"
"f16vec4 ldexp(f16vec4, in ivec4);"
"uint packFloat2x16(f16vec2);"
"f16vec2 unpackFloat2x16(uint);"
"float16_t length(float16_t);"
"float16_t length(f16vec2);"
"float16_t length(f16vec3);"
"float16_t length(f16vec4);"
"float16_t distance(float16_t, float16_t);"
"float16_t distance(f16vec2, f16vec2);"
"float16_t distance(f16vec3, f16vec3);"
"float16_t distance(f16vec4, f16vec4);"
"float16_t dot(float16_t, float16_t);"
"float16_t dot(f16vec2, f16vec2);"
"float16_t dot(f16vec3, f16vec3);"
"float16_t dot(f16vec4, f16vec4);"
"f16vec3 cross(f16vec3, f16vec3);"
"float16_t normalize(float16_t);"
"f16vec2 normalize(f16vec2);"
"f16vec3 normalize(f16vec3);"
"f16vec4 normalize(f16vec4);"
"float16_t faceforward(float16_t, float16_t, float16_t);"
"f16vec2 faceforward(f16vec2, f16vec2, f16vec2);"
"f16vec3 faceforward(f16vec3, f16vec3, f16vec3);"
"f16vec4 faceforward(f16vec4, f16vec4, f16vec4);"
"float16_t reflect(float16_t, float16_t);"
"f16vec2 reflect(f16vec2, f16vec2);"
"f16vec3 reflect(f16vec3, f16vec3);"
"f16vec4 reflect(f16vec4, f16vec4);"
"float16_t refract(float16_t, float16_t, float16_t);"
"f16vec2 refract(f16vec2, f16vec2, float16_t);"
"f16vec3 refract(f16vec3, f16vec3, float16_t);"
"f16vec4 refract(f16vec4, f16vec4, float16_t);"
"f16mat2 matrixCompMult(f16mat2, f16mat2);"
"f16mat3 matrixCompMult(f16mat3, f16mat3);"
"f16mat4 matrixCompMult(f16mat4, f16mat4);"
"f16mat2x3 matrixCompMult(f16mat2x3, f16mat2x3);"
"f16mat2x4 matrixCompMult(f16mat2x4, f16mat2x4);"
"f16mat3x2 matrixCompMult(f16mat3x2, f16mat3x2);"
"f16mat3x4 matrixCompMult(f16mat3x4, f16mat3x4);"
"f16mat4x2 matrixCompMult(f16mat4x2, f16mat4x2);"
"f16mat4x3 matrixCompMult(f16mat4x3, f16mat4x3);"
"f16mat2 outerProduct(f16vec2, f16vec2);"
"f16mat3 outerProduct(f16vec3, f16vec3);"
"f16mat4 outerProduct(f16vec4, f16vec4);"
"f16mat2x3 outerProduct(f16vec3, f16vec2);"
"f16mat3x2 outerProduct(f16vec2, f16vec3);"
"f16mat2x4 outerProduct(f16vec4, f16vec2);"
"f16mat4x2 outerProduct(f16vec2, f16vec4);"
"f16mat3x4 outerProduct(f16vec4, f16vec3);"
"f16mat4x3 outerProduct(f16vec3, f16vec4);"
"f16mat2 transpose(f16mat2);"
"f16mat3 transpose(f16mat3);"
"f16mat4 transpose(f16mat4);"
"f16mat2x3 transpose(f16mat3x2);"
"f16mat3x2 transpose(f16mat2x3);"
"f16mat2x4 transpose(f16mat4x2);"
"f16mat4x2 transpose(f16mat2x4);"
"f16mat3x4 transpose(f16mat4x3);"
"f16mat4x3 transpose(f16mat3x4);"
"float16_t determinant(f16mat2);"
"float16_t determinant(f16mat3);"
"float16_t determinant(f16mat4);"
"f16mat2 inverse(f16mat2);"
"f16mat3 inverse(f16mat3);"
"f16mat4 inverse(f16mat4);"
"bvec2 lessThan(f16vec2, f16vec2);"
"bvec3 lessThan(f16vec3, f16vec3);"
"bvec4 lessThan(f16vec4, f16vec4);"
"bvec2 lessThanEqual(f16vec2, f16vec2);"
"bvec3 lessThanEqual(f16vec3, f16vec3);"
"bvec4 lessThanEqual(f16vec4, f16vec4);"
"bvec2 greaterThan(f16vec2, f16vec2);"
"bvec3 greaterThan(f16vec3, f16vec3);"
"bvec4 greaterThan(f16vec4, f16vec4);"
"bvec2 greaterThanEqual(f16vec2, f16vec2);"
"bvec3 greaterThanEqual(f16vec3, f16vec3);"
"bvec4 greaterThanEqual(f16vec4, f16vec4);"
"bvec2 equal(f16vec2, f16vec2);"
"bvec3 equal(f16vec3, f16vec3);"
"bvec4 equal(f16vec4, f16vec4);"
"bvec2 notEqual(f16vec2, f16vec2);"
"bvec3 notEqual(f16vec3, f16vec3);"
"bvec4 notEqual(f16vec4, f16vec4);"
"\n");
}
// Explicit types
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
commonBuiltins.append(
"int8_t abs(int8_t);"
"i8vec2 abs(i8vec2);"
"i8vec3 abs(i8vec3);"
"i8vec4 abs(i8vec4);"
"int8_t sign(int8_t);"
"i8vec2 sign(i8vec2);"
"i8vec3 sign(i8vec3);"
"i8vec4 sign(i8vec4);"
"int8_t min(int8_t x, int8_t y);"
"i8vec2 min(i8vec2 x, int8_t y);"
"i8vec3 min(i8vec3 x, int8_t y);"
"i8vec4 min(i8vec4 x, int8_t y);"
"i8vec2 min(i8vec2 x, i8vec2 y);"
"i8vec3 min(i8vec3 x, i8vec3 y);"
"i8vec4 min(i8vec4 x, i8vec4 y);"
"uint8_t min(uint8_t x, uint8_t y);"
"u8vec2 min(u8vec2 x, uint8_t y);"
"u8vec3 min(u8vec3 x, uint8_t y);"
"u8vec4 min(u8vec4 x, uint8_t y);"
"u8vec2 min(u8vec2 x, u8vec2 y);"
"u8vec3 min(u8vec3 x, u8vec3 y);"
"u8vec4 min(u8vec4 x, u8vec4 y);"
"int8_t max(int8_t x, int8_t y);"
"i8vec2 max(i8vec2 x, int8_t y);"
"i8vec3 max(i8vec3 x, int8_t y);"
"i8vec4 max(i8vec4 x, int8_t y);"
"i8vec2 max(i8vec2 x, i8vec2 y);"
"i8vec3 max(i8vec3 x, i8vec3 y);"
"i8vec4 max(i8vec4 x, i8vec4 y);"
"uint8_t max(uint8_t x, uint8_t y);"
"u8vec2 max(u8vec2 x, uint8_t y);"
"u8vec3 max(u8vec3 x, uint8_t y);"
"u8vec4 max(u8vec4 x, uint8_t y);"
"u8vec2 max(u8vec2 x, u8vec2 y);"
"u8vec3 max(u8vec3 x, u8vec3 y);"
"u8vec4 max(u8vec4 x, u8vec4 y);"
"int8_t clamp(int8_t x, int8_t minVal, int8_t maxVal);"
"i8vec2 clamp(i8vec2 x, int8_t minVal, int8_t maxVal);"
"i8vec3 clamp(i8vec3 x, int8_t minVal, int8_t maxVal);"
"i8vec4 clamp(i8vec4 x, int8_t minVal, int8_t maxVal);"
"i8vec2 clamp(i8vec2 x, i8vec2 minVal, i8vec2 maxVal);"
"i8vec3 clamp(i8vec3 x, i8vec3 minVal, i8vec3 maxVal);"
"i8vec4 clamp(i8vec4 x, i8vec4 minVal, i8vec4 maxVal);"
"uint8_t clamp(uint8_t x, uint8_t minVal, uint8_t maxVal);"
"u8vec2 clamp(u8vec2 x, uint8_t minVal, uint8_t maxVal);"
"u8vec3 clamp(u8vec3 x, uint8_t minVal, uint8_t maxVal);"
"u8vec4 clamp(u8vec4 x, uint8_t minVal, uint8_t maxVal);"
"u8vec2 clamp(u8vec2 x, u8vec2 minVal, u8vec2 maxVal);"
"u8vec3 clamp(u8vec3 x, u8vec3 minVal, u8vec3 maxVal);"
"u8vec4 clamp(u8vec4 x, u8vec4 minVal, u8vec4 maxVal);"
"int8_t mix(int8_t, int8_t, bool);"
"i8vec2 mix(i8vec2, i8vec2, bvec2);"
"i8vec3 mix(i8vec3, i8vec3, bvec3);"
"i8vec4 mix(i8vec4, i8vec4, bvec4);"
"uint8_t mix(uint8_t, uint8_t, bool);"
"u8vec2 mix(u8vec2, u8vec2, bvec2);"
"u8vec3 mix(u8vec3, u8vec3, bvec3);"
"u8vec4 mix(u8vec4, u8vec4, bvec4);"
"bvec2 lessThan(i8vec2, i8vec2);"
"bvec3 lessThan(i8vec3, i8vec3);"
"bvec4 lessThan(i8vec4, i8vec4);"
"bvec2 lessThan(u8vec2, u8vec2);"
"bvec3 lessThan(u8vec3, u8vec3);"
"bvec4 lessThan(u8vec4, u8vec4);"
"bvec2 lessThanEqual(i8vec2, i8vec2);"
"bvec3 lessThanEqual(i8vec3, i8vec3);"
"bvec4 lessThanEqual(i8vec4, i8vec4);"
"bvec2 lessThanEqual(u8vec2, u8vec2);"
"bvec3 lessThanEqual(u8vec3, u8vec3);"
"bvec4 lessThanEqual(u8vec4, u8vec4);"
"bvec2 greaterThan(i8vec2, i8vec2);"
"bvec3 greaterThan(i8vec3, i8vec3);"
"bvec4 greaterThan(i8vec4, i8vec4);"
"bvec2 greaterThan(u8vec2, u8vec2);"
"bvec3 greaterThan(u8vec3, u8vec3);"
"bvec4 greaterThan(u8vec4, u8vec4);"
"bvec2 greaterThanEqual(i8vec2, i8vec2);"
"bvec3 greaterThanEqual(i8vec3, i8vec3);"
"bvec4 greaterThanEqual(i8vec4, i8vec4);"
"bvec2 greaterThanEqual(u8vec2, u8vec2);"
"bvec3 greaterThanEqual(u8vec3, u8vec3);"
"bvec4 greaterThanEqual(u8vec4, u8vec4);"
"bvec2 equal(i8vec2, i8vec2);"
"bvec3 equal(i8vec3, i8vec3);"
"bvec4 equal(i8vec4, i8vec4);"
"bvec2 equal(u8vec2, u8vec2);"
"bvec3 equal(u8vec3, u8vec3);"
"bvec4 equal(u8vec4, u8vec4);"
"bvec2 notEqual(i8vec2, i8vec2);"
"bvec3 notEqual(i8vec3, i8vec3);"
"bvec4 notEqual(i8vec4, i8vec4);"
"bvec2 notEqual(u8vec2, u8vec2);"
"bvec3 notEqual(u8vec3, u8vec3);"
"bvec4 notEqual(u8vec4, u8vec4);"
" int8_t bitfieldExtract( int8_t, int8_t, int8_t);"
"i8vec2 bitfieldExtract(i8vec2, int8_t, int8_t);"
"i8vec3 bitfieldExtract(i8vec3, int8_t, int8_t);"
"i8vec4 bitfieldExtract(i8vec4, int8_t, int8_t);"
" uint8_t bitfieldExtract( uint8_t, int8_t, int8_t);"
"u8vec2 bitfieldExtract(u8vec2, int8_t, int8_t);"
"u8vec3 bitfieldExtract(u8vec3, int8_t, int8_t);"
"u8vec4 bitfieldExtract(u8vec4, int8_t, int8_t);"
" int8_t bitfieldInsert( int8_t base, int8_t, int8_t, int8_t);"
"i8vec2 bitfieldInsert(i8vec2 base, i8vec2, int8_t, int8_t);"
"i8vec3 bitfieldInsert(i8vec3 base, i8vec3, int8_t, int8_t);"
"i8vec4 bitfieldInsert(i8vec4 base, i8vec4, int8_t, int8_t);"
" uint8_t bitfieldInsert( uint8_t base, uint8_t, int8_t, int8_t);"
"u8vec2 bitfieldInsert(u8vec2 base, u8vec2, int8_t, int8_t);"
"u8vec3 bitfieldInsert(u8vec3 base, u8vec3, int8_t, int8_t);"
"u8vec4 bitfieldInsert(u8vec4 base, u8vec4, int8_t, int8_t);"
" int8_t bitCount( int8_t);"
"i8vec2 bitCount(i8vec2);"
"i8vec3 bitCount(i8vec3);"
"i8vec4 bitCount(i8vec4);"
" int8_t bitCount( uint8_t);"
"i8vec2 bitCount(u8vec2);"
"i8vec3 bitCount(u8vec3);"
"i8vec4 bitCount(u8vec4);"
" int8_t findLSB( int8_t);"
"i8vec2 findLSB(i8vec2);"
"i8vec3 findLSB(i8vec3);"
"i8vec4 findLSB(i8vec4);"
" int8_t findLSB( uint8_t);"
"i8vec2 findLSB(u8vec2);"
"i8vec3 findLSB(u8vec3);"
"i8vec4 findLSB(u8vec4);"
" int8_t findMSB( int8_t);"
"i8vec2 findMSB(i8vec2);"
"i8vec3 findMSB(i8vec3);"
"i8vec4 findMSB(i8vec4);"
" int8_t findMSB( uint8_t);"
"i8vec2 findMSB(u8vec2);"
"i8vec3 findMSB(u8vec3);"
"i8vec4 findMSB(u8vec4);"
"int16_t abs(int16_t);"
"i16vec2 abs(i16vec2);"
"i16vec3 abs(i16vec3);"
"i16vec4 abs(i16vec4);"
"int16_t sign(int16_t);"
"i16vec2 sign(i16vec2);"
"i16vec3 sign(i16vec3);"
"i16vec4 sign(i16vec4);"
"int16_t min(int16_t x, int16_t y);"
"i16vec2 min(i16vec2 x, int16_t y);"
"i16vec3 min(i16vec3 x, int16_t y);"
"i16vec4 min(i16vec4 x, int16_t y);"
"i16vec2 min(i16vec2 x, i16vec2 y);"
"i16vec3 min(i16vec3 x, i16vec3 y);"
"i16vec4 min(i16vec4 x, i16vec4 y);"
"uint16_t min(uint16_t x, uint16_t y);"
"u16vec2 min(u16vec2 x, uint16_t y);"
"u16vec3 min(u16vec3 x, uint16_t y);"
"u16vec4 min(u16vec4 x, uint16_t y);"
"u16vec2 min(u16vec2 x, u16vec2 y);"
"u16vec3 min(u16vec3 x, u16vec3 y);"
"u16vec4 min(u16vec4 x, u16vec4 y);"
"int16_t max(int16_t x, int16_t y);"
"i16vec2 max(i16vec2 x, int16_t y);"
"i16vec3 max(i16vec3 x, int16_t y);"
"i16vec4 max(i16vec4 x, int16_t y);"
"i16vec2 max(i16vec2 x, i16vec2 y);"
"i16vec3 max(i16vec3 x, i16vec3 y);"
"i16vec4 max(i16vec4 x, i16vec4 y);"
"uint16_t max(uint16_t x, uint16_t y);"
"u16vec2 max(u16vec2 x, uint16_t y);"
"u16vec3 max(u16vec3 x, uint16_t y);"
"u16vec4 max(u16vec4 x, uint16_t y);"
"u16vec2 max(u16vec2 x, u16vec2 y);"
"u16vec3 max(u16vec3 x, u16vec3 y);"
"u16vec4 max(u16vec4 x, u16vec4 y);"
"int16_t clamp(int16_t x, int16_t minVal, int16_t maxVal);"
"i16vec2 clamp(i16vec2 x, int16_t minVal, int16_t maxVal);"
"i16vec3 clamp(i16vec3 x, int16_t minVal, int16_t maxVal);"
"i16vec4 clamp(i16vec4 x, int16_t minVal, int16_t maxVal);"
"i16vec2 clamp(i16vec2 x, i16vec2 minVal, i16vec2 maxVal);"
"i16vec3 clamp(i16vec3 x, i16vec3 minVal, i16vec3 maxVal);"
"i16vec4 clamp(i16vec4 x, i16vec4 minVal, i16vec4 maxVal);"
"uint16_t clamp(uint16_t x, uint16_t minVal, uint16_t maxVal);"
"u16vec2 clamp(u16vec2 x, uint16_t minVal, uint16_t maxVal);"
"u16vec3 clamp(u16vec3 x, uint16_t minVal, uint16_t maxVal);"
"u16vec4 clamp(u16vec4 x, uint16_t minVal, uint16_t maxVal);"
"u16vec2 clamp(u16vec2 x, u16vec2 minVal, u16vec2 maxVal);"
"u16vec3 clamp(u16vec3 x, u16vec3 minVal, u16vec3 maxVal);"
"u16vec4 clamp(u16vec4 x, u16vec4 minVal, u16vec4 maxVal);"
"int16_t mix(int16_t, int16_t, bool);"
"i16vec2 mix(i16vec2, i16vec2, bvec2);"
"i16vec3 mix(i16vec3, i16vec3, bvec3);"
"i16vec4 mix(i16vec4, i16vec4, bvec4);"
"uint16_t mix(uint16_t, uint16_t, bool);"
"u16vec2 mix(u16vec2, u16vec2, bvec2);"
"u16vec3 mix(u16vec3, u16vec3, bvec3);"
"u16vec4 mix(u16vec4, u16vec4, bvec4);"
"float16_t frexp(float16_t, out int16_t);"
"f16vec2 frexp(f16vec2, out i16vec2);"
"f16vec3 frexp(f16vec3, out i16vec3);"
"f16vec4 frexp(f16vec4, out i16vec4);"
"float16_t ldexp(float16_t, int16_t);"
"f16vec2 ldexp(f16vec2, i16vec2);"
"f16vec3 ldexp(f16vec3, i16vec3);"
"f16vec4 ldexp(f16vec4, i16vec4);"
"int16_t halfBitsToInt16(float16_t);"
"i16vec2 halfBitsToInt16(f16vec2);"
"i16vec3 halhBitsToInt16(f16vec3);"
"i16vec4 halfBitsToInt16(f16vec4);"
"uint16_t halfBitsToUint16(float16_t);"
"u16vec2 halfBitsToUint16(f16vec2);"
"u16vec3 halfBitsToUint16(f16vec3);"
"u16vec4 halfBitsToUint16(f16vec4);"
"int16_t float16BitsToInt16(float16_t);"
"i16vec2 float16BitsToInt16(f16vec2);"
"i16vec3 float16BitsToInt16(f16vec3);"
"i16vec4 float16BitsToInt16(f16vec4);"
"uint16_t float16BitsToUint16(float16_t);"
"u16vec2 float16BitsToUint16(f16vec2);"
"u16vec3 float16BitsToUint16(f16vec3);"
"u16vec4 float16BitsToUint16(f16vec4);"
"float16_t int16BitsToFloat16(int16_t);"
"f16vec2 int16BitsToFloat16(i16vec2);"
"f16vec3 int16BitsToFloat16(i16vec3);"
"f16vec4 int16BitsToFloat16(i16vec4);"
"float16_t uint16BitsToFloat16(uint16_t);"
"f16vec2 uint16BitsToFloat16(u16vec2);"
"f16vec3 uint16BitsToFloat16(u16vec3);"
"f16vec4 uint16BitsToFloat16(u16vec4);"
"float16_t int16BitsToHalf(int16_t);"
"f16vec2 int16BitsToHalf(i16vec2);"
"f16vec3 int16BitsToHalf(i16vec3);"
"f16vec4 int16BitsToHalf(i16vec4);"
"float16_t uint16BitsToHalf(uint16_t);"
"f16vec2 uint16BitsToHalf(u16vec2);"
"f16vec3 uint16BitsToHalf(u16vec3);"
"f16vec4 uint16BitsToHalf(u16vec4);"
"int packInt2x16(i16vec2);"
"uint packUint2x16(u16vec2);"
"int64_t packInt4x16(i16vec4);"
"uint64_t packUint4x16(u16vec4);"
"i16vec2 unpackInt2x16(int);"
"u16vec2 unpackUint2x16(uint);"
"i16vec4 unpackInt4x16(int64_t);"
"u16vec4 unpackUint4x16(uint64_t);"
"bvec2 lessThan(i16vec2, i16vec2);"
"bvec3 lessThan(i16vec3, i16vec3);"
"bvec4 lessThan(i16vec4, i16vec4);"
"bvec2 lessThan(u16vec2, u16vec2);"
"bvec3 lessThan(u16vec3, u16vec3);"
"bvec4 lessThan(u16vec4, u16vec4);"
"bvec2 lessThanEqual(i16vec2, i16vec2);"
"bvec3 lessThanEqual(i16vec3, i16vec3);"
"bvec4 lessThanEqual(i16vec4, i16vec4);"
"bvec2 lessThanEqual(u16vec2, u16vec2);"
"bvec3 lessThanEqual(u16vec3, u16vec3);"
"bvec4 lessThanEqual(u16vec4, u16vec4);"
"bvec2 greaterThan(i16vec2, i16vec2);"
"bvec3 greaterThan(i16vec3, i16vec3);"
"bvec4 greaterThan(i16vec4, i16vec4);"
"bvec2 greaterThan(u16vec2, u16vec2);"
"bvec3 greaterThan(u16vec3, u16vec3);"
"bvec4 greaterThan(u16vec4, u16vec4);"
"bvec2 greaterThanEqual(i16vec2, i16vec2);"
"bvec3 greaterThanEqual(i16vec3, i16vec3);"
"bvec4 greaterThanEqual(i16vec4, i16vec4);"
"bvec2 greaterThanEqual(u16vec2, u16vec2);"
"bvec3 greaterThanEqual(u16vec3, u16vec3);"
"bvec4 greaterThanEqual(u16vec4, u16vec4);"
"bvec2 equal(i16vec2, i16vec2);"
"bvec3 equal(i16vec3, i16vec3);"
"bvec4 equal(i16vec4, i16vec4);"
"bvec2 equal(u16vec2, u16vec2);"
"bvec3 equal(u16vec3, u16vec3);"
"bvec4 equal(u16vec4, u16vec4);"
"bvec2 notEqual(i16vec2, i16vec2);"
"bvec3 notEqual(i16vec3, i16vec3);"
"bvec4 notEqual(i16vec4, i16vec4);"
"bvec2 notEqual(u16vec2, u16vec2);"
"bvec3 notEqual(u16vec3, u16vec3);"
"bvec4 notEqual(u16vec4, u16vec4);"
" int16_t bitfieldExtract( int16_t, int16_t, int16_t);"
"i16vec2 bitfieldExtract(i16vec2, int16_t, int16_t);"
"i16vec3 bitfieldExtract(i16vec3, int16_t, int16_t);"
"i16vec4 bitfieldExtract(i16vec4, int16_t, int16_t);"
" uint16_t bitfieldExtract( uint16_t, int16_t, int16_t);"
"u16vec2 bitfieldExtract(u16vec2, int16_t, int16_t);"
"u16vec3 bitfieldExtract(u16vec3, int16_t, int16_t);"
"u16vec4 bitfieldExtract(u16vec4, int16_t, int16_t);"
" int16_t bitfieldInsert( int16_t base, int16_t, int16_t, int16_t);"
"i16vec2 bitfieldInsert(i16vec2 base, i16vec2, int16_t, int16_t);"
"i16vec3 bitfieldInsert(i16vec3 base, i16vec3, int16_t, int16_t);"
"i16vec4 bitfieldInsert(i16vec4 base, i16vec4, int16_t, int16_t);"
" uint16_t bitfieldInsert( uint16_t base, uint16_t, int16_t, int16_t);"
"u16vec2 bitfieldInsert(u16vec2 base, u16vec2, int16_t, int16_t);"
"u16vec3 bitfieldInsert(u16vec3 base, u16vec3, int16_t, int16_t);"
"u16vec4 bitfieldInsert(u16vec4 base, u16vec4, int16_t, int16_t);"
" int16_t bitCount( int16_t);"
"i16vec2 bitCount(i16vec2);"
"i16vec3 bitCount(i16vec3);"
"i16vec4 bitCount(i16vec4);"
" int16_t bitCount( uint16_t);"
"i16vec2 bitCount(u16vec2);"
"i16vec3 bitCount(u16vec3);"
"i16vec4 bitCount(u16vec4);"
" int16_t findLSB( int16_t);"
"i16vec2 findLSB(i16vec2);"
"i16vec3 findLSB(i16vec3);"
"i16vec4 findLSB(i16vec4);"
" int16_t findLSB( uint16_t);"
"i16vec2 findLSB(u16vec2);"
"i16vec3 findLSB(u16vec3);"
"i16vec4 findLSB(u16vec4);"
" int16_t findMSB( int16_t);"
"i16vec2 findMSB(i16vec2);"
"i16vec3 findMSB(i16vec3);"
"i16vec4 findMSB(i16vec4);"
" int16_t findMSB( uint16_t);"
"i16vec2 findMSB(u16vec2);"
"i16vec3 findMSB(u16vec3);"
"i16vec4 findMSB(u16vec4);"
"int16_t pack16(i8vec2);"
"uint16_t pack16(u8vec2);"
"int32_t pack32(i8vec4);"
"uint32_t pack32(u8vec4);"
"int32_t pack32(i16vec2);"
"uint32_t pack32(u16vec2);"
"int64_t pack64(i16vec4);"
"uint64_t pack64(u16vec4);"
"int64_t pack64(i32vec2);"
"uint64_t pack64(u32vec2);"
"i8vec2 unpack8(int16_t);"
"u8vec2 unpack8(uint16_t);"
"i8vec4 unpack8(int32_t);"
"u8vec4 unpack8(uint32_t);"
"i16vec2 unpack16(int32_t);"
"u16vec2 unpack16(uint32_t);"
"i16vec4 unpack16(int64_t);"
"u16vec4 unpack16(uint64_t);"
"i32vec2 unpack32(int64_t);"
"u32vec2 unpack32(uint64_t);"
// GL_EXT_expect_assume
"int8_t expectEXT(int8_t, int8_t);"
"i8vec2 expectEXT(i8vec2, i8vec2);"
"i8vec3 expectEXT(i8vec3, i8vec3);"
"i8vec4 expectEXT(i8vec4, i8vec4);"
"uint8_t expectEXT(uint8_t, uint8_t);"
"u8vec2 expectEXT(u8vec2, u8vec2);"
"u8vec3 expectEXT(u8vec3, u8vec3);"
"u8vec4 expectEXT(u8vec4, u8vec4);"
"int16_t expectEXT(int16_t, int16_t);"
"i16vec2 expectEXT(i16vec2, i16vec2);"
"i16vec3 expectEXT(i16vec3, i16vec3);"
"i16vec4 expectEXT(i16vec4, i16vec4);"
"uint16_t expectEXT(uint16_t, uint16_t);"
"u16vec2 expectEXT(u16vec2, u16vec2);"
"u16vec3 expectEXT(u16vec3, u16vec3);"
"u16vec4 expectEXT(u16vec4, u16vec4);"
"int64_t expectEXT(int64_t, int64_t);"
"i64vec2 expectEXT(i64vec2, i64vec2);"
"i64vec3 expectEXT(i64vec3, i64vec3);"
"i64vec4 expectEXT(i64vec4, i64vec4);"
"uint64_t expectEXT(uint64_t, uint64_t);"
"u64vec2 expectEXT(u64vec2, u64vec2);"
"u64vec3 expectEXT(u64vec3, u64vec3);"
"u64vec4 expectEXT(u64vec4, u64vec4);"
"\n");
}
// Builtins for GL_EXT_texture_shadow_lod
if ((profile == EEsProfile && version >= 300) || ((profile != EEsProfile && version >= 130))) {
commonBuiltins.append(
"float texture(sampler2DArrayShadow, vec4, float);"
"float texture(samplerCubeArrayShadow, vec4, float, float);"
"float textureLod(sampler2DArrayShadow, vec4, float);"
"float textureLod(samplerCubeShadow, vec4, float);"
"float textureLod(samplerCubeArrayShadow, vec4, float, float);"
"float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);"
"float textureOffset(sampler2DArrayShadow, vec4 , ivec2, float);"
"\n");
}
if (profile != EEsProfile && version >= 450) {
stageBuiltins[EShLangFragment].append(derivativesAndControl64bits);
stageBuiltins[EShLangFragment].append(
"float64_t interpolateAtCentroid(float64_t);"
"f64vec2 interpolateAtCentroid(f64vec2);"
"f64vec3 interpolateAtCentroid(f64vec3);"
"f64vec4 interpolateAtCentroid(f64vec4);"
"float64_t interpolateAtSample(float64_t, int);"
"f64vec2 interpolateAtSample(f64vec2, int);"
"f64vec3 interpolateAtSample(f64vec3, int);"
"f64vec4 interpolateAtSample(f64vec4, int);"
"float64_t interpolateAtOffset(float64_t, f64vec2);"
"f64vec2 interpolateAtOffset(f64vec2, f64vec2);"
"f64vec3 interpolateAtOffset(f64vec3, f64vec2);"
"f64vec4 interpolateAtOffset(f64vec4, f64vec2);"
"\n");
}
// GL_EXT_expect_assume
if ((profile == EEsProfile && version >= 310) ||
((profile != EEsProfile && version >= 140))) {
commonBuiltins.append(
"void assumeEXT(bool);"
"bool expectEXT(bool, bool);"
"bvec2 expectEXT(bvec2, bvec2);"
"bvec3 expectEXT(bvec3, bvec3);"
"bvec4 expectEXT(bvec4, bvec4);"
"int expectEXT(int, int);"
"ivec2 expectEXT(ivec2, ivec2);"
"ivec3 expectEXT(ivec3, ivec3);"
"ivec4 expectEXT(ivec4, ivec4);"
"uint expectEXT(uint, uint);"
"uvec2 expectEXT(uvec2, uvec2);"
"uvec3 expectEXT(uvec3, uvec3);"
"uvec4 expectEXT(uvec4, uvec4);"
"\n");
}
// QCOM_image_processing
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
commonBuiltins.append(
"vec4 textureWeightedQCOM(sampler2D, vec2, sampler2DArray);"
"vec4 textureWeightedQCOM(sampler2D, vec2, sampler1DArray);"
"vec4 textureBoxFilterQCOM(sampler2D, vec2, vec2);"
"vec4 textureBlockMatchSADQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
"vec4 textureBlockMatchSSDQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
"vec4 textureBlockMatchWindowSSDQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
"vec4 textureBlockMatchWindowSADQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
"vec4 textureBlockMatchGatherSSDQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
"vec4 textureBlockMatchGatherSADQCOM(sampler2D, uvec2, sampler2D, uvec2, uvec2);"
"\n");
}
//============================================================================
//
// Prototypes for built-in functions seen by vertex shaders only.
// (Except legacy lod functions, where it depends which release they are
// vertex only.)
//
//============================================================================
//
// Geometric Functions.
//
if (spvVersion.vulkan == 0 && IncludeLegacy(version, profile, spvVersion))
stageBuiltins[EShLangVertex].append("vec4 ftransform();");
//
// Original-style texture Functions with lod.
//
TString* s;
if (version == 100)
s = &stageBuiltins[EShLangVertex];
else
s = &commonBuiltins;
if ((profile == EEsProfile && version == 100) ||
profile == ECompatibilityProfile ||
(profile == ECoreProfile && version < 420) ||
profile == ENoProfile) {
if (spvVersion.spv == 0) {
s->append(
"vec4 texture2DLod(sampler2D, vec2, float);" // GL_ARB_shader_texture_lod
"vec4 texture2DProjLod(sampler2D, vec3, float);" // GL_ARB_shader_texture_lod
"vec4 texture2DProjLod(sampler2D, vec4, float);" // GL_ARB_shader_texture_lod
"vec4 texture3DLod(sampler3D, vec3, float);" // GL_ARB_shader_texture_lod // OES_texture_3D, but caught by keyword check
"vec4 texture3DProjLod(sampler3D, vec4, float);" // GL_ARB_shader_texture_lod // OES_texture_3D, but caught by keyword check
"vec4 textureCubeLod(samplerCube, vec3, float);" // GL_ARB_shader_texture_lod
"\n");
}
}
if ( profile == ECompatibilityProfile ||
(profile == ECoreProfile && version < 420) ||
profile == ENoProfile) {
if (spvVersion.spv == 0) {
s->append(
"vec4 texture1DLod(sampler1D, float, float);" // GL_ARB_shader_texture_lod
"vec4 texture1DProjLod(sampler1D, vec2, float);" // GL_ARB_shader_texture_lod
"vec4 texture1DProjLod(sampler1D, vec4, float);" // GL_ARB_shader_texture_lod
"vec4 shadow1DLod(sampler1DShadow, vec3, float);" // GL_ARB_shader_texture_lod
"vec4 shadow2DLod(sampler2DShadow, vec3, float);" // GL_ARB_shader_texture_lod
"vec4 shadow1DProjLod(sampler1DShadow, vec4, float);" // GL_ARB_shader_texture_lod
"vec4 shadow2DProjLod(sampler2DShadow, vec4, float);" // GL_ARB_shader_texture_lod
"vec4 texture1DGradARB(sampler1D, float, float, float);" // GL_ARB_shader_texture_lod
"vec4 texture1DProjGradARB(sampler1D, vec2, float, float);" // GL_ARB_shader_texture_lod
"vec4 texture1DProjGradARB(sampler1D, vec4, float, float);" // GL_ARB_shader_texture_lod
"vec4 texture2DGradARB(sampler2D, vec2, vec2, vec2);" // GL_ARB_shader_texture_lod
"vec4 texture2DProjGradARB(sampler2D, vec3, vec2, vec2);" // GL_ARB_shader_texture_lod
"vec4 texture2DProjGradARB(sampler2D, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod
"vec4 texture3DGradARB(sampler3D, vec3, vec3, vec3);" // GL_ARB_shader_texture_lod
"vec4 texture3DProjGradARB(sampler3D, vec4, vec3, vec3);" // GL_ARB_shader_texture_lod
"vec4 textureCubeGradARB(samplerCube, vec3, vec3, vec3);" // GL_ARB_shader_texture_lod
"vec4 shadow1DGradARB(sampler1DShadow, vec3, float, float);" // GL_ARB_shader_texture_lod
"vec4 shadow1DProjGradARB( sampler1DShadow, vec4, float, float);" // GL_ARB_shader_texture_lod
"vec4 shadow2DGradARB(sampler2DShadow, vec3, vec2, vec2);" // GL_ARB_shader_texture_lod
"vec4 shadow2DProjGradARB( sampler2DShadow, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod
"vec4 texture2DRectGradARB(sampler2DRect, vec2, vec2, vec2);" // GL_ARB_shader_texture_lod
"vec4 texture2DRectProjGradARB( sampler2DRect, vec3, vec2, vec2);" // GL_ARB_shader_texture_lod
"vec4 texture2DRectProjGradARB( sampler2DRect, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod
"vec4 shadow2DRectGradARB( sampler2DRectShadow, vec3, vec2, vec2);" // GL_ARB_shader_texture_lod
"vec4 shadow2DRectProjGradARB(sampler2DRectShadow, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod
"\n");
}
}
if ((profile != EEsProfile && version >= 150) ||
(profile == EEsProfile && version >= 310)) {
//============================================================================
//
// Prototypes for built-in functions seen by geometry shaders only.
//
//============================================================================
if (profile != EEsProfile && (version >= 400 || version == 150)) {
stageBuiltins[EShLangGeometry].append(
"void EmitStreamVertex(int);"
"void EndStreamPrimitive(int);"
);
}
stageBuiltins[EShLangGeometry].append(
"void EmitVertex();"
"void EndPrimitive();"
"\n");
}
//============================================================================
//
// Prototypes for all control functions.
//
//============================================================================
bool esBarrier = (profile == EEsProfile && version >= 310);
if ((profile != EEsProfile && version >= 150) || esBarrier)
stageBuiltins[EShLangTessControl].append(
"void barrier();"
);
if ((profile != EEsProfile && version >= 420) || esBarrier)
stageBuiltins[EShLangCompute].append(
"void barrier();"
);
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
stageBuiltins[EShLangMesh].append(
"void barrier();"
);
stageBuiltins[EShLangTask].append(
"void barrier();"
);
}
if ((profile != EEsProfile && version >= 130) || esBarrier)
commonBuiltins.append(
"void memoryBarrier();"
);
if ((profile != EEsProfile && version >= 420) || esBarrier) {
commonBuiltins.append(
"void memoryBarrierBuffer();"
);
stageBuiltins[EShLangCompute].append(
"void memoryBarrierShared();"
"void groupMemoryBarrier();"
);
}
if ((profile != EEsProfile && version >= 420) || esBarrier) {
if (spvVersion.vulkan == 0 || spvVersion.vulkanRelaxed) {
commonBuiltins.append("void memoryBarrierAtomicCounter();");
}
commonBuiltins.append("void memoryBarrierImage();");
}
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
stageBuiltins[EShLangMesh].append(
"void memoryBarrierShared();"
"void groupMemoryBarrier();"
);
stageBuiltins[EShLangTask].append(
"void memoryBarrierShared();"
"void groupMemoryBarrier();"
);
}
commonBuiltins.append("void controlBarrier(int, int, int, int);\n"
"void memoryBarrier(int, int, int);\n");
commonBuiltins.append("void debugPrintfEXT();\n");
if (profile != EEsProfile && version >= 450) {
// coopMatStoreNV perhaps ought to have "out" on the buf parameter, but
// adding it introduces undesirable tempArgs on the stack. What we want
// is more like "buf" thought of as a pointer value being an in parameter.
stageBuiltins[EShLangCompute].append(
"void coopMatLoadNV(out fcoopmatNV m, volatile coherent float16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out fcoopmatNV m, volatile coherent float[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out fcoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out fcoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out fcoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(fcoopmatNV m, volatile coherent float16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(fcoopmatNV m, volatile coherent float[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(fcoopmatNV m, volatile coherent float64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(fcoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(fcoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(fcoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(fcoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(fcoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(fcoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
"fcoopmatNV coopMatMulAddNV(fcoopmatNV A, fcoopmatNV B, fcoopmatNV C);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out icoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatLoadNV(out ucoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(icoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent int8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent int16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent int[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent int64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent ivec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent ivec4[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent uint8_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent uint16_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent uint[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent uint64_t[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent uvec2[] buf, uint element, uint stride, bool colMajor);\n"
"void coopMatStoreNV(ucoopmatNV m, volatile coherent uvec4[] buf, uint element, uint stride, bool colMajor);\n"
"icoopmatNV coopMatMulAddNV(icoopmatNV A, icoopmatNV B, icoopmatNV C);\n"
"ucoopmatNV coopMatMulAddNV(ucoopmatNV A, ucoopmatNV B, ucoopmatNV C);\n"
);
std::string cooperativeMatrixFuncs =
"void coopMatLoad(out coopmat m, volatile coherent int8_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent int16_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent int32_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent int64_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent uint8_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent uint16_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent uint32_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent uint64_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent float16_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent float[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent float64_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent i8vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent i16vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent i32vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent i64vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent u8vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent u16vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent u32vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent u64vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent f16vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent f32vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent f64vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent i8vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent i16vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent i32vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent i64vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent u8vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent u16vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent u32vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent u64vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent f16vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent f32vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatLoad(out coopmat m, volatile coherent f64vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent int8_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent int16_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent int32_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent int64_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent uint8_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent uint16_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent uint32_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent uint64_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent float16_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent float[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent float64_t[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent i8vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent i16vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent i32vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent i64vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent u8vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent u16vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent u32vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent u64vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent f16vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent f32vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent f64vec2[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent i8vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent i16vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent i32vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent i64vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent u8vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent u16vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent u32vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent u64vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent f16vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent f32vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"void coopMatStore(coopmat m, volatile coherent f64vec4[] buf, uint element, uint stride, int matrixLayout);\n"
"coopmat coopMatMulAdd(coopmat A, coopmat B, coopmat C);\n"
"coopmat coopMatMulAdd(coopmat A, coopmat B, coopmat C, int matrixOperands);\n";
commonBuiltins.append(cooperativeMatrixFuncs.c_str());
commonBuiltins.append(
"const int gl_MatrixUseA = 0;\n"
"const int gl_MatrixUseB = 1;\n"
"const int gl_MatrixUseAccumulator = 2;\n"
"const int gl_MatrixOperandsSaturatingAccumulation = 0x10;\n"
"const int gl_CooperativeMatrixLayoutRowMajor = 0;\n"
"const int gl_CooperativeMatrixLayoutColumnMajor = 1;\n"
"const int gl_CooperativeMatrixLayoutRowBlockedInterleavedARM = 4202;\n"
"const int gl_CooperativeMatrixLayoutColumnBlockedInterleavedARM = 4203;\n"
"\n"
);
}
//============================================================================
//
// Prototypes for built-in functions seen by fragment shaders only.
//
//============================================================================
//
// Original-style texture Functions with bias.
//
if (spvVersion.spv == 0 && (profile != EEsProfile || version == 100)) {
stageBuiltins[EShLangFragment].append(
"vec4 texture2D(sampler2D, vec2, float);"
"vec4 texture2DProj(sampler2D, vec3, float);"
"vec4 texture2DProj(sampler2D, vec4, float);"
"vec4 texture3D(sampler3D, vec3, float);" // OES_texture_3D
"vec4 texture3DProj(sampler3D, vec4, float);" // OES_texture_3D
"vec4 textureCube(samplerCube, vec3, float);"
"\n");
}
if (spvVersion.spv == 0 && (profile != EEsProfile && version > 100)) {
stageBuiltins[EShLangFragment].append(
"vec4 texture1D(sampler1D, float, float);"
"vec4 texture1DProj(sampler1D, vec2, float);"
"vec4 texture1DProj(sampler1D, vec4, float);"
"vec4 shadow1D(sampler1DShadow, vec3, float);"
"vec4 shadow2D(sampler2DShadow, vec3, float);"
"vec4 shadow1DProj(sampler1DShadow, vec4, float);"
"vec4 shadow2DProj(sampler2DShadow, vec4, float);"
"\n");
}
if (spvVersion.spv == 0 && profile == EEsProfile) {
stageBuiltins[EShLangFragment].append(
"vec4 texture2DLodEXT(sampler2D, vec2, float);" // GL_EXT_shader_texture_lod
"vec4 texture2DProjLodEXT(sampler2D, vec3, float);" // GL_EXT_shader_texture_lod
"vec4 texture2DProjLodEXT(sampler2D, vec4, float);" // GL_EXT_shader_texture_lod
"vec4 textureCubeLodEXT(samplerCube, vec3, float);" // GL_EXT_shader_texture_lod
"\n");
}
// GL_EXT_shader_tile_image
if (spvVersion.vulkan > 0) {
stageBuiltins[EShLangFragment].append(
"lowp uint stencilAttachmentReadEXT();"
"lowp uint stencilAttachmentReadEXT(int);"
"highp float depthAttachmentReadEXT();"
"highp float depthAttachmentReadEXT(int);"
"\n");
stageBuiltins[EShLangFragment].append(
"vec4 colorAttachmentReadEXT(attachmentEXT);"
"vec4 colorAttachmentReadEXT(attachmentEXT, int);"
"ivec4 colorAttachmentReadEXT(iattachmentEXT);"
"ivec4 colorAttachmentReadEXT(iattachmentEXT, int);"
"uvec4 colorAttachmentReadEXT(uattachmentEXT);"
"uvec4 colorAttachmentReadEXT(uattachmentEXT, int);"
"\n");
}
// GL_ARB_derivative_control
if (profile != EEsProfile && version >= 400) {
stageBuiltins[EShLangFragment].append(derivativeControls);
stageBuiltins[EShLangFragment].append("\n");
}
// GL_OES_shader_multisample_interpolation
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 400)) {
stageBuiltins[EShLangFragment].append(
"float interpolateAtCentroid(float);"
"vec2 interpolateAtCentroid(vec2);"
"vec3 interpolateAtCentroid(vec3);"
"vec4 interpolateAtCentroid(vec4);"
"float interpolateAtSample(float, int);"
"vec2 interpolateAtSample(vec2, int);"
"vec3 interpolateAtSample(vec3, int);"
"vec4 interpolateAtSample(vec4, int);"
"float interpolateAtOffset(float, vec2);"
"vec2 interpolateAtOffset(vec2, vec2);"
"vec3 interpolateAtOffset(vec3, vec2);"
"vec4 interpolateAtOffset(vec4, vec2);"
"\n");
}
stageBuiltins[EShLangFragment].append(
"void beginInvocationInterlockARB(void);"
"void endInvocationInterlockARB(void);");
stageBuiltins[EShLangFragment].append(
"bool helperInvocationEXT();"
"\n");
// GL_AMD_shader_explicit_vertex_parameter
if (profile != EEsProfile && version >= 450) {
stageBuiltins[EShLangFragment].append(
"float interpolateAtVertexAMD(float, uint);"
"vec2 interpolateAtVertexAMD(vec2, uint);"
"vec3 interpolateAtVertexAMD(vec3, uint);"
"vec4 interpolateAtVertexAMD(vec4, uint);"
"int interpolateAtVertexAMD(int, uint);"
"ivec2 interpolateAtVertexAMD(ivec2, uint);"
"ivec3 interpolateAtVertexAMD(ivec3, uint);"
"ivec4 interpolateAtVertexAMD(ivec4, uint);"
"uint interpolateAtVertexAMD(uint, uint);"
"uvec2 interpolateAtVertexAMD(uvec2, uint);"
"uvec3 interpolateAtVertexAMD(uvec3, uint);"
"uvec4 interpolateAtVertexAMD(uvec4, uint);"
"float16_t interpolateAtVertexAMD(float16_t, uint);"
"f16vec2 interpolateAtVertexAMD(f16vec2, uint);"
"f16vec3 interpolateAtVertexAMD(f16vec3, uint);"
"f16vec4 interpolateAtVertexAMD(f16vec4, uint);"
"\n");
}
// GL_AMD_gpu_shader_half_float
if (profile != EEsProfile && version >= 450) {
stageBuiltins[EShLangFragment].append(derivativesAndControl16bits);
stageBuiltins[EShLangFragment].append("\n");
stageBuiltins[EShLangFragment].append(
"float16_t interpolateAtCentroid(float16_t);"
"f16vec2 interpolateAtCentroid(f16vec2);"
"f16vec3 interpolateAtCentroid(f16vec3);"
"f16vec4 interpolateAtCentroid(f16vec4);"
"float16_t interpolateAtSample(float16_t, int);"
"f16vec2 interpolateAtSample(f16vec2, int);"
"f16vec3 interpolateAtSample(f16vec3, int);"
"f16vec4 interpolateAtSample(f16vec4, int);"
"float16_t interpolateAtOffset(float16_t, f16vec2);"
"f16vec2 interpolateAtOffset(f16vec2, f16vec2);"
"f16vec3 interpolateAtOffset(f16vec3, f16vec2);"
"f16vec4 interpolateAtOffset(f16vec4, f16vec2);"
"\n");
}
// GL_ARB_shader_clock& GL_EXT_shader_realtime_clock
if (profile != EEsProfile && version >= 450) {
commonBuiltins.append(
"uvec2 clock2x32ARB();"
"uint64_t clockARB();"
"uvec2 clockRealtime2x32EXT();"
"uint64_t clockRealtimeEXT();"
"\n");
}
// GL_AMD_shader_fragment_mask
if (profile != EEsProfile && version >= 450 && spvVersion.vulkan > 0) {
stageBuiltins[EShLangFragment].append(
"uint fragmentMaskFetchAMD(subpassInputMS);"
"uint fragmentMaskFetchAMD(isubpassInputMS);"
"uint fragmentMaskFetchAMD(usubpassInputMS);"
"vec4 fragmentFetchAMD(subpassInputMS, uint);"
"ivec4 fragmentFetchAMD(isubpassInputMS, uint);"
"uvec4 fragmentFetchAMD(usubpassInputMS, uint);"
"\n");
}
// Builtins for GL_NV_ray_tracing/GL_NV_ray_tracing_motion_blur/GL_EXT_ray_tracing/GL_EXT_ray_query/
// GL_NV_shader_invocation_reorder/GL_KHR_ray_tracing_position_Fetch
if (profile != EEsProfile && version >= 460) {
commonBuiltins.append("void rayQueryInitializeEXT(rayQueryEXT, accelerationStructureEXT, uint, uint, vec3, float, vec3, float);"
"void rayQueryTerminateEXT(rayQueryEXT);"
"void rayQueryGenerateIntersectionEXT(rayQueryEXT, float);"
"void rayQueryConfirmIntersectionEXT(rayQueryEXT);"
"bool rayQueryProceedEXT(rayQueryEXT);"
"uint rayQueryGetIntersectionTypeEXT(rayQueryEXT, bool);"
"float rayQueryGetRayTMinEXT(rayQueryEXT);"
"uint rayQueryGetRayFlagsEXT(rayQueryEXT);"
"vec3 rayQueryGetWorldRayOriginEXT(rayQueryEXT);"
"vec3 rayQueryGetWorldRayDirectionEXT(rayQueryEXT);"
"float rayQueryGetIntersectionTEXT(rayQueryEXT, bool);"
"int rayQueryGetIntersectionInstanceCustomIndexEXT(rayQueryEXT, bool);"
"int rayQueryGetIntersectionInstanceIdEXT(rayQueryEXT, bool);"
"uint rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQueryEXT, bool);"
"int rayQueryGetIntersectionGeometryIndexEXT(rayQueryEXT, bool);"
"int rayQueryGetIntersectionPrimitiveIndexEXT(rayQueryEXT, bool);"
"vec2 rayQueryGetIntersectionBarycentricsEXT(rayQueryEXT, bool);"
"bool rayQueryGetIntersectionFrontFaceEXT(rayQueryEXT, bool);"
"bool rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQueryEXT);"
"vec3 rayQueryGetIntersectionObjectRayDirectionEXT(rayQueryEXT, bool);"
"vec3 rayQueryGetIntersectionObjectRayOriginEXT(rayQueryEXT, bool);"
"mat4x3 rayQueryGetIntersectionObjectToWorldEXT(rayQueryEXT, bool);"
"mat4x3 rayQueryGetIntersectionWorldToObjectEXT(rayQueryEXT, bool);"
"void rayQueryGetIntersectionTriangleVertexPositionsEXT(rayQueryEXT, bool, out vec3[3]);"
"\n");
stageBuiltins[EShLangRayGen].append(
"void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
"void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
"void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
"void executeCallableNV(uint, int);"
"void executeCallableEXT(uint, int);"
"void hitObjectTraceRayNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
"void hitObjectTraceRayMotionNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
"void hitObjectRecordHitNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,int);"
"void hitObjectRecordHitMotionNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,float,int);"
"void hitObjectRecordHitWithIndexNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,int);"
"void hitObjectRecordHitWithIndexMotionNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,float,int);"
"void hitObjectRecordMissNV(hitObjectNV,uint,vec3,float,vec3,float);"
"void hitObjectRecordMissMotionNV(hitObjectNV,uint,vec3,float,vec3,float,float);"
"void hitObjectRecordEmptyNV(hitObjectNV);"
"void hitObjectExecuteShaderNV(hitObjectNV,int);"
"bool hitObjectIsEmptyNV(hitObjectNV);"
"bool hitObjectIsMissNV(hitObjectNV);"
"bool hitObjectIsHitNV(hitObjectNV);"
"float hitObjectGetRayTMinNV(hitObjectNV);"
"float hitObjectGetRayTMaxNV(hitObjectNV);"
"vec3 hitObjectGetWorldRayOriginNV(hitObjectNV);"
"vec3 hitObjectGetWorldRayDirectionNV(hitObjectNV);"
"vec3 hitObjectGetObjectRayOriginNV(hitObjectNV);"
"vec3 hitObjectGetObjectRayDirectionNV(hitObjectNV);"
"mat4x3 hitObjectGetWorldToObjectNV(hitObjectNV);"
"mat4x3 hitObjectGetObjectToWorldNV(hitObjectNV);"
"int hitObjectGetInstanceCustomIndexNV(hitObjectNV);"
"int hitObjectGetInstanceIdNV(hitObjectNV);"
"int hitObjectGetGeometryIndexNV(hitObjectNV);"
"int hitObjectGetPrimitiveIndexNV(hitObjectNV);"
"uint hitObjectGetHitKindNV(hitObjectNV);"
"void hitObjectGetAttributesNV(hitObjectNV,int);"
"float hitObjectGetCurrentTimeNV(hitObjectNV);"
"uint hitObjectGetShaderBindingTableRecordIndexNV(hitObjectNV);"
"uvec2 hitObjectGetShaderRecordBufferHandleNV(hitObjectNV);"
"void reorderThreadNV(uint, uint);"
"void reorderThreadNV(hitObjectNV);"
"void reorderThreadNV(hitObjectNV, uint, uint);"
"vec3 fetchMicroTriangleVertexPositionNV(accelerationStructureEXT, int, int, int, ivec2);"
"vec2 fetchMicroTriangleVertexBarycentricNV(accelerationStructureEXT, int, int, int, ivec2);"
"\n");
stageBuiltins[EShLangIntersect].append(
"bool reportIntersectionNV(float, uint);"
"bool reportIntersectionEXT(float, uint);"
"\n");
stageBuiltins[EShLangAnyHit].append(
"void ignoreIntersectionNV();"
"void terminateRayNV();"
"\n");
stageBuiltins[EShLangClosestHit].append(
"void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
"void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
"void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
"void executeCallableNV(uint, int);"
"void executeCallableEXT(uint, int);"
"void hitObjectTraceRayNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
"void hitObjectTraceRayMotionNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
"void hitObjectRecordHitNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,int);"
"void hitObjectRecordHitMotionNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,float,int);"
"void hitObjectRecordHitWithIndexNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,int);"
"void hitObjectRecordHitWithIndexMotionNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,float,int);"
"void hitObjectRecordMissNV(hitObjectNV, uint, vec3, float, vec3, float);"
"void hitObjectRecordMissMotionNV(hitObjectNV,uint,vec3,float,vec3,float,float);"
"void hitObjectRecordEmptyNV(hitObjectNV);"
"void hitObjectExecuteShaderNV(hitObjectNV, int);"
"bool hitObjectIsEmptyNV(hitObjectNV);"
"bool hitObjectIsMissNV(hitObjectNV);"
"bool hitObjectIsHitNV(hitObjectNV);"
"float hitObjectGetRayTMinNV(hitObjectNV);"
"float hitObjectGetRayTMaxNV(hitObjectNV);"
"vec3 hitObjectGetWorldRayOriginNV(hitObjectNV);"
"vec3 hitObjectGetWorldRayDirectionNV(hitObjectNV);"
"vec3 hitObjectGetObjectRayOriginNV(hitObjectNV);"
"vec3 hitObjectGetObjectRayDirectionNV(hitObjectNV);"
"mat4x3 hitObjectGetWorldToObjectNV(hitObjectNV);"
"mat4x3 hitObjectGetObjectToWorldNV(hitObjectNV);"
"int hitObjectGetInstanceCustomIndexNV(hitObjectNV);"
"int hitObjectGetInstanceIdNV(hitObjectNV);"
"int hitObjectGetGeometryIndexNV(hitObjectNV);"
"int hitObjectGetPrimitiveIndexNV(hitObjectNV);"
"uint hitObjectGetHitKindNV(hitObjectNV);"
"void hitObjectGetAttributesNV(hitObjectNV,int);"
"float hitObjectGetCurrentTimeNV(hitObjectNV);"
"uint hitObjectGetShaderBindingTableRecordIndexNV(hitObjectNV);"
"uvec2 hitObjectGetShaderRecordBufferHandleNV(hitObjectNV);"
"\n");
stageBuiltins[EShLangMiss].append(
"void traceNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
"void traceRayMotionNV(accelerationStructureNV,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
"void traceRayEXT(accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
"void executeCallableNV(uint, int);"
"void executeCallableEXT(uint, int);"
"void hitObjectTraceRayNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,int);"
"void hitObjectTraceRayMotionNV(hitObjectNV,accelerationStructureEXT,uint,uint,uint,uint,uint,vec3,float,vec3,float,float,int);"
"void hitObjectRecordHitNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,int);"
"void hitObjectRecordHitMotionNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,float,int);"
"void hitObjectRecordHitWithIndexNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,int);"
"void hitObjectRecordHitWithIndexMotionNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,float,int);"
"void hitObjectRecordMissNV(hitObjectNV, uint, vec3, float, vec3, float);"
"void hitObjectRecordMissMotionNV(hitObjectNV,uint,vec3,float,vec3,float,float);"
"void hitObjectRecordEmptyNV(hitObjectNV);"
"void hitObjectExecuteShaderNV(hitObjectNV, int);"
"bool hitObjectIsEmptyNV(hitObjectNV);"
"bool hitObjectIsMissNV(hitObjectNV);"
"bool hitObjectIsHitNV(hitObjectNV);"
"float hitObjectGetRayTMinNV(hitObjectNV);"
"float hitObjectGetRayTMaxNV(hitObjectNV);"
"vec3 hitObjectGetWorldRayOriginNV(hitObjectNV);"
"vec3 hitObjectGetWorldRayDirectionNV(hitObjectNV);"
"vec3 hitObjectGetObjectRayOriginNV(hitObjectNV);"
"vec3 hitObjectGetObjectRayDirectionNV(hitObjectNV);"
"mat4x3 hitObjectGetWorldToObjectNV(hitObjectNV);"
"mat4x3 hitObjectGetObjectToWorldNV(hitObjectNV);"
"int hitObjectGetInstanceCustomIndexNV(hitObjectNV);"
"int hitObjectGetInstanceIdNV(hitObjectNV);"
"int hitObjectGetGeometryIndexNV(hitObjectNV);"
"int hitObjectGetPrimitiveIndexNV(hitObjectNV);"
"uint hitObjectGetHitKindNV(hitObjectNV);"
"void hitObjectGetAttributesNV(hitObjectNV,int);"
"float hitObjectGetCurrentTimeNV(hitObjectNV);"
"uint hitObjectGetShaderBindingTableRecordIndexNV(hitObjectNV);"
"uvec2 hitObjectGetShaderRecordBufferHandleNV(hitObjectNV);"
"\n");
stageBuiltins[EShLangCallable].append(
"void executeCallableNV(uint, int);"
"void executeCallableEXT(uint, int);"
"\n");
}
//E_SPV_NV_compute_shader_derivatives
if ((profile == EEsProfile && version >= 320) || (profile != EEsProfile && version >= 450)) {
stageBuiltins[EShLangCompute].append(derivativeControls);
stageBuiltins[EShLangCompute].append("\n");
}
if (profile != EEsProfile && version >= 450) {
stageBuiltins[EShLangCompute].append(derivativesAndControl16bits);
stageBuiltins[EShLangCompute].append(derivativesAndControl64bits);
stageBuiltins[EShLangCompute].append("\n");
}
// Builtins for GL_NV_mesh_shader
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
stageBuiltins[EShLangMesh].append(
"void writePackedPrimitiveIndices4x8NV(uint, uint);"
"\n");
}
// Builtins for GL_EXT_mesh_shader
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
// Builtins for GL_EXT_mesh_shader
stageBuiltins[EShLangTask].append(
"void EmitMeshTasksEXT(uint, uint, uint);"
"\n");
stageBuiltins[EShLangMesh].append(
"void SetMeshOutputsEXT(uint, uint);"
"\n");
}
// Builtins for GL_NV_displacement_micromap
if ((profile != EEsProfile && version >= 460) || (profile == EEsProfile && version >= 320)) {
stageBuiltins[EShLangMesh].append(
"vec3 fetchMicroTriangleVertexPositionNV(accelerationStructureEXT, int, int, int, ivec2);"
"vec2 fetchMicroTriangleVertexBarycentricNV(accelerationStructureEXT, int, int, int, ivec2);"
"\n");
stageBuiltins[EShLangCompute].append(
"vec3 fetchMicroTriangleVertexPositionNV(accelerationStructureEXT, int, int, int, ivec2);"
"vec2 fetchMicroTriangleVertexBarycentricNV(accelerationStructureEXT, int, int, int, ivec2);"
"\n");
}
//============================================================================
//
// Standard Uniforms
//
//============================================================================
//
// Depth range in window coordinates, p. 33
//
if (spvVersion.spv == 0) {
commonBuiltins.append(
"struct gl_DepthRangeParameters {"
);
if (profile == EEsProfile) {
commonBuiltins.append(
"highp float near;" // n
"highp float far;" // f
"highp float diff;" // f - n
);
} else {
commonBuiltins.append(
"float near;" // n
"float far;" // f
"float diff;" // f - n
);
}
commonBuiltins.append(
"};"
"uniform gl_DepthRangeParameters gl_DepthRange;"
"\n");
}
if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) {
//
// Matrix state. p. 31, 32, 37, 39, 40.
//
commonBuiltins.append(
"uniform mat4 gl_ModelViewMatrix;"
"uniform mat4 gl_ProjectionMatrix;"
"uniform mat4 gl_ModelViewProjectionMatrix;"
//
// Derived matrix state that provides inverse and transposed versions
// of the matrices above.
//
"uniform mat3 gl_NormalMatrix;"
"uniform mat4 gl_ModelViewMatrixInverse;"
"uniform mat4 gl_ProjectionMatrixInverse;"
"uniform mat4 gl_ModelViewProjectionMatrixInverse;"
"uniform mat4 gl_ModelViewMatrixTranspose;"
"uniform mat4 gl_ProjectionMatrixTranspose;"
"uniform mat4 gl_ModelViewProjectionMatrixTranspose;"
"uniform mat4 gl_ModelViewMatrixInverseTranspose;"
"uniform mat4 gl_ProjectionMatrixInverseTranspose;"
"uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;"
//
// Normal scaling p. 39.
//
"uniform float gl_NormalScale;"
//
// Point Size, p. 66, 67.
//
"struct gl_PointParameters {"
"float size;"
"float sizeMin;"
"float sizeMax;"
"float fadeThresholdSize;"
"float distanceConstantAttenuation;"
"float distanceLinearAttenuation;"
"float distanceQuadraticAttenuation;"
"};"
"uniform gl_PointParameters gl_Point;"
//
// Material State p. 50, 55.
//
"struct gl_MaterialParameters {"
"vec4 emission;" // Ecm
"vec4 ambient;" // Acm
"vec4 diffuse;" // Dcm
"vec4 specular;" // Scm
"float shininess;" // Srm
"};"
"uniform gl_MaterialParameters gl_FrontMaterial;"
"uniform gl_MaterialParameters gl_BackMaterial;"
//
// Light State p 50, 53, 55.
//
"struct gl_LightSourceParameters {"
"vec4 ambient;" // Acli
"vec4 diffuse;" // Dcli
"vec4 specular;" // Scli
"vec4 position;" // Ppli
"vec4 halfVector;" // Derived: Hi
"vec3 spotDirection;" // Sdli
"float spotExponent;" // Srli
"float spotCutoff;" // Crli
// (range: [0.0,90.0], 180.0)
"float spotCosCutoff;" // Derived: cos(Crli)
// (range: [1.0,0.0],-1.0)
"float constantAttenuation;" // K0
"float linearAttenuation;" // K1
"float quadraticAttenuation;"// K2
"};"
"struct gl_LightModelParameters {"
"vec4 ambient;" // Acs
"};"
"uniform gl_LightModelParameters gl_LightModel;"
//
// Derived state from products of light and material.
//
"struct gl_LightModelProducts {"
"vec4 sceneColor;" // Derived. Ecm + Acm * Acs
"};"
"uniform gl_LightModelProducts gl_FrontLightModelProduct;"
"uniform gl_LightModelProducts gl_BackLightModelProduct;"
"struct gl_LightProducts {"
"vec4 ambient;" // Acm * Acli
"vec4 diffuse;" // Dcm * Dcli
"vec4 specular;" // Scm * Scli
"};"
//
// Fog p. 161
//
"struct gl_FogParameters {"
"vec4 color;"
"float density;"
"float start;"
"float end;"
"float scale;" // 1 / (gl_FogEnd - gl_FogStart)
"};"
"uniform gl_FogParameters gl_Fog;"
"\n");
}
//============================================================================
//
// Define the interface to the compute shader.
//
//============================================================================
if ((profile != EEsProfile && version >= 420) ||
(profile == EEsProfile && version >= 310)) {
stageBuiltins[EShLangCompute].append(
"in highp uvec3 gl_NumWorkGroups;"
"const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
"in highp uvec3 gl_WorkGroupID;"
"in highp uvec3 gl_LocalInvocationID;"
"in highp uvec3 gl_GlobalInvocationID;"
"in highp uint gl_LocalInvocationIndex;"
"\n");
}
if ((profile != EEsProfile && version >= 140) ||
(profile == EEsProfile && version >= 310)) {
stageBuiltins[EShLangCompute].append(
"in highp int gl_DeviceIndex;" // GL_EXT_device_group
"\n");
}
//============================================================================
//
// Define the interface to the mesh/task shader.
//
//============================================================================
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
// per-vertex attributes
stageBuiltins[EShLangMesh].append(
"out gl_MeshPerVertexNV {"
"vec4 gl_Position;"
"float gl_PointSize;"
"float gl_ClipDistance[];"
"float gl_CullDistance[];"
"perviewNV vec4 gl_PositionPerViewNV[];"
"perviewNV float gl_ClipDistancePerViewNV[][];"
"perviewNV float gl_CullDistancePerViewNV[][];"
"} gl_MeshVerticesNV[];"
);
// per-primitive attributes
stageBuiltins[EShLangMesh].append(
"perprimitiveNV out gl_MeshPerPrimitiveNV {"
"int gl_PrimitiveID;"
"int gl_Layer;"
"int gl_ViewportIndex;"
"int gl_ViewportMask[];"
"perviewNV int gl_LayerPerViewNV[];"
"perviewNV int gl_ViewportMaskPerViewNV[][];"
"} gl_MeshPrimitivesNV[];"
);
stageBuiltins[EShLangMesh].append(
"out uint gl_PrimitiveCountNV;"
"out uint gl_PrimitiveIndicesNV[];"
"in uint gl_MeshViewCountNV;"
"in uint gl_MeshViewIndicesNV[4];"
"const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
"in highp uvec3 gl_WorkGroupID;"
"in highp uvec3 gl_LocalInvocationID;"
"in highp uvec3 gl_GlobalInvocationID;"
"in highp uint gl_LocalInvocationIndex;"
"\n");
// GL_EXT_mesh_shader
stageBuiltins[EShLangMesh].append(
"out uint gl_PrimitivePointIndicesEXT[];"
"out uvec2 gl_PrimitiveLineIndicesEXT[];"
"out uvec3 gl_PrimitiveTriangleIndicesEXT[];"
"in highp uvec3 gl_NumWorkGroups;"
"\n");
// per-vertex attributes
stageBuiltins[EShLangMesh].append(
"out gl_MeshPerVertexEXT {"
"vec4 gl_Position;"
"float gl_PointSize;"
"float gl_ClipDistance[];"
"float gl_CullDistance[];"
"} gl_MeshVerticesEXT[];"
);
// per-primitive attributes
stageBuiltins[EShLangMesh].append(
"perprimitiveEXT out gl_MeshPerPrimitiveEXT {"
"int gl_PrimitiveID;"
"int gl_Layer;"
"int gl_ViewportIndex;"
"bool gl_CullPrimitiveEXT;"
"int gl_PrimitiveShadingRateEXT;"
"} gl_MeshPrimitivesEXT[];"
);
stageBuiltins[EShLangTask].append(
"out uint gl_TaskCountNV;"
"const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);"
"in highp uvec3 gl_WorkGroupID;"
"in highp uvec3 gl_LocalInvocationID;"
"in highp uvec3 gl_GlobalInvocationID;"
"in highp uint gl_LocalInvocationIndex;"
"in uint gl_MeshViewCountNV;"
"in uint gl_MeshViewIndicesNV[4];"
"in highp uvec3 gl_NumWorkGroups;"
"\n");
}
if (profile != EEsProfile && version >= 450) {
stageBuiltins[EShLangMesh].append(
"in highp int gl_DeviceIndex;" // GL_EXT_device_group
"in int gl_DrawIDARB;" // GL_ARB_shader_draw_parameters
"in int gl_ViewIndex;" // GL_EXT_multiview
"\n");
stageBuiltins[EShLangTask].append(
"in highp int gl_DeviceIndex;" // GL_EXT_device_group
"in int gl_DrawIDARB;" // GL_ARB_shader_draw_parameters
"\n");
if (version >= 460) {
stageBuiltins[EShLangMesh].append(
"in int gl_DrawID;"
"\n");
stageBuiltins[EShLangTask].append(
"in int gl_DrawID;"
"\n");
}
}
//============================================================================
//
// Define the interface to the vertex shader.
//
//============================================================================
if (profile != EEsProfile) {
if (version < 130) {
stageBuiltins[EShLangVertex].append(
"attribute vec4 gl_Color;"
"attribute vec4 gl_SecondaryColor;"
"attribute vec3 gl_Normal;"
"attribute vec4 gl_Vertex;"
"attribute vec4 gl_MultiTexCoord0;"
"attribute vec4 gl_MultiTexCoord1;"
"attribute vec4 gl_MultiTexCoord2;"
"attribute vec4 gl_MultiTexCoord3;"
"attribute vec4 gl_MultiTexCoord4;"
"attribute vec4 gl_MultiTexCoord5;"
"attribute vec4 gl_MultiTexCoord6;"
"attribute vec4 gl_MultiTexCoord7;"
"attribute float gl_FogCoord;"
"\n");
} else if (IncludeLegacy(version, profile, spvVersion)) {
stageBuiltins[EShLangVertex].append(
"in vec4 gl_Color;"
"in vec4 gl_SecondaryColor;"
"in vec3 gl_Normal;"
"in vec4 gl_Vertex;"
"in vec4 gl_MultiTexCoord0;"
"in vec4 gl_MultiTexCoord1;"
"in vec4 gl_MultiTexCoord2;"
"in vec4 gl_MultiTexCoord3;"
"in vec4 gl_MultiTexCoord4;"
"in vec4 gl_MultiTexCoord5;"
"in vec4 gl_MultiTexCoord6;"
"in vec4 gl_MultiTexCoord7;"
"in float gl_FogCoord;"
"\n");
}
if (version < 150) {
if (version < 130) {
stageBuiltins[EShLangVertex].append(
" vec4 gl_ClipVertex;" // needs qualifier fixed later
"varying vec4 gl_FrontColor;"
"varying vec4 gl_BackColor;"
"varying vec4 gl_FrontSecondaryColor;"
"varying vec4 gl_BackSecondaryColor;"
"varying vec4 gl_TexCoord[];"
"varying float gl_FogFragCoord;"
"\n");
} else if (IncludeLegacy(version, profile, spvVersion)) {
stageBuiltins[EShLangVertex].append(
" vec4 gl_ClipVertex;" // needs qualifier fixed later
"out vec4 gl_FrontColor;"
"out vec4 gl_BackColor;"
"out vec4 gl_FrontSecondaryColor;"
"out vec4 gl_BackSecondaryColor;"
"out vec4 gl_TexCoord[];"
"out float gl_FogFragCoord;"
"\n");
}
stageBuiltins[EShLangVertex].append(
"vec4 gl_Position;" // needs qualifier fixed later
"float gl_PointSize;" // needs qualifier fixed later
);
if (version == 130 || version == 140)
stageBuiltins[EShLangVertex].append(
"out float gl_ClipDistance[];"
);
} else {
// version >= 150
stageBuiltins[EShLangVertex].append(
"out gl_PerVertex {"
"vec4 gl_Position;" // needs qualifier fixed later
"float gl_PointSize;" // needs qualifier fixed later
"float gl_ClipDistance[];"
);
if (IncludeLegacy(version, profile, spvVersion))
stageBuiltins[EShLangVertex].append(
"vec4 gl_ClipVertex;" // needs qualifier fixed later
"vec4 gl_FrontColor;"
"vec4 gl_BackColor;"
"vec4 gl_FrontSecondaryColor;"
"vec4 gl_BackSecondaryColor;"
"vec4 gl_TexCoord[];"
"float gl_FogFragCoord;"
);
if (version >= 450)
stageBuiltins[EShLangVertex].append(
"float gl_CullDistance[];"
);
stageBuiltins[EShLangVertex].append(
"};"
"\n");
}
if (version >= 130 && spvVersion.vulkan == 0)
stageBuiltins[EShLangVertex].append(
"int gl_VertexID;" // needs qualifier fixed later
);
if (spvVersion.vulkan == 0)
stageBuiltins[EShLangVertex].append(
"int gl_InstanceID;" // needs qualifier fixed later
);
if (spvVersion.vulkan > 0 && version >= 140)
stageBuiltins[EShLangVertex].append(
"in int gl_VertexIndex;"
"in int gl_InstanceIndex;"
);
if (spvVersion.vulkan > 0 && version >= 140 && spvVersion.vulkanRelaxed)
stageBuiltins[EShLangVertex].append(
"in int gl_VertexID;" // declare with 'in' qualifier
"in int gl_InstanceID;"
);
if (version >= 440) {
stageBuiltins[EShLangVertex].append(
"in int gl_BaseVertexARB;"
"in int gl_BaseInstanceARB;"
"in int gl_DrawIDARB;"
);
}
if (version >= 410) {
stageBuiltins[EShLangVertex].append(
"out int gl_ViewportIndex;"
"out int gl_Layer;"
);
}
if (version >= 460) {
stageBuiltins[EShLangVertex].append(
"in int gl_BaseVertex;"
"in int gl_BaseInstance;"
"in int gl_DrawID;"
);
}
if (version >= 430)
stageBuiltins[EShLangVertex].append(
"out int gl_ViewportMask[];" // GL_NV_viewport_array2
);
if (version >= 450)
stageBuiltins[EShLangVertex].append(
"out int gl_SecondaryViewportMaskNV[];" // GL_NV_stereo_view_rendering
"out vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"out vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
"out int gl_ViewportMaskPerViewNV[];" // GL_NVX_multiview_per_view_attributes
);
} else {
// ES profile
if (version == 100) {
stageBuiltins[EShLangVertex].append(
"highp vec4 gl_Position;" // needs qualifier fixed later
"mediump float gl_PointSize;" // needs qualifier fixed later
"highp int gl_InstanceID;" // needs qualifier fixed later
);
} else {
if (spvVersion.vulkan == 0 || spvVersion.vulkanRelaxed)
stageBuiltins[EShLangVertex].append(
"in highp int gl_VertexID;" // needs qualifier fixed later
"in highp int gl_InstanceID;" // needs qualifier fixed later
);
if (spvVersion.vulkan > 0)
stageBuiltins[EShLangVertex].append(
"in highp int gl_VertexIndex;"
"in highp int gl_InstanceIndex;"
);
if (version < 310)
stageBuiltins[EShLangVertex].append(
"highp vec4 gl_Position;" // needs qualifier fixed later
"highp float gl_PointSize;" // needs qualifier fixed later
);
else
stageBuiltins[EShLangVertex].append(
"out gl_PerVertex {"
"highp vec4 gl_Position;" // needs qualifier fixed later
"highp float gl_PointSize;" // needs qualifier fixed later
"};"
);
}
}
if ((profile != EEsProfile && version >= 140) ||
(profile == EEsProfile && version >= 310)) {
stageBuiltins[EShLangVertex].append(
"in highp int gl_DeviceIndex;" // GL_EXT_device_group
"in highp int gl_ViewIndex;" // GL_EXT_multiview
"\n");
}
if (version >= 300 /* both ES and non-ES */) {
stageBuiltins[EShLangVertex].append(
"in highp uint gl_ViewID_OVR;" // GL_OVR_multiview, GL_OVR_multiview2
"\n");
}
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
stageBuiltins[EShLangVertex].append(
"out highp int gl_PrimitiveShadingRateEXT;" // GL_EXT_fragment_shading_rate
"\n");
}
//============================================================================
//
// Define the interface to the geometry shader.
//
//============================================================================
if (profile == ECoreProfile || profile == ECompatibilityProfile) {
stageBuiltins[EShLangGeometry].append(
"in gl_PerVertex {"
"vec4 gl_Position;"
"float gl_PointSize;"
"float gl_ClipDistance[];"
);
if (profile == ECompatibilityProfile)
stageBuiltins[EShLangGeometry].append(
"vec4 gl_ClipVertex;"
"vec4 gl_FrontColor;"
"vec4 gl_BackColor;"
"vec4 gl_FrontSecondaryColor;"
"vec4 gl_BackSecondaryColor;"
"vec4 gl_TexCoord[];"
"float gl_FogFragCoord;"
);
if (version >= 450)
stageBuiltins[EShLangGeometry].append(
"float gl_CullDistance[];"
"vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
);
stageBuiltins[EShLangGeometry].append(
"} gl_in[];"
"in int gl_PrimitiveIDIn;"
"out gl_PerVertex {"
"vec4 gl_Position;"
"float gl_PointSize;"
"float gl_ClipDistance[];"
"\n");
if (profile == ECompatibilityProfile && version >= 400)
stageBuiltins[EShLangGeometry].append(
"vec4 gl_ClipVertex;"
"vec4 gl_FrontColor;"
"vec4 gl_BackColor;"
"vec4 gl_FrontSecondaryColor;"
"vec4 gl_BackSecondaryColor;"
"vec4 gl_TexCoord[];"
"float gl_FogFragCoord;"
);
if (version >= 450)
stageBuiltins[EShLangGeometry].append(
"float gl_CullDistance[];"
);
stageBuiltins[EShLangGeometry].append(
"};"
"out int gl_PrimitiveID;"
"out int gl_Layer;");
if (version >= 150)
stageBuiltins[EShLangGeometry].append(
"out int gl_ViewportIndex;"
);
if (profile == ECompatibilityProfile && version < 400)
stageBuiltins[EShLangGeometry].append(
"out vec4 gl_ClipVertex;"
);
if (version >= 400)
stageBuiltins[EShLangGeometry].append(
"in int gl_InvocationID;"
);
if (version >= 430)
stageBuiltins[EShLangGeometry].append(
"out int gl_ViewportMask[];" // GL_NV_viewport_array2
);
if (version >= 450)
stageBuiltins[EShLangGeometry].append(
"out int gl_SecondaryViewportMaskNV[];" // GL_NV_stereo_view_rendering
"out vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"out vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
"out int gl_ViewportMaskPerViewNV[];" // GL_NVX_multiview_per_view_attributes
);
stageBuiltins[EShLangGeometry].append("\n");
} else if (profile == EEsProfile && version >= 310) {
stageBuiltins[EShLangGeometry].append(
"in gl_PerVertex {"
"highp vec4 gl_Position;"
"highp float gl_PointSize;"
"} gl_in[];"
"\n"
"in highp int gl_PrimitiveIDIn;"
"in highp int gl_InvocationID;"
"\n"
"out gl_PerVertex {"
"highp vec4 gl_Position;"
"highp float gl_PointSize;"
"};"
"\n"
"out highp int gl_PrimitiveID;"
"out highp int gl_Layer;"
"\n"
);
}
if ((profile != EEsProfile && version >= 140) ||
(profile == EEsProfile && version >= 310)) {
stageBuiltins[EShLangGeometry].append(
"in highp int gl_DeviceIndex;" // GL_EXT_device_group
"in highp int gl_ViewIndex;" // GL_EXT_multiview
"\n");
}
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
stageBuiltins[EShLangGeometry].append(
"out highp int gl_PrimitiveShadingRateEXT;" // GL_EXT_fragment_shading_rate
"\n");
}
//============================================================================
//
// Define the interface to the tessellation control shader.
//
//============================================================================
if (profile != EEsProfile && version >= 150) {
// Note: "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
// as it depends on the resource sizing of gl_MaxPatchVertices.
stageBuiltins[EShLangTessControl].append(
"in int gl_PatchVerticesIn;"
"in int gl_PrimitiveID;"
"in int gl_InvocationID;"
"out gl_PerVertex {"
"vec4 gl_Position;"
"float gl_PointSize;"
"float gl_ClipDistance[];"
);
if (profile == ECompatibilityProfile)
stageBuiltins[EShLangTessControl].append(
"vec4 gl_ClipVertex;"
"vec4 gl_FrontColor;"
"vec4 gl_BackColor;"
"vec4 gl_FrontSecondaryColor;"
"vec4 gl_BackSecondaryColor;"
"vec4 gl_TexCoord[];"
"float gl_FogFragCoord;"
);
if (version >= 450)
stageBuiltins[EShLangTessControl].append(
"float gl_CullDistance[];"
);
if (version >= 430)
stageBuiltins[EShLangTessControl].append(
"int gl_ViewportMask[];" // GL_NV_viewport_array2
);
if (version >= 450)
stageBuiltins[EShLangTessControl].append(
"vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"int gl_SecondaryViewportMaskNV[];" // GL_NV_stereo_view_rendering
"vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
"int gl_ViewportMaskPerViewNV[];" // GL_NVX_multiview_per_view_attributes
);
stageBuiltins[EShLangTessControl].append(
"} gl_out[];"
"patch out float gl_TessLevelOuter[4];"
"patch out float gl_TessLevelInner[2];"
"\n");
if (version >= 410)
stageBuiltins[EShLangTessControl].append(
"out int gl_ViewportIndex;"
"out int gl_Layer;"
"\n");
} else {
// Note: "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
// as it depends on the resource sizing of gl_MaxPatchVertices.
stageBuiltins[EShLangTessControl].append(
"in highp int gl_PatchVerticesIn;"
"in highp int gl_PrimitiveID;"
"in highp int gl_InvocationID;"
"out gl_PerVertex {"
"highp vec4 gl_Position;"
"highp float gl_PointSize;"
);
stageBuiltins[EShLangTessControl].append(
"} gl_out[];"
"patch out highp float gl_TessLevelOuter[4];"
"patch out highp float gl_TessLevelInner[2];"
"patch out highp vec4 gl_BoundingBoxOES[2];"
"patch out highp vec4 gl_BoundingBoxEXT[2];"
"\n");
if (profile == EEsProfile && version >= 320) {
stageBuiltins[EShLangTessControl].append(
"patch out highp vec4 gl_BoundingBox[2];"
"\n"
);
}
}
if ((profile != EEsProfile && version >= 140) ||
(profile == EEsProfile && version >= 310)) {
stageBuiltins[EShLangTessControl].append(
"in highp int gl_DeviceIndex;" // GL_EXT_device_group
"in highp int gl_ViewIndex;" // GL_EXT_multiview
"\n");
}
//============================================================================
//
// Define the interface to the tessellation evaluation shader.
//
//============================================================================
if (profile != EEsProfile && version >= 150) {
// Note: "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
// as it depends on the resource sizing of gl_MaxPatchVertices.
stageBuiltins[EShLangTessEvaluation].append(
"in int gl_PatchVerticesIn;"
"in int gl_PrimitiveID;"
"in vec3 gl_TessCoord;"
"patch in float gl_TessLevelOuter[4];"
"patch in float gl_TessLevelInner[2];"
"out gl_PerVertex {"
"vec4 gl_Position;"
"float gl_PointSize;"
"float gl_ClipDistance[];"
);
if (version >= 400 && profile == ECompatibilityProfile)
stageBuiltins[EShLangTessEvaluation].append(
"vec4 gl_ClipVertex;"
"vec4 gl_FrontColor;"
"vec4 gl_BackColor;"
"vec4 gl_FrontSecondaryColor;"
"vec4 gl_BackSecondaryColor;"
"vec4 gl_TexCoord[];"
"float gl_FogFragCoord;"
);
if (version >= 450)
stageBuiltins[EShLangTessEvaluation].append(
"float gl_CullDistance[];"
);
stageBuiltins[EShLangTessEvaluation].append(
"};"
"\n");
if (version >= 410)
stageBuiltins[EShLangTessEvaluation].append(
"out int gl_ViewportIndex;"
"out int gl_Layer;"
"\n");
if (version >= 430)
stageBuiltins[EShLangTessEvaluation].append(
"out int gl_ViewportMask[];" // GL_NV_viewport_array2
);
if (version >= 450)
stageBuiltins[EShLangTessEvaluation].append(
"out vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"out int gl_SecondaryViewportMaskNV[];" // GL_NV_stereo_view_rendering
"out vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
"out int gl_ViewportMaskPerViewNV[];" // GL_NVX_multiview_per_view_attributes
);
} else if (profile == EEsProfile && version >= 310) {
// Note: "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below,
// as it depends on the resource sizing of gl_MaxPatchVertices.
stageBuiltins[EShLangTessEvaluation].append(
"in highp int gl_PatchVerticesIn;"
"in highp int gl_PrimitiveID;"
"in highp vec3 gl_TessCoord;"
"patch in highp float gl_TessLevelOuter[4];"
"patch in highp float gl_TessLevelInner[2];"
"out gl_PerVertex {"
"highp vec4 gl_Position;"
"highp float gl_PointSize;"
);
stageBuiltins[EShLangTessEvaluation].append(
"};"
"\n");
}
if ((profile != EEsProfile && version >= 140) ||
(profile == EEsProfile && version >= 310)) {
stageBuiltins[EShLangTessEvaluation].append(
"in highp int gl_DeviceIndex;" // GL_EXT_device_group
"in highp int gl_ViewIndex;" // GL_EXT_multiview
"\n");
}
//============================================================================
//
// Define the interface to the fragment shader.
//
//============================================================================
if (profile != EEsProfile) {
stageBuiltins[EShLangFragment].append(
"vec4 gl_FragCoord;" // needs qualifier fixed later
"bool gl_FrontFacing;" // needs qualifier fixed later
"float gl_FragDepth;" // needs qualifier fixed later
);
if (version >= 120)
stageBuiltins[EShLangFragment].append(
"vec2 gl_PointCoord;" // needs qualifier fixed later
);
if (version >= 140)
stageBuiltins[EShLangFragment].append(
"out int gl_FragStencilRefARB;"
);
if (IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && version < 420))
stageBuiltins[EShLangFragment].append(
"vec4 gl_FragColor;" // needs qualifier fixed later
);
if (version < 130) {
stageBuiltins[EShLangFragment].append(
"varying vec4 gl_Color;"
"varying vec4 gl_SecondaryColor;"
"varying vec4 gl_TexCoord[];"
"varying float gl_FogFragCoord;"
);
} else {
stageBuiltins[EShLangFragment].append(
"in float gl_ClipDistance[];"
);
if (IncludeLegacy(version, profile, spvVersion)) {
if (version < 150)
stageBuiltins[EShLangFragment].append(
"in float gl_FogFragCoord;"
"in vec4 gl_TexCoord[];"
"in vec4 gl_Color;"
"in vec4 gl_SecondaryColor;"
);
else
stageBuiltins[EShLangFragment].append(
"in gl_PerFragment {"
"in float gl_FogFragCoord;"
"in vec4 gl_TexCoord[];"
"in vec4 gl_Color;"
"in vec4 gl_SecondaryColor;"
"};"
);
}
}
if (version >= 150)
stageBuiltins[EShLangFragment].append(
"flat in int gl_PrimitiveID;"
);
if (version >= 130) { // ARB_sample_shading
stageBuiltins[EShLangFragment].append(
"flat in int gl_SampleID;"
" in vec2 gl_SamplePosition;"
" out int gl_SampleMask[];"
);
if (spvVersion.spv == 0) {
stageBuiltins[EShLangFragment].append(
"uniform int gl_NumSamples;"
);
}
}
if (version >= 400)
stageBuiltins[EShLangFragment].append(
"flat in int gl_SampleMaskIn[];"
);
if (version >= 430)
stageBuiltins[EShLangFragment].append(
"flat in int gl_Layer;"
"flat in int gl_ViewportIndex;"
);
if (version >= 450)
stageBuiltins[EShLangFragment].append(
"in float gl_CullDistance[];"
"bool gl_HelperInvocation;" // needs qualifier fixed later
);
if (version >= 450)
stageBuiltins[EShLangFragment].append( // GL_EXT_fragment_invocation_density
"flat in ivec2 gl_FragSizeEXT;"
"flat in int gl_FragInvocationCountEXT;"
);
if (version >= 450)
stageBuiltins[EShLangFragment].append(
"in vec2 gl_BaryCoordNoPerspAMD;"
"in vec2 gl_BaryCoordNoPerspCentroidAMD;"
"in vec2 gl_BaryCoordNoPerspSampleAMD;"
"in vec2 gl_BaryCoordSmoothAMD;"
"in vec2 gl_BaryCoordSmoothCentroidAMD;"
"in vec2 gl_BaryCoordSmoothSampleAMD;"
"in vec3 gl_BaryCoordPullModelAMD;"
);
if (version >= 430)
stageBuiltins[EShLangFragment].append(
"in bool gl_FragFullyCoveredNV;"
);
if (version >= 450)
stageBuiltins[EShLangFragment].append(
"flat in ivec2 gl_FragmentSizeNV;" // GL_NV_shading_rate_image
"flat in int gl_InvocationsPerPixelNV;"
"in vec3 gl_BaryCoordNV;" // GL_NV_fragment_shader_barycentric
"in vec3 gl_BaryCoordNoPerspNV;"
"in vec3 gl_BaryCoordEXT;" // GL_EXT_fragment_shader_barycentric
"in vec3 gl_BaryCoordNoPerspEXT;"
);
if (version >= 450)
stageBuiltins[EShLangFragment].append(
"flat in int gl_ShadingRateEXT;" // GL_EXT_fragment_shading_rate
);
} else {
// ES profile
if (version == 100) {
stageBuiltins[EShLangFragment].append(
"mediump vec4 gl_FragCoord;" // needs qualifier fixed later
" bool gl_FrontFacing;" // needs qualifier fixed later
"mediump vec4 gl_FragColor;" // needs qualifier fixed later
"mediump vec2 gl_PointCoord;" // needs qualifier fixed later
);
}
if (version >= 300) {
stageBuiltins[EShLangFragment].append(
"highp vec4 gl_FragCoord;" // needs qualifier fixed later
" bool gl_FrontFacing;" // needs qualifier fixed later
"mediump vec2 gl_PointCoord;" // needs qualifier fixed later
"highp float gl_FragDepth;" // needs qualifier fixed later
);
}
if (version >= 310) {
stageBuiltins[EShLangFragment].append(
"bool gl_HelperInvocation;" // needs qualifier fixed later
"flat in highp int gl_PrimitiveID;" // needs qualifier fixed later
"flat in highp int gl_Layer;" // needs qualifier fixed later
);
stageBuiltins[EShLangFragment].append( // GL_OES_sample_variables
"flat in lowp int gl_SampleID;"
" in mediump vec2 gl_SamplePosition;"
"flat in highp int gl_SampleMaskIn[];"
" out highp int gl_SampleMask[];"
);
if (spvVersion.spv == 0)
stageBuiltins[EShLangFragment].append( // GL_OES_sample_variables
"uniform lowp int gl_NumSamples;"
);
}
stageBuiltins[EShLangFragment].append(
"highp float gl_FragDepthEXT;" // GL_EXT_frag_depth
);
if (version >= 310)
stageBuiltins[EShLangFragment].append( // GL_EXT_fragment_invocation_density
"flat in ivec2 gl_FragSizeEXT;"
"flat in int gl_FragInvocationCountEXT;"
);
if (version >= 320)
stageBuiltins[EShLangFragment].append( // GL_NV_shading_rate_image
"flat in ivec2 gl_FragmentSizeNV;"
"flat in int gl_InvocationsPerPixelNV;"
);
if (version >= 320)
stageBuiltins[EShLangFragment].append(
"in vec3 gl_BaryCoordNV;"
"in vec3 gl_BaryCoordNoPerspNV;"
"in vec3 gl_BaryCoordEXT;"
"in vec3 gl_BaryCoordNoPerspEXT;"
);
if (version >= 310)
stageBuiltins[EShLangFragment].append(
"flat in highp int gl_ShadingRateEXT;" // GL_EXT_fragment_shading_rate
);
}
stageBuiltins[EShLangFragment].append("\n");
if (version >= 130)
add2ndGenerationSamplingImaging(version, profile, spvVersion);
if ((profile != EEsProfile && version >= 140) ||
(profile == EEsProfile && version >= 310)) {
stageBuiltins[EShLangFragment].append(
"flat in highp int gl_DeviceIndex;" // GL_EXT_device_group
"flat in highp int gl_ViewIndex;" // GL_EXT_multiview
"\n");
}
if (version >= 300 /* both ES and non-ES */) {
stageBuiltins[EShLangFragment].append(
"flat in highp uint gl_ViewID_OVR;" // GL_OVR_multiview, GL_OVR_multiview2
"\n");
}
// GL_ARB_shader_ballot
if (profile != EEsProfile && version >= 450) {
const char* ballotDecls =
"uniform uint gl_SubGroupSizeARB;"
"in uint gl_SubGroupInvocationARB;"
"in uint64_t gl_SubGroupEqMaskARB;"
"in uint64_t gl_SubGroupGeMaskARB;"
"in uint64_t gl_SubGroupGtMaskARB;"
"in uint64_t gl_SubGroupLeMaskARB;"
"in uint64_t gl_SubGroupLtMaskARB;"
"\n";
const char* rtBallotDecls =
"uniform volatile uint gl_SubGroupSizeARB;"
"in volatile uint gl_SubGroupInvocationARB;"
"in volatile uint64_t gl_SubGroupEqMaskARB;"
"in volatile uint64_t gl_SubGroupGeMaskARB;"
"in volatile uint64_t gl_SubGroupGtMaskARB;"
"in volatile uint64_t gl_SubGroupLeMaskARB;"
"in volatile uint64_t gl_SubGroupLtMaskARB;"
"\n";
const char* fragmentBallotDecls =
"uniform uint gl_SubGroupSizeARB;"
"flat in uint gl_SubGroupInvocationARB;"
"flat in uint64_t gl_SubGroupEqMaskARB;"
"flat in uint64_t gl_SubGroupGeMaskARB;"
"flat in uint64_t gl_SubGroupGtMaskARB;"
"flat in uint64_t gl_SubGroupLeMaskARB;"
"flat in uint64_t gl_SubGroupLtMaskARB;"
"\n";
stageBuiltins[EShLangVertex] .append(ballotDecls);
stageBuiltins[EShLangTessControl] .append(ballotDecls);
stageBuiltins[EShLangTessEvaluation].append(ballotDecls);
stageBuiltins[EShLangGeometry] .append(ballotDecls);
stageBuiltins[EShLangCompute] .append(ballotDecls);
stageBuiltins[EShLangFragment] .append(fragmentBallotDecls);
stageBuiltins[EShLangMesh] .append(ballotDecls);
stageBuiltins[EShLangTask] .append(ballotDecls);
stageBuiltins[EShLangRayGen] .append(rtBallotDecls);
stageBuiltins[EShLangIntersect] .append(rtBallotDecls);
// No volatile qualifier on these builtins in any-hit
stageBuiltins[EShLangAnyHit] .append(ballotDecls);
stageBuiltins[EShLangClosestHit] .append(rtBallotDecls);
stageBuiltins[EShLangMiss] .append(rtBallotDecls);
stageBuiltins[EShLangCallable] .append(rtBallotDecls);
}
// GL_KHR_shader_subgroup
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
const char* subgroupDecls =
"in mediump uint gl_SubgroupSize;"
"in mediump uint gl_SubgroupInvocationID;"
"in highp uvec4 gl_SubgroupEqMask;"
"in highp uvec4 gl_SubgroupGeMask;"
"in highp uvec4 gl_SubgroupGtMask;"
"in highp uvec4 gl_SubgroupLeMask;"
"in highp uvec4 gl_SubgroupLtMask;"
// GL_NV_shader_sm_builtins
"in highp uint gl_WarpsPerSMNV;"
"in highp uint gl_SMCountNV;"
"in highp uint gl_WarpIDNV;"
"in highp uint gl_SMIDNV;"
// GL_ARM_shader_core_builtins
"in highp uint gl_CoreIDARM;"
"in highp uint gl_CoreCountARM;"
"in highp uint gl_CoreMaxIDARM;"
"in highp uint gl_WarpIDARM;"
"in highp uint gl_WarpMaxIDARM;"
"\n";
const char* fragmentSubgroupDecls =
"flat in mediump uint gl_SubgroupSize;"
"flat in mediump uint gl_SubgroupInvocationID;"
"flat in highp uvec4 gl_SubgroupEqMask;"
"flat in highp uvec4 gl_SubgroupGeMask;"
"flat in highp uvec4 gl_SubgroupGtMask;"
"flat in highp uvec4 gl_SubgroupLeMask;"
"flat in highp uvec4 gl_SubgroupLtMask;"
// GL_NV_shader_sm_builtins
"flat in highp uint gl_WarpsPerSMNV;"
"flat in highp uint gl_SMCountNV;"
"flat in highp uint gl_WarpIDNV;"
"flat in highp uint gl_SMIDNV;"
// GL_ARM_shader_core_builtins
"flat in highp uint gl_CoreIDARM;"
"flat in highp uint gl_CoreCountARM;"
"flat in highp uint gl_CoreMaxIDARM;"
"flat in highp uint gl_WarpIDARM;"
"flat in highp uint gl_WarpMaxIDARM;"
"\n";
const char* computeSubgroupDecls =
"in highp uint gl_NumSubgroups;"
"in highp uint gl_SubgroupID;"
"\n";
// These builtins are volatile for RT stages
const char* rtSubgroupDecls =
"in mediump volatile uint gl_SubgroupSize;"
"in mediump volatile uint gl_SubgroupInvocationID;"
"in highp volatile uvec4 gl_SubgroupEqMask;"
"in highp volatile uvec4 gl_SubgroupGeMask;"
"in highp volatile uvec4 gl_SubgroupGtMask;"
"in highp volatile uvec4 gl_SubgroupLeMask;"
"in highp volatile uvec4 gl_SubgroupLtMask;"
// GL_NV_shader_sm_builtins
"in highp uint gl_WarpsPerSMNV;"
"in highp uint gl_SMCountNV;"
"in highp volatile uint gl_WarpIDNV;"
"in highp volatile uint gl_SMIDNV;"
// GL_ARM_shader_core_builtins
"in highp uint gl_CoreIDARM;"
"in highp uint gl_CoreCountARM;"
"in highp uint gl_CoreMaxIDARM;"
"in highp uint gl_WarpIDARM;"
"in highp uint gl_WarpMaxIDARM;"
"\n";
stageBuiltins[EShLangVertex] .append(subgroupDecls);
stageBuiltins[EShLangTessControl] .append(subgroupDecls);
stageBuiltins[EShLangTessEvaluation].append(subgroupDecls);
stageBuiltins[EShLangGeometry] .append(subgroupDecls);
stageBuiltins[EShLangCompute] .append(subgroupDecls);
stageBuiltins[EShLangCompute] .append(computeSubgroupDecls);
stageBuiltins[EShLangFragment] .append(fragmentSubgroupDecls);
stageBuiltins[EShLangMesh] .append(subgroupDecls);
stageBuiltins[EShLangMesh] .append(computeSubgroupDecls);
stageBuiltins[EShLangTask] .append(subgroupDecls);
stageBuiltins[EShLangTask] .append(computeSubgroupDecls);
stageBuiltins[EShLangRayGen] .append(rtSubgroupDecls);
stageBuiltins[EShLangIntersect] .append(rtSubgroupDecls);
// No volatile qualifier on these builtins in any-hit
stageBuiltins[EShLangAnyHit] .append(subgroupDecls);
stageBuiltins[EShLangClosestHit] .append(rtSubgroupDecls);
stageBuiltins[EShLangMiss] .append(rtSubgroupDecls);
stageBuiltins[EShLangCallable] .append(rtSubgroupDecls);
}
// GL_NV_ray_tracing/GL_EXT_ray_tracing
if (profile != EEsProfile && version >= 460) {
const char *constRayFlags =
"const uint gl_RayFlagsNoneNV = 0U;"
"const uint gl_RayFlagsNoneEXT = 0U;"
"const uint gl_RayFlagsOpaqueNV = 1U;"
"const uint gl_RayFlagsOpaqueEXT = 1U;"
"const uint gl_RayFlagsNoOpaqueNV = 2U;"
"const uint gl_RayFlagsNoOpaqueEXT = 2U;"
"const uint gl_RayFlagsTerminateOnFirstHitNV = 4U;"
"const uint gl_RayFlagsTerminateOnFirstHitEXT = 4U;"
"const uint gl_RayFlagsSkipClosestHitShaderNV = 8U;"
"const uint gl_RayFlagsSkipClosestHitShaderEXT = 8U;"
"const uint gl_RayFlagsCullBackFacingTrianglesNV = 16U;"
"const uint gl_RayFlagsCullBackFacingTrianglesEXT = 16U;"
"const uint gl_RayFlagsCullFrontFacingTrianglesNV = 32U;"
"const uint gl_RayFlagsCullFrontFacingTrianglesEXT = 32U;"
"const uint gl_RayFlagsCullOpaqueNV = 64U;"
"const uint gl_RayFlagsCullOpaqueEXT = 64U;"
"const uint gl_RayFlagsCullNoOpaqueNV = 128U;"
"const uint gl_RayFlagsCullNoOpaqueEXT = 128U;"
"const uint gl_RayFlagsSkipTrianglesEXT = 256U;"
"const uint gl_RayFlagsSkipAABBEXT = 512U;"
"const uint gl_RayFlagsForceOpacityMicromap2StateEXT = 1024U;"
"const uint gl_HitKindFrontFacingTriangleEXT = 254U;"
"const uint gl_HitKindBackFacingTriangleEXT = 255U;"
"in uint gl_HitKindFrontFacingMicroTriangleNV;"
"in uint gl_HitKindBackFacingMicroTriangleNV;"
"\n";
const char *constRayQueryIntersection =
"const uint gl_RayQueryCandidateIntersectionEXT = 0U;"
"const uint gl_RayQueryCommittedIntersectionEXT = 1U;"
"const uint gl_RayQueryCommittedIntersectionNoneEXT = 0U;"
"const uint gl_RayQueryCommittedIntersectionTriangleEXT = 1U;"
"const uint gl_RayQueryCommittedIntersectionGeneratedEXT = 2U;"
"const uint gl_RayQueryCandidateIntersectionTriangleEXT = 0U;"
"const uint gl_RayQueryCandidateIntersectionAABBEXT = 1U;"
"\n";
const char *rayGenDecls =
"in uvec3 gl_LaunchIDNV;"
"in uvec3 gl_LaunchIDEXT;"
"in uvec3 gl_LaunchSizeNV;"
"in uvec3 gl_LaunchSizeEXT;"
"\n";
const char *intersectDecls =
"in uvec3 gl_LaunchIDNV;"
"in uvec3 gl_LaunchIDEXT;"
"in uvec3 gl_LaunchSizeNV;"
"in uvec3 gl_LaunchSizeEXT;"
"in int gl_PrimitiveID;"
"in int gl_InstanceID;"
"in int gl_InstanceCustomIndexNV;"
"in int gl_InstanceCustomIndexEXT;"
"in int gl_GeometryIndexEXT;"
"in vec3 gl_WorldRayOriginNV;"
"in vec3 gl_WorldRayOriginEXT;"
"in vec3 gl_WorldRayDirectionNV;"
"in vec3 gl_WorldRayDirectionEXT;"
"in vec3 gl_ObjectRayOriginNV;"
"in vec3 gl_ObjectRayOriginEXT;"
"in vec3 gl_ObjectRayDirectionNV;"
"in vec3 gl_ObjectRayDirectionEXT;"
"in float gl_RayTminNV;"
"in float gl_RayTminEXT;"
"in float gl_RayTmaxNV;"
"in volatile float gl_RayTmaxEXT;"
"in mat4x3 gl_ObjectToWorldNV;"
"in mat4x3 gl_ObjectToWorldEXT;"
"in mat3x4 gl_ObjectToWorld3x4EXT;"
"in mat4x3 gl_WorldToObjectNV;"
"in mat4x3 gl_WorldToObjectEXT;"
"in mat3x4 gl_WorldToObject3x4EXT;"
"in uint gl_IncomingRayFlagsNV;"
"in uint gl_IncomingRayFlagsEXT;"
"in float gl_CurrentRayTimeNV;"
"in uint gl_CullMaskEXT;"
"\n";
const char *hitDecls =
"in uvec3 gl_LaunchIDNV;"
"in uvec3 gl_LaunchIDEXT;"
"in uvec3 gl_LaunchSizeNV;"
"in uvec3 gl_LaunchSizeEXT;"
"in int gl_PrimitiveID;"
"in int gl_InstanceID;"
"in int gl_InstanceCustomIndexNV;"
"in int gl_InstanceCustomIndexEXT;"
"in int gl_GeometryIndexEXT;"
"in vec3 gl_WorldRayOriginNV;"
"in vec3 gl_WorldRayOriginEXT;"
"in vec3 gl_WorldRayDirectionNV;"
"in vec3 gl_WorldRayDirectionEXT;"
"in vec3 gl_ObjectRayOriginNV;"
"in vec3 gl_ObjectRayOriginEXT;"
"in vec3 gl_ObjectRayDirectionNV;"
"in vec3 gl_ObjectRayDirectionEXT;"
"in float gl_RayTminNV;"
"in float gl_RayTminEXT;"
"in float gl_RayTmaxNV;"
"in float gl_RayTmaxEXT;"
"in float gl_HitTNV;"
"in float gl_HitTEXT;"
"in uint gl_HitKindNV;"
"in uint gl_HitKindEXT;"
"in mat4x3 gl_ObjectToWorldNV;"
"in mat4x3 gl_ObjectToWorldEXT;"
"in mat3x4 gl_ObjectToWorld3x4EXT;"
"in mat4x3 gl_WorldToObjectNV;"
"in mat4x3 gl_WorldToObjectEXT;"
"in mat3x4 gl_WorldToObject3x4EXT;"
"in uint gl_IncomingRayFlagsNV;"
"in uint gl_IncomingRayFlagsEXT;"
"in float gl_CurrentRayTimeNV;"
"in uint gl_CullMaskEXT;"
"in vec3 gl_HitTriangleVertexPositionsEXT[3];"
"in vec3 gl_HitMicroTriangleVertexPositionsNV[3];"
"in vec2 gl_HitMicroTriangleVertexBarycentricsNV[3];"
"\n";
const char *missDecls =
"in uvec3 gl_LaunchIDNV;"
"in uvec3 gl_LaunchIDEXT;"
"in uvec3 gl_LaunchSizeNV;"
"in uvec3 gl_LaunchSizeEXT;"
"in vec3 gl_WorldRayOriginNV;"
"in vec3 gl_WorldRayOriginEXT;"
"in vec3 gl_WorldRayDirectionNV;"
"in vec3 gl_WorldRayDirectionEXT;"
"in vec3 gl_ObjectRayOriginNV;"
"in vec3 gl_ObjectRayDirectionNV;"
"in float gl_RayTminNV;"
"in float gl_RayTminEXT;"
"in float gl_RayTmaxNV;"
"in float gl_RayTmaxEXT;"
"in uint gl_IncomingRayFlagsNV;"
"in uint gl_IncomingRayFlagsEXT;"
"in float gl_CurrentRayTimeNV;"
"in uint gl_CullMaskEXT;"
"\n";
const char *callableDecls =
"in uvec3 gl_LaunchIDNV;"
"in uvec3 gl_LaunchIDEXT;"
"in uvec3 gl_LaunchSizeNV;"
"in uvec3 gl_LaunchSizeEXT;"
"\n";
commonBuiltins.append(constRayQueryIntersection);
commonBuiltins.append(constRayFlags);
stageBuiltins[EShLangRayGen].append(rayGenDecls);
stageBuiltins[EShLangIntersect].append(intersectDecls);
stageBuiltins[EShLangAnyHit].append(hitDecls);
stageBuiltins[EShLangClosestHit].append(hitDecls);
stageBuiltins[EShLangMiss].append(missDecls);
stageBuiltins[EShLangCallable].append(callableDecls);
}
if ((profile != EEsProfile && version >= 140)) {
const char *deviceIndex =
"in highp int gl_DeviceIndex;" // GL_EXT_device_group
"\n";
stageBuiltins[EShLangRayGen].append(deviceIndex);
stageBuiltins[EShLangIntersect].append(deviceIndex);
stageBuiltins[EShLangAnyHit].append(deviceIndex);
stageBuiltins[EShLangClosestHit].append(deviceIndex);
stageBuiltins[EShLangMiss].append(deviceIndex);
}
if ((profile != EEsProfile && version >= 420) ||
(profile == EEsProfile && version >= 310)) {
commonBuiltins.append("const int gl_ScopeDevice = 1;\n");
commonBuiltins.append("const int gl_ScopeWorkgroup = 2;\n");
commonBuiltins.append("const int gl_ScopeSubgroup = 3;\n");
commonBuiltins.append("const int gl_ScopeInvocation = 4;\n");
commonBuiltins.append("const int gl_ScopeQueueFamily = 5;\n");
commonBuiltins.append("const int gl_ScopeShaderCallEXT = 6;\n");
commonBuiltins.append("const int gl_SemanticsRelaxed = 0x0;\n");
commonBuiltins.append("const int gl_SemanticsAcquire = 0x2;\n");
commonBuiltins.append("const int gl_SemanticsRelease = 0x4;\n");
commonBuiltins.append("const int gl_SemanticsAcquireRelease = 0x8;\n");
commonBuiltins.append("const int gl_SemanticsMakeAvailable = 0x2000;\n");
commonBuiltins.append("const int gl_SemanticsMakeVisible = 0x4000;\n");
commonBuiltins.append("const int gl_SemanticsVolatile = 0x8000;\n");
commonBuiltins.append("const int gl_StorageSemanticsNone = 0x0;\n");
commonBuiltins.append("const int gl_StorageSemanticsBuffer = 0x40;\n");
commonBuiltins.append("const int gl_StorageSemanticsShared = 0x100;\n");
commonBuiltins.append("const int gl_StorageSemanticsImage = 0x800;\n");
commonBuiltins.append("const int gl_StorageSemanticsOutput = 0x1000;\n");
}
// Adding these to common built-ins triggers an assert due to a memory corruption in related code when testing
// So instead add to each stage individually, avoiding the GLSLang bug
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 310)) {
for (int stage=EShLangVertex; stage<EShLangCount; stage++)
{
stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2VerticalPixelsEXT = 1;\n");
stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4VerticalPixelsEXT = 2;\n");
stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag2HorizontalPixelsEXT = 4;\n");
stageBuiltins[static_cast<EShLanguage>(stage)].append("const highp int gl_ShadingRateFlag4HorizontalPixelsEXT = 8;\n");
}
}
// GL_EXT_shader_image_int64
if ((profile != EEsProfile && version >= 420) ||
(profile == EEsProfile && version >= 310)) {
const TBasicType bTypes[] = { EbtInt64, EbtUint64 };
for (int ms = 0; ms <= 1; ++ms) { // loop over "bool" multisample or not
for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
for (int dim = Esd1D; dim < EsdSubpass; ++dim) { // 1D, ..., buffer
if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
continue;
if ((dim == Esd3D || dim == EsdRect || dim == EsdBuffer) && arrayed)
continue;
if (dim != Esd2D && ms)
continue;
// Loop over the bTypes
for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
//
// Now, make all the function prototypes for the type we just built...
//
TSampler sampler;
sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
false,
ms ? true : false);
TString typeName = sampler.getString();
addQueryFunctions(sampler, typeName, version, profile);
addImageFunctions(sampler, typeName, version, profile);
}
}
}
}
}
// printf("%s\n", commonBuiltins.c_str());
// printf("%s\n", stageBuiltins[EShLangFragment].c_str());
}
//
// Helper function for initialize(), to add the second set of names for texturing,
// when adding context-independent built-in functions.
//
void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion)
{
//
// In this function proper, enumerate the types, then calls the next set of functions
// to enumerate all the uses for that type.
//
// enumerate all the types
const TBasicType bTypes[] = { EbtFloat, EbtInt, EbtUint,
EbtFloat16
};
bool skipBuffer = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 140);
bool skipCubeArrayed = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 130);
for (int image = 0; image <= 1; ++image) // loop over "bool" image vs sampler
{
for (int shadow = 0; shadow <= 1; ++shadow) { // loop over "bool" shadow or not
for (int ms = 0; ms <= 1; ++ms) // loop over "bool" multisample or not
{
if ((ms || image) && shadow)
continue;
if (ms && profile != EEsProfile && version < 140)
continue;
if (ms && image && profile == EEsProfile)
continue;
if (ms && profile == EEsProfile && version < 310)
continue;
for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not
for (int dim = Esd1D; dim < EsdNumDims; ++dim) { // 1D, ..., buffer, subpass
if (dim == EsdAttachmentEXT)
continue;
if (dim == EsdSubpass && spvVersion.vulkan == 0)
continue;
if (dim == EsdSubpass && (image || shadow || arrayed))
continue;
if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
continue;
if (dim == EsdSubpass && spvVersion.vulkan == 0)
continue;
if (dim == EsdSubpass && (image || shadow || arrayed))
continue;
if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile)
continue;
if (dim != Esd2D && dim != EsdSubpass && ms)
continue;
if (dim == EsdBuffer && skipBuffer)
continue;
if (dim == EsdBuffer && (shadow || arrayed || ms))
continue;
if (ms && arrayed && profile == EEsProfile && version < 310)
continue;
if (dim == Esd3D && shadow)
continue;
if (dim == EsdCube && arrayed && skipCubeArrayed)
continue;
if ((dim == Esd3D || dim == EsdRect) && arrayed)
continue;
// Loop over the bTypes
for (size_t bType = 0; bType < sizeof(bTypes)/sizeof(TBasicType); ++bType) {
if (bTypes[bType] == EbtFloat16 && (profile == EEsProfile || version < 450))
continue;
if (dim == EsdRect && version < 140 && bType > 0)
continue;
if (shadow && (bTypes[bType] == EbtInt || bTypes[bType] == EbtUint))
continue;
//
// Now, make all the function prototypes for the type we just built...
//
TSampler sampler;
if (dim == EsdSubpass) {
sampler.setSubpass(bTypes[bType], ms ? true : false);
} else if (dim == EsdAttachmentEXT) {
sampler.setAttachmentEXT(bTypes[bType]);
} else
if (image) {
sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
shadow ? true : false,
ms ? true : false);
} else {
sampler.set(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false,
shadow ? true : false,
ms ? true : false);
}
TString typeName = sampler.getString();
if (dim == EsdSubpass) {
addSubpassSampling(sampler, typeName, version, profile);
continue;
}
addQueryFunctions(sampler, typeName, version, profile);
if (image)
addImageFunctions(sampler, typeName, version, profile);
else {
addSamplingFunctions(sampler, typeName, version, profile);
addGatherFunctions(sampler, typeName, version, profile);
if (spvVersion.vulkan > 0 && sampler.isCombined() && !sampler.shadow) {
// Base Vulkan allows texelFetch() for
// textureBuffer (i.e. without sampler).
//
// GL_EXT_samplerless_texture_functions
// allows texelFetch() and query functions
// (other than textureQueryLod()) for all
// texture types.
sampler.setTexture(sampler.type, sampler.dim, sampler.arrayed, sampler.shadow,
sampler.ms);
TString textureTypeName = sampler.getString();
addSamplingFunctions(sampler, textureTypeName, version, profile);
addQueryFunctions(sampler, textureTypeName, version, profile);
}
}
}
}
}
}
}
}
//
// sparseTexelsResidentARB()
//
if (profile != EEsProfile && version >= 450) {
commonBuiltins.append("bool sparseTexelsResidentARB(int code);\n");
}
}
//
// Helper function for add2ndGenerationSamplingImaging(),
// when adding context-independent built-in functions.
//
// Add all the query functions for the given type.
//
void TBuiltIns::addQueryFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
{
//
// textureSize() and imageSize()
//
int sizeDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0) - (sampler.dim == EsdCube ? 1 : 0);
if (sampler.isImage() && ((profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 420)))
return;
if (profile == EEsProfile)
commonBuiltins.append("highp ");
if (sizeDims == 1)
commonBuiltins.append("int");
else {
commonBuiltins.append("ivec");
commonBuiltins.append(postfixes[sizeDims]);
}
if (sampler.isImage())
commonBuiltins.append(" imageSize(readonly writeonly volatile coherent ");
else
commonBuiltins.append(" textureSize(");
commonBuiltins.append(typeName);
if (! sampler.isImage() && ! sampler.isRect() && ! sampler.isBuffer() && ! sampler.isMultiSample())
commonBuiltins.append(",int);\n");
else
commonBuiltins.append(");\n");
//
// textureSamples() and imageSamples()
//
// GL_ARB_shader_texture_image_samples
// TODO: spec issue? there are no memory qualifiers; how to query a writeonly/readonly image, etc?
if (profile != EEsProfile && version >= 430 && sampler.isMultiSample()) {
commonBuiltins.append("int ");
if (sampler.isImage())
commonBuiltins.append("imageSamples(readonly writeonly volatile coherent ");
else
commonBuiltins.append("textureSamples(");
commonBuiltins.append(typeName);
commonBuiltins.append(");\n");
}
//
// textureQueryLod(), fragment stage only
// Also enabled with extension GL_ARB_texture_query_lod
// Extension GL_ARB_texture_query_lod says that textureQueryLOD() also exist at extension.
if (profile != EEsProfile && version >= 150 && sampler.isCombined() && sampler.dim != EsdRect &&
! sampler.isMultiSample() && ! sampler.isBuffer()) {
const TString funcName[2] = {"vec2 textureQueryLod(", "vec2 textureQueryLOD("};
for (int i = 0; i < 2; ++i){
for (int f16TexAddr = 0; f16TexAddr < 2; ++f16TexAddr) {
if (f16TexAddr && sampler.type != EbtFloat16)
continue;
stageBuiltins[EShLangFragment].append(funcName[i]);
stageBuiltins[EShLangFragment].append(typeName);
if (dimMap[sampler.dim] == 1)
if (f16TexAddr)
stageBuiltins[EShLangFragment].append(", float16_t");
else
stageBuiltins[EShLangFragment].append(", float");
else {
if (f16TexAddr)
stageBuiltins[EShLangFragment].append(", f16vec");
else
stageBuiltins[EShLangFragment].append(", vec");
stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]);
}
stageBuiltins[EShLangFragment].append(");\n");
}
stageBuiltins[EShLangCompute].append(funcName[i]);
stageBuiltins[EShLangCompute].append(typeName);
if (dimMap[sampler.dim] == 1)
stageBuiltins[EShLangCompute].append(", float");
else {
stageBuiltins[EShLangCompute].append(", vec");
stageBuiltins[EShLangCompute].append(postfixes[dimMap[sampler.dim]]);
}
stageBuiltins[EShLangCompute].append(");\n");
}
}
//
// textureQueryLevels()
//
if (profile != EEsProfile && version >= 430 && ! sampler.isImage() && sampler.dim != EsdRect &&
! sampler.isMultiSample() && ! sampler.isBuffer()) {
commonBuiltins.append("int textureQueryLevels(");
commonBuiltins.append(typeName);
commonBuiltins.append(");\n");
}
}
//
// Helper function for add2ndGenerationSamplingImaging(),
// when adding context-independent built-in functions.
//
// Add all the image access functions for the given type.
//
void TBuiltIns::addImageFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
{
int dims = dimMap[sampler.dim];
// most things with an array add a dimension, except for cubemaps
if (sampler.arrayed && sampler.dim != EsdCube)
++dims;
TString imageParams = typeName;
if (dims == 1)
imageParams.append(", int");
else {
imageParams.append(", ivec");
imageParams.append(postfixes[dims]);
}
if (sampler.isMultiSample())
imageParams.append(", int");
if (profile == EEsProfile)
commonBuiltins.append("highp ");
commonBuiltins.append(prefixes[sampler.type]);
commonBuiltins.append("vec4 imageLoad(readonly volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(");\n");
commonBuiltins.append("void imageStore(writeonly volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", ");
commonBuiltins.append(prefixes[sampler.type]);
commonBuiltins.append("vec4);\n");
if (! sampler.is1D() && ! sampler.isBuffer() && profile != EEsProfile && version >= 450) {
commonBuiltins.append("int sparseImageLoadARB(readonly volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", out ");
commonBuiltins.append(prefixes[sampler.type]);
commonBuiltins.append("vec4");
commonBuiltins.append(");\n");
}
if ( profile != EEsProfile ||
(profile == EEsProfile && version >= 310)) {
if (sampler.type == EbtInt || sampler.type == EbtUint || sampler.type == EbtInt64 || sampler.type == EbtUint64 ) {
const char* dataType;
switch (sampler.type) {
case(EbtInt): dataType = "highp int"; break;
case(EbtUint): dataType = "highp uint"; break;
case(EbtInt64): dataType = "highp int64_t"; break;
case(EbtUint64): dataType = "highp uint64_t"; break;
default: dataType = "";
}
const int numBuiltins = 7;
static const char* atomicFunc[numBuiltins] = {
" imageAtomicAdd(volatile coherent ",
" imageAtomicMin(volatile coherent ",
" imageAtomicMax(volatile coherent ",
" imageAtomicAnd(volatile coherent ",
" imageAtomicOr(volatile coherent ",
" imageAtomicXor(volatile coherent ",
" imageAtomicExchange(volatile coherent "
};
// Loop twice to add prototypes with/without scope/semantics
for (int j = 0; j < 2; ++j) {
for (size_t i = 0; i < numBuiltins; ++i) {
commonBuiltins.append(dataType);
commonBuiltins.append(atomicFunc[i]);
commonBuiltins.append(imageParams);
commonBuiltins.append(", ");
commonBuiltins.append(dataType);
if (j == 1) {
commonBuiltins.append(", int, int, int");
}
commonBuiltins.append(");\n");
}
commonBuiltins.append(dataType);
commonBuiltins.append(" imageAtomicCompSwap(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", ");
commonBuiltins.append(dataType);
commonBuiltins.append(", ");
commonBuiltins.append(dataType);
if (j == 1) {
commonBuiltins.append(", int, int, int, int, int");
}
commonBuiltins.append(");\n");
}
commonBuiltins.append(dataType);
commonBuiltins.append(" imageAtomicLoad(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", int, int, int);\n");
commonBuiltins.append("void imageAtomicStore(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", ");
commonBuiltins.append(dataType);
commonBuiltins.append(", int, int, int);\n");
} else {
// not int or uint
// GL_ARB_ES3_1_compatibility
// TODO: spec issue: are there restrictions on the kind of layout() that can be used? what about dropping memory qualifiers?
if (profile == EEsProfile && version >= 310) {
commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float);\n");
}
// GL_NV_shader_atomic_fp16_vector
if (profile != EEsProfile && version >= 430) {
const int numFp16Builtins = 4;
const char* atomicFp16Func[numFp16Builtins] = {
" imageAtomicAdd(volatile coherent ",
" imageAtomicMin(volatile coherent ",
" imageAtomicMax(volatile coherent ",
" imageAtomicExchange(volatile coherent "
};
const int numFp16DataTypes = 2;
const char* atomicFp16DataTypes[numFp16DataTypes] = {
"f16vec2",
"f16vec4"
};
// Loop twice to add prototypes with/without scope/semantics
for (int j = 0; j < numFp16DataTypes; ++j) {
for (int i = 0; i < numFp16Builtins; ++i) {
commonBuiltins.append(atomicFp16DataTypes[j]);
commonBuiltins.append(atomicFp16Func[i]);
commonBuiltins.append(imageParams);
commonBuiltins.append(", ");
commonBuiltins.append(atomicFp16DataTypes[j]);
commonBuiltins.append(");\n");
}
}
}
if (profile != EEsProfile && version >= 450) {
commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float);\n");
commonBuiltins.append("float imageAtomicAdd(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float");
commonBuiltins.append(", int, int, int);\n");
commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float);\n");
commonBuiltins.append("float imageAtomicExchange(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float");
commonBuiltins.append(", int, int, int);\n");
commonBuiltins.append("float imageAtomicLoad(readonly volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", int, int, int);\n");
commonBuiltins.append("void imageAtomicStore(writeonly volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float");
commonBuiltins.append(", int, int, int);\n");
commonBuiltins.append("float imageAtomicMin(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float);\n");
commonBuiltins.append("float imageAtomicMin(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float");
commonBuiltins.append(", int, int, int);\n");
commonBuiltins.append("float imageAtomicMax(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float);\n");
commonBuiltins.append("float imageAtomicMax(volatile coherent ");
commonBuiltins.append(imageParams);
commonBuiltins.append(", float");
commonBuiltins.append(", int, int, int);\n");
}
}
}
if (sampler.dim == EsdRect || sampler.dim == EsdBuffer || sampler.shadow || sampler.isMultiSample())
return;
if (profile == EEsProfile || version < 450)
return;
TString imageLodParams = typeName;
if (dims == 1)
imageLodParams.append(", int");
else {
imageLodParams.append(", ivec");
imageLodParams.append(postfixes[dims]);
}
imageLodParams.append(", int");
commonBuiltins.append(prefixes[sampler.type]);
commonBuiltins.append("vec4 imageLoadLodAMD(readonly volatile coherent ");
commonBuiltins.append(imageLodParams);
commonBuiltins.append(");\n");
commonBuiltins.append("void imageStoreLodAMD(writeonly volatile coherent ");
commonBuiltins.append(imageLodParams);
commonBuiltins.append(", ");
commonBuiltins.append(prefixes[sampler.type]);
commonBuiltins.append("vec4);\n");
if (! sampler.is1D()) {
commonBuiltins.append("int sparseImageLoadLodAMD(readonly volatile coherent ");
commonBuiltins.append(imageLodParams);
commonBuiltins.append(", out ");
commonBuiltins.append(prefixes[sampler.type]);
commonBuiltins.append("vec4");
commonBuiltins.append(");\n");
}
}
//
// Helper function for initialize(),
// when adding context-independent built-in functions.
//
// Add all the subpass access functions for the given type.
//
void TBuiltIns::addSubpassSampling(TSampler sampler, const TString& typeName, int /*version*/, EProfile /*profile*/)
{
stageBuiltins[EShLangFragment].append(prefixes[sampler.type]);
stageBuiltins[EShLangFragment].append("vec4 subpassLoad");
stageBuiltins[EShLangFragment].append("(");
stageBuiltins[EShLangFragment].append(typeName.c_str());
if (sampler.isMultiSample())
stageBuiltins[EShLangFragment].append(", int");
stageBuiltins[EShLangFragment].append(");\n");
}
//
// Helper function for add2ndGenerationSamplingImaging(),
// when adding context-independent built-in functions.
//
// Add all the texture lookup functions for the given type.
//
void TBuiltIns::addSamplingFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
{
//
// texturing
//
for (int proj = 0; proj <= 1; ++proj) { // loop over "bool" projective or not
if (proj && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.arrayed || sampler.isMultiSample()
|| !sampler.isCombined()))
continue;
for (int lod = 0; lod <= 1; ++lod) {
if (lod && (sampler.isBuffer() || sampler.isRect() || sampler.isMultiSample() || !sampler.isCombined()))
continue;
if (lod && sampler.dim == Esd2D && sampler.arrayed && sampler.shadow)
continue;
if (lod && sampler.dim == EsdCube && sampler.shadow)
continue;
for (int bias = 0; bias <= 1; ++bias) {
if (bias && (lod || sampler.isMultiSample() || !sampler.isCombined()))
continue;
if (bias && (sampler.dim == Esd2D || sampler.dim == EsdCube) && sampler.shadow && sampler.arrayed)
continue;
if (bias && (sampler.isRect() || sampler.isBuffer()))
continue;
for (int offset = 0; offset <= 1; ++offset) { // loop over "bool" offset or not
if (proj + offset + bias + lod > 3)
continue;
if (offset && (sampler.dim == EsdCube || sampler.isBuffer() || sampler.isMultiSample()))
continue;
for (int fetch = 0; fetch <= 1; ++fetch) { // loop over "bool" fetch or not
if (proj + offset + fetch + bias + lod > 3)
continue;
if (fetch && (lod || bias))
continue;
if (fetch && (sampler.shadow || sampler.dim == EsdCube))
continue;
if (fetch == 0 && (sampler.isMultiSample() || sampler.isBuffer()
|| !sampler.isCombined()))
continue;
for (int grad = 0; grad <= 1; ++grad) { // loop over "bool" grad or not
if (grad && (lod || bias || sampler.isMultiSample() || !sampler.isCombined()))
continue;
if (grad && sampler.isBuffer())
continue;
if (proj + offset + fetch + grad + bias + lod > 3)
continue;
for (int extraProj = 0; extraProj <= 1; ++extraProj) {
bool compare = false;
int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
// skip dummy unused second component for 1D non-array shadows
if (sampler.shadow && totalDims < 2)
totalDims = 2;
totalDims += (sampler.shadow ? 1 : 0) + proj;
if (totalDims > 4 && sampler.shadow) {
compare = true;
totalDims = 4;
}
assert(totalDims <= 4);
if (extraProj && ! proj)
continue;
if (extraProj && (sampler.dim == Esd3D || sampler.shadow || !sampler.isCombined()))
continue;
// loop over 16-bit floating-point texel addressing
for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr)
{
if (f16TexAddr && sampler.type != EbtFloat16)
continue;
if (f16TexAddr && sampler.shadow && ! compare) {
compare = true; // compare argument is always present
totalDims--;
}
// loop over "bool" lod clamp
for (int lodClamp = 0; lodClamp <= 1 ;++lodClamp)
{
if (lodClamp && (profile == EEsProfile || version < 450))
continue;
if (lodClamp && (proj || lod || fetch))
continue;
// loop over "bool" sparse or not
for (int sparse = 0; sparse <= 1; ++sparse)
{
if (sparse && (profile == EEsProfile || version < 450))
continue;
// Sparse sampling is not for 1D/1D array texture, buffer texture, and
// projective texture
if (sparse && (sampler.is1D() || sampler.isBuffer() || proj))
continue;
TString s;
// return type
if (sparse)
s.append("int ");
else {
if (sampler.shadow)
if (sampler.type == EbtFloat16)
s.append("float16_t ");
else
s.append("float ");
else {
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
}
// name
if (sparse) {
if (fetch)
s.append("sparseTexel");
else
s.append("sparseTexture");
}
else {
if (fetch)
s.append("texel");
else
s.append("texture");
}
if (proj)
s.append("Proj");
if (lod)
s.append("Lod");
if (grad)
s.append("Grad");
if (fetch)
s.append("Fetch");
if (offset)
s.append("Offset");
if (lodClamp)
s.append("Clamp");
if (lodClamp != 0 || sparse)
s.append("ARB");
s.append("(");
// sampler type
s.append(typeName);
// P coordinate
if (extraProj) {
if (f16TexAddr)
s.append(",f16vec4");
else
s.append(",vec4");
} else {
s.append(",");
TBasicType t = fetch ? EbtInt : (f16TexAddr ? EbtFloat16 : EbtFloat);
if (totalDims == 1)
s.append(TType::getBasicString(t));
else {
s.append(prefixes[t]);
s.append("vec");
s.append(postfixes[totalDims]);
}
}
// non-optional compare
if (compare)
s.append(",float");
// non-optional lod argument (lod that's not driven by lod loop) or sample
if ((fetch && !sampler.isBuffer() &&
!sampler.isRect() && !sampler.isMultiSample())
|| (sampler.isMultiSample() && fetch))
s.append(",int");
// non-optional lod
if (lod) {
if (f16TexAddr)
s.append(",float16_t");
else
s.append(",float");
}
// gradient arguments
if (grad) {
if (dimMap[sampler.dim] == 1) {
if (f16TexAddr)
s.append(",float16_t,float16_t");
else
s.append(",float,float");
} else {
if (f16TexAddr)
s.append(",f16vec");
else
s.append(",vec");
s.append(postfixes[dimMap[sampler.dim]]);
if (f16TexAddr)
s.append(",f16vec");
else
s.append(",vec");
s.append(postfixes[dimMap[sampler.dim]]);
}
}
// offset
if (offset) {
if (dimMap[sampler.dim] == 1)
s.append(",int");
else {
s.append(",ivec");
s.append(postfixes[dimMap[sampler.dim]]);
}
}
// lod clamp
if (lodClamp) {
if (f16TexAddr)
s.append(",float16_t");
else
s.append(",float");
}
// texel out (for sparse texture)
if (sparse) {
s.append(",out ");
if (sampler.shadow)
if (sampler.type == EbtFloat16)
s.append("float16_t");
else
s.append("float");
else {
s.append(prefixes[sampler.type]);
s.append("vec4");
}
}
// optional bias
if (bias) {
if (f16TexAddr)
s.append(",float16_t");
else
s.append(",float");
}
s.append(");\n");
// Add to the per-language set of built-ins
if (!grad && (bias || lodClamp != 0)) {
stageBuiltins[EShLangFragment].append(s);
stageBuiltins[EShLangCompute].append(s);
} else
commonBuiltins.append(s);
}
}
}
}
}
}
}
}
}
}
}
//
// Helper function for add2ndGenerationSamplingImaging(),
// when adding context-independent built-in functions.
//
// Add all the texture gather functions for the given type.
//
void TBuiltIns::addGatherFunctions(TSampler sampler, const TString& typeName, int version, EProfile profile)
{
switch (sampler.dim) {
case Esd2D:
case EsdRect:
case EsdCube:
break;
default:
return;
}
if (sampler.isMultiSample())
return;
if (version < 140 && sampler.dim == EsdRect && sampler.type != EbtFloat)
return;
for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
if (f16TexAddr && sampler.type != EbtFloat16)
continue;
for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name: none, Offset, and Offsets
for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
if (comp > 0 && sampler.shadow)
continue;
if (offset > 0 && sampler.dim == EsdCube)
continue;
for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
if (sparse && (profile == EEsProfile || version < 450))
continue;
TString s;
// return type
if (sparse)
s.append("int ");
else {
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
// name
if (sparse)
s.append("sparseTextureGather");
else
s.append("textureGather");
switch (offset) {
case 1:
s.append("Offset");
break;
case 2:
s.append("Offsets");
break;
default:
break;
}
if (sparse)
s.append("ARB");
s.append("(");
// sampler type argument
s.append(typeName);
// P coordinate argument
if (f16TexAddr)
s.append(",f16vec");
else
s.append(",vec");
int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
s.append(postfixes[totalDims]);
// refZ argument
if (sampler.shadow)
s.append(",float");
// offset argument
if (offset > 0) {
s.append(",ivec2");
if (offset == 2)
s.append("[4]");
}
// texel out (for sparse texture)
if (sparse) {
s.append(",out ");
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
// comp argument
if (comp)
s.append(",int");
s.append(");\n");
commonBuiltins.append(s);
}
}
}
}
if (sampler.dim == EsdRect || sampler.shadow)
return;
if (profile == EEsProfile || version < 450)
return;
for (int bias = 0; bias < 2; ++bias) { // loop over presence of bias argument
for (int lod = 0; lod < 2; ++lod) { // loop over presence of lod argument
if ((lod && bias) || (lod == 0 && bias == 0))
continue;
for (int f16TexAddr = 0; f16TexAddr <= 1; ++f16TexAddr) { // loop over 16-bit floating-point texel addressing
if (f16TexAddr && sampler.type != EbtFloat16)
continue;
for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name: none, Offset, and Offsets
for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument
if (comp == 0 && bias)
continue;
if (offset > 0 && sampler.dim == EsdCube)
continue;
for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not
if (sparse && (profile == EEsProfile || version < 450))
continue;
TString s;
// return type
if (sparse)
s.append("int ");
else {
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
// name
if (sparse)
s.append("sparseTextureGather");
else
s.append("textureGather");
if (lod)
s.append("Lod");
switch (offset) {
case 1:
s.append("Offset");
break;
case 2:
s.append("Offsets");
break;
default:
break;
}
if (lod)
s.append("AMD");
else if (sparse)
s.append("ARB");
s.append("(");
// sampler type argument
s.append(typeName);
// P coordinate argument
if (f16TexAddr)
s.append(",f16vec");
else
s.append(",vec");
int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0);
s.append(postfixes[totalDims]);
// lod argument
if (lod) {
if (f16TexAddr)
s.append(",float16_t");
else
s.append(",float");
}
// offset argument
if (offset > 0) {
s.append(",ivec2");
if (offset == 2)
s.append("[4]");
}
// texel out (for sparse texture)
if (sparse) {
s.append(",out ");
s.append(prefixes[sampler.type]);
s.append("vec4 ");
}
// comp argument
if (comp)
s.append(",int");
// bias argument
if (bias) {
if (f16TexAddr)
s.append(",float16_t");
else
s.append(",float");
}
s.append(");\n");
if (bias)
stageBuiltins[EShLangFragment].append(s);
else
commonBuiltins.append(s);
}
}
}
}
}
}
}
//
// Add context-dependent built-in functions and variables that are present
// for the given version and profile. All the results are put into just the
// commonBuiltins, because it is called for just a specific stage. So,
// add stage-specific entries to the commonBuiltins, and only if that stage
// was requested.
//
void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language)
{
//
// Initialize the context-dependent (resource-dependent) built-in strings for parsing.
//
//============================================================================
//
// Standard Uniforms
//
//============================================================================
TString& s = commonBuiltins;
const int maxSize = 200;
char builtInConstant[maxSize];
//
// Build string of implementation dependent constants.
//
if (profile == EEsProfile) {
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
s.append(builtInConstant);
if (version == 100) {
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
s.append(builtInConstant);
} else {
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVertexOutputVectors = %d;", resources.maxVertexOutputVectors);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxFragmentInputVectors = %d;", resources.maxFragmentInputVectors);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
s.append(builtInConstant);
}
if (version >= 310) {
// geometry
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.maxGeometryAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.maxGeometryAtomicCounterBuffers);
s.append(builtInConstant);
// tessellation
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
s.append(builtInConstant);
// this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
if (language == EShLangTessControl || language == EShLangTessEvaluation) {
s.append(
"in gl_PerVertex {"
"highp vec4 gl_Position;"
"highp float gl_PointSize;"
"highp vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"highp vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
"} gl_in[gl_MaxPatchVertices];"
"\n");
}
}
if (version >= 320) {
// tessellation
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources.maxTessControlAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources.maxTessEvaluationAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources.maxTessControlAtomicCounterBuffers);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources.maxTessEvaluationAtomicCounterBuffers);
s.append(builtInConstant);
}
if (version >= 100) {
// GL_EXT_blend_func_extended
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxDualSourceDrawBuffersEXT = %d;", resources.maxDualSourceDrawBuffersEXT);
s.append(builtInConstant);
// this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxDualSourceDrawBuffersEXT
if (language == EShLangFragment) {
s.append(
"mediump vec4 gl_SecondaryFragColorEXT;"
"mediump vec4 gl_SecondaryFragDataEXT[gl_MaxDualSourceDrawBuffersEXT];"
"\n");
}
}
} else {
// non-ES profile
if (version > 400) {
snprintf(builtInConstant, maxSize, "const int gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors);
s.append(builtInConstant);
}
snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxLights = %d;", resources.maxLights);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxClipPlanes = %d;", resources.maxClipPlanes);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTextureUnits = %d;", resources.maxTextureUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTextureCoords = %d;", resources.maxTextureCoords);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxVertexUniformComponents = %d;", resources.maxVertexUniformComponents);
s.append(builtInConstant);
// Moved from just being deprecated into compatibility profile only as of 4.20
if (version < 420 || profile == ECompatibilityProfile) {
snprintf(builtInConstant, maxSize, "const int gl_MaxVaryingFloats = %d;", resources.maxVaryingFloats);
s.append(builtInConstant);
}
snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentUniformComponents = %d;", resources.maxFragmentUniformComponents);
s.append(builtInConstant);
if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) {
//
// OpenGL'uniform' state. Page numbers are in reference to version
// 1.4 of the OpenGL specification.
//
//
// Matrix state. p. 31, 32, 37, 39, 40.
//
s.append("uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];"
//
// Derived matrix state that provides inverse and transposed versions
// of the matrices above.
//
"uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];"
"uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];"
"uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];"
//
// Clip planes p. 42.
//
"uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];"
//
// Light State p 50, 53, 55.
//
"uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];"
//
// Derived state from products of light.
//
"uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];"
"uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];"
//
// Texture Environment and Generation, p. 152, p. 40-42.
//
"uniform vec4 gl_TextureEnvColor[gl_MaxTextureImageUnits];"
"uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];"
"uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];"
"uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];"
"uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];"
"uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];"
"uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];"
"uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];"
"uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];");
}
if (version >= 130) {
snprintf(builtInConstant, maxSize, "const int gl_MaxClipDistances = %d;", resources.maxClipDistances);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxVaryingComponents = %d;", resources.maxVaryingComponents);
s.append(builtInConstant);
// GL_ARB_shading_language_420pack
snprintf(builtInConstant, maxSize, "const mediump int gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const mediump int gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset);
s.append(builtInConstant);
}
// geometry
if (version >= 150) {
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryVaryingComponents = %d;", resources.maxGeometryVaryingComponents);
s.append(builtInConstant);
}
if (version >= 150) {
snprintf(builtInConstant, maxSize, "const int gl_MaxVertexOutputComponents = %d;", resources.maxVertexOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentInputComponents = %d;", resources.maxFragmentInputComponents);
s.append(builtInConstant);
}
// tessellation
if (version >= 150) {
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices);
s.append(builtInConstant);
// this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices
if (language == EShLangTessControl || language == EShLangTessEvaluation) {
s.append(
"in gl_PerVertex {"
"vec4 gl_Position;"
"float gl_PointSize;"
"float gl_ClipDistance[];"
);
if (profile == ECompatibilityProfile)
s.append(
"vec4 gl_ClipVertex;"
"vec4 gl_FrontColor;"
"vec4 gl_BackColor;"
"vec4 gl_FrontSecondaryColor;"
"vec4 gl_BackSecondaryColor;"
"vec4 gl_TexCoord[];"
"float gl_FogFragCoord;"
);
if (profile != EEsProfile && version >= 450)
s.append(
"float gl_CullDistance[];"
"vec4 gl_SecondaryPositionNV;" // GL_NV_stereo_view_rendering
"vec4 gl_PositionPerViewNV[];" // GL_NVX_multiview_per_view_attributes
);
s.append(
"} gl_in[gl_MaxPatchVertices];"
"\n");
}
}
if (version >= 150) {
snprintf(builtInConstant, maxSize, "const int gl_MaxViewports = %d;", resources.maxViewports);
s.append(builtInConstant);
}
// images
if (version >= 130) {
snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUnitsAndFragmentOutputs = %d;", resources.maxCombinedImageUnitsAndFragmentOutputs);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxImageSamples = %d;", resources.maxImageSamples);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms);
s.append(builtInConstant);
}
// enhanced layouts
if (version >= 430) {
snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackBuffers = %d;", resources.maxTransformFeedbackBuffers);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackInterleavedComponents = %d;", resources.maxTransformFeedbackInterleavedComponents);
s.append(builtInConstant);
}
}
// compute
if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupCount = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupCountX,
resources.maxComputeWorkGroupCountY,
resources.maxComputeWorkGroupCountZ);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupSize = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupSizeX,
resources.maxComputeWorkGroupSizeY,
resources.maxComputeWorkGroupSizeZ);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxComputeUniformComponents = %d;", resources.maxComputeUniformComponents);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxComputeTextureImageUnits = %d;", resources.maxComputeTextureImageUnits);
s.append(builtInConstant);
s.append("\n");
}
// images (some in compute below)
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 130)) {
snprintf(builtInConstant, maxSize, "const int gl_MaxImageUnits = %d;", resources.maxImageUnits);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedShaderOutputResources = %d;", resources.maxCombinedShaderOutputResources);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxVertexImageUniforms = %d;", resources.maxVertexImageUniforms);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentImageUniforms = %d;", resources.maxFragmentImageUniforms);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUniforms = %d;", resources.maxCombinedImageUniforms);
s.append(builtInConstant);
}
// compute
if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) {
snprintf(builtInConstant, maxSize, "const int gl_MaxComputeImageUniforms = %d;", resources.maxComputeImageUniforms);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounters = %d;", resources.maxComputeAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounterBuffers = %d;", resources.maxComputeAtomicCounterBuffers);
s.append(builtInConstant);
s.append("\n");
}
// atomic counters (some in compute below)
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 420)) {
snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounters = %d;", resources. maxVertexAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounters = %d;", resources. maxFragmentAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounters = %d;", resources. maxCombinedAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBindings = %d;", resources. maxAtomicCounterBindings);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounterBuffers = %d;", resources. maxVertexAtomicCounterBuffers);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounterBuffers = %d;", resources. maxFragmentAtomicCounterBuffers);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounterBuffers = %d;", resources. maxCombinedAtomicCounterBuffers);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBufferSize = %d;", resources. maxAtomicCounterBufferSize);
s.append(builtInConstant);
}
if (profile != EEsProfile && version >= 420) {
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources. maxTessControlAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources. maxTessEvaluationAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources. maxGeometryAtomicCounters);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources. maxTessControlAtomicCounterBuffers);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources. maxTessEvaluationAtomicCounterBuffers);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources. maxGeometryAtomicCounterBuffers);
s.append(builtInConstant);
s.append("\n");
}
// GL_ARB_cull_distance
if (profile != EEsProfile && version >= 450) {
snprintf(builtInConstant, maxSize, "const int gl_MaxCullDistances = %d;", resources.maxCullDistances);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedClipAndCullDistances = %d;", resources.maxCombinedClipAndCullDistances);
s.append(builtInConstant);
}
// GL_ARB_ES3_1_compatibility
if ((profile != EEsProfile && version >= 450) ||
(profile == EEsProfile && version >= 310)) {
snprintf(builtInConstant, maxSize, "const int gl_MaxSamples = %d;", resources.maxSamples);
s.append(builtInConstant);
}
// SPV_NV_mesh_shader
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputVerticesNV = %d;", resources.maxMeshOutputVerticesNV);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxMeshOutputPrimitivesNV = %d;", resources.maxMeshOutputPrimitivesNV);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxMeshWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxMeshWorkGroupSizeX_NV,
resources.maxMeshWorkGroupSizeY_NV,
resources.maxMeshWorkGroupSizeZ_NV);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxTaskWorkGroupSizeNV = ivec3(%d,%d,%d);", resources.maxTaskWorkGroupSizeX_NV,
resources.maxTaskWorkGroupSizeY_NV,
resources.maxTaskWorkGroupSizeZ_NV);
s.append(builtInConstant);
snprintf(builtInConstant, maxSize, "const int gl_MaxMeshViewCountNV = %d;", resources.maxMeshViewCountNV);
s.append(builtInConstant);
s.append("\n");
}
s.append("\n");
}
//
// To support special built-ins that have a special qualifier that cannot be declared textually
// in a shader, like gl_Position.
//
// This lets the type of the built-in be declared textually, and then have just its qualifier be
// updated afterward.
//
// Safe to call even if name is not present.
//
// Only use this for built-in variables that have a special qualifier in TStorageQualifier.
// New built-in variables should use a generic (textually declarable) qualifier in
// TStoraregQualifier and only call BuiltInVariable().
//
static void SpecialQualifier(const char* name, TStorageQualifier qualifier, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
{
TSymbol* symbol = symbolTable.find(name);
if (symbol == nullptr)
return;
TQualifier& symQualifier = symbol->getWritableType().getQualifier();
symQualifier.storage = qualifier;
symQualifier.builtIn = builtIn;
}
//
// Modify the symbol's flat decoration.
//
// Safe to call even if name is not present.
//
// Originally written to transform gl_SubGroupSizeARB from uniform to fragment input in Vulkan.
//
static void ModifyFlatDecoration(const char* name, bool flat, TSymbolTable& symbolTable)
{
TSymbol* symbol = symbolTable.find(name);
if (symbol == nullptr)
return;
TQualifier& symQualifier = symbol->getWritableType().getQualifier();
symQualifier.flat = flat;
}
//
// To tag built-in variables with their TBuiltInVariable enum. Use this when the
// normal declaration text already gets the qualifier right, and all that's needed
// is setting the builtIn field. This should be the normal way for all new
// built-in variables.
//
// If SpecialQualifier() was called, this does not need to be called.
//
// Safe to call even if name is not present.
//
static void BuiltInVariable(const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
{
TSymbol* symbol = symbolTable.find(name);
if (symbol == nullptr)
return;
TQualifier& symQualifier = symbol->getWritableType().getQualifier();
symQualifier.builtIn = builtIn;
}
static void RetargetVariable(const char* from, const char* to, TSymbolTable& symbolTable)
{
symbolTable.retargetSymbol(from, to);
}
//
// For built-in variables inside a named block.
// SpecialQualifier() won't ever go inside a block; their member's qualifier come
// from the qualification of the block.
//
// See comments above for other detail.
//
static void BuiltInVariable(const char* blockName, const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable)
{
TSymbol* symbol = symbolTable.find(blockName);
if (symbol == nullptr)
return;
TTypeList& structure = *symbol->getWritableType().getWritableStruct();
for (int i = 0; i < (int)structure.size(); ++i) {
if (structure[i].type->getFieldName().compare(name) == 0) {
structure[i].type->getQualifier().builtIn = builtIn;
return;
}
}
}
//
// Finish adding/processing context-independent built-in symbols.
// 1) Programmatically add symbols that could not be added by simple text strings above.
// 2) Map built-in functions to operators, for those that will turn into an operation node
// instead of remaining a function call.
// 3) Tag extension-related symbols added to their base version with their extensions, so
// that if an early version has the extension turned off, there is an error reported on use.
//
void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable)
{
//
// Tag built-in variables and functions with additional qualifier and extension information
// that cannot be declared with the text strings.
//
// N.B.: a symbol should only be tagged once, and this function is called multiple times, once
// per stage that's used for this profile. So
// - generally, stick common ones in the fragment stage to ensure they are tagged exactly once
// - for ES, which has different precisions for different stages, the coarsest-grained tagging
// for a built-in used in many stages needs to be once for the fragment stage and once for
// the vertex stage
switch(language) {
case EShLangVertex:
if (spvVersion.vulkan > 0) {
BuiltInVariable("gl_VertexIndex", EbvVertexIndex, symbolTable);
BuiltInVariable("gl_InstanceIndex", EbvInstanceIndex, symbolTable);
}
if (spvVersion.vulkan == 0) {
SpecialQualifier("gl_VertexID", EvqVertexId, EbvVertexId, symbolTable);
SpecialQualifier("gl_InstanceID", EvqInstanceId, EbvInstanceId, symbolTable);
if (version < 140)
symbolTable.setVariableExtensions("gl_InstanceID", 1, &E_GL_EXT_draw_instanced);
}
if (spvVersion.vulkan > 0 && spvVersion.vulkanRelaxed) {
// treat these built-ins as aliases of VertexIndex and InstanceIndex
RetargetVariable("gl_InstanceID", "gl_InstanceIndex", symbolTable);
RetargetVariable("gl_VertexID", "gl_VertexIndex", symbolTable);
}
if (profile != EEsProfile) {
if (version >= 440) {
symbolTable.setVariableExtensions("gl_BaseVertexARB", 1, &E_GL_ARB_shader_draw_parameters);
symbolTable.setVariableExtensions("gl_BaseInstanceARB", 1, &E_GL_ARB_shader_draw_parameters);
symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
BuiltInVariable("gl_BaseVertexARB", EbvBaseVertex, symbolTable);
BuiltInVariable("gl_BaseInstanceARB", EbvBaseInstance, symbolTable);
BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
}
if (version >= 460) {
BuiltInVariable("gl_BaseVertex", EbvBaseVertex, symbolTable);
BuiltInVariable("gl_BaseInstance", EbvBaseInstance, symbolTable);
BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
}
symbolTable.setVariableExtensions("gl_SubGroupSizeARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setFunctionExtensions("ballotARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setFunctionExtensions("readInvocationARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setFunctionExtensions("readFirstInvocationARB", 1, &E_GL_ARB_shader_ballot);
if (version >= 430) {
symbolTable.setFunctionExtensions("anyInvocationARB", 1, &E_GL_ARB_shader_group_vote);
symbolTable.setFunctionExtensions("allInvocationsARB", 1, &E_GL_ARB_shader_group_vote);
symbolTable.setFunctionExtensions("allInvocationsEqualARB", 1, &E_GL_ARB_shader_group_vote);
}
}
if (profile != EEsProfile) {
symbolTable.setFunctionExtensions("minInvocationsAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("maxInvocationsAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("addInvocationsAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("minInvocationsNonUniformAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("maxInvocationsNonUniformAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("addInvocationsNonUniformAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("swizzleInvocationsAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("swizzleInvocationsWithPatternAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("writeInvocationAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("mbcntAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("minInvocationsInclusiveScanAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("addInvocationsInclusiveScanAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("minInvocationsInclusiveScanNonUniformAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("maxInvocationsInclusiveScanNonUniformAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("addInvocationsInclusiveScanNonUniformAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("minInvocationsExclusiveScanAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("addInvocationsExclusiveScanAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("minInvocationsExclusiveScanNonUniformAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("maxInvocationsExclusiveScanNonUniformAMD", 1, &E_GL_AMD_shader_ballot);
symbolTable.setFunctionExtensions("addInvocationsExclusiveScanNonUniformAMD", 1, &E_GL_AMD_shader_ballot);
}
if (profile != EEsProfile) {
symbolTable.setFunctionExtensions("min3", 1, &E_GL_AMD_shader_trinary_minmax);
symbolTable.setFunctionExtensions("max3", 1, &E_GL_AMD_shader_trinary_minmax);
symbolTable.setFunctionExtensions("mid3", 1, &E_GL_AMD_shader_trinary_minmax);
}
if (profile != EEsProfile) {
symbolTable.setVariableExtensions("gl_SIMDGroupSizeAMD", 1, &E_GL_AMD_gcn_shader);
SpecialQualifier("gl_SIMDGroupSizeAMD", EvqVaryingIn, EbvSubGroupSize, symbolTable);
symbolTable.setFunctionExtensions("cubeFaceIndexAMD", 1, &E_GL_AMD_gcn_shader);
symbolTable.setFunctionExtensions("cubeFaceCoordAMD", 1, &E_GL_AMD_gcn_shader);
symbolTable.setFunctionExtensions("timeAMD", 1, &E_GL_AMD_gcn_shader);
}
if (profile != EEsProfile) {
symbolTable.setFunctionExtensions("fragmentMaskFetchAMD", 1, &E_GL_AMD_shader_fragment_mask);
symbolTable.setFunctionExtensions("fragmentFetchAMD", 1, &E_GL_AMD_shader_fragment_mask);
}
symbolTable.setFunctionExtensions("countLeadingZeros", 1, &E_GL_INTEL_shader_integer_functions2);
symbolTable.setFunctionExtensions("countTrailingZeros", 1, &E_GL_INTEL_shader_integer_functions2);
symbolTable.setFunctionExtensions("absoluteDifference", 1, &E_GL_INTEL_shader_integer_functions2);
symbolTable.setFunctionExtensions("addSaturate", 1, &E_GL_INTEL_shader_integer_functions2);
symbolTable.setFunctionExtensions("subtractSaturate", 1, &E_GL_INTEL_shader_integer_functions2);
symbolTable.setFunctionExtensions("average", 1, &E_GL_INTEL_shader_integer_functions2);
symbolTable.setFunctionExtensions("averageRounded", 1, &E_GL_INTEL_shader_integer_functions2);
symbolTable.setFunctionExtensions("multiply32x16", 1, &E_GL_INTEL_shader_integer_functions2);
symbolTable.setFunctionExtensions("textureFootprintNV", 1, &E_GL_NV_shader_texture_footprint);
symbolTable.setFunctionExtensions("textureFootprintClampNV", 1, &E_GL_NV_shader_texture_footprint);
symbolTable.setFunctionExtensions("textureFootprintLodNV", 1, &E_GL_NV_shader_texture_footprint);
symbolTable.setFunctionExtensions("textureFootprintGradNV", 1, &E_GL_NV_shader_texture_footprint);
symbolTable.setFunctionExtensions("textureFootprintGradClampNV", 1, &E_GL_NV_shader_texture_footprint);
// Compatibility variables, vertex only
if (spvVersion.spv == 0) {
BuiltInVariable("gl_Color", EbvColor, symbolTable);
BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
BuiltInVariable("gl_Normal", EbvNormal, symbolTable);
BuiltInVariable("gl_Vertex", EbvVertex, symbolTable);
BuiltInVariable("gl_MultiTexCoord0", EbvMultiTexCoord0, symbolTable);
BuiltInVariable("gl_MultiTexCoord1", EbvMultiTexCoord1, symbolTable);
BuiltInVariable("gl_MultiTexCoord2", EbvMultiTexCoord2, symbolTable);
BuiltInVariable("gl_MultiTexCoord3", EbvMultiTexCoord3, symbolTable);
BuiltInVariable("gl_MultiTexCoord4", EbvMultiTexCoord4, symbolTable);
BuiltInVariable("gl_MultiTexCoord5", EbvMultiTexCoord5, symbolTable);
BuiltInVariable("gl_MultiTexCoord6", EbvMultiTexCoord6, symbolTable);
BuiltInVariable("gl_MultiTexCoord7", EbvMultiTexCoord7, symbolTable);
BuiltInVariable("gl_FogCoord", EbvFogFragCoord, symbolTable);
}
if (profile == EEsProfile) {
if (spvVersion.spv == 0) {
symbolTable.setFunctionExtensions("texture2DGradEXT", 1, &E_GL_EXT_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
symbolTable.setFunctionExtensions("textureCubeGradEXT", 1, &E_GL_EXT_shader_texture_lod);
if (version == 310)
symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
}
if (version == 310)
symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
}
if (profile == EEsProfile && version < 320) {
symbolTable.setFunctionExtensions("imageAtomicAdd", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicMin", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicMax", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicAnd", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicOr", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicXor", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
}
if (version >= 300 /* both ES and non-ES */) {
symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
}
if (profile == EEsProfile) {
symbolTable.setFunctionExtensions("shadow2DEXT", 1, &E_GL_EXT_shadow_samplers);
symbolTable.setFunctionExtensions("shadow2DProjEXT", 1, &E_GL_EXT_shadow_samplers);
}
// E_GL_EXT_texture_array
if (profile != EEsProfile && spvVersion.spv == 0) {
symbolTable.setFunctionExtensions("texture1DArray", 1, &E_GL_EXT_texture_array);
symbolTable.setFunctionExtensions("texture2DArray", 1, &E_GL_EXT_texture_array);
symbolTable.setFunctionExtensions("shadow1DArray", 1, &E_GL_EXT_texture_array);
symbolTable.setFunctionExtensions("shadow2DArray", 1, &E_GL_EXT_texture_array);
symbolTable.setFunctionExtensions("texture1DArrayLod", 1, &E_GL_EXT_texture_array);
symbolTable.setFunctionExtensions("texture2DArrayLod", 1, &E_GL_EXT_texture_array);
symbolTable.setFunctionExtensions("shadow1DArrayLod", 1, &E_GL_EXT_texture_array);
}
[[fallthrough]];
case EShLangTessControl:
if (profile == EEsProfile && version >= 310) {
BuiltInVariable("gl_BoundingBoxEXT", EbvBoundingBox, symbolTable);
symbolTable.setVariableExtensions("gl_BoundingBoxEXT", 1,
&E_GL_EXT_primitive_bounding_box);
BuiltInVariable("gl_BoundingBoxOES", EbvBoundingBox, symbolTable);
symbolTable.setVariableExtensions("gl_BoundingBoxOES", 1,
&E_GL_OES_primitive_bounding_box);
if (version >= 320) {
BuiltInVariable("gl_BoundingBox", EbvBoundingBox, symbolTable);
}
}
[[fallthrough]];
case EShLangTessEvaluation:
case EShLangGeometry:
SpecialQualifier("gl_Position", EvqPosition, EbvPosition, symbolTable);
SpecialQualifier("gl_PointSize", EvqPointSize, EbvPointSize, symbolTable);
BuiltInVariable("gl_in", "gl_Position", EbvPosition, symbolTable);
BuiltInVariable("gl_in", "gl_PointSize", EbvPointSize, symbolTable);
BuiltInVariable("gl_out", "gl_Position", EbvPosition, symbolTable);
BuiltInVariable("gl_out", "gl_PointSize", EbvPointSize, symbolTable);
SpecialQualifier("gl_ClipVertex", EvqClipVertex, EbvClipVertex, symbolTable);
BuiltInVariable("gl_in", "gl_ClipDistance", EbvClipDistance, symbolTable);
BuiltInVariable("gl_in", "gl_CullDistance", EbvCullDistance, symbolTable);
BuiltInVariable("gl_out", "gl_ClipDistance", EbvClipDistance, symbolTable);
BuiltInVariable("gl_out", "gl_CullDistance", EbvCullDistance, symbolTable);
BuiltInVariable("gl_ClipDistance", EbvClipDistance, symbolTable);
BuiltInVariable("gl_CullDistance", EbvCullDistance, symbolTable);
BuiltInVariable("gl_PrimitiveIDIn", EbvPrimitiveId, symbolTable);
BuiltInVariable("gl_PrimitiveID", EbvPrimitiveId, symbolTable);
BuiltInVariable("gl_InvocationID", EbvInvocationId, symbolTable);
BuiltInVariable("gl_Layer", EbvLayer, symbolTable);
BuiltInVariable("gl_ViewportIndex", EbvViewportIndex, symbolTable);
if (language != EShLangGeometry) {
symbolTable.setVariableExtensions("gl_Layer", Num_viewportEXTs, viewportEXTs);
symbolTable.setVariableExtensions("gl_ViewportIndex", Num_viewportEXTs, viewportEXTs);
}
symbolTable.setVariableExtensions("gl_ViewportMask", 1, &E_GL_NV_viewport_array2);
symbolTable.setVariableExtensions("gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
symbolTable.setVariableExtensions("gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
symbolTable.setVariableExtensions("gl_PositionPerViewNV", 1, &E_GL_NVX_multiview_per_view_attributes);
symbolTable.setVariableExtensions("gl_ViewportMaskPerViewNV", 1, &E_GL_NVX_multiview_per_view_attributes);
BuiltInVariable("gl_ViewportMask", EbvViewportMaskNV, symbolTable);
BuiltInVariable("gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
BuiltInVariable("gl_SecondaryViewportMaskNV", EbvSecondaryViewportMaskNV, symbolTable);
BuiltInVariable("gl_PositionPerViewNV", EbvPositionPerViewNV, symbolTable);
BuiltInVariable("gl_ViewportMaskPerViewNV", EbvViewportMaskPerViewNV, symbolTable);
if (language == EShLangVertex || language == EShLangGeometry) {
symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV", 1, &E_GL_NVX_multiview_per_view_attributes);
BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
BuiltInVariable("gl_in", "gl_PositionPerViewNV", EbvPositionPerViewNV, symbolTable);
}
symbolTable.setVariableExtensions("gl_out", "gl_ViewportMask", 1, &E_GL_NV_viewport_array2);
symbolTable.setVariableExtensions("gl_out", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
symbolTable.setVariableExtensions("gl_out", "gl_SecondaryViewportMaskNV", 1, &E_GL_NV_stereo_view_rendering);
symbolTable.setVariableExtensions("gl_out", "gl_PositionPerViewNV", 1, &E_GL_NVX_multiview_per_view_attributes);
symbolTable.setVariableExtensions("gl_out", "gl_ViewportMaskPerViewNV", 1, &E_GL_NVX_multiview_per_view_attributes);
BuiltInVariable("gl_out", "gl_ViewportMask", EbvViewportMaskNV, symbolTable);
BuiltInVariable("gl_out", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
BuiltInVariable("gl_out", "gl_SecondaryViewportMaskNV", EbvSecondaryViewportMaskNV, symbolTable);
BuiltInVariable("gl_out", "gl_PositionPerViewNV", EbvPositionPerViewNV, symbolTable);
BuiltInVariable("gl_out", "gl_ViewportMaskPerViewNV", EbvViewportMaskPerViewNV, symbolTable);
BuiltInVariable("gl_PatchVerticesIn", EbvPatchVertices, symbolTable);
BuiltInVariable("gl_TessLevelOuter", EbvTessLevelOuter, symbolTable);
BuiltInVariable("gl_TessLevelInner", EbvTessLevelInner, symbolTable);
BuiltInVariable("gl_TessCoord", EbvTessCoord, symbolTable);
if (version < 410)
symbolTable.setVariableExtensions("gl_ViewportIndex", 1, &E_GL_ARB_viewport_array);
// Compatibility variables
BuiltInVariable("gl_in", "gl_ClipVertex", EbvClipVertex, symbolTable);
BuiltInVariable("gl_in", "gl_FrontColor", EbvFrontColor, symbolTable);
BuiltInVariable("gl_in", "gl_BackColor", EbvBackColor, symbolTable);
BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
BuiltInVariable("gl_in", "gl_BackSecondaryColor", EbvBackSecondaryColor, symbolTable);
BuiltInVariable("gl_in", "gl_TexCoord", EbvTexCoord, symbolTable);
BuiltInVariable("gl_in", "gl_FogFragCoord", EbvFogFragCoord, symbolTable);
BuiltInVariable("gl_out", "gl_ClipVertex", EbvClipVertex, symbolTable);
BuiltInVariable("gl_out", "gl_FrontColor", EbvFrontColor, symbolTable);
BuiltInVariable("gl_out", "gl_BackColor", EbvBackColor, symbolTable);
BuiltInVariable("gl_out", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
BuiltInVariable("gl_out", "gl_BackSecondaryColor", EbvBackSecondaryColor, symbolTable);
BuiltInVariable("gl_out", "gl_TexCoord", EbvTexCoord, symbolTable);
BuiltInVariable("gl_out", "gl_FogFragCoord", EbvFogFragCoord, symbolTable);
BuiltInVariable("gl_ClipVertex", EbvClipVertex, symbolTable);
BuiltInVariable("gl_FrontColor", EbvFrontColor, symbolTable);
BuiltInVariable("gl_BackColor", EbvBackColor, symbolTable);
BuiltInVariable("gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
BuiltInVariable("gl_BackSecondaryColor", EbvBackSecondaryColor, symbolTable);
BuiltInVariable("gl_TexCoord", EbvTexCoord, symbolTable);
BuiltInVariable("gl_FogFragCoord", EbvFogFragCoord, symbolTable);
// gl_PointSize, when it needs to be tied to an extension, is always a member of a block.
// (Sometimes with an instance name, sometimes anonymous).
if (profile == EEsProfile) {
if (language == EShLangGeometry) {
symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size);
} else if (language == EShLangTessEvaluation || language == EShLangTessControl) {
// gl_in tessellation settings of gl_PointSize are in the context-dependent paths
symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
symbolTable.setVariableExtensions("gl_out", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
}
}
if ((profile != EEsProfile && version >= 140) ||
(profile == EEsProfile && version >= 310)) {
symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
}
if (profile != EEsProfile) {
BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
BuiltInVariable("gl_SubGroupEqMaskARB", EbvSubGroupEqMask, symbolTable);
BuiltInVariable("gl_SubGroupGeMaskARB", EbvSubGroupGeMask, symbolTable);
BuiltInVariable("gl_SubGroupGtMaskARB", EbvSubGroupGtMask, symbolTable);
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}
// GL_KHR_shader_subgroup
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.setVariableExtensions("gl_SubgroupSize", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupEqMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
BuiltInVariable("gl_SubgroupSize", EbvSubgroupSize2, symbolTable);
BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
BuiltInVariable("gl_SubgroupEqMask", EbvSubgroupEqMask2, symbolTable);
BuiltInVariable("gl_SubgroupGeMask", EbvSubgroupGeMask2, symbolTable);
BuiltInVariable("gl_SubgroupGtMask", EbvSubgroupGtMask2, symbolTable);
BuiltInVariable("gl_SubgroupLeMask", EbvSubgroupLeMask2, symbolTable);
BuiltInVariable("gl_SubgroupLtMask", EbvSubgroupLtMask2, symbolTable);
// GL_NV_shader_sm_builtins
symbolTable.setVariableExtensions("gl_WarpsPerSMNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMCountNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_WarpIDNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMIDNV", 1, &E_GL_NV_shader_sm_builtins);
BuiltInVariable("gl_WarpsPerSMNV", EbvWarpsPerSM, symbolTable);
BuiltInVariable("gl_SMCountNV", EbvSMCount, symbolTable);
BuiltInVariable("gl_WarpIDNV", EbvWarpID, symbolTable);
BuiltInVariable("gl_SMIDNV", EbvSMID, symbolTable);
// GL_ARM_shader_core_builtins
symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
BuiltInVariable("gl_CoreIDARM", EbvCoreIDARM, symbolTable);
BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
BuiltInVariable("gl_WarpIDARM", EbvWarpIDARM, symbolTable);
BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
}
if (language == EShLangGeometry || language == EShLangVertex) {
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 450)) {
symbolTable.setVariableExtensions("gl_PrimitiveShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
BuiltInVariable("gl_PrimitiveShadingRateEXT", EbvPrimitiveShadingRateKHR, symbolTable);
symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
}
}
break;
case EShLangFragment:
SpecialQualifier("gl_FrontFacing", EvqFace, EbvFace, symbolTable);
SpecialQualifier("gl_FragCoord", EvqFragCoord, EbvFragCoord, symbolTable);
SpecialQualifier("gl_PointCoord", EvqPointCoord, EbvPointCoord, symbolTable);
if (spvVersion.spv == 0)
SpecialQualifier("gl_FragColor", EvqFragColor, EbvFragColor, symbolTable);
else {
TSymbol* symbol = symbolTable.find("gl_FragColor");
if (symbol) {
symbol->getWritableType().getQualifier().storage = EvqVaryingOut;
symbol->getWritableType().getQualifier().layoutLocation = 0;
}
}
SpecialQualifier("gl_FragDepth", EvqFragDepth, EbvFragDepth, symbolTable);
SpecialQualifier("gl_FragDepthEXT", EvqFragDepth, EbvFragDepth, symbolTable);
SpecialQualifier("gl_FragStencilRefARB", EvqFragStencil, EbvFragStencilRef, symbolTable);
SpecialQualifier("gl_HelperInvocation", EvqVaryingIn, EbvHelperInvocation, symbolTable);
BuiltInVariable("gl_ClipDistance", EbvClipDistance, symbolTable);
BuiltInVariable("gl_CullDistance", EbvCullDistance, symbolTable);
BuiltInVariable("gl_PrimitiveID", EbvPrimitiveId, symbolTable);
if (profile != EEsProfile && version >= 140) {
symbolTable.setVariableExtensions("gl_FragStencilRefARB", 1, &E_GL_ARB_shader_stencil_export);
BuiltInVariable("gl_FragStencilRefARB", EbvFragStencilRef, symbolTable);
}
if (profile != EEsProfile && version < 400) {
symbolTable.setFunctionExtensions("textureQueryLOD", 1, &E_GL_ARB_texture_query_lod);
}
if (profile != EEsProfile && version >= 460) {
symbolTable.setFunctionExtensions("rayQueryInitializeEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryTerminateEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGenerateIntersectionEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryConfirmIntersectionEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryProceedEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionTypeEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionTEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetRayFlagsEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetRayTMinEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceCustomIndexEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceIdEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionGeometryIndexEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionPrimitiveIndexEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionBarycentricsEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionFrontFaceEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionCandidateAABBOpaqueEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayDirectionEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectRayOriginEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionObjectToWorldEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionWorldToObjectEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetWorldRayOriginEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetWorldRayDirectionEXT", 1, &E_GL_EXT_ray_query);
symbolTable.setFunctionExtensions("rayQueryGetIntersectionTriangleVertexPositionsEXT", 1, &E_GL_EXT_ray_tracing_position_fetch);
symbolTable.setVariableExtensions("gl_RayFlagsSkipAABBEXT", 1, &E_GL_EXT_ray_flags_primitive_culling);
symbolTable.setVariableExtensions("gl_RayFlagsSkipTrianglesEXT", 1, &E_GL_EXT_ray_flags_primitive_culling);
symbolTable.setVariableExtensions("gl_RayFlagsForceOpacityMicromap2StateEXT", 1, &E_GL_EXT_opacity_micromap);
}
if ((profile != EEsProfile && version >= 130) ||
(profile == EEsProfile && version >= 310)) {
BuiltInVariable("gl_SampleID", EbvSampleId, symbolTable);
BuiltInVariable("gl_SamplePosition", EbvSamplePosition, symbolTable);
BuiltInVariable("gl_SampleMask", EbvSampleMask, symbolTable);
if (profile != EEsProfile && version < 400) {
BuiltInVariable("gl_NumSamples", EbvSampleMask, symbolTable);
symbolTable.setVariableExtensions("gl_SampleMask", 1, &E_GL_ARB_sample_shading);
symbolTable.setVariableExtensions("gl_SampleID", 1, &E_GL_ARB_sample_shading);
symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_ARB_sample_shading);
symbolTable.setVariableExtensions("gl_NumSamples", 1, &E_GL_ARB_sample_shading);
} else {
BuiltInVariable("gl_SampleMaskIn", EbvSampleMask, symbolTable);
if (profile == EEsProfile && version < 320) {
symbolTable.setVariableExtensions("gl_SampleID", 1, &E_GL_OES_sample_variables);
symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_OES_sample_variables);
symbolTable.setVariableExtensions("gl_SampleMaskIn", 1, &E_GL_OES_sample_variables);
symbolTable.setVariableExtensions("gl_SampleMask", 1, &E_GL_OES_sample_variables);
symbolTable.setVariableExtensions("gl_NumSamples", 1, &E_GL_OES_sample_variables);
}
}
}
BuiltInVariable("gl_Layer", EbvLayer, symbolTable);
BuiltInVariable("gl_ViewportIndex", EbvViewportIndex, symbolTable);
// Compatibility variables
BuiltInVariable("gl_in", "gl_FogFragCoord", EbvFogFragCoord, symbolTable);
BuiltInVariable("gl_in", "gl_TexCoord", EbvTexCoord, symbolTable);
BuiltInVariable("gl_in", "gl_Color", EbvColor, symbolTable);
BuiltInVariable("gl_in", "gl_SecondaryColor", EbvSecondaryColor, symbolTable);
BuiltInVariable("gl_FogFragCoord", EbvFogFragCoord, symbolTable);
BuiltInVariable("gl_TexCoord", EbvTexCoord, symbolTable);
BuiltInVariable("gl_Color", EbvColor, symbolTable);
BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable);
// built-in functions
if (profile == EEsProfile) {
if (spvVersion.spv == 0) {
symbolTable.setFunctionExtensions("texture2DLodEXT", 1, &E_GL_EXT_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DProjLodEXT", 1, &E_GL_EXT_shader_texture_lod);
symbolTable.setFunctionExtensions("textureCubeLodEXT", 1, &E_GL_EXT_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DGradEXT", 1, &E_GL_EXT_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod);
symbolTable.setFunctionExtensions("textureCubeGradEXT", 1, &E_GL_EXT_shader_texture_lod);
if (version < 320)
symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5);
}
if (version == 100) {
symbolTable.setFunctionExtensions("dFdx", 1, &E_GL_OES_standard_derivatives);
symbolTable.setFunctionExtensions("dFdy", 1, &E_GL_OES_standard_derivatives);
symbolTable.setFunctionExtensions("fwidth", 1, &E_GL_OES_standard_derivatives);
}
if (version == 310) {
symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5);
symbolTable.setFunctionExtensions("interpolateAtCentroid", 1, &E_GL_OES_shader_multisample_interpolation);
symbolTable.setFunctionExtensions("interpolateAtSample", 1, &E_GL_OES_shader_multisample_interpolation);
symbolTable.setFunctionExtensions("interpolateAtOffset", 1, &E_GL_OES_shader_multisample_interpolation);
}
} else if (version < 130) {
if (spvVersion.spv == 0) {
symbolTable.setFunctionExtensions("texture1DLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture3DLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("textureCubeLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture1DProjLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DProjLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture3DProjLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow1DLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow2DLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow1DProjLod", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow2DProjLod", 1, &E_GL_ARB_shader_texture_lod);
}
}
// E_GL_ARB_shader_texture_lod functions usable only with the extension enabled
if (profile != EEsProfile && spvVersion.spv == 0) {
symbolTable.setFunctionExtensions("texture1DGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture1DProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture3DGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture3DProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("textureCubeGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow1DGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow1DProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow2DGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow2DProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DRectGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("texture2DRectProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow2DRectGradARB", 1, &E_GL_ARB_shader_texture_lod);
symbolTable.setFunctionExtensions("shadow2DRectProjGradARB", 1, &E_GL_ARB_shader_texture_lod);
}
// E_GL_ARB_shader_image_load_store
if (profile != EEsProfile && version < 420)
symbolTable.setFunctionExtensions("memoryBarrier", 1, &E_GL_ARB_shader_image_load_store);
// All the image access functions are protected by checks on the type of the first argument.
// E_GL_ARB_shader_atomic_counters
if (profile != EEsProfile && version < 420) {
symbolTable.setFunctionExtensions("atomicCounterIncrement", 1, &E_GL_ARB_shader_atomic_counters);
symbolTable.setFunctionExtensions("atomicCounterDecrement", 1, &E_GL_ARB_shader_atomic_counters);
symbolTable.setFunctionExtensions("atomicCounter" , 1, &E_GL_ARB_shader_atomic_counters);
}
// E_GL_ARB_shader_atomic_counter_ops
if (profile != EEsProfile && version == 450) {
symbolTable.setFunctionExtensions("atomicCounterAddARB" , 1, &E_GL_ARB_shader_atomic_counter_ops);
symbolTable.setFunctionExtensions("atomicCounterSubtractARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
symbolTable.setFunctionExtensions("atomicCounterMinARB" , 1, &E_GL_ARB_shader_atomic_counter_ops);
symbolTable.setFunctionExtensions("atomicCounterMaxARB" , 1, &E_GL_ARB_shader_atomic_counter_ops);
symbolTable.setFunctionExtensions("atomicCounterAndARB" , 1, &E_GL_ARB_shader_atomic_counter_ops);
symbolTable.setFunctionExtensions("atomicCounterOrARB" , 1, &E_GL_ARB_shader_atomic_counter_ops);
symbolTable.setFunctionExtensions("atomicCounterXorARB" , 1, &E_GL_ARB_shader_atomic_counter_ops);
symbolTable.setFunctionExtensions("atomicCounterExchangeARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
symbolTable.setFunctionExtensions("atomicCounterCompSwapARB", 1, &E_GL_ARB_shader_atomic_counter_ops);
}
// E_GL_ARB_derivative_control
if (profile != EEsProfile && version < 450) {
symbolTable.setFunctionExtensions("dFdxFine", 1, &E_GL_ARB_derivative_control);
symbolTable.setFunctionExtensions("dFdyFine", 1, &E_GL_ARB_derivative_control);
symbolTable.setFunctionExtensions("fwidthFine", 1, &E_GL_ARB_derivative_control);
symbolTable.setFunctionExtensions("dFdxCoarse", 1, &E_GL_ARB_derivative_control);
symbolTable.setFunctionExtensions("dFdyCoarse", 1, &E_GL_ARB_derivative_control);
symbolTable.setFunctionExtensions("fwidthCoarse", 1, &E_GL_ARB_derivative_control);
}
// E_GL_ARB_sparse_texture2
if (profile != EEsProfile)
{
symbolTable.setFunctionExtensions("sparseTextureARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureLodARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTexelFetchARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTexelFetchOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureLodOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGradARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGradOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGatherARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGatherOffsetARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTextureGatherOffsetsARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseImageLoadARB", 1, &E_GL_ARB_sparse_texture2);
symbolTable.setFunctionExtensions("sparseTexelsResident", 1, &E_GL_ARB_sparse_texture2);
}
// E_GL_ARB_sparse_texture_clamp
if (profile != EEsProfile)
{
symbolTable.setFunctionExtensions("sparseTextureClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("sparseTextureOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("sparseTextureGradClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("sparseTextureGradOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("textureClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("textureOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("textureGradClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
symbolTable.setFunctionExtensions("textureGradOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp);
}
// E_GL_AMD_shader_explicit_vertex_parameter
if (profile != EEsProfile) {
symbolTable.setVariableExtensions("gl_BaryCoordNoPerspAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
symbolTable.setVariableExtensions("gl_BaryCoordNoPerspCentroidAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
symbolTable.setVariableExtensions("gl_BaryCoordNoPerspSampleAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
symbolTable.setVariableExtensions("gl_BaryCoordSmoothAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
symbolTable.setVariableExtensions("gl_BaryCoordSmoothCentroidAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
symbolTable.setVariableExtensions("gl_BaryCoordSmoothSampleAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
symbolTable.setVariableExtensions("gl_BaryCoordPullModelAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
symbolTable.setFunctionExtensions("interpolateAtVertexAMD", 1, &E_GL_AMD_shader_explicit_vertex_parameter);
BuiltInVariable("gl_BaryCoordNoPerspAMD", EbvBaryCoordNoPersp, symbolTable);
BuiltInVariable("gl_BaryCoordNoPerspCentroidAMD", EbvBaryCoordNoPerspCentroid, symbolTable);
BuiltInVariable("gl_BaryCoordNoPerspSampleAMD", EbvBaryCoordNoPerspSample, symbolTable);
BuiltInVariable("gl_BaryCoordSmoothAMD", EbvBaryCoordSmooth, symbolTable);
BuiltInVariable("gl_BaryCoordSmoothCentroidAMD", EbvBaryCoordSmoothCentroid, symbolTable);
BuiltInVariable("gl_BaryCoordSmoothSampleAMD", EbvBaryCoordSmoothSample, symbolTable);
BuiltInVariable("gl_BaryCoordPullModelAMD", EbvBaryCoordPullModel, symbolTable);
}
// E_GL_AMD_texture_gather_bias_lod
if (profile != EEsProfile) {
symbolTable.setFunctionExtensions("textureGatherLodAMD", 1, &E_GL_AMD_texture_gather_bias_lod);
symbolTable.setFunctionExtensions("textureGatherLodOffsetAMD", 1, &E_GL_AMD_texture_gather_bias_lod);
symbolTable.setFunctionExtensions("textureGatherLodOffsetsAMD", 1, &E_GL_AMD_texture_gather_bias_lod);
symbolTable.setFunctionExtensions("sparseTextureGatherLodAMD", 1, &E_GL_AMD_texture_gather_bias_lod);
symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetAMD", 1, &E_GL_AMD_texture_gather_bias_lod);
symbolTable.setFunctionExtensions("sparseTextureGatherLodOffsetsAMD", 1, &E_GL_AMD_texture_gather_bias_lod);
}
// E_GL_AMD_shader_image_load_store_lod
if (profile != EEsProfile) {
symbolTable.setFunctionExtensions("imageLoadLodAMD", 1, &E_GL_AMD_shader_image_load_store_lod);
symbolTable.setFunctionExtensions("imageStoreLodAMD", 1, &E_GL_AMD_shader_image_load_store_lod);
symbolTable.setFunctionExtensions("sparseImageLoadLodAMD", 1, &E_GL_AMD_shader_image_load_store_lod);
}
if (profile != EEsProfile && version >= 430) {
symbolTable.setVariableExtensions("gl_FragFullyCoveredNV", 1, &E_GL_NV_conservative_raster_underestimation);
BuiltInVariable("gl_FragFullyCoveredNV", EbvFragFullyCoveredNV, symbolTable);
}
if ((profile != EEsProfile && version >= 450) ||
(profile == EEsProfile && version >= 320)) {
symbolTable.setVariableExtensions("gl_FragmentSizeNV", 1, &E_GL_NV_shading_rate_image);
symbolTable.setVariableExtensions("gl_InvocationsPerPixelNV", 1, &E_GL_NV_shading_rate_image);
BuiltInVariable("gl_FragmentSizeNV", EbvFragmentSizeNV, symbolTable);
BuiltInVariable("gl_InvocationsPerPixelNV", EbvInvocationsPerPixelNV, symbolTable);
symbolTable.setVariableExtensions("gl_BaryCoordNV", 1, &E_GL_NV_fragment_shader_barycentric);
symbolTable.setVariableExtensions("gl_BaryCoordNoPerspNV", 1, &E_GL_NV_fragment_shader_barycentric);
BuiltInVariable("gl_BaryCoordNV", EbvBaryCoordNV, symbolTable);
BuiltInVariable("gl_BaryCoordNoPerspNV", EbvBaryCoordNoPerspNV, symbolTable);
symbolTable.setVariableExtensions("gl_BaryCoordEXT", 1, &E_GL_EXT_fragment_shader_barycentric);
symbolTable.setVariableExtensions("gl_BaryCoordNoPerspEXT", 1, &E_GL_EXT_fragment_shader_barycentric);
BuiltInVariable("gl_BaryCoordEXT", EbvBaryCoordEXT, symbolTable);
BuiltInVariable("gl_BaryCoordNoPerspEXT", EbvBaryCoordNoPerspEXT, symbolTable);
}
if ((profile != EEsProfile && version >= 450) ||
(profile == EEsProfile && version >= 310)) {
symbolTable.setVariableExtensions("gl_FragSizeEXT", 1, &E_GL_EXT_fragment_invocation_density);
symbolTable.setVariableExtensions("gl_FragInvocationCountEXT", 1, &E_GL_EXT_fragment_invocation_density);
BuiltInVariable("gl_FragSizeEXT", EbvFragSizeEXT, symbolTable);
BuiltInVariable("gl_FragInvocationCountEXT", EbvFragInvocationCountEXT, symbolTable);
}
symbolTable.setVariableExtensions("gl_FragDepthEXT", 1, &E_GL_EXT_frag_depth);
symbolTable.setFunctionExtensions("clockARB", 1, &E_GL_ARB_shader_clock);
symbolTable.setFunctionExtensions("clock2x32ARB", 1, &E_GL_ARB_shader_clock);
symbolTable.setFunctionExtensions("clockRealtimeEXT", 1, &E_GL_EXT_shader_realtime_clock);
symbolTable.setFunctionExtensions("clockRealtime2x32EXT", 1, &E_GL_EXT_shader_realtime_clock);
if (profile == EEsProfile && version < 320) {
symbolTable.setVariableExtensions("gl_PrimitiveID", Num_AEP_geometry_shader, AEP_geometry_shader);
symbolTable.setVariableExtensions("gl_Layer", Num_AEP_geometry_shader, AEP_geometry_shader);
}
if (profile == EEsProfile && version < 320) {
symbolTable.setFunctionExtensions("imageAtomicAdd", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicMin", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicMax", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicAnd", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicOr", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicXor", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
}
if (profile != EEsProfile && version < 330 ) {
const char* bitsConvertExt[2] = {E_GL_ARB_shader_bit_encoding, E_GL_ARB_gpu_shader5};
symbolTable.setFunctionExtensions("floatBitsToInt", 2, bitsConvertExt);
symbolTable.setFunctionExtensions("floatBitsToUint", 2, bitsConvertExt);
symbolTable.setFunctionExtensions("intBitsToFloat", 2, bitsConvertExt);
symbolTable.setFunctionExtensions("uintBitsToFloat", 2, bitsConvertExt);
}
if (profile != EEsProfile && version < 430 ) {
symbolTable.setFunctionExtensions("imageSize", 1, &E_GL_ARB_shader_image_size);
}
// GL_ARB_shader_storage_buffer_object
if (profile != EEsProfile && version < 430 ) {
symbolTable.setFunctionExtensions("atomicAdd", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicMin", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicMax", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicAnd", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicOr", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicXor", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicExchange", 1, &E_GL_ARB_shader_storage_buffer_object);
symbolTable.setFunctionExtensions("atomicCompSwap", 1, &E_GL_ARB_shader_storage_buffer_object);
}
// GL_ARB_shading_language_packing
if (profile != EEsProfile && version < 400 ) {
symbolTable.setFunctionExtensions("packUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
symbolTable.setFunctionExtensions("unpackUnorm2x16", 1, &E_GL_ARB_shading_language_packing);
symbolTable.setFunctionExtensions("packSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
symbolTable.setFunctionExtensions("packUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
symbolTable.setFunctionExtensions("unpackSnorm4x8", 1, &E_GL_ARB_shading_language_packing);
symbolTable.setFunctionExtensions("unpackUnorm4x8", 1, &E_GL_ARB_shading_language_packing);
}
if (profile != EEsProfile && version < 420 ) {
symbolTable.setFunctionExtensions("packSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
symbolTable.setFunctionExtensions("unpackSnorm2x16", 1, &E_GL_ARB_shading_language_packing);
symbolTable.setFunctionExtensions("unpackHalf2x16", 1, &E_GL_ARB_shading_language_packing);
symbolTable.setFunctionExtensions("packHalf2x16", 1, &E_GL_ARB_shading_language_packing);
}
symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
if (version >= 300 /* both ES and non-ES */) {
symbolTable.setVariableExtensions("gl_ViewID_OVR", Num_OVR_multiview_EXTs, OVR_multiview_EXTs);
BuiltInVariable("gl_ViewID_OVR", EbvViewIndex, symbolTable);
}
// GL_ARB_shader_ballot
if (profile != EEsProfile) {
symbolTable.setVariableExtensions("gl_SubGroupSizeARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB", 1, &E_GL_ARB_shader_ballot);
BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
BuiltInVariable("gl_SubGroupEqMaskARB", EbvSubGroupEqMask, symbolTable);
BuiltInVariable("gl_SubGroupGeMaskARB", EbvSubGroupGeMask, symbolTable);
BuiltInVariable("gl_SubGroupGtMaskARB", EbvSubGroupGtMask, symbolTable);
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}
// GL_EXT_expect_assume
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.setFunctionExtensions("assumeEXT", 1, &E_GL_EXT_expect_assume);
symbolTable.setFunctionExtensions("expectEXT", 1, &E_GL_EXT_expect_assume);
}
// GL_KHR_shader_subgroup
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.setVariableExtensions("gl_SubgroupSize", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupEqMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
BuiltInVariable("gl_SubgroupSize", EbvSubgroupSize2, symbolTable);
BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
BuiltInVariable("gl_SubgroupEqMask", EbvSubgroupEqMask2, symbolTable);
BuiltInVariable("gl_SubgroupGeMask", EbvSubgroupGeMask2, symbolTable);
BuiltInVariable("gl_SubgroupGtMask", EbvSubgroupGtMask2, symbolTable);
BuiltInVariable("gl_SubgroupLeMask", EbvSubgroupLeMask2, symbolTable);
BuiltInVariable("gl_SubgroupLtMask", EbvSubgroupLtMask2, symbolTable);
symbolTable.setFunctionExtensions("subgroupBarrier", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setFunctionExtensions("subgroupMemoryBarrier", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setFunctionExtensions("subgroupMemoryBarrierBuffer", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setFunctionExtensions("subgroupMemoryBarrierImage", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setFunctionExtensions("subgroupElect", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setFunctionExtensions("subgroupAll", 1, &E_GL_KHR_shader_subgroup_vote);
symbolTable.setFunctionExtensions("subgroupAny", 1, &E_GL_KHR_shader_subgroup_vote);
symbolTable.setFunctionExtensions("subgroupAllEqual", 1, &E_GL_KHR_shader_subgroup_vote);
symbolTable.setFunctionExtensions("subgroupBroadcast", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupBroadcastFirst", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupBallot", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupInverseBallot", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupBallotBitExtract", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupBallotBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupBallotInclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupBallotExclusiveBitCount", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupBallotFindLSB", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupBallotFindMSB", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setFunctionExtensions("subgroupShuffle", 1, &E_GL_KHR_shader_subgroup_shuffle);
symbolTable.setFunctionExtensions("subgroupShuffleXor", 1, &E_GL_KHR_shader_subgroup_shuffle);
symbolTable.setFunctionExtensions("subgroupShuffleUp", 1, &E_GL_KHR_shader_subgroup_shuffle_relative);
symbolTable.setFunctionExtensions("subgroupShuffleDown", 1, &E_GL_KHR_shader_subgroup_shuffle_relative);
symbolTable.setFunctionExtensions("subgroupRotate", 1, &E_GL_KHR_shader_subgroup_rotate);
symbolTable.setFunctionExtensions("subgroupClusteredRotate", 1, &E_GL_KHR_shader_subgroup_rotate);
symbolTable.setFunctionExtensions("subgroupAdd", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupMul", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupMin", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupMax", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupAnd", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupOr", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupXor", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupInclusiveAdd", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupInclusiveMul", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupInclusiveMin", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupInclusiveMax", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupInclusiveAnd", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupInclusiveOr", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupInclusiveXor", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupExclusiveAdd", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupExclusiveMul", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupExclusiveMin", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupExclusiveMax", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupExclusiveAnd", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupExclusiveOr", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupExclusiveXor", 1, &E_GL_KHR_shader_subgroup_arithmetic);
symbolTable.setFunctionExtensions("subgroupClusteredAdd", 1, &E_GL_KHR_shader_subgroup_clustered);
symbolTable.setFunctionExtensions("subgroupClusteredMul", 1, &E_GL_KHR_shader_subgroup_clustered);
symbolTable.setFunctionExtensions("subgroupClusteredMin", 1, &E_GL_KHR_shader_subgroup_clustered);
symbolTable.setFunctionExtensions("subgroupClusteredMax", 1, &E_GL_KHR_shader_subgroup_clustered);
symbolTable.setFunctionExtensions("subgroupClusteredAnd", 1, &E_GL_KHR_shader_subgroup_clustered);
symbolTable.setFunctionExtensions("subgroupClusteredOr", 1, &E_GL_KHR_shader_subgroup_clustered);
symbolTable.setFunctionExtensions("subgroupClusteredXor", 1, &E_GL_KHR_shader_subgroup_clustered);
symbolTable.setFunctionExtensions("subgroupQuadBroadcast", 1, &E_GL_KHR_shader_subgroup_quad);
symbolTable.setFunctionExtensions("subgroupQuadSwapHorizontal", 1, &E_GL_KHR_shader_subgroup_quad);
symbolTable.setFunctionExtensions("subgroupQuadSwapVertical", 1, &E_GL_KHR_shader_subgroup_quad);
symbolTable.setFunctionExtensions("subgroupQuadSwapDiagonal", 1, &E_GL_KHR_shader_subgroup_quad);
symbolTable.setFunctionExtensions("subgroupPartitionNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedAddNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedMulNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedMinNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedMaxNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedAndNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedOrNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedXorNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAddNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMulNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMinNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveMaxNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveAndNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveOrNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedInclusiveXorNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAddNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMulNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMinNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveMaxNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveAndNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveOrNV", 1, &E_GL_NV_shader_subgroup_partitioned);
symbolTable.setFunctionExtensions("subgroupPartitionedExclusiveXorNV", 1, &E_GL_NV_shader_subgroup_partitioned);
// GL_NV_shader_sm_builtins
symbolTable.setVariableExtensions("gl_WarpsPerSMNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMCountNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_WarpIDNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMIDNV", 1, &E_GL_NV_shader_sm_builtins);
BuiltInVariable("gl_WarpsPerSMNV", EbvWarpsPerSM, symbolTable);
BuiltInVariable("gl_SMCountNV", EbvSMCount, symbolTable);
BuiltInVariable("gl_WarpIDNV", EbvWarpID, symbolTable);
BuiltInVariable("gl_SMIDNV", EbvSMID, symbolTable);
// GL_ARM_shader_core_builtins
symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
BuiltInVariable("gl_CoreIDARM", EbvCoreIDARM, symbolTable);
BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
BuiltInVariable("gl_WarpIDARM", EbvWarpIDARM, symbolTable);
BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
}
if (profile == EEsProfile) {
symbolTable.setFunctionExtensions("shadow2DEXT", 1, &E_GL_EXT_shadow_samplers);
symbolTable.setFunctionExtensions("shadow2DProjEXT", 1, &E_GL_EXT_shadow_samplers);
}
if (spvVersion.vulkan > 0) {
symbolTable.setVariableExtensions("gl_ScopeDevice", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_ScopeWorkgroup", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_ScopeSubgroup", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_ScopeInvocation", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_SemanticsRelaxed", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_SemanticsAcquire", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_SemanticsRelease", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_SemanticsAcquireRelease", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_SemanticsMakeAvailable", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_SemanticsMakeVisible", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_SemanticsVolatile", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_StorageSemanticsNone", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_StorageSemanticsBuffer", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_StorageSemanticsShared", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_StorageSemanticsImage", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setVariableExtensions("gl_StorageSemanticsOutput", 1, &E_GL_KHR_memory_scope_semantics);
}
symbolTable.setFunctionExtensions("helperInvocationEXT", 1, &E_GL_EXT_demote_to_helper_invocation);
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 450)) {
symbolTable.setVariableExtensions("gl_ShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
BuiltInVariable("gl_ShadingRateEXT", EbvShadingRateKHR, symbolTable);
symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
}
// GL_EXT_shader_quad_control
if ((profile != EEsProfile && version >= 140) ||
(profile == EEsProfile && version >= 310)) {
symbolTable.setFunctionExtensions("subgroupQuadAll", 1, &E_GL_KHR_shader_subgroup_vote);
symbolTable.setFunctionExtensions("subgroupQuadAny", 1, &E_GL_KHR_shader_subgroup_vote);
}
// GL_EXT_shader_tile_image
symbolTable.setFunctionExtensions("stencilAttachmentReadEXT", 1, &E_GL_EXT_shader_tile_image);
symbolTable.setFunctionExtensions("depthAttachmentReadEXT", 1, &E_GL_EXT_shader_tile_image);
symbolTable.setFunctionExtensions("colorAttachmentReadEXT", 1, &E_GL_EXT_shader_tile_image);
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.setFunctionExtensions("textureWeightedQCOM", 1, &E_GL_QCOM_image_processing);
symbolTable.setFunctionExtensions("textureBoxFilterQCOM", 1, &E_GL_QCOM_image_processing);
symbolTable.setFunctionExtensions("textureBlockMatchSADQCOM", 1, &E_GL_QCOM_image_processing);
symbolTable.setFunctionExtensions("textureBlockMatchSSDQCOM", 1, &E_GL_QCOM_image_processing);
symbolTable.setFunctionExtensions("textureBlockMatchWindowSSDQCOM", 1, &E_GL_QCOM_image_processing2);
symbolTable.setFunctionExtensions("textureBlockMatchWindowSADQCOM", 1, &E_GL_QCOM_image_processing2);
symbolTable.setFunctionExtensions("textureBlockMatchGatherSSDQCOM", 1, &E_GL_QCOM_image_processing2);
symbolTable.setFunctionExtensions("textureBlockMatchGatherSADQCOM", 1, &E_GL_QCOM_image_processing2);
}
break;
case EShLangCompute:
BuiltInVariable("gl_NumWorkGroups", EbvNumWorkGroups, symbolTable);
BuiltInVariable("gl_WorkGroupSize", EbvWorkGroupSize, symbolTable);
BuiltInVariable("gl_WorkGroupID", EbvWorkGroupId, symbolTable);
BuiltInVariable("gl_LocalInvocationID", EbvLocalInvocationId, symbolTable);
BuiltInVariable("gl_GlobalInvocationID", EbvGlobalInvocationId, symbolTable);
BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
if ((profile != EEsProfile && version >= 140) ||
(profile == EEsProfile && version >= 310)) {
symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
}
if (profile != EEsProfile && version < 430) {
symbolTable.setVariableExtensions("gl_NumWorkGroups", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_WorkGroupSize", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_WorkGroupID", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationID", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_GlobalInvocationID", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupCount", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupSize", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_MaxComputeUniformComponents", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_MaxComputeTextureImageUnits", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_MaxComputeImageUniforms", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounters", 1, &E_GL_ARB_compute_shader);
symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounterBuffers", 1, &E_GL_ARB_compute_shader);
symbolTable.setFunctionExtensions("barrier", 1, &E_GL_ARB_compute_shader);
symbolTable.setFunctionExtensions("memoryBarrierAtomicCounter", 1, &E_GL_ARB_compute_shader);
symbolTable.setFunctionExtensions("memoryBarrierBuffer", 1, &E_GL_ARB_compute_shader);
symbolTable.setFunctionExtensions("memoryBarrierImage", 1, &E_GL_ARB_compute_shader);
symbolTable.setFunctionExtensions("memoryBarrierShared", 1, &E_GL_ARB_compute_shader);
symbolTable.setFunctionExtensions("groupMemoryBarrier", 1, &E_GL_ARB_compute_shader);
}
symbolTable.setFunctionExtensions("controlBarrier", 1, &E_GL_KHR_memory_scope_semantics);
symbolTable.setFunctionExtensions("debugPrintfEXT", 1, &E_GL_EXT_debug_printf);
// GL_ARB_shader_ballot
if (profile != EEsProfile) {
symbolTable.setVariableExtensions("gl_SubGroupSizeARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB", 1, &E_GL_ARB_shader_ballot);
BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
BuiltInVariable("gl_SubGroupEqMaskARB", EbvSubGroupEqMask, symbolTable);
BuiltInVariable("gl_SubGroupGeMaskARB", EbvSubGroupGeMask, symbolTable);
BuiltInVariable("gl_SubGroupGtMaskARB", EbvSubGroupGtMask, symbolTable);
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}
// GL_KHR_shader_subgroup
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.setVariableExtensions("gl_SubgroupSize", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupEqMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
BuiltInVariable("gl_SubgroupSize", EbvSubgroupSize2, symbolTable);
BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
BuiltInVariable("gl_SubgroupEqMask", EbvSubgroupEqMask2, symbolTable);
BuiltInVariable("gl_SubgroupGeMask", EbvSubgroupGeMask2, symbolTable);
BuiltInVariable("gl_SubgroupGtMask", EbvSubgroupGtMask2, symbolTable);
BuiltInVariable("gl_SubgroupLeMask", EbvSubgroupLeMask2, symbolTable);
BuiltInVariable("gl_SubgroupLtMask", EbvSubgroupLtMask2, symbolTable);
// GL_NV_shader_sm_builtins
symbolTable.setVariableExtensions("gl_WarpsPerSMNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMCountNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_WarpIDNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMIDNV", 1, &E_GL_NV_shader_sm_builtins);
BuiltInVariable("gl_WarpsPerSMNV", EbvWarpsPerSM, symbolTable);
BuiltInVariable("gl_SMCountNV", EbvSMCount, symbolTable);
BuiltInVariable("gl_WarpIDNV", EbvWarpID, symbolTable);
BuiltInVariable("gl_SMIDNV", EbvSMID, symbolTable);
// GL_ARM_shader_core_builtins
symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
BuiltInVariable("gl_CoreIDARM", EbvCoreIDARM, symbolTable);
BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
BuiltInVariable("gl_WarpIDARM", EbvWarpIDARM, symbolTable);
BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
}
// GL_KHR_shader_subgroup
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.setVariableExtensions("gl_NumSubgroups", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupID", 1, &E_GL_KHR_shader_subgroup_basic);
BuiltInVariable("gl_NumSubgroups", EbvNumSubgroups, symbolTable);
BuiltInVariable("gl_SubgroupID", EbvSubgroupID, symbolTable);
symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
}
{
const char *coopExt[2] = { E_GL_NV_cooperative_matrix, E_GL_NV_integer_cooperative_matrix };
symbolTable.setFunctionExtensions("coopMatLoadNV", 2, coopExt);
symbolTable.setFunctionExtensions("coopMatStoreNV", 2, coopExt);
symbolTable.setFunctionExtensions("coopMatMulAddNV", 2, coopExt);
}
{
symbolTable.setFunctionExtensions("coopMatLoad", 1, &E_GL_KHR_cooperative_matrix);
symbolTable.setFunctionExtensions("coopMatStore", 1, &E_GL_KHR_cooperative_matrix);
symbolTable.setFunctionExtensions("coopMatMulAdd", 1, &E_GL_KHR_cooperative_matrix);
}
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
symbolTable.setFunctionExtensions("dFdx", 1, &E_GL_NV_compute_shader_derivatives);
symbolTable.setFunctionExtensions("dFdy", 1, &E_GL_NV_compute_shader_derivatives);
symbolTable.setFunctionExtensions("fwidth", 1, &E_GL_NV_compute_shader_derivatives);
symbolTable.setFunctionExtensions("dFdxFine", 1, &E_GL_NV_compute_shader_derivatives);
symbolTable.setFunctionExtensions("dFdyFine", 1, &E_GL_NV_compute_shader_derivatives);
symbolTable.setFunctionExtensions("fwidthFine", 1, &E_GL_NV_compute_shader_derivatives);
symbolTable.setFunctionExtensions("dFdxCoarse", 1, &E_GL_NV_compute_shader_derivatives);
symbolTable.setFunctionExtensions("dFdyCoarse", 1, &E_GL_NV_compute_shader_derivatives);
symbolTable.setFunctionExtensions("fwidthCoarse", 1, &E_GL_NV_compute_shader_derivatives);
}
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 450)) {
symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
}
if ((profile != EEsProfile && version >= 460)) {
symbolTable.setFunctionExtensions("fetchMicroTriangleVertexPositionNV", 1, &E_GL_NV_displacement_micromap);
symbolTable.setFunctionExtensions("fetchMicroTriangleVertexBarycentricNV", 1, &E_GL_NV_displacement_micromap);
}
break;
case EShLangRayGen:
case EShLangIntersect:
case EShLangAnyHit:
case EShLangClosestHit:
case EShLangMiss:
case EShLangCallable:
if (profile != EEsProfile && version >= 460) {
const char *rtexts[] = { E_GL_NV_ray_tracing, E_GL_EXT_ray_tracing };
symbolTable.setVariableExtensions("gl_LaunchIDNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_LaunchIDEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_LaunchSizeNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_LaunchSizeEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_PrimitiveID", 2, rtexts);
symbolTable.setVariableExtensions("gl_InstanceID", 2, rtexts);
symbolTable.setVariableExtensions("gl_InstanceCustomIndexNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_InstanceCustomIndexEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_GeometryIndexEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_WorldRayOriginNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_WorldRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_WorldRayDirectionNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_WorldRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_ObjectRayOriginNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_ObjectRayOriginEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_ObjectRayDirectionNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_ObjectRayDirectionEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_RayTminNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_RayTminEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_RayTmaxNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_RayTmaxEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_CullMaskEXT", 1, &E_GL_EXT_ray_cull_mask);
symbolTable.setVariableExtensions("gl_HitTNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_HitTEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_HitKindNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_HitKindEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_ObjectToWorldNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_ObjectToWorldEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_ObjectToWorld3x4EXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_WorldToObjectNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_WorldToObjectEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_WorldToObject3x4EXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_IncomingRayFlagsNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setVariableExtensions("gl_IncomingRayFlagsEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setVariableExtensions("gl_CurrentRayTimeNV", 1, &E_GL_NV_ray_tracing_motion_blur);
symbolTable.setVariableExtensions("gl_HitTriangleVertexPositionsEXT", 1, &E_GL_EXT_ray_tracing_position_fetch);
symbolTable.setVariableExtensions("gl_HitMicroTriangleVertexPositionsNV", 1, &E_GL_NV_displacement_micromap);
symbolTable.setVariableExtensions("gl_HitMicroTriangleVertexBarycentricsNV", 1, &E_GL_NV_displacement_micromap);
symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
symbolTable.setFunctionExtensions("traceNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setFunctionExtensions("traceRayMotionNV", 1, &E_GL_NV_ray_tracing_motion_blur);
symbolTable.setFunctionExtensions("traceRayEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setFunctionExtensions("reportIntersectionNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setFunctionExtensions("reportIntersectionEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setFunctionExtensions("ignoreIntersectionNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setFunctionExtensions("terminateRayNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setFunctionExtensions("executeCallableNV", 1, &E_GL_NV_ray_tracing);
symbolTable.setFunctionExtensions("executeCallableEXT", 1, &E_GL_EXT_ray_tracing);
symbolTable.setFunctionExtensions("hitObjectTraceRayNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectTraceRayMotionNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectRecordHitNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectRecordHitMotionNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectRecordHitWithIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectRecordHitWithIndexMotionNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectRecordMissNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectRecordMissMotionNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectRecordEmptyNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectExecuteShaderNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectIsEmptyNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectIsMissNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectIsHitNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetRayTMinNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetRayTMaxNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetObjectRayOriginNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetObjectRayDirectionNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetWorldRayOriginNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetWorldRayDirectionNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetWorldToObjectNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetbjectToWorldNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetInstanceCustomIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetInstanceIdNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetGeometryIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetPrimitiveIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetHitKindNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetAttributesNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetCurrentTimeNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetShaderBindingTableRecordIndexNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("hitObjectGetShaderRecordBufferHandleNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("reorderThreadNV", 1, &E_GL_NV_shader_invocation_reorder);
symbolTable.setFunctionExtensions("fetchMicroTriangleVertexPositionNV", 1, &E_GL_NV_displacement_micromap);
symbolTable.setFunctionExtensions("fetchMicroTriangleVertexBarycentricNV", 1, &E_GL_NV_displacement_micromap);
BuiltInVariable("gl_LaunchIDNV", EbvLaunchId, symbolTable);
BuiltInVariable("gl_LaunchIDEXT", EbvLaunchId, symbolTable);
BuiltInVariable("gl_LaunchSizeNV", EbvLaunchSize, symbolTable);
BuiltInVariable("gl_LaunchSizeEXT", EbvLaunchSize, symbolTable);
BuiltInVariable("gl_PrimitiveID", EbvPrimitiveId, symbolTable);
BuiltInVariable("gl_InstanceID", EbvInstanceId, symbolTable);
BuiltInVariable("gl_InstanceCustomIndexNV", EbvInstanceCustomIndex,symbolTable);
BuiltInVariable("gl_InstanceCustomIndexEXT", EbvInstanceCustomIndex,symbolTable);
BuiltInVariable("gl_GeometryIndexEXT", EbvGeometryIndex, symbolTable);
BuiltInVariable("gl_WorldRayOriginNV", EbvWorldRayOrigin, symbolTable);
BuiltInVariable("gl_WorldRayOriginEXT", EbvWorldRayOrigin, symbolTable);
BuiltInVariable("gl_WorldRayDirectionNV", EbvWorldRayDirection, symbolTable);
BuiltInVariable("gl_WorldRayDirectionEXT", EbvWorldRayDirection, symbolTable);
BuiltInVariable("gl_ObjectRayOriginNV", EbvObjectRayOrigin, symbolTable);
BuiltInVariable("gl_ObjectRayOriginEXT", EbvObjectRayOrigin, symbolTable);
BuiltInVariable("gl_ObjectRayDirectionNV", EbvObjectRayDirection, symbolTable);
BuiltInVariable("gl_ObjectRayDirectionEXT", EbvObjectRayDirection, symbolTable);
BuiltInVariable("gl_RayTminNV", EbvRayTmin, symbolTable);
BuiltInVariable("gl_RayTminEXT", EbvRayTmin, symbolTable);
BuiltInVariable("gl_RayTmaxNV", EbvRayTmax, symbolTable);
BuiltInVariable("gl_RayTmaxEXT", EbvRayTmax, symbolTable);
BuiltInVariable("gl_CullMaskEXT", EbvCullMask, symbolTable);
BuiltInVariable("gl_HitKindNV", EbvHitKind, symbolTable);
BuiltInVariable("gl_HitKindEXT", EbvHitKind, symbolTable);
BuiltInVariable("gl_ObjectToWorldNV", EbvObjectToWorld, symbolTable);
BuiltInVariable("gl_ObjectToWorldEXT", EbvObjectToWorld, symbolTable);
BuiltInVariable("gl_ObjectToWorld3x4EXT", EbvObjectToWorld3x4, symbolTable);
BuiltInVariable("gl_WorldToObjectNV", EbvWorldToObject, symbolTable);
BuiltInVariable("gl_WorldToObjectEXT", EbvWorldToObject, symbolTable);
BuiltInVariable("gl_WorldToObject3x4EXT", EbvWorldToObject3x4, symbolTable);
BuiltInVariable("gl_IncomingRayFlagsNV", EbvIncomingRayFlags, symbolTable);
BuiltInVariable("gl_IncomingRayFlagsEXT", EbvIncomingRayFlags, symbolTable);
BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
BuiltInVariable("gl_CurrentRayTimeNV", EbvCurrentRayTimeNV, symbolTable);
BuiltInVariable("gl_HitTriangleVertexPositionsEXT", EbvPositionFetch, symbolTable);
BuiltInVariable("gl_HitMicroTriangleVertexPositionsNV", EbvMicroTrianglePositionNV, symbolTable);
BuiltInVariable("gl_HitMicroTriangleVertexBarycentricsNV", EbvMicroTriangleBaryNV, symbolTable);
BuiltInVariable("gl_HitKindFrontFacingMicroTriangleNV", EbvHitKindFrontFacingMicroTriangleNV, symbolTable);
BuiltInVariable("gl_HitKindBackFacingMicroTriangleNV", EbvHitKindBackFacingMicroTriangleNV, symbolTable);
// gl_HitT variables are aliases of their gl_RayTmax counterparts.
RetargetVariable("gl_HitTNV", "gl_RayTmaxNV", symbolTable);
RetargetVariable("gl_HitTEXT", "gl_RayTmaxEXT", symbolTable);
// GL_ARB_shader_ballot
symbolTable.setVariableExtensions("gl_SubGroupSizeARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB", 1, &E_GL_ARB_shader_ballot);
BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
BuiltInVariable("gl_SubGroupEqMaskARB", EbvSubGroupEqMask, symbolTable);
BuiltInVariable("gl_SubGroupGeMaskARB", EbvSubGroupGeMask, symbolTable);
BuiltInVariable("gl_SubGroupGtMaskARB", EbvSubGroupGtMask, symbolTable);
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
// GL_KHR_shader_subgroup
symbolTable.setVariableExtensions("gl_NumSubgroups", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupID", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupSize", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupEqMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
BuiltInVariable("gl_NumSubgroups", EbvNumSubgroups, symbolTable);
BuiltInVariable("gl_SubgroupID", EbvSubgroupID, symbolTable);
BuiltInVariable("gl_SubgroupSize", EbvSubgroupSize2, symbolTable);
BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
BuiltInVariable("gl_SubgroupEqMask", EbvSubgroupEqMask2, symbolTable);
BuiltInVariable("gl_SubgroupGeMask", EbvSubgroupGeMask2, symbolTable);
BuiltInVariable("gl_SubgroupGtMask", EbvSubgroupGtMask2, symbolTable);
BuiltInVariable("gl_SubgroupLeMask", EbvSubgroupLeMask2, symbolTable);
BuiltInVariable("gl_SubgroupLtMask", EbvSubgroupLtMask2, symbolTable);
// GL_NV_shader_sm_builtins
symbolTable.setVariableExtensions("gl_WarpsPerSMNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMCountNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_WarpIDNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMIDNV", 1, &E_GL_NV_shader_sm_builtins);
BuiltInVariable("gl_WarpsPerSMNV", EbvWarpsPerSM, symbolTable);
BuiltInVariable("gl_SMCountNV", EbvSMCount, symbolTable);
BuiltInVariable("gl_WarpIDNV", EbvWarpID, symbolTable);
BuiltInVariable("gl_SMIDNV", EbvSMID, symbolTable);
// GL_ARM_shader_core_builtins
symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
BuiltInVariable("gl_CoreIDARM", EbvCoreIDARM, symbolTable);
BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
BuiltInVariable("gl_WarpIDARM", EbvWarpIDARM, symbolTable);
BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
}
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 450)) {
symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
}
break;
case EShLangMesh:
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
// per-vertex builtins
symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_Position", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PointSize", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistance", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistance", 1, &E_GL_NV_mesh_shader);
BuiltInVariable("gl_MeshVerticesNV", "gl_Position", EbvPosition, symbolTable);
BuiltInVariable("gl_MeshVerticesNV", "gl_PointSize", EbvPointSize, symbolTable);
BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistance", EbvClipDistance, symbolTable);
BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistance", EbvCullDistance, symbolTable);
symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_PositionPerViewNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", 1, &E_GL_NV_mesh_shader);
BuiltInVariable("gl_MeshVerticesNV", "gl_PositionPerViewNV", EbvPositionPerViewNV, symbolTable);
BuiltInVariable("gl_MeshVerticesNV", "gl_ClipDistancePerViewNV", EbvClipDistancePerViewNV, symbolTable);
BuiltInVariable("gl_MeshVerticesNV", "gl_CullDistancePerViewNV", EbvCullDistancePerViewNV, symbolTable);
// per-primitive builtins
symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_PrimitiveID", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_Layer", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportIndex", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMask", 1, &E_GL_NV_mesh_shader);
BuiltInVariable("gl_MeshPrimitivesNV", "gl_PrimitiveID", EbvPrimitiveId, symbolTable);
BuiltInVariable("gl_MeshPrimitivesNV", "gl_Layer", EbvLayer, symbolTable);
BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportIndex", EbvViewportIndex, symbolTable);
BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMask", EbvViewportMaskNV, symbolTable);
// per-view per-primitive builtins
symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_LayerPerViewNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", 1, &E_GL_NV_mesh_shader);
BuiltInVariable("gl_MeshPrimitivesNV", "gl_LayerPerViewNV", EbvLayerPerViewNV, symbolTable);
BuiltInVariable("gl_MeshPrimitivesNV", "gl_ViewportMaskPerViewNV", EbvViewportMaskPerViewNV, symbolTable);
// other builtins
symbolTable.setVariableExtensions("gl_PrimitiveCountNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_PrimitiveIndicesNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshViewCountNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshViewIndicesNV", 1, &E_GL_NV_mesh_shader);
if (profile != EEsProfile) {
symbolTable.setVariableExtensions("gl_WorkGroupSize", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setVariableExtensions("gl_WorkGroupID", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationID", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setVariableExtensions("gl_GlobalInvocationID", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationIndex", Num_AEP_mesh_shader, AEP_mesh_shader);
} else {
symbolTable.setVariableExtensions("gl_WorkGroupSize", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_WorkGroupID", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationID", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_GlobalInvocationID", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
}
BuiltInVariable("gl_PrimitiveCountNV", EbvPrimitiveCountNV, symbolTable);
BuiltInVariable("gl_PrimitiveIndicesNV", EbvPrimitiveIndicesNV, symbolTable);
BuiltInVariable("gl_MeshViewCountNV", EbvMeshViewCountNV, symbolTable);
BuiltInVariable("gl_MeshViewIndicesNV", EbvMeshViewIndicesNV, symbolTable);
BuiltInVariable("gl_WorkGroupSize", EbvWorkGroupSize, symbolTable);
BuiltInVariable("gl_WorkGroupID", EbvWorkGroupId, symbolTable);
BuiltInVariable("gl_LocalInvocationID", EbvLocalInvocationId, symbolTable);
BuiltInVariable("gl_GlobalInvocationID", EbvGlobalInvocationId, symbolTable);
BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
// builtin constants
symbolTable.setVariableExtensions("gl_MaxMeshOutputVerticesNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MaxMeshOutputPrimitivesNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MaxMeshWorkGroupSizeNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV", 1, &E_GL_NV_mesh_shader);
// builtin functions
if (profile != EEsProfile) {
symbolTable.setFunctionExtensions("barrier", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setFunctionExtensions("memoryBarrierShared", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setFunctionExtensions("groupMemoryBarrier", Num_AEP_mesh_shader, AEP_mesh_shader);
} else {
symbolTable.setFunctionExtensions("barrier", 1, &E_GL_NV_mesh_shader);
symbolTable.setFunctionExtensions("memoryBarrierShared", 1, &E_GL_NV_mesh_shader);
symbolTable.setFunctionExtensions("groupMemoryBarrier", 1, &E_GL_NV_mesh_shader);
}
symbolTable.setFunctionExtensions("writePackedPrimitiveIndices4x8NV", 1, &E_GL_NV_mesh_shader);
}
if (profile != EEsProfile && version >= 450) {
// GL_EXT_Mesh_shader
symbolTable.setVariableExtensions("gl_PrimitivePointIndicesEXT", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_PrimitiveLineIndicesEXT", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_PrimitiveTriangleIndicesEXT", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_NumWorkGroups", 1, &E_GL_EXT_mesh_shader);
BuiltInVariable("gl_PrimitivePointIndicesEXT", EbvPrimitivePointIndicesEXT, symbolTable);
BuiltInVariable("gl_PrimitiveLineIndicesEXT", EbvPrimitiveLineIndicesEXT, symbolTable);
BuiltInVariable("gl_PrimitiveTriangleIndicesEXT", EbvPrimitiveTriangleIndicesEXT, symbolTable);
BuiltInVariable("gl_NumWorkGroups", EbvNumWorkGroups, symbolTable);
symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_Position", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_PointSize", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_ClipDistance", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshVerticesEXT", "gl_CullDistance", 1, &E_GL_EXT_mesh_shader);
BuiltInVariable("gl_MeshVerticesEXT", "gl_Position", EbvPosition, symbolTable);
BuiltInVariable("gl_MeshVerticesEXT", "gl_PointSize", EbvPointSize, symbolTable);
BuiltInVariable("gl_MeshVerticesEXT", "gl_ClipDistance", EbvClipDistance, symbolTable);
BuiltInVariable("gl_MeshVerticesEXT", "gl_CullDistance", EbvCullDistance, symbolTable);
symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_PrimitiveID", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_Layer", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_ViewportIndex", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_CullPrimitiveEXT", 1, &E_GL_EXT_mesh_shader);
// note: technically this member requires both GL_EXT_mesh_shader and GL_EXT_fragment_shading_rate
// since setVariableExtensions only needs *one of* the extensions to validate, it's more useful to specify EXT_fragment_shading_rate
// GL_EXT_mesh_shader will be required in practice by use of other fields of gl_MeshPrimitivesEXT
symbolTable.setVariableExtensions("gl_MeshPrimitivesEXT", "gl_PrimitiveShadingRateEXT", 1, &E_GL_EXT_fragment_shading_rate);
BuiltInVariable("gl_MeshPrimitivesEXT", "gl_PrimitiveID", EbvPrimitiveId, symbolTable);
BuiltInVariable("gl_MeshPrimitivesEXT", "gl_Layer", EbvLayer, symbolTable);
BuiltInVariable("gl_MeshPrimitivesEXT", "gl_ViewportIndex", EbvViewportIndex, symbolTable);
BuiltInVariable("gl_MeshPrimitivesEXT", "gl_CullPrimitiveEXT", EbvCullPrimitiveEXT, symbolTable);
BuiltInVariable("gl_MeshPrimitivesEXT", "gl_PrimitiveShadingRateEXT", EbvPrimitiveShadingRateKHR, symbolTable);
symbolTable.setFunctionExtensions("SetMeshOutputsEXT", 1, &E_GL_EXT_mesh_shader);
// GL_EXT_device_group
symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
// GL_ARB_shader_draw_parameters
symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
if (version >= 460) {
BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
}
// GL_EXT_multiview
BuiltInVariable("gl_ViewIndex", EbvViewIndex, symbolTable);
symbolTable.setVariableExtensions("gl_ViewIndex", 1, &E_GL_EXT_multiview);
// GL_ARB_shader_ballot
symbolTable.setVariableExtensions("gl_SubGroupSizeARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB", 1, &E_GL_ARB_shader_ballot);
BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
BuiltInVariable("gl_SubGroupEqMaskARB", EbvSubGroupEqMask, symbolTable);
BuiltInVariable("gl_SubGroupGeMaskARB", EbvSubGroupGeMask, symbolTable);
BuiltInVariable("gl_SubGroupGtMaskARB", EbvSubGroupGtMask, symbolTable);
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}
// GL_KHR_shader_subgroup
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.setVariableExtensions("gl_NumSubgroups", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupID", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupSize", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupEqMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
BuiltInVariable("gl_NumSubgroups", EbvNumSubgroups, symbolTable);
BuiltInVariable("gl_SubgroupID", EbvSubgroupID, symbolTable);
BuiltInVariable("gl_SubgroupSize", EbvSubgroupSize2, symbolTable);
BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
BuiltInVariable("gl_SubgroupEqMask", EbvSubgroupEqMask2, symbolTable);
BuiltInVariable("gl_SubgroupGeMask", EbvSubgroupGeMask2, symbolTable);
BuiltInVariable("gl_SubgroupGtMask", EbvSubgroupGtMask2, symbolTable);
BuiltInVariable("gl_SubgroupLeMask", EbvSubgroupLeMask2, symbolTable);
BuiltInVariable("gl_SubgroupLtMask", EbvSubgroupLtMask2, symbolTable);
symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
// GL_NV_shader_sm_builtins
symbolTable.setVariableExtensions("gl_WarpsPerSMNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMCountNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_WarpIDNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMIDNV", 1, &E_GL_NV_shader_sm_builtins);
BuiltInVariable("gl_WarpsPerSMNV", EbvWarpsPerSM, symbolTable);
BuiltInVariable("gl_SMCountNV", EbvSMCount, symbolTable);
BuiltInVariable("gl_WarpIDNV", EbvWarpID, symbolTable);
BuiltInVariable("gl_SMIDNV", EbvSMID, symbolTable);
// GL_ARM_shader_core_builtins
symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
BuiltInVariable("gl_CoreIDARM", EbvCoreIDARM, symbolTable);
BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
BuiltInVariable("gl_WarpIDARM", EbvWarpIDARM, symbolTable);
BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
}
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 450)) {
symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
}
// Builtins for GL_NV_displacment_micromap
if ((profile != EEsProfile && version >= 460)) {
symbolTable.setFunctionExtensions("fetchMicroTriangleVertexPositionNV", 1, &E_GL_NV_displacement_micromap);
symbolTable.setFunctionExtensions("fetchMicroTriangleVertexBarycentricNV", 1, &E_GL_NV_displacement_micromap);
}
break;
case EShLangTask:
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
symbolTable.setVariableExtensions("gl_TaskCountNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshViewCountNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MeshViewIndicesNV", 1, &E_GL_NV_mesh_shader);
if (profile != EEsProfile) {
symbolTable.setVariableExtensions("gl_WorkGroupSize", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setVariableExtensions("gl_WorkGroupID", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationID", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setVariableExtensions("gl_GlobalInvocationID", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationIndex", Num_AEP_mesh_shader, AEP_mesh_shader);
} else {
symbolTable.setVariableExtensions("gl_WorkGroupSize", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_WorkGroupID", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationID", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_GlobalInvocationID", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_NV_mesh_shader);
}
BuiltInVariable("gl_TaskCountNV", EbvTaskCountNV, symbolTable);
BuiltInVariable("gl_WorkGroupSize", EbvWorkGroupSize, symbolTable);
BuiltInVariable("gl_WorkGroupID", EbvWorkGroupId, symbolTable);
BuiltInVariable("gl_LocalInvocationID", EbvLocalInvocationId, symbolTable);
BuiltInVariable("gl_GlobalInvocationID", EbvGlobalInvocationId, symbolTable);
BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable);
BuiltInVariable("gl_MeshViewCountNV", EbvMeshViewCountNV, symbolTable);
BuiltInVariable("gl_MeshViewIndicesNV", EbvMeshViewIndicesNV, symbolTable);
symbolTable.setVariableExtensions("gl_MaxTaskWorkGroupSizeNV", 1, &E_GL_NV_mesh_shader);
symbolTable.setVariableExtensions("gl_MaxMeshViewCountNV", 1, &E_GL_NV_mesh_shader);
if (profile != EEsProfile) {
symbolTable.setFunctionExtensions("barrier", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setFunctionExtensions("memoryBarrierShared", Num_AEP_mesh_shader, AEP_mesh_shader);
symbolTable.setFunctionExtensions("groupMemoryBarrier", Num_AEP_mesh_shader, AEP_mesh_shader);
} else {
symbolTable.setFunctionExtensions("barrier", 1, &E_GL_NV_mesh_shader);
symbolTable.setFunctionExtensions("memoryBarrierShared", 1, &E_GL_NV_mesh_shader);
symbolTable.setFunctionExtensions("groupMemoryBarrier", 1, &E_GL_NV_mesh_shader);
}
}
if (profile != EEsProfile && version >= 450) {
// GL_EXT_mesh_shader
symbolTable.setFunctionExtensions("EmitMeshTasksEXT", 1, &E_GL_EXT_mesh_shader);
symbolTable.setVariableExtensions("gl_NumWorkGroups", 1, &E_GL_EXT_mesh_shader);
BuiltInVariable("gl_NumWorkGroups", EbvNumWorkGroups, symbolTable);
// GL_EXT_device_group
symbolTable.setVariableExtensions("gl_DeviceIndex", 1, &E_GL_EXT_device_group);
BuiltInVariable("gl_DeviceIndex", EbvDeviceIndex, symbolTable);
// GL_ARB_shader_draw_parameters
symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters);
BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable);
if (version >= 460) {
BuiltInVariable("gl_DrawID", EbvDrawId, symbolTable);
}
// GL_ARB_shader_ballot
symbolTable.setVariableExtensions("gl_SubGroupSizeARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB", 1, &E_GL_ARB_shader_ballot);
BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
BuiltInVariable("gl_SubGroupEqMaskARB", EbvSubGroupEqMask, symbolTable);
BuiltInVariable("gl_SubGroupGeMaskARB", EbvSubGroupGeMask, symbolTable);
BuiltInVariable("gl_SubGroupGtMaskARB", EbvSubGroupGtMask, symbolTable);
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}
// GL_KHR_shader_subgroup
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.setVariableExtensions("gl_NumSubgroups", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupID", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupSize", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupInvocationID", 1, &E_GL_KHR_shader_subgroup_basic);
symbolTable.setVariableExtensions("gl_SubgroupEqMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupGtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLeMask", 1, &E_GL_KHR_shader_subgroup_ballot);
symbolTable.setVariableExtensions("gl_SubgroupLtMask", 1, &E_GL_KHR_shader_subgroup_ballot);
BuiltInVariable("gl_NumSubgroups", EbvNumSubgroups, symbolTable);
BuiltInVariable("gl_SubgroupID", EbvSubgroupID, symbolTable);
BuiltInVariable("gl_SubgroupSize", EbvSubgroupSize2, symbolTable);
BuiltInVariable("gl_SubgroupInvocationID", EbvSubgroupInvocation2, symbolTable);
BuiltInVariable("gl_SubgroupEqMask", EbvSubgroupEqMask2, symbolTable);
BuiltInVariable("gl_SubgroupGeMask", EbvSubgroupGeMask2, symbolTable);
BuiltInVariable("gl_SubgroupGtMask", EbvSubgroupGtMask2, symbolTable);
BuiltInVariable("gl_SubgroupLeMask", EbvSubgroupLeMask2, symbolTable);
BuiltInVariable("gl_SubgroupLtMask", EbvSubgroupLtMask2, symbolTable);
symbolTable.setFunctionExtensions("subgroupMemoryBarrierShared", 1, &E_GL_KHR_shader_subgroup_basic);
// GL_NV_shader_sm_builtins
symbolTable.setVariableExtensions("gl_WarpsPerSMNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMCountNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_WarpIDNV", 1, &E_GL_NV_shader_sm_builtins);
symbolTable.setVariableExtensions("gl_SMIDNV", 1, &E_GL_NV_shader_sm_builtins);
BuiltInVariable("gl_WarpsPerSMNV", EbvWarpsPerSM, symbolTable);
BuiltInVariable("gl_SMCountNV", EbvSMCount, symbolTable);
BuiltInVariable("gl_WarpIDNV", EbvWarpID, symbolTable);
BuiltInVariable("gl_SMIDNV", EbvSMID, symbolTable);
// GL_ARM_shader_core_builtins
symbolTable.setVariableExtensions("gl_CoreCountARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_CoreMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpIDARM", 1, &E_GL_ARM_shader_core_builtins);
symbolTable.setVariableExtensions("gl_WarpMaxIDARM", 1, &E_GL_ARM_shader_core_builtins);
BuiltInVariable("gl_CoreCountARM", EbvCoreCountARM, symbolTable);
BuiltInVariable("gl_CoreIDARM", EbvCoreIDARM, symbolTable);
BuiltInVariable("gl_CoreMaxIDARM", EbvCoreMaxIDARM, symbolTable);
BuiltInVariable("gl_WarpIDARM", EbvWarpIDARM, symbolTable);
BuiltInVariable("gl_WarpMaxIDARM", EbvWarpMaxIDARM, symbolTable);
}
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 450)) {
symbolTable.setVariableExtensions("gl_ShadingRateFlag2VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4VerticalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag2HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
symbolTable.setVariableExtensions("gl_ShadingRateFlag4HorizontalPixelsEXT", 1, &E_GL_EXT_fragment_shading_rate);
}
break;
default:
assert(false && "Language not supported");
break;
}
//
// Next, identify which built-ins have a mapping to an operator.
// If PureOperatorBuiltins is false, those that are not identified as such are
// expected to be resolved through a library of functions, versus as
// operations.
//
relateTabledBuiltins(version, profile, spvVersion, language, symbolTable);
symbolTable.relateToOperator("doubleBitsToInt64", EOpDoubleBitsToInt64);
symbolTable.relateToOperator("doubleBitsToUint64", EOpDoubleBitsToUint64);
symbolTable.relateToOperator("int64BitsToDouble", EOpInt64BitsToDouble);
symbolTable.relateToOperator("uint64BitsToDouble", EOpUint64BitsToDouble);
symbolTable.relateToOperator("halfBitsToInt16", EOpFloat16BitsToInt16);
symbolTable.relateToOperator("halfBitsToUint16", EOpFloat16BitsToUint16);
symbolTable.relateToOperator("float16BitsToInt16", EOpFloat16BitsToInt16);
symbolTable.relateToOperator("float16BitsToUint16", EOpFloat16BitsToUint16);
symbolTable.relateToOperator("int16BitsToFloat16", EOpInt16BitsToFloat16);
symbolTable.relateToOperator("uint16BitsToFloat16", EOpUint16BitsToFloat16);
symbolTable.relateToOperator("int16BitsToHalf", EOpInt16BitsToFloat16);
symbolTable.relateToOperator("uint16BitsToHalf", EOpUint16BitsToFloat16);
symbolTable.relateToOperator("packSnorm4x8", EOpPackSnorm4x8);
symbolTable.relateToOperator("unpackSnorm4x8", EOpUnpackSnorm4x8);
symbolTable.relateToOperator("packUnorm4x8", EOpPackUnorm4x8);
symbolTable.relateToOperator("unpackUnorm4x8", EOpUnpackUnorm4x8);
symbolTable.relateToOperator("packDouble2x32", EOpPackDouble2x32);
symbolTable.relateToOperator("unpackDouble2x32", EOpUnpackDouble2x32);
symbolTable.relateToOperator("packInt2x32", EOpPackInt2x32);
symbolTable.relateToOperator("unpackInt2x32", EOpUnpackInt2x32);
symbolTable.relateToOperator("packUint2x32", EOpPackUint2x32);
symbolTable.relateToOperator("unpackUint2x32", EOpUnpackUint2x32);
symbolTable.relateToOperator("packInt2x16", EOpPackInt2x16);
symbolTable.relateToOperator("unpackInt2x16", EOpUnpackInt2x16);
symbolTable.relateToOperator("packUint2x16", EOpPackUint2x16);
symbolTable.relateToOperator("unpackUint2x16", EOpUnpackUint2x16);
symbolTable.relateToOperator("packInt4x16", EOpPackInt4x16);
symbolTable.relateToOperator("unpackInt4x16", EOpUnpackInt4x16);
symbolTable.relateToOperator("packUint4x16", EOpPackUint4x16);
symbolTable.relateToOperator("unpackUint4x16", EOpUnpackUint4x16);
symbolTable.relateToOperator("packFloat2x16", EOpPackFloat2x16);
symbolTable.relateToOperator("unpackFloat2x16", EOpUnpackFloat2x16);
symbolTable.relateToOperator("pack16", EOpPack16);
symbolTable.relateToOperator("pack32", EOpPack32);
symbolTable.relateToOperator("pack64", EOpPack64);
symbolTable.relateToOperator("unpack32", EOpUnpack32);
symbolTable.relateToOperator("unpack16", EOpUnpack16);
symbolTable.relateToOperator("unpack8", EOpUnpack8);
symbolTable.relateToOperator("controlBarrier", EOpBarrier);
symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierAtomicCounter);
symbolTable.relateToOperator("memoryBarrierImage", EOpMemoryBarrierImage);
if (spvVersion.vulkanRelaxed) {
//
// functions signature have been replaced to take uint operations on buffer variables
// remap atomic counter functions to atomic operations
//
symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierBuffer);
}
symbolTable.relateToOperator("atomicLoad", EOpAtomicLoad);
symbolTable.relateToOperator("atomicStore", EOpAtomicStore);
symbolTable.relateToOperator("atomicCounterIncrement", EOpAtomicCounterIncrement);
symbolTable.relateToOperator("atomicCounterDecrement", EOpAtomicCounterDecrement);
symbolTable.relateToOperator("atomicCounter", EOpAtomicCounter);
if (spvVersion.vulkanRelaxed) {
//
// functions signature have been replaced to take uint operations
// remap atomic counter functions to atomic operations
//
// these atomic counter functions do not match signatures of glsl
// atomic functions, so they will be remapped to semantically
// equivalent functions in the parser
//
symbolTable.relateToOperator("atomicCounterIncrement", EOpNull);
symbolTable.relateToOperator("atomicCounterDecrement", EOpNull);
symbolTable.relateToOperator("atomicCounter", EOpNull);
}
symbolTable.relateToOperator("clockARB", EOpReadClockSubgroupKHR);
symbolTable.relateToOperator("clock2x32ARB", EOpReadClockSubgroupKHR);
symbolTable.relateToOperator("clockRealtimeEXT", EOpReadClockDeviceKHR);
symbolTable.relateToOperator("clockRealtime2x32EXT", EOpReadClockDeviceKHR);
if (profile != EEsProfile && version == 450) {
symbolTable.relateToOperator("atomicCounterAddARB", EOpAtomicCounterAdd);
symbolTable.relateToOperator("atomicCounterSubtractARB", EOpAtomicCounterSubtract);
symbolTable.relateToOperator("atomicCounterMinARB", EOpAtomicCounterMin);
symbolTable.relateToOperator("atomicCounterMaxARB", EOpAtomicCounterMax);
symbolTable.relateToOperator("atomicCounterAndARB", EOpAtomicCounterAnd);
symbolTable.relateToOperator("atomicCounterOrARB", EOpAtomicCounterOr);
symbolTable.relateToOperator("atomicCounterXorARB", EOpAtomicCounterXor);
symbolTable.relateToOperator("atomicCounterExchangeARB", EOpAtomicCounterExchange);
symbolTable.relateToOperator("atomicCounterCompSwapARB", EOpAtomicCounterCompSwap);
}
if (profile != EEsProfile && version >= 460) {
symbolTable.relateToOperator("atomicCounterAdd", EOpAtomicCounterAdd);
symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicCounterSubtract);
symbolTable.relateToOperator("atomicCounterMin", EOpAtomicCounterMin);
symbolTable.relateToOperator("atomicCounterMax", EOpAtomicCounterMax);
symbolTable.relateToOperator("atomicCounterAnd", EOpAtomicCounterAnd);
symbolTable.relateToOperator("atomicCounterOr", EOpAtomicCounterOr);
symbolTable.relateToOperator("atomicCounterXor", EOpAtomicCounterXor);
symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicCounterExchange);
symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCounterCompSwap);
}
if (spvVersion.vulkanRelaxed) {
//
// functions signature have been replaced to take 'uint' instead of 'atomic_uint'
// remap atomic counter functions to non-counter atomic ops so
// functions act as aliases to non-counter atomic ops
//
symbolTable.relateToOperator("atomicCounterAdd", EOpAtomicAdd);
symbolTable.relateToOperator("atomicCounterSubtract", EOpAtomicSubtract);
symbolTable.relateToOperator("atomicCounterMin", EOpAtomicMin);
symbolTable.relateToOperator("atomicCounterMax", EOpAtomicMax);
symbolTable.relateToOperator("atomicCounterAnd", EOpAtomicAnd);
symbolTable.relateToOperator("atomicCounterOr", EOpAtomicOr);
symbolTable.relateToOperator("atomicCounterXor", EOpAtomicXor);
symbolTable.relateToOperator("atomicCounterExchange", EOpAtomicExchange);
symbolTable.relateToOperator("atomicCounterCompSwap", EOpAtomicCompSwap);
}
symbolTable.relateToOperator("fma", EOpFma);
symbolTable.relateToOperator("frexp", EOpFrexp);
symbolTable.relateToOperator("ldexp", EOpLdexp);
symbolTable.relateToOperator("uaddCarry", EOpAddCarry);
symbolTable.relateToOperator("usubBorrow", EOpSubBorrow);
symbolTable.relateToOperator("umulExtended", EOpUMulExtended);
symbolTable.relateToOperator("imulExtended", EOpIMulExtended);
symbolTable.relateToOperator("bitfieldExtract", EOpBitfieldExtract);
symbolTable.relateToOperator("bitfieldInsert", EOpBitfieldInsert);
symbolTable.relateToOperator("bitfieldReverse", EOpBitFieldReverse);
symbolTable.relateToOperator("bitCount", EOpBitCount);
symbolTable.relateToOperator("findLSB", EOpFindLSB);
symbolTable.relateToOperator("findMSB", EOpFindMSB);
symbolTable.relateToOperator("helperInvocationEXT", EOpIsHelperInvocation);
symbolTable.relateToOperator("countLeadingZeros", EOpCountLeadingZeros);
symbolTable.relateToOperator("countTrailingZeros", EOpCountTrailingZeros);
symbolTable.relateToOperator("absoluteDifference", EOpAbsDifference);
symbolTable.relateToOperator("addSaturate", EOpAddSaturate);
symbolTable.relateToOperator("subtractSaturate", EOpSubSaturate);
symbolTable.relateToOperator("average", EOpAverage);
symbolTable.relateToOperator("averageRounded", EOpAverageRounded);
symbolTable.relateToOperator("multiply32x16", EOpMul32x16);
symbolTable.relateToOperator("debugPrintfEXT", EOpDebugPrintf);
symbolTable.relateToOperator("assumeEXT", EOpAssumeEXT);
symbolTable.relateToOperator("expectEXT", EOpExpectEXT);
if (PureOperatorBuiltins) {
symbolTable.relateToOperator("imageSize", EOpImageQuerySize);
symbolTable.relateToOperator("imageSamples", EOpImageQuerySamples);
symbolTable.relateToOperator("imageLoad", EOpImageLoad);
symbolTable.relateToOperator("imageStore", EOpImageStore);
symbolTable.relateToOperator("imageAtomicAdd", EOpImageAtomicAdd);
symbolTable.relateToOperator("imageAtomicMin", EOpImageAtomicMin);
symbolTable.relateToOperator("imageAtomicMax", EOpImageAtomicMax);
symbolTable.relateToOperator("imageAtomicAnd", EOpImageAtomicAnd);
symbolTable.relateToOperator("imageAtomicOr", EOpImageAtomicOr);
symbolTable.relateToOperator("imageAtomicXor", EOpImageAtomicXor);
symbolTable.relateToOperator("imageAtomicExchange", EOpImageAtomicExchange);
symbolTable.relateToOperator("imageAtomicCompSwap", EOpImageAtomicCompSwap);
symbolTable.relateToOperator("imageAtomicLoad", EOpImageAtomicLoad);
symbolTable.relateToOperator("imageAtomicStore", EOpImageAtomicStore);
symbolTable.relateToOperator("subpassLoad", EOpSubpassLoad);
symbolTable.relateToOperator("subpassLoadMS", EOpSubpassLoadMS);
symbolTable.relateToOperator("textureGather", EOpTextureGather);
symbolTable.relateToOperator("textureGatherOffset", EOpTextureGatherOffset);
symbolTable.relateToOperator("textureGatherOffsets", EOpTextureGatherOffsets);
symbolTable.relateToOperator("noise1", EOpNoise);
symbolTable.relateToOperator("noise2", EOpNoise);
symbolTable.relateToOperator("noise3", EOpNoise);
symbolTable.relateToOperator("noise4", EOpNoise);
symbolTable.relateToOperator("textureFootprintNV", EOpImageSampleFootprintNV);
symbolTable.relateToOperator("textureFootprintClampNV", EOpImageSampleFootprintClampNV);
symbolTable.relateToOperator("textureFootprintLodNV", EOpImageSampleFootprintLodNV);
symbolTable.relateToOperator("textureFootprintGradNV", EOpImageSampleFootprintGradNV);
symbolTable.relateToOperator("textureFootprintGradClampNV", EOpImageSampleFootprintGradClampNV);
if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion))
symbolTable.relateToOperator("ftransform", EOpFtransform);
if (spvVersion.spv == 0 && (IncludeLegacy(version, profile, spvVersion) ||
(profile == EEsProfile && version == 100))) {
symbolTable.relateToOperator("texture1D", EOpTexture);
symbolTable.relateToOperator("texture1DGradARB", EOpTextureGrad);
symbolTable.relateToOperator("texture1DProj", EOpTextureProj);
symbolTable.relateToOperator("texture1DProjGradARB", EOpTextureProjGrad);
symbolTable.relateToOperator("texture1DLod", EOpTextureLod);
symbolTable.relateToOperator("texture1DProjLod", EOpTextureProjLod);
symbolTable.relateToOperator("texture2DRect", EOpTexture);
symbolTable.relateToOperator("texture2DRectProj", EOpTextureProj);
symbolTable.relateToOperator("texture2DRectGradARB", EOpTextureGrad);
symbolTable.relateToOperator("texture2DRectProjGradARB", EOpTextureProjGrad);
symbolTable.relateToOperator("shadow2DRect", EOpTexture);
symbolTable.relateToOperator("shadow2DRectProj", EOpTextureProj);
symbolTable.relateToOperator("shadow2DRectGradARB", EOpTextureGrad);
symbolTable.relateToOperator("shadow2DRectProjGradARB", EOpTextureProjGrad);
symbolTable.relateToOperator("texture2D", EOpTexture);
symbolTable.relateToOperator("texture2DProj", EOpTextureProj);
symbolTable.relateToOperator("texture2DGradEXT", EOpTextureGrad);
symbolTable.relateToOperator("texture2DGradARB", EOpTextureGrad);
symbolTable.relateToOperator("texture2DProjGradEXT", EOpTextureProjGrad);
symbolTable.relateToOperator("texture2DProjGradARB", EOpTextureProjGrad);
symbolTable.relateToOperator("texture2DLod", EOpTextureLod);
symbolTable.relateToOperator("texture2DLodEXT", EOpTextureLod);
symbolTable.relateToOperator("texture2DProjLod", EOpTextureProjLod);
symbolTable.relateToOperator("texture2DProjLodEXT", EOpTextureProjLod);
symbolTable.relateToOperator("texture3D", EOpTexture);
symbolTable.relateToOperator("texture3DGradARB", EOpTextureGrad);
symbolTable.relateToOperator("texture3DProj", EOpTextureProj);
symbolTable.relateToOperator("texture3DProjGradARB", EOpTextureProjGrad);
symbolTable.relateToOperator("texture3DLod", EOpTextureLod);
symbolTable.relateToOperator("texture3DProjLod", EOpTextureProjLod);
symbolTable.relateToOperator("textureCube", EOpTexture);
symbolTable.relateToOperator("textureCubeGradEXT", EOpTextureGrad);
symbolTable.relateToOperator("textureCubeGradARB", EOpTextureGrad);
symbolTable.relateToOperator("textureCubeLod", EOpTextureLod);
symbolTable.relateToOperator("textureCubeLodEXT", EOpTextureLod);
symbolTable.relateToOperator("shadow1D", EOpTexture);
symbolTable.relateToOperator("shadow1DGradARB", EOpTextureGrad);
symbolTable.relateToOperator("shadow2D", EOpTexture);
symbolTable.relateToOperator("shadow2DGradARB", EOpTextureGrad);
symbolTable.relateToOperator("shadow1DProj", EOpTextureProj);
symbolTable.relateToOperator("shadow2DProj", EOpTextureProj);
symbolTable.relateToOperator("shadow1DProjGradARB", EOpTextureProjGrad);
symbolTable.relateToOperator("shadow2DProjGradARB", EOpTextureProjGrad);
symbolTable.relateToOperator("shadow1DLod", EOpTextureLod);
symbolTable.relateToOperator("shadow2DLod", EOpTextureLod);
symbolTable.relateToOperator("shadow1DProjLod", EOpTextureProjLod);
symbolTable.relateToOperator("shadow2DProjLod", EOpTextureProjLod);
}
if (profile != EEsProfile) {
symbolTable.relateToOperator("sparseTextureARB", EOpSparseTexture);
symbolTable.relateToOperator("sparseTextureLodARB", EOpSparseTextureLod);
symbolTable.relateToOperator("sparseTextureOffsetARB", EOpSparseTextureOffset);
symbolTable.relateToOperator("sparseTexelFetchARB", EOpSparseTextureFetch);
symbolTable.relateToOperator("sparseTexelFetchOffsetARB", EOpSparseTextureFetchOffset);
symbolTable.relateToOperator("sparseTextureLodOffsetARB", EOpSparseTextureLodOffset);
symbolTable.relateToOperator("sparseTextureGradARB", EOpSparseTextureGrad);
symbolTable.relateToOperator("sparseTextureGradOffsetARB", EOpSparseTextureGradOffset);
symbolTable.relateToOperator("sparseTextureGatherARB", EOpSparseTextureGather);
symbolTable.relateToOperator("sparseTextureGatherOffsetARB", EOpSparseTextureGatherOffset);
symbolTable.relateToOperator("sparseTextureGatherOffsetsARB", EOpSparseTextureGatherOffsets);
symbolTable.relateToOperator("sparseImageLoadARB", EOpSparseImageLoad);
symbolTable.relateToOperator("sparseTexelsResidentARB", EOpSparseTexelsResident);
symbolTable.relateToOperator("sparseTextureClampARB", EOpSparseTextureClamp);
symbolTable.relateToOperator("sparseTextureOffsetClampARB", EOpSparseTextureOffsetClamp);
symbolTable.relateToOperator("sparseTextureGradClampARB", EOpSparseTextureGradClamp);
symbolTable.relateToOperator("sparseTextureGradOffsetClampARB", EOpSparseTextureGradOffsetClamp);
symbolTable.relateToOperator("textureClampARB", EOpTextureClamp);
symbolTable.relateToOperator("textureOffsetClampARB", EOpTextureOffsetClamp);
symbolTable.relateToOperator("textureGradClampARB", EOpTextureGradClamp);
symbolTable.relateToOperator("textureGradOffsetClampARB", EOpTextureGradOffsetClamp);
symbolTable.relateToOperator("ballotARB", EOpBallot);
symbolTable.relateToOperator("readInvocationARB", EOpReadInvocation);
symbolTable.relateToOperator("readFirstInvocationARB", EOpReadFirstInvocation);
if (version >= 430) {
symbolTable.relateToOperator("anyInvocationARB", EOpAnyInvocation);
symbolTable.relateToOperator("allInvocationsARB", EOpAllInvocations);
symbolTable.relateToOperator("allInvocationsEqualARB", EOpAllInvocationsEqual);
}
if (version >= 460) {
symbolTable.relateToOperator("anyInvocation", EOpAnyInvocation);
symbolTable.relateToOperator("allInvocations", EOpAllInvocations);
symbolTable.relateToOperator("allInvocationsEqual", EOpAllInvocationsEqual);
}
symbolTable.relateToOperator("minInvocationsAMD", EOpMinInvocations);
symbolTable.relateToOperator("maxInvocationsAMD", EOpMaxInvocations);
symbolTable.relateToOperator("addInvocationsAMD", EOpAddInvocations);
symbolTable.relateToOperator("minInvocationsNonUniformAMD", EOpMinInvocationsNonUniform);
symbolTable.relateToOperator("maxInvocationsNonUniformAMD", EOpMaxInvocationsNonUniform);
symbolTable.relateToOperator("addInvocationsNonUniformAMD", EOpAddInvocationsNonUniform);
symbolTable.relateToOperator("minInvocationsInclusiveScanAMD", EOpMinInvocationsInclusiveScan);
symbolTable.relateToOperator("maxInvocationsInclusiveScanAMD", EOpMaxInvocationsInclusiveScan);
symbolTable.relateToOperator("addInvocationsInclusiveScanAMD", EOpAddInvocationsInclusiveScan);
symbolTable.relateToOperator("minInvocationsInclusiveScanNonUniformAMD", EOpMinInvocationsInclusiveScanNonUniform);
symbolTable.relateToOperator("maxInvocationsInclusiveScanNonUniformAMD", EOpMaxInvocationsInclusiveScanNonUniform);
symbolTable.relateToOperator("addInvocationsInclusiveScanNonUniformAMD", EOpAddInvocationsInclusiveScanNonUniform);
symbolTable.relateToOperator("minInvocationsExclusiveScanAMD", EOpMinInvocationsExclusiveScan);
symbolTable.relateToOperator("maxInvocationsExclusiveScanAMD", EOpMaxInvocationsExclusiveScan);
symbolTable.relateToOperator("addInvocationsExclusiveScanAMD", EOpAddInvocationsExclusiveScan);
symbolTable.relateToOperator("minInvocationsExclusiveScanNonUniformAMD", EOpMinInvocationsExclusiveScanNonUniform);
symbolTable.relateToOperator("maxInvocationsExclusiveScanNonUniformAMD", EOpMaxInvocationsExclusiveScanNonUniform);
symbolTable.relateToOperator("addInvocationsExclusiveScanNonUniformAMD", EOpAddInvocationsExclusiveScanNonUniform);
symbolTable.relateToOperator("swizzleInvocationsAMD", EOpSwizzleInvocations);
symbolTable.relateToOperator("swizzleInvocationsMaskedAMD", EOpSwizzleInvocationsMasked);
symbolTable.relateToOperator("writeInvocationAMD", EOpWriteInvocation);
symbolTable.relateToOperator("mbcntAMD", EOpMbcnt);
symbolTable.relateToOperator("min3", EOpMin3);
symbolTable.relateToOperator("max3", EOpMax3);
symbolTable.relateToOperator("mid3", EOpMid3);
symbolTable.relateToOperator("cubeFaceIndexAMD", EOpCubeFaceIndex);
symbolTable.relateToOperator("cubeFaceCoordAMD", EOpCubeFaceCoord);
symbolTable.relateToOperator("timeAMD", EOpTime);
symbolTable.relateToOperator("textureGatherLodAMD", EOpTextureGatherLod);
symbolTable.relateToOperator("textureGatherLodOffsetAMD", EOpTextureGatherLodOffset);
symbolTable.relateToOperator("textureGatherLodOffsetsAMD", EOpTextureGatherLodOffsets);
symbolTable.relateToOperator("sparseTextureGatherLodAMD", EOpSparseTextureGatherLod);
symbolTable.relateToOperator("sparseTextureGatherLodOffsetAMD", EOpSparseTextureGatherLodOffset);
symbolTable.relateToOperator("sparseTextureGatherLodOffsetsAMD", EOpSparseTextureGatherLodOffsets);
symbolTable.relateToOperator("imageLoadLodAMD", EOpImageLoadLod);
symbolTable.relateToOperator("imageStoreLodAMD", EOpImageStoreLod);
symbolTable.relateToOperator("sparseImageLoadLodAMD", EOpSparseImageLoadLod);
symbolTable.relateToOperator("fragmentMaskFetchAMD", EOpFragmentMaskFetch);
symbolTable.relateToOperator("fragmentFetchAMD", EOpFragmentFetch);
}
// GL_KHR_shader_subgroup
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.relateToOperator("subgroupBarrier", EOpSubgroupBarrier);
symbolTable.relateToOperator("subgroupMemoryBarrier", EOpSubgroupMemoryBarrier);
symbolTable.relateToOperator("subgroupMemoryBarrierBuffer", EOpSubgroupMemoryBarrierBuffer);
symbolTable.relateToOperator("subgroupMemoryBarrierImage", EOpSubgroupMemoryBarrierImage);
symbolTable.relateToOperator("subgroupElect", EOpSubgroupElect);
symbolTable.relateToOperator("subgroupAll", EOpSubgroupAll);
symbolTable.relateToOperator("subgroupAny", EOpSubgroupAny);
symbolTable.relateToOperator("subgroupAllEqual", EOpSubgroupAllEqual);
symbolTable.relateToOperator("subgroupBroadcast", EOpSubgroupBroadcast);
symbolTable.relateToOperator("subgroupBroadcastFirst", EOpSubgroupBroadcastFirst);
symbolTable.relateToOperator("subgroupBallot", EOpSubgroupBallot);
symbolTable.relateToOperator("subgroupInverseBallot", EOpSubgroupInverseBallot);
symbolTable.relateToOperator("subgroupBallotBitExtract", EOpSubgroupBallotBitExtract);
symbolTable.relateToOperator("subgroupBallotBitCount", EOpSubgroupBallotBitCount);
symbolTable.relateToOperator("subgroupBallotInclusiveBitCount", EOpSubgroupBallotInclusiveBitCount);
symbolTable.relateToOperator("subgroupBallotExclusiveBitCount", EOpSubgroupBallotExclusiveBitCount);
symbolTable.relateToOperator("subgroupBallotFindLSB", EOpSubgroupBallotFindLSB);
symbolTable.relateToOperator("subgroupBallotFindMSB", EOpSubgroupBallotFindMSB);
symbolTable.relateToOperator("subgroupShuffle", EOpSubgroupShuffle);
symbolTable.relateToOperator("subgroupShuffleXor", EOpSubgroupShuffleXor);
symbolTable.relateToOperator("subgroupShuffleUp", EOpSubgroupShuffleUp);
symbolTable.relateToOperator("subgroupShuffleDown", EOpSubgroupShuffleDown);
symbolTable.relateToOperator("subgroupRotate", EOpSubgroupRotate);
symbolTable.relateToOperator("subgroupClusteredRotate", EOpSubgroupClusteredRotate);
symbolTable.relateToOperator("subgroupAdd", EOpSubgroupAdd);
symbolTable.relateToOperator("subgroupMul", EOpSubgroupMul);
symbolTable.relateToOperator("subgroupMin", EOpSubgroupMin);
symbolTable.relateToOperator("subgroupMax", EOpSubgroupMax);
symbolTable.relateToOperator("subgroupAnd", EOpSubgroupAnd);
symbolTable.relateToOperator("subgroupOr", EOpSubgroupOr);
symbolTable.relateToOperator("subgroupXor", EOpSubgroupXor);
symbolTable.relateToOperator("subgroupInclusiveAdd", EOpSubgroupInclusiveAdd);
symbolTable.relateToOperator("subgroupInclusiveMul", EOpSubgroupInclusiveMul);
symbolTable.relateToOperator("subgroupInclusiveMin", EOpSubgroupInclusiveMin);
symbolTable.relateToOperator("subgroupInclusiveMax", EOpSubgroupInclusiveMax);
symbolTable.relateToOperator("subgroupInclusiveAnd", EOpSubgroupInclusiveAnd);
symbolTable.relateToOperator("subgroupInclusiveOr", EOpSubgroupInclusiveOr);
symbolTable.relateToOperator("subgroupInclusiveXor", EOpSubgroupInclusiveXor);
symbolTable.relateToOperator("subgroupExclusiveAdd", EOpSubgroupExclusiveAdd);
symbolTable.relateToOperator("subgroupExclusiveMul", EOpSubgroupExclusiveMul);
symbolTable.relateToOperator("subgroupExclusiveMin", EOpSubgroupExclusiveMin);
symbolTable.relateToOperator("subgroupExclusiveMax", EOpSubgroupExclusiveMax);
symbolTable.relateToOperator("subgroupExclusiveAnd", EOpSubgroupExclusiveAnd);
symbolTable.relateToOperator("subgroupExclusiveOr", EOpSubgroupExclusiveOr);
symbolTable.relateToOperator("subgroupExclusiveXor", EOpSubgroupExclusiveXor);
symbolTable.relateToOperator("subgroupClusteredAdd", EOpSubgroupClusteredAdd);
symbolTable.relateToOperator("subgroupClusteredMul", EOpSubgroupClusteredMul);
symbolTable.relateToOperator("subgroupClusteredMin", EOpSubgroupClusteredMin);
symbolTable.relateToOperator("subgroupClusteredMax", EOpSubgroupClusteredMax);
symbolTable.relateToOperator("subgroupClusteredAnd", EOpSubgroupClusteredAnd);
symbolTable.relateToOperator("subgroupClusteredOr", EOpSubgroupClusteredOr);
symbolTable.relateToOperator("subgroupClusteredXor", EOpSubgroupClusteredXor);
symbolTable.relateToOperator("subgroupQuadBroadcast", EOpSubgroupQuadBroadcast);
symbolTable.relateToOperator("subgroupQuadSwapHorizontal", EOpSubgroupQuadSwapHorizontal);
symbolTable.relateToOperator("subgroupQuadSwapVertical", EOpSubgroupQuadSwapVertical);
symbolTable.relateToOperator("subgroupQuadSwapDiagonal", EOpSubgroupQuadSwapDiagonal);
symbolTable.relateToOperator("subgroupPartitionNV", EOpSubgroupPartition);
symbolTable.relateToOperator("subgroupPartitionedAddNV", EOpSubgroupPartitionedAdd);
symbolTable.relateToOperator("subgroupPartitionedMulNV", EOpSubgroupPartitionedMul);
symbolTable.relateToOperator("subgroupPartitionedMinNV", EOpSubgroupPartitionedMin);
symbolTable.relateToOperator("subgroupPartitionedMaxNV", EOpSubgroupPartitionedMax);
symbolTable.relateToOperator("subgroupPartitionedAndNV", EOpSubgroupPartitionedAnd);
symbolTable.relateToOperator("subgroupPartitionedOrNV", EOpSubgroupPartitionedOr);
symbolTable.relateToOperator("subgroupPartitionedXorNV", EOpSubgroupPartitionedXor);
symbolTable.relateToOperator("subgroupPartitionedInclusiveAddNV", EOpSubgroupPartitionedInclusiveAdd);
symbolTable.relateToOperator("subgroupPartitionedInclusiveMulNV", EOpSubgroupPartitionedInclusiveMul);
symbolTable.relateToOperator("subgroupPartitionedInclusiveMinNV", EOpSubgroupPartitionedInclusiveMin);
symbolTable.relateToOperator("subgroupPartitionedInclusiveMaxNV", EOpSubgroupPartitionedInclusiveMax);
symbolTable.relateToOperator("subgroupPartitionedInclusiveAndNV", EOpSubgroupPartitionedInclusiveAnd);
symbolTable.relateToOperator("subgroupPartitionedInclusiveOrNV", EOpSubgroupPartitionedInclusiveOr);
symbolTable.relateToOperator("subgroupPartitionedInclusiveXorNV", EOpSubgroupPartitionedInclusiveXor);
symbolTable.relateToOperator("subgroupPartitionedExclusiveAddNV", EOpSubgroupPartitionedExclusiveAdd);
symbolTable.relateToOperator("subgroupPartitionedExclusiveMulNV", EOpSubgroupPartitionedExclusiveMul);
symbolTable.relateToOperator("subgroupPartitionedExclusiveMinNV", EOpSubgroupPartitionedExclusiveMin);
symbolTable.relateToOperator("subgroupPartitionedExclusiveMaxNV", EOpSubgroupPartitionedExclusiveMax);
symbolTable.relateToOperator("subgroupPartitionedExclusiveAndNV", EOpSubgroupPartitionedExclusiveAnd);
symbolTable.relateToOperator("subgroupPartitionedExclusiveOrNV", EOpSubgroupPartitionedExclusiveOr);
symbolTable.relateToOperator("subgroupPartitionedExclusiveXorNV", EOpSubgroupPartitionedExclusiveXor);
}
if (profile == EEsProfile) {
symbolTable.relateToOperator("shadow2DEXT", EOpTexture);
symbolTable.relateToOperator("shadow2DProjEXT", EOpTextureProj);
}
// GL_EXT_shader_quad_control
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.relateToOperator("subgroupQuadAll", EOpSubgroupQuadAll);
symbolTable.relateToOperator("subgroupQuadAny", EOpSubgroupQuadAny);
}
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 140)) {
symbolTable.relateToOperator("textureWeightedQCOM", EOpImageSampleWeightedQCOM);
symbolTable.relateToOperator("textureBoxFilterQCOM", EOpImageBoxFilterQCOM);
symbolTable.relateToOperator("textureBlockMatchSADQCOM", EOpImageBlockMatchSADQCOM);
symbolTable.relateToOperator("textureBlockMatchSSDQCOM", EOpImageBlockMatchSSDQCOM);
symbolTable.relateToOperator("textureBlockMatchWindowSSDQCOM", EOpImageBlockMatchWindowSSDQCOM);
symbolTable.relateToOperator("textureBlockMatchWindowSADQCOM", EOpImageBlockMatchWindowSADQCOM);
symbolTable.relateToOperator("textureBlockMatchGatherSSDQCOM", EOpImageBlockMatchGatherSSDQCOM);
symbolTable.relateToOperator("textureBlockMatchGatherSADQCOM", EOpImageBlockMatchGatherSADQCOM);
}
if (profile != EEsProfile && spvVersion.spv == 0) {
symbolTable.relateToOperator("texture1DArray", EOpTexture);
symbolTable.relateToOperator("texture2DArray", EOpTexture);
symbolTable.relateToOperator("shadow1DArray", EOpTexture);
symbolTable.relateToOperator("shadow2DArray", EOpTexture);
symbolTable.relateToOperator("texture1DArrayLod", EOpTextureLod);
symbolTable.relateToOperator("texture2DArrayLod", EOpTextureLod);
symbolTable.relateToOperator("shadow1DArrayLod", EOpTextureLod);
}
}
switch(language) {
case EShLangVertex:
break;
case EShLangTessControl:
case EShLangTessEvaluation:
break;
case EShLangGeometry:
symbolTable.relateToOperator("EmitStreamVertex", EOpEmitStreamVertex);
symbolTable.relateToOperator("EndStreamPrimitive", EOpEndStreamPrimitive);
symbolTable.relateToOperator("EmitVertex", EOpEmitVertex);
symbolTable.relateToOperator("EndPrimitive", EOpEndPrimitive);
break;
case EShLangFragment:
if (profile != EEsProfile && version >= 400) {
symbolTable.relateToOperator("dFdxFine", EOpDPdxFine);
symbolTable.relateToOperator("dFdyFine", EOpDPdyFine);
symbolTable.relateToOperator("fwidthFine", EOpFwidthFine);
symbolTable.relateToOperator("dFdxCoarse", EOpDPdxCoarse);
symbolTable.relateToOperator("dFdyCoarse", EOpDPdyCoarse);
symbolTable.relateToOperator("fwidthCoarse", EOpFwidthCoarse);
}
if (profile != EEsProfile && version >= 460) {
symbolTable.relateToOperator("rayQueryInitializeEXT", EOpRayQueryInitialize);
symbolTable.relateToOperator("rayQueryTerminateEXT", EOpRayQueryTerminate);
symbolTable.relateToOperator("rayQueryGenerateIntersectionEXT", EOpRayQueryGenerateIntersection);
symbolTable.relateToOperator("rayQueryConfirmIntersectionEXT", EOpRayQueryConfirmIntersection);
symbolTable.relateToOperator("rayQueryProceedEXT", EOpRayQueryProceed);
symbolTable.relateToOperator("rayQueryGetIntersectionTypeEXT", EOpRayQueryGetIntersectionType);
symbolTable.relateToOperator("rayQueryGetRayTMinEXT", EOpRayQueryGetRayTMin);
symbolTable.relateToOperator("rayQueryGetRayFlagsEXT", EOpRayQueryGetRayFlags);
symbolTable.relateToOperator("rayQueryGetIntersectionTEXT", EOpRayQueryGetIntersectionT);
symbolTable.relateToOperator("rayQueryGetIntersectionInstanceCustomIndexEXT", EOpRayQueryGetIntersectionInstanceCustomIndex);
symbolTable.relateToOperator("rayQueryGetIntersectionInstanceIdEXT", EOpRayQueryGetIntersectionInstanceId);
symbolTable.relateToOperator("rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT", EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset);
symbolTable.relateToOperator("rayQueryGetIntersectionGeometryIndexEXT", EOpRayQueryGetIntersectionGeometryIndex);
symbolTable.relateToOperator("rayQueryGetIntersectionPrimitiveIndexEXT", EOpRayQueryGetIntersectionPrimitiveIndex);
symbolTable.relateToOperator("rayQueryGetIntersectionBarycentricsEXT", EOpRayQueryGetIntersectionBarycentrics);
symbolTable.relateToOperator("rayQueryGetIntersectionFrontFaceEXT", EOpRayQueryGetIntersectionFrontFace);
symbolTable.relateToOperator("rayQueryGetIntersectionCandidateAABBOpaqueEXT", EOpRayQueryGetIntersectionCandidateAABBOpaque);
symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayDirectionEXT", EOpRayQueryGetIntersectionObjectRayDirection);
symbolTable.relateToOperator("rayQueryGetIntersectionObjectRayOriginEXT", EOpRayQueryGetIntersectionObjectRayOrigin);
symbolTable.relateToOperator("rayQueryGetWorldRayDirectionEXT", EOpRayQueryGetWorldRayDirection);
symbolTable.relateToOperator("rayQueryGetWorldRayOriginEXT", EOpRayQueryGetWorldRayOrigin);
symbolTable.relateToOperator("rayQueryGetIntersectionObjectToWorldEXT", EOpRayQueryGetIntersectionObjectToWorld);
symbolTable.relateToOperator("rayQueryGetIntersectionWorldToObjectEXT", EOpRayQueryGetIntersectionWorldToObject);
symbolTable.relateToOperator("rayQueryGetIntersectionTriangleVertexPositionsEXT", EOpRayQueryGetIntersectionTriangleVertexPositionsEXT);
}
symbolTable.relateToOperator("interpolateAtCentroid", EOpInterpolateAtCentroid);
symbolTable.relateToOperator("interpolateAtSample", EOpInterpolateAtSample);
symbolTable.relateToOperator("interpolateAtOffset", EOpInterpolateAtOffset);
if (profile != EEsProfile)
symbolTable.relateToOperator("interpolateAtVertexAMD", EOpInterpolateAtVertex);
symbolTable.relateToOperator("beginInvocationInterlockARB", EOpBeginInvocationInterlock);
symbolTable.relateToOperator("endInvocationInterlockARB", EOpEndInvocationInterlock);
symbolTable.relateToOperator("stencilAttachmentReadEXT", EOpStencilAttachmentReadEXT);
symbolTable.relateToOperator("depthAttachmentReadEXT", EOpDepthAttachmentReadEXT);
symbolTable.relateToOperator("colorAttachmentReadEXT", EOpColorAttachmentReadEXT);
break;
case EShLangCompute:
symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
if ((profile != EEsProfile && version >= 450) ||
(profile == EEsProfile && version >= 320)) {
symbolTable.relateToOperator("dFdx", EOpDPdx);
symbolTable.relateToOperator("dFdy", EOpDPdy);
symbolTable.relateToOperator("fwidth", EOpFwidth);
symbolTable.relateToOperator("dFdxFine", EOpDPdxFine);
symbolTable.relateToOperator("dFdyFine", EOpDPdyFine);
symbolTable.relateToOperator("fwidthFine", EOpFwidthFine);
symbolTable.relateToOperator("dFdxCoarse", EOpDPdxCoarse);
symbolTable.relateToOperator("dFdyCoarse", EOpDPdyCoarse);
symbolTable.relateToOperator("fwidthCoarse",EOpFwidthCoarse);
}
symbolTable.relateToOperator("coopMatLoadNV", EOpCooperativeMatrixLoadNV);
symbolTable.relateToOperator("coopMatStoreNV", EOpCooperativeMatrixStoreNV);
symbolTable.relateToOperator("coopMatMulAddNV", EOpCooperativeMatrixMulAddNV);
symbolTable.relateToOperator("coopMatLoad", EOpCooperativeMatrixLoad);
symbolTable.relateToOperator("coopMatStore", EOpCooperativeMatrixStore);
symbolTable.relateToOperator("coopMatMulAdd", EOpCooperativeMatrixMulAdd);
if (profile != EEsProfile && version >= 460) {
symbolTable.relateToOperator("fetchMicroTriangleVertexPositionNV", EOpFetchMicroTriangleVertexPositionNV);
symbolTable.relateToOperator("fetchMicroTriangleVertexBarycentricNV", EOpFetchMicroTriangleVertexBarycentricNV);
}
break;
case EShLangRayGen:
if (profile != EEsProfile && version >= 460) {
symbolTable.relateToOperator("fetchMicroTriangleVertexPositionNV", EOpFetchMicroTriangleVertexPositionNV);
symbolTable.relateToOperator("fetchMicroTriangleVertexBarycentricNV", EOpFetchMicroTriangleVertexBarycentricNV);
}
[[fallthrough]];
case EShLangClosestHit:
case EShLangMiss:
if (profile != EEsProfile && version >= 460) {
symbolTable.relateToOperator("traceNV", EOpTraceNV);
symbolTable.relateToOperator("traceRayMotionNV", EOpTraceRayMotionNV);
symbolTable.relateToOperator("traceRayEXT", EOpTraceKHR);
symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
symbolTable.relateToOperator("hitObjectTraceRayNV", EOpHitObjectTraceRayNV);
symbolTable.relateToOperator("hitObjectTraceRayMotionNV", EOpHitObjectTraceRayMotionNV);
symbolTable.relateToOperator("hitObjectRecordHitNV", EOpHitObjectRecordHitNV);
symbolTable.relateToOperator("hitObjectRecordHitMotionNV", EOpHitObjectRecordHitMotionNV);
symbolTable.relateToOperator("hitObjectRecordHitWithIndexNV", EOpHitObjectRecordHitWithIndexNV);
symbolTable.relateToOperator("hitObjectRecordHitWithIndexMotionNV", EOpHitObjectRecordHitWithIndexMotionNV);
symbolTable.relateToOperator("hitObjectRecordMissNV", EOpHitObjectRecordMissNV);
symbolTable.relateToOperator("hitObjectRecordMissMotionNV", EOpHitObjectRecordMissMotionNV);
symbolTable.relateToOperator("hitObjectRecordEmptyNV", EOpHitObjectRecordEmptyNV);
symbolTable.relateToOperator("hitObjectExecuteShaderNV", EOpHitObjectExecuteShaderNV);
symbolTable.relateToOperator("hitObjectIsEmptyNV", EOpHitObjectIsEmptyNV);
symbolTable.relateToOperator("hitObjectIsMissNV", EOpHitObjectIsMissNV);
symbolTable.relateToOperator("hitObjectIsHitNV", EOpHitObjectIsHitNV);
symbolTable.relateToOperator("hitObjectGetRayTMinNV", EOpHitObjectGetRayTMinNV);
symbolTable.relateToOperator("hitObjectGetRayTMaxNV", EOpHitObjectGetRayTMaxNV);
symbolTable.relateToOperator("hitObjectGetObjectRayOriginNV", EOpHitObjectGetObjectRayOriginNV);
symbolTable.relateToOperator("hitObjectGetObjectRayDirectionNV", EOpHitObjectGetObjectRayDirectionNV);
symbolTable.relateToOperator("hitObjectGetWorldRayOriginNV", EOpHitObjectGetWorldRayOriginNV);
symbolTable.relateToOperator("hitObjectGetWorldRayDirectionNV", EOpHitObjectGetWorldRayDirectionNV);
symbolTable.relateToOperator("hitObjectGetWorldToObjectNV", EOpHitObjectGetWorldToObjectNV);
symbolTable.relateToOperator("hitObjectGetObjectToWorldNV", EOpHitObjectGetObjectToWorldNV);
symbolTable.relateToOperator("hitObjectGetInstanceCustomIndexNV", EOpHitObjectGetInstanceCustomIndexNV);
symbolTable.relateToOperator("hitObjectGetInstanceIdNV", EOpHitObjectGetInstanceIdNV);
symbolTable.relateToOperator("hitObjectGetGeometryIndexNV", EOpHitObjectGetGeometryIndexNV);
symbolTable.relateToOperator("hitObjectGetPrimitiveIndexNV", EOpHitObjectGetPrimitiveIndexNV);
symbolTable.relateToOperator("hitObjectGetHitKindNV", EOpHitObjectGetHitKindNV);
symbolTable.relateToOperator("hitObjectGetAttributesNV", EOpHitObjectGetAttributesNV);
symbolTable.relateToOperator("hitObjectGetCurrentTimeNV", EOpHitObjectGetCurrentTimeNV);
symbolTable.relateToOperator("hitObjectGetShaderBindingTableRecordIndexNV", EOpHitObjectGetShaderBindingTableRecordIndexNV);
symbolTable.relateToOperator("hitObjectGetShaderRecordBufferHandleNV", EOpHitObjectGetShaderRecordBufferHandleNV);
symbolTable.relateToOperator("reorderThreadNV", EOpReorderThreadNV);
}
break;
case EShLangIntersect:
if (profile != EEsProfile && version >= 460) {
symbolTable.relateToOperator("reportIntersectionNV", EOpReportIntersection);
symbolTable.relateToOperator("reportIntersectionEXT", EOpReportIntersection);
}
break;
case EShLangAnyHit:
if (profile != EEsProfile && version >= 460) {
symbolTable.relateToOperator("ignoreIntersectionNV", EOpIgnoreIntersectionNV);
symbolTable.relateToOperator("terminateRayNV", EOpTerminateRayNV);
}
break;
case EShLangCallable:
if (profile != EEsProfile && version >= 460) {
symbolTable.relateToOperator("executeCallableNV", EOpExecuteCallableNV);
symbolTable.relateToOperator("executeCallableEXT", EOpExecuteCallableKHR);
}
break;
case EShLangMesh:
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
symbolTable.relateToOperator("writePackedPrimitiveIndices4x8NV", EOpWritePackedPrimitiveIndices4x8NV);
symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared);
symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier);
symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
}
if (profile != EEsProfile && version >= 450) {
symbolTable.relateToOperator("SetMeshOutputsEXT", EOpSetMeshOutputsEXT);
}
if (profile != EEsProfile && version >= 460) {
// Builtins for GL_NV_displacement_micromap.
symbolTable.relateToOperator("fetchMicroTriangleVertexPositionNV", EOpFetchMicroTriangleVertexPositionNV);
symbolTable.relateToOperator("fetchMicroTriangleVertexBarycentricNV", EOpFetchMicroTriangleVertexBarycentricNV);
}
break;
case EShLangTask:
if ((profile != EEsProfile && version >= 450) || (profile == EEsProfile && version >= 320)) {
symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared);
symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier);
symbolTable.relateToOperator("subgroupMemoryBarrierShared", EOpSubgroupMemoryBarrierShared);
}
if (profile != EEsProfile && version >= 450) {
symbolTable.relateToOperator("EmitMeshTasksEXT", EOpEmitMeshTasksEXT);
}
break;
default:
assert(false && "Language not supported");
}
}
//
// Add context-dependent (resource-specific) built-ins not handled by the above. These
// would be ones that need to be programmatically added because they cannot
// be added by simple text strings. For these, also
// 1) Map built-in functions to operators, for those that will turn into an operation node
// instead of remaining a function call.
// 2) Tag extension-related symbols added to their base version with their extensions, so
// that if an early version has the extension turned off, there is an error reported on use.
//
void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources)
{
if (profile != EEsProfile && version >= 430 && version < 440) {
symbolTable.setVariableExtensions("gl_MaxTransformFeedbackBuffers", 1, &E_GL_ARB_enhanced_layouts);
symbolTable.setVariableExtensions("gl_MaxTransformFeedbackInterleavedComponents", 1, &E_GL_ARB_enhanced_layouts);
}
if (profile != EEsProfile && version >= 130 && version < 420) {
symbolTable.setVariableExtensions("gl_MinProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
symbolTable.setVariableExtensions("gl_MaxProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack);
}
if (profile != EEsProfile && version >= 150 && version < 410)
symbolTable.setVariableExtensions("gl_MaxViewports", 1, &E_GL_ARB_viewport_array);
switch(language) {
case EShLangFragment:
// Set up gl_FragData based on current array size.
if (version == 100 || IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && profile != EEsProfile && version < 420)) {
TPrecisionQualifier pq = profile == EEsProfile ? EpqMedium : EpqNone;
TType fragData(EbtFloat, EvqFragColor, pq, 4);
TArraySizes* arraySizes = new TArraySizes;
arraySizes->addInnerSize(resources.maxDrawBuffers);
fragData.transferArraySizes(arraySizes);
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));
SpecialQualifier("gl_FragData", EvqFragColor, EbvFragData, symbolTable);
}
// GL_EXT_blend_func_extended
if (profile == EEsProfile && version >= 100) {
symbolTable.setVariableExtensions("gl_MaxDualSourceDrawBuffersEXT", 1, &E_GL_EXT_blend_func_extended);
symbolTable.setVariableExtensions("gl_SecondaryFragColorEXT", 1, &E_GL_EXT_blend_func_extended);
symbolTable.setVariableExtensions("gl_SecondaryFragDataEXT", 1, &E_GL_EXT_blend_func_extended);
SpecialQualifier("gl_SecondaryFragColorEXT", EvqVaryingOut, EbvSecondaryFragColorEXT, symbolTable);
SpecialQualifier("gl_SecondaryFragDataEXT", EvqVaryingOut, EbvSecondaryFragDataEXT, symbolTable);
}
break;
case EShLangTessControl:
case EShLangTessEvaluation:
// Because of the context-dependent array size (gl_MaxPatchVertices),
// these variables were added later than the others and need to be mapped now.
// standard members
BuiltInVariable("gl_in", "gl_Position", EbvPosition, symbolTable);
BuiltInVariable("gl_in", "gl_PointSize", EbvPointSize, symbolTable);
BuiltInVariable("gl_in", "gl_ClipDistance", EbvClipDistance, symbolTable);
BuiltInVariable("gl_in", "gl_CullDistance", EbvCullDistance, symbolTable);
// compatibility members
BuiltInVariable("gl_in", "gl_ClipVertex", EbvClipVertex, symbolTable);
BuiltInVariable("gl_in", "gl_FrontColor", EbvFrontColor, symbolTable);
BuiltInVariable("gl_in", "gl_BackColor", EbvBackColor, symbolTable);
BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable);
BuiltInVariable("gl_in", "gl_BackSecondaryColor", EbvBackSecondaryColor, symbolTable);
BuiltInVariable("gl_in", "gl_TexCoord", EbvTexCoord, symbolTable);
BuiltInVariable("gl_in", "gl_FogFragCoord", EbvFogFragCoord, symbolTable);
symbolTable.setVariableExtensions("gl_in", "gl_SecondaryPositionNV", 1, &E_GL_NV_stereo_view_rendering);
symbolTable.setVariableExtensions("gl_in", "gl_PositionPerViewNV", 1, &E_GL_NVX_multiview_per_view_attributes);
BuiltInVariable("gl_in", "gl_SecondaryPositionNV", EbvSecondaryPositionNV, symbolTable);
BuiltInVariable("gl_in", "gl_PositionPerViewNV", EbvPositionPerViewNV, symbolTable);
// extension requirements
if (profile == EEsProfile) {
symbolTable.setVariableExtensions("gl_in", "gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size);
}
break;
default:
break;
}
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/Constant.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
// Copyright (C) 2017 ARM Limited.
// Copyright (C) 2018-2020 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "localintermediate.h"
#include <cmath>
#include <cfloat>
#include <cstdlib>
#include <climits>
namespace {
using namespace glslang;
const double pi = 3.1415926535897932384626433832795;
} // end anonymous namespace
namespace glslang {
//
// The fold functions see if an operation on a constant can be done in place,
// without generating run-time code.
//
// Returns the node to keep using, which may or may not be the node passed in.
//
// Note: As of version 1.2, all constant operations must be folded. It is
// not opportunistic, but rather a semantic requirement.
//
//
// Do folding between a pair of nodes.
// 'this' is the left-hand operand and 'rightConstantNode' is the right-hand operand.
//
// Returns a new node representing the result.
//
TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* rightConstantNode) const
{
// For most cases, the return type matches the argument type, so set that
// up and just code to exceptions below.
TType returnType;
returnType.shallowCopy(getType());
//
// A pair of nodes is to be folded together
//
const TIntermConstantUnion *rightNode = rightConstantNode->getAsConstantUnion();
TConstUnionArray leftUnionArray = getConstArray();
TConstUnionArray rightUnionArray = rightNode->getConstArray();
// Figure out the size of the result
int newComps;
int constComps;
switch(op) {
case EOpMatrixTimesMatrix:
newComps = rightNode->getMatrixCols() * getMatrixRows();
break;
case EOpMatrixTimesVector:
newComps = getMatrixRows();
break;
case EOpVectorTimesMatrix:
newComps = rightNode->getMatrixCols();
break;
default:
newComps = getType().computeNumComponents();
constComps = rightConstantNode->getType().computeNumComponents();
if (constComps == 1 && newComps > 1) {
// for a case like vec4 f = vec4(2,3,4,5) + 1.2;
TConstUnionArray smearedArray(newComps, rightNode->getConstArray()[0]);
rightUnionArray = smearedArray;
} else if (constComps > 1 && newComps == 1) {
// for a case like vec4 f = 1.2 + vec4(2,3,4,5);
newComps = constComps;
rightUnionArray = rightNode->getConstArray();
TConstUnionArray smearedArray(newComps, getConstArray()[0]);
leftUnionArray = smearedArray;
returnType.shallowCopy(rightNode->getType());
}
break;
}
TConstUnionArray newConstArray(newComps);
TType constBool(EbtBool, EvqConst);
switch(op) {
case EOpAdd:
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] + rightUnionArray[i];
break;
case EOpSub:
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] - rightUnionArray[i];
break;
case EOpMul:
case EOpVectorTimesScalar:
case EOpMatrixTimesScalar:
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] * rightUnionArray[i];
break;
case EOpMatrixTimesMatrix:
for (int row = 0; row < getMatrixRows(); row++) {
for (int column = 0; column < rightNode->getMatrixCols(); column++) {
double sum = 0.0f;
for (int i = 0; i < rightNode->getMatrixRows(); i++)
sum += leftUnionArray[i * getMatrixRows() + row].getDConst() * rightUnionArray[column * rightNode->getMatrixRows() + i].getDConst();
newConstArray[column * getMatrixRows() + row].setDConst(sum);
}
}
returnType.shallowCopy(TType(getType().getBasicType(), EvqConst, 0, rightNode->getMatrixCols(), getMatrixRows()));
break;
case EOpDiv:
for (int i = 0; i < newComps; i++) {
switch (getType().getBasicType()) {
case EbtDouble:
case EbtFloat:
case EbtFloat16:
if (rightUnionArray[i].getDConst() != 0.0)
newConstArray[i].setDConst(leftUnionArray[i].getDConst() / rightUnionArray[i].getDConst());
else if (leftUnionArray[i].getDConst() > 0.0)
newConstArray[i].setDConst((double)INFINITY);
else if (leftUnionArray[i].getDConst() < 0.0)
newConstArray[i].setDConst(-(double)INFINITY);
else
newConstArray[i].setDConst((double)NAN);
break;
case EbtInt:
if (rightUnionArray[i] == 0)
newConstArray[i].setIConst(0x7FFFFFFF);
else if (rightUnionArray[i].getIConst() == -1 && leftUnionArray[i].getIConst() == (int)-0x80000000ll)
newConstArray[i].setIConst((int)-0x80000000ll);
else
newConstArray[i].setIConst(leftUnionArray[i].getIConst() / rightUnionArray[i].getIConst());
break;
case EbtUint:
if (rightUnionArray[i] == 0u)
newConstArray[i].setUConst(0xFFFFFFFFu);
else
newConstArray[i].setUConst(leftUnionArray[i].getUConst() / rightUnionArray[i].getUConst());
break;
case EbtInt8:
if (rightUnionArray[i] == (signed char)0)
newConstArray[i].setI8Const((signed char)0x7F);
else if (rightUnionArray[i].getI8Const() == (signed char)-1 && leftUnionArray[i].getI8Const() == (signed char)-0x80)
newConstArray[i].setI8Const((signed char)-0x80);
else
newConstArray[i].setI8Const(leftUnionArray[i].getI8Const() / rightUnionArray[i].getI8Const());
break;
case EbtUint8:
if (rightUnionArray[i] == (unsigned char)0u)
newConstArray[i].setU8Const((unsigned char)0xFFu);
else
newConstArray[i].setU8Const(leftUnionArray[i].getU8Const() / rightUnionArray[i].getU8Const());
break;
case EbtInt16:
if (rightUnionArray[i] == (signed short)0)
newConstArray[i].setI16Const((signed short)0x7FFF);
else if (rightUnionArray[i].getI16Const() == (signed short)-1 && leftUnionArray[i].getI16Const() == (signed short)-0x8000)
newConstArray[i].setI16Const((signed short)-0x8000);
else
newConstArray[i].setI16Const(leftUnionArray[i].getI16Const() / rightUnionArray[i].getI16Const());
break;
case EbtUint16:
if (rightUnionArray[i] == (unsigned short)0u)
newConstArray[i].setU16Const((unsigned short)0xFFFFu);
else
newConstArray[i].setU16Const(leftUnionArray[i].getU16Const() / rightUnionArray[i].getU16Const());
break;
case EbtInt64:
if (rightUnionArray[i] == 0ll)
newConstArray[i].setI64Const(LLONG_MAX);
else if (rightUnionArray[i].getI64Const() == -1 && leftUnionArray[i].getI64Const() == LLONG_MIN)
newConstArray[i].setI64Const(LLONG_MIN);
else
newConstArray[i].setI64Const(leftUnionArray[i].getI64Const() / rightUnionArray[i].getI64Const());
break;
case EbtUint64:
if (rightUnionArray[i] == 0ull)
newConstArray[i].setU64Const(0xFFFFFFFFFFFFFFFFull);
else
newConstArray[i].setU64Const(leftUnionArray[i].getU64Const() / rightUnionArray[i].getU64Const());
break;
default:
return nullptr;
}
}
break;
case EOpMatrixTimesVector:
for (int i = 0; i < getMatrixRows(); i++) {
double sum = 0.0f;
for (int j = 0; j < rightNode->getVectorSize(); j++) {
sum += leftUnionArray[j*getMatrixRows() + i].getDConst() * rightUnionArray[j].getDConst();
}
newConstArray[i].setDConst(sum);
}
returnType.shallowCopy(TType(getBasicType(), EvqConst, getMatrixRows()));
break;
case EOpVectorTimesMatrix:
for (int i = 0; i < rightNode->getMatrixCols(); i++) {
double sum = 0.0f;
for (int j = 0; j < getVectorSize(); j++)
sum += leftUnionArray[j].getDConst() * rightUnionArray[i*rightNode->getMatrixRows() + j].getDConst();
newConstArray[i].setDConst(sum);
}
returnType.shallowCopy(TType(getBasicType(), EvqConst, rightNode->getMatrixCols()));
break;
case EOpMod:
for (int i = 0; i < newComps; i++) {
if (rightUnionArray[i] == 0)
newConstArray[i] = leftUnionArray[i];
else {
switch (getType().getBasicType()) {
case EbtInt:
if (rightUnionArray[i].getIConst() == -1 && leftUnionArray[i].getIConst() == INT_MIN) {
newConstArray[i].setIConst(0);
break;
} else goto modulo_default;
case EbtInt64:
if (rightUnionArray[i].getI64Const() == -1 && leftUnionArray[i].getI64Const() == LLONG_MIN) {
newConstArray[i].setI64Const(0);
break;
} else goto modulo_default;
case EbtInt16:
if (rightUnionArray[i].getIConst() == -1 && leftUnionArray[i].getIConst() == SHRT_MIN) {
newConstArray[i].setIConst(0);
break;
} else goto modulo_default;
default:
modulo_default:
newConstArray[i] = leftUnionArray[i] % rightUnionArray[i];
}
}
}
break;
case EOpRightShift:
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] >> rightUnionArray[i];
break;
case EOpLeftShift:
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] << rightUnionArray[i];
break;
case EOpAnd:
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] & rightUnionArray[i];
break;
case EOpInclusiveOr:
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] | rightUnionArray[i];
break;
case EOpExclusiveOr:
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] ^ rightUnionArray[i];
break;
case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] && rightUnionArray[i];
break;
case EOpLogicalOr: // this code is written for possible future use, will not get executed currently
for (int i = 0; i < newComps; i++)
newConstArray[i] = leftUnionArray[i] || rightUnionArray[i];
break;
case EOpLogicalXor:
for (int i = 0; i < newComps; i++) {
switch (getType().getBasicType()) {
case EbtBool: newConstArray[i].setBConst((leftUnionArray[i] == rightUnionArray[i]) ? false : true); break;
default: assert(false && "Default missing");
}
}
break;
case EOpLessThan:
newConstArray[0].setBConst(leftUnionArray[0] < rightUnionArray[0]);
returnType.shallowCopy(constBool);
break;
case EOpGreaterThan:
newConstArray[0].setBConst(leftUnionArray[0] > rightUnionArray[0]);
returnType.shallowCopy(constBool);
break;
case EOpLessThanEqual:
newConstArray[0].setBConst(! (leftUnionArray[0] > rightUnionArray[0]));
returnType.shallowCopy(constBool);
break;
case EOpGreaterThanEqual:
newConstArray[0].setBConst(! (leftUnionArray[0] < rightUnionArray[0]));
returnType.shallowCopy(constBool);
break;
case EOpEqual:
newConstArray[0].setBConst(rightNode->getConstArray() == leftUnionArray);
returnType.shallowCopy(constBool);
break;
case EOpNotEqual:
newConstArray[0].setBConst(rightNode->getConstArray() != leftUnionArray);
returnType.shallowCopy(constBool);
break;
default:
return nullptr;
}
TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, returnType);
newNode->setLoc(getLoc());
return newNode;
}
//
// Do single unary node folding
//
// Returns a new node representing the result.
//
TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType) const
{
// First, size the result, which is mostly the same as the argument's size,
// but not always, and classify what is componentwise.
// Also, eliminate cases that can't be compile-time constant.
int resultSize;
bool componentWise = true;
int objectSize = getType().computeNumComponents();
switch (op) {
case EOpDeterminant:
case EOpAny:
case EOpAll:
case EOpLength:
componentWise = false;
resultSize = 1;
break;
case EOpEmitStreamVertex:
case EOpEndStreamPrimitive:
// These don't fold
return nullptr;
case EOpPackSnorm2x16:
case EOpPackUnorm2x16:
case EOpPackHalf2x16:
componentWise = false;
resultSize = 1;
break;
case EOpUnpackSnorm2x16:
case EOpUnpackUnorm2x16:
case EOpUnpackHalf2x16:
componentWise = false;
resultSize = 2;
break;
case EOpPack16:
case EOpPack32:
case EOpPack64:
case EOpUnpack32:
case EOpUnpack16:
case EOpUnpack8:
case EOpNormalize:
componentWise = false;
resultSize = objectSize;
break;
default:
resultSize = objectSize;
break;
}
// Set up for processing
TConstUnionArray newConstArray(resultSize);
const TConstUnionArray& unionArray = getConstArray();
// Process non-component-wise operations
switch (op) {
case EOpLength:
case EOpNormalize:
{
double sum = 0;
for (int i = 0; i < objectSize; i++)
sum += unionArray[i].getDConst() * unionArray[i].getDConst();
double length = sqrt(sum);
if (op == EOpLength)
newConstArray[0].setDConst(length);
else {
for (int i = 0; i < objectSize; i++)
newConstArray[i].setDConst(unionArray[i].getDConst() / length);
}
break;
}
case EOpAny:
{
bool result = false;
for (int i = 0; i < objectSize; i++) {
if (unionArray[i].getBConst())
result = true;
}
newConstArray[0].setBConst(result);
break;
}
case EOpAll:
{
bool result = true;
for (int i = 0; i < objectSize; i++) {
if (! unionArray[i].getBConst())
result = false;
}
newConstArray[0].setBConst(result);
break;
}
case EOpPackSnorm2x16:
case EOpPackUnorm2x16:
case EOpPackHalf2x16:
case EOpPack16:
case EOpPack32:
case EOpPack64:
case EOpUnpack32:
case EOpUnpack16:
case EOpUnpack8:
case EOpUnpackSnorm2x16:
case EOpUnpackUnorm2x16:
case EOpUnpackHalf2x16:
case EOpDeterminant:
case EOpMatrixInverse:
case EOpTranspose:
return nullptr;
default:
assert(componentWise);
break;
}
// Turn off the componentwise loop
if (! componentWise)
objectSize = 0;
// Process component-wise operations
for (int i = 0; i < objectSize; i++) {
switch (op) {
case EOpNegative:
switch (getType().getBasicType()) {
case EbtDouble:
case EbtFloat16:
case EbtFloat: newConstArray[i].setDConst(-unionArray[i].getDConst()); break;
// Note: avoid UBSAN error regarding negating 0x80000000
case EbtInt: newConstArray[i].setIConst(
static_cast<unsigned int>(unionArray[i].getIConst()) == 0x80000000
? -0x7FFFFFFF - 1
: -unionArray[i].getIConst());
break;
case EbtUint: newConstArray[i].setUConst(static_cast<unsigned int>(-static_cast<int>(unionArray[i].getUConst()))); break;
case EbtInt8: newConstArray[i].setI8Const(-unionArray[i].getI8Const()); break;
case EbtUint8: newConstArray[i].setU8Const(static_cast<unsigned int>(-static_cast<signed int>(unionArray[i].getU8Const()))); break;
case EbtInt16: newConstArray[i].setI16Const(-unionArray[i].getI16Const()); break;
case EbtUint16:newConstArray[i].setU16Const(static_cast<unsigned int>(-static_cast<signed int>(unionArray[i].getU16Const()))); break;
case EbtInt64: newConstArray[i].setI64Const(-unionArray[i].getI64Const()); break;
case EbtUint64: newConstArray[i].setU64Const(static_cast<unsigned long long>(-static_cast<long long>(unionArray[i].getU64Const()))); break;
default:
return nullptr;
}
break;
case EOpLogicalNot:
case EOpVectorLogicalNot:
switch (getType().getBasicType()) {
case EbtBool: newConstArray[i].setBConst(!unionArray[i].getBConst()); break;
default:
return nullptr;
}
break;
case EOpBitwiseNot:
newConstArray[i] = ~unionArray[i];
break;
case EOpRadians:
newConstArray[i].setDConst(unionArray[i].getDConst() * pi / 180.0);
break;
case EOpDegrees:
newConstArray[i].setDConst(unionArray[i].getDConst() * 180.0 / pi);
break;
case EOpSin:
newConstArray[i].setDConst(sin(unionArray[i].getDConst()));
break;
case EOpCos:
newConstArray[i].setDConst(cos(unionArray[i].getDConst()));
break;
case EOpTan:
newConstArray[i].setDConst(tan(unionArray[i].getDConst()));
break;
case EOpAsin:
newConstArray[i].setDConst(asin(unionArray[i].getDConst()));
break;
case EOpAcos:
newConstArray[i].setDConst(acos(unionArray[i].getDConst()));
break;
case EOpAtan:
newConstArray[i].setDConst(atan(unionArray[i].getDConst()));
break;
case EOpDPdx:
case EOpDPdy:
case EOpFwidth:
case EOpDPdxFine:
case EOpDPdyFine:
case EOpFwidthFine:
case EOpDPdxCoarse:
case EOpDPdyCoarse:
case EOpFwidthCoarse:
// The derivatives are all mandated to create a constant 0.
newConstArray[i].setDConst(0.0);
break;
case EOpExp:
newConstArray[i].setDConst(exp(unionArray[i].getDConst()));
break;
case EOpLog:
newConstArray[i].setDConst(log(unionArray[i].getDConst()));
break;
case EOpExp2:
newConstArray[i].setDConst(exp2(unionArray[i].getDConst()));
break;
case EOpLog2:
newConstArray[i].setDConst(log2(unionArray[i].getDConst()));
break;
case EOpSqrt:
newConstArray[i].setDConst(sqrt(unionArray[i].getDConst()));
break;
case EOpInverseSqrt:
newConstArray[i].setDConst(1.0 / sqrt(unionArray[i].getDConst()));
break;
case EOpAbs:
if (unionArray[i].getType() == EbtDouble)
newConstArray[i].setDConst(fabs(unionArray[i].getDConst()));
else if (unionArray[i].getType() == EbtInt)
newConstArray[i].setIConst(abs(unionArray[i].getIConst()));
else
newConstArray[i] = unionArray[i];
break;
case EOpSign:
#define SIGN(X) (X == 0 ? 0 : (X < 0 ? -1 : 1))
if (unionArray[i].getType() == EbtDouble)
newConstArray[i].setDConst(SIGN(unionArray[i].getDConst()));
else
newConstArray[i].setIConst(SIGN(unionArray[i].getIConst()));
break;
case EOpFloor:
newConstArray[i].setDConst(floor(unionArray[i].getDConst()));
break;
case EOpTrunc:
if (unionArray[i].getDConst() > 0)
newConstArray[i].setDConst(floor(unionArray[i].getDConst()));
else
newConstArray[i].setDConst(ceil(unionArray[i].getDConst()));
break;
case EOpRound:
newConstArray[i].setDConst(floor(0.5 + unionArray[i].getDConst()));
break;
case EOpRoundEven:
{
double flr = floor(unionArray[i].getDConst());
bool even = flr / 2.0 == floor(flr / 2.0);
double rounded = even ? ceil(unionArray[i].getDConst() - 0.5) : floor(unionArray[i].getDConst() + 0.5);
newConstArray[i].setDConst(rounded);
break;
}
case EOpCeil:
newConstArray[i].setDConst(ceil(unionArray[i].getDConst()));
break;
case EOpFract:
{
double x = unionArray[i].getDConst();
newConstArray[i].setDConst(x - floor(x));
break;
}
case EOpIsNan:
{
newConstArray[i].setBConst(std::isnan(unionArray[i].getDConst()));
break;
}
case EOpIsInf:
{
newConstArray[i].setBConst(std::isinf(unionArray[i].getDConst()));
break;
}
case EOpConvIntToBool:
newConstArray[i].setBConst(unionArray[i].getIConst() != 0); break;
case EOpConvUintToBool:
newConstArray[i].setBConst(unionArray[i].getUConst() != 0); break;
case EOpConvBoolToInt:
newConstArray[i].setIConst(unionArray[i].getBConst()); break;
case EOpConvBoolToUint:
newConstArray[i].setUConst(unionArray[i].getBConst()); break;
case EOpConvIntToUint:
newConstArray[i].setUConst(unionArray[i].getIConst()); break;
case EOpConvUintToInt:
newConstArray[i].setIConst(unionArray[i].getUConst()); break;
case EOpConvFloatToBool:
case EOpConvDoubleToBool:
newConstArray[i].setBConst(unionArray[i].getDConst() != 0); break;
case EOpConvBoolToFloat:
case EOpConvBoolToDouble:
newConstArray[i].setDConst(unionArray[i].getBConst()); break;
case EOpConvIntToFloat:
case EOpConvIntToDouble:
newConstArray[i].setDConst(unionArray[i].getIConst()); break;
case EOpConvUintToFloat:
case EOpConvUintToDouble:
newConstArray[i].setDConst(unionArray[i].getUConst()); break;
case EOpConvDoubleToFloat:
case EOpConvFloatToDouble:
newConstArray[i].setDConst(unionArray[i].getDConst()); break;
case EOpConvFloatToUint:
case EOpConvDoubleToUint:
newConstArray[i].setUConst(static_cast<unsigned int>(unionArray[i].getDConst())); break;
case EOpConvFloatToInt:
case EOpConvDoubleToInt:
newConstArray[i].setIConst(static_cast<int>(unionArray[i].getDConst())); break;
case EOpConvInt8ToBool:
newConstArray[i].setBConst(unionArray[i].getI8Const() != 0); break;
case EOpConvUint8ToBool:
newConstArray[i].setBConst(unionArray[i].getU8Const() != 0); break;
case EOpConvInt16ToBool:
newConstArray[i].setBConst(unionArray[i].getI16Const() != 0); break;
case EOpConvUint16ToBool:
newConstArray[i].setBConst(unionArray[i].getU16Const() != 0); break;
case EOpConvInt64ToBool:
newConstArray[i].setBConst(unionArray[i].getI64Const() != 0); break;
case EOpConvUint64ToBool:
newConstArray[i].setBConst(unionArray[i].getU64Const() != 0); break;
case EOpConvFloat16ToBool:
newConstArray[i].setBConst(unionArray[i].getDConst() != 0); break;
case EOpConvBoolToInt8:
newConstArray[i].setI8Const(unionArray[i].getBConst()); break;
case EOpConvBoolToUint8:
newConstArray[i].setU8Const(unionArray[i].getBConst()); break;
case EOpConvBoolToInt16:
newConstArray[i].setI16Const(unionArray[i].getBConst()); break;
case EOpConvBoolToUint16:
newConstArray[i].setU16Const(unionArray[i].getBConst()); break;
case EOpConvBoolToInt64:
newConstArray[i].setI64Const(unionArray[i].getBConst()); break;
case EOpConvBoolToUint64:
newConstArray[i].setU64Const(unionArray[i].getBConst()); break;
case EOpConvBoolToFloat16:
newConstArray[i].setDConst(unionArray[i].getBConst()); break;
case EOpConvInt8ToInt16:
newConstArray[i].setI16Const(unionArray[i].getI8Const()); break;
case EOpConvInt8ToInt:
newConstArray[i].setIConst(unionArray[i].getI8Const()); break;
case EOpConvInt8ToInt64:
newConstArray[i].setI64Const(unionArray[i].getI8Const()); break;
case EOpConvInt8ToUint8:
newConstArray[i].setU8Const(unionArray[i].getI8Const()); break;
case EOpConvInt8ToUint16:
newConstArray[i].setU16Const(unionArray[i].getI8Const()); break;
case EOpConvInt8ToUint:
newConstArray[i].setUConst(unionArray[i].getI8Const()); break;
case EOpConvInt8ToUint64:
newConstArray[i].setU64Const(unionArray[i].getI8Const()); break;
case EOpConvUint8ToInt8:
newConstArray[i].setI8Const(unionArray[i].getU8Const()); break;
case EOpConvUint8ToInt16:
newConstArray[i].setI16Const(unionArray[i].getU8Const()); break;
case EOpConvUint8ToInt:
newConstArray[i].setIConst(unionArray[i].getU8Const()); break;
case EOpConvUint8ToInt64:
newConstArray[i].setI64Const(unionArray[i].getU8Const()); break;
case EOpConvUint8ToUint16:
newConstArray[i].setU16Const(unionArray[i].getU8Const()); break;
case EOpConvUint8ToUint:
newConstArray[i].setUConst(unionArray[i].getU8Const()); break;
case EOpConvUint8ToUint64:
newConstArray[i].setU64Const(unionArray[i].getU8Const()); break;
case EOpConvInt8ToFloat16:
newConstArray[i].setDConst(unionArray[i].getI8Const()); break;
case EOpConvInt8ToFloat:
newConstArray[i].setDConst(unionArray[i].getI8Const()); break;
case EOpConvInt8ToDouble:
newConstArray[i].setDConst(unionArray[i].getI8Const()); break;
case EOpConvUint8ToFloat16:
newConstArray[i].setDConst(unionArray[i].getU8Const()); break;
case EOpConvUint8ToFloat:
newConstArray[i].setDConst(unionArray[i].getU8Const()); break;
case EOpConvUint8ToDouble:
newConstArray[i].setDConst(unionArray[i].getU8Const()); break;
case EOpConvInt16ToInt8:
newConstArray[i].setI8Const(static_cast<signed char>(unionArray[i].getI16Const())); break;
case EOpConvInt16ToInt:
newConstArray[i].setIConst(unionArray[i].getI16Const()); break;
case EOpConvInt16ToInt64:
newConstArray[i].setI64Const(unionArray[i].getI16Const()); break;
case EOpConvInt16ToUint8:
newConstArray[i].setU8Const(static_cast<unsigned char>(unionArray[i].getI16Const())); break;
case EOpConvInt16ToUint16:
newConstArray[i].setU16Const(unionArray[i].getI16Const()); break;
case EOpConvInt16ToUint:
newConstArray[i].setUConst(unionArray[i].getI16Const()); break;
case EOpConvInt16ToUint64:
newConstArray[i].setU64Const(unionArray[i].getI16Const()); break;
case EOpConvUint16ToInt8:
newConstArray[i].setI8Const(static_cast<signed char>(unionArray[i].getU16Const())); break;
case EOpConvUint16ToInt16:
newConstArray[i].setI16Const(unionArray[i].getU16Const()); break;
case EOpConvUint16ToInt:
newConstArray[i].setIConst(unionArray[i].getU16Const()); break;
case EOpConvUint16ToInt64:
newConstArray[i].setI64Const(unionArray[i].getU16Const()); break;
case EOpConvUint16ToUint8:
newConstArray[i].setU8Const(static_cast<unsigned char>(unionArray[i].getU16Const())); break;
case EOpConvUint16ToUint:
newConstArray[i].setUConst(unionArray[i].getU16Const()); break;
case EOpConvUint16ToUint64:
newConstArray[i].setU64Const(unionArray[i].getU16Const()); break;
case EOpConvInt16ToFloat16:
newConstArray[i].setDConst(unionArray[i].getI16Const()); break;
case EOpConvInt16ToFloat:
newConstArray[i].setDConst(unionArray[i].getI16Const()); break;
case EOpConvInt16ToDouble:
newConstArray[i].setDConst(unionArray[i].getI16Const()); break;
case EOpConvUint16ToFloat16:
newConstArray[i].setDConst(unionArray[i].getU16Const()); break;
case EOpConvUint16ToFloat:
newConstArray[i].setDConst(unionArray[i].getU16Const()); break;
case EOpConvUint16ToDouble:
newConstArray[i].setDConst(unionArray[i].getU16Const()); break;
case EOpConvIntToInt8:
newConstArray[i].setI8Const((signed char)unionArray[i].getIConst()); break;
case EOpConvIntToInt16:
newConstArray[i].setI16Const((signed short)unionArray[i].getIConst()); break;
case EOpConvIntToInt64:
newConstArray[i].setI64Const(unionArray[i].getIConst()); break;
case EOpConvIntToUint8:
newConstArray[i].setU8Const((unsigned char)unionArray[i].getIConst()); break;
case EOpConvIntToUint16:
newConstArray[i].setU16Const((unsigned char)unionArray[i].getIConst()); break;
case EOpConvIntToUint64:
newConstArray[i].setU64Const(unionArray[i].getIConst()); break;
case EOpConvUintToInt8:
newConstArray[i].setI8Const((signed char)unionArray[i].getUConst()); break;
case EOpConvUintToInt16:
newConstArray[i].setI16Const((signed short)unionArray[i].getUConst()); break;
case EOpConvUintToInt64:
newConstArray[i].setI64Const(unionArray[i].getUConst()); break;
case EOpConvUintToUint8:
newConstArray[i].setU8Const((unsigned char)unionArray[i].getUConst()); break;
case EOpConvUintToUint16:
newConstArray[i].setU16Const((unsigned short)unionArray[i].getUConst()); break;
case EOpConvUintToUint64:
newConstArray[i].setU64Const(unionArray[i].getUConst()); break;
case EOpConvIntToFloat16:
newConstArray[i].setDConst(unionArray[i].getIConst()); break;
case EOpConvUintToFloat16:
newConstArray[i].setDConst(unionArray[i].getUConst()); break;
case EOpConvInt64ToInt8:
newConstArray[i].setI8Const(static_cast<signed char>(unionArray[i].getI64Const())); break;
case EOpConvInt64ToInt16:
newConstArray[i].setI16Const(static_cast<signed short>(unionArray[i].getI64Const())); break;
case EOpConvInt64ToInt:
newConstArray[i].setIConst(static_cast<int>(unionArray[i].getI64Const())); break;
case EOpConvInt64ToUint8:
newConstArray[i].setU8Const(static_cast<unsigned char>(unionArray[i].getI64Const())); break;
case EOpConvInt64ToUint16:
newConstArray[i].setU16Const(static_cast<unsigned short>(unionArray[i].getI64Const())); break;
case EOpConvInt64ToUint:
newConstArray[i].setUConst(static_cast<unsigned int>(unionArray[i].getI64Const())); break;
case EOpConvInt64ToUint64:
newConstArray[i].setU64Const(unionArray[i].getI64Const()); break;
case EOpConvUint64ToInt8:
newConstArray[i].setI8Const(static_cast<signed char>(unionArray[i].getU64Const())); break;
case EOpConvUint64ToInt16:
newConstArray[i].setI16Const(static_cast<signed short>(unionArray[i].getU64Const())); break;
case EOpConvUint64ToInt:
newConstArray[i].setIConst(static_cast<int>(unionArray[i].getU64Const())); break;
case EOpConvUint64ToInt64:
newConstArray[i].setI64Const(unionArray[i].getU64Const()); break;
case EOpConvUint64ToUint8:
newConstArray[i].setU8Const(static_cast<unsigned char>(unionArray[i].getU64Const())); break;
case EOpConvUint64ToUint16:
newConstArray[i].setU16Const(static_cast<unsigned short>(unionArray[i].getU64Const())); break;
case EOpConvUint64ToUint:
newConstArray[i].setUConst(static_cast<unsigned int>(unionArray[i].getU64Const())); break;
case EOpConvInt64ToFloat16:
newConstArray[i].setDConst(static_cast<double>(unionArray[i].getI64Const())); break;
case EOpConvInt64ToFloat:
newConstArray[i].setDConst(static_cast<double>(unionArray[i].getI64Const())); break;
case EOpConvInt64ToDouble:
newConstArray[i].setDConst(static_cast<double>(unionArray[i].getI64Const())); break;
case EOpConvUint64ToFloat16:
newConstArray[i].setDConst(static_cast<double>(unionArray[i].getU64Const())); break;
case EOpConvUint64ToFloat:
newConstArray[i].setDConst(static_cast<double>(unionArray[i].getU64Const())); break;
case EOpConvUint64ToDouble:
newConstArray[i].setDConst(static_cast<double>(unionArray[i].getU64Const())); break;
case EOpConvFloat16ToInt8:
newConstArray[i].setI8Const(static_cast<signed char>(unionArray[i].getDConst())); break;
case EOpConvFloat16ToInt16:
newConstArray[i].setI16Const(static_cast<signed short>(unionArray[i].getDConst())); break;
case EOpConvFloat16ToInt:
newConstArray[i].setIConst(static_cast<int>(unionArray[i].getDConst())); break;
case EOpConvFloat16ToInt64:
newConstArray[i].setI64Const(static_cast<long long>(unionArray[i].getDConst())); break;
case EOpConvFloat16ToUint8:
newConstArray[i].setU8Const(static_cast<unsigned char>(unionArray[i].getDConst())); break;
case EOpConvFloat16ToUint16:
newConstArray[i].setU16Const(static_cast<unsigned short>(unionArray[i].getDConst())); break;
case EOpConvFloat16ToUint:
newConstArray[i].setUConst(static_cast<unsigned int>(unionArray[i].getDConst())); break;
case EOpConvFloat16ToUint64:
newConstArray[i].setU64Const(static_cast<unsigned long long>(unionArray[i].getDConst())); break;
case EOpConvFloat16ToFloat:
newConstArray[i].setDConst(unionArray[i].getDConst()); break;
case EOpConvFloat16ToDouble:
newConstArray[i].setDConst(unionArray[i].getDConst()); break;
case EOpConvFloatToInt8:
newConstArray[i].setI8Const(static_cast<signed char>(unionArray[i].getDConst())); break;
case EOpConvFloatToInt16:
newConstArray[i].setI16Const(static_cast<signed short>(unionArray[i].getDConst())); break;
case EOpConvFloatToInt64:
newConstArray[i].setI64Const(static_cast<long long>(unionArray[i].getDConst())); break;
case EOpConvFloatToUint8:
newConstArray[i].setU8Const(static_cast<unsigned char>(unionArray[i].getDConst())); break;
case EOpConvFloatToUint16:
newConstArray[i].setU16Const(static_cast<unsigned short>(unionArray[i].getDConst())); break;
case EOpConvFloatToUint64:
newConstArray[i].setU64Const(static_cast<unsigned long long>(unionArray[i].getDConst())); break;
case EOpConvFloatToFloat16:
newConstArray[i].setDConst(unionArray[i].getDConst()); break;
case EOpConvDoubleToInt8:
newConstArray[i].setI8Const(static_cast<signed char>(unionArray[i].getDConst())); break;
case EOpConvDoubleToInt16:
newConstArray[i].setI16Const(static_cast<signed short>(unionArray[i].getDConst())); break;
case EOpConvDoubleToInt64:
newConstArray[i].setI64Const(static_cast<long long>(unionArray[i].getDConst())); break;
case EOpConvDoubleToUint8:
newConstArray[i].setU8Const(static_cast<unsigned char>(unionArray[i].getDConst())); break;
case EOpConvDoubleToUint16:
newConstArray[i].setU16Const(static_cast<unsigned short>(unionArray[i].getDConst())); break;
case EOpConvDoubleToUint64:
newConstArray[i].setU64Const(static_cast<unsigned long long>(unionArray[i].getDConst())); break;
case EOpConvDoubleToFloat16:
newConstArray[i].setDConst(unionArray[i].getDConst()); break;
case EOpConvPtrToUint64:
case EOpConvUint64ToPtr:
case EOpConstructReference:
newConstArray[i].setU64Const(unionArray[i].getU64Const()); break;
// TODO: 3.0 Functionality: unary constant folding: the rest of the ops have to be fleshed out
case EOpSinh:
case EOpCosh:
case EOpTanh:
case EOpAsinh:
case EOpAcosh:
case EOpAtanh:
case EOpFloatBitsToInt:
case EOpFloatBitsToUint:
case EOpIntBitsToFloat:
case EOpUintBitsToFloat:
case EOpDoubleBitsToInt64:
case EOpDoubleBitsToUint64:
case EOpInt64BitsToDouble:
case EOpUint64BitsToDouble:
case EOpFloat16BitsToInt16:
case EOpFloat16BitsToUint16:
case EOpInt16BitsToFloat16:
case EOpUint16BitsToFloat16:
default:
return nullptr;
}
}
TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, returnType);
newNode->getWritableType().getQualifier().storage = EvqConst;
newNode->setLoc(getLoc());
return newNode;
}
//
// Do constant folding for an aggregate node that has all its children
// as constants and an operator that requires constant folding.
//
TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
{
if (aggrNode == nullptr)
return aggrNode;
if (! areAllChildConst(aggrNode))
return aggrNode;
if (aggrNode->isConstructor())
return foldConstructor(aggrNode);
TIntermSequence& children = aggrNode->getSequence();
// First, see if this is an operation to constant fold, kick out if not,
// see what size the result is if so.
bool componentwise = false; // will also say componentwise if a scalar argument gets repeated to make per-component results
int objectSize;
switch (aggrNode->getOp()) {
case EOpAtan:
case EOpPow:
case EOpMin:
case EOpMax:
case EOpMix:
case EOpMod:
case EOpClamp:
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
case EOpVectorEqual:
case EOpVectorNotEqual:
componentwise = true;
objectSize = children[0]->getAsConstantUnion()->getType().computeNumComponents();
break;
case EOpCross:
case EOpReflect:
case EOpRefract:
case EOpFaceForward:
objectSize = children[0]->getAsConstantUnion()->getType().computeNumComponents();
break;
case EOpDistance:
case EOpDot:
objectSize = 1;
break;
case EOpOuterProduct:
objectSize = children[0]->getAsTyped()->getType().getVectorSize() *
children[1]->getAsTyped()->getType().getVectorSize();
break;
case EOpStep:
componentwise = true;
objectSize = std::max(children[0]->getAsTyped()->getType().getVectorSize(),
children[1]->getAsTyped()->getType().getVectorSize());
break;
case EOpSmoothStep:
componentwise = true;
objectSize = std::max(children[0]->getAsTyped()->getType().getVectorSize(),
children[2]->getAsTyped()->getType().getVectorSize());
break;
default:
return aggrNode;
}
TConstUnionArray newConstArray(objectSize);
TVector<TConstUnionArray> childConstUnions;
for (unsigned int arg = 0; arg < children.size(); ++arg)
childConstUnions.push_back(children[arg]->getAsConstantUnion()->getConstArray());
if (componentwise) {
for (int comp = 0; comp < objectSize; comp++) {
// some arguments are scalars instead of matching vectors; simulate a smear
int arg0comp = std::min(comp, children[0]->getAsTyped()->getType().getVectorSize() - 1);
int arg1comp = 0;
if (children.size() > 1)
arg1comp = std::min(comp, children[1]->getAsTyped()->getType().getVectorSize() - 1);
int arg2comp = 0;
if (children.size() > 2)
arg2comp = std::min(comp, children[2]->getAsTyped()->getType().getVectorSize() - 1);
switch (aggrNode->getOp()) {
case EOpAtan:
newConstArray[comp].setDConst(atan2(childConstUnions[0][arg0comp].getDConst(), childConstUnions[1][arg1comp].getDConst()));
break;
case EOpPow:
newConstArray[comp].setDConst(pow(childConstUnions[0][arg0comp].getDConst(), childConstUnions[1][arg1comp].getDConst()));
break;
case EOpMod:
{
double arg0 = childConstUnions[0][arg0comp].getDConst();
double arg1 = childConstUnions[1][arg1comp].getDConst();
double result = arg0 - arg1 * floor(arg0 / arg1);
newConstArray[comp].setDConst(result);
break;
}
case EOpMin:
switch(children[0]->getAsTyped()->getBasicType()) {
case EbtFloat16:
case EbtFloat:
case EbtDouble:
newConstArray[comp].setDConst(std::min(childConstUnions[0][arg0comp].getDConst(), childConstUnions[1][arg1comp].getDConst()));
break;
case EbtInt:
newConstArray[comp].setIConst(std::min(childConstUnions[0][arg0comp].getIConst(), childConstUnions[1][arg1comp].getIConst()));
break;
case EbtUint:
newConstArray[comp].setUConst(std::min(childConstUnions[0][arg0comp].getUConst(), childConstUnions[1][arg1comp].getUConst()));
break;
case EbtInt8:
newConstArray[comp].setI8Const(std::min(childConstUnions[0][arg0comp].getI8Const(), childConstUnions[1][arg1comp].getI8Const()));
break;
case EbtUint8:
newConstArray[comp].setU8Const(std::min(childConstUnions[0][arg0comp].getU8Const(), childConstUnions[1][arg1comp].getU8Const()));
break;
case EbtInt16:
newConstArray[comp].setI16Const(std::min(childConstUnions[0][arg0comp].getI16Const(), childConstUnions[1][arg1comp].getI16Const()));
break;
case EbtUint16:
newConstArray[comp].setU16Const(std::min(childConstUnions[0][arg0comp].getU16Const(), childConstUnions[1][arg1comp].getU16Const()));
break;
case EbtInt64:
newConstArray[comp].setI64Const(std::min(childConstUnions[0][arg0comp].getI64Const(), childConstUnions[1][arg1comp].getI64Const()));
break;
case EbtUint64:
newConstArray[comp].setU64Const(std::min(childConstUnions[0][arg0comp].getU64Const(), childConstUnions[1][arg1comp].getU64Const()));
break;
default: assert(false && "Default missing");
}
break;
case EOpMax:
switch(children[0]->getAsTyped()->getBasicType()) {
case EbtFloat16:
case EbtFloat:
case EbtDouble:
newConstArray[comp].setDConst(std::max(childConstUnions[0][arg0comp].getDConst(), childConstUnions[1][arg1comp].getDConst()));
break;
case EbtInt:
newConstArray[comp].setIConst(std::max(childConstUnions[0][arg0comp].getIConst(), childConstUnions[1][arg1comp].getIConst()));
break;
case EbtUint:
newConstArray[comp].setUConst(std::max(childConstUnions[0][arg0comp].getUConst(), childConstUnions[1][arg1comp].getUConst()));
break;
case EbtInt8:
newConstArray[comp].setI8Const(std::max(childConstUnions[0][arg0comp].getI8Const(), childConstUnions[1][arg1comp].getI8Const()));
break;
case EbtUint8:
newConstArray[comp].setU8Const(std::max(childConstUnions[0][arg0comp].getU8Const(), childConstUnions[1][arg1comp].getU8Const()));
break;
case EbtInt16:
newConstArray[comp].setI16Const(std::max(childConstUnions[0][arg0comp].getI16Const(), childConstUnions[1][arg1comp].getI16Const()));
break;
case EbtUint16:
newConstArray[comp].setU16Const(std::max(childConstUnions[0][arg0comp].getU16Const(), childConstUnions[1][arg1comp].getU16Const()));
break;
case EbtInt64:
newConstArray[comp].setI64Const(std::max(childConstUnions[0][arg0comp].getI64Const(), childConstUnions[1][arg1comp].getI64Const()));
break;
case EbtUint64:
newConstArray[comp].setU64Const(std::max(childConstUnions[0][arg0comp].getU64Const(), childConstUnions[1][arg1comp].getU64Const()));
break;
default: assert(false && "Default missing");
}
break;
case EOpClamp:
switch(children[0]->getAsTyped()->getBasicType()) {
case EbtFloat16:
case EbtFloat:
case EbtDouble:
newConstArray[comp].setDConst(std::min(std::max(childConstUnions[0][arg0comp].getDConst(), childConstUnions[1][arg1comp].getDConst()),
childConstUnions[2][arg2comp].getDConst()));
break;
case EbtUint:
newConstArray[comp].setUConst(std::min(std::max(childConstUnions[0][arg0comp].getUConst(), childConstUnions[1][arg1comp].getUConst()),
childConstUnions[2][arg2comp].getUConst()));
break;
case EbtInt8:
newConstArray[comp].setI8Const(std::min(std::max(childConstUnions[0][arg0comp].getI8Const(), childConstUnions[1][arg1comp].getI8Const()),
childConstUnions[2][arg2comp].getI8Const()));
break;
case EbtUint8:
newConstArray[comp].setU8Const(std::min(std::max(childConstUnions[0][arg0comp].getU8Const(), childConstUnions[1][arg1comp].getU8Const()),
childConstUnions[2][arg2comp].getU8Const()));
break;
case EbtInt16:
newConstArray[comp].setI16Const(std::min(std::max(childConstUnions[0][arg0comp].getI16Const(), childConstUnions[1][arg1comp].getI16Const()),
childConstUnions[2][arg2comp].getI16Const()));
break;
case EbtUint16:
newConstArray[comp].setU16Const(std::min(std::max(childConstUnions[0][arg0comp].getU16Const(), childConstUnions[1][arg1comp].getU16Const()),
childConstUnions[2][arg2comp].getU16Const()));
break;
case EbtInt:
newConstArray[comp].setIConst(std::min(std::max(childConstUnions[0][arg0comp].getIConst(), childConstUnions[1][arg1comp].getIConst()),
childConstUnions[2][arg2comp].getIConst()));
break;
case EbtInt64:
newConstArray[comp].setI64Const(std::min(std::max(childConstUnions[0][arg0comp].getI64Const(), childConstUnions[1][arg1comp].getI64Const()),
childConstUnions[2][arg2comp].getI64Const()));
break;
case EbtUint64:
newConstArray[comp].setU64Const(std::min(std::max(childConstUnions[0][arg0comp].getU64Const(), childConstUnions[1][arg1comp].getU64Const()),
childConstUnions[2][arg2comp].getU64Const()));
break;
default: assert(false && "Default missing");
}
break;
case EOpLessThan:
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] < childConstUnions[1][arg1comp]);
break;
case EOpGreaterThan:
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] > childConstUnions[1][arg1comp]);
break;
case EOpLessThanEqual:
newConstArray[comp].setBConst(! (childConstUnions[0][arg0comp] > childConstUnions[1][arg1comp]));
break;
case EOpGreaterThanEqual:
newConstArray[comp].setBConst(! (childConstUnions[0][arg0comp] < childConstUnions[1][arg1comp]));
break;
case EOpVectorEqual:
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] == childConstUnions[1][arg1comp]);
break;
case EOpVectorNotEqual:
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] != childConstUnions[1][arg1comp]);
break;
case EOpMix:
if (!children[0]->getAsTyped()->isFloatingDomain())
return aggrNode;
if (children[2]->getAsTyped()->getBasicType() == EbtBool) {
newConstArray[comp].setDConst(childConstUnions[2][arg2comp].getBConst()
? childConstUnions[1][arg1comp].getDConst()
: childConstUnions[0][arg0comp].getDConst());
} else {
newConstArray[comp].setDConst(
childConstUnions[0][arg0comp].getDConst() * (1.0 - childConstUnions[2][arg2comp].getDConst()) +
childConstUnions[1][arg1comp].getDConst() * childConstUnions[2][arg2comp].getDConst());
}
break;
case EOpStep:
newConstArray[comp].setDConst(childConstUnions[1][arg1comp].getDConst() < childConstUnions[0][arg0comp].getDConst() ? 0.0 : 1.0);
break;
case EOpSmoothStep:
{
double t = (childConstUnions[2][arg2comp].getDConst() - childConstUnions[0][arg0comp].getDConst()) /
(childConstUnions[1][arg1comp].getDConst() - childConstUnions[0][arg0comp].getDConst());
if (t < 0.0)
t = 0.0;
if (t > 1.0)
t = 1.0;
newConstArray[comp].setDConst(t * t * (3.0 - 2.0 * t));
break;
}
default:
return aggrNode;
}
}
} else {
// Non-componentwise...
int numComps = children[0]->getAsConstantUnion()->getType().computeNumComponents();
double dot;
switch (aggrNode->getOp()) {
case EOpDistance:
{
double sum = 0.0;
for (int comp = 0; comp < numComps; ++comp) {
double diff = childConstUnions[1][comp].getDConst() - childConstUnions[0][comp].getDConst();
sum += diff * diff;
}
newConstArray[0].setDConst(sqrt(sum));
break;
}
case EOpDot:
newConstArray[0].setDConst(childConstUnions[0].dot(childConstUnions[1]));
break;
case EOpCross:
newConstArray[0] = childConstUnions[0][1] * childConstUnions[1][2] - childConstUnions[0][2] * childConstUnions[1][1];
newConstArray[1] = childConstUnions[0][2] * childConstUnions[1][0] - childConstUnions[0][0] * childConstUnions[1][2];
newConstArray[2] = childConstUnions[0][0] * childConstUnions[1][1] - childConstUnions[0][1] * childConstUnions[1][0];
break;
case EOpFaceForward:
// If dot(Nref, I) < 0 return N, otherwise return -N: Arguments are (N, I, Nref).
dot = childConstUnions[1].dot(childConstUnions[2]);
for (int comp = 0; comp < numComps; ++comp) {
if (dot < 0.0)
newConstArray[comp] = childConstUnions[0][comp];
else
newConstArray[comp].setDConst(-childConstUnions[0][comp].getDConst());
}
break;
case EOpReflect:
// I - 2 * dot(N, I) * N: Arguments are (I, N).
dot = childConstUnions[0].dot(childConstUnions[1]);
dot *= 2.0;
for (int comp = 0; comp < numComps; ++comp)
newConstArray[comp].setDConst(childConstUnions[0][comp].getDConst() - dot * childConstUnions[1][comp].getDConst());
break;
case EOpRefract:
{
// Arguments are (I, N, eta).
// k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
// if (k < 0.0)
// return dvec(0.0)
// else
// return eta * I - (eta * dot(N, I) + sqrt(k)) * N
dot = childConstUnions[0].dot(childConstUnions[1]);
double eta = childConstUnions[2][0].getDConst();
double k = 1.0 - eta * eta * (1.0 - dot * dot);
if (k < 0.0) {
for (int comp = 0; comp < numComps; ++comp)
newConstArray[comp].setDConst(0.0);
} else {
for (int comp = 0; comp < numComps; ++comp)
newConstArray[comp].setDConst(eta * childConstUnions[0][comp].getDConst() - (eta * dot + sqrt(k)) * childConstUnions[1][comp].getDConst());
}
break;
}
case EOpOuterProduct:
{
int numRows = numComps;
int numCols = children[1]->getAsConstantUnion()->getType().computeNumComponents();
for (int row = 0; row < numRows; ++row)
for (int col = 0; col < numCols; ++col)
newConstArray[col * numRows + row] = childConstUnions[0][row] * childConstUnions[1][col];
break;
}
default:
return aggrNode;
}
}
TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, aggrNode->getType());
newNode->getWritableType().getQualifier().storage = EvqConst;
newNode->setLoc(aggrNode->getLoc());
return newNode;
}
bool TIntermediate::areAllChildConst(TIntermAggregate* aggrNode)
{
bool allConstant = true;
// check if all the child nodes are constants so that they can be inserted into
// the parent node
if (aggrNode) {
TIntermSequence& childSequenceVector = aggrNode->getSequence();
for (TIntermSequence::iterator p = childSequenceVector.begin();
p != childSequenceVector.end(); p++) {
if (!(*p)->getAsTyped()->getAsConstantUnion())
return false;
}
}
return allConstant;
}
TIntermTyped* TIntermediate::foldConstructor(TIntermAggregate* aggrNode)
{
bool error = false;
TConstUnionArray unionArray(aggrNode->getType().computeNumComponents());
if (aggrNode->getSequence().size() == 1)
error = parseConstTree(aggrNode, unionArray, aggrNode->getOp(), aggrNode->getType(), true);
else
error = parseConstTree(aggrNode, unionArray, aggrNode->getOp(), aggrNode->getType());
if (error)
return aggrNode;
return addConstantUnion(unionArray, aggrNode->getType(), aggrNode->getLoc());
}
//
// Constant folding of a bracket (array-style) dereference or struct-like dot
// dereference. Can handle anything except a multi-character swizzle, though
// all swizzles may go to foldSwizzle().
//
TIntermTyped* TIntermediate::foldDereference(TIntermTyped* node, int index, const TSourceLoc& loc)
{
TType dereferencedType(node->getType(), index);
dereferencedType.getQualifier().storage = EvqConst;
TIntermTyped* result = nullptr;
int size = dereferencedType.computeNumComponents();
// arrays, vectors, matrices, all use simple multiplicative math
// while structures need to add up heterogeneous members
int start;
if (node->getType().isCoopMat())
start = 0;
else if (node->isArray() || ! node->isStruct())
start = size * index;
else {
// it is a structure
assert(node->isStruct());
start = 0;
for (int i = 0; i < index; ++i)
start += (*node->getType().getStruct())[i].type->computeNumComponents();
}
result = addConstantUnion(TConstUnionArray(node->getAsConstantUnion()->getConstArray(), start, size), node->getType(), loc);
if (result == nullptr)
result = node;
else
result->setType(dereferencedType);
return result;
}
//
// Make a constant vector node or constant scalar node, representing a given
// constant vector and constant swizzle into it.
//
TIntermTyped* TIntermediate::foldSwizzle(TIntermTyped* node, TSwizzleSelectors<TVectorSelector>& selectors, const TSourceLoc& loc)
{
const TConstUnionArray& unionArray = node->getAsConstantUnion()->getConstArray();
TConstUnionArray constArray(selectors.size());
for (int i = 0; i < selectors.size(); i++)
constArray[i] = unionArray[selectors[i]];
TIntermTyped* result = addConstantUnion(constArray, node->getType(), loc);
if (result == nullptr)
result = node;
else
result->setType(TType(node->getBasicType(), EvqConst, selectors.size()));
return result;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/LiveTraverser.h | //
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#pragma once
#include "../Include/Common.h"
#include "reflection.h"
#include "localintermediate.h"
#include "gl_types.h"
#include <list>
#include <unordered_set>
namespace glslang {
//
// The traverser: mostly pass through, except
// - processing function-call nodes to push live functions onto the stack of functions to process
// - processing selection nodes to trim semantically dead code
//
// This is in the glslang namespace directly so it can be a friend of TReflection.
// This can be derived from to implement reflection database traversers or
// binding mappers: anything that wants to traverse the live subset of the tree.
//
class TLiveTraverser : public TIntermTraverser {
public:
TLiveTraverser(const TIntermediate& i, bool traverseAll = false,
bool preVisit = true, bool inVisit = false, bool postVisit = false) :
TIntermTraverser(preVisit, inVisit, postVisit),
intermediate(i), traverseAll(traverseAll)
{ }
//
// Given a function name, find its subroot in the tree, and push it onto the stack of
// functions left to process.
//
void pushFunction(const TString& name)
{
TIntermSequence& globals = intermediate.getTreeRoot()->getAsAggregate()->getSequence();
for (unsigned int f = 0; f < globals.size(); ++f) {
TIntermAggregate* candidate = globals[f]->getAsAggregate();
if (candidate && candidate->getOp() == EOpFunction && candidate->getName() == name) {
destinations.push_back(candidate);
break;
}
}
}
void pushGlobalReference(const TString& name)
{
TIntermSequence& globals = intermediate.getTreeRoot()->getAsAggregate()->getSequence();
for (unsigned int f = 0; f < globals.size(); ++f) {
TIntermAggregate* candidate = globals[f]->getAsAggregate();
if (candidate && candidate->getOp() == EOpSequence &&
candidate->getSequence().size() == 1 &&
candidate->getSequence()[0]->getAsBinaryNode()) {
TIntermBinary* binary = candidate->getSequence()[0]->getAsBinaryNode();
TIntermSymbol* symbol = binary->getLeft()->getAsSymbolNode();
if (symbol && symbol->getQualifier().storage == EvqGlobal &&
symbol->getName() == name) {
destinations.push_back(candidate);
break;
}
}
}
}
typedef std::list<TIntermAggregate*> TDestinationStack;
TDestinationStack destinations;
protected:
// To catch which function calls are not dead, and hence which functions must be visited.
virtual bool visitAggregate(TVisit, TIntermAggregate* node)
{
if (!traverseAll)
if (node->getOp() == EOpFunctionCall)
addFunctionCall(node);
return true; // traverse this subtree
}
// To prune semantically dead paths.
virtual bool visitSelection(TVisit /* visit */, TIntermSelection* node)
{
if (traverseAll)
return true; // traverse all code
TIntermConstantUnion* constant = node->getCondition()->getAsConstantUnion();
if (constant) {
// cull the path that is dead
if (constant->getConstArray()[0].getBConst() == true && node->getTrueBlock())
node->getTrueBlock()->traverse(this);
if (constant->getConstArray()[0].getBConst() == false && node->getFalseBlock())
node->getFalseBlock()->traverse(this);
return false; // don't traverse any more, we did it all above
} else
return true; // traverse the whole subtree
}
// Track live functions as well as uniforms, so that we don't visit dead functions
// and only visit each function once.
void addFunctionCall(TIntermAggregate* call)
{
// just use the map to ensure we process each function at most once
if (liveFunctions.find(call->getName()) == liveFunctions.end()) {
liveFunctions.insert(call->getName());
pushFunction(call->getName());
}
}
void addGlobalReference(const TString& name)
{
// just use the map to ensure we process each global at most once
if (liveGlobals.find(name) == liveGlobals.end()) {
liveGlobals.insert(name);
pushGlobalReference(name);
}
}
const TIntermediate& intermediate;
typedef std::unordered_set<TString> TLiveFunctions;
TLiveFunctions liveFunctions;
typedef std::unordered_set<TString> TLiveGlobals;
TLiveGlobals liveGlobals;
bool traverseAll;
private:
// prevent copy & copy construct
TLiveTraverser(TLiveTraverser&);
TLiveTraverser& operator=(TLiveTraverser&);
};
} // namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/ParseContextBase.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Implement the TParseContextBase class.
#include <cstdarg>
#include "ParseHelper.h"
extern int yyparse(glslang::TParseContext*);
namespace glslang {
//
// Used to output syntax, parsing, and semantic errors.
//
void TParseContextBase::outputMessage(const TSourceLoc& loc, const char* szReason,
const char* szToken,
const char* szExtraInfoFormat,
TPrefixType prefix, va_list args)
{
const int maxSize = MaxTokenLength + 200;
char szExtraInfo[maxSize];
safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args);
infoSink.info.prefix(prefix);
infoSink.info.location(loc, messages & EShMsgAbsolutePath);
infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n";
if (prefix == EPrefixError) {
++numErrors;
}
}
void C_DECL TParseContextBase::error(const TSourceLoc& loc, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...)
{
if (messages & EShMsgOnlyPreprocessor)
return;
// If enhanced msg readability, only print one error
if (messages & EShMsgEnhanced && numErrors > 0)
return;
va_list args;
va_start(args, szExtraInfoFormat);
outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixError, args);
va_end(args);
if ((messages & EShMsgCascadingErrors) == 0)
currentScanner->setEndOfInput();
}
void C_DECL TParseContextBase::warn(const TSourceLoc& loc, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...)
{
if (suppressWarnings())
return;
va_list args;
va_start(args, szExtraInfoFormat);
outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixWarning, args);
va_end(args);
}
void C_DECL TParseContextBase::ppError(const TSourceLoc& loc, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...)
{
va_list args;
va_start(args, szExtraInfoFormat);
outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixError, args);
va_end(args);
if ((messages & EShMsgCascadingErrors) == 0)
currentScanner->setEndOfInput();
}
void C_DECL TParseContextBase::ppWarn(const TSourceLoc& loc, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...)
{
va_list args;
va_start(args, szExtraInfoFormat);
outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixWarning, args);
va_end(args);
}
//
// Both test and if necessary, spit out an error, to see if the node is really
// an l-value that can be operated on this way.
//
// Returns true if there was an error.
//
bool TParseContextBase::lValueErrorCheck(const TSourceLoc& loc, const char* op, TIntermTyped* node)
{
TIntermBinary* binaryNode = node->getAsBinaryNode();
const char* symbol = nullptr;
TIntermSymbol* symNode = node->getAsSymbolNode();
if (symNode != nullptr)
symbol = symNode->getName().c_str();
const char* message = nullptr;
switch (node->getQualifier().storage) {
case EvqConst: message = "can't modify a const"; break;
case EvqConstReadOnly: message = "can't modify a const"; break;
case EvqUniform: message = "can't modify a uniform"; break;
case EvqBuffer:
if (node->getQualifier().isReadOnly())
message = "can't modify a readonly buffer";
if (node->getQualifier().isShaderRecord())
message = "can't modify a shaderrecordnv qualified buffer";
break;
case EvqHitAttr:
if (language != EShLangIntersect)
message = "cannot modify hitAttributeNV in this stage";
break;
default:
//
// Type that can't be written to?
//
switch (node->getBasicType()) {
case EbtSampler:
if (extensionTurnedOn(E_GL_ARB_bindless_texture) == false)
message = "can't modify a sampler";
break;
case EbtVoid:
message = "can't modify void";
break;
case EbtAtomicUint:
message = "can't modify an atomic_uint";
break;
case EbtAccStruct:
message = "can't modify accelerationStructureNV";
break;
case EbtRayQuery:
message = "can't modify rayQueryEXT";
break;
case EbtHitObjectNV:
message = "can't modify hitObjectNV";
break;
default:
break;
}
}
if (message == nullptr && binaryNode == nullptr && symNode == nullptr) {
error(loc, " l-value required", op, "", "");
return true;
}
//
// Everything else is okay, no error.
//
if (message == nullptr)
{
if (binaryNode) {
switch (binaryNode->getOp()) {
case EOpIndexDirect:
case EOpIndexIndirect: // fall through
case EOpIndexDirectStruct: // fall through
case EOpVectorSwizzle:
case EOpMatrixSwizzle:
return lValueErrorCheck(loc, op, binaryNode->getLeft());
default:
break;
}
error(loc, " l-value required", op, "", "");
return true;
}
return false;
}
//
// If we get here, we have an error and a message.
//
const TIntermTyped* leftMostTypeNode = TIntermediate::traverseLValueBase(node, true);
if (symNode)
error(loc, " l-value required", op, "\"%s\" (%s)", symbol, message);
else
if (binaryNode && binaryNode->getAsOperator()->getOp() == EOpIndexDirectStruct)
if(IsAnonymous(leftMostTypeNode->getAsSymbolNode()->getName()))
error(loc, " l-value required", op, "\"%s\" (%s)", leftMostTypeNode->getAsSymbolNode()->getAccessName().c_str(), message);
else
error(loc, " l-value required", op, "\"%s\" (%s)", leftMostTypeNode->getAsSymbolNode()->getName().c_str(), message);
else
error(loc, " l-value required", op, "(%s)", message);
return true;
}
// Test for and give an error if the node can't be read from.
void TParseContextBase::rValueErrorCheck(const TSourceLoc& loc, const char* op, TIntermTyped* node)
{
if (! node)
return;
TIntermBinary* binaryNode = node->getAsBinaryNode();
const TIntermSymbol* symNode = node->getAsSymbolNode();
if (node->getQualifier().isWriteOnly()) {
const TIntermTyped* leftMostTypeNode = TIntermediate::traverseLValueBase(node, true);
if (symNode != nullptr)
error(loc, "can't read from writeonly object: ", op, symNode->getName().c_str());
else if (binaryNode &&
(binaryNode->getAsOperator()->getOp() == EOpIndexDirectStruct ||
binaryNode->getAsOperator()->getOp() == EOpIndexDirect))
if(IsAnonymous(leftMostTypeNode->getAsSymbolNode()->getName()))
error(loc, "can't read from writeonly object: ", op, leftMostTypeNode->getAsSymbolNode()->getAccessName().c_str());
else
error(loc, "can't read from writeonly object: ", op, leftMostTypeNode->getAsSymbolNode()->getName().c_str());
else
error(loc, "can't read from writeonly object: ", op, "");
} else {
if (binaryNode) {
switch (binaryNode->getOp()) {
case EOpIndexDirect:
case EOpIndexIndirect:
case EOpIndexDirectStruct:
case EOpVectorSwizzle:
case EOpMatrixSwizzle:
rValueErrorCheck(loc, op, binaryNode->getLeft());
break;
default:
break;
}
}
}
}
// Add 'symbol' to the list of deferred linkage symbols, which
// are later processed in finish(), at which point the symbol
// must still be valid.
// It is okay if the symbol's type will be subsequently edited;
// the modifications will be tracked.
// Order is preserved, to avoid creating novel forward references.
void TParseContextBase::trackLinkage(TSymbol& symbol)
{
if (!parsingBuiltins)
linkageSymbols.push_back(&symbol);
}
// Ensure index is in bounds, correct if necessary.
// Give an error if not.
void TParseContextBase::checkIndex(const TSourceLoc& loc, const TType& type, int& index)
{
const auto sizeIsSpecializationExpression = [&type]() {
return type.containsSpecializationSize() &&
type.getArraySizes()->getOuterNode() != nullptr &&
type.getArraySizes()->getOuterNode()->getAsSymbolNode() == nullptr; };
if (index < 0) {
error(loc, "", "[", "index out of range '%d'", index);
index = 0;
} else if (type.isArray()) {
if (type.isSizedArray() && !sizeIsSpecializationExpression() &&
index >= type.getOuterArraySize()) {
error(loc, "", "[", "array index out of range '%d'", index);
index = type.getOuterArraySize() - 1;
}
} else if (type.isVector()) {
if (index >= type.getVectorSize()) {
error(loc, "", "[", "vector index out of range '%d'", index);
index = type.getVectorSize() - 1;
}
} else if (type.isMatrix()) {
if (index >= type.getMatrixCols()) {
error(loc, "", "[", "matrix index out of range '%d'", index);
index = type.getMatrixCols() - 1;
}
}
}
// Make a shared symbol have a non-shared version that can be edited by the current
// compile, such that editing its type will not change the shared version and will
// effect all nodes already sharing it (non-shallow type),
// or adopting its full type after being edited (shallow type).
void TParseContextBase::makeEditable(TSymbol*& symbol)
{
// copyUp() does a deep copy of the type.
symbol = symbolTable.copyUp(symbol);
// Save it (deferred, so it can be edited first) in the AST for linker use.
if (symbol)
trackLinkage(*symbol);
}
// Return a writable version of the variable 'name'.
//
// Return nullptr if 'name' is not found. This should mean
// something is seriously wrong (e.g., compiler asking self for
// built-in that doesn't exist).
TVariable* TParseContextBase::getEditableVariable(const char* name)
{
bool builtIn;
TSymbol* symbol = symbolTable.find(name, &builtIn);
assert(symbol != nullptr);
if (symbol == nullptr)
return nullptr;
if (builtIn)
makeEditable(symbol);
return symbol->getAsVariable();
}
// Select the best matching function for 'call' from 'candidateList'.
//
// Assumptions
//
// There is no exact match, so a selection algorithm needs to run. That is, the
// language-specific handler should check for exact match first, to
// decide what to do, before calling this selector.
//
// Input
//
// * list of candidate signatures to select from
// * the call
// * a predicate function convertible(from, to) that says whether or not type
// 'from' can implicitly convert to type 'to' (it includes the case of what
// the calling language would consider a matching type with no conversion
// needed)
// * a predicate function better(from1, from2, to1, to2) that says whether or
// not a conversion from <-> to2 is considered better than a conversion
// from <-> to1 (both in and out directions need testing, as declared by the
// formal parameter)
//
// Output
//
// * best matching candidate (or none, if no viable candidates found)
// * whether there was a tie for the best match (ambiguous overload selection,
// caller's choice for how to report)
//
const TFunction* TParseContextBase::selectFunction(
const TVector<const TFunction*> candidateList,
const TFunction& call,
std::function<bool(const TType& from, const TType& to, TOperator op, int arg)> convertible,
std::function<bool(const TType& from, const TType& to1, const TType& to2)> better,
/* output */ bool& tie)
{
//
// Operation
//
// 1. Prune the input list of candidates down to a list of viable candidates,
// where each viable candidate has
//
// * at least as many parameters as there are calling arguments, with any
// remaining parameters being optional or having default values
// * each parameter is true under convertible(A, B), where A is the calling
// type for in and B is the formal type, and in addition, for out B is the
// calling type and A is the formal type
//
// 2. If there are no viable candidates, return with no match.
//
// 3. If there is only one viable candidate, it is the best match.
//
// 4. If there are multiple viable candidates, select the first viable candidate
// as the incumbent. Compare the incumbent to the next viable candidate, and if
// that candidate is better (bullets below), make it the incumbent. Repeat, with
// a linear walk through the viable candidate list. The final incumbent will be
// returned as the best match. A viable candidate is better than the incumbent if
//
// * it has a function argument with a better(...) conversion than the incumbent,
// for all directions needed by in and out
// * the incumbent has no argument with a better(...) conversion then the
// candidate, for either in or out (as needed)
//
// 5. Check for ambiguity by comparing the best match against all other viable
// candidates. If any other viable candidate has a function argument with a
// better(...) conversion than the best candidate (for either in or out
// directions), return that there was a tie for best.
//
tie = false;
// 1. prune to viable...
TVector<const TFunction*> viableCandidates;
for (auto it = candidateList.begin(); it != candidateList.end(); ++it) {
const TFunction& candidate = *(*it);
// to even be a potential match, number of arguments must be >= the number of
// fixed (non-default) parameters, and <= the total (including parameter with defaults).
if (call.getParamCount() < candidate.getFixedParamCount() ||
call.getParamCount() > candidate.getParamCount())
continue;
// see if arguments are convertible
bool viable = true;
// The call can have fewer parameters than the candidate, if some have defaults.
const int paramCount = std::min(call.getParamCount(), candidate.getParamCount());
for (int param = 0; param < paramCount; ++param) {
if (candidate[param].type->getQualifier().isParamInput()) {
if (! convertible(*call[param].type, *candidate[param].type, candidate.getBuiltInOp(), param)) {
viable = false;
break;
}
}
if (candidate[param].type->getQualifier().isParamOutput()) {
if (! convertible(*candidate[param].type, *call[param].type, candidate.getBuiltInOp(), param)) {
viable = false;
break;
}
}
}
if (viable)
viableCandidates.push_back(&candidate);
}
// 2. none viable...
if (viableCandidates.size() == 0)
return nullptr;
// 3. only one viable...
if (viableCandidates.size() == 1)
return viableCandidates.front();
// 4. find best...
const auto betterParam = [&call, &better](const TFunction& can1, const TFunction& can2) -> bool {
// is call -> can2 better than call -> can1 for any parameter
bool hasBetterParam = false;
for (int param = 0; param < call.getParamCount(); ++param) {
if (better(*call[param].type, *can1[param].type, *can2[param].type)) {
hasBetterParam = true;
break;
}
}
return hasBetterParam;
};
const auto equivalentParams = [&call, &better](const TFunction& can1, const TFunction& can2) -> bool {
// is call -> can2 equivalent to call -> can1 for all the call parameters?
for (int param = 0; param < call.getParamCount(); ++param) {
if (better(*call[param].type, *can1[param].type, *can2[param].type) ||
better(*call[param].type, *can2[param].type, *can1[param].type))
return false;
}
return true;
};
const TFunction* incumbent = viableCandidates.front();
for (auto it = viableCandidates.begin() + 1; it != viableCandidates.end(); ++it) {
const TFunction& candidate = *(*it);
if (betterParam(*incumbent, candidate) && ! betterParam(candidate, *incumbent))
incumbent = &candidate;
}
// 5. ambiguity...
for (auto it = viableCandidates.begin(); it != viableCandidates.end(); ++it) {
if (incumbent == *it)
continue;
const TFunction& candidate = *(*it);
// In the case of default parameters, it may have an identical initial set, which is
// also ambiguous
if (betterParam(*incumbent, candidate) || equivalentParams(*incumbent, candidate))
tie = true;
}
return incumbent;
}
//
// Look at a '.' field selector string and change it into numerical selectors
// for a vector or scalar.
//
// Always return some form of swizzle, so the result is always usable.
//
void TParseContextBase::parseSwizzleSelector(const TSourceLoc& loc, const TString& compString, int vecSize,
TSwizzleSelectors<TVectorSelector>& selector)
{
// Too long?
if (compString.size() > MaxSwizzleSelectors)
error(loc, "vector swizzle too long", compString.c_str(), "");
// Use this to test that all swizzle characters are from the same swizzle-namespace-set
enum {
exyzw,
ergba,
estpq,
} fieldSet[MaxSwizzleSelectors];
// Decode the swizzle string.
int size = std::min(MaxSwizzleSelectors, (int)compString.size());
for (int i = 0; i < size; ++i) {
switch (compString[i]) {
case 'x':
selector.push_back(0);
fieldSet[i] = exyzw;
break;
case 'r':
selector.push_back(0);
fieldSet[i] = ergba;
break;
case 's':
selector.push_back(0);
fieldSet[i] = estpq;
break;
case 'y':
selector.push_back(1);
fieldSet[i] = exyzw;
break;
case 'g':
selector.push_back(1);
fieldSet[i] = ergba;
break;
case 't':
selector.push_back(1);
fieldSet[i] = estpq;
break;
case 'z':
selector.push_back(2);
fieldSet[i] = exyzw;
break;
case 'b':
selector.push_back(2);
fieldSet[i] = ergba;
break;
case 'p':
selector.push_back(2);
fieldSet[i] = estpq;
break;
case 'w':
selector.push_back(3);
fieldSet[i] = exyzw;
break;
case 'a':
selector.push_back(3);
fieldSet[i] = ergba;
break;
case 'q':
selector.push_back(3);
fieldSet[i] = estpq;
break;
default:
error(loc, "unknown swizzle selection", compString.c_str(), "");
break;
}
}
// Additional error checking.
for (int i = 0; i < selector.size(); ++i) {
if (selector[i] >= vecSize) {
error(loc, "vector swizzle selection out of range", compString.c_str(), "");
selector.resize(i);
break;
}
if (i > 0 && fieldSet[i] != fieldSet[i-1]) {
error(loc, "vector swizzle selectors not from the same set", compString.c_str(), "");
selector.resize(i);
break;
}
}
// Ensure it is valid.
if (selector.size() == 0)
selector.push_back(0);
}
//
// Make the passed-in variable information become a member of the
// global uniform block. If this doesn't exist yet, make it.
//
void TParseContextBase::growGlobalUniformBlock(const TSourceLoc& loc, TType& memberType, const TString& memberName, TTypeList* typeList)
{
// Make the global block, if not yet made.
if (globalUniformBlock == nullptr) {
TQualifier blockQualifier;
blockQualifier.clear();
blockQualifier.storage = EvqUniform;
TType blockType(new TTypeList, *NewPoolTString(getGlobalUniformBlockName()), blockQualifier);
setUniformBlockDefaults(blockType);
globalUniformBlock = new TVariable(NewPoolTString(""), blockType, true);
firstNewMember = 0;
}
// Update with binding and set
globalUniformBlock->getWritableType().getQualifier().layoutBinding = globalUniformBinding;
globalUniformBlock->getWritableType().getQualifier().layoutSet = globalUniformSet;
// Check for declarations of this default uniform that already exist due to other compilation units.
TSymbol* symbol = symbolTable.find(memberName);
if (symbol) {
if (memberType != symbol->getType()) {
TString err;
err += "Redeclaration: already declared as \"" + symbol->getType().getCompleteString() + "\"";
error(loc, "", memberName.c_str(), err.c_str());
}
return;
}
// Add the requested member as a member to the global block.
TType* type = new TType;
type->shallowCopy(memberType);
type->setFieldName(memberName);
if (typeList)
type->setStruct(typeList);
TTypeLoc typeLoc = {type, loc};
globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc);
// Insert into the symbol table.
if (firstNewMember == 0) {
// This is the first request; we need a normal symbol table insert
if (symbolTable.insert(*globalUniformBlock))
trackLinkage(*globalUniformBlock);
else
error(loc, "failed to insert the global constant buffer", "uniform", "");
} else {
// This is a follow-on request; we need to amend the first insert
symbolTable.amend(*globalUniformBlock, firstNewMember);
}
++firstNewMember;
}
void TParseContextBase::growAtomicCounterBlock(int binding, const TSourceLoc& loc, TType& memberType, const TString& memberName, TTypeList* typeList) {
// Make the atomic counter block, if not yet made.
const auto &at = atomicCounterBuffers.find(binding);
if (at == atomicCounterBuffers.end()) {
atomicCounterBuffers.insert({binding, (TVariable*)nullptr });
atomicCounterBlockFirstNewMember.insert({binding, 0});
}
TVariable*& atomicCounterBuffer = atomicCounterBuffers[binding];
int& bufferNewMember = atomicCounterBlockFirstNewMember[binding];
if (atomicCounterBuffer == nullptr) {
TQualifier blockQualifier;
blockQualifier.clear();
blockQualifier.storage = EvqBuffer;
char charBuffer[512];
if (binding != TQualifier::layoutBindingEnd) {
snprintf(charBuffer, 512, "%s_%d", getAtomicCounterBlockName(), binding);
} else {
snprintf(charBuffer, 512, "%s_0", getAtomicCounterBlockName());
}
TType blockType(new TTypeList, *NewPoolTString(charBuffer), blockQualifier);
setUniformBlockDefaults(blockType);
blockType.getQualifier().layoutPacking = ElpStd430;
atomicCounterBuffer = new TVariable(NewPoolTString(""), blockType, true);
// If we arn't auto mapping bindings then set the block to use the same
// binding as what the atomic was set to use
if (!intermediate.getAutoMapBindings()) {
atomicCounterBuffer->getWritableType().getQualifier().layoutBinding = binding;
}
bufferNewMember = 0;
atomicCounterBuffer->getWritableType().getQualifier().layoutSet = atomicCounterBlockSet;
}
// Add the requested member as a member to the global block.
TType* type = new TType;
type->shallowCopy(memberType);
type->setFieldName(memberName);
if (typeList)
type->setStruct(typeList);
TTypeLoc typeLoc = {type, loc};
atomicCounterBuffer->getType().getWritableStruct()->push_back(typeLoc);
// Insert into the symbol table.
if (bufferNewMember == 0) {
// This is the first request; we need a normal symbol table insert
if (symbolTable.insert(*atomicCounterBuffer))
trackLinkage(*atomicCounterBuffer);
else
error(loc, "failed to insert the global constant buffer", "buffer", "");
} else {
// This is a follow-on request; we need to amend the first insert
symbolTable.amend(*atomicCounterBuffer, bufferNewMember);
}
++bufferNewMember;
}
void TParseContextBase::finish()
{
if (parsingBuiltins)
return;
for (const TString& relaxedSymbol : relaxedSymbols)
{
TSymbol* symbol = symbolTable.find(relaxedSymbol);
TType& type = symbol->getWritableType();
for (const TTypeLoc& typeLoc : *type.getStruct())
{
if (typeLoc.type->isOpaque())
{
typeLoc.type->getSampler() = TSampler{};
typeLoc.type->setBasicType(EbtInt);
TString fieldName("/*");
fieldName.append(typeLoc.type->getFieldName());
fieldName.append("*/");
typeLoc.type->setFieldName(fieldName);
}
}
}
// Transfer the linkage symbols to AST nodes, preserving order.
TIntermAggregate* linkage = new TIntermAggregate;
for (auto i = linkageSymbols.begin(); i != linkageSymbols.end(); ++i)
intermediate.addSymbolLinkageNode(linkage, **i);
intermediate.addSymbolLinkageNodes(linkage, getLanguage(), symbolTable);
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/Intermediate.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2015 LunarG, Inc.
// Copyright (C) 2015-2020 Google, Inc.
// Copyright (C) 2017 ARM Limited.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Build the intermediate representation.
//
#include "localintermediate.h"
#include "RemoveTree.h"
#include "SymbolTable.h"
#include "propagateNoContraction.h"
#include <cfloat>
#include <utility>
#include <tuple>
namespace glslang {
////////////////////////////////////////////////////////////////////////////
//
// First set of functions are to help build the intermediate representation.
// These functions are not member functions of the nodes.
// They are called from parser productions.
//
/////////////////////////////////////////////////////////////////////////////
//
// Add a terminal node for an identifier in an expression.
//
// Returns the added node.
//
TIntermSymbol* TIntermediate::addSymbol(long long id, const TString& name, const TType& type, const TConstUnionArray& constArray,
TIntermTyped* constSubtree, const TSourceLoc& loc)
{
TIntermSymbol* node = new TIntermSymbol(id, name, type);
node->setLoc(loc);
node->setConstArray(constArray);
node->setConstSubtree(constSubtree);
return node;
}
TIntermSymbol* TIntermediate::addSymbol(const TIntermSymbol& intermSymbol)
{
return addSymbol(intermSymbol.getId(),
intermSymbol.getName(),
intermSymbol.getType(),
intermSymbol.getConstArray(),
intermSymbol.getConstSubtree(),
intermSymbol.getLoc());
}
TIntermSymbol* TIntermediate::addSymbol(const TVariable& variable)
{
glslang::TSourceLoc loc; // just a null location
loc.init();
return addSymbol(variable, loc);
}
TIntermSymbol* TIntermediate::addSymbol(const TVariable& variable, const TSourceLoc& loc)
{
return addSymbol(variable.getUniqueId(), variable.getName(), variable.getType(), variable.getConstArray(), variable.getConstSubtree(), loc);
}
TIntermSymbol* TIntermediate::addSymbol(const TType& type, const TSourceLoc& loc)
{
TConstUnionArray unionArray; // just a null constant
return addSymbol(0, "", type, unionArray, nullptr, loc);
}
//
// Connect two nodes with a new parent that does a binary operation on the nodes.
//
// Returns the added node.
//
// Returns nullptr if the working conversions and promotions could not be found.
//
TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc& loc)
{
// No operations work on blocks
if (left->getType().getBasicType() == EbtBlock || right->getType().getBasicType() == EbtBlock)
return nullptr;
// Convert "reference +/- int" and "reference - reference" to integer math
if (op == EOpAdd || op == EOpSub) {
// No addressing math on struct with unsized array.
if ((left->isReference() && left->getType().getReferentType()->containsUnsizedArray()) ||
(right->isReference() && right->getType().getReferentType()->containsUnsizedArray())) {
return nullptr;
}
if (left->isReference() && isTypeInt(right->getBasicType())) {
const TType& referenceType = left->getType();
TIntermConstantUnion* size = addConstantUnion((unsigned long long)computeBufferReferenceTypeSize(left->getType()), loc, true);
left = addBuiltInFunctionCall(loc, EOpConvPtrToUint64, true, left, TType(EbtUint64));
right = createConversion(EbtInt64, right);
right = addBinaryMath(EOpMul, right, size, loc);
TIntermTyped *node = addBinaryMath(op, left, right, loc);
node = addBuiltInFunctionCall(loc, EOpConvUint64ToPtr, true, node, referenceType);
return node;
}
}
if (op == EOpAdd && right->isReference() && isTypeInt(left->getBasicType())) {
const TType& referenceType = right->getType();
TIntermConstantUnion* size =
addConstantUnion((unsigned long long)computeBufferReferenceTypeSize(right->getType()), loc, true);
right = addBuiltInFunctionCall(loc, EOpConvPtrToUint64, true, right, TType(EbtUint64));
left = createConversion(EbtInt64, left);
left = addBinaryMath(EOpMul, left, size, loc);
TIntermTyped *node = addBinaryMath(op, left, right, loc);
node = addBuiltInFunctionCall(loc, EOpConvUint64ToPtr, true, node, referenceType);
return node;
}
if (op == EOpSub && left->isReference() && right->isReference()) {
TIntermConstantUnion* size =
addConstantUnion((long long)computeBufferReferenceTypeSize(left->getType()), loc, true);
left = addBuiltInFunctionCall(loc, EOpConvPtrToUint64, true, left, TType(EbtUint64));
right = addBuiltInFunctionCall(loc, EOpConvPtrToUint64, true, right, TType(EbtUint64));
left = addBuiltInFunctionCall(loc, EOpConvUint64ToInt64, true, left, TType(EbtInt64));
right = addBuiltInFunctionCall(loc, EOpConvUint64ToInt64, true, right, TType(EbtInt64));
left = addBinaryMath(EOpSub, left, right, loc);
TIntermTyped *node = addBinaryMath(EOpDiv, left, size, loc);
return node;
}
// No other math operators supported on references
if (left->isReference() || right->isReference())
return nullptr;
// Try converting the children's base types to compatible types.
auto children = addPairConversion(op, left, right);
left = std::get<0>(children);
right = std::get<1>(children);
if (left == nullptr || right == nullptr)
return nullptr;
// Convert the children's type shape to be compatible.
addBiShapeConversion(op, left, right);
if (left == nullptr || right == nullptr)
return nullptr;
//
// Need a new node holding things together. Make
// one and promote it to the right type.
//
TIntermBinary* node = addBinaryNode(op, left, right, loc);
if (! promote(node))
return nullptr;
node->updatePrecision();
//
// If they are both (non-specialization) constants, they must be folded.
// (Unless it's the sequence (comma) operator, but that's handled in addComma().)
//
TIntermConstantUnion *leftTempConstant = node->getLeft()->getAsConstantUnion();
TIntermConstantUnion *rightTempConstant = node->getRight()->getAsConstantUnion();
if (leftTempConstant && rightTempConstant) {
TIntermTyped* folded = leftTempConstant->fold(node->getOp(), rightTempConstant);
if (folded)
return folded;
}
// If can propagate spec-constantness and if the operation is an allowed
// specialization-constant operation, make a spec-constant.
if (specConstantPropagates(*node->getLeft(), *node->getRight()) && isSpecializationOperation(*node))
node->getWritableType().getQualifier().makeSpecConstant();
// If must propagate nonuniform, make a nonuniform.
if ((node->getLeft()->getQualifier().isNonUniform() || node->getRight()->getQualifier().isNonUniform()) &&
isNonuniformPropagating(node->getOp()))
node->getWritableType().getQualifier().nonUniform = true;
return node;
}
//
// Low level: add binary node (no promotions or other argument modifications)
//
TIntermBinary* TIntermediate::addBinaryNode(TOperator op, TIntermTyped* left, TIntermTyped* right,
const TSourceLoc& loc) const
{
// build the node
TIntermBinary* node = new TIntermBinary(op);
node->setLoc(loc.line != 0 ? loc : left->getLoc());
node->setLeft(left);
node->setRight(right);
return node;
}
//
// like non-type form, but sets node's type.
//
TIntermBinary* TIntermediate::addBinaryNode(TOperator op, TIntermTyped* left, TIntermTyped* right,
const TSourceLoc& loc, const TType& type) const
{
TIntermBinary* node = addBinaryNode(op, left, right, loc);
node->setType(type);
return node;
}
//
// Low level: add unary node (no promotions or other argument modifications)
//
TIntermUnary* TIntermediate::addUnaryNode(TOperator op, TIntermTyped* child, const TSourceLoc& loc) const
{
TIntermUnary* node = new TIntermUnary(op);
node->setLoc(loc.line != 0 ? loc : child->getLoc());
node->setOperand(child);
return node;
}
//
// like non-type form, but sets node's type.
//
TIntermUnary* TIntermediate::addUnaryNode(TOperator op, TIntermTyped* child, const TSourceLoc& loc, const TType& type)
const
{
TIntermUnary* node = addUnaryNode(op, child, loc);
node->setType(type);
return node;
}
//
// Connect two nodes through an assignment.
//
// Returns the added node.
//
// Returns nullptr if the 'right' type could not be converted to match the 'left' type,
// or the resulting operation cannot be properly promoted.
//
TIntermTyped* TIntermediate::addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right,
const TSourceLoc& loc)
{
// No block assignment
if (left->getType().getBasicType() == EbtBlock || right->getType().getBasicType() == EbtBlock)
return nullptr;
// Convert "reference += int" to "reference = reference + int". We need this because the
// "reference + int" calculation involves a cast back to the original type, which makes it
// not an lvalue.
if ((op == EOpAddAssign || op == EOpSubAssign) && left->isReference()) {
if (!(right->getType().isScalar() && right->getType().isIntegerDomain()))
return nullptr;
TIntermTyped* node = addBinaryMath(op == EOpAddAssign ? EOpAdd : EOpSub, left, right, loc);
if (!node)
return nullptr;
TIntermSymbol* symbol = left->getAsSymbolNode();
left = addSymbol(*symbol);
node = addAssign(EOpAssign, left, node, loc);
return node;
}
//
// Like adding binary math, except the conversion can only go
// from right to left.
//
// convert base types, nullptr return means not possible
right = addConversion(op, left->getType(), right);
if (right == nullptr)
return nullptr;
// convert shape
right = addUniShapeConversion(op, left->getType(), right);
// build the node
TIntermBinary* node = addBinaryNode(op, left, right, loc);
if (! promote(node))
return nullptr;
node->updatePrecision();
return node;
}
//
// Connect two nodes through an index operator, where the left node is the base
// of an array or struct, and the right node is a direct or indirect offset.
//
// Returns the added node.
// The caller should set the type of the returned node.
//
TIntermTyped* TIntermediate::addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index,
const TSourceLoc& loc)
{
// caller should set the type
return addBinaryNode(op, base, index, loc);
}
//
// Add one node as the parent of another that it operates on.
//
// Returns the added node.
//
TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermTyped* child,
const TSourceLoc& loc)
{
if (child == nullptr)
return nullptr;
if (child->getType().getBasicType() == EbtBlock)
return nullptr;
switch (op) {
case EOpLogicalNot:
if (getSource() == EShSourceHlsl) {
break; // HLSL can promote logical not
}
if (child->getType().getBasicType() != EbtBool || child->getType().isMatrix() || child->getType().isArray() || child->getType().isVector()) {
return nullptr;
}
break;
case EOpPostIncrement:
case EOpPreIncrement:
case EOpPostDecrement:
case EOpPreDecrement:
case EOpNegative:
if (child->getType().getBasicType() == EbtStruct || child->getType().isArray())
return nullptr;
break;
default: break; // some compilers want this
}
//
// Do we need to promote the operand?
//
TBasicType newType = EbtVoid;
switch (op) {
case EOpConstructBool: newType = EbtBool; break;
case EOpConstructFloat: newType = EbtFloat; break;
case EOpConstructInt: newType = EbtInt; break;
case EOpConstructUint: newType = EbtUint; break;
case EOpConstructInt8: newType = EbtInt8; break;
case EOpConstructUint8: newType = EbtUint8; break;
case EOpConstructInt16: newType = EbtInt16; break;
case EOpConstructUint16: newType = EbtUint16; break;
case EOpConstructInt64: newType = EbtInt64; break;
case EOpConstructUint64: newType = EbtUint64; break;
case EOpConstructDouble: newType = EbtDouble; break;
case EOpConstructFloat16: newType = EbtFloat16; break;
default: break; // some compilers want this
}
if (newType != EbtVoid) {
child = addConversion(op, TType(newType, EvqTemporary, child->getVectorSize(),
child->getMatrixCols(),
child->getMatrixRows(),
child->isVector()),
child);
if (child == nullptr)
return nullptr;
}
//
// For constructors, we are now done, it was all in the conversion.
// TODO: but, did this bypass constant folding?
//
switch (op) {
case EOpConstructInt8:
case EOpConstructUint8:
case EOpConstructInt16:
case EOpConstructUint16:
case EOpConstructInt:
case EOpConstructUint:
case EOpConstructInt64:
case EOpConstructUint64:
case EOpConstructBool:
case EOpConstructFloat:
case EOpConstructDouble:
case EOpConstructFloat16: {
TIntermUnary* unary_node = child->getAsUnaryNode();
if (unary_node != nullptr)
unary_node->updatePrecision();
return child;
}
default: break; // some compilers want this
}
//
// Make a new node for the operator.
//
TIntermUnary* node = addUnaryNode(op, child, loc);
if (! promote(node))
return nullptr;
node->updatePrecision();
// If it's a (non-specialization) constant, it must be folded.
if (node->getOperand()->getAsConstantUnion())
return node->getOperand()->getAsConstantUnion()->fold(op, node->getType());
// If it's a specialization constant, the result is too,
// if the operation is allowed for specialization constants.
if (node->getOperand()->getType().getQualifier().isSpecConstant() && isSpecializationOperation(*node))
node->getWritableType().getQualifier().makeSpecConstant();
// If must propagate nonuniform, make a nonuniform.
if (node->getOperand()->getQualifier().isNonUniform() && isNonuniformPropagating(node->getOp()))
node->getWritableType().getQualifier().nonUniform = true;
return node;
}
TIntermTyped* TIntermediate::addBuiltInFunctionCall(const TSourceLoc& loc, TOperator op, bool unary,
TIntermNode* childNode, const TType& returnType)
{
if (unary) {
//
// Treat it like a unary operator.
// addUnaryMath() should get the type correct on its own;
// including constness (which would differ from the prototype).
//
TIntermTyped* child = childNode->getAsTyped();
if (child == nullptr)
return nullptr;
if (child->getAsConstantUnion()) {
TIntermTyped* folded = child->getAsConstantUnion()->fold(op, returnType);
if (folded)
return folded;
}
return addUnaryNode(op, child, child->getLoc(), returnType);
} else {
// setAggregateOperater() calls fold() for constant folding
TIntermTyped* node = setAggregateOperator(childNode, op, returnType, loc);
return node;
}
}
//
// This is the safe way to change the operator on an aggregate, as it
// does lots of error checking and fixing. Especially for establishing
// a function call's operation on its set of parameters. Sequences
// of instructions are also aggregates, but they just directly set
// their operator to EOpSequence.
//
// Returns an aggregate node, which could be the one passed in if
// it was already an aggregate.
//
TIntermTyped* TIntermediate::setAggregateOperator(TIntermNode* node, TOperator op, const TType& type,
const TSourceLoc& loc)
{
TIntermAggregate* aggNode;
//
// Make sure we have an aggregate. If not turn it into one.
//
if (node != nullptr) {
aggNode = node->getAsAggregate();
if (aggNode == nullptr || aggNode->getOp() != EOpNull) {
//
// Make an aggregate containing this node.
//
aggNode = new TIntermAggregate();
aggNode->getSequence().push_back(node);
}
} else
aggNode = new TIntermAggregate();
//
// Set the operator.
//
aggNode->setOperator(op);
if (loc.line != 0 || node != nullptr)
aggNode->setLoc(loc.line != 0 ? loc : node->getLoc());
aggNode->setType(type);
return fold(aggNode);
}
bool TIntermediate::isConversionAllowed(TOperator op, TIntermTyped* node) const
{
//
// Does the base type even allow the operation?
//
switch (node->getBasicType()) {
case EbtVoid:
return false;
case EbtAtomicUint:
case EbtSampler:
case EbtAccStruct:
// opaque types can be passed to functions
if (op == EOpFunction)
break;
// HLSL can assign samplers directly (no constructor)
if (getSource() == EShSourceHlsl && node->getBasicType() == EbtSampler)
break;
// samplers can get assigned via a sampler constructor
// (well, not yet, but code in the rest of this function is ready for it)
if (node->getBasicType() == EbtSampler && op == EOpAssign &&
node->getAsOperator() != nullptr && node->getAsOperator()->getOp() == EOpConstructTextureSampler)
break;
// otherwise, opaque types can't even be operated on, let alone converted
return false;
default:
break;
}
return true;
}
bool TIntermediate::buildConvertOp(TBasicType dst, TBasicType src, TOperator& newOp) const
{
switch (dst) {
case EbtDouble:
switch (src) {
case EbtUint: newOp = EOpConvUintToDouble; break;
case EbtBool: newOp = EOpConvBoolToDouble; break;
case EbtFloat: newOp = EOpConvFloatToDouble; break;
case EbtInt: newOp = EOpConvIntToDouble; break;
case EbtInt8: newOp = EOpConvInt8ToDouble; break;
case EbtUint8: newOp = EOpConvUint8ToDouble; break;
case EbtInt16: newOp = EOpConvInt16ToDouble; break;
case EbtUint16: newOp = EOpConvUint16ToDouble; break;
case EbtFloat16: newOp = EOpConvFloat16ToDouble; break;
case EbtInt64: newOp = EOpConvInt64ToDouble; break;
case EbtUint64: newOp = EOpConvUint64ToDouble; break;
default:
return false;
}
break;
case EbtFloat:
switch (src) {
case EbtInt: newOp = EOpConvIntToFloat; break;
case EbtUint: newOp = EOpConvUintToFloat; break;
case EbtBool: newOp = EOpConvBoolToFloat; break;
case EbtDouble: newOp = EOpConvDoubleToFloat; break;
case EbtInt8: newOp = EOpConvInt8ToFloat; break;
case EbtUint8: newOp = EOpConvUint8ToFloat; break;
case EbtInt16: newOp = EOpConvInt16ToFloat; break;
case EbtUint16: newOp = EOpConvUint16ToFloat; break;
case EbtFloat16: newOp = EOpConvFloat16ToFloat; break;
case EbtInt64: newOp = EOpConvInt64ToFloat; break;
case EbtUint64: newOp = EOpConvUint64ToFloat; break;
default:
return false;
}
break;
case EbtFloat16:
switch (src) {
case EbtInt8: newOp = EOpConvInt8ToFloat16; break;
case EbtUint8: newOp = EOpConvUint8ToFloat16; break;
case EbtInt16: newOp = EOpConvInt16ToFloat16; break;
case EbtUint16: newOp = EOpConvUint16ToFloat16; break;
case EbtInt: newOp = EOpConvIntToFloat16; break;
case EbtUint: newOp = EOpConvUintToFloat16; break;
case EbtBool: newOp = EOpConvBoolToFloat16; break;
case EbtFloat: newOp = EOpConvFloatToFloat16; break;
case EbtDouble: newOp = EOpConvDoubleToFloat16; break;
case EbtInt64: newOp = EOpConvInt64ToFloat16; break;
case EbtUint64: newOp = EOpConvUint64ToFloat16; break;
default:
return false;
}
break;
case EbtBool:
switch (src) {
case EbtInt: newOp = EOpConvIntToBool; break;
case EbtUint: newOp = EOpConvUintToBool; break;
case EbtFloat: newOp = EOpConvFloatToBool; break;
case EbtDouble: newOp = EOpConvDoubleToBool; break;
case EbtInt8: newOp = EOpConvInt8ToBool; break;
case EbtUint8: newOp = EOpConvUint8ToBool; break;
case EbtInt16: newOp = EOpConvInt16ToBool; break;
case EbtUint16: newOp = EOpConvUint16ToBool; break;
case EbtFloat16: newOp = EOpConvFloat16ToBool; break;
case EbtInt64: newOp = EOpConvInt64ToBool; break;
case EbtUint64: newOp = EOpConvUint64ToBool; break;
default:
return false;
}
break;
case EbtInt8:
switch (src) {
case EbtUint8: newOp = EOpConvUint8ToInt8; break;
case EbtInt16: newOp = EOpConvInt16ToInt8; break;
case EbtUint16: newOp = EOpConvUint16ToInt8; break;
case EbtInt: newOp = EOpConvIntToInt8; break;
case EbtUint: newOp = EOpConvUintToInt8; break;
case EbtInt64: newOp = EOpConvInt64ToInt8; break;
case EbtUint64: newOp = EOpConvUint64ToInt8; break;
case EbtBool: newOp = EOpConvBoolToInt8; break;
case EbtFloat: newOp = EOpConvFloatToInt8; break;
case EbtDouble: newOp = EOpConvDoubleToInt8; break;
case EbtFloat16: newOp = EOpConvFloat16ToInt8; break;
default:
return false;
}
break;
case EbtUint8:
switch (src) {
case EbtInt8: newOp = EOpConvInt8ToUint8; break;
case EbtInt16: newOp = EOpConvInt16ToUint8; break;
case EbtUint16: newOp = EOpConvUint16ToUint8; break;
case EbtInt: newOp = EOpConvIntToUint8; break;
case EbtUint: newOp = EOpConvUintToUint8; break;
case EbtInt64: newOp = EOpConvInt64ToUint8; break;
case EbtUint64: newOp = EOpConvUint64ToUint8; break;
case EbtBool: newOp = EOpConvBoolToUint8; break;
case EbtFloat: newOp = EOpConvFloatToUint8; break;
case EbtDouble: newOp = EOpConvDoubleToUint8; break;
case EbtFloat16: newOp = EOpConvFloat16ToUint8; break;
default:
return false;
}
break;
case EbtInt16:
switch (src) {
case EbtUint8: newOp = EOpConvUint8ToInt16; break;
case EbtInt8: newOp = EOpConvInt8ToInt16; break;
case EbtUint16: newOp = EOpConvUint16ToInt16; break;
case EbtInt: newOp = EOpConvIntToInt16; break;
case EbtUint: newOp = EOpConvUintToInt16; break;
case EbtInt64: newOp = EOpConvInt64ToInt16; break;
case EbtUint64: newOp = EOpConvUint64ToInt16; break;
case EbtBool: newOp = EOpConvBoolToInt16; break;
case EbtFloat: newOp = EOpConvFloatToInt16; break;
case EbtDouble: newOp = EOpConvDoubleToInt16; break;
case EbtFloat16: newOp = EOpConvFloat16ToInt16; break;
default:
return false;
}
break;
case EbtUint16:
switch (src) {
case EbtInt8: newOp = EOpConvInt8ToUint16; break;
case EbtUint8: newOp = EOpConvUint8ToUint16; break;
case EbtInt16: newOp = EOpConvInt16ToUint16; break;
case EbtInt: newOp = EOpConvIntToUint16; break;
case EbtUint: newOp = EOpConvUintToUint16; break;
case EbtInt64: newOp = EOpConvInt64ToUint16; break;
case EbtUint64: newOp = EOpConvUint64ToUint16; break;
case EbtBool: newOp = EOpConvBoolToUint16; break;
case EbtFloat: newOp = EOpConvFloatToUint16; break;
case EbtDouble: newOp = EOpConvDoubleToUint16; break;
case EbtFloat16: newOp = EOpConvFloat16ToUint16; break;
default:
return false;
}
break;
case EbtInt:
switch (src) {
case EbtUint: newOp = EOpConvUintToInt; break;
case EbtBool: newOp = EOpConvBoolToInt; break;
case EbtFloat: newOp = EOpConvFloatToInt; break;
case EbtInt8: newOp = EOpConvInt8ToInt; break;
case EbtUint8: newOp = EOpConvUint8ToInt; break;
case EbtInt16: newOp = EOpConvInt16ToInt; break;
case EbtUint16: newOp = EOpConvUint16ToInt; break;
case EbtDouble: newOp = EOpConvDoubleToInt; break;
case EbtFloat16: newOp = EOpConvFloat16ToInt; break;
case EbtInt64: newOp = EOpConvInt64ToInt; break;
case EbtUint64: newOp = EOpConvUint64ToInt; break;
default:
return false;
}
break;
case EbtUint:
switch (src) {
case EbtInt: newOp = EOpConvIntToUint; break;
case EbtBool: newOp = EOpConvBoolToUint; break;
case EbtFloat: newOp = EOpConvFloatToUint; break;
case EbtInt8: newOp = EOpConvInt8ToUint; break;
case EbtUint8: newOp = EOpConvUint8ToUint; break;
case EbtInt16: newOp = EOpConvInt16ToUint; break;
case EbtUint16: newOp = EOpConvUint16ToUint; break;
case EbtDouble: newOp = EOpConvDoubleToUint; break;
case EbtFloat16: newOp = EOpConvFloat16ToUint; break;
case EbtInt64: newOp = EOpConvInt64ToUint; break;
case EbtUint64: newOp = EOpConvUint64ToUint; break;
// For bindless texture type conversion, add a dummy convert op, just
// to generate a new TIntermTyped
// uvec2(any sampler type)
// uvec2(any image type)
case EbtSampler: newOp = EOpConvIntToUint; break;
default:
return false;
}
break;
case EbtInt64:
switch (src) {
case EbtInt8: newOp = EOpConvInt8ToInt64; break;
case EbtUint8: newOp = EOpConvUint8ToInt64; break;
case EbtInt16: newOp = EOpConvInt16ToInt64; break;
case EbtUint16: newOp = EOpConvUint16ToInt64; break;
case EbtInt: newOp = EOpConvIntToInt64; break;
case EbtUint: newOp = EOpConvUintToInt64; break;
case EbtBool: newOp = EOpConvBoolToInt64; break;
case EbtFloat: newOp = EOpConvFloatToInt64; break;
case EbtDouble: newOp = EOpConvDoubleToInt64; break;
case EbtFloat16: newOp = EOpConvFloat16ToInt64; break;
case EbtUint64: newOp = EOpConvUint64ToInt64; break;
default:
return false;
}
break;
case EbtUint64:
switch (src) {
case EbtInt8: newOp = EOpConvInt8ToUint64; break;
case EbtUint8: newOp = EOpConvUint8ToUint64; break;
case EbtInt16: newOp = EOpConvInt16ToUint64; break;
case EbtUint16: newOp = EOpConvUint16ToUint64; break;
case EbtInt: newOp = EOpConvIntToUint64; break;
case EbtUint: newOp = EOpConvUintToUint64; break;
case EbtBool: newOp = EOpConvBoolToUint64; break;
case EbtFloat: newOp = EOpConvFloatToUint64; break;
case EbtDouble: newOp = EOpConvDoubleToUint64; break;
case EbtFloat16: newOp = EOpConvFloat16ToUint64; break;
case EbtInt64: newOp = EOpConvInt64ToUint64; break;
default:
return false;
}
break;
default:
return false;
}
return true;
}
// This is 'mechanism' here, it does any conversion told.
// It is about basic type, not about shape.
// The policy comes from the shader or the calling code.
TIntermTyped* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped* node) const
{
//
// Add a new newNode for the conversion.
//
bool convertToIntTypes = (convertTo == EbtInt8 || convertTo == EbtUint8 ||
convertTo == EbtInt16 || convertTo == EbtUint16 ||
convertTo == EbtInt || convertTo == EbtUint ||
convertTo == EbtInt64 || convertTo == EbtUint64);
bool convertFromIntTypes = (node->getBasicType() == EbtInt8 || node->getBasicType() == EbtUint8 ||
node->getBasicType() == EbtInt16 || node->getBasicType() == EbtUint16 ||
node->getBasicType() == EbtInt || node->getBasicType() == EbtUint ||
node->getBasicType() == EbtInt64 || node->getBasicType() == EbtUint64);
bool convertToFloatTypes = (convertTo == EbtFloat16 || convertTo == EbtFloat || convertTo == EbtDouble);
bool convertFromFloatTypes = (node->getBasicType() == EbtFloat16 ||
node->getBasicType() == EbtFloat ||
node->getBasicType() == EbtDouble);
if (((convertTo == EbtInt8 || convertTo == EbtUint8) && ! convertFromIntTypes) ||
((node->getBasicType() == EbtInt8 || node->getBasicType() == EbtUint8) && ! convertToIntTypes)) {
if (! getArithemeticInt8Enabled()) {
return nullptr;
}
}
if (((convertTo == EbtInt16 || convertTo == EbtUint16) && ! convertFromIntTypes) ||
((node->getBasicType() == EbtInt16 || node->getBasicType() == EbtUint16) && ! convertToIntTypes)) {
if (! getArithemeticInt16Enabled()) {
return nullptr;
}
}
if ((convertTo == EbtFloat16 && ! convertFromFloatTypes) ||
(node->getBasicType() == EbtFloat16 && ! convertToFloatTypes)) {
if (! getArithemeticFloat16Enabled()) {
return nullptr;
}
}
TIntermUnary* newNode = nullptr;
TOperator newOp = EOpNull;
if (!buildConvertOp(convertTo, node->getBasicType(), newOp)) {
return nullptr;
}
TType newType(convertTo, EvqTemporary, node->getVectorSize(), node->getMatrixCols(), node->getMatrixRows());
newNode = addUnaryNode(newOp, node, node->getLoc(), newType);
if (node->getAsConstantUnion()) {
// 8/16-bit storage extensions don't support 8/16-bit constants, so don't fold conversions
// to those types
if ((getArithemeticInt8Enabled() || !(convertTo == EbtInt8 || convertTo == EbtUint8)) &&
(getArithemeticInt16Enabled() || !(convertTo == EbtInt16 || convertTo == EbtUint16)) &&
(getArithemeticFloat16Enabled() || !(convertTo == EbtFloat16)))
{
TIntermTyped* folded = node->getAsConstantUnion()->fold(newOp, newType);
if (folded)
return folded;
}
}
// Propagate specialization-constant-ness, if allowed
if (node->getType().getQualifier().isSpecConstant() && isSpecializationOperation(*newNode))
newNode->getWritableType().getQualifier().makeSpecConstant();
return newNode;
}
TIntermTyped* TIntermediate::addConversion(TBasicType convertTo, TIntermTyped* node) const
{
return createConversion(convertTo, node);
}
// For converting a pair of operands to a binary operation to compatible
// types with each other, relative to the operation in 'op'.
// This does not cover assignment operations, which is asymmetric in that the
// left type is not changeable.
// See addConversion(op, type, node) for assignments and unary operation
// conversions.
//
// Generally, this is focused on basic type conversion, not shape conversion.
// See addShapeConversion() for shape conversions.
//
// Returns the converted pair of nodes.
// Returns <nullptr, nullptr> when there is no conversion.
std::tuple<TIntermTyped*, TIntermTyped*>
TIntermediate::addPairConversion(TOperator op, TIntermTyped* node0, TIntermTyped* node1)
{
if (!isConversionAllowed(op, node0) || !isConversionAllowed(op, node1))
return std::make_tuple(nullptr, nullptr);
if (node0->getType() != node1->getType()) {
// If differing structure, then no conversions.
if (node0->isStruct() || node1->isStruct())
return std::make_tuple(nullptr, nullptr);
// If differing arrays, then no conversions.
if (node0->getType().isArray() || node1->getType().isArray())
return std::make_tuple(nullptr, nullptr);
// No implicit conversions for operations involving cooperative matrices
if (node0->getType().isCoopMat() || node1->getType().isCoopMat())
return std::make_tuple(node0, node1);
}
auto promoteTo = std::make_tuple(EbtNumTypes, EbtNumTypes);
switch (op) {
//
// List all the binary ops that can implicitly convert one operand to the other's type;
// This implements the 'policy' for implicit type conversion.
//
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
case EOpEqual:
case EOpNotEqual:
case EOpAdd:
case EOpSub:
case EOpMul:
case EOpDiv:
case EOpMod:
case EOpVectorTimesScalar:
case EOpVectorTimesMatrix:
case EOpMatrixTimesVector:
case EOpMatrixTimesScalar:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpSequence: // used by ?:
if (node0->getBasicType() == node1->getBasicType())
return std::make_tuple(node0, node1);
promoteTo = getConversionDestinationType(node0->getBasicType(), node1->getBasicType(), op);
if (std::get<0>(promoteTo) == EbtNumTypes || std::get<1>(promoteTo) == EbtNumTypes)
return std::make_tuple(nullptr, nullptr);
break;
case EOpLogicalAnd:
case EOpLogicalOr:
case EOpLogicalXor:
if (getSource() == EShSourceHlsl)
promoteTo = std::make_tuple(EbtBool, EbtBool);
else
return std::make_tuple(node0, node1);
break;
// There are no conversions needed for GLSL; the shift amount just needs to be an
// integer type, as does the base.
// HLSL can promote bools to ints to make this work.
case EOpLeftShift:
case EOpRightShift:
if (getSource() == EShSourceHlsl) {
TBasicType node0BasicType = node0->getBasicType();
if (node0BasicType == EbtBool)
node0BasicType = EbtInt;
if (node1->getBasicType() == EbtBool)
promoteTo = std::make_tuple(node0BasicType, EbtInt);
else
promoteTo = std::make_tuple(node0BasicType, node1->getBasicType());
} else {
if (isTypeInt(node0->getBasicType()) && isTypeInt(node1->getBasicType()))
return std::make_tuple(node0, node1);
else
return std::make_tuple(nullptr, nullptr);
}
break;
default:
if (node0->getType() == node1->getType())
return std::make_tuple(node0, node1);
return std::make_tuple(nullptr, nullptr);
}
TIntermTyped* newNode0;
TIntermTyped* newNode1;
if (std::get<0>(promoteTo) != node0->getType().getBasicType()) {
if (node0->getAsConstantUnion())
newNode0 = promoteConstantUnion(std::get<0>(promoteTo), node0->getAsConstantUnion());
else
newNode0 = createConversion(std::get<0>(promoteTo), node0);
} else
newNode0 = node0;
if (std::get<1>(promoteTo) != node1->getType().getBasicType()) {
if (node1->getAsConstantUnion())
newNode1 = promoteConstantUnion(std::get<1>(promoteTo), node1->getAsConstantUnion());
else
newNode1 = createConversion(std::get<1>(promoteTo), node1);
} else
newNode1 = node1;
return std::make_tuple(newNode0, newNode1);
}
//
// Convert the node's type to the given type, as allowed by the operation involved: 'op'.
// For implicit conversions, 'op' is not the requested conversion, it is the explicit
// operation requiring the implicit conversion.
//
// Binary operation conversions should be handled by addConversion(op, node, node), not here.
//
// Returns a node representing the conversion, which could be the same
// node passed in if no conversion was needed.
//
// Generally, this is focused on basic type conversion, not shape conversion.
// See addShapeConversion() for shape conversions.
//
// Return nullptr if a conversion can't be done.
//
TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TIntermTyped* node)
{
if (!isConversionAllowed(op, node))
return nullptr;
// Otherwise, if types are identical, no problem
if (type == node->getType())
return node;
// If one's a structure, then no conversions.
if (type.isStruct() || node->isStruct())
return nullptr;
// If one's an array, then no conversions.
if (type.isArray() || node->getType().isArray())
return nullptr;
// Reject implicit conversions to cooperative matrix types
if (node->getType().isCoopMat() &&
op != EOpConstructCooperativeMatrixNV &&
op != EOpConstructCooperativeMatrixKHR)
return nullptr;
// Note: callers are responsible for other aspects of shape,
// like vector and matrix sizes.
switch (op) {
//
// Explicit conversions (unary operations)
//
case EOpConstructBool:
case EOpConstructFloat:
case EOpConstructInt:
case EOpConstructUint:
case EOpConstructDouble:
case EOpConstructFloat16:
case EOpConstructInt8:
case EOpConstructUint8:
case EOpConstructInt16:
case EOpConstructUint16:
case EOpConstructInt64:
case EOpConstructUint64:
break;
//
// Implicit conversions
//
case EOpLogicalNot:
case EOpFunctionCall:
case EOpReturn:
case EOpAssign:
case EOpAddAssign:
case EOpSubAssign:
case EOpMulAssign:
case EOpVectorTimesScalarAssign:
case EOpMatrixTimesScalarAssign:
case EOpDivAssign:
case EOpModAssign:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
case EOpAtan:
case EOpClamp:
case EOpCross:
case EOpDistance:
case EOpDot:
case EOpDst:
case EOpFaceForward:
case EOpFma:
case EOpFrexp:
case EOpLdexp:
case EOpMix:
case EOpLit:
case EOpMax:
case EOpMin:
case EOpMod:
case EOpModf:
case EOpPow:
case EOpReflect:
case EOpRefract:
case EOpSmoothStep:
case EOpStep:
case EOpSequence:
case EOpConstructStruct:
case EOpConstructCooperativeMatrixNV:
case EOpConstructCooperativeMatrixKHR:
if (type.isReference() || node->getType().isReference()) {
// types must match to assign a reference
if (type == node->getType())
return node;
else
return nullptr;
}
if (type.getBasicType() == node->getType().getBasicType())
return node;
if (! canImplicitlyPromote(node->getBasicType(), type.getBasicType(), op))
return nullptr;
break;
// For GLSL, there are no conversions needed; the shift amount just needs to be an
// integer type, as do the base/result.
// HLSL can convert the shift from a bool to an int.
case EOpLeftShiftAssign:
case EOpRightShiftAssign:
{
if (!(getSource() == EShSourceHlsl && node->getType().getBasicType() == EbtBool)) {
if (isTypeInt(type.getBasicType()) && isTypeInt(node->getBasicType()))
return node;
else
return nullptr;
}
break;
}
default:
// default is to require a match; all exceptions should have case statements above
if (type.getBasicType() == node->getType().getBasicType())
return node;
else
return nullptr;
}
bool canPromoteConstant = true;
// GL_EXT_shader_16bit_storage can't do OpConstantComposite with
// 16-bit types, so disable promotion for those types.
// Many issues with this, from JohnK:
// - this isn't really right to discuss SPIR-V here
// - this could easily be entirely about scalars, so is overstepping
// - we should be looking at what the shader asked for, and saying whether or
// not it can be done, in the parser, by calling requireExtensions(), not
// changing language sementics on the fly by asking what extensions are in use
// - at the time of this writing (14-Aug-2020), no test results are changed by this.
switch (op) {
case EOpConstructFloat16:
canPromoteConstant = numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_float16);
break;
case EOpConstructInt8:
case EOpConstructUint8:
canPromoteConstant = numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_int8);
break;
case EOpConstructInt16:
case EOpConstructUint16:
canPromoteConstant = numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_int16);
break;
default:
break;
}
if (canPromoteConstant && node->getAsConstantUnion())
return promoteConstantUnion(type.getBasicType(), node->getAsConstantUnion());
//
// Add a new newNode for the conversion.
//
TIntermTyped* newNode = createConversion(type.getBasicType(), node);
return newNode;
}
// Convert the node's shape of type for the given type, as allowed by the
// operation involved: 'op'. This is for situations where there is only one
// direction to consider doing the shape conversion.
//
// This implements policy, it call addShapeConversion() for the mechanism.
//
// Generally, the AST represents allowed GLSL shapes, so this isn't needed
// for GLSL. Bad shapes are caught in conversion or promotion.
//
// Return 'node' if no conversion was done. Promotion handles final shape
// checking.
//
TIntermTyped* TIntermediate::addUniShapeConversion(TOperator op, const TType& type, TIntermTyped* node)
{
// some source languages don't do this
switch (getSource()) {
case EShSourceHlsl:
break;
case EShSourceGlsl:
default:
return node;
}
// some operations don't do this
switch (op) {
case EOpFunctionCall:
case EOpReturn:
break;
case EOpMulAssign:
// want to support vector *= scalar native ops in AST and lower, not smear, similarly for
// matrix *= scalar, etc.
case EOpAddAssign:
case EOpSubAssign:
case EOpDivAssign:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
case EOpRightShiftAssign:
case EOpLeftShiftAssign:
if (node->getVectorSize() == 1)
return node;
break;
case EOpAssign:
break;
case EOpMix:
break;
default:
return node;
}
return addShapeConversion(type, node);
}
// Convert the nodes' shapes to be compatible for the operation 'op'.
//
// This implements policy, it call addShapeConversion() for the mechanism.
//
// Generally, the AST represents allowed GLSL shapes, so this isn't needed
// for GLSL. Bad shapes are caught in conversion or promotion.
//
void TIntermediate::addBiShapeConversion(TOperator op, TIntermTyped*& lhsNode, TIntermTyped*& rhsNode)
{
// some source languages don't do this
switch (getSource()) {
case EShSourceHlsl:
break;
case EShSourceGlsl:
default:
return;
}
// some operations don't do this
// 'break' will mean attempt bidirectional conversion
switch (op) {
case EOpMulAssign:
case EOpAssign:
case EOpAddAssign:
case EOpSubAssign:
case EOpDivAssign:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
case EOpRightShiftAssign:
case EOpLeftShiftAssign:
// switch to unidirectional conversion (the lhs can't change)
rhsNode = addUniShapeConversion(op, lhsNode->getType(), rhsNode);
return;
case EOpMul:
// matrix multiply does not change shapes
if (lhsNode->isMatrix() && rhsNode->isMatrix())
return;
[[fallthrough]];
case EOpAdd:
case EOpSub:
case EOpDiv:
// want to support vector * scalar native ops in AST and lower, not smear, similarly for
// matrix * vector, etc.
if (lhsNode->getVectorSize() == 1 || rhsNode->getVectorSize() == 1)
return;
break;
case EOpRightShift:
case EOpLeftShift:
// can natively support the right operand being a scalar and the left a vector,
// but not the reverse
if (rhsNode->getVectorSize() == 1)
return;
break;
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
case EOpEqual:
case EOpNotEqual:
case EOpLogicalAnd:
case EOpLogicalOr:
case EOpLogicalXor:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpMix:
break;
default:
return;
}
// Do bidirectional conversions
if (lhsNode->getType().isScalarOrVec1() || rhsNode->getType().isScalarOrVec1()) {
if (lhsNode->getType().isScalarOrVec1())
lhsNode = addShapeConversion(rhsNode->getType(), lhsNode);
else
rhsNode = addShapeConversion(lhsNode->getType(), rhsNode);
}
lhsNode = addShapeConversion(rhsNode->getType(), lhsNode);
rhsNode = addShapeConversion(lhsNode->getType(), rhsNode);
}
// Convert the node's shape of type for the given type, as allowed by the
// operation involved: 'op'.
//
// Generally, the AST represents allowed GLSL shapes, so this isn't needed
// for GLSL. Bad shapes are caught in conversion or promotion.
//
// Return 'node' if no conversion was done. Promotion handles final shape
// checking.
//
TIntermTyped* TIntermediate::addShapeConversion(const TType& type, TIntermTyped* node)
{
// no conversion needed
if (node->getType() == type)
return node;
// structures and arrays don't change shape, either to or from
if (node->getType().isStruct() || node->getType().isArray() ||
type.isStruct() || type.isArray())
return node;
// The new node that handles the conversion
TOperator constructorOp = mapTypeToConstructorOp(type);
if (getSource() == EShSourceHlsl) {
// HLSL rules for scalar, vector and matrix conversions:
// 1) scalar can become anything, initializing every component with its value
// 2) vector and matrix can become scalar, first element is used (warning: truncation)
// 3) matrix can become matrix with less rows and/or columns (warning: truncation)
// 4) vector can become vector with less rows size (warning: truncation)
// 5a) vector 4 can become 2x2 matrix (special case) (same packing layout, its a reinterpret)
// 5b) 2x2 matrix can become vector 4 (special case) (same packing layout, its a reinterpret)
const TType &sourceType = node->getType();
// rule 1 for scalar to matrix is special
if (sourceType.isScalarOrVec1() && type.isMatrix()) {
// HLSL semantics: the scalar (or vec1) is replicated to every component of the matrix. Left to its
// own devices, the constructor from a scalar would populate the diagonal. This forces replication
// to every matrix element.
// Note that if the node is complex (e.g, a function call), we don't want to duplicate it here
// repeatedly, so we copy it to a temp, then use the temp.
const int matSize = type.computeNumComponents();
TIntermAggregate* rhsAggregate = new TIntermAggregate();
const bool isSimple = (node->getAsSymbolNode() != nullptr) || (node->getAsConstantUnion() != nullptr);
if (!isSimple) {
assert(0); // TODO: use node replicator service when available.
}
for (int x = 0; x < matSize; ++x)
rhsAggregate->getSequence().push_back(node);
return setAggregateOperator(rhsAggregate, constructorOp, type, node->getLoc());
}
// rule 1 and 2
if ((sourceType.isScalar() && !type.isScalar()) || (!sourceType.isScalar() && type.isScalar()))
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
// rule 3 and 5b
if (sourceType.isMatrix()) {
// rule 3
if (type.isMatrix()) {
if ((sourceType.getMatrixCols() != type.getMatrixCols() || sourceType.getMatrixRows() != type.getMatrixRows()) &&
sourceType.getMatrixCols() >= type.getMatrixCols() && sourceType.getMatrixRows() >= type.getMatrixRows())
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
// rule 5b
} else if (type.isVector()) {
if (type.getVectorSize() == 4 && sourceType.getMatrixCols() == 2 && sourceType.getMatrixRows() == 2)
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
}
}
// rule 4 and 5a
if (sourceType.isVector()) {
// rule 4
if (type.isVector())
{
if (sourceType.getVectorSize() > type.getVectorSize())
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
// rule 5a
} else if (type.isMatrix()) {
if (sourceType.getVectorSize() == 4 && type.getMatrixCols() == 2 && type.getMatrixRows() == 2)
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
}
}
}
// scalar -> vector or vec1 -> vector or
// vector -> scalar or
// bigger vector -> smaller vector
if ((node->getType().isScalarOrVec1() && type.isVector()) ||
(node->getType().isVector() && type.isScalar()) ||
(node->isVector() && type.isVector() && node->getVectorSize() > type.getVectorSize()))
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
return node;
}
bool TIntermediate::isIntegralPromotion(TBasicType from, TBasicType to) const
{
// integral promotions
if (to == EbtInt) {
switch(from) {
case EbtInt8:
case EbtInt16:
case EbtUint8:
case EbtUint16:
return true;
default:
break;
}
}
return false;
}
bool TIntermediate::isFPPromotion(TBasicType from, TBasicType to) const
{
// floating-point promotions
if (to == EbtDouble) {
switch(from) {
case EbtFloat16:
case EbtFloat:
return true;
default:
break;
}
}
return false;
}
bool TIntermediate::isIntegralConversion(TBasicType from, TBasicType to) const
{
switch (from) {
case EbtInt:
switch(to) {
case EbtUint:
return version >= 400 || getSource() == EShSourceHlsl;
case EbtInt64:
case EbtUint64:
return true;
default:
break;
}
break;
case EbtUint:
switch(to) {
case EbtInt64:
case EbtUint64:
return true;
default:
break;
}
break;
case EbtInt8:
switch (to) {
case EbtUint8:
case EbtInt16:
case EbtUint16:
case EbtUint:
case EbtInt64:
case EbtUint64:
return true;
default:
break;
}
break;
case EbtUint8:
switch (to) {
case EbtInt16:
case EbtUint16:
case EbtUint:
case EbtInt64:
case EbtUint64:
return true;
default:
break;
}
break;
case EbtInt16:
switch(to) {
case EbtUint16:
case EbtUint:
case EbtInt64:
case EbtUint64:
return true;
default:
break;
}
break;
case EbtUint16:
switch(to) {
case EbtUint:
case EbtInt64:
case EbtUint64:
return true;
default:
break;
}
break;
case EbtInt64:
if (to == EbtUint64) {
return true;
}
break;
default:
break;
}
return false;
}
bool TIntermediate::isFPConversion(TBasicType from, TBasicType to) const
{
if (to == EbtFloat && from == EbtFloat16) {
return true;
} else {
return false;
}
}
bool TIntermediate::isFPIntegralConversion(TBasicType from, TBasicType to) const
{
switch (from) {
case EbtInt:
case EbtUint:
switch(to) {
case EbtFloat:
case EbtDouble:
return true;
default:
break;
}
break;
case EbtInt8:
case EbtUint8:
case EbtInt16:
case EbtUint16:
switch (to) {
case EbtFloat16:
case EbtFloat:
case EbtDouble:
return true;
default:
break;
}
break;
case EbtInt64:
case EbtUint64:
if (to == EbtDouble) {
return true;
}
break;
default:
break;
}
return false;
}
//
// See if the 'from' type is allowed to be implicitly converted to the
// 'to' type. This is not about vector/array/struct, only about basic type.
//
bool TIntermediate::canImplicitlyPromote(TBasicType from, TBasicType to, TOperator op) const
{
if ((isEsProfile() && version < 310 ) || version == 110)
return false;
if (from == to)
return true;
// TODO: Move more policies into language-specific handlers.
// Some languages allow more general (or potentially, more specific) conversions under some conditions.
if (getSource() == EShSourceHlsl) {
const bool fromConvertable = (from == EbtFloat || from == EbtDouble || from == EbtInt || from == EbtUint || from == EbtBool);
const bool toConvertable = (to == EbtFloat || to == EbtDouble || to == EbtInt || to == EbtUint || to == EbtBool);
if (fromConvertable && toConvertable) {
switch (op) {
case EOpAndAssign: // assignments can perform arbitrary conversions
case EOpInclusiveOrAssign: // ...
case EOpExclusiveOrAssign: // ...
case EOpAssign: // ...
case EOpAddAssign: // ...
case EOpSubAssign: // ...
case EOpMulAssign: // ...
case EOpVectorTimesScalarAssign: // ...
case EOpMatrixTimesScalarAssign: // ...
case EOpDivAssign: // ...
case EOpModAssign: // ...
case EOpReturn: // function returns can also perform arbitrary conversions
case EOpFunctionCall: // conversion of a calling parameter
case EOpLogicalNot:
case EOpLogicalAnd:
case EOpLogicalOr:
case EOpLogicalXor:
case EOpConstructStruct:
return true;
default:
break;
}
}
}
if (getSource() == EShSourceHlsl) {
// HLSL
if (from == EbtBool && (to == EbtInt || to == EbtUint || to == EbtFloat))
return true;
} else {
// GLSL
if (isIntegralPromotion(from, to) ||
isFPPromotion(from, to) ||
isIntegralConversion(from, to) ||
isFPConversion(from, to) ||
isFPIntegralConversion(from, to)) {
if (numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_int8) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_int16) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_int32) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_int64) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_float16) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_float32) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_float64)) {
return true;
}
}
}
if (isEsProfile()) {
switch (to) {
case EbtFloat:
switch (from) {
case EbtInt:
case EbtUint:
return numericFeatures.contains(TNumericFeatures::shader_implicit_conversions);
default:
return false;
}
case EbtUint:
switch (from) {
case EbtInt:
return numericFeatures.contains(TNumericFeatures::shader_implicit_conversions);
default:
return false;
}
default:
return false;
}
} else {
switch (to) {
case EbtDouble:
switch (from) {
case EbtInt:
case EbtUint:
case EbtInt64:
case EbtUint64:
case EbtFloat:
return version >= 400 || numericFeatures.contains(TNumericFeatures::gpu_shader_fp64);
case EbtInt16:
case EbtUint16:
return (version >= 400 || numericFeatures.contains(TNumericFeatures::gpu_shader_fp64)) &&
numericFeatures.contains(TNumericFeatures::gpu_shader_int16);
case EbtFloat16:
return (version >= 400 || numericFeatures.contains(TNumericFeatures::gpu_shader_fp64)) &&
numericFeatures.contains(TNumericFeatures::gpu_shader_half_float);
default:
return false;
}
case EbtFloat:
switch (from) {
case EbtInt:
case EbtUint:
return true;
case EbtBool:
return getSource() == EShSourceHlsl;
case EbtInt16:
case EbtUint16:
return numericFeatures.contains(TNumericFeatures::gpu_shader_int16);
case EbtFloat16:
return numericFeatures.contains(TNumericFeatures::gpu_shader_half_float) ||
getSource() == EShSourceHlsl;
default:
return false;
}
case EbtUint:
switch (from) {
case EbtInt:
return version >= 400 || getSource() == EShSourceHlsl || IsRequestedExtension(E_GL_ARB_gpu_shader5);
case EbtBool:
return getSource() == EShSourceHlsl;
case EbtInt16:
case EbtUint16:
return numericFeatures.contains(TNumericFeatures::gpu_shader_int16);
default:
return false;
}
case EbtInt:
switch (from) {
case EbtBool:
return getSource() == EShSourceHlsl;
case EbtInt16:
return numericFeatures.contains(TNumericFeatures::gpu_shader_int16);
default:
return false;
}
case EbtUint64:
switch (from) {
case EbtInt:
case EbtUint:
case EbtInt64:
return true;
case EbtInt16:
case EbtUint16:
return numericFeatures.contains(TNumericFeatures::gpu_shader_int16);
default:
return false;
}
case EbtInt64:
switch (from) {
case EbtInt:
return true;
case EbtInt16:
return numericFeatures.contains(TNumericFeatures::gpu_shader_int16);
default:
return false;
}
case EbtFloat16:
switch (from) {
case EbtInt16:
case EbtUint16:
return numericFeatures.contains(TNumericFeatures::gpu_shader_int16);
default:
break;
}
return false;
case EbtUint16:
switch (from) {
case EbtInt16:
return numericFeatures.contains(TNumericFeatures::gpu_shader_int16);
default:
break;
}
return false;
default:
return false;
}
}
return false;
}
static bool canSignedIntTypeRepresentAllUnsignedValues(TBasicType sintType, TBasicType uintType)
{
switch(sintType) {
case EbtInt8:
switch(uintType) {
case EbtUint8:
case EbtUint16:
case EbtUint:
case EbtUint64:
return false;
default:
assert(false);
return false;
}
break;
case EbtInt16:
switch(uintType) {
case EbtUint8:
return true;
case EbtUint16:
case EbtUint:
case EbtUint64:
return false;
default:
assert(false);
return false;
}
break;
case EbtInt:
switch(uintType) {
case EbtUint8:
case EbtUint16:
return true;
case EbtUint:
return false;
default:
assert(false);
return false;
}
break;
case EbtInt64:
switch(uintType) {
case EbtUint8:
case EbtUint16:
case EbtUint:
return true;
case EbtUint64:
return false;
default:
assert(false);
return false;
}
break;
default:
assert(false);
return false;
}
}
static TBasicType getCorrespondingUnsignedType(TBasicType type)
{
switch(type) {
case EbtInt8:
return EbtUint8;
case EbtInt16:
return EbtUint16;
case EbtInt:
return EbtUint;
case EbtInt64:
return EbtUint64;
default:
assert(false);
return EbtNumTypes;
}
}
// Implements the following rules
// - If either operand has type float64_t or derived from float64_t,
// the other shall be converted to float64_t or derived type.
// - Otherwise, if either operand has type float32_t or derived from
// float32_t, the other shall be converted to float32_t or derived type.
// - Otherwise, if either operand has type float16_t or derived from
// float16_t, the other shall be converted to float16_t or derived type.
// - Otherwise, if both operands have integer types the following rules
// shall be applied to the operands:
// - If both operands have the same type, no further conversion
// is needed.
// - Otherwise, if both operands have signed integer types or both
// have unsigned integer types, the operand with the type of lesser
// integer conversion rank shall be converted to the type of the
// operand with greater rank.
// - Otherwise, if the operand that has unsigned integer type has rank
// greater than or equal to the rank of the type of the other
// operand, the operand with signed integer type shall be converted
// to the type of the operand with unsigned integer type.
// - Otherwise, if the type of the operand with signed integer type can
// represent all of the values of the type of the operand with
// unsigned integer type, the operand with unsigned integer type
// shall be converted to the type of the operand with signed
// integer type.
// - Otherwise, both operands shall be converted to the unsigned
// integer type corresponding to the type of the operand with signed
// integer type.
std::tuple<TBasicType, TBasicType> TIntermediate::getConversionDestinationType(TBasicType type0, TBasicType type1, TOperator op) const
{
TBasicType res0 = EbtNumTypes;
TBasicType res1 = EbtNumTypes;
if ((isEsProfile() &&
(version < 310 || !numericFeatures.contains(TNumericFeatures::shader_implicit_conversions))) ||
version == 110)
return std::make_tuple(res0, res1);
if (getSource() == EShSourceHlsl) {
if (canImplicitlyPromote(type1, type0, op)) {
res0 = type0;
res1 = type0;
} else if (canImplicitlyPromote(type0, type1, op)) {
res0 = type1;
res1 = type1;
}
return std::make_tuple(res0, res1);
}
if ((type0 == EbtDouble && canImplicitlyPromote(type1, EbtDouble, op)) ||
(type1 == EbtDouble && canImplicitlyPromote(type0, EbtDouble, op)) ) {
res0 = EbtDouble;
res1 = EbtDouble;
} else if ((type0 == EbtFloat && canImplicitlyPromote(type1, EbtFloat, op)) ||
(type1 == EbtFloat && canImplicitlyPromote(type0, EbtFloat, op)) ) {
res0 = EbtFloat;
res1 = EbtFloat;
} else if ((type0 == EbtFloat16 && canImplicitlyPromote(type1, EbtFloat16, op)) ||
(type1 == EbtFloat16 && canImplicitlyPromote(type0, EbtFloat16, op)) ) {
res0 = EbtFloat16;
res1 = EbtFloat16;
} else if (isTypeInt(type0) && isTypeInt(type1) &&
(canImplicitlyPromote(type0, type1, op) || canImplicitlyPromote(type1, type0, op))) {
if ((isTypeSignedInt(type0) && isTypeSignedInt(type1)) ||
(isTypeUnsignedInt(type0) && isTypeUnsignedInt(type1))) {
if (getTypeRank(type0) < getTypeRank(type1)) {
res0 = type1;
res1 = type1;
} else {
res0 = type0;
res1 = type0;
}
} else if (isTypeUnsignedInt(type0) && (getTypeRank(type0) > getTypeRank(type1))) {
res0 = type0;
res1 = type0;
} else if (isTypeUnsignedInt(type1) && (getTypeRank(type1) > getTypeRank(type0))) {
res0 = type1;
res1 = type1;
} else if (isTypeSignedInt(type0)) {
if (canSignedIntTypeRepresentAllUnsignedValues(type0, type1)) {
res0 = type0;
res1 = type0;
} else {
res0 = getCorrespondingUnsignedType(type0);
res1 = getCorrespondingUnsignedType(type0);
}
} else if (isTypeSignedInt(type1)) {
if (canSignedIntTypeRepresentAllUnsignedValues(type1, type0)) {
res0 = type1;
res1 = type1;
} else {
res0 = getCorrespondingUnsignedType(type1);
res1 = getCorrespondingUnsignedType(type1);
}
}
}
return std::make_tuple(res0, res1);
}
//
// Given a type, find what operation would fully construct it.
//
TOperator TIntermediate::mapTypeToConstructorOp(const TType& type) const
{
TOperator op = EOpNull;
if (type.getQualifier().isNonUniform())
return EOpConstructNonuniform;
if (type.isCoopMatNV())
return EOpConstructCooperativeMatrixNV;
if (type.isCoopMatKHR())
return EOpConstructCooperativeMatrixKHR;
switch (type.getBasicType()) {
case EbtStruct:
op = EOpConstructStruct;
break;
case EbtSampler:
if (type.getSampler().isCombined())
op = EOpConstructTextureSampler;
break;
case EbtFloat:
if (type.isMatrix()) {
switch (type.getMatrixCols()) {
case 2:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructMat2x2; break;
case 3: op = EOpConstructMat2x3; break;
case 4: op = EOpConstructMat2x4; break;
default: break; // some compilers want this
}
break;
case 3:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructMat3x2; break;
case 3: op = EOpConstructMat3x3; break;
case 4: op = EOpConstructMat3x4; break;
default: break; // some compilers want this
}
break;
case 4:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructMat4x2; break;
case 3: op = EOpConstructMat4x3; break;
case 4: op = EOpConstructMat4x4; break;
default: break; // some compilers want this
}
break;
default: break; // some compilers want this
}
} else {
switch(type.getVectorSize()) {
case 1: op = EOpConstructFloat; break;
case 2: op = EOpConstructVec2; break;
case 3: op = EOpConstructVec3; break;
case 4: op = EOpConstructVec4; break;
default: break; // some compilers want this
}
}
break;
case EbtInt:
if (type.getMatrixCols()) {
switch (type.getMatrixCols()) {
case 2:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructIMat2x2; break;
case 3: op = EOpConstructIMat2x3; break;
case 4: op = EOpConstructIMat2x4; break;
default: break; // some compilers want this
}
break;
case 3:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructIMat3x2; break;
case 3: op = EOpConstructIMat3x3; break;
case 4: op = EOpConstructIMat3x4; break;
default: break; // some compilers want this
}
break;
case 4:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructIMat4x2; break;
case 3: op = EOpConstructIMat4x3; break;
case 4: op = EOpConstructIMat4x4; break;
default: break; // some compilers want this
}
break;
}
} else {
switch(type.getVectorSize()) {
case 1: op = EOpConstructInt; break;
case 2: op = EOpConstructIVec2; break;
case 3: op = EOpConstructIVec3; break;
case 4: op = EOpConstructIVec4; break;
default: break; // some compilers want this
}
}
break;
case EbtUint:
if (type.getMatrixCols()) {
switch (type.getMatrixCols()) {
case 2:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructUMat2x2; break;
case 3: op = EOpConstructUMat2x3; break;
case 4: op = EOpConstructUMat2x4; break;
default: break; // some compilers want this
}
break;
case 3:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructUMat3x2; break;
case 3: op = EOpConstructUMat3x3; break;
case 4: op = EOpConstructUMat3x4; break;
default: break; // some compilers want this
}
break;
case 4:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructUMat4x2; break;
case 3: op = EOpConstructUMat4x3; break;
case 4: op = EOpConstructUMat4x4; break;
default: break; // some compilers want this
}
break;
}
} else {
switch(type.getVectorSize()) {
case 1: op = EOpConstructUint; break;
case 2: op = EOpConstructUVec2; break;
case 3: op = EOpConstructUVec3; break;
case 4: op = EOpConstructUVec4; break;
default: break; // some compilers want this
}
}
break;
case EbtBool:
if (type.getMatrixCols()) {
switch (type.getMatrixCols()) {
case 2:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructBMat2x2; break;
case 3: op = EOpConstructBMat2x3; break;
case 4: op = EOpConstructBMat2x4; break;
default: break; // some compilers want this
}
break;
case 3:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructBMat3x2; break;
case 3: op = EOpConstructBMat3x3; break;
case 4: op = EOpConstructBMat3x4; break;
default: break; // some compilers want this
}
break;
case 4:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructBMat4x2; break;
case 3: op = EOpConstructBMat4x3; break;
case 4: op = EOpConstructBMat4x4; break;
default: break; // some compilers want this
}
break;
}
} else {
switch(type.getVectorSize()) {
case 1: op = EOpConstructBool; break;
case 2: op = EOpConstructBVec2; break;
case 3: op = EOpConstructBVec3; break;
case 4: op = EOpConstructBVec4; break;
default: break; // some compilers want this
}
}
break;
case EbtDouble:
if (type.getMatrixCols()) {
switch (type.getMatrixCols()) {
case 2:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructDMat2x2; break;
case 3: op = EOpConstructDMat2x3; break;
case 4: op = EOpConstructDMat2x4; break;
default: break; // some compilers want this
}
break;
case 3:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructDMat3x2; break;
case 3: op = EOpConstructDMat3x3; break;
case 4: op = EOpConstructDMat3x4; break;
default: break; // some compilers want this
}
break;
case 4:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructDMat4x2; break;
case 3: op = EOpConstructDMat4x3; break;
case 4: op = EOpConstructDMat4x4; break;
default: break; // some compilers want this
}
break;
}
} else {
switch(type.getVectorSize()) {
case 1: op = EOpConstructDouble; break;
case 2: op = EOpConstructDVec2; break;
case 3: op = EOpConstructDVec3; break;
case 4: op = EOpConstructDVec4; break;
default: break; // some compilers want this
}
}
break;
case EbtFloat16:
if (type.getMatrixCols()) {
switch (type.getMatrixCols()) {
case 2:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructF16Mat2x2; break;
case 3: op = EOpConstructF16Mat2x3; break;
case 4: op = EOpConstructF16Mat2x4; break;
default: break; // some compilers want this
}
break;
case 3:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructF16Mat3x2; break;
case 3: op = EOpConstructF16Mat3x3; break;
case 4: op = EOpConstructF16Mat3x4; break;
default: break; // some compilers want this
}
break;
case 4:
switch (type.getMatrixRows()) {
case 2: op = EOpConstructF16Mat4x2; break;
case 3: op = EOpConstructF16Mat4x3; break;
case 4: op = EOpConstructF16Mat4x4; break;
default: break; // some compilers want this
}
break;
}
}
else {
switch (type.getVectorSize()) {
case 1: op = EOpConstructFloat16; break;
case 2: op = EOpConstructF16Vec2; break;
case 3: op = EOpConstructF16Vec3; break;
case 4: op = EOpConstructF16Vec4; break;
default: break; // some compilers want this
}
}
break;
case EbtInt8:
switch(type.getVectorSize()) {
case 1: op = EOpConstructInt8; break;
case 2: op = EOpConstructI8Vec2; break;
case 3: op = EOpConstructI8Vec3; break;
case 4: op = EOpConstructI8Vec4; break;
default: break; // some compilers want this
}
break;
case EbtUint8:
switch(type.getVectorSize()) {
case 1: op = EOpConstructUint8; break;
case 2: op = EOpConstructU8Vec2; break;
case 3: op = EOpConstructU8Vec3; break;
case 4: op = EOpConstructU8Vec4; break;
default: break; // some compilers want this
}
break;
case EbtInt16:
switch(type.getVectorSize()) {
case 1: op = EOpConstructInt16; break;
case 2: op = EOpConstructI16Vec2; break;
case 3: op = EOpConstructI16Vec3; break;
case 4: op = EOpConstructI16Vec4; break;
default: break; // some compilers want this
}
break;
case EbtUint16:
switch(type.getVectorSize()) {
case 1: op = EOpConstructUint16; break;
case 2: op = EOpConstructU16Vec2; break;
case 3: op = EOpConstructU16Vec3; break;
case 4: op = EOpConstructU16Vec4; break;
default: break; // some compilers want this
}
break;
case EbtInt64:
switch(type.getVectorSize()) {
case 1: op = EOpConstructInt64; break;
case 2: op = EOpConstructI64Vec2; break;
case 3: op = EOpConstructI64Vec3; break;
case 4: op = EOpConstructI64Vec4; break;
default: break; // some compilers want this
}
break;
case EbtUint64:
switch(type.getVectorSize()) {
case 1: op = EOpConstructUint64; break;
case 2: op = EOpConstructU64Vec2; break;
case 3: op = EOpConstructU64Vec3; break;
case 4: op = EOpConstructU64Vec4; break;
default: break; // some compilers want this
}
break;
case EbtReference:
op = EOpConstructReference;
break;
case EbtAccStruct:
op = EOpConstructAccStruct;
break;
default:
break;
}
return op;
}
//
// Safe way to combine two nodes into an aggregate. Works with null pointers,
// a node that's not a aggregate yet, etc.
//
// Returns the resulting aggregate, unless nullptr was passed in for
// both existing nodes.
//
TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* right)
{
if (left == nullptr && right == nullptr)
return nullptr;
TIntermAggregate* aggNode = nullptr;
if (left != nullptr)
aggNode = left->getAsAggregate();
if (aggNode == nullptr || aggNode->getOp() != EOpNull) {
aggNode = new TIntermAggregate;
if (left != nullptr)
aggNode->getSequence().push_back(left);
}
if (right != nullptr)
aggNode->getSequence().push_back(right);
return aggNode;
}
TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc& loc)
{
TIntermAggregate* aggNode = growAggregate(left, right);
if (aggNode)
aggNode->setLoc(loc);
return aggNode;
}
TIntermAggregate* TIntermediate::mergeAggregate(TIntermNode* left, TIntermNode* right)
{
if (left == nullptr && right == nullptr)
return nullptr;
TIntermAggregate* aggNode = nullptr;
if (left != nullptr)
aggNode = left->getAsAggregate();
if (aggNode == nullptr || aggNode->getOp() != EOpNull) {
aggNode = new TIntermAggregate;
if (left != nullptr)
aggNode->getSequence().push_back(left);
}
TIntermAggregate* rhsagg = right->getAsAggregate();
if (rhsagg == nullptr || rhsagg->getOp() != EOpNull)
aggNode->getSequence().push_back(right);
else
aggNode->getSequence().insert(aggNode->getSequence().end(),
rhsagg->getSequence().begin(),
rhsagg->getSequence().end());
return aggNode;
}
TIntermAggregate* TIntermediate::mergeAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc& loc)
{
TIntermAggregate* aggNode = mergeAggregate(left, right);
if (aggNode)
aggNode->setLoc(loc);
return aggNode;
}
//
// Turn an existing node into an aggregate.
//
// Returns an aggregate, unless nullptr was passed in for the existing node.
//
TIntermAggregate* TIntermediate::makeAggregate(TIntermNode* node)
{
if (node == nullptr)
return nullptr;
TIntermAggregate* aggNode = new TIntermAggregate;
aggNode->getSequence().push_back(node);
aggNode->setLoc(node->getLoc());
return aggNode;
}
TIntermAggregate* TIntermediate::makeAggregate(TIntermNode* node, const TSourceLoc& loc)
{
if (node == nullptr)
return nullptr;
TIntermAggregate* aggNode = new TIntermAggregate;
aggNode->getSequence().push_back(node);
aggNode->setLoc(loc);
return aggNode;
}
//
// Make an aggregate with an empty sequence.
//
TIntermAggregate* TIntermediate::makeAggregate(const TSourceLoc& loc)
{
TIntermAggregate* aggNode = new TIntermAggregate;
aggNode->setLoc(loc);
return aggNode;
}
//
// For "if" test nodes. There are three children; a condition,
// a true path, and a false path. The two paths are in the
// nodePair.
//
// Returns the selection node created.
//
TIntermSelection* TIntermediate::addSelection(TIntermTyped* cond, TIntermNodePair nodePair, const TSourceLoc& loc)
{
//
// Don't prune the false path for compile-time constants; it's needed
// for static access analysis.
//
TIntermSelection* node = new TIntermSelection(cond, nodePair.node1, nodePair.node2);
node->setLoc(loc);
return node;
}
TIntermTyped* TIntermediate::addComma(TIntermTyped* left, TIntermTyped* right, const TSourceLoc& loc)
{
// However, the lowest precedence operators of the sequence operator ( , ) and the assignment operators
// ... are not included in the operators that can create a constant expression.
//
// if (left->getType().getQualifier().storage == EvqConst &&
// right->getType().getQualifier().storage == EvqConst) {
// return right;
//}
TIntermTyped *commaAggregate = growAggregate(left, right, loc);
commaAggregate->getAsAggregate()->setOperator(EOpComma);
commaAggregate->setType(right->getType());
commaAggregate->getWritableType().getQualifier().makeTemporary();
return commaAggregate;
}
TIntermTyped* TIntermediate::addMethod(TIntermTyped* object, const TType& type, const TString* name, const TSourceLoc& loc)
{
TIntermMethod* method = new TIntermMethod(object, type, *name);
method->setLoc(loc);
return method;
}
//
// For "?:" test nodes. There are three children; a condition,
// a true path, and a false path. The two paths are specified
// as separate parameters. For vector 'cond', the true and false
// are not paths, but vectors to mix.
//
// Specialization constant operations include
// - The ternary operator ( ? : )
//
// Returns the selection node created, or nullptr if one could not be.
//
TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock,
const TSourceLoc& loc)
{
// If it's void, go to the if-then-else selection()
if (trueBlock->getBasicType() == EbtVoid && falseBlock->getBasicType() == EbtVoid) {
TIntermNodePair pair = { trueBlock, falseBlock };
TIntermSelection* selection = addSelection(cond, pair, loc);
if (getSource() == EShSourceHlsl)
selection->setNoShortCircuit();
return selection;
}
//
// Get compatible types.
//
auto children = addPairConversion(EOpSequence, trueBlock, falseBlock);
trueBlock = std::get<0>(children);
falseBlock = std::get<1>(children);
if (trueBlock == nullptr || falseBlock == nullptr)
return nullptr;
// Handle a vector condition as a mix
if (!cond->getType().isScalarOrVec1()) {
TType targetVectorType(trueBlock->getType().getBasicType(), EvqTemporary,
cond->getType().getVectorSize());
// smear true/false operands as needed
trueBlock = addUniShapeConversion(EOpMix, targetVectorType, trueBlock);
falseBlock = addUniShapeConversion(EOpMix, targetVectorType, falseBlock);
// After conversion, types have to match.
if (falseBlock->getType() != trueBlock->getType())
return nullptr;
// make the mix operation
TIntermAggregate* mix = makeAggregate(loc);
mix = growAggregate(mix, falseBlock);
mix = growAggregate(mix, trueBlock);
mix = growAggregate(mix, cond);
mix->setType(targetVectorType);
mix->setOp(EOpMix);
return mix;
}
// Now have a scalar condition...
// Convert true and false expressions to matching types
addBiShapeConversion(EOpMix, trueBlock, falseBlock);
// After conversion, types have to match.
if (falseBlock->getType() != trueBlock->getType())
return nullptr;
// Eliminate the selection when the condition is a scalar and all operands are constant.
if (cond->getAsConstantUnion() && trueBlock->getAsConstantUnion() && falseBlock->getAsConstantUnion()) {
if (cond->getAsConstantUnion()->getConstArray()[0].getBConst())
return trueBlock;
else
return falseBlock;
}
//
// Make a selection node.
//
TIntermSelection* node = new TIntermSelection(cond, trueBlock, falseBlock, trueBlock->getType());
node->setLoc(loc);
node->getQualifier().precision = std::max(trueBlock->getQualifier().precision, falseBlock->getQualifier().precision);
if ((cond->getQualifier().isConstant() && specConstantPropagates(*trueBlock, *falseBlock)) ||
(cond->getQualifier().isSpecConstant() && trueBlock->getQualifier().isConstant() &&
falseBlock->getQualifier().isConstant()))
node->getQualifier().makeSpecConstant();
else
node->getQualifier().makeTemporary();
if (getSource() == EShSourceHlsl)
node->setNoShortCircuit();
return node;
}
//
// Constant terminal nodes. Has a union that contains bool, float or int constants
//
// Returns the constant union node created.
//
TIntermConstantUnion* TIntermediate::addConstantUnion(const TConstUnionArray& unionArray, const TType& t, const TSourceLoc& loc, bool literal) const
{
TIntermConstantUnion* node = new TIntermConstantUnion(unionArray, t);
node->getQualifier().storage = EvqConst;
node->setLoc(loc);
if (literal)
node->setLiteral();
return node;
}
TIntermConstantUnion* TIntermediate::addConstantUnion(signed char i8, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setI8Const(i8);
return addConstantUnion(unionArray, TType(EbtInt8, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(unsigned char u8, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setUConst(u8);
return addConstantUnion(unionArray, TType(EbtUint8, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(signed short i16, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setI16Const(i16);
return addConstantUnion(unionArray, TType(EbtInt16, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(unsigned short u16, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setU16Const(u16);
return addConstantUnion(unionArray, TType(EbtUint16, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(int i, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setIConst(i);
return addConstantUnion(unionArray, TType(EbtInt, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(unsigned int u, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setUConst(u);
return addConstantUnion(unionArray, TType(EbtUint, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(long long i64, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setI64Const(i64);
return addConstantUnion(unionArray, TType(EbtInt64, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(unsigned long long u64, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setU64Const(u64);
return addConstantUnion(unionArray, TType(EbtUint64, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(bool b, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setBConst(b);
return addConstantUnion(unionArray, TType(EbtBool, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(double d, TBasicType baseType, const TSourceLoc& loc, bool literal) const
{
assert(baseType == EbtFloat || baseType == EbtDouble || baseType == EbtFloat16);
if (isEsProfile() && (baseType == EbtFloat || baseType == EbtFloat16)) {
int exponent = 0;
frexp(d, &exponent);
int minExp = baseType == EbtFloat ? -126 : -14;
int maxExp = baseType == EbtFloat ? 127 : 15;
if (exponent > maxExp) { //overflow, d = inf
d = std::numeric_limits<double>::infinity();
} else if (exponent < minExp) { //underflow, d = 0.0;
d = 0.0;
}
}
TConstUnionArray unionArray(1);
unionArray[0].setDConst(d);
return addConstantUnion(unionArray, TType(baseType, EvqConst), loc, literal);
}
TIntermConstantUnion* TIntermediate::addConstantUnion(const TString* s, const TSourceLoc& loc, bool literal) const
{
TConstUnionArray unionArray(1);
unionArray[0].setSConst(s);
return addConstantUnion(unionArray, TType(EbtString, EvqConst), loc, literal);
}
// Put vector swizzle selectors onto the given sequence
void TIntermediate::pushSelector(TIntermSequence& sequence, const TVectorSelector& selector, const TSourceLoc& loc)
{
TIntermConstantUnion* constIntNode = addConstantUnion(selector, loc);
sequence.push_back(constIntNode);
}
// Put matrix swizzle selectors onto the given sequence
void TIntermediate::pushSelector(TIntermSequence& sequence, const TMatrixSelector& selector, const TSourceLoc& loc)
{
TIntermConstantUnion* constIntNode = addConstantUnion(selector.coord1, loc);
sequence.push_back(constIntNode);
constIntNode = addConstantUnion(selector.coord2, loc);
sequence.push_back(constIntNode);
}
// Make an aggregate node that has a sequence of all selectors.
template TIntermTyped* TIntermediate::addSwizzle<TVectorSelector>(TSwizzleSelectors<TVectorSelector>& selector, const TSourceLoc& loc);
template TIntermTyped* TIntermediate::addSwizzle<TMatrixSelector>(TSwizzleSelectors<TMatrixSelector>& selector, const TSourceLoc& loc);
template<typename selectorType>
TIntermTyped* TIntermediate::addSwizzle(TSwizzleSelectors<selectorType>& selector, const TSourceLoc& loc)
{
TIntermAggregate* node = new TIntermAggregate(EOpSequence);
node->setLoc(loc);
TIntermSequence &sequenceVector = node->getSequence();
for (int i = 0; i < selector.size(); i++)
pushSelector(sequenceVector, selector[i], loc);
return node;
}
//
// Follow the left branches down to the root of an l-value
// expression (just "." and []).
//
// Return the base of the l-value (where following indexing quits working).
// Return nullptr if a chain following dereferences cannot be followed.
//
// 'swizzleOkay' says whether or not it is okay to consider a swizzle
// a valid part of the dereference chain.
//
// 'bufferReferenceOk' says if type is buffer_reference, the routine will stop to find the most left node.
//
// 'proc' is an optional function to run on each node that is processed during the traversal. 'proc' must
// return true to continue the traversal, or false to end the traversal early.
//
const TIntermTyped* TIntermediate::traverseLValueBase(const TIntermTyped* node, bool swizzleOkay,
bool bufferReferenceOk,
std::function<bool(const TIntermNode&)> proc)
{
do {
const TIntermBinary* binary = node->getAsBinaryNode();
if (binary == nullptr) {
if (proc) {
proc(*node);
}
return node;
}
TOperator op = binary->getOp();
if (op != EOpIndexDirect && op != EOpIndexIndirect && op != EOpIndexDirectStruct && op != EOpVectorSwizzle &&
op != EOpMatrixSwizzle)
return nullptr;
if (!swizzleOkay) {
if (op == EOpVectorSwizzle || op == EOpMatrixSwizzle)
return nullptr;
if ((op == EOpIndexDirect || op == EOpIndexIndirect) &&
(binary->getLeft()->getType().isVector() || binary->getLeft()->getType().isScalar()) &&
!binary->getLeft()->getType().isArray())
return nullptr;
}
if (proc) {
if (!proc(*node)) {
return node;
}
}
node = binary->getLeft();
if (bufferReferenceOk && node->isReference())
return node;
} while (true);
}
//
// Create while and do-while loop nodes.
//
TIntermLoop* TIntermediate::addLoop(TIntermNode* body, TIntermTyped* test, TIntermTyped* terminal, bool testFirst,
const TSourceLoc& loc)
{
TIntermLoop* node = new TIntermLoop(body, test, terminal, testFirst);
node->setLoc(loc);
return node;
}
//
// Create a for-loop sequence.
//
TIntermAggregate* TIntermediate::addForLoop(TIntermNode* body, TIntermNode* initializer, TIntermTyped* test,
TIntermTyped* terminal, bool testFirst, const TSourceLoc& loc, TIntermLoop*& node)
{
node = new TIntermLoop(body, test, terminal, testFirst);
node->setLoc(loc);
// make a sequence of the initializer and statement, but try to reuse the
// aggregate already created for whatever is in the initializer, if there is one
TIntermAggregate* loopSequence = (initializer == nullptr ||
initializer->getAsAggregate() == nullptr) ? makeAggregate(initializer, loc)
: initializer->getAsAggregate();
if (loopSequence != nullptr && (loopSequence->getOp() == EOpSequence || loopSequence->getOp() == EOpScope))
loopSequence->setOp(EOpNull);
loopSequence = growAggregate(loopSequence, node);
loopSequence->setOperator(getDebugInfo() ? EOpScope : EOpSequence);
return loopSequence;
}
//
// Add branches.
//
TIntermBranch* TIntermediate::addBranch(TOperator branchOp, const TSourceLoc& loc)
{
return addBranch(branchOp, nullptr, loc);
}
TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TIntermTyped* expression, const TSourceLoc& loc)
{
TIntermBranch* node = new TIntermBranch(branchOp, expression);
node->setLoc(loc);
return node;
}
// Propagate precision from formal function return type to actual return type,
// and on to its subtree.
void TIntermBranch::updatePrecision(TPrecisionQualifier parentPrecision)
{
TIntermTyped* exp = getExpression();
if (exp == nullptr)
return;
if (exp->getBasicType() == EbtInt || exp->getBasicType() == EbtUint ||
exp->getBasicType() == EbtFloat) {
if (parentPrecision != EpqNone && exp->getQualifier().precision == EpqNone) {
exp->propagatePrecision(parentPrecision);
}
}
}
//
// This is to be executed after the final root is put on top by the parsing
// process.
//
bool TIntermediate::postProcess(TIntermNode* root, EShLanguage /*language*/)
{
if (root == nullptr)
return true;
// Finish off the top-level sequence
TIntermAggregate* aggRoot = root->getAsAggregate();
if (aggRoot && aggRoot->getOp() == EOpNull)
aggRoot->setOperator(EOpSequence);
// Propagate 'noContraction' label in backward from 'precise' variables.
glslang::PropagateNoContraction(*this);
switch (textureSamplerTransformMode) {
case EShTexSampTransKeep:
break;
case EShTexSampTransUpgradeTextureRemoveSampler:
performTextureUpgradeAndSamplerRemovalTransformation(root);
break;
case EShTexSampTransCount:
assert(0);
break;
}
return true;
}
void TIntermediate::addSymbolLinkageNodes(TIntermAggregate*& linkage, EShLanguage language, TSymbolTable& symbolTable)
{
// Add top-level nodes for declarations that must be checked cross
// compilation unit by a linker, yet might not have been referenced
// by the AST.
//
// Almost entirely, translation of symbols is driven by what's present
// in the AST traversal, not by translating the symbol table.
//
// However, there are some special cases:
// - From the specification: "Special built-in inputs gl_VertexID and
// gl_InstanceID are also considered active vertex attributes."
// - Linker-based type mismatch error reporting needs to see all
// uniforms/ins/outs variables and blocks.
// - ftransform() can make gl_Vertex and gl_ModelViewProjectionMatrix active.
//
// if (ftransformUsed) {
// TODO: 1.1 lowering functionality: track ftransform() usage
// addSymbolLinkageNode(root, symbolTable, "gl_Vertex");
// addSymbolLinkageNode(root, symbolTable, "gl_ModelViewProjectionMatrix");
//}
if (language == EShLangVertex) {
addSymbolLinkageNode(linkage, symbolTable, "gl_VertexID");
if ((version < 140 && requestedExtensions.find(E_GL_EXT_draw_instanced) != requestedExtensions.end()) || version >= 140)
addSymbolLinkageNode(linkage, symbolTable, "gl_InstanceID");
}
// Add a child to the root node for the linker objects
linkage->setOperator(EOpLinkerObjects);
treeRoot = growAggregate(treeRoot, linkage);
}
//
// Add the given name or symbol to the list of nodes at the end of the tree used
// for link-time checking and external linkage.
//
void TIntermediate::addSymbolLinkageNode(TIntermAggregate*& linkage, TSymbolTable& symbolTable, const TString& name)
{
TSymbol* symbol = symbolTable.find(name);
if (symbol)
addSymbolLinkageNode(linkage, *symbol->getAsVariable());
}
void TIntermediate::addSymbolLinkageNode(TIntermAggregate*& linkage, const TSymbol& symbol)
{
const TVariable* variable = symbol.getAsVariable();
if (! variable) {
// This must be a member of an anonymous block, and we need to add the whole block
const TAnonMember* anon = symbol.getAsAnonMember();
variable = &anon->getAnonContainer();
}
TIntermSymbol* node = addSymbol(*variable);
linkage = growAggregate(linkage, node);
}
//
// Add a caller->callee relationship to the call graph.
// Assumes the strings are unique per signature.
//
void TIntermediate::addToCallGraph(TInfoSink& /*infoSink*/, const TString& caller, const TString& callee)
{
// Duplicates are okay, but faster to not keep them, and they come grouped by caller,
// as long as new ones are push on the same end we check on for duplicates
for (TGraph::const_iterator call = callGraph.begin(); call != callGraph.end(); ++call) {
if (call->caller != caller)
break;
if (call->callee == callee)
return;
}
callGraph.emplace_front(caller, callee);
}
//
// This deletes the tree.
//
void TIntermediate::removeTree()
{
if (treeRoot)
RemoveAllTreeNodes(treeRoot);
}
//
// Implement the part of KHR_vulkan_glsl that lists the set of operations
// that can result in a specialization constant operation.
//
// "5.x Specialization Constant Operations"
//
// Only some operations discussed in this section may be applied to a
// specialization constant and still yield a result that is as
// specialization constant. The operations allowed are listed below.
// When a specialization constant is operated on with one of these
// operators and with another constant or specialization constant, the
// result is implicitly a specialization constant.
//
// - int(), uint(), and bool() constructors for type conversions
// from any of the following types to any of the following types:
// * int
// * uint
// * bool
// - vector versions of the above conversion constructors
// - allowed implicit conversions of the above
// - swizzles (e.g., foo.yx)
// - The following when applied to integer or unsigned integer types:
// * unary negative ( - )
// * binary operations ( + , - , * , / , % )
// * shift ( <<, >> )
// * bitwise operations ( & , | , ^ )
// - The following when applied to integer or unsigned integer scalar types:
// * comparison ( == , != , > , >= , < , <= )
// - The following when applied to the Boolean scalar type:
// * not ( ! )
// * logical operations ( && , || , ^^ )
// * comparison ( == , != )"
//
// This function just handles binary and unary nodes. Construction
// rules are handled in construction paths that are not covered by the unary
// and binary paths, while required conversions will still show up here
// as unary converters in the from a construction operator.
//
bool TIntermediate::isSpecializationOperation(const TIntermOperator& node) const
{
// The operations resulting in floating point are quite limited
// (However, some floating-point operations result in bool, like ">",
// so are handled later.)
if (node.getType().isFloatingDomain()) {
switch (node.getOp()) {
case EOpIndexDirect:
case EOpIndexIndirect:
case EOpIndexDirectStruct:
case EOpVectorSwizzle:
case EOpConvFloatToDouble:
case EOpConvDoubleToFloat:
case EOpConvFloat16ToFloat:
case EOpConvFloatToFloat16:
case EOpConvFloat16ToDouble:
case EOpConvDoubleToFloat16:
return true;
default:
return false;
}
}
// Check for floating-point arguments
if (const TIntermBinary* bin = node.getAsBinaryNode())
if (bin->getLeft() ->getType().isFloatingDomain() ||
bin->getRight()->getType().isFloatingDomain())
return false;
// So, for now, we can assume everything left is non-floating-point...
// Now check for integer/bool-based operations
switch (node.getOp()) {
// dereference/swizzle
case EOpIndexDirect:
case EOpIndexIndirect:
case EOpIndexDirectStruct:
case EOpVectorSwizzle:
// (u)int* -> bool
case EOpConvInt8ToBool:
case EOpConvInt16ToBool:
case EOpConvIntToBool:
case EOpConvInt64ToBool:
case EOpConvUint8ToBool:
case EOpConvUint16ToBool:
case EOpConvUintToBool:
case EOpConvUint64ToBool:
// bool -> (u)int*
case EOpConvBoolToInt8:
case EOpConvBoolToInt16:
case EOpConvBoolToInt:
case EOpConvBoolToInt64:
case EOpConvBoolToUint8:
case EOpConvBoolToUint16:
case EOpConvBoolToUint:
case EOpConvBoolToUint64:
// int8_t -> (u)int*
case EOpConvInt8ToInt16:
case EOpConvInt8ToInt:
case EOpConvInt8ToInt64:
case EOpConvInt8ToUint8:
case EOpConvInt8ToUint16:
case EOpConvInt8ToUint:
case EOpConvInt8ToUint64:
// int16_t -> (u)int*
case EOpConvInt16ToInt8:
case EOpConvInt16ToInt:
case EOpConvInt16ToInt64:
case EOpConvInt16ToUint8:
case EOpConvInt16ToUint16:
case EOpConvInt16ToUint:
case EOpConvInt16ToUint64:
// int32_t -> (u)int*
case EOpConvIntToInt8:
case EOpConvIntToInt16:
case EOpConvIntToInt64:
case EOpConvIntToUint8:
case EOpConvIntToUint16:
case EOpConvIntToUint:
case EOpConvIntToUint64:
// int64_t -> (u)int*
case EOpConvInt64ToInt8:
case EOpConvInt64ToInt16:
case EOpConvInt64ToInt:
case EOpConvInt64ToUint8:
case EOpConvInt64ToUint16:
case EOpConvInt64ToUint:
case EOpConvInt64ToUint64:
// uint8_t -> (u)int*
case EOpConvUint8ToInt8:
case EOpConvUint8ToInt16:
case EOpConvUint8ToInt:
case EOpConvUint8ToInt64:
case EOpConvUint8ToUint16:
case EOpConvUint8ToUint:
case EOpConvUint8ToUint64:
// uint16_t -> (u)int*
case EOpConvUint16ToInt8:
case EOpConvUint16ToInt16:
case EOpConvUint16ToInt:
case EOpConvUint16ToInt64:
case EOpConvUint16ToUint8:
case EOpConvUint16ToUint:
case EOpConvUint16ToUint64:
// uint32_t -> (u)int*
case EOpConvUintToInt8:
case EOpConvUintToInt16:
case EOpConvUintToInt:
case EOpConvUintToInt64:
case EOpConvUintToUint8:
case EOpConvUintToUint16:
case EOpConvUintToUint64:
// uint64_t -> (u)int*
case EOpConvUint64ToInt8:
case EOpConvUint64ToInt16:
case EOpConvUint64ToInt:
case EOpConvUint64ToInt64:
case EOpConvUint64ToUint8:
case EOpConvUint64ToUint16:
case EOpConvUint64ToUint:
// unary operations
case EOpNegative:
case EOpLogicalNot:
case EOpBitwiseNot:
// binary operations
case EOpAdd:
case EOpSub:
case EOpMul:
case EOpVectorTimesScalar:
case EOpDiv:
case EOpMod:
case EOpRightShift:
case EOpLeftShift:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpLogicalOr:
case EOpLogicalXor:
case EOpLogicalAnd:
case EOpEqual:
case EOpNotEqual:
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
return true;
default:
return false;
}
}
// Is the operation one that must propagate nonuniform?
bool TIntermediate::isNonuniformPropagating(TOperator op) const
{
// "* All Operators in Section 5.1 (Operators), except for assignment,
// arithmetic assignment, and sequence
// * Component selection in Section 5.5
// * Matrix components in Section 5.6
// * Structure and Array Operations in Section 5.7, except for the length
// method."
switch (op) {
case EOpPostIncrement:
case EOpPostDecrement:
case EOpPreIncrement:
case EOpPreDecrement:
case EOpNegative:
case EOpLogicalNot:
case EOpVectorLogicalNot:
case EOpBitwiseNot:
case EOpAdd:
case EOpSub:
case EOpMul:
case EOpDiv:
case EOpMod:
case EOpRightShift:
case EOpLeftShift:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpEqual:
case EOpNotEqual:
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
case EOpVectorTimesScalar:
case EOpVectorTimesMatrix:
case EOpMatrixTimesVector:
case EOpMatrixTimesScalar:
case EOpLogicalOr:
case EOpLogicalXor:
case EOpLogicalAnd:
case EOpIndexDirect:
case EOpIndexIndirect:
case EOpIndexDirectStruct:
case EOpVectorSwizzle:
return true;
default:
break;
}
return false;
}
////////////////////////////////////////////////////////////////
//
// Member functions of the nodes used for building the tree.
//
////////////////////////////////////////////////////////////////
//
// Say whether or not an operation node changes the value of a variable.
//
// Returns true if state is modified.
//
bool TIntermOperator::modifiesState() const
{
switch (op) {
case EOpPostIncrement:
case EOpPostDecrement:
case EOpPreIncrement:
case EOpPreDecrement:
case EOpAssign:
case EOpAddAssign:
case EOpSubAssign:
case EOpMulAssign:
case EOpVectorTimesMatrixAssign:
case EOpVectorTimesScalarAssign:
case EOpMatrixTimesScalarAssign:
case EOpMatrixTimesMatrixAssign:
case EOpDivAssign:
case EOpModAssign:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
case EOpLeftShiftAssign:
case EOpRightShiftAssign:
return true;
default:
return false;
}
}
//
// returns true if the operator is for one of the constructors
//
bool TIntermOperator::isConstructor() const
{
return op > EOpConstructGuardStart && op < EOpConstructGuardEnd;
}
//
// Make sure the type of an operator is appropriate for its
// combination of operation and operand type. This will invoke
// promoteUnary, promoteBinary, etc as needed.
//
// Returns false if nothing makes sense.
//
bool TIntermediate::promote(TIntermOperator* node)
{
if (node == nullptr)
return false;
if (node->getAsUnaryNode())
return promoteUnary(*node->getAsUnaryNode());
if (node->getAsBinaryNode())
return promoteBinary(*node->getAsBinaryNode());
if (node->getAsAggregate())
return promoteAggregate(*node->getAsAggregate());
return false;
}
//
// See TIntermediate::promote
//
bool TIntermediate::promoteUnary(TIntermUnary& node)
{
const TOperator op = node.getOp();
TIntermTyped* operand = node.getOperand();
switch (op) {
case EOpLogicalNot:
// Convert operand to a boolean type
if (operand->getBasicType() != EbtBool) {
// Add constructor to boolean type. If that fails, we can't do it, so return false.
TIntermTyped* converted = addConversion(op, TType(EbtBool), operand);
if (converted == nullptr)
return false;
// Use the result of converting the node to a bool.
node.setOperand(operand = converted); // also updates stack variable
}
break;
case EOpBitwiseNot:
if (!isTypeInt(operand->getBasicType()))
return false;
break;
case EOpNegative:
case EOpPostIncrement:
case EOpPostDecrement:
case EOpPreIncrement:
case EOpPreDecrement:
if (!isTypeInt(operand->getBasicType()) &&
operand->getBasicType() != EbtFloat &&
operand->getBasicType() != EbtFloat16 &&
operand->getBasicType() != EbtDouble)
return false;
break;
default:
// HLSL uses this path for initial function signature finding for built-ins
// taking a single argument, which generally don't participate in
// operator-based type promotion (type conversion will occur later).
// For now, scalar argument cases are relying on the setType() call below.
if (getSource() == EShSourceHlsl)
break;
// GLSL only allows integer arguments for the cases identified above in the
// case statements.
if (operand->getBasicType() != EbtFloat)
return false;
}
node.setType(operand->getType());
node.getWritableType().getQualifier().makeTemporary();
return true;
}
// Propagate precision qualifiers *up* from children to parent.
void TIntermUnary::updatePrecision()
{
if (getBasicType() == EbtInt || getBasicType() == EbtUint ||
getBasicType() == EbtFloat) {
if (operand->getQualifier().precision > getQualifier().precision)
getQualifier().precision = operand->getQualifier().precision;
}
}
//
// See TIntermediate::promote
//
bool TIntermediate::promoteBinary(TIntermBinary& node)
{
TOperator op = node.getOp();
TIntermTyped* left = node.getLeft();
TIntermTyped* right = node.getRight();
// Arrays and structures have to be exact matches.
if ((left->isArray() || right->isArray() || left->getBasicType() == EbtStruct || right->getBasicType() == EbtStruct)
&& left->getType() != right->getType())
return false;
// Base assumption: just make the type the same as the left
// operand. Only deviations from this will be coded.
node.setType(left->getType());
node.getWritableType().getQualifier().clear();
// Composite and opaque types don't having pending operator changes, e.g.,
// array, structure, and samplers. Just establish final type and correctness.
if (left->isArray() || left->getBasicType() == EbtStruct || left->getBasicType() == EbtSampler) {
switch (op) {
case EOpEqual:
case EOpNotEqual:
if (left->getBasicType() == EbtSampler) {
// can't compare samplers
return false;
} else {
// Promote to conditional
node.setType(TType(EbtBool));
}
return true;
case EOpAssign:
// Keep type from above
return true;
default:
return false;
}
}
//
// We now have only scalars, vectors, and matrices to worry about.
//
// HLSL implicitly promotes bool -> int for numeric operations.
// (Implicit conversions to make the operands match each other's types were already done.)
if (getSource() == EShSourceHlsl &&
(left->getBasicType() == EbtBool || right->getBasicType() == EbtBool)) {
switch (op) {
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
case EOpRightShift:
case EOpLeftShift:
case EOpMod:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpMul:
if (left->getBasicType() == EbtBool)
left = createConversion(EbtInt, left);
if (right->getBasicType() == EbtBool)
right = createConversion(EbtInt, right);
if (left == nullptr || right == nullptr)
return false;
node.setLeft(left);
node.setRight(right);
// Update the original base assumption on result type..
node.setType(left->getType());
node.getWritableType().getQualifier().clear();
break;
default:
break;
}
}
// Do general type checks against individual operands (comparing left and right is coming up, checking mixed shapes after that)
switch (op) {
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
// Relational comparisons need numeric types and will promote to scalar Boolean.
if (left->getBasicType() == EbtBool)
return false;
node.setType(TType(EbtBool, EvqTemporary, left->getVectorSize()));
break;
case EOpEqual:
case EOpNotEqual:
if (getSource() == EShSourceHlsl) {
const int resultWidth = std::max(left->getVectorSize(), right->getVectorSize());
// In HLSL, == or != on vectors means component-wise comparison.
if (resultWidth > 1) {
op = (op == EOpEqual) ? EOpVectorEqual : EOpVectorNotEqual;
node.setOp(op);
}
node.setType(TType(EbtBool, EvqTemporary, resultWidth));
} else {
// All the above comparisons result in a bool (but not the vector compares)
node.setType(TType(EbtBool));
}
break;
case EOpLogicalAnd:
case EOpLogicalOr:
case EOpLogicalXor:
// logical ops operate only on Booleans or vectors of Booleans.
if (left->getBasicType() != EbtBool || left->isMatrix())
return false;
if (getSource() == EShSourceGlsl) {
// logical ops operate only on scalar Booleans and will promote to scalar Boolean.
if (left->isVector())
return false;
}
node.setType(TType(EbtBool, EvqTemporary, left->getVectorSize()));
break;
case EOpRightShift:
case EOpLeftShift:
case EOpRightShiftAssign:
case EOpLeftShiftAssign:
case EOpMod:
case EOpModAssign:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
if (getSource() == EShSourceHlsl)
break;
// Check for integer-only operands.
if (!isTypeInt(left->getBasicType()) && !isTypeInt(right->getBasicType()))
return false;
if (left->isMatrix() || right->isMatrix())
return false;
break;
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpMul:
case EOpAddAssign:
case EOpSubAssign:
case EOpMulAssign:
case EOpDivAssign:
// check for non-Boolean operands
if (left->getBasicType() == EbtBool || right->getBasicType() == EbtBool)
return false;
break;
default:
break;
}
// Compare left and right, and finish with the cases where the operand types must match
switch (op) {
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
case EOpEqual:
case EOpNotEqual:
case EOpVectorEqual:
case EOpVectorNotEqual:
case EOpLogicalAnd:
case EOpLogicalOr:
case EOpLogicalXor:
return left->getType() == right->getType();
case EOpMod:
case EOpModAssign:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpAddAssign:
case EOpSubAssign:
case EOpDivAssign:
// Quick out in case the types do match
if (left->getType() == right->getType())
return true;
[[fallthrough]];
case EOpMul:
case EOpMulAssign:
// At least the basic type has to match
if (left->getBasicType() != right->getBasicType())
return false;
break;
default:
break;
}
if (left->getType().isCoopMat() || right->getType().isCoopMat()) {
// Operations on two cooperative matrices must have identical types
if (left->getType().isCoopMat() && right->getType().isCoopMat() &&
left->getType() != right->getType()) {
return false;
}
switch (op) {
case EOpMul:
case EOpMulAssign:
// Mul not supported in NV_cooperative_matrix
if (left->getType().isCoopMatNV() && right->getType().isCoopMatNV()) {
return false;
}
// NV_cooperative_matrix supports MulAssign is for mat*=scalar only.
// KHR_cooperative_matrix supports it for mat*=mat as well.
if (op == EOpMulAssign && right->getType().isCoopMatNV()) {
return false;
}
// Use MatrixTimesScalar if either operand is not a matrix. Otherwise use Mul.
if (!left->getType().isCoopMat() || !right->getType().isCoopMat()) {
node.setOp(op == EOpMulAssign ? EOpMatrixTimesScalarAssign : EOpMatrixTimesScalar);
}
// In case of scalar*matrix, take the result type from the matrix.
if (right->getType().isCoopMat()) {
node.setType(right->getType());
}
return true;
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpAssign:
// These require both to be cooperative matrices
if (!left->getType().isCoopMat() || !right->getType().isCoopMat()) {
return false;
}
return true;
default:
break;
}
return false;
}
// Finish handling the case, for all ops, where both operands are scalars.
if (left->isScalar() && right->isScalar())
return true;
// Finish handling the case, for all ops, where there are two vectors of different sizes
if (left->isVector() && right->isVector() && left->getVectorSize() != right->getVectorSize() && right->getVectorSize() > 1)
return false;
//
// We now have a mix of scalars, vectors, or matrices, for non-relational operations.
//
// Can these two operands be combined, what is the resulting type?
TBasicType basicType = left->getBasicType();
switch (op) {
case EOpMul:
if (!left->isMatrix() && right->isMatrix()) {
if (left->isVector()) {
if (left->getVectorSize() != right->getMatrixRows())
return false;
node.setOp(op = EOpVectorTimesMatrix);
node.setType(TType(basicType, EvqTemporary, right->getMatrixCols()));
} else {
node.setOp(op = EOpMatrixTimesScalar);
node.setType(TType(basicType, EvqTemporary, 0, right->getMatrixCols(), right->getMatrixRows()));
}
} else if (left->isMatrix() && !right->isMatrix()) {
if (right->isVector()) {
if (left->getMatrixCols() != right->getVectorSize())
return false;
node.setOp(op = EOpMatrixTimesVector);
node.setType(TType(basicType, EvqTemporary, left->getMatrixRows()));
} else {
node.setOp(op = EOpMatrixTimesScalar);
}
} else if (left->isMatrix() && right->isMatrix()) {
if (left->getMatrixCols() != right->getMatrixRows())
return false;
node.setOp(op = EOpMatrixTimesMatrix);
node.setType(TType(basicType, EvqTemporary, 0, right->getMatrixCols(), left->getMatrixRows()));
} else if (! left->isMatrix() && ! right->isMatrix()) {
if (left->isVector() && right->isVector()) {
; // leave as component product
} else if (left->isVector() || right->isVector()) {
node.setOp(op = EOpVectorTimesScalar);
if (right->isVector())
node.setType(TType(basicType, EvqTemporary, right->getVectorSize()));
}
} else {
return false;
}
break;
case EOpMulAssign:
if (! left->isMatrix() && right->isMatrix()) {
if (left->isVector()) {
if (left->getVectorSize() != right->getMatrixRows() || left->getVectorSize() != right->getMatrixCols())
return false;
node.setOp(op = EOpVectorTimesMatrixAssign);
} else {
return false;
}
} else if (left->isMatrix() && !right->isMatrix()) {
if (right->isVector()) {
return false;
} else {
node.setOp(op = EOpMatrixTimesScalarAssign);
}
} else if (left->isMatrix() && right->isMatrix()) {
if (left->getMatrixCols() != right->getMatrixCols() || left->getMatrixCols() != right->getMatrixRows())
return false;
node.setOp(op = EOpMatrixTimesMatrixAssign);
} else if (!left->isMatrix() && !right->isMatrix()) {
if (left->isVector() && right->isVector()) {
// leave as component product
} else if (left->isVector() || right->isVector()) {
if (! left->isVector())
return false;
node.setOp(op = EOpVectorTimesScalarAssign);
}
} else {
return false;
}
break;
case EOpRightShift:
case EOpLeftShift:
case EOpRightShiftAssign:
case EOpLeftShiftAssign:
if (right->isVector() && (! left->isVector() || right->getVectorSize() != left->getVectorSize()))
return false;
break;
case EOpAssign:
if (left->getVectorSize() != right->getVectorSize() || left->getMatrixCols() != right->getMatrixCols() || left->getMatrixRows() != right->getMatrixRows())
return false;
[[fallthrough]];
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpMod:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpAddAssign:
case EOpSubAssign:
case EOpDivAssign:
case EOpModAssign:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
if ((left->isMatrix() && right->isVector()) ||
(left->isVector() && right->isMatrix()) ||
left->getBasicType() != right->getBasicType())
return false;
if (left->isMatrix() && right->isMatrix() && (left->getMatrixCols() != right->getMatrixCols() || left->getMatrixRows() != right->getMatrixRows()))
return false;
if (left->isVector() && right->isVector() && left->getVectorSize() != right->getVectorSize())
return false;
if (right->isVector() || right->isMatrix()) {
node.getWritableType().shallowCopy(right->getType());
node.getWritableType().getQualifier().makeTemporary();
}
break;
default:
return false;
}
//
// One more check for assignment.
//
switch (op) {
// The resulting type has to match the left operand.
case EOpAssign:
case EOpAddAssign:
case EOpSubAssign:
case EOpMulAssign:
case EOpDivAssign:
case EOpModAssign:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
case EOpLeftShiftAssign:
case EOpRightShiftAssign:
if (node.getType() != left->getType())
return false;
break;
default:
break;
}
return true;
}
//
// See TIntermediate::promote
//
bool TIntermediate::promoteAggregate(TIntermAggregate& node)
{
TOperator op = node.getOp();
TIntermSequence& args = node.getSequence();
const int numArgs = static_cast<int>(args.size());
// Presently, only hlsl does intrinsic promotions.
if (getSource() != EShSourceHlsl)
return true;
// set of opcodes that can be promoted in this manner.
switch (op) {
case EOpAtan:
case EOpClamp:
case EOpCross:
case EOpDistance:
case EOpDot:
case EOpDst:
case EOpFaceForward:
// case EOpFindMSB: TODO:
// case EOpFindLSB: TODO:
case EOpFma:
case EOpMod:
case EOpFrexp:
case EOpLdexp:
case EOpMix:
case EOpLit:
case EOpMax:
case EOpMin:
case EOpModf:
// case EOpGenMul: TODO:
case EOpPow:
case EOpReflect:
case EOpRefract:
// case EOpSinCos: TODO:
case EOpSmoothStep:
case EOpStep:
break;
default:
return true;
}
// TODO: array and struct behavior
// Try converting all nodes to the given node's type
TIntermSequence convertedArgs(numArgs, nullptr);
// Try to convert all types to the nonConvArg type.
for (int nonConvArg = 0; nonConvArg < numArgs; ++nonConvArg) {
// Try converting all args to this arg's type
for (int convArg = 0; convArg < numArgs; ++convArg) {
convertedArgs[convArg] = addConversion(op, args[nonConvArg]->getAsTyped()->getType(),
args[convArg]->getAsTyped());
}
// If we successfully converted all the args, use the result.
if (std::all_of(convertedArgs.begin(), convertedArgs.end(),
[](const TIntermNode* node) { return node != nullptr; })) {
std::swap(args, convertedArgs);
return true;
}
}
return false;
}
// Propagate precision qualifiers *up* from children to parent, and then
// back *down* again to the children's subtrees.
void TIntermAggregate::updatePrecision()
{
if (getBasicType() == EbtInt || getBasicType() == EbtUint ||
getBasicType() == EbtFloat) {
TPrecisionQualifier maxPrecision = EpqNone;
TIntermSequence operands = getSequence();
for (unsigned int i = 0; i < operands.size(); ++i) {
TIntermTyped* typedNode = operands[i]->getAsTyped();
assert(typedNode);
maxPrecision = std::max(maxPrecision, typedNode->getQualifier().precision);
}
getQualifier().precision = maxPrecision;
for (unsigned int i = 0; i < operands.size(); ++i) {
TIntermTyped* typedNode = operands[i]->getAsTyped();
assert(typedNode);
typedNode->propagatePrecision(maxPrecision);
}
}
}
// Propagate precision qualifiers *up* from children to parent, and then
// back *down* again to the children's subtrees.
void TIntermBinary::updatePrecision()
{
if (getBasicType() == EbtInt || getBasicType() == EbtUint ||
getBasicType() == EbtFloat) {
if (op == EOpRightShift || op == EOpLeftShift) {
// For shifts get precision from left side only and thus no need to propagate
getQualifier().precision = left->getQualifier().precision;
} else {
getQualifier().precision = std::max(right->getQualifier().precision, left->getQualifier().precision);
if (getQualifier().precision != EpqNone) {
left->propagatePrecision(getQualifier().precision);
right->propagatePrecision(getQualifier().precision);
}
}
}
}
// Recursively propagate precision qualifiers *down* the subtree of the current node,
// until reaching a node that already has a precision qualifier or otherwise does
// not participate in precision propagation.
void TIntermTyped::propagatePrecision(TPrecisionQualifier newPrecision)
{
if (getQualifier().precision != EpqNone ||
(getBasicType() != EbtInt && getBasicType() != EbtUint &&
getBasicType() != EbtFloat && getBasicType() != EbtFloat16))
return;
getQualifier().precision = newPrecision;
TIntermBinary* binaryNode = getAsBinaryNode();
if (binaryNode) {
binaryNode->getLeft()->propagatePrecision(newPrecision);
binaryNode->getRight()->propagatePrecision(newPrecision);
return;
}
TIntermUnary* unaryNode = getAsUnaryNode();
if (unaryNode) {
unaryNode->getOperand()->propagatePrecision(newPrecision);
return;
}
TIntermAggregate* aggregateNode = getAsAggregate();
if (aggregateNode) {
TIntermSequence operands = aggregateNode->getSequence();
for (unsigned int i = 0; i < operands.size(); ++i) {
TIntermTyped* typedNode = operands[i]->getAsTyped();
if (! typedNode)
break;
typedNode->propagatePrecision(newPrecision);
}
return;
}
TIntermSelection* selectionNode = getAsSelectionNode();
if (selectionNode) {
TIntermTyped* typedNode = selectionNode->getTrueBlock()->getAsTyped();
if (typedNode) {
typedNode->propagatePrecision(newPrecision);
typedNode = selectionNode->getFalseBlock()->getAsTyped();
if (typedNode)
typedNode->propagatePrecision(newPrecision);
}
return;
}
}
TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermConstantUnion* node) const
{
const TConstUnionArray& rightUnionArray = node->getConstArray();
int size = node->getType().computeNumComponents();
TConstUnionArray leftUnionArray(size);
for (int i=0; i < size; i++) {
#define PROMOTE(Set, CType, Get) leftUnionArray[i].Set(static_cast<CType>(rightUnionArray[i].Get()))
#define PROMOTE_TO_BOOL(Get) leftUnionArray[i].setBConst(rightUnionArray[i].Get() != 0)
#define TO_ALL(Get) \
switch (promoteTo) { \
case EbtFloat16: PROMOTE(setDConst, double, Get); break; \
case EbtFloat: PROMOTE(setDConst, double, Get); break; \
case EbtDouble: PROMOTE(setDConst, double, Get); break; \
case EbtInt8: PROMOTE(setI8Const, signed char, Get); break; \
case EbtInt16: PROMOTE(setI16Const, short, Get); break; \
case EbtInt: PROMOTE(setIConst, int, Get); break; \
case EbtInt64: PROMOTE(setI64Const, long long, Get); break; \
case EbtUint8: PROMOTE(setU8Const, unsigned char, Get); break; \
case EbtUint16: PROMOTE(setU16Const, unsigned short, Get); break; \
case EbtUint: PROMOTE(setUConst, unsigned int, Get); break; \
case EbtUint64: PROMOTE(setU64Const, unsigned long long, Get); break; \
case EbtBool: PROMOTE_TO_BOOL(Get); break; \
default: return node; \
}
switch (node->getType().getBasicType()) {
case EbtFloat: TO_ALL(getDConst); break;
case EbtInt: TO_ALL(getIConst); break;
case EbtUint: TO_ALL(getUConst); break;
case EbtBool: TO_ALL(getBConst); break;
case EbtFloat16: TO_ALL(getDConst); break;
case EbtDouble: TO_ALL(getDConst); break;
case EbtInt8: TO_ALL(getI8Const); break;
case EbtInt16: TO_ALL(getI16Const); break;
case EbtInt64: TO_ALL(getI64Const); break;
case EbtUint8: TO_ALL(getU8Const); break;
case EbtUint16: TO_ALL(getU16Const); break;
case EbtUint64: TO_ALL(getU64Const); break;
default: return node;
}
}
const TType& t = node->getType();
return addConstantUnion(leftUnionArray, TType(promoteTo, t.getQualifier().storage, t.getVectorSize(), t.getMatrixCols(), t.getMatrixRows()),
node->getLoc());
}
void TIntermAggregate::setPragmaTable(const TPragmaTable& pTable)
{
assert(pragmaTable == nullptr);
pragmaTable = new TPragmaTable;
*pragmaTable = pTable;
}
// If either node is a specialization constant, while the other is
// a constant (or specialization constant), the result is still
// a specialization constant.
bool TIntermediate::specConstantPropagates(const TIntermTyped& node1, const TIntermTyped& node2)
{
return (node1.getType().getQualifier().isSpecConstant() && node2.getType().getQualifier().isConstant()) ||
(node2.getType().getQualifier().isSpecConstant() && node1.getType().getQualifier().isConstant());
}
struct TextureUpgradeAndSamplerRemovalTransform : public TIntermTraverser {
void visitSymbol(TIntermSymbol* symbol) override {
if (symbol->getBasicType() == EbtSampler && symbol->getType().getSampler().isTexture()) {
symbol->getWritableType().getSampler().setCombined(true);
}
}
bool visitAggregate(TVisit, TIntermAggregate* ag) override {
using namespace std;
TIntermSequence& seq = ag->getSequence();
TQualifierList& qual = ag->getQualifierList();
// qual and seq are indexed using the same indices, so we have to modify both in lock-step
assert(seq.size() == qual.size() || qual.empty());
size_t write = 0;
for (size_t i = 0; i < seq.size(); ++i) {
TIntermSymbol* symbol = seq[i]->getAsSymbolNode();
if (symbol && symbol->getBasicType() == EbtSampler && symbol->getType().getSampler().isPureSampler()) {
// remove pure sampler variables
continue;
}
TIntermNode* result = seq[i];
// replace constructors with sampler/textures
TIntermAggregate *constructor = seq[i]->getAsAggregate();
if (constructor && constructor->getOp() == EOpConstructTextureSampler) {
if (!constructor->getSequence().empty())
result = constructor->getSequence()[0];
}
// write new node & qualifier
seq[write] = result;
if (!qual.empty())
qual[write] = qual[i];
write++;
}
seq.resize(write);
if (!qual.empty())
qual.resize(write);
return true;
}
};
void TIntermediate::performTextureUpgradeAndSamplerRemovalTransformation(TIntermNode* root)
{
TextureUpgradeAndSamplerRemovalTransform transform;
root->traverse(&transform);
}
const char* TIntermediate::getResourceName(TResourceType res)
{
switch (res) {
case EResSampler: return "shift-sampler-binding";
case EResTexture: return "shift-texture-binding";
case EResImage: return "shift-image-binding";
case EResUbo: return "shift-UBO-binding";
case EResSsbo: return "shift-ssbo-binding";
case EResUav: return "shift-uav-binding";
default:
assert(0); // internal error: should only be called with valid resource types.
return nullptr;
}
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/Initialize.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013-2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _INITIALIZE_INCLUDED_
#define _INITIALIZE_INCLUDED_
#include "../Include/ResourceLimits.h"
#include "../Include/Common.h"
#include "../Include/ShHandle.h"
#include "SymbolTable.h"
#include "Versions.h"
namespace glslang {
//
// This is made to hold parseable strings for almost all the built-in
// functions and variables for one specific combination of version
// and profile. (Some still need to be added programmatically.)
// This is a base class for language-specific derivations, which
// can be used for language independent builtins.
//
// The strings are organized by
// commonBuiltins: intersection of all stages' built-ins, processed just once
// stageBuiltins[]: anything a stage needs that's not in commonBuiltins
//
class TBuiltInParseables {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TBuiltInParseables();
virtual ~TBuiltInParseables();
virtual void initialize(int version, EProfile, const SpvVersion& spvVersion) = 0;
virtual void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage) = 0;
virtual const TString& getCommonString() const { return commonBuiltins; }
virtual const TString& getStageString(EShLanguage language) const { return stageBuiltins[language]; }
virtual void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable) = 0;
virtual void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources) = 0;
protected:
TString commonBuiltins;
TString stageBuiltins[EShLangCount];
};
//
// This is a GLSL specific derivation of TBuiltInParseables. To present a stable
// interface and match other similar code, it is called TBuiltIns, rather
// than TBuiltInParseablesGlsl.
//
class TBuiltIns : public TBuiltInParseables {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TBuiltIns();
virtual ~TBuiltIns();
void initialize(int version, EProfile, const SpvVersion& spvVersion);
void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage);
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable);
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources);
protected:
void addTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion);
void relateTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage, TSymbolTable&);
void add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion);
void addSubpassSampling(TSampler, const TString& typeName, int version, EProfile profile);
void addQueryFunctions(TSampler, const TString& typeName, int version, EProfile profile);
void addImageFunctions(TSampler, const TString& typeName, int version, EProfile profile);
void addSamplingFunctions(TSampler, const TString& typeName, int version, EProfile profile);
void addGatherFunctions(TSampler, const TString& typeName, int version, EProfile profile);
// Helpers for making textual representations of the permutations
// of texturing/imaging functions.
const char* postfixes[5];
const char* prefixes[EbtNumTypes];
int dimMap[EsdNumDims];
};
// change this back to false if depending on textual spellings of texturing calls when consuming the AST
// Using PureOperatorBuiltins=false is deprecated.
constexpr bool PureOperatorBuiltins = true;
} // end namespace glslang
#endif // _INITIALIZE_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/intermOut.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2016 LunarG, Inc.
// Copyright (C) 2017, 2022-2024 Arm Limited.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "localintermediate.h"
#include "../Include/InfoSink.h"
#ifdef _MSC_VER
#include <cfloat>
#else
#include <cmath>
#endif
#include <cstdint>
namespace glslang {
//
// Two purposes:
// 1. Show an example of how to iterate tree. Functions can
// also directly call Traverse() on children themselves to
// have finer grained control over the process than shown here.
// See the last function for how to get started.
// 2. Print out a text based description of the tree.
//
//
// Use this class to carry along data from node to node in
// the traversal
//
class TOutputTraverser : public TIntermTraverser {
public:
TOutputTraverser(TInfoSink& i) : infoSink(i), extraOutput(NoExtraOutput) { }
enum EExtraOutput {
NoExtraOutput,
BinaryDoubleOutput
};
void setDoubleOutput(EExtraOutput extra) { extraOutput = extra; }
virtual bool visitBinary(TVisit, TIntermBinary* node);
virtual bool visitUnary(TVisit, TIntermUnary* node);
virtual bool visitAggregate(TVisit, TIntermAggregate* node);
virtual bool visitSelection(TVisit, TIntermSelection* node);
virtual void visitConstantUnion(TIntermConstantUnion* node);
virtual void visitSymbol(TIntermSymbol* node);
virtual bool visitLoop(TVisit, TIntermLoop* node);
virtual bool visitBranch(TVisit, TIntermBranch* node);
virtual bool visitSwitch(TVisit, TIntermSwitch* node);
TInfoSink& infoSink;
protected:
TOutputTraverser(TOutputTraverser&);
TOutputTraverser& operator=(TOutputTraverser&);
EExtraOutput extraOutput;
};
//
// Helper functions for printing, not part of traversing.
//
static void OutputTreeText(TInfoSink& infoSink, const TIntermNode* node, const int depth)
{
int i;
infoSink.debug << node->getLoc().string << ":";
if (node->getLoc().line)
infoSink.debug << node->getLoc().line;
else
infoSink.debug << "? ";
for (i = 0; i < depth; ++i)
infoSink.debug << " ";
}
//
// The rest of the file are the traversal functions. The last one
// is the one that starts the traversal.
//
// Return true from interior nodes to have the external traversal
// continue on to children. If you process children yourself,
// return false.
//
bool TOutputTraverser::visitBinary(TVisit /* visit */, TIntermBinary* node)
{
TInfoSink& out = infoSink;
OutputTreeText(out, node, depth);
switch (node->getOp()) {
case EOpAssign: out.debug << "move second child to first child"; break;
case EOpAddAssign: out.debug << "add second child into first child"; break;
case EOpSubAssign: out.debug << "subtract second child into first child"; break;
case EOpMulAssign: out.debug << "multiply second child into first child"; break;
case EOpVectorTimesMatrixAssign: out.debug << "matrix mult second child into first child"; break;
case EOpVectorTimesScalarAssign: out.debug << "vector scale second child into first child"; break;
case EOpMatrixTimesScalarAssign: out.debug << "matrix scale second child into first child"; break;
case EOpMatrixTimesMatrixAssign: out.debug << "matrix mult second child into first child"; break;
case EOpDivAssign: out.debug << "divide second child into first child"; break;
case EOpModAssign: out.debug << "mod second child into first child"; break;
case EOpAndAssign: out.debug << "and second child into first child"; break;
case EOpInclusiveOrAssign: out.debug << "or second child into first child"; break;
case EOpExclusiveOrAssign: out.debug << "exclusive or second child into first child"; break;
case EOpLeftShiftAssign: out.debug << "left shift second child into first child"; break;
case EOpRightShiftAssign: out.debug << "right shift second child into first child"; break;
case EOpIndexDirect: out.debug << "direct index"; break;
case EOpIndexIndirect: out.debug << "indirect index"; break;
case EOpIndexDirectStruct:
{
bool reference = node->getLeft()->getType().isReference();
const TTypeList *members = reference ? node->getLeft()->getType().getReferentType()->getStruct() : node->getLeft()->getType().getStruct();
out.debug << (*members)[node->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst()].type->getFieldName();
out.debug << ": direct index for structure"; break;
}
case EOpVectorSwizzle: out.debug << "vector swizzle"; break;
case EOpMatrixSwizzle: out.debug << "matrix swizzle"; break;
case EOpAdd: out.debug << "add"; break;
case EOpSub: out.debug << "subtract"; break;
case EOpMul: out.debug << "component-wise multiply"; break;
case EOpDiv: out.debug << "divide"; break;
case EOpMod: out.debug << "mod"; break;
case EOpRightShift: out.debug << "right-shift"; break;
case EOpLeftShift: out.debug << "left-shift"; break;
case EOpAnd: out.debug << "bitwise and"; break;
case EOpInclusiveOr: out.debug << "inclusive-or"; break;
case EOpExclusiveOr: out.debug << "exclusive-or"; break;
case EOpEqual: out.debug << "Compare Equal"; break;
case EOpNotEqual: out.debug << "Compare Not Equal"; break;
case EOpLessThan: out.debug << "Compare Less Than"; break;
case EOpGreaterThan: out.debug << "Compare Greater Than"; break;
case EOpLessThanEqual: out.debug << "Compare Less Than or Equal"; break;
case EOpGreaterThanEqual: out.debug << "Compare Greater Than or Equal"; break;
case EOpVectorEqual: out.debug << "Equal"; break;
case EOpVectorNotEqual: out.debug << "NotEqual"; break;
case EOpVectorTimesScalar: out.debug << "vector-scale"; break;
case EOpVectorTimesMatrix: out.debug << "vector-times-matrix"; break;
case EOpMatrixTimesVector: out.debug << "matrix-times-vector"; break;
case EOpMatrixTimesScalar: out.debug << "matrix-scale"; break;
case EOpMatrixTimesMatrix: out.debug << "matrix-multiply"; break;
case EOpLogicalOr: out.debug << "logical-or"; break;
case EOpLogicalXor: out.debug << "logical-xor"; break;
case EOpLogicalAnd: out.debug << "logical-and"; break;
case EOpAbsDifference: out.debug << "absoluteDifference"; break;
case EOpAddSaturate: out.debug << "addSaturate"; break;
case EOpSubSaturate: out.debug << "subtractSaturate"; break;
case EOpAverage: out.debug << "average"; break;
case EOpAverageRounded: out.debug << "averageRounded"; break;
case EOpMul32x16: out.debug << "multiply32x16"; break;
default: out.debug << "<unknown op>";
}
out.debug << " (" << node->getCompleteString() << ")";
out.debug << "\n";
return true;
}
bool TOutputTraverser::visitUnary(TVisit /* visit */, TIntermUnary* node)
{
TInfoSink& out = infoSink;
OutputTreeText(out, node, depth);
switch (node->getOp()) {
case EOpNegative: out.debug << "Negate value"; break;
case EOpVectorLogicalNot:
case EOpLogicalNot: out.debug << "Negate conditional"; break;
case EOpBitwiseNot: out.debug << "Bitwise not"; break;
case EOpPostIncrement: out.debug << "Post-Increment"; break;
case EOpPostDecrement: out.debug << "Post-Decrement"; break;
case EOpPreIncrement: out.debug << "Pre-Increment"; break;
case EOpPreDecrement: out.debug << "Pre-Decrement"; break;
case EOpCopyObject: out.debug << "copy object"; break;
// * -> bool
case EOpConvInt8ToBool: out.debug << "Convert int8_t to bool"; break;
case EOpConvUint8ToBool: out.debug << "Convert uint8_t to bool"; break;
case EOpConvInt16ToBool: out.debug << "Convert int16_t to bool"; break;
case EOpConvUint16ToBool: out.debug << "Convert uint16_t to bool";break;
case EOpConvIntToBool: out.debug << "Convert int to bool"; break;
case EOpConvUintToBool: out.debug << "Convert uint to bool"; break;
case EOpConvInt64ToBool: out.debug << "Convert int64 to bool"; break;
case EOpConvUint64ToBool: out.debug << "Convert uint64 to bool"; break;
case EOpConvFloat16ToBool: out.debug << "Convert float16_t to bool"; break;
case EOpConvFloatToBool: out.debug << "Convert float to bool"; break;
case EOpConvDoubleToBool: out.debug << "Convert double to bool"; break;
// bool -> *
case EOpConvBoolToInt8: out.debug << "Convert bool to int8_t"; break;
case EOpConvBoolToUint8: out.debug << "Convert bool to uint8_t"; break;
case EOpConvBoolToInt16: out.debug << "Convert bool to in16t_t"; break;
case EOpConvBoolToUint16: out.debug << "Convert bool to uint16_t";break;
case EOpConvBoolToInt: out.debug << "Convert bool to int" ; break;
case EOpConvBoolToUint: out.debug << "Convert bool to uint"; break;
case EOpConvBoolToInt64: out.debug << "Convert bool to int64"; break;
case EOpConvBoolToUint64: out.debug << "Convert bool to uint64";break;
case EOpConvBoolToFloat16: out.debug << "Convert bool to float16_t"; break;
case EOpConvBoolToFloat: out.debug << "Convert bool to float"; break;
case EOpConvBoolToDouble: out.debug << "Convert bool to double"; break;
// int8_t -> (u)int*
case EOpConvInt8ToInt16: out.debug << "Convert int8_t to int16_t";break;
case EOpConvInt8ToInt: out.debug << "Convert int8_t to int"; break;
case EOpConvInt8ToInt64: out.debug << "Convert int8_t to int64"; break;
case EOpConvInt8ToUint8: out.debug << "Convert int8_t to uint8_t";break;
case EOpConvInt8ToUint16: out.debug << "Convert int8_t to uint16_t";break;
case EOpConvInt8ToUint: out.debug << "Convert int8_t to uint"; break;
case EOpConvInt8ToUint64: out.debug << "Convert int8_t to uint64"; break;
// uint8_t -> (u)int*
case EOpConvUint8ToInt8: out.debug << "Convert uint8_t to int8_t";break;
case EOpConvUint8ToInt16: out.debug << "Convert uint8_t to int16_t";break;
case EOpConvUint8ToInt: out.debug << "Convert uint8_t to int"; break;
case EOpConvUint8ToInt64: out.debug << "Convert uint8_t to int64"; break;
case EOpConvUint8ToUint16: out.debug << "Convert uint8_t to uint16_t";break;
case EOpConvUint8ToUint: out.debug << "Convert uint8_t to uint"; break;
case EOpConvUint8ToUint64: out.debug << "Convert uint8_t to uint64"; break;
// int8_t -> float*
case EOpConvInt8ToFloat16: out.debug << "Convert int8_t to float16_t";break;
case EOpConvInt8ToFloat: out.debug << "Convert int8_t to float"; break;
case EOpConvInt8ToDouble: out.debug << "Convert int8_t to double"; break;
// uint8_t -> float*
case EOpConvUint8ToFloat16: out.debug << "Convert uint8_t to float16_t";break;
case EOpConvUint8ToFloat: out.debug << "Convert uint8_t to float"; break;
case EOpConvUint8ToDouble: out.debug << "Convert uint8_t to double"; break;
// int16_t -> (u)int*
case EOpConvInt16ToInt8: out.debug << "Convert int16_t to int8_t";break;
case EOpConvInt16ToInt: out.debug << "Convert int16_t to int"; break;
case EOpConvInt16ToInt64: out.debug << "Convert int16_t to int64"; break;
case EOpConvInt16ToUint8: out.debug << "Convert int16_t to uint8_t";break;
case EOpConvInt16ToUint16: out.debug << "Convert int16_t to uint16_t";break;
case EOpConvInt16ToUint: out.debug << "Convert int16_t to uint"; break;
case EOpConvInt16ToUint64: out.debug << "Convert int16_t to uint64"; break;
// int16_t -> float*
case EOpConvInt16ToFloat16: out.debug << "Convert int16_t to float16_t";break;
case EOpConvInt16ToFloat: out.debug << "Convert int16_t to float"; break;
case EOpConvInt16ToDouble: out.debug << "Convert int16_t to double"; break;
// uint16_t -> (u)int*
case EOpConvUint16ToInt8: out.debug << "Convert uint16_t to int8_t";break;
case EOpConvUint16ToInt16: out.debug << "Convert uint16_t to int16_t";break;
case EOpConvUint16ToInt: out.debug << "Convert uint16_t to int"; break;
case EOpConvUint16ToInt64: out.debug << "Convert uint16_t to int64"; break;
case EOpConvUint16ToUint8: out.debug << "Convert uint16_t to uint8_t";break;
case EOpConvUint16ToUint: out.debug << "Convert uint16_t to uint"; break;
case EOpConvUint16ToUint64: out.debug << "Convert uint16_t to uint64"; break;
// uint16_t -> float*
case EOpConvUint16ToFloat16: out.debug << "Convert uint16_t to float16_t";break;
case EOpConvUint16ToFloat: out.debug << "Convert uint16_t to float"; break;
case EOpConvUint16ToDouble: out.debug << "Convert uint16_t to double"; break;
// int32_t -> (u)int*
case EOpConvIntToInt8: out.debug << "Convert int to int8_t";break;
case EOpConvIntToInt16: out.debug << "Convert int to int16_t";break;
case EOpConvIntToInt64: out.debug << "Convert int to int64"; break;
case EOpConvIntToUint8: out.debug << "Convert int to uint8_t";break;
case EOpConvIntToUint16: out.debug << "Convert int to uint16_t";break;
case EOpConvIntToUint: out.debug << "Convert int to uint"; break;
case EOpConvIntToUint64: out.debug << "Convert int to uint64"; break;
// int32_t -> float*
case EOpConvIntToFloat16: out.debug << "Convert int to float16_t";break;
case EOpConvIntToFloat: out.debug << "Convert int to float"; break;
case EOpConvIntToDouble: out.debug << "Convert int to double"; break;
// uint32_t -> (u)int*
case EOpConvUintToInt8: out.debug << "Convert uint to int8_t";break;
case EOpConvUintToInt16: out.debug << "Convert uint to int16_t";break;
case EOpConvUintToInt: out.debug << "Convert uint to int";break;
case EOpConvUintToInt64: out.debug << "Convert uint to int64"; break;
case EOpConvUintToUint8: out.debug << "Convert uint to uint8_t";break;
case EOpConvUintToUint16: out.debug << "Convert uint to uint16_t";break;
case EOpConvUintToUint64: out.debug << "Convert uint to uint64"; break;
// uint32_t -> float*
case EOpConvUintToFloat16: out.debug << "Convert uint to float16_t";break;
case EOpConvUintToFloat: out.debug << "Convert uint to float"; break;
case EOpConvUintToDouble: out.debug << "Convert uint to double"; break;
// int64 -> (u)int*
case EOpConvInt64ToInt8: out.debug << "Convert int64 to int8_t"; break;
case EOpConvInt64ToInt16: out.debug << "Convert int64 to int16_t"; break;
case EOpConvInt64ToInt: out.debug << "Convert int64 to int"; break;
case EOpConvInt64ToUint8: out.debug << "Convert int64 to uint8_t";break;
case EOpConvInt64ToUint16: out.debug << "Convert int64 to uint16_t";break;
case EOpConvInt64ToUint: out.debug << "Convert int64 to uint"; break;
case EOpConvInt64ToUint64: out.debug << "Convert int64 to uint64"; break;
// int64 -> float*
case EOpConvInt64ToFloat16: out.debug << "Convert int64 to float16_t";break;
case EOpConvInt64ToFloat: out.debug << "Convert int64 to float"; break;
case EOpConvInt64ToDouble: out.debug << "Convert int64 to double"; break;
// uint64 -> (u)int*
case EOpConvUint64ToInt8: out.debug << "Convert uint64 to int8_t";break;
case EOpConvUint64ToInt16: out.debug << "Convert uint64 to int16_t";break;
case EOpConvUint64ToInt: out.debug << "Convert uint64 to int"; break;
case EOpConvUint64ToInt64: out.debug << "Convert uint64 to int64"; break;
case EOpConvUint64ToUint8: out.debug << "Convert uint64 to uint8_t";break;
case EOpConvUint64ToUint16: out.debug << "Convert uint64 to uint16"; break;
case EOpConvUint64ToUint: out.debug << "Convert uint64 to uint"; break;
// uint64 -> float*
case EOpConvUint64ToFloat16: out.debug << "Convert uint64 to float16_t";break;
case EOpConvUint64ToFloat: out.debug << "Convert uint64 to float"; break;
case EOpConvUint64ToDouble: out.debug << "Convert uint64 to double"; break;
// float16_t -> int*
case EOpConvFloat16ToInt8: out.debug << "Convert float16_t to int8_t"; break;
case EOpConvFloat16ToInt16: out.debug << "Convert float16_t to int16_t"; break;
case EOpConvFloat16ToInt: out.debug << "Convert float16_t to int"; break;
case EOpConvFloat16ToInt64: out.debug << "Convert float16_t to int64"; break;
// float16_t -> uint*
case EOpConvFloat16ToUint8: out.debug << "Convert float16_t to uint8_t"; break;
case EOpConvFloat16ToUint16: out.debug << "Convert float16_t to uint16_t"; break;
case EOpConvFloat16ToUint: out.debug << "Convert float16_t to uint"; break;
case EOpConvFloat16ToUint64: out.debug << "Convert float16_t to uint64"; break;
// float16_t -> float*
case EOpConvFloat16ToFloat: out.debug << "Convert float16_t to float"; break;
case EOpConvFloat16ToDouble: out.debug << "Convert float16_t to double"; break;
// float32 -> float*
case EOpConvFloatToFloat16: out.debug << "Convert float to float16_t"; break;
case EOpConvFloatToDouble: out.debug << "Convert float to double"; break;
// float32_t -> int*
case EOpConvFloatToInt8: out.debug << "Convert float to int8_t"; break;
case EOpConvFloatToInt16: out.debug << "Convert float to int16_t"; break;
case EOpConvFloatToInt: out.debug << "Convert float to int"; break;
case EOpConvFloatToInt64: out.debug << "Convert float to int64"; break;
// float32_t -> uint*
case EOpConvFloatToUint8: out.debug << "Convert float to uint8_t"; break;
case EOpConvFloatToUint16: out.debug << "Convert float to uint16_t"; break;
case EOpConvFloatToUint: out.debug << "Convert float to uint"; break;
case EOpConvFloatToUint64: out.debug << "Convert float to uint64"; break;
// double -> float*
case EOpConvDoubleToFloat16: out.debug << "Convert double to float16_t"; break;
case EOpConvDoubleToFloat: out.debug << "Convert double to float"; break;
// double -> int*
case EOpConvDoubleToInt8: out.debug << "Convert double to int8_t"; break;
case EOpConvDoubleToInt16: out.debug << "Convert double to int16_t"; break;
case EOpConvDoubleToInt: out.debug << "Convert double to int"; break;
case EOpConvDoubleToInt64: out.debug << "Convert double to int64"; break;
// float32_t -> uint*
case EOpConvDoubleToUint8: out.debug << "Convert double to uint8_t"; break;
case EOpConvDoubleToUint16: out.debug << "Convert double to uint16_t"; break;
case EOpConvDoubleToUint: out.debug << "Convert double to uint"; break;
case EOpConvDoubleToUint64: out.debug << "Convert double to uint64"; break;
case EOpConvUint64ToPtr: out.debug << "Convert uint64_t to pointer"; break;
case EOpConvPtrToUint64: out.debug << "Convert pointer to uint64_t"; break;
case EOpConvUint64ToAccStruct: out.debug << "Convert uint64_t to acceleration structure"; break;
case EOpConvUvec2ToAccStruct: out.debug << "Convert uvec2 to acceleration strucuture "; break;
case EOpRadians: out.debug << "radians"; break;
case EOpDegrees: out.debug << "degrees"; break;
case EOpSin: out.debug << "sine"; break;
case EOpCos: out.debug << "cosine"; break;
case EOpTan: out.debug << "tangent"; break;
case EOpAsin: out.debug << "arc sine"; break;
case EOpAcos: out.debug << "arc cosine"; break;
case EOpAtan: out.debug << "arc tangent"; break;
case EOpSinh: out.debug << "hyp. sine"; break;
case EOpCosh: out.debug << "hyp. cosine"; break;
case EOpTanh: out.debug << "hyp. tangent"; break;
case EOpAsinh: out.debug << "arc hyp. sine"; break;
case EOpAcosh: out.debug << "arc hyp. cosine"; break;
case EOpAtanh: out.debug << "arc hyp. tangent"; break;
case EOpExp: out.debug << "exp"; break;
case EOpLog: out.debug << "log"; break;
case EOpExp2: out.debug << "exp2"; break;
case EOpLog2: out.debug << "log2"; break;
case EOpSqrt: out.debug << "sqrt"; break;
case EOpInverseSqrt: out.debug << "inverse sqrt"; break;
case EOpAbs: out.debug << "Absolute value"; break;
case EOpSign: out.debug << "Sign"; break;
case EOpFloor: out.debug << "Floor"; break;
case EOpTrunc: out.debug << "trunc"; break;
case EOpRound: out.debug << "round"; break;
case EOpRoundEven: out.debug << "roundEven"; break;
case EOpCeil: out.debug << "Ceiling"; break;
case EOpFract: out.debug << "Fraction"; break;
case EOpIsNan: out.debug << "isnan"; break;
case EOpIsInf: out.debug << "isinf"; break;
case EOpFloatBitsToInt: out.debug << "floatBitsToInt"; break;
case EOpFloatBitsToUint:out.debug << "floatBitsToUint"; break;
case EOpIntBitsToFloat: out.debug << "intBitsToFloat"; break;
case EOpUintBitsToFloat:out.debug << "uintBitsToFloat"; break;
case EOpDoubleBitsToInt64: out.debug << "doubleBitsToInt64"; break;
case EOpDoubleBitsToUint64: out.debug << "doubleBitsToUint64"; break;
case EOpInt64BitsToDouble: out.debug << "int64BitsToDouble"; break;
case EOpUint64BitsToDouble: out.debug << "uint64BitsToDouble"; break;
case EOpFloat16BitsToInt16: out.debug << "float16BitsToInt16"; break;
case EOpFloat16BitsToUint16: out.debug << "float16BitsToUint16"; break;
case EOpInt16BitsToFloat16: out.debug << "int16BitsToFloat16"; break;
case EOpUint16BitsToFloat16: out.debug << "uint16BitsToFloat16"; break;
case EOpPackSnorm2x16: out.debug << "packSnorm2x16"; break;
case EOpUnpackSnorm2x16:out.debug << "unpackSnorm2x16"; break;
case EOpPackUnorm2x16: out.debug << "packUnorm2x16"; break;
case EOpUnpackUnorm2x16:out.debug << "unpackUnorm2x16"; break;
case EOpPackHalf2x16: out.debug << "packHalf2x16"; break;
case EOpUnpackHalf2x16: out.debug << "unpackHalf2x16"; break;
case EOpPack16: out.debug << "pack16"; break;
case EOpPack32: out.debug << "pack32"; break;
case EOpPack64: out.debug << "pack64"; break;
case EOpUnpack32: out.debug << "unpack32"; break;
case EOpUnpack16: out.debug << "unpack16"; break;
case EOpUnpack8: out.debug << "unpack8"; break;
case EOpPackSnorm4x8: out.debug << "PackSnorm4x8"; break;
case EOpUnpackSnorm4x8: out.debug << "UnpackSnorm4x8"; break;
case EOpPackUnorm4x8: out.debug << "PackUnorm4x8"; break;
case EOpUnpackUnorm4x8: out.debug << "UnpackUnorm4x8"; break;
case EOpPackDouble2x32: out.debug << "PackDouble2x32"; break;
case EOpUnpackDouble2x32: out.debug << "UnpackDouble2x32"; break;
case EOpPackInt2x32: out.debug << "packInt2x32"; break;
case EOpUnpackInt2x32: out.debug << "unpackInt2x32"; break;
case EOpPackUint2x32: out.debug << "packUint2x32"; break;
case EOpUnpackUint2x32: out.debug << "unpackUint2x32"; break;
case EOpPackInt2x16: out.debug << "packInt2x16"; break;
case EOpUnpackInt2x16: out.debug << "unpackInt2x16"; break;
case EOpPackUint2x16: out.debug << "packUint2x16"; break;
case EOpUnpackUint2x16: out.debug << "unpackUint2x16"; break;
case EOpPackInt4x16: out.debug << "packInt4x16"; break;
case EOpUnpackInt4x16: out.debug << "unpackInt4x16"; break;
case EOpPackUint4x16: out.debug << "packUint4x16"; break;
case EOpUnpackUint4x16: out.debug << "unpackUint4x16"; break;
case EOpPackFloat2x16: out.debug << "packFloat2x16"; break;
case EOpUnpackFloat2x16: out.debug << "unpackFloat2x16"; break;
case EOpLength: out.debug << "length"; break;
case EOpNormalize: out.debug << "normalize"; break;
case EOpDPdx: out.debug << "dPdx"; break;
case EOpDPdy: out.debug << "dPdy"; break;
case EOpFwidth: out.debug << "fwidth"; break;
case EOpDPdxFine: out.debug << "dPdxFine"; break;
case EOpDPdyFine: out.debug << "dPdyFine"; break;
case EOpFwidthFine: out.debug << "fwidthFine"; break;
case EOpDPdxCoarse: out.debug << "dPdxCoarse"; break;
case EOpDPdyCoarse: out.debug << "dPdyCoarse"; break;
case EOpFwidthCoarse: out.debug << "fwidthCoarse"; break;
case EOpInterpolateAtCentroid: out.debug << "interpolateAtCentroid"; break;
case EOpDeterminant: out.debug << "determinant"; break;
case EOpMatrixInverse: out.debug << "inverse"; break;
case EOpTranspose: out.debug << "transpose"; break;
case EOpAny: out.debug << "any"; break;
case EOpAll: out.debug << "all"; break;
case EOpArrayLength: out.debug << "array length"; break;
case EOpEmitStreamVertex: out.debug << "EmitStreamVertex"; break;
case EOpEndStreamPrimitive: out.debug << "EndStreamPrimitive"; break;
case EOpAtomicCounterIncrement: out.debug << "AtomicCounterIncrement";break;
case EOpAtomicCounterDecrement: out.debug << "AtomicCounterDecrement";break;
case EOpAtomicCounter: out.debug << "AtomicCounter"; break;
case EOpTextureQuerySize: out.debug << "textureSize"; break;
case EOpTextureQueryLod: out.debug << "textureQueryLod"; break;
case EOpTextureQueryLevels: out.debug << "textureQueryLevels"; break;
case EOpTextureQuerySamples: out.debug << "textureSamples"; break;
case EOpImageQuerySize: out.debug << "imageQuerySize"; break;
case EOpImageQuerySamples: out.debug << "imageQuerySamples"; break;
case EOpImageLoad: out.debug << "imageLoad"; break;
case EOpBitFieldReverse: out.debug << "bitFieldReverse"; break;
case EOpBitCount: out.debug << "bitCount"; break;
case EOpFindLSB: out.debug << "findLSB"; break;
case EOpFindMSB: out.debug << "findMSB"; break;
case EOpCountLeadingZeros: out.debug << "countLeadingZeros"; break;
case EOpCountTrailingZeros: out.debug << "countTrailingZeros"; break;
case EOpNoise: out.debug << "noise"; break;
case EOpBallot: out.debug << "ballot"; break;
case EOpReadFirstInvocation: out.debug << "readFirstInvocation"; break;
case EOpAnyInvocation: out.debug << "anyInvocation"; break;
case EOpAllInvocations: out.debug << "allInvocations"; break;
case EOpAllInvocationsEqual: out.debug << "allInvocationsEqual"; break;
case EOpSubgroupElect: out.debug << "subgroupElect"; break;
case EOpSubgroupAll: out.debug << "subgroupAll"; break;
case EOpSubgroupAny: out.debug << "subgroupAny"; break;
case EOpSubgroupAllEqual: out.debug << "subgroupAllEqual"; break;
case EOpSubgroupBroadcast: out.debug << "subgroupBroadcast"; break;
case EOpSubgroupBroadcastFirst: out.debug << "subgroupBroadcastFirst"; break;
case EOpSubgroupBallot: out.debug << "subgroupBallot"; break;
case EOpSubgroupInverseBallot: out.debug << "subgroupInverseBallot"; break;
case EOpSubgroupBallotBitExtract: out.debug << "subgroupBallotBitExtract"; break;
case EOpSubgroupBallotBitCount: out.debug << "subgroupBallotBitCount"; break;
case EOpSubgroupBallotInclusiveBitCount: out.debug << "subgroupBallotInclusiveBitCount"; break;
case EOpSubgroupBallotExclusiveBitCount: out.debug << "subgroupBallotExclusiveBitCount"; break;
case EOpSubgroupBallotFindLSB: out.debug << "subgroupBallotFindLSB"; break;
case EOpSubgroupBallotFindMSB: out.debug << "subgroupBallotFindMSB"; break;
case EOpSubgroupShuffle: out.debug << "subgroupShuffle"; break;
case EOpSubgroupShuffleXor: out.debug << "subgroupShuffleXor"; break;
case EOpSubgroupShuffleUp: out.debug << "subgroupShuffleUp"; break;
case EOpSubgroupShuffleDown: out.debug << "subgroupShuffleDown"; break;
case EOpSubgroupRotate: out.debug << "subgroupRotate"; break;
case EOpSubgroupClusteredRotate: out.debug << "subgroupClusteredRotate"; break;
case EOpSubgroupAdd: out.debug << "subgroupAdd"; break;
case EOpSubgroupMul: out.debug << "subgroupMul"; break;
case EOpSubgroupMin: out.debug << "subgroupMin"; break;
case EOpSubgroupMax: out.debug << "subgroupMax"; break;
case EOpSubgroupAnd: out.debug << "subgroupAnd"; break;
case EOpSubgroupOr: out.debug << "subgroupOr"; break;
case EOpSubgroupXor: out.debug << "subgroupXor"; break;
case EOpSubgroupInclusiveAdd: out.debug << "subgroupInclusiveAdd"; break;
case EOpSubgroupInclusiveMul: out.debug << "subgroupInclusiveMul"; break;
case EOpSubgroupInclusiveMin: out.debug << "subgroupInclusiveMin"; break;
case EOpSubgroupInclusiveMax: out.debug << "subgroupInclusiveMax"; break;
case EOpSubgroupInclusiveAnd: out.debug << "subgroupInclusiveAnd"; break;
case EOpSubgroupInclusiveOr: out.debug << "subgroupInclusiveOr"; break;
case EOpSubgroupInclusiveXor: out.debug << "subgroupInclusiveXor"; break;
case EOpSubgroupExclusiveAdd: out.debug << "subgroupExclusiveAdd"; break;
case EOpSubgroupExclusiveMul: out.debug << "subgroupExclusiveMul"; break;
case EOpSubgroupExclusiveMin: out.debug << "subgroupExclusiveMin"; break;
case EOpSubgroupExclusiveMax: out.debug << "subgroupExclusiveMax"; break;
case EOpSubgroupExclusiveAnd: out.debug << "subgroupExclusiveAnd"; break;
case EOpSubgroupExclusiveOr: out.debug << "subgroupExclusiveOr"; break;
case EOpSubgroupExclusiveXor: out.debug << "subgroupExclusiveXor"; break;
case EOpSubgroupClusteredAdd: out.debug << "subgroupClusteredAdd"; break;
case EOpSubgroupClusteredMul: out.debug << "subgroupClusteredMul"; break;
case EOpSubgroupClusteredMin: out.debug << "subgroupClusteredMin"; break;
case EOpSubgroupClusteredMax: out.debug << "subgroupClusteredMax"; break;
case EOpSubgroupClusteredAnd: out.debug << "subgroupClusteredAnd"; break;
case EOpSubgroupClusteredOr: out.debug << "subgroupClusteredOr"; break;
case EOpSubgroupClusteredXor: out.debug << "subgroupClusteredXor"; break;
case EOpSubgroupQuadBroadcast: out.debug << "subgroupQuadBroadcast"; break;
case EOpSubgroupQuadSwapHorizontal: out.debug << "subgroupQuadSwapHorizontal"; break;
case EOpSubgroupQuadSwapVertical: out.debug << "subgroupQuadSwapVertical"; break;
case EOpSubgroupQuadSwapDiagonal: out.debug << "subgroupQuadSwapDiagonal"; break;
case EOpSubgroupQuadAll: out.debug << "subgroupQuadAll"; break;
case EOpSubgroupQuadAny: out.debug << "subgroupQuadAny"; break;
case EOpSubgroupPartition: out.debug << "subgroupPartitionNV"; break;
case EOpSubgroupPartitionedAdd: out.debug << "subgroupPartitionedAddNV"; break;
case EOpSubgroupPartitionedMul: out.debug << "subgroupPartitionedMulNV"; break;
case EOpSubgroupPartitionedMin: out.debug << "subgroupPartitionedMinNV"; break;
case EOpSubgroupPartitionedMax: out.debug << "subgroupPartitionedMaxNV"; break;
case EOpSubgroupPartitionedAnd: out.debug << "subgroupPartitionedAndNV"; break;
case EOpSubgroupPartitionedOr: out.debug << "subgroupPartitionedOrNV"; break;
case EOpSubgroupPartitionedXor: out.debug << "subgroupPartitionedXorNV"; break;
case EOpSubgroupPartitionedInclusiveAdd: out.debug << "subgroupPartitionedInclusiveAddNV"; break;
case EOpSubgroupPartitionedInclusiveMul: out.debug << "subgroupPartitionedInclusiveMulNV"; break;
case EOpSubgroupPartitionedInclusiveMin: out.debug << "subgroupPartitionedInclusiveMinNV"; break;
case EOpSubgroupPartitionedInclusiveMax: out.debug << "subgroupPartitionedInclusiveMaxNV"; break;
case EOpSubgroupPartitionedInclusiveAnd: out.debug << "subgroupPartitionedInclusiveAndNV"; break;
case EOpSubgroupPartitionedInclusiveOr: out.debug << "subgroupPartitionedInclusiveOrNV"; break;
case EOpSubgroupPartitionedInclusiveXor: out.debug << "subgroupPartitionedInclusiveXorNV"; break;
case EOpSubgroupPartitionedExclusiveAdd: out.debug << "subgroupPartitionedExclusiveAddNV"; break;
case EOpSubgroupPartitionedExclusiveMul: out.debug << "subgroupPartitionedExclusiveMulNV"; break;
case EOpSubgroupPartitionedExclusiveMin: out.debug << "subgroupPartitionedExclusiveMinNV"; break;
case EOpSubgroupPartitionedExclusiveMax: out.debug << "subgroupPartitionedExclusiveMaxNV"; break;
case EOpSubgroupPartitionedExclusiveAnd: out.debug << "subgroupPartitionedExclusiveAndNV"; break;
case EOpSubgroupPartitionedExclusiveOr: out.debug << "subgroupPartitionedExclusiveOrNV"; break;
case EOpSubgroupPartitionedExclusiveXor: out.debug << "subgroupPartitionedExclusiveXorNV"; break;
case EOpClip: out.debug << "clip"; break;
case EOpIsFinite: out.debug << "isfinite"; break;
case EOpLog10: out.debug << "log10"; break;
case EOpRcp: out.debug << "rcp"; break;
case EOpSaturate: out.debug << "saturate"; break;
case EOpSparseTexelsResident: out.debug << "sparseTexelsResident"; break;
case EOpMinInvocations: out.debug << "minInvocations"; break;
case EOpMaxInvocations: out.debug << "maxInvocations"; break;
case EOpAddInvocations: out.debug << "addInvocations"; break;
case EOpMinInvocationsNonUniform: out.debug << "minInvocationsNonUniform"; break;
case EOpMaxInvocationsNonUniform: out.debug << "maxInvocationsNonUniform"; break;
case EOpAddInvocationsNonUniform: out.debug << "addInvocationsNonUniform"; break;
case EOpMinInvocationsInclusiveScan: out.debug << "minInvocationsInclusiveScan"; break;
case EOpMaxInvocationsInclusiveScan: out.debug << "maxInvocationsInclusiveScan"; break;
case EOpAddInvocationsInclusiveScan: out.debug << "addInvocationsInclusiveScan"; break;
case EOpMinInvocationsInclusiveScanNonUniform: out.debug << "minInvocationsInclusiveScanNonUniform"; break;
case EOpMaxInvocationsInclusiveScanNonUniform: out.debug << "maxInvocationsInclusiveScanNonUniform"; break;
case EOpAddInvocationsInclusiveScanNonUniform: out.debug << "addInvocationsInclusiveScanNonUniform"; break;
case EOpMinInvocationsExclusiveScan: out.debug << "minInvocationsExclusiveScan"; break;
case EOpMaxInvocationsExclusiveScan: out.debug << "maxInvocationsExclusiveScan"; break;
case EOpAddInvocationsExclusiveScan: out.debug << "addInvocationsExclusiveScan"; break;
case EOpMinInvocationsExclusiveScanNonUniform: out.debug << "minInvocationsExclusiveScanNonUniform"; break;
case EOpMaxInvocationsExclusiveScanNonUniform: out.debug << "maxInvocationsExclusiveScanNonUniform"; break;
case EOpAddInvocationsExclusiveScanNonUniform: out.debug << "addInvocationsExclusiveScanNonUniform"; break;
case EOpMbcnt: out.debug << "mbcnt"; break;
case EOpFragmentMaskFetch: out.debug << "fragmentMaskFetchAMD"; break;
case EOpFragmentFetch: out.debug << "fragmentFetchAMD"; break;
case EOpCubeFaceIndex: out.debug << "cubeFaceIndex"; break;
case EOpCubeFaceCoord: out.debug << "cubeFaceCoord"; break;
case EOpSubpassLoad: out.debug << "subpassLoad"; break;
case EOpSubpassLoadMS: out.debug << "subpassLoadMS"; break;
case EOpColorAttachmentReadEXT: out.debug << "colorAttachmentReadEXT"; break;
case EOpConstructReference: out.debug << "Construct reference type"; break;
case EOpDeclare: out.debug << "Declare"; break;
case EOpSpirvInst: out.debug << "spirv_instruction"; break;
default: out.debug.message(EPrefixError, "Bad unary op");
}
out.debug << " (" << node->getCompleteString() << ")";
out.debug << "\n";
return true;
}
bool TOutputTraverser::visitAggregate(TVisit /* visit */, TIntermAggregate* node)
{
TInfoSink& out = infoSink;
if (node->getOp() == EOpNull) {
out.debug.message(EPrefixError, "node is still EOpNull!");
return true;
}
OutputTreeText(out, node, depth);
switch (node->getOp()) {
case EOpSequence: out.debug << "Sequence\n"; return true;
case EOpScope: out.debug << "Scope\n"; return true;
case EOpLinkerObjects: out.debug << "Linker Objects\n"; return true;
case EOpComma: out.debug << "Comma"; break;
case EOpFunction: out.debug << "Function Definition: " << node->getName(); break;
case EOpFunctionCall: out.debug << "Function Call: " << node->getName(); break;
case EOpParameters: out.debug << "Function Parameters: "; break;
case EOpConstructFloat: out.debug << "Construct float"; break;
case EOpConstructDouble:out.debug << "Construct double"; break;
case EOpConstructVec2: out.debug << "Construct vec2"; break;
case EOpConstructVec3: out.debug << "Construct vec3"; break;
case EOpConstructVec4: out.debug << "Construct vec4"; break;
case EOpConstructDVec2: out.debug << "Construct dvec2"; break;
case EOpConstructDVec3: out.debug << "Construct dvec3"; break;
case EOpConstructDVec4: out.debug << "Construct dvec4"; break;
case EOpConstructBool: out.debug << "Construct bool"; break;
case EOpConstructBVec2: out.debug << "Construct bvec2"; break;
case EOpConstructBVec3: out.debug << "Construct bvec3"; break;
case EOpConstructBVec4: out.debug << "Construct bvec4"; break;
case EOpConstructInt8: out.debug << "Construct int8_t"; break;
case EOpConstructI8Vec2: out.debug << "Construct i8vec2"; break;
case EOpConstructI8Vec3: out.debug << "Construct i8vec3"; break;
case EOpConstructI8Vec4: out.debug << "Construct i8vec4"; break;
case EOpConstructInt: out.debug << "Construct int"; break;
case EOpConstructIVec2: out.debug << "Construct ivec2"; break;
case EOpConstructIVec3: out.debug << "Construct ivec3"; break;
case EOpConstructIVec4: out.debug << "Construct ivec4"; break;
case EOpConstructUint8: out.debug << "Construct uint8_t"; break;
case EOpConstructU8Vec2: out.debug << "Construct u8vec2"; break;
case EOpConstructU8Vec3: out.debug << "Construct u8vec3"; break;
case EOpConstructU8Vec4: out.debug << "Construct u8vec4"; break;
case EOpConstructUint: out.debug << "Construct uint"; break;
case EOpConstructUVec2: out.debug << "Construct uvec2"; break;
case EOpConstructUVec3: out.debug << "Construct uvec3"; break;
case EOpConstructUVec4: out.debug << "Construct uvec4"; break;
case EOpConstructInt64: out.debug << "Construct int64"; break;
case EOpConstructI64Vec2: out.debug << "Construct i64vec2"; break;
case EOpConstructI64Vec3: out.debug << "Construct i64vec3"; break;
case EOpConstructI64Vec4: out.debug << "Construct i64vec4"; break;
case EOpConstructUint64: out.debug << "Construct uint64"; break;
case EOpConstructU64Vec2: out.debug << "Construct u64vec2"; break;
case EOpConstructU64Vec3: out.debug << "Construct u64vec3"; break;
case EOpConstructU64Vec4: out.debug << "Construct u64vec4"; break;
case EOpConstructInt16: out.debug << "Construct int16_t"; break;
case EOpConstructI16Vec2: out.debug << "Construct i16vec2"; break;
case EOpConstructI16Vec3: out.debug << "Construct i16vec3"; break;
case EOpConstructI16Vec4: out.debug << "Construct i16vec4"; break;
case EOpConstructUint16: out.debug << "Construct uint16_t"; break;
case EOpConstructU16Vec2: out.debug << "Construct u16vec2"; break;
case EOpConstructU16Vec3: out.debug << "Construct u16vec3"; break;
case EOpConstructU16Vec4: out.debug << "Construct u16vec4"; break;
case EOpConstructMat2x2: out.debug << "Construct mat2"; break;
case EOpConstructMat2x3: out.debug << "Construct mat2x3"; break;
case EOpConstructMat2x4: out.debug << "Construct mat2x4"; break;
case EOpConstructMat3x2: out.debug << "Construct mat3x2"; break;
case EOpConstructMat3x3: out.debug << "Construct mat3"; break;
case EOpConstructMat3x4: out.debug << "Construct mat3x4"; break;
case EOpConstructMat4x2: out.debug << "Construct mat4x2"; break;
case EOpConstructMat4x3: out.debug << "Construct mat4x3"; break;
case EOpConstructMat4x4: out.debug << "Construct mat4"; break;
case EOpConstructDMat2x2: out.debug << "Construct dmat2"; break;
case EOpConstructDMat2x3: out.debug << "Construct dmat2x3"; break;
case EOpConstructDMat2x4: out.debug << "Construct dmat2x4"; break;
case EOpConstructDMat3x2: out.debug << "Construct dmat3x2"; break;
case EOpConstructDMat3x3: out.debug << "Construct dmat3"; break;
case EOpConstructDMat3x4: out.debug << "Construct dmat3x4"; break;
case EOpConstructDMat4x2: out.debug << "Construct dmat4x2"; break;
case EOpConstructDMat4x3: out.debug << "Construct dmat4x3"; break;
case EOpConstructDMat4x4: out.debug << "Construct dmat4"; break;
case EOpConstructIMat2x2: out.debug << "Construct imat2"; break;
case EOpConstructIMat2x3: out.debug << "Construct imat2x3"; break;
case EOpConstructIMat2x4: out.debug << "Construct imat2x4"; break;
case EOpConstructIMat3x2: out.debug << "Construct imat3x2"; break;
case EOpConstructIMat3x3: out.debug << "Construct imat3"; break;
case EOpConstructIMat3x4: out.debug << "Construct imat3x4"; break;
case EOpConstructIMat4x2: out.debug << "Construct imat4x2"; break;
case EOpConstructIMat4x3: out.debug << "Construct imat4x3"; break;
case EOpConstructIMat4x4: out.debug << "Construct imat4"; break;
case EOpConstructUMat2x2: out.debug << "Construct umat2"; break;
case EOpConstructUMat2x3: out.debug << "Construct umat2x3"; break;
case EOpConstructUMat2x4: out.debug << "Construct umat2x4"; break;
case EOpConstructUMat3x2: out.debug << "Construct umat3x2"; break;
case EOpConstructUMat3x3: out.debug << "Construct umat3"; break;
case EOpConstructUMat3x4: out.debug << "Construct umat3x4"; break;
case EOpConstructUMat4x2: out.debug << "Construct umat4x2"; break;
case EOpConstructUMat4x3: out.debug << "Construct umat4x3"; break;
case EOpConstructUMat4x4: out.debug << "Construct umat4"; break;
case EOpConstructBMat2x2: out.debug << "Construct bmat2"; break;
case EOpConstructBMat2x3: out.debug << "Construct bmat2x3"; break;
case EOpConstructBMat2x4: out.debug << "Construct bmat2x4"; break;
case EOpConstructBMat3x2: out.debug << "Construct bmat3x2"; break;
case EOpConstructBMat3x3: out.debug << "Construct bmat3"; break;
case EOpConstructBMat3x4: out.debug << "Construct bmat3x4"; break;
case EOpConstructBMat4x2: out.debug << "Construct bmat4x2"; break;
case EOpConstructBMat4x3: out.debug << "Construct bmat4x3"; break;
case EOpConstructBMat4x4: out.debug << "Construct bmat4"; break;
case EOpConstructFloat16: out.debug << "Construct float16_t"; break;
case EOpConstructF16Vec2: out.debug << "Construct f16vec2"; break;
case EOpConstructF16Vec3: out.debug << "Construct f16vec3"; break;
case EOpConstructF16Vec4: out.debug << "Construct f16vec4"; break;
case EOpConstructF16Mat2x2: out.debug << "Construct f16mat2"; break;
case EOpConstructF16Mat2x3: out.debug << "Construct f16mat2x3"; break;
case EOpConstructF16Mat2x4: out.debug << "Construct f16mat2x4"; break;
case EOpConstructF16Mat3x2: out.debug << "Construct f16mat3x2"; break;
case EOpConstructF16Mat3x3: out.debug << "Construct f16mat3"; break;
case EOpConstructF16Mat3x4: out.debug << "Construct f16mat3x4"; break;
case EOpConstructF16Mat4x2: out.debug << "Construct f16mat4x2"; break;
case EOpConstructF16Mat4x3: out.debug << "Construct f16mat4x3"; break;
case EOpConstructF16Mat4x4: out.debug << "Construct f16mat4"; break;
case EOpConstructStruct: out.debug << "Construct structure"; break;
case EOpConstructTextureSampler: out.debug << "Construct combined texture-sampler"; break;
case EOpConstructReference: out.debug << "Construct reference"; break;
case EOpConstructCooperativeMatrixNV: out.debug << "Construct cooperative matrix NV"; break;
case EOpConstructCooperativeMatrixKHR: out.debug << "Construct cooperative matrix KHR"; break;
case EOpConstructAccStruct: out.debug << "Construct acceleration structure"; break;
case EOpLessThan: out.debug << "Compare Less Than"; break;
case EOpGreaterThan: out.debug << "Compare Greater Than"; break;
case EOpLessThanEqual: out.debug << "Compare Less Than or Equal"; break;
case EOpGreaterThanEqual: out.debug << "Compare Greater Than or Equal"; break;
case EOpVectorEqual: out.debug << "Equal"; break;
case EOpVectorNotEqual: out.debug << "NotEqual"; break;
case EOpMod: out.debug << "mod"; break;
case EOpModf: out.debug << "modf"; break;
case EOpPow: out.debug << "pow"; break;
case EOpAtan: out.debug << "arc tangent"; break;
case EOpMin: out.debug << "min"; break;
case EOpMax: out.debug << "max"; break;
case EOpClamp: out.debug << "clamp"; break;
case EOpMix: out.debug << "mix"; break;
case EOpStep: out.debug << "step"; break;
case EOpSmoothStep: out.debug << "smoothstep"; break;
case EOpDistance: out.debug << "distance"; break;
case EOpDot: out.debug << "dot-product"; break;
case EOpCross: out.debug << "cross-product"; break;
case EOpFaceForward: out.debug << "face-forward"; break;
case EOpReflect: out.debug << "reflect"; break;
case EOpRefract: out.debug << "refract"; break;
case EOpMul: out.debug << "component-wise multiply"; break;
case EOpOuterProduct: out.debug << "outer product"; break;
case EOpEmitVertex: out.debug << "EmitVertex"; break;
case EOpEndPrimitive: out.debug << "EndPrimitive"; break;
case EOpBarrier: out.debug << "Barrier"; break;
case EOpMemoryBarrier: out.debug << "MemoryBarrier"; break;
case EOpMemoryBarrierAtomicCounter: out.debug << "MemoryBarrierAtomicCounter"; break;
case EOpMemoryBarrierBuffer: out.debug << "MemoryBarrierBuffer"; break;
case EOpMemoryBarrierImage: out.debug << "MemoryBarrierImage"; break;
case EOpMemoryBarrierShared: out.debug << "MemoryBarrierShared"; break;
case EOpGroupMemoryBarrier: out.debug << "GroupMemoryBarrier"; break;
case EOpReadInvocation: out.debug << "readInvocation"; break;
case EOpSwizzleInvocations: out.debug << "swizzleInvocations"; break;
case EOpSwizzleInvocationsMasked: out.debug << "swizzleInvocationsMasked"; break;
case EOpWriteInvocation: out.debug << "writeInvocation"; break;
case EOpMin3: out.debug << "min3"; break;
case EOpMax3: out.debug << "max3"; break;
case EOpMid3: out.debug << "mid3"; break;
case EOpTime: out.debug << "time"; break;
case EOpAtomicAdd: out.debug << "AtomicAdd"; break;
case EOpAtomicSubtract: out.debug << "AtomicSubtract"; break;
case EOpAtomicMin: out.debug << "AtomicMin"; break;
case EOpAtomicMax: out.debug << "AtomicMax"; break;
case EOpAtomicAnd: out.debug << "AtomicAnd"; break;
case EOpAtomicOr: out.debug << "AtomicOr"; break;
case EOpAtomicXor: out.debug << "AtomicXor"; break;
case EOpAtomicExchange: out.debug << "AtomicExchange"; break;
case EOpAtomicCompSwap: out.debug << "AtomicCompSwap"; break;
case EOpAtomicLoad: out.debug << "AtomicLoad"; break;
case EOpAtomicStore: out.debug << "AtomicStore"; break;
case EOpAtomicCounterAdd: out.debug << "AtomicCounterAdd"; break;
case EOpAtomicCounterSubtract: out.debug << "AtomicCounterSubtract"; break;
case EOpAtomicCounterMin: out.debug << "AtomicCounterMin"; break;
case EOpAtomicCounterMax: out.debug << "AtomicCounterMax"; break;
case EOpAtomicCounterAnd: out.debug << "AtomicCounterAnd"; break;
case EOpAtomicCounterOr: out.debug << "AtomicCounterOr"; break;
case EOpAtomicCounterXor: out.debug << "AtomicCounterXor"; break;
case EOpAtomicCounterExchange: out.debug << "AtomicCounterExchange"; break;
case EOpAtomicCounterCompSwap: out.debug << "AtomicCounterCompSwap"; break;
case EOpImageQuerySize: out.debug << "imageQuerySize"; break;
case EOpImageQuerySamples: out.debug << "imageQuerySamples"; break;
case EOpImageLoad: out.debug << "imageLoad"; break;
case EOpImageStore: out.debug << "imageStore"; break;
case EOpImageAtomicAdd: out.debug << "imageAtomicAdd"; break;
case EOpImageAtomicMin: out.debug << "imageAtomicMin"; break;
case EOpImageAtomicMax: out.debug << "imageAtomicMax"; break;
case EOpImageAtomicAnd: out.debug << "imageAtomicAnd"; break;
case EOpImageAtomicOr: out.debug << "imageAtomicOr"; break;
case EOpImageAtomicXor: out.debug << "imageAtomicXor"; break;
case EOpImageAtomicExchange: out.debug << "imageAtomicExchange"; break;
case EOpImageAtomicCompSwap: out.debug << "imageAtomicCompSwap"; break;
case EOpImageAtomicLoad: out.debug << "imageAtomicLoad"; break;
case EOpImageAtomicStore: out.debug << "imageAtomicStore"; break;
case EOpImageLoadLod: out.debug << "imageLoadLod"; break;
case EOpImageStoreLod: out.debug << "imageStoreLod"; break;
case EOpTextureQuerySize: out.debug << "textureSize"; break;
case EOpTextureQueryLod: out.debug << "textureQueryLod"; break;
case EOpTextureQueryLevels: out.debug << "textureQueryLevels"; break;
case EOpTextureQuerySamples: out.debug << "textureSamples"; break;
case EOpTexture: out.debug << "texture"; break;
case EOpTextureProj: out.debug << "textureProj"; break;
case EOpTextureLod: out.debug << "textureLod"; break;
case EOpTextureOffset: out.debug << "textureOffset"; break;
case EOpTextureFetch: out.debug << "textureFetch"; break;
case EOpTextureFetchOffset: out.debug << "textureFetchOffset"; break;
case EOpTextureProjOffset: out.debug << "textureProjOffset"; break;
case EOpTextureLodOffset: out.debug << "textureLodOffset"; break;
case EOpTextureProjLod: out.debug << "textureProjLod"; break;
case EOpTextureProjLodOffset: out.debug << "textureProjLodOffset"; break;
case EOpTextureGrad: out.debug << "textureGrad"; break;
case EOpTextureGradOffset: out.debug << "textureGradOffset"; break;
case EOpTextureProjGrad: out.debug << "textureProjGrad"; break;
case EOpTextureProjGradOffset: out.debug << "textureProjGradOffset"; break;
case EOpTextureGather: out.debug << "textureGather"; break;
case EOpTextureGatherOffset: out.debug << "textureGatherOffset"; break;
case EOpTextureGatherOffsets: out.debug << "textureGatherOffsets"; break;
case EOpTextureClamp: out.debug << "textureClamp"; break;
case EOpTextureOffsetClamp: out.debug << "textureOffsetClamp"; break;
case EOpTextureGradClamp: out.debug << "textureGradClamp"; break;
case EOpTextureGradOffsetClamp: out.debug << "textureGradOffsetClamp"; break;
case EOpTextureGatherLod: out.debug << "textureGatherLod"; break;
case EOpTextureGatherLodOffset: out.debug << "textureGatherLodOffset"; break;
case EOpTextureGatherLodOffsets: out.debug << "textureGatherLodOffsets"; break;
case EOpSparseTexture: out.debug << "sparseTexture"; break;
case EOpSparseTextureOffset: out.debug << "sparseTextureOffset"; break;
case EOpSparseTextureLod: out.debug << "sparseTextureLod"; break;
case EOpSparseTextureLodOffset: out.debug << "sparseTextureLodOffset"; break;
case EOpSparseTextureFetch: out.debug << "sparseTexelFetch"; break;
case EOpSparseTextureFetchOffset: out.debug << "sparseTexelFetchOffset"; break;
case EOpSparseTextureGrad: out.debug << "sparseTextureGrad"; break;
case EOpSparseTextureGradOffset: out.debug << "sparseTextureGradOffset"; break;
case EOpSparseTextureGather: out.debug << "sparseTextureGather"; break;
case EOpSparseTextureGatherOffset: out.debug << "sparseTextureGatherOffset"; break;
case EOpSparseTextureGatherOffsets: out.debug << "sparseTextureGatherOffsets"; break;
case EOpSparseImageLoad: out.debug << "sparseImageLoad"; break;
case EOpSparseTextureClamp: out.debug << "sparseTextureClamp"; break;
case EOpSparseTextureOffsetClamp: out.debug << "sparseTextureOffsetClamp"; break;
case EOpSparseTextureGradClamp: out.debug << "sparseTextureGradClamp"; break;
case EOpSparseTextureGradOffsetClamp: out.debug << "sparseTextureGradOffsetClam"; break;
case EOpSparseTextureGatherLod: out.debug << "sparseTextureGatherLod"; break;
case EOpSparseTextureGatherLodOffset: out.debug << "sparseTextureGatherLodOffset"; break;
case EOpSparseTextureGatherLodOffsets: out.debug << "sparseTextureGatherLodOffsets"; break;
case EOpSparseImageLoadLod: out.debug << "sparseImageLoadLod"; break;
case EOpImageSampleFootprintNV: out.debug << "imageSampleFootprintNV"; break;
case EOpImageSampleFootprintClampNV: out.debug << "imageSampleFootprintClampNV"; break;
case EOpImageSampleFootprintLodNV: out.debug << "imageSampleFootprintLodNV"; break;
case EOpImageSampleFootprintGradNV: out.debug << "imageSampleFootprintGradNV"; break;
case EOpImageSampleFootprintGradClampNV: out.debug << "mageSampleFootprintGradClampNV"; break;
case EOpAddCarry: out.debug << "addCarry"; break;
case EOpSubBorrow: out.debug << "subBorrow"; break;
case EOpUMulExtended: out.debug << "uMulExtended"; break;
case EOpIMulExtended: out.debug << "iMulExtended"; break;
case EOpBitfieldExtract: out.debug << "bitfieldExtract"; break;
case EOpBitfieldInsert: out.debug << "bitfieldInsert"; break;
case EOpFma: out.debug << "fma"; break;
case EOpFrexp: out.debug << "frexp"; break;
case EOpLdexp: out.debug << "ldexp"; break;
case EOpInterpolateAtSample: out.debug << "interpolateAtSample"; break;
case EOpInterpolateAtOffset: out.debug << "interpolateAtOffset"; break;
case EOpInterpolateAtVertex: out.debug << "interpolateAtVertex"; break;
case EOpSinCos: out.debug << "sincos"; break;
case EOpGenMul: out.debug << "mul"; break;
case EOpAllMemoryBarrierWithGroupSync: out.debug << "AllMemoryBarrierWithGroupSync"; break;
case EOpDeviceMemoryBarrier: out.debug << "DeviceMemoryBarrier"; break;
case EOpDeviceMemoryBarrierWithGroupSync: out.debug << "DeviceMemoryBarrierWithGroupSync"; break;
case EOpWorkgroupMemoryBarrier: out.debug << "WorkgroupMemoryBarrier"; break;
case EOpWorkgroupMemoryBarrierWithGroupSync: out.debug << "WorkgroupMemoryBarrierWithGroupSync"; break;
case EOpSubgroupBarrier: out.debug << "subgroupBarrier"; break;
case EOpSubgroupMemoryBarrier: out.debug << "subgroupMemoryBarrier"; break;
case EOpSubgroupMemoryBarrierBuffer: out.debug << "subgroupMemoryBarrierBuffer"; break;
case EOpSubgroupMemoryBarrierImage: out.debug << "subgroupMemoryBarrierImage"; break;
case EOpSubgroupMemoryBarrierShared: out.debug << "subgroupMemoryBarrierShared"; break;
case EOpSubgroupElect: out.debug << "subgroupElect"; break;
case EOpSubgroupAll: out.debug << "subgroupAll"; break;
case EOpSubgroupAny: out.debug << "subgroupAny"; break;
case EOpSubgroupAllEqual: out.debug << "subgroupAllEqual"; break;
case EOpSubgroupBroadcast: out.debug << "subgroupBroadcast"; break;
case EOpSubgroupBroadcastFirst: out.debug << "subgroupBroadcastFirst"; break;
case EOpSubgroupBallot: out.debug << "subgroupBallot"; break;
case EOpSubgroupInverseBallot: out.debug << "subgroupInverseBallot"; break;
case EOpSubgroupBallotBitExtract: out.debug << "subgroupBallotBitExtract"; break;
case EOpSubgroupBallotBitCount: out.debug << "subgroupBallotBitCount"; break;
case EOpSubgroupBallotInclusiveBitCount: out.debug << "subgroupBallotInclusiveBitCount"; break;
case EOpSubgroupBallotExclusiveBitCount: out.debug << "subgroupBallotExclusiveBitCount"; break;
case EOpSubgroupBallotFindLSB: out.debug << "subgroupBallotFindLSB"; break;
case EOpSubgroupBallotFindMSB: out.debug << "subgroupBallotFindMSB"; break;
case EOpSubgroupShuffle: out.debug << "subgroupShuffle"; break;
case EOpSubgroupShuffleXor: out.debug << "subgroupShuffleXor"; break;
case EOpSubgroupShuffleUp: out.debug << "subgroupShuffleUp"; break;
case EOpSubgroupShuffleDown: out.debug << "subgroupShuffleDown"; break;
case EOpSubgroupRotate: out.debug << "subgroupRotate"; break;
case EOpSubgroupClusteredRotate: out.debug << "subgroupClusteredRotate"; break;
case EOpSubgroupAdd: out.debug << "subgroupAdd"; break;
case EOpSubgroupMul: out.debug << "subgroupMul"; break;
case EOpSubgroupMin: out.debug << "subgroupMin"; break;
case EOpSubgroupMax: out.debug << "subgroupMax"; break;
case EOpSubgroupAnd: out.debug << "subgroupAnd"; break;
case EOpSubgroupOr: out.debug << "subgroupOr"; break;
case EOpSubgroupXor: out.debug << "subgroupXor"; break;
case EOpSubgroupInclusiveAdd: out.debug << "subgroupInclusiveAdd"; break;
case EOpSubgroupInclusiveMul: out.debug << "subgroupInclusiveMul"; break;
case EOpSubgroupInclusiveMin: out.debug << "subgroupInclusiveMin"; break;
case EOpSubgroupInclusiveMax: out.debug << "subgroupInclusiveMax"; break;
case EOpSubgroupInclusiveAnd: out.debug << "subgroupInclusiveAnd"; break;
case EOpSubgroupInclusiveOr: out.debug << "subgroupInclusiveOr"; break;
case EOpSubgroupInclusiveXor: out.debug << "subgroupInclusiveXor"; break;
case EOpSubgroupExclusiveAdd: out.debug << "subgroupExclusiveAdd"; break;
case EOpSubgroupExclusiveMul: out.debug << "subgroupExclusiveMul"; break;
case EOpSubgroupExclusiveMin: out.debug << "subgroupExclusiveMin"; break;
case EOpSubgroupExclusiveMax: out.debug << "subgroupExclusiveMax"; break;
case EOpSubgroupExclusiveAnd: out.debug << "subgroupExclusiveAnd"; break;
case EOpSubgroupExclusiveOr: out.debug << "subgroupExclusiveOr"; break;
case EOpSubgroupExclusiveXor: out.debug << "subgroupExclusiveXor"; break;
case EOpSubgroupClusteredAdd: out.debug << "subgroupClusteredAdd"; break;
case EOpSubgroupClusteredMul: out.debug << "subgroupClusteredMul"; break;
case EOpSubgroupClusteredMin: out.debug << "subgroupClusteredMin"; break;
case EOpSubgroupClusteredMax: out.debug << "subgroupClusteredMax"; break;
case EOpSubgroupClusteredAnd: out.debug << "subgroupClusteredAnd"; break;
case EOpSubgroupClusteredOr: out.debug << "subgroupClusteredOr"; break;
case EOpSubgroupClusteredXor: out.debug << "subgroupClusteredXor"; break;
case EOpSubgroupQuadBroadcast: out.debug << "subgroupQuadBroadcast"; break;
case EOpSubgroupQuadSwapHorizontal: out.debug << "subgroupQuadSwapHorizontal"; break;
case EOpSubgroupQuadSwapVertical: out.debug << "subgroupQuadSwapVertical"; break;
case EOpSubgroupQuadSwapDiagonal: out.debug << "subgroupQuadSwapDiagonal"; break;
case EOpSubgroupQuadAll: out.debug << "subgroupQuadAll"; break;
case EOpSubgroupQuadAny: out.debug << "subgroupQuadAny"; break;
case EOpSubgroupPartition: out.debug << "subgroupPartitionNV"; break;
case EOpSubgroupPartitionedAdd: out.debug << "subgroupPartitionedAddNV"; break;
case EOpSubgroupPartitionedMul: out.debug << "subgroupPartitionedMulNV"; break;
case EOpSubgroupPartitionedMin: out.debug << "subgroupPartitionedMinNV"; break;
case EOpSubgroupPartitionedMax: out.debug << "subgroupPartitionedMaxNV"; break;
case EOpSubgroupPartitionedAnd: out.debug << "subgroupPartitionedAndNV"; break;
case EOpSubgroupPartitionedOr: out.debug << "subgroupPartitionedOrNV"; break;
case EOpSubgroupPartitionedXor: out.debug << "subgroupPartitionedXorNV"; break;
case EOpSubgroupPartitionedInclusiveAdd: out.debug << "subgroupPartitionedInclusiveAddNV"; break;
case EOpSubgroupPartitionedInclusiveMul: out.debug << "subgroupPartitionedInclusiveMulNV"; break;
case EOpSubgroupPartitionedInclusiveMin: out.debug << "subgroupPartitionedInclusiveMinNV"; break;
case EOpSubgroupPartitionedInclusiveMax: out.debug << "subgroupPartitionedInclusiveMaxNV"; break;
case EOpSubgroupPartitionedInclusiveAnd: out.debug << "subgroupPartitionedInclusiveAndNV"; break;
case EOpSubgroupPartitionedInclusiveOr: out.debug << "subgroupPartitionedInclusiveOrNV"; break;
case EOpSubgroupPartitionedInclusiveXor: out.debug << "subgroupPartitionedInclusiveXorNV"; break;
case EOpSubgroupPartitionedExclusiveAdd: out.debug << "subgroupPartitionedExclusiveAddNV"; break;
case EOpSubgroupPartitionedExclusiveMul: out.debug << "subgroupPartitionedExclusiveMulNV"; break;
case EOpSubgroupPartitionedExclusiveMin: out.debug << "subgroupPartitionedExclusiveMinNV"; break;
case EOpSubgroupPartitionedExclusiveMax: out.debug << "subgroupPartitionedExclusiveMaxNV"; break;
case EOpSubgroupPartitionedExclusiveAnd: out.debug << "subgroupPartitionedExclusiveAndNV"; break;
case EOpSubgroupPartitionedExclusiveOr: out.debug << "subgroupPartitionedExclusiveOrNV"; break;
case EOpSubgroupPartitionedExclusiveXor: out.debug << "subgroupPartitionedExclusiveXorNV"; break;
case EOpSubpassLoad: out.debug << "subpassLoad"; break;
case EOpSubpassLoadMS: out.debug << "subpassLoadMS"; break;
case EOpColorAttachmentReadEXT: out.debug << "colorAttachmentReadEXT"; break;
case EOpTraceNV: out.debug << "traceNV"; break;
case EOpTraceRayMotionNV: out.debug << "traceRayMotionNV"; break;
case EOpTraceKHR: out.debug << "traceRayKHR"; break;
case EOpReportIntersection: out.debug << "reportIntersectionNV"; break;
case EOpIgnoreIntersectionNV: out.debug << "ignoreIntersectionNV"; break;
case EOpIgnoreIntersectionKHR: out.debug << "ignoreIntersectionKHR"; break;
case EOpTerminateRayNV: out.debug << "terminateRayNV"; break;
case EOpTerminateRayKHR: out.debug << "terminateRayKHR"; break;
case EOpExecuteCallableNV: out.debug << "executeCallableNV"; break;
case EOpExecuteCallableKHR: out.debug << "executeCallableKHR"; break;
case EOpWritePackedPrimitiveIndices4x8NV: out.debug << "writePackedPrimitiveIndices4x8NV"; break;
case EOpEmitMeshTasksEXT: out.debug << "EmitMeshTasksEXT"; break;
case EOpSetMeshOutputsEXT: out.debug << "SetMeshOutputsEXT"; break;
case EOpRayQueryInitialize: out.debug << "rayQueryInitializeEXT"; break;
case EOpRayQueryTerminate: out.debug << "rayQueryTerminateEXT"; break;
case EOpRayQueryGenerateIntersection: out.debug << "rayQueryGenerateIntersectionEXT"; break;
case EOpRayQueryConfirmIntersection: out.debug << "rayQueryConfirmIntersectionEXT"; break;
case EOpRayQueryProceed: out.debug << "rayQueryProceedEXT"; break;
case EOpRayQueryGetIntersectionType: out.debug << "rayQueryGetIntersectionTypeEXT"; break;
case EOpRayQueryGetRayTMin: out.debug << "rayQueryGetRayTMinEXT"; break;
case EOpRayQueryGetRayFlags: out.debug << "rayQueryGetRayFlagsEXT"; break;
case EOpRayQueryGetIntersectionT: out.debug << "rayQueryGetIntersectionTEXT"; break;
case EOpRayQueryGetIntersectionInstanceCustomIndex: out.debug << "rayQueryGetIntersectionInstanceCustomIndexEXT"; break;
case EOpRayQueryGetIntersectionInstanceId: out.debug << "rayQueryGetIntersectionInstanceIdEXT"; break;
case EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset: out.debug << "rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT"; break;
case EOpRayQueryGetIntersectionGeometryIndex: out.debug << "rayQueryGetIntersectionGeometryIndexEXT"; break;
case EOpRayQueryGetIntersectionPrimitiveIndex: out.debug << "rayQueryGetIntersectionPrimitiveIndexEXT"; break;
case EOpRayQueryGetIntersectionBarycentrics: out.debug << "rayQueryGetIntersectionBarycentricsEXT"; break;
case EOpRayQueryGetIntersectionFrontFace: out.debug << "rayQueryGetIntersectionFrontFaceEXT"; break;
case EOpRayQueryGetIntersectionCandidateAABBOpaque: out.debug << "rayQueryGetIntersectionCandidateAABBOpaqueEXT"; break;
case EOpRayQueryGetIntersectionObjectRayDirection: out.debug << "rayQueryGetIntersectionObjectRayDirectionEXT"; break;
case EOpRayQueryGetIntersectionObjectRayOrigin: out.debug << "rayQueryGetIntersectionObjectRayOriginEXT"; break;
case EOpRayQueryGetWorldRayDirection: out.debug << "rayQueryGetWorldRayDirectionEXT"; break;
case EOpRayQueryGetWorldRayOrigin: out.debug << "rayQueryGetWorldRayOriginEXT"; break;
case EOpRayQueryGetIntersectionObjectToWorld: out.debug << "rayQueryGetIntersectionObjectToWorldEXT"; break;
case EOpRayQueryGetIntersectionWorldToObject: out.debug << "rayQueryGetIntersectionWorldToObjectEXT"; break;
case EOpRayQueryGetIntersectionTriangleVertexPositionsEXT: out.debug << "rayQueryGetIntersectionTriangleVertexPositionsEXT"; break;
case EOpCooperativeMatrixLoad: out.debug << "Load cooperative matrix KHR"; break;
case EOpCooperativeMatrixStore: out.debug << "Store cooperative matrix KHR"; break;
case EOpCooperativeMatrixMulAdd: out.debug << "MulAdd cooperative matrices KHR"; break;
case EOpCooperativeMatrixLoadNV: out.debug << "Load cooperative matrix NV"; break;
case EOpCooperativeMatrixStoreNV: out.debug << "Store cooperative matrix NV"; break;
case EOpCooperativeMatrixMulAddNV: out.debug << "MulAdd cooperative matrices NV"; break;
case EOpIsHelperInvocation: out.debug << "IsHelperInvocation"; break;
case EOpDebugPrintf: out.debug << "Debug printf"; break;
case EOpHitObjectTraceRayNV: out.debug << "HitObjectTraceRayNV"; break;
case EOpHitObjectTraceRayMotionNV: out.debug << "HitObjectTraceRayMotionNV"; break;
case EOpHitObjectRecordHitNV: out.debug << "HitObjectRecordHitNV"; break;
case EOpHitObjectRecordHitMotionNV: out.debug << "HitObjectRecordHitMotionNV"; break;
case EOpHitObjectRecordHitWithIndexNV: out.debug << "HitObjectRecordHitWithIndexNV"; break;
case EOpHitObjectRecordHitWithIndexMotionNV: out.debug << "HitObjectRecordHitWithIndexMotionNV"; break;
case EOpHitObjectRecordMissNV: out.debug << "HitObjectRecordMissNV"; break;
case EOpHitObjectRecordMissMotionNV: out.debug << "HitObjectRecordMissMotionNV"; break;
case EOpHitObjectRecordEmptyNV: out.debug << "HitObjectRecordEmptyNV"; break;
case EOpHitObjectExecuteShaderNV: out.debug << "HitObjectExecuteShaderNV"; break;
case EOpHitObjectIsEmptyNV: out.debug << "HitObjectIsEmptyNV"; break;
case EOpHitObjectIsMissNV: out.debug << "HitObjectIsMissNV"; break;
case EOpHitObjectIsHitNV: out.debug << "HitObjectIsHitNV"; break;
case EOpHitObjectGetRayTMinNV: out.debug << "HitObjectGetRayTMinNV"; break;
case EOpHitObjectGetRayTMaxNV: out.debug << "HitObjectGetRayTMaxNV"; break;
case EOpHitObjectGetObjectRayOriginNV: out.debug << "HitObjectGetObjectRayOriginNV"; break;
case EOpHitObjectGetObjectRayDirectionNV: out.debug << "HitObjectGetObjectRayDirectionNV"; break;
case EOpHitObjectGetWorldRayOriginNV: out.debug << "HitObjectGetWorldRayOriginNV"; break;
case EOpHitObjectGetWorldRayDirectionNV: out.debug << "HitObjectGetWorldRayDirectionNV"; break;
case EOpHitObjectGetObjectToWorldNV: out.debug << "HitObjectGetObjectToWorldNV"; break;
case EOpHitObjectGetWorldToObjectNV: out.debug << "HitObjectGetWorldToObjectNV"; break;
case EOpHitObjectGetInstanceCustomIndexNV: out.debug<< "HitObjectGetInstanceCustomIndexNV"; break;
case EOpHitObjectGetInstanceIdNV: out.debug << "HitObjectGetInstaneIdNV"; break;
case EOpHitObjectGetGeometryIndexNV: out.debug << "HitObjectGetGeometryIndexNV"; break;
case EOpHitObjectGetPrimitiveIndexNV: out.debug << "HitObjectGetPrimitiveIndexNV"; break;
case EOpHitObjectGetHitKindNV: out.debug << "HitObjectGetHitKindNV"; break;
case EOpHitObjectGetAttributesNV: out.debug << "HitObjectGetAttributesNV"; break;
case EOpHitObjectGetCurrentTimeNV: out.debug << "HitObjectGetCurrentTimeNV"; break;
case EOpHitObjectGetShaderBindingTableRecordIndexNV: out.debug << "HitObjectGetShaderBindingTableRecordIndexNV"; break;
case EOpHitObjectGetShaderRecordBufferHandleNV: out.debug << "HitObjectReadShaderRecordBufferHandleNV"; break;
case EOpReorderThreadNV: out.debug << "ReorderThreadNV"; break;
case EOpFetchMicroTriangleVertexPositionNV: out.debug << "MicroTriangleVertexPositionNV"; break;
case EOpFetchMicroTriangleVertexBarycentricNV: out.debug << "MicroTriangleVertexBarycentricNV"; break;
case EOpSpirvInst: out.debug << "spirv_instruction"; break;
case EOpStencilAttachmentReadEXT: out.debug << "stencilAttachmentReadEXT"; break;
case EOpDepthAttachmentReadEXT: out.debug << "depthAttachmentReadEXT"; break;
default: out.debug.message(EPrefixError, "Bad aggregation op");
}
if (node->getOp() != EOpSequence && node->getOp() != EOpScope && node->getOp() != EOpParameters)
out.debug << " (" << node->getCompleteString() << ")";
out.debug << "\n";
return true;
}
bool TOutputTraverser::visitSelection(TVisit /* visit */, TIntermSelection* node)
{
TInfoSink& out = infoSink;
OutputTreeText(out, node, depth);
out.debug << "Test condition and select";
out.debug << " (" << node->getCompleteString() << ")";
if (node->getShortCircuit() == false)
out.debug << ": no shortcircuit";
if (node->getFlatten())
out.debug << ": Flatten";
if (node->getDontFlatten())
out.debug << ": DontFlatten";
out.debug << "\n";
++depth;
OutputTreeText(out, node, depth);
out.debug << "Condition\n";
node->getCondition()->traverse(this);
OutputTreeText(out, node, depth);
if (node->getTrueBlock()) {
out.debug << "true case\n";
node->getTrueBlock()->traverse(this);
} else
out.debug << "true case is null\n";
if (node->getFalseBlock()) {
OutputTreeText(out, node, depth);
out.debug << "false case\n";
node->getFalseBlock()->traverse(this);
}
--depth;
return false;
}
// Print infinities and NaNs, and numbers in a portable way.
// Goals:
// - portable (across IEEE 754 platforms)
// - shows all possible IEEE values
// - shows simple numbers in a simple way, e.g., no leading/trailing 0s
// - shows all digits, no premature rounding
static void OutputDouble(TInfoSink& out, double value, TOutputTraverser::EExtraOutput extra)
{
if (std::isinf(value)) {
if (value < 0)
out.debug << "-1.#INF";
else
out.debug << "+1.#INF";
} else if (std::isnan(value))
out.debug << "1.#IND";
else {
const int maxSize = 340;
char buf[maxSize];
const char* format = "%f";
if (fabs(value) > 0.0 && (fabs(value) < 1e-5 || fabs(value) > 1e12))
format = "%-.13e";
int len = snprintf(buf, maxSize, format, value);
assert(len < maxSize);
// remove a leading zero in the 100s slot in exponent; it is not portable
// pattern: XX...XXXe+0XX or XX...XXXe-0XX
if (len > 5) {
if (buf[len-5] == 'e' && (buf[len-4] == '+' || buf[len-4] == '-') && buf[len-3] == '0') {
buf[len-3] = buf[len-2];
buf[len-2] = buf[len-1];
buf[len-1] = '\0';
}
}
out.debug << buf;
switch (extra) {
case TOutputTraverser::BinaryDoubleOutput:
{
uint64_t b;
static_assert(sizeof(b) == sizeof(value), "sizeof(uint64_t) != sizeof(double)");
memcpy(&b, &value, sizeof(b));
out.debug << " : ";
for (size_t i = 0; i < 8 * sizeof(value); ++i, ++b) {
out.debug << ((b & 0x8000000000000000) != 0 ? "1" : "0");
b <<= 1;
}
break;
}
default:
break;
}
}
}
static void OutputConstantUnion(TInfoSink& out, const TIntermTyped* node, const TConstUnionArray& constUnion,
TOutputTraverser::EExtraOutput extra, int depth)
{
int size = node->getType().computeNumComponents();
for (int i = 0; i < size; i++) {
OutputTreeText(out, node, depth);
switch (constUnion[i].getType()) {
case EbtBool:
if (constUnion[i].getBConst())
out.debug << "true";
else
out.debug << "false";
out.debug << " (" << "const bool" << ")";
out.debug << "\n";
break;
case EbtFloat:
case EbtDouble:
case EbtFloat16:
OutputDouble(out, constUnion[i].getDConst(), extra);
out.debug << "\n";
break;
case EbtInt8:
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%d (%s)", constUnion[i].getI8Const(), "const int8_t");
out.debug << buf << "\n";
}
break;
case EbtUint8:
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%u (%s)", constUnion[i].getU8Const(), "const uint8_t");
out.debug << buf << "\n";
}
break;
case EbtInt16:
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%d (%s)", constUnion[i].getI16Const(), "const int16_t");
out.debug << buf << "\n";
}
break;
case EbtUint16:
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%u (%s)", constUnion[i].getU16Const(), "const uint16_t");
out.debug << buf << "\n";
}
break;
case EbtInt:
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%d (%s)", constUnion[i].getIConst(), "const int");
out.debug << buf << "\n";
}
break;
case EbtUint:
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%u (%s)", constUnion[i].getUConst(), "const uint");
out.debug << buf << "\n";
}
break;
case EbtInt64:
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%lld (%s)", constUnion[i].getI64Const(), "const int64_t");
out.debug << buf << "\n";
}
break;
case EbtUint64:
{
const int maxSize = 300;
char buf[maxSize];
snprintf(buf, maxSize, "%llu (%s)", constUnion[i].getU64Const(), "const uint64_t");
out.debug << buf << "\n";
}
break;
case EbtString:
out.debug << "\"" << constUnion[i].getSConst()->c_str() << "\"\n";
break;
default:
out.info.message(EPrefixInternalError, "Unknown constant", node->getLoc());
break;
}
}
}
void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
{
OutputTreeText(infoSink, node, depth);
infoSink.debug << "Constant:\n";
OutputConstantUnion(infoSink, node, node->getConstArray(), extraOutput, depth + 1);
}
void TOutputTraverser::visitSymbol(TIntermSymbol* node)
{
OutputTreeText(infoSink, node, depth);
infoSink.debug << "'" << node->getName() << "' (" << node->getCompleteString() << ")\n";
if (! node->getConstArray().empty())
OutputConstantUnion(infoSink, node, node->getConstArray(), extraOutput, depth + 1);
else if (node->getConstSubtree()) {
incrementDepth(node);
node->getConstSubtree()->traverse(this);
decrementDepth();
}
}
bool TOutputTraverser::visitLoop(TVisit /* visit */, TIntermLoop* node)
{
TInfoSink& out = infoSink;
OutputTreeText(out, node, depth);
out.debug << "Loop with condition ";
if (! node->testFirst())
out.debug << "not ";
out.debug << "tested first";
if (node->getUnroll())
out.debug << ": Unroll";
if (node->getDontUnroll())
out.debug << ": DontUnroll";
if (node->getLoopDependency()) {
out.debug << ": Dependency ";
out.debug << node->getLoopDependency();
}
out.debug << "\n";
++depth;
OutputTreeText(infoSink, node, depth);
if (node->getTest()) {
out.debug << "Loop Condition\n";
node->getTest()->traverse(this);
} else
out.debug << "No loop condition\n";
OutputTreeText(infoSink, node, depth);
if (node->getBody()) {
out.debug << "Loop Body\n";
node->getBody()->traverse(this);
} else
out.debug << "No loop body\n";
if (node->getTerminal()) {
OutputTreeText(infoSink, node, depth);
out.debug << "Loop Terminal Expression\n";
node->getTerminal()->traverse(this);
}
--depth;
return false;
}
bool TOutputTraverser::visitBranch(TVisit /* visit*/, TIntermBranch* node)
{
TInfoSink& out = infoSink;
OutputTreeText(out, node, depth);
switch (node->getFlowOp()) {
case EOpKill: out.debug << "Branch: Kill"; break;
case EOpTerminateInvocation: out.debug << "Branch: TerminateInvocation"; break;
case EOpIgnoreIntersectionKHR: out.debug << "Branch: IgnoreIntersectionKHR"; break;
case EOpTerminateRayKHR: out.debug << "Branch: TerminateRayKHR"; break;
case EOpBreak: out.debug << "Branch: Break"; break;
case EOpContinue: out.debug << "Branch: Continue"; break;
case EOpReturn: out.debug << "Branch: Return"; break;
case EOpCase: out.debug << "case: "; break;
case EOpDemote: out.debug << "Demote"; break;
case EOpDefault: out.debug << "default: "; break;
default: out.debug << "Branch: Unknown Branch"; break;
}
if (node->getExpression()) {
out.debug << " with expression\n";
++depth;
node->getExpression()->traverse(this);
--depth;
} else
out.debug << "\n";
return false;
}
bool TOutputTraverser::visitSwitch(TVisit /* visit */, TIntermSwitch* node)
{
TInfoSink& out = infoSink;
OutputTreeText(out, node, depth);
out.debug << "switch";
if (node->getFlatten())
out.debug << ": Flatten";
if (node->getDontFlatten())
out.debug << ": DontFlatten";
out.debug << "\n";
OutputTreeText(out, node, depth);
out.debug << "condition\n";
++depth;
node->getCondition()->traverse(this);
--depth;
OutputTreeText(out, node, depth);
out.debug << "body\n";
++depth;
node->getBody()->traverse(this);
--depth;
return false;
}
//
// This function is the one to call externally to start the traversal.
// Individual functions can be initialized to 0 to skip processing of that
// type of node. It's children will still be processed.
//
void TIntermediate::output(TInfoSink& infoSink, bool tree)
{
infoSink.debug << "Shader version: " << version << "\n";
if (requestedExtensions.size() > 0) {
for (auto extIt = requestedExtensions.begin(); extIt != requestedExtensions.end(); ++extIt)
infoSink.debug << "Requested " << *extIt << "\n";
}
if (xfbMode)
infoSink.debug << "in xfb mode\n";
if (getSubgroupUniformControlFlow())
infoSink.debug << "subgroup_uniform_control_flow\n";
if (getMaximallyReconverges())
infoSink.debug << "maximally_reconverges\n";
switch (language) {
case EShLangVertex:
break;
case EShLangTessControl:
infoSink.debug << "vertices = " << vertices << "\n";
if (inputPrimitive != ElgNone)
infoSink.debug << "input primitive = " << TQualifier::getGeometryString(inputPrimitive) << "\n";
if (vertexSpacing != EvsNone)
infoSink.debug << "vertex spacing = " << TQualifier::getVertexSpacingString(vertexSpacing) << "\n";
if (vertexOrder != EvoNone)
infoSink.debug << "triangle order = " << TQualifier::getVertexOrderString(vertexOrder) << "\n";
break;
case EShLangTessEvaluation:
infoSink.debug << "input primitive = " << TQualifier::getGeometryString(inputPrimitive) << "\n";
infoSink.debug << "vertex spacing = " << TQualifier::getVertexSpacingString(vertexSpacing) << "\n";
infoSink.debug << "triangle order = " << TQualifier::getVertexOrderString(vertexOrder) << "\n";
if (pointMode)
infoSink.debug << "using point mode\n";
break;
case EShLangGeometry:
infoSink.debug << "invocations = " << invocations << "\n";
infoSink.debug << "max_vertices = " << vertices << "\n";
infoSink.debug << "input primitive = " << TQualifier::getGeometryString(inputPrimitive) << "\n";
infoSink.debug << "output primitive = " << TQualifier::getGeometryString(outputPrimitive) << "\n";
break;
case EShLangFragment:
if (pixelCenterInteger)
infoSink.debug << "gl_FragCoord pixel center is integer\n";
if (originUpperLeft)
infoSink.debug << "gl_FragCoord origin is upper left\n";
if (earlyFragmentTests)
infoSink.debug << "using early_fragment_tests\n";
if (postDepthCoverage)
infoSink.debug << "using post_depth_coverage\n";
if (nonCoherentColorAttachmentReadEXT)
infoSink.debug << "using non_coherent_color_attachment_readEXT\n";
if (nonCoherentDepthAttachmentReadEXT)
infoSink.debug << "using non_coherent_depth_attachment_readEXT\n";
if (nonCoherentStencilAttachmentReadEXT)
infoSink.debug << "using non_coherent_stencil_attachment_readEXT\n";
if (depthLayout != EldNone)
infoSink.debug << "using " << TQualifier::getLayoutDepthString(depthLayout) << "\n";
if (blendEquations != 0) {
infoSink.debug << "using";
// blendEquations is a mask, decode it
for (TBlendEquationShift be = (TBlendEquationShift)0; be < EBlendCount; be = (TBlendEquationShift)(be + 1)) {
if (blendEquations & (1 << be))
infoSink.debug << " " << TQualifier::getBlendEquationString(be);
}
infoSink.debug << "\n";
}
if (interlockOrdering != EioNone)
infoSink.debug << "interlock ordering = " << TQualifier::getInterlockOrderingString(interlockOrdering) << "\n";
break;
case EShLangMesh:
infoSink.debug << "max_vertices = " << vertices << "\n";
infoSink.debug << "max_primitives = " << primitives << "\n";
infoSink.debug << "output primitive = " << TQualifier::getGeometryString(outputPrimitive) << "\n";
[[fallthrough]];
case EShLangTask:
// Fall through
case EShLangCompute:
infoSink.debug << "local_size = (" << localSize[0] << ", " << localSize[1] << ", " << localSize[2] << ")\n";
{
if (localSizeSpecId[0] != TQualifier::layoutNotSet ||
localSizeSpecId[1] != TQualifier::layoutNotSet ||
localSizeSpecId[2] != TQualifier::layoutNotSet) {
infoSink.debug << "local_size ids = (" <<
localSizeSpecId[0] << ", " <<
localSizeSpecId[1] << ", " <<
localSizeSpecId[2] << ")\n";
}
}
break;
default:
break;
}
if (treeRoot == nullptr || ! tree)
return;
TOutputTraverser it(infoSink);
if (getBinaryDoubleOutput())
it.setDoubleOutput(TOutputTraverser::BinaryDoubleOutput);
treeRoot->traverse(&it);
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/SymbolTable.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
// Copyright (C) 2017 ARM Limited.
// Copyright (C) 2015-2018 Google, Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Symbol table for parsing. Most functionality and main ideas
// are documented in the header file.
//
#include "SymbolTable.h"
namespace glslang {
//
// TType helper function needs a place to live.
//
//
// Recursively generate mangled names.
//
void TType::buildMangledName(TString& mangledName) const
{
if (isMatrix())
mangledName += 'm';
else if (isVector())
mangledName += 'v';
switch (basicType) {
case EbtFloat: mangledName += 'f'; break;
case EbtInt: mangledName += 'i'; break;
case EbtUint: mangledName += 'u'; break;
case EbtBool: mangledName += 'b'; break;
case EbtDouble: mangledName += 'd'; break;
case EbtFloat16: mangledName += "f16"; break;
case EbtInt8: mangledName += "i8"; break;
case EbtUint8: mangledName += "u8"; break;
case EbtInt16: mangledName += "i16"; break;
case EbtUint16: mangledName += "u16"; break;
case EbtInt64: mangledName += "i64"; break;
case EbtUint64: mangledName += "u64"; break;
case EbtAtomicUint: mangledName += "au"; break;
case EbtAccStruct: mangledName += "as"; break;
case EbtRayQuery: mangledName += "rq"; break;
case EbtSpirvType: mangledName += "spv-t"; break;
case EbtHitObjectNV: mangledName += "ho"; break;
case EbtSampler:
switch (sampler.type) {
case EbtFloat16: mangledName += "f16"; break;
case EbtInt: mangledName += "i"; break;
case EbtUint: mangledName += "u"; break;
case EbtInt64: mangledName += "i64"; break;
case EbtUint64: mangledName += "u64"; break;
default: break; // some compilers want this
}
if (sampler.isImageClass())
mangledName += "I"; // a normal image or subpass
else if (sampler.isPureSampler())
mangledName += "p"; // a "pure" sampler
else if (!sampler.isCombined())
mangledName += "t"; // a "pure" texture
else
mangledName += "s"; // traditional combined sampler
if (sampler.isArrayed())
mangledName += "A";
if (sampler.isShadow())
mangledName += "S";
if (sampler.isExternal())
mangledName += "E";
if (sampler.isYuv())
mangledName += "Y";
switch (sampler.dim) {
case Esd2D: mangledName += "2"; break;
case Esd3D: mangledName += "3"; break;
case EsdCube: mangledName += "C"; break;
case Esd1D: mangledName += "1"; break;
case EsdRect: mangledName += "R2"; break;
case EsdBuffer: mangledName += "B"; break;
case EsdSubpass: mangledName += "P"; break;
default: break; // some compilers want this
}
#ifdef ENABLE_HLSL
if (sampler.hasReturnStruct()) {
// Name mangle for sampler return struct uses struct table index.
mangledName += "-tx-struct";
char text[16]; // plenty enough space for the small integers.
snprintf(text, sizeof(text), "%u-", sampler.getStructReturnIndex());
mangledName += text;
} else {
switch (sampler.getVectorSize()) {
case 1: mangledName += "1"; break;
case 2: mangledName += "2"; break;
case 3: mangledName += "3"; break;
case 4: break; // default to prior name mangle behavior
}
}
#endif
if (sampler.isMultiSample())
mangledName += "M";
break;
case EbtStruct:
case EbtBlock:
if (basicType == EbtStruct)
mangledName += "struct-";
else
mangledName += "block-";
if (typeName)
mangledName += *typeName;
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->getBasicType() == EbtVoid)
continue;
mangledName += '-';
(*structure)[i].type->buildMangledName(mangledName);
}
break;
default:
break;
}
if (getVectorSize() > 0)
mangledName += static_cast<char>('0' + getVectorSize());
else {
mangledName += static_cast<char>('0' + getMatrixCols());
mangledName += static_cast<char>('0' + getMatrixRows());
}
if (arraySizes) {
const int maxSize = 11;
char buf[maxSize];
for (int i = 0; i < arraySizes->getNumDims(); ++i) {
if (arraySizes->getDimNode(i)) {
if (arraySizes->getDimNode(i)->getAsSymbolNode())
snprintf(buf, maxSize, "s%lld", arraySizes->getDimNode(i)->getAsSymbolNode()->getId());
else
snprintf(buf, maxSize, "s%p", arraySizes->getDimNode(i));
} else
snprintf(buf, maxSize, "%d", arraySizes->getDimSize(i));
mangledName += '[';
mangledName += buf;
mangledName += ']';
}
}
}
//
// Dump functions.
//
void TSymbol::dumpExtensions(TInfoSink& infoSink) const
{
int numExtensions = getNumExtensions();
if (numExtensions) {
infoSink.debug << " <";
for (int i = 0; i < numExtensions; i++)
infoSink.debug << getExtensions()[i] << ",";
infoSink.debug << ">";
}
}
void TVariable::dump(TInfoSink& infoSink, bool complete) const
{
if (complete) {
infoSink.debug << getName().c_str() << ": " << type.getCompleteString();
dumpExtensions(infoSink);
} else {
infoSink.debug << getName().c_str() << ": " << type.getStorageQualifierString() << " "
<< type.getBasicTypeString();
if (type.isArray())
infoSink.debug << "[0]";
}
infoSink.debug << "\n";
}
void TFunction::dump(TInfoSink& infoSink, bool complete) const
{
if (complete) {
infoSink.debug << getName().c_str() << ": " << returnType.getCompleteString() << " " << getName().c_str()
<< "(";
int numParams = getParamCount();
for (int i = 0; i < numParams; i++) {
const TParameter ¶m = parameters[i];
infoSink.debug << param.type->getCompleteString() << " "
<< (param.type->isStruct() ? "of " + param.type->getTypeName() + " " : "")
<< (param.name ? *param.name : "") << (i < numParams - 1 ? "," : "");
}
infoSink.debug << ")";
dumpExtensions(infoSink);
} else {
infoSink.debug << getName().c_str() << ": " << returnType.getBasicTypeString() << " "
<< getMangledName().c_str() << "n";
}
infoSink.debug << "\n";
}
void TAnonMember::dump(TInfoSink& TInfoSink, bool) const
{
TInfoSink.debug << "anonymous member " << getMemberNumber() << " of " << getAnonContainer().getName().c_str()
<< "\n";
}
void TSymbolTableLevel::dump(TInfoSink& infoSink, bool complete) const
{
tLevel::const_iterator it;
for (it = level.begin(); it != level.end(); ++it)
(*it).second->dump(infoSink, complete);
}
void TSymbolTable::dump(TInfoSink& infoSink, bool complete) const
{
for (int level = currentLevel(); level >= 0; --level) {
infoSink.debug << "LEVEL " << level << "\n";
table[level]->dump(infoSink, complete);
}
}
//
// Functions have buried pointers to delete.
//
TFunction::~TFunction()
{
for (TParamList::iterator i = parameters.begin(); i != parameters.end(); ++i)
delete (*i).type;
}
//
// Symbol table levels are a map of pointers to symbols that have to be deleted.
//
TSymbolTableLevel::~TSymbolTableLevel()
{
for (tLevel::iterator it = level.begin(); it != level.end(); ++it) {
const TString& name = it->first;
auto retargetIter = std::find_if(retargetedSymbols.begin(), retargetedSymbols.end(),
[&name](const std::pair<TString, TString>& i) { return i.first == name; });
if (retargetIter == retargetedSymbols.end())
delete (*it).second;
}
delete [] defaultPrecision;
}
//
// Change all function entries in the table with the non-mangled name
// to be related to the provided built-in operation.
//
void TSymbolTableLevel::relateToOperator(const char* name, TOperator op)
{
tLevel::const_iterator candidate = level.lower_bound(name);
while (candidate != level.end()) {
const TString& candidateName = (*candidate).first;
TString::size_type parenAt = candidateName.find_first_of('(');
if (parenAt != candidateName.npos && candidateName.compare(0, parenAt, name) == 0) {
TFunction* function = (*candidate).second->getAsFunction();
function->relateToOperator(op);
} else
break;
++candidate;
}
}
// Make all function overloads of the given name require an extension(s).
// Should only be used for a version/profile that actually needs the extension(s).
void TSymbolTableLevel::setFunctionExtensions(const char* name, int num, const char* const extensions[])
{
tLevel::const_iterator candidate = level.lower_bound(name);
while (candidate != level.end()) {
const TString& candidateName = (*candidate).first;
TString::size_type parenAt = candidateName.find_first_of('(');
if (parenAt != candidateName.npos && candidateName.compare(0, parenAt, name) == 0) {
TSymbol* symbol = candidate->second;
symbol->setExtensions(num, extensions);
} else
break;
++candidate;
}
}
// Make a single function require an extension(s). i.e., this will only set the extensions for the symbol that matches 'name' exactly.
// This is different from setFunctionExtensions, which uses std::map::lower_bound to effectively set all symbols that start with 'name'.
// Should only be used for a version/profile that actually needs the extension(s).
void TSymbolTableLevel::setSingleFunctionExtensions(const char* name, int num, const char* const extensions[])
{
if (auto candidate = level.find(name); candidate != level.end()) {
candidate->second->setExtensions(num, extensions);
}
}
//
// Make all symbols in this table level read only.
//
void TSymbolTableLevel::readOnly()
{
for (tLevel::iterator it = level.begin(); it != level.end(); ++it)
(*it).second->makeReadOnly();
}
//
// Copy a symbol, but the copy is writable; call readOnly() afterward if that's not desired.
//
TSymbol::TSymbol(const TSymbol& copyOf)
{
name = NewPoolTString(copyOf.name->c_str());
uniqueId = copyOf.uniqueId;
writable = true;
}
TVariable::TVariable(const TVariable& copyOf) : TSymbol(copyOf)
{
type.deepCopy(copyOf.type);
userType = copyOf.userType;
// we don't support specialization-constant subtrees in cloned tables, only extensions
constSubtree = nullptr;
extensions = nullptr;
memberExtensions = nullptr;
if (copyOf.getNumExtensions() > 0)
setExtensions(copyOf.getNumExtensions(), copyOf.getExtensions());
if (copyOf.hasMemberExtensions()) {
for (int m = 0; m < (int)copyOf.type.getStruct()->size(); ++m) {
if (copyOf.getNumMemberExtensions(m) > 0)
setMemberExtensions(m, copyOf.getNumMemberExtensions(m), copyOf.getMemberExtensions(m));
}
}
if (! copyOf.constArray.empty()) {
assert(! copyOf.type.isStruct());
TConstUnionArray newArray(copyOf.constArray, 0, copyOf.constArray.size());
constArray = newArray;
}
}
TVariable* TVariable::clone() const
{
TVariable *variable = new TVariable(*this);
return variable;
}
TFunction::TFunction(const TFunction& copyOf) : TSymbol(copyOf)
{
for (unsigned int i = 0; i < copyOf.parameters.size(); ++i) {
TParameter param{};
parameters.push_back(param);
(void)parameters.back().copyParam(copyOf.parameters[i]);
}
extensions = nullptr;
if (copyOf.getNumExtensions() > 0)
setExtensions(copyOf.getNumExtensions(), copyOf.getExtensions());
returnType.deepCopy(copyOf.returnType);
mangledName = copyOf.mangledName;
op = copyOf.op;
defined = copyOf.defined;
prototyped = copyOf.prototyped;
implicitThis = copyOf.implicitThis;
illegalImplicitThis = copyOf.illegalImplicitThis;
defaultParamCount = copyOf.defaultParamCount;
spirvInst = copyOf.spirvInst;
}
TFunction* TFunction::clone() const
{
TFunction *function = new TFunction(*this);
return function;
}
TAnonMember* TAnonMember::clone() const
{
// Anonymous members of a given block should be cloned at a higher level,
// where they can all be assured to still end up pointing to a single
// copy of the original container.
assert(0);
return nullptr;
}
TSymbolTableLevel* TSymbolTableLevel::clone() const
{
TSymbolTableLevel *symTableLevel = new TSymbolTableLevel();
symTableLevel->anonId = anonId;
symTableLevel->thisLevel = thisLevel;
symTableLevel->retargetedSymbols.clear();
for (auto &s : retargetedSymbols) {
symTableLevel->retargetedSymbols.push_back({s.first, s.second});
}
std::vector<bool> containerCopied(anonId, false);
tLevel::const_iterator iter;
for (iter = level.begin(); iter != level.end(); ++iter) {
const TAnonMember* anon = iter->second->getAsAnonMember();
if (anon) {
// Insert all the anonymous members of this same container at once,
// avoid inserting the remaining members in the future, once this has been done,
// allowing them to all be part of the same new container.
if (! containerCopied[anon->getAnonId()]) {
TVariable* container = anon->getAnonContainer().clone();
container->changeName(NewPoolTString(""));
// insert the container and all its members
symTableLevel->insert(*container, false);
containerCopied[anon->getAnonId()] = true;
}
} else {
const TString& name = iter->first;
auto retargetIter = std::find_if(retargetedSymbols.begin(), retargetedSymbols.end(),
[&name](const std::pair<TString, TString>& i) { return i.first == name; });
if (retargetIter != retargetedSymbols.end())
continue;
symTableLevel->insert(*iter->second->clone(), false);
}
}
// Now point retargeted symbols to the newly created versions of them
for (auto &s : retargetedSymbols) {
TSymbol* sym = symTableLevel->find(s.second);
if (!sym)
continue;
symTableLevel->insert(s.first, sym);
}
return symTableLevel;
}
void TSymbolTable::copyTable(const TSymbolTable& copyOf)
{
assert(adoptedLevels == copyOf.adoptedLevels);
uniqueId = copyOf.uniqueId;
noBuiltInRedeclarations = copyOf.noBuiltInRedeclarations;
separateNameSpaces = copyOf.separateNameSpaces;
for (unsigned int i = copyOf.adoptedLevels; i < copyOf.table.size(); ++i)
table.push_back(copyOf.table[i]->clone());
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/ShaderLang.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013-2016 LunarG, Inc.
// Copyright (C) 2015-2020 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Implement the top-level of interface to the compiler/linker,
// as defined in ShaderLang.h
// This is the platform independent interface between an OGL driver
// and the shading language compiler/linker.
//
#include <cstring>
#include <iostream>
#include <sstream>
#include <memory>
#include <mutex>
#include "SymbolTable.h"
#include "ParseHelper.h"
#include "Scan.h"
#include "ScanContext.h"
#ifdef ENABLE_HLSL
#include "../HLSL/hlslParseHelper.h"
#include "../HLSL/hlslParseables.h"
#include "../HLSL/hlslScanContext.h"
#endif
#include "../Include/ShHandle.h"
#include "preprocessor/PpContext.h"
#define SH_EXPORTING
#include "../Public/ShaderLang.h"
#include "reflection.h"
#include "iomapper.h"
#include "Initialize.h"
// TODO: this really shouldn't be here, it is only because of the trial addition
// of printing pre-processed tokens, which requires knowing the string literal
// token to print ", but none of that seems appropriate for this file.
#include "preprocessor/PpTokens.h"
// Build-time generated includes
#include "glslang/build_info.h"
namespace { // anonymous namespace for file-local functions and symbols
// Total number of successful initializers of glslang: a refcount
// Shared global; access should be protected by a global mutex/critical section.
int NumberOfClients = 0;
// global initialization lock
std::mutex init_lock;
using namespace glslang;
// Create a language specific version of parseables.
TBuiltInParseables* CreateBuiltInParseables(TInfoSink& infoSink, EShSource source)
{
switch (source) {
case EShSourceGlsl: return new TBuiltIns(); // GLSL builtIns
#ifdef ENABLE_HLSL
case EShSourceHlsl: return new TBuiltInParseablesHlsl(); // HLSL intrinsics
#endif
default:
infoSink.info.message(EPrefixInternalError, "Unable to determine source language");
return nullptr;
}
}
// Create a language specific version of a parse context.
TParseContextBase* CreateParseContext(TSymbolTable& symbolTable, TIntermediate& intermediate,
int version, EProfile profile, EShSource source,
EShLanguage language, TInfoSink& infoSink,
SpvVersion spvVersion, bool forwardCompatible, EShMessages messages,
bool parsingBuiltIns, std::string sourceEntryPointName = "")
{
switch (source) {
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, &entryPoint);
}
#ifdef ENABLE_HLSL
case EShSourceHlsl:
return new HlslParseContext(symbolTable, intermediate, parsingBuiltIns, version, profile, spvVersion,
language, infoSink, sourceEntryPointName.c_str(), forwardCompatible, messages);
#endif
default:
infoSink.info.message(EPrefixInternalError, "Unable to determine source language");
return nullptr;
}
}
// Local mapping functions for making arrays of symbol tables....
const int VersionCount = 17; // index range in MapVersionToIndex
int MapVersionToIndex(int version)
{
int index = 0;
switch (version) {
case 100: index = 0; break;
case 110: index = 1; break;
case 120: index = 2; break;
case 130: index = 3; break;
case 140: index = 4; break;
case 150: index = 5; break;
case 300: index = 6; break;
case 330: index = 7; break;
case 400: index = 8; break;
case 410: index = 9; break;
case 420: index = 10; break;
case 430: index = 11; break;
case 440: index = 12; break;
case 310: index = 13; break;
case 450: index = 14; break;
case 500: index = 0; break; // HLSL
case 320: index = 15; break;
case 460: index = 16; break;
default: assert(0); break;
}
assert(index < VersionCount);
return index;
}
const int SpvVersionCount = 4; // index range in MapSpvVersionToIndex
int MapSpvVersionToIndex(const SpvVersion& spvVersion)
{
int index = 0;
if (spvVersion.openGl > 0)
index = 1;
else if (spvVersion.vulkan > 0) {
if (!spvVersion.vulkanRelaxed)
index = 2;
else
index = 3;
}
assert(index < SpvVersionCount);
return index;
}
const int ProfileCount = 4; // index range in MapProfileToIndex
int MapProfileToIndex(EProfile profile)
{
int index = 0;
switch (profile) {
case ENoProfile: index = 0; break;
case ECoreProfile: index = 1; break;
case ECompatibilityProfile: index = 2; break;
case EEsProfile: index = 3; break;
default: break;
}
assert(index < ProfileCount);
return index;
}
const int SourceCount = 2;
int MapSourceToIndex(EShSource source)
{
int index = 0;
switch (source) {
case EShSourceGlsl: index = 0; break;
case EShSourceHlsl: index = 1; break;
default: break;
}
assert(index < SourceCount);
return index;
}
// only one of these needed for non-ES; ES needs 2 for different precision defaults of built-ins
enum EPrecisionClass {
EPcGeneral,
EPcFragment,
EPcCount
};
// A process-global symbol table per version per profile for built-ins common
// to multiple stages (languages), and a process-global symbol table per version
// per profile per stage for built-ins unique to each stage. They will be sparsely
// populated, so they will only be generated as needed.
//
// Each has a different set of built-ins, and we want to preserve that from
// compile to compile.
//
TSymbolTable* CommonSymbolTable[VersionCount][SpvVersionCount][ProfileCount][SourceCount][EPcCount] = {};
TSymbolTable* SharedSymbolTables[VersionCount][SpvVersionCount][ProfileCount][SourceCount][EShLangCount] = {};
TPoolAllocator* PerProcessGPA = nullptr;
//
// Parse and add to the given symbol table the content of the given shader string.
//
bool InitializeSymbolTable(const TString& builtIns, int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language,
EShSource source, TInfoSink& infoSink, TSymbolTable& symbolTable)
{
TIntermediate intermediate(language, version, profile);
intermediate.setSource(source);
std::unique_ptr<TParseContextBase> parseContext(CreateParseContext(symbolTable, intermediate, version, profile, source,
language, infoSink, spvVersion, true, EShMsgDefault,
true));
TShader::ForbidIncluder includer;
TPpContext ppContext(*parseContext, "", includer);
TScanContext scanContext(*parseContext);
parseContext->setScanContext(&scanContext);
parseContext->setPpContext(&ppContext);
//
// Push the symbol table to give it an initial scope. This
// push should not have a corresponding pop, so that built-ins
// are preserved, and the test for an empty table fails.
//
symbolTable.push();
const char* builtInShaders[2];
size_t builtInLengths[2];
builtInShaders[0] = builtIns.c_str();
builtInLengths[0] = builtIns.size();
if (builtInLengths[0] == 0)
return true;
TInputScanner input(1, builtInShaders, builtInLengths);
if (! parseContext->parseShaderStrings(ppContext, input) != 0) {
infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins");
printf("Unable to parse built-ins\n%s\n", infoSink.info.c_str());
printf("%s\n", builtInShaders[0]);
return false;
}
return true;
}
int CommonIndex(EProfile profile, EShLanguage language)
{
return (profile == EEsProfile && language == EShLangFragment) ? EPcFragment : EPcGeneral;
}
//
// To initialize per-stage shared tables, with the common table already complete.
//
void InitializeStageSymbolTable(TBuiltInParseables& builtInParseables, int version, EProfile profile, const SpvVersion& spvVersion,
EShLanguage language, EShSource source, TInfoSink& infoSink, TSymbolTable** commonTable,
TSymbolTable** symbolTables)
{
(*symbolTables[language]).adoptLevels(*commonTable[CommonIndex(profile, language)]);
InitializeSymbolTable(builtInParseables.getStageString(language), version, profile, spvVersion, language, source,
infoSink, *symbolTables[language]);
builtInParseables.identifyBuiltIns(version, profile, spvVersion, language, *symbolTables[language]);
if (profile == EEsProfile && version >= 300)
(*symbolTables[language]).setNoBuiltInRedeclarations();
if (version == 110)
(*symbolTables[language]).setSeparateNameSpaces();
}
//
// Initialize the full set of shareable symbol tables;
// The common (cross-stage) and those shareable per-stage.
//
bool InitializeSymbolTables(TInfoSink& infoSink, TSymbolTable** commonTable, TSymbolTable** symbolTables, int version, EProfile profile, const SpvVersion& spvVersion, EShSource source)
{
std::unique_ptr<TBuiltInParseables> builtInParseables(CreateBuiltInParseables(infoSink, source));
if (builtInParseables == nullptr)
return false;
builtInParseables->initialize(version, profile, spvVersion);
// do the common tables
InitializeSymbolTable(builtInParseables->getCommonString(), version, profile, spvVersion, EShLangVertex, source,
infoSink, *commonTable[EPcGeneral]);
if (profile == EEsProfile)
InitializeSymbolTable(builtInParseables->getCommonString(), version, profile, spvVersion, EShLangFragment, source,
infoSink, *commonTable[EPcFragment]);
// do the per-stage tables
// always have vertex and fragment
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangVertex, source,
infoSink, commonTable, symbolTables);
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangFragment, source,
infoSink, commonTable, symbolTables);
// check for tessellation
if ((profile != EEsProfile && version >= 150) ||
(profile == EEsProfile && version >= 310)) {
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangTessControl, source,
infoSink, commonTable, symbolTables);
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangTessEvaluation, source,
infoSink, commonTable, symbolTables);
}
// check for geometry
if ((profile != EEsProfile && version >= 150) ||
(profile == EEsProfile && version >= 310))
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangGeometry, source,
infoSink, commonTable, symbolTables);
// check for compute
if ((profile != EEsProfile && version >= 420) ||
(profile == EEsProfile && version >= 310))
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangCompute, source,
infoSink, commonTable, symbolTables);
// check for ray tracing stages
if (profile != EEsProfile && version >= 450) {
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangRayGen, source,
infoSink, commonTable, symbolTables);
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangIntersect, source,
infoSink, commonTable, symbolTables);
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangAnyHit, source,
infoSink, commonTable, symbolTables);
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangClosestHit, source,
infoSink, commonTable, symbolTables);
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangMiss, source,
infoSink, commonTable, symbolTables);
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangCallable, source,
infoSink, commonTable, symbolTables);
}
// check for mesh
if ((profile != EEsProfile && version >= 450) ||
(profile == EEsProfile && version >= 320))
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangMesh, source,
infoSink, commonTable, symbolTables);
// check for task
if ((profile != EEsProfile && version >= 450) ||
(profile == EEsProfile && version >= 320))
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangTask, source,
infoSink, commonTable, symbolTables);
return true;
}
bool AddContextSpecificSymbols(const TBuiltInResource* resources, TInfoSink& infoSink, TSymbolTable& symbolTable, int version,
EProfile profile, const SpvVersion& spvVersion, EShLanguage language, EShSource source)
{
std::unique_ptr<TBuiltInParseables> builtInParseables(CreateBuiltInParseables(infoSink, source));
if (builtInParseables == nullptr)
return false;
builtInParseables->initialize(*resources, version, profile, spvVersion, language);
InitializeSymbolTable(builtInParseables->getCommonString(), version, profile, spvVersion, language, source, infoSink, symbolTable);
builtInParseables->identifyBuiltIns(version, profile, spvVersion, language, symbolTable, *resources);
return true;
}
//
// To do this on the fly, we want to leave the current state of our thread's
// pool allocator intact, so:
// - Switch to a new pool for parsing the built-ins
// - Do the parsing, which builds the symbol table, using the new pool
// - Switch to the process-global pool to save a copy of the resulting symbol table
// - Free up the new pool used to parse the built-ins
// - Switch back to the original thread's pool
//
// This only gets done the first time any thread needs a particular symbol table
// (lazy evaluation).
//
void SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& spvVersion, EShSource source)
{
TInfoSink infoSink;
// Make sure only one thread tries to do this at a time
const std::lock_guard<std::mutex> lock(init_lock);
// See if it's already been done for this version/profile combination
int versionIndex = MapVersionToIndex(version);
int spvVersionIndex = MapSpvVersionToIndex(spvVersion);
int profileIndex = MapProfileToIndex(profile);
int sourceIndex = MapSourceToIndex(source);
if (CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][EPcGeneral])
return;
// Switch to a new pool
TPoolAllocator& previousAllocator = GetThreadPoolAllocator();
TPoolAllocator* builtInPoolAllocator = new TPoolAllocator;
SetThreadPoolAllocator(builtInPoolAllocator);
// Dynamically allocate the local symbol tables so we can control when they are deallocated WRT when the pool is popped.
TSymbolTable* commonTable[EPcCount];
TSymbolTable* stageTables[EShLangCount];
for (int precClass = 0; precClass < EPcCount; ++precClass)
commonTable[precClass] = new TSymbolTable;
for (int stage = 0; stage < EShLangCount; ++stage)
stageTables[stage] = new TSymbolTable;
// Generate the local symbol tables using the new pool
InitializeSymbolTables(infoSink, commonTable, stageTables, version, profile, spvVersion, source);
// Switch to the process-global pool
SetThreadPoolAllocator(PerProcessGPA);
// Copy the local symbol tables from the new pool to the global tables using the process-global pool
for (int precClass = 0; precClass < EPcCount; ++precClass) {
if (! commonTable[precClass]->isEmpty()) {
CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][precClass] = new TSymbolTable;
CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][precClass]->copyTable(*commonTable[precClass]);
CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][precClass]->readOnly();
}
}
for (int stage = 0; stage < EShLangCount; ++stage) {
if (! stageTables[stage]->isEmpty()) {
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][sourceIndex][stage] = new TSymbolTable;
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][sourceIndex][stage]->adoptLevels(*CommonSymbolTable
[versionIndex][spvVersionIndex][profileIndex][sourceIndex][CommonIndex(profile, (EShLanguage)stage)]);
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][sourceIndex][stage]->copyTable(*stageTables[stage]);
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][sourceIndex][stage]->readOnly();
}
}
// Clean up the local tables before deleting the pool they used.
for (int precClass = 0; precClass < EPcCount; ++precClass)
delete commonTable[precClass];
for (int stage = 0; stage < EShLangCount; ++stage)
delete stageTables[stage];
delete builtInPoolAllocator;
SetThreadPoolAllocator(&previousAllocator);
}
// Function to Print all builtins
void DumpBuiltinSymbolTable(TInfoSink& infoSink, const TSymbolTable& symbolTable)
{
infoSink.debug << "BuiltinSymbolTable {\n";
symbolTable.dump(infoSink, true);
infoSink.debug << "}\n";
}
// Return true if the shader was correctly specified for version/profile/stage.
bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool versionNotFirst, int defaultVersion,
EShSource source, int& version, EProfile& profile, const SpvVersion& spvVersion)
{
const int FirstProfileVersion = 150;
bool correct = true;
if (source == EShSourceHlsl) {
version = 500; // shader model; currently a characteristic of glslang, not the input
profile = ECoreProfile; // allow doubles in prototype parsing
return correct;
}
// Get a version...
if (version == 0) {
version = defaultVersion;
// infoSink.info.message(EPrefixWarning, "#version: statement missing; use #version on first line of shader");
}
// Get a good profile...
if (profile == ENoProfile) {
if (version == 300 || version == 310 || version == 320) {
correct = false;
infoSink.info.message(EPrefixError, "#version: versions 300, 310, and 320 require specifying the 'es' profile");
profile = EEsProfile;
} else if (version == 100)
profile = EEsProfile;
else if (version >= FirstProfileVersion)
profile = ECoreProfile;
else
profile = ENoProfile;
} else {
// a profile was provided...
if (version < 150) {
correct = false;
infoSink.info.message(EPrefixError, "#version: versions before 150 do not allow a profile token");
if (version == 100)
profile = EEsProfile;
else
profile = ENoProfile;
} else if (version == 300 || version == 310 || version == 320) {
if (profile != EEsProfile) {
correct = false;
infoSink.info.message(EPrefixError, "#version: versions 300, 310, and 320 support only the es profile");
}
profile = EEsProfile;
} else {
if (profile == EEsProfile) {
correct = false;
infoSink.info.message(EPrefixError, "#version: only version 300, 310, and 320 support the es profile");
if (version >= FirstProfileVersion)
profile = ECoreProfile;
else
profile = ENoProfile;
}
// else: typical desktop case... e.g., "#version 410 core"
}
}
// Fix version...
switch (version) {
// ES versions
case 100: break;
case 300: break;
case 310: break;
case 320: break;
// desktop versions
case 110: break;
case 120: break;
case 130: break;
case 140: break;
case 150: break;
case 330: break;
case 400: break;
case 410: break;
case 420: break;
case 430: break;
case 440: break;
case 450: break;
case 460: break;
// unknown version
default:
correct = false;
infoSink.info.message(EPrefixError, "version not supported");
if (profile == EEsProfile)
version = 310;
else {
version = 450;
profile = ECoreProfile;
}
break;
}
// Correct for stage type...
switch (stage) {
case EShLangGeometry:
if ((profile == EEsProfile && version < 310) ||
(profile != EEsProfile && version < 150)) {
correct = false;
infoSink.info.message(EPrefixError, "#version: geometry shaders require es profile with version 310 or non-es profile with version 150 or above");
version = (profile == EEsProfile) ? 310 : 150;
if (profile == EEsProfile || profile == ENoProfile)
profile = ECoreProfile;
}
break;
case EShLangTessControl:
case EShLangTessEvaluation:
if ((profile == EEsProfile && version < 310) ||
(profile != EEsProfile && version < 150)) {
correct = false;
infoSink.info.message(EPrefixError, "#version: tessellation shaders require es profile with version 310 or non-es profile with version 150 or above");
version = (profile == EEsProfile) ? 310 : 400; // 150 supports the extension, correction is to 400 which does not
if (profile == EEsProfile || profile == ENoProfile)
profile = ECoreProfile;
}
break;
case EShLangCompute:
if ((profile == EEsProfile && version < 310) ||
(profile != EEsProfile && version < 420)) {
correct = false;
infoSink.info.message(EPrefixError, "#version: compute shaders require es profile with version 310 or above, or non-es profile with version 420 or above");
version = profile == EEsProfile ? 310 : 420;
}
break;
case EShLangRayGen:
case EShLangIntersect:
case EShLangAnyHit:
case EShLangClosestHit:
case EShLangMiss:
case EShLangCallable:
if (profile == EEsProfile || version < 460) {
correct = false;
infoSink.info.message(EPrefixError, "#version: ray tracing shaders require non-es profile with version 460 or above");
version = 460;
}
break;
case EShLangMesh:
case EShLangTask:
if ((profile == EEsProfile && version < 320) ||
(profile != EEsProfile && version < 450)) {
correct = false;
infoSink.info.message(EPrefixError, "#version: mesh/task shaders require es profile with version 320 or above, or non-es profile with version 450 or above");
version = profile == EEsProfile ? 320 : 450;
}
break;
default:
break;
}
if (profile == EEsProfile && version >= 300 && versionNotFirst) {
correct = false;
infoSink.info.message(EPrefixError, "#version: statement must appear first in es-profile shader; before comments or newlines");
}
// Check for SPIR-V compatibility
if (spvVersion.spv != 0) {
switch (profile) {
case EEsProfile:
if (version < 310) {
correct = false;
infoSink.info.message(EPrefixError, "#version: ES shaders for SPIR-V require version 310 or higher");
version = 310;
}
break;
case ECompatibilityProfile:
infoSink.info.message(EPrefixError, "#version: compilation for SPIR-V does not support the compatibility profile");
break;
default:
if (spvVersion.vulkan > 0 && version < 140) {
correct = false;
infoSink.info.message(EPrefixError, "#version: Desktop shaders for Vulkan SPIR-V require version 140 or higher");
version = 140;
}
if (spvVersion.openGl >= 100 && version < 330) {
correct = false;
infoSink.info.message(EPrefixError, "#version: Desktop shaders for OpenGL SPIR-V require version 330 or higher");
version = 330;
}
break;
}
}
return correct;
}
// There are multiple paths in for setting environment stuff.
// TEnvironment takes precedence, for what it sets, so sort all this out.
// Ideally, the internal code could be made to use TEnvironment, but for
// now, translate it to the historically used parameters.
void TranslateEnvironment(const TEnvironment* environment, EShMessages& messages, EShSource& source,
EShLanguage& stage, SpvVersion& spvVersion)
{
// Set up environmental defaults, first ignoring 'environment'.
if (messages & EShMsgSpvRules)
spvVersion.spv = EShTargetSpv_1_0;
if (messages & EShMsgVulkanRules) {
spvVersion.vulkan = EShTargetVulkan_1_0;
spvVersion.vulkanGlsl = 100;
} else if (spvVersion.spv != 0)
spvVersion.openGl = 100;
// Now, override, based on any content set in 'environment'.
// 'environment' must be cleared to ESh*None settings when items
// are not being set.
if (environment != nullptr) {
// input language
if (environment->input.languageFamily != EShSourceNone) {
stage = environment->input.stage;
switch (environment->input.dialect) {
case EShClientNone:
break;
case EShClientVulkan:
spvVersion.vulkanGlsl = environment->input.dialectVersion;
spvVersion.vulkanRelaxed = environment->input.vulkanRulesRelaxed;
break;
case EShClientOpenGL:
spvVersion.openGl = environment->input.dialectVersion;
break;
case EShClientCount:
assert(0);
break;
}
switch (environment->input.languageFamily) {
case EShSourceNone:
break;
case EShSourceGlsl:
source = EShSourceGlsl;
messages = static_cast<EShMessages>(messages & ~EShMsgReadHlsl);
break;
case EShSourceHlsl:
source = EShSourceHlsl;
messages = static_cast<EShMessages>(messages | EShMsgReadHlsl);
break;
case EShSourceCount:
assert(0);
break;
}
}
// client
switch (environment->client.client) {
case EShClientVulkan:
spvVersion.vulkan = environment->client.version;
break;
default:
break;
}
// generated code
switch (environment->target.language) {
case EshTargetSpv:
spvVersion.spv = environment->target.version;
break;
default:
break;
}
}
}
// Most processes are recorded when set in the intermediate representation,
// These are the few that are not.
void RecordProcesses(TIntermediate& intermediate, EShMessages messages, const std::string& sourceEntryPointName)
{
if ((messages & EShMsgRelaxedErrors) != 0)
intermediate.addProcess("relaxed-errors");
if ((messages & EShMsgSuppressWarnings) != 0)
intermediate.addProcess("suppress-warnings");
if ((messages & EShMsgKeepUncalled) != 0)
intermediate.addProcess("keep-uncalled");
if (sourceEntryPointName.size() > 0) {
intermediate.addProcess("source-entrypoint");
intermediate.addProcessArgument(sourceEntryPointName);
}
}
// This is the common setup and cleanup code for PreprocessDeferred and
// CompileDeferred.
// It takes any callable with a signature of
// bool (TParseContextBase& parseContext, TPpContext& ppContext,
// TInputScanner& input, bool versionWillBeError,
// TSymbolTable& , TIntermediate& ,
// EShOptimizationLevel , EShMessages );
// Which returns false if a failure was detected and true otherwise.
//
template<typename ProcessingContext>
bool ProcessDeferred(
TCompiler* compiler,
const char* const shaderStrings[],
const int numStrings,
const int* inputLengths,
const char* const stringNames[],
const char* customPreamble,
const EShOptimizationLevel optLevel,
const TBuiltInResource* resources,
int defaultVersion, // use 100 for ES environment, 110 for desktop; this is the GLSL version, not SPIR-V or Vulkan
EProfile defaultProfile,
// set version/profile to defaultVersion/defaultProfile regardless of the #version
// directive in the source code
bool forceDefaultVersionAndProfile,
int overrideVersion, // overrides version specified by #version or default version
bool forwardCompatible, // give errors for use of deprecated features
EShMessages messages, // warnings/errors/AST; things to print out
TIntermediate& intermediate, // returned tree, etc.
ProcessingContext& processingContext,
bool requireNonempty,
TShader::Includer& includer,
const std::string sourceEntryPointName = "",
const TEnvironment* environment = nullptr, // optional way of fully setting all versions, overriding the above
bool compileOnly = false)
{
// This must be undone (.pop()) by the caller, after it finishes consuming the created tree.
GetThreadPoolAllocator().push();
if (numStrings == 0)
return true;
// Move to length-based strings, rather than null-terminated strings.
// Also, add strings to include the preamble and to ensure the shader is not null,
// which lets the grammar accept what was a null (post preprocessing) shader.
//
// Shader will look like
// string 0: system preamble
// string 1: custom preamble
// string 2...numStrings+1: user's shader
// string numStrings+2: "int;"
const int numPre = 2;
const int numPost = requireNonempty? 1 : 0;
const int numTotal = numPre + numStrings + numPost;
std::unique_ptr<size_t[]> lengths(new size_t[numTotal]);
std::unique_ptr<const char*[]> strings(new const char*[numTotal]);
std::unique_ptr<const char*[]> names(new const char*[numTotal]);
for (int s = 0; s < numStrings; ++s) {
strings[s + numPre] = shaderStrings[s];
if (inputLengths == nullptr || inputLengths[s] < 0)
lengths[s + numPre] = strlen(shaderStrings[s]);
else
lengths[s + numPre] = inputLengths[s];
}
if (stringNames != nullptr) {
for (int s = 0; s < numStrings; ++s)
names[s + numPre] = stringNames[s];
} else {
for (int s = 0; s < numStrings; ++s)
names[s + numPre] = nullptr;
}
// Get all the stages, languages, clients, and other environment
// stuff sorted out.
EShSource sourceGuess = (messages & EShMsgReadHlsl) != 0 ? EShSourceHlsl : EShSourceGlsl;
SpvVersion spvVersion;
EShLanguage stage = compiler->getLanguage();
TranslateEnvironment(environment, messages, sourceGuess, stage, spvVersion);
#ifdef ENABLE_HLSL
EShSource source = sourceGuess;
if (environment != nullptr && environment->target.hlslFunctionality1)
intermediate.setHlslFunctionality1();
#else
const EShSource source = EShSourceGlsl;
#endif
// First, without using the preprocessor or parser, find the #version, so we know what
// symbol tables, processing rules, etc. to set up. This does not need the extra strings
// outlined above, just the user shader, after the system and user preambles.
glslang::TInputScanner userInput(numStrings, &strings[numPre], &lengths[numPre]);
int version = 0;
EProfile profile = ENoProfile;
bool versionNotFirstToken = false;
bool versionNotFirst = (source == EShSourceHlsl)
? true
: userInput.scanVersion(version, profile, versionNotFirstToken);
bool versionNotFound = version == 0;
if (forceDefaultVersionAndProfile && source == EShSourceGlsl) {
if (! (messages & EShMsgSuppressWarnings) && ! versionNotFound &&
(version != defaultVersion || profile != defaultProfile)) {
compiler->infoSink.info << "Warning, (version, profile) forced to be ("
<< defaultVersion << ", " << ProfileName(defaultProfile)
<< "), while in source code it is ("
<< version << ", " << ProfileName(profile) << ")\n";
}
if (versionNotFound) {
versionNotFirstToken = false;
versionNotFirst = false;
versionNotFound = false;
}
version = defaultVersion;
profile = defaultProfile;
}
if (source == EShSourceGlsl && overrideVersion != 0) {
version = overrideVersion;
}
bool goodVersion = DeduceVersionProfile(compiler->infoSink, stage,
versionNotFirst, defaultVersion, source, version, profile, spvVersion);
bool versionWillBeError = (versionNotFound || (profile == EEsProfile && version >= 300 && versionNotFirst));
bool warnVersionNotFirst = false;
if (! versionWillBeError && versionNotFirstToken) {
if (messages & EShMsgRelaxedErrors)
warnVersionNotFirst = true;
else
versionWillBeError = true;
}
intermediate.setSource(source);
intermediate.setVersion(version);
intermediate.setProfile(profile);
intermediate.setSpv(spvVersion);
RecordProcesses(intermediate, messages, sourceEntryPointName);
if (spvVersion.vulkan > 0)
intermediate.setOriginUpperLeft();
#ifdef ENABLE_HLSL
if ((messages & EShMsgHlslOffsets) || source == EShSourceHlsl)
intermediate.setHlslOffsets();
#endif
if (messages & EShMsgDebugInfo) {
intermediate.setSourceFile(names[numPre]);
for (int s = 0; s < numStrings; ++s) {
// The string may not be null-terminated, so make sure we provide
// the length along with the string.
intermediate.addSourceText(strings[numPre + s], lengths[numPre + s]);
}
}
SetupBuiltinSymbolTable(version, profile, spvVersion, source);
TSymbolTable* cachedTable = SharedSymbolTables[MapVersionToIndex(version)]
[MapSpvVersionToIndex(spvVersion)]
[MapProfileToIndex(profile)]
[MapSourceToIndex(source)]
[stage];
// Dynamically allocate the symbol table so we can control when it is deallocated WRT the pool.
std::unique_ptr<TSymbolTable> symbolTable(new TSymbolTable);
if (cachedTable)
symbolTable->adoptLevels(*cachedTable);
if (intermediate.getUniqueId() != 0)
symbolTable->overwriteUniqueId(intermediate.getUniqueId());
// Add built-in symbols that are potentially context dependent;
// they get popped again further down.
if (! AddContextSpecificSymbols(resources, compiler->infoSink, *symbolTable, version, profile, spvVersion,
stage, source)) {
return false;
}
if (messages & EShMsgBuiltinSymbolTable)
DumpBuiltinSymbolTable(compiler->infoSink, *symbolTable);
//
// Now we can process the full shader under proper symbols and rules.
//
std::unique_ptr<TParseContextBase> parseContext(CreateParseContext(*symbolTable, intermediate, version, profile, source,
stage, compiler->infoSink,
spvVersion, forwardCompatible, messages, false, sourceEntryPointName));
parseContext->compileOnly = compileOnly;
TPpContext ppContext(*parseContext, names[numPre] ? names[numPre] : "", includer);
// only GLSL (bison triggered, really) needs an externally set scan context
glslang::TScanContext scanContext(*parseContext);
if (source == EShSourceGlsl)
parseContext->setScanContext(&scanContext);
parseContext->setPpContext(&ppContext);
parseContext->setLimits(*resources);
if (! goodVersion)
parseContext->addError();
if (warnVersionNotFirst) {
TSourceLoc loc;
loc.init();
parseContext->warn(loc, "Illegal to have non-comment, non-whitespace tokens before #version", "#version", "");
}
parseContext->initializeExtensionBehavior();
// Fill in the strings as outlined above.
std::string preamble;
parseContext->getPreamble(preamble);
strings[0] = preamble.c_str();
lengths[0] = strlen(strings[0]);
names[0] = nullptr;
strings[1] = customPreamble;
lengths[1] = strlen(strings[1]);
names[1] = nullptr;
assert(2 == numPre);
if (requireNonempty) {
const int postIndex = numStrings + numPre;
strings[postIndex] = "\n int;";
lengths[postIndex] = strlen(strings[numStrings + numPre]);
names[postIndex] = nullptr;
}
TInputScanner fullInput(numStrings + numPre + numPost, strings.get(), lengths.get(), names.get(), numPre, numPost);
// Push a new symbol allocation scope that will get used for the shader's globals.
symbolTable->push();
bool success = processingContext(*parseContext, ppContext, fullInput,
versionWillBeError, *symbolTable,
intermediate, optLevel, messages);
intermediate.setUniqueId(symbolTable->getMaxSymbolId());
return success;
}
// Responsible for keeping track of the most recent source string and line in
// the preprocessor and outputting newlines appropriately if the source string
// or line changes.
class SourceLineSynchronizer {
public:
SourceLineSynchronizer(const std::function<int()>& lastSourceIndex,
std::string* output)
: getLastSourceIndex(lastSourceIndex), output(output), lastSource(-1), lastLine(0) {}
// SourceLineSynchronizer(const SourceLineSynchronizer&) = delete;
// SourceLineSynchronizer& operator=(const SourceLineSynchronizer&) = delete;
// Sets the internally tracked source string index to that of the most
// recently read token. If we switched to a new source string, returns
// true and inserts a newline. Otherwise, returns false and outputs nothing.
bool syncToMostRecentString() {
if (getLastSourceIndex() != lastSource) {
// After switching to a new source string, we need to reset lastLine
// because line number resets every time a new source string is
// used. We also need to output a newline to separate the output
// from the previous source string (if there is one).
if (lastSource != -1 || lastLine != 0)
*output += '\n';
lastSource = getLastSourceIndex();
lastLine = -1;
return true;
}
return false;
}
// Calls syncToMostRecentString() and then sets the internally tracked line
// number to tokenLine. If we switched to a new line, returns true and inserts
// newlines appropriately. Otherwise, returns false and outputs nothing.
bool syncToLine(int tokenLine) {
syncToMostRecentString();
const bool newLineStarted = lastLine < tokenLine;
for (; lastLine < tokenLine; ++lastLine) {
if (lastLine > 0) *output += '\n';
}
return newLineStarted;
}
// Sets the internally tracked line number to newLineNum.
void setLineNum(int newLineNum) { lastLine = newLineNum; }
private:
SourceLineSynchronizer& operator=(const SourceLineSynchronizer&);
// A function for getting the index of the last valid source string we've
// read tokens from.
const std::function<int()> getLastSourceIndex;
// output string for newlines.
std::string* output;
// lastSource is the source string index (starting from 0) of the last token
// processed. It is tracked in order for newlines to be inserted when a new
// source string starts. -1 means we haven't started processing any source
// string.
int lastSource;
// lastLine is the line number (starting from 1) of the last token processed.
// It is tracked in order for newlines to be inserted when a token appears
// on a new line. 0 means we haven't started processing any line in the
// current source string.
int lastLine;
};
// DoPreprocessing is a valid ProcessingContext template argument,
// which only performs the preprocessing step of compilation.
// It places the result in the "string" argument to its constructor.
//
// This is not an officially supported or fully working path.
struct DoPreprocessing {
explicit DoPreprocessing(std::string* string): outputString(string) {}
bool operator()(TParseContextBase& parseContext, TPpContext& ppContext,
TInputScanner& input, bool versionWillBeError,
TSymbolTable&, TIntermediate&,
EShOptimizationLevel, EShMessages)
{
// This is a list of tokens that do not require a space before or after.
static const std::string noNeededSpaceBeforeTokens = ";)[].,";
static const std::string noNeededSpaceAfterTokens = ".([";
glslang::TPpToken ppToken;
parseContext.setScanner(&input);
ppContext.setInput(input, versionWillBeError);
std::string outputBuffer;
SourceLineSynchronizer lineSync(
std::bind(&TInputScanner::getLastValidSourceIndex, &input), &outputBuffer);
parseContext.setExtensionCallback([&lineSync, &outputBuffer](
int line, const char* extension, const char* behavior) {
lineSync.syncToLine(line);
outputBuffer += "#extension ";
outputBuffer += extension;
outputBuffer += " : ";
outputBuffer += behavior;
});
parseContext.setLineCallback([&lineSync, &outputBuffer, &parseContext](
int curLineNum, int newLineNum, bool hasSource, int sourceNum, const char* sourceName) {
// SourceNum is the number of the source-string that is being parsed.
lineSync.syncToLine(curLineNum);
outputBuffer += "#line ";
outputBuffer += std::to_string(newLineNum);
if (hasSource) {
outputBuffer += ' ';
if (sourceName != nullptr) {
outputBuffer += '\"';
outputBuffer += sourceName;
outputBuffer += '\"';
} else {
outputBuffer += std::to_string(sourceNum);
}
}
if (parseContext.lineDirectiveShouldSetNextLine()) {
// newLineNum is the new line number for the line following the #line
// directive. So the new line number for the current line is
newLineNum -= 1;
}
outputBuffer += '\n';
// And we are at the next line of the #line directive now.
lineSync.setLineNum(newLineNum + 1);
});
parseContext.setVersionCallback(
[&lineSync, &outputBuffer](int line, int version, const char* str) {
lineSync.syncToLine(line);
outputBuffer += "#version ";
outputBuffer += std::to_string(version);
if (str) {
outputBuffer += ' ';
outputBuffer += str;
}
});
parseContext.setPragmaCallback([&lineSync, &outputBuffer](
int line, const glslang::TVector<glslang::TString>& ops) {
lineSync.syncToLine(line);
outputBuffer += "#pragma ";
for(size_t i = 0; i < ops.size(); ++i) {
outputBuffer += ops[i].c_str();
}
});
parseContext.setErrorCallback([&lineSync, &outputBuffer](
int line, const char* errorMessage) {
lineSync.syncToLine(line);
outputBuffer += "#error ";
outputBuffer += errorMessage;
});
int lastToken = EndOfInput; // lastToken records the last token processed.
std::string lastTokenName;
do {
int token = ppContext.tokenize(ppToken);
if (token == EndOfInput)
break;
bool isNewString = lineSync.syncToMostRecentString();
bool isNewLine = lineSync.syncToLine(ppToken.loc.line);
if (isNewLine) {
// Don't emit whitespace onto empty lines.
// Copy any whitespace characters at the start of a line
// from the input to the output.
outputBuffer += std::string(ppToken.loc.column - 1, ' ');
}
// Output a space in between tokens, but not at the start of a line,
// and also not around special tokens. This helps with readability
// and consistency.
if (!isNewString && !isNewLine && lastToken != EndOfInput) {
// left parenthesis need a leading space, except it is in a function-call-like context.
// examples: `for (xxx)`, `a * (b + c)`, `vec(2.0)`, `foo(x, y, z)`
if (token == '(') {
if (lastToken != PpAtomIdentifier ||
lastTokenName == "if" ||
lastTokenName == "for" ||
lastTokenName == "while" ||
lastTokenName == "switch")
outputBuffer += ' ';
} else if ((noNeededSpaceBeforeTokens.find((char)token) == std::string::npos) &&
(noNeededSpaceAfterTokens.find((char)lastToken) == std::string::npos)) {
outputBuffer += ' ';
}
}
if (token == PpAtomIdentifier)
lastTokenName = ppToken.name;
lastToken = token;
if (token == PpAtomConstString)
outputBuffer += "\"";
outputBuffer += ppToken.name;
if (token == PpAtomConstString)
outputBuffer += "\"";
} while (true);
outputBuffer += '\n';
*outputString = std::move(outputBuffer);
bool success = true;
if (parseContext.getNumErrors() > 0) {
success = false;
parseContext.infoSink.info.prefix(EPrefixError);
parseContext.infoSink.info << parseContext.getNumErrors() << " compilation errors. No code generated.\n\n";
}
return success;
}
std::string* outputString;
};
// DoFullParse is a valid ProcessingConext template argument for fully
// parsing the shader. It populates the "intermediate" with the AST.
struct DoFullParse{
bool operator()(TParseContextBase& parseContext, TPpContext& ppContext,
TInputScanner& fullInput, bool versionWillBeError,
TSymbolTable&, TIntermediate& intermediate,
EShOptimizationLevel optLevel, EShMessages messages)
{
bool success = true;
// Parse the full shader.
if (! parseContext.parseShaderStrings(ppContext, fullInput, versionWillBeError))
success = false;
if (success && intermediate.getTreeRoot()) {
if (optLevel == EShOptNoGeneration)
parseContext.infoSink.info.message(EPrefixNone, "No errors. No code generation or linking was requested.");
else
success = intermediate.postProcess(intermediate.getTreeRoot(), parseContext.getLanguage());
} else if (! success) {
parseContext.infoSink.info.prefix(EPrefixError);
parseContext.infoSink.info << parseContext.getNumErrors() << " compilation errors. No code generated.\n\n";
}
if (messages & EShMsgAST)
intermediate.output(parseContext.infoSink, true);
return success;
}
};
// Take a single compilation unit, and run the preprocessor on it.
// Return: True if there were no issues found in preprocessing,
// False if during preprocessing any unknown version, pragmas or
// extensions were found.
//
// NOTE: Doing just preprocessing to obtain a correct preprocessed shader string
// is not an officially supported or fully working path.
bool PreprocessDeferred(
TCompiler* compiler,
const char* const shaderStrings[],
const int numStrings,
const int* inputLengths,
const char* const stringNames[],
const char* preamble,
const EShOptimizationLevel optLevel,
const TBuiltInResource* resources,
int defaultVersion, // use 100 for ES environment, 110 for desktop
EProfile defaultProfile,
bool forceDefaultVersionAndProfile,
int overrideVersion, // use 0 if not overriding GLSL version
bool forwardCompatible, // give errors for use of deprecated features
EShMessages messages, // warnings/errors/AST; things to print out
TShader::Includer& includer,
TIntermediate& intermediate, // returned tree, etc.
std::string* outputString,
TEnvironment* environment = nullptr)
{
DoPreprocessing parser(outputString);
return ProcessDeferred(compiler, shaderStrings, numStrings, inputLengths, stringNames,
preamble, optLevel, resources, defaultVersion,
defaultProfile, forceDefaultVersionAndProfile, overrideVersion,
forwardCompatible, messages, intermediate, parser,
false, includer, "", environment);
}
//
// do a partial compile on the given strings for a single compilation unit
// for a potential deferred link into a single stage (and deferred full compile of that
// stage through machine-dependent compilation).
//
// all preprocessing, parsing, semantic checks, etc. for a single compilation unit
// are done here.
//
// return: the tree and other information is filled into the intermediate argument,
// and true is returned by the function for success.
//
bool CompileDeferred(
TCompiler* compiler,
const char* const shaderStrings[],
const int numStrings,
const int* inputLengths,
const char* const stringNames[],
const char* preamble,
const EShOptimizationLevel optLevel,
const TBuiltInResource* resources,
int defaultVersion, // use 100 for ES environment, 110 for desktop
EProfile defaultProfile,
bool forceDefaultVersionAndProfile,
int overrideVersion, // use 0 if not overriding GLSL version
bool forwardCompatible, // give errors for use of deprecated features
EShMessages messages, // warnings/errors/AST; things to print out
TIntermediate& intermediate,// returned tree, etc.
TShader::Includer& includer,
const std::string sourceEntryPointName = "",
TEnvironment* environment = nullptr,
bool compileOnly = false)
{
DoFullParse parser;
return ProcessDeferred(compiler, shaderStrings, numStrings, inputLengths, stringNames,
preamble, optLevel, resources, defaultVersion,
defaultProfile, forceDefaultVersionAndProfile, overrideVersion,
forwardCompatible, messages, intermediate, parser,
true, includer, sourceEntryPointName, environment, compileOnly);
}
} // end anonymous namespace for local functions
//
// ShInitialize() should be called exactly once per process, not per thread.
//
int ShInitialize()
{
const std::lock_guard<std::mutex> lock(init_lock);
++NumberOfClients;
if (PerProcessGPA == nullptr)
PerProcessGPA = new TPoolAllocator();
glslang::TScanContext::fillInKeywordMap();
#ifdef ENABLE_HLSL
glslang::HlslScanContext::fillInKeywordMap();
#endif
return 1;
}
//
// Driver calls these to create and destroy compiler/linker
// objects.
//
ShHandle ShConstructCompiler(const EShLanguage language, int /*debugOptions unused*/)
{
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(language, 0));
return reinterpret_cast<void*>(base);
}
ShHandle ShConstructLinker(const EShExecutable executable, int /*debugOptions unused*/)
{
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructLinker(executable, 0));
return reinterpret_cast<void*>(base);
}
ShHandle ShConstructUniformMap()
{
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructUniformMap());
return reinterpret_cast<void*>(base);
}
void ShDestruct(ShHandle handle)
{
if (handle == nullptr)
return;
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
if (base->getAsCompiler())
DeleteCompiler(base->getAsCompiler());
else if (base->getAsLinker())
DeleteLinker(base->getAsLinker());
else if (base->getAsUniformMap())
DeleteUniformMap(base->getAsUniformMap());
}
//
// Cleanup symbol tables
//
int ShFinalize()
{
const std::lock_guard<std::mutex> lock(init_lock);
--NumberOfClients;
assert(NumberOfClients >= 0);
if (NumberOfClients > 0)
return 1;
for (int version = 0; version < VersionCount; ++version) {
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
for (int p = 0; p < ProfileCount; ++p) {
for (int source = 0; source < SourceCount; ++source) {
for (int stage = 0; stage < EShLangCount; ++stage) {
delete SharedSymbolTables[version][spvVersion][p][source][stage];
SharedSymbolTables[version][spvVersion][p][source][stage] = nullptr;
}
}
}
}
}
for (int version = 0; version < VersionCount; ++version) {
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
for (int p = 0; p < ProfileCount; ++p) {
for (int source = 0; source < SourceCount; ++source) {
for (int pc = 0; pc < EPcCount; ++pc) {
delete CommonSymbolTable[version][spvVersion][p][source][pc];
CommonSymbolTable[version][spvVersion][p][source][pc] = nullptr;
}
}
}
}
}
if (PerProcessGPA != nullptr) {
delete PerProcessGPA;
PerProcessGPA = nullptr;
}
glslang::TScanContext::deleteKeywordMap();
#ifdef ENABLE_HLSL
glslang::HlslScanContext::deleteKeywordMap();
#endif
return 1;
}
//
// Do a full compile on the given strings for a single compilation unit
// forming a complete stage. The result of the machine dependent compilation
// is left in the provided compile object.
//
// Return: The return value is really boolean, indicating
// success (1) or failure (0).
//
int ShCompile(
const ShHandle handle,
const char* const shaderStrings[],
const int numStrings,
const int* inputLengths,
const EShOptimizationLevel optLevel,
const TBuiltInResource* resources,
int /*debugOptions*/,
int defaultVersion, // use 100 for ES environment, 110 for desktop
bool forwardCompatible, // give errors for use of deprecated features
EShMessages messages, // warnings/errors/AST; things to print out,
const char *shaderFileName // the filename
)
{
// Map the generic handle to the C++ object
if (handle == nullptr)
return 0;
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (compiler == nullptr)
return 0;
SetThreadPoolAllocator(compiler->getPool());
compiler->infoSink.info.erase();
compiler->infoSink.debug.erase();
compiler->infoSink.info.setShaderFileName(shaderFileName);
compiler->infoSink.debug.setShaderFileName(shaderFileName);
TIntermediate intermediate(compiler->getLanguage());
TShader::ForbidIncluder includer;
bool success = CompileDeferred(compiler, shaderStrings, numStrings, inputLengths, nullptr,
"", optLevel, resources, defaultVersion, ENoProfile, false, 0,
forwardCompatible, messages, intermediate, includer);
//
// Call the machine dependent compiler
//
if (success && intermediate.getTreeRoot() && optLevel != EShOptNoGeneration)
success = compiler->compile(intermediate.getTreeRoot(), intermediate.getVersion(), intermediate.getProfile());
intermediate.removeTree();
// Throw away all the temporary memory used by the compilation process.
// The push was done in the CompileDeferred() call above.
GetThreadPoolAllocator().pop();
return success ? 1 : 0;
}
//
// Link the given compile objects.
//
// Return: The return value of is really boolean, indicating
// success or failure.
//
int ShLinkExt(
const ShHandle linkHandle,
const ShHandle compHandles[],
const int numHandles)
{
if (linkHandle == nullptr || numHandles == 0)
return 0;
THandleList cObjects;
for (int i = 0; i < numHandles; ++i) {
if (compHandles[i] == nullptr)
return 0;
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(compHandles[i]);
if (base->getAsLinker()) {
cObjects.push_back(base->getAsLinker());
}
if (base->getAsCompiler())
cObjects.push_back(base->getAsCompiler());
if (cObjects[i] == nullptr)
return 0;
}
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(linkHandle);
TLinker* linker = static_cast<TLinker*>(base->getAsLinker());
if (linker == nullptr)
return 0;
SetThreadPoolAllocator(linker->getPool());
linker->infoSink.info.erase();
for (int i = 0; i < numHandles; ++i) {
if (cObjects[i]->getAsCompiler()) {
if (! cObjects[i]->getAsCompiler()->linkable()) {
linker->infoSink.info.message(EPrefixError, "Not all shaders have valid object code.");
return 0;
}
}
}
bool ret = linker->link(cObjects);
return ret ? 1 : 0;
}
//
// ShSetEncrpytionMethod is a place-holder for specifying
// how source code is encrypted.
//
void ShSetEncryptionMethod(ShHandle handle)
{
if (handle == nullptr)
return;
}
//
// Return any compiler/linker/uniformmap log of messages for the application.
//
const char* ShGetInfoLog(const ShHandle handle)
{
if (handle == nullptr)
return nullptr;
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
TInfoSink* infoSink;
if (base->getAsCompiler())
infoSink = &(base->getAsCompiler()->getInfoSink());
else if (base->getAsLinker())
infoSink = &(base->getAsLinker()->getInfoSink());
else
return nullptr;
infoSink->info << infoSink->debug.c_str();
return infoSink->info.c_str();
}
//
// Return the resulting binary code from the link process. Structure
// is machine dependent.
//
const void* ShGetExecutable(const ShHandle handle)
{
if (handle == nullptr)
return nullptr;
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
TLinker* linker = static_cast<TLinker*>(base->getAsLinker());
if (linker == nullptr)
return nullptr;
return linker->getObjectCode();
}
//
// Let the linker know where the application said it's attributes are bound.
// The linker does not use these values, they are remapped by the ICD or
// hardware. It just needs them to know what's aliased.
//
// Return: The return value of is really boolean, indicating
// success or failure.
//
int ShSetVirtualAttributeBindings(const ShHandle handle, const ShBindingTable* table)
{
if (handle == nullptr)
return 0;
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
TLinker* linker = static_cast<TLinker*>(base->getAsLinker());
if (linker == nullptr)
return 0;
linker->setAppAttributeBindings(table);
return 1;
}
//
// Let the linker know where the predefined attributes have to live.
//
int ShSetFixedAttributeBindings(const ShHandle handle, const ShBindingTable* table)
{
if (handle == nullptr)
return 0;
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
TLinker* linker = static_cast<TLinker*>(base->getAsLinker());
if (linker == nullptr)
return 0;
linker->setFixedAttributeBindings(table);
return 1;
}
//
// Some attribute locations are off-limits to the linker...
//
int ShExcludeAttributes(const ShHandle handle, int *attributes, int count)
{
if (handle == nullptr)
return 0;
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
TLinker* linker = static_cast<TLinker*>(base->getAsLinker());
if (linker == nullptr)
return 0;
linker->setExcludedAttributes(attributes, count);
return 1;
}
//
// Return the index for OpenGL to use for knowing where a uniform lives.
//
// Return: The return value of is really boolean, indicating
// success or failure.
//
int ShGetUniformLocation(const ShHandle handle, const char* name)
{
if (handle == nullptr)
return -1;
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
TUniformMap* uniformMap= base->getAsUniformMap();
if (uniformMap == nullptr)
return -1;
return uniformMap->getLocation(name);
}
////////////////////////////////////////////////////////////////////////////////////////////
//
// Deferred-Lowering C++ Interface
// -----------------------------------
//
// Below is a new alternate C++ interface that might potentially replace the above
// opaque handle-based interface.
//
// See more detailed comment in ShaderLang.h
//
namespace glslang {
Version GetVersion()
{
Version version;
version.major = GLSLANG_VERSION_MAJOR;
version.minor = GLSLANG_VERSION_MINOR;
version.patch = GLSLANG_VERSION_PATCH;
version.flavor = GLSLANG_VERSION_FLAVOR;
return version;
}
#define QUOTE(s) #s
#define STR(n) QUOTE(n)
const char* GetEsslVersionString()
{
return "OpenGL ES GLSL 3.20 glslang Khronos. " STR(GLSLANG_VERSION_MAJOR) "." STR(GLSLANG_VERSION_MINOR) "." STR(
GLSLANG_VERSION_PATCH) GLSLANG_VERSION_FLAVOR;
}
const char* GetGlslVersionString()
{
return "4.60 glslang Khronos. " STR(GLSLANG_VERSION_MAJOR) "." STR(GLSLANG_VERSION_MINOR) "." STR(
GLSLANG_VERSION_PATCH) GLSLANG_VERSION_FLAVOR;
}
int GetKhronosToolId()
{
return 8;
}
bool InitializeProcess()
{
return ShInitialize() != 0;
}
void FinalizeProcess()
{
ShFinalize();
}
class TDeferredCompiler : public TCompiler {
public:
TDeferredCompiler(EShLanguage s, TInfoSink& i) : TCompiler(s, i) { }
virtual bool compile(TIntermNode*, int = 0, EProfile = ENoProfile) { return true; }
};
TShader::TShader(EShLanguage s)
: stage(s), lengths(nullptr), stringNames(nullptr), preamble(""), overrideVersion(0)
{
pool = new TPoolAllocator;
infoSink = new TInfoSink;
compiler = new TDeferredCompiler(stage, *infoSink);
intermediate = new TIntermediate(s);
// clear environment (avoid constructors in them for use in a C interface)
environment.input.languageFamily = EShSourceNone;
environment.input.dialect = EShClientNone;
environment.input.vulkanRulesRelaxed = false;
environment.client.client = EShClientNone;
environment.target.language = EShTargetNone;
environment.target.hlslFunctionality1 = false;
}
TShader::~TShader()
{
delete infoSink;
delete compiler;
delete intermediate;
delete pool;
}
void TShader::setStrings(const char* const* s, int n)
{
strings = s;
numStrings = n;
lengths = nullptr;
}
void TShader::setStringsWithLengths(const char* const* s, const int* l, int n)
{
strings = s;
numStrings = n;
lengths = l;
}
void TShader::setStringsWithLengthsAndNames(
const char* const* s, const int* l, const char* const* names, int n)
{
strings = s;
numStrings = n;
lengths = l;
stringNames = names;
}
void TShader::setEntryPoint(const char* entryPoint)
{
intermediate->setEntryPointName(entryPoint);
}
void TShader::setSourceEntryPoint(const char* name)
{
sourceEntryPointName = name;
}
// Log initial settings and transforms.
// See comment for class TProcesses.
void TShader::addProcesses(const std::vector<std::string>& p)
{
intermediate->addProcesses(p);
}
void TShader::setUniqueId(unsigned long long id)
{
intermediate->setUniqueId(id);
}
void TShader::setOverrideVersion(int version)
{
overrideVersion = version;
}
void TShader::setDebugInfo(bool debugInfo) { intermediate->setDebugInfo(debugInfo); }
void TShader::setInvertY(bool invert) { intermediate->setInvertY(invert); }
void TShader::setDxPositionW(bool invert) { intermediate->setDxPositionW(invert); }
void TShader::setEnhancedMsgs() { intermediate->setEnhancedMsgs(); }
void TShader::setNanMinMaxClamp(bool useNonNan) { intermediate->setNanMinMaxClamp(useNonNan); }
// Set binding base for given resource type
void TShader::setShiftBinding(TResourceType res, unsigned int base) {
intermediate->setShiftBinding(res, base);
}
// Set binding base for given resource type for a given binding set.
void TShader::setShiftBindingForSet(TResourceType res, unsigned int base, unsigned int set) {
intermediate->setShiftBindingForSet(res, base, set);
}
// Set binding base for sampler types
void TShader::setShiftSamplerBinding(unsigned int base) { setShiftBinding(EResSampler, base); }
// Set binding base for texture types (SRV)
void TShader::setShiftTextureBinding(unsigned int base) { setShiftBinding(EResTexture, base); }
// Set binding base for image types
void TShader::setShiftImageBinding(unsigned int base) { setShiftBinding(EResImage, base); }
// Set binding base for uniform buffer objects (CBV)
void TShader::setShiftUboBinding(unsigned int base) { setShiftBinding(EResUbo, base); }
// Synonym for setShiftUboBinding, to match HLSL language.
void TShader::setShiftCbufferBinding(unsigned int base) { setShiftBinding(EResUbo, base); }
// Set binding base for UAV (unordered access view)
void TShader::setShiftUavBinding(unsigned int base) { setShiftBinding(EResUav, base); }
// Set binding base for SSBOs
void TShader::setShiftSsboBinding(unsigned int base) { setShiftBinding(EResSsbo, base); }
// Enables binding automapping using TIoMapper
void TShader::setAutoMapBindings(bool map) { intermediate->setAutoMapBindings(map); }
// Enables position.Y output negation in vertex shader
// Fragile: currently within one stage: simple auto-assignment of location
void TShader::setAutoMapLocations(bool map) { intermediate->setAutoMapLocations(map); }
void TShader::addUniformLocationOverride(const char* name, int loc)
{
intermediate->addUniformLocationOverride(name, loc);
}
void TShader::setUniformLocationBase(int base)
{
intermediate->setUniformLocationBase(base);
}
void TShader::setNoStorageFormat(bool useUnknownFormat) { intermediate->setNoStorageFormat(useUnknownFormat); }
void TShader::setResourceSetBinding(const std::vector<std::string>& base) { intermediate->setResourceSetBinding(base); }
void TShader::setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode) { intermediate->setTextureSamplerTransformMode(mode); }
void TShader::addBlockStorageOverride(const char* nameStr, TBlockStorageClass backing) { intermediate->addBlockStorageOverride(nameStr, backing); }
void TShader::setGlobalUniformBlockName(const char* name) { intermediate->setGlobalUniformBlockName(name); }
void TShader::setGlobalUniformSet(unsigned int set) { intermediate->setGlobalUniformSet(set); }
void TShader::setGlobalUniformBinding(unsigned int binding) { intermediate->setGlobalUniformBinding(binding); }
void TShader::setAtomicCounterBlockName(const char* name) { intermediate->setAtomicCounterBlockName(name); }
void TShader::setAtomicCounterBlockSet(unsigned int set) { intermediate->setAtomicCounterBlockSet(set); }
#ifdef ENABLE_HLSL
// See comment above TDefaultHlslIoMapper in iomapper.cpp:
void TShader::setHlslIoMapping(bool hlslIoMap) { intermediate->setHlslIoMapping(hlslIoMap); }
void TShader::setFlattenUniformArrays(bool flatten) { intermediate->setFlattenUniformArrays(flatten); }
#endif
//
// Turn the shader strings into a parse tree in the TIntermediate.
//
// Returns true for success.
//
bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
bool forwardCompatible, EShMessages messages, Includer& includer)
{
SetThreadPoolAllocator(pool);
if (! preamble)
preamble = "";
return CompileDeferred(compiler, strings, numStrings, lengths, stringNames,
preamble, EShOptNone, builtInResources, defaultVersion,
defaultProfile, forceDefaultVersionAndProfile, overrideVersion,
forwardCompatible, messages, *intermediate, includer, sourceEntryPointName,
&environment, compileOnly);
}
// Fill in a string with the result of preprocessing ShaderStrings
// Returns true if all extensions, pragmas and version strings were valid.
//
// NOTE: Doing just preprocessing to obtain a correct preprocessed shader string
// is not an officially supported or fully working path.
bool TShader::preprocess(const TBuiltInResource* builtInResources,
int defaultVersion, EProfile defaultProfile,
bool forceDefaultVersionAndProfile,
bool forwardCompatible, EShMessages message,
std::string* output_string,
Includer& includer)
{
SetThreadPoolAllocator(pool);
if (! preamble)
preamble = "";
return PreprocessDeferred(compiler, strings, numStrings, lengths, stringNames, preamble,
EShOptNone, builtInResources, defaultVersion,
defaultProfile, forceDefaultVersionAndProfile, overrideVersion,
forwardCompatible, message, includer, *intermediate, output_string,
&environment);
}
const char* TShader::getInfoLog()
{
return infoSink->info.c_str();
}
const char* TShader::getInfoDebugLog()
{
return infoSink->debug.c_str();
}
TProgram::TProgram() : reflection(nullptr), linked(false)
{
pool = new TPoolAllocator;
infoSink = new TInfoSink;
for (int s = 0; s < EShLangCount; ++s) {
intermediate[s] = nullptr;
newedIntermediate[s] = false;
}
}
TProgram::~TProgram()
{
delete infoSink;
delete reflection;
for (int s = 0; s < EShLangCount; ++s)
if (newedIntermediate[s])
delete intermediate[s];
delete pool;
}
//
// Merge the compilation units within each stage into a single TIntermediate.
// All starting compilation units need to be the result of calling TShader::parse().
//
// Return true for success.
//
bool TProgram::link(EShMessages messages)
{
if (linked)
return false;
linked = true;
bool error = false;
SetThreadPoolAllocator(pool);
for (int s = 0; s < EShLangCount; ++s) {
if (! linkStage((EShLanguage)s, messages))
error = true;
}
if (!error) {
if (! crossStageCheck(messages))
error = true;
}
return ! error;
}
//
// Merge the compilation units within the given stage into a single TIntermediate.
//
// Return true for success.
//
bool TProgram::linkStage(EShLanguage stage, EShMessages messages)
{
if (stages[stage].size() == 0)
return true;
int numEsShaders = 0, numNonEsShaders = 0;
for (auto it = stages[stage].begin(); it != stages[stage].end(); ++it) {
if ((*it)->intermediate->getProfile() == EEsProfile) {
numEsShaders++;
} else {
numNonEsShaders++;
}
}
if (numEsShaders > 0 && numNonEsShaders > 0) {
infoSink->info.message(EPrefixError, "Cannot mix ES profile with non-ES profile shaders");
return false;
} else if (numEsShaders > 1) {
infoSink->info.message(EPrefixError, "Cannot attach multiple ES shaders of the same type to a single program");
return false;
}
//
// Be efficient for the common single compilation unit per stage case,
// reusing it's TIntermediate instead of merging into a new one.
//
TIntermediate *firstIntermediate = stages[stage].front()->intermediate;
if (stages[stage].size() == 1)
intermediate[stage] = firstIntermediate;
else {
intermediate[stage] = new TIntermediate(stage,
firstIntermediate->getVersion(),
firstIntermediate->getProfile());
intermediate[stage]->setLimits(firstIntermediate->getLimits());
if (firstIntermediate->getEnhancedMsgs())
intermediate[stage]->setEnhancedMsgs();
// The new TIntermediate must use the same origin as the original TIntermediates.
// Otherwise linking will fail due to different coordinate systems.
if (firstIntermediate->getOriginUpperLeft()) {
intermediate[stage]->setOriginUpperLeft();
}
intermediate[stage]->setSpv(firstIntermediate->getSpv());
newedIntermediate[stage] = true;
}
if (messages & EShMsgAST)
infoSink->info << "\nLinked " << StageName(stage) << " stage:\n\n";
if (stages[stage].size() > 1) {
std::list<TShader*>::const_iterator it;
for (it = stages[stage].begin(); it != stages[stage].end(); ++it)
intermediate[stage]->merge(*infoSink, *(*it)->intermediate);
}
intermediate[stage]->finalCheck(*infoSink, (messages & EShMsgKeepUncalled) != 0);
if (messages & EShMsgAST)
intermediate[stage]->output(*infoSink, true);
return intermediate[stage]->getNumErrors() == 0;
}
//
// Check that there are no errors in linker objects accross stages
//
// Return true if no errors.
//
bool TProgram::crossStageCheck(EShMessages) {
// make temporary intermediates to hold the linkage symbols for each linking interface
// while we do the checks
// Independent interfaces are:
// all uniform variables and blocks
// all buffer blocks
// all in/out on a stage boundary
TVector<TIntermediate*> activeStages;
for (int s = 0; s < EShLangCount; ++s) {
if (intermediate[s])
activeStages.push_back(intermediate[s]);
}
// no extra linking if there is only one stage
if (! (activeStages.size() > 1))
return true;
// setup temporary tree to hold unfirom objects from different stages
TIntermediate* firstIntermediate = activeStages.front();
TIntermediate uniforms(EShLangCount,
firstIntermediate->getVersion(),
firstIntermediate->getProfile());
uniforms.setSpv(firstIntermediate->getSpv());
TIntermAggregate uniformObjects(EOpLinkerObjects);
TIntermAggregate root(EOpSequence);
root.getSequence().push_back(&uniformObjects);
uniforms.setTreeRoot(&root);
bool error = false;
// merge uniforms from all stages into a single intermediate
for (unsigned int i = 0; i < activeStages.size(); ++i) {
uniforms.mergeUniformObjects(*infoSink, *activeStages[i]);
}
error |= uniforms.getNumErrors() != 0;
// copy final definition of global block back into each stage
for (unsigned int i = 0; i < activeStages.size(); ++i) {
// We only want to merge into already existing global uniform blocks.
// A stage that doesn't already know about the global doesn't care about it's content.
// Otherwise we end up pointing to the same object between different stages
// and that will break binding/set remappings
bool mergeExistingOnly = true;
activeStages[i]->mergeGlobalUniformBlocks(*infoSink, uniforms, mergeExistingOnly);
}
// compare cross stage symbols for each stage boundary
for (unsigned int i = 1; i < activeStages.size(); ++i) {
activeStages[i - 1]->checkStageIO(*infoSink, *activeStages[i]);
error |= (activeStages[i - 1]->getNumErrors() != 0);
}
return !error;
}
const char* TProgram::getInfoLog()
{
return infoSink->info.c_str();
}
const char* TProgram::getInfoDebugLog()
{
return infoSink->debug.c_str();
}
//
// Reflection implementation.
//
unsigned int TObjectReflection::layoutLocation() const { return type->getQualifier().layoutLocation; }
bool TProgram::buildReflection(int opts)
{
if (! linked || reflection != nullptr)
return false;
int firstStage = EShLangVertex, lastStage = EShLangFragment;
if (opts & EShReflectionIntermediateIO) {
// if we're reflecting intermediate I/O, determine the first and last stage linked and use those as the
// boundaries for which stages generate pipeline inputs/outputs
firstStage = EShLangCount;
lastStage = 0;
for (int s = 0; s < EShLangCount; ++s) {
if (intermediate[s]) {
firstStage = std::min(firstStage, s);
lastStage = std::max(lastStage, s);
}
}
}
reflection = new TReflection((EShReflectionOptions)opts, (EShLanguage)firstStage, (EShLanguage)lastStage);
for (int s = 0; s < EShLangCount; ++s) {
if (intermediate[s]) {
if (! reflection->addStage((EShLanguage)s, *intermediate[s]))
return false;
}
}
return true;
}
unsigned TProgram::getLocalSize(int dim) const { return reflection->getLocalSize(dim); }
int TProgram::getReflectionIndex(const char* name) const { return reflection->getIndex(name); }
int TProgram::getReflectionPipeIOIndex(const char* name, const bool inOrOut) const
{ return reflection->getPipeIOIndex(name, inOrOut); }
int TProgram::getNumUniformVariables() const { return reflection->getNumUniforms(); }
const TObjectReflection& TProgram::getUniform(int index) const { return reflection->getUniform(index); }
int TProgram::getNumUniformBlocks() const { return reflection->getNumUniformBlocks(); }
const TObjectReflection& TProgram::getUniformBlock(int index) const { return reflection->getUniformBlock(index); }
int TProgram::getNumPipeInputs() const { return reflection->getNumPipeInputs(); }
const TObjectReflection& TProgram::getPipeInput(int index) const { return reflection->getPipeInput(index); }
int TProgram::getNumPipeOutputs() const { return reflection->getNumPipeOutputs(); }
const TObjectReflection& TProgram::getPipeOutput(int index) const { return reflection->getPipeOutput(index); }
int TProgram::getNumBufferVariables() const { return reflection->getNumBufferVariables(); }
const TObjectReflection& TProgram::getBufferVariable(int index) const { return reflection->getBufferVariable(index); }
int TProgram::getNumBufferBlocks() const { return reflection->getNumStorageBuffers(); }
const TObjectReflection& TProgram::getBufferBlock(int index) const { return reflection->getStorageBufferBlock(index); }
int TProgram::getNumAtomicCounters() const { return reflection->getNumAtomicCounters(); }
const TObjectReflection& TProgram::getAtomicCounter(int index) const { return reflection->getAtomicCounter(index); }
void TProgram::dumpReflection() { if (reflection != nullptr) reflection->dump(); }
//
// I/O mapping implementation.
//
bool TProgram::mapIO(TIoMapResolver* pResolver, TIoMapper* pIoMapper)
{
if (! linked)
return false;
TIoMapper* ioMapper = nullptr;
TIoMapper defaultIOMapper;
if (pIoMapper == nullptr)
ioMapper = &defaultIOMapper;
else
ioMapper = pIoMapper;
for (int s = 0; s < EShLangCount; ++s) {
if (intermediate[s]) {
if (! ioMapper->addStage((EShLanguage)s, *intermediate[s], *infoSink, pResolver))
return false;
}
}
return ioMapper->doMap(pResolver, *infoSink);
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/propagateNoContraction.h | //
// Copyright (C) 2015-2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Visit the nodes in the glslang intermediate tree representation to
// propagate 'noContraction' qualifier.
//
#pragma once
#include "../Include/intermediate.h"
namespace glslang {
// Propagates the 'precise' qualifier for objects (objects marked with
// 'noContraction' qualifier) from the shader source specified 'precise'
// variables to all the involved objects, and add 'noContraction' qualifier for
// the involved arithmetic operations.
// Note that the same qualifier: 'noContraction' is used in both object nodes
// and arithmetic operation nodes, but has different meaning. For object nodes,
// 'noContraction' means the object is 'precise'; and for arithmetic operation
// nodes, it means the operation should not be contracted.
void PropagateNoContraction(const glslang::TIntermediate& intermediate);
};
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/Versions.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
// Copyright (C) 2017, 2022-2024 Arm Limited.
// Copyright (C) 2015-2020 Google, Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Help manage multiple profiles, versions, extensions etc.
//
// These don't return error codes, as the presumption is parsing will
// always continue as if the tested feature were enabled, and thus there
// is no error recovery needed.
//
//
// HOW TO add a feature enabled by an extension.
//
// To add a new hypothetical "Feature F" to the front end, where an extension
// "XXX_extension_X" can be used to enable the feature, do the following.
//
// OVERVIEW: Specific features are what are error-checked for, not
// extensions: A specific Feature F might be enabled by an extension, or a
// particular version in a particular profile, or a stage, or combinations, etc.
//
// The basic mechanism is to use the following to "declare" all the things that
// enable/disable Feature F, in a code path that implements Feature F:
//
// requireProfile()
// profileRequires()
// requireStage()
// checkDeprecated()
// requireNotRemoved()
// requireExtensions()
// extensionRequires()
//
// Typically, only the first two calls are needed. They go into a code path that
// implements Feature F, and will log the proper error/warning messages. Parsing
// will then always continue as if the tested feature was enabled.
//
// There is typically no if-testing or conditional parsing, just insertion of the calls above.
// However, if symbols specific to the extension are added (step 5), they will
// only be added under tests that the minimum version and profile are present.
//
// 1) Add a symbol name for the extension string at the bottom of Versions.h:
//
// const char* const XXX_extension_X = "XXX_extension_X";
//
// 2) Add extension initialization to TParseVersions::initializeExtensionBehavior(),
// the first function below and optionally a entry to extensionData for additional
// error checks:
//
// extensionBehavior[XXX_extension_X] = EBhDisable;
// (Optional) exts[] = {XXX_extension_X, EShTargetSpv_1_4}
//
// 3) Add any preprocessor directives etc. in the next function, TParseVersions::getPreamble():
//
// "#define XXX_extension_X 1\n"
//
// The new-line is important, as that ends preprocess tokens.
//
// 4) Insert a profile check in the feature's path (unless all profiles support the feature,
// for some version level). That is, call requireProfile() to constrain the profiles, e.g.:
//
// // ... in a path specific to Feature F...
// requireProfile(loc,
// ECoreProfile | ECompatibilityProfile,
// "Feature F");
//
// 5) For each profile that supports the feature, insert version/extension checks:
//
// The mostly likely scenario is that Feature F can only be used with a
// particular profile if XXX_extension_X is present or the version is
// high enough that the core specification already incorporated it.
//
// // following the requireProfile() call...
// profileRequires(loc,
// ECoreProfile | ECompatibilityProfile,
// 420, // 0 if no version incorporated the feature into the core spec.
// XXX_extension_X, // can be a list of extensions that all add the feature
// "Feature F Description");
//
// This allows the feature if either A) one of the extensions is enabled or
// B) the version is high enough. If no version yet incorporates the feature
// into core, pass in 0.
//
// This can be called multiple times, if different profiles support the
// feature starting at different version numbers or with different
// extensions.
//
// This must be called for each profile allowed by the initial call to requireProfile().
//
// Profiles are all masks, which can be "or"-ed together.
//
// ENoProfile
// ECoreProfile
// ECompatibilityProfile
// EEsProfile
//
// The ENoProfile profile is only for desktop, before profiles showed up in version 150;
// All other #version with no profile default to either es or core, and so have profiles.
//
// You can select all but a particular profile using ~. The following basically means "desktop":
//
// ~EEsProfile
//
// 6) If built-in symbols are added by the extension, add them in Initialize.cpp: Their use
// will be automatically error checked against the extensions enabled at that moment.
// see the comment at the top of Initialize.cpp for where to put them. Establish them at
// the earliest release that supports the extension. Then, tag them with the
// set of extensions that both enable them and are necessary, given the version of the symbol
// table. (There is a different symbol table for each version.)
//
// 7) If the extension has additional requirements like minimum SPIR-V version required, add them
// to extensionRequires()
#include "parseVersions.h"
#include "localintermediate.h"
namespace glslang {
//
// Initialize all extensions, almost always to 'disable', as once their features
// are incorporated into a core version, their features are supported through allowing that
// core version, not through a pseudo-enablement of the extension.
//
void TParseVersions::initializeExtensionBehavior()
{
typedef struct {
const char *const extensionName;
EShTargetLanguageVersion minSpvVersion;
} extensionData;
const extensionData exts[] = { {E_GL_EXT_ray_tracing, EShTargetSpv_1_4},
{E_GL_NV_ray_tracing_motion_blur, EShTargetSpv_1_4},
{E_GL_EXT_mesh_shader, EShTargetSpv_1_4}
};
for (size_t ii = 0; ii < sizeof(exts) / sizeof(exts[0]); ii++) {
// Add only extensions which require > spv1.0 to save space in map
if (exts[ii].minSpvVersion > EShTargetSpv_1_0) {
extensionMinSpv[exts[ii].extensionName] = exts[ii].minSpvVersion;
}
}
extensionBehavior[E_GL_OES_texture_3D] = EBhDisable;
extensionBehavior[E_GL_OES_standard_derivatives] = EBhDisable;
extensionBehavior[E_GL_EXT_frag_depth] = EBhDisable;
extensionBehavior[E_GL_OES_EGL_image_external] = EBhDisable;
extensionBehavior[E_GL_OES_EGL_image_external_essl3] = EBhDisable;
extensionBehavior[E_GL_EXT_YUV_target] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_texture_lod] = EBhDisable;
extensionBehavior[E_GL_EXT_shadow_samplers] = EBhDisable;
extensionBehavior[E_GL_ARB_texture_rectangle] = EBhDisable;
extensionBehavior[E_GL_3DL_array_objects] = EBhDisable;
extensionBehavior[E_GL_ARB_shading_language_420pack] = EBhDisable;
extensionBehavior[E_GL_ARB_texture_gather] = EBhDisable;
extensionBehavior[E_GL_ARB_gpu_shader5] = EBhDisablePartial;
extensionBehavior[E_GL_ARB_separate_shader_objects] = EBhDisable;
extensionBehavior[E_GL_ARB_compute_shader] = EBhDisable;
extensionBehavior[E_GL_ARB_tessellation_shader] = EBhDisable;
extensionBehavior[E_GL_ARB_enhanced_layouts] = EBhDisable;
extensionBehavior[E_GL_ARB_texture_cube_map_array] = EBhDisable;
extensionBehavior[E_GL_ARB_texture_multisample] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_texture_lod] = EBhDisable;
extensionBehavior[E_GL_ARB_explicit_attrib_location] = EBhDisable;
extensionBehavior[E_GL_ARB_explicit_uniform_location] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_image_load_store] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_atomic_counters] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_atomic_counter_ops] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_draw_parameters] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_group_vote] = EBhDisable;
extensionBehavior[E_GL_ARB_derivative_control] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_texture_image_samples] = EBhDisable;
extensionBehavior[E_GL_ARB_viewport_array] = EBhDisable;
extensionBehavior[E_GL_ARB_gpu_shader_int64] = EBhDisable;
extensionBehavior[E_GL_ARB_gpu_shader_fp64] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_ballot] = EBhDisable;
extensionBehavior[E_GL_ARB_sparse_texture2] = EBhDisable;
extensionBehavior[E_GL_ARB_sparse_texture_clamp] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_stencil_export] = EBhDisable;
// extensionBehavior[E_GL_ARB_cull_distance] = EBhDisable; // present for 4.5, but need extension control over block members
extensionBehavior[E_GL_ARB_post_depth_coverage] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_viewport_layer_array] = EBhDisable;
extensionBehavior[E_GL_ARB_fragment_shader_interlock] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_clock] = EBhDisable;
extensionBehavior[E_GL_ARB_uniform_buffer_object] = EBhDisable;
extensionBehavior[E_GL_ARB_sample_shading] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_bit_encoding] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_image_size] = EBhDisable;
extensionBehavior[E_GL_ARB_shader_storage_buffer_object] = EBhDisable;
extensionBehavior[E_GL_ARB_shading_language_packing] = EBhDisable;
extensionBehavior[E_GL_ARB_texture_query_lod] = EBhDisable;
extensionBehavior[E_GL_ARB_vertex_attrib_64bit] = EBhDisable;
extensionBehavior[E_GL_ARB_draw_instanced] = EBhDisable;
extensionBehavior[E_GL_ARB_bindless_texture] = EBhDisable;
extensionBehavior[E_GL_ARB_fragment_coord_conventions] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_basic] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_vote] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_arithmetic] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_ballot] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_shuffle] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_shuffle_relative] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_rotate] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_clustered] = EBhDisable;
extensionBehavior[E_GL_KHR_shader_subgroup_quad] = EBhDisable;
extensionBehavior[E_GL_KHR_memory_scope_semantics] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_atomic_int64] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_non_constant_global_initializers] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_image_load_formatted] = EBhDisable;
extensionBehavior[E_GL_EXT_post_depth_coverage] = EBhDisable;
extensionBehavior[E_GL_EXT_control_flow_attributes] = EBhDisable;
extensionBehavior[E_GL_EXT_nonuniform_qualifier] = EBhDisable;
extensionBehavior[E_GL_EXT_samplerless_texture_functions] = EBhDisable;
extensionBehavior[E_GL_EXT_scalar_block_layout] = EBhDisable;
extensionBehavior[E_GL_EXT_fragment_invocation_density] = EBhDisable;
extensionBehavior[E_GL_EXT_buffer_reference] = EBhDisable;
extensionBehavior[E_GL_EXT_buffer_reference2] = EBhDisable;
extensionBehavior[E_GL_EXT_buffer_reference_uvec2] = EBhDisable;
extensionBehavior[E_GL_EXT_demote_to_helper_invocation] = EBhDisable;
extensionBehavior[E_GL_EXT_debug_printf] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_16bit_storage] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_8bit_storage] = EBhDisable;
extensionBehavior[E_GL_EXT_subgroup_uniform_control_flow] = EBhDisable;
extensionBehavior[E_GL_EXT_maximal_reconvergence] = EBhDisable;
extensionBehavior[E_GL_EXT_fragment_shader_barycentric] = EBhDisable;
extensionBehavior[E_GL_EXT_expect_assume] = EBhDisable;
extensionBehavior[E_GL_EXT_control_flow_attributes2] = EBhDisable;
extensionBehavior[E_GL_EXT_spec_constant_composites] = EBhDisable;
extensionBehavior[E_GL_KHR_cooperative_matrix] = EBhDisable;
// #line and #include
extensionBehavior[E_GL_GOOGLE_cpp_style_line_directive] = EBhDisable;
extensionBehavior[E_GL_GOOGLE_include_directive] = EBhDisable;
extensionBehavior[E_GL_ARB_shading_language_include] = EBhDisable;
extensionBehavior[E_GL_AMD_shader_ballot] = EBhDisable;
extensionBehavior[E_GL_AMD_shader_trinary_minmax] = EBhDisable;
extensionBehavior[E_GL_AMD_shader_explicit_vertex_parameter] = EBhDisable;
extensionBehavior[E_GL_AMD_gcn_shader] = EBhDisable;
extensionBehavior[E_GL_AMD_gpu_shader_half_float] = EBhDisable;
extensionBehavior[E_GL_AMD_texture_gather_bias_lod] = EBhDisable;
extensionBehavior[E_GL_AMD_gpu_shader_int16] = EBhDisable;
extensionBehavior[E_GL_AMD_shader_image_load_store_lod] = EBhDisable;
extensionBehavior[E_GL_AMD_shader_fragment_mask] = EBhDisable;
extensionBehavior[E_GL_AMD_gpu_shader_half_float_fetch] = EBhDisable;
extensionBehavior[E_GL_AMD_shader_early_and_late_fragment_tests] = EBhDisable;
extensionBehavior[E_GL_INTEL_shader_integer_functions2] = EBhDisable;
extensionBehavior[E_GL_NV_sample_mask_override_coverage] = EBhDisable;
extensionBehavior[E_SPV_NV_geometry_shader_passthrough] = EBhDisable;
extensionBehavior[E_GL_NV_viewport_array2] = EBhDisable;
extensionBehavior[E_GL_NV_stereo_view_rendering] = EBhDisable;
extensionBehavior[E_GL_NVX_multiview_per_view_attributes] = EBhDisable;
extensionBehavior[E_GL_NV_shader_atomic_int64] = EBhDisable;
extensionBehavior[E_GL_NV_conservative_raster_underestimation] = EBhDisable;
extensionBehavior[E_GL_NV_shader_noperspective_interpolation] = EBhDisable;
extensionBehavior[E_GL_NV_shader_subgroup_partitioned] = EBhDisable;
extensionBehavior[E_GL_NV_shading_rate_image] = EBhDisable;
extensionBehavior[E_GL_NV_ray_tracing] = EBhDisable;
extensionBehavior[E_GL_NV_ray_tracing_motion_blur] = EBhDisable;
extensionBehavior[E_GL_NV_fragment_shader_barycentric] = EBhDisable;
extensionBehavior[E_GL_NV_compute_shader_derivatives] = EBhDisable;
extensionBehavior[E_GL_NV_shader_texture_footprint] = EBhDisable;
extensionBehavior[E_GL_NV_mesh_shader] = EBhDisable;
extensionBehavior[E_GL_NV_cooperative_matrix] = EBhDisable;
extensionBehavior[E_GL_NV_shader_sm_builtins] = EBhDisable;
extensionBehavior[E_GL_NV_integer_cooperative_matrix] = EBhDisable;
extensionBehavior[E_GL_NV_shader_invocation_reorder] = EBhDisable;
extensionBehavior[E_GL_NV_displacement_micromap] = EBhDisable;
extensionBehavior[E_GL_NV_shader_atomic_fp16_vector] = EBhDisable;
// ARM
extensionBehavior[E_GL_ARM_shader_core_builtins] = EBhDisable;
// QCOM
extensionBehavior[E_GL_QCOM_image_processing] = EBhDisable;
extensionBehavior[E_GL_QCOM_image_processing2] = EBhDisable;
// AEP
extensionBehavior[E_GL_ANDROID_extension_pack_es31a] = EBhDisable;
extensionBehavior[E_GL_KHR_blend_equation_advanced] = EBhDisable;
extensionBehavior[E_GL_OES_sample_variables] = EBhDisable;
extensionBehavior[E_GL_OES_shader_image_atomic] = EBhDisable;
extensionBehavior[E_GL_OES_shader_multisample_interpolation] = EBhDisable;
extensionBehavior[E_GL_OES_texture_storage_multisample_2d_array] = EBhDisable;
extensionBehavior[E_GL_EXT_geometry_shader] = EBhDisable;
extensionBehavior[E_GL_EXT_geometry_point_size] = EBhDisable;
extensionBehavior[E_GL_EXT_gpu_shader5] = EBhDisable;
extensionBehavior[E_GL_EXT_primitive_bounding_box] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_io_blocks] = EBhDisable;
extensionBehavior[E_GL_EXT_tessellation_shader] = EBhDisable;
extensionBehavior[E_GL_EXT_tessellation_point_size] = EBhDisable;
extensionBehavior[E_GL_EXT_texture_buffer] = EBhDisable;
extensionBehavior[E_GL_EXT_texture_cube_map_array] = EBhDisable;
extensionBehavior[E_GL_EXT_null_initializer] = EBhDisable;
// OES matching AEP
extensionBehavior[E_GL_OES_geometry_shader] = EBhDisable;
extensionBehavior[E_GL_OES_geometry_point_size] = EBhDisable;
extensionBehavior[E_GL_OES_gpu_shader5] = EBhDisable;
extensionBehavior[E_GL_OES_primitive_bounding_box] = EBhDisable;
extensionBehavior[E_GL_OES_shader_io_blocks] = EBhDisable;
extensionBehavior[E_GL_OES_tessellation_shader] = EBhDisable;
extensionBehavior[E_GL_OES_tessellation_point_size] = EBhDisable;
extensionBehavior[E_GL_OES_texture_buffer] = EBhDisable;
extensionBehavior[E_GL_OES_texture_cube_map_array] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_integer_mix] = EBhDisable;
// EXT extensions
extensionBehavior[E_GL_EXT_device_group] = EBhDisable;
extensionBehavior[E_GL_EXT_multiview] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_realtime_clock] = EBhDisable;
extensionBehavior[E_GL_EXT_ray_tracing] = EBhDisable;
extensionBehavior[E_GL_EXT_ray_query] = EBhDisable;
extensionBehavior[E_GL_EXT_ray_flags_primitive_culling] = EBhDisable;
extensionBehavior[E_GL_EXT_ray_cull_mask] = EBhDisable;
extensionBehavior[E_GL_EXT_blend_func_extended] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_implicit_conversions] = EBhDisable;
extensionBehavior[E_GL_EXT_fragment_shading_rate] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_image_int64] = EBhDisable;
extensionBehavior[E_GL_EXT_terminate_invocation] = EBhDisable;
extensionBehavior[E_GL_EXT_shared_memory_block] = EBhDisable;
extensionBehavior[E_GL_EXT_spirv_intrinsics] = EBhDisable;
extensionBehavior[E_GL_EXT_mesh_shader] = EBhDisable;
extensionBehavior[E_GL_EXT_opacity_micromap] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_quad_control] = EBhDisable;
extensionBehavior[E_GL_EXT_ray_tracing_position_fetch] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_tile_image] = EBhDisable;
extensionBehavior[E_GL_EXT_texture_shadow_lod] = EBhDisable;
extensionBehavior[E_GL_EXT_draw_instanced] = EBhDisable;
extensionBehavior[E_GL_EXT_texture_array] = EBhDisable;
// OVR extensions
extensionBehavior[E_GL_OVR_multiview] = EBhDisable;
extensionBehavior[E_GL_OVR_multiview2] = EBhDisable;
// explicit types
extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int8] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int16] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int32] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int64] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float16] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float32] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float64] = EBhDisable;
// subgroup extended types
extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int8] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int16] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int64] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_float16] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_atomic_float] = EBhDisable;
extensionBehavior[E_GL_EXT_shader_atomic_float2] = EBhDisable;
// Record extensions not for spv.
spvUnsupportedExt.push_back(E_GL_ARB_bindless_texture);
}
// Get code that is not part of a shared symbol table, is specific to this shader,
// or needed by the preprocessor (which does not use a shared symbol table).
void TParseVersions::getPreamble(std::string& preamble)
{
if (isEsProfile()) {
preamble =
"#define GL_ES 1\n"
"#define GL_FRAGMENT_PRECISION_HIGH 1\n"
"#define GL_OES_texture_3D 1\n"
"#define GL_OES_standard_derivatives 1\n"
"#define GL_EXT_frag_depth 1\n"
"#define GL_OES_EGL_image_external 1\n"
"#define GL_OES_EGL_image_external_essl3 1\n"
"#define GL_EXT_YUV_target 1\n"
"#define GL_EXT_shader_texture_lod 1\n"
"#define GL_EXT_shadow_samplers 1\n"
"#define GL_EXT_fragment_shading_rate 1\n"
// AEP
"#define GL_ANDROID_extension_pack_es31a 1\n"
"#define GL_OES_sample_variables 1\n"
"#define GL_OES_shader_image_atomic 1\n"
"#define GL_OES_shader_multisample_interpolation 1\n"
"#define GL_OES_texture_storage_multisample_2d_array 1\n"
"#define GL_EXT_geometry_shader 1\n"
"#define GL_EXT_geometry_point_size 1\n"
"#define GL_EXT_gpu_shader5 1\n"
"#define GL_EXT_primitive_bounding_box 1\n"
"#define GL_EXT_shader_io_blocks 1\n"
"#define GL_EXT_tessellation_shader 1\n"
"#define GL_EXT_tessellation_point_size 1\n"
"#define GL_EXT_texture_buffer 1\n"
"#define GL_EXT_texture_cube_map_array 1\n"
"#define GL_EXT_shader_implicit_conversions 1\n"
"#define GL_EXT_shader_integer_mix 1\n"
"#define GL_EXT_blend_func_extended 1\n"
// OES matching AEP
"#define GL_OES_geometry_shader 1\n"
"#define GL_OES_geometry_point_size 1\n"
"#define GL_OES_gpu_shader5 1\n"
"#define GL_OES_primitive_bounding_box 1\n"
"#define GL_OES_shader_io_blocks 1\n"
"#define GL_OES_tessellation_shader 1\n"
"#define GL_OES_tessellation_point_size 1\n"
"#define GL_OES_texture_buffer 1\n"
"#define GL_OES_texture_cube_map_array 1\n"
"#define GL_EXT_shader_non_constant_global_initializers 1\n"
"#define GL_QCOM_image_processing 1\n"
"#define GL_QCOM_image_processing2 1\n"
;
if (version >= 300) {
preamble += "#define GL_NV_shader_noperspective_interpolation 1\n";
}
if (version >= 310) {
preamble += "#define GL_EXT_null_initializer 1\n";
preamble += "#define GL_EXT_subgroup_uniform_control_flow 1\n";
preamble += "#define GL_EXT_maximal_reconvergence 1\n";
}
} else { // !isEsProfile()
preamble =
"#define GL_ARB_texture_rectangle 1\n"
"#define GL_ARB_shading_language_420pack 1\n"
"#define GL_ARB_texture_gather 1\n"
"#define GL_ARB_gpu_shader5 1\n"
"#define GL_ARB_separate_shader_objects 1\n"
"#define GL_ARB_compute_shader 1\n"
"#define GL_ARB_tessellation_shader 1\n"
"#define GL_ARB_enhanced_layouts 1\n"
"#define GL_ARB_texture_cube_map_array 1\n"
"#define GL_ARB_texture_multisample 1\n"
"#define GL_ARB_shader_texture_lod 1\n"
"#define GL_ARB_explicit_attrib_location 1\n"
"#define GL_ARB_explicit_uniform_location 1\n"
"#define GL_ARB_shader_image_load_store 1\n"
"#define GL_ARB_shader_atomic_counters 1\n"
"#define GL_ARB_shader_draw_parameters 1\n"
"#define GL_ARB_shader_group_vote 1\n"
"#define GL_ARB_derivative_control 1\n"
"#define GL_ARB_shader_texture_image_samples 1\n"
"#define GL_ARB_viewport_array 1\n"
"#define GL_ARB_gpu_shader_int64 1\n"
"#define GL_ARB_gpu_shader_fp64 1\n"
"#define GL_ARB_shader_ballot 1\n"
"#define GL_ARB_sparse_texture2 1\n"
"#define GL_ARB_sparse_texture_clamp 1\n"
"#define GL_ARB_shader_stencil_export 1\n"
"#define GL_ARB_sample_shading 1\n"
"#define GL_ARB_shader_image_size 1\n"
"#define GL_ARB_shading_language_packing 1\n"
// "#define GL_ARB_cull_distance 1\n" // present for 4.5, but need extension control over block members
"#define GL_ARB_post_depth_coverage 1\n"
"#define GL_ARB_fragment_shader_interlock 1\n"
"#define GL_ARB_uniform_buffer_object 1\n"
"#define GL_ARB_shader_bit_encoding 1\n"
"#define GL_ARB_shader_storage_buffer_object 1\n"
"#define GL_ARB_texture_query_lod 1\n"
"#define GL_ARB_vertex_attrib_64bit 1\n"
"#define GL_ARB_draw_instanced 1\n"
"#define GL_ARB_fragment_coord_conventions 1\n"
"#define GL_EXT_shader_non_constant_global_initializers 1\n"
"#define GL_EXT_shader_image_load_formatted 1\n"
"#define GL_EXT_post_depth_coverage 1\n"
"#define GL_EXT_control_flow_attributes 1\n"
"#define GL_EXT_nonuniform_qualifier 1\n"
"#define GL_EXT_shader_16bit_storage 1\n"
"#define GL_EXT_shader_8bit_storage 1\n"
"#define GL_EXT_samplerless_texture_functions 1\n"
"#define GL_EXT_scalar_block_layout 1\n"
"#define GL_EXT_fragment_invocation_density 1\n"
"#define GL_EXT_buffer_reference 1\n"
"#define GL_EXT_buffer_reference2 1\n"
"#define GL_EXT_buffer_reference_uvec2 1\n"
"#define GL_EXT_demote_to_helper_invocation 1\n"
"#define GL_EXT_debug_printf 1\n"
"#define GL_EXT_fragment_shading_rate 1\n"
"#define GL_EXT_shared_memory_block 1\n"
"#define GL_EXT_shader_integer_mix 1\n"
"#define GL_EXT_spec_constant_composites 1\n"
// GL_KHR_shader_subgroup
"#define GL_KHR_shader_subgroup_basic 1\n"
"#define GL_KHR_shader_subgroup_vote 1\n"
"#define GL_KHR_shader_subgroup_arithmetic 1\n"
"#define GL_KHR_shader_subgroup_ballot 1\n"
"#define GL_KHR_shader_subgroup_shuffle 1\n"
"#define GL_KHR_shader_subgroup_shuffle_relative 1\n"
"#define GL_KHR_shader_subgroup_clustered 1\n"
"#define GL_KHR_shader_subgroup_quad 1\n"
"#define GL_KHR_cooperative_matrix 1\n"
"#define GL_EXT_shader_image_int64 1\n"
"#define GL_EXT_shader_atomic_int64 1\n"
"#define GL_EXT_shader_realtime_clock 1\n"
"#define GL_EXT_ray_tracing 1\n"
"#define GL_EXT_ray_query 1\n"
"#define GL_EXT_ray_flags_primitive_culling 1\n"
"#define GL_EXT_ray_cull_mask 1\n"
"#define GL_EXT_ray_tracing_position_fetch 1\n"
"#define GL_EXT_spirv_intrinsics 1\n"
"#define GL_EXT_mesh_shader 1\n"
"#define GL_AMD_shader_ballot 1\n"
"#define GL_AMD_shader_trinary_minmax 1\n"
"#define GL_AMD_shader_explicit_vertex_parameter 1\n"
"#define GL_AMD_gcn_shader 1\n"
"#define GL_AMD_gpu_shader_half_float 1\n"
"#define GL_AMD_texture_gather_bias_lod 1\n"
"#define GL_AMD_gpu_shader_int16 1\n"
"#define GL_AMD_shader_image_load_store_lod 1\n"
"#define GL_AMD_shader_fragment_mask 1\n"
"#define GL_AMD_gpu_shader_half_float_fetch 1\n"
"#define GL_INTEL_shader_integer_functions2 1\n"
"#define GL_NV_sample_mask_override_coverage 1\n"
"#define GL_NV_geometry_shader_passthrough 1\n"
"#define GL_NV_viewport_array2 1\n"
"#define GL_NV_shader_atomic_int64 1\n"
"#define GL_NV_conservative_raster_underestimation 1\n"
"#define GL_NV_shader_subgroup_partitioned 1\n"
"#define GL_NV_shading_rate_image 1\n"
"#define GL_NV_ray_tracing 1\n"
"#define GL_NV_ray_tracing_motion_blur 1\n"
"#define GL_NV_fragment_shader_barycentric 1\n"
"#define GL_NV_compute_shader_derivatives 1\n"
"#define GL_NV_shader_texture_footprint 1\n"
"#define GL_NV_mesh_shader 1\n"
"#define GL_NV_cooperative_matrix 1\n"
"#define GL_NV_integer_cooperative_matrix 1\n"
"#define GL_NV_shader_invocation_reorder 1\n"
"#define GL_QCOM_image_processing 1\n"
"#define GL_QCOM_image_processing2 1\n"
"#define GL_EXT_shader_explicit_arithmetic_types 1\n"
"#define GL_EXT_shader_explicit_arithmetic_types_int8 1\n"
"#define GL_EXT_shader_explicit_arithmetic_types_int16 1\n"
"#define GL_EXT_shader_explicit_arithmetic_types_int32 1\n"
"#define GL_EXT_shader_explicit_arithmetic_types_int64 1\n"
"#define GL_EXT_shader_explicit_arithmetic_types_float16 1\n"
"#define GL_EXT_shader_explicit_arithmetic_types_float32 1\n"
"#define GL_EXT_shader_explicit_arithmetic_types_float64 1\n"
"#define GL_EXT_shader_subgroup_extended_types_int8 1\n"
"#define GL_EXT_shader_subgroup_extended_types_int16 1\n"
"#define GL_EXT_shader_subgroup_extended_types_int64 1\n"
"#define GL_EXT_shader_subgroup_extended_types_float16 1\n"
"#define GL_EXT_shader_atomic_float 1\n"
"#define GL_EXT_shader_atomic_float2 1\n"
"#define GL_EXT_fragment_shader_barycentric 1\n"
"#define GL_EXT_shader_quad_control 1\n"
"#define GL_EXT_texture_array 1\n"
"#define GL_EXT_control_flow_attributes2 1\n"
;
if (spvVersion.spv == 0) {
preamble += "#define GL_ARB_bindless_texture 1\n";
}
if (version >= 150) {
// define GL_core_profile and GL_compatibility_profile
preamble += "#define GL_core_profile 1\n";
if (profile == ECompatibilityProfile)
preamble += "#define GL_compatibility_profile 1\n";
}
if (version >= 140) {
preamble += "#define GL_EXT_null_initializer 1\n";
preamble += "#define GL_EXT_subgroup_uniform_control_flow 1\n";
preamble += "#define GL_EXT_maximal_reconvergence 1\n";
}
if (version >= 130) {
preamble +="#define GL_FRAGMENT_PRECISION_HIGH 1\n";
}
}
if ((!isEsProfile() && version >= 140) ||
(isEsProfile() && version >= 310)) {
preamble +=
"#define GL_EXT_device_group 1\n"
"#define GL_EXT_multiview 1\n"
"#define GL_NV_shader_sm_builtins 1\n"
;
}
if (version >= 300 /* both ES and non-ES */) {
preamble +=
"#define GL_OVR_multiview 1\n"
"#define GL_OVR_multiview2 1\n"
;
}
// #line and #include
preamble +=
"#define GL_GOOGLE_cpp_style_line_directive 1\n"
"#define GL_GOOGLE_include_directive 1\n"
"#define GL_KHR_blend_equation_advanced 1\n"
;
// other general extensions
preamble +=
"#define GL_EXT_terminate_invocation 1\n"
;
// #define VULKAN XXXX
const int numberBufSize = 12;
char numberBuf[numberBufSize];
if (spvVersion.vulkanGlsl > 0) {
preamble += "#define VULKAN ";
snprintf(numberBuf, numberBufSize, "%d", spvVersion.vulkanGlsl);
preamble += numberBuf;
preamble += "\n";
}
// #define GL_SPIRV XXXX
if (spvVersion.openGl > 0) {
preamble += "#define GL_SPIRV ";
snprintf(numberBuf, numberBufSize, "%d", spvVersion.openGl);
preamble += numberBuf;
preamble += "\n";
}
// GL_EXT_spirv_intrinsics
if (!isEsProfile()) {
switch (language) {
case EShLangVertex: preamble += "#define GL_VERTEX_SHADER 1 \n"; break;
case EShLangTessControl: preamble += "#define GL_TESSELLATION_CONTROL_SHADER 1 \n"; break;
case EShLangTessEvaluation: preamble += "#define GL_TESSELLATION_EVALUATION_SHADER 1 \n"; break;
case EShLangGeometry: preamble += "#define GL_GEOMETRY_SHADER 1 \n"; break;
case EShLangFragment: preamble += "#define GL_FRAGMENT_SHADER 1 \n"; break;
case EShLangCompute: preamble += "#define GL_COMPUTE_SHADER 1 \n"; break;
case EShLangRayGen: preamble += "#define GL_RAY_GENERATION_SHADER_EXT 1 \n"; break;
case EShLangIntersect: preamble += "#define GL_INTERSECTION_SHADER_EXT 1 \n"; break;
case EShLangAnyHit: preamble += "#define GL_ANY_HIT_SHADER_EXT 1 \n"; break;
case EShLangClosestHit: preamble += "#define GL_CLOSEST_HIT_SHADER_EXT 1 \n"; break;
case EShLangMiss: preamble += "#define GL_MISS_SHADER_EXT 1 \n"; break;
case EShLangCallable: preamble += "#define GL_CALLABLE_SHADER_EXT 1 \n"; break;
case EShLangTask: preamble += "#define GL_TASK_SHADER_NV 1 \n"; break;
case EShLangMesh: preamble += "#define GL_MESH_SHADER_NV 1 \n"; break;
default: break;
}
}
}
//
// Map from stage enum to externally readable text name.
//
const char* StageName(EShLanguage stage)
{
switch(stage) {
case EShLangVertex: return "vertex";
case EShLangFragment: return "fragment";
case EShLangCompute: return "compute";
case EShLangTessControl: return "tessellation control";
case EShLangTessEvaluation: return "tessellation evaluation";
case EShLangGeometry: return "geometry";
case EShLangRayGen: return "ray-generation";
case EShLangIntersect: return "intersection";
case EShLangAnyHit: return "any-hit";
case EShLangClosestHit: return "closest-hit";
case EShLangMiss: return "miss";
case EShLangCallable: return "callable";
case EShLangMesh: return "mesh";
case EShLangTask: return "task";
default: return "unknown stage";
}
}
//
// When to use requireStage()
//
// If only some stages support a feature.
//
// Operation: If the current stage is not present, give an error message.
//
void TParseVersions::requireStage(const TSourceLoc& loc, EShLanguageMask languageMask, const char* featureDesc)
{
if (((1 << language) & languageMask) == 0)
error(loc, "not supported in this stage:", featureDesc, StageName(language));
}
// If only one stage supports a feature, this can be called. But, all supporting stages
// must be specified with one call.
void TParseVersions::requireStage(const TSourceLoc& loc, EShLanguage stage, const char* featureDesc)
{
requireStage(loc, static_cast<EShLanguageMask>(1 << stage), featureDesc);
}
//
// When to use requireProfile():
//
// Use if only some profiles support a feature. However, if within a profile the feature
// is version or extension specific, follow this call with calls to profileRequires().
//
// Operation: If the current profile is not one of the profileMask,
// give an error message.
//
void TParseVersions::requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc)
{
if (! (profile & profileMask))
error(loc, "not supported with this profile:", featureDesc, ProfileName(profile));
}
//
// When to use profileRequires():
//
// If a set of profiles have the same requirements for what version or extensions
// are needed to support a feature.
//
// It must be called for each profile that needs protection. Use requireProfile() first
// to reduce that set of profiles.
//
// Operation: Will issue warnings/errors based on the current profile, version, and extension
// behaviors. It only checks extensions when the current profile is one of the profileMask.
//
// A minVersion of 0 means no version of the profileMask support this in core,
// the extension must be present.
//
// entry point that takes multiple extensions
void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions,
const char* const extensions[], const char* featureDesc)
{
if (profile & profileMask) {
bool okay = minVersion > 0 && version >= minVersion;
for (int i = 0; i < numExtensions; ++i) {
switch (getExtensionBehavior(extensions[i])) {
case EBhWarn:
infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc);
[[fallthrough]];
case EBhRequire:
case EBhEnable:
okay = true;
break;
default: break; // some compilers want this
}
}
if (! okay)
error(loc, "not supported for this version or the enabled extensions", featureDesc, "");
}
}
// entry point for the above that takes a single extension
void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension,
const char* featureDesc)
{
profileRequires(loc, profileMask, minVersion, extension ? 1 : 0, &extension, featureDesc);
}
void TParseVersions::unimplemented(const TSourceLoc& loc, const char* featureDesc)
{
error(loc, "feature not yet implemented", featureDesc, "");
}
//
// Within a set of profiles, see if a feature is deprecated and give an error or warning based on whether
// a future compatibility context is being use.
//
void TParseVersions::checkDeprecated(const TSourceLoc& loc, int profileMask, int depVersion, const char* featureDesc)
{
if (profile & profileMask) {
if (version >= depVersion) {
if (forwardCompatible)
error(loc, "deprecated, may be removed in future release", featureDesc, "");
else if (! suppressWarnings())
infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " +
String(depVersion) + "; may be removed in future release").c_str(), loc);
}
}
}
//
// Within a set of profiles, see if a feature has now been removed and if so, give an error.
// The version argument is the first version no longer having the feature.
//
void TParseVersions::requireNotRemoved(const TSourceLoc& loc, int profileMask, int removedVersion, const char* featureDesc)
{
if (profile & profileMask) {
if (version >= removedVersion) {
const int maxSize = 60;
char buf[maxSize];
snprintf(buf, maxSize, "%s profile; removed in version %d", ProfileName(profile), removedVersion);
error(loc, "no longer supported in", featureDesc, buf);
}
}
}
// Returns true if at least one of the extensions in the extensions parameter is requested. Otherwise, returns false.
// Warns appropriately if the requested behavior of an extension is "warn".
bool TParseVersions::checkExtensionsRequested(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc)
{
// First, see if any of the extensions are enabled
for (int i = 0; i < numExtensions; ++i) {
TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
if (behavior == EBhEnable || behavior == EBhRequire)
return true;
}
// See if any extensions want to give a warning on use; give warnings for all such extensions
bool warned = false;
for (int i = 0; i < numExtensions; ++i) {
TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
if (behavior == EBhDisable && relaxedErrors()) {
infoSink.info.message(EPrefixWarning, "The following extension must be enabled to use this feature:", loc);
behavior = EBhWarn;
}
if (behavior == EBhWarn) {
infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc);
warned = true;
}
}
if (warned)
return true;
return false;
}
//
// Use when there are no profile/version to check, it's just an error if one of the
// extensions is not present.
//
void TParseVersions::requireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[],
const char* featureDesc)
{
if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc))
return;
// If we get this far, give errors explaining what extensions are needed
if (numExtensions == 1)
error(loc, "required extension not requested:", featureDesc, extensions[0]);
else {
error(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
for (int i = 0; i < numExtensions; ++i)
infoSink.info.message(EPrefixNone, extensions[i]);
}
}
//
// Use by preprocessor when there are no profile/version to check, it's just an error if one of the
// extensions is not present.
//
void TParseVersions::ppRequireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[],
const char* featureDesc)
{
if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc))
return;
// If we get this far, give errors explaining what extensions are needed
if (numExtensions == 1)
ppError(loc, "required extension not requested:", featureDesc, extensions[0]);
else {
ppError(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
for (int i = 0; i < numExtensions; ++i)
infoSink.info.message(EPrefixNone, extensions[i]);
}
}
TExtensionBehavior TParseVersions::getExtensionBehavior(const char* extension)
{
auto iter = extensionBehavior.find(TString(extension));
if (iter == extensionBehavior.end())
return EBhMissing;
else
return iter->second;
}
// Returns true if the given extension is set to enable, require, or warn.
bool TParseVersions::extensionTurnedOn(const char* const extension)
{
switch (getExtensionBehavior(extension)) {
case EBhEnable:
case EBhRequire:
case EBhWarn:
return true;
default:
break;
}
return false;
}
// See if any of the extensions are set to enable, require, or warn.
bool TParseVersions::extensionsTurnedOn(int numExtensions, const char* const extensions[])
{
for (int i = 0; i < numExtensions; ++i) {
if (extensionTurnedOn(extensions[i]))
return true;
}
return false;
}
//
// Change the current state of an extension's behavior.
//
void TParseVersions::updateExtensionBehavior(int line, const char* extension, const char* behaviorString)
{
// Translate from text string of extension's behavior to an enum.
TExtensionBehavior behavior = EBhDisable;
if (! strcmp("require", behaviorString))
behavior = EBhRequire;
else if (! strcmp("enable", behaviorString))
behavior = EBhEnable;
else if (! strcmp("disable", behaviorString))
behavior = EBhDisable;
else if (! strcmp("warn", behaviorString))
behavior = EBhWarn;
else {
error(getCurrentLoc(), "behavior not supported:", "#extension", behaviorString);
return;
}
bool on = behavior != EBhDisable;
// check if extension is used with correct shader stage
checkExtensionStage(getCurrentLoc(), extension);
// check if extension has additional requirements
extensionRequires(getCurrentLoc(), extension, behaviorString);
// update the requested extension
updateExtensionBehavior(extension, behavior);
// see if need to propagate to implicitly modified things
if (strcmp(extension, "GL_ANDROID_extension_pack_es31a") == 0) {
// to everything in AEP
updateExtensionBehavior(line, "GL_KHR_blend_equation_advanced", behaviorString);
updateExtensionBehavior(line, "GL_OES_sample_variables", behaviorString);
updateExtensionBehavior(line, "GL_OES_shader_image_atomic", behaviorString);
updateExtensionBehavior(line, "GL_OES_shader_multisample_interpolation", behaviorString);
updateExtensionBehavior(line, "GL_OES_texture_storage_multisample_2d_array", behaviorString);
updateExtensionBehavior(line, "GL_EXT_geometry_shader", behaviorString);
updateExtensionBehavior(line, "GL_EXT_gpu_shader5", behaviorString);
updateExtensionBehavior(line, "GL_EXT_primitive_bounding_box", behaviorString);
updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
updateExtensionBehavior(line, "GL_EXT_tessellation_shader", behaviorString);
updateExtensionBehavior(line, "GL_EXT_texture_buffer", behaviorString);
updateExtensionBehavior(line, "GL_EXT_texture_cube_map_array", behaviorString);
}
// geometry to io_blocks
else if (strcmp(extension, "GL_EXT_geometry_shader") == 0)
updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
else if (strcmp(extension, "GL_OES_geometry_shader") == 0)
updateExtensionBehavior(line, "GL_OES_shader_io_blocks", behaviorString);
// tessellation to io_blocks
else if (strcmp(extension, "GL_EXT_tessellation_shader") == 0)
updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
else if (strcmp(extension, "GL_OES_tessellation_shader") == 0)
updateExtensionBehavior(line, "GL_OES_shader_io_blocks", behaviorString);
else if (strcmp(extension, "GL_GOOGLE_include_directive") == 0)
updateExtensionBehavior(line, "GL_GOOGLE_cpp_style_line_directive", behaviorString);
else if (strcmp(extension, "GL_ARB_shading_language_include") == 0)
updateExtensionBehavior(line, "GL_GOOGLE_cpp_style_line_directive", behaviorString);
// subgroup_* to subgroup_basic
else if (strcmp(extension, "GL_KHR_shader_subgroup_vote") == 0)
updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
else if (strcmp(extension, "GL_KHR_shader_subgroup_arithmetic") == 0)
updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
else if (strcmp(extension, "GL_KHR_shader_subgroup_ballot") == 0)
updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
else if (strcmp(extension, "GL_KHR_shader_subgroup_shuffle") == 0)
updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
else if (strcmp(extension, "GL_KHR_shader_subgroup_shuffle_relative") == 0)
updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
else if (strcmp(extension, "GL_KHR_shader_subgroup_clustered") == 0)
updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
else if (strcmp(extension, "GL_KHR_shader_subgroup_quad") == 0)
updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
else if (strcmp(extension, "GL_NV_shader_subgroup_partitioned") == 0)
updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
else if (strcmp(extension, "GL_EXT_buffer_reference2") == 0 ||
strcmp(extension, "GL_EXT_buffer_reference_uvec2") == 0)
updateExtensionBehavior(line, "GL_EXT_buffer_reference", behaviorString);
else if (strcmp(extension, "GL_NV_integer_cooperative_matrix") == 0)
updateExtensionBehavior(line, "GL_NV_cooperative_matrix", behaviorString);
// subgroup extended types to explicit types
else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int8") == 0)
updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int8", behaviorString);
else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int16") == 0)
updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int16", behaviorString);
else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int64") == 0)
updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int64", behaviorString);
else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_float16") == 0)
updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_float16", behaviorString);
// see if we need to update the numeric features
else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types") == 0)
intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types, on);
else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int8") == 0)
intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int8, on);
else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int16") == 0)
intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int16, on);
else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int32") == 0)
intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int32, on);
else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int64") == 0)
intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int64, on);
else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float16") == 0)
intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float16, on);
else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float32") == 0)
intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float32, on);
else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float64") == 0)
intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float64, on);
else if (strcmp(extension, "GL_EXT_shader_implicit_conversions") == 0)
intermediate.updateNumericFeature(TNumericFeatures::shader_implicit_conversions, on);
else if (strcmp(extension, "GL_ARB_gpu_shader_fp64") == 0)
intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_fp64, on);
else if (strcmp(extension, "GL_AMD_gpu_shader_int16") == 0)
intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_int16, on);
else if (strcmp(extension, "GL_AMD_gpu_shader_half_float") == 0)
intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_half_float, on);
}
void TParseVersions::updateExtensionBehavior(const char* extension, TExtensionBehavior behavior)
{
// Update the current behavior
if (strcmp(extension, "all") == 0) {
// special case for the 'all' extension; apply it to every extension present
if (behavior == EBhRequire || behavior == EBhEnable) {
error(getCurrentLoc(), "extension 'all' cannot have 'require' or 'enable' behavior", "#extension", "");
return;
} else {
for (auto iter = extensionBehavior.begin(); iter != extensionBehavior.end(); ++iter)
iter->second = behavior;
}
} else {
// Do the update for this single extension
auto iter = extensionBehavior.find(TString(extension));
if (iter == extensionBehavior.end()) {
switch (behavior) {
case EBhRequire:
error(getCurrentLoc(), "extension not supported:", "#extension", extension);
break;
case EBhEnable:
case EBhWarn:
case EBhDisable:
warn(getCurrentLoc(), "extension not supported:", "#extension", extension);
break;
default:
assert(0 && "unexpected behavior");
}
return;
} else {
if (iter->second == EBhDisablePartial)
warn(getCurrentLoc(), "extension is only partially supported:", "#extension", extension);
if (behavior != EBhDisable)
intermediate.addRequestedExtension(extension);
iter->second = behavior;
}
}
}
// Check if extension is used with correct shader stage.
void TParseVersions::checkExtensionStage(const TSourceLoc& loc, const char * const extension)
{
// GL_NV_mesh_shader extension is only allowed in task/mesh shaders
if (strcmp(extension, "GL_NV_mesh_shader") == 0) {
requireStage(loc, (EShLanguageMask)(EShLangTaskMask | EShLangMeshMask | EShLangFragmentMask),
"#extension GL_NV_mesh_shader");
profileRequires(loc, ECoreProfile, 450, nullptr, "#extension GL_NV_mesh_shader");
profileRequires(loc, EEsProfile, 320, nullptr, "#extension GL_NV_mesh_shader");
if (extensionTurnedOn(E_GL_EXT_mesh_shader)) {
error(loc, "GL_EXT_mesh_shader is already turned on, and not allowed with", "#extension", extension);
}
}
else if (strcmp(extension, "GL_EXT_mesh_shader") == 0) {
requireStage(loc, (EShLanguageMask)(EShLangTaskMask | EShLangMeshMask | EShLangFragmentMask),
"#extension GL_EXT_mesh_shader");
profileRequires(loc, ECoreProfile, 450, nullptr, "#extension GL_EXT_mesh_shader");
profileRequires(loc, EEsProfile, 320, nullptr, "#extension GL_EXT_mesh_shader");
if (extensionTurnedOn(E_GL_NV_mesh_shader)) {
error(loc, "GL_NV_mesh_shader is already turned on, and not allowed with", "#extension", extension);
}
}
}
// Check if extension has additional requirements
void TParseVersions::extensionRequires(const TSourceLoc &loc, const char * const extension, const char *behaviorString)
{
bool isEnabled = false;
if (!strcmp("require", behaviorString))
isEnabled = true;
else if (!strcmp("enable", behaviorString))
isEnabled = true;
if (isEnabled) {
unsigned int minSpvVersion = 0;
auto iter = extensionMinSpv.find(TString(extension));
if (iter != extensionMinSpv.end())
minSpvVersion = iter->second;
requireSpv(loc, extension, minSpvVersion);
}
if (spvVersion.spv != 0){
for (auto ext : spvUnsupportedExt){
if (strcmp(extension, ext.c_str()) == 0)
error(loc, "not allowed when using generating SPIR-V codes", extension, "");
}
}
}
// Call for any operation needing full GLSL integer data-type support.
void TParseVersions::fullIntegerCheck(const TSourceLoc& loc, const char* op)
{
profileRequires(loc, ENoProfile, 130, nullptr, op);
profileRequires(loc, EEsProfile, 300, nullptr, op);
}
// Call for any operation needing GLSL double data-type support.
void TParseVersions::doubleCheck(const TSourceLoc& loc, const char* op)
{
//requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
if (language == EShLangVertex) {
const char* const f64_Extensions[] = {E_GL_ARB_gpu_shader_fp64, E_GL_ARB_vertex_attrib_64bit};
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, 2, f64_Extensions, op);
} else
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, E_GL_ARB_gpu_shader_fp64, op);
}
// Call for any operation needing GLSL float16 data-type support.
void TParseVersions::float16Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (!builtIn) {
const char* const extensions[] = {
E_GL_AMD_gpu_shader_half_float,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_float16};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
}
}
bool TParseVersions::float16Arithmetic()
{
const char* const extensions[] = {
E_GL_AMD_gpu_shader_half_float,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_float16};
return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
}
bool TParseVersions::int16Arithmetic()
{
const char* const extensions[] = {
E_GL_AMD_gpu_shader_int16,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int16};
return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
}
bool TParseVersions::int8Arithmetic()
{
const char* const extensions[] = {
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int8};
return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
}
void TParseVersions::requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
{
TString combined;
combined = op;
combined += ": ";
combined += featureDesc;
const char* const extensions[] = {
E_GL_AMD_gpu_shader_half_float,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_float16};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
}
void TParseVersions::requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
{
TString combined;
combined = op;
combined += ": ";
combined += featureDesc;
const char* const extensions[] = {
E_GL_AMD_gpu_shader_int16,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int16};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
}
void TParseVersions::requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
{
TString combined;
combined = op;
combined += ": ";
combined += featureDesc;
const char* const extensions[] = {
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int8};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
}
void TParseVersions::float16ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (!builtIn) {
const char* const extensions[] = {
E_GL_AMD_gpu_shader_half_float,
E_GL_EXT_shader_16bit_storage,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_float16};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
}
}
// Call for any operation needing GLSL float32 data-type support.
void TParseVersions::explicitFloat32Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (!builtIn) {
const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_float32};
requireExtensions(loc, 2, extensions, op);
}
}
// Call for any operation needing GLSL float64 data-type support.
void TParseVersions::explicitFloat64Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (!builtIn) {
const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_float64};
requireExtensions(loc, 2, extensions, op);
requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
}
}
// Call for any operation needing GLSL explicit int8 data-type support.
void TParseVersions::explicitInt8Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (! builtIn) {
const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int8};
requireExtensions(loc, 2, extensions, op);
}
}
// Call for any operation needing GLSL float16 opaque-type support
void TParseVersions::float16OpaqueCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (! builtIn) {
requireExtensions(loc, 1, &E_GL_AMD_gpu_shader_half_float_fetch, op);
requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
}
}
// Call for any operation needing GLSL explicit int16 data-type support.
void TParseVersions::explicitInt16Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (! builtIn) {
const char* const extensions[] = {
E_GL_AMD_gpu_shader_int16,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int16};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
}
}
void TParseVersions::int16ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (! builtIn) {
const char* const extensions[] = {
E_GL_AMD_gpu_shader_int16,
E_GL_EXT_shader_16bit_storage,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int16};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
}
}
void TParseVersions::int8ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (! builtIn) {
const char* const extensions[] = {
E_GL_EXT_shader_8bit_storage,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int8};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
}
}
// Call for any operation needing GLSL explicit int32 data-type support.
void TParseVersions::explicitInt32Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (! builtIn) {
const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int32};
requireExtensions(loc, 2, extensions, op);
}
}
// Call for any operation needing GLSL 64-bit integer data-type support.
void TParseVersions::int64Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (! builtIn) {
const char* const extensions[3] = {E_GL_ARB_gpu_shader_int64,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int64};
requireExtensions(loc, 3, extensions, op);
requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
}
}
void TParseVersions::fcoopmatCheckNV(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (!builtIn) {
const char* const extensions[] = {E_GL_NV_cooperative_matrix};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
}
}
void TParseVersions::intcoopmatCheckNV(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (!builtIn) {
const char* const extensions[] = {E_GL_NV_integer_cooperative_matrix};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
}
}
void TParseVersions::coopmatCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
if (!builtIn) {
const char* const extensions[] = {E_GL_KHR_cooperative_matrix};
requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
}
}
// Call for any operation removed because SPIR-V is in use.
void TParseVersions::spvRemoved(const TSourceLoc& loc, const char* op)
{
if (spvVersion.spv != 0)
error(loc, "not allowed when generating SPIR-V", op, "");
}
// Call for any operation removed because Vulkan SPIR-V is being generated.
void TParseVersions::vulkanRemoved(const TSourceLoc& loc, const char* op)
{
if (spvVersion.vulkan > 0 && !spvVersion.vulkanRelaxed)
error(loc, "not allowed when using GLSL for Vulkan", op, "");
}
// Call for any operation that requires Vulkan.
void TParseVersions::requireVulkan(const TSourceLoc& loc, const char* op)
{
if (spvVersion.vulkan == 0)
error(loc, "only allowed when using GLSL for Vulkan", op, "");
}
// Call for any operation that requires SPIR-V.
void TParseVersions::requireSpv(const TSourceLoc& loc, const char* op)
{
if (spvVersion.spv == 0)
error(loc, "only allowed when generating SPIR-V", op, "");
}
void TParseVersions::requireSpv(const TSourceLoc& loc, const char *op, unsigned int version)
{
if (spvVersion.spv < version)
error(loc, "not supported for current targeted SPIR-V version", op, "");
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/attribute.cpp | //
// Copyright (C) 2017 LunarG, Inc.
// Copyright (C) 2018 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "attribute.h"
#include "../Include/intermediate.h"
#include "ParseHelper.h"
namespace glslang {
// extract integers out of attribute arguments stored in attribute aggregate
bool TAttributeArgs::getInt(int& value, int argNum) const
{
const TConstUnion* intConst = getConstUnion(EbtInt, argNum);
if (intConst == nullptr)
return false;
value = intConst->getIConst();
return true;
}
// extract strings out of attribute arguments stored in attribute aggregate.
// convert to lower case if converToLower is true (for case-insensitive compare convenience)
bool TAttributeArgs::getString(TString& value, int argNum, bool convertToLower) const
{
const TConstUnion* stringConst = getConstUnion(EbtString, argNum);
if (stringConst == nullptr)
return false;
value = *stringConst->getSConst();
// Convenience.
if (convertToLower)
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
return true;
}
// How many arguments were supplied?
int TAttributeArgs::size() const
{
return args == nullptr ? 0 : (int)args->getSequence().size();
}
// Helper to get attribute const union. Returns nullptr on failure.
const TConstUnion* TAttributeArgs::getConstUnion(TBasicType basicType, int argNum) const
{
if (args == nullptr)
return nullptr;
if (argNum >= (int)args->getSequence().size())
return nullptr;
if (args->getSequence()[argNum]->getAsConstantUnion() == nullptr)
return nullptr;
const TConstUnion* constVal = &args->getSequence()[argNum]->getAsConstantUnion()->getConstArray()[0];
if (constVal == nullptr || constVal->getType() != basicType)
return nullptr;
return constVal;
}
// Implementation of TParseContext parts of attributes
TAttributeType TParseContext::attributeFromName(const TString& name) const
{
if (name == "branch" || name == "dont_flatten")
return EatBranch;
else if (name == "flatten")
return EatFlatten;
else if (name == "unroll")
return EatUnroll;
else if (name == "loop" || name == "dont_unroll")
return EatLoop;
else if (name == "dependency_infinite")
return EatDependencyInfinite;
else if (name == "dependency_length")
return EatDependencyLength;
else if (name == "min_iterations")
return EatMinIterations;
else if (name == "max_iterations")
return EatMaxIterations;
else if (name == "iteration_multiple")
return EatIterationMultiple;
else if (name == "peel_count")
return EatPeelCount;
else if (name == "partial_count")
return EatPartialCount;
else if (name == "subgroup_uniform_control_flow")
return EatSubgroupUniformControlFlow;
else if (name == "export")
return EatExport;
else if (name == "maximally_reconverges")
return EatMaximallyReconverges;
else
return EatNone;
}
// Make an initial leaf for the grammar from a no-argument attribute
TAttributes* TParseContext::makeAttributes(const TString& identifier) const
{
TAttributes *attributes = nullptr;
attributes = NewPoolObject(attributes);
TAttributeArgs args = { attributeFromName(identifier), nullptr };
attributes->push_back(args);
return attributes;
}
// Make an initial leaf for the grammar from a one-argument attribute
TAttributes* TParseContext::makeAttributes(const TString& identifier, TIntermNode* node) const
{
TAttributes *attributes = nullptr;
attributes = NewPoolObject(attributes);
// for now, node is always a simple single expression, but other code expects
// a list, so make it so
TIntermAggregate* agg = intermediate.makeAggregate(node);
TAttributeArgs args = { attributeFromName(identifier), agg };
attributes->push_back(args);
return attributes;
}
// Merge two sets of attributes into a single set.
// The second argument is destructively consumed.
TAttributes* TParseContext::mergeAttributes(TAttributes* attr1, TAttributes* attr2) const
{
attr1->splice(attr1->end(), *attr2);
return attr1;
}
//
// Selection attributes
//
void TParseContext::handleSelectionAttributes(const TAttributes& attributes, TIntermNode* node)
{
TIntermSelection* selection = node->getAsSelectionNode();
if (selection == nullptr)
return;
for (auto it = attributes.begin(); it != attributes.end(); ++it) {
if (it->size() > 0) {
warn(node->getLoc(), "attribute with arguments not recognized, skipping", "", "");
continue;
}
switch (it->name) {
case EatFlatten:
selection->setFlatten();
break;
case EatBranch:
selection->setDontFlatten();
break;
default:
warn(node->getLoc(), "attribute does not apply to a selection", "", "");
break;
}
}
}
//
// Switch attributes
//
void TParseContext::handleSwitchAttributes(const TAttributes& attributes, TIntermNode* node)
{
TIntermSwitch* selection = node->getAsSwitchNode();
if (selection == nullptr)
return;
for (auto it = attributes.begin(); it != attributes.end(); ++it) {
if (it->size() > 0) {
warn(node->getLoc(), "attribute with arguments not recognized, skipping", "", "");
continue;
}
switch (it->name) {
case EatFlatten:
selection->setFlatten();
break;
case EatBranch:
selection->setDontFlatten();
break;
default:
warn(node->getLoc(), "attribute does not apply to a switch", "", "");
break;
}
}
}
//
// Loop attributes
//
void TParseContext::handleLoopAttributes(const TAttributes& attributes, TIntermNode* node)
{
TIntermLoop* loop = node->getAsLoopNode();
if (loop == nullptr) {
// the actual loop might be part of a sequence
TIntermAggregate* agg = node->getAsAggregate();
if (agg == nullptr)
return;
for (auto it = agg->getSequence().begin(); it != agg->getSequence().end(); ++it) {
loop = (*it)->getAsLoopNode();
if (loop != nullptr)
break;
}
if (loop == nullptr)
return;
}
for (auto it = attributes.begin(); it != attributes.end(); ++it) {
const auto noArgument = [&](const char* feature) {
if (it->size() > 0) {
warn(node->getLoc(), "expected no arguments", feature, "");
return false;
}
return true;
};
const auto positiveSignedArgument = [&](const char* feature, int& value) {
if (it->size() == 1 && it->getInt(value)) {
if (value <= 0) {
error(node->getLoc(), "must be positive", feature, "");
return false;
}
} else {
warn(node->getLoc(), "expected a single integer argument", feature, "");
return false;
}
return true;
};
const auto unsignedArgument = [&](const char* feature, unsigned int& uiValue) {
int value;
if (!(it->size() == 1 && it->getInt(value))) {
warn(node->getLoc(), "expected a single integer argument", feature, "");
return false;
}
uiValue = (unsigned int)value;
return true;
};
const auto positiveUnsignedArgument = [&](const char* feature, unsigned int& uiValue) {
int value;
if (it->size() == 1 && it->getInt(value)) {
if (value == 0) {
error(node->getLoc(), "must be greater than or equal to 1", feature, "");
return false;
}
} else {
warn(node->getLoc(), "expected a single integer argument", feature, "");
return false;
}
uiValue = (unsigned int)value;
return true;
};
const auto spirv14 = [&](const char* feature) {
if (spvVersion.spv > 0 && spvVersion.spv < EShTargetSpv_1_4)
warn(node->getLoc(), "attribute requires a SPIR-V 1.4 target-env", feature, "");
};
int value = 0;
unsigned uiValue = 0;
switch (it->name) {
case EatUnroll:
if (noArgument("unroll"))
loop->setUnroll();
break;
case EatLoop:
if (noArgument("dont_unroll"))
loop->setDontUnroll();
break;
case EatDependencyInfinite:
if (noArgument("dependency_infinite"))
loop->setLoopDependency(TIntermLoop::dependencyInfinite);
break;
case EatDependencyLength:
if (positiveSignedArgument("dependency_length", value))
loop->setLoopDependency(value);
break;
case EatMinIterations:
spirv14("min_iterations");
if (unsignedArgument("min_iterations", uiValue))
loop->setMinIterations(uiValue);
break;
case EatMaxIterations:
spirv14("max_iterations");
if (unsignedArgument("max_iterations", uiValue))
loop->setMaxIterations(uiValue);
break;
case EatIterationMultiple:
spirv14("iteration_multiple");
if (positiveUnsignedArgument("iteration_multiple", uiValue))
loop->setIterationMultiple(uiValue);
break;
case EatPeelCount:
spirv14("peel_count");
if (unsignedArgument("peel_count", uiValue))
loop->setPeelCount(uiValue);
break;
case EatPartialCount:
spirv14("partial_count");
if (unsignedArgument("partial_count", uiValue))
loop->setPartialCount(uiValue);
break;
default:
warn(node->getLoc(), "attribute does not apply to a loop", "", "");
break;
}
}
}
//
// Function attributes
//
void TParseContext::handleFunctionAttributes(const TSourceLoc& loc, const TAttributes& attributes)
{
for (auto it = attributes.begin(); it != attributes.end(); ++it) {
if (it->size() > 0) {
warn(loc, "attribute with arguments not recognized, skipping", "", "");
continue;
}
switch (it->name) {
case EatSubgroupUniformControlFlow:
requireExtensions(loc, 1, &E_GL_EXT_subgroup_uniform_control_flow, "attribute");
intermediate.setSubgroupUniformControlFlow();
break;
case EatMaximallyReconverges:
requireExtensions(loc, 1, &E_GL_EXT_maximal_reconvergence, "attribute");
intermediate.setMaximallyReconverges();
break;
default:
warn(loc, "attribute does not apply to a function", "", "");
break;
}
}
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/propagateNoContraction.cpp | //
// Copyright (C) 2015-2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Visit the nodes in the glslang intermediate tree representation to
// propagate the 'noContraction' qualifier.
//
#include "propagateNoContraction.h"
#include <cstdlib>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include "localintermediate.h"
namespace {
// Use a string to hold the access chain information, as in most cases the
// access chain is short and may contain only one element, which is the symbol
// ID.
// Example: struct {float a; float b;} s;
// Object s.a will be represented with: <symbol ID of s>/0
// Object s.b will be represented with: <symbol ID of s>/1
// Object s will be represented with: <symbol ID of s>
// For members of vector, matrix and arrays, they will be represented with the
// same symbol ID of their container symbol objects. This is because their
// preciseness is always the same as their container symbol objects.
typedef std::string ObjectAccessChain;
// The delimiter used in the ObjectAccessChain string to separate symbol ID and
// different level of struct indices.
const char ObjectAccesschainDelimiter = '/';
// Mapping from Symbol IDs of symbol nodes, to their defining operation
// nodes.
typedef std::unordered_multimap<ObjectAccessChain, glslang::TIntermOperator*> NodeMapping;
// Mapping from object nodes to their access chain info string.
typedef std::unordered_map<glslang::TIntermTyped*, ObjectAccessChain> AccessChainMapping;
// Set of object IDs.
typedef std::unordered_set<ObjectAccessChain> ObjectAccesschainSet;
// Set of return branch nodes.
typedef std::unordered_set<glslang::TIntermBranch*> ReturnBranchNodeSet;
// A helper function to tell whether a node is 'noContraction'. Returns true if
// the node has 'noContraction' qualifier, otherwise false.
bool isPreciseObjectNode(glslang::TIntermTyped* node)
{
return node->getType().getQualifier().isNoContraction();
}
// Returns true if the opcode is a dereferencing one.
bool isDereferenceOperation(glslang::TOperator op)
{
switch (op) {
case glslang::EOpIndexDirect:
case glslang::EOpIndexDirectStruct:
case glslang::EOpIndexIndirect:
case glslang::EOpVectorSwizzle:
case glslang::EOpMatrixSwizzle:
return true;
default:
return false;
}
}
// Returns true if the opcode leads to an assignment operation.
bool isAssignOperation(glslang::TOperator op)
{
switch (op) {
case glslang::EOpAssign:
case glslang::EOpAddAssign:
case glslang::EOpSubAssign:
case glslang::EOpMulAssign:
case glslang::EOpVectorTimesMatrixAssign:
case glslang::EOpVectorTimesScalarAssign:
case glslang::EOpMatrixTimesScalarAssign:
case glslang::EOpMatrixTimesMatrixAssign:
case glslang::EOpDivAssign:
case glslang::EOpModAssign:
case glslang::EOpAndAssign:
case glslang::EOpLeftShiftAssign:
case glslang::EOpRightShiftAssign:
case glslang::EOpInclusiveOrAssign:
case glslang::EOpExclusiveOrAssign:
case glslang::EOpPostIncrement:
case glslang::EOpPostDecrement:
case glslang::EOpPreIncrement:
case glslang::EOpPreDecrement:
return true;
default:
return false;
}
}
// A helper function to get the unsigned int from a given constant union node.
// Note the node should only hold a uint scalar.
unsigned getStructIndexFromConstantUnion(glslang::TIntermTyped* node)
{
assert(node->getAsConstantUnion() && node->getAsConstantUnion()->isScalar());
unsigned struct_dereference_index = node->getAsConstantUnion()->getConstArray()[0].getUConst();
return struct_dereference_index;
}
// A helper function to generate symbol_label.
ObjectAccessChain generateSymbolLabel(glslang::TIntermSymbol* node)
{
ObjectAccessChain symbol_id =
std::to_string(node->getId()) + "(" + node->getName().c_str() + ")";
return symbol_id;
}
// Returns true if the operation is an arithmetic operation and valid for
// the 'NoContraction' decoration.
bool isArithmeticOperation(glslang::TOperator op)
{
switch (op) {
case glslang::EOpAddAssign:
case glslang::EOpSubAssign:
case glslang::EOpMulAssign:
case glslang::EOpVectorTimesMatrixAssign:
case glslang::EOpVectorTimesScalarAssign:
case glslang::EOpMatrixTimesScalarAssign:
case glslang::EOpMatrixTimesMatrixAssign:
case glslang::EOpDivAssign:
case glslang::EOpModAssign:
case glslang::EOpNegative:
case glslang::EOpAdd:
case glslang::EOpSub:
case glslang::EOpMul:
case glslang::EOpDiv:
case glslang::EOpMod:
case glslang::EOpVectorTimesScalar:
case glslang::EOpVectorTimesMatrix:
case glslang::EOpMatrixTimesVector:
case glslang::EOpMatrixTimesScalar:
case glslang::EOpMatrixTimesMatrix:
case glslang::EOpDot:
case glslang::EOpPostIncrement:
case glslang::EOpPostDecrement:
case glslang::EOpPreIncrement:
case glslang::EOpPreDecrement:
return true;
default:
return false;
}
}
// A helper class to help manage the populating_initial_no_contraction_ flag.
template <typename T> class StateSettingGuard {
public:
StateSettingGuard(T* state_ptr, T new_state_value)
: state_ptr_(state_ptr), previous_state_(*state_ptr)
{
*state_ptr = new_state_value;
}
StateSettingGuard(T* state_ptr) : state_ptr_(state_ptr), previous_state_(*state_ptr) {}
void setState(T new_state_value) { *state_ptr_ = new_state_value; }
~StateSettingGuard() { *state_ptr_ = previous_state_; }
private:
T* state_ptr_;
T previous_state_;
};
// A helper function to get the front element from a given ObjectAccessChain
ObjectAccessChain getFrontElement(const ObjectAccessChain& chain)
{
size_t pos_delimiter = chain.find(ObjectAccesschainDelimiter);
return pos_delimiter == std::string::npos ? chain : chain.substr(0, pos_delimiter);
}
// A helper function to get the access chain starting from the second element.
ObjectAccessChain subAccessChainFromSecondElement(const ObjectAccessChain& chain)
{
size_t pos_delimiter = chain.find(ObjectAccesschainDelimiter);
return pos_delimiter == std::string::npos ? "" : chain.substr(pos_delimiter + 1);
}
// A helper function to get the access chain after removing a given prefix.
ObjectAccessChain getSubAccessChainAfterPrefix(const ObjectAccessChain& chain,
const ObjectAccessChain& prefix)
{
size_t pos = chain.find(prefix);
if (pos != 0)
return chain;
return chain.substr(prefix.length() + sizeof(ObjectAccesschainDelimiter));
}
//
// A traverser which traverses the whole AST and populates:
// 1) A mapping from symbol nodes' IDs to their defining operation nodes.
// 2) A set of access chains of the initial precise object nodes.
//
class TSymbolDefinitionCollectingTraverser : public glslang::TIntermTraverser {
public:
TSymbolDefinitionCollectingTraverser(NodeMapping* symbol_definition_mapping,
AccessChainMapping* accesschain_mapping,
ObjectAccesschainSet* precise_objects,
ReturnBranchNodeSet* precise_return_nodes);
bool visitUnary(glslang::TVisit, glslang::TIntermUnary*) override;
bool visitBinary(glslang::TVisit, glslang::TIntermBinary*) override;
void visitSymbol(glslang::TIntermSymbol*) override;
bool visitAggregate(glslang::TVisit, glslang::TIntermAggregate*) override;
bool visitBranch(glslang::TVisit, glslang::TIntermBranch*) override;
protected:
TSymbolDefinitionCollectingTraverser& operator=(const TSymbolDefinitionCollectingTraverser&);
// The mapping from symbol node IDs to their defining nodes. This should be
// populated along traversing the AST.
NodeMapping& symbol_definition_mapping_;
// The set of symbol node IDs for precise symbol nodes, the ones marked as
// 'noContraction'.
ObjectAccesschainSet& precise_objects_;
// The set of precise return nodes.
ReturnBranchNodeSet& precise_return_nodes_;
// A temporary cache of the symbol node whose defining node is to be found
// currently along traversing the AST.
ObjectAccessChain current_object_;
// A map from object node to its access chain. This traverser stores
// the built access chains into this map for each object node it has
// visited.
AccessChainMapping& accesschain_mapping_;
// The pointer to the Function Definition node, so we can get the
// preciseness of the return expression from it when we traverse the
// return branch node.
glslang::TIntermAggregate* current_function_definition_node_;
};
TSymbolDefinitionCollectingTraverser::TSymbolDefinitionCollectingTraverser(
NodeMapping* symbol_definition_mapping, AccessChainMapping* accesschain_mapping,
ObjectAccesschainSet* precise_objects,
std::unordered_set<glslang::TIntermBranch*>* precise_return_nodes)
: TIntermTraverser(true, false, false), symbol_definition_mapping_(*symbol_definition_mapping),
precise_objects_(*precise_objects), precise_return_nodes_(*precise_return_nodes),
current_object_(), accesschain_mapping_(*accesschain_mapping),
current_function_definition_node_(nullptr) {}
// Visits a symbol node, set the current_object_ to the
// current node symbol ID, and record a mapping from this node to the current
// current_object_, which is the just obtained symbol
// ID.
void TSymbolDefinitionCollectingTraverser::visitSymbol(glslang::TIntermSymbol* node)
{
current_object_ = generateSymbolLabel(node);
accesschain_mapping_[node] = current_object_;
}
// Visits an aggregate node, traverses all of its children.
bool TSymbolDefinitionCollectingTraverser::visitAggregate(glslang::TVisit,
glslang::TIntermAggregate* node)
{
// This aggregate node might be a function definition node, in which case we need to
// cache this node, so we can get the preciseness information of the return value
// of this function later.
StateSettingGuard<glslang::TIntermAggregate*> current_function_definition_node_setting_guard(
¤t_function_definition_node_);
if (node->getOp() == glslang::EOpFunction) {
// This is function definition node, we need to cache this node so that we can
// get the preciseness of the return value later.
current_function_definition_node_setting_guard.setState(node);
}
// Traverse the items in the sequence.
glslang::TIntermSequence& seq = node->getSequence();
for (int i = 0; i < (int)seq.size(); ++i) {
current_object_.clear();
seq[i]->traverse(this);
}
return false;
}
bool TSymbolDefinitionCollectingTraverser::visitBranch(glslang::TVisit,
glslang::TIntermBranch* node)
{
if (node->getFlowOp() == glslang::EOpReturn && node->getExpression() &&
current_function_definition_node_ &&
current_function_definition_node_->getType().getQualifier().noContraction) {
// This node is a return node with an expression, and its function has a
// precise return value. We need to find the involved objects in its
// expression and add them to the set of initial precise objects.
precise_return_nodes_.insert(node);
node->getExpression()->traverse(this);
}
return false;
}
// Visits a unary node. This might be an implicit assignment like i++, i--. etc.
bool TSymbolDefinitionCollectingTraverser::visitUnary(glslang::TVisit /* visit */,
glslang::TIntermUnary* node)
{
current_object_.clear();
node->getOperand()->traverse(this);
if (isAssignOperation(node->getOp())) {
// We should always be able to get an access chain of the operand node.
assert(!current_object_.empty());
// If the operand node object is 'precise', we collect its access chain
// for the initial set of 'precise' objects.
if (isPreciseObjectNode(node->getOperand())) {
// The operand node is an 'precise' object node, add its
// access chain to the set of 'precise' objects. This is to collect
// the initial set of 'precise' objects.
precise_objects_.insert(current_object_);
}
// Gets the symbol ID from the object's access chain.
ObjectAccessChain id_symbol = getFrontElement(current_object_);
// Add a mapping from the symbol ID to this assignment operation node.
symbol_definition_mapping_.insert(std::make_pair(id_symbol, node));
}
// A unary node is not a dereference node, so we clear the access chain which
// is under construction.
current_object_.clear();
return false;
}
// Visits a binary node and updates the mapping from symbol IDs to the definition
// nodes. Also collects the access chains for the initial precise objects.
bool TSymbolDefinitionCollectingTraverser::visitBinary(glslang::TVisit /* visit */,
glslang::TIntermBinary* node)
{
// Traverses the left node to build the access chain info for the object.
current_object_.clear();
node->getLeft()->traverse(this);
if (isAssignOperation(node->getOp())) {
// We should always be able to get an access chain for the left node.
assert(!current_object_.empty());
// If the left node object is 'precise', it is an initial precise object
// specified in the shader source. Adds it to the initial work list to
// process later.
if (isPreciseObjectNode(node->getLeft())) {
// The left node is an 'precise' object node, add its access chain to
// the set of 'precise' objects. This is to collect the initial set
// of 'precise' objects.
precise_objects_.insert(current_object_);
}
// Gets the symbol ID from the object access chain, which should be the
// first element recorded in the access chain.
ObjectAccessChain id_symbol = getFrontElement(current_object_);
// Adds a mapping from the symbol ID to this assignment operation node.
symbol_definition_mapping_.insert(std::make_pair(id_symbol, node));
// Traverses the right node, there may be other 'assignment'
// operations in the right.
current_object_.clear();
node->getRight()->traverse(this);
} else if (isDereferenceOperation(node->getOp())) {
// The left node (parent node) is a struct type object. We need to
// record the access chain information of the current node into its
// object id.
if (node->getOp() == glslang::EOpIndexDirectStruct) {
unsigned struct_dereference_index = getStructIndexFromConstantUnion(node->getRight());
current_object_.push_back(ObjectAccesschainDelimiter);
current_object_.append(std::to_string(struct_dereference_index));
}
accesschain_mapping_[node] = current_object_;
// For a dereference node, there is no need to traverse the right child
// node as the right node should always be an integer type object.
} else {
// For other binary nodes, still traverse the right node.
current_object_.clear();
node->getRight()->traverse(this);
}
return false;
}
// Traverses the AST and returns a tuple of four members:
// 1) a mapping from symbol IDs to the definition nodes (aka. assignment nodes) of these symbols.
// 2) a mapping from object nodes in the AST to the access chains of these objects.
// 3) a set of access chains of precise objects.
// 4) a set of return nodes with precise expressions.
std::tuple<NodeMapping, AccessChainMapping, ObjectAccesschainSet, ReturnBranchNodeSet>
getSymbolToDefinitionMappingAndPreciseSymbolIDs(const glslang::TIntermediate& intermediate)
{
auto result_tuple = std::make_tuple(NodeMapping(), AccessChainMapping(), ObjectAccesschainSet(),
ReturnBranchNodeSet());
TIntermNode* root = intermediate.getTreeRoot();
if (root == nullptr)
return result_tuple;
NodeMapping& symbol_definition_mapping = std::get<0>(result_tuple);
AccessChainMapping& accesschain_mapping = std::get<1>(result_tuple);
ObjectAccesschainSet& precise_objects = std::get<2>(result_tuple);
ReturnBranchNodeSet& precise_return_nodes = std::get<3>(result_tuple);
// Traverses the AST and populate the results.
TSymbolDefinitionCollectingTraverser collector(&symbol_definition_mapping, &accesschain_mapping,
&precise_objects, &precise_return_nodes);
root->traverse(&collector);
return result_tuple;
}
//
// A traverser that determine whether the left node (or operand node for unary
// node) of an assignment node is 'precise', containing 'precise' or not,
// according to the access chain a given precise object which share the same
// symbol as the left node.
//
// Post-orderly traverses the left node subtree of an binary assignment node and:
//
// 1) Propagates the 'precise' from the left object nodes to this object node.
//
// 2) Builds object access chain along the traversal, and also compares with
// the access chain of the given 'precise' object along with the traversal to
// tell if the node to be defined is 'precise' or not.
//
class TNoContractionAssigneeCheckingTraverser : public glslang::TIntermTraverser {
enum DecisionStatus {
// The object node to be assigned to may contain 'precise' objects and also not 'precise' objects.
Mixed = 0,
// The object node to be assigned to is either a 'precise' object or a struct objects whose members are all 'precise'.
Precise = 1,
// The object node to be assigned to is not a 'precise' object.
NotPreicse = 2,
};
public:
TNoContractionAssigneeCheckingTraverser(const AccessChainMapping& accesschain_mapping)
: TIntermTraverser(true, false, false), accesschain_mapping_(accesschain_mapping),
precise_object_(nullptr) {}
// Checks the preciseness of a given assignment node with a precise object
// represented as access chain. The precise object shares the same symbol
// with the assignee of the given assignment node. Return a tuple of two:
//
// 1) The preciseness of the assignee node of this assignment node. True
// if the assignee contains 'precise' objects or is 'precise', false if
// the assignee is not 'precise' according to the access chain of the given
// precise object.
//
// 2) The incremental access chain from the assignee node to its nested
// 'precise' object, according to the access chain of the given precise
// object. This incremental access chain can be empty, which means the
// assignee is 'precise'. Otherwise it shows the path to the nested
// precise object.
std::tuple<bool, ObjectAccessChain>
getPrecisenessAndRemainedAccessChain(glslang::TIntermOperator* node,
const ObjectAccessChain& precise_object)
{
assert(isAssignOperation(node->getOp()));
precise_object_ = &precise_object;
ObjectAccessChain assignee_object;
if (glslang::TIntermBinary* BN = node->getAsBinaryNode()) {
// This is a binary assignment node, we need to check the
// preciseness of the left node.
assert(accesschain_mapping_.count(BN->getLeft()));
// The left node (assignee node) is an object node, traverse the
// node to let the 'precise' of nesting objects being transfered to
// nested objects.
BN->getLeft()->traverse(this);
// After traversing the left node, if the left node is 'precise',
// we can conclude this assignment should propagate 'precise'.
if (isPreciseObjectNode(BN->getLeft())) {
return make_tuple(true, ObjectAccessChain());
}
// If the preciseness of the left node (assignee node) can not
// be determined by now, we need to compare the access chain string
// of the assignee object with the given precise object.
assignee_object = accesschain_mapping_.at(BN->getLeft());
} else if (glslang::TIntermUnary* UN = node->getAsUnaryNode()) {
// This is a unary assignment node, we need to check the
// preciseness of the operand node. For unary assignment node, the
// operand node should always be an object node.
assert(accesschain_mapping_.count(UN->getOperand()));
// Traverse the operand node to let the 'precise' being propagated
// from lower nodes to upper nodes.
UN->getOperand()->traverse(this);
// After traversing the operand node, if the operand node is
// 'precise', this assignment should propagate 'precise'.
if (isPreciseObjectNode(UN->getOperand())) {
return make_tuple(true, ObjectAccessChain());
}
// If the preciseness of the operand node (assignee node) can not
// be determined by now, we need to compare the access chain string
// of the assignee object with the given precise object.
assignee_object = accesschain_mapping_.at(UN->getOperand());
} else {
// Not a binary or unary node, should not happen.
assert(false);
}
// Compare the access chain string of the assignee node with the given
// precise object to determine if this assignment should propagate
// 'precise'.
if (assignee_object.find(precise_object) == 0) {
// The access chain string of the given precise object is a prefix
// of assignee's access chain string. The assignee should be
// 'precise'.
return make_tuple(true, ObjectAccessChain());
} else if (precise_object.find(assignee_object) == 0) {
// The assignee's access chain string is a prefix of the given
// precise object, the assignee object contains 'precise' object,
// and we need to pass the remained access chain to the object nodes
// in the right.
return make_tuple(true, getSubAccessChainAfterPrefix(precise_object, assignee_object));
} else {
// The access chain strings do not match, the assignee object can
// not be labeled as 'precise' according to the given precise
// object.
return make_tuple(false, ObjectAccessChain());
}
}
protected:
TNoContractionAssigneeCheckingTraverser& operator=(const TNoContractionAssigneeCheckingTraverser&);
bool visitBinary(glslang::TVisit, glslang::TIntermBinary* node) override;
void visitSymbol(glslang::TIntermSymbol* node) override;
// A map from object nodes to their access chain string (used as object ID).
const AccessChainMapping& accesschain_mapping_;
// A given precise object, represented in it access chain string. This
// precise object is used to be compared with the assignee node to tell if
// the assignee node is 'precise', contains 'precise' object or not
// 'precise'.
const ObjectAccessChain* precise_object_;
};
// Visits a binary node. If the node is an object node, it must be a dereference
// node. In such cases, if the left node is 'precise', this node should also be
// 'precise'.
bool TNoContractionAssigneeCheckingTraverser::visitBinary(glslang::TVisit,
glslang::TIntermBinary* node)
{
// Traverses the left so that we transfer the 'precise' from nesting object
// to its nested object.
node->getLeft()->traverse(this);
// If this binary node is an object node, we should have it in the
// accesschain_mapping_.
if (accesschain_mapping_.count(node)) {
// A binary object node must be a dereference node.
assert(isDereferenceOperation(node->getOp()));
// If the left node is 'precise', this node should also be precise,
// otherwise, compare with the given precise_object_. If the
// access chain of this node matches with the given precise_object_,
// this node should be marked as 'precise'.
if (isPreciseObjectNode(node->getLeft())) {
node->getWritableType().getQualifier().noContraction = true;
} else if (accesschain_mapping_.at(node) == *precise_object_) {
node->getWritableType().getQualifier().noContraction = true;
}
}
return false;
}
// Visits a symbol node, if the symbol node ID (its access chain string) matches
// with the given precise object, this node should be 'precise'.
void TNoContractionAssigneeCheckingTraverser::visitSymbol(glslang::TIntermSymbol* node)
{
// A symbol node should always be an object node, and should have been added
// to the map from object nodes to their access chain strings.
assert(accesschain_mapping_.count(node));
if (accesschain_mapping_.at(node) == *precise_object_) {
node->getWritableType().getQualifier().noContraction = true;
}
}
//
// A traverser that only traverses the right side of binary assignment nodes
// and the operand node of unary assignment nodes.
//
// 1) Marks arithmetic operations as 'NoContraction'.
//
// 2) Find the object which should be marked as 'precise' in the right and
// update the 'precise' object work list.
//
class TNoContractionPropagator : public glslang::TIntermTraverser {
public:
TNoContractionPropagator(ObjectAccesschainSet* precise_objects,
const AccessChainMapping& accesschain_mapping)
: TIntermTraverser(true, false, false),
precise_objects_(*precise_objects), added_precise_object_ids_(),
remained_accesschain_(), accesschain_mapping_(accesschain_mapping) {}
// Propagates 'precise' in the right nodes of a given assignment node with
// access chain record from the assignee node to a 'precise' object it
// contains.
void
propagateNoContractionInOneExpression(glslang::TIntermTyped* defining_node,
const ObjectAccessChain& assignee_remained_accesschain)
{
remained_accesschain_ = assignee_remained_accesschain;
if (glslang::TIntermBinary* BN = defining_node->getAsBinaryNode()) {
assert(isAssignOperation(BN->getOp()));
BN->getRight()->traverse(this);
if (isArithmeticOperation(BN->getOp())) {
BN->getWritableType().getQualifier().noContraction = true;
}
} else if (glslang::TIntermUnary* UN = defining_node->getAsUnaryNode()) {
assert(isAssignOperation(UN->getOp()));
UN->getOperand()->traverse(this);
if (isArithmeticOperation(UN->getOp())) {
UN->getWritableType().getQualifier().noContraction = true;
}
}
}
// Propagates 'precise' in a given precise return node.
void propagateNoContractionInReturnNode(glslang::TIntermBranch* return_node)
{
remained_accesschain_ = "";
assert(return_node->getFlowOp() == glslang::EOpReturn && return_node->getExpression());
return_node->getExpression()->traverse(this);
}
protected:
TNoContractionPropagator& operator=(const TNoContractionPropagator&);
// Visits an aggregate node. The node can be a initializer list, in which
// case we need to find the 'precise' or 'precise' containing object node
// with the access chain record. In other cases, just need to traverse all
// the children nodes.
bool visitAggregate(glslang::TVisit, glslang::TIntermAggregate* node) override
{
if (!remained_accesschain_.empty() && node->getOp() == glslang::EOpConstructStruct) {
// This is a struct initializer node, and the remained
// access chain is not empty, we need to refer to the
// assignee_remained_access_chain_ to find the nested
// 'precise' object. And we don't need to visit other nodes in this
// aggregate node.
// Gets the struct dereference index that leads to 'precise' object.
ObjectAccessChain precise_accesschain_index_str =
getFrontElement(remained_accesschain_);
unsigned precise_accesschain_index = (unsigned)strtoul(precise_accesschain_index_str.c_str(), nullptr, 10);
// Gets the node pointed by the access chain index extracted before.
glslang::TIntermTyped* potential_precise_node =
node->getSequence()[precise_accesschain_index]->getAsTyped();
assert(potential_precise_node);
// Pop the front access chain index from the path, and visit the nested node.
{
ObjectAccessChain next_level_accesschain =
subAccessChainFromSecondElement(remained_accesschain_);
StateSettingGuard<ObjectAccessChain> setup_remained_accesschain_for_next_level(
&remained_accesschain_, next_level_accesschain);
potential_precise_node->traverse(this);
}
return false;
}
return true;
}
// Visits a binary node. A binary node can be an object node, e.g. a dereference node.
// As only the top object nodes in the right side of an assignment needs to be visited
// and added to 'precise' work list, this traverser won't visit the children nodes of
// an object node. If the binary node does not represent an object node, it should
// go on to traverse its children nodes and if it is an arithmetic operation node, this
// operation should be marked as 'noContraction'.
bool visitBinary(glslang::TVisit, glslang::TIntermBinary* node) override
{
if (isDereferenceOperation(node->getOp())) {
// This binary node is an object node. Need to update the precise
// object set with the access chain of this node + remained
// access chain .
ObjectAccessChain new_precise_accesschain = accesschain_mapping_.at(node);
if (remained_accesschain_.empty()) {
node->getWritableType().getQualifier().noContraction = true;
} else {
new_precise_accesschain += ObjectAccesschainDelimiter + remained_accesschain_;
}
// Cache the access chain as added precise object, so we won't add the
// same object to the work list again.
if (!added_precise_object_ids_.count(new_precise_accesschain)) {
precise_objects_.insert(new_precise_accesschain);
added_precise_object_ids_.insert(new_precise_accesschain);
}
// Only the upper-most object nodes should be visited, so do not
// visit children of this object node.
return false;
}
// If this is an arithmetic operation, marks this node as 'noContraction'.
if (isArithmeticOperation(node->getOp()) && node->getBasicType() != glslang::EbtInt) {
node->getWritableType().getQualifier().noContraction = true;
}
// As this node is not an object node, need to traverse the children nodes.
return true;
}
// Visits a unary node. A unary node can not be an object node. If the operation
// is an arithmetic operation, need to mark this node as 'noContraction'.
bool visitUnary(glslang::TVisit /* visit */, glslang::TIntermUnary* node) override
{
// If this is an arithmetic operation, marks this with 'noContraction'
if (isArithmeticOperation(node->getOp())) {
node->getWritableType().getQualifier().noContraction = true;
}
return true;
}
// Visits a symbol node. A symbol node is always an object node. So we
// should always be able to find its in our collected mapping from object
// nodes to access chains. As an object node, a symbol node can be either
// 'precise' or containing 'precise' objects according to unused
// access chain information we have when we visit this node.
void visitSymbol(glslang::TIntermSymbol* node) override
{
// Symbol nodes are object nodes and should always have an
// access chain collected before matches with it.
assert(accesschain_mapping_.count(node));
ObjectAccessChain new_precise_accesschain = accesschain_mapping_.at(node);
// If the unused access chain is empty, this symbol node should be
// marked as 'precise'. Otherwise, the unused access chain should be
// appended to the symbol ID to build a new access chain which points to
// the nested 'precise' object in this symbol object.
if (remained_accesschain_.empty()) {
node->getWritableType().getQualifier().noContraction = true;
} else {
new_precise_accesschain += ObjectAccesschainDelimiter + remained_accesschain_;
}
// Add the new 'precise' access chain to the work list and make sure we
// don't visit it again.
if (!added_precise_object_ids_.count(new_precise_accesschain)) {
precise_objects_.insert(new_precise_accesschain);
added_precise_object_ids_.insert(new_precise_accesschain);
}
}
// A set of precise objects, represented as access chains.
ObjectAccesschainSet& precise_objects_;
// Visited symbol nodes, should not revisit these nodes.
ObjectAccesschainSet added_precise_object_ids_;
// The left node of an assignment operation might be an parent of 'precise' objects.
// This means the left node might not be an 'precise' object node, but it may contains
// 'precise' qualifier which should be propagated to the corresponding child node in
// the right. So we need the path from the left node to its nested 'precise' node to
// tell us how to find the corresponding 'precise' node in the right.
ObjectAccessChain remained_accesschain_;
// A map from node pointers to their access chains.
const AccessChainMapping& accesschain_mapping_;
};
}
namespace glslang {
void PropagateNoContraction(const glslang::TIntermediate& intermediate)
{
// First, traverses the AST, records symbols with their defining operations
// and collects the initial set of precise symbols (symbol nodes that marked
// as 'noContraction') and precise return nodes.
auto mappings_and_precise_objects =
getSymbolToDefinitionMappingAndPreciseSymbolIDs(intermediate);
// The mapping of symbol node IDs to their defining nodes. This enables us
// to get the defining node directly from a given symbol ID without
// traversing the tree again.
NodeMapping& symbol_definition_mapping = std::get<0>(mappings_and_precise_objects);
// The mapping of object nodes to their access chains recorded.
AccessChainMapping& accesschain_mapping = std::get<1>(mappings_and_precise_objects);
// The initial set of 'precise' objects which are represented as the
// access chain toward them.
ObjectAccesschainSet& precise_object_accesschains = std::get<2>(mappings_and_precise_objects);
// The set of 'precise' return nodes.
ReturnBranchNodeSet& precise_return_nodes = std::get<3>(mappings_and_precise_objects);
// Second, uses the initial set of precise objects as a work list, pops an
// access chain, extract the symbol ID from it. Then:
// 1) Check the assignee object, see if it is 'precise' object node or
// contains 'precise' object. Obtain the incremental access chain from the
// assignee node to its nested 'precise' node (if any).
// 2) If the assignee object node is 'precise' or it contains 'precise'
// objects, traverses the right side of the assignment operation
// expression to mark arithmetic operations as 'noContration' and update
// 'precise' access chain work list with new found object nodes.
// Repeat above steps until the work list is empty.
TNoContractionAssigneeCheckingTraverser checker(accesschain_mapping);
TNoContractionPropagator propagator(&precise_object_accesschains, accesschain_mapping);
// We have two initial precise work lists to handle:
// 1) precise return nodes
// 2) precise object access chains
// We should process the precise return nodes first and the involved
// objects in the return expression should be added to the precise object
// access chain set.
while (!precise_return_nodes.empty()) {
glslang::TIntermBranch* precise_return_node = *precise_return_nodes.begin();
propagator.propagateNoContractionInReturnNode(precise_return_node);
precise_return_nodes.erase(precise_return_node);
}
while (!precise_object_accesschains.empty()) {
// Get the access chain of a precise object from the work list.
ObjectAccessChain precise_object_accesschain = *precise_object_accesschains.begin();
// Get the symbol id from the access chain.
ObjectAccessChain symbol_id = getFrontElement(precise_object_accesschain);
// Get all the defining nodes of that symbol ID.
std::pair<NodeMapping::iterator, NodeMapping::iterator> range =
symbol_definition_mapping.equal_range(symbol_id);
// Visits all the assignment nodes of that symbol ID and
// 1) Check if the assignee node is 'precise' or contains 'precise'
// objects.
// 2) Propagate the 'precise' to the top layer object nodes
// in the right side of the assignment operation, update the 'precise'
// work list with new access chains representing the new 'precise'
// objects, and mark arithmetic operations as 'noContraction'.
for (NodeMapping::iterator defining_node_iter = range.first;
defining_node_iter != range.second; defining_node_iter++) {
TIntermOperator* defining_node = defining_node_iter->second;
// Check the assignee node.
auto checker_result = checker.getPrecisenessAndRemainedAccessChain(
defining_node, precise_object_accesschain);
bool& contain_precise = std::get<0>(checker_result);
ObjectAccessChain& remained_accesschain = std::get<1>(checker_result);
// If the assignee node is 'precise' or contains 'precise', propagate the
// 'precise' to the right. Otherwise just skip this assignment node.
if (contain_precise) {
propagator.propagateNoContractionInOneExpression(defining_node,
remained_accesschain);
}
}
// Remove the last processed 'precise' object from the work list.
precise_object_accesschains.erase(precise_object_accesschain);
}
}
}
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/localintermediate.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2016 LunarG, Inc.
// Copyright (C) 2017 ARM Limited.
// Copyright (C) 2015-2018 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _LOCAL_INTERMEDIATE_INCLUDED_
#define _LOCAL_INTERMEDIATE_INCLUDED_
#include "../Include/intermediate.h"
#include "../Public/ShaderLang.h"
#include "Versions.h"
#include <algorithm>
#include <array>
#include <functional>
#include <set>
#include <string>
#include <vector>
class TInfoSink;
namespace glslang {
struct TMatrixSelector {
int coord1; // stay agnostic about column/row; this is parse order
int coord2;
};
typedef int TVectorSelector;
const int MaxSwizzleSelectors = 4;
template<typename selectorType>
class TSwizzleSelectors {
public:
TSwizzleSelectors() : size_(0) { }
void push_back(selectorType comp)
{
if (size_ < MaxSwizzleSelectors)
components[size_++] = comp;
}
void resize(int s)
{
assert(s <= size_);
size_ = s;
}
int size() const { return size_; }
selectorType operator[](int i) const
{
assert(i < MaxSwizzleSelectors);
return components[i];
}
private:
int size_;
selectorType components[MaxSwizzleSelectors];
};
//
// Some helper structures for TIntermediate. Their contents are encapsulated
// by TIntermediate.
//
// Used for call-graph algorithms for detecting recursion, missing bodies, and dead bodies.
// A "call" is a pair: <caller, callee>.
// There can be duplicates. General assumption is the list is small.
struct TCall {
TCall(const TString& pCaller, const TString& pCallee) : caller(pCaller), callee(pCallee) { }
TString caller;
TString callee;
bool visited;
bool currentPath;
bool errorGiven;
int calleeBodyPosition;
};
// A generic 1-D range.
struct TRange {
TRange(int start, int last) : start(start), last(last) { }
bool overlap(const TRange& rhs) const
{
return last >= rhs.start && start <= rhs.last;
}
int start;
int last;
};
// An IO range is a 3-D rectangle; the set of (location, component, index) triples all lying
// within the same location range, component range, and index value. Locations don't alias unless
// all other dimensions of their range overlap.
struct TIoRange {
TIoRange(TRange location, TRange component, TBasicType basicType, int index, bool centroid, bool smooth, bool flat)
: location(location), component(component), basicType(basicType), index(index), centroid(centroid), smooth(smooth), flat(flat)
{
}
bool overlap(const TIoRange& rhs) const
{
return location.overlap(rhs.location) && component.overlap(rhs.component) && index == rhs.index;
}
TRange location;
TRange component;
TBasicType basicType;
int index;
bool centroid;
bool smooth;
bool flat;
};
// An offset range is a 2-D rectangle; the set of (binding, offset) pairs all lying
// within the same binding and offset range.
struct TOffsetRange {
TOffsetRange(TRange binding, TRange offset)
: binding(binding), offset(offset) { }
bool overlap(const TOffsetRange& rhs) const
{
return binding.overlap(rhs.binding) && offset.overlap(rhs.offset);
}
TRange binding;
TRange offset;
};
// Things that need to be tracked per xfb buffer.
struct TXfbBuffer {
TXfbBuffer() : stride(TQualifier::layoutXfbStrideEnd), implicitStride(0), contains64BitType(false),
contains32BitType(false), contains16BitType(false) { }
std::vector<TRange> ranges; // byte offsets that have already been assigned
unsigned int stride;
unsigned int implicitStride;
bool contains64BitType;
bool contains32BitType;
bool contains16BitType;
};
// Track a set of strings describing how the module was processed.
// This includes command line options, transforms, etc., ideally inclusive enough
// to reproduce the steps used to transform the input source to the output.
// E.g., see SPIR-V OpModuleProcessed.
// Each "process" or "transform" uses is expressed in the form:
// process arg0 arg1 arg2 ...
// process arg0 arg1 arg2 ...
// where everything is textual, and there can be zero or more arguments
class TProcesses {
public:
TProcesses() {}
~TProcesses() {}
void addProcess(const char* process)
{
processes.push_back(process);
}
void addProcess(const std::string& process)
{
processes.push_back(process);
}
void addArgument(int arg)
{
processes.back().append(" ");
std::string argString = std::to_string(arg);
processes.back().append(argString);
}
void addArgument(const char* arg)
{
processes.back().append(" ");
processes.back().append(arg);
}
void addArgument(const std::string& arg)
{
processes.back().append(" ");
processes.back().append(arg);
}
void addIfNonZero(const char* process, int value)
{
if (value != 0) {
addProcess(process);
addArgument(value);
}
}
const std::vector<std::string>& getProcesses() const { return processes; }
private:
std::vector<std::string> processes;
};
class TSymbolTable;
class TSymbol;
class TVariable;
//
// Texture and Sampler transformation mode.
//
enum ComputeDerivativeMode {
LayoutDerivativeNone, // default layout as SPV_NV_compute_shader_derivatives not enabled
LayoutDerivativeGroupQuads, // derivative_group_quadsNV
LayoutDerivativeGroupLinear, // derivative_group_linearNV
};
//
// Status type on AST level. Some uncalled status or functions would be reset in call graph.
// Currently we will keep status set by explicitly declared layout or variable decl.
//
enum AstRefType {
AstRefTypeVar, // Status set by variable decl
AstRefTypeFunc, // Status set by function decl
AstRefTypeLayout, // Status set by layout decl
};
class TIdMaps {
public:
TMap<TString, long long>& operator[](long long i) { return maps[i]; }
const TMap<TString, long long>& operator[](long long i) const { return maps[i]; }
private:
TMap<TString, long long> maps[EsiCount];
};
class TNumericFeatures {
public:
TNumericFeatures() : features(0) { }
TNumericFeatures(const TNumericFeatures&) = delete;
TNumericFeatures& operator=(const TNumericFeatures&) = delete;
typedef enum : unsigned int {
shader_explicit_arithmetic_types = 1 << 0,
shader_explicit_arithmetic_types_int8 = 1 << 1,
shader_explicit_arithmetic_types_int16 = 1 << 2,
shader_explicit_arithmetic_types_int32 = 1 << 3,
shader_explicit_arithmetic_types_int64 = 1 << 4,
shader_explicit_arithmetic_types_float16 = 1 << 5,
shader_explicit_arithmetic_types_float32 = 1 << 6,
shader_explicit_arithmetic_types_float64 = 1 << 7,
shader_implicit_conversions = 1 << 8,
gpu_shader_fp64 = 1 << 9,
gpu_shader_int16 = 1 << 10,
gpu_shader_half_float = 1 << 11,
} feature;
void insert(feature f) { features |= f; }
void erase(feature f) { features &= ~f; }
bool contains(feature f) const { return (features & f) != 0; }
private:
unsigned int features;
};
// MustBeAssigned wraps a T, asserting that it has been assigned with
// operator =() before attempting to read with operator T() or operator ->().
// Used to catch cases where fields are read before they have been assigned.
template<typename T>
class MustBeAssigned
{
public:
MustBeAssigned() = default;
MustBeAssigned(const T& v) : value(v) {}
operator const T&() const { assert(isSet); return value; }
const T* operator ->() const { assert(isSet); return &value; }
MustBeAssigned& operator = (const T& v) { value = v; isSet = true; return *this; }
private:
T value;
bool isSet = false;
};
//
// Set of helper functions to help parse and build the tree.
//
class TIntermediate {
public:
explicit TIntermediate(EShLanguage l, int v = 0, EProfile p = ENoProfile) :
language(l),
profile(p), version(v),
treeRoot(nullptr),
resources(TBuiltInResource{}),
numEntryPoints(0), numErrors(0), numPushConstants(0), recursive(false),
invertY(false),
dxPositionW(false),
enhancedMsgs(false),
debugInfo(false),
useStorageBuffer(false),
invariantAll(false),
nanMinMaxClamp(false),
depthReplacing(false),
stencilReplacing(false),
uniqueId(0),
globalUniformBlockName(""),
atomicCounterBlockName(""),
globalUniformBlockSet(TQualifier::layoutSetEnd),
globalUniformBlockBinding(TQualifier::layoutBindingEnd),
atomicCounterBlockSet(TQualifier::layoutSetEnd),
implicitThisName("@this"), implicitCounterName("@count"),
source(EShSourceNone),
useVulkanMemoryModel(false),
invocations(TQualifier::layoutNotSet), vertices(TQualifier::layoutNotSet),
inputPrimitive(ElgNone), outputPrimitive(ElgNone),
pixelCenterInteger(false), originUpperLeft(false),texCoordBuiltinRedeclared(false),
vertexSpacing(EvsNone), vertexOrder(EvoNone), interlockOrdering(EioNone), pointMode(false), earlyFragmentTests(false),
postDepthCoverage(false), earlyAndLateFragmentTestsAMD(false),
nonCoherentColorAttachmentReadEXT(false),
nonCoherentDepthAttachmentReadEXT(false),
nonCoherentStencilAttachmentReadEXT(false),
depthLayout(EldNone),
stencilLayout(ElsNone),
hlslFunctionality1(false),
blendEquations(0), xfbMode(false), multiStream(false),
layoutOverrideCoverage(false),
geoPassthroughEXT(false),
numShaderRecordBlocks(0),
computeDerivativeMode(LayoutDerivativeNone),
primitives(TQualifier::layoutNotSet),
numTaskNVBlocks(0),
layoutPrimitiveCulling(false),
numTaskEXTPayloads(0),
autoMapBindings(false),
autoMapLocations(false),
flattenUniformArrays(false),
useUnknownFormat(false),
hlslOffsets(false),
hlslIoMapping(false),
useVariablePointers(false),
textureSamplerTransformMode(EShTexSampTransKeep),
needToLegalize(false),
binaryDoubleOutput(false),
subgroupUniformControlFlow(false),
maximallyReconverges(false),
usePhysicalStorageBuffer(false),
spirvRequirement(nullptr),
spirvExecutionMode(nullptr),
uniformLocationBase(0),
quadDerivMode(false), reqFullQuadsMode(false)
{
localSize[0] = 1;
localSize[1] = 1;
localSize[2] = 1;
localSizeNotDefault[0] = false;
localSizeNotDefault[1] = false;
localSizeNotDefault[2] = false;
localSizeSpecId[0] = TQualifier::layoutNotSet;
localSizeSpecId[1] = TQualifier::layoutNotSet;
localSizeSpecId[2] = TQualifier::layoutNotSet;
xfbBuffers.resize(TQualifier::layoutXfbBufferEnd);
shiftBinding.fill(0);
}
void setVersion(int v)
{
version = v;
}
void setProfile(EProfile p)
{
profile = p;
}
int getVersion() const { return version; }
EProfile getProfile() const { return profile; }
void setSpv(const SpvVersion& s)
{
spvVersion = s;
// client processes
if (spvVersion.vulkan > 0)
processes.addProcess("client vulkan100");
if (spvVersion.openGl > 0)
processes.addProcess("client opengl100");
// target SPV
switch (spvVersion.spv) {
case 0:
break;
case EShTargetSpv_1_0:
break;
case EShTargetSpv_1_1:
processes.addProcess("target-env spirv1.1");
break;
case EShTargetSpv_1_2:
processes.addProcess("target-env spirv1.2");
break;
case EShTargetSpv_1_3:
processes.addProcess("target-env spirv1.3");
break;
case EShTargetSpv_1_4:
processes.addProcess("target-env spirv1.4");
break;
case EShTargetSpv_1_5:
processes.addProcess("target-env spirv1.5");
break;
case EShTargetSpv_1_6:
processes.addProcess("target-env spirv1.6");
break;
default:
processes.addProcess("target-env spirvUnknown");
break;
}
// target-environment processes
switch (spvVersion.vulkan) {
case 0:
break;
case EShTargetVulkan_1_0:
processes.addProcess("target-env vulkan1.0");
break;
case EShTargetVulkan_1_1:
processes.addProcess("target-env vulkan1.1");
break;
case EShTargetVulkan_1_2:
processes.addProcess("target-env vulkan1.2");
break;
case EShTargetVulkan_1_3:
processes.addProcess("target-env vulkan1.3");
break;
default:
processes.addProcess("target-env vulkanUnknown");
break;
}
if (spvVersion.openGl > 0)
processes.addProcess("target-env opengl");
}
const SpvVersion& getSpv() const { return spvVersion; }
EShLanguage getStage() const { return language; }
void addRequestedExtension(const char* extension) { requestedExtensions.insert(extension); }
const std::set<std::string>& getRequestedExtensions() const { return requestedExtensions; }
bool isRayTracingStage() const {
return language >= EShLangRayGen && language <= EShLangCallableNV;
}
void setTreeRoot(TIntermNode* r) { treeRoot = r; }
TIntermNode* getTreeRoot() const { return treeRoot; }
void incrementEntryPointCount() { ++numEntryPoints; }
int getNumEntryPoints() const { return numEntryPoints; }
int getNumErrors() const { return numErrors; }
void addPushConstantCount() { ++numPushConstants; }
void setLimits(const TBuiltInResource& r) { resources = r; }
const TBuiltInResource& getLimits() const { return resources; }
bool postProcess(TIntermNode*, EShLanguage);
void removeTree();
void setEntryPointName(const char* ep)
{
entryPointName = ep;
processes.addProcess("entry-point");
processes.addArgument(entryPointName);
}
void setEntryPointMangledName(const char* ep) { entryPointMangledName = ep; }
const std::string& getEntryPointName() const { return entryPointName; }
const std::string& getEntryPointMangledName() const { return entryPointMangledName; }
void setDebugInfo(bool debuginfo)
{
debugInfo = debuginfo;
}
bool getDebugInfo() const { return debugInfo; }
void setInvertY(bool invert)
{
invertY = invert;
if (invertY)
processes.addProcess("invert-y");
}
bool getInvertY() const { return invertY; }
void setDxPositionW(bool dxPosW)
{
dxPositionW = dxPosW;
if (dxPositionW)
processes.addProcess("dx-position-w");
}
bool getDxPositionW() const { return dxPositionW; }
void setEnhancedMsgs()
{
enhancedMsgs = true;
}
bool getEnhancedMsgs() const { return enhancedMsgs && getSource() == EShSourceGlsl; }
#ifdef ENABLE_HLSL
void setSource(EShSource s) { source = s; }
EShSource getSource() const { return source; }
#else
void setSource(EShSource s) { assert(s == EShSourceGlsl); (void)s; }
EShSource getSource() const { return EShSourceGlsl; }
#endif
bool isRecursive() const { return recursive; }
TIntermSymbol* addSymbol(const TVariable&);
TIntermSymbol* addSymbol(const TVariable&, const TSourceLoc&);
TIntermSymbol* addSymbol(const TType&, const TSourceLoc&);
TIntermSymbol* addSymbol(const TIntermSymbol&);
TIntermTyped* addConversion(TOperator, const TType&, TIntermTyped*);
std::tuple<TIntermTyped*, TIntermTyped*> addPairConversion(TOperator op, TIntermTyped* node0, TIntermTyped* node1);
TIntermTyped* addUniShapeConversion(TOperator, const TType&, TIntermTyped*);
TIntermTyped* addConversion(TBasicType convertTo, TIntermTyped* node) const;
void addBiShapeConversion(TOperator, TIntermTyped*& lhsNode, TIntermTyped*& rhsNode);
TIntermTyped* addShapeConversion(const TType&, TIntermTyped*);
TIntermTyped* addBinaryMath(TOperator, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, const TSourceLoc&);
TIntermTyped* addUnaryMath(TOperator, TIntermTyped* child, const TSourceLoc&);
TIntermTyped* addBuiltInFunctionCall(const TSourceLoc& line, TOperator, bool unary, TIntermNode*, const TType& returnType);
bool canImplicitlyPromote(TBasicType from, TBasicType to, TOperator op = EOpNull) const;
bool isIntegralPromotion(TBasicType from, TBasicType to) const;
bool isFPPromotion(TBasicType from, TBasicType to) const;
bool isIntegralConversion(TBasicType from, TBasicType to) const;
bool isFPConversion(TBasicType from, TBasicType to) const;
bool isFPIntegralConversion(TBasicType from, TBasicType to) const;
TOperator mapTypeToConstructorOp(const TType&) const;
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc&);
TIntermAggregate* mergeAggregate(TIntermNode* left, TIntermNode* right);
TIntermAggregate* mergeAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc&);
TIntermAggregate* makeAggregate(TIntermNode* node);
TIntermAggregate* makeAggregate(TIntermNode* node, const TSourceLoc&);
TIntermAggregate* makeAggregate(const TSourceLoc&);
TIntermTyped* setAggregateOperator(TIntermNode*, TOperator, const TType& type, const TSourceLoc&);
bool areAllChildConst(TIntermAggregate* aggrNode);
TIntermSelection* addSelection(TIntermTyped* cond, TIntermNodePair code, const TSourceLoc&);
TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, const TSourceLoc&);
TIntermTyped* addComma(TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermTyped* addMethod(TIntermTyped*, const TType&, const TString*, const TSourceLoc&);
TIntermConstantUnion* addConstantUnion(const TConstUnionArray&, const TType&, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(signed char, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(unsigned char, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(signed short, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(unsigned short, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(int, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(unsigned int, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(long long, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(unsigned long long, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(bool, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(double, TBasicType, const TSourceLoc&, bool literal = false) const;
TIntermConstantUnion* addConstantUnion(const TString*, const TSourceLoc&, bool literal = false) const;
TIntermTyped* promoteConstantUnion(TBasicType, TIntermConstantUnion*) const;
bool parseConstTree(TIntermNode*, TConstUnionArray, TOperator, const TType&, bool singleConstantParam = false);
TIntermLoop* addLoop(TIntermNode*, TIntermTyped*, TIntermTyped*, bool testFirst, const TSourceLoc&);
TIntermAggregate* addForLoop(TIntermNode*, TIntermNode*, TIntermTyped*, TIntermTyped*, bool testFirst,
const TSourceLoc&, TIntermLoop*&);
TIntermBranch* addBranch(TOperator, const TSourceLoc&);
TIntermBranch* addBranch(TOperator, TIntermTyped*, const TSourceLoc&);
template<typename selectorType> TIntermTyped* addSwizzle(TSwizzleSelectors<selectorType>&, const TSourceLoc&);
// Low level functions to add nodes (no conversions or other higher level transformations)
// If a type is provided, the node's type will be set to it.
TIntermBinary* addBinaryNode(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&) const;
TIntermBinary* addBinaryNode(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&,
const TType&) const;
TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, const TSourceLoc&) const;
TIntermUnary* addUnaryNode(TOperator op, TIntermTyped* child, const TSourceLoc&, const TType&) const;
// Constant folding (in Constant.cpp)
TIntermTyped* fold(TIntermAggregate* aggrNode);
TIntermTyped* foldConstructor(TIntermAggregate* aggrNode);
TIntermTyped* foldDereference(TIntermTyped* node, int index, const TSourceLoc&);
TIntermTyped* foldSwizzle(TIntermTyped* node, TSwizzleSelectors<TVectorSelector>& fields, const TSourceLoc&);
// Tree ops
static const TIntermTyped* traverseLValueBase(const TIntermTyped*, bool swizzleOkay, bool bufferReferenceOk = false,
std::function<bool(const TIntermNode&)> proc = {});
// Linkage related
void addSymbolLinkageNodes(TIntermAggregate*& linkage, EShLanguage, TSymbolTable&);
void addSymbolLinkageNode(TIntermAggregate*& linkage, const TSymbol&);
TIntermAggregate* findLinkerObjects() const;
void setGlobalUniformBlockName(const char* name) { globalUniformBlockName = std::string(name); }
const char* getGlobalUniformBlockName() const { return globalUniformBlockName.c_str(); }
void setGlobalUniformSet(unsigned int set) { globalUniformBlockSet = set; }
unsigned int getGlobalUniformSet() const { return globalUniformBlockSet; }
void setGlobalUniformBinding(unsigned int binding) { globalUniformBlockBinding = binding; }
unsigned int getGlobalUniformBinding() const { return globalUniformBlockBinding; }
void setAtomicCounterBlockName(const char* name) { atomicCounterBlockName = std::string(name); }
const char* getAtomicCounterBlockName() const { return atomicCounterBlockName.c_str(); }
void setAtomicCounterBlockSet(unsigned int set) { atomicCounterBlockSet = set; }
unsigned int getAtomicCounterBlockSet() const { return atomicCounterBlockSet; }
void setUseStorageBuffer() { useStorageBuffer = true; }
bool usingStorageBuffer() const { return useStorageBuffer; }
void setInvariantAll() { invariantAll = true; }
bool isInvariantAll() const { return invariantAll; }
void setDepthReplacing() { depthReplacing = true; }
bool isDepthReplacing() const { return depthReplacing; }
void setStencilReplacing() { stencilReplacing = true; }
bool isStencilReplacing() const { return stencilReplacing; }
bool setLocalSize(int dim, int size)
{
if (localSizeNotDefault[dim])
return size == localSize[dim];
localSizeNotDefault[dim] = true;
localSize[dim] = size;
return true;
}
unsigned int getLocalSize(int dim) const { return localSize[dim]; }
bool isLocalSizeSet() const
{
// Return true if any component has been set (i.e. any component is not default).
return localSizeNotDefault[0] || localSizeNotDefault[1] || localSizeNotDefault[2];
}
bool setLocalSizeSpecId(int dim, int id)
{
if (localSizeSpecId[dim] != TQualifier::layoutNotSet)
return id == localSizeSpecId[dim];
localSizeSpecId[dim] = id;
return true;
}
int getLocalSizeSpecId(int dim) const { return localSizeSpecId[dim]; }
bool isLocalSizeSpecialized() const
{
// Return true if any component has been specialized.
return localSizeSpecId[0] != TQualifier::layoutNotSet ||
localSizeSpecId[1] != TQualifier::layoutNotSet ||
localSizeSpecId[2] != TQualifier::layoutNotSet;
}
void output(TInfoSink&, bool tree);
bool isEsProfile() const { return profile == EEsProfile; }
void setShiftBinding(TResourceType res, unsigned int shift)
{
shiftBinding[res] = shift;
const char* name = getResourceName(res);
if (name != nullptr)
processes.addIfNonZero(name, shift);
}
unsigned int getShiftBinding(TResourceType res) const { return shiftBinding[res]; }
void setShiftBindingForSet(TResourceType res, unsigned int shift, unsigned int set)
{
if (shift == 0) // ignore if there's no shift: it's a no-op.
return;
shiftBindingForSet[res][set] = shift;
const char* name = getResourceName(res);
if (name != nullptr) {
processes.addProcess(name);
processes.addArgument(shift);
processes.addArgument(set);
}
}
int getShiftBindingForSet(TResourceType res, unsigned int set) const
{
const auto shift = shiftBindingForSet[res].find(set);
return shift == shiftBindingForSet[res].end() ? -1 : shift->second;
}
bool hasShiftBindingForSet(TResourceType res) const { return !shiftBindingForSet[res].empty(); }
void setResourceSetBinding(const std::vector<std::string>& shift)
{
resourceSetBinding = shift;
if (shift.size() > 0) {
processes.addProcess("resource-set-binding");
for (int s = 0; s < (int)shift.size(); ++s)
processes.addArgument(shift[s]);
}
}
const std::vector<std::string>& getResourceSetBinding() const { return resourceSetBinding; }
void setAutoMapBindings(bool map)
{
autoMapBindings = map;
if (autoMapBindings)
processes.addProcess("auto-map-bindings");
}
bool getAutoMapBindings() const { return autoMapBindings; }
void setAutoMapLocations(bool map)
{
autoMapLocations = map;
if (autoMapLocations)
processes.addProcess("auto-map-locations");
}
bool getAutoMapLocations() const { return autoMapLocations; }
#ifdef ENABLE_HLSL
void setFlattenUniformArrays(bool flatten)
{
flattenUniformArrays = flatten;
if (flattenUniformArrays)
processes.addProcess("flatten-uniform-arrays");
}
bool getFlattenUniformArrays() const { return flattenUniformArrays; }
#endif
void setNoStorageFormat(bool b)
{
useUnknownFormat = b;
if (useUnknownFormat)
processes.addProcess("no-storage-format");
}
bool getNoStorageFormat() const { return useUnknownFormat; }
void setUseVulkanMemoryModel()
{
useVulkanMemoryModel = true;
processes.addProcess("use-vulkan-memory-model");
}
bool usingVulkanMemoryModel() const { return useVulkanMemoryModel; }
void setUsePhysicalStorageBuffer()
{
usePhysicalStorageBuffer = true;
}
bool usingPhysicalStorageBuffer() const { return usePhysicalStorageBuffer; }
void setReplicatedComposites()
{
useReplicatedComposites = true;
}
bool usingReplicatedComposites() const { return useReplicatedComposites; }
void setUseVariablePointers()
{
useVariablePointers = true;
processes.addProcess("use-variable-pointers");
}
// Set the global flag for bindless texture
void setBindlessTextureMode(const TString& currentCaller, AstRefType type)
{
// When type is not func, currentCaller should be "" (empty string)
bindlessTextureModeCaller[currentCaller] = type;
}
// Get the global flag for bindless texture
bool getBindlessTextureMode() const
{
return (bindlessTextureModeCaller.size() > 0);
}
// Set the global flag for bindless image
void setBindlessImageMode(const TString& currentCaller, AstRefType type)
{
// When type is not func, currentCaller should be "" (empty string)
bindlessImageModeCaller[currentCaller] = type;
}
// Get the global flag for bindless image
bool getBindlessImageMode() const
{
return (bindlessImageModeCaller.size() > 0);
}
// Get the global flag for bindless texture
bool resetTopLevelUncalledStatus(const TString& deadCaller)
{
// For reflection collection purpose, currently uniform layout setting and some
// flags introduced by variables (IO, global, etc,.) won't be reset here.
// Remove each global status (AST top level) introduced by uncalled functions.
// If a status is set by several functions, keep those which in call graph.
bool result = false;
// For two types of bindless mode flag, we would only reset which is set by an uncalled function.
// If one status flag's key in caller vec is empty, it should be come from a non-function setting.
if (!bindlessTextureModeCaller.empty()) {
auto caller = bindlessTextureModeCaller.find(deadCaller);
if (caller != bindlessTextureModeCaller.end() && bindlessTextureModeCaller[deadCaller] == AstRefTypeFunc) {
bindlessTextureModeCaller.erase(caller);
result = true;
}
}
if (!bindlessImageModeCaller.empty()) {
auto caller = bindlessImageModeCaller.find(deadCaller);
if (caller != bindlessImageModeCaller.end() && bindlessImageModeCaller[deadCaller] == AstRefTypeFunc) {
bindlessImageModeCaller.erase(caller);
result = true;
}
}
return result;
}
bool getBindlessMode() const
{
return getBindlessTextureMode() || getBindlessImageMode();
}
bool usingVariablePointers() const { return useVariablePointers; }
#ifdef ENABLE_HLSL
template<class T> T addCounterBufferName(const T& name) const { return name + implicitCounterName; }
bool hasCounterBufferName(const TString& name) const {
size_t len = strlen(implicitCounterName);
return name.size() > len &&
name.compare(name.size() - len, len, implicitCounterName) == 0;
}
#endif
void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode) { textureSamplerTransformMode = mode; }
int getNumPushConstants() const { return numPushConstants; }
void addShaderRecordCount() { ++numShaderRecordBlocks; }
void addTaskNVCount() { ++numTaskNVBlocks; }
void addTaskPayloadEXTCount() { ++numTaskEXTPayloads; }
bool setInvocations(int i)
{
if (invocations != TQualifier::layoutNotSet)
return invocations == i;
invocations = i;
return true;
}
int getInvocations() const { return invocations; }
bool setVertices(int m)
{
if (vertices != TQualifier::layoutNotSet)
return vertices == m;
vertices = m;
return true;
}
int getVertices() const { return vertices; }
bool setInputPrimitive(TLayoutGeometry p)
{
if (inputPrimitive != ElgNone)
return inputPrimitive == p;
inputPrimitive = p;
return true;
}
TLayoutGeometry getInputPrimitive() const { return inputPrimitive; }
bool setVertexSpacing(TVertexSpacing s)
{
if (vertexSpacing != EvsNone)
return vertexSpacing == s;
vertexSpacing = s;
return true;
}
TVertexSpacing getVertexSpacing() const { return vertexSpacing; }
bool setVertexOrder(TVertexOrder o)
{
if (vertexOrder != EvoNone)
return vertexOrder == o;
vertexOrder = o;
return true;
}
TVertexOrder getVertexOrder() const { return vertexOrder; }
void setPointMode() { pointMode = true; }
bool getPointMode() const { return pointMode; }
bool setInterlockOrdering(TInterlockOrdering o)
{
if (interlockOrdering != EioNone)
return interlockOrdering == o;
interlockOrdering = o;
return true;
}
TInterlockOrdering getInterlockOrdering() const { return interlockOrdering; }
void setXfbMode() { xfbMode = true; }
bool getXfbMode() const { return xfbMode; }
void setQuadDerivMode(bool mode = true) { quadDerivMode = mode; }
bool getQuadDerivMode() const { return quadDerivMode; }
void setReqFullQuadsMode(bool mode = true) { reqFullQuadsMode = mode; }
bool getReqFullQuadsMode() const { return reqFullQuadsMode; }
void setMultiStream() { multiStream = true; }
bool isMultiStream() const { return multiStream; }
bool setOutputPrimitive(TLayoutGeometry p)
{
if (outputPrimitive != ElgNone)
return outputPrimitive == p;
outputPrimitive = p;
return true;
}
TLayoutGeometry getOutputPrimitive() const { return outputPrimitive; }
void setNonCoherentColorAttachmentReadEXT() { nonCoherentColorAttachmentReadEXT = true; }
bool getNonCoherentColorAttachmentReadEXT() const { return nonCoherentColorAttachmentReadEXT; }
void setNonCoherentDepthAttachmentReadEXT() { nonCoherentDepthAttachmentReadEXT = true; }
bool getNonCoherentDepthAttachmentReadEXT() const { return nonCoherentDepthAttachmentReadEXT; }
void setNonCoherentStencilAttachmentReadEXT() { nonCoherentStencilAttachmentReadEXT = true; }
bool getNonCoherentStencilAttachmentReadEXT() const { return nonCoherentStencilAttachmentReadEXT; }
void setPostDepthCoverage() { postDepthCoverage = true; }
bool getPostDepthCoverage() const { return postDepthCoverage; }
void setEarlyFragmentTests() { earlyFragmentTests = true; }
void setEarlyAndLateFragmentTestsAMD() { earlyAndLateFragmentTestsAMD = true; }
bool getEarlyFragmentTests() const { return earlyFragmentTests; }
bool getEarlyAndLateFragmentTestsAMD() const { return earlyAndLateFragmentTestsAMD; }
bool setDepth(TLayoutDepth d)
{
if (depthLayout != EldNone)
return depthLayout == d;
depthLayout = d;
return true;
}
bool setStencil(TLayoutStencil s)
{
if (stencilLayout != ElsNone)
return stencilLayout == s;
stencilLayout = s;
return true;
}
TLayoutDepth getDepth() const { return depthLayout; }
TLayoutStencil getStencil() const { return stencilLayout; }
void setOriginUpperLeft() { originUpperLeft = true; }
bool getOriginUpperLeft() const { return originUpperLeft; }
void setPixelCenterInteger() { pixelCenterInteger = true; }
bool getPixelCenterInteger() const { return pixelCenterInteger; }
void setTexCoordRedeclared() { texCoordBuiltinRedeclared = true; }
bool getTexCoordRedeclared() const { return texCoordBuiltinRedeclared; }
void addBlendEquation(TBlendEquationShift b) { blendEquations |= (1 << b); }
unsigned int getBlendEquations() const { return blendEquations; }
bool setXfbBufferStride(int buffer, unsigned stride)
{
if (xfbBuffers[buffer].stride != TQualifier::layoutXfbStrideEnd)
return xfbBuffers[buffer].stride == stride;
xfbBuffers[buffer].stride = stride;
return true;
}
unsigned getXfbStride(int buffer) const { return xfbBuffers[buffer].stride; }
int addXfbBufferOffset(const TType&);
unsigned int computeTypeXfbSize(const TType&, bool& contains64BitType, bool& contains32BitType, bool& contains16BitType) const;
unsigned int computeTypeXfbSize(const TType&, bool& contains64BitType) const;
void setLayoutOverrideCoverage() { layoutOverrideCoverage = true; }
bool getLayoutOverrideCoverage() const { return layoutOverrideCoverage; }
void setGeoPassthroughEXT() { geoPassthroughEXT = true; }
bool getGeoPassthroughEXT() const { return geoPassthroughEXT; }
void setLayoutDerivativeMode(ComputeDerivativeMode mode) { computeDerivativeMode = mode; }
bool hasLayoutDerivativeModeNone() const { return computeDerivativeMode != LayoutDerivativeNone; }
ComputeDerivativeMode getLayoutDerivativeModeNone() const { return computeDerivativeMode; }
void setLayoutPrimitiveCulling() { layoutPrimitiveCulling = true; }
bool getLayoutPrimitiveCulling() const { return layoutPrimitiveCulling; }
bool setPrimitives(int m)
{
if (primitives != TQualifier::layoutNotSet)
return primitives == m;
primitives = m;
return true;
}
int getPrimitives() const { return primitives; }
const char* addSemanticName(const TString& name)
{
return semanticNameSet.insert(name).first->c_str();
}
void addUniformLocationOverride(const char* nameStr, int location)
{
std::string name = nameStr;
uniformLocationOverrides[name] = location;
}
int getUniformLocationOverride(const char* nameStr) const
{
std::string name = nameStr;
auto pos = uniformLocationOverrides.find(name);
if (pos == uniformLocationOverrides.end())
return -1;
else
return pos->second;
}
void setUniformLocationBase(int base) { uniformLocationBase = base; }
int getUniformLocationBase() const { return uniformLocationBase; }
void setNeedsLegalization() { needToLegalize = true; }
bool needsLegalization() const { return needToLegalize; }
void setBinaryDoubleOutput() { binaryDoubleOutput = true; }
bool getBinaryDoubleOutput() { return binaryDoubleOutput; }
void setSubgroupUniformControlFlow() { subgroupUniformControlFlow = true; }
bool getSubgroupUniformControlFlow() const { return subgroupUniformControlFlow; }
void setMaximallyReconverges() { maximallyReconverges = true; }
bool getMaximallyReconverges() const { return maximallyReconverges; }
// GL_EXT_spirv_intrinsics
void insertSpirvRequirement(const TSpirvRequirement* spirvReq);
bool hasSpirvRequirement() const { return spirvRequirement != nullptr; }
const TSpirvRequirement& getSpirvRequirement() const { return *spirvRequirement; }
void insertSpirvExecutionMode(int executionMode, const TIntermAggregate* args = nullptr);
void insertSpirvExecutionModeId(int executionMode, const TIntermAggregate* args);
bool hasSpirvExecutionMode() const { return spirvExecutionMode != nullptr; }
const TSpirvExecutionMode& getSpirvExecutionMode() const { return *spirvExecutionMode; }
void addBlockStorageOverride(const char* nameStr, TBlockStorageClass backing)
{
std::string name(nameStr);
blockBackingOverrides[name] = backing;
}
TBlockStorageClass getBlockStorageOverride(const char* nameStr) const
{
std::string name = nameStr;
auto pos = blockBackingOverrides.find(name);
if (pos == blockBackingOverrides.end())
return EbsNone;
else
return pos->second;
}
#ifdef ENABLE_HLSL
void setHlslFunctionality1() { hlslFunctionality1 = true; }
bool getHlslFunctionality1() const { return hlslFunctionality1; }
void setHlslOffsets()
{
hlslOffsets = true;
if (hlslOffsets)
processes.addProcess("hlsl-offsets");
}
bool usingHlslOffsets() const { return hlslOffsets; }
void setHlslIoMapping(bool b)
{
hlslIoMapping = b;
if (hlslIoMapping)
processes.addProcess("hlsl-iomap");
}
bool usingHlslIoMapping() { return hlslIoMapping; }
#else
bool getHlslFunctionality1() const { return false; }
bool usingHlslOffsets() const { return false; }
bool usingHlslIoMapping() { return false; }
#endif
bool usingScalarBlockLayout() const {
for (auto extIt = requestedExtensions.begin(); extIt != requestedExtensions.end(); ++extIt) {
if (*extIt == E_GL_EXT_scalar_block_layout)
return true;
}
return false;
}
bool IsRequestedExtension(const char* extension) const
{
return (requestedExtensions.find(extension) != requestedExtensions.end());
}
void addToCallGraph(TInfoSink&, const TString& caller, const TString& callee);
void merge(TInfoSink&, TIntermediate&);
void finalCheck(TInfoSink&, bool keepUncalled);
void mergeGlobalUniformBlocks(TInfoSink& infoSink, TIntermediate& unit, bool mergeExistingOnly);
void mergeUniformObjects(TInfoSink& infoSink, TIntermediate& unit);
void checkStageIO(TInfoSink&, TIntermediate&);
bool buildConvertOp(TBasicType dst, TBasicType src, TOperator& convertOp) const;
TIntermTyped* createConversion(TBasicType convertTo, TIntermTyped* node) const;
void addIoAccessed(const TString& name) { ioAccessed.insert(name); }
bool inIoAccessed(const TString& name) const { return ioAccessed.find(name) != ioAccessed.end(); }
int addUsedLocation(const TQualifier&, const TType&, bool& typeCollision);
int checkLocationRange(int set, const TIoRange& range, const TType&, bool& typeCollision);
int checkLocationRT(int set, int location);
int addUsedOffsets(int binding, int offset, int numOffsets);
bool addUsedConstantId(int id);
static int computeTypeLocationSize(const TType&, EShLanguage);
static int computeTypeUniformLocationSize(const TType&);
static int getBaseAlignmentScalar(const TType&, int& size);
static int getBaseAlignment(const TType&, int& size, int& stride, TLayoutPacking layoutPacking, bool rowMajor);
static int getScalarAlignment(const TType&, int& size, int& stride, bool rowMajor);
static int getMemberAlignment(const TType&, int& size, int& stride, TLayoutPacking layoutPacking, bool rowMajor);
static bool improperStraddle(const TType& type, int size, int offset, bool vectorLike);
static void updateOffset(const TType& parentType, const TType& memberType, int& offset, int& memberSize);
static int getOffset(const TType& type, int index);
static int getBlockSize(const TType& blockType);
static int computeBufferReferenceTypeSize(const TType&);
static bool isIoResizeArray(const TType& type, EShLanguage language);
bool promote(TIntermOperator*);
void setNanMinMaxClamp(bool setting) { nanMinMaxClamp = setting; }
bool getNanMinMaxClamp() const { return nanMinMaxClamp; }
void setSourceFile(const char* file) { if (file != nullptr) sourceFile = file; }
const std::string& getSourceFile() const { return sourceFile; }
void addSourceText(const char* text, size_t len) { sourceText.append(text, len); }
const std::string& getSourceText() const { return sourceText; }
const std::map<std::string, std::string>& getIncludeText() const { return includeText; }
void addIncludeText(const char* name, const char* text, size_t len) { includeText[name].assign(text,len); }
void addProcesses(const std::vector<std::string>& p)
{
for (int i = 0; i < (int)p.size(); ++i)
processes.addProcess(p[i]);
}
void addProcess(const std::string& process) { processes.addProcess(process); }
void addProcessArgument(const std::string& arg) { processes.addArgument(arg); }
const std::vector<std::string>& getProcesses() const { return processes.getProcesses(); }
unsigned long long getUniqueId() const { return uniqueId; }
void setUniqueId(unsigned long long id) { uniqueId = id; }
// Certain explicit conversions are allowed conditionally
bool getArithemeticInt8Enabled() const {
return numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_int8);
}
bool getArithemeticInt16Enabled() const {
return numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types) ||
numericFeatures.contains(TNumericFeatures::gpu_shader_int16) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_int16);
}
bool getArithemeticFloat16Enabled() const {
return numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types) ||
numericFeatures.contains(TNumericFeatures::gpu_shader_half_float) ||
numericFeatures.contains(TNumericFeatures::shader_explicit_arithmetic_types_float16);
}
void updateNumericFeature(TNumericFeatures::feature f, bool on)
{ on ? numericFeatures.insert(f) : numericFeatures.erase(f); }
protected:
TIntermSymbol* addSymbol(long long Id, const TString&, const TType&, const TConstUnionArray&, TIntermTyped* subtree, const TSourceLoc&);
void error(TInfoSink& infoSink, const char*, EShLanguage unitStage = EShLangCount);
void warn(TInfoSink& infoSink, const char*, EShLanguage unitStage = EShLangCount);
void mergeCallGraphs(TInfoSink&, TIntermediate&);
void mergeModes(TInfoSink&, TIntermediate&);
void mergeTrees(TInfoSink&, TIntermediate&);
void seedIdMap(TIdMaps& idMaps, long long& IdShift);
void remapIds(const TIdMaps& idMaps, long long idShift, TIntermediate&);
void mergeBodies(TInfoSink&, TIntermSequence& globals, const TIntermSequence& unitGlobals);
void mergeLinkerObjects(TInfoSink&, TIntermSequence& linkerObjects, const TIntermSequence& unitLinkerObjects, EShLanguage);
void mergeBlockDefinitions(TInfoSink&, TIntermSymbol* block, TIntermSymbol* unitBlock, TIntermediate* unitRoot);
void mergeImplicitArraySizes(TType&, const TType&);
void mergeErrorCheck(TInfoSink&, const TIntermSymbol&, const TIntermSymbol&, EShLanguage);
void checkCallGraphCycles(TInfoSink&);
void checkCallGraphBodies(TInfoSink&, bool keepUncalled);
void inOutLocationCheck(TInfoSink&);
void sharedBlockCheck(TInfoSink&);
bool userOutputUsed() const;
bool isSpecializationOperation(const TIntermOperator&) const;
bool isNonuniformPropagating(TOperator) const;
bool promoteUnary(TIntermUnary&);
bool promoteBinary(TIntermBinary&);
void addSymbolLinkageNode(TIntermAggregate*& linkage, TSymbolTable&, const TString&);
bool promoteAggregate(TIntermAggregate&);
void pushSelector(TIntermSequence&, const TVectorSelector&, const TSourceLoc&);
void pushSelector(TIntermSequence&, const TMatrixSelector&, const TSourceLoc&);
bool specConstantPropagates(const TIntermTyped&, const TIntermTyped&);
void performTextureUpgradeAndSamplerRemovalTransformation(TIntermNode* root);
bool isConversionAllowed(TOperator op, TIntermTyped* node) const;
std::tuple<TBasicType, TBasicType> getConversionDestinationType(TBasicType type0, TBasicType type1, TOperator op) const;
static const char* getResourceName(TResourceType);
const EShLanguage language; // stage, known at construction time
std::string entryPointName;
std::string entryPointMangledName;
typedef std::list<TCall> TGraph;
TGraph callGraph;
EProfile profile; // source profile
int version; // source version
SpvVersion spvVersion;
TIntermNode* treeRoot;
std::set<std::string> requestedExtensions; // cumulation of all enabled or required extensions; not connected to what subset of the shader used them
MustBeAssigned<TBuiltInResource> resources;
int numEntryPoints;
int numErrors;
int numPushConstants;
bool recursive;
bool invertY;
bool dxPositionW;
bool enhancedMsgs;
bool debugInfo;
bool useStorageBuffer;
bool invariantAll;
bool nanMinMaxClamp; // true if desiring min/max/clamp to favor non-NaN over NaN
bool depthReplacing;
bool stencilReplacing;
int localSize[3];
bool localSizeNotDefault[3];
int localSizeSpecId[3];
unsigned long long uniqueId;
std::string globalUniformBlockName;
std::string atomicCounterBlockName;
unsigned int globalUniformBlockSet;
unsigned int globalUniformBlockBinding;
unsigned int atomicCounterBlockSet;
public:
const char* const implicitThisName;
const char* const implicitCounterName;
protected:
EShSource source; // source language, known a bit later
bool useVulkanMemoryModel;
int invocations;
int vertices;
TLayoutGeometry inputPrimitive;
TLayoutGeometry outputPrimitive;
bool pixelCenterInteger;
bool originUpperLeft;
bool texCoordBuiltinRedeclared;
TVertexSpacing vertexSpacing;
TVertexOrder vertexOrder;
TInterlockOrdering interlockOrdering;
bool pointMode;
bool earlyFragmentTests;
bool postDepthCoverage;
bool earlyAndLateFragmentTestsAMD;
bool nonCoherentColorAttachmentReadEXT;
bool nonCoherentDepthAttachmentReadEXT;
bool nonCoherentStencilAttachmentReadEXT;
TLayoutDepth depthLayout;
TLayoutStencil stencilLayout;
bool hlslFunctionality1;
int blendEquations; // an 'or'ing of masks of shifts of TBlendEquationShift
bool xfbMode;
std::vector<TXfbBuffer> xfbBuffers; // all the data we need to track per xfb buffer
bool multiStream;
bool layoutOverrideCoverage;
bool geoPassthroughEXT;
int numShaderRecordBlocks;
ComputeDerivativeMode computeDerivativeMode;
int primitives;
int numTaskNVBlocks;
bool layoutPrimitiveCulling;
int numTaskEXTPayloads;
// Base shift values
std::array<unsigned int, EResCount> shiftBinding;
// Per-descriptor-set shift values
std::array<std::map<int, int>, EResCount> shiftBindingForSet;
std::vector<std::string> resourceSetBinding;
bool autoMapBindings;
bool autoMapLocations;
bool flattenUniformArrays;
bool useUnknownFormat;
bool hlslOffsets;
bool hlslIoMapping;
bool useVariablePointers;
std::set<TString> semanticNameSet;
EShTextureSamplerTransformMode textureSamplerTransformMode;
bool needToLegalize;
bool binaryDoubleOutput;
bool subgroupUniformControlFlow;
bool maximallyReconverges;
bool usePhysicalStorageBuffer;
bool useReplicatedComposites { false };
TSpirvRequirement* spirvRequirement;
TSpirvExecutionMode* spirvExecutionMode;
std::map<TString, AstRefType> bindlessTextureModeCaller;
std::map<TString, AstRefType> bindlessImageModeCaller;
std::unordered_map<std::string, int> uniformLocationOverrides;
int uniformLocationBase;
bool quadDerivMode;
bool reqFullQuadsMode;
TNumericFeatures numericFeatures;
std::unordered_map<std::string, TBlockStorageClass> blockBackingOverrides;
std::unordered_set<int> usedConstantId; // specialization constant ids used
std::vector<TOffsetRange> usedAtomics; // sets of bindings used by atomic counters
std::vector<TIoRange> usedIo[5]; // sets of used locations, one for each of in, out, uniform, and buffers
std::vector<TRange> usedIoRT[4]; // sets of used location, one for rayPayload/rayPayloadIN,
// one for callableData/callableDataIn, one for hitObjectAttributeNV and
// one for shaderrecordhitobjectNV
// set of names of statically read/written I/O that might need extra checking
std::set<TString> ioAccessed;
// source code of shader, useful as part of debug information
std::string sourceFile;
std::string sourceText;
// Included text. First string is a name, second is the included text
std::map<std::string, std::string> includeText;
// for OpModuleProcessed, or equivalent
TProcesses processes;
private:
void operator=(TIntermediate&); // prevent assignments
};
} // end namespace glslang
#endif // _LOCAL_INTERMEDIATE_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/PoolAlloc.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "../Include/Common.h"
#include "../Include/PoolAlloc.h"
namespace glslang {
namespace {
thread_local TPoolAllocator* threadPoolAllocator = nullptr;
TPoolAllocator* GetDefaultThreadPoolAllocator()
{
thread_local TPoolAllocator defaultAllocator;
return &defaultAllocator;
}
} // anonymous namespace
// Return the thread-specific current pool.
TPoolAllocator& GetThreadPoolAllocator()
{
return *(threadPoolAllocator ? threadPoolAllocator : GetDefaultThreadPoolAllocator());
}
// Set the thread-specific current pool.
void SetThreadPoolAllocator(TPoolAllocator* poolAllocator)
{
threadPoolAllocator = poolAllocator;
}
//
// Implement the functionality of the TPoolAllocator class, which
// is documented in PoolAlloc.h.
//
TPoolAllocator::TPoolAllocator(int growthIncrement, int allocationAlignment) :
pageSize(growthIncrement),
alignment(allocationAlignment),
freeList(nullptr),
inUseList(nullptr),
numCalls(0)
{
//
// Don't allow page sizes we know are smaller than all common
// OS page sizes.
//
if (pageSize < 4*1024)
pageSize = 4*1024;
//
// A large currentPageOffset indicates a new page needs to
// be obtained to allocate memory.
//
currentPageOffset = pageSize;
//
// Adjust alignment to be at least pointer aligned and
// power of 2.
//
size_t minAlign = sizeof(void*);
alignment &= ~(minAlign - 1);
if (alignment < minAlign)
alignment = minAlign;
size_t a = 1;
while (a < alignment)
a <<= 1;
alignment = a;
alignmentMask = a - 1;
//
// Align header skip
//
headerSkip = minAlign;
if (headerSkip < sizeof(tHeader)) {
headerSkip = (sizeof(tHeader) + alignmentMask) & ~alignmentMask;
}
push();
}
TPoolAllocator::~TPoolAllocator()
{
while (inUseList) {
tHeader* next = inUseList->nextPage;
inUseList->~tHeader();
delete [] reinterpret_cast<char*>(inUseList);
inUseList = next;
}
//
// Always delete the free list memory - it can't be being
// (correctly) referenced, whether the pool allocator was
// global or not. We should not check the guard blocks
// here, because we did it already when the block was
// placed into the free list.
//
while (freeList) {
tHeader* next = freeList->nextPage;
delete [] reinterpret_cast<char*>(freeList);
freeList = next;
}
}
//
// Check a single guard block for damage
//
#ifdef GUARD_BLOCKS
void TAllocation::checkGuardBlock(unsigned char* blockMem, unsigned char val, const char* locText) const
#else
void TAllocation::checkGuardBlock(unsigned char*, unsigned char, const char*) const
#endif
{
#ifdef GUARD_BLOCKS
for (size_t x = 0; x < guardBlockSize; x++) {
if (blockMem[x] != val) {
const int maxSize = 80;
char assertMsg[maxSize];
// We don't print the assert message. It's here just to be helpful.
snprintf(assertMsg, maxSize, "PoolAlloc: Damage %s %zu byte allocation at 0x%p\n",
locText, size, data());
assert(0 && "PoolAlloc: Damage in guard block");
}
}
#else
assert(guardBlockSize == 0);
#endif
}
void TPoolAllocator::push()
{
tAllocState state = { currentPageOffset, inUseList };
stack.push_back(state);
//
// Indicate there is no current page to allocate from.
//
currentPageOffset = pageSize;
}
//
// Do a mass-deallocation of all the individual allocations
// that have occurred since the last push(), or since the
// last pop(), or since the object's creation.
//
// The deallocated pages are saved for future allocations.
//
void TPoolAllocator::pop()
{
if (stack.size() < 1)
return;
tHeader* page = stack.back().page;
currentPageOffset = stack.back().offset;
while (inUseList != page) {
tHeader* nextInUse = inUseList->nextPage;
size_t pageCount = inUseList->pageCount;
// This technically ends the lifetime of the header as C++ object,
// but we will still control the memory and reuse it.
inUseList->~tHeader(); // currently, just a debug allocation checker
if (pageCount > 1) {
delete [] reinterpret_cast<char*>(inUseList);
} else {
inUseList->nextPage = freeList;
freeList = inUseList;
}
inUseList = nextInUse;
}
stack.pop_back();
}
//
// Do a mass-deallocation of all the individual allocations
// that have occurred.
//
void TPoolAllocator::popAll()
{
while (stack.size() > 0)
pop();
}
void* TPoolAllocator::allocate(size_t numBytes)
{
// If we are using guard blocks, all allocations are bracketed by
// them: [guardblock][allocation][guardblock]. numBytes is how
// much memory the caller asked for. allocationSize is the total
// size including guard blocks. In release build,
// guardBlockSize=0 and this all gets optimized away.
size_t allocationSize = TAllocation::allocationSize(numBytes);
//
// Just keep some interesting statistics.
//
++numCalls;
totalBytes += numBytes;
//
// Do the allocation, most likely case first, for efficiency.
// This step could be moved to be inline sometime.
//
if (currentPageOffset + allocationSize <= pageSize) {
//
// Safe to allocate from currentPageOffset.
//
unsigned char* memory = reinterpret_cast<unsigned char*>(inUseList) + currentPageOffset;
currentPageOffset += allocationSize;
currentPageOffset = (currentPageOffset + alignmentMask) & ~alignmentMask;
return initializeAllocation(inUseList, memory, numBytes);
}
if (allocationSize + headerSkip > pageSize) {
//
// Do a multi-page allocation. Don't mix these with the others.
// The OS is efficient and allocating and free-ing multiple pages.
//
size_t numBytesToAlloc = allocationSize + headerSkip;
tHeader* memory = reinterpret_cast<tHeader*>(::new char[numBytesToAlloc]);
if (memory == nullptr)
return nullptr;
// Use placement-new to initialize header
new(memory) tHeader(inUseList, (numBytesToAlloc + pageSize - 1) / pageSize);
inUseList = memory;
currentPageOffset = pageSize; // make next allocation come from a new page
// No guard blocks for multi-page allocations (yet)
return reinterpret_cast<void*>(reinterpret_cast<UINT_PTR>(memory) + headerSkip);
}
//
// Need a simple page to allocate from.
//
tHeader* memory;
if (freeList) {
memory = freeList;
freeList = freeList->nextPage;
} else {
memory = reinterpret_cast<tHeader*>(::new char[pageSize]);
if (memory == nullptr)
return nullptr;
}
// Use placement-new to initialize header
new(memory) tHeader(inUseList, 1);
inUseList = memory;
unsigned char* ret = reinterpret_cast<unsigned char*>(inUseList) + headerSkip;
currentPageOffset = (headerSkip + allocationSize + alignmentMask) & ~alignmentMask;
return initializeAllocation(inUseList, ret, numBytes);
}
//
// Check all allocations in a list for damage by calling check on each.
//
void TAllocation::checkAllocList() const
{
for (const TAllocation* alloc = this; alloc != nullptr; alloc = alloc->prevAlloc)
alloc->check();
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/limits.cpp | //
// Copyright (C) 2013 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Do sub tree walks for
// 1) inductive loop bodies to see if the inductive variable is modified
// 2) array-index expressions to see if they are "constant-index-expression"
//
// These are per Appendix A of ES 2.0:
//
// "Within the body of the loop, the loop index is not statically assigned to nor is it used as the
// argument to a function out or inout parameter."
//
// "The following are constant-index-expressions:
// - Constant expressions
// - Loop indices as defined in section 4
// - Expressions composed of both of the above"
//
// N.B.: assuming the last rule excludes function calls
//
#include "ParseHelper.h"
namespace glslang {
//
// The inductive loop-body traverser.
//
// Just look at things that might modify the loop index.
//
class TInductiveTraverser : public TIntermTraverser {
public:
TInductiveTraverser(long long id, TSymbolTable& st)
: loopId(id), symbolTable(st), bad(false) { }
virtual bool visitBinary(TVisit, TIntermBinary* node);
virtual bool visitUnary(TVisit, TIntermUnary* node);
virtual bool visitAggregate(TVisit, TIntermAggregate* node);
long long loopId; // unique ID of the symbol that's the loop inductive variable
TSymbolTable& symbolTable;
bool bad;
TSourceLoc badLoc;
protected:
TInductiveTraverser(TInductiveTraverser&);
TInductiveTraverser& operator=(TInductiveTraverser&);
};
// check binary operations for those modifying the loop index
bool TInductiveTraverser::visitBinary(TVisit /* visit */, TIntermBinary* node)
{
if (node->modifiesState() && node->getLeft()->getAsSymbolNode() &&
node->getLeft()->getAsSymbolNode()->getId() == loopId) {
bad = true;
badLoc = node->getLoc();
}
return true;
}
// check unary operations for those modifying the loop index
bool TInductiveTraverser::visitUnary(TVisit /* visit */, TIntermUnary* node)
{
if (node->modifiesState() && node->getOperand()->getAsSymbolNode() &&
node->getOperand()->getAsSymbolNode()->getId() == loopId) {
bad = true;
badLoc = node->getLoc();
}
return true;
}
// check function calls for arguments modifying the loop index
bool TInductiveTraverser::visitAggregate(TVisit /* visit */, TIntermAggregate* node)
{
if (node->getOp() == EOpFunctionCall) {
// see if an out or inout argument is the loop index
const TIntermSequence& args = node->getSequence();
for (int i = 0; i < (int)args.size(); ++i) {
if (args[i]->getAsSymbolNode() && args[i]->getAsSymbolNode()->getId() == loopId) {
TSymbol* function = symbolTable.find(node->getName());
const TType* type = (*function->getAsFunction())[i].type;
if (type->getQualifier().storage == EvqOut ||
type->getQualifier().storage == EvqInOut) {
bad = true;
badLoc = node->getLoc();
}
}
}
}
return true;
}
//
// External function to call for loop check.
//
void TParseContext::inductiveLoopBodyCheck(TIntermNode* body, long long loopId, TSymbolTable& symbolTable)
{
TInductiveTraverser it(loopId, symbolTable);
if (body == nullptr)
return;
body->traverse(&it);
if (it.bad)
error(it.badLoc, "inductive loop index modified", "limitations", "");
}
//
// The "constant-index-expression" tranverser.
//
// Just look at things that can form an index.
//
class TIndexTraverser : public TIntermTraverser {
public:
TIndexTraverser(const TIdSetType& ids) : inductiveLoopIds(ids), bad(false) { }
virtual void visitSymbol(TIntermSymbol* symbol);
virtual bool visitAggregate(TVisit, TIntermAggregate* node);
const TIdSetType& inductiveLoopIds;
bool bad;
TSourceLoc badLoc;
protected:
TIndexTraverser(TIndexTraverser&);
TIndexTraverser& operator=(TIndexTraverser&);
};
// make sure symbols are inductive-loop indexes
void TIndexTraverser::visitSymbol(TIntermSymbol* symbol)
{
if (inductiveLoopIds.find(symbol->getId()) == inductiveLoopIds.end()) {
bad = true;
badLoc = symbol->getLoc();
}
}
// check for function calls, assuming they are bad; spec. doesn't really say
bool TIndexTraverser::visitAggregate(TVisit /* visit */, TIntermAggregate* node)
{
if (node->getOp() == EOpFunctionCall) {
bad = true;
badLoc = node->getLoc();
}
return true;
}
//
// External function to call for loop check.
//
void TParseContext::constantIndexExpressionCheck(TIntermNode* index)
{
TIndexTraverser it(inductiveLoopIds);
index->traverse(&it);
if (it.bad)
error(it.badLoc, "Non-constant-index-expression", "limitations", "");
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/Scan.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _GLSLANG_SCAN_INCLUDED_
#define _GLSLANG_SCAN_INCLUDED_
#include "Versions.h"
namespace glslang {
// Use a global end-of-input character, so no translation is needed across
// layers of encapsulation. Characters are all 8 bit, and positive, so there is
// no aliasing of character 255 onto -1, for example.
const int EndOfInput = -1;
//
// A character scanner that seamlessly, on read-only strings, reads across an
// array of strings without assuming null termination.
//
class TInputScanner {
public:
TInputScanner(int n, const char* const s[], size_t L[], const char* const* names = nullptr,
int b = 0, int f = 0, bool single = false) :
numSources(n),
// up to this point, common usage is "char*", but now we need positive 8-bit characters
sources(reinterpret_cast<const unsigned char* const *>(s)),
lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f), singleLogical(single),
endOfFileReached(false)
{
loc = new TSourceLoc[numSources];
for (int i = 0; i < numSources; ++i) {
loc[i].init(i - stringBias);
}
if (names != nullptr) {
for (int i = 0; i < numSources; ++i)
loc[i].name = names[i] != nullptr ? NewPoolTString(names[i]) : nullptr;
}
loc[currentSource].line = 1;
logicalSourceLoc.init(1);
logicalSourceLoc.name = loc[0].name;
}
virtual ~TInputScanner()
{
delete [] loc;
}
// retrieve the next character and advance one character
int get()
{
int ret = peek();
if (ret == EndOfInput)
return ret;
++loc[currentSource].column;
++logicalSourceLoc.column;
if (ret == '\n') {
++loc[currentSource].line;
++logicalSourceLoc.line;
logicalSourceLoc.column = 0;
loc[currentSource].column = 0;
}
advance();
return ret;
}
// retrieve the next character, no advance
int peek()
{
if (currentSource >= numSources) {
endOfFileReached = true;
return EndOfInput;
}
// Make sure we do not read off the end of a string.
// N.B. Sources can have a length of 0.
int sourceToRead = currentSource;
size_t charToRead = currentChar;
while(charToRead >= lengths[sourceToRead]) {
charToRead = 0;
sourceToRead += 1;
if (sourceToRead >= numSources) {
return EndOfInput;
}
}
// Here, we care about making negative valued characters positive
return sources[sourceToRead][charToRead];
}
// go back one character
void unget()
{
// Do not roll back once we've reached the end of the file.
if (endOfFileReached)
return;
if (currentChar > 0) {
--currentChar;
--loc[currentSource].column;
--logicalSourceLoc.column;
if (loc[currentSource].column < 0) {
// We've moved back past a new line. Find the
// previous newline (or start of the file) to compute
// the column count on the now current line.
size_t chIndex = currentChar;
while (chIndex > 0) {
if (sources[currentSource][chIndex] == '\n') {
break;
}
--chIndex;
}
logicalSourceLoc.column = (int)(currentChar - chIndex);
loc[currentSource].column = (int)(currentChar - chIndex);
}
} else {
do {
--currentSource;
} while (currentSource > 0 && lengths[currentSource] == 0);
if (lengths[currentSource] == 0) {
// set to 0 if we've backed up to the start of an empty string
currentChar = 0;
} else
currentChar = lengths[currentSource] - 1;
}
if (peek() == '\n') {
--loc[currentSource].line;
--logicalSourceLoc.line;
}
}
// for #line override
void setLine(int newLine)
{
logicalSourceLoc.line = newLine;
loc[getLastValidSourceIndex()].line = newLine;
}
// for #line override in filename based parsing
void setFile(const char* filename)
{
TString* fn_tstr = NewPoolTString(filename);
logicalSourceLoc.name = fn_tstr;
loc[getLastValidSourceIndex()].name = fn_tstr;
}
void setFile(const char* filename, int i)
{
TString* fn_tstr = NewPoolTString(filename);
if (i == getLastValidSourceIndex()) {
logicalSourceLoc.name = fn_tstr;
}
loc[i].name = fn_tstr;
}
void setString(int newString)
{
logicalSourceLoc.string = newString;
loc[getLastValidSourceIndex()].string = newString;
logicalSourceLoc.name = nullptr;
loc[getLastValidSourceIndex()].name = nullptr;
}
// for #include content indentation
void setColumn(int col)
{
logicalSourceLoc.column = col;
loc[getLastValidSourceIndex()].column = col;
}
void setEndOfInput()
{
endOfFileReached = true;
currentSource = numSources;
}
bool atEndOfInput() const { return endOfFileReached; }
const TSourceLoc& getSourceLoc() const
{
if (singleLogical) {
return logicalSourceLoc;
} else {
return loc[std::max(0, std::min(currentSource, numSources - finale - 1))];
}
}
// Returns the index (starting from 0) of the most recent valid source string we are reading from.
int getLastValidSourceIndex() const { return std::min(currentSource, numSources - 1); }
void consumeWhiteSpace(bool& foundNonSpaceTab);
bool consumeComment();
void consumeWhitespaceComment(bool& foundNonSpaceTab);
bool scanVersion(int& version, EProfile& profile, bool& notFirstToken);
protected:
// advance one character
void advance()
{
++currentChar;
if (currentChar >= lengths[currentSource]) {
++currentSource;
if (currentSource < numSources) {
loc[currentSource].string = loc[currentSource - 1].string + 1;
loc[currentSource].line = 1;
loc[currentSource].column = 0;
}
while (currentSource < numSources && lengths[currentSource] == 0) {
++currentSource;
if (currentSource < numSources) {
loc[currentSource].string = loc[currentSource - 1].string + 1;
loc[currentSource].line = 1;
loc[currentSource].column = 0;
}
}
currentChar = 0;
}
}
int numSources; // number of strings in source
const unsigned char* const *sources; // array of strings; must be converted to positive values on use, to avoid aliasing with -1 as EndOfInput
const size_t *lengths; // length of each string
int currentSource;
size_t currentChar;
// This is for reporting what string/line an error occurred on, and can be overridden by #line.
// It remembers the last state of each source string as it is left for the next one, so unget()
// can restore that state.
TSourceLoc* loc; // an array
int stringBias; // the first string that is the user's string number 0
int finale; // number of internal strings after user's last string
TSourceLoc logicalSourceLoc;
bool singleLogical; // treats the strings as a single logical string.
// locations will be reported from the first string.
// Set to true once peek() returns EndOfFile, so that we won't roll back
// once we've reached EndOfFile.
bool endOfFileReached;
};
} // end namespace glslang
#endif // _GLSLANG_SCAN_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/MachineIndependent/iomapper.h | //
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _IOMAPPER_INCLUDED
#define _IOMAPPER_INCLUDED
#include <cstdint>
#include "LiveTraverser.h"
#include <unordered_map>
#include <unordered_set>
//
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
//
class TInfoSink;
namespace glslang {
class TIntermediate;
struct TVarEntryInfo {
long long id;
TIntermSymbol* symbol;
bool live;
bool upgradedToPushConstant;
int newBinding;
int newSet;
int newLocation;
int newComponent;
int newIndex;
EShLanguage stage;
void clearNewAssignments() {
upgradedToPushConstant = false;
newBinding = -1;
newSet = -1;
newLocation = -1;
newComponent = -1;
newIndex = -1;
}
struct TOrderById {
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) { return l.id < r.id; }
};
struct TOrderByPriority {
// ordering:
// 1) has both binding and set
// 2) has binding but no set
// 3) has no binding but set
// 4) has no binding and no set
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
const TQualifier& lq = l.symbol->getQualifier();
const TQualifier& rq = r.symbol->getQualifier();
// simple rules:
// has binding gives 2 points
// has set gives 1 point
// who has the most points is more important.
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
if (lPoints == rPoints)
return l.id < r.id;
return lPoints > rPoints;
}
};
struct TOrderByPriorityAndLive {
// ordering:
// 1) do live variables first
// 2) has both binding and set
// 3) has binding but no set
// 4) has no binding but set
// 5) has no binding and no set
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
const TQualifier& lq = l.symbol->getQualifier();
const TQualifier& rq = r.symbol->getQualifier();
// simple rules:
// has binding gives 2 points
// has set gives 1 point
// who has the most points is more important.
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
if (l.live != r.live)
return l.live > r.live;
if (lPoints != rPoints)
return lPoints > rPoints;
return l.id < r.id;
}
};
};
// Base class for shared TIoMapResolver services, used by several derivations.
struct TDefaultIoResolverBase : public glslang::TIoMapResolver {
public:
TDefaultIoResolverBase(const TIntermediate& intermediate);
typedef std::vector<int> TSlotSet;
typedef std::unordered_map<int, TSlotSet> TSlotSetMap;
// grow the reflection stage by stage
void notifyBinding(EShLanguage, TVarEntryInfo& /*ent*/) override {}
void notifyInOut(EShLanguage, TVarEntryInfo& /*ent*/) override {}
void beginNotifications(EShLanguage) override {}
void endNotifications(EShLanguage) override {}
void beginResolve(EShLanguage) override {}
void endResolve(EShLanguage) override {}
void beginCollect(EShLanguage) override {}
void endCollect(EShLanguage) override {}
void reserverResourceSlot(TVarEntryInfo& /*ent*/, TInfoSink& /*infoSink*/) override {}
void reserverStorageSlot(TVarEntryInfo& /*ent*/, TInfoSink& /*infoSink*/) override {}
int getBaseBinding(EShLanguage stage, TResourceType res, unsigned int set) const;
const std::vector<std::string>& getResourceSetBinding(EShLanguage stage) const;
virtual TResourceType getResourceType(const glslang::TType& type) = 0;
bool doAutoBindingMapping() const;
bool doAutoLocationMapping() const;
TSlotSet::iterator findSlot(int set, int slot);
bool checkEmpty(int set, int slot);
bool validateInOut(EShLanguage /*stage*/, TVarEntryInfo& /*ent*/) override { return true; }
int reserveSlot(int set, int slot, int size = 1);
int getFreeSlot(int set, int base, int size = 1);
int resolveSet(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
int resolveUniformLocation(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) override;
int resolveInOutComponent(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
int resolveInOutIndex(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
void addStage(EShLanguage stage, TIntermediate& stageIntermediate) override {
if (stage < EShLangCount) {
stageMask[stage] = true;
stageIntermediates[stage] = &stageIntermediate;
}
}
uint32_t computeTypeLocationSize(const TType& type, EShLanguage stage);
TSlotSetMap slots;
bool hasError = false;
protected:
TDefaultIoResolverBase(TDefaultIoResolverBase&);
TDefaultIoResolverBase& operator=(TDefaultIoResolverBase&);
const TIntermediate& referenceIntermediate;
int nextUniformLocation;
int nextInputLocation;
int nextOutputLocation;
bool stageMask[EShLangCount + 1];
const TIntermediate* stageIntermediates[EShLangCount];
// Return descriptor set specific base if there is one, and the generic base otherwise.
int selectBaseBinding(int base, int descriptorSetBase) const {
return descriptorSetBase != -1 ? descriptorSetBase : base;
}
static int getLayoutSet(const glslang::TType& type) {
if (type.getQualifier().hasSet())
return type.getQualifier().layoutSet;
else
return 0;
}
static bool isSamplerType(const glslang::TType& type) {
return type.getBasicType() == glslang::EbtSampler && type.getSampler().isPureSampler();
}
static bool isTextureType(const glslang::TType& type) {
return (type.getBasicType() == glslang::EbtSampler &&
(type.getSampler().isTexture() || type.getSampler().isSubpass()));
}
static bool isUboType(const glslang::TType& type) {
return type.getQualifier().storage == EvqUniform;
}
static bool isImageType(const glslang::TType& type) {
return type.getBasicType() == glslang::EbtSampler && type.getSampler().isImage();
}
static bool isSsboType(const glslang::TType& type) {
return type.getQualifier().storage == EvqBuffer;
}
// Return true if this is a SRV (shader resource view) type:
static bool isSrvType(const glslang::TType& type) {
return isTextureType(type) || type.getQualifier().storage == EvqBuffer;
}
// Return true if this is a UAV (unordered access view) type:
static bool isUavType(const glslang::TType& type) {
if (type.getQualifier().isReadOnly())
return false;
return (type.getBasicType() == glslang::EbtSampler && type.getSampler().isImage()) ||
(type.getQualifier().storage == EvqBuffer);
}
};
// Default I/O resolver for OpenGL
struct TDefaultGlslIoResolver : public TDefaultIoResolverBase {
public:
typedef std::map<TString, int> TVarSlotMap; // <resourceName, location/binding>
typedef std::map<int, TVarSlotMap> TSlotMap; // <resourceKey, TVarSlotMap>
TDefaultGlslIoResolver(const TIntermediate& intermediate);
bool validateBinding(EShLanguage /*stage*/, TVarEntryInfo& /*ent*/) override { return true; }
TResourceType getResourceType(const glslang::TType& type) override;
int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) override;
int resolveUniformLocation(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
int resolveBinding(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
void beginResolve(EShLanguage /*stage*/) override;
void endResolve(EShLanguage stage) override;
void beginCollect(EShLanguage) override;
void endCollect(EShLanguage) override;
void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) override;
void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) override;
// in/out symbol and uniform symbol are stored in the same resourceSlotMap, the storage key is used to identify each type of symbol.
// We use stage and storage qualifier to construct a storage key. it can help us identify the same storage resource used in different stage.
// if a resource is a program resource and we don't need know it usage stage, we can use same stage to build storage key.
// Note: both stage and type must less then 0xffff.
int buildStorageKey(EShLanguage stage, TStorageQualifier type) {
assert(static_cast<uint32_t>(stage) <= 0x0000ffff && static_cast<uint32_t>(type) <= 0x0000ffff);
return (stage << 16) | type;
}
protected:
// Use for mark pre stage, to get more interface symbol information.
EShLanguage preStage;
// Use for mark current shader stage for resolver
EShLanguage currentStage;
// Slot map for storage resource(location of uniform and interface symbol) It's a program share slot
TSlotMap resourceSlotMap;
// Slot map for other resource(image, ubo, ssbo), It's a program share slot.
TSlotMap storageSlotMap;
};
typedef std::map<TString, TVarEntryInfo> TVarLiveMap;
// override function "operator=", if a vector<const _Kty, _Ty> being sort,
// when use vc++, the sort function will call :
// pair& operator=(const pair<_Other1, _Other2>& _Right)
// {
// first = _Right.first;
// second = _Right.second;
// return (*this);
// }
// that will make a const type handing on left.
// override this function can avoid a compiler error.
// In the future, if the vc++ compiler can handle such a situation,
// this part of the code will be removed.
struct TVarLivePair : std::pair<const TString, TVarEntryInfo> {
TVarLivePair(const std::pair<const TString, TVarEntryInfo>& _Right) : pair(_Right.first, _Right.second) {}
TVarLivePair& operator=(const TVarLivePair& _Right) {
const_cast<TString&>(first) = _Right.first;
second = _Right.second;
return (*this);
}
TVarLivePair(const TVarLivePair& src) : pair(src) { }
};
typedef std::vector<TVarLivePair> TVarLiveVector;
// I/O mapper
class TIoMapper {
public:
TIoMapper() {}
virtual ~TIoMapper() {}
// grow the reflection stage by stage
bool virtual addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*);
bool virtual doMap(TIoMapResolver*, TInfoSink&) { return true; }
};
// I/O mapper for GLSL
class TGlslIoMapper : public TIoMapper {
public:
TGlslIoMapper() {
memset(inVarMaps, 0, sizeof(TVarLiveMap*) * (EShLangCount + 1));
memset(outVarMaps, 0, sizeof(TVarLiveMap*) * (EShLangCount + 1));
memset(uniformVarMap, 0, sizeof(TVarLiveMap*) * (EShLangCount + 1));
memset(intermediates, 0, sizeof(TIntermediate*) * (EShLangCount + 1));
profile = ENoProfile;
version = 0;
autoPushConstantMaxSize = 128;
autoPushConstantBlockPacking = ElpStd430;
}
virtual ~TGlslIoMapper() {
for (size_t stage = 0; stage < EShLangCount; stage++) {
if (inVarMaps[stage] != nullptr) {
delete inVarMaps[stage];
inVarMaps[stage] = nullptr;
}
if (outVarMaps[stage] != nullptr) {
delete outVarMaps[stage];
outVarMaps[stage] = nullptr;
}
if (uniformVarMap[stage] != nullptr) {
delete uniformVarMap[stage];
uniformVarMap[stage] = nullptr;
}
if (intermediates[stage] != nullptr)
intermediates[stage] = nullptr;
}
}
// If set, the uniform block with the given name will be changed to be backed by
// push_constant if it's size is <= maxSize
void setAutoPushConstantBlock(const char* name, unsigned int maxSize, TLayoutPacking packing) {
autoPushConstantBlockName = name;
autoPushConstantMaxSize = maxSize;
autoPushConstantBlockPacking = packing;
}
// grow the reflection stage by stage
bool addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*) override;
bool doMap(TIoMapResolver*, TInfoSink&) override;
TVarLiveMap *inVarMaps[EShLangCount], *outVarMaps[EShLangCount],
*uniformVarMap[EShLangCount];
TIntermediate* intermediates[EShLangCount];
bool hadError = false;
EProfile profile;
int version;
private:
TString autoPushConstantBlockName;
unsigned int autoPushConstantMaxSize;
TLayoutPacking autoPushConstantBlockPacking;
};
} // end namespace glslang
#endif // _IOMAPPER_INCLUDED
|
0 | repos/glslang.zig/glslang/glslang/MachineIndependent | repos/glslang.zig/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
// Copyright (C) 2017 ARM Limited.
// Copyright (C) 2015-2018 Google, Inc.
// Copyright (c) 2023, Mobica Limited
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cstdlib>
#include <cstring>
#include "PpContext.h"
#include "PpTokens.h"
#include "../Scan.h"
namespace glslang {
///////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// Floating point constants: /////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
//
// Scan a single- or double-precision floating point constant.
// Assumes that the scanner has seen at least one digit,
// followed by either a decimal '.' or the letter 'e', or a
// precision ending (e.g., F or LF).
//
// This is technically not correct, as the preprocessor should just
// accept the numeric literal along with whatever suffix it has, but
// currently, it stops on seeing a bad suffix, treating that as the
// next token. This effects things like token pasting, where it is
// relevant how many tokens something was broken into.
//
// See peekContinuedPasting().
int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
{
const auto saveName = [&](int ch) {
if (len <= MaxTokenLength)
ppToken->name[len++] = static_cast<char>(ch);
};
// find the range of non-zero digits before the decimal point
int startNonZero = 0;
while (startNonZero < len && ppToken->name[startNonZero] == '0')
++startNonZero;
int endNonZero = len;
while (endNonZero > startNonZero && ppToken->name[endNonZero-1] == '0')
--endNonZero;
int numWholeNumberDigits = endNonZero - startNonZero;
// accumulate the range's value
bool fastPath = numWholeNumberDigits <= 15; // when the number gets too complex, set to false
unsigned long long wholeNumber = 0;
if (fastPath) {
for (int i = startNonZero; i < endNonZero; ++i)
wholeNumber = wholeNumber * 10 + (ppToken->name[i] - '0');
}
int decimalShift = len - endNonZero;
// Decimal point:
bool hasDecimalOrExponent = false;
if (ch == '.') {
hasDecimalOrExponent = true;
saveName(ch);
ch = getChar();
int firstDecimal = len;
#ifdef ENABLE_HLSL
// 1.#INF or -1.#INF
if (ch == '#' && (ifdepth > 0 || parseContext.intermediate.getSource() == EShSourceHlsl)) {
if ((len < 2) ||
(len == 2 && ppToken->name[0] != '1') ||
(len == 3 && ppToken->name[1] != '1' && !(ppToken->name[0] == '-' || ppToken->name[0] == '+')) ||
(len > 3))
parseContext.ppError(ppToken->loc, "unexpected use of", "#", "");
else {
// we have 1.# or -1.# or +1.#, check for 'INF'
if ((ch = getChar()) != 'I' ||
(ch = getChar()) != 'N' ||
(ch = getChar()) != 'F')
parseContext.ppError(ppToken->loc, "expected 'INF'", "#", "");
else {
// we have [+-].#INF, and we are targeting IEEE 754, so wrap it up:
saveName('I');
saveName('N');
saveName('F');
ppToken->name[len] = '\0';
if (ppToken->name[0] == '-')
ppToken->i64val = 0xfff0000000000000; // -Infinity
else
ppToken->i64val = 0x7ff0000000000000; // +Infinity
return PpAtomConstFloat;
}
}
}
#endif
// Consume leading-zero digits after the decimal point
while (ch == '0') {
saveName(ch);
ch = getChar();
}
int startNonZeroDecimal = len;
int endNonZeroDecimal = len;
// Consume remaining digits, up to the exponent
while (ch >= '0' && ch <= '9') {
saveName(ch);
if (ch != '0')
endNonZeroDecimal = len;
ch = getChar();
}
// Compute accumulation up to the last non-zero digit
if (endNonZeroDecimal > startNonZeroDecimal) {
numWholeNumberDigits += endNonZeroDecimal - endNonZero - 1; // don't include the "."
if (numWholeNumberDigits > 15)
fastPath = false;
if (fastPath) {
for (int i = endNonZero; i < endNonZeroDecimal; ++i) {
if (ppToken->name[i] != '.')
wholeNumber = wholeNumber * 10 + (ppToken->name[i] - '0');
}
}
decimalShift = firstDecimal - endNonZeroDecimal;
}
}
// Exponent:
bool negativeExponent = false;
double exponentValue = 0.0;
int exponent = 0;
{
if (ch == 'e' || ch == 'E') {
hasDecimalOrExponent = true;
saveName(ch);
ch = getChar();
if (ch == '+' || ch == '-') {
negativeExponent = ch == '-';
saveName(ch);
ch = getChar();
}
if (ch >= '0' && ch <= '9') {
while (ch >= '0' && ch <= '9') {
if (exponent < 500) {
exponent = exponent * 10 + (ch - '0');
}
saveName(ch);
ch = getChar();
}
} else {
parseContext.ppError(ppToken->loc, "bad character in float exponent", "", "");
}
}
// Compensate for location of decimal
if (negativeExponent)
exponent -= decimalShift;
else {
exponent += decimalShift;
if (exponent < 0) {
negativeExponent = true;
exponent = -exponent;
}
}
if (exponent > 22)
fastPath = false;
if (fastPath) {
// Compute the floating-point value of the exponent
exponentValue = 1.0;
if (exponent > 0) {
double expFactor = 10;
while (exponent > 0) {
if (exponent & 0x1)
exponentValue *= expFactor;
expFactor *= expFactor;
exponent >>= 1;
}
}
}
}
// Suffix:
bool isDouble = false;
bool isFloat16 = false;
if (ch == 'l' || ch == 'L') {
if (ifdepth == 0 && parseContext.intermediate.getSource() == EShSourceGlsl)
parseContext.doubleCheck(ppToken->loc, "double floating-point suffix");
if (ifdepth == 0 && !hasDecimalOrExponent)
parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
if (parseContext.intermediate.getSource() == EShSourceGlsl) {
int ch2 = getChar();
if (ch2 != 'f' && ch2 != 'F') {
ungetChar();
ungetChar();
} else {
saveName(ch);
saveName(ch2);
isDouble = true;
}
} else if (parseContext.intermediate.getSource() == EShSourceHlsl) {
saveName(ch);
isDouble = true;
}
} else if (ch == 'h' || ch == 'H') {
if (ifdepth == 0 && parseContext.intermediate.getSource() == EShSourceGlsl)
parseContext.float16Check(ppToken->loc, "half floating-point suffix");
if (ifdepth == 0 && !hasDecimalOrExponent)
parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
if (parseContext.intermediate.getSource() == EShSourceGlsl) {
int ch2 = getChar();
if (ch2 != 'f' && ch2 != 'F') {
ungetChar();
ungetChar();
} else {
saveName(ch);
saveName(ch2);
isFloat16 = true;
}
} else if (parseContext.intermediate.getSource() == EShSourceHlsl) {
saveName(ch);
isFloat16 = true;
}
} else
if (ch == 'f' || ch == 'F') {
if (ifdepth == 0)
parseContext.profileRequires(ppToken->loc, EEsProfile, 300, nullptr, "floating-point suffix");
if (ifdepth == 0 && !parseContext.relaxedErrors())
parseContext.profileRequires(ppToken->loc, ~EEsProfile, 120, nullptr, "floating-point suffix");
if (ifdepth == 0 && !hasDecimalOrExponent)
parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
saveName(ch);
} else
ungetChar();
// Patch up the name and length for overflow
if (len > MaxTokenLength) {
len = MaxTokenLength;
parseContext.ppError(ppToken->loc, "float literal too long", "", "");
}
ppToken->name[len] = '\0';
// Compute the numerical value
if (fastPath) {
// compute the floating-point value of the exponent
if (exponentValue == 0.0)
ppToken->dval = (double)wholeNumber;
else if (negativeExponent)
ppToken->dval = (double)wholeNumber / exponentValue;
else
ppToken->dval = (double)wholeNumber * exponentValue;
} else {
// slow path
ppToken->dval = 0.0;
// remove suffix
TString numstr(ppToken->name);
if (numstr.back() == 'f' || numstr.back() == 'F')
numstr.pop_back();
if (numstr.back() == 'h' || numstr.back() == 'H')
numstr.pop_back();
if (numstr.back() == 'l' || numstr.back() == 'L')
numstr.pop_back();
// use platform library
strtodStream.clear();
strtodStream.str(numstr.c_str());
strtodStream >> ppToken->dval;
if (strtodStream.fail()) {
// Assume failure combined with a large exponent was overflow, in
// an attempt to set INF.
if (!negativeExponent && exponent + numWholeNumberDigits > 300)
ppToken->i64val = 0x7ff0000000000000; // +Infinity
// Assume failure combined with a small exponent was overflow.
if (negativeExponent && exponent + numWholeNumberDigits > 300)
ppToken->dval = 0.0;
// Unknown reason for failure. Theory is that either
// - the 0.0 is still there, or
// - something reasonable was written that is better than 0.0
}
}
// Return the right token type
if (isDouble)
return PpAtomConstDouble;
else if (isFloat16)
return PpAtomConstFloat16;
else
return PpAtomConstFloat;
}
// Recognize a character literal.
//
// The first ' has already been accepted, read the rest, through the closing '.
//
// Always returns PpAtomConstInt.
//
int TPpContext::characterLiteral(TPpToken* ppToken)
{
ppToken->name[0] = 0;
ppToken->ival = 0;
if (parseContext.intermediate.getSource() != EShSourceHlsl) {
// illegal, except in macro definition, for which case we report the character
return '\'';
}
int ch = getChar();
switch (ch) {
case '\'':
// As empty sequence: ''
parseContext.ppError(ppToken->loc, "unexpected", "\'", "");
return PpAtomConstInt;
case '\\':
// As escape sequence: '\XXX'
switch (ch = getChar()) {
case 'a':
ppToken->ival = 7;
break;
case 'b':
ppToken->ival = 8;
break;
case 't':
ppToken->ival = 9;
break;
case 'n':
ppToken->ival = 10;
break;
case 'v':
ppToken->ival = 11;
break;
case 'f':
ppToken->ival = 12;
break;
case 'r':
ppToken->ival = 13;
break;
case 'x':
case '0':
parseContext.ppError(ppToken->loc, "octal and hex sequences not supported", "\\", "");
break;
default:
// This catches '\'', '\"', '\?', etc.
// Also, things like '\C' mean the same thing as 'C'
// (after the above cases are filtered out).
ppToken->ival = ch;
break;
}
break;
default:
ppToken->ival = ch;
break;
}
ppToken->name[0] = (char)ppToken->ival;
ppToken->name[1] = '\0';
ch = getChar();
if (ch != '\'') {
parseContext.ppError(ppToken->loc, "expected", "\'", "");
// Look ahead for a closing '
do {
ch = getChar();
} while (ch != '\'' && ch != EndOfInput && ch != '\n');
}
return PpAtomConstInt;
}
//
// Scanner used to tokenize source stream.
//
// N.B. Invalid numeric suffixes are not consumed.//
// This is technically not correct, as the preprocessor should just
// accept the numeric literal along with whatever suffix it has, but
// currently, it stops on seeing a bad suffix, treating that as the
// next token. This effects things like token pasting, where it is
// relevant how many tokens something was broken into.
// See peekContinuedPasting().
//
int TPpContext::tStringInput::scan(TPpToken* ppToken)
{
int AlreadyComplained = 0;
int len = 0;
int ch = 0;
int ii = 0;
unsigned long long ival = 0;
const auto floatingPointChar = [&](int ch) { return ch == '.' || ch == 'e' || ch == 'E' ||
ch == 'f' || ch == 'F' ||
ch == 'h' || ch == 'H'; };
static const char* const Int64_Extensions[] = {
E_GL_ARB_gpu_shader_int64,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int64 };
static const int Num_Int64_Extensions = sizeof(Int64_Extensions) / sizeof(Int64_Extensions[0]);
static const char* const Int16_Extensions[] = {
E_GL_AMD_gpu_shader_int16,
E_GL_EXT_shader_explicit_arithmetic_types,
E_GL_EXT_shader_explicit_arithmetic_types_int16 };
static const int Num_Int16_Extensions = sizeof(Int16_Extensions) / sizeof(Int16_Extensions[0]);
ppToken->clear();
ch = getch();
for (;;) {
while (ch == ' ' || ch == '\t') {
ppToken->space = true;
ch = getch();
}
ppToken->loc = pp->parseContext.getCurrentLoc();
len = 0;
switch (ch) {
default:
// Single character token, including EndOfInput, '#' and '\' (escaped newlines are handled at a lower level, so this is just a '\' token)
if (ch > PpAtomMaxSingle)
ch = PpAtomBadToken;
return ch;
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
case 'K': case 'L': case 'M': case 'N': case 'O':
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y':
case 'Z': case '_':
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z':
do {
if (len < MaxTokenLength) {
ppToken->name[len++] = (char)ch;
ch = getch();
} else {
if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "name too long", "", "");
AlreadyComplained = 1;
}
ch = getch();
}
} while ((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9') ||
ch == '_');
// line continuation with no token before or after makes len == 0, and need to start over skipping white space, etc.
if (len == 0)
continue;
ppToken->name[len] = '\0';
ungetch();
return PpAtomIdentifier;
case '0':
ppToken->name[len++] = (char)ch;
ch = getch();
if (ch == 'x' || ch == 'X') {
// must be hexadecimal
bool isUnsigned = false;
bool isInt64 = false;
bool isInt16 = false;
ppToken->name[len++] = (char)ch;
ch = getch();
if ((ch >= '0' && ch <= '9') ||
(ch >= 'A' && ch <= 'F') ||
(ch >= 'a' && ch <= 'f')) {
ival = 0;
do {
if (len < MaxTokenLength && ival <= 0x7fffffffffffffffull) {
ppToken->name[len++] = (char)ch;
if (ch >= '0' && ch <= '9') {
ii = ch - '0';
} else if (ch >= 'A' && ch <= 'F') {
ii = ch - 'A' + 10;
} else if (ch >= 'a' && ch <= 'f') {
ii = ch - 'a' + 10;
} else
pp->parseContext.ppError(ppToken->loc, "bad digit in hexadecimal literal", "", "");
ival = (ival << 4) | ii;
} else {
if (! AlreadyComplained) {
if(len < MaxTokenLength)
pp->parseContext.ppError(ppToken->loc, "hexadecimal literal too big", "", "");
else
pp->parseContext.ppError(ppToken->loc, "hexadecimal literal too long", "", "");
AlreadyComplained = 1;
}
ival = 0xffffffffffffffffull;
}
ch = getch();
} while ((ch >= '0' && ch <= '9') ||
(ch >= 'A' && ch <= 'F') ||
(ch >= 'a' && ch <= 'f'));
} else {
pp->parseContext.ppError(ppToken->loc, "bad digit in hexadecimal literal", "", "");
}
if (ch == 'u' || ch == 'U') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isUnsigned = true;
int nextCh = getch();
if (nextCh == 'l' || nextCh == 'L') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)nextCh;
isInt64 = true;
} else
ungetch();
nextCh = getch();
if ((nextCh == 's' || nextCh == 'S') &&
pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)nextCh;
isInt16 = true;
} else
ungetch();
} else if (ch == 'l' || ch == 'L') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isInt64 = true;
} else if ((ch == 's' || ch == 'S') &&
pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isInt16 = true;
} else
ungetch();
ppToken->name[len] = '\0';
if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (pp->ifdepth == 0) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"64-bit hexadecimal literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int64_Extensions, Int64_Extensions, "64-bit hexadecimal literal");
}
ppToken->i64val = ival;
return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64;
} else if (isInt16) {
if (pp->ifdepth == 0) {
if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"16-bit hexadecimal literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int16_Extensions, Int16_Extensions, "16-bit hexadecimal literal");
}
}
ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16;
} else {
if (ival > 0xffffffffu && !AlreadyComplained)
pp->parseContext.ppError(ppToken->loc, "hexadecimal literal too big", "", "");
ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint : PpAtomConstInt;
}
} else if ((ch == 'b' || ch == 'B') && pp->parseContext.intermediate.getSource() == EShSourceHlsl) {
// must be binary
bool isUnsigned = false;
bool isInt64 = false;
bool isInt16 = false;
ppToken->name[len++] = (char)ch;
ch = getch();
// Check value
if ((ch == '0' || ch == '1'))
{
ival = 0;
do {
if (len < MaxTokenLength && ival <= 0x7fffffffffffffffull) {
ppToken->name[len++] = (char)ch;
if (ch == '0' || ch == '1') {
ii = ch - '0';
} else {
pp->parseContext.ppError(ppToken->loc, "bad digit in binary literal", "", "");
}
ival = (ival << 1) | ii;
}
else
{
if (! AlreadyComplained) {
if(len < MaxTokenLength)
pp->parseContext.ppError(ppToken->loc, "binary literal too big", "", "");
else
pp->parseContext.ppError(ppToken->loc, "binary literal too long", "", "");
AlreadyComplained = 1;
}
ival = 0xffffffffffffffffull;
}
ch = getch();
} while (ch == '0' || ch == '1');
}
else
{
pp->parseContext.ppError(ppToken->loc, "bad digit in binary literal", "", "");
}
// check type
if (ch == 'u' || ch == 'U') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isUnsigned = true;
int nextCh = getch();
if (nextCh == 'l' || nextCh == 'L') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)nextCh;
isInt64 = true;
} else
ungetch();
nextCh = getch();
if ((nextCh == 's' || nextCh == 'S') &&
pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)nextCh;
isInt16 = true;
} else
ungetch();
} else if (ch == 'l' || ch == 'L') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isInt64 = true;
} else if ((ch == 's' || ch == 'S') &&
pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isInt16 = true;
} else {
ungetch();
}
ppToken->name[len] = '\0';
// Assign value
if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (pp->ifdepth == 0) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"64-bit binary literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int64_Extensions, Int64_Extensions, "64-bit binary literal");
}
ppToken->i64val = ival;
return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64;
} else if (isInt16) {
if (pp->ifdepth == 0) {
if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"16-bit binary literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int16_Extensions, Int16_Extensions, "16-bit binary literal");
}
}
ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16;
} else {
ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint : PpAtomConstInt;
}
} else {
// could be octal integer or floating point, speculative pursue octal until it must be floating point
bool isUnsigned = false;
bool isInt64 = false;
bool isInt16 = false;
bool octalOverflow = false;
bool nonOctal = false;
ival = 0;
// see how much octal-like stuff we can read
while (ch >= '0' && ch <= '7') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
else if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", "");
AlreadyComplained = 1;
}
if (ival <= 0x1fffffffffffffffull) {
ii = ch - '0';
ival = (ival << 3) | ii;
} else
octalOverflow = true;
ch = getch();
}
// could be part of a float...
if (ch == '8' || ch == '9') {
nonOctal = true;
do {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
else if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", "");
AlreadyComplained = 1;
}
ch = getch();
} while (ch >= '0' && ch <= '9');
}
if (floatingPointChar(ch))
return pp->lFloatConst(len, ch, ppToken);
// wasn't a float, so must be octal...
if (nonOctal)
pp->parseContext.ppError(ppToken->loc, "octal literal digit too large", "", "");
if (ch == 'u' || ch == 'U') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isUnsigned = true;
int nextCh = getch();
if (nextCh == 'l' || nextCh == 'L') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)nextCh;
isInt64 = true;
} else
ungetch();
nextCh = getch();
if ((nextCh == 's' || nextCh == 'S') &&
pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)nextCh;
isInt16 = true;
} else
ungetch();
} else if (ch == 'l' || ch == 'L') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isInt64 = true;
} else if ((ch == 's' || ch == 'S') &&
pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isInt16 = true;
} else
ungetch();
ppToken->name[len] = '\0';
if (!isInt64 && ival > 0xffffffffu)
octalOverflow = true;
if (octalOverflow)
pp->parseContext.ppError(ppToken->loc, "octal literal too big", "", "");
if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (pp->ifdepth == 0) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"64-bit octal literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int64_Extensions, Int64_Extensions, "64-bit octal literal");
}
ppToken->i64val = ival;
return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64;
} else if (isInt16) {
if (pp->ifdepth == 0) {
if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"16-bit octal literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int16_Extensions, Int16_Extensions, "16-bit octal literal");
}
}
ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16;
} else {
ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint : PpAtomConstInt;
}
}
break;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
// can't be hexadecimal or octal, is either decimal or floating point
do {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
else if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", "");
AlreadyComplained = 1;
}
ch = getch();
} while (ch >= '0' && ch <= '9');
if (floatingPointChar(ch))
return pp->lFloatConst(len, ch, ppToken);
else {
// Finish handling signed and unsigned integers
int numericLen = len;
bool isUnsigned = false;
bool isInt64 = false;
bool isInt16 = false;
if (ch == 'u' || ch == 'U') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isUnsigned = true;
int nextCh = getch();
if (nextCh == 'l' || nextCh == 'L') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)nextCh;
isInt64 = true;
} else
ungetch();
nextCh = getch();
if ((nextCh == 's' || nextCh == 'S') &&
pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)nextCh;
isInt16 = true;
} else
ungetch();
} else if (ch == 'l' || ch == 'L') {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isInt64 = true;
} else if ((ch == 's' || ch == 'S') &&
pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isInt16 = true;
} else
ungetch();
ppToken->name[len] = '\0';
ival = 0;
const unsigned oneTenthMaxInt = 0xFFFFFFFFu / 10;
const unsigned remainderMaxInt = 0xFFFFFFFFu - 10 * oneTenthMaxInt;
const unsigned long long oneTenthMaxInt64 = 0xFFFFFFFFFFFFFFFFull / 10;
const unsigned long long remainderMaxInt64 = 0xFFFFFFFFFFFFFFFFull - 10 * oneTenthMaxInt64;
const unsigned short oneTenthMaxInt16 = 0xFFFFu / 10;
const unsigned short remainderMaxInt16 = 0xFFFFu - 10 * oneTenthMaxInt16;
for (int i = 0; i < numericLen; i++) {
ch = ppToken->name[i] - '0';
bool overflow = false;
if (isInt64)
overflow = (ival > oneTenthMaxInt64 || (ival == oneTenthMaxInt64 && (unsigned long long)ch > remainderMaxInt64));
else if (isInt16)
overflow = (ival > oneTenthMaxInt16 || (ival == oneTenthMaxInt16 && (unsigned short)ch > remainderMaxInt16));
else
overflow = (ival > oneTenthMaxInt || (ival == oneTenthMaxInt && (unsigned)ch > remainderMaxInt));
if (overflow) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too big", "", "");
ival = 0xFFFFFFFFFFFFFFFFull;
break;
} else
ival = ival * 10 + ch;
}
if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
if (pp->ifdepth == 0) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"64-bit literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int64_Extensions, Int64_Extensions, "64-bit literal");
}
ppToken->i64val = ival;
return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64;
} else if (isInt16) {
if (pp->ifdepth == 0 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) {
pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile,
"16-bit literal");
pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0,
Num_Int16_Extensions, Int16_Extensions, "16-bit literal");
}
ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16;
} else {
ppToken->ival = (int)ival;
return isUnsigned ? PpAtomConstUint : PpAtomConstInt;
}
}
break;
case '-':
ch = getch();
if (ch == '-') {
return PpAtomDecrement;
} else if (ch == '=') {
return PPAtomSubAssign;
} else {
ungetch();
return '-';
}
case '+':
ch = getch();
if (ch == '+') {
return PpAtomIncrement;
} else if (ch == '=') {
return PPAtomAddAssign;
} else {
ungetch();
return '+';
}
case '*':
ch = getch();
if (ch == '=') {
return PPAtomMulAssign;
} else {
ungetch();
return '*';
}
case '%':
ch = getch();
if (ch == '=') {
return PPAtomModAssign;
} else {
ungetch();
return '%';
}
case '^':
ch = getch();
if (ch == '^') {
return PpAtomXor;
} else {
if (ch == '=')
return PpAtomXorAssign;
else{
ungetch();
return '^';
}
}
case '=':
ch = getch();
if (ch == '=') {
return PpAtomEQ;
} else {
ungetch();
return '=';
}
case '!':
ch = getch();
if (ch == '=') {
return PpAtomNE;
} else {
ungetch();
return '!';
}
case '|':
ch = getch();
if (ch == '|') {
return PpAtomOr;
} else if (ch == '=') {
return PpAtomOrAssign;
} else {
ungetch();
return '|';
}
case '&':
ch = getch();
if (ch == '&') {
return PpAtomAnd;
} else if (ch == '=') {
return PpAtomAndAssign;
} else {
ungetch();
return '&';
}
case '<':
ch = getch();
if (ch == '<') {
ch = getch();
if (ch == '=')
return PpAtomLeftAssign;
else {
ungetch();
return PpAtomLeft;
}
} else if (ch == '=') {
return PpAtomLE;
} else {
ungetch();
return '<';
}
case '>':
ch = getch();
if (ch == '>') {
ch = getch();
if (ch == '=')
return PpAtomRightAssign;
else {
ungetch();
return PpAtomRight;
}
} else if (ch == '=') {
return PpAtomGE;
} else {
ungetch();
return '>';
}
case '.':
ch = getch();
if (ch >= '0' && ch <= '9') {
ungetch();
return pp->lFloatConst(0, '.', ppToken);
} else {
ungetch();
return '.';
}
case '/':
ch = getch();
if (ch == '/') {
pp->inComment = true;
do {
ch = getch();
} while (ch != '\n' && ch != EndOfInput);
ppToken->space = true;
pp->inComment = false;
return ch;
} else if (ch == '*') {
ch = getch();
do {
while (ch != '*') {
if (ch == EndOfInput) {
pp->parseContext.ppError(ppToken->loc, "End of input in comment", "comment", "");
return ch;
}
ch = getch();
}
ch = getch();
if (ch == EndOfInput) {
pp->parseContext.ppError(ppToken->loc, "End of input in comment", "comment", "");
return ch;
}
} while (ch != '/');
ppToken->space = true;
// loop again to get the next token...
break;
} else if (ch == '=') {
return PPAtomDivAssign;
} else {
ungetch();
return '/';
}
break;
case '\'':
return pp->characterLiteral(ppToken);
case '"':
// #include uses scanHeaderName() to ignore these escape sequences.
ch = getch();
while (ch != '"' && ch != '\n' && ch != EndOfInput) {
if (len < MaxTokenLength) {
if (ch == '\\' && !pp->disableEscapeSequences) {
int nextCh = getch();
switch (nextCh) {
case '\'': ch = 0x27; break;
case '"': ch = 0x22; break;
case '?': ch = 0x3f; break;
case '\\': ch = 0x5c; break;
case 'a': ch = 0x07; break;
case 'b': ch = 0x08; break;
case 'f': ch = 0x0c; break;
case 'n': ch = 0x0a; break;
case 'r': ch = 0x0d; break;
case 't': ch = 0x09; break;
case 'v': ch = 0x0b; break;
case 'x':
// Hex value, arbitrary number of characters. Terminated by the first
// non-hex digit
{
int numDigits = 0;
ch = 0;
while (true) {
nextCh = getch();
if (nextCh >= '0' && nextCh <= '9')
nextCh -= '0';
else if (nextCh >= 'A' && nextCh <= 'F')
nextCh -= 'A' - 10;
else if (nextCh >= 'a' && nextCh <= 'f')
nextCh -= 'a' - 10;
else {
ungetch();
break;
}
numDigits++;
ch = ch * 0x10 + nextCh;
}
if (numDigits == 0) {
pp->parseContext.ppError(ppToken->loc, "Expected hex value in escape sequence", "string", "");
}
break;
}
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
// Octal value, up to three octal digits
{
int numDigits = 1;
ch = nextCh - '0';
while (numDigits < 3) {
nextCh = getch();
if (nextCh >= '0' && nextCh <= '7')
nextCh -= '0';
else {
ungetch();
break;
}
numDigits++;
ch = ch * 8 + nextCh;
}
break;
}
default:
pp->parseContext.ppError(ppToken->loc, "Invalid escape sequence", "string", "");
break;
}
}
ppToken->name[len] = (char)ch;
len++;
ch = getch();
} else
break;
};
ppToken->name[len] = '\0';
if (ch != '"') {
ungetch();
pp->parseContext.ppError(ppToken->loc, "End of line in string", "string", "");
}
return PpAtomConstString;
case ':':
ch = getch();
if (ch == ':')
return PpAtomColonColon;
ungetch();
return ':';
}
ch = getch();
}
}
//
// The main functional entry point into the preprocessor, which will
// scan the source strings to figure out and return the next processing token.
//
// Return the token, or EndOfInput when no more tokens.
//
int TPpContext::tokenize(TPpToken& ppToken)
{
for(;;) {
int token = scanToken(&ppToken);
// Handle token-pasting logic
token = tokenPaste(token, ppToken);
if (token == EndOfInput) {
missingEndifCheck();
return EndOfInput;
}
if (token == '#') {
if (previous_token == '\n') {
token = readCPPline(&ppToken);
if (token == EndOfInput) {
missingEndifCheck();
return EndOfInput;
}
continue;
} else {
parseContext.ppError(ppToken.loc, "preprocessor directive cannot be preceded by another token", "#", "");
return EndOfInput;
}
}
previous_token = token;
if (token == '\n')
continue;
// expand macros
if (token == PpAtomIdentifier) {
switch (MacroExpand(&ppToken, false, true)) {
case MacroExpandNotStarted:
break;
case MacroExpandError:
return EndOfInput;
case MacroExpandStarted:
case MacroExpandUndef:
continue;
}
}
switch (token) {
case PpAtomIdentifier:
case PpAtomConstInt:
case PpAtomConstUint:
case PpAtomConstFloat:
case PpAtomConstInt64:
case PpAtomConstUint64:
case PpAtomConstInt16:
case PpAtomConstUint16:
case PpAtomConstDouble:
case PpAtomConstFloat16:
if (ppToken.name[0] == '\0')
continue;
break;
case PpAtomConstString:
// HLSL allows string literals.
// GLSL allows string literals with GL_EXT_debug_printf.
if (ifdepth == 0 && parseContext.intermediate.getSource() != EShSourceHlsl) {
const char* const string_literal_EXTs[] = { E_GL_EXT_debug_printf, E_GL_EXT_spirv_intrinsics };
parseContext.requireExtensions(ppToken.loc, 2, string_literal_EXTs, "string literal");
if (!parseContext.extensionTurnedOn(E_GL_EXT_debug_printf) &&
!parseContext.extensionTurnedOn(E_GL_EXT_spirv_intrinsics))
continue;
}
break;
case '\'':
parseContext.ppError(ppToken.loc, "character literals not supported", "\'", "");
continue;
default:
snprintf(ppToken.name, sizeof(ppToken.name), "%s", atomStrings.getString(token));
break;
}
return token;
}
}
//
// Do all token-pasting related combining of two pasted tokens when getting a
// stream of tokens from a replacement list. Degenerates to no processing if a
// replacement list is not the source of the token stream.
//
int TPpContext::tokenPaste(int token, TPpToken& ppToken)
{
// starting with ## is illegal, skip to next token
if (token == PpAtomPaste) {
parseContext.ppError(ppToken.loc, "unexpected location", "##", "");
return scanToken(&ppToken);
}
int resultToken = token; // "foo" pasted with "35" is an identifier, not a number
// ## can be chained, process all in the chain at once
while (peekPasting()) {
TPpToken pastedPpToken;
// next token has to be ##
token = scanToken(&pastedPpToken);
assert(token == PpAtomPaste);
// This covers end of macro expansion
if (endOfReplacementList()) {
parseContext.ppError(ppToken.loc, "unexpected location; end of replacement list", "##", "");
break;
}
// Get the token(s) after the ##.
// Because of "space" semantics, and prior tokenization, what
// appeared a single token, e.g. "3A", might have been tokenized
// into two tokens "3" and "A", but the "A" will have 'space' set to
// false. Accumulate all of these to recreate the original lexical
// appearing token.
do {
token = scanToken(&pastedPpToken);
// This covers end of argument expansion
if (token == tMarkerInput::marker) {
parseContext.ppError(ppToken.loc, "unexpected location; end of argument", "##", "");
return resultToken;
}
// get the token text
switch (resultToken) {
case PpAtomIdentifier:
// already have the correct text in token.names
break;
case '=':
case '!':
case '-':
case '~':
case '+':
case '*':
case '/':
case '%':
case '<':
case '>':
case '|':
case '^':
case '&':
case PpAtomRight:
case PpAtomLeft:
case PpAtomAnd:
case PpAtomOr:
case PpAtomXor:
snprintf(ppToken.name, sizeof(ppToken.name), "%s", atomStrings.getString(resultToken));
snprintf(pastedPpToken.name, sizeof(pastedPpToken.name), "%s", atomStrings.getString(token));
break;
default:
parseContext.ppError(ppToken.loc, "not supported for these tokens", "##", "");
return resultToken;
}
// combine the tokens
if (strlen(ppToken.name) + strlen(pastedPpToken.name) > MaxTokenLength) {
parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", "");
return resultToken;
}
snprintf(&ppToken.name[0] + strlen(ppToken.name), sizeof(ppToken.name) - strlen(ppToken.name),
"%s", pastedPpToken.name);
// correct the kind of token we are making, if needed (identifiers stay identifiers)
if (resultToken != PpAtomIdentifier) {
int newToken = atomStrings.getAtom(ppToken.name);
if (newToken > 0)
resultToken = newToken;
else
parseContext.ppError(ppToken.loc, "combined token is invalid", "##", "");
}
} while (peekContinuedPasting(resultToken));
}
return resultToken;
}
// Checks if we've seen balanced #if...#endif
void TPpContext::missingEndifCheck()
{
if (ifdepth > 0)
parseContext.ppError(parseContext.getCurrentLoc(), "missing #endif", "", "");
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang/MachineIndependent | repos/glslang.zig/glslang/glslang/MachineIndependent/preprocessor/PpContext.h | //
// Copyright (C) 2013 LunarG, Inc.
// Copyright (C) 2015-2018 Google, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
#ifndef PPCONTEXT_H
#define PPCONTEXT_H
#include <stack>
#include <unordered_map>
#include <sstream>
#include "../ParseHelper.h"
#include "PpTokens.h"
namespace glslang {
class TPpToken {
public:
TPpToken() { clear(); }
void clear()
{
space = false;
i64val = 0;
loc.init();
name[0] = 0;
fullyExpanded = false;
}
// Used for comparing macro definitions, so checks what is relevant for that.
bool operator==(const TPpToken& right) const
{
return space == right.space &&
ival == right.ival && dval == right.dval && i64val == right.i64val &&
strncmp(name, right.name, MaxTokenLength) == 0;
}
bool operator!=(const TPpToken& right) const { return ! operator==(right); }
TSourceLoc loc;
// True if a space (for white space or a removed comment) should also be
// recognized, in front of the token returned:
bool space;
bool fullyExpanded;
// Numeric value of the token:
union {
int ival;
double dval;
long long i64val;
};
// Text string of the token:
char name[MaxTokenLength + 1];
};
class TStringAtomMap {
//
// Implementation is in PpAtom.cpp
//
// Maintain a bi-directional mapping between relevant preprocessor strings and
// "atoms" which a unique integers (small, contiguous, not hash-like) per string.
//
public:
TStringAtomMap();
// Map string -> atom.
// Return 0 if no existing string.
int getAtom(const char* s) const
{
auto it = atomMap.find(s);
return it == atomMap.end() ? 0 : it->second;
}
// Map a new or existing string -> atom, inventing a new atom if necessary.
int getAddAtom(const char* s)
{
int atom = getAtom(s);
if (atom == 0) {
atom = nextAtom++;
addAtomFixed(s, atom);
}
return atom;
}
// Map atom -> string.
const char* getString(int atom) const { return stringMap[atom]->c_str(); }
protected:
TStringAtomMap(TStringAtomMap&);
TStringAtomMap& operator=(TStringAtomMap&);
TUnorderedMap<TString, int> atomMap;
TVector<const TString*> stringMap; // these point into the TString in atomMap
int nextAtom;
// Bad source characters can lead to bad atoms, so gracefully handle those by
// pre-filling the table with them (to avoid if tests later).
TString badToken;
// Add bi-directional mappings:
// - string -> atom
// - atom -> string
void addAtomFixed(const char* s, int atom)
{
auto it = atomMap.insert(std::pair<TString, int>(s, atom)).first;
if (stringMap.size() < (size_t)atom + 1)
stringMap.resize(atom + 100, &badToken);
stringMap[atom] = &it->first;
}
};
class TInputScanner;
enum MacroExpandResult {
MacroExpandNotStarted, // macro not expanded, which might not be an error
MacroExpandError, // a clear error occurred while expanding, no expansion
MacroExpandStarted, // macro expansion process has started
MacroExpandUndef // macro is undefined and will be expanded
};
// This class is the result of turning a huge pile of C code communicating through globals
// into a class. This was done to allowing instancing to attain thread safety.
// Don't expect too much in terms of OO design.
class TPpContext {
public:
TPpContext(TParseContextBase&, const std::string& rootFileName, TShader::Includer&);
virtual ~TPpContext();
void setPreamble(const char* preamble, size_t length);
int tokenize(TPpToken& ppToken);
int tokenPaste(int token, TPpToken&);
class tInput {
public:
tInput(TPpContext* p) : done(false), pp(p) { }
virtual ~tInput() { }
virtual int scan(TPpToken*) = 0;
virtual int getch() = 0;
virtual void ungetch() = 0;
virtual bool peekPasting() { return false; } // true when about to see ##
virtual bool peekContinuedPasting(int) { return false; } // true when non-spaced tokens can paste
virtual bool endOfReplacementList() { return false; } // true when at the end of a macro replacement list (RHS of #define)
virtual bool isMacroInput() { return false; }
virtual bool isStringInput() { return false; }
// Will be called when we start reading tokens from this instance
virtual void notifyActivated() {}
// Will be called when we do not read tokens from this instance anymore
virtual void notifyDeleted() {}
protected:
bool done;
TPpContext* pp;
};
void setInput(TInputScanner& input, bool versionWillBeError);
void pushInput(tInput* in)
{
inputStack.push_back(in);
in->notifyActivated();
}
void popInput()
{
inputStack.back()->notifyDeleted();
delete inputStack.back();
inputStack.pop_back();
}
//
// From PpTokens.cpp
//
// Capture the needed parts of a token stream for macro recording/playback.
class TokenStream {
public:
// Manage a stream of these 'Token', which capture the relevant parts
// of a TPpToken, plus its atom.
class Token {
public:
Token(int atom, const TPpToken& ppToken) :
atom(atom),
space(ppToken.space),
i64val(ppToken.i64val),
name(ppToken.name) { }
int get(TPpToken& ppToken)
{
ppToken.clear();
ppToken.space = space;
ppToken.i64val = i64val;
snprintf(ppToken.name, sizeof(ppToken.name), "%s", name.c_str());
return atom;
}
bool isAtom(int a) const { return atom == a; }
int getAtom() const { return atom; }
bool nonSpaced() const { return !space; }
protected:
Token() {}
int atom;
bool space; // did a space precede the token?
long long i64val;
TString name;
};
TokenStream() : currentPos(0) { }
void putToken(int token, TPpToken* ppToken);
bool peekToken(int atom) { return !atEnd() && stream[currentPos].isAtom(atom); }
bool peekContinuedPasting(int atom)
{
// This is basically necessary because, for example, the PP
// tokenizer only accepts valid numeric-literals plus suffixes, so
// separates numeric-literals plus bad suffix into two tokens, which
// should get both pasted together as one token when token pasting.
//
// The following code is a bit more generalized than the above example.
if (!atEnd() && atom == PpAtomIdentifier && stream[currentPos].nonSpaced()) {
switch(stream[currentPos].getAtom()) {
case PpAtomConstInt:
case PpAtomConstUint:
case PpAtomConstInt64:
case PpAtomConstUint64:
case PpAtomConstInt16:
case PpAtomConstUint16:
case PpAtomConstFloat:
case PpAtomConstDouble:
case PpAtomConstFloat16:
case PpAtomConstString:
case PpAtomIdentifier:
return true;
default:
break;
}
}
return false;
}
int getToken(TParseContextBase&, TPpToken*);
bool atEnd() { return currentPos >= stream.size(); }
bool peekTokenizedPasting(bool lastTokenPastes);
bool peekUntokenizedPasting();
void reset() { currentPos = 0; }
protected:
TVector<Token> stream;
size_t currentPos;
};
//
// From Pp.cpp
//
struct MacroSymbol {
MacroSymbol() : functionLike(0), busy(0), undef(0) { }
TVector<int> args;
TokenStream body;
unsigned functionLike : 1; // 0 means object-like, 1 means function-like
unsigned busy : 1;
unsigned undef : 1;
};
typedef TMap<int, MacroSymbol> TSymbolMap;
TSymbolMap macroDefs; // map atoms to macro definitions
MacroSymbol* lookupMacroDef(int atom)
{
auto existingMacroIt = macroDefs.find(atom);
return (existingMacroIt == macroDefs.end()) ? nullptr : &(existingMacroIt->second);
}
void addMacroDef(int atom, MacroSymbol& macroDef) { macroDefs[atom] = macroDef; }
protected:
TPpContext(TPpContext&);
TPpContext& operator=(TPpContext&);
TStringAtomMap atomStrings;
char* preamble; // string to parse, all before line 1 of string 0, it is 0 if no preamble
int preambleLength;
char** strings; // official strings of shader, starting a string 0 line 1
size_t* lengths;
int numStrings; // how many official strings there are
int currentString; // which string we're currently parsing (-1 for preamble)
// Scanner data:
int previous_token;
TParseContextBase& parseContext;
std::vector<int> lastLineTokens;
std::vector<TSourceLoc> lastLineTokenLocs;
// Get the next token from *stack* of input sources, popping input sources
// that are out of tokens, down until an input source is found that has a token.
// Return EndOfInput when there are no more tokens to be found by doing this.
int scanToken(TPpToken* ppToken)
{
int token = EndOfInput;
while (! inputStack.empty()) {
token = inputStack.back()->scan(ppToken);
if (token != EndOfInput || inputStack.empty())
break;
popInput();
}
if (!inputStack.empty() && inputStack.back()->isStringInput()) {
if (token == '\n') {
bool seenNumSign = false;
for (int i = 0; i < (int)lastLineTokens.size() - 1;) {
int curPos = i;
int curToken = lastLineTokens[i++];
if (curToken == '#' && lastLineTokens[i] == '#') {
curToken = PpAtomPaste;
i++;
}
if (curToken == '#') {
if (seenNumSign) {
parseContext.ppError(lastLineTokenLocs[curPos], "(#) can be preceded in its line only by spaces or horizontal tabs", "#", "");
} else {
seenNumSign = true;
}
}
}
lastLineTokens.clear();
lastLineTokenLocs.clear();
} else {
lastLineTokens.push_back(token);
lastLineTokenLocs.push_back(ppToken->loc);
}
}
return token;
}
int getChar() { return inputStack.back()->getch(); }
void ungetChar() { inputStack.back()->ungetch(); }
bool peekPasting() { return !inputStack.empty() && inputStack.back()->peekPasting(); }
bool peekContinuedPasting(int a)
{
return !inputStack.empty() && inputStack.back()->peekContinuedPasting(a);
}
bool endOfReplacementList() { return inputStack.empty() || inputStack.back()->endOfReplacementList(); }
bool isMacroInput() { return inputStack.size() > 0 && inputStack.back()->isMacroInput(); }
static const int maxIfNesting = 65;
int ifdepth; // current #if-#else-#endif nesting in the cpp.c file (pre-processor)
bool elseSeen[maxIfNesting]; // Keep a track of whether an else has been seen at a particular depth
int elsetracker; // #if-#else and #endif constructs...Counter.
class tMacroInput : public tInput {
public:
tMacroInput(TPpContext* pp) : tInput(pp), prepaste(false), postpaste(false) { }
virtual ~tMacroInput()
{
for (size_t i = 0; i < args.size(); ++i)
delete args[i];
for (size_t i = 0; i < expandedArgs.size(); ++i)
delete expandedArgs[i];
}
virtual int scan(TPpToken*) override;
virtual int getch() override { assert(0); return EndOfInput; }
virtual void ungetch() override { assert(0); }
bool peekPasting() override { return prepaste; }
bool peekContinuedPasting(int a) override { return mac->body.peekContinuedPasting(a); }
bool endOfReplacementList() override { return mac->body.atEnd(); }
bool isMacroInput() override { return true; }
MacroSymbol *mac;
TVector<TokenStream*> args;
TVector<TokenStream*> expandedArgs;
protected:
bool prepaste; // true if we are just before ##
bool postpaste; // true if we are right after ##
};
class tMarkerInput : public tInput {
public:
tMarkerInput(TPpContext* pp) : tInput(pp) { }
virtual int scan(TPpToken*) override
{
if (done)
return EndOfInput;
done = true;
return marker;
}
virtual int getch() override { assert(0); return EndOfInput; }
virtual void ungetch() override { assert(0); }
static const int marker = -3;
};
class tZeroInput : public tInput {
public:
tZeroInput(TPpContext* pp) : tInput(pp) { }
virtual int scan(TPpToken*) override;
virtual int getch() override { assert(0); return EndOfInput; }
virtual void ungetch() override { assert(0); }
};
std::vector<tInput*> inputStack;
bool errorOnVersion;
bool versionSeen;
//
// from Pp.cpp
//
// Used to obtain #include content.
TShader::Includer& includer;
int CPPdefine(TPpToken * ppToken);
int CPPundef(TPpToken * ppToken);
int CPPelse(int matchelse, TPpToken * ppToken);
int extraTokenCheck(int atom, TPpToken* ppToken, int token);
int eval(int token, int precedence, bool shortCircuit, int& res, bool& err, TPpToken * ppToken);
int evalToToken(int token, bool shortCircuit, int& res, bool& err, TPpToken * ppToken);
int CPPif (TPpToken * ppToken);
int CPPifdef(int defined, TPpToken * ppToken);
int CPPinclude(TPpToken * ppToken);
int CPPline(TPpToken * ppToken);
int CPPerror(TPpToken * ppToken);
int CPPpragma(TPpToken * ppToken);
int CPPversion(TPpToken * ppToken);
int CPPextension(TPpToken * ppToken);
int readCPPline(TPpToken * ppToken);
int scanHeaderName(TPpToken* ppToken, char delimit);
TokenStream* PrescanMacroArg(TokenStream&, TPpToken*, bool newLineOkay);
MacroExpandResult MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOkay);
//
// From PpTokens.cpp
//
void pushTokenStreamInput(TokenStream&, bool pasting = false, bool expanded = false);
void UngetToken(int token, TPpToken*);
class tTokenInput : public tInput {
public:
tTokenInput(TPpContext* pp, TokenStream* t, bool prepasting, bool expanded) :
tInput(pp),
tokens(t),
lastTokenPastes(prepasting),
preExpanded(expanded) { }
virtual int scan(TPpToken *ppToken) override {
int token = tokens->getToken(pp->parseContext, ppToken);
ppToken->fullyExpanded = preExpanded;
if (tokens->atEnd() && token == PpAtomIdentifier) {
int macroAtom = pp->atomStrings.getAtom(ppToken->name);
MacroSymbol* macro = macroAtom == 0 ? nullptr : pp->lookupMacroDef(macroAtom);
if (macro && macro->functionLike)
ppToken->fullyExpanded = false;
}
return token;
}
virtual int getch() override { assert(0); return EndOfInput; }
virtual void ungetch() override { assert(0); }
virtual bool peekPasting() override { return tokens->peekTokenizedPasting(lastTokenPastes); }
bool peekContinuedPasting(int a) override { return tokens->peekContinuedPasting(a); }
protected:
TokenStream* tokens;
bool lastTokenPastes; // true if the last token in the input is to be pasted, rather than consumed as a token
bool preExpanded;
};
class tUngotTokenInput : public tInput {
public:
tUngotTokenInput(TPpContext* pp, int t, TPpToken* p) : tInput(pp), token(t), lval(*p) { }
virtual int scan(TPpToken *) override;
virtual int getch() override { assert(0); return EndOfInput; }
virtual void ungetch() override { assert(0); }
protected:
int token;
TPpToken lval;
};
//
// From PpScanner.cpp
//
class tStringInput : public tInput {
public:
tStringInput(TPpContext* pp, TInputScanner& i) : tInput(pp), input(&i) { }
virtual int scan(TPpToken*) override;
bool isStringInput() override { return true; }
// Scanner used to get source stream characters.
// - Escaped newlines are handled here, invisibly to the caller.
// - All forms of newline are handled, and turned into just a '\n'.
int getch() override
{
int ch = input->get();
if (ch == '\\') {
// Move past escaped newlines, as many as sequentially exist
do {
if (input->peek() == '\r' || input->peek() == '\n') {
bool allowed = pp->parseContext.lineContinuationCheck(input->getSourceLoc(), pp->inComment);
if (! allowed && pp->inComment)
return '\\';
// escape one newline now
ch = input->get();
int nextch = input->get();
if (ch == '\r' && nextch == '\n')
ch = input->get();
else
ch = nextch;
} else
return '\\';
} while (ch == '\\');
}
// handle any non-escaped newline
if (ch == '\r' || ch == '\n') {
if (ch == '\r' && input->peek() == '\n')
input->get();
return '\n';
}
return ch;
}
// Scanner used to backup the source stream characters. Newlines are
// handled here, invisibly to the caller, meaning have to undo exactly
// what getch() above does (e.g., don't leave things in the middle of a
// sequence of escaped newlines).
void ungetch() override
{
input->unget();
do {
int ch = input->peek();
if (ch == '\r' || ch == '\n') {
if (ch == '\n') {
// correct for two-character newline
input->unget();
if (input->peek() != '\r')
input->get();
}
// now in front of a complete newline, move past an escape character
input->unget();
if (input->peek() == '\\')
input->unget();
else {
input->get();
break;
}
} else
break;
} while (true);
}
protected:
TInputScanner* input;
};
// Holds a reference to included file data, as well as a
// prologue and an epilogue string. This can be scanned using the tInput
// interface and acts as a single source string.
class TokenizableIncludeFile : public tInput {
public:
// Copies prologue and epilogue. The includedFile must remain valid
// until this TokenizableIncludeFile is no longer used.
TokenizableIncludeFile(const TSourceLoc& startLoc,
const std::string& prologue,
TShader::Includer::IncludeResult* includedFile,
const std::string& epilogue,
TPpContext* pp)
: tInput(pp),
prologue_(prologue),
epilogue_(epilogue),
includedFile_(includedFile),
scanner(3, strings, lengths, nullptr, 0, 0, true),
prevScanner(nullptr),
stringInput(pp, scanner)
{
strings[0] = prologue_.data();
strings[1] = includedFile_->headerData;
strings[2] = epilogue_.data();
lengths[0] = prologue_.size();
lengths[1] = includedFile_->headerLength;
lengths[2] = epilogue_.size();
scanner.setLine(startLoc.line);
scanner.setString(startLoc.string);
scanner.setFile(startLoc.getFilenameStr(), 0);
scanner.setFile(startLoc.getFilenameStr(), 1);
scanner.setFile(startLoc.getFilenameStr(), 2);
}
// tInput methods:
int scan(TPpToken* t) override { return stringInput.scan(t); }
int getch() override { return stringInput.getch(); }
void ungetch() override { stringInput.ungetch(); }
void notifyActivated() override
{
prevScanner = pp->parseContext.getScanner();
pp->parseContext.setScanner(&scanner);
pp->push_include(includedFile_);
}
void notifyDeleted() override
{
pp->parseContext.setScanner(prevScanner);
pp->pop_include();
}
private:
TokenizableIncludeFile& operator=(const TokenizableIncludeFile&);
// Stores the prologue for this string.
const std::string prologue_;
// Stores the epilogue for this string.
const std::string epilogue_;
// Points to the IncludeResult that this TokenizableIncludeFile represents.
TShader::Includer::IncludeResult* includedFile_;
// Will point to prologue_, includedFile_->headerData and epilogue_
// This is passed to scanner constructor.
// These do not own the storage and it must remain valid until this
// object has been destroyed.
const char* strings[3];
// Length of str_, passed to scanner constructor.
size_t lengths[3];
// Scans over str_.
TInputScanner scanner;
// The previous effective scanner before the scanner in this instance
// has been activated.
TInputScanner* prevScanner;
// Delegate object implementing the tInput interface.
tStringInput stringInput;
};
int ScanFromString(char* s);
void missingEndifCheck();
int lFloatConst(int len, int ch, TPpToken* ppToken);
int characterLiteral(TPpToken* ppToken);
void push_include(TShader::Includer::IncludeResult* result)
{
currentSourceFile = result->headerName;
includeStack.push(result);
}
void pop_include()
{
TShader::Includer::IncludeResult* include = includeStack.top();
includeStack.pop();
includer.releaseInclude(include);
if (includeStack.empty()) {
currentSourceFile = rootFileName;
} else {
currentSourceFile = includeStack.top()->headerName;
}
}
bool inComment;
std::string rootFileName;
std::stack<TShader::Includer::IncludeResult*> includeStack;
std::string currentSourceFile;
std::istringstream strtodStream;
bool disableEscapeSequences;
};
} // end namespace glslang
#endif // PPCONTEXT_H
|
0 | repos/glslang.zig/glslang/glslang/MachineIndependent | repos/glslang.zig/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
// Copyright (C) 2015-2018 Google, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <climits>
#include "PpContext.h"
#include "PpTokens.h"
namespace glslang {
// Handle #define
int TPpContext::CPPdefine(TPpToken* ppToken)
{
MacroSymbol mac;
// get the macro name
int token = scanToken(ppToken);
if (token != PpAtomIdentifier) {
parseContext.ppError(ppToken->loc, "must be followed by macro name", "#define", "");
return token;
}
if (ppToken->loc.string >= 0) {
// We are in user code; check for reserved name use:
parseContext.reservedPpErrorCheck(ppToken->loc, ppToken->name, "#define");
}
// save the macro name
const int defAtom = atomStrings.getAddAtom(ppToken->name);
TSourceLoc defineLoc = ppToken->loc; // because ppToken might go to the next line before we report errors
// gather parameters to the macro, between (...)
token = scanToken(ppToken);
if (token == '(' && !ppToken->space) {
mac.functionLike = 1;
do {
token = scanToken(ppToken);
if (mac.args.size() == 0 && token == ')')
break;
if (token != PpAtomIdentifier) {
parseContext.ppError(ppToken->loc, "bad argument", "#define", "");
return token;
}
const int argAtom = atomStrings.getAddAtom(ppToken->name);
// check for duplication of parameter name
bool duplicate = false;
for (size_t a = 0; a < mac.args.size(); ++a) {
if (mac.args[a] == argAtom) {
parseContext.ppError(ppToken->loc, "duplicate macro parameter", "#define", "");
duplicate = true;
break;
}
}
if (! duplicate)
mac.args.push_back(argAtom);
token = scanToken(ppToken);
} while (token == ',');
if (token != ')') {
parseContext.ppError(ppToken->loc, "missing parenthesis", "#define", "");
return token;
}
token = scanToken(ppToken);
} else if (token != '\n' && token != EndOfInput && !ppToken->space) {
parseContext.ppWarn(ppToken->loc, "missing space after macro name", "#define", "");
return token;
}
// record the definition of the macro
while (token != '\n' && token != EndOfInput) {
mac.body.putToken(token, ppToken);
token = scanToken(ppToken);
if (token != '\n' && ppToken->space)
mac.body.putToken(' ', ppToken);
}
// check for duplicate definition
MacroSymbol* existing = lookupMacroDef(defAtom);
if (existing != nullptr) {
if (! existing->undef) {
// Already defined -- need to make sure they are identical:
// "Two replacement lists are identical if and only if the
// preprocessing tokens in both have the same number,
// ordering, spelling, and white-space separation, where all
// white-space separations are considered identical."
if (existing->functionLike != mac.functionLike) {
parseContext.ppError(defineLoc, "Macro redefined; function-like versus object-like:", "#define",
atomStrings.getString(defAtom));
} else if (existing->args.size() != mac.args.size()) {
parseContext.ppError(defineLoc, "Macro redefined; different number of arguments:", "#define",
atomStrings.getString(defAtom));
} else {
if (existing->args != mac.args) {
parseContext.ppError(defineLoc, "Macro redefined; different argument names:", "#define",
atomStrings.getString(defAtom));
}
// set up to compare the two
existing->body.reset();
mac.body.reset();
int newToken;
bool firstToken = true;
do {
int oldToken;
TPpToken oldPpToken;
TPpToken newPpToken;
oldToken = existing->body.getToken(parseContext, &oldPpToken);
newToken = mac.body.getToken(parseContext, &newPpToken);
// for the first token, preceding spaces don't matter
if (firstToken) {
newPpToken.space = oldPpToken.space;
firstToken = false;
}
if (oldToken != newToken || oldPpToken != newPpToken) {
parseContext.ppError(defineLoc, "Macro redefined; different substitutions:", "#define",
atomStrings.getString(defAtom));
break;
}
} while (newToken != EndOfInput);
}
}
*existing = mac;
} else
addMacroDef(defAtom, mac);
return '\n';
}
// Handle #undef
int TPpContext::CPPundef(TPpToken* ppToken)
{
int token = scanToken(ppToken);
if (token != PpAtomIdentifier) {
parseContext.ppError(ppToken->loc, "must be followed by macro name", "#undef", "");
return token;
}
parseContext.reservedPpErrorCheck(ppToken->loc, ppToken->name, "#undef");
MacroSymbol* macro = lookupMacroDef(atomStrings.getAtom(ppToken->name));
if (macro != nullptr)
macro->undef = 1;
token = scanToken(ppToken);
if (token != '\n')
parseContext.ppError(ppToken->loc, "can only be followed by a single macro name", "#undef", "");
return token;
}
// Handle #else
/* Skip forward to appropriate spot. This is used both
** to skip to a #endif after seeing an #else, AND to skip to a #else,
** #elif, or #endif after a #if/#ifdef/#ifndef/#elif test was false.
*/
int TPpContext::CPPelse(int matchelse, TPpToken* ppToken)
{
int depth = 0;
int token = scanToken(ppToken);
while (token != EndOfInput) {
if (token != '#') {
while (token != '\n' && token != EndOfInput)
token = scanToken(ppToken);
if (token == EndOfInput)
return token;
token = scanToken(ppToken);
continue;
}
if ((token = scanToken(ppToken)) != PpAtomIdentifier)
continue;
int nextAtom = atomStrings.getAtom(ppToken->name);
if (nextAtom == PpAtomIf || nextAtom == PpAtomIfdef || nextAtom == PpAtomIfndef) {
depth++;
if (ifdepth >= maxIfNesting || elsetracker >= maxIfNesting) {
parseContext.ppError(ppToken->loc, "maximum nesting depth exceeded", "#if/#ifdef/#ifndef", "");
return EndOfInput;
} else {
ifdepth++;
elsetracker++;
}
} else if (nextAtom == PpAtomEndif) {
token = extraTokenCheck(nextAtom, ppToken, scanToken(ppToken));
elseSeen[elsetracker] = false;
--elsetracker;
if (depth == 0) {
// found the #endif we are looking for
if (ifdepth > 0)
--ifdepth;
break;
}
--depth;
--ifdepth;
} else if (matchelse && depth == 0) {
if (nextAtom == PpAtomElse) {
elseSeen[elsetracker] = true;
token = extraTokenCheck(nextAtom, ppToken, scanToken(ppToken));
// found the #else we are looking for
break;
} else if (nextAtom == PpAtomElif) {
if (elseSeen[elsetracker])
parseContext.ppError(ppToken->loc, "#elif after #else", "#elif", "");
/* we decrement ifdepth here, because CPPif will increment
* it and we really want to leave it alone */
if (ifdepth > 0) {
--ifdepth;
elseSeen[elsetracker] = false;
--elsetracker;
}
return CPPif(ppToken);
}
} else if (nextAtom == PpAtomElse) {
if (elseSeen[elsetracker])
parseContext.ppError(ppToken->loc, "#else after #else", "#else", "");
else
elseSeen[elsetracker] = true;
token = extraTokenCheck(nextAtom, ppToken, scanToken(ppToken));
} else if (nextAtom == PpAtomElif) {
if (elseSeen[elsetracker])
parseContext.ppError(ppToken->loc, "#elif after #else", "#elif", "");
}
}
return token;
}
// Call when there should be no more tokens left on a line.
int TPpContext::extraTokenCheck(int contextAtom, TPpToken* ppToken, int token)
{
if (token != '\n' && token != EndOfInput) {
static const char* message = "unexpected tokens following directive";
const char* label;
if (contextAtom == PpAtomElse)
label = "#else";
else if (contextAtom == PpAtomElif)
label = "#elif";
else if (contextAtom == PpAtomEndif)
label = "#endif";
else if (contextAtom == PpAtomIf)
label = "#if";
else if (contextAtom == PpAtomLine)
label = "#line";
else
label = "";
if (parseContext.relaxedErrors())
parseContext.ppWarn(ppToken->loc, message, label, "");
else
parseContext.ppError(ppToken->loc, message, label, "");
while (token != '\n' && token != EndOfInput)
token = scanToken(ppToken);
}
return token;
}
enum eval_prec {
MIN_PRECEDENCE,
COND, LOGOR, LOGAND, OR, XOR, AND, EQUAL, RELATION, SHIFT, ADD, MUL, UNARY,
MAX_PRECEDENCE
};
namespace {
int op_logor(int a, int b) { return a || b; }
int op_logand(int a, int b) { return a && b; }
int op_or(int a, int b) { return a | b; }
int op_xor(int a, int b) { return a ^ b; }
int op_and(int a, int b) { return a & b; }
int op_eq(int a, int b) { return a == b; }
int op_ne(int a, int b) { return a != b; }
int op_ge(int a, int b) { return a >= b; }
int op_le(int a, int b) { return a <= b; }
int op_gt(int a, int b) { return a > b; }
int op_lt(int a, int b) { return a < b; }
int op_shl(int a, int b) { return a << b; }
int op_shr(int a, int b) { return a >> b; }
int op_add(int a, int b) { return a + b; }
int op_sub(int a, int b) { return a - b; }
int op_mul(int a, int b) { return a * b; }
int op_div(int a, int b) { return a == INT_MIN && b == -1 ? 0 : a / b; }
int op_mod(int a, int b) { return a == INT_MIN && b == -1 ? 0 : a % b; }
int op_pos(int a) { return a; }
int op_neg(int a) { return -a; }
int op_cmpl(int a) { return ~a; }
int op_not(int a) { return !a; }
struct TBinop {
int token, precedence, (*op)(int, int);
} binop[] = {
{ PpAtomOr, LOGOR, op_logor },
{ PpAtomAnd, LOGAND, op_logand },
{ '|', OR, op_or },
{ '^', XOR, op_xor },
{ '&', AND, op_and },
{ PpAtomEQ, EQUAL, op_eq },
{ PpAtomNE, EQUAL, op_ne },
{ '>', RELATION, op_gt },
{ PpAtomGE, RELATION, op_ge },
{ '<', RELATION, op_lt },
{ PpAtomLE, RELATION, op_le },
{ PpAtomLeft, SHIFT, op_shl },
{ PpAtomRight, SHIFT, op_shr },
{ '+', ADD, op_add },
{ '-', ADD, op_sub },
{ '*', MUL, op_mul },
{ '/', MUL, op_div },
{ '%', MUL, op_mod },
};
struct TUnop {
int token, (*op)(int);
} unop[] = {
{ '+', op_pos },
{ '-', op_neg },
{ '~', op_cmpl },
{ '!', op_not },
};
} // anonymous namespace
#define NUM_ELEMENTS(A) (sizeof(A) / sizeof(A[0]))
int TPpContext::eval(int token, int precedence, bool shortCircuit, int& res, bool& err, TPpToken* ppToken)
{
TSourceLoc loc = ppToken->loc; // because we sometimes read the newline before reporting the error
if (token == PpAtomIdentifier) {
if (strcmp("defined", ppToken->name) == 0) {
if (! parseContext.isReadingHLSL() && isMacroInput()) {
if (parseContext.relaxedErrors())
parseContext.ppWarn(ppToken->loc, "nonportable when expanded from macros for preprocessor expression",
"defined", "");
else
parseContext.ppError(ppToken->loc, "cannot use in preprocessor expression when expanded from macros",
"defined", "");
}
bool needclose = 0;
token = scanToken(ppToken);
if (token == '(') {
needclose = true;
token = scanToken(ppToken);
}
if (token != PpAtomIdentifier) {
parseContext.ppError(loc, "incorrect directive, expected identifier", "preprocessor evaluation", "");
err = true;
res = 0;
return token;
}
MacroSymbol* macro = lookupMacroDef(atomStrings.getAtom(ppToken->name));
res = macro != nullptr ? !macro->undef : 0;
token = scanToken(ppToken);
if (needclose) {
if (token != ')') {
parseContext.ppError(loc, "expected ')'", "preprocessor evaluation", "");
err = true;
res = 0;
return token;
}
token = scanToken(ppToken);
}
} else {
token = tokenPaste(token, *ppToken);
token = evalToToken(token, shortCircuit, res, err, ppToken);
return eval(token, precedence, shortCircuit, res, err, ppToken);
}
} else if (token == PpAtomConstInt) {
res = ppToken->ival;
token = scanToken(ppToken);
} else if (token == '(') {
token = scanToken(ppToken);
token = eval(token, MIN_PRECEDENCE, shortCircuit, res, err, ppToken);
if (! err) {
if (token != ')') {
parseContext.ppError(loc, "expected ')'", "preprocessor evaluation", "");
err = true;
res = 0;
return token;
}
token = scanToken(ppToken);
}
} else {
int op = NUM_ELEMENTS(unop) - 1;
for (; op >= 0; op--) {
if (unop[op].token == token)
break;
}
if (op >= 0) {
token = scanToken(ppToken);
token = eval(token, UNARY, shortCircuit, res, err, ppToken);
res = unop[op].op(res);
} else {
parseContext.ppError(loc, "bad expression", "preprocessor evaluation", "");
err = true;
res = 0;
return token;
}
}
token = evalToToken(token, shortCircuit, res, err, ppToken);
// Perform evaluation of binary operation, if there is one, otherwise we are done.
while (! err) {
if (token == ')' || token == '\n')
break;
int op;
for (op = NUM_ELEMENTS(binop) - 1; op >= 0; op--) {
if (binop[op].token == token)
break;
}
if (op < 0 || binop[op].precedence <= precedence)
break;
int leftSide = res;
// Setup short-circuiting, needed for ES, unless already in a short circuit.
// (Once in a short-circuit, can't turn off again, until that whole subexpression is done.
if (! shortCircuit) {
if ((token == PpAtomOr && leftSide == 1) ||
(token == PpAtomAnd && leftSide == 0))
shortCircuit = true;
}
token = scanToken(ppToken);
token = eval(token, binop[op].precedence, shortCircuit, res, err, ppToken);
if (binop[op].op == op_div || binop[op].op == op_mod) {
if (res == 0) {
parseContext.ppError(loc, "division by 0", "preprocessor evaluation", "");
res = 1;
}
}
res = binop[op].op(leftSide, res);
}
return token;
}
// Expand macros, skipping empty expansions, to get to the first real token in those expansions.
int TPpContext::evalToToken(int token, bool shortCircuit, int& res, bool& err, TPpToken* ppToken)
{
while (token == PpAtomIdentifier && strcmp("defined", ppToken->name) != 0) {
switch (MacroExpand(ppToken, true, false)) {
case MacroExpandNotStarted:
case MacroExpandError:
parseContext.ppError(ppToken->loc, "can't evaluate expression", "preprocessor evaluation", "");
err = true;
res = 0;
break;
case MacroExpandStarted:
break;
case MacroExpandUndef:
if (! shortCircuit && parseContext.isEsProfile()) {
const char* message = "undefined macro in expression not allowed in es profile";
if (parseContext.relaxedErrors())
parseContext.ppWarn(ppToken->loc, message, "preprocessor evaluation", ppToken->name);
else
parseContext.ppError(ppToken->loc, message, "preprocessor evaluation", ppToken->name);
}
break;
}
token = scanToken(ppToken);
if (err)
break;
}
return token;
}
// Handle #if
int TPpContext::CPPif(TPpToken* ppToken)
{
int token = scanToken(ppToken);
if (ifdepth >= maxIfNesting || elsetracker >= maxIfNesting) {
parseContext.ppError(ppToken->loc, "maximum nesting depth exceeded", "#if", "");
return EndOfInput;
} else {
elsetracker++;
ifdepth++;
}
int res = 0;
bool err = false;
token = eval(token, MIN_PRECEDENCE, false, res, err, ppToken);
token = extraTokenCheck(PpAtomIf, ppToken, token);
if (!res && !err)
token = CPPelse(1, ppToken);
return token;
}
// Handle #ifdef
int TPpContext::CPPifdef(int defined, TPpToken* ppToken)
{
int token = scanToken(ppToken);
if (ifdepth > maxIfNesting || elsetracker > maxIfNesting) {
parseContext.ppError(ppToken->loc, "maximum nesting depth exceeded", "#ifdef", "");
return EndOfInput;
} else {
elsetracker++;
ifdepth++;
}
if (token != PpAtomIdentifier) {
if (defined)
parseContext.ppError(ppToken->loc, "must be followed by macro name", "#ifdef", "");
else
parseContext.ppError(ppToken->loc, "must be followed by macro name", "#ifndef", "");
} else {
MacroSymbol* macro = lookupMacroDef(atomStrings.getAtom(ppToken->name));
token = scanToken(ppToken);
if (token != '\n') {
parseContext.ppError(ppToken->loc, "unexpected tokens following #ifdef directive - expected a newline", "#ifdef", "");
while (token != '\n' && token != EndOfInput)
token = scanToken(ppToken);
}
if (((macro != nullptr && !macro->undef) ? 1 : 0) != defined)
token = CPPelse(1, ppToken);
}
return token;
}
// Handle #include ...
// TODO: Handle macro expansions for the header name
int TPpContext::CPPinclude(TPpToken* ppToken)
{
const TSourceLoc directiveLoc = ppToken->loc;
bool startWithLocalSearch = true; // to additionally include the extra "" paths
int token;
// Find the first non-whitespace char after #include
int ch = getChar();
while (ch == ' ' || ch == '\t') {
ch = getChar();
}
if (ch == '<') {
// <header-name> style
startWithLocalSearch = false;
token = scanHeaderName(ppToken, '>');
} else if (ch == '"') {
// "header-name" style
token = scanHeaderName(ppToken, '"');
} else {
// unexpected, get the full token to generate the error
ungetChar();
token = scanToken(ppToken);
}
if (token != PpAtomConstString) {
parseContext.ppError(directiveLoc, "must be followed by a header name", "#include", "");
return token;
}
// Make a copy of the name because it will be overwritten by the next token scan.
const std::string filename = ppToken->name;
// See if the directive was well formed
token = scanToken(ppToken);
if (token != '\n') {
if (token == EndOfInput)
parseContext.ppError(ppToken->loc, "expected newline after header name:", "#include", "%s", filename.c_str());
else
parseContext.ppError(ppToken->loc, "extra content after header name:", "#include", "%s", filename.c_str());
return token;
}
// Process well-formed directive
// Find the inclusion, first look in "Local" ("") paths, if requested,
// otherwise, only search the "System" (<>) paths.
TShader::Includer::IncludeResult* res = nullptr;
if (startWithLocalSearch)
res = includer.includeLocal(filename.c_str(), currentSourceFile.c_str(), includeStack.size() + 1);
if (res == nullptr || res->headerName.empty()) {
includer.releaseInclude(res);
res = includer.includeSystem(filename.c_str(), currentSourceFile.c_str(), includeStack.size() + 1);
}
// Process the results
if (res != nullptr && !res->headerName.empty()) {
if (res->headerData != nullptr && res->headerLength > 0) {
// path for processing one or more tokens from an included header, hand off 'res'
const bool forNextLine = parseContext.lineDirectiveShouldSetNextLine();
std::ostringstream prologue;
std::ostringstream epilogue;
prologue << "#line " << forNextLine << " " << "\"" << res->headerName << "\"\n";
epilogue << (res->headerData[res->headerLength - 1] == '\n'? "" : "\n") <<
"#line " << directiveLoc.line + forNextLine << " " << directiveLoc.getStringNameOrNum() << "\n";
pushInput(new TokenizableIncludeFile(directiveLoc, prologue.str(), res, epilogue.str(), this));
parseContext.intermediate.addIncludeText(res->headerName.c_str(), res->headerData, res->headerLength);
// There's no "current" location anymore.
parseContext.setCurrentColumn(0);
} else {
// things are okay, but there is nothing to process
includer.releaseInclude(res);
}
} else {
// error path, clean up
std::string message =
res != nullptr ? std::string(res->headerData, res->headerLength)
: std::string("Could not process include directive");
parseContext.ppError(directiveLoc, message.c_str(), "#include", "for header name: %s", filename.c_str());
includer.releaseInclude(res);
}
return token;
}
// Handle #line
int TPpContext::CPPline(TPpToken* ppToken)
{
// "#line must have, after macro substitution, one of the following forms:
// "#line line
// "#line line source-string-number"
int token = scanToken(ppToken);
const TSourceLoc directiveLoc = ppToken->loc;
if (token == '\n') {
parseContext.ppError(ppToken->loc, "must by followed by an integral literal", "#line", "");
return token;
}
int lineRes = 0; // Line number after macro expansion.
int lineToken = 0;
bool hasFile = false;
int fileRes = 0; // Source file number after macro expansion.
const char* sourceName = nullptr; // Optional source file name.
bool lineErr = false;
bool fileErr = false;
disableEscapeSequences = true;
token = eval(token, MIN_PRECEDENCE, false, lineRes, lineErr, ppToken);
disableEscapeSequences = false;
if (! lineErr) {
lineToken = lineRes;
if (token == '\n')
++lineRes;
if (parseContext.lineDirectiveShouldSetNextLine())
--lineRes;
parseContext.setCurrentLine(lineRes);
if (token != '\n') {
if (token == PpAtomConstString) {
parseContext.ppRequireExtensions(directiveLoc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based #line");
// We need to save a copy of the string instead of pointing
// to the name field of the token since the name field
// will likely be overwritten by the next token scan.
sourceName = atomStrings.getString(atomStrings.getAddAtom(ppToken->name));
parseContext.setCurrentSourceName(sourceName);
hasFile = true;
token = scanToken(ppToken);
} else {
token = eval(token, MIN_PRECEDENCE, false, fileRes, fileErr, ppToken);
if (! fileErr) {
parseContext.setCurrentString(fileRes);
hasFile = true;
}
}
}
}
if (!fileErr && !lineErr) {
parseContext.notifyLineDirective(directiveLoc.line, lineToken, hasFile, fileRes, sourceName);
}
token = extraTokenCheck(PpAtomLine, ppToken, token);
return token;
}
// Handle #error
int TPpContext::CPPerror(TPpToken* ppToken)
{
disableEscapeSequences = true;
int token = scanToken(ppToken);
disableEscapeSequences = false;
std::string message;
TSourceLoc loc = ppToken->loc;
while (token != '\n' && token != EndOfInput) {
if (token == PpAtomConstInt16 || token == PpAtomConstUint16 ||
token == PpAtomConstInt || token == PpAtomConstUint ||
token == PpAtomConstInt64 || token == PpAtomConstUint64 ||
token == PpAtomConstFloat16 ||
token == PpAtomConstFloat || token == PpAtomConstDouble) {
message.append(ppToken->name);
} else if (token == PpAtomIdentifier || token == PpAtomConstString) {
message.append(ppToken->name);
} else {
message.append(atomStrings.getString(token));
}
message.append(" ");
token = scanToken(ppToken);
}
parseContext.notifyErrorDirective(loc.line, message.c_str());
// store this msg into the shader's information log..set the Compile Error flag!!!!
parseContext.ppError(loc, message.c_str(), "#error", "");
return '\n';
}
// Handle #pragma
int TPpContext::CPPpragma(TPpToken* ppToken)
{
char SrcStrName[2];
TVector<TString> tokens;
TSourceLoc loc = ppToken->loc; // because we go to the next line before processing
int token = scanToken(ppToken);
while (token != '\n' && token != EndOfInput) {
switch (token) {
case PpAtomIdentifier:
case PpAtomConstInt:
case PpAtomConstUint:
case PpAtomConstInt64:
case PpAtomConstUint64:
case PpAtomConstInt16:
case PpAtomConstUint16:
case PpAtomConstFloat:
case PpAtomConstDouble:
case PpAtomConstFloat16:
tokens.push_back(ppToken->name);
break;
default:
SrcStrName[0] = (char)token;
SrcStrName[1] = '\0';
tokens.push_back(SrcStrName);
}
token = scanToken(ppToken);
}
if (token == EndOfInput)
parseContext.ppError(loc, "directive must end with a newline", "#pragma", "");
else
parseContext.handlePragma(loc, tokens);
return token;
}
// #version: This is just for error checking: the version and profile are decided before preprocessing starts
int TPpContext::CPPversion(TPpToken* ppToken)
{
int token = scanToken(ppToken);
if (errorOnVersion || versionSeen) {
if (parseContext.isReadingHLSL())
parseContext.ppError(ppToken->loc, "invalid preprocessor command", "#version", "");
else
parseContext.ppError(ppToken->loc, "must occur first in shader", "#version", "");
}
versionSeen = true;
if (token == '\n') {
parseContext.ppError(ppToken->loc, "must be followed by version number", "#version", "");
return token;
}
if (token != PpAtomConstInt)
parseContext.ppError(ppToken->loc, "must be followed by version number", "#version", "");
ppToken->ival = atoi(ppToken->name);
int versionNumber = ppToken->ival;
int line = ppToken->loc.line;
token = scanToken(ppToken);
if (token == '\n') {
parseContext.notifyVersion(line, versionNumber, nullptr);
return token;
} else {
int profileAtom = atomStrings.getAtom(ppToken->name);
if (profileAtom != PpAtomCore &&
profileAtom != PpAtomCompatibility &&
profileAtom != PpAtomEs)
parseContext.ppError(ppToken->loc, "bad profile name; use es, core, or compatibility", "#version", "");
parseContext.notifyVersion(line, versionNumber, ppToken->name);
token = scanToken(ppToken);
if (token == '\n')
return token;
else
parseContext.ppError(ppToken->loc, "bad tokens following profile -- expected newline", "#version", "");
}
return token;
}
// Handle #extension
int TPpContext::CPPextension(TPpToken* ppToken)
{
int line = ppToken->loc.line;
int token = scanToken(ppToken);
char extensionName[MaxTokenLength + 1];
if (token=='\n') {
parseContext.ppError(ppToken->loc, "extension name not specified", "#extension", "");
return token;
}
if (token != PpAtomIdentifier)
parseContext.ppError(ppToken->loc, "extension name expected", "#extension", "");
snprintf(extensionName, sizeof(extensionName), "%s", ppToken->name);
token = scanToken(ppToken);
if (token != ':') {
parseContext.ppError(ppToken->loc, "':' missing after extension name", "#extension", "");
return token;
}
token = scanToken(ppToken);
if (token != PpAtomIdentifier) {
parseContext.ppError(ppToken->loc, "behavior for extension not specified", "#extension", "");
return token;
}
parseContext.updateExtensionBehavior(line, extensionName, ppToken->name);
parseContext.notifyExtensionDirective(line, extensionName, ppToken->name);
token = scanToken(ppToken);
if (token == '\n')
return token;
else
parseContext.ppError(ppToken->loc, "extra tokens -- expected newline", "#extension","");
return token;
}
int TPpContext::readCPPline(TPpToken* ppToken)
{
int token = scanToken(ppToken);
if (token == PpAtomIdentifier) {
switch (atomStrings.getAtom(ppToken->name)) {
case PpAtomDefine:
token = CPPdefine(ppToken);
break;
case PpAtomElse:
if (elseSeen[elsetracker])
parseContext.ppError(ppToken->loc, "#else after #else", "#else", "");
elseSeen[elsetracker] = true;
if (ifdepth == 0)
parseContext.ppError(ppToken->loc, "mismatched statements", "#else", "");
token = extraTokenCheck(PpAtomElse, ppToken, scanToken(ppToken));
token = CPPelse(0, ppToken);
break;
case PpAtomElif:
if (ifdepth == 0)
parseContext.ppError(ppToken->loc, "mismatched statements", "#elif", "");
if (elseSeen[elsetracker])
parseContext.ppError(ppToken->loc, "#elif after #else", "#elif", "");
// this token is really a dont care, but we still need to eat the tokens
token = scanToken(ppToken);
while (token != '\n' && token != EndOfInput)
token = scanToken(ppToken);
token = CPPelse(0, ppToken);
break;
case PpAtomEndif:
if (ifdepth == 0)
parseContext.ppError(ppToken->loc, "mismatched statements", "#endif", "");
else {
elseSeen[elsetracker] = false;
--elsetracker;
--ifdepth;
}
token = extraTokenCheck(PpAtomEndif, ppToken, scanToken(ppToken));
break;
case PpAtomIf:
token = CPPif(ppToken);
break;
case PpAtomIfdef:
token = CPPifdef(1, ppToken);
break;
case PpAtomIfndef:
token = CPPifdef(0, ppToken);
break;
case PpAtomLine:
token = CPPline(ppToken);
break;
case PpAtomInclude:
if(!parseContext.isReadingHLSL()) {
const std::array exts = { E_GL_GOOGLE_include_directive, E_GL_ARB_shading_language_include };
parseContext.ppRequireExtensions(ppToken->loc, exts, "#include");
}
token = CPPinclude(ppToken);
break;
case PpAtomPragma:
token = CPPpragma(ppToken);
break;
case PpAtomUndef:
token = CPPundef(ppToken);
break;
case PpAtomError:
token = CPPerror(ppToken);
break;
case PpAtomVersion:
token = CPPversion(ppToken);
break;
case PpAtomExtension:
token = CPPextension(ppToken);
break;
default:
parseContext.ppError(ppToken->loc, "invalid directive:", "#", ppToken->name);
break;
}
} else if (token != '\n' && token != EndOfInput)
parseContext.ppError(ppToken->loc, "invalid directive", "#", "");
while (token != '\n' && token != EndOfInput)
token = scanToken(ppToken);
return token;
}
// Context-dependent parsing of a #include <header-name>.
// Assumes no macro expansions etc. are being done; the name is just on the current input.
// Always creates a name and returns PpAtomicConstString, unless we run out of input.
int TPpContext::scanHeaderName(TPpToken* ppToken, char delimit)
{
bool tooLong = false;
if (inputStack.empty())
return EndOfInput;
int len = 0;
ppToken->name[0] = '\0';
do {
int ch = inputStack.back()->getch();
// done yet?
if (ch == delimit) {
ppToken->name[len] = '\0';
if (tooLong)
parseContext.ppError(ppToken->loc, "header name too long", "", "");
return PpAtomConstString;
} else if (ch == EndOfInput)
return EndOfInput;
// found a character to expand the name with
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
else
tooLong = true;
} while (true);
}
// Macro-expand a macro argument 'arg' to create 'expandedArg'.
// Does not replace 'arg'.
// Returns nullptr if no expanded argument is created.
TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream& arg, TPpToken* ppToken, bool newLineOkay)
{
// expand the argument
TokenStream* expandedArg = new TokenStream;
pushInput(new tMarkerInput(this));
pushTokenStreamInput(arg);
int token;
while ((token = scanToken(ppToken)) != tMarkerInput::marker && token != EndOfInput) {
token = tokenPaste(token, *ppToken);
if (token == PpAtomIdentifier) {
switch (MacroExpand(ppToken, false, newLineOkay)) {
case MacroExpandNotStarted:
break;
case MacroExpandError:
// toss the rest of the pushed-input argument by scanning until tMarkerInput
while ((token = scanToken(ppToken)) != tMarkerInput::marker && token != EndOfInput)
;
break;
case MacroExpandStarted:
case MacroExpandUndef:
continue;
}
}
if (token == tMarkerInput::marker || token == EndOfInput)
break;
expandedArg->putToken(token, ppToken);
}
if (token != tMarkerInput::marker) {
// Error, or MacroExpand ate the marker, so had bad input, recover
delete expandedArg;
expandedArg = nullptr;
}
return expandedArg;
}
//
// Return the next token for a macro expansion, handling macro arguments,
// whose semantics are dependent on being adjacent to ##.
//
int TPpContext::tMacroInput::scan(TPpToken* ppToken)
{
int token;
do {
token = mac->body.getToken(pp->parseContext, ppToken);
} while (token == ' '); // handle white space in macro
// Hash operators basically turn off a round of macro substitution
// (the round done on the argument before the round done on the RHS of the
// macro definition):
//
// "A parameter in the replacement list, unless preceded by a # or ##
// preprocessing token or followed by a ## preprocessing token (see below),
// is replaced by the corresponding argument after all macros contained
// therein have been expanded."
//
// "If, in the replacement list, a parameter is immediately preceded or
// followed by a ## preprocessing token, the parameter is replaced by the
// corresponding argument's preprocessing token sequence."
bool pasting = false;
if (postpaste) {
// don't expand next token
pasting = true;
postpaste = false;
}
if (prepaste) {
// already know we should be on a ##, verify
assert(token == PpAtomPaste);
prepaste = false;
postpaste = true;
}
// see if are preceding a ##
if (mac->body.peekUntokenizedPasting()) {
prepaste = true;
pasting = true;
}
// TODO: preprocessor: properly handle whitespace (or lack of it) between tokens when expanding
if (token == PpAtomIdentifier) {
int i;
for (i = (int)mac->args.size() - 1; i >= 0; i--)
if (strcmp(pp->atomStrings.getString(mac->args[i]), ppToken->name) == 0)
break;
if (i >= 0) {
TokenStream* arg = expandedArgs[i];
bool expanded = !!arg && !pasting;
// HLSL does expand macros before concatenation
if (arg == nullptr || (pasting && !pp->parseContext.isReadingHLSL()) ) {
arg = args[i];
}
pp->pushTokenStreamInput(*arg, prepaste, expanded);
return pp->scanToken(ppToken);
}
}
if (token == EndOfInput)
mac->busy = 0;
return token;
}
// return a textual zero, for scanning a macro that was never defined
int TPpContext::tZeroInput::scan(TPpToken* ppToken)
{
if (done)
return EndOfInput;
ppToken->name[0] = '0';
ppToken->name[1] = 0;
ppToken->ival = 0;
ppToken->space = false;
done = true;
return PpAtomConstInt;
}
//
// Check a token to see if it is a macro that should be expanded:
// - If it is, and defined, push a tInput that will produce the appropriate
// expansion and return MacroExpandStarted.
// - If it is, but undefined, and expandUndef is requested, push a tInput
// that will expand to 0 and return MacroExpandUndef.
// - Otherwise, there is no expansion, and there are two cases:
// * It might be okay there is no expansion, and no specific error was
// detected. Returns MacroExpandNotStarted.
// * The expansion was started, but could not be completed, due to an error
// that cannot be recovered from. Returns MacroExpandError.
//
MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOkay)
{
ppToken->space = false;
int macroAtom = atomStrings.getAtom(ppToken->name);
if (ppToken->fullyExpanded)
return MacroExpandNotStarted;
switch (macroAtom) {
case PpAtomLineMacro:
// Arguments which are macro have been replaced in the first stage.
if (ppToken->ival == 0)
ppToken->ival = parseContext.getCurrentLoc().line;
snprintf(ppToken->name, sizeof(ppToken->name), "%d", ppToken->ival);
UngetToken(PpAtomConstInt, ppToken);
return MacroExpandStarted;
case PpAtomFileMacro: {
if (parseContext.getCurrentLoc().name)
parseContext.ppRequireExtensions(ppToken->loc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based __FILE__");
ppToken->ival = parseContext.getCurrentLoc().string;
snprintf(ppToken->name, sizeof(ppToken->name), "%s", ppToken->loc.getStringNameOrNum().c_str());
UngetToken(PpAtomConstInt, ppToken);
return MacroExpandStarted;
}
case PpAtomVersionMacro:
ppToken->ival = parseContext.version;
snprintf(ppToken->name, sizeof(ppToken->name), "%d", ppToken->ival);
UngetToken(PpAtomConstInt, ppToken);
return MacroExpandStarted;
default:
break;
}
MacroSymbol* macro = macroAtom == 0 ? nullptr : lookupMacroDef(macroAtom);
// no recursive expansions
if (macro != nullptr && macro->busy) {
ppToken->fullyExpanded = true;
return MacroExpandNotStarted;
}
// not expanding undefined macros
if ((macro == nullptr || macro->undef) && ! expandUndef)
return MacroExpandNotStarted;
// 0 is the value of an undefined macro
if ((macro == nullptr || macro->undef) && expandUndef) {
pushInput(new tZeroInput(this));
return MacroExpandUndef;
}
tMacroInput *in = new tMacroInput(this);
TSourceLoc loc = ppToken->loc; // in case we go to the next line before discovering the error
in->mac = macro;
if (macro->functionLike) {
// We don't know yet if this will be a successful call of a
// function-like macro; need to look for a '(', but without trashing
// the passed in ppToken, until we know we are no longer speculative.
TPpToken parenToken;
int token = scanToken(&parenToken);
if (newLineOkay) {
while (token == '\n')
token = scanToken(&parenToken);
}
if (token != '(') {
// Function-like macro called with object-like syntax: okay, don't expand.
// (We ate exactly one token that might not be white space; put it back.
UngetToken(token, &parenToken);
delete in;
return MacroExpandNotStarted;
}
in->args.resize(in->mac->args.size());
for (size_t i = 0; i < in->mac->args.size(); i++)
in->args[i] = new TokenStream;
in->expandedArgs.resize(in->mac->args.size());
for (size_t i = 0; i < in->mac->args.size(); i++)
in->expandedArgs[i] = nullptr;
size_t arg = 0;
bool tokenRecorded = false;
do {
TVector<char> nestStack;
while (true) {
token = scanToken(ppToken);
if (token == EndOfInput || token == tMarkerInput::marker) {
parseContext.ppError(loc, "End of input in macro", "macro expansion", atomStrings.getString(macroAtom));
delete in;
return MacroExpandError;
}
if (token == '\n') {
if (! newLineOkay) {
parseContext.ppError(loc, "End of line in macro substitution:", "macro expansion", atomStrings.getString(macroAtom));
delete in;
return MacroExpandError;
}
continue;
}
if (token == '#') {
parseContext.ppError(ppToken->loc, "unexpected '#'", "macro expansion", atomStrings.getString(macroAtom));
delete in;
return MacroExpandError;
}
if (in->mac->args.size() == 0 && token != ')')
break;
if (nestStack.size() == 0 && (token == ',' || token == ')'))
break;
if (token == '(')
nestStack.push_back(')');
else if (token == '{' && parseContext.isReadingHLSL())
nestStack.push_back('}');
else if (nestStack.size() > 0 && token == nestStack.back())
nestStack.pop_back();
//Macro replacement list is expanded in the last stage.
if (atomStrings.getAtom(ppToken->name) == PpAtomLineMacro)
ppToken->ival = parseContext.getCurrentLoc().line;
in->args[arg]->putToken(token, ppToken);
tokenRecorded = true;
}
// end of single argument scan
if (token == ')') {
// closing paren of call
if (in->mac->args.size() == 1 && !tokenRecorded)
break;
arg++;
break;
}
arg++;
} while (arg < in->mac->args.size());
// end of all arguments scan
if (arg < in->mac->args.size())
parseContext.ppError(loc, "Too few args in Macro", "macro expansion", atomStrings.getString(macroAtom));
else if (token != ')') {
// Error recover code; find end of call, if possible
int depth = 0;
while (token != EndOfInput && (depth > 0 || token != ')')) {
if (token == ')' || token == '}')
depth--;
token = scanToken(ppToken);
if (token == '(' || token == '{')
depth++;
}
if (token == EndOfInput) {
parseContext.ppError(loc, "End of input in macro", "macro expansion", atomStrings.getString(macroAtom));
delete in;
return MacroExpandError;
}
parseContext.ppError(loc, "Too many args in macro", "macro expansion", atomStrings.getString(macroAtom));
}
// We need both expanded and non-expanded forms of the argument, for whether or
// not token pasting will be applied later when the argument is consumed next to ##.
for (size_t i = 0; i < in->mac->args.size(); i++)
in->expandedArgs[i] = PrescanMacroArg(*in->args[i], ppToken, newLineOkay);
}
pushInput(in);
macro->busy = 1;
macro->body.reset();
return MacroExpandStarted;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang/MachineIndependent | repos/glslang.zig/glslang/glslang/MachineIndependent/preprocessor/PpTokens.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
#ifndef PARSER_H
#define PARSER_H
namespace glslang {
// Multi-character tokens
enum EFixedAtoms {
// single character tokens get their own char value as their token; start here for multi-character tokens
PpAtomMaxSingle = 127,
// replace bad character tokens with this, to avoid accidental aliasing with the below
PpAtomBadToken,
// Operators
PPAtomAddAssign,
PPAtomSubAssign,
PPAtomMulAssign,
PPAtomDivAssign,
PPAtomModAssign,
PpAtomRight,
PpAtomLeft,
PpAtomRightAssign,
PpAtomLeftAssign,
PpAtomAndAssign,
PpAtomOrAssign,
PpAtomXorAssign,
PpAtomAnd,
PpAtomOr,
PpAtomXor,
PpAtomEQ,
PpAtomNE,
PpAtomGE,
PpAtomLE,
PpAtomDecrement,
PpAtomIncrement,
PpAtomColonColon,
PpAtomPaste,
// Constants
PpAtomConstInt,
PpAtomConstUint,
PpAtomConstInt64,
PpAtomConstUint64,
PpAtomConstInt16,
PpAtomConstUint16,
PpAtomConstFloat,
PpAtomConstDouble,
PpAtomConstFloat16,
PpAtomConstString,
// Identifiers
PpAtomIdentifier,
// preprocessor "keywords"
PpAtomDefine,
PpAtomUndef,
PpAtomIf,
PpAtomIfdef,
PpAtomIfndef,
PpAtomElse,
PpAtomElif,
PpAtomEndif,
PpAtomLine,
PpAtomPragma,
PpAtomError,
// #version ...
PpAtomVersion,
PpAtomCore,
PpAtomCompatibility,
PpAtomEs,
// #extension
PpAtomExtension,
// __LINE__, __FILE__, __VERSION__
PpAtomLineMacro,
PpAtomFileMacro,
PpAtomVersionMacro,
// #include
PpAtomInclude,
PpAtomLast,
};
} // end namespace glslang
#endif /* not PARSER_H */
|
0 | repos/glslang.zig/glslang/glslang/MachineIndependent | repos/glslang.zig/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
// Copyright (C) 2015-2018 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
//
// For recording and playing back the stream of tokens in a macro definition.
//
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include "PpContext.h"
#include "PpTokens.h"
namespace glslang {
// Add a token (including backing string) to the end of a macro
// token stream, for later playback.
void TPpContext::TokenStream::putToken(int atom, TPpToken* ppToken)
{
TokenStream::Token streamToken(atom, *ppToken);
stream.push_back(streamToken);
}
// Read the next token from a macro token stream.
int TPpContext::TokenStream::getToken(TParseContextBase& parseContext, TPpToken *ppToken)
{
if (atEnd())
return EndOfInput;
int atom = stream[currentPos++].get(*ppToken);
ppToken->loc = parseContext.getCurrentLoc();
// Check for ##, unless the current # is the last character
if (atom == '#') {
if (peekToken('#')) {
parseContext.requireProfile(ppToken->loc, ~EEsProfile, "token pasting (##)");
parseContext.profileRequires(ppToken->loc, ~EEsProfile, 130, nullptr, "token pasting (##)");
currentPos++;
atom = PpAtomPaste;
}
}
return atom;
}
// We are pasting if
// 1. we are preceding a pasting operator within this stream
// or
// 2. the entire macro is preceding a pasting operator (lastTokenPastes)
// and we are also on the last token
bool TPpContext::TokenStream::peekTokenizedPasting(bool lastTokenPastes)
{
// 1. preceding ##?
size_t savePos = currentPos;
// skip white space
while (peekToken(' '))
++currentPos;
if (peekToken(PpAtomPaste)) {
currentPos = savePos;
return true;
}
// 2. last token and we've been told after this there will be a ##
if (! lastTokenPastes)
return false;
// Getting here means the last token will be pasted, after this
// Are we at the last non-whitespace token?
savePos = currentPos;
bool moreTokens = false;
do {
if (atEnd())
break;
if (!peekToken(' ')) {
moreTokens = true;
break;
}
++currentPos;
} while (true);
currentPos = savePos;
return !moreTokens;
}
// See if the next non-white-space tokens are two consecutive #
bool TPpContext::TokenStream::peekUntokenizedPasting()
{
// don't return early, have to restore this
size_t savePos = currentPos;
// skip white-space
while (peekToken(' '))
++currentPos;
// check for ##
bool pasting = false;
if (peekToken('#')) {
++currentPos;
if (peekToken('#'))
pasting = true;
}
currentPos = savePos;
return pasting;
}
void TPpContext::pushTokenStreamInput(TokenStream& ts, bool prepasting, bool expanded)
{
pushInput(new tTokenInput(this, &ts, prepasting, expanded));
ts.reset();
}
int TPpContext::tUngotTokenInput::scan(TPpToken* ppToken)
{
if (done)
return EndOfInput;
int ret = token;
*ppToken = lval;
done = true;
return ret;
}
void TPpContext::UngetToken(int token, TPpToken* ppToken)
{
pushInput(new tUngotTokenInput(this, token, ppToken));
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang/MachineIndependent | repos/glslang.zig/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
// Copyright (C) 2015-2018 Google, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
#include <cstdlib>
#include <locale>
#include "PpContext.h"
namespace glslang {
TPpContext::TPpContext(TParseContextBase& pc, const std::string& rootFileName, TShader::Includer& inclr) :
preamble(nullptr), strings(nullptr), previous_token('\n'), parseContext(pc), includer(inclr), inComment(false),
rootFileName(rootFileName),
currentSourceFile(rootFileName),
disableEscapeSequences(false)
{
ifdepth = 0;
for (elsetracker = 0; elsetracker < maxIfNesting; elsetracker++)
elseSeen[elsetracker] = false;
elsetracker = 0;
strtodStream.imbue(std::locale::classic());
}
TPpContext::~TPpContext()
{
delete [] preamble;
// free up the inputStack
while (! inputStack.empty())
popInput();
}
void TPpContext::setInput(TInputScanner& input, bool versionWillBeError)
{
assert(inputStack.size() == 0);
pushInput(new tStringInput(this, input));
errorOnVersion = versionWillBeError;
versionSeen = false;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang/MachineIndependent | repos/glslang.zig/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cassert>
#include <cstdlib>
#include <cstring>
#include "PpContext.h"
#include "PpTokens.h"
namespace {
using namespace glslang;
const struct {
int val;
const char* str;
} tokens[] = {
{ PPAtomAddAssign, "+=" },
{ PPAtomSubAssign, "-=" },
{ PPAtomMulAssign, "*=" },
{ PPAtomDivAssign, "/=" },
{ PPAtomModAssign, "%=" },
{ PpAtomRight, ">>" },
{ PpAtomLeft, "<<" },
{ PpAtomAnd, "&&" },
{ PpAtomOr, "||" },
{ PpAtomXor, "^^" },
{ PpAtomRightAssign, ">>=" },
{ PpAtomLeftAssign, "<<=" },
{ PpAtomAndAssign, "&=" },
{ PpAtomOrAssign, "|=" },
{ PpAtomXorAssign, "^=" },
{ PpAtomEQ, "==" },
{ PpAtomNE, "!=" },
{ PpAtomGE, ">=" },
{ PpAtomLE, "<=" },
{ PpAtomDecrement, "--" },
{ PpAtomIncrement, "++" },
{ PpAtomColonColon, "::" },
{ PpAtomDefine, "define" },
{ PpAtomUndef, "undef" },
{ PpAtomIf, "if" },
{ PpAtomElif, "elif" },
{ PpAtomElse, "else" },
{ PpAtomEndif, "endif" },
{ PpAtomIfdef, "ifdef" },
{ PpAtomIfndef, "ifndef" },
{ PpAtomLine, "line" },
{ PpAtomPragma, "pragma" },
{ PpAtomError, "error" },
{ PpAtomVersion, "version" },
{ PpAtomCore, "core" },
{ PpAtomCompatibility, "compatibility" },
{ PpAtomEs, "es" },
{ PpAtomExtension, "extension" },
{ PpAtomLineMacro, "__LINE__" },
{ PpAtomFileMacro, "__FILE__" },
{ PpAtomVersionMacro, "__VERSION__" },
{ PpAtomInclude, "include" },
};
} // end anonymous namespace
namespace glslang {
//
// Initialize the atom table.
//
TStringAtomMap::TStringAtomMap()
{
badToken.assign("<bad token>");
// Add single character tokens to the atom table:
const char* s = "~!%^&*()-+=|,.<>/?;:[]{}#\\";
char t[2];
t[1] = '\0';
while (*s) {
t[0] = *s;
addAtomFixed(t, s[0]);
s++;
}
// Add multiple character scanner tokens :
for (size_t ii = 0; ii < sizeof(tokens)/sizeof(tokens[0]); ii++)
addAtomFixed(tokens[ii].str, tokens[ii].val);
nextAtom = PpAtomLast;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/OSDependent/osinclude.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef __OSINCLUDE_H
#define __OSINCLUDE_H
namespace glslang {
void OS_DumpMemoryCounters();
} // end namespace glslang
#endif // __OSINCLUDE_H
|
0 | repos/glslang.zig/glslang/glslang/OSDependent | repos/glslang.zig/glslang/glslang/OSDependent/Unix/ossource.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// This file contains the Linux-specific functions
//
#include "../osinclude.h"
#include <cstdio>
#if !defined(__Fuchsia__)
#include <sys/resource.h>
#endif
namespace glslang {
// #define DUMP_COUNTERS
void OS_DumpMemoryCounters()
{
#ifdef DUMP_COUNTERS
struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage) == 0)
printf("Working set size: %ld\n", usage.ru_maxrss * 1024);
#else
printf("Recompile with DUMP_COUNTERS defined to see counters.\n");
#endif
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang/OSDependent | repos/glslang.zig/glslang/glslang/OSDependent/Web/glslang.js.cpp | //
// Copyright (C) 2019 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include <cstdio>
#include <cstdint>
#include <memory>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#include "../../../SPIRV/GlslangToSpv.h"
#include "../../../glslang/Public/ShaderLang.h"
#ifndef __EMSCRIPTEN__
#define EMSCRIPTEN_KEEPALIVE
#endif
const TBuiltInResource DefaultTBuiltInResource = {
/* .MaxLights = */ 32,
/* .MaxClipPlanes = */ 6,
/* .MaxTextureUnits = */ 32,
/* .MaxTextureCoords = */ 32,
/* .MaxVertexAttribs = */ 64,
/* .MaxVertexUniformComponents = */ 4096,
/* .MaxVaryingFloats = */ 64,
/* .MaxVertexTextureImageUnits = */ 32,
/* .MaxCombinedTextureImageUnits = */ 80,
/* .MaxTextureImageUnits = */ 32,
/* .MaxFragmentUniformComponents = */ 4096,
/* .MaxDrawBuffers = */ 32,
/* .MaxVertexUniformVectors = */ 128,
/* .MaxVaryingVectors = */ 8,
/* .MaxFragmentUniformVectors = */ 16,
/* .MaxVertexOutputVectors = */ 16,
/* .MaxFragmentInputVectors = */ 15,
/* .MinProgramTexelOffset = */ -8,
/* .MaxProgramTexelOffset = */ 7,
/* .MaxClipDistances = */ 8,
/* .MaxComputeWorkGroupCountX = */ 65535,
/* .MaxComputeWorkGroupCountY = */ 65535,
/* .MaxComputeWorkGroupCountZ = */ 65535,
/* .MaxComputeWorkGroupSizeX = */ 1024,
/* .MaxComputeWorkGroupSizeY = */ 1024,
/* .MaxComputeWorkGroupSizeZ = */ 64,
/* .MaxComputeUniformComponents = */ 1024,
/* .MaxComputeTextureImageUnits = */ 16,
/* .MaxComputeImageUniforms = */ 8,
/* .MaxComputeAtomicCounters = */ 8,
/* .MaxComputeAtomicCounterBuffers = */ 1,
/* .MaxVaryingComponents = */ 60,
/* .MaxVertexOutputComponents = */ 64,
/* .MaxGeometryInputComponents = */ 64,
/* .MaxGeometryOutputComponents = */ 128,
/* .MaxFragmentInputComponents = */ 128,
/* .MaxImageUnits = */ 8,
/* .MaxCombinedImageUnitsAndFragmentOutputs = */ 8,
/* .MaxCombinedShaderOutputResources = */ 8,
/* .MaxImageSamples = */ 0,
/* .MaxVertexImageUniforms = */ 0,
/* .MaxTessControlImageUniforms = */ 0,
/* .MaxTessEvaluationImageUniforms = */ 0,
/* .MaxGeometryImageUniforms = */ 0,
/* .MaxFragmentImageUniforms = */ 8,
/* .MaxCombinedImageUniforms = */ 8,
/* .MaxGeometryTextureImageUnits = */ 16,
/* .MaxGeometryOutputVertices = */ 256,
/* .MaxGeometryTotalOutputComponents = */ 1024,
/* .MaxGeometryUniformComponents = */ 1024,
/* .MaxGeometryVaryingComponents = */ 64,
/* .MaxTessControlInputComponents = */ 128,
/* .MaxTessControlOutputComponents = */ 128,
/* .MaxTessControlTextureImageUnits = */ 16,
/* .MaxTessControlUniformComponents = */ 1024,
/* .MaxTessControlTotalOutputComponents = */ 4096,
/* .MaxTessEvaluationInputComponents = */ 128,
/* .MaxTessEvaluationOutputComponents = */ 128,
/* .MaxTessEvaluationTextureImageUnits = */ 16,
/* .MaxTessEvaluationUniformComponents = */ 1024,
/* .MaxTessPatchComponents = */ 120,
/* .MaxPatchVertices = */ 32,
/* .MaxTessGenLevel = */ 64,
/* .MaxViewports = */ 16,
/* .MaxVertexAtomicCounters = */ 0,
/* .MaxTessControlAtomicCounters = */ 0,
/* .MaxTessEvaluationAtomicCounters = */ 0,
/* .MaxGeometryAtomicCounters = */ 0,
/* .MaxFragmentAtomicCounters = */ 8,
/* .MaxCombinedAtomicCounters = */ 8,
/* .MaxAtomicCounterBindings = */ 1,
/* .MaxVertexAtomicCounterBuffers = */ 0,
/* .MaxTessControlAtomicCounterBuffers = */ 0,
/* .MaxTessEvaluationAtomicCounterBuffers = */ 0,
/* .MaxGeometryAtomicCounterBuffers = */ 0,
/* .MaxFragmentAtomicCounterBuffers = */ 1,
/* .MaxCombinedAtomicCounterBuffers = */ 1,
/* .MaxAtomicCounterBufferSize = */ 16384,
/* .MaxTransformFeedbackBuffers = */ 4,
/* .MaxTransformFeedbackInterleavedComponents = */ 64,
/* .MaxCullDistances = */ 8,
/* .MaxCombinedClipAndCullDistances = */ 8,
/* .MaxSamples = */ 4,
/* .maxMeshOutputVerticesNV = */ 256,
/* .maxMeshOutputPrimitivesNV = */ 512,
/* .maxMeshWorkGroupSizeX_NV = */ 32,
/* .maxMeshWorkGroupSizeY_NV = */ 1,
/* .maxMeshWorkGroupSizeZ_NV = */ 1,
/* .maxTaskWorkGroupSizeX_NV = */ 32,
/* .maxTaskWorkGroupSizeY_NV = */ 1,
/* .maxTaskWorkGroupSizeZ_NV = */ 1,
/* .maxMeshViewCountNV = */ 4,
/* .maxMeshOutputVerticesEXT = */ 256,
/* .maxMeshOutputPrimitivesEXT = */ 512,
/* .maxMeshWorkGroupSizeX_EXT = */ 32,
/* .maxMeshWorkGroupSizeY_EXT = */ 1,
/* .maxMeshWorkGroupSizeZ_EXT = */ 1,
/* .maxTaskWorkGroupSizeX_EXT = */ 32,
/* .maxTaskWorkGroupSizeY_EXT = */ 1,
/* .maxTaskWorkGroupSizeZ_EXT = */ 1,
/* .maxMeshViewCountEXT = */ 4,
/* .maxDualSourceDrawBuffersEXT = */ 1,
/* .limits = */ {
/* .nonInductiveForLoops = */ 1,
/* .whileLoops = */ 1,
/* .doWhileLoops = */ 1,
/* .generalUniformIndexing = */ 1,
/* .generalAttributeMatrixVectorIndexing = */ 1,
/* .generalVaryingIndexing = */ 1,
/* .generalSamplerIndexing = */ 1,
/* .generalVariableIndexing = */ 1,
/* .generalConstantMatrixVectorIndexing = */ 1,
}};
static bool initialized = false;
extern "C" {
/*
* Takes in a GLSL shader as a string and converts it to SPIR-V in binary form.
*
* |glsl| Null-terminated string containing the shader to be converted.
* |stage_int| Magic number indicating the type of shader being processed.
* Legal values are as follows:
* Vertex = 0
* Fragment = 4
* Compute = 5
* |gen_debug| Flag to indicate if debug information should be generated.
* |spirv| Output parameter for a pointer to the resulting SPIR-V data.
* |spirv_len| Output parameter for the length of the output binary buffer.
*
* Returns a void* pointer which, if not null, must be destroyed by
* destroy_output_buffer.o. (This is not the same pointer returned in |spirv|.)
* If null, the compilation failed.
*/
EMSCRIPTEN_KEEPALIVE
void* convert_glsl_to_spirv(const char* glsl,
int stage_int,
bool gen_debug,
glslang::EShTargetLanguageVersion spirv_version,
uint32_t** spirv,
size_t* spirv_len)
{
if (glsl == nullptr) {
fprintf(stderr, "Input pointer null\n");
return nullptr;
}
if (spirv == nullptr || spirv_len == nullptr) {
fprintf(stderr, "Output pointer null\n");
return nullptr;
}
*spirv = nullptr;
*spirv_len = 0;
if (stage_int != 0 && stage_int != 4 && stage_int != 5) {
fprintf(stderr, "Invalid shader stage\n");
return nullptr;
}
EShLanguage stage = static_cast<EShLanguage>(stage_int);
switch (spirv_version) {
case glslang::EShTargetSpv_1_0:
case glslang::EShTargetSpv_1_1:
case glslang::EShTargetSpv_1_2:
case glslang::EShTargetSpv_1_3:
case glslang::EShTargetSpv_1_4:
case glslang::EShTargetSpv_1_5:
break;
default:
fprintf(stderr, "Invalid SPIR-V version number\n");
return nullptr;
}
if (!initialized) {
glslang::InitializeProcess();
initialized = true;
}
glslang::TShader shader(stage);
shader.setStrings(&glsl, 1);
shader.setEnvInput(glslang::EShSourceGlsl, stage, glslang::EShClientVulkan, 100);
shader.setEnvClient(glslang::EShClientVulkan, glslang::EShTargetVulkan_1_0);
shader.setEnvTarget(glslang::EShTargetSpv, spirv_version);
if (!shader.parse(&DefaultTBuiltInResource, 100, true, EShMsgDefault)) {
fprintf(stderr, "Parse failed\n");
fprintf(stderr, "%s\n", shader.getInfoLog());
return nullptr;
}
glslang::TProgram program;
program.addShader(&shader);
if (!program.link(EShMsgDefault)) {
fprintf(stderr, "Link failed\n");
fprintf(stderr, "%s\n", program.getInfoLog());
return nullptr;
}
glslang::SpvOptions spvOptions;
spvOptions.generateDebugInfo = gen_debug;
spvOptions.optimizeSize = false;
spvOptions.disassemble = false;
spvOptions.validate = false;
std::vector<uint32_t>* output = new std::vector<uint32_t>;
glslang::GlslangToSpv(*program.getIntermediate(stage), *output, nullptr, &spvOptions);
*spirv_len = output->size();
*spirv = output->data();
return output;
}
/*
* Destroys a buffer created by convert_glsl_to_spirv
*/
EMSCRIPTEN_KEEPALIVE
void destroy_output_buffer(void* p)
{
delete static_cast<std::vector<uint32_t>*>(p);
}
} // extern "C"
/*
* For non-Emscripten builds we supply a generic main, so that the glslang.js
* build target can generate an executable with a trivial use case instead of
* generating a WASM binary. This is done so that there is a target that can be
* built and output analyzed using desktop tools, since WASM binaries are
* specific to the Emscripten toolchain.
*/
#ifndef __EMSCRIPTEN__
int main() {
const char* input = R"(#version 310 es
void main() { })";
uint32_t* output;
size_t output_len;
void* id = convert_glsl_to_spirv(input, 4, false, glslang::EShTargetSpv_1_0, &output, &output_len);
assert(output != nullptr);
assert(output_len != 0);
destroy_output_buffer(id);
return 0;
}
#endif // ifndef __EMSCRIPTEN__
|
0 | repos/glslang.zig/glslang/glslang/OSDependent | repos/glslang.zig/glslang/glslang/OSDependent/Windows/ossource.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "../osinclude.h"
#define STRICT
#define VC_EXTRALEAN 1
#include <windows.h>
#include <process.h>
#include <psapi.h>
#include <cstdio>
//
// This file contains the Window-OS-specific functions
//
#if !(defined(_WIN32) || defined(_WIN64))
#error Trying to build a windows specific file in a non windows build.
#endif
namespace glslang {
//#define DUMP_COUNTERS
void OS_DumpMemoryCounters()
{
#ifdef DUMP_COUNTERS
PROCESS_MEMORY_COUNTERS counters;
GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters));
printf("Working set size: %d\n", counters.WorkingSetSize);
#else
printf("Recompile with DUMP_COUNTERS defined to see counters.\n");
#endif
}
} // namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/ConstantUnion.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
// Copyright (C) 2017 ARM Limited.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _CONSTANT_UNION_INCLUDED_
#define _CONSTANT_UNION_INCLUDED_
#include "../Include/Common.h"
#include "../Include/BaseTypes.h"
namespace glslang {
class TConstUnion {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TConstUnion() : iConst(0), type(EbtInt) { }
void setI8Const(signed char i)
{
i8Const = i;
type = EbtInt8;
}
void setU8Const(unsigned char u)
{
u8Const = u;
type = EbtUint8;
}
void setI16Const(signed short i)
{
i16Const = i;
type = EbtInt16;
}
void setU16Const(unsigned short u)
{
u16Const = u;
type = EbtUint16;
}
void setIConst(int i)
{
iConst = i;
type = EbtInt;
}
void setUConst(unsigned int u)
{
uConst = u;
type = EbtUint;
}
void setI64Const(long long i64)
{
i64Const = i64;
type = EbtInt64;
}
void setU64Const(unsigned long long u64)
{
u64Const = u64;
type = EbtUint64;
}
void setDConst(double d)
{
dConst = d;
type = EbtDouble;
}
void setBConst(bool b)
{
bConst = b;
type = EbtBool;
}
void setSConst(const TString* s)
{
sConst = s;
type = EbtString;
}
signed char getI8Const() const { return i8Const; }
unsigned char getU8Const() const { return u8Const; }
signed short getI16Const() const { return i16Const; }
unsigned short getU16Const() const { return u16Const; }
int getIConst() const { return iConst; }
unsigned int getUConst() const { return uConst; }
long long getI64Const() const { return i64Const; }
unsigned long long getU64Const() const { return u64Const; }
double getDConst() const { return dConst; }
bool getBConst() const { return bConst; }
const TString* getSConst() const { return sConst; }
bool operator==(const signed char i) const
{
if (i == i8Const)
return true;
return false;
}
bool operator==(const unsigned char u) const
{
if (u == u8Const)
return true;
return false;
}
bool operator==(const signed short i) const
{
if (i == i16Const)
return true;
return false;
}
bool operator==(const unsigned short u) const
{
if (u == u16Const)
return true;
return false;
}
bool operator==(const int i) const
{
if (i == iConst)
return true;
return false;
}
bool operator==(const unsigned int u) const
{
if (u == uConst)
return true;
return false;
}
bool operator==(const long long i64) const
{
if (i64 == i64Const)
return true;
return false;
}
bool operator==(const unsigned long long u64) const
{
if (u64 == u64Const)
return true;
return false;
}
bool operator==(const double d) const
{
if (d == dConst)
return true;
return false;
}
bool operator==(const bool b) const
{
if (b == bConst)
return true;
return false;
}
bool operator==(const TConstUnion& constant) const
{
if (constant.type != type)
return false;
switch (type) {
case EbtInt:
if (constant.iConst == iConst)
return true;
break;
case EbtUint:
if (constant.uConst == uConst)
return true;
break;
case EbtBool:
if (constant.bConst == bConst)
return true;
break;
case EbtDouble:
if (constant.dConst == dConst)
return true;
break;
case EbtInt16:
if (constant.i16Const == i16Const)
return true;
break;
case EbtUint16:
if (constant.u16Const == u16Const)
return true;
break;
case EbtInt8:
if (constant.i8Const == i8Const)
return true;
break;
case EbtUint8:
if (constant.u8Const == u8Const)
return true;
break;
case EbtInt64:
if (constant.i64Const == i64Const)
return true;
break;
case EbtUint64:
if (constant.u64Const == u64Const)
return true;
break;
default:
assert(false && "Default missing");
}
return false;
}
bool operator!=(const signed char i) const
{
return !operator==(i);
}
bool operator!=(const unsigned char u) const
{
return !operator==(u);
}
bool operator!=(const signed short i) const
{
return !operator==(i);
}
bool operator!=(const unsigned short u) const
{
return !operator==(u);
}
bool operator!=(const int i) const
{
return !operator==(i);
}
bool operator!=(const unsigned int u) const
{
return !operator==(u);
}
bool operator!=(const long long i) const
{
return !operator==(i);
}
bool operator!=(const unsigned long long u) const
{
return !operator==(u);
}
bool operator!=(const float f) const
{
return !operator==(f);
}
bool operator!=(const bool b) const
{
return !operator==(b);
}
bool operator!=(const TConstUnion& constant) const
{
return !operator==(constant);
}
bool operator>(const TConstUnion& constant) const
{
assert(type == constant.type);
switch (type) {
case EbtInt:
if (iConst > constant.iConst)
return true;
return false;
case EbtUint:
if (uConst > constant.uConst)
return true;
return false;
case EbtDouble:
if (dConst > constant.dConst)
return true;
return false;
case EbtInt8:
if (i8Const > constant.i8Const)
return true;
return false;
case EbtUint8:
if (u8Const > constant.u8Const)
return true;
return false;
case EbtInt16:
if (i16Const > constant.i16Const)
return true;
return false;
case EbtUint16:
if (u16Const > constant.u16Const)
return true;
return false;
case EbtInt64:
if (i64Const > constant.i64Const)
return true;
return false;
case EbtUint64:
if (u64Const > constant.u64Const)
return true;
return false;
default:
assert(false && "Default missing");
return false;
}
}
bool operator<(const TConstUnion& constant) const
{
assert(type == constant.type);
switch (type) {
case EbtInt8:
if (i8Const < constant.i8Const)
return true;
return false;
case EbtUint8:
if (u8Const < constant.u8Const)
return true;
return false;
case EbtInt16:
if (i16Const < constant.i16Const)
return true;
return false;
case EbtUint16:
if (u16Const < constant.u16Const)
return true;
return false;
case EbtInt64:
if (i64Const < constant.i64Const)
return true;
return false;
case EbtUint64:
if (u64Const < constant.u64Const)
return true;
return false;
case EbtDouble:
if (dConst < constant.dConst)
return true;
return false;
case EbtInt:
if (iConst < constant.iConst)
return true;
return false;
case EbtUint:
if (uConst < constant.uConst)
return true;
return false;
default:
assert(false && "Default missing");
return false;
}
}
TConstUnion operator+(const TConstUnion& constant) const
{
TConstUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
case EbtUint: returnValue.setUConst(uConst + constant.uConst); break;
case EbtDouble: returnValue.setDConst(dConst + constant.dConst); break;
case EbtInt8: returnValue.setI8Const(i8Const + constant.i8Const); break;
case EbtInt16: returnValue.setI16Const(i16Const + constant.i16Const); break;
case EbtInt64: returnValue.setI64Const(i64Const + constant.i64Const); break;
case EbtUint8: returnValue.setU8Const(u8Const + constant.u8Const); break;
case EbtUint16: returnValue.setU16Const(u16Const + constant.u16Const); break;
case EbtUint64: returnValue.setU64Const(u64Const + constant.u64Const); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator-(const TConstUnion& constant) const
{
TConstUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
case EbtUint: returnValue.setUConst(uConst - constant.uConst); break;
case EbtDouble: returnValue.setDConst(dConst - constant.dConst); break;
case EbtInt8: returnValue.setI8Const(i8Const - constant.i8Const); break;
case EbtInt16: returnValue.setI16Const(i16Const - constant.i16Const); break;
case EbtInt64: returnValue.setI64Const(i64Const - constant.i64Const); break;
case EbtUint8: returnValue.setU8Const(u8Const - constant.u8Const); break;
case EbtUint16: returnValue.setU16Const(u16Const - constant.u16Const); break;
case EbtUint64: returnValue.setU64Const(u64Const - constant.u64Const); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator*(const TConstUnion& constant) const
{
TConstUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
case EbtUint: returnValue.setUConst(uConst * constant.uConst); break;
case EbtDouble: returnValue.setDConst(dConst * constant.dConst); break;
case EbtInt8: returnValue.setI8Const(i8Const * constant.i8Const); break;
case EbtInt16: returnValue.setI16Const(i16Const * constant.i16Const); break;
case EbtInt64: returnValue.setI64Const(i64Const * constant.i64Const); break;
case EbtUint8: returnValue.setU8Const(u8Const * constant.u8Const); break;
case EbtUint16: returnValue.setU16Const(u16Const * constant.u16Const); break;
case EbtUint64: returnValue.setU64Const(u64Const * constant.u64Const); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator%(const TConstUnion& constant) const
{
TConstUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
case EbtUint: returnValue.setUConst(uConst % constant.uConst); break;
case EbtInt8: returnValue.setI8Const(i8Const % constant.i8Const); break;
case EbtInt16: returnValue.setI16Const(i16Const % constant.i16Const); break;
case EbtInt64: returnValue.setI64Const(i64Const % constant.i64Const); break;
case EbtUint8: returnValue.setU8Const(u8Const % constant.u8Const); break;
case EbtUint16: returnValue.setU16Const(u16Const % constant.u16Const); break;
case EbtUint64: returnValue.setU64Const(u64Const % constant.u64Const); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator>>(const TConstUnion& constant) const
{
TConstUnion returnValue;
switch (type) {
case EbtInt8:
switch (constant.type) {
case EbtInt8: returnValue.setI8Const(i8Const >> constant.i8Const); break;
case EbtUint8: returnValue.setI8Const(i8Const >> constant.u8Const); break;
case EbtInt16: returnValue.setI8Const(i8Const >> constant.i16Const); break;
case EbtUint16: returnValue.setI8Const(i8Const >> constant.u16Const); break;
case EbtInt: returnValue.setI8Const(i8Const >> constant.iConst); break;
case EbtUint: returnValue.setI8Const(i8Const >> constant.uConst); break;
case EbtInt64: returnValue.setI8Const(i8Const >> constant.i64Const); break;
case EbtUint64: returnValue.setI8Const(i8Const >> constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtUint8:
switch (constant.type) {
case EbtInt8: returnValue.setU8Const(u8Const >> constant.i8Const); break;
case EbtUint8: returnValue.setU8Const(u8Const >> constant.u8Const); break;
case EbtInt16: returnValue.setU8Const(u8Const >> constant.i16Const); break;
case EbtUint16: returnValue.setU8Const(u8Const >> constant.u16Const); break;
case EbtInt: returnValue.setU8Const(u8Const >> constant.iConst); break;
case EbtUint: returnValue.setU8Const(u8Const >> constant.uConst); break;
case EbtInt64: returnValue.setU8Const(u8Const >> constant.i64Const); break;
case EbtUint64: returnValue.setU8Const(u8Const >> constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtInt16:
switch (constant.type) {
case EbtInt8: returnValue.setI16Const(i16Const >> constant.i8Const); break;
case EbtUint8: returnValue.setI16Const(i16Const >> constant.u8Const); break;
case EbtInt16: returnValue.setI16Const(i16Const >> constant.i16Const); break;
case EbtUint16: returnValue.setI16Const(i16Const >> constant.u16Const); break;
case EbtInt: returnValue.setI16Const(i16Const >> constant.iConst); break;
case EbtUint: returnValue.setI16Const(i16Const >> constant.uConst); break;
case EbtInt64: returnValue.setI16Const(i16Const >> constant.i64Const); break;
case EbtUint64: returnValue.setI16Const(i16Const >> constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtUint16:
switch (constant.type) {
case EbtInt8: returnValue.setU16Const(u16Const >> constant.i8Const); break;
case EbtUint8: returnValue.setU16Const(u16Const >> constant.u8Const); break;
case EbtInt16: returnValue.setU16Const(u16Const >> constant.i16Const); break;
case EbtUint16: returnValue.setU16Const(u16Const >> constant.u16Const); break;
case EbtInt: returnValue.setU16Const(u16Const >> constant.iConst); break;
case EbtUint: returnValue.setU16Const(u16Const >> constant.uConst); break;
case EbtInt64: returnValue.setU16Const(u16Const >> constant.i64Const); break;
case EbtUint64: returnValue.setU16Const(u16Const >> constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtInt:
switch (constant.type) {
case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
case EbtUint: returnValue.setIConst(iConst >> constant.uConst); break;
case EbtInt8: returnValue.setIConst(iConst >> constant.i8Const); break;
case EbtUint8: returnValue.setIConst(iConst >> constant.u8Const); break;
case EbtInt16: returnValue.setIConst(iConst >> constant.i16Const); break;
case EbtUint16: returnValue.setIConst(iConst >> constant.u16Const); break;
case EbtInt64: returnValue.setIConst(iConst >> constant.i64Const); break;
case EbtUint64: returnValue.setIConst(iConst >> constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtUint:
switch (constant.type) {
case EbtInt: returnValue.setUConst(uConst >> constant.iConst); break;
case EbtUint: returnValue.setUConst(uConst >> constant.uConst); break;
case EbtInt8: returnValue.setUConst(uConst >> constant.i8Const); break;
case EbtUint8: returnValue.setUConst(uConst >> constant.u8Const); break;
case EbtInt16: returnValue.setUConst(uConst >> constant.i16Const); break;
case EbtUint16: returnValue.setUConst(uConst >> constant.u16Const); break;
case EbtInt64: returnValue.setUConst(uConst >> constant.i64Const); break;
case EbtUint64: returnValue.setUConst(uConst >> constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtInt64:
switch (constant.type) {
case EbtInt8: returnValue.setI64Const(i64Const >> constant.i8Const); break;
case EbtUint8: returnValue.setI64Const(i64Const >> constant.u8Const); break;
case EbtInt16: returnValue.setI64Const(i64Const >> constant.i16Const); break;
case EbtUint16: returnValue.setI64Const(i64Const >> constant.u16Const); break;
case EbtInt: returnValue.setI64Const(i64Const >> constant.iConst); break;
case EbtUint: returnValue.setI64Const(i64Const >> constant.uConst); break;
case EbtInt64: returnValue.setI64Const(i64Const >> constant.i64Const); break;
case EbtUint64: returnValue.setI64Const(i64Const >> constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtUint64:
switch (constant.type) {
case EbtInt8: returnValue.setU64Const(u64Const >> constant.i8Const); break;
case EbtUint8: returnValue.setU64Const(u64Const >> constant.u8Const); break;
case EbtInt16: returnValue.setU64Const(u64Const >> constant.i16Const); break;
case EbtUint16: returnValue.setU64Const(u64Const >> constant.u16Const); break;
case EbtInt: returnValue.setU64Const(u64Const >> constant.iConst); break;
case EbtUint: returnValue.setU64Const(u64Const >> constant.uConst); break;
case EbtInt64: returnValue.setU64Const(u64Const >> constant.i64Const); break;
case EbtUint64: returnValue.setU64Const(u64Const >> constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator<<(const TConstUnion& constant) const
{
TConstUnion returnValue;
switch (type) {
case EbtInt8:
switch (constant.type) {
case EbtInt8: returnValue.setI8Const(i8Const << constant.i8Const); break;
case EbtUint8: returnValue.setI8Const(i8Const << constant.u8Const); break;
case EbtInt16: returnValue.setI8Const(i8Const << constant.i16Const); break;
case EbtUint16: returnValue.setI8Const(i8Const << constant.u16Const); break;
case EbtInt: returnValue.setI8Const(i8Const << constant.iConst); break;
case EbtUint: returnValue.setI8Const(i8Const << constant.uConst); break;
case EbtInt64: returnValue.setI8Const(i8Const << constant.i64Const); break;
case EbtUint64: returnValue.setI8Const(i8Const << constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtUint8:
switch (constant.type) {
case EbtInt8: returnValue.setU8Const(u8Const << constant.i8Const); break;
case EbtUint8: returnValue.setU8Const(u8Const << constant.u8Const); break;
case EbtInt16: returnValue.setU8Const(u8Const << constant.i16Const); break;
case EbtUint16: returnValue.setU8Const(u8Const << constant.u16Const); break;
case EbtInt: returnValue.setU8Const(u8Const << constant.iConst); break;
case EbtUint: returnValue.setU8Const(u8Const << constant.uConst); break;
case EbtInt64: returnValue.setU8Const(u8Const << constant.i64Const); break;
case EbtUint64: returnValue.setU8Const(u8Const << constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtInt16:
switch (constant.type) {
case EbtInt8: returnValue.setI16Const(i16Const << constant.i8Const); break;
case EbtUint8: returnValue.setI16Const(i16Const << constant.u8Const); break;
case EbtInt16: returnValue.setI16Const(i16Const << constant.i16Const); break;
case EbtUint16: returnValue.setI16Const(i16Const << constant.u16Const); break;
case EbtInt: returnValue.setI16Const(i16Const << constant.iConst); break;
case EbtUint: returnValue.setI16Const(i16Const << constant.uConst); break;
case EbtInt64: returnValue.setI16Const(i16Const << constant.i64Const); break;
case EbtUint64: returnValue.setI16Const(i16Const << constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtUint16:
switch (constant.type) {
case EbtInt8: returnValue.setU16Const(u16Const << constant.i8Const); break;
case EbtUint8: returnValue.setU16Const(u16Const << constant.u8Const); break;
case EbtInt16: returnValue.setU16Const(u16Const << constant.i16Const); break;
case EbtUint16: returnValue.setU16Const(u16Const << constant.u16Const); break;
case EbtInt: returnValue.setU16Const(u16Const << constant.iConst); break;
case EbtUint: returnValue.setU16Const(u16Const << constant.uConst); break;
case EbtInt64: returnValue.setU16Const(u16Const << constant.i64Const); break;
case EbtUint64: returnValue.setU16Const(u16Const << constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtInt64:
switch (constant.type) {
case EbtInt8: returnValue.setI64Const(i64Const << constant.i8Const); break;
case EbtUint8: returnValue.setI64Const(i64Const << constant.u8Const); break;
case EbtInt16: returnValue.setI64Const(i64Const << constant.i16Const); break;
case EbtUint16: returnValue.setI64Const(i64Const << constant.u16Const); break;
case EbtInt: returnValue.setI64Const(i64Const << constant.iConst); break;
case EbtUint: returnValue.setI64Const(i64Const << constant.uConst); break;
case EbtInt64: returnValue.setI64Const(i64Const << constant.i64Const); break;
case EbtUint64: returnValue.setI64Const(i64Const << constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtUint64:
switch (constant.type) {
case EbtInt8: returnValue.setU64Const(u64Const << constant.i8Const); break;
case EbtUint8: returnValue.setU64Const(u64Const << constant.u8Const); break;
case EbtInt16: returnValue.setU64Const(u64Const << constant.i16Const); break;
case EbtUint16: returnValue.setU64Const(u64Const << constant.u16Const); break;
case EbtInt: returnValue.setU64Const(u64Const << constant.iConst); break;
case EbtUint: returnValue.setU64Const(u64Const << constant.uConst); break;
case EbtInt64: returnValue.setU64Const(u64Const << constant.i64Const); break;
case EbtUint64: returnValue.setU64Const(u64Const << constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtInt:
switch (constant.type) {
case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
case EbtUint: returnValue.setIConst(iConst << constant.uConst); break;
case EbtInt8: returnValue.setIConst(iConst << constant.i8Const); break;
case EbtUint8: returnValue.setIConst(iConst << constant.u8Const); break;
case EbtInt16: returnValue.setIConst(iConst << constant.i16Const); break;
case EbtUint16: returnValue.setIConst(iConst << constant.u16Const); break;
case EbtInt64: returnValue.setIConst(iConst << constant.i64Const); break;
case EbtUint64: returnValue.setIConst(iConst << constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
case EbtUint:
switch (constant.type) {
case EbtInt: returnValue.setUConst(uConst << constant.iConst); break;
case EbtUint: returnValue.setUConst(uConst << constant.uConst); break;
case EbtInt8: returnValue.setUConst(uConst << constant.i8Const); break;
case EbtUint8: returnValue.setUConst(uConst << constant.u8Const); break;
case EbtInt16: returnValue.setUConst(uConst << constant.i16Const); break;
case EbtUint16: returnValue.setUConst(uConst << constant.u16Const); break;
case EbtInt64: returnValue.setUConst(uConst << constant.i64Const); break;
case EbtUint64: returnValue.setUConst(uConst << constant.u64Const); break;
default: assert(false && "Default missing");
}
break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator&(const TConstUnion& constant) const
{
TConstUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst & constant.iConst); break;
case EbtUint: returnValue.setUConst(uConst & constant.uConst); break;
case EbtInt8: returnValue.setI8Const(i8Const & constant.i8Const); break;
case EbtUint8: returnValue.setU8Const(u8Const & constant.u8Const); break;
case EbtInt16: returnValue.setI16Const(i16Const & constant.i16Const); break;
case EbtUint16: returnValue.setU16Const(u16Const & constant.u16Const); break;
case EbtInt64: returnValue.setI64Const(i64Const & constant.i64Const); break;
case EbtUint64: returnValue.setU64Const(u64Const & constant.u64Const); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator|(const TConstUnion& constant) const
{
TConstUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst | constant.iConst); break;
case EbtUint: returnValue.setUConst(uConst | constant.uConst); break;
case EbtInt8: returnValue.setI8Const(i8Const | constant.i8Const); break;
case EbtUint8: returnValue.setU8Const(u8Const | constant.u8Const); break;
case EbtInt16: returnValue.setI16Const(i16Const | constant.i16Const); break;
case EbtUint16: returnValue.setU16Const(u16Const | constant.u16Const); break;
case EbtInt64: returnValue.setI64Const(i64Const | constant.i64Const); break;
case EbtUint64: returnValue.setU64Const(u64Const | constant.u64Const); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator^(const TConstUnion& constant) const
{
TConstUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst ^ constant.iConst); break;
case EbtUint: returnValue.setUConst(uConst ^ constant.uConst); break;
case EbtInt8: returnValue.setI8Const(i8Const ^ constant.i8Const); break;
case EbtUint8: returnValue.setU8Const(u8Const ^ constant.u8Const); break;
case EbtInt16: returnValue.setI16Const(i16Const ^ constant.i16Const); break;
case EbtUint16: returnValue.setU16Const(u16Const ^ constant.u16Const); break;
case EbtInt64: returnValue.setI64Const(i64Const ^ constant.i64Const); break;
case EbtUint64: returnValue.setU64Const(u64Const ^ constant.u64Const); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator~() const
{
TConstUnion returnValue;
switch (type) {
case EbtInt: returnValue.setIConst(~iConst); break;
case EbtUint: returnValue.setUConst(~uConst); break;
case EbtInt8: returnValue.setI8Const(~i8Const); break;
case EbtUint8: returnValue.setU8Const(~u8Const); break;
case EbtInt16: returnValue.setI16Const(~i16Const); break;
case EbtUint16: returnValue.setU16Const(~u16Const); break;
case EbtInt64: returnValue.setI64Const(~i64Const); break;
case EbtUint64: returnValue.setU64Const(~u64Const); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator&&(const TConstUnion& constant) const
{
TConstUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TConstUnion operator||(const TConstUnion& constant) const
{
TConstUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TBasicType getType() const { return type; }
private:
union {
signed char i8Const; // used for i8vec, scalar int8s
unsigned char u8Const; // used for u8vec, scalar uint8s
signed short i16Const; // used for i16vec, scalar int16s
unsigned short u16Const; // used for u16vec, scalar uint16s
int iConst; // used for ivec, scalar ints
unsigned int uConst; // used for uvec, scalar uints
long long i64Const; // used for i64vec, scalar int64s
unsigned long long u64Const; // used for u64vec, scalar uint64s
bool bConst; // used for bvec, scalar bools
double dConst; // used for vec, dvec, mat, dmat, scalar floats and doubles
const TString* sConst; // string constant
};
TBasicType type;
};
// Encapsulate having a pointer to an array of TConstUnion,
// which only needs to be allocated if its size is going to be
// bigger than 0.
//
// One convenience is being able to use [] to go inside the array, instead
// of C++ assuming it as an array of pointers to vectors.
//
// General usage is that the size is known up front, and it is
// created once with the proper size.
//
class TConstUnionArray {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TConstUnionArray() : unionArray(nullptr) { }
virtual ~TConstUnionArray() { }
explicit TConstUnionArray(int size)
{
if (size == 0)
unionArray = nullptr;
else
unionArray = new TConstUnionVector(size);
}
TConstUnionArray(const TConstUnionArray& a) = default;
TConstUnionArray(const TConstUnionArray& a, int start, int size)
{
unionArray = new TConstUnionVector(size);
for (int i = 0; i < size; ++i)
(*unionArray)[i] = a[start + i];
}
// Use this constructor for a smear operation
TConstUnionArray(int size, const TConstUnion& val)
{
unionArray = new TConstUnionVector(size, val);
}
int size() const { return unionArray ? (int)unionArray->size() : 0; }
TConstUnion& operator[](size_t index) { return (*unionArray)[index]; }
const TConstUnion& operator[](size_t index) const { return (*unionArray)[index]; }
bool operator==(const TConstUnionArray& rhs) const
{
// this includes the case that both are unallocated
if (unionArray == rhs.unionArray)
return true;
if (! unionArray || ! rhs.unionArray)
return false;
return *unionArray == *rhs.unionArray;
}
bool operator!=(const TConstUnionArray& rhs) const { return ! operator==(rhs); }
double dot(const TConstUnionArray& rhs)
{
assert(rhs.unionArray->size() == unionArray->size());
double sum = 0.0;
for (size_t comp = 0; comp < unionArray->size(); ++comp)
sum += (*this)[comp].getDConst() * rhs[comp].getDConst();
return sum;
}
bool empty() const { return unionArray == nullptr; }
protected:
typedef TVector<TConstUnion> TConstUnionVector;
TConstUnionVector* unionArray;
};
} // end namespace glslang
#endif // _CONSTANT_UNION_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/intermediate.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2016 LunarG, Inc.
// Copyright (C) 2017, 2022-2024 Arm Limited.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Definition of the in-memory high-level intermediate representation
// of shaders. This is a tree that parser creates.
//
// Nodes in the tree are defined as a hierarchy of classes derived from
// TIntermNode. Each is a node in a tree. There is no preset branching factor;
// each node can have it's own type of list of children.
//
#ifndef __INTERMEDIATE_H
#define __INTERMEDIATE_H
#include "Common.h"
#include "Types.h"
#include "ConstantUnion.h"
namespace glslang {
class TIntermediate;
//
// Operators used by the high-level (parse tree) representation.
//
enum TOperator {
EOpNull, // if in a node, should only mean a node is still being built
EOpSequence, // denotes a list of statements, or parameters, etc.
EOpScope, // Used by debugging to denote a scoped list of statements
EOpLinkerObjects, // for aggregate node of objects the linker may need, if not reference by the rest of the AST
EOpFunctionCall,
EOpFunction, // For function definition
EOpParameters, // an aggregate listing the parameters to a function
EOpSpirvInst,
//
// Unary operators
//
EOpNegative,
EOpLogicalNot,
EOpVectorLogicalNot,
EOpBitwiseNot,
EOpPostIncrement,
EOpPostDecrement,
EOpPreIncrement,
EOpPreDecrement,
EOpCopyObject,
EOpDeclare, // Used by debugging to force declaration of variable in correct scope
// (u)int* -> bool
EOpConvInt8ToBool,
EOpConvUint8ToBool,
EOpConvInt16ToBool,
EOpConvUint16ToBool,
EOpConvIntToBool,
EOpConvUintToBool,
EOpConvInt64ToBool,
EOpConvUint64ToBool,
// float* -> bool
EOpConvFloat16ToBool,
EOpConvFloatToBool,
EOpConvDoubleToBool,
// bool -> (u)int*
EOpConvBoolToInt8,
EOpConvBoolToUint8,
EOpConvBoolToInt16,
EOpConvBoolToUint16,
EOpConvBoolToInt,
EOpConvBoolToUint,
EOpConvBoolToInt64,
EOpConvBoolToUint64,
// bool -> float*
EOpConvBoolToFloat16,
EOpConvBoolToFloat,
EOpConvBoolToDouble,
// int8_t -> (u)int*
EOpConvInt8ToInt16,
EOpConvInt8ToInt,
EOpConvInt8ToInt64,
EOpConvInt8ToUint8,
EOpConvInt8ToUint16,
EOpConvInt8ToUint,
EOpConvInt8ToUint64,
// uint8_t -> (u)int*
EOpConvUint8ToInt8,
EOpConvUint8ToInt16,
EOpConvUint8ToInt,
EOpConvUint8ToInt64,
EOpConvUint8ToUint16,
EOpConvUint8ToUint,
EOpConvUint8ToUint64,
// int8_t -> float*
EOpConvInt8ToFloat16,
EOpConvInt8ToFloat,
EOpConvInt8ToDouble,
// uint8_t -> float*
EOpConvUint8ToFloat16,
EOpConvUint8ToFloat,
EOpConvUint8ToDouble,
// int16_t -> (u)int*
EOpConvInt16ToInt8,
EOpConvInt16ToInt,
EOpConvInt16ToInt64,
EOpConvInt16ToUint8,
EOpConvInt16ToUint16,
EOpConvInt16ToUint,
EOpConvInt16ToUint64,
// uint16_t -> (u)int*
EOpConvUint16ToInt8,
EOpConvUint16ToInt16,
EOpConvUint16ToInt,
EOpConvUint16ToInt64,
EOpConvUint16ToUint8,
EOpConvUint16ToUint,
EOpConvUint16ToUint64,
// int16_t -> float*
EOpConvInt16ToFloat16,
EOpConvInt16ToFloat,
EOpConvInt16ToDouble,
// uint16_t -> float*
EOpConvUint16ToFloat16,
EOpConvUint16ToFloat,
EOpConvUint16ToDouble,
// int32_t -> (u)int*
EOpConvIntToInt8,
EOpConvIntToInt16,
EOpConvIntToInt64,
EOpConvIntToUint8,
EOpConvIntToUint16,
EOpConvIntToUint,
EOpConvIntToUint64,
// uint32_t -> (u)int*
EOpConvUintToInt8,
EOpConvUintToInt16,
EOpConvUintToInt,
EOpConvUintToInt64,
EOpConvUintToUint8,
EOpConvUintToUint16,
EOpConvUintToUint64,
// int32_t -> float*
EOpConvIntToFloat16,
EOpConvIntToFloat,
EOpConvIntToDouble,
// uint32_t -> float*
EOpConvUintToFloat16,
EOpConvUintToFloat,
EOpConvUintToDouble,
// int64_t -> (u)int*
EOpConvInt64ToInt8,
EOpConvInt64ToInt16,
EOpConvInt64ToInt,
EOpConvInt64ToUint8,
EOpConvInt64ToUint16,
EOpConvInt64ToUint,
EOpConvInt64ToUint64,
// uint64_t -> (u)int*
EOpConvUint64ToInt8,
EOpConvUint64ToInt16,
EOpConvUint64ToInt,
EOpConvUint64ToInt64,
EOpConvUint64ToUint8,
EOpConvUint64ToUint16,
EOpConvUint64ToUint,
// int64_t -> float*
EOpConvInt64ToFloat16,
EOpConvInt64ToFloat,
EOpConvInt64ToDouble,
// uint64_t -> float*
EOpConvUint64ToFloat16,
EOpConvUint64ToFloat,
EOpConvUint64ToDouble,
// float16_t -> (u)int*
EOpConvFloat16ToInt8,
EOpConvFloat16ToInt16,
EOpConvFloat16ToInt,
EOpConvFloat16ToInt64,
EOpConvFloat16ToUint8,
EOpConvFloat16ToUint16,
EOpConvFloat16ToUint,
EOpConvFloat16ToUint64,
// float16_t -> float*
EOpConvFloat16ToFloat,
EOpConvFloat16ToDouble,
// float -> (u)int*
EOpConvFloatToInt8,
EOpConvFloatToInt16,
EOpConvFloatToInt,
EOpConvFloatToInt64,
EOpConvFloatToUint8,
EOpConvFloatToUint16,
EOpConvFloatToUint,
EOpConvFloatToUint64,
// float -> float*
EOpConvFloatToFloat16,
EOpConvFloatToDouble,
// float64 _t-> (u)int*
EOpConvDoubleToInt8,
EOpConvDoubleToInt16,
EOpConvDoubleToInt,
EOpConvDoubleToInt64,
EOpConvDoubleToUint8,
EOpConvDoubleToUint16,
EOpConvDoubleToUint,
EOpConvDoubleToUint64,
// float64_t -> float*
EOpConvDoubleToFloat16,
EOpConvDoubleToFloat,
// uint64_t <-> pointer
EOpConvUint64ToPtr,
EOpConvPtrToUint64,
// uvec2 <-> pointer
EOpConvUvec2ToPtr,
EOpConvPtrToUvec2,
// uint64_t -> accelerationStructureEXT
EOpConvUint64ToAccStruct,
// uvec2 -> accelerationStructureEXT
EOpConvUvec2ToAccStruct,
//
// binary operations
//
EOpAdd,
EOpSub,
EOpMul,
EOpDiv,
EOpMod,
EOpRightShift,
EOpLeftShift,
EOpAnd,
EOpInclusiveOr,
EOpExclusiveOr,
EOpEqual,
EOpNotEqual,
EOpVectorEqual,
EOpVectorNotEqual,
EOpLessThan,
EOpGreaterThan,
EOpLessThanEqual,
EOpGreaterThanEqual,
EOpComma,
EOpVectorTimesScalar,
EOpVectorTimesMatrix,
EOpMatrixTimesVector,
EOpMatrixTimesScalar,
EOpLogicalOr,
EOpLogicalXor,
EOpLogicalAnd,
EOpIndexDirect,
EOpIndexIndirect,
EOpIndexDirectStruct,
EOpVectorSwizzle,
EOpMethod,
EOpScoping,
//
// Built-in functions mapped to operators
//
EOpRadians,
EOpDegrees,
EOpSin,
EOpCos,
EOpTan,
EOpAsin,
EOpAcos,
EOpAtan,
EOpSinh,
EOpCosh,
EOpTanh,
EOpAsinh,
EOpAcosh,
EOpAtanh,
EOpPow,
EOpExp,
EOpLog,
EOpExp2,
EOpLog2,
EOpSqrt,
EOpInverseSqrt,
EOpAbs,
EOpSign,
EOpFloor,
EOpTrunc,
EOpRound,
EOpRoundEven,
EOpCeil,
EOpFract,
EOpModf,
EOpMin,
EOpMax,
EOpClamp,
EOpMix,
EOpStep,
EOpSmoothStep,
EOpIsNan,
EOpIsInf,
EOpFma,
EOpFrexp,
EOpLdexp,
EOpFloatBitsToInt,
EOpFloatBitsToUint,
EOpIntBitsToFloat,
EOpUintBitsToFloat,
EOpDoubleBitsToInt64,
EOpDoubleBitsToUint64,
EOpInt64BitsToDouble,
EOpUint64BitsToDouble,
EOpFloat16BitsToInt16,
EOpFloat16BitsToUint16,
EOpInt16BitsToFloat16,
EOpUint16BitsToFloat16,
EOpPackSnorm2x16,
EOpUnpackSnorm2x16,
EOpPackUnorm2x16,
EOpUnpackUnorm2x16,
EOpPackSnorm4x8,
EOpUnpackSnorm4x8,
EOpPackUnorm4x8,
EOpUnpackUnorm4x8,
EOpPackHalf2x16,
EOpUnpackHalf2x16,
EOpPackDouble2x32,
EOpUnpackDouble2x32,
EOpPackInt2x32,
EOpUnpackInt2x32,
EOpPackUint2x32,
EOpUnpackUint2x32,
EOpPackFloat2x16,
EOpUnpackFloat2x16,
EOpPackInt2x16,
EOpUnpackInt2x16,
EOpPackUint2x16,
EOpUnpackUint2x16,
EOpPackInt4x16,
EOpUnpackInt4x16,
EOpPackUint4x16,
EOpUnpackUint4x16,
EOpPack16,
EOpPack32,
EOpPack64,
EOpUnpack32,
EOpUnpack16,
EOpUnpack8,
EOpLength,
EOpDistance,
EOpDot,
EOpCross,
EOpNormalize,
EOpFaceForward,
EOpReflect,
EOpRefract,
EOpMin3,
EOpMax3,
EOpMid3,
EOpDPdx, // Fragment only
EOpDPdy, // Fragment only
EOpFwidth, // Fragment only
EOpDPdxFine, // Fragment only
EOpDPdyFine, // Fragment only
EOpFwidthFine, // Fragment only
EOpDPdxCoarse, // Fragment only
EOpDPdyCoarse, // Fragment only
EOpFwidthCoarse, // Fragment only
EOpInterpolateAtCentroid, // Fragment only
EOpInterpolateAtSample, // Fragment only
EOpInterpolateAtOffset, // Fragment only
EOpInterpolateAtVertex,
EOpMatrixTimesMatrix,
EOpOuterProduct,
EOpDeterminant,
EOpMatrixInverse,
EOpTranspose,
EOpFtransform,
EOpNoise,
EOpEmitVertex, // geometry only
EOpEndPrimitive, // geometry only
EOpEmitStreamVertex, // geometry only
EOpEndStreamPrimitive, // geometry only
EOpBarrier,
EOpMemoryBarrier,
EOpMemoryBarrierAtomicCounter,
EOpMemoryBarrierBuffer,
EOpMemoryBarrierImage,
EOpMemoryBarrierShared, // compute only
EOpGroupMemoryBarrier, // compute only
EOpBallot,
EOpReadInvocation,
EOpReadFirstInvocation,
EOpAnyInvocation,
EOpAllInvocations,
EOpAllInvocationsEqual,
EOpSubgroupGuardStart,
EOpSubgroupBarrier,
EOpSubgroupMemoryBarrier,
EOpSubgroupMemoryBarrierBuffer,
EOpSubgroupMemoryBarrierImage,
EOpSubgroupMemoryBarrierShared, // compute only
EOpSubgroupElect,
EOpSubgroupAll,
EOpSubgroupAny,
EOpSubgroupAllEqual,
EOpSubgroupBroadcast,
EOpSubgroupBroadcastFirst,
EOpSubgroupBallot,
EOpSubgroupInverseBallot,
EOpSubgroupBallotBitExtract,
EOpSubgroupBallotBitCount,
EOpSubgroupBallotInclusiveBitCount,
EOpSubgroupBallotExclusiveBitCount,
EOpSubgroupBallotFindLSB,
EOpSubgroupBallotFindMSB,
EOpSubgroupShuffle,
EOpSubgroupShuffleXor,
EOpSubgroupShuffleUp,
EOpSubgroupShuffleDown,
EOpSubgroupRotate,
EOpSubgroupClusteredRotate,
EOpSubgroupAdd,
EOpSubgroupMul,
EOpSubgroupMin,
EOpSubgroupMax,
EOpSubgroupAnd,
EOpSubgroupOr,
EOpSubgroupXor,
EOpSubgroupInclusiveAdd,
EOpSubgroupInclusiveMul,
EOpSubgroupInclusiveMin,
EOpSubgroupInclusiveMax,
EOpSubgroupInclusiveAnd,
EOpSubgroupInclusiveOr,
EOpSubgroupInclusiveXor,
EOpSubgroupExclusiveAdd,
EOpSubgroupExclusiveMul,
EOpSubgroupExclusiveMin,
EOpSubgroupExclusiveMax,
EOpSubgroupExclusiveAnd,
EOpSubgroupExclusiveOr,
EOpSubgroupExclusiveXor,
EOpSubgroupClusteredAdd,
EOpSubgroupClusteredMul,
EOpSubgroupClusteredMin,
EOpSubgroupClusteredMax,
EOpSubgroupClusteredAnd,
EOpSubgroupClusteredOr,
EOpSubgroupClusteredXor,
EOpSubgroupQuadBroadcast,
EOpSubgroupQuadSwapHorizontal,
EOpSubgroupQuadSwapVertical,
EOpSubgroupQuadSwapDiagonal,
EOpSubgroupQuadAll,
EOpSubgroupQuadAny,
EOpSubgroupPartition,
EOpSubgroupPartitionedAdd,
EOpSubgroupPartitionedMul,
EOpSubgroupPartitionedMin,
EOpSubgroupPartitionedMax,
EOpSubgroupPartitionedAnd,
EOpSubgroupPartitionedOr,
EOpSubgroupPartitionedXor,
EOpSubgroupPartitionedInclusiveAdd,
EOpSubgroupPartitionedInclusiveMul,
EOpSubgroupPartitionedInclusiveMin,
EOpSubgroupPartitionedInclusiveMax,
EOpSubgroupPartitionedInclusiveAnd,
EOpSubgroupPartitionedInclusiveOr,
EOpSubgroupPartitionedInclusiveXor,
EOpSubgroupPartitionedExclusiveAdd,
EOpSubgroupPartitionedExclusiveMul,
EOpSubgroupPartitionedExclusiveMin,
EOpSubgroupPartitionedExclusiveMax,
EOpSubgroupPartitionedExclusiveAnd,
EOpSubgroupPartitionedExclusiveOr,
EOpSubgroupPartitionedExclusiveXor,
EOpSubgroupGuardStop,
EOpMinInvocations,
EOpMaxInvocations,
EOpAddInvocations,
EOpMinInvocationsNonUniform,
EOpMaxInvocationsNonUniform,
EOpAddInvocationsNonUniform,
EOpMinInvocationsInclusiveScan,
EOpMaxInvocationsInclusiveScan,
EOpAddInvocationsInclusiveScan,
EOpMinInvocationsInclusiveScanNonUniform,
EOpMaxInvocationsInclusiveScanNonUniform,
EOpAddInvocationsInclusiveScanNonUniform,
EOpMinInvocationsExclusiveScan,
EOpMaxInvocationsExclusiveScan,
EOpAddInvocationsExclusiveScan,
EOpMinInvocationsExclusiveScanNonUniform,
EOpMaxInvocationsExclusiveScanNonUniform,
EOpAddInvocationsExclusiveScanNonUniform,
EOpSwizzleInvocations,
EOpSwizzleInvocationsMasked,
EOpWriteInvocation,
EOpMbcnt,
EOpCubeFaceIndex,
EOpCubeFaceCoord,
EOpTime,
EOpAtomicAdd,
EOpAtomicSubtract,
EOpAtomicMin,
EOpAtomicMax,
EOpAtomicAnd,
EOpAtomicOr,
EOpAtomicXor,
EOpAtomicExchange,
EOpAtomicCompSwap,
EOpAtomicLoad,
EOpAtomicStore,
EOpAtomicCounterIncrement, // results in pre-increment value
EOpAtomicCounterDecrement, // results in post-decrement value
EOpAtomicCounter,
EOpAtomicCounterAdd,
EOpAtomicCounterSubtract,
EOpAtomicCounterMin,
EOpAtomicCounterMax,
EOpAtomicCounterAnd,
EOpAtomicCounterOr,
EOpAtomicCounterXor,
EOpAtomicCounterExchange,
EOpAtomicCounterCompSwap,
EOpAny,
EOpAll,
EOpCooperativeMatrixLoad,
EOpCooperativeMatrixStore,
EOpCooperativeMatrixMulAdd,
EOpCooperativeMatrixLoadNV,
EOpCooperativeMatrixStoreNV,
EOpCooperativeMatrixMulAddNV,
EOpBeginInvocationInterlock, // Fragment only
EOpEndInvocationInterlock, // Fragment only
EOpIsHelperInvocation,
EOpDebugPrintf,
//
// Branch
//
EOpKill, // Fragment only
EOpTerminateInvocation, // Fragment only
EOpDemote, // Fragment only
EOpTerminateRayKHR, // Any-hit only
EOpIgnoreIntersectionKHR, // Any-hit only
EOpReturn,
EOpBreak,
EOpContinue,
EOpCase,
EOpDefault,
//
// Constructors
//
EOpConstructGuardStart,
EOpConstructInt, // these first scalar forms also identify what implicit conversion is needed
EOpConstructUint,
EOpConstructInt8,
EOpConstructUint8,
EOpConstructInt16,
EOpConstructUint16,
EOpConstructInt64,
EOpConstructUint64,
EOpConstructBool,
EOpConstructFloat,
EOpConstructDouble,
// Keep vector and matrix constructors in a consistent relative order for
// TParseContext::constructBuiltIn, which converts between 8/16/32 bit
// vector constructors
EOpConstructVec2,
EOpConstructVec3,
EOpConstructVec4,
EOpConstructMat2x2,
EOpConstructMat2x3,
EOpConstructMat2x4,
EOpConstructMat3x2,
EOpConstructMat3x3,
EOpConstructMat3x4,
EOpConstructMat4x2,
EOpConstructMat4x3,
EOpConstructMat4x4,
EOpConstructDVec2,
EOpConstructDVec3,
EOpConstructDVec4,
EOpConstructBVec2,
EOpConstructBVec3,
EOpConstructBVec4,
EOpConstructI8Vec2,
EOpConstructI8Vec3,
EOpConstructI8Vec4,
EOpConstructU8Vec2,
EOpConstructU8Vec3,
EOpConstructU8Vec4,
EOpConstructI16Vec2,
EOpConstructI16Vec3,
EOpConstructI16Vec4,
EOpConstructU16Vec2,
EOpConstructU16Vec3,
EOpConstructU16Vec4,
EOpConstructIVec2,
EOpConstructIVec3,
EOpConstructIVec4,
EOpConstructUVec2,
EOpConstructUVec3,
EOpConstructUVec4,
EOpConstructI64Vec2,
EOpConstructI64Vec3,
EOpConstructI64Vec4,
EOpConstructU64Vec2,
EOpConstructU64Vec3,
EOpConstructU64Vec4,
EOpConstructDMat2x2,
EOpConstructDMat2x3,
EOpConstructDMat2x4,
EOpConstructDMat3x2,
EOpConstructDMat3x3,
EOpConstructDMat3x4,
EOpConstructDMat4x2,
EOpConstructDMat4x3,
EOpConstructDMat4x4,
EOpConstructIMat2x2,
EOpConstructIMat2x3,
EOpConstructIMat2x4,
EOpConstructIMat3x2,
EOpConstructIMat3x3,
EOpConstructIMat3x4,
EOpConstructIMat4x2,
EOpConstructIMat4x3,
EOpConstructIMat4x4,
EOpConstructUMat2x2,
EOpConstructUMat2x3,
EOpConstructUMat2x4,
EOpConstructUMat3x2,
EOpConstructUMat3x3,
EOpConstructUMat3x4,
EOpConstructUMat4x2,
EOpConstructUMat4x3,
EOpConstructUMat4x4,
EOpConstructBMat2x2,
EOpConstructBMat2x3,
EOpConstructBMat2x4,
EOpConstructBMat3x2,
EOpConstructBMat3x3,
EOpConstructBMat3x4,
EOpConstructBMat4x2,
EOpConstructBMat4x3,
EOpConstructBMat4x4,
EOpConstructFloat16,
EOpConstructF16Vec2,
EOpConstructF16Vec3,
EOpConstructF16Vec4,
EOpConstructF16Mat2x2,
EOpConstructF16Mat2x3,
EOpConstructF16Mat2x4,
EOpConstructF16Mat3x2,
EOpConstructF16Mat3x3,
EOpConstructF16Mat3x4,
EOpConstructF16Mat4x2,
EOpConstructF16Mat4x3,
EOpConstructF16Mat4x4,
EOpConstructStruct,
EOpConstructTextureSampler,
EOpConstructNonuniform, // expected to be transformed away, not present in final AST
EOpConstructReference,
EOpConstructCooperativeMatrixNV,
EOpConstructCooperativeMatrixKHR,
EOpConstructAccStruct,
EOpConstructGuardEnd,
//
// moves
//
EOpAssign,
EOpAddAssign,
EOpSubAssign,
EOpMulAssign,
EOpVectorTimesMatrixAssign,
EOpVectorTimesScalarAssign,
EOpMatrixTimesScalarAssign,
EOpMatrixTimesMatrixAssign,
EOpDivAssign,
EOpModAssign,
EOpAndAssign,
EOpInclusiveOrAssign,
EOpExclusiveOrAssign,
EOpLeftShiftAssign,
EOpRightShiftAssign,
//
// Array operators
//
// Can apply to arrays, vectors, or matrices.
// Can be decomposed to a constant at compile time, but this does not always happen,
// due to link-time effects. So, consumer can expect either a link-time sized or
// run-time sized array.
EOpArrayLength,
//
// Image operations
//
EOpImageGuardBegin,
EOpImageQuerySize,
EOpImageQuerySamples,
EOpImageLoad,
EOpImageStore,
EOpImageLoadLod,
EOpImageStoreLod,
EOpImageAtomicAdd,
EOpImageAtomicMin,
EOpImageAtomicMax,
EOpImageAtomicAnd,
EOpImageAtomicOr,
EOpImageAtomicXor,
EOpImageAtomicExchange,
EOpImageAtomicCompSwap,
EOpImageAtomicLoad,
EOpImageAtomicStore,
EOpSubpassLoad,
EOpSubpassLoadMS,
EOpSparseImageLoad,
EOpSparseImageLoadLod,
EOpColorAttachmentReadEXT, // Fragment only
EOpImageGuardEnd,
//
// Texture operations
//
EOpTextureGuardBegin,
EOpTextureQuerySize,
EOpTextureQueryLod,
EOpTextureQueryLevels,
EOpTextureQuerySamples,
EOpSamplingGuardBegin,
EOpTexture,
EOpTextureProj,
EOpTextureLod,
EOpTextureOffset,
EOpTextureFetch,
EOpTextureFetchOffset,
EOpTextureProjOffset,
EOpTextureLodOffset,
EOpTextureProjLod,
EOpTextureProjLodOffset,
EOpTextureGrad,
EOpTextureGradOffset,
EOpTextureProjGrad,
EOpTextureProjGradOffset,
EOpTextureGather,
EOpTextureGatherOffset,
EOpTextureGatherOffsets,
EOpTextureClamp,
EOpTextureOffsetClamp,
EOpTextureGradClamp,
EOpTextureGradOffsetClamp,
EOpTextureGatherLod,
EOpTextureGatherLodOffset,
EOpTextureGatherLodOffsets,
EOpFragmentMaskFetch,
EOpFragmentFetch,
EOpSparseTextureGuardBegin,
EOpSparseTexture,
EOpSparseTextureLod,
EOpSparseTextureOffset,
EOpSparseTextureFetch,
EOpSparseTextureFetchOffset,
EOpSparseTextureLodOffset,
EOpSparseTextureGrad,
EOpSparseTextureGradOffset,
EOpSparseTextureGather,
EOpSparseTextureGatherOffset,
EOpSparseTextureGatherOffsets,
EOpSparseTexelsResident,
EOpSparseTextureClamp,
EOpSparseTextureOffsetClamp,
EOpSparseTextureGradClamp,
EOpSparseTextureGradOffsetClamp,
EOpSparseTextureGatherLod,
EOpSparseTextureGatherLodOffset,
EOpSparseTextureGatherLodOffsets,
EOpSparseTextureGuardEnd,
EOpImageFootprintGuardBegin,
EOpImageSampleFootprintNV,
EOpImageSampleFootprintClampNV,
EOpImageSampleFootprintLodNV,
EOpImageSampleFootprintGradNV,
EOpImageSampleFootprintGradClampNV,
EOpImageFootprintGuardEnd,
EOpSamplingGuardEnd,
EOpTextureGuardEnd,
//
// Integer operations
//
EOpAddCarry,
EOpSubBorrow,
EOpUMulExtended,
EOpIMulExtended,
EOpBitfieldExtract,
EOpBitfieldInsert,
EOpBitFieldReverse,
EOpBitCount,
EOpFindLSB,
EOpFindMSB,
EOpCountLeadingZeros,
EOpCountTrailingZeros,
EOpAbsDifference,
EOpAddSaturate,
EOpSubSaturate,
EOpAverage,
EOpAverageRounded,
EOpMul32x16,
EOpTraceNV,
EOpTraceRayMotionNV,
EOpTraceKHR,
EOpReportIntersection,
EOpIgnoreIntersectionNV,
EOpTerminateRayNV,
EOpExecuteCallableNV,
EOpExecuteCallableKHR,
EOpWritePackedPrimitiveIndices4x8NV,
EOpEmitMeshTasksEXT,
EOpSetMeshOutputsEXT,
//
// GL_EXT_ray_query operations
//
EOpRayQueryInitialize,
EOpRayQueryTerminate,
EOpRayQueryGenerateIntersection,
EOpRayQueryConfirmIntersection,
EOpRayQueryProceed,
EOpRayQueryGetIntersectionType,
EOpRayQueryGetRayTMin,
EOpRayQueryGetRayFlags,
EOpRayQueryGetIntersectionT,
EOpRayQueryGetIntersectionInstanceCustomIndex,
EOpRayQueryGetIntersectionInstanceId,
EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset,
EOpRayQueryGetIntersectionGeometryIndex,
EOpRayQueryGetIntersectionPrimitiveIndex,
EOpRayQueryGetIntersectionBarycentrics,
EOpRayQueryGetIntersectionFrontFace,
EOpRayQueryGetIntersectionCandidateAABBOpaque,
EOpRayQueryGetIntersectionObjectRayDirection,
EOpRayQueryGetIntersectionObjectRayOrigin,
EOpRayQueryGetWorldRayDirection,
EOpRayQueryGetWorldRayOrigin,
EOpRayQueryGetIntersectionObjectToWorld,
EOpRayQueryGetIntersectionWorldToObject,
//
// GL_NV_shader_invocation_reorder
//
EOpHitObjectTraceRayNV,
EOpHitObjectTraceRayMotionNV,
EOpHitObjectRecordHitNV,
EOpHitObjectRecordHitMotionNV,
EOpHitObjectRecordHitWithIndexNV,
EOpHitObjectRecordHitWithIndexMotionNV,
EOpHitObjectRecordMissNV,
EOpHitObjectRecordMissMotionNV,
EOpHitObjectRecordEmptyNV,
EOpHitObjectExecuteShaderNV,
EOpHitObjectIsEmptyNV,
EOpHitObjectIsMissNV,
EOpHitObjectIsHitNV,
EOpHitObjectGetRayTMinNV,
EOpHitObjectGetRayTMaxNV,
EOpHitObjectGetObjectRayOriginNV,
EOpHitObjectGetObjectRayDirectionNV,
EOpHitObjectGetWorldRayOriginNV,
EOpHitObjectGetWorldRayDirectionNV,
EOpHitObjectGetWorldToObjectNV,
EOpHitObjectGetObjectToWorldNV,
EOpHitObjectGetInstanceCustomIndexNV,
EOpHitObjectGetInstanceIdNV,
EOpHitObjectGetGeometryIndexNV,
EOpHitObjectGetPrimitiveIndexNV,
EOpHitObjectGetHitKindNV,
EOpHitObjectGetShaderBindingTableRecordIndexNV,
EOpHitObjectGetShaderRecordBufferHandleNV,
EOpHitObjectGetAttributesNV,
EOpHitObjectGetCurrentTimeNV,
EOpReorderThreadNV,
EOpFetchMicroTriangleVertexPositionNV,
EOpFetchMicroTriangleVertexBarycentricNV,
// HLSL operations
//
EOpClip, // discard if input value < 0
EOpIsFinite,
EOpLog10, // base 10 log
EOpRcp, // 1/x
EOpSaturate, // clamp from 0 to 1
EOpSinCos, // sin and cos in out parameters
EOpGenMul, // mul(x,y) on any of mat/vec/scalars
EOpDst, // x = 1, y=src0.y * src1.y, z=src0.z, w=src1.w
EOpInterlockedAdd, // atomic ops, but uses [optional] out arg instead of return
EOpInterlockedAnd, // ...
EOpInterlockedCompareExchange, // ...
EOpInterlockedCompareStore, // ...
EOpInterlockedExchange, // ...
EOpInterlockedMax, // ...
EOpInterlockedMin, // ...
EOpInterlockedOr, // ...
EOpInterlockedXor, // ...
EOpAllMemoryBarrierWithGroupSync, // memory barriers without non-hlsl AST equivalents
EOpDeviceMemoryBarrier, // ...
EOpDeviceMemoryBarrierWithGroupSync, // ...
EOpWorkgroupMemoryBarrier, // ...
EOpWorkgroupMemoryBarrierWithGroupSync, // ...
EOpEvaluateAttributeSnapped, // InterpolateAtOffset with int position on 16x16 grid
EOpF32tof16, // HLSL conversion: half of a PackHalf2x16
EOpF16tof32, // HLSL conversion: half of an UnpackHalf2x16
EOpLit, // HLSL lighting coefficient vector
EOpTextureBias, // HLSL texture bias: will be lowered to EOpTexture
EOpAsDouble, // slightly different from EOpUint64BitsToDouble
EOpD3DCOLORtoUBYTE4, // convert and swizzle 4-component color to UBYTE4 range
EOpMethodSample, // Texture object methods. These are translated to existing
EOpMethodSampleBias, // AST methods, and exist to represent HLSL semantics until that
EOpMethodSampleCmp, // translation is performed. See HlslParseContext::decomposeSampleMethods().
EOpMethodSampleCmpLevelZero, // ...
EOpMethodSampleGrad, // ...
EOpMethodSampleLevel, // ...
EOpMethodLoad, // ...
EOpMethodGetDimensions, // ...
EOpMethodGetSamplePosition, // ...
EOpMethodGather, // ...
EOpMethodCalculateLevelOfDetail, // ...
EOpMethodCalculateLevelOfDetailUnclamped, // ...
// Load already defined above for textures
EOpMethodLoad2, // Structure buffer object methods. These are translated to existing
EOpMethodLoad3, // AST methods, and exist to represent HLSL semantics until that
EOpMethodLoad4, // translation is performed. See HlslParseContext::decomposeSampleMethods().
EOpMethodStore, // ...
EOpMethodStore2, // ...
EOpMethodStore3, // ...
EOpMethodStore4, // ...
EOpMethodIncrementCounter, // ...
EOpMethodDecrementCounter, // ...
// EOpMethodAppend is defined for geo shaders below
EOpMethodConsume,
// SM5 texture methods
EOpMethodGatherRed, // These are covered under the above EOpMethodSample comment about
EOpMethodGatherGreen, // translation to existing AST opcodes. They exist temporarily
EOpMethodGatherBlue, // because HLSL arguments are slightly different.
EOpMethodGatherAlpha, // ...
EOpMethodGatherCmp, // ...
EOpMethodGatherCmpRed, // ...
EOpMethodGatherCmpGreen, // ...
EOpMethodGatherCmpBlue, // ...
EOpMethodGatherCmpAlpha, // ...
// geometry methods
EOpMethodAppend, // Geometry shader methods
EOpMethodRestartStrip, // ...
// matrix
EOpMatrixSwizzle, // select multiple matrix components (non-column)
// SM6 wave ops
EOpWaveGetLaneCount, // Will decompose to gl_SubgroupSize.
EOpWaveGetLaneIndex, // Will decompose to gl_SubgroupInvocationID.
EOpWaveActiveCountBits, // Will decompose to subgroupBallotBitCount(subgroupBallot()).
EOpWavePrefixCountBits, // Will decompose to subgroupBallotInclusiveBitCount(subgroupBallot()).
// GL_EXT_expect_assume
EOpAssumeEXT,
EOpExpectEXT,
// Shader Clock Ops
EOpReadClockSubgroupKHR,
EOpReadClockDeviceKHR,
// GL_EXT_ray_tracing_position_fetch
EOpRayQueryGetIntersectionTriangleVertexPositionsEXT,
// Shader tile image ops
EOpStencilAttachmentReadEXT, // Fragment only
EOpDepthAttachmentReadEXT, // Fragment only
// Image processing
EOpImageSampleWeightedQCOM,
EOpImageBoxFilterQCOM,
EOpImageBlockMatchSADQCOM,
EOpImageBlockMatchSSDQCOM,
// Image processing2
EOpImageBlockMatchWindowSSDQCOM,
EOpImageBlockMatchWindowSADQCOM,
EOpImageBlockMatchGatherSSDQCOM,
EOpImageBlockMatchGatherSADQCOM,
};
enum TLinkType {
ELinkNone,
ELinkExport,
};
class TIntermTraverser;
class TIntermOperator;
class TIntermAggregate;
class TIntermUnary;
class TIntermBinary;
class TIntermConstantUnion;
class TIntermSelection;
class TIntermSwitch;
class TIntermBranch;
class TIntermTyped;
class TIntermMethod;
class TIntermSymbol;
class TIntermLoop;
} // end namespace glslang
//
// Base class for the tree nodes
//
// (Put outside the glslang namespace, as it's used as part of the external interface.)
//
class TIntermNode {
public:
POOL_ALLOCATOR_NEW_DELETE(glslang::GetThreadPoolAllocator())
TIntermNode() { loc.init(); }
virtual const glslang::TSourceLoc& getLoc() const { return loc; }
virtual void setLoc(const glslang::TSourceLoc& l) { loc = l; }
virtual void traverse(glslang::TIntermTraverser*) = 0;
virtual glslang::TIntermTyped* getAsTyped() { return nullptr; }
virtual glslang::TIntermOperator* getAsOperator() { return nullptr; }
virtual glslang::TIntermConstantUnion* getAsConstantUnion() { return nullptr; }
virtual glslang::TIntermAggregate* getAsAggregate() { return nullptr; }
virtual glslang::TIntermUnary* getAsUnaryNode() { return nullptr; }
virtual glslang::TIntermBinary* getAsBinaryNode() { return nullptr; }
virtual glslang::TIntermSelection* getAsSelectionNode() { return nullptr; }
virtual glslang::TIntermSwitch* getAsSwitchNode() { return nullptr; }
virtual glslang::TIntermMethod* getAsMethodNode() { return nullptr; }
virtual glslang::TIntermSymbol* getAsSymbolNode() { return nullptr; }
virtual glslang::TIntermBranch* getAsBranchNode() { return nullptr; }
virtual glslang::TIntermLoop* getAsLoopNode() { return nullptr; }
virtual const glslang::TIntermTyped* getAsTyped() const { return nullptr; }
virtual const glslang::TIntermOperator* getAsOperator() const { return nullptr; }
virtual const glslang::TIntermConstantUnion* getAsConstantUnion() const { return nullptr; }
virtual const glslang::TIntermAggregate* getAsAggregate() const { return nullptr; }
virtual const glslang::TIntermUnary* getAsUnaryNode() const { return nullptr; }
virtual const glslang::TIntermBinary* getAsBinaryNode() const { return nullptr; }
virtual const glslang::TIntermSelection* getAsSelectionNode() const { return nullptr; }
virtual const glslang::TIntermSwitch* getAsSwitchNode() const { return nullptr; }
virtual const glslang::TIntermMethod* getAsMethodNode() const { return nullptr; }
virtual const glslang::TIntermSymbol* getAsSymbolNode() const { return nullptr; }
virtual const glslang::TIntermBranch* getAsBranchNode() const { return nullptr; }
virtual const glslang::TIntermLoop* getAsLoopNode() const { return nullptr; }
virtual ~TIntermNode() { }
protected:
TIntermNode(const TIntermNode&);
TIntermNode& operator=(const TIntermNode&);
glslang::TSourceLoc loc;
};
namespace glslang {
//
// This is just to help yacc.
//
struct TIntermNodePair {
TIntermNode* node1;
TIntermNode* node2;
};
//
// Intermediate class for nodes that have a type.
//
class TIntermTyped : public TIntermNode {
public:
TIntermTyped(const TType& t) { type.shallowCopy(t); }
TIntermTyped(TBasicType basicType) { TType bt(basicType); type.shallowCopy(bt); }
virtual TIntermTyped* getAsTyped() { return this; }
virtual const TIntermTyped* getAsTyped() const { return this; }
virtual void setType(const TType& t) { type.shallowCopy(t); }
virtual const TType& getType() const { return type; }
virtual TType& getWritableType() { return type; }
virtual TBasicType getBasicType() const { return type.getBasicType(); }
virtual TQualifier& getQualifier() { return type.getQualifier(); }
virtual const TQualifier& getQualifier() const { return type.getQualifier(); }
virtual TArraySizes* getArraySizes() { return type.getArraySizes(); }
virtual const TArraySizes* getArraySizes() const { return type.getArraySizes(); }
virtual void propagatePrecision(TPrecisionQualifier);
virtual int getVectorSize() const { return type.getVectorSize(); }
virtual int getMatrixCols() const { return type.getMatrixCols(); }
virtual int getMatrixRows() const { return type.getMatrixRows(); }
virtual bool isMatrix() const { return type.isMatrix(); }
virtual bool isArray() const { return type.isArray(); }
virtual bool isVector() const { return type.isVector(); }
virtual bool isScalar() const { return type.isScalar(); }
virtual bool isStruct() const { return type.isStruct(); }
virtual bool isFloatingDomain() const { return type.isFloatingDomain(); }
virtual bool isIntegerDomain() const { return type.isIntegerDomain(); }
bool isAtomic() const { return type.isAtomic(); }
bool isReference() const { return type.isReference(); }
TString getCompleteString(bool enhanced = false) const { return type.getCompleteString(enhanced); }
protected:
TIntermTyped& operator=(const TIntermTyped&);
TType type;
};
//
// Handle for, do-while, and while loops.
//
class TIntermLoop : public TIntermNode {
public:
TIntermLoop(TIntermNode* aBody, TIntermTyped* aTest, TIntermTyped* aTerminal, bool testFirst) :
body(aBody),
test(aTest),
terminal(aTerminal),
first(testFirst),
unroll(false),
dontUnroll(false),
dependency(0),
minIterations(0),
maxIterations(iterationsInfinite),
iterationMultiple(1),
peelCount(0),
partialCount(0)
{ }
virtual TIntermLoop* getAsLoopNode() { return this; }
virtual const TIntermLoop* getAsLoopNode() const { return this; }
virtual void traverse(TIntermTraverser*);
TIntermNode* getBody() const { return body; }
TIntermTyped* getTest() const { return test; }
TIntermTyped* getTerminal() const { return terminal; }
bool testFirst() const { return first; }
void setUnroll() { unroll = true; }
void setDontUnroll() {
dontUnroll = true;
peelCount = 0;
partialCount = 0;
}
bool getUnroll() const { return unroll; }
bool getDontUnroll() const { return dontUnroll; }
static const unsigned int dependencyInfinite = 0xFFFFFFFF;
static const unsigned int iterationsInfinite = 0xFFFFFFFF;
void setLoopDependency(int d) { dependency = d; }
int getLoopDependency() const { return dependency; }
void setMinIterations(unsigned int v) { minIterations = v; }
unsigned int getMinIterations() const { return minIterations; }
void setMaxIterations(unsigned int v) { maxIterations = v; }
unsigned int getMaxIterations() const { return maxIterations; }
void setIterationMultiple(unsigned int v) { iterationMultiple = v; }
unsigned int getIterationMultiple() const { return iterationMultiple; }
void setPeelCount(unsigned int v) {
peelCount = v;
dontUnroll = false;
}
unsigned int getPeelCount() const { return peelCount; }
void setPartialCount(unsigned int v) {
partialCount = v;
dontUnroll = false;
}
unsigned int getPartialCount() const { return partialCount; }
protected:
TIntermNode* body; // code to loop over
TIntermTyped* test; // exit condition associated with loop, could be 0 for 'for' loops
TIntermTyped* terminal; // exists for for-loops
bool first; // true for while and for, not for do-while
bool unroll; // true if unroll requested
bool dontUnroll; // true if request to not unroll
unsigned int dependency; // loop dependency hint; 0 means not set or unknown
unsigned int minIterations; // as per the SPIR-V specification
unsigned int maxIterations; // as per the SPIR-V specification
unsigned int iterationMultiple; // as per the SPIR-V specification
unsigned int peelCount; // as per the SPIR-V specification
unsigned int partialCount; // as per the SPIR-V specification
};
//
// Handle case, break, continue, return, and kill.
//
class TIntermBranch : public TIntermNode {
public:
TIntermBranch(TOperator op, TIntermTyped* e) :
flowOp(op),
expression(e) { }
virtual TIntermBranch* getAsBranchNode() { return this; }
virtual const TIntermBranch* getAsBranchNode() const { return this; }
virtual void traverse(TIntermTraverser*);
TOperator getFlowOp() const { return flowOp; }
TIntermTyped* getExpression() const { return expression; }
void setExpression(TIntermTyped* pExpression) { expression = pExpression; }
void updatePrecision(TPrecisionQualifier parentPrecision);
protected:
TOperator flowOp;
TIntermTyped* expression;
};
//
// Represent method names before seeing their calling signature
// or resolving them to operations. Just an expression as the base object
// and a textural name.
//
class TIntermMethod : public TIntermTyped {
public:
TIntermMethod(TIntermTyped* o, const TType& t, const TString& m) : TIntermTyped(t), object(o), method(m) { }
virtual TIntermMethod* getAsMethodNode() { return this; }
virtual const TIntermMethod* getAsMethodNode() const { return this; }
virtual const TString& getMethodName() const { return method; }
virtual TIntermTyped* getObject() const { return object; }
virtual void traverse(TIntermTraverser*);
void setExport() { linkType = ELinkExport; }
protected:
TIntermTyped* object;
TString method;
TLinkType linkType;
};
//
// Nodes that correspond to symbols or constants in the source code.
//
class TIntermSymbol : public TIntermTyped {
public:
// if symbol is initialized as symbol(sym), the memory comes from the pool allocator of sym. If sym comes from
// per process threadPoolAllocator, then it causes increased memory usage per compile
// it is essential to use "symbol = sym" to assign to symbol
TIntermSymbol(long long i, const TString& n, const TType& t)
: TIntermTyped(t), id(i), flattenSubset(-1), constSubtree(nullptr) { name = n; }
virtual long long getId() const { return id; }
virtual void changeId(long long i) { id = i; }
virtual const TString& getName() const { return name; }
virtual void traverse(TIntermTraverser*);
virtual TIntermSymbol* getAsSymbolNode() { return this; }
virtual const TIntermSymbol* getAsSymbolNode() const { return this; }
void setConstArray(const TConstUnionArray& c) { constArray = c; }
const TConstUnionArray& getConstArray() const { return constArray; }
void setConstSubtree(TIntermTyped* subtree) { constSubtree = subtree; }
TIntermTyped* getConstSubtree() const { return constSubtree; }
void setFlattenSubset(int subset) { flattenSubset = subset; }
virtual const TString& getAccessName() const;
int getFlattenSubset() const { return flattenSubset; } // -1 means full object
// This is meant for cases where a node has already been constructed, and
// later on, it becomes necessary to switch to a different symbol.
virtual void switchId(long long newId) { id = newId; }
protected:
long long id; // the unique id of the symbol this node represents
int flattenSubset; // how deeply the flattened object rooted at id has been dereferenced
TString name; // the name of the symbol this node represents
TConstUnionArray constArray; // if the symbol is a front-end compile-time constant, this is its value
TIntermTyped* constSubtree;
};
class TIntermConstantUnion : public TIntermTyped {
public:
TIntermConstantUnion(const TConstUnionArray& ua, const TType& t) : TIntermTyped(t), constArray(ua), literal(false) { }
const TConstUnionArray& getConstArray() const { return constArray; }
virtual TIntermConstantUnion* getAsConstantUnion() { return this; }
virtual const TIntermConstantUnion* getAsConstantUnion() const { return this; }
virtual void traverse(TIntermTraverser*);
virtual TIntermTyped* fold(TOperator, const TIntermTyped*) const;
virtual TIntermTyped* fold(TOperator, const TType&) const;
void setLiteral() { literal = true; }
void setExpression() { literal = false; }
bool isLiteral() const { return literal; }
protected:
TIntermConstantUnion& operator=(const TIntermConstantUnion&);
const TConstUnionArray constArray;
bool literal; // true if node represents a literal in the source code
};
// Represent the independent aspects of a texturing TOperator
struct TCrackedTextureOp {
bool query;
bool proj;
bool lod;
bool fetch;
bool offset;
bool offsets;
bool gather;
bool grad;
bool subpass;
bool lodClamp;
bool fragMask;
bool attachmentEXT;
};
//
// Intermediate class for node types that hold operators.
//
class TIntermOperator : public TIntermTyped {
public:
virtual TIntermOperator* getAsOperator() { return this; }
virtual const TIntermOperator* getAsOperator() const { return this; }
TOperator getOp() const { return op; }
void setOp(TOperator newOp) { op = newOp; }
bool modifiesState() const;
bool isConstructor() const;
bool isTexture() const { return op > EOpTextureGuardBegin && op < EOpTextureGuardEnd; }
bool isSampling() const { return op > EOpSamplingGuardBegin && op < EOpSamplingGuardEnd; }
bool isImage() const { return op > EOpImageGuardBegin && op < EOpImageGuardEnd; }
bool isSparseTexture() const { return op > EOpSparseTextureGuardBegin && op < EOpSparseTextureGuardEnd; }
bool isImageFootprint() const { return op > EOpImageFootprintGuardBegin && op < EOpImageFootprintGuardEnd; }
bool isSparseImage() const { return op == EOpSparseImageLoad; }
bool isSubgroup() const { return op > EOpSubgroupGuardStart && op < EOpSubgroupGuardStop; }
void setOperationPrecision(TPrecisionQualifier p) { operationPrecision = p; }
TPrecisionQualifier getOperationPrecision() const { return operationPrecision != EpqNone ?
operationPrecision :
type.getQualifier().precision; }
TString getCompleteString() const
{
TString cs = type.getCompleteString();
if (getOperationPrecision() != type.getQualifier().precision) {
cs += ", operation at ";
cs += GetPrecisionQualifierString(getOperationPrecision());
}
return cs;
}
// Crack the op into the individual dimensions of texturing operation.
void crackTexture(TSampler sampler, TCrackedTextureOp& cracked) const
{
cracked.query = false;
cracked.proj = false;
cracked.lod = false;
cracked.fetch = false;
cracked.offset = false;
cracked.offsets = false;
cracked.gather = false;
cracked.grad = false;
cracked.subpass = false;
cracked.attachmentEXT = false;
cracked.lodClamp = false;
cracked.fragMask = false;
switch (op) {
case EOpImageQuerySize:
case EOpImageQuerySamples:
case EOpTextureQuerySize:
case EOpTextureQueryLod:
case EOpTextureQueryLevels:
case EOpTextureQuerySamples:
case EOpSparseTexelsResident:
cracked.query = true;
break;
case EOpTexture:
case EOpSparseTexture:
break;
case EOpTextureProj:
cracked.proj = true;
break;
case EOpTextureLod:
case EOpSparseTextureLod:
cracked.lod = true;
break;
case EOpTextureOffset:
case EOpSparseTextureOffset:
cracked.offset = true;
break;
case EOpTextureFetch:
case EOpSparseTextureFetch:
cracked.fetch = true;
if (sampler.is1D() || (sampler.dim == Esd2D && ! sampler.isMultiSample()) || sampler.dim == Esd3D)
cracked.lod = true;
break;
case EOpTextureFetchOffset:
case EOpSparseTextureFetchOffset:
cracked.fetch = true;
cracked.offset = true;
if (sampler.is1D() || (sampler.dim == Esd2D && ! sampler.isMultiSample()) || sampler.dim == Esd3D)
cracked.lod = true;
break;
case EOpTextureProjOffset:
cracked.offset = true;
cracked.proj = true;
break;
case EOpTextureLodOffset:
case EOpSparseTextureLodOffset:
cracked.offset = true;
cracked.lod = true;
break;
case EOpTextureProjLod:
cracked.lod = true;
cracked.proj = true;
break;
case EOpTextureProjLodOffset:
cracked.offset = true;
cracked.lod = true;
cracked.proj = true;
break;
case EOpTextureGrad:
case EOpSparseTextureGrad:
cracked.grad = true;
break;
case EOpTextureGradOffset:
case EOpSparseTextureGradOffset:
cracked.grad = true;
cracked.offset = true;
break;
case EOpTextureProjGrad:
cracked.grad = true;
cracked.proj = true;
break;
case EOpTextureProjGradOffset:
cracked.grad = true;
cracked.offset = true;
cracked.proj = true;
break;
case EOpTextureClamp:
case EOpSparseTextureClamp:
cracked.lodClamp = true;
break;
case EOpTextureOffsetClamp:
case EOpSparseTextureOffsetClamp:
cracked.offset = true;
cracked.lodClamp = true;
break;
case EOpTextureGradClamp:
case EOpSparseTextureGradClamp:
cracked.grad = true;
cracked.lodClamp = true;
break;
case EOpTextureGradOffsetClamp:
case EOpSparseTextureGradOffsetClamp:
cracked.grad = true;
cracked.offset = true;
cracked.lodClamp = true;
break;
case EOpTextureGather:
case EOpSparseTextureGather:
cracked.gather = true;
break;
case EOpTextureGatherOffset:
case EOpSparseTextureGatherOffset:
cracked.gather = true;
cracked.offset = true;
break;
case EOpTextureGatherOffsets:
case EOpSparseTextureGatherOffsets:
cracked.gather = true;
cracked.offsets = true;
break;
case EOpTextureGatherLod:
case EOpSparseTextureGatherLod:
cracked.gather = true;
cracked.lod = true;
break;
case EOpTextureGatherLodOffset:
case EOpSparseTextureGatherLodOffset:
cracked.gather = true;
cracked.offset = true;
cracked.lod = true;
break;
case EOpTextureGatherLodOffsets:
case EOpSparseTextureGatherLodOffsets:
cracked.gather = true;
cracked.offsets = true;
cracked.lod = true;
break;
case EOpImageLoadLod:
case EOpImageStoreLod:
case EOpSparseImageLoadLod:
cracked.lod = true;
break;
case EOpFragmentMaskFetch:
cracked.subpass = sampler.dim == EsdSubpass;
cracked.fragMask = true;
break;
case EOpFragmentFetch:
cracked.subpass = sampler.dim == EsdSubpass;
cracked.fragMask = true;
break;
case EOpImageSampleFootprintNV:
break;
case EOpImageSampleFootprintClampNV:
cracked.lodClamp = true;
break;
case EOpImageSampleFootprintLodNV:
cracked.lod = true;
break;
case EOpImageSampleFootprintGradNV:
cracked.grad = true;
break;
case EOpImageSampleFootprintGradClampNV:
cracked.lodClamp = true;
cracked.grad = true;
break;
case EOpSubpassLoad:
case EOpSubpassLoadMS:
cracked.subpass = true;
break;
case EOpColorAttachmentReadEXT:
cracked.attachmentEXT = true;
break;
default:
break;
}
}
protected:
TIntermOperator(TOperator o) : TIntermTyped(EbtFloat), op(o), operationPrecision(EpqNone) {}
TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o), operationPrecision(EpqNone) {}
TOperator op;
// The result precision is in the inherited TType, and is usually meant to be both
// the operation precision and the result precision. However, some more complex things,
// like built-in function calls, distinguish between the two, in which case non-EqpNone
// 'operationPrecision' overrides the result precision as far as operation precision
// is concerned.
TPrecisionQualifier operationPrecision;
};
//
// Nodes for all the basic binary math operators.
//
class TIntermBinary : public TIntermOperator {
public:
TIntermBinary(TOperator o) : TIntermOperator(o) {}
virtual void traverse(TIntermTraverser*);
virtual void setLeft(TIntermTyped* n) { left = n; }
virtual void setRight(TIntermTyped* n) { right = n; }
virtual TIntermTyped* getLeft() const { return left; }
virtual TIntermTyped* getRight() const { return right; }
virtual TIntermBinary* getAsBinaryNode() { return this; }
virtual const TIntermBinary* getAsBinaryNode() const { return this; }
virtual void updatePrecision();
protected:
TIntermTyped* left;
TIntermTyped* right;
};
//
// Nodes for unary math operators.
//
class TIntermUnary : public TIntermOperator {
public:
TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(nullptr) {}
TIntermUnary(TOperator o) : TIntermOperator(o), operand(nullptr) {}
virtual void traverse(TIntermTraverser*);
virtual void setOperand(TIntermTyped* o) { operand = o; }
virtual TIntermTyped* getOperand() { return operand; }
virtual const TIntermTyped* getOperand() const { return operand; }
virtual TIntermUnary* getAsUnaryNode() { return this; }
virtual const TIntermUnary* getAsUnaryNode() const { return this; }
virtual void updatePrecision();
void setSpirvInstruction(const TSpirvInstruction& inst) { spirvInst = inst; }
const TSpirvInstruction& getSpirvInstruction() const { return spirvInst; }
protected:
TIntermTyped* operand;
TSpirvInstruction spirvInst;
};
typedef TVector<TIntermNode*> TIntermSequence;
typedef TVector<TStorageQualifier> TQualifierList;
//
// Nodes that operate on an arbitrary sized set of children.
//
class TIntermAggregate : public TIntermOperator {
public:
TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(nullptr) { }
TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(nullptr) { }
~TIntermAggregate() { delete pragmaTable; }
virtual TIntermAggregate* getAsAggregate() { return this; }
virtual const TIntermAggregate* getAsAggregate() const { return this; }
virtual void updatePrecision();
virtual void setOperator(TOperator o) { op = o; }
virtual TIntermSequence& getSequence() { return sequence; }
virtual const TIntermSequence& getSequence() const { return sequence; }
virtual void setName(const TString& n) { name = n; }
virtual const TString& getName() const { return name; }
virtual void traverse(TIntermTraverser*);
virtual void setUserDefined() { userDefined = true; }
virtual bool isUserDefined() { return userDefined; }
virtual TQualifierList& getQualifierList() { return qualifier; }
virtual const TQualifierList& getQualifierList() const { return qualifier; }
void setOptimize(bool o) { optimize = o; }
void setDebug(bool d) { debug = d; }
bool getOptimize() const { return optimize; }
bool getDebug() const { return debug; }
void setPragmaTable(const TPragmaTable& pTable);
const TPragmaTable& getPragmaTable() const { return *pragmaTable; }
void setSpirvInstruction(const TSpirvInstruction& inst) { spirvInst = inst; }
const TSpirvInstruction& getSpirvInstruction() const { return spirvInst; }
void setLinkType(TLinkType l) { linkType = l; }
TLinkType getLinkType() const { return linkType; }
protected:
TIntermAggregate(const TIntermAggregate&); // disallow copy constructor
TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator
TIntermSequence sequence;
TQualifierList qualifier;
TString name;
bool userDefined; // used for user defined function names
bool optimize;
bool debug;
TPragmaTable* pragmaTable;
TSpirvInstruction spirvInst;
TLinkType linkType = ELinkNone;
};
//
// For if tests.
//
class TIntermSelection : public TIntermTyped {
public:
TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) :
TIntermTyped(EbtVoid), condition(cond), trueBlock(trueB), falseBlock(falseB),
shortCircuit(true),
flatten(false), dontFlatten(false) {}
TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) :
TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB),
shortCircuit(true),
flatten(false), dontFlatten(false) {}
virtual void traverse(TIntermTraverser*);
virtual TIntermTyped* getCondition() const { return condition; }
virtual void setCondition(TIntermTyped* c) { condition = c; }
virtual TIntermNode* getTrueBlock() const { return trueBlock; }
virtual void setTrueBlock(TIntermTyped* tb) { trueBlock = tb; }
virtual TIntermNode* getFalseBlock() const { return falseBlock; }
virtual void setFalseBlock(TIntermTyped* fb) { falseBlock = fb; }
virtual TIntermSelection* getAsSelectionNode() { return this; }
virtual const TIntermSelection* getAsSelectionNode() const { return this; }
void setNoShortCircuit() { shortCircuit = false; }
bool getShortCircuit() const { return shortCircuit; }
void setFlatten() { flatten = true; }
void setDontFlatten() { dontFlatten = true; }
bool getFlatten() const { return flatten; }
bool getDontFlatten() const { return dontFlatten; }
protected:
TIntermTyped* condition;
TIntermNode* trueBlock;
TIntermNode* falseBlock;
bool shortCircuit; // normally all if-then-else and all GLSL ?: short-circuit, but HLSL ?: does not
bool flatten; // true if flatten requested
bool dontFlatten; // true if requested to not flatten
};
//
// For switch statements. Designed use is that a switch will have sequence of nodes
// that are either case/default nodes or a *single* node that represents all the code
// in between (if any) consecutive case/defaults. So, a traversal need only deal with
// 0 or 1 nodes per case/default statement.
//
class TIntermSwitch : public TIntermNode {
public:
TIntermSwitch(TIntermTyped* cond, TIntermAggregate* b) : condition(cond), body(b),
flatten(false), dontFlatten(false) {}
virtual void traverse(TIntermTraverser*);
virtual TIntermNode* getCondition() const { return condition; }
virtual TIntermAggregate* getBody() const { return body; }
virtual TIntermSwitch* getAsSwitchNode() { return this; }
virtual const TIntermSwitch* getAsSwitchNode() const { return this; }
void setFlatten() { flatten = true; }
void setDontFlatten() { dontFlatten = true; }
bool getFlatten() const { return flatten; }
bool getDontFlatten() const { return dontFlatten; }
protected:
TIntermTyped* condition;
TIntermAggregate* body;
bool flatten; // true if flatten requested
bool dontFlatten; // true if requested to not flatten
};
enum TVisit
{
EvPreVisit,
EvInVisit,
EvPostVisit
};
//
// For traversing the tree. User should derive from this,
// put their traversal specific data in it, and then pass
// it to a Traverse method.
//
// When using this, just fill in the methods for nodes you want visited.
// Return false from a pre-visit to skip visiting that node's subtree.
//
// Explicitly set postVisit to true if you want post visiting, otherwise,
// filled in methods will only be called at pre-visit time (before processing
// the subtree). Similarly for inVisit for in-order visiting of nodes with
// multiple children.
//
// If you only want post-visits, explicitly turn off preVisit (and inVisit)
// and turn on postVisit.
//
// In general, for the visit*() methods, return true from interior nodes
// to have the traversal continue on to children.
//
// If you process children yourself, or don't want them processed, return false.
//
class TIntermTraverser {
public:
POOL_ALLOCATOR_NEW_DELETE(glslang::GetThreadPoolAllocator())
TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, bool rightToLeft = false) :
preVisit(preVisit),
inVisit(inVisit),
postVisit(postVisit),
rightToLeft(rightToLeft),
depth(0),
maxDepth(0) { }
virtual ~TIntermTraverser() { }
virtual void visitSymbol(TIntermSymbol*) { }
virtual void visitConstantUnion(TIntermConstantUnion*) { }
virtual bool visitBinary(TVisit, TIntermBinary*) { return true; }
virtual bool visitUnary(TVisit, TIntermUnary*) { return true; }
virtual bool visitSelection(TVisit, TIntermSelection*) { return true; }
virtual bool visitAggregate(TVisit, TIntermAggregate*) { return true; }
virtual bool visitLoop(TVisit, TIntermLoop*) { return true; }
virtual bool visitBranch(TVisit, TIntermBranch*) { return true; }
virtual bool visitSwitch(TVisit, TIntermSwitch*) { return true; }
int getMaxDepth() const { return maxDepth; }
void incrementDepth(TIntermNode *current)
{
depth++;
maxDepth = (std::max)(maxDepth, depth);
path.push_back(current);
}
void decrementDepth()
{
depth--;
path.pop_back();
}
TIntermNode *getParentNode()
{
return path.size() == 0 ? nullptr : path.back();
}
const bool preVisit;
const bool inVisit;
const bool postVisit;
const bool rightToLeft;
protected:
TIntermTraverser& operator=(TIntermTraverser&);
int depth;
int maxDepth;
// All the nodes from root to the current node's parent during traversing.
TVector<TIntermNode *> path;
};
// KHR_vulkan_glsl says "Two arrays sized with specialization constants are the same type only if
// sized with the same symbol, involving no operations"
inline bool SameSpecializationConstants(TIntermTyped* node1, TIntermTyped* node2)
{
return node1->getAsSymbolNode() && node2->getAsSymbolNode() &&
node1->getAsSymbolNode()->getId() == node2->getAsSymbolNode()->getId();
}
} // end namespace glslang
#endif // __INTERMEDIATE_H
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/BaseTypes.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
// Copyright (C) 2017 ARM Limited.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _BASICTYPES_INCLUDED_
#define _BASICTYPES_INCLUDED_
namespace glslang {
//
// Basic type. Arrays, vectors, sampler details, etc., are orthogonal to this.
//
enum TBasicType {
EbtVoid,
EbtFloat,
EbtDouble,
EbtFloat16,
EbtInt8,
EbtUint8,
EbtInt16,
EbtUint16,
EbtInt,
EbtUint,
EbtInt64,
EbtUint64,
EbtBool,
EbtAtomicUint,
EbtSampler,
EbtStruct,
EbtBlock,
EbtAccStruct,
EbtReference,
EbtRayQuery,
EbtHitObjectNV,
EbtCoopmat,
// SPIR-V type defined by spirv_type
EbtSpirvType,
// HLSL types that live only temporarily.
EbtString,
EbtNumTypes
};
//
// Storage qualifiers. Should align with different kinds of storage or
// resource or GLSL storage qualifier. Expansion is deprecated.
//
// N.B.: You probably DON'T want to add anything here, but rather just add it
// to the built-in variables. See the comment above TBuiltInVariable.
//
// A new built-in variable will normally be an existing qualifier, like 'in', 'out', etc.
// DO NOT follow the design pattern of, say EvqInstanceId, etc.
//
enum TStorageQualifier {
EvqTemporary, // For temporaries (within a function), read/write
EvqGlobal, // For globals read/write
EvqConst, // User-defined constant values, will be semantically constant and constant folded
EvqVaryingIn, // pipeline input, read only, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
EvqVaryingOut, // pipeline output, read/write, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
EvqUniform, // read only, shared with app
EvqBuffer, // read/write, shared with app
EvqShared, // compute shader's read/write 'shared' qualifier
EvqSpirvStorageClass, // spirv_storage_class
EvqPayload,
EvqPayloadIn,
EvqHitAttr,
EvqCallableData,
EvqCallableDataIn,
EvqHitObjectAttrNV,
EvqtaskPayloadSharedEXT,
// parameters
EvqIn, // also, for 'in' in the grammar before we know if it's a pipeline input or an 'in' parameter
EvqOut, // also, for 'out' in the grammar before we know if it's a pipeline output or an 'out' parameter
EvqInOut,
EvqConstReadOnly, // input; also other read-only types having neither a constant value nor constant-value semantics
// built-ins read by vertex shader
EvqVertexId,
EvqInstanceId,
// built-ins written by vertex shader
EvqPosition,
EvqPointSize,
EvqClipVertex,
// built-ins read by fragment shader
EvqFace,
EvqFragCoord,
EvqPointCoord,
// built-ins written by fragment shader
EvqFragColor,
EvqFragDepth,
EvqFragStencil,
EvqTileImageEXT,
// end of list
EvqLast
};
//
// Subcategories of the TStorageQualifier, simply to give a direct mapping
// between built-in variable names and an numerical value (the enum).
//
// For backward compatibility, there is some redundancy between the
// TStorageQualifier and these. Existing members should both be maintained accurately.
// However, any new built-in variable (and any existing non-redundant one)
// must follow the pattern that the specific built-in is here, and only its
// general qualifier is in TStorageQualifier.
//
// Something like gl_Position, which is sometimes 'in' and sometimes 'out'
// shows up as two different built-in variables in a single stage, but
// only has a single enum in TBuiltInVariable, so both the
// TStorageQualifier and the TBuitinVariable are needed to distinguish
// between them.
//
enum TBuiltInVariable {
EbvNone,
EbvNumWorkGroups,
EbvWorkGroupSize,
EbvWorkGroupId,
EbvLocalInvocationId,
EbvGlobalInvocationId,
EbvLocalInvocationIndex,
EbvNumSubgroups,
EbvSubgroupID,
EbvSubGroupSize,
EbvSubGroupInvocation,
EbvSubGroupEqMask,
EbvSubGroupGeMask,
EbvSubGroupGtMask,
EbvSubGroupLeMask,
EbvSubGroupLtMask,
EbvSubgroupSize2,
EbvSubgroupInvocation2,
EbvSubgroupEqMask2,
EbvSubgroupGeMask2,
EbvSubgroupGtMask2,
EbvSubgroupLeMask2,
EbvSubgroupLtMask2,
EbvVertexId,
EbvInstanceId,
EbvVertexIndex,
EbvInstanceIndex,
EbvBaseVertex,
EbvBaseInstance,
EbvDrawId,
EbvPosition,
EbvPointSize,
EbvClipVertex,
EbvClipDistance,
EbvCullDistance,
EbvNormal,
EbvVertex,
EbvMultiTexCoord0,
EbvMultiTexCoord1,
EbvMultiTexCoord2,
EbvMultiTexCoord3,
EbvMultiTexCoord4,
EbvMultiTexCoord5,
EbvMultiTexCoord6,
EbvMultiTexCoord7,
EbvFrontColor,
EbvBackColor,
EbvFrontSecondaryColor,
EbvBackSecondaryColor,
EbvTexCoord,
EbvFogFragCoord,
EbvInvocationId,
EbvPrimitiveId,
EbvLayer,
EbvViewportIndex,
EbvPatchVertices,
EbvTessLevelOuter,
EbvTessLevelInner,
EbvBoundingBox,
EbvTessCoord,
EbvColor,
EbvSecondaryColor,
EbvFace,
EbvFragCoord,
EbvPointCoord,
EbvFragColor,
EbvFragData,
EbvFragDepth,
EbvFragStencilRef,
EbvSampleId,
EbvSamplePosition,
EbvSampleMask,
EbvHelperInvocation,
EbvBaryCoordNoPersp,
EbvBaryCoordNoPerspCentroid,
EbvBaryCoordNoPerspSample,
EbvBaryCoordSmooth,
EbvBaryCoordSmoothCentroid,
EbvBaryCoordSmoothSample,
EbvBaryCoordPullModel,
EbvViewIndex,
EbvDeviceIndex,
EbvShadingRateKHR,
EbvPrimitiveShadingRateKHR,
EbvFragSizeEXT,
EbvFragInvocationCountEXT,
EbvSecondaryFragDataEXT,
EbvSecondaryFragColorEXT,
EbvViewportMaskNV,
EbvSecondaryPositionNV,
EbvSecondaryViewportMaskNV,
EbvPositionPerViewNV,
EbvViewportMaskPerViewNV,
EbvFragFullyCoveredNV,
EbvFragmentSizeNV,
EbvInvocationsPerPixelNV,
// ray tracing
EbvLaunchId,
EbvLaunchSize,
EbvInstanceCustomIndex,
EbvGeometryIndex,
EbvWorldRayOrigin,
EbvWorldRayDirection,
EbvObjectRayOrigin,
EbvObjectRayDirection,
EbvRayTmin,
EbvRayTmax,
EbvCullMask,
EbvHitKind,
EbvObjectToWorld,
EbvObjectToWorld3x4,
EbvWorldToObject,
EbvWorldToObject3x4,
EbvIncomingRayFlags,
EbvCurrentRayTimeNV,
// barycentrics
EbvBaryCoordNV,
EbvBaryCoordNoPerspNV,
EbvBaryCoordEXT,
EbvBaryCoordNoPerspEXT,
// mesh shaders
EbvTaskCountNV,
EbvPrimitiveCountNV,
EbvPrimitiveIndicesNV,
EbvClipDistancePerViewNV,
EbvCullDistancePerViewNV,
EbvLayerPerViewNV,
EbvMeshViewCountNV,
EbvMeshViewIndicesNV,
EbvMicroTrianglePositionNV,
EbvMicroTriangleBaryNV,
EbvHitKindFrontFacingMicroTriangleNV,
EbvHitKindBackFacingMicroTriangleNV,
//GL_EXT_mesh_shader
EbvPrimitivePointIndicesEXT,
EbvPrimitiveLineIndicesEXT,
EbvPrimitiveTriangleIndicesEXT,
EbvCullPrimitiveEXT,
// sm builtins
EbvWarpsPerSM,
EbvSMCount,
EbvWarpID,
EbvSMID,
// HLSL built-ins that live only temporarily, until they get remapped
// to one of the above.
EbvFragDepthGreater,
EbvFragDepthLesser,
EbvGsOutputStream,
EbvOutputPatch,
EbvInputPatch,
// structbuffer types
EbvAppendConsume, // no need to differentiate append and consume
EbvRWStructuredBuffer,
EbvStructuredBuffer,
EbvByteAddressBuffer,
EbvRWByteAddressBuffer,
// ARM specific core builtins
EbvCoreCountARM,
EbvCoreIDARM,
EbvCoreMaxIDARM,
EbvWarpIDARM,
EbvWarpMaxIDARM,
EbvPositionFetch,
EbvLast
};
// In this enum, order matters; users can assume higher precision is a bigger value
// and EpqNone is 0.
enum TPrecisionQualifier {
EpqNone = 0,
EpqLow,
EpqMedium,
EpqHigh
};
// These will show up in error messages
__inline const char* GetStorageQualifierString(TStorageQualifier q)
{
switch (q) {
case EvqTemporary: return "temp"; break;
case EvqGlobal: return "global"; break;
case EvqConst: return "const"; break;
case EvqConstReadOnly: return "const (read only)"; break;
case EvqSpirvStorageClass: return "spirv_storage_class"; break;
case EvqVaryingIn: return "in"; break;
case EvqVaryingOut: return "out"; break;
case EvqUniform: return "uniform"; break;
case EvqBuffer: return "buffer"; break;
case EvqShared: return "shared"; break;
case EvqIn: return "in"; break;
case EvqOut: return "out"; break;
case EvqInOut: return "inout"; break;
case EvqVertexId: return "gl_VertexId"; break;
case EvqInstanceId: return "gl_InstanceId"; break;
case EvqPosition: return "gl_Position"; break;
case EvqPointSize: return "gl_PointSize"; break;
case EvqClipVertex: return "gl_ClipVertex"; break;
case EvqFace: return "gl_FrontFacing"; break;
case EvqFragCoord: return "gl_FragCoord"; break;
case EvqPointCoord: return "gl_PointCoord"; break;
case EvqFragColor: return "fragColor"; break;
case EvqFragDepth: return "gl_FragDepth"; break;
case EvqFragStencil: return "gl_FragStencilRefARB"; break;
case EvqPayload: return "rayPayloadNV"; break;
case EvqPayloadIn: return "rayPayloadInNV"; break;
case EvqHitAttr: return "hitAttributeNV"; break;
case EvqCallableData: return "callableDataNV"; break;
case EvqCallableDataIn: return "callableDataInNV"; break;
case EvqtaskPayloadSharedEXT: return "taskPayloadSharedEXT"; break;
case EvqHitObjectAttrNV:return "hitObjectAttributeNV"; break;
default: return "unknown qualifier";
}
}
__inline const char* GetBuiltInVariableString(TBuiltInVariable v)
{
switch (v) {
case EbvNone: return "";
case EbvNumWorkGroups: return "NumWorkGroups";
case EbvWorkGroupSize: return "WorkGroupSize";
case EbvWorkGroupId: return "WorkGroupID";
case EbvLocalInvocationId: return "LocalInvocationID";
case EbvGlobalInvocationId: return "GlobalInvocationID";
case EbvLocalInvocationIndex: return "LocalInvocationIndex";
case EbvNumSubgroups: return "NumSubgroups";
case EbvSubgroupID: return "SubgroupID";
case EbvSubGroupSize: return "SubGroupSize";
case EbvSubGroupInvocation: return "SubGroupInvocation";
case EbvSubGroupEqMask: return "SubGroupEqMask";
case EbvSubGroupGeMask: return "SubGroupGeMask";
case EbvSubGroupGtMask: return "SubGroupGtMask";
case EbvSubGroupLeMask: return "SubGroupLeMask";
case EbvSubGroupLtMask: return "SubGroupLtMask";
case EbvSubgroupSize2: return "SubgroupSize";
case EbvSubgroupInvocation2: return "SubgroupInvocationID";
case EbvSubgroupEqMask2: return "SubgroupEqMask";
case EbvSubgroupGeMask2: return "SubgroupGeMask";
case EbvSubgroupGtMask2: return "SubgroupGtMask";
case EbvSubgroupLeMask2: return "SubgroupLeMask";
case EbvSubgroupLtMask2: return "SubgroupLtMask";
case EbvVertexId: return "VertexId";
case EbvInstanceId: return "InstanceId";
case EbvVertexIndex: return "VertexIndex";
case EbvInstanceIndex: return "InstanceIndex";
case EbvBaseVertex: return "BaseVertex";
case EbvBaseInstance: return "BaseInstance";
case EbvDrawId: return "DrawId";
case EbvPosition: return "Position";
case EbvPointSize: return "PointSize";
case EbvClipVertex: return "ClipVertex";
case EbvClipDistance: return "ClipDistance";
case EbvCullDistance: return "CullDistance";
case EbvNormal: return "Normal";
case EbvVertex: return "Vertex";
case EbvMultiTexCoord0: return "MultiTexCoord0";
case EbvMultiTexCoord1: return "MultiTexCoord1";
case EbvMultiTexCoord2: return "MultiTexCoord2";
case EbvMultiTexCoord3: return "MultiTexCoord3";
case EbvMultiTexCoord4: return "MultiTexCoord4";
case EbvMultiTexCoord5: return "MultiTexCoord5";
case EbvMultiTexCoord6: return "MultiTexCoord6";
case EbvMultiTexCoord7: return "MultiTexCoord7";
case EbvFrontColor: return "FrontColor";
case EbvBackColor: return "BackColor";
case EbvFrontSecondaryColor: return "FrontSecondaryColor";
case EbvBackSecondaryColor: return "BackSecondaryColor";
case EbvTexCoord: return "TexCoord";
case EbvFogFragCoord: return "FogFragCoord";
case EbvInvocationId: return "InvocationID";
case EbvPrimitiveId: return "PrimitiveID";
case EbvLayer: return "Layer";
case EbvViewportIndex: return "ViewportIndex";
case EbvPatchVertices: return "PatchVertices";
case EbvTessLevelOuter: return "TessLevelOuter";
case EbvTessLevelInner: return "TessLevelInner";
case EbvBoundingBox: return "BoundingBox";
case EbvTessCoord: return "TessCoord";
case EbvColor: return "Color";
case EbvSecondaryColor: return "SecondaryColor";
case EbvFace: return "Face";
case EbvFragCoord: return "FragCoord";
case EbvPointCoord: return "PointCoord";
case EbvFragColor: return "FragColor";
case EbvFragData: return "FragData";
case EbvFragDepth: return "FragDepth";
case EbvFragStencilRef: return "FragStencilRef";
case EbvSampleId: return "SampleId";
case EbvSamplePosition: return "SamplePosition";
case EbvSampleMask: return "SampleMaskIn";
case EbvHelperInvocation: return "HelperInvocation";
case EbvBaryCoordNoPersp: return "BaryCoordNoPersp";
case EbvBaryCoordNoPerspCentroid: return "BaryCoordNoPerspCentroid";
case EbvBaryCoordNoPerspSample: return "BaryCoordNoPerspSample";
case EbvBaryCoordSmooth: return "BaryCoordSmooth";
case EbvBaryCoordSmoothCentroid: return "BaryCoordSmoothCentroid";
case EbvBaryCoordSmoothSample: return "BaryCoordSmoothSample";
case EbvBaryCoordPullModel: return "BaryCoordPullModel";
case EbvViewIndex: return "ViewIndex";
case EbvDeviceIndex: return "DeviceIndex";
case EbvFragSizeEXT: return "FragSizeEXT";
case EbvFragInvocationCountEXT: return "FragInvocationCountEXT";
case EbvSecondaryFragDataEXT: return "SecondaryFragDataEXT";
case EbvSecondaryFragColorEXT: return "SecondaryFragColorEXT";
case EbvViewportMaskNV: return "ViewportMaskNV";
case EbvSecondaryPositionNV: return "SecondaryPositionNV";
case EbvSecondaryViewportMaskNV: return "SecondaryViewportMaskNV";
case EbvPositionPerViewNV: return "PositionPerViewNV";
case EbvViewportMaskPerViewNV: return "ViewportMaskPerViewNV";
case EbvFragFullyCoveredNV: return "FragFullyCoveredNV";
case EbvFragmentSizeNV: return "FragmentSizeNV";
case EbvInvocationsPerPixelNV: return "InvocationsPerPixelNV";
case EbvLaunchId: return "LaunchIdNV";
case EbvLaunchSize: return "LaunchSizeNV";
case EbvInstanceCustomIndex: return "InstanceCustomIndexNV";
case EbvGeometryIndex: return "GeometryIndexEXT";
case EbvWorldRayOrigin: return "WorldRayOriginNV";
case EbvWorldRayDirection: return "WorldRayDirectionNV";
case EbvObjectRayOrigin: return "ObjectRayOriginNV";
case EbvObjectRayDirection: return "ObjectRayDirectionNV";
case EbvRayTmin: return "ObjectRayTminNV";
case EbvRayTmax: return "ObjectRayTmaxNV";
case EbvHitKind: return "HitKindNV";
case EbvIncomingRayFlags: return "IncomingRayFlagsNV";
case EbvObjectToWorld: return "ObjectToWorldNV";
case EbvWorldToObject: return "WorldToObjectNV";
case EbvCurrentRayTimeNV: return "CurrentRayTimeNV";
case EbvBaryCoordEXT:
case EbvBaryCoordNV: return "BaryCoordKHR";
case EbvBaryCoordNoPerspEXT:
case EbvBaryCoordNoPerspNV: return "BaryCoordNoPerspKHR";
case EbvTaskCountNV: return "TaskCountNV";
case EbvPrimitiveCountNV: return "PrimitiveCountNV";
case EbvPrimitiveIndicesNV: return "PrimitiveIndicesNV";
case EbvClipDistancePerViewNV: return "ClipDistancePerViewNV";
case EbvCullDistancePerViewNV: return "CullDistancePerViewNV";
case EbvLayerPerViewNV: return "LayerPerViewNV";
case EbvMeshViewCountNV: return "MeshViewCountNV";
case EbvMeshViewIndicesNV: return "MeshViewIndicesNV";
// GL_EXT_mesh_shader
case EbvPrimitivePointIndicesEXT: return "PrimitivePointIndicesEXT";
case EbvPrimitiveLineIndicesEXT: return "PrimitiveLineIndicesEXT";
case EbvPrimitiveTriangleIndicesEXT: return "PrimitiveTriangleIndicesEXT";
case EbvCullPrimitiveEXT: return "CullPrimitiveEXT";
case EbvWarpsPerSM: return "WarpsPerSMNV";
case EbvSMCount: return "SMCountNV";
case EbvWarpID: return "WarpIDNV";
case EbvSMID: return "SMIDNV";
case EbvShadingRateKHR: return "ShadingRateKHR";
case EbvPrimitiveShadingRateKHR: return "PrimitiveShadingRateKHR";
case EbvHitKindFrontFacingMicroTriangleNV: return "HitKindFrontFacingMicroTriangleNV";
case EbvHitKindBackFacingMicroTriangleNV: return "HitKindBackFacingMicroTriangleNV";
default: return "unknown built-in variable";
}
}
__inline const char* GetPrecisionQualifierString(TPrecisionQualifier p)
{
switch (p) {
case EpqNone: return ""; break;
case EpqLow: return "lowp"; break;
case EpqMedium: return "mediump"; break;
case EpqHigh: return "highp"; break;
default: return "unknown precision qualifier";
}
}
__inline bool isTypeSignedInt(TBasicType type)
{
switch (type) {
case EbtInt8:
case EbtInt16:
case EbtInt:
case EbtInt64:
return true;
default:
return false;
}
}
__inline bool isTypeUnsignedInt(TBasicType type)
{
switch (type) {
case EbtUint8:
case EbtUint16:
case EbtUint:
case EbtUint64:
return true;
default:
return false;
}
}
__inline bool isTypeInt(TBasicType type)
{
return isTypeSignedInt(type) || isTypeUnsignedInt(type);
}
__inline bool isTypeFloat(TBasicType type)
{
switch (type) {
case EbtFloat:
case EbtDouble:
case EbtFloat16:
return true;
default:
return false;
}
}
__inline int getTypeRank(TBasicType type)
{
int res = -1;
switch(type) {
case EbtInt8:
case EbtUint8:
res = 0;
break;
case EbtInt16:
case EbtUint16:
res = 1;
break;
case EbtInt:
case EbtUint:
res = 2;
break;
case EbtInt64:
case EbtUint64:
res = 3;
break;
default:
assert(false);
break;
}
return res;
}
} // end namespace glslang
#endif // _BASICTYPES_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/Common.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _COMMON_INCLUDED_
#define _COMMON_INCLUDED_
#include <algorithm>
#include <cassert>
#ifdef _MSC_VER
#include <cfloat>
#else
#include <cmath>
#endif
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <list>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#if defined(__ANDROID__)
#include <sstream>
namespace std {
template<typename T>
std::string to_string(const T& val) {
std::ostringstream os;
os << val;
return os.str();
}
}
#endif
#if defined(MINGW_HAS_SECURE_API) && MINGW_HAS_SECURE_API
#include <basetsd.h>
#ifndef snprintf
#define snprintf sprintf_s
#endif
#define safe_vsprintf(buf,max,format,args) vsnprintf_s((buf), (max), (max), (format), (args))
#elif defined (solaris)
#define safe_vsprintf(buf,max,format,args) vsnprintf((buf), (max), (format), (args))
#include <sys/int_types.h>
#define UINT_PTR uintptr_t
#else
#define safe_vsprintf(buf,max,format,args) vsnprintf((buf), (max), (format), (args))
#include <stdint.h>
#define UINT_PTR uintptr_t
#endif
#if defined(_MSC_VER)
#define strdup _strdup
#endif
/* windows only pragma */
#ifdef _MSC_VER
#pragma warning(disable : 4786) // Don't warn about too long identifiers
#pragma warning(disable : 4514) // unused inline method
#pragma warning(disable : 4201) // nameless union
#endif
#include "PoolAlloc.h"
//
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
//
#define POOL_ALLOCATOR_NEW_DELETE(A) \
void* operator new(size_t s) { return (A).allocate(s); } \
void* operator new(size_t, void *_Where) { return (_Where); } \
void operator delete(void*) { } \
void operator delete(void *, void *) { } \
void* operator new[](size_t s) { return (A).allocate(s); } \
void* operator new[](size_t, void *_Where) { return (_Where); } \
void operator delete[](void*) { } \
void operator delete[](void *, void *) { }
namespace glslang {
//
// Pool version of string.
//
typedef pool_allocator<char> TStringAllocator;
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
} // end namespace glslang
// Repackage the std::hash for use by unordered map/set with a TString key.
namespace std {
template<> struct hash<glslang::TString> {
std::size_t operator()(const glslang::TString& s) const
{
const unsigned _FNV_offset_basis = 2166136261U;
const unsigned _FNV_prime = 16777619U;
unsigned _Val = _FNV_offset_basis;
size_t _Count = s.size();
const char* _First = s.c_str();
for (size_t _Next = 0; _Next < _Count; ++_Next)
{
_Val ^= (unsigned)_First[_Next];
_Val *= _FNV_prime;
}
return _Val;
}
};
}
namespace glslang {
inline TString* NewPoolTString(const char* s)
{
void* memory = GetThreadPoolAllocator().allocate(sizeof(TString));
return new(memory) TString(s);
}
template<class T> inline T* NewPoolObject(T*)
{
return new(GetThreadPoolAllocator().allocate(sizeof(T))) T;
}
template<class T> inline T* NewPoolObject(T, int instances)
{
return new(GetThreadPoolAllocator().allocate(instances * sizeof(T))) T[instances];
}
inline bool StartsWith(TString const &str, const char *prefix)
{
return str.compare(0, strlen(prefix), prefix) == 0;
}
//
// Pool allocator versions of vectors, lists, and maps
//
template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
TVector() : std::vector<T, pool_allocator<T> >() {}
TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
TVector(size_type i) : std::vector<T, pool_allocator<T> >(i) {}
TVector(size_type i, const T& val) : std::vector<T, pool_allocator<T> >(i, val) {}
};
template <class T> class TList : public std::list<T, pool_allocator<T> > {
};
template <class K, class D, class CMP = std::less<K> >
class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<K const, D> > > {
};
template <class K, class D, class HASH = std::hash<K>, class PRED = std::equal_to<K> >
class TUnorderedMap : public std::unordered_map<K, D, HASH, PRED, pool_allocator<std::pair<K const, D> > > {
};
template <class K, class CMP = std::less<K> >
class TSet : public std::set<K, CMP, pool_allocator<K> > {
};
//
// Persistent string memory. Should only be used for strings that survive
// across compiles/links.
//
typedef std::basic_string<char> TPersistString;
//
// templatized min and max functions.
//
template <class T> T Min(const T a, const T b) { return a < b ? a : b; }
template <class T> T Max(const T a, const T b) { return a > b ? a : b; }
//
// Create a TString object from an integer.
//
#if defined(_MSC_VER) || (defined(MINGW_HAS_SECURE_API) && MINGW_HAS_SECURE_API)
inline const TString String(const int i, const int base = 10)
{
char text[16]; // 32 bit ints are at most 10 digits in base 10
_itoa_s(i, text, sizeof(text), base);
return text;
}
#else
inline const TString String(const int i, const int /*base*/ = 10)
{
char text[16]; // 32 bit ints are at most 10 digits in base 10
// we assume base 10 for all cases
snprintf(text, sizeof(text), "%d", i);
return text;
}
#endif
struct TSourceLoc {
void init()
{
name = nullptr; string = 0; line = 0; column = 0;
}
void init(int stringNum) { init(); string = stringNum; }
// Returns the name if it exists. Otherwise, returns the string number.
std::string getStringNameOrNum(bool quoteStringName = true) const
{
if (name != nullptr) {
TString qstr = quoteStringName ? ("\"" + *name + "\"") : *name;
std::string ret_str(qstr.c_str());
return ret_str;
}
return std::to_string((long long)string);
}
const char* getFilename() const
{
if (name == nullptr)
return nullptr;
return name->c_str();
}
const char* getFilenameStr() const { return name == nullptr ? "" : name->c_str(); }
TString* name; // descriptive name for this string, when a textual name is available, otherwise nullptr
int string;
int line;
int column;
};
class TPragmaTable : public TMap<TString, TString> {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
};
const int MaxTokenLength = 1024;
template <class T> bool IsPow2(T powerOf2)
{
if (powerOf2 <= 0)
return false;
return (powerOf2 & (powerOf2 - 1)) == 0;
}
// Round number up to a multiple of the given powerOf2, which is not
// a power, just a number that must be a power of 2.
template <class T> void RoundToPow2(T& number, int powerOf2)
{
assert(IsPow2(powerOf2));
number = (number + powerOf2 - 1) & ~(powerOf2 - 1);
}
template <class T> bool IsMultipleOfPow2(T number, int powerOf2)
{
assert(IsPow2(powerOf2));
return ! (number & (powerOf2 - 1));
}
// Returns log2 of an integer power of 2.
// T should be integral.
template <class T> int IntLog2(T n)
{
assert(IsPow2(n));
int result = 0;
while ((T(1) << result) != n) {
result++;
}
return result;
}
} // end namespace glslang
#endif // _COMMON_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/arrays.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Implement types for tracking GLSL arrays, arrays of arrays, etc.
//
#ifndef _ARRAYS_INCLUDED
#define _ARRAYS_INCLUDED
#include <algorithm>
namespace glslang {
// This is used to mean there is no size yet (unsized), it is waiting to get a size from somewhere else.
const int UnsizedArraySize = 0;
class TIntermTyped;
extern bool SameSpecializationConstants(TIntermTyped*, TIntermTyped*);
// Specialization constants need both a nominal size and a node that defines
// the specialization constant being used. Array types are the same when their
// size and specialization constant nodes are the same.
struct TArraySize {
unsigned int size;
TIntermTyped* node; // nullptr means no specialization constant node
bool operator==(const TArraySize& rhs) const
{
if (size != rhs.size)
return false;
if (node == nullptr || rhs.node == nullptr)
return node == rhs.node;
return SameSpecializationConstants(node, rhs.node);
}
};
//
// TSmallArrayVector is used as the container for the set of sizes in TArraySizes.
// It has generic-container semantics, while TArraySizes has array-of-array semantics.
// That is, TSmallArrayVector should be more focused on mechanism and TArraySizes on policy.
//
struct TSmallArrayVector {
//
// TODO: memory: TSmallArrayVector is intended to be smaller.
// Almost all arrays could be handled by two sizes each fitting
// in 16 bits, needing a real vector only in the cases where there
// are more than 3 sizes or a size needing more than 16 bits.
//
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TSmallArrayVector() : sizes(nullptr) { }
virtual ~TSmallArrayVector() { dealloc(); }
// For breaking into two non-shared copies, independently modifiable.
TSmallArrayVector& operator=(const TSmallArrayVector& from)
{
if (from.sizes == nullptr)
sizes = nullptr;
else {
alloc();
*sizes = *from.sizes;
}
return *this;
}
int size() const
{
if (sizes == nullptr)
return 0;
return (int)sizes->size();
}
unsigned int frontSize() const
{
assert(sizes != nullptr && sizes->size() > 0);
return sizes->front().size;
}
TIntermTyped* frontNode() const
{
assert(sizes != nullptr && sizes->size() > 0);
return sizes->front().node;
}
void changeFront(unsigned int s)
{
assert(sizes != nullptr);
// this should only happen for implicitly sized arrays, not specialization constants
assert(sizes->front().node == nullptr);
sizes->front().size = s;
}
void push_back(unsigned int e, TIntermTyped* n)
{
alloc();
TArraySize pair = { e, n };
sizes->push_back(pair);
}
void push_back(const TSmallArrayVector& newDims)
{
alloc();
sizes->insert(sizes->end(), newDims.sizes->begin(), newDims.sizes->end());
}
void pop_front()
{
assert(sizes != nullptr && sizes->size() > 0);
if (sizes->size() == 1)
dealloc();
else
sizes->erase(sizes->begin());
}
void pop_back()
{
assert(sizes != nullptr && sizes->size() > 0);
if (sizes->size() == 1)
dealloc();
else
sizes->resize(sizes->size() - 1);
}
// 'this' should currently not be holding anything, and copyNonFront
// will make it hold a copy of all but the first element of rhs.
// (This would be useful for making a type that is dereferenced by
// one dimension.)
void copyNonFront(const TSmallArrayVector& rhs)
{
assert(sizes == nullptr);
if (rhs.size() > 1) {
alloc();
sizes->insert(sizes->begin(), rhs.sizes->begin() + 1, rhs.sizes->end());
}
}
unsigned int getDimSize(int i) const
{
assert(sizes != nullptr && (int)sizes->size() > i);
return (*sizes)[i].size;
}
void setDimSize(int i, unsigned int size) const
{
assert(sizes != nullptr && (int)sizes->size() > i);
assert((*sizes)[i].node == nullptr);
(*sizes)[i].size = size;
}
TIntermTyped* getDimNode(int i) const
{
assert(sizes != nullptr && (int)sizes->size() > i);
return (*sizes)[i].node;
}
bool operator==(const TSmallArrayVector& rhs) const
{
if (sizes == nullptr && rhs.sizes == nullptr)
return true;
if (sizes == nullptr || rhs.sizes == nullptr)
return false;
return *sizes == *rhs.sizes;
}
bool operator!=(const TSmallArrayVector& rhs) const { return ! operator==(rhs); }
protected:
TSmallArrayVector(const TSmallArrayVector&);
void alloc()
{
if (sizes == nullptr)
sizes = new TVector<TArraySize>;
}
void dealloc()
{
delete sizes;
sizes = nullptr;
}
TVector<TArraySize>* sizes; // will either hold such a pointer, or in the future, hold the two array sizes
};
//
// Represent an array, or array of arrays, to arbitrary depth. This is not
// done through a hierarchy of types in a type tree, rather all contiguous arrayness
// in the type hierarchy is localized into this single cumulative object.
//
// The arrayness in TTtype is a pointer, so that it can be non-allocated and zero
// for the vast majority of types that are non-array types.
//
// Order Policy: these are all identical:
// - left to right order within a contiguous set of ...[..][..][..]... in the source language
// - index order 0, 1, 2, ... within the 'sizes' member below
// - outer-most to inner-most
//
struct TArraySizes {
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TArraySizes() : implicitArraySize(0), implicitlySized(true), variablyIndexed(false){ }
// For breaking into two non-shared copies, independently modifiable.
TArraySizes& operator=(const TArraySizes& from)
{
implicitArraySize = from.implicitArraySize;
variablyIndexed = from.variablyIndexed;
sizes = from.sizes;
implicitlySized = from.implicitlySized;
return *this;
}
// translate from array-of-array semantics to container semantics
int getNumDims() const { return sizes.size(); }
int getDimSize(int dim) const { return sizes.getDimSize(dim); }
TIntermTyped* getDimNode(int dim) const { return sizes.getDimNode(dim); }
void setDimSize(int dim, int size) { sizes.setDimSize(dim, size); }
int getOuterSize() const { return sizes.frontSize(); }
TIntermTyped* getOuterNode() const { return sizes.frontNode(); }
int getCumulativeSize() const
{
int size = 1;
for (int d = 0; d < sizes.size(); ++d) {
// this only makes sense in paths that have a known array size
assert(sizes.getDimSize(d) != UnsizedArraySize);
size *= sizes.getDimSize(d);
}
return size;
}
void addInnerSize() { addInnerSize((unsigned)UnsizedArraySize); }
void addInnerSize(int s) { addInnerSize((unsigned)s, nullptr); }
void addInnerSize(int s, TIntermTyped* n) { sizes.push_back((unsigned)s, n); }
void addInnerSize(TArraySize pair) {
sizes.push_back(pair.size, pair.node);
implicitlySized = false;
}
void addInnerSizes(const TArraySizes& s) { sizes.push_back(s.sizes); }
void changeOuterSize(int s) {
sizes.changeFront((unsigned)s);
implicitlySized = false;
}
int getImplicitSize() const { return implicitArraySize > 0 ? implicitArraySize : 1; }
void updateImplicitSize(int s) {
implicitArraySize = (std::max)(implicitArraySize, s);
}
bool isInnerUnsized() const
{
for (int d = 1; d < sizes.size(); ++d) {
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
return true;
}
return false;
}
bool clearInnerUnsized()
{
for (int d = 1; d < sizes.size(); ++d) {
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
setDimSize(d, 1);
}
return false;
}
bool isInnerSpecialization() const
{
for (int d = 1; d < sizes.size(); ++d) {
if (sizes.getDimNode(d) != nullptr)
return true;
}
return false;
}
bool isOuterSpecialization()
{
return sizes.getDimNode(0) != nullptr;
}
bool hasUnsized() const { return getOuterSize() == UnsizedArraySize || isInnerUnsized(); }
bool isSized() const { return getOuterSize() != UnsizedArraySize; }
bool isImplicitlySized() const { return implicitlySized; }
bool isDefaultImplicitlySized() const { return implicitlySized && implicitArraySize == 0; }
void setImplicitlySized(bool isImplicitSizing) { implicitlySized = isImplicitSizing; }
void dereference() { sizes.pop_front(); }
void removeLastSize() { sizes.pop_back(); }
void copyDereferenced(const TArraySizes& rhs)
{
assert(sizes.size() == 0);
if (rhs.sizes.size() > 1)
sizes.copyNonFront(rhs.sizes);
}
bool sameInnerArrayness(const TArraySizes& rhs) const
{
if (sizes.size() != rhs.sizes.size())
return false;
for (int d = 1; d < sizes.size(); ++d) {
if (sizes.getDimSize(d) != rhs.sizes.getDimSize(d) ||
sizes.getDimNode(d) != rhs.sizes.getDimNode(d))
return false;
}
return true;
}
void setVariablyIndexed() { variablyIndexed = true; }
bool isVariablyIndexed() const { return variablyIndexed; }
bool operator==(const TArraySizes& rhs) const { return sizes == rhs.sizes; }
bool operator!=(const TArraySizes& rhs) const { return sizes != rhs.sizes; }
protected:
TSmallArrayVector sizes;
TArraySizes(const TArraySizes&);
// For tracking maximum referenced compile-time constant index.
// Applies only to the outer-most dimension. Potentially becomes
// the implicit size of the array, if not variably indexed and
// otherwise legal.
int implicitArraySize;
bool implicitlySized;
bool variablyIndexed; // true if array is indexed with a non compile-time constant
};
} // end namespace glslang
#endif // _ARRAYS_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/ShHandle.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _SHHANDLE_INCLUDED_
#define _SHHANDLE_INCLUDED_
//
// Machine independent part of the compiler private objects
// sent as ShHandle to the driver.
//
// This should not be included by driver code.
//
#define SH_EXPORTING
#include "../Public/ShaderLang.h"
#include "../MachineIndependent/Versions.h"
#include "InfoSink.h"
class TCompiler;
class TLinker;
class TUniformMap;
//
// The base class used to back handles returned to the driver.
//
class TShHandleBase {
public:
TShHandleBase() { pool = new glslang::TPoolAllocator; }
virtual ~TShHandleBase() { delete pool; }
virtual TCompiler* getAsCompiler() { return nullptr; }
virtual TLinker* getAsLinker() { return nullptr; }
virtual TUniformMap* getAsUniformMap() { return nullptr; }
virtual glslang::TPoolAllocator* getPool() const { return pool; }
private:
glslang::TPoolAllocator* pool;
};
//
// The base class for the machine dependent linker to derive from
// for managing where uniforms live.
//
class TUniformMap : public TShHandleBase {
public:
TUniformMap() { }
virtual ~TUniformMap() { }
virtual TUniformMap* getAsUniformMap() { return this; }
virtual int getLocation(const char* name) = 0;
virtual TInfoSink& getInfoSink() { return infoSink; }
TInfoSink infoSink;
};
class TIntermNode;
//
// The base class for the machine dependent compiler to derive from
// for managing object code from the compile.
//
class TCompiler : public TShHandleBase {
public:
TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { }
virtual ~TCompiler() { }
EShLanguage getLanguage() { return language; }
virtual TInfoSink& getInfoSink() { return infoSink; }
virtual bool compile(TIntermNode* root, int version = 0, EProfile profile = ENoProfile) = 0;
virtual TCompiler* getAsCompiler() { return this; }
virtual bool linkable() { return haveValidObjectCode; }
TInfoSink& infoSink;
protected:
TCompiler& operator=(TCompiler&);
EShLanguage language;
bool haveValidObjectCode;
};
//
// Link operations are based on a list of compile results...
//
typedef glslang::TVector<TCompiler*> TCompilerList;
typedef glslang::TVector<TShHandleBase*> THandleList;
//
// The base class for the machine dependent linker to derive from
// to manage the resulting executable.
//
class TLinker : public TShHandleBase {
public:
TLinker(EShExecutable e, TInfoSink& iSink) :
infoSink(iSink),
executable(e),
haveReturnableObjectCode(false),
appAttributeBindings(nullptr),
fixedAttributeBindings(nullptr),
excludedAttributes(nullptr),
excludedCount(0),
uniformBindings(nullptr) { }
virtual TLinker* getAsLinker() { return this; }
virtual ~TLinker() { }
virtual bool link(TCompilerList&, TUniformMap*) = 0;
virtual bool link(THandleList&) { return false; }
virtual void setAppAttributeBindings(const ShBindingTable* t) { appAttributeBindings = t; }
virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }
virtual void getAttributeBindings(ShBindingTable const **t) const = 0;
virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }
virtual ShBindingTable* getUniformBindings() const { return uniformBindings; }
virtual const void* getObjectCode() const { return nullptr; } // a real compiler would be returning object code here
virtual TInfoSink& getInfoSink() { return infoSink; }
TInfoSink& infoSink;
protected:
TLinker& operator=(TLinker&);
EShExecutable executable;
bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver
const ShBindingTable* appAttributeBindings;
const ShBindingTable* fixedAttributeBindings;
const int* excludedAttributes;
int excludedCount;
ShBindingTable* uniformBindings; // created by the linker
};
//
// This is the interface between the machine independent code
// and the machine dependent code.
//
// The machine dependent code should derive from the classes
// above. Then Construct*() and Delete*() will create and
// destroy the machine dependent objects, which contain the
// above machine independent information.
//
TCompiler* ConstructCompiler(EShLanguage, int);
TShHandleBase* ConstructLinker(EShExecutable, int);
TShHandleBase* ConstructBindings();
void DeleteLinker(TShHandleBase*);
void DeleteBindingList(TShHandleBase* bindingList);
TUniformMap* ConstructUniformMap();
void DeleteCompiler(TCompiler*);
void DeleteUniformMap(TUniformMap*);
#endif // _SHHANDLE_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/Types.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2016 LunarG, Inc.
// Copyright (C) 2015-2016 Google, Inc.
// Copyright (C) 2017 ARM Limited.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _TYPES_INCLUDED
#define _TYPES_INCLUDED
#include "../Include/Common.h"
#include "../Include/BaseTypes.h"
#include "../Public/ShaderLang.h"
#include "arrays.h"
#include "SpirvIntrinsics.h"
#include <algorithm>
namespace glslang {
class TIntermAggregate;
const int GlslangMaxTypeLength = 200; // TODO: need to print block/struct one member per line, so this can stay bounded
const char* const AnonymousPrefix = "anon@"; // for something like a block whose members can be directly accessed
inline bool IsAnonymous(const TString& name)
{
return name.compare(0, 5, AnonymousPrefix) == 0;
}
//
// Details within a sampler type
//
enum TSamplerDim {
EsdNone,
Esd1D,
Esd2D,
Esd3D,
EsdCube,
EsdRect,
EsdBuffer,
EsdSubpass, // goes only with non-sampled image (image is true)
EsdAttachmentEXT,
EsdNumDims
};
struct TSampler { // misnomer now; includes images, textures without sampler, and textures with sampler
TBasicType type : 8; // type returned by sampler
TSamplerDim dim : 8;
bool arrayed : 1;
bool shadow : 1;
bool ms : 1;
bool image : 1; // image, combined should be false
bool combined : 1; // true means texture is combined with a sampler, false means texture with no sampler
bool sampler : 1; // true means a pure sampler, other fields should be clear()
unsigned int vectorSize : 3; // vector return type size.
// Some languages support structures as sample results. Storing the whole structure in the
// TSampler is too large, so there is an index to a separate table.
static const unsigned structReturnIndexBits = 4; // number of index bits to use.
static const unsigned structReturnSlots = (1<<structReturnIndexBits)-1; // number of valid values
static const unsigned noReturnStruct = structReturnSlots; // value if no return struct type.
// Index into a language specific table of texture return structures.
unsigned int structReturnIndex : structReturnIndexBits;
bool external : 1; // GL_OES_EGL_image_external
bool yuv : 1; // GL_EXT_YUV_target
#ifdef ENABLE_HLSL
unsigned int getVectorSize() const { return vectorSize; }
void clearReturnStruct() { structReturnIndex = noReturnStruct; }
bool hasReturnStruct() const { return structReturnIndex != noReturnStruct; }
unsigned getStructReturnIndex() const { return structReturnIndex; }
#endif
bool is1D() const { return dim == Esd1D; }
bool is2D() const { return dim == Esd2D; }
bool isBuffer() const { return dim == EsdBuffer; }
bool isRect() const { return dim == EsdRect; }
bool isSubpass() const { return dim == EsdSubpass; }
bool isAttachmentEXT() const { return dim == EsdAttachmentEXT; }
bool isCombined() const { return combined; }
bool isImage() const { return image && !isSubpass() && !isAttachmentEXT();}
bool isImageClass() const { return image; }
bool isMultiSample() const { return ms; }
bool isExternal() const { return external; }
void setExternal(bool e) { external = e; }
bool isYuv() const { return yuv; }
bool isTexture() const { return !sampler && !image; }
bool isPureSampler() const { return sampler; }
void setCombined(bool c) { combined = c; }
void setBasicType(TBasicType t) { type = t; }
TBasicType getBasicType() const { return type; }
bool isShadow() const { return shadow; }
bool isArrayed() const { return arrayed; }
void clear()
{
type = EbtVoid;
dim = EsdNone;
arrayed = false;
shadow = false;
ms = false;
image = false;
combined = false;
sampler = false;
external = false;
yuv = false;
#ifdef ENABLE_HLSL
clearReturnStruct();
// by default, returns a single vec4;
vectorSize = 4;
#endif
}
// make a combined sampler and texture
void set(TBasicType t, TSamplerDim d, bool a = false, bool s = false, bool m = false)
{
clear();
type = t;
dim = d;
arrayed = a;
shadow = s;
ms = m;
combined = true;
}
// make an image
void setImage(TBasicType t, TSamplerDim d, bool a = false, bool s = false, bool m = false)
{
clear();
type = t;
dim = d;
arrayed = a;
shadow = s;
ms = m;
image = true;
}
// make a texture with no sampler
void setTexture(TBasicType t, TSamplerDim d, bool a = false, bool s = false, bool m = false)
{
clear();
type = t;
dim = d;
arrayed = a;
shadow = s;
ms = m;
}
// make a pure sampler, no texture, no image, nothing combined, the 'sampler' keyword
void setPureSampler(bool s)
{
clear();
sampler = true;
shadow = s;
}
// make a subpass input attachment
void setSubpass(TBasicType t, bool m = false)
{
clear();
type = t;
image = true;
dim = EsdSubpass;
ms = m;
}
// make an AttachmentEXT
void setAttachmentEXT(TBasicType t)
{
clear();
type = t;
image = true;
dim = EsdAttachmentEXT;
}
bool operator==(const TSampler& right) const
{
return type == right.type &&
dim == right.dim &&
arrayed == right.arrayed &&
shadow == right.shadow &&
isMultiSample() == right.isMultiSample() &&
isImageClass() == right.isImageClass() &&
isCombined() == right.isCombined() &&
isPureSampler() == right.isPureSampler() &&
isExternal() == right.isExternal() &&
isYuv() == right.isYuv()
#ifdef ENABLE_HLSL
&& getVectorSize() == right.getVectorSize() &&
getStructReturnIndex() == right.getStructReturnIndex()
#endif
;
}
bool operator!=(const TSampler& right) const
{
return ! operator==(right);
}
TString getString() const
{
TString s;
if (isPureSampler()) {
s.append("sampler");
return s;
}
switch (type) {
case EbtInt: s.append("i"); break;
case EbtUint: s.append("u"); break;
case EbtFloat16: s.append("f16"); break;
case EbtInt8: s.append("i8"); break;
case EbtUint16: s.append("u8"); break;
case EbtInt16: s.append("i16"); break;
case EbtUint8: s.append("u16"); break;
case EbtInt64: s.append("i64"); break;
case EbtUint64: s.append("u64"); break;
default: break;
}
if (isImageClass()) {
if (isAttachmentEXT())
s.append("attachmentEXT");
else if (isSubpass())
s.append("subpass");
else
s.append("image");
} else if (isCombined()) {
s.append("sampler");
} else {
s.append("texture");
}
if (isExternal()) {
s.append("ExternalOES");
return s;
}
if (isYuv()) {
return "__" + s + "External2DY2YEXT";
}
switch (dim) {
case Esd2D: s.append("2D"); break;
case Esd3D: s.append("3D"); break;
case EsdCube: s.append("Cube"); break;
case Esd1D: s.append("1D"); break;
case EsdRect: s.append("2DRect"); break;
case EsdBuffer: s.append("Buffer"); break;
case EsdSubpass: s.append("Input"); break;
case EsdAttachmentEXT: s.append(""); break;
default: break; // some compilers want this
}
if (isMultiSample())
s.append("MS");
if (arrayed)
s.append("Array");
if (shadow)
s.append("Shadow");
return s;
}
};
//
// Need to have association of line numbers to types in a list for building structs.
//
class TType;
struct TTypeLoc {
TType* type;
TSourceLoc loc;
};
typedef TVector<TTypeLoc> TTypeList;
typedef TVector<TString*> TIdentifierList;
//
// Following are a series of helper enums for managing layouts and qualifiers,
// used for TPublicType, TType, others.
//
enum TLayoutPacking {
ElpNone,
ElpShared, // default, but different than saying nothing
ElpStd140,
ElpStd430,
ElpPacked,
ElpScalar,
ElpCount // If expanding, see bitfield width below
};
enum TLayoutMatrix {
ElmNone,
ElmRowMajor,
ElmColumnMajor, // default, but different than saying nothing
ElmCount // If expanding, see bitfield width below
};
// Union of geometry shader and tessellation shader geometry types.
// They don't go into TType, but rather have current state per shader or
// active parser type (TPublicType).
enum TLayoutGeometry {
ElgNone,
ElgPoints,
ElgLines,
ElgLinesAdjacency,
ElgLineStrip,
ElgTriangles,
ElgTrianglesAdjacency,
ElgTriangleStrip,
ElgQuads,
ElgIsolines,
};
enum TVertexSpacing {
EvsNone,
EvsEqual,
EvsFractionalEven,
EvsFractionalOdd
};
enum TVertexOrder {
EvoNone,
EvoCw,
EvoCcw
};
// Note: order matters, as type of format is done by comparison.
enum TLayoutFormat {
ElfNone,
// Float image
ElfRgba32f,
ElfRgba16f,
ElfR32f,
ElfRgba8,
ElfRgba8Snorm,
ElfEsFloatGuard, // to help with comparisons
ElfRg32f,
ElfRg16f,
ElfR11fG11fB10f,
ElfR16f,
ElfRgba16,
ElfRgb10A2,
ElfRg16,
ElfRg8,
ElfR16,
ElfR8,
ElfRgba16Snorm,
ElfRg16Snorm,
ElfRg8Snorm,
ElfR16Snorm,
ElfR8Snorm,
ElfFloatGuard, // to help with comparisons
// Int image
ElfRgba32i,
ElfRgba16i,
ElfRgba8i,
ElfR32i,
ElfEsIntGuard, // to help with comparisons
ElfRg32i,
ElfRg16i,
ElfRg8i,
ElfR16i,
ElfR8i,
ElfR64i,
ElfIntGuard, // to help with comparisons
// Uint image
ElfRgba32ui,
ElfRgba16ui,
ElfRgba8ui,
ElfR32ui,
ElfEsUintGuard, // to help with comparisons
ElfRg32ui,
ElfRg16ui,
ElfRgb10a2ui,
ElfRg8ui,
ElfR16ui,
ElfR8ui,
ElfR64ui,
ElfExtSizeGuard, // to help with comparisons
ElfSize1x8,
ElfSize1x16,
ElfSize1x32,
ElfSize2x32,
ElfSize4x32,
ElfCount
};
enum TLayoutDepth {
EldNone,
EldAny,
EldGreater,
EldLess,
EldUnchanged,
EldCount
};
enum TLayoutStencil {
ElsNone,
ElsRefUnchangedFrontAMD,
ElsRefGreaterFrontAMD,
ElsRefLessFrontAMD,
ElsRefUnchangedBackAMD,
ElsRefGreaterBackAMD,
ElsRefLessBackAMD,
ElsCount
};
enum TBlendEquationShift {
// No 'EBlendNone':
// These are used as bit-shift amounts. A mask of such shifts will have type 'int',
// and in that space, 0 means no bits set, or none. In this enum, 0 means (1 << 0), a bit is set.
EBlendMultiply,
EBlendScreen,
EBlendOverlay,
EBlendDarken,
EBlendLighten,
EBlendColordodge,
EBlendColorburn,
EBlendHardlight,
EBlendSoftlight,
EBlendDifference,
EBlendExclusion,
EBlendHslHue,
EBlendHslSaturation,
EBlendHslColor,
EBlendHslLuminosity,
EBlendAllEquations,
EBlendCount
};
enum TInterlockOrdering {
EioNone,
EioPixelInterlockOrdered,
EioPixelInterlockUnordered,
EioSampleInterlockOrdered,
EioSampleInterlockUnordered,
EioShadingRateInterlockOrdered,
EioShadingRateInterlockUnordered,
EioCount,
};
enum TShaderInterface
{
// Includes both uniform blocks and buffer blocks
EsiUniform = 0,
EsiInput,
EsiOutput,
EsiNone,
EsiCount
};
class TQualifier {
public:
static const int layoutNotSet = -1;
void clear()
{
precision = EpqNone;
invariant = false;
makeTemporary();
declaredBuiltIn = EbvNone;
noContraction = false;
nullInit = false;
spirvByReference = false;
spirvLiteral = false;
defaultBlock = false;
}
// drop qualifiers that don't belong in a temporary variable
void makeTemporary()
{
semanticName = nullptr;
storage = EvqTemporary;
builtIn = EbvNone;
clearInterstage();
clearMemory();
specConstant = false;
nonUniform = false;
nullInit = false;
defaultBlock = false;
clearLayout();
spirvStorageClass = -1;
spirvDecorate = nullptr;
spirvByReference = false;
spirvLiteral = false;
}
void clearInterstage()
{
clearInterpolation();
patch = false;
sample = false;
}
void clearInterpolation()
{
centroid = false;
smooth = false;
flat = false;
nopersp = false;
explicitInterp = false;
pervertexNV = false;
perPrimitiveNV = false;
perViewNV = false;
perTaskNV = false;
pervertexEXT = false;
}
void clearMemory()
{
coherent = false;
devicecoherent = false;
queuefamilycoherent = false;
workgroupcoherent = false;
subgroupcoherent = false;
shadercallcoherent = false;
nonprivate = false;
volatil = false;
restrict = false;
readonly = false;
writeonly = false;
}
const char* semanticName;
TStorageQualifier storage : 7;
static_assert(EvqLast < 64, "need to increase size of TStorageQualifier bitfields!");
TBuiltInVariable builtIn : 9;
TBuiltInVariable declaredBuiltIn : 9;
static_assert(EbvLast < 256, "need to increase size of TBuiltInVariable bitfields!");
TPrecisionQualifier precision : 3;
bool invariant : 1; // require canonical treatment for cross-shader invariance
bool centroid : 1;
bool smooth : 1;
bool flat : 1;
// having a constant_id is not sufficient: expressions have no id, but are still specConstant
bool specConstant : 1;
bool nonUniform : 1;
bool explicitOffset : 1;
bool defaultBlock : 1; // default blocks with matching names have structures merged when linking
bool noContraction: 1; // prevent contraction and reassociation, e.g., for 'precise' keyword, and expressions it affects
bool nopersp : 1;
bool explicitInterp : 1;
bool pervertexNV : 1;
bool pervertexEXT : 1;
bool perPrimitiveNV : 1;
bool perViewNV : 1;
bool perTaskNV : 1;
bool patch : 1;
bool sample : 1;
bool restrict : 1;
bool readonly : 1;
bool writeonly : 1;
bool coherent : 1;
bool volatil : 1;
bool devicecoherent : 1;
bool queuefamilycoherent : 1;
bool workgroupcoherent : 1;
bool subgroupcoherent : 1;
bool shadercallcoherent : 1;
bool nonprivate : 1;
bool nullInit : 1;
bool spirvByReference : 1;
bool spirvLiteral : 1;
bool isWriteOnly() const { return writeonly; }
bool isReadOnly() const { return readonly; }
bool isRestrict() const { return restrict; }
bool isCoherent() const { return coherent; }
bool isVolatile() const { return volatil; }
bool isSample() const { return sample; }
bool isMemory() const
{
return shadercallcoherent || subgroupcoherent || workgroupcoherent || queuefamilycoherent || devicecoherent || coherent || volatil || restrict || readonly || writeonly || nonprivate;
}
bool isMemoryQualifierImageAndSSBOOnly() const
{
return shadercallcoherent || subgroupcoherent || workgroupcoherent || queuefamilycoherent || devicecoherent || coherent || volatil || restrict || readonly || writeonly;
}
bool bufferReferenceNeedsVulkanMemoryModel() const
{
// include qualifiers that map to load/store availability/visibility/nonprivate memory access operands
return subgroupcoherent || workgroupcoherent || queuefamilycoherent || devicecoherent || coherent || nonprivate;
}
bool isInterpolation() const
{
return flat || smooth || nopersp || explicitInterp;
}
bool isExplicitInterpolation() const
{
return explicitInterp;
}
bool isAuxiliary() const
{
return centroid || patch || sample || pervertexNV || pervertexEXT;
}
bool isPatch() const { return patch; }
bool isNoContraction() const { return noContraction; }
void setNoContraction() { noContraction = true; }
bool isPervertexNV() const { return pervertexNV; }
bool isPervertexEXT() const { return pervertexEXT; }
void setNullInit() { nullInit = true; }
bool isNullInit() const { return nullInit; }
void setSpirvByReference() { spirvByReference = true; }
bool isSpirvByReference() const { return spirvByReference; }
void setSpirvLiteral() { spirvLiteral = true; }
bool isSpirvLiteral() const { return spirvLiteral; }
bool isPipeInput() const
{
switch (storage) {
case EvqVaryingIn:
case EvqFragCoord:
case EvqPointCoord:
case EvqFace:
case EvqVertexId:
case EvqInstanceId:
return true;
default:
return false;
}
}
bool isPipeOutput() const
{
switch (storage) {
case EvqPosition:
case EvqPointSize:
case EvqClipVertex:
case EvqVaryingOut:
case EvqFragColor:
case EvqFragDepth:
case EvqFragStencil:
return true;
default:
return false;
}
}
bool isParamInput() const
{
switch (storage) {
case EvqIn:
case EvqInOut:
case EvqConstReadOnly:
return true;
default:
return false;
}
}
bool isParamOutput() const
{
switch (storage) {
case EvqOut:
case EvqInOut:
return true;
default:
return false;
}
}
bool isUniformOrBuffer() const
{
switch (storage) {
case EvqUniform:
case EvqBuffer:
return true;
default:
return false;
}
}
bool isUniform() const
{
switch (storage) {
case EvqUniform:
return true;
default:
return false;
}
}
bool isIo() const
{
switch (storage) {
case EvqUniform:
case EvqBuffer:
case EvqVaryingIn:
case EvqFragCoord:
case EvqPointCoord:
case EvqFace:
case EvqVertexId:
case EvqInstanceId:
case EvqPosition:
case EvqPointSize:
case EvqClipVertex:
case EvqVaryingOut:
case EvqFragColor:
case EvqFragDepth:
case EvqFragStencil:
return true;
default:
return false;
}
}
// non-built-in symbols that might link between compilation units
bool isLinkable() const
{
switch (storage) {
case EvqGlobal:
case EvqVaryingIn:
case EvqVaryingOut:
case EvqUniform:
case EvqBuffer:
case EvqShared:
return true;
default:
return false;
}
}
TBlockStorageClass getBlockStorage() const {
if (storage == EvqUniform && !isPushConstant()) {
return EbsUniform;
}
else if (storage == EvqUniform) {
return EbsPushConstant;
}
else if (storage == EvqBuffer) {
return EbsStorageBuffer;
}
return EbsNone;
}
void setBlockStorage(TBlockStorageClass newBacking) {
layoutPushConstant = (newBacking == EbsPushConstant);
switch (newBacking) {
case EbsUniform :
if (layoutPacking == ElpStd430) {
// std430 would not be valid
layoutPacking = ElpStd140;
}
storage = EvqUniform;
break;
case EbsStorageBuffer :
storage = EvqBuffer;
break;
case EbsPushConstant :
storage = EvqUniform;
layoutSet = TQualifier::layoutSetEnd;
layoutBinding = TQualifier::layoutBindingEnd;
break;
default:
break;
}
}
bool isPerPrimitive() const { return perPrimitiveNV; }
bool isPerView() const { return perViewNV; }
bool isTaskMemory() const { return perTaskNV; }
bool isTaskPayload() const { return storage == EvqtaskPayloadSharedEXT; }
bool isAnyPayload() const {
return storage == EvqPayload || storage == EvqPayloadIn;
}
bool isAnyCallable() const {
return storage == EvqCallableData || storage == EvqCallableDataIn;
}
bool isHitObjectAttrNV() const {
return storage == EvqHitObjectAttrNV;
}
// True if this type of IO is supposed to be arrayed with extra level for per-vertex data
bool isArrayedIo(EShLanguage language) const
{
switch (language) {
case EShLangGeometry:
return isPipeInput();
case EShLangTessControl:
return ! patch && (isPipeInput() || isPipeOutput());
case EShLangTessEvaluation:
return ! patch && isPipeInput();
case EShLangFragment:
return (pervertexNV || pervertexEXT) && isPipeInput();
case EShLangMesh:
return ! perTaskNV && isPipeOutput();
default:
return false;
}
}
// Implementing an embedded layout-qualifier class here, since C++ can't have a real class bitfield
void clearLayout() // all layout
{
clearUniformLayout();
layoutPushConstant = false;
layoutBufferReference = false;
layoutPassthrough = false;
layoutViewportRelative = false;
// -2048 as the default value indicating layoutSecondaryViewportRelative is not set
layoutSecondaryViewportRelativeOffset = -2048;
layoutShaderRecord = false;
layoutFullQuads = false;
layoutQuadDeriv = false;
layoutHitObjectShaderRecordNV = false;
layoutBindlessSampler = false;
layoutBindlessImage = false;
layoutBufferReferenceAlign = layoutBufferReferenceAlignEnd;
layoutFormat = ElfNone;
clearInterstageLayout();
layoutSpecConstantId = layoutSpecConstantIdEnd;
}
void clearInterstageLayout()
{
layoutLocation = layoutLocationEnd;
layoutComponent = layoutComponentEnd;
layoutIndex = layoutIndexEnd;
clearStreamLayout();
clearXfbLayout();
}
void clearStreamLayout()
{
layoutStream = layoutStreamEnd;
}
void clearXfbLayout()
{
layoutXfbBuffer = layoutXfbBufferEnd;
layoutXfbStride = layoutXfbStrideEnd;
layoutXfbOffset = layoutXfbOffsetEnd;
}
bool hasNonXfbLayout() const
{
return hasUniformLayout() ||
hasAnyLocation() ||
hasStream() ||
hasFormat() ||
isShaderRecord() ||
isPushConstant() ||
hasBufferReference();
}
bool hasLayout() const
{
return hasNonXfbLayout() ||
hasXfb();
}
TLayoutMatrix layoutMatrix : 3;
TLayoutPacking layoutPacking : 4;
int layoutOffset;
int layoutAlign;
unsigned int layoutLocation : 12;
static const unsigned int layoutLocationEnd = 0xFFF;
unsigned int layoutComponent : 3;
static const unsigned int layoutComponentEnd = 4;
unsigned int layoutSet : 7;
static const unsigned int layoutSetEnd = 0x3F;
unsigned int layoutBinding : 16;
static const unsigned int layoutBindingEnd = 0xFFFF;
unsigned int layoutIndex : 8;
static const unsigned int layoutIndexEnd = 0xFF;
unsigned int layoutStream : 8;
static const unsigned int layoutStreamEnd = 0xFF;
unsigned int layoutXfbBuffer : 4;
static const unsigned int layoutXfbBufferEnd = 0xF;
unsigned int layoutXfbStride : 14;
static const unsigned int layoutXfbStrideEnd = 0x3FFF;
unsigned int layoutXfbOffset : 13;
static const unsigned int layoutXfbOffsetEnd = 0x1FFF;
unsigned int layoutAttachment : 8; // for input_attachment_index
static const unsigned int layoutAttachmentEnd = 0XFF;
unsigned int layoutSpecConstantId : 11;
static const unsigned int layoutSpecConstantIdEnd = 0x7FF;
// stored as log2 of the actual alignment value
unsigned int layoutBufferReferenceAlign : 6;
static const unsigned int layoutBufferReferenceAlignEnd = 0x3F;
TLayoutFormat layoutFormat : 8;
bool layoutPushConstant;
bool layoutBufferReference;
bool layoutPassthrough;
bool layoutViewportRelative;
int layoutSecondaryViewportRelativeOffset;
bool layoutShaderRecord;
bool layoutFullQuads;
bool layoutQuadDeriv;
bool layoutHitObjectShaderRecordNV;
// GL_EXT_spirv_intrinsics
int spirvStorageClass;
TSpirvDecorate* spirvDecorate;
bool layoutBindlessSampler;
bool layoutBindlessImage;
bool hasUniformLayout() const
{
return hasMatrix() ||
hasPacking() ||
hasOffset() ||
hasBinding() ||
hasSet() ||
hasAlign();
}
void clearUniformLayout() // only uniform specific
{
layoutMatrix = ElmNone;
layoutPacking = ElpNone;
layoutOffset = layoutNotSet;
layoutAlign = layoutNotSet;
layoutSet = layoutSetEnd;
layoutBinding = layoutBindingEnd;
layoutAttachment = layoutAttachmentEnd;
}
bool hasMatrix() const
{
return layoutMatrix != ElmNone;
}
bool hasPacking() const
{
return layoutPacking != ElpNone;
}
bool hasAlign() const
{
return layoutAlign != layoutNotSet;
}
bool hasAnyLocation() const
{
return hasLocation() ||
hasComponent() ||
hasIndex();
}
bool hasLocation() const
{
return layoutLocation != layoutLocationEnd;
}
bool hasSet() const
{
return layoutSet != layoutSetEnd;
}
bool hasBinding() const
{
return layoutBinding != layoutBindingEnd;
}
bool hasOffset() const
{
return layoutOffset != layoutNotSet;
}
bool isNonPerspective() const { return nopersp; }
bool hasIndex() const
{
return layoutIndex != layoutIndexEnd;
}
unsigned getIndex() const { return layoutIndex; }
bool hasComponent() const
{
return layoutComponent != layoutComponentEnd;
}
bool hasStream() const
{
return layoutStream != layoutStreamEnd;
}
bool hasFormat() const
{
return layoutFormat != ElfNone;
}
bool hasXfb() const
{
return hasXfbBuffer() ||
hasXfbStride() ||
hasXfbOffset();
}
bool hasXfbBuffer() const
{
return layoutXfbBuffer != layoutXfbBufferEnd;
}
bool hasXfbStride() const
{
return layoutXfbStride != layoutXfbStrideEnd;
}
bool hasXfbOffset() const
{
return layoutXfbOffset != layoutXfbOffsetEnd;
}
bool hasAttachment() const
{
return layoutAttachment != layoutAttachmentEnd;
}
TLayoutFormat getFormat() const { return layoutFormat; }
bool isPushConstant() const { return layoutPushConstant; }
bool isShaderRecord() const { return layoutShaderRecord; }
bool isFullQuads() const { return layoutFullQuads; }
bool isQuadDeriv() const { return layoutQuadDeriv; }
bool hasHitObjectShaderRecordNV() const { return layoutHitObjectShaderRecordNV; }
bool hasBufferReference() const { return layoutBufferReference; }
bool hasBufferReferenceAlign() const
{
return layoutBufferReferenceAlign != layoutBufferReferenceAlignEnd;
}
bool isNonUniform() const
{
return nonUniform;
}
bool isBindlessSampler() const
{
return layoutBindlessSampler;
}
bool isBindlessImage() const
{
return layoutBindlessImage;
}
// GL_EXT_spirv_intrinsics
bool hasSpirvDecorate() const { return spirvDecorate != nullptr; }
void setSpirvDecorate(int decoration, const TIntermAggregate* args = nullptr);
void setSpirvDecorateId(int decoration, const TIntermAggregate* args);
void setSpirvDecorateString(int decoration, const TIntermAggregate* args);
const TSpirvDecorate& getSpirvDecorate() const { assert(spirvDecorate); return *spirvDecorate; }
TSpirvDecorate& getSpirvDecorate() { assert(spirvDecorate); return *spirvDecorate; }
TString getSpirvDecorateQualifierString() const;
bool hasSpecConstantId() const
{
// Not the same thing as being a specialization constant, this
// is just whether or not it was declared with an ID.
return layoutSpecConstantId != layoutSpecConstantIdEnd;
}
bool isSpecConstant() const
{
// True if type is a specialization constant, whether or not it
// had a specialization-constant ID, and false if it is not a
// true front-end constant.
return specConstant;
}
bool isFrontEndConstant() const
{
// True if the front-end knows the final constant value.
// This allows front-end constant folding.
return storage == EvqConst && ! specConstant;
}
bool isConstant() const
{
// True if is either kind of constant; specialization or regular.
return isFrontEndConstant() || isSpecConstant();
}
void makeSpecConstant()
{
storage = EvqConst;
specConstant = true;
}
static const char* getLayoutPackingString(TLayoutPacking packing)
{
switch (packing) {
case ElpStd140: return "std140";
case ElpPacked: return "packed";
case ElpShared: return "shared";
case ElpStd430: return "std430";
case ElpScalar: return "scalar";
default: return "none";
}
}
static const char* getLayoutMatrixString(TLayoutMatrix m)
{
switch (m) {
case ElmColumnMajor: return "column_major";
case ElmRowMajor: return "row_major";
default: return "none";
}
}
static const char* getLayoutFormatString(TLayoutFormat f)
{
switch (f) {
case ElfRgba32f: return "rgba32f";
case ElfRgba16f: return "rgba16f";
case ElfRg32f: return "rg32f";
case ElfRg16f: return "rg16f";
case ElfR11fG11fB10f: return "r11f_g11f_b10f";
case ElfR32f: return "r32f";
case ElfR16f: return "r16f";
case ElfRgba16: return "rgba16";
case ElfRgb10A2: return "rgb10_a2";
case ElfRgba8: return "rgba8";
case ElfRg16: return "rg16";
case ElfRg8: return "rg8";
case ElfR16: return "r16";
case ElfR8: return "r8";
case ElfRgba16Snorm: return "rgba16_snorm";
case ElfRgba8Snorm: return "rgba8_snorm";
case ElfRg16Snorm: return "rg16_snorm";
case ElfRg8Snorm: return "rg8_snorm";
case ElfR16Snorm: return "r16_snorm";
case ElfR8Snorm: return "r8_snorm";
case ElfRgba32i: return "rgba32i";
case ElfRgba16i: return "rgba16i";
case ElfRgba8i: return "rgba8i";
case ElfRg32i: return "rg32i";
case ElfRg16i: return "rg16i";
case ElfRg8i: return "rg8i";
case ElfR32i: return "r32i";
case ElfR16i: return "r16i";
case ElfR8i: return "r8i";
case ElfRgba32ui: return "rgba32ui";
case ElfRgba16ui: return "rgba16ui";
case ElfRgba8ui: return "rgba8ui";
case ElfRg32ui: return "rg32ui";
case ElfRg16ui: return "rg16ui";
case ElfRgb10a2ui: return "rgb10_a2ui";
case ElfRg8ui: return "rg8ui";
case ElfR32ui: return "r32ui";
case ElfR16ui: return "r16ui";
case ElfR8ui: return "r8ui";
case ElfR64ui: return "r64ui";
case ElfR64i: return "r64i";
case ElfSize1x8: return "size1x8";
case ElfSize1x16: return "size1x16";
case ElfSize1x32: return "size1x32";
case ElfSize2x32: return "size2x32";
case ElfSize4x32: return "size4x32";
default: return "none";
}
}
static const char* getLayoutDepthString(TLayoutDepth d)
{
switch (d) {
case EldAny: return "depth_any";
case EldGreater: return "depth_greater";
case EldLess: return "depth_less";
case EldUnchanged: return "depth_unchanged";
default: return "none";
}
}
static const char* getLayoutStencilString(TLayoutStencil s)
{
switch (s) {
case ElsRefUnchangedFrontAMD: return "stencil_ref_unchanged_front_amd";
case ElsRefGreaterFrontAMD: return "stencil_ref_greater_front_amd";
case ElsRefLessFrontAMD: return "stencil_ref_less_front_amd";
case ElsRefUnchangedBackAMD: return "stencil_ref_unchanged_back_amd";
case ElsRefGreaterBackAMD: return "stencil_ref_greater_back_amd";
case ElsRefLessBackAMD: return "stencil_ref_less_back_amd";
default: return "none";
}
}
static const char* getBlendEquationString(TBlendEquationShift e)
{
switch (e) {
case EBlendMultiply: return "blend_support_multiply";
case EBlendScreen: return "blend_support_screen";
case EBlendOverlay: return "blend_support_overlay";
case EBlendDarken: return "blend_support_darken";
case EBlendLighten: return "blend_support_lighten";
case EBlendColordodge: return "blend_support_colordodge";
case EBlendColorburn: return "blend_support_colorburn";
case EBlendHardlight: return "blend_support_hardlight";
case EBlendSoftlight: return "blend_support_softlight";
case EBlendDifference: return "blend_support_difference";
case EBlendExclusion: return "blend_support_exclusion";
case EBlendHslHue: return "blend_support_hsl_hue";
case EBlendHslSaturation: return "blend_support_hsl_saturation";
case EBlendHslColor: return "blend_support_hsl_color";
case EBlendHslLuminosity: return "blend_support_hsl_luminosity";
case EBlendAllEquations: return "blend_support_all_equations";
default: return "unknown";
}
}
static const char* getGeometryString(TLayoutGeometry geometry)
{
switch (geometry) {
case ElgPoints: return "points";
case ElgLines: return "lines";
case ElgLinesAdjacency: return "lines_adjacency";
case ElgLineStrip: return "line_strip";
case ElgTriangles: return "triangles";
case ElgTrianglesAdjacency: return "triangles_adjacency";
case ElgTriangleStrip: return "triangle_strip";
case ElgQuads: return "quads";
case ElgIsolines: return "isolines";
default: return "none";
}
}
static const char* getVertexSpacingString(TVertexSpacing spacing)
{
switch (spacing) {
case EvsEqual: return "equal_spacing";
case EvsFractionalEven: return "fractional_even_spacing";
case EvsFractionalOdd: return "fractional_odd_spacing";
default: return "none";
}
}
static const char* getVertexOrderString(TVertexOrder order)
{
switch (order) {
case EvoCw: return "cw";
case EvoCcw: return "ccw";
default: return "none";
}
}
static int mapGeometryToSize(TLayoutGeometry geometry)
{
switch (geometry) {
case ElgPoints: return 1;
case ElgLines: return 2;
case ElgLinesAdjacency: return 4;
case ElgTriangles: return 3;
case ElgTrianglesAdjacency: return 6;
default: return 0;
}
}
static const char* getInterlockOrderingString(TInterlockOrdering order)
{
switch (order) {
case EioPixelInterlockOrdered: return "pixel_interlock_ordered";
case EioPixelInterlockUnordered: return "pixel_interlock_unordered";
case EioSampleInterlockOrdered: return "sample_interlock_ordered";
case EioSampleInterlockUnordered: return "sample_interlock_unordered";
case EioShadingRateInterlockOrdered: return "shading_rate_interlock_ordered";
case EioShadingRateInterlockUnordered: return "shading_rate_interlock_unordered";
default: return "none";
}
}
};
// Qualifiers that don't need to be keep per object. They have shader scope, not object scope.
// So, they will not be part of TType, TQualifier, etc.
struct TShaderQualifiers {
TLayoutGeometry geometry; // geometry/tessellation shader in/out primitives
bool pixelCenterInteger; // fragment shader
bool originUpperLeft; // fragment shader
int invocations;
int vertices; // for tessellation "vertices", geometry & mesh "max_vertices"
TVertexSpacing spacing;
TVertexOrder order;
bool pointMode;
int localSize[3]; // compute shader
bool localSizeNotDefault[3]; // compute shader
int localSizeSpecId[3]; // compute shader specialization id for gl_WorkGroupSize
bool earlyFragmentTests; // fragment input
bool postDepthCoverage; // fragment input
bool earlyAndLateFragmentTestsAMD; //fragment input
bool nonCoherentColorAttachmentReadEXT; // fragment input
bool nonCoherentDepthAttachmentReadEXT; // fragment input
bool nonCoherentStencilAttachmentReadEXT; // fragment input
TLayoutDepth layoutDepth;
TLayoutStencil layoutStencil;
bool blendEquation; // true if any blend equation was specified
int numViews; // multiview extenstions
TInterlockOrdering interlockOrdering;
bool layoutOverrideCoverage; // true if layout override_coverage set
bool layoutDerivativeGroupQuads; // true if layout derivative_group_quadsNV set
bool layoutDerivativeGroupLinear; // true if layout derivative_group_linearNV set
int primitives; // mesh shader "max_primitives"DerivativeGroupLinear; // true if layout derivative_group_linearNV set
bool layoutPrimitiveCulling; // true if layout primitive_culling set
TLayoutDepth getDepth() const { return layoutDepth; }
TLayoutStencil getStencil() const { return layoutStencil; }
void init()
{
geometry = ElgNone;
originUpperLeft = false;
pixelCenterInteger = false;
invocations = TQualifier::layoutNotSet;
vertices = TQualifier::layoutNotSet;
spacing = EvsNone;
order = EvoNone;
pointMode = false;
localSize[0] = 1;
localSize[1] = 1;
localSize[2] = 1;
localSizeNotDefault[0] = false;
localSizeNotDefault[1] = false;
localSizeNotDefault[2] = false;
localSizeSpecId[0] = TQualifier::layoutNotSet;
localSizeSpecId[1] = TQualifier::layoutNotSet;
localSizeSpecId[2] = TQualifier::layoutNotSet;
earlyFragmentTests = false;
earlyAndLateFragmentTestsAMD = false;
postDepthCoverage = false;
nonCoherentColorAttachmentReadEXT = false;
nonCoherentDepthAttachmentReadEXT = false;
nonCoherentStencilAttachmentReadEXT = false;
layoutDepth = EldNone;
layoutStencil = ElsNone;
blendEquation = false;
numViews = TQualifier::layoutNotSet;
layoutOverrideCoverage = false;
layoutDerivativeGroupQuads = false;
layoutDerivativeGroupLinear = false;
layoutPrimitiveCulling = false;
primitives = TQualifier::layoutNotSet;
interlockOrdering = EioNone;
}
bool hasBlendEquation() const { return blendEquation; }
// Merge in characteristics from the 'src' qualifier. They can override when
// set, but never erase when not set.
void merge(const TShaderQualifiers& src)
{
if (src.geometry != ElgNone)
geometry = src.geometry;
if (src.pixelCenterInteger)
pixelCenterInteger = src.pixelCenterInteger;
if (src.originUpperLeft)
originUpperLeft = src.originUpperLeft;
if (src.invocations != TQualifier::layoutNotSet)
invocations = src.invocations;
if (src.vertices != TQualifier::layoutNotSet)
vertices = src.vertices;
if (src.spacing != EvsNone)
spacing = src.spacing;
if (src.order != EvoNone)
order = src.order;
if (src.pointMode)
pointMode = true;
for (int i = 0; i < 3; ++i) {
if (src.localSize[i] > 1)
localSize[i] = src.localSize[i];
}
for (int i = 0; i < 3; ++i) {
localSizeNotDefault[i] = src.localSizeNotDefault[i] || localSizeNotDefault[i];
}
for (int i = 0; i < 3; ++i) {
if (src.localSizeSpecId[i] != TQualifier::layoutNotSet)
localSizeSpecId[i] = src.localSizeSpecId[i];
}
if (src.earlyFragmentTests)
earlyFragmentTests = true;
if (src.earlyAndLateFragmentTestsAMD)
earlyAndLateFragmentTestsAMD = true;
if (src.postDepthCoverage)
postDepthCoverage = true;
if (src.nonCoherentColorAttachmentReadEXT)
nonCoherentColorAttachmentReadEXT = true;
if (src.nonCoherentDepthAttachmentReadEXT)
nonCoherentDepthAttachmentReadEXT = true;
if (src.nonCoherentStencilAttachmentReadEXT)
nonCoherentStencilAttachmentReadEXT = true;
if (src.layoutDepth)
layoutDepth = src.layoutDepth;
if (src.layoutStencil)
layoutStencil = src.layoutStencil;
if (src.blendEquation)
blendEquation = src.blendEquation;
if (src.numViews != TQualifier::layoutNotSet)
numViews = src.numViews;
if (src.layoutOverrideCoverage)
layoutOverrideCoverage = src.layoutOverrideCoverage;
if (src.layoutDerivativeGroupQuads)
layoutDerivativeGroupQuads = src.layoutDerivativeGroupQuads;
if (src.layoutDerivativeGroupLinear)
layoutDerivativeGroupLinear = src.layoutDerivativeGroupLinear;
if (src.primitives != TQualifier::layoutNotSet)
primitives = src.primitives;
if (src.interlockOrdering != EioNone)
interlockOrdering = src.interlockOrdering;
if (src.layoutPrimitiveCulling)
layoutPrimitiveCulling = src.layoutPrimitiveCulling;
}
};
class TTypeParameters {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TTypeParameters() : basicType(EbtVoid), arraySizes(nullptr), spirvType(nullptr) {}
TBasicType basicType;
TArraySizes *arraySizes;
TSpirvType *spirvType;
bool operator==(const TTypeParameters& rhs) const
{
bool same = basicType == rhs.basicType && *arraySizes == *rhs.arraySizes;
if (same && basicType == EbtSpirvType) {
assert(spirvType && rhs.spirvType);
return *spirvType == *rhs.spirvType;
}
return same;
}
bool operator!=(const TTypeParameters& rhs) const
{
return !(*this == rhs);
}
};
//
// TPublicType is just temporarily used while parsing and not quite the same
// information kept per node in TType. Due to the bison stack, it can't have
// types that it thinks have non-trivial constructors. It should
// just be used while recognizing the grammar, not anything else.
// Once enough is known about the situation, the proper information
// moved into a TType, or the parse context, etc.
//
class TPublicType {
public:
TBasicType basicType;
TSampler sampler;
TQualifier qualifier;
TShaderQualifiers shaderQualifiers;
uint32_t vectorSize : 4;
uint32_t matrixCols : 4;
uint32_t matrixRows : 4;
bool coopmatNV : 1;
bool coopmatKHR : 1;
TArraySizes* arraySizes;
const TType* userDef;
TSourceLoc loc;
TTypeParameters* typeParameters;
// SPIR-V type defined by spirv_type directive
TSpirvType* spirvType;
bool isCoopmat() const { return coopmatNV || coopmatKHR; }
bool isCoopmatNV() const { return coopmatNV; }
bool isCoopmatKHR() const { return coopmatKHR; }
void initType(const TSourceLoc& l)
{
basicType = EbtVoid;
vectorSize = 1u;
matrixRows = 0;
matrixCols = 0;
arraySizes = nullptr;
userDef = nullptr;
loc = l;
typeParameters = nullptr;
coopmatNV = false;
coopmatKHR = false;
spirvType = nullptr;
}
void initQualifiers(bool global = false)
{
qualifier.clear();
if (global)
qualifier.storage = EvqGlobal;
}
void init(const TSourceLoc& l, bool global = false)
{
initType(l);
sampler.clear();
initQualifiers(global);
shaderQualifiers.init();
}
void setVector(int s)
{
matrixRows = 0;
matrixCols = 0;
assert(s >= 0);
vectorSize = static_cast<uint32_t>(s) & 0b1111;
}
void setMatrix(int c, int r)
{
assert(r >= 0);
matrixRows = static_cast<uint32_t>(r) & 0b1111;
assert(c >= 0);
matrixCols = static_cast<uint32_t>(c) & 0b1111;
vectorSize = 0;
}
bool isScalar() const
{
return matrixCols == 0u && vectorSize == 1u && arraySizes == nullptr && userDef == nullptr;
}
// GL_EXT_spirv_intrinsics
void setSpirvType(const TSpirvInstruction& spirvInst, const TSpirvTypeParameters* typeParams = nullptr);
// "Image" is a superset of "Subpass"
bool isImage() const { return basicType == EbtSampler && sampler.isImage(); }
bool isSubpass() const { return basicType == EbtSampler && sampler.isSubpass(); }
bool isAttachmentEXT() const { return basicType == EbtSampler && sampler.isAttachmentEXT(); }
};
//
// Base class for things that have a type.
//
class TType {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
// for "empty" type (no args) or simple scalar/vector/matrix
explicit TType(TBasicType t = EbtVoid, TStorageQualifier q = EvqTemporary, int vs = 1, int mc = 0, int mr = 0,
bool isVector = false) :
basicType(t), vectorSize(static_cast<uint32_t>(vs) & 0b1111), matrixCols(static_cast<uint32_t>(mc) & 0b1111), matrixRows(static_cast<uint32_t>(mr) & 0b1111), vector1(isVector && vs == 1), coopmatNV(false), coopmatKHR(false), coopmatKHRuse(0), coopmatKHRUseValid(false),
arraySizes(nullptr), structure(nullptr), fieldName(nullptr), typeName(nullptr), typeParameters(nullptr),
spirvType(nullptr)
{
assert(vs >= 0);
assert(mc >= 0);
assert(mr >= 0);
sampler.clear();
qualifier.clear();
qualifier.storage = q;
assert(!(isMatrix() && vectorSize != 0)); // prevent vectorSize != 0 on matrices
}
// for explicit precision qualifier
TType(TBasicType t, TStorageQualifier q, TPrecisionQualifier p, int vs = 1, int mc = 0, int mr = 0,
bool isVector = false) :
basicType(t), vectorSize(static_cast<uint32_t>(vs) & 0b1111), matrixCols(static_cast<uint32_t>(mc) & 0b1111), matrixRows(static_cast<uint32_t>(mr) & 0b1111), vector1(isVector && vs == 1), coopmatNV(false), coopmatKHR(false), coopmatKHRuse(0), coopmatKHRUseValid(false),
arraySizes(nullptr), structure(nullptr), fieldName(nullptr), typeName(nullptr), typeParameters(nullptr),
spirvType(nullptr)
{
assert(vs >= 0);
assert(mc >= 0);
assert(mr >= 0);
sampler.clear();
qualifier.clear();
qualifier.storage = q;
qualifier.precision = p;
assert(p >= EpqNone && p <= EpqHigh);
assert(!(isMatrix() && vectorSize != 0)); // prevent vectorSize != 0 on matrices
}
// for turning a TPublicType into a TType, using a shallow copy
explicit TType(const TPublicType& p) :
basicType(p.basicType),
vectorSize(p.vectorSize), matrixCols(p.matrixCols), matrixRows(p.matrixRows), vector1(false), coopmatNV(p.coopmatNV), coopmatKHR(p.coopmatKHR), coopmatKHRuse(0), coopmatKHRUseValid(false),
arraySizes(p.arraySizes), structure(nullptr), fieldName(nullptr), typeName(nullptr), typeParameters(p.typeParameters),
spirvType(p.spirvType)
{
if (basicType == EbtSampler)
sampler = p.sampler;
else
sampler.clear();
qualifier = p.qualifier;
if (p.userDef) {
if (p.userDef->basicType == EbtReference) {
basicType = EbtReference;
referentType = p.userDef->referentType;
} else {
structure = p.userDef->getWritableStruct(); // public type is short-lived; there are no sharing issues
}
typeName = NewPoolTString(p.userDef->getTypeName().c_str());
}
if (p.isCoopmatNV() && p.typeParameters && p.typeParameters->arraySizes->getNumDims() > 0) {
int numBits = p.typeParameters->arraySizes->getDimSize(0);
if (p.basicType == EbtFloat && numBits == 16) {
basicType = EbtFloat16;
qualifier.precision = EpqNone;
} else if (p.basicType == EbtUint && numBits == 8) {
basicType = EbtUint8;
qualifier.precision = EpqNone;
} else if (p.basicType == EbtUint && numBits == 16) {
basicType = EbtUint16;
qualifier.precision = EpqNone;
} else if (p.basicType == EbtInt && numBits == 8) {
basicType = EbtInt8;
qualifier.precision = EpqNone;
} else if (p.basicType == EbtInt && numBits == 16) {
basicType = EbtInt16;
qualifier.precision = EpqNone;
}
}
if (p.isCoopmatKHR() && p.typeParameters && p.typeParameters->arraySizes->getNumDims() > 0) {
basicType = p.typeParameters->basicType;
if (isSpirvType()) {
assert(p.typeParameters->spirvType);
spirvType = p.typeParameters->spirvType;
}
if (p.typeParameters->arraySizes->getNumDims() == 4) {
const int dimSize = p.typeParameters->arraySizes->getDimSize(3);
assert(dimSize >= 0);
coopmatKHRuse = static_cast<uint32_t>(dimSize) & 0b111;
coopmatKHRUseValid = true;
p.typeParameters->arraySizes->removeLastSize();
}
}
}
// for construction of sampler types
TType(const TSampler& sampler, TStorageQualifier q = EvqUniform, TArraySizes* as = nullptr) :
basicType(EbtSampler), vectorSize(1u), matrixCols(0u), matrixRows(0u), vector1(false), coopmatNV(false), coopmatKHR(false), coopmatKHRuse(0), coopmatKHRUseValid(false),
arraySizes(as), structure(nullptr), fieldName(nullptr), typeName(nullptr),
sampler(sampler), typeParameters(nullptr), spirvType(nullptr)
{
qualifier.clear();
qualifier.storage = q;
}
// to efficiently make a dereferenced type
// without ever duplicating the outer structure that will be thrown away
// and using only shallow copy
TType(const TType& type, int derefIndex, bool rowMajor = false)
{
if (type.isArray()) {
shallowCopy(type);
if (type.getArraySizes()->getNumDims() == 1) {
arraySizes = nullptr;
} else {
// want our own copy of the array, so we can edit it
arraySizes = new TArraySizes;
arraySizes->copyDereferenced(*type.arraySizes);
}
} else if (type.basicType == EbtStruct || type.basicType == EbtBlock) {
// do a structure dereference
const TTypeList& memberList = *type.getStruct();
shallowCopy(*memberList[derefIndex].type);
return;
} else {
// do a vector/matrix dereference
shallowCopy(type);
if (matrixCols > 0) {
// dereference from matrix to vector
if (rowMajor)
vectorSize = matrixCols;
else
vectorSize = matrixRows;
matrixCols = 0;
matrixRows = 0;
if (vectorSize == 1)
vector1 = true;
} else if (isVector()) {
// dereference from vector to scalar
vectorSize = 1;
vector1 = false;
} else if (isCoopMat()) {
coopmatNV = false;
coopmatKHR = false;
coopmatKHRuse = 0;
coopmatKHRUseValid = false;
typeParameters = nullptr;
}
}
}
// for making structures, ...
TType(TTypeList* userDef, const TString& n) :
basicType(EbtStruct), vectorSize(1), matrixCols(0), matrixRows(0), vector1(false), coopmatNV(false), coopmatKHR(false), coopmatKHRuse(0), coopmatKHRUseValid(false),
arraySizes(nullptr), structure(userDef), fieldName(nullptr), typeParameters(nullptr),
spirvType(nullptr)
{
sampler.clear();
qualifier.clear();
typeName = NewPoolTString(n.c_str());
}
// For interface blocks
TType(TTypeList* userDef, const TString& n, const TQualifier& q) :
basicType(EbtBlock), vectorSize(1), matrixCols(0), matrixRows(0), vector1(false), coopmatNV(false), coopmatKHR(false), coopmatKHRuse(0), coopmatKHRUseValid(false),
qualifier(q), arraySizes(nullptr), structure(userDef), fieldName(nullptr), typeParameters(nullptr),
spirvType(nullptr)
{
sampler.clear();
typeName = NewPoolTString(n.c_str());
}
// for block reference (first parameter must be EbtReference)
explicit TType(TBasicType t, const TType &p, const TString& n) :
basicType(t), vectorSize(1), matrixCols(0), matrixRows(0), vector1(false), coopmatNV(false), coopmatKHR(false), coopmatKHRuse(0), coopmatKHRUseValid(false),
arraySizes(nullptr), structure(nullptr), fieldName(nullptr), typeName(nullptr), typeParameters(nullptr),
spirvType(nullptr)
{
assert(t == EbtReference);
typeName = NewPoolTString(n.c_str());
sampler.clear();
qualifier.clear();
qualifier.storage = p.qualifier.storage;
referentType = p.clone();
}
virtual ~TType() {}
// Not for use across pool pops; it will cause multiple instances of TType to point to the same information.
// This only works if that information (like a structure's list of types) does not change and
// the instances are sharing the same pool.
void shallowCopy(const TType& copyOf)
{
basicType = copyOf.basicType;
sampler = copyOf.sampler;
qualifier = copyOf.qualifier;
vectorSize = copyOf.vectorSize;
matrixCols = copyOf.matrixCols;
matrixRows = copyOf.matrixRows;
vector1 = copyOf.vector1;
arraySizes = copyOf.arraySizes; // copying the pointer only, not the contents
fieldName = copyOf.fieldName;
typeName = copyOf.typeName;
if (isStruct()) {
structure = copyOf.structure;
} else {
referentType = copyOf.referentType;
}
typeParameters = copyOf.typeParameters;
spirvType = copyOf.spirvType;
coopmatNV = copyOf.isCoopMatNV();
coopmatKHR = copyOf.isCoopMatKHR();
coopmatKHRuse = copyOf.coopmatKHRuse;
coopmatKHRUseValid = copyOf.coopmatKHRUseValid;
}
// Make complete copy of the whole type graph rooted at 'copyOf'.
void deepCopy(const TType& copyOf)
{
TMap<TTypeList*,TTypeList*> copied; // to enable copying a type graph as a graph, not a tree
deepCopy(copyOf, copied);
}
// Recursively make temporary
void makeTemporary()
{
getQualifier().makeTemporary();
if (isStruct())
for (unsigned int i = 0; i < structure->size(); ++i)
(*structure)[i].type->makeTemporary();
}
TType* clone() const
{
TType *newType = new TType();
newType->deepCopy(*this);
return newType;
}
void makeVector() { vector1 = true; }
virtual void hideMember() { basicType = EbtVoid; vectorSize = 1u; }
virtual bool hiddenMember() const { return basicType == EbtVoid; }
virtual void setFieldName(const TString& n) { fieldName = NewPoolTString(n.c_str()); }
virtual const TString& getTypeName() const
{
assert(typeName);
return *typeName;
}
virtual const TString& getFieldName() const
{
assert(fieldName);
return *fieldName;
}
TShaderInterface getShaderInterface() const
{
if (basicType != EbtBlock)
return EsiNone;
switch (qualifier.storage) {
default:
return EsiNone;
case EvqVaryingIn:
return EsiInput;
case EvqVaryingOut:
return EsiOutput;
case EvqUniform:
case EvqBuffer:
return EsiUniform;
}
}
virtual TBasicType getBasicType() const { return basicType; }
virtual const TSampler& getSampler() const { return sampler; }
virtual TSampler& getSampler() { return sampler; }
virtual TQualifier& getQualifier() { return qualifier; }
virtual const TQualifier& getQualifier() const { return qualifier; }
virtual int getVectorSize() const { return static_cast<int>(vectorSize); } // returns 1 for either scalar or vector of size 1, valid for both
virtual int getMatrixCols() const { return static_cast<int>(matrixCols); }
virtual int getMatrixRows() const { return static_cast<int>(matrixRows); }
virtual int getOuterArraySize() const { return arraySizes->getOuterSize(); }
virtual TIntermTyped* getOuterArrayNode() const { return arraySizes->getOuterNode(); }
virtual int getCumulativeArraySize() const { return arraySizes->getCumulativeSize(); }
bool isArrayOfArrays() const { return arraySizes != nullptr && arraySizes->getNumDims() > 1; }
virtual int getImplicitArraySize() const { return arraySizes->getImplicitSize(); }
virtual const TArraySizes* getArraySizes() const { return arraySizes; }
virtual TArraySizes* getArraySizes() { return arraySizes; }
virtual TType* getReferentType() const { return referentType; }
virtual const TTypeParameters* getTypeParameters() const { return typeParameters; }
virtual TTypeParameters* getTypeParameters() { return typeParameters; }
virtual bool isScalar() const { return ! isVector() && ! isMatrix() && ! isStruct() && ! isArray(); }
virtual bool isScalarOrVec1() const { return isScalar() || vector1; }
virtual bool isScalarOrVector() const { return !isMatrix() && !isStruct() && !isArray(); }
virtual bool isVector() const { return vectorSize > 1u || vector1; }
virtual bool isMatrix() const { return matrixCols ? true : false; }
virtual bool isArray() const { return arraySizes != nullptr; }
virtual bool isSizedArray() const { return isArray() && arraySizes->isSized(); }
virtual bool isUnsizedArray() const { return isArray() && !arraySizes->isSized(); }
virtual bool isImplicitlySizedArray() const { return isArray() && arraySizes->isImplicitlySized(); }
virtual bool isArrayVariablyIndexed() const { assert(isArray()); return arraySizes->isVariablyIndexed(); }
virtual void setArrayVariablyIndexed() { assert(isArray()); arraySizes->setVariablyIndexed(); }
virtual void updateImplicitArraySize(int size) { assert(isArray()); arraySizes->updateImplicitSize(size); }
virtual void setImplicitlySized(bool isImplicitSized) { arraySizes->setImplicitlySized(isImplicitSized); }
virtual bool isStruct() const { return basicType == EbtStruct || basicType == EbtBlock; }
virtual bool isFloatingDomain() const { return basicType == EbtFloat || basicType == EbtDouble || basicType == EbtFloat16; }
virtual bool isIntegerDomain() const
{
switch (basicType) {
case EbtInt8:
case EbtUint8:
case EbtInt16:
case EbtUint16:
case EbtInt:
case EbtUint:
case EbtInt64:
case EbtUint64:
case EbtAtomicUint:
return true;
default:
break;
}
return false;
}
virtual bool isOpaque() const { return basicType == EbtSampler
|| basicType == EbtAtomicUint || basicType == EbtAccStruct || basicType == EbtRayQuery
|| basicType == EbtHitObjectNV; }
virtual bool isBuiltIn() const { return getQualifier().builtIn != EbvNone; }
virtual bool isAttachmentEXT() const { return basicType == EbtSampler && getSampler().isAttachmentEXT(); }
virtual bool isImage() const { return basicType == EbtSampler && getSampler().isImage(); }
virtual bool isSubpass() const { return basicType == EbtSampler && getSampler().isSubpass(); }
virtual bool isTexture() const { return basicType == EbtSampler && getSampler().isTexture(); }
virtual bool isBindlessImage() const { return isImage() && qualifier.layoutBindlessImage; }
virtual bool isBindlessTexture() const { return isTexture() && qualifier.layoutBindlessSampler; }
// Check the block-name convention of creating a block without populating it's members:
virtual bool isUnusableName() const { return isStruct() && structure == nullptr; }
virtual bool isParameterized() const { return typeParameters != nullptr; }
bool isAtomic() const { return basicType == EbtAtomicUint; }
bool isCoopMat() const { return coopmatNV || coopmatKHR; }
bool isCoopMatNV() const { return coopmatNV; }
bool isCoopMatKHR() const { return coopmatKHR; }
bool isReference() const { return getBasicType() == EbtReference; }
bool isSpirvType() const { return getBasicType() == EbtSpirvType; }
int getCoopMatKHRuse() const { return static_cast<int>(coopmatKHRuse); }
// return true if this type contains any subtype which satisfies the given predicate.
template <typename P>
bool contains(P predicate) const
{
if (predicate(this))
return true;
const auto hasa = [predicate](const TTypeLoc& tl) { return tl.type->contains(predicate); };
return isStruct() && std::any_of(structure->begin(), structure->end(), hasa);
}
// Recursively checks if the type contains the given basic type
virtual bool containsBasicType(TBasicType checkType) const
{
return contains([checkType](const TType* t) { return t->basicType == checkType; } );
}
// Recursively check the structure for any arrays, needed for some error checks
virtual bool containsArray() const
{
return contains([](const TType* t) { return t->isArray(); } );
}
// Check the structure for any structures, needed for some error checks
virtual bool containsStructure() const
{
return contains([this](const TType* t) { return t != this && t->isStruct(); } );
}
// Recursively check the structure for any unsized arrays, needed for triggering a copyUp().
virtual bool containsUnsizedArray() const
{
return contains([](const TType* t) { return t->isUnsizedArray(); } );
}
virtual bool containsOpaque() const
{
return contains([](const TType* t) { return t->isOpaque(); } );
}
virtual bool containsSampler() const
{
return contains([](const TType* t) { return t->isTexture() || t->isImage(); });
}
// Recursively checks if the type contains a built-in variable
virtual bool containsBuiltIn() const
{
return contains([](const TType* t) { return t->isBuiltIn(); } );
}
virtual bool containsNonOpaque() const
{
const auto nonOpaque = [](const TType* t) {
switch (t->basicType) {
case EbtVoid:
case EbtFloat:
case EbtDouble:
case EbtFloat16:
case EbtInt8:
case EbtUint8:
case EbtInt16:
case EbtUint16:
case EbtInt:
case EbtUint:
case EbtInt64:
case EbtUint64:
case EbtBool:
case EbtReference:
return true;
default:
return false;
}
};
return contains(nonOpaque);
}
virtual bool containsSpecializationSize() const
{
return contains([](const TType* t) { return t->isArray() && t->arraySizes->isOuterSpecialization(); } );
}
bool containsDouble() const
{
return containsBasicType(EbtDouble);
}
bool contains16BitFloat() const
{
return containsBasicType(EbtFloat16);
}
bool contains64BitInt() const
{
return containsBasicType(EbtInt64) || containsBasicType(EbtUint64);
}
bool contains16BitInt() const
{
return containsBasicType(EbtInt16) || containsBasicType(EbtUint16);
}
bool contains8BitInt() const
{
return containsBasicType(EbtInt8) || containsBasicType(EbtUint8);
}
bool containsCoopMat() const
{
return contains([](const TType* t) { return t->coopmatNV || t->coopmatKHR; } );
}
bool containsReference() const
{
return containsBasicType(EbtReference);
}
// Array editing methods. Array descriptors can be shared across
// type instances. This allows all uses of the same array
// to be updated at once. E.g., all nodes can be explicitly sized
// by tracking and correcting one implicit size. Or, all nodes
// can get the explicit size on a redeclaration that gives size.
//
// N.B.: Don't share with the shared symbol tables (symbols are
// marked as isReadOnly(). Such symbols with arrays that will be
// edited need to copyUp() on first use, so that
// A) the edits don't effect the shared symbol table, and
// B) the edits are shared across all users.
void updateArraySizes(const TType& type)
{
// For when we may already be sharing existing array descriptors,
// keeping the pointers the same, just updating the contents.
assert(arraySizes != nullptr);
assert(type.arraySizes != nullptr);
*arraySizes = *type.arraySizes;
}
void copyArraySizes(const TArraySizes& s)
{
// For setting a fresh new set of array sizes, not yet worrying about sharing.
arraySizes = new TArraySizes;
*arraySizes = s;
}
void transferArraySizes(TArraySizes* s)
{
// For setting an already allocated set of sizes that this type can use
// (no copy made).
arraySizes = s;
}
void clearArraySizes()
{
arraySizes = nullptr;
}
// Add inner array sizes, to any existing sizes, via copy; the
// sizes passed in can still be reused for other purposes.
void copyArrayInnerSizes(const TArraySizes* s)
{
if (s != nullptr) {
if (arraySizes == nullptr)
copyArraySizes(*s);
else
arraySizes->addInnerSizes(*s);
}
}
void changeOuterArraySize(int s) { arraySizes->changeOuterSize(s); }
// Recursively make the implicit array size the explicit array size.
// Expicit arrays are compile-time or link-time sized, never run-time sized.
// Sometimes, policy calls for an array to be run-time sized even if it was
// never variably indexed: Don't turn a 'skipNonvariablyIndexed' array into
// an explicit array.
void adoptImplicitArraySizes(bool skipNonvariablyIndexed)
{
if (isUnsizedArray() &&
(qualifier.builtIn == EbvSampleMask ||
!(skipNonvariablyIndexed || isArrayVariablyIndexed()))) {
changeOuterArraySize(getImplicitArraySize());
setImplicitlySized(true);
}
// For multi-dim per-view arrays, set unsized inner dimension size to 1
if (qualifier.isPerView() && arraySizes && arraySizes->isInnerUnsized())
arraySizes->clearInnerUnsized();
if (isStruct() && structure->size() > 0) {
int lastMember = (int)structure->size() - 1;
for (int i = 0; i < lastMember; ++i)
(*structure)[i].type->adoptImplicitArraySizes(false);
// implement the "last member of an SSBO" policy
(*structure)[lastMember].type->adoptImplicitArraySizes(getQualifier().storage == EvqBuffer);
}
}
void copyTypeParameters(const TTypeParameters& s)
{
// For setting a fresh new set of type parameters, not yet worrying about sharing.
typeParameters = new TTypeParameters;
*typeParameters = s;
}
const char* getBasicString() const
{
return TType::getBasicString(basicType);
}
static const char* getBasicString(TBasicType t)
{
switch (t) {
case EbtFloat: return "float";
case EbtInt: return "int";
case EbtUint: return "uint";
case EbtSampler: return "sampler/image";
case EbtVoid: return "void";
case EbtDouble: return "double";
case EbtFloat16: return "float16_t";
case EbtInt8: return "int8_t";
case EbtUint8: return "uint8_t";
case EbtInt16: return "int16_t";
case EbtUint16: return "uint16_t";
case EbtInt64: return "int64_t";
case EbtUint64: return "uint64_t";
case EbtBool: return "bool";
case EbtAtomicUint: return "atomic_uint";
case EbtStruct: return "structure";
case EbtBlock: return "block";
case EbtAccStruct: return "accelerationStructureNV";
case EbtRayQuery: return "rayQueryEXT";
case EbtReference: return "reference";
case EbtString: return "string";
case EbtSpirvType: return "spirv_type";
case EbtCoopmat: return "coopmat";
default: return "unknown type";
}
}
TString getCompleteString(bool syntactic = false, bool getQualifiers = true, bool getPrecision = true,
bool getType = true, TString name = "", TString structName = "") const
{
TString typeString;
const auto appendStr = [&](const char* s) { typeString.append(s); };
const auto appendUint = [&](unsigned int u) { typeString.append(std::to_string(u).c_str()); };
const auto appendInt = [&](int i) { typeString.append(std::to_string(i).c_str()); };
if (getQualifiers) {
if (qualifier.hasSpirvDecorate())
appendStr(qualifier.getSpirvDecorateQualifierString().c_str());
if (qualifier.hasLayout()) {
// To reduce noise, skip this if the only layout is an xfb_buffer
// with no triggering xfb_offset.
TQualifier noXfbBuffer = qualifier;
noXfbBuffer.layoutXfbBuffer = TQualifier::layoutXfbBufferEnd;
if (noXfbBuffer.hasLayout()) {
appendStr("layout(");
if (qualifier.hasAnyLocation()) {
appendStr(" location=");
appendUint(qualifier.layoutLocation);
if (qualifier.hasComponent()) {
appendStr(" component=");
appendUint(qualifier.layoutComponent);
}
if (qualifier.hasIndex()) {
appendStr(" index=");
appendUint(qualifier.layoutIndex);
}
}
if (qualifier.hasSet()) {
appendStr(" set=");
appendUint(qualifier.layoutSet);
}
if (qualifier.hasBinding()) {
appendStr(" binding=");
appendUint(qualifier.layoutBinding);
}
if (qualifier.hasStream()) {
appendStr(" stream=");
appendUint(qualifier.layoutStream);
}
if (qualifier.hasMatrix()) {
appendStr(" ");
appendStr(TQualifier::getLayoutMatrixString(qualifier.layoutMatrix));
}
if (qualifier.hasPacking()) {
appendStr(" ");
appendStr(TQualifier::getLayoutPackingString(qualifier.layoutPacking));
}
if (qualifier.hasOffset()) {
appendStr(" offset=");
appendInt(qualifier.layoutOffset);
}
if (qualifier.hasAlign()) {
appendStr(" align=");
appendInt(qualifier.layoutAlign);
}
if (qualifier.hasFormat()) {
appendStr(" ");
appendStr(TQualifier::getLayoutFormatString(qualifier.layoutFormat));
}
if (qualifier.hasXfbBuffer() && qualifier.hasXfbOffset()) {
appendStr(" xfb_buffer=");
appendUint(qualifier.layoutXfbBuffer);
}
if (qualifier.hasXfbOffset()) {
appendStr(" xfb_offset=");
appendUint(qualifier.layoutXfbOffset);
}
if (qualifier.hasXfbStride()) {
appendStr(" xfb_stride=");
appendUint(qualifier.layoutXfbStride);
}
if (qualifier.hasAttachment()) {
appendStr(" input_attachment_index=");
appendUint(qualifier.layoutAttachment);
}
if (qualifier.hasSpecConstantId()) {
appendStr(" constant_id=");
appendUint(qualifier.layoutSpecConstantId);
}
if (qualifier.layoutPushConstant)
appendStr(" push_constant");
if (qualifier.layoutBufferReference)
appendStr(" buffer_reference");
if (qualifier.hasBufferReferenceAlign()) {
appendStr(" buffer_reference_align=");
appendUint(1u << qualifier.layoutBufferReferenceAlign);
}
if (qualifier.layoutPassthrough)
appendStr(" passthrough");
if (qualifier.layoutViewportRelative)
appendStr(" layoutViewportRelative");
if (qualifier.layoutSecondaryViewportRelativeOffset != -2048) {
appendStr(" layoutSecondaryViewportRelativeOffset=");
appendInt(qualifier.layoutSecondaryViewportRelativeOffset);
}
if (qualifier.layoutShaderRecord)
appendStr(" shaderRecordNV");
if (qualifier.layoutFullQuads)
appendStr(" full_quads");
if (qualifier.layoutQuadDeriv)
appendStr(" quad_derivatives");
if (qualifier.layoutHitObjectShaderRecordNV)
appendStr(" hitobjectshaderrecordnv");
if (qualifier.layoutBindlessSampler)
appendStr(" layoutBindlessSampler");
if (qualifier.layoutBindlessImage)
appendStr(" layoutBindlessImage");
appendStr(")");
}
}
if (qualifier.invariant)
appendStr(" invariant");
if (qualifier.noContraction)
appendStr(" noContraction");
if (qualifier.centroid)
appendStr(" centroid");
if (qualifier.smooth)
appendStr(" smooth");
if (qualifier.flat)
appendStr(" flat");
if (qualifier.nopersp)
appendStr(" noperspective");
if (qualifier.explicitInterp)
appendStr(" __explicitInterpAMD");
if (qualifier.pervertexNV)
appendStr(" pervertexNV");
if (qualifier.pervertexEXT)
appendStr(" pervertexEXT");
if (qualifier.perPrimitiveNV)
appendStr(" perprimitiveNV");
if (qualifier.perViewNV)
appendStr(" perviewNV");
if (qualifier.perTaskNV)
appendStr(" taskNV");
if (qualifier.patch)
appendStr(" patch");
if (qualifier.sample)
appendStr(" sample");
if (qualifier.coherent)
appendStr(" coherent");
if (qualifier.devicecoherent)
appendStr(" devicecoherent");
if (qualifier.queuefamilycoherent)
appendStr(" queuefamilycoherent");
if (qualifier.workgroupcoherent)
appendStr(" workgroupcoherent");
if (qualifier.subgroupcoherent)
appendStr(" subgroupcoherent");
if (qualifier.shadercallcoherent)
appendStr(" shadercallcoherent");
if (qualifier.nonprivate)
appendStr(" nonprivate");
if (qualifier.volatil)
appendStr(" volatile");
if (qualifier.restrict)
appendStr(" restrict");
if (qualifier.readonly)
appendStr(" readonly");
if (qualifier.writeonly)
appendStr(" writeonly");
if (qualifier.specConstant)
appendStr(" specialization-constant");
if (qualifier.nonUniform)
appendStr(" nonuniform");
if (qualifier.isNullInit())
appendStr(" null-init");
if (qualifier.isSpirvByReference())
appendStr(" spirv_by_reference");
if (qualifier.isSpirvLiteral())
appendStr(" spirv_literal");
appendStr(" ");
appendStr(getStorageQualifierString());
}
if (getType) {
if (syntactic) {
if (getPrecision && qualifier.precision != EpqNone) {
appendStr(" ");
appendStr(getPrecisionQualifierString());
}
if (isVector() || isMatrix()) {
appendStr(" ");
switch (basicType) {
case EbtDouble:
appendStr("d");
break;
case EbtInt:
appendStr("i");
break;
case EbtUint:
appendStr("u");
break;
case EbtBool:
appendStr("b");
break;
case EbtFloat:
default:
break;
}
if (isVector()) {
appendStr("vec");
appendInt(vectorSize);
} else {
appendStr("mat");
appendInt(matrixCols);
appendStr("x");
appendInt(matrixRows);
}
} else if (isStruct() && structure) {
appendStr(" ");
appendStr(structName.c_str());
appendStr("{");
bool hasHiddenMember = true;
for (size_t i = 0; i < structure->size(); ++i) {
if (!(*structure)[i].type->hiddenMember()) {
if (!hasHiddenMember)
appendStr(", ");
typeString.append((*structure)[i].type->getCompleteString(syntactic, getQualifiers, getPrecision, getType, (*structure)[i].type->getFieldName()));
hasHiddenMember = false;
}
}
appendStr("}");
} else {
appendStr(" ");
switch (basicType) {
case EbtDouble:
appendStr("double");
break;
case EbtInt:
appendStr("int");
break;
case EbtUint:
appendStr("uint");
break;
case EbtBool:
appendStr("bool");
break;
case EbtFloat:
appendStr("float");
break;
default:
appendStr("unexpected");
break;
}
}
if (name.length() > 0) {
appendStr(" ");
appendStr(name.c_str());
}
if (isArray()) {
for (int i = 0; i < (int)arraySizes->getNumDims(); ++i) {
int size = arraySizes->getDimSize(i);
if (size == UnsizedArraySize && i == 0 && arraySizes->isVariablyIndexed())
appendStr("[]");
else {
if (size == UnsizedArraySize) {
appendStr("[");
if (i == 0)
appendInt(arraySizes->getImplicitSize());
appendStr("]");
}
else {
appendStr("[");
appendInt(arraySizes->getDimSize(i));
appendStr("]");
}
}
}
}
}
else {
if (isArray()) {
for (int i = 0; i < (int)arraySizes->getNumDims(); ++i) {
int size = arraySizes->getDimSize(i);
if (size == UnsizedArraySize && i == 0 && arraySizes->isVariablyIndexed())
appendStr(" runtime-sized array of");
else {
if (size == UnsizedArraySize) {
appendStr(" unsized");
if (i == 0) {
appendStr(" ");
appendInt(arraySizes->getImplicitSize());
}
}
else {
appendStr(" ");
appendInt(arraySizes->getDimSize(i));
}
appendStr("-element array of");
}
}
}
if (isParameterized()) {
if (isCoopMatKHR()) {
appendStr(" ");
appendStr("coopmat");
}
appendStr("<");
for (int i = 0; i < (int)typeParameters->arraySizes->getNumDims(); ++i) {
appendInt(typeParameters->arraySizes->getDimSize(i));
if (i != (int)typeParameters->arraySizes->getNumDims() - 1)
appendStr(", ");
}
if (coopmatKHRUseValid) {
appendStr(", ");
appendInt(coopmatKHRuse);
}
appendStr(">");
}
if (getPrecision && qualifier.precision != EpqNone) {
appendStr(" ");
appendStr(getPrecisionQualifierString());
}
if (isMatrix()) {
appendStr(" ");
appendInt(matrixCols);
appendStr("X");
appendInt(matrixRows);
appendStr(" matrix of");
}
else if (isVector()) {
appendStr(" ");
appendInt(vectorSize);
appendStr("-component vector of");
}
appendStr(" ");
typeString.append(getBasicTypeString());
if (qualifier.builtIn != EbvNone) {
appendStr(" ");
appendStr(getBuiltInVariableString());
}
// Add struct/block members
if (isStruct() && structure) {
appendStr("{");
bool hasHiddenMember = true;
for (size_t i = 0; i < structure->size(); ++i) {
if (!(*structure)[i].type->hiddenMember()) {
if (!hasHiddenMember)
appendStr(", ");
typeString.append((*structure)[i].type->getCompleteString());
typeString.append(" ");
typeString.append((*structure)[i].type->getFieldName());
hasHiddenMember = false;
}
}
appendStr("}");
}
}
}
return typeString;
}
TString getBasicTypeString() const
{
if (basicType == EbtSampler)
return sampler.getString();
else
return getBasicString();
}
const char* getStorageQualifierString() const { return GetStorageQualifierString(qualifier.storage); }
const char* getBuiltInVariableString() const { return GetBuiltInVariableString(qualifier.builtIn); }
const char* getPrecisionQualifierString() const { return GetPrecisionQualifierString(qualifier.precision); }
const TTypeList* getStruct() const { assert(isStruct()); return structure; }
void setStruct(TTypeList* s) { assert(isStruct()); structure = s; }
TTypeList* getWritableStruct() const { assert(isStruct()); return structure; } // This should only be used when known to not be sharing with other threads
void setBasicType(const TBasicType& t) { basicType = t; }
void setVectorSize(int s) {
assert(s >= 0);
vectorSize = static_cast<uint32_t>(s) & 0b1111;
}
int computeNumComponents() const
{
uint32_t components = 0;
if (getBasicType() == EbtStruct || getBasicType() == EbtBlock) {
for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++)
components += ((*tl).type)->computeNumComponents();
} else if (matrixCols)
components = matrixCols * matrixRows;
else
components = vectorSize;
if (arraySizes != nullptr) {
components *= arraySizes->getCumulativeSize();
}
return static_cast<int>(components);
}
// append this type's mangled name to the passed in 'name'
void appendMangledName(TString& name) const
{
buildMangledName(name);
name += ';' ;
}
// These variables are inconsistently declared inside and outside of gl_PerVertex in glslang right now.
// They are declared inside of 'in gl_PerVertex', but sitting as standalone when they are 'out'puts.
bool isInconsistentGLPerVertexMember(const TString& name) const
{
if (name == "gl_SecondaryPositionNV" ||
name == "gl_PositionPerViewNV")
return true;
return false;
}
// Do two structure types match? They could be declared independently,
// in different places, but still might satisfy the definition of matching.
// From the spec:
//
// "Structures must have the same name, sequence of type names, and
// type definitions, and member names to be considered the same type.
// This rule applies recursively for nested or embedded types."
//
// If type mismatch in structure, return member indices through lpidx and rpidx.
// If matching members for either block are exhausted, return -1 for exhausted
// block and the index of the unmatched member. Otherwise return {-1,-1}.
//
bool sameStructType(const TType& right, int* lpidx = nullptr, int* rpidx = nullptr) const
{
// Initialize error to general type mismatch.
if (lpidx != nullptr) {
*lpidx = -1;
*rpidx = -1;
}
// Most commonly, they are both nullptr, or the same pointer to the same actual structure
// TODO: Why return true when neither types are structures?
if ((!isStruct() && !right.isStruct()) ||
(isStruct() && right.isStruct() && structure == right.structure))
return true;
if (!isStruct() || !right.isStruct())
return false;
// Structure names have to match
if (*typeName != *right.typeName)
return false;
// There are inconsistencies with how gl_PerVertex is setup. For now ignore those as errors if they
// are known inconsistencies.
bool isGLPerVertex = *typeName == "gl_PerVertex";
// Both being nullptr was caught above, now they both have to be structures of the same number of elements
if (lpidx == nullptr &&
(structure->size() != right.structure->size() && !isGLPerVertex)) {
return false;
}
// Compare the names and types of all the members, which have to match
for (size_t li = 0, ri = 0; li < structure->size() || ri < right.structure->size(); ++li, ++ri) {
if (lpidx != nullptr) {
*lpidx = static_cast<int>(li);
*rpidx = static_cast<int>(ri);
}
if (li < structure->size() && ri < right.structure->size()) {
if ((*structure)[li].type->getFieldName() == (*right.structure)[ri].type->getFieldName()) {
if (*(*structure)[li].type != *(*right.structure)[ri].type)
return false;
} else {
// Skip hidden members
if ((*structure)[li].type->hiddenMember()) {
ri--;
continue;
} else if ((*right.structure)[ri].type->hiddenMember()) {
li--;
continue;
}
// If one of the members is something that's inconsistently declared, skip over it
// for now.
if (isGLPerVertex) {
if (isInconsistentGLPerVertexMember((*structure)[li].type->getFieldName())) {
ri--;
continue;
} else if (isInconsistentGLPerVertexMember((*right.structure)[ri].type->getFieldName())) {
li--;
continue;
}
} else {
return false;
}
}
// If we get here, then there should only be inconsistently declared members left
} else if (li < structure->size()) {
if (!(*structure)[li].type->hiddenMember() && !isInconsistentGLPerVertexMember((*structure)[li].type->getFieldName())) {
if (lpidx != nullptr) {
*rpidx = -1;
}
return false;
}
} else {
if (!(*right.structure)[ri].type->hiddenMember() && !isInconsistentGLPerVertexMember((*right.structure)[ri].type->getFieldName())) {
if (lpidx != nullptr) {
*lpidx = -1;
}
return false;
}
}
}
return true;
}
bool sameReferenceType(const TType& right) const
{
if (isReference() != right.isReference())
return false;
if (!isReference() && !right.isReference())
return true;
assert(referentType != nullptr);
assert(right.referentType != nullptr);
if (referentType == right.referentType)
return true;
return *referentType == *right.referentType;
}
// See if two types match, in all aspects except arrayness
// If mismatch in structure members, return member indices in lpidx and rpidx.
bool sameElementType(const TType& right, int* lpidx = nullptr, int* rpidx = nullptr) const
{
if (lpidx != nullptr) {
*lpidx = -1;
*rpidx = -1;
}
return basicType == right.basicType && sameElementShape(right, lpidx, rpidx);
}
// See if two type's arrayness match
bool sameArrayness(const TType& right) const
{
return ((arraySizes == nullptr && right.arraySizes == nullptr) ||
(arraySizes != nullptr && right.arraySizes != nullptr &&
(*arraySizes == *right.arraySizes ||
(arraySizes->isImplicitlySized() && right.arraySizes->isDefaultImplicitlySized()) ||
(right.arraySizes->isImplicitlySized() && arraySizes->isDefaultImplicitlySized()))));
}
// See if two type's arrayness match in everything except their outer dimension
bool sameInnerArrayness(const TType& right) const
{
assert(arraySizes != nullptr && right.arraySizes != nullptr);
return arraySizes->sameInnerArrayness(*right.arraySizes);
}
// See if two type's parameters match
bool sameTypeParameters(const TType& right) const
{
return ((typeParameters == nullptr && right.typeParameters == nullptr) ||
(typeParameters != nullptr && right.typeParameters != nullptr && *typeParameters == *right.typeParameters));
}
// See if two type's SPIR-V type contents match
bool sameSpirvType(const TType& right) const
{
return ((spirvType == nullptr && right.spirvType == nullptr) ||
(spirvType != nullptr && right.spirvType != nullptr && *spirvType == *right.spirvType));
}
// See if two type's elements match in all ways except basic type
// If mismatch in structure members, return member indices in lpidx and rpidx.
bool sameElementShape(const TType& right, int* lpidx = nullptr, int* rpidx = nullptr) const
{
if (lpidx != nullptr) {
*lpidx = -1;
*rpidx = -1;
}
return ((basicType != EbtSampler && right.basicType != EbtSampler) || sampler == right.sampler) &&
vectorSize == right.vectorSize &&
matrixCols == right.matrixCols &&
matrixRows == right.matrixRows &&
vector1 == right.vector1 &&
isCoopMatNV() == right.isCoopMatNV() &&
isCoopMatKHR() == right.isCoopMatKHR() &&
sameStructType(right, lpidx, rpidx) &&
sameReferenceType(right);
}
// See if a cooperative matrix type parameter with unspecified parameters is
// an OK function parameter
bool coopMatParameterOK(const TType& right) const
{
if (isCoopMatNV()) {
return right.isCoopMatNV() && (getBasicType() == right.getBasicType()) && typeParameters == nullptr &&
right.typeParameters != nullptr;
}
if (isCoopMatKHR() && right.isCoopMatKHR()) {
return ((getBasicType() == right.getBasicType()) || (getBasicType() == EbtCoopmat) ||
(right.getBasicType() == EbtCoopmat)) &&
((typeParameters == nullptr && right.typeParameters != nullptr) ||
(typeParameters != nullptr && right.typeParameters == nullptr));
}
return false;
}
bool sameCoopMatBaseType(const TType &right) const {
bool rv = false;
if (isCoopMatNV()) {
rv = isCoopMatNV() && right.isCoopMatNV();
if (getBasicType() == EbtFloat || getBasicType() == EbtFloat16)
rv = right.getBasicType() == EbtFloat || right.getBasicType() == EbtFloat16;
else if (getBasicType() == EbtUint || getBasicType() == EbtUint8 || getBasicType() == EbtUint16)
rv = right.getBasicType() == EbtUint || right.getBasicType() == EbtUint8 || right.getBasicType() == EbtUint16;
else if (getBasicType() == EbtInt || getBasicType() == EbtInt8 || getBasicType() == EbtInt16)
rv = right.getBasicType() == EbtInt || right.getBasicType() == EbtInt8 || right.getBasicType() == EbtInt16;
else
rv = false;
} else if (isCoopMatKHR() && right.isCoopMatKHR()) {
if (getBasicType() == EbtFloat || getBasicType() == EbtFloat16)
rv = right.getBasicType() == EbtFloat || right.getBasicType() == EbtFloat16 || right.getBasicType() == EbtCoopmat;
else if (getBasicType() == EbtUint || getBasicType() == EbtUint8 || getBasicType() == EbtUint16)
rv = right.getBasicType() == EbtUint || right.getBasicType() == EbtUint8 || right.getBasicType() == EbtUint16 || right.getBasicType() == EbtCoopmat;
else if (getBasicType() == EbtInt || getBasicType() == EbtInt8 || getBasicType() == EbtInt16)
rv = right.getBasicType() == EbtInt || right.getBasicType() == EbtInt8 || right.getBasicType() == EbtInt16 || right.getBasicType() == EbtCoopmat;
else
rv = false;
}
return rv;
}
bool sameCoopMatUse(const TType &right) const {
return coopmatKHRuse == right.coopmatKHRuse;
}
bool sameCoopMatShapeAndUse(const TType &right) const
{
if (!isCoopMat() || !right.isCoopMat() || isCoopMatKHR() != right.isCoopMatKHR())
return false;
if (coopmatKHRuse != right.coopmatKHRuse)
return false;
// Skip bit width type parameter (first array size) for coopmatNV
int firstArrayDimToCompare = isCoopMatNV() ? 1 : 0;
for (int i = firstArrayDimToCompare; i < typeParameters->arraySizes->getNumDims(); ++i) {
if (typeParameters->arraySizes->getDimSize(i) != right.typeParameters->arraySizes->getDimSize(i))
return false;
}
return true;
}
// See if two types match in all ways (just the actual type, not qualification)
bool operator==(const TType& right) const
{
return sameElementType(right) && sameArrayness(right) && sameTypeParameters(right) && sameCoopMatUse(right) && sameSpirvType(right);
}
bool operator!=(const TType& right) const
{
return ! operator==(right);
}
unsigned int getBufferReferenceAlignment() const
{
if (getBasicType() == glslang::EbtReference) {
return getReferentType()->getQualifier().hasBufferReferenceAlign() ?
(1u << getReferentType()->getQualifier().layoutBufferReferenceAlign) : 16u;
}
return 0;
}
const TSpirvType& getSpirvType() const { assert(spirvType); return *spirvType; }
protected:
// Require consumer to pick between deep copy and shallow copy.
TType(const TType& type);
TType& operator=(const TType& type);
// Recursively copy a type graph, while preserving the graph-like
// quality. That is, don't make more than one copy of a structure that
// gets reused multiple times in the type graph.
void deepCopy(const TType& copyOf, TMap<TTypeList*,TTypeList*>& copiedMap)
{
shallowCopy(copyOf);
// GL_EXT_spirv_intrinsics
if (copyOf.qualifier.spirvDecorate) {
qualifier.spirvDecorate = new TSpirvDecorate;
*qualifier.spirvDecorate = *copyOf.qualifier.spirvDecorate;
}
if (copyOf.spirvType) {
spirvType = new TSpirvType;
*spirvType = *copyOf.spirvType;
}
if (copyOf.arraySizes) {
arraySizes = new TArraySizes;
*arraySizes = *copyOf.arraySizes;
}
if (copyOf.typeParameters) {
typeParameters = new TTypeParameters;
typeParameters->arraySizes = new TArraySizes;
*typeParameters->arraySizes = *copyOf.typeParameters->arraySizes;
*typeParameters->spirvType = *copyOf.typeParameters->spirvType;
typeParameters->basicType = copyOf.basicType;
}
if (copyOf.isStruct() && copyOf.structure) {
auto prevCopy = copiedMap.find(copyOf.structure);
if (prevCopy != copiedMap.end())
structure = prevCopy->second;
else {
structure = new TTypeList;
copiedMap[copyOf.structure] = structure;
for (unsigned int i = 0; i < copyOf.structure->size(); ++i) {
TTypeLoc typeLoc;
typeLoc.loc = (*copyOf.structure)[i].loc;
typeLoc.type = new TType();
typeLoc.type->deepCopy(*(*copyOf.structure)[i].type, copiedMap);
structure->push_back(typeLoc);
}
}
}
if (copyOf.fieldName)
fieldName = NewPoolTString(copyOf.fieldName->c_str());
if (copyOf.typeName)
typeName = NewPoolTString(copyOf.typeName->c_str());
}
void buildMangledName(TString&) const;
TBasicType basicType : 8;
uint32_t vectorSize : 4; // 1 means either scalar or 1-component vector; see vector1 to disambiguate.
uint32_t matrixCols : 4;
uint32_t matrixRows : 4;
bool vector1 : 1; // Backward-compatible tracking of a 1-component vector distinguished from a scalar.
// GLSL 4.5 never has a 1-component vector; so this will always be false until such
// functionality is added.
// HLSL does have a 1-component vectors, so this will be true to disambiguate
// from a scalar.
bool coopmatNV : 1;
bool coopmatKHR : 1;
uint32_t coopmatKHRuse : 3; // Accepts one of three values: 0, 1, 2 (gl_MatrixUseA, gl_MatrixUseB, gl_MatrixUseAccumulator)
bool coopmatKHRUseValid : 1; // True if coopmatKHRuse has been set
TQualifier qualifier;
TArraySizes* arraySizes; // nullptr unless an array; can be shared across types
// A type can't be both a structure (EbtStruct/EbtBlock) and a reference (EbtReference), so
// conserve space by making these a union
union {
TTypeList* structure; // invalid unless this is a struct; can be shared across types
TType *referentType; // invalid unless this is an EbtReference
};
TString *fieldName; // for structure field names
TString *typeName; // for structure type name
TSampler sampler;
TTypeParameters *typeParameters;// nullptr unless a parameterized type; can be shared across types
TSpirvType* spirvType; // SPIR-V type defined by spirv_type directive
};
} // end namespace glslang
#endif // _TYPES_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/glslang_c_interface.h | /**
This code is based on the glslang_c_interface implementation by Viktor Latypov
**/
/**
BSD 2-Clause License
Copyright (c) 2019, Viktor Latypov
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
#ifndef GLSLANG_C_IFACE_H_INCLUDED
#define GLSLANG_C_IFACE_H_INCLUDED
#include <stdbool.h>
#include <stdlib.h>
#include "glslang_c_shader_types.h"
typedef struct glslang_shader_s glslang_shader_t;
typedef struct glslang_program_s glslang_program_t;
/* TLimits counterpart */
typedef struct glslang_limits_s {
bool non_inductive_for_loops;
bool while_loops;
bool do_while_loops;
bool general_uniform_indexing;
bool general_attribute_matrix_vector_indexing;
bool general_varying_indexing;
bool general_sampler_indexing;
bool general_variable_indexing;
bool general_constant_matrix_vector_indexing;
} glslang_limits_t;
/* TBuiltInResource counterpart */
typedef struct glslang_resource_s {
int max_lights;
int max_clip_planes;
int max_texture_units;
int max_texture_coords;
int max_vertex_attribs;
int max_vertex_uniform_components;
int max_varying_floats;
int max_vertex_texture_image_units;
int max_combined_texture_image_units;
int max_texture_image_units;
int max_fragment_uniform_components;
int max_draw_buffers;
int max_vertex_uniform_vectors;
int max_varying_vectors;
int max_fragment_uniform_vectors;
int max_vertex_output_vectors;
int max_fragment_input_vectors;
int min_program_texel_offset;
int max_program_texel_offset;
int max_clip_distances;
int max_compute_work_group_count_x;
int max_compute_work_group_count_y;
int max_compute_work_group_count_z;
int max_compute_work_group_size_x;
int max_compute_work_group_size_y;
int max_compute_work_group_size_z;
int max_compute_uniform_components;
int max_compute_texture_image_units;
int max_compute_image_uniforms;
int max_compute_atomic_counters;
int max_compute_atomic_counter_buffers;
int max_varying_components;
int max_vertex_output_components;
int max_geometry_input_components;
int max_geometry_output_components;
int max_fragment_input_components;
int max_image_units;
int max_combined_image_units_and_fragment_outputs;
int max_combined_shader_output_resources;
int max_image_samples;
int max_vertex_image_uniforms;
int max_tess_control_image_uniforms;
int max_tess_evaluation_image_uniforms;
int max_geometry_image_uniforms;
int max_fragment_image_uniforms;
int max_combined_image_uniforms;
int max_geometry_texture_image_units;
int max_geometry_output_vertices;
int max_geometry_total_output_components;
int max_geometry_uniform_components;
int max_geometry_varying_components;
int max_tess_control_input_components;
int max_tess_control_output_components;
int max_tess_control_texture_image_units;
int max_tess_control_uniform_components;
int max_tess_control_total_output_components;
int max_tess_evaluation_input_components;
int max_tess_evaluation_output_components;
int max_tess_evaluation_texture_image_units;
int max_tess_evaluation_uniform_components;
int max_tess_patch_components;
int max_patch_vertices;
int max_tess_gen_level;
int max_viewports;
int max_vertex_atomic_counters;
int max_tess_control_atomic_counters;
int max_tess_evaluation_atomic_counters;
int max_geometry_atomic_counters;
int max_fragment_atomic_counters;
int max_combined_atomic_counters;
int max_atomic_counter_bindings;
int max_vertex_atomic_counter_buffers;
int max_tess_control_atomic_counter_buffers;
int max_tess_evaluation_atomic_counter_buffers;
int max_geometry_atomic_counter_buffers;
int max_fragment_atomic_counter_buffers;
int max_combined_atomic_counter_buffers;
int max_atomic_counter_buffer_size;
int max_transform_feedback_buffers;
int max_transform_feedback_interleaved_components;
int max_cull_distances;
int max_combined_clip_and_cull_distances;
int max_samples;
int max_mesh_output_vertices_nv;
int max_mesh_output_primitives_nv;
int max_mesh_work_group_size_x_nv;
int max_mesh_work_group_size_y_nv;
int max_mesh_work_group_size_z_nv;
int max_task_work_group_size_x_nv;
int max_task_work_group_size_y_nv;
int max_task_work_group_size_z_nv;
int max_mesh_view_count_nv;
int max_mesh_output_vertices_ext;
int max_mesh_output_primitives_ext;
int max_mesh_work_group_size_x_ext;
int max_mesh_work_group_size_y_ext;
int max_mesh_work_group_size_z_ext;
int max_task_work_group_size_x_ext;
int max_task_work_group_size_y_ext;
int max_task_work_group_size_z_ext;
int max_mesh_view_count_ext;
union
{
int max_dual_source_draw_buffers_ext;
/* Incorrectly capitalized name retained for backward compatibility */
int maxDualSourceDrawBuffersEXT;
};
glslang_limits_t limits;
} glslang_resource_t;
/* Inclusion result structure allocated by C include_local/include_system callbacks */
typedef struct glsl_include_result_s {
/* Header file name or NULL if inclusion failed */
const char* header_name;
/* Header contents or NULL */
const char* header_data;
size_t header_length;
} glsl_include_result_t;
/* Callback for local file inclusion */
typedef glsl_include_result_t* (*glsl_include_local_func)(void* ctx, const char* header_name, const char* includer_name,
size_t include_depth);
/* Callback for system file inclusion */
typedef glsl_include_result_t* (*glsl_include_system_func)(void* ctx, const char* header_name,
const char* includer_name, size_t include_depth);
/* Callback for include result destruction */
typedef int (*glsl_free_include_result_func)(void* ctx, glsl_include_result_t* result);
/* Collection of callbacks for GLSL preprocessor */
typedef struct glsl_include_callbacks_s {
glsl_include_system_func include_system;
glsl_include_local_func include_local;
glsl_free_include_result_func free_include_result;
} glsl_include_callbacks_t;
typedef struct glslang_input_s {
glslang_source_t language;
glslang_stage_t stage;
glslang_client_t client;
glslang_target_client_version_t client_version;
glslang_target_language_t target_language;
glslang_target_language_version_t target_language_version;
/** Shader source code */
const char* code;
int default_version;
glslang_profile_t default_profile;
int force_default_version_and_profile;
int forward_compatible;
glslang_messages_t messages;
const glslang_resource_t* resource;
glsl_include_callbacks_t callbacks;
void* callbacks_ctx;
} glslang_input_t;
/* SpvOptions counterpart */
typedef struct glslang_spv_options_s {
bool generate_debug_info;
bool strip_debug_info;
bool disable_optimizer;
bool optimize_size;
bool disassemble;
bool validate;
bool emit_nonsemantic_shader_debug_info;
bool emit_nonsemantic_shader_debug_source;
bool compile_only;
} glslang_spv_options_t;
#ifdef __cplusplus
extern "C" {
#endif
#ifdef GLSLANG_IS_SHARED_LIBRARY
#ifdef _WIN32
#ifdef GLSLANG_EXPORTING
#define GLSLANG_EXPORT __declspec(dllexport)
#else
#define GLSLANG_EXPORT __declspec(dllimport)
#endif
#elif __GNUC__ >= 4
#define GLSLANG_EXPORT __attribute__((visibility("default")))
#endif
#endif // GLSLANG_IS_SHARED_LIBRARY
#ifndef GLSLANG_EXPORT
#define GLSLANG_EXPORT
#endif
GLSLANG_EXPORT int glslang_initialize_process(void);
GLSLANG_EXPORT void glslang_finalize_process(void);
GLSLANG_EXPORT glslang_shader_t* glslang_shader_create(const glslang_input_t* input);
GLSLANG_EXPORT void glslang_shader_delete(glslang_shader_t* shader);
GLSLANG_EXPORT void glslang_shader_set_preamble(glslang_shader_t* shader, const char* s);
GLSLANG_EXPORT void glslang_shader_shift_binding(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base);
GLSLANG_EXPORT void glslang_shader_shift_binding_for_set(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base, unsigned int set);
GLSLANG_EXPORT void glslang_shader_set_options(glslang_shader_t* shader, int options); // glslang_shader_options_t
GLSLANG_EXPORT void glslang_shader_set_glsl_version(glslang_shader_t* shader, int version);
GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input);
GLSLANG_EXPORT int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input);
GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);
GLSLANG_EXPORT const char* glslang_shader_get_info_log(glslang_shader_t* shader);
GLSLANG_EXPORT const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader);
GLSLANG_EXPORT glslang_program_t* glslang_program_create(void);
GLSLANG_EXPORT void glslang_program_delete(glslang_program_t* program);
GLSLANG_EXPORT void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader);
GLSLANG_EXPORT int glslang_program_link(glslang_program_t* program, int messages); // glslang_messages_t
GLSLANG_EXPORT void glslang_program_add_source_text(glslang_program_t* program, glslang_stage_t stage, const char* text, size_t len);
GLSLANG_EXPORT void glslang_program_set_source_file(glslang_program_t* program, glslang_stage_t stage, const char* file);
GLSLANG_EXPORT int glslang_program_map_io(glslang_program_t* program);
GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage);
GLSLANG_EXPORT void glslang_program_SPIRV_generate_with_options(glslang_program_t* program, glslang_stage_t stage, glslang_spv_options_t* spv_options);
GLSLANG_EXPORT size_t glslang_program_SPIRV_get_size(glslang_program_t* program);
GLSLANG_EXPORT void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*);
GLSLANG_EXPORT unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program);
GLSLANG_EXPORT const char* glslang_program_SPIRV_get_messages(glslang_program_t* program);
GLSLANG_EXPORT const char* glslang_program_get_info_log(glslang_program_t* program);
GLSLANG_EXPORT const char* glslang_program_get_info_debug_log(glslang_program_t* program);
#ifdef __cplusplus
}
#endif
#endif /* #ifdef GLSLANG_C_IFACE_INCLUDED */
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/ResourceLimits.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _RESOURCE_LIMITS_INCLUDED_
#define _RESOURCE_LIMITS_INCLUDED_
struct TLimits {
bool nonInductiveForLoops;
bool whileLoops;
bool doWhileLoops;
bool generalUniformIndexing;
bool generalAttributeMatrixVectorIndexing;
bool generalVaryingIndexing;
bool generalSamplerIndexing;
bool generalVariableIndexing;
bool generalConstantMatrixVectorIndexing;
};
struct TBuiltInResource {
int maxLights;
int maxClipPlanes;
int maxTextureUnits;
int maxTextureCoords;
int maxVertexAttribs;
int maxVertexUniformComponents;
int maxVaryingFloats;
int maxVertexTextureImageUnits;
int maxCombinedTextureImageUnits;
int maxTextureImageUnits;
int maxFragmentUniformComponents;
int maxDrawBuffers;
int maxVertexUniformVectors;
int maxVaryingVectors;
int maxFragmentUniformVectors;
int maxVertexOutputVectors;
int maxFragmentInputVectors;
int minProgramTexelOffset;
int maxProgramTexelOffset;
int maxClipDistances;
int maxComputeWorkGroupCountX;
int maxComputeWorkGroupCountY;
int maxComputeWorkGroupCountZ;
int maxComputeWorkGroupSizeX;
int maxComputeWorkGroupSizeY;
int maxComputeWorkGroupSizeZ;
int maxComputeUniformComponents;
int maxComputeTextureImageUnits;
int maxComputeImageUniforms;
int maxComputeAtomicCounters;
int maxComputeAtomicCounterBuffers;
int maxVaryingComponents;
int maxVertexOutputComponents;
int maxGeometryInputComponents;
int maxGeometryOutputComponents;
int maxFragmentInputComponents;
int maxImageUnits;
int maxCombinedImageUnitsAndFragmentOutputs;
int maxCombinedShaderOutputResources;
int maxImageSamples;
int maxVertexImageUniforms;
int maxTessControlImageUniforms;
int maxTessEvaluationImageUniforms;
int maxGeometryImageUniforms;
int maxFragmentImageUniforms;
int maxCombinedImageUniforms;
int maxGeometryTextureImageUnits;
int maxGeometryOutputVertices;
int maxGeometryTotalOutputComponents;
int maxGeometryUniformComponents;
int maxGeometryVaryingComponents;
int maxTessControlInputComponents;
int maxTessControlOutputComponents;
int maxTessControlTextureImageUnits;
int maxTessControlUniformComponents;
int maxTessControlTotalOutputComponents;
int maxTessEvaluationInputComponents;
int maxTessEvaluationOutputComponents;
int maxTessEvaluationTextureImageUnits;
int maxTessEvaluationUniformComponents;
int maxTessPatchComponents;
int maxPatchVertices;
int maxTessGenLevel;
int maxViewports;
int maxVertexAtomicCounters;
int maxTessControlAtomicCounters;
int maxTessEvaluationAtomicCounters;
int maxGeometryAtomicCounters;
int maxFragmentAtomicCounters;
int maxCombinedAtomicCounters;
int maxAtomicCounterBindings;
int maxVertexAtomicCounterBuffers;
int maxTessControlAtomicCounterBuffers;
int maxTessEvaluationAtomicCounterBuffers;
int maxGeometryAtomicCounterBuffers;
int maxFragmentAtomicCounterBuffers;
int maxCombinedAtomicCounterBuffers;
int maxAtomicCounterBufferSize;
int maxTransformFeedbackBuffers;
int maxTransformFeedbackInterleavedComponents;
int maxCullDistances;
int maxCombinedClipAndCullDistances;
int maxSamples;
int maxMeshOutputVerticesNV;
int maxMeshOutputPrimitivesNV;
int maxMeshWorkGroupSizeX_NV;
int maxMeshWorkGroupSizeY_NV;
int maxMeshWorkGroupSizeZ_NV;
int maxTaskWorkGroupSizeX_NV;
int maxTaskWorkGroupSizeY_NV;
int maxTaskWorkGroupSizeZ_NV;
int maxMeshViewCountNV;
int maxMeshOutputVerticesEXT;
int maxMeshOutputPrimitivesEXT;
int maxMeshWorkGroupSizeX_EXT;
int maxMeshWorkGroupSizeY_EXT;
int maxMeshWorkGroupSizeZ_EXT;
int maxTaskWorkGroupSizeX_EXT;
int maxTaskWorkGroupSizeY_EXT;
int maxTaskWorkGroupSizeZ_EXT;
int maxMeshViewCountEXT;
int maxDualSourceDrawBuffersEXT;
TLimits limits;
};
#endif // _RESOURCE_LIMITS_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/glslang_c_shader_types.h | /**
This code is based on the glslang_c_interface implementation by Viktor Latypov
**/
/**
BSD 2-Clause License
Copyright (c) 2019, Viktor Latypov
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
#ifndef C_SHADER_TYPES_H_INCLUDED
#define C_SHADER_TYPES_H_INCLUDED
#define LAST_ELEMENT_MARKER(x) x
/* EShLanguage counterpart */
typedef enum {
GLSLANG_STAGE_VERTEX,
GLSLANG_STAGE_TESSCONTROL,
GLSLANG_STAGE_TESSEVALUATION,
GLSLANG_STAGE_GEOMETRY,
GLSLANG_STAGE_FRAGMENT,
GLSLANG_STAGE_COMPUTE,
GLSLANG_STAGE_RAYGEN,
GLSLANG_STAGE_RAYGEN_NV = GLSLANG_STAGE_RAYGEN,
GLSLANG_STAGE_INTERSECT,
GLSLANG_STAGE_INTERSECT_NV = GLSLANG_STAGE_INTERSECT,
GLSLANG_STAGE_ANYHIT,
GLSLANG_STAGE_ANYHIT_NV = GLSLANG_STAGE_ANYHIT,
GLSLANG_STAGE_CLOSESTHIT,
GLSLANG_STAGE_CLOSESTHIT_NV = GLSLANG_STAGE_CLOSESTHIT,
GLSLANG_STAGE_MISS,
GLSLANG_STAGE_MISS_NV = GLSLANG_STAGE_MISS,
GLSLANG_STAGE_CALLABLE,
GLSLANG_STAGE_CALLABLE_NV = GLSLANG_STAGE_CALLABLE,
GLSLANG_STAGE_TASK,
GLSLANG_STAGE_TASK_NV = GLSLANG_STAGE_TASK,
GLSLANG_STAGE_MESH,
GLSLANG_STAGE_MESH_NV = GLSLANG_STAGE_MESH,
LAST_ELEMENT_MARKER(GLSLANG_STAGE_COUNT),
} glslang_stage_t; // would be better as stage, but this is ancient now
/* EShLanguageMask counterpart */
typedef enum {
GLSLANG_STAGE_VERTEX_MASK = (1 << GLSLANG_STAGE_VERTEX),
GLSLANG_STAGE_TESSCONTROL_MASK = (1 << GLSLANG_STAGE_TESSCONTROL),
GLSLANG_STAGE_TESSEVALUATION_MASK = (1 << GLSLANG_STAGE_TESSEVALUATION),
GLSLANG_STAGE_GEOMETRY_MASK = (1 << GLSLANG_STAGE_GEOMETRY),
GLSLANG_STAGE_FRAGMENT_MASK = (1 << GLSLANG_STAGE_FRAGMENT),
GLSLANG_STAGE_COMPUTE_MASK = (1 << GLSLANG_STAGE_COMPUTE),
GLSLANG_STAGE_RAYGEN_MASK = (1 << GLSLANG_STAGE_RAYGEN),
GLSLANG_STAGE_RAYGEN_NV_MASK = GLSLANG_STAGE_RAYGEN_MASK,
GLSLANG_STAGE_INTERSECT_MASK = (1 << GLSLANG_STAGE_INTERSECT),
GLSLANG_STAGE_INTERSECT_NV_MASK = GLSLANG_STAGE_INTERSECT_MASK,
GLSLANG_STAGE_ANYHIT_MASK = (1 << GLSLANG_STAGE_ANYHIT),
GLSLANG_STAGE_ANYHIT_NV_MASK = GLSLANG_STAGE_ANYHIT_MASK,
GLSLANG_STAGE_CLOSESTHIT_MASK = (1 << GLSLANG_STAGE_CLOSESTHIT),
GLSLANG_STAGE_CLOSESTHIT_NV_MASK = GLSLANG_STAGE_CLOSESTHIT_MASK,
GLSLANG_STAGE_MISS_MASK = (1 << GLSLANG_STAGE_MISS),
GLSLANG_STAGE_MISS_NV_MASK = GLSLANG_STAGE_MISS_MASK,
GLSLANG_STAGE_CALLABLE_MASK = (1 << GLSLANG_STAGE_CALLABLE),
GLSLANG_STAGE_CALLABLE_NV_MASK = GLSLANG_STAGE_CALLABLE_MASK,
GLSLANG_STAGE_TASK_MASK = (1 << GLSLANG_STAGE_TASK),
GLSLANG_STAGE_TASK_NV_MASK = GLSLANG_STAGE_TASK_MASK,
GLSLANG_STAGE_MESH_MASK = (1 << GLSLANG_STAGE_MESH),
GLSLANG_STAGE_MESH_NV_MASK = GLSLANG_STAGE_MESH_MASK,
LAST_ELEMENT_MARKER(GLSLANG_STAGE_MASK_COUNT),
} glslang_stage_mask_t;
/* EShSource counterpart */
typedef enum {
GLSLANG_SOURCE_NONE,
GLSLANG_SOURCE_GLSL,
GLSLANG_SOURCE_HLSL,
LAST_ELEMENT_MARKER(GLSLANG_SOURCE_COUNT),
} glslang_source_t;
/* EShClient counterpart */
typedef enum {
GLSLANG_CLIENT_NONE,
GLSLANG_CLIENT_VULKAN,
GLSLANG_CLIENT_OPENGL,
LAST_ELEMENT_MARKER(GLSLANG_CLIENT_COUNT),
} glslang_client_t;
/* EShTargetLanguage counterpart */
typedef enum {
GLSLANG_TARGET_NONE,
GLSLANG_TARGET_SPV,
LAST_ELEMENT_MARKER(GLSLANG_TARGET_COUNT),
} glslang_target_language_t;
/* SH_TARGET_ClientVersion counterpart */
typedef enum {
GLSLANG_TARGET_VULKAN_1_0 = (1 << 22),
GLSLANG_TARGET_VULKAN_1_1 = (1 << 22) | (1 << 12),
GLSLANG_TARGET_VULKAN_1_2 = (1 << 22) | (2 << 12),
GLSLANG_TARGET_VULKAN_1_3 = (1 << 22) | (3 << 12),
GLSLANG_TARGET_OPENGL_450 = 450,
LAST_ELEMENT_MARKER(GLSLANG_TARGET_CLIENT_VERSION_COUNT = 5),
} glslang_target_client_version_t;
/* SH_TARGET_LanguageVersion counterpart */
typedef enum {
GLSLANG_TARGET_SPV_1_0 = (1 << 16),
GLSLANG_TARGET_SPV_1_1 = (1 << 16) | (1 << 8),
GLSLANG_TARGET_SPV_1_2 = (1 << 16) | (2 << 8),
GLSLANG_TARGET_SPV_1_3 = (1 << 16) | (3 << 8),
GLSLANG_TARGET_SPV_1_4 = (1 << 16) | (4 << 8),
GLSLANG_TARGET_SPV_1_5 = (1 << 16) | (5 << 8),
GLSLANG_TARGET_SPV_1_6 = (1 << 16) | (6 << 8),
LAST_ELEMENT_MARKER(GLSLANG_TARGET_LANGUAGE_VERSION_COUNT = 7),
} glslang_target_language_version_t;
/* EShExecutable counterpart */
typedef enum { GLSLANG_EX_VERTEX_FRAGMENT, GLSLANG_EX_FRAGMENT } glslang_executable_t;
// EShOptimizationLevel counterpart
// This enum is not used in the current C interface, but could be added at a later date.
// GLSLANG_OPT_NONE is the current default.
typedef enum {
GLSLANG_OPT_NO_GENERATION,
GLSLANG_OPT_NONE,
GLSLANG_OPT_SIMPLE,
GLSLANG_OPT_FULL,
LAST_ELEMENT_MARKER(GLSLANG_OPT_LEVEL_COUNT),
} glslang_optimization_level_t;
/* EShTextureSamplerTransformMode counterpart */
typedef enum {
GLSLANG_TEX_SAMP_TRANS_KEEP,
GLSLANG_TEX_SAMP_TRANS_UPGRADE_TEXTURE_REMOVE_SAMPLER,
LAST_ELEMENT_MARKER(GLSLANG_TEX_SAMP_TRANS_COUNT),
} glslang_texture_sampler_transform_mode_t;
/* EShMessages counterpart */
typedef enum {
GLSLANG_MSG_DEFAULT_BIT = 0,
GLSLANG_MSG_RELAXED_ERRORS_BIT = (1 << 0),
GLSLANG_MSG_SUPPRESS_WARNINGS_BIT = (1 << 1),
GLSLANG_MSG_AST_BIT = (1 << 2),
GLSLANG_MSG_SPV_RULES_BIT = (1 << 3),
GLSLANG_MSG_VULKAN_RULES_BIT = (1 << 4),
GLSLANG_MSG_ONLY_PREPROCESSOR_BIT = (1 << 5),
GLSLANG_MSG_READ_HLSL_BIT = (1 << 6),
GLSLANG_MSG_CASCADING_ERRORS_BIT = (1 << 7),
GLSLANG_MSG_KEEP_UNCALLED_BIT = (1 << 8),
GLSLANG_MSG_HLSL_OFFSETS_BIT = (1 << 9),
GLSLANG_MSG_DEBUG_INFO_BIT = (1 << 10),
GLSLANG_MSG_HLSL_ENABLE_16BIT_TYPES_BIT = (1 << 11),
GLSLANG_MSG_HLSL_LEGALIZATION_BIT = (1 << 12),
GLSLANG_MSG_HLSL_DX9_COMPATIBLE_BIT = (1 << 13),
GLSLANG_MSG_BUILTIN_SYMBOL_TABLE_BIT = (1 << 14),
GLSLANG_MSG_ENHANCED = (1 << 15),
GLSLANG_MSG_ABSOLUTE_PATH = (1 << 16),
LAST_ELEMENT_MARKER(GLSLANG_MSG_COUNT),
} glslang_messages_t;
/* EShReflectionOptions counterpart */
typedef enum {
GLSLANG_REFLECTION_DEFAULT_BIT = 0,
GLSLANG_REFLECTION_STRICT_ARRAY_SUFFIX_BIT = (1 << 0),
GLSLANG_REFLECTION_BASIC_ARRAY_SUFFIX_BIT = (1 << 1),
GLSLANG_REFLECTION_INTERMEDIATE_IOO_BIT = (1 << 2),
GLSLANG_REFLECTION_SEPARATE_BUFFERS_BIT = (1 << 3),
GLSLANG_REFLECTION_ALL_BLOCK_VARIABLES_BIT = (1 << 4),
GLSLANG_REFLECTION_UNWRAP_IO_BLOCKS_BIT = (1 << 5),
GLSLANG_REFLECTION_ALL_IO_VARIABLES_BIT = (1 << 6),
GLSLANG_REFLECTION_SHARED_STD140_SSBO_BIT = (1 << 7),
GLSLANG_REFLECTION_SHARED_STD140_UBO_BIT = (1 << 8),
LAST_ELEMENT_MARKER(GLSLANG_REFLECTION_COUNT),
} glslang_reflection_options_t;
/* EProfile counterpart (from Versions.h) */
typedef enum {
GLSLANG_BAD_PROFILE = 0,
GLSLANG_NO_PROFILE = (1 << 0),
GLSLANG_CORE_PROFILE = (1 << 1),
GLSLANG_COMPATIBILITY_PROFILE = (1 << 2),
GLSLANG_ES_PROFILE = (1 << 3),
LAST_ELEMENT_MARKER(GLSLANG_PROFILE_COUNT),
} glslang_profile_t;
/* Shader options */
typedef enum {
GLSLANG_SHADER_DEFAULT_BIT = 0,
GLSLANG_SHADER_AUTO_MAP_BINDINGS = (1 << 0),
GLSLANG_SHADER_AUTO_MAP_LOCATIONS = (1 << 1),
GLSLANG_SHADER_VULKAN_RULES_RELAXED = (1 << 2),
LAST_ELEMENT_MARKER(GLSLANG_SHADER_COUNT),
} glslang_shader_options_t;
/* TResourceType counterpart */
typedef enum {
GLSLANG_RESOURCE_TYPE_SAMPLER,
GLSLANG_RESOURCE_TYPE_TEXTURE,
GLSLANG_RESOURCE_TYPE_IMAGE,
GLSLANG_RESOURCE_TYPE_UBO,
GLSLANG_RESOURCE_TYPE_SSBO,
GLSLANG_RESOURCE_TYPE_UAV,
LAST_ELEMENT_MARKER(GLSLANG_RESOURCE_TYPE_COUNT),
} glslang_resource_type_t;
#undef LAST_ELEMENT_MARKER
#endif
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/InitializeGlobals.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef __INITIALIZE_GLOBALS_INCLUDED_
#define __INITIALIZE_GLOBALS_INCLUDED_
namespace glslang {
inline bool InitializePoolIndex() { return true; } // DEPRECATED: No need to call
} // end namespace glslang
#endif // __INITIALIZE_GLOBALS_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/SpirvIntrinsics.h | //
// Copyright(C) 2021 Advanced Micro Devices, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#pragma once
//
// GL_EXT_spirv_intrinsics
//
#include "Common.h"
#include <variant>
namespace glslang {
class TIntermTyped;
class TIntermConstantUnion;
class TType;
// SPIR-V requirements
struct TSpirvRequirement {
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
// capability = [..]
TSet<TString> extensions;
// extension = [..]
TSet<int> capabilities;
};
// SPIR-V execution modes
struct TSpirvExecutionMode {
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
// spirv_execution_mode
TMap<int, TVector<const TIntermConstantUnion*>> modes;
// spirv_execution_mode_id
TMap<int, TVector<const TIntermTyped*> > modeIds;
};
// SPIR-V decorations
struct TSpirvDecorate {
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
// spirv_decorate
TMap<int, TVector<const TIntermConstantUnion*> > decorates;
// spirv_decorate_id
TMap<int, TVector<const TIntermTyped*>> decorateIds;
// spirv_decorate_string
TMap<int, TVector<const TIntermConstantUnion*> > decorateStrings;
};
// SPIR-V instruction
struct TSpirvInstruction {
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TSpirvInstruction() { set = ""; id = -1; }
bool operator==(const TSpirvInstruction& rhs) const { return set == rhs.set && id == rhs.id; }
bool operator!=(const TSpirvInstruction& rhs) const { return !operator==(rhs); }
// spirv_instruction
TString set;
int id;
};
// SPIR-V type parameter
struct TSpirvTypeParameter {
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TSpirvTypeParameter(const TIntermConstantUnion* arg) { value = arg; }
TSpirvTypeParameter(const TType* arg) { value = arg; }
const TIntermConstantUnion* getAsConstant() const
{
if (value.index() == 0)
return std::get<const TIntermConstantUnion*>(value);
return nullptr;
}
const TType* getAsType() const
{
if (value.index() == 1)
return std::get<const TType*>(value);
return nullptr;
}
bool operator==(const TSpirvTypeParameter& rhs) const;
bool operator!=(const TSpirvTypeParameter& rhs) const { return !operator==(rhs); }
// Parameter value: constant expression or type specifier
std::variant<const TIntermConstantUnion*, const TType*> value;
};
typedef TVector<TSpirvTypeParameter> TSpirvTypeParameters;
// SPIR-V type
struct TSpirvType {
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
bool operator==(const TSpirvType& rhs) const
{
return spirvInst == rhs.spirvInst && typeParams == rhs.typeParams;
}
bool operator!=(const TSpirvType& rhs) const { return !operator==(rhs); }
// spirv_type
TSpirvInstruction spirvInst;
TSpirvTypeParameters typeParams;
};
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/InfoSink.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _INFOSINK_INCLUDED_
#define _INFOSINK_INCLUDED_
#include "../Include/Common.h"
#include <filesystem>
#include <cmath>
namespace glslang {
//
// TPrefixType is used to centralize how info log messages start.
// See below.
//
enum TPrefixType {
EPrefixNone,
EPrefixWarning,
EPrefixError,
EPrefixInternalError,
EPrefixUnimplemented,
EPrefixNote
};
enum TOutputStream {
ENull = 0,
EDebugger = 0x01,
EStdOut = 0x02,
EString = 0x04,
};
//
// Encapsulate info logs for all objects that have them.
//
// The methods are a general set of tools for getting a variety of
// messages and types inserted into the log.
//
class TInfoSinkBase {
public:
TInfoSinkBase() : outputStream(4), shaderFileName(nullptr) {}
void erase() { sink.erase(); }
TInfoSinkBase& operator<<(const TPersistString& t) { append(t); return *this; }
TInfoSinkBase& operator<<(char c) { append(1, c); return *this; }
TInfoSinkBase& operator<<(const char* s) { append(s); return *this; }
TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; }
TInfoSinkBase& operator<<(unsigned int n) { append(String(n)); return *this; }
TInfoSinkBase& operator<<(float n) { const int size = 40; char buf[size];
snprintf(buf, size, (fabs(n) > 1e-8 && fabs(n) < 1e8) || n == 0.0f ? "%f" : "%g", n);
append(buf);
return *this; }
TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; }
TInfoSinkBase& operator+(const TString& t) { append(t); return *this; }
TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; }
TInfoSinkBase& operator+(const char* s) { append(s); return *this; }
const char* c_str() const { return sink.c_str(); }
void prefix(TPrefixType message) {
switch(message) {
case EPrefixNone: break;
case EPrefixWarning: append("WARNING: "); break;
case EPrefixError: append("ERROR: "); break;
case EPrefixInternalError: append("INTERNAL ERROR: "); break;
case EPrefixUnimplemented: append("UNIMPLEMENTED: "); break;
case EPrefixNote: append("NOTE: "); break;
default: append("UNKNOWN ERROR: "); break;
}
}
void location(const TSourceLoc& loc, bool absolute = false) {
const int maxSize = 24;
char locText[maxSize];
snprintf(locText, maxSize, ":%d", loc.line);
if(loc.getFilename() == nullptr && shaderFileName != nullptr && absolute) {
append(std::filesystem::absolute(shaderFileName).string());
} else {
std::string location = loc.getStringNameOrNum(false);
if (absolute) {
append(std::filesystem::absolute(location).string());
} else {
append(location);
}
}
append(locText);
append(": ");
}
void message(TPrefixType message, const char* s) {
prefix(message);
append(s);
append("\n");
}
void message(TPrefixType message, const char* s, const TSourceLoc& loc) {
prefix(message);
location(loc);
append(s);
append("\n");
}
void setOutputStream(int output = 4)
{
outputStream = output;
}
void setShaderFileName(const char* file = nullptr)
{
shaderFileName = file;
}
protected:
void append(const char* s);
void append(int count, char c);
void append(const TPersistString& t);
void append(const TString& t);
void checkMem(size_t growth) { if (sink.capacity() < sink.size() + growth + 2)
sink.reserve(sink.capacity() + sink.capacity() / 2); }
void appendToStream(const char* s);
TPersistString sink;
int outputStream;
const char* shaderFileName;
};
} // end namespace glslang
class TInfoSink {
public:
glslang::TInfoSinkBase info;
glslang::TInfoSinkBase debug;
};
#endif // _INFOSINK_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Include/PoolAlloc.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _POOLALLOC_INCLUDED_
#define _POOLALLOC_INCLUDED_
#ifndef NDEBUG
# define GUARD_BLOCKS // define to enable guard block sanity checking
#endif
//
// This header defines an allocator that can be used to efficiently
// allocate a large number of small requests for heap memory, with the
// intention that they are not individually deallocated, but rather
// collectively deallocated at one time.
//
// This simultaneously
//
// * Makes each individual allocation much more efficient; the
// typical allocation is trivial.
// * Completely avoids the cost of doing individual deallocation.
// * Saves the trouble of tracking down and plugging a large class of leaks.
//
// Individual classes can use this allocator by supplying their own
// new and delete methods.
//
// STL containers can use this allocator by using the pool_allocator
// class as the allocator (second) template argument.
//
#include <cstddef>
#include <cstring>
#include <vector>
namespace glslang {
// If we are using guard blocks, we must track each individual
// allocation. If we aren't using guard blocks, these
// never get instantiated, so won't have any impact.
//
class TAllocation {
public:
TAllocation(size_t size, unsigned char* mem, TAllocation* prev = nullptr) :
size(size), mem(mem), prevAlloc(prev) {
// Allocations are bracketed:
// [allocationHeader][initialGuardBlock][userData][finalGuardBlock]
// This would be cleaner with if (guardBlockSize)..., but that
// makes the compiler print warnings about 0 length memsets,
// even with the if() protecting them.
# ifdef GUARD_BLOCKS
memset(preGuard(), guardBlockBeginVal, guardBlockSize);
memset(data(), userDataFill, size);
memset(postGuard(), guardBlockEndVal, guardBlockSize);
# endif
}
void check() const {
checkGuardBlock(preGuard(), guardBlockBeginVal, "before");
checkGuardBlock(postGuard(), guardBlockEndVal, "after");
}
void checkAllocList() const;
// Return total size needed to accommodate user buffer of 'size',
// plus our tracking data.
inline static size_t allocationSize(size_t size) {
return size + 2 * guardBlockSize + headerSize();
}
// Offset from surrounding buffer to get to user data buffer.
inline static unsigned char* offsetAllocation(unsigned char* m) {
return m + guardBlockSize + headerSize();
}
private:
void checkGuardBlock(unsigned char* blockMem, unsigned char val, const char* locText) const;
// Find offsets to pre and post guard blocks, and user data buffer
unsigned char* preGuard() const { return mem + headerSize(); }
unsigned char* data() const { return preGuard() + guardBlockSize; }
unsigned char* postGuard() const { return data() + size; }
size_t size; // size of the user data area
unsigned char* mem; // beginning of our allocation (pts to header)
TAllocation* prevAlloc; // prior allocation in the chain
static inline constexpr unsigned char guardBlockBeginVal = 0xfb;
static inline constexpr unsigned char guardBlockEndVal = 0xfe;
static inline constexpr unsigned char userDataFill = 0xcd;
# ifdef GUARD_BLOCKS
static inline constexpr size_t guardBlockSize = 16;
# else
static inline constexpr size_t guardBlockSize = 0;
# endif
# ifdef GUARD_BLOCKS
inline static size_t headerSize() { return sizeof(TAllocation); }
# else
inline static size_t headerSize() { return 0; }
# endif
};
//
// There are several stacks. One is to track the pushing and popping
// of the user, and not yet implemented. The others are simply a
// repositories of free pages or used pages.
//
// Page stacks are linked together with a simple header at the beginning
// of each allocation obtained from the underlying OS. Multi-page allocations
// are returned to the OS. Individual page allocations are kept for future
// re-use.
//
// The "page size" used is not, nor must it match, the underlying OS
// page size. But, having it be about that size or equal to a set of
// pages is likely most optimal.
//
class TPoolAllocator {
public:
TPoolAllocator(int growthIncrement = 8*1024, int allocationAlignment = 16);
//
// Don't call the destructor just to free up the memory, call pop()
//
~TPoolAllocator();
//
// Call push() to establish a new place to pop memory too. Does not
// have to be called to get things started.
//
void push();
//
// Call pop() to free all memory allocated since the last call to push(),
// or if no last call to push, frees all memory since first allocation.
//
void pop();
//
// Call popAll() to free all memory allocated.
//
void popAll();
//
// Call allocate() to actually acquire memory. Returns nullptr if no memory
// available, otherwise a properly aligned pointer to 'numBytes' of memory.
//
void* allocate(size_t numBytes);
//
// There is no deallocate. The point of this class is that
// deallocation can be skipped by the user of it, as the model
// of use is to simultaneously deallocate everything at once
// by calling pop(), and to not have to solve memory leak problems.
//
protected:
friend struct tHeader;
struct tHeader {
tHeader(tHeader* nextPage, size_t pageCount) :
#ifdef GUARD_BLOCKS
lastAllocation(nullptr),
#endif
nextPage(nextPage), pageCount(pageCount) { }
~tHeader() {
#ifdef GUARD_BLOCKS
if (lastAllocation)
lastAllocation->checkAllocList();
#endif
}
#ifdef GUARD_BLOCKS
TAllocation* lastAllocation;
#endif
tHeader* nextPage;
size_t pageCount;
};
struct tAllocState {
size_t offset;
tHeader* page;
};
typedef std::vector<tAllocState> tAllocStack;
// Track allocations if and only if we're using guard blocks
#ifndef GUARD_BLOCKS
void* initializeAllocation(tHeader*, unsigned char* memory, size_t) {
#else
void* initializeAllocation(tHeader* block, unsigned char* memory, size_t numBytes) {
new(memory) TAllocation(numBytes, memory, block->lastAllocation);
block->lastAllocation = reinterpret_cast<TAllocation*>(memory);
#endif
// This is optimized entirely away if GUARD_BLOCKS is not defined.
return TAllocation::offsetAllocation(memory);
}
size_t pageSize; // granularity of allocation from the OS
size_t alignment; // all returned allocations will be aligned at
// this granularity, which will be a power of 2
size_t alignmentMask;
size_t headerSkip; // amount of memory to skip to make room for the
// header (basically, size of header, rounded
// up to make it aligned
size_t currentPageOffset; // next offset in top of inUseList to allocate from
tHeader* freeList; // list of popped memory
tHeader* inUseList; // list of all memory currently being used
tAllocStack stack; // stack of where to allocate from, to partition pool
int numCalls; // just an interesting statistic
size_t totalBytes; // just an interesting statistic
private:
TPoolAllocator& operator=(const TPoolAllocator&); // don't allow assignment operator
TPoolAllocator(const TPoolAllocator&); // don't allow default copy constructor
};
//
// There could potentially be many pools with pops happening at
// different times. But a simple use is to have a global pop
// with everyone using the same global allocator.
//
extern TPoolAllocator& GetThreadPoolAllocator();
void SetThreadPoolAllocator(TPoolAllocator* poolAllocator);
//
// This STL compatible allocator is intended to be used as the allocator
// parameter to templatized STL containers, like vector and map.
//
// It will use the pools for allocation, and not
// do any deallocation, but will still do destruction.
//
template<class T>
class pool_allocator {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T *pointer;
typedef const T *const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template<class Other>
struct rebind {
typedef pool_allocator<Other> other;
};
pointer address(reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; }
pool_allocator() : allocator(GetThreadPoolAllocator()) { }
pool_allocator(TPoolAllocator& a) : allocator(a) { }
pool_allocator(const pool_allocator<T>& p) : allocator(p.allocator) { }
template<class Other>
pool_allocator(const pool_allocator<Other>& p) : allocator(p.getAllocator()) { }
pointer allocate(size_type n) {
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
pointer allocate(size_type n, const void*) {
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
void deallocate(void*, size_type) { }
void deallocate(pointer, size_type) { }
pointer _Charalloc(size_t n) {
return reinterpret_cast<pointer>(getAllocator().allocate(n)); }
void construct(pointer p, const T& val) { new ((void *)p) T(val); }
void destroy(pointer p) { p->T::~T(); }
bool operator==(const pool_allocator& rhs) const { return &getAllocator() == &rhs.getAllocator(); }
bool operator!=(const pool_allocator& rhs) const { return &getAllocator() != &rhs.getAllocator(); }
size_type max_size() const { return static_cast<size_type>(-1) / sizeof(T); }
size_type max_size(int size) const { return static_cast<size_type>(-1) / size; }
TPoolAllocator& getAllocator() const { return allocator; }
pool_allocator select_on_container_copy_construction() const { return pool_allocator{}; }
protected:
pool_allocator& operator=(const pool_allocator&) { return *this; }
TPoolAllocator& allocator;
};
} // end namespace glslang
#endif // _POOLALLOC_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslScanContext.h | //
// Copyright (C) 2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// This holds context specific to the HLSL scanner, which
// sits between the preprocessor scanner and HLSL parser.
//
#ifndef HLSLSCANCONTEXT_H_
#define HLSLSCANCONTEXT_H_
#include "../MachineIndependent/ParseHelper.h"
#include "hlslTokens.h"
namespace glslang {
class TPpContext;
class TPpToken;
//
// Everything needed to fully describe a token.
//
struct HlslToken {
HlslToken() : string(nullptr) { loc.init(); }
TSourceLoc loc; // location of token in the source
EHlslTokenClass tokenClass; // what kind of token it is
union { // what data the token holds
glslang::TString *string; // for identifiers
int i; // for literals
unsigned int u;
bool b;
double d;
};
};
//
// The state of scanning and translating raw tokens to slightly richer
// semantics, like knowing if an identifier is an existing symbol, or
// user-defined type.
//
class HlslScanContext {
public:
HlslScanContext(TParseContextBase& parseContext, TPpContext& ppContext)
: parseContext(parseContext), ppContext(ppContext) { }
virtual ~HlslScanContext() { }
static void fillInKeywordMap();
static void deleteKeywordMap();
void tokenize(HlslToken&);
glslang::TBuiltInVariable mapSemantic(const char*);
protected:
HlslScanContext(HlslScanContext&);
HlslScanContext& operator=(HlslScanContext&);
EHlslTokenClass tokenizeClass(HlslToken&);
EHlslTokenClass tokenizeIdentifier();
EHlslTokenClass identifierOrType();
EHlslTokenClass reservedWord();
EHlslTokenClass identifierOrReserved(bool reserved);
EHlslTokenClass nonreservedKeyword(int version);
TParseContextBase& parseContext;
TPpContext& ppContext;
TSourceLoc loc;
TPpToken* ppToken;
HlslToken* parserToken;
const char* tokenText;
EHlslTokenClass keyword;
};
} // end namespace glslang
#endif // HLSLSCANCONTEXT_H_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslGrammar.h | //
// Copyright (C) 2016-2018 Google, Inc.
// Copyright (C) 2016 LunarG, Inc.
// Copyright (C) 2023 Mobica Limited.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef HLSLGRAMMAR_H_
#define HLSLGRAMMAR_H_
#include "hlslParseHelper.h"
#include "hlslOpMap.h"
#include "hlslTokenStream.h"
namespace glslang {
class TFunctionDeclarator;
// Should just be the grammar aspect of HLSL.
// Described in more detail in hlslGrammar.cpp.
class HlslGrammar : public HlslTokenStream {
public:
HlslGrammar(HlslScanContext& scanner, HlslParseContext& parseContext)
: HlslTokenStream(scanner), parseContext(parseContext), intermediate(parseContext.intermediate),
typeIdentifiers(false), unitNode(nullptr) { }
virtual ~HlslGrammar() { }
bool parse();
protected:
HlslGrammar();
HlslGrammar& operator=(const HlslGrammar&);
void expected(const char*);
void unimplemented(const char*);
bool acceptIdentifier(HlslToken&);
bool acceptCompilationUnit();
bool acceptDeclarationList(TIntermNode*&);
bool acceptDeclaration(TIntermNode*&);
bool acceptControlDeclaration(TIntermNode*& node);
bool acceptSamplerDeclarationDX9(TType&);
bool acceptSamplerState();
bool acceptFullySpecifiedType(TType&, const TAttributes&);
bool acceptFullySpecifiedType(TType&, TIntermNode*& nodeList, const TAttributes&, bool forbidDeclarators = false);
bool acceptPreQualifier(TQualifier&);
bool acceptPostQualifier(TQualifier&);
bool acceptLayoutQualifierList(TQualifier&);
bool acceptType(TType&);
bool acceptType(TType&, TIntermNode*& nodeList);
bool acceptTemplateVecMatBasicType(TBasicType&, TPrecisionQualifier&);
bool acceptVectorTemplateType(TType&);
bool acceptMatrixTemplateType(TType&);
bool acceptTessellationDeclType(TBuiltInVariable&);
bool acceptTessellationPatchTemplateType(TType&);
bool acceptStreamOutTemplateType(TType&, TLayoutGeometry&);
bool acceptOutputPrimitiveGeometry(TLayoutGeometry&);
bool acceptAnnotations(TQualifier&);
bool acceptSamplerTypeDX9(TType &);
bool acceptSamplerType(TType&);
bool acceptTextureType(TType&);
bool acceptSubpassInputType(TType&);
bool acceptStructBufferType(TType&);
bool acceptTextureBufferType(TType&);
bool acceptConstantBufferType(TType&);
bool acceptStruct(TType&, TIntermNode*& nodeList);
bool acceptStructDeclarationList(TTypeList*&, TIntermNode*& nodeList, TVector<TFunctionDeclarator>&);
bool acceptMemberFunctionDefinition(TIntermNode*& nodeList, const TType&, TString& memberName,
TFunctionDeclarator&);
bool acceptFunctionParameters(TFunction&);
bool acceptParameterDeclaration(TFunction&);
bool acceptFunctionDefinition(TFunctionDeclarator&, TIntermNode*& nodeList, TVector<HlslToken>* deferredTokens);
bool acceptFunctionBody(TFunctionDeclarator& declarator, TIntermNode*& nodeList);
bool acceptParenExpression(TIntermTyped*&);
bool acceptExpression(TIntermTyped*&);
bool acceptInitializer(TIntermTyped*&);
bool acceptAssignmentExpression(TIntermTyped*&);
bool acceptConditionalExpression(TIntermTyped*&);
bool acceptBinaryExpression(TIntermTyped*&, PrecedenceLevel);
bool acceptUnaryExpression(TIntermTyped*&);
bool acceptPostfixExpression(TIntermTyped*&);
bool acceptConstructor(TIntermTyped*&);
bool acceptFunctionCall(const TSourceLoc&, TString& name, TIntermTyped*&, TIntermTyped* objectBase);
bool acceptArguments(TFunction*, TIntermTyped*&);
bool acceptLiteral(TIntermTyped*&);
bool acceptSimpleStatement(TIntermNode*&);
bool acceptCompoundStatement(TIntermNode*&);
bool acceptScopedStatement(TIntermNode*&);
bool acceptScopedCompoundStatement(TIntermNode*&);
bool acceptStatement(TIntermNode*&);
bool acceptNestedStatement(TIntermNode*&);
void acceptAttributes(TAttributes&);
bool acceptSelectionStatement(TIntermNode*&, const TAttributes&);
bool acceptSwitchStatement(TIntermNode*&, const TAttributes&);
bool acceptIterationStatement(TIntermNode*&, const TAttributes&);
bool acceptJumpStatement(TIntermNode*&);
bool acceptCaseLabel(TIntermNode*&);
bool acceptDefaultLabel(TIntermNode*&);
void acceptArraySpecifier(TArraySizes*&);
bool acceptPostDecls(TQualifier&);
bool acceptDefaultParameterDeclaration(const TType&, TIntermTyped*&);
bool captureBlockTokens(TVector<HlslToken>& tokens);
const char* getTypeString(EHlslTokenClass tokenClass) const;
HlslParseContext& parseContext; // state of parsing and helper functions for building the intermediate
TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST
bool typeIdentifiers; // shader uses some types as identifiers
TIntermNode* unitNode;
};
} // end namespace glslang
#endif // HLSLGRAMMAR_H_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslTokenStream.cpp | //
// Copyright (C) 2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "hlslTokenStream.h"
namespace glslang {
void HlslTokenStream::pushPreToken(const HlslToken& tok)
{
assert(preTokenStackSize < tokenBufferSize);
preTokenStack[preTokenStackSize++] = tok;
}
HlslToken HlslTokenStream::popPreToken()
{
assert(preTokenStackSize > 0);
return preTokenStack[--preTokenStackSize];
}
void HlslTokenStream::pushTokenBuffer(const HlslToken& tok)
{
tokenBuffer[tokenBufferPos] = tok;
tokenBufferPos = (tokenBufferPos+1) % tokenBufferSize;
}
HlslToken HlslTokenStream::popTokenBuffer()
{
// Back up
tokenBufferPos = (tokenBufferPos+tokenBufferSize-1) % tokenBufferSize;
return tokenBuffer[tokenBufferPos];
}
//
// Make a new source of tokens, not from the source, but from an
// already pre-processed token stream.
//
// This interrupts current token processing which must be restored
// later. Some simplifying assumptions are made (and asserted).
//
void HlslTokenStream::pushTokenStream(const TVector<HlslToken>* tokens)
{
// not yet setup to interrupt a stream that has been receded
// and not yet reconsumed
assert(preTokenStackSize == 0);
// save current state
currentTokenStack.push_back(token);
// set up new token stream
tokenStreamStack.push_back(tokens);
// start position at first token:
token = (*tokens)[0];
tokenPosition.push_back(0);
}
// Undo pushTokenStream(), see above
void HlslTokenStream::popTokenStream()
{
tokenStreamStack.pop_back();
tokenPosition.pop_back();
token = currentTokenStack.back();
currentTokenStack.pop_back();
}
// Load 'token' with the next token in the stream of tokens.
void HlslTokenStream::advanceToken()
{
pushTokenBuffer(token);
if (preTokenStackSize > 0)
token = popPreToken();
else {
if (tokenStreamStack.size() == 0)
scanner.tokenize(token);
else {
++tokenPosition.back();
if (tokenPosition.back() >= (int)tokenStreamStack.back()->size())
token.tokenClass = EHTokNone;
else
token = (*tokenStreamStack.back())[tokenPosition.back()];
}
}
}
void HlslTokenStream::recedeToken()
{
pushPreToken(token);
token = popTokenBuffer();
}
// Return the current token class.
EHlslTokenClass HlslTokenStream::peek() const
{
return token.tokenClass;
}
// Return true, without advancing to the next token, if the current token is
// the expected (passed in) token class.
bool HlslTokenStream::peekTokenClass(EHlslTokenClass tokenClass) const
{
return peek() == tokenClass;
}
// Return true and advance to the next token if the current token is the
// expected (passed in) token class.
bool HlslTokenStream::acceptTokenClass(EHlslTokenClass tokenClass)
{
if (peekTokenClass(tokenClass)) {
advanceToken();
return true;
}
return false;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslAttributes.h | //
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef HLSLATTRIBUTES_H_
#define HLSLATTRIBUTES_H_
#include <unordered_map>
#include <functional>
#include "../MachineIndependent/attribute.h"
#include "../MachineIndependent/SymbolTable.h"
#include "hlslScanContext.h"
namespace glslang {
class TFunctionDeclarator {
public:
TFunctionDeclarator() : function(nullptr), body(nullptr) { }
TSourceLoc loc;
TFunction* function;
TAttributes attributes;
TVector<HlslToken>* body;
};
} // end namespace glslang
#endif // HLSLATTRIBUTES_H_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslTokens.h | //
// Copyright (C) 2016 Google, Inc.
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef EHLSLTOKENS_H_
#define EHLSLTOKENS_H_
namespace glslang {
enum EHlslTokenClass {
EHTokNone = 0,
// qualifiers
EHTokStatic,
EHTokConst,
EHTokSNorm,
EHTokUnorm,
EHTokExtern,
EHTokUniform,
EHTokVolatile,
EHTokPrecise,
EHTokShared,
EHTokGroupShared,
EHTokLinear,
EHTokCentroid,
EHTokNointerpolation,
EHTokNoperspective,
EHTokSample,
EHTokRowMajor,
EHTokColumnMajor,
EHTokPackOffset,
EHTokIn,
EHTokOut,
EHTokInOut,
EHTokLayout,
EHTokGloballyCoherent,
EHTokInline,
// primitive types
EHTokPoint,
EHTokLine,
EHTokTriangle,
EHTokLineAdj,
EHTokTriangleAdj,
// stream out types
EHTokPointStream,
EHTokLineStream,
EHTokTriangleStream,
// Tessellation patches
EHTokInputPatch,
EHTokOutputPatch,
// template types
EHTokBuffer,
EHTokVector,
EHTokMatrix,
// scalar types
EHTokVoid,
EHTokString,
EHTokBool,
EHTokInt,
EHTokUint,
EHTokUint64,
EHTokDword,
EHTokHalf,
EHTokFloat,
EHTokDouble,
EHTokMin16float,
EHTokMin10float,
EHTokMin16int,
EHTokMin12int,
EHTokMin16uint,
// vector types
EHTokBool1,
EHTokBool2,
EHTokBool3,
EHTokBool4,
EHTokFloat1,
EHTokFloat2,
EHTokFloat3,
EHTokFloat4,
EHTokInt1,
EHTokInt2,
EHTokInt3,
EHTokInt4,
EHTokDouble1,
EHTokDouble2,
EHTokDouble3,
EHTokDouble4,
EHTokUint1,
EHTokUint2,
EHTokUint3,
EHTokUint4,
EHTokHalf1,
EHTokHalf2,
EHTokHalf3,
EHTokHalf4,
EHTokMin16float1,
EHTokMin16float2,
EHTokMin16float3,
EHTokMin16float4,
EHTokMin10float1,
EHTokMin10float2,
EHTokMin10float3,
EHTokMin10float4,
EHTokMin16int1,
EHTokMin16int2,
EHTokMin16int3,
EHTokMin16int4,
EHTokMin12int1,
EHTokMin12int2,
EHTokMin12int3,
EHTokMin12int4,
EHTokMin16uint1,
EHTokMin16uint2,
EHTokMin16uint3,
EHTokMin16uint4,
// matrix types
EHTokInt1x1,
EHTokInt1x2,
EHTokInt1x3,
EHTokInt1x4,
EHTokInt2x1,
EHTokInt2x2,
EHTokInt2x3,
EHTokInt2x4,
EHTokInt3x1,
EHTokInt3x2,
EHTokInt3x3,
EHTokInt3x4,
EHTokInt4x1,
EHTokInt4x2,
EHTokInt4x3,
EHTokInt4x4,
EHTokUint1x1,
EHTokUint1x2,
EHTokUint1x3,
EHTokUint1x4,
EHTokUint2x1,
EHTokUint2x2,
EHTokUint2x3,
EHTokUint2x4,
EHTokUint3x1,
EHTokUint3x2,
EHTokUint3x3,
EHTokUint3x4,
EHTokUint4x1,
EHTokUint4x2,
EHTokUint4x3,
EHTokUint4x4,
EHTokBool1x1,
EHTokBool1x2,
EHTokBool1x3,
EHTokBool1x4,
EHTokBool2x1,
EHTokBool2x2,
EHTokBool2x3,
EHTokBool2x4,
EHTokBool3x1,
EHTokBool3x2,
EHTokBool3x3,
EHTokBool3x4,
EHTokBool4x1,
EHTokBool4x2,
EHTokBool4x3,
EHTokBool4x4,
EHTokFloat1x1,
EHTokFloat1x2,
EHTokFloat1x3,
EHTokFloat1x4,
EHTokFloat2x1,
EHTokFloat2x2,
EHTokFloat2x3,
EHTokFloat2x4,
EHTokFloat3x1,
EHTokFloat3x2,
EHTokFloat3x3,
EHTokFloat3x4,
EHTokFloat4x1,
EHTokFloat4x2,
EHTokFloat4x3,
EHTokFloat4x4,
EHTokHalf1x1,
EHTokHalf1x2,
EHTokHalf1x3,
EHTokHalf1x4,
EHTokHalf2x1,
EHTokHalf2x2,
EHTokHalf2x3,
EHTokHalf2x4,
EHTokHalf3x1,
EHTokHalf3x2,
EHTokHalf3x3,
EHTokHalf3x4,
EHTokHalf4x1,
EHTokHalf4x2,
EHTokHalf4x3,
EHTokHalf4x4,
EHTokDouble1x1,
EHTokDouble1x2,
EHTokDouble1x3,
EHTokDouble1x4,
EHTokDouble2x1,
EHTokDouble2x2,
EHTokDouble2x3,
EHTokDouble2x4,
EHTokDouble3x1,
EHTokDouble3x2,
EHTokDouble3x3,
EHTokDouble3x4,
EHTokDouble4x1,
EHTokDouble4x2,
EHTokDouble4x3,
EHTokDouble4x4,
EHTokMin16float1x1,
EHTokMin16float1x2,
EHTokMin16float1x3,
EHTokMin16float1x4,
EHTokMin16float2x1,
EHTokMin16float2x2,
EHTokMin16float2x3,
EHTokMin16float2x4,
EHTokMin16float3x1,
EHTokMin16float3x2,
EHTokMin16float3x3,
EHTokMin16float3x4,
EHTokMin16float4x1,
EHTokMin16float4x2,
EHTokMin16float4x3,
EHTokMin16float4x4,
EHTokMin10float1x1,
EHTokMin10float1x2,
EHTokMin10float1x3,
EHTokMin10float1x4,
EHTokMin10float2x1,
EHTokMin10float2x2,
EHTokMin10float2x3,
EHTokMin10float2x4,
EHTokMin10float3x1,
EHTokMin10float3x2,
EHTokMin10float3x3,
EHTokMin10float3x4,
EHTokMin10float4x1,
EHTokMin10float4x2,
EHTokMin10float4x3,
EHTokMin10float4x4,
EHTokMin16int1x1,
EHTokMin16int1x2,
EHTokMin16int1x3,
EHTokMin16int1x4,
EHTokMin16int2x1,
EHTokMin16int2x2,
EHTokMin16int2x3,
EHTokMin16int2x4,
EHTokMin16int3x1,
EHTokMin16int3x2,
EHTokMin16int3x3,
EHTokMin16int3x4,
EHTokMin16int4x1,
EHTokMin16int4x2,
EHTokMin16int4x3,
EHTokMin16int4x4,
EHTokMin12int1x1,
EHTokMin12int1x2,
EHTokMin12int1x3,
EHTokMin12int1x4,
EHTokMin12int2x1,
EHTokMin12int2x2,
EHTokMin12int2x3,
EHTokMin12int2x4,
EHTokMin12int3x1,
EHTokMin12int3x2,
EHTokMin12int3x3,
EHTokMin12int3x4,
EHTokMin12int4x1,
EHTokMin12int4x2,
EHTokMin12int4x3,
EHTokMin12int4x4,
EHTokMin16uint1x1,
EHTokMin16uint1x2,
EHTokMin16uint1x3,
EHTokMin16uint1x4,
EHTokMin16uint2x1,
EHTokMin16uint2x2,
EHTokMin16uint2x3,
EHTokMin16uint2x4,
EHTokMin16uint3x1,
EHTokMin16uint3x2,
EHTokMin16uint3x3,
EHTokMin16uint3x4,
EHTokMin16uint4x1,
EHTokMin16uint4x2,
EHTokMin16uint4x3,
EHTokMin16uint4x4,
// texturing types
EHTokSampler,
EHTokSampler1d,
EHTokSampler2d,
EHTokSampler3d,
EHTokSamplerCube,
EHTokSamplerState,
EHTokSamplerComparisonState,
EHTokTexture,
EHTokTexture1d,
EHTokTexture1darray,
EHTokTexture2d,
EHTokTexture2darray,
EHTokTexture3d,
EHTokTextureCube,
EHTokTextureCubearray,
EHTokTexture2DMS,
EHTokTexture2DMSarray,
EHTokRWTexture1d,
EHTokRWTexture1darray,
EHTokRWTexture2d,
EHTokRWTexture2darray,
EHTokRWTexture3d,
EHTokRWBuffer,
EHTokSubpassInput,
EHTokSubpassInputMS,
// Structure buffer variants
EHTokAppendStructuredBuffer,
EHTokByteAddressBuffer,
EHTokConsumeStructuredBuffer,
EHTokRWByteAddressBuffer,
EHTokRWStructuredBuffer,
EHTokStructuredBuffer,
EHTokTextureBuffer,
// variable, user type, ...
EHTokIdentifier,
EHTokClass,
EHTokStruct,
EHTokCBuffer,
EHTokTBuffer,
EHTokTypedef,
EHTokThis,
EHTokNamespace,
EHTokConstantBuffer,
// constant
EHTokFloat16Constant,
EHTokFloatConstant,
EHTokDoubleConstant,
EHTokIntConstant,
EHTokUintConstant,
EHTokBoolConstant,
EHTokStringConstant,
// control flow
EHTokFor,
EHTokDo,
EHTokWhile,
EHTokBreak,
EHTokContinue,
EHTokIf,
EHTokElse,
EHTokDiscard,
EHTokReturn,
EHTokSwitch,
EHTokCase,
EHTokDefault,
// expressions
EHTokLeftOp,
EHTokRightOp,
EHTokIncOp,
EHTokDecOp,
EHTokLeOp,
EHTokGeOp,
EHTokEqOp,
EHTokNeOp,
EHTokAndOp,
EHTokOrOp,
EHTokXorOp,
EHTokAssign,
EHTokMulAssign,
EHTokDivAssign,
EHTokAddAssign,
EHTokModAssign,
EHTokLeftAssign,
EHTokRightAssign,
EHTokAndAssign,
EHTokXorAssign,
EHTokOrAssign,
EHTokSubAssign,
EHTokLeftParen,
EHTokRightParen,
EHTokLeftBracket,
EHTokRightBracket,
EHTokLeftBrace,
EHTokRightBrace,
EHTokDot,
EHTokComma,
EHTokColon,
EHTokColonColon,
EHTokSemicolon,
EHTokBang,
EHTokDash,
EHTokTilde,
EHTokPlus,
EHTokStar,
EHTokSlash,
EHTokPercent,
EHTokLeftAngle,
EHTokRightAngle,
EHTokVerticalBar,
EHTokCaret,
EHTokAmpersand,
EHTokQuestion,
};
} // end namespace glslang
#endif // EHLSLTOKENS_H_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/pch.h | #ifndef _PCH_H
#define _PCH_H
//
// Copyright (C) 2018 The Khronos Group Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "hlslAttributes.h"
#include "hlslGrammar.h"
#include "hlslParseHelper.h"
#include "hlslScanContext.h"
#include "../MachineIndependent/Scan.h"
#include "../MachineIndependent/preprocessor/PpContext.h"
#include "../OSDependent/osinclude.h"
#include <algorithm>
#include <array>
#include <cctype>
#include <functional>
#include <set>
#endif /* _PCH_H */
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslParseHelper.h | //
// Copyright (C) 2016-2018 Google, Inc.
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef HLSL_PARSE_INCLUDED_
#define HLSL_PARSE_INCLUDED_
#include "../MachineIndependent/parseVersions.h"
#include "../MachineIndependent/ParseHelper.h"
#include "../MachineIndependent/attribute.h"
#include <array>
namespace glslang {
class TFunctionDeclarator;
class HlslParseContext : public TParseContextBase {
public:
HlslParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins,
int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&,
const TString sourceEntryPointName,
bool forwardCompatible = false, EShMessages messages = EShMsgDefault);
virtual ~HlslParseContext();
void initializeExtensionBehavior() override;
void setLimits(const TBuiltInResource&) override;
bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) override;
virtual const char* getGlobalUniformBlockName() const override { return "$Global"; }
virtual void setUniformBlockDefaults(TType& block) const override
{
block.getQualifier().layoutPacking = globalUniformDefaults.layoutPacking;
block.getQualifier().layoutMatrix = globalUniformDefaults.layoutMatrix;
}
void reservedPpErrorCheck(const TSourceLoc&, const char* /*name*/, const char* /*op*/) override { }
bool lineContinuationCheck(const TSourceLoc&, bool /*endOfComment*/) override { return true; }
bool lineDirectiveShouldSetNextLine() const override { return true; }
bool builtInName(const TString&);
void handlePragma(const TSourceLoc&, const TVector<TString>&) override;
TIntermTyped* handleVariable(const TSourceLoc&, const TString* string);
TIntermTyped* handleBracketDereference(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
TIntermTyped* handleBracketOperator(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
TIntermTyped* handleBinaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* left, TIntermTyped* right);
TIntermTyped* handleUnaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* childNode);
TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field);
bool isBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field);
void assignToInterface(TVariable& variable);
void handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&, const TAttributes&, TIntermNode*& entryPointTree);
TIntermNode* transformEntryPoint(const TSourceLoc&, TFunction&, const TAttributes&);
void handleEntryPointAttributes(const TSourceLoc&, const TAttributes&);
void transferTypeAttributes(const TSourceLoc&, const TAttributes&, TType&, bool allowEntry = false);
void handleFunctionBody(const TSourceLoc&, TFunction&, TIntermNode* functionBody, TIntermNode*& node);
void remapEntryPointIO(TFunction& function, TVariable*& returnValue, TVector<TVariable*>& inputs, TVector<TVariable*>& outputs);
void remapNonEntryPointIO(TFunction& function);
TIntermNode* handleDeclare(const TSourceLoc&, TIntermTyped*);
TIntermNode* handleReturnValue(const TSourceLoc&, TIntermTyped*);
void handleFunctionArgument(TFunction*, TIntermTyped*& arguments, TIntermTyped* newArg);
TIntermTyped* handleAssign(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
TIntermTyped* handleAssignToMatrixSwizzle(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermTyped*);
TIntermAggregate* assignClipCullDistance(const TSourceLoc&, TOperator, int semanticId, TIntermTyped* left, TIntermTyped* right);
TIntermTyped* assignPosition(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
TIntermTyped* assignFromFragCoord(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
void decomposeIntrinsic(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
void decomposeSampleMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
void decomposeStructBufferMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
void decomposeGeometryMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
void pushFrontArguments(TIntermTyped* front, TIntermTyped*& arguments);
void addInputArgumentConversions(const TFunction&, TIntermTyped*&);
void expandArguments(const TSourceLoc&, const TFunction&, TIntermTyped*&);
TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermOperator&);
void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
TFunction* makeConstructorCall(const TSourceLoc&, const TType&);
void handleSemantic(TSourceLoc, TQualifier&, TBuiltInVariable, const TString& upperCase);
void handlePackOffset(const TSourceLoc&, TQualifier&, const glslang::TString& location,
const glslang::TString* component);
void handleRegister(const TSourceLoc&, TQualifier&, const glslang::TString* profile, const glslang::TString& desc,
int subComponent, const glslang::TString*);
TIntermTyped* convertConditionalExpression(const TSourceLoc&, TIntermTyped*, bool mustBeScalar = true);
TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler);
bool parseMatrixSwizzleSelector(const TSourceLoc&, const TString&, int cols, int rows, TSwizzleSelectors<TMatrixSelector>&);
int getMatrixComponentsColumn(int rows, const TSwizzleSelectors<TMatrixSelector>&);
void assignError(const TSourceLoc&, const char* op, TString left, TString right);
void unaryOpError(const TSourceLoc&, const char* op, TString operand);
void binaryOpError(const TSourceLoc&, const char* op, TString left, TString right);
void variableCheck(TIntermTyped*& nodePtr);
void constantValueCheck(TIntermTyped* node, const char* token);
void integerCheck(const TIntermTyped* node, const char* token);
void globalCheck(const TSourceLoc&, const char* token);
bool constructorError(const TSourceLoc&, TIntermNode*, TFunction&, TOperator, TType&);
void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&);
void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&);
void structArrayCheck(const TSourceLoc&, const TType& structure);
bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType);
void globalQualifierFix(const TSourceLoc&, TQualifier&);
bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType);
void mergeQualifiers(TQualifier& dst, const TQualifier& src);
int computeSamplerTypeIndex(TSampler&);
TSymbol* redeclareBuiltinVariable(const TSourceLoc&, const TString&, const TQualifier&, const TShaderQualifiers&);
void paramFix(TType& type);
void specializationCheck(const TSourceLoc&, const TType&, const char* op);
void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&);
void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&, const TIntermTyped*);
void setSpecConstantId(const TSourceLoc&, TQualifier&, int value);
void mergeObjectLayoutQualifiers(TQualifier& dest, const TQualifier& src, bool inheritOnly);
void checkNoShaderLayouts(const TSourceLoc&, const TShaderQualifiers&);
const TFunction* findFunction(const TSourceLoc& loc, TFunction& call, bool& builtIn, int& thisDepth, TIntermTyped*& args);
void addGenMulArgumentConversion(const TSourceLoc& loc, TFunction& call, TIntermTyped*& args);
void declareTypedef(const TSourceLoc&, const TString& identifier, const TType&);
void declareStruct(const TSourceLoc&, TString& structName, TType&);
TSymbol* lookupUserType(const TString&, TType&);
TIntermNode* declareVariable(const TSourceLoc&, const TString& identifier, TType&, TIntermTyped* initializer = nullptr);
void lengthenList(const TSourceLoc&, TIntermSequence& list, int size, TIntermTyped* scalarInit);
TIntermTyped* handleConstructor(const TSourceLoc&, TIntermTyped*, const TType&);
TIntermTyped* addConstructor(const TSourceLoc&, TIntermTyped*, const TType&);
TIntermTyped* convertArray(TIntermTyped*, const TType&);
TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&);
TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset);
void declareBlock(const TSourceLoc&, TType&, const TString* instanceName = nullptr);
void declareStructBufferCounter(const TSourceLoc& loc, const TType& bufferType, const TString& name);
void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation);
void fixXfbOffsets(TQualifier&, TTypeList&);
void fixBlockUniformOffsets(const TQualifier&, TTypeList&);
void addQualifierToExisting(const TSourceLoc&, TQualifier, const TString& identifier);
void addQualifierToExisting(const TSourceLoc&, TQualifier, TIdentifierList&);
void updateStandaloneQualifierDefaults(const TSourceLoc&, const TPublicType&);
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body, const TAttributes&);
void nestLooping() { ++loopNestingLevel; }
void unnestLooping() { --loopNestingLevel; }
void nestAnnotations() { ++annotationNestingLevel; }
void unnestAnnotations() { --annotationNestingLevel; }
int getAnnotationNestingLevel() { return annotationNestingLevel; }
void pushScope() { symbolTable.push(); }
void popScope() { symbolTable.pop(nullptr); }
void pushThisScope(const TType&, const TVector<TFunctionDeclarator>&);
void popThisScope() { symbolTable.pop(nullptr); }
void pushImplicitThis(TVariable* thisParameter) { implicitThisStack.push_back(thisParameter); }
void popImplicitThis() { implicitThisStack.pop_back(); }
TVariable* getImplicitThis(int thisDepth) const { return implicitThisStack[implicitThisStack.size() - thisDepth]; }
void pushNamespace(const TString& name);
void popNamespace();
void getFullNamespaceName(TString*&) const;
void addScopeMangler(TString&);
void beginParameterParsing(TFunction& function)
{
parsingEntrypointParameters = isEntrypointName(function.getName());
}
void pushSwitchSequence(TIntermSequence* sequence) { switchSequenceStack.push_back(sequence); }
void popSwitchSequence() { switchSequenceStack.pop_back(); }
virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName,
TTypeList* typeList = nullptr) override;
// Apply L-value conversions. E.g, turning a write to a RWTexture into an ImageStore.
TIntermTyped* handleLvalue(const TSourceLoc&, const char* op, TIntermTyped*& node);
bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
TLayoutFormat getLayoutFromTxType(const TSourceLoc&, const TType&);
bool handleOutputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry);
bool handleInputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry);
// Determine selection control from attributes
void handleSelectionAttributes(const TSourceLoc& loc, TIntermSelection*, const TAttributes& attributes);
void handleSwitchAttributes(const TSourceLoc& loc, TIntermSwitch*, const TAttributes& attributes);
// Determine loop control from attributes
void handleLoopAttributes(const TSourceLoc& loc, TIntermLoop*, const TAttributes& attributes);
// Share struct buffer deep types
void shareStructBufferType(TType&);
// Set texture return type of the given sampler. Returns success (not all types are valid).
bool setTextureReturnType(TSampler& sampler, const TType& retType, const TSourceLoc& loc);
// Obtain the sampler return type of the given sampler in retType.
void getTextureReturnType(const TSampler& sampler, TType& retType) const;
TAttributeType attributeFromName(const TString& nameSpace, const TString& name) const;
protected:
struct TFlattenData {
TFlattenData() : nextBinding(TQualifier::layoutBindingEnd),
nextLocation(TQualifier::layoutLocationEnd) { }
TFlattenData(int nb, int nl) : nextBinding(nb), nextLocation(nl) { }
TVector<TVariable*> members; // individual flattened variables
TVector<int> offsets; // offset to next tree level
unsigned int nextBinding; // next binding to use.
unsigned int nextLocation; // next location to use
};
void fixConstInit(const TSourceLoc&, const TString& identifier, TType& type, TIntermTyped*& initializer);
void inheritGlobalDefaults(TQualifier& dst) const;
TVariable* makeInternalVariable(const char* name, const TType&) const;
TVariable* makeInternalVariable(const TString& name, const TType& type) const {
return makeInternalVariable(name.c_str(), type);
}
TIntermSymbol* makeInternalVariableNode(const TSourceLoc&, const char* name, const TType&) const;
TVariable* declareNonArray(const TSourceLoc&, const TString& identifier, const TType&, bool track);
void declareArray(const TSourceLoc&, const TString& identifier, const TType&, TSymbol*&, bool track);
TIntermNode* executeDeclaration(const TSourceLoc&, TVariable* variable);
TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer, TIntermTyped* scalarInit);
bool isScalarConstructor(const TIntermNode*);
TOperator mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage);
bool isEntrypointName(const TString& name) { return name.compare(intermediate.getEntryPointName().c_str()) == 0; }
// Return true if this node requires L-value conversion (e.g, to an imageStore).
bool shouldConvertLValue(const TIntermNode*) const;
// Array and struct flattening
TIntermTyped* flattenAccess(TIntermTyped* base, int member);
TIntermTyped* flattenAccess(long long uniqueId, int member, TStorageQualifier outerStorage, const TType&, int subset = -1);
int findSubtreeOffset(const TIntermNode&) const;
int findSubtreeOffset(const TType&, int subset, const TVector<int>& offsets) const;
bool shouldFlatten(const TType&, TStorageQualifier, bool topLevel) const;
bool wasFlattened(const TIntermTyped* node) const;
bool wasFlattened(long long id) const { return flattenMap.find(id) != flattenMap.end(); }
int addFlattenedMember(const TVariable&, const TType&, TFlattenData&, const TString& name, bool linkage,
const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes);
// Structure splitting (splits interstage built-in types into its own struct)
void split(const TVariable&);
void splitBuiltIn(const TString& baseName, const TType& memberType, const TArraySizes*, const TQualifier&);
const TType& split(const TType& type, const TString& name, const TQualifier&);
bool wasSplit(const TIntermTyped* node) const;
bool wasSplit(long long id) const { return splitNonIoVars.find(id) != splitNonIoVars.end(); }
TVariable* getSplitNonIoVar(long long id) const;
void addPatchConstantInvocation();
void fixTextureShadowModes();
void finalizeAppendMethods();
TIntermTyped* makeIntegerIndex(TIntermTyped*);
void fixBuiltInIoType(TType&);
void flatten(const TVariable& variable, bool linkage, bool arrayed = false);
int flatten(const TVariable& variable, const TType&, TFlattenData&, TString name, bool linkage,
const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes);
int flattenStruct(const TVariable& variable, const TType&, TFlattenData&, TString name, bool linkage,
const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes);
int flattenArray(const TVariable& variable, const TType&, TFlattenData&, TString name, bool linkage,
const TQualifier& outerQualifier);
bool hasUniform(const TQualifier& qualifier) const;
void clearUniform(TQualifier& qualifier);
bool isInputBuiltIn(const TQualifier& qualifier) const;
bool hasInput(const TQualifier& qualifier) const;
void correctOutput(TQualifier& qualifier);
bool isOutputBuiltIn(const TQualifier& qualifier) const;
bool hasOutput(const TQualifier& qualifier) const;
void correctInput(TQualifier& qualifier);
void correctUniform(TQualifier& qualifier);
void clearUniformInputOutput(TQualifier& qualifier);
// Test method names
bool isStructBufferMethod(const TString& name) const;
void counterBufferType(const TSourceLoc& loc, TType& type);
// Return standard sample position array
TIntermConstantUnion* getSamplePosArray(int count);
TType* getStructBufferContentType(const TType& type) const;
bool isStructBufferType(const TType& type) const { return getStructBufferContentType(type) != nullptr; }
TIntermTyped* indexStructBufferContent(const TSourceLoc& loc, TIntermTyped* buffer) const;
TIntermTyped* getStructBufferCounter(const TSourceLoc& loc, TIntermTyped* buffer);
TString getStructBuffCounterName(const TString&) const;
void addStructBuffArguments(const TSourceLoc& loc, TIntermAggregate*&);
void addStructBufferHiddenCounterParam(const TSourceLoc& loc, TParameter&, TIntermAggregate*&);
// Return true if this type is a reference. This is not currently a type method in case that's
// a language specific answer.
bool isReference(const TType& type) const { return isStructBufferType(type); }
// Return true if this a buffer type that has an associated counter buffer.
bool hasStructBuffCounter(const TType&) const;
// Finalization step: remove unused buffer blocks from linkage (we don't know until the
// shader is entirely compiled)
void removeUnusedStructBufferCounters();
static bool isClipOrCullDistance(TBuiltInVariable);
static bool isClipOrCullDistance(const TQualifier& qual) { return isClipOrCullDistance(qual.builtIn); }
static bool isClipOrCullDistance(const TType& type) { return isClipOrCullDistance(type.getQualifier()); }
// Find the patch constant function (issues error, returns nullptr if not found)
const TFunction* findPatchConstantFunction(const TSourceLoc& loc);
// Pass through to base class after remembering built-in mappings.
using TParseContextBase::trackLinkage;
void trackLinkage(TSymbol& variable) override;
void finish() override; // post-processing
// Linkage symbol helpers
TIntermSymbol* findTessLinkageSymbol(TBuiltInVariable biType) const;
// Current state of parsing
int annotationNestingLevel; // 0 if outside all annotations
HlslParseContext(HlslParseContext&);
HlslParseContext& operator=(HlslParseContext&);
static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2)); // see computeSamplerTypeIndex()
TQualifier globalBufferDefaults;
TQualifier globalUniformDefaults;
TQualifier globalInputDefaults;
TQualifier globalOutputDefaults;
TString currentCaller; // name of last function body entered (not valid when at global scope)
TIdSetType inductiveLoopIds;
TVector<TIntermTyped*> needsIndexLimitationChecking;
//
// Geometry shader input arrays:
// - array sizing is based on input primitive and/or explicit size
//
// Tessellation control output arrays:
// - array sizing is based on output layout(vertices=...) and/or explicit size
//
// Both:
// - array sizing is retroactive
// - built-in block redeclarations interact with this
//
// Design:
// - use a per-context "resize-list", a list of symbols whose array sizes
// can be fixed
//
// - the resize-list starts empty at beginning of user-shader compilation, it does
// not have built-ins in it
//
// - on built-in array use: copyUp() symbol and add it to the resize-list
//
// - on user array declaration: add it to the resize-list
//
// - on block redeclaration: copyUp() symbol and add it to the resize-list
// * note, that appropriately gives an error if redeclaring a block that
// was already used and hence already copied-up
//
// - on seeing a layout declaration that sizes the array, fix everything in the
// resize-list, giving errors for mismatch
//
// - on seeing an array size declaration, give errors on mismatch between it and previous
// array-sizing declarations
//
TVector<TSymbol*> ioArraySymbolResizeList;
TMap<long long, TFlattenData> flattenMap;
// IO-type map. Maps a pure symbol-table form of a structure-member list into
// each of the (up to) three kinds of IO, as each as different allowed decorations,
// but HLSL allows mixing all in the same structure.
struct tIoKinds {
TTypeList* input;
TTypeList* output;
TTypeList* uniform;
};
TMap<const TTypeList*, tIoKinds> ioTypeMap;
// Structure splitting data:
TMap<long long, TVariable*> splitNonIoVars; // variables with the built-in interstage IO removed, indexed by unique ID.
// Structuredbuffer shared types. Typically there are only a few.
TVector<TType*> structBufferTypes;
// This tracks texture sample user structure return types. Only a limited number are supported, as
// may fit in TSampler::structReturnIndex.
TVector<TTypeList*> textureReturnStruct;
TMap<TString, bool> structBufferCounter; // true if counter buffer is in use
// The built-in interstage IO map considers e.g, EvqPosition on input and output separately, so that we
// can build the linkage correctly if position appears on both sides. Otherwise, multiple positions
// are considered identical.
struct tInterstageIoData {
tInterstageIoData(TBuiltInVariable bi, TStorageQualifier q) :
builtIn(bi), storage(q) { }
TBuiltInVariable builtIn;
TStorageQualifier storage;
// ordering for maps
bool operator<(const tInterstageIoData d) const {
return (builtIn != d.builtIn) ? (builtIn < d.builtIn) : (storage < d.storage);
}
};
TMap<tInterstageIoData, TVariable*> splitBuiltIns; // split built-ins, indexed by built-in type.
TVariable* inputPatch; // input patch is special for PCF: it's the only non-builtin PCF input,
// and is handled as a pseudo-builtin.
unsigned int nextInLocation;
unsigned int nextOutLocation;
TFunction* entryPointFunction;
TIntermNode* entryPointFunctionBody;
TString patchConstantFunctionName; // hull shader patch constant function name, from function level attribute.
TMap<TBuiltInVariable, TSymbol*> builtInTessLinkageSymbols; // used for tessellation, finding declared built-ins
TVector<TString> currentTypePrefix; // current scoping prefix for nested structures
TVector<TVariable*> implicitThisStack; // currently active 'this' variables for nested structures
TVariable* gsStreamOutput; // geometry shader stream outputs, for emit (Append method)
TVariable* clipDistanceOutput; // synthesized clip distance out variable (shader might have >1)
TVariable* cullDistanceOutput; // synthesized cull distance out variable (shader might have >1)
TVariable* clipDistanceInput; // synthesized clip distance in variable (shader might have >1)
TVariable* cullDistanceInput; // synthesized cull distance in variable (shader might have >1)
static const int maxClipCullRegs = 2;
std::array<int, maxClipCullRegs> clipSemanticNSizeIn; // vector, indexed by clip semantic ID
std::array<int, maxClipCullRegs> cullSemanticNSizeIn; // vector, indexed by cull semantic ID
std::array<int, maxClipCullRegs> clipSemanticNSizeOut; // vector, indexed by clip semantic ID
std::array<int, maxClipCullRegs> cullSemanticNSizeOut; // vector, indexed by cull semantic ID
// This tracks the first (mip level) argument to the .mips[][] operator. Since this can be nested as
// in tx.mips[tx.mips[0][1].x][2], we need a stack. We also track the TSourceLoc for error reporting
// purposes.
struct tMipsOperatorData {
tMipsOperatorData(TSourceLoc l, TIntermTyped* m) : loc(l), mipLevel(m) { }
TSourceLoc loc;
TIntermTyped* mipLevel;
};
TVector<tMipsOperatorData> mipsOperatorMipArg;
// The geometry output stream is not copied out from the entry point as a typical output variable
// is. It's written via EmitVertex (hlsl=Append), which may happen in arbitrary control flow.
// For this we need the real output symbol. Since it may not be known at the time and Append()
// method is parsed, the sequence will be patched during finalization.
struct tGsAppendData {
TIntermAggregate* node;
TSourceLoc loc;
};
TVector<tGsAppendData> gsAppends;
// A texture object may be used with shadow and non-shadow samplers, but both may not be
// alive post-DCE in the same shader. We do not know at compilation time which are alive: that's
// only known post-DCE. If a texture is used both ways, we create two textures, and
// leave the elimiation of one to the optimizer. This maps the shader variant to
// the shadow variant.
//
// This can be removed if and when the texture shadow code in
// HlslParseContext::handleSamplerTextureCombine is removed.
struct tShadowTextureSymbols {
tShadowTextureSymbols() { symId.fill(-1); }
void set(bool shadow, long long id) { symId[int(shadow)] = id; }
long long get(bool shadow) const { return symId[int(shadow)]; }
// True if this texture has been seen with both shadow and non-shadow modes
bool overloaded() const { return symId[0] != -1 && symId[1] != -1; }
bool isShadowId(long long id) const { return symId[1] == id; }
private:
std::array<long long, 2> symId;
};
TMap<long long, tShadowTextureSymbols*> textureShadowVariant;
bool parsingEntrypointParameters;
};
// This is the prefix we use for built-in methods to avoid namespace collisions with
// global scope user functions.
// TODO: this would be better as a nonparseable character, but that would
// require changing the scanner.
#define BUILTIN_PREFIX "__BI_"
} // end namespace glslang
#endif // HLSL_PARSE_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslParseables.h | //
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _HLSLPARSEABLES_INCLUDED_
#define _HLSLPARSEABLES_INCLUDED_
#include "../MachineIndependent/Initialize.h"
namespace glslang {
//
// This is an HLSL specific derivation of TBuiltInParseables. See comment
// above TBuiltInParseables for details.
//
class TBuiltInParseablesHlsl : public TBuiltInParseables {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TBuiltInParseablesHlsl();
void initialize(int version, EProfile, const SpvVersion& spvVersion);
void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage);
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable);
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources);
private:
void createMatTimesMat();
};
} // end namespace glslang
#endif // _HLSLPARSEABLES_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslParseHelper.cpp | //
// Copyright (C) 2017-2018 Google, Inc.
// Copyright (C) 2017 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "hlslParseHelper.h"
#include "hlslScanContext.h"
#include "hlslGrammar.h"
#include "hlslAttributes.h"
#include "../Include/Common.h"
#include "../MachineIndependent/Scan.h"
#include "../MachineIndependent/preprocessor/PpContext.h"
#include "../OSDependent/osinclude.h"
#include <algorithm>
#include <functional>
#include <cctype>
#include <array>
#include <set>
namespace glslang {
HlslParseContext::HlslParseContext(TSymbolTable& symbolTable, TIntermediate& interm, bool parsingBuiltins,
int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language,
TInfoSink& infoSink,
const TString sourceEntryPointName,
bool forwardCompatible, EShMessages messages) :
TParseContextBase(symbolTable, interm, parsingBuiltins, version, profile, spvVersion, language, infoSink,
forwardCompatible, messages, &sourceEntryPointName),
annotationNestingLevel(0),
inputPatch(nullptr),
nextInLocation(0), nextOutLocation(0),
entryPointFunction(nullptr),
entryPointFunctionBody(nullptr),
gsStreamOutput(nullptr),
clipDistanceOutput(nullptr),
cullDistanceOutput(nullptr),
clipDistanceInput(nullptr),
cullDistanceInput(nullptr),
parsingEntrypointParameters(false)
{
globalUniformDefaults.clear();
globalUniformDefaults.layoutMatrix = ElmRowMajor;
globalUniformDefaults.layoutPacking = ElpStd140;
globalBufferDefaults.clear();
globalBufferDefaults.layoutMatrix = ElmRowMajor;
globalBufferDefaults.layoutPacking = ElpStd430;
globalInputDefaults.clear();
globalOutputDefaults.clear();
clipSemanticNSizeIn.fill(0);
cullSemanticNSizeIn.fill(0);
clipSemanticNSizeOut.fill(0);
cullSemanticNSizeOut.fill(0);
// "Shaders in the transform
// feedback capturing mode have an initial global default of
// layout(xfb_buffer = 0) out;"
if (language == EShLangVertex ||
language == EShLangTessControl ||
language == EShLangTessEvaluation ||
language == EShLangGeometry)
globalOutputDefaults.layoutXfbBuffer = 0;
if (language == EShLangGeometry)
globalOutputDefaults.layoutStream = 0;
}
HlslParseContext::~HlslParseContext()
{
}
void HlslParseContext::initializeExtensionBehavior()
{
TParseContextBase::initializeExtensionBehavior();
// HLSL allows #line by default.
extensionBehavior[E_GL_GOOGLE_cpp_style_line_directive] = EBhEnable;
}
void HlslParseContext::setLimits(const TBuiltInResource& r)
{
resources = r;
intermediate.setLimits(resources);
}
//
// Parse an array of strings using the parser in HlslRules.
//
// Returns true for successful acceptance of the shader, false if any errors.
//
bool HlslParseContext::parseShaderStrings(TPpContext& ppContext, TInputScanner& input, bool versionWillBeError)
{
currentScanner = &input;
ppContext.setInput(input, versionWillBeError);
HlslScanContext scanContext(*this, ppContext);
HlslGrammar grammar(scanContext, *this);
if (!grammar.parse()) {
// Print a message formated such that if you click on the message it will take you right to
// the line through most UIs.
const glslang::TSourceLoc& sourceLoc = input.getSourceLoc();
infoSink.info << sourceLoc.getFilenameStr() << "(" << sourceLoc.line << "): error at column " << sourceLoc.column
<< ", HLSL parsing failed.\n";
++numErrors;
return false;
}
finish();
return numErrors == 0;
}
//
// Return true if this l-value node should be converted in some manner.
// For instance: turning a load aggregate into a store in an l-value.
//
bool HlslParseContext::shouldConvertLValue(const TIntermNode* node) const
{
if (node == nullptr || node->getAsTyped() == nullptr)
return false;
const TIntermAggregate* lhsAsAggregate = node->getAsAggregate();
const TIntermBinary* lhsAsBinary = node->getAsBinaryNode();
// If it's a swizzled/indexed aggregate, look at the left node instead.
if (lhsAsBinary != nullptr &&
(lhsAsBinary->getOp() == EOpVectorSwizzle || lhsAsBinary->getOp() == EOpIndexDirect))
lhsAsAggregate = lhsAsBinary->getLeft()->getAsAggregate();
if (lhsAsAggregate != nullptr && lhsAsAggregate->getOp() == EOpImageLoad)
return true;
return false;
}
void HlslParseContext::growGlobalUniformBlock(const TSourceLoc& loc, TType& memberType, const TString& memberName,
TTypeList* newTypeList)
{
newTypeList = nullptr;
correctUniform(memberType.getQualifier());
if (memberType.isStruct()) {
auto it = ioTypeMap.find(memberType.getStruct());
if (it != ioTypeMap.end() && it->second.uniform)
newTypeList = it->second.uniform;
}
TParseContextBase::growGlobalUniformBlock(loc, memberType, memberName, newTypeList);
}
//
// Return a TLayoutFormat corresponding to the given texture type.
//
TLayoutFormat HlslParseContext::getLayoutFromTxType(const TSourceLoc& loc, const TType& txType)
{
if (txType.isStruct()) {
// TODO: implement.
error(loc, "unimplemented: structure type in image or buffer", "", "");
return ElfNone;
}
const int components = txType.getVectorSize();
const TBasicType txBasicType = txType.getBasicType();
const auto selectFormat = [this,&components](TLayoutFormat v1, TLayoutFormat v2, TLayoutFormat v4) -> TLayoutFormat {
if (intermediate.getNoStorageFormat())
return ElfNone;
return components == 1 ? v1 :
components == 2 ? v2 : v4;
};
switch (txBasicType) {
case EbtFloat: return selectFormat(ElfR32f, ElfRg32f, ElfRgba32f);
case EbtInt: return selectFormat(ElfR32i, ElfRg32i, ElfRgba32i);
case EbtUint: return selectFormat(ElfR32ui, ElfRg32ui, ElfRgba32ui);
default:
error(loc, "unknown basic type in image format", "", "");
return ElfNone;
}
}
//
// Both test and if necessary, spit out an error, to see if the node is really
// an l-value that can be operated on this way.
//
// Returns true if there was an error.
//
bool HlslParseContext::lValueErrorCheck(const TSourceLoc& loc, const char* op, TIntermTyped* node)
{
if (shouldConvertLValue(node)) {
// if we're writing to a texture, it must be an RW form.
TIntermAggregate* lhsAsAggregate = node->getAsAggregate();
TIntermTyped* object = lhsAsAggregate->getSequence()[0]->getAsTyped();
if (!object->getType().getSampler().isImage()) {
error(loc, "operator[] on a non-RW texture must be an r-value", "", "");
return true;
}
}
// We tolerate samplers as l-values, even though they are nominally
// illegal, because we expect a later optimization to eliminate them.
if (node->getType().getBasicType() == EbtSampler) {
intermediate.setNeedsLegalization();
return false;
}
// Let the base class check errors
return TParseContextBase::lValueErrorCheck(loc, op, node);
}
//
// This function handles l-value conversions and verifications. It uses, but is not synonymous
// with lValueErrorCheck. That function accepts an l-value directly, while this one must be
// given the surrounding tree - e.g, with an assignment, so we can convert the assign into a
// series of other image operations.
//
// Most things are passed through unmodified, except for error checking.
//
TIntermTyped* HlslParseContext::handleLvalue(const TSourceLoc& loc, const char* op, TIntermTyped*& node)
{
if (node == nullptr)
return nullptr;
TIntermBinary* nodeAsBinary = node->getAsBinaryNode();
TIntermUnary* nodeAsUnary = node->getAsUnaryNode();
TIntermAggregate* sequence = nullptr;
TIntermTyped* lhs = nodeAsUnary ? nodeAsUnary->getOperand() :
nodeAsBinary ? nodeAsBinary->getLeft() :
nullptr;
// Early bail out if there is no conversion to apply
if (!shouldConvertLValue(lhs)) {
if (lhs != nullptr)
if (lValueErrorCheck(loc, op, lhs))
return nullptr;
return node;
}
// *** If we get here, we're going to apply some conversion to an l-value.
// Helper to create a load.
const auto makeLoad = [&](TIntermSymbol* rhsTmp, TIntermTyped* object, TIntermTyped* coord, const TType& derefType) {
TIntermAggregate* loadOp = new TIntermAggregate(EOpImageLoad);
loadOp->setLoc(loc);
loadOp->getSequence().push_back(object);
loadOp->getSequence().push_back(intermediate.addSymbol(*coord->getAsSymbolNode()));
loadOp->setType(derefType);
sequence = intermediate.growAggregate(sequence,
intermediate.addAssign(EOpAssign, rhsTmp, loadOp, loc),
loc);
};
// Helper to create a store.
const auto makeStore = [&](TIntermTyped* object, TIntermTyped* coord, TIntermSymbol* rhsTmp) {
TIntermAggregate* storeOp = new TIntermAggregate(EOpImageStore);
storeOp->getSequence().push_back(object);
storeOp->getSequence().push_back(coord);
storeOp->getSequence().push_back(intermediate.addSymbol(*rhsTmp));
storeOp->setLoc(loc);
storeOp->setType(TType(EbtVoid));
sequence = intermediate.growAggregate(sequence, storeOp);
};
// Helper to create an assign.
const auto makeBinary = [&](TOperator op, TIntermTyped* lhs, TIntermTyped* rhs) {
sequence = intermediate.growAggregate(sequence,
intermediate.addBinaryNode(op, lhs, rhs, loc, lhs->getType()),
loc);
};
// Helper to complete sequence by adding trailing variable, so we evaluate to the right value.
const auto finishSequence = [&](TIntermSymbol* rhsTmp, const TType& derefType) -> TIntermAggregate* {
// Add a trailing use of the temp, so the sequence returns the proper value.
sequence = intermediate.growAggregate(sequence, intermediate.addSymbol(*rhsTmp));
sequence->setOperator(EOpSequence);
sequence->setLoc(loc);
sequence->setType(derefType);
return sequence;
};
// Helper to add unary op
const auto makeUnary = [&](TOperator op, TIntermSymbol* rhsTmp) {
sequence = intermediate.growAggregate(sequence,
intermediate.addUnaryNode(op, intermediate.addSymbol(*rhsTmp), loc,
rhsTmp->getType()),
loc);
};
// Return true if swizzle or index writes all components of the given variable.
const auto writesAllComponents = [&](TIntermSymbol* var, TIntermBinary* swizzle) -> bool {
if (swizzle == nullptr) // not a swizzle or index
return true;
// Track which components are being set.
std::array<bool, 4> compIsSet;
compIsSet.fill(false);
const TIntermConstantUnion* asConst = swizzle->getRight()->getAsConstantUnion();
const TIntermAggregate* asAggregate = swizzle->getRight()->getAsAggregate();
// This could be either a direct index, or a swizzle.
if (asConst) {
compIsSet[asConst->getConstArray()[0].getIConst()] = true;
} else if (asAggregate) {
const TIntermSequence& seq = asAggregate->getSequence();
for (int comp=0; comp<int(seq.size()); ++comp)
compIsSet[seq[comp]->getAsConstantUnion()->getConstArray()[0].getIConst()] = true;
} else {
assert(0);
}
// Return true if all components are being set by the index or swizzle
return std::all_of(compIsSet.begin(), compIsSet.begin() + var->getType().getVectorSize(),
[](bool isSet) { return isSet; } );
};
// Create swizzle matching input swizzle
const auto addSwizzle = [&](TIntermSymbol* var, TIntermBinary* swizzle) -> TIntermTyped* {
if (swizzle)
return intermediate.addBinaryNode(swizzle->getOp(), var, swizzle->getRight(), loc, swizzle->getType());
else
return var;
};
TIntermBinary* lhsAsBinary = lhs->getAsBinaryNode();
TIntermAggregate* lhsAsAggregate = lhs->getAsAggregate();
bool lhsIsSwizzle = false;
// If it's a swizzled L-value, remember the swizzle, and use the LHS.
if (lhsAsBinary != nullptr && (lhsAsBinary->getOp() == EOpVectorSwizzle || lhsAsBinary->getOp() == EOpIndexDirect)) {
lhsAsAggregate = lhsAsBinary->getLeft()->getAsAggregate();
lhsIsSwizzle = true;
}
TIntermTyped* object = lhsAsAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* coord = lhsAsAggregate->getSequence()[1]->getAsTyped();
const TSampler& texSampler = object->getType().getSampler();
TType objDerefType;
getTextureReturnType(texSampler, objDerefType);
if (nodeAsBinary) {
TIntermTyped* rhs = nodeAsBinary->getRight();
const TOperator assignOp = nodeAsBinary->getOp();
bool isModifyOp = false;
switch (assignOp) {
case EOpAddAssign:
case EOpSubAssign:
case EOpMulAssign:
case EOpVectorTimesMatrixAssign:
case EOpVectorTimesScalarAssign:
case EOpMatrixTimesScalarAssign:
case EOpMatrixTimesMatrixAssign:
case EOpDivAssign:
case EOpModAssign:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
case EOpLeftShiftAssign:
case EOpRightShiftAssign:
isModifyOp = true;
[[fallthrough]];
case EOpAssign:
{
// Since this is an lvalue, we'll convert an image load to a sequence like this
// (to still provide the value):
// OpSequence
// OpImageStore(object, lhs, rhs)
// rhs
// But if it's not a simple symbol RHS (say, a fn call), we don't want to duplicate the RHS,
// so we'll convert instead to this:
// OpSequence
// rhsTmp = rhs
// OpImageStore(object, coord, rhsTmp)
// rhsTmp
// If this is a read-modify-write op, like +=, we issue:
// OpSequence
// coordtmp = load's param1
// rhsTmp = OpImageLoad(object, coordTmp)
// rhsTmp op= rhs
// OpImageStore(object, coordTmp, rhsTmp)
// rhsTmp
//
// If the lvalue is swizzled, we apply that when writing the temp variable, like so:
// ...
// rhsTmp.some_swizzle = ...
// For partial writes, an error is generated.
TIntermSymbol* rhsTmp = rhs->getAsSymbolNode();
TIntermTyped* coordTmp = coord;
if (rhsTmp == nullptr || isModifyOp || lhsIsSwizzle) {
rhsTmp = makeInternalVariableNode(loc, "storeTemp", objDerefType);
// Partial updates not yet supported
if (!writesAllComponents(rhsTmp, lhsAsBinary)) {
error(loc, "unimplemented: partial image updates", "", "");
}
// Assign storeTemp = rhs
if (isModifyOp) {
// We have to make a temp var for the coordinate, to avoid evaluating it twice.
coordTmp = makeInternalVariableNode(loc, "coordTemp", coord->getType());
makeBinary(EOpAssign, coordTmp, coord); // coordtmp = load[param1]
makeLoad(rhsTmp, object, coordTmp, objDerefType); // rhsTmp = OpImageLoad(object, coordTmp)
}
// rhsTmp op= rhs.
makeBinary(assignOp, addSwizzle(intermediate.addSymbol(*rhsTmp), lhsAsBinary), rhs);
}
makeStore(object, coordTmp, rhsTmp); // add a store
return finishSequence(rhsTmp, objDerefType); // return rhsTmp from sequence
}
default:
break;
}
}
if (nodeAsUnary) {
const TOperator assignOp = nodeAsUnary->getOp();
switch (assignOp) {
case EOpPreIncrement:
case EOpPreDecrement:
{
// We turn this into:
// OpSequence
// coordtmp = load's param1
// rhsTmp = OpImageLoad(object, coordTmp)
// rhsTmp op
// OpImageStore(object, coordTmp, rhsTmp)
// rhsTmp
TIntermSymbol* rhsTmp = makeInternalVariableNode(loc, "storeTemp", objDerefType);
TIntermTyped* coordTmp = makeInternalVariableNode(loc, "coordTemp", coord->getType());
makeBinary(EOpAssign, coordTmp, coord); // coordtmp = load[param1]
makeLoad(rhsTmp, object, coordTmp, objDerefType); // rhsTmp = OpImageLoad(object, coordTmp)
makeUnary(assignOp, rhsTmp); // op rhsTmp
makeStore(object, coordTmp, rhsTmp); // OpImageStore(object, coordTmp, rhsTmp)
return finishSequence(rhsTmp, objDerefType); // return rhsTmp from sequence
}
case EOpPostIncrement:
case EOpPostDecrement:
{
// We turn this into:
// OpSequence
// coordtmp = load's param1
// rhsTmp1 = OpImageLoad(object, coordTmp)
// rhsTmp2 = rhsTmp1
// rhsTmp2 op
// OpImageStore(object, coordTmp, rhsTmp2)
// rhsTmp1 (pre-op value)
TIntermSymbol* rhsTmp1 = makeInternalVariableNode(loc, "storeTempPre", objDerefType);
TIntermSymbol* rhsTmp2 = makeInternalVariableNode(loc, "storeTempPost", objDerefType);
TIntermTyped* coordTmp = makeInternalVariableNode(loc, "coordTemp", coord->getType());
makeBinary(EOpAssign, coordTmp, coord); // coordtmp = load[param1]
makeLoad(rhsTmp1, object, coordTmp, objDerefType); // rhsTmp1 = OpImageLoad(object, coordTmp)
makeBinary(EOpAssign, rhsTmp2, rhsTmp1); // rhsTmp2 = rhsTmp1
makeUnary(assignOp, rhsTmp2); // rhsTmp op
makeStore(object, coordTmp, rhsTmp2); // OpImageStore(object, coordTmp, rhsTmp2)
return finishSequence(rhsTmp1, objDerefType); // return rhsTmp from sequence
}
default:
break;
}
}
if (lhs)
if (lValueErrorCheck(loc, op, lhs))
return nullptr;
return node;
}
void HlslParseContext::handlePragma(const TSourceLoc& loc, const TVector<TString>& tokens)
{
if (pragmaCallback)
pragmaCallback(loc.line, tokens);
if (tokens.size() == 0)
return;
// These pragmas are case insensitive in HLSL, so we'll compare in lower case.
TVector<TString> lowerTokens = tokens;
for (auto it = lowerTokens.begin(); it != lowerTokens.end(); ++it)
std::transform(it->begin(), it->end(), it->begin(), ::tolower);
// Handle pack_matrix
if (tokens.size() == 4 && lowerTokens[0] == "pack_matrix" && tokens[1] == "(" && tokens[3] == ")") {
// Note that HLSL semantic order is Mrc, not Mcr like SPIR-V, so we reverse the sense.
// Row major becomes column major and vice versa.
if (lowerTokens[2] == "row_major") {
globalUniformDefaults.layoutMatrix = globalBufferDefaults.layoutMatrix = ElmColumnMajor;
} else if (lowerTokens[2] == "column_major") {
globalUniformDefaults.layoutMatrix = globalBufferDefaults.layoutMatrix = ElmRowMajor;
} else {
// unknown majorness strings are treated as (HLSL column major)==(SPIR-V row major)
warn(loc, "unknown pack_matrix pragma value", tokens[2].c_str(), "");
globalUniformDefaults.layoutMatrix = globalBufferDefaults.layoutMatrix = ElmRowMajor;
}
return;
}
// Handle once
if (lowerTokens[0] == "once") {
warn(loc, "not implemented", "#pragma once", "");
return;
}
}
//
// Look at a '.' matrix selector string and change it into components
// for a matrix. There are two types:
//
// _21 second row, first column (one based)
// _m21 third row, second column (zero based)
//
// Returns true if there is no error.
//
bool HlslParseContext::parseMatrixSwizzleSelector(const TSourceLoc& loc, const TString& fields, int cols, int rows,
TSwizzleSelectors<TMatrixSelector>& components)
{
int startPos[MaxSwizzleSelectors];
int numComps = 0;
TString compString = fields;
// Find where each component starts,
// recording the first character position after the '_'.
for (size_t c = 0; c < compString.size(); ++c) {
if (compString[c] == '_') {
if (numComps >= MaxSwizzleSelectors) {
error(loc, "matrix component swizzle has too many components", compString.c_str(), "");
return false;
}
if (c > compString.size() - 3 ||
((compString[c+1] == 'm' || compString[c+1] == 'M') && c > compString.size() - 4)) {
error(loc, "matrix component swizzle missing", compString.c_str(), "");
return false;
}
startPos[numComps++] = (int)c + 1;
}
}
// Process each component
for (int i = 0; i < numComps; ++i) {
int pos = startPos[i];
int bias = -1;
if (compString[pos] == 'm' || compString[pos] == 'M') {
bias = 0;
++pos;
}
TMatrixSelector comp;
comp.coord1 = compString[pos+0] - '0' + bias;
comp.coord2 = compString[pos+1] - '0' + bias;
if (comp.coord1 < 0 || comp.coord1 >= cols) {
error(loc, "matrix row component out of range", compString.c_str(), "");
return false;
}
if (comp.coord2 < 0 || comp.coord2 >= rows) {
error(loc, "matrix column component out of range", compString.c_str(), "");
return false;
}
components.push_back(comp);
}
return true;
}
// If the 'comps' express a column of a matrix,
// return the column. Column means the first coords all match.
//
// Otherwise, return -1.
//
int HlslParseContext::getMatrixComponentsColumn(int rows, const TSwizzleSelectors<TMatrixSelector>& selector)
{
int col = -1;
// right number of comps?
if (selector.size() != rows)
return -1;
// all comps in the same column?
// rows in order?
col = selector[0].coord1;
for (int i = 0; i < rows; ++i) {
if (col != selector[i].coord1)
return -1;
if (i != selector[i].coord2)
return -1;
}
return col;
}
//
// Handle seeing a variable identifier in the grammar.
//
TIntermTyped* HlslParseContext::handleVariable(const TSourceLoc& loc, const TString* string)
{
int thisDepth;
TSymbol* symbol = symbolTable.find(*string, thisDepth);
if (symbol && symbol->getAsVariable() && symbol->getAsVariable()->isUserType()) {
error(loc, "expected symbol, not user-defined type", string->c_str(), "");
return nullptr;
}
const TVariable* variable = nullptr;
const TAnonMember* anon = symbol ? symbol->getAsAnonMember() : nullptr;
TIntermTyped* node = nullptr;
if (anon) {
// It was a member of an anonymous container, which could be a 'this' structure.
// Create a subtree for its dereference.
if (thisDepth > 0) {
variable = getImplicitThis(thisDepth);
if (variable == nullptr)
error(loc, "cannot access member variables (static member function?)", "this", "");
}
if (variable == nullptr)
variable = anon->getAnonContainer().getAsVariable();
TIntermTyped* container = intermediate.addSymbol(*variable, loc);
TIntermTyped* constNode = intermediate.addConstantUnion(anon->getMemberNumber(), loc);
node = intermediate.addIndex(EOpIndexDirectStruct, container, constNode, loc);
node->setType(*(*variable->getType().getStruct())[anon->getMemberNumber()].type);
if (node->getType().hiddenMember())
error(loc, "member of nameless block was not redeclared", string->c_str(), "");
} else {
// Not a member of an anonymous container.
// The symbol table search was done in the lexical phase.
// See if it was a variable.
variable = symbol ? symbol->getAsVariable() : nullptr;
if (variable) {
if ((variable->getType().getBasicType() == EbtBlock ||
variable->getType().getBasicType() == EbtStruct) && variable->getType().getStruct() == nullptr) {
error(loc, "cannot be used (maybe an instance name is needed)", string->c_str(), "");
variable = nullptr;
}
} else {
if (symbol)
error(loc, "variable name expected", string->c_str(), "");
}
// Recovery, if it wasn't found or was not a variable.
if (variable == nullptr) {
error(loc, "unknown variable", string->c_str(), "");
variable = new TVariable(string, TType(EbtVoid));
}
if (variable->getType().getQualifier().isFrontEndConstant())
node = intermediate.addConstantUnion(variable->getConstArray(), variable->getType(), loc);
else
node = intermediate.addSymbol(*variable, loc);
}
if (variable->getType().getQualifier().isIo())
intermediate.addIoAccessed(*string);
return node;
}
//
// Handle operator[] on any objects it applies to. Currently:
// Textures
// Buffers
//
TIntermTyped* HlslParseContext::handleBracketOperator(const TSourceLoc& loc, TIntermTyped* base, TIntermTyped* index)
{
// handle r-value operator[] on textures and images. l-values will be processed later.
if (base->getType().getBasicType() == EbtSampler && !base->isArray()) {
const TSampler& sampler = base->getType().getSampler();
if (sampler.isImage() || sampler.isTexture()) {
if (! mipsOperatorMipArg.empty() && mipsOperatorMipArg.back().mipLevel == nullptr) {
// The first operator[] to a .mips[] sequence is the mip level. We'll remember it.
mipsOperatorMipArg.back().mipLevel = index;
return base; // next [] index is to the same base.
} else {
TIntermAggregate* load = new TIntermAggregate(sampler.isImage() ? EOpImageLoad : EOpTextureFetch);
TType sampReturnType;
getTextureReturnType(sampler, sampReturnType);
load->setType(sampReturnType);
load->setLoc(loc);
load->getSequence().push_back(base);
load->getSequence().push_back(index);
// Textures need a MIP. If we saw one go by, use it. Otherwise, use zero.
if (sampler.isTexture()) {
if (! mipsOperatorMipArg.empty()) {
load->getSequence().push_back(mipsOperatorMipArg.back().mipLevel);
mipsOperatorMipArg.pop_back();
} else {
load->getSequence().push_back(intermediate.addConstantUnion(0, loc, true));
}
}
return load;
}
}
}
// Handle operator[] on structured buffers: this indexes into the array element of the buffer.
// indexStructBufferContent returns nullptr if it isn't a structuredbuffer (SSBO).
TIntermTyped* sbArray = indexStructBufferContent(loc, base);
if (sbArray != nullptr) {
// Now we'll apply the [] index to that array
const TOperator idxOp = (index->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
TIntermTyped* element = intermediate.addIndex(idxOp, sbArray, index, loc);
const TType derefType(sbArray->getType(), 0);
element->setType(derefType);
return element;
}
return nullptr;
}
//
// Cast index value to a uint if it isn't already (for operator[], load indexes, etc)
TIntermTyped* HlslParseContext::makeIntegerIndex(TIntermTyped* index)
{
const TBasicType indexBasicType = index->getType().getBasicType();
const int vecSize = index->getType().getVectorSize();
// We can use int types directly as the index
if (indexBasicType == EbtInt || indexBasicType == EbtUint ||
indexBasicType == EbtInt64 || indexBasicType == EbtUint64)
return index;
// Cast index to unsigned integer if it isn't one.
return intermediate.addConversion(EOpConstructUint, TType(EbtUint, EvqTemporary, vecSize), index);
}
//
// Handle seeing a base[index] dereference in the grammar.
//
TIntermTyped* HlslParseContext::handleBracketDereference(const TSourceLoc& loc, TIntermTyped* base, TIntermTyped* index)
{
index = makeIntegerIndex(index);
if (index == nullptr) {
error(loc, " unknown index type ", "", "");
return nullptr;
}
TIntermTyped* result = handleBracketOperator(loc, base, index);
if (result != nullptr)
return result; // it was handled as an operator[]
bool flattened = false;
int indexValue = 0;
if (index->getQualifier().isFrontEndConstant())
indexValue = index->getAsConstantUnion()->getConstArray()[0].getIConst();
variableCheck(base);
if (! base->isArray() && ! base->isMatrix() && ! base->isVector()) {
if (base->getAsSymbolNode())
error(loc, " left of '[' is not of type array, matrix, or vector ",
base->getAsSymbolNode()->getName().c_str(), "");
else
error(loc, " left of '[' is not of type array, matrix, or vector ", "expression", "");
} else if (base->getType().getQualifier().isFrontEndConstant() &&
index->getQualifier().isFrontEndConstant()) {
// both base and index are front-end constants
checkIndex(loc, base->getType(), indexValue);
return intermediate.foldDereference(base, indexValue, loc);
} else {
// at least one of base and index is variable...
if (index->getQualifier().isFrontEndConstant())
checkIndex(loc, base->getType(), indexValue);
if (base->getType().isScalarOrVec1())
result = base;
else if (base->getAsSymbolNode() && wasFlattened(base)) {
if (index->getQualifier().storage != EvqConst)
error(loc, "Invalid variable index to flattened array", base->getAsSymbolNode()->getName().c_str(), "");
result = flattenAccess(base, indexValue);
flattened = (result != base);
} else {
if (index->getQualifier().isFrontEndConstant()) {
if (base->getType().isUnsizedArray())
base->getWritableType().updateImplicitArraySize(indexValue + 1);
else
checkIndex(loc, base->getType(), indexValue);
result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
} else
result = intermediate.addIndex(EOpIndexIndirect, base, index, loc);
}
}
if (result == nullptr) {
// Insert dummy error-recovery result
result = intermediate.addConstantUnion(0.0, EbtFloat, loc);
} else {
// If the array reference was flattened, it has the correct type. E.g, if it was
// a uniform array, it was flattened INTO a set of scalar uniforms, not scalar temps.
// In that case, we preserve the qualifiers.
if (!flattened) {
// Insert valid dereferenced result
TType newType(base->getType(), 0); // dereferenced type
if (base->getType().getQualifier().storage == EvqConst && index->getQualifier().storage == EvqConst)
newType.getQualifier().storage = EvqConst;
else
newType.getQualifier().storage = EvqTemporary;
result->setType(newType);
}
}
return result;
}
// Handle seeing a binary node with a math operation.
TIntermTyped* HlslParseContext::handleBinaryMath(const TSourceLoc& loc, const char* str, TOperator op,
TIntermTyped* left, TIntermTyped* right)
{
TIntermTyped* result = intermediate.addBinaryMath(op, left, right, loc);
if (result == nullptr)
binaryOpError(loc, str, left->getCompleteString(), right->getCompleteString());
return result;
}
// Handle seeing a unary node with a math operation.
TIntermTyped* HlslParseContext::handleUnaryMath(const TSourceLoc& loc, const char* str, TOperator op,
TIntermTyped* childNode)
{
TIntermTyped* result = intermediate.addUnaryMath(op, childNode, loc);
if (result)
return result;
else
unaryOpError(loc, str, childNode->getCompleteString());
return childNode;
}
//
// Return true if the name is a struct buffer method
//
bool HlslParseContext::isStructBufferMethod(const TString& name) const
{
return
name == "GetDimensions" ||
name == "Load" ||
name == "Load2" ||
name == "Load3" ||
name == "Load4" ||
name == "Store" ||
name == "Store2" ||
name == "Store3" ||
name == "Store4" ||
name == "InterlockedAdd" ||
name == "InterlockedAnd" ||
name == "InterlockedCompareExchange" ||
name == "InterlockedCompareStore" ||
name == "InterlockedExchange" ||
name == "InterlockedMax" ||
name == "InterlockedMin" ||
name == "InterlockedOr" ||
name == "InterlockedXor" ||
name == "IncrementCounter" ||
name == "DecrementCounter" ||
name == "Append" ||
name == "Consume";
}
//
// Handle seeing a base.field dereference in the grammar, where 'field' is a
// swizzle or member variable.
//
TIntermTyped* HlslParseContext::handleDotDereference(const TSourceLoc& loc, TIntermTyped* base, const TString& field)
{
variableCheck(base);
if (base->isArray()) {
error(loc, "cannot apply to an array:", ".", field.c_str());
return base;
}
TIntermTyped* result = base;
if (base->getType().getBasicType() == EbtSampler) {
// Handle .mips[mipid][pos] operation on textures
const TSampler& sampler = base->getType().getSampler();
if (sampler.isTexture() && field == "mips") {
// Push a null to signify that we expect a mip level under operator[] next.
mipsOperatorMipArg.push_back(tMipsOperatorData(loc, nullptr));
// Keep 'result' pointing to 'base', since we expect an operator[] to go by next.
} else {
if (field == "mips")
error(loc, "unexpected texture type for .mips[][] operator:",
base->getType().getCompleteString().c_str(), "");
else
error(loc, "unexpected operator on texture type:", field.c_str(),
base->getType().getCompleteString().c_str());
}
} else if (base->isVector() || base->isScalar()) {
TSwizzleSelectors<TVectorSelector> selectors;
parseSwizzleSelector(loc, field, base->getVectorSize(), selectors);
if (base->isScalar()) {
if (selectors.size() == 1)
return result;
else {
TType type(base->getBasicType(), EvqTemporary, selectors.size());
return addConstructor(loc, base, type);
}
}
// Use EOpIndexDirect (below) with vec1.x so that it remains l-value (Test/hlsl.swizzle.vec1.comp)
if (base->getVectorSize() == 1 && selectors.size() > 1) {
TType scalarType(base->getBasicType(), EvqTemporary, 1);
TType vectorType(base->getBasicType(), EvqTemporary, selectors.size());
return addConstructor(loc, addConstructor(loc, base, scalarType), vectorType);
}
if (base->getType().getQualifier().isFrontEndConstant())
result = intermediate.foldSwizzle(base, selectors, loc);
else {
if (selectors.size() == 1) {
TIntermTyped* index = intermediate.addConstantUnion(selectors[0], loc);
result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
result->setType(TType(base->getBasicType(), EvqTemporary));
} else {
TIntermTyped* index = intermediate.addSwizzle(selectors, loc);
result = intermediate.addIndex(EOpVectorSwizzle, base, index, loc);
result->setType(TType(base->getBasicType(), EvqTemporary, base->getType().getQualifier().precision,
selectors.size()));
}
}
} else if (base->isMatrix()) {
TSwizzleSelectors<TMatrixSelector> selectors;
if (! parseMatrixSwizzleSelector(loc, field, base->getMatrixCols(), base->getMatrixRows(), selectors))
return result;
if (selectors.size() == 1) {
// Representable by m[c][r]
if (base->getType().getQualifier().isFrontEndConstant()) {
result = intermediate.foldDereference(base, selectors[0].coord1, loc);
result = intermediate.foldDereference(result, selectors[0].coord2, loc);
} else {
result = intermediate.addIndex(EOpIndexDirect, base,
intermediate.addConstantUnion(selectors[0].coord1, loc),
loc);
TType dereferencedCol(base->getType(), 0);
result->setType(dereferencedCol);
result = intermediate.addIndex(EOpIndexDirect, result,
intermediate.addConstantUnion(selectors[0].coord2, loc),
loc);
TType dereferenced(dereferencedCol, 0);
result->setType(dereferenced);
}
} else {
int column = getMatrixComponentsColumn(base->getMatrixRows(), selectors);
if (column >= 0) {
// Representable by m[c]
if (base->getType().getQualifier().isFrontEndConstant())
result = intermediate.foldDereference(base, column, loc);
else {
result = intermediate.addIndex(EOpIndexDirect, base, intermediate.addConstantUnion(column, loc),
loc);
TType dereferenced(base->getType(), 0);
result->setType(dereferenced);
}
} else {
// general case, not a column, not a single component
TIntermTyped* index = intermediate.addSwizzle(selectors, loc);
result = intermediate.addIndex(EOpMatrixSwizzle, base, index, loc);
result->setType(TType(base->getBasicType(), EvqTemporary, base->getType().getQualifier().precision,
selectors.size()));
}
}
} else if (base->getBasicType() == EbtStruct || base->getBasicType() == EbtBlock) {
const TTypeList* fields = base->getType().getStruct();
bool fieldFound = false;
int member;
for (member = 0; member < (int)fields->size(); ++member) {
if ((*fields)[member].type->getFieldName() == field) {
fieldFound = true;
break;
}
}
if (fieldFound) {
if (base->getAsSymbolNode() && wasFlattened(base)) {
result = flattenAccess(base, member);
} else {
if (base->getType().getQualifier().storage == EvqConst)
result = intermediate.foldDereference(base, member, loc);
else {
TIntermTyped* index = intermediate.addConstantUnion(member, loc);
result = intermediate.addIndex(EOpIndexDirectStruct, base, index, loc);
result->setType(*(*fields)[member].type);
}
}
} else
error(loc, "no such field in structure", field.c_str(), "");
} else
error(loc, "does not apply to this type:", field.c_str(), base->getType().getCompleteString().c_str());
return result;
}
//
// Return true if the field should be treated as a built-in method.
// Return false otherwise.
//
bool HlslParseContext::isBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field)
{
if (base == nullptr)
return false;
variableCheck(base);
if (base->getType().getBasicType() == EbtSampler) {
return true;
} else if (isStructBufferType(base->getType()) && isStructBufferMethod(field)) {
return true;
} else if (field == "Append" ||
field == "RestartStrip") {
// We cannot check the type here: it may be sanitized if we're not compiling a geometry shader, but
// the code is around in the shader source.
return true;
} else
return false;
}
// Independently establish a built-in that is a member of a structure.
// 'arraySizes' are what's desired for the independent built-in, whatever
// the higher-level source/expression of them was.
void HlslParseContext::splitBuiltIn(const TString& baseName, const TType& memberType, const TArraySizes* arraySizes,
const TQualifier& outerQualifier)
{
// Because of arrays of structs, we might be asked more than once,
// but the arraySizes passed in should have captured the whole thing
// the first time.
// However, clip/cull rely on multiple updates.
if (!isClipOrCullDistance(memberType))
if (splitBuiltIns.find(tInterstageIoData(memberType.getQualifier().builtIn, outerQualifier.storage)) !=
splitBuiltIns.end())
return;
TVariable* ioVar = makeInternalVariable(baseName + "." + memberType.getFieldName(), memberType);
if (arraySizes != nullptr && !memberType.isArray())
ioVar->getWritableType().copyArraySizes(*arraySizes);
splitBuiltIns[tInterstageIoData(memberType.getQualifier().builtIn, outerQualifier.storage)] = ioVar;
if (!isClipOrCullDistance(ioVar->getType()))
trackLinkage(*ioVar);
// Merge qualifier from the user structure
mergeQualifiers(ioVar->getWritableType().getQualifier(), outerQualifier);
// Fix the builtin type if needed (e.g, some types require fixed array sizes, no matter how the
// shader declared them). This is done after mergeQualifiers(), in case fixBuiltInIoType looks
// at the qualifier to determine e.g, in or out qualifications.
fixBuiltInIoType(ioVar->getWritableType());
// But, not location, we're losing that
ioVar->getWritableType().getQualifier().layoutLocation = TQualifier::layoutLocationEnd;
}
// Split a type into
// 1. a struct of non-I/O members
// 2. a collection of independent I/O variables
void HlslParseContext::split(const TVariable& variable)
{
// Create a new variable:
const TType& clonedType = *variable.getType().clone();
const TType& splitType = split(clonedType, variable.getName(), clonedType.getQualifier());
splitNonIoVars[variable.getUniqueId()] = makeInternalVariable(variable.getName(), splitType);
}
// Recursive implementation of split().
// Returns reference to the modified type.
const TType& HlslParseContext::split(const TType& type, const TString& name, const TQualifier& outerQualifier)
{
if (type.isStruct()) {
TTypeList* userStructure = type.getWritableStruct();
for (auto ioType = userStructure->begin(); ioType != userStructure->end(); ) {
if (ioType->type->isBuiltIn()) {
// move out the built-in
splitBuiltIn(name, *ioType->type, type.getArraySizes(), outerQualifier);
ioType = userStructure->erase(ioType);
} else {
split(*ioType->type, name + "." + ioType->type->getFieldName(), outerQualifier);
++ioType;
}
}
}
return type;
}
// Is this an aggregate that should be flattened?
// Can be applied to intermediate levels of type in a hierarchy.
// Some things like flattening uniform arrays are only about the top level
// of the aggregate, triggered on 'topLevel'.
bool HlslParseContext::shouldFlatten(const TType& type, TStorageQualifier qualifier, bool topLevel) const
{
switch (qualifier) {
case EvqVaryingIn:
case EvqVaryingOut:
return type.isStruct() || type.isArray();
case EvqUniform:
return (type.isArray() && intermediate.getFlattenUniformArrays() && topLevel) ||
(type.isStruct() && type.containsOpaque());
default:
return false;
};
}
// Top level variable flattening: construct data
void HlslParseContext::flatten(const TVariable& variable, bool linkage, bool arrayed)
{
const TType& type = variable.getType();
// If it's a standalone built-in, there is nothing to flatten
if (type.isBuiltIn() && !type.isStruct())
return;
auto entry = flattenMap.insert(std::make_pair(variable.getUniqueId(),
TFlattenData(type.getQualifier().layoutBinding,
type.getQualifier().layoutLocation)));
if (type.isStruct() && type.getStruct()->size()==0)
return;
// if flattening arrayed io struct, array each member of dereferenced type
if (arrayed) {
const TType dereferencedType(type, 0);
flatten(variable, dereferencedType, entry.first->second, variable.getName(), linkage,
type.getQualifier(), type.getArraySizes());
} else {
flatten(variable, type, entry.first->second, variable.getName(), linkage,
type.getQualifier(), nullptr);
}
}
// Recursively flatten the given variable at the provided type, building the flattenData as we go.
//
// This is mutually recursive with flattenStruct and flattenArray.
// We are going to flatten an arbitrarily nested composite structure into a linear sequence of
// members, and later on, we want to turn a path through the tree structure into a final
// location in this linear sequence.
//
// If the tree was N-ary, that can be directly calculated. However, we are dealing with
// arbitrary numbers - perhaps a struct of 7 members containing an array of 3. Thus, we must
// build a data structure to allow the sequence of bracket and dot operators on arrays and
// structs to arrive at the proper member.
//
// To avoid storing a tree with pointers, we are going to flatten the tree into a vector of integers.
// The leaves are the indexes into the flattened member array.
// Each level will have the next location for the Nth item stored sequentially, so for instance:
//
// struct { float2 a[2]; int b; float4 c[3] };
//
// This will produce the following flattened tree:
// Pos: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
// (3, 7, 8, 5, 6, 0, 1, 2, 11, 12, 13, 3, 4, 5}
//
// Given a reference to mystruct.c[1], the access chain is (2,1), so we traverse:
// (0+2) = 8 --> (8+1) = 12 --> 12 = 4
//
// so the 4th flattened member in traversal order is ours.
//
int HlslParseContext::flatten(const TVariable& variable, const TType& type,
TFlattenData& flattenData, TString name, bool linkage,
const TQualifier& outerQualifier,
const TArraySizes* builtInArraySizes)
{
// If something is an arrayed struct, the array flattener will recursively call flatten()
// to then flatten the struct, so this is an "if else": we don't do both.
if (type.isArray())
return flattenArray(variable, type, flattenData, name, linkage, outerQualifier);
else if (type.isStruct())
return flattenStruct(variable, type, flattenData, name, linkage, outerQualifier, builtInArraySizes);
else {
assert(0); // should never happen
return -1;
}
}
// Add a single flattened member to the flattened data being tracked for the composite
// Returns true for the final flattening level.
int HlslParseContext::addFlattenedMember(const TVariable& variable, const TType& type, TFlattenData& flattenData,
const TString& memberName, bool linkage,
const TQualifier& outerQualifier,
const TArraySizes* builtInArraySizes)
{
if (!shouldFlatten(type, outerQualifier.storage, false)) {
// This is as far as we flatten. Insert the variable.
TVariable* memberVariable = makeInternalVariable(memberName, type);
mergeQualifiers(memberVariable->getWritableType().getQualifier(), variable.getType().getQualifier());
if (flattenData.nextBinding != TQualifier::layoutBindingEnd)
memberVariable->getWritableType().getQualifier().layoutBinding = flattenData.nextBinding++;
if (memberVariable->getType().isBuiltIn()) {
// inherited locations are nonsensical for built-ins (TODO: what if semantic had a number)
memberVariable->getWritableType().getQualifier().layoutLocation = TQualifier::layoutLocationEnd;
} else {
// inherited locations must be auto bumped, not replicated
if (flattenData.nextLocation != TQualifier::layoutLocationEnd) {
memberVariable->getWritableType().getQualifier().layoutLocation = flattenData.nextLocation;
flattenData.nextLocation += intermediate.computeTypeLocationSize(memberVariable->getType(), language);
nextOutLocation = std::max(nextOutLocation, flattenData.nextLocation);
}
}
// Only propagate arraysizes here for arrayed io
if (variable.getType().getQualifier().isArrayedIo(language) && builtInArraySizes != nullptr)
memberVariable->getWritableType().copyArraySizes(*builtInArraySizes);
flattenData.offsets.push_back(static_cast<int>(flattenData.members.size()));
flattenData.members.push_back(memberVariable);
if (linkage)
trackLinkage(*memberVariable);
return static_cast<int>(flattenData.offsets.size()) - 1; // location of the member reference
} else {
// Further recursion required
return flatten(variable, type, flattenData, memberName, linkage, outerQualifier, builtInArraySizes);
}
}
// Figure out the mapping between an aggregate's top members and an
// equivalent set of individual variables.
//
// Assumes shouldFlatten() or equivalent was called first.
int HlslParseContext::flattenStruct(const TVariable& variable, const TType& type,
TFlattenData& flattenData, TString name, bool linkage,
const TQualifier& outerQualifier,
const TArraySizes* builtInArraySizes)
{
assert(type.isStruct());
auto members = *type.getStruct();
// Reserve space for this tree level.
int start = static_cast<int>(flattenData.offsets.size());
int pos = start;
flattenData.offsets.resize(int(pos + members.size()), -1);
for (int member = 0; member < (int)members.size(); ++member) {
TType& dereferencedType = *members[member].type;
if (dereferencedType.isBuiltIn())
splitBuiltIn(variable.getName(), dereferencedType, builtInArraySizes, outerQualifier);
else {
const int mpos = addFlattenedMember(variable, dereferencedType, flattenData,
name + "." + dereferencedType.getFieldName(),
linkage, outerQualifier,
builtInArraySizes == nullptr && dereferencedType.isArray()
? dereferencedType.getArraySizes()
: builtInArraySizes);
flattenData.offsets[pos++] = mpos;
}
}
return start;
}
// Figure out mapping between an array's members and an
// equivalent set of individual variables.
//
// Assumes shouldFlatten() or equivalent was called first.
int HlslParseContext::flattenArray(const TVariable& variable, const TType& type,
TFlattenData& flattenData, TString name, bool linkage,
const TQualifier& outerQualifier)
{
assert(type.isSizedArray());
const int size = type.getOuterArraySize();
const TType dereferencedType(type, 0);
if (name.empty())
name = variable.getName();
// Reserve space for this tree level.
int start = static_cast<int>(flattenData.offsets.size());
int pos = start;
flattenData.offsets.resize(int(pos + size), -1);
for (int element=0; element < size; ++element) {
char elementNumBuf[20]; // sufficient for MAXINT
snprintf(elementNumBuf, sizeof(elementNumBuf)-1, "[%d]", element);
const int mpos = addFlattenedMember(variable, dereferencedType, flattenData,
name + elementNumBuf, linkage, outerQualifier,
type.getArraySizes());
flattenData.offsets[pos++] = mpos;
}
return start;
}
// Return true if we have flattened this node.
bool HlslParseContext::wasFlattened(const TIntermTyped* node) const
{
return node != nullptr && node->getAsSymbolNode() != nullptr &&
wasFlattened(node->getAsSymbolNode()->getId());
}
// Return true if we have split this structure
bool HlslParseContext::wasSplit(const TIntermTyped* node) const
{
return node != nullptr && node->getAsSymbolNode() != nullptr &&
wasSplit(node->getAsSymbolNode()->getId());
}
// Turn an access into an aggregate that was flattened to instead be
// an access to the individual variable the member was flattened to.
// Assumes wasFlattened() or equivalent was called first.
TIntermTyped* HlslParseContext::flattenAccess(TIntermTyped* base, int member)
{
const TType dereferencedType(base->getType(), member); // dereferenced type
const TIntermSymbol& symbolNode = *base->getAsSymbolNode();
TIntermTyped* flattened = flattenAccess(symbolNode.getId(), member, base->getQualifier().storage,
dereferencedType, symbolNode.getFlattenSubset());
return flattened ? flattened : base;
}
TIntermTyped* HlslParseContext::flattenAccess(long long uniqueId, int member, TStorageQualifier outerStorage,
const TType& dereferencedType, int subset)
{
const auto flattenData = flattenMap.find(uniqueId);
if (flattenData == flattenMap.end())
return nullptr;
// Calculate new cumulative offset from the packed tree
int newSubset = flattenData->second.offsets[subset >= 0 ? subset + member : member];
TIntermSymbol* subsetSymbol;
if (!shouldFlatten(dereferencedType, outerStorage, false)) {
// Finished flattening: create symbol for variable
member = flattenData->second.offsets[newSubset];
const TVariable* memberVariable = flattenData->second.members[member];
subsetSymbol = intermediate.addSymbol(*memberVariable);
subsetSymbol->setFlattenSubset(-1);
} else {
// If this is not the final flattening, accumulate the position and return
// an object of the partially dereferenced type.
subsetSymbol = new TIntermSymbol(uniqueId, "flattenShadow", dereferencedType);
subsetSymbol->setFlattenSubset(newSubset);
}
return subsetSymbol;
}
// For finding where the first leaf is in a subtree of a multi-level aggregate
// that is just getting a subset assigned. Follows the same logic as flattenAccess,
// but logically going down the "left-most" tree branch each step of the way.
//
// Returns the offset into the first leaf of the subset.
int HlslParseContext::findSubtreeOffset(const TIntermNode& node) const
{
const TIntermSymbol* sym = node.getAsSymbolNode();
if (sym == nullptr)
return 0;
if (!sym->isArray() && !sym->isStruct())
return 0;
int subset = sym->getFlattenSubset();
if (subset == -1)
return 0;
// Getting this far means a partial aggregate is identified by the flatten subset.
// Find the first leaf of the subset.
const auto flattenData = flattenMap.find(sym->getId());
if (flattenData == flattenMap.end())
return 0;
return findSubtreeOffset(sym->getType(), subset, flattenData->second.offsets);
do {
subset = flattenData->second.offsets[subset];
} while (true);
}
// Recursively do the desent
int HlslParseContext::findSubtreeOffset(const TType& type, int subset, const TVector<int>& offsets) const
{
if (!type.isArray() && !type.isStruct())
return offsets[subset];
TType derefType(type, 0);
return findSubtreeOffset(derefType, offsets[subset], offsets);
};
// Find and return the split IO TVariable for id, or nullptr if none.
TVariable* HlslParseContext::getSplitNonIoVar(long long id) const
{
const auto splitNonIoVar = splitNonIoVars.find(id);
if (splitNonIoVar == splitNonIoVars.end())
return nullptr;
return splitNonIoVar->second;
}
// Pass through to base class after remembering built-in mappings.
void HlslParseContext::trackLinkage(TSymbol& symbol)
{
TBuiltInVariable biType = symbol.getType().getQualifier().builtIn;
if (biType != EbvNone)
builtInTessLinkageSymbols[biType] = symbol.clone();
TParseContextBase::trackLinkage(symbol);
}
// Returns true if the built-in is a clip or cull distance variable.
bool HlslParseContext::isClipOrCullDistance(TBuiltInVariable builtIn)
{
return builtIn == EbvClipDistance || builtIn == EbvCullDistance;
}
// Some types require fixed array sizes in SPIR-V, but can be scalars or
// arrays of sizes SPIR-V doesn't allow. For example, tessellation factors.
// This creates the right size. A conversion is performed when the internal
// type is copied to or from the external type. This corrects the externally
// facing input or output type to abide downstream semantics.
void HlslParseContext::fixBuiltInIoType(TType& type)
{
int requiredArraySize = 0;
int requiredVectorSize = 0;
switch (type.getQualifier().builtIn) {
case EbvTessLevelOuter: requiredArraySize = 4; break;
case EbvTessLevelInner: requiredArraySize = 2; break;
case EbvSampleMask:
{
// Promote scalar to array of size 1. Leave existing arrays alone.
if (!type.isArray())
requiredArraySize = 1;
break;
}
case EbvWorkGroupId: requiredVectorSize = 3; break;
case EbvGlobalInvocationId: requiredVectorSize = 3; break;
case EbvLocalInvocationId: requiredVectorSize = 3; break;
case EbvTessCoord: requiredVectorSize = 3; break;
default:
if (isClipOrCullDistance(type)) {
const int loc = type.getQualifier().layoutLocation;
if (type.getQualifier().builtIn == EbvClipDistance) {
if (type.getQualifier().storage == EvqVaryingIn)
clipSemanticNSizeIn[loc] = type.getVectorSize();
else
clipSemanticNSizeOut[loc] = type.getVectorSize();
} else {
if (type.getQualifier().storage == EvqVaryingIn)
cullSemanticNSizeIn[loc] = type.getVectorSize();
else
cullSemanticNSizeOut[loc] = type.getVectorSize();
}
}
return;
}
// Alter or set vector size as needed.
if (requiredVectorSize > 0) {
TType newType(type.getBasicType(), type.getQualifier().storage, requiredVectorSize);
newType.getQualifier() = type.getQualifier();
type.shallowCopy(newType);
}
// Alter or set array size as needed.
if (requiredArraySize > 0) {
if (!type.isArray() || type.getOuterArraySize() != requiredArraySize) {
TArraySizes* arraySizes = new TArraySizes;
arraySizes->addInnerSize(requiredArraySize);
type.transferArraySizes(arraySizes);
}
}
}
// Variables that correspond to the user-interface in and out of a stage
// (not the built-in interface) are
// - assigned locations
// - registered as a linkage node (part of the stage's external interface).
// Assumes it is called in the order in which locations should be assigned.
void HlslParseContext::assignToInterface(TVariable& variable)
{
const auto assignLocation = [&](TVariable& variable) {
TType& type = variable.getWritableType();
if (!type.isStruct() || type.getStruct()->size() > 0) {
TQualifier& qualifier = type.getQualifier();
if (qualifier.storage == EvqVaryingIn || qualifier.storage == EvqVaryingOut) {
if (qualifier.builtIn == EbvNone && !qualifier.hasLocation()) {
// Strip off the outer array dimension for those having an extra one.
int size;
if (type.isArray() && qualifier.isArrayedIo(language)) {
TType elementType(type, 0);
size = intermediate.computeTypeLocationSize(elementType, language);
} else
size = intermediate.computeTypeLocationSize(type, language);
if (qualifier.storage == EvqVaryingIn) {
variable.getWritableType().getQualifier().layoutLocation = nextInLocation;
nextInLocation += size;
} else {
variable.getWritableType().getQualifier().layoutLocation = nextOutLocation;
nextOutLocation += size;
}
}
trackLinkage(variable);
}
}
};
if (wasFlattened(variable.getUniqueId())) {
auto& memberList = flattenMap[variable.getUniqueId()].members;
for (auto member = memberList.begin(); member != memberList.end(); ++member)
assignLocation(**member);
} else if (wasSplit(variable.getUniqueId())) {
TVariable* splitIoVar = getSplitNonIoVar(variable.getUniqueId());
assignLocation(*splitIoVar);
} else {
assignLocation(variable);
}
}
//
// Handle seeing a function declarator in the grammar. This is the precursor
// to recognizing a function prototype or function definition.
//
void HlslParseContext::handleFunctionDeclarator(const TSourceLoc& loc, TFunction& function, bool prototype)
{
//
// Multiple declarations of the same function name are allowed.
//
// If this is a definition, the definition production code will check for redefinitions
// (we don't know at this point if it's a definition or not).
//
bool builtIn;
TSymbol* symbol = symbolTable.find(function.getMangledName(), &builtIn);
const TFunction* prevDec = symbol ? symbol->getAsFunction() : nullptr;
if (prototype) {
// All built-in functions are defined, even though they don't have a body.
// Count their prototype as a definition instead.
if (symbolTable.atBuiltInLevel())
function.setDefined();
else {
if (prevDec && ! builtIn)
symbol->getAsFunction()->setPrototyped(); // need a writable one, but like having prevDec as a const
function.setPrototyped();
}
}
// This insert won't actually insert it if it's a duplicate signature, but it will still check for
// other forms of name collisions.
if (! symbolTable.insert(function))
error(loc, "function name is redeclaration of existing name", function.getName().c_str(), "");
}
// For struct buffers with counters, we must pass the counter buffer as hidden parameter.
// This adds the hidden parameter to the parameter list in 'paramNodes' if needed.
// Otherwise, it's a no-op
void HlslParseContext::addStructBufferHiddenCounterParam(const TSourceLoc& loc, TParameter& param,
TIntermAggregate*& paramNodes)
{
if (! hasStructBuffCounter(*param.type))
return;
const TString counterBlockName(intermediate.addCounterBufferName(*param.name));
TType counterType;
counterBufferType(loc, counterType);
TVariable *variable = makeInternalVariable(counterBlockName, counterType);
if (! symbolTable.insert(*variable))
error(loc, "redefinition", variable->getName().c_str(), "");
paramNodes = intermediate.growAggregate(paramNodes,
intermediate.addSymbol(*variable, loc),
loc);
}
//
// Handle seeing the function prototype in front of a function definition in the grammar.
// The body is handled after this function returns.
//
// Returns an aggregate of parameter-symbol nodes.
//
TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& loc, TFunction& function,
const TAttributes& attributes,
TIntermNode*& entryPointTree)
{
currentCaller = function.getMangledName();
TSymbol* symbol = symbolTable.find(function.getMangledName());
TFunction* prevDec = symbol ? symbol->getAsFunction() : nullptr;
if (prevDec == nullptr)
error(loc, "can't find function", function.getName().c_str(), "");
// Note: 'prevDec' could be 'function' if this is the first time we've seen function
// as it would have just been put in the symbol table. Otherwise, we're looking up
// an earlier occurrence.
if (prevDec && prevDec->isDefined()) {
// Then this function already has a body.
error(loc, "function already has a body", function.getName().c_str(), "");
}
if (prevDec && ! prevDec->isDefined()) {
prevDec->setDefined();
// Remember the return type for later checking for RETURN statements.
currentFunctionType = &(prevDec->getType());
} else
currentFunctionType = new TType(EbtVoid);
functionReturnsValue = false;
// Entry points need different I/O and other handling, transform it so the
// rest of this function doesn't care.
entryPointTree = transformEntryPoint(loc, function, attributes);
//
// New symbol table scope for body of function plus its arguments
//
pushScope();
//
// Insert parameters into the symbol table.
// If the parameter has no name, it's not an error, just don't insert it
// (could be used for unused args).
//
// Also, accumulate the list of parameters into the AST, so lower level code
// knows where to find parameters.
//
TIntermAggregate* paramNodes = new TIntermAggregate;
for (int i = 0; i < function.getParamCount(); i++) {
TParameter& param = function[i];
if (param.name != nullptr) {
TVariable *variable = new TVariable(param.name, *param.type);
if (i == 0 && function.hasImplicitThis()) {
// Anonymous 'this' members are already in a symbol-table level,
// and we need to know what function parameter to map them to.
symbolTable.makeInternalVariable(*variable);
pushImplicitThis(variable);
}
// Insert the parameters with name in the symbol table.
if (! symbolTable.insert(*variable))
error(loc, "redefinition", variable->getName().c_str(), "");
// Add parameters to the AST list.
if (shouldFlatten(variable->getType(), variable->getType().getQualifier().storage, true)) {
// Expand the AST parameter nodes (but not the name mangling or symbol table view)
// for structures that need to be flattened.
flatten(*variable, false);
const TTypeList* structure = variable->getType().getStruct();
for (int mem = 0; mem < (int)structure->size(); ++mem) {
paramNodes = intermediate.growAggregate(paramNodes,
flattenAccess(variable->getUniqueId(), mem,
variable->getType().getQualifier().storage,
*(*structure)[mem].type),
loc);
}
} else {
// Add the parameter to the AST
paramNodes = intermediate.growAggregate(paramNodes,
intermediate.addSymbol(*variable, loc),
loc);
}
// Add hidden AST parameter for struct buffer counters, if needed.
addStructBufferHiddenCounterParam(loc, param, paramNodes);
} else
paramNodes = intermediate.growAggregate(paramNodes, intermediate.addSymbol(*param.type, loc), loc);
}
if (function.hasIllegalImplicitThis())
pushImplicitThis(nullptr);
intermediate.setAggregateOperator(paramNodes, EOpParameters, TType(EbtVoid), loc);
loopNestingLevel = 0;
controlFlowNestingLevel = 0;
postEntryPointReturn = false;
return paramNodes;
}
// Handle all [attrib] attribute for the shader entry point
void HlslParseContext::handleEntryPointAttributes(const TSourceLoc& loc, const TAttributes& attributes)
{
for (auto it = attributes.begin(); it != attributes.end(); ++it) {
switch (it->name) {
case EatNumThreads:
{
const TIntermSequence& sequence = it->args->getSequence();
for (int lid = 0; lid < int(sequence.size()); ++lid)
intermediate.setLocalSize(lid, sequence[lid]->getAsConstantUnion()->getConstArray()[0].getIConst());
break;
}
case EatInstance:
{
int invocations;
if (!it->getInt(invocations)) {
error(loc, "invalid instance", "", "");
} else {
if (!intermediate.setInvocations(invocations))
error(loc, "cannot change previously set instance attribute", "", "");
}
break;
}
case EatMaxVertexCount:
{
int maxVertexCount;
if (! it->getInt(maxVertexCount)) {
error(loc, "invalid maxvertexcount", "", "");
} else {
if (! intermediate.setVertices(maxVertexCount))
error(loc, "cannot change previously set maxvertexcount attribute", "", "");
}
break;
}
case EatPatchConstantFunc:
{
TString pcfName;
if (! it->getString(pcfName, 0, false)) {
error(loc, "invalid patch constant function", "", "");
} else {
patchConstantFunctionName = pcfName;
}
break;
}
case EatDomain:
{
// Handle [domain("...")]
TString domainStr;
if (! it->getString(domainStr)) {
error(loc, "invalid domain", "", "");
} else {
TLayoutGeometry domain = ElgNone;
if (domainStr == "tri") {
domain = ElgTriangles;
} else if (domainStr == "quad") {
domain = ElgQuads;
} else if (domainStr == "isoline") {
domain = ElgIsolines;
} else {
error(loc, "unsupported domain type", domainStr.c_str(), "");
}
if (language == EShLangTessEvaluation) {
if (! intermediate.setInputPrimitive(domain))
error(loc, "cannot change previously set domain", TQualifier::getGeometryString(domain), "");
} else {
if (! intermediate.setOutputPrimitive(domain))
error(loc, "cannot change previously set domain", TQualifier::getGeometryString(domain), "");
}
}
break;
}
case EatOutputTopology:
{
// Handle [outputtopology("...")]
TString topologyStr;
if (! it->getString(topologyStr)) {
error(loc, "invalid outputtopology", "", "");
} else {
TVertexOrder vertexOrder = EvoNone;
TLayoutGeometry primitive = ElgNone;
if (topologyStr == "point") {
intermediate.setPointMode();
} else if (topologyStr == "line") {
primitive = ElgIsolines;
} else if (topologyStr == "triangle_cw") {
vertexOrder = EvoCw;
primitive = ElgTriangles;
} else if (topologyStr == "triangle_ccw") {
vertexOrder = EvoCcw;
primitive = ElgTriangles;
} else {
error(loc, "unsupported outputtopology type", topologyStr.c_str(), "");
}
if (vertexOrder != EvoNone) {
if (! intermediate.setVertexOrder(vertexOrder)) {
error(loc, "cannot change previously set outputtopology",
TQualifier::getVertexOrderString(vertexOrder), "");
}
}
if (primitive != ElgNone)
intermediate.setOutputPrimitive(primitive);
}
break;
}
case EatPartitioning:
{
// Handle [partitioning("...")]
TString partitionStr;
if (! it->getString(partitionStr)) {
error(loc, "invalid partitioning", "", "");
} else {
TVertexSpacing partitioning = EvsNone;
if (partitionStr == "integer") {
partitioning = EvsEqual;
} else if (partitionStr == "fractional_even") {
partitioning = EvsFractionalEven;
} else if (partitionStr == "fractional_odd") {
partitioning = EvsFractionalOdd;
//} else if (partition == "pow2") { // TODO: currently nothing to map this to.
} else {
error(loc, "unsupported partitioning type", partitionStr.c_str(), "");
}
if (! intermediate.setVertexSpacing(partitioning))
error(loc, "cannot change previously set partitioning",
TQualifier::getVertexSpacingString(partitioning), "");
}
break;
}
case EatOutputControlPoints:
{
// Handle [outputcontrolpoints("...")]
int ctrlPoints;
if (! it->getInt(ctrlPoints)) {
error(loc, "invalid outputcontrolpoints", "", "");
} else {
if (! intermediate.setVertices(ctrlPoints)) {
error(loc, "cannot change previously set outputcontrolpoints attribute", "", "");
}
}
break;
}
case EatEarlyDepthStencil:
intermediate.setEarlyFragmentTests();
break;
case EatBuiltIn:
case EatLocation:
// tolerate these because of dual use of entrypoint and type attributes
break;
default:
warn(loc, "attribute does not apply to entry point", "", "");
break;
}
}
}
// Update the given type with any type-like attribute information in the
// attributes.
void HlslParseContext::transferTypeAttributes(const TSourceLoc& loc, const TAttributes& attributes, TType& type,
bool allowEntry)
{
if (attributes.size() == 0)
return;
int value;
TString builtInString;
for (auto it = attributes.begin(); it != attributes.end(); ++it) {
switch (it->name) {
case EatLocation:
// location
if (it->getInt(value))
type.getQualifier().layoutLocation = value;
else
error(loc, "needs a literal integer", "location", "");
break;
case EatBinding:
// binding
if (it->getInt(value)) {
type.getQualifier().layoutBinding = value;
type.getQualifier().layoutSet = 0;
} else
error(loc, "needs a literal integer", "binding", "");
// set
if (it->getInt(value, 1))
type.getQualifier().layoutSet = value;
break;
case EatGlobalBinding:
// global cbuffer binding
if (it->getInt(value))
globalUniformBinding = value;
else
error(loc, "needs a literal integer", "global binding", "");
// global cbuffer set
if (it->getInt(value, 1))
globalUniformSet = value;
break;
case EatInputAttachment:
// input attachment
if (it->getInt(value))
type.getQualifier().layoutAttachment = value;
else
error(loc, "needs a literal integer", "input attachment", "");
break;
case EatBuiltIn:
// PointSize built-in
if (it->getString(builtInString, 0, false)) {
if (builtInString == "PointSize")
type.getQualifier().builtIn = EbvPointSize;
}
break;
case EatPushConstant:
// push_constant
type.getQualifier().layoutPushConstant = true;
break;
case EatConstantId:
// specialization constant
if (type.getQualifier().storage != EvqConst) {
error(loc, "needs a const type", "constant_id", "");
break;
}
if (it->getInt(value)) {
TSourceLoc loc;
loc.init();
setSpecConstantId(loc, type.getQualifier(), value);
}
break;
// image formats
case EatFormatRgba32f: type.getQualifier().layoutFormat = ElfRgba32f; break;
case EatFormatRgba16f: type.getQualifier().layoutFormat = ElfRgba16f; break;
case EatFormatR32f: type.getQualifier().layoutFormat = ElfR32f; break;
case EatFormatRgba8: type.getQualifier().layoutFormat = ElfRgba8; break;
case EatFormatRgba8Snorm: type.getQualifier().layoutFormat = ElfRgba8Snorm; break;
case EatFormatRg32f: type.getQualifier().layoutFormat = ElfRg32f; break;
case EatFormatRg16f: type.getQualifier().layoutFormat = ElfRg16f; break;
case EatFormatR11fG11fB10f: type.getQualifier().layoutFormat = ElfR11fG11fB10f; break;
case EatFormatR16f: type.getQualifier().layoutFormat = ElfR16f; break;
case EatFormatRgba16: type.getQualifier().layoutFormat = ElfRgba16; break;
case EatFormatRgb10A2: type.getQualifier().layoutFormat = ElfRgb10A2; break;
case EatFormatRg16: type.getQualifier().layoutFormat = ElfRg16; break;
case EatFormatRg8: type.getQualifier().layoutFormat = ElfRg8; break;
case EatFormatR16: type.getQualifier().layoutFormat = ElfR16; break;
case EatFormatR8: type.getQualifier().layoutFormat = ElfR8; break;
case EatFormatRgba16Snorm: type.getQualifier().layoutFormat = ElfRgba16Snorm; break;
case EatFormatRg16Snorm: type.getQualifier().layoutFormat = ElfRg16Snorm; break;
case EatFormatRg8Snorm: type.getQualifier().layoutFormat = ElfRg8Snorm; break;
case EatFormatR16Snorm: type.getQualifier().layoutFormat = ElfR16Snorm; break;
case EatFormatR8Snorm: type.getQualifier().layoutFormat = ElfR8Snorm; break;
case EatFormatRgba32i: type.getQualifier().layoutFormat = ElfRgba32i; break;
case EatFormatRgba16i: type.getQualifier().layoutFormat = ElfRgba16i; break;
case EatFormatRgba8i: type.getQualifier().layoutFormat = ElfRgba8i; break;
case EatFormatR32i: type.getQualifier().layoutFormat = ElfR32i; break;
case EatFormatRg32i: type.getQualifier().layoutFormat = ElfRg32i; break;
case EatFormatRg16i: type.getQualifier().layoutFormat = ElfRg16i; break;
case EatFormatRg8i: type.getQualifier().layoutFormat = ElfRg8i; break;
case EatFormatR16i: type.getQualifier().layoutFormat = ElfR16i; break;
case EatFormatR8i: type.getQualifier().layoutFormat = ElfR8i; break;
case EatFormatRgba32ui: type.getQualifier().layoutFormat = ElfRgba32ui; break;
case EatFormatRgba16ui: type.getQualifier().layoutFormat = ElfRgba16ui; break;
case EatFormatRgba8ui: type.getQualifier().layoutFormat = ElfRgba8ui; break;
case EatFormatR32ui: type.getQualifier().layoutFormat = ElfR32ui; break;
case EatFormatRgb10a2ui: type.getQualifier().layoutFormat = ElfRgb10a2ui; break;
case EatFormatRg32ui: type.getQualifier().layoutFormat = ElfRg32ui; break;
case EatFormatRg16ui: type.getQualifier().layoutFormat = ElfRg16ui; break;
case EatFormatRg8ui: type.getQualifier().layoutFormat = ElfRg8ui; break;
case EatFormatR16ui: type.getQualifier().layoutFormat = ElfR16ui; break;
case EatFormatR8ui: type.getQualifier().layoutFormat = ElfR8ui; break;
case EatFormatUnknown: type.getQualifier().layoutFormat = ElfNone; break;
case EatNonWritable: type.getQualifier().readonly = true; break;
case EatNonReadable: type.getQualifier().writeonly = true; break;
default:
if (! allowEntry)
warn(loc, "attribute does not apply to a type", "", "");
break;
}
}
}
//
// Do all special handling for the entry point, including wrapping
// the shader's entry point with the official entry point that will call it.
//
// The following:
//
// retType shaderEntryPoint(args...) // shader declared entry point
// { body }
//
// Becomes
//
// out retType ret;
// in iargs<that are input>...;
// out oargs<that are output> ...;
//
// void shaderEntryPoint() // synthesized, but official, entry point
// {
// args<that are input> = iargs...;
// ret = @shaderEntryPoint(args...);
// oargs = args<that are output>...;
// }
// retType @shaderEntryPoint(args...)
// { body }
//
// The symbol table will still map the original entry point name to the
// the modified function and its new name:
//
// symbol table: shaderEntryPoint -> @shaderEntryPoint
//
// Returns nullptr if no entry-point tree was built, otherwise, returns
// a subtree that creates the entry point.
//
TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunction& userFunction,
const TAttributes& attributes)
{
// Return true if this is a tessellation patch constant function input to a domain shader.
const auto isDsPcfInput = [this](const TType& type) {
return language == EShLangTessEvaluation &&
type.contains([](const TType* t) {
return t->getQualifier().builtIn == EbvTessLevelOuter ||
t->getQualifier().builtIn == EbvTessLevelInner;
});
};
// if we aren't in the entry point, fix the IO as such and exit
if (! isEntrypointName(userFunction.getName())) {
remapNonEntryPointIO(userFunction);
return nullptr;
}
entryPointFunction = &userFunction; // needed in finish()
// Handle entry point attributes
handleEntryPointAttributes(loc, attributes);
// entry point logic...
// Move parameters and return value to shader in/out
TVariable* entryPointOutput; // gets created in remapEntryPointIO
TVector<TVariable*> inputs;
TVector<TVariable*> outputs;
remapEntryPointIO(userFunction, entryPointOutput, inputs, outputs);
// Further this return/in/out transform by flattening, splitting, and assigning locations
const auto makeVariableInOut = [&](TVariable& variable) {
if (variable.getType().isStruct()) {
bool arrayed = variable.getType().getQualifier().isArrayedIo(language);
flatten(variable, false /* don't track linkage here, it will be tracked in assignToInterface() */, arrayed);
}
// TODO: flatten arrays too
// TODO: flatten everything in I/O
// TODO: replace all split with flatten, make all paths can create flattened I/O, then split code can be removed
// For clip and cull distance, multiple output variables potentially get merged
// into one in assignClipCullDistance. That code in assignClipCullDistance
// handles the interface logic, so we avoid it here in that case.
if (!isClipOrCullDistance(variable.getType()))
assignToInterface(variable);
};
if (entryPointOutput != nullptr)
makeVariableInOut(*entryPointOutput);
for (auto it = inputs.begin(); it != inputs.end(); ++it)
if (!isDsPcfInput((*it)->getType())) // wait until the end for PCF input (see comment below)
makeVariableInOut(*(*it));
for (auto it = outputs.begin(); it != outputs.end(); ++it)
makeVariableInOut(*(*it));
// In the domain shader, PCF input must be at the end of the linkage. That's because in the
// hull shader there is no ordering: the output comes from the separate PCF, which does not
// participate in the argument list. That is always put at the end of the HS linkage, so the
// input side of the DS must match. The argument may be in any position in the DS argument list
// however, so this ensures the linkage is built in the correct order regardless of argument order.
if (language == EShLangTessEvaluation) {
for (auto it = inputs.begin(); it != inputs.end(); ++it)
if (isDsPcfInput((*it)->getType()))
makeVariableInOut(*(*it));
}
// Add uniform parameters to the $Global uniform block.
TVector<TVariable*> opaque_uniforms;
for (int i = 0; i < userFunction.getParamCount(); i++) {
TType& paramType = *userFunction[i].type;
TString& paramName = *userFunction[i].name;
if (paramType.getQualifier().storage == EvqUniform) {
if (!paramType.containsOpaque()) {
// Add it to the global uniform block.
growGlobalUniformBlock(loc, paramType, paramName);
} else {
// Declare it as a separate variable.
TVariable *var = makeInternalVariable(paramName.c_str(), paramType);
opaque_uniforms.push_back(var);
}
}
}
// Synthesize the call
pushScope(); // matches the one in handleFunctionBody()
// new signature
TType voidType(EbtVoid);
TFunction synthEntryPoint(&userFunction.getName(), voidType);
TIntermAggregate* synthParams = new TIntermAggregate();
intermediate.setAggregateOperator(synthParams, EOpParameters, voidType, loc);
intermediate.setEntryPointMangledName(synthEntryPoint.getMangledName().c_str());
intermediate.incrementEntryPointCount();
TFunction callee(&userFunction.getName(), voidType); // call based on old name, which is still in the symbol table
// change original name
userFunction.addPrefix("@"); // change the name in the function, but not in the symbol table
// Copy inputs (shader-in -> calling arg), while building up the call node
TVector<TVariable*> argVars;
TIntermAggregate* synthBody = new TIntermAggregate();
auto inputIt = inputs.begin();
auto opaqueUniformIt = opaque_uniforms.begin();
TIntermTyped* callingArgs = nullptr;
for (int i = 0; i < userFunction.getParamCount(); i++) {
TParameter& param = userFunction[i];
argVars.push_back(makeInternalVariable(*param.name, *param.type));
argVars.back()->getWritableType().getQualifier().makeTemporary();
// Track the input patch, which is the only non-builtin supported by hull shader PCF.
if (param.getDeclaredBuiltIn() == EbvInputPatch)
inputPatch = argVars.back();
TIntermSymbol* arg = intermediate.addSymbol(*argVars.back());
handleFunctionArgument(&callee, callingArgs, arg);
if (param.type->getQualifier().isParamInput()) {
TIntermTyped* input = intermediate.addSymbol(**inputIt);
if (input->getType().getQualifier().builtIn == EbvFragCoord && intermediate.getDxPositionW()) {
// Replace FragCoord W with reciprocal
auto pos_xyz = handleDotDereference(loc, input, "xyz");
auto pos_w = handleDotDereference(loc, input, "w");
auto one = intermediate.addConstantUnion(1.0, EbtFloat, loc);
auto recip_w = intermediate.addBinaryMath(EOpDiv, one, pos_w, loc);
TIntermAggregate* dst = new TIntermAggregate(EOpConstructVec4);
dst->getSequence().push_back(pos_xyz);
dst->getSequence().push_back(recip_w);
dst->setType(TType(EbtFloat, EvqTemporary, 4));
dst->setLoc(loc);
input = dst;
}
intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign, arg, input));
inputIt++;
}
if (param.type->getQualifier().storage == EvqUniform) {
if (!param.type->containsOpaque()) {
// Look it up in the $Global uniform block.
intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign, arg,
handleVariable(loc, param.name)));
} else {
intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign, arg,
intermediate.addSymbol(**opaqueUniformIt)));
++opaqueUniformIt;
}
}
}
// Call
currentCaller = synthEntryPoint.getMangledName();
TIntermTyped* callReturn = handleFunctionCall(loc, &callee, callingArgs);
currentCaller = userFunction.getMangledName();
// Return value
if (entryPointOutput) {
TIntermTyped* returnAssign;
// For hull shaders, the wrapped entry point return value is written to
// an array element as indexed by invocation ID, which we might have to make up.
// This is required to match SPIR-V semantics.
if (language == EShLangTessControl) {
TIntermSymbol* invocationIdSym = findTessLinkageSymbol(EbvInvocationId);
// If there is no user declared invocation ID, we must make one.
if (invocationIdSym == nullptr) {
TType invocationIdType(EbtUint, EvqIn, 1);
TString* invocationIdName = NewPoolTString("InvocationId");
invocationIdType.getQualifier().builtIn = EbvInvocationId;
TVariable* variable = makeInternalVariable(*invocationIdName, invocationIdType);
globalQualifierFix(loc, variable->getWritableType().getQualifier());
trackLinkage(*variable);
invocationIdSym = intermediate.addSymbol(*variable);
}
TIntermTyped* element = intermediate.addIndex(EOpIndexIndirect, intermediate.addSymbol(*entryPointOutput),
invocationIdSym, loc);
// Set the type of the array element being dereferenced
const TType derefElementType(entryPointOutput->getType(), 0);
element->setType(derefElementType);
returnAssign = handleAssign(loc, EOpAssign, element, callReturn);
} else {
returnAssign = handleAssign(loc, EOpAssign, intermediate.addSymbol(*entryPointOutput), callReturn);
}
intermediate.growAggregate(synthBody, returnAssign);
} else
intermediate.growAggregate(synthBody, callReturn);
// Output copies
auto outputIt = outputs.begin();
for (int i = 0; i < userFunction.getParamCount(); i++) {
TParameter& param = userFunction[i];
// GS outputs are via emit, so we do not copy them here.
if (param.type->getQualifier().isParamOutput()) {
if (param.getDeclaredBuiltIn() == EbvGsOutputStream) {
// GS output stream does not assign outputs here: it's the Append() method
// which writes to the output, probably multiple times separated by Emit.
// We merely remember the output to use, here.
gsStreamOutput = *outputIt;
} else {
intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign,
intermediate.addSymbol(**outputIt),
intermediate.addSymbol(*argVars[i])));
}
outputIt++;
}
}
// Put the pieces together to form a full function subtree
// for the synthesized entry point.
synthBody->setOperator(EOpSequence);
TIntermNode* synthFunctionDef = synthParams;
handleFunctionBody(loc, synthEntryPoint, synthBody, synthFunctionDef);
entryPointFunctionBody = synthBody;
return synthFunctionDef;
}
void HlslParseContext::handleFunctionBody(const TSourceLoc& loc, TFunction& function, TIntermNode* functionBody,
TIntermNode*& node)
{
node = intermediate.growAggregate(node, functionBody);
intermediate.setAggregateOperator(node, EOpFunction, function.getType(), loc);
node->getAsAggregate()->setName(function.getMangledName().c_str());
popScope();
if (function.hasImplicitThis())
popImplicitThis();
if (function.getType().getBasicType() != EbtVoid && ! functionReturnsValue)
error(loc, "function does not return a value:", "", function.getName().c_str());
}
// AST I/O is done through shader globals declared in the 'in' or 'out'
// storage class. An HLSL entry point has a return value, input parameters
// and output parameters. These need to get remapped to the AST I/O.
void HlslParseContext::remapEntryPointIO(TFunction& function, TVariable*& returnValue,
TVector<TVariable*>& inputs, TVector<TVariable*>& outputs)
{
// We might have in input structure type with no decorations that caused it
// to look like an input type, yet it has (e.g.) interpolation types that
// must be modified that turn it into an input type.
// Hence, a missing ioTypeMap for 'input' might need to be synthesized.
const auto synthesizeEditedInput = [this](TType& type) {
// True if a type needs to be 'flat'
const auto needsFlat = [](const TType& type) {
return type.containsBasicType(EbtInt) ||
type.containsBasicType(EbtUint) ||
type.containsBasicType(EbtInt64) ||
type.containsBasicType(EbtUint64) ||
type.containsBasicType(EbtBool) ||
type.containsBasicType(EbtDouble);
};
if (language == EShLangFragment && needsFlat(type)) {
if (type.isStruct()) {
TTypeList* finalList = nullptr;
auto it = ioTypeMap.find(type.getStruct());
if (it == ioTypeMap.end() || it->second.input == nullptr) {
// Getting here means we have no input struct, but we need one.
auto list = new TTypeList;
for (auto member = type.getStruct()->begin(); member != type.getStruct()->end(); ++member) {
TType* newType = new TType;
newType->shallowCopy(*member->type);
TTypeLoc typeLoc = { newType, member->loc };
list->push_back(typeLoc);
}
// install the new input type
if (it == ioTypeMap.end()) {
tIoKinds newLists = { list, nullptr, nullptr };
ioTypeMap[type.getStruct()] = newLists;
} else
it->second.input = list;
finalList = list;
} else
finalList = it->second.input;
// edit for 'flat'
for (auto member = finalList->begin(); member != finalList->end(); ++member) {
if (needsFlat(*member->type)) {
member->type->getQualifier().clearInterpolation();
member->type->getQualifier().flat = true;
}
}
} else {
type.getQualifier().clearInterpolation();
type.getQualifier().flat = true;
}
}
};
// Do the actual work to make a type be a shader input or output variable,
// and clear the original to be non-IO (for use as a normal function parameter/return).
const auto makeIoVariable = [this](const char* name, TType& type, TStorageQualifier storage) -> TVariable* {
TVariable* ioVariable = makeInternalVariable(name, type);
clearUniformInputOutput(type.getQualifier());
if (type.isStruct()) {
auto newLists = ioTypeMap.find(ioVariable->getType().getStruct());
if (newLists != ioTypeMap.end()) {
if (storage == EvqVaryingIn && newLists->second.input)
ioVariable->getWritableType().setStruct(newLists->second.input);
else if (storage == EvqVaryingOut && newLists->second.output)
ioVariable->getWritableType().setStruct(newLists->second.output);
}
}
if (storage == EvqVaryingIn) {
correctInput(ioVariable->getWritableType().getQualifier());
if (language == EShLangTessEvaluation)
if (!ioVariable->getType().isArray())
ioVariable->getWritableType().getQualifier().patch = true;
} else {
correctOutput(ioVariable->getWritableType().getQualifier());
}
ioVariable->getWritableType().getQualifier().storage = storage;
fixBuiltInIoType(ioVariable->getWritableType());
return ioVariable;
};
// return value is actually a shader-scoped output (out)
if (function.getType().getBasicType() == EbtVoid) {
returnValue = nullptr;
} else {
if (language == EShLangTessControl) {
// tessellation evaluation in HLSL writes a per-ctrl-pt value, but it needs to be an
// array in SPIR-V semantics. We'll write to it indexed by invocation ID.
returnValue = makeIoVariable("@entryPointOutput", function.getWritableType(), EvqVaryingOut);
TType outputType;
outputType.shallowCopy(function.getType());
// vertices has necessarily already been set when handling entry point attributes.
TArraySizes* arraySizes = new TArraySizes;
arraySizes->addInnerSize(intermediate.getVertices());
outputType.transferArraySizes(arraySizes);
clearUniformInputOutput(function.getWritableType().getQualifier());
returnValue = makeIoVariable("@entryPointOutput", outputType, EvqVaryingOut);
} else {
returnValue = makeIoVariable("@entryPointOutput", function.getWritableType(), EvqVaryingOut);
}
}
// parameters are actually shader-scoped inputs and outputs (in or out)
for (int i = 0; i < function.getParamCount(); i++) {
TType& paramType = *function[i].type;
if (paramType.getQualifier().isParamInput()) {
synthesizeEditedInput(paramType);
TVariable* argAsGlobal = makeIoVariable(function[i].name->c_str(), paramType, EvqVaryingIn);
inputs.push_back(argAsGlobal);
}
if (paramType.getQualifier().isParamOutput()) {
TVariable* argAsGlobal = makeIoVariable(function[i].name->c_str(), paramType, EvqVaryingOut);
outputs.push_back(argAsGlobal);
}
}
}
// An HLSL function that looks like an entry point, but is not,
// declares entry point IO built-ins, but these have to be undone.
void HlslParseContext::remapNonEntryPointIO(TFunction& function)
{
// return value
if (function.getType().getBasicType() != EbtVoid)
clearUniformInputOutput(function.getWritableType().getQualifier());
// parameters.
// References to structuredbuffer types are left unmodified
for (int i = 0; i < function.getParamCount(); i++)
if (!isReference(*function[i].type))
clearUniformInputOutput(function[i].type->getQualifier());
}
TIntermNode* HlslParseContext::handleDeclare(const TSourceLoc& loc, TIntermTyped* var)
{
return intermediate.addUnaryNode(EOpDeclare, var, loc, TType(EbtVoid));
}
// Handle function returns, including type conversions to the function return type
// if necessary.
TIntermNode* HlslParseContext::handleReturnValue(const TSourceLoc& loc, TIntermTyped* value)
{
functionReturnsValue = true;
if (currentFunctionType->getBasicType() == EbtVoid) {
error(loc, "void function cannot return a value", "return", "");
return intermediate.addBranch(EOpReturn, loc);
} else if (*currentFunctionType != value->getType()) {
value = intermediate.addConversion(EOpReturn, *currentFunctionType, value);
if (value && *currentFunctionType != value->getType())
value = intermediate.addUniShapeConversion(EOpReturn, *currentFunctionType, value);
if (value == nullptr || *currentFunctionType != value->getType()) {
error(loc, "type does not match, or is not convertible to, the function's return type", "return", "");
return value;
}
}
return intermediate.addBranch(EOpReturn, value, loc);
}
void HlslParseContext::handleFunctionArgument(TFunction* function,
TIntermTyped*& arguments, TIntermTyped* newArg)
{
TParameter param = { nullptr, new TType, nullptr };
param.type->shallowCopy(newArg->getType());
function->addParameter(param);
if (arguments)
arguments = intermediate.growAggregate(arguments, newArg);
else
arguments = newArg;
}
// FragCoord may require special loading: we can optionally reciprocate W.
TIntermTyped* HlslParseContext::assignFromFragCoord(const TSourceLoc& loc, TOperator op,
TIntermTyped* left, TIntermTyped* right)
{
// If we are not asked for reciprocal W, use a plain old assign.
if (!intermediate.getDxPositionW())
return intermediate.addAssign(op, left, right, loc);
// If we get here, we should reciprocate W.
TIntermAggregate* assignList = nullptr;
// If this is a complex rvalue, we don't want to dereference it many times. Create a temporary.
TVariable* rhsTempVar = nullptr;
rhsTempVar = makeInternalVariable("@fragcoord", right->getType());
rhsTempVar->getWritableType().getQualifier().makeTemporary();
{
TIntermTyped* rhsTempSym = intermediate.addSymbol(*rhsTempVar, loc);
assignList = intermediate.growAggregate(assignList,
intermediate.addAssign(EOpAssign, rhsTempSym, right, loc), loc);
}
// tmp.w = 1.0 / tmp.w
{
const int W = 3;
TIntermTyped* tempSymL = intermediate.addSymbol(*rhsTempVar, loc);
TIntermTyped* tempSymR = intermediate.addSymbol(*rhsTempVar, loc);
TIntermTyped* index = intermediate.addConstantUnion(W, loc);
TIntermTyped* lhsElement = intermediate.addIndex(EOpIndexDirect, tempSymL, index, loc);
TIntermTyped* rhsElement = intermediate.addIndex(EOpIndexDirect, tempSymR, index, loc);
const TType derefType(right->getType(), 0);
lhsElement->setType(derefType);
rhsElement->setType(derefType);
auto one = intermediate.addConstantUnion(1.0, EbtFloat, loc);
auto recip_w = intermediate.addBinaryMath(EOpDiv, one, rhsElement, loc);
assignList = intermediate.growAggregate(assignList, intermediate.addAssign(EOpAssign, lhsElement, recip_w, loc));
}
// Assign the rhs temp (now with W reciprocal) to the final output
{
TIntermTyped* rhsTempSym = intermediate.addSymbol(*rhsTempVar, loc);
assignList = intermediate.growAggregate(assignList, intermediate.addAssign(op, left, rhsTempSym, loc));
}
assert(assignList != nullptr);
assignList->setOperator(EOpSequence);
return assignList;
}
// Position may require special handling: we can optionally invert Y.
// See: https://github.com/KhronosGroup/glslang/issues/1173
// https://github.com/KhronosGroup/glslang/issues/494
TIntermTyped* HlslParseContext::assignPosition(const TSourceLoc& loc, TOperator op,
TIntermTyped* left, TIntermTyped* right)
{
// If we are not asked for Y inversion, use a plain old assign.
if (!intermediate.getInvertY())
return intermediate.addAssign(op, left, right, loc);
// If we get here, we should invert Y.
TIntermAggregate* assignList = nullptr;
// If this is a complex rvalue, we don't want to dereference it many times. Create a temporary.
TVariable* rhsTempVar = nullptr;
rhsTempVar = makeInternalVariable("@position", right->getType());
rhsTempVar->getWritableType().getQualifier().makeTemporary();
{
TIntermTyped* rhsTempSym = intermediate.addSymbol(*rhsTempVar, loc);
assignList = intermediate.growAggregate(assignList,
intermediate.addAssign(EOpAssign, rhsTempSym, right, loc), loc);
}
// pos.y = -pos.y
{
const int Y = 1;
TIntermTyped* tempSymL = intermediate.addSymbol(*rhsTempVar, loc);
TIntermTyped* tempSymR = intermediate.addSymbol(*rhsTempVar, loc);
TIntermTyped* index = intermediate.addConstantUnion(Y, loc);
TIntermTyped* lhsElement = intermediate.addIndex(EOpIndexDirect, tempSymL, index, loc);
TIntermTyped* rhsElement = intermediate.addIndex(EOpIndexDirect, tempSymR, index, loc);
const TType derefType(right->getType(), 0);
lhsElement->setType(derefType);
rhsElement->setType(derefType);
TIntermTyped* yNeg = intermediate.addUnaryMath(EOpNegative, rhsElement, loc);
assignList = intermediate.growAggregate(assignList, intermediate.addAssign(EOpAssign, lhsElement, yNeg, loc));
}
// Assign the rhs temp (now with Y inversion) to the final output
{
TIntermTyped* rhsTempSym = intermediate.addSymbol(*rhsTempVar, loc);
assignList = intermediate.growAggregate(assignList, intermediate.addAssign(op, left, rhsTempSym, loc));
}
assert(assignList != nullptr);
assignList->setOperator(EOpSequence);
return assignList;
}
// Clip and cull distance require special handling due to a semantic mismatch. In HLSL,
// these can be float scalar, float vector, or arrays of float scalar or float vector.
// In SPIR-V, they are arrays of scalar floats in all cases. We must copy individual components
// (e.g, both x and y components of a float2) out into the destination float array.
//
// The values are assigned to sequential members of the output array. The inner dimension
// is vector components. The outer dimension is array elements.
TIntermAggregate* HlslParseContext::assignClipCullDistance(const TSourceLoc& loc, TOperator op, int semanticId,
TIntermTyped* left, TIntermTyped* right)
{
switch (language) {
case EShLangFragment:
case EShLangVertex:
case EShLangGeometry:
break;
default:
error(loc, "unimplemented: clip/cull not currently implemented for this stage", "", "");
return nullptr;
}
TVariable** clipCullVar = nullptr;
// Figure out if we are assigning to, or from, clip or cull distance.
const bool isOutput = isClipOrCullDistance(left->getType());
// This is the rvalue or lvalue holding the clip or cull distance.
TIntermTyped* clipCullNode = isOutput ? left : right;
// This is the value going into or out of the clip or cull distance.
TIntermTyped* internalNode = isOutput ? right : left;
const TBuiltInVariable builtInType = clipCullNode->getQualifier().builtIn;
decltype(clipSemanticNSizeIn)* semanticNSize = nullptr;
// Refer to either the clip or the cull distance, depending on semantic.
switch (builtInType) {
case EbvClipDistance:
clipCullVar = isOutput ? &clipDistanceOutput : &clipDistanceInput;
semanticNSize = isOutput ? &clipSemanticNSizeOut : &clipSemanticNSizeIn;
break;
case EbvCullDistance:
clipCullVar = isOutput ? &cullDistanceOutput : &cullDistanceInput;
semanticNSize = isOutput ? &cullSemanticNSizeOut : &cullSemanticNSizeIn;
break;
// called invalidly: we expected a clip or a cull distance.
// static compile time problem: should not happen.
default: assert(0); return nullptr;
}
// This is the offset in the destination array of a given semantic's data
std::array<int, maxClipCullRegs> semanticOffset;
// Calculate offset of variable of semantic N in destination array
int arrayLoc = 0;
int vecItems = 0;
for (int x = 0; x < maxClipCullRegs; ++x) {
// See if we overflowed the vec4 packing
if ((vecItems + (*semanticNSize)[x]) > 4) {
arrayLoc = (arrayLoc + 3) & (~0x3); // round up to next multiple of 4
vecItems = 0;
}
semanticOffset[x] = arrayLoc;
vecItems += (*semanticNSize)[x];
arrayLoc += (*semanticNSize)[x];
}
// It can have up to 2 array dimensions (in the case of geometry shader inputs)
const TArraySizes* const internalArraySizes = internalNode->getType().getArraySizes();
const int internalArrayDims = internalNode->getType().isArray() ? internalArraySizes->getNumDims() : 0;
// vector sizes:
const int internalVectorSize = internalNode->getType().getVectorSize();
// array sizes, or 1 if it's not an array:
const int internalInnerArraySize = (internalArrayDims > 0 ? internalArraySizes->getDimSize(internalArrayDims-1) : 1);
const int internalOuterArraySize = (internalArrayDims > 1 ? internalArraySizes->getDimSize(0) : 1);
// The created type may be an array of arrays, e.g, for geometry shader inputs.
const bool isImplicitlyArrayed = (language == EShLangGeometry && !isOutput);
// If we haven't created the output already, create it now.
if (*clipCullVar == nullptr) {
// ClipDistance and CullDistance are handled specially in the entry point input/output copy
// algorithm, because they may need to be unpacked from components of vectors (or a scalar)
// into a float array, or vice versa. Here, we make the array the right size and type,
// which depends on the incoming data, which has several potential dimensions:
// * Semantic ID
// * vector size
// * array size
// Of those, semantic ID and array size cannot appear simultaneously.
//
// Also to note: for implicitly arrayed forms (e.g, geometry shader inputs), we need to create two
// array dimensions. The shader's declaration may have one or two array dimensions. One is always
// the geometry's dimension.
const bool useInnerSize = internalArrayDims > 1 || !isImplicitlyArrayed;
const int requiredInnerArraySize = arrayLoc * (useInnerSize ? internalInnerArraySize : 1);
const int requiredOuterArraySize = (internalArrayDims > 0) ? internalArraySizes->getDimSize(0) : 1;
TType clipCullType(EbtFloat, clipCullNode->getType().getQualifier().storage, 1);
clipCullType.getQualifier() = clipCullNode->getType().getQualifier();
// Create required array dimension
TArraySizes* arraySizes = new TArraySizes;
if (isImplicitlyArrayed)
arraySizes->addInnerSize(requiredOuterArraySize);
arraySizes->addInnerSize(requiredInnerArraySize);
clipCullType.transferArraySizes(arraySizes);
// Obtain symbol name: we'll use that for the symbol we introduce.
TIntermSymbol* sym = clipCullNode->getAsSymbolNode();
assert(sym != nullptr);
// We are moving the semantic ID from the layout location, so it is no longer needed or
// desired there.
clipCullType.getQualifier().layoutLocation = TQualifier::layoutLocationEnd;
// Create variable and track its linkage
*clipCullVar = makeInternalVariable(sym->getName().c_str(), clipCullType);
trackLinkage(**clipCullVar);
}
// Create symbol for the clip or cull variable.
TIntermSymbol* clipCullSym = intermediate.addSymbol(**clipCullVar);
// vector sizes:
const int clipCullVectorSize = clipCullSym->getType().getVectorSize();
// array sizes, or 1 if it's not an array:
const TArraySizes* const clipCullArraySizes = clipCullSym->getType().getArraySizes();
const int clipCullOuterArraySize = isImplicitlyArrayed ? clipCullArraySizes->getDimSize(0) : 1;
const int clipCullInnerArraySize = clipCullArraySizes->getDimSize(isImplicitlyArrayed ? 1 : 0);
// clipCullSym has got to be an array of scalar floats, per SPIR-V semantics.
// fixBuiltInIoType() should have handled that upstream.
assert(clipCullSym->getType().isArray());
assert(clipCullSym->getType().getVectorSize() == 1);
assert(clipCullSym->getType().getBasicType() == EbtFloat);
// We may be creating multiple sub-assignments. This is an aggregate to hold them.
// TODO: it would be possible to be clever sometimes and avoid the sequence node if not needed.
TIntermAggregate* assignList = nullptr;
// Holds individual component assignments as we make them.
TIntermTyped* clipCullAssign = nullptr;
// If the types are homomorphic, use a simple assign. No need to mess about with
// individual components.
if (clipCullSym->getType().isArray() == internalNode->getType().isArray() &&
clipCullInnerArraySize == internalInnerArraySize &&
clipCullOuterArraySize == internalOuterArraySize &&
clipCullVectorSize == internalVectorSize) {
if (isOutput)
clipCullAssign = intermediate.addAssign(op, clipCullSym, internalNode, loc);
else
clipCullAssign = intermediate.addAssign(op, internalNode, clipCullSym, loc);
assignList = intermediate.growAggregate(assignList, clipCullAssign);
assignList->setOperator(EOpSequence);
return assignList;
}
// We are going to copy each component of the internal (per array element if indicated) to sequential
// array elements of the clipCullSym. This tracks the lhs element we're writing to as we go along.
// We may be starting in the middle - e.g, for a non-zero semantic ID calculated above.
int clipCullInnerArrayPos = semanticOffset[semanticId];
int clipCullOuterArrayPos = 0;
// Lambda to add an index to a node, set the type of the result, and return the new node.
const auto addIndex = [this, &loc](TIntermTyped* node, int pos) -> TIntermTyped* {
const TType derefType(node->getType(), 0);
node = intermediate.addIndex(EOpIndexDirect, node, intermediate.addConstantUnion(pos, loc), loc);
node->setType(derefType);
return node;
};
// Loop through every component of every element of the internal, and copy to or from the matching external.
for (int internalOuterArrayPos = 0; internalOuterArrayPos < internalOuterArraySize; ++internalOuterArrayPos) {
for (int internalInnerArrayPos = 0; internalInnerArrayPos < internalInnerArraySize; ++internalInnerArrayPos) {
for (int internalComponent = 0; internalComponent < internalVectorSize; ++internalComponent) {
// clip/cull array member to read from / write to:
TIntermTyped* clipCullMember = clipCullSym;
// If implicitly arrayed, there is an outer array dimension involved
if (isImplicitlyArrayed)
clipCullMember = addIndex(clipCullMember, clipCullOuterArrayPos);
// Index into proper array position for clip cull member
clipCullMember = addIndex(clipCullMember, clipCullInnerArrayPos++);
// if needed, start over with next outer array slice.
if (isImplicitlyArrayed && clipCullInnerArrayPos >= clipCullInnerArraySize) {
clipCullInnerArrayPos = semanticOffset[semanticId];
++clipCullOuterArrayPos;
}
// internal member to read from / write to:
TIntermTyped* internalMember = internalNode;
// If internal node has outer array dimension, index appropriately.
if (internalArrayDims > 1)
internalMember = addIndex(internalMember, internalOuterArrayPos);
// If internal node has inner array dimension, index appropriately.
if (internalArrayDims > 0)
internalMember = addIndex(internalMember, internalInnerArrayPos);
// If internal node is a vector, extract the component of interest.
if (internalNode->getType().isVector())
internalMember = addIndex(internalMember, internalComponent);
// Create an assignment: output from internal to clip cull, or input from clip cull to internal.
if (isOutput)
clipCullAssign = intermediate.addAssign(op, clipCullMember, internalMember, loc);
else
clipCullAssign = intermediate.addAssign(op, internalMember, clipCullMember, loc);
// Track assignment in the sequence.
assignList = intermediate.growAggregate(assignList, clipCullAssign);
}
}
}
assert(assignList != nullptr);
assignList->setOperator(EOpSequence);
return assignList;
}
// Some simple source assignments need to be flattened to a sequence
// of AST assignments. Catch these and flatten, otherwise, pass through
// to intermediate.addAssign().
//
// Also, assignment to matrix swizzles requires multiple component assignments,
// intercept those as well.
TIntermTyped* HlslParseContext::handleAssign(const TSourceLoc& loc, TOperator op, TIntermTyped* left,
TIntermTyped* right)
{
if (left == nullptr || right == nullptr)
return nullptr;
// writing to opaques will require fixing transforms
if (left->getType().containsOpaque())
intermediate.setNeedsLegalization();
if (left->getAsOperator() && left->getAsOperator()->getOp() == EOpMatrixSwizzle)
return handleAssignToMatrixSwizzle(loc, op, left, right);
// Return true if the given node is an index operation into a split variable.
const auto indexesSplit = [this](const TIntermTyped* node) -> bool {
const TIntermBinary* binaryNode = node->getAsBinaryNode();
if (binaryNode == nullptr)
return false;
return (binaryNode->getOp() == EOpIndexDirect || binaryNode->getOp() == EOpIndexIndirect) &&
wasSplit(binaryNode->getLeft());
};
// Return symbol if node is symbol or index ref
const auto getSymbol = [](const TIntermTyped* node) -> const TIntermSymbol* {
const TIntermSymbol* symbolNode = node->getAsSymbolNode();
if (symbolNode != nullptr)
return symbolNode;
const TIntermBinary* binaryNode = node->getAsBinaryNode();
if (binaryNode != nullptr && (binaryNode->getOp() == EOpIndexDirect || binaryNode->getOp() == EOpIndexIndirect))
return binaryNode->getLeft()->getAsSymbolNode();
return nullptr;
};
// Return true if this stage assigns clip position with potentially inverted Y
const auto assignsClipPos = [this](const TIntermTyped* node) -> bool {
return node->getType().getQualifier().builtIn == EbvPosition &&
(language == EShLangVertex || language == EShLangGeometry || language == EShLangTessEvaluation);
};
const TIntermSymbol* leftSymbol = getSymbol(left);
const TIntermSymbol* rightSymbol = getSymbol(right);
const bool isSplitLeft = wasSplit(left) || indexesSplit(left);
const bool isSplitRight = wasSplit(right) || indexesSplit(right);
const bool isFlattenLeft = wasFlattened(leftSymbol);
const bool isFlattenRight = wasFlattened(rightSymbol);
// OK to do a single assign if neither side is split or flattened. Otherwise,
// fall through to a member-wise copy.
if (!isFlattenLeft && !isFlattenRight && !isSplitLeft && !isSplitRight) {
// Clip and cull distance requires more processing. See comment above assignClipCullDistance.
if (isClipOrCullDistance(left->getType()) || isClipOrCullDistance(right->getType())) {
const bool isOutput = isClipOrCullDistance(left->getType());
const int semanticId = (isOutput ? left : right)->getType().getQualifier().layoutLocation;
return assignClipCullDistance(loc, op, semanticId, left, right);
} else if (assignsClipPos(left)) {
// Position can require special handling: see comment above assignPosition
return assignPosition(loc, op, left, right);
} else if (left->getQualifier().builtIn == EbvSampleMask) {
// Certain builtins are required to be arrayed outputs in SPIR-V, but may internally be scalars
// in the shader. Copy the scalar RHS into the LHS array element zero, if that happens.
if (left->isArray() && !right->isArray()) {
const TType derefType(left->getType(), 0);
left = intermediate.addIndex(EOpIndexDirect, left, intermediate.addConstantUnion(0, loc), loc);
left->setType(derefType);
// Fall through to add assign.
}
}
return intermediate.addAssign(op, left, right, loc);
}
TIntermAggregate* assignList = nullptr;
const TVector<TVariable*>* leftVariables = nullptr;
const TVector<TVariable*>* rightVariables = nullptr;
// A temporary to store the right node's value, so we don't keep indirecting into it
// if it's not a simple symbol.
TVariable* rhsTempVar = nullptr;
// If the RHS is a simple symbol node, we'll copy it for each member.
TIntermSymbol* cloneSymNode = nullptr;
int memberCount = 0;
// Track how many items there are to copy.
if (left->getType().isStruct())
memberCount = (int)left->getType().getStruct()->size();
if (left->getType().isArray())
memberCount = left->getType().getCumulativeArraySize();
if (isFlattenLeft)
leftVariables = &flattenMap.find(leftSymbol->getId())->second.members;
if (isFlattenRight) {
rightVariables = &flattenMap.find(rightSymbol->getId())->second.members;
} else {
// The RHS is not flattened. There are several cases:
// 1. 1 item to copy: Use the RHS directly.
// 2. >1 item, simple symbol RHS: we'll create a new TIntermSymbol node for each, but no assign to temp.
// 3. >1 item, complex RHS: assign it to a new temp variable, and create a TIntermSymbol for each member.
if (memberCount <= 1) {
// case 1: we'll use the symbol directly below. Nothing to do.
} else {
if (right->getAsSymbolNode() != nullptr) {
// case 2: we'll copy the symbol per iteration below.
cloneSymNode = right->getAsSymbolNode();
} else {
// case 3: assign to a temp, and indirect into that.
rhsTempVar = makeInternalVariable("flattenTemp", right->getType());
rhsTempVar->getWritableType().getQualifier().makeTemporary();
TIntermTyped* noFlattenRHS = intermediate.addSymbol(*rhsTempVar, loc);
// Add this to the aggregate being built.
assignList = intermediate.growAggregate(assignList,
intermediate.addAssign(op, noFlattenRHS, right, loc), loc);
}
}
}
// When dealing with split arrayed structures of built-ins, the arrayness is moved to the extracted built-in
// variables, which is awkward when copying between split and unsplit structures. This variable tracks
// array indirections so they can be percolated from outer structs to inner variables.
std::vector <int> arrayElement;
TStorageQualifier leftStorage = left->getType().getQualifier().storage;
TStorageQualifier rightStorage = right->getType().getQualifier().storage;
int leftOffsetStart = findSubtreeOffset(*left);
int rightOffsetStart = findSubtreeOffset(*right);
int leftOffset = leftOffsetStart;
int rightOffset = rightOffsetStart;
const auto getMember = [&](bool isLeft, const TType& type, int member, TIntermTyped* splitNode, int splitMember,
bool flattened)
-> TIntermTyped * {
const bool split = isLeft ? isSplitLeft : isSplitRight;
TIntermTyped* subTree;
const TType derefType(type, member);
const TVariable* builtInVar = nullptr;
if ((flattened || split) && derefType.isBuiltIn()) {
auto splitPair = splitBuiltIns.find(HlslParseContext::tInterstageIoData(
derefType.getQualifier().builtIn,
isLeft ? leftStorage : rightStorage));
if (splitPair != splitBuiltIns.end())
builtInVar = splitPair->second;
}
if (builtInVar != nullptr) {
// copy from interstage IO built-in if needed
subTree = intermediate.addSymbol(*builtInVar);
if (subTree->getType().isArray()) {
// Arrayness of builtIn symbols isn't handled by the normal recursion:
// it's been extracted and moved to the built-in.
if (!arrayElement.empty()) {
const TType splitDerefType(subTree->getType(), arrayElement.back());
subTree = intermediate.addIndex(EOpIndexDirect, subTree,
intermediate.addConstantUnion(arrayElement.back(), loc), loc);
subTree->setType(splitDerefType);
} else if (splitNode->getAsOperator() != nullptr && (splitNode->getAsOperator()->getOp() == EOpIndexIndirect)) {
// This might also be a stage with arrayed outputs, in which case there's an index
// operation we should transfer to the output builtin.
const TType splitDerefType(subTree->getType(), 0);
subTree = intermediate.addIndex(splitNode->getAsOperator()->getOp(), subTree,
splitNode->getAsBinaryNode()->getRight(), loc);
subTree->setType(splitDerefType);
}
}
} else if (flattened && !shouldFlatten(derefType, isLeft ? leftStorage : rightStorage, false)) {
if (isLeft) {
// offset will cycle through variables for arrayed io
if (leftOffset >= static_cast<int>(leftVariables->size()))
leftOffset = leftOffsetStart;
subTree = intermediate.addSymbol(*(*leftVariables)[leftOffset++]);
} else {
// offset will cycle through variables for arrayed io
if (rightOffset >= static_cast<int>(rightVariables->size()))
rightOffset = rightOffsetStart;
subTree = intermediate.addSymbol(*(*rightVariables)[rightOffset++]);
}
// arrayed io
if (subTree->getType().isArray()) {
if (!arrayElement.empty()) {
const TType derefType(subTree->getType(), arrayElement.front());
subTree = intermediate.addIndex(EOpIndexDirect, subTree,
intermediate.addConstantUnion(arrayElement.front(), loc), loc);
subTree->setType(derefType);
} else {
// There's an index operation we should transfer to the output builtin.
assert(splitNode->getAsOperator() != nullptr &&
splitNode->getAsOperator()->getOp() == EOpIndexIndirect);
const TType splitDerefType(subTree->getType(), 0);
subTree = intermediate.addIndex(splitNode->getAsOperator()->getOp(), subTree,
splitNode->getAsBinaryNode()->getRight(), loc);
subTree->setType(splitDerefType);
}
}
} else {
// Index operator if it's an aggregate, else EOpNull
const TOperator accessOp = type.isArray() ? EOpIndexDirect
: type.isStruct() ? EOpIndexDirectStruct
: EOpNull;
if (accessOp == EOpNull) {
subTree = splitNode;
} else {
subTree = intermediate.addIndex(accessOp, splitNode, intermediate.addConstantUnion(splitMember, loc),
loc);
const TType splitDerefType(splitNode->getType(), splitMember);
subTree->setType(splitDerefType);
}
}
return subTree;
};
// Use the proper RHS node: a new symbol from a TVariable, copy
// of an TIntermSymbol node, or sometimes the right node directly.
right = rhsTempVar != nullptr ? intermediate.addSymbol(*rhsTempVar, loc) :
cloneSymNode != nullptr ? intermediate.addSymbol(*cloneSymNode) :
right;
// Cannot use auto here, because this is recursive, and auto can't work out the type without seeing the
// whole thing. So, we'll resort to an explicit type via std::function.
const std::function<void(TIntermTyped* left, TIntermTyped* right, TIntermTyped* splitLeft, TIntermTyped* splitRight,
bool topLevel)>
traverse = [&](TIntermTyped* left, TIntermTyped* right, TIntermTyped* splitLeft, TIntermTyped* splitRight,
bool topLevel) -> void {
// If we get here, we are assigning to or from a whole array or struct that must be
// flattened, so have to do member-by-member assignment:
bool shouldFlattenSubsetLeft = isFlattenLeft && shouldFlatten(left->getType(), leftStorage, topLevel);
bool shouldFlattenSubsetRight = isFlattenRight && shouldFlatten(right->getType(), rightStorage, topLevel);
if ((left->getType().isArray() || right->getType().isArray()) &&
(shouldFlattenSubsetLeft || isSplitLeft ||
shouldFlattenSubsetRight || isSplitRight)) {
const int elementsL = left->getType().isArray() ? left->getType().getOuterArraySize() : 1;
const int elementsR = right->getType().isArray() ? right->getType().getOuterArraySize() : 1;
// The arrays might not be the same size,
// e.g., if the size has been forced for EbvTessLevelInner/Outer.
const int elementsToCopy = std::min(elementsL, elementsR);
// array case
for (int element = 0; element < elementsToCopy; ++element) {
arrayElement.push_back(element);
// Add a new AST symbol node if we have a temp variable holding a complex RHS.
TIntermTyped* subLeft = getMember(true, left->getType(), element, left, element,
shouldFlattenSubsetLeft);
TIntermTyped* subRight = getMember(false, right->getType(), element, right, element,
shouldFlattenSubsetRight);
TIntermTyped* subSplitLeft = isSplitLeft ? getMember(true, left->getType(), element, splitLeft,
element, shouldFlattenSubsetLeft)
: subLeft;
TIntermTyped* subSplitRight = isSplitRight ? getMember(false, right->getType(), element, splitRight,
element, shouldFlattenSubsetRight)
: subRight;
traverse(subLeft, subRight, subSplitLeft, subSplitRight, false);
arrayElement.pop_back();
}
} else if (left->getType().isStruct() && (shouldFlattenSubsetLeft || isSplitLeft ||
shouldFlattenSubsetRight || isSplitRight)) {
// struct case
const auto& membersL = *left->getType().getStruct();
const auto& membersR = *right->getType().getStruct();
// These track the members in the split structures corresponding to the same in the unsplit structures,
// which we traverse in parallel.
int memberL = 0;
int memberR = 0;
// Handle empty structure assignment
if (int(membersL.size()) == 0 && int(membersR.size()) == 0)
assignList = intermediate.growAggregate(assignList, intermediate.addAssign(op, left, right, loc), loc);
for (int member = 0; member < int(membersL.size()); ++member) {
const TType& typeL = *membersL[member].type;
const TType& typeR = *membersR[member].type;
TIntermTyped* subLeft = getMember(true, left->getType(), member, left, member,
shouldFlattenSubsetLeft);
TIntermTyped* subRight = getMember(false, right->getType(), member, right, member,
shouldFlattenSubsetRight);
// If there is no splitting, use the same values to avoid inefficiency.
TIntermTyped* subSplitLeft = isSplitLeft ? getMember(true, left->getType(), member, splitLeft,
memberL, shouldFlattenSubsetLeft)
: subLeft;
TIntermTyped* subSplitRight = isSplitRight ? getMember(false, right->getType(), member, splitRight,
memberR, shouldFlattenSubsetRight)
: subRight;
if (isClipOrCullDistance(subSplitLeft->getType()) || isClipOrCullDistance(subSplitRight->getType())) {
// Clip and cull distance built-in assignment is complex in its own right, and is handled in
// a separate function dedicated to that task. See comment above assignClipCullDistance;
const bool isOutput = isClipOrCullDistance(subSplitLeft->getType());
// Since all clip/cull semantics boil down to the same built-in type, we need to get the
// semantic ID from the dereferenced type's layout location, to avoid an N-1 mapping.
const TType derefType((isOutput ? left : right)->getType(), member);
const int semanticId = derefType.getQualifier().layoutLocation;
TIntermAggregate* clipCullAssign = assignClipCullDistance(loc, op, semanticId,
subSplitLeft, subSplitRight);
assignList = intermediate.growAggregate(assignList, clipCullAssign, loc);
} else if (subSplitRight->getType().getQualifier().builtIn == EbvFragCoord) {
// FragCoord can require special handling: see comment above assignFromFragCoord
TIntermTyped* fragCoordAssign = assignFromFragCoord(loc, op, subSplitLeft, subSplitRight);
assignList = intermediate.growAggregate(assignList, fragCoordAssign, loc);
} else if (assignsClipPos(subSplitLeft)) {
// Position can require special handling: see comment above assignPosition
TIntermTyped* positionAssign = assignPosition(loc, op, subSplitLeft, subSplitRight);
assignList = intermediate.growAggregate(assignList, positionAssign, loc);
} else if (!shouldFlattenSubsetLeft && !shouldFlattenSubsetRight &&
!typeL.containsBuiltIn() && !typeR.containsBuiltIn()) {
// If this is the final flattening (no nested types below to flatten)
// we'll copy the member, else recurse into the type hierarchy.
// However, if splitting the struct, that means we can copy a whole
// subtree here IFF it does not itself contain any interstage built-in
// IO variables, so we only have to recurse into it if there's something
// for splitting to do. That can save a lot of AST verbosity for
// a bunch of memberwise copies.
assignList = intermediate.growAggregate(assignList,
intermediate.addAssign(op, subSplitLeft, subSplitRight, loc),
loc);
} else {
traverse(subLeft, subRight, subSplitLeft, subSplitRight, false);
}
memberL += (typeL.isBuiltIn() ? 0 : 1);
memberR += (typeR.isBuiltIn() ? 0 : 1);
}
} else {
// Member copy
assignList = intermediate.growAggregate(assignList, intermediate.addAssign(op, left, right, loc), loc);
}
};
TIntermTyped* splitLeft = left;
TIntermTyped* splitRight = right;
// If either left or right was a split structure, we must read or write it, but still have to
// parallel-recurse through the unsplit structure to identify the built-in IO vars.
// The left can be either a symbol, or an index into a symbol (e.g, array reference)
if (isSplitLeft) {
if (indexesSplit(left)) {
// Index case: Refer to the indexed symbol, if the left is an index operator.
const TIntermSymbol* symNode = left->getAsBinaryNode()->getLeft()->getAsSymbolNode();
TIntermTyped* splitLeftNonIo = intermediate.addSymbol(*getSplitNonIoVar(symNode->getId()), loc);
splitLeft = intermediate.addIndex(left->getAsBinaryNode()->getOp(), splitLeftNonIo,
left->getAsBinaryNode()->getRight(), loc);
const TType derefType(splitLeftNonIo->getType(), 0);
splitLeft->setType(derefType);
} else {
// Symbol case: otherwise, if not indexed, we have the symbol directly.
const TIntermSymbol* symNode = left->getAsSymbolNode();
splitLeft = intermediate.addSymbol(*getSplitNonIoVar(symNode->getId()), loc);
}
}
if (isSplitRight)
splitRight = intermediate.addSymbol(*getSplitNonIoVar(right->getAsSymbolNode()->getId()), loc);
// This makes the whole assignment, recursing through subtypes as needed.
traverse(left, right, splitLeft, splitRight, true);
assert(assignList != nullptr);
assignList->setOperator(EOpSequence);
return assignList;
}
// An assignment to matrix swizzle must be decomposed into individual assignments.
// These must be selected component-wise from the RHS and stored component-wise
// into the LHS.
TIntermTyped* HlslParseContext::handleAssignToMatrixSwizzle(const TSourceLoc& loc, TOperator op, TIntermTyped* left,
TIntermTyped* right)
{
assert(left->getAsOperator() && left->getAsOperator()->getOp() == EOpMatrixSwizzle);
if (op != EOpAssign)
error(loc, "only simple assignment to non-simple matrix swizzle is supported", "assign", "");
// isolate the matrix and swizzle nodes
TIntermTyped* matrix = left->getAsBinaryNode()->getLeft()->getAsTyped();
const TIntermSequence& swizzle = left->getAsBinaryNode()->getRight()->getAsAggregate()->getSequence();
// if the RHS isn't already a simple vector, let's store into one
TIntermSymbol* vector = right->getAsSymbolNode();
TIntermTyped* vectorAssign = nullptr;
if (vector == nullptr) {
// create a new intermediate vector variable to assign to
TType vectorType(matrix->getBasicType(), EvqTemporary, matrix->getQualifier().precision, (int)swizzle.size()/2);
vector = intermediate.addSymbol(*makeInternalVariable("intermVec", vectorType), loc);
// assign the right to the new vector
vectorAssign = handleAssign(loc, op, vector, right);
}
// Assign the vector components to the matrix components.
// Store this as a sequence, so a single aggregate node represents this
// entire operation.
TIntermAggregate* result = intermediate.makeAggregate(vectorAssign);
TType columnType(matrix->getType(), 0);
TType componentType(columnType, 0);
TType indexType(EbtInt);
for (int i = 0; i < (int)swizzle.size(); i += 2) {
// the right component, single index into the RHS vector
TIntermTyped* rightComp = intermediate.addIndex(EOpIndexDirect, vector,
intermediate.addConstantUnion(i/2, loc), loc);
// the left component, double index into the LHS matrix
TIntermTyped* leftComp = intermediate.addIndex(EOpIndexDirect, matrix,
intermediate.addConstantUnion(swizzle[i]->getAsConstantUnion()->getConstArray(),
indexType, loc),
loc);
leftComp->setType(columnType);
leftComp = intermediate.addIndex(EOpIndexDirect, leftComp,
intermediate.addConstantUnion(swizzle[i+1]->getAsConstantUnion()->getConstArray(),
indexType, loc),
loc);
leftComp->setType(componentType);
// Add the assignment to the aggregate
result = intermediate.growAggregate(result, intermediate.addAssign(op, leftComp, rightComp, loc));
}
result->setOp(EOpSequence);
return result;
}
//
// HLSL atomic operations have slightly different arguments than
// GLSL/AST/SPIRV. The semantics are converted below in decomposeIntrinsic.
// This provides the post-decomposition equivalent opcode.
//
TOperator HlslParseContext::mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage)
{
switch (op) {
case EOpInterlockedAdd: return isImage ? EOpImageAtomicAdd : EOpAtomicAdd;
case EOpInterlockedAnd: return isImage ? EOpImageAtomicAnd : EOpAtomicAnd;
case EOpInterlockedCompareExchange: return isImage ? EOpImageAtomicCompSwap : EOpAtomicCompSwap;
case EOpInterlockedMax: return isImage ? EOpImageAtomicMax : EOpAtomicMax;
case EOpInterlockedMin: return isImage ? EOpImageAtomicMin : EOpAtomicMin;
case EOpInterlockedOr: return isImage ? EOpImageAtomicOr : EOpAtomicOr;
case EOpInterlockedXor: return isImage ? EOpImageAtomicXor : EOpAtomicXor;
case EOpInterlockedExchange: return isImage ? EOpImageAtomicExchange : EOpAtomicExchange;
case EOpInterlockedCompareStore: // TODO: ...
default:
error(loc, "unknown atomic operation", "unknown op", "");
return EOpNull;
}
}
//
// Create a combined sampler/texture from separate sampler and texture.
//
TIntermAggregate* HlslParseContext::handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex,
TIntermTyped* argSampler)
{
TIntermAggregate* txcombine = new TIntermAggregate(EOpConstructTextureSampler);
txcombine->getSequence().push_back(argTex);
txcombine->getSequence().push_back(argSampler);
TSampler samplerType = argTex->getType().getSampler();
samplerType.combined = true;
// TODO:
// This block exists until the spec no longer requires shadow modes on texture objects.
// It can be deleted after that, along with the shadowTextureVariant member.
{
const bool shadowMode = argSampler->getType().getSampler().shadow;
TIntermSymbol* texSymbol = argTex->getAsSymbolNode();
if (texSymbol == nullptr)
texSymbol = argTex->getAsBinaryNode()->getLeft()->getAsSymbolNode();
if (texSymbol == nullptr) {
error(loc, "unable to find texture symbol", "", "");
return nullptr;
}
// This forces the texture's shadow state to be the sampler's
// shadow state. This depends on downstream optimization to
// DCE one variant in [shadow, nonshadow] if both are present,
// or the SPIR-V module would be invalid.
long long newId = texSymbol->getId();
// Check to see if this texture has been given a shadow mode already.
// If so, look up the one we already have.
const auto textureShadowEntry = textureShadowVariant.find(texSymbol->getId());
if (textureShadowEntry != textureShadowVariant.end())
newId = textureShadowEntry->second->get(shadowMode);
else
textureShadowVariant[texSymbol->getId()] = NewPoolObject(tShadowTextureSymbols(), 1);
// Sometimes we have to create another symbol (if this texture has been seen before,
// and we haven't created the form for this shadow mode).
if (newId == -1) {
TType texType;
texType.shallowCopy(argTex->getType());
texType.getSampler().shadow = shadowMode; // set appropriate shadow mode.
globalQualifierFix(loc, texType.getQualifier());
TVariable* newTexture = makeInternalVariable(texSymbol->getName(), texType);
trackLinkage(*newTexture);
newId = newTexture->getUniqueId();
}
assert(newId != -1);
if (textureShadowVariant.find(newId) == textureShadowVariant.end())
textureShadowVariant[newId] = textureShadowVariant[texSymbol->getId()];
textureShadowVariant[newId]->set(shadowMode, newId);
// Remember this shadow mode in the texture and the merged type.
argTex->getWritableType().getSampler().shadow = shadowMode;
samplerType.shadow = shadowMode;
texSymbol->switchId(newId);
}
txcombine->setType(TType(samplerType, EvqTemporary));
txcombine->setLoc(loc);
return txcombine;
}
// Return true if this a buffer type that has an associated counter buffer.
bool HlslParseContext::hasStructBuffCounter(const TType& type) const
{
switch (type.getQualifier().declaredBuiltIn) {
case EbvAppendConsume: // fall through...
case EbvRWStructuredBuffer: // ...
return true;
default:
return false; // the other structuredbuffer types do not have a counter.
}
}
void HlslParseContext::counterBufferType(const TSourceLoc& loc, TType& type)
{
// Counter type
TType* counterType = new TType(EbtUint, EvqBuffer);
counterType->setFieldName(intermediate.implicitCounterName);
TTypeList* blockStruct = new TTypeList;
TTypeLoc member = { counterType, loc };
blockStruct->push_back(member);
TType blockType(blockStruct, "", counterType->getQualifier());
blockType.getQualifier().storage = EvqBuffer;
type.shallowCopy(blockType);
shareStructBufferType(type);
}
// declare counter for a structured buffer type
void HlslParseContext::declareStructBufferCounter(const TSourceLoc& loc, const TType& bufferType, const TString& name)
{
// Bail out if not a struct buffer
if (! isStructBufferType(bufferType))
return;
if (! hasStructBuffCounter(bufferType))
return;
TType blockType;
counterBufferType(loc, blockType);
TString* blockName = NewPoolTString(intermediate.addCounterBufferName(name).c_str());
// Counter buffer is not yet in use
structBufferCounter[*blockName] = false;
shareStructBufferType(blockType);
declareBlock(loc, blockType, blockName);
}
// return the counter that goes with a given structuredbuffer
TIntermTyped* HlslParseContext::getStructBufferCounter(const TSourceLoc& loc, TIntermTyped* buffer)
{
// Bail out if not a struct buffer
if (buffer == nullptr || ! isStructBufferType(buffer->getType()))
return nullptr;
const TString counterBlockName(intermediate.addCounterBufferName(buffer->getAsSymbolNode()->getName()));
// Mark the counter as being used
structBufferCounter[counterBlockName] = true;
TIntermTyped* counterVar = handleVariable(loc, &counterBlockName); // find the block structure
TIntermTyped* index = intermediate.addConstantUnion(0, loc); // index to counter inside block struct
TIntermTyped* counterMember = intermediate.addIndex(EOpIndexDirectStruct, counterVar, index, loc);
counterMember->setType(TType(EbtUint));
return counterMember;
}
//
// Decompose structure buffer methods into AST
//
void HlslParseContext::decomposeStructBufferMethods(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
{
if (node == nullptr || node->getAsOperator() == nullptr || arguments == nullptr)
return;
const TOperator op = node->getAsOperator()->getOp();
TIntermAggregate* argAggregate = arguments->getAsAggregate();
// Buffer is the object upon which method is called, so always arg 0
TIntermTyped* bufferObj = nullptr;
// The parameters can be an aggregate, or just a the object as a symbol if there are no fn params.
if (argAggregate) {
if (argAggregate->getSequence().empty())
return;
if (argAggregate->getSequence()[0])
bufferObj = argAggregate->getSequence()[0]->getAsTyped();
} else {
bufferObj = arguments->getAsSymbolNode();
}
if (bufferObj == nullptr || bufferObj->getAsSymbolNode() == nullptr)
return;
// Some methods require a hidden internal counter, obtained via getStructBufferCounter().
// This lambda adds something to it and returns the old value.
const auto incDecCounter = [&](int incval) -> TIntermTyped* {
TIntermTyped* incrementValue = intermediate.addConstantUnion(static_cast<unsigned int>(incval), loc, true);
TIntermTyped* counter = getStructBufferCounter(loc, bufferObj); // obtain the counter member
if (counter == nullptr)
return nullptr;
TIntermAggregate* counterIncrement = new TIntermAggregate(EOpAtomicAdd);
counterIncrement->setType(TType(EbtUint, EvqTemporary));
counterIncrement->setLoc(loc);
counterIncrement->getSequence().push_back(counter);
counterIncrement->getSequence().push_back(incrementValue);
return counterIncrement;
};
// Index to obtain the runtime sized array out of the buffer.
TIntermTyped* argArray = indexStructBufferContent(loc, bufferObj);
if (argArray == nullptr)
return; // It might not be a struct buffer method.
switch (op) {
case EOpMethodLoad:
{
TIntermTyped* argIndex = makeIntegerIndex(argAggregate->getSequence()[1]->getAsTyped()); // index
const TType& bufferType = bufferObj->getType();
const TBuiltInVariable builtInType = bufferType.getQualifier().declaredBuiltIn;
// Byte address buffers index in bytes (only multiples of 4 permitted... not so much a byte address
// buffer then, but that's what it calls itself.
const bool isByteAddressBuffer = (builtInType == EbvByteAddressBuffer ||
builtInType == EbvRWByteAddressBuffer);
if (isByteAddressBuffer)
argIndex = intermediate.addBinaryNode(EOpRightShift, argIndex,
intermediate.addConstantUnion(2, loc, true),
loc, TType(EbtInt));
// Index into the array to find the item being loaded.
const TOperator idxOp = (argIndex->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
node = intermediate.addIndex(idxOp, argArray, argIndex, loc);
const TType derefType(argArray->getType(), 0);
node->setType(derefType);
}
break;
case EOpMethodLoad2:
case EOpMethodLoad3:
case EOpMethodLoad4:
{
TIntermTyped* argIndex = makeIntegerIndex(argAggregate->getSequence()[1]->getAsTyped()); // index
TOperator constructOp = EOpNull;
int size = 0;
switch (op) {
case EOpMethodLoad2: size = 2; constructOp = EOpConstructVec2; break;
case EOpMethodLoad3: size = 3; constructOp = EOpConstructVec3; break;
case EOpMethodLoad4: size = 4; constructOp = EOpConstructVec4; break;
default: assert(0);
}
TIntermTyped* body = nullptr;
// First, we'll store the address in a variable to avoid multiple shifts
// (we must convert the byte address to an item address)
TIntermTyped* byteAddrIdx = intermediate.addBinaryNode(EOpRightShift, argIndex,
intermediate.addConstantUnion(2, loc, true),
loc, TType(EbtInt));
TVariable* byteAddrSym = makeInternalVariable("byteAddrTemp", TType(EbtInt, EvqTemporary));
TIntermTyped* byteAddrIdxVar = intermediate.addSymbol(*byteAddrSym, loc);
body = intermediate.growAggregate(body, intermediate.addAssign(EOpAssign, byteAddrIdxVar, byteAddrIdx, loc));
TIntermTyped* vec = nullptr;
// These are only valid on (rw)byteaddressbuffers, so we can always perform the >>2
// address conversion.
for (int idx=0; idx<size; ++idx) {
TIntermTyped* offsetIdx = byteAddrIdxVar;
// add index offset
if (idx != 0)
offsetIdx = intermediate.addBinaryNode(EOpAdd, offsetIdx,
intermediate.addConstantUnion(idx, loc, true),
loc, TType(EbtInt));
const TOperator idxOp = (offsetIdx->getQualifier().storage == EvqConst) ? EOpIndexDirect
: EOpIndexIndirect;
TIntermTyped* indexVal = intermediate.addIndex(idxOp, argArray, offsetIdx, loc);
TType derefType(argArray->getType(), 0);
derefType.getQualifier().makeTemporary();
indexVal->setType(derefType);
vec = intermediate.growAggregate(vec, indexVal);
}
vec->setType(TType(argArray->getBasicType(), EvqTemporary, size));
vec->getAsAggregate()->setOperator(constructOp);
body = intermediate.growAggregate(body, vec);
body->setType(vec->getType());
body->getAsAggregate()->setOperator(EOpSequence);
node = body;
}
break;
case EOpMethodStore:
case EOpMethodStore2:
case EOpMethodStore3:
case EOpMethodStore4:
{
TIntermTyped* argIndex = makeIntegerIndex(argAggregate->getSequence()[1]->getAsTyped()); // index
TIntermTyped* argValue = argAggregate->getSequence()[2]->getAsTyped(); // value
// Index into the array to find the item being loaded.
// Byte address buffers index in bytes (only multiples of 4 permitted... not so much a byte address
// buffer then, but that's what it calls itself).
int size = 0;
switch (op) {
case EOpMethodStore: size = 1; break;
case EOpMethodStore2: size = 2; break;
case EOpMethodStore3: size = 3; break;
case EOpMethodStore4: size = 4; break;
default: assert(0);
}
TIntermAggregate* body = nullptr;
// First, we'll store the address in a variable to avoid multiple shifts
// (we must convert the byte address to an item address)
TIntermTyped* byteAddrIdx = intermediate.addBinaryNode(EOpRightShift, argIndex,
intermediate.addConstantUnion(2, loc, true), loc, TType(EbtInt));
TVariable* byteAddrSym = makeInternalVariable("byteAddrTemp", TType(EbtInt, EvqTemporary));
TIntermTyped* byteAddrIdxVar = intermediate.addSymbol(*byteAddrSym, loc);
body = intermediate.growAggregate(body, intermediate.addAssign(EOpAssign, byteAddrIdxVar, byteAddrIdx, loc));
for (int idx=0; idx<size; ++idx) {
TIntermTyped* offsetIdx = byteAddrIdxVar;
TIntermTyped* idxConst = intermediate.addConstantUnion(idx, loc, true);
// add index offset
if (idx != 0)
offsetIdx = intermediate.addBinaryNode(EOpAdd, offsetIdx, idxConst, loc, TType(EbtInt));
const TOperator idxOp = (offsetIdx->getQualifier().storage == EvqConst) ? EOpIndexDirect
: EOpIndexIndirect;
TIntermTyped* lValue = intermediate.addIndex(idxOp, argArray, offsetIdx, loc);
const TType derefType(argArray->getType(), 0);
lValue->setType(derefType);
TIntermTyped* rValue;
if (size == 1) {
rValue = argValue;
} else {
rValue = intermediate.addIndex(EOpIndexDirect, argValue, idxConst, loc);
const TType indexType(argValue->getType(), 0);
rValue->setType(indexType);
}
TIntermTyped* assign = intermediate.addAssign(EOpAssign, lValue, rValue, loc);
body = intermediate.growAggregate(body, assign);
}
body->setOperator(EOpSequence);
node = body;
}
break;
case EOpMethodGetDimensions:
{
const int numArgs = (int)argAggregate->getSequence().size();
TIntermTyped* argNumItems = argAggregate->getSequence()[1]->getAsTyped(); // out num items
TIntermTyped* argStride = numArgs > 2 ? argAggregate->getSequence()[2]->getAsTyped() : nullptr; // out stride
TIntermAggregate* body = nullptr;
// Length output:
if (argArray->getType().isSizedArray()) {
const int length = argArray->getType().getOuterArraySize();
TIntermTyped* assign = intermediate.addAssign(EOpAssign, argNumItems,
intermediate.addConstantUnion(length, loc, true), loc);
body = intermediate.growAggregate(body, assign, loc);
} else {
TIntermTyped* lengthCall = intermediate.addBuiltInFunctionCall(loc, EOpArrayLength, true, argArray,
argNumItems->getType());
TIntermTyped* assign = intermediate.addAssign(EOpAssign, argNumItems, lengthCall, loc);
body = intermediate.growAggregate(body, assign, loc);
}
// Stride output:
if (argStride != nullptr) {
int size;
int stride;
intermediate.getMemberAlignment(argArray->getType(), size, stride, argArray->getType().getQualifier().layoutPacking,
argArray->getType().getQualifier().layoutMatrix == ElmRowMajor);
TIntermTyped* assign = intermediate.addAssign(EOpAssign, argStride,
intermediate.addConstantUnion(stride, loc, true), loc);
body = intermediate.growAggregate(body, assign);
}
body->setOperator(EOpSequence);
node = body;
}
break;
case EOpInterlockedAdd:
case EOpInterlockedAnd:
case EOpInterlockedExchange:
case EOpInterlockedMax:
case EOpInterlockedMin:
case EOpInterlockedOr:
case EOpInterlockedXor:
case EOpInterlockedCompareExchange:
case EOpInterlockedCompareStore:
{
// We'll replace the first argument with the block dereference, and let
// downstream decomposition handle the rest.
TIntermSequence& sequence = argAggregate->getSequence();
TIntermTyped* argIndex = makeIntegerIndex(sequence[1]->getAsTyped()); // index
argIndex = intermediate.addBinaryNode(EOpRightShift, argIndex, intermediate.addConstantUnion(2, loc, true),
loc, TType(EbtInt));
const TOperator idxOp = (argIndex->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
TIntermTyped* element = intermediate.addIndex(idxOp, argArray, argIndex, loc);
const TType derefType(argArray->getType(), 0);
element->setType(derefType);
// Replace the numeric byte offset parameter with array reference.
sequence[1] = element;
sequence.erase(sequence.begin(), sequence.begin()+1);
}
break;
case EOpMethodIncrementCounter:
{
node = incDecCounter(1);
break;
}
case EOpMethodDecrementCounter:
{
TIntermTyped* preIncValue = incDecCounter(-1); // result is original value
node = intermediate.addBinaryNode(EOpAdd, preIncValue, intermediate.addConstantUnion(-1, loc, true), loc,
preIncValue->getType());
break;
}
case EOpMethodAppend:
{
TIntermTyped* oldCounter = incDecCounter(1);
TIntermTyped* lValue = intermediate.addIndex(EOpIndexIndirect, argArray, oldCounter, loc);
TIntermTyped* rValue = argAggregate->getSequence()[1]->getAsTyped();
const TType derefType(argArray->getType(), 0);
lValue->setType(derefType);
node = intermediate.addAssign(EOpAssign, lValue, rValue, loc);
break;
}
case EOpMethodConsume:
{
TIntermTyped* oldCounter = incDecCounter(-1);
TIntermTyped* newCounter = intermediate.addBinaryNode(EOpAdd, oldCounter,
intermediate.addConstantUnion(-1, loc, true), loc,
oldCounter->getType());
node = intermediate.addIndex(EOpIndexIndirect, argArray, newCounter, loc);
const TType derefType(argArray->getType(), 0);
node->setType(derefType);
break;
}
default:
break; // most pass through unchanged
}
}
// Create array of standard sample positions for given sample count.
// TODO: remove when a real method to query sample pos exists in SPIR-V.
TIntermConstantUnion* HlslParseContext::getSamplePosArray(int count)
{
struct tSamplePos { float x, y; };
static const tSamplePos pos1[] = {
{ 0.0/16.0, 0.0/16.0 },
};
// standard sample positions for 2, 4, 8, and 16 samples.
static const tSamplePos pos2[] = {
{ 4.0/16.0, 4.0/16.0 }, {-4.0/16.0, -4.0/16.0 },
};
static const tSamplePos pos4[] = {
{-2.0/16.0, -6.0/16.0 }, { 6.0/16.0, -2.0/16.0 }, {-6.0/16.0, 2.0/16.0 }, { 2.0/16.0, 6.0/16.0 },
};
static const tSamplePos pos8[] = {
{ 1.0/16.0, -3.0/16.0 }, {-1.0/16.0, 3.0/16.0 }, { 5.0/16.0, 1.0/16.0 }, {-3.0/16.0, -5.0/16.0 },
{-5.0/16.0, 5.0/16.0 }, {-7.0/16.0, -1.0/16.0 }, { 3.0/16.0, 7.0/16.0 }, { 7.0/16.0, -7.0/16.0 },
};
static const tSamplePos pos16[] = {
{ 1.0/16.0, 1.0/16.0 }, {-1.0/16.0, -3.0/16.0 }, {-3.0/16.0, 2.0/16.0 }, { 4.0/16.0, -1.0/16.0 },
{-5.0/16.0, -2.0/16.0 }, { 2.0/16.0, 5.0/16.0 }, { 5.0/16.0, 3.0/16.0 }, { 3.0/16.0, -5.0/16.0 },
{-2.0/16.0, 6.0/16.0 }, { 0.0/16.0, -7.0/16.0 }, {-4.0/16.0, -6.0/16.0 }, {-6.0/16.0, 4.0/16.0 },
{-8.0/16.0, 0.0/16.0 }, { 7.0/16.0, -4.0/16.0 }, { 6.0/16.0, 7.0/16.0 }, {-7.0/16.0, -8.0/16.0 },
};
const tSamplePos* sampleLoc = nullptr;
int numSamples = count;
switch (count) {
case 2: sampleLoc = pos2; break;
case 4: sampleLoc = pos4; break;
case 8: sampleLoc = pos8; break;
case 16: sampleLoc = pos16; break;
default:
sampleLoc = pos1;
numSamples = 1;
}
TConstUnionArray* values = new TConstUnionArray(numSamples*2);
for (int pos=0; pos<count; ++pos) {
TConstUnion x, y;
x.setDConst(sampleLoc[pos].x);
y.setDConst(sampleLoc[pos].y);
(*values)[pos*2+0] = x;
(*values)[pos*2+1] = y;
}
TType retType(EbtFloat, EvqConst, 2);
if (numSamples != 1) {
TArraySizes* arraySizes = new TArraySizes;
arraySizes->addInnerSize(numSamples);
retType.transferArraySizes(arraySizes);
}
return new TIntermConstantUnion(*values, retType);
}
//
// Decompose DX9 and DX10 sample intrinsics & object methods into AST
//
void HlslParseContext::decomposeSampleMethods(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
{
if (node == nullptr || !node->getAsOperator())
return;
// Sampler return must always be a vec4, but we can construct a shorter vector or a structure from it.
const auto convertReturn = [&loc, &node, this](TIntermTyped* result, const TSampler& sampler) -> TIntermTyped* {
result->setType(TType(node->getType().getBasicType(), EvqTemporary, node->getVectorSize()));
TIntermTyped* convertedResult = nullptr;
TType retType;
getTextureReturnType(sampler, retType);
if (retType.isStruct()) {
// For type convenience, conversionAggregate points to the convertedResult (we know it's an aggregate here)
TIntermAggregate* conversionAggregate = new TIntermAggregate;
convertedResult = conversionAggregate;
// Convert vector output to return structure. We will need a temp symbol to copy the results to.
TVariable* structVar = makeInternalVariable("@sampleStructTemp", retType);
// We also need a temp symbol to hold the result of the texture. We don't want to re-fetch the
// sample each time we'll index into the result, so we'll copy to this, and index into the copy.
TVariable* sampleShadow = makeInternalVariable("@sampleResultShadow", result->getType());
// Initial copy from texture to our sample result shadow.
TIntermTyped* shadowCopy = intermediate.addAssign(EOpAssign, intermediate.addSymbol(*sampleShadow, loc),
result, loc);
conversionAggregate->getSequence().push_back(shadowCopy);
unsigned vec4Pos = 0;
for (unsigned m = 0; m < unsigned(retType.getStruct()->size()); ++m) {
const TType memberType(retType, m); // dereferenced type of the member we're about to assign.
// Check for bad struct members. This should have been caught upstream. Complain, because
// wwe don't know what to do with it. This algorithm could be generalized to handle
// other things, e.g, sub-structures, but HLSL doesn't allow them.
if (!memberType.isVector() && !memberType.isScalar()) {
error(loc, "expected: scalar or vector type in texture structure", "", "");
return nullptr;
}
// Index into the struct variable to find the member to assign.
TIntermTyped* structMember = intermediate.addIndex(EOpIndexDirectStruct,
intermediate.addSymbol(*structVar, loc),
intermediate.addConstantUnion(m, loc), loc);
structMember->setType(memberType);
// Assign each component of (possible) vector in struct member.
for (int component = 0; component < memberType.getVectorSize(); ++component) {
TIntermTyped* vec4Member = intermediate.addIndex(EOpIndexDirect,
intermediate.addSymbol(*sampleShadow, loc),
intermediate.addConstantUnion(vec4Pos++, loc), loc);
vec4Member->setType(TType(memberType.getBasicType(), EvqTemporary, 1));
TIntermTyped* memberAssign = nullptr;
if (memberType.isVector()) {
// Vector member: we need to create an access chain to the vector component.
TIntermTyped* structVecComponent = intermediate.addIndex(EOpIndexDirect, structMember,
intermediate.addConstantUnion(component, loc), loc);
memberAssign = intermediate.addAssign(EOpAssign, structVecComponent, vec4Member, loc);
} else {
// Scalar member: we can assign to it directly.
memberAssign = intermediate.addAssign(EOpAssign, structMember, vec4Member, loc);
}
conversionAggregate->getSequence().push_back(memberAssign);
}
}
// Add completed variable so the expression results in the whole struct value we just built.
conversionAggregate->getSequence().push_back(intermediate.addSymbol(*structVar, loc));
// Make it a sequence.
intermediate.setAggregateOperator(conversionAggregate, EOpSequence, retType, loc);
} else {
// vector clamp the output if template vector type is smaller than sample result.
if (retType.getVectorSize() < node->getVectorSize()) {
// Too many components. Construct shorter vector from it.
const TOperator op = intermediate.mapTypeToConstructorOp(retType);
convertedResult = constructBuiltIn(retType, op, result, loc, false);
} else {
// Enough components. Use directly.
convertedResult = result;
}
}
convertedResult->setLoc(loc);
return convertedResult;
};
const TOperator op = node->getAsOperator()->getOp();
const TIntermAggregate* argAggregate = arguments ? arguments->getAsAggregate() : nullptr;
// Bail out if not a sampler method.
// Note though this is odd to do before checking the op, because the op
// could be something that takes the arguments, and the function in question
// takes the result of the op. So, this is not the final word.
if (arguments != nullptr) {
if (argAggregate == nullptr) {
if (arguments->getAsTyped()->getBasicType() != EbtSampler)
return;
} else {
if (argAggregate->getSequence().size() == 0 ||
argAggregate->getSequence()[0] == nullptr ||
argAggregate->getSequence()[0]->getAsTyped()->getBasicType() != EbtSampler)
return;
}
}
switch (op) {
// **** DX9 intrinsics: ****
case EOpTexture:
{
// Texture with ddx & ddy is really gradient form in HLSL
if (argAggregate->getSequence().size() == 4)
node->getAsAggregate()->setOperator(EOpTextureGrad);
break;
}
case EOpTextureLod: //is almost EOpTextureBias (only args & operations are different)
{
TIntermTyped *argSamp = argAggregate->getSequence()[0]->getAsTyped(); // sampler
TIntermTyped *argCoord = argAggregate->getSequence()[1]->getAsTyped(); // coord
assert(argCoord->getVectorSize() == 4);
TIntermTyped *w = intermediate.addConstantUnion(3, loc, true);
TIntermTyped *argLod = intermediate.addIndex(EOpIndexDirect, argCoord, w, loc);
TOperator constructOp = EOpNull;
const TSampler &sampler = argSamp->getType().getSampler();
int coordSize = 0;
switch (sampler.dim)
{
case Esd1D: constructOp = EOpConstructFloat; coordSize = 1; break; // 1D
case Esd2D: constructOp = EOpConstructVec2; coordSize = 2; break; // 2D
case Esd3D: constructOp = EOpConstructVec3; coordSize = 3; break; // 3D
case EsdCube: constructOp = EOpConstructVec3; coordSize = 3; break; // also 3D
default:
error(loc, "unhandled DX9 texture LoD dimension", "", "");
break;
}
TIntermAggregate *constructCoord = new TIntermAggregate(constructOp);
constructCoord->getSequence().push_back(argCoord);
constructCoord->setLoc(loc);
constructCoord->setType(TType(argCoord->getBasicType(), EvqTemporary, coordSize));
TIntermAggregate *tex = new TIntermAggregate(EOpTextureLod);
tex->getSequence().push_back(argSamp); // sampler
tex->getSequence().push_back(constructCoord); // coordinate
tex->getSequence().push_back(argLod); // lod
node = convertReturn(tex, sampler);
break;
}
case EOpTextureBias:
{
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // sampler
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // coord
// HLSL puts bias in W component of coordinate. We extract it and add it to
// the argument list, instead
TIntermTyped* w = intermediate.addConstantUnion(3, loc, true);
TIntermTyped* bias = intermediate.addIndex(EOpIndexDirect, arg1, w, loc);
TOperator constructOp = EOpNull;
const TSampler& sampler = arg0->getType().getSampler();
switch (sampler.dim) {
case Esd1D: constructOp = EOpConstructFloat; break; // 1D
case Esd2D: constructOp = EOpConstructVec2; break; // 2D
case Esd3D: constructOp = EOpConstructVec3; break; // 3D
case EsdCube: constructOp = EOpConstructVec3; break; // also 3D
default:
error(loc, "unhandled DX9 texture bias dimension", "", "");
break;
}
TIntermAggregate* constructCoord = new TIntermAggregate(constructOp);
constructCoord->getSequence().push_back(arg1);
constructCoord->setLoc(loc);
// The input vector should never be less than 2, since there's always a bias.
// The max is for safety, and should be a no-op.
constructCoord->setType(TType(arg1->getBasicType(), EvqTemporary, std::max(arg1->getVectorSize() - 1, 0)));
TIntermAggregate* tex = new TIntermAggregate(EOpTexture);
tex->getSequence().push_back(arg0); // sampler
tex->getSequence().push_back(constructCoord); // coordinate
tex->getSequence().push_back(bias); // bias
node = convertReturn(tex, sampler);
break;
}
// **** DX10 methods: ****
case EOpMethodSample: // fall through
case EOpMethodSampleBias: // ...
{
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
TIntermTyped* argBias = nullptr;
TIntermTyped* argOffset = nullptr;
const TSampler& sampler = argTex->getType().getSampler();
int nextArg = 3;
if (op == EOpMethodSampleBias) // SampleBias has a bias arg
argBias = argAggregate->getSequence()[nextArg++]->getAsTyped();
TOperator textureOp = EOpTexture;
if ((int)argAggregate->getSequence().size() == (nextArg+1)) { // last parameter is offset form
textureOp = EOpTextureOffset;
argOffset = argAggregate->getSequence()[nextArg++]->getAsTyped();
}
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
TIntermAggregate* txsample = new TIntermAggregate(textureOp);
txsample->getSequence().push_back(txcombine);
txsample->getSequence().push_back(argCoord);
if (argOffset != nullptr)
txsample->getSequence().push_back(argOffset);
if (argBias != nullptr)
txsample->getSequence().push_back(argBias);
node = convertReturn(txsample, sampler);
break;
}
case EOpMethodSampleGrad: // ...
{
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
TIntermTyped* argDDX = argAggregate->getSequence()[3]->getAsTyped();
TIntermTyped* argDDY = argAggregate->getSequence()[4]->getAsTyped();
TIntermTyped* argOffset = nullptr;
const TSampler& sampler = argTex->getType().getSampler();
TOperator textureOp = EOpTextureGrad;
if (argAggregate->getSequence().size() == 6) { // last parameter is offset form
textureOp = EOpTextureGradOffset;
argOffset = argAggregate->getSequence()[5]->getAsTyped();
}
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
TIntermAggregate* txsample = new TIntermAggregate(textureOp);
txsample->getSequence().push_back(txcombine);
txsample->getSequence().push_back(argCoord);
txsample->getSequence().push_back(argDDX);
txsample->getSequence().push_back(argDDY);
if (argOffset != nullptr)
txsample->getSequence().push_back(argOffset);
node = convertReturn(txsample, sampler);
break;
}
case EOpMethodGetDimensions:
{
// AST returns a vector of results, which we break apart component-wise into
// separate values to assign to the HLSL method's outputs, ala:
// tx . GetDimensions(width, height);
// float2 sizeQueryTemp = EOpTextureQuerySize
// width = sizeQueryTemp.X;
// height = sizeQueryTemp.Y;
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
const TType& texType = argTex->getType();
assert(texType.getBasicType() == EbtSampler);
const TSampler& sampler = texType.getSampler();
const TSamplerDim dim = sampler.dim;
const bool isImage = sampler.isImage();
const bool isMs = sampler.isMultiSample();
const int numArgs = (int)argAggregate->getSequence().size();
int numDims = 0;
switch (dim) {
case Esd1D: numDims = 1; break; // W
case Esd2D: numDims = 2; break; // W, H
case Esd3D: numDims = 3; break; // W, H, D
case EsdCube: numDims = 2; break; // W, H (cube)
case EsdBuffer: numDims = 1; break; // W (buffers)
case EsdRect: numDims = 2; break; // W, H (rect)
default:
error(loc, "unhandled DX10 MethodGet dimension", "", "");
break;
}
// Arrayed adds another dimension for the number of array elements
if (sampler.isArrayed())
++numDims;
// Establish whether the method itself is querying mip levels. This can be false even
// if the underlying query requires a MIP level, due to the available HLSL method overloads.
const bool mipQuery = (numArgs > (numDims + 1 + (isMs ? 1 : 0)));
// Establish whether we must use the LOD form of query (even if the method did not supply a mip level to query).
// True if:
// 1. 1D/2D/3D/Cube AND multisample==0 AND NOT image (those can be sent to the non-LOD query)
// or,
// 2. There is a LOD (because the non-LOD query cannot be used in that case, per spec)
const bool mipRequired =
((dim == Esd1D || dim == Esd2D || dim == Esd3D || dim == EsdCube) && !isMs && !isImage) || // 1...
mipQuery; // 2...
// AST assumes integer return. Will be converted to float if required.
TIntermAggregate* sizeQuery = new TIntermAggregate(isImage ? EOpImageQuerySize : EOpTextureQuerySize);
sizeQuery->getSequence().push_back(argTex);
// If we're building an LOD query, add the LOD.
if (mipRequired) {
// If the base HLSL query had no MIP level given, use level 0.
TIntermTyped* queryLod = mipQuery ? argAggregate->getSequence()[1]->getAsTyped() :
intermediate.addConstantUnion(0, loc, true);
sizeQuery->getSequence().push_back(queryLod);
}
sizeQuery->setType(TType(EbtUint, EvqTemporary, numDims));
sizeQuery->setLoc(loc);
// Return value from size query
TVariable* tempArg = makeInternalVariable("sizeQueryTemp", sizeQuery->getType());
tempArg->getWritableType().getQualifier().makeTemporary();
TIntermTyped* sizeQueryAssign = intermediate.addAssign(EOpAssign,
intermediate.addSymbol(*tempArg, loc),
sizeQuery, loc);
// Compound statement for assigning outputs
TIntermAggregate* compoundStatement = intermediate.makeAggregate(sizeQueryAssign, loc);
// Index of first output parameter
const int outParamBase = mipQuery ? 2 : 1;
for (int compNum = 0; compNum < numDims; ++compNum) {
TIntermTyped* indexedOut = nullptr;
TIntermSymbol* sizeQueryReturn = intermediate.addSymbol(*tempArg, loc);
if (numDims > 1) {
TIntermTyped* component = intermediate.addConstantUnion(compNum, loc, true);
indexedOut = intermediate.addIndex(EOpIndexDirect, sizeQueryReturn, component, loc);
indexedOut->setType(TType(EbtUint, EvqTemporary, 1));
indexedOut->setLoc(loc);
} else {
indexedOut = sizeQueryReturn;
}
TIntermTyped* outParam = argAggregate->getSequence()[outParamBase + compNum]->getAsTyped();
TIntermTyped* compAssign = intermediate.addAssign(EOpAssign, outParam, indexedOut, loc);
compoundStatement = intermediate.growAggregate(compoundStatement, compAssign);
}
// handle mip level parameter
if (mipQuery) {
TIntermTyped* outParam = argAggregate->getSequence()[outParamBase + numDims]->getAsTyped();
TIntermAggregate* levelsQuery = new TIntermAggregate(EOpTextureQueryLevels);
levelsQuery->getSequence().push_back(argTex);
levelsQuery->setType(TType(EbtUint, EvqTemporary, 1));
levelsQuery->setLoc(loc);
TIntermTyped* compAssign = intermediate.addAssign(EOpAssign, outParam, levelsQuery, loc);
compoundStatement = intermediate.growAggregate(compoundStatement, compAssign);
}
// 2DMS formats query # samples, which needs a different query op
if (sampler.isMultiSample()) {
TIntermTyped* outParam = argAggregate->getSequence()[outParamBase + numDims]->getAsTyped();
TIntermAggregate* samplesQuery = new TIntermAggregate(EOpImageQuerySamples);
samplesQuery->getSequence().push_back(argTex);
samplesQuery->setType(TType(EbtUint, EvqTemporary, 1));
samplesQuery->setLoc(loc);
TIntermTyped* compAssign = intermediate.addAssign(EOpAssign, outParam, samplesQuery, loc);
compoundStatement = intermediate.growAggregate(compoundStatement, compAssign);
}
compoundStatement->setOperator(EOpSequence);
compoundStatement->setLoc(loc);
compoundStatement->setType(TType(EbtVoid));
node = compoundStatement;
break;
}
case EOpMethodSampleCmp: // fall through...
case EOpMethodSampleCmpLevelZero:
{
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
TIntermTyped* argCmpVal = argAggregate->getSequence()[3]->getAsTyped();
TIntermTyped* argOffset = nullptr;
// Sampler argument should be a sampler.
if (argSamp->getType().getBasicType() != EbtSampler) {
error(loc, "expected: sampler type", "", "");
return;
}
// Sampler should be a SamplerComparisonState
if (! argSamp->getType().getSampler().isShadow()) {
error(loc, "expected: SamplerComparisonState", "", "");
return;
}
// optional offset value
if (argAggregate->getSequence().size() > 4)
argOffset = argAggregate->getSequence()[4]->getAsTyped();
const int coordDimWithCmpVal = argCoord->getType().getVectorSize() + 1; // +1 for cmp
// AST wants comparison value as one of the texture coordinates
TOperator constructOp = EOpNull;
switch (coordDimWithCmpVal) {
// 1D can't happen: there's always at least 1 coordinate dimension + 1 cmp val
case 2: constructOp = EOpConstructVec2; break;
case 3: constructOp = EOpConstructVec3; break;
case 4: constructOp = EOpConstructVec4; break;
case 5: constructOp = EOpConstructVec4; break; // cubeArrayShadow, cmp value is separate arg.
default:
error(loc, "unhandled DX10 MethodSample dimension", "", "");
break;
}
TIntermAggregate* coordWithCmp = new TIntermAggregate(constructOp);
coordWithCmp->getSequence().push_back(argCoord);
if (coordDimWithCmpVal != 5) // cube array shadow is special.
coordWithCmp->getSequence().push_back(argCmpVal);
coordWithCmp->setLoc(loc);
coordWithCmp->setType(TType(argCoord->getBasicType(), EvqTemporary, std::min(coordDimWithCmpVal, 4)));
TOperator textureOp = (op == EOpMethodSampleCmpLevelZero ? EOpTextureLod : EOpTexture);
if (argOffset != nullptr)
textureOp = (op == EOpMethodSampleCmpLevelZero ? EOpTextureLodOffset : EOpTextureOffset);
// Create combined sampler & texture op
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
TIntermAggregate* txsample = new TIntermAggregate(textureOp);
txsample->getSequence().push_back(txcombine);
txsample->getSequence().push_back(coordWithCmp);
if (coordDimWithCmpVal == 5) // cube array shadow is special: cmp val follows coord.
txsample->getSequence().push_back(argCmpVal);
// the LevelZero form uses 0 as an explicit LOD
if (op == EOpMethodSampleCmpLevelZero)
txsample->getSequence().push_back(intermediate.addConstantUnion(0.0, EbtFloat, loc, true));
// Add offset if present
if (argOffset != nullptr)
txsample->getSequence().push_back(argOffset);
txsample->setType(node->getType());
txsample->setLoc(loc);
node = txsample;
break;
}
case EOpMethodLoad:
{
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* argCoord = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* argOffset = nullptr;
TIntermTyped* lodComponent = nullptr;
TIntermTyped* coordSwizzle = nullptr;
const TSampler& sampler = argTex->getType().getSampler();
const bool isMS = sampler.isMultiSample();
const bool isBuffer = sampler.dim == EsdBuffer;
const bool isImage = sampler.isImage();
const TBasicType coordBaseType = argCoord->getType().getBasicType();
// Last component of coordinate is the mip level, for non-MS. we separate them here:
if (isMS || isBuffer || isImage) {
// MS, Buffer, and Image have no LOD
coordSwizzle = argCoord;
} else {
// Extract coordinate
int swizzleSize = argCoord->getType().getVectorSize() - (isMS ? 0 : 1);
TSwizzleSelectors<TVectorSelector> coordFields;
for (int i = 0; i < swizzleSize; ++i)
coordFields.push_back(i);
TIntermTyped* coordIdx = intermediate.addSwizzle(coordFields, loc);
coordSwizzle = intermediate.addIndex(EOpVectorSwizzle, argCoord, coordIdx, loc);
coordSwizzle->setType(TType(coordBaseType, EvqTemporary, coordFields.size()));
// Extract LOD
TIntermTyped* lodIdx = intermediate.addConstantUnion(coordFields.size(), loc, true);
lodComponent = intermediate.addIndex(EOpIndexDirect, argCoord, lodIdx, loc);
lodComponent->setType(TType(coordBaseType, EvqTemporary, 1));
}
const int numArgs = (int)argAggregate->getSequence().size();
const bool hasOffset = ((!isMS && numArgs == 3) || (isMS && numArgs == 4));
// Create texel fetch
const TOperator fetchOp = (isImage ? EOpImageLoad :
hasOffset ? EOpTextureFetchOffset :
EOpTextureFetch);
TIntermAggregate* txfetch = new TIntermAggregate(fetchOp);
// Build up the fetch
txfetch->getSequence().push_back(argTex);
txfetch->getSequence().push_back(coordSwizzle);
if (isMS) {
// add 2DMS sample index
TIntermTyped* argSampleIdx = argAggregate->getSequence()[2]->getAsTyped();
txfetch->getSequence().push_back(argSampleIdx);
} else if (isBuffer) {
// Nothing else to do for buffers.
} else if (isImage) {
// Nothing else to do for images.
} else {
// 2DMS and buffer have no LOD, but everything else does.
txfetch->getSequence().push_back(lodComponent);
}
// Obtain offset arg, if there is one.
if (hasOffset) {
const int offsetPos = (isMS ? 3 : 2);
argOffset = argAggregate->getSequence()[offsetPos]->getAsTyped();
txfetch->getSequence().push_back(argOffset);
}
node = convertReturn(txfetch, sampler);
break;
}
case EOpMethodSampleLevel:
{
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
TIntermTyped* argLod = argAggregate->getSequence()[3]->getAsTyped();
TIntermTyped* argOffset = nullptr;
const TSampler& sampler = argTex->getType().getSampler();
const int numArgs = (int)argAggregate->getSequence().size();
if (numArgs == 5) // offset, if present
argOffset = argAggregate->getSequence()[4]->getAsTyped();
const TOperator textureOp = (argOffset == nullptr ? EOpTextureLod : EOpTextureLodOffset);
TIntermAggregate* txsample = new TIntermAggregate(textureOp);
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
txsample->getSequence().push_back(txcombine);
txsample->getSequence().push_back(argCoord);
txsample->getSequence().push_back(argLod);
if (argOffset != nullptr)
txsample->getSequence().push_back(argOffset);
node = convertReturn(txsample, sampler);
break;
}
case EOpMethodGather:
{
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
TIntermTyped* argOffset = nullptr;
// Offset is optional
if (argAggregate->getSequence().size() > 3)
argOffset = argAggregate->getSequence()[3]->getAsTyped();
const TOperator textureOp = (argOffset == nullptr ? EOpTextureGather : EOpTextureGatherOffset);
TIntermAggregate* txgather = new TIntermAggregate(textureOp);
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
txgather->getSequence().push_back(txcombine);
txgather->getSequence().push_back(argCoord);
// Offset if not given is implicitly channel 0 (red)
if (argOffset != nullptr)
txgather->getSequence().push_back(argOffset);
txgather->setType(node->getType());
txgather->setLoc(loc);
node = txgather;
break;
}
case EOpMethodGatherRed: // fall through...
case EOpMethodGatherGreen: // ...
case EOpMethodGatherBlue: // ...
case EOpMethodGatherAlpha: // ...
case EOpMethodGatherCmpRed: // ...
case EOpMethodGatherCmpGreen: // ...
case EOpMethodGatherCmpBlue: // ...
case EOpMethodGatherCmpAlpha: // ...
{
int channel = 0; // the channel we are gathering
int cmpValues = 0; // 1 if there is a compare value (handier than a bool below)
switch (op) {
case EOpMethodGatherCmpRed: cmpValues = 1; [[fallthrough]];
case EOpMethodGatherRed: channel = 0; break;
case EOpMethodGatherCmpGreen: cmpValues = 1; [[fallthrough]];
case EOpMethodGatherGreen: channel = 1; break;
case EOpMethodGatherCmpBlue: cmpValues = 1; [[fallthrough]];
case EOpMethodGatherBlue: channel = 2; break;
case EOpMethodGatherCmpAlpha: cmpValues = 1; [[fallthrough]];
case EOpMethodGatherAlpha: channel = 3; break;
default: assert(0); break;
}
// For now, we have nothing to map the component-wise comparison forms
// to, because neither GLSL nor SPIR-V has such an opcode. Issue an
// unimplemented error instead. Most of the machinery is here if that
// should ever become available. However, red can be passed through
// to OpImageDrefGather. G/B/A cannot, because that opcode does not
// accept a component.
if (cmpValues != 0 && op != EOpMethodGatherCmpRed) {
error(loc, "unimplemented: component-level gather compare", "", "");
return;
}
int arg = 0;
TIntermTyped* argTex = argAggregate->getSequence()[arg++]->getAsTyped();
TIntermTyped* argSamp = argAggregate->getSequence()[arg++]->getAsTyped();
TIntermTyped* argCoord = argAggregate->getSequence()[arg++]->getAsTyped();
TIntermTyped* argOffset = nullptr;
TIntermTyped* argOffsets[4] = { nullptr, nullptr, nullptr, nullptr };
// TIntermTyped* argStatus = nullptr; // TODO: residency
TIntermTyped* argCmp = nullptr;
const TSamplerDim dim = argTex->getType().getSampler().dim;
const int argSize = (int)argAggregate->getSequence().size();
bool hasStatus = (argSize == (5+cmpValues) || argSize == (8+cmpValues));
bool hasOffset1 = false;
bool hasOffset4 = false;
// Sampler argument should be a sampler.
if (argSamp->getType().getBasicType() != EbtSampler) {
error(loc, "expected: sampler type", "", "");
return;
}
// Cmp forms require SamplerComparisonState
if (cmpValues > 0 && ! argSamp->getType().getSampler().isShadow()) {
error(loc, "expected: SamplerComparisonState", "", "");
return;
}
// Only 2D forms can have offsets. Discover if we have 0, 1 or 4 offsets.
if (dim == Esd2D) {
hasOffset1 = (argSize == (4+cmpValues) || argSize == (5+cmpValues));
hasOffset4 = (argSize == (7+cmpValues) || argSize == (8+cmpValues));
}
assert(!(hasOffset1 && hasOffset4));
TOperator textureOp = EOpTextureGather;
// Compare forms have compare value
if (cmpValues != 0)
argCmp = argOffset = argAggregate->getSequence()[arg++]->getAsTyped();
// Some forms have single offset
if (hasOffset1) {
textureOp = EOpTextureGatherOffset; // single offset form
argOffset = argAggregate->getSequence()[arg++]->getAsTyped();
}
// Some forms have 4 gather offsets
if (hasOffset4) {
textureOp = EOpTextureGatherOffsets; // note plural, for 4 offset form
for (int offsetNum = 0; offsetNum < 4; ++offsetNum)
argOffsets[offsetNum] = argAggregate->getSequence()[arg++]->getAsTyped();
}
// Residency status
if (hasStatus) {
// argStatus = argAggregate->getSequence()[arg++]->getAsTyped();
error(loc, "unimplemented: residency status", "", "");
return;
}
TIntermAggregate* txgather = new TIntermAggregate(textureOp);
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
TIntermTyped* argChannel = intermediate.addConstantUnion(channel, loc, true);
txgather->getSequence().push_back(txcombine);
txgather->getSequence().push_back(argCoord);
// AST wants an array of 4 offsets, where HLSL has separate args. Here
// we construct an array from the separate args.
if (hasOffset4) {
TType arrayType(EbtInt, EvqTemporary, 2);
TArraySizes* arraySizes = new TArraySizes;
arraySizes->addInnerSize(4);
arrayType.transferArraySizes(arraySizes);
TIntermAggregate* initList = new TIntermAggregate(EOpNull);
for (int offsetNum = 0; offsetNum < 4; ++offsetNum)
initList->getSequence().push_back(argOffsets[offsetNum]);
argOffset = addConstructor(loc, initList, arrayType);
}
// Add comparison value if we have one
if (argCmp != nullptr)
txgather->getSequence().push_back(argCmp);
// Add offset (either 1, or an array of 4) if we have one
if (argOffset != nullptr)
txgather->getSequence().push_back(argOffset);
// Add channel value if the sampler is not shadow
if (! argSamp->getType().getSampler().isShadow())
txgather->getSequence().push_back(argChannel);
txgather->setType(node->getType());
txgather->setLoc(loc);
node = txgather;
break;
}
case EOpMethodCalculateLevelOfDetail:
case EOpMethodCalculateLevelOfDetailUnclamped:
{
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* argSamp = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* argCoord = argAggregate->getSequence()[2]->getAsTyped();
TIntermAggregate* txquerylod = new TIntermAggregate(EOpTextureQueryLod);
TIntermAggregate* txcombine = handleSamplerTextureCombine(loc, argTex, argSamp);
txquerylod->getSequence().push_back(txcombine);
txquerylod->getSequence().push_back(argCoord);
TIntermTyped* lodComponent = intermediate.addConstantUnion(
op == EOpMethodCalculateLevelOfDetail ? 0 : 1,
loc, true);
TIntermTyped* lodComponentIdx = intermediate.addIndex(EOpIndexDirect, txquerylod, lodComponent, loc);
lodComponentIdx->setType(TType(EbtFloat, EvqTemporary, 1));
node = lodComponentIdx;
break;
}
case EOpMethodGetSamplePosition:
{
// TODO: this entire decomposition exists because there is not yet a way to query
// the sample position directly through SPIR-V. Instead, we return fixed sample
// positions for common cases. *** If the sample positions are set differently,
// this will be wrong. ***
TIntermTyped* argTex = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* argSampIdx = argAggregate->getSequence()[1]->getAsTyped();
TIntermAggregate* samplesQuery = new TIntermAggregate(EOpImageQuerySamples);
samplesQuery->getSequence().push_back(argTex);
samplesQuery->setType(TType(EbtUint, EvqTemporary, 1));
samplesQuery->setLoc(loc);
TIntermAggregate* compoundStatement = nullptr;
TVariable* outSampleCount = makeInternalVariable("@sampleCount", TType(EbtUint));
outSampleCount->getWritableType().getQualifier().makeTemporary();
TIntermTyped* compAssign = intermediate.addAssign(EOpAssign, intermediate.addSymbol(*outSampleCount, loc),
samplesQuery, loc);
compoundStatement = intermediate.growAggregate(compoundStatement, compAssign);
TIntermTyped* idxtest[4];
// Create tests against 2, 4, 8, and 16 sample values
int count = 0;
for (int val = 2; val <= 16; val *= 2)
idxtest[count++] =
intermediate.addBinaryNode(EOpEqual,
intermediate.addSymbol(*outSampleCount, loc),
intermediate.addConstantUnion(val, loc),
loc, TType(EbtBool));
const TOperator idxOp = (argSampIdx->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
// Create index ops into position arrays given sample index.
// TODO: should it be clamped?
TIntermTyped* index[4];
count = 0;
for (int val = 2; val <= 16; val *= 2) {
index[count] = intermediate.addIndex(idxOp, getSamplePosArray(val), argSampIdx, loc);
index[count++]->setType(TType(EbtFloat, EvqTemporary, 2));
}
// Create expression as:
// (sampleCount == 2) ? pos2[idx] :
// (sampleCount == 4) ? pos4[idx] :
// (sampleCount == 8) ? pos8[idx] :
// (sampleCount == 16) ? pos16[idx] : float2(0,0);
TIntermTyped* test =
intermediate.addSelection(idxtest[0], index[0],
intermediate.addSelection(idxtest[1], index[1],
intermediate.addSelection(idxtest[2], index[2],
intermediate.addSelection(idxtest[3], index[3],
getSamplePosArray(1), loc), loc), loc), loc);
compoundStatement = intermediate.growAggregate(compoundStatement, test);
compoundStatement->setOperator(EOpSequence);
compoundStatement->setLoc(loc);
compoundStatement->setType(TType(EbtFloat, EvqTemporary, 2));
node = compoundStatement;
break;
}
case EOpSubpassLoad:
{
const TIntermTyped* argSubpass =
argAggregate ? argAggregate->getSequence()[0]->getAsTyped() :
arguments->getAsTyped();
const TSampler& sampler = argSubpass->getType().getSampler();
// subpass load: the multisample form is overloaded. Here, we convert that to
// the EOpSubpassLoadMS opcode.
if (argAggregate != nullptr && argAggregate->getSequence().size() > 1)
node->getAsOperator()->setOp(EOpSubpassLoadMS);
node = convertReturn(node, sampler);
break;
}
default:
break; // most pass through unchanged
}
}
//
// Decompose geometry shader methods
//
void HlslParseContext::decomposeGeometryMethods(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
{
if (node == nullptr || !node->getAsOperator())
return;
const TOperator op = node->getAsOperator()->getOp();
const TIntermAggregate* argAggregate = arguments ? arguments->getAsAggregate() : nullptr;
switch (op) {
case EOpMethodAppend:
if (argAggregate) {
// Don't emit these for non-GS stage, since we won't have the gsStreamOutput symbol.
if (language != EShLangGeometry) {
node = nullptr;
return;
}
TIntermAggregate* sequence = nullptr;
TIntermAggregate* emit = new TIntermAggregate(EOpEmitVertex);
emit->setLoc(loc);
emit->setType(TType(EbtVoid));
TIntermTyped* data = argAggregate->getSequence()[1]->getAsTyped();
// This will be patched in finalization during finalizeAppendMethods()
sequence = intermediate.growAggregate(sequence, data, loc);
sequence = intermediate.growAggregate(sequence, emit);
sequence->setOperator(EOpSequence);
sequence->setLoc(loc);
sequence->setType(TType(EbtVoid));
gsAppends.push_back({sequence, loc});
node = sequence;
}
break;
case EOpMethodRestartStrip:
{
// Don't emit these for non-GS stage, since we won't have the gsStreamOutput symbol.
if (language != EShLangGeometry) {
node = nullptr;
return;
}
TIntermAggregate* cut = new TIntermAggregate(EOpEndPrimitive);
cut->setLoc(loc);
cut->setType(TType(EbtVoid));
node = cut;
}
break;
default:
break; // most pass through unchanged
}
}
//
// Optionally decompose intrinsics to AST opcodes.
//
void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
{
// Helper to find image data for image atomics:
// OpImageLoad(image[idx])
// We take the image load apart and add its params to the atomic op aggregate node
const auto imageAtomicParams = [this, &loc, &node](TIntermAggregate* atomic, TIntermTyped* load) {
TIntermAggregate* loadOp = load->getAsAggregate();
if (loadOp == nullptr) {
error(loc, "unknown image type in atomic operation", "", "");
node = nullptr;
return;
}
atomic->getSequence().push_back(loadOp->getSequence()[0]);
atomic->getSequence().push_back(loadOp->getSequence()[1]);
};
// Return true if this is an imageLoad, which we will change to an image atomic.
const auto isImageParam = [](TIntermTyped* image) -> bool {
TIntermAggregate* imageAggregate = image->getAsAggregate();
return imageAggregate != nullptr && imageAggregate->getOp() == EOpImageLoad;
};
const auto lookupBuiltinVariable = [&](const char* name, TBuiltInVariable builtin, TType& type) -> TIntermTyped* {
TSymbol* symbol = symbolTable.find(name);
if (nullptr == symbol) {
type.getQualifier().builtIn = builtin;
TVariable* variable = new TVariable(NewPoolTString(name), type);
symbolTable.insert(*variable);
symbol = symbolTable.find(name);
assert(symbol && "Inserted symbol could not be found!");
}
return intermediate.addSymbol(*(symbol->getAsVariable()), loc);
};
// HLSL intrinsics can be pass through to native AST opcodes, or decomposed here to existing AST
// opcodes for compatibility with existing software stacks.
static const bool decomposeHlslIntrinsics = true;
if (!decomposeHlslIntrinsics || !node || !node->getAsOperator())
return;
const TIntermAggregate* argAggregate = arguments ? arguments->getAsAggregate() : nullptr;
TIntermUnary* fnUnary = node->getAsUnaryNode();
const TOperator op = node->getAsOperator()->getOp();
switch (op) {
case EOpGenMul:
{
// mul(a,b) -> MatrixTimesMatrix, MatrixTimesVector, MatrixTimesScalar, VectorTimesScalar, Dot, Mul
// Since we are treating HLSL rows like GLSL columns (the first matrix indirection),
// we must reverse the operand order here. Hence, arg0 gets sequence[1], etc.
TIntermTyped* arg0 = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* arg1 = argAggregate->getSequence()[0]->getAsTyped();
if (arg0->isVector() && arg1->isVector()) { // vec * vec
node->getAsAggregate()->setOperator(EOpDot);
} else {
node = handleBinaryMath(loc, "mul", EOpMul, arg0, arg1);
}
break;
}
case EOpRcp:
{
// rcp(a) -> 1 / a
TIntermTyped* arg0 = fnUnary->getOperand();
TBasicType type0 = arg0->getBasicType();
TIntermTyped* one = intermediate.addConstantUnion(1, type0, loc, true);
node = handleBinaryMath(loc, "rcp", EOpDiv, one, arg0);
break;
}
case EOpAny: // fall through
case EOpAll:
{
TIntermTyped* typedArg = arguments->getAsTyped();
// HLSL allows float/etc types here, and the SPIR-V opcode requires a bool.
// We'll convert here. Note that for efficiency, we could add a smarter
// decomposition for some type cases, e.g, maybe by decomposing a dot product.
if (typedArg->getType().getBasicType() != EbtBool) {
const TType boolType(EbtBool, EvqTemporary,
typedArg->getVectorSize(),
typedArg->getMatrixCols(),
typedArg->getMatrixRows(),
typedArg->isVector());
typedArg = intermediate.addConversion(EOpConstructBool, boolType, typedArg);
node->getAsUnaryNode()->setOperand(typedArg);
}
break;
}
case EOpSaturate:
{
// saturate(a) -> clamp(a,0,1)
TIntermTyped* arg0 = fnUnary->getOperand();
TBasicType type0 = arg0->getBasicType();
TIntermAggregate* clamp = new TIntermAggregate(EOpClamp);
clamp->getSequence().push_back(arg0);
clamp->getSequence().push_back(intermediate.addConstantUnion(0, type0, loc, true));
clamp->getSequence().push_back(intermediate.addConstantUnion(1, type0, loc, true));
clamp->setLoc(loc);
clamp->setType(node->getType());
clamp->getWritableType().getQualifier().makeTemporary();
node = clamp;
break;
}
case EOpSinCos:
{
// sincos(a,b,c) -> b = sin(a), c = cos(a)
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* arg2 = argAggregate->getSequence()[2]->getAsTyped();
TIntermTyped* sinStatement = handleUnaryMath(loc, "sin", EOpSin, arg0);
TIntermTyped* cosStatement = handleUnaryMath(loc, "cos", EOpCos, arg0);
TIntermTyped* sinAssign = intermediate.addAssign(EOpAssign, arg1, sinStatement, loc);
TIntermTyped* cosAssign = intermediate.addAssign(EOpAssign, arg2, cosStatement, loc);
TIntermAggregate* compoundStatement = intermediate.makeAggregate(sinAssign, loc);
compoundStatement = intermediate.growAggregate(compoundStatement, cosAssign);
compoundStatement->setOperator(EOpSequence);
compoundStatement->setLoc(loc);
compoundStatement->setType(TType(EbtVoid));
node = compoundStatement;
break;
}
case EOpClip:
{
// clip(a) -> if (any(a<0)) discard;
TIntermTyped* arg0 = fnUnary->getOperand();
TBasicType type0 = arg0->getBasicType();
TIntermTyped* compareNode = nullptr;
// For non-scalars: per experiment with FXC compiler, discard if any component < 0.
if (!arg0->isScalar()) {
// component-wise compare: a < 0
TIntermAggregate* less = new TIntermAggregate(EOpLessThan);
less->getSequence().push_back(arg0);
less->setLoc(loc);
// make vec or mat of bool matching dimensions of input
less->setType(TType(EbtBool, EvqTemporary,
arg0->getType().getVectorSize(),
arg0->getType().getMatrixCols(),
arg0->getType().getMatrixRows(),
arg0->getType().isVector()));
// calculate # of components for comparison const
const int constComponentCount =
std::max(arg0->getType().getVectorSize(), 1) *
std::max(arg0->getType().getMatrixCols(), 1) *
std::max(arg0->getType().getMatrixRows(), 1);
TConstUnion zero;
if (arg0->getType().isIntegerDomain())
zero.setDConst(0);
else
zero.setDConst(0.0);
TConstUnionArray zeros(constComponentCount, zero);
less->getSequence().push_back(intermediate.addConstantUnion(zeros, arg0->getType(), loc, true));
compareNode = intermediate.addBuiltInFunctionCall(loc, EOpAny, true, less, TType(EbtBool));
} else {
TIntermTyped* zero;
if (arg0->getType().isIntegerDomain())
zero = intermediate.addConstantUnion(0, loc, true);
else
zero = intermediate.addConstantUnion(0.0, type0, loc, true);
compareNode = handleBinaryMath(loc, "clip", EOpLessThan, arg0, zero);
}
TIntermBranch* killNode = intermediate.addBranch(EOpKill, loc);
node = new TIntermSelection(compareNode, killNode, nullptr);
node->setLoc(loc);
break;
}
case EOpLog10:
{
// log10(a) -> log2(a) * 0.301029995663981 (== 1/log2(10))
TIntermTyped* arg0 = fnUnary->getOperand();
TIntermTyped* log2 = handleUnaryMath(loc, "log2", EOpLog2, arg0);
TIntermTyped* base = intermediate.addConstantUnion(0.301029995663981f, EbtFloat, loc, true);
node = handleBinaryMath(loc, "mul", EOpMul, log2, base);
break;
}
case EOpDst:
{
// dest.x = 1;
// dest.y = src0.y * src1.y;
// dest.z = src0.z;
// dest.w = src1.w;
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* y = intermediate.addConstantUnion(1, loc, true);
TIntermTyped* z = intermediate.addConstantUnion(2, loc, true);
TIntermTyped* w = intermediate.addConstantUnion(3, loc, true);
TIntermTyped* src0y = intermediate.addIndex(EOpIndexDirect, arg0, y, loc);
TIntermTyped* src1y = intermediate.addIndex(EOpIndexDirect, arg1, y, loc);
TIntermTyped* src0z = intermediate.addIndex(EOpIndexDirect, arg0, z, loc);
TIntermTyped* src1w = intermediate.addIndex(EOpIndexDirect, arg1, w, loc);
TIntermAggregate* dst = new TIntermAggregate(EOpConstructVec4);
dst->getSequence().push_back(intermediate.addConstantUnion(1.0, EbtFloat, loc, true));
dst->getSequence().push_back(handleBinaryMath(loc, "mul", EOpMul, src0y, src1y));
dst->getSequence().push_back(src0z);
dst->getSequence().push_back(src1w);
dst->setType(TType(EbtFloat, EvqTemporary, 4));
dst->setLoc(loc);
node = dst;
break;
}
case EOpInterlockedAdd: // optional last argument (if present) is assigned from return value
case EOpInterlockedMin: // ...
case EOpInterlockedMax: // ...
case EOpInterlockedAnd: // ...
case EOpInterlockedOr: // ...
case EOpInterlockedXor: // ...
case EOpInterlockedExchange: // always has output arg
{
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // dest
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // value
TIntermTyped* arg2 = nullptr;
if (argAggregate->getSequence().size() > 2)
arg2 = argAggregate->getSequence()[2]->getAsTyped();
const bool isImage = isImageParam(arg0);
const TOperator atomicOp = mapAtomicOp(loc, op, isImage);
TIntermAggregate* atomic = new TIntermAggregate(atomicOp);
atomic->setType(arg0->getType());
atomic->getWritableType().getQualifier().makeTemporary();
atomic->setLoc(loc);
if (isImage) {
// orig_value = imageAtomicOp(image, loc, data)
imageAtomicParams(atomic, arg0);
atomic->getSequence().push_back(arg1);
if (argAggregate->getSequence().size() > 2) {
node = intermediate.addAssign(EOpAssign, arg2, atomic, loc);
} else {
node = atomic; // no assignment needed, as there was no out var.
}
} else {
// Normal memory variable:
// arg0 = mem, arg1 = data, arg2(optional,out) = orig_value
if (argAggregate->getSequence().size() > 2) {
// optional output param is present. return value goes to arg2.
atomic->getSequence().push_back(arg0);
atomic->getSequence().push_back(arg1);
node = intermediate.addAssign(EOpAssign, arg2, atomic, loc);
} else {
// Set the matching operator. Since output is absent, this is all we need to do.
node->getAsAggregate()->setOperator(atomicOp);
node->setType(atomic->getType());
}
}
break;
}
case EOpInterlockedCompareExchange:
{
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // dest
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // cmp
TIntermTyped* arg2 = argAggregate->getSequence()[2]->getAsTyped(); // value
TIntermTyped* arg3 = argAggregate->getSequence()[3]->getAsTyped(); // orig
const bool isImage = isImageParam(arg0);
TIntermAggregate* atomic = new TIntermAggregate(mapAtomicOp(loc, op, isImage));
atomic->setLoc(loc);
atomic->setType(arg2->getType());
atomic->getWritableType().getQualifier().makeTemporary();
if (isImage) {
imageAtomicParams(atomic, arg0);
} else {
atomic->getSequence().push_back(arg0);
}
atomic->getSequence().push_back(arg1);
atomic->getSequence().push_back(arg2);
node = intermediate.addAssign(EOpAssign, arg3, atomic, loc);
break;
}
case EOpEvaluateAttributeSnapped:
{
// SPIR-V InterpolateAtOffset uses float vec2 offset in pixels
// HLSL uses int2 offset on a 16x16 grid in [-8..7] on x & y:
// iU = (iU<<28)>>28
// fU = ((float)iU)/16
// Targets might handle this natively, in which case they can disable
// decompositions.
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // value
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // offset
TIntermTyped* i28 = intermediate.addConstantUnion(28, loc, true);
TIntermTyped* iU = handleBinaryMath(loc, ">>", EOpRightShift,
handleBinaryMath(loc, "<<", EOpLeftShift, arg1, i28),
i28);
TIntermTyped* recip16 = intermediate.addConstantUnion((1.0/16.0), EbtFloat, loc, true);
TIntermTyped* floatOffset = handleBinaryMath(loc, "mul", EOpMul,
intermediate.addConversion(EOpConstructFloat,
TType(EbtFloat, EvqTemporary, 2), iU),
recip16);
TIntermAggregate* interp = new TIntermAggregate(EOpInterpolateAtOffset);
interp->getSequence().push_back(arg0);
interp->getSequence().push_back(floatOffset);
interp->setLoc(loc);
interp->setType(arg0->getType());
interp->getWritableType().getQualifier().makeTemporary();
node = interp;
break;
}
case EOpLit:
{
TIntermTyped* n_dot_l = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* n_dot_h = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* m = argAggregate->getSequence()[2]->getAsTyped();
TIntermAggregate* dst = new TIntermAggregate(EOpConstructVec4);
// Ambient
dst->getSequence().push_back(intermediate.addConstantUnion(1.0, EbtFloat, loc, true));
// Diffuse:
TIntermTyped* zero = intermediate.addConstantUnion(0.0, EbtFloat, loc, true);
TIntermAggregate* diffuse = new TIntermAggregate(EOpMax);
diffuse->getSequence().push_back(n_dot_l);
diffuse->getSequence().push_back(zero);
diffuse->setLoc(loc);
diffuse->setType(TType(EbtFloat));
dst->getSequence().push_back(diffuse);
// Specular:
TIntermAggregate* min_ndot = new TIntermAggregate(EOpMin);
min_ndot->getSequence().push_back(n_dot_l);
min_ndot->getSequence().push_back(n_dot_h);
min_ndot->setLoc(loc);
min_ndot->setType(TType(EbtFloat));
TIntermTyped* compare = handleBinaryMath(loc, "<", EOpLessThan, min_ndot, zero);
TIntermTyped* n_dot_h_m = handleBinaryMath(loc, "mul", EOpMul, n_dot_h, m); // n_dot_h * m
dst->getSequence().push_back(intermediate.addSelection(compare, zero, n_dot_h_m, loc));
// One:
dst->getSequence().push_back(intermediate.addConstantUnion(1.0, EbtFloat, loc, true));
dst->setLoc(loc);
dst->setType(TType(EbtFloat, EvqTemporary, 4));
node = dst;
break;
}
case EOpAsDouble:
{
// asdouble accepts two 32 bit ints. we can use EOpUint64BitsToDouble, but must
// first construct a uint64.
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped();
if (arg0->getType().isVector()) { // TODO: ...
error(loc, "double2 conversion not implemented", "asdouble", "");
break;
}
TIntermAggregate* uint64 = new TIntermAggregate(EOpConstructUVec2);
uint64->getSequence().push_back(arg0);
uint64->getSequence().push_back(arg1);
uint64->setType(TType(EbtUint, EvqTemporary, 2)); // convert 2 uints to a uint2
uint64->setLoc(loc);
// bitcast uint2 to a double
TIntermTyped* convert = new TIntermUnary(EOpUint64BitsToDouble);
convert->getAsUnaryNode()->setOperand(uint64);
convert->setLoc(loc);
convert->setType(TType(EbtDouble, EvqTemporary));
node = convert;
break;
}
case EOpF16tof32:
{
// input uvecN with low 16 bits of each component holding a float16. convert to float32.
TIntermTyped* argValue = node->getAsUnaryNode()->getOperand();
TIntermTyped* zero = intermediate.addConstantUnion(0, loc, true);
const int vecSize = argValue->getType().getVectorSize();
TOperator constructOp = EOpNull;
switch (vecSize) {
case 1: constructOp = EOpNull; break; // direct use, no construct needed
case 2: constructOp = EOpConstructVec2; break;
case 3: constructOp = EOpConstructVec3; break;
case 4: constructOp = EOpConstructVec4; break;
default: assert(0); break;
}
// For scalar case, we don't need to construct another type.
TIntermAggregate* result = (vecSize > 1) ? new TIntermAggregate(constructOp) : nullptr;
if (result) {
result->setType(TType(EbtFloat, EvqTemporary, vecSize));
result->setLoc(loc);
}
for (int idx = 0; idx < vecSize; ++idx) {
TIntermTyped* idxConst = intermediate.addConstantUnion(idx, loc, true);
TIntermTyped* component = argValue->getType().isVector() ?
intermediate.addIndex(EOpIndexDirect, argValue, idxConst, loc) : argValue;
if (component != argValue)
component->setType(TType(argValue->getBasicType(), EvqTemporary));
TIntermTyped* unpackOp = new TIntermUnary(EOpUnpackHalf2x16);
unpackOp->setType(TType(EbtFloat, EvqTemporary, 2));
unpackOp->getAsUnaryNode()->setOperand(component);
unpackOp->setLoc(loc);
TIntermTyped* lowOrder = intermediate.addIndex(EOpIndexDirect, unpackOp, zero, loc);
if (result != nullptr) {
result->getSequence().push_back(lowOrder);
node = result;
} else {
node = lowOrder;
}
}
break;
}
case EOpF32tof16:
{
// input floatN converted to 16 bit float in low order bits of each component of uintN
TIntermTyped* argValue = node->getAsUnaryNode()->getOperand();
TIntermTyped* zero = intermediate.addConstantUnion(0.0, EbtFloat, loc, true);
const int vecSize = argValue->getType().getVectorSize();
TOperator constructOp = EOpNull;
switch (vecSize) {
case 1: constructOp = EOpNull; break; // direct use, no construct needed
case 2: constructOp = EOpConstructUVec2; break;
case 3: constructOp = EOpConstructUVec3; break;
case 4: constructOp = EOpConstructUVec4; break;
default: assert(0); break;
}
// For scalar case, we don't need to construct another type.
TIntermAggregate* result = (vecSize > 1) ? new TIntermAggregate(constructOp) : nullptr;
if (result) {
result->setType(TType(EbtUint, EvqTemporary, vecSize));
result->setLoc(loc);
}
for (int idx = 0; idx < vecSize; ++idx) {
TIntermTyped* idxConst = intermediate.addConstantUnion(idx, loc, true);
TIntermTyped* component = argValue->getType().isVector() ?
intermediate.addIndex(EOpIndexDirect, argValue, idxConst, loc) : argValue;
if (component != argValue)
component->setType(TType(argValue->getBasicType(), EvqTemporary));
TIntermAggregate* vec2ComponentAndZero = new TIntermAggregate(EOpConstructVec2);
vec2ComponentAndZero->getSequence().push_back(component);
vec2ComponentAndZero->getSequence().push_back(zero);
vec2ComponentAndZero->setType(TType(EbtFloat, EvqTemporary, 2));
vec2ComponentAndZero->setLoc(loc);
TIntermTyped* packOp = new TIntermUnary(EOpPackHalf2x16);
packOp->getAsUnaryNode()->setOperand(vec2ComponentAndZero);
packOp->setLoc(loc);
packOp->setType(TType(EbtUint, EvqTemporary));
if (result != nullptr) {
result->getSequence().push_back(packOp);
node = result;
} else {
node = packOp;
}
}
break;
}
case EOpD3DCOLORtoUBYTE4:
{
// ivec4 ( x.zyxw * 255.001953 );
TIntermTyped* arg0 = node->getAsUnaryNode()->getOperand();
TSwizzleSelectors<TVectorSelector> selectors;
selectors.push_back(2);
selectors.push_back(1);
selectors.push_back(0);
selectors.push_back(3);
TIntermTyped* swizzleIdx = intermediate.addSwizzle(selectors, loc);
TIntermTyped* swizzled = intermediate.addIndex(EOpVectorSwizzle, arg0, swizzleIdx, loc);
swizzled->setType(arg0->getType());
swizzled->getWritableType().getQualifier().makeTemporary();
TIntermTyped* conversion = intermediate.addConstantUnion(255.001953f, EbtFloat, loc, true);
TIntermTyped* rangeConverted = handleBinaryMath(loc, "mul", EOpMul, conversion, swizzled);
rangeConverted->setType(arg0->getType());
rangeConverted->getWritableType().getQualifier().makeTemporary();
node = intermediate.addConversion(EOpConstructInt, TType(EbtInt, EvqTemporary, 4), rangeConverted);
node->setLoc(loc);
node->setType(TType(EbtInt, EvqTemporary, 4));
break;
}
case EOpIsFinite:
{
// Since OPIsFinite in SPIR-V is only supported with the Kernel capability, we translate
// it to !isnan && !isinf
TIntermTyped* arg0 = node->getAsUnaryNode()->getOperand();
// We'll make a temporary in case the RHS is cmoplex
TVariable* tempArg = makeInternalVariable("@finitetmp", arg0->getType());
tempArg->getWritableType().getQualifier().makeTemporary();
TIntermTyped* tmpArgAssign = intermediate.addAssign(EOpAssign,
intermediate.addSymbol(*tempArg, loc),
arg0, loc);
TIntermAggregate* compoundStatement = intermediate.makeAggregate(tmpArgAssign, loc);
const TType boolType(EbtBool, EvqTemporary, arg0->getVectorSize(), arg0->getMatrixCols(),
arg0->getMatrixRows());
TIntermTyped* isnan = handleUnaryMath(loc, "isnan", EOpIsNan, intermediate.addSymbol(*tempArg, loc));
isnan->setType(boolType);
TIntermTyped* notnan = handleUnaryMath(loc, "!", EOpLogicalNot, isnan);
notnan->setType(boolType);
TIntermTyped* isinf = handleUnaryMath(loc, "isinf", EOpIsInf, intermediate.addSymbol(*tempArg, loc));
isinf->setType(boolType);
TIntermTyped* notinf = handleUnaryMath(loc, "!", EOpLogicalNot, isinf);
notinf->setType(boolType);
TIntermTyped* andNode = handleBinaryMath(loc, "and", EOpLogicalAnd, notnan, notinf);
andNode->setType(boolType);
compoundStatement = intermediate.growAggregate(compoundStatement, andNode);
compoundStatement->setOperator(EOpSequence);
compoundStatement->setLoc(loc);
compoundStatement->setType(boolType);
node = compoundStatement;
break;
}
case EOpWaveGetLaneCount:
{
// Mapped to gl_SubgroupSize builtin (We preprend @ to the symbol
// so that it inhabits the symbol table, but has a user-invalid name
// in-case some source HLSL defined the symbol also).
TType type(EbtUint, EvqVaryingIn);
node = lookupBuiltinVariable("@gl_SubgroupSize", EbvSubgroupSize2, type);
break;
}
case EOpWaveGetLaneIndex:
{
// Mapped to gl_SubgroupInvocationID builtin (We preprend @ to the
// symbol so that it inhabits the symbol table, but has a
// user-invalid name in-case some source HLSL defined the symbol
// also).
TType type(EbtUint, EvqVaryingIn);
node = lookupBuiltinVariable("@gl_SubgroupInvocationID", EbvSubgroupInvocation2, type);
break;
}
case EOpWaveActiveCountBits:
{
// Mapped to subgroupBallotBitCount(subgroupBallot()) builtin
// uvec4 type.
TType uvec4Type(EbtUint, EvqTemporary, 4);
// Get the uvec4 return from subgroupBallot().
TIntermTyped* res = intermediate.addBuiltInFunctionCall(loc,
EOpSubgroupBallot, true, arguments, uvec4Type);
// uint type.
TType uintType(EbtUint, EvqTemporary);
node = intermediate.addBuiltInFunctionCall(loc,
EOpSubgroupBallotBitCount, true, res, uintType);
break;
}
case EOpWavePrefixCountBits:
{
// Mapped to subgroupBallotExclusiveBitCount(subgroupBallot())
// builtin
// uvec4 type.
TType uvec4Type(EbtUint, EvqTemporary, 4);
// Get the uvec4 return from subgroupBallot().
TIntermTyped* res = intermediate.addBuiltInFunctionCall(loc,
EOpSubgroupBallot, true, arguments, uvec4Type);
// uint type.
TType uintType(EbtUint, EvqTemporary);
node = intermediate.addBuiltInFunctionCall(loc,
EOpSubgroupBallotExclusiveBitCount, true, res, uintType);
break;
}
default:
break; // most pass through unchanged
}
}
//
// Handle seeing function call syntax in the grammar, which could be any of
// - .length() method
// - constructor
// - a call to a built-in function mapped to an operator
// - a call to a built-in function that will remain a function call (e.g., texturing)
// - user function
// - subroutine call (not implemented yet)
//
TIntermTyped* HlslParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction* function, TIntermTyped* arguments)
{
TIntermTyped* result = nullptr;
TOperator op = function->getBuiltInOp();
if (op != EOpNull) {
//
// Then this should be a constructor.
// Don't go through the symbol table for constructors.
// Their parameters will be verified algorithmically.
//
TType type(EbtVoid); // use this to get the type back
if (! constructorError(loc, arguments, *function, op, type)) {
//
// It's a constructor, of type 'type'.
//
result = handleConstructor(loc, arguments, type);
if (result == nullptr) {
error(loc, "cannot construct with these arguments", type.getCompleteString().c_str(), "");
return nullptr;
}
}
} else {
//
// Find it in the symbol table.
//
const TFunction* fnCandidate = nullptr;
bool builtIn = false;
int thisDepth = 0;
// For mat mul, the situation is unusual: we have to compare vector sizes to mat row or col sizes,
// and clamp the opposite arg. Since that's complex, we farm it off to a separate method.
// It doesn't naturally fall out of processing an argument at a time in isolation.
if (function->getName() == "mul")
addGenMulArgumentConversion(loc, *function, arguments);
TIntermAggregate* aggregate = arguments ? arguments->getAsAggregate() : nullptr;
// TODO: this needs improvement: there's no way at present to look up a signature in
// the symbol table for an arbitrary type. This is a temporary hack until that ability exists.
// It will have false positives, since it doesn't check arg counts or types.
if (arguments) {
// Check if first argument is struct buffer type. It may be an aggregate or a symbol, so we
// look for either case.
TIntermTyped* arg0 = nullptr;
if (aggregate && aggregate->getSequence().size() > 0 && aggregate->getSequence()[0])
arg0 = aggregate->getSequence()[0]->getAsTyped();
else if (arguments->getAsSymbolNode())
arg0 = arguments->getAsSymbolNode();
if (arg0 != nullptr && isStructBufferType(arg0->getType())) {
static const int methodPrefixSize = sizeof(BUILTIN_PREFIX)-1;
if (function->getName().length() > methodPrefixSize &&
isStructBufferMethod(function->getName().substr(methodPrefixSize))) {
const TString mangle = function->getName() + "(";
TSymbol* symbol = symbolTable.find(mangle, &builtIn);
if (symbol)
fnCandidate = symbol->getAsFunction();
}
}
}
if (fnCandidate == nullptr)
fnCandidate = findFunction(loc, *function, builtIn, thisDepth, arguments);
if (fnCandidate) {
// This is a declared function that might map to
// - a built-in operator,
// - a built-in function not mapped to an operator, or
// - a user function.
// turn an implicit member-function resolution into an explicit call
TString callerName;
if (thisDepth == 0)
callerName = fnCandidate->getMangledName();
else {
// get the explicit (full) name of the function
callerName = currentTypePrefix[currentTypePrefix.size() - thisDepth];
callerName += fnCandidate->getMangledName();
// insert the implicit calling argument
pushFrontArguments(intermediate.addSymbol(*getImplicitThis(thisDepth)), arguments);
}
// Convert 'in' arguments, so that types match.
// However, skip those that need expansion, that is covered next.
if (arguments)
addInputArgumentConversions(*fnCandidate, arguments);
// Expand arguments. Some arguments must physically expand to a different set
// than what the shader declared and passes.
if (arguments && !builtIn)
expandArguments(loc, *fnCandidate, arguments);
// Expansion may have changed the form of arguments
aggregate = arguments ? arguments->getAsAggregate() : nullptr;
op = fnCandidate->getBuiltInOp();
if (builtIn && op != EOpNull) {
// SM 4.0 and above guarantees roundEven semantics for round()
if (!hlslDX9Compatible() && op == EOpRound)
op = EOpRoundEven;
// A function call mapped to a built-in operation.
result = intermediate.addBuiltInFunctionCall(loc, op, fnCandidate->getParamCount() == 1, arguments,
fnCandidate->getType());
if (result == nullptr) {
error(arguments->getLoc(), " wrong operand type", "Internal Error",
"built in unary operator function. Type: %s",
static_cast<TIntermTyped*>(arguments)->getCompleteString().c_str());
} else if (result->getAsOperator()) {
builtInOpCheck(loc, *fnCandidate, *result->getAsOperator());
}
} else {
// This is a function call not mapped to built-in operator.
// It could still be a built-in function, but only if PureOperatorBuiltins == false.
result = intermediate.setAggregateOperator(arguments, EOpFunctionCall, fnCandidate->getType(), loc);
TIntermAggregate* call = result->getAsAggregate();
call->setName(callerName);
// this is how we know whether the given function is a built-in function or a user-defined function
// if builtIn == false, it's a userDefined -> could be an overloaded built-in function also
// if builtIn == true, it's definitely a built-in function with EOpNull
if (! builtIn) {
call->setUserDefined();
intermediate.addToCallGraph(infoSink, currentCaller, callerName);
}
}
// for decompositions, since we want to operate on the function node, not the aggregate holding
// output conversions.
const TIntermTyped* fnNode = result;
decomposeStructBufferMethods(loc, result, arguments); // HLSL->AST struct buffer method decompositions
decomposeIntrinsic(loc, result, arguments); // HLSL->AST intrinsic decompositions
decomposeSampleMethods(loc, result, arguments); // HLSL->AST sample method decompositions
decomposeGeometryMethods(loc, result, arguments); // HLSL->AST geometry method decompositions
// Create the qualifier list, carried in the AST for the call.
// Because some arguments expand to multiple arguments, the qualifier list will
// be longer than the formal parameter list.
if (result == fnNode && result->getAsAggregate()) {
TQualifierList& qualifierList = result->getAsAggregate()->getQualifierList();
for (int i = 0; i < fnCandidate->getParamCount(); ++i) {
TStorageQualifier qual = (*fnCandidate)[i].type->getQualifier().storage;
if (hasStructBuffCounter(*(*fnCandidate)[i].type)) {
// add buffer and counter buffer argument qualifier
qualifierList.push_back(qual);
qualifierList.push_back(qual);
} else if (shouldFlatten(*(*fnCandidate)[i].type, (*fnCandidate)[i].type->getQualifier().storage,
true)) {
// add structure member expansion
for (int memb = 0; memb < (int)(*fnCandidate)[i].type->getStruct()->size(); ++memb)
qualifierList.push_back(qual);
} else {
// Normal 1:1 case
qualifierList.push_back(qual);
}
}
}
// Convert 'out' arguments. If it was a constant folded built-in, it won't be an aggregate anymore.
// Built-ins with a single argument aren't called with an aggregate, but they also don't have an output.
// Also, build the qualifier list for user function calls, which are always called with an aggregate.
// We don't do this is if there has been a decomposition, which will have added its own conversions
// for output parameters.
if (result == fnNode && result->getAsAggregate())
result = addOutputArgumentConversions(*fnCandidate, *result->getAsOperator());
}
}
// generic error recovery
// TODO: simplification: localize all the error recoveries that look like this, and taking type into account to
// reduce cascades
if (result == nullptr)
result = intermediate.addConstantUnion(0.0, EbtFloat, loc);
return result;
}
// An initial argument list is difficult: it can be null, or a single node,
// or an aggregate if more than one argument. Add one to the front, maintaining
// this lack of uniformity.
void HlslParseContext::pushFrontArguments(TIntermTyped* front, TIntermTyped*& arguments)
{
if (arguments == nullptr)
arguments = front;
else if (arguments->getAsAggregate() != nullptr)
arguments->getAsAggregate()->getSequence().insert(arguments->getAsAggregate()->getSequence().begin(), front);
else
arguments = intermediate.growAggregate(front, arguments);
}
//
// HLSL allows mismatched dimensions on vec*mat, mat*vec, vec*vec, and mat*mat. This is a
// situation not well suited to resolution in intrinsic selection, but we can do so here, since we
// can look at both arguments insert explicit shape changes if required.
//
void HlslParseContext::addGenMulArgumentConversion(const TSourceLoc& loc, TFunction& call, TIntermTyped*& args)
{
TIntermAggregate* argAggregate = args ? args->getAsAggregate() : nullptr;
if (argAggregate == nullptr || argAggregate->getSequence().size() != 2) {
// It really ought to have two arguments.
error(loc, "expected: mul arguments", "", "");
return;
}
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped();
if (arg0->isVector() && arg1->isVector()) {
// For:
// vec * vec: it's handled during intrinsic selection, so while we could do it here,
// we can also ignore it, which is easier.
} else if (arg0->isVector() && arg1->isMatrix()) {
// vec * mat: we clamp the vec if the mat col is smaller, else clamp the mat col.
if (arg0->getVectorSize() < arg1->getMatrixCols()) {
// vec is smaller, so truncate larger mat dimension
const TType truncType(arg1->getBasicType(), arg1->getQualifier().storage, arg1->getQualifier().precision,
0, arg0->getVectorSize(), arg1->getMatrixRows());
arg1 = addConstructor(loc, arg1, truncType);
} else if (arg0->getVectorSize() > arg1->getMatrixCols()) {
// vec is larger, so truncate vec to mat size
const TType truncType(arg0->getBasicType(), arg0->getQualifier().storage, arg0->getQualifier().precision,
arg1->getMatrixCols());
arg0 = addConstructor(loc, arg0, truncType);
}
} else if (arg0->isMatrix() && arg1->isVector()) {
// mat * vec: we clamp the vec if the mat col is smaller, else clamp the mat col.
if (arg1->getVectorSize() < arg0->getMatrixRows()) {
// vec is smaller, so truncate larger mat dimension
const TType truncType(arg0->getBasicType(), arg0->getQualifier().storage, arg0->getQualifier().precision,
0, arg0->getMatrixCols(), arg1->getVectorSize());
arg0 = addConstructor(loc, arg0, truncType);
} else if (arg1->getVectorSize() > arg0->getMatrixRows()) {
// vec is larger, so truncate vec to mat size
const TType truncType(arg1->getBasicType(), arg1->getQualifier().storage, arg1->getQualifier().precision,
arg0->getMatrixRows());
arg1 = addConstructor(loc, arg1, truncType);
}
} else if (arg0->isMatrix() && arg1->isMatrix()) {
// mat * mat: we clamp the smaller inner dimension to match the other matrix size.
// Remember, HLSL Mrc = GLSL/SPIRV Mcr.
if (arg0->getMatrixRows() > arg1->getMatrixCols()) {
const TType truncType(arg0->getBasicType(), arg0->getQualifier().storage, arg0->getQualifier().precision,
0, arg0->getMatrixCols(), arg1->getMatrixCols());
arg0 = addConstructor(loc, arg0, truncType);
} else if (arg0->getMatrixRows() < arg1->getMatrixCols()) {
const TType truncType(arg1->getBasicType(), arg1->getQualifier().storage, arg1->getQualifier().precision,
0, arg0->getMatrixRows(), arg1->getMatrixRows());
arg1 = addConstructor(loc, arg1, truncType);
}
} else {
// It's something with scalars: we'll just leave it alone. Function selection will handle it
// downstream.
}
// Warn if we altered one of the arguments
if (arg0 != argAggregate->getSequence()[0] || arg1 != argAggregate->getSequence()[1])
warn(loc, "mul() matrix size mismatch", "", "");
// Put arguments back. (They might be unchanged, in which case this is harmless).
argAggregate->getSequence()[0] = arg0;
argAggregate->getSequence()[1] = arg1;
call[0].type = &arg0->getWritableType();
call[1].type = &arg1->getWritableType();
}
//
// Add any needed implicit conversions for function-call arguments to input parameters.
//
void HlslParseContext::addInputArgumentConversions(const TFunction& function, TIntermTyped*& arguments)
{
TIntermAggregate* aggregate = arguments->getAsAggregate();
// Replace a single argument with a single argument.
const auto setArg = [&](int paramNum, TIntermTyped* arg) {
if (function.getParamCount() == 1)
arguments = arg;
else {
if (aggregate == nullptr)
arguments = arg;
else
aggregate->getSequence()[paramNum] = arg;
}
};
// Process each argument's conversion
for (int param = 0; param < function.getParamCount(); ++param) {
if (! function[param].type->getQualifier().isParamInput())
continue;
// At this early point there is a slight ambiguity between whether an aggregate 'arguments'
// is the single argument itself or its children are the arguments. Only one argument
// means take 'arguments' itself as the one argument.
TIntermTyped* arg = function.getParamCount() == 1
? arguments->getAsTyped()
: (aggregate ?
aggregate->getSequence()[param]->getAsTyped() :
arguments->getAsTyped());
if (*function[param].type != arg->getType()) {
// In-qualified arguments just need an extra node added above the argument to
// convert to the correct type.
TIntermTyped* convArg = intermediate.addConversion(EOpFunctionCall, *function[param].type, arg);
if (convArg != nullptr)
convArg = intermediate.addUniShapeConversion(EOpFunctionCall, *function[param].type, convArg);
if (convArg != nullptr)
setArg(param, convArg);
else
error(arg->getLoc(), "cannot convert input argument, argument", "", "%d", param);
} else {
if (wasFlattened(arg)) {
// If both formal and calling arg are to be flattened, leave that to argument
// expansion, not conversion.
if (!shouldFlatten(*function[param].type, function[param].type->getQualifier().storage, true)) {
// Will make a two-level subtree.
// The deepest will copy member-by-member to build the structure to pass.
// The level above that will be a two-operand EOpComma sequence that follows the copy by the
// object itself.
TVariable* internalAggregate = makeInternalVariable("aggShadow", *function[param].type);
internalAggregate->getWritableType().getQualifier().makeTemporary();
TIntermSymbol* internalSymbolNode = new TIntermSymbol(internalAggregate->getUniqueId(),
internalAggregate->getName(),
internalAggregate->getType());
internalSymbolNode->setLoc(arg->getLoc());
// This makes the deepest level, the member-wise copy
TIntermAggregate* assignAgg = handleAssign(arg->getLoc(), EOpAssign,
internalSymbolNode, arg)->getAsAggregate();
// Now, pair that with the resulting aggregate.
assignAgg = intermediate.growAggregate(assignAgg, internalSymbolNode, arg->getLoc());
assignAgg->setOperator(EOpComma);
assignAgg->setType(internalAggregate->getType());
setArg(param, assignAgg);
}
}
}
}
}
//
// Add any needed implicit expansion of calling arguments from what the shader listed to what's
// internally needed for the AST (given the constraints downstream).
//
void HlslParseContext::expandArguments(const TSourceLoc& loc, const TFunction& function, TIntermTyped*& arguments)
{
TIntermAggregate* aggregate = arguments->getAsAggregate();
int functionParamNumberOffset = 0;
// Replace a single argument with a single argument.
const auto setArg = [&](int paramNum, TIntermTyped* arg) {
if (function.getParamCount() + functionParamNumberOffset == 1)
arguments = arg;
else {
if (aggregate == nullptr)
arguments = arg;
else
aggregate->getSequence()[paramNum] = arg;
}
};
// Replace a single argument with a list of arguments
const auto setArgList = [&](int paramNum, const TVector<TIntermTyped*>& args) {
if (args.size() == 1)
setArg(paramNum, args.front());
else if (args.size() > 1) {
if (function.getParamCount() + functionParamNumberOffset == 1) {
arguments = intermediate.makeAggregate(args.front());
std::for_each(args.begin() + 1, args.end(),
[&](TIntermTyped* arg) {
arguments = intermediate.growAggregate(arguments, arg);
});
} else {
auto it = aggregate->getSequence().erase(aggregate->getSequence().begin() + paramNum);
aggregate->getSequence().insert(it, args.begin(), args.end());
}
functionParamNumberOffset += (int)(args.size() - 1);
}
};
// Process each argument's conversion
for (int param = 0; param < function.getParamCount(); ++param) {
// At this early point there is a slight ambiguity between whether an aggregate 'arguments'
// is the single argument itself or its children are the arguments. Only one argument
// means take 'arguments' itself as the one argument.
TIntermTyped* arg = function.getParamCount() == 1
? arguments->getAsTyped()
: (aggregate ?
aggregate->getSequence()[param + functionParamNumberOffset]->getAsTyped() :
arguments->getAsTyped());
if (wasFlattened(arg) && shouldFlatten(*function[param].type, function[param].type->getQualifier().storage, true)) {
// Need to pass the structure members instead of the structure.
TVector<TIntermTyped*> memberArgs;
for (int memb = 0; memb < (int)arg->getType().getStruct()->size(); ++memb)
memberArgs.push_back(flattenAccess(arg, memb));
setArgList(param + functionParamNumberOffset, memberArgs);
}
}
// TODO: if we need both hidden counter args (below) and struct expansion (above)
// the two algorithms need to be merged: Each assumes the list starts out 1:1 between
// parameters and arguments.
// If any argument is a pass-by-reference struct buffer with an associated counter
// buffer, we have to add another hidden parameter for that counter.
if (aggregate)
addStructBuffArguments(loc, aggregate);
}
//
// Add any needed implicit output conversions for function-call arguments. This
// can require a new tree topology, complicated further by whether the function
// has a return value.
//
// Returns a node of a subtree that evaluates to the return value of the function.
//
TIntermTyped* HlslParseContext::addOutputArgumentConversions(const TFunction& function, TIntermOperator& intermNode)
{
assert (intermNode.getAsAggregate() != nullptr || intermNode.getAsUnaryNode() != nullptr);
const TSourceLoc& loc = intermNode.getLoc();
TIntermSequence argSequence; // temp sequence for unary node args
if (intermNode.getAsUnaryNode())
argSequence.push_back(intermNode.getAsUnaryNode()->getOperand());
TIntermSequence& arguments = argSequence.empty() ? intermNode.getAsAggregate()->getSequence() : argSequence;
const auto needsConversion = [&](int argNum) {
return function[argNum].type->getQualifier().isParamOutput() &&
(*function[argNum].type != arguments[argNum]->getAsTyped()->getType() ||
shouldConvertLValue(arguments[argNum]) ||
wasFlattened(arguments[argNum]->getAsTyped()));
};
// Will there be any output conversions?
bool outputConversions = false;
for (int i = 0; i < function.getParamCount(); ++i) {
if (needsConversion(i)) {
outputConversions = true;
break;
}
}
if (! outputConversions)
return &intermNode;
// Setup for the new tree, if needed:
//
// Output conversions need a different tree topology.
// Out-qualified arguments need a temporary of the correct type, with the call
// followed by an assignment of the temporary to the original argument:
// void: function(arg, ...) -> ( function(tempArg, ...), arg = tempArg, ...)
// ret = function(arg, ...) -> ret = (tempRet = function(tempArg, ...), arg = tempArg, ..., tempRet)
// Where the "tempArg" type needs no conversion as an argument, but will convert on assignment.
TIntermTyped* conversionTree = nullptr;
TVariable* tempRet = nullptr;
if (intermNode.getBasicType() != EbtVoid) {
// do the "tempRet = function(...), " bit from above
tempRet = makeInternalVariable("tempReturn", intermNode.getType());
TIntermSymbol* tempRetNode = intermediate.addSymbol(*tempRet, loc);
conversionTree = intermediate.addAssign(EOpAssign, tempRetNode, &intermNode, loc);
} else
conversionTree = &intermNode;
conversionTree = intermediate.makeAggregate(conversionTree);
// Process each argument's conversion
for (int i = 0; i < function.getParamCount(); ++i) {
if (needsConversion(i)) {
// Out-qualified arguments needing conversion need to use the topology setup above.
// Do the " ...(tempArg, ...), arg = tempArg" bit from above.
// Make a temporary for what the function expects the argument to look like.
TVariable* tempArg = makeInternalVariable("tempArg", *function[i].type);
tempArg->getWritableType().getQualifier().makeTemporary();
TIntermSymbol* tempArgNode = intermediate.addSymbol(*tempArg, loc);
// This makes the deepest level, the member-wise copy
TIntermTyped* tempAssign = handleAssign(arguments[i]->getLoc(), EOpAssign, arguments[i]->getAsTyped(),
tempArgNode);
tempAssign = handleLvalue(arguments[i]->getLoc(), "assign", tempAssign);
conversionTree = intermediate.growAggregate(conversionTree, tempAssign, arguments[i]->getLoc());
// replace the argument with another node for the same tempArg variable
arguments[i] = intermediate.addSymbol(*tempArg, loc);
}
}
// Finalize the tree topology (see bigger comment above).
if (tempRet) {
// do the "..., tempRet" bit from above
TIntermSymbol* tempRetNode = intermediate.addSymbol(*tempRet, loc);
conversionTree = intermediate.growAggregate(conversionTree, tempRetNode, loc);
}
conversionTree = intermediate.setAggregateOperator(conversionTree, EOpComma, intermNode.getType(), loc);
return conversionTree;
}
//
// Add any needed "hidden" counter buffer arguments for function calls.
//
// Modifies the 'aggregate' argument if needed. Otherwise, is no-op.
//
void HlslParseContext::addStructBuffArguments(const TSourceLoc& loc, TIntermAggregate*& aggregate)
{
// See if there are any SB types with counters.
const bool hasStructBuffArg =
std::any_of(aggregate->getSequence().begin(),
aggregate->getSequence().end(),
[this](const TIntermNode* node) {
return (node && node->getAsTyped() != nullptr) && hasStructBuffCounter(node->getAsTyped()->getType());
});
// Nothing to do, if we didn't find one.
if (! hasStructBuffArg)
return;
TIntermSequence argsWithCounterBuffers;
for (int param = 0; param < int(aggregate->getSequence().size()); ++param) {
argsWithCounterBuffers.push_back(aggregate->getSequence()[param]);
if (hasStructBuffCounter(aggregate->getSequence()[param]->getAsTyped()->getType())) {
const TIntermSymbol* blockSym = aggregate->getSequence()[param]->getAsSymbolNode();
if (blockSym != nullptr) {
TType counterType;
counterBufferType(loc, counterType);
const TString counterBlockName(intermediate.addCounterBufferName(blockSym->getName()));
TVariable* variable = makeInternalVariable(counterBlockName, counterType);
// Mark this buffer's counter block as being in use
structBufferCounter[counterBlockName] = true;
TIntermSymbol* sym = intermediate.addSymbol(*variable, loc);
argsWithCounterBuffers.push_back(sym);
}
}
}
// Swap with the temp list we've built up.
aggregate->getSequence().swap(argsWithCounterBuffers);
}
//
// Do additional checking of built-in function calls that is not caught
// by normal semantic checks on argument type, extension tagging, etc.
//
// Assumes there has been a semantically correct match to a built-in function prototype.
//
void HlslParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCandidate, TIntermOperator& callNode)
{
// Set up convenience accessors to the argument(s). There is almost always
// multiple arguments for the cases below, but when there might be one,
// check the unaryArg first.
const TIntermSequence* argp = nullptr; // confusing to use [] syntax on a pointer, so this is to help get a reference
const TIntermTyped* unaryArg = nullptr;
const TIntermTyped* arg0 = nullptr;
if (callNode.getAsAggregate()) {
argp = &callNode.getAsAggregate()->getSequence();
if (argp->size() > 0)
arg0 = (*argp)[0]->getAsTyped();
} else {
assert(callNode.getAsUnaryNode());
unaryArg = callNode.getAsUnaryNode()->getOperand();
arg0 = unaryArg;
}
const TIntermSequence& aggArgs = *argp; // only valid when unaryArg is nullptr
switch (callNode.getOp()) {
case EOpTextureGather:
case EOpTextureGatherOffset:
case EOpTextureGatherOffsets:
{
// Figure out which variants are allowed by what extensions,
// and what arguments must be constant for which situations.
TString featureString = fnCandidate.getName() + "(...)";
const char* feature = featureString.c_str();
int compArg = -1; // track which argument, if any, is the constant component argument
switch (callNode.getOp()) {
case EOpTextureGather:
// More than two arguments needs gpu_shader5, and rectangular or shadow needs gpu_shader5,
// otherwise, need GL_ARB_texture_gather.
if (fnCandidate.getParamCount() > 2 || fnCandidate[0].type->getSampler().dim == EsdRect ||
fnCandidate[0].type->getSampler().shadow) {
if (! fnCandidate[0].type->getSampler().shadow)
compArg = 2;
}
break;
case EOpTextureGatherOffset:
// GL_ARB_texture_gather is good enough for 2D non-shadow textures with no component argument
if (! fnCandidate[0].type->getSampler().shadow)
compArg = 3;
break;
case EOpTextureGatherOffsets:
if (! fnCandidate[0].type->getSampler().shadow)
compArg = 3;
break;
default:
break;
}
if (compArg > 0 && compArg < fnCandidate.getParamCount()) {
if (aggArgs[compArg]->getAsConstantUnion()) {
int value = aggArgs[compArg]->getAsConstantUnion()->getConstArray()[0].getIConst();
if (value < 0 || value > 3)
error(loc, "must be 0, 1, 2, or 3:", feature, "component argument");
} else
error(loc, "must be a compile-time constant:", feature, "component argument");
}
break;
}
case EOpTextureOffset:
case EOpTextureFetchOffset:
case EOpTextureProjOffset:
case EOpTextureLodOffset:
case EOpTextureProjLodOffset:
case EOpTextureGradOffset:
case EOpTextureProjGradOffset:
{
// Handle texture-offset limits checking
// Pick which argument has to hold constant offsets
int arg = -1;
switch (callNode.getOp()) {
case EOpTextureOffset: arg = 2; break;
case EOpTextureFetchOffset: arg = (arg0->getType().getSampler().dim != EsdRect) ? 3 : 2; break;
case EOpTextureProjOffset: arg = 2; break;
case EOpTextureLodOffset: arg = 3; break;
case EOpTextureProjLodOffset: arg = 3; break;
case EOpTextureGradOffset: arg = 4; break;
case EOpTextureProjGradOffset: arg = 4; break;
default:
assert(0);
break;
}
if (arg > 0) {
if (aggArgs[arg]->getAsConstantUnion() == nullptr)
error(loc, "argument must be compile-time constant", "texel offset", "");
else {
const TType& type = aggArgs[arg]->getAsTyped()->getType();
for (int c = 0; c < type.getVectorSize(); ++c) {
int offset = aggArgs[arg]->getAsConstantUnion()->getConstArray()[c].getIConst();
if (offset > resources.maxProgramTexelOffset || offset < resources.minProgramTexelOffset)
error(loc, "value is out of range:", "texel offset",
"[gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]");
}
}
}
break;
}
case EOpTextureQuerySamples:
case EOpImageQuerySamples:
break;
case EOpImageAtomicAdd:
case EOpImageAtomicMin:
case EOpImageAtomicMax:
case EOpImageAtomicAnd:
case EOpImageAtomicOr:
case EOpImageAtomicXor:
case EOpImageAtomicExchange:
case EOpImageAtomicCompSwap:
break;
case EOpInterpolateAtCentroid:
case EOpInterpolateAtSample:
case EOpInterpolateAtOffset:
// TODO(greg-lunarg): Re-enable this check. It currently gives false errors for builtins
// defined and passed as members of a struct. In this case the storage class is showing to be
// Function. See glslang #2584
// Make sure the first argument is an interpolant, or an array element of an interpolant
// if (arg0->getType().getQualifier().storage != EvqVaryingIn) {
// It might still be an array element.
//
// We could check more, but the semantics of the first argument are already met; the
// only way to turn an array into a float/vec* is array dereference and swizzle.
//
// ES and desktop 4.3 and earlier: swizzles may not be used
// desktop 4.4 and later: swizzles may be used
// const TIntermTyped* base = TIntermediate::findLValueBase(arg0, true);
// if (base == nullptr || base->getType().getQualifier().storage != EvqVaryingIn)
// error(loc, "first argument must be an interpolant, or interpolant-array element",
// fnCandidate.getName().c_str(), "");
// }
break;
default:
break;
}
}
//
// Handle seeing something in a grammar production that can be done by calling
// a constructor.
//
// The constructor still must be "handled" by handleFunctionCall(), which will
// then call handleConstructor().
//
TFunction* HlslParseContext::makeConstructorCall(const TSourceLoc& loc, const TType& type)
{
TOperator op = intermediate.mapTypeToConstructorOp(type);
if (op == EOpNull) {
error(loc, "cannot construct this type", type.getBasicString(), "");
return nullptr;
}
TString empty("");
return new TFunction(&empty, type, op);
}
//
// Handle seeing a "COLON semantic" at the end of a type declaration,
// by updating the type according to the semantic.
//
void HlslParseContext::handleSemantic(TSourceLoc loc, TQualifier& qualifier, TBuiltInVariable builtIn,
const TString& upperCase)
{
// Parse and return semantic number. If limit is 0, it will be ignored. Otherwise, if the parsed
// semantic number is >= limit, errorMsg is issued and 0 is returned.
// TODO: it would be nicer if limit and errorMsg had default parameters, but some compilers don't yet
// accept those in lambda functions.
const auto getSemanticNumber = [this, loc](const TString& semantic, unsigned int limit, const char* errorMsg) -> unsigned int {
size_t pos = semantic.find_last_not_of("0123456789");
if (pos == std::string::npos)
return 0u;
unsigned int semanticNum = (unsigned int)atoi(semantic.c_str() + pos + 1);
if (limit != 0 && semanticNum >= limit) {
error(loc, errorMsg, semantic.c_str(), "");
return 0u;
}
return semanticNum;
};
if (builtIn == EbvNone && hlslDX9Compatible()) {
if (language == EShLangVertex) {
if (qualifier.isParamOutput()) {
if (upperCase == "POSITION") {
builtIn = EbvPosition;
}
if (upperCase == "PSIZE") {
builtIn = EbvPointSize;
}
}
} else if (language == EShLangFragment) {
if (qualifier.isParamInput() && upperCase == "VPOS") {
builtIn = EbvFragCoord;
}
if (qualifier.isParamOutput()) {
if (upperCase.compare(0, 5, "COLOR") == 0) {
qualifier.layoutLocation = getSemanticNumber(upperCase, 0, nullptr);
nextOutLocation = std::max(nextOutLocation, qualifier.layoutLocation + 1u);
}
if (upperCase == "DEPTH") {
builtIn = EbvFragDepth;
}
}
}
}
switch(builtIn) {
case EbvNone:
// Get location numbers from fragment outputs, instead of
// auto-assigning them.
if (language == EShLangFragment && upperCase.compare(0, 9, "SV_TARGET") == 0) {
qualifier.layoutLocation = getSemanticNumber(upperCase, 0, nullptr);
nextOutLocation = std::max(nextOutLocation, qualifier.layoutLocation + 1u);
} else if (upperCase.compare(0, 15, "SV_CLIPDISTANCE") == 0) {
builtIn = EbvClipDistance;
qualifier.layoutLocation = getSemanticNumber(upperCase, maxClipCullRegs, "invalid clip semantic");
} else if (upperCase.compare(0, 15, "SV_CULLDISTANCE") == 0) {
builtIn = EbvCullDistance;
qualifier.layoutLocation = getSemanticNumber(upperCase, maxClipCullRegs, "invalid cull semantic");
}
break;
case EbvPosition:
// adjust for stage in/out
if (language == EShLangFragment)
builtIn = EbvFragCoord;
break;
case EbvFragStencilRef:
error(loc, "unimplemented; need ARB_shader_stencil_export", "SV_STENCILREF", "");
break;
case EbvTessLevelInner:
case EbvTessLevelOuter:
qualifier.patch = true;
break;
default:
break;
}
if (qualifier.builtIn == EbvNone)
qualifier.builtIn = builtIn;
qualifier.semanticName = intermediate.addSemanticName(upperCase);
}
//
// Handle seeing something like "PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN"
//
// 'location' has the "c[Subcomponent]" part.
// 'component' points to the "component" part, or nullptr if not present.
//
void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TQualifier& qualifier, const glslang::TString& location,
const glslang::TString* component)
{
if (location.size() == 0 || location[0] != 'c') {
error(loc, "expected 'c'", "packoffset", "");
return;
}
if (location.size() == 1)
return;
if (! isdigit(location[1])) {
error(loc, "expected number after 'c'", "packoffset", "");
return;
}
qualifier.layoutOffset = 16 * atoi(location.substr(1, location.size()).c_str());
if (component != nullptr) {
int componentOffset = 0;
switch ((*component)[0]) {
case 'x': componentOffset = 0; break;
case 'y': componentOffset = 4; break;
case 'z': componentOffset = 8; break;
case 'w': componentOffset = 12; break;
default:
componentOffset = -1;
break;
}
if (componentOffset < 0 || component->size() > 1) {
error(loc, "expected {x, y, z, w} for component", "packoffset", "");
return;
}
qualifier.layoutOffset += componentOffset;
}
}
//
// Handle seeing something like "REGISTER LEFT_PAREN [shader_profile,] Type# RIGHT_PAREN"
//
// 'profile' points to the shader_profile part, or nullptr if not present.
// 'desc' is the type# part.
//
void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifier, const glslang::TString* profile,
const glslang::TString& desc, int subComponent, const glslang::TString* spaceDesc)
{
if (profile != nullptr)
warn(loc, "ignoring shader_profile", "register", "");
if (desc.size() < 1) {
error(loc, "expected register type", "register", "");
return;
}
int regNumber = 0;
if (desc.size() > 1) {
if (isdigit(desc[1]))
regNumber = atoi(desc.substr(1, desc.size()).c_str());
else {
error(loc, "expected register number after register type", "register", "");
return;
}
}
// more information about register types see
// https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/dx-graphics-hlsl-variable-register
const std::vector<std::string>& resourceInfo = intermediate.getResourceSetBinding();
switch (std::tolower(desc[0])) {
case 'c':
// c register is the register slot in the global const buffer
// each slot is a vector of 4 32 bit components
qualifier.layoutOffset = regNumber * 4 * 4;
break;
// const buffer register slot
case 'b':
// textrues and structured buffers
case 't':
// samplers
case 's':
// uav resources
case 'u':
// if nothing else has set the binding, do so now
// (other mechanisms override this one)
if (!qualifier.hasBinding())
qualifier.layoutBinding = regNumber + subComponent;
// This handles per-register layout sets numbers. For the global mode which sets
// every symbol to the same value, see setLinkageLayoutSets().
if ((resourceInfo.size() % 3) == 0) {
// Apply per-symbol resource set and binding.
for (auto it = resourceInfo.cbegin(); it != resourceInfo.cend(); it = it + 3) {
if (strcmp(desc.c_str(), it[0].c_str()) == 0) {
qualifier.layoutSet = atoi(it[1].c_str());
qualifier.layoutBinding = atoi(it[2].c_str()) + subComponent;
break;
}
}
}
break;
default:
warn(loc, "ignoring unrecognized register type", "register", "%c", desc[0]);
break;
}
// space
unsigned int setNumber;
const auto crackSpace = [&]() -> bool {
const int spaceLen = 5;
if (spaceDesc->size() < spaceLen + 1)
return false;
if (spaceDesc->compare(0, spaceLen, "space") != 0)
return false;
if (! isdigit((*spaceDesc)[spaceLen]))
return false;
setNumber = atoi(spaceDesc->substr(spaceLen, spaceDesc->size()).c_str());
return true;
};
// if nothing else has set the set, do so now
// (other mechanisms override this one)
if (spaceDesc && !qualifier.hasSet()) {
if (! crackSpace()) {
error(loc, "expected spaceN", "register", "");
return;
}
qualifier.layoutSet = setNumber;
}
}
// Convert to a scalar boolean, or if not allowed by HLSL semantics,
// report an error and return nullptr.
TIntermTyped* HlslParseContext::convertConditionalExpression(const TSourceLoc& loc, TIntermTyped* condition,
bool mustBeScalar)
{
if (mustBeScalar && !condition->getType().isScalarOrVec1()) {
error(loc, "requires a scalar", "conditional expression", "");
return nullptr;
}
return intermediate.addConversion(EOpConstructBool, TType(EbtBool, EvqTemporary, condition->getVectorSize()),
condition);
}
//
// Same error message for all places assignments don't work.
//
void HlslParseContext::assignError(const TSourceLoc& loc, const char* op, TString left, TString right)
{
error(loc, "", op, "cannot convert from '%s' to '%s'",
right.c_str(), left.c_str());
}
//
// Same error message for all places unary operations don't work.
//
void HlslParseContext::unaryOpError(const TSourceLoc& loc, const char* op, TString operand)
{
error(loc, " wrong operand type", op,
"no operation '%s' exists that takes an operand of type %s (or there is no acceptable conversion)",
op, operand.c_str());
}
//
// Same error message for all binary operations don't work.
//
void HlslParseContext::binaryOpError(const TSourceLoc& loc, const char* op, TString left, TString right)
{
error(loc, " wrong operand types:", op,
"no operation '%s' exists that takes a left-hand operand of type '%s' and "
"a right operand of type '%s' (or there is no acceptable conversion)",
op, left.c_str(), right.c_str());
}
//
// A basic type of EbtVoid is a key that the name string was seen in the source, but
// it was not found as a variable in the symbol table. If so, give the error
// message and insert a dummy variable in the symbol table to prevent future errors.
//
void HlslParseContext::variableCheck(TIntermTyped*& nodePtr)
{
TIntermSymbol* symbol = nodePtr->getAsSymbolNode();
if (! symbol)
return;
if (symbol->getType().getBasicType() == EbtVoid) {
error(symbol->getLoc(), "undeclared identifier", symbol->getName().c_str(), "");
// Add to symbol table to prevent future error messages on the same name
if (symbol->getName().size() > 0) {
TVariable* fakeVariable = new TVariable(&symbol->getName(), TType(EbtFloat));
symbolTable.insert(*fakeVariable);
// substitute a symbol node for this new variable
nodePtr = intermediate.addSymbol(*fakeVariable, symbol->getLoc());
}
}
}
//
// Both test, and if necessary spit out an error, to see if the node is really
// a constant.
//
void HlslParseContext::constantValueCheck(TIntermTyped* node, const char* token)
{
if (node->getQualifier().storage != EvqConst)
error(node->getLoc(), "constant expression required", token, "");
}
//
// Both test, and if necessary spit out an error, to see if the node is really
// an integer.
//
void HlslParseContext::integerCheck(const TIntermTyped* node, const char* token)
{
if ((node->getBasicType() == EbtInt || node->getBasicType() == EbtUint) && node->isScalar())
return;
error(node->getLoc(), "scalar integer expression required", token, "");
}
//
// Both test, and if necessary spit out an error, to see if we are currently
// globally scoped.
//
void HlslParseContext::globalCheck(const TSourceLoc& loc, const char* token)
{
if (! symbolTable.atGlobalLevel())
error(loc, "not allowed in nested scope", token, "");
}
bool HlslParseContext::builtInName(const TString& /*identifier*/)
{
return false;
}
//
// Make sure there is enough data and not too many arguments provided to the
// constructor to build something of the type of the constructor. Also returns
// the type of the constructor.
//
// Returns true if there was an error in construction.
//
bool HlslParseContext::constructorError(const TSourceLoc& loc, TIntermNode* node, TFunction& function,
TOperator op, TType& type)
{
type.shallowCopy(function.getType());
bool constructingMatrix = false;
switch (op) {
case EOpConstructTextureSampler:
error(loc, "unhandled texture constructor", "constructor", "");
return true;
case EOpConstructMat2x2:
case EOpConstructMat2x3:
case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3x3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4x4:
case EOpConstructDMat2x2:
case EOpConstructDMat2x3:
case EOpConstructDMat2x4:
case EOpConstructDMat3x2:
case EOpConstructDMat3x3:
case EOpConstructDMat3x4:
case EOpConstructDMat4x2:
case EOpConstructDMat4x3:
case EOpConstructDMat4x4:
case EOpConstructIMat2x2:
case EOpConstructIMat2x3:
case EOpConstructIMat2x4:
case EOpConstructIMat3x2:
case EOpConstructIMat3x3:
case EOpConstructIMat3x4:
case EOpConstructIMat4x2:
case EOpConstructIMat4x3:
case EOpConstructIMat4x4:
case EOpConstructUMat2x2:
case EOpConstructUMat2x3:
case EOpConstructUMat2x4:
case EOpConstructUMat3x2:
case EOpConstructUMat3x3:
case EOpConstructUMat3x4:
case EOpConstructUMat4x2:
case EOpConstructUMat4x3:
case EOpConstructUMat4x4:
case EOpConstructBMat2x2:
case EOpConstructBMat2x3:
case EOpConstructBMat2x4:
case EOpConstructBMat3x2:
case EOpConstructBMat3x3:
case EOpConstructBMat3x4:
case EOpConstructBMat4x2:
case EOpConstructBMat4x3:
case EOpConstructBMat4x4:
constructingMatrix = true;
break;
default:
break;
}
//
// Walk the arguments for first-pass checks and collection of information.
//
int size = 0;
bool constType = true;
bool full = false;
bool overFull = false;
bool matrixInMatrix = false;
bool arrayArg = false;
for (int arg = 0; arg < function.getParamCount(); ++arg) {
if (function[arg].type->isArray()) {
if (function[arg].type->isUnsizedArray()) {
// Can't construct from an unsized array.
error(loc, "array argument must be sized", "constructor", "");
return true;
}
arrayArg = true;
}
if (constructingMatrix && function[arg].type->isMatrix())
matrixInMatrix = true;
// 'full' will go to true when enough args have been seen. If we loop
// again, there is an extra argument.
if (full) {
// For vectors and matrices, it's okay to have too many components
// available, but not okay to have unused arguments.
overFull = true;
}
size += function[arg].type->computeNumComponents();
if (op != EOpConstructStruct && ! type.isArray() && size >= type.computeNumComponents())
full = true;
if (function[arg].type->getQualifier().storage != EvqConst)
constType = false;
}
if (constType)
type.getQualifier().storage = EvqConst;
if (type.isArray()) {
if (function.getParamCount() == 0) {
error(loc, "array constructor must have at least one argument", "constructor", "");
return true;
}
if (type.isUnsizedArray()) {
// auto adapt the constructor type to the number of arguments
type.changeOuterArraySize(function.getParamCount());
} else if (type.getOuterArraySize() != function.getParamCount() && type.computeNumComponents() > size) {
error(loc, "array constructor needs one argument per array element", "constructor", "");
return true;
}
if (type.isArrayOfArrays()) {
// Types have to match, but we're still making the type.
// Finish making the type, and the comparison is done later
// when checking for conversion.
TArraySizes& arraySizes = *type.getArraySizes();
// At least the dimensionalities have to match.
if (! function[0].type->isArray() ||
arraySizes.getNumDims() != function[0].type->getArraySizes()->getNumDims() + 1) {
error(loc, "array constructor argument not correct type to construct array element", "constructor", "");
return true;
}
if (arraySizes.isInnerUnsized()) {
// "Arrays of arrays ..., and the size for any dimension is optional"
// That means we need to adopt (from the first argument) the other array sizes into the type.
for (int d = 1; d < arraySizes.getNumDims(); ++d) {
if (arraySizes.getDimSize(d) == UnsizedArraySize) {
arraySizes.setDimSize(d, function[0].type->getArraySizes()->getDimSize(d - 1));
}
}
}
}
}
// Some array -> array type casts are okay
if (arrayArg && function.getParamCount() == 1 && op != EOpConstructStruct && type.isArray() &&
!type.isArrayOfArrays() && !function[0].type->isArrayOfArrays() &&
type.getVectorSize() >= 1 && function[0].type->getVectorSize() >= 1)
return false;
if (arrayArg && op != EOpConstructStruct && ! type.isArrayOfArrays()) {
error(loc, "constructing non-array constituent from array argument", "constructor", "");
return true;
}
if (matrixInMatrix && ! type.isArray()) {
return false;
}
if (overFull) {
error(loc, "too many arguments", "constructor", "");
return true;
}
if (op == EOpConstructStruct && ! type.isArray()) {
if (isScalarConstructor(node))
return false;
// Self-type construction: e.g, we can construct a struct from a single identically typed object.
if (function.getParamCount() == 1 && type == *function[0].type)
return false;
if ((int)type.getStruct()->size() != function.getParamCount()) {
error(loc, "Number of constructor parameters does not match the number of structure fields", "constructor", "");
return true;
}
}
if ((op != EOpConstructStruct && size != 1 && size < type.computeNumComponents()) ||
(op == EOpConstructStruct && size < type.computeNumComponents())) {
error(loc, "not enough data provided for construction", "constructor", "");
return true;
}
return false;
}
// See if 'node', in the context of constructing aggregates, is a scalar argument
// to a constructor.
//
bool HlslParseContext::isScalarConstructor(const TIntermNode* node)
{
// Obviously, it must be a scalar, but an aggregate node might not be fully
// completed yet: holding a sequence of initializers under an aggregate
// would not yet be typed, so don't check it's type. This corresponds to
// the aggregate operator also not being set yet. (An aggregate operation
// that legitimately yields a scalar will have a getOp() of that operator,
// not EOpNull.)
return node->getAsTyped() != nullptr &&
node->getAsTyped()->isScalar() &&
(node->getAsAggregate() == nullptr || node->getAsAggregate()->getOp() != EOpNull);
}
// Checks to see if a void variable has been declared and raise an error message for such a case
//
// returns true in case of an error
//
bool HlslParseContext::voidErrorCheck(const TSourceLoc& loc, const TString& identifier, const TBasicType basicType)
{
if (basicType == EbtVoid) {
error(loc, "illegal use of type 'void'", identifier.c_str(), "");
return true;
}
return false;
}
//
// Fix just a full qualifier (no variables or types yet, but qualifier is complete) at global level.
//
void HlslParseContext::globalQualifierFix(const TSourceLoc&, TQualifier& qualifier)
{
// move from parameter/unknown qualifiers to pipeline in/out qualifiers
switch (qualifier.storage) {
case EvqIn:
qualifier.storage = EvqVaryingIn;
break;
case EvqOut:
qualifier.storage = EvqVaryingOut;
break;
default:
break;
}
}
//
// Merge characteristics of the 'src' qualifier into the 'dst'.
//
void HlslParseContext::mergeQualifiers(TQualifier& dst, const TQualifier& src)
{
// Storage qualification
if (dst.storage == EvqTemporary || dst.storage == EvqGlobal)
dst.storage = src.storage;
else if ((dst.storage == EvqIn && src.storage == EvqOut) ||
(dst.storage == EvqOut && src.storage == EvqIn))
dst.storage = EvqInOut;
else if ((dst.storage == EvqIn && src.storage == EvqConst) ||
(dst.storage == EvqConst && src.storage == EvqIn))
dst.storage = EvqConstReadOnly;
// Layout qualifiers
mergeObjectLayoutQualifiers(dst, src, false);
// individual qualifiers
#define MERGE_SINGLETON(field) dst.field |= src.field;
MERGE_SINGLETON(invariant);
MERGE_SINGLETON(noContraction);
MERGE_SINGLETON(centroid);
MERGE_SINGLETON(smooth);
MERGE_SINGLETON(flat);
MERGE_SINGLETON(nopersp);
MERGE_SINGLETON(patch);
MERGE_SINGLETON(sample);
MERGE_SINGLETON(coherent);
MERGE_SINGLETON(volatil);
MERGE_SINGLETON(restrict);
MERGE_SINGLETON(readonly);
MERGE_SINGLETON(writeonly);
MERGE_SINGLETON(specConstant);
MERGE_SINGLETON(nonUniform);
}
// used to flatten the sampler type space into a single dimension
// correlates with the declaration of defaultSamplerPrecision[]
int HlslParseContext::computeSamplerTypeIndex(TSampler& sampler)
{
int arrayIndex = sampler.arrayed ? 1 : 0;
int shadowIndex = sampler.shadow ? 1 : 0;
int externalIndex = sampler.external ? 1 : 0;
return EsdNumDims *
(EbtNumTypes * (2 * (2 * arrayIndex + shadowIndex) + externalIndex) + sampler.type) + sampler.dim;
}
//
// Do size checking for an array type's size.
//
void HlslParseContext::arraySizeCheck(const TSourceLoc& loc, TIntermTyped* expr, TArraySize& sizePair)
{
bool isConst = false;
sizePair.size = 1;
sizePair.node = nullptr;
TIntermConstantUnion* constant = expr->getAsConstantUnion();
if (constant) {
// handle true (non-specialization) constant
sizePair.size = constant->getConstArray()[0].getIConst();
isConst = true;
} else {
// see if it's a specialization constant instead
if (expr->getQualifier().isSpecConstant()) {
isConst = true;
sizePair.node = expr;
TIntermSymbol* symbol = expr->getAsSymbolNode();
if (symbol && symbol->getConstArray().size() > 0)
sizePair.size = symbol->getConstArray()[0].getIConst();
}
}
if (! isConst || (expr->getBasicType() != EbtInt && expr->getBasicType() != EbtUint)) {
error(loc, "array size must be a constant integer expression", "", "");
return;
}
if (sizePair.size <= 0) {
error(loc, "array size must be a positive integer", "", "");
return;
}
}
//
// Require array to be completely sized
//
void HlslParseContext::arraySizeRequiredCheck(const TSourceLoc& loc, const TArraySizes& arraySizes)
{
if (arraySizes.hasUnsized())
error(loc, "array size required", "", "");
}
void HlslParseContext::structArrayCheck(const TSourceLoc& /*loc*/, const TType& type)
{
const TTypeList& structure = *type.getStruct();
for (int m = 0; m < (int)structure.size(); ++m) {
const TType& member = *structure[m].type;
if (member.isArray())
arraySizeRequiredCheck(structure[m].loc, *member.getArraySizes());
}
}
//
// Do all the semantic checking for declaring or redeclaring an array, with and
// without a size, and make the right changes to the symbol table.
//
void HlslParseContext::declareArray(const TSourceLoc& loc, const TString& identifier, const TType& type,
TSymbol*& symbol, bool track)
{
if (symbol == nullptr) {
bool currentScope;
symbol = symbolTable.find(identifier, nullptr, ¤tScope);
if (symbol && builtInName(identifier) && ! symbolTable.atBuiltInLevel()) {
// bad shader (errors already reported) trying to redeclare a built-in name as an array
return;
}
if (symbol == nullptr || ! currentScope) {
//
// Successfully process a new definition.
// (Redeclarations have to take place at the same scope; otherwise they are hiding declarations)
//
symbol = new TVariable(&identifier, type);
symbolTable.insert(*symbol);
if (track && symbolTable.atGlobalLevel())
trackLinkage(*symbol);
return;
}
if (symbol->getAsAnonMember()) {
error(loc, "cannot redeclare a user-block member array", identifier.c_str(), "");
symbol = nullptr;
return;
}
}
//
// Process a redeclaration.
//
if (symbol == nullptr) {
error(loc, "array variable name expected", identifier.c_str(), "");
return;
}
// redeclareBuiltinVariable() should have already done the copyUp()
TType& existingType = symbol->getWritableType();
if (existingType.isSizedArray()) {
// be more lenient for input arrays to geometry shaders and tessellation control outputs,
// where the redeclaration is the same size
return;
}
existingType.updateArraySizes(type);
}
//
// Enforce non-initializer type/qualifier rules.
//
void HlslParseContext::fixConstInit(const TSourceLoc& loc, const TString& identifier, TType& type,
TIntermTyped*& initializer)
{
//
// Make the qualifier make sense, given that there is an initializer.
//
if (initializer == nullptr) {
if (type.getQualifier().storage == EvqConst ||
type.getQualifier().storage == EvqConstReadOnly) {
initializer = intermediate.makeAggregate(loc);
warn(loc, "variable with qualifier 'const' not initialized; zero initializing", identifier.c_str(), "");
}
}
}
//
// See if the identifier is a built-in symbol that can be redeclared, and if so,
// copy the symbol table's read-only built-in variable to the current
// global level, where it can be modified based on the passed in type.
//
// Returns nullptr if no redeclaration took place; meaning a normal declaration still
// needs to occur for it, not necessarily an error.
//
// Returns a redeclared and type-modified variable if a redeclared occurred.
//
TSymbol* HlslParseContext::redeclareBuiltinVariable(const TSourceLoc& /*loc*/, const TString& identifier,
const TQualifier& /*qualifier*/,
const TShaderQualifiers& /*publicType*/)
{
if (! builtInName(identifier) || symbolTable.atBuiltInLevel() || ! symbolTable.atGlobalLevel())
return nullptr;
return nullptr;
}
//
// Generate index to the array element in a structure buffer (SSBO)
//
TIntermTyped* HlslParseContext::indexStructBufferContent(const TSourceLoc& loc, TIntermTyped* buffer) const
{
// Bail out if not a struct buffer
if (buffer == nullptr || ! isStructBufferType(buffer->getType()))
return nullptr;
// Runtime sized array is always the last element.
const TTypeList* bufferStruct = buffer->getType().getStruct();
TIntermTyped* arrayPosition = intermediate.addConstantUnion(unsigned(bufferStruct->size()-1), loc);
TIntermTyped* argArray = intermediate.addIndex(EOpIndexDirectStruct, buffer, arrayPosition, loc);
argArray->setType(*(*bufferStruct)[bufferStruct->size()-1].type);
return argArray;
}
//
// IFF type is a structuredbuffer/byteaddressbuffer type, return the content
// (template) type. E.g, StructuredBuffer<MyType> -> MyType. Else return nullptr.
//
TType* HlslParseContext::getStructBufferContentType(const TType& type) const
{
if (type.getBasicType() != EbtBlock || type.getQualifier().storage != EvqBuffer)
return nullptr;
const int memberCount = (int)type.getStruct()->size();
assert(memberCount > 0);
TType* contentType = (*type.getStruct())[memberCount-1].type;
return contentType->isUnsizedArray() ? contentType : nullptr;
}
//
// If an existing struct buffer has a sharable type, then share it.
//
void HlslParseContext::shareStructBufferType(TType& type)
{
// PackOffset must be equivalent to share types on a per-member basis.
// Note: cannot use auto type due to recursion. Thus, this is a std::function.
const std::function<bool(TType& lhs, TType& rhs)>
compareQualifiers = [&](TType& lhs, TType& rhs) -> bool {
if (lhs.getQualifier().layoutOffset != rhs.getQualifier().layoutOffset)
return false;
if (lhs.isStruct() != rhs.isStruct())
return false;
if (lhs.getQualifier().builtIn != rhs.getQualifier().builtIn)
return false;
if (lhs.isStruct() && rhs.isStruct()) {
if (lhs.getStruct()->size() != rhs.getStruct()->size())
return false;
for (int i = 0; i < int(lhs.getStruct()->size()); ++i)
if (!compareQualifiers(*(*lhs.getStruct())[i].type, *(*rhs.getStruct())[i].type))
return false;
}
return true;
};
// We need to compare certain qualifiers in addition to the type.
const auto typeEqual = [compareQualifiers](TType& lhs, TType& rhs) -> bool {
if (lhs.getQualifier().readonly != rhs.getQualifier().readonly)
return false;
// If both are structures, recursively look for packOffset equality
// as well as type equality.
return compareQualifiers(lhs, rhs) && lhs == rhs;
};
// This is an exhaustive O(N) search, but real world shaders have
// only a small number of these.
for (int idx = 0; idx < int(structBufferTypes.size()); ++idx) {
// If the deep structure matches, modulo qualifiers, use it
if (typeEqual(*structBufferTypes[idx], type)) {
type.shallowCopy(*structBufferTypes[idx]);
return;
}
}
// Otherwise, remember it:
TType* typeCopy = new TType;
typeCopy->shallowCopy(type);
structBufferTypes.push_back(typeCopy);
}
void HlslParseContext::paramFix(TType& type)
{
switch (type.getQualifier().storage) {
case EvqConst:
type.getQualifier().storage = EvqConstReadOnly;
break;
case EvqGlobal:
case EvqTemporary:
type.getQualifier().storage = EvqIn;
break;
case EvqBuffer:
{
// SSBO parameter. These do not go through the declareBlock path since they are fn parameters.
correctUniform(type.getQualifier());
TQualifier bufferQualifier = globalBufferDefaults;
mergeObjectLayoutQualifiers(bufferQualifier, type.getQualifier(), true);
bufferQualifier.storage = type.getQualifier().storage;
bufferQualifier.readonly = type.getQualifier().readonly;
bufferQualifier.coherent = type.getQualifier().coherent;
bufferQualifier.declaredBuiltIn = type.getQualifier().declaredBuiltIn;
type.getQualifier() = bufferQualifier;
break;
}
default:
break;
}
}
void HlslParseContext::specializationCheck(const TSourceLoc& loc, const TType& type, const char* op)
{
if (type.containsSpecializationSize())
error(loc, "can't use with types containing arrays sized with a specialization constant", op, "");
}
//
// Layout qualifier stuff.
//
// Put the id's layout qualification into the public type, for qualifiers not having a number set.
// This is before we know any type information for error checking.
void HlslParseContext::setLayoutQualifier(const TSourceLoc& loc, TQualifier& qualifier, TString& id)
{
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
if (id == TQualifier::getLayoutMatrixString(ElmColumnMajor)) {
qualifier.layoutMatrix = ElmRowMajor;
return;
}
if (id == TQualifier::getLayoutMatrixString(ElmRowMajor)) {
qualifier.layoutMatrix = ElmColumnMajor;
return;
}
if (id == "push_constant") {
requireVulkan(loc, "push_constant");
qualifier.layoutPushConstant = true;
return;
}
if (language == EShLangGeometry || language == EShLangTessEvaluation) {
if (id == TQualifier::getGeometryString(ElgTriangles)) {
// publicType.shaderQualifiers.geometry = ElgTriangles;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (language == EShLangGeometry) {
if (id == TQualifier::getGeometryString(ElgPoints)) {
// publicType.shaderQualifiers.geometry = ElgPoints;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getGeometryString(ElgLineStrip)) {
// publicType.shaderQualifiers.geometry = ElgLineStrip;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getGeometryString(ElgLines)) {
// publicType.shaderQualifiers.geometry = ElgLines;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getGeometryString(ElgLinesAdjacency)) {
// publicType.shaderQualifiers.geometry = ElgLinesAdjacency;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getGeometryString(ElgTrianglesAdjacency)) {
// publicType.shaderQualifiers.geometry = ElgTrianglesAdjacency;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getGeometryString(ElgTriangleStrip)) {
// publicType.shaderQualifiers.geometry = ElgTriangleStrip;
warn(loc, "ignored", id.c_str(), "");
return;
}
} else {
assert(language == EShLangTessEvaluation);
// input primitive
if (id == TQualifier::getGeometryString(ElgTriangles)) {
// publicType.shaderQualifiers.geometry = ElgTriangles;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getGeometryString(ElgQuads)) {
// publicType.shaderQualifiers.geometry = ElgQuads;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getGeometryString(ElgIsolines)) {
// publicType.shaderQualifiers.geometry = ElgIsolines;
warn(loc, "ignored", id.c_str(), "");
return;
}
// vertex spacing
if (id == TQualifier::getVertexSpacingString(EvsEqual)) {
// publicType.shaderQualifiers.spacing = EvsEqual;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getVertexSpacingString(EvsFractionalEven)) {
// publicType.shaderQualifiers.spacing = EvsFractionalEven;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getVertexSpacingString(EvsFractionalOdd)) {
// publicType.shaderQualifiers.spacing = EvsFractionalOdd;
warn(loc, "ignored", id.c_str(), "");
return;
}
// triangle order
if (id == TQualifier::getVertexOrderString(EvoCw)) {
// publicType.shaderQualifiers.order = EvoCw;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == TQualifier::getVertexOrderString(EvoCcw)) {
// publicType.shaderQualifiers.order = EvoCcw;
warn(loc, "ignored", id.c_str(), "");
return;
}
// point mode
if (id == "point_mode") {
// publicType.shaderQualifiers.pointMode = true;
warn(loc, "ignored", id.c_str(), "");
return;
}
}
}
if (language == EShLangFragment) {
if (id == "origin_upper_left") {
// publicType.shaderQualifiers.originUpperLeft = true;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == "pixel_center_integer") {
// publicType.shaderQualifiers.pixelCenterInteger = true;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == "early_fragment_tests") {
// publicType.shaderQualifiers.earlyFragmentTests = true;
warn(loc, "ignored", id.c_str(), "");
return;
}
for (TLayoutDepth depth = (TLayoutDepth)(EldNone + 1); depth < EldCount; depth = (TLayoutDepth)(depth + 1)) {
if (id == TQualifier::getLayoutDepthString(depth)) {
// publicType.shaderQualifiers.layoutDepth = depth;
warn(loc, "ignored", id.c_str(), "");
return;
}
}
if (id.compare(0, 13, "blend_support") == 0) {
bool found = false;
for (TBlendEquationShift be = (TBlendEquationShift)0; be < EBlendCount; be = (TBlendEquationShift)(be + 1)) {
if (id == TQualifier::getBlendEquationString(be)) {
requireExtensions(loc, 1, &E_GL_KHR_blend_equation_advanced, "blend equation");
intermediate.addBlendEquation(be);
// publicType.shaderQualifiers.blendEquation = true;
warn(loc, "ignored", id.c_str(), "");
found = true;
break;
}
}
if (! found)
error(loc, "unknown blend equation", "blend_support", "");
return;
}
}
error(loc, "unrecognized layout identifier, or qualifier requires assignment (e.g., binding = 4)", id.c_str(), "");
}
// Put the id's layout qualifier value into the public type, for qualifiers having a number set.
// This is before we know any type information for error checking.
void HlslParseContext::setLayoutQualifier(const TSourceLoc& loc, TQualifier& qualifier, TString& id,
const TIntermTyped* node)
{
const char* feature = "layout-id value";
// const char* nonLiteralFeature = "non-literal layout-id value";
integerCheck(node, feature);
const TIntermConstantUnion* constUnion = node->getAsConstantUnion();
int value = 0;
if (constUnion) {
value = constUnion->getConstArray()[0].getIConst();
}
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
if (id == "offset") {
qualifier.layoutOffset = value;
return;
} else if (id == "align") {
// "The specified alignment must be a power of 2, or a compile-time error results."
if (! IsPow2(value))
error(loc, "must be a power of 2", "align", "");
else
qualifier.layoutAlign = value;
return;
} else if (id == "location") {
if ((unsigned int)value >= TQualifier::layoutLocationEnd)
error(loc, "location is too large", id.c_str(), "");
else
qualifier.layoutLocation = value;
return;
} else if (id == "set") {
if ((unsigned int)value >= TQualifier::layoutSetEnd)
error(loc, "set is too large", id.c_str(), "");
else
qualifier.layoutSet = value;
return;
} else if (id == "binding") {
if ((unsigned int)value >= TQualifier::layoutBindingEnd)
error(loc, "binding is too large", id.c_str(), "");
else
qualifier.layoutBinding = value;
return;
} else if (id == "component") {
if ((unsigned)value >= TQualifier::layoutComponentEnd)
error(loc, "component is too large", id.c_str(), "");
else
qualifier.layoutComponent = value;
return;
} else if (id.compare(0, 4, "xfb_") == 0) {
// "Any shader making any static use (after preprocessing) of any of these
// *xfb_* qualifiers will cause the shader to be in a transform feedback
// capturing mode and hence responsible for describing the transform feedback
// setup."
intermediate.setXfbMode();
if (id == "xfb_buffer") {
// "It is a compile-time error to specify an *xfb_buffer* that is greater than
// the implementation-dependent constant gl_MaxTransformFeedbackBuffers."
if (value >= resources.maxTransformFeedbackBuffers)
error(loc, "buffer is too large:", id.c_str(), "gl_MaxTransformFeedbackBuffers is %d",
resources.maxTransformFeedbackBuffers);
if (value >= (int)TQualifier::layoutXfbBufferEnd)
error(loc, "buffer is too large:", id.c_str(), "internal max is %d", TQualifier::layoutXfbBufferEnd - 1);
else
qualifier.layoutXfbBuffer = value;
return;
} else if (id == "xfb_offset") {
if (value >= (int)TQualifier::layoutXfbOffsetEnd)
error(loc, "offset is too large:", id.c_str(), "internal max is %d", TQualifier::layoutXfbOffsetEnd - 1);
else
qualifier.layoutXfbOffset = value;
return;
} else if (id == "xfb_stride") {
// "The resulting stride (implicit or explicit), when divided by 4, must be less than or equal to the
// implementation-dependent constant gl_MaxTransformFeedbackInterleavedComponents."
if (value > 4 * resources.maxTransformFeedbackInterleavedComponents)
error(loc, "1/4 stride is too large:", id.c_str(), "gl_MaxTransformFeedbackInterleavedComponents is %d",
resources.maxTransformFeedbackInterleavedComponents);
else if (value >= (int)TQualifier::layoutXfbStrideEnd)
error(loc, "stride is too large:", id.c_str(), "internal max is %d", TQualifier::layoutXfbStrideEnd - 1);
if (value < (int)TQualifier::layoutXfbStrideEnd)
qualifier.layoutXfbStride = value;
return;
}
}
if (id == "input_attachment_index") {
requireVulkan(loc, "input_attachment_index");
if (value >= (int)TQualifier::layoutAttachmentEnd)
error(loc, "attachment index is too large", id.c_str(), "");
else
qualifier.layoutAttachment = value;
return;
}
if (id == "constant_id") {
setSpecConstantId(loc, qualifier, value);
return;
}
switch (language) {
case EShLangVertex:
break;
case EShLangTessControl:
if (id == "vertices") {
if (value == 0)
error(loc, "must be greater than 0", "vertices", "");
else
// publicType.shaderQualifiers.vertices = value;
warn(loc, "ignored", id.c_str(), "");
return;
}
break;
case EShLangTessEvaluation:
break;
case EShLangGeometry:
if (id == "invocations") {
if (value == 0)
error(loc, "must be at least 1", "invocations", "");
else
// publicType.shaderQualifiers.invocations = value;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == "max_vertices") {
// publicType.shaderQualifiers.vertices = value;
warn(loc, "ignored", id.c_str(), "");
if (value > resources.maxGeometryOutputVertices)
error(loc, "too large, must be less than gl_MaxGeometryOutputVertices", "max_vertices", "");
return;
}
if (id == "stream") {
qualifier.layoutStream = value;
return;
}
break;
case EShLangFragment:
if (id == "index") {
qualifier.layoutIndex = value;
return;
}
break;
case EShLangCompute:
if (id.compare(0, 11, "local_size_") == 0) {
if (id == "local_size_x") {
// publicType.shaderQualifiers.localSize[0] = value;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == "local_size_y") {
// publicType.shaderQualifiers.localSize[1] = value;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == "local_size_z") {
// publicType.shaderQualifiers.localSize[2] = value;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (spvVersion.spv != 0) {
if (id == "local_size_x_id") {
// publicType.shaderQualifiers.localSizeSpecId[0] = value;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == "local_size_y_id") {
// publicType.shaderQualifiers.localSizeSpecId[1] = value;
warn(loc, "ignored", id.c_str(), "");
return;
}
if (id == "local_size_z_id") {
// publicType.shaderQualifiers.localSizeSpecId[2] = value;
warn(loc, "ignored", id.c_str(), "");
return;
}
}
}
break;
default:
break;
}
error(loc, "there is no such layout identifier for this stage taking an assigned value", id.c_str(), "");
}
void HlslParseContext::setSpecConstantId(const TSourceLoc& loc, TQualifier& qualifier, int value)
{
if (value >= (int)TQualifier::layoutSpecConstantIdEnd) {
error(loc, "specialization-constant id is too large", "constant_id", "");
} else {
qualifier.layoutSpecConstantId = value;
qualifier.specConstant = true;
if (! intermediate.addUsedConstantId(value))
error(loc, "specialization-constant id already used", "constant_id", "");
}
return;
}
// Merge any layout qualifier information from src into dst, leaving everything else in dst alone
//
// "More than one layout qualifier may appear in a single declaration.
// Additionally, the same layout-qualifier-name can occur multiple times
// within a layout qualifier or across multiple layout qualifiers in the
// same declaration. When the same layout-qualifier-name occurs
// multiple times, in a single declaration, the last occurrence overrides
// the former occurrence(s). Further, if such a layout-qualifier-name
// will effect subsequent declarations or other observable behavior, it
// is only the last occurrence that will have any effect, behaving as if
// the earlier occurrence(s) within the declaration are not present.
// This is also true for overriding layout-qualifier-names, where one
// overrides the other (e.g., row_major vs. column_major); only the last
// occurrence has any effect."
//
void HlslParseContext::mergeObjectLayoutQualifiers(TQualifier& dst, const TQualifier& src, bool inheritOnly)
{
if (src.hasMatrix())
dst.layoutMatrix = src.layoutMatrix;
if (src.hasPacking())
dst.layoutPacking = src.layoutPacking;
if (src.hasStream())
dst.layoutStream = src.layoutStream;
if (src.hasFormat())
dst.layoutFormat = src.layoutFormat;
if (src.hasXfbBuffer())
dst.layoutXfbBuffer = src.layoutXfbBuffer;
if (src.hasAlign())
dst.layoutAlign = src.layoutAlign;
if (! inheritOnly) {
if (src.hasLocation())
dst.layoutLocation = src.layoutLocation;
if (src.hasComponent())
dst.layoutComponent = src.layoutComponent;
if (src.hasIndex())
dst.layoutIndex = src.layoutIndex;
if (src.hasOffset())
dst.layoutOffset = src.layoutOffset;
if (src.hasSet())
dst.layoutSet = src.layoutSet;
if (src.layoutBinding != TQualifier::layoutBindingEnd)
dst.layoutBinding = src.layoutBinding;
if (src.hasXfbStride())
dst.layoutXfbStride = src.layoutXfbStride;
if (src.hasXfbOffset())
dst.layoutXfbOffset = src.layoutXfbOffset;
if (src.hasAttachment())
dst.layoutAttachment = src.layoutAttachment;
if (src.hasSpecConstantId())
dst.layoutSpecConstantId = src.layoutSpecConstantId;
if (src.layoutPushConstant)
dst.layoutPushConstant = true;
}
}
//
// Look up a function name in the symbol table, and make sure it is a function.
//
// First, look for an exact match. If there is none, use the generic selector
// TParseContextBase::selectFunction() to find one, parameterized by the
// convertible() and better() predicates defined below.
//
// Return the function symbol if found, otherwise nullptr.
//
const TFunction* HlslParseContext::findFunction(const TSourceLoc& loc, TFunction& call, bool& builtIn, int& thisDepth,
TIntermTyped*& args)
{
if (symbolTable.isFunctionNameVariable(call.getName())) {
error(loc, "can't use function syntax on variable", call.getName().c_str(), "");
return nullptr;
}
// first, look for an exact match
bool dummyScope;
TSymbol* symbol = symbolTable.find(call.getMangledName(), &builtIn, &dummyScope, &thisDepth);
if (symbol)
return symbol->getAsFunction();
// no exact match, use the generic selector, parameterized by the GLSL rules
// create list of candidates to send
TVector<const TFunction*> candidateList;
symbolTable.findFunctionNameList(call.getMangledName(), candidateList, builtIn);
// These built-in ops can accept any type, so we bypass the argument selection
if (candidateList.size() == 1 && builtIn &&
(candidateList[0]->getBuiltInOp() == EOpMethodAppend ||
candidateList[0]->getBuiltInOp() == EOpMethodRestartStrip ||
candidateList[0]->getBuiltInOp() == EOpMethodIncrementCounter ||
candidateList[0]->getBuiltInOp() == EOpMethodDecrementCounter ||
candidateList[0]->getBuiltInOp() == EOpMethodConsume)) {
return candidateList[0];
}
bool allowOnlyUpConversions = true;
// can 'from' convert to 'to'?
const auto convertible = [&](const TType& from, const TType& to, TOperator op, int arg) -> bool {
if (from == to)
return true;
// no aggregate conversions
if (from.isArray() || to.isArray() ||
from.isStruct() || to.isStruct())
return false;
switch (op) {
case EOpInterlockedAdd:
case EOpInterlockedAnd:
case EOpInterlockedCompareExchange:
case EOpInterlockedCompareStore:
case EOpInterlockedExchange:
case EOpInterlockedMax:
case EOpInterlockedMin:
case EOpInterlockedOr:
case EOpInterlockedXor:
// We do not promote the texture or image type for these ocodes. Normally that would not
// be an issue because it's a buffer, but we haven't decomposed the opcode yet, and at this
// stage it's merely e.g, a basic integer type.
//
// Instead, we want to promote other arguments, but stay within the same family. In other
// words, InterlockedAdd(RWBuffer<int>, ...) will always use the int flavor, never the uint flavor,
// but it is allowed to promote its other arguments.
if (arg == 0)
return false;
break;
case EOpMethodSample:
case EOpMethodSampleBias:
case EOpMethodSampleCmp:
case EOpMethodSampleCmpLevelZero:
case EOpMethodSampleGrad:
case EOpMethodSampleLevel:
case EOpMethodLoad:
case EOpMethodGetDimensions:
case EOpMethodGetSamplePosition:
case EOpMethodGather:
case EOpMethodCalculateLevelOfDetail:
case EOpMethodCalculateLevelOfDetailUnclamped:
case EOpMethodGatherRed:
case EOpMethodGatherGreen:
case EOpMethodGatherBlue:
case EOpMethodGatherAlpha:
case EOpMethodGatherCmp:
case EOpMethodGatherCmpRed:
case EOpMethodGatherCmpGreen:
case EOpMethodGatherCmpBlue:
case EOpMethodGatherCmpAlpha:
case EOpMethodAppend:
case EOpMethodRestartStrip:
// those are method calls, the object type can not be changed
// they are equal if the dim and type match (is dim sufficient?)
if (arg == 0)
return from.getSampler().type == to.getSampler().type &&
from.getSampler().arrayed == to.getSampler().arrayed &&
from.getSampler().shadow == to.getSampler().shadow &&
from.getSampler().ms == to.getSampler().ms &&
from.getSampler().dim == to.getSampler().dim;
break;
default:
break;
}
// basic types have to be convertible
if (allowOnlyUpConversions)
if (! intermediate.canImplicitlyPromote(from.getBasicType(), to.getBasicType(), EOpFunctionCall))
return false;
// shapes have to be convertible
if ((from.isScalarOrVec1() && to.isScalarOrVec1()) ||
(from.isScalarOrVec1() && to.isVector()) ||
(from.isScalarOrVec1() && to.isMatrix()) ||
(from.isVector() && to.isVector() && from.getVectorSize() >= to.getVectorSize()))
return true;
// TODO: what are the matrix rules? they go here
return false;
};
// Is 'to2' a better conversion than 'to1'?
// Ties should not be considered as better.
// Assumes 'convertible' already said true.
const auto better = [](const TType& from, const TType& to1, const TType& to2) -> bool {
// exact match is always better than mismatch
if (from == to2)
return from != to1;
if (from == to1)
return false;
// shape changes are always worse
if (from.isScalar() || from.isVector()) {
if (from.getVectorSize() == to2.getVectorSize() &&
from.getVectorSize() != to1.getVectorSize())
return true;
if (from.getVectorSize() == to1.getVectorSize() &&
from.getVectorSize() != to2.getVectorSize())
return false;
}
// Handle sampler betterness: An exact sampler match beats a non-exact match.
// (If we just looked at basic type, all EbtSamplers would look the same).
// If any type is not a sampler, just use the linearize function below.
if (from.getBasicType() == EbtSampler && to1.getBasicType() == EbtSampler && to2.getBasicType() == EbtSampler) {
// We can ignore the vector size in the comparison.
TSampler to1Sampler = to1.getSampler();
TSampler to2Sampler = to2.getSampler();
to1Sampler.vectorSize = to2Sampler.vectorSize = from.getSampler().vectorSize;
if (from.getSampler() == to2Sampler)
return from.getSampler() != to1Sampler;
if (from.getSampler() == to1Sampler)
return false;
}
// Might or might not be changing shape, which means basic type might
// or might not match, so within that, the question is how big a
// basic-type conversion is being done.
//
// Use a hierarchy of domains, translated to order of magnitude
// in a linearized view:
// - floating-point vs. integer
// - 32 vs. 64 bit (or width in general)
// - bool vs. non bool
// - signed vs. not signed
const auto linearize = [](const TBasicType& basicType) -> int {
switch (basicType) {
case EbtBool: return 1;
case EbtInt: return 10;
case EbtUint: return 11;
case EbtInt64: return 20;
case EbtUint64: return 21;
case EbtFloat: return 100;
case EbtDouble: return 110;
default: return 0;
}
};
return abs(linearize(to2.getBasicType()) - linearize(from.getBasicType())) <
abs(linearize(to1.getBasicType()) - linearize(from.getBasicType()));
};
// for ambiguity reporting
bool tie = false;
// send to the generic selector
const TFunction* bestMatch = nullptr;
// printf has var args and is in the symbol table as "printf()",
// mangled to "printf("
if (call.getName() == "printf") {
TSymbol* symbol = symbolTable.find("printf(", &builtIn);
if (symbol)
return symbol->getAsFunction();
}
bestMatch = selectFunction(candidateList, call, convertible, better, tie);
if (bestMatch == nullptr) {
// If there is nothing selected by allowing only up-conversions (to a larger linearize() value),
// we instead try down-conversions, which are valid in HLSL, but not preferred if there are any
// upconversions possible.
allowOnlyUpConversions = false;
bestMatch = selectFunction(candidateList, call, convertible, better, tie);
}
if (bestMatch == nullptr) {
error(loc, "no matching overloaded function found", call.getName().c_str(), "");
return nullptr;
}
// For built-ins, we can convert across the arguments. This will happen in several steps:
// Step 1: If there's an exact match, use it.
// Step 2a: Otherwise, get the operator from the best match and promote arguments:
// Step 2b: reconstruct the TFunction based on the new arg types
// Step 3: Re-select after type promotion is applied, to find proper candidate.
if (builtIn) {
// Step 1: If there's an exact match, use it.
if (call.getMangledName() == bestMatch->getMangledName())
return bestMatch;
// Step 2a: Otherwise, get the operator from the best match and promote arguments as if we
// are that kind of operator.
if (args != nullptr) {
// The arg list can be a unary node, or an aggregate. We have to handle both.
// We will use the normal promote() facilities, which require an interm node.
TIntermOperator* promote = nullptr;
if (call.getParamCount() == 1) {
promote = new TIntermUnary(bestMatch->getBuiltInOp());
promote->getAsUnaryNode()->setOperand(args->getAsTyped());
} else {
promote = new TIntermAggregate(bestMatch->getBuiltInOp());
promote->getAsAggregate()->getSequence().swap(args->getAsAggregate()->getSequence());
}
if (! intermediate.promote(promote))
return nullptr;
// Obtain the promoted arg list.
if (call.getParamCount() == 1) {
args = promote->getAsUnaryNode()->getOperand();
} else {
promote->getAsAggregate()->getSequence().swap(args->getAsAggregate()->getSequence());
}
}
// Step 2b: reconstruct the TFunction based on the new arg types
TFunction convertedCall(&call.getName(), call.getType(), call.getBuiltInOp());
if (args->getAsAggregate()) {
// Handle aggregates: put all args into the new function call
for (int arg = 0; arg < int(args->getAsAggregate()->getSequence().size()); ++arg) {
// TODO: But for constness, we could avoid the new & shallowCopy, and use the pointer directly.
TParameter param = { nullptr, new TType, nullptr };
param.type->shallowCopy(args->getAsAggregate()->getSequence()[arg]->getAsTyped()->getType());
convertedCall.addParameter(param);
}
} else if (args->getAsUnaryNode()) {
// Handle unaries: put all args into the new function call
TParameter param = { nullptr, new TType, nullptr };
param.type->shallowCopy(args->getAsUnaryNode()->getOperand()->getAsTyped()->getType());
convertedCall.addParameter(param);
} else if (args->getAsTyped()) {
// Handle bare e.g, floats, not in an aggregate.
TParameter param = { nullptr, new TType, nullptr };
param.type->shallowCopy(args->getAsTyped()->getType());
convertedCall.addParameter(param);
} else {
assert(0); // unknown argument list.
return nullptr;
}
// Step 3: Re-select after type promotion, to find proper candidate
// send to the generic selector
bestMatch = selectFunction(candidateList, convertedCall, convertible, better, tie);
// At this point, there should be no tie.
}
if (tie)
error(loc, "ambiguous best function under implicit type conversion", call.getName().c_str(), "");
// Append default parameter values if needed
if (!tie && bestMatch != nullptr) {
for (int defParam = call.getParamCount(); defParam < bestMatch->getParamCount(); ++defParam) {
handleFunctionArgument(&call, args, (*bestMatch)[defParam].defaultValue);
}
}
return bestMatch;
}
//
// Do everything necessary to handle a typedef declaration, for a single symbol.
//
// 'parseType' is the type part of the declaration (to the left)
// 'arraySizes' is the arrayness tagged on the identifier (to the right)
//
void HlslParseContext::declareTypedef(const TSourceLoc& loc, const TString& identifier, const TType& parseType)
{
TVariable* typeSymbol = new TVariable(&identifier, parseType, true);
if (! symbolTable.insert(*typeSymbol))
error(loc, "name already defined", "typedef", identifier.c_str());
}
// Do everything necessary to handle a struct declaration, including
// making IO aliases because HLSL allows mixed IO in a struct that specializes
// based on the usage (input, output, uniform, none).
void HlslParseContext::declareStruct(const TSourceLoc& loc, TString& structName, TType& type)
{
// If it was named, which means the type can be reused later, add
// it to the symbol table. (Unless it's a block, in which
// case the name is not a type.)
if (type.getBasicType() == EbtBlock || structName.size() == 0)
return;
TVariable* userTypeDef = new TVariable(&structName, type, true);
if (! symbolTable.insert(*userTypeDef)) {
error(loc, "redefinition", structName.c_str(), "struct");
return;
}
// See if we need IO aliases for the structure typeList
const auto condAlloc = [](bool pred, TTypeList*& list) {
if (pred && list == nullptr)
list = new TTypeList;
};
tIoKinds newLists = { nullptr, nullptr, nullptr }; // allocate for each kind found
for (auto member = type.getStruct()->begin(); member != type.getStruct()->end(); ++member) {
condAlloc(hasUniform(member->type->getQualifier()), newLists.uniform);
condAlloc( hasInput(member->type->getQualifier()), newLists.input);
condAlloc( hasOutput(member->type->getQualifier()), newLists.output);
if (member->type->isStruct()) {
auto it = ioTypeMap.find(member->type->getStruct());
if (it != ioTypeMap.end()) {
condAlloc(it->second.uniform != nullptr, newLists.uniform);
condAlloc(it->second.input != nullptr, newLists.input);
condAlloc(it->second.output != nullptr, newLists.output);
}
}
}
if (newLists.uniform == nullptr &&
newLists.input == nullptr &&
newLists.output == nullptr) {
// Won't do any IO caching, clear up the type and get out now.
for (auto member = type.getStruct()->begin(); member != type.getStruct()->end(); ++member)
clearUniformInputOutput(member->type->getQualifier());
return;
}
// We have IO involved.
// Make a pure typeList for the symbol table, and cache side copies of IO versions.
for (auto member = type.getStruct()->begin(); member != type.getStruct()->end(); ++member) {
const auto inheritStruct = [&](TTypeList* s, TTypeLoc& ioMember) {
if (s != nullptr) {
ioMember.type = new TType;
ioMember.type->shallowCopy(*member->type);
ioMember.type->setStruct(s);
}
};
const auto newMember = [&](TTypeLoc& m) {
if (m.type == nullptr) {
m.type = new TType;
m.type->shallowCopy(*member->type);
}
};
TTypeLoc newUniformMember = { nullptr, member->loc };
TTypeLoc newInputMember = { nullptr, member->loc };
TTypeLoc newOutputMember = { nullptr, member->loc };
if (member->type->isStruct()) {
// swap in an IO child if there is one
auto it = ioTypeMap.find(member->type->getStruct());
if (it != ioTypeMap.end()) {
inheritStruct(it->second.uniform, newUniformMember);
inheritStruct(it->second.input, newInputMember);
inheritStruct(it->second.output, newOutputMember);
}
}
if (newLists.uniform) {
newMember(newUniformMember);
// inherit default matrix layout (changeable via #pragma pack_matrix), if none given.
if (member->type->isMatrix() && member->type->getQualifier().layoutMatrix == ElmNone)
newUniformMember.type->getQualifier().layoutMatrix = globalUniformDefaults.layoutMatrix;
correctUniform(newUniformMember.type->getQualifier());
newLists.uniform->push_back(newUniformMember);
}
if (newLists.input) {
newMember(newInputMember);
correctInput(newInputMember.type->getQualifier());
newLists.input->push_back(newInputMember);
}
if (newLists.output) {
newMember(newOutputMember);
correctOutput(newOutputMember.type->getQualifier());
newLists.output->push_back(newOutputMember);
}
// make original pure
clearUniformInputOutput(member->type->getQualifier());
}
ioTypeMap[type.getStruct()] = newLists;
}
// Lookup a user-type by name.
// If found, fill in the type and return the defining symbol.
// If not found, return nullptr.
TSymbol* HlslParseContext::lookupUserType(const TString& typeName, TType& type)
{
TSymbol* symbol = symbolTable.find(typeName);
if (symbol && symbol->getAsVariable() && symbol->getAsVariable()->isUserType()) {
type.shallowCopy(symbol->getType());
return symbol;
} else
return nullptr;
}
//
// Do everything necessary to handle a variable (non-block) declaration.
// Either redeclaring a variable, or making a new one, updating the symbol
// table, and all error checking.
//
// Returns a subtree node that computes an initializer, if needed.
// Returns nullptr if there is no code to execute for initialization.
//
// 'parseType' is the type part of the declaration (to the left)
// 'arraySizes' is the arrayness tagged on the identifier (to the right)
//
TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, const TString& identifier, TType& type,
TIntermTyped* initializer)
{
if (voidErrorCheck(loc, identifier, type.getBasicType()))
return nullptr;
// Global consts with initializers that are non-const act like EvqGlobal in HLSL.
// This test is implicitly recursive, because initializers propagate constness
// up the aggregate node tree during creation. E.g, for:
// { { 1, 2 }, { 3, 4 } }
// the initializer list is marked EvqConst at the top node, and remains so here. However:
// { 1, { myvar, 2 }, 3 }
// is not a const intializer, and still becomes EvqGlobal here.
const bool nonConstInitializer = (initializer != nullptr && initializer->getQualifier().storage != EvqConst);
if (type.getQualifier().storage == EvqConst && symbolTable.atGlobalLevel() && nonConstInitializer) {
// Force to global
type.getQualifier().storage = EvqGlobal;
}
// make const and initialization consistent
fixConstInit(loc, identifier, type, initializer);
// Check for redeclaration of built-ins and/or attempting to declare a reserved name
TSymbol* symbol = nullptr;
inheritGlobalDefaults(type.getQualifier());
const bool flattenVar = shouldFlatten(type, type.getQualifier().storage, true);
// correct IO in the type
switch (type.getQualifier().storage) {
case EvqGlobal:
case EvqTemporary:
clearUniformInputOutput(type.getQualifier());
break;
case EvqUniform:
case EvqBuffer:
correctUniform(type.getQualifier());
if (type.isStruct()) {
auto it = ioTypeMap.find(type.getStruct());
if (it != ioTypeMap.end())
type.setStruct(it->second.uniform);
}
break;
default:
break;
}
// Declare the variable
if (type.isArray()) {
// array case
declareArray(loc, identifier, type, symbol, !flattenVar);
} else {
// non-array case
if (symbol == nullptr)
symbol = declareNonArray(loc, identifier, type, !flattenVar);
else if (type != symbol->getType())
error(loc, "cannot change the type of", "redeclaration", symbol->getName().c_str());
}
if (symbol == nullptr)
return nullptr;
if (flattenVar)
flatten(*symbol->getAsVariable(), symbolTable.atGlobalLevel());
TVariable* variable = symbol->getAsVariable();
if (initializer == nullptr) {
if (intermediate.getDebugInfo())
return executeDeclaration(loc, variable);
else
return nullptr;
}
// Deal with initializer
if (variable == nullptr) {
error(loc, "initializer requires a variable, not a member", identifier.c_str(), "");
return nullptr;
}
return executeInitializer(loc, initializer, variable);
}
// Pick up global defaults from the provide global defaults into dst.
void HlslParseContext::inheritGlobalDefaults(TQualifier& dst) const
{
if (dst.storage == EvqVaryingOut) {
if (! dst.hasStream() && language == EShLangGeometry)
dst.layoutStream = globalOutputDefaults.layoutStream;
if (! dst.hasXfbBuffer())
dst.layoutXfbBuffer = globalOutputDefaults.layoutXfbBuffer;
}
}
//
// Make an internal-only variable whose name is for debug purposes only
// and won't be searched for. Callers will only use the return value to use
// the variable, not the name to look it up. It is okay if the name
// is the same as other names; there won't be any conflict.
//
TVariable* HlslParseContext::makeInternalVariable(const char* name, const TType& type) const
{
TString* nameString = NewPoolTString(name);
TVariable* variable = new TVariable(nameString, type);
symbolTable.makeInternalVariable(*variable);
return variable;
}
// Make a symbol node holding a new internal temporary variable.
TIntermSymbol* HlslParseContext::makeInternalVariableNode(const TSourceLoc& loc, const char* name,
const TType& type) const
{
TVariable* tmpVar = makeInternalVariable(name, type);
tmpVar->getWritableType().getQualifier().makeTemporary();
return intermediate.addSymbol(*tmpVar, loc);
}
//
// Declare a non-array variable, the main point being there is no redeclaration
// for resizing allowed.
//
// Return the successfully declared variable.
//
TVariable* HlslParseContext::declareNonArray(const TSourceLoc& loc, const TString& identifier, const TType& type,
bool track)
{
// make a new variable
TVariable* variable = new TVariable(&identifier, type);
// add variable to symbol table
if (symbolTable.insert(*variable)) {
if (track && symbolTable.atGlobalLevel())
trackLinkage(*variable);
return variable;
}
error(loc, "redefinition", variable->getName().c_str(), "");
return nullptr;
}
// Return a declaration of a temporary variable
//
// This is used to force a variable to be declared in the correct scope
// when debug information is being generated.
TIntermNode* HlslParseContext::executeDeclaration(const TSourceLoc& loc, TVariable* variable)
{
//
// Identifier must be of type temporary.
//
TStorageQualifier qualifier = variable->getType().getQualifier().storage;
if (qualifier != EvqTemporary)
return nullptr;
TIntermSymbol* intermSymbol = intermediate.addSymbol(*variable, loc);
return handleDeclare(loc, intermSymbol);
}
//
// Handle all types of initializers from the grammar.
//
// Returning nullptr just means there is no code to execute to handle the
// initializer, which will, for example, be the case for constant initializers.
//
// Returns a subtree that accomplished the initialization.
//
TIntermNode* HlslParseContext::executeInitializer(const TSourceLoc& loc, TIntermTyped* initializer, TVariable* variable)
{
//
// Identifier must be of type constant, a global, or a temporary, and
// starting at version 120, desktop allows uniforms to have initializers.
//
TStorageQualifier qualifier = variable->getType().getQualifier().storage;
//
// If the initializer was from braces { ... }, we convert the whole subtree to a
// constructor-style subtree, allowing the rest of the code to operate
// identically for both kinds of initializers.
//
//
// Type can't be deduced from the initializer list, so a skeletal type to
// follow has to be passed in. Constness and specialization-constness
// should be deduced bottom up, not dictated by the skeletal type.
//
TType skeletalType;
skeletalType.shallowCopy(variable->getType());
skeletalType.getQualifier().makeTemporary();
if (initializer->getAsAggregate() && initializer->getAsAggregate()->getOp() == EOpNull)
initializer = convertInitializerList(loc, skeletalType, initializer, nullptr);
if (initializer == nullptr) {
// error recovery; don't leave const without constant values
if (qualifier == EvqConst)
variable->getWritableType().getQualifier().storage = EvqTemporary;
return nullptr;
}
// Fix outer arrayness if variable is unsized, getting size from the initializer
if (initializer->getType().isSizedArray() && variable->getType().isUnsizedArray())
variable->getWritableType().changeOuterArraySize(initializer->getType().getOuterArraySize());
// Inner arrayness can also get set by an initializer
if (initializer->getType().isArrayOfArrays() && variable->getType().isArrayOfArrays() &&
initializer->getType().getArraySizes()->getNumDims() ==
variable->getType().getArraySizes()->getNumDims()) {
// adopt unsized sizes from the initializer's sizes
for (int d = 1; d < variable->getType().getArraySizes()->getNumDims(); ++d) {
if (variable->getType().getArraySizes()->getDimSize(d) == UnsizedArraySize) {
variable->getWritableType().getArraySizes()->setDimSize(d,
initializer->getType().getArraySizes()->getDimSize(d));
}
}
}
// Uniform and global consts require a constant initializer
if (qualifier == EvqUniform && initializer->getType().getQualifier().storage != EvqConst) {
error(loc, "uniform initializers must be constant", "=", "'%s'", variable->getType().getCompleteString().c_str());
variable->getWritableType().getQualifier().storage = EvqTemporary;
return nullptr;
}
// Const variables require a constant initializer
if (qualifier == EvqConst) {
if (initializer->getType().getQualifier().storage != EvqConst) {
variable->getWritableType().getQualifier().storage = EvqConstReadOnly;
qualifier = EvqConstReadOnly;
}
}
if (qualifier == EvqConst || qualifier == EvqUniform) {
// Compile-time tagging of the variable with its constant value...
initializer = intermediate.addConversion(EOpAssign, variable->getType(), initializer);
if (initializer != nullptr && variable->getType() != initializer->getType())
initializer = intermediate.addUniShapeConversion(EOpAssign, variable->getType(), initializer);
if (initializer == nullptr || !initializer->getAsConstantUnion() ||
variable->getType() != initializer->getType()) {
error(loc, "non-matching or non-convertible constant type for const initializer",
variable->getType().getStorageQualifierString(), "");
variable->getWritableType().getQualifier().storage = EvqTemporary;
return nullptr;
}
variable->setConstArray(initializer->getAsConstantUnion()->getConstArray());
} else {
// normal assigning of a value to a variable...
specializationCheck(loc, initializer->getType(), "initializer");
TIntermSymbol* intermSymbol = intermediate.addSymbol(*variable, loc);
TIntermNode* initNode = handleAssign(loc, EOpAssign, intermSymbol, initializer);
if (initNode == nullptr)
assignError(loc, "=", intermSymbol->getCompleteString(), initializer->getCompleteString());
return initNode;
}
return nullptr;
}
//
// Reprocess any initializer-list { ... } parts of the initializer.
// Need to hierarchically assign correct types and implicit
// conversions. Will do this mimicking the same process used for
// creating a constructor-style initializer, ensuring we get the
// same form.
//
// Returns a node representing an expression for the initializer list expressed
// as the correct type.
//
// Returns nullptr if there is an error.
//
TIntermTyped* HlslParseContext::convertInitializerList(const TSourceLoc& loc, const TType& type,
TIntermTyped* initializer, TIntermTyped* scalarInit)
{
// Will operate recursively. Once a subtree is found that is constructor style,
// everything below it is already good: Only the "top part" of the initializer
// can be an initializer list, where "top part" can extend for several (or all) levels.
// see if we have bottomed out in the tree within the initializer-list part
TIntermAggregate* initList = initializer->getAsAggregate();
if (initList == nullptr || initList->getOp() != EOpNull) {
// We don't have a list, but if it's a scalar and the 'type' is a
// composite, we need to lengthen below to make it useful.
// Otherwise, this is an already formed object to initialize with.
if (type.isScalar() || !initializer->getType().isScalar())
return initializer;
else
initList = intermediate.makeAggregate(initializer);
}
// Of the initializer-list set of nodes, need to process bottom up,
// so recurse deep, then process on the way up.
// Go down the tree here...
if (type.isArray()) {
// The type's array might be unsized, which could be okay, so base sizes on the size of the aggregate.
// Later on, initializer execution code will deal with array size logic.
TType arrayType;
arrayType.shallowCopy(type); // sharing struct stuff is fine
arrayType.copyArraySizes(*type.getArraySizes()); // but get a fresh copy of the array information, to edit below
// edit array sizes to fill in unsized dimensions
if (type.isUnsizedArray())
arrayType.changeOuterArraySize((int)initList->getSequence().size());
// set unsized array dimensions that can be derived from the initializer's first element
if (arrayType.isArrayOfArrays() && initList->getSequence().size() > 0) {
TIntermTyped* firstInit = initList->getSequence()[0]->getAsTyped();
if (firstInit->getType().isArray() &&
arrayType.getArraySizes()->getNumDims() == firstInit->getType().getArraySizes()->getNumDims() + 1) {
for (int d = 1; d < arrayType.getArraySizes()->getNumDims(); ++d) {
if (arrayType.getArraySizes()->getDimSize(d) == UnsizedArraySize)
arrayType.getArraySizes()->setDimSize(d, firstInit->getType().getArraySizes()->getDimSize(d - 1));
}
}
}
// lengthen list to be long enough
lengthenList(loc, initList->getSequence(), arrayType.getOuterArraySize(), scalarInit);
// recursively process each element
TType elementType(arrayType, 0); // dereferenced type
for (int i = 0; i < arrayType.getOuterArraySize(); ++i) {
initList->getSequence()[i] = convertInitializerList(loc, elementType,
initList->getSequence()[i]->getAsTyped(), scalarInit);
if (initList->getSequence()[i] == nullptr)
return nullptr;
}
return addConstructor(loc, initList, arrayType);
} else if (type.isStruct()) {
// do we have implicit assignments to opaques?
for (size_t i = initList->getSequence().size(); i < type.getStruct()->size(); ++i) {
if ((*type.getStruct())[i].type->containsOpaque()) {
error(loc, "cannot implicitly initialize opaque members", "initializer list", "");
return nullptr;
}
}
// lengthen list to be long enough
lengthenList(loc, initList->getSequence(), static_cast<int>(type.getStruct()->size()), scalarInit);
if (type.getStruct()->size() != initList->getSequence().size()) {
error(loc, "wrong number of structure members", "initializer list", "");
return nullptr;
}
for (size_t i = 0; i < type.getStruct()->size(); ++i) {
initList->getSequence()[i] = convertInitializerList(loc, *(*type.getStruct())[i].type,
initList->getSequence()[i]->getAsTyped(), scalarInit);
if (initList->getSequence()[i] == nullptr)
return nullptr;
}
} else if (type.isMatrix()) {
if (type.computeNumComponents() == (int)initList->getSequence().size()) {
// This means the matrix is initialized component-wise, rather than as
// a series of rows and columns. We can just use the list directly as
// a constructor; no further processing needed.
} else {
// lengthen list to be long enough
lengthenList(loc, initList->getSequence(), type.getMatrixCols(), scalarInit);
if (type.getMatrixCols() != (int)initList->getSequence().size()) {
error(loc, "wrong number of matrix columns:", "initializer list", type.getCompleteString().c_str());
return nullptr;
}
TType vectorType(type, 0); // dereferenced type
for (int i = 0; i < type.getMatrixCols(); ++i) {
initList->getSequence()[i] = convertInitializerList(loc, vectorType,
initList->getSequence()[i]->getAsTyped(), scalarInit);
if (initList->getSequence()[i] == nullptr)
return nullptr;
}
}
} else if (type.isVector()) {
// lengthen list to be long enough
lengthenList(loc, initList->getSequence(), type.getVectorSize(), scalarInit);
// error check; we're at bottom, so work is finished below
if (type.getVectorSize() != (int)initList->getSequence().size()) {
error(loc, "wrong vector size (or rows in a matrix column):", "initializer list",
type.getCompleteString().c_str());
return nullptr;
}
} else if (type.isScalar()) {
// lengthen list to be long enough
lengthenList(loc, initList->getSequence(), 1, scalarInit);
if ((int)initList->getSequence().size() != 1) {
error(loc, "scalar expected one element:", "initializer list", type.getCompleteString().c_str());
return nullptr;
}
} else {
error(loc, "unexpected initializer-list type:", "initializer list", type.getCompleteString().c_str());
return nullptr;
}
// Now that the subtree is processed, process this node as if the
// initializer list is a set of arguments to a constructor.
TIntermTyped* emulatedConstructorArguments;
if (initList->getSequence().size() == 1)
emulatedConstructorArguments = initList->getSequence()[0]->getAsTyped();
else
emulatedConstructorArguments = initList;
return addConstructor(loc, emulatedConstructorArguments, type);
}
// Lengthen list to be long enough to cover any gap from the current list size
// to 'size'. If the list is longer, do nothing.
// The value to lengthen with is the default for short lists.
//
// By default, lists that are too short due to lack of initializers initialize to zero.
// Alternatively, it could be a scalar initializer for a structure. Both cases are handled,
// based on whether something is passed in as 'scalarInit'.
//
// 'scalarInit' must be safe to use each time this is called (no side effects replication).
//
void HlslParseContext::lengthenList(const TSourceLoc& loc, TIntermSequence& list, int size, TIntermTyped* scalarInit)
{
for (int c = (int)list.size(); c < size; ++c) {
if (scalarInit == nullptr)
list.push_back(intermediate.addConstantUnion(0, loc));
else
list.push_back(scalarInit);
}
}
//
// Test for the correctness of the parameters passed to various constructor functions
// and also convert them to the right data type, if allowed and required.
//
// Returns nullptr for an error or the constructed node (aggregate or typed) for no error.
//
TIntermTyped* HlslParseContext::handleConstructor(const TSourceLoc& loc, TIntermTyped* node, const TType& type)
{
if (node == nullptr)
return nullptr;
// Construct identical type
if (type == node->getType())
return node;
// Handle the idiom "(struct type)<scalar value>"
if (type.isStruct() && isScalarConstructor(node)) {
// 'node' will almost always get used multiple times, so should not be used directly,
// it would create a DAG instead of a tree, which might be okay (would
// like to formalize that for constants and symbols), but if it has
// side effects, they would get executed multiple times, which is not okay.
if (node->getAsConstantUnion() == nullptr && node->getAsSymbolNode() == nullptr) {
TIntermAggregate* seq = intermediate.makeAggregate(loc);
TIntermSymbol* copy = makeInternalVariableNode(loc, "scalarCopy", node->getType());
seq = intermediate.growAggregate(seq, intermediate.addBinaryNode(EOpAssign, copy, node, loc));
seq = intermediate.growAggregate(seq, convertInitializerList(loc, type, intermediate.makeAggregate(loc), copy));
seq->setOp(EOpComma);
seq->setType(type);
return seq;
} else
return convertInitializerList(loc, type, intermediate.makeAggregate(loc), node);
}
return addConstructor(loc, node, type);
}
// Add a constructor, either from the grammar, or other programmatic reasons.
//
// 'node' is what to construct from.
// 'type' is what type to construct.
//
// Returns the constructed object.
// Return nullptr if it can't be done.
//
TIntermTyped* HlslParseContext::addConstructor(const TSourceLoc& loc, TIntermTyped* node, const TType& type)
{
TIntermAggregate* aggrNode = node->getAsAggregate();
TOperator op = intermediate.mapTypeToConstructorOp(type);
if (op == EOpConstructTextureSampler)
return intermediate.setAggregateOperator(aggrNode, op, type, loc);
TTypeList::const_iterator memberTypes;
if (op == EOpConstructStruct)
memberTypes = type.getStruct()->begin();
TType elementType;
if (type.isArray()) {
TType dereferenced(type, 0);
elementType.shallowCopy(dereferenced);
} else
elementType.shallowCopy(type);
bool singleArg;
if (aggrNode != nullptr) {
if (aggrNode->getOp() != EOpNull)
singleArg = true;
else
singleArg = false;
} else
singleArg = true;
TIntermTyped *newNode;
if (singleArg) {
// Handle array -> array conversion
// Constructing an array of one type from an array of another type is allowed,
// assuming there are enough components available (semantic-checked earlier).
if (type.isArray() && node->isArray())
newNode = convertArray(node, type);
// If structure constructor or array constructor is being called
// for only one parameter inside the aggregate, we need to call constructAggregate function once.
else if (type.isArray())
newNode = constructAggregate(node, elementType, 1, node->getLoc());
else if (op == EOpConstructStruct)
newNode = constructAggregate(node, *(*memberTypes).type, 1, node->getLoc());
else {
// shape conversion for matrix constructor from scalar. HLSL semantics are: scalar
// is replicated into every element of the matrix (not just the diagnonal), so
// that is handled specially here.
if (type.isMatrix() && node->getType().isScalarOrVec1())
node = intermediate.addShapeConversion(type, node);
newNode = constructBuiltIn(type, op, node, node->getLoc(), false);
}
if (newNode && (type.isArray() || op == EOpConstructStruct))
newNode = intermediate.setAggregateOperator(newNode, EOpConstructStruct, type, loc);
return newNode;
}
//
// Handle list of arguments.
//
TIntermSequence& sequenceVector = aggrNode->getSequence(); // Stores the information about the parameter to the constructor
// if the structure constructor contains more than one parameter, then construct
// each parameter
int paramCount = 0; // keeps a track of the constructor parameter number being checked
// for each parameter to the constructor call, check to see if the right type is passed or convert them
// to the right type if possible (and allowed).
// for structure constructors, just check if the right type is passed, no conversion is allowed.
for (TIntermSequence::iterator p = sequenceVector.begin();
p != sequenceVector.end(); p++, paramCount++) {
if (type.isArray())
newNode = constructAggregate(*p, elementType, paramCount + 1, node->getLoc());
else if (op == EOpConstructStruct)
newNode = constructAggregate(*p, *(memberTypes[paramCount]).type, paramCount + 1, node->getLoc());
else
newNode = constructBuiltIn(type, op, (*p)->getAsTyped(), node->getLoc(), true);
if (newNode)
*p = newNode;
else
return nullptr;
}
TIntermTyped* constructor = intermediate.setAggregateOperator(aggrNode, op, type, loc);
return constructor;
}
// Function for constructor implementation. Calls addUnaryMath with appropriate EOp value
// for the parameter to the constructor (passed to this function). Essentially, it converts
// the parameter types correctly. If a constructor expects an int (like ivec2) and is passed a
// float, then float is converted to int.
//
// Returns nullptr for an error or the constructed node.
//
TIntermTyped* HlslParseContext::constructBuiltIn(const TType& type, TOperator op, TIntermTyped* node,
const TSourceLoc& loc, bool subset)
{
TIntermTyped* newNode;
TOperator basicOp;
//
// First, convert types as needed.
//
switch (op) {
case EOpConstructF16Vec2:
case EOpConstructF16Vec3:
case EOpConstructF16Vec4:
case EOpConstructF16Mat2x2:
case EOpConstructF16Mat2x3:
case EOpConstructF16Mat2x4:
case EOpConstructF16Mat3x2:
case EOpConstructF16Mat3x3:
case EOpConstructF16Mat3x4:
case EOpConstructF16Mat4x2:
case EOpConstructF16Mat4x3:
case EOpConstructF16Mat4x4:
case EOpConstructFloat16:
basicOp = EOpConstructFloat16;
break;
case EOpConstructVec2:
case EOpConstructVec3:
case EOpConstructVec4:
case EOpConstructMat2x2:
case EOpConstructMat2x3:
case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3x3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4x4:
case EOpConstructFloat:
basicOp = EOpConstructFloat;
break;
case EOpConstructDVec2:
case EOpConstructDVec3:
case EOpConstructDVec4:
case EOpConstructDMat2x2:
case EOpConstructDMat2x3:
case EOpConstructDMat2x4:
case EOpConstructDMat3x2:
case EOpConstructDMat3x3:
case EOpConstructDMat3x4:
case EOpConstructDMat4x2:
case EOpConstructDMat4x3:
case EOpConstructDMat4x4:
case EOpConstructDouble:
basicOp = EOpConstructDouble;
break;
case EOpConstructI16Vec2:
case EOpConstructI16Vec3:
case EOpConstructI16Vec4:
case EOpConstructInt16:
basicOp = EOpConstructInt16;
break;
case EOpConstructIVec2:
case EOpConstructIVec3:
case EOpConstructIVec4:
case EOpConstructIMat2x2:
case EOpConstructIMat2x3:
case EOpConstructIMat2x4:
case EOpConstructIMat3x2:
case EOpConstructIMat3x3:
case EOpConstructIMat3x4:
case EOpConstructIMat4x2:
case EOpConstructIMat4x3:
case EOpConstructIMat4x4:
case EOpConstructInt:
basicOp = EOpConstructInt;
break;
case EOpConstructU16Vec2:
case EOpConstructU16Vec3:
case EOpConstructU16Vec4:
case EOpConstructUint16:
basicOp = EOpConstructUint16;
break;
case EOpConstructUVec2:
case EOpConstructUVec3:
case EOpConstructUVec4:
case EOpConstructUMat2x2:
case EOpConstructUMat2x3:
case EOpConstructUMat2x4:
case EOpConstructUMat3x2:
case EOpConstructUMat3x3:
case EOpConstructUMat3x4:
case EOpConstructUMat4x2:
case EOpConstructUMat4x3:
case EOpConstructUMat4x4:
case EOpConstructUint:
basicOp = EOpConstructUint;
break;
case EOpConstructBVec2:
case EOpConstructBVec3:
case EOpConstructBVec4:
case EOpConstructBMat2x2:
case EOpConstructBMat2x3:
case EOpConstructBMat2x4:
case EOpConstructBMat3x2:
case EOpConstructBMat3x3:
case EOpConstructBMat3x4:
case EOpConstructBMat4x2:
case EOpConstructBMat4x3:
case EOpConstructBMat4x4:
case EOpConstructBool:
basicOp = EOpConstructBool;
break;
default:
error(loc, "unsupported construction", "", "");
return nullptr;
}
newNode = intermediate.addUnaryMath(basicOp, node, node->getLoc());
if (newNode == nullptr) {
error(loc, "can't convert", "constructor", "");
return nullptr;
}
//
// Now, if there still isn't an operation to do the construction, and we need one, add one.
//
// Otherwise, skip out early.
if (subset || (newNode != node && newNode->getType() == type))
return newNode;
// setAggregateOperator will insert a new node for the constructor, as needed.
return intermediate.setAggregateOperator(newNode, op, type, loc);
}
// Convert the array in node to the requested type, which is also an array.
// Returns nullptr on failure, otherwise returns aggregate holding the list of
// elements needed to construct the array.
TIntermTyped* HlslParseContext::convertArray(TIntermTyped* node, const TType& type)
{
assert(node->isArray() && type.isArray());
if (node->getType().computeNumComponents() < type.computeNumComponents())
return nullptr;
// TODO: write an argument replicator, for the case the argument should not be
// executed multiple times, yet multiple copies are needed.
TIntermTyped* constructee = node->getAsTyped();
// track where we are in consuming the argument
int constructeeElement = 0;
int constructeeComponent = 0;
// bump up to the next component to consume
const auto getNextComponent = [&]() {
TIntermTyped* component;
component = handleBracketDereference(node->getLoc(), constructee,
intermediate.addConstantUnion(constructeeElement, node->getLoc()));
if (component->isVector())
component = handleBracketDereference(node->getLoc(), component,
intermediate.addConstantUnion(constructeeComponent, node->getLoc()));
// bump component pointer up
++constructeeComponent;
if (constructeeComponent == constructee->getVectorSize()) {
constructeeComponent = 0;
++constructeeElement;
}
return component;
};
// make one subnode per constructed array element
TIntermAggregate* constructor = nullptr;
TType derefType(type, 0);
TType speculativeComponentType(derefType, 0);
TType* componentType = derefType.isVector() ? &speculativeComponentType : &derefType;
TOperator componentOp = intermediate.mapTypeToConstructorOp(*componentType);
TType crossType(node->getBasicType(), EvqTemporary, type.getVectorSize());
for (int e = 0; e < type.getOuterArraySize(); ++e) {
// construct an element
TIntermTyped* elementArg;
if (type.getVectorSize() == constructee->getVectorSize()) {
// same element shape
elementArg = handleBracketDereference(node->getLoc(), constructee,
intermediate.addConstantUnion(e, node->getLoc()));
} else {
// mismatched element shapes
if (type.getVectorSize() == 1)
elementArg = getNextComponent();
else {
// make a vector
TIntermAggregate* elementConstructee = nullptr;
for (int c = 0; c < type.getVectorSize(); ++c)
elementConstructee = intermediate.growAggregate(elementConstructee, getNextComponent());
elementArg = addConstructor(node->getLoc(), elementConstructee, crossType);
}
}
// convert basic types
elementArg = intermediate.addConversion(componentOp, derefType, elementArg);
if (elementArg == nullptr)
return nullptr;
// combine with top-level constructor
constructor = intermediate.growAggregate(constructor, elementArg);
}
return constructor;
}
// This function tests for the type of the parameters to the structure or array constructor. Raises
// an error message if the expected type does not match the parameter passed to the constructor.
//
// Returns nullptr for an error or the input node itself if the expected and the given parameter types match.
//
TIntermTyped* HlslParseContext::constructAggregate(TIntermNode* node, const TType& type, int paramCount,
const TSourceLoc& loc)
{
// Handle cases that map more 1:1 between constructor arguments and constructed.
TIntermTyped* converted = intermediate.addConversion(EOpConstructStruct, type, node->getAsTyped());
if (converted == nullptr || converted->getType() != type) {
error(loc, "", "constructor", "cannot convert parameter %d from '%s' to '%s'", paramCount,
node->getAsTyped()->getType().getCompleteString().c_str(), type.getCompleteString().c_str());
return nullptr;
}
return converted;
}
//
// Do everything needed to add an interface block.
//
void HlslParseContext::declareBlock(const TSourceLoc& loc, TType& type, const TString* instanceName)
{
assert(type.getWritableStruct() != nullptr);
// Clean up top-level decorations that don't belong.
switch (type.getQualifier().storage) {
case EvqUniform:
case EvqBuffer:
correctUniform(type.getQualifier());
break;
case EvqVaryingIn:
correctInput(type.getQualifier());
break;
case EvqVaryingOut:
correctOutput(type.getQualifier());
break;
default:
break;
}
TTypeList& typeList = *type.getWritableStruct();
// fix and check for member storage qualifiers and types that don't belong within a block
for (unsigned int member = 0; member < typeList.size(); ++member) {
TType& memberType = *typeList[member].type;
TQualifier& memberQualifier = memberType.getQualifier();
const TSourceLoc& memberLoc = typeList[member].loc;
globalQualifierFix(memberLoc, memberQualifier);
memberQualifier.storage = type.getQualifier().storage;
if (memberType.isStruct()) {
// clean up and pick up the right set of decorations
auto it = ioTypeMap.find(memberType.getStruct());
switch (type.getQualifier().storage) {
case EvqUniform:
case EvqBuffer:
correctUniform(type.getQualifier());
if (it != ioTypeMap.end() && it->second.uniform)
memberType.setStruct(it->second.uniform);
break;
case EvqVaryingIn:
correctInput(type.getQualifier());
if (it != ioTypeMap.end() && it->second.input)
memberType.setStruct(it->second.input);
break;
case EvqVaryingOut:
correctOutput(type.getQualifier());
if (it != ioTypeMap.end() && it->second.output)
memberType.setStruct(it->second.output);
break;
default:
break;
}
}
}
// Make default block qualification, and adjust the member qualifications
TQualifier defaultQualification;
switch (type.getQualifier().storage) {
case EvqUniform: defaultQualification = globalUniformDefaults; break;
case EvqBuffer: defaultQualification = globalBufferDefaults; break;
case EvqVaryingIn: defaultQualification = globalInputDefaults; break;
case EvqVaryingOut: defaultQualification = globalOutputDefaults; break;
default: defaultQualification.clear(); break;
}
// Special case for "push_constant uniform", which has a default of std430,
// contrary to normal uniform defaults, and can't have a default tracked for it.
if (type.getQualifier().layoutPushConstant && ! type.getQualifier().hasPacking())
type.getQualifier().layoutPacking = ElpStd430;
// fix and check for member layout qualifiers
mergeObjectLayoutQualifiers(defaultQualification, type.getQualifier(), true);
bool memberWithLocation = false;
bool memberWithoutLocation = false;
for (unsigned int member = 0; member < typeList.size(); ++member) {
TQualifier& memberQualifier = typeList[member].type->getQualifier();
const TSourceLoc& memberLoc = typeList[member].loc;
if (memberQualifier.hasStream()) {
if (defaultQualification.layoutStream != memberQualifier.layoutStream)
error(memberLoc, "member cannot contradict block", "stream", "");
}
// "This includes a block's inheritance of the
// current global default buffer, a block member's inheritance of the block's
// buffer, and the requirement that any *xfb_buffer* declared on a block
// member must match the buffer inherited from the block."
if (memberQualifier.hasXfbBuffer()) {
if (defaultQualification.layoutXfbBuffer != memberQualifier.layoutXfbBuffer)
error(memberLoc, "member cannot contradict block (or what block inherited from global)", "xfb_buffer", "");
}
if (memberQualifier.hasLocation()) {
switch (type.getQualifier().storage) {
case EvqVaryingIn:
case EvqVaryingOut:
memberWithLocation = true;
break;
default:
break;
}
} else
memberWithoutLocation = true;
TQualifier newMemberQualification = defaultQualification;
mergeQualifiers(newMemberQualification, memberQualifier);
memberQualifier = newMemberQualification;
}
// Process the members
fixBlockLocations(loc, type.getQualifier(), typeList, memberWithLocation, memberWithoutLocation);
fixXfbOffsets(type.getQualifier(), typeList);
fixBlockUniformOffsets(type.getQualifier(), typeList);
// reverse merge, so that currentBlockQualifier now has all layout information
// (can't use defaultQualification directly, it's missing other non-layout-default-class qualifiers)
mergeObjectLayoutQualifiers(type.getQualifier(), defaultQualification, true);
//
// Build and add the interface block as a new type named 'blockName'
//
// Use the instance name as the interface name if one exists, else the block name.
const TString& interfaceName = (instanceName && !instanceName->empty()) ? *instanceName : type.getTypeName();
TType blockType(&typeList, interfaceName, type.getQualifier());
if (type.isArray())
blockType.transferArraySizes(type.getArraySizes());
// Add the variable, as anonymous or named instanceName.
// Make an anonymous variable if no name was provided.
if (instanceName == nullptr)
instanceName = NewPoolTString("");
TVariable& variable = *new TVariable(instanceName, blockType);
if (! symbolTable.insert(variable)) {
if (*instanceName == "")
error(loc, "nameless block contains a member that already has a name at global scope",
"" /* blockName->c_str() */, "");
else
error(loc, "block instance name redefinition", variable.getName().c_str(), "");
return;
}
// Save it in the AST for linker use.
if (symbolTable.atGlobalLevel())
trackLinkage(variable);
}
//
// "For a block, this process applies to the entire block, or until the first member
// is reached that has a location layout qualifier. When a block member is declared with a location
// qualifier, its location comes from that qualifier: The member's location qualifier overrides the block-level
// declaration. Subsequent members are again assigned consecutive locations, based on the newest location,
// until the next member declared with a location qualifier. The values used for locations do not have to be
// declared in increasing order."
void HlslParseContext::fixBlockLocations(const TSourceLoc& loc, TQualifier& qualifier, TTypeList& typeList, bool memberWithLocation, bool memberWithoutLocation)
{
// "If a block has no block-level location layout qualifier, it is required that either all or none of its members
// have a location layout qualifier, or a compile-time error results."
if (! qualifier.hasLocation() && memberWithLocation && memberWithoutLocation)
error(loc, "either the block needs a location, or all members need a location, or no members have a location", "location", "");
else {
if (memberWithLocation) {
// remove any block-level location and make it per *every* member
int nextLocation = 0; // by the rule above, initial value is not relevant
if (qualifier.hasAnyLocation()) {
nextLocation = qualifier.layoutLocation;
qualifier.layoutLocation = TQualifier::layoutLocationEnd;
if (qualifier.hasComponent()) {
// "It is a compile-time error to apply the *component* qualifier to a ... block"
error(loc, "cannot apply to a block", "component", "");
}
if (qualifier.hasIndex()) {
error(loc, "cannot apply to a block", "index", "");
}
}
for (unsigned int member = 0; member < typeList.size(); ++member) {
TQualifier& memberQualifier = typeList[member].type->getQualifier();
const TSourceLoc& memberLoc = typeList[member].loc;
if (! memberQualifier.hasLocation()) {
if (nextLocation >= (int)TQualifier::layoutLocationEnd)
error(memberLoc, "location is too large", "location", "");
memberQualifier.layoutLocation = nextLocation;
memberQualifier.layoutComponent = 0;
}
nextLocation = memberQualifier.layoutLocation +
intermediate.computeTypeLocationSize(*typeList[member].type, language);
}
}
}
}
void HlslParseContext::fixXfbOffsets(TQualifier& qualifier, TTypeList& typeList)
{
// "If a block is qualified with xfb_offset, all its
// members are assigned transform feedback buffer offsets. If a block is not qualified with xfb_offset, any
// members of that block not qualified with an xfb_offset will not be assigned transform feedback buffer
// offsets."
if (! qualifier.hasXfbBuffer() || ! qualifier.hasXfbOffset())
return;
int nextOffset = qualifier.layoutXfbOffset;
for (unsigned int member = 0; member < typeList.size(); ++member) {
TQualifier& memberQualifier = typeList[member].type->getQualifier();
bool contains64BitType = false;
bool contains32BitType = false;
bool contains16BitType = false;
int memberSize = intermediate.computeTypeXfbSize(*typeList[member].type, contains64BitType, contains32BitType, contains16BitType);
// see if we need to auto-assign an offset to this member
if (! memberQualifier.hasXfbOffset()) {
// "if applied to an aggregate containing a double or 64-bit integer, the offset must also be a multiple of 8"
if (contains64BitType)
RoundToPow2(nextOffset, 8);
else if (contains32BitType)
RoundToPow2(nextOffset, 4);
// "if applied to an aggregate containing a half float or 16-bit integer, the offset must also be a multiple of 2"
else if (contains16BitType)
RoundToPow2(nextOffset, 2);
memberQualifier.layoutXfbOffset = nextOffset;
} else
nextOffset = memberQualifier.layoutXfbOffset;
nextOffset += memberSize;
}
// The above gave all block members an offset, so we can take it off the block now,
// which will avoid double counting the offset usage.
qualifier.layoutXfbOffset = TQualifier::layoutXfbOffsetEnd;
}
// Calculate and save the offset of each block member, using the recursively
// defined block offset rules and the user-provided offset and align.
//
// Also, compute and save the total size of the block. For the block's size, arrayness
// is not taken into account, as each element is backed by a separate buffer.
//
void HlslParseContext::fixBlockUniformOffsets(const TQualifier& qualifier, TTypeList& typeList)
{
if (! qualifier.isUniformOrBuffer())
return;
if (qualifier.layoutPacking != ElpStd140 && qualifier.layoutPacking != ElpStd430 && qualifier.layoutPacking != ElpScalar)
return;
int offset = 0;
int memberSize;
for (unsigned int member = 0; member < typeList.size(); ++member) {
TQualifier& memberQualifier = typeList[member].type->getQualifier();
const TSourceLoc& memberLoc = typeList[member].loc;
// "When align is applied to an array, it effects only the start of the array, not the array's internal stride."
// modify just the children's view of matrix layout, if there is one for this member
TLayoutMatrix subMatrixLayout = typeList[member].type->getQualifier().layoutMatrix;
int dummyStride;
int memberAlignment = intermediate.getMemberAlignment(*typeList[member].type, memberSize, dummyStride,
qualifier.layoutPacking,
subMatrixLayout != ElmNone
? subMatrixLayout == ElmRowMajor
: qualifier.layoutMatrix == ElmRowMajor);
if (memberQualifier.hasOffset()) {
// "The specified offset must be a multiple
// of the base alignment of the type of the block member it qualifies, or a compile-time error results."
if (! IsMultipleOfPow2(memberQualifier.layoutOffset, memberAlignment))
error(memberLoc, "must be a multiple of the member's alignment", "offset",
"(layout offset = %d | member alignment = %d)", memberQualifier.layoutOffset, memberAlignment);
// "The offset qualifier forces the qualified member to start at or after the specified
// integral-constant expression, which will be its byte offset from the beginning of the buffer.
// "The actual offset of a member is computed as
// follows: If offset was declared, start with that offset, otherwise start with the next available offset."
offset = std::max(offset, memberQualifier.layoutOffset);
}
// "The actual alignment of a member will be the greater of the specified align alignment and the standard
// (e.g., std140) base alignment for the member's type."
if (memberQualifier.hasAlign())
memberAlignment = std::max(memberAlignment, memberQualifier.layoutAlign);
// "If the resulting offset is not a multiple of the actual alignment,
// increase it to the first offset that is a multiple of
// the actual alignment."
RoundToPow2(offset, memberAlignment);
typeList[member].type->getQualifier().layoutOffset = offset;
offset += memberSize;
}
}
// For an identifier that is already declared, add more qualification to it.
void HlslParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier qualifier, const TString& identifier)
{
TSymbol* symbol = symbolTable.find(identifier);
if (symbol == nullptr) {
error(loc, "identifier not previously declared", identifier.c_str(), "");
return;
}
if (symbol->getAsFunction()) {
error(loc, "cannot re-qualify a function name", identifier.c_str(), "");
return;
}
if (qualifier.isAuxiliary() ||
qualifier.isMemory() ||
qualifier.isInterpolation() ||
qualifier.hasLayout() ||
qualifier.storage != EvqTemporary ||
qualifier.precision != EpqNone) {
error(loc, "cannot add storage, auxiliary, memory, interpolation, layout, or precision qualifier to an existing variable", identifier.c_str(), "");
return;
}
// For read-only built-ins, add a new symbol for holding the modified qualifier.
// This will bring up an entire block, if a block type has to be modified (e.g., gl_Position inside a block)
if (symbol->isReadOnly())
symbol = symbolTable.copyUp(symbol);
if (qualifier.invariant) {
if (intermediate.inIoAccessed(identifier))
error(loc, "cannot change qualification after use", "invariant", "");
symbol->getWritableType().getQualifier().invariant = true;
} else if (qualifier.noContraction) {
if (intermediate.inIoAccessed(identifier))
error(loc, "cannot change qualification after use", "precise", "");
symbol->getWritableType().getQualifier().noContraction = true;
} else if (qualifier.specConstant) {
symbol->getWritableType().getQualifier().makeSpecConstant();
if (qualifier.hasSpecConstantId())
symbol->getWritableType().getQualifier().layoutSpecConstantId = qualifier.layoutSpecConstantId;
} else
warn(loc, "unknown requalification", "", "");
}
void HlslParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier qualifier, TIdentifierList& identifiers)
{
for (unsigned int i = 0; i < identifiers.size(); ++i)
addQualifierToExisting(loc, qualifier, *identifiers[i]);
}
//
// Update the intermediate for the given input geometry
//
bool HlslParseContext::handleInputGeometry(const TSourceLoc& loc, const TLayoutGeometry& geometry)
{
// these can be declared on non-entry-points, in which case they lose their meaning
if (! parsingEntrypointParameters)
return true;
switch (geometry) {
case ElgPoints: // fall through
case ElgLines: // ...
case ElgTriangles: // ...
case ElgLinesAdjacency: // ...
case ElgTrianglesAdjacency: // ...
if (! intermediate.setInputPrimitive(geometry)) {
error(loc, "input primitive geometry redefinition", TQualifier::getGeometryString(geometry), "");
return false;
}
break;
default:
error(loc, "cannot apply to 'in'", TQualifier::getGeometryString(geometry), "");
return false;
}
return true;
}
//
// Update the intermediate for the given output geometry
//
bool HlslParseContext::handleOutputGeometry(const TSourceLoc& loc, const TLayoutGeometry& geometry)
{
// If this is not a geometry shader, ignore. It might be a mixed shader including several stages.
// Since that's an OK situation, return true for success.
if (language != EShLangGeometry)
return true;
// these can be declared on non-entry-points, in which case they lose their meaning
if (! parsingEntrypointParameters)
return true;
switch (geometry) {
case ElgPoints:
case ElgLineStrip:
case ElgTriangleStrip:
if (! intermediate.setOutputPrimitive(geometry)) {
error(loc, "output primitive geometry redefinition", TQualifier::getGeometryString(geometry), "");
return false;
}
break;
default:
error(loc, "cannot apply to 'out'", TQualifier::getGeometryString(geometry), "");
return false;
}
return true;
}
//
// Selection attributes
//
void HlslParseContext::handleSelectionAttributes(const TSourceLoc& loc, TIntermSelection* selection,
const TAttributes& attributes)
{
if (selection == nullptr)
return;
for (auto it = attributes.begin(); it != attributes.end(); ++it) {
switch (it->name) {
case EatFlatten:
selection->setFlatten();
break;
case EatBranch:
selection->setDontFlatten();
break;
default:
warn(loc, "attribute does not apply to a selection", "", "");
break;
}
}
}
//
// Switch attributes
//
void HlslParseContext::handleSwitchAttributes(const TSourceLoc& loc, TIntermSwitch* selection,
const TAttributes& attributes)
{
if (selection == nullptr)
return;
for (auto it = attributes.begin(); it != attributes.end(); ++it) {
switch (it->name) {
case EatFlatten:
selection->setFlatten();
break;
case EatBranch:
selection->setDontFlatten();
break;
default:
warn(loc, "attribute does not apply to a switch", "", "");
break;
}
}
}
//
// Loop attributes
//
void HlslParseContext::handleLoopAttributes(const TSourceLoc& loc, TIntermLoop* loop,
const TAttributes& attributes)
{
if (loop == nullptr)
return;
for (auto it = attributes.begin(); it != attributes.end(); ++it) {
switch (it->name) {
case EatUnroll:
loop->setUnroll();
break;
case EatLoop:
loop->setDontUnroll();
break;
default:
warn(loc, "attribute does not apply to a loop", "", "");
break;
}
}
}
//
// Updating default qualifier for the case of a declaration with just a qualifier,
// no type, block, or identifier.
//
void HlslParseContext::updateStandaloneQualifierDefaults(const TSourceLoc& loc, const TPublicType& publicType)
{
if (publicType.shaderQualifiers.vertices != TQualifier::layoutNotSet) {
assert(language == EShLangTessControl || language == EShLangGeometry);
// const char* id = (language == EShLangTessControl) ? "vertices" : "max_vertices";
}
if (publicType.shaderQualifiers.invocations != TQualifier::layoutNotSet) {
if (! intermediate.setInvocations(publicType.shaderQualifiers.invocations))
error(loc, "cannot change previously set layout value", "invocations", "");
}
if (publicType.shaderQualifiers.geometry != ElgNone) {
if (publicType.qualifier.storage == EvqVaryingIn) {
switch (publicType.shaderQualifiers.geometry) {
case ElgPoints:
case ElgLines:
case ElgLinesAdjacency:
case ElgTriangles:
case ElgTrianglesAdjacency:
case ElgQuads:
case ElgIsolines:
break;
default:
error(loc, "cannot apply to input", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry),
"");
}
} else if (publicType.qualifier.storage == EvqVaryingOut) {
handleOutputGeometry(loc, publicType.shaderQualifiers.geometry);
} else
error(loc, "cannot apply to:", TQualifier::getGeometryString(publicType.shaderQualifiers.geometry),
GetStorageQualifierString(publicType.qualifier.storage));
}
if (publicType.shaderQualifiers.spacing != EvsNone)
intermediate.setVertexSpacing(publicType.shaderQualifiers.spacing);
if (publicType.shaderQualifiers.order != EvoNone)
intermediate.setVertexOrder(publicType.shaderQualifiers.order);
if (publicType.shaderQualifiers.pointMode)
intermediate.setPointMode();
for (int i = 0; i < 3; ++i) {
if (publicType.shaderQualifiers.localSize[i] > 1) {
int max = 0;
switch (i) {
case 0: max = resources.maxComputeWorkGroupSizeX; break;
case 1: max = resources.maxComputeWorkGroupSizeY; break;
case 2: max = resources.maxComputeWorkGroupSizeZ; break;
default: break;
}
if (intermediate.getLocalSize(i) > (unsigned int)max)
error(loc, "too large; see gl_MaxComputeWorkGroupSize", "local_size", "");
// Fix the existing constant gl_WorkGroupSize with this new information.
TVariable* workGroupSize = getEditableVariable("gl_WorkGroupSize");
workGroupSize->getWritableConstArray()[i].setUConst(intermediate.getLocalSize(i));
}
if (publicType.shaderQualifiers.localSizeSpecId[i] != TQualifier::layoutNotSet) {
intermediate.setLocalSizeSpecId(i, publicType.shaderQualifiers.localSizeSpecId[i]);
// Set the workgroup built-in variable as a specialization constant
TVariable* workGroupSize = getEditableVariable("gl_WorkGroupSize");
workGroupSize->getWritableType().getQualifier().specConstant = true;
}
}
if (publicType.shaderQualifiers.earlyFragmentTests)
intermediate.setEarlyFragmentTests();
const TQualifier& qualifier = publicType.qualifier;
switch (qualifier.storage) {
case EvqUniform:
if (qualifier.hasMatrix())
globalUniformDefaults.layoutMatrix = qualifier.layoutMatrix;
if (qualifier.hasPacking())
globalUniformDefaults.layoutPacking = qualifier.layoutPacking;
break;
case EvqBuffer:
if (qualifier.hasMatrix())
globalBufferDefaults.layoutMatrix = qualifier.layoutMatrix;
if (qualifier.hasPacking())
globalBufferDefaults.layoutPacking = qualifier.layoutPacking;
break;
case EvqVaryingIn:
break;
case EvqVaryingOut:
if (qualifier.hasStream())
globalOutputDefaults.layoutStream = qualifier.layoutStream;
if (qualifier.hasXfbBuffer())
globalOutputDefaults.layoutXfbBuffer = qualifier.layoutXfbBuffer;
if (globalOutputDefaults.hasXfbBuffer() && qualifier.hasXfbStride()) {
if (! intermediate.setXfbBufferStride(globalOutputDefaults.layoutXfbBuffer, qualifier.layoutXfbStride))
error(loc, "all stride settings must match for xfb buffer", "xfb_stride", "%d",
qualifier.layoutXfbBuffer);
}
break;
default:
error(loc, "default qualifier requires 'uniform', 'buffer', 'in', or 'out' storage qualification", "", "");
return;
}
}
//
// Take the sequence of statements that has been built up since the last case/default,
// put it on the list of top-level nodes for the current (inner-most) switch statement,
// and follow that by the case/default we are on now. (See switch topology comment on
// TIntermSwitch.)
//
void HlslParseContext::wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode)
{
TIntermSequence* switchSequence = switchSequenceStack.back();
if (statements) {
statements->setOperator(EOpSequence);
switchSequence->push_back(statements);
}
if (branchNode) {
// check all previous cases for the same label (or both are 'default')
for (unsigned int s = 0; s < switchSequence->size(); ++s) {
TIntermBranch* prevBranch = (*switchSequence)[s]->getAsBranchNode();
if (prevBranch) {
TIntermTyped* prevExpression = prevBranch->getExpression();
TIntermTyped* newExpression = branchNode->getAsBranchNode()->getExpression();
if (prevExpression == nullptr && newExpression == nullptr)
error(branchNode->getLoc(), "duplicate label", "default", "");
else if (prevExpression != nullptr &&
newExpression != nullptr &&
prevExpression->getAsConstantUnion() &&
newExpression->getAsConstantUnion() &&
prevExpression->getAsConstantUnion()->getConstArray()[0].getIConst() ==
newExpression->getAsConstantUnion()->getConstArray()[0].getIConst())
error(branchNode->getLoc(), "duplicated value", "case", "");
}
}
switchSequence->push_back(branchNode);
}
}
//
// Turn the top-level node sequence built up of wrapupSwitchSubsequence
// into a switch node.
//
TIntermNode* HlslParseContext::addSwitch(const TSourceLoc& loc, TIntermTyped* expression,
TIntermAggregate* lastStatements, const TAttributes& attributes)
{
wrapupSwitchSubsequence(lastStatements, nullptr);
if (expression == nullptr ||
(expression->getBasicType() != EbtInt && expression->getBasicType() != EbtUint) ||
expression->getType().isArray() || expression->getType().isMatrix() || expression->getType().isVector())
error(loc, "condition must be a scalar integer expression", "switch", "");
// If there is nothing to do, drop the switch but still execute the expression
TIntermSequence* switchSequence = switchSequenceStack.back();
if (switchSequence->size() == 0)
return expression;
if (lastStatements == nullptr) {
// emulate a break for error recovery
lastStatements = intermediate.makeAggregate(intermediate.addBranch(EOpBreak, loc));
lastStatements->setOperator(EOpSequence);
switchSequence->push_back(lastStatements);
}
TIntermAggregate* body = new TIntermAggregate(EOpSequence);
body->getSequence() = *switchSequenceStack.back();
body->setLoc(loc);
TIntermSwitch* switchNode = new TIntermSwitch(expression, body);
switchNode->setLoc(loc);
handleSwitchAttributes(loc, switchNode, attributes);
return switchNode;
}
// Make a new symbol-table level that is made out of the members of a structure.
// This should be done as an anonymous struct (name is "") so that the symbol table
// finds the members with no explicit reference to a 'this' variable.
void HlslParseContext::pushThisScope(const TType& thisStruct, const TVector<TFunctionDeclarator>& functionDeclarators)
{
// member variables
TVariable& thisVariable = *new TVariable(NewPoolTString(""), thisStruct);
symbolTable.pushThis(thisVariable);
// member functions
for (auto it = functionDeclarators.begin(); it != functionDeclarators.end(); ++it) {
// member should have a prefix matching currentTypePrefix.back()
// but, symbol lookup within the class scope will just use the
// unprefixed name. Hence, there are two: one fully prefixed and
// one with no prefix.
TFunction& member = *it->function->clone();
member.removePrefix(currentTypePrefix.back());
symbolTable.insert(member);
}
}
// Track levels of class/struct/namespace nesting with a prefix string using
// the type names separated by the scoping operator. E.g., two levels
// would look like:
//
// outer::inner
//
// The string is empty when at normal global level.
//
void HlslParseContext::pushNamespace(const TString& typeName)
{
// make new type prefix
TString newPrefix;
if (currentTypePrefix.size() > 0)
newPrefix = currentTypePrefix.back();
newPrefix.append(typeName);
newPrefix.append(scopeMangler);
currentTypePrefix.push_back(newPrefix);
}
// Opposite of pushNamespace(), see above
void HlslParseContext::popNamespace()
{
currentTypePrefix.pop_back();
}
// Use the class/struct nesting string to create a global name for
// a member of a class/struct.
void HlslParseContext::getFullNamespaceName(TString*& name) const
{
if (currentTypePrefix.size() == 0)
return;
TString* fullName = NewPoolTString(currentTypePrefix.back().c_str());
fullName->append(*name);
name = fullName;
}
// Helper function to add the namespace scope mangling syntax to a string.
void HlslParseContext::addScopeMangler(TString& name)
{
name.append(scopeMangler);
}
// Return true if this has uniform-interface like decorations.
bool HlslParseContext::hasUniform(const TQualifier& qualifier) const
{
return qualifier.hasUniformLayout() ||
qualifier.layoutPushConstant;
}
// Potentially not the opposite of hasUniform(), as if some characteristic is
// ever used for more than one thing (e.g., uniform or input), hasUniform() should
// say it exists, but clearUniform() should leave it in place.
void HlslParseContext::clearUniform(TQualifier& qualifier)
{
qualifier.clearUniformLayout();
qualifier.layoutPushConstant = false;
}
// Return false if builtIn by itself doesn't force this qualifier to be an input qualifier.
bool HlslParseContext::isInputBuiltIn(const TQualifier& qualifier) const
{
switch (qualifier.builtIn) {
case EbvPosition:
case EbvPointSize:
return language != EShLangVertex && language != EShLangCompute && language != EShLangFragment;
case EbvClipDistance:
case EbvCullDistance:
return language != EShLangVertex && language != EShLangCompute;
case EbvFragCoord:
case EbvFace:
case EbvHelperInvocation:
case EbvLayer:
case EbvPointCoord:
case EbvSampleId:
case EbvSampleMask:
case EbvSamplePosition:
case EbvViewportIndex:
return language == EShLangFragment;
case EbvGlobalInvocationId:
case EbvLocalInvocationIndex:
case EbvLocalInvocationId:
case EbvNumWorkGroups:
case EbvWorkGroupId:
case EbvWorkGroupSize:
return language == EShLangCompute;
case EbvInvocationId:
return language == EShLangTessControl || language == EShLangTessEvaluation || language == EShLangGeometry;
case EbvPatchVertices:
return language == EShLangTessControl || language == EShLangTessEvaluation;
case EbvInstanceId:
case EbvInstanceIndex:
case EbvVertexId:
case EbvVertexIndex:
return language == EShLangVertex;
case EbvPrimitiveId:
return language == EShLangGeometry || language == EShLangFragment || language == EShLangTessControl;
case EbvTessLevelInner:
case EbvTessLevelOuter:
return language == EShLangTessEvaluation;
case EbvTessCoord:
return language == EShLangTessEvaluation;
case EbvViewIndex:
return language != EShLangCompute;
default:
return false;
}
}
// Return true if there are decorations to preserve for input-like storage.
bool HlslParseContext::hasInput(const TQualifier& qualifier) const
{
if (qualifier.hasAnyLocation())
return true;
if (language == EShLangFragment && (qualifier.isInterpolation() || qualifier.centroid || qualifier.sample))
return true;
if (language == EShLangTessEvaluation && qualifier.patch)
return true;
if (isInputBuiltIn(qualifier))
return true;
return false;
}
// Return false if builtIn by itself doesn't force this qualifier to be an output qualifier.
bool HlslParseContext::isOutputBuiltIn(const TQualifier& qualifier) const
{
switch (qualifier.builtIn) {
case EbvPosition:
case EbvPointSize:
case EbvClipVertex:
case EbvClipDistance:
case EbvCullDistance:
return language != EShLangFragment && language != EShLangCompute;
case EbvFragDepth:
case EbvFragDepthGreater:
case EbvFragDepthLesser:
case EbvSampleMask:
return language == EShLangFragment;
case EbvLayer:
case EbvViewportIndex:
return language == EShLangGeometry || language == EShLangVertex;
case EbvPrimitiveId:
return language == EShLangGeometry;
case EbvTessLevelInner:
case EbvTessLevelOuter:
return language == EShLangTessControl;
default:
return false;
}
}
// Return true if there are decorations to preserve for output-like storage.
bool HlslParseContext::hasOutput(const TQualifier& qualifier) const
{
if (qualifier.hasAnyLocation())
return true;
if (language != EShLangFragment && language != EShLangCompute && qualifier.hasXfb())
return true;
if (language == EShLangTessControl && qualifier.patch)
return true;
if (language == EShLangGeometry && qualifier.hasStream())
return true;
if (isOutputBuiltIn(qualifier))
return true;
return false;
}
// Make the IO decorations etc. be appropriate only for an input interface.
void HlslParseContext::correctInput(TQualifier& qualifier)
{
clearUniform(qualifier);
if (language == EShLangVertex)
qualifier.clearInterstage();
if (language != EShLangTessEvaluation)
qualifier.patch = false;
if (language != EShLangFragment) {
qualifier.clearInterpolation();
qualifier.sample = false;
}
qualifier.clearStreamLayout();
qualifier.clearXfbLayout();
if (! isInputBuiltIn(qualifier))
qualifier.builtIn = EbvNone;
}
// Make the IO decorations etc. be appropriate only for an output interface.
void HlslParseContext::correctOutput(TQualifier& qualifier)
{
clearUniform(qualifier);
if (language == EShLangFragment)
qualifier.clearInterstage();
if (language != EShLangGeometry)
qualifier.clearStreamLayout();
if (language == EShLangFragment)
qualifier.clearXfbLayout();
if (language != EShLangTessControl)
qualifier.patch = false;
// Fixes Test/hlsl.entry-inout.vert (SV_Position will not become a varying).
if (qualifier.builtIn == EbvNone)
qualifier.builtIn = qualifier.declaredBuiltIn;
switch (qualifier.builtIn) {
case EbvFragDepth:
intermediate.setDepthReplacing();
intermediate.setDepth(EldAny);
break;
case EbvFragDepthGreater:
intermediate.setDepthReplacing();
intermediate.setDepth(EldGreater);
qualifier.builtIn = EbvFragDepth;
break;
case EbvFragDepthLesser:
intermediate.setDepthReplacing();
intermediate.setDepth(EldLess);
qualifier.builtIn = EbvFragDepth;
break;
default:
break;
}
if (! isOutputBuiltIn(qualifier))
qualifier.builtIn = EbvNone;
}
// Make the IO decorations etc. be appropriate only for uniform type interfaces.
void HlslParseContext::correctUniform(TQualifier& qualifier)
{
if (qualifier.declaredBuiltIn == EbvNone)
qualifier.declaredBuiltIn = qualifier.builtIn;
qualifier.builtIn = EbvNone;
qualifier.clearInterstage();
qualifier.clearInterstageLayout();
}
// Clear out all IO/Uniform stuff, so this has nothing to do with being an IO interface.
void HlslParseContext::clearUniformInputOutput(TQualifier& qualifier)
{
clearUniform(qualifier);
correctUniform(qualifier);
}
// Set texture return type. Returns success (not all types are valid).
bool HlslParseContext::setTextureReturnType(TSampler& sampler, const TType& retType, const TSourceLoc& loc)
{
// Seed the output with an invalid index. We will set it to a valid one if we can.
sampler.structReturnIndex = TSampler::noReturnStruct;
// Arrays aren't supported.
if (retType.isArray()) {
error(loc, "Arrays not supported in texture template types", "", "");
return false;
}
// If return type is a vector, remember the vector size in the sampler, and return.
if (retType.isVector() || retType.isScalar()) {
sampler.vectorSize = retType.getVectorSize();
return true;
}
// If it wasn't a vector, it must be a struct meeting certain requirements. The requirements
// are checked below: just check for struct-ness here.
if (!retType.isStruct()) {
error(loc, "Invalid texture template type", "", "");
return false;
}
// TODO: Subpass doesn't handle struct returns, due to some oddities with fn overloading.
if (sampler.isSubpass()) {
error(loc, "Unimplemented: structure template type in subpass input", "", "");
return false;
}
TTypeList* members = retType.getWritableStruct();
// Check for too many or not enough structure members.
if (members->size() > 4 || members->size() == 0) {
error(loc, "Invalid member count in texture template structure", "", "");
return false;
}
// Error checking: We must have <= 4 total components, all of the same basic type.
unsigned totalComponents = 0;
for (unsigned m = 0; m < members->size(); ++m) {
// Check for bad member types
if (!(*members)[m].type->isScalar() && !(*members)[m].type->isVector()) {
error(loc, "Invalid texture template struct member type", "", "");
return false;
}
const unsigned memberVectorSize = (*members)[m].type->getVectorSize();
totalComponents += memberVectorSize;
// too many total member components
if (totalComponents > 4) {
error(loc, "Too many components in texture template structure type", "", "");
return false;
}
// All members must be of a common basic type
if ((*members)[m].type->getBasicType() != (*members)[0].type->getBasicType()) {
error(loc, "Texture template structure members must same basic type", "", "");
return false;
}
}
// If the structure in the return type already exists in the table, we'll use it. Otherwise, we'll make
// a new entry. This is a linear search, but it hardly ever happens, and the list cannot be very large.
for (unsigned int idx = 0; idx < textureReturnStruct.size(); ++idx) {
if (textureReturnStruct[idx] == members) {
sampler.structReturnIndex = idx;
return true;
}
}
// It wasn't found as an existing entry. See if we have room for a new one.
if (textureReturnStruct.size() >= TSampler::structReturnSlots) {
error(loc, "Texture template struct return slots exceeded", "", "");
return false;
}
// Insert it in the vector that tracks struct return types.
sampler.structReturnIndex = unsigned(textureReturnStruct.size());
textureReturnStruct.push_back(members);
// Success!
return true;
}
// Return the sampler return type in retType.
void HlslParseContext::getTextureReturnType(const TSampler& sampler, TType& retType) const
{
if (sampler.hasReturnStruct()) {
assert(textureReturnStruct.size() >= sampler.structReturnIndex);
// We land here if the texture return is a structure.
TTypeList* blockStruct = textureReturnStruct[sampler.structReturnIndex];
const TType resultType(blockStruct, "");
retType.shallowCopy(resultType);
} else {
// We land here if the texture return is a vector or scalar.
const TType resultType(sampler.type, EvqTemporary, sampler.getVectorSize());
retType.shallowCopy(resultType);
}
}
// Return a symbol for the tessellation linkage variable of the given TBuiltInVariable type
TIntermSymbol* HlslParseContext::findTessLinkageSymbol(TBuiltInVariable biType) const
{
const auto it = builtInTessLinkageSymbols.find(biType);
if (it == builtInTessLinkageSymbols.end()) // if it wasn't declared by the user, return nullptr
return nullptr;
return intermediate.addSymbol(*it->second->getAsVariable());
}
// Find the patch constant function (issues error, returns nullptr if not found)
const TFunction* HlslParseContext::findPatchConstantFunction(const TSourceLoc& loc)
{
if (symbolTable.isFunctionNameVariable(patchConstantFunctionName)) {
error(loc, "can't use variable in patch constant function", patchConstantFunctionName.c_str(), "");
return nullptr;
}
const TString mangledName = patchConstantFunctionName + "(";
// create list of PCF candidates
TVector<const TFunction*> candidateList;
bool builtIn;
symbolTable.findFunctionNameList(mangledName, candidateList, builtIn);
// We have to have one and only one, or we don't know which to pick: the patchconstantfunc does not
// allow any disambiguation of overloads.
if (candidateList.empty()) {
error(loc, "patch constant function not found", patchConstantFunctionName.c_str(), "");
return nullptr;
}
// Based on directed experiments, it appears that if there are overloaded patchconstantfunctions,
// HLSL picks the last one in shader source order. Since that isn't yet implemented here, error
// out if there is more than one candidate.
if (candidateList.size() > 1) {
error(loc, "ambiguous patch constant function", patchConstantFunctionName.c_str(), "");
return nullptr;
}
return candidateList[0];
}
// Finalization step: Add patch constant function invocation
void HlslParseContext::addPatchConstantInvocation()
{
TSourceLoc loc;
loc.init();
// If there's no patch constant function, or we're not a HS, do nothing.
if (patchConstantFunctionName.empty() || language != EShLangTessControl)
return;
// Look for built-in variables in a function's parameter list.
const auto findBuiltIns = [&](const TFunction& function, std::set<tInterstageIoData>& builtIns) {
for (int p=0; p<function.getParamCount(); ++p) {
TStorageQualifier storage = function[p].type->getQualifier().storage;
if (storage == EvqConstReadOnly) // treated identically to input
storage = EvqIn;
if (function[p].getDeclaredBuiltIn() != EbvNone)
builtIns.insert(HlslParseContext::tInterstageIoData(function[p].getDeclaredBuiltIn(), storage));
else
builtIns.insert(HlslParseContext::tInterstageIoData(function[p].type->getQualifier().builtIn, storage));
}
};
// If we synthesize a built-in interface variable, we must add it to the linkage.
const auto addToLinkage = [&](const TType& type, const TString* name, TIntermSymbol** symbolNode) {
if (name == nullptr) {
error(loc, "unable to locate patch function parameter name", "", "");
return;
} else {
TVariable& variable = *new TVariable(name, type);
if (! symbolTable.insert(variable)) {
error(loc, "unable to declare patch constant function interface variable", name->c_str(), "");
return;
}
globalQualifierFix(loc, variable.getWritableType().getQualifier());
if (symbolNode != nullptr)
*symbolNode = intermediate.addSymbol(variable);
trackLinkage(variable);
}
};
const auto isOutputPatch = [](TFunction& patchConstantFunction, int param) {
const TType& type = *patchConstantFunction[param].type;
const TBuiltInVariable biType = patchConstantFunction[param].getDeclaredBuiltIn();
return type.isSizedArray() && biType == EbvOutputPatch;
};
// We will perform these steps. Each is in a scoped block for separation: they could
// become separate functions to make addPatchConstantInvocation shorter.
//
// 1. Union the interfaces, and create built-ins for anything present in the PCF and
// declared as a built-in variable that isn't present in the entry point's signature.
//
// 2. Synthesizes a call to the patchconstfunction using built-in variables from either main,
// or the ones we created. Matching is based on built-in type. We may use synthesized
// variables from (1) above.
//
// 2B: Synthesize per control point invocations of wrapped entry point if the PCF requires them.
//
// 3. Create a return sequence: copy the return value (if any) from the PCF to a
// (non-sanitized) output variable. In case this may involve multiple copies, such as for
// an arrayed variable, a temporary copy of the PCF output is created to avoid multiple
// indirections into a complex R-value coming from the call to the PCF.
//
// 4. Create a barrier.
//
// 5/5B. Call the PCF inside an if test for (invocation id == 0).
TFunction* patchConstantFunctionPtr = const_cast<TFunction*>(findPatchConstantFunction(loc));
if (patchConstantFunctionPtr == nullptr)
return;
TFunction& patchConstantFunction = *patchConstantFunctionPtr;
const int pcfParamCount = patchConstantFunction.getParamCount();
TIntermSymbol* invocationIdSym = findTessLinkageSymbol(EbvInvocationId);
TIntermSequence& epBodySeq = entryPointFunctionBody->getAsAggregate()->getSequence();
int outPatchParam = -1; // -1 means there isn't one.
// ================ Step 1A: Union Interfaces ================
// Our patch constant function.
{
std::set<tInterstageIoData> pcfBuiltIns; // patch constant function built-ins
std::set<tInterstageIoData> epfBuiltIns; // entry point function built-ins
assert(entryPointFunction);
assert(entryPointFunctionBody);
findBuiltIns(patchConstantFunction, pcfBuiltIns);
findBuiltIns(*entryPointFunction, epfBuiltIns);
// Find the set of built-ins in the PCF that are not present in the entry point.
std::set<tInterstageIoData> notInEntryPoint;
notInEntryPoint = pcfBuiltIns;
// std::set_difference not usable on unordered containers
for (auto bi = epfBuiltIns.begin(); bi != epfBuiltIns.end(); ++bi)
notInEntryPoint.erase(*bi);
// Now we'll add those to the entry and to the linkage.
for (int p=0; p<pcfParamCount; ++p) {
const TBuiltInVariable biType = patchConstantFunction[p].getDeclaredBuiltIn();
TStorageQualifier storage = patchConstantFunction[p].type->getQualifier().storage;
// Track whether there is an output patch param
if (isOutputPatch(patchConstantFunction, p)) {
if (outPatchParam >= 0) {
// Presently we only support one per ctrl pt input.
error(loc, "unimplemented: multiple output patches in patch constant function", "", "");
return;
}
outPatchParam = p;
}
if (biType != EbvNone) {
TType* paramType = patchConstantFunction[p].type->clone();
if (storage == EvqConstReadOnly) // treated identically to input
storage = EvqIn;
// Presently, the only non-built-in we support is InputPatch, which is treated as
// a pseudo-built-in.
if (biType == EbvInputPatch) {
builtInTessLinkageSymbols[biType] = inputPatch;
} else if (biType == EbvOutputPatch) {
// Nothing...
} else {
// Use the original declaration type for the linkage
paramType->getQualifier().builtIn = biType;
if (biType == EbvTessLevelInner || biType == EbvTessLevelOuter)
paramType->getQualifier().patch = true;
if (notInEntryPoint.count(tInterstageIoData(biType, storage)) == 1)
addToLinkage(*paramType, patchConstantFunction[p].name, nullptr);
}
}
}
// If we didn't find it because the shader made one, add our own.
if (invocationIdSym == nullptr) {
TType invocationIdType(EbtUint, EvqIn, 1);
TString* invocationIdName = NewPoolTString("InvocationId");
invocationIdType.getQualifier().builtIn = EbvInvocationId;
addToLinkage(invocationIdType, invocationIdName, &invocationIdSym);
}
assert(invocationIdSym);
}
TIntermTyped* pcfArguments = nullptr;
TVariable* perCtrlPtVar = nullptr;
// ================ Step 1B: Argument synthesis ================
// Create pcfArguments for synthesis of patchconstantfunction invocation
{
for (int p=0; p<pcfParamCount; ++p) {
TIntermTyped* inputArg = nullptr;
if (p == outPatchParam) {
if (perCtrlPtVar == nullptr) {
perCtrlPtVar = makeInternalVariable(*patchConstantFunction[outPatchParam].name,
*patchConstantFunction[outPatchParam].type);
perCtrlPtVar->getWritableType().getQualifier().makeTemporary();
}
inputArg = intermediate.addSymbol(*perCtrlPtVar, loc);
} else {
// find which built-in it is
const TBuiltInVariable biType = patchConstantFunction[p].getDeclaredBuiltIn();
if (biType == EbvInputPatch && inputPatch == nullptr) {
error(loc, "unimplemented: PCF input patch without entry point input patch parameter", "", "");
return;
}
inputArg = findTessLinkageSymbol(biType);
if (inputArg == nullptr) {
error(loc, "unable to find patch constant function built-in variable", "", "");
return;
}
}
if (pcfParamCount == 1)
pcfArguments = inputArg;
else
pcfArguments = intermediate.growAggregate(pcfArguments, inputArg);
}
}
// ================ Step 2: Synthesize call to PCF ================
TIntermAggregate* pcfCallSequence = nullptr;
TIntermTyped* pcfCall = nullptr;
{
// Create a function call to the patchconstantfunction
if (pcfArguments)
addInputArgumentConversions(patchConstantFunction, pcfArguments);
// Synthetic call.
pcfCall = intermediate.setAggregateOperator(pcfArguments, EOpFunctionCall, patchConstantFunction.getType(), loc);
pcfCall->getAsAggregate()->setUserDefined();
pcfCall->getAsAggregate()->setName(patchConstantFunction.getMangledName());
intermediate.addToCallGraph(infoSink, intermediate.getEntryPointMangledName().c_str(),
patchConstantFunction.getMangledName());
if (pcfCall->getAsAggregate()) {
TQualifierList& qualifierList = pcfCall->getAsAggregate()->getQualifierList();
for (int i = 0; i < patchConstantFunction.getParamCount(); ++i) {
TStorageQualifier qual = patchConstantFunction[i].type->getQualifier().storage;
qualifierList.push_back(qual);
}
pcfCall = addOutputArgumentConversions(patchConstantFunction, *pcfCall->getAsOperator());
}
}
// ================ Step 2B: Per Control Point synthesis ================
// If there is per control point data, we must either emulate that with multiple
// invocations of the entry point to build up an array, or (TODO:) use a yet
// unavailable extension to look across the SIMD lanes. This is the former
// as a placeholder for the latter.
if (outPatchParam >= 0) {
// We must introduce a local temp variable of the type wanted by the PCF input.
const int arraySize = patchConstantFunction[outPatchParam].type->getOuterArraySize();
if (entryPointFunction->getType().getBasicType() == EbtVoid) {
error(loc, "entry point must return a value for use with patch constant function", "", "");
return;
}
// Create calls to wrapped main to fill in the array. We will substitute fixed values
// of invocation ID when calling the wrapped main.
// This is the type of the each member of the per ctrl point array.
const TType derefType(perCtrlPtVar->getType(), 0);
for (int cpt = 0; cpt < arraySize; ++cpt) {
// TODO: improve. substr(1) here is to avoid the '@' that was grafted on but isn't in the symtab
// for this function.
const TString origName = entryPointFunction->getName().substr(1);
TFunction callee(&origName, TType(EbtVoid));
TIntermTyped* callingArgs = nullptr;
for (int i = 0; i < entryPointFunction->getParamCount(); i++) {
TParameter& param = (*entryPointFunction)[i];
TType& paramType = *param.type;
if (paramType.getQualifier().isParamOutput()) {
error(loc, "unimplemented: entry point outputs in patch constant function invocation", "", "");
return;
}
if (paramType.getQualifier().isParamInput()) {
TIntermTyped* arg = nullptr;
if ((*entryPointFunction)[i].getDeclaredBuiltIn() == EbvInvocationId) {
// substitute invocation ID with the array element ID
arg = intermediate.addConstantUnion(cpt, loc);
} else {
TVariable* argVar = makeInternalVariable(*param.name, *param.type);
argVar->getWritableType().getQualifier().makeTemporary();
arg = intermediate.addSymbol(*argVar);
}
handleFunctionArgument(&callee, callingArgs, arg);
}
}
// Call and assign to per ctrl point variable
currentCaller = intermediate.getEntryPointMangledName().c_str();
TIntermTyped* callReturn = handleFunctionCall(loc, &callee, callingArgs);
TIntermTyped* index = intermediate.addConstantUnion(cpt, loc);
TIntermSymbol* perCtrlPtSym = intermediate.addSymbol(*perCtrlPtVar, loc);
TIntermTyped* element = intermediate.addIndex(EOpIndexDirect, perCtrlPtSym, index, loc);
element->setType(derefType);
element->setLoc(loc);
pcfCallSequence = intermediate.growAggregate(pcfCallSequence,
handleAssign(loc, EOpAssign, element, callReturn));
}
}
// ================ Step 3: Create return Sequence ================
// Return sequence: copy PCF result to a temporary, then to shader output variable.
if (pcfCall->getBasicType() != EbtVoid) {
const TType* retType = &patchConstantFunction.getType(); // return type from the PCF
TType outType; // output type that goes with the return type.
outType.shallowCopy(*retType);
// substitute the output type
const auto newLists = ioTypeMap.find(retType->getStruct());
if (newLists != ioTypeMap.end())
outType.setStruct(newLists->second.output);
// Substitute the top level type's built-in type
if (patchConstantFunction.getDeclaredBuiltInType() != EbvNone)
outType.getQualifier().builtIn = patchConstantFunction.getDeclaredBuiltInType();
outType.getQualifier().patch = true; // make it a per-patch variable
TVariable* pcfOutput = makeInternalVariable("@patchConstantOutput", outType);
pcfOutput->getWritableType().getQualifier().storage = EvqVaryingOut;
if (pcfOutput->getType().isStruct())
flatten(*pcfOutput, false);
assignToInterface(*pcfOutput);
TIntermSymbol* pcfOutputSym = intermediate.addSymbol(*pcfOutput, loc);
// The call to the PCF is a complex R-value: we want to store it in a temp to avoid
// repeated calls to the PCF:
TVariable* pcfCallResult = makeInternalVariable("@patchConstantResult", *retType);
pcfCallResult->getWritableType().getQualifier().makeTemporary();
TIntermSymbol* pcfResultVar = intermediate.addSymbol(*pcfCallResult, loc);
TIntermNode* pcfResultAssign = handleAssign(loc, EOpAssign, pcfResultVar, pcfCall);
TIntermNode* pcfResultToOut = handleAssign(loc, EOpAssign, pcfOutputSym,
intermediate.addSymbol(*pcfCallResult, loc));
pcfCallSequence = intermediate.growAggregate(pcfCallSequence, pcfResultAssign);
pcfCallSequence = intermediate.growAggregate(pcfCallSequence, pcfResultToOut);
} else {
pcfCallSequence = intermediate.growAggregate(pcfCallSequence, pcfCall);
}
// ================ Step 4: Barrier ================
TIntermTyped* barrier = new TIntermAggregate(EOpBarrier);
barrier->setLoc(loc);
barrier->setType(TType(EbtVoid));
epBodySeq.insert(epBodySeq.end(), barrier);
// ================ Step 5: Test on invocation ID ================
TIntermTyped* zero = intermediate.addConstantUnion(0, loc, true);
TIntermTyped* cmp = intermediate.addBinaryNode(EOpEqual, invocationIdSym, zero, loc, TType(EbtBool));
// ================ Step 5B: Create if statement on Invocation ID == 0 ================
intermediate.setAggregateOperator(pcfCallSequence, EOpSequence, TType(EbtVoid), loc);
TIntermTyped* invocationIdTest = new TIntermSelection(cmp, pcfCallSequence, nullptr);
invocationIdTest->setLoc(loc);
// add our test sequence before the return.
epBodySeq.insert(epBodySeq.end(), invocationIdTest);
}
// Finalization step: remove unused buffer blocks from linkage (we don't know until the
// shader is entirely compiled).
// Preserve order of remaining symbols.
void HlslParseContext::removeUnusedStructBufferCounters()
{
const auto endIt = std::remove_if(linkageSymbols.begin(), linkageSymbols.end(),
[this](const TSymbol* sym) {
const auto sbcIt = structBufferCounter.find(sym->getName());
return sbcIt != structBufferCounter.end() && !sbcIt->second;
});
linkageSymbols.erase(endIt, linkageSymbols.end());
}
// Finalization step: patch texture shadow modes to match samplers they were combined with
void HlslParseContext::fixTextureShadowModes()
{
for (auto symbol = linkageSymbols.begin(); symbol != linkageSymbols.end(); ++symbol) {
TSampler& sampler = (*symbol)->getWritableType().getSampler();
if (sampler.isTexture()) {
const auto shadowMode = textureShadowVariant.find((*symbol)->getUniqueId());
if (shadowMode != textureShadowVariant.end()) {
if (shadowMode->second->overloaded())
// Texture needs legalization if it's been seen with both shadow and non-shadow modes.
intermediate.setNeedsLegalization();
sampler.shadow = shadowMode->second->isShadowId((*symbol)->getUniqueId());
}
}
}
}
// Finalization step: patch append methods to use proper stream output, which isn't known until
// main is parsed, which could happen after the append method is parsed.
void HlslParseContext::finalizeAppendMethods()
{
TSourceLoc loc;
loc.init();
// Nothing to do: bypass test for valid stream output.
if (gsAppends.empty())
return;
if (gsStreamOutput == nullptr) {
error(loc, "unable to find output symbol for Append()", "", "");
return;
}
// Patch append sequences, now that we know the stream output symbol.
for (auto append = gsAppends.begin(); append != gsAppends.end(); ++append) {
append->node->getSequence()[0] =
handleAssign(append->loc, EOpAssign,
intermediate.addSymbol(*gsStreamOutput, append->loc),
append->node->getSequence()[0]->getAsTyped());
}
}
// post-processing
void HlslParseContext::finish()
{
// Error check: There was a dangling .mips operator. These are not nested constructs in the grammar, so
// cannot be detected there. This is not strictly needed in a non-validating parser; it's just helpful.
if (! mipsOperatorMipArg.empty()) {
error(mipsOperatorMipArg.back().loc, "unterminated mips operator:", "", "");
}
removeUnusedStructBufferCounters();
addPatchConstantInvocation();
fixTextureShadowModes();
finalizeAppendMethods();
// Communicate out (esp. for command line) that we formed AST that will make
// illegal AST SPIR-V and it needs transforms to legalize it.
if (intermediate.needsLegalization() && (messages & EShMsgHlslLegalization))
infoSink.info << "WARNING: AST will form illegal SPIR-V; need to transform to legalize";
TParseContextBase::finish();
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslParseables.cpp | //
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// Create strings that declare built-in definitions, add built-ins programmatically
// that cannot be expressed in the strings, and establish mappings between
// built-in functions and operators.
//
// Where to put a built-in:
// TBuiltInParseablesHlsl::initialize(version,profile) context-independent textual built-ins; add them to the right string
// TBuiltInParseablesHlsl::initialize(resources,...) context-dependent textual built-ins; add them to the right string
// TBuiltInParseablesHlsl::identifyBuiltIns(...,symbolTable) context-independent programmatic additions/mappings to the symbol table,
// including identifying what extensions are needed if a version does not allow a symbol
// TBuiltInParseablesHlsl::identifyBuiltIns(...,symbolTable, resources) context-dependent programmatic additions/mappings to the
// symbol table, including identifying what extensions are needed if a version does
// not allow a symbol
//
#include "hlslParseables.h"
#include "hlslParseHelper.h"
#include <cctype>
#include <utility>
#include <algorithm>
namespace { // anonymous namespace functions
// arg order queries
bool IsSamplerType(const char argType) { return argType == 'S' || argType == 's'; }
bool IsArrayed(const char argOrder) { return argOrder == '@' || argOrder == '&' || argOrder == '#'; }
bool IsTextureNonMS(const char argOrder) { return argOrder == '%'; }
bool IsSubpassInput(const char argOrder) { return argOrder == '[' || argOrder == ']'; }
bool IsArrayedTexture(const char argOrder) { return argOrder == '@'; }
bool IsTextureMS(const char argOrder) { return argOrder == '$' || argOrder == '&'; }
bool IsMS(const char argOrder) { return IsTextureMS(argOrder) || argOrder == ']'; }
bool IsBuffer(const char argOrder) { return argOrder == '*' || argOrder == '~'; }
bool IsImage(const char argOrder) { return argOrder == '!' || argOrder == '#' || argOrder == '~'; }
bool IsTextureType(const char argOrder)
{
return IsTextureNonMS(argOrder) || IsArrayedTexture(argOrder) ||
IsTextureMS(argOrder) || IsBuffer(argOrder) || IsImage(argOrder);
}
// Reject certain combinations that are illegal sample methods. For example,
// 3D arrays.
bool IsIllegalSample(const glslang::TString& name, const char* argOrder, int dim0)
{
const bool isArrayed = IsArrayed(*argOrder);
const bool isMS = IsTextureMS(*argOrder);
const bool isBuffer = IsBuffer(*argOrder);
// there are no 3D arrayed textures, or 3D SampleCmp(LevelZero)
if (dim0 == 3 && (isArrayed || name == "SampleCmp" || name == "SampleCmpLevelZero"))
return true;
const int numArgs = int(std::count(argOrder, argOrder + strlen(argOrder), ',')) + 1;
// Reject invalid offset forms with cubemaps
if (dim0 == 4) {
if ((name == "Sample" && numArgs >= 4) ||
(name == "SampleBias" && numArgs >= 5) ||
(name == "SampleCmp" && numArgs >= 5) ||
(name == "SampleCmpLevelZero" && numArgs >= 5) ||
(name == "SampleGrad" && numArgs >= 6) ||
(name == "SampleLevel" && numArgs >= 5))
return true;
}
const bool isGather =
(name == "Gather" ||
name == "GatherRed" ||
name == "GatherGreen" ||
name == "GatherBlue" ||
name == "GatherAlpha");
const bool isGatherCmp =
(name == "GatherCmp" ||
name == "GatherCmpRed" ||
name == "GatherCmpGreen" ||
name == "GatherCmpBlue" ||
name == "GatherCmpAlpha");
// Reject invalid Gathers
if (isGather || isGatherCmp) {
if (dim0 == 1 || dim0 == 3) // there are no 1D or 3D gathers
return true;
// no offset on cube or cube array gathers
if (dim0 == 4) {
if ((isGather && numArgs > 3) || (isGatherCmp && numArgs > 4))
return true;
}
}
// Reject invalid Loads
if (name == "Load" && dim0 == 4)
return true; // Load does not support any cubemaps, arrayed or not.
// Multisample formats are only 2D and 2Darray
if (isMS && dim0 != 2)
return true;
// Buffer are only 1D
if (isBuffer && dim0 != 1)
return true;
return false;
}
// Return the number of the coordinate arg, if any
int CoordinateArgPos(const glslang::TString& name, bool isTexture)
{
if (!isTexture || (name == "GetDimensions"))
return -1; // has none
else if (name == "Load")
return 1;
else
return 2; // other texture methods are 2
}
// Some texture methods use an addition coordinate dimension for the mip
bool HasMipInCoord(const glslang::TString& name, bool isMS, bool isBuffer, bool isImage)
{
return name == "Load" && !isMS && !isBuffer && !isImage;
}
// LOD calculations don't pass the array level in the coordinate.
bool NoArrayCoord(const glslang::TString& name)
{
return name == "CalculateLevelOfDetail" || name == "CalculateLevelOfDetailUnclamped";
}
// Handle IO params marked with > or <
const char* IoParam(glslang::TString& s, const char* nthArgOrder)
{
if (*nthArgOrder == '>') { // output params
++nthArgOrder;
s.append("out ");
} else if (*nthArgOrder == '<') { // input params
++nthArgOrder;
s.append("in ");
}
return nthArgOrder;
}
// Handle repeated args
void HandleRepeatArg(const char*& arg, const char*& prev, const char* current)
{
if (*arg == ',' || *arg == '\0')
arg = prev;
else
prev = current;
}
// Return true for the end of a single argument key, which can be the end of the string, or
// the comma separator.
inline bool IsEndOfArg(const char* arg)
{
return arg == nullptr || *arg == '\0' || *arg == ',';
}
// If this is a fixed vector size, such as V3, return the size. Else return 0.
int FixedVecSize(const char* arg)
{
while (!IsEndOfArg(arg)) {
if (isdigit(*arg))
return *arg - '0';
++arg;
}
return 0; // none found.
}
// Create and return a type name, using HLSL type conventions.
//
// order: S = scalar, V = vector, M = matrix
// argType: F = float, D = double, I = int, U = uint, B = bool, S = sampler
// dim0 = vector dimension, or matrix 1st dimension
// dim1 = matrix 2nd dimension
glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, const char* argType, int dim0, int dim1)
{
const bool isTranspose = (argOrder[0] == '^');
const bool isTexture = IsTextureType(argOrder[0]);
const bool isArrayed = IsArrayed(argOrder[0]);
const bool isSampler = IsSamplerType(argType[0]);
const bool isMS = IsMS(argOrder[0]);
const bool isBuffer = IsBuffer(argOrder[0]);
const bool isImage = IsImage(argOrder[0]);
const bool isSubpass = IsSubpassInput(argOrder[0]);
char type = *argType;
if (isTranspose) { // Take transpose of matrix dimensions
std::swap(dim0, dim1);
} else if (isTexture || isSubpass) {
if (type == 'F') // map base type to texture of that type.
type = 'T'; // e.g, int -> itexture, uint -> utexture, etc.
else if (type == 'I')
type = 'i';
else if (type == 'U')
type = 'u';
}
if (isTranspose)
++argOrder;
char order = *argOrder;
switch (type) {
case '-': s += "void"; break;
case 'F': s += "float"; break;
case 'D': s += "double"; break;
case 'I': s += "int"; break;
case 'U': s += "uint"; break;
case 'L': s += "int64_t"; break;
case 'M': s += "uint64_t"; break;
case 'B': s += "bool"; break;
case 'S': s += "sampler"; break;
case 's': s += "SamplerComparisonState"; break;
case 'T': s += ((isBuffer && isImage) ? "RWBuffer" :
isSubpass ? "SubpassInput" :
isBuffer ? "Buffer" :
isImage ? "RWTexture" : "Texture"); break;
case 'i': s += ((isBuffer && isImage) ? "RWBuffer" :
isSubpass ? "SubpassInput" :
isBuffer ? "Buffer" :
isImage ? "RWTexture" : "Texture"); break;
case 'u': s += ((isBuffer && isImage) ? "RWBuffer" :
isSubpass ? "SubpassInput" :
isBuffer ? "Buffer" :
isImage ? "RWTexture" : "Texture"); break;
default: s += "UNKNOWN_TYPE"; break;
}
if (isSubpass && isMS)
s += "MS";
// handle fixed vector sizes, such as float3, and only ever 3.
const int fixedVecSize = FixedVecSize(argOrder);
if (fixedVecSize != 0)
dim0 = dim1 = fixedVecSize;
const char dim0Char = ('0' + char(dim0));
const char dim1Char = ('0' + char(dim1));
// Add sampler dimensions
if (isSampler || isTexture) {
if ((order == 'V' || isTexture) && !isBuffer) {
switch (dim0) {
case 1: s += "1D"; break;
case 2: s += (isMS ? "2DMS" : "2D"); break;
case 3: s += "3D"; break;
case 4: s += (type == 'S'? "CUBE" : "Cube"); break;
default: s += "UNKNOWN_SAMPLER"; break;
}
}
} else {
// Non-sampler type:
// verify dimensions
if (((order == 'V' || order == 'M') && (dim0 < 1 || dim0 > 4)) ||
(order == 'M' && (dim1 < 1 || dim1 > 4))) {
s += "UNKNOWN_DIMENSION";
return s;
}
switch (order) {
case '-': break; // no dimensions for voids
case 'S': break; // no dimensions on scalars
case 'V':
s += dim0Char;
break;
case 'M':
s += dim0Char;
s += 'x';
s += dim1Char;
break;
default:
break;
}
}
// handle arrayed textures
if (isArrayed)
s += "Array";
switch (type) {
case 'i': s += "<int"; s += dim0Char; s += ">"; break;
case 'u': s += "<uint"; s += dim0Char; s += ">"; break;
case 'T': s += "<float"; s += dim0Char; s += ">"; break;
default: break;
}
return s;
}
// This rejects prototypes not normally valid for GLSL and it's way of finding
// overloaded built-ins under implicit type conversion.
//
// It is possible that this is not needed, but that would require some tweaking
// of other rules to get the same results.
inline bool IsValid(const char* cname, char /* retOrder */, char /* retType */, char argOrder, char /* argType */, int dim0, int /* dim1 */)
{
const bool isVec = (argOrder == 'V');
const std::string name(cname);
// these do not have vec1 versions
if (dim0 == 1 && (name == "normalize" || name == "reflect" || name == "refract"))
return false;
if (!IsTextureType(argOrder) && (isVec && dim0 == 1)) // avoid vec1
return false;
return true;
}
// return position of end of argument specifier
inline const char* FindEndOfArg(const char* arg)
{
while (!IsEndOfArg(arg))
++arg;
return *arg == '\0' ? nullptr : arg;
}
// Return pointer to beginning of Nth argument specifier in the string.
inline const char* NthArg(const char* arg, int n)
{
for (int x=0; x<n && arg; ++x)
if ((arg = FindEndOfArg(arg)) != nullptr)
++arg; // skip arg separator
return arg;
}
inline void FindVectorMatrixBounds(const char* argOrder, int fixedVecSize, int& dim0Min, int& dim0Max, int& /*dim1Min*/, int& dim1Max)
{
for (int arg = 0; ; ++arg) {
const char* nthArgOrder(NthArg(argOrder, arg));
if (nthArgOrder == nullptr)
break;
else if (*nthArgOrder == 'V' || IsSubpassInput(*nthArgOrder))
dim0Max = 4;
else if (*nthArgOrder == 'M')
dim0Max = dim1Max = 4;
}
if (fixedVecSize > 0) // handle fixed sized vectors
dim0Min = dim0Max = fixedVecSize;
}
} // end anonymous namespace
namespace glslang {
TBuiltInParseablesHlsl::TBuiltInParseablesHlsl()
{
}
//
// Handle creation of mat*mat specially, since it doesn't fall conveniently out of
// the generic prototype creation code below.
//
void TBuiltInParseablesHlsl::createMatTimesMat()
{
TString& s = commonBuiltins;
for (int xRows = 1; xRows <=4; xRows++) {
for (int xCols = 1; xCols <=4; xCols++) {
const int yRows = xCols;
for (int yCols = 1; yCols <=4; yCols++) {
const int retRows = xRows;
const int retCols = yCols;
// Create a mat * mat of the appropriate dimensions
AppendTypeName(s, "M", "F", retRows, retCols); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append("("); // open paren
AppendTypeName(s, "M", "F", xRows, xCols); // add X input
s.append(", ");
AppendTypeName(s, "M", "F", yRows, yCols); // add Y input
s.append(");\n"); // close paren
}
// Create M*V
AppendTypeName(s, "V", "F", xRows, 1); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append("("); // open paren
AppendTypeName(s, "M", "F", xRows, xCols); // add X input
s.append(", ");
AppendTypeName(s, "V", "F", xCols, 1); // add Y input
s.append(");\n"); // close paren
// Create V*M
AppendTypeName(s, "V", "F", xCols, 1); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append("("); // open paren
AppendTypeName(s, "V", "F", xRows, 1); // add Y input
s.append(", ");
AppendTypeName(s, "M", "F", xRows, xCols); // add X input
s.append(");\n"); // close paren
}
}
}
//
// Add all context-independent built-in functions and variables that are present
// for the given version and profile. Share common ones across stages, otherwise
// make stage-specific entries.
//
// Most built-ins variables can be added as simple text strings. Some need to
// be added programmatically, which is done later in IdentifyBuiltIns() below.
//
void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, const SpvVersion& /*spvVersion*/)
{
static const EShLanguageMask EShLangAll = EShLanguageMask(EShLangCount - 1);
// These are the actual stage masks defined in the documentation, in case they are
// needed for future validation. For now, they are commented out, and set below
// to EShLangAll, to allow any intrinsic to be used in any shader, which is legal
// if it is not called.
//
// static const EShLanguageMask EShLangPSCS = EShLanguageMask(EShLangFragmentMask | EShLangComputeMask);
// static const EShLanguageMask EShLangVSPSGS = EShLanguageMask(EShLangVertexMask | EShLangFragmentMask | EShLangGeometryMask);
// static const EShLanguageMask EShLangCS = EShLangComputeMask;
// static const EShLanguageMask EShLangPS = EShLangFragmentMask;
// static const EShLanguageMask EShLangHS = EShLangTessControlMask;
// This set uses EShLangAll for everything.
static const EShLanguageMask EShLangPSCS = EShLangAll;
static const EShLanguageMask EShLangVSPSGS = EShLangAll;
static const EShLanguageMask EShLangCS = EShLangAll;
static const EShLanguageMask EShLangPS = EShLangAll;
static const EShLanguageMask EShLangHS = EShLangAll;
static const EShLanguageMask EShLangGS = EShLangAll;
// This structure encodes the prototype information for each HLSL intrinsic.
// Because explicit enumeration would be cumbersome, it's procedurally generated.
// orderKey can be:
// S = scalar, V = vector, M = matrix, - = void
// typekey can be:
// D = double, F = float, U = uint, I = int, B = bool, S = sampler, s = shadowSampler, M = uint64_t, L = int64_t
// An empty order or type key repeats the first one. E.g: SVM,, means 3 args each of SVM.
// '>' as first letter of order creates an output parameter
// '<' as first letter of order creates an input parameter
// '^' as first letter of order takes transpose dimensions
// '%' as first letter of order creates texture of given F/I/U type (texture, itexture, etc)
// '@' as first letter of order creates arrayed texture of given type
// '$' / '&' as first letter of order creates 2DMS / 2DMSArray textures
// '*' as first letter of order creates buffer object
// '!' as first letter of order creates image object
// '#' as first letter of order creates arrayed image object
// '~' as first letter of order creates an image buffer object
// '[' / ']' as first letter of order creates a SubpassInput/SubpassInputMS object
static const struct {
const char* name; // intrinsic name
const char* retOrder; // return type key: empty matches order of 1st argument
const char* retType; // return type key: empty matches type of 1st argument
const char* argOrder; // argument order key
const char* argType; // argument type key
unsigned int stage; // stage mask
bool method; // true if it's a method.
} hlslIntrinsics[] = {
// name retOrd retType argOrder argType stage mask method
// ----------------------------------------------------------------------------------------------------------------
{ "abort", nullptr, nullptr, "-", "-", EShLangAll, false },
{ "abs", nullptr, nullptr, "SVM", "DFUI", EShLangAll, false },
{ "acos", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "all", "S", "B", "SVM", "BFIU", EShLangAll, false },
{ "AllMemoryBarrier", nullptr, nullptr, "-", "-", EShLangCS, false },
{ "AllMemoryBarrierWithGroupSync", nullptr, nullptr, "-", "-", EShLangCS, false },
{ "any", "S", "B", "SVM", "BFIU", EShLangAll, false },
{ "asdouble", "S", "D", "S,", "UI,", EShLangAll, false },
{ "asdouble", "V2", "D", "V2,", "UI,", EShLangAll, false },
{ "asfloat", nullptr, "F", "SVM", "BFIU", EShLangAll, false },
{ "asin", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "asint", nullptr, "I", "SVM", "FIU", EShLangAll, false },
{ "asuint", nullptr, "U", "SVM", "FIU", EShLangAll, false },
{ "atan", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "atan2", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
{ "ceil", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "CheckAccessFullyMapped", "S", "B" , "S", "U", EShLangPSCS, false },
{ "clamp", nullptr, nullptr, "SVM,,", "FUI,,", EShLangAll, false },
{ "clip", "-", "-", "SVM", "FUI", EShLangPS, false },
{ "cos", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "cosh", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "countbits", nullptr, nullptr, "SV", "UI", EShLangAll, false },
{ "cross", nullptr, nullptr, "V3,", "F,", EShLangAll, false },
{ "D3DCOLORtoUBYTE4", "V4", "I", "V4", "F", EShLangAll, false },
{ "ddx", nullptr, nullptr, "SVM", "F", EShLangPS, false },
{ "ddx_coarse", nullptr, nullptr, "SVM", "F", EShLangPS, false },
{ "ddx_fine", nullptr, nullptr, "SVM", "F", EShLangPS, false },
{ "ddy", nullptr, nullptr, "SVM", "F", EShLangPS, false },
{ "ddy_coarse", nullptr, nullptr, "SVM", "F", EShLangPS, false },
{ "ddy_fine", nullptr, nullptr, "SVM", "F", EShLangPS, false },
{ "degrees", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "determinant", "S", "F", "M", "F", EShLangAll, false },
{ "DeviceMemoryBarrier", nullptr, nullptr, "-", "-", EShLangPSCS, false },
{ "DeviceMemoryBarrierWithGroupSync", nullptr, nullptr, "-", "-", EShLangCS, false },
{ "distance", "S", "F", "SV,", "F,", EShLangAll, false },
{ "dot", "S", nullptr, "SV,", "FI,", EShLangAll, false },
{ "dst", nullptr, nullptr, "V4,", "F,", EShLangAll, false },
// { "errorf", "-", "-", "", "", EShLangAll, false }, TODO: varargs
{ "EvaluateAttributeAtCentroid", nullptr, nullptr, "SVM", "F", EShLangPS, false },
{ "EvaluateAttributeAtSample", nullptr, nullptr, "SVM,S", "F,U", EShLangPS, false },
{ "EvaluateAttributeSnapped", nullptr, nullptr, "SVM,V2", "F,I", EShLangPS, false },
{ "exp", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "exp2", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "f16tof32", nullptr, "F", "SV", "U", EShLangAll, false },
{ "f32tof16", nullptr, "U", "SV", "F", EShLangAll, false },
{ "faceforward", nullptr, nullptr, "V,,", "F,,", EShLangAll, false },
{ "firstbithigh", nullptr, nullptr, "SV", "UI", EShLangAll, false },
{ "firstbitlow", nullptr, nullptr, "SV", "UI", EShLangAll, false },
{ "floor", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "fma", nullptr, nullptr, "SVM,,", "D,,", EShLangAll, false },
{ "fmod", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
{ "frac", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "frexp", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
{ "fwidth", nullptr, nullptr, "SVM", "F", EShLangPS, false },
{ "GetRenderTargetSampleCount", "S", "U", "-", "-", EShLangAll, false },
{ "GetRenderTargetSamplePosition", "V2", "F", "V1", "I", EShLangAll, false },
{ "GroupMemoryBarrier", nullptr, nullptr, "-", "-", EShLangCS, false },
{ "GroupMemoryBarrierWithGroupSync", nullptr, nullptr, "-", "-", EShLangCS, false },
{ "InterlockedAdd", "-", "-", "SVM,,>", "FUI,,", EShLangPSCS, false },
{ "InterlockedAdd", "-", "-", "SVM,", "FUI,", EShLangPSCS, false },
{ "InterlockedAnd", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
{ "InterlockedAnd", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
{ "InterlockedCompareExchange", "-", "-", "SVM,,,>", "UI,,,", EShLangPSCS, false },
{ "InterlockedCompareStore", "-", "-", "SVM,,", "UI,,", EShLangPSCS, false },
{ "InterlockedExchange", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
{ "InterlockedMax", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
{ "InterlockedMax", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
{ "InterlockedMin", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
{ "InterlockedMin", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
{ "InterlockedOr", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
{ "InterlockedOr", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
{ "InterlockedXor", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
{ "InterlockedXor", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
{ "isfinite", nullptr, "B" , "SVM", "F", EShLangAll, false },
{ "isinf", nullptr, "B" , "SVM", "F", EShLangAll, false },
{ "isnan", nullptr, "B" , "SVM", "F", EShLangAll, false },
{ "ldexp", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
{ "length", "S", "F", "SV", "F", EShLangAll, false },
{ "lerp", nullptr, nullptr, "VM,,", "F,,", EShLangAll, false },
{ "lerp", nullptr, nullptr, "SVM,,S", "F,,", EShLangAll, false },
{ "lit", "V4", "F", "S,,", "F,,", EShLangAll, false },
{ "log", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "log10", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "log2", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "mad", nullptr, nullptr, "SVM,,", "DFUI,,", EShLangAll, false },
{ "max", nullptr, nullptr, "SVM,", "FIU,", EShLangAll, false },
{ "min", nullptr, nullptr, "SVM,", "FIU,", EShLangAll, false },
{ "modf", nullptr, nullptr, "SVM,>", "FIU,", EShLangAll, false },
{ "msad4", "V4", "U", "S,V2,V4", "U,,", EShLangAll, false },
{ "mul", "S", nullptr, "S,S", "FI,", EShLangAll, false },
{ "mul", "V", nullptr, "S,V", "FI,", EShLangAll, false },
{ "mul", "M", nullptr, "S,M", "FI,", EShLangAll, false },
{ "mul", "V", nullptr, "V,S", "FI,", EShLangAll, false },
{ "mul", "S", nullptr, "V,V", "FI,", EShLangAll, false },
{ "mul", "M", nullptr, "M,S", "FI,", EShLangAll, false },
// mat*mat form of mul is handled in createMatTimesMat()
{ "noise", "S", "F", "V", "F", EShLangPS, false },
{ "normalize", nullptr, nullptr, "V", "F", EShLangAll, false },
{ "pow", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
{ "printf", nullptr, nullptr, "-", "-", EShLangAll, false },
{ "Process2DQuadTessFactorsAvg", "-", "-", "V4,V2,>V4,>V2,", "F,,,,", EShLangHS, false },
{ "Process2DQuadTessFactorsMax", "-", "-", "V4,V2,>V4,>V2,", "F,,,,", EShLangHS, false },
{ "Process2DQuadTessFactorsMin", "-", "-", "V4,V2,>V4,>V2,", "F,,,,", EShLangHS, false },
{ "ProcessIsolineTessFactors", "-", "-", "S,,>,>", "F,,,", EShLangHS, false },
{ "ProcessQuadTessFactorsAvg", "-", "-", "V4,S,>V4,>V2,", "F,,,,", EShLangHS, false },
{ "ProcessQuadTessFactorsMax", "-", "-", "V4,S,>V4,>V2,", "F,,,,", EShLangHS, false },
{ "ProcessQuadTessFactorsMin", "-", "-", "V4,S,>V4,>V2,", "F,,,,", EShLangHS, false },
{ "ProcessTriTessFactorsAvg", "-", "-", "V3,S,>V3,>S,", "F,,,,", EShLangHS, false },
{ "ProcessTriTessFactorsMax", "-", "-", "V3,S,>V3,>S,", "F,,,,", EShLangHS, false },
{ "ProcessTriTessFactorsMin", "-", "-", "V3,S,>V3,>S,", "F,,,,", EShLangHS, false },
{ "radians", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "rcp", nullptr, nullptr, "SVM", "FD", EShLangAll, false },
{ "reflect", nullptr, nullptr, "V,", "F,", EShLangAll, false },
{ "refract", nullptr, nullptr, "V,V,S", "F,,", EShLangAll, false },
{ "reversebits", nullptr, nullptr, "SV", "UI", EShLangAll, false },
{ "round", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "rsqrt", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "saturate", nullptr, nullptr , "SVM", "F", EShLangAll, false },
{ "sign", nullptr, nullptr, "SVM", "FI", EShLangAll, false },
{ "sin", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "sincos", "-", "-", "SVM,>,>", "F,,", EShLangAll, false },
{ "sinh", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "smoothstep", nullptr, nullptr, "SVM,,", "F,,", EShLangAll, false },
{ "sqrt", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "step", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
{ "tan", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "tanh", nullptr, nullptr, "SVM", "F", EShLangAll, false },
{ "tex1D", "V4", "F", "S,S", "S,F", EShLangPS, false },
{ "tex1D", "V4", "F", "S,S,V1,", "S,F,,", EShLangPS, false },
{ "tex1Dbias", "V4", "F", "S,V4", "S,F", EShLangPS, false },
{ "tex1Dgrad", "V4", "F", "S,,,", "S,F,,", EShLangPS, false },
{ "tex1Dlod", "V4", "F", "S,V4", "S,F", EShLangPS, false },
{ "tex1Dproj", "V4", "F", "S,V4", "S,F", EShLangPS, false },
{ "tex2D", "V4", "F", "V2,", "S,F", EShLangPS, false },
{ "tex2D", "V4", "F", "V2,,,", "S,F,,", EShLangPS, false },
{ "tex2Dbias", "V4", "F", "V2,V4", "S,F", EShLangPS, false },
{ "tex2Dgrad", "V4", "F", "V2,,,", "S,F,,", EShLangPS, false },
{ "tex2Dlod", "V4", "F", "V2,V4", "S,F", EShLangAll, false },
{ "tex2Dproj", "V4", "F", "V2,V4", "S,F", EShLangPS, false },
{ "tex3D", "V4", "F", "V3,", "S,F", EShLangPS, false },
{ "tex3D", "V4", "F", "V3,,,", "S,F,,", EShLangPS, false },
{ "tex3Dbias", "V4", "F", "V3,V4", "S,F", EShLangPS, false },
{ "tex3Dgrad", "V4", "F", "V3,,,", "S,F,,", EShLangPS, false },
{ "tex3Dlod", "V4", "F", "V3,V4", "S,F", EShLangPS, false },
{ "tex3Dproj", "V4", "F", "V3,V4", "S,F", EShLangPS, false },
{ "texCUBE", "V4", "F", "V4,V3", "S,F", EShLangPS, false },
{ "texCUBE", "V4", "F", "V4,V3,,", "S,F,,", EShLangPS, false },
{ "texCUBEbias", "V4", "F", "V4,", "S,F", EShLangPS, false },
{ "texCUBEgrad", "V4", "F", "V4,V3,,", "S,F,,", EShLangPS, false },
{ "texCUBElod", "V4", "F", "V4,", "S,F", EShLangPS, false },
{ "texCUBEproj", "V4", "F", "V4,", "S,F", EShLangPS, false },
{ "transpose", "^M", nullptr, "M", "FUIB", EShLangAll, false },
{ "trunc", nullptr, nullptr, "SVM", "F", EShLangAll, false },
// Texture object methods. Return type can be overridden by shader declaration.
// !O = no offset, O = offset
{ "Sample", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangPS, true },
{ "Sample", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangPS, true },
{ "SampleBias", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,S,F,F", EShLangPS, true },
{ "SampleBias", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,S,F,F,I", EShLangPS, true },
// TODO: FXC accepts int/uint samplers here. unclear what that means.
{ "SampleCmp", /*!O*/ "S", "F", "%@,S,V,S", "FIU,s,F,", EShLangPS, true },
{ "SampleCmp", /* O*/ "S", "F", "%@,S,V,S,V", "FIU,s,F,,I", EShLangPS, true },
// TODO: FXC accepts int/uint samplers here. unclear what that means.
{ "SampleCmpLevelZero", /*!O*/ "S", "F", "%@,S,V,S", "FIU,s,F,F", EShLangPS, true },
{ "SampleCmpLevelZero", /* O*/ "S", "F", "%@,S,V,S,V", "FIU,s,F,F,I", EShLangPS, true },
{ "SampleGrad", /*!O*/ "V4", nullptr, "%@,S,V,,", "FIU,S,F,,", EShLangAll, true },
{ "SampleGrad", /* O*/ "V4", nullptr, "%@,S,V,,,", "FIU,S,F,,,I", EShLangAll, true },
{ "SampleLevel", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,S,F,", EShLangAll, true },
{ "SampleLevel", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,S,F,,I", EShLangAll, true },
{ "Load", /*!O*/ "V4", nullptr, "%@,V", "FIU,I", EShLangAll, true },
{ "Load", /* O*/ "V4", nullptr, "%@,V,V", "FIU,I,I", EShLangAll, true },
{ "Load", /* +sampleidex*/ "V4", nullptr, "$&,V,S", "FIU,I,I", EShLangAll, true },
{ "Load", /* +samplindex, offset*/ "V4", nullptr, "$&,V,S,V", "FIU,I,I,I", EShLangAll, true },
// RWTexture loads
{ "Load", "V4", nullptr, "!#,V", "FIU,I", EShLangAll, true },
// (RW)Buffer loads
{ "Load", "V4", nullptr, "~*1,V", "FIU,I", EShLangAll, true },
{ "Gather", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
{ "Gather", /* O*/ "V4", nullptr, "%@,S,V,V", "FIU,S,F,I", EShLangAll, true },
{ "CalculateLevelOfDetail", "S", "F", "%@,S,V", "FUI,S,F", EShLangPS, true },
{ "CalculateLevelOfDetailUnclamped", "S", "F", "%@,S,V", "FUI,S,F", EShLangPS, true },
{ "GetSamplePosition", "V2", "F", "$&2,S", "FUI,I", EShLangVSPSGS,true },
//
// UINT Width
// UINT MipLevel, UINT Width, UINT NumberOfLevels
{ "GetDimensions", /* 1D */ "-", "-", "%!~1,>S", "FUI,U", EShLangAll, true },
{ "GetDimensions", /* 1D */ "-", "-", "%!~1,>S", "FUI,F", EShLangAll, true },
{ "GetDimensions", /* 1D */ "-", "-", "%1,S,>S,", "FUI,U,,", EShLangAll, true },
{ "GetDimensions", /* 1D */ "-", "-", "%1,S,>S,", "FUI,U,F,", EShLangAll, true },
// UINT Width, UINT Elements
// UINT MipLevel, UINT Width, UINT Elements, UINT NumberOfLevels
{ "GetDimensions", /* 1DArray */ "-", "-", "@#1,>S,", "FUI,U,", EShLangAll, true },
{ "GetDimensions", /* 1DArray */ "-", "-", "@#1,>S,", "FUI,F,", EShLangAll, true },
{ "GetDimensions", /* 1DArray */ "-", "-", "@1,S,>S,,", "FUI,U,,,", EShLangAll, true },
{ "GetDimensions", /* 1DArray */ "-", "-", "@1,S,>S,,", "FUI,U,F,,", EShLangAll, true },
// UINT Width, UINT Height
// UINT MipLevel, UINT Width, UINT Height, UINT NumberOfLevels
{ "GetDimensions", /* 2D */ "-", "-", "%!2,>S,", "FUI,U,", EShLangAll, true },
{ "GetDimensions", /* 2D */ "-", "-", "%!2,>S,", "FUI,F,", EShLangAll, true },
{ "GetDimensions", /* 2D */ "-", "-", "%2,S,>S,,", "FUI,U,,,", EShLangAll, true },
{ "GetDimensions", /* 2D */ "-", "-", "%2,S,>S,,", "FUI,U,F,,", EShLangAll, true },
// UINT Width, UINT Height, UINT Elements
// UINT MipLevel, UINT Width, UINT Height, UINT Elements, UINT NumberOfLevels
{ "GetDimensions", /* 2DArray */ "-", "-", "@#2,>S,,", "FUI,U,,", EShLangAll, true },
{ "GetDimensions", /* 2DArray */ "-", "-", "@#2,>S,,", "FUI,F,F,F", EShLangAll, true },
{ "GetDimensions", /* 2DArray */ "-", "-", "@2,S,>S,,,", "FUI,U,,,,", EShLangAll, true },
{ "GetDimensions", /* 2DArray */ "-", "-", "@2,S,>S,,,", "FUI,U,F,,,", EShLangAll, true },
// UINT Width, UINT Height, UINT Depth
// UINT MipLevel, UINT Width, UINT Height, UINT Depth, UINT NumberOfLevels
{ "GetDimensions", /* 3D */ "-", "-", "%!3,>S,,", "FUI,U,,", EShLangAll, true },
{ "GetDimensions", /* 3D */ "-", "-", "%!3,>S,,", "FUI,F,,", EShLangAll, true },
{ "GetDimensions", /* 3D */ "-", "-", "%3,S,>S,,,", "FUI,U,,,,", EShLangAll, true },
{ "GetDimensions", /* 3D */ "-", "-", "%3,S,>S,,,", "FUI,U,F,,,", EShLangAll, true },
// UINT Width, UINT Height
// UINT MipLevel, UINT Width, UINT Height, UINT NumberOfLevels
{ "GetDimensions", /* Cube */ "-", "-", "%4,>S,", "FUI,U,", EShLangAll, true },
{ "GetDimensions", /* Cube */ "-", "-", "%4,>S,", "FUI,F,", EShLangAll, true },
{ "GetDimensions", /* Cube */ "-", "-", "%4,S,>S,,", "FUI,U,,,", EShLangAll, true },
{ "GetDimensions", /* Cube */ "-", "-", "%4,S,>S,,", "FUI,U,F,,", EShLangAll, true },
// UINT Width, UINT Height, UINT Elements
// UINT MipLevel, UINT Width, UINT Height, UINT Elements, UINT NumberOfLevels
{ "GetDimensions", /* CubeArray */ "-", "-", "@4,>S,,", "FUI,U,,", EShLangAll, true },
{ "GetDimensions", /* CubeArray */ "-", "-", "@4,>S,,", "FUI,F,,", EShLangAll, true },
{ "GetDimensions", /* CubeArray */ "-", "-", "@4,S,>S,,,", "FUI,U,,,,", EShLangAll, true },
{ "GetDimensions", /* CubeArray */ "-", "-", "@4,S,>S,,,", "FUI,U,F,,,", EShLangAll, true },
// UINT Width, UINT Height, UINT Samples
// UINT Width, UINT Height, UINT Elements, UINT Samples
{ "GetDimensions", /* 2DMS */ "-", "-", "$2,>S,,", "FUI,U,,", EShLangAll, true },
{ "GetDimensions", /* 2DMS */ "-", "-", "$2,>S,,", "FUI,U,,", EShLangAll, true },
{ "GetDimensions", /* 2DMSArray */ "-", "-", "&2,>S,,,", "FUI,U,,,", EShLangAll, true },
{ "GetDimensions", /* 2DMSArray */ "-", "-", "&2,>S,,,", "FUI,U,,,", EShLangAll, true },
// SM5 texture methods
{ "GatherRed", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
{ "GatherRed", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangAll, true },
{ "GatherRed", /* O, status*/ "V4", nullptr, "%@,S,V,,>S", "FIU,S,F,I,U", EShLangAll, true },
{ "GatherRed", /* O-4 */ "V4", nullptr, "%@,S,V,,,,", "FIU,S,F,I,,,", EShLangAll, true },
{ "GatherRed", /* O-4, status */"V4", nullptr, "%@,S,V,,,,,S", "FIU,S,F,I,,,,U", EShLangAll, true },
{ "GatherGreen", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
{ "GatherGreen", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangAll, true },
{ "GatherGreen", /* O, status*/ "V4", nullptr, "%@,S,V,,>S", "FIU,S,F,I,U", EShLangAll, true },
{ "GatherGreen", /* O-4 */ "V4", nullptr, "%@,S,V,,,,", "FIU,S,F,I,,,", EShLangAll, true },
{ "GatherGreen", /* O-4, status */"V4", nullptr, "%@,S,V,,,,,S", "FIU,S,F,I,,,,U", EShLangAll, true },
{ "GatherBlue", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
{ "GatherBlue", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangAll, true },
{ "GatherBlue", /* O, status*/ "V4", nullptr, "%@,S,V,,>S", "FIU,S,F,I,U", EShLangAll, true },
{ "GatherBlue", /* O-4 */ "V4", nullptr, "%@,S,V,,,,", "FIU,S,F,I,,,", EShLangAll, true },
{ "GatherBlue", /* O-4, status */"V4", nullptr, "%@,S,V,,,,,S", "FIU,S,F,I,,,,U", EShLangAll, true },
{ "GatherAlpha", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
{ "GatherAlpha", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangAll, true },
{ "GatherAlpha", /* O, status*/ "V4", nullptr, "%@,S,V,,>S", "FIU,S,F,I,U", EShLangAll, true },
{ "GatherAlpha", /* O-4 */ "V4", nullptr, "%@,S,V,,,,", "FIU,S,F,I,,,", EShLangAll, true },
{ "GatherAlpha", /* O-4, status */"V4", nullptr, "%@,S,V,,,,,S", "FIU,S,F,I,,,,U", EShLangAll, true },
{ "GatherCmp", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
{ "GatherCmp", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
{ "GatherCmp", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
{ "GatherCmp", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
{ "GatherCmp", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,V,S","FIU,s,F,,I,,,,U",EShLangAll, true },
{ "GatherCmpRed", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
{ "GatherCmpRed", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
{ "GatherCmpRed", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
{ "GatherCmpRed", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
{ "GatherCmpRed", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,V,S","FIU,s,F,,I,,,,U",EShLangAll, true },
{ "GatherCmpGreen", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
{ "GatherCmpGreen", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
{ "GatherCmpGreen", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
{ "GatherCmpGreen", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
{ "GatherCmpGreen", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,,,S","FIU,s,F,,I,,,,U",EShLangAll, true },
{ "GatherCmpBlue", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
{ "GatherCmpBlue", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
{ "GatherCmpBlue", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
{ "GatherCmpBlue", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
{ "GatherCmpBlue", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,,,S","FIU,s,F,,I,,,,U",EShLangAll, true },
{ "GatherCmpAlpha", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
{ "GatherCmpAlpha", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
{ "GatherCmpAlpha", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
{ "GatherCmpAlpha", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
{ "GatherCmpAlpha", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,,,S","FIU,s,F,,I,,,,U",EShLangAll, true },
// geometry methods
{ "Append", "-", "-", "-", "-", EShLangGS , true },
{ "RestartStrip", "-", "-", "-", "-", EShLangGS , true },
// Methods for structurebuffers. TODO: wildcard type matching.
{ "Load", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "Load2", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "Load3", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "Load4", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "Store", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "Store2", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "Store3", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "Store4", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "GetDimensions", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "InterlockedAdd", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "InterlockedAnd", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "InterlockedCompareExchange", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "InterlockedCompareStore", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "InterlockedExchange", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "InterlockedMax", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "InterlockedMin", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "InterlockedOr", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "InterlockedXor", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "IncrementCounter", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "DecrementCounter", nullptr, nullptr, "-", "-", EShLangAll, true },
{ "Consume", nullptr, nullptr, "-", "-", EShLangAll, true },
// SM 6.0
{ "WaveIsFirstLane", "S", "B", "-", "-", EShLangPSCS, false},
{ "WaveGetLaneCount", "S", "U", "-", "-", EShLangPSCS, false},
{ "WaveGetLaneIndex", "S", "U", "-", "-", EShLangPSCS, false},
{ "WaveActiveAnyTrue", "S", "B", "S", "B", EShLangPSCS, false},
{ "WaveActiveAllTrue", "S", "B", "S", "B", EShLangPSCS, false},
{ "WaveActiveBallot", "V4", "U", "S", "B", EShLangPSCS, false},
{ "WaveReadLaneAt", nullptr, nullptr, "SV,S", "DFUI,U", EShLangPSCS, false},
{ "WaveReadLaneFirst", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveAllEqual", "S", "B", "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveAllEqualBool", "S", "B", "S", "B", EShLangPSCS, false},
{ "WaveActiveCountBits", "S", "U", "S", "B", EShLangPSCS, false},
{ "WaveActiveSum", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveProduct", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveBitAnd", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveBitOr", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveBitXor", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveMin", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveMax", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WavePrefixSum", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WavePrefixProduct", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WavePrefixCountBits", "S", "U", "S", "B", EShLangPSCS, false},
{ "QuadReadAcrossX", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "QuadReadAcrossY", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "QuadReadAcrossDiagonal", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "QuadReadLaneAt", nullptr, nullptr, "SV,S", "DFUI,U", EShLangPSCS, false},
// Methods for subpass input objects
{ "SubpassLoad", "V4", nullptr, "[", "FIU", EShLangPS, true },
{ "SubpassLoad", "V4", nullptr, "],S", "FIU,I", EShLangPS, true },
// Mark end of list, since we want to avoid a range-based for, as some compilers don't handle it yet.
{ nullptr, nullptr, nullptr, nullptr, nullptr, 0, false },
};
// Create prototypes for the intrinsics. TODO: Avoid ranged based for until all compilers can handle it.
for (int icount = 0; hlslIntrinsics[icount].name; ++icount) {
const auto& intrinsic = hlslIntrinsics[icount];
for (int stage = 0; stage < EShLangCount; ++stage) { // for each stage...
if ((intrinsic.stage & (1<<stage)) == 0) // skip inapplicable stages
continue;
// reference to either the common builtins, or stage specific builtins.
TString& s = (intrinsic.stage == EShLangAll) ? commonBuiltins : stageBuiltins[stage];
for (const char* argOrder = intrinsic.argOrder; !IsEndOfArg(argOrder); ++argOrder) { // for each order...
const bool isTexture = IsTextureType(*argOrder);
const bool isArrayed = IsArrayed(*argOrder);
const bool isMS = IsTextureMS(*argOrder);
const bool isBuffer = IsBuffer(*argOrder);
const bool isImage = IsImage(*argOrder);
const bool mipInCoord = HasMipInCoord(intrinsic.name, isMS, isBuffer, isImage);
const int fixedVecSize = FixedVecSize(argOrder);
const int coordArg = CoordinateArgPos(intrinsic.name, isTexture);
// calculate min and max vector and matrix dimensions
int dim0Min = 1;
int dim0Max = 1;
int dim1Min = 1;
int dim1Max = 1;
FindVectorMatrixBounds(argOrder, fixedVecSize, dim0Min, dim0Max, dim1Min, dim1Max);
for (const char* argType = intrinsic.argType; !IsEndOfArg(argType); ++argType) { // for each type...
for (int dim0 = dim0Min; dim0 <= dim0Max; ++dim0) { // for each dim 0...
for (int dim1 = dim1Min; dim1 <= dim1Max; ++dim1) { // for each dim 1...
const char* retOrder = intrinsic.retOrder ? intrinsic.retOrder : argOrder;
const char* retType = intrinsic.retType ? intrinsic.retType : argType;
if (!IsValid(intrinsic.name, *retOrder, *retType, *argOrder, *argType, dim0, dim1))
continue;
// Reject some forms of sample methods that don't exist.
if (isTexture && IsIllegalSample(intrinsic.name, argOrder, dim0))
continue;
AppendTypeName(s, retOrder, retType, dim0, dim1); // add return type
s.append(" "); // space between type and name
// methods have a prefix. TODO: it would be better as an invalid identifier character,
// but that requires a scanner change.
if (intrinsic.method)
s.append(BUILTIN_PREFIX);
s.append(intrinsic.name); // intrinsic name
s.append("("); // open paren
const char* prevArgOrder = nullptr;
const char* prevArgType = nullptr;
// Append argument types, if any.
for (int arg = 0; ; ++arg) {
const char* nthArgOrder(NthArg(argOrder, arg));
const char* nthArgType(NthArg(argType, arg));
if (nthArgOrder == nullptr || nthArgType == nullptr)
break;
// cube textures use vec3 coordinates
int argDim0 = isTexture && arg > 0 ? std::min(dim0, 3) : dim0;
s.append(arg > 0 ? ", ": ""); // comma separator if needed
const char* orderBegin = nthArgOrder;
nthArgOrder = IoParam(s, nthArgOrder);
// Comma means use the previous argument order and type.
HandleRepeatArg(nthArgOrder, prevArgOrder, orderBegin);
HandleRepeatArg(nthArgType, prevArgType, nthArgType);
// In case the repeated arg has its own I/O marker
nthArgOrder = IoParam(s, nthArgOrder);
// arrayed textures have one extra coordinate dimension, except for
// the CalculateLevelOfDetail family.
if (isArrayed && arg == coordArg && !NoArrayCoord(intrinsic.name))
argDim0++;
// Some texture methods use an addition arg dimension to hold mip
if (arg == coordArg && mipInCoord)
argDim0++;
// For textures, the 1D case isn't a 1-vector, but a scalar.
if (isTexture && argDim0 == 1 && arg > 0 && *nthArgOrder == 'V')
nthArgOrder = "S";
AppendTypeName(s, nthArgOrder, nthArgType, argDim0, dim1); // Add arguments
}
s.append(");\n"); // close paren and trailing semicolon
} // dim 1 loop
} // dim 0 loop
} // arg type loop
// skip over special characters
if (isTexture && isalpha(argOrder[1]))
++argOrder;
if (isdigit(argOrder[1]))
++argOrder;
} // arg order loop
if (intrinsic.stage == EShLangAll) // common builtins are only added once.
break;
}
}
createMatTimesMat(); // handle this case separately, for convenience
// printf("Common:\n%s\n", getCommonString().c_str());
// printf("Frag:\n%s\n", getStageString(EShLangFragment).c_str());
// printf("Vertex:\n%s\n", getStageString(EShLangVertex).c_str());
// printf("Geo:\n%s\n", getStageString(EShLangGeometry).c_str());
// printf("TessCtrl:\n%s\n", getStageString(EShLangTessControl).c_str());
// printf("TessEval:\n%s\n", getStageString(EShLangTessEvaluation).c_str());
// printf("Compute:\n%s\n", getStageString(EShLangCompute).c_str());
}
//
// Add context-dependent built-in functions and variables that are present
// for the given version and profile. All the results are put into just the
// commonBuiltins, because it is called for just a specific stage. So,
// add stage-specific entries to the commonBuiltins, and only if that stage
// was requested.
//
void TBuiltInParseablesHlsl::initialize(const TBuiltInResource& /*resources*/, int /*version*/, EProfile /*profile*/,
const SpvVersion& /*spvVersion*/, EShLanguage /*language*/)
{
}
//
// Finish adding/processing context-independent built-in symbols.
// 1) Programmatically add symbols that could not be added by simple text strings above.
// 2) Map built-in functions to operators, for those that will turn into an operation node
// instead of remaining a function call.
// 3) Tag extension-related symbols added to their base version with their extensions, so
// that if an early version has the extension turned off, there is an error reported on use.
//
void TBuiltInParseablesHlsl::identifyBuiltIns(int /*version*/, EProfile /*profile*/, const SpvVersion& /*spvVersion*/, EShLanguage /*language*/,
TSymbolTable& symbolTable)
{
// symbolTable.relateToOperator("abort", EOpAbort);
symbolTable.relateToOperator("abs", EOpAbs);
symbolTable.relateToOperator("acos", EOpAcos);
symbolTable.relateToOperator("all", EOpAll);
symbolTable.relateToOperator("AllMemoryBarrier", EOpMemoryBarrier);
symbolTable.relateToOperator("AllMemoryBarrierWithGroupSync", EOpAllMemoryBarrierWithGroupSync);
symbolTable.relateToOperator("any", EOpAny);
symbolTable.relateToOperator("asdouble", EOpAsDouble);
symbolTable.relateToOperator("asfloat", EOpIntBitsToFloat);
symbolTable.relateToOperator("asin", EOpAsin);
symbolTable.relateToOperator("asint", EOpFloatBitsToInt);
symbolTable.relateToOperator("asuint", EOpFloatBitsToUint);
symbolTable.relateToOperator("atan", EOpAtan);
symbolTable.relateToOperator("atan2", EOpAtan);
symbolTable.relateToOperator("ceil", EOpCeil);
// symbolTable.relateToOperator("CheckAccessFullyMapped");
symbolTable.relateToOperator("clamp", EOpClamp);
symbolTable.relateToOperator("clip", EOpClip);
symbolTable.relateToOperator("cos", EOpCos);
symbolTable.relateToOperator("cosh", EOpCosh);
symbolTable.relateToOperator("countbits", EOpBitCount);
symbolTable.relateToOperator("cross", EOpCross);
symbolTable.relateToOperator("D3DCOLORtoUBYTE4", EOpD3DCOLORtoUBYTE4);
symbolTable.relateToOperator("ddx", EOpDPdx);
symbolTable.relateToOperator("ddx_coarse", EOpDPdxCoarse);
symbolTable.relateToOperator("ddx_fine", EOpDPdxFine);
symbolTable.relateToOperator("ddy", EOpDPdy);
symbolTable.relateToOperator("ddy_coarse", EOpDPdyCoarse);
symbolTable.relateToOperator("ddy_fine", EOpDPdyFine);
symbolTable.relateToOperator("degrees", EOpDegrees);
symbolTable.relateToOperator("determinant", EOpDeterminant);
symbolTable.relateToOperator("DeviceMemoryBarrier", EOpDeviceMemoryBarrier);
symbolTable.relateToOperator("DeviceMemoryBarrierWithGroupSync", EOpDeviceMemoryBarrierWithGroupSync);
symbolTable.relateToOperator("distance", EOpDistance);
symbolTable.relateToOperator("dot", EOpDot);
symbolTable.relateToOperator("dst", EOpDst);
// symbolTable.relateToOperator("errorf", EOpErrorf);
symbolTable.relateToOperator("EvaluateAttributeAtCentroid", EOpInterpolateAtCentroid);
symbolTable.relateToOperator("EvaluateAttributeAtSample", EOpInterpolateAtSample);
symbolTable.relateToOperator("EvaluateAttributeSnapped", EOpEvaluateAttributeSnapped);
symbolTable.relateToOperator("exp", EOpExp);
symbolTable.relateToOperator("exp2", EOpExp2);
symbolTable.relateToOperator("f16tof32", EOpF16tof32);
symbolTable.relateToOperator("f32tof16", EOpF32tof16);
symbolTable.relateToOperator("faceforward", EOpFaceForward);
symbolTable.relateToOperator("firstbithigh", EOpFindMSB);
symbolTable.relateToOperator("firstbitlow", EOpFindLSB);
symbolTable.relateToOperator("floor", EOpFloor);
symbolTable.relateToOperator("fma", EOpFma);
symbolTable.relateToOperator("fmod", EOpMod);
symbolTable.relateToOperator("frac", EOpFract);
symbolTable.relateToOperator("frexp", EOpFrexp);
symbolTable.relateToOperator("fwidth", EOpFwidth);
// symbolTable.relateToOperator("GetRenderTargetSampleCount");
// symbolTable.relateToOperator("GetRenderTargetSamplePosition");
symbolTable.relateToOperator("GroupMemoryBarrier", EOpWorkgroupMemoryBarrier);
symbolTable.relateToOperator("GroupMemoryBarrierWithGroupSync", EOpWorkgroupMemoryBarrierWithGroupSync);
symbolTable.relateToOperator("InterlockedAdd", EOpInterlockedAdd);
symbolTable.relateToOperator("InterlockedAnd", EOpInterlockedAnd);
symbolTable.relateToOperator("InterlockedCompareExchange", EOpInterlockedCompareExchange);
symbolTable.relateToOperator("InterlockedCompareStore", EOpInterlockedCompareStore);
symbolTable.relateToOperator("InterlockedExchange", EOpInterlockedExchange);
symbolTable.relateToOperator("InterlockedMax", EOpInterlockedMax);
symbolTable.relateToOperator("InterlockedMin", EOpInterlockedMin);
symbolTable.relateToOperator("InterlockedOr", EOpInterlockedOr);
symbolTable.relateToOperator("InterlockedXor", EOpInterlockedXor);
symbolTable.relateToOperator("isfinite", EOpIsFinite);
symbolTable.relateToOperator("isinf", EOpIsInf);
symbolTable.relateToOperator("isnan", EOpIsNan);
symbolTable.relateToOperator("ldexp", EOpLdexp);
symbolTable.relateToOperator("length", EOpLength);
symbolTable.relateToOperator("lerp", EOpMix);
symbolTable.relateToOperator("lit", EOpLit);
symbolTable.relateToOperator("log", EOpLog);
symbolTable.relateToOperator("log10", EOpLog10);
symbolTable.relateToOperator("log2", EOpLog2);
symbolTable.relateToOperator("mad", EOpFma);
symbolTable.relateToOperator("max", EOpMax);
symbolTable.relateToOperator("min", EOpMin);
symbolTable.relateToOperator("modf", EOpModf);
// symbolTable.relateToOperator("msad4", EOpMsad4);
symbolTable.relateToOperator("mul", EOpGenMul);
// symbolTable.relateToOperator("noise", EOpNoise); // TODO: check return type
symbolTable.relateToOperator("normalize", EOpNormalize);
symbolTable.relateToOperator("pow", EOpPow);
symbolTable.relateToOperator("printf", EOpDebugPrintf);
// symbolTable.relateToOperator("Process2DQuadTessFactorsAvg");
// symbolTable.relateToOperator("Process2DQuadTessFactorsMax");
// symbolTable.relateToOperator("Process2DQuadTessFactorsMin");
// symbolTable.relateToOperator("ProcessIsolineTessFactors");
// symbolTable.relateToOperator("ProcessQuadTessFactorsAvg");
// symbolTable.relateToOperator("ProcessQuadTessFactorsMax");
// symbolTable.relateToOperator("ProcessQuadTessFactorsMin");
// symbolTable.relateToOperator("ProcessTriTessFactorsAvg");
// symbolTable.relateToOperator("ProcessTriTessFactorsMax");
// symbolTable.relateToOperator("ProcessTriTessFactorsMin");
symbolTable.relateToOperator("radians", EOpRadians);
symbolTable.relateToOperator("rcp", EOpRcp);
symbolTable.relateToOperator("reflect", EOpReflect);
symbolTable.relateToOperator("refract", EOpRefract);
symbolTable.relateToOperator("reversebits", EOpBitFieldReverse);
symbolTable.relateToOperator("round", EOpRound);
symbolTable.relateToOperator("rsqrt", EOpInverseSqrt);
symbolTable.relateToOperator("saturate", EOpSaturate);
symbolTable.relateToOperator("sign", EOpSign);
symbolTable.relateToOperator("sin", EOpSin);
symbolTable.relateToOperator("sincos", EOpSinCos);
symbolTable.relateToOperator("sinh", EOpSinh);
symbolTable.relateToOperator("smoothstep", EOpSmoothStep);
symbolTable.relateToOperator("sqrt", EOpSqrt);
symbolTable.relateToOperator("step", EOpStep);
symbolTable.relateToOperator("tan", EOpTan);
symbolTable.relateToOperator("tanh", EOpTanh);
symbolTable.relateToOperator("tex1D", EOpTexture);
symbolTable.relateToOperator("tex1Dbias", EOpTextureBias);
symbolTable.relateToOperator("tex1Dgrad", EOpTextureGrad);
symbolTable.relateToOperator("tex1Dlod", EOpTextureLod);
symbolTable.relateToOperator("tex1Dproj", EOpTextureProj);
symbolTable.relateToOperator("tex2D", EOpTexture);
symbolTable.relateToOperator("tex2Dbias", EOpTextureBias);
symbolTable.relateToOperator("tex2Dgrad", EOpTextureGrad);
symbolTable.relateToOperator("tex2Dlod", EOpTextureLod);
symbolTable.relateToOperator("tex2Dproj", EOpTextureProj);
symbolTable.relateToOperator("tex3D", EOpTexture);
symbolTable.relateToOperator("tex3Dbias", EOpTextureBias);
symbolTable.relateToOperator("tex3Dgrad", EOpTextureGrad);
symbolTable.relateToOperator("tex3Dlod", EOpTextureLod);
symbolTable.relateToOperator("tex3Dproj", EOpTextureProj);
symbolTable.relateToOperator("texCUBE", EOpTexture);
symbolTable.relateToOperator("texCUBEbias", EOpTextureBias);
symbolTable.relateToOperator("texCUBEgrad", EOpTextureGrad);
symbolTable.relateToOperator("texCUBElod", EOpTextureLod);
symbolTable.relateToOperator("texCUBEproj", EOpTextureProj);
symbolTable.relateToOperator("transpose", EOpTranspose);
symbolTable.relateToOperator("trunc", EOpTrunc);
// Texture methods
symbolTable.relateToOperator(BUILTIN_PREFIX "Sample", EOpMethodSample);
symbolTable.relateToOperator(BUILTIN_PREFIX "SampleBias", EOpMethodSampleBias);
symbolTable.relateToOperator(BUILTIN_PREFIX "SampleCmp", EOpMethodSampleCmp);
symbolTable.relateToOperator(BUILTIN_PREFIX "SampleCmpLevelZero", EOpMethodSampleCmpLevelZero);
symbolTable.relateToOperator(BUILTIN_PREFIX "SampleGrad", EOpMethodSampleGrad);
symbolTable.relateToOperator(BUILTIN_PREFIX "SampleLevel", EOpMethodSampleLevel);
symbolTable.relateToOperator(BUILTIN_PREFIX "Load", EOpMethodLoad);
symbolTable.relateToOperator(BUILTIN_PREFIX "GetDimensions", EOpMethodGetDimensions);
symbolTable.relateToOperator(BUILTIN_PREFIX "GetSamplePosition", EOpMethodGetSamplePosition);
symbolTable.relateToOperator(BUILTIN_PREFIX "Gather", EOpMethodGather);
symbolTable.relateToOperator(BUILTIN_PREFIX "CalculateLevelOfDetail", EOpMethodCalculateLevelOfDetail);
symbolTable.relateToOperator(BUILTIN_PREFIX "CalculateLevelOfDetailUnclamped", EOpMethodCalculateLevelOfDetailUnclamped);
// Structure buffer methods (excluding associations already made above for texture methods w/ same name)
symbolTable.relateToOperator(BUILTIN_PREFIX "Load2", EOpMethodLoad2);
symbolTable.relateToOperator(BUILTIN_PREFIX "Load3", EOpMethodLoad3);
symbolTable.relateToOperator(BUILTIN_PREFIX "Load4", EOpMethodLoad4);
symbolTable.relateToOperator(BUILTIN_PREFIX "Store", EOpMethodStore);
symbolTable.relateToOperator(BUILTIN_PREFIX "Store2", EOpMethodStore2);
symbolTable.relateToOperator(BUILTIN_PREFIX "Store3", EOpMethodStore3);
symbolTable.relateToOperator(BUILTIN_PREFIX "Store4", EOpMethodStore4);
symbolTable.relateToOperator(BUILTIN_PREFIX "IncrementCounter", EOpMethodIncrementCounter);
symbolTable.relateToOperator(BUILTIN_PREFIX "DecrementCounter", EOpMethodDecrementCounter);
// Append is also a GS method: we don't add it twice
symbolTable.relateToOperator(BUILTIN_PREFIX "Consume", EOpMethodConsume);
symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedAdd", EOpInterlockedAdd);
symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedAnd", EOpInterlockedAnd);
symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedCompareExchange", EOpInterlockedCompareExchange);
symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedCompareStore", EOpInterlockedCompareStore);
symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedExchange", EOpInterlockedExchange);
symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedMax", EOpInterlockedMax);
symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedMin", EOpInterlockedMin);
symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedOr", EOpInterlockedOr);
symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedXor", EOpInterlockedXor);
// SM5 Texture methods
symbolTable.relateToOperator(BUILTIN_PREFIX "GatherRed", EOpMethodGatherRed);
symbolTable.relateToOperator(BUILTIN_PREFIX "GatherGreen", EOpMethodGatherGreen);
symbolTable.relateToOperator(BUILTIN_PREFIX "GatherBlue", EOpMethodGatherBlue);
symbolTable.relateToOperator(BUILTIN_PREFIX "GatherAlpha", EOpMethodGatherAlpha);
symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmp", EOpMethodGatherCmpRed); // alias
symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmpRed", EOpMethodGatherCmpRed);
symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmpGreen", EOpMethodGatherCmpGreen);
symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmpBlue", EOpMethodGatherCmpBlue);
symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmpAlpha", EOpMethodGatherCmpAlpha);
// GS methods
symbolTable.relateToOperator(BUILTIN_PREFIX "Append", EOpMethodAppend);
symbolTable.relateToOperator(BUILTIN_PREFIX "RestartStrip", EOpMethodRestartStrip);
// Wave ops
symbolTable.relateToOperator("WaveIsFirstLane", EOpSubgroupElect);
symbolTable.relateToOperator("WaveGetLaneCount", EOpWaveGetLaneCount);
symbolTable.relateToOperator("WaveGetLaneIndex", EOpWaveGetLaneIndex);
symbolTable.relateToOperator("WaveActiveAnyTrue", EOpSubgroupAny);
symbolTable.relateToOperator("WaveActiveAllTrue", EOpSubgroupAll);
symbolTable.relateToOperator("WaveActiveBallot", EOpSubgroupBallot);
symbolTable.relateToOperator("WaveReadLaneFirst", EOpSubgroupBroadcastFirst);
symbolTable.relateToOperator("WaveReadLaneAt", EOpSubgroupShuffle);
symbolTable.relateToOperator("WaveActiveAllEqual", EOpSubgroupAllEqual);
symbolTable.relateToOperator("WaveActiveAllEqualBool", EOpSubgroupAllEqual);
symbolTable.relateToOperator("WaveActiveCountBits", EOpWaveActiveCountBits);
symbolTable.relateToOperator("WaveActiveSum", EOpSubgroupAdd);
symbolTable.relateToOperator("WaveActiveProduct", EOpSubgroupMul);
symbolTable.relateToOperator("WaveActiveBitAnd", EOpSubgroupAnd);
symbolTable.relateToOperator("WaveActiveBitOr", EOpSubgroupOr);
symbolTable.relateToOperator("WaveActiveBitXor", EOpSubgroupXor);
symbolTable.relateToOperator("WaveActiveMin", EOpSubgroupMin);
symbolTable.relateToOperator("WaveActiveMax", EOpSubgroupMax);
symbolTable.relateToOperator("WavePrefixSum", EOpSubgroupInclusiveAdd);
symbolTable.relateToOperator("WavePrefixProduct", EOpSubgroupInclusiveMul);
symbolTable.relateToOperator("WavePrefixCountBits", EOpWavePrefixCountBits);
symbolTable.relateToOperator("QuadReadAcrossX", EOpSubgroupQuadSwapHorizontal);
symbolTable.relateToOperator("QuadReadAcrossY", EOpSubgroupQuadSwapVertical);
symbolTable.relateToOperator("QuadReadAcrossDiagonal", EOpSubgroupQuadSwapDiagonal);
symbolTable.relateToOperator("QuadReadLaneAt", EOpSubgroupQuadBroadcast);
// Subpass input methods
symbolTable.relateToOperator(BUILTIN_PREFIX "SubpassLoad", EOpSubpassLoad);
symbolTable.relateToOperator(BUILTIN_PREFIX "SubpassLoadMS", EOpSubpassLoadMS);
}
//
// Add context-dependent (resource-specific) built-ins not handled by the above. These
// would be ones that need to be programmatically added because they cannot
// be added by simple text strings. For these, also
// 1) Map built-in functions to operators, for those that will turn into an operation node
// instead of remaining a function call.
// 2) Tag extension-related symbols added to their base version with their extensions, so
// that if an early version has the extension turned off, there is an error reported on use.
//
void TBuiltInParseablesHlsl::identifyBuiltIns(int /*version*/, EProfile /*profile*/, const SpvVersion& /*spvVersion*/, EShLanguage /*language*/,
TSymbolTable& /*symbolTable*/, const TBuiltInResource& /*resources*/)
{
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslOpMap.h | //
// Copyright (C) 2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef HLSLOPMAP_H_
#define HLSLOPMAP_H_
#include "hlslScanContext.h"
namespace glslang {
enum PrecedenceLevel {
PlBad,
PlLogicalOr,
PlLogicalXor,
PlLogicalAnd,
PlBitwiseOr,
PlBitwiseXor,
PlBitwiseAnd,
PlEquality,
PlRelational,
PlShift,
PlAdd,
PlMul
};
class HlslOpMap {
public:
static TOperator assignment(EHlslTokenClass op);
static TOperator binary(EHlslTokenClass op);
static TOperator preUnary(EHlslTokenClass op);
static TOperator postUnary(EHlslTokenClass op);
static PrecedenceLevel precedenceLevel(TOperator);
};
} // end namespace glslang
#endif // HLSLOPMAP_H_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslGrammar.cpp | //
// Copyright (C) 2016-2018 Google, Inc.
// Copyright (C) 2016 LunarG, Inc.
// Copyright (C) 2023 Mobica Limited.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// This is a set of mutually recursive methods implementing the HLSL grammar.
// Generally, each returns
// - through an argument: a type specifically appropriate to which rule it
// recognized
// - through the return value: true/false to indicate whether or not it
// recognized its rule
//
// As much as possible, only grammar recognition should happen in this file,
// with all other work being farmed out to hlslParseHelper.cpp, which in turn
// will build the AST.
//
// The next token, yet to be "accepted" is always sitting in 'token'.
// When a method says it accepts a rule, that means all tokens involved
// in the rule will have been consumed, and none left in 'token'.
//
#include "hlslTokens.h"
#include "hlslGrammar.h"
#include "hlslAttributes.h"
namespace glslang {
// Root entry point to this recursive decent parser.
// Return true if compilation unit was successfully accepted.
bool HlslGrammar::parse()
{
advanceToken();
return acceptCompilationUnit();
}
void HlslGrammar::expected(const char* syntax)
{
parseContext.error(token.loc, "Expected", syntax, "");
}
void HlslGrammar::unimplemented(const char* error)
{
parseContext.error(token.loc, "Unimplemented", error, "");
}
// IDENTIFIER
// THIS
// type that can be used as IDENTIFIER
//
// Only process the next token if it is an identifier.
// Return true if it was an identifier.
bool HlslGrammar::acceptIdentifier(HlslToken& idToken)
{
// IDENTIFIER
if (peekTokenClass(EHTokIdentifier)) {
idToken = token;
advanceToken();
return true;
}
// THIS
// -> maps to the IDENTIFIER spelled with the internal special name for 'this'
if (peekTokenClass(EHTokThis)) {
idToken = token;
advanceToken();
idToken.tokenClass = EHTokIdentifier;
idToken.string = NewPoolTString(intermediate.implicitThisName);
return true;
}
// type that can be used as IDENTIFIER
// Even though "sample", "bool", "float", etc keywords (for types, interpolation modifiers),
// they ARE still accepted as identifiers. This is not a dense space: e.g, "void" is not a
// valid identifier, nor is "linear". This code special cases the known instances of this, so
// e.g, "int sample;" or "float float;" is accepted. Other cases can be added here if needed.
const char* idString = getTypeString(peek());
if (idString == nullptr)
return false;
token.string = NewPoolTString(idString);
token.tokenClass = EHTokIdentifier;
idToken = token;
typeIdentifiers = true;
advanceToken();
return true;
}
// compilationUnit
// : declaration_list EOF
//
bool HlslGrammar::acceptCompilationUnit()
{
if (! acceptDeclarationList(unitNode))
return false;
if (! peekTokenClass(EHTokNone))
return false;
// set root of AST
if (unitNode && !unitNode->getAsAggregate())
unitNode = intermediate.growAggregate(nullptr, unitNode);
intermediate.setTreeRoot(unitNode);
return true;
}
// Recognize the following, but with the extra condition that it can be
// successfully terminated by EOF or '}'.
//
// declaration_list
// : list of declaration_or_semicolon followed by EOF or RIGHT_BRACE
//
// declaration_or_semicolon
// : declaration
// : SEMICOLON
//
bool HlslGrammar::acceptDeclarationList(TIntermNode*& nodeList)
{
do {
// HLSL allows extra semicolons between global declarations
do { } while (acceptTokenClass(EHTokSemicolon));
// EOF or RIGHT_BRACE
if (peekTokenClass(EHTokNone) || peekTokenClass(EHTokRightBrace))
return true;
// declaration
if (! acceptDeclaration(nodeList)) {
expected("declaration");
return false;
}
} while (true);
return true;
}
// sampler_state
// : LEFT_BRACE [sampler_state_assignment ... ] RIGHT_BRACE
//
// sampler_state_assignment
// : sampler_state_identifier EQUAL value SEMICOLON
//
// sampler_state_identifier
// : ADDRESSU
// | ADDRESSV
// | ADDRESSW
// | BORDERCOLOR
// | FILTER
// | MAXANISOTROPY
// | MAXLOD
// | MINLOD
// | MIPLODBIAS
//
bool HlslGrammar::acceptSamplerState()
{
// TODO: this should be genericized to accept a list of valid tokens and
// return token/value pairs. Presently it is specific to texture values.
if (! acceptTokenClass(EHTokLeftBrace))
return true;
parseContext.warn(token.loc, "unimplemented", "immediate sampler state", "");
do {
// read state name
HlslToken state;
if (! acceptIdentifier(state))
break; // end of list
// FXC accepts any case
TString stateName = *state.string;
std::transform(stateName.begin(), stateName.end(), stateName.begin(), ::tolower);
if (! acceptTokenClass(EHTokAssign)) {
expected("assign");
return false;
}
if (stateName == "minlod" || stateName == "maxlod") {
if (! peekTokenClass(EHTokIntConstant)) {
expected("integer");
return false;
}
TIntermTyped* lod = nullptr;
if (! acceptLiteral(lod)) // should never fail, since we just looked for an integer
return false;
} else if (stateName == "maxanisotropy") {
if (! peekTokenClass(EHTokIntConstant)) {
expected("integer");
return false;
}
TIntermTyped* maxAnisotropy = nullptr;
if (! acceptLiteral(maxAnisotropy)) // should never fail, since we just looked for an integer
return false;
} else if (stateName == "filter") {
HlslToken filterMode;
if (! acceptIdentifier(filterMode)) {
expected("filter mode");
return false;
}
} else if (stateName == "addressu" || stateName == "addressv" || stateName == "addressw") {
HlslToken addrMode;
if (! acceptIdentifier(addrMode)) {
expected("texture address mode");
return false;
}
} else if (stateName == "miplodbias") {
TIntermTyped* lodBias = nullptr;
if (! acceptLiteral(lodBias)) {
expected("lod bias");
return false;
}
} else if (stateName == "bordercolor") {
return false;
} else {
expected("texture state");
return false;
}
// SEMICOLON
if (! acceptTokenClass(EHTokSemicolon)) {
expected("semicolon");
return false;
}
} while (true);
if (! acceptTokenClass(EHTokRightBrace))
return false;
return true;
}
// sampler_declaration_dx9
// : SAMPLER identifier EQUAL sampler_type sampler_state
//
bool HlslGrammar::acceptSamplerDeclarationDX9(TType& /*type*/)
{
if (! acceptTokenClass(EHTokSampler))
return false;
// TODO: remove this when DX9 style declarations are implemented.
unimplemented("Direct3D 9 sampler declaration");
// read sampler name
HlslToken name;
if (! acceptIdentifier(name)) {
expected("sampler name");
return false;
}
if (! acceptTokenClass(EHTokAssign)) {
expected("=");
return false;
}
return false;
}
// declaration
// : attributes attributed_declaration
// | NAMESPACE IDENTIFIER LEFT_BRACE declaration_list RIGHT_BRACE
//
// attributed_declaration
// : sampler_declaration_dx9 post_decls SEMICOLON
// | fully_specified_type // for cbuffer/tbuffer
// | fully_specified_type declarator_list SEMICOLON // for non cbuffer/tbuffer
// | fully_specified_type identifier function_parameters post_decls compound_statement // function definition
// | fully_specified_type identifier sampler_state post_decls compound_statement // sampler definition
// | typedef declaration
//
// declarator_list
// : declarator COMMA declarator COMMA declarator... // zero or more declarators
//
// declarator
// : identifier array_specifier post_decls
// | identifier array_specifier post_decls EQUAL assignment_expression
// | identifier function_parameters post_decls // function prototype
//
// Parsing has to go pretty far in to know whether it's a variable, prototype, or
// function definition, so the implementation below doesn't perfectly divide up the grammar
// as above. (The 'identifier' in the first item in init_declarator list is the
// same as 'identifier' for function declarations.)
//
// This can generate more than one subtree, one per initializer or a function body.
// All initializer subtrees are put in their own aggregate node, making one top-level
// node for all the initializers. Each function created is a top-level node to grow
// into the passed-in nodeList.
//
// If 'nodeList' is passed in as non-null, it must be an aggregate to extend for
// each top-level node the declaration creates. Otherwise, if only one top-level
// node in generated here, that is want is returned in nodeList.
//
bool HlslGrammar::acceptDeclaration(TIntermNode*& nodeList)
{
// NAMESPACE IDENTIFIER LEFT_BRACE declaration_list RIGHT_BRACE
if (acceptTokenClass(EHTokNamespace)) {
HlslToken namespaceToken;
if (!acceptIdentifier(namespaceToken)) {
expected("namespace name");
return false;
}
parseContext.pushNamespace(*namespaceToken.string);
if (!acceptTokenClass(EHTokLeftBrace)) {
expected("{");
return false;
}
if (!acceptDeclarationList(nodeList)) {
expected("declaration list");
return false;
}
if (!acceptTokenClass(EHTokRightBrace)) {
expected("}");
return false;
}
parseContext.popNamespace();
return true;
}
bool declarator_list = false; // true when processing comma separation
// attributes
TFunctionDeclarator declarator;
acceptAttributes(declarator.attributes);
// typedef
bool typedefDecl = acceptTokenClass(EHTokTypedef);
TType declaredType;
// DX9 sampler declaration use a different syntax
// DX9 shaders need to run through HLSL compiler (fxc) via a back compat mode, it isn't going to
// be possible to simultaneously compile D3D10+ style shaders and DX9 shaders. If we want to compile DX9
// HLSL shaders, this will have to be a master level switch
// As such, the sampler keyword in D3D10+ turns into an automatic sampler type, and is commonly used
// For that reason, this line is commented out
// if (acceptSamplerDeclarationDX9(declaredType))
// return true;
bool forbidDeclarators = (peekTokenClass(EHTokCBuffer) || peekTokenClass(EHTokTBuffer));
// fully_specified_type
if (! acceptFullySpecifiedType(declaredType, nodeList, declarator.attributes, forbidDeclarators))
return false;
// cbuffer and tbuffer end with the closing '}'.
// No semicolon is included.
if (forbidDeclarators)
return true;
// Check if there are invalid in/out qualifiers
switch (declaredType.getQualifier().storage) {
case EvqIn:
case EvqOut:
case EvqInOut:
parseContext.error(token.loc, "in/out qualifiers are only valid on parameters", token.string->c_str(), "");
break;
default:
break;
}
// declarator_list
// : declarator
// : identifier
HlslToken idToken;
TIntermAggregate* initializers = nullptr;
while (acceptIdentifier(idToken)) {
TString *fullName = idToken.string;
if (parseContext.symbolTable.atGlobalLevel())
parseContext.getFullNamespaceName(fullName);
if (peekTokenClass(EHTokLeftParen)) {
// looks like function parameters
// merge in the attributes into the return type
parseContext.transferTypeAttributes(token.loc, declarator.attributes, declaredType, true);
// Potentially rename shader entry point function. No-op most of the time.
parseContext.renameShaderFunction(fullName);
// function_parameters
declarator.function = new TFunction(fullName, declaredType);
if (!acceptFunctionParameters(*declarator.function)) {
expected("function parameter list");
return false;
}
// post_decls
acceptPostDecls(declarator.function->getWritableType().getQualifier());
// compound_statement (function body definition) or just a prototype?
declarator.loc = token.loc;
if (peekTokenClass(EHTokLeftBrace)) {
if (declarator_list)
parseContext.error(idToken.loc, "function body can't be in a declarator list", "{", "");
if (typedefDecl)
parseContext.error(idToken.loc, "function body can't be in a typedef", "{", "");
return acceptFunctionDefinition(declarator, nodeList, nullptr);
} else {
if (typedefDecl)
parseContext.error(idToken.loc, "function typedefs not implemented", "{", "");
parseContext.handleFunctionDeclarator(declarator.loc, *declarator.function, true);
}
} else {
// A variable declaration.
// merge in the attributes, the first time around, into the shared type
if (! declarator_list)
parseContext.transferTypeAttributes(token.loc, declarator.attributes, declaredType);
// Fix the storage qualifier if it's a global.
if (declaredType.getQualifier().storage == EvqTemporary && parseContext.symbolTable.atGlobalLevel())
declaredType.getQualifier().storage = EvqUniform;
// recognize array_specifier
TArraySizes* arraySizes = nullptr;
acceptArraySpecifier(arraySizes);
// We can handle multiple variables per type declaration, so
// the number of types can expand when arrayness is different.
TType variableType;
variableType.shallowCopy(declaredType);
// In the most general case, arrayness is potentially coming both from the
// declared type and from the variable: "int[] a[];" or just one or the other.
// Merge it all to the variableType, so all arrayness is part of the variableType.
variableType.transferArraySizes(arraySizes);
variableType.copyArrayInnerSizes(declaredType.getArraySizes());
// samplers accept immediate sampler state
if (variableType.getBasicType() == EbtSampler) {
if (! acceptSamplerState())
return false;
}
// post_decls
acceptPostDecls(variableType.getQualifier());
// EQUAL assignment_expression
TIntermTyped* expressionNode = nullptr;
if (acceptTokenClass(EHTokAssign)) {
if (typedefDecl)
parseContext.error(idToken.loc, "can't have an initializer", "typedef", "");
if (! acceptAssignmentExpression(expressionNode)) {
expected("initializer");
return false;
}
}
// TODO: things scoped within an annotation need their own name space;
// TODO: non-constant strings are not yet handled.
if (!(variableType.getBasicType() == EbtString && !variableType.getQualifier().isConstant()) &&
parseContext.getAnnotationNestingLevel() == 0) {
if (typedefDecl)
parseContext.declareTypedef(idToken.loc, *fullName, variableType);
else if (variableType.getBasicType() == EbtBlock) {
if (expressionNode)
parseContext.error(idToken.loc, "buffer aliasing not yet supported", "block initializer", "");
parseContext.declareBlock(idToken.loc, variableType, fullName);
parseContext.declareStructBufferCounter(idToken.loc, variableType, *fullName);
} else {
if (variableType.getQualifier().storage == EvqUniform && ! variableType.containsOpaque()) {
// this isn't really an individual variable, but a member of the $Global buffer
parseContext.growGlobalUniformBlock(idToken.loc, variableType, *fullName);
} else {
// Declare the variable and add any initializer code to the AST.
// The top-level node is always made into an aggregate, as that's
// historically how the AST has been.
initializers = intermediate.growAggregate(initializers,
parseContext.declareVariable(idToken.loc, *fullName, variableType, expressionNode),
idToken.loc);
}
}
}
}
// COMMA
if (acceptTokenClass(EHTokComma))
declarator_list = true;
}
// The top-level initializer node is a sequence.
if (initializers != nullptr)
initializers->setOperator(EOpSequence);
// if we have a locally scoped static, it needs a globally scoped initializer
if (declaredType.getQualifier().storage == EvqGlobal && !parseContext.symbolTable.atGlobalLevel()) {
unitNode = intermediate.growAggregate(unitNode, initializers, idToken.loc);
} else {
// Add the initializers' aggregate to the nodeList we were handed.
if (nodeList)
nodeList = intermediate.growAggregate(nodeList, initializers);
else
nodeList = initializers;
}
// SEMICOLON
if (! acceptTokenClass(EHTokSemicolon)) {
// This may have been a false detection of what appeared to be a declaration, but
// was actually an assignment such as "float = 4", where "float" is an identifier.
// We put the token back to let further parsing happen for cases where that may
// happen. This errors on the side of caution, and mostly triggers the error.
if (peek() == EHTokAssign || peek() == EHTokLeftBracket || peek() == EHTokDot || peek() == EHTokComma)
recedeToken();
else
expected(";");
return false;
}
return true;
}
// control_declaration
// : fully_specified_type identifier EQUAL expression
//
bool HlslGrammar::acceptControlDeclaration(TIntermNode*& node)
{
node = nullptr;
TAttributes attributes;
// fully_specified_type
TType type;
if (! acceptFullySpecifiedType(type, attributes))
return false;
if (attributes.size() > 0)
parseContext.warn(token.loc, "attributes don't apply to control declaration", "", "");
// filter out type casts
if (peekTokenClass(EHTokLeftParen)) {
recedeToken();
return false;
}
// identifier
HlslToken idToken;
if (! acceptIdentifier(idToken)) {
expected("identifier");
return false;
}
// EQUAL
TIntermTyped* expressionNode = nullptr;
if (! acceptTokenClass(EHTokAssign)) {
expected("=");
return false;
}
// expression
if (! acceptExpression(expressionNode)) {
expected("initializer");
return false;
}
node = parseContext.declareVariable(idToken.loc, *idToken.string, type, expressionNode);
return true;
}
// fully_specified_type
// : type_specifier
// | type_qualifier type_specifier
// | type_specifier type_qualifier
//
bool HlslGrammar::acceptFullySpecifiedType(TType& type, const TAttributes& attributes)
{
TIntermNode* nodeList = nullptr;
return acceptFullySpecifiedType(type, nodeList, attributes);
}
bool HlslGrammar::acceptFullySpecifiedType(TType& type, TIntermNode*& nodeList, const TAttributes& attributes, bool forbidDeclarators)
{
// type_qualifier
TQualifier qualifier;
qualifier.clear();
if (! acceptPreQualifier(qualifier))
return false;
TSourceLoc loc = token.loc;
// type_specifier
if (! acceptType(type, nodeList)) {
// If this is not a type, we may have inadvertently gone down a wrong path
// by parsing "sample", which can be treated like either an identifier or a
// qualifier. Back it out, if we did.
if (qualifier.sample)
recedeToken();
return false;
}
// type_qualifier
if (! acceptPostQualifier(qualifier))
return false;
if (type.getBasicType() == EbtBlock) {
// the type was a block, which set some parts of the qualifier
parseContext.mergeQualifiers(type.getQualifier(), qualifier);
// merge in the attributes
parseContext.transferTypeAttributes(token.loc, attributes, type);
// further, it can create an anonymous instance of the block
// (cbuffer and tbuffer don't consume the next identifier, and
// should set forbidDeclarators)
if (forbidDeclarators || peek() != EHTokIdentifier)
parseContext.declareBlock(loc, type);
} else {
// Some qualifiers are set when parsing the type. Merge those with
// whatever comes from acceptPreQualifier and acceptPostQualifier.
assert(qualifier.layoutFormat == ElfNone);
qualifier.layoutFormat = type.getQualifier().layoutFormat;
qualifier.precision = type.getQualifier().precision;
if (type.getQualifier().storage == EvqOut ||
type.getQualifier().storage == EvqBuffer) {
qualifier.storage = type.getQualifier().storage;
qualifier.readonly = type.getQualifier().readonly;
}
if (type.isBuiltIn())
qualifier.builtIn = type.getQualifier().builtIn;
type.getQualifier() = qualifier;
}
return true;
}
// type_qualifier
// : qualifier qualifier ...
//
// Zero or more of these, so this can't return false.
//
bool HlslGrammar::acceptPreQualifier(TQualifier& qualifier)
{
do {
switch (peek()) {
case EHTokStatic:
qualifier.storage = EvqGlobal;
break;
case EHTokExtern:
// TODO: no meaning in glslang?
break;
case EHTokShared:
// TODO: hint
break;
case EHTokGroupShared:
qualifier.storage = EvqShared;
break;
case EHTokUniform:
qualifier.storage = EvqUniform;
break;
case EHTokConst:
qualifier.storage = EvqConst;
break;
case EHTokVolatile:
qualifier.volatil = true;
break;
case EHTokLinear:
qualifier.smooth = true;
break;
case EHTokCentroid:
qualifier.centroid = true;
break;
case EHTokNointerpolation:
qualifier.flat = true;
break;
case EHTokNoperspective:
qualifier.nopersp = true;
break;
case EHTokSample:
qualifier.sample = true;
break;
case EHTokRowMajor:
qualifier.layoutMatrix = ElmColumnMajor;
break;
case EHTokColumnMajor:
qualifier.layoutMatrix = ElmRowMajor;
break;
case EHTokPrecise:
qualifier.noContraction = true;
break;
case EHTokIn:
if (qualifier.storage != EvqUniform) {
qualifier.storage = (qualifier.storage == EvqOut) ? EvqInOut : EvqIn;
}
break;
case EHTokOut:
qualifier.storage = (qualifier.storage == EvqIn) ? EvqInOut : EvqOut;
break;
case EHTokInOut:
qualifier.storage = EvqInOut;
break;
case EHTokLayout:
if (! acceptLayoutQualifierList(qualifier))
return false;
continue;
case EHTokGloballyCoherent:
qualifier.coherent = true;
break;
case EHTokInline:
// TODO: map this to SPIR-V function control
break;
// GS geometries: these are specified on stage input variables, and are an error (not verified here)
// for output variables.
case EHTokPoint:
qualifier.storage = EvqIn;
if (!parseContext.handleInputGeometry(token.loc, ElgPoints))
return false;
break;
case EHTokLine:
qualifier.storage = EvqIn;
if (!parseContext.handleInputGeometry(token.loc, ElgLines))
return false;
break;
case EHTokTriangle:
qualifier.storage = EvqIn;
if (!parseContext.handleInputGeometry(token.loc, ElgTriangles))
return false;
break;
case EHTokLineAdj:
qualifier.storage = EvqIn;
if (!parseContext.handleInputGeometry(token.loc, ElgLinesAdjacency))
return false;
break;
case EHTokTriangleAdj:
qualifier.storage = EvqIn;
if (!parseContext.handleInputGeometry(token.loc, ElgTrianglesAdjacency))
return false;
break;
default:
return true;
}
advanceToken();
} while (true);
}
// type_qualifier
// : qualifier qualifier ...
//
// Zero or more of these, so this can't return false.
//
bool HlslGrammar::acceptPostQualifier(TQualifier& qualifier)
{
do {
switch (peek()) {
case EHTokConst:
qualifier.storage = EvqConst;
break;
default:
return true;
}
advanceToken();
} while (true);
}
// layout_qualifier_list
// : LAYOUT LEFT_PAREN layout_qualifier COMMA layout_qualifier ... RIGHT_PAREN
//
// layout_qualifier
// : identifier
// | identifier EQUAL expression
//
// Zero or more of these, so this can't return false.
//
bool HlslGrammar::acceptLayoutQualifierList(TQualifier& qualifier)
{
if (! acceptTokenClass(EHTokLayout))
return false;
// LEFT_PAREN
if (! acceptTokenClass(EHTokLeftParen))
return false;
do {
// identifier
HlslToken idToken;
if (! acceptIdentifier(idToken))
break;
// EQUAL expression
if (acceptTokenClass(EHTokAssign)) {
TIntermTyped* expr;
if (! acceptConditionalExpression(expr)) {
expected("expression");
return false;
}
parseContext.setLayoutQualifier(idToken.loc, qualifier, *idToken.string, expr);
} else
parseContext.setLayoutQualifier(idToken.loc, qualifier, *idToken.string);
// COMMA
if (! acceptTokenClass(EHTokComma))
break;
} while (true);
// RIGHT_PAREN
if (! acceptTokenClass(EHTokRightParen)) {
expected(")");
return false;
}
return true;
}
// template_type
// : FLOAT
// | DOUBLE
// | INT
// | DWORD
// | UINT
// | BOOL
//
bool HlslGrammar::acceptTemplateVecMatBasicType(TBasicType& basicType,
TPrecisionQualifier& precision)
{
precision = EpqNone;
switch (peek()) {
case EHTokFloat:
basicType = EbtFloat;
break;
case EHTokDouble:
basicType = EbtDouble;
break;
case EHTokInt:
case EHTokDword:
basicType = EbtInt;
break;
case EHTokUint:
basicType = EbtUint;
break;
case EHTokBool:
basicType = EbtBool;
break;
case EHTokHalf:
basicType = parseContext.hlslEnable16BitTypes() ? EbtFloat16 : EbtFloat;
break;
case EHTokMin16float:
case EHTokMin10float:
basicType = parseContext.hlslEnable16BitTypes() ? EbtFloat16 : EbtFloat;
precision = EpqMedium;
break;
case EHTokMin16int:
case EHTokMin12int:
basicType = parseContext.hlslEnable16BitTypes() ? EbtInt16 : EbtInt;
precision = EpqMedium;
break;
case EHTokMin16uint:
basicType = parseContext.hlslEnable16BitTypes() ? EbtUint16 : EbtUint;
precision = EpqMedium;
break;
default:
return false;
}
advanceToken();
return true;
}
// vector_template_type
// : VECTOR
// | VECTOR LEFT_ANGLE template_type COMMA integer_literal RIGHT_ANGLE
//
bool HlslGrammar::acceptVectorTemplateType(TType& type)
{
if (! acceptTokenClass(EHTokVector))
return false;
if (! acceptTokenClass(EHTokLeftAngle)) {
// in HLSL, 'vector' alone means float4.
new(&type) TType(EbtFloat, EvqTemporary, 4);
return true;
}
TBasicType basicType;
TPrecisionQualifier precision;
if (! acceptTemplateVecMatBasicType(basicType, precision)) {
expected("scalar type");
return false;
}
// COMMA
if (! acceptTokenClass(EHTokComma)) {
expected(",");
return false;
}
// integer
if (! peekTokenClass(EHTokIntConstant)) {
expected("literal integer");
return false;
}
TIntermTyped* vecSize;
if (! acceptLiteral(vecSize))
return false;
const int vecSizeI = vecSize->getAsConstantUnion()->getConstArray()[0].getIConst();
new(&type) TType(basicType, EvqTemporary, precision, vecSizeI);
if (vecSizeI == 1)
type.makeVector();
if (!acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
return true;
}
// matrix_template_type
// : MATRIX
// | MATRIX LEFT_ANGLE template_type COMMA integer_literal COMMA integer_literal RIGHT_ANGLE
//
bool HlslGrammar::acceptMatrixTemplateType(TType& type)
{
if (! acceptTokenClass(EHTokMatrix))
return false;
if (! acceptTokenClass(EHTokLeftAngle)) {
// in HLSL, 'matrix' alone means float4x4.
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 4);
return true;
}
TBasicType basicType;
TPrecisionQualifier precision;
if (! acceptTemplateVecMatBasicType(basicType, precision)) {
expected("scalar type");
return false;
}
// COMMA
if (! acceptTokenClass(EHTokComma)) {
expected(",");
return false;
}
// integer rows
if (! peekTokenClass(EHTokIntConstant)) {
expected("literal integer");
return false;
}
TIntermTyped* rows;
if (! acceptLiteral(rows))
return false;
// COMMA
if (! acceptTokenClass(EHTokComma)) {
expected(",");
return false;
}
// integer cols
if (! peekTokenClass(EHTokIntConstant)) {
expected("literal integer");
return false;
}
TIntermTyped* cols;
if (! acceptLiteral(cols))
return false;
new(&type) TType(basicType, EvqTemporary, precision, 0,
rows->getAsConstantUnion()->getConstArray()[0].getIConst(),
cols->getAsConstantUnion()->getConstArray()[0].getIConst());
if (!acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
return true;
}
// layout_geometry
// : LINESTREAM
// | POINTSTREAM
// | TRIANGLESTREAM
//
bool HlslGrammar::acceptOutputPrimitiveGeometry(TLayoutGeometry& geometry)
{
// read geometry type
const EHlslTokenClass geometryType = peek();
switch (geometryType) {
case EHTokPointStream: geometry = ElgPoints; break;
case EHTokLineStream: geometry = ElgLineStrip; break;
case EHTokTriangleStream: geometry = ElgTriangleStrip; break;
default:
return false; // not a layout geometry
}
advanceToken(); // consume the layout keyword
return true;
}
// tessellation_decl_type
// : INPUTPATCH
// | OUTPUTPATCH
//
bool HlslGrammar::acceptTessellationDeclType(TBuiltInVariable& patchType)
{
// read geometry type
const EHlslTokenClass tessType = peek();
switch (tessType) {
case EHTokInputPatch: patchType = EbvInputPatch; break;
case EHTokOutputPatch: patchType = EbvOutputPatch; break;
default:
return false; // not a tessellation decl
}
advanceToken(); // consume the keyword
return true;
}
// tessellation_patch_template_type
// : tessellation_decl_type LEFT_ANGLE type comma integer_literal RIGHT_ANGLE
//
bool HlslGrammar::acceptTessellationPatchTemplateType(TType& type)
{
TBuiltInVariable patchType;
if (! acceptTessellationDeclType(patchType))
return false;
if (! acceptTokenClass(EHTokLeftAngle))
return false;
if (! acceptType(type)) {
expected("tessellation patch type");
return false;
}
if (! acceptTokenClass(EHTokComma))
return false;
// integer size
if (! peekTokenClass(EHTokIntConstant)) {
expected("literal integer");
return false;
}
TIntermTyped* size;
if (! acceptLiteral(size))
return false;
TArraySizes* arraySizes = new TArraySizes;
arraySizes->addInnerSize(size->getAsConstantUnion()->getConstArray()[0].getIConst());
type.transferArraySizes(arraySizes);
type.getQualifier().builtIn = patchType;
if (! acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
return true;
}
// stream_out_template_type
// : output_primitive_geometry_type LEFT_ANGLE type RIGHT_ANGLE
//
bool HlslGrammar::acceptStreamOutTemplateType(TType& type, TLayoutGeometry& geometry)
{
geometry = ElgNone;
if (! acceptOutputPrimitiveGeometry(geometry))
return false;
if (! acceptTokenClass(EHTokLeftAngle))
return false;
if (! acceptType(type)) {
expected("stream output type");
return false;
}
type.getQualifier().storage = EvqOut;
type.getQualifier().builtIn = EbvGsOutputStream;
if (! acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
return true;
}
// annotations
// : LEFT_ANGLE declaration SEMI_COLON ... declaration SEMICOLON RIGHT_ANGLE
//
bool HlslGrammar::acceptAnnotations(TQualifier&)
{
if (! acceptTokenClass(EHTokLeftAngle))
return false;
// note that we are nesting a name space
parseContext.nestAnnotations();
// declaration SEMI_COLON ... declaration SEMICOLON RIGHT_ANGLE
do {
// eat any extra SEMI_COLON; don't know if the grammar calls for this or not
while (acceptTokenClass(EHTokSemicolon))
;
if (acceptTokenClass(EHTokRightAngle))
break;
// declaration
TIntermNode* node = nullptr;
if (! acceptDeclaration(node)) {
expected("declaration in annotation");
return false;
}
} while (true);
parseContext.unnestAnnotations();
return true;
}
// subpass input type
// : SUBPASSINPUT
// | SUBPASSINPUT VECTOR LEFT_ANGLE template_type RIGHT_ANGLE
// | SUBPASSINPUTMS
// | SUBPASSINPUTMS VECTOR LEFT_ANGLE template_type RIGHT_ANGLE
bool HlslGrammar::acceptSubpassInputType(TType& type)
{
// read subpass type
const EHlslTokenClass subpassInputType = peek();
bool multisample;
switch (subpassInputType) {
case EHTokSubpassInput: multisample = false; break;
case EHTokSubpassInputMS: multisample = true; break;
default:
return false; // not a subpass input declaration
}
advanceToken(); // consume the sampler type keyword
TType subpassType(EbtFloat, EvqUniform, 4); // default type is float4
if (acceptTokenClass(EHTokLeftAngle)) {
if (! acceptType(subpassType)) {
expected("scalar or vector type");
return false;
}
const TBasicType basicRetType = subpassType.getBasicType() ;
switch (basicRetType) {
case EbtFloat:
case EbtUint:
case EbtInt:
case EbtStruct:
break;
default:
unimplemented("basic type in subpass input");
return false;
}
if (! acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
}
const TBasicType subpassBasicType = subpassType.isStruct() ? (*subpassType.getStruct())[0].type->getBasicType()
: subpassType.getBasicType();
TSampler sampler;
sampler.setSubpass(subpassBasicType, multisample);
// Remember the declared return type. Function returns false on error.
if (!parseContext.setTextureReturnType(sampler, subpassType, token.loc))
return false;
type.shallowCopy(TType(sampler, EvqUniform));
return true;
}
// sampler_type for DX9 compatibility
// : SAMPLER
// | SAMPLER1D
// | SAMPLER2D
// | SAMPLER3D
// | SAMPLERCUBE
bool HlslGrammar::acceptSamplerTypeDX9(TType &type)
{
// read sampler type
const EHlslTokenClass samplerType = peek();
TSamplerDim dim = EsdNone;
TType txType(EbtFloat, EvqUniform, 4); // default type is float4
bool isShadow = false;
switch (samplerType)
{
case EHTokSampler: dim = Esd2D; break;
case EHTokSampler1d: dim = Esd1D; break;
case EHTokSampler2d: dim = Esd2D; break;
case EHTokSampler3d: dim = Esd3D; break;
case EHTokSamplerCube: dim = EsdCube; break;
default:
return false; // not a dx9 sampler declaration
}
advanceToken(); // consume the sampler type keyword
TArraySizes *arraySizes = nullptr; // TODO: array
TSampler sampler;
sampler.set(txType.getBasicType(), dim, false, isShadow, false);
if (!parseContext.setTextureReturnType(sampler, txType, token.loc))
return false;
type.shallowCopy(TType(sampler, EvqUniform, arraySizes));
type.getQualifier().layoutFormat = ElfNone;
return true;
}
// sampler_type
// : SAMPLER
// | SAMPLER1D
// | SAMPLER2D
// | SAMPLER3D
// | SAMPLERCUBE
// | SAMPLERSTATE
// | SAMPLERCOMPARISONSTATE
bool HlslGrammar::acceptSamplerType(TType& type)
{
// read sampler type
const EHlslTokenClass samplerType = peek();
// TODO: for DX9
// TSamplerDim dim = EsdNone;
bool isShadow = false;
switch (samplerType) {
case EHTokSampler: break;
case EHTokSampler1d: /*dim = Esd1D*/; break;
case EHTokSampler2d: /*dim = Esd2D*/; break;
case EHTokSampler3d: /*dim = Esd3D*/; break;
case EHTokSamplerCube: /*dim = EsdCube*/; break;
case EHTokSamplerState: break;
case EHTokSamplerComparisonState: isShadow = true; break;
default:
return false; // not a sampler declaration
}
advanceToken(); // consume the sampler type keyword
TArraySizes* arraySizes = nullptr; // TODO: array
TSampler sampler;
sampler.setPureSampler(isShadow);
type.shallowCopy(TType(sampler, EvqUniform, arraySizes));
return true;
}
// texture_type
// | BUFFER
// | TEXTURE1D
// | TEXTURE1DARRAY
// | TEXTURE2D
// | TEXTURE2DARRAY
// | TEXTURE3D
// | TEXTURECUBE
// | TEXTURECUBEARRAY
// | TEXTURE2DMS
// | TEXTURE2DMSARRAY
// | RWBUFFER
// | RWTEXTURE1D
// | RWTEXTURE1DARRAY
// | RWTEXTURE2D
// | RWTEXTURE2DARRAY
// | RWTEXTURE3D
bool HlslGrammar::acceptTextureType(TType& type)
{
const EHlslTokenClass textureType = peek();
TSamplerDim dim = EsdNone;
bool array = false;
bool ms = false;
bool image = false;
bool combined = true;
switch (textureType) {
case EHTokBuffer: dim = EsdBuffer; combined = false; break;
case EHTokTexture1d: dim = Esd1D; break;
case EHTokTexture1darray: dim = Esd1D; array = true; break;
case EHTokTexture2d: dim = Esd2D; break;
case EHTokTexture2darray: dim = Esd2D; array = true; break;
case EHTokTexture3d: dim = Esd3D; break;
case EHTokTextureCube: dim = EsdCube; break;
case EHTokTextureCubearray: dim = EsdCube; array = true; break;
case EHTokTexture2DMS: dim = Esd2D; ms = true; break;
case EHTokTexture2DMSarray: dim = Esd2D; array = true; ms = true; break;
case EHTokRWBuffer: dim = EsdBuffer; image=true; break;
case EHTokRWTexture1d: dim = Esd1D; array=false; image=true; break;
case EHTokRWTexture1darray: dim = Esd1D; array=true; image=true; break;
case EHTokRWTexture2d: dim = Esd2D; array=false; image=true; break;
case EHTokRWTexture2darray: dim = Esd2D; array=true; image=true; break;
case EHTokRWTexture3d: dim = Esd3D; array=false; image=true; break;
default:
return false; // not a texture declaration
}
advanceToken(); // consume the texture object keyword
TType txType(EbtFloat, EvqUniform, 4); // default type is float4
TIntermTyped* msCount = nullptr;
// texture type: required for multisample types and RWBuffer/RWTextures!
if (acceptTokenClass(EHTokLeftAngle)) {
if (! acceptType(txType)) {
expected("scalar or vector type");
return false;
}
const TBasicType basicRetType = txType.getBasicType() ;
switch (basicRetType) {
case EbtFloat:
case EbtUint:
case EbtInt:
case EbtStruct:
break;
default:
unimplemented("basic type in texture");
return false;
}
// Buffers can handle small mats if they fit in 4 components
if (dim == EsdBuffer && txType.isMatrix()) {
if ((txType.getMatrixCols() * txType.getMatrixRows()) > 4) {
expected("components < 4 in matrix buffer type");
return false;
}
// TODO: except we don't handle it yet...
unimplemented("matrix type in buffer");
return false;
}
if (!txType.isScalar() && !txType.isVector() && !txType.isStruct()) {
expected("scalar, vector, or struct type");
return false;
}
if (ms && acceptTokenClass(EHTokComma)) {
// read sample count for multisample types, if given
if (! peekTokenClass(EHTokIntConstant)) {
expected("multisample count");
return false;
}
if (! acceptLiteral(msCount)) // should never fail, since we just found an integer
return false;
}
if (! acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
} else if (ms) {
expected("texture type for multisample");
return false;
} else if (image) {
expected("type for RWTexture/RWBuffer");
return false;
}
TArraySizes* arraySizes = nullptr;
const bool shadow = false; // declared on the sampler
TSampler sampler;
TLayoutFormat format = ElfNone;
// Buffer, RWBuffer and RWTexture (images) require a TLayoutFormat. We handle only a limit set.
if (image || dim == EsdBuffer)
format = parseContext.getLayoutFromTxType(token.loc, txType);
const TBasicType txBasicType = txType.isStruct() ? (*txType.getStruct())[0].type->getBasicType()
: txType.getBasicType();
// Non-image Buffers are combined
if (dim == EsdBuffer && !image) {
sampler.set(txType.getBasicType(), dim, array);
} else {
// DX10 textures are separated. TODO: DX9.
if (image) {
sampler.setImage(txBasicType, dim, array, shadow, ms);
} else {
sampler.setTexture(txBasicType, dim, array, shadow, ms);
}
}
// Remember the declared return type. Function returns false on error.
if (!parseContext.setTextureReturnType(sampler, txType, token.loc))
return false;
// Force uncombined, if necessary
if (!combined)
sampler.combined = false;
type.shallowCopy(TType(sampler, EvqUniform, arraySizes));
type.getQualifier().layoutFormat = format;
return true;
}
// If token is for a type, update 'type' with the type information,
// and return true and advance.
// Otherwise, return false, and don't advance
bool HlslGrammar::acceptType(TType& type)
{
TIntermNode* nodeList = nullptr;
return acceptType(type, nodeList);
}
bool HlslGrammar::acceptType(TType& type, TIntermNode*& nodeList)
{
// Basic types for min* types, use native halfs if the option allows them.
bool enable16BitTypes = parseContext.hlslEnable16BitTypes();
const TBasicType min16float_bt = enable16BitTypes ? EbtFloat16 : EbtFloat;
const TBasicType min10float_bt = enable16BitTypes ? EbtFloat16 : EbtFloat;
const TBasicType half_bt = enable16BitTypes ? EbtFloat16 : EbtFloat;
const TBasicType min16int_bt = enable16BitTypes ? EbtInt16 : EbtInt;
const TBasicType min12int_bt = enable16BitTypes ? EbtInt16 : EbtInt;
const TBasicType min16uint_bt = enable16BitTypes ? EbtUint16 : EbtUint;
// Some types might have turned into identifiers. Take the hit for checking
// when this has happened.
if (typeIdentifiers) {
const char* identifierString = getTypeString(peek());
if (identifierString != nullptr) {
TString name = identifierString;
// if it's an identifier, it's not a type
if (parseContext.symbolTable.find(name) != nullptr)
return false;
}
}
bool isUnorm = false;
bool isSnorm = false;
// Accept snorm and unorm. Presently, this is ignored, save for an error check below.
switch (peek()) {
case EHTokUnorm:
isUnorm = true;
advanceToken(); // eat the token
break;
case EHTokSNorm:
isSnorm = true;
advanceToken(); // eat the token
break;
default:
break;
}
switch (peek()) {
case EHTokVector:
return acceptVectorTemplateType(type);
break;
case EHTokMatrix:
return acceptMatrixTemplateType(type);
break;
case EHTokPointStream: // fall through
case EHTokLineStream: // ...
case EHTokTriangleStream: // ...
{
TLayoutGeometry geometry;
if (! acceptStreamOutTemplateType(type, geometry))
return false;
if (! parseContext.handleOutputGeometry(token.loc, geometry))
return false;
return true;
}
case EHTokInputPatch: // fall through
case EHTokOutputPatch: // ...
{
if (! acceptTessellationPatchTemplateType(type))
return false;
return true;
}
case EHTokSampler: // fall through
case EHTokSampler1d: // ...
case EHTokSampler2d: // ...
case EHTokSampler3d: // ...
case EHTokSamplerCube: // ...
if (parseContext.hlslDX9Compatible())
return acceptSamplerTypeDX9(type);
else
return acceptSamplerType(type);
break;
case EHTokSamplerState: // fall through
case EHTokSamplerComparisonState: // ...
return acceptSamplerType(type);
break;
case EHTokSubpassInput: // fall through
case EHTokSubpassInputMS: // ...
return acceptSubpassInputType(type);
break;
case EHTokBuffer: // fall through
case EHTokTexture1d: // ...
case EHTokTexture1darray: // ...
case EHTokTexture2d: // ...
case EHTokTexture2darray: // ...
case EHTokTexture3d: // ...
case EHTokTextureCube: // ...
case EHTokTextureCubearray: // ...
case EHTokTexture2DMS: // ...
case EHTokTexture2DMSarray: // ...
case EHTokRWTexture1d: // ...
case EHTokRWTexture1darray: // ...
case EHTokRWTexture2d: // ...
case EHTokRWTexture2darray: // ...
case EHTokRWTexture3d: // ...
case EHTokRWBuffer: // ...
return acceptTextureType(type);
break;
case EHTokAppendStructuredBuffer:
case EHTokByteAddressBuffer:
case EHTokConsumeStructuredBuffer:
case EHTokRWByteAddressBuffer:
case EHTokRWStructuredBuffer:
case EHTokStructuredBuffer:
return acceptStructBufferType(type);
break;
case EHTokTextureBuffer:
return acceptTextureBufferType(type);
break;
case EHTokConstantBuffer:
return acceptConstantBufferType(type);
case EHTokClass:
case EHTokStruct:
case EHTokCBuffer:
case EHTokTBuffer:
return acceptStruct(type, nodeList);
case EHTokIdentifier:
// An identifier could be for a user-defined type.
// Note we cache the symbol table lookup, to save for a later rule
// when this is not a type.
if (parseContext.lookupUserType(*token.string, type) != nullptr) {
advanceToken();
return true;
} else
return false;
case EHTokVoid:
new(&type) TType(EbtVoid);
break;
case EHTokString:
new(&type) TType(EbtString);
break;
case EHTokFloat:
new(&type) TType(EbtFloat);
break;
case EHTokFloat1:
new(&type) TType(EbtFloat);
type.makeVector();
break;
case EHTokFloat2:
new(&type) TType(EbtFloat, EvqTemporary, 2);
break;
case EHTokFloat3:
new(&type) TType(EbtFloat, EvqTemporary, 3);
break;
case EHTokFloat4:
new(&type) TType(EbtFloat, EvqTemporary, 4);
break;
case EHTokDouble:
new(&type) TType(EbtDouble);
break;
case EHTokDouble1:
new(&type) TType(EbtDouble);
type.makeVector();
break;
case EHTokDouble2:
new(&type) TType(EbtDouble, EvqTemporary, 2);
break;
case EHTokDouble3:
new(&type) TType(EbtDouble, EvqTemporary, 3);
break;
case EHTokDouble4:
new(&type) TType(EbtDouble, EvqTemporary, 4);
break;
case EHTokInt:
case EHTokDword:
new(&type) TType(EbtInt);
break;
case EHTokInt1:
new(&type) TType(EbtInt);
type.makeVector();
break;
case EHTokInt2:
new(&type) TType(EbtInt, EvqTemporary, 2);
break;
case EHTokInt3:
new(&type) TType(EbtInt, EvqTemporary, 3);
break;
case EHTokInt4:
new(&type) TType(EbtInt, EvqTemporary, 4);
break;
case EHTokUint:
new(&type) TType(EbtUint);
break;
case EHTokUint1:
new(&type) TType(EbtUint);
type.makeVector();
break;
case EHTokUint2:
new(&type) TType(EbtUint, EvqTemporary, 2);
break;
case EHTokUint3:
new(&type) TType(EbtUint, EvqTemporary, 3);
break;
case EHTokUint4:
new(&type) TType(EbtUint, EvqTemporary, 4);
break;
case EHTokUint64:
new(&type) TType(EbtUint64);
break;
case EHTokBool:
new(&type) TType(EbtBool);
break;
case EHTokBool1:
new(&type) TType(EbtBool);
type.makeVector();
break;
case EHTokBool2:
new(&type) TType(EbtBool, EvqTemporary, 2);
break;
case EHTokBool3:
new(&type) TType(EbtBool, EvqTemporary, 3);
break;
case EHTokBool4:
new(&type) TType(EbtBool, EvqTemporary, 4);
break;
case EHTokHalf:
new(&type) TType(half_bt, EvqTemporary);
break;
case EHTokHalf1:
new(&type) TType(half_bt, EvqTemporary);
type.makeVector();
break;
case EHTokHalf2:
new(&type) TType(half_bt, EvqTemporary, 2);
break;
case EHTokHalf3:
new(&type) TType(half_bt, EvqTemporary, 3);
break;
case EHTokHalf4:
new(&type) TType(half_bt, EvqTemporary, 4);
break;
case EHTokMin16float:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin16float1:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin16float2:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin16float3:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin16float4:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokMin10float:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin10float1:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin10float2:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin10float3:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin10float4:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokMin16int:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin16int1:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin16int2:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin16int3:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin16int4:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokMin12int:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin12int1:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin12int2:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin12int3:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin12int4:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokMin16uint:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium);
break;
case EHTokMin16uint1:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium);
type.makeVector();
break;
case EHTokMin16uint2:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 2);
break;
case EHTokMin16uint3:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 3);
break;
case EHTokMin16uint4:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 4);
break;
case EHTokInt1x1:
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 1);
break;
case EHTokInt1x2:
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 2);
break;
case EHTokInt1x3:
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 3);
break;
case EHTokInt1x4:
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 4);
break;
case EHTokInt2x1:
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 1);
break;
case EHTokInt2x2:
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 2);
break;
case EHTokInt2x3:
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 3);
break;
case EHTokInt2x4:
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 4);
break;
case EHTokInt3x1:
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 1);
break;
case EHTokInt3x2:
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 2);
break;
case EHTokInt3x3:
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 3);
break;
case EHTokInt3x4:
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 4);
break;
case EHTokInt4x1:
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 1);
break;
case EHTokInt4x2:
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 2);
break;
case EHTokInt4x3:
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 3);
break;
case EHTokInt4x4:
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 4);
break;
case EHTokUint1x1:
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 1);
break;
case EHTokUint1x2:
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 2);
break;
case EHTokUint1x3:
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 3);
break;
case EHTokUint1x4:
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 4);
break;
case EHTokUint2x1:
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 1);
break;
case EHTokUint2x2:
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 2);
break;
case EHTokUint2x3:
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 3);
break;
case EHTokUint2x4:
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 4);
break;
case EHTokUint3x1:
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 1);
break;
case EHTokUint3x2:
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 2);
break;
case EHTokUint3x3:
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 3);
break;
case EHTokUint3x4:
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 4);
break;
case EHTokUint4x1:
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 1);
break;
case EHTokUint4x2:
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 2);
break;
case EHTokUint4x3:
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 3);
break;
case EHTokUint4x4:
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 4);
break;
case EHTokBool1x1:
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 1);
break;
case EHTokBool1x2:
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 2);
break;
case EHTokBool1x3:
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 3);
break;
case EHTokBool1x4:
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 4);
break;
case EHTokBool2x1:
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 1);
break;
case EHTokBool2x2:
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 2);
break;
case EHTokBool2x3:
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 3);
break;
case EHTokBool2x4:
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 4);
break;
case EHTokBool3x1:
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 1);
break;
case EHTokBool3x2:
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 2);
break;
case EHTokBool3x3:
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 3);
break;
case EHTokBool3x4:
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 4);
break;
case EHTokBool4x1:
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 1);
break;
case EHTokBool4x2:
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 2);
break;
case EHTokBool4x3:
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 3);
break;
case EHTokBool4x4:
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 4);
break;
case EHTokFloat1x1:
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 1);
break;
case EHTokFloat1x2:
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 2);
break;
case EHTokFloat1x3:
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 3);
break;
case EHTokFloat1x4:
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 4);
break;
case EHTokFloat2x1:
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 1);
break;
case EHTokFloat2x2:
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 2);
break;
case EHTokFloat2x3:
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 3);
break;
case EHTokFloat2x4:
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 4);
break;
case EHTokFloat3x1:
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 1);
break;
case EHTokFloat3x2:
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 2);
break;
case EHTokFloat3x3:
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 3);
break;
case EHTokFloat3x4:
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 4);
break;
case EHTokFloat4x1:
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 1);
break;
case EHTokFloat4x2:
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 2);
break;
case EHTokFloat4x3:
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 3);
break;
case EHTokFloat4x4:
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 4);
break;
case EHTokHalf1x1:
new(&type) TType(half_bt, EvqTemporary, 0, 1, 1);
break;
case EHTokHalf1x2:
new(&type) TType(half_bt, EvqTemporary, 0, 1, 2);
break;
case EHTokHalf1x3:
new(&type) TType(half_bt, EvqTemporary, 0, 1, 3);
break;
case EHTokHalf1x4:
new(&type) TType(half_bt, EvqTemporary, 0, 1, 4);
break;
case EHTokHalf2x1:
new(&type) TType(half_bt, EvqTemporary, 0, 2, 1);
break;
case EHTokHalf2x2:
new(&type) TType(half_bt, EvqTemporary, 0, 2, 2);
break;
case EHTokHalf2x3:
new(&type) TType(half_bt, EvqTemporary, 0, 2, 3);
break;
case EHTokHalf2x4:
new(&type) TType(half_bt, EvqTemporary, 0, 2, 4);
break;
case EHTokHalf3x1:
new(&type) TType(half_bt, EvqTemporary, 0, 3, 1);
break;
case EHTokHalf3x2:
new(&type) TType(half_bt, EvqTemporary, 0, 3, 2);
break;
case EHTokHalf3x3:
new(&type) TType(half_bt, EvqTemporary, 0, 3, 3);
break;
case EHTokHalf3x4:
new(&type) TType(half_bt, EvqTemporary, 0, 3, 4);
break;
case EHTokHalf4x1:
new(&type) TType(half_bt, EvqTemporary, 0, 4, 1);
break;
case EHTokHalf4x2:
new(&type) TType(half_bt, EvqTemporary, 0, 4, 2);
break;
case EHTokHalf4x3:
new(&type) TType(half_bt, EvqTemporary, 0, 4, 3);
break;
case EHTokHalf4x4:
new(&type) TType(half_bt, EvqTemporary, 0, 4, 4);
break;
case EHTokDouble1x1:
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 1);
break;
case EHTokDouble1x2:
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 2);
break;
case EHTokDouble1x3:
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 3);
break;
case EHTokDouble1x4:
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 4);
break;
case EHTokDouble2x1:
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 1);
break;
case EHTokDouble2x2:
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 2);
break;
case EHTokDouble2x3:
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 3);
break;
case EHTokDouble2x4:
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 4);
break;
case EHTokDouble3x1:
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 1);
break;
case EHTokDouble3x2:
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 2);
break;
case EHTokDouble3x3:
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 3);
break;
case EHTokDouble3x4:
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 4);
break;
case EHTokDouble4x1:
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 1);
break;
case EHTokDouble4x2:
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 2);
break;
case EHTokDouble4x3:
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 3);
break;
case EHTokDouble4x4:
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 4);
break;
case EHTokMin16float1x1:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 1, 1);
break;
case EHTokMin16float1x2:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 1, 2);
break;
case EHTokMin16float1x3:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 1, 3);
break;
case EHTokMin16float1x4:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 1, 4);
break;
case EHTokMin16float2x1:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 2, 1);
break;
case EHTokMin16float2x2:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 2, 2);
break;
case EHTokMin16float2x3:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 2, 3);
break;
case EHTokMin16float2x4:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 2, 4);
break;
case EHTokMin16float3x1:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 3, 1);
break;
case EHTokMin16float3x2:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 3, 2);
break;
case EHTokMin16float3x3:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 3, 3);
break;
case EHTokMin16float3x4:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 3, 4);
break;
case EHTokMin16float4x1:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 4, 1);
break;
case EHTokMin16float4x2:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 4, 2);
break;
case EHTokMin16float4x3:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 4, 3);
break;
case EHTokMin16float4x4:
new(&type) TType(min16float_bt, EvqTemporary, EpqMedium, 0, 4, 4);
break;
case EHTokMin10float1x1:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 1, 1);
break;
case EHTokMin10float1x2:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 1, 2);
break;
case EHTokMin10float1x3:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 1, 3);
break;
case EHTokMin10float1x4:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 1, 4);
break;
case EHTokMin10float2x1:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 2, 1);
break;
case EHTokMin10float2x2:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 2, 2);
break;
case EHTokMin10float2x3:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 2, 3);
break;
case EHTokMin10float2x4:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 2, 4);
break;
case EHTokMin10float3x1:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 3, 1);
break;
case EHTokMin10float3x2:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 3, 2);
break;
case EHTokMin10float3x3:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 3, 3);
break;
case EHTokMin10float3x4:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 3, 4);
break;
case EHTokMin10float4x1:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 4, 1);
break;
case EHTokMin10float4x2:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 4, 2);
break;
case EHTokMin10float4x3:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 4, 3);
break;
case EHTokMin10float4x4:
new(&type) TType(min10float_bt, EvqTemporary, EpqMedium, 0, 4, 4);
break;
case EHTokMin16int1x1:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 1, 1);
break;
case EHTokMin16int1x2:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 1, 2);
break;
case EHTokMin16int1x3:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 1, 3);
break;
case EHTokMin16int1x4:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 1, 4);
break;
case EHTokMin16int2x1:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 2, 1);
break;
case EHTokMin16int2x2:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 2, 2);
break;
case EHTokMin16int2x3:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 2, 3);
break;
case EHTokMin16int2x4:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 2, 4);
break;
case EHTokMin16int3x1:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 3, 1);
break;
case EHTokMin16int3x2:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 3, 2);
break;
case EHTokMin16int3x3:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 3, 3);
break;
case EHTokMin16int3x4:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 3, 4);
break;
case EHTokMin16int4x1:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 4, 1);
break;
case EHTokMin16int4x2:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 4, 2);
break;
case EHTokMin16int4x3:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 4, 3);
break;
case EHTokMin16int4x4:
new(&type) TType(min16int_bt, EvqTemporary, EpqMedium, 0, 4, 4);
break;
case EHTokMin12int1x1:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 1, 1);
break;
case EHTokMin12int1x2:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 1, 2);
break;
case EHTokMin12int1x3:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 1, 3);
break;
case EHTokMin12int1x4:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 1, 4);
break;
case EHTokMin12int2x1:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 2, 1);
break;
case EHTokMin12int2x2:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 2, 2);
break;
case EHTokMin12int2x3:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 2, 3);
break;
case EHTokMin12int2x4:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 2, 4);
break;
case EHTokMin12int3x1:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 3, 1);
break;
case EHTokMin12int3x2:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 3, 2);
break;
case EHTokMin12int3x3:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 3, 3);
break;
case EHTokMin12int3x4:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 3, 4);
break;
case EHTokMin12int4x1:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 4, 1);
break;
case EHTokMin12int4x2:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 4, 2);
break;
case EHTokMin12int4x3:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 4, 3);
break;
case EHTokMin12int4x4:
new(&type) TType(min12int_bt, EvqTemporary, EpqMedium, 0, 4, 4);
break;
case EHTokMin16uint1x1:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 1, 1);
break;
case EHTokMin16uint1x2:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 1, 2);
break;
case EHTokMin16uint1x3:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 1, 3);
break;
case EHTokMin16uint1x4:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 1, 4);
break;
case EHTokMin16uint2x1:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 2, 1);
break;
case EHTokMin16uint2x2:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 2, 2);
break;
case EHTokMin16uint2x3:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 2, 3);
break;
case EHTokMin16uint2x4:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 2, 4);
break;
case EHTokMin16uint3x1:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 3, 1);
break;
case EHTokMin16uint3x2:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 3, 2);
break;
case EHTokMin16uint3x3:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 3, 3);
break;
case EHTokMin16uint3x4:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 3, 4);
break;
case EHTokMin16uint4x1:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 4, 1);
break;
case EHTokMin16uint4x2:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 4, 2);
break;
case EHTokMin16uint4x3:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 4, 3);
break;
case EHTokMin16uint4x4:
new(&type) TType(min16uint_bt, EvqTemporary, EpqMedium, 0, 4, 4);
break;
default:
return false;
}
advanceToken();
if ((isUnorm || isSnorm) && !type.isFloatingDomain()) {
parseContext.error(token.loc, "unorm and snorm only valid in floating point domain", "", "");
return false;
}
return true;
}
// struct
// : struct_type IDENTIFIER post_decls LEFT_BRACE struct_declaration_list RIGHT_BRACE
// | struct_type post_decls LEFT_BRACE struct_declaration_list RIGHT_BRACE
// | struct_type IDENTIFIER // use of previously declared struct type
//
// struct_type
// : STRUCT
// | CLASS
// | CBUFFER
// | TBUFFER
//
bool HlslGrammar::acceptStruct(TType& type, TIntermNode*& nodeList)
{
// This storage qualifier will tell us whether it's an AST
// block type or just a generic structure type.
TStorageQualifier storageQualifier = EvqTemporary;
bool readonly = false;
if (acceptTokenClass(EHTokCBuffer)) {
// CBUFFER
storageQualifier = EvqUniform;
} else if (acceptTokenClass(EHTokTBuffer)) {
// TBUFFER
storageQualifier = EvqBuffer;
readonly = true;
} else if (! acceptTokenClass(EHTokClass) && ! acceptTokenClass(EHTokStruct)) {
// Neither CLASS nor STRUCT
return false;
}
// Now known to be one of CBUFFER, TBUFFER, CLASS, or STRUCT
// IDENTIFIER. It might also be a keyword which can double as an identifier.
// For example: 'cbuffer ConstantBuffer' or 'struct ConstantBuffer' is legal.
// 'cbuffer int' is also legal, and 'struct int' appears rejected only because
// it attempts to redefine the 'int' type.
const char* idString = getTypeString(peek());
TString structName = "";
if (peekTokenClass(EHTokIdentifier) || idString != nullptr) {
if (idString != nullptr)
structName = *idString;
else
structName = *token.string;
advanceToken();
}
// post_decls
TQualifier postDeclQualifier;
postDeclQualifier.clear();
bool postDeclsFound = acceptPostDecls(postDeclQualifier);
// LEFT_BRACE, or
// struct_type IDENTIFIER
if (! acceptTokenClass(EHTokLeftBrace)) {
if (structName.size() > 0 && !postDeclsFound && parseContext.lookupUserType(structName, type) != nullptr) {
// struct_type IDENTIFIER
return true;
} else {
expected("{");
return false;
}
}
// struct_declaration_list
TTypeList* typeList;
// Save each member function so they can be processed after we have a fully formed 'this'.
TVector<TFunctionDeclarator> functionDeclarators;
parseContext.pushNamespace(structName);
bool acceptedList = acceptStructDeclarationList(typeList, nodeList, functionDeclarators);
parseContext.popNamespace();
if (! acceptedList) {
expected("struct member declarations");
return false;
}
// RIGHT_BRACE
if (! acceptTokenClass(EHTokRightBrace)) {
expected("}");
return false;
}
// create the user-defined type
if (storageQualifier == EvqTemporary)
new(&type) TType(typeList, structName);
else {
postDeclQualifier.storage = storageQualifier;
postDeclQualifier.readonly = readonly;
new(&type) TType(typeList, structName, postDeclQualifier); // sets EbtBlock
}
parseContext.declareStruct(token.loc, structName, type);
// For member functions: now that we know the type of 'this', go back and
// - add their implicit argument with 'this' (not to the mangling, just the argument list)
// - parse the functions, their tokens were saved for deferred parsing (now)
for (int b = 0; b < (int)functionDeclarators.size(); ++b) {
// update signature
if (functionDeclarators[b].function->hasImplicitThis())
functionDeclarators[b].function->addThisParameter(type, intermediate.implicitThisName);
}
// All member functions get parsed inside the class/struct namespace and with the
// class/struct members in a symbol-table level.
parseContext.pushNamespace(structName);
parseContext.pushThisScope(type, functionDeclarators);
bool deferredSuccess = true;
for (int b = 0; b < (int)functionDeclarators.size() && deferredSuccess; ++b) {
// parse body
pushTokenStream(functionDeclarators[b].body);
if (! acceptFunctionBody(functionDeclarators[b], nodeList))
deferredSuccess = false;
popTokenStream();
}
parseContext.popThisScope();
parseContext.popNamespace();
return deferredSuccess;
}
// constantbuffer
// : CONSTANTBUFFER LEFT_ANGLE type RIGHT_ANGLE
bool HlslGrammar::acceptConstantBufferType(TType& type)
{
if (! acceptTokenClass(EHTokConstantBuffer))
return false;
if (! acceptTokenClass(EHTokLeftAngle)) {
expected("left angle bracket");
return false;
}
TType templateType;
if (! acceptType(templateType)) {
expected("type");
return false;
}
if (! acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
TQualifier postDeclQualifier;
postDeclQualifier.clear();
postDeclQualifier.storage = EvqUniform;
if (templateType.isStruct()) {
// Make a block from the type parsed as the template argument
TTypeList* typeList = templateType.getWritableStruct();
new(&type) TType(typeList, "", postDeclQualifier); // sets EbtBlock
type.getQualifier().storage = EvqUniform;
return true;
} else {
parseContext.error(token.loc, "non-structure type in ConstantBuffer", "", "");
return false;
}
}
// texture_buffer
// : TEXTUREBUFFER LEFT_ANGLE type RIGHT_ANGLE
bool HlslGrammar::acceptTextureBufferType(TType& type)
{
if (! acceptTokenClass(EHTokTextureBuffer))
return false;
if (! acceptTokenClass(EHTokLeftAngle)) {
expected("left angle bracket");
return false;
}
TType templateType;
if (! acceptType(templateType)) {
expected("type");
return false;
}
if (! acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
templateType.getQualifier().storage = EvqBuffer;
templateType.getQualifier().readonly = true;
TType blockType(templateType.getWritableStruct(), "", templateType.getQualifier());
blockType.getQualifier().storage = EvqBuffer;
blockType.getQualifier().readonly = true;
type.shallowCopy(blockType);
return true;
}
// struct_buffer
// : APPENDSTRUCTUREDBUFFER
// | BYTEADDRESSBUFFER
// | CONSUMESTRUCTUREDBUFFER
// | RWBYTEADDRESSBUFFER
// | RWSTRUCTUREDBUFFER
// | STRUCTUREDBUFFER
bool HlslGrammar::acceptStructBufferType(TType& type)
{
const EHlslTokenClass structBuffType = peek();
// TODO: globallycoherent
bool hasTemplateType = true;
bool readonly = false;
TStorageQualifier storage = EvqBuffer;
TBuiltInVariable builtinType = EbvNone;
switch (structBuffType) {
case EHTokAppendStructuredBuffer:
builtinType = EbvAppendConsume;
break;
case EHTokByteAddressBuffer:
hasTemplateType = false;
readonly = true;
builtinType = EbvByteAddressBuffer;
break;
case EHTokConsumeStructuredBuffer:
builtinType = EbvAppendConsume;
break;
case EHTokRWByteAddressBuffer:
hasTemplateType = false;
builtinType = EbvRWByteAddressBuffer;
break;
case EHTokRWStructuredBuffer:
builtinType = EbvRWStructuredBuffer;
break;
case EHTokStructuredBuffer:
builtinType = EbvStructuredBuffer;
readonly = true;
break;
default:
return false; // not a structure buffer type
}
advanceToken(); // consume the structure keyword
// type on which this StructedBuffer is templatized. E.g, StructedBuffer<MyStruct> ==> MyStruct
TType* templateType = new TType;
if (hasTemplateType) {
if (! acceptTokenClass(EHTokLeftAngle)) {
expected("left angle bracket");
return false;
}
if (! acceptType(*templateType)) {
expected("type");
return false;
}
if (! acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
} else {
// byte address buffers have no explicit type.
TType uintType(EbtUint, storage);
templateType->shallowCopy(uintType);
}
// Create an unsized array out of that type.
// TODO: does this work if it's already an array type?
TArraySizes* unsizedArray = new TArraySizes;
unsizedArray->addInnerSize(UnsizedArraySize);
templateType->transferArraySizes(unsizedArray);
templateType->getQualifier().storage = storage;
// field name is canonical for all structbuffers
templateType->setFieldName("@data");
TTypeList* blockStruct = new TTypeList;
TTypeLoc member = { templateType, token.loc };
blockStruct->push_back(member);
// This is the type of the buffer block (SSBO)
TType blockType(blockStruct, "", templateType->getQualifier());
blockType.getQualifier().storage = storage;
blockType.getQualifier().readonly = readonly;
blockType.getQualifier().builtIn = builtinType;
// We may have created an equivalent type before, in which case we should use its
// deep structure.
parseContext.shareStructBufferType(blockType);
type.shallowCopy(blockType);
return true;
}
// struct_declaration_list
// : struct_declaration SEMI_COLON struct_declaration SEMI_COLON ...
//
// struct_declaration
// : attributes fully_specified_type struct_declarator COMMA struct_declarator ...
// | attributes fully_specified_type IDENTIFIER function_parameters post_decls compound_statement // member-function definition
//
// struct_declarator
// : IDENTIFIER post_decls
// | IDENTIFIER array_specifier post_decls
// | IDENTIFIER function_parameters post_decls // member-function prototype
//
bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList, TIntermNode*& nodeList,
TVector<TFunctionDeclarator>& declarators)
{
typeList = new TTypeList();
HlslToken idToken;
do {
// success on seeing the RIGHT_BRACE coming up
if (peekTokenClass(EHTokRightBrace))
break;
// struct_declaration
// attributes
TAttributes attributes;
acceptAttributes(attributes);
bool declarator_list = false;
// fully_specified_type
TType memberType;
if (! acceptFullySpecifiedType(memberType, nodeList, attributes)) {
expected("member type");
return false;
}
// merge in the attributes
parseContext.transferTypeAttributes(token.loc, attributes, memberType);
// struct_declarator COMMA struct_declarator ...
bool functionDefinitionAccepted = false;
do {
if (! acceptIdentifier(idToken)) {
expected("member name");
return false;
}
if (peekTokenClass(EHTokLeftParen)) {
// function_parameters
if (!declarator_list) {
declarators.resize(declarators.size() + 1);
// request a token stream for deferred processing
functionDefinitionAccepted = acceptMemberFunctionDefinition(nodeList, memberType, *idToken.string,
declarators.back());
if (functionDefinitionAccepted)
break;
}
expected("member-function definition");
return false;
} else {
// add it to the list of members
TTypeLoc member = { new TType(EbtVoid), token.loc };
member.type->shallowCopy(memberType);
member.type->setFieldName(*idToken.string);
typeList->push_back(member);
// array_specifier
TArraySizes* arraySizes = nullptr;
acceptArraySpecifier(arraySizes);
if (arraySizes)
typeList->back().type->transferArraySizes(arraySizes);
acceptPostDecls(member.type->getQualifier());
// EQUAL assignment_expression
if (acceptTokenClass(EHTokAssign)) {
parseContext.warn(idToken.loc, "struct-member initializers ignored", "typedef", "");
TIntermTyped* expressionNode = nullptr;
if (! acceptAssignmentExpression(expressionNode)) {
expected("initializer");
return false;
}
}
}
// success on seeing the SEMICOLON coming up
if (peekTokenClass(EHTokSemicolon))
break;
// COMMA
if (acceptTokenClass(EHTokComma))
declarator_list = true;
else {
expected(",");
return false;
}
} while (true);
// SEMI_COLON
if (! functionDefinitionAccepted && ! acceptTokenClass(EHTokSemicolon)) {
expected(";");
return false;
}
} while (true);
return true;
}
// member_function_definition
// | function_parameters post_decls compound_statement
//
// Expects type to have EvqGlobal for a static member and
// EvqTemporary for non-static member.
bool HlslGrammar::acceptMemberFunctionDefinition(TIntermNode*& nodeList, const TType& type, TString& memberName,
TFunctionDeclarator& declarator)
{
bool accepted = false;
TString* functionName = &memberName;
parseContext.getFullNamespaceName(functionName);
declarator.function = new TFunction(functionName, type);
if (type.getQualifier().storage == EvqTemporary)
declarator.function->setImplicitThis();
else
declarator.function->setIllegalImplicitThis();
// function_parameters
if (acceptFunctionParameters(*declarator.function)) {
// post_decls
acceptPostDecls(declarator.function->getWritableType().getQualifier());
// compound_statement (function body definition)
if (peekTokenClass(EHTokLeftBrace)) {
declarator.loc = token.loc;
declarator.body = new TVector<HlslToken>;
accepted = acceptFunctionDefinition(declarator, nodeList, declarator.body);
}
} else
expected("function parameter list");
return accepted;
}
// function_parameters
// : LEFT_PAREN parameter_declaration COMMA parameter_declaration ... RIGHT_PAREN
// | LEFT_PAREN VOID RIGHT_PAREN
//
bool HlslGrammar::acceptFunctionParameters(TFunction& function)
{
parseContext.beginParameterParsing(function);
// LEFT_PAREN
if (! acceptTokenClass(EHTokLeftParen))
return false;
// VOID RIGHT_PAREN
if (! acceptTokenClass(EHTokVoid)) {
do {
// parameter_declaration
if (! acceptParameterDeclaration(function))
break;
// COMMA
if (! acceptTokenClass(EHTokComma))
break;
} while (true);
}
// RIGHT_PAREN
if (! acceptTokenClass(EHTokRightParen)) {
expected(")");
return false;
}
return true;
}
// default_parameter_declaration
// : EQUAL conditional_expression
// : EQUAL initializer
bool HlslGrammar::acceptDefaultParameterDeclaration(const TType& type, TIntermTyped*& node)
{
node = nullptr;
// Valid not to have a default_parameter_declaration
if (!acceptTokenClass(EHTokAssign))
return true;
if (!acceptConditionalExpression(node)) {
if (!acceptInitializer(node))
return false;
// For initializer lists, we have to const-fold into a constructor for the type, so build
// that.
TFunction* constructor = parseContext.makeConstructorCall(token.loc, type);
if (constructor == nullptr) // cannot construct
return false;
TIntermTyped* arguments = nullptr;
for (int i = 0; i < int(node->getAsAggregate()->getSequence().size()); i++)
parseContext.handleFunctionArgument(constructor, arguments, node->getAsAggregate()->getSequence()[i]->getAsTyped());
node = parseContext.handleFunctionCall(token.loc, constructor, node);
}
if (node == nullptr)
return false;
// If this is simply a constant, we can use it directly.
if (node->getAsConstantUnion())
return true;
// Otherwise, it has to be const-foldable.
TIntermTyped* origNode = node;
node = intermediate.fold(node->getAsAggregate());
if (node != nullptr && origNode != node)
return true;
parseContext.error(token.loc, "invalid default parameter value", "", "");
return false;
}
// parameter_declaration
// : attributes attributed_declaration
//
// attributed_declaration
// : fully_specified_type post_decls [ = default_parameter_declaration ]
// | fully_specified_type identifier array_specifier post_decls [ = default_parameter_declaration ]
//
bool HlslGrammar::acceptParameterDeclaration(TFunction& function)
{
// attributes
TAttributes attributes;
acceptAttributes(attributes);
// fully_specified_type
TType* type = new TType;
if (! acceptFullySpecifiedType(*type, attributes))
return false;
// merge in the attributes
parseContext.transferTypeAttributes(token.loc, attributes, *type);
// identifier
HlslToken idToken;
acceptIdentifier(idToken);
// array_specifier
TArraySizes* arraySizes = nullptr;
acceptArraySpecifier(arraySizes);
if (arraySizes) {
if (arraySizes->hasUnsized()) {
parseContext.error(token.loc, "function parameter requires array size", "[]", "");
return false;
}
type->transferArraySizes(arraySizes);
}
// post_decls
acceptPostDecls(type->getQualifier());
TIntermTyped* defaultValue;
if (!acceptDefaultParameterDeclaration(*type, defaultValue))
return false;
parseContext.paramFix(*type);
// If any prior parameters have default values, all the parameters after that must as well.
if (defaultValue == nullptr && function.getDefaultParamCount() > 0) {
parseContext.error(idToken.loc, "invalid parameter after default value parameters", idToken.string->c_str(), "");
return false;
}
TParameter param = { idToken.string, type, defaultValue };
function.addParameter(param);
return true;
}
// Do the work to create the function definition in addition to
// parsing the body (compound_statement).
//
// If 'deferredTokens' are passed in, just get the token stream,
// don't process.
//
bool HlslGrammar::acceptFunctionDefinition(TFunctionDeclarator& declarator, TIntermNode*& nodeList,
TVector<HlslToken>* deferredTokens)
{
parseContext.handleFunctionDeclarator(declarator.loc, *declarator.function, false /* not prototype */);
if (deferredTokens)
return captureBlockTokens(*deferredTokens);
else
return acceptFunctionBody(declarator, nodeList);
}
bool HlslGrammar::acceptFunctionBody(TFunctionDeclarator& declarator, TIntermNode*& nodeList)
{
// we might get back an entry-point
TIntermNode* entryPointNode = nullptr;
// This does a pushScope()
TIntermNode* functionNode = parseContext.handleFunctionDefinition(declarator.loc, *declarator.function,
declarator.attributes, entryPointNode);
// compound_statement
TIntermNode* functionBody = nullptr;
if (! acceptCompoundStatement(functionBody))
return false;
// this does a popScope()
parseContext.handleFunctionBody(declarator.loc, *declarator.function, functionBody, functionNode);
// Hook up the 1 or 2 function definitions.
nodeList = intermediate.growAggregate(nodeList, functionNode);
nodeList = intermediate.growAggregate(nodeList, entryPointNode);
return true;
}
// Accept an expression with parenthesis around it, where
// the parenthesis ARE NOT expression parenthesis, but the
// syntactically required ones like in "if ( expression )".
//
// Also accepts a declaration expression; "if (int a = expression)".
//
// Note this one is not set up to be speculative; as it gives
// errors if not found.
//
bool HlslGrammar::acceptParenExpression(TIntermTyped*& expression)
{
expression = nullptr;
// LEFT_PAREN
if (! acceptTokenClass(EHTokLeftParen))
expected("(");
bool decl = false;
TIntermNode* declNode = nullptr;
decl = acceptControlDeclaration(declNode);
if (decl) {
if (declNode == nullptr || declNode->getAsTyped() == nullptr) {
expected("initialized declaration");
return false;
} else
expression = declNode->getAsTyped();
} else {
// no declaration
if (! acceptExpression(expression)) {
expected("expression");
return false;
}
}
// RIGHT_PAREN
if (! acceptTokenClass(EHTokRightParen))
expected(")");
return true;
}
// The top-level full expression recognizer.
//
// expression
// : assignment_expression COMMA assignment_expression COMMA assignment_expression ...
//
bool HlslGrammar::acceptExpression(TIntermTyped*& node)
{
node = nullptr;
// assignment_expression
if (! acceptAssignmentExpression(node))
return false;
if (! peekTokenClass(EHTokComma))
return true;
do {
// ... COMMA
TSourceLoc loc = token.loc;
advanceToken();
// ... assignment_expression
TIntermTyped* rightNode = nullptr;
if (! acceptAssignmentExpression(rightNode)) {
expected("assignment expression");
return false;
}
node = intermediate.addComma(node, rightNode, loc);
if (! peekTokenClass(EHTokComma))
return true;
} while (true);
}
// initializer
// : LEFT_BRACE RIGHT_BRACE
// | LEFT_BRACE initializer_list RIGHT_BRACE
//
// initializer_list
// : assignment_expression COMMA assignment_expression COMMA ...
//
bool HlslGrammar::acceptInitializer(TIntermTyped*& node)
{
// LEFT_BRACE
if (! acceptTokenClass(EHTokLeftBrace))
return false;
// RIGHT_BRACE
TSourceLoc loc = token.loc;
if (acceptTokenClass(EHTokRightBrace)) {
// a zero-length initializer list
node = intermediate.makeAggregate(loc);
return true;
}
// initializer_list
node = nullptr;
do {
// assignment_expression
TIntermTyped* expr;
if (! acceptAssignmentExpression(expr)) {
expected("assignment expression in initializer list");
return false;
}
const bool firstNode = (node == nullptr);
node = intermediate.growAggregate(node, expr, loc);
// If every sub-node in the list has qualifier EvqConst, the returned node becomes
// EvqConst. Otherwise, it becomes EvqTemporary. That doesn't happen with e.g.
// EvqIn or EvqPosition, since the collection isn't EvqPosition if all the members are.
if (firstNode && expr->getQualifier().storage == EvqConst)
node->getQualifier().storage = EvqConst;
else if (expr->getQualifier().storage != EvqConst)
node->getQualifier().storage = EvqTemporary;
// COMMA
if (acceptTokenClass(EHTokComma)) {
if (acceptTokenClass(EHTokRightBrace)) // allow trailing comma
return true;
continue;
}
// RIGHT_BRACE
if (acceptTokenClass(EHTokRightBrace))
return true;
expected(", or }");
return false;
} while (true);
}
// Accept an assignment expression, where assignment operations
// associate right-to-left. That is, it is implicit, for example
//
// a op (b op (c op d))
//
// assigment_expression
// : initializer
// | conditional_expression
// | conditional_expression assign_op conditional_expression assign_op conditional_expression ...
//
bool HlslGrammar::acceptAssignmentExpression(TIntermTyped*& node)
{
// initializer
if (peekTokenClass(EHTokLeftBrace)) {
if (acceptInitializer(node))
return true;
expected("initializer");
return false;
}
// conditional_expression
if (! acceptConditionalExpression(node))
return false;
// assignment operation?
TOperator assignOp = HlslOpMap::assignment(peek());
if (assignOp == EOpNull)
return true;
// assign_op
TSourceLoc loc = token.loc;
advanceToken();
// conditional_expression assign_op conditional_expression ...
// Done by recursing this function, which automatically
// gets the right-to-left associativity.
TIntermTyped* rightNode = nullptr;
if (! acceptAssignmentExpression(rightNode)) {
expected("assignment expression");
return false;
}
node = parseContext.handleAssign(loc, assignOp, node, rightNode);
node = parseContext.handleLvalue(loc, "assign", node);
if (node == nullptr) {
parseContext.error(loc, "could not create assignment", "", "");
return false;
}
if (! peekTokenClass(EHTokComma))
return true;
return true;
}
// Accept a conditional expression, which associates right-to-left,
// accomplished by the "true" expression calling down to lower
// precedence levels than this level.
//
// conditional_expression
// : binary_expression
// | binary_expression QUESTION expression COLON assignment_expression
//
bool HlslGrammar::acceptConditionalExpression(TIntermTyped*& node)
{
// binary_expression
if (! acceptBinaryExpression(node, PlLogicalOr))
return false;
if (! acceptTokenClass(EHTokQuestion))
return true;
node = parseContext.convertConditionalExpression(token.loc, node, false);
if (node == nullptr)
return false;
++parseContext.controlFlowNestingLevel; // this only needs to work right if no errors
TIntermTyped* trueNode = nullptr;
if (! acceptExpression(trueNode)) {
expected("expression after ?");
return false;
}
TSourceLoc loc = token.loc;
if (! acceptTokenClass(EHTokColon)) {
expected(":");
return false;
}
TIntermTyped* falseNode = nullptr;
if (! acceptAssignmentExpression(falseNode)) {
expected("expression after :");
return false;
}
--parseContext.controlFlowNestingLevel;
node = intermediate.addSelection(node, trueNode, falseNode, loc);
return true;
}
// Accept a binary expression, for binary operations that
// associate left-to-right. This is, it is implicit, for example
//
// ((a op b) op c) op d
//
// binary_expression
// : expression op expression op expression ...
//
// where 'expression' is the next higher level in precedence.
//
bool HlslGrammar::acceptBinaryExpression(TIntermTyped*& node, PrecedenceLevel precedenceLevel)
{
if (precedenceLevel > PlMul)
return acceptUnaryExpression(node);
// assignment_expression
if (! acceptBinaryExpression(node, (PrecedenceLevel)(precedenceLevel + 1)))
return false;
do {
TOperator op = HlslOpMap::binary(peek());
PrecedenceLevel tokenLevel = HlslOpMap::precedenceLevel(op);
if (tokenLevel < precedenceLevel)
return true;
// ... op
TSourceLoc loc = token.loc;
advanceToken();
// ... expression
TIntermTyped* rightNode = nullptr;
if (! acceptBinaryExpression(rightNode, (PrecedenceLevel)(precedenceLevel + 1))) {
expected("expression");
return false;
}
node = intermediate.addBinaryMath(op, node, rightNode, loc);
if (node == nullptr) {
parseContext.error(loc, "Could not perform requested binary operation", "", "");
return false;
}
} while (true);
}
// unary_expression
// : (type) unary_expression
// | + unary_expression
// | - unary_expression
// | ! unary_expression
// | ~ unary_expression
// | ++ unary_expression
// | -- unary_expression
// | postfix_expression
//
bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node)
{
// (type) unary_expression
// Have to look two steps ahead, because this could be, e.g., a
// postfix_expression instead, since that also starts with at "(".
if (acceptTokenClass(EHTokLeftParen)) {
TType castType;
if (acceptType(castType)) {
// recognize any array_specifier as part of the type
TArraySizes* arraySizes = nullptr;
acceptArraySpecifier(arraySizes);
if (arraySizes != nullptr)
castType.transferArraySizes(arraySizes);
TSourceLoc loc = token.loc;
if (acceptTokenClass(EHTokRightParen)) {
// We've matched "(type)" now, get the expression to cast
if (! acceptUnaryExpression(node))
return false;
// Hook it up like a constructor
TFunction* constructorFunction = parseContext.makeConstructorCall(loc, castType);
if (constructorFunction == nullptr) {
expected("type that can be constructed");
return false;
}
TIntermTyped* arguments = nullptr;
parseContext.handleFunctionArgument(constructorFunction, arguments, node);
node = parseContext.handleFunctionCall(loc, constructorFunction, arguments);
return node != nullptr;
} else {
// This could be a parenthesized constructor, ala (int(3)), and we just accepted
// the '(int' part. We must back up twice.
recedeToken();
recedeToken();
// Note, there are no array constructors like
// (float[2](...))
if (arraySizes != nullptr)
parseContext.error(loc, "parenthesized array constructor not allowed", "([]())", "", "");
}
} else {
// This isn't a type cast, but it still started "(", so if it is a
// unary expression, it can only be a postfix_expression, so try that.
// Back it up first.
recedeToken();
return acceptPostfixExpression(node);
}
}
// peek for "op unary_expression"
TOperator unaryOp = HlslOpMap::preUnary(peek());
// postfix_expression (if no unary operator)
if (unaryOp == EOpNull)
return acceptPostfixExpression(node);
// op unary_expression
TSourceLoc loc = token.loc;
advanceToken();
if (! acceptUnaryExpression(node))
return false;
// + is a no-op
if (unaryOp == EOpAdd)
return true;
node = intermediate.addUnaryMath(unaryOp, node, loc);
// These unary ops require lvalues
if (unaryOp == EOpPreIncrement || unaryOp == EOpPreDecrement)
node = parseContext.handleLvalue(loc, "unary operator", node);
return node != nullptr;
}
// postfix_expression
// : LEFT_PAREN expression RIGHT_PAREN
// | literal
// | constructor
// | IDENTIFIER [ COLONCOLON IDENTIFIER [ COLONCOLON IDENTIFIER ... ] ]
// | function_call
// | postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET
// | postfix_expression DOT IDENTIFIER
// | postfix_expression DOT IDENTIFIER arguments
// | postfix_expression arguments
// | postfix_expression INC_OP
// | postfix_expression DEC_OP
//
bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node)
{
// Not implemented as self-recursive:
// The logical "right recursion" is done with a loop at the end
// idToken will pick up either a variable or a function name in a function call
HlslToken idToken;
// Find something before the postfix operations, as they can't operate
// on nothing. So, no "return true", they fall through, only "return false".
if (acceptTokenClass(EHTokLeftParen)) {
// LEFT_PAREN expression RIGHT_PAREN
if (! acceptExpression(node)) {
expected("expression");
return false;
}
if (! acceptTokenClass(EHTokRightParen)) {
expected(")");
return false;
}
} else if (acceptLiteral(node)) {
// literal (nothing else to do yet)
} else if (acceptConstructor(node)) {
// constructor (nothing else to do yet)
} else if (acceptIdentifier(idToken)) {
// user-type, namespace name, variable, or function name
TString* fullName = idToken.string;
while (acceptTokenClass(EHTokColonColon)) {
// user-type or namespace name
fullName = NewPoolTString(fullName->c_str());
fullName->append(parseContext.scopeMangler);
if (acceptIdentifier(idToken))
fullName->append(*idToken.string);
else {
expected("identifier after ::");
return false;
}
}
if (! peekTokenClass(EHTokLeftParen)) {
node = parseContext.handleVariable(idToken.loc, fullName);
if (node == nullptr)
return false;
} else if (acceptFunctionCall(idToken.loc, *fullName, node, nullptr)) {
// function_call (nothing else to do yet)
} else {
expected("function call arguments");
return false;
}
} else {
// nothing found, can't post operate
return false;
}
// Something was found, chain as many postfix operations as exist.
do {
TSourceLoc loc = token.loc;
TOperator postOp = HlslOpMap::postUnary(peek());
// Consume only a valid post-unary operator, otherwise we are done.
switch (postOp) {
case EOpIndexDirectStruct:
case EOpIndexIndirect:
case EOpPostIncrement:
case EOpPostDecrement:
case EOpScoping:
advanceToken();
break;
default:
return true;
}
// We have a valid post-unary operator, process it.
switch (postOp) {
case EOpScoping:
case EOpIndexDirectStruct:
{
// DOT IDENTIFIER
// includes swizzles, member variables, and member functions
HlslToken field;
if (! acceptIdentifier(field)) {
expected("swizzle or member");
return false;
}
if (peekTokenClass(EHTokLeftParen)) {
// member function
TIntermTyped* thisNode = node;
// arguments
if (! acceptFunctionCall(field.loc, *field.string, node, thisNode)) {
expected("function parameters");
return false;
}
} else
node = parseContext.handleDotDereference(field.loc, node, *field.string);
break;
}
case EOpIndexIndirect:
{
// LEFT_BRACKET integer_expression RIGHT_BRACKET
TIntermTyped* indexNode = nullptr;
if (! acceptExpression(indexNode) ||
! peekTokenClass(EHTokRightBracket)) {
expected("expression followed by ']'");
return false;
}
advanceToken();
node = parseContext.handleBracketDereference(indexNode->getLoc(), node, indexNode);
if (node == nullptr)
return false;
break;
}
case EOpPostIncrement:
// INC_OP
// fall through
case EOpPostDecrement:
// DEC_OP
node = intermediate.addUnaryMath(postOp, node, loc);
node = parseContext.handleLvalue(loc, "unary operator", node);
break;
default:
assert(0);
break;
}
} while (true);
}
// constructor
// : type argument_list
//
bool HlslGrammar::acceptConstructor(TIntermTyped*& node)
{
// type
TType type;
if (acceptType(type)) {
TFunction* constructorFunction = parseContext.makeConstructorCall(token.loc, type);
if (constructorFunction == nullptr)
return false;
// arguments
TIntermTyped* arguments = nullptr;
if (! acceptArguments(constructorFunction, arguments)) {
// It's possible this is a type keyword used as an identifier. Put the token back
// for later use.
recedeToken();
return false;
}
if (arguments == nullptr) {
expected("one or more arguments");
return false;
}
// hook it up
node = parseContext.handleFunctionCall(token.loc, constructorFunction, arguments);
return node != nullptr;
}
return false;
}
// The function_call identifier was already recognized, and passed in as idToken.
//
// function_call
// : [idToken] arguments
//
bool HlslGrammar::acceptFunctionCall(const TSourceLoc& loc, TString& name, TIntermTyped*& node, TIntermTyped* baseObject)
{
// name
TString* functionName = nullptr;
if (baseObject == nullptr) {
functionName = &name;
} else if (parseContext.isBuiltInMethod(loc, baseObject, name)) {
// Built-in methods are not in the symbol table as methods, but as global functions
// taking an explicit 'this' as the first argument.
functionName = NewPoolTString(BUILTIN_PREFIX);
functionName->append(name);
} else {
if (! baseObject->getType().isStruct()) {
expected("structure");
return false;
}
functionName = NewPoolTString("");
functionName->append(baseObject->getType().getTypeName());
parseContext.addScopeMangler(*functionName);
functionName->append(name);
}
// function
TFunction* function = new TFunction(functionName, TType(EbtVoid));
// arguments
TIntermTyped* arguments = nullptr;
if (baseObject != nullptr) {
// Non-static member functions have an implicit first argument of the base object.
parseContext.handleFunctionArgument(function, arguments, baseObject);
}
if (! acceptArguments(function, arguments))
return false;
// call
node = parseContext.handleFunctionCall(loc, function, arguments);
return node != nullptr;
}
// arguments
// : LEFT_PAREN expression COMMA expression COMMA ... RIGHT_PAREN
//
// The arguments are pushed onto the 'function' argument list and
// onto the 'arguments' aggregate.
//
bool HlslGrammar::acceptArguments(TFunction* function, TIntermTyped*& arguments)
{
// LEFT_PAREN
if (! acceptTokenClass(EHTokLeftParen))
return false;
// RIGHT_PAREN
if (acceptTokenClass(EHTokRightParen))
return true;
// must now be at least one expression...
do {
// expression
TIntermTyped* arg;
if (! acceptAssignmentExpression(arg))
return false;
// hook it up
parseContext.handleFunctionArgument(function, arguments, arg);
// COMMA
if (! acceptTokenClass(EHTokComma))
break;
} while (true);
// RIGHT_PAREN
if (! acceptTokenClass(EHTokRightParen)) {
expected(")");
return false;
}
return true;
}
bool HlslGrammar::acceptLiteral(TIntermTyped*& node)
{
switch (token.tokenClass) {
case EHTokIntConstant:
node = intermediate.addConstantUnion(token.i, token.loc, true);
break;
case EHTokUintConstant:
node = intermediate.addConstantUnion(token.u, token.loc, true);
break;
case EHTokFloat16Constant:
node = intermediate.addConstantUnion(token.d, EbtFloat16, token.loc, true);
break;
case EHTokFloatConstant:
node = intermediate.addConstantUnion(token.d, EbtFloat, token.loc, true);
break;
case EHTokDoubleConstant:
node = intermediate.addConstantUnion(token.d, EbtDouble, token.loc, true);
break;
case EHTokBoolConstant:
node = intermediate.addConstantUnion(token.b, token.loc, true);
break;
case EHTokStringConstant:
node = intermediate.addConstantUnion(token.string, token.loc, true);
break;
default:
return false;
}
advanceToken();
return true;
}
// simple_statement
// : SEMICOLON
// | declaration_statement
// | expression SEMICOLON
//
bool HlslGrammar::acceptSimpleStatement(TIntermNode*& statement)
{
// SEMICOLON
if (acceptTokenClass(EHTokSemicolon))
return true;
// declaration
if (acceptDeclaration(statement))
return true;
// expression
TIntermTyped* node;
if (acceptExpression(node))
statement = node;
else
return false;
// SEMICOLON (following an expression)
if (acceptTokenClass(EHTokSemicolon))
return true;
else {
expected(";");
return false;
}
}
// compound_statement
// : LEFT_CURLY statement statement ... RIGHT_CURLY
//
bool HlslGrammar::acceptCompoundStatement(TIntermNode*& retStatement)
{
TIntermAggregate* compoundStatement = nullptr;
// LEFT_CURLY
if (! acceptTokenClass(EHTokLeftBrace))
return false;
// statement statement ...
TIntermNode* statement = nullptr;
while (acceptStatement(statement)) {
TIntermBranch* branch = statement ? statement->getAsBranchNode() : nullptr;
if (branch != nullptr && (branch->getFlowOp() == EOpCase ||
branch->getFlowOp() == EOpDefault)) {
// hook up individual subsequences within a switch statement
parseContext.wrapupSwitchSubsequence(compoundStatement, statement);
compoundStatement = nullptr;
} else {
// hook it up to the growing compound statement
compoundStatement = intermediate.growAggregate(compoundStatement, statement);
}
}
if (compoundStatement)
compoundStatement->setOperator(intermediate.getDebugInfo() ? EOpScope : EOpSequence);
retStatement = compoundStatement;
// RIGHT_CURLY
return acceptTokenClass(EHTokRightBrace);
}
bool HlslGrammar::acceptScopedStatement(TIntermNode*& statement)
{
parseContext.pushScope();
bool result = acceptStatement(statement);
parseContext.popScope();
return result;
}
bool HlslGrammar::acceptScopedCompoundStatement(TIntermNode*& statement)
{
parseContext.pushScope();
bool result = acceptCompoundStatement(statement);
parseContext.popScope();
return result;
}
// statement
// : attributes attributed_statement
//
// attributed_statement
// : compound_statement
// | simple_statement
// | selection_statement
// | switch_statement
// | case_label
// | default_label
// | iteration_statement
// | jump_statement
//
bool HlslGrammar::acceptStatement(TIntermNode*& statement)
{
statement = nullptr;
// attributes
TAttributes attributes;
acceptAttributes(attributes);
// attributed_statement
switch (peek()) {
case EHTokLeftBrace:
return acceptScopedCompoundStatement(statement);
case EHTokIf:
return acceptSelectionStatement(statement, attributes);
case EHTokSwitch:
return acceptSwitchStatement(statement, attributes);
case EHTokFor:
case EHTokDo:
case EHTokWhile:
return acceptIterationStatement(statement, attributes);
case EHTokContinue:
case EHTokBreak:
case EHTokDiscard:
case EHTokReturn:
return acceptJumpStatement(statement);
case EHTokCase:
return acceptCaseLabel(statement);
case EHTokDefault:
return acceptDefaultLabel(statement);
case EHTokRightBrace:
// Performance: not strictly necessary, but stops a bunch of hunting early,
// and is how sequences of statements end.
return false;
default:
return acceptSimpleStatement(statement);
}
return true;
}
// attributes
// : [zero or more:] bracketed-attribute
//
// bracketed-attribute:
// : LEFT_BRACKET scoped-attribute RIGHT_BRACKET
// : LEFT_BRACKET LEFT_BRACKET scoped-attribute RIGHT_BRACKET RIGHT_BRACKET
//
// scoped-attribute:
// : attribute
// | namespace COLON COLON attribute
//
// attribute:
// : UNROLL
// | UNROLL LEFT_PAREN literal RIGHT_PAREN
// | FASTOPT
// | ALLOW_UAV_CONDITION
// | BRANCH
// | FLATTEN
// | FORCECASE
// | CALL
// | DOMAIN
// | EARLYDEPTHSTENCIL
// | INSTANCE
// | MAXTESSFACTOR
// | OUTPUTCONTROLPOINTS
// | OUTPUTTOPOLOGY
// | PARTITIONING
// | PATCHCONSTANTFUNC
// | NUMTHREADS LEFT_PAREN x_size, y_size,z z_size RIGHT_PAREN
//
void HlslGrammar::acceptAttributes(TAttributes& attributes)
{
// For now, accept the [ XXX(X) ] syntax, but drop all but
// numthreads, which is used to set the CS local size.
// TODO: subset to correct set? Pass on?
do {
HlslToken attributeToken;
// LEFT_BRACKET?
if (! acceptTokenClass(EHTokLeftBracket))
return;
// another LEFT_BRACKET?
bool doubleBrackets = false;
if (acceptTokenClass(EHTokLeftBracket))
doubleBrackets = true;
// attribute? (could be namespace; will adjust later)
if (!acceptIdentifier(attributeToken)) {
if (!peekTokenClass(EHTokRightBracket)) {
expected("namespace or attribute identifier");
advanceToken();
}
}
TString nameSpace;
if (acceptTokenClass(EHTokColonColon)) {
// namespace COLON COLON
nameSpace = *attributeToken.string;
// attribute
if (!acceptIdentifier(attributeToken)) {
expected("attribute identifier");
return;
}
}
TIntermAggregate* expressions = nullptr;
// (x, ...)
if (acceptTokenClass(EHTokLeftParen)) {
expressions = new TIntermAggregate;
TIntermTyped* node;
bool expectingExpression = false;
while (acceptAssignmentExpression(node)) {
expectingExpression = false;
expressions->getSequence().push_back(node);
if (acceptTokenClass(EHTokComma))
expectingExpression = true;
}
// 'expressions' is an aggregate with the expressions in it
if (! acceptTokenClass(EHTokRightParen))
expected(")");
// Error for partial or missing expression
if (expectingExpression || expressions->getSequence().empty())
expected("expression");
}
// RIGHT_BRACKET
if (!acceptTokenClass(EHTokRightBracket)) {
expected("]");
return;
}
// another RIGHT_BRACKET?
if (doubleBrackets && !acceptTokenClass(EHTokRightBracket)) {
expected("]]");
return;
}
// Add any values we found into the attribute map.
if (attributeToken.string != nullptr) {
TAttributeType attributeType = parseContext.attributeFromName(nameSpace, *attributeToken.string);
if (attributeType == EatNone)
parseContext.warn(attributeToken.loc, "unrecognized attribute", attributeToken.string->c_str(), "");
else {
TAttributeArgs attributeArgs = { attributeType, expressions };
attributes.push_back(attributeArgs);
}
}
} while (true);
}
// selection_statement
// : IF LEFT_PAREN expression RIGHT_PAREN statement
// : IF LEFT_PAREN expression RIGHT_PAREN statement ELSE statement
//
bool HlslGrammar::acceptSelectionStatement(TIntermNode*& statement, const TAttributes& attributes)
{
TSourceLoc loc = token.loc;
// IF
if (! acceptTokenClass(EHTokIf))
return false;
// so that something declared in the condition is scoped to the lifetimes
// of the then-else statements
parseContext.pushScope();
// LEFT_PAREN expression RIGHT_PAREN
TIntermTyped* condition;
if (! acceptParenExpression(condition))
return false;
condition = parseContext.convertConditionalExpression(loc, condition);
if (condition == nullptr)
return false;
// create the child statements
TIntermNodePair thenElse = { nullptr, nullptr };
++parseContext.controlFlowNestingLevel; // this only needs to work right if no errors
// then statement
if (! acceptScopedStatement(thenElse.node1)) {
expected("then statement");
return false;
}
// ELSE
if (acceptTokenClass(EHTokElse)) {
// else statement
if (! acceptScopedStatement(thenElse.node2)) {
expected("else statement");
return false;
}
}
// Put the pieces together
statement = intermediate.addSelection(condition, thenElse, loc);
parseContext.handleSelectionAttributes(loc, statement->getAsSelectionNode(), attributes);
parseContext.popScope();
--parseContext.controlFlowNestingLevel;
return true;
}
// switch_statement
// : SWITCH LEFT_PAREN expression RIGHT_PAREN compound_statement
//
bool HlslGrammar::acceptSwitchStatement(TIntermNode*& statement, const TAttributes& attributes)
{
// SWITCH
TSourceLoc loc = token.loc;
if (! acceptTokenClass(EHTokSwitch))
return false;
// LEFT_PAREN expression RIGHT_PAREN
parseContext.pushScope();
TIntermTyped* switchExpression;
if (! acceptParenExpression(switchExpression)) {
parseContext.popScope();
return false;
}
// compound_statement
parseContext.pushSwitchSequence(new TIntermSequence);
++parseContext.controlFlowNestingLevel;
bool statementOkay = acceptCompoundStatement(statement);
--parseContext.controlFlowNestingLevel;
if (statementOkay)
statement = parseContext.addSwitch(loc, switchExpression, statement ? statement->getAsAggregate() : nullptr,
attributes);
parseContext.popSwitchSequence();
parseContext.popScope();
return statementOkay;
}
// iteration_statement
// : WHILE LEFT_PAREN condition RIGHT_PAREN statement
// | DO LEFT_BRACE statement RIGHT_BRACE WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON
// | FOR LEFT_PAREN for_init_statement for_rest_statement RIGHT_PAREN statement
//
// Non-speculative, only call if it needs to be found; WHILE or DO or FOR already seen.
bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement, const TAttributes& attributes)
{
TSourceLoc loc = token.loc;
TIntermTyped* condition = nullptr;
EHlslTokenClass loop = peek();
assert(loop == EHTokDo || loop == EHTokFor || loop == EHTokWhile);
// WHILE or DO or FOR
advanceToken();
TIntermLoop* loopNode = nullptr;
switch (loop) {
case EHTokWhile:
// so that something declared in the condition is scoped to the lifetime
// of the while sub-statement
parseContext.pushScope(); // this only needs to work right if no errors
parseContext.nestLooping();
++parseContext.controlFlowNestingLevel;
// LEFT_PAREN condition RIGHT_PAREN
if (! acceptParenExpression(condition))
return false;
condition = parseContext.convertConditionalExpression(loc, condition);
if (condition == nullptr)
return false;
// statement
if (! acceptScopedStatement(statement)) {
expected("while sub-statement");
return false;
}
parseContext.unnestLooping();
parseContext.popScope();
--parseContext.controlFlowNestingLevel;
loopNode = intermediate.addLoop(statement, condition, nullptr, true, loc);
statement = loopNode;
break;
case EHTokDo:
parseContext.nestLooping(); // this only needs to work right if no errors
++parseContext.controlFlowNestingLevel;
// statement
if (! acceptScopedStatement(statement)) {
expected("do sub-statement");
return false;
}
// WHILE
if (! acceptTokenClass(EHTokWhile)) {
expected("while");
return false;
}
// LEFT_PAREN condition RIGHT_PAREN
if (! acceptParenExpression(condition))
return false;
condition = parseContext.convertConditionalExpression(loc, condition);
if (condition == nullptr)
return false;
if (! acceptTokenClass(EHTokSemicolon))
expected(";");
parseContext.unnestLooping();
--parseContext.controlFlowNestingLevel;
loopNode = intermediate.addLoop(statement, condition, nullptr, false, loc);
statement = loopNode;
break;
case EHTokFor:
{
// LEFT_PAREN
if (! acceptTokenClass(EHTokLeftParen))
expected("(");
// so that something declared in the condition is scoped to the lifetime
// of the for sub-statement
parseContext.pushScope();
// initializer
TIntermNode* initNode = nullptr;
if (! acceptSimpleStatement(initNode))
expected("for-loop initializer statement");
parseContext.nestLooping(); // this only needs to work right if no errors
++parseContext.controlFlowNestingLevel;
// condition SEMI_COLON
acceptExpression(condition);
if (! acceptTokenClass(EHTokSemicolon))
expected(";");
if (condition != nullptr) {
condition = parseContext.convertConditionalExpression(loc, condition);
if (condition == nullptr)
return false;
}
// iterator SEMI_COLON
TIntermTyped* iterator = nullptr;
acceptExpression(iterator);
if (! acceptTokenClass(EHTokRightParen))
expected(")");
// statement
if (! acceptScopedStatement(statement)) {
expected("for sub-statement");
return false;
}
statement = intermediate.addForLoop(statement, initNode, condition, iterator, true, loc, loopNode);
parseContext.popScope();
parseContext.unnestLooping();
--parseContext.controlFlowNestingLevel;
break;
}
default:
return false;
}
parseContext.handleLoopAttributes(loc, loopNode, attributes);
return true;
}
// jump_statement
// : CONTINUE SEMICOLON
// | BREAK SEMICOLON
// | DISCARD SEMICOLON
// | RETURN SEMICOLON
// | RETURN expression SEMICOLON
//
bool HlslGrammar::acceptJumpStatement(TIntermNode*& statement)
{
EHlslTokenClass jump = peek();
switch (jump) {
case EHTokContinue:
case EHTokBreak:
case EHTokDiscard:
case EHTokReturn:
advanceToken();
break;
default:
// not something we handle in this function
return false;
}
switch (jump) {
case EHTokContinue:
statement = intermediate.addBranch(EOpContinue, token.loc);
if (parseContext.loopNestingLevel == 0) {
expected("loop");
return false;
}
break;
case EHTokBreak:
statement = intermediate.addBranch(EOpBreak, token.loc);
if (parseContext.loopNestingLevel == 0 && parseContext.switchSequenceStack.size() == 0) {
expected("loop or switch");
return false;
}
break;
case EHTokDiscard:
statement = intermediate.addBranch(EOpKill, token.loc);
break;
case EHTokReturn:
{
// expression
TIntermTyped* node;
if (acceptExpression(node)) {
// hook it up
statement = parseContext.handleReturnValue(token.loc, node);
} else
statement = intermediate.addBranch(EOpReturn, token.loc);
break;
}
default:
assert(0);
return false;
}
// SEMICOLON
if (! acceptTokenClass(EHTokSemicolon))
expected(";");
return true;
}
// case_label
// : CASE expression COLON
//
bool HlslGrammar::acceptCaseLabel(TIntermNode*& statement)
{
TSourceLoc loc = token.loc;
if (! acceptTokenClass(EHTokCase))
return false;
TIntermTyped* expression;
if (! acceptExpression(expression)) {
expected("case expression");
return false;
}
if (! acceptTokenClass(EHTokColon)) {
expected(":");
return false;
}
statement = parseContext.intermediate.addBranch(EOpCase, expression, loc);
return true;
}
// default_label
// : DEFAULT COLON
//
bool HlslGrammar::acceptDefaultLabel(TIntermNode*& statement)
{
TSourceLoc loc = token.loc;
if (! acceptTokenClass(EHTokDefault))
return false;
if (! acceptTokenClass(EHTokColon)) {
expected(":");
return false;
}
statement = parseContext.intermediate.addBranch(EOpDefault, loc);
return true;
}
// array_specifier
// : LEFT_BRACKET integer_expression RGHT_BRACKET ... // optional
// : LEFT_BRACKET RGHT_BRACKET // optional
//
void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes)
{
arraySizes = nullptr;
// Early-out if there aren't any array dimensions
if (!peekTokenClass(EHTokLeftBracket))
return;
// If we get here, we have at least one array dimension. This will track the sizes we find.
arraySizes = new TArraySizes;
// Collect each array dimension.
while (acceptTokenClass(EHTokLeftBracket)) {
TSourceLoc loc = token.loc;
TIntermTyped* sizeExpr = nullptr;
// Array sizing expression is optional. If omitted, array will be later sized by initializer list.
const bool hasArraySize = acceptAssignmentExpression(sizeExpr);
if (! acceptTokenClass(EHTokRightBracket)) {
expected("]");
return;
}
if (hasArraySize) {
TArraySize arraySize;
parseContext.arraySizeCheck(loc, sizeExpr, arraySize);
arraySizes->addInnerSize(arraySize);
} else {
arraySizes->addInnerSize(0); // sized by initializers.
}
}
}
// post_decls
// : COLON semantic // optional
// COLON PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN // optional
// COLON REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt (COMMA SPACEN)opt RIGHT_PAREN // optional
// COLON LAYOUT layout_qualifier_list
// annotations // optional
//
// Return true if any tokens were accepted. That is,
// false can be returned on successfully recognizing nothing,
// not necessarily meaning bad syntax.
//
bool HlslGrammar::acceptPostDecls(TQualifier& qualifier)
{
bool found = false;
do {
// COLON
if (acceptTokenClass(EHTokColon)) {
found = true;
HlslToken idToken;
if (peekTokenClass(EHTokLayout))
acceptLayoutQualifierList(qualifier);
else if (acceptTokenClass(EHTokPackOffset)) {
// PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN
if (! acceptTokenClass(EHTokLeftParen)) {
expected("(");
return false;
}
HlslToken locationToken;
if (! acceptIdentifier(locationToken)) {
expected("c[subcomponent][.component]");
return false;
}
HlslToken componentToken;
if (acceptTokenClass(EHTokDot)) {
if (! acceptIdentifier(componentToken)) {
expected("component");
return false;
}
}
if (! acceptTokenClass(EHTokRightParen)) {
expected(")");
break;
}
parseContext.handlePackOffset(locationToken.loc, qualifier, *locationToken.string, componentToken.string);
} else if (! acceptIdentifier(idToken)) {
expected("layout, semantic, packoffset, or register");
return false;
} else if (*idToken.string == "register") {
// REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt (COMMA SPACEN)opt RIGHT_PAREN
// LEFT_PAREN
if (! acceptTokenClass(EHTokLeftParen)) {
expected("(");
return false;
}
HlslToken registerDesc; // for Type#
HlslToken profile;
if (! acceptIdentifier(registerDesc)) {
expected("register number description");
return false;
}
if (registerDesc.string->size() > 1 && !isdigit((*registerDesc.string)[1]) &&
acceptTokenClass(EHTokComma)) {
// Then we didn't really see the registerDesc yet, it was
// actually the profile. Adjust...
profile = registerDesc;
if (! acceptIdentifier(registerDesc)) {
expected("register number description");
return false;
}
}
int subComponent = 0;
if (acceptTokenClass(EHTokLeftBracket)) {
// LEFT_BRACKET subcomponent RIGHT_BRACKET
if (! peekTokenClass(EHTokIntConstant)) {
expected("literal integer");
return false;
}
subComponent = token.i;
advanceToken();
if (! acceptTokenClass(EHTokRightBracket)) {
expected("]");
break;
}
}
// (COMMA SPACEN)opt
HlslToken spaceDesc;
if (acceptTokenClass(EHTokComma)) {
if (! acceptIdentifier(spaceDesc)) {
expected ("space identifier");
return false;
}
}
// RIGHT_PAREN
if (! acceptTokenClass(EHTokRightParen)) {
expected(")");
break;
}
parseContext.handleRegister(registerDesc.loc, qualifier, profile.string, *registerDesc.string, subComponent, spaceDesc.string);
} else {
// semantic, in idToken.string
TString semanticUpperCase = *idToken.string;
std::transform(semanticUpperCase.begin(), semanticUpperCase.end(), semanticUpperCase.begin(), ::toupper);
parseContext.handleSemantic(idToken.loc, qualifier, mapSemantic(semanticUpperCase.c_str()), semanticUpperCase);
}
} else if (peekTokenClass(EHTokLeftAngle)) {
found = true;
acceptAnnotations(qualifier);
} else
break;
} while (true);
return found;
}
//
// Get the stream of tokens from the scanner, but skip all syntactic/semantic
// processing.
//
bool HlslGrammar::captureBlockTokens(TVector<HlslToken>& tokens)
{
if (! peekTokenClass(EHTokLeftBrace))
return false;
int braceCount = 0;
do {
switch (peek()) {
case EHTokLeftBrace:
++braceCount;
break;
case EHTokRightBrace:
--braceCount;
break;
case EHTokNone:
// End of input before balance { } is bad...
return false;
default:
break;
}
tokens.push_back(token);
advanceToken();
} while (braceCount > 0);
return true;
}
// Return a string for just the types that can also be declared as an identifier.
const char* HlslGrammar::getTypeString(EHlslTokenClass tokenClass) const
{
switch (tokenClass) {
case EHTokSample: return "sample";
case EHTokHalf: return "half";
case EHTokHalf1x1: return "half1x1";
case EHTokHalf1x2: return "half1x2";
case EHTokHalf1x3: return "half1x3";
case EHTokHalf1x4: return "half1x4";
case EHTokHalf2x1: return "half2x1";
case EHTokHalf2x2: return "half2x2";
case EHTokHalf2x3: return "half2x3";
case EHTokHalf2x4: return "half2x4";
case EHTokHalf3x1: return "half3x1";
case EHTokHalf3x2: return "half3x2";
case EHTokHalf3x3: return "half3x3";
case EHTokHalf3x4: return "half3x4";
case EHTokHalf4x1: return "half4x1";
case EHTokHalf4x2: return "half4x2";
case EHTokHalf4x3: return "half4x3";
case EHTokHalf4x4: return "half4x4";
case EHTokBool: return "bool";
case EHTokFloat: return "float";
case EHTokDouble: return "double";
case EHTokInt: return "int";
case EHTokUint: return "uint";
case EHTokMin16float: return "min16float";
case EHTokMin10float: return "min10float";
case EHTokMin16int: return "min16int";
case EHTokMin12int: return "min12int";
case EHTokConstantBuffer: return "ConstantBuffer";
case EHTokLayout: return "layout";
default:
return nullptr;
}
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslAttributes.cpp | //
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "hlslAttributes.h"
#include "hlslParseHelper.h"
namespace glslang {
// Map the given string to an attribute enum from TAttributeType,
// or EatNone if invalid.
TAttributeType HlslParseContext::attributeFromName(const TString& nameSpace, const TString& name) const
{
// handle names within a namespace
if (nameSpace == "vk") {
if (name == "input_attachment_index")
return EatInputAttachment;
else if (name == "location")
return EatLocation;
else if (name == "binding")
return EatBinding;
else if (name == "global_cbuffer_binding")
return EatGlobalBinding;
else if (name == "builtin")
return EatBuiltIn;
else if (name == "constant_id")
return EatConstantId;
else if (name == "push_constant")
return EatPushConstant;
} else if (nameSpace == "spv") {
if (name == "format_rgba32f") return EatFormatRgba32f;
if (name == "format_rgba16f") return EatFormatRgba16f;
if (name == "format_r32f") return EatFormatR32f;
if (name == "format_rgba8") return EatFormatRgba8;
if (name == "format_rgba8snorm") return EatFormatRgba8Snorm;
if (name == "format_rg32f") return EatFormatRg32f;
if (name == "format_rg16f") return EatFormatRg16f;
if (name == "format_r11fg11fb10f") return EatFormatR11fG11fB10f;
if (name == "format_r16f") return EatFormatR16f;
if (name == "format_rgba16") return EatFormatRgba16;
if (name == "format_rgb10a2") return EatFormatRgb10A2;
if (name == "format_rg16") return EatFormatRg16;
if (name == "format_rg8") return EatFormatRg8;
if (name == "format_r16") return EatFormatR16;
if (name == "format_r8") return EatFormatR8;
if (name == "format_rgba16snorm") return EatFormatRgba16Snorm;
if (name == "format_rg16snorm") return EatFormatRg16Snorm;
if (name == "format_rg8snorm") return EatFormatRg8Snorm;
if (name == "format_r16snorm") return EatFormatR16Snorm;
if (name == "format_r8snorm") return EatFormatR8Snorm;
if (name == "format_rgba32i") return EatFormatRgba32i;
if (name == "format_rgba16i") return EatFormatRgba16i;
if (name == "format_rgba8i") return EatFormatRgba8i;
if (name == "format_r32i") return EatFormatR32i;
if (name == "format_rg32i") return EatFormatRg32i;
if (name == "format_rg16i") return EatFormatRg16i;
if (name == "format_rg8i") return EatFormatRg8i;
if (name == "format_r16i") return EatFormatR16i;
if (name == "format_r8i") return EatFormatR8i;
if (name == "format_rgba32ui") return EatFormatRgba32ui;
if (name == "format_rgba16ui") return EatFormatRgba16ui;
if (name == "format_rgba8ui") return EatFormatRgba8ui;
if (name == "format_r32ui") return EatFormatR32ui;
if (name == "format_rgb10a2ui") return EatFormatRgb10a2ui;
if (name == "format_rg32ui") return EatFormatRg32ui;
if (name == "format_rg16ui") return EatFormatRg16ui;
if (name == "format_rg8ui") return EatFormatRg8ui;
if (name == "format_r16ui") return EatFormatR16ui;
if (name == "format_r8ui") return EatFormatR8ui;
if (name == "nonwritable") return EatNonWritable;
if (name == "nonreadable") return EatNonReadable;
if (name == "export") return EatExport;
} else if (nameSpace.size() > 0)
return EatNone;
// handle names with no namespace
if (name == "allow_uav_condition")
return EatAllow_uav_condition;
else if (name == "branch")
return EatBranch;
else if (name == "call")
return EatCall;
else if (name == "domain")
return EatDomain;
else if (name == "earlydepthstencil")
return EatEarlyDepthStencil;
else if (name == "fastopt")
return EatFastOpt;
else if (name == "flatten")
return EatFlatten;
else if (name == "forcecase")
return EatForceCase;
else if (name == "instance")
return EatInstance;
else if (name == "maxtessfactor")
return EatMaxTessFactor;
else if (name == "maxvertexcount")
return EatMaxVertexCount;
else if (name == "numthreads")
return EatNumThreads;
else if (name == "outputcontrolpoints")
return EatOutputControlPoints;
else if (name == "outputtopology")
return EatOutputTopology;
else if (name == "partitioning")
return EatPartitioning;
else if (name == "patchconstantfunc")
return EatPatchConstantFunc;
else if (name == "unroll")
return EatUnroll;
else if (name == "loop")
return EatLoop;
else
return EatNone;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslOpMap.cpp | //
// Copyright (C) 2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Map from physical token form (e.g. '-') to logical operator
// form (e.g., binary subtract or unary negate).
#include "hlslOpMap.h"
namespace glslang {
// Map parsing tokens that could be assignments into assignment operators.
TOperator HlslOpMap::assignment(EHlslTokenClass op)
{
switch (op) {
case EHTokAssign: return EOpAssign;
case EHTokMulAssign: return EOpMulAssign;
case EHTokDivAssign: return EOpDivAssign;
case EHTokAddAssign: return EOpAddAssign;
case EHTokModAssign: return EOpModAssign;
case EHTokLeftAssign: return EOpLeftShiftAssign;
case EHTokRightAssign: return EOpRightShiftAssign;
case EHTokAndAssign: return EOpAndAssign;
case EHTokXorAssign: return EOpExclusiveOrAssign;
case EHTokOrAssign: return EOpInclusiveOrAssign;
case EHTokSubAssign: return EOpSubAssign;
default:
return EOpNull;
}
}
// Map parsing tokens that could be binary operations into binary operators.
TOperator HlslOpMap::binary(EHlslTokenClass op)
{
switch (op) {
case EHTokPlus: return EOpAdd;
case EHTokDash: return EOpSub;
case EHTokStar: return EOpMul;
case EHTokSlash: return EOpDiv;
case EHTokPercent: return EOpMod;
case EHTokRightOp: return EOpRightShift;
case EHTokLeftOp: return EOpLeftShift;
case EHTokAmpersand: return EOpAnd;
case EHTokVerticalBar: return EOpInclusiveOr;
case EHTokCaret: return EOpExclusiveOr;
case EHTokEqOp: return EOpEqual;
case EHTokNeOp: return EOpNotEqual;
case EHTokLeftAngle: return EOpLessThan;
case EHTokRightAngle: return EOpGreaterThan;
case EHTokLeOp: return EOpLessThanEqual;
case EHTokGeOp: return EOpGreaterThanEqual;
case EHTokOrOp: return EOpLogicalOr;
case EHTokXorOp: return EOpLogicalXor;
case EHTokAndOp: return EOpLogicalAnd;
default:
return EOpNull;
}
}
// Map parsing tokens that could be unary operations into unary operators.
// These are just the ones that can appear in front of its operand.
TOperator HlslOpMap::preUnary(EHlslTokenClass op)
{
switch (op) {
case EHTokPlus: return EOpAdd; // means no-op, but still a unary op was present
case EHTokDash: return EOpNegative;
case EHTokBang: return EOpLogicalNot;
case EHTokTilde: return EOpBitwiseNot;
case EHTokIncOp: return EOpPreIncrement;
case EHTokDecOp: return EOpPreDecrement;
default: return EOpNull; // means not a pre-unary op
}
}
// Map parsing tokens that could be unary operations into unary operators.
// These are just the ones that can appear behind its operand.
TOperator HlslOpMap::postUnary(EHlslTokenClass op)
{
switch (op) {
case EHTokDot: return EOpIndexDirectStruct;
case EHTokLeftBracket: return EOpIndexIndirect;
case EHTokIncOp: return EOpPostIncrement;
case EHTokDecOp: return EOpPostDecrement;
case EHTokColonColon: return EOpScoping;
default: return EOpNull; // means not a post-unary op
}
}
// Map operators into their level of precedence.
PrecedenceLevel HlslOpMap::precedenceLevel(TOperator op)
{
switch (op) {
case EOpLogicalOr:
return PlLogicalOr;
case EOpLogicalXor:
return PlLogicalXor;
case EOpLogicalAnd:
return PlLogicalAnd;
case EOpInclusiveOr:
return PlBitwiseOr;
case EOpExclusiveOr:
return PlBitwiseXor;
case EOpAnd:
return PlBitwiseAnd;
case EOpEqual:
case EOpNotEqual:
return PlEquality;
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
return PlRelational;
case EOpRightShift:
case EOpLeftShift:
return PlShift;
case EOpAdd:
case EOpSub:
return PlAdd;
case EOpMul:
case EOpDiv:
case EOpMod:
return PlMul;
default:
return PlBad;
}
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslScanContext.cpp | //
// Copyright (C) 2016 Google, Inc.
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// HLSL scanning, leveraging the scanning done by the preprocessor.
//
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include "../Include/Types.h"
#include "../MachineIndependent/SymbolTable.h"
#include "../MachineIndependent/ParseHelper.h"
#include "hlslScanContext.h"
#include "hlslTokens.h"
// preprocessor includes
#include "../MachineIndependent/preprocessor/PpContext.h"
#include "../MachineIndependent/preprocessor/PpTokens.h"
namespace {
struct str_eq
{
bool operator()(const char* lhs, const char* rhs) const
{
return strcmp(lhs, rhs) == 0;
}
};
struct str_hash
{
size_t operator()(const char* str) const
{
// djb2
unsigned long hash = 5381;
int c;
while ((c = *str++) != 0)
hash = ((hash << 5) + hash) + c;
return hash;
}
};
// A single global usable by all threads, by all versions, by all languages.
// After a single process-level initialization, this is read only and thread safe
std::unordered_map<const char*, glslang::EHlslTokenClass, str_hash, str_eq>* KeywordMap = nullptr;
std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = nullptr;
std::unordered_map<const char*, glslang::TBuiltInVariable, str_hash, str_eq>* SemanticMap = nullptr;
};
namespace glslang {
void HlslScanContext::fillInKeywordMap()
{
if (KeywordMap != nullptr) {
// this is really an error, as this should called only once per process
// but, the only risk is if two threads called simultaneously
return;
}
KeywordMap = new std::unordered_map<const char*, EHlslTokenClass, str_hash, str_eq>;
(*KeywordMap)["static"] = EHTokStatic;
(*KeywordMap)["const"] = EHTokConst;
(*KeywordMap)["unorm"] = EHTokUnorm;
(*KeywordMap)["snorm"] = EHTokSNorm;
(*KeywordMap)["extern"] = EHTokExtern;
(*KeywordMap)["uniform"] = EHTokUniform;
(*KeywordMap)["volatile"] = EHTokVolatile;
(*KeywordMap)["precise"] = EHTokPrecise;
(*KeywordMap)["shared"] = EHTokShared;
(*KeywordMap)["groupshared"] = EHTokGroupShared;
(*KeywordMap)["linear"] = EHTokLinear;
(*KeywordMap)["centroid"] = EHTokCentroid;
(*KeywordMap)["nointerpolation"] = EHTokNointerpolation;
(*KeywordMap)["noperspective"] = EHTokNoperspective;
(*KeywordMap)["sample"] = EHTokSample;
(*KeywordMap)["row_major"] = EHTokRowMajor;
(*KeywordMap)["column_major"] = EHTokColumnMajor;
(*KeywordMap)["packoffset"] = EHTokPackOffset;
(*KeywordMap)["in"] = EHTokIn;
(*KeywordMap)["out"] = EHTokOut;
(*KeywordMap)["inout"] = EHTokInOut;
(*KeywordMap)["layout"] = EHTokLayout;
(*KeywordMap)["globallycoherent"] = EHTokGloballyCoherent;
(*KeywordMap)["inline"] = EHTokInline;
(*KeywordMap)["point"] = EHTokPoint;
(*KeywordMap)["line"] = EHTokLine;
(*KeywordMap)["triangle"] = EHTokTriangle;
(*KeywordMap)["lineadj"] = EHTokLineAdj;
(*KeywordMap)["triangleadj"] = EHTokTriangleAdj;
(*KeywordMap)["PointStream"] = EHTokPointStream;
(*KeywordMap)["LineStream"] = EHTokLineStream;
(*KeywordMap)["TriangleStream"] = EHTokTriangleStream;
(*KeywordMap)["InputPatch"] = EHTokInputPatch;
(*KeywordMap)["OutputPatch"] = EHTokOutputPatch;
(*KeywordMap)["Buffer"] = EHTokBuffer;
(*KeywordMap)["vector"] = EHTokVector;
(*KeywordMap)["matrix"] = EHTokMatrix;
(*KeywordMap)["void"] = EHTokVoid;
(*KeywordMap)["string"] = EHTokString;
(*KeywordMap)["bool"] = EHTokBool;
(*KeywordMap)["int"] = EHTokInt;
(*KeywordMap)["uint"] = EHTokUint;
(*KeywordMap)["uint64_t"] = EHTokUint64;
(*KeywordMap)["dword"] = EHTokDword;
(*KeywordMap)["half"] = EHTokHalf;
(*KeywordMap)["float"] = EHTokFloat;
(*KeywordMap)["double"] = EHTokDouble;
(*KeywordMap)["min16float"] = EHTokMin16float;
(*KeywordMap)["min10float"] = EHTokMin10float;
(*KeywordMap)["min16int"] = EHTokMin16int;
(*KeywordMap)["min12int"] = EHTokMin12int;
(*KeywordMap)["min16uint"] = EHTokMin16uint;
(*KeywordMap)["bool1"] = EHTokBool1;
(*KeywordMap)["bool2"] = EHTokBool2;
(*KeywordMap)["bool3"] = EHTokBool3;
(*KeywordMap)["bool4"] = EHTokBool4;
(*KeywordMap)["float1"] = EHTokFloat1;
(*KeywordMap)["float2"] = EHTokFloat2;
(*KeywordMap)["float3"] = EHTokFloat3;
(*KeywordMap)["float4"] = EHTokFloat4;
(*KeywordMap)["int1"] = EHTokInt1;
(*KeywordMap)["int2"] = EHTokInt2;
(*KeywordMap)["int3"] = EHTokInt3;
(*KeywordMap)["int4"] = EHTokInt4;
(*KeywordMap)["double1"] = EHTokDouble1;
(*KeywordMap)["double2"] = EHTokDouble2;
(*KeywordMap)["double3"] = EHTokDouble3;
(*KeywordMap)["double4"] = EHTokDouble4;
(*KeywordMap)["uint1"] = EHTokUint1;
(*KeywordMap)["uint2"] = EHTokUint2;
(*KeywordMap)["uint3"] = EHTokUint3;
(*KeywordMap)["uint4"] = EHTokUint4;
(*KeywordMap)["half1"] = EHTokHalf1;
(*KeywordMap)["half2"] = EHTokHalf2;
(*KeywordMap)["half3"] = EHTokHalf3;
(*KeywordMap)["half4"] = EHTokHalf4;
(*KeywordMap)["min16float1"] = EHTokMin16float1;
(*KeywordMap)["min16float2"] = EHTokMin16float2;
(*KeywordMap)["min16float3"] = EHTokMin16float3;
(*KeywordMap)["min16float4"] = EHTokMin16float4;
(*KeywordMap)["min10float1"] = EHTokMin10float1;
(*KeywordMap)["min10float2"] = EHTokMin10float2;
(*KeywordMap)["min10float3"] = EHTokMin10float3;
(*KeywordMap)["min10float4"] = EHTokMin10float4;
(*KeywordMap)["min16int1"] = EHTokMin16int1;
(*KeywordMap)["min16int2"] = EHTokMin16int2;
(*KeywordMap)["min16int3"] = EHTokMin16int3;
(*KeywordMap)["min16int4"] = EHTokMin16int4;
(*KeywordMap)["min12int1"] = EHTokMin12int1;
(*KeywordMap)["min12int2"] = EHTokMin12int2;
(*KeywordMap)["min12int3"] = EHTokMin12int3;
(*KeywordMap)["min12int4"] = EHTokMin12int4;
(*KeywordMap)["min16uint1"] = EHTokMin16uint1;
(*KeywordMap)["min16uint2"] = EHTokMin16uint2;
(*KeywordMap)["min16uint3"] = EHTokMin16uint3;
(*KeywordMap)["min16uint4"] = EHTokMin16uint4;
(*KeywordMap)["bool1x1"] = EHTokBool1x1;
(*KeywordMap)["bool1x2"] = EHTokBool1x2;
(*KeywordMap)["bool1x3"] = EHTokBool1x3;
(*KeywordMap)["bool1x4"] = EHTokBool1x4;
(*KeywordMap)["bool2x1"] = EHTokBool2x1;
(*KeywordMap)["bool2x2"] = EHTokBool2x2;
(*KeywordMap)["bool2x3"] = EHTokBool2x3;
(*KeywordMap)["bool2x4"] = EHTokBool2x4;
(*KeywordMap)["bool3x1"] = EHTokBool3x1;
(*KeywordMap)["bool3x2"] = EHTokBool3x2;
(*KeywordMap)["bool3x3"] = EHTokBool3x3;
(*KeywordMap)["bool3x4"] = EHTokBool3x4;
(*KeywordMap)["bool4x1"] = EHTokBool4x1;
(*KeywordMap)["bool4x2"] = EHTokBool4x2;
(*KeywordMap)["bool4x3"] = EHTokBool4x3;
(*KeywordMap)["bool4x4"] = EHTokBool4x4;
(*KeywordMap)["int1x1"] = EHTokInt1x1;
(*KeywordMap)["int1x2"] = EHTokInt1x2;
(*KeywordMap)["int1x3"] = EHTokInt1x3;
(*KeywordMap)["int1x4"] = EHTokInt1x4;
(*KeywordMap)["int2x1"] = EHTokInt2x1;
(*KeywordMap)["int2x2"] = EHTokInt2x2;
(*KeywordMap)["int2x3"] = EHTokInt2x3;
(*KeywordMap)["int2x4"] = EHTokInt2x4;
(*KeywordMap)["int3x1"] = EHTokInt3x1;
(*KeywordMap)["int3x2"] = EHTokInt3x2;
(*KeywordMap)["int3x3"] = EHTokInt3x3;
(*KeywordMap)["int3x4"] = EHTokInt3x4;
(*KeywordMap)["int4x1"] = EHTokInt4x1;
(*KeywordMap)["int4x2"] = EHTokInt4x2;
(*KeywordMap)["int4x3"] = EHTokInt4x3;
(*KeywordMap)["int4x4"] = EHTokInt4x4;
(*KeywordMap)["uint1x1"] = EHTokUint1x1;
(*KeywordMap)["uint1x2"] = EHTokUint1x2;
(*KeywordMap)["uint1x3"] = EHTokUint1x3;
(*KeywordMap)["uint1x4"] = EHTokUint1x4;
(*KeywordMap)["uint2x1"] = EHTokUint2x1;
(*KeywordMap)["uint2x2"] = EHTokUint2x2;
(*KeywordMap)["uint2x3"] = EHTokUint2x3;
(*KeywordMap)["uint2x4"] = EHTokUint2x4;
(*KeywordMap)["uint3x1"] = EHTokUint3x1;
(*KeywordMap)["uint3x2"] = EHTokUint3x2;
(*KeywordMap)["uint3x3"] = EHTokUint3x3;
(*KeywordMap)["uint3x4"] = EHTokUint3x4;
(*KeywordMap)["uint4x1"] = EHTokUint4x1;
(*KeywordMap)["uint4x2"] = EHTokUint4x2;
(*KeywordMap)["uint4x3"] = EHTokUint4x3;
(*KeywordMap)["uint4x4"] = EHTokUint4x4;
(*KeywordMap)["bool1x1"] = EHTokBool1x1;
(*KeywordMap)["bool1x2"] = EHTokBool1x2;
(*KeywordMap)["bool1x3"] = EHTokBool1x3;
(*KeywordMap)["bool1x4"] = EHTokBool1x4;
(*KeywordMap)["bool2x1"] = EHTokBool2x1;
(*KeywordMap)["bool2x2"] = EHTokBool2x2;
(*KeywordMap)["bool2x3"] = EHTokBool2x3;
(*KeywordMap)["bool2x4"] = EHTokBool2x4;
(*KeywordMap)["bool3x1"] = EHTokBool3x1;
(*KeywordMap)["bool3x2"] = EHTokBool3x2;
(*KeywordMap)["bool3x3"] = EHTokBool3x3;
(*KeywordMap)["bool3x4"] = EHTokBool3x4;
(*KeywordMap)["bool4x1"] = EHTokBool4x1;
(*KeywordMap)["bool4x2"] = EHTokBool4x2;
(*KeywordMap)["bool4x3"] = EHTokBool4x3;
(*KeywordMap)["bool4x4"] = EHTokBool4x4;
(*KeywordMap)["float1x1"] = EHTokFloat1x1;
(*KeywordMap)["float1x2"] = EHTokFloat1x2;
(*KeywordMap)["float1x3"] = EHTokFloat1x3;
(*KeywordMap)["float1x4"] = EHTokFloat1x4;
(*KeywordMap)["float2x1"] = EHTokFloat2x1;
(*KeywordMap)["float2x2"] = EHTokFloat2x2;
(*KeywordMap)["float2x3"] = EHTokFloat2x3;
(*KeywordMap)["float2x4"] = EHTokFloat2x4;
(*KeywordMap)["float3x1"] = EHTokFloat3x1;
(*KeywordMap)["float3x2"] = EHTokFloat3x2;
(*KeywordMap)["float3x3"] = EHTokFloat3x3;
(*KeywordMap)["float3x4"] = EHTokFloat3x4;
(*KeywordMap)["float4x1"] = EHTokFloat4x1;
(*KeywordMap)["float4x2"] = EHTokFloat4x2;
(*KeywordMap)["float4x3"] = EHTokFloat4x3;
(*KeywordMap)["float4x4"] = EHTokFloat4x4;
(*KeywordMap)["half1x1"] = EHTokHalf1x1;
(*KeywordMap)["half1x2"] = EHTokHalf1x2;
(*KeywordMap)["half1x3"] = EHTokHalf1x3;
(*KeywordMap)["half1x4"] = EHTokHalf1x4;
(*KeywordMap)["half2x1"] = EHTokHalf2x1;
(*KeywordMap)["half2x2"] = EHTokHalf2x2;
(*KeywordMap)["half2x3"] = EHTokHalf2x3;
(*KeywordMap)["half2x4"] = EHTokHalf2x4;
(*KeywordMap)["half3x1"] = EHTokHalf3x1;
(*KeywordMap)["half3x2"] = EHTokHalf3x2;
(*KeywordMap)["half3x3"] = EHTokHalf3x3;
(*KeywordMap)["half3x4"] = EHTokHalf3x4;
(*KeywordMap)["half4x1"] = EHTokHalf4x1;
(*KeywordMap)["half4x2"] = EHTokHalf4x2;
(*KeywordMap)["half4x3"] = EHTokHalf4x3;
(*KeywordMap)["half4x4"] = EHTokHalf4x4;
(*KeywordMap)["double1x1"] = EHTokDouble1x1;
(*KeywordMap)["double1x2"] = EHTokDouble1x2;
(*KeywordMap)["double1x3"] = EHTokDouble1x3;
(*KeywordMap)["double1x4"] = EHTokDouble1x4;
(*KeywordMap)["double2x1"] = EHTokDouble2x1;
(*KeywordMap)["double2x2"] = EHTokDouble2x2;
(*KeywordMap)["double2x3"] = EHTokDouble2x3;
(*KeywordMap)["double2x4"] = EHTokDouble2x4;
(*KeywordMap)["double3x1"] = EHTokDouble3x1;
(*KeywordMap)["double3x2"] = EHTokDouble3x2;
(*KeywordMap)["double3x3"] = EHTokDouble3x3;
(*KeywordMap)["double3x4"] = EHTokDouble3x4;
(*KeywordMap)["double4x1"] = EHTokDouble4x1;
(*KeywordMap)["double4x2"] = EHTokDouble4x2;
(*KeywordMap)["double4x3"] = EHTokDouble4x3;
(*KeywordMap)["double4x4"] = EHTokDouble4x4;
(*KeywordMap)["min16float1x1"] = EHTokMin16float1x1;
(*KeywordMap)["min16float1x2"] = EHTokMin16float1x2;
(*KeywordMap)["min16float1x3"] = EHTokMin16float1x3;
(*KeywordMap)["min16float1x4"] = EHTokMin16float1x4;
(*KeywordMap)["min16float2x1"] = EHTokMin16float2x1;
(*KeywordMap)["min16float2x2"] = EHTokMin16float2x2;
(*KeywordMap)["min16float2x3"] = EHTokMin16float2x3;
(*KeywordMap)["min16float2x4"] = EHTokMin16float2x4;
(*KeywordMap)["min16float3x1"] = EHTokMin16float3x1;
(*KeywordMap)["min16float3x2"] = EHTokMin16float3x2;
(*KeywordMap)["min16float3x3"] = EHTokMin16float3x3;
(*KeywordMap)["min16float3x4"] = EHTokMin16float3x4;
(*KeywordMap)["min16float4x1"] = EHTokMin16float4x1;
(*KeywordMap)["min16float4x2"] = EHTokMin16float4x2;
(*KeywordMap)["min16float4x3"] = EHTokMin16float4x3;
(*KeywordMap)["min16float4x4"] = EHTokMin16float4x4;
(*KeywordMap)["min10float1x1"] = EHTokMin10float1x1;
(*KeywordMap)["min10float1x2"] = EHTokMin10float1x2;
(*KeywordMap)["min10float1x3"] = EHTokMin10float1x3;
(*KeywordMap)["min10float1x4"] = EHTokMin10float1x4;
(*KeywordMap)["min10float2x1"] = EHTokMin10float2x1;
(*KeywordMap)["min10float2x2"] = EHTokMin10float2x2;
(*KeywordMap)["min10float2x3"] = EHTokMin10float2x3;
(*KeywordMap)["min10float2x4"] = EHTokMin10float2x4;
(*KeywordMap)["min10float3x1"] = EHTokMin10float3x1;
(*KeywordMap)["min10float3x2"] = EHTokMin10float3x2;
(*KeywordMap)["min10float3x3"] = EHTokMin10float3x3;
(*KeywordMap)["min10float3x4"] = EHTokMin10float3x4;
(*KeywordMap)["min10float4x1"] = EHTokMin10float4x1;
(*KeywordMap)["min10float4x2"] = EHTokMin10float4x2;
(*KeywordMap)["min10float4x3"] = EHTokMin10float4x3;
(*KeywordMap)["min10float4x4"] = EHTokMin10float4x4;
(*KeywordMap)["min16int1x1"] = EHTokMin16int1x1;
(*KeywordMap)["min16int1x2"] = EHTokMin16int1x2;
(*KeywordMap)["min16int1x3"] = EHTokMin16int1x3;
(*KeywordMap)["min16int1x4"] = EHTokMin16int1x4;
(*KeywordMap)["min16int2x1"] = EHTokMin16int2x1;
(*KeywordMap)["min16int2x2"] = EHTokMin16int2x2;
(*KeywordMap)["min16int2x3"] = EHTokMin16int2x3;
(*KeywordMap)["min16int2x4"] = EHTokMin16int2x4;
(*KeywordMap)["min16int3x1"] = EHTokMin16int3x1;
(*KeywordMap)["min16int3x2"] = EHTokMin16int3x2;
(*KeywordMap)["min16int3x3"] = EHTokMin16int3x3;
(*KeywordMap)["min16int3x4"] = EHTokMin16int3x4;
(*KeywordMap)["min16int4x1"] = EHTokMin16int4x1;
(*KeywordMap)["min16int4x2"] = EHTokMin16int4x2;
(*KeywordMap)["min16int4x3"] = EHTokMin16int4x3;
(*KeywordMap)["min16int4x4"] = EHTokMin16int4x4;
(*KeywordMap)["min12int1x1"] = EHTokMin12int1x1;
(*KeywordMap)["min12int1x2"] = EHTokMin12int1x2;
(*KeywordMap)["min12int1x3"] = EHTokMin12int1x3;
(*KeywordMap)["min12int1x4"] = EHTokMin12int1x4;
(*KeywordMap)["min12int2x1"] = EHTokMin12int2x1;
(*KeywordMap)["min12int2x2"] = EHTokMin12int2x2;
(*KeywordMap)["min12int2x3"] = EHTokMin12int2x3;
(*KeywordMap)["min12int2x4"] = EHTokMin12int2x4;
(*KeywordMap)["min12int3x1"] = EHTokMin12int3x1;
(*KeywordMap)["min12int3x2"] = EHTokMin12int3x2;
(*KeywordMap)["min12int3x3"] = EHTokMin12int3x3;
(*KeywordMap)["min12int3x4"] = EHTokMin12int3x4;
(*KeywordMap)["min12int4x1"] = EHTokMin12int4x1;
(*KeywordMap)["min12int4x2"] = EHTokMin12int4x2;
(*KeywordMap)["min12int4x3"] = EHTokMin12int4x3;
(*KeywordMap)["min12int4x4"] = EHTokMin12int4x4;
(*KeywordMap)["min16uint1x1"] = EHTokMin16uint1x1;
(*KeywordMap)["min16uint1x2"] = EHTokMin16uint1x2;
(*KeywordMap)["min16uint1x3"] = EHTokMin16uint1x3;
(*KeywordMap)["min16uint1x4"] = EHTokMin16uint1x4;
(*KeywordMap)["min16uint2x1"] = EHTokMin16uint2x1;
(*KeywordMap)["min16uint2x2"] = EHTokMin16uint2x2;
(*KeywordMap)["min16uint2x3"] = EHTokMin16uint2x3;
(*KeywordMap)["min16uint2x4"] = EHTokMin16uint2x4;
(*KeywordMap)["min16uint3x1"] = EHTokMin16uint3x1;
(*KeywordMap)["min16uint3x2"] = EHTokMin16uint3x2;
(*KeywordMap)["min16uint3x3"] = EHTokMin16uint3x3;
(*KeywordMap)["min16uint3x4"] = EHTokMin16uint3x4;
(*KeywordMap)["min16uint4x1"] = EHTokMin16uint4x1;
(*KeywordMap)["min16uint4x2"] = EHTokMin16uint4x2;
(*KeywordMap)["min16uint4x3"] = EHTokMin16uint4x3;
(*KeywordMap)["min16uint4x4"] = EHTokMin16uint4x4;
(*KeywordMap)["sampler"] = EHTokSampler;
(*KeywordMap)["sampler1D"] = EHTokSampler1d;
(*KeywordMap)["sampler2D"] = EHTokSampler2d;
(*KeywordMap)["sampler3D"] = EHTokSampler3d;
(*KeywordMap)["samplerCUBE"] = EHTokSamplerCube;
(*KeywordMap)["sampler_state"] = EHTokSamplerState;
(*KeywordMap)["SamplerState"] = EHTokSamplerState;
(*KeywordMap)["SamplerComparisonState"] = EHTokSamplerComparisonState;
(*KeywordMap)["texture"] = EHTokTexture;
(*KeywordMap)["Texture1D"] = EHTokTexture1d;
(*KeywordMap)["Texture1DArray"] = EHTokTexture1darray;
(*KeywordMap)["Texture2D"] = EHTokTexture2d;
(*KeywordMap)["Texture2DArray"] = EHTokTexture2darray;
(*KeywordMap)["Texture3D"] = EHTokTexture3d;
(*KeywordMap)["TextureCube"] = EHTokTextureCube;
(*KeywordMap)["TextureCubeArray"] = EHTokTextureCubearray;
(*KeywordMap)["Texture2DMS"] = EHTokTexture2DMS;
(*KeywordMap)["Texture2DMSArray"] = EHTokTexture2DMSarray;
(*KeywordMap)["RWTexture1D"] = EHTokRWTexture1d;
(*KeywordMap)["RWTexture1DArray"] = EHTokRWTexture1darray;
(*KeywordMap)["RWTexture2D"] = EHTokRWTexture2d;
(*KeywordMap)["RWTexture2DArray"] = EHTokRWTexture2darray;
(*KeywordMap)["RWTexture3D"] = EHTokRWTexture3d;
(*KeywordMap)["RWBuffer"] = EHTokRWBuffer;
(*KeywordMap)["SubpassInput"] = EHTokSubpassInput;
(*KeywordMap)["SubpassInputMS"] = EHTokSubpassInputMS;
(*KeywordMap)["AppendStructuredBuffer"] = EHTokAppendStructuredBuffer;
(*KeywordMap)["ByteAddressBuffer"] = EHTokByteAddressBuffer;
(*KeywordMap)["ConsumeStructuredBuffer"] = EHTokConsumeStructuredBuffer;
(*KeywordMap)["RWByteAddressBuffer"] = EHTokRWByteAddressBuffer;
(*KeywordMap)["RWStructuredBuffer"] = EHTokRWStructuredBuffer;
(*KeywordMap)["StructuredBuffer"] = EHTokStructuredBuffer;
(*KeywordMap)["TextureBuffer"] = EHTokTextureBuffer;
(*KeywordMap)["class"] = EHTokClass;
(*KeywordMap)["struct"] = EHTokStruct;
(*KeywordMap)["cbuffer"] = EHTokCBuffer;
(*KeywordMap)["ConstantBuffer"] = EHTokConstantBuffer;
(*KeywordMap)["tbuffer"] = EHTokTBuffer;
(*KeywordMap)["typedef"] = EHTokTypedef;
(*KeywordMap)["this"] = EHTokThis;
(*KeywordMap)["namespace"] = EHTokNamespace;
(*KeywordMap)["true"] = EHTokBoolConstant;
(*KeywordMap)["false"] = EHTokBoolConstant;
(*KeywordMap)["for"] = EHTokFor;
(*KeywordMap)["do"] = EHTokDo;
(*KeywordMap)["while"] = EHTokWhile;
(*KeywordMap)["break"] = EHTokBreak;
(*KeywordMap)["continue"] = EHTokContinue;
(*KeywordMap)["if"] = EHTokIf;
(*KeywordMap)["else"] = EHTokElse;
(*KeywordMap)["discard"] = EHTokDiscard;
(*KeywordMap)["return"] = EHTokReturn;
(*KeywordMap)["switch"] = EHTokSwitch;
(*KeywordMap)["case"] = EHTokCase;
(*KeywordMap)["default"] = EHTokDefault;
// TODO: get correct set here
ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
ReservedSet->insert("auto");
ReservedSet->insert("catch");
ReservedSet->insert("char");
ReservedSet->insert("const_cast");
ReservedSet->insert("enum");
ReservedSet->insert("explicit");
ReservedSet->insert("friend");
ReservedSet->insert("goto");
ReservedSet->insert("long");
ReservedSet->insert("mutable");
ReservedSet->insert("new");
ReservedSet->insert("operator");
ReservedSet->insert("private");
ReservedSet->insert("protected");
ReservedSet->insert("public");
ReservedSet->insert("reinterpret_cast");
ReservedSet->insert("short");
ReservedSet->insert("signed");
ReservedSet->insert("sizeof");
ReservedSet->insert("static_cast");
ReservedSet->insert("template");
ReservedSet->insert("throw");
ReservedSet->insert("try");
ReservedSet->insert("typename");
ReservedSet->insert("union");
ReservedSet->insert("unsigned");
ReservedSet->insert("using");
ReservedSet->insert("virtual");
SemanticMap = new std::unordered_map<const char*, glslang::TBuiltInVariable, str_hash, str_eq>;
// in DX9, all outputs had to have a semantic associated with them, that was either consumed
// by the system or was a specific register assignment
// in DX10+, only semantics with the SV_ prefix have any meaning beyond decoration
// Fxc will only accept DX9 style semantics in compat mode
// Also, in DX10 if a SV value is present as the input of a stage, but isn't appropriate for that
// stage, it would just be ignored as it is likely there as part of an output struct from one stage
// to the next
bool bParseDX9 = false;
if (bParseDX9) {
(*SemanticMap)["PSIZE"] = EbvPointSize;
(*SemanticMap)["FOG"] = EbvFogFragCoord;
(*SemanticMap)["DEPTH"] = EbvFragDepth;
(*SemanticMap)["VFACE"] = EbvFace;
(*SemanticMap)["VPOS"] = EbvFragCoord;
}
(*SemanticMap)["SV_POSITION"] = EbvPosition;
(*SemanticMap)["SV_VERTEXID"] = EbvVertexIndex;
(*SemanticMap)["SV_VIEWPORTARRAYINDEX"] = EbvViewportIndex;
(*SemanticMap)["SV_TESSFACTOR"] = EbvTessLevelOuter;
(*SemanticMap)["SV_SAMPLEINDEX"] = EbvSampleId;
(*SemanticMap)["SV_RENDERTARGETARRAYINDEX"] = EbvLayer;
(*SemanticMap)["SV_PRIMITIVEID"] = EbvPrimitiveId;
(*SemanticMap)["SV_OUTPUTCONTROLPOINTID"] = EbvInvocationId;
(*SemanticMap)["SV_ISFRONTFACE"] = EbvFace;
(*SemanticMap)["SV_VIEWID"] = EbvViewIndex;
(*SemanticMap)["SV_INSTANCEID"] = EbvInstanceIndex;
(*SemanticMap)["SV_INSIDETESSFACTOR"] = EbvTessLevelInner;
(*SemanticMap)["SV_GSINSTANCEID"] = EbvInvocationId;
(*SemanticMap)["SV_DISPATCHTHREADID"] = EbvGlobalInvocationId;
(*SemanticMap)["SV_GROUPTHREADID"] = EbvLocalInvocationId;
(*SemanticMap)["SV_GROUPINDEX"] = EbvLocalInvocationIndex;
(*SemanticMap)["SV_GROUPID"] = EbvWorkGroupId;
(*SemanticMap)["SV_DOMAINLOCATION"] = EbvTessCoord;
(*SemanticMap)["SV_DEPTH"] = EbvFragDepth;
(*SemanticMap)["SV_COVERAGE"] = EbvSampleMask;
(*SemanticMap)["SV_DEPTHGREATEREQUAL"] = EbvFragDepthGreater;
(*SemanticMap)["SV_DEPTHLESSEQUAL"] = EbvFragDepthLesser;
(*SemanticMap)["SV_STENCILREF"] = EbvFragStencilRef;
}
void HlslScanContext::deleteKeywordMap()
{
delete KeywordMap;
KeywordMap = nullptr;
delete ReservedSet;
ReservedSet = nullptr;
delete SemanticMap;
SemanticMap = nullptr;
}
// Wrapper for tokenizeClass() to get everything inside the token.
void HlslScanContext::tokenize(HlslToken& token)
{
EHlslTokenClass tokenClass = tokenizeClass(token);
token.tokenClass = tokenClass;
}
glslang::TBuiltInVariable HlslScanContext::mapSemantic(const char* upperCase)
{
auto it = SemanticMap->find(upperCase);
if (it != SemanticMap->end())
return it->second;
else
return glslang::EbvNone;
}
//
// Fill in token information for the next token, except for the token class.
// Returns the enum value of the token class of the next token found.
// Return 0 (EndOfTokens) on end of input.
//
EHlslTokenClass HlslScanContext::tokenizeClass(HlslToken& token)
{
do {
parserToken = &token;
TPpToken ppToken;
int token = ppContext.tokenize(ppToken);
if (token == EndOfInput)
return EHTokNone;
tokenText = ppToken.name;
loc = ppToken.loc;
parserToken->loc = loc;
switch (token) {
case ';': return EHTokSemicolon;
case ',': return EHTokComma;
case ':': return EHTokColon;
case '=': return EHTokAssign;
case '(': return EHTokLeftParen;
case ')': return EHTokRightParen;
case '.': return EHTokDot;
case '!': return EHTokBang;
case '-': return EHTokDash;
case '~': return EHTokTilde;
case '+': return EHTokPlus;
case '*': return EHTokStar;
case '/': return EHTokSlash;
case '%': return EHTokPercent;
case '<': return EHTokLeftAngle;
case '>': return EHTokRightAngle;
case '|': return EHTokVerticalBar;
case '^': return EHTokCaret;
case '&': return EHTokAmpersand;
case '?': return EHTokQuestion;
case '[': return EHTokLeftBracket;
case ']': return EHTokRightBracket;
case '{': return EHTokLeftBrace;
case '}': return EHTokRightBrace;
case '\\':
parseContext.error(loc, "illegal use of escape character", "\\", "");
break;
case PPAtomAddAssign: return EHTokAddAssign;
case PPAtomSubAssign: return EHTokSubAssign;
case PPAtomMulAssign: return EHTokMulAssign;
case PPAtomDivAssign: return EHTokDivAssign;
case PPAtomModAssign: return EHTokModAssign;
case PpAtomRight: return EHTokRightOp;
case PpAtomLeft: return EHTokLeftOp;
case PpAtomRightAssign: return EHTokRightAssign;
case PpAtomLeftAssign: return EHTokLeftAssign;
case PpAtomAndAssign: return EHTokAndAssign;
case PpAtomOrAssign: return EHTokOrAssign;
case PpAtomXorAssign: return EHTokXorAssign;
case PpAtomAnd: return EHTokAndOp;
case PpAtomOr: return EHTokOrOp;
case PpAtomXor: return EHTokXorOp;
case PpAtomEQ: return EHTokEqOp;
case PpAtomGE: return EHTokGeOp;
case PpAtomNE: return EHTokNeOp;
case PpAtomLE: return EHTokLeOp;
case PpAtomDecrement: return EHTokDecOp;
case PpAtomIncrement: return EHTokIncOp;
case PpAtomColonColon: return EHTokColonColon;
case PpAtomConstInt: parserToken->i = ppToken.ival; return EHTokIntConstant;
case PpAtomConstUint: parserToken->i = ppToken.ival; return EHTokUintConstant;
case PpAtomConstFloat16: parserToken->d = ppToken.dval; return EHTokFloat16Constant;
case PpAtomConstFloat: parserToken->d = ppToken.dval; return EHTokFloatConstant;
case PpAtomConstDouble: parserToken->d = ppToken.dval; return EHTokDoubleConstant;
case PpAtomIdentifier:
{
EHlslTokenClass token = tokenizeIdentifier();
return token;
}
case PpAtomConstString: {
parserToken->string = NewPoolTString(tokenText);
return EHTokStringConstant;
}
case EndOfInput: return EHTokNone;
default:
if (token < PpAtomMaxSingle) {
char buf[2];
buf[0] = (char)token;
buf[1] = 0;
parseContext.error(loc, "unexpected token", buf, "");
} else if (tokenText[0] != 0)
parseContext.error(loc, "unexpected token", tokenText, "");
else
parseContext.error(loc, "unexpected token", "", "");
break;
}
} while (true);
}
EHlslTokenClass HlslScanContext::tokenizeIdentifier()
{
if (ReservedSet->find(tokenText) != ReservedSet->end())
return reservedWord();
auto it = KeywordMap->find(tokenText);
if (it == KeywordMap->end()) {
// Should have an identifier of some sort
return identifierOrType();
}
keyword = it->second;
switch (keyword) {
// qualifiers
case EHTokStatic:
case EHTokConst:
case EHTokSNorm:
case EHTokUnorm:
case EHTokExtern:
case EHTokUniform:
case EHTokVolatile:
case EHTokShared:
case EHTokGroupShared:
case EHTokLinear:
case EHTokCentroid:
case EHTokNointerpolation:
case EHTokNoperspective:
case EHTokSample:
case EHTokRowMajor:
case EHTokColumnMajor:
case EHTokPackOffset:
case EHTokIn:
case EHTokOut:
case EHTokInOut:
case EHTokPrecise:
case EHTokLayout:
case EHTokGloballyCoherent:
case EHTokInline:
return keyword;
// primitive types
case EHTokPoint:
case EHTokLine:
case EHTokTriangle:
case EHTokLineAdj:
case EHTokTriangleAdj:
return keyword;
// stream out types
case EHTokPointStream:
case EHTokLineStream:
case EHTokTriangleStream:
return keyword;
// Tessellation patches
case EHTokInputPatch:
case EHTokOutputPatch:
return keyword;
case EHTokBuffer:
case EHTokVector:
case EHTokMatrix:
return keyword;
// scalar types
case EHTokVoid:
case EHTokString:
case EHTokBool:
case EHTokInt:
case EHTokUint:
case EHTokUint64:
case EHTokDword:
case EHTokHalf:
case EHTokFloat:
case EHTokDouble:
case EHTokMin16float:
case EHTokMin10float:
case EHTokMin16int:
case EHTokMin12int:
case EHTokMin16uint:
// vector types
case EHTokBool1:
case EHTokBool2:
case EHTokBool3:
case EHTokBool4:
case EHTokFloat1:
case EHTokFloat2:
case EHTokFloat3:
case EHTokFloat4:
case EHTokInt1:
case EHTokInt2:
case EHTokInt3:
case EHTokInt4:
case EHTokDouble1:
case EHTokDouble2:
case EHTokDouble3:
case EHTokDouble4:
case EHTokUint1:
case EHTokUint2:
case EHTokUint3:
case EHTokUint4:
case EHTokHalf1:
case EHTokHalf2:
case EHTokHalf3:
case EHTokHalf4:
case EHTokMin16float1:
case EHTokMin16float2:
case EHTokMin16float3:
case EHTokMin16float4:
case EHTokMin10float1:
case EHTokMin10float2:
case EHTokMin10float3:
case EHTokMin10float4:
case EHTokMin16int1:
case EHTokMin16int2:
case EHTokMin16int3:
case EHTokMin16int4:
case EHTokMin12int1:
case EHTokMin12int2:
case EHTokMin12int3:
case EHTokMin12int4:
case EHTokMin16uint1:
case EHTokMin16uint2:
case EHTokMin16uint3:
case EHTokMin16uint4:
// matrix types
case EHTokBool1x1:
case EHTokBool1x2:
case EHTokBool1x3:
case EHTokBool1x4:
case EHTokBool2x1:
case EHTokBool2x2:
case EHTokBool2x3:
case EHTokBool2x4:
case EHTokBool3x1:
case EHTokBool3x2:
case EHTokBool3x3:
case EHTokBool3x4:
case EHTokBool4x1:
case EHTokBool4x2:
case EHTokBool4x3:
case EHTokBool4x4:
case EHTokInt1x1:
case EHTokInt1x2:
case EHTokInt1x3:
case EHTokInt1x4:
case EHTokInt2x1:
case EHTokInt2x2:
case EHTokInt2x3:
case EHTokInt2x4:
case EHTokInt3x1:
case EHTokInt3x2:
case EHTokInt3x3:
case EHTokInt3x4:
case EHTokInt4x1:
case EHTokInt4x2:
case EHTokInt4x3:
case EHTokInt4x4:
case EHTokUint1x1:
case EHTokUint1x2:
case EHTokUint1x3:
case EHTokUint1x4:
case EHTokUint2x1:
case EHTokUint2x2:
case EHTokUint2x3:
case EHTokUint2x4:
case EHTokUint3x1:
case EHTokUint3x2:
case EHTokUint3x3:
case EHTokUint3x4:
case EHTokUint4x1:
case EHTokUint4x2:
case EHTokUint4x3:
case EHTokUint4x4:
case EHTokFloat1x1:
case EHTokFloat1x2:
case EHTokFloat1x3:
case EHTokFloat1x4:
case EHTokFloat2x1:
case EHTokFloat2x2:
case EHTokFloat2x3:
case EHTokFloat2x4:
case EHTokFloat3x1:
case EHTokFloat3x2:
case EHTokFloat3x3:
case EHTokFloat3x4:
case EHTokFloat4x1:
case EHTokFloat4x2:
case EHTokFloat4x3:
case EHTokFloat4x4:
case EHTokHalf1x1:
case EHTokHalf1x2:
case EHTokHalf1x3:
case EHTokHalf1x4:
case EHTokHalf2x1:
case EHTokHalf2x2:
case EHTokHalf2x3:
case EHTokHalf2x4:
case EHTokHalf3x1:
case EHTokHalf3x2:
case EHTokHalf3x3:
case EHTokHalf3x4:
case EHTokHalf4x1:
case EHTokHalf4x2:
case EHTokHalf4x3:
case EHTokHalf4x4:
case EHTokDouble1x1:
case EHTokDouble1x2:
case EHTokDouble1x3:
case EHTokDouble1x4:
case EHTokDouble2x1:
case EHTokDouble2x2:
case EHTokDouble2x3:
case EHTokDouble2x4:
case EHTokDouble3x1:
case EHTokDouble3x2:
case EHTokDouble3x3:
case EHTokDouble3x4:
case EHTokDouble4x1:
case EHTokDouble4x2:
case EHTokDouble4x3:
case EHTokDouble4x4:
case EHTokMin16float1x1:
case EHTokMin16float1x2:
case EHTokMin16float1x3:
case EHTokMin16float1x4:
case EHTokMin16float2x1:
case EHTokMin16float2x2:
case EHTokMin16float2x3:
case EHTokMin16float2x4:
case EHTokMin16float3x1:
case EHTokMin16float3x2:
case EHTokMin16float3x3:
case EHTokMin16float3x4:
case EHTokMin16float4x1:
case EHTokMin16float4x2:
case EHTokMin16float4x3:
case EHTokMin16float4x4:
case EHTokMin10float1x1:
case EHTokMin10float1x2:
case EHTokMin10float1x3:
case EHTokMin10float1x4:
case EHTokMin10float2x1:
case EHTokMin10float2x2:
case EHTokMin10float2x3:
case EHTokMin10float2x4:
case EHTokMin10float3x1:
case EHTokMin10float3x2:
case EHTokMin10float3x3:
case EHTokMin10float3x4:
case EHTokMin10float4x1:
case EHTokMin10float4x2:
case EHTokMin10float4x3:
case EHTokMin10float4x4:
case EHTokMin16int1x1:
case EHTokMin16int1x2:
case EHTokMin16int1x3:
case EHTokMin16int1x4:
case EHTokMin16int2x1:
case EHTokMin16int2x2:
case EHTokMin16int2x3:
case EHTokMin16int2x4:
case EHTokMin16int3x1:
case EHTokMin16int3x2:
case EHTokMin16int3x3:
case EHTokMin16int3x4:
case EHTokMin16int4x1:
case EHTokMin16int4x2:
case EHTokMin16int4x3:
case EHTokMin16int4x4:
case EHTokMin12int1x1:
case EHTokMin12int1x2:
case EHTokMin12int1x3:
case EHTokMin12int1x4:
case EHTokMin12int2x1:
case EHTokMin12int2x2:
case EHTokMin12int2x3:
case EHTokMin12int2x4:
case EHTokMin12int3x1:
case EHTokMin12int3x2:
case EHTokMin12int3x3:
case EHTokMin12int3x4:
case EHTokMin12int4x1:
case EHTokMin12int4x2:
case EHTokMin12int4x3:
case EHTokMin12int4x4:
case EHTokMin16uint1x1:
case EHTokMin16uint1x2:
case EHTokMin16uint1x3:
case EHTokMin16uint1x4:
case EHTokMin16uint2x1:
case EHTokMin16uint2x2:
case EHTokMin16uint2x3:
case EHTokMin16uint2x4:
case EHTokMin16uint3x1:
case EHTokMin16uint3x2:
case EHTokMin16uint3x3:
case EHTokMin16uint3x4:
case EHTokMin16uint4x1:
case EHTokMin16uint4x2:
case EHTokMin16uint4x3:
case EHTokMin16uint4x4:
return keyword;
// texturing types
case EHTokSampler:
case EHTokSampler1d:
case EHTokSampler2d:
case EHTokSampler3d:
case EHTokSamplerCube:
case EHTokSamplerState:
case EHTokSamplerComparisonState:
case EHTokTexture:
case EHTokTexture1d:
case EHTokTexture1darray:
case EHTokTexture2d:
case EHTokTexture2darray:
case EHTokTexture3d:
case EHTokTextureCube:
case EHTokTextureCubearray:
case EHTokTexture2DMS:
case EHTokTexture2DMSarray:
case EHTokRWTexture1d:
case EHTokRWTexture1darray:
case EHTokRWTexture2d:
case EHTokRWTexture2darray:
case EHTokRWTexture3d:
case EHTokRWBuffer:
case EHTokAppendStructuredBuffer:
case EHTokByteAddressBuffer:
case EHTokConsumeStructuredBuffer:
case EHTokRWByteAddressBuffer:
case EHTokRWStructuredBuffer:
case EHTokStructuredBuffer:
case EHTokTextureBuffer:
case EHTokSubpassInput:
case EHTokSubpassInputMS:
return keyword;
// variable, user type, ...
case EHTokClass:
case EHTokStruct:
case EHTokTypedef:
case EHTokCBuffer:
case EHTokConstantBuffer:
case EHTokTBuffer:
case EHTokThis:
case EHTokNamespace:
return keyword;
case EHTokBoolConstant:
if (strcmp("true", tokenText) == 0)
parserToken->b = true;
else
parserToken->b = false;
return keyword;
// control flow
case EHTokFor:
case EHTokDo:
case EHTokWhile:
case EHTokBreak:
case EHTokContinue:
case EHTokIf:
case EHTokElse:
case EHTokDiscard:
case EHTokReturn:
case EHTokCase:
case EHTokSwitch:
case EHTokDefault:
return keyword;
default:
parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
return EHTokNone;
}
}
EHlslTokenClass HlslScanContext::identifierOrType()
{
parserToken->string = NewPoolTString(tokenText);
return EHTokIdentifier;
}
// Give an error for use of a reserved symbol.
// However, allow built-in declarations to use reserved words, to allow
// extension support before the extension is enabled.
EHlslTokenClass HlslScanContext::reservedWord()
{
if (! parseContext.symbolTable.atBuiltInLevel())
parseContext.error(loc, "Reserved word.", tokenText, "", "");
return EHTokNone;
}
} // end namespace glslang
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/HLSL/hlslTokenStream.h | //
// Copyright (C) 2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google, Inc., nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef HLSLTOKENSTREAM_H_
#define HLSLTOKENSTREAM_H_
#include "hlslScanContext.h"
namespace glslang {
class HlslTokenStream {
public:
explicit HlslTokenStream(HlslScanContext& scanner)
: scanner(scanner), preTokenStackSize(0), tokenBufferPos(0) { }
virtual ~HlslTokenStream() { }
public:
void advanceToken();
void recedeToken();
bool acceptTokenClass(EHlslTokenClass);
EHlslTokenClass peek() const;
bool peekTokenClass(EHlslTokenClass) const;
glslang::TBuiltInVariable mapSemantic(const char* upperCase) { return scanner.mapSemantic(upperCase); }
void pushTokenStream(const TVector<HlslToken>* tokens);
void popTokenStream();
protected:
HlslToken token; // the token we are currently looking at, but have not yet accepted
private:
HlslTokenStream();
HlslTokenStream& operator=(const HlslTokenStream&);
HlslScanContext& scanner; // lexical scanner, to get next token from source file
TVector<const TVector<HlslToken>*> tokenStreamStack; // for getting the next token from an existing vector of tokens
TVector<int> tokenPosition;
TVector<HlslToken> currentTokenStack;
// This is the number of tokens we can recedeToken() over.
static const int tokenBufferSize = 2;
// Previously scanned tokens, returned for future advances,
// so logically in front of the token stream.
// Is logically a stack; needs last in last out semantics.
// Currently implemented as a stack of size 2.
HlslToken preTokenStack[tokenBufferSize];
int preTokenStackSize;
void pushPreToken(const HlslToken&);
HlslToken popPreToken();
// Previously scanned tokens, not yet returned for future advances,
// but available for that.
// Is logically a fifo for normal advances, and a stack for recession.
// Currently implemented with an intrinsic size of 2.
HlslToken tokenBuffer[tokenBufferSize];
int tokenBufferPos;
void pushTokenBuffer(const HlslToken&);
HlslToken popTokenBuffer();
};
} // end namespace glslang
#endif // HLSLTOKENSTREAM_H_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/GenericCodeGen/Link.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//
// The top level algorithms for linking multiple
// shaders together.
//
#include "../Include/Common.h"
#include "../Include/ShHandle.h"
//
// Actual link object, derived from the shader handle base classes.
//
class TGenericLinker : public TLinker {
public:
TGenericLinker(EShExecutable e) : TLinker(e, infoSink) {}
bool link(TCompilerList&, TUniformMap*) { return true; }
void getAttributeBindings(ShBindingTable const **) const { }
TInfoSink infoSink;
};
//
// The internal view of a uniform/float object exchanged with the driver.
//
class TUniformLinkedMap : public TUniformMap {
public:
TUniformLinkedMap() { }
virtual int getLocation(const char*) { return 0; }
};
TShHandleBase* ConstructLinker(EShExecutable executable, int) { return new TGenericLinker(executable); }
void DeleteLinker(TShHandleBase* linker)
{
delete linker;
}
TUniformMap* ConstructUniformMap()
{
return new TUniformLinkedMap();
}
void DeleteUniformMap(TUniformMap* map)
{
delete map;
}
TShHandleBase* ConstructBindings()
{
return nullptr;
}
void DeleteBindingList(TShHandleBase* bindingList)
{
delete bindingList;
}
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/GenericCodeGen/CodeGen.cpp | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "../Include/Common.h"
#include "../Include/ShHandle.h"
#include "../MachineIndependent/Versions.h"
//
// Here is where real machine specific high-level data would be defined.
//
class TGenericCompiler : public TCompiler {
public:
TGenericCompiler(EShLanguage l) : TCompiler(l, infoSink) {}
virtual bool compile(TIntermNode* root, int version = 0, EProfile profile = ENoProfile);
TInfoSink infoSink;
};
//
// This function must be provided to create the actual
// compile object used by higher level code. It returns
// a subclass of TCompiler.
//
TCompiler* ConstructCompiler(EShLanguage language, int) { return new TGenericCompiler(language); }
//
// Delete the compiler made by ConstructCompiler
//
void DeleteCompiler(TCompiler* compiler)
{
delete compiler;
}
//
// Generate code from the given parse tree
//
bool TGenericCompiler::compile(TIntermNode* /*root*/, int /*version*/, EProfile /*profile*/)
{
haveValidObjectCode = true;
return haveValidObjectCode;
}
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Public/ResourceLimits.h | //
// Copyright (C) 2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#ifndef _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
#define _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
#include <string>
#include "../Include/ResourceLimits.h"
// Return pointer to user-writable Resource to pass through API in
// future-proof way.
extern TBuiltInResource* GetResources();
// These are the default resources for TBuiltInResources, used for both
// - parsing this string for the case where the user didn't supply one,
// - dumping out a template for user construction of a config file.
extern const TBuiltInResource* GetDefaultResources();
// Returns the DefaultTBuiltInResource as a human-readable string.
std::string GetDefaultTBuiltInResourceString();
// Decodes the resource limits from |config| to |resources|.
void DecodeResourceLimits(TBuiltInResource* resources, char* config);
#endif // _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Public/resource_limits_c.h | /**
BSD 2-Clause License
Copyright (c) 2020, Travis Fort
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
#ifndef _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
#define _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
#include "../Include/glslang_c_interface.h"
#ifdef __cplusplus
extern "C" {
#endif
// Returns a struct that can be use to create custom resource values.
glslang_resource_t* glslang_resource(void);
// These are the default resources for TBuiltInResources, used for both
// - parsing this string for the case where the user didn't supply one,
// - dumping out a template for user construction of a config file.
const glslang_resource_t* glslang_default_resource(void);
// Returns the DefaultTBuiltInResource as a human-readable string.
// NOTE: User is responsible for freeing this string.
const char* glslang_default_resource_string();
// Decodes the resource limits from |config| to |resources|.
void glslang_decode_resource_limits(glslang_resource_t* resources, char* config);
#ifdef __cplusplus
}
#endif
#endif // _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
0 | repos/glslang.zig/glslang/glslang | repos/glslang.zig/glslang/glslang/Public/ShaderLang.h | //
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
// Copyright (C) 2013-2016 LunarG, Inc.
// Copyright (C) 2015-2018 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _COMPILER_INTERFACE_INCLUDED_
#define _COMPILER_INTERFACE_INCLUDED_
#include "../Include/ResourceLimits.h"
#include "../MachineIndependent/Versions.h"
#include <cstring>
#include <vector>
#ifdef _WIN32
#define C_DECL __cdecl
#else
#define C_DECL
#endif
#ifdef GLSLANG_IS_SHARED_LIBRARY
#ifdef _WIN32
#ifdef GLSLANG_EXPORTING
#define GLSLANG_EXPORT __declspec(dllexport)
#else
#define GLSLANG_EXPORT __declspec(dllimport)
#endif
#elif __GNUC__ >= 4
#define GLSLANG_EXPORT __attribute__((visibility("default")))
#endif
#endif // GLSLANG_IS_SHARED_LIBRARY
#ifndef GLSLANG_EXPORT
#define GLSLANG_EXPORT
#endif
//
// This is the platform independent interface between an OGL driver
// and the shading language compiler/linker.
//
#ifdef __cplusplus
extern "C" {
#endif
//
// Call before doing any other compiler/linker operations.
//
// (Call once per process, not once per thread.)
//
GLSLANG_EXPORT int ShInitialize();
//
// Call this at process shutdown to clean up memory.
//
GLSLANG_EXPORT int ShFinalize();
//
// Types of languages the compiler can consume.
//
typedef enum {
EShLangVertex,
EShLangTessControl,
EShLangTessEvaluation,
EShLangGeometry,
EShLangFragment,
EShLangCompute,
EShLangRayGen,
EShLangRayGenNV = EShLangRayGen,
EShLangIntersect,
EShLangIntersectNV = EShLangIntersect,
EShLangAnyHit,
EShLangAnyHitNV = EShLangAnyHit,
EShLangClosestHit,
EShLangClosestHitNV = EShLangClosestHit,
EShLangMiss,
EShLangMissNV = EShLangMiss,
EShLangCallable,
EShLangCallableNV = EShLangCallable,
EShLangTask,
EShLangTaskNV = EShLangTask,
EShLangMesh,
EShLangMeshNV = EShLangMesh,
LAST_ELEMENT_MARKER(EShLangCount),
} EShLanguage; // would be better as stage, but this is ancient now
typedef enum : unsigned {
EShLangVertexMask = (1 << EShLangVertex),
EShLangTessControlMask = (1 << EShLangTessControl),
EShLangTessEvaluationMask = (1 << EShLangTessEvaluation),
EShLangGeometryMask = (1 << EShLangGeometry),
EShLangFragmentMask = (1 << EShLangFragment),
EShLangComputeMask = (1 << EShLangCompute),
EShLangRayGenMask = (1 << EShLangRayGen),
EShLangRayGenNVMask = EShLangRayGenMask,
EShLangIntersectMask = (1 << EShLangIntersect),
EShLangIntersectNVMask = EShLangIntersectMask,
EShLangAnyHitMask = (1 << EShLangAnyHit),
EShLangAnyHitNVMask = EShLangAnyHitMask,
EShLangClosestHitMask = (1 << EShLangClosestHit),
EShLangClosestHitNVMask = EShLangClosestHitMask,
EShLangMissMask = (1 << EShLangMiss),
EShLangMissNVMask = EShLangMissMask,
EShLangCallableMask = (1 << EShLangCallable),
EShLangCallableNVMask = EShLangCallableMask,
EShLangTaskMask = (1 << EShLangTask),
EShLangTaskNVMask = EShLangTaskMask,
EShLangMeshMask = (1 << EShLangMesh),
EShLangMeshNVMask = EShLangMeshMask,
LAST_ELEMENT_MARKER(EShLanguageMaskCount),
} EShLanguageMask;
namespace glslang {
class TType;
typedef enum {
EShSourceNone,
EShSourceGlsl, // GLSL, includes ESSL (OpenGL ES GLSL)
EShSourceHlsl, // HLSL
LAST_ELEMENT_MARKER(EShSourceCount),
} EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead
typedef enum {
EShClientNone, // use when there is no client, e.g. for validation
EShClientVulkan, // as GLSL dialect, specifies KHR_vulkan_glsl extension
EShClientOpenGL, // as GLSL dialect, specifies ARB_gl_spirv extension
LAST_ELEMENT_MARKER(EShClientCount),
} EShClient;
typedef enum {
EShTargetNone,
EShTargetSpv, // SPIR-V (preferred spelling)
EshTargetSpv = EShTargetSpv, // legacy spelling
LAST_ELEMENT_MARKER(EShTargetCount),
} EShTargetLanguage;
typedef enum {
EShTargetVulkan_1_0 = (1 << 22), // Vulkan 1.0
EShTargetVulkan_1_1 = (1 << 22) | (1 << 12), // Vulkan 1.1
EShTargetVulkan_1_2 = (1 << 22) | (2 << 12), // Vulkan 1.2
EShTargetVulkan_1_3 = (1 << 22) | (3 << 12), // Vulkan 1.3
EShTargetOpenGL_450 = 450, // OpenGL
LAST_ELEMENT_MARKER(EShTargetClientVersionCount = 5),
} EShTargetClientVersion;
typedef EShTargetClientVersion EshTargetClientVersion;
typedef enum {
EShTargetSpv_1_0 = (1 << 16), // SPIR-V 1.0
EShTargetSpv_1_1 = (1 << 16) | (1 << 8), // SPIR-V 1.1
EShTargetSpv_1_2 = (1 << 16) | (2 << 8), // SPIR-V 1.2
EShTargetSpv_1_3 = (1 << 16) | (3 << 8), // SPIR-V 1.3
EShTargetSpv_1_4 = (1 << 16) | (4 << 8), // SPIR-V 1.4
EShTargetSpv_1_5 = (1 << 16) | (5 << 8), // SPIR-V 1.5
EShTargetSpv_1_6 = (1 << 16) | (6 << 8), // SPIR-V 1.6
LAST_ELEMENT_MARKER(EShTargetLanguageVersionCount = 7),
} EShTargetLanguageVersion;
struct TInputLanguage {
EShSource languageFamily; // redundant information with other input, this one overrides when not EShSourceNone
EShLanguage stage; // redundant information with other input, this one overrides when not EShSourceNone
EShClient dialect;
int dialectVersion; // version of client's language definition, not the client (when not EShClientNone)
bool vulkanRulesRelaxed;
};
struct TClient {
EShClient client;
EShTargetClientVersion version; // version of client itself (not the client's input dialect)
};
struct TTarget {
EShTargetLanguage language;
EShTargetLanguageVersion version; // version to target, if SPIR-V, defined by "word 1" of the SPIR-V header
bool hlslFunctionality1; // can target hlsl_functionality1 extension(s)
};
// All source/client/target versions and settings.
// Can override previous methods of setting, when items are set here.
// Expected to grow, as more are added, rather than growing parameter lists.
struct TEnvironment {
TInputLanguage input; // definition of the input language
TClient client; // what client is the overall compilation being done for?
TTarget target; // what to generate
};
GLSLANG_EXPORT const char* StageName(EShLanguage);
} // end namespace glslang
//
// Types of output the linker will create.
//
typedef enum {
EShExVertexFragment,
EShExFragment
} EShExecutable;
//
// Optimization level for the compiler.
//
typedef enum {
EShOptNoGeneration,
EShOptNone,
EShOptSimple, // Optimizations that can be done quickly
EShOptFull, // Optimizations that will take more time
LAST_ELEMENT_MARKER(EshOptLevelCount),
} EShOptimizationLevel;
//
// Texture and Sampler transformation mode.
//
typedef enum {
EShTexSampTransKeep, // keep textures and samplers as is (default)
EShTexSampTransUpgradeTextureRemoveSampler, // change texture w/o embeded sampler into sampled texture and throw away all samplers
LAST_ELEMENT_MARKER(EShTexSampTransCount),
} EShTextureSamplerTransformMode;
//
// Message choices for what errors and warnings are given.
//
enum EShMessages : unsigned {
EShMsgDefault = 0, // default is to give all required errors and extra warnings
EShMsgRelaxedErrors = (1 << 0), // be liberal in accepting input
EShMsgSuppressWarnings = (1 << 1), // suppress all warnings, except those required by the specification
EShMsgAST = (1 << 2), // print the AST intermediate representation
EShMsgSpvRules = (1 << 3), // issue messages for SPIR-V generation
EShMsgVulkanRules = (1 << 4), // issue messages for Vulkan-requirements of GLSL for SPIR-V
EShMsgOnlyPreprocessor = (1 << 5), // only print out errors produced by the preprocessor
EShMsgReadHlsl = (1 << 6), // use HLSL parsing rules and semantics
EShMsgCascadingErrors = (1 << 7), // get cascading errors; risks error-recovery issues, instead of an early exit
EShMsgKeepUncalled = (1 << 8), // for testing, don't eliminate uncalled functions
EShMsgHlslOffsets = (1 << 9), // allow block offsets to follow HLSL rules instead of GLSL rules
EShMsgDebugInfo = (1 << 10), // save debug information
EShMsgHlslEnable16BitTypes = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL
EShMsgHlslLegalization = (1 << 12), // enable HLSL Legalization messages
EShMsgHlslDX9Compatible = (1 << 13), // enable HLSL DX9 compatible mode (for samplers and semantics)
EShMsgBuiltinSymbolTable = (1 << 14), // print the builtin symbol table
EShMsgEnhanced = (1 << 15), // enhanced message readability
EShMsgAbsolutePath = (1 << 16), // Output Absolute path for messages
LAST_ELEMENT_MARKER(EShMsgCount),
};
//
// Options for building reflection
//
typedef enum {
EShReflectionDefault = 0, // default is original behaviour before options were added
EShReflectionStrictArraySuffix = (1 << 0), // reflection will follow stricter rules for array-of-structs suffixes
EShReflectionBasicArraySuffix = (1 << 1), // arrays of basic types will be appended with [0] as in GL reflection
EShReflectionIntermediateIO = (1 << 2), // reflect inputs and outputs to program, even with no vertex shader
EShReflectionSeparateBuffers = (1 << 3), // buffer variables and buffer blocks are reflected separately
EShReflectionAllBlockVariables = (1 << 4), // reflect all variables in blocks, even if they are inactive
EShReflectionUnwrapIOBlocks = (1 << 5), // unwrap input/output blocks the same as with uniform blocks
EShReflectionAllIOVariables = (1 << 6), // reflect all input/output variables, even if they are inactive
EShReflectionSharedStd140SSBO = (1 << 7), // Apply std140/shared rules for ubo to ssbo
EShReflectionSharedStd140UBO = (1 << 8), // Apply std140/shared rules for ubo to ssbo
LAST_ELEMENT_MARKER(EShReflectionCount),
} EShReflectionOptions;
//
// Build a table for bindings. This can be used for locating
// attributes, uniforms, globals, etc., as needed.
//
typedef struct {
const char* name;
int binding;
} ShBinding;
typedef struct {
int numBindings;
ShBinding* bindings; // array of bindings
} ShBindingTable;
//
// ShHandle held by but opaque to the driver. It is allocated,
// managed, and de-allocated by the compiler/linker. Its contents
// are defined by and used by the compiler and linker. For example,
// symbol table information and object code passed from the compiler
// to the linker can be stored where ShHandle points.
//
// If handle creation fails, 0 will be returned.
//
typedef void* ShHandle;
//
// Driver calls these to create and destroy compiler/linker
// objects.
//
GLSLANG_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int /*debugOptions unused*/); // one per shader
GLSLANG_EXPORT ShHandle ShConstructLinker(const EShExecutable, int /*debugOptions unused*/); // one per shader pair
GLSLANG_EXPORT ShHandle ShConstructUniformMap(); // one per uniform namespace (currently entire program object)
GLSLANG_EXPORT void ShDestruct(ShHandle);
//
// The return value of ShCompile is boolean, non-zero indicating
// success.
//
// The info-log should be written by ShCompile into
// ShHandle, so it can answer future queries.
//
GLSLANG_EXPORT int ShCompile(const ShHandle, const char* const shaderStrings[], const int numStrings,
const int* lengths, const EShOptimizationLevel, const TBuiltInResource* resources,
int, // debugOptions unused
int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader
bool forwardCompatible = false, // give errors for use of deprecated features
EShMessages messages = EShMsgDefault, // warnings and errors
const char* fileName = nullptr
);
GLSLANG_EXPORT int ShLinkExt(
const ShHandle, // linker object
const ShHandle h[], // compiler objects to link together
const int numHandles);
//
// ShSetEncrpytionMethod is a place-holder for specifying
// how source code is encrypted.
//
GLSLANG_EXPORT void ShSetEncryptionMethod(ShHandle);
//
// All the following return 0 if the information is not
// available in the object passed down, or the object is bad.
//
GLSLANG_EXPORT const char* ShGetInfoLog(const ShHandle);
GLSLANG_EXPORT const void* ShGetExecutable(const ShHandle);
GLSLANG_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); // to detect user aliasing
GLSLANG_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); // to force any physical mappings
//
// Tell the linker to never assign a vertex attribute to this list of physical attributes
//
GLSLANG_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count);
//
// Returns the location ID of the named uniform.
// Returns -1 if error.
//
GLSLANG_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name);
#ifdef __cplusplus
} // end extern "C"
#endif
////////////////////////////////////////////////////////////////////////////////////////////
//
// Deferred-Lowering C++ Interface
// -----------------------------------
//
// Below is a new alternate C++ interface, which deprecates the above
// opaque handle-based interface.
//
// The below is further designed to handle multiple compilation units per stage, where
// the intermediate results, including the parse tree, are preserved until link time,
// rather than the above interface which is designed to have each compilation unit
// lowered at compile time. In the above model, linking occurs on the lowered results,
// whereas in this model intra-stage linking can occur at the parse tree
// (treeRoot in TIntermediate) level, and then a full stage can be lowered.
//
#include <list>
#include <string>
#include <utility>
class TCompiler;
class TInfoSink;
namespace glslang {
struct Version {
int major;
int minor;
int patch;
const char* flavor;
};
GLSLANG_EXPORT Version GetVersion();
GLSLANG_EXPORT const char* GetEsslVersionString();
GLSLANG_EXPORT const char* GetGlslVersionString();
GLSLANG_EXPORT int GetKhronosToolId();
class TIntermediate;
class TProgram;
class TPoolAllocator;
// Call this exactly once per process before using anything else
GLSLANG_EXPORT bool InitializeProcess();
// Call once per process to tear down everything
GLSLANG_EXPORT void FinalizeProcess();
// Resource type for IO resolver
enum TResourceType {
EResSampler,
EResTexture,
EResImage,
EResUbo,
EResSsbo,
EResUav,
EResCount
};
enum TBlockStorageClass
{
EbsUniform = 0,
EbsStorageBuffer,
EbsPushConstant,
EbsNone, // not a uniform or buffer variable
EbsCount,
};
// Make one TShader per shader that you will link into a program. Then
// - provide the shader through setStrings() or setStringsWithLengths()
// - optionally call setEnv*(), see below for more detail
// - optionally use setPreamble() to set a special shader string that will be
// processed before all others but won't affect the validity of #version
// - optionally call addProcesses() for each setting/transform,
// see comment for class TProcesses
// - call parse(): source language and target environment must be selected
// either by correct setting of EShMessages sent to parse(), or by
// explicitly calling setEnv*()
// - query the info logs
//
// N.B.: Does not yet support having the same TShader instance being linked into
// multiple programs.
//
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
//
class TShader {
public:
GLSLANG_EXPORT explicit TShader(EShLanguage);
GLSLANG_EXPORT virtual ~TShader();
GLSLANG_EXPORT void setStrings(const char* const* s, int n);
GLSLANG_EXPORT void setStringsWithLengths(
const char* const* s, const int* l, int n);
GLSLANG_EXPORT void setStringsWithLengthsAndNames(
const char* const* s, const int* l, const char* const* names, int n);
void setPreamble(const char* s) { preamble = s; }
GLSLANG_EXPORT void setEntryPoint(const char* entryPoint);
GLSLANG_EXPORT void setSourceEntryPoint(const char* sourceEntryPointName);
GLSLANG_EXPORT void addProcesses(const std::vector<std::string>&);
GLSLANG_EXPORT void setUniqueId(unsigned long long id);
GLSLANG_EXPORT void setOverrideVersion(int version);
GLSLANG_EXPORT void setDebugInfo(bool debugInfo);
// IO resolver binding data: see comments in ShaderLang.cpp
GLSLANG_EXPORT void setShiftBinding(TResourceType res, unsigned int base);
GLSLANG_EXPORT void setShiftSamplerBinding(unsigned int base); // DEPRECATED: use setShiftBinding
GLSLANG_EXPORT void setShiftTextureBinding(unsigned int base); // DEPRECATED: use setShiftBinding
GLSLANG_EXPORT void setShiftImageBinding(unsigned int base); // DEPRECATED: use setShiftBinding
GLSLANG_EXPORT void setShiftUboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
GLSLANG_EXPORT void setShiftUavBinding(unsigned int base); // DEPRECATED: use setShiftBinding
GLSLANG_EXPORT void setShiftCbufferBinding(unsigned int base); // synonym for setShiftUboBinding
GLSLANG_EXPORT void setShiftSsboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
GLSLANG_EXPORT void setShiftBindingForSet(TResourceType res, unsigned int base, unsigned int set);
GLSLANG_EXPORT void setResourceSetBinding(const std::vector<std::string>& base);
GLSLANG_EXPORT void setAutoMapBindings(bool map);
GLSLANG_EXPORT void setAutoMapLocations(bool map);
GLSLANG_EXPORT void addUniformLocationOverride(const char* name, int loc);
GLSLANG_EXPORT void setUniformLocationBase(int base);
GLSLANG_EXPORT void setInvertY(bool invert);
GLSLANG_EXPORT void setDxPositionW(bool dxPosW);
GLSLANG_EXPORT void setEnhancedMsgs();
#ifdef ENABLE_HLSL
GLSLANG_EXPORT void setHlslIoMapping(bool hlslIoMap);
GLSLANG_EXPORT void setFlattenUniformArrays(bool flatten);
#endif
GLSLANG_EXPORT void setNoStorageFormat(bool useUnknownFormat);
GLSLANG_EXPORT void setNanMinMaxClamp(bool nanMinMaxClamp);
GLSLANG_EXPORT void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode);
GLSLANG_EXPORT void addBlockStorageOverride(const char* nameStr, glslang::TBlockStorageClass backing);
GLSLANG_EXPORT void setGlobalUniformBlockName(const char* name);
GLSLANG_EXPORT void setAtomicCounterBlockName(const char* name);
GLSLANG_EXPORT void setGlobalUniformSet(unsigned int set);
GLSLANG_EXPORT void setGlobalUniformBinding(unsigned int binding);
GLSLANG_EXPORT void setAtomicCounterBlockSet(unsigned int set);
GLSLANG_EXPORT void setAtomicCounterBlockBinding(unsigned int binding);
// For setting up the environment (cleared to nothingness in the constructor).
// These must be called so that parsing is done for the right source language and
// target environment, either indirectly through TranslateEnvironment() based on
// EShMessages et. al., or directly by the user.
//
// setEnvInput: The input source language and stage. If generating code for a
// specific client, the input client semantics to use and the
// version of that client's input semantics to use, otherwise
// use EShClientNone and version of 0, e.g. for validation mode.
// Note 'version' does not describe the target environment,
// just the version of the source dialect to compile under.
// For example, to choose the Vulkan dialect of GLSL defined by
// version 100 of the KHR_vulkan_glsl extension: lang = EShSourceGlsl,
// dialect = EShClientVulkan, and version = 100.
//
// See the definitions of TEnvironment, EShSource, EShLanguage,
// and EShClient for choices and more detail.
//
// setEnvClient: The client that will be hosting the execution, and its version.
// Note 'version' is not the version of the languages involved, but
// the version of the client environment.
// Use EShClientNone and version of 0 if there is no client, e.g.
// for validation mode.
//
// See EShTargetClientVersion for choices.
//
// setEnvTarget: The language to translate to when generating code, and that
// language's version.
// Use EShTargetNone and version of 0 if there is no client, e.g.
// for validation mode.
//
void setEnvInput(EShSource lang, EShLanguage envStage, EShClient client, int version)
{
environment.input.languageFamily = lang;
environment.input.stage = envStage;
environment.input.dialect = client;
environment.input.dialectVersion = version;
}
void setEnvClient(EShClient client, EShTargetClientVersion version)
{
environment.client.client = client;
environment.client.version = version;
}
void setEnvTarget(EShTargetLanguage lang, EShTargetLanguageVersion version)
{
environment.target.language = lang;
environment.target.version = version;
}
void getStrings(const char* const* &s, int& n) { s = strings; n = numStrings; }
#ifdef ENABLE_HLSL
void setEnvTargetHlslFunctionality1() { environment.target.hlslFunctionality1 = true; }
bool getEnvTargetHlslFunctionality1() const { return environment.target.hlslFunctionality1; }
#else
bool getEnvTargetHlslFunctionality1() const { return false; }
#endif
void setEnvInputVulkanRulesRelaxed() { environment.input.vulkanRulesRelaxed = true; }
bool getEnvInputVulkanRulesRelaxed() const { return environment.input.vulkanRulesRelaxed; }
void setCompileOnly() { compileOnly = true; }
bool getCompileOnly() const { return compileOnly; }
// Interface to #include handlers.
//
// To support #include, a client of Glslang does the following:
// 1. Call setStringsWithNames to set the source strings and associated
// names. For example, the names could be the names of the files
// containing the shader sources.
// 2. Call parse with an Includer.
//
// When the Glslang parser encounters an #include directive, it calls
// the Includer's include method with the requested include name
// together with the current string name. The returned IncludeResult
// contains the fully resolved name of the included source, together
// with the source text that should replace the #include directive
// in the source stream. After parsing that source, Glslang will
// release the IncludeResult object.
class Includer {
public:
// An IncludeResult contains the resolved name and content of a source
// inclusion.
struct IncludeResult {
IncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength, void* userData) :
headerName(headerName), headerData(headerData), headerLength(headerLength), userData(userData) { }
// For a successful inclusion, the fully resolved name of the requested
// include. For example, in a file system-based includer, full resolution
// should convert a relative path name into an absolute path name.
// For a failed inclusion, this is an empty string.
const std::string headerName;
// The content and byte length of the requested inclusion. The
// Includer producing this IncludeResult retains ownership of the
// storage.
// For a failed inclusion, the header
// field points to a string containing error details.
const char* const headerData;
const size_t headerLength;
// Include resolver's context.
void* userData;
protected:
IncludeResult& operator=(const IncludeResult&);
IncludeResult();
};
// For both include methods below:
//
// Resolves an inclusion request by name, current source name,
// and include depth.
// On success, returns an IncludeResult containing the resolved name
// and content of the include.
// On failure, returns a nullptr, or an IncludeResult
// with an empty string for the headerName and error details in the
// header field.
// The Includer retains ownership of the contents
// of the returned IncludeResult value, and those contents must
// remain valid until the releaseInclude method is called on that
// IncludeResult object.
//
// Note "local" vs. "system" is not an "either/or": "local" is an
// extra thing to do over "system". Both might get called, as per
// the C++ specification.
// For the "system" or <>-style includes; search the "system" paths.
virtual IncludeResult* includeSystem(const char* /*headerName*/,
const char* /*includerName*/,
size_t /*inclusionDepth*/) { return nullptr; }
// For the "local"-only aspect of a "" include. Should not search in the
// "system" paths, because on returning a failure, the parser will
// call includeSystem() to look in the "system" locations.
virtual IncludeResult* includeLocal(const char* /*headerName*/,
const char* /*includerName*/,
size_t /*inclusionDepth*/) { return nullptr; }
// Signals that the parser will no longer use the contents of the
// specified IncludeResult.
virtual void releaseInclude(IncludeResult*) = 0;
virtual ~Includer() {}
};
// Fail all Includer searches
class ForbidIncluder : public Includer {
public:
virtual void releaseInclude(IncludeResult*) override { }
};
GLSLANG_EXPORT bool parse(
const TBuiltInResource*, int defaultVersion, EProfile defaultProfile,
bool forceDefaultVersionAndProfile, bool forwardCompatible,
EShMessages, Includer&);
bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
bool forwardCompatible, EShMessages messages)
{
TShader::ForbidIncluder includer;
return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer);
}
// Equivalent to parse() without a default profile and without forcing defaults.
bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages)
{
return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages);
}
bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages,
Includer& includer)
{
return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages, includer);
}
// NOTE: Doing just preprocessing to obtain a correct preprocessed shader string
// is not an officially supported or fully working path.
GLSLANG_EXPORT bool preprocess(
const TBuiltInResource* builtInResources, int defaultVersion,
EProfile defaultProfile, bool forceDefaultVersionAndProfile,
bool forwardCompatible, EShMessages message, std::string* outputString,
Includer& includer);
GLSLANG_EXPORT const char* getInfoLog();
GLSLANG_EXPORT const char* getInfoDebugLog();
EShLanguage getStage() const { return stage; }
TIntermediate* getIntermediate() const { return intermediate; }
protected:
TPoolAllocator* pool;
EShLanguage stage;
TCompiler* compiler;
TIntermediate* intermediate;
TInfoSink* infoSink;
// strings and lengths follow the standard for glShaderSource:
// strings is an array of numStrings pointers to string data.
// lengths can be null, but if not it is an array of numStrings
// integers containing the length of the associated strings.
// if lengths is null or lengths[n] < 0 the associated strings[n] is
// assumed to be null-terminated.
// stringNames is the optional names for all the strings. If stringNames
// is null, then none of the strings has name. If a certain element in
// stringNames is null, then the corresponding string does not have name.
const char* const* strings; // explicit code to compile, see previous comment
const int* lengths;
const char* const* stringNames;
int numStrings; // size of the above arrays
const char* preamble; // string of implicit code to compile before the explicitly provided code
// a function in the source string can be renamed FROM this TO the name given in setEntryPoint.
std::string sourceEntryPointName;
// overrides #version in shader source or default version if #version isn't present
int overrideVersion;
TEnvironment environment;
// Indicates this shader is meant to be used without linking
bool compileOnly = false;
friend class TProgram;
private:
TShader& operator=(TShader&);
};
//
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
//
// Data needed for just a single object at the granularity exchanged by the reflection API
class TObjectReflection {
public:
GLSLANG_EXPORT TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex);
const TType* getType() const { return type; }
GLSLANG_EXPORT int getBinding() const;
GLSLANG_EXPORT void dump() const;
static TObjectReflection badReflection() { return TObjectReflection(); }
GLSLANG_EXPORT unsigned int layoutLocation() const;
std::string name;
int offset;
int glDefineType;
int size; // data size in bytes for a block, array size for a (non-block) object that's an array
int index;
int counterIndex;
int numMembers;
int arrayStride; // stride of an array variable
int topLevelArraySize; // size of the top-level variable in a storage buffer member
int topLevelArrayStride; // stride of the top-level variable in a storage buffer member
EShLanguageMask stages;
protected:
TObjectReflection()
: offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), numMembers(-1), arrayStride(0),
topLevelArrayStride(0), stages(EShLanguageMask(0)), type(nullptr)
{
}
const TType* type;
};
class TReflection;
class TIoMapper;
struct TVarEntryInfo;
// Allows to customize the binding layout after linking.
// All used uniform variables will invoke at least validateBinding.
// If validateBinding returned true then the other resolveBinding,
// resolveSet, and resolveLocation are invoked to resolve the binding
// and descriptor set index respectively.
//
// Invocations happen in a particular order:
// 1) all shader inputs
// 2) all shader outputs
// 3) all uniforms with binding and set already defined
// 4) all uniforms with binding but no set defined
// 5) all uniforms with set but no binding defined
// 6) all uniforms with no binding and no set defined
//
// mapIO will use this resolver in two phases. The first
// phase is a notification phase, calling the corresponging
// notifiy callbacks, this phase ends with a call to endNotifications.
// Phase two starts directly after the call to endNotifications
// and calls all other callbacks to validate and to get the
// bindings, sets, locations, component and color indices.
//
// NOTE: that still limit checks are applied to bindings and sets
// and may result in an error.
class TIoMapResolver
{
public:
virtual ~TIoMapResolver() {}
// Should return true if the resulting/current binding would be okay.
// Basic idea is to do aliasing binding checks with this.
virtual bool validateBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current binding should be overridden.
// Return -1 if the current binding (including no binding) should be kept.
virtual int resolveBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current set should be overridden.
// Return -1 if the current set (including no set) should be kept.
virtual int resolveSet(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current location should be overridden.
// Return -1 if the current location (including no location) should be kept.
virtual int resolveUniformLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return true if the resulting/current setup would be okay.
// Basic idea is to do aliasing checks and reject invalid semantic names.
virtual bool validateInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current location should be overridden.
// Return -1 if the current location (including no location) should be kept.
virtual int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current component index should be overridden.
// Return -1 if the current component index (including no index) should be kept.
virtual int resolveInOutComponent(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current color index should be overridden.
// Return -1 if the current color index (including no index) should be kept.
virtual int resolveInOutIndex(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Notification of a uniform variable
virtual void notifyBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Notification of a in or out variable
virtual void notifyInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Called by mapIO when it starts its notify pass for the given stage
virtual void beginNotifications(EShLanguage stage) = 0;
// Called by mapIO when it has finished the notify pass
virtual void endNotifications(EShLanguage stage) = 0;
// Called by mipIO when it starts its resolve pass for the given stage
virtual void beginResolve(EShLanguage stage) = 0;
// Called by mapIO when it has finished the resolve pass
virtual void endResolve(EShLanguage stage) = 0;
// Called by mapIO when it starts its symbol collect for teh given stage
virtual void beginCollect(EShLanguage stage) = 0;
// Called by mapIO when it has finished the symbol collect
virtual void endCollect(EShLanguage stage) = 0;
// Called by TSlotCollector to resolve storage locations or bindings
virtual void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
// Called by TSlotCollector to resolve resource locations or bindings
virtual void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
// Called by mapIO.addStage to set shader stage mask to mark a stage be added to this pipeline
virtual void addStage(EShLanguage stage, TIntermediate& stageIntermediate) = 0;
};
// Make one TProgram per set of shaders that will get linked together. Add all
// the shaders that are to be linked together. After calling shader.parse()
// for all shaders, call link().
//
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
//
class TProgram {
public:
GLSLANG_EXPORT TProgram();
GLSLANG_EXPORT virtual ~TProgram();
void addShader(TShader* shader) { stages[shader->stage].push_back(shader); }
std::list<TShader*>& getShaders(EShLanguage stage) { return stages[stage]; }
// Link Validation interface
GLSLANG_EXPORT bool link(EShMessages);
GLSLANG_EXPORT const char* getInfoLog();
GLSLANG_EXPORT const char* getInfoDebugLog();
TIntermediate* getIntermediate(EShLanguage stage) const { return intermediate[stage]; }
// Reflection Interface
// call first, to do liveness analysis, index mapping, etc.; returns false on failure
GLSLANG_EXPORT bool buildReflection(int opts = EShReflectionDefault);
GLSLANG_EXPORT unsigned getLocalSize(int dim) const; // return dim'th local size
GLSLANG_EXPORT int getReflectionIndex(const char *name) const;
GLSLANG_EXPORT int getReflectionPipeIOIndex(const char* name, const bool inOrOut) const;
GLSLANG_EXPORT int getNumUniformVariables() const;
GLSLANG_EXPORT const TObjectReflection& getUniform(int index) const;
GLSLANG_EXPORT int getNumUniformBlocks() const;
GLSLANG_EXPORT const TObjectReflection& getUniformBlock(int index) const;
GLSLANG_EXPORT int getNumPipeInputs() const;
GLSLANG_EXPORT const TObjectReflection& getPipeInput(int index) const;
GLSLANG_EXPORT int getNumPipeOutputs() const;
GLSLANG_EXPORT const TObjectReflection& getPipeOutput(int index) const;
GLSLANG_EXPORT int getNumBufferVariables() const;
GLSLANG_EXPORT const TObjectReflection& getBufferVariable(int index) const;
GLSLANG_EXPORT int getNumBufferBlocks() const;
GLSLANG_EXPORT const TObjectReflection& getBufferBlock(int index) const;
GLSLANG_EXPORT int getNumAtomicCounters() const;
GLSLANG_EXPORT const TObjectReflection& getAtomicCounter(int index) const;
// Legacy Reflection Interface - expressed in terms of above interface
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS)
int getNumLiveUniformVariables() const { return getNumUniformVariables(); }
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS)
int getNumLiveUniformBlocks() const { return getNumUniformBlocks(); }
// can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
int getNumLiveAttributes() const { return getNumPipeInputs(); }
// can be used for glGetUniformIndices()
int getUniformIndex(const char *name) const { return getReflectionIndex(name); }
int getPipeIOIndex(const char *name, const bool inOrOut) const
{ return getReflectionPipeIOIndex(name, inOrOut); }
// can be used for "name" part of glGetActiveUniform()
const char *getUniformName(int index) const { return getUniform(index).name.c_str(); }
// returns the binding number
int getUniformBinding(int index) const { return getUniform(index).getBinding(); }
// returns Shaders Stages where a Uniform is present
EShLanguageMask getUniformStages(int index) const { return getUniform(index).stages; }
// can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
int getUniformBlockIndex(int index) const { return getUniform(index).index; }
// can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
int getUniformType(int index) const { return getUniform(index).glDefineType; }
// can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
int getUniformBufferOffset(int index) const { return getUniform(index).offset; }
// can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
int getUniformArraySize(int index) const { return getUniform(index).size; }
// returns a TType*
const TType *getUniformTType(int index) const { return getUniform(index).getType(); }
// can be used for glGetActiveUniformBlockName()
const char *getUniformBlockName(int index) const { return getUniformBlock(index).name.c_str(); }
// can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
int getUniformBlockSize(int index) const { return getUniformBlock(index).size; }
// returns the block binding number
int getUniformBlockBinding(int index) const { return getUniformBlock(index).getBinding(); }
// returns block index of associated counter.
int getUniformBlockCounterIndex(int index) const { return getUniformBlock(index).counterIndex; }
// returns a TType*
const TType *getUniformBlockTType(int index) const { return getUniformBlock(index).getType(); }
// can be used for glGetActiveAttrib()
const char *getAttributeName(int index) const { return getPipeInput(index).name.c_str(); }
// can be used for glGetActiveAttrib()
int getAttributeType(int index) const { return getPipeInput(index).glDefineType; }
// returns a TType*
const TType *getAttributeTType(int index) const { return getPipeInput(index).getType(); }
GLSLANG_EXPORT void dumpReflection();
// I/O mapping: apply base offsets and map live unbound variables
// If resolver is not provided it uses the previous approach
// and respects auto assignment and offsets.
GLSLANG_EXPORT bool mapIO(TIoMapResolver* pResolver = nullptr, TIoMapper* pIoMapper = nullptr);
protected:
GLSLANG_EXPORT bool linkStage(EShLanguage, EShMessages);
GLSLANG_EXPORT bool crossStageCheck(EShMessages);
TPoolAllocator* pool;
std::list<TShader*> stages[EShLangCount];
TIntermediate* intermediate[EShLangCount];
bool newedIntermediate[EShLangCount]; // track which intermediate were "new" versus reusing a singleton unit in a stage
TInfoSink* infoSink;
TReflection* reflection;
bool linked;
private:
TProgram(TProgram&);
TProgram& operator=(TProgram&);
};
} // end namespace glslang
#endif // _COMPILER_INTERFACE_INCLUDED_
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/NonSemanticShaderDebugInfo100.h | // Copyright (c) 2018 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and/or associated documentation files (the "Materials"),
// to deal in the Materials without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Materials, and to permit persons to whom the
// Materials are furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Materials.
//
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
// STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
// HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
// IN THE MATERIALS.
#ifndef SPIRV_UNIFIED1_NonSemanticShaderDebugInfo100_H_
#define SPIRV_UNIFIED1_NonSemanticShaderDebugInfo100_H_
#ifdef __cplusplus
extern "C" {
#endif
enum {
NonSemanticShaderDebugInfo100Version = 100,
NonSemanticShaderDebugInfo100Version_BitWidthPadding = 0x7fffffff
};
enum {
NonSemanticShaderDebugInfo100Revision = 6,
NonSemanticShaderDebugInfo100Revision_BitWidthPadding = 0x7fffffff
};
enum NonSemanticShaderDebugInfo100Instructions {
NonSemanticShaderDebugInfo100DebugInfoNone = 0,
NonSemanticShaderDebugInfo100DebugCompilationUnit = 1,
NonSemanticShaderDebugInfo100DebugTypeBasic = 2,
NonSemanticShaderDebugInfo100DebugTypePointer = 3,
NonSemanticShaderDebugInfo100DebugTypeQualifier = 4,
NonSemanticShaderDebugInfo100DebugTypeArray = 5,
NonSemanticShaderDebugInfo100DebugTypeVector = 6,
NonSemanticShaderDebugInfo100DebugTypedef = 7,
NonSemanticShaderDebugInfo100DebugTypeFunction = 8,
NonSemanticShaderDebugInfo100DebugTypeEnum = 9,
NonSemanticShaderDebugInfo100DebugTypeComposite = 10,
NonSemanticShaderDebugInfo100DebugTypeMember = 11,
NonSemanticShaderDebugInfo100DebugTypeInheritance = 12,
NonSemanticShaderDebugInfo100DebugTypePtrToMember = 13,
NonSemanticShaderDebugInfo100DebugTypeTemplate = 14,
NonSemanticShaderDebugInfo100DebugTypeTemplateParameter = 15,
NonSemanticShaderDebugInfo100DebugTypeTemplateTemplateParameter = 16,
NonSemanticShaderDebugInfo100DebugTypeTemplateParameterPack = 17,
NonSemanticShaderDebugInfo100DebugGlobalVariable = 18,
NonSemanticShaderDebugInfo100DebugFunctionDeclaration = 19,
NonSemanticShaderDebugInfo100DebugFunction = 20,
NonSemanticShaderDebugInfo100DebugLexicalBlock = 21,
NonSemanticShaderDebugInfo100DebugLexicalBlockDiscriminator = 22,
NonSemanticShaderDebugInfo100DebugScope = 23,
NonSemanticShaderDebugInfo100DebugNoScope = 24,
NonSemanticShaderDebugInfo100DebugInlinedAt = 25,
NonSemanticShaderDebugInfo100DebugLocalVariable = 26,
NonSemanticShaderDebugInfo100DebugInlinedVariable = 27,
NonSemanticShaderDebugInfo100DebugDeclare = 28,
NonSemanticShaderDebugInfo100DebugValue = 29,
NonSemanticShaderDebugInfo100DebugOperation = 30,
NonSemanticShaderDebugInfo100DebugExpression = 31,
NonSemanticShaderDebugInfo100DebugMacroDef = 32,
NonSemanticShaderDebugInfo100DebugMacroUndef = 33,
NonSemanticShaderDebugInfo100DebugImportedEntity = 34,
NonSemanticShaderDebugInfo100DebugSource = 35,
NonSemanticShaderDebugInfo100DebugFunctionDefinition = 101,
NonSemanticShaderDebugInfo100DebugSourceContinued = 102,
NonSemanticShaderDebugInfo100DebugLine = 103,
NonSemanticShaderDebugInfo100DebugNoLine = 104,
NonSemanticShaderDebugInfo100DebugBuildIdentifier = 105,
NonSemanticShaderDebugInfo100DebugStoragePath = 106,
NonSemanticShaderDebugInfo100DebugEntryPoint = 107,
NonSemanticShaderDebugInfo100DebugTypeMatrix = 108,
NonSemanticShaderDebugInfo100InstructionsMax = 0x7fffffff
};
enum NonSemanticShaderDebugInfo100DebugInfoFlags {
NonSemanticShaderDebugInfo100None = 0x0000,
NonSemanticShaderDebugInfo100FlagIsProtected = 0x01,
NonSemanticShaderDebugInfo100FlagIsPrivate = 0x02,
NonSemanticShaderDebugInfo100FlagIsPublic = 0x03,
NonSemanticShaderDebugInfo100FlagIsLocal = 0x04,
NonSemanticShaderDebugInfo100FlagIsDefinition = 0x08,
NonSemanticShaderDebugInfo100FlagFwdDecl = 0x10,
NonSemanticShaderDebugInfo100FlagArtificial = 0x20,
NonSemanticShaderDebugInfo100FlagExplicit = 0x40,
NonSemanticShaderDebugInfo100FlagPrototyped = 0x80,
NonSemanticShaderDebugInfo100FlagObjectPointer = 0x100,
NonSemanticShaderDebugInfo100FlagStaticMember = 0x200,
NonSemanticShaderDebugInfo100FlagIndirectVariable = 0x400,
NonSemanticShaderDebugInfo100FlagLValueReference = 0x800,
NonSemanticShaderDebugInfo100FlagRValueReference = 0x1000,
NonSemanticShaderDebugInfo100FlagIsOptimized = 0x2000,
NonSemanticShaderDebugInfo100FlagIsEnumClass = 0x4000,
NonSemanticShaderDebugInfo100FlagTypePassByValue = 0x8000,
NonSemanticShaderDebugInfo100FlagTypePassByReference = 0x10000,
NonSemanticShaderDebugInfo100FlagUnknownPhysicalLayout = 0x20000,
NonSemanticShaderDebugInfo100DebugInfoFlagsMax = 0x7fffffff
};
enum NonSemanticShaderDebugInfo100BuildIdentifierFlags {
NonSemanticShaderDebugInfo100IdentifierPossibleDuplicates = 0x01,
NonSemanticShaderDebugInfo100BuildIdentifierFlagsMax = 0x7fffffff
};
enum NonSemanticShaderDebugInfo100DebugBaseTypeAttributeEncoding {
NonSemanticShaderDebugInfo100Unspecified = 0,
NonSemanticShaderDebugInfo100Address = 1,
NonSemanticShaderDebugInfo100Boolean = 2,
NonSemanticShaderDebugInfo100Float = 3,
NonSemanticShaderDebugInfo100Signed = 4,
NonSemanticShaderDebugInfo100SignedChar = 5,
NonSemanticShaderDebugInfo100Unsigned = 6,
NonSemanticShaderDebugInfo100UnsignedChar = 7,
NonSemanticShaderDebugInfo100DebugBaseTypeAttributeEncodingMax = 0x7fffffff
};
enum NonSemanticShaderDebugInfo100DebugCompositeType {
NonSemanticShaderDebugInfo100Class = 0,
NonSemanticShaderDebugInfo100Structure = 1,
NonSemanticShaderDebugInfo100Union = 2,
NonSemanticShaderDebugInfo100DebugCompositeTypeMax = 0x7fffffff
};
enum NonSemanticShaderDebugInfo100DebugTypeQualifier {
NonSemanticShaderDebugInfo100ConstType = 0,
NonSemanticShaderDebugInfo100VolatileType = 1,
NonSemanticShaderDebugInfo100RestrictType = 2,
NonSemanticShaderDebugInfo100AtomicType = 3,
NonSemanticShaderDebugInfo100DebugTypeQualifierMax = 0x7fffffff
};
enum NonSemanticShaderDebugInfo100DebugOperation {
NonSemanticShaderDebugInfo100Deref = 0,
NonSemanticShaderDebugInfo100Plus = 1,
NonSemanticShaderDebugInfo100Minus = 2,
NonSemanticShaderDebugInfo100PlusUconst = 3,
NonSemanticShaderDebugInfo100BitPiece = 4,
NonSemanticShaderDebugInfo100Swap = 5,
NonSemanticShaderDebugInfo100Xderef = 6,
NonSemanticShaderDebugInfo100StackValue = 7,
NonSemanticShaderDebugInfo100Constu = 8,
NonSemanticShaderDebugInfo100Fragment = 9,
NonSemanticShaderDebugInfo100DebugOperationMax = 0x7fffffff
};
enum NonSemanticShaderDebugInfo100DebugImportedEntity {
NonSemanticShaderDebugInfo100ImportedModule = 0,
NonSemanticShaderDebugInfo100ImportedDeclaration = 1,
NonSemanticShaderDebugInfo100DebugImportedEntityMax = 0x7fffffff
};
#ifdef __cplusplus
}
#endif
#endif // SPIRV_UNIFIED1_NonSemanticShaderDebugInfo100_H_
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/disassemble.cpp | //
// Copyright (C) 2014-2015 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Disassembler for SPIR-V.
//
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <stack>
#include <sstream>
#include <cstring>
#include <utility>
#include "disassemble.h"
#include "doc.h"
namespace spv {
extern "C" {
// Include C-based headers that don't have a namespace
#include "GLSL.std.450.h"
#include "GLSL.ext.AMD.h"
#include "GLSL.ext.NV.h"
#include "GLSL.ext.ARM.h"
#include "NonSemanticShaderDebugInfo100.h"
#include "GLSL.ext.QCOM.h"
}
}
const char* GlslStd450DebugNames[spv::GLSLstd450Count];
namespace spv {
static const char* GLSLextAMDGetDebugNames(const char*, unsigned);
static const char* GLSLextNVGetDebugNames(const char*, unsigned);
static const char* NonSemanticShaderDebugInfo100GetDebugNames(unsigned);
static void Kill(std::ostream& out, const char* message)
{
out << std::endl << "Disassembly failed: " << message << std::endl;
exit(1);
}
// used to identify the extended instruction library imported when printing
enum ExtInstSet {
GLSL450Inst,
GLSLextAMDInst,
GLSLextNVInst,
OpenCLExtInst,
NonSemanticDebugPrintfExtInst,
NonSemanticDebugBreakExtInst,
NonSemanticShaderDebugInfo100
};
// Container class for a single instance of a SPIR-V stream, with methods for disassembly.
class SpirvStream {
public:
SpirvStream(std::ostream& out, const std::vector<unsigned int>& stream) : out(out), stream(stream), word(0), nextNestedControl(0) { }
virtual ~SpirvStream() { }
void validate();
void processInstructions();
protected:
SpirvStream(const SpirvStream&);
SpirvStream& operator=(const SpirvStream&);
Op getOpCode(int id) const { return idInstruction[id] ? (Op)(stream[idInstruction[id]] & OpCodeMask) : OpNop; }
// Output methods
void outputIndent();
void formatId(Id id, std::stringstream&);
void outputResultId(Id id);
void outputTypeId(Id id);
void outputId(Id id);
void outputMask(OperandClass operandClass, unsigned mask);
void disassembleImmediates(int numOperands);
void disassembleIds(int numOperands);
std::pair<int, std::string> decodeString();
int disassembleString();
void disassembleInstruction(Id resultId, Id typeId, Op opCode, int numOperands);
// Data
std::ostream& out; // where to write the disassembly
const std::vector<unsigned int>& stream; // the actual word stream
int size; // the size of the word stream
int word; // the next word of the stream to read
// map each <id> to the instruction that created it
Id bound;
std::vector<unsigned int> idInstruction; // the word offset into the stream where the instruction for result [id] starts; 0 if not yet seen (forward reference or function parameter)
std::vector<std::string> idDescriptor; // the best text string known for explaining the <id>
// schema
unsigned int schema;
// stack of structured-merge points
std::stack<Id> nestedControl;
Id nextNestedControl; // need a slight delay for when we are nested
};
void SpirvStream::validate()
{
size = (int)stream.size();
if (size < 4)
Kill(out, "stream is too short");
// Magic number
if (stream[word++] != MagicNumber) {
out << "Bad magic number";
return;
}
// Version
out << "// Module Version " << std::hex << stream[word++] << std::endl;
// Generator's magic number
out << "// Generated by (magic number): " << std::hex << stream[word++] << std::dec << std::endl;
// Result <id> bound
bound = stream[word++];
idInstruction.resize(bound);
idDescriptor.resize(bound);
out << "// Id's are bound by " << bound << std::endl;
out << std::endl;
// Reserved schema, must be 0 for now
schema = stream[word++];
if (schema != 0)
Kill(out, "bad schema, must be 0");
}
// Loop over all the instructions, in order, processing each.
// Boiler plate for each is handled here directly, the rest is dispatched.
void SpirvStream::processInstructions()
{
// Instructions
while (word < size) {
int instructionStart = word;
// Instruction wordCount and opcode
unsigned int firstWord = stream[word];
unsigned wordCount = firstWord >> WordCountShift;
Op opCode = (Op)(firstWord & OpCodeMask);
int nextInst = word + wordCount;
++word;
// Presence of full instruction
if (nextInst > size)
Kill(out, "stream instruction terminated too early");
// Base for computing number of operands; will be updated as more is learned
unsigned numOperands = wordCount - 1;
// Type <id>
Id typeId = 0;
if (InstructionDesc[opCode].hasType()) {
typeId = stream[word++];
--numOperands;
}
// Result <id>
Id resultId = 0;
if (InstructionDesc[opCode].hasResult()) {
resultId = stream[word++];
--numOperands;
// save instruction for future reference
idInstruction[resultId] = instructionStart;
}
outputResultId(resultId);
outputTypeId(typeId);
outputIndent();
// Hand off the Op and all its operands
disassembleInstruction(resultId, typeId, opCode, numOperands);
if (word != nextInst) {
out << " ERROR, incorrect number of operands consumed. At " << word << " instead of " << nextInst << " instruction start was " << instructionStart;
word = nextInst;
}
out << std::endl;
}
}
void SpirvStream::outputIndent()
{
for (int i = 0; i < (int)nestedControl.size(); ++i)
out << " ";
}
void SpirvStream::formatId(Id id, std::stringstream& idStream)
{
if (id != 0) {
// On instructions with no IDs, this is called with "0", which does not
// have to be within ID bounds on null shaders.
if (id >= bound)
Kill(out, "Bad <id>");
idStream << id;
if (idDescriptor[id].size() > 0)
idStream << "(" << idDescriptor[id] << ")";
}
}
void SpirvStream::outputResultId(Id id)
{
const int width = 16;
std::stringstream idStream;
formatId(id, idStream);
out << std::setw(width) << std::right << idStream.str();
if (id != 0)
out << ":";
else
out << " ";
if (nestedControl.size() && id == nestedControl.top())
nestedControl.pop();
}
void SpirvStream::outputTypeId(Id id)
{
const int width = 12;
std::stringstream idStream;
formatId(id, idStream);
out << std::setw(width) << std::right << idStream.str() << " ";
}
void SpirvStream::outputId(Id id)
{
if (id >= bound)
Kill(out, "Bad <id>");
out << id;
if (idDescriptor[id].size() > 0)
out << "(" << idDescriptor[id] << ")";
}
void SpirvStream::outputMask(OperandClass operandClass, unsigned mask)
{
if (mask == 0)
out << "None";
else {
for (int m = 0; m < OperandClassParams[operandClass].ceiling; ++m) {
if (mask & (1 << m))
out << OperandClassParams[operandClass].getName(m) << " ";
}
}
}
void SpirvStream::disassembleImmediates(int numOperands)
{
for (int i = 0; i < numOperands; ++i) {
out << stream[word++];
if (i < numOperands - 1)
out << " ";
}
}
void SpirvStream::disassembleIds(int numOperands)
{
for (int i = 0; i < numOperands; ++i) {
outputId(stream[word++]);
if (i < numOperands - 1)
out << " ";
}
}
// decode string from words at current position (non-consuming)
std::pair<int, std::string> SpirvStream::decodeString()
{
std::string res;
int wordPos = word;
char c;
bool done = false;
do {
unsigned int content = stream[wordPos];
for (int charCount = 0; charCount < 4; ++charCount) {
c = content & 0xff;
content >>= 8;
if (c == '\0') {
done = true;
break;
}
res += c;
}
++wordPos;
} while(! done);
return std::make_pair(wordPos - word, res);
}
// return the number of operands consumed by the string
int SpirvStream::disassembleString()
{
out << " \"";
std::pair<int, std::string> decoderes = decodeString();
out << decoderes.second;
out << "\"";
word += decoderes.first;
return decoderes.first;
}
void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, int numOperands)
{
// Process the opcode
out << (OpcodeString(opCode) + 2); // leave out the "Op"
if (opCode == OpLoopMerge || opCode == OpSelectionMerge)
nextNestedControl = stream[word];
else if (opCode == OpBranchConditional || opCode == OpSwitch) {
if (nextNestedControl) {
nestedControl.push(nextNestedControl);
nextNestedControl = 0;
}
} else if (opCode == OpExtInstImport) {
idDescriptor[resultId] = decodeString().second;
}
else {
if (resultId != 0 && idDescriptor[resultId].size() == 0) {
switch (opCode) {
case OpTypeInt:
switch (stream[word]) {
case 8: idDescriptor[resultId] = "int8_t"; break;
case 16: idDescriptor[resultId] = "int16_t"; break;
default: assert(0); [[fallthrough]];
case 32: idDescriptor[resultId] = "int"; break;
case 64: idDescriptor[resultId] = "int64_t"; break;
}
break;
case OpTypeFloat:
switch (stream[word]) {
case 16: idDescriptor[resultId] = "float16_t"; break;
default: assert(0); [[fallthrough]];
case 32: idDescriptor[resultId] = "float"; break;
case 64: idDescriptor[resultId] = "float64_t"; break;
}
break;
case OpTypeBool:
idDescriptor[resultId] = "bool";
break;
case OpTypeStruct:
idDescriptor[resultId] = "struct";
break;
case OpTypePointer:
idDescriptor[resultId] = "ptr";
break;
case OpTypeVector:
if (idDescriptor[stream[word]].size() > 0) {
idDescriptor[resultId].append(idDescriptor[stream[word]].begin(), idDescriptor[stream[word]].begin() + 1);
if (strstr(idDescriptor[stream[word]].c_str(), "8")) {
idDescriptor[resultId].append("8");
}
if (strstr(idDescriptor[stream[word]].c_str(), "16")) {
idDescriptor[resultId].append("16");
}
if (strstr(idDescriptor[stream[word]].c_str(), "64")) {
idDescriptor[resultId].append("64");
}
}
idDescriptor[resultId].append("vec");
switch (stream[word + 1]) {
case 2: idDescriptor[resultId].append("2"); break;
case 3: idDescriptor[resultId].append("3"); break;
case 4: idDescriptor[resultId].append("4"); break;
case 8: idDescriptor[resultId].append("8"); break;
case 16: idDescriptor[resultId].append("16"); break;
case 32: idDescriptor[resultId].append("32"); break;
default: break;
}
break;
default:
break;
}
}
}
// Process the operands. Note, a new context-dependent set could be
// swapped in mid-traversal.
// Handle images specially, so can put out helpful strings.
if (opCode == OpTypeImage) {
out << " ";
disassembleIds(1);
out << " " << DimensionString((Dim)stream[word++]);
out << (stream[word++] != 0 ? " depth" : "");
out << (stream[word++] != 0 ? " array" : "");
out << (stream[word++] != 0 ? " multi-sampled" : "");
switch (stream[word++]) {
case 0: out << " runtime"; break;
case 1: out << " sampled"; break;
case 2: out << " nonsampled"; break;
}
out << " format:" << ImageFormatString((ImageFormat)stream[word++]);
if (numOperands == 8) {
out << " " << AccessQualifierString(stream[word++]);
}
return;
}
// Handle all the parameterized operands
for (int op = 0; op < InstructionDesc[opCode].operands.getNum() && numOperands > 0; ++op) {
out << " ";
OperandClass operandClass = InstructionDesc[opCode].operands.getClass(op);
switch (operandClass) {
case OperandId:
case OperandScope:
case OperandMemorySemantics:
disassembleIds(1);
--numOperands;
// Get names for printing "(XXX)" for readability, *after* this id
if (opCode == OpName)
idDescriptor[stream[word - 1]] = decodeString().second;
break;
case OperandVariableIds:
disassembleIds(numOperands);
return;
case OperandImageOperands:
outputMask(OperandImageOperands, stream[word++]);
--numOperands;
disassembleIds(numOperands);
return;
case OperandOptionalLiteral:
case OperandVariableLiterals:
if ((opCode == OpDecorate && stream[word - 1] == DecorationBuiltIn) ||
(opCode == OpMemberDecorate && stream[word - 1] == DecorationBuiltIn)) {
out << BuiltInString(stream[word++]);
--numOperands;
++op;
}
disassembleImmediates(numOperands);
return;
case OperandVariableIdLiteral:
while (numOperands > 0) {
out << std::endl;
outputResultId(0);
outputTypeId(0);
outputIndent();
out << " Type ";
disassembleIds(1);
out << ", member ";
disassembleImmediates(1);
numOperands -= 2;
}
return;
case OperandVariableLiteralId:
while (numOperands > 0) {
out << std::endl;
outputResultId(0);
outputTypeId(0);
outputIndent();
out << " case ";
disassembleImmediates(1);
out << ": ";
disassembleIds(1);
numOperands -= 2;
}
return;
case OperandLiteralNumber:
disassembleImmediates(1);
--numOperands;
if (opCode == OpExtInst) {
ExtInstSet extInstSet = GLSL450Inst;
const char* name = idDescriptor[stream[word - 2]].c_str();
if (strcmp("OpenCL.std", name) == 0) {
extInstSet = OpenCLExtInst;
} else if (strcmp("OpenCL.DebugInfo.100", name) == 0) {
extInstSet = OpenCLExtInst;
} else if (strcmp("NonSemantic.DebugPrintf", name) == 0) {
extInstSet = NonSemanticDebugPrintfExtInst;
} else if (strcmp("NonSemantic.DebugBreak", name) == 0) {
extInstSet = NonSemanticDebugBreakExtInst;
} else if (strcmp("NonSemantic.Shader.DebugInfo.100", name) == 0) {
extInstSet = NonSemanticShaderDebugInfo100;
} else if (strcmp(spv::E_SPV_AMD_shader_ballot, name) == 0 ||
strcmp(spv::E_SPV_AMD_shader_trinary_minmax, name) == 0 ||
strcmp(spv::E_SPV_AMD_shader_explicit_vertex_parameter, name) == 0 ||
strcmp(spv::E_SPV_AMD_gcn_shader, name) == 0) {
extInstSet = GLSLextAMDInst;
} else if (strcmp(spv::E_SPV_NV_sample_mask_override_coverage, name) == 0 ||
strcmp(spv::E_SPV_NV_geometry_shader_passthrough, name) == 0 ||
strcmp(spv::E_SPV_NV_viewport_array2, name) == 0 ||
strcmp(spv::E_SPV_NVX_multiview_per_view_attributes, name) == 0 ||
strcmp(spv::E_SPV_NV_fragment_shader_barycentric, name) == 0 ||
strcmp(spv::E_SPV_NV_mesh_shader, name) == 0) {
extInstSet = GLSLextNVInst;
}
unsigned entrypoint = stream[word - 1];
if (extInstSet == GLSL450Inst) {
if (entrypoint < GLSLstd450Count) {
out << "(" << GlslStd450DebugNames[entrypoint] << ")";
}
} else if (extInstSet == GLSLextAMDInst) {
out << "(" << GLSLextAMDGetDebugNames(name, entrypoint) << ")";
}
else if (extInstSet == GLSLextNVInst) {
out << "(" << GLSLextNVGetDebugNames(name, entrypoint) << ")";
} else if (extInstSet == NonSemanticDebugPrintfExtInst) {
out << "(DebugPrintf)";
} else if (extInstSet == NonSemanticDebugBreakExtInst) {
out << "(DebugBreak)";
} else if (extInstSet == NonSemanticShaderDebugInfo100) {
out << "(" << NonSemanticShaderDebugInfo100GetDebugNames(entrypoint) << ")";
}
}
break;
case OperandOptionalLiteralString:
case OperandLiteralString:
numOperands -= disassembleString();
break;
case OperandVariableLiteralStrings:
while (numOperands > 0)
numOperands -= disassembleString();
return;
case OperandMemoryAccess:
outputMask(OperandMemoryAccess, stream[word++]);
--numOperands;
// Aligned is the only memory access operand that uses an immediate
// value, and it is also the first operand that uses a value at all.
if (stream[word-1] & MemoryAccessAlignedMask) {
disassembleImmediates(1);
numOperands--;
if (numOperands)
out << " ";
}
disassembleIds(numOperands);
return;
default:
assert(operandClass >= OperandSource && operandClass < OperandOpcode);
if (OperandClassParams[operandClass].bitmask)
outputMask(operandClass, stream[word++]);
else
out << OperandClassParams[operandClass].getName(stream[word++]);
--numOperands;
break;
}
}
return;
}
static void GLSLstd450GetDebugNames(const char** names)
{
for (int i = 0; i < GLSLstd450Count; ++i)
names[i] = "Unknown";
names[GLSLstd450Round] = "Round";
names[GLSLstd450RoundEven] = "RoundEven";
names[GLSLstd450Trunc] = "Trunc";
names[GLSLstd450FAbs] = "FAbs";
names[GLSLstd450SAbs] = "SAbs";
names[GLSLstd450FSign] = "FSign";
names[GLSLstd450SSign] = "SSign";
names[GLSLstd450Floor] = "Floor";
names[GLSLstd450Ceil] = "Ceil";
names[GLSLstd450Fract] = "Fract";
names[GLSLstd450Radians] = "Radians";
names[GLSLstd450Degrees] = "Degrees";
names[GLSLstd450Sin] = "Sin";
names[GLSLstd450Cos] = "Cos";
names[GLSLstd450Tan] = "Tan";
names[GLSLstd450Asin] = "Asin";
names[GLSLstd450Acos] = "Acos";
names[GLSLstd450Atan] = "Atan";
names[GLSLstd450Sinh] = "Sinh";
names[GLSLstd450Cosh] = "Cosh";
names[GLSLstd450Tanh] = "Tanh";
names[GLSLstd450Asinh] = "Asinh";
names[GLSLstd450Acosh] = "Acosh";
names[GLSLstd450Atanh] = "Atanh";
names[GLSLstd450Atan2] = "Atan2";
names[GLSLstd450Pow] = "Pow";
names[GLSLstd450Exp] = "Exp";
names[GLSLstd450Log] = "Log";
names[GLSLstd450Exp2] = "Exp2";
names[GLSLstd450Log2] = "Log2";
names[GLSLstd450Sqrt] = "Sqrt";
names[GLSLstd450InverseSqrt] = "InverseSqrt";
names[GLSLstd450Determinant] = "Determinant";
names[GLSLstd450MatrixInverse] = "MatrixInverse";
names[GLSLstd450Modf] = "Modf";
names[GLSLstd450ModfStruct] = "ModfStruct";
names[GLSLstd450FMin] = "FMin";
names[GLSLstd450SMin] = "SMin";
names[GLSLstd450UMin] = "UMin";
names[GLSLstd450FMax] = "FMax";
names[GLSLstd450SMax] = "SMax";
names[GLSLstd450UMax] = "UMax";
names[GLSLstd450FClamp] = "FClamp";
names[GLSLstd450SClamp] = "SClamp";
names[GLSLstd450UClamp] = "UClamp";
names[GLSLstd450FMix] = "FMix";
names[GLSLstd450Step] = "Step";
names[GLSLstd450SmoothStep] = "SmoothStep";
names[GLSLstd450Fma] = "Fma";
names[GLSLstd450Frexp] = "Frexp";
names[GLSLstd450FrexpStruct] = "FrexpStruct";
names[GLSLstd450Ldexp] = "Ldexp";
names[GLSLstd450PackSnorm4x8] = "PackSnorm4x8";
names[GLSLstd450PackUnorm4x8] = "PackUnorm4x8";
names[GLSLstd450PackSnorm2x16] = "PackSnorm2x16";
names[GLSLstd450PackUnorm2x16] = "PackUnorm2x16";
names[GLSLstd450PackHalf2x16] = "PackHalf2x16";
names[GLSLstd450PackDouble2x32] = "PackDouble2x32";
names[GLSLstd450UnpackSnorm2x16] = "UnpackSnorm2x16";
names[GLSLstd450UnpackUnorm2x16] = "UnpackUnorm2x16";
names[GLSLstd450UnpackHalf2x16] = "UnpackHalf2x16";
names[GLSLstd450UnpackSnorm4x8] = "UnpackSnorm4x8";
names[GLSLstd450UnpackUnorm4x8] = "UnpackUnorm4x8";
names[GLSLstd450UnpackDouble2x32] = "UnpackDouble2x32";
names[GLSLstd450Length] = "Length";
names[GLSLstd450Distance] = "Distance";
names[GLSLstd450Cross] = "Cross";
names[GLSLstd450Normalize] = "Normalize";
names[GLSLstd450FaceForward] = "FaceForward";
names[GLSLstd450Reflect] = "Reflect";
names[GLSLstd450Refract] = "Refract";
names[GLSLstd450FindILsb] = "FindILsb";
names[GLSLstd450FindSMsb] = "FindSMsb";
names[GLSLstd450FindUMsb] = "FindUMsb";
names[GLSLstd450InterpolateAtCentroid] = "InterpolateAtCentroid";
names[GLSLstd450InterpolateAtSample] = "InterpolateAtSample";
names[GLSLstd450InterpolateAtOffset] = "InterpolateAtOffset";
names[GLSLstd450NMin] = "NMin";
names[GLSLstd450NMax] = "NMax";
names[GLSLstd450NClamp] = "NClamp";
}
static const char* GLSLextAMDGetDebugNames(const char* name, unsigned entrypoint)
{
if (strcmp(name, spv::E_SPV_AMD_shader_ballot) == 0) {
switch (entrypoint) {
case SwizzleInvocationsAMD: return "SwizzleInvocationsAMD";
case SwizzleInvocationsMaskedAMD: return "SwizzleInvocationsMaskedAMD";
case WriteInvocationAMD: return "WriteInvocationAMD";
case MbcntAMD: return "MbcntAMD";
default: return "Bad";
}
} else if (strcmp(name, spv::E_SPV_AMD_shader_trinary_minmax) == 0) {
switch (entrypoint) {
case FMin3AMD: return "FMin3AMD";
case UMin3AMD: return "UMin3AMD";
case SMin3AMD: return "SMin3AMD";
case FMax3AMD: return "FMax3AMD";
case UMax3AMD: return "UMax3AMD";
case SMax3AMD: return "SMax3AMD";
case FMid3AMD: return "FMid3AMD";
case UMid3AMD: return "UMid3AMD";
case SMid3AMD: return "SMid3AMD";
default: return "Bad";
}
} else if (strcmp(name, spv::E_SPV_AMD_shader_explicit_vertex_parameter) == 0) {
switch (entrypoint) {
case InterpolateAtVertexAMD: return "InterpolateAtVertexAMD";
default: return "Bad";
}
}
else if (strcmp(name, spv::E_SPV_AMD_gcn_shader) == 0) {
switch (entrypoint) {
case CubeFaceIndexAMD: return "CubeFaceIndexAMD";
case CubeFaceCoordAMD: return "CubeFaceCoordAMD";
case TimeAMD: return "TimeAMD";
default:
break;
}
}
return "Bad";
}
static const char* GLSLextNVGetDebugNames(const char* name, unsigned entrypoint)
{
if (strcmp(name, spv::E_SPV_NV_sample_mask_override_coverage) == 0 ||
strcmp(name, spv::E_SPV_NV_geometry_shader_passthrough) == 0 ||
strcmp(name, spv::E_ARB_shader_viewport_layer_array) == 0 ||
strcmp(name, spv::E_SPV_NV_viewport_array2) == 0 ||
strcmp(name, spv::E_SPV_NVX_multiview_per_view_attributes) == 0 ||
strcmp(name, spv::E_SPV_NV_fragment_shader_barycentric) == 0 ||
strcmp(name, spv::E_SPV_NV_mesh_shader) == 0 ||
strcmp(name, spv::E_SPV_NV_shader_image_footprint) == 0) {
switch (entrypoint) {
// NV builtins
case BuiltInViewportMaskNV: return "ViewportMaskNV";
case BuiltInSecondaryPositionNV: return "SecondaryPositionNV";
case BuiltInSecondaryViewportMaskNV: return "SecondaryViewportMaskNV";
case BuiltInPositionPerViewNV: return "PositionPerViewNV";
case BuiltInViewportMaskPerViewNV: return "ViewportMaskPerViewNV";
case BuiltInBaryCoordNV: return "BaryCoordNV";
case BuiltInBaryCoordNoPerspNV: return "BaryCoordNoPerspNV";
case BuiltInTaskCountNV: return "TaskCountNV";
case BuiltInPrimitiveCountNV: return "PrimitiveCountNV";
case BuiltInPrimitiveIndicesNV: return "PrimitiveIndicesNV";
case BuiltInClipDistancePerViewNV: return "ClipDistancePerViewNV";
case BuiltInCullDistancePerViewNV: return "CullDistancePerViewNV";
case BuiltInLayerPerViewNV: return "LayerPerViewNV";
case BuiltInMeshViewCountNV: return "MeshViewCountNV";
case BuiltInMeshViewIndicesNV: return "MeshViewIndicesNV";
// NV Capabilities
case CapabilityGeometryShaderPassthroughNV: return "GeometryShaderPassthroughNV";
case CapabilityShaderViewportMaskNV: return "ShaderViewportMaskNV";
case CapabilityShaderStereoViewNV: return "ShaderStereoViewNV";
case CapabilityPerViewAttributesNV: return "PerViewAttributesNV";
case CapabilityFragmentBarycentricNV: return "FragmentBarycentricNV";
case CapabilityMeshShadingNV: return "MeshShadingNV";
case CapabilityImageFootprintNV: return "ImageFootprintNV";
case CapabilitySampleMaskOverrideCoverageNV:return "SampleMaskOverrideCoverageNV";
// NV Decorations
case DecorationOverrideCoverageNV: return "OverrideCoverageNV";
case DecorationPassthroughNV: return "PassthroughNV";
case DecorationViewportRelativeNV: return "ViewportRelativeNV";
case DecorationSecondaryViewportRelativeNV: return "SecondaryViewportRelativeNV";
case DecorationPerVertexNV: return "PerVertexNV";
case DecorationPerPrimitiveNV: return "PerPrimitiveNV";
case DecorationPerViewNV: return "PerViewNV";
case DecorationPerTaskNV: return "PerTaskNV";
default: return "Bad";
}
}
return "Bad";
}
static const char* NonSemanticShaderDebugInfo100GetDebugNames(unsigned entrypoint)
{
switch (entrypoint) {
case NonSemanticShaderDebugInfo100DebugInfoNone: return "DebugInfoNone";
case NonSemanticShaderDebugInfo100DebugCompilationUnit: return "DebugCompilationUnit";
case NonSemanticShaderDebugInfo100DebugTypeBasic: return "DebugTypeBasic";
case NonSemanticShaderDebugInfo100DebugTypePointer: return "DebugTypePointer";
case NonSemanticShaderDebugInfo100DebugTypeQualifier: return "DebugTypeQualifier";
case NonSemanticShaderDebugInfo100DebugTypeArray: return "DebugTypeArray";
case NonSemanticShaderDebugInfo100DebugTypeVector: return "DebugTypeVector";
case NonSemanticShaderDebugInfo100DebugTypedef: return "DebugTypedef";
case NonSemanticShaderDebugInfo100DebugTypeFunction: return "DebugTypeFunction";
case NonSemanticShaderDebugInfo100DebugTypeEnum: return "DebugTypeEnum";
case NonSemanticShaderDebugInfo100DebugTypeComposite: return "DebugTypeComposite";
case NonSemanticShaderDebugInfo100DebugTypeMember: return "DebugTypeMember";
case NonSemanticShaderDebugInfo100DebugTypeInheritance: return "DebugTypeInheritance";
case NonSemanticShaderDebugInfo100DebugTypePtrToMember: return "DebugTypePtrToMember";
case NonSemanticShaderDebugInfo100DebugTypeTemplate: return "DebugTypeTemplate";
case NonSemanticShaderDebugInfo100DebugTypeTemplateParameter: return "DebugTypeTemplateParameter";
case NonSemanticShaderDebugInfo100DebugTypeTemplateTemplateParameter: return "DebugTypeTemplateTemplateParameter";
case NonSemanticShaderDebugInfo100DebugTypeTemplateParameterPack: return "DebugTypeTemplateParameterPack";
case NonSemanticShaderDebugInfo100DebugGlobalVariable: return "DebugGlobalVariable";
case NonSemanticShaderDebugInfo100DebugFunctionDeclaration: return "DebugFunctionDeclaration";
case NonSemanticShaderDebugInfo100DebugFunction: return "DebugFunction";
case NonSemanticShaderDebugInfo100DebugLexicalBlock: return "DebugLexicalBlock";
case NonSemanticShaderDebugInfo100DebugLexicalBlockDiscriminator: return "DebugLexicalBlockDiscriminator";
case NonSemanticShaderDebugInfo100DebugScope: return "DebugScope";
case NonSemanticShaderDebugInfo100DebugNoScope: return "DebugNoScope";
case NonSemanticShaderDebugInfo100DebugInlinedAt: return "DebugInlinedAt";
case NonSemanticShaderDebugInfo100DebugLocalVariable: return "DebugLocalVariable";
case NonSemanticShaderDebugInfo100DebugInlinedVariable: return "DebugInlinedVariable";
case NonSemanticShaderDebugInfo100DebugDeclare: return "DebugDeclare";
case NonSemanticShaderDebugInfo100DebugValue: return "DebugValue";
case NonSemanticShaderDebugInfo100DebugOperation: return "DebugOperation";
case NonSemanticShaderDebugInfo100DebugExpression: return "DebugExpression";
case NonSemanticShaderDebugInfo100DebugMacroDef: return "DebugMacroDef";
case NonSemanticShaderDebugInfo100DebugMacroUndef: return "DebugMacroUndef";
case NonSemanticShaderDebugInfo100DebugImportedEntity: return "DebugImportedEntity";
case NonSemanticShaderDebugInfo100DebugSource: return "DebugSource";
case NonSemanticShaderDebugInfo100DebugFunctionDefinition: return "DebugFunctionDefinition";
case NonSemanticShaderDebugInfo100DebugSourceContinued: return "DebugSourceContinued";
case NonSemanticShaderDebugInfo100DebugLine: return "DebugLine";
case NonSemanticShaderDebugInfo100DebugNoLine: return "DebugNoLine";
case NonSemanticShaderDebugInfo100DebugBuildIdentifier: return "DebugBuildIdentifier";
case NonSemanticShaderDebugInfo100DebugStoragePath: return "DebugStoragePath";
case NonSemanticShaderDebugInfo100DebugEntryPoint: return "DebugEntryPoint";
case NonSemanticShaderDebugInfo100DebugTypeMatrix: return "DebugTypeMatrix";
default: return "Bad";
}
return "Bad";
}
void Disassemble(std::ostream& out, const std::vector<unsigned int>& stream)
{
SpirvStream SpirvStream(out, stream);
spv::Parameterize();
GLSLstd450GetDebugNames(GlslStd450DebugNames);
SpirvStream.validate();
SpirvStream.processInstructions();
}
}; // end namespace spv
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/SPVRemapper.h | //
// Copyright (C) 2015 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef SPIRVREMAPPER_H
#define SPIRVREMAPPER_H
#include <string>
#include <vector>
#include <cstdlib>
#include <exception>
namespace spv {
class spirvbin_base_t
{
public:
enum Options {
NONE = 0,
STRIP = (1<<0),
MAP_TYPES = (1<<1),
MAP_NAMES = (1<<2),
MAP_FUNCS = (1<<3),
DCE_FUNCS = (1<<4),
DCE_VARS = (1<<5),
DCE_TYPES = (1<<6),
OPT_LOADSTORE = (1<<7),
OPT_FWD_LS = (1<<8), // EXPERIMENTAL: PRODUCES INVALID SCHEMA-0 SPIRV
MAP_ALL = (MAP_TYPES | MAP_NAMES | MAP_FUNCS),
DCE_ALL = (DCE_FUNCS | DCE_VARS | DCE_TYPES),
OPT_ALL = (OPT_LOADSTORE),
ALL_BUT_STRIP = (MAP_ALL | DCE_ALL | OPT_ALL),
DO_EVERYTHING = (STRIP | ALL_BUT_STRIP)
};
};
} // namespace SPV
#include <functional>
#include <cstdint>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <cassert>
#include "spirv.hpp"
namespace spv {
const Id NoResult = 0;
// class to hold SPIR-V binary data for remapping, DCE, and debug stripping
class spirvbin_t : public spirvbin_base_t
{
public:
spirvbin_t(int verbose = 0) : entryPoint(spv::NoResult), largestNewId(0), verbose(verbose), errorLatch(false)
{ }
virtual ~spirvbin_t() { }
// remap on an existing binary in memory
void remap(std::vector<std::uint32_t>& spv, const std::vector<std::string>& whiteListStrings,
std::uint32_t opts = DO_EVERYTHING);
// remap on an existing binary in memory - legacy interface without white list
void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = DO_EVERYTHING);
// Type for error/log handler functions
typedef std::function<void(const std::string&)> errorfn_t;
typedef std::function<void(const std::string&)> logfn_t;
// Register error/log handling functions (can be lambda fn / functor / etc)
static void registerErrorHandler(errorfn_t handler) { errorHandler = handler; }
static void registerLogHandler(logfn_t handler) { logHandler = handler; }
protected:
// This can be overridden to provide other message behavior if needed
virtual void msg(int minVerbosity, int indent, const std::string& txt) const;
private:
// Local to global, or global to local ID map
typedef std::unordered_map<spv::Id, spv::Id> idmap_t;
typedef std::unordered_set<spv::Id> idset_t;
typedef std::unordered_map<spv::Id, int> blockmap_t;
void remap(std::uint32_t opts = DO_EVERYTHING);
// Map of names to IDs
typedef std::unordered_map<std::string, spv::Id> namemap_t;
typedef std::uint32_t spirword_t;
typedef std::pair<unsigned, unsigned> range_t;
typedef std::function<void(spv::Id&)> idfn_t;
typedef std::function<bool(spv::Op, unsigned start)> instfn_t;
// Special Values for ID map:
static const spv::Id unmapped; // unchanged from default value
static const spv::Id unused; // unused ID
static const int header_size; // SPIR header = 5 words
class id_iterator_t;
// For mapping type entries between different shaders
typedef std::vector<spirword_t> typeentry_t;
typedef std::map<spv::Id, typeentry_t> globaltypes_t;
// A set that preserves position order, and a reverse map
typedef std::set<int> posmap_t;
typedef std::unordered_map<spv::Id, int> posmap_rev_t;
// Maps and ID to the size of its base type, if known.
typedef std::unordered_map<spv::Id, unsigned> typesize_map_t;
// handle error
void error(const std::string& txt) const { errorLatch = true; errorHandler(txt); }
bool isConstOp(spv::Op opCode) const;
bool isTypeOp(spv::Op opCode) const;
bool isStripOp(spv::Op opCode) const;
bool isFlowCtrl(spv::Op opCode) const;
range_t literalRange(spv::Op opCode) const;
range_t typeRange(spv::Op opCode) const;
range_t constRange(spv::Op opCode) const;
unsigned typeSizeInWords(spv::Id id) const;
unsigned idTypeSizeInWords(spv::Id id) const;
bool isStripOp(spv::Op opCode, unsigned start) const;
spv::Id& asId(unsigned word) { return spv[word]; }
const spv::Id& asId(unsigned word) const { return spv[word]; }
spv::Op asOpCode(unsigned word) const { return opOpCode(spv[word]); }
std::uint32_t asOpCodeHash(unsigned word);
spv::Decoration asDecoration(unsigned word) const { return spv::Decoration(spv[word]); }
unsigned asWordCount(unsigned word) const { return opWordCount(spv[word]); }
spv::Id asTypeConstId(unsigned word) const { return asId(word + (isTypeOp(asOpCode(word)) ? 1 : 2)); }
unsigned idPos(spv::Id id) const;
static unsigned opWordCount(spirword_t data) { return data >> spv::WordCountShift; }
static spv::Op opOpCode(spirword_t data) { return spv::Op(data & spv::OpCodeMask); }
// Header access & set methods
spirword_t magic() const { return spv[0]; } // return magic number
spirword_t bound() const { return spv[3]; } // return Id bound from header
spirword_t bound(spirword_t b) { return spv[3] = b; }
spirword_t genmagic() const { return spv[2]; } // generator magic
spirword_t genmagic(spirword_t m) { return spv[2] = m; }
spirword_t schemaNum() const { return spv[4]; } // schema number from header
// Mapping fns: get
spv::Id localId(spv::Id id) const { return idMapL[id]; }
// Mapping fns: set
inline spv::Id localId(spv::Id id, spv::Id newId);
void countIds(spv::Id id);
// Return next unused new local ID.
// NOTE: boost::dynamic_bitset would be more efficient due to find_next(),
// which std::vector<bool> doens't have.
inline spv::Id nextUnusedId(spv::Id id);
void buildLocalMaps();
std::string literalString(unsigned word) const; // Return literal as a std::string
int literalStringWords(const std::string& str) const { return (int(str.size())+4)/4; }
bool isNewIdMapped(spv::Id newId) const { return isMapped(newId); }
bool isOldIdUnmapped(spv::Id oldId) const { return localId(oldId) == unmapped; }
bool isOldIdUnused(spv::Id oldId) const { return localId(oldId) == unused; }
bool isOldIdMapped(spv::Id oldId) const { return !isOldIdUnused(oldId) && !isOldIdUnmapped(oldId); }
bool isFunction(spv::Id oldId) const { return fnPos.find(oldId) != fnPos.end(); }
// bool matchType(const globaltypes_t& globalTypes, spv::Id lt, spv::Id gt) const;
// spv::Id findType(const globaltypes_t& globalTypes, spv::Id lt) const;
std::uint32_t hashType(unsigned typeStart) const;
spirvbin_t& process(instfn_t, idfn_t, unsigned begin = 0, unsigned end = 0);
int processInstruction(unsigned word, instfn_t, idfn_t);
void validate() const;
void mapTypeConst();
void mapFnBodies();
void optLoadStore();
void dceFuncs();
void dceVars();
void dceTypes();
void mapNames();
void foldIds(); // fold IDs to smallest space
void forwardLoadStores(); // load store forwarding (EXPERIMENTAL)
void offsetIds(); // create relative offset IDs
void applyMap(); // remap per local name map
void mapRemainder(); // map any IDs we haven't touched yet
void stripDebug(); // strip all debug info
void stripDeadRefs(); // strips debug info for now-dead references after DCE
void strip(); // remove debug symbols
std::vector<spirword_t> spv; // SPIR words
std::vector<std::string> stripWhiteList;
namemap_t nameMap; // ID names from OpName
// Since we want to also do binary ops, we can't use std::vector<bool>. we could use
// boost::dynamic_bitset, but we're trying to avoid a boost dependency.
typedef std::uint64_t bits_t;
std::vector<bits_t> mapped; // which new IDs have been mapped
static const int mBits = sizeof(bits_t) * 4;
bool isMapped(spv::Id id) const { return id < maxMappedId() && ((mapped[id/mBits] & (1LL<<(id%mBits))) != 0); }
void setMapped(spv::Id id) { resizeMapped(id); mapped[id/mBits] |= (1LL<<(id%mBits)); }
void resizeMapped(spv::Id id) { if (id >= maxMappedId()) mapped.resize(id/mBits+1, 0); }
size_t maxMappedId() const { return mapped.size() * mBits; }
// Add a strip range for a given instruction starting at 'start'
// Note: avoiding brace initializers to please older versions os MSVC.
void stripInst(unsigned start) { stripRange.push_back(range_t(start, start + asWordCount(start))); }
// Function start and end. use unordered_map because we'll have
// many fewer functions than IDs.
std::unordered_map<spv::Id, range_t> fnPos;
// Which functions are called, anywhere in the module, with a call count
std::unordered_map<spv::Id, int> fnCalls;
posmap_t typeConstPos; // word positions that define types & consts (ordered)
posmap_rev_t idPosR; // reverse map from IDs to positions
typesize_map_t idTypeSizeMap; // maps each ID to its type size, if known.
std::vector<spv::Id> idMapL; // ID {M}ap from {L}ocal to {G}lobal IDs
spv::Id entryPoint; // module entry point
spv::Id largestNewId; // biggest new ID we have mapped anything to
// Sections of the binary to strip, given as [begin,end)
std::vector<range_t> stripRange;
// processing options:
std::uint32_t options;
int verbose; // verbosity level
// Error latch: this is set if the error handler is ever executed. It would be better to
// use a try/catch block and throw, but that's not desired for certain environments, so
// this is the alternative.
mutable bool errorLatch;
static errorfn_t errorHandler;
static logfn_t logHandler;
};
} // namespace SPV
#endif // SPIRVREMAPPER_H
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/GLSL.ext.ARM.h | /*
** Copyright (c) 2022 ARM Limited
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and/or associated documentation files (the "Materials"),
** to deal in the Materials without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Materials, and to permit persons to whom the
** Materials are furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Materials.
**
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
** IN THE MATERIALS.
*/
#ifndef GLSLextARM_H
#define GLSLextARM_H
static const int GLSLextARMVersion = 100;
static const int GLSLextARMRevision = 1;
static const char * const E_SPV_ARM_core_builtins = "SPV_ARM_core_builtins";
#endif // #ifndef GLSLextARM_H
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/InReadableOrder.cpp | //
// Copyright (C) 2016 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// The SPIR-V spec requires code blocks to appear in an order satisfying the
// dominator-tree direction (ie, dominator before the dominated). This is,
// actually, easy to achieve: any pre-order CFG traversal algorithm will do it.
// Because such algorithms visit a block only after traversing some path to it
// from the root, they necessarily visit the block's idom first.
//
// But not every graph-traversal algorithm outputs blocks in an order that
// appears logical to human readers. The problem is that unrelated branches may
// be interspersed with each other, and merge blocks may come before some of the
// branches being merged.
//
// A good, human-readable order of blocks may be achieved by performing
// depth-first search but delaying merge nodes until after all their branches
// have been visited. This is implemented below by the inReadableOrder()
// function.
#include "spvIR.h"
#include <cassert>
#include <unordered_set>
using spv::Block;
using spv::Id;
namespace {
// Traverses CFG in a readable order, invoking a pre-set callback on each block.
// Use by calling visit() on the root block.
class ReadableOrderTraverser {
public:
ReadableOrderTraverser(std::function<void(Block*, spv::ReachReason, Block*)> callback)
: callback_(callback) {}
// Visits the block if it hasn't been visited already and isn't currently
// being delayed. Invokes callback(block, why, header), then descends into its
// successors. Delays merge-block and continue-block processing until all
// the branches have been completed. If |block| is an unreachable merge block or
// an unreachable continue target, then |header| is the corresponding header block.
void visit(Block* block, spv::ReachReason why, Block* header)
{
assert(block);
if (why == spv::ReachViaControlFlow) {
reachableViaControlFlow_.insert(block);
}
if (visited_.count(block) || delayed_.count(block))
return;
callback_(block, why, header);
visited_.insert(block);
Block* mergeBlock = nullptr;
Block* continueBlock = nullptr;
auto mergeInst = block->getMergeInstruction();
if (mergeInst) {
Id mergeId = mergeInst->getIdOperand(0);
mergeBlock = block->getParent().getParent().getInstruction(mergeId)->getBlock();
delayed_.insert(mergeBlock);
if (mergeInst->getOpCode() == spv::OpLoopMerge) {
Id continueId = mergeInst->getIdOperand(1);
continueBlock =
block->getParent().getParent().getInstruction(continueId)->getBlock();
delayed_.insert(continueBlock);
}
}
if (why == spv::ReachViaControlFlow) {
const auto& successors = block->getSuccessors();
for (auto it = successors.cbegin(); it != successors.cend(); ++it)
visit(*it, why, nullptr);
}
if (continueBlock) {
const spv::ReachReason continueWhy =
(reachableViaControlFlow_.count(continueBlock) > 0)
? spv::ReachViaControlFlow
: spv::ReachDeadContinue;
delayed_.erase(continueBlock);
visit(continueBlock, continueWhy, block);
}
if (mergeBlock) {
const spv::ReachReason mergeWhy =
(reachableViaControlFlow_.count(mergeBlock) > 0)
? spv::ReachViaControlFlow
: spv::ReachDeadMerge;
delayed_.erase(mergeBlock);
visit(mergeBlock, mergeWhy, block);
}
}
private:
std::function<void(Block*, spv::ReachReason, Block*)> callback_;
// Whether a block has already been visited or is being delayed.
std::unordered_set<Block *> visited_, delayed_;
// The set of blocks that actually are reached via control flow.
std::unordered_set<Block *> reachableViaControlFlow_;
};
}
void spv::inReadableOrder(Block* root, std::function<void(Block*, spv::ReachReason, Block*)> callback)
{
ReadableOrderTraverser(callback).visit(root, spv::ReachViaControlFlow, nullptr);
}
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/GLSL.ext.KHR.h | /*
** Copyright (c) 2014-2020 The Khronos Group Inc.
** Copyright (C) 2022-2024 Arm Limited.
** Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and/or associated documentation files (the "Materials"),
** to deal in the Materials without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Materials, and to permit persons to whom the
** Materials are furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Materials.
**
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
** IN THE MATERIALS.
*/
#ifndef GLSLextKHR_H
#define GLSLextKHR_H
static const int GLSLextKHRVersion = 100;
static const int GLSLextKHRRevision = 3;
static const char* const E_SPV_KHR_shader_ballot = "SPV_KHR_shader_ballot";
static const char* const E_SPV_KHR_subgroup_vote = "SPV_KHR_subgroup_vote";
static const char* const E_SPV_KHR_device_group = "SPV_KHR_device_group";
static const char* const E_SPV_KHR_multiview = "SPV_KHR_multiview";
static const char* const E_SPV_KHR_shader_draw_parameters = "SPV_KHR_shader_draw_parameters";
static const char* const E_SPV_KHR_16bit_storage = "SPV_KHR_16bit_storage";
static const char* const E_SPV_KHR_8bit_storage = "SPV_KHR_8bit_storage";
static const char* const E_SPV_KHR_storage_buffer_storage_class = "SPV_KHR_storage_buffer_storage_class";
static const char* const E_SPV_KHR_post_depth_coverage = "SPV_KHR_post_depth_coverage";
static const char* const E_SPV_KHR_vulkan_memory_model = "SPV_KHR_vulkan_memory_model";
static const char* const E_SPV_EXT_physical_storage_buffer = "SPV_EXT_physical_storage_buffer";
static const char* const E_SPV_KHR_physical_storage_buffer = "SPV_KHR_physical_storage_buffer";
static const char* const E_SPV_EXT_fragment_shader_interlock = "SPV_EXT_fragment_shader_interlock";
static const char* const E_SPV_KHR_shader_clock = "SPV_KHR_shader_clock";
static const char* const E_SPV_KHR_non_semantic_info = "SPV_KHR_non_semantic_info";
static const char* const E_SPV_KHR_ray_tracing = "SPV_KHR_ray_tracing";
static const char* const E_SPV_KHR_ray_query = "SPV_KHR_ray_query";
static const char* const E_SPV_KHR_fragment_shading_rate = "SPV_KHR_fragment_shading_rate";
static const char* const E_SPV_KHR_terminate_invocation = "SPV_KHR_terminate_invocation";
static const char* const E_SPV_KHR_workgroup_memory_explicit_layout = "SPV_KHR_workgroup_memory_explicit_layout";
static const char* const E_SPV_KHR_subgroup_uniform_control_flow = "SPV_KHR_subgroup_uniform_control_flow";
static const char* const E_SPV_KHR_fragment_shader_barycentric = "SPV_KHR_fragment_shader_barycentric";
static const char* const E_SPV_KHR_quad_control = "SPV_KHR_quad_control";
static const char* const E_SPV_AMD_shader_early_and_late_fragment_tests = "SPV_AMD_shader_early_and_late_fragment_tests";
static const char* const E_SPV_KHR_ray_tracing_position_fetch = "SPV_KHR_ray_tracing_position_fetch";
static const char* const E_SPV_KHR_cooperative_matrix = "SPV_KHR_cooperative_matrix";
static const char* const E_SPV_KHR_maximal_reconvergence = "SPV_KHR_maximal_reconvergence";
static const char* const E_SPV_KHR_subgroup_rotate = "SPV_KHR_subgroup_rotate";
static const char* const E_SPV_KHR_expect_assume = "SPV_KHR_expect_assume";
static const char* const E_SPV_EXT_replicated_composites = "SPV_EXT_replicated_composites";
static const char* const E_SPV_KHR_relaxed_extended_instruction = "SPV_KHR_relaxed_extended_instruction";
#endif // #ifndef GLSLextKHR_H
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/doc.h | //
// Copyright (C) 2014-2015 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Parameterize the SPIR-V enumerants.
//
#pragma once
#include "spirv.hpp"
#include <vector>
namespace spv {
// Fill in all the parameters
void Parameterize();
// Return the English names of all the enums.
const char* SourceString(int);
const char* AddressingString(int);
const char* MemoryString(int);
const char* ExecutionModelString(int);
const char* ExecutionModeString(int);
const char* StorageClassString(int);
const char* DecorationString(int);
const char* BuiltInString(int);
const char* DimensionString(int);
const char* SelectControlString(int);
const char* LoopControlString(int);
const char* FunctionControlString(int);
const char* SamplerAddressingModeString(int);
const char* SamplerFilterModeString(int);
const char* ImageFormatString(int);
const char* ImageChannelOrderString(int);
const char* ImageChannelTypeString(int);
const char* ImageChannelDataTypeString(int type);
const char* ImageOperandsString(int format);
const char* ImageOperands(int);
const char* FPFastMathString(int);
const char* FPRoundingModeString(int);
const char* LinkageTypeString(int);
const char* FuncParamAttrString(int);
const char* AccessQualifierString(int);
const char* MemorySemanticsString(int);
const char* MemoryAccessString(int);
const char* ExecutionScopeString(int);
const char* GroupOperationString(int);
const char* KernelEnqueueFlagsString(int);
const char* KernelProfilingInfoString(int);
const char* CapabilityString(int);
const char* OpcodeString(int);
const char* ScopeString(int mem);
// For grouping opcodes into subsections
enum OpcodeClass {
OpClassMisc,
OpClassDebug,
OpClassAnnotate,
OpClassExtension,
OpClassMode,
OpClassType,
OpClassConstant,
OpClassMemory,
OpClassFunction,
OpClassImage,
OpClassConvert,
OpClassComposite,
OpClassArithmetic,
OpClassBit,
OpClassRelationalLogical,
OpClassDerivative,
OpClassFlowControl,
OpClassAtomic,
OpClassPrimitive,
OpClassBarrier,
OpClassGroup,
OpClassDeviceSideEnqueue,
OpClassPipe,
OpClassCount,
OpClassMissing // all instructions start out as missing
};
// For parameterizing operands.
enum OperandClass {
OperandNone,
OperandId,
OperandVariableIds,
OperandOptionalLiteral,
OperandOptionalLiteralString,
OperandVariableLiterals,
OperandVariableIdLiteral,
OperandVariableLiteralId,
OperandLiteralNumber,
OperandLiteralString,
OperandVariableLiteralStrings,
OperandSource,
OperandExecutionModel,
OperandAddressing,
OperandMemory,
OperandExecutionMode,
OperandStorage,
OperandDimensionality,
OperandSamplerAddressingMode,
OperandSamplerFilterMode,
OperandSamplerImageFormat,
OperandImageChannelOrder,
OperandImageChannelDataType,
OperandImageOperands,
OperandFPFastMath,
OperandFPRoundingMode,
OperandLinkageType,
OperandAccessQualifier,
OperandFuncParamAttr,
OperandDecoration,
OperandBuiltIn,
OperandSelect,
OperandLoop,
OperandFunction,
OperandMemorySemantics,
OperandMemoryAccess,
OperandScope,
OperandGroupOperation,
OperandKernelEnqueueFlags,
OperandKernelProfilingInfo,
OperandCapability,
OperandCooperativeMatrixOperands,
OperandOpcode,
OperandCount
};
// Any specific enum can have a set of capabilities that allow it:
typedef std::vector<Capability> EnumCaps;
// Parameterize a set of operands with their OperandClass(es) and descriptions.
class OperandParameters {
public:
OperandParameters() { }
void push(OperandClass oc, const char* d, bool opt = false)
{
opClass.push_back(oc);
desc.push_back(d);
optional.push_back(opt);
}
void setOptional();
OperandClass getClass(int op) const { return opClass[op]; }
const char* getDesc(int op) const { return desc[op]; }
bool isOptional(int op) const { return optional[op]; }
int getNum() const { return (int)opClass.size(); }
protected:
std::vector<OperandClass> opClass;
std::vector<const char*> desc;
std::vector<bool> optional;
};
// Parameterize an enumerant
class EnumParameters {
public:
EnumParameters() : desc(nullptr) { }
const char* desc;
};
// Parameterize a set of enumerants that form an enum
class EnumDefinition : public EnumParameters {
public:
EnumDefinition() :
ceiling(0), bitmask(false), getName(nullptr), enumParams(nullptr), operandParams(nullptr) { }
void set(int ceil, const char* (*name)(int), EnumParameters* ep, bool mask = false)
{
ceiling = ceil;
getName = name;
bitmask = mask;
enumParams = ep;
}
void setOperands(OperandParameters* op) { operandParams = op; }
int ceiling; // ceiling of enumerants
bool bitmask; // true if these enumerants combine into a bitmask
const char* (*getName)(int); // a function that returns the name for each enumerant value (or shift)
EnumParameters* enumParams; // parameters for each individual enumerant
OperandParameters* operandParams; // sets of operands
};
// Parameterize an instruction's logical format, including its known set of operands,
// per OperandParameters above.
class InstructionParameters {
public:
InstructionParameters() :
opDesc("TBD"),
opClass(OpClassMissing),
typePresent(true), // most normal, only exceptions have to be spelled out
resultPresent(true) // most normal, only exceptions have to be spelled out
{ }
void setResultAndType(bool r, bool t)
{
resultPresent = r;
typePresent = t;
}
bool hasResult() const { return resultPresent != 0; }
bool hasType() const { return typePresent != 0; }
const char* opDesc;
OpcodeClass opClass;
OperandParameters operands;
protected:
bool typePresent : 1;
bool resultPresent : 1;
};
// The set of objects that hold all the instruction/operand
// parameterization information.
extern InstructionParameters InstructionDesc[];
// These hold definitions of the enumerants used for operands
extern EnumDefinition OperandClassParams[];
const char* GetOperandDesc(OperandClass operand);
void PrintImmediateRow(int imm, const char* name, const EnumParameters* enumParams, bool caps, bool hex = false);
const char* AccessQualifierString(int attr);
void PrintOperands(const OperandParameters& operands, int reservedOperands);
} // end namespace spv
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/NonSemanticDebugPrintf.h | // Copyright (c) 2020 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and/or associated documentation files (the
// "Materials"), to deal in the Materials without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Materials, and to
// permit persons to whom the Materials are furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Materials.
//
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
// https://www.khronos.org/registry/
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
//
#ifndef SPIRV_UNIFIED1_NonSemanticDebugPrintf_H_
#define SPIRV_UNIFIED1_NonSemanticDebugPrintf_H_
#ifdef __cplusplus
extern "C" {
#endif
enum {
NonSemanticDebugPrintfRevision = 1,
NonSemanticDebugPrintfRevision_BitWidthPadding = 0x7fffffff
};
enum NonSemanticDebugPrintfInstructions {
NonSemanticDebugPrintfDebugPrintf = 1,
NonSemanticDebugPrintfInstructionsMax = 0x7fffffff
};
#ifdef __cplusplus
}
#endif
#endif // SPIRV_UNIFIED1_NonSemanticDebugPrintf_H_
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/GLSL.ext.QCOM.h | /*
** Copyright (c) 2021 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and/or associated documentation files (the "Materials"),
** to deal in the Materials without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Materials, and to permit persons to whom the
** Materials are furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Materials.
**
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
** IN THE MATERIALS.
*/
#ifndef GLSLextQCOM_H
#define GLSLextQCOM_H
enum BuiltIn;
enum Decoration;
enum Op;
enum Capability;
static const int GLSLextQCOMVersion = 100;
static const int GLSLextQCOMRevision = 1;
//SPV_QCOM_image_processing
const char* const E_SPV_QCOM_image_processing = "SPV_QCOM_image_processing";
//SPV_QCOM_image_processing2
const char* const E_SPV_QCOM_image_processing2 = "SPV_QCOM_image_processing2";
#endif // #ifndef GLSLextQCOM_H
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/SpvBuilder.h | //
// Copyright (C) 2014-2015 LunarG, Inc.
// Copyright (C) 2015-2020 Google, Inc.
// Copyright (C) 2017 ARM Limited.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// "Builder" is an interface to fully build SPIR-V IR. Allocate one of
// these to build (a thread safe) internal SPIR-V representation (IR),
// and then dump it as a binary stream according to the SPIR-V specification.
//
// A Builder has a 1:1 relationship with a SPIR-V module.
//
#pragma once
#ifndef SpvBuilder_H
#define SpvBuilder_H
#include "Logger.h"
#include "spirv.hpp"
#include "spvIR.h"
namespace spv {
#include "GLSL.ext.KHR.h"
#include "NonSemanticShaderDebugInfo100.h"
}
#include <algorithm>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <map>
namespace spv {
typedef enum {
Spv_1_0 = (1 << 16),
Spv_1_1 = (1 << 16) | (1 << 8),
Spv_1_2 = (1 << 16) | (2 << 8),
Spv_1_3 = (1 << 16) | (3 << 8),
Spv_1_4 = (1 << 16) | (4 << 8),
Spv_1_5 = (1 << 16) | (5 << 8),
} SpvVersion;
class Builder {
public:
Builder(unsigned int spvVersion, unsigned int userNumber, SpvBuildLogger* logger);
virtual ~Builder();
static const int maxMatrixSize = 4;
unsigned int getSpvVersion() const { return spvVersion; }
void setSource(spv::SourceLanguage lang, int version)
{
sourceLang = lang;
sourceVersion = version;
}
spv::Id getStringId(const std::string& str)
{
auto sItr = stringIds.find(str);
if (sItr != stringIds.end())
return sItr->second;
spv::Id strId = getUniqueId();
Instruction* fileString = new Instruction(strId, NoType, OpString);
const char* file_c_str = str.c_str();
fileString->addStringOperand(file_c_str);
strings.push_back(std::unique_ptr<Instruction>(fileString));
module.mapInstruction(fileString);
stringIds[file_c_str] = strId;
return strId;
}
spv::Id getMainFileId() const { return mainFileId; }
// Initialize the main source file name
void setDebugSourceFile(const std::string& file)
{
if (trackDebugInfo) {
dirtyLineTracker = true;
mainFileId = getStringId(file);
currentFileId = mainFileId;
}
}
// Set the debug source location tracker in the builder.
// The upcoming instructions in basic blocks will be associated to this location.
void setDebugSourceLocation(int line, const char* filename)
{
if (trackDebugInfo) {
dirtyLineTracker = true;
if (line != 0) {
// TODO: This is special handling of some AST nodes having (untracked) line 0.
// But they should have a valid line number.
currentLine = line;
if (filename) {
currentFileId = getStringId(filename);
}
}
}
}
void setSourceText(const std::string& text) { sourceText = text; }
void addSourceExtension(const char* ext) { sourceExtensions.push_back(ext); }
void addModuleProcessed(const std::string& p) { moduleProcesses.push_back(p.c_str()); }
void setEmitSpirvDebugInfo()
{
trackDebugInfo = true;
emitSpirvDebugInfo = true;
}
void setEmitNonSemanticShaderDebugInfo(bool emitSourceText)
{
trackDebugInfo = true;
emitNonSemanticShaderDebugInfo = true;
importNonSemanticShaderDebugInfoInstructions();
if (emitSourceText) {
emitNonSemanticShaderDebugSource = emitSourceText;
}
}
void addExtension(const char* ext) { extensions.insert(ext); }
void removeExtension(const char* ext)
{
extensions.erase(ext);
}
void addIncorporatedExtension(const char* ext, SpvVersion incorporatedVersion)
{
if (getSpvVersion() < static_cast<unsigned>(incorporatedVersion))
addExtension(ext);
}
void promoteIncorporatedExtension(const char* baseExt, const char* promoExt, SpvVersion incorporatedVersion)
{
removeExtension(baseExt);
addIncorporatedExtension(promoExt, incorporatedVersion);
}
void addInclude(const std::string& name, const std::string& text)
{
spv::Id incId = getStringId(name);
includeFiles[incId] = &text;
}
Id import(const char*);
void setMemoryModel(spv::AddressingModel addr, spv::MemoryModel mem)
{
addressModel = addr;
memoryModel = mem;
}
void addCapability(spv::Capability cap) { capabilities.insert(cap); }
// To get a new <id> for anything needing a new one.
Id getUniqueId() { return ++uniqueId; }
// To get a set of new <id>s, e.g., for a set of function parameters
Id getUniqueIds(int numIds)
{
Id id = uniqueId + 1;
uniqueId += numIds;
return id;
}
// For creating new types (will return old type if the requested one was already made).
Id makeVoidType();
Id makeBoolType();
Id makePointer(StorageClass, Id pointee);
Id makeForwardPointer(StorageClass);
Id makePointerFromForwardPointer(StorageClass, Id forwardPointerType, Id pointee);
Id makeIntegerType(int width, bool hasSign); // generic
Id makeIntType(int width) { return makeIntegerType(width, true); }
Id makeUintType(int width) { return makeIntegerType(width, false); }
Id makeFloatType(int width);
Id makeStructType(const std::vector<Id>& members, const char* name, bool const compilerGenerated = true);
Id makeStructResultType(Id type0, Id type1);
Id makeVectorType(Id component, int size);
Id makeMatrixType(Id component, int cols, int rows);
Id makeArrayType(Id element, Id sizeId, int stride); // 0 stride means no stride decoration
Id makeRuntimeArray(Id element);
Id makeFunctionType(Id returnType, const std::vector<Id>& paramTypes);
Id makeImageType(Id sampledType, Dim, bool depth, bool arrayed, bool ms, unsigned sampled, ImageFormat format);
Id makeSamplerType();
Id makeSampledImageType(Id imageType);
Id makeCooperativeMatrixTypeKHR(Id component, Id scope, Id rows, Id cols, Id use);
Id makeCooperativeMatrixTypeNV(Id component, Id scope, Id rows, Id cols);
Id makeCooperativeMatrixTypeWithSameShape(Id component, Id otherType);
Id makeGenericType(spv::Op opcode, std::vector<spv::IdImmediate>& operands);
// SPIR-V NonSemantic Shader DebugInfo Instructions
struct DebugTypeLoc {
std::string name {};
int line {0};
int column {0};
};
std::unordered_map<Id, DebugTypeLoc> debugTypeLocs;
Id makeDebugInfoNone();
Id makeBoolDebugType(int const size);
Id makeIntegerDebugType(int const width, bool const hasSign);
Id makeFloatDebugType(int const width);
Id makeSequentialDebugType(Id const baseType, Id const componentCount, NonSemanticShaderDebugInfo100Instructions const sequenceType);
Id makeArrayDebugType(Id const baseType, Id const componentCount);
Id makeVectorDebugType(Id const baseType, int const componentCount);
Id makeMatrixDebugType(Id const vectorType, int const vectorCount, bool columnMajor = true);
Id makeMemberDebugType(Id const memberType, DebugTypeLoc const& debugTypeLoc);
Id makeCompositeDebugType(std::vector<Id> const& memberTypes, char const*const name,
NonSemanticShaderDebugInfo100DebugCompositeType const tag, bool const isOpaqueType = false);
Id makePointerDebugType(StorageClass storageClass, Id const baseType);
Id makeForwardPointerDebugType(StorageClass storageClass);
Id makeDebugSource(const Id fileName);
Id makeDebugCompilationUnit();
Id createDebugGlobalVariable(Id const type, char const*const name, Id const variable);
Id createDebugLocalVariable(Id type, char const*const name, size_t const argNumber = 0);
Id makeDebugExpression();
Id makeDebugDeclare(Id const debugLocalVariable, Id const pointer);
Id makeDebugValue(Id const debugLocalVariable, Id const value);
Id makeDebugFunctionType(Id returnType, const std::vector<Id>& paramTypes);
Id makeDebugFunction(Function* function, Id nameId, Id funcTypeId);
Id makeDebugLexicalBlock(uint32_t line);
std::string unmangleFunctionName(std::string const& name) const;
void setupDebugFunctionEntry(Function* function, const char* name, int line,
const std::vector<Id>& paramTypes,
const std::vector<char const*>& paramNames);
// accelerationStructureNV type
Id makeAccelerationStructureType();
// rayQueryEXT type
Id makeRayQueryType();
// hitObjectNV type
Id makeHitObjectNVType();
// For querying about types.
Id getTypeId(Id resultId) const { return module.getTypeId(resultId); }
Id getDerefTypeId(Id resultId) const;
Op getOpCode(Id id) const { return module.getInstruction(id)->getOpCode(); }
Op getTypeClass(Id typeId) const { return getOpCode(typeId); }
Op getMostBasicTypeClass(Id typeId) const;
unsigned int getNumComponents(Id resultId) const { return getNumTypeComponents(getTypeId(resultId)); }
unsigned int getNumTypeConstituents(Id typeId) const;
unsigned int getNumTypeComponents(Id typeId) const { return getNumTypeConstituents(typeId); }
Id getScalarTypeId(Id typeId) const;
Id getContainedTypeId(Id typeId) const;
Id getContainedTypeId(Id typeId, int) const;
StorageClass getTypeStorageClass(Id typeId) const { return module.getStorageClass(typeId); }
ImageFormat getImageTypeFormat(Id typeId) const
{ return (ImageFormat)module.getInstruction(typeId)->getImmediateOperand(6); }
Id getResultingAccessChainType() const;
Id getIdOperand(Id resultId, int idx) { return module.getInstruction(resultId)->getIdOperand(idx); }
bool isPointer(Id resultId) const { return isPointerType(getTypeId(resultId)); }
bool isScalar(Id resultId) const { return isScalarType(getTypeId(resultId)); }
bool isVector(Id resultId) const { return isVectorType(getTypeId(resultId)); }
bool isMatrix(Id resultId) const { return isMatrixType(getTypeId(resultId)); }
bool isCooperativeMatrix(Id resultId)const { return isCooperativeMatrixType(getTypeId(resultId)); }
bool isAggregate(Id resultId) const { return isAggregateType(getTypeId(resultId)); }
bool isSampledImage(Id resultId) const { return isSampledImageType(getTypeId(resultId)); }
bool isBoolType(Id typeId)
{ return groupedTypes[OpTypeBool].size() > 0 && typeId == groupedTypes[OpTypeBool].back()->getResultId(); }
bool isIntType(Id typeId) const
{ return getTypeClass(typeId) == OpTypeInt && module.getInstruction(typeId)->getImmediateOperand(1) != 0; }
bool isUintType(Id typeId) const
{ return getTypeClass(typeId) == OpTypeInt && module.getInstruction(typeId)->getImmediateOperand(1) == 0; }
bool isFloatType(Id typeId) const { return getTypeClass(typeId) == OpTypeFloat; }
bool isPointerType(Id typeId) const { return getTypeClass(typeId) == OpTypePointer; }
bool isScalarType(Id typeId) const
{ return getTypeClass(typeId) == OpTypeFloat || getTypeClass(typeId) == OpTypeInt ||
getTypeClass(typeId) == OpTypeBool; }
bool isVectorType(Id typeId) const { return getTypeClass(typeId) == OpTypeVector; }
bool isMatrixType(Id typeId) const { return getTypeClass(typeId) == OpTypeMatrix; }
bool isStructType(Id typeId) const { return getTypeClass(typeId) == OpTypeStruct; }
bool isArrayType(Id typeId) const { return getTypeClass(typeId) == OpTypeArray; }
bool isCooperativeMatrixType(Id typeId)const
{
return getTypeClass(typeId) == OpTypeCooperativeMatrixKHR || getTypeClass(typeId) == OpTypeCooperativeMatrixNV;
}
bool isAggregateType(Id typeId) const
{ return isArrayType(typeId) || isStructType(typeId) || isCooperativeMatrixType(typeId); }
bool isImageType(Id typeId) const { return getTypeClass(typeId) == OpTypeImage; }
bool isSamplerType(Id typeId) const { return getTypeClass(typeId) == OpTypeSampler; }
bool isSampledImageType(Id typeId) const { return getTypeClass(typeId) == OpTypeSampledImage; }
bool containsType(Id typeId, Op typeOp, unsigned int width) const;
bool containsPhysicalStorageBufferOrArray(Id typeId) const;
bool isConstantOpCode(Op opcode) const;
bool isSpecConstantOpCode(Op opcode) const;
bool isConstant(Id resultId) const { return isConstantOpCode(getOpCode(resultId)); }
bool isConstantScalar(Id resultId) const { return getOpCode(resultId) == OpConstant; }
bool isSpecConstant(Id resultId) const { return isSpecConstantOpCode(getOpCode(resultId)); }
unsigned int getConstantScalar(Id resultId) const
{ return module.getInstruction(resultId)->getImmediateOperand(0); }
StorageClass getStorageClass(Id resultId) const { return getTypeStorageClass(getTypeId(resultId)); }
bool isVariableOpCode(Op opcode) const { return opcode == OpVariable; }
bool isVariable(Id resultId) const { return isVariableOpCode(getOpCode(resultId)); }
bool isGlobalStorage(Id resultId) const { return getStorageClass(resultId) != StorageClassFunction; }
bool isGlobalVariable(Id resultId) const { return isVariable(resultId) && isGlobalStorage(resultId); }
// See if a resultId is valid for use as an initializer.
bool isValidInitializer(Id resultId) const { return isConstant(resultId) || isGlobalVariable(resultId); }
int getScalarTypeWidth(Id typeId) const
{
Id scalarTypeId = getScalarTypeId(typeId);
assert(getTypeClass(scalarTypeId) == OpTypeInt || getTypeClass(scalarTypeId) == OpTypeFloat);
return module.getInstruction(scalarTypeId)->getImmediateOperand(0);
}
unsigned int getTypeNumColumns(Id typeId) const
{
assert(isMatrixType(typeId));
return getNumTypeConstituents(typeId);
}
unsigned int getNumColumns(Id resultId) const { return getTypeNumColumns(getTypeId(resultId)); }
unsigned int getTypeNumRows(Id typeId) const
{
assert(isMatrixType(typeId));
return getNumTypeComponents(getContainedTypeId(typeId));
}
unsigned int getNumRows(Id resultId) const { return getTypeNumRows(getTypeId(resultId)); }
Dim getTypeDimensionality(Id typeId) const
{
assert(isImageType(typeId));
return (Dim)module.getInstruction(typeId)->getImmediateOperand(1);
}
Id getImageType(Id resultId) const
{
Id typeId = getTypeId(resultId);
assert(isImageType(typeId) || isSampledImageType(typeId));
return isSampledImageType(typeId) ? module.getInstruction(typeId)->getIdOperand(0) : typeId;
}
bool isArrayedImageType(Id typeId) const
{
assert(isImageType(typeId));
return module.getInstruction(typeId)->getImmediateOperand(3) != 0;
}
// For making new constants (will return old constant if the requested one was already made).
Id makeNullConstant(Id typeId);
Id makeBoolConstant(bool b, bool specConstant = false);
Id makeInt8Constant(int i, bool specConstant = false)
{ return makeIntConstant(makeIntType(8), (unsigned)i, specConstant); }
Id makeUint8Constant(unsigned u, bool specConstant = false)
{ return makeIntConstant(makeUintType(8), u, specConstant); }
Id makeInt16Constant(int i, bool specConstant = false)
{ return makeIntConstant(makeIntType(16), (unsigned)i, specConstant); }
Id makeUint16Constant(unsigned u, bool specConstant = false)
{ return makeIntConstant(makeUintType(16), u, specConstant); }
Id makeIntConstant(int i, bool specConstant = false)
{ return makeIntConstant(makeIntType(32), (unsigned)i, specConstant); }
Id makeUintConstant(unsigned u, bool specConstant = false)
{ return makeIntConstant(makeUintType(32), u, specConstant); }
Id makeInt64Constant(long long i, bool specConstant = false)
{ return makeInt64Constant(makeIntType(64), (unsigned long long)i, specConstant); }
Id makeUint64Constant(unsigned long long u, bool specConstant = false)
{ return makeInt64Constant(makeUintType(64), u, specConstant); }
Id makeFloatConstant(float f, bool specConstant = false);
Id makeDoubleConstant(double d, bool specConstant = false);
Id makeFloat16Constant(float f16, bool specConstant = false);
Id makeFpConstant(Id type, double d, bool specConstant = false);
Id importNonSemanticShaderDebugInfoInstructions();
// Turn the array of constants into a proper spv constant of the requested type.
Id makeCompositeConstant(Id type, const std::vector<Id>& comps, bool specConst = false);
// Methods for adding information outside the CFG.
Instruction* addEntryPoint(ExecutionModel, Function*, const char* name);
void addExecutionMode(Function*, ExecutionMode mode, int value1 = -1, int value2 = -1, int value3 = -1);
void addExecutionMode(Function*, ExecutionMode mode, const std::vector<unsigned>& literals);
void addExecutionModeId(Function*, ExecutionMode mode, const std::vector<Id>& operandIds);
void addName(Id, const char* name);
void addMemberName(Id, int member, const char* name);
void addDecoration(Id, Decoration, int num = -1);
void addDecoration(Id, Decoration, const char*);
void addDecoration(Id, Decoration, const std::vector<unsigned>& literals);
void addDecoration(Id, Decoration, const std::vector<const char*>& strings);
void addLinkageDecoration(Id id, const char* name, spv::LinkageType linkType);
void addDecorationId(Id id, Decoration, Id idDecoration);
void addDecorationId(Id id, Decoration, const std::vector<Id>& operandIds);
void addMemberDecoration(Id, unsigned int member, Decoration, int num = -1);
void addMemberDecoration(Id, unsigned int member, Decoration, const char*);
void addMemberDecoration(Id, unsigned int member, Decoration, const std::vector<unsigned>& literals);
void addMemberDecoration(Id, unsigned int member, Decoration, const std::vector<const char*>& strings);
// At the end of what block do the next create*() instructions go?
// Also reset current last DebugScope and current source line to unknown
void setBuildPoint(Block* bp) {
buildPoint = bp;
// TODO: Technically, change of build point should set line tracker dirty. But we'll have bad line info for
// branch instructions. Commenting this for now because at least this matches the old behavior.
dirtyScopeTracker = true;
}
Block* getBuildPoint() const { return buildPoint; }
// Append an instruction to the end of the current build point.
// Optionally, additional debug info instructions may also be prepended.
void addInstruction(std::unique_ptr<Instruction> inst);
// Make the entry-point function. The returned pointer is only valid
// for the lifetime of this builder.
Function* makeEntryPoint(const char*);
// Make a shader-style function, and create its entry block if entry is non-zero.
// Return the function, pass back the entry.
// The returned pointer is only valid for the lifetime of this builder.
Function* makeFunctionEntry(Decoration precision, Id returnType, const char* name, LinkageType linkType,
const std::vector<Id>& paramTypes,
const std::vector<std::vector<Decoration>>& precisions, Block** entry = nullptr);
// Create a return. An 'implicit' return is one not appearing in the source
// code. In the case of an implicit return, no post-return block is inserted.
void makeReturn(bool implicit, Id retVal = 0);
// Initialize state and generate instructions for new lexical scope
void enterLexicalBlock(uint32_t line);
// Set state and generate instructions to exit current lexical scope
void leaveLexicalBlock();
// Prepare builder for generation of instructions for a function.
void enterFunction(Function const* function);
// Generate all the code needed to finish up a function.
void leaveFunction();
// Create block terminator instruction for certain statements like
// discard, terminate-invocation, terminateRayEXT, or ignoreIntersectionEXT
void makeStatementTerminator(spv::Op opcode, const char *name);
// Create block terminator instruction for statements that have input operands
// such as OpEmitMeshTasksEXT
void makeStatementTerminator(spv::Op opcode, const std::vector<Id>& operands, const char* name);
// Create a global or function local or IO variable.
Id createVariable(Decoration precision, StorageClass storageClass, Id type, const char* name = nullptr,
Id initializer = NoResult, bool const compilerGenerated = true);
// Create an intermediate with an undefined value.
Id createUndefined(Id type);
// Store into an Id and return the l-value
void createStore(Id rValue, Id lValue, spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone,
spv::Scope scope = spv::ScopeMax, unsigned int alignment = 0);
// Load from an Id and return it
Id createLoad(Id lValue, spv::Decoration precision,
spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone,
spv::Scope scope = spv::ScopeMax, unsigned int alignment = 0);
// Create an OpAccessChain instruction
Id createAccessChain(StorageClass, Id base, const std::vector<Id>& offsets);
// Create an OpArrayLength instruction
Id createArrayLength(Id base, unsigned int member);
// Create an OpCooperativeMatrixLengthKHR instruction
Id createCooperativeMatrixLengthKHR(Id type);
// Create an OpCooperativeMatrixLengthNV instruction
Id createCooperativeMatrixLengthNV(Id type);
// Create an OpCompositeExtract instruction
Id createCompositeExtract(Id composite, Id typeId, unsigned index);
Id createCompositeExtract(Id composite, Id typeId, const std::vector<unsigned>& indexes);
Id createCompositeInsert(Id object, Id composite, Id typeId, unsigned index);
Id createCompositeInsert(Id object, Id composite, Id typeId, const std::vector<unsigned>& indexes);
Id createVectorExtractDynamic(Id vector, Id typeId, Id componentIndex);
Id createVectorInsertDynamic(Id vector, Id typeId, Id component, Id componentIndex);
void createNoResultOp(Op);
void createNoResultOp(Op, Id operand);
void createNoResultOp(Op, const std::vector<Id>& operands);
void createNoResultOp(Op, const std::vector<IdImmediate>& operands);
void createControlBarrier(Scope execution, Scope memory, MemorySemanticsMask);
void createMemoryBarrier(unsigned executionScope, unsigned memorySemantics);
Id createUnaryOp(Op, Id typeId, Id operand);
Id createBinOp(Op, Id typeId, Id operand1, Id operand2);
Id createTriOp(Op, Id typeId, Id operand1, Id operand2, Id operand3);
Id createOp(Op, Id typeId, const std::vector<Id>& operands);
Id createOp(Op, Id typeId, const std::vector<IdImmediate>& operands);
Id createFunctionCall(spv::Function*, const std::vector<spv::Id>&);
Id createSpecConstantOp(Op, Id typeId, const std::vector<spv::Id>& operands, const std::vector<unsigned>& literals);
// Take an rvalue (source) and a set of channels to extract from it to
// make a new rvalue, which is returned.
Id createRvalueSwizzle(Decoration precision, Id typeId, Id source, const std::vector<unsigned>& channels);
// Take a copy of an lvalue (target) and a source of components, and set the
// source components into the lvalue where the 'channels' say to put them.
// An updated version of the target is returned.
// (No true lvalue or stores are used.)
Id createLvalueSwizzle(Id typeId, Id target, Id source, const std::vector<unsigned>& channels);
// If both the id and precision are valid, the id
// gets tagged with the requested precision.
// The passed in id is always the returned id, to simplify use patterns.
Id setPrecision(Id id, Decoration precision)
{
if (precision != NoPrecision && id != NoResult)
addDecoration(id, precision);
return id;
}
// Can smear a scalar to a vector for the following forms:
// - promoteScalar(scalar, vector) // smear scalar to width of vector
// - promoteScalar(vector, scalar) // smear scalar to width of vector
// - promoteScalar(pointer, scalar) // smear scalar to width of what pointer points to
// - promoteScalar(scalar, scalar) // do nothing
// Other forms are not allowed.
//
// Generally, the type of 'scalar' does not need to be the same type as the components in 'vector'.
// The type of the created vector is a vector of components of the same type as the scalar.
//
// Note: One of the arguments will change, with the result coming back that way rather than
// through the return value.
void promoteScalar(Decoration precision, Id& left, Id& right);
// Make a value by smearing the scalar to fill the type.
// vectorType should be the correct type for making a vector of scalarVal.
// (No conversions are done.)
Id smearScalar(Decoration precision, Id scalarVal, Id vectorType);
// Create a call to a built-in function.
Id createBuiltinCall(Id resultType, Id builtins, int entryPoint, const std::vector<Id>& args);
// List of parameters used to create a texture operation
struct TextureParameters {
Id sampler;
Id coords;
Id bias;
Id lod;
Id Dref;
Id offset;
Id offsets;
Id gradX;
Id gradY;
Id sample;
Id component;
Id texelOut;
Id lodClamp;
Id granularity;
Id coarse;
bool nonprivate;
bool volatil;
};
// Select the correct texture operation based on all inputs, and emit the correct instruction
Id createTextureCall(Decoration precision, Id resultType, bool sparse, bool fetch, bool proj, bool gather,
bool noImplicit, const TextureParameters&, ImageOperandsMask);
// Emit the OpTextureQuery* instruction that was passed in.
// Figure out the right return value and type, and return it.
Id createTextureQueryCall(Op, const TextureParameters&, bool isUnsignedResult);
Id createSamplePositionCall(Decoration precision, Id, Id);
Id createBitFieldExtractCall(Decoration precision, Id, Id, Id, bool isSigned);
Id createBitFieldInsertCall(Decoration precision, Id, Id, Id, Id);
// Reduction comparison for composites: For equal and not-equal resulting in a scalar.
Id createCompositeCompare(Decoration precision, Id, Id, bool /* true if for equal, false if for not-equal */);
// OpCompositeConstruct
Id createCompositeConstruct(Id typeId, const std::vector<Id>& constituents);
// vector or scalar constructor
Id createConstructor(Decoration precision, const std::vector<Id>& sources, Id resultTypeId);
// matrix constructor
Id createMatrixConstructor(Decoration precision, const std::vector<Id>& sources, Id constructee);
// Helper to use for building nested control flow with if-then-else.
class If {
public:
If(Id condition, unsigned int ctrl, Builder& builder);
~If() {}
void makeBeginElse();
void makeEndIf();
private:
If(const If&);
If& operator=(If&);
Builder& builder;
Id condition;
unsigned int control;
Function* function;
Block* headerBlock;
Block* thenBlock;
Block* elseBlock;
Block* mergeBlock;
};
// Make a switch statement. A switch has 'numSegments' of pieces of code, not containing
// any case/default labels, all separated by one or more case/default labels. Each possible
// case value v is a jump to the caseValues[v] segment. The defaultSegment is also in this
// number space. How to compute the value is given by 'condition', as in switch(condition).
//
// The SPIR-V Builder will maintain the stack of post-switch merge blocks for nested switches.
//
// Use a defaultSegment < 0 if there is no default segment (to branch to post switch).
//
// Returns the right set of basic blocks to start each code segment with, so that the caller's
// recursion stack can hold the memory for it.
//
void makeSwitch(Id condition, unsigned int control, int numSegments, const std::vector<int>& caseValues,
const std::vector<int>& valueToSegment, int defaultSegment, std::vector<Block*>& segmentBB);
// Add a branch to the innermost switch's merge block.
void addSwitchBreak();
// Move to the next code segment, passing in the return argument in makeSwitch()
void nextSwitchSegment(std::vector<Block*>& segmentBB, int segment);
// Finish off the innermost switch.
void endSwitch(std::vector<Block*>& segmentBB);
struct LoopBlocks {
LoopBlocks(Block& head, Block& body, Block& merge, Block& continue_target) :
head(head), body(body), merge(merge), continue_target(continue_target) { }
Block &head, &body, &merge, &continue_target;
private:
LoopBlocks();
LoopBlocks& operator=(const LoopBlocks&) = delete;
};
// Start a new loop and prepare the builder to generate code for it. Until
// closeLoop() is called for this loop, createLoopContinue() and
// createLoopExit() will target its corresponding blocks.
LoopBlocks& makeNewLoop();
// Create a new block in the function containing the build point. Memory is
// owned by the function object.
Block& makeNewBlock();
// Add a branch to the continue_target of the current (innermost) loop.
void createLoopContinue();
// Add an exit (e.g. "break") from the innermost loop that we're currently
// in.
void createLoopExit();
// Close the innermost loop that you're in
void closeLoop();
//
// Access chain design for an R-Value vs. L-Value:
//
// There is a single access chain the builder is building at
// any particular time. Such a chain can be used to either to a load or
// a store, when desired.
//
// Expressions can be r-values, l-values, or both, or only r-values:
// a[b.c].d = .... // l-value
// ... = a[b.c].d; // r-value, that also looks like an l-value
// ++a[b.c].d; // r-value and l-value
// (x + y)[2]; // r-value only, can't possibly be l-value
//
// Computing an r-value means generating code. Hence,
// r-values should only be computed when they are needed, not speculatively.
//
// Computing an l-value means saving away information for later use in the compiler,
// no code is generated until the l-value is later dereferenced. It is okay
// to speculatively generate an l-value, just not okay to speculatively dereference it.
//
// The base of the access chain (the left-most variable or expression
// from which everything is based) can be set either as an l-value
// or as an r-value. Most efficient would be to set an l-value if one
// is available. If an expression was evaluated, the resulting r-value
// can be set as the chain base.
//
// The users of this single access chain can save and restore if they
// want to nest or manage multiple chains.
//
struct AccessChain {
Id base; // for l-values, pointer to the base object, for r-values, the base object
std::vector<Id> indexChain;
Id instr; // cache the instruction that generates this access chain
std::vector<unsigned> swizzle; // each std::vector element selects the next GLSL component number
Id component; // a dynamic component index, can coexist with a swizzle,
// done after the swizzle, NoResult if not present
Id preSwizzleBaseType; // dereferenced type, before swizzle or component is applied;
// NoType unless a swizzle or component is present
bool isRValue; // true if 'base' is an r-value, otherwise, base is an l-value
unsigned int alignment; // bitwise OR of alignment values passed in. Accumulates worst alignment.
// Only tracks base and (optional) component selection alignment.
// Accumulate whether anything in the chain of structures has coherent decorations.
struct CoherentFlags {
CoherentFlags() { clear(); }
bool isVolatile() const { return volatil; }
bool isNonUniform() const { return nonUniform; }
bool anyCoherent() const {
return coherent || devicecoherent || queuefamilycoherent || workgroupcoherent ||
subgroupcoherent || shadercallcoherent;
}
unsigned coherent : 1;
unsigned devicecoherent : 1;
unsigned queuefamilycoherent : 1;
unsigned workgroupcoherent : 1;
unsigned subgroupcoherent : 1;
unsigned shadercallcoherent : 1;
unsigned nonprivate : 1;
unsigned volatil : 1;
unsigned isImage : 1;
unsigned nonUniform : 1;
void clear() {
coherent = 0;
devicecoherent = 0;
queuefamilycoherent = 0;
workgroupcoherent = 0;
subgroupcoherent = 0;
shadercallcoherent = 0;
nonprivate = 0;
volatil = 0;
isImage = 0;
nonUniform = 0;
}
CoherentFlags operator |=(const CoherentFlags &other) {
coherent |= other.coherent;
devicecoherent |= other.devicecoherent;
queuefamilycoherent |= other.queuefamilycoherent;
workgroupcoherent |= other.workgroupcoherent;
subgroupcoherent |= other.subgroupcoherent;
shadercallcoherent |= other.shadercallcoherent;
nonprivate |= other.nonprivate;
volatil |= other.volatil;
isImage |= other.isImage;
nonUniform |= other.nonUniform;
return *this;
}
};
CoherentFlags coherentFlags;
};
//
// the SPIR-V builder maintains a single active chain that
// the following methods operate on
//
// for external save and restore
AccessChain getAccessChain() { return accessChain; }
void setAccessChain(AccessChain newChain) { accessChain = newChain; }
// clear accessChain
void clearAccessChain();
// set new base as an l-value base
void setAccessChainLValue(Id lValue)
{
assert(isPointer(lValue));
accessChain.base = lValue;
}
// set new base value as an r-value
void setAccessChainRValue(Id rValue)
{
accessChain.isRValue = true;
accessChain.base = rValue;
}
// push offset onto the end of the chain
void accessChainPush(Id offset, AccessChain::CoherentFlags coherentFlags, unsigned int alignment)
{
accessChain.indexChain.push_back(offset);
accessChain.coherentFlags |= coherentFlags;
accessChain.alignment |= alignment;
}
// push new swizzle onto the end of any existing swizzle, merging into a single swizzle
void accessChainPushSwizzle(std::vector<unsigned>& swizzle, Id preSwizzleBaseType,
AccessChain::CoherentFlags coherentFlags, unsigned int alignment);
// push a dynamic component selection onto the access chain, only applicable with a
// non-trivial swizzle or no swizzle
void accessChainPushComponent(Id component, Id preSwizzleBaseType, AccessChain::CoherentFlags coherentFlags,
unsigned int alignment)
{
if (accessChain.swizzle.size() != 1) {
accessChain.component = component;
if (accessChain.preSwizzleBaseType == NoType)
accessChain.preSwizzleBaseType = preSwizzleBaseType;
}
accessChain.coherentFlags |= coherentFlags;
accessChain.alignment |= alignment;
}
// use accessChain and swizzle to store value
void accessChainStore(Id rvalue, Decoration nonUniform,
spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone,
spv::Scope scope = spv::ScopeMax, unsigned int alignment = 0);
// use accessChain and swizzle to load an r-value
Id accessChainLoad(Decoration precision, Decoration l_nonUniform, Decoration r_nonUniform, Id ResultType,
spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone, spv::Scope scope = spv::ScopeMax,
unsigned int alignment = 0);
// Return whether or not the access chain can be represented in SPIR-V
// as an l-value.
// E.g., a[3].yx cannot be, while a[3].y and a[3].y[x] can be.
bool isSpvLvalue() const { return accessChain.swizzle.size() <= 1; }
// get the direct pointer for an l-value
Id accessChainGetLValue();
// Get the inferred SPIR-V type of the result of the current access chain,
// based on the type of the base and the chain of dereferences.
Id accessChainGetInferredType();
// Add capabilities, extensions, remove unneeded decorations, etc.,
// based on the resulting SPIR-V.
void postProcess(bool compileOnly);
// Prune unreachable blocks in the CFG and remove unneeded decorations.
void postProcessCFG();
// Add capabilities, extensions based on instructions in the module.
void postProcessFeatures();
// Hook to visit each instruction in a block in a function
void postProcess(Instruction&);
// Hook to visit each non-32-bit sized float/int operation in a block.
void postProcessType(const Instruction&, spv::Id typeId);
// move OpSampledImage instructions to be next to their users.
void postProcessSamplers();
void dump(std::vector<unsigned int>&) const;
void createBranch(Block* block);
void createConditionalBranch(Id condition, Block* thenBlock, Block* elseBlock);
void createLoopMerge(Block* mergeBlock, Block* continueBlock, unsigned int control,
const std::vector<unsigned int>& operands);
// Sets to generate opcode for specialization constants.
void setToSpecConstCodeGenMode() { generatingOpCodeForSpecConst = true; }
// Sets to generate opcode for non-specialization constants (normal mode).
void setToNormalCodeGenMode() { generatingOpCodeForSpecConst = false; }
// Check if the builder is generating code for spec constants.
bool isInSpecConstCodeGenMode() { return generatingOpCodeForSpecConst; }
void setUseReplicatedComposites(bool use) { useReplicatedComposites = use; }
protected:
Id makeIntConstant(Id typeId, unsigned value, bool specConstant);
Id makeInt64Constant(Id typeId, unsigned long long value, bool specConstant);
Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned value);
Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned v1, unsigned v2);
Id findCompositeConstant(Op typeClass, Id typeId, const std::vector<Id>& comps);
Id findStructConstant(Id typeId, const std::vector<Id>& comps);
Id collapseAccessChain();
void remapDynamicSwizzle();
void transferAccessChainSwizzle(bool dynamic);
void simplifyAccessChainSwizzle();
void createAndSetNoPredecessorBlock(const char*);
void createSelectionMerge(Block* mergeBlock, unsigned int control);
void dumpSourceInstructions(std::vector<unsigned int>&) const;
void dumpSourceInstructions(const spv::Id fileId, const std::string& text, std::vector<unsigned int>&) const;
void dumpInstructions(std::vector<unsigned int>&, const std::vector<std::unique_ptr<Instruction> >&) const;
void dumpModuleProcesses(std::vector<unsigned int>&) const;
spv::MemoryAccessMask sanitizeMemoryAccessForStorageClass(spv::MemoryAccessMask memoryAccess, StorageClass sc)
const;
unsigned int spvVersion; // the version of SPIR-V to emit in the header
SourceLanguage sourceLang;
int sourceVersion;
spv::Id nonSemanticShaderCompilationUnitId {0};
spv::Id nonSemanticShaderDebugInfo {0};
spv::Id debugInfoNone {0};
spv::Id debugExpression {0}; // Debug expression with zero operations.
std::string sourceText;
// True if an new OpLine/OpDebugLine may need to be inserted. Either:
// 1. The current debug location changed
// 2. The current build point changed
bool dirtyLineTracker;
int currentLine = 0;
// OpString id of the current file name. Always 0 if debug info is off.
spv::Id currentFileId = 0;
// OpString id of the main file name. Always 0 if debug info is off.
spv::Id mainFileId = 0;
// True if an new OpDebugScope may need to be inserted. Either:
// 1. A new lexical block is pushed
// 2. The current build point changed
bool dirtyScopeTracker;
std::stack<spv::Id> currentDebugScopeId;
// This flag toggles tracking of debug info while building the SPIR-V.
bool trackDebugInfo = false;
// This flag toggles emission of SPIR-V debug instructions, like OpLine and OpSource.
bool emitSpirvDebugInfo = false;
// This flag toggles emission of Non-Semantic Debug extension debug instructions.
bool emitNonSemanticShaderDebugInfo = false;
bool restoreNonSemanticShaderDebugInfo = false;
bool emitNonSemanticShaderDebugSource = false;
std::set<std::string> extensions;
std::vector<const char*> sourceExtensions;
std::vector<const char*> moduleProcesses;
AddressingModel addressModel;
MemoryModel memoryModel;
std::set<spv::Capability> capabilities;
int builderNumber;
Module module;
Block* buildPoint;
Id uniqueId;
Function* entryPointFunction;
bool generatingOpCodeForSpecConst;
bool useReplicatedComposites { false };
AccessChain accessChain;
// special blocks of instructions for output
std::vector<std::unique_ptr<Instruction> > strings;
std::vector<std::unique_ptr<Instruction> > imports;
std::vector<std::unique_ptr<Instruction> > entryPoints;
std::vector<std::unique_ptr<Instruction> > executionModes;
std::vector<std::unique_ptr<Instruction> > names;
std::vector<std::unique_ptr<Instruction> > decorations;
std::vector<std::unique_ptr<Instruction> > constantsTypesGlobals;
std::vector<std::unique_ptr<Instruction> > externals;
std::vector<std::unique_ptr<Function> > functions;
// not output, internally used for quick & dirty canonical (unique) creation
// map type opcodes to constant inst.
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedConstants;
// map struct-id to constant instructions
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedStructConstants;
// map type opcodes to type instructions
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedTypes;
// map type opcodes to debug type instructions
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedDebugTypes;
// list of OpConstantNull instructions
std::vector<Instruction*> nullConstants;
// stack of switches
std::stack<Block*> switchMerges;
// Our loop stack.
std::stack<LoopBlocks> loops;
// map from strings to their string ids
std::unordered_map<std::string, spv::Id> stringIds;
// map from include file name ids to their contents
std::map<spv::Id, const std::string*> includeFiles;
// map from core id to debug id
std::map <spv::Id, spv::Id> debugId;
// map from file name string id to DebugSource id
std::unordered_map<spv::Id, spv::Id> debugSourceId;
// The stream for outputting warnings and errors.
SpvBuildLogger* logger;
}; // end Builder class
}; // end spv namespace
#endif // SpvBuilder_H
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/spvIR.h | //
// Copyright (C) 2014 LunarG, Inc.
// Copyright (C) 2015-2018 Google, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// SPIRV-IR
//
// Simple in-memory representation (IR) of SPIRV. Just for holding
// Each function's CFG of blocks. Has this hierarchy:
// - Module, which is a list of
// - Function, which is a list of
// - Block, which is a list of
// - Instruction
//
#pragma once
#ifndef spvIR_H
#define spvIR_H
#include "spirv.hpp"
#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <memory>
#include <vector>
#include <set>
#include <optional>
namespace spv {
class Block;
class Function;
class Module;
const Id NoResult = 0;
const Id NoType = 0;
const Decoration NoPrecision = DecorationMax;
#ifdef __GNUC__
# define POTENTIALLY_UNUSED __attribute__((unused))
#else
# define POTENTIALLY_UNUSED
#endif
POTENTIALLY_UNUSED
const MemorySemanticsMask MemorySemanticsAllMemory =
(MemorySemanticsMask)(MemorySemanticsUniformMemoryMask |
MemorySemanticsWorkgroupMemoryMask |
MemorySemanticsAtomicCounterMemoryMask |
MemorySemanticsImageMemoryMask);
struct IdImmediate {
bool isId; // true if word is an Id, false if word is an immediate
unsigned word;
IdImmediate(bool i, unsigned w) : isId(i), word(w) {}
};
//
// SPIR-V IR instruction.
//
class Instruction {
public:
Instruction(Id resultId, Id typeId, Op opCode) : resultId(resultId), typeId(typeId), opCode(opCode), block(nullptr) { }
explicit Instruction(Op opCode) : resultId(NoResult), typeId(NoType), opCode(opCode), block(nullptr) { }
virtual ~Instruction() {}
void reserveOperands(size_t count) {
operands.reserve(count);
idOperand.reserve(count);
}
void addIdOperand(Id id) {
// ids can't be 0
assert(id);
operands.push_back(id);
idOperand.push_back(true);
}
// This method is potentially dangerous as it can break assumptions
// about SSA and lack of forward references.
void setIdOperand(unsigned idx, Id id) {
assert(id);
assert(idOperand[idx]);
operands[idx] = id;
}
void addImmediateOperand(unsigned int immediate) {
operands.push_back(immediate);
idOperand.push_back(false);
}
void setImmediateOperand(unsigned idx, unsigned int immediate) {
assert(!idOperand[idx]);
operands[idx] = immediate;
}
void addStringOperand(const char* str)
{
unsigned int word = 0;
unsigned int shiftAmount = 0;
char c;
do {
c = *(str++);
word |= ((unsigned int)c) << shiftAmount;
shiftAmount += 8;
if (shiftAmount == 32) {
addImmediateOperand(word);
word = 0;
shiftAmount = 0;
}
} while (c != 0);
// deal with partial last word
if (shiftAmount > 0) {
addImmediateOperand(word);
}
}
bool isIdOperand(int op) const { return idOperand[op]; }
void setBlock(Block* b) { block = b; }
Block* getBlock() const { return block; }
Op getOpCode() const { return opCode; }
int getNumOperands() const
{
assert(operands.size() == idOperand.size());
return (int)operands.size();
}
Id getResultId() const { return resultId; }
Id getTypeId() const { return typeId; }
Id getIdOperand(int op) const {
assert(idOperand[op]);
return operands[op];
}
unsigned int getImmediateOperand(int op) const {
assert(!idOperand[op]);
return operands[op];
}
// Write out the binary form.
void dump(std::vector<unsigned int>& out) const
{
// Compute the wordCount
unsigned int wordCount = 1;
if (typeId)
++wordCount;
if (resultId)
++wordCount;
wordCount += (unsigned int)operands.size();
// Write out the beginning of the instruction
out.push_back(((wordCount) << WordCountShift) | opCode);
if (typeId)
out.push_back(typeId);
if (resultId)
out.push_back(resultId);
// Write out the operands
for (int op = 0; op < (int)operands.size(); ++op)
out.push_back(operands[op]);
}
protected:
Instruction(const Instruction&);
Id resultId;
Id typeId;
Op opCode;
std::vector<Id> operands; // operands, both <id> and immediates (both are unsigned int)
std::vector<bool> idOperand; // true for operands that are <id>, false for immediates
Block* block;
};
//
// SPIR-V IR block.
//
struct DebugSourceLocation {
int line;
int column;
spv::Id fileId;
};
class Block {
public:
Block(Id id, Function& parent);
virtual ~Block()
{
}
Id getId() { return instructions.front()->getResultId(); }
Function& getParent() const { return parent; }
// Returns true if the source location is actually updated.
// Note we still need the builder to insert the line marker instruction. This is just a tracker.
bool updateDebugSourceLocation(int line, int column, spv::Id fileId) {
if (currentSourceLoc && currentSourceLoc->line == line && currentSourceLoc->column == column &&
currentSourceLoc->fileId == fileId) {
return false;
}
currentSourceLoc = DebugSourceLocation{line, column, fileId};
return true;
}
// Returns true if the scope is actually updated.
// Note we still need the builder to insert the debug scope instruction. This is just a tracker.
bool updateDebugScope(spv::Id scopeId) {
assert(scopeId);
if (currentDebugScope && *currentDebugScope == scopeId) {
return false;
}
currentDebugScope = scopeId;
return true;
}
void addInstruction(std::unique_ptr<Instruction> inst);
void addPredecessor(Block* pred) { predecessors.push_back(pred); pred->successors.push_back(this);}
void addLocalVariable(std::unique_ptr<Instruction> inst) { localVariables.push_back(std::move(inst)); }
const std::vector<Block*>& getPredecessors() const { return predecessors; }
const std::vector<Block*>& getSuccessors() const { return successors; }
std::vector<std::unique_ptr<Instruction> >& getInstructions() {
return instructions;
}
const std::vector<std::unique_ptr<Instruction> >& getLocalVariables() const { return localVariables; }
void setUnreachable() { unreachable = true; }
bool isUnreachable() const { return unreachable; }
// Returns the block's merge instruction, if one exists (otherwise null).
const Instruction* getMergeInstruction() const {
if (instructions.size() < 2) return nullptr;
const Instruction* nextToLast = (instructions.cend() - 2)->get();
switch (nextToLast->getOpCode()) {
case OpSelectionMerge:
case OpLoopMerge:
return nextToLast;
default:
return nullptr;
}
return nullptr;
}
// Change this block into a canonical dead merge block. Delete instructions
// as necessary. A canonical dead merge block has only an OpLabel and an
// OpUnreachable.
void rewriteAsCanonicalUnreachableMerge() {
assert(localVariables.empty());
// Delete all instructions except for the label.
assert(instructions.size() > 0);
instructions.resize(1);
successors.clear();
addInstruction(std::unique_ptr<Instruction>(new Instruction(OpUnreachable)));
}
// Change this block into a canonical dead continue target branching to the
// given header ID. Delete instructions as necessary. A canonical dead continue
// target has only an OpLabel and an unconditional branch back to the corresponding
// header.
void rewriteAsCanonicalUnreachableContinue(Block* header) {
assert(localVariables.empty());
// Delete all instructions except for the label.
assert(instructions.size() > 0);
instructions.resize(1);
successors.clear();
// Add OpBranch back to the header.
assert(header != nullptr);
Instruction* branch = new Instruction(OpBranch);
branch->addIdOperand(header->getId());
addInstruction(std::unique_ptr<Instruction>(branch));
successors.push_back(header);
}
bool isTerminated() const
{
switch (instructions.back()->getOpCode()) {
case OpBranch:
case OpBranchConditional:
case OpSwitch:
case OpKill:
case OpTerminateInvocation:
case OpReturn:
case OpReturnValue:
case OpUnreachable:
return true;
default:
return false;
}
}
void dump(std::vector<unsigned int>& out) const
{
instructions[0]->dump(out);
for (int i = 0; i < (int)localVariables.size(); ++i)
localVariables[i]->dump(out);
for (int i = 1; i < (int)instructions.size(); ++i)
instructions[i]->dump(out);
}
protected:
Block(const Block&);
Block& operator=(Block&);
// To enforce keeping parent and ownership in sync:
friend Function;
std::vector<std::unique_ptr<Instruction> > instructions;
std::vector<Block*> predecessors, successors;
std::vector<std::unique_ptr<Instruction> > localVariables;
Function& parent;
// Track source location of the last source location marker instruction.
std::optional<DebugSourceLocation> currentSourceLoc;
// Track scope of the last debug scope instruction.
std::optional<spv::Id> currentDebugScope;
// track whether this block is known to be uncreachable (not necessarily
// true for all unreachable blocks, but should be set at least
// for the extraneous ones introduced by the builder).
bool unreachable;
};
// The different reasons for reaching a block in the inReadableOrder traversal.
enum ReachReason {
// Reachable from the entry block via transfers of control, i.e. branches.
ReachViaControlFlow = 0,
// A continue target that is not reachable via control flow.
ReachDeadContinue,
// A merge block that is not reachable via control flow.
ReachDeadMerge
};
// Traverses the control-flow graph rooted at root in an order suited for
// readable code generation. Invokes callback at every node in the traversal
// order. The callback arguments are:
// - the block,
// - the reason we reached the block,
// - if the reason was that block is an unreachable continue or unreachable merge block
// then the last parameter is the corresponding header block.
void inReadableOrder(Block* root, std::function<void(Block*, ReachReason, Block* header)> callback);
//
// SPIR-V IR Function.
//
class Function {
public:
Function(Id id, Id resultType, Id functionType, Id firstParam, LinkageType linkage, const std::string& name, Module& parent);
virtual ~Function()
{
for (int i = 0; i < (int)parameterInstructions.size(); ++i)
delete parameterInstructions[i];
for (int i = 0; i < (int)blocks.size(); ++i)
delete blocks[i];
}
Id getId() const { return functionInstruction.getResultId(); }
Id getParamId(int p) const { return parameterInstructions[p]->getResultId(); }
Id getParamType(int p) const { return parameterInstructions[p]->getTypeId(); }
void addBlock(Block* block) { blocks.push_back(block); }
void removeBlock(Block* block)
{
auto found = find(blocks.begin(), blocks.end(), block);
assert(found != blocks.end());
blocks.erase(found);
delete block;
}
Module& getParent() const { return parent; }
Block* getEntryBlock() const { return blocks.front(); }
Block* getLastBlock() const { return blocks.back(); }
const std::vector<Block*>& getBlocks() const { return blocks; }
void addLocalVariable(std::unique_ptr<Instruction> inst);
Id getReturnType() const { return functionInstruction.getTypeId(); }
Id getFuncId() const { return functionInstruction.getResultId(); }
Id getFuncTypeId() const { return functionInstruction.getIdOperand(1); }
void setReturnPrecision(Decoration precision)
{
if (precision == DecorationRelaxedPrecision)
reducedPrecisionReturn = true;
}
Decoration getReturnPrecision() const
{ return reducedPrecisionReturn ? DecorationRelaxedPrecision : NoPrecision; }
void setDebugLineInfo(Id fileName, int line, int column) {
lineInstruction = std::unique_ptr<Instruction>{new Instruction(OpLine)};
lineInstruction->reserveOperands(3);
lineInstruction->addIdOperand(fileName);
lineInstruction->addImmediateOperand(line);
lineInstruction->addImmediateOperand(column);
}
bool hasDebugLineInfo() const { return lineInstruction != nullptr; }
void setImplicitThis() { implicitThis = true; }
bool hasImplicitThis() const { return implicitThis; }
void addParamPrecision(unsigned param, Decoration precision)
{
if (precision == DecorationRelaxedPrecision)
reducedPrecisionParams.insert(param);
}
Decoration getParamPrecision(unsigned param) const
{
return reducedPrecisionParams.find(param) != reducedPrecisionParams.end() ?
DecorationRelaxedPrecision : NoPrecision;
}
void dump(std::vector<unsigned int>& out) const
{
// OpLine
if (lineInstruction != nullptr) {
lineInstruction->dump(out);
}
// OpFunction
functionInstruction.dump(out);
// OpFunctionParameter
for (int p = 0; p < (int)parameterInstructions.size(); ++p)
parameterInstructions[p]->dump(out);
// Blocks
inReadableOrder(blocks[0], [&out](const Block* b, ReachReason, Block*) { b->dump(out); });
Instruction end(0, 0, OpFunctionEnd);
end.dump(out);
}
LinkageType getLinkType() const { return linkType; }
const char* getExportName() const { return exportName.c_str(); }
protected:
Function(const Function&);
Function& operator=(Function&);
Module& parent;
std::unique_ptr<Instruction> lineInstruction;
Instruction functionInstruction;
std::vector<Instruction*> parameterInstructions;
std::vector<Block*> blocks;
bool implicitThis; // true if this is a member function expecting to be passed a 'this' as the first argument
bool reducedPrecisionReturn;
std::set<int> reducedPrecisionParams; // list of parameter indexes that need a relaxed precision arg
LinkageType linkType;
std::string exportName;
};
//
// SPIR-V IR Module.
//
class Module {
public:
Module() {}
virtual ~Module()
{
// TODO delete things
}
void addFunction(Function *fun) { functions.push_back(fun); }
void mapInstruction(Instruction *instruction)
{
spv::Id resultId = instruction->getResultId();
// map the instruction's result id
if (resultId >= idToInstruction.size())
idToInstruction.resize(resultId + 16);
idToInstruction[resultId] = instruction;
}
Instruction* getInstruction(Id id) const { return idToInstruction[id]; }
const std::vector<Function*>& getFunctions() const { return functions; }
spv::Id getTypeId(Id resultId) const {
return idToInstruction[resultId] == nullptr ? NoType : idToInstruction[resultId]->getTypeId();
}
StorageClass getStorageClass(Id typeId) const
{
assert(idToInstruction[typeId]->getOpCode() == spv::OpTypePointer);
return (StorageClass)idToInstruction[typeId]->getImmediateOperand(0);
}
void dump(std::vector<unsigned int>& out) const
{
for (int f = 0; f < (int)functions.size(); ++f)
functions[f]->dump(out);
}
protected:
Module(const Module&);
std::vector<Function*> functions;
// map from result id to instruction having that result id
std::vector<Instruction*> idToInstruction;
// map from a result id to its type id
};
//
// Implementation (it's here due to circular type definitions).
//
// Add both
// - the OpFunction instruction
// - all the OpFunctionParameter instructions
__inline Function::Function(Id id, Id resultType, Id functionType, Id firstParamId, LinkageType linkage, const std::string& name, Module& parent)
: parent(parent), lineInstruction(nullptr),
functionInstruction(id, resultType, OpFunction), implicitThis(false),
reducedPrecisionReturn(false),
linkType(linkage)
{
// OpFunction
functionInstruction.reserveOperands(2);
functionInstruction.addImmediateOperand(FunctionControlMaskNone);
functionInstruction.addIdOperand(functionType);
parent.mapInstruction(&functionInstruction);
parent.addFunction(this);
// OpFunctionParameter
Instruction* typeInst = parent.getInstruction(functionType);
int numParams = typeInst->getNumOperands() - 1;
for (int p = 0; p < numParams; ++p) {
Instruction* param = new Instruction(firstParamId + p, typeInst->getIdOperand(p + 1), OpFunctionParameter);
parent.mapInstruction(param);
parameterInstructions.push_back(param);
}
// If importing/exporting, save the function name (without the mangled parameters) for the linkage decoration
if (linkType != LinkageTypeMax) {
exportName = name.substr(0, name.find_first_of('('));
}
}
__inline void Function::addLocalVariable(std::unique_ptr<Instruction> inst)
{
Instruction* raw_instruction = inst.get();
blocks[0]->addLocalVariable(std::move(inst));
parent.mapInstruction(raw_instruction);
}
__inline Block::Block(Id id, Function& parent) : parent(parent), unreachable(false)
{
instructions.push_back(std::unique_ptr<Instruction>(new Instruction(id, NoType, OpLabel)));
instructions.back()->setBlock(this);
parent.getParent().mapInstruction(instructions.back().get());
}
__inline void Block::addInstruction(std::unique_ptr<Instruction> inst)
{
Instruction* raw_instruction = inst.get();
instructions.push_back(std::move(inst));
raw_instruction->setBlock(this);
if (raw_instruction->getResultId())
parent.getParent().mapInstruction(raw_instruction);
}
} // end spv namespace
#endif // spvIR_H
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/GLSL.ext.EXT.h | /*
** Copyright (c) 2014-2016 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and/or associated documentation files (the "Materials"),
** to deal in the Materials without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Materials, and to permit persons to whom the
** Materials are furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Materials.
**
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
** IN THE MATERIALS.
*/
#ifndef GLSLextEXT_H
#define GLSLextEXT_H
static const int GLSLextEXTVersion = 100;
static const int GLSLextEXTRevision = 2;
static const char* const E_SPV_EXT_shader_stencil_export = "SPV_EXT_shader_stencil_export";
static const char* const E_SPV_EXT_shader_viewport_index_layer = "SPV_EXT_shader_viewport_index_layer";
static const char* const E_SPV_EXT_fragment_fully_covered = "SPV_EXT_fragment_fully_covered";
static const char* const E_SPV_EXT_fragment_invocation_density = "SPV_EXT_fragment_invocation_density";
static const char* const E_SPV_EXT_demote_to_helper_invocation = "SPV_EXT_demote_to_helper_invocation";
static const char* const E_SPV_EXT_shader_atomic_float_add = "SPV_EXT_shader_atomic_float_add";
static const char* const E_SPV_EXT_shader_atomic_float16_add = "SPV_EXT_shader_atomic_float16_add";
static const char* const E_SPV_EXT_shader_atomic_float_min_max = "SPV_EXT_shader_atomic_float_min_max";
static const char* const E_SPV_EXT_shader_image_int64 = "SPV_EXT_shader_image_int64";
static const char* const E_SPV_EXT_shader_tile_image = "SPV_EXT_shader_tile_image";
static const char* const E_SPV_EXT_mesh_shader = "SPV_EXT_mesh_shader";
static const char* const E_SPV_ARM_cooperative_matrix_layouts = "SPV_ARM_cooperative_matrix_layouts";
#endif // #ifndef GLSLextEXT_H
|
0 | repos/glslang.zig/glslang | repos/glslang.zig/glslang/SPIRV/SPVRemapper.cpp | //
// Copyright (C) 2015 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "SPVRemapper.h"
#include "doc.h"
#include <algorithm>
#include <cassert>
#include "../glslang/Include/Common.h"
namespace spv {
// By default, just abort on error. Can be overridden via RegisterErrorHandler
spirvbin_t::errorfn_t spirvbin_t::errorHandler = [](const std::string&) { exit(5); };
// By default, eat log messages. Can be overridden via RegisterLogHandler
spirvbin_t::logfn_t spirvbin_t::logHandler = [](const std::string&) { };
// This can be overridden to provide other message behavior if needed
void spirvbin_t::msg(int minVerbosity, int indent, const std::string& txt) const
{
if (verbose >= minVerbosity)
logHandler(std::string(indent, ' ') + txt);
}
// hash opcode, with special handling for OpExtInst
std::uint32_t spirvbin_t::asOpCodeHash(unsigned word)
{
const spv::Op opCode = asOpCode(word);
std::uint32_t offset = 0;
switch (opCode) {
case spv::OpExtInst:
offset += asId(word + 4); break;
default:
break;
}
return opCode * 19 + offset; // 19 = small prime
}
spirvbin_t::range_t spirvbin_t::literalRange(spv::Op opCode) const
{
static const int maxCount = 1<<30;
switch (opCode) {
case spv::OpTypeFloat: // fall through...
case spv::OpTypePointer: return range_t(2, 3);
case spv::OpTypeInt: return range_t(2, 4);
// TODO: case spv::OpTypeImage:
// TODO: case spv::OpTypeSampledImage:
case spv::OpTypeSampler: return range_t(3, 8);
case spv::OpTypeVector: // fall through
case spv::OpTypeMatrix: // ...
case spv::OpTypePipe: return range_t(3, 4);
case spv::OpConstant: return range_t(3, maxCount);
default: return range_t(0, 0);
}
}
spirvbin_t::range_t spirvbin_t::typeRange(spv::Op opCode) const
{
static const int maxCount = 1<<30;
if (isConstOp(opCode))
return range_t(1, 2);
switch (opCode) {
case spv::OpTypeVector: // fall through
case spv::OpTypeMatrix: // ...
case spv::OpTypeSampler: // ...
case spv::OpTypeArray: // ...
case spv::OpTypeRuntimeArray: // ...
case spv::OpTypePipe: return range_t(2, 3);
case spv::OpTypeStruct: // fall through
case spv::OpTypeFunction: return range_t(2, maxCount);
case spv::OpTypePointer: return range_t(3, 4);
default: return range_t(0, 0);
}
}
spirvbin_t::range_t spirvbin_t::constRange(spv::Op opCode) const
{
static const int maxCount = 1<<30;
switch (opCode) {
case spv::OpTypeArray: // fall through...
case spv::OpTypeRuntimeArray: return range_t(3, 4);
case spv::OpConstantComposite: return range_t(3, maxCount);
default: return range_t(0, 0);
}
}
// Return the size of a type in 32-bit words. This currently only
// handles ints and floats, and is only invoked by queries which must be
// integer types. If ever needed, it can be generalized.
unsigned spirvbin_t::typeSizeInWords(spv::Id id) const
{
const unsigned typeStart = idPos(id);
const spv::Op opCode = asOpCode(typeStart);
if (errorLatch)
return 0;
switch (opCode) {
case spv::OpTypeInt: // fall through...
case spv::OpTypeFloat: return (spv[typeStart+2]+31)/32;
default:
return 0;
}
}
// Looks up the type of a given const or variable ID, and
// returns its size in 32-bit words.
unsigned spirvbin_t::idTypeSizeInWords(spv::Id id) const
{
const auto tid_it = idTypeSizeMap.find(id);
if (tid_it == idTypeSizeMap.end()) {
error("type size for ID not found");
return 0;
}
return tid_it->second;
}
// Is this an opcode we should remove when using --strip?
bool spirvbin_t::isStripOp(spv::Op opCode, unsigned start) const
{
switch (opCode) {
case spv::OpSource:
case spv::OpSourceExtension:
case spv::OpName:
case spv::OpMemberName:
case spv::OpLine :
{
const std::string name = literalString(start + 2);
std::vector<std::string>::const_iterator it;
for (it = stripWhiteList.begin(); it < stripWhiteList.end(); it++)
{
if (name.find(*it) != std::string::npos) {
return false;
}
}
return true;
}
default :
return false;
}
}
// Return true if this opcode is flow control
bool spirvbin_t::isFlowCtrl(spv::Op opCode) const
{
switch (opCode) {
case spv::OpBranchConditional:
case spv::OpBranch:
case spv::OpSwitch:
case spv::OpLoopMerge:
case spv::OpSelectionMerge:
case spv::OpLabel:
case spv::OpFunction:
case spv::OpFunctionEnd: return true;
default: return false;
}
}
// Return true if this opcode defines a type
bool spirvbin_t::isTypeOp(spv::Op opCode) const
{
switch (opCode) {
case spv::OpTypeVoid:
case spv::OpTypeBool:
case spv::OpTypeInt:
case spv::OpTypeFloat:
case spv::OpTypeVector:
case spv::OpTypeMatrix:
case spv::OpTypeImage:
case spv::OpTypeSampler:
case spv::OpTypeArray:
case spv::OpTypeRuntimeArray:
case spv::OpTypeStruct:
case spv::OpTypeOpaque:
case spv::OpTypePointer:
case spv::OpTypeFunction:
case spv::OpTypeEvent:
case spv::OpTypeDeviceEvent:
case spv::OpTypeReserveId:
case spv::OpTypeQueue:
case spv::OpTypeSampledImage:
case spv::OpTypePipe: return true;
default: return false;
}
}
// Return true if this opcode defines a constant
bool spirvbin_t::isConstOp(spv::Op opCode) const
{
switch (opCode) {
case spv::OpConstantSampler:
error("unimplemented constant type");
return true;
case spv::OpConstantNull:
case spv::OpConstantTrue:
case spv::OpConstantFalse:
case spv::OpConstantComposite:
case spv::OpConstant:
return true;
default:
return false;
}
}
const auto inst_fn_nop = [](spv::Op, unsigned) { return false; };
const auto op_fn_nop = [](spv::Id&) { };
// g++ doesn't like these defined in the class proper in an anonymous namespace.
// Dunno why. Also MSVC doesn't like the constexpr keyword. Also dunno why.
// Defining them externally seems to please both compilers, so, here they are.
const spv::Id spirvbin_t::unmapped = spv::Id(-10000);
const spv::Id spirvbin_t::unused = spv::Id(-10001);
const int spirvbin_t::header_size = 5;
spv::Id spirvbin_t::nextUnusedId(spv::Id id)
{
while (isNewIdMapped(id)) // search for an unused ID
++id;
return id;
}
spv::Id spirvbin_t::localId(spv::Id id, spv::Id newId)
{
//assert(id != spv::NoResult && newId != spv::NoResult);
if (id > bound()) {
error(std::string("ID out of range: ") + std::to_string(id));
return spirvbin_t::unused;
}
if (id >= idMapL.size())
idMapL.resize(id+1, unused);
if (newId != unmapped && newId != unused) {
if (isOldIdUnused(id)) {
error(std::string("ID unused in module: ") + std::to_string(id));
return spirvbin_t::unused;
}
if (!isOldIdUnmapped(id)) {
error(std::string("ID already mapped: ") + std::to_string(id) + " -> "
+ std::to_string(localId(id)));
return spirvbin_t::unused;
}
if (isNewIdMapped(newId)) {
error(std::string("ID already used in module: ") + std::to_string(newId));
return spirvbin_t::unused;
}
msg(4, 4, std::string("map: ") + std::to_string(id) + " -> " + std::to_string(newId));
setMapped(newId);
largestNewId = std::max(largestNewId, newId);
}
return idMapL[id] = newId;
}
// Parse a literal string from the SPIR binary and return it as an std::string
// Due to C++11 RValue references, this doesn't copy the result string.
std::string spirvbin_t::literalString(unsigned word) const
{
std::string literal;
const spirword_t * pos = spv.data() + word;
literal.reserve(16);
do {
spirword_t word = *pos;
for (int i = 0; i < 4; i++) {
char c = word & 0xff;
if (c == '\0')
return literal;
literal += c;
word >>= 8;
}
pos++;
} while (true);
}
void spirvbin_t::applyMap()
{
msg(3, 2, std::string("Applying map: "));
// Map local IDs through the ID map
process(inst_fn_nop, // ignore instructions
[this](spv::Id& id) {
id = localId(id);
if (errorLatch)
return;
assert(id != unused && id != unmapped);
}
);
}
// Find free IDs for anything we haven't mapped
void spirvbin_t::mapRemainder()
{
msg(3, 2, std::string("Remapping remainder: "));
spv::Id unusedId = 1; // can't use 0: that's NoResult
spirword_t maxBound = 0;
for (spv::Id id = 0; id < idMapL.size(); ++id) {
if (isOldIdUnused(id))
continue;
// Find a new mapping for any used but unmapped IDs
if (isOldIdUnmapped(id)) {
localId(id, unusedId = nextUnusedId(unusedId));
if (errorLatch)
return;
}
if (isOldIdUnmapped(id)) {
error(std::string("old ID not mapped: ") + std::to_string(id));
return;
}
// Track max bound
maxBound = std::max(maxBound, localId(id) + 1);
if (errorLatch)
return;
}
bound(maxBound); // reset header ID bound to as big as it now needs to be
}
// Mark debug instructions for stripping
void spirvbin_t::stripDebug()
{
// Strip instructions in the stripOp set: debug info.
process(
[&](spv::Op opCode, unsigned start) {
// remember opcodes we want to strip later
if (isStripOp(opCode, start))
stripInst(start);
return true;
},
op_fn_nop);
}
// Mark instructions that refer to now-removed IDs for stripping
void spirvbin_t::stripDeadRefs()
{
process(
[&](spv::Op opCode, unsigned start) {
// strip opcodes pointing to removed data
switch (opCode) {
case spv::OpName:
case spv::OpMemberName:
case spv::OpDecorate:
case spv::OpMemberDecorate:
if (idPosR.find(asId(start+1)) == idPosR.end())
stripInst(start);
break;
default:
break; // leave it alone
}
return true;
},
op_fn_nop);
strip();
}
// Update local maps of ID, type, etc positions
void spirvbin_t::buildLocalMaps()
{
msg(2, 2, std::string("build local maps: "));
mapped.clear();
idMapL.clear();
// preserve nameMap, so we don't clear that.
fnPos.clear();
fnCalls.clear();
typeConstPos.clear();
idPosR.clear();
entryPoint = spv::NoResult;
largestNewId = 0;
idMapL.resize(bound(), unused);
int fnStart = 0;
spv::Id fnRes = spv::NoResult;
// build local Id and name maps
process(
[&](spv::Op opCode, unsigned start) {
unsigned word = start+1;
spv::Id typeId = spv::NoResult;
if (spv::InstructionDesc[opCode].hasType())
typeId = asId(word++);
// If there's a result ID, remember the size of its type
if (spv::InstructionDesc[opCode].hasResult()) {
const spv::Id resultId = asId(word++);
idPosR[resultId] = start;
if (typeId != spv::NoResult) {
const unsigned idTypeSize = typeSizeInWords(typeId);
if (errorLatch)
return false;
if (idTypeSize != 0)
idTypeSizeMap[resultId] = idTypeSize;
}
}
if (opCode == spv::Op::OpName) {
const spv::Id target = asId(start+1);
const std::string name = literalString(start+2);
nameMap[name] = target;
} else if (opCode == spv::Op::OpFunctionCall) {
++fnCalls[asId(start + 3)];
} else if (opCode == spv::Op::OpEntryPoint) {
entryPoint = asId(start + 2);
} else if (opCode == spv::Op::OpFunction) {
if (fnStart != 0) {
error("nested function found");
return false;
}
fnStart = start;
fnRes = asId(start + 2);
} else if (opCode == spv::Op::OpFunctionEnd) {
assert(fnRes != spv::NoResult);
if (fnStart == 0) {
error("function end without function start");
return false;
}
fnPos[fnRes] = range_t(fnStart, start + asWordCount(start));
fnStart = 0;
} else if (isConstOp(opCode)) {
if (errorLatch)
return false;
assert(asId(start + 2) != spv::NoResult);
typeConstPos.insert(start);
} else if (isTypeOp(opCode)) {
assert(asId(start + 1) != spv::NoResult);
typeConstPos.insert(start);
}
return false;
},
[this](spv::Id& id) { localId(id, unmapped); }
);
}
// Validate the SPIR header
void spirvbin_t::validate() const
{
msg(2, 2, std::string("validating: "));
if (spv.size() < header_size) {
error("file too short: ");
return;
}
if (magic() != spv::MagicNumber) {
error("bad magic number");
return;
}
// field 1 = version
// field 2 = generator magic
// field 3 = result <id> bound
if (schemaNum() != 0) {
error("bad schema, must be 0");
return;
}
}
int spirvbin_t::processInstruction(unsigned word, instfn_t instFn, idfn_t idFn)
{
const auto instructionStart = word;
const unsigned wordCount = asWordCount(instructionStart);
const int nextInst = word++ + wordCount;
spv::Op opCode = asOpCode(instructionStart);
if (nextInst > int(spv.size())) {
error("spir instruction terminated too early");
return -1;
}
// Base for computing number of operands; will be updated as more is learned
unsigned numOperands = wordCount - 1;
if (instFn(opCode, instructionStart))
return nextInst;
// Read type and result ID from instruction desc table
if (spv::InstructionDesc[opCode].hasType()) {
idFn(asId(word++));
--numOperands;
}
if (spv::InstructionDesc[opCode].hasResult()) {
idFn(asId(word++));
--numOperands;
}
// Extended instructions: currently, assume everything is an ID.
// TODO: add whatever data we need for exceptions to that
if (opCode == spv::OpExtInst) {
idFn(asId(word)); // Instruction set is an ID that also needs to be mapped
word += 2; // instruction set, and instruction from set
numOperands -= 2;
for (unsigned op=0; op < numOperands; ++op)
idFn(asId(word++)); // ID
return nextInst;
}
// Circular buffer so we can look back at previous unmapped values during the mapping pass.
static const unsigned idBufferSize = 4;
spv::Id idBuffer[idBufferSize];
unsigned idBufferPos = 0;
// Store IDs from instruction in our map
for (int op = 0; numOperands > 0; ++op, --numOperands) {
// SpecConstantOp is special: it includes the operands of another opcode which is
// given as a literal in the 3rd word. We will switch over to pretending that the
// opcode being processed is the literal opcode value of the SpecConstantOp. See the
// SPIRV spec for details. This way we will handle IDs and literals as appropriate for
// the embedded op.
if (opCode == spv::OpSpecConstantOp) {
if (op == 0) {
opCode = asOpCode(word++); // this is the opcode embedded in the SpecConstantOp.
--numOperands;
}
}
switch (spv::InstructionDesc[opCode].operands.getClass(op)) {
case spv::OperandId:
case spv::OperandScope:
case spv::OperandMemorySemantics:
idBuffer[idBufferPos] = asId(word);
idBufferPos = (idBufferPos + 1) % idBufferSize;
idFn(asId(word++));
break;
case spv::OperandVariableIds:
for (unsigned i = 0; i < numOperands; ++i)
idFn(asId(word++));
return nextInst;
case spv::OperandVariableLiterals:
// for clarity
// if (opCode == spv::OpDecorate && asDecoration(word - 1) == spv::DecorationBuiltIn) {
// ++word;
// --numOperands;
// }
// word += numOperands;
return nextInst;
case spv::OperandVariableLiteralId: {
if (opCode == OpSwitch) {
// word-2 is the position of the selector ID. OpSwitch Literals match its type.
// In case the IDs are currently being remapped, we get the word[-2] ID from
// the circular idBuffer.
const unsigned literalSizePos = (idBufferPos+idBufferSize-2) % idBufferSize;
const unsigned literalSize = idTypeSizeInWords(idBuffer[literalSizePos]);
const unsigned numLiteralIdPairs = (nextInst-word) / (1+literalSize);
if (errorLatch)
return -1;
for (unsigned arg=0; arg<numLiteralIdPairs; ++arg) {
word += literalSize; // literal
idFn(asId(word++)); // label
}
} else {
assert(0); // currentely, only OpSwitch uses OperandVariableLiteralId
}
return nextInst;
}
case spv::OperandLiteralString: {
const int stringWordCount = literalStringWords(literalString(word));
word += stringWordCount;
numOperands -= (stringWordCount-1); // -1 because for() header post-decrements
break;
}
case spv::OperandVariableLiteralStrings:
return nextInst;
// Execution mode might have extra literal operands. Skip them.
case spv::OperandExecutionMode:
return nextInst;
// Single word operands we simply ignore, as they hold no IDs
case spv::OperandLiteralNumber:
case spv::OperandSource:
case spv::OperandExecutionModel:
case spv::OperandAddressing:
case spv::OperandMemory:
case spv::OperandStorage:
case spv::OperandDimensionality:
case spv::OperandSamplerAddressingMode:
case spv::OperandSamplerFilterMode:
case spv::OperandSamplerImageFormat:
case spv::OperandImageChannelOrder:
case spv::OperandImageChannelDataType:
case spv::OperandImageOperands:
case spv::OperandFPFastMath:
case spv::OperandFPRoundingMode:
case spv::OperandLinkageType:
case spv::OperandAccessQualifier:
case spv::OperandFuncParamAttr:
case spv::OperandDecoration:
case spv::OperandBuiltIn:
case spv::OperandSelect:
case spv::OperandLoop:
case spv::OperandFunction:
case spv::OperandMemoryAccess:
case spv::OperandGroupOperation:
case spv::OperandKernelEnqueueFlags:
case spv::OperandKernelProfilingInfo:
case spv::OperandCapability:
case spv::OperandCooperativeMatrixOperands:
++word;
break;
default:
assert(0 && "Unhandled Operand Class");
break;
}
}
return nextInst;
}
// Make a pass over all the instructions and process them given appropriate functions
spirvbin_t& spirvbin_t::process(instfn_t instFn, idfn_t idFn, unsigned begin, unsigned end)
{
// For efficiency, reserve name map space. It can grow if needed.
nameMap.reserve(32);
// If begin or end == 0, use defaults
begin = (begin == 0 ? header_size : begin);
end = (end == 0 ? unsigned(spv.size()) : end);
// basic parsing and InstructionDesc table borrowed from SpvDisassemble.cpp...
unsigned nextInst = unsigned(spv.size());
for (unsigned word = begin; word < end; word = nextInst) {
nextInst = processInstruction(word, instFn, idFn);
if (errorLatch)
return *this;
}
return *this;
}
// Apply global name mapping to a single module
void spirvbin_t::mapNames()
{
static const std::uint32_t softTypeIdLimit = 3011; // small prime. TODO: get from options
static const std::uint32_t firstMappedID = 3019; // offset into ID space
for (const auto& name : nameMap) {
std::uint32_t hashval = 1911;
for (const char c : name.first)
hashval = hashval * 1009 + c;
if (isOldIdUnmapped(name.second)) {
localId(name.second, nextUnusedId(hashval % softTypeIdLimit + firstMappedID));
if (errorLatch)
return;
}
}
}
// Map fn contents to IDs of similar functions in other modules
void spirvbin_t::mapFnBodies()
{
static const std::uint32_t softTypeIdLimit = 19071; // small prime. TODO: get from options
static const std::uint32_t firstMappedID = 6203; // offset into ID space
// Initial approach: go through some high priority opcodes first and assign them
// hash values.
spv::Id fnId = spv::NoResult;
std::vector<unsigned> instPos;
instPos.reserve(unsigned(spv.size()) / 16); // initial estimate; can grow if needed.
// Build local table of instruction start positions
process(
[&](spv::Op, unsigned start) { instPos.push_back(start); return true; },
op_fn_nop);
if (errorLatch)
return;
// Window size for context-sensitive canonicalization values
// Empirical best size from a single data set. TODO: Would be a good tunable.
// We essentially perform a little convolution around each instruction,
// to capture the flavor of nearby code, to hopefully match to similar
// code in other modules.
static const unsigned windowSize = 2;
for (unsigned entry = 0; entry < unsigned(instPos.size()); ++entry) {
const unsigned start = instPos[entry];
const spv::Op opCode = asOpCode(start);
if (opCode == spv::OpFunction)
fnId = asId(start + 2);
if (opCode == spv::OpFunctionEnd)
fnId = spv::NoResult;
if (fnId != spv::NoResult) { // if inside a function
if (spv::InstructionDesc[opCode].hasResult()) {
const unsigned word = start + (spv::InstructionDesc[opCode].hasType() ? 2 : 1);
const spv::Id resId = asId(word);
std::uint32_t hashval = fnId * 17; // small prime
for (unsigned i = entry-1; i >= entry-windowSize; --i) {
if (asOpCode(instPos[i]) == spv::OpFunction)
break;
hashval = hashval * 30103 + asOpCodeHash(instPos[i]); // 30103 = semiarbitrary prime
}
for (unsigned i = entry; i <= entry + windowSize; ++i) {
if (asOpCode(instPos[i]) == spv::OpFunctionEnd)
break;
hashval = hashval * 30103 + asOpCodeHash(instPos[i]); // 30103 = semiarbitrary prime
}
if (isOldIdUnmapped(resId)) {
localId(resId, nextUnusedId(hashval % softTypeIdLimit + firstMappedID));
if (errorLatch)
return;
}
}
}
}
spv::Op thisOpCode(spv::OpNop);
std::unordered_map<int, int> opCounter;
int idCounter(0);
fnId = spv::NoResult;
process(
[&](spv::Op opCode, unsigned start) {
switch (opCode) {
case spv::OpFunction:
// Reset counters at each function
idCounter = 0;
opCounter.clear();
fnId = asId(start + 2);
break;
case spv::OpImageSampleImplicitLod:
case spv::OpImageSampleExplicitLod:
case spv::OpImageSampleDrefImplicitLod:
case spv::OpImageSampleDrefExplicitLod:
case spv::OpImageSampleProjImplicitLod:
case spv::OpImageSampleProjExplicitLod:
case spv::OpImageSampleProjDrefImplicitLod:
case spv::OpImageSampleProjDrefExplicitLod:
case spv::OpDot:
case spv::OpCompositeExtract:
case spv::OpCompositeInsert:
case spv::OpVectorShuffle:
case spv::OpLabel:
case spv::OpVariable:
case spv::OpAccessChain:
case spv::OpLoad:
case spv::OpStore:
case spv::OpCompositeConstruct:
case spv::OpFunctionCall:
++opCounter[opCode];
idCounter = 0;
thisOpCode = opCode;
break;
default:
thisOpCode = spv::OpNop;
}
return false;
},
[&](spv::Id& id) {
if (thisOpCode != spv::OpNop) {
++idCounter;
const std::uint32_t hashval =
// Explicitly cast operands to unsigned int to avoid integer
// promotion to signed int followed by integer overflow,
// which would result in undefined behavior.
static_cast<unsigned int>(opCounter[thisOpCode])
* thisOpCode
* 50047
+ idCounter
+ static_cast<unsigned int>(fnId) * 117;
if (isOldIdUnmapped(id))
localId(id, nextUnusedId(hashval % softTypeIdLimit + firstMappedID));
}
});
}
// EXPERIMENTAL: forward IO and uniform load/stores into operands
// This produces invalid Schema-0 SPIRV
void spirvbin_t::forwardLoadStores()
{
idset_t fnLocalVars; // set of function local vars
idmap_t idMap; // Map of load result IDs to what they load
// EXPERIMENTAL: Forward input and access chain loads into consumptions
process(
[&](spv::Op opCode, unsigned start) {
// Add inputs and uniforms to the map
if ((opCode == spv::OpVariable && asWordCount(start) == 4) &&
(spv[start+3] == spv::StorageClassUniform ||
spv[start+3] == spv::StorageClassUniformConstant ||
spv[start+3] == spv::StorageClassInput))
fnLocalVars.insert(asId(start+2));
if (opCode == spv::OpAccessChain && fnLocalVars.count(asId(start+3)) > 0)
fnLocalVars.insert(asId(start+2));
if (opCode == spv::OpLoad && fnLocalVars.count(asId(start+3)) > 0) {
idMap[asId(start+2)] = asId(start+3);
stripInst(start);
}
return false;
},
[&](spv::Id& id) { if (idMap.find(id) != idMap.end()) id = idMap[id]; }
);
if (errorLatch)
return;
// EXPERIMENTAL: Implicit output stores
fnLocalVars.clear();
idMap.clear();
process(
[&](spv::Op opCode, unsigned start) {
// Add inputs and uniforms to the map
if ((opCode == spv::OpVariable && asWordCount(start) == 4) &&
(spv[start+3] == spv::StorageClassOutput))
fnLocalVars.insert(asId(start+2));
if (opCode == spv::OpStore && fnLocalVars.count(asId(start+1)) > 0) {
idMap[asId(start+2)] = asId(start+1);
stripInst(start);
}
return false;
},
op_fn_nop);
if (errorLatch)
return;
process(
inst_fn_nop,
[&](spv::Id& id) { if (idMap.find(id) != idMap.end()) id = idMap[id]; }
);
if (errorLatch)
return;
strip(); // strip out data we decided to eliminate
}
// optimize loads and stores
void spirvbin_t::optLoadStore()
{
idset_t fnLocalVars; // candidates for removal (only locals)
idmap_t idMap; // Map of load result IDs to what they load
blockmap_t blockMap; // Map of IDs to blocks they first appear in
int blockNum = 0; // block count, to avoid crossing flow control
// Find all the function local pointers stored at most once, and not via access chains
process(
[&](spv::Op opCode, unsigned start) {
const int wordCount = asWordCount(start);
// Count blocks, so we can avoid crossing flow control
if (isFlowCtrl(opCode))
++blockNum;
// Add local variables to the map
if ((opCode == spv::OpVariable && spv[start+3] == spv::StorageClassFunction && asWordCount(start) == 4)) {
fnLocalVars.insert(asId(start+2));
return true;
}
// Ignore process vars referenced via access chain
if ((opCode == spv::OpAccessChain || opCode == spv::OpInBoundsAccessChain) && fnLocalVars.count(asId(start+3)) > 0) {
fnLocalVars.erase(asId(start+3));
idMap.erase(asId(start+3));
return true;
}
if (opCode == spv::OpLoad && fnLocalVars.count(asId(start+3)) > 0) {
const spv::Id varId = asId(start+3);
// Avoid loads before stores
if (idMap.find(varId) == idMap.end()) {
fnLocalVars.erase(varId);
idMap.erase(varId);
}
// don't do for volatile references
if (wordCount > 4 && (spv[start+4] & spv::MemoryAccessVolatileMask)) {
fnLocalVars.erase(varId);
idMap.erase(varId);
}
// Handle flow control
if (blockMap.find(varId) == blockMap.end()) {
blockMap[varId] = blockNum; // track block we found it in.
} else if (blockMap[varId] != blockNum) {
fnLocalVars.erase(varId); // Ignore if crosses flow control
idMap.erase(varId);
}
return true;
}
if (opCode == spv::OpStore && fnLocalVars.count(asId(start+1)) > 0) {
const spv::Id varId = asId(start+1);
if (idMap.find(varId) == idMap.end()) {
idMap[varId] = asId(start+2);
} else {
// Remove if it has more than one store to the same pointer
fnLocalVars.erase(varId);
idMap.erase(varId);
}
// don't do for volatile references
if (wordCount > 3 && (spv[start+3] & spv::MemoryAccessVolatileMask)) {
fnLocalVars.erase(asId(start+3));
idMap.erase(asId(start+3));
}
// Handle flow control
if (blockMap.find(varId) == blockMap.end()) {
blockMap[varId] = blockNum; // track block we found it in.
} else if (blockMap[varId] != blockNum) {
fnLocalVars.erase(varId); // Ignore if crosses flow control
idMap.erase(varId);
}
return true;
}
return false;
},
// If local var id used anywhere else, don't eliminate
[&](spv::Id& id) {
if (fnLocalVars.count(id) > 0) {
fnLocalVars.erase(id);
idMap.erase(id);
}
}
);
if (errorLatch)
return;
process(
[&](spv::Op opCode, unsigned start) {
if (opCode == spv::OpLoad && fnLocalVars.count(asId(start+3)) > 0)
idMap[asId(start+2)] = idMap[asId(start+3)];
return false;
},
op_fn_nop);
if (errorLatch)
return;
// Chase replacements to their origins, in case there is a chain such as:
// 2 = store 1
// 3 = load 2
// 4 = store 3
// 5 = load 4
// We want to replace uses of 5 with 1.
for (const auto& idPair : idMap) {
spv::Id id = idPair.first;
while (idMap.find(id) != idMap.end()) // Chase to end of chain
id = idMap[id];
idMap[idPair.first] = id; // replace with final result
}
// Remove the load/store/variables for the ones we've discovered
process(
[&](spv::Op opCode, unsigned start) {
if ((opCode == spv::OpLoad && fnLocalVars.count(asId(start+3)) > 0) ||
(opCode == spv::OpStore && fnLocalVars.count(asId(start+1)) > 0) ||
(opCode == spv::OpVariable && fnLocalVars.count(asId(start+2)) > 0)) {
stripInst(start);
return true;
}
return false;
},
[&](spv::Id& id) {
if (idMap.find(id) != idMap.end()) id = idMap[id];
}
);
if (errorLatch)
return;
strip(); // strip out data we decided to eliminate
}
// remove bodies of uncalled functions
void spirvbin_t::dceFuncs()
{
msg(3, 2, std::string("Removing Dead Functions: "));
// TODO: There are more efficient ways to do this.
bool changed = true;
while (changed) {
changed = false;
for (auto fn = fnPos.begin(); fn != fnPos.end(); ) {
if (fn->first == entryPoint) { // don't DCE away the entry point!
++fn;
continue;
}
const auto call_it = fnCalls.find(fn->first);
if (call_it == fnCalls.end() || call_it->second == 0) {
changed = true;
stripRange.push_back(fn->second);
// decrease counts of called functions
process(
[&](spv::Op opCode, unsigned start) {
if (opCode == spv::Op::OpFunctionCall) {
const auto call_it = fnCalls.find(asId(start + 3));
if (call_it != fnCalls.end()) {
if (--call_it->second <= 0)
fnCalls.erase(call_it);
}
}
return true;
},
op_fn_nop,
fn->second.first,
fn->second.second);
if (errorLatch)
return;
fn = fnPos.erase(fn);
} else ++fn;
}
}
}
// remove unused function variables + decorations
void spirvbin_t::dceVars()
{
msg(3, 2, std::string("DCE Vars: "));
std::unordered_map<spv::Id, int> varUseCount;
// Count function variable use
process(
[&](spv::Op opCode, unsigned start) {
if (opCode == spv::OpVariable) {
++varUseCount[asId(start+2)];
return true;
} else if (opCode == spv::OpEntryPoint) {
const int wordCount = asWordCount(start);
for (int i = 4; i < wordCount; i++) {
++varUseCount[asId(start+i)];
}
return true;
} else
return false;
},
[&](spv::Id& id) { if (varUseCount[id]) ++varUseCount[id]; }
);
if (errorLatch)
return;
// Remove single-use function variables + associated decorations and names
process(
[&](spv::Op opCode, unsigned start) {
spv::Id id = spv::NoResult;
if (opCode == spv::OpVariable)
id = asId(start+2);
if (opCode == spv::OpDecorate || opCode == spv::OpName)
id = asId(start+1);
if (id != spv::NoResult && varUseCount[id] == 1)
stripInst(start);
return true;
},
op_fn_nop);
}
// remove unused types
void spirvbin_t::dceTypes()
{
std::vector<bool> isType(bound(), false);
// for speed, make O(1) way to get to type query (map is log(n))
for (const auto typeStart : typeConstPos)
isType[asTypeConstId(typeStart)] = true;
std::unordered_map<spv::Id, int> typeUseCount;
// This is not the most efficient algorithm, but this is an offline tool, and
// it's easy to write this way. Can be improved opportunistically if needed.
bool changed = true;
while (changed) {
changed = false;
strip();
typeUseCount.clear();
// Count total type usage
process(inst_fn_nop,
[&](spv::Id& id) { if (isType[id]) ++typeUseCount[id]; }
);
if (errorLatch)
return;
// Remove single reference types
for (const auto typeStart : typeConstPos) {
const spv::Id typeId = asTypeConstId(typeStart);
if (typeUseCount[typeId] == 1) {
changed = true;
--typeUseCount[typeId];
stripInst(typeStart);
}
}
if (errorLatch)
return;
}
}
#ifdef NOTDEF
bool spirvbin_t::matchType(const spirvbin_t::globaltypes_t& globalTypes, spv::Id lt, spv::Id gt) const
{
// Find the local type id "lt" and global type id "gt"
const auto lt_it = typeConstPosR.find(lt);
if (lt_it == typeConstPosR.end())
return false;
const auto typeStart = lt_it->second;
// Search for entry in global table
const auto gtype = globalTypes.find(gt);
if (gtype == globalTypes.end())
return false;
const auto& gdata = gtype->second;
// local wordcount and opcode
const int wordCount = asWordCount(typeStart);
const spv::Op opCode = asOpCode(typeStart);
// no type match if opcodes don't match, or operand count doesn't match
if (opCode != opOpCode(gdata[0]) || wordCount != opWordCount(gdata[0]))
return false;
const unsigned numOperands = wordCount - 2; // all types have a result
const auto cmpIdRange = [&](range_t range) {
for (int x=range.first; x<std::min(range.second, wordCount); ++x)
if (!matchType(globalTypes, asId(typeStart+x), gdata[x]))
return false;
return true;
};
const auto cmpConst = [&]() { return cmpIdRange(constRange(opCode)); };
const auto cmpSubType = [&]() { return cmpIdRange(typeRange(opCode)); };
// Compare literals in range [start,end)
const auto cmpLiteral = [&]() {
const auto range = literalRange(opCode);
return std::equal(spir.begin() + typeStart + range.first,
spir.begin() + typeStart + std::min(range.second, wordCount),
gdata.begin() + range.first);
};
assert(isTypeOp(opCode) || isConstOp(opCode));
switch (opCode) {
case spv::OpTypeOpaque: // TODO: disable until we compare the literal strings.
case spv::OpTypeQueue: return false;
case spv::OpTypeEvent: // fall through...
case spv::OpTypeDeviceEvent: // ...
case spv::OpTypeReserveId: return false;
// for samplers, we don't handle the optional parameters yet
case spv::OpTypeSampler: return cmpLiteral() && cmpConst() && cmpSubType() && wordCount == 8;
default: return cmpLiteral() && cmpConst() && cmpSubType();
}
}
// Look for an equivalent type in the globalTypes map
spv::Id spirvbin_t::findType(const spirvbin_t::globaltypes_t& globalTypes, spv::Id lt) const
{
// Try a recursive type match on each in turn, and return a match if we find one
for (const auto& gt : globalTypes)
if (matchType(globalTypes, lt, gt.first))
return gt.first;
return spv::NoType;
}
#endif // NOTDEF
// Return start position in SPV of given Id. error if not found.
unsigned spirvbin_t::idPos(spv::Id id) const
{
const auto tid_it = idPosR.find(id);
if (tid_it == idPosR.end()) {
error("ID not found");
return 0;
}
return tid_it->second;
}
// Hash types to canonical values. This can return ID collisions (it's a bit
// inevitable): it's up to the caller to handle that gracefully.
std::uint32_t spirvbin_t::hashType(unsigned typeStart) const
{
const unsigned wordCount = asWordCount(typeStart);
const spv::Op opCode = asOpCode(typeStart);
switch (opCode) {
case spv::OpTypeVoid: return 0;
case spv::OpTypeBool: return 1;
case spv::OpTypeInt: return 3 + (spv[typeStart+3]);
case spv::OpTypeFloat: return 5;
case spv::OpTypeVector:
return 6 + hashType(idPos(spv[typeStart+2])) * (spv[typeStart+3] - 1);
case spv::OpTypeMatrix:
return 30 + hashType(idPos(spv[typeStart+2])) * (spv[typeStart+3] - 1);
case spv::OpTypeImage:
return 120 + hashType(idPos(spv[typeStart+2])) +
spv[typeStart+3] + // dimensionality
spv[typeStart+4] * 8 * 16 + // depth
spv[typeStart+5] * 4 * 16 + // arrayed
spv[typeStart+6] * 2 * 16 + // multisampled
spv[typeStart+7] * 1 * 16; // format
case spv::OpTypeSampler:
return 500;
case spv::OpTypeSampledImage:
return 502;
case spv::OpTypeArray:
return 501 + hashType(idPos(spv[typeStart+2])) * spv[typeStart+3];
case spv::OpTypeRuntimeArray:
return 5000 + hashType(idPos(spv[typeStart+2]));
case spv::OpTypeStruct:
{
std::uint32_t hash = 10000;
for (unsigned w=2; w < wordCount; ++w)
hash += w * hashType(idPos(spv[typeStart+w]));
return hash;
}
case spv::OpTypeOpaque: return 6000 + spv[typeStart+2];
case spv::OpTypePointer: return 100000 + hashType(idPos(spv[typeStart+3]));
case spv::OpTypeFunction:
{
std::uint32_t hash = 200000;
for (unsigned w=2; w < wordCount; ++w)
hash += w * hashType(idPos(spv[typeStart+w]));
return hash;
}
case spv::OpTypeEvent: return 300000;
case spv::OpTypeDeviceEvent: return 300001;
case spv::OpTypeReserveId: return 300002;
case spv::OpTypeQueue: return 300003;
case spv::OpTypePipe: return 300004;
case spv::OpConstantTrue: return 300007;
case spv::OpConstantFalse: return 300008;
case spv::OpConstantComposite:
{
std::uint32_t hash = 300011 + hashType(idPos(spv[typeStart+1]));
for (unsigned w=3; w < wordCount; ++w)
hash += w * hashType(idPos(spv[typeStart+w]));
return hash;
}
case spv::OpConstant:
{
std::uint32_t hash = 400011 + hashType(idPos(spv[typeStart+1]));
for (unsigned w=3; w < wordCount; ++w)
hash += w * spv[typeStart+w];
return hash;
}
case spv::OpConstantNull:
{
std::uint32_t hash = 500009 + hashType(idPos(spv[typeStart+1]));
return hash;
}
case spv::OpConstantSampler:
{
std::uint32_t hash = 600011 + hashType(idPos(spv[typeStart+1]));
for (unsigned w=3; w < wordCount; ++w)
hash += w * spv[typeStart+w];
return hash;
}
default:
error("unknown type opcode");
return 0;
}
}
void spirvbin_t::mapTypeConst()
{
globaltypes_t globalTypeMap;
msg(3, 2, std::string("Remapping Consts & Types: "));
static const std::uint32_t softTypeIdLimit = 3011; // small prime. TODO: get from options
static const std::uint32_t firstMappedID = 8; // offset into ID space
for (auto& typeStart : typeConstPos) {
const spv::Id resId = asTypeConstId(typeStart);
const std::uint32_t hashval = hashType(typeStart);
if (errorLatch)
return;
if (isOldIdUnmapped(resId)) {
localId(resId, nextUnusedId(hashval % softTypeIdLimit + firstMappedID));
if (errorLatch)
return;
}
}
}
// Strip a single binary by removing ranges given in stripRange
void spirvbin_t::strip()
{
if (stripRange.empty()) // nothing to do
return;
// Sort strip ranges in order of traversal
std::sort(stripRange.begin(), stripRange.end());
// Allocate a new binary big enough to hold old binary
// We'll step this iterator through the strip ranges as we go through the binary
auto strip_it = stripRange.begin();
int strippedPos = 0;
for (unsigned word = 0; word < unsigned(spv.size()); ++word) {
while (strip_it != stripRange.end() && word >= strip_it->second)
++strip_it;
if (strip_it == stripRange.end() || word < strip_it->first || word >= strip_it->second)
spv[strippedPos++] = spv[word];
}
spv.resize(strippedPos);
stripRange.clear();
buildLocalMaps();
}
// Strip a single binary by removing ranges given in stripRange
void spirvbin_t::remap(std::uint32_t opts)
{
options = opts;
// Set up opcode tables from SpvDoc
spv::Parameterize();
validate(); // validate header
buildLocalMaps(); // build ID maps
msg(3, 4, std::string("ID bound: ") + std::to_string(bound()));
if (options & STRIP) stripDebug();
if (errorLatch) return;
strip(); // strip out data we decided to eliminate
if (errorLatch) return;
if (options & OPT_LOADSTORE) optLoadStore();
if (errorLatch) return;
if (options & OPT_FWD_LS) forwardLoadStores();
if (errorLatch) return;
if (options & DCE_FUNCS) dceFuncs();
if (errorLatch) return;
if (options & DCE_VARS) dceVars();
if (errorLatch) return;
if (options & DCE_TYPES) dceTypes();
if (errorLatch) return;
strip(); // strip out data we decided to eliminate
if (errorLatch) return;
stripDeadRefs(); // remove references to things we DCEed
if (errorLatch) return;
// after the last strip, we must clean any debug info referring to now-deleted data
if (options & MAP_TYPES) mapTypeConst();
if (errorLatch) return;
if (options & MAP_NAMES) mapNames();
if (errorLatch) return;
if (options & MAP_FUNCS) mapFnBodies();
if (errorLatch) return;
if (options & MAP_ALL) {
mapRemainder(); // map any unmapped IDs
if (errorLatch) return;
applyMap(); // Now remap each shader to the new IDs we've come up with
if (errorLatch) return;
}
}
// remap from a memory image
void spirvbin_t::remap(std::vector<std::uint32_t>& in_spv, const std::vector<std::string>& whiteListStrings,
std::uint32_t opts)
{
stripWhiteList = whiteListStrings;
spv.swap(in_spv);
remap(opts);
spv.swap(in_spv);
}
// remap from a memory image - legacy interface without white list
void spirvbin_t::remap(std::vector<std::uint32_t>& in_spv, std::uint32_t opts)
{
stripWhiteList.clear();
spv.swap(in_spv);
remap(opts);
spv.swap(in_spv);
}
} // namespace SPV
|
Subsets and Splits