1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Intel Corporation
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 *//*!
21 * \file
22 * \brief Buffer Object Util
23 *//*--------------------------------------------------------------------*/
24
25 #include "vktDrawBufferObjectUtil.hpp"
26
27 #include "vkQueryUtil.hpp"
28
29 namespace vkt
30 {
31 namespace Draw
32 {
33
Buffer(const vk::DeviceInterface & vk,vk::VkDevice device,vk::Move<vk::VkBuffer> object_)34 Buffer::Buffer (const vk::DeviceInterface& vk, vk::VkDevice device, vk::Move<vk::VkBuffer> object_)
35 : m_allocation (DE_NULL)
36 , m_object (object_)
37 , m_vk (vk)
38 , m_device (device)
39 {
40 }
41
bindMemory(de::MovePtr<vk::Allocation> allocation)42 void Buffer::bindMemory (de::MovePtr<vk::Allocation> allocation)
43 {
44 DE_ASSERT(allocation);
45 VK_CHECK(m_vk.bindBufferMemory(m_device, *m_object, allocation->getMemory(), allocation->getOffset()));
46
47 DE_ASSERT(!m_allocation);
48 m_allocation = allocation;
49 }
50
createAndAlloc(const vk::DeviceInterface & vk,vk::VkDevice device,const vk::VkBufferCreateInfo & createInfo,vk::Allocator & allocator,vk::MemoryRequirement memoryRequirement)51 de::SharedPtr<Buffer> Buffer::createAndAlloc (const vk::DeviceInterface& vk,
52 vk::VkDevice device,
53 const vk::VkBufferCreateInfo &createInfo,
54 vk::Allocator &allocator,
55 vk::MemoryRequirement memoryRequirement)
56 {
57 de::SharedPtr<Buffer> ret = create(vk, device, createInfo);
58
59 vk::VkMemoryRequirements bufferRequirements = vk::getBufferMemoryRequirements(vk, device, ret->object());
60 ret->bindMemory(allocator.allocate(bufferRequirements, memoryRequirement));
61 return ret;
62 }
63
create(const vk::DeviceInterface & vk,vk::VkDevice device,const vk::VkBufferCreateInfo & createInfo)64 de::SharedPtr<Buffer> Buffer::create (const vk::DeviceInterface& vk,
65 vk::VkDevice device,
66 const vk::VkBufferCreateInfo& createInfo)
67 {
68 return de::SharedPtr<Buffer>(new Buffer(vk, device, vk::createBuffer(vk, device, &createInfo)));
69 }
70
bufferBarrier(const vk::DeviceInterface & vk,vk::VkCommandBuffer cmdBuffer,vk::VkBuffer buffer,vk::VkAccessFlags srcAccessMask,vk::VkAccessFlags dstAccessMask,vk::VkPipelineStageFlags srcStageMask,vk::VkPipelineStageFlags dstStageMask)71 void bufferBarrier (const vk::DeviceInterface& vk,
72 vk::VkCommandBuffer cmdBuffer,
73 vk::VkBuffer buffer,
74 vk::VkAccessFlags srcAccessMask,
75 vk::VkAccessFlags dstAccessMask,
76 vk::VkPipelineStageFlags srcStageMask,
77 vk::VkPipelineStageFlags dstStageMask)
78 {
79 vk::VkBufferMemoryBarrier barrier;
80 barrier.sType = vk::VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
81 barrier.pNext = DE_NULL;
82 barrier.srcAccessMask = srcAccessMask;
83 barrier.dstAccessMask = dstAccessMask;
84 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
85 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
86 barrier.buffer = buffer;
87 barrier.offset = 0;
88 barrier.size = VK_WHOLE_SIZE;
89
90 vk.cmdPipelineBarrier(cmdBuffer, srcStageMask, dstStageMask, (vk::VkDependencyFlags)0, 0, (const vk::VkMemoryBarrier*)DE_NULL,
91 1, &barrier, 0, (const vk::VkImageMemoryBarrier*)DE_NULL);
92 }
93
94 } // Draw
95 } // vkt
96