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 ContextGL *contextGL = GetImplAs<ContextGL>(context);
34 mFunctions->setFenceNV(mFence, condition);
35 contextGL->markWorkSubmitted();
36 return angle::Result::Continue;
37 }
38
test(const gl::Context * context,GLboolean * outFinished)39 angle::Result FenceNVGL::test(const gl::Context *context, GLboolean *outFinished)
40 {
41 ASSERT(outFinished);
42 *outFinished = mFunctions->testFenceNV(mFence);
43 return angle::Result::Continue;
44 }
45
finish(const gl::Context * context)46 angle::Result FenceNVGL::finish(const gl::Context *context)
47 {
48 mFunctions->finishFenceNV(mFence);
49 return angle::Result::Continue;
50 }
51
52 // static
Supported(const FunctionsGL * functions)53 bool FenceNVGL::Supported(const FunctionsGL *functions)
54 {
55 return functions->hasGLESExtension("GL_NV_fence") || functions->hasGLExtension("GL_NV_fence");
56 }
57
FenceNVSyncGL(const FunctionsGL * functions)58 FenceNVSyncGL::FenceNVSyncGL(const FunctionsGL *functions)
59 : FenceNVImpl(), mSyncObject(0), mFunctions(functions)
60 {}
61
~FenceNVSyncGL()62 FenceNVSyncGL::~FenceNVSyncGL()
63 {
64 if (mSyncObject != 0)
65 {
66 mFunctions->deleteSync(mSyncObject);
67 mSyncObject = 0;
68 }
69 }
70
set(const gl::Context * context,GLenum condition)71 angle::Result FenceNVSyncGL::set(const gl::Context *context, GLenum condition)
72 {
73 ASSERT(condition == GL_ALL_COMPLETED_NV);
74 ContextGL *contextGL = GetImplAs<ContextGL>(context);
75 mSyncObject = mFunctions->fenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
76 ANGLE_CHECK(contextGL, mSyncObject != 0, "glFenceSync failed to create a GLsync object.",
77 GL_OUT_OF_MEMORY);
78 contextGL->markWorkSubmitted();
79 return angle::Result::Continue;
80 }
81
test(const gl::Context * context,GLboolean * outFinished)82 angle::Result FenceNVSyncGL::test(const gl::Context *context, GLboolean *outFinished)
83 {
84 ASSERT(mFunctions->isSync(mSyncObject));
85 GLint result = 0;
86 mFunctions->getSynciv(mSyncObject, GL_SYNC_STATUS, 1, nullptr, &result);
87 *outFinished = (result == GL_SIGNALED);
88 return angle::Result::Continue;
89 }
90
finish(const gl::Context * context)91 angle::Result FenceNVSyncGL::finish(const gl::Context *context)
92 {
93 ASSERT(mFunctions->isSync(mSyncObject));
94 GLenum result =
95 mFunctions->clientWaitSync(mSyncObject, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED);
96 ANGLE_CHECK(GetImplAs<ContextGL>(context),
97 result == GL_ALREADY_SIGNALED || result == GL_CONDITION_SATISFIED,
98 "glClientWaitSync did not return GL_ALREADY_SIGNALED or GL_CONDITION_SATISFIED.",
99 GL_OUT_OF_MEMORY);
100 return angle::Result::Continue;
101 }
102
103 // static
Supported(const FunctionsGL * functions)104 bool FenceNVSyncGL::Supported(const FunctionsGL *functions)
105 {
106 return functions->isAtLeastGL(gl::Version(3, 2)) ||
107 functions->isAtLeastGLES(gl::Version(3, 0)) || functions->hasGLExtension("GL_ARB_sync");
108 }
109
110 } // namespace rx
111