blob: 34b7b0113b5b57da90f54f4edeb4a29bb34f3155 [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{
Yunchao He9550c602018-02-13 14:47:05 +0800765 ANGLE_SKIP_TEST_IF(!requestMultiviewExtension());
Martin Radevffe754b2017-07-31 10:38:07 +0300766
Yunchao He9550c602018-02-13 14:47:05 +0800767 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_disjoint_timer_query"));
Martin Radevffe754b2017-07-31 10:38:07 +0300768
769 const GLint viewportOffsets[4] = {0, 0, 2, 0};
770 const std::string &vsSource =
771 "#version 300 es\n"
772 "void main()\n"
773 "{}\n";
774 const std::string &fsSource =
775 "#version 300 es\n"
776 "precision mediump float;\n"
777 "void main()\n"
778 "{}\n";
779 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
780 glUseProgram(program);
781
782 GLuint query = 0u;
783 glGenQueriesEXT(1, &query);
784 glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query);
785
786 // Check first case.
787 {
788 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
789 0, 2, &viewportOffsets[0]);
790 glDrawArrays(GL_TRIANGLES, 0, 3);
791 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
792 }
793
794 // Check second case.
795 {
796 glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
797 0, 1, &viewportOffsets[0]);
798 glDrawArrays(GL_TRIANGLES, 0, 3);
799 EXPECT_GL_NO_ERROR();
800 }
801
802 glEndQueryEXT(GL_TIME_ELAPSED_EXT);
803 glDeleteQueries(1, &query);
804}
805
Martin Radev8f276e22017-05-30 12:05:52 +0300806// The test checks that glDrawArrays can be used to render into two views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300807TEST_P(MultiviewRenderDualViewTest, DrawArrays)
Martin Radev8f276e22017-05-30 12:05:52 +0300808{
809 if (!requestMultiviewExtension())
810 {
811 return;
812 }
813 drawQuad(mProgram, "vPosition", 0.0f, 1.0f, true);
814 ASSERT_GL_NO_ERROR();
815
816 checkOutput();
817}
818
819// The test checks that glDrawElements can be used to render into two views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300820TEST_P(MultiviewRenderDualViewTest, DrawElements)
Martin Radev8f276e22017-05-30 12:05:52 +0300821{
822 if (!requestMultiviewExtension())
823 {
824 return;
825 }
826 drawIndexedQuad(mProgram, "vPosition", 0.0f, 1.0f, true);
827 ASSERT_GL_NO_ERROR();
828
829 checkOutput();
830}
831
832// The test checks that glDrawRangeElements can be used to render into two views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300833TEST_P(MultiviewRenderDualViewTest, DrawRangeElements)
Martin Radev8f276e22017-05-30 12:05:52 +0300834{
835 if (!requestMultiviewExtension())
836 {
837 return;
838 }
839 drawIndexedQuad(mProgram, "vPosition", 0.0f, 1.0f, true, true);
840 ASSERT_GL_NO_ERROR();
841
842 checkOutput();
843}
844
845// The test checks that glDrawArrays can be used to render into four views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300846TEST_P(MultiviewRenderTest, DrawArraysFourViews)
Martin Radev8f276e22017-05-30 12:05:52 +0300847{
848 if (!requestMultiviewExtension())
849 {
850 return;
851 }
852
853 const std::string vsSource =
854 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +0300855 "#extension GL_OVR_multiview : require\n"
Martin Radev8f276e22017-05-30 12:05:52 +0300856 "layout(num_views = 4) in;\n"
857 "in vec4 vPosition;\n"
858 "void main()\n"
859 "{\n"
860 " if (gl_ViewID_OVR == 0u) {\n"
861 " gl_Position.x = vPosition.x*0.25 - 0.75;\n"
862 " } else if (gl_ViewID_OVR == 1u) {\n"
863 " gl_Position.x = vPosition.x*0.25 - 0.25;\n"
864 " } else if (gl_ViewID_OVR == 2u) {\n"
865 " gl_Position.x = vPosition.x*0.25 + 0.25;\n"
866 " } else {\n"
867 " gl_Position.x = vPosition.x*0.25 + 0.75;\n"
868 " }"
869 " gl_Position.yzw = vPosition.yzw;\n"
870 "}\n";
871
872 const std::string fsSource =
873 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +0300874 "#extension GL_OVR_multiview : require\n"
Martin Radev8f276e22017-05-30 12:05:52 +0300875 "precision mediump float;\n"
876 "out vec4 col;\n"
877 "void main()\n"
878 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +0300879 " col = vec4(0,1,0,1);\n"
Martin Radev8f276e22017-05-30 12:05:52 +0300880 "}\n";
881
Martin Radev3c25ad02017-08-22 17:36:53 +0300882 createFBO(4, 1, 4);
Martin Radev8f276e22017-05-30 12:05:52 +0300883 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev8f276e22017-05-30 12:05:52 +0300884
885 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
886 ASSERT_GL_NO_ERROR();
887
888 for (int i = 0; i < 4; ++i)
889 {
890 for (int j = 0; j < 4; ++j)
891 {
Martin Radev8f276e22017-05-30 12:05:52 +0300892 if (i == j)
893 {
Martin Radev67a8a012017-09-08 13:03:52 +0300894 EXPECT_EQ(GLColor::green, GetViewColor(j, 0, i));
Martin Radev8f276e22017-05-30 12:05:52 +0300895 }
896 else
897 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300898 EXPECT_EQ(GLColor::black, GetViewColor(j, 0, i));
Martin Radev8f276e22017-05-30 12:05:52 +0300899 }
900 }
901 }
902 EXPECT_GL_NO_ERROR();
903}
904
905// The test checks that glDrawArraysInstanced can be used to render into two views.
Martin Radev3c25ad02017-08-22 17:36:53 +0300906TEST_P(MultiviewRenderTest, DrawArraysInstanced)
Martin Radev8f276e22017-05-30 12:05:52 +0300907{
908 if (!requestMultiviewExtension())
909 {
910 return;
911 }
912
913 const std::string vsSource =
914 "#version 300 es\n"
915 "#extension GL_OVR_multiview : require\n"
916 "layout(num_views = 2) in;\n"
917 "in vec4 vPosition;\n"
918 "void main()\n"
919 "{\n"
920 " vec4 p = vPosition;\n"
921 " if (gl_InstanceID == 1){\n"
922 " p.y = .5*p.y + .5;\n"
923 " } else {\n"
924 " p.y = p.y*.5;\n"
925 " }\n"
926 " gl_Position.x = (gl_ViewID_OVR == 0u ? p.x*0.5 + 0.5 : p.x*0.5);\n"
927 " gl_Position.yzw = p.yzw;\n"
928 "}\n";
929
930 const std::string fsSource =
931 "#version 300 es\n"
932 "#extension GL_OVR_multiview : require\n"
933 "precision mediump float;\n"
934 "out vec4 col;\n"
935 "void main()\n"
936 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +0300937 " col = vec4(0,1,0,1);\n"
Martin Radev8f276e22017-05-30 12:05:52 +0300938 "}\n";
939
Martin Radev3c25ad02017-08-22 17:36:53 +0300940 const int kViewWidth = 2;
941 const int kViewHeight = 2;
942 const int kNumViews = 2;
943 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev8f276e22017-05-30 12:05:52 +0300944 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev8f276e22017-05-30 12:05:52 +0300945
Martin Radev67a8a012017-09-08 13:03:52 +0300946 drawQuadInstanced(program, "vPosition", 0.0f, 1.0f, true, 2u);
Martin Radev8f276e22017-05-30 12:05:52 +0300947 ASSERT_GL_NO_ERROR();
948
Martin Radev67a8a012017-09-08 13:03:52 +0300949 const GLubyte expectedGreenChannel[kNumViews][kViewHeight][kViewWidth] = {{{0, 255}, {0, 255}},
950 {{255, 0}, {255, 0}}};
Martin Radev3c25ad02017-08-22 17:36:53 +0300951
952 for (int view = 0; view < 2; ++view)
Martin Radev8f276e22017-05-30 12:05:52 +0300953 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300954 for (int y = 0; y < 2; ++y)
Martin Radev8f276e22017-05-30 12:05:52 +0300955 {
Martin Radev3c25ad02017-08-22 17:36:53 +0300956 for (int x = 0; x < 2; ++x)
957 {
Martin Radev67a8a012017-09-08 13:03:52 +0300958 EXPECT_EQ(GLColor(0, expectedGreenChannel[view][y][x], 0, 255),
Martin Radev3c25ad02017-08-22 17:36:53 +0300959 GetViewColor(x, y, view));
960 }
Martin Radev8f276e22017-05-30 12:05:52 +0300961 }
962 }
963}
964
Martin Radev553590a2017-07-31 16:40:39 +0300965// The test verifies that the attribute divisor is correctly adjusted when drawing with a multi-view
966// program. The test draws 4 instances of a quad each of which covers a single pixel. The x and y
967// offset of each quad are passed as separate attributes which are indexed based on the
968// corresponding attribute divisors. A divisor of 1 is used for the y offset to have all quads
969// drawn vertically next to each other. A divisor of 3 is used for the x offset to have the last
970// quad offsetted by one pixel to the right. Note that the number of views is divisible by 1, but
971// not by 3.
Martin Radev3c25ad02017-08-22 17:36:53 +0300972TEST_P(MultiviewRenderTest, AttribDivisor)
Martin Radev553590a2017-07-31 16:40:39 +0300973{
974 if (!requestMultiviewExtension())
975 {
976 return;
977 }
978
979 const std::string &vsSource =
980 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +0300981 "#extension GL_OVR_multiview : require\n"
Martin Radev553590a2017-07-31 16:40:39 +0300982 "layout(num_views = 2) in;\n"
983 "in vec3 vPosition;\n"
984 "in float offsetX;\n"
985 "in float offsetY;\n"
986 "void main()\n"
987 "{\n"
988 " vec4 p = vec4(vPosition, 1.);\n"
Martin Radev0abb7a22017-08-28 15:34:45 +0300989 " p.xy = p.xy * 0.25 - vec2(0.75) + vec2(offsetX, offsetY);\n"
Martin Radev553590a2017-07-31 16:40:39 +0300990 " gl_Position.x = (gl_ViewID_OVR == 0u ? p.x : p.x + 1.0);\n"
991 " gl_Position.yzw = p.yzw;\n"
992 "}\n";
993
994 const std::string &fsSource =
995 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +0300996 "#extension GL_OVR_multiview : require\n"
Martin Radev553590a2017-07-31 16:40:39 +0300997 "precision mediump float;\n"
998 "out vec4 col;\n"
999 "void main()\n"
1000 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03001001 " col = vec4(0,1,0,1);\n"
Martin Radev553590a2017-07-31 16:40:39 +03001002 "}\n";
Martin Radev3c25ad02017-08-22 17:36:53 +03001003
1004 const int kViewWidth = 4;
1005 const int kViewHeight = 4;
1006 const int kNumViews = 2;
1007 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev553590a2017-07-31 16:40:39 +03001008 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev553590a2017-07-31 16:40:39 +03001009
1010 GLBuffer xOffsetVBO;
1011 glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
1012 const GLfloat xOffsetData[4] = {0.0f, 0.5f, 1.0f, 1.0f};
1013 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4, xOffsetData, GL_STATIC_DRAW);
1014 GLint xOffsetLoc = glGetAttribLocation(program, "offsetX");
1015 glVertexAttribPointer(xOffsetLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
1016 glVertexAttribDivisor(xOffsetLoc, 3);
1017 glEnableVertexAttribArray(xOffsetLoc);
1018
1019 GLBuffer yOffsetVBO;
1020 glBindBuffer(GL_ARRAY_BUFFER, yOffsetVBO);
1021 const GLfloat yOffsetData[4] = {0.0f, 0.5f, 1.0f, 1.5f};
1022 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4, yOffsetData, GL_STATIC_DRAW);
1023 GLint yOffsetLoc = glGetAttribLocation(program, "offsetY");
1024 glVertexAttribDivisor(yOffsetLoc, 1);
1025 glVertexAttribPointer(yOffsetLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
1026 glEnableVertexAttribArray(yOffsetLoc);
1027
Martin Radev67a8a012017-09-08 13:03:52 +03001028 drawQuadInstanced(program, "vPosition", 0.0f, 1.0f, true, 4u);
Martin Radev553590a2017-07-31 16:40:39 +03001029 ASSERT_GL_NO_ERROR();
1030
Martin Radev67a8a012017-09-08 13:03:52 +03001031 const GLubyte expectedGreenChannel[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001032 {{255, 0, 0, 0}, {255, 0, 0, 0}, {255, 0, 0, 0}, {0, 255, 0, 0}},
1033 {{0, 0, 255, 0}, {0, 0, 255, 0}, {0, 0, 255, 0}, {0, 0, 0, 255}}};
1034 for (int view = 0; view < 2; ++view)
Martin Radev553590a2017-07-31 16:40:39 +03001035 {
Martin Radev3c25ad02017-08-22 17:36:53 +03001036 for (int row = 0; row < 4; ++row)
Martin Radev553590a2017-07-31 16:40:39 +03001037 {
Martin Radev3c25ad02017-08-22 17:36:53 +03001038 for (int col = 0; col < 4; ++col)
1039 {
Martin Radev67a8a012017-09-08 13:03:52 +03001040 EXPECT_EQ(GLColor(0, expectedGreenChannel[view][row][col], 0, 255),
Martin Radev3c25ad02017-08-22 17:36:53 +03001041 GetViewColor(col, row, view));
1042 }
Martin Radev553590a2017-07-31 16:40:39 +03001043 }
1044 }
1045}
1046
1047// Test that different sequences of vertexAttribDivisor, useProgram and bindVertexArray in a
1048// multi-view context propagate the correct divisor to the driver.
Martin Radev3c25ad02017-08-22 17:36:53 +03001049TEST_P(MultiviewRenderTest, DivisorOrderOfOperation)
Martin Radev553590a2017-07-31 16:40:39 +03001050{
1051 if (!requestMultiviewExtension())
1052 {
1053 return;
1054 }
1055
Martin Radev3c25ad02017-08-22 17:36:53 +03001056 createFBO(1, 1, 2);
Martin Radev553590a2017-07-31 16:40:39 +03001057
1058 // Create multiview program.
1059 const std::string &vs =
1060 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001061 "#extension GL_OVR_multiview : require\n"
Martin Radev553590a2017-07-31 16:40:39 +03001062 "layout(num_views = 2) in;\n"
1063 "layout(location = 0) in vec2 vPosition;\n"
1064 "layout(location = 1) in float offsetX;\n"
1065 "void main()\n"
1066 "{\n"
1067 " vec4 p = vec4(vPosition, 0.0, 1.0);\n"
1068 " p.x += offsetX;\n"
1069 " gl_Position = p;\n"
1070 "}\n";
1071
1072 const std::string &fs =
1073 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001074 "#extension GL_OVR_multiview : require\n"
Martin Radev553590a2017-07-31 16:40:39 +03001075 "precision mediump float;\n"
1076 "out vec4 col;\n"
1077 "void main()\n"
1078 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03001079 " col = vec4(0,1,0,1);\n"
Martin Radev553590a2017-07-31 16:40:39 +03001080 "}\n";
1081
1082 ANGLE_GL_PROGRAM(program, vs, fs);
1083
1084 const std::string &dummyVS =
1085 "#version 300 es\n"
1086 "layout(location = 0) in vec2 vPosition;\n"
1087 "layout(location = 1) in float offsetX;\n"
1088 "void main()\n"
1089 "{\n"
1090 " gl_Position = vec4(vPosition, 0.0, 1.0);\n"
1091 "}\n";
1092
1093 const std::string &dummyFS =
1094 "#version 300 es\n"
1095 "precision mediump float;\n"
1096 "out vec4 col;\n"
1097 "void main()\n"
1098 "{\n"
Martin Radev61bd9992017-08-11 13:10:55 +03001099 " col = vec4(0,0,0,1);\n"
Martin Radev553590a2017-07-31 16:40:39 +03001100 "}\n";
1101
1102 ANGLE_GL_PROGRAM(dummyProgram, dummyVS, dummyFS);
1103
1104 GLBuffer xOffsetVBO;
1105 glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
1106 const GLfloat xOffsetData[12] = {0.0f, 4.0f, 4.0f, 4.0f, 4.0f, 4.0f,
1107 4.0f, 4.0f, 4.0f, 4.0f, 4.0f, 4.0f};
1108 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 12, xOffsetData, GL_STATIC_DRAW);
1109
1110 GLBuffer vertexVBO;
1111 glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
1112 Vector2 kQuadVertices[6] = {Vector2(-1.f, -1.f), Vector2(1.f, -1.f), Vector2(1.f, 1.f),
1113 Vector2(-1.f, -1.f), Vector2(1.f, 1.f), Vector2(-1.f, 1.f)};
1114 glBufferData(GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW);
1115
1116 GLVertexArray vao[2];
1117 for (size_t i = 0u; i < 2u; ++i)
1118 {
1119 glBindVertexArray(vao[i]);
1120
1121 glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
1122 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
1123 glEnableVertexAttribArray(0);
1124
1125 glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
1126 glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, 0);
1127 glEnableVertexAttribArray(1);
1128 }
1129 ASSERT_GL_NO_ERROR();
1130
1131 glViewport(0, 0, 1, 1);
1132 glScissor(0, 0, 1, 1);
Martin Radeveef80e42017-08-11 14:44:57 +03001133 glEnable(GL_SCISSOR_TEST);
Martin Radev61bd9992017-08-11 13:10:55 +03001134 glClearColor(0, 0, 0, 1);
Martin Radev553590a2017-07-31 16:40:39 +03001135
1136 // Clear the buffers, propagate divisor to the driver, bind the vao and keep it active.
1137 // It is necessary to call draw, so that the divisor is propagated and to guarantee that dirty
1138 // bits are cleared.
1139 glUseProgram(dummyProgram);
Martin Radevda8e2572017-09-12 17:21:16 +03001140 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1141 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001142 glBindVertexArray(vao[0]);
1143 glVertexAttribDivisor(1, 0);
1144 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
1145 glUseProgram(0);
Martin Radev553590a2017-07-31 16:40:39 +03001146 ASSERT_GL_NO_ERROR();
1147
1148 // Check that vertexAttribDivisor uses the number of views to update the divisor.
Martin Radevda8e2572017-09-12 17:21:16 +03001149 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
1150 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001151 glUseProgram(program);
1152 glVertexAttribDivisor(1, 1);
1153 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
Martin Radev67a8a012017-09-08 13:03:52 +03001154 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 0));
1155 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev553590a2017-07-31 16:40:39 +03001156
1157 // Clear the buffers and propagate divisor to the driver.
1158 // We keep the vao active and propagate the divisor to guarantee that there are no unresolved
1159 // dirty bits when useProgram is called.
1160 glUseProgram(dummyProgram);
Martin Radevda8e2572017-09-12 17:21:16 +03001161 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1162 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001163 glVertexAttribDivisor(1, 1);
1164 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
1165 glUseProgram(0);
Martin Radev553590a2017-07-31 16:40:39 +03001166 ASSERT_GL_NO_ERROR();
1167
1168 // Check that useProgram uses the number of views to update the divisor.
Martin Radevda8e2572017-09-12 17:21:16 +03001169 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
1170 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001171 glUseProgram(program);
1172 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
Martin Radev67a8a012017-09-08 13:03:52 +03001173 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 0));
1174 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev553590a2017-07-31 16:40:39 +03001175
1176 // We go through similar steps as before.
1177 glUseProgram(dummyProgram);
Martin Radevda8e2572017-09-12 17:21:16 +03001178 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1179 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001180 glVertexAttribDivisor(1, 1);
1181 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
1182 glUseProgram(0);
Martin Radev553590a2017-07-31 16:40:39 +03001183 ASSERT_GL_NO_ERROR();
1184
1185 // Check that bindVertexArray uses the number of views to update the divisor.
1186 {
1187 // Call useProgram with vao[1] being active to guarantee that useProgram will adjust the
1188 // divisor for vao[1] only.
Martin Radevda8e2572017-09-12 17:21:16 +03001189 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
1190 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001191 glBindVertexArray(vao[1]);
1192 glUseProgram(program);
1193 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
Martin Radev553590a2017-07-31 16:40:39 +03001194 glBindVertexArray(0);
1195 ASSERT_GL_NO_ERROR();
1196 }
1197 // Bind vao[0] after useProgram is called to ensure that bindVertexArray is the call which
1198 // adjusts the divisor.
Martin Radevda8e2572017-09-12 17:21:16 +03001199 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev553590a2017-07-31 16:40:39 +03001200 glBindVertexArray(vao[0]);
1201 glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
Martin Radev67a8a012017-09-08 13:03:52 +03001202 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 0));
1203 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev553590a2017-07-31 16:40:39 +03001204}
1205
Martin Radev0d671c92017-08-10 16:41:52 +03001206// Test that no fragments pass the occlusion query for a multi-view vertex shader which always
1207// transforms geometry to be outside of the clip region.
Martin Radev3c25ad02017-08-22 17:36:53 +03001208TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryNothingVisible)
Martin Radev0d671c92017-08-10 16:41:52 +03001209{
Geoff Lang8c5b31c2017-09-26 18:07:44 -04001210 ANGLE_SKIP_TEST_IF(!requestMultiviewExtension());
1211 ANGLE_SKIP_TEST_IF(!requestOcclusionQueryExtension());
Martin Radev0d671c92017-08-10 16:41:52 +03001212
1213 const std::string vsSource =
1214 "#version 300 es\n"
1215 "#extension GL_OVR_multiview : require\n"
1216 "layout(num_views = 2) in;\n"
1217 "in vec3 vPosition;\n"
1218 "void main()\n"
1219 "{\n"
1220 " gl_Position.x = 2.0;\n"
1221 " gl_Position.yzw = vec3(vPosition.yz, 1.);\n"
1222 "}\n";
1223
1224 const std::string fsSource =
1225 "#version 300 es\n"
1226 "#extension GL_OVR_multiview : require\n"
1227 "precision mediump float;\n"
1228 "out vec4 col;\n"
1229 "void main()\n"
1230 "{\n"
1231 " col = vec4(1,0,0,0);\n"
1232 "}\n";
1233 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev3c25ad02017-08-22 17:36:53 +03001234 createFBO(1, 1, 2);
Martin Radev0d671c92017-08-10 16:41:52 +03001235
1236 GLuint result = drawAndRetrieveOcclusionQueryResult(program);
1237 ASSERT_GL_NO_ERROR();
1238 EXPECT_GL_FALSE(result);
1239}
1240
1241// Test that there are fragments passing the occlusion query if only view 0 can produce
1242// output.
Martin Radev3c25ad02017-08-22 17:36:53 +03001243TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyLeftVisible)
Martin Radev0d671c92017-08-10 16:41:52 +03001244{
Geoff Lang8c5b31c2017-09-26 18:07:44 -04001245 ANGLE_SKIP_TEST_IF(!requestMultiviewExtension());
1246 ANGLE_SKIP_TEST_IF(!requestOcclusionQueryExtension());
Martin Radev0d671c92017-08-10 16:41:52 +03001247
1248 const std::string vsSource =
1249 "#version 300 es\n"
1250 "#extension GL_OVR_multiview : require\n"
1251 "layout(num_views = 2) in;\n"
1252 "in vec3 vPosition;\n"
1253 "void main()\n"
1254 "{\n"
1255 " gl_Position.x = gl_ViewID_OVR == 0u ? vPosition.x : 2.0;\n"
1256 " gl_Position.yzw = vec3(vPosition.yz, 1.);\n"
1257 "}\n";
1258
1259 const std::string fsSource =
1260 "#version 300 es\n"
1261 "#extension GL_OVR_multiview : require\n"
1262 "precision mediump float;\n"
1263 "out vec4 col;\n"
1264 "void main()\n"
1265 "{\n"
1266 " col = vec4(1,0,0,0);\n"
1267 "}\n";
1268 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev3c25ad02017-08-22 17:36:53 +03001269 createFBO(1, 1, 2);
Martin Radev0d671c92017-08-10 16:41:52 +03001270
1271 GLuint result = drawAndRetrieveOcclusionQueryResult(program);
1272 ASSERT_GL_NO_ERROR();
1273 EXPECT_GL_TRUE(result);
1274}
1275
1276// Test that there are fragments passing the occlusion query if only view 1 can produce
1277// output.
Martin Radev3c25ad02017-08-22 17:36:53 +03001278TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyRightVisible)
Martin Radev0d671c92017-08-10 16:41:52 +03001279{
Geoff Lang8c5b31c2017-09-26 18:07:44 -04001280 ANGLE_SKIP_TEST_IF(!requestMultiviewExtension());
1281 ANGLE_SKIP_TEST_IF(!requestOcclusionQueryExtension());
Martin Radev0d671c92017-08-10 16:41:52 +03001282
1283 const std::string vsSource =
1284 "#version 300 es\n"
1285 "#extension GL_OVR_multiview : require\n"
1286 "layout(num_views = 2) in;\n"
1287 "in vec3 vPosition;\n"
1288 "void main()\n"
1289 "{\n"
1290 " gl_Position.x = gl_ViewID_OVR == 1u ? vPosition.x : 2.0;\n"
1291 " gl_Position.yzw = vec3(vPosition.yz, 1.);\n"
1292 "}\n";
1293
1294 const std::string fsSource =
1295 "#version 300 es\n"
1296 "#extension GL_OVR_multiview : require\n"
1297 "precision mediump float;\n"
1298 "out vec4 col;\n"
1299 "void main()\n"
1300 "{\n"
1301 " col = vec4(1,0,0,0);\n"
1302 "}\n";
1303 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev3c25ad02017-08-22 17:36:53 +03001304 createFBO(1, 1, 2);
Martin Radev0d671c92017-08-10 16:41:52 +03001305
1306 GLuint result = drawAndRetrieveOcclusionQueryResult(program);
1307 ASSERT_GL_NO_ERROR();
1308 EXPECT_GL_TRUE(result);
1309}
1310
Martin Radev41ac68e2017-06-06 12:16:58 +03001311// Test that a simple multi-view program which doesn't use gl_ViewID_OVR in neither VS nor FS
1312// compiles and links without an error.
1313TEST_P(MultiviewProgramGenerationTest, SimpleProgram)
1314{
1315 if (!requestMultiviewExtension())
1316 {
1317 return;
1318 }
1319
1320 const std::string vsSource =
1321 "#version 300 es\n"
1322 "#extension GL_OVR_multiview : require\n"
1323 "layout(num_views = 2) in;\n"
1324 "void main()\n"
1325 "{\n"
1326 "}\n";
1327
1328 const std::string fsSource =
1329 "#version 300 es\n"
1330 "#extension GL_OVR_multiview : require\n"
1331 "precision mediump float;\n"
1332 "void main()\n"
1333 "{\n"
1334 "}\n";
1335
1336 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1337 glUseProgram(program);
1338
1339 EXPECT_GL_NO_ERROR();
1340}
1341
1342// Test that a simple multi-view program which uses gl_ViewID_OVR only in VS compiles and links
1343// without an error.
1344TEST_P(MultiviewProgramGenerationTest, UseViewIDInVertexShader)
1345{
1346 if (!requestMultiviewExtension())
1347 {
1348 return;
1349 }
1350
1351 const std::string vsSource =
1352 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001353 "#extension GL_OVR_multiview : require\n"
Martin Radev41ac68e2017-06-06 12:16:58 +03001354 "layout(num_views = 2) in;\n"
1355 "void main()\n"
1356 "{\n"
1357 " if (gl_ViewID_OVR == 0u) {\n"
1358 " gl_Position = vec4(1,0,0,1);\n"
1359 " } else {\n"
1360 " gl_Position = vec4(-1,0,0,1);\n"
1361 " }\n"
1362 "}\n";
1363
1364 const std::string fsSource =
1365 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001366 "#extension GL_OVR_multiview : require\n"
Martin Radev41ac68e2017-06-06 12:16:58 +03001367 "precision mediump float;\n"
1368 "void main()\n"
1369 "{\n"
1370 "}\n";
1371
1372 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1373 glUseProgram(program);
1374
1375 EXPECT_GL_NO_ERROR();
1376}
1377
1378// Test that a simple multi-view program which uses gl_ViewID_OVR only in FS compiles and links
1379// without an error.
1380TEST_P(MultiviewProgramGenerationTest, UseViewIDInFragmentShader)
1381{
1382 if (!requestMultiviewExtension())
1383 {
1384 return;
1385 }
1386
1387 const std::string vsSource =
1388 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001389 "#extension GL_OVR_multiview : require\n"
Martin Radev41ac68e2017-06-06 12:16:58 +03001390 "layout(num_views = 2) in;\n"
1391 "void main()\n"
1392 "{\n"
1393 "}\n";
1394
1395 const std::string fsSource =
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 "precision mediump float;\n"
1399 "out vec4 col;\n"
1400 "void main()\n"
1401 "{\n"
1402 " if (gl_ViewID_OVR == 0u) {\n"
1403 " col = vec4(1,0,0,1);\n"
1404 " } else {\n"
1405 " col = vec4(-1,0,0,1);\n"
1406 " }\n"
1407 "}\n";
1408
1409 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1410 glUseProgram(program);
1411
1412 EXPECT_GL_NO_ERROR();
1413}
1414
Martin Radev61bd9992017-08-11 13:10:55 +03001415// The test checks that GL_POINTS is correctly rendered.
Martin Radev3c25ad02017-08-22 17:36:53 +03001416TEST_P(MultiviewRenderPrimitiveTest, Points)
Martin Radev61bd9992017-08-11 13:10:55 +03001417{
1418 if (!requestMultiviewExtension())
1419 {
1420 return;
1421 }
1422
Geoff Lang25858162017-11-06 11:25:58 -05001423 // Test failing on P400 graphics card (anglebug.com/2228)
1424 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11() && IsNVIDIA());
1425
Martin Radev61bd9992017-08-11 13:10:55 +03001426 const std::string vsSource =
1427 "#version 300 es\n"
1428 "#extension GL_OVR_multiview : require\n"
1429 "layout(num_views = 2) in;\n"
1430 "layout(location=0) in vec2 vPosition;\n"
1431 "void main()\n"
1432 "{\n"
1433 " gl_PointSize = 1.0;\n"
1434 " gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n"
1435 "}\n";
1436
1437 const std::string fsSource =
1438 "#version 300 es\n"
1439 "#extension GL_OVR_multiview : require\n"
1440 "precision mediump float;\n"
1441 "out vec4 col;\n"
1442 "void main()\n"
1443 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03001444 " col = vec4(0,1,0,1);\n"
Martin Radev61bd9992017-08-11 13:10:55 +03001445 "}\n";
1446 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1447 glUseProgram(program);
1448
Martin Radev3c25ad02017-08-22 17:36:53 +03001449 const int kViewWidth = 4;
1450 const int kViewHeight = 2;
1451 const int kNumViews = 2;
1452 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001453
1454 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(3, 1)};
1455 std::vector<Vector2> vertexDataInClipSpace =
1456 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 2);
1457 setupGeometry(vertexDataInClipSpace);
1458
1459 glDrawArrays(GL_POINTS, 0, 2);
1460
Martin Radev67a8a012017-09-08 13:03:52 +03001461 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001462 {{255, 0, 0, 0}, {0, 0, 0, 255}}, {{255, 0, 0, 0}, {0, 0, 0, 255}}};
Martin Radev67a8a012017-09-08 13:03:52 +03001463 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001464}
1465
1466// The test checks that GL_LINES is correctly rendered.
1467// The behavior of this test is not guaranteed by the spec:
1468// OpenGL ES 3.0.5 (November 3, 2016), Section 3.5.1 Basic Line Segment Rasterization:
1469// "The coordinates of a fragment produced by the algorithm may not deviate by more than one unit in
1470// either x or y window coordinates from a corresponding fragment produced by the diamond-exit
1471// rule."
Martin Radev3c25ad02017-08-22 17:36:53 +03001472TEST_P(MultiviewRenderPrimitiveTest, Lines)
Martin Radev61bd9992017-08-11 13:10:55 +03001473{
1474 if (!requestMultiviewExtension())
1475 {
1476 return;
1477 }
1478
Martin Radevced5c862017-08-17 16:05:29 +03001479 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001480 ASSERT_NE(program, 0u);
1481 glUseProgram(program);
1482 ASSERT_GL_NO_ERROR();
1483
Martin Radev3c25ad02017-08-22 17:36:53 +03001484 const int kViewWidth = 4;
1485 const int kViewHeight = 2;
1486 const int kNumViews = 2;
1487 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001488
1489 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(4, 0)};
1490 std::vector<Vector2> vertexDataInClipSpace =
1491 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 2);
1492 setupGeometry(vertexDataInClipSpace);
1493
1494 glDrawArrays(GL_LINES, 0, 2);
1495
Martin Radev67a8a012017-09-08 13:03:52 +03001496 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001497 {{255, 255, 255, 255}, {0, 0, 0, 0}}, {{255, 255, 255, 255}, {0, 0, 0, 0}}};
Martin Radev67a8a012017-09-08 13:03:52 +03001498 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001499
1500 glDeleteProgram(program);
1501}
1502
1503// The test checks that GL_LINE_STRIP is correctly rendered.
1504// The behavior of this test is not guaranteed by the spec:
1505// OpenGL ES 3.0.5 (November 3, 2016), Section 3.5.1 Basic Line Segment Rasterization:
1506// "The coordinates of a fragment produced by the algorithm may not deviate by more than one unit in
1507// either x or y window coordinates from a corresponding fragment produced by the diamond-exit
1508// rule."
Martin Radev3c25ad02017-08-22 17:36:53 +03001509TEST_P(MultiviewRenderPrimitiveTest, LineStrip)
Martin Radev61bd9992017-08-11 13:10:55 +03001510{
1511 if (!requestMultiviewExtension())
1512 {
1513 return;
1514 }
1515
Martin Radevced5c862017-08-17 16:05:29 +03001516 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001517 ASSERT_NE(program, 0u);
1518 glUseProgram(program);
1519 ASSERT_GL_NO_ERROR();
1520
Martin Radev3c25ad02017-08-22 17:36:53 +03001521 const int kViewWidth = 4;
1522 const int kViewHeight = 2;
1523 const int kNumViews = 2;
1524 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001525
1526 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(3, 0), Vector2I(3, 2)};
1527 std::vector<Vector2> vertexDataInClipSpace =
1528 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 2);
1529 setupGeometry(vertexDataInClipSpace);
1530
1531 glDrawArrays(GL_LINE_STRIP, 0, 3);
1532
Martin Radev67a8a012017-09-08 13:03:52 +03001533 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001534 {{255, 255, 255, 255}, {0, 0, 0, 255}}, {{255, 255, 255, 255}, {0, 0, 0, 255}}};
Martin Radev67a8a012017-09-08 13:03:52 +03001535 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001536
1537 glDeleteProgram(program);
1538}
1539
1540// The test checks that GL_LINE_LOOP is correctly rendered.
1541// The behavior of this test is not guaranteed by the spec:
1542// OpenGL ES 3.0.5 (November 3, 2016), Section 3.5.1 Basic Line Segment Rasterization:
1543// "The coordinates of a fragment produced by the algorithm may not deviate by more than one unit in
1544// either x or y window coordinates from a corresponding fragment produced by the diamond-exit
1545// rule."
Martin Radev3c25ad02017-08-22 17:36:53 +03001546TEST_P(MultiviewRenderPrimitiveTest, LineLoop)
Martin Radev61bd9992017-08-11 13:10:55 +03001547{
1548 if (!requestMultiviewExtension())
1549 {
1550 return;
1551 }
1552
Martin Radevced5c862017-08-17 16:05:29 +03001553 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001554 ASSERT_NE(program, 0u);
1555 glUseProgram(program);
1556 ASSERT_GL_NO_ERROR();
1557
Martin Radev3c25ad02017-08-22 17:36:53 +03001558 const int kViewWidth = 4;
1559 const int kViewHeight = 4;
1560 const int kNumViews = 2;
1561 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001562
1563 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(3, 0), Vector2I(3, 3),
1564 Vector2I(0, 3)};
1565 std::vector<Vector2> vertexDataInClipSpace =
1566 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 4);
1567 setupGeometry(vertexDataInClipSpace);
1568
1569 glDrawArrays(GL_LINE_LOOP, 0, 4);
1570
Martin Radev67a8a012017-09-08 13:03:52 +03001571 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
Martin Radev3c25ad02017-08-22 17:36:53 +03001572 {{255, 255, 255, 255}, {255, 0, 0, 255}, {255, 0, 0, 255}, {255, 255, 255, 255}},
1573 {{255, 255, 255, 255}, {255, 0, 0, 255}, {255, 0, 0, 255}, {255, 255, 255, 255}}};
Martin Radev67a8a012017-09-08 13:03:52 +03001574 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001575
1576 glDeleteProgram(program);
1577}
1578
1579// The test checks that GL_TRIANGLE_STRIP is correctly rendered.
Martin Radev3c25ad02017-08-22 17:36:53 +03001580TEST_P(MultiviewRenderPrimitiveTest, TriangleStrip)
Martin Radev61bd9992017-08-11 13:10:55 +03001581{
1582 if (!requestMultiviewExtension())
1583 {
1584 return;
1585 }
1586
Martin Radevced5c862017-08-17 16:05:29 +03001587 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001588 ASSERT_NE(program, 0u);
1589 glUseProgram(program);
1590 ASSERT_GL_NO_ERROR();
1591
1592 std::vector<Vector2> vertexDataInClipSpace = {Vector2(1.0f, 0.0f), Vector2(0.0f, 0.0f),
1593 Vector2(1.0f, 1.0f), Vector2(0.0f, 1.0f)};
1594 setupGeometry(vertexDataInClipSpace);
1595
Martin Radev3c25ad02017-08-22 17:36:53 +03001596 const int kViewWidth = 2;
1597 const int kViewHeight = 2;
1598 const int kNumViews = 2;
1599 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001600
1601 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1602
Martin Radev67a8a012017-09-08 13:03:52 +03001603 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
1604 {{0, 0}, {0, 255}}, {{0, 0}, {0, 255}}};
1605 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001606
1607 glDeleteProgram(program);
1608}
1609
1610// The test checks that GL_TRIANGLE_FAN is correctly rendered.
Martin Radev3c25ad02017-08-22 17:36:53 +03001611TEST_P(MultiviewRenderPrimitiveTest, TriangleFan)
Martin Radev61bd9992017-08-11 13:10:55 +03001612{
1613 if (!requestMultiviewExtension())
1614 {
1615 return;
1616 }
1617
Martin Radevced5c862017-08-17 16:05:29 +03001618 GLuint program = CreateSimplePassthroughProgram(2);
Martin Radev61bd9992017-08-11 13:10:55 +03001619 ASSERT_NE(program, 0u);
1620 glUseProgram(program);
1621 ASSERT_GL_NO_ERROR();
1622
1623 std::vector<Vector2> vertexDataInClipSpace = {Vector2(0.0f, 0.0f), Vector2(0.0f, 1.0f),
1624 Vector2(1.0f, 1.0f), Vector2(1.0f, 0.0f)};
1625 setupGeometry(vertexDataInClipSpace);
1626
Martin Radev3c25ad02017-08-22 17:36:53 +03001627 const int kViewWidth = 2;
1628 const int kViewHeight = 2;
1629 const int kNumViews = 2;
1630 createFBO(kViewWidth, kViewHeight, kNumViews);
Martin Radev61bd9992017-08-11 13:10:55 +03001631
1632 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1633
Martin Radev67a8a012017-09-08 13:03:52 +03001634 const GLubyte expectedGreenChannelData[kNumViews][kViewHeight][kViewWidth] = {
1635 {{0, 0}, {0, 255}}, {{0, 0}, {0, 255}}};
1636 checkGreenChannel(expectedGreenChannelData[0][0]);
Martin Radev61bd9992017-08-11 13:10:55 +03001637
1638 glDeleteProgram(program);
1639}
1640
1641// Test that rendering enlarged points and lines does not leak fragments outside of the views'
1642// bounds. The test does not rely on the actual line width being greater than 1.0.
Martin Radev3c25ad02017-08-22 17:36:53 +03001643TEST_P(MultiviewSideBySideRenderTest, NoLeakingFragments)
Martin Radev61bd9992017-08-11 13:10:55 +03001644{
Luc Ferronaf7dc012018-06-26 07:56:49 -04001645 // TODO(oetuaho): Diagnose and fix http://anglebug.com/2687
1646 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11());
1647
Martin Radev61bd9992017-08-11 13:10:55 +03001648 if (!requestMultiviewExtension())
1649 {
1650 return;
1651 }
1652
Martin Radev3c25ad02017-08-22 17:36:53 +03001653 createFBO(2, 1, 2);
Martin Radev61bd9992017-08-11 13:10:55 +03001654
1655 GLint viewportOffsets[4] = {1, 0, 3, 0};
1656 glFramebufferTextureMultiviewSideBySideANGLE(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
1657 mColorTexture, 0, 2, &viewportOffsets[0]);
1658 glFramebufferTextureMultiviewSideBySideANGLE(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
1659 mDepthTexture, 0, 2, &viewportOffsets[0]);
1660
1661 glViewport(0, 0, 1, 1);
1662 glScissor(0, 0, 1, 1);
1663 glEnable(GL_SCISSOR_TEST);
1664
1665 const std::string vsSource =
1666 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001667 "#extension GL_OVR_multiview : require\n"
Martin Radev61bd9992017-08-11 13:10:55 +03001668 "layout(num_views = 2) in;\n"
1669 "layout(location=0) in vec2 vPosition;\n"
1670 "void main()\n"
1671 "{\n"
1672 " gl_PointSize = 10.0;\n"
1673 " gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n"
1674 "}\n";
1675
1676 const std::string fsSource =
1677 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001678 "#extension GL_OVR_multiview : require\n"
Martin Radev61bd9992017-08-11 13:10:55 +03001679 "precision mediump float;\n"
1680 "out vec4 col;\n"
1681 "void main()\n"
1682 "{\n"
1683 " if (gl_ViewID_OVR == 0u) {\n"
1684 " col = vec4(1,0,0,1);\n"
1685 " } else {\n"
1686 " col = vec4(0,1,0,1);\n"
1687 " }\n"
1688 "}\n";
1689 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1690 glUseProgram(program);
1691
1692 const std::vector<Vector2I> &windowCoordinates = {Vector2I(0, 0), Vector2I(2, 0)};
1693 const std::vector<Vector2> &vertexDataInClipSpace =
1694 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 1, 1);
Martin Radev3c25ad02017-08-22 17:36:53 +03001695
1696 GLBuffer vbo;
1697 glBindBuffer(GL_ARRAY_BUFFER, vbo);
1698 glBufferData(GL_ARRAY_BUFFER, vertexDataInClipSpace.size() * sizeof(Vector2),
1699 vertexDataInClipSpace.data(), GL_STATIC_DRAW);
1700 glEnableVertexAttribArray(0);
Luc Ferronadcf0ae2018-01-24 08:27:37 -05001701 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
Martin Radev61bd9992017-08-11 13:10:55 +03001702
1703 // Test rendering points.
1704 {
1705 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1706 glDrawArrays(GL_POINTS, 0, 2);
1707 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1708 EXPECT_PIXEL_COLOR_EQ(1, 0, GLColor::red);
1709 EXPECT_PIXEL_COLOR_EQ(2, 0, GLColor::black);
1710 EXPECT_PIXEL_COLOR_EQ(3, 0, GLColor::green);
1711 }
1712
1713 // Test rendering lines.
1714 {
1715 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1716 glLineWidth(10.f);
1717 glDrawArrays(GL_LINES, 0, 2);
1718 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1719 EXPECT_PIXEL_COLOR_EQ(1, 0, GLColor::red);
1720 EXPECT_PIXEL_COLOR_EQ(2, 0, GLColor::black);
1721 EXPECT_PIXEL_COLOR_EQ(3, 0, GLColor::green);
1722 }
1723}
1724
Martin Radev0abb7a22017-08-28 15:34:45 +03001725// Verify that re-linking a program adjusts the attribute divisor.
1726// The test uses instacing to draw for each view a strips of two red quads and two blue quads next
1727// to each other. The quads' position and color depend on the corresponding attribute divisors.
1728TEST_P(MultiviewRenderTest, ProgramRelinkUpdatesAttribDivisor)
1729{
1730 if (!requestMultiviewExtension())
1731 {
1732 return;
1733 }
1734
1735 const int kViewWidth = 4;
1736 const int kViewHeight = 1;
1737 const int kNumViews = 2;
1738
1739 const std::string &fsSource =
1740 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001741 "#extension GL_OVR_multiview : require\n"
Martin Radev0abb7a22017-08-28 15:34:45 +03001742 "precision mediump float;\n"
1743 "in vec4 oColor;\n"
1744 "out vec4 col;\n"
1745 "void main()\n"
1746 "{\n"
1747 " col = oColor;\n"
1748 "}\n";
1749
1750 auto generateVertexShaderSource = [](int numViews) -> std::string {
1751 std::string source =
1752 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001753 "#extension GL_OVR_multiview : require\n"
Martin Radev0abb7a22017-08-28 15:34:45 +03001754 "layout(num_views = " +
1755 ToString(numViews) +
1756 ") in;\n"
1757 "in vec3 vPosition;\n"
1758 "in float vOffsetX;\n"
1759 "in vec4 vColor;\n"
1760 "out vec4 oColor;\n"
1761 "void main()\n"
1762 "{\n"
1763 " vec4 p = vec4(vPosition, 1.);\n"
1764 " p.x = p.x * 0.25 - 0.75 + vOffsetX;\n"
1765 " oColor = vColor;\n"
1766 " gl_Position = p;\n"
1767 "}\n";
1768 return source;
1769 };
1770
1771 std::string vsSource = generateVertexShaderSource(kNumViews);
1772 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
1773 glUseProgram(program);
1774
1775 GLint positionLoc;
1776 GLBuffer xOffsetVBO;
1777 GLint xOffsetLoc;
1778 GLBuffer colorVBO;
1779 GLint colorLoc;
1780
1781 {
1782 // Initialize buffers and setup attributes.
1783 glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
1784 const GLfloat kXOffsetData[4] = {0.0f, 0.5f, 1.0f, 1.5f};
1785 glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4, kXOffsetData, GL_STATIC_DRAW);
1786 xOffsetLoc = glGetAttribLocation(program, "vOffsetX");
1787 glVertexAttribPointer(xOffsetLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
1788 glVertexAttribDivisor(xOffsetLoc, 1);
1789 glEnableVertexAttribArray(xOffsetLoc);
1790
1791 glBindBuffer(GL_ARRAY_BUFFER, colorVBO);
1792 const GLColor kColors[2] = {GLColor::red, GLColor::blue};
1793 glBufferData(GL_ARRAY_BUFFER, sizeof(GLColor) * 2, kColors, GL_STATIC_DRAW);
1794 colorLoc = glGetAttribLocation(program, "vColor");
1795 glVertexAttribDivisor(colorLoc, 2);
1796 glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1797 glEnableVertexAttribArray(colorLoc);
1798
1799 positionLoc = glGetAttribLocation(program, "vPosition");
1800 }
1801
1802 {
1803 createFBO(kViewWidth, kViewHeight, kNumViews);
1804
Martin Radev67a8a012017-09-08 13:03:52 +03001805 drawQuadInstanced(program, "vPosition", 0.0f, 1.0f, true, 4u);
Martin Radev0abb7a22017-08-28 15:34:45 +03001806 ASSERT_GL_NO_ERROR();
1807
1808 EXPECT_EQ(GLColor::red, GetViewColor(0, 0, 0));
1809 EXPECT_EQ(GLColor::red, GetViewColor(1, 0, 0));
1810 EXPECT_EQ(GLColor::blue, GetViewColor(2, 0, 0));
1811 EXPECT_EQ(GLColor::blue, GetViewColor(3, 0, 0));
1812 }
1813
1814 {
1815 const int kNewNumViews = 3;
1816 vsSource = generateVertexShaderSource(kNewNumViews);
1817 createFBO(kViewWidth, kViewHeight, kNewNumViews);
1818
1819 GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource);
1820 ASSERT_NE(0u, vs);
1821 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource);
1822 ASSERT_NE(0u, fs);
1823
1824 GLint numAttachedShaders = 0;
1825 glGetProgramiv(program, GL_ATTACHED_SHADERS, &numAttachedShaders);
1826
1827 GLuint attachedShaders[2] = {0u};
1828 glGetAttachedShaders(program, numAttachedShaders, nullptr, attachedShaders);
1829 for (int i = 0; i < 2; ++i)
1830 {
1831 glDetachShader(program, attachedShaders[i]);
1832 }
1833
1834 glAttachShader(program, vs);
1835 glDeleteShader(vs);
1836
1837 glAttachShader(program, fs);
1838 glDeleteShader(fs);
1839
1840 glBindAttribLocation(program, positionLoc, "vPosition");
1841 glBindAttribLocation(program, xOffsetLoc, "vOffsetX");
1842 glBindAttribLocation(program, colorLoc, "vColor");
1843
1844 glLinkProgram(program);
1845
Martin Radev67a8a012017-09-08 13:03:52 +03001846 drawQuadInstanced(program, "vPosition", 0.0f, 1.0f, true, 4u);
Martin Radev0abb7a22017-08-28 15:34:45 +03001847 ASSERT_GL_NO_ERROR();
1848
1849 for (int i = 0; i < kNewNumViews; ++i)
1850 {
1851 EXPECT_EQ(GLColor::red, GetViewColor(0, 0, i));
1852 EXPECT_EQ(GLColor::red, GetViewColor(1, 0, i));
1853 EXPECT_EQ(GLColor::blue, GetViewColor(2, 0, i));
1854 EXPECT_EQ(GLColor::blue, GetViewColor(3, 0, i));
1855 }
1856 }
1857}
1858
Martin Radevced5c862017-08-17 16:05:29 +03001859// Test that useProgram applies the number of views in computing the final value of the attribute
1860// divisor.
1861TEST_P(MultiviewRenderTest, DivisorUpdatedOnProgramChange)
1862{
1863 if (!requestMultiviewExtension())
1864 {
1865 return;
1866 }
1867
Geoff Lang25858162017-11-06 11:25:58 -05001868 // Test failing on P400 graphics card (anglebug.com/2228)
1869 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11() && IsNVIDIA());
1870
Martin Radevced5c862017-08-17 16:05:29 +03001871 GLVertexArray vao;
1872 glBindVertexArray(vao);
1873 GLBuffer vbo;
1874 glBindBuffer(GL_ARRAY_BUFFER, vbo);
1875 std::vector<Vector2I> windowCoordinates = {Vector2I(0, 0), Vector2I(1, 0), Vector2I(2, 0),
1876 Vector2I(3, 0)};
1877 std::vector<Vector2> vertexDataInClipSpace =
1878 ConvertPixelCoordinatesToClipSpace(windowCoordinates, 4, 1);
1879 // Fill with x positions so that the resulting clip space coordinate fails the clip test.
1880 glBufferData(GL_ARRAY_BUFFER, sizeof(Vector2) * vertexDataInClipSpace.size(),
1881 vertexDataInClipSpace.data(), GL_STATIC_DRAW);
1882 glEnableVertexAttribArray(0);
1883 glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, nullptr);
1884 glVertexAttribDivisor(0, 1);
1885 ASSERT_GL_NO_ERROR();
1886
1887 // Create a program and fbo with N views and draw N instances of a point horizontally.
1888 for (int numViews = 2; numViews <= 4; ++numViews)
1889 {
1890 createFBO(4, 1, numViews);
1891 ASSERT_GL_NO_ERROR();
1892
1893 GLuint program = CreateSimplePassthroughProgram(numViews);
1894 ASSERT_NE(program, 0u);
1895 glUseProgram(program);
1896 ASSERT_GL_NO_ERROR();
1897
1898 glDrawArraysInstanced(GL_POINTS, 0, 1, numViews);
1899
1900 for (int view = 0; view < numViews; ++view)
1901 {
1902 for (int j = 0; j < numViews; ++j)
1903 {
Martin Radev67a8a012017-09-08 13:03:52 +03001904 EXPECT_EQ(GLColor::green, GetViewColor(j, 0, view));
Martin Radevced5c862017-08-17 16:05:29 +03001905 }
1906 for (int j = numViews; j < 4; ++j)
1907 {
1908 EXPECT_EQ(GLColor::black, GetViewColor(j, 0, view));
1909 }
1910 }
1911
1912 glDeleteProgram(program);
1913 }
1914}
1915
Martin Radev72b4e1e2017-08-31 15:42:56 +03001916// The test checks that gl_ViewID_OVR is correctly propagated to the fragment shader.
1917TEST_P(MultiviewRenderTest, SelectColorBasedOnViewIDOVR)
1918{
1919 if (!requestMultiviewExtension())
1920 {
1921 return;
1922 }
1923
1924 const std::string vsSource =
1925 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001926 "#extension GL_OVR_multiview : require\n"
Martin Radev72b4e1e2017-08-31 15:42:56 +03001927 "layout(num_views = 3) in;\n"
1928 "in vec3 vPosition;\n"
1929 "void main()\n"
1930 "{\n"
1931 " gl_Position = vec4(vPosition, 1.);\n"
1932 "}\n";
1933
1934 const std::string fsSource =
1935 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03001936 "#extension GL_OVR_multiview : require\n"
Martin Radev72b4e1e2017-08-31 15:42:56 +03001937 "precision mediump float;\n"
1938 "out vec4 col;\n"
1939 "void main()\n"
1940 "{\n"
1941 " if (gl_ViewID_OVR == 0u) {\n"
1942 " col = vec4(1,0,0,1);\n"
1943 " } else if (gl_ViewID_OVR == 1u) {\n"
1944 " col = vec4(0,1,0,1);\n"
1945 " } else if (gl_ViewID_OVR == 2u) {\n"
1946 " col = vec4(0,0,1,1);\n"
1947 " } else {\n"
1948 " col = vec4(0,0,0,0);\n"
1949 " }\n"
1950 "}\n";
1951
1952 createFBO(1, 1, 3);
1953 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev72b4e1e2017-08-31 15:42:56 +03001954
1955 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
1956 ASSERT_GL_NO_ERROR();
1957
1958 EXPECT_EQ(GLColor::red, GetViewColor(0, 0, 0));
1959 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
1960 EXPECT_EQ(GLColor::blue, GetViewColor(0, 0, 2));
1961}
1962
1963// The test checks that the inactive layers of a 2D texture array are not written to by a
1964// multi-view program.
1965TEST_P(MultiviewLayeredRenderTest, RenderToSubrageOfLayers)
1966{
1967 if (!requestMultiviewExtension())
1968 {
1969 return;
1970 }
1971
1972 const std::string vsSource =
1973 "#version 300 es\n"
1974 "#extension GL_OVR_multiview : require\n"
1975 "layout(num_views = 2) in;\n"
1976 "in vec3 vPosition;\n"
1977 "void main()\n"
1978 "{\n"
1979 " gl_Position = vec4(vPosition, 1.);\n"
1980 "}\n";
1981
1982 const std::string fsSource =
1983 "#version 300 es\n"
1984 "#extension GL_OVR_multiview : require\n"
1985 "precision mediump float;\n"
1986 "out vec4 col;\n"
1987 "void main()\n"
1988 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03001989 " col = vec4(0,1,0,1);\n"
Martin Radev72b4e1e2017-08-31 15:42:56 +03001990 "}\n";
1991
1992 createFBO(1, 1, 2, 4, 1);
1993 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
Martin Radev72b4e1e2017-08-31 15:42:56 +03001994
1995 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
1996 ASSERT_GL_NO_ERROR();
1997
1998 EXPECT_EQ(GLColor::transparentBlack, GetViewColor(0, 0, 0));
Martin Radev67a8a012017-09-08 13:03:52 +03001999 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
2000 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 2));
Martin Radev72b4e1e2017-08-31 15:42:56 +03002001 EXPECT_EQ(GLColor::transparentBlack, GetViewColor(0, 0, 3));
2002}
2003
Martin Radevc1d4e552017-08-21 12:01:10 +03002004// The D3D11 renderer uses a GS whenever the varyings are flat interpolated which can cause
2005// potential bugs if the view is selected in the VS. The test contains a program in which the
2006// gl_InstanceID is passed as a flat varying to the fragment shader where it is used to discard the
2007// fragment if its value is negative. The gl_InstanceID should never be negative and that branch is
2008// never taken. One quad is drawn and the color is selected based on the ViewID - red for view 0 and
2009// green for view 1.
2010TEST_P(MultiviewRenderTest, FlatInterpolation)
Martin Radev3c25ad02017-08-22 17:36:53 +03002011{
Martin Radevc1d4e552017-08-21 12:01:10 +03002012 if (!requestMultiviewExtension())
2013 {
2014 return;
2015 }
2016
Geoff Lang25858162017-11-06 11:25:58 -05002017 // Test failing on P400 graphics card (anglebug.com/2228)
2018 ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11() && IsNVIDIA());
2019
Yuly Novikov1de29ab2017-09-07 18:07:23 -04002020 // TODO(mradev): Find out why this fails on Win10 Intel HD 630 D3D11
2021 // (http://anglebug.com/2062)
2022 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsD3D11());
2023
Martin Radevc1d4e552017-08-21 12:01:10 +03002024 const std::string vsSource =
2025 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03002026 "#extension GL_OVR_multiview : require\n"
Martin Radevc1d4e552017-08-21 12:01:10 +03002027 "layout(num_views = 2) in;\n"
2028 "in vec3 vPosition;\n"
2029 "flat out int oInstanceID;\n"
2030 "void main()\n"
2031 "{\n"
2032 " gl_Position = vec4(vPosition, 1.);\n"
2033 " oInstanceID = gl_InstanceID;\n"
2034 "}\n";
2035
2036 const std::string fsSource =
2037 "#version 300 es\n"
Olli Etuahoec3a9cb2017-09-07 12:18:01 +03002038 "#extension GL_OVR_multiview : require\n"
Martin Radevc1d4e552017-08-21 12:01:10 +03002039 "precision mediump float;\n"
2040 "flat in int oInstanceID;\n"
2041 "out vec4 col;\n"
2042 "void main()\n"
2043 "{\n"
2044 " if (oInstanceID < 0) {\n"
2045 " discard;\n"
2046 " }\n"
2047 " if (gl_ViewID_OVR == 0u) {\n"
2048 " col = vec4(1,0,0,1);\n"
2049 " } else {\n"
2050 " col = vec4(0,1,0,1);\n"
2051 " }\n"
2052 "}\n";
2053
2054 createFBO(1, 1, 2);
2055 ANGLE_GL_PROGRAM(program, vsSource, fsSource);
2056
2057 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
2058 ASSERT_GL_NO_ERROR();
2059
2060 EXPECT_EQ(GLColor::red, GetViewColor(0, 0, 0));
2061 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev3c25ad02017-08-22 17:36:53 +03002062}
2063
Martin Radev265a6d42017-09-12 16:51:37 +03002064// The test is added to cover a bug which resulted in the viewport/scissor and viewport offsets not
2065// being correctly applied.
2066TEST_P(MultiviewSideBySideRenderTest, ViewportOffsetsAppliedBugCoverage)
2067{
2068 if (!requestMultiviewExtension())
2069 {
2070 return;
2071 }
2072
2073 createFBO(1, 1, 2);
2074
2075 // Create multiview program.
2076 const std::string &vs =
2077 "#version 300 es\n"
2078 "#extension GL_OVR_multiview : require\n"
2079 "layout(num_views = 2) in;\n"
2080 "layout(location = 0) in vec3 vPosition;\n"
2081 "void main()\n"
2082 "{\n"
2083 " gl_Position = vec4(vPosition, 1.0);\n"
2084 "}\n";
2085
2086 const std::string &fs =
2087 "#version 300 es\n"
2088 "#extension GL_OVR_multiview : require\n"
2089 "precision mediump float;\n"
2090 "out vec4 col;\n"
2091 "void main()\n"
2092 "{\n"
Martin Radev67a8a012017-09-08 13:03:52 +03002093 " col = vec4(0,1,0,1);\n"
Martin Radev265a6d42017-09-12 16:51:37 +03002094 "}\n";
2095
2096 ANGLE_GL_PROGRAM(program, vs, fs);
2097
2098 glViewport(0, 0, 1, 1);
2099 glScissor(0, 0, 1, 1);
2100 glEnable(GL_SCISSOR_TEST);
2101 glClearColor(0, 0, 0, 1);
2102
2103 // Bind the default FBO and make sure that the state is synchronized.
2104 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
2105 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2106 ASSERT_GL_NO_ERROR();
2107
2108 // Draw and check that both views are rendered to.
2109 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
2110 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Martin Radev67a8a012017-09-08 13:03:52 +03002111
Martin Radev265a6d42017-09-12 16:51:37 +03002112 drawQuad(program, "vPosition", 0.0f, 1.0f, true);
Martin Radev67a8a012017-09-08 13:03:52 +03002113 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 0));
2114 EXPECT_EQ(GLColor::green, GetViewColor(0, 0, 1));
Martin Radev265a6d42017-09-12 16:51:37 +03002115}
2116
Martin Radevc1d4e552017-08-21 12:01:10 +03002117MultiviewImplementationParams VertexShaderOpenGL()
Martin Radev3c25ad02017-08-22 17:36:53 +03002118{
Martin Radevc1d4e552017-08-21 12:01:10 +03002119 return MultiviewImplementationParams(false, egl_platform::OPENGL());
Martin Radev3c25ad02017-08-22 17:36:53 +03002120}
2121
Martin Radevc1d4e552017-08-21 12:01:10 +03002122MultiviewImplementationParams VertexShaderD3D11()
Martin Radev3c25ad02017-08-22 17:36:53 +03002123{
Martin Radevc1d4e552017-08-21 12:01:10 +03002124 return MultiviewImplementationParams(false, egl_platform::D3D11());
Martin Radev3c25ad02017-08-22 17:36:53 +03002125}
2126
Martin Radevc1d4e552017-08-21 12:01:10 +03002127MultiviewImplementationParams GeomShaderD3D11()
Martin Radev72b4e1e2017-08-31 15:42:56 +03002128{
Martin Radevc1d4e552017-08-21 12:01:10 +03002129 return MultiviewImplementationParams(true, egl_platform::D3D11());
2130}
2131
2132MultiviewTestParams SideBySideVertexShaderOpenGL()
2133{
2134 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, VertexShaderOpenGL());
2135}
2136
2137MultiviewTestParams LayeredVertexShaderOpenGL()
2138{
2139 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE, VertexShaderOpenGL());
2140}
2141
2142MultiviewTestParams SideBySideGeomShaderD3D11()
2143{
2144 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, GeomShaderD3D11());
2145}
2146
2147MultiviewTestParams LayeredGeomShaderD3D11()
2148{
2149 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE, GeomShaderD3D11());
2150}
2151
2152MultiviewTestParams SideBySideVertexShaderD3D11()
2153{
2154 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, VertexShaderD3D11());
2155}
2156
2157MultiviewTestParams LayeredVertexShaderD3D11()
2158{
2159 return MultiviewTestParams(GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE, VertexShaderD3D11());
Martin Radev72b4e1e2017-08-31 15:42:56 +03002160}
2161
Martin Radev8f276e22017-05-30 12:05:52 +03002162ANGLE_INSTANTIATE_TEST(MultiviewDrawValidationTest, ES31_OPENGL());
Martin Radevced5c862017-08-17 16:05:29 +03002163ANGLE_INSTANTIATE_TEST(MultiviewRenderDualViewTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002164 SideBySideVertexShaderOpenGL(),
2165 LayeredVertexShaderOpenGL(),
2166 SideBySideGeomShaderD3D11(),
2167 SideBySideVertexShaderD3D11(),
2168 LayeredGeomShaderD3D11(),
2169 LayeredVertexShaderD3D11());
Martin Radev72b4e1e2017-08-31 15:42:56 +03002170ANGLE_INSTANTIATE_TEST(MultiviewRenderTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002171 SideBySideVertexShaderOpenGL(),
2172 LayeredVertexShaderOpenGL(),
2173 SideBySideGeomShaderD3D11(),
2174 SideBySideVertexShaderD3D11(),
2175 LayeredGeomShaderD3D11(),
2176 LayeredVertexShaderD3D11());
Martin Radevced5c862017-08-17 16:05:29 +03002177ANGLE_INSTANTIATE_TEST(MultiviewOcclusionQueryTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002178 SideBySideVertexShaderOpenGL(),
2179 LayeredVertexShaderOpenGL(),
2180 SideBySideGeomShaderD3D11(),
2181 SideBySideVertexShaderD3D11(),
2182 LayeredGeomShaderD3D11(),
2183 LayeredVertexShaderD3D11());
Martin Radev72b4e1e2017-08-31 15:42:56 +03002184ANGLE_INSTANTIATE_TEST(MultiviewProgramGenerationTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002185 SideBySideVertexShaderOpenGL(),
2186 LayeredVertexShaderOpenGL(),
2187 SideBySideGeomShaderD3D11(),
2188 SideBySideVertexShaderD3D11(),
2189 LayeredGeomShaderD3D11(),
2190 LayeredVertexShaderD3D11());
Martin Radevced5c862017-08-17 16:05:29 +03002191ANGLE_INSTANTIATE_TEST(MultiviewRenderPrimitiveTest,
Martin Radevc1d4e552017-08-21 12:01:10 +03002192 SideBySideVertexShaderOpenGL(),
2193 LayeredVertexShaderOpenGL(),
2194 SideBySideGeomShaderD3D11(),
2195 SideBySideVertexShaderD3D11(),
2196 LayeredGeomShaderD3D11(),
2197 LayeredVertexShaderD3D11());
2198ANGLE_INSTANTIATE_TEST(MultiviewSideBySideRenderTest, VertexShaderOpenGL(), GeomShaderD3D11());
2199ANGLE_INSTANTIATE_TEST(MultiviewLayeredRenderTest, VertexShaderOpenGL(), GeomShaderD3D11());