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 | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 14 | #include "libANGLE/Program.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 15 | #include "libANGLE/renderer/vulkan/BufferVk.h" |
| 16 | #include "libANGLE/renderer/vulkan/CompilerVk.h" |
| 17 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
| 18 | #include "libANGLE/renderer/vulkan/DeviceVk.h" |
| 19 | #include "libANGLE/renderer/vulkan/FenceNVVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 20 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
| 21 | #include "libANGLE/renderer/vulkan/ImageVk.h" |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 22 | #include "libANGLE/renderer/vulkan/ProgramPipelineVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 23 | #include "libANGLE/renderer/vulkan/ProgramVk.h" |
| 24 | #include "libANGLE/renderer/vulkan/QueryVk.h" |
| 25 | #include "libANGLE/renderer/vulkan/RenderbufferVk.h" |
| 26 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
| 27 | #include "libANGLE/renderer/vulkan/SamplerVk.h" |
| 28 | #include "libANGLE/renderer/vulkan/ShaderVk.h" |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 29 | #include "libANGLE/renderer/vulkan/SyncVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 30 | #include "libANGLE/renderer/vulkan/TextureVk.h" |
| 31 | #include "libANGLE/renderer/vulkan/TransformFeedbackVk.h" |
| 32 | #include "libANGLE/renderer/vulkan/VertexArrayVk.h" |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 33 | #include "libANGLE/renderer/vulkan/formatutilsvk.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 34 | |
| 35 | namespace rx |
| 36 | { |
| 37 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 38 | ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer) |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 39 | : ContextImpl(state), mRenderer(renderer), mCurrentDrawMode(GL_NONE) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | ContextVk::~ContextVk() |
| 44 | { |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 45 | invalidateCurrentPipeline(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | gl::Error ContextVk::initialize() |
| 49 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 50 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | gl::Error ContextVk::flush() |
| 54 | { |
| 55 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 56 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | gl::Error ContextVk::finish() |
| 60 | { |
| 61 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 62 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 63 | } |
| 64 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 65 | gl::Error ContextVk::initPipeline(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 66 | { |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 67 | ASSERT(!mCurrentPipeline.valid()); |
| 68 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 69 | VkDevice device = mRenderer->getDevice(); |
| 70 | const auto &state = mState.getState(); |
| 71 | const auto &programGL = state.getProgram(); |
| 72 | const auto &vao = state.getVertexArray(); |
| 73 | const auto &attribs = vao->getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 74 | const auto &bindings = vao->getVertexBindings(); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 75 | const auto &programVk = GetImplAs<ProgramVk>(programGL); |
| 76 | const auto *drawFBO = state.getDrawFramebuffer(); |
| 77 | FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO); |
| 78 | |
| 79 | // { vertex, fragment } |
| 80 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 81 | |
| 82 | shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 83 | shaderStages[0].pNext = nullptr; |
| 84 | shaderStages[0].flags = 0; |
| 85 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
| 86 | shaderStages[0].module = programVk->getLinkedVertexModule().getHandle(); |
| 87 | shaderStages[0].pName = "main"; |
| 88 | shaderStages[0].pSpecializationInfo = nullptr; |
| 89 | |
| 90 | shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 91 | shaderStages[1].pNext = nullptr; |
| 92 | shaderStages[1].flags = 0; |
| 93 | shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 94 | shaderStages[1].module = programVk->getLinkedFragmentModule().getHandle(); |
| 95 | shaderStages[1].pName = "main"; |
| 96 | shaderStages[1].pSpecializationInfo = nullptr; |
| 97 | |
| 98 | // Process vertex attributes |
| 99 | // TODO(jmadill): Caching with dirty bits. |
| 100 | std::vector<VkVertexInputBindingDescription> vertexBindings; |
| 101 | std::vector<VkVertexInputAttributeDescription> vertexAttribs; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 102 | |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 103 | for (auto attribIndex : programGL->getActiveAttribLocationsMask()) |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 104 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 105 | const auto &attrib = attribs[attribIndex]; |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 106 | const auto &binding = bindings[attrib.bindingIndex]; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 107 | if (attrib.enabled) |
| 108 | { |
| 109 | VkVertexInputBindingDescription bindingDesc; |
| 110 | bindingDesc.binding = static_cast<uint32_t>(vertexBindings.size()); |
| 111 | bindingDesc.stride = static_cast<uint32_t>(gl::ComputeVertexAttributeTypeSize(attrib)); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 112 | bindingDesc.inputRate = (binding.getDivisor() > 0 ? VK_VERTEX_INPUT_RATE_INSTANCE |
| 113 | : VK_VERTEX_INPUT_RATE_VERTEX); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 114 | |
| 115 | gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib); |
| 116 | |
| 117 | VkVertexInputAttributeDescription attribDesc; |
| 118 | attribDesc.binding = bindingDesc.binding; |
| 119 | attribDesc.format = vk::GetNativeVertexFormat(vertexFormatType); |
| 120 | attribDesc.location = static_cast<uint32_t>(attribIndex); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 121 | attribDesc.offset = |
| 122 | static_cast<uint32_t>(ComputeVertexAttributeOffset(attrib, binding)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 123 | |
| 124 | vertexBindings.push_back(bindingDesc); |
| 125 | vertexAttribs.push_back(attribDesc); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 126 | } |
| 127 | else |
| 128 | { |
| 129 | UNIMPLEMENTED(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // TODO(jmadill): Validate with ASSERT against physical device limits/caps? |
| 134 | VkPipelineVertexInputStateCreateInfo vertexInputState; |
| 135 | vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 136 | vertexInputState.pNext = nullptr; |
| 137 | vertexInputState.flags = 0; |
| 138 | vertexInputState.vertexBindingDescriptionCount = static_cast<uint32_t>(vertexBindings.size()); |
| 139 | vertexInputState.pVertexBindingDescriptions = vertexBindings.data(); |
| 140 | vertexInputState.vertexAttributeDescriptionCount = static_cast<uint32_t>(vertexAttribs.size()); |
| 141 | vertexInputState.pVertexAttributeDescriptions = vertexAttribs.data(); |
| 142 | |
| 143 | VkPipelineInputAssemblyStateCreateInfo inputAssemblyState; |
| 144 | inputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 145 | inputAssemblyState.pNext = nullptr; |
| 146 | inputAssemblyState.flags = 0; |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 147 | inputAssemblyState.topology = gl_vk::GetPrimitiveTopology(mCurrentDrawMode); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 148 | inputAssemblyState.primitiveRestartEnable = VK_FALSE; |
| 149 | |
| 150 | const gl::Rectangle &viewportGL = state.getViewport(); |
| 151 | VkViewport viewportVk; |
| 152 | viewportVk.x = static_cast<float>(viewportGL.x); |
| 153 | viewportVk.y = static_cast<float>(viewportGL.y); |
| 154 | viewportVk.width = static_cast<float>(viewportGL.width); |
| 155 | viewportVk.height = static_cast<float>(viewportGL.height); |
| 156 | viewportVk.minDepth = state.getNearPlane(); |
| 157 | viewportVk.maxDepth = state.getFarPlane(); |
| 158 | |
| 159 | // TODO(jmadill): Scissor. |
| 160 | VkRect2D scissorVk; |
| 161 | scissorVk.offset.x = viewportGL.x; |
| 162 | scissorVk.offset.y = viewportGL.y; |
| 163 | scissorVk.extent.width = viewportGL.width; |
| 164 | scissorVk.extent.height = viewportGL.height; |
| 165 | |
| 166 | VkPipelineViewportStateCreateInfo viewportState; |
| 167 | viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 168 | viewportState.pNext = nullptr; |
| 169 | viewportState.flags = 0; |
| 170 | viewportState.viewportCount = 1; |
| 171 | viewportState.pViewports = &viewportVk; |
| 172 | viewportState.scissorCount = 1; |
| 173 | viewportState.pScissors = &scissorVk; |
| 174 | |
| 175 | // TODO(jmadill): Extra rasterizer state features. |
| 176 | VkPipelineRasterizationStateCreateInfo rasterState; |
| 177 | rasterState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 178 | rasterState.pNext = nullptr; |
| 179 | rasterState.flags = 0; |
| 180 | rasterState.depthClampEnable = VK_FALSE; |
| 181 | rasterState.rasterizerDiscardEnable = VK_FALSE; |
| 182 | rasterState.polygonMode = VK_POLYGON_MODE_FILL; |
| 183 | rasterState.cullMode = gl_vk::GetCullMode(state.getRasterizerState()); |
| 184 | rasterState.frontFace = gl_vk::GetFrontFace(state.getRasterizerState().frontFace); |
| 185 | rasterState.depthBiasEnable = VK_FALSE; |
| 186 | rasterState.depthBiasConstantFactor = 0.0f; |
| 187 | rasterState.depthBiasClamp = 0.0f; |
| 188 | rasterState.depthBiasSlopeFactor = 0.0f; |
| 189 | rasterState.lineWidth = state.getLineWidth(); |
| 190 | |
| 191 | // TODO(jmadill): Multisample state. |
| 192 | VkPipelineMultisampleStateCreateInfo multisampleState; |
| 193 | multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 194 | multisampleState.pNext = nullptr; |
| 195 | multisampleState.flags = 0; |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 196 | multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 197 | multisampleState.sampleShadingEnable = VK_FALSE; |
| 198 | multisampleState.minSampleShading = 0.0f; |
| 199 | multisampleState.pSampleMask = nullptr; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 200 | multisampleState.alphaToCoverageEnable = VK_FALSE; |
| 201 | multisampleState.alphaToOneEnable = VK_FALSE; |
| 202 | |
| 203 | // TODO(jmadill): Depth/stencil state. |
| 204 | |
| 205 | // TODO(jmadill): Blend state/MRT. |
| 206 | VkPipelineColorBlendAttachmentState blendAttachmentState; |
| 207 | blendAttachmentState.blendEnable = VK_FALSE; |
| 208 | blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_ONE; |
| 209 | blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE; |
| 210 | blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD; |
| 211 | blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; |
| 212 | blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE; |
| 213 | blendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD; |
| 214 | blendAttachmentState.colorWriteMask = (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | |
| 215 | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT); |
| 216 | |
| 217 | VkPipelineColorBlendStateCreateInfo blendState; |
| 218 | blendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 219 | blendState.pNext = 0; |
| 220 | blendState.flags = 0; |
| 221 | blendState.logicOpEnable = VK_FALSE; |
| 222 | blendState.logicOp = VK_LOGIC_OP_CLEAR; |
| 223 | blendState.attachmentCount = 1; |
| 224 | blendState.pAttachments = &blendAttachmentState; |
| 225 | blendState.blendConstants[0] = 0.0f; |
| 226 | blendState.blendConstants[1] = 0.0f; |
| 227 | blendState.blendConstants[2] = 0.0f; |
| 228 | blendState.blendConstants[3] = 0.0f; |
| 229 | |
| 230 | // TODO(jmadill): Dynamic state. |
| 231 | vk::RenderPass *renderPass = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 232 | ANGLE_TRY_RESULT(vkFBO->getRenderPass(context, device), renderPass); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 233 | ASSERT(renderPass && renderPass->valid()); |
| 234 | |
| 235 | vk::PipelineLayout *pipelineLayout = nullptr; |
| 236 | ANGLE_TRY_RESULT(programVk->getPipelineLayout(device), pipelineLayout); |
| 237 | ASSERT(pipelineLayout && pipelineLayout->valid()); |
| 238 | |
| 239 | VkGraphicsPipelineCreateInfo pipelineInfo; |
| 240 | pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 241 | pipelineInfo.pNext = nullptr; |
| 242 | pipelineInfo.flags = 0; |
| 243 | pipelineInfo.stageCount = 2; |
| 244 | pipelineInfo.pStages = shaderStages; |
| 245 | pipelineInfo.pVertexInputState = &vertexInputState; |
| 246 | pipelineInfo.pInputAssemblyState = &inputAssemblyState; |
| 247 | pipelineInfo.pTessellationState = nullptr; |
| 248 | pipelineInfo.pViewportState = &viewportState; |
| 249 | pipelineInfo.pRasterizationState = &rasterState; |
| 250 | pipelineInfo.pMultisampleState = &multisampleState; |
| 251 | pipelineInfo.pDepthStencilState = nullptr; |
| 252 | pipelineInfo.pColorBlendState = &blendState; |
| 253 | pipelineInfo.pDynamicState = nullptr; |
| 254 | pipelineInfo.layout = pipelineLayout->getHandle(); |
| 255 | pipelineInfo.renderPass = renderPass->getHandle(); |
| 256 | pipelineInfo.subpass = 0; |
| 257 | pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; |
| 258 | pipelineInfo.basePipelineIndex = 0; |
| 259 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 260 | vk::Pipeline newPipeline; |
| 261 | ANGLE_TRY(newPipeline.initGraphics(device, pipelineInfo)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 262 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 263 | mCurrentPipeline.retain(device, std::move(newPipeline)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 264 | |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 265 | return gl::NoError(); |
| 266 | } |
| 267 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 268 | gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count) |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 269 | { |
| 270 | if (mode != mCurrentDrawMode) |
| 271 | { |
| 272 | invalidateCurrentPipeline(); |
| 273 | mCurrentDrawMode = mode; |
| 274 | } |
| 275 | |
| 276 | if (!mCurrentPipeline.valid()) |
| 277 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 278 | ANGLE_TRY(initPipeline(context)); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 279 | ASSERT(mCurrentPipeline.valid()); |
| 280 | } |
| 281 | |
| 282 | VkDevice device = mRenderer->getDevice(); |
| 283 | const auto &state = mState.getState(); |
| 284 | const auto &programGL = state.getProgram(); |
| 285 | const auto &vao = state.getVertexArray(); |
| 286 | const auto &attribs = vao->getVertexAttributes(); |
| 287 | const auto &bindings = vao->getVertexBindings(); |
| 288 | const auto *drawFBO = state.getDrawFramebuffer(); |
| 289 | FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO); |
| 290 | Serial queueSerial = mRenderer->getCurrentQueueSerial(); |
| 291 | |
| 292 | // Process vertex attributes |
| 293 | // TODO(jmadill): Caching with dirty bits. |
| 294 | std::vector<VkBuffer> vertexHandles; |
| 295 | std::vector<VkDeviceSize> vertexOffsets; |
| 296 | |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 297 | for (auto attribIndex : programGL->getActiveAttribLocationsMask()) |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 298 | { |
| 299 | const auto &attrib = attribs[attribIndex]; |
| 300 | const auto &binding = bindings[attrib.bindingIndex]; |
| 301 | if (attrib.enabled) |
| 302 | { |
| 303 | // TODO(jmadill): Offset handling. |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 304 | gl::Buffer *bufferGL = binding.getBuffer().get(); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 305 | ASSERT(bufferGL); |
| 306 | BufferVk *bufferVk = GetImplAs<BufferVk>(bufferGL); |
| 307 | vertexHandles.push_back(bufferVk->getVkBuffer().getHandle()); |
| 308 | vertexOffsets.push_back(0); |
| 309 | |
| 310 | bufferVk->setQueueSerial(queueSerial); |
| 311 | } |
| 312 | else |
| 313 | { |
| 314 | UNIMPLEMENTED(); |
| 315 | } |
| 316 | } |
| 317 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 318 | vk::CommandBuffer *commandBuffer = nullptr; |
| 319 | ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer)); |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 320 | ANGLE_TRY(vkFBO->ensureInRenderPass(context, device, commandBuffer, queueSerial, state)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 321 | |
| 322 | commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline); |
Jamie Madill | abd3135 | 2017-09-19 00:24:58 -0400 | [diff] [blame] | 323 | // TODO(jmadill): the queue serial should be bound to the pipeline. |
| 324 | setQueueSerial(queueSerial); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 325 | commandBuffer->bindVertexBuffers(0, vertexHandles, vertexOffsets); |
| 326 | commandBuffer->draw(count, 1, first, 0); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 327 | |
| 328 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 329 | } |
| 330 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 331 | gl::Error ContextVk::drawArraysInstanced(const gl::Context *context, |
| 332 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 333 | GLint first, |
| 334 | GLsizei count, |
| 335 | GLsizei instanceCount) |
| 336 | { |
| 337 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 338 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 339 | } |
| 340 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 341 | gl::Error ContextVk::drawElements(const gl::Context *context, |
| 342 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 343 | GLsizei count, |
| 344 | GLenum type, |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 345 | const void *indices) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 346 | { |
| 347 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 348 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 349 | } |
| 350 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 351 | gl::Error ContextVk::drawElementsInstanced(const gl::Context *context, |
| 352 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 353 | GLsizei count, |
| 354 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 355 | const void *indices, |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 356 | GLsizei instances) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 357 | { |
| 358 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 359 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 360 | } |
| 361 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 362 | gl::Error ContextVk::drawRangeElements(const gl::Context *context, |
| 363 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 364 | GLuint start, |
| 365 | GLuint end, |
| 366 | GLsizei count, |
| 367 | GLenum type, |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 368 | const void *indices) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 369 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 370 | return gl::NoError(); |
| 371 | } |
| 372 | |
| 373 | VkDevice ContextVk::getDevice() const |
| 374 | { |
| 375 | return mRenderer->getDevice(); |
| 376 | } |
| 377 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 378 | vk::Error ContextVk::getStartedCommandBuffer(vk::CommandBuffer **commandBufferOut) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 379 | { |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 380 | return mRenderer->getStartedCommandBuffer(commandBufferOut); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 381 | } |
| 382 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 383 | vk::Error ContextVk::submitCommands(vk::CommandBuffer *commandBuffer) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 384 | { |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 385 | setQueueSerial(mRenderer->getCurrentQueueSerial()); |
Jamie Madill | f651c77 | 2017-02-21 15:03:51 -0500 | [diff] [blame] | 386 | ANGLE_TRY(mRenderer->submitCommandBuffer(commandBuffer)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 387 | return vk::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 388 | } |
| 389 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 390 | gl::Error ContextVk::drawArraysIndirect(const gl::Context *context, |
| 391 | GLenum mode, |
| 392 | const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 393 | { |
| 394 | UNIMPLEMENTED(); |
| 395 | return gl::InternalError() << "DrawArraysIndirect hasn't been implemented for vulkan backend."; |
| 396 | } |
| 397 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 398 | gl::Error ContextVk::drawElementsIndirect(const gl::Context *context, |
| 399 | GLenum mode, |
| 400 | GLenum type, |
| 401 | const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 402 | { |
| 403 | UNIMPLEMENTED(); |
| 404 | return gl::InternalError() |
| 405 | << "DrawElementsIndirect hasn't been implemented for vulkan backend."; |
| 406 | } |
| 407 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 408 | GLenum ContextVk::getResetStatus() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 409 | { |
| 410 | UNIMPLEMENTED(); |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 411 | return GL_NO_ERROR; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | std::string ContextVk::getVendorString() const |
| 415 | { |
| 416 | UNIMPLEMENTED(); |
| 417 | return std::string(); |
| 418 | } |
| 419 | |
| 420 | std::string ContextVk::getRendererDescription() const |
| 421 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 422 | return mRenderer->getRendererDescription(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | void ContextVk::insertEventMarker(GLsizei length, const char *marker) |
| 426 | { |
| 427 | UNIMPLEMENTED(); |
| 428 | } |
| 429 | |
| 430 | void ContextVk::pushGroupMarker(GLsizei length, const char *marker) |
| 431 | { |
| 432 | UNIMPLEMENTED(); |
| 433 | } |
| 434 | |
| 435 | void ContextVk::popGroupMarker() |
| 436 | { |
| 437 | UNIMPLEMENTED(); |
| 438 | } |
| 439 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 440 | void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 441 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 442 | // TODO(jmadill): Vulkan dirty bits. |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 443 | if (dirtyBits.any()) |
| 444 | { |
| 445 | invalidateCurrentPipeline(); |
| 446 | } |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | GLint ContextVk::getGPUDisjoint() |
| 450 | { |
| 451 | UNIMPLEMENTED(); |
| 452 | return GLint(); |
| 453 | } |
| 454 | |
| 455 | GLint64 ContextVk::getTimestamp() |
| 456 | { |
| 457 | UNIMPLEMENTED(); |
| 458 | return GLint64(); |
| 459 | } |
| 460 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 461 | void ContextVk::onMakeCurrent(const gl::Context * /*context*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 462 | { |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | const gl::Caps &ContextVk::getNativeCaps() const |
| 466 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 467 | return mRenderer->getNativeCaps(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | const gl::TextureCapsMap &ContextVk::getNativeTextureCaps() const |
| 471 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 472 | return mRenderer->getNativeTextureCaps(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | const gl::Extensions &ContextVk::getNativeExtensions() const |
| 476 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 477 | return mRenderer->getNativeExtensions(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | const gl::Limitations &ContextVk::getNativeLimitations() const |
| 481 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 482 | return mRenderer->getNativeLimitations(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | CompilerImpl *ContextVk::createCompiler() |
| 486 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 487 | return new CompilerVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 488 | } |
| 489 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 490 | ShaderImpl *ContextVk::createShader(const gl::ShaderState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 491 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 492 | return new ShaderVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 495 | ProgramImpl *ContextVk::createProgram(const gl::ProgramState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 496 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 497 | return new ProgramVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 498 | } |
| 499 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 500 | FramebufferImpl *ContextVk::createFramebuffer(const gl::FramebufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 501 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 502 | return FramebufferVk::CreateUserFBO(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | TextureImpl *ContextVk::createTexture(const gl::TextureState &state) |
| 506 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 507 | return new TextureVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | RenderbufferImpl *ContextVk::createRenderbuffer() |
| 511 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 512 | return new RenderbufferVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 513 | } |
| 514 | |
Jamie Madill | 8f77560 | 2016-11-03 16:45:34 -0400 | [diff] [blame] | 515 | BufferImpl *ContextVk::createBuffer(const gl::BufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 516 | { |
Jamie Madill | 8f77560 | 2016-11-03 16:45:34 -0400 | [diff] [blame] | 517 | return new BufferVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 518 | } |
| 519 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 520 | VertexArrayImpl *ContextVk::createVertexArray(const gl::VertexArrayState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 521 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 522 | return new VertexArrayVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | QueryImpl *ContextVk::createQuery(GLenum type) |
| 526 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 527 | return new QueryVk(type); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | FenceNVImpl *ContextVk::createFenceNV() |
| 531 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 532 | return new FenceNVVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 533 | } |
| 534 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 535 | SyncImpl *ContextVk::createSync() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 536 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 537 | return new SyncVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 538 | } |
| 539 | |
Geoff Lang | 73bd218 | 2016-07-15 13:01:24 -0400 | [diff] [blame] | 540 | TransformFeedbackImpl *ContextVk::createTransformFeedback(const gl::TransformFeedbackState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 541 | { |
Geoff Lang | 73bd218 | 2016-07-15 13:01:24 -0400 | [diff] [blame] | 542 | return new TransformFeedbackVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 543 | } |
| 544 | |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 545 | SamplerImpl *ContextVk::createSampler(const gl::SamplerState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 546 | { |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 547 | return new SamplerVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 548 | } |
| 549 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 550 | ProgramPipelineImpl *ContextVk::createProgramPipeline(const gl::ProgramPipelineState &state) |
| 551 | { |
| 552 | return new ProgramPipelineVk(state); |
| 553 | } |
| 554 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 555 | std::vector<PathImpl *> ContextVk::createPaths(GLsizei) |
| 556 | { |
| 557 | return std::vector<PathImpl *>(); |
| 558 | } |
| 559 | |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 560 | // TODO(jmadill): Use pipeline cache. |
| 561 | void ContextVk::invalidateCurrentPipeline() |
| 562 | { |
| 563 | mRenderer->enqueueGarbageOrDeleteNow(*this, mCurrentPipeline); |
| 564 | } |
| 565 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 566 | gl::Error ContextVk::dispatchCompute(const gl::Context *context, |
| 567 | GLuint numGroupsX, |
| 568 | GLuint numGroupsY, |
| 569 | GLuint numGroupsZ) |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 570 | { |
| 571 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 572 | return gl::InternalError(); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 573 | } |
| 574 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 575 | } // namespace rx |