Skip to content

Commit

Permalink
Implement EGL_ANGLE_create_context_backwards_compatible
Browse files Browse the repository at this point in the history
This extension allows the user to specify if ANGLE should create a
context of the exact requested version or a higher version context that
is backwards compatible.

BUG=angleproject:3425

Change-Id: I7d0b75cdd7e34a2fc888aa238e1eeb67af82ae0d
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1601560
Commit-Queue: Geoff Lang <[email protected]>
Reviewed-by: Shahbaz Youssefi <[email protected]>
  • Loading branch information
vonture authored and Commit Bot committed Jul 18, 2019
1 parent 3d4dfa6 commit 6a02f06
Show file tree
Hide file tree
Showing 31 changed files with 386 additions and 30 deletions.
3 changes: 0 additions & 3 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ config("internal_config") {
if (angle_enable_vulkan_gpu_trace_events) {
defines += [ "ANGLE_ENABLE_VULKAN_GPU_TRACE_EVENTS=1" ]
}
if (angle_vulkan_conformant_configs_only) {
defines += [ "ANGLE_VULKAN_CONFORMANT_CONFIGS_ONLY=1" ]
}
}

if (angle_enable_trace) {
Expand Down
93 changes: 93 additions & 0 deletions extensions/EGL_ANGLE_create_context_backwards_compatible.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Name

ANGLE_create_context_backwards_compatible

Name Strings

EGL_ANGLE_create_context_backwards_compatible

Contributors

Geoff Lang

Contacts

Geoff Lang (geofflang 'at' google.com)

Status

Draft

Version

Version 1, May 8, 2019

Number

EGL Extension #??

Dependencies

Requires EGL 1.4.

Written against the EGL 1.5 specification.

Overview

This extension allows the user to create a context with exact major and
minor versions. By default, a context may be created of any version that
is backwards-compatible with the requested verion but it is often useful to
users to request and target a specific version.

New Types

None

New Procedures and Functions

None

New Tokens

Accepted as an attribute name in the <*attrib_list> argument to
eglCreateContext:

EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE 0x3483

Additions to the EGL 1.5 Specification

Modify section 3.7.1.1 "OpenGL and OpenGL ES Context Versions":

- The context returned must be the specified version, or a later version
- which is backwards compatible with that version.

+ The context returned must be the specified version, or a later version
+ which is backwards compatible with that version if
+ EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE is EGL_TRUE.

Append to section 3.7.1.1 "OpenGL and OpenGL ES Context Versions":

The default value of EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE is
EGL_TRUE.

Errors

None

New State

None

Conformance Tests

TBD

Issues

None

Revision History

Rev. Date Author Changes
---- ------------- --------- ----------------------------------------
1 May 8, 2019 geofflang Initial version
3 changes: 0 additions & 3 deletions gni/angle.gni
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ declare_args() {
# Enable Vulkan GPU trace event capability
angle_enable_vulkan_gpu_trace_events = false

# Disallow non-conformant configurations in official builds.
angle_vulkan_conformant_configs_only = is_official_build

# Enable custom (cpu-side) secondary command buffers
angle_enable_custom_vulkan_cmd_buffers = true
}
Expand Down
5 changes: 5 additions & 0 deletions include/EGL/eglext_angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribANGLE(EGLDisplay dpy, EGLint
#define EGL_D3D11_TEXTURE_ANGLE 0x3484
#endif /* EGL_ANGLE_image_d3d11_texture */

#ifndef EGL_ANGLE_create_context_backwards_compatible
#define EGL_ANGLE_create_context_backwards_compatible 1
#define EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE 0x3483
#endif /* EGL_ANGLE_create_context_backwards_compatible */

// clang-format on

#endif // INCLUDE_EGL_EGLEXT_ANGLE_
1 change: 1 addition & 0 deletions src/libANGLE/Caps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@ std::vector<std::string> DisplayExtensions::getStrings() const
InsertExtensionString("EGL_ANGLE_image_d3d11_texture", imageD3D11Texture, &extensionStrings);
InsertExtensionString("EGL_ANDROID_get_native_client_buffer", getNativeClientBufferANDROID, &extensionStrings);
InsertExtensionString("EGL_ANDROID_native_fence_sync", nativeFenceSyncANDROID, &extensionStrings);
InsertExtensionString("EGL_ANGLE_create_context_backwards_compatible", createContextBackwardsCompatible, &extensionStrings);
// TODO(jmadill): Enable this when complete.
//InsertExtensionString("KHR_create_context_no_error", createContextNoError, &extensionStrings);
// clang-format on
Expand Down
3 changes: 3 additions & 0 deletions src/libANGLE/Caps.h
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,9 @@ struct DisplayExtensions

// EGL_ANDROID_native_fence_sync
bool nativeFenceSyncANDROID = false;

// EGL_ANGLE_create_context_backwards_compatible
bool createContextBackwardsCompatible = false;
};

struct DeviceExtensions
Expand Down
39 changes: 32 additions & 7 deletions src/libANGLE/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
#include "libANGLE/formatutils.h"
#include "libANGLE/queryconversions.h"
#include "libANGLE/queryutils.h"
#include "libANGLE/renderer/BufferImpl.h"
#include "libANGLE/renderer/EGLImplFactory.h"
#include "libANGLE/renderer/DisplayImpl.h"
#include "libANGLE/renderer/Format.h"
#include "libANGLE/validationES.h"

Expand Down Expand Up @@ -143,9 +142,34 @@ EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
}

Version GetClientVersion(const egl::AttributeMap &attribs)
bool GetBackwardCompatibleContext(const egl::AttributeMap &attribs)
{
return Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
return attribs.get(EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE, EGL_TRUE) == EGL_TRUE;
}

Version GetClientVersion(egl::Display *display, const egl::AttributeMap &attribs)
{
Version requestedVersion =
Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
if (GetBackwardCompatibleContext(attribs))
{
if (requestedVersion.major == 1)
{
// If the user requests an ES1 context, we cannot return an ES 2+ context.
return Version(1, 1);
}
else
{
// Always up the version to at least the max conformant version this display supports.
// Only return a higher client version if requested.
return std::max(display->getImplementation()->getMaxConformantESVersion(),
requestedVersion);
}
}
else
{
return requestedVersion;
}
}

GLenum GetResetStrategy(const egl::AttributeMap &attribs)
Expand Down Expand Up @@ -272,7 +296,7 @@ enum SubjectIndexes : angle::SubjectIndex
};
} // anonymous namespace

Context::Context(rx::EGLImplFactory *implFactory,
Context::Context(egl::Display *display,
const egl::Config *config,
const Context *shareContext,
TextureManager *shareTextures,
Expand All @@ -285,7 +309,7 @@ Context::Context(rx::EGLImplFactory *implFactory,
shareContext ? &shareContext->mState : nullptr,
shareTextures,
clientType,
GetClientVersion(attribs),
GetClientVersion(display, attribs),
GetDebug(attribs),
GetBindGeneratesResource(attribs),
GetClientArraysEnabled(attribs),
Expand All @@ -294,7 +318,8 @@ Context::Context(rx::EGLImplFactory *implFactory,
mSkipValidation(GetNoError(attribs)),
mDisplayTextureShareGroup(shareTextures != nullptr),
mErrors(this),
mImplementation(implFactory->createContext(mState, &mErrors, config, shareContext, attribs)),
mImplementation(display->getImplementation()
->createContext(mState, &mErrors, config, shareContext, attribs)),
mLabel(nullptr),
mCompiler(),
mConfig(config),
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class StateCache final : angle::NonCopyable
class Context final : public egl::LabeledObject, angle::NonCopyable, public angle::ObserverInterface
{
public:
Context(rx::EGLImplFactory *implFactory,
Context(egl::Display *display,
const egl::Config *config,
const Context *shareContext,
TextureManager *shareTextures,
Expand Down
7 changes: 5 additions & 2 deletions src/libANGLE/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,8 @@ Error Display::createContext(const Config *configuration,
}

gl::Context *context =
new gl::Context(mImplementation, configuration, shareContext, shareTextures, cachePointer,
clientType, attribs, mDisplayExtensions, GetClientExtensions());
new gl::Context(this, configuration, shareContext, shareTextures, cachePointer, clientType,
attribs, mDisplayExtensions, GetClientExtensions());

ASSERT(context != nullptr);
mContextSet.insert(context);
Expand Down Expand Up @@ -1312,6 +1312,9 @@ void Display::initDisplayExtensions()
// that ANativeWindow is not recordable.
mDisplayExtensions.recordable = true;

// All backends support specific context versions
mDisplayExtensions.createContextBackwardsCompatible = true;

mDisplayExtensionString = GenerateExtensionsString(mDisplayExtensions);
}

Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/DisplayImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class DisplayImpl : public EGLImplFactory
virtual egl::Error waitClient(const gl::Context *context) = 0;
virtual egl::Error waitNative(const gl::Context *context, EGLint engine) = 0;
virtual gl::Version getMaxSupportedESVersion() const = 0;
virtual gl::Version getMaxConformantESVersion() const = 0;
const egl::Caps &getCaps() const;

virtual void setBlobCacheFuncs(EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get) {}
Expand Down
5 changes: 5 additions & 0 deletions src/libANGLE/renderer/d3d/DisplayD3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ gl::Version DisplayD3D::getMaxSupportedESVersion() const
return mRenderer->getMaxSupportedESVersion();
}

gl::Version DisplayD3D::getMaxConformantESVersion() const
{
return mRenderer->getMaxConformantESVersion();
}

void DisplayD3D::handleResult(HRESULT hr,
const char *message,
const char *file,
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/d3d/DisplayD3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class DisplayD3D : public DisplayImpl, public d3d::Context
egl::Error waitClient(const gl::Context *context) override;
egl::Error waitNative(const gl::Context *context, EGLint engine) override;
gl::Version getMaxSupportedESVersion() const override;
gl::Version getMaxConformantESVersion() const override;

void handleResult(HRESULT hr,
const char *message,
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/d3d/RendererD3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ class RendererD3D : public BufferFactoryD3D
virtual FramebufferImpl *createDefaultFramebuffer(const gl::FramebufferState &state) = 0;

virtual gl::Version getMaxSupportedESVersion() const = 0;
virtual gl::Version getMaxConformantESVersion() const = 0;

angle::Result initRenderTarget(const gl::Context *context, RenderTargetD3D *renderTarget);

Expand Down
6 changes: 6 additions & 0 deletions src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3702,6 +3702,12 @@ gl::Version Renderer11::getMaxSupportedESVersion() const
return d3d11_gl::GetMaximumClientVersion(mRenderer11DeviceCaps.featureLevel);
}

gl::Version Renderer11::getMaxConformantESVersion() const
{
// Always force a 2.0 context unless the user explicitly requests higher
return std::min(getMaxSupportedESVersion(), gl::Version(2, 0));
}

gl::DebugAnnotator *Renderer11::getAnnotator()
{
return &mAnnotator;
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/d3d/d3d11/Renderer11.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ class Renderer11 : public RendererD3D
angle::MemoryBuffer **bufferOut);

gl::Version getMaxSupportedESVersion() const override;
gl::Version getMaxConformantESVersion() const override;

angle::Result dispatchCompute(const gl::Context *context,
GLuint numGroupsX,
Expand Down
5 changes: 5 additions & 0 deletions src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3084,6 +3084,11 @@ gl::Version Renderer9::getMaxSupportedESVersion() const
return gl::Version(2, 0);
}

gl::Version Renderer9::getMaxConformantESVersion() const
{
return gl::Version(2, 0);
}

angle::Result Renderer9::clearRenderTarget(const gl::Context *context,
RenderTargetD3D *renderTarget,
const gl::ColorF &clearColorValue,
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/d3d/d3d9/Renderer9.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ class Renderer9 : public RendererD3D
DebugAnnotator9 *getAnnotator() { return &mAnnotator; }

gl::Version getMaxSupportedESVersion() const override;
gl::Version getMaxConformantESVersion() const override;

angle::Result clearRenderTarget(const gl::Context *context,
RenderTargetD3D *renderTarget,
Expand Down
6 changes: 6 additions & 0 deletions src/libANGLE/renderer/gl/DisplayGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ egl::Error DisplayGL::makeCurrent(egl::Surface *drawSurface,
return egl::NoError();
}

gl::Version DisplayGL::getMaxConformantESVersion() const
{
// Always force a 2.0 context unless the user explicitly requests higher
return std::min(getMaxSupportedESVersion(), gl::Version(2, 0));
}

void DisplayGL::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
// Advertise robust resource initialization on all OpenGL backends for testing even though it is
Expand Down
2 changes: 2 additions & 0 deletions src/libANGLE/renderer/gl/DisplayGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class DisplayGL : public DisplayImpl
egl::Surface *readSurface,
gl::Context *context) override;

gl::Version getMaxConformantESVersion() const override;

protected:
void generateExtensions(egl::DisplayExtensions *outExtensions) const override;

Expand Down
5 changes: 5 additions & 0 deletions src/libANGLE/renderer/null/DisplayNULL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ gl::Version DisplayNULL::getMaxSupportedESVersion() const
return gl::Version(3, 2);
}

gl::Version DisplayNULL::getMaxConformantESVersion() const
{
return getMaxSupportedESVersion();
}

SurfaceImpl *DisplayNULL::createWindowSurface(const egl::SurfaceState &state,
EGLNativeWindowType window,
const egl::AttributeMap &attribs)
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/null/DisplayNULL.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class DisplayNULL : public DisplayImpl
egl::Error waitClient(const gl::Context *context) override;
egl::Error waitNative(const gl::Context *context, EGLint engine) override;
gl::Version getMaxSupportedESVersion() const override;
gl::Version getMaxConformantESVersion() const override;

SurfaceImpl *createWindowSurface(const egl::SurfaceState &state,
EGLNativeWindowType window,
Expand Down
5 changes: 5 additions & 0 deletions src/libANGLE/renderer/vulkan/DisplayVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ gl::Version DisplayVk::getMaxSupportedESVersion() const
return mRenderer->getMaxSupportedESVersion();
}

gl::Version DisplayVk::getMaxConformantESVersion() const
{
return mRenderer->getMaxConformantESVersion();
}

void DisplayVk::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
outExtensions->createContextRobustness = true;
Expand Down
1 change: 1 addition & 0 deletions src/libANGLE/renderer/vulkan/DisplayVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class DisplayVk : public DisplayImpl, public vk::Context
EGLSyncImpl *createSync(const egl::AttributeMap &attribs) override;

gl::Version getMaxSupportedESVersion() const override;
gl::Version getMaxConformantESVersion() const override;

virtual const char *getWSIExtension() const = 0;
virtual const char *getWSILayer() const;
Expand Down
Loading

0 comments on commit 6a02f06

Please sign in to comment.