blob: 58d50eaa7cdebcf5e3e3a5f7e151aae4f9a0df36 [file] [log] [blame]
Martin Radev14a26ae2017-07-24 15:56:29 +03001//
2// Copyright 2017 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// Multiview draw tests:
7// Test issuing multiview Draw* commands.
8//
9
Martin Radevc1d4e552017-08-21 12:01:10 +030010#include "platform/WorkaroundsD3D.h"
Martin Radev14a26ae2017-07-24 15:56:29 +030011#include "test_utils/ANGLETest.h"
12#include "test_utils/gl_raii.h"
13
14using namespace angle;
15
Martin Radev61bd9992017-08-11 13:10:55 +030016namespace
17{
Martin Radevced5c862017-08-17 16:05:29 +030018GLuint CreateSimplePassthroughProgram(int numViews)
Martin Radev61bd9992017-08-11 13:10:55 +030019{
20 const std::string vsSource =
21 "#version 300 es\n"
22 "#extension GL_OVR_multiview : require\n"
Martin Radevced5c862017-08-17 16:05:29 +030023 "layout(num_views = " +
24 ToString(numViews) +
25 ") in;\n"
Martin Radev61bd9992017-08-11 13:10:55 +030026 "layout(location=0) in vec2 vPosition;\n"
27 "void main()\n"
28 "{\n"
Martin Radevced5c862017-08-17 16:05:29 +030029 " gl_PointSize = 1.;\n"
Martin Radev61bd9992017-08-11 13:10:55 +030030 " gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n"
31 "}\n";
32
33 const std::string fsSource =
34 "#version 300 es\n"
35 "#extension GL_OVR_multiview : require\n"
36 "precision mediump float;\n"
37 "out vec4 col;\n"
38 "void main()\n"
39 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +030040 " col = vec4(0,1,0,1);\n"
Martin Radev61bd9992017-08-11 13:10:55 +030041 "}\n";
42 return CompileProgram(vsSource, fsSource);
43}
44
45std::vector<Vector2> ConvertPixelCoordinatesToClipSpace(const std::vector<Vector2I> &pixels,
46 int width,
47 int height)
48{
49 std::vector<Vector2> result(pixels.size());
50 for (size_t i = 0; i < pixels.size(); ++i)
51 {
52 const auto &pixel = pixels[i];
53 float pixelCenterRelativeX = (static_cast<float>(pixel.x()) + .5f) / width;
54 float pixelCenterRelativeY = (static_cast<float>(pixel.y()) + .5f) / height;
55 float xInClipSpace = 2.f * pixelCenterRelativeX - 1.f;
56 float yInClipSpace = 2.f * pixelCenterRelativeY - 1.f;
57 result[i] = Vector2(xInClipSpace, yInClipSpace);
58 }
59 return result;
60}
61} // namespace
62
Martin Radevc1d4e552017-08-21 12:01:10 +030063struct MultiviewImplementationParams : public PlatformParameters
Martin Radev3c25ad02017-08-22 17:36:53 +030064{
Martin Radevc1d4e552017-08-21 12:01:10 +030065 MultiviewImplementationParams(bool forceUseGeometryShaderOnD3D,
66 const EGLPlatformParameters &eglPlatformParameters)
67 : PlatformParameters(3, 0, eglPlatformParameters),
68 mForceUseGeometryShaderOnD3D(forceUseGeometryShaderOnD3D)
69 {
70 }
71 bool mForceUseGeometryShaderOnD3D;
72};
73
74std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams &params)
75{
76 const PlatformParameters &base = static_cast<const PlatformParameters &>(params);
77 os << base;
78 if (params.mForceUseGeometryShaderOnD3D)
79 {
80 os << "_force_geom_shader";
81 }
82 else
83 {
84 os << "_vertex_shader";
85 }
86 return os;
87}
88
89struct MultiviewTestParams final : public MultiviewImplementationParams
90{
91 MultiviewTestParams(GLenum multiviewLayout,
92 const MultiviewImplementationParams &implementationParams)
93 : MultiviewImplementationParams(implementationParams), mMultiviewLayout(multiviewLayout)
Martin Radev3c25ad02017-08-22 17:36:53 +030094 {
95 ASSERT(multiviewLayout == GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE ||
96 multiviewLayout == GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE);
97 }
98 GLenum mMultiviewLayout;
99};
100
101std::ostream &operator<<(std::ostream &os, const MultiviewTestParams &params)
102{
Martin Radevc1d4e552017-08-21 12:01:10 +0300103 const MultiviewImplementationParams &base =
104 static_cast<const MultiviewImplementationParams &>(params);
Martin Radev3c25ad02017-08-22 17:36:53 +0300105 os << base;
106 switch (params.mMultiviewLayout)
107 {
108 case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE:
109 os << "_layered";
110 break;
111 case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE:
112 os << "_side_by_side";
113 break;
114 default:
115 UNREACHABLE();
116 }
117 return os;
118}
119
120class MultiviewDrawTest : public ANGLETestBase
Martin Radev14a26ae2017-07-24 15:56:29 +0300121{
122 protected:
Martin Radev3c25ad02017-08-22 17:36:53 +0300123 MultiviewDrawTest(const PlatformParameters &params) : ANGLETestBase(params)
Martin Radev14a26ae2017-07-24 15:56:29 +0300124 {
125 setWindowWidth(128);
126 setWindowHeight(128);
127 setWebGLCompatibilityEnabled(true);
128 }
Martin Radev7cf61662017-07-26 17:10:53 +0300129 virtual ~MultiviewDrawTest() {}
Martin Radev14a26ae2017-07-24 15:56:29 +0300130
Martin Radev3c25ad02017-08-22 17:36:53 +0300131 void DrawTestSetUp()
Martin Radev14a26ae2017-07-24 15:56:29 +0300132 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300133 ANGLETestBase::ANGLETestSetUp();
Martin Radev14a26ae2017-07-24 15:56:29 +0300134
135 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
136 eglGetProcAddress("glRequestExtensionANGLE"));
137 }
138
139 // Requests the ANGLE_multiview extension and returns true if the operation succeeds.
140 bool requestMultiviewExtension()
141 {
142 if (extensionRequestable("GL_ANGLE_multiview"))
143 {
144 glRequestExtensionANGLE("GL_ANGLE_multiview");
145 }
146
147 if (!extensionEnabled("GL_ANGLE_multiview"))
148 {
149 std::cout << "Test skipped due to missing GL_ANGLE_multiview." << std::endl;
150 return false;
151 }
152 return true;
153 }
154
155 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
156};
157
Martin Radev3c25ad02017-08-22 17:36:53 +0300158class MultiviewDrawValidationTest : public MultiviewDrawTest,
159 public ::testing::TestWithParam<PlatformParameters>
Martin Radev7cf61662017-07-26 17:10:53 +0300160{
161 protected:
Martin Radev3c25ad02017-08-22 17:36:53 +0300162 MultiviewDrawValidationTest() : MultiviewDrawTest(GetParam()) {}
Martin Radev7cf61662017-07-26 17:10:53 +0300163
164 void SetUp() override
165 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300166 MultiviewDrawTest::DrawTestSetUp();
Martin Radev7cf61662017-07-26 17:10:53 +0300167
168 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
169
170 glBindTexture(GL_TEXTURE_2D, mTex2d);
171 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
172
173 glBindVertexArray(mVao);
174
175 const float kVertexData[3] = {0.0f};
176 glBindBuffer(GL_ARRAY_BUFFER, mVbo);
177 glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3u, &kVertexData[0], GL_STATIC_DRAW);
178
179 const unsigned int kIndices[3] = {0u, 1u, 2u};
180 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIbo);
181 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * 3, &kIndices[0],
182 GL_STATIC_DRAW);
183 ASSERT_GL_NO_ERROR();
184 }
185
186 GLTexture mTex2d;
187 GLVertexArray mVao;
188 GLBuffer mVbo;
189 GLBuffer mIbo;
190 GLFramebuffer mFramebuffer;
191};
192
Martin Radev3c25ad02017-08-22 17:36:53 +0300193class MultiviewRenderTestBase : public MultiviewDrawTest
Martin Radev8f276e22017-05-30 12:05:52 +0300194{
195 protected:
Martin Radev3c25ad02017-08-22 17:36:53 +0300196 MultiviewRenderTestBase(const PlatformParameters &params, GLenum multiviewLayout)
197 : MultiviewDrawTest(params),
198 mMultiviewLayout(multiviewLayout),
199 mViewWidth(0),
200 mViewHeight(0),
201 mNumViews(0)
Martin Radev8f276e22017-05-30 12:05:52 +0300202 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300203 }
204 void RenderTestSetUp() { MultiviewDrawTest::DrawTestSetUp(); }
Martin Radev72b4e1e2017-08-31 15:42:56 +0300205 void createFBO(int viewWidth, int height, int numViews, int numLayers, int baseViewIndex)
Martin Radev3c25ad02017-08-22 17:36:53 +0300206 {
Martin Radev72b4e1e2017-08-31 15:42:56 +0300207 ASSERT(numViews + baseViewIndex <= numLayers);
208
Martin Radev3c25ad02017-08-22 17:36:53 +0300209 mViewWidth = viewWidth;
210 mViewHeight = height;
211 mNumViews = numViews;
Martin Radev8f276e22017-05-30 12:05:52 +0300212
Martin Radev0abb7a22017-08-28 15:34:45 +0300213 mColorTexture.reset();
214 mDepthTexture.reset();
215 mDrawFramebuffer.reset();
216 mReadFramebuffer.clear();
217
Martin Radev8f276e22017-05-30 12:05:52 +0300218 // Create color and depth textures.
Martin Radev3c25ad02017-08-22 17:36:53 +0300219 switch (mMultiviewLayout)
Martin Radev8f276e22017-05-30 12:05:52 +0300220 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300221 case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE:
222 {
223 int textureWidth = viewWidth * numViews;
224 glBindTexture(GL_TEXTURE_2D, mColorTexture);
225 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, height, 0, GL_RGBA,
Luc Ferronadcf0ae2018-01-24 08:27:37 -0500226 GL_UNSIGNED_BYTE, nullptr);
Martin Radev3c25ad02017-08-22 17:36:53 +0300227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
229
230 glBindTexture(GL_TEXTURE_2D, mDepthTexture);
231 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, textureWidth, height, 0,
Luc Ferronadcf0ae2018-01-24 08:27:37 -0500232 GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
Martin Radev3c25ad02017-08-22 17:36:53 +0300233 glBindTexture(GL_TEXTURE_2D, 0);
234 break;
235 }
236 case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE:
237 glBindTexture(GL_TEXTURE_2D_ARRAY, mColorTexture);
Martin Radev72b4e1e2017-08-31 15:42:56 +0300238 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, viewWidth, height, numLayers, 0,
Luc Ferronadcf0ae2018-01-24 08:27:37 -0500239 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Martin Radev3c25ad02017-08-22 17:36:53 +0300240 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
241 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
242
243 glBindTexture(GL_TEXTURE_2D_ARRAY, mDepthTexture);
244 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT32F, viewWidth, height,
Luc Ferronadcf0ae2018-01-24 08:27:37 -0500245 numLayers, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
Martin Radev3c25ad02017-08-22 17:36:53 +0300246 glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
247 break;
248 default:
249 UNREACHABLE();
Martin Radev8f276e22017-05-30 12:05:52 +0300250 }
Martin Radev3c25ad02017-08-22 17:36:53 +0300251 ASSERT_GL_NO_ERROR();
252
253 // Create draw framebuffer to be used for multiview rendering.
254 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
255 switch (mMultiviewLayout)
256 {
257 case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE:
258 {
259 std::vector<GLint> viewportOffsets(numViews * 2);
260 for (int i = 0u; i < numViews; ++i)
261 {
262 viewportOffsets[i * 2] = i * viewWidth;
263 viewportOffsets[i * 2 + 1] = 0;
264 }
265 glFramebufferTextureMultiviewSideBySideANGLE(GL_DRAW_FRAMEBUFFER,
266 GL_COLOR_ATTACHMENT0, mColorTexture, 0,
267 numViews, &viewportOffsets[0]);
268 glFramebufferTextureMultiviewSideBySideANGLE(GL_DRAW_FRAMEBUFFER,
269 GL_DEPTH_ATTACHMENT, mDepthTexture, 0,
270 numViews, &viewportOffsets[0]);
271 break;
272 }
273 case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE:
274 glFramebufferTextureMultiviewLayeredANGLE(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
Martin Radev72b4e1e2017-08-31 15:42:56 +0300275 mColorTexture, 0, baseViewIndex,
276 numViews);
Martin Radev3c25ad02017-08-22 17:36:53 +0300277 glFramebufferTextureMultiviewLayeredANGLE(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
Martin Radev72b4e1e2017-08-31 15:42:56 +0300278 mDepthTexture, 0, baseViewIndex,
279 numViews);
Martin Radev3c25ad02017-08-22 17:36:53 +0300280 break;
281 default:
282 UNREACHABLE();
283 }
Martin Radev8f276e22017-05-30 12:05:52 +0300284
285 GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
286 glDrawBuffers(1, DrawBuffers);
287 ASSERT_GL_NO_ERROR();
288 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER));
289
290 // Create read framebuffer to be used to retrieve the pixel information for testing
291 // purposes.
Martin Radev3c25ad02017-08-22 17:36:53 +0300292 switch (mMultiviewLayout)
293 {
294 case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE:
295 mReadFramebuffer.resize(1);
296 glBindFramebuffer(GL_READ_FRAMEBUFFER, mReadFramebuffer[0]);
297 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
298 mColorTexture, 0);
Martin Radev72b4e1e2017-08-31 15:42:56 +0300299 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE,
300 glCheckFramebufferStatus(GL_READ_FRAMEBUFFER));
Martin Radev3c25ad02017-08-22 17:36:53 +0300301 break;
302 case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE:
Martin Radev72b4e1e2017-08-31 15:42:56 +0300303 mReadFramebuffer.resize(numLayers);
304 for (int i = 0; i < numLayers; ++i)
Martin Radev3c25ad02017-08-22 17:36:53 +0300305 {
Martin Radev72b4e1e2017-08-31 15:42:56 +0300306 glBindFramebuffer(GL_FRAMEBUFFER, mReadFramebuffer[i]);
307 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mColorTexture,
308 0, i);
309 glClearColor(0, 0, 0, 0);
310 glClear(GL_COLOR_BUFFER_BIT);
311 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE,
312 glCheckFramebufferStatus(GL_READ_FRAMEBUFFER));
Martin Radev3c25ad02017-08-22 17:36:53 +0300313 }
Martin Radev72b4e1e2017-08-31 15:42:56 +0300314 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
Martin Radev3c25ad02017-08-22 17:36:53 +0300315 break;
316 default:
317 UNREACHABLE();
318 }
Martin Radev8f276e22017-05-30 12:05:52 +0300319
320 // Clear the buffers.
Martin Radev3c25ad02017-08-22 17:36:53 +0300321 glViewport(0, 0, viewWidth, height);
322 if (mMultiviewLayout == GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE)
323 {
324 // Enable the scissor test only for side-by-side framebuffers.
325 glEnable(GL_SCISSOR_TEST);
326 glScissor(0, 0, viewWidth, height);
327 }
Martin Radev61bd9992017-08-11 13:10:55 +0300328 glClearColor(0, 0, 0, 1);
Martin Radev8f276e22017-05-30 12:05:52 +0300329 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev3c25ad02017-08-22 17:36:53 +0300330 }
Martin Radev8f276e22017-05-30 12:05:52 +0300331
Martin Radev72b4e1e2017-08-31 15:42:56 +0300332 void createFBO(int viewWidth, int height, int numViews)
333 {
334 createFBO(viewWidth, height, numViews, numViews, 0);
335 }
336
Martin Radev3c25ad02017-08-22 17:36:53 +0300337 GLColor GetViewColor(int x, int y, int view)
338 {
339 switch (mMultiviewLayout)
340 {
341 case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE:
342 return ReadColor(view * mViewWidth + x, y);
343 case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE:
344 ASSERT(static_cast<size_t>(view) < mReadFramebuffer.size());
345 glBindFramebuffer(GL_READ_FRAMEBUFFER, mReadFramebuffer[view]);
346 return ReadColor(x, y);
347 default:
348 UNREACHABLE();
349 }
350 return GLColor(0, 0, 0, 0);
Martin Radev8f276e22017-05-30 12:05:52 +0300351 }
352
353 GLTexture mColorTexture;
354 GLTexture mDepthTexture;
355 GLFramebuffer mDrawFramebuffer;
Martin Radev3c25ad02017-08-22 17:36:53 +0300356 std::vector<GLFramebuffer> mReadFramebuffer;
357 GLenum mMultiviewLayout;
358 int mViewWidth;
359 int mViewHeight;
360 int mNumViews;
Martin Radev8f276e22017-05-30 12:05:52 +0300361};
362
Martin Radev3c25ad02017-08-22 17:36:53 +0300363class MultiviewRenderTest : public MultiviewRenderTestBase,
364 public ::testing::TestWithParam<MultiviewTestParams>
Martin Radev8f276e22017-05-30 12:05:52 +0300365{
366 protected:
Martin Radev3c25ad02017-08-22 17:36:53 +0300367 MultiviewRenderTest() : MultiviewRenderTestBase(GetParam(), GetParam().mMultiviewLayout) {}
368 void SetUp() override { MultiviewRenderTestBase::RenderTestSetUp(); }
Martin Radevc1d4e552017-08-21 12:01:10 +0300369
370 void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) override
371 {
372 workarounds->selectViewInGeometryShader = GetParam().mForceUseGeometryShaderOnD3D;
373 }
Martin Radev3c25ad02017-08-22 17:36:53 +0300374};
375
376class MultiviewRenderDualViewTest : public MultiviewRenderTest
377{
378 protected:
379 MultiviewRenderDualViewTest() : mProgram(0u) {}
380 ~MultiviewRenderDualViewTest()
Martin Radev8f276e22017-05-30 12:05:52 +0300381 {
382 if (mProgram != 0u)
383 {
384 glDeleteProgram(mProgram);
385 }
386 }
387
388 void SetUp() override
389 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300390 MultiviewRenderTest::SetUp();
Martin Radev8f276e22017-05-30 12:05:52 +0300391
392 if (!requestMultiviewExtension())
393 {
394 return;
395 }
396
397 const std::string vsSource =
398 "#version 300 es\n"
399 "#extension GL_OVR_multiview : require\n"
400 "layout(num_views = 2) in;\n"
401 "in vec4 vPosition;\n"
402 "void main()\n"
403 "{\n"
404 " gl_Position.x = (gl_ViewID_OVR == 0u ? vPosition.x*0.5 + 0.5 : vPosition.x*0.5);\n"
405 " gl_Position.yzw = vPosition.yzw;\n"
406 "}\n";
407
408 const std::string fsSource =
409 "#version 300 es\n"
410 "#extension GL_OVR_multiview : require\n"
411 "precision mediump float;\n"
412 "out vec4 col;\n"
413 "void main()\n"
414 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +0300415 " col = vec4(0,1,0,1);\n"
Martin Radev8f276e22017-05-30 12:05:52 +0300416 "}\n";
417
Martin Radev3c25ad02017-08-22 17:36:53 +0300418 createFBO(2, 1, 2);
Martin Radev61bd9992017-08-11 13:10:55 +0300419 mProgram = CompileProgram(vsSource, fsSource);
420 ASSERT_NE(mProgram, 0u);
Martin Radev8f276e22017-05-30 12:05:52 +0300421 glUseProgram(mProgram);
422 ASSERT_GL_NO_ERROR();
423 }
424
425 void checkOutput()
426 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300427 EXPECT_EQ(GLColor::black, GetViewColor(0, 0, 0));
Martin Radev67a8a012017-09-08 13:03:52 +0300428 EXPECT_EQ(GLColor::green, GetViewColor(1, 0, 0));
429 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev3c25ad02017-08-22 17:36:53 +0300430 EXPECT_EQ(GLColor::black, GetViewColor(1, 0, 1));
Martin Radev8f276e22017-05-30 12:05:52 +0300431 }
432
433 GLuint mProgram;
434};
435
Martin Radev3c25ad02017-08-22 17:36:53 +0300436class MultiviewOcclusionQueryTest : public MultiviewRenderTest
Martin Radev0d671c92017-08-10 16:41:52 +0300437{
438 protected:
Martin Radev3c25ad02017-08-22 17:36:53 +0300439 MultiviewOcclusionQueryTest() {}
Martin Radev0d671c92017-08-10 16:41:52 +0300440
Geoff Lang8c5b31c2017-09-26 18:07:44 -0400441 bool requestOcclusionQueryExtension()
442 {
443 if (extensionRequestable("GL_EXT_occlusion_query_boolean"))
444 {
445 glRequestExtensionANGLE("GL_EXT_occlusion_query_boolean");
446 }
447
448 if (!extensionEnabled("GL_EXT_occlusion_query_boolean"))
449 {
450 std::cout << "Test skipped due to missing GL_EXT_occlusion_query_boolean." << std::endl;
451 return false;
452 }
453 return true;
454 }
455
Martin Radev0d671c92017-08-10 16:41:52 +0300456 GLuint drawAndRetrieveOcclusionQueryResult(GLuint program)
457 {
Geoff Lang8c5b31c2017-09-26 18:07:44 -0400458 GLQueryEXT query;
459 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED, query);
Martin Radev0d671c92017-08-10 16:41:52 +0300460 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
461 glEndQueryEXT(GL_ANY_SAMPLES_PASSED);
462
463 GLuint result = GL_TRUE;
Geoff Lang8c5b31c2017-09-26 18:07:44 -0400464 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT, &result);
Martin Radev0d671c92017-08-10 16:41:52 +0300465 return result;
466 }
467};
468
Martin Radev3c25ad02017-08-22 17:36:53 +0300469class MultiviewProgramGenerationTest : public MultiviewRenderTest
Martin Radev41ac68e2017-06-06 12:16:58 +0300470{
471 protected:
472 MultiviewProgramGenerationTest() {}
473};
474
Martin Radev3c25ad02017-08-22 17:36:53 +0300475class MultiviewRenderPrimitiveTest : public MultiviewRenderTest
Martin Radev61bd9992017-08-11 13:10:55 +0300476{
477 protected:
Martin Radev3c25ad02017-08-22 17:36:53 +0300478 MultiviewRenderPrimitiveTest() {}
Martin Radev61bd9992017-08-11 13:10:55 +0300479
480 void setupGeometry(const std::vector<Vector2> &vertexData)
481 {
Martin Radev61bd9992017-08-11 13:10:55 +0300482 glBindBuffer(GL_ARRAY_BUFFER, mVBO);
483 glBufferData(GL_ARRAY_BUFFER, vertexData.size() * sizeof(Vector2), vertexData.data(),
484 GL_STATIC_DRAW);
485 glEnableVertexAttribArray(0);
Luc Ferronadcf0ae2018-01-24 08:27:37 -0500486 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
Martin Radev61bd9992017-08-11 13:10:55 +0300487 }
488
Martin Radev67a8a012017-09-08 13:03:52 +0300489 void checkGreenChannel(const GLubyte expectedGreenChannelData[])
Martin Radev61bd9992017-08-11 13:10:55 +0300490 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300491 for (int view = 0; view < mNumViews; ++view)
Martin Radev61bd9992017-08-11 13:10:55 +0300492 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300493 for (int w = 0; w < mViewWidth; ++w)
Martin Radev61bd9992017-08-11 13:10:55 +0300494 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300495 for (int h = 0; h < mViewHeight; ++h)
496 {
497 size_t flatIndex =
498 static_cast<size_t>(view * mViewWidth * mViewHeight + mViewWidth * h + w);
Martin Radev67a8a012017-09-08 13:03:52 +0300499 EXPECT_EQ(GLColor(0, expectedGreenChannelData[flatIndex], 0, 255),
Martin Radev3c25ad02017-08-22 17:36:53 +0300500 GetViewColor(w, h, view));
501 }
Martin Radev61bd9992017-08-11 13:10:55 +0300502 }
503 }
504 }
Martin Radev61bd9992017-08-11 13:10:55 +0300505 GLBuffer mVBO;
506};
507
Martin Radev3c25ad02017-08-22 17:36:53 +0300508class MultiviewSideBySideRenderTest : public MultiviewRenderTestBase,
Martin Radevc1d4e552017-08-21 12:01:10 +0300509 public ::testing::TestWithParam<MultiviewImplementationParams>
Martin Radev3c25ad02017-08-22 17:36:53 +0300510{
511 protected:
512 MultiviewSideBySideRenderTest()
513 : MultiviewRenderTestBase(GetParam(), GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE)
514 {
515 }
516 void SetUp() override { MultiviewRenderTestBase::RenderTestSetUp(); }
Martin Radevc1d4e552017-08-21 12:01:10 +0300517 void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) override
518 {
519 workarounds->selectViewInGeometryShader = GetParam().mForceUseGeometryShaderOnD3D;
520 }
Martin Radev3c25ad02017-08-22 17:36:53 +0300521};
522
Martin Radev72b4e1e2017-08-31 15:42:56 +0300523class MultiviewLayeredRenderTest : public MultiviewRenderTestBase,
Martin Radevc1d4e552017-08-21 12:01:10 +0300524 public ::testing::TestWithParam<MultiviewImplementationParams>
Martin Radev72b4e1e2017-08-31 15:42:56 +0300525{
526 protected:
527 MultiviewLayeredRenderTest()
528 : MultiviewRenderTestBase(GetParam(), GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE)
529 {
530 }
531 void SetUp() override { MultiviewRenderTestBase::RenderTestSetUp(); }
Martin Radevc1d4e552017-08-21 12:01:10 +0300532 void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) override
533 {
534 workarounds->selectViewInGeometryShader = GetParam().mForceUseGeometryShaderOnD3D;
535 }
Martin Radev72b4e1e2017-08-31 15:42:56 +0300536};
537
Martin Radev14a26ae2017-07-24 15:56:29 +0300538// The test verifies that glDraw*Indirect:
539// 1) generates an INVALID_OPERATION error if the number of views in the draw framebuffer is greater
540// than 1.
541// 2) does not generate any error if the draw framebuffer has exactly 1 view.
Martin Radev7cf61662017-07-26 17:10:53 +0300542TEST_P(MultiviewDrawValidationTest, IndirectDraw)
Martin Radev14a26ae2017-07-24 15:56:29 +0300543{
544 if (!requestMultiviewExtension())
545 {
546 return;
547 }
548
Martin Radev14a26ae2017-07-24 15:56:29 +0300549 const GLint viewportOffsets[4] = {0, 0, 2, 0};
Martin Radev14a26ae2017-07-24 15:56:29 +0300550
551 const std::string fsSource =
552 "#version 300 es\n"
553 "#extension GL_OVR_multiview : require\n"
554 "precision mediump float;\n"
555 "void main()\n"
556 "{}\n";
557
Martin Radev14a26ae2017-07-24 15:56:29 +0300558 GLBuffer commandBuffer;
559 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, commandBuffer);
560 const GLuint commandData[] = {1u, 1u, 0u, 0u, 0u};
561 glBufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(GLuint) * 5u, &commandData[0], GL_STATIC_DRAW);
562 ASSERT_GL_NO_ERROR();
563
Martin Radev14a26ae2017-07-24 15:56:29 +0300564 // Check for a GL_INVALID_OPERATION error with the framebuffer having 2 views.
565 {
566 const std::string &vsSource =
567 "#version 300 es\n"
568 "#extension GL_OVR_multiview : require\n"
569 "layout(num_views = 2) in;\n"
570 "void main()\n"
571 "{}\n";
572 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
573 glUseProgram(program);
574
Martin Radev7cf61662017-07-26 17:10:53 +0300575 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
576 0, 2, &viewportOffsets[0]);
Martin Radev14a26ae2017-07-24 15:56:29 +0300577
578 glDrawArraysIndirect(GL_TRIANGLES, nullptr);
579 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
580
581 glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr);
582 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
583 }
584
585 // Check that no errors are generated if the number of views is 1.
586 {
587 const std::string &vsSource =
588 "#version 300 es\n"
589 "#extension GL_OVR_multiview : require\n"
590 "layout(num_views = 1) in;\n"
591 "void main()\n"
592 "{}\n";
593 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
594 glUseProgram(program);
595
Martin Radev7cf61662017-07-26 17:10:53 +0300596 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
597 0, 1, &viewportOffsets[0]);
Martin Radev14a26ae2017-07-24 15:56:29 +0300598
599 glDrawArraysIndirect(GL_TRIANGLES, nullptr);
600 EXPECT_GL_NO_ERROR();
601
602 glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr);
603 EXPECT_GL_NO_ERROR();
604 }
605}
606
Martin Radev7cf61662017-07-26 17:10:53 +0300607// The test verifies that glDraw*:
608// 1) generates an INVALID_OPERATION error if the number of views in the active draw framebuffer and
609// program differs.
610// 2) does not generate any error if the number of views is the same.
Martin Radev7cf61662017-07-26 17:10:53 +0300611TEST_P(MultiviewDrawValidationTest, NumViewsMismatch)
612{
613 if (!requestMultiviewExtension())
614 {
615 return;
616 }
617
618 const GLint viewportOffsets[4] = {0, 0, 2, 0};
619
620 const std::string &vsSource =
621 "#version 300 es\n"
622 "#extension GL_OVR_multiview : require\n"
623 "layout(num_views = 2) in;\n"
624 "void main()\n"
625 "{}\n";
626 const std::string &fsSource =
627 "#version 300 es\n"
628 "#extension GL_OVR_multiview : require\n"
629 "precision mediump float;\n"
630 "void main()\n"
631 "{}\n";
632 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
633 glUseProgram(program);
634
635 // Check for a GL_INVALID_OPERATION error with the framebuffer and program having different
636 // number of views.
637 {
638 // The framebuffer has only 1 view.
639 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
640 0, 1, &viewportOffsets[0]);
641
642 glDrawArrays(GL_TRIANGLES, 0, 3);
643 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
644
645 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, nullptr);
646 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
647 }
648
649 // Check that no errors are generated if the number of views in both program and draw
650 // framebuffer matches.
651 {
652 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
653 0, 2, &viewportOffsets[0]);
654
655 glDrawArrays(GL_TRIANGLES, 0, 3);
656 EXPECT_GL_NO_ERROR();
657
658 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, nullptr);
659 EXPECT_GL_NO_ERROR();
660 }
Martin Radevda8e2572017-09-12 17:21:16 +0300661}
Martin Radev7cf61662017-07-26 17:10:53 +0300662
Martin Radevda8e2572017-09-12 17:21:16 +0300663// The test verifies that glDraw* generates an INVALID_OPERATION error if the program does not use
664// the multiview extension, but the active draw framebuffer has more than one view.
665TEST_P(MultiviewDrawValidationTest, NumViewsMismatchForNonMultiviewProgram)
666{
667 if (!requestMultiviewExtension())
Martin Radev7cf61662017-07-26 17:10:53 +0300668 {
Martin Radevda8e2572017-09-12 17:21:16 +0300669 return;
Martin Radev7cf61662017-07-26 17:10:53 +0300670 }
Martin Radevda8e2572017-09-12 17:21:16 +0300671
672 const std::string &vsSourceNoMultiview =
673 "#version 300 es\n"
674 "void main()\n"
675 "{}\n";
676 const std::string &fsSourceNoMultiview =
677 "#version 300 es\n"
678 "precision mediump float;\n"
679 "void main()\n"
680 "{}\n";
681 ANGLE_GL_PROGRAM(programNoMultiview, vsSourceNoMultiview, fsSourceNoMultiview);
682 glUseProgram(programNoMultiview);
683
684 const GLint viewportOffsets[4] = {0, 0, 2, 0};
685 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d, 0, 2,
686 &viewportOffsets[0]);
687
688 glDrawArrays(GL_TRIANGLES, 0, 3);
689 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
690
691 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, nullptr);
692 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Martin Radev7cf61662017-07-26 17:10:53 +0300693}
694
Martin Radev7e69f762017-07-27 14:54:13 +0300695// The test verifies that glDraw*:
696// 1) generates an INVALID_OPERATION error if the number of views in the active draw framebuffer is
697// greater than 1 and there is an active transform feedback object.
698// 2) does not generate any error if the number of views in the draw framebuffer is 1.
699TEST_P(MultiviewDrawValidationTest, ActiveTransformFeedback)
700{
701 if (!requestMultiviewExtension())
702 {
703 return;
704 }
705
706 const GLint viewportOffsets[4] = {0, 0, 2, 0};
707
708 const std::string &vsSource =
Olli Etuaho3755c482017-10-13 15:40:26 +0300709 R"(#version 300 es
710 out float tfVarying;
711 void main()
712 {
713 tfVarying = 1.0;
714 })";
Martin Radev7e69f762017-07-27 14:54:13 +0300715 const std::string &fsSource =
Olli Etuaho3755c482017-10-13 15:40:26 +0300716 R"(#version 300 es
717 precision mediump float;
718 void main()
719 {})";
720 std::vector<std::string> tfVaryings;
721 tfVaryings.push_back(std::string("tfVarying"));
722 ANGLE_GL_PROGRAM_TRANSFORM_FEEDBACK(program, vsSource, fsSource, tfVaryings,
723 GL_SEPARATE_ATTRIBS);
Martin Radev7e69f762017-07-27 14:54:13 +0300724 glUseProgram(program);
725
726 GLBuffer tbo;
727 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, tbo);
728 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(float) * 4u, nullptr, GL_STATIC_DRAW);
729
730 GLTransformFeedback transformFeedback;
731 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedback);
Olli Etuaho3755c482017-10-13 15:40:26 +0300732
733 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo);
734
Martin Radev7e69f762017-07-27 14:54:13 +0300735 glBeginTransformFeedback(GL_TRIANGLES);
736 ASSERT_GL_NO_ERROR();
737
738 // Check that drawArrays generates an error when there is an active transform feedback object
739 // and the number of views in the draw framebuffer is greater than 1.
740 {
741 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
742 0, 2, &viewportOffsets[0]);
743 glDrawArrays(GL_TRIANGLES, 0, 3);
744 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
745 }
746
747 // Check that drawArrays does not generate an error when the number of views in the draw
748 // framebuffer is 1.
749 {
750 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
751 0, 1, &viewportOffsets[0]);
752 glDrawArrays(GL_TRIANGLES, 0, 3);
753 EXPECT_GL_NO_ERROR();
754 }
755
756 glEndTransformFeedback();
757}
758
Martin Radevffe754b2017-07-31 10:38:07 +0300759// The test verifies that glDraw*:
760// 1) generates an INVALID_OPERATION error if the number of views in the active draw framebuffer is
761// greater than 1 and there is an active query for target GL_TIME_ELAPSED_EXT.
762// 2) does not generate any error if the number of views in the draw framebuffer is 1.
763TEST_P(MultiviewDrawValidationTest, ActiveTimeElapsedQuery)
764{
765 if (!requestMultiviewExtension())
766 {
767 return;
768 }
769
770 if (!extensionEnabled("GL_EXT_disjoint_timer_query"))
771 {
772 std::cout << "Test skipped because GL_EXT_disjoint_timer_query is not available."
773 << std::endl;
774 return;
775 }
776
777 const GLint viewportOffsets[4] = {0, 0, 2, 0};
778 const std::string &vsSource =
779 "#version 300 es\n"
780 "void main()\n"
781 "{}\n";
782 const std::string &fsSource =
783 "#version 300 es\n"
784 "precision mediump float;\n"
785 "void main()\n"
786 "{}\n";
787 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
788 glUseProgram(program);
789
790 GLuint query = 0u;
791 glGenQueriesEXT(1, &query);
792 glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query);
793
794 // Check first case.
795 {
796 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
797 0, 2, &viewportOffsets[0]);
798 glDrawArrays(GL_TRIANGLES, 0, 3);
799 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
800 }
801
802 // Check second case.
803 {
804 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
805 0, 1, &viewportOffsets[0]);
806 glDrawArrays(GL_TRIANGLES, 0, 3);
807 EXPECT_GL_NO_ERROR();
808 }
809
810 glEndQueryEXT(GL_TIME_ELAPSED_EXT);
811 glDeleteQueries(1, &query);
812}
813
Martin Radev8f276e22017-05-30 12:05:52 +0300814// The test checks that glDrawArrays can be used to render into two views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300815TEST_P(MultiviewRenderDualViewTest, DrawArrays)
Martin Radev8f276e22017-05-30 12:05:52 +0300816{
817 if (!requestMultiviewExtension())
818 {
819 return;
820 }
821 drawQuad(mProgram, "vPosition", 0.0f, 1.0f, true);
822 ASSERT_GL_NO_ERROR();
823
824 checkOutput();
825}
826
827// The test checks that glDrawElements can be used to render into two views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300828TEST_P(MultiviewRenderDualViewTest, DrawElements)
Martin Radev8f276e22017-05-30 12:05:52 +0300829{
830 if (!requestMultiviewExtension())
831 {
832 return;
833 }
834 drawIndexedQuad(mProgram, "vPosition", 0.0f, 1.0f, true);
835 ASSERT_GL_NO_ERROR();
836
837 checkOutput();
838}
839
840// The test checks that glDrawRangeElements can be used to render into two views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300841TEST_P(MultiviewRenderDualViewTest, DrawRangeElements)
Martin Radev8f276e22017-05-30 12:05:52 +0300842{
843 if (!requestMultiviewExtension())
844 {
845 return;
846 }
847 drawIndexedQuad(mProgram, "vPosition", 0.0f, 1.0f, true, true);
848 ASSERT_GL_NO_ERROR();
849
850 checkOutput();
851}
852
853// The test checks that glDrawArrays can be used to render into four views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300854TEST_P(MultiviewRenderTest, DrawArraysFourViews)
Martin Radev8f276e22017-05-30 12:05:52 +0300855{
856 if (!requestMultiviewExtension())
857 {
858 return;
859 }
860
861 const std::string vsSource =
862 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +0300863 "#extension GL_OVR_multiview : require\n"
Martin Radev8f276e22017-05-30 12:05:52 +0300864 "layout(num_views = 4) in;\n"
865 "in vec4 vPosition;\n"
866 "void main()\n"
867 "{\n"
868 " if (gl_ViewID_OVR == 0u) {\n"
869 " gl_Position.x = vPosition.x*0.25 - 0.75;\n"
870 " } else if (gl_ViewID_OVR == 1u) {\n"
871 " gl_Position.x = vPosition.x*0.25 - 0.25;\n"
872 " } else if (gl_ViewID_OVR == 2u) {\n"
873 " gl_Position.x = vPosition.x*0.25 + 0.25;\n"
874 " } else {\n"
875 " gl_Position.x = vPosition.x*0.25 + 0.75;\n"
876 " }"
877 " gl_Position.yzw = vPosition.yzw;\n"
878 "}\n";
879
880 const std::string fsSource =
881 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +0300882 "#extension GL_OVR_multiview : require\n"
Martin Radev8f276e22017-05-30 12:05:52 +0300883 "precision mediump float;\n"
884 "out vec4 col;\n"
885 "void main()\n"
886 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +0300887 " col = vec4(0,1,0,1);\n"
Martin Radev8f276e22017-05-30 12:05:52 +0300888 "}\n";
889
Martin Radev3c25ad02017-08-22 17:36:53 +0300890 createFBO(4, 1, 4);
Martin Radev8f276e22017-05-30 12:05:52 +0300891 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev8f276e22017-05-30 12:05:52 +0300892
893 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
894 ASSERT_GL_NO_ERROR();
895
896 for (int i = 0; i < 4; ++i)
897 {
898 for (int j = 0; j < 4; ++j)
899 {
Martin Radev8f276e22017-05-30 12:05:52 +0300900 if (i == j)
901 {
Martin Radev67a8a012017-09-08 13:03:52 +0300902 EXPECT_EQ(GLColor::green, GetViewColor(j, 0, i));
Martin Radev8f276e22017-05-30 12:05:52 +0300903 }
904 else
905 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300906 EXPECT_EQ(GLColor::black, GetViewColor(j, 0, i));
Martin Radev8f276e22017-05-30 12:05:52 +0300907 }
908 }
909 }
910 EXPECT_GL_NO_ERROR();
911}
912
913// The test checks that glDrawArraysInstanced can be used to render into two views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300914TEST_P(MultiviewRenderTest, DrawArraysInstanced)
Martin Radev8f276e22017-05-30 12:05:52 +0300915{
916 if (!requestMultiviewExtension())
917 {
918 return;
919 }
920
921 const std::string vsSource =
922 "#version 300 es\n"
923 "#extension GL_OVR_multiview : require\n"
924 "layout(num_views = 2) in;\n"
925 "in vec4 vPosition;\n"
926 "void main()\n"
927 "{\n"
928 " vec4 p = vPosition;\n"
929 " if (gl_InstanceID == 1){\n"
930 " p.y = .5*p.y + .5;\n"
931 " } else {\n"
932 " p.y = p.y*.5;\n"
933 " }\n"
934 " gl_Position.x = (gl_ViewID_OVR == 0u ? p.x*0.5 + 0.5 : p.x*0.5);\n"
935 " gl_Position.yzw = p.yzw;\n"
936 "}\n";
937
938 const std::string fsSource =
939 "#version 300 es\n"
940 "#extension GL_OVR_multiview : require\n"
941 "precision mediump float;\n"
942 "out vec4 col;\n"
943 "void main()\n"
944 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +0300945 " col = vec4(0,1,0,1);\n"
Martin Radev8f276e22017-05-30 12:05:52 +0300946 "}\n";
947
Martin Radev3c25ad02017-08-22 17:36:53 +0300948 const int kViewWidth = 2;
949 const int kViewHeight = 2;
950 const int kNumViews = 2;
951 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev8f276e22017-05-30 12:05:52 +0300952 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev8f276e22017-05-30 12:05:52 +0300953
Martin Radev67a8a012017-09-08 13:03:52 +0300954 drawQuadInstanced(program, "vPosition", 0.0f, 1.0f, true, 2u);
Martin Radev8f276e22017-05-30 12:05:52 +0300955 ASSERT_GL_NO_ERROR();
956
Martin Radev67a8a012017-09-08 13:03:52 +0300957 const GLubyte expectedGreenChannel[kNumViews][kViewHeight][kViewWidth] = {{{0, 255}, {0, 255}},
958 {{255, 0}, {255, 0}}};
Martin Radev3c25ad02017-08-22 17:36:53 +0300959
960 for (int view = 0; view < 2; ++view)
Martin Radev8f276e22017-05-30 12:05:52 +0300961 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300962 for (int y = 0; y < 2; ++y)
Martin Radev8f276e22017-05-30 12:05:52 +0300963 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300964 for (int x = 0; x < 2; ++x)
965 {
Martin Radev67a8a012017-09-08 13:03:52 +0300966 EXPECT_EQ(GLColor(0, expectedGreenChannel[view][y][x], 0, 255),
Martin Radev3c25ad02017-08-22 17:36:53 +0300967 GetViewColor(x, y, view));
968 }
Martin Radev8f276e22017-05-30 12:05:52 +0300969 }
970 }
971}
972
Martin Radev553590a2017-07-31 16:40:39 +0300973// The test verifies that the attribute divisor is correctly adjusted when drawing with a multi-view
974// program. The test draws 4 instances of a quad each of which covers a single pixel. The x and y
975// offset of each quad are passed as separate attributes which are indexed based on the
976// corresponding attribute divisors. A divisor of 1 is used for the y offset to have all quads
977// drawn vertically next to each other. A divisor of 3 is used for the x offset to have the last
978// quad offsetted by one pixel to the right. Note that the number of views is divisible by 1, but
979// not by 3.
Martin Radev3c25ad02017-08-22 17:36:53 +0300980TEST_P(MultiviewRenderTest, AttribDivisor)
Martin Radev553590a2017-07-31 16:40:39 +0300981{
982 if (!requestMultiviewExtension())
983 {
984 return;
985 }
986
987 const std::string &vsSource =
988 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +0300989 "#extension GL_OVR_multiview : require\n"
Martin Radev553590a2017-07-31 16:40:39 +0300990 "layout(num_views = 2) in;\n"
991 "in vec3 vPosition;\n"
992 "in float offsetX;\n"
993 "in float offsetY;\n"
994 "void main()\n"
995 "{\n"
996 " vec4 p = vec4(vPosition, 1.);\n"
Martin Radev0abb7a22017-08-28 15:34:45 +0300997 " p.xy = p.xy * 0.25 - vec2(0.75) + vec2(offsetX, offsetY);\n"
Martin Radev553590a2017-07-31 16:40:39 +0300998 " gl_Position.x = (gl_ViewID_OVR == 0u ? p.x : p.x + 1.0);\n"
999 " gl_Position.yzw = p.yzw;\n"
1000 "}\n";
1001
1002 const std::string &fsSource =
1003 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001004 "#extension GL_OVR_multiview : require\n"
Martin Radev553590a2017-07-31 16:40:39 +03001005 "precision mediump float;\n"
1006 "out vec4 col;\n"
1007 "void main()\n"
1008 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03001009 " col = vec4(0,1,0,1);\n"
Martin Radev553590a2017-07-31 16:40:39 +03001010 "}\n";
Martin Radev3c25ad02017-08-22 17:36:53 +03001011
1012 const int kViewWidth = 4;
1013 const int kViewHeight = 4;
1014 const int kNumViews = 2;
1015 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev553590a2017-07-31 16:40:39 +03001016 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev553590a2017-07-31 16:40:39 +03001017
1018 GLBuffer xOffsetVBO;
1019 glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
1020 const GLfloat xOffsetData[4] = {0.0f, 0.5f, 1.0f, 1.0f};
1021 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4, xOffsetData, GL_STATIC_DRAW);
1022 GLint xOffsetLoc = glGetAttribLocation(program, "offsetX");
1023 glVertexAttribPointer(xOffsetLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
1024 glVertexAttribDivisor(xOffsetLoc, 3);
1025 glEnableVertexAttribArray(xOffsetLoc);
1026
1027 GLBuffer yOffsetVBO;
1028 glBindBuffer(GL_ARRAY_BUFFER, yOffsetVBO);
1029 const GLfloat yOffsetData[4] = {0.0f, 0.5f, 1.0f, 1.5f};
1030 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4, yOffsetData, GL_STATIC_DRAW);
1031 GLint yOffsetLoc = glGetAttribLocation(program, "offsetY");
1032 glVertexAttribDivisor(yOffsetLoc, 1);
1033 glVertexAttribPointer(yOffsetLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
1034 glEnableVertexAttribArray(yOffsetLoc);
1035
Martin Radev67a8a012017-09-08 13:03:52 +03001036 drawQuadInstanced(program, "vPosition", 0.0f, 1.0f, true, 4u);
Martin Radev553590a2017-07-31 16:40:39 +03001037 ASSERT_GL_NO_ERROR();
1038
Martin Radev67a8a012017-09-08 13:03:52 +03001039 const GLubyte expectedGreenChannel[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001040 {{255, 0, 0, 0}, {255, 0, 0, 0}, {255, 0, 0, 0}, {0, 255, 0, 0}},
1041 {{0, 0, 255, 0}, {0, 0, 255, 0}, {0, 0, 255, 0}, {0, 0, 0, 255}}};
1042 for (int view = 0; view < 2; ++view)
Martin Radev553590a2017-07-31 16:40:39 +03001043 {
Martin Radev3c25ad02017-08-22 17:36:53 +03001044 for (int row = 0; row < 4; ++row)
Martin Radev553590a2017-07-31 16:40:39 +03001045 {
Martin Radev3c25ad02017-08-22 17:36:53 +03001046 for (int col = 0; col < 4; ++col)
1047 {
Martin Radev67a8a012017-09-08 13:03:52 +03001048 EXPECT_EQ(GLColor(0, expectedGreenChannel[view][row][col], 0, 255),
Martin Radev3c25ad02017-08-22 17:36:53 +03001049 GetViewColor(col, row, view));
1050 }
Martin Radev553590a2017-07-31 16:40:39 +03001051 }
1052 }
1053}
1054
1055// Test that different sequences of vertexAttribDivisor, useProgram and bindVertexArray in a
1056// multi-view context propagate the correct divisor to the driver.
Martin Radev3c25ad02017-08-22 17:36:53 +03001057TEST_P(MultiviewRenderTest, DivisorOrderOfOperation)
Martin Radev553590a2017-07-31 16:40:39 +03001058{
1059 if (!requestMultiviewExtension())
1060 {
1061 return;
1062 }
1063
Martin Radev3c25ad02017-08-22 17:36:53 +03001064 createFBO(1, 1, 2);
Martin Radev553590a2017-07-31 16:40:39 +03001065
1066 // Create multiview program.
1067 const std::string &vs =
1068 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001069 "#extension GL_OVR_multiview : require\n"
Martin Radev553590a2017-07-31 16:40:39 +03001070 "layout(num_views = 2) in;\n"
1071 "layout(location = 0) in vec2 vPosition;\n"
1072 "layout(location = 1) in float offsetX;\n"
1073 "void main()\n"
1074 "{\n"
1075 " vec4 p = vec4(vPosition, 0.0, 1.0);\n"
1076 " p.x += offsetX;\n"
1077 " gl_Position = p;\n"
1078 "}\n";
1079
1080 const std::string &fs =
1081 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001082 "#extension GL_OVR_multiview : require\n"
Martin Radev553590a2017-07-31 16:40:39 +03001083 "precision mediump float;\n"
1084 "out vec4 col;\n"
1085 "void main()\n"
1086 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03001087 " col = vec4(0,1,0,1);\n"
Martin Radev553590a2017-07-31 16:40:39 +03001088 "}\n";
1089
1090 ANGLE_GL_PROGRAM(program, vs, fs);
1091
1092 const std::string &dummyVS =
1093 "#version 300 es\n"
1094 "layout(location = 0) in vec2 vPosition;\n"
1095 "layout(location = 1) in float offsetX;\n"
1096 "void main()\n"
1097 "{\n"
1098 " gl_Position = vec4(vPosition, 0.0, 1.0);\n"
1099 "}\n";
1100
1101 const std::string &dummyFS =
1102 "#version 300 es\n"
1103 "precision mediump float;\n"
1104 "out vec4 col;\n"
1105 "void main()\n"
1106 "{\n"
Martin Radev61bd9992017-08-11 13:10:55 +03001107 " col = vec4(0,0,0,1);\n"
Martin Radev553590a2017-07-31 16:40:39 +03001108 "}\n";
1109
1110 ANGLE_GL_PROGRAM(dummyProgram, dummyVS, dummyFS);
1111
1112 GLBuffer xOffsetVBO;
1113 glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
1114 const GLfloat xOffsetData[12] = {0.0f, 4.0f, 4.0f, 4.0f, 4.0f, 4.0f,
1115 4.0f, 4.0f, 4.0f, 4.0f, 4.0f, 4.0f};
1116 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 12, xOffsetData, GL_STATIC_DRAW);
1117
1118 GLBuffer vertexVBO;
1119 glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
1120 Vector2 kQuadVertices[6] = {Vector2(-1.f, -1.f), Vector2(1.f, -1.f), Vector2(1.f, 1.f),
1121 Vector2(-1.f, -1.f), Vector2(1.f, 1.f), Vector2(-1.f, 1.f)};
1122 glBufferData(GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW);
1123
1124 GLVertexArray vao[2];
1125 for (size_t i = 0u; i < 2u; ++i)
1126 {
1127 glBindVertexArray(vao[i]);
1128
1129 glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
1130 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
1131 glEnableVertexAttribArray(0);
1132
1133 glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
1134 glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, 0);
1135 glEnableVertexAttribArray(1);
1136 }
1137 ASSERT_GL_NO_ERROR();
1138
1139 glViewport(0, 0, 1, 1);
1140 glScissor(0, 0, 1, 1);
Martin Radeveef80e42017-08-11 14:44:57 +03001141 glEnable(GL_SCISSOR_TEST);
Martin Radev61bd9992017-08-11 13:10:55 +03001142 glClearColor(0, 0, 0, 1);
Martin Radev553590a2017-07-31 16:40:39 +03001143
1144 // Clear the buffers, propagate divisor to the driver, bind the vao and keep it active.
1145 // It is necessary to call draw, so that the divisor is propagated and to guarantee that dirty
1146 // bits are cleared.
1147 glUseProgram(dummyProgram);
Martin Radevda8e2572017-09-12 17:21:16 +03001148 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1149 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001150 glBindVertexArray(vao[0]);
1151 glVertexAttribDivisor(1, 0);
1152 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
1153 glUseProgram(0);
Martin Radev553590a2017-07-31 16:40:39 +03001154 ASSERT_GL_NO_ERROR();
1155
1156 // Check that vertexAttribDivisor uses the number of views to update the divisor.
Martin Radevda8e2572017-09-12 17:21:16 +03001157 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
1158 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001159 glUseProgram(program);
1160 glVertexAttribDivisor(1, 1);
1161 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
Martin Radev67a8a012017-09-08 13:03:52 +03001162 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 0));
1163 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev553590a2017-07-31 16:40:39 +03001164
1165 // Clear the buffers and propagate divisor to the driver.
1166 // We keep the vao active and propagate the divisor to guarantee that there are no unresolved
1167 // dirty bits when useProgram is called.
1168 glUseProgram(dummyProgram);
Martin Radevda8e2572017-09-12 17:21:16 +03001169 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1170 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001171 glVertexAttribDivisor(1, 1);
1172 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
1173 glUseProgram(0);
Martin Radev553590a2017-07-31 16:40:39 +03001174 ASSERT_GL_NO_ERROR();
1175
1176 // Check that useProgram uses the number of views to update the divisor.
Martin Radevda8e2572017-09-12 17:21:16 +03001177 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
1178 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001179 glUseProgram(program);
1180 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
Martin Radev67a8a012017-09-08 13:03:52 +03001181 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 0));
1182 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev553590a2017-07-31 16:40:39 +03001183
1184 // We go through similar steps as before.
1185 glUseProgram(dummyProgram);
Martin Radevda8e2572017-09-12 17:21:16 +03001186 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1187 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001188 glVertexAttribDivisor(1, 1);
1189 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
1190 glUseProgram(0);
Martin Radev553590a2017-07-31 16:40:39 +03001191 ASSERT_GL_NO_ERROR();
1192
1193 // Check that bindVertexArray uses the number of views to update the divisor.
1194 {
1195 // Call useProgram with vao[1] being active to guarantee that useProgram will adjust the
1196 // divisor for vao[1] only.
Martin Radevda8e2572017-09-12 17:21:16 +03001197 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
1198 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001199 glBindVertexArray(vao[1]);
1200 glUseProgram(program);
1201 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
Martin Radev553590a2017-07-31 16:40:39 +03001202 glBindVertexArray(0);
1203 ASSERT_GL_NO_ERROR();
1204 }
1205 // Bind vao[0] after useProgram is called to ensure that bindVertexArray is the call which
1206 // adjusts the divisor.
Martin Radevda8e2572017-09-12 17:21:16 +03001207 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001208 glBindVertexArray(vao[0]);
1209 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
Martin Radev67a8a012017-09-08 13:03:52 +03001210 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 0));
1211 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev553590a2017-07-31 16:40:39 +03001212}
1213
Martin Radev0d671c92017-08-10 16:41:52 +03001214// Test that no fragments pass the occlusion query for a multi-view vertex shader which always
1215// transforms geometry to be outside of the clip region.
Martin Radev3c25ad02017-08-22 17:36:53 +03001216TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryNothingVisible)
Martin Radev0d671c92017-08-10 16:41:52 +03001217{
Geoff Lang8c5b31c2017-09-26 18:07:44 -04001218 ANGLE_SKIP_TEST_IF(!requestMultiviewExtension());
1219 ANGLE_SKIP_TEST_IF(!requestOcclusionQueryExtension());
Martin Radev0d671c92017-08-10 16:41:52 +03001220
1221 const std::string vsSource =
1222 "#version 300 es\n"
1223 "#extension GL_OVR_multiview : require\n"
1224 "layout(num_views = 2) in;\n"
1225 "in vec3 vPosition;\n"
1226 "void main()\n"
1227 "{\n"
1228 " gl_Position.x = 2.0;\n"
1229 " gl_Position.yzw = vec3(vPosition.yz, 1.);\n"
1230 "}\n";
1231
1232 const std::string fsSource =
1233 "#version 300 es\n"
1234 "#extension GL_OVR_multiview : require\n"
1235 "precision mediump float;\n"
1236 "out vec4 col;\n"
1237 "void main()\n"
1238 "{\n"
1239 " col = vec4(1,0,0,0);\n"
1240 "}\n";
1241 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev3c25ad02017-08-22 17:36:53 +03001242 createFBO(1, 1, 2);
Martin Radev0d671c92017-08-10 16:41:52 +03001243
1244 GLuint result = drawAndRetrieveOcclusionQueryResult(program);
1245 ASSERT_GL_NO_ERROR();
1246 EXPECT_GL_FALSE(result);
1247}
1248
1249// Test that there are fragments passing the occlusion query if only view 0 can produce
1250// output.
Martin Radev3c25ad02017-08-22 17:36:53 +03001251TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyLeftVisible)
Martin Radev0d671c92017-08-10 16:41:52 +03001252{
Geoff Lang8c5b31c2017-09-26 18:07:44 -04001253 ANGLE_SKIP_TEST_IF(!requestMultiviewExtension());
1254 ANGLE_SKIP_TEST_IF(!requestOcclusionQueryExtension());
Martin Radev0d671c92017-08-10 16:41:52 +03001255
1256 const std::string vsSource =
1257 "#version 300 es\n"
1258 "#extension GL_OVR_multiview : require\n"
1259 "layout(num_views = 2) in;\n"
1260 "in vec3 vPosition;\n"
1261 "void main()\n"
1262 "{\n"
1263 " gl_Position.x = gl_ViewID_OVR == 0u ? vPosition.x : 2.0;\n"
1264 " gl_Position.yzw = vec3(vPosition.yz, 1.);\n"
1265 "}\n";
1266
1267 const std::string fsSource =
1268 "#version 300 es\n"
1269 "#extension GL_OVR_multiview : require\n"
1270 "precision mediump float;\n"
1271 "out vec4 col;\n"
1272 "void main()\n"
1273 "{\n"
1274 " col = vec4(1,0,0,0);\n"
1275 "}\n";
1276 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev3c25ad02017-08-22 17:36:53 +03001277 createFBO(1, 1, 2);
Martin Radev0d671c92017-08-10 16:41:52 +03001278
1279 GLuint result = drawAndRetrieveOcclusionQueryResult(program);
1280 ASSERT_GL_NO_ERROR();
1281 EXPECT_GL_TRUE(result);
1282}
1283
1284// Test that there are fragments passing the occlusion query if only view 1 can produce
1285// output.
Martin Radev3c25ad02017-08-22 17:36:53 +03001286TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyRightVisible)
Martin Radev0d671c92017-08-10 16:41:52 +03001287{
Geoff Lang8c5b31c2017-09-26 18:07:44 -04001288 ANGLE_SKIP_TEST_IF(!requestMultiviewExtension());
1289 ANGLE_SKIP_TEST_IF(!requestOcclusionQueryExtension());
Martin Radev0d671c92017-08-10 16:41:52 +03001290
1291 const std::string vsSource =
1292 "#version 300 es\n"
1293 "#extension GL_OVR_multiview : require\n"
1294 "layout(num_views = 2) in;\n"
1295 "in vec3 vPosition;\n"
1296 "void main()\n"
1297 "{\n"
1298 " gl_Position.x = gl_ViewID_OVR == 1u ? vPosition.x : 2.0;\n"
1299 " gl_Position.yzw = vec3(vPosition.yz, 1.);\n"
1300 "}\n";
1301
1302 const std::string fsSource =
1303 "#version 300 es\n"
1304 "#extension GL_OVR_multiview : require\n"
1305 "precision mediump float;\n"
1306 "out vec4 col;\n"
1307 "void main()\n"
1308 "{\n"
1309 " col = vec4(1,0,0,0);\n"
1310 "}\n";
1311 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev3c25ad02017-08-22 17:36:53 +03001312 createFBO(1, 1, 2);
Martin Radev0d671c92017-08-10 16:41:52 +03001313
1314 GLuint result = drawAndRetrieveOcclusionQueryResult(program);
1315 ASSERT_GL_NO_ERROR();
1316 EXPECT_GL_TRUE(result);
1317}
1318
Martin Radev41ac68e2017-06-06 12:16:58 +03001319// Test that a simple multi-view program which doesn't use gl_ViewID_OVR in neither VS nor FS
1320// compiles and links without an error.
1321TEST_P(MultiviewProgramGenerationTest, SimpleProgram)
1322{
1323 if (!requestMultiviewExtension())
1324 {
1325 return;
1326 }
1327
1328 const std::string vsSource =
1329 "#version 300 es\n"
1330 "#extension GL_OVR_multiview : require\n"
1331 "layout(num_views = 2) in;\n"
1332 "void main()\n"
1333 "{\n"
1334 "}\n";
1335
1336 const std::string fsSource =
1337 "#version 300 es\n"
1338 "#extension GL_OVR_multiview : require\n"
1339 "precision mediump float;\n"
1340 "void main()\n"
1341 "{\n"
1342 "}\n";
1343
1344 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1345 glUseProgram(program);
1346
1347 EXPECT_GL_NO_ERROR();
1348}
1349
1350// Test that a simple multi-view program which uses gl_ViewID_OVR only in VS compiles and links
1351// without an error.
1352TEST_P(MultiviewProgramGenerationTest, UseViewIDInVertexShader)
1353{
1354 if (!requestMultiviewExtension())
1355 {
1356 return;
1357 }
1358
1359 const std::string vsSource =
1360 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001361 "#extension GL_OVR_multiview : require\n"
Martin Radev41ac68e2017-06-06 12:16:58 +03001362 "layout(num_views = 2) in;\n"
1363 "void main()\n"
1364 "{\n"
1365 " if (gl_ViewID_OVR == 0u) {\n"
1366 " gl_Position = vec4(1,0,0,1);\n"
1367 " } else {\n"
1368 " gl_Position = vec4(-1,0,0,1);\n"
1369 " }\n"
1370 "}\n";
1371
1372 const std::string fsSource =
1373 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001374 "#extension GL_OVR_multiview : require\n"
Martin Radev41ac68e2017-06-06 12:16:58 +03001375 "precision mediump float;\n"
1376 "void main()\n"
1377 "{\n"
1378 "}\n";
1379
1380 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1381 glUseProgram(program);
1382
1383 EXPECT_GL_NO_ERROR();
1384}
1385
1386// Test that a simple multi-view program which uses gl_ViewID_OVR only in FS compiles and links
1387// without an error.
1388TEST_P(MultiviewProgramGenerationTest, UseViewIDInFragmentShader)
1389{
1390 if (!requestMultiviewExtension())
1391 {
1392 return;
1393 }
1394
1395 const std::string vsSource =
1396 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001397 "#extension GL_OVR_multiview : require\n"
Martin Radev41ac68e2017-06-06 12:16:58 +03001398 "layout(num_views = 2) in;\n"
1399 "void main()\n"
1400 "{\n"
1401 "}\n";
1402
1403 const std::string fsSource =
1404 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001405 "#extension GL_OVR_multiview : require\n"
Martin Radev41ac68e2017-06-06 12:16:58 +03001406 "precision mediump float;\n"
1407 "out vec4 col;\n"
1408 "void main()\n"
1409 "{\n"
1410 " if (gl_ViewID_OVR == 0u) {\n"
1411 " col = vec4(1,0,0,1);\n"
1412 " } else {\n"
1413 " col = vec4(-1,0,0,1);\n"
1414 " }\n"
1415 "}\n";
1416
1417 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1418 glUseProgram(program);
1419
1420 EXPECT_GL_NO_ERROR();
1421}
1422
Martin Radev61bd9992017-08-11 13:10:55 +03001423// The test checks that GL_POINTS is correctly rendered.
Martin Radev3c25ad02017-08-22 17:36:53 +03001424TEST_P(MultiviewRenderPrimitiveTest, Points)
Martin Radev61bd9992017-08-11 13:10:55 +03001425{
1426 if (!requestMultiviewExtension())
1427 {
1428 return;
1429 }
1430
Geoff Lang25858162017-11-06 11:25:58 -05001431 // Test failing on P400 graphics card (anglebug.com/2228)
1432 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11() && IsNVIDIA());
1433
Martin Radev61bd9992017-08-11 13:10:55 +03001434 const std::string vsSource =
1435 "#version 300 es\n"
1436 "#extension GL_OVR_multiview : require\n"
1437 "layout(num_views = 2) in;\n"
1438 "layout(location=0) in vec2 vPosition;\n"
1439 "void main()\n"
1440 "{\n"
1441 " gl_PointSize = 1.0;\n"
1442 " gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n"
1443 "}\n";
1444
1445 const std::string fsSource =
1446 "#version 300 es\n"
1447 "#extension GL_OVR_multiview : require\n"
1448 "precision mediump float;\n"
1449 "out vec4 col;\n"
1450 "void main()\n"
1451 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03001452 " col = vec4(0,1,0,1);\n"
Martin Radev61bd9992017-08-11 13:10:55 +03001453 "}\n";
1454 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1455 glUseProgram(program);
1456
Martin Radev3c25ad02017-08-22 17:36:53 +03001457 const int kViewWidth = 4;
1458 const int kViewHeight = 2;
1459 const int kNumViews = 2;
1460 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001461
1462 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(3, 1)};
1463 std::vector<Vector2> vertexDataInClipSpace =
1464 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 2);
1465 setupGeometry(vertexDataInClipSpace);
1466
1467 glDrawArrays(GL_POINTS, 0, 2);
1468
Martin Radev67a8a012017-09-08 13:03:52 +03001469 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001470 {{255, 0, 0, 0}, {0, 0, 0, 255}}, {{255, 0, 0, 0}, {0, 0, 0, 255}}};
Martin Radev67a8a012017-09-08 13:03:52 +03001471 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001472}
1473
1474// The test checks that GL_LINES is correctly rendered.
1475// The behavior of this test is not guaranteed by the spec:
1476// OpenGL ES 3.0.5 (November 3, 2016), Section 3.5.1 Basic Line Segment Rasterization:
1477// "The coordinates of a fragment produced by the algorithm may not deviate by more than one unit in
1478// either x or y window coordinates from a corresponding fragment produced by the diamond-exit
1479// rule."
Martin Radev3c25ad02017-08-22 17:36:53 +03001480TEST_P(MultiviewRenderPrimitiveTest, Lines)
Martin Radev61bd9992017-08-11 13:10:55 +03001481{
1482 if (!requestMultiviewExtension())
1483 {
1484 return;
1485 }
1486
Martin Radevced5c862017-08-17 16:05:29 +03001487 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001488 ASSERT_NE(program, 0u);
1489 glUseProgram(program);
1490 ASSERT_GL_NO_ERROR();
1491
Martin Radev3c25ad02017-08-22 17:36:53 +03001492 const int kViewWidth = 4;
1493 const int kViewHeight = 2;
1494 const int kNumViews = 2;
1495 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001496
1497 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(4, 0)};
1498 std::vector<Vector2> vertexDataInClipSpace =
1499 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 2);
1500 setupGeometry(vertexDataInClipSpace);
1501
1502 glDrawArrays(GL_LINES, 0, 2);
1503
Martin Radev67a8a012017-09-08 13:03:52 +03001504 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001505 {{255, 255, 255, 255}, {0, 0, 0, 0}}, {{255, 255, 255, 255}, {0, 0, 0, 0}}};
Martin Radev67a8a012017-09-08 13:03:52 +03001506 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001507
1508 glDeleteProgram(program);
1509}
1510
1511// The test checks that GL_LINE_STRIP is correctly rendered.
1512// The behavior of this test is not guaranteed by the spec:
1513// OpenGL ES 3.0.5 (November 3, 2016), Section 3.5.1 Basic Line Segment Rasterization:
1514// "The coordinates of a fragment produced by the algorithm may not deviate by more than one unit in
1515// either x or y window coordinates from a corresponding fragment produced by the diamond-exit
1516// rule."
Martin Radev3c25ad02017-08-22 17:36:53 +03001517TEST_P(MultiviewRenderPrimitiveTest, LineStrip)
Martin Radev61bd9992017-08-11 13:10:55 +03001518{
1519 if (!requestMultiviewExtension())
1520 {
1521 return;
1522 }
1523
Martin Radevced5c862017-08-17 16:05:29 +03001524 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001525 ASSERT_NE(program, 0u);
1526 glUseProgram(program);
1527 ASSERT_GL_NO_ERROR();
1528
Martin Radev3c25ad02017-08-22 17:36:53 +03001529 const int kViewWidth = 4;
1530 const int kViewHeight = 2;
1531 const int kNumViews = 2;
1532 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001533
1534 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(3, 0), Vector2I(3, 2)};
1535 std::vector<Vector2> vertexDataInClipSpace =
1536 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 2);
1537 setupGeometry(vertexDataInClipSpace);
1538
1539 glDrawArrays(GL_LINE_STRIP, 0, 3);
1540
Martin Radev67a8a012017-09-08 13:03:52 +03001541 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001542 {{255, 255, 255, 255}, {0, 0, 0, 255}}, {{255, 255, 255, 255}, {0, 0, 0, 255}}};
Martin Radev67a8a012017-09-08 13:03:52 +03001543 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001544
1545 glDeleteProgram(program);
1546}
1547
1548// The test checks that GL_LINE_LOOP is correctly rendered.
1549// The behavior of this test is not guaranteed by the spec:
1550// OpenGL ES 3.0.5 (November 3, 2016), Section 3.5.1 Basic Line Segment Rasterization:
1551// "The coordinates of a fragment produced by the algorithm may not deviate by more than one unit in
1552// either x or y window coordinates from a corresponding fragment produced by the diamond-exit
1553// rule."
Martin Radev3c25ad02017-08-22 17:36:53 +03001554TEST_P(MultiviewRenderPrimitiveTest, LineLoop)
Martin Radev61bd9992017-08-11 13:10:55 +03001555{
1556 if (!requestMultiviewExtension())
1557 {
1558 return;
1559 }
1560
Martin Radevced5c862017-08-17 16:05:29 +03001561 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001562 ASSERT_NE(program, 0u);
1563 glUseProgram(program);
1564 ASSERT_GL_NO_ERROR();
1565
Martin Radev3c25ad02017-08-22 17:36:53 +03001566 const int kViewWidth = 4;
1567 const int kViewHeight = 4;
1568 const int kNumViews = 2;
1569 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001570
1571 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(3, 0), Vector2I(3, 3),
1572 Vector2I(0, 3)};
1573 std::vector<Vector2> vertexDataInClipSpace =
1574 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 4);
1575 setupGeometry(vertexDataInClipSpace);
1576
1577 glDrawArrays(GL_LINE_LOOP, 0, 4);
1578
Martin Radev67a8a012017-09-08 13:03:52 +03001579 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001580 {{255, 255, 255, 255}, {255, 0, 0, 255}, {255, 0, 0, 255}, {255, 255, 255, 255}},
1581 {{255, 255, 255, 255}, {255, 0, 0, 255}, {255, 0, 0, 255}, {255, 255, 255, 255}}};
Martin Radev67a8a012017-09-08 13:03:52 +03001582 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001583
1584 glDeleteProgram(program);
1585}
1586
1587// The test checks that GL_TRIANGLE_STRIP is correctly rendered.
Martin Radev3c25ad02017-08-22 17:36:53 +03001588TEST_P(MultiviewRenderPrimitiveTest, TriangleStrip)
Martin Radev61bd9992017-08-11 13:10:55 +03001589{
1590 if (!requestMultiviewExtension())
1591 {
1592 return;
1593 }
1594
Martin Radevced5c862017-08-17 16:05:29 +03001595 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001596 ASSERT_NE(program, 0u);
1597 glUseProgram(program);
1598 ASSERT_GL_NO_ERROR();
1599
1600 std::vector<Vector2> vertexDataInClipSpace = {Vector2(1.0f, 0.0f), Vector2(0.0f, 0.0f),
1601 Vector2(1.0f, 1.0f), Vector2(0.0f, 1.0f)};
1602 setupGeometry(vertexDataInClipSpace);
1603
Martin Radev3c25ad02017-08-22 17:36:53 +03001604 const int kViewWidth = 2;
1605 const int kViewHeight = 2;
1606 const int kNumViews = 2;
1607 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001608
1609 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1610
Martin Radev67a8a012017-09-08 13:03:52 +03001611 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
1612 {{0, 0}, {0, 255}}, {{0, 0}, {0, 255}}};
1613 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001614
1615 glDeleteProgram(program);
1616}
1617
1618// The test checks that GL_TRIANGLE_FAN is correctly rendered.
Martin Radev3c25ad02017-08-22 17:36:53 +03001619TEST_P(MultiviewRenderPrimitiveTest, TriangleFan)
Martin Radev61bd9992017-08-11 13:10:55 +03001620{
1621 if (!requestMultiviewExtension())
1622 {
1623 return;
1624 }
1625
Martin Radevced5c862017-08-17 16:05:29 +03001626 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001627 ASSERT_NE(program, 0u);
1628 glUseProgram(program);
1629 ASSERT_GL_NO_ERROR();
1630
1631 std::vector<Vector2> vertexDataInClipSpace = {Vector2(0.0f, 0.0f), Vector2(0.0f, 1.0f),
1632 Vector2(1.0f, 1.0f), Vector2(1.0f, 0.0f)};
1633 setupGeometry(vertexDataInClipSpace);
1634
Martin Radev3c25ad02017-08-22 17:36:53 +03001635 const int kViewWidth = 2;
1636 const int kViewHeight = 2;
1637 const int kNumViews = 2;
1638 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001639
1640 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1641
Martin Radev67a8a012017-09-08 13:03:52 +03001642 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
1643 {{0, 0}, {0, 255}}, {{0, 0}, {0, 255}}};
1644 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001645
1646 glDeleteProgram(program);
1647}
1648
1649// Test that rendering enlarged points and lines does not leak fragments outside of the views'
1650// bounds. The test does not rely on the actual line width being greater than 1.0.
Martin Radev3c25ad02017-08-22 17:36:53 +03001651TEST_P(MultiviewSideBySideRenderTest, NoLeakingFragments)
Martin Radev61bd9992017-08-11 13:10:55 +03001652{
1653 if (!requestMultiviewExtension())
1654 {
1655 return;
1656 }
1657
Martin Radev3c25ad02017-08-22 17:36:53 +03001658 createFBO(2, 1, 2);
Martin Radev61bd9992017-08-11 13:10:55 +03001659
1660 GLint viewportOffsets[4] = {1, 0, 3, 0};
1661 glFramebufferTextureMultiviewSideBySideANGLE(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1662 mColorTexture, 0, 2, &viewportOffsets[0]);
1663 glFramebufferTextureMultiviewSideBySideANGLE(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
1664 mDepthTexture, 0, 2, &viewportOffsets[0]);
1665
1666 glViewport(0, 0, 1, 1);
1667 glScissor(0, 0, 1, 1);
1668 glEnable(GL_SCISSOR_TEST);
1669
1670 const std::string vsSource =
1671 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001672 "#extension GL_OVR_multiview : require\n"
Martin Radev61bd9992017-08-11 13:10:55 +03001673 "layout(num_views = 2) in;\n"
1674 "layout(location=0) in vec2 vPosition;\n"
1675 "void main()\n"
1676 "{\n"
1677 " gl_PointSize = 10.0;\n"
1678 " gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n"
1679 "}\n";
1680
1681 const std::string fsSource =
1682 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001683 "#extension GL_OVR_multiview : require\n"
Martin Radev61bd9992017-08-11 13:10:55 +03001684 "precision mediump float;\n"
1685 "out vec4 col;\n"
1686 "void main()\n"
1687 "{\n"
1688 " if (gl_ViewID_OVR == 0u) {\n"
1689 " col = vec4(1,0,0,1);\n"
1690 " } else {\n"
1691 " col = vec4(0,1,0,1);\n"
1692 " }\n"
1693 "}\n";
1694 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1695 glUseProgram(program);
1696
1697 const std::vector<Vector2I> &windowCoordinates = {Vector2I(0, 0), Vector2I(2, 0)};
1698 const std::vector<Vector2> &vertexDataInClipSpace =
1699 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 1, 1);
Martin Radev3c25ad02017-08-22 17:36:53 +03001700
1701 GLBuffer vbo;
1702 glBindBuffer(GL_ARRAY_BUFFER, vbo);
1703 glBufferData(GL_ARRAY_BUFFER, vertexDataInClipSpace.size() * sizeof(Vector2),
1704 vertexDataInClipSpace.data(), GL_STATIC_DRAW);
1705 glEnableVertexAttribArray(0);
Luc Ferronadcf0ae2018-01-24 08:27:37 -05001706 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
Martin Radev61bd9992017-08-11 13:10:55 +03001707
1708 // Test rendering points.
1709 {
1710 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1711 glDrawArrays(GL_POINTS, 0, 2);
1712 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1713 EXPECT_PIXEL_COLOR_EQ(1, 0, GLColor::red);
1714 EXPECT_PIXEL_COLOR_EQ(2, 0, GLColor::black);
1715 EXPECT_PIXEL_COLOR_EQ(3, 0, GLColor::green);
1716 }
1717
1718 // Test rendering lines.
1719 {
1720 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1721 glLineWidth(10.f);
1722 glDrawArrays(GL_LINES, 0, 2);
1723 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1724 EXPECT_PIXEL_COLOR_EQ(1, 0, GLColor::red);
1725 EXPECT_PIXEL_COLOR_EQ(2, 0, GLColor::black);
1726 EXPECT_PIXEL_COLOR_EQ(3, 0, GLColor::green);
1727 }
1728}
1729
Martin Radev0abb7a22017-08-28 15:34:45 +03001730// Verify that re-linking a program adjusts the attribute divisor.
1731// The test uses instacing to draw for each view a strips of two red quads and two blue quads next
1732// to each other. The quads' position and color depend on the corresponding attribute divisors.
1733TEST_P(MultiviewRenderTest, ProgramRelinkUpdatesAttribDivisor)
1734{
1735 if (!requestMultiviewExtension())
1736 {
1737 return;
1738 }
1739
1740 const int kViewWidth = 4;
1741 const int kViewHeight = 1;
1742 const int kNumViews = 2;
1743
1744 const std::string &fsSource =
1745 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001746 "#extension GL_OVR_multiview : require\n"
Martin Radev0abb7a22017-08-28 15:34:45 +03001747 "precision mediump float;\n"
1748 "in vec4 oColor;\n"
1749 "out vec4 col;\n"
1750 "void main()\n"
1751 "{\n"
1752 " col = oColor;\n"
1753 "}\n";
1754
1755 auto generateVertexShaderSource = [](int numViews) -> std::string {
1756 std::string source =
1757 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001758 "#extension GL_OVR_multiview : require\n"
Martin Radev0abb7a22017-08-28 15:34:45 +03001759 "layout(num_views = " +
1760 ToString(numViews) +
1761 ") in;\n"
1762 "in vec3 vPosition;\n"
1763 "in float vOffsetX;\n"
1764 "in vec4 vColor;\n"
1765 "out vec4 oColor;\n"
1766 "void main()\n"
1767 "{\n"
1768 " vec4 p = vec4(vPosition, 1.);\n"
1769 " p.x = p.x * 0.25 - 0.75 + vOffsetX;\n"
1770 " oColor = vColor;\n"
1771 " gl_Position = p;\n"
1772 "}\n";
1773 return source;
1774 };
1775
1776 std::string vsSource = generateVertexShaderSource(kNumViews);
1777 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1778 glUseProgram(program);
1779
1780 GLint positionLoc;
1781 GLBuffer xOffsetVBO;
1782 GLint xOffsetLoc;
1783 GLBuffer colorVBO;
1784 GLint colorLoc;
1785
1786 {
1787 // Initialize buffers and setup attributes.
1788 glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
1789 const GLfloat kXOffsetData[4] = {0.0f, 0.5f, 1.0f, 1.5f};
1790 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4, kXOffsetData, GL_STATIC_DRAW);
1791 xOffsetLoc = glGetAttribLocation(program, "vOffsetX");
1792 glVertexAttribPointer(xOffsetLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
1793 glVertexAttribDivisor(xOffsetLoc, 1);
1794 glEnableVertexAttribArray(xOffsetLoc);
1795
1796 glBindBuffer(GL_ARRAY_BUFFER, colorVBO);
1797 const GLColor kColors[2] = {GLColor::red, GLColor::blue};
1798 glBufferData(GL_ARRAY_BUFFER, sizeof(GLColor) * 2, kColors, GL_STATIC_DRAW);
1799 colorLoc = glGetAttribLocation(program, "vColor");
1800 glVertexAttribDivisor(colorLoc, 2);
1801 glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1802 glEnableVertexAttribArray(colorLoc);
1803
1804 positionLoc = glGetAttribLocation(program, "vPosition");
1805 }
1806
1807 {
1808 createFBO(kViewWidth, kViewHeight, kNumViews);
1809
Martin Radev67a8a012017-09-08 13:03:52 +03001810 drawQuadInstanced(program, "vPosition", 0.0f, 1.0f, true, 4u);
Martin Radev0abb7a22017-08-28 15:34:45 +03001811 ASSERT_GL_NO_ERROR();
1812
1813 EXPECT_EQ(GLColor::red, GetViewColor(0, 0, 0));
1814 EXPECT_EQ(GLColor::red, GetViewColor(1, 0, 0));
1815 EXPECT_EQ(GLColor::blue, GetViewColor(2, 0, 0));
1816 EXPECT_EQ(GLColor::blue, GetViewColor(3, 0, 0));
1817 }
1818
1819 {
1820 const int kNewNumViews = 3;
1821 vsSource = generateVertexShaderSource(kNewNumViews);
1822 createFBO(kViewWidth, kViewHeight, kNewNumViews);
1823
1824 GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource);
1825 ASSERT_NE(0u, vs);
1826 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource);
1827 ASSERT_NE(0u, fs);
1828
1829 GLint numAttachedShaders = 0;
1830 glGetProgramiv(program, GL_ATTACHED_SHADERS, &numAttachedShaders);
1831
1832 GLuint attachedShaders[2] = {0u};
1833 glGetAttachedShaders(program, numAttachedShaders, nullptr, attachedShaders);
1834 for (int i = 0; i < 2; ++i)
1835 {
1836 glDetachShader(program, attachedShaders[i]);
1837 }
1838
1839 glAttachShader(program, vs);
1840 glDeleteShader(vs);
1841
1842 glAttachShader(program, fs);
1843 glDeleteShader(fs);
1844
1845 glBindAttribLocation(program, positionLoc, "vPosition");
1846 glBindAttribLocation(program, xOffsetLoc, "vOffsetX");
1847 glBindAttribLocation(program, colorLoc, "vColor");
1848
1849 glLinkProgram(program);
1850
Martin Radev67a8a012017-09-08 13:03:52 +03001851 drawQuadInstanced(program, "vPosition", 0.0f, 1.0f, true, 4u);
Martin Radev0abb7a22017-08-28 15:34:45 +03001852 ASSERT_GL_NO_ERROR();
1853
1854 for (int i = 0; i < kNewNumViews; ++i)
1855 {
1856 EXPECT_EQ(GLColor::red, GetViewColor(0, 0, i));
1857 EXPECT_EQ(GLColor::red, GetViewColor(1, 0, i));
1858 EXPECT_EQ(GLColor::blue, GetViewColor(2, 0, i));
1859 EXPECT_EQ(GLColor::blue, GetViewColor(3, 0, i));
1860 }
1861 }
1862}
1863
Martin Radevced5c862017-08-17 16:05:29 +03001864// Test that useProgram applies the number of views in computing the final value of the attribute
1865// divisor.
1866TEST_P(MultiviewRenderTest, DivisorUpdatedOnProgramChange)
1867{
1868 if (!requestMultiviewExtension())
1869 {
1870 return;
1871 }
1872
Geoff Lang25858162017-11-06 11:25:58 -05001873 // Test failing on P400 graphics card (anglebug.com/2228)
1874 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11() && IsNVIDIA());
1875
Martin Radevced5c862017-08-17 16:05:29 +03001876 GLVertexArray vao;
1877 glBindVertexArray(vao);
1878 GLBuffer vbo;
1879 glBindBuffer(GL_ARRAY_BUFFER, vbo);
1880 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(1, 0), Vector2I(2, 0),
1881 Vector2I(3, 0)};
1882 std::vector<Vector2> vertexDataInClipSpace =
1883 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 1);
1884 // Fill with x positions so that the resulting clip space coordinate fails the clip test.
1885 glBufferData(GL_ARRAY_BUFFER, sizeof(Vector2) * vertexDataInClipSpace.size(),
1886 vertexDataInClipSpace.data(), GL_STATIC_DRAW);
1887 glEnableVertexAttribArray(0);
1888 glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, nullptr);
1889 glVertexAttribDivisor(0, 1);
1890 ASSERT_GL_NO_ERROR();
1891
1892 // Create a program and fbo with N views and draw N instances of a point horizontally.
1893 for (int numViews = 2; numViews <= 4; ++numViews)
1894 {
1895 createFBO(4, 1, numViews);
1896 ASSERT_GL_NO_ERROR();
1897
1898 GLuint program = CreateSimplePassthroughProgram(numViews);
1899 ASSERT_NE(program, 0u);
1900 glUseProgram(program);
1901 ASSERT_GL_NO_ERROR();
1902
1903 glDrawArraysInstanced(GL_POINTS, 0, 1, numViews);
1904
1905 for (int view = 0; view < numViews; ++view)
1906 {
1907 for (int j = 0; j < numViews; ++j)
1908 {
Martin Radev67a8a012017-09-08 13:03:52 +03001909 EXPECT_EQ(GLColor::green, GetViewColor(j, 0, view));
Martin Radevced5c862017-08-17 16:05:29 +03001910 }
1911 for (int j = numViews; j < 4; ++j)
1912 {
1913 EXPECT_EQ(GLColor::black, GetViewColor(j, 0, view));
1914 }
1915 }
1916
1917 glDeleteProgram(program);
1918 }
1919}
1920
Martin Radev72b4e1e2017-08-31 15:42:56 +03001921// The test checks that gl_ViewID_OVR is correctly propagated to the fragment shader.
1922TEST_P(MultiviewRenderTest, SelectColorBasedOnViewIDOVR)
1923{
1924 if (!requestMultiviewExtension())
1925 {
1926 return;
1927 }
1928
1929 const std::string vsSource =
1930 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001931 "#extension GL_OVR_multiview : require\n"
Martin Radev72b4e1e2017-08-31 15:42:56 +03001932 "layout(num_views = 3) in;\n"
1933 "in vec3 vPosition;\n"
1934 "void main()\n"
1935 "{\n"
1936 " gl_Position = vec4(vPosition, 1.);\n"
1937 "}\n";
1938
1939 const std::string fsSource =
1940 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001941 "#extension GL_OVR_multiview : require\n"
Martin Radev72b4e1e2017-08-31 15:42:56 +03001942 "precision mediump float;\n"
1943 "out vec4 col;\n"
1944 "void main()\n"
1945 "{\n"
1946 " if (gl_ViewID_OVR == 0u) {\n"
1947 " col = vec4(1,0,0,1);\n"
1948 " } else if (gl_ViewID_OVR == 1u) {\n"
1949 " col = vec4(0,1,0,1);\n"
1950 " } else if (gl_ViewID_OVR == 2u) {\n"
1951 " col = vec4(0,0,1,1);\n"
1952 " } else {\n"
1953 " col = vec4(0,0,0,0);\n"
1954 " }\n"
1955 "}\n";
1956
1957 createFBO(1, 1, 3);
1958 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev72b4e1e2017-08-31 15:42:56 +03001959
1960 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
1961 ASSERT_GL_NO_ERROR();
1962
1963 EXPECT_EQ(GLColor::red, GetViewColor(0, 0, 0));
1964 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
1965 EXPECT_EQ(GLColor::blue, GetViewColor(0, 0, 2));
1966}
1967
1968// The test checks that the inactive layers of a 2D texture array are not written to by a
1969// multi-view program.
1970TEST_P(MultiviewLayeredRenderTest, RenderToSubrageOfLayers)
1971{
1972 if (!requestMultiviewExtension())
1973 {
1974 return;
1975 }
1976
1977 const std::string vsSource =
1978 "#version 300 es\n"
1979 "#extension GL_OVR_multiview : require\n"
1980 "layout(num_views = 2) in;\n"
1981 "in vec3 vPosition;\n"
1982 "void main()\n"
1983 "{\n"
1984 " gl_Position = vec4(vPosition, 1.);\n"
1985 "}\n";
1986
1987 const std::string fsSource =
1988 "#version 300 es\n"
1989 "#extension GL_OVR_multiview : require\n"
1990 "precision mediump float;\n"
1991 "out vec4 col;\n"
1992 "void main()\n"
1993 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03001994 " col = vec4(0,1,0,1);\n"
Martin Radev72b4e1e2017-08-31 15:42:56 +03001995 "}\n";
1996
1997 createFBO(1, 1, 2, 4, 1);
1998 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev72b4e1e2017-08-31 15:42:56 +03001999
2000 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
2001 ASSERT_GL_NO_ERROR();
2002
2003 EXPECT_EQ(GLColor::transparentBlack, GetViewColor(0, 0, 0));
Martin Radev67a8a012017-09-08 13:03:52 +03002004 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
2005 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 2));
Martin Radev72b4e1e2017-08-31 15:42:56 +03002006 EXPECT_EQ(GLColor::transparentBlack, GetViewColor(0, 0, 3));
2007}
2008
Martin Radevc1d4e552017-08-21 12:01:10 +03002009// The D3D11 renderer uses a GS whenever the varyings are flat interpolated which can cause
2010// potential bugs if the view is selected in the VS. The test contains a program in which the
2011// gl_InstanceID is passed as a flat varying to the fragment shader where it is used to discard the
2012// fragment if its value is negative. The gl_InstanceID should never be negative and that branch is
2013// never taken. One quad is drawn and the color is selected based on the ViewID - red for view 0 and
2014// green for view 1.
2015TEST_P(MultiviewRenderTest, FlatInterpolation)
Martin Radev3c25ad02017-08-22 17:36:53 +03002016{
Martin Radevc1d4e552017-08-21 12:01:10 +03002017 if (!requestMultiviewExtension())
2018 {
2019 return;
2020 }
2021
Geoff Lang25858162017-11-06 11:25:58 -05002022 // Test failing on P400 graphics card (anglebug.com/2228)
2023 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11() && IsNVIDIA());
2024
Yuly Novikov1de29ab2017-09-07 18:07:23 -04002025 // TODO(mradev): Find out why this fails on Win10 Intel HD 630 D3D11
2026 // (http://anglebug.com/2062)
2027 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsD3D11());
2028
Martin Radevc1d4e552017-08-21 12:01:10 +03002029 const std::string vsSource =
2030 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03002031 "#extension GL_OVR_multiview : require\n"
Martin Radevc1d4e552017-08-21 12:01:10 +03002032 "layout(num_views = 2) in;\n"
2033 "in vec3 vPosition;\n"
2034 "flat out int oInstanceID;\n"
2035 "void main()\n"
2036 "{\n"
2037 " gl_Position = vec4(vPosition, 1.);\n"
2038 " oInstanceID = gl_InstanceID;\n"
2039 "}\n";
2040
2041 const std::string fsSource =
2042 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03002043 "#extension GL_OVR_multiview : require\n"
Martin Radevc1d4e552017-08-21 12:01:10 +03002044 "precision mediump float;\n"
2045 "flat in int oInstanceID;\n"
2046 "out vec4 col;\n"
2047 "void main()\n"
2048 "{\n"
2049 " if (oInstanceID < 0) {\n"
2050 " discard;\n"
2051 " }\n"
2052 " if (gl_ViewID_OVR == 0u) {\n"
2053 " col = vec4(1,0,0,1);\n"
2054 " } else {\n"
2055 " col = vec4(0,1,0,1);\n"
2056 " }\n"
2057 "}\n";
2058
2059 createFBO(1, 1, 2);
2060 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
2061
2062 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
2063 ASSERT_GL_NO_ERROR();
2064
2065 EXPECT_EQ(GLColor::red, GetViewColor(0, 0, 0));
2066 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev3c25ad02017-08-22 17:36:53 +03002067}
2068
Martin Radev265a6d42017-09-12 16:51:37 +03002069// The test is added to cover a bug which resulted in the viewport/scissor and viewport offsets not
2070// being correctly applied.
2071TEST_P(MultiviewSideBySideRenderTest, ViewportOffsetsAppliedBugCoverage)
2072{
2073 if (!requestMultiviewExtension())
2074 {
2075 return;
2076 }
2077
2078 createFBO(1, 1, 2);
2079
2080 // Create multiview program.
2081 const std::string &vs =
2082 "#version 300 es\n"
2083 "#extension GL_OVR_multiview : require\n"
2084 "layout(num_views = 2) in;\n"
2085 "layout(location = 0) in vec3 vPosition;\n"
2086 "void main()\n"
2087 "{\n"
2088 " gl_Position = vec4(vPosition, 1.0);\n"
2089 "}\n";
2090
2091 const std::string &fs =
2092 "#version 300 es\n"
2093 "#extension GL_OVR_multiview : require\n"
2094 "precision mediump float;\n"
2095 "out vec4 col;\n"
2096 "void main()\n"
2097 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03002098 " col = vec4(0,1,0,1);\n"
Martin Radev265a6d42017-09-12 16:51:37 +03002099 "}\n";
2100
2101 ANGLE_GL_PROGRAM(program, vs, fs);
2102
2103 glViewport(0, 0, 1, 1);
2104 glScissor(0, 0, 1, 1);
2105 glEnable(GL_SCISSOR_TEST);
2106 glClearColor(0, 0, 0, 1);
2107
2108 // Bind the default FBO and make sure that the state is synchronized.
2109 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
2110 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2111 ASSERT_GL_NO_ERROR();
2112
2113 // Draw and check that both views are rendered to.
2114 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
2115 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev67a8a012017-09-08 13:03:52 +03002116
Martin Radev265a6d42017-09-12 16:51:37 +03002117 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
Martin Radev67a8a012017-09-08 13:03:52 +03002118 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 0));
2119 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev265a6d42017-09-12 16:51:37 +03002120}
2121
Martin Radevc1d4e552017-08-21 12:01:10 +03002122MultiviewImplementationParams VertexShaderOpenGL()
Martin Radev3c25ad02017-08-22 17:36:53 +03002123{
Martin Radevc1d4e552017-08-21 12:01:10 +03002124 return MultiviewImplementationParams(false, egl_platform::OPENGL());
Martin Radev3c25ad02017-08-22 17:36:53 +03002125}
2126
Martin Radevc1d4e552017-08-21 12:01:10 +03002127MultiviewImplementationParams VertexShaderD3D11()
Martin Radev3c25ad02017-08-22 17:36:53 +03002128{
Martin Radevc1d4e552017-08-21 12:01:10 +03002129 return MultiviewImplementationParams(false, egl_platform::D3D11());
Martin Radev3c25ad02017-08-22 17:36:53 +03002130}
2131
Martin Radevc1d4e552017-08-21 12:01:10 +03002132MultiviewImplementationParams GeomShaderD3D11()
Martin Radev72b4e1e2017-08-31 15:42:56 +03002133{
Martin Radevc1d4e552017-08-21 12:01:10 +03002134 return MultiviewImplementationParams(true, egl_platform::D3D11());
2135}
2136
2137MultiviewTestParams SideBySideVertexShaderOpenGL()
2138{
2139 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, VertexShaderOpenGL());
2140}
2141
2142MultiviewTestParams LayeredVertexShaderOpenGL()
2143{
2144 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE, VertexShaderOpenGL());
2145}
2146
2147MultiviewTestParams SideBySideGeomShaderD3D11()
2148{
2149 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, GeomShaderD3D11());
2150}
2151
2152MultiviewTestParams LayeredGeomShaderD3D11()
2153{
2154 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE, GeomShaderD3D11());
2155}
2156
2157MultiviewTestParams SideBySideVertexShaderD3D11()
2158{
2159 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, VertexShaderD3D11());
2160}
2161
2162MultiviewTestParams LayeredVertexShaderD3D11()
2163{
2164 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE, VertexShaderD3D11());
Martin Radev72b4e1e2017-08-31 15:42:56 +03002165}
2166
Martin Radev8f276e22017-05-30 12:05:52 +03002167ANGLE_INSTANTIATE_TEST(MultiviewDrawValidationTest, ES31_OPENGL());
Martin Radevced5c862017-08-17 16:05:29 +03002168ANGLE_INSTANTIATE_TEST(MultiviewRenderDualViewTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002169 SideBySideVertexShaderOpenGL(),
2170 LayeredVertexShaderOpenGL(),
2171 SideBySideGeomShaderD3D11(),
2172 SideBySideVertexShaderD3D11(),
2173 LayeredGeomShaderD3D11(),
2174 LayeredVertexShaderD3D11());
Martin Radev72b4e1e2017-08-31 15:42:56 +03002175ANGLE_INSTANTIATE_TEST(MultiviewRenderTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002176 SideBySideVertexShaderOpenGL(),
2177 LayeredVertexShaderOpenGL(),
2178 SideBySideGeomShaderD3D11(),
2179 SideBySideVertexShaderD3D11(),
2180 LayeredGeomShaderD3D11(),
2181 LayeredVertexShaderD3D11());
Martin Radevced5c862017-08-17 16:05:29 +03002182ANGLE_INSTANTIATE_TEST(MultiviewOcclusionQueryTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002183 SideBySideVertexShaderOpenGL(),
2184 LayeredVertexShaderOpenGL(),
2185 SideBySideGeomShaderD3D11(),
2186 SideBySideVertexShaderD3D11(),
2187 LayeredGeomShaderD3D11(),
2188 LayeredVertexShaderD3D11());
Martin Radev72b4e1e2017-08-31 15:42:56 +03002189ANGLE_INSTANTIATE_TEST(MultiviewProgramGenerationTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002190 SideBySideVertexShaderOpenGL(),
2191 LayeredVertexShaderOpenGL(),
2192 SideBySideGeomShaderD3D11(),
2193 SideBySideVertexShaderD3D11(),
2194 LayeredGeomShaderD3D11(),
2195 LayeredVertexShaderD3D11());
Martin Radevced5c862017-08-17 16:05:29 +03002196ANGLE_INSTANTIATE_TEST(MultiviewRenderPrimitiveTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002197 SideBySideVertexShaderOpenGL(),
2198 LayeredVertexShaderOpenGL(),
2199 SideBySideGeomShaderD3D11(),
2200 SideBySideVertexShaderD3D11(),
2201 LayeredGeomShaderD3D11(),
2202 LayeredVertexShaderD3D11());
2203ANGLE_INSTANTIATE_TEST(MultiviewSideBySideRenderTest, VertexShaderOpenGL(), GeomShaderD3D11());
2204ANGLE_INSTANTIATE_TEST(MultiviewLayeredRenderTest, VertexShaderOpenGL(), GeomShaderD3D11());