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
63{
64 return m_size;
65}
A device containing images (ie. USB stick, CD, storage group etc)
MythIndexBufferVulkan(MythRenderVulkan *Render, VkDevice Device, QVulkanDeviceFunctions *Functions, const std::vector< uint16_t > &Indices)
static MythIndexBufferVulkan * Create(MythRenderVulkan *Render, VkDevice Device, QVulkanDeviceFunctions *Functions, const std::vector< uint16_t > &Indices)
uint32_t GetSize(void) const
VkBuffer GetBuffer(void) const
bool CreateBuffer(VkDeviceSize Size, VkBufferUsageFlags Usage, VkMemoryPropertyFlags Properties, VkBuffer &Buffer, VkDeviceMemory &Memory)
void CopyBuffer(VkBuffer Src, VkBuffer Dst, VkDeviceSize Size, VkCommandBuffer CommandBuffer=nullptr)
MythRenderVulkan * Render()
static guint32 * tmp
Definition: goom_core.cpp:26