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" |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 14 | #include "libANGLE/Context.h" |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 15 | #include "libANGLE/Program.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 16 | #include "libANGLE/renderer/vulkan/BufferVk.h" |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 17 | #include "libANGLE/renderer/vulkan/CommandGraph.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 18 | #include "libANGLE/renderer/vulkan/CompilerVk.h" |
| 19 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
| 20 | #include "libANGLE/renderer/vulkan/DeviceVk.h" |
| 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" |
| 23 | #include "libANGLE/renderer/vulkan/ImageVk.h" |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 24 | #include "libANGLE/renderer/vulkan/ProgramPipelineVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 25 | #include "libANGLE/renderer/vulkan/ProgramVk.h" |
| 26 | #include "libANGLE/renderer/vulkan/QueryVk.h" |
| 27 | #include "libANGLE/renderer/vulkan/RenderbufferVk.h" |
| 28 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
| 29 | #include "libANGLE/renderer/vulkan/SamplerVk.h" |
| 30 | #include "libANGLE/renderer/vulkan/ShaderVk.h" |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 31 | #include "libANGLE/renderer/vulkan/SyncVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 32 | #include "libANGLE/renderer/vulkan/TextureVk.h" |
| 33 | #include "libANGLE/renderer/vulkan/TransformFeedbackVk.h" |
| 34 | #include "libANGLE/renderer/vulkan/VertexArrayVk.h" |
Jamie Madill | 3c424b4 | 2018-01-19 12:35:09 -0500 | [diff] [blame] | 35 | #include "libANGLE/renderer/vulkan/vk_format_utils.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 36 | |
| 37 | namespace rx |
| 38 | { |
| 39 | |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 40 | namespace |
| 41 | { |
| 42 | |
| 43 | VkIndexType GetVkIndexType(GLenum glIndexType) |
| 44 | { |
| 45 | switch (glIndexType) |
| 46 | { |
| 47 | case GL_UNSIGNED_SHORT: |
| 48 | return VK_INDEX_TYPE_UINT16; |
| 49 | case GL_UNSIGNED_INT: |
| 50 | return VK_INDEX_TYPE_UINT32; |
| 51 | default: |
| 52 | UNREACHABLE(); |
| 53 | return VK_INDEX_TYPE_MAX_ENUM; |
| 54 | } |
| 55 | } |
| 56 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 57 | enum DescriptorPoolIndex : uint8_t |
| 58 | { |
| 59 | UniformBufferPool = 0, |
| 60 | TexturePool = 1, |
| 61 | }; |
| 62 | |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 63 | } // anonymous namespace |
| 64 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 65 | ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer) |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 66 | : ContextImpl(state), |
| 67 | mRenderer(renderer), |
| 68 | mCurrentDrawMode(GL_NONE), |
| 69 | mVertexArrayDirty(false), |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 70 | mTexturesDirty(false), |
| 71 | mStreamingVertexData(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, 1024 * 1024) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 72 | { |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 73 | memset(&mClearColorValue, 0, sizeof(mClearColorValue)); |
| 74 | memset(&mClearDepthStencilValue, 0, sizeof(mClearDepthStencilValue)); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | ContextVk::~ContextVk() |
| 78 | { |
| 79 | } |
| 80 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 81 | void ContextVk::onDestroy(const gl::Context *context) |
| 82 | { |
| 83 | VkDevice device = mRenderer->getDevice(); |
| 84 | |
| 85 | mDescriptorPool.destroy(device); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 86 | mStreamingVertexData.destroy(device); |
Luc Ferron | 360098d | 2018-02-21 07:33:50 -0500 | [diff] [blame] | 87 | mLineLoopHandler.destroy(device); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 88 | } |
| 89 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 90 | gl::Error ContextVk::initialize() |
| 91 | { |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 92 | VkDevice device = mRenderer->getDevice(); |
| 93 | |
| 94 | VkDescriptorPoolSize poolSizes[2]; |
| 95 | poolSizes[UniformBufferPool].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 96 | poolSizes[UniformBufferPool].descriptorCount = 1024; |
| 97 | poolSizes[TexturePool].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 98 | poolSizes[TexturePool].descriptorCount = 1024; |
| 99 | |
| 100 | VkDescriptorPoolCreateInfo descriptorPoolInfo; |
| 101 | descriptorPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 102 | descriptorPoolInfo.pNext = nullptr; |
| 103 | descriptorPoolInfo.flags = 0; |
| 104 | |
| 105 | // TODO(jmadill): Pick non-arbitrary max. |
| 106 | descriptorPoolInfo.maxSets = 2048; |
| 107 | |
| 108 | // Reserve pools for uniform blocks and textures. |
| 109 | descriptorPoolInfo.poolSizeCount = 2; |
| 110 | descriptorPoolInfo.pPoolSizes = poolSizes; |
| 111 | |
| 112 | ANGLE_TRY(mDescriptorPool.init(device, descriptorPoolInfo)); |
| 113 | |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 114 | mPipelineDesc.reset(new vk::PipelineDesc()); |
| 115 | mPipelineDesc->initDefaults(); |
| 116 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 117 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 118 | } |
| 119 | |
Jamie Madill | afa02a2 | 2017-11-23 12:57:38 -0500 | [diff] [blame] | 120 | gl::Error ContextVk::flush(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 121 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 122 | // TODO(jmadill): Flush will need to insert a semaphore for the next flush to wait on. |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 123 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 124 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Jamie Madill | afa02a2 | 2017-11-23 12:57:38 -0500 | [diff] [blame] | 127 | gl::Error ContextVk::finish(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 128 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 129 | return mRenderer->finish(context); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 130 | } |
| 131 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 132 | gl::Error ContextVk::initPipeline(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 133 | { |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 134 | ASSERT(!mCurrentPipeline); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 135 | |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 136 | const gl::State &state = mState.getState(); |
| 137 | VertexArrayVk *vertexArrayVk = vk::GetImpl(state.getVertexArray()); |
| 138 | FramebufferVk *framebufferVk = vk::GetImpl(state.getDrawFramebuffer()); |
| 139 | ProgramVk *programVk = vk::GetImpl(state.getProgram()); |
Luc Ferron | ceb7190 | 2018-02-05 15:18:47 -0500 | [diff] [blame] | 140 | const gl::AttributesMask activeAttribLocationsMask = |
| 141 | state.getProgram()->getActiveAttribLocationsMask(); |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 142 | |
| 143 | // Ensure the topology of the pipeline description is updated. |
| 144 | mPipelineDesc->updateTopology(mCurrentDrawMode); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 145 | |
Jamie Madill | 112a3a8 | 2018-01-23 13:04:06 -0500 | [diff] [blame] | 146 | // Copy over the latest attrib and binding descriptions. |
| 147 | vertexArrayVk->getPackedInputDescriptions(mPipelineDesc.get()); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 148 | |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 149 | // Ensure that the RenderPass description is updated. |
| 150 | mPipelineDesc->updateRenderPassDesc(framebufferVk->getRenderPassDesc(context)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 151 | |
| 152 | // TODO(jmadill): Validate with ASSERT against physical device limits/caps? |
Luc Ferron | ceb7190 | 2018-02-05 15:18:47 -0500 | [diff] [blame] | 153 | ANGLE_TRY(mRenderer->getPipeline(programVk, *mPipelineDesc, activeAttribLocationsMask, |
| 154 | &mCurrentPipeline)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 155 | |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 156 | return gl::NoError(); |
| 157 | } |
| 158 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 159 | gl::Error ContextVk::setupDraw(const gl::Context *context, |
| 160 | GLenum mode, |
| 161 | DrawType drawType, |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 162 | int firstVertex, |
| 163 | int lastVertex, |
Luc Ferron | 78e39b3 | 2018-02-26 07:42:44 -0500 | [diff] [blame^] | 164 | ResourceVk *elementArrayBufferOverride, |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 165 | vk::CommandBuffer **commandBuffer) |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 166 | { |
| 167 | if (mode != mCurrentDrawMode) |
| 168 | { |
| 169 | invalidateCurrentPipeline(); |
| 170 | mCurrentDrawMode = mode; |
| 171 | } |
| 172 | |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 173 | if (!mCurrentPipeline) |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 174 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 175 | ANGLE_TRY(initPipeline(context)); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 176 | } |
| 177 | |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 178 | const auto &state = mState.getState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 179 | const gl::Program *programGL = state.getProgram(); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 180 | ProgramVk *programVk = vk::GetImpl(programGL); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 181 | const gl::VertexArray *vao = state.getVertexArray(); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 182 | VertexArrayVk *vkVAO = vk::GetImpl(vao); |
| 183 | const auto *drawFBO = state.getDrawFramebuffer(); |
| 184 | FramebufferVk *vkFBO = vk::GetImpl(drawFBO); |
Luc Ferron | f8be756 | 2018-02-06 15:59:11 -0500 | [diff] [blame] | 185 | Serial queueSerial = mRenderer->getCurrentQueueSerial(); |
| 186 | uint32_t maxAttrib = programGL->getState().getMaxActiveAttribLocation(); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 187 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 188 | vk::CommandGraphNode *renderNode = nullptr; |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 189 | ANGLE_TRY(vkFBO->getRenderNode(context, &renderNode)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 190 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 191 | if (!renderNode->getInsideRenderPassCommands()->valid()) |
| 192 | { |
| 193 | mVertexArrayDirty = true; |
| 194 | mTexturesDirty = true; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 195 | ANGLE_TRY(renderNode->beginInsideRenderPassRecording(mRenderer, commandBuffer)); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 196 | } |
| 197 | else |
| 198 | { |
| 199 | *commandBuffer = renderNode->getInsideRenderPassCommands(); |
| 200 | } |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 201 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 202 | // Ensure any writes to the VAO buffers are flushed before we read from them. |
Luc Ferron | 78e39b3 | 2018-02-26 07:42:44 -0500 | [diff] [blame^] | 203 | if (mVertexArrayDirty || elementArrayBufferOverride != nullptr) |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 204 | { |
Luc Ferron | 78e39b3 | 2018-02-26 07:42:44 -0500 | [diff] [blame^] | 205 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 206 | mVertexArrayDirty = false; |
| 207 | vkVAO->updateDrawDependencies(renderNode, programGL->getActiveAttribLocationsMask(), |
Luc Ferron | 78e39b3 | 2018-02-26 07:42:44 -0500 | [diff] [blame^] | 208 | elementArrayBufferOverride, queueSerial, drawType); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | // Ensure any writes to the textures are flushed before we read from them. |
| 212 | if (mTexturesDirty) |
| 213 | { |
| 214 | mTexturesDirty = false; |
| 215 | // TODO(jmadill): Should probably merge this for loop with programVk's descriptor update. |
| 216 | const auto &completeTextures = state.getCompleteTextureCache(); |
| 217 | for (const gl::SamplerBinding &samplerBinding : programGL->getSamplerBindings()) |
| 218 | { |
| 219 | ASSERT(!samplerBinding.unreferenced); |
| 220 | |
| 221 | // TODO(jmadill): Sampler arrays |
| 222 | ASSERT(samplerBinding.boundTextureUnits.size() == 1); |
| 223 | |
| 224 | GLuint textureUnit = samplerBinding.boundTextureUnits[0]; |
| 225 | const gl::Texture *texture = completeTextures[textureUnit]; |
| 226 | |
| 227 | // TODO(jmadill): Incomplete textures handling. |
| 228 | ASSERT(texture); |
| 229 | |
| 230 | TextureVk *textureVk = vk::GetImpl(texture); |
Jamie Madill | 0e65454 | 2018-02-07 14:50:06 -0500 | [diff] [blame] | 231 | textureVk->onReadResource(renderNode, mRenderer->getCurrentQueueSerial()); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 235 | (*commandBuffer)->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline->get()); |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 236 | ContextVk *contextVk = vk::GetImpl(context); |
| 237 | ANGLE_TRY(vkVAO->streamVertexData(contextVk, &mStreamingVertexData, firstVertex, lastVertex)); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 238 | (*commandBuffer) |
Frank Henigman | 1744895 | 2017-01-05 15:48:26 -0500 | [diff] [blame] | 239 | ->bindVertexBuffers(0, maxAttrib, vkVAO->getCurrentArrayBufferHandles().data(), |
| 240 | vkVAO->getCurrentArrayBufferOffsets().data()); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 241 | |
| 242 | // Update the queue serial for the pipeline object. |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 243 | ASSERT(mCurrentPipeline && mCurrentPipeline->valid()); |
| 244 | mCurrentPipeline->updateSerial(queueSerial); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 245 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 246 | // TODO(jmadill): Can probably use more dirty bits here. |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 247 | ANGLE_TRY(programVk->updateUniforms(this)); |
| 248 | programVk->updateTexturesDescriptorSet(this); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 249 | |
| 250 | // Bind the graphics descriptor sets. |
| 251 | // TODO(jmadill): Handle multiple command buffers. |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 252 | const auto &descriptorSets = programVk->getDescriptorSets(); |
Jamie Madill | 8c3988c | 2017-12-21 14:44:56 -0500 | [diff] [blame] | 253 | const gl::RangeUI &usedRange = programVk->getUsedDescriptorSetRange(); |
| 254 | if (!usedRange.empty()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 255 | { |
Jamie Madill | 8c3988c | 2017-12-21 14:44:56 -0500 | [diff] [blame] | 256 | ASSERT(!descriptorSets.empty()); |
| 257 | const vk::PipelineLayout &pipelineLayout = mRenderer->getGraphicsPipelineLayout(); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 258 | (*commandBuffer) |
Jamie Madill | 8c3988c | 2017-12-21 14:44:56 -0500 | [diff] [blame] | 259 | ->bindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, usedRange.low(), |
| 260 | usedRange.length(), &descriptorSets[usedRange.low()], 0, nullptr); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 261 | } |
| 262 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 263 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 264 | } |
| 265 | |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 266 | gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count) |
| 267 | { |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 268 | vk::CommandBuffer *commandBuffer = nullptr; |
Luc Ferron | 78e39b3 | 2018-02-26 07:42:44 -0500 | [diff] [blame^] | 269 | ANGLE_TRY(setupDraw(context, mode, DrawType::Arrays, first, first + count - 1, nullptr, |
| 270 | &commandBuffer)); |
Luc Ferron | 360098d | 2018-02-21 07:33:50 -0500 | [diff] [blame] | 271 | |
| 272 | if (mode == GL_LINE_LOOP) |
| 273 | { |
Luc Ferron | 78e39b3 | 2018-02-26 07:42:44 -0500 | [diff] [blame^] | 274 | ANGLE_TRY(mLineLoopHandler.createIndexBuffer(this, first, count)); |
| 275 | mLineLoopHandler.bindIndexBuffer(VK_INDEX_TYPE_UINT32, &commandBuffer); |
| 276 | ANGLE_TRY(mLineLoopHandler.draw(count, commandBuffer)); |
Luc Ferron | 360098d | 2018-02-21 07:33:50 -0500 | [diff] [blame] | 277 | } |
| 278 | else |
| 279 | { |
| 280 | commandBuffer->draw(count, 1, first, 0); |
| 281 | } |
| 282 | |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 283 | return gl::NoError(); |
| 284 | } |
| 285 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 286 | gl::Error ContextVk::drawArraysInstanced(const gl::Context *context, |
| 287 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 288 | GLint first, |
| 289 | GLsizei count, |
| 290 | GLsizei instanceCount) |
| 291 | { |
| 292 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 293 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 296 | gl::Error ContextVk::drawElements(const gl::Context *context, |
| 297 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 298 | GLsizei count, |
| 299 | GLenum type, |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 300 | const void *indices) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 301 | { |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 302 | const gl::Buffer *elementArrayBuffer = |
| 303 | mState.getState().getVertexArray()->getElementArrayBuffer().get(); |
| 304 | ASSERT(elementArrayBuffer); |
| 305 | |
Luc Ferron | 78e39b3 | 2018-02-26 07:42:44 -0500 | [diff] [blame^] | 306 | BufferVk *elementArrayBufferVk = vk::GetImpl(elementArrayBuffer); |
| 307 | vk::CommandBuffer *commandBuffer = nullptr; |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 308 | |
Luc Ferron | 78e39b3 | 2018-02-26 07:42:44 -0500 | [diff] [blame^] | 309 | if (mode == GL_LINE_LOOP) |
| 310 | { |
| 311 | ANGLE_TRY(mLineLoopHandler.createIndexBufferFromElementArrayBuffer( |
| 312 | this, elementArrayBufferVk, GetVkIndexType(type), count)); |
| 313 | |
| 314 | // TODO(fjhenigman): calculate the index range and pass to setupDraw() |
| 315 | ANGLE_TRY(setupDraw(context, mode, DrawType::Elements, 0, 0, |
| 316 | mLineLoopHandler.getLineLoopBufferResource(), &commandBuffer)); |
| 317 | |
| 318 | mLineLoopHandler.bindIndexBuffer(GetVkIndexType(type), &commandBuffer); |
| 319 | commandBuffer->drawIndexed(count + 1, 1, 0, 0, 0); |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | // TODO(fjhenigman): calculate the index range and pass to setupDraw() |
| 324 | ANGLE_TRY(setupDraw(context, mode, DrawType::Elements, 0, 0, nullptr, &commandBuffer)); |
| 325 | |
| 326 | if (indices) |
| 327 | { |
| 328 | // TODO(jmadill): Buffer offsets and immediate data. |
| 329 | UNIMPLEMENTED(); |
| 330 | return gl::InternalError() |
| 331 | << "Only zero-offset index buffers are currently implemented."; |
| 332 | } |
| 333 | |
| 334 | if (type == GL_UNSIGNED_BYTE) |
| 335 | { |
| 336 | // TODO(jmadill): Index translation. |
| 337 | UNIMPLEMENTED(); |
| 338 | return gl::InternalError() << "Unsigned byte translation is not yet implemented."; |
| 339 | } |
| 340 | |
| 341 | commandBuffer->bindIndexBuffer(elementArrayBufferVk->getVkBuffer(), 0, |
| 342 | GetVkIndexType(type)); |
| 343 | commandBuffer->drawIndexed(count, 1, 0, 0, 0); |
| 344 | } |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 345 | |
| 346 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 347 | } |
| 348 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 349 | gl::Error ContextVk::drawElementsInstanced(const gl::Context *context, |
| 350 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 351 | GLsizei count, |
| 352 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 353 | const void *indices, |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 354 | GLsizei instances) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 355 | { |
| 356 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 357 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 358 | } |
| 359 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 360 | gl::Error ContextVk::drawRangeElements(const gl::Context *context, |
| 361 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 362 | GLuint start, |
| 363 | GLuint end, |
| 364 | GLsizei count, |
| 365 | GLenum type, |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 366 | const void *indices) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 367 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 368 | return gl::NoError(); |
| 369 | } |
| 370 | |
| 371 | VkDevice ContextVk::getDevice() const |
| 372 | { |
| 373 | return mRenderer->getDevice(); |
| 374 | } |
| 375 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 376 | gl::Error ContextVk::drawArraysIndirect(const gl::Context *context, |
| 377 | GLenum mode, |
| 378 | const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 379 | { |
| 380 | UNIMPLEMENTED(); |
| 381 | return gl::InternalError() << "DrawArraysIndirect hasn't been implemented for vulkan backend."; |
| 382 | } |
| 383 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 384 | gl::Error ContextVk::drawElementsIndirect(const gl::Context *context, |
| 385 | GLenum mode, |
| 386 | GLenum type, |
| 387 | const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 388 | { |
| 389 | UNIMPLEMENTED(); |
| 390 | return gl::InternalError() |
| 391 | << "DrawElementsIndirect hasn't been implemented for vulkan backend."; |
| 392 | } |
| 393 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 394 | GLenum ContextVk::getResetStatus() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 395 | { |
| 396 | UNIMPLEMENTED(); |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 397 | return GL_NO_ERROR; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | std::string ContextVk::getVendorString() const |
| 401 | { |
| 402 | UNIMPLEMENTED(); |
| 403 | return std::string(); |
| 404 | } |
| 405 | |
| 406 | std::string ContextVk::getRendererDescription() const |
| 407 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 408 | return mRenderer->getRendererDescription(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void ContextVk::insertEventMarker(GLsizei length, const char *marker) |
| 412 | { |
| 413 | UNIMPLEMENTED(); |
| 414 | } |
| 415 | |
| 416 | void ContextVk::pushGroupMarker(GLsizei length, const char *marker) |
| 417 | { |
| 418 | UNIMPLEMENTED(); |
| 419 | } |
| 420 | |
| 421 | void ContextVk::popGroupMarker() |
| 422 | { |
| 423 | UNIMPLEMENTED(); |
| 424 | } |
| 425 | |
Geoff Lang | 5d5253a | 2017-11-22 14:51:12 -0500 | [diff] [blame] | 426 | void ContextVk::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) |
| 427 | { |
| 428 | UNIMPLEMENTED(); |
| 429 | } |
| 430 | |
| 431 | void ContextVk::popDebugGroup() |
| 432 | { |
| 433 | UNIMPLEMENTED(); |
| 434 | } |
| 435 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 436 | void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 437 | { |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 438 | if (dirtyBits.any()) |
| 439 | { |
| 440 | invalidateCurrentPipeline(); |
| 441 | } |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 442 | |
| 443 | const auto &glState = context->getGLState(); |
| 444 | |
| 445 | // TODO(jmadill): Full dirty bits implementation. |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 446 | bool dirtyTextures = false; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 447 | |
| 448 | for (auto dirtyBit : dirtyBits) |
| 449 | { |
| 450 | switch (dirtyBit) |
| 451 | { |
| 452 | case gl::State::DIRTY_BIT_SCISSOR_TEST_ENABLED: |
Luc Ferron | 00155d5 | 2018-02-06 10:48:47 -0500 | [diff] [blame] | 453 | if (glState.isScissorTestEnabled()) |
| 454 | { |
| 455 | mPipelineDesc->updateScissor(glState.getScissor()); |
| 456 | } |
| 457 | else |
| 458 | { |
| 459 | mPipelineDesc->updateScissor(glState.getViewport()); |
| 460 | } |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 461 | break; |
| 462 | case gl::State::DIRTY_BIT_SCISSOR: |
Luc Ferron | 00155d5 | 2018-02-06 10:48:47 -0500 | [diff] [blame] | 463 | // Only modify the scissor region if the test is enabled, otherwise we want to keep |
| 464 | // the viewport size as the scissor region. |
| 465 | if (glState.isScissorTestEnabled()) |
| 466 | { |
| 467 | mPipelineDesc->updateScissor(glState.getScissor()); |
| 468 | } |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 469 | break; |
| 470 | case gl::State::DIRTY_BIT_VIEWPORT: |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 471 | mPipelineDesc->updateViewport(glState.getViewport(), glState.getNearPlane(), |
| 472 | glState.getFarPlane()); |
Luc Ferron | 00155d5 | 2018-02-06 10:48:47 -0500 | [diff] [blame] | 473 | |
| 474 | // If the scissor test isn't enabled, we have to also update the scissor to |
| 475 | // be equal to the viewport to make sure we keep rendering everything in the |
| 476 | // viewport. |
| 477 | if (!glState.isScissorTestEnabled()) |
| 478 | { |
| 479 | mPipelineDesc->updateScissor(glState.getViewport()); |
| 480 | } |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 481 | break; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 482 | case gl::State::DIRTY_BIT_DEPTH_RANGE: |
| 483 | WARN() << "DIRTY_BIT_DEPTH_RANGE unimplemented"; |
| 484 | break; |
| 485 | case gl::State::DIRTY_BIT_BLEND_ENABLED: |
Luc Ferron | f8be756 | 2018-02-06 15:59:11 -0500 | [diff] [blame] | 486 | mPipelineDesc->updateBlendEnabled(glState.isBlendEnabled()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 487 | break; |
| 488 | case gl::State::DIRTY_BIT_BLEND_COLOR: |
Luc Ferron | f8be756 | 2018-02-06 15:59:11 -0500 | [diff] [blame] | 489 | mPipelineDesc->updateBlendColor(glState.getBlendColor()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 490 | break; |
| 491 | case gl::State::DIRTY_BIT_BLEND_FUNCS: |
Luc Ferron | f8be756 | 2018-02-06 15:59:11 -0500 | [diff] [blame] | 492 | mPipelineDesc->updateBlendFuncs(glState.getBlendState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 493 | break; |
| 494 | case gl::State::DIRTY_BIT_BLEND_EQUATIONS: |
Luc Ferron | f8be756 | 2018-02-06 15:59:11 -0500 | [diff] [blame] | 495 | mPipelineDesc->updateBlendEquations(glState.getBlendState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 496 | break; |
| 497 | case gl::State::DIRTY_BIT_COLOR_MASK: |
| 498 | WARN() << "DIRTY_BIT_COLOR_MASK unimplemented"; |
| 499 | break; |
| 500 | case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED: |
| 501 | WARN() << "DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED unimplemented"; |
| 502 | break; |
| 503 | case gl::State::DIRTY_BIT_SAMPLE_COVERAGE_ENABLED: |
| 504 | WARN() << "DIRTY_BIT_SAMPLE_COVERAGE_ENABLED unimplemented"; |
| 505 | break; |
| 506 | case gl::State::DIRTY_BIT_SAMPLE_COVERAGE: |
| 507 | WARN() << "DIRTY_BIT_SAMPLE_COVERAGE unimplemented"; |
| 508 | break; |
| 509 | case gl::State::DIRTY_BIT_SAMPLE_MASK_ENABLED: |
| 510 | WARN() << "DIRTY_BIT_SAMPLE_MASK_ENABLED unimplemented"; |
| 511 | break; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 512 | case gl::State::DIRTY_BIT_SAMPLE_MASK: |
| 513 | WARN() << "DIRTY_BIT_SAMPLE_MASK unimplemented"; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 514 | break; |
| 515 | case gl::State::DIRTY_BIT_DEPTH_TEST_ENABLED: |
| 516 | WARN() << "DIRTY_BIT_DEPTH_TEST_ENABLED unimplemented"; |
| 517 | break; |
| 518 | case gl::State::DIRTY_BIT_DEPTH_FUNC: |
| 519 | WARN() << "DIRTY_BIT_DEPTH_FUNC unimplemented"; |
| 520 | break; |
| 521 | case gl::State::DIRTY_BIT_DEPTH_MASK: |
| 522 | WARN() << "DIRTY_BIT_DEPTH_MASK unimplemented"; |
| 523 | break; |
| 524 | case gl::State::DIRTY_BIT_STENCIL_TEST_ENABLED: |
| 525 | WARN() << "DIRTY_BIT_STENCIL_TEST_ENABLED unimplemented"; |
| 526 | break; |
| 527 | case gl::State::DIRTY_BIT_STENCIL_FUNCS_FRONT: |
| 528 | WARN() << "DIRTY_BIT_STENCIL_FUNCS_FRONT unimplemented"; |
| 529 | break; |
| 530 | case gl::State::DIRTY_BIT_STENCIL_FUNCS_BACK: |
| 531 | WARN() << "DIRTY_BIT_STENCIL_FUNCS_BACK unimplemented"; |
| 532 | break; |
| 533 | case gl::State::DIRTY_BIT_STENCIL_OPS_FRONT: |
| 534 | WARN() << "DIRTY_BIT_STENCIL_OPS_FRONT unimplemented"; |
| 535 | break; |
| 536 | case gl::State::DIRTY_BIT_STENCIL_OPS_BACK: |
| 537 | WARN() << "DIRTY_BIT_STENCIL_OPS_BACK unimplemented"; |
| 538 | break; |
| 539 | case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT: |
| 540 | WARN() << "DIRTY_BIT_STENCIL_WRITEMASK_FRONT unimplemented"; |
| 541 | break; |
| 542 | case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_BACK: |
| 543 | WARN() << "DIRTY_BIT_STENCIL_WRITEMASK_BACK unimplemented"; |
| 544 | break; |
| 545 | case gl::State::DIRTY_BIT_CULL_FACE_ENABLED: |
| 546 | case gl::State::DIRTY_BIT_CULL_FACE: |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 547 | mPipelineDesc->updateCullMode(glState.getRasterizerState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 548 | break; |
| 549 | case gl::State::DIRTY_BIT_FRONT_FACE: |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 550 | mPipelineDesc->updateFrontFace(glState.getRasterizerState()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 551 | break; |
| 552 | case gl::State::DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED: |
| 553 | WARN() << "DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED unimplemented"; |
| 554 | break; |
| 555 | case gl::State::DIRTY_BIT_POLYGON_OFFSET: |
| 556 | WARN() << "DIRTY_BIT_POLYGON_OFFSET unimplemented"; |
| 557 | break; |
| 558 | case gl::State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED: |
| 559 | WARN() << "DIRTY_BIT_RASTERIZER_DISCARD_ENABLED unimplemented"; |
| 560 | break; |
| 561 | case gl::State::DIRTY_BIT_LINE_WIDTH: |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 562 | mPipelineDesc->updateLineWidth(glState.getLineWidth()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 563 | break; |
| 564 | case gl::State::DIRTY_BIT_PRIMITIVE_RESTART_ENABLED: |
| 565 | WARN() << "DIRTY_BIT_PRIMITIVE_RESTART_ENABLED unimplemented"; |
| 566 | break; |
| 567 | case gl::State::DIRTY_BIT_CLEAR_COLOR: |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 568 | mClearColorValue.color.float32[0] = glState.getColorClearValue().red; |
| 569 | mClearColorValue.color.float32[1] = glState.getColorClearValue().green; |
| 570 | mClearColorValue.color.float32[2] = glState.getColorClearValue().blue; |
| 571 | mClearColorValue.color.float32[3] = glState.getColorClearValue().alpha; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 572 | break; |
| 573 | case gl::State::DIRTY_BIT_CLEAR_DEPTH: |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 574 | mClearDepthStencilValue.depthStencil.depth = glState.getDepthClearValue(); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 575 | break; |
| 576 | case gl::State::DIRTY_BIT_CLEAR_STENCIL: |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 577 | mClearDepthStencilValue.depthStencil.stencil = |
| 578 | static_cast<uint32_t>(glState.getStencilClearValue()); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 579 | break; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 580 | case gl::State::DIRTY_BIT_UNPACK_STATE: |
| 581 | WARN() << "DIRTY_BIT_UNPACK_STATE unimplemented"; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 582 | break; |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 583 | case gl::State::DIRTY_BIT_UNPACK_BUFFER_BINDING: |
| 584 | WARN() << "DIRTY_BIT_UNPACK_BUFFER_BINDING unimplemented"; |
| 585 | break; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 586 | case gl::State::DIRTY_BIT_PACK_STATE: |
| 587 | WARN() << "DIRTY_BIT_PACK_STATE unimplemented"; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 588 | break; |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 589 | case gl::State::DIRTY_BIT_PACK_BUFFER_BINDING: |
| 590 | WARN() << "DIRTY_BIT_PACK_BUFFER_BINDING unimplemented"; |
| 591 | break; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 592 | case gl::State::DIRTY_BIT_DITHER_ENABLED: |
| 593 | WARN() << "DIRTY_BIT_DITHER_ENABLED unimplemented"; |
| 594 | break; |
| 595 | case gl::State::DIRTY_BIT_GENERATE_MIPMAP_HINT: |
| 596 | WARN() << "DIRTY_BIT_GENERATE_MIPMAP_HINT unimplemented"; |
| 597 | break; |
| 598 | case gl::State::DIRTY_BIT_SHADER_DERIVATIVE_HINT: |
| 599 | WARN() << "DIRTY_BIT_SHADER_DERIVATIVE_HINT unimplemented"; |
| 600 | break; |
| 601 | case gl::State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING: |
| 602 | WARN() << "DIRTY_BIT_READ_FRAMEBUFFER_BINDING unimplemented"; |
| 603 | break; |
| 604 | case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING: |
| 605 | WARN() << "DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING unimplemented"; |
| 606 | break; |
| 607 | case gl::State::DIRTY_BIT_RENDERBUFFER_BINDING: |
| 608 | WARN() << "DIRTY_BIT_RENDERBUFFER_BINDING unimplemented"; |
| 609 | break; |
| 610 | case gl::State::DIRTY_BIT_VERTEX_ARRAY_BINDING: |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 611 | mVertexArrayDirty = true; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 612 | break; |
| 613 | case gl::State::DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING: |
| 614 | WARN() << "DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING unimplemented"; |
| 615 | break; |
Qin Jiajia | a98a281 | 2017-11-30 18:12:06 +0800 | [diff] [blame] | 616 | case gl::State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING: |
| 617 | WARN() << "DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING unimplemented"; |
| 618 | break; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 619 | case gl::State::DIRTY_BIT_PROGRAM_BINDING: |
| 620 | WARN() << "DIRTY_BIT_PROGRAM_BINDING unimplemented"; |
| 621 | break; |
| 622 | case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE: |
| 623 | { |
Jamie Madill | f2f6d37 | 2018-01-10 21:37:23 -0500 | [diff] [blame] | 624 | ProgramVk *programVk = vk::GetImpl(glState.getProgram()); |
| 625 | mPipelineDesc->updateShaders(programVk); |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 626 | dirtyTextures = true; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 627 | break; |
| 628 | } |
| 629 | case gl::State::DIRTY_BIT_TEXTURE_BINDINGS: |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 630 | dirtyTextures = true; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 631 | break; |
| 632 | case gl::State::DIRTY_BIT_SAMPLER_BINDINGS: |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 633 | dirtyTextures = true; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 634 | break; |
Geoff Lang | ded7923 | 2017-11-28 15:21:11 -0500 | [diff] [blame] | 635 | case gl::State::DIRTY_BIT_TRANSFORM_FEEDBACK_BINDING: |
| 636 | WARN() << "DIRTY_BIT_TRANSFORM_FEEDBACK_BINDING unimplemented"; |
| 637 | break; |
Xinghua Cao | 10a4d43 | 2017-11-28 14:46:26 +0800 | [diff] [blame] | 638 | case gl::State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING: |
| 639 | WARN() << "DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING unimplemented"; |
| 640 | break; |
Jamie Madill | f414121 | 2017-12-12 15:08:07 -0500 | [diff] [blame] | 641 | case gl::State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS: |
| 642 | WARN() << "DIRTY_BIT_UNIFORM_BUFFER_BINDINGS unimplemented"; |
| 643 | break; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 644 | case gl::State::DIRTY_BIT_MULTISAMPLING: |
| 645 | WARN() << "DIRTY_BIT_MULTISAMPLING unimplemented"; |
| 646 | break; |
| 647 | case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_ONE: |
| 648 | WARN() << "DIRTY_BIT_SAMPLE_ALPHA_TO_ONE unimplemented"; |
| 649 | break; |
| 650 | case gl::State::DIRTY_BIT_COVERAGE_MODULATION: |
| 651 | WARN() << "DIRTY_BIT_COVERAGE_MODULATION unimplemented"; |
| 652 | break; |
| 653 | case gl::State::DIRTY_BIT_PATH_RENDERING_MATRIX_MV: |
| 654 | WARN() << "DIRTY_BIT_PATH_RENDERING_MATRIX_MV unimplemented"; |
| 655 | break; |
| 656 | case gl::State::DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ: |
| 657 | WARN() << "DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ unimplemented"; |
| 658 | break; |
| 659 | case gl::State::DIRTY_BIT_PATH_RENDERING_STENCIL_STATE: |
| 660 | WARN() << "DIRTY_BIT_PATH_RENDERING_STENCIL_STATE unimplemented"; |
| 661 | break; |
| 662 | case gl::State::DIRTY_BIT_FRAMEBUFFER_SRGB: |
| 663 | WARN() << "DIRTY_BIT_FRAMEBUFFER_SRGB unimplemented"; |
| 664 | break; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 665 | case gl::State::DIRTY_BIT_CURRENT_VALUES: |
| 666 | WARN() << "DIRTY_BIT_CURRENT_VALUES unimplemented"; |
| 667 | break; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 668 | default: |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 669 | UNREACHABLE(); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 670 | break; |
| 671 | } |
| 672 | } |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 673 | |
| 674 | if (dirtyTextures) |
| 675 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 676 | ProgramVk *programVk = vk::GetImpl(glState.getProgram()); |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 677 | programVk->invalidateTextures(); |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 678 | mTexturesDirty = true; |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 679 | } |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | GLint ContextVk::getGPUDisjoint() |
| 683 | { |
| 684 | UNIMPLEMENTED(); |
| 685 | return GLint(); |
| 686 | } |
| 687 | |
| 688 | GLint64 ContextVk::getTimestamp() |
| 689 | { |
| 690 | UNIMPLEMENTED(); |
| 691 | return GLint64(); |
| 692 | } |
| 693 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 694 | void ContextVk::onMakeCurrent(const gl::Context * /*context*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 695 | { |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | const gl::Caps &ContextVk::getNativeCaps() const |
| 699 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 700 | return mRenderer->getNativeCaps(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | const gl::TextureCapsMap &ContextVk::getNativeTextureCaps() const |
| 704 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 705 | return mRenderer->getNativeTextureCaps(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | const gl::Extensions &ContextVk::getNativeExtensions() const |
| 709 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 710 | return mRenderer->getNativeExtensions(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | const gl::Limitations &ContextVk::getNativeLimitations() const |
| 714 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 715 | return mRenderer->getNativeLimitations(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | CompilerImpl *ContextVk::createCompiler() |
| 719 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 720 | return new CompilerVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 721 | } |
| 722 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 723 | ShaderImpl *ContextVk::createShader(const gl::ShaderState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 724 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 725 | return new ShaderVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 726 | } |
| 727 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 728 | ProgramImpl *ContextVk::createProgram(const gl::ProgramState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 729 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 730 | return new ProgramVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 731 | } |
| 732 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 733 | FramebufferImpl *ContextVk::createFramebuffer(const gl::FramebufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 734 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 735 | return FramebufferVk::CreateUserFBO(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | TextureImpl *ContextVk::createTexture(const gl::TextureState &state) |
| 739 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 740 | return new TextureVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 741 | } |
| 742 | |
Jamie Madill | e703c60 | 2018-02-20 10:21:48 -0500 | [diff] [blame] | 743 | RenderbufferImpl *ContextVk::createRenderbuffer(const gl::RenderbufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 744 | { |
Jamie Madill | e703c60 | 2018-02-20 10:21:48 -0500 | [diff] [blame] | 745 | return new RenderbufferVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 746 | } |
| 747 | |
Jamie Madill | 8f77560 | 2016-11-03 16:45:34 -0400 | [diff] [blame] | 748 | BufferImpl *ContextVk::createBuffer(const gl::BufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 749 | { |
Jamie Madill | 8f77560 | 2016-11-03 16:45:34 -0400 | [diff] [blame] | 750 | return new BufferVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 751 | } |
| 752 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 753 | VertexArrayImpl *ContextVk::createVertexArray(const gl::VertexArrayState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 754 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 755 | return new VertexArrayVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | QueryImpl *ContextVk::createQuery(GLenum type) |
| 759 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 760 | return new QueryVk(type); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | FenceNVImpl *ContextVk::createFenceNV() |
| 764 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 765 | return new FenceNVVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 766 | } |
| 767 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 768 | SyncImpl *ContextVk::createSync() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 769 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 770 | return new SyncVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 771 | } |
| 772 | |
Geoff Lang | 73bd218 | 2016-07-15 13:01:24 -0400 | [diff] [blame] | 773 | TransformFeedbackImpl *ContextVk::createTransformFeedback(const gl::TransformFeedbackState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 774 | { |
Geoff Lang | 73bd218 | 2016-07-15 13:01:24 -0400 | [diff] [blame] | 775 | return new TransformFeedbackVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 776 | } |
| 777 | |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 778 | SamplerImpl *ContextVk::createSampler(const gl::SamplerState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 779 | { |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 780 | return new SamplerVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 781 | } |
| 782 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 783 | ProgramPipelineImpl *ContextVk::createProgramPipeline(const gl::ProgramPipelineState &state) |
| 784 | { |
| 785 | return new ProgramPipelineVk(state); |
| 786 | } |
| 787 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 788 | std::vector<PathImpl *> ContextVk::createPaths(GLsizei) |
| 789 | { |
| 790 | return std::vector<PathImpl *>(); |
| 791 | } |
| 792 | |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 793 | void ContextVk::invalidateCurrentPipeline() |
| 794 | { |
Jamie Madill | ffa4cbb | 2018-01-23 13:04:07 -0500 | [diff] [blame] | 795 | mCurrentPipeline = nullptr; |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 796 | } |
| 797 | |
Jamie Madill | 49ac74b | 2017-12-21 14:42:33 -0500 | [diff] [blame] | 798 | void ContextVk::onVertexArrayChange() |
| 799 | { |
| 800 | // TODO(jmadill): Does not handle dependent state changes. |
| 801 | mVertexArrayDirty = true; |
| 802 | invalidateCurrentPipeline(); |
| 803 | } |
| 804 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 805 | gl::Error ContextVk::dispatchCompute(const gl::Context *context, |
| 806 | GLuint numGroupsX, |
| 807 | GLuint numGroupsY, |
| 808 | GLuint numGroupsZ) |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 809 | { |
| 810 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 811 | return gl::InternalError(); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 812 | } |
| 813 | |
Qin Jiajia | 62fcf62 | 2017-11-30 16:16:12 +0800 | [diff] [blame] | 814 | gl::Error ContextVk::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect) |
| 815 | { |
| 816 | UNIMPLEMENTED(); |
| 817 | return gl::InternalError(); |
| 818 | } |
| 819 | |
Xinghua Cao | 89c422a | 2017-11-29 18:24:20 +0800 | [diff] [blame] | 820 | gl::Error ContextVk::memoryBarrier(const gl::Context *context, GLbitfield barriers) |
| 821 | { |
| 822 | UNIMPLEMENTED(); |
| 823 | return gl::InternalError(); |
| 824 | } |
| 825 | |
| 826 | gl::Error ContextVk::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) |
| 827 | { |
| 828 | UNIMPLEMENTED(); |
| 829 | return gl::InternalError(); |
| 830 | } |
| 831 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 832 | vk::DescriptorPool *ContextVk::getDescriptorPool() |
| 833 | { |
| 834 | return &mDescriptorPool; |
| 835 | } |
| 836 | |
Jamie Madill | f4d693c | 2018-02-14 16:38:16 -0500 | [diff] [blame] | 837 | const VkClearValue &ContextVk::getClearColorValue() const |
| 838 | { |
| 839 | return mClearColorValue; |
| 840 | } |
| 841 | |
| 842 | const VkClearValue &ContextVk::getClearDepthStencilValue() const |
| 843 | { |
| 844 | return mClearDepthStencilValue; |
| 845 | } |
| 846 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 847 | } // namespace rx |