MythTV  master
mythvisualvulkan.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "mythlogging.h"
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);
115  if (m_descriptorPool)
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 }
MythShaderVulkan::GetDescSetLayout
VkDescriptorSetLayout GetDescSetLayout(size_t Set) const
Definition: mythshadervulkan.cpp:471
MythVisualVulkan::m_vulkanShader
MythShaderVulkan * m_vulkanShader
Definition: mythvisualvulkan.h:23
mythwindowvulkan.h
MythUniformBufferVulkan::GetBufferInfo
VkDescriptorBufferInfo GetBufferInfo(void) const
Definition: mythuniformbuffervulkan.cpp:41
MythShaderVulkan::GetPoolSizes
const std::vector< VkDescriptorPoolSize > & GetPoolSizes(size_t Set) const
Definition: mythshadervulkan.cpp:463
MythVisualVulkan::InitialiseVulkan
virtual MythRenderVulkan * InitialiseVulkan(QRect)
Definition: mythvisualvulkan.cpp:29
MythVisualVulkan::m_shaderStages
std::vector< int > m_shaderStages
Definition: mythvisualvulkan.h:29
MythVulkanObject
Definition: mythrendervulkan.h:29
MYTH_NULL_DISPATCH
#define MYTH_NULL_DISPATCH
Definition: mythrendervulkan.h:26
mythburn.write
def write(text, progress=True)
Definition: mythburn.py:308
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythUniformBufferVulkan::Update
void Update(void *Source)
Definition: mythuniformbuffervulkan.cpp:46
MythVisualVulkan::m_projectionUniform
MythUniformBufferVulkan * m_projectionUniform
Definition: mythvisualvulkan.h:27
MythVisualVulkan::~MythVisualVulkan
virtual ~MythVisualVulkan()
Definition: mythvisualvulkan.cpp:24
MythShaderVulkan::Create
static MythShaderVulkan * Create(MythVulkanObject *Vulkan, const std::vector< int > &Stages, const MythShaderMap *Sources=nullptr, const MythBindingMap *Bindings=nullptr)
Definition: mythshadervulkan.cpp:260
MythVulkanObject::m_vulkanDevice
VkDevice m_vulkanDevice
Definition: mythrendervulkan.h:46
mythuniformbuffervulkan.h
MythVulkanObject::m_vulkanRender
MythRenderVulkan * m_vulkanRender
Definition: mythrendervulkan.h:45
mythlogging.h
LOC
#define LOC
Definition: mythvisualvulkan.cpp:9
MythVisualVulkan::m_shaderBindings
const MythBindingMap * m_shaderBindings
Definition: mythvisualvulkan.h:31
MythVisualVulkan::m_descriptorPool
VkDescriptorPool m_descriptorPool
Definition: mythvisualvulkan.h:25
MythBindingMap
std::map< int, MythBindingDesc > MythBindingMap
Definition: mythshadervulkan.h:18
MythVisualVulkan::MythVisualVulkan
MythVisualVulkan(MythRenderVulkan *Render, std::vector< VkDynamicState > Dynamic, std::vector< int > Stages, const MythShaderMap *Sources, const MythBindingMap *Bindings)
Definition: mythvisualvulkan.cpp:11
MythVisualVulkan::m_shaderSources
const MythShaderMap * m_shaderSources
Definition: mythvisualvulkan.h:30
MythVulkanObject::m_vulkanFuncs
QVulkanDeviceFunctions * m_vulkanFuncs
Definition: mythrendervulkan.h:47
MythVisualVulkan::m_dynamicState
std::vector< VkDynamicState > m_dynamicState
Definition: mythvisualvulkan.h:28
MythVisualVulkan::TearDownVulkan
virtual void TearDownVulkan()
Definition: mythvisualvulkan.cpp:109
MythVisualVulkan::m_pipeline
VkPipeline m_pipeline
Definition: mythvisualvulkan.h:24
MythRenderVulkan::CreatePipeline
VkPipeline CreatePipeline(MythShaderVulkan *Shader, QRect Viewport, std::vector< VkDynamicState > Dynamic={ })
Definition: mythrendervulkan.cpp:639
std
Definition: mythchrono.h:23
MythVulkanObject::m_vulkanWindow
MythWindowVulkan * m_vulkanWindow
Definition: mythrendervulkan.h:48
mythvisualvulkan.h
MythVulkanObject::IsValidVulkan
bool IsValidVulkan() const
Definition: mythrendervulkan.cpp:63
MythShaderMap
std::map< int, std::pair< QString, std::vector< uint32_t > >> MythShaderMap
Definition: mythshadervulkan.h:7
MythRenderVulkan
Definition: mythrendervulkan.h:54
MythUniformBufferVulkan::Create
static MythUniformBufferVulkan * Create(MythVulkanObject *Vulkan, VkDeviceSize Size)
Definition: mythuniformbuffervulkan.cpp:4
MythVisualVulkan::m_projectionDescriptor
VkDescriptorSet m_projectionDescriptor
Definition: mythvisualvulkan.h:26