Skip to content

Commit 7c9d72e

Browse files
committed
Relocate the read-only property to OpenGLContext
This is a preparatory cleanup step to resolve a TSan warning ahead of a planned refactor of the OpenGLContext class. BUGS=[491522442]
1 parent e2b1957 commit 7c9d72e

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

filament/backend/src/opengl/OpenGLContext.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,22 @@ OpenGLContext::OpenGLContext(OpenGLPlatform& platform,
222222
#endif
223223
#endif
224224

225+
#if defined(BACKEND_OPENGL_VERSION_GL) || defined(GL_EXT_disjoint_timer_query)
226+
if (ext.EXT_disjoint_timer_query) {
227+
// timer queries are available
228+
if (bugs.dont_use_timer_query && platform.canCreateFence()) {
229+
mGpuTimerType = TimerQueryFactory::Type::Fence;
230+
} else {
231+
mGpuTimerType = TimerQueryFactory::Type::Native;
232+
}
233+
} else
234+
#endif
235+
if (platform.canCreateFence()) {
236+
mGpuTimerType = TimerQueryFactory::Type::Fence;
237+
} else {
238+
mGpuTimerType = TimerQueryFactory::Type::Fallback;
239+
}
240+
225241
// in practice KHR_Debug has never been useful, and actually is confusing. We keep this
226242
// only for our own debugging, in case we need it some day.
227243
#if false && !defined(NDEBUG) && defined(GL_KHR_debug)

filament/backend/src/opengl/OpenGLContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ class OpenGLContext final : public TimerQueryFactoryInterface {
159159

160160
ShaderModel getShaderModel() const noexcept { return mShaderModel; }
161161

162+
TimerQueryFactory::Type getGpuTimerType() const noexcept { return mGpuTimerType; }
163+
164+
bool isGpuTimeSupported() const noexcept {
165+
return getGpuTimerType() != TimerQueryFactory::Type::Fallback;
166+
}
167+
162168
void resetState() noexcept;
163169

164170
inline void useProgram(GLuint program) noexcept;
@@ -542,6 +548,8 @@ class OpenGLContext final : public TimerQueryFactoryInterface {
542548

543549
Platform::DriverConfig const mDriverConfig;
544550

551+
TimerQueryFactory::Type mGpuTimerType{ TimerQueryFactory::Type::Fallback };
552+
545553
void bindFramebufferResolved(GLenum target, GLuint buffer) noexcept;
546554

547555
const std::array<std::tuple<bool const&, char const*, char const*>, sizeof(bugs)> mBugDatabase{{

filament/backend/src/opengl/OpenGLDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2859,7 +2859,7 @@ bool OpenGLDriver::isFrameBufferFetchMultiSampleSupported() {
28592859
}
28602860

28612861
bool OpenGLDriver::isFrameTimeSupported() {
2862-
return TimerQueryFactory::isGpuTimeSupported();
2862+
return mContext.isGpuTimeSupported();
28632863
}
28642864

28652865
bool OpenGLDriver::isAutoDepthResolveSupported() {

filament/backend/src/opengl/OpenGLTimerQuery.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,34 +48,25 @@ class OpenGLDriver;
4848

4949
// ------------------------------------------------------------------------------------------------
5050

51-
bool TimerQueryFactory::mGpuTimeSupported = false;
52-
5351
TimerQueryFactoryInterface* TimerQueryFactory::init(
5452
OpenGLPlatform& platform, OpenGLContext& context) {
5553
(void)context;
5654

5755
TimerQueryFactoryInterface* impl = nullptr;
5856

59-
#if defined(BACKEND_OPENGL_VERSION_GL) || defined(GL_EXT_disjoint_timer_query)
60-
if (context.ext.EXT_disjoint_timer_query) {
61-
// timer queries are available
62-
if (context.bugs.dont_use_timer_query && platform.canCreateFence()) {
63-
// however, they don't work well, revert to using fences if we can.
64-
impl = new(std::nothrow) TimerQueryFenceFactory(platform);
65-
} else {
57+
switch (context.getGpuTimerType()) {
58+
case Type::Fallback: {
59+
impl = new(std::nothrow) TimerQueryFallbackFactory();
60+
break;
61+
}
62+
case Type::Native: {
6663
impl = new(std::nothrow) TimerQueryNativeFactory(context);
64+
break;
65+
}
66+
case Type::Fence: {
67+
impl = new(std::nothrow) TimerQueryFenceFactory(platform);
68+
break;
6769
}
68-
mGpuTimeSupported = true;
69-
} else
70-
#endif
71-
if (platform.canCreateFence()) {
72-
// no timer queries, but we can use fences
73-
impl = new(std::nothrow) TimerQueryFenceFactory(platform);
74-
mGpuTimeSupported = true;
75-
} else {
76-
// no queries, no fences -- that's a problem
77-
impl = new(std::nothrow) TimerQueryFallbackFactory();
78-
mGpuTimeSupported = false;
7970
}
8071
assert_invariant(impl);
8172
return impl;
@@ -100,8 +91,6 @@ TimerQueryResult TimerQueryFactoryInterface::getTimerQueryValue(
10091

10192
// ------------------------------------------------------------------------------------------------
10293

103-
#if defined(BACKEND_OPENGL_VERSION_GL) || defined(GL_EXT_disjoint_timer_query)
104-
10594
TimerQueryNativeFactory::TimerQueryNativeFactory(OpenGLContext& context)
10695
: mContext(context) {
10796
}
@@ -165,8 +154,6 @@ void TimerQueryNativeFactory::endTimeElapsedQuery(OpenGLDriver& driver, GLTimerQ
165154
});
166155
}
167156

168-
#endif
169-
170157
// ------------------------------------------------------------------------------------------------
171158

172159
TimerQueryFenceFactory::TimerQueryFenceFactory(OpenGLPlatform& platform)

filament/backend/src/opengl/OpenGLTimerQuery.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ struct GLTimerQuery : public HwTimerQuery {
6161
*/
6262

6363
class TimerQueryFactory {
64-
static bool mGpuTimeSupported;
6564
public:
65+
enum class Type {
66+
Fallback = 0,
67+
Native,
68+
Fence,
69+
};
70+
6671
static TimerQueryFactoryInterface* init(
6772
OpenGLPlatform& platform, OpenGLContext& context);
68-
69-
static bool isGpuTimeSupported() noexcept {
70-
return mGpuTimeSupported;
71-
}
7273
};
7374

7475
class TimerQueryFactoryInterface {
@@ -86,8 +87,6 @@ class TimerQueryFactoryInterface {
8687
static TimerQueryResult getTimerQueryValue(GLTimerQuery* tq, uint64_t* elapsedTime) noexcept;
8788
};
8889

89-
#if defined(BACKEND_OPENGL_VERSION_GL) || defined(GL_EXT_disjoint_timer_query)
90-
9190
class TimerQueryNativeFactory final : public TimerQueryFactoryInterface {
9291
public:
9392
explicit TimerQueryNativeFactory(OpenGLContext& context);
@@ -100,8 +99,6 @@ class TimerQueryNativeFactory final : public TimerQueryFactoryInterface {
10099
OpenGLContext& mContext;
101100
};
102101

103-
#endif
104-
105102
class TimerQueryFenceFactory final : public TimerQueryFactoryInterface {
106103
public:
107104
explicit TimerQueryFenceFactory(OpenGLPlatform& platform);

0 commit comments

Comments
 (0)