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.
6
// ANGLE_base_vertex_base_instance.cpp:
7
// Test for ANGLE_base_vertex_base_instance extension
10
#include "GLSLANG/ShaderLang.h"
12
#include "compiler/translator/tree_ops/EmulateMultiDrawShaderBuiltins.h"
13
#include "gtest/gtest.h"
14
#include "tests/test_utils/compiler_test.h"
18
class EmulateGLBaseVertexBaseInstanceTest : public MatchOutputCodeTest
21
EmulateGLBaseVertexBaseInstanceTest()
22
: MatchOutputCodeTest(GL_VERTEX_SHADER, SH_VARIABLES, SH_GLSL_COMPATIBILITY_OUTPUT)
24
getResources()->ANGLE_base_vertex_base_instance = 1;
28
void CheckCompileFailure(const std::string &shaderString, const char *expectedError = nullptr)
30
std::string translatedCode;
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);
38
EXPECT_TRUE(infoLog.find(expectedError) != std::string::npos);
43
// Check that compilation fails if the compile option to emulate gl_BaseVertex and gl_BaseInstance
45
TEST_F(EmulateGLBaseVertexBaseInstanceTest, RequiresEmulation)
48
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
50
" gl_Position = vec4(float(gl_BaseVertex), float(gl_BaseInstance), 0.0, 1.0);\n"
52
"extension is not supported");
55
// Check that compiling with emulation with gl_BaseVertex and gl_BaseInstance works with different
57
TEST_F(EmulateGLBaseVertexBaseInstanceTest, CheckCompile)
59
const std::string shaderString =
60
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
62
" gl_Position = vec4(float(gl_BaseVertex), float(gl_BaseInstance), 0.0, 1.0);\n"
65
compile("#version 300 es\n" + shaderString,
66
SH_OBJECT_CODE | SH_VARIABLES | SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE);
69
// Check that gl_BaseVertex and gl_BaseInstance is properly emulated
70
TEST_F(EmulateGLBaseVertexBaseInstanceTest, EmulatesUniform)
72
addOutputType(SH_GLSL_COMPATIBILITY_OUTPUT);
73
addOutputType(SH_ESSL_OUTPUT);
74
#ifdef ANGLE_ENABLE_VULKAN
75
addOutputType(SH_GLSL_VULKAN_OUTPUT);
77
#ifdef ANGLE_ENABLE_HLSL
78
addOutputType(SH_HLSL_3_0_OUTPUT);
79
addOutputType(SH_HLSL_3_0_OUTPUT);
82
const std::string &shaderString =
84
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
86
" gl_Position = vec4(float(gl_BaseVertex), float(gl_BaseInstance), 0.0, 1.0);\n"
89
compile(shaderString, SH_OBJECT_CODE | SH_VARIABLES | SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE);
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"));
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"));
102
#ifdef ANGLE_ENABLE_VULKAN
103
EXPECT_TRUE(foundInCode(
104
SH_GLSL_VULKAN_OUTPUT,
105
"uniform defaultUniformsVS\n{\n int angle_BaseInstance;\n int angle_BaseVertex;"));
107
#ifdef ANGLE_ENABLE_HLSL
108
EXPECT_TRUE(foundInCode(SH_HLSL_3_0_OUTPUT, "uniform int angle_BaseVertex : register"));
109
EXPECT_TRUE(foundInCode(SH_HLSL_3_0_OUTPUT, "uniform int angle_BaseInstance : register"));
113
// Check that a user-defined "gl_BaseVertex" or "gl_BaseInstance" is not permitted
114
TEST_F(EmulateGLBaseVertexBaseInstanceTest, DisallowsUserDefinedGLDrawID)
116
// Check that it is not permitted without the extension
119
"uniform int gl_BaseVertex;\n"
121
" gl_Position = vec4(float(gl_BaseVertex), 0.0, 0.0, 1.0);\n"
123
"reserved built-in name");
127
"uniform int gl_BaseInstance;\n"
129
" gl_Position = vec4(float(gl_BaseInstance), 0.0, 0.0, 1.0);\n"
131
"reserved built-in name");
136
" int gl_BaseVertex = 0;\n"
137
" gl_Position = vec4(float(gl_BaseVertex), 0.0, 0.0, 1.0);\n"
139
"reserved built-in name");
144
" int gl_BaseInstance = 0;\n"
145
" gl_Position = vec4(float(gl_BaseInstance), 0.0, 0.0, 1.0);\n"
147
"reserved built-in name");
149
// Check that it is not permitted with the extension
152
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
153
"uniform int gl_BaseVertex;\n"
155
" gl_Position = vec4(float(gl_BaseVertex), 0.0, 0.0, 1.0);\n"
157
"reserved built-in name");
161
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
162
"uniform int gl_BaseInstance;\n"
164
" gl_Position = vec4(float(gl_BaseInstance), 0.0, 0.0, 1.0);\n"
166
"reserved built-in name");
170
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
172
" int gl_BaseVertex = 0;\n"
173
" gl_Position = vec4(float(gl_BaseVertex), 0.0, 0.0, 1.0);\n"
175
"reserved built-in name");
179
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
181
" int gl_BaseInstance = 0;\n"
182
" gl_Position = vec4(float(gl_BaseInstance), 0.0, 0.0, 1.0);\n"
184
"reserved built-in name");
187
// gl_BaseVertex and gl_BaseInstance are translated to angle_BaseVertex and angle_BaseInstance
188
// internally. Check that a user-defined angle_BaseVertex or angle_BaseInstance is permitted
189
TEST_F(EmulateGLBaseVertexBaseInstanceTest, AllowsUserDefinedANGLEDrawID)
191
addOutputType(SH_GLSL_COMPATIBILITY_OUTPUT);
192
addOutputType(SH_ESSL_OUTPUT);
193
#ifdef ANGLE_ENABLE_VULKAN
194
addOutputType(SH_GLSL_VULKAN_OUTPUT);
196
#ifdef ANGLE_ENABLE_HLSL
197
addOutputType(SH_HLSL_3_0_OUTPUT);
198
addOutputType(SH_HLSL_3_0_OUTPUT);
201
const std::string &shaderString =
203
"#extension GL_ANGLE_base_vertex_base_instance : require\n"
204
"uniform int angle_BaseVertex;\n"
205
"uniform int angle_BaseInstance;\n"
207
" gl_Position = vec4(\n"
208
" float(angle_BaseVertex + gl_BaseVertex),\n"
209
" float(angle_BaseInstance + gl_BaseInstance),\n"
213
compile(shaderString, SH_OBJECT_CODE | SH_VARIABLES | SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE);
215
// " angle_BaseVertex" (note the space) should appear exactly twice:
216
// once in the declaration and once in the body.
217
// The user-defined angle_BaseVertex should be decorated
218
EXPECT_TRUE(foundInCode(" angle_BaseVertex", 2));
219
EXPECT_TRUE(foundInCode(" angle_BaseInstance", 2));