Skip to content

Commit

Permalink
Vulkan: Add MythBufferVulkan
Browse files Browse the repository at this point in the history
- re-enable compilation of MythVertexBufferVulkan
- add base class MythBufferVulkan - a generic Vulkan buffer class
  • Loading branch information
mark-kendall committed Sep 7, 2020
1 parent 0979978 commit fb224aa
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 31 deletions.
2 changes: 2 additions & 0 deletions mythtv/libs/libmythui/libmythui.pro
Expand Up @@ -205,6 +205,7 @@ using_vulkan {
HEADERS += vulkan/mythuniformbuffervulkan.h
HEADERS += vulkan/mythcombobuffervulkan.h
HEADERS += vulkan/mythdebugvulkan.h
HEADERS += vulkan/mythvertexbuffervulkan.h
SOURCES += vulkan/mythpainterwindowvulkan.cpp
SOURCES += vulkan/mythpaintervulkan.cpp
SOURCES += vulkan/mythrendervulkan.cpp
Expand All @@ -214,6 +215,7 @@ using_vulkan {
SOURCES += vulkan/mythuniformbuffervulkan.cpp
SOURCES += vulkan/mythcombobuffervulkan.cpp
SOURCES += vulkan/mythdebugvulkan.cpp
SOURCES += vulkan/mythvertexbuffervulkan.cpp
using_libglslang: DEFINES += USING_GLSLANG
}

Expand Down
51 changes: 36 additions & 15 deletions mythtv/libs/libmythui/vulkan/mythvertexbuffervulkan.cpp
Expand Up @@ -2,12 +2,12 @@
#include "mythlogging.h"
#include "vulkan/mythvertexbuffervulkan.h"

#define LOC QString("VulkanVBO: ")
#define LOC QString("VulkanBuf: ")

MythVertexBufferVulkan* MythVertexBufferVulkan::Create(MythRenderVulkan *Render, VkDevice Device,
QVulkanDeviceFunctions *Functions, VkDeviceSize Size)
MythBufferVulkan* MythBufferVulkan::Create(MythRenderVulkan *Render, VkDevice Device,
QVulkanDeviceFunctions *Functions, VkDeviceSize Size)
{
MythVertexBufferVulkan* result = new MythVertexBufferVulkan(Render, Device, Functions, Size);
MythBufferVulkan* result = new MythBufferVulkan(Render, Device, Functions, Size);
if (result && !result->IsValid())
{
delete result;
Expand All @@ -16,17 +16,14 @@ MythVertexBufferVulkan* MythVertexBufferVulkan::Create(MythRenderVulkan *Render,
return result;
}

MythVertexBufferVulkan::MythVertexBufferVulkan(MythRenderVulkan *Render, VkDevice Device,
QVulkanDeviceFunctions* Functions, VkDeviceSize Size)
MythBufferVulkan::MythBufferVulkan(MythRenderVulkan *Render, VkDevice Device,
QVulkanDeviceFunctions* Functions, VkDeviceSize Size)
: MythVulkanObject(Render, Device, Functions),
m_bufferSize(Size)
{
if (!m_valid)
return;

if (m_render->CreateBuffer(Size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
m_stagingBuffer, m_stagingMemory))
if (m_valid && m_render->CreateBuffer(Size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
m_stagingBuffer, m_stagingMemory))
{
if (m_render->CreateBuffer(Size, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
Expand All @@ -37,7 +34,7 @@ MythVertexBufferVulkan::MythVertexBufferVulkan(MythRenderVulkan *Render, VkDevic
}
}

MythVertexBufferVulkan::~MythVertexBufferVulkan()
MythBufferVulkan::~MythBufferVulkan()
{
if (m_device && m_devFuncs)
{
Expand All @@ -48,15 +45,39 @@ MythVertexBufferVulkan::~MythVertexBufferVulkan()
}
}

VkBuffer MythVertexBufferVulkan::GetBuffer(void) const
VkBuffer MythBufferVulkan::GetBuffer(void) const
{
return m_buffer;
}
void* MythVertexBufferVulkan::GetMappedMemory(void) const

void* MythBufferVulkan::GetMappedMemory(void) const
{
return m_mappedMemory;
}

void MythBufferVulkan::Update(VkCommandBuffer CommandBuffer)
{
m_render->CopyBuffer(m_stagingBuffer, m_buffer, m_bufferSize, CommandBuffer);
}

MythVertexBufferVulkan* MythVertexBufferVulkan::Create(MythRenderVulkan *Render, VkDevice Device,
QVulkanDeviceFunctions *Functions, VkDeviceSize Size)
{
MythVertexBufferVulkan* result = new MythVertexBufferVulkan(Render, Device, Functions, Size);
if (result && !result->IsValid())
{
delete result;
result = nullptr;
}
return result;
}

MythVertexBufferVulkan::MythVertexBufferVulkan(MythRenderVulkan *Render, VkDevice Device,
QVulkanDeviceFunctions* Functions, VkDeviceSize Size)
: MythBufferVulkan(Render, Device, Functions, Size)
{
}

void MythVertexBufferVulkan::Update(const QRect &Source, const QRect &Dest,
int Alpha, int Rotation, VkCommandBuffer CommandBuffer)
{
Expand Down
48 changes: 32 additions & 16 deletions mythtv/libs/libmythui/vulkan/mythvertexbuffervulkan.h
Expand Up @@ -4,35 +4,51 @@
// MythTV
#include "vulkan/mythrendervulkan.h"

class MythVertexBufferVulkan : protected MythVulkanObject
class MythBufferVulkan : protected MythVulkanObject
{
public:
static MythVertexBufferVulkan* Create(MythRenderVulkan* Render, VkDevice Device,
QVulkanDeviceFunctions* Functions, VkDeviceSize Size);
~MythVertexBufferVulkan();
static MythBufferVulkan* Create(MythRenderVulkan* Render, VkDevice Device,
QVulkanDeviceFunctions* Functions, VkDeviceSize Size);
virtual ~MythBufferVulkan();

VkBuffer GetBuffer (void) const;
bool NeedsUpdate (const QRect& Source, const QRect& Dest, int Alpha, int Rotation);
void* GetMappedMemory (void) const;
void Update (const QRect& Source, const QRect& Dest, int Alpha, int Rotation,
VkCommandBuffer CommandBuffer = nullptr);
VkBuffer GetBuffer () const;
void* GetMappedMemory () const;
void Update (VkCommandBuffer CommandBuffer = nullptr);

protected:
MythVertexBufferVulkan(MythRenderVulkan* Render, VkDevice Device,
QVulkanDeviceFunctions* Functions, VkDeviceSize Size);
private:
Q_DISABLE_COPY(MythVertexBufferVulkan)
MythBufferVulkan(MythRenderVulkan* Render, VkDevice Device,
QVulkanDeviceFunctions* Functions, VkDeviceSize Size);

VkDeviceSize m_bufferSize { 0 };
VkBuffer m_buffer { nullptr };
VkDeviceMemory m_bufferMemory { nullptr };
VkBuffer m_stagingBuffer { nullptr };
VkDeviceMemory m_stagingMemory { nullptr };
void* m_mappedMemory { nullptr };

private:
Q_DISABLE_COPY(MythBufferVulkan)
};

class MythVertexBufferVulkan : public MythBufferVulkan
{
public:
static MythVertexBufferVulkan* Create(MythRenderVulkan* Render, VkDevice Device,
QVulkanDeviceFunctions* Functions, VkDeviceSize Size);

bool NeedsUpdate (const QRect& Source, const QRect& Dest, int Alpha, int Rotation);
void Update (const QRect& Source, const QRect& Dest, int Alpha, int Rotation,
VkCommandBuffer CommandBuffer = nullptr);

protected:
MythVertexBufferVulkan(MythRenderVulkan* Render, VkDevice Device,
QVulkanDeviceFunctions* Functions, VkDeviceSize Size);

private:
QRect m_source;
QRect m_dest;
int m_rotation { 0 };
int m_alpha { 255 };
int m_rotation { 0 };
int m_alpha { 255 };
};

#endif // MYTHVBOVULKAN_H
#endif

0 comments on commit fb224aa

Please sign in to comment.