Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2018 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 | // MultiviewTest: |
| 7 | // Implementation of helpers for multiview testing. |
| 8 | // |
| 9 | |
| 10 | #ifndef ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_ |
| 11 | #define ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_ |
| 12 | |
| 13 | #include "test_utils/ANGLETest.h" |
| 14 | |
| 15 | namespace angle |
| 16 | { |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame^] | 17 | enum ExtensionName |
| 18 | { |
| 19 | multiview, |
| 20 | multiview2 |
| 21 | }; |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 22 | |
| 23 | // Creates a simple program that passes through two-dimensional vertices and renders green |
| 24 | // fragments. |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame^] | 25 | GLuint CreateSimplePassthroughProgram(int numViews, ExtensionName multiviewExtension); |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 26 | |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 27 | // Create a 2D texture array to use for multiview rendering. Texture ids should be |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 28 | // created beforehand. If depthTexture or stencilTexture is 0, it will not be initialized. |
Olli Etuaho | 2c8f084 | 2018-09-12 14:44:55 +0300 | [diff] [blame] | 29 | // If samples is 0, then non-multisampled textures are created. Otherwise multisampled textures are |
| 30 | // created with the requested sample count. |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 31 | void CreateMultiviewBackingTextures(int samples, |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 32 | int viewWidth, |
| 33 | int height, |
| 34 | int numLayers, |
| 35 | std::vector<GLuint> colorTextures, |
| 36 | GLuint depthTexture, |
| 37 | GLuint depthStencilTexture); |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 38 | void CreateMultiviewBackingTextures(int samples, |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 39 | int viewWidth, |
| 40 | int height, |
| 41 | int numLayers, |
| 42 | GLuint colorTexture, |
| 43 | GLuint depthTexture, |
| 44 | GLuint depthStencilTexture); |
| 45 | |
| 46 | // Attach multiview textures to the framebuffer denoted by target. If there are multiple color |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 47 | // textures they get attached to different color attachments starting from 0. |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 48 | void AttachMultiviewTextures(GLenum target, |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 49 | int viewWidth, |
| 50 | int numViews, |
| 51 | int baseViewIndex, |
| 52 | std::vector<GLuint> colorTextures, |
| 53 | GLuint depthTexture, |
| 54 | GLuint depthStencilTexture); |
| 55 | void AttachMultiviewTextures(GLenum target, |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 56 | int viewWidth, |
| 57 | int numViews, |
| 58 | int baseViewIndex, |
| 59 | GLuint colorTexture, |
| 60 | GLuint depthTexture, |
| 61 | GLuint depthStencilTexture); |
| 62 | |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 63 | struct MultiviewImplementationParams : public PlatformParameters |
| 64 | { |
| 65 | MultiviewImplementationParams(GLint majorVersion, |
| 66 | GLint minorVersion, |
| 67 | bool forceUseGeometryShaderOnD3D, |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame^] | 68 | const EGLPlatformParameters &eglPlatformParameters, |
| 69 | ExtensionName multiviewExtension) |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 70 | : PlatformParameters(majorVersion, minorVersion, eglPlatformParameters), |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame^] | 71 | mForceUseGeometryShaderOnD3D(forceUseGeometryShaderOnD3D), |
| 72 | mMultiviewExtension(multiviewExtension) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 73 | {} |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 74 | bool mForceUseGeometryShaderOnD3D; |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame^] | 75 | ExtensionName mMultiviewExtension; |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 76 | }; |
| 77 | std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams ¶ms); |
| 78 | |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame^] | 79 | MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion, |
| 80 | GLint minorVersion, |
| 81 | ExtensionName multiviewExtension); |
| 82 | MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion, |
| 83 | GLint minorVersion, |
| 84 | ExtensionName multiviewExtension); |
| 85 | MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion, |
| 86 | GLint minorVersion, |
| 87 | ExtensionName multiviewExtension); |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 88 | |
| 89 | class MultiviewTestBase : public ANGLETestBase |
| 90 | { |
| 91 | protected: |
| 92 | MultiviewTestBase(const PlatformParameters ¶ms) : ANGLETestBase(params) |
| 93 | { |
| 94 | setWindowWidth(128); |
| 95 | setWindowHeight(128); |
| 96 | setWebGLCompatibilityEnabled(true); |
| 97 | } |
| 98 | virtual ~MultiviewTestBase() {} |
| 99 | |
| 100 | void MultiviewTestBaseSetUp() |
| 101 | { |
| 102 | ANGLETestBase::ANGLETestSetUp(); |
| 103 | |
| 104 | glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>( |
| 105 | eglGetProcAddress("glRequestExtensionANGLE")); |
| 106 | } |
| 107 | |
| 108 | void MultiviewTestBaseTearDown() { ANGLETestBase::ANGLETestTearDown(); } |
| 109 | |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 110 | PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr; |
| 111 | }; |
| 112 | |
| 113 | // Base class for multiview tests that don't need specific helper functions. |
| 114 | class MultiviewTest : public MultiviewTestBase, |
| 115 | public ::testing::TestWithParam<MultiviewImplementationParams> |
| 116 | { |
| 117 | protected: |
| 118 | MultiviewTest() : MultiviewTestBase(GetParam()) {} |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 119 | |
| 120 | void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) final; |
Jamie Madill | 5cbaa3f | 2019-05-07 15:49:22 -0400 | [diff] [blame] | 121 | |
| 122 | virtual void testSetUp() {} |
| 123 | virtual void testTearDown() {} |
| 124 | |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame^] | 125 | // Requests the OVR_multiview(2) extension and returns true if the operation succeeds. |
| 126 | bool requestMultiviewExtension(bool requireMultiviewMultisample) |
| 127 | { |
| 128 | if (!EnsureGLExtensionEnabled(extensionName())) |
| 129 | { |
| 130 | std::cout << "Test skipped due to missing " << extensionName() << "." << std::endl; |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | if (requireMultiviewMultisample) |
| 135 | { |
| 136 | if (!EnsureGLExtensionEnabled("GL_OES_texture_storage_multisample_2d_array")) |
| 137 | { |
| 138 | std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample." |
| 139 | << std::endl; |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | if (!EnsureGLExtensionEnabled("GL_ANGLE_multiview_multisample")) |
| 144 | { |
| 145 | std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample." |
| 146 | << std::endl; |
| 147 | return false; |
| 148 | } |
| 149 | } |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | bool requestMultiviewExtension() { return requestMultiviewExtension(false); } |
| 154 | |
| 155 | std::string extensionName() |
| 156 | { |
| 157 | switch (GetParam().mMultiviewExtension) |
| 158 | { |
| 159 | case multiview: |
| 160 | return "GL_OVR_multiview"; |
| 161 | case multiview2: |
| 162 | return "GL_OVR_multiview2"; |
| 163 | default: |
| 164 | // Ignore unknown. |
| 165 | return ""; |
| 166 | } |
| 167 | } |
| 168 | |
Jamie Madill | 5cbaa3f | 2019-05-07 15:49:22 -0400 | [diff] [blame] | 169 | private: |
| 170 | void SetUp() override |
| 171 | { |
| 172 | MultiviewTestBase::MultiviewTestBaseSetUp(); |
| 173 | testSetUp(); |
| 174 | } |
| 175 | void TearDown() override |
| 176 | { |
| 177 | testTearDown(); |
| 178 | MultiviewTestBase::MultiviewTestBaseTearDown(); |
| 179 | } |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | } // namespace angle |
| 183 | |
Mingyu Hu | ebab670 | 2019-04-19 14:36:45 -0700 | [diff] [blame^] | 184 | #endif // ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_ |