Commit 2add15ef by John Bauman Committed by Commit Bot

Fix creating pbuffers on IDCompositionSurfaces.

IDCompositionSurfaces can't be bound as SRVs, so don't try to create SRVs for them. Also, OMSetRenderTargets must have NumViews <= 1 if an IDCompositionSurface is being bound. MRT doesn't work with them, and just having the remaining elements be null isn't enough. BUG=678800 Change-Id: I76b28de7cbda772bff286eae2b83b70c9dcd2232 Reviewed-on: https://chromium-review.googlesource.com/431134Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: John Bauman <jbauman@chromium.org>
parent b8353b01
...@@ -1016,6 +1016,7 @@ gl::Error StateManager11::syncFramebuffer(gl::Framebuffer *framebuffer) ...@@ -1016,6 +1016,7 @@ gl::Error StateManager11::syncFramebuffer(gl::Framebuffer *framebuffer)
size_t appliedRTIndex = 0; size_t appliedRTIndex = 0;
bool skipInactiveRTs = mRenderer->getWorkarounds().mrtPerfWorkaround; bool skipInactiveRTs = mRenderer->getWorkarounds().mrtPerfWorkaround;
const auto &drawStates = framebuffer->getDrawBufferStates(); const auto &drawStates = framebuffer->getDrawBufferStates();
UINT maxExistingRT = 0;
for (size_t rtIndex = 0; rtIndex < colorRTs.size(); ++rtIndex) for (size_t rtIndex = 0; rtIndex < colorRTs.size(); ++rtIndex)
{ {
...@@ -1031,6 +1032,7 @@ gl::Error StateManager11::syncFramebuffer(gl::Framebuffer *framebuffer) ...@@ -1031,6 +1032,7 @@ gl::Error StateManager11::syncFramebuffer(gl::Framebuffer *framebuffer)
{ {
framebufferRTVs[appliedRTIndex] = renderTarget->getRenderTargetView(); framebufferRTVs[appliedRTIndex] = renderTarget->getRenderTargetView();
ASSERT(framebufferRTVs[appliedRTIndex]); ASSERT(framebufferRTVs[appliedRTIndex]);
maxExistingRT = static_cast<UINT>(appliedRTIndex) + 1;
if (missingColorRenderTarget) if (missingColorRenderTarget)
{ {
...@@ -1071,10 +1073,10 @@ gl::Error StateManager11::syncFramebuffer(gl::Framebuffer *framebuffer) ...@@ -1071,10 +1073,10 @@ gl::Error StateManager11::syncFramebuffer(gl::Framebuffer *framebuffer)
} }
// TODO(jmadill): Use context caps? // TODO(jmadill): Use context caps?
UINT drawBuffers = mRenderer->getNativeCaps().maxDrawBuffers; ASSERT(maxExistingRT <= static_cast<UINT>(mRenderer->getNativeCaps().maxDrawBuffers));
// Apply the render target and depth stencil // Apply the render target and depth stencil
mRenderer->getDeviceContext()->OMSetRenderTargets(drawBuffers, framebufferRTVs.data(), mRenderer->getDeviceContext()->OMSetRenderTargets(maxExistingRT, framebufferRTVs.data(),
framebufferDSV); framebufferDSV);
// The D3D11 blend state is heavily dependent on the current render target. // The D3D11 blend state is heavily dependent on the current render target.
......
...@@ -180,6 +180,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe ...@@ -180,6 +180,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
const d3d11::Format &backbufferFormatInfo = const d3d11::Format &backbufferFormatInfo =
d3d11::Format::Get(mOffscreenRenderTargetFormat, mRenderer->getRenderer11DeviceCaps()); d3d11::Format::Get(mOffscreenRenderTargetFormat, mRenderer->getRenderer11DeviceCaps());
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
// If the app passed in a share handle or D3D texture, open the resource // If the app passed in a share handle or D3D texture, open the resource
// See EGL_ANGLE_d3d_share_handle_client_buffer and EGL_ANGLE_d3d_texture_client_buffer // See EGL_ANGLE_d3d_share_handle_client_buffer and EGL_ANGLE_d3d_texture_client_buffer
...@@ -204,13 +205,13 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe ...@@ -204,13 +205,13 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
UNREACHABLE(); UNREACHABLE();
} }
ASSERT(mOffscreenTexture != nullptr); ASSERT(mOffscreenTexture != nullptr);
mOffscreenTexture->GetDesc(&offscreenTextureDesc);
} }
else else
{ {
const bool useSharedResource = const bool useSharedResource =
!mNativeWindow->getNativeWindow() && mRenderer->getShareHandleSupport(); !mNativeWindow->getNativeWindow() && mRenderer->getShareHandleSupport();
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
offscreenTextureDesc.Width = backbufferWidth; offscreenTextureDesc.Width = backbufferWidth;
offscreenTextureDesc.Height = backbufferHeight; offscreenTextureDesc.Height = backbufferHeight;
offscreenTextureDesc.Format = backbufferFormatInfo.texFormat; offscreenTextureDesc.Format = backbufferFormatInfo.texFormat;
...@@ -285,9 +286,13 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe ...@@ -285,9 +286,13 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
offscreenSRVDesc.Texture2D.MostDetailedMip = 0; offscreenSRVDesc.Texture2D.MostDetailedMip = 0;
offscreenSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1); offscreenSRVDesc.Texture2D.MipLevels = static_cast<UINT>(-1);
result = device->CreateShaderResourceView(mOffscreenTexture, &offscreenSRVDesc, &mOffscreenSRView); if (offscreenTextureDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE)
ASSERT(SUCCEEDED(result)); {
d3d11::SetDebugName(mOffscreenSRView, "Offscreen back buffer shader resource"); result = device->CreateShaderResourceView(mOffscreenTexture, &offscreenSRVDesc,
&mOffscreenSRView);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mOffscreenSRView, "Offscreen back buffer shader resource");
}
if (previousOffscreenTexture != nullptr) if (previousOffscreenTexture != nullptr)
{ {
......
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
#include "OSWindow.h" #include "OSWindow.h"
#include "test_utils/ANGLETest.h" #include "test_utils/ANGLETest.h"
#if defined(ANGLE_ENABLE_D3D11)
#define INITGUID
#include <guiddef.h>
#include <d3d11.h>
#include <dcomp.h>
#endif
namespace namespace
{ {
...@@ -109,6 +117,17 @@ class EGLSurfaceTest : public testing::Test ...@@ -109,6 +117,17 @@ class EGLSurfaceTest : public testing::Test
ASSERT_TRUE(eglGetError() == EGL_SUCCESS); ASSERT_TRUE(eglGetError() == EGL_SUCCESS);
} }
void initializeContext()
{
EGLint contextAttibutes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
mContext = eglCreateContext(mDisplay, mConfig, nullptr, contextAttibutes);
ASSERT_TRUE(eglGetError() == EGL_SUCCESS);
mSecondContext = eglCreateContext(mDisplay, mConfig, nullptr, contextAttibutes);
ASSERT_TRUE(eglGetError() == EGL_SUCCESS);
}
void initializeSurface(EGLConfig config) void initializeSurface(EGLConfig config)
{ {
mConfig = config; mConfig = config;
...@@ -122,18 +141,7 @@ class EGLSurfaceTest : public testing::Test ...@@ -122,18 +141,7 @@ class EGLSurfaceTest : public testing::Test
ASSERT_TRUE(eglGetError() == EGL_SUCCESS); ASSERT_TRUE(eglGetError() == EGL_SUCCESS);
mPbufferSurface = eglCreatePbufferSurface(mDisplay, mConfig, &surfaceAttributes[0]); mPbufferSurface = eglCreatePbufferSurface(mDisplay, mConfig, &surfaceAttributes[0]);
initializeContext();
EGLint contextAttibutes[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
mContext = eglCreateContext(mDisplay, mConfig, nullptr, contextAttibutes);
ASSERT_TRUE(eglGetError() == EGL_SUCCESS);
mSecondContext = eglCreateContext(mDisplay, mConfig, nullptr, contextAttibutes);
ASSERT_TRUE(eglGetError() == EGL_SUCCESS);
} }
void initializeSurfaceWithDefaultConfig() void initializeSurfaceWithDefaultConfig()
...@@ -514,4 +522,83 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig8880Support) ...@@ -514,4 +522,83 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig8880Support)
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
glDeleteProgram(program); glDeleteProgram(program);
} }
#if defined(ANGLE_ENABLE_D3D11)
// Test that rendering to an IDCompositionSurface using a pbuffer works.
TEST_F(EGLSurfaceTest, CreateDirectCompositionSurface)
{
if (!ANGLETest::eglDisplayExtensionEnabled(EGL_NO_DISPLAY, "EGL_ANGLE_platform_angle_d3d"))
{
std::cout << "D3D Platform not supported in ANGLE" << std::endl;
return;
}
initializeDisplay(EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE);
EGLAttrib device = 0;
EGLAttrib newEglDevice = 0;
ASSERT_EGL_TRUE(eglQueryDisplayAttribEXT(mDisplay, EGL_DEVICE_EXT, &newEglDevice));
ASSERT_EGL_TRUE(eglQueryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(newEglDevice),
EGL_D3D11_DEVICE_ANGLE, &device));
angle::ComPtr<ID3D11Device> d3d11Device(reinterpret_cast<ID3D11Device *>(device));
ASSERT_TRUE(!!d3d11Device);
HMODULE dcompLibrary = LoadLibraryA("dcomp.dll");
if (!dcompLibrary)
{
std::cout << "DirectComposition not supported" << std::endl;
return;
}
typedef HRESULT(WINAPI * PFN_DCOMPOSITION_CREATE_DEVICE2)(IUnknown * dxgiDevice, REFIID iid,
void **dcompositionDevice);
PFN_DCOMPOSITION_CREATE_DEVICE2 createDComp = reinterpret_cast<PFN_DCOMPOSITION_CREATE_DEVICE2>(
GetProcAddress(dcompLibrary, "DCompositionCreateDevice2"));
if (!createDComp)
{
std::cout << "DirectComposition2 not supported" << std::endl;
FreeLibrary(dcompLibrary);
return;
}
angle::ComPtr<IDCompositionDevice> dcompDevice;
HRESULT hr = createDComp(d3d11Device.Get(), IID_PPV_ARGS(dcompDevice.GetAddressOf()));
ASSERT_TRUE(SUCCEEDED(hr));
angle::ComPtr<IDCompositionSurface> dcompSurface;
hr = dcompDevice->CreateSurface(100, 100, DXGI_FORMAT_B8G8R8A8_UNORM,
DXGI_ALPHA_MODE_PREMULTIPLIED, dcompSurface.GetAddressOf());
ASSERT_TRUE(SUCCEEDED(hr));
angle::ComPtr<ID3D11Texture2D> texture;
POINT updateOffset;
hr = dcompSurface->BeginDraw(nullptr, IID_PPV_ARGS(texture.GetAddressOf()), &updateOffset);
ASSERT_TRUE(SUCCEEDED(hr));
const EGLint configAttributes[] = {
EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 0, EGL_SAMPLE_BUFFERS, 0, EGL_NONE};
EGLConfig config;
ASSERT_EGL_TRUE(EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config));
const EGLint surfaceAttributes[] = {EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE};
EGLClientBuffer buffer = reinterpret_cast<EGLClientBuffer>(texture.Get());
mPbufferSurface = eglCreatePbufferFromClientBuffer(mDisplay, EGL_D3D_TEXTURE_ANGLE, buffer,
config, surfaceAttributes);
ASSERT_EGL_SUCCESS();
mConfig = config;
initializeContext();
eglMakeCurrent(mDisplay, mPbufferSurface, mPbufferSurface, mContext);
ASSERT_EGL_SUCCESS();
GLuint program = createProgram();
ASSERT_NE(0u, program);
drawWithProgram(program);
EXPECT_GL_NO_ERROR();
glDeleteProgram(program);
}
#endif
} }
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