Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 1 | // |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 2 | // Copyright 2018 The ANGLE Project Authors. All rights reserved. |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 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 | // Context.inl.h: Defines inline functions of gl::Context class |
| 8 | // Has to be included after libANGLE/Context.h when using one |
| 9 | // of the defined functions |
| 10 | |
| 11 | #ifndef LIBANGLE_CONTEXT_INL_H_ |
| 12 | #define LIBANGLE_CONTEXT_INL_H_ |
| 13 | |
| 14 | #include "libANGLE/GLES1Renderer.h" |
| 15 | #include "libANGLE/renderer/ContextImpl.h" |
| 16 | |
| 17 | #define ANGLE_HANDLE_ERR(X) \ |
| 18 | (void)(X); \ |
| 19 | return; |
Jamie Madill | c09ae15 | 2019-02-01 14:16:32 -0500 | [diff] [blame] | 20 | #define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR) |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 21 | |
| 22 | namespace gl |
| 23 | { |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 24 | constexpr angle::PackedEnumMap<PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{ |
| 25 | {PrimitiveMode::Points, 1}, |
| 26 | {PrimitiveMode::Lines, 2}, |
| 27 | {PrimitiveMode::LineLoop, 2}, |
| 28 | {PrimitiveMode::LineStrip, 2}, |
| 29 | {PrimitiveMode::Triangles, 3}, |
| 30 | {PrimitiveMode::TriangleStrip, 3}, |
| 31 | {PrimitiveMode::TriangleFan, 3}, |
| 32 | {PrimitiveMode::LinesAdjacency, 2}, |
| 33 | {PrimitiveMode::LineStripAdjacency, 2}, |
| 34 | {PrimitiveMode::TrianglesAdjacency, 3}, |
| 35 | {PrimitiveMode::TriangleStripAdjacency, 3}, |
| 36 | }}; |
| 37 | |
| 38 | ANGLE_INLINE void MarkTransformFeedbackBufferUsage(const Context *context, |
| 39 | GLsizei count, |
| 40 | GLsizei instanceCount) |
| 41 | { |
| 42 | if (context->getStateCache().isTransformFeedbackActiveUnpaused()) |
| 43 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 44 | TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback(); |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 45 | transformFeedback->onVerticesDrawn(context, count, instanceCount); |
| 46 | } |
| 47 | } |
| 48 | |
James Dong | 020abb8 | 2019-07-24 11:33:49 -0600 | [diff] [blame] | 49 | ANGLE_INLINE void MarkShaderStorageBufferUsage(const Context *context) |
| 50 | { |
| 51 | for (size_t index : context->getStateCache().getActiveShaderStorageBufferIndices()) |
| 52 | { |
| 53 | gl::Buffer *buffer = context->getState().getIndexedShaderStorageBuffer(index).get(); |
| 54 | if (buffer) |
| 55 | { |
| 56 | buffer->onDataChanged(); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 61 | // Return true if the draw is a no-op, else return false. |
Tim Van Patten | 405f8e7 | 2020-02-24 17:38:10 -0700 | [diff] [blame^] | 62 | // If there is no active program for the vertex or fragment shader stages, the results of vertex |
| 63 | // and fragment shader execution will respectively be undefined. However, this is not |
| 64 | // an error. ANGLE will treat this as a no-op. |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 65 | // A no-op draw occurs if the count of vertices is less than the minimum required to |
| 66 | // have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris). |
| 67 | ANGLE_INLINE bool Context::noopDraw(PrimitiveMode mode, GLsizei count) |
| 68 | { |
Jamie Madill | d03b15b | 2020-03-26 17:22:18 -0400 | [diff] [blame] | 69 | return count < kMinimumPrimitiveCounts[mode]; |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 70 | } |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 71 | |
| 72 | ANGLE_INLINE angle::Result Context::syncDirtyBits() |
| 73 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 74 | const State::DirtyBits &dirtyBits = mState.getDirtyBits(); |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 75 | ANGLE_TRY(mImplementation->syncState(this, dirtyBits, mAllDirtyBits)); |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 76 | mState.clearDirtyBits(); |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 77 | return angle::Result::Continue; |
| 78 | } |
| 79 | |
| 80 | ANGLE_INLINE angle::Result Context::syncDirtyBits(const State::DirtyBits &bitMask) |
| 81 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 82 | const State::DirtyBits &dirtyBits = (mState.getDirtyBits() & bitMask); |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 83 | ANGLE_TRY(mImplementation->syncState(this, dirtyBits, bitMask)); |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 84 | mState.clearDirtyBits(dirtyBits); |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 85 | return angle::Result::Continue; |
| 86 | } |
| 87 | |
| 88 | ANGLE_INLINE angle::Result Context::syncDirtyObjects(const State::DirtyObjects &objectMask) |
| 89 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 90 | return mState.syncDirtyObjects(this, objectMask); |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | ANGLE_INLINE angle::Result Context::prepareForDraw(PrimitiveMode mode) |
| 94 | { |
| 95 | if (mGLES1Renderer) |
| 96 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 97 | ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mState)); |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects)); |
| 101 | ASSERT(!isRobustResourceInitEnabled() || |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 102 | !mState.getDrawFramebuffer()->hasResourceThatNeedsInit()); |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 103 | return syncDirtyBits(); |
| 104 | } |
| 105 | |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 106 | ANGLE_INLINE void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count) |
| 107 | { |
| 108 | // No-op if count draws no primitives for given mode |
| 109 | if (noopDraw(mode, count)) |
| 110 | { |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | ANGLE_CONTEXT_TRY(prepareForDraw(mode)); |
| 115 | ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count)); |
| 116 | MarkTransformFeedbackBufferUsage(this, count, 1); |
| 117 | } |
| 118 | |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 119 | ANGLE_INLINE void Context::drawElements(PrimitiveMode mode, |
| 120 | GLsizei count, |
| 121 | DrawElementsType type, |
| 122 | const void *indices) |
| 123 | { |
| 124 | // No-op if count draws no primitives for given mode |
| 125 | if (noopDraw(mode, count)) |
| 126 | { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | ANGLE_CONTEXT_TRY(prepareForDraw(mode)); |
| 131 | ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices)); |
| 132 | } |
| 133 | |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 134 | ANGLE_INLINE void StateCache::onBufferBindingChange(Context *context) |
| 135 | { |
| 136 | updateBasicDrawStatesError(); |
| 137 | updateBasicDrawElementsError(); |
| 138 | } |
| 139 | |
Jamie Madill | 3b3fe83 | 2019-08-06 17:44:12 -0400 | [diff] [blame] | 140 | ANGLE_INLINE void Context::bindBuffer(BufferBinding target, BufferID buffer) |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 141 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 142 | Buffer *bufferObject = |
| 143 | mState.mBufferManager->checkBufferAllocation(mImplementation.get(), buffer); |
| 144 | mState.setBufferBinding(this, target, bufferObject); |
Jamie Madill | 60a50cf | 2018-12-29 16:04:05 -0500 | [diff] [blame] | 145 | mStateCache.onBufferBindingChange(this); |
| 146 | } |
| 147 | |
Markus Tavenrath | cb9609f | 2018-12-26 00:52:44 +0900 | [diff] [blame] | 148 | } // namespace gl |
| 149 | |
| 150 | #endif // LIBANGLE_CONTEXT_INL_H_ |