Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2016 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 | // ContextVk.cpp: |
| 7 | // Implements the class methods for ContextVk. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
| 11 | |
Jamie Madill | 20e005b | 2017-04-07 14:19:22 -0400 | [diff] [blame] | 12 | #include "common/bitset_utils.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 13 | #include "common/debug.h" |
Frank Henigman | a53d0e1 | 2018-02-13 00:06:06 -0500 | [diff] [blame] | 14 | #include "common/utilities.h" |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 15 | #include "libANGLE/Context.h" |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 16 | #include "libANGLE/Program.h" |
Geoff Lang | caa55cd | 2018-07-05 13:19:35 -0400 | [diff] [blame] | 17 | #include "libANGLE/Surface.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 18 | #include "libANGLE/renderer/vulkan/BufferVk.h" |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 19 | #include "libANGLE/renderer/vulkan/CommandGraph.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 20 | #include "libANGLE/renderer/vulkan/CompilerVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 21 | #include "libANGLE/renderer/vulkan/FenceNVVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 22 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 23 | #include "libANGLE/renderer/vulkan/ProgramPipelineVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 24 | #include "libANGLE/renderer/vulkan/ProgramVk.h" |
| 25 | #include "libANGLE/renderer/vulkan/QueryVk.h" |
| 26 | #include "libANGLE/renderer/vulkan/RenderbufferVk.h" |
| 27 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
| 28 | #include "libANGLE/renderer/vulkan/SamplerVk.h" |
| 29 | #include "libANGLE/renderer/vulkan/ShaderVk.h" |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 30 | #include "libANGLE/renderer/vulkan/SyncVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 31 | #include "libANGLE/renderer/vulkan/TextureVk.h" |
| 32 | #include "libANGLE/renderer/vulkan/TransformFeedbackVk.h" |
| 33 | #include "libANGLE/renderer/vulkan/VertexArrayVk.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 34 | |
Tobin Ehlis | 573f76b | 2018-05-03 11:10:44 -0600 | [diff] [blame] | 35 | #include "third_party/trace_event/trace_event.h" |
| 36 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 37 | namespace rx |
| 38 | { |
Luc Ferron | 14f4817 | 2018-04-11 08:43:28 -0400 | [diff] [blame] | 39 | |
| 40 | namespace |
| 41 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 42 | GLenum DefaultGLErrorCode(VkResult result) |
| 43 | { |
| 44 | switch (result) |
| 45 | { |
| 46 | case VK_ERROR_OUT_OF_HOST_MEMORY: |
| 47 | case VK_ERROR_OUT_OF_DEVICE_MEMORY: |
| 48 | case VK_ERROR_TOO_MANY_OBJECTS: |
| 49 | return GL_OUT_OF_MEMORY; |
| 50 | default: |
| 51 | return GL_INVALID_OPERATION; |
| 52 | } |
| 53 | } |
| 54 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 55 | constexpr VkColorComponentFlags kAllColorChannelsMask = |
| 56 | (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | |
| 57 | VK_COLOR_COMPONENT_A_BIT); |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 58 | |
| 59 | constexpr VkBufferUsageFlags kVertexBufferUsage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; |
| 60 | constexpr size_t kDefaultValueSize = sizeof(float) * 4; |
| 61 | constexpr size_t kDefaultBufferSize = kDefaultValueSize * 16; |
Luc Ferron | 14f4817 | 2018-04-11 08:43:28 -0400 | [diff] [blame] | 62 | } // anonymous namespace |
| 63 | |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 64 | // std::array only uses aggregate init. Thus we make a helper macro to reduce on code duplication. |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 65 | #define INIT \ |
| 66 | { \ |
| 67 | kVertexBufferUsage, kDefaultBufferSize, true \ |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 68 | } |
| 69 | |
Jamie Madill | 0c66721 | 2019-01-01 14:40:36 -0500 | [diff] [blame] | 70 | ContextVk::ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk *renderer) |
| 71 | : ContextImpl(state, errorSet), |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 72 | vk::Context(renderer), |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 73 | mCurrentPipeline(nullptr), |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 74 | mCurrentDrawMode(gl::PrimitiveMode::InvalidEnum), |
Jamie Madill | 37386b0 | 2018-08-30 16:18:37 -0400 | [diff] [blame] | 75 | mVertexArray(nullptr), |
| 76 | mDrawFramebuffer(nullptr), |
| 77 | mProgram(nullptr), |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 78 | mLastIndexBufferOffset(0), |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 79 | mCurrentDrawElementsType(gl::DrawElementsType::InvalidEnum), |
Geoff Lang | caa55cd | 2018-07-05 13:19:35 -0400 | [diff] [blame] | 80 | mClearColorMask(kAllColorChannelsMask), |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 81 | mFlipYForCurrentSurface(false), |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 82 | mDriverUniformsBuffer(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, sizeof(DriverUniforms) * 16, true), |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 83 | mDriverUniformsDescriptorSet(VK_NULL_HANDLE), |
| 84 | mDefaultAttribBuffers{{INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, INIT, |
Jamie Madill | 633d5e6 | 2018-12-23 19:58:01 -0500 | [diff] [blame] | 85 | INIT, INIT, INIT, INIT}} |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 86 | { |
Tobin Ehlis | 573f76b | 2018-05-03 11:10:44 -0600 | [diff] [blame] | 87 | TRACE_EVENT0("gpu.angle", "ContextVk::ContextVk"); |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 88 | memset(&mClearColorValue, 0, sizeof(mClearColorValue)); |
| 89 | memset(&mClearDepthStencilValue, 0, sizeof(mClearDepthStencilValue)); |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 90 | |
| 91 | mNonIndexedDirtyBitsMask.set(); |
| 92 | mNonIndexedDirtyBitsMask.reset(DIRTY_BIT_INDEX_BUFFER); |
| 93 | |
| 94 | mIndexedDirtyBitsMask.set(); |
| 95 | |
| 96 | mNewCommandBufferDirtyBits.set(DIRTY_BIT_PIPELINE); |
| 97 | mNewCommandBufferDirtyBits.set(DIRTY_BIT_TEXTURES); |
| 98 | mNewCommandBufferDirtyBits.set(DIRTY_BIT_VERTEX_BUFFERS); |
| 99 | mNewCommandBufferDirtyBits.set(DIRTY_BIT_INDEX_BUFFER); |
| 100 | mNewCommandBufferDirtyBits.set(DIRTY_BIT_DESCRIPTOR_SETS); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 101 | |
| 102 | mDirtyBitHandlers[DIRTY_BIT_DEFAULT_ATTRIBS] = &ContextVk::handleDirtyDefaultAttribs; |
| 103 | mDirtyBitHandlers[DIRTY_BIT_PIPELINE] = &ContextVk::handleDirtyPipeline; |
| 104 | mDirtyBitHandlers[DIRTY_BIT_TEXTURES] = &ContextVk::handleDirtyTextures; |
| 105 | mDirtyBitHandlers[DIRTY_BIT_VERTEX_BUFFERS] = &ContextVk::handleDirtyVertexBuffers; |
| 106 | mDirtyBitHandlers[DIRTY_BIT_INDEX_BUFFER] = &ContextVk::handleDirtyIndexBuffer; |
Jamie Madill | ef6023e | 2018-09-06 16:24:38 -0400 | [diff] [blame] | 107 | mDirtyBitHandlers[DIRTY_BIT_DRIVER_UNIFORMS] = &ContextVk::handleDirtyDriverUniforms; |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 108 | mDirtyBitHandlers[DIRTY_BIT_DESCRIPTOR_SETS] = &ContextVk::handleDirtyDescriptorSets; |
Jamie Madill | b36a481 | 2018-09-25 10:15:11 -0400 | [diff] [blame] | 109 | |
| 110 | mDirtyBits = mNewCommandBufferDirtyBits; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Shahbaz Youssefi | 996628a | 2018-09-24 16:39:26 -0400 | [diff] [blame] | 113 | #undef INIT |
| 114 | |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 115 | ContextVk::~ContextVk() = default; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 116 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 117 | void ContextVk::onDestroy(const gl::Context *context) |
| 118 | { |
Jamie Madill | 198658a | 2019-03-19 22:09:14 -0400 | [diff] [blame] | 119 | // Force a flush on destroy. |
| 120 | (void)mRenderer->finish(this); |
| 121 | |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 122 | mDriverUniformsSetLayout.reset(); |
Luc Ferron | 9096836 | 2018-05-04 08:47:22 -0400 | [diff] [blame] | 123 | mIncompleteTextures.onDestroy(context); |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 124 | mDriverUniformsBuffer.destroy(getDevice()); |
Jamie Madill | 78bcd2b | 2018-10-16 15:05:20 -0400 | [diff] [blame] | 125 | mDriverUniformsDescriptorPoolBinding.reset(); |
Jamie Madill | edeaa83 | 2018-06-22 09:18:41 -0400 | [diff] [blame] | 126 | |
| 127 | for (vk::DynamicDescriptorPool &descriptorPool : mDynamicDescriptorPools) |
| 128 | { |
| 129 | descriptorPool.destroy(getDevice()); |
| 130 | } |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 131 | |
| 132 | for (vk::DynamicBuffer &defaultBuffer : mDefaultAttribBuffers) |
| 133 | { |
| 134 | defaultBuffer.destroy(getDevice()); |
| 135 | } |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 136 | |
| 137 | for (vk::DynamicQueryPool &queryPool : mQueryPools) |
| 138 | { |
| 139 | queryPool.destroy(getDevice()); |
| 140 | } |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Jamie Madill | 666818e | 2018-11-14 09:54:33 -0500 | [diff] [blame] | 143 | angle::Result ContextVk::getIncompleteTexture(const gl::Context *context, |
| 144 | gl::TextureType type, |
| 145 | gl::Texture **textureOut) |
Luc Ferron | 9096836 | 2018-05-04 08:47:22 -0400 | [diff] [blame] | 146 | { |
| 147 | // At some point, we'll need to support multisample and we'll pass "this" instead of nullptr |
| 148 | // and implement the necessary interface. |
| 149 | return mIncompleteTextures.getIncompleteTexture(context, type, nullptr, textureOut); |
| 150 | } |
| 151 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 152 | angle::Result ContextVk::initialize() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 153 | { |
Tobin Ehlis | 573f76b | 2018-05-03 11:10:44 -0600 | [diff] [blame] | 154 | TRACE_EVENT0("gpu.angle", "ContextVk::initialize"); |
Jamie Madill | 8a4c49f | 2018-06-21 15:43:06 -0400 | [diff] [blame] | 155 | // Note that this may reserve more sets than strictly necessary for a particular layout. |
Shahbaz Youssefi | 5f01324 | 2018-11-26 12:41:12 -0500 | [diff] [blame] | 156 | VkDescriptorPoolSize uniformSetSize = {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, |
| 157 | GetUniformBufferDescriptorCount()}; |
| 158 | VkDescriptorPoolSize textureSetSize = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, |
| 159 | mRenderer->getMaxActiveTextures()}; |
| 160 | VkDescriptorPoolSize driverSetSize = {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1}; |
| 161 | ANGLE_TRY(mDynamicDescriptorPools[kUniformsDescriptorSetIndex].init(this, &uniformSetSize, 1)); |
| 162 | ANGLE_TRY(mDynamicDescriptorPools[kTextureDescriptorSetIndex].init(this, &textureSetSize, 1)); |
| 163 | ANGLE_TRY( |
| 164 | mDynamicDescriptorPools[kDriverUniformsDescriptorSetIndex].init(this, &driverSetSize, 1)); |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 165 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 166 | ANGLE_TRY(mQueryPools[gl::QueryType::AnySamples].init(this, VK_QUERY_TYPE_OCCLUSION, |
| 167 | vk::kDefaultOcclusionQueryPoolSize)); |
| 168 | ANGLE_TRY(mQueryPools[gl::QueryType::AnySamplesConservative].init( |
| 169 | this, VK_QUERY_TYPE_OCCLUSION, vk::kDefaultOcclusionQueryPoolSize)); |
Shahbaz Youssefi | c2b576d | 2018-10-12 14:45:34 -0400 | [diff] [blame] | 170 | ANGLE_TRY(mQueryPools[gl::QueryType::Timestamp].init(this, VK_QUERY_TYPE_TIMESTAMP, |
| 171 | vk::kDefaultTimestampQueryPoolSize)); |
| 172 | ANGLE_TRY(mQueryPools[gl::QueryType::TimeElapsed].init(this, VK_QUERY_TYPE_TIMESTAMP, |
| 173 | vk::kDefaultTimestampQueryPoolSize)); |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 174 | |
Frank Henigman | 18f7e50 | 2018-07-19 16:06:43 -0400 | [diff] [blame] | 175 | size_t minAlignment = static_cast<size_t>( |
| 176 | mRenderer->getPhysicalDeviceProperties().limits.minUniformBufferOffsetAlignment); |
| 177 | mDriverUniformsBuffer.init(minAlignment, mRenderer); |
| 178 | |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 179 | mGraphicsPipelineDesc.reset(new vk::GraphicsPipelineDesc()); |
| 180 | mGraphicsPipelineDesc->initDefaults(); |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 181 | |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 182 | // Initialize current value/default attribute buffers. |
| 183 | for (vk::DynamicBuffer &buffer : mDefaultAttribBuffers) |
| 184 | { |
| 185 | buffer.init(1, mRenderer); |
| 186 | } |
| 187 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 188 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 189 | } |
| 190 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 191 | angle::Result ContextVk::flush(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 192 | { |
Shahbaz Youssefi | 3a48217 | 2018-10-11 10:34:44 -0400 | [diff] [blame] | 193 | return mRenderer->flush(this); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 194 | } |
| 195 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 196 | angle::Result ContextVk::finish(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 197 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 198 | return mRenderer->finish(this); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 199 | } |
| 200 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 201 | angle::Result ContextVk::setupDraw(const gl::Context *context, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 202 | gl::PrimitiveMode mode, |
| 203 | GLint firstVertex, |
| 204 | GLsizei vertexOrIndexCount, |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 205 | GLsizei instanceCount, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 206 | gl::DrawElementsType indexTypeOrNone, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 207 | const void *indices, |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 208 | DirtyBits dirtyBitMask, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 209 | CommandBufferT **commandBufferOut) |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 210 | { |
Jamie Madill | d1249de | 2018-08-28 16:58:53 -0400 | [diff] [blame] | 211 | // Set any dirty bits that depend on draw call parameters or other objects. |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 212 | if (mode != mCurrentDrawMode) |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 213 | { |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 214 | invalidateCurrentPipeline(); |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 215 | mCurrentDrawMode = mode; |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 216 | mGraphicsPipelineDesc->updateTopology(&mGraphicsPipelineTransition, mCurrentDrawMode); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 217 | } |
| 218 | |
Jamie Madill | 85ca189 | 2019-01-16 13:27:15 -0500 | [diff] [blame] | 219 | // Must be called before the command buffer is started. Can call finish. |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 220 | if (context->getStateCache().hasAnyActiveClientAttrib()) |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 221 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 222 | ANGLE_TRY(mVertexArray->updateClientAttribs(context, firstVertex, vertexOrIndexCount, |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 223 | instanceCount, indexTypeOrNone, indices)); |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 224 | mDirtyBits.set(DIRTY_BIT_VERTEX_BUFFERS); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 225 | } |
| 226 | |
Jamie Madill | 85ca189 | 2019-01-16 13:27:15 -0500 | [diff] [blame] | 227 | // This could be improved using a dirty bit. But currently it's slower to use a handler |
| 228 | // function than an inlined if. We should probably replace the dirty bit dispatch table |
| 229 | // with a switch with inlined handler functions. |
| 230 | // TODO(jmadill): Use dirty bit. http://anglebug.com/3014 |
| 231 | if (!mCommandBuffer) |
| 232 | { |
Jamie Madill | 54ed8f0 | 2019-02-11 12:32:04 -0500 | [diff] [blame] | 233 | mDirtyBits |= mNewCommandBufferDirtyBits; |
Jamie Madill | 85ca189 | 2019-01-16 13:27:15 -0500 | [diff] [blame] | 234 | if (!mDrawFramebuffer->appendToStartedRenderPass(mRenderer->getCurrentQueueSerial(), |
| 235 | &mCommandBuffer)) |
| 236 | { |
| 237 | ANGLE_TRY(mDrawFramebuffer->startNewRenderPass(this, &mCommandBuffer)); |
Jamie Madill | 85ca189 | 2019-01-16 13:27:15 -0500 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
| 241 | // We keep a local copy of the command buffer. It's possible that some state changes could |
| 242 | // trigger a command buffer invalidation. The local copy ensures we retain the reference. |
| 243 | // Command buffers are pool allocated and only deleted after submit. Thus we know the |
| 244 | // command buffer will still be valid for the duration of this API call. |
| 245 | *commandBufferOut = mCommandBuffer; |
| 246 | ASSERT(*commandBufferOut); |
| 247 | |
Jamie Madill | 37386b0 | 2018-08-30 16:18:37 -0400 | [diff] [blame] | 248 | if (mProgram->dirtyUniforms()) |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 249 | { |
Jamie Madill | 37386b0 | 2018-08-30 16:18:37 -0400 | [diff] [blame] | 250 | ANGLE_TRY(mProgram->updateUniforms(this)); |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 251 | mDirtyBits.set(DIRTY_BIT_DESCRIPTOR_SETS); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 252 | } |
| 253 | |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 254 | DirtyBits dirtyBits = mDirtyBits & dirtyBitMask; |
| 255 | |
| 256 | if (dirtyBits.none()) |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 257 | return angle::Result::Continue; |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 258 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 259 | // Flush any relevant dirty bits. |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 260 | for (size_t dirtyBit : dirtyBits) |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 261 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 262 | ANGLE_TRY((this->*mDirtyBitHandlers[dirtyBit])(context, *commandBufferOut)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 263 | } |
| 264 | |
Jamie Madill | c759b8b | 2019-01-03 15:16:50 -0500 | [diff] [blame] | 265 | mDirtyBits &= ~dirtyBitMask; |
| 266 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 267 | return angle::Result::Continue; |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | angle::Result ContextVk::setupIndexedDraw(const gl::Context *context, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 271 | gl::PrimitiveMode mode, |
| 272 | GLsizei indexCount, |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 273 | GLsizei instanceCount, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 274 | gl::DrawElementsType indexType, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 275 | const void *indices, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 276 | CommandBufferT **commandBufferOut) |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 277 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 278 | if (indexType != mCurrentDrawElementsType) |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 279 | { |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 280 | mDirtyBits.set(DIRTY_BIT_INDEX_BUFFER); |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 281 | mCurrentDrawElementsType = indexType; |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 282 | } |
| 283 | |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 284 | const gl::Buffer *elementArrayBuffer = mVertexArray->getState().getElementArrayBuffer(); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 285 | if (!elementArrayBuffer) |
| 286 | { |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 287 | mDirtyBits.set(DIRTY_BIT_INDEX_BUFFER); |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 288 | ANGLE_TRY(mVertexArray->updateIndexTranslation(this, indexCount, indexType, indices)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 289 | } |
| 290 | else |
| 291 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 292 | if (indices != mLastIndexBufferOffset) |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 293 | { |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 294 | mDirtyBits.set(DIRTY_BIT_INDEX_BUFFER); |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 295 | mLastIndexBufferOffset = indices; |
Jamie Madill | 37386b0 | 2018-08-30 16:18:37 -0400 | [diff] [blame] | 296 | mVertexArray->updateCurrentElementArrayBufferOffset(mLastIndexBufferOffset); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 299 | if (indexType == gl::DrawElementsType::UnsignedByte && mDirtyBits[DIRTY_BIT_INDEX_BUFFER]) |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 300 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 301 | ANGLE_TRY(mVertexArray->updateIndexTranslation(this, indexCount, indexType, indices)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 305 | return setupDraw(context, mode, 0, indexCount, instanceCount, indexType, indices, |
| 306 | mIndexedDirtyBitsMask, commandBufferOut); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | angle::Result ContextVk::setupLineLoopDraw(const gl::Context *context, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 310 | gl::PrimitiveMode mode, |
| 311 | GLint firstVertex, |
| 312 | GLsizei vertexOrIndexCount, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 313 | gl::DrawElementsType indexTypeOrInvalid, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 314 | const void *indices, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 315 | CommandBufferT **commandBufferOut) |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 316 | { |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 317 | ANGLE_TRY(mVertexArray->handleLineLoop(this, firstVertex, vertexOrIndexCount, |
| 318 | indexTypeOrInvalid, indices)); |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 319 | mDirtyBits.set(DIRTY_BIT_INDEX_BUFFER); |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 320 | mCurrentDrawElementsType = indexTypeOrInvalid != gl::DrawElementsType::InvalidEnum |
| 321 | ? indexTypeOrInvalid |
| 322 | : gl::DrawElementsType::UnsignedInt; |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 323 | return setupDraw(context, mode, firstVertex, vertexOrIndexCount, 1, indexTypeOrInvalid, indices, |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 324 | mIndexedDirtyBitsMask, commandBufferOut); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 325 | } |
| 326 | |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 327 | angle::Result ContextVk::handleDirtyDefaultAttribs(const gl::Context *context, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 328 | CommandBufferT *commandBuffer) |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 329 | { |
| 330 | ASSERT(mDirtyDefaultAttribsMask.any()); |
| 331 | |
| 332 | for (size_t attribIndex : mDirtyDefaultAttribsMask) |
| 333 | { |
Jamie Madill | c09ae15 | 2019-02-01 14:16:32 -0500 | [diff] [blame] | 334 | ANGLE_TRY(updateDefaultAttribute(attribIndex)); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | mDirtyDefaultAttribsMask.reset(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 338 | return angle::Result::Continue; |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | angle::Result ContextVk::handleDirtyPipeline(const gl::Context *context, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 342 | CommandBufferT *commandBuffer) |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 343 | { |
| 344 | if (!mCurrentPipeline) |
| 345 | { |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 346 | const vk::GraphicsPipelineDesc *descPtr; |
| 347 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 348 | // Draw call shader patching, shader compilation, and pipeline cache query. |
| 349 | ANGLE_TRY(mProgram->getGraphicsPipeline(this, mCurrentDrawMode, *mGraphicsPipelineDesc, |
| 350 | mProgram->getState().getActiveAttribLocationsMask(), |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 351 | &descPtr, &mCurrentPipeline)); |
| 352 | mGraphicsPipelineTransition.reset(); |
| 353 | } |
| 354 | else if (mGraphicsPipelineTransition.any()) |
| 355 | { |
| 356 | if (!mCurrentPipeline->findTransition(mGraphicsPipelineTransition, *mGraphicsPipelineDesc, |
| 357 | &mCurrentPipeline)) |
| 358 | { |
| 359 | vk::PipelineHelper *oldPipeline = mCurrentPipeline; |
| 360 | |
| 361 | const vk::GraphicsPipelineDesc *descPtr; |
| 362 | |
| 363 | ANGLE_TRY(mProgram->getGraphicsPipeline( |
| 364 | this, mCurrentDrawMode, *mGraphicsPipelineDesc, |
| 365 | mProgram->getState().getActiveAttribLocationsMask(), &descPtr, &mCurrentPipeline)); |
| 366 | |
| 367 | oldPipeline->addTransition(mGraphicsPipelineTransition, descPtr, mCurrentPipeline); |
| 368 | } |
| 369 | |
| 370 | mGraphicsPipelineTransition.reset(); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 371 | } |
| 372 | |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 373 | commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline->getPipeline()); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 374 | |
| 375 | // Update the queue serial for the pipeline object. |
| 376 | ASSERT(mCurrentPipeline && mCurrentPipeline->valid()); |
| 377 | mCurrentPipeline->updateSerial(mRenderer->getCurrentQueueSerial()); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 378 | return angle::Result::Continue; |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | angle::Result ContextVk::handleDirtyTextures(const gl::Context *context, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 382 | CommandBufferT *commandBuffer) |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 383 | { |
| 384 | ANGLE_TRY(updateActiveTextures(context)); |
| 385 | |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 386 | if (mProgram->hasTextures()) |
| 387 | { |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 388 | ANGLE_TRY(mProgram->updateTexturesDescriptorSet(this, mDrawFramebuffer->getFramebuffer())); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 389 | } |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 390 | return angle::Result::Continue; |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | angle::Result ContextVk::handleDirtyVertexBuffers(const gl::Context *context, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 394 | CommandBufferT *commandBuffer) |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 395 | { |
Jamie Madill | c759b8b | 2019-01-03 15:16:50 -0500 | [diff] [blame] | 396 | uint32_t maxAttrib = mProgram->getState().getMaxActiveAttribLocation(); |
| 397 | const gl::AttribArray<VkBuffer> &bufferHandles = mVertexArray->getCurrentArrayBufferHandles(); |
| 398 | const gl::AttribArray<VkDeviceSize> &bufferOffsets = |
| 399 | mVertexArray->getCurrentArrayBufferOffsets(); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 400 | |
Jamie Madill | c759b8b | 2019-01-03 15:16:50 -0500 | [diff] [blame] | 401 | commandBuffer->bindVertexBuffers(0, maxAttrib, bufferHandles.data(), bufferOffsets.data()); |
Jamie Madill | 03d1a5e | 2018-11-12 11:34:24 -0500 | [diff] [blame] | 402 | |
Jamie Madill | c759b8b | 2019-01-03 15:16:50 -0500 | [diff] [blame] | 403 | const gl::AttribArray<vk::BufferHelper *> &arrayBufferResources = |
| 404 | mVertexArray->getCurrentArrayBuffers(); |
Jamie Madill | 03d1a5e | 2018-11-12 11:34:24 -0500 | [diff] [blame] | 405 | vk::FramebufferHelper *framebuffer = mDrawFramebuffer->getFramebuffer(); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 406 | |
| 407 | for (size_t attribIndex : context->getStateCache().getActiveBufferedAttribsMask()) |
| 408 | { |
Jamie Madill | 03d1a5e | 2018-11-12 11:34:24 -0500 | [diff] [blame] | 409 | vk::BufferHelper *arrayBuffer = arrayBufferResources[attribIndex]; |
| 410 | if (arrayBuffer) |
| 411 | { |
Shahbaz Youssefi | 4abdf74 | 2018-11-28 14:41:10 -0500 | [diff] [blame] | 412 | arrayBuffer->onRead(framebuffer, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT); |
Jamie Madill | 03d1a5e | 2018-11-12 11:34:24 -0500 | [diff] [blame] | 413 | } |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 414 | } |
Jamie Madill | 03d1a5e | 2018-11-12 11:34:24 -0500 | [diff] [blame] | 415 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 416 | return angle::Result::Continue; |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | angle::Result ContextVk::handleDirtyIndexBuffer(const gl::Context *context, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 420 | CommandBufferT *commandBuffer) |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 421 | { |
Shahbaz Youssefi | 4abdf74 | 2018-11-28 14:41:10 -0500 | [diff] [blame] | 422 | vk::BufferHelper *elementArrayBuffer = mVertexArray->getCurrentElementArrayBuffer(); |
| 423 | ASSERT(elementArrayBuffer != nullptr); |
| 424 | |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 425 | commandBuffer->bindIndexBuffer(elementArrayBuffer->getBuffer(), |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 426 | mVertexArray->getCurrentElementArrayBufferOffset(), |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 427 | gl_vk::kIndexTypeMap[mCurrentDrawElementsType]); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 428 | |
Shahbaz Youssefi | 4abdf74 | 2018-11-28 14:41:10 -0500 | [diff] [blame] | 429 | vk::FramebufferHelper *framebuffer = mDrawFramebuffer->getFramebuffer(); |
| 430 | elementArrayBuffer->onRead(framebuffer, VK_ACCESS_INDEX_READ_BIT); |
| 431 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 432 | return angle::Result::Continue; |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | angle::Result ContextVk::handleDirtyDescriptorSets(const gl::Context *context, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 436 | CommandBufferT *commandBuffer) |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 437 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 438 | ANGLE_TRY(mProgram->updateDescriptorSets(this, commandBuffer)); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 439 | |
| 440 | // Bind the graphics descriptor sets. |
| 441 | commandBuffer->bindDescriptorSets( |
| 442 | VK_PIPELINE_BIND_POINT_GRAPHICS, mProgram->getPipelineLayout(), |
| 443 | kDriverUniformsDescriptorSetIndex, 1, &mDriverUniformsDescriptorSet, 0, nullptr); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 444 | return angle::Result::Continue; |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 445 | } |
| 446 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 447 | angle::Result ContextVk::drawArrays(const gl::Context *context, |
| 448 | gl::PrimitiveMode mode, |
| 449 | GLint first, |
| 450 | GLsizei count) |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 451 | { |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 452 | CommandBufferT *commandBuffer = nullptr; |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 453 | uint32_t clampedVertexCount = gl::GetClampedVertexCount<uint32_t>(count); |
Luc Ferron | 360098d | 2018-02-21 07:33:50 -0500 | [diff] [blame] | 454 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 455 | if (mode == gl::PrimitiveMode::LineLoop) |
| 456 | { |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 457 | ANGLE_TRY(setupLineLoopDraw(context, mode, first, count, gl::DrawElementsType::InvalidEnum, |
| 458 | nullptr, &commandBuffer)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 459 | vk::LineLoopHelper::Draw(clampedVertexCount, commandBuffer); |
| 460 | } |
| 461 | else |
| 462 | { |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 463 | ANGLE_TRY(setupDraw(context, mode, first, count, 1, gl::DrawElementsType::InvalidEnum, |
| 464 | nullptr, mNonIndexedDirtyBitsMask, &commandBuffer)); |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 465 | commandBuffer->draw(clampedVertexCount, 1, first, 0); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 466 | } |
Luc Ferron | 360098d | 2018-02-21 07:33:50 -0500 | [diff] [blame] | 467 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 468 | return angle::Result::Continue; |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 469 | } |
| 470 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 471 | angle::Result ContextVk::drawArraysInstanced(const gl::Context *context, |
| 472 | gl::PrimitiveMode mode, |
| 473 | GLint first, |
| 474 | GLsizei count, |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 475 | GLsizei instances) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 476 | { |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 477 | if (mode == gl::PrimitiveMode::LineLoop) |
| 478 | { |
| 479 | // TODO - http://anglebug.com/2672 |
| 480 | ANGLE_VK_UNREACHABLE(this); |
| 481 | return angle::Result::Stop; |
| 482 | } |
| 483 | |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 484 | CommandBufferT *commandBuffer = nullptr; |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 485 | ANGLE_TRY(setupDraw(context, mode, first, count, instances, gl::DrawElementsType::InvalidEnum, |
| 486 | nullptr, mNonIndexedDirtyBitsMask, &commandBuffer)); |
| 487 | commandBuffer->draw(gl::GetClampedVertexCount<uint32_t>(count), instances, first, 0); |
| 488 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 491 | angle::Result ContextVk::drawElements(const gl::Context *context, |
| 492 | gl::PrimitiveMode mode, |
| 493 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 494 | gl::DrawElementsType type, |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 495 | const void *indices) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 496 | { |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 497 | CommandBufferT *commandBuffer = nullptr; |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 498 | if (mode == gl::PrimitiveMode::LineLoop) |
| 499 | { |
Jamie Madill | bfe31c4 | 2018-10-25 17:03:47 -0400 | [diff] [blame] | 500 | ANGLE_TRY(setupLineLoopDraw(context, mode, 0, count, type, indices, &commandBuffer)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 501 | vk::LineLoopHelper::Draw(count, commandBuffer); |
| 502 | } |
| 503 | else |
| 504 | { |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 505 | ANGLE_TRY(setupIndexedDraw(context, mode, count, 1, type, indices, &commandBuffer)); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 506 | commandBuffer->drawIndexed(count, 1, 0, 0, 0); |
| 507 | } |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 508 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 509 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 510 | } |
| 511 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 512 | angle::Result ContextVk::drawElementsInstanced(const gl::Context *context, |
| 513 | gl::PrimitiveMode mode, |
| 514 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 515 | gl::DrawElementsType type, |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 516 | const void *indices, |
| 517 | GLsizei instances) |
| 518 | { |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 519 | if (mode == gl::PrimitiveMode::LineLoop) |
| 520 | { |
| 521 | // TODO - http://anglebug.com/2672 |
| 522 | ANGLE_VK_UNREACHABLE(this); |
| 523 | return angle::Result::Stop; |
| 524 | } |
| 525 | |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 526 | CommandBufferT *commandBuffer = nullptr; |
Frank Henigman | 52047de | 2018-11-13 17:22:36 -0500 | [diff] [blame] | 527 | ANGLE_TRY(setupIndexedDraw(context, mode, count, instances, type, indices, &commandBuffer)); |
| 528 | commandBuffer->drawIndexed(count, instances, 0, 0, 0); |
| 529 | return angle::Result::Continue; |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | angle::Result ContextVk::drawRangeElements(const gl::Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 533 | gl::PrimitiveMode mode, |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 534 | GLuint start, |
| 535 | GLuint end, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 536 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 537 | gl::DrawElementsType type, |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 538 | const void *indices) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 539 | { |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 540 | ANGLE_VK_UNREACHABLE(this); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 541 | return angle::Result::Stop; |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | VkDevice ContextVk::getDevice() const |
| 545 | { |
| 546 | return mRenderer->getDevice(); |
| 547 | } |
| 548 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 549 | angle::Result ContextVk::drawArraysIndirect(const gl::Context *context, |
| 550 | gl::PrimitiveMode mode, |
| 551 | const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 552 | { |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 553 | ANGLE_VK_UNREACHABLE(this); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 554 | return angle::Result::Stop; |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 555 | } |
| 556 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 557 | angle::Result ContextVk::drawElementsIndirect(const gl::Context *context, |
| 558 | gl::PrimitiveMode mode, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 559 | gl::DrawElementsType type, |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 560 | const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 561 | { |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 562 | ANGLE_VK_UNREACHABLE(this); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 563 | return angle::Result::Stop; |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 564 | } |
| 565 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 566 | GLenum ContextVk::getResetStatus() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 567 | { |
Geoff Lang | 2fe5e1d | 2018-08-28 14:00:24 -0400 | [diff] [blame] | 568 | if (mRenderer->isDeviceLost()) |
| 569 | { |
| 570 | // TODO(geofflang): It may be possible to track which context caused the device lost and |
| 571 | // return either GL_GUILTY_CONTEXT_RESET or GL_INNOCENT_CONTEXT_RESET. |
| 572 | // http://anglebug.com/2787 |
| 573 | return GL_UNKNOWN_CONTEXT_RESET; |
| 574 | } |
| 575 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 576 | return GL_NO_ERROR; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | std::string ContextVk::getVendorString() const |
| 580 | { |
| 581 | UNIMPLEMENTED(); |
| 582 | return std::string(); |
| 583 | } |
| 584 | |
| 585 | std::string ContextVk::getRendererDescription() const |
| 586 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 587 | return mRenderer->getRendererDescription(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | void ContextVk::insertEventMarker(GLsizei length, const char *marker) |
| 591 | { |
Shahbaz Youssefi | 4d15338 | 2019-02-26 15:08:11 +0000 | [diff] [blame] | 592 | std::string markerStr(marker, length <= 0 ? strlen(marker) : length); |
| 593 | mRenderer->insertDebugMarker(GL_DEBUG_SOURCE_APPLICATION, static_cast<GLuint>(-1), |
| 594 | std::move(markerStr)); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | void ContextVk::pushGroupMarker(GLsizei length, const char *marker) |
| 598 | { |
Shahbaz Youssefi | 4d15338 | 2019-02-26 15:08:11 +0000 | [diff] [blame] | 599 | std::string markerStr(marker, length <= 0 ? strlen(marker) : length); |
| 600 | mRenderer->pushDebugMarker(GL_DEBUG_SOURCE_APPLICATION, static_cast<GLuint>(-1), |
| 601 | std::move(markerStr)); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | void ContextVk::popGroupMarker() |
| 605 | { |
Shahbaz Youssefi | 4d15338 | 2019-02-26 15:08:11 +0000 | [diff] [blame] | 606 | mRenderer->popDebugMarker(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Shahbaz Youssefi | 4d15338 | 2019-02-26 15:08:11 +0000 | [diff] [blame] | 609 | void ContextVk::pushDebugGroup(GLenum source, GLuint id, const std::string &message) |
Geoff Lang | 5d5253a | 2017-11-22 14:51:12 -0500 | [diff] [blame] | 610 | { |
Shahbaz Youssefi | 4d15338 | 2019-02-26 15:08:11 +0000 | [diff] [blame] | 611 | mRenderer->pushDebugMarker(source, id, std::string(message)); |
Geoff Lang | 5d5253a | 2017-11-22 14:51:12 -0500 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | void ContextVk::popDebugGroup() |
| 615 | { |
Shahbaz Youssefi | 4d15338 | 2019-02-26 15:08:11 +0000 | [diff] [blame] | 616 | mRenderer->popDebugMarker(); |
Geoff Lang | 5d5253a | 2017-11-22 14:51:12 -0500 | [diff] [blame] | 617 | } |
| 618 | |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 619 | bool ContextVk::isViewportFlipEnabledForDrawFBO() const |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 620 | { |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 621 | return mFlipViewportForDrawFramebuffer && mFlipYForCurrentSurface; |
| 622 | } |
| 623 | |
| 624 | bool ContextVk::isViewportFlipEnabledForReadFBO() const |
| 625 | { |
| 626 | return mFlipViewportForReadFramebuffer; |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 627 | } |
| 628 | |
Luc Ferron | 0bb940a | 2018-06-22 09:59:34 -0400 | [diff] [blame] | 629 | void ContextVk::updateColorMask(const gl::BlendState &blendState) |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 630 | { |
| 631 | mClearColorMask = |
| 632 | gl_vk::GetColorComponentFlags(blendState.colorMaskRed, blendState.colorMaskGreen, |
| 633 | blendState.colorMaskBlue, blendState.colorMaskAlpha); |
| 634 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 635 | FramebufferVk *framebufferVk = vk::GetImpl(mState.getDrawFramebuffer()); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 636 | mGraphicsPipelineDesc->updateColorWriteMask(&mGraphicsPipelineTransition, mClearColorMask, |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 637 | framebufferVk->getEmulatedAlphaAttachmentMask()); |
Luc Ferron | 5fd3693 | 2018-06-19 14:55:50 -0400 | [diff] [blame] | 638 | } |
| 639 | |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 640 | void ContextVk::updateViewport(FramebufferVk *framebufferVk, |
| 641 | const gl::Rectangle &viewport, |
| 642 | float nearPlane, |
| 643 | float farPlane, |
| 644 | bool invertViewport) |
| 645 | { |
Jamie Madill | 633d5e6 | 2018-12-23 19:58:01 -0500 | [diff] [blame] | 646 | VkViewport vkViewport; |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 647 | gl_vk::GetViewport(viewport, nearPlane, farPlane, invertViewport, |
Jamie Madill | 633d5e6 | 2018-12-23 19:58:01 -0500 | [diff] [blame] | 648 | framebufferVk->getState().getDimensions().height, &vkViewport); |
| 649 | mGraphicsPipelineDesc->updateViewport(&mGraphicsPipelineTransition, vkViewport); |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 650 | invalidateDriverUniforms(); |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | void ContextVk::updateDepthRange(float nearPlane, float farPlane) |
| 654 | { |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 655 | invalidateDriverUniforms(); |
Jamie Madill | 633d5e6 | 2018-12-23 19:58:01 -0500 | [diff] [blame] | 656 | mGraphicsPipelineDesc->updateDepthRange(&mGraphicsPipelineTransition, nearPlane, farPlane); |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | void ContextVk::updateScissor(const gl::State &glState) |
Luc Ferron | d17bdfe | 2018-04-05 13:50:10 -0400 | [diff] [blame] | 660 | { |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 661 | FramebufferVk *framebufferVk = vk::GetImpl(glState.getDrawFramebuffer()); |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 662 | gl::Box dimensions = framebufferVk->getState().getDimensions(); |
| 663 | gl::Rectangle renderArea(0, 0, dimensions.width, dimensions.height); |
| 664 | |
Jamie Madill | 633d5e6 | 2018-12-23 19:58:01 -0500 | [diff] [blame] | 665 | VkRect2D scissor; |
| 666 | gl_vk::GetScissor(glState, isViewportFlipEnabledForDrawFBO(), renderArea, &scissor); |
| 667 | mGraphicsPipelineDesc->updateScissor(&mGraphicsPipelineTransition, scissor); |
Luc Ferron | d17bdfe | 2018-04-05 13:50:10 -0400 | [diff] [blame] | 668 | } |
| 669 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 670 | angle::Result ContextVk::syncState(const gl::Context *context, |
Jamie Madill | 9d0bb3d | 2018-10-09 20:29:13 -0400 | [diff] [blame] | 671 | const gl::State::DirtyBits &dirtyBits, |
| 672 | const gl::State::DirtyBits &bitMask) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 673 | { |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 674 | if (dirtyBits.any()) |
| 675 | { |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 676 | invalidateVertexAndIndexBuffers(); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 677 | } |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 678 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 679 | const gl::State &glState = context->getState(); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 680 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 681 | for (size_t dirtyBit : dirtyBits) |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 682 | { |
| 683 | switch (dirtyBit) |
| 684 | { |
| 685 | case gl::State::DIRTY_BIT_SCISSOR_TEST_ENABLED: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 686 | case gl::State::DIRTY_BIT_SCISSOR: |
Luc Ferron | 14f4817 | 2018-04-11 08:43:28 -0400 | [diff] [blame] | 687 | updateScissor(glState); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 688 | break; |
| 689 | case gl::State::DIRTY_BIT_VIEWPORT: |
Luc Ferron | 1a135ad | 2018-07-04 10:35:31 -0400 | [diff] [blame] | 690 | { |
| 691 | FramebufferVk *framebufferVk = vk::GetImpl(glState.getDrawFramebuffer()); |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 692 | updateViewport(framebufferVk, glState.getViewport(), glState.getNearPlane(), |
| 693 | glState.getFarPlane(), isViewportFlipEnabledForDrawFBO()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 694 | break; |
Luc Ferron | 1a135ad | 2018-07-04 10:35:31 -0400 | [diff] [blame] | 695 | } |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 696 | case gl::State::DIRTY_BIT_DEPTH_RANGE: |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 697 | updateDepthRange(glState.getNearPlane(), glState.getFarPlane()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 698 | break; |
| 699 | case gl::State::DIRTY_BIT_BLEND_ENABLED: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 700 | mGraphicsPipelineDesc->updateBlendEnabled(&mGraphicsPipelineTransition, |
| 701 | glState.isBlendEnabled()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 702 | break; |
| 703 | case gl::State::DIRTY_BIT_BLEND_COLOR: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 704 | mGraphicsPipelineDesc->updateBlendColor(&mGraphicsPipelineTransition, |
| 705 | glState.getBlendColor()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 706 | break; |
| 707 | case gl::State::DIRTY_BIT_BLEND_FUNCS: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 708 | mGraphicsPipelineDesc->updateBlendFuncs(&mGraphicsPipelineTransition, |
| 709 | glState.getBlendState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 710 | break; |
| 711 | case gl::State::DIRTY_BIT_BLEND_EQUATIONS: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 712 | mGraphicsPipelineDesc->updateBlendEquations(&mGraphicsPipelineTransition, |
| 713 | glState.getBlendState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 714 | break; |
| 715 | case gl::State::DIRTY_BIT_COLOR_MASK: |
Luc Ferron | 0bb940a | 2018-06-22 09:59:34 -0400 | [diff] [blame] | 716 | updateColorMask(glState.getBlendState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 717 | break; |
| 718 | case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 719 | break; |
| 720 | case gl::State::DIRTY_BIT_SAMPLE_COVERAGE_ENABLED: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 721 | break; |
| 722 | case gl::State::DIRTY_BIT_SAMPLE_COVERAGE: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 723 | break; |
| 724 | case gl::State::DIRTY_BIT_SAMPLE_MASK_ENABLED: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 725 | break; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 726 | case gl::State::DIRTY_BIT_SAMPLE_MASK: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 727 | break; |
| 728 | case gl::State::DIRTY_BIT_DEPTH_TEST_ENABLED: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 729 | mGraphicsPipelineDesc->updateDepthTestEnabled(&mGraphicsPipelineTransition, |
| 730 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 731 | glState.getDrawFramebuffer()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 732 | break; |
| 733 | case gl::State::DIRTY_BIT_DEPTH_FUNC: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 734 | mGraphicsPipelineDesc->updateDepthFunc(&mGraphicsPipelineTransition, |
| 735 | glState.getDepthStencilState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 736 | break; |
| 737 | case gl::State::DIRTY_BIT_DEPTH_MASK: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 738 | mGraphicsPipelineDesc->updateDepthWriteEnabled(&mGraphicsPipelineTransition, |
| 739 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 740 | glState.getDrawFramebuffer()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 741 | break; |
| 742 | case gl::State::DIRTY_BIT_STENCIL_TEST_ENABLED: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 743 | mGraphicsPipelineDesc->updateStencilTestEnabled(&mGraphicsPipelineTransition, |
| 744 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 745 | glState.getDrawFramebuffer()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 746 | break; |
| 747 | case gl::State::DIRTY_BIT_STENCIL_FUNCS_FRONT: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 748 | mGraphicsPipelineDesc->updateStencilFrontFuncs(&mGraphicsPipelineTransition, |
| 749 | glState.getStencilRef(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 750 | glState.getDepthStencilState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 751 | break; |
| 752 | case gl::State::DIRTY_BIT_STENCIL_FUNCS_BACK: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 753 | mGraphicsPipelineDesc->updateStencilBackFuncs(&mGraphicsPipelineTransition, |
| 754 | glState.getStencilBackRef(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 755 | glState.getDepthStencilState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 756 | break; |
| 757 | case gl::State::DIRTY_BIT_STENCIL_OPS_FRONT: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 758 | mGraphicsPipelineDesc->updateStencilFrontOps(&mGraphicsPipelineTransition, |
| 759 | glState.getDepthStencilState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 760 | break; |
| 761 | case gl::State::DIRTY_BIT_STENCIL_OPS_BACK: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 762 | mGraphicsPipelineDesc->updateStencilBackOps(&mGraphicsPipelineTransition, |
| 763 | glState.getDepthStencilState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 764 | break; |
| 765 | case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 766 | mGraphicsPipelineDesc->updateStencilFrontWriteMask(&mGraphicsPipelineTransition, |
| 767 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 768 | glState.getDrawFramebuffer()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 769 | break; |
| 770 | case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_BACK: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 771 | mGraphicsPipelineDesc->updateStencilBackWriteMask(&mGraphicsPipelineTransition, |
| 772 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 773 | glState.getDrawFramebuffer()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 774 | break; |
| 775 | case gl::State::DIRTY_BIT_CULL_FACE_ENABLED: |
| 776 | case gl::State::DIRTY_BIT_CULL_FACE: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 777 | mGraphicsPipelineDesc->updateCullMode(&mGraphicsPipelineTransition, |
| 778 | glState.getRasterizerState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 779 | break; |
| 780 | case gl::State::DIRTY_BIT_FRONT_FACE: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 781 | mGraphicsPipelineDesc->updateFrontFace(&mGraphicsPipelineTransition, |
| 782 | glState.getRasterizerState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 783 | isViewportFlipEnabledForDrawFBO()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 784 | break; |
| 785 | case gl::State::DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED: |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 786 | mGraphicsPipelineDesc->updatePolygonOffsetFillEnabled( |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 787 | &mGraphicsPipelineTransition, glState.isPolygonOffsetFillEnabled()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 788 | break; |
| 789 | case gl::State::DIRTY_BIT_POLYGON_OFFSET: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 790 | mGraphicsPipelineDesc->updatePolygonOffset(&mGraphicsPipelineTransition, |
| 791 | glState.getRasterizerState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 792 | break; |
| 793 | case gl::State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 794 | break; |
| 795 | case gl::State::DIRTY_BIT_LINE_WIDTH: |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 796 | mGraphicsPipelineDesc->updateLineWidth(&mGraphicsPipelineTransition, |
| 797 | glState.getLineWidth()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 798 | break; |
| 799 | case gl::State::DIRTY_BIT_PRIMITIVE_RESTART_ENABLED: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 800 | break; |
| 801 | case gl::State::DIRTY_BIT_CLEAR_COLOR: |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 802 | mClearColorValue.color.float32[0] = glState.getColorClearValue().red; |
| 803 | mClearColorValue.color.float32[1] = glState.getColorClearValue().green; |
| 804 | mClearColorValue.color.float32[2] = glState.getColorClearValue().blue; |
| 805 | mClearColorValue.color.float32[3] = glState.getColorClearValue().alpha; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 806 | break; |
| 807 | case gl::State::DIRTY_BIT_CLEAR_DEPTH: |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 808 | mClearDepthStencilValue.depthStencil.depth = glState.getDepthClearValue(); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 809 | break; |
| 810 | case gl::State::DIRTY_BIT_CLEAR_STENCIL: |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 811 | mClearDepthStencilValue.depthStencil.stencil = |
| 812 | static_cast<uint32_t>(glState.getStencilClearValue()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 813 | break; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 814 | case gl::State::DIRTY_BIT_UNPACK_STATE: |
Luc Ferron | f9749ea | 2018-04-24 15:34:53 -0400 | [diff] [blame] | 815 | // This is a no-op, its only important to use the right unpack state when we do |
| 816 | // setImage or setSubImage in TextureVk, which is plumbed through the frontend call |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 817 | break; |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 818 | case gl::State::DIRTY_BIT_UNPACK_BUFFER_BINDING: |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 819 | break; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 820 | case gl::State::DIRTY_BIT_PACK_STATE: |
Luc Ferron | a1c7242 | 2018-05-14 15:58:28 -0400 | [diff] [blame] | 821 | // This is a no-op, its only important to use the right pack state when we do |
| 822 | // call readPixels later on. |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 823 | break; |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 824 | case gl::State::DIRTY_BIT_PACK_BUFFER_BINDING: |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 825 | break; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 826 | case gl::State::DIRTY_BIT_DITHER_ENABLED: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 827 | break; |
| 828 | case gl::State::DIRTY_BIT_GENERATE_MIPMAP_HINT: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 829 | break; |
| 830 | case gl::State::DIRTY_BIT_SHADER_DERIVATIVE_HINT: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 831 | break; |
| 832 | case gl::State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING: |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 833 | updateFlipViewportReadFramebuffer(context->getState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 834 | break; |
| 835 | case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING: |
Luc Ferron | 1a135ad | 2018-07-04 10:35:31 -0400 | [diff] [blame] | 836 | { |
Jamie Madill | 85ca189 | 2019-01-16 13:27:15 -0500 | [diff] [blame] | 837 | // FramebufferVk::syncState signals that we should start a new command buffer. But |
| 838 | // changing the binding can skip FramebufferVk::syncState if the Framebuffer has no |
| 839 | // dirty bits. Thus we need to explicitly clear the current command buffer to |
| 840 | // ensure we start a new one. Note that we need a new command buffer because a |
| 841 | // command graph node can only support one RenderPass configuration at a time. |
| 842 | onCommandBufferFinished(); |
| 843 | |
Jamie Madill | 37386b0 | 2018-08-30 16:18:37 -0400 | [diff] [blame] | 844 | mDrawFramebuffer = vk::GetImpl(glState.getDrawFramebuffer()); |
Luc Ferron | e835609 | 2018-07-12 12:36:47 -0400 | [diff] [blame] | 845 | updateFlipViewportDrawFramebuffer(glState); |
Jamie Madill | bc5834c | 2018-11-06 11:13:50 -0500 | [diff] [blame] | 846 | updateViewport(mDrawFramebuffer, glState.getViewport(), glState.getNearPlane(), |
| 847 | glState.getFarPlane(), isViewportFlipEnabledForDrawFBO()); |
Luc Ferron | 0bb940a | 2018-06-22 09:59:34 -0400 | [diff] [blame] | 848 | updateColorMask(glState.getBlendState()); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 849 | mGraphicsPipelineDesc->updateCullMode(&mGraphicsPipelineTransition, |
| 850 | glState.getRasterizerState()); |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 851 | updateScissor(glState); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 852 | mGraphicsPipelineDesc->updateDepthTestEnabled(&mGraphicsPipelineTransition, |
| 853 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 854 | glState.getDrawFramebuffer()); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 855 | mGraphicsPipelineDesc->updateDepthWriteEnabled(&mGraphicsPipelineTransition, |
| 856 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 857 | glState.getDrawFramebuffer()); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 858 | mGraphicsPipelineDesc->updateStencilTestEnabled(&mGraphicsPipelineTransition, |
| 859 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 860 | glState.getDrawFramebuffer()); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 861 | mGraphicsPipelineDesc->updateStencilFrontWriteMask(&mGraphicsPipelineTransition, |
| 862 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 863 | glState.getDrawFramebuffer()); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 864 | mGraphicsPipelineDesc->updateStencilBackWriteMask(&mGraphicsPipelineTransition, |
| 865 | glState.getDepthStencilState(), |
Shahbaz Youssefi | c30f45d | 2018-11-12 16:37:59 -0500 | [diff] [blame] | 866 | glState.getDrawFramebuffer()); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 867 | mGraphicsPipelineDesc->updateRenderPassDesc(&mGraphicsPipelineTransition, |
| 868 | mDrawFramebuffer->getRenderPassDesc()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 869 | break; |
Luc Ferron | 1a135ad | 2018-07-04 10:35:31 -0400 | [diff] [blame] | 870 | } |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 871 | case gl::State::DIRTY_BIT_RENDERBUFFER_BINDING: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 872 | break; |
| 873 | case gl::State::DIRTY_BIT_VERTEX_ARRAY_BINDING: |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 874 | { |
Jamie Madill | 37386b0 | 2018-08-30 16:18:37 -0400 | [diff] [blame] | 875 | mVertexArray = vk::GetImpl(glState.getVertexArray()); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 876 | invalidateDefaultAttributes(context->getStateCache().getActiveDefaultAttribsMask()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 877 | break; |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 878 | } |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 879 | case gl::State::DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 880 | break; |
Qin Jiajia | a98a281 | 2017-11-30 18:12:06 +0800 | [diff] [blame] | 881 | case gl::State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING: |
Qin Jiajia | a98a281 | 2017-11-30 18:12:06 +0800 | [diff] [blame] | 882 | break; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 883 | case gl::State::DIRTY_BIT_PROGRAM_BINDING: |
Jamie Madill | 37386b0 | 2018-08-30 16:18:37 -0400 | [diff] [blame] | 884 | mProgram = vk::GetImpl(glState.getProgram()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 885 | break; |
| 886 | case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE: |
| 887 | { |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 888 | invalidateCurrentTextures(); |
Jamie Madill | 06ca634 | 2018-07-12 15:56:53 -0400 | [diff] [blame] | 889 | // No additional work is needed here. We will update the pipeline desc later. |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 890 | invalidateDefaultAttributes(context->getStateCache().getActiveDefaultAttribsMask()); |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 891 | bool useVertexBuffer = (mProgram->getState().getMaxActiveAttribLocation()); |
| 892 | mNonIndexedDirtyBitsMask.set(DIRTY_BIT_VERTEX_BUFFERS, useVertexBuffer); |
| 893 | mIndexedDirtyBitsMask.set(DIRTY_BIT_VERTEX_BUFFERS, useVertexBuffer); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 894 | mCurrentPipeline = nullptr; |
| 895 | mGraphicsPipelineTransition.reset(); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 896 | break; |
| 897 | } |
| 898 | case gl::State::DIRTY_BIT_TEXTURE_BINDINGS: |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 899 | invalidateCurrentTextures(); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 900 | break; |
| 901 | case gl::State::DIRTY_BIT_SAMPLER_BINDINGS: |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 902 | invalidateCurrentTextures(); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 903 | break; |
Geoff Lang | ded7923 | 2017-11-28 15:21:11 -0500 | [diff] [blame] | 904 | case gl::State::DIRTY_BIT_TRANSFORM_FEEDBACK_BINDING: |
Geoff Lang | ded7923 | 2017-11-28 15:21:11 -0500 | [diff] [blame] | 905 | break; |
Xinghua Cao | 10a4d43 | 2017-11-28 14:46:26 +0800 | [diff] [blame] | 906 | case gl::State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING: |
Xinghua Cao | 10a4d43 | 2017-11-28 14:46:26 +0800 | [diff] [blame] | 907 | break; |
Jamie Madill | f414121 | 2017-12-12 15:08:07 -0500 | [diff] [blame] | 908 | case gl::State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS: |
Jamie Madill | f414121 | 2017-12-12 15:08:07 -0500 | [diff] [blame] | 909 | break; |
jchen10 | 99118c1 | 2018-09-10 16:28:51 +0800 | [diff] [blame] | 910 | case gl::State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING: |
| 911 | break; |
| 912 | case gl::State::DIRTY_BIT_IMAGE_BINDINGS: |
| 913 | break; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 914 | case gl::State::DIRTY_BIT_MULTISAMPLING: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 915 | break; |
| 916 | case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_ONE: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 917 | break; |
| 918 | case gl::State::DIRTY_BIT_COVERAGE_MODULATION: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 919 | break; |
jchen10 | bb2f2c4 | 2018-09-16 09:47:38 +0800 | [diff] [blame] | 920 | case gl::State::DIRTY_BIT_PATH_RENDERING: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 921 | break; |
| 922 | case gl::State::DIRTY_BIT_FRAMEBUFFER_SRGB: |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 923 | break; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 924 | case gl::State::DIRTY_BIT_CURRENT_VALUES: |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 925 | { |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 926 | invalidateDefaultAttributes(glState.getAndResetDirtyCurrentValues()); |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 927 | break; |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 928 | } |
Jeff Gilbert | 465d609 | 2019-01-02 16:21:18 -0800 | [diff] [blame] | 929 | case gl::State::DIRTY_BIT_PROVOKING_VERTEX: |
| 930 | break; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 931 | default: |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 932 | UNREACHABLE(); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 933 | break; |
| 934 | } |
| 935 | } |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 936 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 937 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | GLint ContextVk::getGPUDisjoint() |
| 941 | { |
Shahbaz Youssefi | 749589f | 2018-10-25 12:48:49 -0400 | [diff] [blame] | 942 | // No extension seems to be available to query this information. |
| 943 | return 0; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | GLint64 ContextVk::getTimestamp() |
| 947 | { |
Shahbaz Youssefi | 749589f | 2018-10-25 12:48:49 -0400 | [diff] [blame] | 948 | uint64_t timestamp = 0; |
| 949 | |
| 950 | (void)mRenderer->getTimestamp(this, ×tamp); |
| 951 | |
| 952 | return static_cast<GLint64>(timestamp); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 953 | } |
| 954 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 955 | angle::Result ContextVk::onMakeCurrent(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 956 | { |
Geoff Lang | caa55cd | 2018-07-05 13:19:35 -0400 | [diff] [blame] | 957 | // Flip viewports if FeaturesVk::flipViewportY is enabled and the user did not request that the |
| 958 | // surface is flipped. |
| 959 | egl::Surface *drawSurface = context->getCurrentDrawSurface(); |
| 960 | mFlipYForCurrentSurface = |
| 961 | drawSurface != nullptr && mRenderer->getFeatures().flipViewportY && |
| 962 | !IsMaskFlagSet(drawSurface->getOrientation(), EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE); |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 963 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 964 | const gl::State &glState = context->getState(); |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 965 | updateFlipViewportDrawFramebuffer(glState); |
| 966 | updateFlipViewportReadFramebuffer(glState); |
Jamie Madill | 74c179b | 2018-09-24 10:53:23 -0400 | [diff] [blame] | 967 | invalidateDriverUniforms(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 968 | return angle::Result::Continue; |
Luc Ferron | 82eda93 | 2018-07-09 15:10:22 -0400 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | void ContextVk::updateFlipViewportDrawFramebuffer(const gl::State &glState) |
| 972 | { |
| 973 | gl::Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
| 974 | mFlipViewportForDrawFramebuffer = |
| 975 | drawFramebuffer->isDefault() && mRenderer->getFeatures().flipViewportY; |
| 976 | } |
| 977 | |
| 978 | void ContextVk::updateFlipViewportReadFramebuffer(const gl::State &glState) |
| 979 | { |
| 980 | gl::Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 981 | mFlipViewportForReadFramebuffer = |
| 982 | readFramebuffer->isDefault() && mRenderer->getFeatures().flipViewportY; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 983 | } |
| 984 | |
Jiawei Shao | d0a7d10 | 2018-05-07 12:40:20 +0800 | [diff] [blame] | 985 | gl::Caps ContextVk::getNativeCaps() const |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 986 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 987 | return mRenderer->getNativeCaps(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | const gl::TextureCapsMap &ContextVk::getNativeTextureCaps() const |
| 991 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 992 | return mRenderer->getNativeTextureCaps(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | const gl::Extensions &ContextVk::getNativeExtensions() const |
| 996 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 997 | return mRenderer->getNativeExtensions(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | const gl::Limitations &ContextVk::getNativeLimitations() const |
| 1001 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1002 | return mRenderer->getNativeLimitations(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | CompilerImpl *ContextVk::createCompiler() |
| 1006 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1007 | return new CompilerVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1008 | } |
| 1009 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1010 | ShaderImpl *ContextVk::createShader(const gl::ShaderState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1011 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1012 | return new ShaderVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1015 | ProgramImpl *ContextVk::createProgram(const gl::ProgramState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1016 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1017 | return new ProgramVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1018 | } |
| 1019 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1020 | FramebufferImpl *ContextVk::createFramebuffer(const gl::FramebufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1021 | { |
Jamie Madill | 639bc90 | 2018-07-18 17:08:27 -0400 | [diff] [blame] | 1022 | return FramebufferVk::CreateUserFBO(mRenderer, state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | TextureImpl *ContextVk::createTexture(const gl::TextureState &state) |
| 1026 | { |
Luc Ferron | a9ab0f3 | 2018-05-17 17:03:55 -0400 | [diff] [blame] | 1027 | return new TextureVk(state, mRenderer); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1028 | } |
| 1029 | |
Jamie Madill | e703c60 | 2018-02-20 10:21:48 -0500 | [diff] [blame] | 1030 | RenderbufferImpl *ContextVk::createRenderbuffer(const gl::RenderbufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1031 | { |
Jamie Madill | e703c60 | 2018-02-20 10:21:48 -0500 | [diff] [blame] | 1032 | return new RenderbufferVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1033 | } |
| 1034 | |
Jamie Madill | 8f77560 | 2016-11-03 16:45:34 -0400 | [diff] [blame] | 1035 | BufferImpl *ContextVk::createBuffer(const gl::BufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1036 | { |
Jamie Madill | 8f77560 | 2016-11-03 16:45:34 -0400 | [diff] [blame] | 1037 | return new BufferVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1038 | } |
| 1039 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1040 | VertexArrayImpl *ContextVk::createVertexArray(const gl::VertexArrayState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1041 | { |
Jamie Madill | c759b8b | 2019-01-03 15:16:50 -0500 | [diff] [blame] | 1042 | return new VertexArrayVk(this, state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1043 | } |
| 1044 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1045 | QueryImpl *ContextVk::createQuery(gl::QueryType type) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1046 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1047 | return new QueryVk(type); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | FenceNVImpl *ContextVk::createFenceNV() |
| 1051 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 1052 | return new FenceNVVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 1055 | SyncImpl *ContextVk::createSync() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1056 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 1057 | return new SyncVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1058 | } |
| 1059 | |
Geoff Lang | 73bd218 | 2016-07-15 13:01:24 -0400 | [diff] [blame] | 1060 | TransformFeedbackImpl *ContextVk::createTransformFeedback(const gl::TransformFeedbackState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1061 | { |
Geoff Lang | 73bd218 | 2016-07-15 13:01:24 -0400 | [diff] [blame] | 1062 | return new TransformFeedbackVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1063 | } |
| 1064 | |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1065 | SamplerImpl *ContextVk::createSampler(const gl::SamplerState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1066 | { |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1067 | return new SamplerVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1068 | } |
| 1069 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 1070 | ProgramPipelineImpl *ContextVk::createProgramPipeline(const gl::ProgramPipelineState &state) |
| 1071 | { |
| 1072 | return new ProgramPipelineVk(state); |
| 1073 | } |
| 1074 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1075 | std::vector<PathImpl *> ContextVk::createPaths(GLsizei) |
| 1076 | { |
| 1077 | return std::vector<PathImpl *>(); |
| 1078 | } |
| 1079 | |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 1080 | void ContextVk::invalidateCurrentTextures() |
| 1081 | { |
| 1082 | ASSERT(mProgram); |
| 1083 | if (mProgram->hasTextures()) |
| 1084 | { |
| 1085 | mDirtyBits.set(DIRTY_BIT_TEXTURES); |
| 1086 | mDirtyBits.set(DIRTY_BIT_DESCRIPTOR_SETS); |
| 1087 | } |
| 1088 | } |
| 1089 | |
Jamie Madill | 74c179b | 2018-09-24 10:53:23 -0400 | [diff] [blame] | 1090 | void ContextVk::invalidateDriverUniforms() |
| 1091 | { |
| 1092 | mDirtyBits.set(DIRTY_BIT_DRIVER_UNIFORMS); |
| 1093 | mDirtyBits.set(DIRTY_BIT_DESCRIPTOR_SETS); |
| 1094 | } |
| 1095 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 1096 | void ContextVk::onFramebufferChange(const vk::RenderPassDesc &renderPassDesc) |
| 1097 | { |
| 1098 | // Ensure that the RenderPass description is updated. |
| 1099 | invalidateCurrentPipeline(); |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 1100 | mGraphicsPipelineDesc->updateRenderPassDesc(&mGraphicsPipelineTransition, renderPassDesc); |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 1103 | angle::Result ContextVk::dispatchCompute(const gl::Context *context, |
| 1104 | GLuint numGroupsX, |
| 1105 | GLuint numGroupsY, |
| 1106 | GLuint numGroupsZ) |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 1107 | { |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 1108 | ANGLE_VK_UNREACHABLE(this); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1109 | return angle::Result::Stop; |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 1110 | } |
| 1111 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 1112 | angle::Result ContextVk::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect) |
Qin Jiajia | 62fcf62 | 2017-11-30 16:16:12 +0800 | [diff] [blame] | 1113 | { |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 1114 | ANGLE_VK_UNREACHABLE(this); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1115 | return angle::Result::Stop; |
Qin Jiajia | 62fcf62 | 2017-11-30 16:16:12 +0800 | [diff] [blame] | 1116 | } |
| 1117 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 1118 | angle::Result ContextVk::memoryBarrier(const gl::Context *context, GLbitfield barriers) |
Xinghua Cao | 89c422a | 2017-11-29 18:24:20 +0800 | [diff] [blame] | 1119 | { |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 1120 | ANGLE_VK_UNREACHABLE(this); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1121 | return angle::Result::Stop; |
Xinghua Cao | 89c422a | 2017-11-29 18:24:20 +0800 | [diff] [blame] | 1122 | } |
| 1123 | |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 1124 | angle::Result ContextVk::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) |
Xinghua Cao | 89c422a | 2017-11-29 18:24:20 +0800 | [diff] [blame] | 1125 | { |
Jamie Madill | 32643ce | 2018-10-19 11:38:03 -0400 | [diff] [blame] | 1126 | ANGLE_VK_UNREACHABLE(this); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1127 | return angle::Result::Stop; |
Xinghua Cao | 89c422a | 2017-11-29 18:24:20 +0800 | [diff] [blame] | 1128 | } |
| 1129 | |
Jamie Madill | edeaa83 | 2018-06-22 09:18:41 -0400 | [diff] [blame] | 1130 | vk::DynamicDescriptorPool *ContextVk::getDynamicDescriptorPool(uint32_t descriptorSetIndex) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 1131 | { |
Jamie Madill | edeaa83 | 2018-06-22 09:18:41 -0400 | [diff] [blame] | 1132 | return &mDynamicDescriptorPools[descriptorSetIndex]; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 1133 | } |
| 1134 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 1135 | vk::DynamicQueryPool *ContextVk::getQueryPool(gl::QueryType queryType) |
| 1136 | { |
| 1137 | ASSERT(queryType == gl::QueryType::AnySamples || |
Shahbaz Youssefi | c2b576d | 2018-10-12 14:45:34 -0400 | [diff] [blame] | 1138 | queryType == gl::QueryType::AnySamplesConservative || |
| 1139 | queryType == gl::QueryType::Timestamp || queryType == gl::QueryType::TimeElapsed); |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 1140 | ASSERT(mQueryPools[queryType].isValid()); |
| 1141 | return &mQueryPools[queryType]; |
| 1142 | } |
| 1143 | |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 1144 | const VkClearValue &ContextVk::getClearColorValue() const |
| 1145 | { |
| 1146 | return mClearColorValue; |
| 1147 | } |
| 1148 | |
| 1149 | const VkClearValue &ContextVk::getClearDepthStencilValue() const |
| 1150 | { |
| 1151 | return mClearDepthStencilValue; |
| 1152 | } |
| 1153 | |
Jamie Madill | 9aef367 | 2018-04-27 11:45:06 -0400 | [diff] [blame] | 1154 | VkColorComponentFlags ContextVk::getClearColorMask() const |
| 1155 | { |
| 1156 | return mClearColorMask; |
| 1157 | } |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1158 | |
Jamie Madill | ef6023e | 2018-09-06 16:24:38 -0400 | [diff] [blame] | 1159 | angle::Result ContextVk::handleDirtyDriverUniforms(const gl::Context *context, |
Tobin Ehlis | 134425c | 2019-03-15 17:02:17 -0600 | [diff] [blame^] | 1160 | CommandBufferT *commandBuffer) |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1161 | { |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1162 | // Release any previously retained buffers. |
| 1163 | mDriverUniformsBuffer.releaseRetainedBuffers(mRenderer); |
| 1164 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1165 | const gl::Rectangle &glViewport = mState.getViewport(); |
Jamie Madill | 8e9d234 | 2018-09-10 13:29:37 -0400 | [diff] [blame] | 1166 | float halfRenderAreaHeight = |
| 1167 | static_cast<float>(mDrawFramebuffer->getState().getDimensions().height) * 0.5f; |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1168 | |
| 1169 | // Allocate a new region in the dynamic buffer. |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 1170 | uint8_t *ptr = nullptr; |
| 1171 | VkBuffer buffer = VK_NULL_HANDLE; |
| 1172 | VkDeviceSize offset = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1173 | ANGLE_TRY(mDriverUniformsBuffer.allocate(this, sizeof(DriverUniforms), &ptr, &buffer, &offset, |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 1174 | nullptr)); |
Jamie Madill | fb19e08 | 2018-09-06 15:39:09 -0400 | [diff] [blame] | 1175 | float scaleY = isViewportFlipEnabledForDrawFBO() ? -1.0f : 1.0f; |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1176 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1177 | float depthRangeNear = mState.getNearPlane(); |
| 1178 | float depthRangeFar = mState.getFarPlane(); |
Luc Ferron | e835609 | 2018-07-12 12:36:47 -0400 | [diff] [blame] | 1179 | float depthRangeDiff = depthRangeFar - depthRangeNear; |
| 1180 | |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1181 | // Copy and flush to the device. |
| 1182 | DriverUniforms *driverUniforms = reinterpret_cast<DriverUniforms *>(ptr); |
Luc Ferron | 9ff9c77 | 2018-07-11 13:08:18 -0400 | [diff] [blame] | 1183 | *driverUniforms = { |
| 1184 | {static_cast<float>(glViewport.x), static_cast<float>(glViewport.y), |
| 1185 | static_cast<float>(glViewport.width), static_cast<float>(glViewport.height)}, |
Jamie Madill | 8e9d234 | 2018-09-10 13:29:37 -0400 | [diff] [blame] | 1186 | halfRenderAreaHeight, |
| 1187 | scaleY, |
| 1188 | -scaleY, |
| 1189 | 0.0f, |
Luc Ferron | e835609 | 2018-07-12 12:36:47 -0400 | [diff] [blame] | 1190 | {depthRangeNear, depthRangeFar, depthRangeDiff, 0.0f}}; |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1191 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1192 | ANGLE_TRY(mDriverUniformsBuffer.flush(this)); |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1193 | |
| 1194 | // Get the descriptor set layout. |
| 1195 | if (!mDriverUniformsSetLayout.valid()) |
| 1196 | { |
| 1197 | vk::DescriptorSetLayoutDesc desc; |
| 1198 | desc.update(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1); |
| 1199 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1200 | ANGLE_TRY(mRenderer->getDescriptorSetLayout(this, desc, &mDriverUniformsSetLayout)); |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | // Allocate a new descriptor set. |
| 1204 | ANGLE_TRY(mDynamicDescriptorPools[kDriverUniformsDescriptorSetIndex].allocateSets( |
Jamie Madill | 78bcd2b | 2018-10-16 15:05:20 -0400 | [diff] [blame] | 1205 | this, mDriverUniformsSetLayout.get().ptr(), 1, &mDriverUniformsDescriptorPoolBinding, |
| 1206 | &mDriverUniformsDescriptorSet)); |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1207 | |
| 1208 | // Update the driver uniform descriptor set. |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 1209 | VkDescriptorBufferInfo bufferInfo = {}; |
Jamie Madill | 77abad8 | 2018-10-25 17:03:48 -0400 | [diff] [blame] | 1210 | bufferInfo.buffer = buffer; |
| 1211 | bufferInfo.offset = offset; |
| 1212 | bufferInfo.range = sizeof(DriverUniforms); |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1213 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 1214 | VkWriteDescriptorSet writeInfo = {}; |
Jamie Madill | 77abad8 | 2018-10-25 17:03:48 -0400 | [diff] [blame] | 1215 | writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1216 | writeInfo.dstSet = mDriverUniformsDescriptorSet; |
| 1217 | writeInfo.dstBinding = 0; |
| 1218 | writeInfo.dstArrayElement = 0; |
| 1219 | writeInfo.descriptorCount = 1; |
| 1220 | writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1221 | writeInfo.pImageInfo = nullptr; |
| 1222 | writeInfo.pTexelBufferView = nullptr; |
| 1223 | writeInfo.pBufferInfo = &bufferInfo; |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1224 | |
| 1225 | vkUpdateDescriptorSets(getDevice(), 1, &writeInfo, 0, nullptr); |
| 1226 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1227 | return angle::Result::Continue; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1228 | } |
| 1229 | |
Jamie Madill | 4f6592f | 2018-11-27 16:37:45 -0500 | [diff] [blame] | 1230 | void ContextVk::handleError(VkResult errorCode, |
| 1231 | const char *file, |
| 1232 | const char *function, |
| 1233 | unsigned int line) |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1234 | { |
Jamie Madill | 4f6592f | 2018-11-27 16:37:45 -0500 | [diff] [blame] | 1235 | ASSERT(errorCode != VK_SUCCESS); |
| 1236 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1237 | GLenum glErrorCode = DefaultGLErrorCode(errorCode); |
| 1238 | |
| 1239 | std::stringstream errorStream; |
Jamie Madill | 4f6592f | 2018-11-27 16:37:45 -0500 | [diff] [blame] | 1240 | errorStream << "Internal Vulkan error: " << VulkanResultString(errorCode) << "."; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 1241 | |
Geoff Lang | 2fe5e1d | 2018-08-28 14:00:24 -0400 | [diff] [blame] | 1242 | if (errorCode == VK_ERROR_DEVICE_LOST) |
| 1243 | { |
Yuly Novikov | ffdbfa3 | 2018-11-19 12:04:17 -0500 | [diff] [blame] | 1244 | WARN() << errorStream.str(); |
Yuly Novikov | b56ddbb | 2018-11-02 16:53:18 -0400 | [diff] [blame] | 1245 | mRenderer->notifyDeviceLost(); |
Geoff Lang | 2fe5e1d | 2018-08-28 14:00:24 -0400 | [diff] [blame] | 1246 | } |
| 1247 | |
Jamie Madill | 4f6592f | 2018-11-27 16:37:45 -0500 | [diff] [blame] | 1248 | mErrors->handleError(glErrorCode, errorStream.str().c_str(), file, function, line); |
Jamie Madill | 834a3a1 | 2018-07-09 13:32:39 -0400 | [diff] [blame] | 1249 | } |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 1250 | |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 1251 | angle::Result ContextVk::updateActiveTextures(const gl::Context *context) |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 1252 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1253 | const gl::State &glState = mState; |
Jamie Madill | 4787d70 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 1254 | const gl::Program *program = glState.getProgram(); |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 1255 | |
| 1256 | mActiveTextures.fill(nullptr); |
| 1257 | |
Jamie Madill | 4787d70 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 1258 | const gl::ActiveTexturePointerArray &textures = glState.getActiveTexturesCache(); |
| 1259 | const gl::ActiveTextureMask &activeTextures = program->getActiveSamplersMask(); |
| 1260 | const gl::ActiveTextureTypeArray &textureTypes = program->getActiveSamplerTypes(); |
| 1261 | |
| 1262 | for (size_t textureUnit : activeTextures) |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 1263 | { |
Jamie Madill | 4787d70 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 1264 | gl::Texture *texture = textures[textureUnit]; |
| 1265 | gl::TextureType textureType = textureTypes[textureUnit]; |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 1266 | |
Jamie Madill | 4787d70 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 1267 | // Null textures represent incomplete textures. |
| 1268 | if (texture == nullptr) |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 1269 | { |
Jamie Madill | 666818e | 2018-11-14 09:54:33 -0500 | [diff] [blame] | 1270 | ANGLE_TRY(getIncompleteTexture(context, textureType, &texture)); |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 1271 | } |
Jamie Madill | 4787d70 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 1272 | |
| 1273 | mActiveTextures[textureUnit] = vk::GetImpl(texture); |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 1274 | } |
| 1275 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1276 | return angle::Result::Continue; |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | const gl::ActiveTextureArray<TextureVk *> &ContextVk::getActiveTextures() const |
| 1280 | { |
| 1281 | return mActiveTextures; |
| 1282 | } |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 1283 | |
| 1284 | void ContextVk::invalidateDefaultAttribute(size_t attribIndex) |
| 1285 | { |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 1286 | mDirtyDefaultAttribsMask.set(attribIndex); |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 1287 | mDirtyBits.set(DIRTY_BIT_DEFAULT_ATTRIBS); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | void ContextVk::invalidateDefaultAttributes(const gl::AttributesMask &dirtyMask) |
| 1291 | { |
| 1292 | if (dirtyMask.any()) |
| 1293 | { |
Shahbaz Youssefi | 0c2dc8c | 2018-12-07 08:00:49 +0100 | [diff] [blame] | 1294 | mDirtyDefaultAttribsMask |= dirtyMask; |
Jamie Madill | ef3b9b4 | 2018-08-30 16:18:38 -0400 | [diff] [blame] | 1295 | mDirtyBits.set(DIRTY_BIT_DEFAULT_ATTRIBS); |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 1296 | } |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 1297 | } |
| 1298 | |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 1299 | angle::Result ContextVk::updateDefaultAttribute(size_t attribIndex) |
| 1300 | { |
| 1301 | vk::DynamicBuffer &defaultBuffer = mDefaultAttribBuffers[attribIndex]; |
| 1302 | |
| 1303 | defaultBuffer.releaseRetainedBuffers(mRenderer); |
| 1304 | |
| 1305 | uint8_t *ptr; |
| 1306 | VkBuffer bufferHandle = VK_NULL_HANDLE; |
Jamie Madill | 4c31083 | 2018-08-29 13:43:17 -0400 | [diff] [blame] | 1307 | VkDeviceSize offset = 0; |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 1308 | ANGLE_TRY( |
| 1309 | defaultBuffer.allocate(this, kDefaultValueSize, &ptr, &bufferHandle, &offset, nullptr)); |
| 1310 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1311 | const gl::State &glState = mState; |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 1312 | const gl::VertexAttribCurrentValueData &defaultValue = |
| 1313 | glState.getVertexAttribCurrentValues()[attribIndex]; |
| 1314 | |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame] | 1315 | ASSERT(defaultValue.Type == gl::VertexAttribType::Float); |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 1316 | |
| 1317 | memcpy(ptr, defaultValue.FloatValues, kDefaultValueSize); |
| 1318 | |
| 1319 | ANGLE_TRY(defaultBuffer.flush(this)); |
| 1320 | |
Jamie Madill | 80766cf | 2019-01-10 10:20:34 -0500 | [diff] [blame] | 1321 | mVertexArray->updateDefaultAttrib(this, attribIndex, bufferHandle, |
Jamie Madill | 37386b0 | 2018-08-30 16:18:37 -0400 | [diff] [blame] | 1322 | static_cast<uint32_t>(offset)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1323 | return angle::Result::Continue; |
Jamie Madill | 5a4c932 | 2018-07-16 11:01:58 -0400 | [diff] [blame] | 1324 | } |
Jamie Madill | 3f0c4a5 | 2019-01-10 10:20:35 -0500 | [diff] [blame] | 1325 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1326 | } // namespace rx |