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