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