1 /* 2 * Copyright 2017 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "GrVkBufferView.h" 9 #include "GrVkGpu.h" 10 #include "GrVkUtil.h" 11 12 const GrVkBufferView* GrVkBufferView::Create(const GrVkGpu* gpu, VkBuffer buffer, VkFormat format, 13 VkDeviceSize offset, VkDeviceSize range) { 14 VkBufferView bufferView; 15 16 // Create the VkBufferView 17 VkBufferViewCreateInfo viewInfo; 18 memset(&viewInfo, 0, sizeof(VkBufferViewCreateInfo)); 19 viewInfo.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; 20 viewInfo.pNext = nullptr; 21 viewInfo.flags = 0; 22 viewInfo.buffer = buffer; 23 viewInfo.format = format; 24 viewInfo.offset = offset; 25 viewInfo.range = range; 26 27 VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateBufferView(gpu->device(), &viewInfo, 28 nullptr, &bufferView)); 29 if (err) { 30 return nullptr; 31 } 32 33 return new GrVkBufferView(bufferView); 34 } 35 36 void GrVkBufferView::freeGPUData(const GrVkGpu* gpu) const { 37 GR_VK_CALL(gpu->vkInterface(), DestroyBufferView(gpu->device(), fBufferView, nullptr)); 38 } 39