blob: 3af5de7242cc83524eae71167a6632ce5c3577ce [file] [log] [blame]
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -05001//
2// Copyright 2018 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// DispatchUtilsVk.cpp:
7// Implements the DispatchUtilsVk class.
8//
9
10#include "libANGLE/renderer/vulkan/DispatchUtilsVk.h"
11
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -050012#include "libANGLE/renderer/vulkan/RendererVk.h"
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -050013
14namespace rx
15{
16
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +010017namespace BufferUtils_comp = vk::InternalShader::BufferUtils_comp;
18namespace ConvertVertex_comp = vk::InternalShader::ConvertVertex_comp;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -050019
20namespace
21{
22// All internal shaders assume there is only one descriptor set, indexed at 0
23constexpr uint32_t kSetIndex = 0;
24
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +010025constexpr uint32_t kBufferClearOutputBinding = 0;
26constexpr uint32_t kBufferCopyDestinationBinding = 0;
27constexpr uint32_t kBufferCopySourceBinding = 1;
28constexpr uint32_t kConvertVertexDestinationBinding = 0;
29constexpr uint32_t kConvertVertexSourceBinding = 1;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -050030
31uint32_t GetBufferUtilsFlags(size_t dispatchSize, const vk::Format &format)
32{
33 uint32_t flags = dispatchSize % 64 == 0 ? BufferUtils_comp::kIsAligned : 0;
34 const angle::Format &bufferFormat = format.bufferFormat();
35
36 flags |= bufferFormat.componentType == GL_INT
37 ? BufferUtils_comp::kIsInt
38 : bufferFormat.componentType == GL_UNSIGNED_INT ? BufferUtils_comp::kIsUint
39 : BufferUtils_comp::kIsFloat;
40
41 return flags;
42}
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +010043
44uint32_t GetConvertVertexFlags(const DispatchUtilsVk::ConvertVertexParameters &params)
45{
46 bool srcIsInt = params.srcFormat->componentType == GL_INT;
47 bool srcIsUint = params.srcFormat->componentType == GL_UNSIGNED_INT;
48 bool srcIsSnorm = params.srcFormat->componentType == GL_SIGNED_NORMALIZED;
49 bool srcIsUnorm = params.srcFormat->componentType == GL_UNSIGNED_NORMALIZED;
50 bool srcIsFixed = params.srcFormat->isFixed;
51 bool srcIsFloat = params.srcFormat->componentType == GL_FLOAT;
52
53 bool destIsInt = params.destFormat->componentType == GL_INT;
54 bool destIsUint = params.destFormat->componentType == GL_UNSIGNED_INT;
55 bool destIsFloat = params.destFormat->componentType == GL_FLOAT;
56
57 // Assert on the types to make sure the shader supports its. These are based on
58 // ConvertVertex_comp::Conversion values.
59 ASSERT(!destIsInt || srcIsInt); // If destination is int, src must be int too
60 ASSERT(!destIsUint || srcIsUint); // If destination is uint, src must be uint too
61 ASSERT(!srcIsFixed || destIsFloat); // If source is fixed, dest must be float
62 // One of each bool set must be true
63 ASSERT(srcIsInt || srcIsUint || srcIsSnorm || srcIsUnorm || srcIsFixed || srcIsFloat);
64 ASSERT(destIsInt || destIsUint || destIsFloat);
65
66 // We currently don't have any big-endian devices in the list of supported platforms. The
67 // shader is capable of supporting big-endian architectures, but the relevant flag (IsBigEndian)
68 // is not added to the build configuration file (to reduce binary size). If necessary, add
69 // IsBigEndian to ConvertVertex.comp.json and select the appropriate flag based on the
70 // endian-ness test here.
71 uint32_t endiannessTest = 0;
72 *reinterpret_cast<uint8_t *>(&endiannessTest) = 1;
73 ASSERT(endiannessTest == 1);
74
75 uint32_t flags = 0;
76
77 if (srcIsInt && destIsInt)
78 {
79 flags |= ConvertVertex_comp::kIntToInt;
80 }
81 else if (srcIsUint && destIsUint)
82 {
83 flags |= ConvertVertex_comp::kUintToUint;
84 }
85 else if (srcIsInt)
86 {
87 flags |= ConvertVertex_comp::kIntToFloat;
88 }
89 else if (srcIsUint)
90 {
91 flags |= ConvertVertex_comp::kUintToFloat;
92 }
93 else if (srcIsSnorm)
94 {
95 flags |= ConvertVertex_comp::kSnormToFloat;
96 }
97 else if (srcIsUnorm)
98 {
99 flags |= ConvertVertex_comp::kUnormToFloat;
100 }
101 else if (srcIsFixed)
102 {
103 flags |= ConvertVertex_comp::kFixedToFloat;
104 }
105 else if (srcIsFloat)
106 {
107 flags |= ConvertVertex_comp::kFloatToFloat;
108 }
109 else
110 {
111 UNREACHABLE();
112 }
113
114 return flags;
115}
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500116} // namespace
117
118DispatchUtilsVk::DispatchUtilsVk() = default;
119
120DispatchUtilsVk::~DispatchUtilsVk() = default;
121
122void DispatchUtilsVk::destroy(VkDevice device)
123{
124 for (Function f : angle::AllEnums<Function>())
125 {
126 for (auto &descriptorSetLayout : mDescriptorSetLayouts[f])
127 {
128 descriptorSetLayout.reset();
129 }
130 mPipelineLayouts[f].reset();
131 mDescriptorPools[f].destroy(device);
132 }
133
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100134 for (vk::ShaderProgramHelper &program : mBufferUtilsPrograms)
135 {
136 program.destroy(device);
137 }
138 for (vk::ShaderProgramHelper &program : mConvertVertexPrograms)
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500139 {
140 program.destroy(device);
141 }
142}
143
144angle::Result DispatchUtilsVk::ensureResourcesInitialized(vk::Context *context,
145 Function function,
146 VkDescriptorPoolSize *setSizes,
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100147 size_t setSizesCount,
148 size_t pushConstantsSize)
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500149{
150 RendererVk *renderer = context->getRenderer();
151
152 vk::DescriptorSetLayoutDesc descriptorSetDesc;
153
154 uint32_t currentBinding = 0;
155 for (size_t i = 0; i < setSizesCount; ++i)
156 {
157 descriptorSetDesc.update(currentBinding, setSizes[i].type, setSizes[i].descriptorCount);
158 currentBinding += setSizes[i].descriptorCount;
159 }
160
161 ANGLE_TRY(renderer->getDescriptorSetLayout(context, descriptorSetDesc,
162 &mDescriptorSetLayouts[function][kSetIndex]));
163
164 // Corresponding pipeline layouts:
165 vk::PipelineLayoutDesc pipelineLayoutDesc;
166
167 pipelineLayoutDesc.updateDescriptorSetLayout(kSetIndex, descriptorSetDesc);
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100168 pipelineLayoutDesc.updatePushConstantRange(gl::ShaderType::Compute, 0, pushConstantsSize);
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500169
170 ANGLE_TRY(renderer->getPipelineLayout(
171 context, pipelineLayoutDesc, mDescriptorSetLayouts[function], &mPipelineLayouts[function]));
172
173 ANGLE_TRY(mDescriptorPools[function].init(context, setSizes, setSizesCount));
174
Jamie Madill7c985f52018-11-29 18:16:17 -0500175 return angle::Result::Continue;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500176}
177
178angle::Result DispatchUtilsVk::ensureBufferClearInitialized(vk::Context *context)
179{
180 if (mPipelineLayouts[Function::BufferClear].valid())
181 {
Jamie Madill7c985f52018-11-29 18:16:17 -0500182 return angle::Result::Continue;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500183 }
184
185 VkDescriptorPoolSize setSizes[1] = {
186 {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1},
187 };
188
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100189 return ensureResourcesInitialized(context, Function::BufferClear, setSizes, ArraySize(setSizes),
190 sizeof(BufferUtilsShaderParams));
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500191}
192
193angle::Result DispatchUtilsVk::ensureBufferCopyInitialized(vk::Context *context)
194{
195 if (mPipelineLayouts[Function::BufferCopy].valid())
196 {
Jamie Madill7c985f52018-11-29 18:16:17 -0500197 return angle::Result::Continue;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500198 }
199
200 VkDescriptorPoolSize setSizes[2] = {
201 {VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1},
202 {VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1},
203 };
204
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100205 return ensureResourcesInitialized(context, Function::BufferCopy, setSizes, ArraySize(setSizes),
206 sizeof(BufferUtilsShaderParams));
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500207}
208
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100209angle::Result DispatchUtilsVk::ensureConvertVertexInitialized(vk::Context *context)
210{
211 if (mPipelineLayouts[Function::ConvertVertexBuffer].valid())
212 {
213 return angle::Result::Continue;
214 }
215
216 VkDescriptorPoolSize setSizes[2] = {
217 {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1},
218 {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1},
219 };
220
221 return ensureResourcesInitialized(context, Function::ConvertVertexBuffer, setSizes,
222 ArraySize(setSizes), sizeof(ConvertVertexShaderParams));
223}
224
225angle::Result DispatchUtilsVk::setupProgramCommon(vk::Context *context,
226 Function function,
227 vk::RefCounted<vk::ShaderAndSerial> *shader,
228 vk::ShaderProgramHelper *program,
229 const VkDescriptorSet descriptorSet,
230 const void *pushConstants,
231 size_t pushConstantsSize,
232 vk::CommandBuffer *commandBuffer)
233{
234 RendererVk *renderer = context->getRenderer();
235
236 program->setShader(gl::ShaderType::Compute, shader);
237
238 const vk::BindingPointer<vk::PipelineLayout> &pipelineLayout = mPipelineLayouts[function];
239
240 vk::PipelineAndSerial *pipelineAndSerial;
241 ANGLE_TRY(program->getComputePipeline(context, pipelineLayout.get(), &pipelineAndSerial));
242
243 commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, pipelineAndSerial->get());
244 pipelineAndSerial->updateSerial(renderer->getCurrentQueueSerial());
245
246 commandBuffer->bindDescriptorSets(VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout.get(), 0, 1,
247 &descriptorSet, 0, nullptr);
248
249 commandBuffer->pushConstants(pipelineLayout.get(), VK_SHADER_STAGE_COMPUTE_BIT, 0,
250 pushConstantsSize, pushConstants);
251
252 return angle::Result::Continue;
253}
254
255template <angle::Result (vk::ShaderLibrary::*getShader)(vk::Context *,
256 uint32_t,
257 vk::RefCounted<vk::ShaderAndSerial> **),
258 DispatchUtilsVk::Function function,
259 typename ShaderParams>
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500260angle::Result DispatchUtilsVk::setupProgram(vk::Context *context,
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100261 vk::ShaderProgramHelper *program,
262 uint32_t flags,
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500263 const VkDescriptorSet &descriptorSet,
264 const ShaderParams &params,
265 vk::CommandBuffer *commandBuffer)
266{
267 RendererVk *renderer = context->getRenderer();
268 vk::ShaderLibrary &shaderLibrary = renderer->getShaderLibrary();
269
270 vk::RefCounted<vk::ShaderAndSerial> *shader = nullptr;
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100271 ANGLE_TRY((shaderLibrary.*getShader)(context, flags, &shader));
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500272
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100273 ANGLE_TRY(setupProgramCommon(context, function, shader, program, descriptorSet, &params,
274 sizeof(params), commandBuffer));
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500275
Jamie Madill7c985f52018-11-29 18:16:17 -0500276 return angle::Result::Continue;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500277}
278
279angle::Result DispatchUtilsVk::clearBuffer(vk::Context *context,
280 vk::BufferHelper *dest,
281 const ClearParameters &params)
282{
283 ANGLE_TRY(ensureBufferClearInitialized(context));
284
285 vk::CommandBuffer *commandBuffer;
286 ANGLE_TRY(dest->recordCommands(context, &commandBuffer));
287
288 // Tell dest it's being written to.
289 dest->onWrite(VK_ACCESS_SHADER_WRITE_BIT);
290
291 const vk::Format &destFormat = dest->getViewFormat();
292
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100293 uint32_t flags = BufferUtils_comp::kIsClear | GetBufferUtilsFlags(params.size, destFormat);
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500294
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100295 BufferUtilsShaderParams shaderParams;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500296 shaderParams.destOffset = params.offset;
297 shaderParams.size = params.size;
298 shaderParams.clearValue = params.clearValue;
299
300 VkDescriptorSet descriptorSet;
301 vk::SharedDescriptorPoolBinding descriptorPoolBinding;
302 ANGLE_TRY(mDescriptorPools[Function::BufferClear].allocateSets(
303 context, mDescriptorSetLayouts[Function::BufferClear][kSetIndex].get().ptr(), 1,
304 &descriptorPoolBinding, &descriptorSet));
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100305 descriptorPoolBinding.get().updateSerial(context->getRenderer()->getCurrentQueueSerial());
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500306
307 VkWriteDescriptorSet writeInfo = {};
308
309 writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
310 writeInfo.dstSet = descriptorSet;
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100311 writeInfo.dstBinding = kBufferClearOutputBinding;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500312 writeInfo.descriptorCount = 1;
313 writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
314 writeInfo.pTexelBufferView = dest->getBufferView().ptr();
315
316 vkUpdateDescriptorSets(context->getDevice(), 1, &writeInfo, 0, nullptr);
317
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100318 ANGLE_TRY((setupProgram<&vk::ShaderLibrary::getBufferUtils_comp, Function::BufferClear,
319 BufferUtilsShaderParams>(context, &mBufferUtilsPrograms[flags], flags,
320 descriptorSet, shaderParams, commandBuffer)));
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500321
322 commandBuffer->dispatch(UnsignedCeilDivide(params.size, 64), 1, 1);
323
324 descriptorPoolBinding.reset();
325
Jamie Madill7c985f52018-11-29 18:16:17 -0500326 return angle::Result::Continue;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500327}
328
329angle::Result DispatchUtilsVk::copyBuffer(vk::Context *context,
330 vk::BufferHelper *dest,
331 vk::BufferHelper *src,
332 const CopyParameters &params)
333{
334 ANGLE_TRY(ensureBufferCopyInitialized(context));
335
336 vk::CommandBuffer *commandBuffer;
337 ANGLE_TRY(dest->recordCommands(context, &commandBuffer));
338
339 // Tell src we are going to read from it.
340 src->onRead(dest, VK_ACCESS_SHADER_READ_BIT);
341 // Tell dest it's being written to.
342 dest->onWrite(VK_ACCESS_SHADER_WRITE_BIT);
343
344 const vk::Format &destFormat = dest->getViewFormat();
345 const vk::Format &srcFormat = src->getViewFormat();
346
347 ASSERT(destFormat.vkFormatIsInt == srcFormat.vkFormatIsInt);
348 ASSERT(destFormat.vkFormatIsUnsigned == srcFormat.vkFormatIsUnsigned);
349
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100350 uint32_t flags = BufferUtils_comp::kIsCopy | GetBufferUtilsFlags(params.size, destFormat);
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500351
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100352 BufferUtilsShaderParams shaderParams;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500353 shaderParams.destOffset = params.destOffset;
354 shaderParams.size = params.size;
355 shaderParams.srcOffset = params.srcOffset;
356
357 VkDescriptorSet descriptorSet;
358 vk::SharedDescriptorPoolBinding descriptorPoolBinding;
359 ANGLE_TRY(mDescriptorPools[Function::BufferCopy].allocateSets(
360 context, mDescriptorSetLayouts[Function::BufferCopy][kSetIndex].get().ptr(), 1,
361 &descriptorPoolBinding, &descriptorSet));
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100362 descriptorPoolBinding.get().updateSerial(context->getRenderer()->getCurrentQueueSerial());
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500363
364 VkWriteDescriptorSet writeInfo[2] = {};
365
366 writeInfo[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
367 writeInfo[0].dstSet = descriptorSet;
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100368 writeInfo[0].dstBinding = kBufferCopyDestinationBinding;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500369 writeInfo[0].descriptorCount = 1;
370 writeInfo[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
371 writeInfo[0].pTexelBufferView = dest->getBufferView().ptr();
372
373 writeInfo[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
374 writeInfo[1].dstSet = descriptorSet;
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100375 writeInfo[1].dstBinding = kBufferCopySourceBinding;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500376 writeInfo[1].descriptorCount = 1;
377 writeInfo[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
378 writeInfo[1].pTexelBufferView = src->getBufferView().ptr();
379
380 vkUpdateDescriptorSets(context->getDevice(), 2, writeInfo, 0, nullptr);
381
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100382 ANGLE_TRY((setupProgram<&vk::ShaderLibrary::getBufferUtils_comp, Function::BufferCopy,
383 BufferUtilsShaderParams>(context, &mBufferUtilsPrograms[flags], flags,
384 descriptorSet, shaderParams, commandBuffer)));
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500385
386 commandBuffer->dispatch(UnsignedCeilDivide(params.size, 64), 1, 1);
387
388 descriptorPoolBinding.reset();
389
Jamie Madill7c985f52018-11-29 18:16:17 -0500390 return angle::Result::Continue;
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500391}
392
Shahbaz Youssefi611bbaa2018-12-06 01:59:53 +0100393angle::Result DispatchUtilsVk::convertVertexBuffer(vk::Context *context,
394 vk::BufferHelper *dest,
395 vk::BufferHelper *src,
396 const ConvertVertexParameters &params)
397{
398 ANGLE_TRY(ensureConvertVertexInitialized(context));
399
400 vk::CommandBuffer *commandBuffer;
401 ANGLE_TRY(dest->recordCommands(context, &commandBuffer));
402
403 // Tell src we are going to read from it.
404 src->onRead(dest, VK_ACCESS_SHADER_READ_BIT);
405 // Tell dest it's being written to.
406 dest->onWrite(VK_ACCESS_SHADER_WRITE_BIT);
407
408 ConvertVertexShaderParams shaderParams;
409 shaderParams.Ns = params.srcFormat->channelCount();
410 shaderParams.Bs = params.srcFormat->pixelBytes / params.srcFormat->channelCount();
411 shaderParams.Ss = params.srcStride;
412 shaderParams.Nd = params.destFormat->channelCount();
413 shaderParams.Bd = params.destFormat->pixelBytes / params.destFormat->channelCount();
414 shaderParams.Sd = shaderParams.Nd * shaderParams.Bd;
415 // The component size is expected to either be 1, 2 or 4 bytes.
416 ASSERT(4 % shaderParams.Bs == 0);
417 ASSERT(4 % shaderParams.Bd == 0);
418 shaderParams.Es = 4 / shaderParams.Bs;
419 shaderParams.Ed = 4 / shaderParams.Bd;
420 // Total number of output components is simply the number of vertices by number of components in
421 // each.
422 shaderParams.componentCount = params.vertexCount * shaderParams.Nd;
423 // Total number of 4-byte outputs is the number of components divided by how many components can
424 // fit in a 4-byte value. Note that this value is also the invocation size of the shader.
425 shaderParams.outputCount = shaderParams.componentCount / shaderParams.Ed;
426 shaderParams.srcOffset = params.srcOffset;
427 shaderParams.destOffset = params.destOffset;
428
429 uint32_t flags = GetConvertVertexFlags(params);
430
431 bool isAligned =
432 shaderParams.outputCount % 64 == 0 && shaderParams.componentCount % shaderParams.Ed == 0;
433 flags |= isAligned ? ConvertVertex_comp::kIsAligned : 0;
434
435 VkDescriptorSet descriptorSet;
436 vk::SharedDescriptorPoolBinding descriptorPoolBinding;
437 ANGLE_TRY(mDescriptorPools[Function::ConvertVertexBuffer].allocateSets(
438 context, mDescriptorSetLayouts[Function::ConvertVertexBuffer][kSetIndex].get().ptr(), 1,
439 &descriptorPoolBinding, &descriptorSet));
440 descriptorPoolBinding.get().updateSerial(context->getRenderer()->getCurrentQueueSerial());
441
442 VkWriteDescriptorSet writeInfo = {};
443 VkDescriptorBufferInfo buffers[2] = {
444 {dest->getBuffer().getHandle(), 0, VK_WHOLE_SIZE},
445 {src->getBuffer().getHandle(), 0, VK_WHOLE_SIZE},
446 };
447 static_assert(kConvertVertexDestinationBinding + 1 == kConvertVertexSourceBinding,
448 "Update write info");
449
450 writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
451 writeInfo.dstSet = descriptorSet;
452 writeInfo.dstBinding = kConvertVertexDestinationBinding;
453 writeInfo.descriptorCount = 2;
454 writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
455 writeInfo.pBufferInfo = buffers;
456
457 vkUpdateDescriptorSets(context->getDevice(), 1, &writeInfo, 0, nullptr);
458
459 ANGLE_TRY(
460 (setupProgram<&vk::ShaderLibrary::getConvertVertex_comp, Function::ConvertVertexBuffer,
461 ConvertVertexShaderParams>(context, &mConvertVertexPrograms[flags], flags,
462 descriptorSet, shaderParams, commandBuffer)));
463
464 commandBuffer->dispatch(UnsignedCeilDivide(shaderParams.outputCount, 64), 1, 1);
465
466 descriptorPoolBinding.reset();
467
468 return angle::Result::Continue;
469}
470
Shahbaz Youssefi8f1b7a62018-11-14 16:02:54 -0500471} // namespace rx