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