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 
16 class MythImage;
17 class MythDebugVulkan;
18 class MythRenderVulkan;
19 class MythWindowVulkan;
20 class MythShaderVulkan;
21 class MythTextureVulkan;
22 
23 using 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 
57 class 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);
111  void PhysicalDeviceLost (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
MythRender::GetDescription
virtual QStringList GetDescription()
Definition: mythrender.cpp:16
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythDebugVulkan
Definition: mythdebugvulkan.h:8
MythVulkanObject
Definition: mythrendervulkan.h:32
MythDate::Format
Format
Definition: mythdate.h:15
Device
A device containing images (ie. USB stick, CD, storage group etc)
Definition: imagemanager.cpp:35
MythWindowVulkan
Definition: mythwindowvulkan.h:10
Image
Definition: image.h:33
MythTextureVulkan
Definition: mythtexturevulkan.h:14
MythRenderVulkan::m_debugInfo
QMap< QString, QString > m_debugInfo
Definition: mythrendervulkan.h:130
mythrender_base.h
Properties
QMultiMap< QString, Property * > Properties
Definition: upnpcdsobjects.h:96
MythVulkan4F
std::array< float, 4 > MythVulkan4F
Definition: mythrendervulkan.h:23
Buffer
Definition: MythExternControl.h:36
MythRender
Definition: mythrender_base.h:23
MythImage
Definition: mythimage.h:36
Name
Definition: channelsettings.cpp:71
MythRenderVulkan
Definition: mythrendervulkan.h:57
MythShaderVulkan
Creates shader objects suitable for use with the Vulkan API.
Definition: mythshadervulkan.h:20
mythuiexp.h
Color
Definition: graphic.h:6