1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // FenceNVGL.cpp: Implements the class methods for FenceNVGL.
8
9 #include "libANGLE/renderer/gl/FenceNVGL.h"
10
11 #include "common/debug.h"
12 #include "libANGLE/Context.h"
13 #include "libANGLE/renderer/gl/ContextGL.h"
14 #include "libANGLE/renderer/gl/FunctionsGL.h"
15
16 namespace rx
17 {
18
FenceNVGL(const FunctionsGL * functions)19 FenceNVGL::FenceNVGL(const FunctionsGL *functions) : FenceNVImpl(), mFunctions(functions)
20 {
21 mFunctions->genFencesNV(1, &mFence);
22 }
23
~FenceNVGL()24 FenceNVGL::~FenceNVGL()
25 {
26 mFunctions->deleteFencesNV(1, &mFence);
27 mFence = 0;
28 }
29
set(const gl::Context * context,GLenum condition)30 angle::Result FenceNVGL::set(const gl::Context *context, GLenum condition)
31 {
32 ASSERT(condition == GL_ALL_COMPLETED_NV);
33 mFunctions->setFenceNV(mFence, condition);
34 return angle::Result::Continue;
35 }
36
test(const gl::Context * context,GLboolean * outFinished)37 angle::Result FenceNVGL::test(const gl::Context *context, GLboolean *outFinished)
38 {
39 ASSERT(outFinished);
40 *outFinished = mFunctions->testFenceNV(mFence);
41 return angle::Result::Continue;
42 }
43
finish(const gl::Context * context)44 angle::Result FenceNVGL::finish(const gl::Context *context)
45 {
46 mFunctions->finishFenceNV(mFence);
47 return angle::Result::Continue;
48 }
49
50 // static
Supported(const FunctionsGL * functions)51 bool FenceNVGL::Supported(const FunctionsGL *functions)
52 {
53 return functions->hasGLESExtension("GL_NV_fence") || functions->hasGLExtension("GL_NV_fence");
54 }
55
FenceNVSyncGL(const FunctionsGL * functions)56 FenceNVSyncGL::FenceNVSyncGL(const FunctionsGL *functions)
57 : FenceNVImpl(), mSyncObject(0), mFunctions(functions)
58 {}
59
~FenceNVSyncGL()60 FenceNVSyncGL::~FenceNVSyncGL()
61 {
62 if (mSyncObject != 0)
63 {
64 mFunctions->deleteSync(mSyncObject);
65 mSyncObject = 0;
66 }
67 }
68
set(const gl::Context * context,GLenum condition)69 angle::Result FenceNVSyncGL::set(const gl::Context *context, GLenum condition)
70 {
71 ASSERT(condition == GL_ALL_COMPLETED_NV);
72 mSyncObject = mFunctions->fenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
73 ANGLE_CHECK(GetImplAs<ContextGL>(context), mSyncObject != 0,
74 "glFenceSync failed to create a GLsync object.", GL_OUT_OF_MEMORY);
75 return angle::Result::Continue;
76 }
77
test(const gl::Context * context,GLboolean * outFinished)78 angle::Result FenceNVSyncGL::test(const gl::Context *context, GLboolean *outFinished)
79 {
80 ASSERT(mFunctions->isSync(mSyncObject));
81 GLint result = 0;
82 mFunctions->getSynciv(mSyncObject, GL_SYNC_STATUS, 1, nullptr, &result);
83 *outFinished = (result == GL_SIGNALED);
84 return angle::Result::Continue;
85 }
86
finish(const gl::Context * context)87 angle::Result FenceNVSyncGL::finish(const gl::Context *context)
88 {
89 ASSERT(mFunctions->isSync(mSyncObject));
90 GLenum result =
91 mFunctions->clientWaitSync(mSyncObject, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED);
92 ANGLE_CHECK(GetImplAs<ContextGL>(context),
93 result == GL_ALREADY_SIGNALED || result == GL_CONDITION_SATISFIED,
94 "glClientWaitSync did not return GL_ALREADY_SIGNALED or GL_CONDITION_SATISFIED.",
95 GL_OUT_OF_MEMORY);
96 return angle::Result::Continue;
97 }
98
99 // static
Supported(const FunctionsGL * functions)100 bool FenceNVSyncGL::Supported(const FunctionsGL *functions)
101 {
102 return functions->isAtLeastGL(gl::Version(3, 2)) ||
103 functions->isAtLeastGLES(gl::Version(3, 0)) || functions->hasGLExtension("GL_ARB_sync");
104 }
105
106 } // namespace rx
107