This saves about 7K.
By changing just a few methods to be compile-time known, a bunch of
scattered code becomes DCE.
-1210368 ../build/install/bin/glslangValidator.exe
+1202688 ../build/install/bin/glslangValidator.exe
switch (op) {
case EOpLogicalNot:
- if (source == EShSourceHlsl) {
+ if (getSource() == EShSourceHlsl) {
break; // HLSL can promote logical not
}
break;
// HLSL can assign samplers directly (no constructor)
- if (source == EShSourceHlsl && node->getBasicType() == EbtSampler)
+ if (getSource() == EShSourceHlsl && node->getBasicType() == EbtSampler)
break;
// samplers can get assigned via a sampler constructor
case EOpLogicalAnd:
case EOpLogicalOr:
case EOpLogicalXor:
- if (source == EShSourceHlsl)
+ if (getSource() == EShSourceHlsl)
promoteTo = std::make_tuple(EbtBool, EbtBool);
else
return std::make_tuple(node0, node1);
// HLSL can promote bools to ints to make this work.
case EOpLeftShift:
case EOpRightShift:
- if (source == EShSourceHlsl) {
+ if (getSource() == EShSourceHlsl) {
TBasicType node0BasicType = node0->getBasicType();
if (node0BasicType == EbtBool)
node0BasicType = EbtInt;
case EOpLeftShiftAssign:
case EOpRightShiftAssign:
{
- if (source == EShSourceHlsl && node->getType().getBasicType() == EbtBool)
+ if (getSource() == EShSourceHlsl && node->getType().getBasicType() == EbtBool)
promoteTo = type.getBasicType();
else {
if (isTypeInt(type.getBasicType()) && isTypeInt(node->getBasicType()))
TIntermTyped* TIntermediate::addUniShapeConversion(TOperator op, const TType& type, TIntermTyped* node)
{
// some source languages don't do this
- switch (source) {
+ switch (getSource()) {
case EShSourceHlsl:
break;
case EShSourceGlsl:
void TIntermediate::addBiShapeConversion(TOperator op, TIntermTyped*& lhsNode, TIntermTyped*& rhsNode)
{
// some source languages don't do this
- switch (source) {
+ switch (getSource()) {
case EShSourceHlsl:
break;
case EShSourceGlsl:
// The new node that handles the conversion
TOperator constructorOp = mapTypeToConstructorOp(type);
- if (source == EShSourceHlsl) {
+ 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)
case EbtInt:
switch(to) {
case EbtUint:
- return version >= 400 || (source == EShSourceHlsl);
+ return version >= 400 || getSource() == EShSourceHlsl;
case EbtInt64:
case EbtUint64:
return true;
// TODO: Move more policies into language-specific handlers.
// Some languages allow more general (or potentially, more specific) conversions under some conditions.
- if (source == EShSourceHlsl) {
+ 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);
}
// hlsl supported conversions
- if (source == EShSourceHlsl) {
+ if (getSource() == EShSourceHlsl) {
if (from == EbtBool && (to == EbtInt || to == EbtUint || to == EbtFloat))
return true;
}
case EbtFloat:
return true;
case EbtBool:
- return (source == EShSourceHlsl);
+ return (getSource() == EShSourceHlsl);
#ifdef AMD_EXTENSIONS
case EbtInt16:
case EbtUint16:
#ifdef AMD_EXTENSIONS
extensionRequested(E_GL_AMD_gpu_shader_half_float) ||
#endif
- (source == EShSourceHlsl);
+ getSource() == EShSourceHlsl;
default:
return false;
}
case EbtUint:
switch (from) {
case EbtInt:
- return version >= 400 || (source == EShSourceHlsl);
+ return version >= 400 || getSource() == EShSourceHlsl;
case EbtUint:
return true;
case EbtBool:
- return (source == EShSourceHlsl);
+ return getSource() == EShSourceHlsl;
#ifdef AMD_EXTENSIONS
case EbtInt16:
case EbtUint16:
case EbtInt:
return true;
case EbtBool:
- return (source == EShSourceHlsl);
+ return getSource() == EShSourceHlsl;
#ifdef AMD_EXTENSIONS
case EbtInt16:
return extensionRequested(E_GL_AMD_gpu_shader_int16);
if (profile == EEsProfile || version == 110)
return std::make_tuple(res0, res1);;
- if (source == EShSourceHlsl) {
+ if (getSource() == EShSourceHlsl) {
if (canImplicitlyPromote(type1, type0, op)) {
res0 = type0;
res1 = type0;
selector.push_back(0);
}
+#ifdef ENABLE_HLSL
//
// Make the passed-in variable information become a member of the
// global uniform block. If this doesn't exist yet, make it.
++firstNewMember;
}
+#endif
void TParseContextBase::finish()
{
extensionCallback(line, extension, behavior);
}
+#ifdef ENABLE_HLSL
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr);
+#endif
// Potentially rename shader entry point function
void renameShaderFunction(TString*& name) const
// Get all the stages, languages, clients, and other environment
// stuff sorted out.
- EShSource source = (messages & EShMsgReadHlsl) != 0 ? EShSourceHlsl : EShSourceGlsl;
+ EShSource sourceGuess = (messages & EShMsgReadHlsl) != 0 ? EShSourceHlsl : EShSourceGlsl;
SpvVersion spvVersion;
EShLanguage stage = compiler->getLanguage();
- TranslateEnvironment(environment, messages, source, stage, spvVersion);
+ 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
}
};
+#ifdef ENABLE_HLSL
/********************************************************************************
The following IO resolver maps types in HLSL register space, as follows:
return ent.newBinding = -1;
}
};
+#endif
// Map I/O variables to provided offsets, and make bindings for
// unbound but live variables.
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
resolver = &defaultResolver;
}
resolver->addStage(stage);
+#else
+ resolver = &defaultResolver;
+#endif
+
TVarLiveMap inVarMap, outVarMap, uniformVarMap;
TVarLiveVector inVector, outVector, uniformVector;
TVarGatherTraverser iter_binding_all(intermediate, true, inVarMap, outVarMap, uniformVarMap);
if (language != unit.language)
error(infoSink, "stages must match when linking into a single stage");
- if (source == EShSourceNone)
- source = unit.source;
- if (source != unit.source)
+ if (getSource() == EShSourceNone)
+ setSource(unit.getSource());
+ if (getSource() != unit.getSource())
error(infoSink, "can't link compilation units from different source languages");
if (treeRoot == nullptr) {
return;
if (numEntryPoints < 1) {
- if (source == EShSourceGlsl)
+ if (getSource() == EShSourceGlsl)
error(infoSink, "Missing entry point: Each stage requires one entry point");
else
warn(infoSink, "Entry point not found");
error(infoSink, "At least one shader must specify an output layout(vertices=...)");
break;
case EShLangTessEvaluation:
- if (source == EShSourceGlsl) {
+ if (getSource() == EShSourceGlsl) {
if (inputPrimitive == ElgNone)
error(infoSink, "At least one shader must specify an input layout primitive");
if (vertexSpacing == EvsNone)
public:
explicit TIntermediate(EShLanguage l, int v = 0, EProfile p = ENoProfile) :
implicitThisName("@this"), implicitCounterName("@count"),
- language(l), source(EShSourceNone), profile(p), version(v), treeRoot(0),
+ language(l),
+#ifdef ENABLE_HLSL
+ source(EShSourceNone),
+#endif
+ profile(p), version(v), treeRoot(0),
numEntryPoints(0), numErrors(0), numPushConstants(0), recursive(false),
invocations(TQualifier::layoutNotSet), vertices(TQualifier::layoutNotSet),
inputPrimitive(ElgNone), outputPrimitive(ElgNone),
void output(TInfoSink&, bool tree);
void removeTree();
+#ifdef ENABLE_HLSL
void setSource(EShSource s) { source = s; }
EShSource getSource() const { return source; }
+#else
+ void setSource(EShSource s) { assert(s == EShSourceGlsl); }
+ EShSource getSource() const { return EShSourceGlsl; }
+#endif
void setEntryPointName(const char* ep)
{
entryPointName = ep;
static const char* getResourceName(TResourceType);
const EShLanguage language; // stage, known at construction time
+#ifdef ENABLE_HLSL
EShSource source; // source language, known a bit later
+#endif
std::string entryPointName;
std::string entryPointMangledName;
typedef std::list<TCall> TGraph;
void getPreamble(std::string&);
bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; }
bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; }
+#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;