2011-10-19 20:43:20 +00:00
|
|
|
/*
|
2013-02-28 20:16:25 +00:00
|
|
|
* Copyright 2013 Google Inc.
|
2011-10-19 20:43:20 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/gl/GLTestContext.h"
|
2016-10-05 15:42:03 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "src/gpu/gl/GrGLUtil.h"
|
|
|
|
#include "tools/gpu/GpuTimer.h"
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2016-10-04 18:08:45 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-10-05 15:42:03 +00:00
|
|
|
class GLGpuTimer : public sk_gpu_test::GpuTimer {
|
|
|
|
public:
|
2016-11-03 18:40:50 +00:00
|
|
|
static std::unique_ptr<GLGpuTimer> MakeIfSupported(const sk_gpu_test::GLTestContext*);
|
2016-10-05 15:42:03 +00:00
|
|
|
|
|
|
|
QueryStatus checkQueryStatus(sk_gpu_test::PlatformTimerQuery) override;
|
|
|
|
std::chrono::nanoseconds getTimeElapsed(sk_gpu_test::PlatformTimerQuery) override;
|
|
|
|
void deleteQuery(sk_gpu_test::PlatformTimerQuery) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
GLGpuTimer(bool disjointSupport, const sk_gpu_test::GLTestContext*, const char* ext = "");
|
|
|
|
|
|
|
|
bool validate() const;
|
|
|
|
|
|
|
|
sk_gpu_test::PlatformTimerQuery onQueueTimerStart() const override;
|
|
|
|
void onQueueTimerStop(sk_gpu_test::PlatformTimerQuery) const override;
|
|
|
|
|
|
|
|
static constexpr GrGLenum GL_QUERY_RESULT = 0x8866;
|
|
|
|
static constexpr GrGLenum GL_QUERY_RESULT_AVAILABLE = 0x8867;
|
|
|
|
static constexpr GrGLenum GL_TIME_ELAPSED = 0x88bf;
|
|
|
|
static constexpr GrGLenum GL_GPU_DISJOINT = 0x8fbb;
|
|
|
|
|
|
|
|
typedef void (GR_GL_FUNCTION_TYPE* GLGetIntegervProc) (GrGLenum, GrGLint*);
|
|
|
|
typedef void (GR_GL_FUNCTION_TYPE* GLGenQueriesProc) (GrGLsizei, GrGLuint*);
|
|
|
|
typedef void (GR_GL_FUNCTION_TYPE* GLDeleteQueriesProc) (GrGLsizei, const GrGLuint*);
|
|
|
|
typedef void (GR_GL_FUNCTION_TYPE* GLBeginQueryProc) (GrGLenum, GrGLuint);
|
|
|
|
typedef void (GR_GL_FUNCTION_TYPE* GLEndQueryProc) (GrGLenum);
|
|
|
|
typedef void (GR_GL_FUNCTION_TYPE* GLGetQueryObjectuivProc) (GrGLuint, GrGLenum, GrGLuint*);
|
|
|
|
typedef void (GR_GL_FUNCTION_TYPE* GLGetQueryObjectui64vProc) (GrGLuint, GrGLenum, GrGLuint64*);
|
|
|
|
|
|
|
|
GLGetIntegervProc fGLGetIntegerv;
|
|
|
|
GLGenQueriesProc fGLGenQueries;
|
|
|
|
GLDeleteQueriesProc fGLDeleteQueries;
|
|
|
|
GLBeginQueryProc fGLBeginQuery;
|
|
|
|
GLEndQueryProc fGLEndQuery;
|
|
|
|
GLGetQueryObjectuivProc fGLGetQueryObjectuiv;
|
|
|
|
GLGetQueryObjectui64vProc fGLGetQueryObjectui64v;
|
|
|
|
|
|
|
|
|
|
|
|
typedef sk_gpu_test::GpuTimer INHERITED;
|
|
|
|
};
|
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<GLGpuTimer> GLGpuTimer::MakeIfSupported(const sk_gpu_test::GLTestContext* ctx) {
|
|
|
|
std::unique_ptr<GLGpuTimer> ret;
|
2016-10-05 15:42:03 +00:00
|
|
|
const GrGLInterface* gl = ctx->gl();
|
|
|
|
if (gl->fExtensions.has("GL_EXT_disjoint_timer_query")) {
|
|
|
|
ret.reset(new GLGpuTimer(true, ctx, "EXT"));
|
|
|
|
} else if (kGL_GrGLStandard == gl->fStandard &&
|
|
|
|
(GrGLGetVersion(gl) > GR_GL_VER(3,3) || gl->fExtensions.has("GL_ARB_timer_query"))) {
|
|
|
|
ret.reset(new GLGpuTimer(false, ctx));
|
|
|
|
} else if (gl->fExtensions.has("GL_EXT_timer_query")) {
|
|
|
|
ret.reset(new GLGpuTimer(false, ctx, "EXT"));
|
|
|
|
}
|
2016-11-03 18:40:50 +00:00
|
|
|
if (ret && !ret->validate()) {
|
|
|
|
ret = nullptr;
|
|
|
|
}
|
|
|
|
return ret;
|
2016-10-05 15:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLGpuTimer::GLGpuTimer(bool disjointSupport, const sk_gpu_test::GLTestContext* ctx, const char* ext)
|
|
|
|
: INHERITED(disjointSupport) {
|
|
|
|
ctx->getGLProcAddress(&fGLGetIntegerv, "glGetIntegerv");
|
|
|
|
ctx->getGLProcAddress(&fGLGenQueries, "glGenQueries", ext);
|
|
|
|
ctx->getGLProcAddress(&fGLDeleteQueries, "glDeleteQueries", ext);
|
|
|
|
ctx->getGLProcAddress(&fGLBeginQuery, "glBeginQuery", ext);
|
|
|
|
ctx->getGLProcAddress(&fGLEndQuery, "glEndQuery", ext);
|
|
|
|
ctx->getGLProcAddress(&fGLGetQueryObjectuiv, "glGetQueryObjectuiv", ext);
|
|
|
|
ctx->getGLProcAddress(&fGLGetQueryObjectui64v, "glGetQueryObjectui64v", ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLGpuTimer::validate() const {
|
|
|
|
return fGLGetIntegerv && fGLGenQueries && fGLDeleteQueries && fGLBeginQuery && fGLEndQuery &&
|
|
|
|
fGLGetQueryObjectuiv && fGLGetQueryObjectui64v;
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_gpu_test::PlatformTimerQuery GLGpuTimer::onQueueTimerStart() const {
|
|
|
|
GrGLuint queryID;
|
|
|
|
fGLGenQueries(1, &queryID);
|
|
|
|
if (!queryID) {
|
|
|
|
return sk_gpu_test::kInvalidTimerQuery;
|
|
|
|
}
|
|
|
|
if (this->disjointSupport()) {
|
|
|
|
// Clear the disjoint flag.
|
|
|
|
GrGLint disjoint;
|
|
|
|
fGLGetIntegerv(GL_GPU_DISJOINT, &disjoint);
|
|
|
|
}
|
|
|
|
fGLBeginQuery(GL_TIME_ELAPSED, queryID);
|
|
|
|
return static_cast<sk_gpu_test::PlatformTimerQuery>(queryID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLGpuTimer::onQueueTimerStop(sk_gpu_test::PlatformTimerQuery platformTimer) const {
|
|
|
|
if (sk_gpu_test::kInvalidTimerQuery == platformTimer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fGLEndQuery(GL_TIME_ELAPSED);
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_gpu_test::GpuTimer::QueryStatus
|
|
|
|
GLGpuTimer::checkQueryStatus(sk_gpu_test::PlatformTimerQuery platformTimer) {
|
|
|
|
const GrGLuint queryID = static_cast<GrGLuint>(platformTimer);
|
|
|
|
if (!queryID) {
|
|
|
|
return QueryStatus::kInvalid;
|
|
|
|
}
|
|
|
|
GrGLuint available = 0;
|
|
|
|
fGLGetQueryObjectuiv(queryID, GL_QUERY_RESULT_AVAILABLE, &available);
|
|
|
|
if (!available) {
|
|
|
|
return QueryStatus::kPending;
|
|
|
|
}
|
|
|
|
if (this->disjointSupport()) {
|
|
|
|
GrGLint disjoint = 1;
|
|
|
|
fGLGetIntegerv(GL_GPU_DISJOINT, &disjoint);
|
|
|
|
if (disjoint) {
|
|
|
|
return QueryStatus::kDisjoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QueryStatus::kAccurate;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::chrono::nanoseconds GLGpuTimer::getTimeElapsed(sk_gpu_test::PlatformTimerQuery platformTimer) {
|
|
|
|
SkASSERT(this->checkQueryStatus(platformTimer) >= QueryStatus::kDisjoint);
|
|
|
|
const GrGLuint queryID = static_cast<GrGLuint>(platformTimer);
|
|
|
|
GrGLuint64 nanoseconds;
|
|
|
|
fGLGetQueryObjectui64v(queryID, GL_QUERY_RESULT, &nanoseconds);
|
|
|
|
return std::chrono::nanoseconds(nanoseconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLGpuTimer::deleteQuery(sk_gpu_test::PlatformTimerQuery platformTimer) {
|
|
|
|
const GrGLuint queryID = static_cast<GrGLuint>(platformTimer);
|
|
|
|
fGLDeleteQueries(1, &queryID);
|
|
|
|
}
|
|
|
|
|
2019-12-18 15:43:10 +00:00
|
|
|
static_assert(sizeof(GrGLuint) <= sizeof(sk_gpu_test::PlatformTimerQuery));
|
2016-10-05 15:42:03 +00:00
|
|
|
|
2016-10-04 18:08:45 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
GLTestContext::GLTestContext() : TestContext() {}
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
GLTestContext::~GLTestContext() {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(nullptr == fGL.get());
|
2015-06-23 20:23:44 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
static bool fence_is_supported(const GLTestContext* ctx) {
|
|
|
|
if (kGL_GrGLStandard == ctx->gl()->fStandard) {
|
|
|
|
if (GrGLGetVersion(ctx->gl()) < GR_GL_VER(3, 2) &&
|
|
|
|
!ctx->gl()->hasExtension("GL_ARB_sync")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (ctx->gl()->hasExtension("GL_APPLE_sync")) {
|
|
|
|
return true;
|
|
|
|
} else if (ctx->gl()->hasExtension("GL_NV_fence")) {
|
|
|
|
return true;
|
|
|
|
} else if (GrGLGetVersion(ctx->gl()) >= GR_GL_VER(3, 0)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLTestContext::init(sk_sp<const GrGLInterface> gl) {
|
2017-12-11 15:06:31 +00:00
|
|
|
fGL = std::move(gl);
|
2020-02-21 20:46:27 +00:00
|
|
|
fFenceSupport = fence_is_supported(this);
|
2016-11-03 18:40:50 +00:00
|
|
|
fGpuTimer = GLGpuTimer::MakeIfSupported(this);
|
2015-06-23 20:23:44 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
void GLTestContext::teardown() {
|
2015-08-27 14:41:13 +00:00
|
|
|
fGL.reset(nullptr);
|
2016-05-11 17:09:18 +00:00
|
|
|
INHERITED::teardown();
|
2011-10-19 20:43:20 +00:00
|
|
|
}
|
2014-07-29 15:01:52 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
void GLTestContext::testAbandon() {
|
2016-05-11 17:09:18 +00:00
|
|
|
INHERITED::testAbandon();
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fGL) {
|
2014-07-29 15:01:52 +00:00
|
|
|
fGL->abandon();
|
|
|
|
}
|
2015-06-23 20:23:44 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 18:55:36 +00:00
|
|
|
void GLTestContext::finish() {
|
|
|
|
if (fGL) {
|
|
|
|
GR_GL_CALL(fGL.get(), Finish());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 17:33:08 +00:00
|
|
|
GrGLuint GLTestContext::createTextureRectangle(int width, int height, GrGLenum internalFormat,
|
|
|
|
GrGLenum externalFormat, GrGLenum externalType,
|
|
|
|
GrGLvoid* data) {
|
2018-07-12 21:13:35 +00:00
|
|
|
// Should match GrGLCaps check for fRectangleTextureSupport.
|
|
|
|
if (kGL_GrGLStandard != fGL->fStandard ||
|
|
|
|
(GrGLGetVersion(fGL.get()) < GR_GL_VER(3, 1) &&
|
|
|
|
!fGL->fExtensions.has("GL_ARB_texture_rectangle") &&
|
|
|
|
!fGL->fExtensions.has("GL_ANGLE_texture_rectangle"))) {
|
2016-01-14 17:24:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-01-20 14:18:10 +00:00
|
|
|
|
2016-11-03 20:26:13 +00:00
|
|
|
if (GrGLGetGLSLVersion(fGL.get()) < GR_GLSL_VER(1, 40)) {
|
2016-01-20 14:18:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-14 17:24:09 +00:00
|
|
|
GrGLuint id;
|
2016-11-03 20:26:13 +00:00
|
|
|
GR_GL_CALL(fGL.get(), GenTextures(1, &id));
|
|
|
|
GR_GL_CALL(fGL.get(), BindTexture(GR_GL_TEXTURE_RECTANGLE, id));
|
|
|
|
GR_GL_CALL(fGL.get(), TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MAG_FILTER,
|
|
|
|
GR_GL_NEAREST));
|
|
|
|
GR_GL_CALL(fGL.get(), TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FILTER,
|
|
|
|
GR_GL_NEAREST));
|
|
|
|
GR_GL_CALL(fGL.get(), TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S,
|
|
|
|
GR_GL_CLAMP_TO_EDGE));
|
|
|
|
GR_GL_CALL(fGL.get(), TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T,
|
|
|
|
GR_GL_CLAMP_TO_EDGE));
|
|
|
|
GR_GL_CALL(fGL.get(), TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width, height, 0,
|
|
|
|
externalFormat, externalType, data));
|
2016-01-14 17:24:09 +00:00
|
|
|
return id;
|
|
|
|
}
|
2017-07-25 14:05:01 +00:00
|
|
|
|
|
|
|
sk_sp<GrContext> GLTestContext::makeGrContext(const GrContextOptions& options) {
|
2017-12-07 17:33:05 +00:00
|
|
|
return GrContext::MakeGL(fGL, options);
|
2017-07-25 14:05:01 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
} // namespace sk_gpu_test
|