Commit f0d3b901 by Brandon Jones Committed by Commit Bot

Enable Multisample Sources in copyImageInternal For D3D11

This enables the copyTexImage2D and copyTexSubImage2D to handle multisampled source through through the blit path. We attempt to use a cached texture as an intermediate to resolve to, or create a new texture if there's a mismatch. The resolved texture is sent through blit11::copyTexture as normal. BUG:angleproject:2316 Change-Id: Ie3490b45b1a368300ee13fe5a0b35dc3920364ff Reviewed-on: https://chromium-review.googlesource.com/911889Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 560bfbcb
......@@ -2378,9 +2378,6 @@ gl::Error Renderer11::copyImageInternal(const gl::Context *context,
ANGLE_TRY(colorAttachment->getRenderTarget(context, &sourceRenderTarget));
ASSERT(sourceRenderTarget);
const d3d11::SharedSRV &source = sourceRenderTarget->getBlitShaderResourceView();
ASSERT(source.valid());
const d3d11::RenderTargetView &dest =
GetAs<RenderTarget11>(destRenderTarget)->getRenderTargetView();
ASSERT(dest.valid());
......@@ -2401,6 +2398,36 @@ gl::Error Renderer11::copyImageInternal(const gl::Context *context,
// Use nearest filtering because source and destination are the same size for the direct copy.
// Convert to the unsized format before calling copyTexture.
GLenum sourceFormat = colorAttachment->getFormat().info->format;
if (sourceRenderTarget->getTexture().is2D() && sourceRenderTarget->isMultisampled())
{
TextureHelper11 tex;
ANGLE_TRY_RESULT(
resolveMultisampledTexture(context, sourceRenderTarget, colorAttachment->getDepthSize(),
colorAttachment->getStencilSize()),
tex);
D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc;
viewDesc.Format = sourceRenderTarget->getFormatSet().srvFormat;
viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
viewDesc.Texture2D.MipLevels = 1;
viewDesc.Texture2D.MostDetailedMip = 0;
d3d11::SharedSRV readSRV;
ANGLE_TRY(allocateResource(viewDesc, tex.get(), &readSRV));
ASSERT(readSRV.valid());
ANGLE_TRY(mBlit->copyTexture(context, readSRV, sourceArea, sourceSize, sourceFormat, dest,
destArea, destSize, nullptr, gl::GetUnsizedFormat(destFormat),
GL_NEAREST, false, false, false));
return gl::NoError();
}
ASSERT(!sourceRenderTarget->isMultisampled());
const d3d11::SharedSRV &source = sourceRenderTarget->getBlitShaderResourceView();
ASSERT(source.valid());
ANGLE_TRY(mBlit->copyTexture(context, source, sourceArea, sourceSize, sourceFormat, dest,
destArea, destSize, nullptr, gl::GetUnsizedFormat(destFormat),
GL_NEAREST, false, false, false));
......
......@@ -1117,6 +1117,90 @@ TEST_P(D3DTextureTestMS, DepthStencil)
eglDestroySurface(display, pbuffer);
}
// Test copyTexImage2D with a multisampled resource
TEST_P(D3DTextureTestMS, CopyTexImage2DTest)
{
EGLWindow *window = getEGLWindow();
EGLDisplay display = window->getDisplay();
constexpr size_t bufferSize = 32;
EGLSurface pbuffer = createPBuffer(bufferSize, bufferSize, EGL_NO_TEXTURE, EGL_NO_TEXTURE, 4,
static_cast<UINT>(D3D11_STANDARD_MULTISAMPLE_PATTERN));
ASSERT_EGL_SUCCESS();
ASSERT_NE(EGL_NO_SURFACE, pbuffer);
// Apply the Pbuffer and clear it to magenta and verify
eglMakeCurrent(display, pbuffer, pbuffer, window->getContext());
ASSERT_EGL_SUCCESS();
glViewport(0, 0, static_cast<GLsizei>(bufferSize), static_cast<GLsizei>(bufferSize));
glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ASSERT_GL_NO_ERROR();
glUseProgram(mTextureProgram);
glUniform1i(mTextureUniformLocation, 0);
// Specify a 2D texture and set it to green
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
// Copy from the multisampled framebuffer to the 2D texture
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0);
// Draw a quad and verify the color is magenta, not green
drawQuad(mTextureProgram, "position", 1.0f);
EXPECT_PIXEL_COLOR_EQ(static_cast<GLint>(bufferSize) / 2, static_cast<GLint>(bufferSize) / 2,
GLColor::magenta);
ASSERT_GL_NO_ERROR();
// Make current with fixture EGL to ensure the Surface can be released immediately.
getEGLWindow()->makeCurrent();
eglDestroySurface(display, pbuffer);
}
// Test copyTexSubImage2D with a multisampled resource
TEST_P(D3DTextureTestMS, CopyTexSubImage2DTest)
{
EGLWindow *window = getEGLWindow();
EGLDisplay display = window->getDisplay();
constexpr size_t bufferSize = 32;
EGLSurface pbuffer = createPBuffer(bufferSize, bufferSize, EGL_NO_TEXTURE, EGL_NO_TEXTURE, 4,
static_cast<UINT>(D3D11_STANDARD_MULTISAMPLE_PATTERN));
ASSERT_EGL_SUCCESS();
ASSERT_NE(EGL_NO_SURFACE, pbuffer);
// Apply the Pbuffer and clear it to magenta and verify
eglMakeCurrent(display, pbuffer, pbuffer, window->getContext());
ASSERT_EGL_SUCCESS();
glViewport(0, 0, static_cast<GLsizei>(bufferSize), static_cast<GLsizei>(bufferSize));
glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ASSERT_GL_NO_ERROR();
glUseProgram(mTextureProgram);
glUniform1i(mTextureUniformLocation, 0);
// Specify a 2D texture and set it to green
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
// Copy from the multisampled framebuffer to the 2D texture
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
// Draw a quad and verify the color is magenta, not green
drawQuad(mTextureProgram, "position", 1.0f);
EXPECT_PIXEL_COLOR_EQ(static_cast<GLint>(bufferSize) / 2, static_cast<GLint>(bufferSize) / 2,
GLColor::magenta);
ASSERT_GL_NO_ERROR();
// Make current with fixture EGL to ensure the Surface can be released immediately.
getEGLWindow()->makeCurrent();
eglDestroySurface(display, pbuffer);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
ANGLE_INSTANTIATE_TEST(D3DTextureTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment