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 | #include "test_utils/MultiviewTest.h" |
| 11 | #include "platform/WorkaroundsD3D.h" |
| 12 | |
| 13 | namespace angle |
| 14 | { |
| 15 | |
| 16 | GLuint CreateSimplePassthroughProgram(int numViews) |
| 17 | { |
| 18 | const std::string vsSource = |
| 19 | "#version 300 es\n" |
| 20 | "#extension GL_OVR_multiview : require\n" |
| 21 | "layout(num_views = " + |
| 22 | ToString(numViews) + |
| 23 | ") in;\n" |
| 24 | "layout(location=0) in vec2 vPosition;\n" |
| 25 | "void main()\n" |
| 26 | "{\n" |
| 27 | " gl_PointSize = 1.;\n" |
| 28 | " gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n" |
| 29 | "}\n"; |
| 30 | |
| 31 | const std::string fsSource = |
| 32 | "#version 300 es\n" |
| 33 | "#extension GL_OVR_multiview : require\n" |
| 34 | "precision mediump float;\n" |
| 35 | "out vec4 col;\n" |
| 36 | "void main()\n" |
| 37 | "{\n" |
| 38 | " col = vec4(0,1,0,1);\n" |
| 39 | "}\n"; |
| 40 | return CompileProgram(vsSource, fsSource); |
| 41 | } |
| 42 | |
Olli Etuaho | a7b35c3 | 2018-08-21 16:32:24 +0300 | [diff] [blame] | 43 | void CreateMultiviewBackingTextures(GLenum multiviewLayout, |
| 44 | int viewWidth, |
| 45 | int height, |
| 46 | int numLayers, |
| 47 | std::vector<GLuint> colorTextures, |
| 48 | GLuint depthTexture, |
| 49 | GLuint depthStencilTexture) |
| 50 | { |
| 51 | // The same zero data is used to initialize both color and depth/stencil textures. |
| 52 | std::vector<GLubyte> textureData; |
| 53 | textureData.resize(viewWidth * height * numLayers * 4, 0u); |
| 54 | |
| 55 | // Create color and depth textures. |
| 56 | switch (multiviewLayout) |
| 57 | { |
| 58 | case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE: |
| 59 | { |
| 60 | int textureWidth = viewWidth * numLayers; |
| 61 | for (auto colorTexture : colorTextures) |
| 62 | { |
| 63 | glBindTexture(GL_TEXTURE_2D, colorTexture); |
| 64 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, height, 0, GL_RGBA, |
| 65 | GL_UNSIGNED_BYTE, textureData.data()); |
| 66 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 67 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 68 | } |
| 69 | |
| 70 | if (depthTexture != 0) |
| 71 | { |
| 72 | glBindTexture(GL_TEXTURE_2D, depthTexture); |
| 73 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, textureWidth, height, 0, |
| 74 | GL_DEPTH_COMPONENT, GL_FLOAT, textureData.data()); |
| 75 | } |
| 76 | if (depthStencilTexture != 0) |
| 77 | { |
| 78 | glBindTexture(GL_TEXTURE_2D, depthStencilTexture); |
| 79 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, textureWidth, height, 0, |
| 80 | GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, textureData.data()); |
| 81 | } |
| 82 | glBindTexture(GL_TEXTURE_2D, 0); |
| 83 | break; |
| 84 | } |
| 85 | case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE: |
| 86 | for (auto colorTexture : colorTextures) |
| 87 | { |
| 88 | glBindTexture(GL_TEXTURE_2D_ARRAY, colorTexture); |
| 89 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, viewWidth, height, numLayers, 0, |
| 90 | GL_RGBA, GL_UNSIGNED_BYTE, textureData.data()); |
| 91 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 92 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 93 | } |
| 94 | |
| 95 | if (depthTexture != 0) |
| 96 | { |
| 97 | glBindTexture(GL_TEXTURE_2D_ARRAY, depthTexture); |
| 98 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT32F, viewWidth, height, |
| 99 | numLayers, 0, GL_DEPTH_COMPONENT, GL_FLOAT, textureData.data()); |
| 100 | } |
| 101 | if (depthStencilTexture != 0) |
| 102 | { |
| 103 | glBindTexture(GL_TEXTURE_2D_ARRAY, depthStencilTexture); |
| 104 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH24_STENCIL8, viewWidth, height, |
| 105 | numLayers, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, |
| 106 | textureData.data()); |
| 107 | } |
| 108 | glBindTexture(GL_TEXTURE_2D_ARRAY, 0); |
| 109 | break; |
| 110 | default: |
| 111 | UNREACHABLE(); |
| 112 | } |
| 113 | ASSERT_GL_NO_ERROR(); |
| 114 | } |
| 115 | |
| 116 | void CreateMultiviewBackingTextures(GLenum multiviewLayout, |
| 117 | int viewWidth, |
| 118 | int height, |
| 119 | int numLayers, |
| 120 | GLuint colorTexture, |
| 121 | GLuint depthTexture, |
| 122 | GLuint depthStencilTexture) |
| 123 | { |
| 124 | ASSERT(colorTexture != 0u); |
| 125 | std::vector<GLuint> colorTextures(1, colorTexture); |
| 126 | CreateMultiviewBackingTextures(multiviewLayout, viewWidth, height, numLayers, colorTextures, |
| 127 | depthTexture, depthStencilTexture); |
| 128 | } |
| 129 | |
| 130 | void AttachMultiviewTextures(GLenum target, |
| 131 | GLenum multiviewLayout, |
| 132 | int viewWidth, |
| 133 | int numViews, |
| 134 | int baseViewIndex, |
| 135 | std::vector<GLuint> colorTextures, |
| 136 | GLuint depthTexture, |
| 137 | GLuint depthStencilTexture) |
| 138 | { |
| 139 | ASSERT(multiviewLayout == GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE || (baseViewIndex == 0)); |
| 140 | ASSERT(depthTexture == 0u || depthStencilTexture == 0u); |
| 141 | switch (multiviewLayout) |
| 142 | { |
| 143 | case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE: |
| 144 | { |
| 145 | std::vector<GLint> viewportOffsets(numViews * 2); |
| 146 | for (int i = 0u; i < numViews; ++i) |
| 147 | { |
| 148 | viewportOffsets[i * 2] = i * viewWidth; |
| 149 | viewportOffsets[i * 2 + 1] = 0; |
| 150 | } |
| 151 | for (size_t i = 0; i < colorTextures.size(); ++i) |
| 152 | { |
| 153 | glFramebufferTextureMultiviewSideBySideANGLE(target, GL_COLOR_ATTACHMENT0 + i, |
| 154 | colorTextures[i], 0, numViews, |
| 155 | viewportOffsets.data()); |
| 156 | } |
| 157 | if (depthTexture) |
| 158 | { |
| 159 | glFramebufferTextureMultiviewSideBySideANGLE( |
| 160 | target, GL_DEPTH_ATTACHMENT, depthTexture, 0, numViews, viewportOffsets.data()); |
| 161 | } |
| 162 | if (depthStencilTexture) |
| 163 | { |
| 164 | glFramebufferTextureMultiviewSideBySideANGLE(target, GL_DEPTH_STENCIL_ATTACHMENT, |
| 165 | depthStencilTexture, 0, numViews, |
| 166 | viewportOffsets.data()); |
| 167 | } |
| 168 | break; |
| 169 | } |
| 170 | case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE: |
| 171 | for (size_t i = 0; i < colorTextures.size(); ++i) |
| 172 | { |
| 173 | glFramebufferTextureMultiviewLayeredANGLE( |
| 174 | target, GL_COLOR_ATTACHMENT0 + i, colorTextures[i], 0, baseViewIndex, numViews); |
| 175 | } |
| 176 | if (depthTexture) |
| 177 | { |
| 178 | glFramebufferTextureMultiviewLayeredANGLE(target, GL_DEPTH_ATTACHMENT, depthTexture, |
| 179 | 0, baseViewIndex, numViews); |
| 180 | } |
| 181 | if (depthStencilTexture) |
| 182 | { |
| 183 | glFramebufferTextureMultiviewLayeredANGLE(target, GL_DEPTH_STENCIL_ATTACHMENT, |
| 184 | depthStencilTexture, 0, baseViewIndex, |
| 185 | numViews); |
| 186 | } |
| 187 | break; |
| 188 | default: |
| 189 | UNREACHABLE(); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | void AttachMultiviewTextures(GLenum target, |
| 194 | GLenum multiviewLayout, |
| 195 | int viewWidth, |
| 196 | int numViews, |
| 197 | int baseViewIndex, |
| 198 | GLuint colorTexture, |
| 199 | GLuint depthTexture, |
| 200 | GLuint depthStencilTexture) |
| 201 | { |
| 202 | ASSERT(colorTexture != 0u); |
| 203 | std::vector<GLuint> colorTextures(1, colorTexture); |
| 204 | AttachMultiviewTextures(target, multiviewLayout, viewWidth, numViews, baseViewIndex, |
| 205 | colorTextures, depthTexture, depthStencilTexture); |
| 206 | } |
| 207 | |
Olli Etuaho | f26b27e | 2018-08-17 11:01:19 +0300 | [diff] [blame] | 208 | std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams ¶ms) |
| 209 | { |
| 210 | const PlatformParameters &base = static_cast<const PlatformParameters &>(params); |
| 211 | os << base; |
| 212 | if (params.mForceUseGeometryShaderOnD3D) |
| 213 | { |
| 214 | os << "_force_geom_shader"; |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | os << "_vertex_shader"; |
| 219 | } |
| 220 | return os; |
| 221 | } |
| 222 | |
| 223 | MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion, GLint minorVersion) |
| 224 | { |
| 225 | return MultiviewImplementationParams(majorVersion, minorVersion, false, egl_platform::OPENGL()); |
| 226 | } |
| 227 | |
| 228 | MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion, GLint minorVersion) |
| 229 | { |
| 230 | return MultiviewImplementationParams(majorVersion, minorVersion, false, egl_platform::D3D11()); |
| 231 | } |
| 232 | |
| 233 | MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion, GLint minorVersion) |
| 234 | { |
| 235 | return MultiviewImplementationParams(majorVersion, minorVersion, true, egl_platform::D3D11()); |
| 236 | } |
| 237 | |
| 238 | void MultiviewTest::overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) |
| 239 | { |
| 240 | workarounds->selectViewInGeometryShader = GetParam().mForceUseGeometryShaderOnD3D; |
| 241 | } |
| 242 | |
| 243 | } // namespace angle |