Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/compiler_tests/EmulateGLBaseVertexBaseInstance_test.cpp
1693 views
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
// ANGLE_base_vertex_base_instance.cpp:
7
// Test for ANGLE_base_vertex_base_instance extension
8
//
9
10
#include "GLSLANG/ShaderLang.h"
11
#include "angle_gl.h"
12
#include "compiler/translator/tree_ops/EmulateMultiDrawShaderBuiltins.h"
13
#include "gtest/gtest.h"
14
#include "tests/test_utils/compiler_test.h"
15
16
using namespace sh;
17
18
class EmulateGLBaseVertexBaseInstanceTest : public MatchOutputCodeTest
19
{
20
public:
21
EmulateGLBaseVertexBaseInstanceTest()
22
: MatchOutputCodeTest(GL_VERTEX_SHADER, SH_VARIABLES, SH_GLSL_COMPATIBILITY_OUTPUT)
23
{
24
getResources()->ANGLE_base_vertex_base_instance = 1;
25
}
26
27
protected:
28
void CheckCompileFailure(const std::string &shaderString, const char *expectedError = nullptr)
29
{
30
std::string translatedCode;
31
std::string infoLog;
32
bool success = compileTestShader(GL_VERTEX_SHADER, SH_GLES3_SPEC,
33
SH_GLSL_COMPATIBILITY_OUTPUT, shaderString, getResources(),
34
SH_VARIABLES, &translatedCode, &infoLog);
35
EXPECT_FALSE(success);
36
if (expectedError)
37
{
38
EXPECT_TRUE(infoLog.find(expectedError) != std::string::npos);
39
}
40
}
41
};
42
43
// Check that compilation fails if the compile option to emulate gl_BaseVertex and gl_BaseInstance
44
// is not set
45
TEST_F(EmulateGLBaseVertexBaseInstanceTest, RequiresEmulation)
46
{
47
CheckCompileFailure(
48
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
49
"void main() {\n"
50
" gl_Position = vec4(float(gl_BaseVertex), float(gl_BaseInstance), 0.0, 1.0);\n"
51
"}\n",
52
"extension is not supported");
53
}
54
55
// Check that compiling with emulation with gl_BaseVertex and gl_BaseInstance works with different
56
// shader versions
57
TEST_F(EmulateGLBaseVertexBaseInstanceTest, CheckCompile)
58
{
59
const std::string shaderString =
60
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
61
"void main() {\n"
62
" gl_Position = vec4(float(gl_BaseVertex), float(gl_BaseInstance), 0.0, 1.0);\n"
63
"}\n";
64
65
compile("#version 300 es\n" + shaderString,
66
SH_OBJECT_CODE | SH_VARIABLES | SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE);
67
}
68
69
// Check that gl_BaseVertex and gl_BaseInstance is properly emulated
70
TEST_F(EmulateGLBaseVertexBaseInstanceTest, EmulatesUniform)
71
{
72
addOutputType(SH_GLSL_COMPATIBILITY_OUTPUT);
73
addOutputType(SH_ESSL_OUTPUT);
74
#ifdef ANGLE_ENABLE_VULKAN
75
addOutputType(SH_SPIRV_VULKAN_OUTPUT);
76
#endif
77
#ifdef ANGLE_ENABLE_HLSL
78
addOutputType(SH_HLSL_3_0_OUTPUT);
79
addOutputType(SH_HLSL_3_0_OUTPUT);
80
#endif
81
82
const std::string &shaderString =
83
"#version 300 es\n"
84
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
85
"void main() {\n"
86
" gl_Position = vec4(float(gl_BaseVertex), float(gl_BaseInstance), 0.0, 1.0);\n"
87
"}\n";
88
89
compile(shaderString, SH_OBJECT_CODE | SH_VARIABLES | SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE);
90
91
EXPECT_TRUE(notFoundInCode("gl_BaseVertex"));
92
EXPECT_TRUE(foundInCode("angle_BaseVertex"));
93
EXPECT_TRUE(notFoundInCode("gl_BaseInstance"));
94
EXPECT_TRUE(foundInCode("angle_BaseInstance"));
95
EXPECT_TRUE(notFoundInCode("GL_ANGLE_base_vertex_base_instance"));
96
97
EXPECT_TRUE(foundInCode(SH_GLSL_COMPATIBILITY_OUTPUT, "uniform int angle_BaseVertex"));
98
EXPECT_TRUE(foundInCode(SH_GLSL_COMPATIBILITY_OUTPUT, "uniform int angle_BaseInstance"));
99
EXPECT_TRUE(foundInCode(SH_ESSL_OUTPUT, "uniform highp int angle_BaseVertex"));
100
EXPECT_TRUE(foundInCode(SH_ESSL_OUTPUT, "uniform highp int angle_BaseInstance"));
101
102
#ifdef ANGLE_ENABLE_HLSL
103
EXPECT_TRUE(foundInCode(SH_HLSL_3_0_OUTPUT, "uniform int angle_BaseVertex : register"));
104
EXPECT_TRUE(foundInCode(SH_HLSL_3_0_OUTPUT, "uniform int angle_BaseInstance : register"));
105
#endif
106
}
107
108
// Check that a user-defined "gl_BaseVertex" or "gl_BaseInstance" is not permitted
109
TEST_F(EmulateGLBaseVertexBaseInstanceTest, DisallowsUserDefinedGLDrawID)
110
{
111
// Check that it is not permitted without the extension
112
CheckCompileFailure(
113
"#version 300 es\n"
114
"uniform int gl_BaseVertex;\n"
115
"void main() {\n"
116
" gl_Position = vec4(float(gl_BaseVertex), 0.0, 0.0, 1.0);\n"
117
"}\n",
118
"reserved built-in name");
119
120
CheckCompileFailure(
121
"#version 300 es\n"
122
"uniform int gl_BaseInstance;\n"
123
"void main() {\n"
124
" gl_Position = vec4(float(gl_BaseInstance), 0.0, 0.0, 1.0);\n"
125
"}\n",
126
"reserved built-in name");
127
128
CheckCompileFailure(
129
"#version 300 es\n"
130
"void main() {\n"
131
" int gl_BaseVertex = 0;\n"
132
" gl_Position = vec4(float(gl_BaseVertex), 0.0, 0.0, 1.0);\n"
133
"}\n",
134
"reserved built-in name");
135
136
CheckCompileFailure(
137
"#version 300 es\n"
138
"void main() {\n"
139
" int gl_BaseInstance = 0;\n"
140
" gl_Position = vec4(float(gl_BaseInstance), 0.0, 0.0, 1.0);\n"
141
"}\n",
142
"reserved built-in name");
143
144
// Check that it is not permitted with the extension
145
CheckCompileFailure(
146
"#version 300 es\n"
147
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
148
"uniform int gl_BaseVertex;\n"
149
"void main() {\n"
150
" gl_Position = vec4(float(gl_BaseVertex), 0.0, 0.0, 1.0);\n"
151
"}\n",
152
"reserved built-in name");
153
154
CheckCompileFailure(
155
"#version 300 es\n"
156
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
157
"uniform int gl_BaseInstance;\n"
158
"void main() {\n"
159
" gl_Position = vec4(float(gl_BaseInstance), 0.0, 0.0, 1.0);\n"
160
"}\n",
161
"reserved built-in name");
162
163
CheckCompileFailure(
164
"#version 300 es\n"
165
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
166
"void main() {\n"
167
" int gl_BaseVertex = 0;\n"
168
" gl_Position = vec4(float(gl_BaseVertex), 0.0, 0.0, 1.0);\n"
169
"}\n",
170
"reserved built-in name");
171
172
CheckCompileFailure(
173
"#version 300 es\n"
174
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
175
"void main() {\n"
176
" int gl_BaseInstance = 0;\n"
177
" gl_Position = vec4(float(gl_BaseInstance), 0.0, 0.0, 1.0);\n"
178
"}\n",
179
"reserved built-in name");
180
}
181
182
// gl_BaseVertex and gl_BaseInstance are translated to angle_BaseVertex and angle_BaseInstance
183
// internally. Check that a user-defined angle_BaseVertex or angle_BaseInstance is permitted
184
TEST_F(EmulateGLBaseVertexBaseInstanceTest, AllowsUserDefinedANGLEDrawID)
185
{
186
addOutputType(SH_GLSL_COMPATIBILITY_OUTPUT);
187
addOutputType(SH_ESSL_OUTPUT);
188
#ifdef ANGLE_ENABLE_VULKAN
189
addOutputType(SH_SPIRV_VULKAN_OUTPUT);
190
#endif
191
#ifdef ANGLE_ENABLE_HLSL
192
addOutputType(SH_HLSL_3_0_OUTPUT);
193
addOutputType(SH_HLSL_3_0_OUTPUT);
194
#endif
195
196
const std::string &shaderString =
197
"#version 300 es\n"
198
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
199
"uniform int angle_BaseVertex;\n"
200
"uniform int angle_BaseInstance;\n"
201
"void main() {\n"
202
" gl_Position = vec4(\n"
203
" float(angle_BaseVertex + gl_BaseVertex),\n"
204
" float(angle_BaseInstance + gl_BaseInstance),\n"
205
" 0.0, 1.0);\n"
206
"}\n";
207
208
compile(shaderString, SH_OBJECT_CODE | SH_VARIABLES | SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE);
209
210
// " angle_BaseVertex" (note the space) should appear exactly twice:
211
// once in the declaration and once in the body.
212
// The user-defined angle_BaseVertex should be decorated
213
EXPECT_TRUE(foundInCode(" angle_BaseVertex", 2));
214
EXPECT_TRUE(foundInCode(" angle_BaseInstance", 2));
215
}
216
217