MythTV  master
mythindexbuffervulkan.cpp
Go to the documentation of this file.
1 // MythTV
3 
5  QVulkanDeviceFunctions *Functions,
6  const std::vector<uint16_t> &Indices)
7 {
8  MythIndexBufferVulkan* result = new MythIndexBufferVulkan(Render, Device, Functions, Indices);
9  if (result && !result->m_valid)
10  {
11  delete result;
12  result = nullptr;
13  }
14  return result;
15 }
16 
18  QVulkanDeviceFunctions *Functions,
19  const std::vector<uint16_t> &Indices)
20  : MythVulkanObject(Render, Device, Functions)
21 {
22  m_size = static_cast<uint32_t>(Indices.size());
23  VkDeviceSize size = sizeof(Indices[0]) * Indices.size();
24  VkBuffer stagingbuf = nullptr;
25  VkDeviceMemory stagingmem = nullptr;
26  if (Render->CreateBuffer(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
27  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
28  stagingbuf, stagingmem))
29  {
30  void* tmp;
31  m_devFuncs->vkMapMemory(m_device, stagingmem, 0, size, 0, &tmp);
32  memcpy(tmp, Indices.data(), static_cast<size_t>(size));
33  m_devFuncs->vkUnmapMemory(m_device, stagingmem);
34 
35  if (Render->CreateBuffer(size, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
36  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
38  {
39  Render->CopyBuffer(stagingbuf, m_buffer, size);
40  m_valid = true;
41  }
42 
43  m_devFuncs->vkDestroyBuffer(m_device, stagingbuf, nullptr);
44  m_devFuncs->vkFreeMemory(m_device, stagingmem, nullptr);
45  }
46 }
47 
49 {
50  if (m_device && m_devFuncs)
51  {
52  m_devFuncs->vkDestroyBuffer(m_device, m_buffer, nullptr);
53  m_devFuncs->vkFreeMemory(m_device, m_memory, nullptr);
54  }
55 }
56 
58 {
59  return m_buffer;
60 }
61 
62 uint32_t MythIndexBufferVulkan::GetSize(void) const
63 {
64  return m_size;
65 }
MythIndexBufferVulkan::~MythIndexBufferVulkan
~MythIndexBufferVulkan()
Definition: mythindexbuffervulkan.cpp:48
MythRenderVulkan::CopyBuffer
void CopyBuffer(VkBuffer Src, VkBuffer Dst, VkDeviceSize Size, VkCommandBuffer CommandBuffer=nullptr)
Definition: mythrendervulkan.cpp:433
MythIndexBufferVulkan::GetBuffer
VkBuffer GetBuffer(void) const
Definition: mythindexbuffervulkan.cpp:57
MythVulkanObject
Definition: mythrendervulkan.h:32
MythIndexBufferVulkan::MythIndexBufferVulkan
MythIndexBufferVulkan(MythRenderVulkan *Render, VkDevice Device, QVulkanDeviceFunctions *Functions, const std::vector< uint16_t > &Indices)
Definition: mythindexbuffervulkan.cpp:17
MythIndexBufferVulkan::GetSize
uint32_t GetSize(void) const
Definition: mythindexbuffervulkan.cpp:62
Device
A device containing images (ie. USB stick, CD, storage group etc)
Definition: imagemanager.cpp:35
tmp
static guint32 * tmp
Definition: goom_core.cpp:26
mythindexbuffervulkan.h
MythIndexBufferVulkan
Definition: mythindexbuffervulkan.h:7
MythIndexBufferVulkan::Create
static MythIndexBufferVulkan * Create(MythRenderVulkan *Render, VkDevice Device, QVulkanDeviceFunctions *Functions, const std::vector< uint16_t > &Indices)
Definition: mythindexbuffervulkan.cpp:4
MythRenderVulkan
Definition: mythrendervulkan.h:57
MythIndexBufferVulkan::m_memory
VkDeviceMemory m_memory
Definition: mythindexbuffervulkan.h:26
MythIndexBufferVulkan::m_size
uint32_t m_size
Definition: mythindexbuffervulkan.h:24
MythVulkanObject::Render
MythRenderVulkan * Render()
Definition: mythrendervulkan.cpp:68
MythRenderVulkan::CreateBuffer
bool CreateBuffer(VkDeviceSize Size, VkBufferUsageFlags Usage, VkMemoryPropertyFlags Properties, VkBuffer &Buffer, VkDeviceMemory &Memory)
Definition: mythrendervulkan.cpp:450
MythIndexBufferVulkan::m_buffer
VkBuffer m_buffer
Definition: mythindexbuffervulkan.h:25