MythTV master
mythvisualvulkan.cpp
Go to the documentation of this file.
1// MythTV
6
7#include <utility>
8
9#define LOC QString("VulkanVis: ")
10
12 std::vector<VkDynamicState> Dynamic,
13 std::vector<int> Stages,
14 const MythShaderMap *Sources,
15 const MythBindingMap *Bindings)
16 : MythVulkanObject(Render),
17 m_dynamicState(std::move(Dynamic)),
18 m_shaderStages(std::move(Stages)),
19 m_shaderSources(Sources),
20 m_shaderBindings(Bindings)
21{
22}
23
25{
27}
28
30{
31 if (!IsValidVulkan())
32 return nullptr;
33
35 return m_vulkanRender;
36
38
39 // Create shader
41 {
43 if (!m_vulkanShader)
44 return nullptr;
45 }
46 else
47 {
48 return nullptr;
49 }
50
51 // Create pipeline
52 QRect viewport(QPoint{0, 0}, m_vulkanWindow->swapChainImageSize());
54 if (!m_pipeline)
55 return nullptr;
56
57 // Create projection uniform
58 m_projectionUniform = MythUniformBufferVulkan::Create(this, sizeof(float) * 16);
60 return nullptr;
61
62 // Set projection
63 QMatrix4x4 projection;
64 projection.setToIdentity();
65 projection.ortho(viewport);
66 projection = m_vulkanWindow->clipCorrectionMatrix() * projection;
67 m_projectionUniform->Update(projection.data());
68
69 // Create descriptor pool
70 const auto & sizes = m_vulkanShader->GetPoolSizes(0);
71 VkDescriptorPoolCreateInfo pool { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, nullptr,
72 0, 1, static_cast<uint32_t>(sizes.size()), sizes.data() };
73 if (m_vulkanFuncs->vkCreateDescriptorPool(m_vulkanDevice, &pool, nullptr, &m_descriptorPool) != VK_SUCCESS)
74 {
75 LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create descriptor pool for projection");
76 return nullptr;
77 }
78
79 // Create descriptor
80 VkDescriptorSetLayout layout = m_vulkanShader->GetDescSetLayout(0);
81 VkDescriptorSetAllocateInfo alloc { };
82 alloc.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
83 alloc.descriptorPool = m_descriptorPool;
84 alloc.descriptorSetCount = 1;
85 alloc.pSetLayouts = &layout;
86
87 if (m_vulkanFuncs->vkAllocateDescriptorSets(m_vulkanDevice, &alloc,
88 &m_projectionDescriptor) != VK_SUCCESS)
89 {
90 LOG(VB_GENERAL, LOG_INFO, LOC + "Failed to allocate projection descriptor set");
91 return nullptr;
92 }
93
94 // Update descriptor
95 auto buffdesc = m_projectionUniform->GetBufferInfo();
96 VkWriteDescriptorSet write { };
97 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
99 write.dstBinding = 0;
100 write.dstArrayElement = 0;
101 write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
102 write.descriptorCount = 1;
103 write.pBufferInfo = &buffdesc;
104 m_vulkanFuncs->vkUpdateDescriptorSets(m_vulkanDevice, 1, &write, 0, nullptr);
105
106 return m_vulkanRender;
107}
108
110{
111 if (IsValidVulkan())
112 {
113 if (m_pipeline)
114 m_vulkanFuncs->vkDestroyPipeline(m_vulkanDevice, m_pipeline, nullptr);
116 m_vulkanFuncs->vkDestroyDescriptorPool(m_vulkanDevice, m_descriptorPool, nullptr);
117 }
118
119 delete m_projectionUniform;
120 delete m_vulkanShader;
121
123 m_projectionDescriptor = MYTH_NULL_DISPATCH; // destroyed with pool
125 m_projectionUniform = nullptr;
126 m_vulkanShader = nullptr;
127}
VkPipeline CreatePipeline(MythShaderVulkan *Shader, QRect Viewport, std::vector< VkDynamicState > Dynamic={ })
const std::vector< VkDescriptorPoolSize > & GetPoolSizes(size_t Set) const
VkDescriptorSetLayout GetDescSetLayout(size_t Set) const
static MythShaderVulkan * Create(MythVulkanObject *Vulkan, const std::vector< int > &Stages, const MythShaderMap *Sources=nullptr, const MythBindingMap *Bindings=nullptr)
static MythUniformBufferVulkan * Create(MythVulkanObject *Vulkan, VkDeviceSize Size)
VkDescriptorBufferInfo GetBufferInfo(void) const
virtual void TearDownVulkan()
VkDescriptorPool m_descriptorPool
MythVisualVulkan(MythRenderVulkan *Render, std::vector< VkDynamicState > Dynamic, std::vector< int > Stages, const MythShaderMap *Sources, const MythBindingMap *Bindings)
const MythBindingMap * m_shaderBindings
VkPipeline m_pipeline
std::vector< VkDynamicState > m_dynamicState
virtual MythRenderVulkan * InitialiseVulkan(QRect)
MythUniformBufferVulkan * m_projectionUniform
virtual ~MythVisualVulkan()
std::vector< int > m_shaderStages
VkDescriptorSet m_projectionDescriptor
MythShaderVulkan * m_vulkanShader
const MythShaderMap * m_shaderSources
QVulkanDeviceFunctions * m_vulkanFuncs
MythRenderVulkan * m_vulkanRender
MythWindowVulkan * m_vulkanWindow
bool IsValidVulkan() const
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
#define MYTH_NULL_DISPATCH
std::map< int, std::pair< QString, std::vector< uint32_t > > > MythShaderMap
std::map< int, MythBindingDesc > MythBindingMap
#define LOC
def write(text, progress=True)
Definition: mythburn.py:307
STL namespace.