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