blob: 11e2afdd913b0a0dcdafccf23e766107164d462b [file] [log] [blame]
Jamie Madill9e54b5a2016-05-25 12:57:39 -04001//
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 Madill20e005b2017-04-07 14:19:22 -040012#include "common/bitset_utils.h"
Jamie Madill9e54b5a2016-05-25 12:57:39 -040013#include "common/debug.h"
Jamie Madillbd159f02017-10-09 19:39:06 -040014#include "libANGLE/Context.h"
Jamie Madilldf68a6f2017-01-13 17:29:53 -050015#include "libANGLE/Program.h"
Jamie Madillacccc6c2016-05-03 17:22:10 -040016#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 Madillacccc6c2016-05-03 17:22:10 -040021#include "libANGLE/renderer/vulkan/FramebufferVk.h"
22#include "libANGLE/renderer/vulkan/ImageVk.h"
Yunchao Hea336b902017-08-02 16:05:21 +080023#include "libANGLE/renderer/vulkan/ProgramPipelineVk.h"
Jamie Madillacccc6c2016-05-03 17:22:10 -040024#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 Madill70b5bb02017-08-28 13:32:37 -040030#include "libANGLE/renderer/vulkan/SyncVk.h"
Jamie Madillacccc6c2016-05-03 17:22:10 -040031#include "libANGLE/renderer/vulkan/TextureVk.h"
32#include "libANGLE/renderer/vulkan/TransformFeedbackVk.h"
33#include "libANGLE/renderer/vulkan/VertexArrayVk.h"
Jamie Madilldf68a6f2017-01-13 17:29:53 -050034#include "libANGLE/renderer/vulkan/formatutilsvk.h"
Jamie Madill9e54b5a2016-05-25 12:57:39 -040035
36namespace rx
37{
38
Jamie Madilld03a8492017-10-03 15:46:06 -040039namespace
40{
41
42VkIndexType 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
56} // anonymous namespace
57
Jamie Madillacccc6c2016-05-03 17:22:10 -040058ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer)
Jamie Madill72106562017-03-24 14:18:50 -040059 : ContextImpl(state), mRenderer(renderer), mCurrentDrawMode(GL_NONE)
Jamie Madill9e54b5a2016-05-25 12:57:39 -040060{
61}
62
63ContextVk::~ContextVk()
64{
Jamie Madill72106562017-03-24 14:18:50 -040065 invalidateCurrentPipeline();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040066}
67
68gl::Error ContextVk::initialize()
69{
Jamie Madille09bd5d2016-11-29 16:20:35 -050070 return gl::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040071}
72
73gl::Error ContextVk::flush()
74{
75 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -050076 return gl::InternalError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040077}
78
79gl::Error ContextVk::finish()
80{
Jamie Madillbd159f02017-10-09 19:39:06 -040081 // TODO(jmadill): Implement finish.
82 // UNIMPLEMENTED();
83 return gl::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040084}
85
Jamie Madill4928b7c2017-06-20 12:57:39 -040086gl::Error ContextVk::initPipeline(const gl::Context *context)
Jamie Madill9e54b5a2016-05-25 12:57:39 -040087{
Jamie Madill72106562017-03-24 14:18:50 -040088 ASSERT(!mCurrentPipeline.valid());
89
Jamie Madilldf68a6f2017-01-13 17:29:53 -050090 VkDevice device = mRenderer->getDevice();
91 const auto &state = mState.getState();
92 const auto &programGL = state.getProgram();
93 const auto &vao = state.getVertexArray();
94 const auto &attribs = vao->getVertexAttributes();
Jiawei-Shao2597fb62016-12-09 16:38:02 +080095 const auto &bindings = vao->getVertexBindings();
Jamie Madilldf68a6f2017-01-13 17:29:53 -050096 const auto &programVk = GetImplAs<ProgramVk>(programGL);
97 const auto *drawFBO = state.getDrawFramebuffer();
98 FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO);
99
100 // { vertex, fragment }
101 VkPipelineShaderStageCreateInfo shaderStages[2];
102
103 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
104 shaderStages[0].pNext = nullptr;
105 shaderStages[0].flags = 0;
106 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
107 shaderStages[0].module = programVk->getLinkedVertexModule().getHandle();
108 shaderStages[0].pName = "main";
109 shaderStages[0].pSpecializationInfo = nullptr;
110
111 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
112 shaderStages[1].pNext = nullptr;
113 shaderStages[1].flags = 0;
114 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
115 shaderStages[1].module = programVk->getLinkedFragmentModule().getHandle();
116 shaderStages[1].pName = "main";
117 shaderStages[1].pSpecializationInfo = nullptr;
118
119 // Process vertex attributes
120 // TODO(jmadill): Caching with dirty bits.
121 std::vector<VkVertexInputBindingDescription> vertexBindings;
122 std::vector<VkVertexInputAttributeDescription> vertexAttribs;
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500123
Jamie Madill6de51852017-04-12 09:53:01 -0400124 for (auto attribIndex : programGL->getActiveAttribLocationsMask())
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500125 {
Jamie Madill231c7f52017-04-26 13:45:37 -0400126 const auto &attrib = attribs[attribIndex];
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800127 const auto &binding = bindings[attrib.bindingIndex];
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500128 if (attrib.enabled)
129 {
130 VkVertexInputBindingDescription bindingDesc;
131 bindingDesc.binding = static_cast<uint32_t>(vertexBindings.size());
132 bindingDesc.stride = static_cast<uint32_t>(gl::ComputeVertexAttributeTypeSize(attrib));
Martin Radevdd5f27e2017-06-07 10:17:09 +0300133 bindingDesc.inputRate = (binding.getDivisor() > 0 ? VK_VERTEX_INPUT_RATE_INSTANCE
134 : VK_VERTEX_INPUT_RATE_VERTEX);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500135
136 gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib);
137
138 VkVertexInputAttributeDescription attribDesc;
139 attribDesc.binding = bindingDesc.binding;
140 attribDesc.format = vk::GetNativeVertexFormat(vertexFormatType);
141 attribDesc.location = static_cast<uint32_t>(attribIndex);
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800142 attribDesc.offset =
143 static_cast<uint32_t>(ComputeVertexAttributeOffset(attrib, binding));
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500144
145 vertexBindings.push_back(bindingDesc);
146 vertexAttribs.push_back(attribDesc);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500147 }
148 else
149 {
150 UNIMPLEMENTED();
151 }
152 }
153
154 // TODO(jmadill): Validate with ASSERT against physical device limits/caps?
155 VkPipelineVertexInputStateCreateInfo vertexInputState;
156 vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
157 vertexInputState.pNext = nullptr;
158 vertexInputState.flags = 0;
159 vertexInputState.vertexBindingDescriptionCount = static_cast<uint32_t>(vertexBindings.size());
160 vertexInputState.pVertexBindingDescriptions = vertexBindings.data();
161 vertexInputState.vertexAttributeDescriptionCount = static_cast<uint32_t>(vertexAttribs.size());
162 vertexInputState.pVertexAttributeDescriptions = vertexAttribs.data();
163
164 VkPipelineInputAssemblyStateCreateInfo inputAssemblyState;
165 inputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
166 inputAssemblyState.pNext = nullptr;
167 inputAssemblyState.flags = 0;
Jamie Madill72106562017-03-24 14:18:50 -0400168 inputAssemblyState.topology = gl_vk::GetPrimitiveTopology(mCurrentDrawMode);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500169 inputAssemblyState.primitiveRestartEnable = VK_FALSE;
170
171 const gl::Rectangle &viewportGL = state.getViewport();
172 VkViewport viewportVk;
173 viewportVk.x = static_cast<float>(viewportGL.x);
174 viewportVk.y = static_cast<float>(viewportGL.y);
175 viewportVk.width = static_cast<float>(viewportGL.width);
176 viewportVk.height = static_cast<float>(viewportGL.height);
177 viewportVk.minDepth = state.getNearPlane();
178 viewportVk.maxDepth = state.getFarPlane();
179
180 // TODO(jmadill): Scissor.
181 VkRect2D scissorVk;
182 scissorVk.offset.x = viewportGL.x;
183 scissorVk.offset.y = viewportGL.y;
184 scissorVk.extent.width = viewportGL.width;
185 scissorVk.extent.height = viewportGL.height;
186
187 VkPipelineViewportStateCreateInfo viewportState;
188 viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
189 viewportState.pNext = nullptr;
190 viewportState.flags = 0;
191 viewportState.viewportCount = 1;
192 viewportState.pViewports = &viewportVk;
193 viewportState.scissorCount = 1;
194 viewportState.pScissors = &scissorVk;
195
196 // TODO(jmadill): Extra rasterizer state features.
197 VkPipelineRasterizationStateCreateInfo rasterState;
198 rasterState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
199 rasterState.pNext = nullptr;
200 rasterState.flags = 0;
201 rasterState.depthClampEnable = VK_FALSE;
202 rasterState.rasterizerDiscardEnable = VK_FALSE;
203 rasterState.polygonMode = VK_POLYGON_MODE_FILL;
204 rasterState.cullMode = gl_vk::GetCullMode(state.getRasterizerState());
205 rasterState.frontFace = gl_vk::GetFrontFace(state.getRasterizerState().frontFace);
206 rasterState.depthBiasEnable = VK_FALSE;
207 rasterState.depthBiasConstantFactor = 0.0f;
208 rasterState.depthBiasClamp = 0.0f;
209 rasterState.depthBiasSlopeFactor = 0.0f;
210 rasterState.lineWidth = state.getLineWidth();
211
212 // TODO(jmadill): Multisample state.
213 VkPipelineMultisampleStateCreateInfo multisampleState;
214 multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
215 multisampleState.pNext = nullptr;
216 multisampleState.flags = 0;
Jamie Madill72106562017-03-24 14:18:50 -0400217 multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
218 multisampleState.sampleShadingEnable = VK_FALSE;
219 multisampleState.minSampleShading = 0.0f;
220 multisampleState.pSampleMask = nullptr;
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500221 multisampleState.alphaToCoverageEnable = VK_FALSE;
222 multisampleState.alphaToOneEnable = VK_FALSE;
223
224 // TODO(jmadill): Depth/stencil state.
225
226 // TODO(jmadill): Blend state/MRT.
227 VkPipelineColorBlendAttachmentState blendAttachmentState;
228 blendAttachmentState.blendEnable = VK_FALSE;
229 blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
230 blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
231 blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD;
232 blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
233 blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
234 blendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD;
235 blendAttachmentState.colorWriteMask = (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
236 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT);
237
238 VkPipelineColorBlendStateCreateInfo blendState;
239 blendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
240 blendState.pNext = 0;
241 blendState.flags = 0;
242 blendState.logicOpEnable = VK_FALSE;
243 blendState.logicOp = VK_LOGIC_OP_CLEAR;
244 blendState.attachmentCount = 1;
245 blendState.pAttachments = &blendAttachmentState;
246 blendState.blendConstants[0] = 0.0f;
247 blendState.blendConstants[1] = 0.0f;
248 blendState.blendConstants[2] = 0.0f;
249 blendState.blendConstants[3] = 0.0f;
250
251 // TODO(jmadill): Dynamic state.
252 vk::RenderPass *renderPass = nullptr;
Jamie Madill4928b7c2017-06-20 12:57:39 -0400253 ANGLE_TRY_RESULT(vkFBO->getRenderPass(context, device), renderPass);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500254 ASSERT(renderPass && renderPass->valid());
255
256 vk::PipelineLayout *pipelineLayout = nullptr;
257 ANGLE_TRY_RESULT(programVk->getPipelineLayout(device), pipelineLayout);
258 ASSERT(pipelineLayout && pipelineLayout->valid());
259
260 VkGraphicsPipelineCreateInfo pipelineInfo;
261 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
262 pipelineInfo.pNext = nullptr;
263 pipelineInfo.flags = 0;
264 pipelineInfo.stageCount = 2;
265 pipelineInfo.pStages = shaderStages;
266 pipelineInfo.pVertexInputState = &vertexInputState;
267 pipelineInfo.pInputAssemblyState = &inputAssemblyState;
268 pipelineInfo.pTessellationState = nullptr;
269 pipelineInfo.pViewportState = &viewportState;
270 pipelineInfo.pRasterizationState = &rasterState;
271 pipelineInfo.pMultisampleState = &multisampleState;
272 pipelineInfo.pDepthStencilState = nullptr;
273 pipelineInfo.pColorBlendState = &blendState;
274 pipelineInfo.pDynamicState = nullptr;
275 pipelineInfo.layout = pipelineLayout->getHandle();
276 pipelineInfo.renderPass = renderPass->getHandle();
277 pipelineInfo.subpass = 0;
278 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
279 pipelineInfo.basePipelineIndex = 0;
280
Jamie Madill5deea722017-02-16 10:44:46 -0500281 vk::Pipeline newPipeline;
282 ANGLE_TRY(newPipeline.initGraphics(device, pipelineInfo));
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500283
Jamie Madill5deea722017-02-16 10:44:46 -0500284 mCurrentPipeline.retain(device, std::move(newPipeline));
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500285
Jamie Madill72106562017-03-24 14:18:50 -0400286 return gl::NoError();
287}
288
Jamie Madilld03a8492017-10-03 15:46:06 -0400289gl::Error ContextVk::setupDraw(const gl::Context *context, GLenum mode)
Jamie Madill72106562017-03-24 14:18:50 -0400290{
291 if (mode != mCurrentDrawMode)
292 {
293 invalidateCurrentPipeline();
294 mCurrentDrawMode = mode;
295 }
296
297 if (!mCurrentPipeline.valid())
298 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400299 ANGLE_TRY(initPipeline(context));
Jamie Madill72106562017-03-24 14:18:50 -0400300 ASSERT(mCurrentPipeline.valid());
301 }
302
303 VkDevice device = mRenderer->getDevice();
304 const auto &state = mState.getState();
305 const auto &programGL = state.getProgram();
306 const auto &vao = state.getVertexArray();
Jamie Madillbd159f02017-10-09 19:39:06 -0400307 VertexArrayVk *vkVAO = GetImplAs<VertexArrayVk>(vao);
Jamie Madill72106562017-03-24 14:18:50 -0400308 const auto *drawFBO = state.getDrawFramebuffer();
309 FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO);
310 Serial queueSerial = mRenderer->getCurrentQueueSerial();
Jamie Madillbd159f02017-10-09 19:39:06 -0400311 uint32_t maxAttrib = programGL->getState().getMaxActiveAttribLocation();
Jamie Madill72106562017-03-24 14:18:50 -0400312
Jamie Madillbd159f02017-10-09 19:39:06 -0400313 // Process vertex attributes. Assume zero offsets for now.
314 // TODO(jmadill): Offset handling.
315 const std::vector<VkBuffer> &vertexHandles = vkVAO->getCurrentVertexBufferHandlesCache();
316 angle::MemoryBuffer *zeroBuf = nullptr;
317 ANGLE_TRY(context->getZeroFilledBuffer(maxAttrib * sizeof(VkDeviceSize), &zeroBuf));
Jamie Madill72106562017-03-24 14:18:50 -0400318
Jamie Madill0c0dc342017-03-24 14:18:51 -0400319 vk::CommandBuffer *commandBuffer = nullptr;
320 ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer));
Jamie Madilld4826152017-09-21 11:18:59 -0400321 ANGLE_TRY(vkFBO->ensureInRenderPass(context, device, commandBuffer, queueSerial, state));
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500322
323 commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline);
Jamie Madillbd159f02017-10-09 19:39:06 -0400324 commandBuffer->bindVertexBuffers(0, maxAttrib, vertexHandles.data(),
325 reinterpret_cast<const VkDeviceSize *>(zeroBuf->data()));
326
Jamie Madillabd31352017-09-19 00:24:58 -0400327 // TODO(jmadill): the queue serial should be bound to the pipeline.
328 setQueueSerial(queueSerial);
Jamie Madillbd159f02017-10-09 19:39:06 -0400329 vkVAO->updateCurrentBufferSerials(programGL->getActiveAttribLocationsMask(), queueSerial);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500330
331 return gl::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400332}
333
Jamie Madilld03a8492017-10-03 15:46:06 -0400334gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count)
335{
336 ANGLE_TRY(setupDraw(context, mode));
337
338 vk::CommandBuffer *commandBuffer = nullptr;
339 ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer));
340
341 commandBuffer->draw(count, 1, first, 0);
342 return gl::NoError();
343}
344
Jamie Madillc564c072017-06-01 12:45:42 -0400345gl::Error ContextVk::drawArraysInstanced(const gl::Context *context,
346 GLenum mode,
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400347 GLint first,
348 GLsizei count,
349 GLsizei instanceCount)
350{
351 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500352 return gl::InternalError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400353}
354
Jamie Madillc564c072017-06-01 12:45:42 -0400355gl::Error ContextVk::drawElements(const gl::Context *context,
356 GLenum mode,
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400357 GLsizei count,
358 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800359 const void *indices)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400360{
Jamie Madilld03a8492017-10-03 15:46:06 -0400361 ANGLE_TRY(setupDraw(context, mode));
362
363 if (indices)
364 {
365 // TODO(jmadill): Buffer offsets and immediate data.
366 UNIMPLEMENTED();
367 return gl::InternalError() << "Only zero-offset index buffers are currently implemented.";
368 }
369
370 if (type == GL_UNSIGNED_BYTE)
371 {
372 // TODO(jmadill): Index translation.
373 UNIMPLEMENTED();
374 return gl::InternalError() << "Unsigned byte translation is not yet implemented.";
375 }
376
377 vk::CommandBuffer *commandBuffer = nullptr;
378 ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer));
379
380 const gl::Buffer *elementArrayBuffer =
381 mState.getState().getVertexArray()->getElementArrayBuffer().get();
382 ASSERT(elementArrayBuffer);
383
384 BufferVk *elementArrayBufferVk = GetImplAs<BufferVk>(elementArrayBuffer);
385
386 commandBuffer->bindIndexBuffer(elementArrayBufferVk->getVkBuffer(), 0, GetVkIndexType(type));
387 commandBuffer->drawIndexed(count, 1, 0, 0, 0);
388
389 return gl::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400390}
391
Jamie Madillc564c072017-06-01 12:45:42 -0400392gl::Error ContextVk::drawElementsInstanced(const gl::Context *context,
393 GLenum mode,
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400394 GLsizei count,
395 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -0400396 const void *indices,
Qin Jiajia1da00652017-06-20 17:16:25 +0800397 GLsizei instances)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400398{
399 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500400 return gl::InternalError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400401}
402
Jamie Madillc564c072017-06-01 12:45:42 -0400403gl::Error ContextVk::drawRangeElements(const gl::Context *context,
404 GLenum mode,
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400405 GLuint start,
406 GLuint end,
407 GLsizei count,
408 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800409 const void *indices)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400410{
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500411 return gl::NoError();
412}
413
414VkDevice ContextVk::getDevice() const
415{
416 return mRenderer->getDevice();
417}
418
Jamie Madill0c0dc342017-03-24 14:18:51 -0400419vk::Error ContextVk::getStartedCommandBuffer(vk::CommandBuffer **commandBufferOut)
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500420{
Jamie Madill0c0dc342017-03-24 14:18:51 -0400421 return mRenderer->getStartedCommandBuffer(commandBufferOut);
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500422}
423
Jamie Madill0c0dc342017-03-24 14:18:51 -0400424vk::Error ContextVk::submitCommands(vk::CommandBuffer *commandBuffer)
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500425{
Jamie Madill72106562017-03-24 14:18:50 -0400426 setQueueSerial(mRenderer->getCurrentQueueSerial());
Jamie Madillf651c772017-02-21 15:03:51 -0500427 ANGLE_TRY(mRenderer->submitCommandBuffer(commandBuffer));
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500428 return vk::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400429}
430
Jamie Madillc564c072017-06-01 12:45:42 -0400431gl::Error ContextVk::drawArraysIndirect(const gl::Context *context,
432 GLenum mode,
433 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800434{
435 UNIMPLEMENTED();
436 return gl::InternalError() << "DrawArraysIndirect hasn't been implemented for vulkan backend.";
437}
438
Jamie Madillc564c072017-06-01 12:45:42 -0400439gl::Error ContextVk::drawElementsIndirect(const gl::Context *context,
440 GLenum mode,
441 GLenum type,
442 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800443{
444 UNIMPLEMENTED();
445 return gl::InternalError()
446 << "DrawElementsIndirect hasn't been implemented for vulkan backend.";
447}
448
Corentin Wallez87fbe1c2016-08-03 14:41:42 -0400449GLenum ContextVk::getResetStatus()
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400450{
451 UNIMPLEMENTED();
Corentin Wallez87fbe1c2016-08-03 14:41:42 -0400452 return GL_NO_ERROR;
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400453}
454
455std::string ContextVk::getVendorString() const
456{
457 UNIMPLEMENTED();
458 return std::string();
459}
460
461std::string ContextVk::getRendererDescription() const
462{
Jamie Madille09bd5d2016-11-29 16:20:35 -0500463 return mRenderer->getRendererDescription();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400464}
465
466void ContextVk::insertEventMarker(GLsizei length, const char *marker)
467{
468 UNIMPLEMENTED();
469}
470
471void ContextVk::pushGroupMarker(GLsizei length, const char *marker)
472{
473 UNIMPLEMENTED();
474}
475
476void ContextVk::popGroupMarker()
477{
478 UNIMPLEMENTED();
479}
480
Jamie Madillfe548342017-06-19 11:13:24 -0400481void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400482{
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500483 // TODO(jmadill): Vulkan dirty bits.
Jamie Madill72106562017-03-24 14:18:50 -0400484 if (dirtyBits.any())
485 {
486 invalidateCurrentPipeline();
487 }
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400488}
489
490GLint ContextVk::getGPUDisjoint()
491{
492 UNIMPLEMENTED();
493 return GLint();
494}
495
496GLint64 ContextVk::getTimestamp()
497{
498 UNIMPLEMENTED();
499 return GLint64();
500}
501
Jamie Madill4928b7c2017-06-20 12:57:39 -0400502void ContextVk::onMakeCurrent(const gl::Context * /*context*/)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400503{
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400504}
505
506const gl::Caps &ContextVk::getNativeCaps() const
507{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400508 return mRenderer->getNativeCaps();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400509}
510
511const gl::TextureCapsMap &ContextVk::getNativeTextureCaps() const
512{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400513 return mRenderer->getNativeTextureCaps();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400514}
515
516const gl::Extensions &ContextVk::getNativeExtensions() const
517{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400518 return mRenderer->getNativeExtensions();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400519}
520
521const gl::Limitations &ContextVk::getNativeLimitations() const
522{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400523 return mRenderer->getNativeLimitations();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400524}
525
526CompilerImpl *ContextVk::createCompiler()
527{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400528 return new CompilerVk();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400529}
530
Jamie Madillacccc6c2016-05-03 17:22:10 -0400531ShaderImpl *ContextVk::createShader(const gl::ShaderState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400532{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400533 return new ShaderVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400534}
535
Jamie Madillacccc6c2016-05-03 17:22:10 -0400536ProgramImpl *ContextVk::createProgram(const gl::ProgramState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400537{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400538 return new ProgramVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400539}
540
Jamie Madillacccc6c2016-05-03 17:22:10 -0400541FramebufferImpl *ContextVk::createFramebuffer(const gl::FramebufferState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400542{
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500543 return FramebufferVk::CreateUserFBO(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400544}
545
546TextureImpl *ContextVk::createTexture(const gl::TextureState &state)
547{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400548 return new TextureVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400549}
550
551RenderbufferImpl *ContextVk::createRenderbuffer()
552{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400553 return new RenderbufferVk();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400554}
555
Jamie Madill8f775602016-11-03 16:45:34 -0400556BufferImpl *ContextVk::createBuffer(const gl::BufferState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400557{
Jamie Madill8f775602016-11-03 16:45:34 -0400558 return new BufferVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400559}
560
Jamie Madillacccc6c2016-05-03 17:22:10 -0400561VertexArrayImpl *ContextVk::createVertexArray(const gl::VertexArrayState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400562{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400563 return new VertexArrayVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400564}
565
566QueryImpl *ContextVk::createQuery(GLenum type)
567{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400568 return new QueryVk(type);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400569}
570
571FenceNVImpl *ContextVk::createFenceNV()
572{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400573 return new FenceNVVk();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400574}
575
Jamie Madill70b5bb02017-08-28 13:32:37 -0400576SyncImpl *ContextVk::createSync()
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400577{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400578 return new SyncVk();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400579}
580
Geoff Lang73bd2182016-07-15 13:01:24 -0400581TransformFeedbackImpl *ContextVk::createTransformFeedback(const gl::TransformFeedbackState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400582{
Geoff Lang73bd2182016-07-15 13:01:24 -0400583 return new TransformFeedbackVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400584}
585
Jamie Madill06ef36b2017-09-09 23:32:46 -0400586SamplerImpl *ContextVk::createSampler(const gl::SamplerState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400587{
Jamie Madill06ef36b2017-09-09 23:32:46 -0400588 return new SamplerVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400589}
590
Yunchao Hea336b902017-08-02 16:05:21 +0800591ProgramPipelineImpl *ContextVk::createProgramPipeline(const gl::ProgramPipelineState &state)
592{
593 return new ProgramPipelineVk(state);
594}
595
Sami Väisänene45e53b2016-05-25 10:36:04 +0300596std::vector<PathImpl *> ContextVk::createPaths(GLsizei)
597{
598 return std::vector<PathImpl *>();
599}
600
Jamie Madill72106562017-03-24 14:18:50 -0400601// TODO(jmadill): Use pipeline cache.
602void ContextVk::invalidateCurrentPipeline()
603{
604 mRenderer->enqueueGarbageOrDeleteNow(*this, mCurrentPipeline);
605}
606
Jamie Madillfe548342017-06-19 11:13:24 -0400607gl::Error ContextVk::dispatchCompute(const gl::Context *context,
608 GLuint numGroupsX,
609 GLuint numGroupsY,
610 GLuint numGroupsZ)
Xinghua Cao2b396592017-03-29 15:36:04 +0800611{
612 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500613 return gl::InternalError();
Xinghua Cao2b396592017-03-29 15:36:04 +0800614}
615
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400616} // namespace rx