blob: 6bbfd9b509c947f196bc45617600a767e8ce1c7b [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 Madilldf68a6f2017-01-13 17:29:53 -050014#include "libANGLE/Program.h"
Jamie Madillacccc6c2016-05-03 17:22:10 -040015#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 Madillacccc6c2016-05-03 17:22:10 -040020#include "libANGLE/renderer/vulkan/FramebufferVk.h"
21#include "libANGLE/renderer/vulkan/ImageVk.h"
Yunchao Hea336b902017-08-02 16:05:21 +080022#include "libANGLE/renderer/vulkan/ProgramPipelineVk.h"
Jamie Madillacccc6c2016-05-03 17:22:10 -040023#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 Madill70b5bb02017-08-28 13:32:37 -040029#include "libANGLE/renderer/vulkan/SyncVk.h"
Jamie Madillacccc6c2016-05-03 17:22:10 -040030#include "libANGLE/renderer/vulkan/TextureVk.h"
31#include "libANGLE/renderer/vulkan/TransformFeedbackVk.h"
32#include "libANGLE/renderer/vulkan/VertexArrayVk.h"
Jamie Madilldf68a6f2017-01-13 17:29:53 -050033#include "libANGLE/renderer/vulkan/formatutilsvk.h"
Jamie Madill9e54b5a2016-05-25 12:57:39 -040034
35namespace rx
36{
37
Jamie Madilld03a8492017-10-03 15:46:06 -040038namespace
39{
40
41VkIndexType GetVkIndexType(GLenum glIndexType)
42{
43 switch (glIndexType)
44 {
45 case GL_UNSIGNED_SHORT:
46 return VK_INDEX_TYPE_UINT16;
47 case GL_UNSIGNED_INT:
48 return VK_INDEX_TYPE_UINT32;
49 default:
50 UNREACHABLE();
51 return VK_INDEX_TYPE_MAX_ENUM;
52 }
53}
54
55} // anonymous namespace
56
Jamie Madillacccc6c2016-05-03 17:22:10 -040057ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer)
Jamie Madill72106562017-03-24 14:18:50 -040058 : ContextImpl(state), mRenderer(renderer), mCurrentDrawMode(GL_NONE)
Jamie Madill9e54b5a2016-05-25 12:57:39 -040059{
60}
61
62ContextVk::~ContextVk()
63{
Jamie Madill72106562017-03-24 14:18:50 -040064 invalidateCurrentPipeline();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040065}
66
67gl::Error ContextVk::initialize()
68{
Jamie Madille09bd5d2016-11-29 16:20:35 -050069 return gl::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040070}
71
72gl::Error ContextVk::flush()
73{
74 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -050075 return gl::InternalError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040076}
77
78gl::Error ContextVk::finish()
79{
80 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -050081 return gl::InternalError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040082}
83
Jamie Madill4928b7c2017-06-20 12:57:39 -040084gl::Error ContextVk::initPipeline(const gl::Context *context)
Jamie Madill9e54b5a2016-05-25 12:57:39 -040085{
Jamie Madill72106562017-03-24 14:18:50 -040086 ASSERT(!mCurrentPipeline.valid());
87
Jamie Madilldf68a6f2017-01-13 17:29:53 -050088 VkDevice device = mRenderer->getDevice();
89 const auto &state = mState.getState();
90 const auto &programGL = state.getProgram();
91 const auto &vao = state.getVertexArray();
92 const auto &attribs = vao->getVertexAttributes();
Jiawei-Shao2597fb62016-12-09 16:38:02 +080093 const auto &bindings = vao->getVertexBindings();
Jamie Madilldf68a6f2017-01-13 17:29:53 -050094 const auto &programVk = GetImplAs<ProgramVk>(programGL);
95 const auto *drawFBO = state.getDrawFramebuffer();
96 FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO);
97
98 // { vertex, fragment }
99 VkPipelineShaderStageCreateInfo shaderStages[2];
100
101 shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
102 shaderStages[0].pNext = nullptr;
103 shaderStages[0].flags = 0;
104 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
105 shaderStages[0].module = programVk->getLinkedVertexModule().getHandle();
106 shaderStages[0].pName = "main";
107 shaderStages[0].pSpecializationInfo = nullptr;
108
109 shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
110 shaderStages[1].pNext = nullptr;
111 shaderStages[1].flags = 0;
112 shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
113 shaderStages[1].module = programVk->getLinkedFragmentModule().getHandle();
114 shaderStages[1].pName = "main";
115 shaderStages[1].pSpecializationInfo = nullptr;
116
117 // Process vertex attributes
118 // TODO(jmadill): Caching with dirty bits.
119 std::vector<VkVertexInputBindingDescription> vertexBindings;
120 std::vector<VkVertexInputAttributeDescription> vertexAttribs;
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500121
Jamie Madill6de51852017-04-12 09:53:01 -0400122 for (auto attribIndex : programGL->getActiveAttribLocationsMask())
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500123 {
Jamie Madill231c7f52017-04-26 13:45:37 -0400124 const auto &attrib = attribs[attribIndex];
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800125 const auto &binding = bindings[attrib.bindingIndex];
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500126 if (attrib.enabled)
127 {
128 VkVertexInputBindingDescription bindingDesc;
129 bindingDesc.binding = static_cast<uint32_t>(vertexBindings.size());
130 bindingDesc.stride = static_cast<uint32_t>(gl::ComputeVertexAttributeTypeSize(attrib));
Martin Radevdd5f27e2017-06-07 10:17:09 +0300131 bindingDesc.inputRate = (binding.getDivisor() > 0 ? VK_VERTEX_INPUT_RATE_INSTANCE
132 : VK_VERTEX_INPUT_RATE_VERTEX);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500133
134 gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib);
135
136 VkVertexInputAttributeDescription attribDesc;
137 attribDesc.binding = bindingDesc.binding;
138 attribDesc.format = vk::GetNativeVertexFormat(vertexFormatType);
139 attribDesc.location = static_cast<uint32_t>(attribIndex);
Jiawei-Shao2597fb62016-12-09 16:38:02 +0800140 attribDesc.offset =
141 static_cast<uint32_t>(ComputeVertexAttributeOffset(attrib, binding));
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500142
143 vertexBindings.push_back(bindingDesc);
144 vertexAttribs.push_back(attribDesc);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500145 }
146 else
147 {
148 UNIMPLEMENTED();
149 }
150 }
151
152 // TODO(jmadill): Validate with ASSERT against physical device limits/caps?
153 VkPipelineVertexInputStateCreateInfo vertexInputState;
154 vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
155 vertexInputState.pNext = nullptr;
156 vertexInputState.flags = 0;
157 vertexInputState.vertexBindingDescriptionCount = static_cast<uint32_t>(vertexBindings.size());
158 vertexInputState.pVertexBindingDescriptions = vertexBindings.data();
159 vertexInputState.vertexAttributeDescriptionCount = static_cast<uint32_t>(vertexAttribs.size());
160 vertexInputState.pVertexAttributeDescriptions = vertexAttribs.data();
161
162 VkPipelineInputAssemblyStateCreateInfo inputAssemblyState;
163 inputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
164 inputAssemblyState.pNext = nullptr;
165 inputAssemblyState.flags = 0;
Jamie Madill72106562017-03-24 14:18:50 -0400166 inputAssemblyState.topology = gl_vk::GetPrimitiveTopology(mCurrentDrawMode);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500167 inputAssemblyState.primitiveRestartEnable = VK_FALSE;
168
169 const gl::Rectangle &viewportGL = state.getViewport();
170 VkViewport viewportVk;
171 viewportVk.x = static_cast<float>(viewportGL.x);
172 viewportVk.y = static_cast<float>(viewportGL.y);
173 viewportVk.width = static_cast<float>(viewportGL.width);
174 viewportVk.height = static_cast<float>(viewportGL.height);
175 viewportVk.minDepth = state.getNearPlane();
176 viewportVk.maxDepth = state.getFarPlane();
177
178 // TODO(jmadill): Scissor.
179 VkRect2D scissorVk;
180 scissorVk.offset.x = viewportGL.x;
181 scissorVk.offset.y = viewportGL.y;
182 scissorVk.extent.width = viewportGL.width;
183 scissorVk.extent.height = viewportGL.height;
184
185 VkPipelineViewportStateCreateInfo viewportState;
186 viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
187 viewportState.pNext = nullptr;
188 viewportState.flags = 0;
189 viewportState.viewportCount = 1;
190 viewportState.pViewports = &viewportVk;
191 viewportState.scissorCount = 1;
192 viewportState.pScissors = &scissorVk;
193
194 // TODO(jmadill): Extra rasterizer state features.
195 VkPipelineRasterizationStateCreateInfo rasterState;
196 rasterState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
197 rasterState.pNext = nullptr;
198 rasterState.flags = 0;
199 rasterState.depthClampEnable = VK_FALSE;
200 rasterState.rasterizerDiscardEnable = VK_FALSE;
201 rasterState.polygonMode = VK_POLYGON_MODE_FILL;
202 rasterState.cullMode = gl_vk::GetCullMode(state.getRasterizerState());
203 rasterState.frontFace = gl_vk::GetFrontFace(state.getRasterizerState().frontFace);
204 rasterState.depthBiasEnable = VK_FALSE;
205 rasterState.depthBiasConstantFactor = 0.0f;
206 rasterState.depthBiasClamp = 0.0f;
207 rasterState.depthBiasSlopeFactor = 0.0f;
208 rasterState.lineWidth = state.getLineWidth();
209
210 // TODO(jmadill): Multisample state.
211 VkPipelineMultisampleStateCreateInfo multisampleState;
212 multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
213 multisampleState.pNext = nullptr;
214 multisampleState.flags = 0;
Jamie Madill72106562017-03-24 14:18:50 -0400215 multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
216 multisampleState.sampleShadingEnable = VK_FALSE;
217 multisampleState.minSampleShading = 0.0f;
218 multisampleState.pSampleMask = nullptr;
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500219 multisampleState.alphaToCoverageEnable = VK_FALSE;
220 multisampleState.alphaToOneEnable = VK_FALSE;
221
222 // TODO(jmadill): Depth/stencil state.
223
224 // TODO(jmadill): Blend state/MRT.
225 VkPipelineColorBlendAttachmentState blendAttachmentState;
226 blendAttachmentState.blendEnable = VK_FALSE;
227 blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
228 blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
229 blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD;
230 blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
231 blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
232 blendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD;
233 blendAttachmentState.colorWriteMask = (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
234 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT);
235
236 VkPipelineColorBlendStateCreateInfo blendState;
237 blendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
238 blendState.pNext = 0;
239 blendState.flags = 0;
240 blendState.logicOpEnable = VK_FALSE;
241 blendState.logicOp = VK_LOGIC_OP_CLEAR;
242 blendState.attachmentCount = 1;
243 blendState.pAttachments = &blendAttachmentState;
244 blendState.blendConstants[0] = 0.0f;
245 blendState.blendConstants[1] = 0.0f;
246 blendState.blendConstants[2] = 0.0f;
247 blendState.blendConstants[3] = 0.0f;
248
249 // TODO(jmadill): Dynamic state.
250 vk::RenderPass *renderPass = nullptr;
Jamie Madill4928b7c2017-06-20 12:57:39 -0400251 ANGLE_TRY_RESULT(vkFBO->getRenderPass(context, device), renderPass);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500252 ASSERT(renderPass && renderPass->valid());
253
254 vk::PipelineLayout *pipelineLayout = nullptr;
255 ANGLE_TRY_RESULT(programVk->getPipelineLayout(device), pipelineLayout);
256 ASSERT(pipelineLayout && pipelineLayout->valid());
257
258 VkGraphicsPipelineCreateInfo pipelineInfo;
259 pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
260 pipelineInfo.pNext = nullptr;
261 pipelineInfo.flags = 0;
262 pipelineInfo.stageCount = 2;
263 pipelineInfo.pStages = shaderStages;
264 pipelineInfo.pVertexInputState = &vertexInputState;
265 pipelineInfo.pInputAssemblyState = &inputAssemblyState;
266 pipelineInfo.pTessellationState = nullptr;
267 pipelineInfo.pViewportState = &viewportState;
268 pipelineInfo.pRasterizationState = &rasterState;
269 pipelineInfo.pMultisampleState = &multisampleState;
270 pipelineInfo.pDepthStencilState = nullptr;
271 pipelineInfo.pColorBlendState = &blendState;
272 pipelineInfo.pDynamicState = nullptr;
273 pipelineInfo.layout = pipelineLayout->getHandle();
274 pipelineInfo.renderPass = renderPass->getHandle();
275 pipelineInfo.subpass = 0;
276 pipelineInfo.basePipelineHandle = VK_NULL_HANDLE;
277 pipelineInfo.basePipelineIndex = 0;
278
Jamie Madill5deea722017-02-16 10:44:46 -0500279 vk::Pipeline newPipeline;
280 ANGLE_TRY(newPipeline.initGraphics(device, pipelineInfo));
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500281
Jamie Madill5deea722017-02-16 10:44:46 -0500282 mCurrentPipeline.retain(device, std::move(newPipeline));
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500283
Jamie Madill72106562017-03-24 14:18:50 -0400284 return gl::NoError();
285}
286
Jamie Madilld03a8492017-10-03 15:46:06 -0400287gl::Error ContextVk::setupDraw(const gl::Context *context, GLenum mode)
Jamie Madill72106562017-03-24 14:18:50 -0400288{
289 if (mode != mCurrentDrawMode)
290 {
291 invalidateCurrentPipeline();
292 mCurrentDrawMode = mode;
293 }
294
295 if (!mCurrentPipeline.valid())
296 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400297 ANGLE_TRY(initPipeline(context));
Jamie Madill72106562017-03-24 14:18:50 -0400298 ASSERT(mCurrentPipeline.valid());
299 }
300
301 VkDevice device = mRenderer->getDevice();
302 const auto &state = mState.getState();
303 const auto &programGL = state.getProgram();
304 const auto &vao = state.getVertexArray();
305 const auto &attribs = vao->getVertexAttributes();
306 const auto &bindings = vao->getVertexBindings();
307 const auto *drawFBO = state.getDrawFramebuffer();
308 FramebufferVk *vkFBO = GetImplAs<FramebufferVk>(drawFBO);
309 Serial queueSerial = mRenderer->getCurrentQueueSerial();
310
311 // Process vertex attributes
312 // TODO(jmadill): Caching with dirty bits.
313 std::vector<VkBuffer> vertexHandles;
314 std::vector<VkDeviceSize> vertexOffsets;
315
Jamie Madill6de51852017-04-12 09:53:01 -0400316 for (auto attribIndex : programGL->getActiveAttribLocationsMask())
Jamie Madill72106562017-03-24 14:18:50 -0400317 {
318 const auto &attrib = attribs[attribIndex];
319 const auto &binding = bindings[attrib.bindingIndex];
320 if (attrib.enabled)
321 {
322 // TODO(jmadill): Offset handling.
Martin Radevdd5f27e2017-06-07 10:17:09 +0300323 gl::Buffer *bufferGL = binding.getBuffer().get();
Jamie Madill72106562017-03-24 14:18:50 -0400324 ASSERT(bufferGL);
325 BufferVk *bufferVk = GetImplAs<BufferVk>(bufferGL);
326 vertexHandles.push_back(bufferVk->getVkBuffer().getHandle());
327 vertexOffsets.push_back(0);
328
329 bufferVk->setQueueSerial(queueSerial);
330 }
331 else
332 {
333 UNIMPLEMENTED();
334 }
335 }
336
Jamie Madill0c0dc342017-03-24 14:18:51 -0400337 vk::CommandBuffer *commandBuffer = nullptr;
338 ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer));
Jamie Madilld4826152017-09-21 11:18:59 -0400339 ANGLE_TRY(vkFBO->ensureInRenderPass(context, device, commandBuffer, queueSerial, state));
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500340
341 commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline);
Jamie Madillabd31352017-09-19 00:24:58 -0400342 // TODO(jmadill): the queue serial should be bound to the pipeline.
343 setQueueSerial(queueSerial);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500344 commandBuffer->bindVertexBuffers(0, vertexHandles, vertexOffsets);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500345
346 return gl::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400347}
348
Jamie Madilld03a8492017-10-03 15:46:06 -0400349gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count)
350{
351 ANGLE_TRY(setupDraw(context, mode));
352
353 vk::CommandBuffer *commandBuffer = nullptr;
354 ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer));
355
356 commandBuffer->draw(count, 1, first, 0);
357 return gl::NoError();
358}
359
Jamie Madillc564c072017-06-01 12:45:42 -0400360gl::Error ContextVk::drawArraysInstanced(const gl::Context *context,
361 GLenum mode,
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400362 GLint first,
363 GLsizei count,
364 GLsizei instanceCount)
365{
366 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500367 return gl::InternalError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400368}
369
Jamie Madillc564c072017-06-01 12:45:42 -0400370gl::Error ContextVk::drawElements(const gl::Context *context,
371 GLenum mode,
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400372 GLsizei count,
373 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800374 const void *indices)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400375{
Jamie Madilld03a8492017-10-03 15:46:06 -0400376 ANGLE_TRY(setupDraw(context, mode));
377
378 if (indices)
379 {
380 // TODO(jmadill): Buffer offsets and immediate data.
381 UNIMPLEMENTED();
382 return gl::InternalError() << "Only zero-offset index buffers are currently implemented.";
383 }
384
385 if (type == GL_UNSIGNED_BYTE)
386 {
387 // TODO(jmadill): Index translation.
388 UNIMPLEMENTED();
389 return gl::InternalError() << "Unsigned byte translation is not yet implemented.";
390 }
391
392 vk::CommandBuffer *commandBuffer = nullptr;
393 ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer));
394
395 const gl::Buffer *elementArrayBuffer =
396 mState.getState().getVertexArray()->getElementArrayBuffer().get();
397 ASSERT(elementArrayBuffer);
398
399 BufferVk *elementArrayBufferVk = GetImplAs<BufferVk>(elementArrayBuffer);
400
401 commandBuffer->bindIndexBuffer(elementArrayBufferVk->getVkBuffer(), 0, GetVkIndexType(type));
402 commandBuffer->drawIndexed(count, 1, 0, 0, 0);
403
404 return gl::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400405}
406
Jamie Madillc564c072017-06-01 12:45:42 -0400407gl::Error ContextVk::drawElementsInstanced(const gl::Context *context,
408 GLenum mode,
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400409 GLsizei count,
410 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -0400411 const void *indices,
Qin Jiajia1da00652017-06-20 17:16:25 +0800412 GLsizei instances)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400413{
414 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500415 return gl::InternalError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400416}
417
Jamie Madillc564c072017-06-01 12:45:42 -0400418gl::Error ContextVk::drawRangeElements(const gl::Context *context,
419 GLenum mode,
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400420 GLuint start,
421 GLuint end,
422 GLsizei count,
423 GLenum type,
Qin Jiajia1da00652017-06-20 17:16:25 +0800424 const void *indices)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400425{
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500426 return gl::NoError();
427}
428
429VkDevice ContextVk::getDevice() const
430{
431 return mRenderer->getDevice();
432}
433
Jamie Madill0c0dc342017-03-24 14:18:51 -0400434vk::Error ContextVk::getStartedCommandBuffer(vk::CommandBuffer **commandBufferOut)
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500435{
Jamie Madill0c0dc342017-03-24 14:18:51 -0400436 return mRenderer->getStartedCommandBuffer(commandBufferOut);
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500437}
438
Jamie Madill0c0dc342017-03-24 14:18:51 -0400439vk::Error ContextVk::submitCommands(vk::CommandBuffer *commandBuffer)
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500440{
Jamie Madill72106562017-03-24 14:18:50 -0400441 setQueueSerial(mRenderer->getCurrentQueueSerial());
Jamie Madillf651c772017-02-21 15:03:51 -0500442 ANGLE_TRY(mRenderer->submitCommandBuffer(commandBuffer));
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500443 return vk::NoError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400444}
445
Jamie Madillc564c072017-06-01 12:45:42 -0400446gl::Error ContextVk::drawArraysIndirect(const gl::Context *context,
447 GLenum mode,
448 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800449{
450 UNIMPLEMENTED();
451 return gl::InternalError() << "DrawArraysIndirect hasn't been implemented for vulkan backend.";
452}
453
Jamie Madillc564c072017-06-01 12:45:42 -0400454gl::Error ContextVk::drawElementsIndirect(const gl::Context *context,
455 GLenum mode,
456 GLenum type,
457 const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +0800458{
459 UNIMPLEMENTED();
460 return gl::InternalError()
461 << "DrawElementsIndirect hasn't been implemented for vulkan backend.";
462}
463
Corentin Wallez87fbe1c2016-08-03 14:41:42 -0400464GLenum ContextVk::getResetStatus()
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400465{
466 UNIMPLEMENTED();
Corentin Wallez87fbe1c2016-08-03 14:41:42 -0400467 return GL_NO_ERROR;
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400468}
469
470std::string ContextVk::getVendorString() const
471{
472 UNIMPLEMENTED();
473 return std::string();
474}
475
476std::string ContextVk::getRendererDescription() const
477{
Jamie Madille09bd5d2016-11-29 16:20:35 -0500478 return mRenderer->getRendererDescription();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400479}
480
481void ContextVk::insertEventMarker(GLsizei length, const char *marker)
482{
483 UNIMPLEMENTED();
484}
485
486void ContextVk::pushGroupMarker(GLsizei length, const char *marker)
487{
488 UNIMPLEMENTED();
489}
490
491void ContextVk::popGroupMarker()
492{
493 UNIMPLEMENTED();
494}
495
Jamie Madillfe548342017-06-19 11:13:24 -0400496void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400497{
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500498 // TODO(jmadill): Vulkan dirty bits.
Jamie Madill72106562017-03-24 14:18:50 -0400499 if (dirtyBits.any())
500 {
501 invalidateCurrentPipeline();
502 }
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400503}
504
505GLint ContextVk::getGPUDisjoint()
506{
507 UNIMPLEMENTED();
508 return GLint();
509}
510
511GLint64 ContextVk::getTimestamp()
512{
513 UNIMPLEMENTED();
514 return GLint64();
515}
516
Jamie Madill4928b7c2017-06-20 12:57:39 -0400517void ContextVk::onMakeCurrent(const gl::Context * /*context*/)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400518{
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400519}
520
521const gl::Caps &ContextVk::getNativeCaps() const
522{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400523 return mRenderer->getNativeCaps();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400524}
525
526const gl::TextureCapsMap &ContextVk::getNativeTextureCaps() const
527{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400528 return mRenderer->getNativeTextureCaps();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400529}
530
531const gl::Extensions &ContextVk::getNativeExtensions() const
532{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400533 return mRenderer->getNativeExtensions();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400534}
535
536const gl::Limitations &ContextVk::getNativeLimitations() const
537{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400538 return mRenderer->getNativeLimitations();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400539}
540
541CompilerImpl *ContextVk::createCompiler()
542{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400543 return new CompilerVk();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400544}
545
Jamie Madillacccc6c2016-05-03 17:22:10 -0400546ShaderImpl *ContextVk::createShader(const gl::ShaderState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400547{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400548 return new ShaderVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400549}
550
Jamie Madillacccc6c2016-05-03 17:22:10 -0400551ProgramImpl *ContextVk::createProgram(const gl::ProgramState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400552{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400553 return new ProgramVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400554}
555
Jamie Madillacccc6c2016-05-03 17:22:10 -0400556FramebufferImpl *ContextVk::createFramebuffer(const gl::FramebufferState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400557{
Jamie Madill7b57b9d2017-01-13 09:33:38 -0500558 return FramebufferVk::CreateUserFBO(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400559}
560
561TextureImpl *ContextVk::createTexture(const gl::TextureState &state)
562{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400563 return new TextureVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400564}
565
566RenderbufferImpl *ContextVk::createRenderbuffer()
567{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400568 return new RenderbufferVk();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400569}
570
Jamie Madill8f775602016-11-03 16:45:34 -0400571BufferImpl *ContextVk::createBuffer(const gl::BufferState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400572{
Jamie Madill8f775602016-11-03 16:45:34 -0400573 return new BufferVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400574}
575
Jamie Madillacccc6c2016-05-03 17:22:10 -0400576VertexArrayImpl *ContextVk::createVertexArray(const gl::VertexArrayState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400577{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400578 return new VertexArrayVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400579}
580
581QueryImpl *ContextVk::createQuery(GLenum type)
582{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400583 return new QueryVk(type);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400584}
585
586FenceNVImpl *ContextVk::createFenceNV()
587{
Jamie Madillacccc6c2016-05-03 17:22:10 -0400588 return new FenceNVVk();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400589}
590
Jamie Madill70b5bb02017-08-28 13:32:37 -0400591SyncImpl *ContextVk::createSync()
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400592{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400593 return new SyncVk();
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400594}
595
Geoff Lang73bd2182016-07-15 13:01:24 -0400596TransformFeedbackImpl *ContextVk::createTransformFeedback(const gl::TransformFeedbackState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400597{
Geoff Lang73bd2182016-07-15 13:01:24 -0400598 return new TransformFeedbackVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400599}
600
Jamie Madill06ef36b2017-09-09 23:32:46 -0400601SamplerImpl *ContextVk::createSampler(const gl::SamplerState &state)
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400602{
Jamie Madill06ef36b2017-09-09 23:32:46 -0400603 return new SamplerVk(state);
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400604}
605
Yunchao Hea336b902017-08-02 16:05:21 +0800606ProgramPipelineImpl *ContextVk::createProgramPipeline(const gl::ProgramPipelineState &state)
607{
608 return new ProgramPipelineVk(state);
609}
610
Sami Väisänene45e53b2016-05-25 10:36:04 +0300611std::vector<PathImpl *> ContextVk::createPaths(GLsizei)
612{
613 return std::vector<PathImpl *>();
614}
615
Jamie Madill72106562017-03-24 14:18:50 -0400616// TODO(jmadill): Use pipeline cache.
617void ContextVk::invalidateCurrentPipeline()
618{
619 mRenderer->enqueueGarbageOrDeleteNow(*this, mCurrentPipeline);
620}
621
Jamie Madillfe548342017-06-19 11:13:24 -0400622gl::Error ContextVk::dispatchCompute(const gl::Context *context,
623 GLuint numGroupsX,
624 GLuint numGroupsY,
625 GLuint numGroupsZ)
Xinghua Cao2b396592017-03-29 15:36:04 +0800626{
627 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500628 return gl::InternalError();
Xinghua Cao2b396592017-03-29 15:36:04 +0800629}
630
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400631} // namespace rx