From cce8d48bcc9a0794845cf284f2caccf3458c8bf4 Mon Sep 17 00:00:00 2001 From: steve-lunarg Date: Fri, 14 Oct 2016 18:36:42 -0600 Subject: [PATCH] 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. --- StandAlone/StandAlone.cpp | 8 +++++++ .../hlsl.sample.sub-vec4.dx10.frag.out | 8 +++---- glslang/MachineIndependent/ShaderLang.cpp | 1 + .../MachineIndependent/localintermediate.h | 8 +++++-- glslang/Public/ShaderLang.h | 1 + hlsl/hlslParseHelper.cpp | 22 +++++-------------- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index f0a4f93c..7ffd2324 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -82,6 +82,7 @@ enum TOptions { EOptionCascadingErrors = (1 << 18), EOptionAutoMapBindings = (1 << 19), EOptionFlattenUniformArrays = (1 << 20), + EOptionNoStorageFormat = (1 << 21), }; // @@ -290,6 +291,9 @@ void ProcessArguments(int argc, char* argv[]) lowerword == "flatten-uniform-array" || lowerword == "fua") { Options |= EOptionFlattenUniformArrays; + } else if (lowerword == "no-storage-format" || // synonyms + lowerword == "nsf") { + Options |= EOptionNoStorageFormat; } else { usage(); } @@ -542,6 +546,7 @@ void CompileAndLinkShaderUnits(std::vector compUnits) shader->setShiftTextureBinding(baseTextureBinding[compUnit.stage]); shader->setShiftUboBinding(baseUboBinding[compUnit.stage]); shader->setFlattenUniformArrays((Options & EOptionFlattenUniformArrays) != 0); + shader->setNoStorageFormat((Options & EOptionNoStorageFormat) != 0); if (Options & EOptionAutoMapBindings) shader->setAutoMapBindings(true); @@ -945,6 +950,9 @@ void usage() "\n" " --flatten-uniform-arrays flatten uniform texture & sampler arrays to scalars\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); diff --git a/Test/baseResults/hlsl.sample.sub-vec4.dx10.frag.out b/Test/baseResults/hlsl.sample.sub-vec4.dx10.frag.out index abe1cb5a..5a97ed96 100644 --- a/Test/baseResults/hlsl.sample.sub-vec4.dx10.frag.out +++ b/Test/baseResults/hlsl.sample.sub-vec4.dx10.frag.out @@ -18,7 +18,7 @@ gl_FragCoord origin is upper left 0:18 Sequence 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 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:18 Construct combined texture-sampler (temp sampler1D) 0:18 'g_tTex1df2' (uniform texture1D) @@ -28,7 +28,7 @@ gl_FragCoord origin is upper left 0:19 Sequence 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 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:19 Construct combined texture-sampler (temp sampler1D) 0:19 'g_tTex1df3' (uniform texture1D) @@ -94,7 +94,7 @@ gl_FragCoord origin is upper left 0:18 Sequence 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 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:18 Construct combined texture-sampler (temp sampler1D) 0:18 'g_tTex1df2' (uniform texture1D) @@ -104,7 +104,7 @@ gl_FragCoord origin is upper left 0:19 Sequence 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 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:19 Construct combined texture-sampler (temp sampler1D) 0:19 'g_tTex1df3' (uniform texture1D) diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index 5333af45..6d044452 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -1497,6 +1497,7 @@ void TShader::setShiftTextureBinding(unsigned int base) { intermediate->setShift void TShader::setShiftUboBinding(unsigned int base) { intermediate->setShiftUboBinding(base); } void TShader::setAutoMapBindings(bool map) { intermediate->setAutoMapBindings(map); } 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. diff --git a/glslang/MachineIndependent/localintermediate.h b/glslang/MachineIndependent/localintermediate.h index 348b78e0..aae22ecc 100644 --- a/glslang/MachineIndependent/localintermediate.h +++ b/glslang/MachineIndependent/localintermediate.h @@ -146,7 +146,8 @@ public: shiftTextureBinding(0), shiftUboBinding(0), autoMapBindings(false), - flattenUniformArrays(false) + flattenUniformArrays(false), + useUnknownFormat(false) { localSize[0] = 1; localSize[1] = 1; @@ -179,7 +180,9 @@ public: bool getAutoMapBindings() const { return autoMapBindings; } void setFlattenUniformArrays(bool flatten) { flattenUniformArrays = flatten; } bool getFlattenUniformArrays() const { return flattenUniformArrays; } - + void setNoStorageFormat(bool b) { useUnknownFormat = b; } + bool getNoStorageFormat() const { return useUnknownFormat; } + void setVersion(int v) { version = v; } int getVersion() const { return version; } void setProfile(EProfile p) { profile = p; } @@ -397,6 +400,7 @@ protected: unsigned int shiftUboBinding; bool autoMapBindings; bool flattenUniformArrays; + bool useUnknownFormat; EProfile profile; int version; diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index 6b894c19..e5e8b4d7 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -309,6 +309,7 @@ public: void setShiftUboBinding(unsigned int base); void setAutoMapBindings(bool map); void setFlattenUniformArrays(bool flatten); + void setNoStorageFormat(bool useUnknownFormat); // Interface to #include handlers. // diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 97999d0e..aa415452 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -154,7 +154,10 @@ TLayoutFormat HlslParseContext::getLayoutFromTxType(const TSourceLoc& loc, const { 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 : components == 2 ? v2 : v4; }; @@ -288,13 +291,6 @@ TIntermTyped* HlslParseContext::handleLvalue(const TSourceLoc& loc, const char* 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); if (nodeAsBinary) { @@ -1452,15 +1448,7 @@ void HlslParseContext::decomposeSampleMethods(const TSourceLoc& loc, TIntermType // Too many components. Construct shorter vector from it. const TType clampedType(result->getType().getBasicType(), EvqTemporary, sampler.vectorSize); - TOperator op; - - 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", "", ""); - } + const TOperator op = intermediate.mapTypeToConstructorOp(clampedType); result = constructBuiltIn(clampedType, op, result, loc, false); }