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