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" |
| 17 | #include "libANGLE/renderer/vulkan/CompilerVk.h" |
| 18 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
| 19 | #include "libANGLE/renderer/vulkan/DeviceVk.h" |
| 20 | #include "libANGLE/renderer/vulkan/FenceNVVk.h" |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 21 | #include "libANGLE/renderer/vulkan/FramebufferVk.h" |
| 22 | #include "libANGLE/renderer/vulkan/ImageVk.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 | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 34 | #include "libANGLE/renderer/vulkan/formatutilsvk.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 35 | |
| 36 | namespace rx |
| 37 | { |
| 38 | |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 39 | namespace |
| 40 | { |
| 41 | |
| 42 | VkIndexType GetVkIndexType(GLenum glIndexType) |
| 43 | { |
| 44 | switch (glIndexType) |
| 45 | { |
| 46 | case GL_UNSIGNED_SHORT: |
| 47 | return VK_INDEX_TYPE_UINT16; |
| 48 | case GL_UNSIGNED_INT: |
| 49 | return VK_INDEX_TYPE_UINT32; |
| 50 | default: |
| 51 | UNREACHABLE(); |
| 52 | return VK_INDEX_TYPE_MAX_ENUM; |
| 53 | } |
| 54 | } |
| 55 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 56 | enum DescriptorPoolIndex : uint8_t |
| 57 | { |
| 58 | UniformBufferPool = 0, |
| 59 | TexturePool = 1, |
| 60 | }; |
| 61 | |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 62 | } // anonymous namespace |
| 63 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 64 | ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer) |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 65 | : ContextImpl(state), mRenderer(renderer), mCurrentDrawMode(GL_NONE) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 66 | { |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 67 | // The module handle is filled out at draw time. |
| 68 | mCurrentShaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 69 | mCurrentShaderStages[0].pNext = nullptr; |
| 70 | mCurrentShaderStages[0].flags = 0; |
| 71 | mCurrentShaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
| 72 | mCurrentShaderStages[0].module = VK_NULL_HANDLE; |
| 73 | mCurrentShaderStages[0].pName = "main"; |
| 74 | mCurrentShaderStages[0].pSpecializationInfo = nullptr; |
| 75 | |
| 76 | mCurrentShaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 77 | mCurrentShaderStages[1].pNext = nullptr; |
| 78 | mCurrentShaderStages[1].flags = 0; |
| 79 | mCurrentShaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 80 | mCurrentShaderStages[1].module = VK_NULL_HANDLE; |
| 81 | mCurrentShaderStages[1].pName = "main"; |
| 82 | mCurrentShaderStages[1].pSpecializationInfo = nullptr; |
| 83 | |
| 84 | // The binding descriptions are filled in at draw time. |
| 85 | mCurrentVertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 86 | mCurrentVertexInputState.pNext = nullptr; |
| 87 | mCurrentVertexInputState.flags = 0; |
| 88 | mCurrentVertexInputState.vertexBindingDescriptionCount = 0; |
| 89 | mCurrentVertexInputState.pVertexBindingDescriptions = nullptr; |
| 90 | mCurrentVertexInputState.vertexAttributeDescriptionCount = 0; |
| 91 | mCurrentVertexInputState.pVertexAttributeDescriptions = nullptr; |
| 92 | |
| 93 | // Primitive topology is filled in at draw time. |
| 94 | mCurrentInputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 95 | mCurrentInputAssemblyState.pNext = nullptr; |
| 96 | mCurrentInputAssemblyState.flags = 0; |
| 97 | mCurrentInputAssemblyState.topology = gl_vk::GetPrimitiveTopology(mCurrentDrawMode); |
| 98 | mCurrentInputAssemblyState.primitiveRestartEnable = VK_FALSE; |
| 99 | |
| 100 | // Set initial viewport and scissor state. |
| 101 | mCurrentViewportVk.x = 0.0f; |
| 102 | mCurrentViewportVk.y = 0.0f; |
| 103 | mCurrentViewportVk.width = 0.0f; |
| 104 | mCurrentViewportVk.height = 0.0f; |
| 105 | mCurrentViewportVk.minDepth = 0.0f; |
| 106 | mCurrentViewportVk.maxDepth = 1.0f; |
| 107 | |
| 108 | mCurrentScissorVk.offset.x = 0; |
| 109 | mCurrentScissorVk.offset.y = 0; |
| 110 | mCurrentScissorVk.extent.width = 0u; |
| 111 | mCurrentScissorVk.extent.height = 0u; |
| 112 | |
| 113 | mCurrentViewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 114 | mCurrentViewportState.pNext = nullptr; |
| 115 | mCurrentViewportState.flags = 0; |
| 116 | mCurrentViewportState.viewportCount = 1; |
| 117 | mCurrentViewportState.pViewports = &mCurrentViewportVk; |
| 118 | mCurrentViewportState.scissorCount = 1; |
| 119 | mCurrentViewportState.pScissors = &mCurrentScissorVk; |
| 120 | |
| 121 | // Set initial rasterizer state. |
| 122 | // TODO(jmadill): Extra rasterizer state features. |
| 123 | mCurrentRasterState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 124 | mCurrentRasterState.pNext = nullptr; |
| 125 | mCurrentRasterState.flags = 0; |
| 126 | mCurrentRasterState.depthClampEnable = VK_FALSE; |
| 127 | mCurrentRasterState.rasterizerDiscardEnable = VK_FALSE; |
| 128 | mCurrentRasterState.polygonMode = VK_POLYGON_MODE_FILL; |
| 129 | mCurrentRasterState.cullMode = VK_CULL_MODE_NONE; |
| 130 | mCurrentRasterState.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 131 | mCurrentRasterState.depthBiasEnable = VK_FALSE; |
| 132 | mCurrentRasterState.depthBiasConstantFactor = 0.0f; |
| 133 | mCurrentRasterState.depthBiasClamp = 0.0f; |
| 134 | mCurrentRasterState.depthBiasSlopeFactor = 0.0f; |
| 135 | mCurrentRasterState.lineWidth = 1.0f; |
| 136 | |
| 137 | // Initialize a dummy multisample state. |
| 138 | // TODO(jmadill): Multisample state. |
| 139 | mCurrentMultisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 140 | mCurrentMultisampleState.pNext = nullptr; |
| 141 | mCurrentMultisampleState.flags = 0; |
| 142 | mCurrentMultisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 143 | mCurrentMultisampleState.sampleShadingEnable = VK_FALSE; |
| 144 | mCurrentMultisampleState.minSampleShading = 0.0f; |
| 145 | mCurrentMultisampleState.pSampleMask = nullptr; |
| 146 | mCurrentMultisampleState.alphaToCoverageEnable = VK_FALSE; |
| 147 | mCurrentMultisampleState.alphaToOneEnable = VK_FALSE; |
| 148 | |
| 149 | // TODO(jmadill): Depth/stencil state. |
| 150 | |
| 151 | // Initialize a dummy MRT blend state. |
| 152 | // TODO(jmadill): Blend state/MRT. |
| 153 | mCurrentBlendAttachmentState.blendEnable = VK_FALSE; |
| 154 | mCurrentBlendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_ONE; |
| 155 | mCurrentBlendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE; |
| 156 | mCurrentBlendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD; |
| 157 | mCurrentBlendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; |
| 158 | mCurrentBlendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE; |
| 159 | mCurrentBlendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD; |
| 160 | mCurrentBlendAttachmentState.colorWriteMask = |
| 161 | (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | |
| 162 | VK_COLOR_COMPONENT_A_BIT); |
| 163 | |
| 164 | mCurrentBlendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 165 | mCurrentBlendState.pNext = 0; |
| 166 | mCurrentBlendState.flags = 0; |
| 167 | mCurrentBlendState.logicOpEnable = VK_FALSE; |
| 168 | mCurrentBlendState.logicOp = VK_LOGIC_OP_CLEAR; |
| 169 | mCurrentBlendState.attachmentCount = 1; |
| 170 | mCurrentBlendState.pAttachments = &mCurrentBlendAttachmentState; |
| 171 | mCurrentBlendState.blendConstants[0] = 0.0f; |
| 172 | mCurrentBlendState.blendConstants[1] = 0.0f; |
| 173 | mCurrentBlendState.blendConstants[2] = 0.0f; |
| 174 | mCurrentBlendState.blendConstants[3] = 0.0f; |
| 175 | |
| 176 | // TODO(jmadill): Dynamic state. |
| 177 | |
| 178 | // The layout and renderpass are filled out at draw time. |
| 179 | mCurrentPipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 180 | mCurrentPipelineInfo.pNext = nullptr; |
| 181 | mCurrentPipelineInfo.flags = 0; |
| 182 | mCurrentPipelineInfo.stageCount = 2; |
| 183 | mCurrentPipelineInfo.pStages = mCurrentShaderStages; |
| 184 | mCurrentPipelineInfo.pVertexInputState = &mCurrentVertexInputState; |
| 185 | mCurrentPipelineInfo.pInputAssemblyState = &mCurrentInputAssemblyState; |
| 186 | mCurrentPipelineInfo.pTessellationState = nullptr; |
| 187 | mCurrentPipelineInfo.pViewportState = &mCurrentViewportState; |
| 188 | mCurrentPipelineInfo.pRasterizationState = &mCurrentRasterState; |
| 189 | mCurrentPipelineInfo.pMultisampleState = &mCurrentMultisampleState; |
| 190 | mCurrentPipelineInfo.pDepthStencilState = nullptr; |
| 191 | mCurrentPipelineInfo.pColorBlendState = &mCurrentBlendState; |
| 192 | mCurrentPipelineInfo.pDynamicState = nullptr; |
| 193 | mCurrentPipelineInfo.layout = VK_NULL_HANDLE; |
| 194 | mCurrentPipelineInfo.renderPass = VK_NULL_HANDLE; |
| 195 | mCurrentPipelineInfo.subpass = 0; |
| 196 | mCurrentPipelineInfo.basePipelineHandle = VK_NULL_HANDLE; |
| 197 | mCurrentPipelineInfo.basePipelineIndex = 0; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | ContextVk::~ContextVk() |
| 201 | { |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 202 | invalidateCurrentPipeline(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 203 | } |
| 204 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 205 | void ContextVk::onDestroy(const gl::Context *context) |
| 206 | { |
| 207 | VkDevice device = mRenderer->getDevice(); |
| 208 | |
| 209 | mDescriptorPool.destroy(device); |
| 210 | } |
| 211 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 212 | gl::Error ContextVk::initialize() |
| 213 | { |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 214 | VkDevice device = mRenderer->getDevice(); |
| 215 | |
| 216 | VkDescriptorPoolSize poolSizes[2]; |
| 217 | poolSizes[UniformBufferPool].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 218 | poolSizes[UniformBufferPool].descriptorCount = 1024; |
| 219 | poolSizes[TexturePool].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 220 | poolSizes[TexturePool].descriptorCount = 1024; |
| 221 | |
| 222 | VkDescriptorPoolCreateInfo descriptorPoolInfo; |
| 223 | descriptorPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 224 | descriptorPoolInfo.pNext = nullptr; |
| 225 | descriptorPoolInfo.flags = 0; |
| 226 | |
| 227 | // TODO(jmadill): Pick non-arbitrary max. |
| 228 | descriptorPoolInfo.maxSets = 2048; |
| 229 | |
| 230 | // Reserve pools for uniform blocks and textures. |
| 231 | descriptorPoolInfo.poolSizeCount = 2; |
| 232 | descriptorPoolInfo.pPoolSizes = poolSizes; |
| 233 | |
| 234 | ANGLE_TRY(mDescriptorPool.init(device, descriptorPoolInfo)); |
| 235 | |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 236 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | gl::Error ContextVk::flush() |
| 240 | { |
| 241 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 242 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | gl::Error ContextVk::finish() |
| 246 | { |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 247 | // TODO(jmadill): Implement finish. |
| 248 | // UNIMPLEMENTED(); |
| 249 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 250 | } |
| 251 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 252 | gl::Error ContextVk::initPipeline(const gl::Context *context) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 253 | { |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 254 | ASSERT(!mCurrentPipeline.valid()); |
| 255 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 256 | VkDevice device = mRenderer->getDevice(); |
| 257 | const auto &state = mState.getState(); |
| 258 | const auto &programGL = state.getProgram(); |
| 259 | const auto &vao = state.getVertexArray(); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 260 | const auto &programVk = GetImplAs<ProgramVk>(programGL); |
| 261 | const auto *drawFBO = state.getDrawFramebuffer(); |
| 262 | FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 263 | VertexArrayVk *vkVAO = GetImplAs<VertexArrayVk>(vao); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 264 | |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 265 | // Ensure the attribs and bindings are updated. |
| 266 | vkVAO->updateVertexDescriptions(context); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 267 | |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 268 | const auto &vertexBindings = vkVAO->getVertexBindingDescs(); |
| 269 | const auto &vertexAttribs = vkVAO->getVertexAttribDescs(); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 270 | |
| 271 | // TODO(jmadill): Validate with ASSERT against physical device limits/caps? |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 272 | mCurrentVertexInputState.vertexBindingDescriptionCount = |
| 273 | static_cast<uint32_t>(vertexBindings.size()); |
| 274 | mCurrentVertexInputState.pVertexBindingDescriptions = vertexBindings.data(); |
| 275 | mCurrentVertexInputState.vertexAttributeDescriptionCount = |
| 276 | static_cast<uint32_t>(vertexAttribs.size()); |
| 277 | mCurrentVertexInputState.pVertexAttributeDescriptions = vertexAttribs.data(); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 278 | |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 279 | mCurrentInputAssemblyState.topology = gl_vk::GetPrimitiveTopology(mCurrentDrawMode); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 280 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 281 | vk::RenderPass *renderPass = nullptr; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 282 | ANGLE_TRY_RESULT(vkFBO->getRenderPass(context, device), renderPass); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 283 | ASSERT(renderPass && renderPass->valid()); |
| 284 | |
Jamie Madill | c514348 | 2017-10-15 20:20:06 -0400 | [diff] [blame] | 285 | const vk::PipelineLayout &pipelineLayout = programVk->getPipelineLayout(); |
| 286 | ASSERT(pipelineLayout.valid()); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 287 | |
Jamie Madill | c514348 | 2017-10-15 20:20:06 -0400 | [diff] [blame] | 288 | mCurrentPipelineInfo.layout = pipelineLayout.getHandle(); |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 289 | mCurrentPipelineInfo.renderPass = renderPass->getHandle(); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 290 | |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 291 | vk::Pipeline newPipeline; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 292 | ANGLE_TRY(newPipeline.initGraphics(device, mCurrentPipelineInfo)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 293 | |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 294 | // TODO(jmadill): Don't dispose the current pipeline immediately, it could be in use. |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 295 | mCurrentPipeline.retain(device, std::move(newPipeline)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 296 | |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 297 | return gl::NoError(); |
| 298 | } |
| 299 | |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 300 | gl::Error ContextVk::setupDraw(const gl::Context *context, GLenum mode) |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 301 | { |
| 302 | if (mode != mCurrentDrawMode) |
| 303 | { |
| 304 | invalidateCurrentPipeline(); |
| 305 | mCurrentDrawMode = mode; |
| 306 | } |
| 307 | |
| 308 | if (!mCurrentPipeline.valid()) |
| 309 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 310 | ANGLE_TRY(initPipeline(context)); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 311 | ASSERT(mCurrentPipeline.valid()); |
| 312 | } |
| 313 | |
| 314 | VkDevice device = mRenderer->getDevice(); |
| 315 | const auto &state = mState.getState(); |
| 316 | const auto &programGL = state.getProgram(); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 317 | ProgramVk *programVk = GetImplAs<ProgramVk>(programGL); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 318 | const auto &vao = state.getVertexArray(); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 319 | VertexArrayVk *vkVAO = GetImplAs<VertexArrayVk>(vao); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 320 | const auto *drawFBO = state.getDrawFramebuffer(); |
| 321 | FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO); |
| 322 | Serial queueSerial = mRenderer->getCurrentQueueSerial(); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 323 | uint32_t maxAttrib = programGL->getState().getMaxActiveAttribLocation(); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 324 | |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 325 | // Process vertex attributes. Assume zero offsets for now. |
| 326 | // TODO(jmadill): Offset handling. |
| 327 | const std::vector<VkBuffer> &vertexHandles = vkVAO->getCurrentVertexBufferHandlesCache(); |
| 328 | angle::MemoryBuffer *zeroBuf = nullptr; |
| 329 | ANGLE_TRY(context->getZeroFilledBuffer(maxAttrib * sizeof(VkDeviceSize), &zeroBuf)); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 330 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 331 | vk::CommandBuffer *commandBuffer = nullptr; |
| 332 | ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer)); |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 333 | ANGLE_TRY(vkFBO->ensureInRenderPass(context, device, commandBuffer, queueSerial, state)); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 334 | |
| 335 | commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 336 | commandBuffer->bindVertexBuffers(0, maxAttrib, vertexHandles.data(), |
| 337 | reinterpret_cast<const VkDeviceSize *>(zeroBuf->data())); |
| 338 | |
Jamie Madill | abd3135 | 2017-09-19 00:24:58 -0400 | [diff] [blame] | 339 | // TODO(jmadill): the queue serial should be bound to the pipeline. |
| 340 | setQueueSerial(queueSerial); |
Jamie Madill | bd159f0 | 2017-10-09 19:39:06 -0400 | [diff] [blame] | 341 | vkVAO->updateCurrentBufferSerials(programGL->getActiveAttribLocationsMask(), queueSerial); |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 342 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 343 | // TODO(jmadill): Can probably use more dirty bits here. |
| 344 | ContextVk *contextVk = GetImplAs<ContextVk>(context); |
| 345 | ANGLE_TRY(programVk->updateUniforms(contextVk)); |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 346 | programVk->updateTexturesDescriptorSet(contextVk); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 347 | |
| 348 | // Bind the graphics descriptor sets. |
| 349 | // TODO(jmadill): Handle multiple command buffers. |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 350 | const auto &descriptorSets = programVk->getDescriptorSets(); |
| 351 | uint32_t firstSet = programVk->getDescriptorSetOffset(); |
| 352 | uint32_t setCount = static_cast<uint32_t>(descriptorSets.size()); |
| 353 | if (!descriptorSets.empty() && ((setCount - firstSet) > 0)) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 354 | { |
| 355 | const vk::PipelineLayout &pipelineLayout = programVk->getPipelineLayout(); |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 356 | commandBuffer->bindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, firstSet, |
| 357 | setCount - firstSet, &descriptorSets[firstSet], 0, |
| 358 | nullptr); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 359 | } |
| 360 | |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 361 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 362 | } |
| 363 | |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 364 | gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count) |
| 365 | { |
| 366 | ANGLE_TRY(setupDraw(context, mode)); |
| 367 | |
| 368 | vk::CommandBuffer *commandBuffer = nullptr; |
| 369 | ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer)); |
| 370 | |
| 371 | commandBuffer->draw(count, 1, first, 0); |
| 372 | return gl::NoError(); |
| 373 | } |
| 374 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 375 | gl::Error ContextVk::drawArraysInstanced(const gl::Context *context, |
| 376 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 377 | GLint first, |
| 378 | GLsizei count, |
| 379 | GLsizei instanceCount) |
| 380 | { |
| 381 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 382 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 385 | gl::Error ContextVk::drawElements(const gl::Context *context, |
| 386 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 387 | GLsizei count, |
| 388 | GLenum type, |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 389 | const void *indices) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 390 | { |
Jamie Madill | d03a849 | 2017-10-03 15:46:06 -0400 | [diff] [blame] | 391 | ANGLE_TRY(setupDraw(context, mode)); |
| 392 | |
| 393 | if (indices) |
| 394 | { |
| 395 | // TODO(jmadill): Buffer offsets and immediate data. |
| 396 | UNIMPLEMENTED(); |
| 397 | return gl::InternalError() << "Only zero-offset index buffers are currently implemented."; |
| 398 | } |
| 399 | |
| 400 | if (type == GL_UNSIGNED_BYTE) |
| 401 | { |
| 402 | // TODO(jmadill): Index translation. |
| 403 | UNIMPLEMENTED(); |
| 404 | return gl::InternalError() << "Unsigned byte translation is not yet implemented."; |
| 405 | } |
| 406 | |
| 407 | vk::CommandBuffer *commandBuffer = nullptr; |
| 408 | ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer)); |
| 409 | |
| 410 | const gl::Buffer *elementArrayBuffer = |
| 411 | mState.getState().getVertexArray()->getElementArrayBuffer().get(); |
| 412 | ASSERT(elementArrayBuffer); |
| 413 | |
| 414 | BufferVk *elementArrayBufferVk = GetImplAs<BufferVk>(elementArrayBuffer); |
| 415 | |
| 416 | commandBuffer->bindIndexBuffer(elementArrayBufferVk->getVkBuffer(), 0, GetVkIndexType(type)); |
| 417 | commandBuffer->drawIndexed(count, 1, 0, 0, 0); |
| 418 | |
| 419 | return gl::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 420 | } |
| 421 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 422 | gl::Error ContextVk::drawElementsInstanced(const gl::Context *context, |
| 423 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 424 | GLsizei count, |
| 425 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 426 | const void *indices, |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 427 | GLsizei instances) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 428 | { |
| 429 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 430 | return gl::InternalError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 433 | gl::Error ContextVk::drawRangeElements(const gl::Context *context, |
| 434 | GLenum mode, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 435 | GLuint start, |
| 436 | GLuint end, |
| 437 | GLsizei count, |
| 438 | GLenum type, |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 439 | const void *indices) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 440 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 441 | return gl::NoError(); |
| 442 | } |
| 443 | |
| 444 | VkDevice ContextVk::getDevice() const |
| 445 | { |
| 446 | return mRenderer->getDevice(); |
| 447 | } |
| 448 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 449 | vk::Error ContextVk::getStartedCommandBuffer(vk::CommandBuffer **commandBufferOut) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 450 | { |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 451 | return mRenderer->getStartedCommandBuffer(commandBufferOut); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 452 | } |
| 453 | |
Jamie Madill | 0c0dc34 | 2017-03-24 14:18:51 -0400 | [diff] [blame] | 454 | vk::Error ContextVk::submitCommands(vk::CommandBuffer *commandBuffer) |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 455 | { |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 456 | setQueueSerial(mRenderer->getCurrentQueueSerial()); |
Jamie Madill | f651c77 | 2017-02-21 15:03:51 -0500 | [diff] [blame] | 457 | ANGLE_TRY(mRenderer->submitCommandBuffer(commandBuffer)); |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 458 | return vk::NoError(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 459 | } |
| 460 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 461 | gl::Error ContextVk::drawArraysIndirect(const gl::Context *context, |
| 462 | GLenum mode, |
| 463 | const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 464 | { |
| 465 | UNIMPLEMENTED(); |
| 466 | return gl::InternalError() << "DrawArraysIndirect hasn't been implemented for vulkan backend."; |
| 467 | } |
| 468 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 469 | gl::Error ContextVk::drawElementsIndirect(const gl::Context *context, |
| 470 | GLenum mode, |
| 471 | GLenum type, |
| 472 | const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 473 | { |
| 474 | UNIMPLEMENTED(); |
| 475 | return gl::InternalError() |
| 476 | << "DrawElementsIndirect hasn't been implemented for vulkan backend."; |
| 477 | } |
| 478 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 479 | GLenum ContextVk::getResetStatus() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 480 | { |
| 481 | UNIMPLEMENTED(); |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 482 | return GL_NO_ERROR; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | std::string ContextVk::getVendorString() const |
| 486 | { |
| 487 | UNIMPLEMENTED(); |
| 488 | return std::string(); |
| 489 | } |
| 490 | |
| 491 | std::string ContextVk::getRendererDescription() const |
| 492 | { |
Jamie Madill | e09bd5d | 2016-11-29 16:20:35 -0500 | [diff] [blame] | 493 | return mRenderer->getRendererDescription(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | void ContextVk::insertEventMarker(GLsizei length, const char *marker) |
| 497 | { |
| 498 | UNIMPLEMENTED(); |
| 499 | } |
| 500 | |
| 501 | void ContextVk::pushGroupMarker(GLsizei length, const char *marker) |
| 502 | { |
| 503 | UNIMPLEMENTED(); |
| 504 | } |
| 505 | |
| 506 | void ContextVk::popGroupMarker() |
| 507 | { |
| 508 | UNIMPLEMENTED(); |
| 509 | } |
| 510 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 511 | void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 512 | { |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 513 | if (dirtyBits.any()) |
| 514 | { |
| 515 | invalidateCurrentPipeline(); |
| 516 | } |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 517 | |
| 518 | const auto &glState = context->getGLState(); |
| 519 | |
| 520 | // TODO(jmadill): Full dirty bits implementation. |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 521 | bool dirtyTextures = false; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 522 | |
| 523 | for (auto dirtyBit : dirtyBits) |
| 524 | { |
| 525 | switch (dirtyBit) |
| 526 | { |
| 527 | case gl::State::DIRTY_BIT_SCISSOR_TEST_ENABLED: |
| 528 | WARN() << "DIRTY_BIT_SCISSOR_TEST_ENABLED unimplemented"; |
| 529 | break; |
| 530 | case gl::State::DIRTY_BIT_SCISSOR: |
| 531 | WARN() << "DIRTY_BIT_SCISSOR unimplemented"; |
| 532 | break; |
| 533 | case gl::State::DIRTY_BIT_VIEWPORT: |
| 534 | { |
| 535 | const gl::Rectangle &viewportGL = glState.getViewport(); |
| 536 | mCurrentViewportVk.x = static_cast<float>(viewportGL.x); |
| 537 | mCurrentViewportVk.y = static_cast<float>(viewportGL.y); |
| 538 | mCurrentViewportVk.width = static_cast<float>(viewportGL.width); |
| 539 | mCurrentViewportVk.height = static_cast<float>(viewportGL.height); |
| 540 | mCurrentViewportVk.minDepth = glState.getNearPlane(); |
| 541 | mCurrentViewportVk.maxDepth = glState.getFarPlane(); |
| 542 | |
| 543 | // TODO(jmadill): Scissor. |
| 544 | mCurrentScissorVk.offset.x = viewportGL.x; |
| 545 | mCurrentScissorVk.offset.y = viewportGL.y; |
| 546 | mCurrentScissorVk.extent.width = viewportGL.width; |
| 547 | mCurrentScissorVk.extent.height = viewportGL.height; |
| 548 | break; |
| 549 | } |
| 550 | case gl::State::DIRTY_BIT_DEPTH_RANGE: |
| 551 | WARN() << "DIRTY_BIT_DEPTH_RANGE unimplemented"; |
| 552 | break; |
| 553 | case gl::State::DIRTY_BIT_BLEND_ENABLED: |
| 554 | WARN() << "DIRTY_BIT_BLEND_ENABLED unimplemented"; |
| 555 | break; |
| 556 | case gl::State::DIRTY_BIT_BLEND_COLOR: |
| 557 | WARN() << "DIRTY_BIT_BLEND_COLOR unimplemented"; |
| 558 | break; |
| 559 | case gl::State::DIRTY_BIT_BLEND_FUNCS: |
| 560 | WARN() << "DIRTY_BIT_BLEND_FUNCS unimplemented"; |
| 561 | break; |
| 562 | case gl::State::DIRTY_BIT_BLEND_EQUATIONS: |
| 563 | WARN() << "DIRTY_BIT_BLEND_EQUATIONS unimplemented"; |
| 564 | break; |
| 565 | case gl::State::DIRTY_BIT_COLOR_MASK: |
| 566 | WARN() << "DIRTY_BIT_COLOR_MASK unimplemented"; |
| 567 | break; |
| 568 | case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED: |
| 569 | WARN() << "DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED unimplemented"; |
| 570 | break; |
| 571 | case gl::State::DIRTY_BIT_SAMPLE_COVERAGE_ENABLED: |
| 572 | WARN() << "DIRTY_BIT_SAMPLE_COVERAGE_ENABLED unimplemented"; |
| 573 | break; |
| 574 | case gl::State::DIRTY_BIT_SAMPLE_COVERAGE: |
| 575 | WARN() << "DIRTY_BIT_SAMPLE_COVERAGE unimplemented"; |
| 576 | break; |
| 577 | case gl::State::DIRTY_BIT_SAMPLE_MASK_ENABLED: |
| 578 | WARN() << "DIRTY_BIT_SAMPLE_MASK_ENABLED unimplemented"; |
| 579 | break; |
| 580 | case gl::State::DIRTY_BIT_SAMPLE_MASK_WORD_0: |
| 581 | case gl::State::DIRTY_BIT_SAMPLE_MASK_WORD_0 + 1: |
| 582 | WARN() << "DIRTY_BIT_SAMPLE_MASK_WORD unimplemented"; |
| 583 | break; |
| 584 | case gl::State::DIRTY_BIT_DEPTH_TEST_ENABLED: |
| 585 | WARN() << "DIRTY_BIT_DEPTH_TEST_ENABLED unimplemented"; |
| 586 | break; |
| 587 | case gl::State::DIRTY_BIT_DEPTH_FUNC: |
| 588 | WARN() << "DIRTY_BIT_DEPTH_FUNC unimplemented"; |
| 589 | break; |
| 590 | case gl::State::DIRTY_BIT_DEPTH_MASK: |
| 591 | WARN() << "DIRTY_BIT_DEPTH_MASK unimplemented"; |
| 592 | break; |
| 593 | case gl::State::DIRTY_BIT_STENCIL_TEST_ENABLED: |
| 594 | WARN() << "DIRTY_BIT_STENCIL_TEST_ENABLED unimplemented"; |
| 595 | break; |
| 596 | case gl::State::DIRTY_BIT_STENCIL_FUNCS_FRONT: |
| 597 | WARN() << "DIRTY_BIT_STENCIL_FUNCS_FRONT unimplemented"; |
| 598 | break; |
| 599 | case gl::State::DIRTY_BIT_STENCIL_FUNCS_BACK: |
| 600 | WARN() << "DIRTY_BIT_STENCIL_FUNCS_BACK unimplemented"; |
| 601 | break; |
| 602 | case gl::State::DIRTY_BIT_STENCIL_OPS_FRONT: |
| 603 | WARN() << "DIRTY_BIT_STENCIL_OPS_FRONT unimplemented"; |
| 604 | break; |
| 605 | case gl::State::DIRTY_BIT_STENCIL_OPS_BACK: |
| 606 | WARN() << "DIRTY_BIT_STENCIL_OPS_BACK unimplemented"; |
| 607 | break; |
| 608 | case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT: |
| 609 | WARN() << "DIRTY_BIT_STENCIL_WRITEMASK_FRONT unimplemented"; |
| 610 | break; |
| 611 | case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_BACK: |
| 612 | WARN() << "DIRTY_BIT_STENCIL_WRITEMASK_BACK unimplemented"; |
| 613 | break; |
| 614 | case gl::State::DIRTY_BIT_CULL_FACE_ENABLED: |
| 615 | case gl::State::DIRTY_BIT_CULL_FACE: |
| 616 | mCurrentRasterState.cullMode = gl_vk::GetCullMode(glState.getRasterizerState()); |
| 617 | break; |
| 618 | case gl::State::DIRTY_BIT_FRONT_FACE: |
| 619 | mCurrentRasterState.frontFace = |
| 620 | gl_vk::GetFrontFace(glState.getRasterizerState().frontFace); |
| 621 | break; |
| 622 | case gl::State::DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED: |
| 623 | WARN() << "DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED unimplemented"; |
| 624 | break; |
| 625 | case gl::State::DIRTY_BIT_POLYGON_OFFSET: |
| 626 | WARN() << "DIRTY_BIT_POLYGON_OFFSET unimplemented"; |
| 627 | break; |
| 628 | case gl::State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED: |
| 629 | WARN() << "DIRTY_BIT_RASTERIZER_DISCARD_ENABLED unimplemented"; |
| 630 | break; |
| 631 | case gl::State::DIRTY_BIT_LINE_WIDTH: |
| 632 | mCurrentRasterState.lineWidth = glState.getLineWidth(); |
| 633 | break; |
| 634 | case gl::State::DIRTY_BIT_PRIMITIVE_RESTART_ENABLED: |
| 635 | WARN() << "DIRTY_BIT_PRIMITIVE_RESTART_ENABLED unimplemented"; |
| 636 | break; |
| 637 | case gl::State::DIRTY_BIT_CLEAR_COLOR: |
| 638 | WARN() << "DIRTY_BIT_CLEAR_COLOR unimplemented"; |
| 639 | break; |
| 640 | case gl::State::DIRTY_BIT_CLEAR_DEPTH: |
| 641 | WARN() << "DIRTY_BIT_CLEAR_DEPTH unimplemented"; |
| 642 | break; |
| 643 | case gl::State::DIRTY_BIT_CLEAR_STENCIL: |
| 644 | WARN() << "DIRTY_BIT_CLEAR_STENCIL unimplemented"; |
| 645 | break; |
| 646 | case gl::State::DIRTY_BIT_UNPACK_ALIGNMENT: |
| 647 | WARN() << "DIRTY_BIT_UNPACK_ALIGNMENT unimplemented"; |
| 648 | break; |
| 649 | case gl::State::DIRTY_BIT_UNPACK_ROW_LENGTH: |
| 650 | WARN() << "DIRTY_BIT_UNPACK_ROW_LENGTH unimplemented"; |
| 651 | break; |
| 652 | case gl::State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT: |
| 653 | WARN() << "DIRTY_BIT_UNPACK_IMAGE_HEIGHT unimplemented"; |
| 654 | break; |
| 655 | case gl::State::DIRTY_BIT_UNPACK_SKIP_IMAGES: |
| 656 | WARN() << "DIRTY_BIT_UNPACK_SKIP_IMAGES unimplemented"; |
| 657 | break; |
| 658 | case gl::State::DIRTY_BIT_UNPACK_SKIP_ROWS: |
| 659 | WARN() << "DIRTY_BIT_UNPACK_SKIP_ROWS unimplemented"; |
| 660 | break; |
| 661 | case gl::State::DIRTY_BIT_UNPACK_SKIP_PIXELS: |
| 662 | WARN() << "DIRTY_BIT_UNPACK_SKIP_PIXELS unimplemented"; |
| 663 | break; |
| 664 | case gl::State::DIRTY_BIT_UNPACK_BUFFER_BINDING: |
| 665 | WARN() << "DIRTY_BIT_UNPACK_BUFFER_BINDING unimplemented"; |
| 666 | break; |
| 667 | case gl::State::DIRTY_BIT_PACK_ALIGNMENT: |
| 668 | WARN() << "DIRTY_BIT_PACK_ALIGNMENT unimplemented"; |
| 669 | break; |
| 670 | case gl::State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER: |
| 671 | WARN() << "DIRTY_BIT_PACK_REVERSE_ROW_ORDER unimplemented"; |
| 672 | break; |
| 673 | case gl::State::DIRTY_BIT_PACK_ROW_LENGTH: |
| 674 | WARN() << "DIRTY_BIT_PACK_ROW_LENGTH unimplemented"; |
| 675 | break; |
| 676 | case gl::State::DIRTY_BIT_PACK_SKIP_ROWS: |
| 677 | WARN() << "DIRTY_BIT_PACK_SKIP_ROWS unimplemented"; |
| 678 | break; |
| 679 | case gl::State::DIRTY_BIT_PACK_SKIP_PIXELS: |
| 680 | WARN() << "DIRTY_BIT_PACK_SKIP_PIXELS unimplemented"; |
| 681 | break; |
| 682 | case gl::State::DIRTY_BIT_PACK_BUFFER_BINDING: |
| 683 | WARN() << "DIRTY_BIT_PACK_BUFFER_BINDING unimplemented"; |
| 684 | break; |
| 685 | case gl::State::DIRTY_BIT_DITHER_ENABLED: |
| 686 | WARN() << "DIRTY_BIT_DITHER_ENABLED unimplemented"; |
| 687 | break; |
| 688 | case gl::State::DIRTY_BIT_GENERATE_MIPMAP_HINT: |
| 689 | WARN() << "DIRTY_BIT_GENERATE_MIPMAP_HINT unimplemented"; |
| 690 | break; |
| 691 | case gl::State::DIRTY_BIT_SHADER_DERIVATIVE_HINT: |
| 692 | WARN() << "DIRTY_BIT_SHADER_DERIVATIVE_HINT unimplemented"; |
| 693 | break; |
| 694 | case gl::State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING: |
| 695 | WARN() << "DIRTY_BIT_READ_FRAMEBUFFER_BINDING unimplemented"; |
| 696 | break; |
| 697 | case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING: |
| 698 | WARN() << "DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING unimplemented"; |
| 699 | break; |
| 700 | case gl::State::DIRTY_BIT_RENDERBUFFER_BINDING: |
| 701 | WARN() << "DIRTY_BIT_RENDERBUFFER_BINDING unimplemented"; |
| 702 | break; |
| 703 | case gl::State::DIRTY_BIT_VERTEX_ARRAY_BINDING: |
| 704 | WARN() << "DIRTY_BIT_VERTEX_ARRAY_BINDING unimplemented"; |
| 705 | break; |
| 706 | case gl::State::DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING: |
| 707 | WARN() << "DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING unimplemented"; |
| 708 | break; |
| 709 | case gl::State::DIRTY_BIT_PROGRAM_BINDING: |
| 710 | WARN() << "DIRTY_BIT_PROGRAM_BINDING unimplemented"; |
| 711 | break; |
| 712 | case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE: |
| 713 | { |
| 714 | // { vertex, fragment } |
| 715 | ProgramVk *programVk = GetImplAs<ProgramVk>(glState.getProgram()); |
| 716 | mCurrentShaderStages[0].module = programVk->getLinkedVertexModule().getHandle(); |
| 717 | mCurrentShaderStages[1].module = programVk->getLinkedFragmentModule().getHandle(); |
| 718 | |
| 719 | // Also invalidate the vertex descriptions cache in the Vertex Array. |
| 720 | VertexArrayVk *vaoVk = GetImplAs<VertexArrayVk>(glState.getVertexArray()); |
| 721 | vaoVk->invalidateVertexDescriptions(); |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 722 | |
| 723 | dirtyTextures = true; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 724 | break; |
| 725 | } |
| 726 | case gl::State::DIRTY_BIT_TEXTURE_BINDINGS: |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 727 | dirtyTextures = true; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 728 | break; |
| 729 | case gl::State::DIRTY_BIT_SAMPLER_BINDINGS: |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 730 | dirtyTextures = true; |
Jamie Madill | ebf7299 | 2017-10-13 14:09:45 -0400 | [diff] [blame] | 731 | break; |
| 732 | case gl::State::DIRTY_BIT_MULTISAMPLING: |
| 733 | WARN() << "DIRTY_BIT_MULTISAMPLING unimplemented"; |
| 734 | break; |
| 735 | case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_ONE: |
| 736 | WARN() << "DIRTY_BIT_SAMPLE_ALPHA_TO_ONE unimplemented"; |
| 737 | break; |
| 738 | case gl::State::DIRTY_BIT_COVERAGE_MODULATION: |
| 739 | WARN() << "DIRTY_BIT_COVERAGE_MODULATION unimplemented"; |
| 740 | break; |
| 741 | case gl::State::DIRTY_BIT_PATH_RENDERING_MATRIX_MV: |
| 742 | WARN() << "DIRTY_BIT_PATH_RENDERING_MATRIX_MV unimplemented"; |
| 743 | break; |
| 744 | case gl::State::DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ: |
| 745 | WARN() << "DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ unimplemented"; |
| 746 | break; |
| 747 | case gl::State::DIRTY_BIT_PATH_RENDERING_STENCIL_STATE: |
| 748 | WARN() << "DIRTY_BIT_PATH_RENDERING_STENCIL_STATE unimplemented"; |
| 749 | break; |
| 750 | case gl::State::DIRTY_BIT_FRAMEBUFFER_SRGB: |
| 751 | WARN() << "DIRTY_BIT_FRAMEBUFFER_SRGB unimplemented"; |
| 752 | break; |
| 753 | default: |
| 754 | if (dirtyBit >= gl::State::DIRTY_BIT_CURRENT_VALUE_0 && |
| 755 | dirtyBit < gl::State::DIRTY_BIT_CURRENT_VALUE_MAX) |
| 756 | { |
| 757 | WARN() << "DIRTY_BIT_CURRENT_VALUE unimplemented"; |
| 758 | } |
| 759 | else |
| 760 | { |
| 761 | UNREACHABLE(); |
| 762 | } |
| 763 | break; |
| 764 | } |
| 765 | } |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 766 | |
| 767 | if (dirtyTextures) |
| 768 | { |
| 769 | ProgramVk *programVk = GetImplAs<ProgramVk>(glState.getProgram()); |
| 770 | programVk->invalidateTextures(); |
| 771 | } |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | GLint ContextVk::getGPUDisjoint() |
| 775 | { |
| 776 | UNIMPLEMENTED(); |
| 777 | return GLint(); |
| 778 | } |
| 779 | |
| 780 | GLint64 ContextVk::getTimestamp() |
| 781 | { |
| 782 | UNIMPLEMENTED(); |
| 783 | return GLint64(); |
| 784 | } |
| 785 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 786 | void ContextVk::onMakeCurrent(const gl::Context * /*context*/) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 787 | { |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | const gl::Caps &ContextVk::getNativeCaps() const |
| 791 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 792 | return mRenderer->getNativeCaps(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | const gl::TextureCapsMap &ContextVk::getNativeTextureCaps() const |
| 796 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 797 | return mRenderer->getNativeTextureCaps(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | const gl::Extensions &ContextVk::getNativeExtensions() const |
| 801 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 802 | return mRenderer->getNativeExtensions(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | const gl::Limitations &ContextVk::getNativeLimitations() const |
| 806 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 807 | return mRenderer->getNativeLimitations(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | CompilerImpl *ContextVk::createCompiler() |
| 811 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 812 | return new CompilerVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 813 | } |
| 814 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 815 | ShaderImpl *ContextVk::createShader(const gl::ShaderState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 816 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 817 | return new ShaderVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 818 | } |
| 819 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 820 | ProgramImpl *ContextVk::createProgram(const gl::ProgramState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 821 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 822 | return new ProgramVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 823 | } |
| 824 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 825 | FramebufferImpl *ContextVk::createFramebuffer(const gl::FramebufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 826 | { |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 827 | return FramebufferVk::CreateUserFBO(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | TextureImpl *ContextVk::createTexture(const gl::TextureState &state) |
| 831 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 832 | return new TextureVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | RenderbufferImpl *ContextVk::createRenderbuffer() |
| 836 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 837 | return new RenderbufferVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 838 | } |
| 839 | |
Jamie Madill | 8f77560 | 2016-11-03 16:45:34 -0400 | [diff] [blame] | 840 | BufferImpl *ContextVk::createBuffer(const gl::BufferState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 841 | { |
Jamie Madill | 8f77560 | 2016-11-03 16:45:34 -0400 | [diff] [blame] | 842 | return new BufferVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 843 | } |
| 844 | |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 845 | VertexArrayImpl *ContextVk::createVertexArray(const gl::VertexArrayState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 846 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 847 | return new VertexArrayVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | QueryImpl *ContextVk::createQuery(GLenum type) |
| 851 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 852 | return new QueryVk(type); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | FenceNVImpl *ContextVk::createFenceNV() |
| 856 | { |
Jamie Madill | acccc6c | 2016-05-03 17:22:10 -0400 | [diff] [blame] | 857 | return new FenceNVVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 858 | } |
| 859 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 860 | SyncImpl *ContextVk::createSync() |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 861 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 862 | return new SyncVk(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 863 | } |
| 864 | |
Geoff Lang | 73bd218 | 2016-07-15 13:01:24 -0400 | [diff] [blame] | 865 | TransformFeedbackImpl *ContextVk::createTransformFeedback(const gl::TransformFeedbackState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 866 | { |
Geoff Lang | 73bd218 | 2016-07-15 13:01:24 -0400 | [diff] [blame] | 867 | return new TransformFeedbackVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 868 | } |
| 869 | |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 870 | SamplerImpl *ContextVk::createSampler(const gl::SamplerState &state) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 871 | { |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 872 | return new SamplerVk(state); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 873 | } |
| 874 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 875 | ProgramPipelineImpl *ContextVk::createProgramPipeline(const gl::ProgramPipelineState &state) |
| 876 | { |
| 877 | return new ProgramPipelineVk(state); |
| 878 | } |
| 879 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 880 | std::vector<PathImpl *> ContextVk::createPaths(GLsizei) |
| 881 | { |
| 882 | return std::vector<PathImpl *>(); |
| 883 | } |
| 884 | |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 885 | // TODO(jmadill): Use pipeline cache. |
| 886 | void ContextVk::invalidateCurrentPipeline() |
| 887 | { |
Jamie Madill | e88ec8e | 2017-10-31 17:18:14 -0400 | [diff] [blame] | 888 | mRenderer->releaseResource(*this, &mCurrentPipeline); |
Jamie Madill | 7210656 | 2017-03-24 14:18:50 -0400 | [diff] [blame] | 889 | } |
| 890 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 891 | gl::Error ContextVk::dispatchCompute(const gl::Context *context, |
| 892 | GLuint numGroupsX, |
| 893 | GLuint numGroupsY, |
| 894 | GLuint numGroupsZ) |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 895 | { |
| 896 | UNIMPLEMENTED(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 897 | return gl::InternalError(); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 898 | } |
| 899 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 900 | vk::DescriptorPool *ContextVk::getDescriptorPool() |
| 901 | { |
| 902 | return &mDescriptorPool; |
| 903 | } |
| 904 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 905 | } // namespace rx |