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 <QtGlobal>
10#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
11#include <QtProcessorDetection>
12#endif
13#include <QVulkanWindowRenderer>
14#include <QVulkanDeviceFunctions>
15
16// MythTV
17#include "libmythui/mythuiexp.h"
19
20class MythImage;
21class MythDebugVulkan;
26
27using MythVulkan4F = std::array<float,4>;
28
29// workaround 32bit Vulkan defines
30#if QT_POINTER_SIZE == 8
31#define MYTH_NULL_DISPATCH nullptr
32#else
33#define MYTH_NULL_DISPATCH 0
34#endif
35
37{
38 public:
39 static MythVulkanObject* Create(MythRenderVulkan* Render);
42
43 bool IsValidVulkan() const;
44 MythRenderVulkan* Render ();
45 VkDevice Device ();
46 QVulkanDeviceFunctions* Funcs ();
47 MythWindowVulkan* Window ();
48
49 protected:
50 void CheckValid();
51 bool m_vulkanValid { true };
52 MythRenderVulkan* m_vulkanRender { nullptr };
53 VkDevice m_vulkanDevice { nullptr };
54 QVulkanDeviceFunctions* m_vulkanFuncs { nullptr };
55 MythWindowVulkan* m_vulkanWindow { nullptr };
56
57 private:
58 Q_DISABLE_COPY(MythVulkanObject)
59};
60
61class MUI_PUBLIC MythRenderVulkan : public QObject, public QVulkanWindowRenderer, public MythRender
62{
63 Q_OBJECT
64
65 public:
66
67 static MythRenderVulkan* GetVulkanRender(void);
68
70 ~MythRenderVulkan() override;
71
72 void SetVulkanWindow (MythWindowVulkan *VulkanWindow);
73 MythWindowVulkan* GetVulkanWindow(void);
74 void SetFrameExpected (void);
75 bool GetFrameExpected (void) const;
76 bool GetFrameStarted (void) const;
77 void EndFrame (void);
78 QStringList GetDescription(void) override;
79
80 void preInitResources (void) override;
81 void initResources (void) override;
82 void initSwapChainResources (void) override;
83 void releaseSwapChainResources (void) override;
84 void releaseResources (void) override;
85 void startNextFrame (void) override;
86 void physicalDeviceLost (void) override;
87 void logicalDeviceLost (void) override;
88
89 void BeginDebugRegion(VkCommandBuffer CommandBuffer, const char *Name,
91 void EndDebugRegion(VkCommandBuffer CommandBuffer);
92 bool CreateImage(QSize Size, VkFormat Format, VkImageTiling Tiling,
93 VkImageUsageFlags Usage, VkMemoryPropertyFlags Properties,
94 VkImage& Image, VkDeviceMemory& ImageMemory);
95 void TransitionImageLayout(VkImage &Image, VkImageLayout OldLayout,
96 VkImageLayout NewLayout, VkCommandBuffer CommandBuffer = nullptr);
97 void CopyBufferToImage(VkBuffer Buffer, VkImage Image,
98 uint32_t Width, uint32_t Height,
99 VkCommandBuffer CommandBuffer = nullptr);
100 bool CreateBuffer(VkDeviceSize Size, VkBufferUsageFlags Usage,
101 VkMemoryPropertyFlags Properties, VkBuffer& Buffer,
102 VkDeviceMemory& Memory);
103 void CopyBuffer(VkBuffer Src, VkBuffer Dst, VkDeviceSize Size,
104 VkCommandBuffer CommandBuffer = nullptr);
105 VkPipeline CreatePipeline(MythShaderVulkan* Shader, QRect Viewport,
106 std::vector<VkDynamicState> Dynamic = { });
107 VkCommandBuffer CreateSingleUseCommandBuffer(void);
108 void FinishSingleUseCommandBuffer(VkCommandBuffer &Buffer);
109 VkSampler CreateSampler(VkFilter Min, VkFilter Mag);
110 VkPhysicalDeviceFeatures GetPhysicalDeviceFeatures() const;
111 VkPhysicalDeviceLimits GetPhysicalDeviceLimits () const;
112
113 signals:
114 void DoFreeResources (void);
116 void LogicalDeviceLost (void);
117
118 private:
119 Q_DISABLE_COPY(MythRenderVulkan)
120
121 std::optional<uint32_t> FindMemoryType(uint32_t Filter, VkMemoryPropertyFlags Properties);
122
123 void BeginFrame (void);
124 void DebugVulkan (void);
125
126 MythWindowVulkan* m_window { nullptr };
127 VkDevice m_device { nullptr };
128 QVulkanFunctions* m_funcs { nullptr };
129 QVulkanDeviceFunctions *m_devFuncs { nullptr };
130 VkPhysicalDeviceFeatures m_phyDevFeatures { };
131 VkPhysicalDeviceLimits m_phyDevLimits { };
132 bool m_frameExpected { false };
133 bool m_frameStarted { false };
134 QMap<QString,QString> m_debugInfo;
135 MythDebugVulkan* m_debugMarker { nullptr };
136};
137
138#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:5
QMultiMap< QString, Property * > Properties