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 | { |
| 17 | |
| 18 | // Creates a simple program that passes through two-dimensional vertices and renders green |
| 19 | // fragments. |
| 20 | GLuint CreateSimplePassthroughProgram(int numViews); |
| 21 | |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 22 | // Create a set of textures to use for multiview rendering. If multiviewLayout is |
| 23 | // GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, then 2D textures are created. If multiviewLayout is |
| 24 | // GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE, then 2D texture arrays are created. Texture ids should be |
| 25 | // 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] | 26 | // If samples is 0, then non-multisampled textures are created. Otherwise multisampled textures are |
| 27 | // created with the requested sample count. |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 28 | void CreateMultiviewBackingTextures(GLenum multiviewLayout, |
Olli Etuaho | 2c8f084 | 2018-09-12 14:44:55 +0300 | [diff] [blame] | 29 | int samples, |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 30 | int viewWidth, |
| 31 | int height, |
| 32 | int numLayers, |
| 33 | std::vector<GLuint> colorTextures, |
| 34 | GLuint depthTexture, |
| 35 | GLuint depthStencilTexture); |
| 36 | void CreateMultiviewBackingTextures(GLenum multiviewLayout, |
Olli Etuaho | 2c8f084 | 2018-09-12 14:44:55 +0300 | [diff] [blame] | 37 | int samples, |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 38 | int viewWidth, |
| 39 | int height, |
| 40 | int numLayers, |
| 41 | GLuint colorTexture, |
| 42 | GLuint depthTexture, |
| 43 | GLuint depthStencilTexture); |
| 44 | |
| 45 | // Attach multiview textures to the framebuffer denoted by target. If there are multiple color |
| 46 | // textures they get attached to different color attachments starting from 0. If multiviewLayout is |
| 47 | // GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, then the viewport offsets are set so that the views |
| 48 | // are tightly packed inside the attachments. |
| 49 | void AttachMultiviewTextures(GLenum target, |
| 50 | GLenum multiviewLayout, |
| 51 | int viewWidth, |
| 52 | int numViews, |
| 53 | int baseViewIndex, |
| 54 | std::vector<GLuint> colorTextures, |
| 55 | GLuint depthTexture, |
| 56 | GLuint depthStencilTexture); |
| 57 | void AttachMultiviewTextures(GLenum target, |
| 58 | GLenum multiviewLayout, |
| 59 | int viewWidth, |
| 60 | int numViews, |
| 61 | int baseViewIndex, |
| 62 | GLuint colorTexture, |
| 63 | GLuint depthTexture, |
| 64 | GLuint depthStencilTexture); |
| 65 | |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 66 | struct MultiviewImplementationParams : public PlatformParameters |
| 67 | { |
| 68 | MultiviewImplementationParams(GLint majorVersion, |
| 69 | GLint minorVersion, |
| 70 | bool forceUseGeometryShaderOnD3D, |
| 71 | const EGLPlatformParameters &eglPlatformParameters) |
| 72 | : PlatformParameters(majorVersion, minorVersion, eglPlatformParameters), |
| 73 | mForceUseGeometryShaderOnD3D(forceUseGeometryShaderOnD3D) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame^] | 74 | {} |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 75 | bool mForceUseGeometryShaderOnD3D; |
| 76 | }; |
| 77 | std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams ¶ms); |
| 78 | |
| 79 | MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion, GLint minorVersion); |
| 80 | MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion, GLint minorVersion); |
| 81 | MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion, GLint minorVersion); |
| 82 | |
| 83 | class MultiviewTestBase : public ANGLETestBase |
| 84 | { |
| 85 | protected: |
| 86 | MultiviewTestBase(const PlatformParameters ¶ms) : ANGLETestBase(params) |
| 87 | { |
| 88 | setWindowWidth(128); |
| 89 | setWindowHeight(128); |
| 90 | setWebGLCompatibilityEnabled(true); |
| 91 | } |
| 92 | virtual ~MultiviewTestBase() {} |
| 93 | |
| 94 | void MultiviewTestBaseSetUp() |
| 95 | { |
| 96 | ANGLETestBase::ANGLETestSetUp(); |
| 97 | |
| 98 | glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>( |
| 99 | eglGetProcAddress("glRequestExtensionANGLE")); |
| 100 | } |
| 101 | |
| 102 | void MultiviewTestBaseTearDown() { ANGLETestBase::ANGLETestTearDown(); } |
| 103 | |
| 104 | // Requests the ANGLE_multiview extension and returns true if the operation succeeds. |
Olli Etuaho | 2c8f084 | 2018-09-12 14:44:55 +0300 | [diff] [blame] | 105 | bool requestMultiviewExtension(bool requireMultiviewMultisample) |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 106 | { |
| 107 | if (extensionRequestable("GL_ANGLE_multiview")) |
| 108 | { |
| 109 | glRequestExtensionANGLE("GL_ANGLE_multiview"); |
| 110 | } |
| 111 | |
| 112 | if (!extensionEnabled("GL_ANGLE_multiview")) |
| 113 | { |
| 114 | std::cout << "Test skipped due to missing GL_ANGLE_multiview." << std::endl; |
| 115 | return false; |
| 116 | } |
Olli Etuaho | 2c8f084 | 2018-09-12 14:44:55 +0300 | [diff] [blame] | 117 | |
| 118 | if (requireMultiviewMultisample) |
| 119 | { |
| 120 | if (extensionRequestable("GL_OES_texture_storage_multisample_2d_array")) |
| 121 | { |
| 122 | glRequestExtensionANGLE("GL_OES_texture_storage_multisample_2d_array"); |
| 123 | } |
| 124 | if (extensionRequestable("GL_ANGLE_multiview_multisample")) |
| 125 | { |
| 126 | glRequestExtensionANGLE("GL_ANGLE_multiview_multisample"); |
| 127 | } |
| 128 | |
| 129 | if (!extensionEnabled("GL_ANGLE_multiview_multisample")) |
| 130 | { |
| 131 | std::cout << "Test skipped due to missing GL_ANGLE_multiview_multisample." |
| 132 | << std::endl; |
| 133 | return false; |
| 134 | } |
| 135 | } |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 136 | return true; |
| 137 | } |
| 138 | |
Olli Etuaho | 2c8f084 | 2018-09-12 14:44:55 +0300 | [diff] [blame] | 139 | bool requestMultiviewExtension() { return requestMultiviewExtension(false); } |
| 140 | |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 141 | PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr; |
| 142 | }; |
| 143 | |
| 144 | // Base class for multiview tests that don't need specific helper functions. |
| 145 | class MultiviewTest : public MultiviewTestBase, |
| 146 | public ::testing::TestWithParam<MultiviewImplementationParams> |
| 147 | { |
| 148 | protected: |
| 149 | MultiviewTest() : MultiviewTestBase(GetParam()) {} |
| 150 | void SetUp() override { MultiviewTestBase::MultiviewTestBaseSetUp(); } |
| 151 | void TearDown() override { MultiviewTestBase::MultiviewTestBaseTearDown(); } |
| 152 | |
| 153 | void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) final; |
| 154 | }; |
| 155 | |
| 156 | } // namespace angle |
| 157 | |
| 158 | #endif // ANGLE_TESTS_TESTUTILS_MULTIVIEWTEST_H_ |