Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6423b7f

Browse files
timvpGoogleCommit Bot
authored andcommitted
Return the correct location count for Matrices
GetLocationCount() is currently returning the number of rows in the matrix, rather than the columns, which leads to shader validation errors (and test failures). This fix returns the number of columns in a matrix. Bug: angleproject:4200 Test: dEQP-GLES31.functional.separate_shader.random.63 Change-Id: I8d25eb3733c2ddbe53ff54794f480c1d43e22a88 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1952173 Reviewed-by: Shahbaz Youssefi <[email protected]> Reviewed-by: Courtney Goeltzenleuchter <[email protected]> Commit-Queue: Tim Van Patten <[email protected]>
1 parent 20432bf commit 6423b7f

File tree

3 files changed

+238
-1
lines changed

3 files changed

+238
-1
lines changed

src/compiler/translator/ValidateVaryingLocations.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ int GetLocationCount(const TIntermSymbol *varying, bool ignoreVaryingArraySize)
5353
ASSERT(!varyingType.isArrayOfArrays());
5454
return varyingType.getSecondarySize();
5555
}
56+
else if (varyingType.isMatrix())
57+
{
58+
return varyingType.getNominalSize() * static_cast<int>(varyingType.getArraySizeProduct());
59+
}
5660
else
5761
{
58-
return varyingType.getSecondarySize() * static_cast<int>(varyingType.getArraySizeProduct());
62+
return static_cast<int>(varyingType.getArraySizeProduct());
5963
}
6064
}
6165

src/tests/angle_end2end_tests.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ angle_end2end_tests_sources = [
7676
"gl_tests/InstancingTest.cpp",
7777
"gl_tests/LineLoopTest.cpp",
7878
"gl_tests/LinkAndRelinkTest.cpp",
79+
"gl_tests/MatrixTest.cpp",
7980
"gl_tests/MaxTextureSizeTest.cpp",
8081
"gl_tests/MemorySizeTest.cpp",
8182
"gl_tests/MemoryObjectTest.cpp",

src/tests/gl_tests/MatrixTest.cpp

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
//
2+
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
//
6+
// MatrixTest:
7+
// Test various shader matrix variable declarations.
8+
9+
#include <vector>
10+
#include "test_utils/ANGLETest.h"
11+
#include "test_utils/gl_raii.h"
12+
13+
using namespace angle;
14+
15+
namespace
16+
{
17+
18+
class MatrixTest31 : public ANGLETest
19+
{
20+
protected:
21+
MatrixTest31()
22+
{
23+
setWindowWidth(64);
24+
setWindowHeight(64);
25+
setConfigRedBits(8);
26+
setConfigGreenBits(8);
27+
setConfigBlueBits(8);
28+
setConfigAlphaBits(8);
29+
}
30+
};
31+
32+
TEST_P(MatrixTest31, Mat3Varying)
33+
{
34+
constexpr char kVS[] = R"(#version 310 es
35+
precision mediump float;
36+
37+
in vec4 a_position;
38+
39+
layout(location=0) out mat3 matrix;
40+
layout(location=3) out vec3 vector;
41+
42+
void main()
43+
{
44+
matrix = mat3(1.0);
45+
vector = vec3(1.0);
46+
gl_Position = a_position;
47+
})";
48+
49+
constexpr char kFS[] = R"(#version 310 es
50+
precision mediump float;
51+
52+
layout(location=0) in mat3 matrix;
53+
layout(location=3) in vec3 vector;
54+
55+
out vec4 oColor;
56+
57+
void main()
58+
{
59+
oColor = vec4(matrix[0], 1.0);
60+
})";
61+
62+
ANGLE_GL_PROGRAM(program, kVS, kFS);
63+
glUseProgram(program);
64+
drawQuad(program, "a_position", 0.5f);
65+
EXPECT_GL_NO_ERROR();
66+
}
67+
68+
TEST_P(MatrixTest31, Mat3VaryingBadLocation)
69+
{
70+
constexpr char kVS[] = R"(#version 310 es
71+
precision mediump float;
72+
73+
in vec4 a_position;
74+
75+
layout(location=0) out mat3 matrix;
76+
layout(location=2) out vec3 vector;
77+
78+
void main()
79+
{
80+
matrix = mat3(1.0);
81+
vector = vec3(1.0);
82+
gl_Position = a_position;
83+
})";
84+
85+
GLProgram program;
86+
87+
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
88+
const char *sourceVsArray[1] = {kVS};
89+
glShaderSource(vs, 1, sourceVsArray, nullptr);
90+
glCompileShader(vs);
91+
GLint compileResult;
92+
glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
93+
EXPECT_GL_FALSE(compileResult);
94+
}
95+
96+
TEST_P(MatrixTest31, Mat3x4Varying)
97+
{
98+
constexpr char kVS[] = R"(#version 310 es
99+
precision mediump float;
100+
101+
in vec4 a_position;
102+
103+
layout(location=0) out mat3x4 matrix;
104+
layout(location=3) out vec3 vector;
105+
106+
void main()
107+
{
108+
matrix = mat3x4(1.0);
109+
vector = vec3(1.0);
110+
gl_Position = a_position;
111+
})";
112+
113+
constexpr char kFS[] = R"(#version 310 es
114+
precision mediump float;
115+
116+
layout(location=0) in mat3x4 matrix;
117+
layout(location=3) in vec3 vector;
118+
119+
out vec4 oColor;
120+
121+
void main()
122+
{
123+
oColor = vec4(matrix[0]);
124+
})";
125+
126+
ANGLE_GL_PROGRAM(program, kVS, kFS);
127+
glUseProgram(program);
128+
drawQuad(program, "a_position", 0.5f);
129+
EXPECT_GL_NO_ERROR();
130+
}
131+
132+
TEST_P(MatrixTest31, Mat3x4VaryingBadLocation)
133+
{
134+
constexpr char kVS[] = R"(#version 310 es
135+
precision mediump float;
136+
137+
in vec4 a_position;
138+
139+
layout(location=0) out mat3x4 matrix;
140+
layout(location=2) out vec3 vector;
141+
142+
void main()
143+
{
144+
matrix = mat3x4(1.0);
145+
vector = vec3(1.0);
146+
gl_Position = a_position;
147+
})";
148+
149+
GLProgram program;
150+
151+
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
152+
const char *sourceVsArray[1] = {kVS};
153+
glShaderSource(vs, 1, sourceVsArray, nullptr);
154+
glCompileShader(vs);
155+
GLint compileResult;
156+
glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
157+
EXPECT_GL_FALSE(compileResult);
158+
}
159+
160+
TEST_P(MatrixTest31, Mat3x4ArrayVarying)
161+
{
162+
constexpr char kVS[] = R"(#version 310 es
163+
precision mediump float;
164+
165+
in vec4 a_position;
166+
167+
layout(location=0) out mat3x4[2] matrix;
168+
layout(location=6) out vec3 vector;
169+
170+
void main()
171+
{
172+
matrix[0] = mat3x4(1.0);
173+
matrix[1] = mat3x4(1.0);
174+
vector = vec3(1.0);
175+
gl_Position = a_position;
176+
})";
177+
178+
constexpr char kFS[] = R"(#version 310 es
179+
precision mediump float;
180+
181+
layout(location=0) in mat3x4[2] matrix;
182+
layout(location=6) in vec3 vector;
183+
184+
out vec4 oColor;
185+
186+
bool isZero(vec4 value) {
187+
return value == vec4(0,0,0,0);
188+
}
189+
190+
void main()
191+
{
192+
oColor = vec4(matrix[0][0]);
193+
})";
194+
195+
ANGLE_GL_PROGRAM(program, kVS, kFS);
196+
glUseProgram(program);
197+
drawQuad(program, "a_position", 0.5f);
198+
EXPECT_GL_NO_ERROR();
199+
}
200+
201+
TEST_P(MatrixTest31, Mat3x4ArrayVaryingBadLocation)
202+
{
203+
constexpr char kVS[] = R"(#version 310 es
204+
precision mediump float;
205+
206+
in vec4 a_position;
207+
208+
layout(location=0) out mat3x4[2] matrix;
209+
layout(location=5) out vec3 vector;
210+
211+
void main()
212+
{
213+
matrix[0] = mat3x4(1.0);
214+
matrix[1] = mat3x4(1.0);
215+
vector = vec3(1.0);
216+
gl_Position = a_position;
217+
})";
218+
219+
GLProgram program;
220+
221+
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
222+
const char *sourceVsArray[1] = {kVS};
223+
glShaderSource(vs, 1, sourceVsArray, nullptr);
224+
glCompileShader(vs);
225+
GLint compileResult;
226+
glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
227+
EXPECT_GL_FALSE(compileResult);
228+
}
229+
230+
ANGLE_INSTANTIATE_TEST_ES31(MatrixTest31);
231+
232+
} // namespace

0 commit comments

Comments
 (0)