1 //
2 // Copyright 2019 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 #include "libANGLE/renderer/gl/SemaphoreGL.h"
8
9 #include "libANGLE/Context.h"
10 #include "libANGLE/renderer/gl/BufferGL.h"
11 #include "libANGLE/renderer/gl/ContextGL.h"
12 #include "libANGLE/renderer/gl/FunctionsGL.h"
13 #include "libANGLE/renderer/gl/TextureGL.h"
14 #include "libANGLE/renderer/gl/renderergl_utils.h"
15
16 namespace rx
17 {
18 namespace
19 {
GatherNativeBufferIDs(const gl::BufferBarrierVector & bufferBarriers,gl::BarrierVector<GLuint> * outIDs)20 void GatherNativeBufferIDs(const gl::BufferBarrierVector &bufferBarriers,
21 gl::BarrierVector<GLuint> *outIDs)
22 {
23 outIDs->resize(bufferBarriers.size());
24 for (GLuint bufferIdx = 0; bufferIdx < bufferBarriers.size(); bufferIdx++)
25 {
26 (*outIDs)[bufferIdx] = GetImplAs<BufferGL>(bufferBarriers[bufferIdx])->getBufferID();
27 }
28 }
29
GatherNativeTextureIDs(const gl::TextureBarrierVector & textureBarriers,gl::BarrierVector<GLuint> * outIDs,gl::BarrierVector<GLenum> * outLayouts)30 void GatherNativeTextureIDs(const gl::TextureBarrierVector &textureBarriers,
31 gl::BarrierVector<GLuint> *outIDs,
32 gl::BarrierVector<GLenum> *outLayouts)
33 {
34 outIDs->resize(textureBarriers.size());
35 outLayouts->resize(textureBarriers.size());
36 for (GLuint textureIdx = 0; textureIdx < textureBarriers.size(); textureIdx++)
37 {
38 (*outIDs)[textureIdx] =
39 GetImplAs<TextureGL>(textureBarriers[textureIdx].texture)->getTextureID();
40 (*outLayouts)[textureIdx] = textureBarriers[textureIdx].layout;
41 }
42 }
43
44 } // anonymous namespace
45
SemaphoreGL(GLuint semaphoreID)46 SemaphoreGL::SemaphoreGL(GLuint semaphoreID) : mSemaphoreID(semaphoreID)
47 {
48 ASSERT(mSemaphoreID != 0);
49 }
50
~SemaphoreGL()51 SemaphoreGL::~SemaphoreGL()
52 {
53 ASSERT(mSemaphoreID == 0);
54 }
55
onDestroy(const gl::Context * context)56 void SemaphoreGL::onDestroy(const gl::Context *context)
57 {
58 const FunctionsGL *functions = GetFunctionsGL(context);
59 functions->deleteSemaphoresEXT(1, &mSemaphoreID);
60 mSemaphoreID = 0;
61 }
62
importFd(gl::Context * context,gl::HandleType handleType,GLint fd)63 angle::Result SemaphoreGL::importFd(gl::Context *context, gl::HandleType handleType, GLint fd)
64 {
65 const FunctionsGL *functions = GetFunctionsGL(context);
66 functions->importSemaphoreFdEXT(mSemaphoreID, ToGLenum(handleType), fd);
67 return angle::Result::Continue;
68 }
69
importZirconHandle(gl::Context * context,gl::HandleType handleType,GLuint handle)70 angle::Result SemaphoreGL::importZirconHandle(gl::Context *context,
71 gl::HandleType handleType,
72 GLuint handle)
73 {
74 UNREACHABLE();
75 return angle::Result::Stop;
76 }
77
wait(gl::Context * context,const gl::BufferBarrierVector & bufferBarriers,const gl::TextureBarrierVector & textureBarriers)78 angle::Result SemaphoreGL::wait(gl::Context *context,
79 const gl::BufferBarrierVector &bufferBarriers,
80 const gl::TextureBarrierVector &textureBarriers)
81 {
82 const FunctionsGL *functions = GetFunctionsGL(context);
83
84 gl::BarrierVector<GLuint> bufferIDs(bufferBarriers.size());
85 GatherNativeBufferIDs(bufferBarriers, &bufferIDs);
86
87 gl::BarrierVector<GLuint> textureIDs(textureBarriers.size());
88 gl::BarrierVector<GLenum> textureLayouts(textureBarriers.size());
89 GatherNativeTextureIDs(textureBarriers, &textureIDs, &textureLayouts);
90 ASSERT(textureIDs.size() == textureLayouts.size());
91
92 functions->waitSemaphoreEXT(mSemaphoreID, static_cast<GLuint>(bufferIDs.size()),
93 bufferIDs.data(), static_cast<GLuint>(textureIDs.size()),
94 textureIDs.data(), textureLayouts.data());
95
96 return angle::Result::Continue;
97 }
98
signal(gl::Context * context,const gl::BufferBarrierVector & bufferBarriers,const gl::TextureBarrierVector & textureBarriers)99 angle::Result SemaphoreGL::signal(gl::Context *context,
100 const gl::BufferBarrierVector &bufferBarriers,
101 const gl::TextureBarrierVector &textureBarriers)
102 {
103 const FunctionsGL *functions = GetFunctionsGL(context);
104
105 gl::BarrierVector<GLuint> bufferIDs(bufferBarriers.size());
106 GatherNativeBufferIDs(bufferBarriers, &bufferIDs);
107
108 gl::BarrierVector<GLuint> textureIDs(textureBarriers.size());
109 gl::BarrierVector<GLenum> textureLayouts(textureBarriers.size());
110 GatherNativeTextureIDs(textureBarriers, &textureIDs, &textureLayouts);
111 ASSERT(textureIDs.size() == textureLayouts.size());
112
113 functions->signalSemaphoreEXT(mSemaphoreID, static_cast<GLuint>(bufferIDs.size()),
114 bufferIDs.data(), static_cast<GLuint>(textureIDs.size()),
115 textureIDs.data(), textureLayouts.data());
116
117 return angle::Result::Continue;
118 }
119
getSemaphoreID() const120 GLuint SemaphoreGL::getSemaphoreID() const
121 {
122 return mSemaphoreID;
123 }
124 } // namespace rx
125