1 #ifndef _VKBUFFERWITHMEMORY_HPP 2 #define _VKBUFFERWITHMEMORY_HPP 3 /*------------------------------------------------------------------------- 4 * Vulkan CTS Framework 5 * -------------------- 6 * 7 * Copyright (c) 2016 The Khronos Group Inc. 8 * Copyright (c) 2016 Google Inc. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Buffer backed with memory 25 *//*--------------------------------------------------------------------*/ 26 27 #include "vkDefs.hpp" 28 29 #include "vkMemUtil.hpp" 30 #include "vkQueryUtil.hpp" 31 #include "vkRef.hpp" 32 #include "vkRefUtil.hpp" 33 34 namespace vk 35 { 36 class BufferWithMemory 37 { 38 public: BufferWithMemory(const vk::DeviceInterface & vk,const vk::VkDevice device,vk::Allocator & allocator,const vk::VkBufferCreateInfo & bufferCreateInfo,const vk::MemoryRequirement memoryRequirement)39 BufferWithMemory (const vk::DeviceInterface& vk, 40 const vk::VkDevice device, 41 vk::Allocator& allocator, 42 const vk::VkBufferCreateInfo& bufferCreateInfo, 43 const vk::MemoryRequirement memoryRequirement) 44 45 : m_buffer (createBuffer(vk, device, &bufferCreateInfo)) 46 , m_allocation (allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement)) 47 { 48 VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset())); 49 } 50 get(void) const51 const vk::VkBuffer& get (void) const { return *m_buffer; } operator *(void) const52 const vk::VkBuffer& operator* (void) const { return get(); } getAllocation(void) const53 vk::Allocation& getAllocation (void) const { return *m_allocation; } 54 55 private: 56 const vk::Unique<vk::VkBuffer> m_buffer; 57 const de::UniquePtr<vk::Allocation> m_allocation; 58 59 // "deleted" 60 BufferWithMemory (const BufferWithMemory&); 61 BufferWithMemory operator= (const BufferWithMemory&); 62 }; 63 } // vk 64 65 #endif // _VKBUFFERWITHMEMORY_HPP 66