OpenGL: only load extension procs if extension supported.

Only load extension entry points if the extension is supported.

From the eglGetProcAddress manpage:

"A non-NULL return value does not guarantee that an extension function
is actually supported at runtime. The client must also make a
corresponding query, such as glGetString(GL_EXTENSIONS) for OpenGL and
OpenGL ES extensions [...] to determine if a function is supported by
EGL or a specific client API context."

This required moving extension initialization from OpenGLFunctions
into OpenGLFunctionsBase.

Change-Id: Ib4e8360ba455818701990b4476689b651d097ca8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121760
Commit-Queue: Stephen White <senorblanco@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Stephen White 2023-02-27 19:31:08 +00:00 committed by Dawn LUCI CQ
parent 43ffb09247
commit 55183e6c3a
4 changed files with 34 additions and 29 deletions

View File

@ -36,11 +36,15 @@ MaybeError OpenGLFunctionsBase::LoadOpenGLESProcs(GetProcAddress getProc, int ma
{% endfor %}
InitializeSupportedGLExtensions();
{% for block in extension_gles_blocks %}
// {{block.extension}}
if (IsGLExtensionSupported("{{block.extension}}")) {
{% for proc in block.procs %}
DAWN_TRY(LoadProc(getProc, &{{proc.ProcName()}}, "{{proc.glProcName()}}"));
{% endfor %}
}
{% endfor %}
return {};
@ -57,14 +61,33 @@ MaybeError OpenGLFunctionsBase::LoadDesktopGLProcs(GetProcAddress getProc, int m
{% endfor %}
InitializeSupportedGLExtensions();
{% for block in extension_desktop_gl_blocks %}
// {{block.extension}}
if (IsGLExtensionSupported("{{block.extension}}")) {
{% for proc in block.procs %}
DAWN_TRY(LoadProc(getProc, &{{proc.ProcName()}}, "{{proc.glProcName()}}"));
{% endfor %}
}
{% endfor %}
return {};
}
void OpenGLFunctionsBase::InitializeSupportedGLExtensions() {
int32_t numExtensions;
GetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
for (int32_t i = 0; i < numExtensions; ++i) {
const char* extensionName = reinterpret_cast<const char*>(GetStringi(GL_EXTENSIONS, i));
mSupportedGLExtensionsSet.insert(extensionName);
}
}
bool OpenGLFunctionsBase::IsGLExtensionSupported(const char* extension) const {
ASSERT(extension != nullptr);
return mSupportedGLExtensionsSet.count(extension) != 0;
}
} // namespace dawn::native::opengl

View File

@ -15,6 +15,8 @@
#ifndef DAWNNATIVE_OPENGL_OPENGLFUNCTIONSBASE_H_
#define DAWNNATIVE_OPENGL_OPENGLFUNCTIONSBASE_H_
#include <unordered_set>
#include "dawn/native/Error.h"
#include "dawn/native/opengl/opengl_platform.h"
@ -30,6 +32,7 @@ namespace dawn::native::opengl {
{% endfor %}
{% endfor%}
bool IsGLExtensionSupported(const char* extension) const;
protected:
MaybeError LoadDesktopGLProcs(GetProcAddress getProc, int majorVersion, int minorVersion);
@ -38,6 +41,9 @@ namespace dawn::native::opengl {
private:
template<typename T>
MaybeError LoadProc(GetProcAddress getProc, T* memberProc, const char* name);
void InitializeSupportedGLExtensions();
std::unordered_set<std::string> mSupportedGLExtensionsSet;
};
} // namespace dawn::native::opengl

View File

@ -26,26 +26,9 @@ MaybeError OpenGLFunctions::Initialize(GetProcAddress getProc) {
DAWN_TRY(LoadDesktopGLProcs(getProc, mVersion.GetMajor(), mVersion.GetMinor()));
}
InitializeSupportedGLExtensions();
return {};
}
void OpenGLFunctions::InitializeSupportedGLExtensions() {
int32_t numExtensions;
GetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
for (int32_t i = 0; i < numExtensions; ++i) {
const char* extensionName = reinterpret_cast<const char*>(GetStringi(GL_EXTENSIONS, i));
mSupportedGLExtensionsSet.insert(extensionName);
}
}
bool OpenGLFunctions::IsGLExtensionSupported(const char* extension) const {
ASSERT(extension != nullptr);
return mSupportedGLExtensionsSet.count(extension) != 0;
}
const OpenGLVersion& OpenGLFunctions::GetVersion() const {
return mVersion;
}

View File

@ -16,7 +16,6 @@
#define SRC_DAWN_NATIVE_OPENGL_OPENGLFUNCTIONS_H_
#include <string>
#include <unordered_set>
#include "dawn/native/opengl/OpenGLFunctionsBase_autogen.h"
#include "dawn/native/opengl/OpenGLVersion.h"
@ -31,14 +30,8 @@ struct OpenGLFunctions : OpenGLFunctionsBase {
bool IsAtLeastGL(uint32_t majorVersion, uint32_t minorVersion) const;
bool IsAtLeastGLES(uint32_t majorVersion, uint32_t minorVersion) const;
bool IsGLExtensionSupported(const char* extension) const;
private:
void InitializeSupportedGLExtensions();
OpenGLVersion mVersion;
std::unordered_set<std::string> mSupportedGLExtensionsSet;
};
} // namespace dawn::native::opengl