Refactor OpenGLVersion out of OpenGLFunctions.
We need the ability to parse the GL version irrespective of GL extension handling, so pull it out into its own class. BUG=dawn:580 Change-Id: I620267146159ba8e4fa8cba5f6ebff57e981add0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33540 Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
parent
66f753b5ed
commit
03badec5d7
|
@ -12,6 +12,9 @@
|
|||
//* See the License for the specific language governing permissions and
|
||||
//* limitations under the License.
|
||||
|
||||
#ifndef DAWNNATIVE_OPENGL_OPENGLFUNCTIONSBASE_H_
|
||||
#define DAWNNATIVE_OPENGL_OPENGLFUNCTIONSBASE_H_
|
||||
|
||||
#include "dawn_native/Error.h"
|
||||
#include "dawn_native/opengl/opengl_platform.h"
|
||||
|
||||
|
@ -38,3 +41,5 @@ namespace dawn_native { namespace opengl {
|
|||
};
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
||||
#endif // DAWNNATIVE_OPENGL_OPENGLFUNCTIONSBASE_H_
|
||||
|
|
|
@ -448,6 +448,8 @@ source_set("dawn_native_sources") {
|
|||
"opengl/NativeSwapChainImplGL.h",
|
||||
"opengl/OpenGLFunctions.cpp",
|
||||
"opengl/OpenGLFunctions.h",
|
||||
"opengl/OpenGLVersion.cpp",
|
||||
"opengl/OpenGLVersion.h",
|
||||
"opengl/PersistentPipelineStateGL.cpp",
|
||||
"opengl/PersistentPipelineStateGL.h",
|
||||
"opengl/PipelineGL.cpp",
|
||||
|
|
|
@ -15,43 +15,15 @@
|
|||
#include "dawn_native/opengl/OpenGLFunctions.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <tuple>
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
MaybeError OpenGLFunctions::Initialize(GetProcAddress getProc) {
|
||||
PFNGLGETSTRINGPROC getString = reinterpret_cast<PFNGLGETSTRINGPROC>(getProc("glGetString"));
|
||||
if (getString == nullptr) {
|
||||
return DAWN_INTERNAL_ERROR("Couldn't load glGetString");
|
||||
}
|
||||
|
||||
std::string version = reinterpret_cast<const char*>(getString(GL_VERSION));
|
||||
|
||||
if (version.find("OpenGL ES") != std::string::npos) {
|
||||
// ES spec states that the GL_VERSION string will be in the following format:
|
||||
// "OpenGL ES N.M vendor-specific information"
|
||||
mStandard = Standard::ES;
|
||||
mMajorVersion = version[10] - '0';
|
||||
mMinorVersion = version[12] - '0';
|
||||
|
||||
// The minor version shouldn't get to two digits.
|
||||
ASSERT(version.size() <= 13 || !isdigit(version[13]));
|
||||
|
||||
DAWN_TRY(LoadOpenGLESProcs(getProc, mMajorVersion, mMinorVersion));
|
||||
DAWN_TRY(mVersion.Initialize(getProc));
|
||||
if (mVersion.IsES()) {
|
||||
DAWN_TRY(LoadOpenGLESProcs(getProc, mVersion.GetMajor(), mVersion.GetMinor()));
|
||||
} else {
|
||||
// OpenGL spec states the GL_VERSION string will be in the following format:
|
||||
// <version number><space><vendor-specific information>
|
||||
// The version number is either of the form major number.minor number or major
|
||||
// number.minor number.release number, where the numbers all have one or more
|
||||
// digits
|
||||
mStandard = Standard::Desktop;
|
||||
mMajorVersion = version[0] - '0';
|
||||
mMinorVersion = version[2] - '0';
|
||||
|
||||
// The minor version shouldn't get to two digits.
|
||||
ASSERT(version.size() <= 3 || !isdigit(version[3]));
|
||||
|
||||
DAWN_TRY(LoadDesktopGLProcs(getProc, mMajorVersion, mMinorVersion));
|
||||
DAWN_TRY(LoadDesktopGLProcs(getProc, mVersion.GetMajor(), mVersion.GetMinor()));
|
||||
}
|
||||
|
||||
InitializeSupportedGLExtensions();
|
||||
|
@ -74,14 +46,16 @@ namespace dawn_native { namespace opengl {
|
|||
return mSupportedGLExtensionsSet.count(extension) != 0;
|
||||
}
|
||||
|
||||
const OpenGLVersion& OpenGLFunctions::GetVersion() const {
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
bool OpenGLFunctions::IsAtLeastGL(uint32_t majorVersion, uint32_t minorVersion) const {
|
||||
return mStandard == Standard::Desktop &&
|
||||
std::tie(mMajorVersion, mMinorVersion) >= std::tie(majorVersion, minorVersion);
|
||||
return mVersion.IsDesktop() && mVersion.IsAtLeast(majorVersion, minorVersion);
|
||||
}
|
||||
|
||||
bool OpenGLFunctions::IsAtLeastGLES(uint32_t majorVersion, uint32_t minorVersion) const {
|
||||
return mStandard == Standard::ES &&
|
||||
std::tie(mMajorVersion, mMinorVersion) >= std::tie(majorVersion, minorVersion);
|
||||
return mVersion.IsES() && mVersion.IsAtLeast(majorVersion, minorVersion);
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <unordered_set>
|
||||
|
||||
#include "dawn_native/opengl/OpenGLFunctionsBase_autogen.h"
|
||||
#include "dawn_native/opengl/OpenGLVersion.h"
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
|
@ -25,6 +26,7 @@ namespace dawn_native { namespace opengl {
|
|||
public:
|
||||
MaybeError Initialize(GetProcAddress getProc);
|
||||
|
||||
const OpenGLVersion& GetVersion() const;
|
||||
bool IsAtLeastGL(uint32_t majorVersion, uint32_t minorVersion) const;
|
||||
bool IsAtLeastGLES(uint32_t majorVersion, uint32_t minorVersion) const;
|
||||
|
||||
|
@ -33,14 +35,7 @@ namespace dawn_native { namespace opengl {
|
|||
private:
|
||||
void InitializeSupportedGLExtensions();
|
||||
|
||||
uint32_t mMajorVersion;
|
||||
uint32_t mMinorVersion;
|
||||
|
||||
enum class Standard {
|
||||
Desktop,
|
||||
ES,
|
||||
};
|
||||
Standard mStandard;
|
||||
OpenGLVersion mVersion;
|
||||
|
||||
std::unordered_set<std::string> mSupportedGLExtensionsSet;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
// Copyright 2020 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "dawn_native/opengl/OpenGLVersion.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <tuple>
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
MaybeError OpenGLVersion::Initialize(GetProcAddress getProc) {
|
||||
PFNGLGETSTRINGPROC getString = reinterpret_cast<PFNGLGETSTRINGPROC>(getProc("glGetString"));
|
||||
if (getString == nullptr) {
|
||||
return DAWN_INTERNAL_ERROR("Couldn't load glGetString");
|
||||
}
|
||||
|
||||
std::string version = reinterpret_cast<const char*>(getString(GL_VERSION));
|
||||
|
||||
if (version.find("OpenGL ES") != std::string::npos) {
|
||||
// ES spec states that the GL_VERSION string will be in the following format:
|
||||
// "OpenGL ES N.M vendor-specific information"
|
||||
mStandard = Standard::ES;
|
||||
mMajorVersion = version[10] - '0';
|
||||
mMinorVersion = version[12] - '0';
|
||||
|
||||
// The minor version shouldn't get to two digits.
|
||||
ASSERT(version.size() <= 13 || !isdigit(version[13]));
|
||||
} else {
|
||||
// OpenGL spec states the GL_VERSION string will be in the following format:
|
||||
// <version number><space><vendor-specific information>
|
||||
// The version number is either of the form major number.minor number or major
|
||||
// number.minor number.release number, where the numbers all have one or more
|
||||
// digits
|
||||
mStandard = Standard::Desktop;
|
||||
mMajorVersion = version[0] - '0';
|
||||
mMinorVersion = version[2] - '0';
|
||||
|
||||
// The minor version shouldn't get to two digits.
|
||||
ASSERT(version.size() <= 3 || !isdigit(version[3]));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool OpenGLVersion::IsDesktop() const {
|
||||
return mStandard == Standard::Desktop;
|
||||
}
|
||||
|
||||
bool OpenGLVersion::IsES() const {
|
||||
return mStandard == Standard::ES;
|
||||
}
|
||||
|
||||
uint32_t OpenGLVersion::GetMajor() const {
|
||||
return mMajorVersion;
|
||||
}
|
||||
|
||||
uint32_t OpenGLVersion::GetMinor() const {
|
||||
return mMinorVersion;
|
||||
}
|
||||
|
||||
bool OpenGLVersion::IsAtLeast(uint32_t majorVersion, uint32_t minorVersion) const {
|
||||
return std::tie(mMajorVersion, mMinorVersion) >= std::tie(majorVersion, minorVersion);
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::opengl
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright 2020 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef DAWNNATIVE_OPENGL_OPENGLVERSION_H_
|
||||
#define DAWNNATIVE_OPENGL_OPENGLVERSION_H_
|
||||
|
||||
#include "dawn_native/opengl/OpenGLFunctionsBase_autogen.h"
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
struct OpenGLVersion {
|
||||
public:
|
||||
MaybeError Initialize(GetProcAddress getProc);
|
||||
|
||||
bool IsDesktop() const;
|
||||
bool IsES() const;
|
||||
uint32_t GetMajor() const;
|
||||
uint32_t GetMinor() const;
|
||||
bool IsAtLeast(uint32_t majorVersion, uint32_t minorVersion) const;
|
||||
|
||||
private:
|
||||
enum class Standard {
|
||||
Desktop,
|
||||
ES,
|
||||
};
|
||||
uint32_t mMajorVersion;
|
||||
uint32_t mMinorVersion;
|
||||
Standard mStandard;
|
||||
};
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
||||
#endif // DAWNNATIVE_OPENGL_OPENGLVERSION_H_
|
|
@ -77,12 +77,13 @@ namespace dawn_native { namespace opengl {
|
|||
options.vertex.flip_vert_y = true;
|
||||
options.vertex.fixup_clipspace = true;
|
||||
|
||||
// TODO(cwallez@chromium.org): discover the backing context version and use that.
|
||||
#if defined(DAWN_PLATFORM_APPLE)
|
||||
options.version = 410;
|
||||
#else
|
||||
options.version = 440;
|
||||
#endif
|
||||
const OpenGLVersion& version = ToBackend(GetDevice())->gl.GetVersion();
|
||||
if (version.IsDesktop()) {
|
||||
// The computation of GLSL version below only works for 3.3 and above.
|
||||
ASSERT(version.IsAtLeast(3, 3));
|
||||
}
|
||||
options.es = version.IsES();
|
||||
options.version = version.GetMajor() * 100 + version.GetMinor() * 10;
|
||||
|
||||
spirv_cross::CompilerGLSL compiler(GetSpirv());
|
||||
compiler.set_common_options(options);
|
||||
|
|
Loading…
Reference in New Issue