blob: 14e547621f6c84ab06202347e9033958b6348f0c [file] [log] [blame]
Geoff Langf9a6f082015-01-22 13:32:49 -05001//
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// VertexArrayGL.cpp: Implements the class methods for VertexArrayGL.
8
9#include "libANGLE/renderer/gl/VertexArrayGL.h"
10
Jamie Madill20e005b2017-04-07 14:19:22 -040011#include "common/bitset_utils.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050012#include "common/debug.h"
Geoff Lang7c82bc42015-03-09 16:18:08 -040013#include "common/mathutil.h"
Geoff Lang831b1952015-05-05 11:02:27 -040014#include "common/utilities.h"
Geoff Lang6ae6efc2015-03-09 14:42:35 -040015#include "libANGLE/Buffer.h"
Jamie Madilldc358af2018-07-31 11:22:13 -040016#include "libANGLE/Context.h"
Geoff Langba4c4a82015-02-24 12:38:46 -050017#include "libANGLE/angletypes.h"
Geoff Lang7c82bc42015-03-09 16:18:08 -040018#include "libANGLE/formatutils.h"
Geoff Langba4c4a82015-02-24 12:38:46 -050019#include "libANGLE/renderer/gl/BufferGL.h"
Jamie Madille39e8f42018-10-05 08:17:38 -040020#include "libANGLE/renderer/gl/ContextGL.h"
Geoff Langba4c4a82015-02-24 12:38:46 -050021#include "libANGLE/renderer/gl/FunctionsGL.h"
22#include "libANGLE/renderer/gl/StateManagerGL.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040023#include "libANGLE/renderer/gl/renderergl_utils.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050024
Jamie Madill0b9e9032015-08-17 11:51:52 +000025using namespace gl;
26
Geoff Langf9a6f082015-01-22 13:32:49 -050027namespace rx
28{
Jamie Madill0b9e9032015-08-17 11:51:52 +000029namespace
30{
Shaodf682a82017-03-31 15:13:21 +080031bool SameVertexAttribFormat(const VertexAttribute &a, const VertexAttribute &b)
32{
33 return a.size == b.size && a.type == b.type && a.normalized == b.normalized &&
34 a.pureInteger == b.pureInteger && a.relativeOffset == b.relativeOffset;
35}
36
37bool SameVertexBuffer(const VertexBinding &a, const VertexBinding &b)
38{
Martin Radevdd5f27e2017-06-07 10:17:09 +030039 return a.getStride() == b.getStride() && a.getOffset() == b.getOffset() &&
40 a.getBuffer().get() == b.getBuffer().get();
Shaodf682a82017-03-31 15:13:21 +080041}
42
43bool IsVertexAttribPointerSupported(size_t attribIndex, const VertexAttribute &attrib)
44{
45 return (attribIndex == attrib.bindingIndex && attrib.relativeOffset == 0);
46}
Martin Radev553590a2017-07-31 16:40:39 +030047
48GLuint GetAdjustedDivisor(GLuint numViews, GLuint divisor)
49{
50 return numViews * divisor;
51}
52
Jamie Madill0b9e9032015-08-17 11:51:52 +000053} // anonymous namespace
54
Jamie Madill3f572682016-04-26 13:41:36 -040055VertexArrayGL::VertexArrayGL(const VertexArrayState &state,
Jamie Madill77a90c22015-08-11 16:33:17 -040056 const FunctionsGL *functions,
57 StateManagerGL *stateManager)
Jamie Madill3f572682016-04-26 13:41:36 -040058 : VertexArrayImpl(state),
Geoff Langba4c4a82015-02-24 12:38:46 -050059 mFunctions(functions),
60 mStateManager(stateManager),
61 mVertexArrayID(0),
Martin Radev553590a2017-07-31 16:40:39 +030062 mAppliedNumViews(1),
Jamie Madill77a90c22015-08-11 16:33:17 -040063 mAppliedElementArrayBuffer(),
Jiawei-Shao2597fb62016-12-09 16:38:02 +080064 mAppliedBindings(state.getMaxBindings()),
Geoff Lang7c82bc42015-03-09 16:18:08 -040065 mStreamingElementArrayBufferSize(0),
66 mStreamingElementArrayBuffer(0),
67 mStreamingArrayBufferSize(0),
68 mStreamingArrayBuffer(0)
Geoff Langba4c4a82015-02-24 12:38:46 -050069{
70 ASSERT(mFunctions);
71 ASSERT(mStateManager);
72 mFunctions->genVertexArrays(1, &mVertexArrayID);
73
Jiawei-Shao2597fb62016-12-09 16:38:02 +080074 // Set the cached vertex attribute array and vertex attribute binding array size
75 GLuint maxVertexAttribs = static_cast<GLuint>(state.getMaxAttribs());
76 for (GLuint i = 0; i < maxVertexAttribs; i++)
77 {
78 mAppliedAttributes.emplace_back(i);
79 }
Geoff Langba4c4a82015-02-24 12:38:46 -050080}
Geoff Langf9a6f082015-01-22 13:32:49 -050081
Jamie Madillb980c562018-11-27 11:34:27 -050082VertexArrayGL::~VertexArrayGL() {}
Jamie Madillacf2f3a2017-11-21 19:22:44 -050083
Jamie Madill4928b7c2017-06-20 12:57:39 -040084void VertexArrayGL::destroy(const gl::Context *context)
Geoff Langba4c4a82015-02-24 12:38:46 -050085{
Geoff Lang1eb708e2015-05-04 14:58:23 -040086 mStateManager->deleteVertexArray(mVertexArrayID);
Jamie Madille4634a12018-11-14 09:54:35 -050087 mVertexArrayID = 0;
Martin Radev553590a2017-07-31 16:40:39 +030088 mAppliedNumViews = 1;
Geoff Langba4c4a82015-02-24 12:38:46 -050089
Geoff Lang1eb708e2015-05-04 14:58:23 -040090 mStateManager->deleteBuffer(mStreamingElementArrayBuffer);
91 mStreamingElementArrayBufferSize = 0;
Shao80957d92017-02-20 21:25:59 +080092 mStreamingElementArrayBuffer = 0;
Geoff Lang7c82bc42015-03-09 16:18:08 -040093
Geoff Lang1eb708e2015-05-04 14:58:23 -040094 mStateManager->deleteBuffer(mStreamingArrayBuffer);
95 mStreamingArrayBufferSize = 0;
Shao80957d92017-02-20 21:25:59 +080096 mStreamingArrayBuffer = 0;
Geoff Lang7c82bc42015-03-09 16:18:08 -040097
Jamie Madill4928b7c2017-06-20 12:57:39 -040098 mAppliedElementArrayBuffer.set(context, nullptr);
Jiawei-Shao2597fb62016-12-09 16:38:02 +080099 for (auto &binding : mAppliedBindings)
Geoff Langba4c4a82015-02-24 12:38:46 -0500100 {
James Darpiniane8a93c62018-01-04 18:02:24 -0800101 binding.setBuffer(context, nullptr, false);
Geoff Langba4c4a82015-02-24 12:38:46 -0500102 }
103}
Geoff Langf9a6f082015-01-22 13:32:49 -0500104
Jamie Madill0cc11c62018-10-12 18:07:18 -0400105angle::Result VertexArrayGL::syncClientSideData(const gl::Context *context,
106 const gl::AttributesMask &activeAttributesMask,
107 GLint first,
108 GLsizei count,
109 GLsizei instanceCount) const
Geoff Lang7c82bc42015-03-09 16:18:08 -0400110{
Jamie Madill8dc27f92018-11-29 11:45:44 -0500111 return syncDrawState(context, activeAttributesMask, first, count,
112 gl::DrawElementsType::InvalidEnum, nullptr, instanceCount, false, nullptr);
Geoff Lang7c82bc42015-03-09 16:18:08 -0400113}
114
Jamie Madille39e8f42018-10-05 08:17:38 -0400115angle::Result VertexArrayGL::syncDrawElementsState(const gl::Context *context,
116 const gl::AttributesMask &activeAttributesMask,
117 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -0500118 gl::DrawElementsType type,
Jamie Madille39e8f42018-10-05 08:17:38 -0400119 const void *indices,
120 GLsizei instanceCount,
121 bool primitiveRestartEnabled,
122 const void **outIndices) const
Geoff Lang7c82bc42015-03-09 16:18:08 -0400123{
Jamie Madill4928b7c2017-06-20 12:57:39 -0400124 return syncDrawState(context, activeAttributesMask, 0, count, type, indices, instanceCount,
Geoff Lang3edfe032015-09-04 16:38:24 -0400125 primitiveRestartEnabled, outIndices);
Geoff Lang7c82bc42015-03-09 16:18:08 -0400126}
127
Jiajia Qin47474142017-12-29 13:41:00 +0800128void VertexArrayGL::updateElementArrayBufferBinding(const gl::Context *context) const
Jiajia Qind9671222016-11-29 16:30:31 +0800129{
Jamie Madillcd0a0a32018-10-18 18:41:57 -0400130 gl::Buffer *elementArrayBuffer = mState.getElementArrayBuffer();
Jiajia Qin47474142017-12-29 13:41:00 +0800131 if (elementArrayBuffer != nullptr && elementArrayBuffer != mAppliedElementArrayBuffer.get())
Jiajia Qind9671222016-11-29 16:30:31 +0800132 {
133 const BufferGL *bufferGL = GetImplAs<BufferGL>(elementArrayBuffer);
Corentin Wallez336129f2017-10-17 15:55:40 -0400134 mStateManager->bindBuffer(gl::BufferBinding::ElementArray, bufferGL->getBufferID());
Jamie Madill4928b7c2017-06-20 12:57:39 -0400135 mAppliedElementArrayBuffer.set(context, elementArrayBuffer);
Jiajia Qind9671222016-11-29 16:30:31 +0800136 }
Jiajia Qind9671222016-11-29 16:30:31 +0800137}
138
Jamie Madille39e8f42018-10-05 08:17:38 -0400139angle::Result VertexArrayGL::syncDrawState(const gl::Context *context,
140 const gl::AttributesMask &activeAttributesMask,
141 GLint first,
142 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -0500143 gl::DrawElementsType type,
Jamie Madille39e8f42018-10-05 08:17:38 -0400144 const void *indices,
145 GLsizei instanceCount,
146 bool primitiveRestartEnabled,
147 const void **outIndices) const
Geoff Lang6ae6efc2015-03-09 14:42:35 -0400148{
Shao80957d92017-02-20 21:25:59 +0800149 // Check if any attributes need to be streamed, determines if the index range needs to be
150 // computed
Jamie Madillbcef3222018-04-13 15:19:11 -0400151 const gl::AttributesMask &needsStreamingAttribs =
Jamie Madilldc358af2018-07-31 11:22:13 -0400152 context->getStateCache().getActiveClientAttribsMask();
Geoff Lang7c82bc42015-03-09 16:18:08 -0400153
Shao80957d92017-02-20 21:25:59 +0800154 // Determine if an index buffer needs to be streamed and the range of vertices that need to be
155 // copied
Geoff Lang3edfe032015-09-04 16:38:24 -0400156 IndexRange indexRange;
Jamie Madill8dc27f92018-11-29 11:45:44 -0500157 if (type != gl::DrawElementsType::InvalidEnum)
Geoff Langba4c4a82015-02-24 12:38:46 -0500158 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400159 ANGLE_TRY(syncIndexData(context, count, type, indices, primitiveRestartEnabled,
Jamie Madillbcef3222018-04-13 15:19:11 -0400160 needsStreamingAttribs.any(), &indexRange, outIndices));
Geoff Lang7c82bc42015-03-09 16:18:08 -0400161 }
162 else
163 {
Corentin Wallez2c34a4b2015-08-25 16:26:02 -0400164 // Not an indexed call, set the range to [first, first + count - 1]
Geoff Lang7c82bc42015-03-09 16:18:08 -0400165 indexRange.start = first;
Shao80957d92017-02-20 21:25:59 +0800166 indexRange.end = first + count - 1;
Geoff Langba4c4a82015-02-24 12:38:46 -0500167 }
168
Jamie Madillbcef3222018-04-13 15:19:11 -0400169 if (needsStreamingAttribs.any())
Geoff Langba4c4a82015-02-24 12:38:46 -0500170 {
Jamie Madille39e8f42018-10-05 08:17:38 -0400171 ANGLE_TRY(streamAttributes(context, needsStreamingAttribs, instanceCount, indexRange));
Geoff Lang7c82bc42015-03-09 16:18:08 -0400172 }
173
Jamie Madille39e8f42018-10-05 08:17:38 -0400174 return angle::Result::Continue();
Geoff Lang7c82bc42015-03-09 16:18:08 -0400175}
176
Jamie Madille39e8f42018-10-05 08:17:38 -0400177angle::Result VertexArrayGL::syncIndexData(const gl::Context *context,
178 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -0500179 gl::DrawElementsType type,
Jamie Madille39e8f42018-10-05 08:17:38 -0400180 const void *indices,
181 bool primitiveRestartEnabled,
182 bool attributesNeedStreaming,
183 IndexRange *outIndexRange,
184 const void **outIndices) const
Geoff Lang7c82bc42015-03-09 16:18:08 -0400185{
186 ASSERT(outIndices);
187
Jamie Madillcd0a0a32018-10-18 18:41:57 -0400188 gl::Buffer *elementArrayBuffer = mState.getElementArrayBuffer();
Jamie Madill8e344942015-07-09 14:22:07 -0400189
Geoff Lang7c82bc42015-03-09 16:18:08 -0400190 // Need to check the range of indices if attributes need to be streamed
Jamie Madill8e344942015-07-09 14:22:07 -0400191 if (elementArrayBuffer != nullptr)
Geoff Lang7c82bc42015-03-09 16:18:08 -0400192 {
Jiajia Qin47474142017-12-29 13:41:00 +0800193 ASSERT(elementArrayBuffer == mAppliedElementArrayBuffer.get());
Geoff Lang7c82bc42015-03-09 16:18:08 -0400194 // Only compute the index range if the attributes also need to be streamed
195 if (attributesNeedStreaming)
196 {
197 ptrdiff_t elementArrayBufferOffset = reinterpret_cast<ptrdiff_t>(indices);
Jamie Madill526392d2018-11-16 09:35:14 -0500198 ANGLE_TRY(mState.getElementArrayBuffer()->getIndexRange(
199 context, type, elementArrayBufferOffset, count, primitiveRestartEnabled,
200 outIndexRange));
Geoff Lang7c82bc42015-03-09 16:18:08 -0400201 }
202
Shao80957d92017-02-20 21:25:59 +0800203 // Indices serves as an offset into the index buffer in this case, use the same value for
204 // the draw call
Geoff Lang7c82bc42015-03-09 16:18:08 -0400205 *outIndices = indices;
206 }
207 else
208 {
209 // Need to stream the index buffer
210 // TODO: if GLES, nothing needs to be streamed
211
212 // Only compute the index range if the attributes also need to be streamed
213 if (attributesNeedStreaming)
214 {
Geoff Lang3edfe032015-09-04 16:38:24 -0400215 *outIndexRange = ComputeIndexRange(type, indices, count, primitiveRestartEnabled);
Geoff Lang7c82bc42015-03-09 16:18:08 -0400216 }
217
218 // Allocate the streaming element array buffer
219 if (mStreamingElementArrayBuffer == 0)
220 {
221 mFunctions->genBuffers(1, &mStreamingElementArrayBuffer);
222 mStreamingElementArrayBufferSize = 0;
223 }
224
Geoff Lang5f3047c2018-02-14 14:39:12 -0500225 mStateManager->bindVertexArray(mVertexArrayID, getAppliedElementArrayBufferID());
226
Corentin Wallez336129f2017-10-17 15:55:40 -0400227 mStateManager->bindBuffer(gl::BufferBinding::ElementArray, mStreamingElementArrayBuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400228 mAppliedElementArrayBuffer.set(context, nullptr);
Geoff Lang7c82bc42015-03-09 16:18:08 -0400229
230 // Make sure the element array buffer is large enough
Jamie Madill8dc27f92018-11-29 11:45:44 -0500231 const GLuint indexTypeBytes = gl::GetDrawElementsTypeSize(type);
232 size_t requiredStreamingBufferSize = indexTypeBytes * count;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400233 if (requiredStreamingBufferSize > mStreamingElementArrayBufferSize)
234 {
235 // Copy the indices in while resizing the buffer
Shao80957d92017-02-20 21:25:59 +0800236 mFunctions->bufferData(GL_ELEMENT_ARRAY_BUFFER, requiredStreamingBufferSize, indices,
237 GL_DYNAMIC_DRAW);
Geoff Lang7c82bc42015-03-09 16:18:08 -0400238 mStreamingElementArrayBufferSize = requiredStreamingBufferSize;
239 }
240 else
241 {
242 // Put the indices at the beginning of the buffer
Shao80957d92017-02-20 21:25:59 +0800243 mFunctions->bufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, requiredStreamingBufferSize,
244 indices);
Geoff Lang7c82bc42015-03-09 16:18:08 -0400245 }
246
Shao80957d92017-02-20 21:25:59 +0800247 // Set the index offset for the draw call to zero since the supplied index pointer is to
248 // client data
Geoff Lang7c82bc42015-03-09 16:18:08 -0400249 *outIndices = nullptr;
250 }
251
Jamie Madille39e8f42018-10-05 08:17:38 -0400252 return angle::Result::Continue();
Geoff Lang7c82bc42015-03-09 16:18:08 -0400253}
254
Jamie Madillbcef3222018-04-13 15:19:11 -0400255void VertexArrayGL::computeStreamingAttributeSizes(const gl::AttributesMask &attribsToStream,
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400256 GLsizei instanceCount,
Geoff Lang3edfe032015-09-04 16:38:24 -0400257 const gl::IndexRange &indexRange,
Jamie Madill0b9e9032015-08-17 11:51:52 +0000258 size_t *outStreamingDataSize,
259 size_t *outMaxAttributeDataSize) const
Geoff Lang7c82bc42015-03-09 16:18:08 -0400260{
Jamie Madill0b9e9032015-08-17 11:51:52 +0000261 *outStreamingDataSize = 0;
262 *outMaxAttributeDataSize = 0;
263
Jamie Madillbcef3222018-04-13 15:19:11 -0400264 ASSERT(attribsToStream.any());
Jamie Madill0b9e9032015-08-17 11:51:52 +0000265
Jamie Madill492f58e2017-10-09 19:41:33 -0400266 const auto &attribs = mState.getVertexAttributes();
267 const auto &bindings = mState.getVertexBindings();
Jamie Madill6de51852017-04-12 09:53:01 -0400268
Jamie Madill6de51852017-04-12 09:53:01 -0400269 for (auto idx : attribsToStream)
Jamie Madill0b9e9032015-08-17 11:51:52 +0000270 {
Shao80957d92017-02-20 21:25:59 +0800271 const auto &attrib = attribs[idx];
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800272 const auto &binding = bindings[attrib.bindingIndex];
Jamie Madill0b9e9032015-08-17 11:51:52 +0000273
Jamie Madill0b9e9032015-08-17 11:51:52 +0000274 // If streaming is going to be required, compute the size of the required buffer
275 // and how much slack space at the beginning of the buffer will be required by determining
276 // the attribute with the largest data size.
Jamie Madille4634a12018-11-14 09:54:35 -0500277 size_t typeSize = ComputeVertexAttributeTypeSize(attrib);
Martin Radev553590a2017-07-31 16:40:39 +0300278 GLuint adjustedDivisor = GetAdjustedDivisor(mAppliedNumViews, binding.getDivisor());
279 *outStreamingDataSize +=
280 typeSize * ComputeVertexBindingElementCount(adjustedDivisor, indexRange.vertexCount(),
281 instanceCount);
Jamie Madill0b9e9032015-08-17 11:51:52 +0000282 *outMaxAttributeDataSize = std::max(*outMaxAttributeDataSize, typeSize);
283 }
284}
285
Jamie Madille39e8f42018-10-05 08:17:38 -0400286angle::Result VertexArrayGL::streamAttributes(const gl::Context *context,
287 const gl::AttributesMask &attribsToStream,
288 GLsizei instanceCount,
289 const gl::IndexRange &indexRange) const
Jamie Madill0b9e9032015-08-17 11:51:52 +0000290{
291 // Sync the vertex attribute state and track what data needs to be streamed
292 size_t streamingDataSize = 0;
293 size_t maxAttributeDataSize = 0;
294
Jamie Madillbcef3222018-04-13 15:19:11 -0400295 computeStreamingAttributeSizes(attribsToStream, instanceCount, indexRange, &streamingDataSize,
296 &maxAttributeDataSize);
Jamie Madill0b9e9032015-08-17 11:51:52 +0000297
298 if (streamingDataSize == 0)
299 {
Jamie Madille39e8f42018-10-05 08:17:38 -0400300 return angle::Result::Continue();
Jamie Madill0b9e9032015-08-17 11:51:52 +0000301 }
302
Geoff Lang7c82bc42015-03-09 16:18:08 -0400303 if (mStreamingArrayBuffer == 0)
304 {
305 mFunctions->genBuffers(1, &mStreamingArrayBuffer);
306 mStreamingArrayBufferSize = 0;
307 }
308
Shao80957d92017-02-20 21:25:59 +0800309 // If first is greater than zero, a slack space needs to be left at the beginning of the buffer
310 // so that the same 'first' argument can be passed into the draw call.
311 const size_t bufferEmptySpace = maxAttributeDataSize * indexRange.start;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400312 const size_t requiredBufferSize = streamingDataSize + bufferEmptySpace;
313
Corentin Wallez336129f2017-10-17 15:55:40 -0400314 mStateManager->bindBuffer(gl::BufferBinding::Array, mStreamingArrayBuffer);
Geoff Lang7c82bc42015-03-09 16:18:08 -0400315 if (requiredBufferSize > mStreamingArrayBufferSize)
316 {
317 mFunctions->bufferData(GL_ARRAY_BUFFER, requiredBufferSize, nullptr, GL_DYNAMIC_DRAW);
318 mStreamingArrayBufferSize = requiredBufferSize;
319 }
320
Geoff Lang5f3047c2018-02-14 14:39:12 -0500321 mStateManager->bindVertexArray(mVertexArrayID, getAppliedElementArrayBufferID());
322
Geoff Lang7c82bc42015-03-09 16:18:08 -0400323 // Unmapping a buffer can return GL_FALSE to indicate that the system has corrupted the data
Shao80957d92017-02-20 21:25:59 +0800324 // somehow (such as by a screen change), retry writing the data a few times and return
325 // OUT_OF_MEMORY if that fails.
326 GLboolean unmapResult = GL_FALSE;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400327 size_t unmapRetryAttempts = 5;
328 while (unmapResult != GL_TRUE && --unmapRetryAttempts > 0)
329 {
Geoff Langb2ebb5e2016-06-08 18:17:55 +0000330 uint8_t *bufferPointer = MapBufferRangeWithFallback(mFunctions, GL_ARRAY_BUFFER, 0,
331 requiredBufferSize, GL_MAP_WRITE_BIT);
Geoff Lang7c82bc42015-03-09 16:18:08 -0400332 size_t curBufferOffset = bufferEmptySpace;
333
Jamie Madill492f58e2017-10-09 19:41:33 -0400334 const auto &attribs = mState.getVertexAttributes();
335 const auto &bindings = mState.getVertexBindings();
Jamie Madill6de51852017-04-12 09:53:01 -0400336
Jamie Madill6de51852017-04-12 09:53:01 -0400337 for (auto idx : attribsToStream)
Geoff Lang7c82bc42015-03-09 16:18:08 -0400338 {
Jamie Madille4634a12018-11-14 09:54:35 -0500339 const auto &attrib = attribs[idx];
Shaodde78e82017-05-22 14:13:27 +0800340 ASSERT(IsVertexAttribPointerSupported(idx, attrib));
341
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800342 const auto &binding = bindings[attrib.bindingIndex];
Geoff Lang7c82bc42015-03-09 16:18:08 -0400343
Martin Radev553590a2017-07-31 16:40:39 +0300344 GLuint adjustedDivisor = GetAdjustedDivisor(mAppliedNumViews, binding.getDivisor());
345 const size_t streamedVertexCount = ComputeVertexBindingElementCount(
346 adjustedDivisor, indexRange.vertexCount(), instanceCount);
Geoff Lang3cf12ce2015-08-27 14:40:48 -0400347
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800348 const size_t sourceStride = ComputeVertexAttributeStride(attrib, binding);
Jamie Madill0b9e9032015-08-17 11:51:52 +0000349 const size_t destStride = ComputeVertexAttributeTypeSize(attrib);
350
Geoff Lang38a24a92017-02-15 13:53:06 -0500351 // Vertices do not apply the 'start' offset when the divisor is non-zero even when doing
352 // a non-instanced draw call
Martin Radev553590a2017-07-31 16:40:39 +0300353 const size_t firstIndex = adjustedDivisor == 0 ? indexRange.start : 0;
Geoff Lang38a24a92017-02-15 13:53:06 -0500354
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800355 // Attributes using client memory ignore the VERTEX_ATTRIB_BINDING state.
356 // https://www.opengl.org/registry/specs/ARB/vertex_attrib_binding.txt
Rafael Cintron05a449a2018-06-20 18:08:04 -0700357 const uint8_t *inputPointer = static_cast<const uint8_t *>(attrib.pointer);
Jamie Madill0b9e9032015-08-17 11:51:52 +0000358
359 // Pack the data when copying it, user could have supplied a very large stride that
360 // would cause the buffer to be much larger than needed.
361 if (destStride == sourceStride)
Jamie Madill8e344942015-07-09 14:22:07 -0400362 {
Jamie Madill0b9e9032015-08-17 11:51:52 +0000363 // Can copy in one go, the data is packed
Geoff Lang38a24a92017-02-15 13:53:06 -0500364 memcpy(bufferPointer + curBufferOffset, inputPointer + (sourceStride * firstIndex),
Jamie Madill0b9e9032015-08-17 11:51:52 +0000365 destStride * streamedVertexCount);
Jamie Madill6d51c702015-08-14 10:38:10 -0400366 }
Jamie Madill0b9e9032015-08-17 11:51:52 +0000367 else
368 {
369 // Copy each vertex individually
Geoff Lang6b10ddb2015-09-02 15:55:10 -0400370 for (size_t vertexIdx = 0; vertexIdx < streamedVertexCount; vertexIdx++)
Jamie Madill0b9e9032015-08-17 11:51:52 +0000371 {
Shao80957d92017-02-20 21:25:59 +0800372 uint8_t *out = bufferPointer + curBufferOffset + (destStride * vertexIdx);
Geoff Lang38a24a92017-02-15 13:53:06 -0500373 const uint8_t *in = inputPointer + sourceStride * (vertexIdx + firstIndex);
Corentin Wallez4d5362d2015-08-25 11:25:14 -0400374 memcpy(out, in, destStride);
Jamie Madill0b9e9032015-08-17 11:51:52 +0000375 }
376 }
377
378 // Compute where the 0-index vertex would be.
Geoff Lang38a24a92017-02-15 13:53:06 -0500379 const size_t vertexStartOffset = curBufferOffset - (firstIndex * destStride);
Jamie Madill0b9e9032015-08-17 11:51:52 +0000380
Shaodf682a82017-03-31 15:13:21 +0800381 callVertexAttribPointer(static_cast<GLuint>(idx), attrib,
382 static_cast<GLsizei>(destStride),
383 static_cast<GLintptr>(vertexStartOffset));
Jamie Madill0b9e9032015-08-17 11:51:52 +0000384
385 curBufferOffset += destStride * streamedVertexCount;
Geoff Lang7c82bc42015-03-09 16:18:08 -0400386 }
387
388 unmapResult = mFunctions->unmapBuffer(GL_ARRAY_BUFFER);
389 }
390
Jamie Madille39e8f42018-10-05 08:17:38 -0400391 ANGLE_CHECK(GetImplAs<ContextGL>(context), unmapResult == GL_TRUE,
392 "Failed to unmap the client data streaming buffer.", GL_OUT_OF_MEMORY);
393 return angle::Result::Continue();
Geoff Langba4c4a82015-02-24 12:38:46 -0500394}
395
396GLuint VertexArrayGL::getVertexArrayID() const
397{
398 return mVertexArrayID;
Geoff Langf9a6f082015-01-22 13:32:49 -0500399}
400
Geoff Lang294cad92015-05-26 15:11:23 -0400401GLuint VertexArrayGL::getAppliedElementArrayBufferID() const
402{
Jamie Madill77a90c22015-08-11 16:33:17 -0400403 if (mAppliedElementArrayBuffer.get() == nullptr)
404 {
405 return mStreamingElementArrayBuffer;
406 }
407
408 return GetImplAs<BufferGL>(mAppliedElementArrayBuffer.get())->getBufferID();
Geoff Lang294cad92015-05-26 15:11:23 -0400409}
410
Jamie Madill0b9e9032015-08-17 11:51:52 +0000411void VertexArrayGL::updateAttribEnabled(size_t attribIndex)
412{
Shahbaz Youssefi337bd692018-08-22 16:16:38 -0400413 const bool enabled = mState.getVertexAttribute(attribIndex).enabled &
414 mProgramActiveAttribLocationsMask.test(attribIndex);
Shaodf682a82017-03-31 15:13:21 +0800415 if (mAppliedAttributes[attribIndex].enabled == enabled)
Jamie Madill0b9e9032015-08-17 11:51:52 +0000416 {
417 return;
418 }
419
Shaodf682a82017-03-31 15:13:21 +0800420 if (enabled)
Jamie Madill0b9e9032015-08-17 11:51:52 +0000421 {
422 mFunctions->enableVertexAttribArray(static_cast<GLuint>(attribIndex));
423 }
424 else
425 {
426 mFunctions->disableVertexAttribArray(static_cast<GLuint>(attribIndex));
427 }
Shaodf682a82017-03-31 15:13:21 +0800428
429 mAppliedAttributes[attribIndex].enabled = enabled;
Jamie Madill0b9e9032015-08-17 11:51:52 +0000430}
431
Jamie Madill4928b7c2017-06-20 12:57:39 -0400432void VertexArrayGL::updateAttribPointer(const gl::Context *context, size_t attribIndex)
Jamie Madill0b9e9032015-08-17 11:51:52 +0000433{
Jamie Madill492f58e2017-10-09 19:41:33 -0400434 const VertexAttribute &attrib = mState.getVertexAttribute(attribIndex);
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800435
Shaodde78e82017-05-22 14:13:27 +0800436 // According to SPEC, VertexAttribPointer should update the binding indexed attribIndex instead
437 // of the binding indexed attrib.bindingIndex (unless attribIndex == attrib.bindingIndex).
Jamie Madill492f58e2017-10-09 19:41:33 -0400438 const VertexBinding &binding = mState.getVertexBinding(attribIndex);
Shaodf682a82017-03-31 15:13:21 +0800439
Shaodde78e82017-05-22 14:13:27 +0800440 // Early return when the vertex attribute isn't using a buffer object:
441 // - If we need to stream, defer the attribPointer to the draw call.
442 // - Skip the attribute that is disabled and uses a client memory pointer.
443 // - Skip the attribute whose buffer is detached by BindVertexBuffer. Since it cannot have a
444 // client memory pointer either, it must be disabled and shouldn't affect the draw.
Jamie Madillbcef3222018-04-13 15:19:11 -0400445 const auto &bindingBuffer = binding.getBuffer();
Shaodde78e82017-05-22 14:13:27 +0800446 const Buffer *arrayBuffer = bindingBuffer.get();
447 if (arrayBuffer == nullptr)
448 {
449 // Mark the applied binding isn't using a buffer by setting its buffer to nullptr so that if
450 // it starts to use a buffer later, there is no chance that the caching will skip it.
James Darpiniane8a93c62018-01-04 18:02:24 -0800451 mAppliedBindings[attribIndex].setBuffer(context, nullptr, false);
Shaodde78e82017-05-22 14:13:27 +0800452 return;
453 }
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800454
Shaodf682a82017-03-31 15:13:21 +0800455 // We do not need to compare attrib.pointer because when we use a different client memory
456 // pointer, we don't need to update mAttributesNeedStreaming by binding.buffer and we won't
457 // update attribPointer in this function.
Shaodde78e82017-05-22 14:13:27 +0800458 if ((SameVertexAttribFormat(mAppliedAttributes[attribIndex], attrib)) &&
459 (mAppliedAttributes[attribIndex].bindingIndex == attrib.bindingIndex) &&
460 (SameVertexBuffer(mAppliedBindings[attribIndex], binding)))
Jamie Madill0b9e9032015-08-17 11:51:52 +0000461 {
462 return;
463 }
464
Shao4181bc92017-03-17 14:55:25 +0800465 // Since ANGLE always uses a non-zero VAO, we cannot use a client memory pointer on it:
466 // [OpenGL ES 3.0.2] Section 2.8 page 24:
467 // An INVALID_OPERATION error is generated when a non-zero vertex array object is bound,
468 // zero is bound to the ARRAY_BUFFER buffer object binding point, and the pointer argument
469 // is not NULL.
Shaodf682a82017-03-31 15:13:21 +0800470
Shao4181bc92017-03-17 14:55:25 +0800471 const BufferGL *arrayBufferGL = GetImplAs<BufferGL>(arrayBuffer);
Corentin Wallez336129f2017-10-17 15:55:40 -0400472 mStateManager->bindBuffer(gl::BufferBinding::Array, arrayBufferGL->getBufferID());
Martin Radevdd5f27e2017-06-07 10:17:09 +0300473 callVertexAttribPointer(static_cast<GLuint>(attribIndex), attrib, binding.getStride(),
474 binding.getOffset());
Shaodf682a82017-03-31 15:13:21 +0800475
Shaodde78e82017-05-22 14:13:27 +0800476 mAppliedAttributes[attribIndex].size = attrib.size;
477 mAppliedAttributes[attribIndex].type = attrib.type;
478 mAppliedAttributes[attribIndex].normalized = attrib.normalized;
479 mAppliedAttributes[attribIndex].pureInteger = attrib.pureInteger;
Shaodf682a82017-03-31 15:13:21 +0800480
Shaodde78e82017-05-22 14:13:27 +0800481 // After VertexAttribPointer, attrib.relativeOffset is set to 0 and attrib.bindingIndex is set
482 // to attribIndex in driver. If attrib.relativeOffset != 0 or attrib.bindingIndex !=
483 // attribIndex, they should be set in updateAttribFormat and updateAttribBinding. The cache
484 // should be consistent with driver so that we won't miss anything.
485 mAppliedAttributes[attribIndex].relativeOffset = 0;
486 mAppliedAttributes[attribIndex].bindingIndex = static_cast<GLuint>(attribIndex);
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800487
Shaodde78e82017-05-22 14:13:27 +0800488 mAppliedBindings[attribIndex].setStride(binding.getStride());
489 mAppliedBindings[attribIndex].setOffset(binding.getOffset());
James Darpiniane8a93c62018-01-04 18:02:24 -0800490 mAppliedBindings[attribIndex].setBuffer(context, binding.getBuffer().get(), false);
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800491}
492
Shaodf682a82017-03-31 15:13:21 +0800493void VertexArrayGL::callVertexAttribPointer(GLuint attribIndex,
494 const VertexAttribute &attrib,
495 GLsizei stride,
496 GLintptr offset) const
497{
498 const GLvoid *pointer = reinterpret_cast<const GLvoid *>(offset);
499 if (attrib.pureInteger)
500 {
501 ASSERT(!attrib.normalized);
502 mFunctions->vertexAttribIPointer(attribIndex, attrib.size, attrib.type, stride, pointer);
503 }
504 else
505 {
506 mFunctions->vertexAttribPointer(attribIndex, attrib.size, attrib.type, attrib.normalized,
507 stride, pointer);
508 }
509}
510
Shaodde78e82017-05-22 14:13:27 +0800511bool VertexArrayGL::supportVertexAttribBinding() const
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800512{
Shaodde78e82017-05-22 14:13:27 +0800513 ASSERT(mFunctions);
514 return (mFunctions->vertexAttribBinding != nullptr);
515}
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800516
Shaodde78e82017-05-22 14:13:27 +0800517void VertexArrayGL::updateAttribFormat(size_t attribIndex)
518{
519 ASSERT(supportVertexAttribBinding());
520
Jamie Madill492f58e2017-10-09 19:41:33 -0400521 const VertexAttribute &attrib = mState.getVertexAttribute(attribIndex);
Shaodde78e82017-05-22 14:13:27 +0800522 if (SameVertexAttribFormat(mAppliedAttributes[attribIndex], attrib))
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800523 {
Shaodf682a82017-03-31 15:13:21 +0800524 return;
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800525 }
Shaodf682a82017-03-31 15:13:21 +0800526
Shaodde78e82017-05-22 14:13:27 +0800527 if (attrib.pureInteger)
528 {
529 ASSERT(!attrib.normalized);
530 mFunctions->vertexAttribIFormat(static_cast<GLuint>(attribIndex), attrib.size, attrib.type,
531 attrib.relativeOffset);
532 }
533 else
534 {
535 mFunctions->vertexAttribFormat(static_cast<GLuint>(attribIndex), attrib.size, attrib.type,
536 attrib.normalized, attrib.relativeOffset);
537 }
538
539 mAppliedAttributes[attribIndex].size = attrib.size;
540 mAppliedAttributes[attribIndex].type = attrib.type;
541 mAppliedAttributes[attribIndex].normalized = attrib.normalized;
542 mAppliedAttributes[attribIndex].pureInteger = attrib.pureInteger;
543 mAppliedAttributes[attribIndex].relativeOffset = attrib.relativeOffset;
544}
545
546void VertexArrayGL::updateAttribBinding(size_t attribIndex)
547{
548 ASSERT(supportVertexAttribBinding());
549
Jamie Madill492f58e2017-10-09 19:41:33 -0400550 GLuint bindingIndex = mState.getVertexAttribute(attribIndex).bindingIndex;
Shaodde78e82017-05-22 14:13:27 +0800551 if (mAppliedAttributes[attribIndex].bindingIndex == bindingIndex)
552 {
553 return;
554 }
555
556 mFunctions->vertexAttribBinding(static_cast<GLuint>(attribIndex), bindingIndex);
Shaodf682a82017-03-31 15:13:21 +0800557
558 mAppliedAttributes[attribIndex].bindingIndex = bindingIndex;
Shaodde78e82017-05-22 14:13:27 +0800559}
560
561void VertexArrayGL::updateBindingBuffer(const gl::Context *context, size_t bindingIndex)
562{
563 ASSERT(supportVertexAttribBinding());
564
Jamie Madill492f58e2017-10-09 19:41:33 -0400565 const VertexBinding &binding = mState.getVertexBinding(bindingIndex);
Shaodde78e82017-05-22 14:13:27 +0800566 if (SameVertexBuffer(mAppliedBindings[bindingIndex], binding))
567 {
568 return;
569 }
570
571 const Buffer *arrayBuffer = binding.getBuffer().get();
572 GLuint bufferId = 0;
573 if (arrayBuffer != nullptr)
574 {
575 bufferId = GetImplAs<BufferGL>(arrayBuffer)->getBufferID();
576 }
577
578 mFunctions->bindVertexBuffer(static_cast<GLuint>(bindingIndex), bufferId, binding.getOffset(),
579 binding.getStride());
580
581 mAppliedBindings[bindingIndex].setStride(binding.getStride());
582 mAppliedBindings[bindingIndex].setOffset(binding.getOffset());
James Darpiniane8a93c62018-01-04 18:02:24 -0800583 mAppliedBindings[bindingIndex].setBuffer(context, binding.getBuffer().get(), false);
Shaodde78e82017-05-22 14:13:27 +0800584}
585
586void VertexArrayGL::updateBindingDivisor(size_t bindingIndex)
587{
Martin Radev553590a2017-07-31 16:40:39 +0300588 GLuint adjustedDivisor =
Jamie Madill492f58e2017-10-09 19:41:33 -0400589 GetAdjustedDivisor(mAppliedNumViews, mState.getVertexBinding(bindingIndex).getDivisor());
Martin Radev553590a2017-07-31 16:40:39 +0300590 if (mAppliedBindings[bindingIndex].getDivisor() == adjustedDivisor)
Shaodde78e82017-05-22 14:13:27 +0800591 {
592 return;
593 }
594
595 if (supportVertexAttribBinding())
596 {
Martin Radev553590a2017-07-31 16:40:39 +0300597 mFunctions->vertexBindingDivisor(static_cast<GLuint>(bindingIndex), adjustedDivisor);
Shaodde78e82017-05-22 14:13:27 +0800598 }
599 else
600 {
601 // We can only use VertexAttribDivisor on platforms that don't support Vertex Attrib
602 // Binding.
Martin Radev553590a2017-07-31 16:40:39 +0300603 mFunctions->vertexAttribDivisor(static_cast<GLuint>(bindingIndex), adjustedDivisor);
Shaodde78e82017-05-22 14:13:27 +0800604 }
605
Martin Radev553590a2017-07-31 16:40:39 +0300606 mAppliedBindings[bindingIndex].setDivisor(adjustedDivisor);
Jamie Madill0b9e9032015-08-17 11:51:52 +0000607}
608
Jamie Madille858cb12018-03-27 09:44:32 -0400609void VertexArrayGL::syncDirtyAttrib(const gl::Context *context,
610 size_t attribIndex,
611 const gl::VertexArray::DirtyAttribBits &dirtyAttribBits)
612{
613 ASSERT(dirtyAttribBits.any());
614
615 for (size_t dirtyBit : dirtyAttribBits)
616 {
617 switch (dirtyBit)
618 {
619 case VertexArray::DIRTY_ATTRIB_ENABLED:
620 updateAttribEnabled(attribIndex);
621 break;
622
623 case VertexArray::DIRTY_ATTRIB_POINTER:
624 updateAttribPointer(context, attribIndex);
625 break;
626
627 case VertexArray::DIRTY_ATTRIB_FORMAT:
628 ASSERT(supportVertexAttribBinding());
629 updateAttribFormat(attribIndex);
630 break;
631
632 case VertexArray::DIRTY_ATTRIB_BINDING:
633 ASSERT(supportVertexAttribBinding());
634 updateAttribBinding(attribIndex);
635 break;
636
637 default:
638 UNREACHABLE();
639 break;
640 }
641 }
642}
643
644void VertexArrayGL::syncDirtyBinding(const gl::Context *context,
645 size_t bindingIndex,
646 const gl::VertexArray::DirtyBindingBits &dirtyBindingBits)
647{
Jamie Madill02c9c042018-04-17 13:43:48 -0400648 // Dependent state changes in buffers can trigger updates with no dirty bits set.
Jamie Madille858cb12018-03-27 09:44:32 -0400649
650 for (size_t dirtyBit : dirtyBindingBits)
651 {
652 switch (dirtyBit)
653 {
654 case VertexArray::DIRTY_BINDING_BUFFER:
655 ASSERT(supportVertexAttribBinding());
656 updateBindingBuffer(context, bindingIndex);
657 break;
658
659 case VertexArray::DIRTY_BINDING_DIVISOR:
660 updateBindingDivisor(bindingIndex);
661 break;
662
663 default:
664 UNREACHABLE();
665 break;
666 }
667 }
668}
669
Jamie Madilla56467e2018-04-11 16:19:41 -0400670#define ANGLE_DIRTY_ATTRIB_FUNC(INDEX) \
671 case VertexArray::DIRTY_BIT_ATTRIB_0 + INDEX: \
672 syncDirtyAttrib(context, INDEX, attribBits[INDEX]); \
673 break;
674
675#define ANGLE_DIRTY_BINDING_FUNC(INDEX) \
676 case VertexArray::DIRTY_BIT_BINDING_0 + INDEX: \
677 syncDirtyBinding(context, INDEX, bindingBits[INDEX]); \
678 break;
679
680#define ANGLE_DIRTY_BUFFER_DATA_FUNC(INDEX) \
681 case VertexArray::DIRTY_BIT_BUFFER_DATA_0 + INDEX: \
682 break;
683
Jamie Madill6f755b22018-10-09 12:48:54 -0400684angle::Result VertexArrayGL::syncState(const gl::Context *context,
685 const gl::VertexArray::DirtyBits &dirtyBits,
686 const gl::VertexArray::DirtyAttribBitsArray &attribBits,
687 const gl::VertexArray::DirtyBindingBitsArray &bindingBits)
Jamie Madill0b9e9032015-08-17 11:51:52 +0000688{
Shaodf682a82017-03-31 15:13:21 +0800689 mStateManager->bindVertexArray(mVertexArrayID, getAppliedElementArrayBufferID());
690
Jamie Madill6de51852017-04-12 09:53:01 -0400691 for (size_t dirtyBit : dirtyBits)
Jamie Madill0b9e9032015-08-17 11:51:52 +0000692 {
Jamie Madille858cb12018-03-27 09:44:32 -0400693 switch (dirtyBit)
Jamie Madill0b9e9032015-08-17 11:51:52 +0000694 {
Jamie Madille858cb12018-03-27 09:44:32 -0400695 case VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER:
696 updateElementArrayBufferBinding(context);
697 break;
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800698
Jamie Madill09463932018-04-04 05:26:59 -0400699 case VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA:
700 break;
701
Jamie Madilla56467e2018-04-11 16:19:41 -0400702 ANGLE_VERTEX_INDEX_CASES(ANGLE_DIRTY_ATTRIB_FUNC);
703 ANGLE_VERTEX_INDEX_CASES(ANGLE_DIRTY_BINDING_FUNC);
704 ANGLE_VERTEX_INDEX_CASES(ANGLE_DIRTY_BUFFER_DATA_FUNC);
705
Jamie Madille858cb12018-03-27 09:44:32 -0400706 default:
Jamie Madilla56467e2018-04-11 16:19:41 -0400707 UNREACHABLE();
Jamie Madille858cb12018-03-27 09:44:32 -0400708 break;
Jamie Madill0b9e9032015-08-17 11:51:52 +0000709 }
Jamie Madill0b9e9032015-08-17 11:51:52 +0000710 }
Frank Henigman0af5b862018-03-27 20:19:33 -0400711
Jamie Madill6f755b22018-10-09 12:48:54 -0400712 return angle::Result::Continue();
Jamie Madill0b9e9032015-08-17 11:51:52 +0000713}
714
Martin Radev553590a2017-07-31 16:40:39 +0300715void VertexArrayGL::applyNumViewsToDivisor(int numViews)
716{
717 if (numViews != mAppliedNumViews)
718 {
719 mStateManager->bindVertexArray(mVertexArrayID, getAppliedElementArrayBufferID());
720 mAppliedNumViews = numViews;
721 for (size_t index = 0u; index < mAppliedBindings.size(); ++index)
722 {
723 updateBindingDivisor(index);
724 }
725 }
726}
727
Shahbaz Youssefi337bd692018-08-22 16:16:38 -0400728void VertexArrayGL::applyActiveAttribLocationsMask(const gl::AttributesMask &activeMask)
729{
Jamie Madille4634a12018-11-14 09:54:35 -0500730 gl::AttributesMask updateMask = mProgramActiveAttribLocationsMask ^ activeMask;
Qin Jiajiafcf10b62018-09-19 12:53:18 +0800731 if (!updateMask.any())
732 {
733 return;
734 }
735 ASSERT(mVertexArrayID == mStateManager->getVertexArrayID());
Shahbaz Youssefi337bd692018-08-22 16:16:38 -0400736 mProgramActiveAttribLocationsMask = activeMask;
737
738 for (size_t attribIndex : updateMask)
739 {
740 updateAttribEnabled(attribIndex);
741 }
742}
743
Jamie Madill09463932018-04-04 05:26:59 -0400744} // namespace rx