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