blob: 4ec40643baddb2ab437ba057a92003c00fdb55e4 [file] [log] [blame]
Olli Etuahof26b27e2018-08-17 11:01:19 +03001//
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
13namespace angle
14{
15
16GLuint 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 Etuahoa7b35c32018-08-21 16:32:24 +030043void 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
116void 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
130void 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 {
Shahbaz Youssefic4097442018-08-22 12:14:52 -0400153 GLenum attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i);
154 glFramebufferTextureMultiviewSideBySideANGLE(target, attachment, colorTextures[i],
155 0, numViews, viewportOffsets.data());
Olli Etuahoa7b35c32018-08-21 16:32:24 +0300156 }
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 {
Shahbaz Youssefic4097442018-08-22 12:14:52 -0400173 GLenum attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i);
174 glFramebufferTextureMultiviewLayeredANGLE(target, attachment, colorTextures[i], 0,
175 baseViewIndex, numViews);
Olli Etuahoa7b35c32018-08-21 16:32:24 +0300176 }
177 if (depthTexture)
178 {
179 glFramebufferTextureMultiviewLayeredANGLE(target, GL_DEPTH_ATTACHMENT, depthTexture,
180 0, baseViewIndex, numViews);
181 }
182 if (depthStencilTexture)
183 {
184 glFramebufferTextureMultiviewLayeredANGLE(target, GL_DEPTH_STENCIL_ATTACHMENT,
185 depthStencilTexture, 0, baseViewIndex,
186 numViews);
187 }
188 break;
189 default:
190 UNREACHABLE();
191 }
192}
193
194void AttachMultiviewTextures(GLenum target,
195 GLenum multiviewLayout,
196 int viewWidth,
197 int numViews,
198 int baseViewIndex,
199 GLuint colorTexture,
200 GLuint depthTexture,
201 GLuint depthStencilTexture)
202{
203 ASSERT(colorTexture != 0u);
204 std::vector<GLuint> colorTextures(1, colorTexture);
205 AttachMultiviewTextures(target, multiviewLayout, viewWidth, numViews, baseViewIndex,
206 colorTextures, depthTexture, depthStencilTexture);
207}
208
Olli Etuahof26b27e2018-08-17 11:01:19 +0300209std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams &params)
210{
211 const PlatformParameters &base = static_cast<const PlatformParameters &>(params);
212 os << base;
213 if (params.mForceUseGeometryShaderOnD3D)
214 {
215 os << "_force_geom_shader";
216 }
217 else
218 {
219 os << "_vertex_shader";
220 }
221 return os;
222}
223
224MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion, GLint minorVersion)
225{
226 return MultiviewImplementationParams(majorVersion, minorVersion, false, egl_platform::OPENGL());
227}
228
229MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion, GLint minorVersion)
230{
231 return MultiviewImplementationParams(majorVersion, minorVersion, false, egl_platform::D3D11());
232}
233
234MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion, GLint minorVersion)
235{
236 return MultiviewImplementationParams(majorVersion, minorVersion, true, egl_platform::D3D11());
237}
238
239void MultiviewTest::overrideWorkaroundsD3D(WorkaroundsD3D *workarounds)
240{
241 workarounds->selectViewInGeometryShader = GetParam().mForceUseGeometryShaderOnD3D;
242}
243
244} // namespace angle