MythTV master
mythrendervulkan.h
Go to the documentation of this file.
1#ifndef MYTHRENDERVULKAN_H
2#define MYTHRENDERVULKAN_H
3
4// C++
5#include <array>
6#include <optional>
7
8// Qt
9#include <QVulkanWindowRenderer>
10#include <QVulkanDeviceFunctions>
11
12// MythTV
13#include "libmythui/mythuiexp.h"
15
16class MythImage;
17class MythDebugVulkan;
22
23using MythVulkan4F = std::array<float,4>;
24
25// workaround 32bit Vulkan defines
26#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
27#define MYTH_NULL_DISPATCH nullptr
28#else
29#define MYTH_NULL_DISPATCH 0
30#endif
31
33{
34 public:
35 static MythVulkanObject* Create(MythRenderVulkan* Render);
38
39 bool IsValidVulkan() const;
40 MythRenderVulkan* Render ();
41 VkDevice Device ();
42 QVulkanDeviceFunctions* Funcs ();
43 MythWindowVulkan* Window ();
44
45 protected:
46 void CheckValid();
47 bool m_vulkanValid { true };
48 MythRenderVulkan* m_vulkanRender { nullptr };
49 VkDevice m_vulkanDevice { nullptr };
50 QVulkanDeviceFunctions* m_vulkanFuncs { nullptr };
51 MythWindowVulkan* m_vulkanWindow { nullptr };
52
53 private:
54 Q_DISABLE_COPY(MythVulkanObject)
55};
56
57class MUI_PUBLIC MythRenderVulkan : public QObject, public QVulkanWindowRenderer, public MythRender
58{
59 Q_OBJECT
60
61 public:
62
63 static MythRenderVulkan* GetVulkanRender(void);
64
66 ~MythRenderVulkan() override;
67
68 void SetVulkanWindow (MythWindowVulkan *VulkanWindow);
69 MythWindowVulkan* GetVulkanWindow(void);
70 void SetFrameExpected (void);
71 bool GetFrameExpected (void) const;
72 bool GetFrameStarted (void) const;
73 void EndFrame (void);
74 QStringList GetDescription(void) override;
75
76 void preInitResources (void) override;
77 void initResources (void) override;
78 void initSwapChainResources (void) override;
79 void releaseSwapChainResources (void) override;
80 void releaseResources (void) override;
81 void startNextFrame (void) override;
82 void physicalDeviceLost (void) override;
83 void logicalDeviceLost (void) override;
84
85 void BeginDebugRegion(VkCommandBuffer CommandBuffer, const char *Name,
87 void EndDebugRegion(VkCommandBuffer CommandBuffer);
88 bool CreateImage(QSize Size, VkFormat Format, VkImageTiling Tiling,
89 VkImageUsageFlags Usage, VkMemoryPropertyFlags Properties,
90 VkImage& Image, VkDeviceMemory& ImageMemory);
91 void TransitionImageLayout(VkImage &Image, VkImageLayout OldLayout,
92 VkImageLayout NewLayout, VkCommandBuffer CommandBuffer = nullptr);
93 void CopyBufferToImage(VkBuffer Buffer, VkImage Image,
94 uint32_t Width, uint32_t Height,
95 VkCommandBuffer CommandBuffer = nullptr);
96 bool CreateBuffer(VkDeviceSize Size, VkBufferUsageFlags Usage,
97 VkMemoryPropertyFlags Properties, VkBuffer& Buffer,
98 VkDeviceMemory& Memory);
99 void CopyBuffer(VkBuffer Src, VkBuffer Dst, VkDeviceSize Size,
100 VkCommandBuffer CommandBuffer = nullptr);
101 VkPipeline CreatePipeline(MythShaderVulkan* Shader, QRect Viewport,
102 std::vector<VkDynamicState> Dynamic = { });
103 VkCommandBuffer CreateSingleUseCommandBuffer(void);
104 void FinishSingleUseCommandBuffer(VkCommandBuffer &Buffer);
105 VkSampler CreateSampler(VkFilter Min, VkFilter Mag);
106 VkPhysicalDeviceFeatures GetPhysicalDeviceFeatures() const;
107 VkPhysicalDeviceLimits GetPhysicalDeviceLimits () const;
108
109 signals:
110 void DoFreeResources (void);
112 void LogicalDeviceLost (void);
113
114 private:
115 Q_DISABLE_COPY(MythRenderVulkan)
116
117 std::optional<uint32_t> FindMemoryType(uint32_t Filter, VkMemoryPropertyFlags Properties);
118
119 void BeginFrame (void);
120 void DebugVulkan (void);
121
122 MythWindowVulkan* m_window { nullptr };
123 VkDevice m_device { nullptr };
124 QVulkanFunctions* m_funcs { nullptr };
125 QVulkanDeviceFunctions *m_devFuncs { nullptr };
126 VkPhysicalDeviceFeatures m_phyDevFeatures { };
127 VkPhysicalDeviceLimits m_phyDevLimits { };
128 bool m_frameExpected { false };
129 bool m_frameStarted { false };
130 QMap<QString,QString> m_debugInfo;
131 MythDebugVulkan* m_debugMarker { nullptr };
132};
133
134#endif
A device containing images (ie. USB stick, CD, storage group etc)
void PhysicalDeviceLost(void)
void LogicalDeviceLost(void)
QMap< QString, QString > m_debugInfo
void DoFreeResources(void)
Creates shader objects suitable for use with the Vulkan API.
std::array< float, 4 > MythVulkan4F
#define MUI_PUBLIC
Definition: mythuiexp.h:9
Definition: graphic.h:7
QMultiMap< QString, Property * > Properties