Hi, I'm working on the D3D11Texture2D and angle Texture sharing depends on the EGL_ANGLE_d3d_share_handle_client_buffer extension. After I choose an EGLConfig with eglChooseConfig, and pass the config to eglCreatePbufferFromClientBuffer, it returns the EGL_BAD_PARAMETER error. After digging into the angle source code, I found the reason is that render target format (BGRA) of first config return by eglChooseConfig differs with
D3D11Texture2D format (RGBA) as I assigned.
egl::Error Renderer11::validateShareHandle(const egl::Config *config,
HANDLE shareHandle,
const egl::AttributeMap &attribs) const
{
// ....
// ....
// desc.Format != backbufferFormatInfo.texFormat is true.
const d3d11::Format &backbufferFormatInfo =
d3d11::Format::Get(config->renderTargetFormat, getRenderer11DeviceCaps());
if (desc.Width != static_cast<UINT>(width) || desc.Height != static_cast<UINT>(height) ||
desc.Format != backbufferFormatInfo.texFormat || desc.MipLevels != 1 || desc.ArraySize != 1)
{
std::string msgHeader = std::to_string(desc.Format) + " vs " + std::to_string(backbufferFormatInfo.texFormat);
std::cout << msgHeader << std::endl;
return egl::EglBadParameter() << msgHeader + ", Invalid texture parameters in share handle texture.";
}
return egl::NoError();
}
So the question is, if it's possible to query the expected render target format with
eglChooseConfig API? And if not, any suggestion on how to get appropriate
EGLConfig to eglCreatePbufferFromClientBuffer?
following is my code snippet, any help is appreciated:
D3D11_TEXTURE2D_DESC dst_desc;
memset(&dst_desc, 0x0, sizeof(dst_desc));
dst_desc.Width = width;
dst_desc.Height = height;
dst_desc.MipLevels = dst_desc.ArraySize = 1;
dst_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
dst_desc.SampleDesc.Count = 1;
dst_desc.Usage = D3D11_USAGE_DEFAULT;
dst_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
dst_desc.CPUAccessFlags = 0;
dst_desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
ID3D11Texture2D* pd3dtex = NULL;
HRESULT hr = device->CreateTexture2D(&dst_desc, NULL, &pd3dtex);
IDXGIResource* dxgiResource;
HANDLE sharedHandle;
pd3dtex->QueryInterface(__uuidof(IDXGIResource), (LPVOID*)&dxgiResource);
hr = dxgiResource->GetSharedHandle(&sharedHandle);
if FAILED(hr)
{
std::cerr << "open shared handle failed: " << GetLastError() << std::endl;
}
else
{
std::cout << "shared handle: " << sharedHandle << std::endl;
}
dxgiResource->Release();
ptex->d3d_tex = pd3dtex;
EGLint pBufferAttributes[] =
{
EGL_WIDTH, width,
EGL_HEIGHT, height,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
EGL_NONE, EGL_NONE
};
int attribs[] = {
// 32 bit color
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
// at least 24 bit depth
EGL_DEPTH_SIZE, 0,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE, EGL_NONE
};
EGLConfig configs[10];
int num_config;
eglChooseConfig(display, attribs, configs, 10, &num_config);
if (num_config <= 0)
{
std::cerr << "no egl config found supports input attributes.\n";
}
else
{
//std::cout << "query count: " << num_config << ", selected config: " << configs[0] << std::endl;
}
EGLSurface surface1 = eglCreatePbufferFromClientBuffer(display, EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE,
sharedHandle, configs[0], pBufferAttributes);
if (surface1 == EGL_NO_SURFACE)
{
EGLint error = eglGetError();
std::cout << "egl error: " << std::hex << error << std::dec << std::endl;
std::abort();
}