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