Hash :
c1af9abf
Author :
Date :
2019-08-28T14:35:32
Add support for overriding internal format for D3D11 texture EGLImages Add an optional EGL_D3D11_TEXTURE_FORMAT_ANGLE attribute that is the GL internal format to use for EGLImage being created. This will be used for RGB emulation of swap chain texture backed WebGL contexts in Chrome when they have alpha:false set. Without RGB emulation it is possible to observe side-effects of the underlying swap chain being RGBA such as reading/writing the alpha channel, BlitFramebuffer working/not working when expected, etc. Also document creating EGLImages from D3D11 textures in the existing EGL_ANGLE_d3d_texture_client_buffer extension along with RGB emulation. Bug: chromium:699566, chromium:939657 Change-Id: I4931cb7bdc46e9bc6debd56b79ecc10ea27bd78b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1777099 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Sunny Sachanandani <sunnyps@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
//
// Copyright 2019 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.
//
#include "libANGLE/renderer/d3d/d3d11/ExternalImageSiblingImpl11.h"
#include "libANGLE/Context.h"
#include "libANGLE/Error.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/d3d11/Context11.h"
#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
namespace rx
{
ExternalImageSiblingImpl11::ExternalImageSiblingImpl11(Renderer11 *renderer,
EGLClientBuffer buffer,
const egl::AttributeMap &attribs)
: mRenderer(renderer), mBuffer(buffer), mAttribs(attribs)
{}
ExternalImageSiblingImpl11::~ExternalImageSiblingImpl11() {}
egl::Error ExternalImageSiblingImpl11::initialize(const egl::Display *display)
{
const angle::Format *angleFormat = nullptr;
ANGLE_TRY(mRenderer->getD3DTextureInfo(nullptr, static_cast<IUnknown *>(mBuffer), mAttribs,
&mWidth, &mHeight, &mSamples, &mFormat, &angleFormat));
ID3D11Texture2D *texture =
d3d11::DynamicCastComObject<ID3D11Texture2D>(static_cast<IUnknown *>(mBuffer));
ASSERT(texture != nullptr);
// TextureHelper11 will release texture on destruction.
mTexture.set(texture, d3d11::Format::Get(angleFormat->glInternalFormat,
mRenderer->getRenderer11DeviceCaps()));
D3D11_TEXTURE2D_DESC textureDesc = {};
mTexture.getDesc(&textureDesc);
IDXGIResource *resource = d3d11::DynamicCastComObject<IDXGIResource>(mTexture.get());
ASSERT(resource != nullptr);
DXGI_USAGE resourceUsage = 0;
resource->GetUsage(&resourceUsage);
SafeRelease(resource);
mIsRenderable = (textureDesc.BindFlags & D3D11_BIND_RENDER_TARGET) &&
(resourceUsage & DXGI_USAGE_RENDER_TARGET_OUTPUT) &&
!(resourceUsage & DXGI_USAGE_READ_ONLY);
mIsTexturable = (textureDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE) &&
(resourceUsage & DXGI_USAGE_SHADER_INPUT);
return egl::NoError();
}
gl::Format ExternalImageSiblingImpl11::getFormat() const
{
return mFormat;
}
bool ExternalImageSiblingImpl11::isRenderable(const gl::Context *context) const
{
return mIsRenderable;
}
bool ExternalImageSiblingImpl11::isTexturable(const gl::Context *context) const
{
return mIsTexturable;
}
gl::Extents ExternalImageSiblingImpl11::getSize() const
{
return gl::Extents(mWidth, mHeight, 1);
}
size_t ExternalImageSiblingImpl11::getSamples() const
{
return mSamples;
}
angle::Result ExternalImageSiblingImpl11::getAttachmentRenderTarget(
const gl::Context *context,
GLenum binding,
const gl::ImageIndex &imageIndex,
GLsizei samples,
FramebufferAttachmentRenderTarget **rtOut)
{
ANGLE_TRY(createRenderTarget(context));
*rtOut = mRenderTarget.get();
return angle::Result::Continue;
}
angle::Result ExternalImageSiblingImpl11::initializeContents(const gl::Context *context,
const gl::ImageIndex &imageIndex)
{
UNREACHABLE();
return angle::Result::Stop;
}
angle::Result ExternalImageSiblingImpl11::createRenderTarget(const gl::Context *context)
{
if (mRenderTarget)
return angle::Result::Continue;
Context11 *context11 = GetImplAs<Context11>(context);
const d3d11::Format &formatInfo = mTexture.getFormatSet();
d3d11::RenderTargetView rtv;
if (mIsRenderable)
{
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = formatInfo.rtvFormat;
rtvDesc.ViewDimension =
mSamples == 0 ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS;
rtvDesc.Texture2D.MipSlice = 0;
ANGLE_TRY(mRenderer->allocateResource(context11, rtvDesc, mTexture.get(), &rtv));
rtv.setDebugName("getAttachmentRenderTarget.RTV");
}
d3d11::SharedSRV srv;
if (mIsTexturable)
{
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = formatInfo.srvFormat;
srvDesc.ViewDimension =
mSamples == 0 ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1;
ANGLE_TRY(mRenderer->allocateResource(context11, srvDesc, mTexture.get(), &srv));
srv.setDebugName("getAttachmentRenderTarget.SRV");
}
d3d11::SharedSRV blitSrv = srv.makeCopy();
mRenderTarget = std::make_unique<TextureRenderTarget11>(
std::move(rtv), mTexture, std::move(srv), std::move(blitSrv), mFormat.info->internalFormat,
formatInfo, mWidth, mHeight, 1, mSamples);
return angle::Result::Continue;
}
} // namespace rx