HLSL: phase 3c: add option to use Unknown storage format

This uses the Unknown storage format, instead of deducing the
format from the texture declaration type.
This commit is contained in:
steve-lunarg
2016-10-14 18:36:42 -06:00
parent 8b0227ced9
commit cce8d48bcc
6 changed files with 25 additions and 23 deletions

View File

@@ -82,6 +82,7 @@ enum TOptions {
EOptionCascadingErrors = (1 << 18), EOptionCascadingErrors = (1 << 18),
EOptionAutoMapBindings = (1 << 19), EOptionAutoMapBindings = (1 << 19),
EOptionFlattenUniformArrays = (1 << 20), EOptionFlattenUniformArrays = (1 << 20),
EOptionNoStorageFormat = (1 << 21),
}; };
// //
@@ -290,6 +291,9 @@ void ProcessArguments(int argc, char* argv[])
lowerword == "flatten-uniform-array" || lowerword == "flatten-uniform-array" ||
lowerword == "fua") { lowerword == "fua") {
Options |= EOptionFlattenUniformArrays; Options |= EOptionFlattenUniformArrays;
} else if (lowerword == "no-storage-format" || // synonyms
lowerword == "nsf") {
Options |= EOptionNoStorageFormat;
} else { } else {
usage(); usage();
} }
@@ -542,6 +546,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
shader->setShiftTextureBinding(baseTextureBinding[compUnit.stage]); shader->setShiftTextureBinding(baseTextureBinding[compUnit.stage]);
shader->setShiftUboBinding(baseUboBinding[compUnit.stage]); shader->setShiftUboBinding(baseUboBinding[compUnit.stage]);
shader->setFlattenUniformArrays((Options & EOptionFlattenUniformArrays) != 0); shader->setFlattenUniformArrays((Options & EOptionFlattenUniformArrays) != 0);
shader->setNoStorageFormat((Options & EOptionNoStorageFormat) != 0);
if (Options & EOptionAutoMapBindings) if (Options & EOptionAutoMapBindings)
shader->setAutoMapBindings(true); shader->setAutoMapBindings(true);
@@ -945,6 +950,9 @@ void usage()
"\n" "\n"
" --flatten-uniform-arrays flatten uniform texture & sampler arrays to scalars\n" " --flatten-uniform-arrays flatten uniform texture & sampler arrays to scalars\n"
" --fua synonym for --flatten-uniform-arrays\n" " --fua synonym for --flatten-uniform-arrays\n"
"\n"
" --no-storage-format use Unknown image format\n"
" --nsf synonym for --no-storage-format\n"
); );
exit(EFailUsage); exit(EFailUsage);

View File

@@ -18,7 +18,7 @@ gl_FragCoord origin is upper left
0:18 Sequence 0:18 Sequence
0:18 move second child to first child (temp 2-component vector of float) 0:18 move second child to first child (temp 2-component vector of float)
0:18 'txval11' (temp 2-component vector of float) 0:18 'txval11' (temp 2-component vector of float)
0:18 Construct float (temp 2-component vector of float) 0:18 Construct vec2 (temp 2-component vector of float)
0:? texture (temp 4-component vector of float) 0:? texture (temp 4-component vector of float)
0:18 Construct combined texture-sampler (temp sampler1D) 0:18 Construct combined texture-sampler (temp sampler1D)
0:18 'g_tTex1df2' (uniform texture1D) 0:18 'g_tTex1df2' (uniform texture1D)
@@ -28,7 +28,7 @@ gl_FragCoord origin is upper left
0:19 Sequence 0:19 Sequence
0:19 move second child to first child (temp 3-component vector of float) 0:19 move second child to first child (temp 3-component vector of float)
0:19 'txval12' (temp 3-component vector of float) 0:19 'txval12' (temp 3-component vector of float)
0:19 Construct float (temp 3-component vector of float) 0:19 Construct vec3 (temp 3-component vector of float)
0:? texture (temp 4-component vector of float) 0:? texture (temp 4-component vector of float)
0:19 Construct combined texture-sampler (temp sampler1D) 0:19 Construct combined texture-sampler (temp sampler1D)
0:19 'g_tTex1df3' (uniform texture1D) 0:19 'g_tTex1df3' (uniform texture1D)
@@ -94,7 +94,7 @@ gl_FragCoord origin is upper left
0:18 Sequence 0:18 Sequence
0:18 move second child to first child (temp 2-component vector of float) 0:18 move second child to first child (temp 2-component vector of float)
0:18 'txval11' (temp 2-component vector of float) 0:18 'txval11' (temp 2-component vector of float)
0:18 Construct float (temp 2-component vector of float) 0:18 Construct vec2 (temp 2-component vector of float)
0:? texture (temp 4-component vector of float) 0:? texture (temp 4-component vector of float)
0:18 Construct combined texture-sampler (temp sampler1D) 0:18 Construct combined texture-sampler (temp sampler1D)
0:18 'g_tTex1df2' (uniform texture1D) 0:18 'g_tTex1df2' (uniform texture1D)
@@ -104,7 +104,7 @@ gl_FragCoord origin is upper left
0:19 Sequence 0:19 Sequence
0:19 move second child to first child (temp 3-component vector of float) 0:19 move second child to first child (temp 3-component vector of float)
0:19 'txval12' (temp 3-component vector of float) 0:19 'txval12' (temp 3-component vector of float)
0:19 Construct float (temp 3-component vector of float) 0:19 Construct vec3 (temp 3-component vector of float)
0:? texture (temp 4-component vector of float) 0:? texture (temp 4-component vector of float)
0:19 Construct combined texture-sampler (temp sampler1D) 0:19 Construct combined texture-sampler (temp sampler1D)
0:19 'g_tTex1df3' (uniform texture1D) 0:19 'g_tTex1df3' (uniform texture1D)

View File

@@ -1497,6 +1497,7 @@ void TShader::setShiftTextureBinding(unsigned int base) { intermediate->setShift
void TShader::setShiftUboBinding(unsigned int base) { intermediate->setShiftUboBinding(base); } void TShader::setShiftUboBinding(unsigned int base) { intermediate->setShiftUboBinding(base); }
void TShader::setAutoMapBindings(bool map) { intermediate->setAutoMapBindings(map); } void TShader::setAutoMapBindings(bool map) { intermediate->setAutoMapBindings(map); }
void TShader::setFlattenUniformArrays(bool flatten) { intermediate->setFlattenUniformArrays(flatten); } void TShader::setFlattenUniformArrays(bool flatten) { intermediate->setFlattenUniformArrays(flatten); }
void TShader::setNoStorageFormat(bool useUnknownFormat) { intermediate->setNoStorageFormat(useUnknownFormat); }
// //
// Turn the shader strings into a parse tree in the TIntermediate. // Turn the shader strings into a parse tree in the TIntermediate.

View File

@@ -146,7 +146,8 @@ public:
shiftTextureBinding(0), shiftTextureBinding(0),
shiftUboBinding(0), shiftUboBinding(0),
autoMapBindings(false), autoMapBindings(false),
flattenUniformArrays(false) flattenUniformArrays(false),
useUnknownFormat(false)
{ {
localSize[0] = 1; localSize[0] = 1;
localSize[1] = 1; localSize[1] = 1;
@@ -179,6 +180,8 @@ public:
bool getAutoMapBindings() const { return autoMapBindings; } bool getAutoMapBindings() const { return autoMapBindings; }
void setFlattenUniformArrays(bool flatten) { flattenUniformArrays = flatten; } void setFlattenUniformArrays(bool flatten) { flattenUniformArrays = flatten; }
bool getFlattenUniformArrays() const { return flattenUniformArrays; } bool getFlattenUniformArrays() const { return flattenUniformArrays; }
void setNoStorageFormat(bool b) { useUnknownFormat = b; }
bool getNoStorageFormat() const { return useUnknownFormat; }
void setVersion(int v) { version = v; } void setVersion(int v) { version = v; }
int getVersion() const { return version; } int getVersion() const { return version; }
@@ -397,6 +400,7 @@ protected:
unsigned int shiftUboBinding; unsigned int shiftUboBinding;
bool autoMapBindings; bool autoMapBindings;
bool flattenUniformArrays; bool flattenUniformArrays;
bool useUnknownFormat;
EProfile profile; EProfile profile;
int version; int version;

View File

@@ -309,6 +309,7 @@ public:
void setShiftUboBinding(unsigned int base); void setShiftUboBinding(unsigned int base);
void setAutoMapBindings(bool map); void setAutoMapBindings(bool map);
void setFlattenUniformArrays(bool flatten); void setFlattenUniformArrays(bool flatten);
void setNoStorageFormat(bool useUnknownFormat);
// Interface to #include handlers. // Interface to #include handlers.
// //

View File

@@ -154,7 +154,10 @@ TLayoutFormat HlslParseContext::getLayoutFromTxType(const TSourceLoc& loc, const
{ {
const int components = txType.getVectorSize(); const int components = txType.getVectorSize();
const auto selectFormat = [&components](TLayoutFormat v1, TLayoutFormat v2, TLayoutFormat v4) { const auto selectFormat = [this,&components](TLayoutFormat v1, TLayoutFormat v2, TLayoutFormat v4) {
if (intermediate.getNoStorageFormat())
return ElfNone;
return components == 1 ? v1 : return components == 1 ? v1 :
components == 2 ? v2 : v4; components == 2 ? v2 : v4;
}; };
@@ -288,13 +291,6 @@ TIntermTyped* HlslParseContext::handleLvalue(const TSourceLoc& loc, const char*
const TSampler& texSampler = object->getType().getSampler(); const TSampler& texSampler = object->getType().getSampler();
const TLayoutFormat fmt = object->getType().getQualifier().layoutFormat;
// We only handle this subset of the possible formats.
assert(fmt == ElfRgba32f || fmt == ElfRgba32i || fmt == ElfRgba32ui ||
fmt == ElfRg32f || fmt == ElfRg32i || fmt == ElfRg32ui ||
fmt == ElfR32f || fmt == ElfR32i || fmt == ElfR32ui);
const TType objDerefType(texSampler.type, EvqTemporary, texSampler.vectorSize); const TType objDerefType(texSampler.type, EvqTemporary, texSampler.vectorSize);
if (nodeAsBinary) { if (nodeAsBinary) {
@@ -1452,15 +1448,7 @@ void HlslParseContext::decomposeSampleMethods(const TSourceLoc& loc, TIntermType
// Too many components. Construct shorter vector from it. // Too many components. Construct shorter vector from it.
const TType clampedType(result->getType().getBasicType(), EvqTemporary, sampler.vectorSize); const TType clampedType(result->getType().getBasicType(), EvqTemporary, sampler.vectorSize);
TOperator op; const TOperator op = intermediate.mapTypeToConstructorOp(clampedType);
switch (sampler.type) {
case EbtInt: op = EOpConstructInt; break;
case EbtUint: op = EOpConstructUint; break;
case EbtFloat: op = EOpConstructFloat; break;
default:
error(loc, "unknown basic type in texture op", "", "");
}
result = constructBuiltIn(clampedType, op, result, loc, false); result = constructBuiltIn(clampedType, op, result, loc, false);
} }