Hash :
89e38b57
        
        Author :
  
        
        Date :
2022-06-22T15:04:08
        
      
Refactor to use ANGLETest vs ANGLETestWithParam Bug: angleproject:6747 Change-Id: I72ad52d0268eae0e1a401f12f3e94cc5efa402f2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3719002 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
//
// Copyright 2019 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.
//
// MatrixTest:
//   Test various shader matrix variable declarations.
#include <vector>
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
namespace
{
class MatrixTest31 : public ANGLETest<>
{
  protected:
    MatrixTest31()
    {
        setWindowWidth(64);
        setWindowHeight(64);
        setConfigRedBits(8);
        setConfigGreenBits(8);
        setConfigBlueBits(8);
        setConfigAlphaBits(8);
    }
};
TEST_P(MatrixTest31, Mat3Varying)
{
    constexpr char kVS[] = R"(#version 310 es
precision mediump float;
in vec4 a_position;
layout(location=0) out mat3 matrix;
layout(location=3) out vec3 vector;
void main()
{
    matrix = mat3(1.0);
    vector = vec3(1.0);
    gl_Position = a_position;
})";
    constexpr char kFS[] = R"(#version 310 es
precision mediump float;
layout(location=0) in mat3 matrix;
layout(location=3) in vec3 vector;
out vec4 oColor;
void main()
{
    oColor = vec4(matrix[0], 1.0);
})";
    ANGLE_GL_PROGRAM(program, kVS, kFS);
    glUseProgram(program);
    drawQuad(program, "a_position", 0.5f);
    EXPECT_GL_NO_ERROR();
}
TEST_P(MatrixTest31, Mat3VaryingBadLocation)
{
    constexpr char kVS[] = R"(#version 310 es
precision mediump float;
in vec4 a_position;
layout(location=0) out mat3 matrix;
layout(location=2) out vec3 vector;
void main()
{
    matrix = mat3(1.0);
    vector = vec3(1.0);
    gl_Position = a_position;
})";
    GLProgram program;
    GLuint vs                    = glCreateShader(GL_VERTEX_SHADER);
    const char *sourceVsArray[1] = {kVS};
    glShaderSource(vs, 1, sourceVsArray, nullptr);
    glCompileShader(vs);
    GLint compileResult;
    glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
    EXPECT_GL_FALSE(compileResult);
}
TEST_P(MatrixTest31, Mat3x4Varying)
{
    constexpr char kVS[] = R"(#version 310 es
precision mediump float;
in vec4 a_position;
layout(location=0) out mat3x4 matrix;
layout(location=3) out vec3 vector;
void main()
{
    matrix = mat3x4(1.0);
    vector = vec3(1.0);
    gl_Position = a_position;
})";
    constexpr char kFS[] = R"(#version 310 es
precision mediump float;
layout(location=0) in mat3x4 matrix;
layout(location=3) in vec3 vector;
out vec4 oColor;
void main()
{
    oColor = vec4(matrix[0]);
})";
    ANGLE_GL_PROGRAM(program, kVS, kFS);
    glUseProgram(program);
    drawQuad(program, "a_position", 0.5f);
    EXPECT_GL_NO_ERROR();
}
TEST_P(MatrixTest31, Mat3x4VaryingBadLocation)
{
    constexpr char kVS[] = R"(#version 310 es
precision mediump float;
in vec4 a_position;
layout(location=0) out mat3x4 matrix;
layout(location=2) out vec3 vector;
void main()
{
    matrix = mat3x4(1.0);
    vector = vec3(1.0);
    gl_Position = a_position;
})";
    GLProgram program;
    GLuint vs                    = glCreateShader(GL_VERTEX_SHADER);
    const char *sourceVsArray[1] = {kVS};
    glShaderSource(vs, 1, sourceVsArray, nullptr);
    glCompileShader(vs);
    GLint compileResult;
    glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
    EXPECT_GL_FALSE(compileResult);
}
TEST_P(MatrixTest31, Mat3x4ArrayVarying)
{
    constexpr char kVS[] = R"(#version 310 es
precision mediump float;
in vec4 a_position;
layout(location=0) out mat3x4[2] matrix;
layout(location=6) out vec3 vector;
void main()
{
    matrix[0] = mat3x4(1.0);
    matrix[1] = mat3x4(1.0);
    vector = vec3(1.0);
    gl_Position = a_position;
})";
    constexpr char kFS[] = R"(#version 310 es
precision mediump float;
layout(location=0) in mat3x4[2] matrix;
layout(location=6) in vec3 vector;
out vec4 oColor;
void main()
{
    oColor = vec4(matrix[0][0]);
})";
    ANGLE_GL_PROGRAM(program, kVS, kFS);
    glUseProgram(program);
    drawQuad(program, "a_position", 0.5f);
    EXPECT_GL_NO_ERROR();
}
TEST_P(MatrixTest31, Mat3x4ArrayVaryingBadLocation)
{
    constexpr char kVS[] = R"(#version 310 es
precision mediump float;
in vec4 a_position;
layout(location=0) out mat3x4[2] matrix;
layout(location=5) out vec3 vector;
void main()
{
    matrix[0] = mat3x4(1.0);
    matrix[1] = mat3x4(1.0);
    vector = vec3(1.0);
    gl_Position = a_position;
})";
    GLProgram program;
    GLuint vs                    = glCreateShader(GL_VERTEX_SHADER);
    const char *sourceVsArray[1] = {kVS};
    glShaderSource(vs, 1, sourceVsArray, nullptr);
    glCompileShader(vs);
    GLint compileResult;
    glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
    EXPECT_GL_FALSE(compileResult);
}
TEST_P(MatrixTest31, Mat3x4StructVarying)
{
    constexpr char kVS[] = R"(#version 310 es
precision mediump float;
in vec4 a_position;
struct S
{
    mat3x4 m;
};
layout(location=0) out S matrix;
layout(location=3) out vec3 vector;
void main()
{
    matrix.m = mat3x4(1.0);
    vector = vec3(1.0);
    gl_Position = a_position;
})";
    constexpr char kFS[] = R"(#version 310 es
precision mediump float;
struct S
{
    mat3x4 m;
};
layout(location=0) in S matrix;
layout(location=3) in vec3 vector;
out vec4 oColor;
void main()
{
    oColor = vec4(matrix.m[0]);
})";
    ANGLE_GL_PROGRAM(program, kVS, kFS);
    glUseProgram(program);
    drawQuad(program, "a_position", 0.5f);
    EXPECT_GL_NO_ERROR();
}
TEST_P(MatrixTest31, Mat3x4StructVaryingBadLocation)
{
    constexpr char kVS[] = R"(#version 310 es
precision mediump float;
in vec4 a_position;
struct S
{
    mat3x4 m;
};
layout(location=0) out S matrix;
layout(location=2) out vec3 vector;
void main()
{
    matrix.m = mat3x4(1.0);
    vector = vec3(1.0);
    gl_Position = a_position;
})";
    GLProgram program;
    GLuint vs                    = glCreateShader(GL_VERTEX_SHADER);
    const char *sourceVsArray[1] = {kVS};
    glShaderSource(vs, 1, sourceVsArray, nullptr);
    glCompileShader(vs);
    GLint compileResult;
    glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
    EXPECT_GL_FALSE(compileResult);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MatrixTest31);
ANGLE_INSTANTIATE_TEST_ES31(MatrixTest31);
}  // namespace