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