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