Update nanobench and skpbench to use flush API for gpu syncing.
This also allows us to remove all the one off Fence code that we
implemented in all the backend TestContexts
Change-Id: I9ff7ba4690cf3f19a180f51fc510991a112bb62c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/272456
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/tools/gpu/gl/GLTestContext.cpp b/tools/gpu/gl/GLTestContext.cpp
index fad8c4f..9126799 100644
--- a/tools/gpu/gl/GLTestContext.cpp
+++ b/tools/gpu/gl/GLTestContext.cpp
@@ -13,135 +13,6 @@
namespace {
-class GLFenceSync : public sk_gpu_test::FenceSync {
-public:
- static std::unique_ptr<FenceSync> MakeIfSupported(const sk_gpu_test::GLTestContext*);
-
- sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override;
- bool waitFence(sk_gpu_test::PlatformFence fence) const override;
- void deleteFence(sk_gpu_test::PlatformFence fence) const override;
-
-private:
- GLFenceSync(const sk_gpu_test::GLTestContext*, const char* ext = "");
-
- bool validate() const override { return fGLFenceSync && fGLClientWaitSync && fGLDeleteSync; }
-
- static constexpr GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117;
- static constexpr GrGLenum GL_WAIT_FAILED = 0x911d;
- static constexpr GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001;
-
- typedef struct __GLsync *GLsync;
- static_assert(sizeof(GLsync) <= sizeof(sk_gpu_test::PlatformFence));
-
- typedef GLsync (GR_GL_FUNCTION_TYPE* GLFenceSyncProc) (GrGLenum, GrGLbitfield);
- typedef GrGLenum (GR_GL_FUNCTION_TYPE* GLClientWaitSyncProc) (GLsync, GrGLbitfield, GrGLuint64);
- typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GLDeleteSyncProc) (GLsync);
-
- GLFenceSyncProc fGLFenceSync;
- GLClientWaitSyncProc fGLClientWaitSync;
- GLDeleteSyncProc fGLDeleteSync;
-
- typedef FenceSync INHERITED;
-};
-
-class GLNVFenceSync : public sk_gpu_test::FenceSync {
-public:
- GLNVFenceSync(const sk_gpu_test::GLTestContext*);
-
- sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override;
- bool waitFence(sk_gpu_test::PlatformFence fence) const override;
- void deleteFence(sk_gpu_test::PlatformFence fence) const override;
-
-private:
- bool validate() const override {
- return fGLGenFencesNV && fGLDeleteFencesNV && fGLSetFenceNV && fGLFinishFenceNV;
- }
-
- static constexpr GrGLenum GL_ALL_COMPLETED_NV = 0x84F2;
-
- typedef GrGLvoid(GR_GL_FUNCTION_TYPE* GLGenFencesNVProc) (GrGLsizei, GrGLuint*);
- typedef GrGLvoid(GR_GL_FUNCTION_TYPE* GLDeleteFencesNVProc) (GrGLsizei, const GrGLuint*);
- typedef GrGLvoid(GR_GL_FUNCTION_TYPE* GLSetFenceNVProc) (GrGLuint, GrGLenum);
- typedef GrGLvoid(GR_GL_FUNCTION_TYPE* GLFinishFenceNVProc) (GrGLuint);
-
- GLGenFencesNVProc fGLGenFencesNV;
- GLDeleteFencesNVProc fGLDeleteFencesNV;
- GLSetFenceNVProc fGLSetFenceNV;
- GLFinishFenceNVProc fGLFinishFenceNV;
-
- typedef FenceSync INHERITED;
-};
-
-std::unique_ptr<sk_gpu_test::FenceSync> GLFenceSync::MakeIfSupported(
- const sk_gpu_test::GLTestContext* ctx) {
- std::unique_ptr<FenceSync> ret;
- if (kGL_GrGLStandard == ctx->gl()->fStandard) {
- if (GrGLGetVersion(ctx->gl()) < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) {
- return nullptr;
- }
- ret.reset(new GLFenceSync(ctx));
- } else {
- if (ctx->gl()->hasExtension("GL_APPLE_sync")) {
- ret.reset(new GLFenceSync(ctx, "APPLE"));
- } else if (ctx->gl()->hasExtension("GL_NV_fence")) {
- ret.reset(new GLNVFenceSync(ctx));
- } else if (GrGLGetVersion(ctx->gl()) >= GR_GL_VER(3, 0)) {
- ret.reset(new GLFenceSync(ctx));
- } else {
- return nullptr;
- }
- }
- if (!ret->validate()) {
- ret = nullptr;
- }
- return ret;
-}
-
-GLFenceSync::GLFenceSync(const sk_gpu_test::GLTestContext* ctx, const char* ext) {
- ctx->getGLProcAddress(&fGLFenceSync, "glFenceSync", ext);
- ctx->getGLProcAddress(&fGLClientWaitSync, "glClientWaitSync", ext);
- ctx->getGLProcAddress(&fGLDeleteSync, "glDeleteSync", ext);
-}
-
-sk_gpu_test::PlatformFence GLFenceSync::insertFence() const {
- __GLsync* glsync = fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
- return reinterpret_cast<sk_gpu_test::PlatformFence>(glsync);
-}
-
-bool GLFenceSync::waitFence(sk_gpu_test::PlatformFence fence) const {
- GLsync glsync = reinterpret_cast<GLsync>(fence);
- return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BIT, -1);
-}
-
-void GLFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const {
- GLsync glsync = reinterpret_cast<GLsync>(fence);
- fGLDeleteSync(glsync);
-}
-
-GLNVFenceSync::GLNVFenceSync(const sk_gpu_test::GLTestContext* ctx) {
- ctx->getGLProcAddress(&fGLGenFencesNV, "glGenFencesNV");
- ctx->getGLProcAddress(&fGLDeleteFencesNV, "glDeleteFencesNV");
- ctx->getGLProcAddress(&fGLSetFenceNV, "glSetFenceNV");
- ctx->getGLProcAddress(&fGLFinishFenceNV, "glFinishFenceNV");
-}
-
-sk_gpu_test::PlatformFence GLNVFenceSync::insertFence() const {
- GrGLuint fence;
- fGLGenFencesNV(1, &fence);
- fGLSetFenceNV(fence, GL_ALL_COMPLETED_NV);
- return fence;
-}
-
-bool GLNVFenceSync::waitFence(sk_gpu_test::PlatformFence fence) const {
- fGLFinishFenceNV(fence);
- return true;
-}
-
-void GLNVFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const {
- GrGLuint glFence = static_cast<GrGLuint>(fence);
- fGLDeleteFencesNV(1, &glFence);
-}
-
class GLGpuTimer : public sk_gpu_test::GpuTimer {
public:
static std::unique_ptr<GLGpuTimer> MakeIfSupported(const sk_gpu_test::GLTestContext*);
@@ -284,9 +155,29 @@
SkASSERT(nullptr == fGL.get());
}
-void GLTestContext::init(sk_sp<const GrGLInterface> gl, std::unique_ptr<FenceSync> fenceSync) {
+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) {
fGL = std::move(gl);
- fFenceSync = fenceSync ? std::move(fenceSync) : GLFenceSync::MakeIfSupported(this);
+ fFenceSupport = fence_is_supported(this);
fGpuTimer = GLGpuTimer::MakeIfSupported(this);
}
@@ -302,12 +193,6 @@
}
}
-void GLTestContext::submit() {
- if (fGL) {
- GR_GL_CALL(fGL.get(), Flush());
- }
-}
-
void GLTestContext::finish() {
if (fGL) {
GR_GL_CALL(fGL.get(), Finish());