Hash :
9f01a0d4
Author :
Date :
2017-06-12T10:54:53
Fix RewriteElseBlocks using a non-prefixed struct name RewriteElseBlocks used to have an issue where it could add an unprefixed struct name to the AST in a TIntermRaw node, as opposed to the prefixed name that the struct would be defined with. Use a proper return statement node instead of a raw node to fix this issue and make the code more robust. BUG=angleproject:2061 TEST=angle_unittests Change-Id: I3993b5093646983f038268f3a5ffe26ccdae66e8 Reviewed-on: https://chromium-review.googlesource.com/530785 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
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
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// HLSLOutput_test.cpp:
// Tests for HLSL output.
//
#include "GLSLANG/ShaderLang.h"
#include "angle_gl.h"
#include "gtest/gtest.h"
#include "tests/test_utils/compiler_test.h"
using namespace sh;
class HLSLOutputTest : public MatchOutputCodeTest
{
public:
HLSLOutputTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_HLSL_4_1_OUTPUT) {}
};
class HLSL30VertexOutputTest : public MatchOutputCodeTest
{
public:
HLSL30VertexOutputTest() : MatchOutputCodeTest(GL_VERTEX_SHADER, 0, SH_HLSL_3_0_OUTPUT) {}
};
// Test that having dynamic indexing of a vector inside the right hand side of logical or doesn't
// trigger asserts in HLSL output.
TEST_F(HLSLOutputTest, DynamicIndexingOfVectorOnRightSideOfLogicalOr)
{
const std::string &shaderString =
"#version 300 es\n"
"precision highp float;\n"
"out vec4 my_FragColor;\n"
"uniform int u1;\n"
"void main() {\n"
" bvec4 v = bvec4(true, true, true, false);\n"
" my_FragColor = vec4(v[u1 + 1] || v[u1]);\n"
"}\n";
compile(shaderString);
}
// Test that rewriting else blocks in a function that returns a struct doesn't use the struct name
// without a prefix.
TEST_F(HLSL30VertexOutputTest, RewriteElseBlockReturningStruct)
{
const std::string &shaderString =
"struct foo\n"
"{\n"
" float member;\n"
"};\n"
"uniform bool b;\n"
"foo getFoo()\n"
"{\n"
" if (b)\n"
" {\n"
" return foo(0.0);\n"
" }\n"
" else\n"
" {\n"
" return foo(1.0);\n"
" }\n"
"}\n"
"void main()\n"
"{\n"
" gl_Position = vec4(getFoo().member);\n"
"}\n";
compile(shaderString);
EXPECT_TRUE(foundInCode("_foo"));
EXPECT_FALSE(foundInCode("(foo)"));
EXPECT_FALSE(foundInCode(" foo"));
}