Commit 2e295e23 by Jamie Madill

hlsl: Fix struct specifiers in uniforms.

We would miss the definition for structs specfied in uniforms. Fix this by always checking to add the constructor. Fixes the WebGL test 'glsl/misc/struct-specifiers-in-uniforms'. BUG=angleproject:818 BUG=433412 Change-Id: I411e4a4477f7ef34fceb9faa77489f77d8efdce8 Reviewed-on: https://chromium-review.googlesource.com/267797Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent a1884f2b
...@@ -1321,8 +1321,8 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node) ...@@ -1321,8 +1321,8 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
if (qualifier == EvqUniform) if (qualifier == EvqUniform)
{ {
const TType& nodeType = node->getType(); const TType &nodeType = node->getType();
const TInterfaceBlock* interfaceBlock = nodeType.getInterfaceBlock(); const TInterfaceBlock *interfaceBlock = nodeType.getInterfaceBlock();
if (interfaceBlock) if (interfaceBlock)
{ {
...@@ -1333,6 +1333,8 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node) ...@@ -1333,6 +1333,8 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
mReferencedUniforms[name] = node; mReferencedUniforms[name] = node;
} }
ensureStructDefined(nodeType);
out << DecorateUniform(name, nodeType); out << DecorateUniform(name, nodeType);
} }
else if (qualifier == EvqAttribute || qualifier == EvqVertexIn) else if (qualifier == EvqAttribute || qualifier == EvqVertexIn)
...@@ -1877,12 +1879,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1877,12 +1879,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
if (variable && (variable->getQualifier() == EvqTemporary || variable->getQualifier() == EvqGlobal)) if (variable && (variable->getQualifier() == EvqTemporary || variable->getQualifier() == EvqGlobal))
{ {
TStructure *structure = variable->getType().getStruct(); ensureStructDefined(variable->getType());
if (structure)
{
mStructureHLSL->addConstructor(variable->getType(), StructNameString(*structure), NULL);
}
if (!variable->getAsSymbolNode() || variable->getAsSymbolNode()->getSymbol() != "") // Variable declaration if (!variable->getAsSymbolNode() || variable->getAsSymbolNode()->getSymbol() != "") // Variable declaration
{ {
...@@ -2027,12 +2024,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2027,12 +2024,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
if (symbol) if (symbol)
{ {
TStructure *structure = symbol->getType().getStruct(); ensureStructDefined(symbol->getType());
if (structure)
{
mStructureHLSL->addConstructor(symbol->getType(), StructNameString(*structure), NULL);
}
out << argumentString(symbol); out << argumentString(symbol);
...@@ -3207,5 +3199,16 @@ TString OutputHLSL::addArrayConstructIntoFunction(const TType& type) ...@@ -3207,5 +3199,16 @@ TString OutputHLSL::addArrayConstructIntoFunction(const TType& type)
return function.functionName; return function.functionName;
} }
void OutputHLSL::ensureStructDefined(const TType &type)
{
TStructure *structure = type.getStruct();
if (structure)
{
mStructureHLSL->addConstructor(type, StructNameString(*structure), nullptr);
}
}
} }
...@@ -93,6 +93,9 @@ class OutputHLSL : public TIntermTraverser ...@@ -93,6 +93,9 @@ class OutputHLSL : public TIntermTraverser
TString addArrayAssignmentFunction(const TType &type); TString addArrayAssignmentFunction(const TType &type);
TString addArrayConstructIntoFunction(const TType &type); TString addArrayConstructIntoFunction(const TType &type);
// Ensures if the type is a struct, the struct is defined
void ensureStructDefined(const TType &type);
sh::GLenum mShaderType; sh::GLenum mShaderType;
int mShaderVersion; int mShaderVersion;
const TExtensionBehavior &mExtensionBehavior; const TExtensionBehavior &mExtensionBehavior;
......
...@@ -4,15 +4,13 @@ https://www.khronos.org/registry/webgl/sdk/tests/webgl-conformance-tests.html ...@@ -4,15 +4,13 @@ https://www.khronos.org/registry/webgl/sdk/tests/webgl-conformance-tests.html
conformance/extensions/webgl-draw-buffers-max-draw-buffers.html: 2 tests failed conformance/extensions/webgl-draw-buffers-max-draw-buffers.html: 2 tests failed
conformance/glsl/bugs/pow-of-small-constant-in-user-defined-function.html: 1 tests failed conformance/glsl/bugs/pow-of-small-constant-in-user-defined-function.html: 1 tests failed
conformance/glsl/bugs/sampler-struct-function-arg.html: 1 tests failed conformance/glsl/bugs/sampler-struct-function-arg.html: 1 tests failed
conformance/glsl/misc/const-variable-initialization.html: 207 tests failed conformance/glsl/misc/const-variable-initialization.html: 90 tests failed
conformance/glsl/misc/empty-declaration.html: 1 tests failed
conformance/glsl/misc/struct-specifiers-in-uniforms.html: 12 tests failed
conformance/glsl/misc/ternary-operators-in-global-initializers.html: 12 tests failed conformance/glsl/misc/ternary-operators-in-global-initializers.html: 12 tests failed
conformance/misc/expando-loss.html: 1 tests failed conformance/misc/expando-loss.html: 2 tests failed
conformance/ogles/GL/biuDepthRange/biuDepthRange_001_to_002.html: 2 tests failed conformance/ogles/GL/biuDepthRange/biuDepthRange_001_to_002.html: 2 tests failed
conformance/ogles/GL/gl_FragCoord/gl_FragCoord_001_to_003.html: 1 tests failed conformance/ogles/GL/gl_FragCoord/gl_FragCoord_001_to_003.html: 1 tests failed
deqp/data/gles2/shaders/constant_expressions.html: 4 tests failed deqp/data/gles2/shaders/constant_expressions.html: 2 tests failed
deqp/data/gles2/shaders/fragdata.html: 3 tests failed deqp/data/gles2/shaders/fragdata.html: 3 tests failed
deqp/data/gles2/shaders/functions.html: 8 tests failed deqp/data/gles2/shaders/functions.html: 8 tests failed
deqp/data/gles2/shaders/preprocessor.html: 41 tests failed deqp/data/gles2/shaders/preprocessor.html: 41 tests failed
deqp/data/gles2/shaders/scoping.html: 4 tests failed deqp/data/gles2/shaders/scoping.html: 4 tests failed
\ No newline at end of file
...@@ -1047,3 +1047,23 @@ TYPED_TEST(GLSLTest_ES3, GlobalStaticAndInstanceID) ...@@ -1047,3 +1047,23 @@ TYPED_TEST(GLSLTest_ES3, GlobalStaticAndInstanceID)
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(0, 0, 6, 0, 0, 255); EXPECT_PIXEL_EQ(0, 0, 6, 0, 0, 255);
} }
// Test that structs defined in uniforms are translated correctly.
TYPED_TEST(GLSLTest, StructSpecifiersUniforms)
{
const std::string fragmentShaderSource = SHADER_SOURCE
(
precision mediump float;
uniform struct S { float field;} s;
void main()
{
gl_FragColor = vec4(1, 0, 0, 1);
gl_FragColor.a += s.field;
}
);
GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
EXPECT_NE(0u, program);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment