Hash :
2c8f0845
Author :
Date :
2018-09-12T14:44:55
Add ANGLE_multiview_multisample We add a novel multiview multisampling extension that includes the requirement to explicitly resolve the multisampled framebuffer. The explicit resolve is much more straightforward to implement on top of OpenGL and D3D11 than implicit resolve found in the native extension OVR_multiview_multisampled_render_to_texture. It also has predictable performance characteristics. The extension allows multiview drawing to 2D multisample texture arrays and is now enabled on both the GL backend and the D3D11 backend. The implementation is fairly simple, as it involves just small changes in validation to allow multisampled framebuffer attachments. The multiview rendering logic is exactly the same regardless of whether multisampling is enabled. For the most part the same tests are used to test both multisampled and non-multisampled rendering. The tests will use a different framebuffer setup depending on the test param. They resolve the multisampled framebuffer to a non-multisampled framebuffer prior to any readbacks from the framebuffer. Some of the tests are adjusted so that they have the correct sub-pixel positioning of multisampled quads, so there won't be any pixels that would be just partially covered. The tests don't have any tolerance for partially covered pixels - if we find any platforms where the tests run into a sub-pixel positioning corner case, tolerance may need to be added later. BUG=angleproject:2775 TEST=angle_end2end_tests Change-Id: I590d7f300a92ea5439f2720d9db14a7976db2e1d Reviewed-on: https://chromium-review.googlesource.com/1221214 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// MultiviewTest:
// Implementation of helpers for multiview testing.
//
#include "test_utils/MultiviewTest.h"
#include "platform/WorkaroundsD3D.h"
#include "test_utils/gl_raii.h"
namespace angle
{
GLuint CreateSimplePassthroughProgram(int numViews)
{
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = " +
ToString(numViews) +
") in;\n"
"layout(location=0) in vec2 vPosition;\n"
"void main()\n"
"{\n"
" gl_PointSize = 1.;\n"
" gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n"
"}\n";
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(0,1,0,1);\n"
"}\n";
return CompileProgram(vsSource, fsSource);
}
void CreateMultiviewBackingTextures(GLenum multiviewLayout,
int samples,
int viewWidth,
int height,
int numLayers,
std::vector<GLuint> colorTextures,
GLuint depthTexture,
GLuint depthStencilTexture)
{
// The same zero data is used to initialize both color and depth/stencil textures.
std::vector<GLubyte> textureData;
textureData.resize(viewWidth * height * numLayers * 4, 0u);
// Multisampling is only supported for layered framebuffers.
ASSERT((samples == 0) || multiviewLayout == GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE);
// We can't upload data to multisample textures, so we clear them using a temporary framebuffer
// instead. The current framebuffer binding is stored so we can restore it once we're done with
// using the temporary framebuffers.
GLint restoreDrawFramebuffer;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &restoreDrawFramebuffer);
// Create color and depth textures.
switch (multiviewLayout)
{
case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE:
{
int textureWidth = viewWidth * numLayers;
for (auto colorTexture : colorTextures)
{
glBindTexture(GL_TEXTURE_2D, colorTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, textureData.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
if (depthTexture != 0)
{
glBindTexture(GL_TEXTURE_2D, depthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, textureWidth, height, 0,
GL_DEPTH_COMPONENT, GL_FLOAT, textureData.data());
}
if (depthStencilTexture != 0)
{
glBindTexture(GL_TEXTURE_2D, depthStencilTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, textureWidth, height, 0,
GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, textureData.data());
}
glBindTexture(GL_TEXTURE_2D, 0);
break;
}
case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE:
{
GLenum texTarget =
(samples > 0) ? GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES : GL_TEXTURE_2D_ARRAY;
for (auto colorTexture : colorTextures)
{
glBindTexture(texTarget, colorTexture);
if (samples > 0)
{
glTexStorage3DMultisampleOES(texTarget, samples, GL_RGBA8, viewWidth, height,
numLayers, false);
GLFramebuffer tempFbo;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, tempFbo);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
for (int layerIndex = 0; layerIndex < numLayers; ++layerIndex)
{
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
colorTexture, 0, layerIndex);
glClear(GL_COLOR_BUFFER_BIT);
}
}
else
{
glTexImage3D(texTarget, 0, GL_RGBA8, viewWidth, height, numLayers, 0, GL_RGBA,
GL_UNSIGNED_BYTE, textureData.data());
glTexParameteri(texTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(texTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
}
if (depthTexture != 0)
{
glBindTexture(texTarget, depthTexture);
if (samples > 0)
{
glTexStorage3DMultisampleOES(texTarget, samples, GL_DEPTH_COMPONENT32F,
viewWidth, height, numLayers, false);
GLFramebuffer tempFbo;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, tempFbo);
glClearDepthf(0.0f);
for (int layerIndex = 0; layerIndex < numLayers; ++layerIndex)
{
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
depthTexture, 0, layerIndex);
glClear(GL_DEPTH_BUFFER_BIT);
}
}
else
{
glTexImage3D(texTarget, 0, GL_DEPTH_COMPONENT32F, viewWidth, height, numLayers,
0, GL_DEPTH_COMPONENT, GL_FLOAT, textureData.data());
}
}
if (depthStencilTexture != 0)
{
glBindTexture(texTarget, depthStencilTexture);
if (samples > 0)
{
glTexStorage3DMultisampleOES(texTarget, samples, GL_DEPTH24_STENCIL8, viewWidth,
height, numLayers, false);
GLFramebuffer tempFbo;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, tempFbo);
glClearDepthf(0.0f);
glClearStencil(0);
for (int layerIndex = 0; layerIndex < numLayers; ++layerIndex)
{
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
depthTexture, 0, layerIndex);
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
}
else
{
glTexImage3D(texTarget, 0, GL_DEPTH24_STENCIL8, viewWidth, height, numLayers, 0,
GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, textureData.data());
}
}
glBindTexture(texTarget, 0);
break;
}
default:
UNREACHABLE();
}
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, restoreDrawFramebuffer);
}
void CreateMultiviewBackingTextures(GLenum multiviewLayout,
int samples,
int viewWidth,
int height,
int numLayers,
GLuint colorTexture,
GLuint depthTexture,
GLuint depthStencilTexture)
{
ASSERT(colorTexture != 0u);
std::vector<GLuint> colorTextures(1, colorTexture);
CreateMultiviewBackingTextures(multiviewLayout, samples, viewWidth, height, numLayers,
colorTextures, depthTexture, depthStencilTexture);
}
void AttachMultiviewTextures(GLenum target,
GLenum multiviewLayout,
int viewWidth,
int numViews,
int baseViewIndex,
std::vector<GLuint> colorTextures,
GLuint depthTexture,
GLuint depthStencilTexture)
{
ASSERT(multiviewLayout == GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE || (baseViewIndex == 0));
ASSERT(depthTexture == 0u || depthStencilTexture == 0u);
switch (multiviewLayout)
{
case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE:
{
std::vector<GLint> viewportOffsets(numViews * 2);
for (int i = 0u; i < numViews; ++i)
{
viewportOffsets[i * 2] = i * viewWidth;
viewportOffsets[i * 2 + 1] = 0;
}
for (size_t i = 0; i < colorTextures.size(); ++i)
{
GLenum attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i);
glFramebufferTextureMultiviewSideBySideANGLE(target, attachment, colorTextures[i],
0, numViews, viewportOffsets.data());
}
if (depthTexture)
{
glFramebufferTextureMultiviewSideBySideANGLE(
target, GL_DEPTH_ATTACHMENT, depthTexture, 0, numViews, viewportOffsets.data());
}
if (depthStencilTexture)
{
glFramebufferTextureMultiviewSideBySideANGLE(target, GL_DEPTH_STENCIL_ATTACHMENT,
depthStencilTexture, 0, numViews,
viewportOffsets.data());
}
break;
}
case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE:
for (size_t i = 0; i < colorTextures.size(); ++i)
{
GLenum attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i);
glFramebufferTextureMultiviewLayeredANGLE(target, attachment, colorTextures[i], 0,
baseViewIndex, numViews);
}
if (depthTexture)
{
glFramebufferTextureMultiviewLayeredANGLE(target, GL_DEPTH_ATTACHMENT, depthTexture,
0, baseViewIndex, numViews);
}
if (depthStencilTexture)
{
glFramebufferTextureMultiviewLayeredANGLE(target, GL_DEPTH_STENCIL_ATTACHMENT,
depthStencilTexture, 0, baseViewIndex,
numViews);
}
break;
default:
UNREACHABLE();
}
}
void AttachMultiviewTextures(GLenum target,
GLenum multiviewLayout,
int viewWidth,
int numViews,
int baseViewIndex,
GLuint colorTexture,
GLuint depthTexture,
GLuint depthStencilTexture)
{
ASSERT(colorTexture != 0u);
std::vector<GLuint> colorTextures(1, colorTexture);
AttachMultiviewTextures(target, multiviewLayout, viewWidth, numViews, baseViewIndex,
colorTextures, depthTexture, depthStencilTexture);
}
std::ostream &operator<<(std::ostream &os, const MultiviewImplementationParams ¶ms)
{
const PlatformParameters &base = static_cast<const PlatformParameters &>(params);
os << base;
if (params.mForceUseGeometryShaderOnD3D)
{
os << "_force_geom_shader";
}
else
{
os << "_vertex_shader";
}
return os;
}
MultiviewImplementationParams VertexShaderOpenGL(GLint majorVersion, GLint minorVersion)
{
return MultiviewImplementationParams(majorVersion, minorVersion, false, egl_platform::OPENGL());
}
MultiviewImplementationParams VertexShaderD3D11(GLint majorVersion, GLint minorVersion)
{
return MultiviewImplementationParams(majorVersion, minorVersion, false, egl_platform::D3D11());
}
MultiviewImplementationParams GeomShaderD3D11(GLint majorVersion, GLint minorVersion)
{
return MultiviewImplementationParams(majorVersion, minorVersion, true, egl_platform::D3D11());
}
void MultiviewTest::overrideWorkaroundsD3D(WorkaroundsD3D *workarounds)
{
workarounds->selectViewInGeometryShader = GetParam().mForceUseGeometryShaderOnD3D;
}
} // namespace angle