5#include <QGuiApplication>
18#define LOC QString("VulkanPainter: ")
50 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Releasing Vulkan resources");
84 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Finished releasing resources");
112 newtop.translate(
static_cast<float>(Center.x()),
static_cast<float>(Center.y()));
114 newtop.rotate(Fx.
m_angle, 0, 0, 1);
115 newtop.translate(
static_cast<float>(-Center.x()),
static_cast<float>(-Center.y()));
135 if (!window || !window->device())
153 QRect viewport(QPoint{0, 0},
m_vulkan->
Window()->swapChainImageSize());
162 VkDescriptorPoolCreateInfo pool { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
nullptr,
163 0, 1,
static_cast<uint32_t
>(sizes.size()), sizes.data() };
166 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to create descriptor pool for projection");
178 QRect viewport(QPoint{0, 0},
m_vulkan->
Window()->swapChainImageSize());
188 VkDescriptorSetAllocateInfo alloc { };
189 alloc.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
191 alloc.descriptorSetCount = 1;
192 alloc.pSetLayouts = &layout;
196 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Failed to allocate projection descriptor set");
202 VkWriteDescriptorSet
write { };
203 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
205 write.dstBinding = 0;
206 write.dstArrayElement = 0;
207 write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
208 write.descriptorCount = 1;
209 write.pBufferInfo = &buffdesc;
218 std::vector<VkDescriptorPoolSize> adjsizes;
219 std::transform(sizes.cbegin(), sizes.cend(), std::back_inserter(adjsizes),
220 [](VkDescriptorPoolSize Size){ return VkDescriptorPoolSize { Size.type, MAX_TEXTURE_COUNT }; });
221 VkDescriptorPoolCreateInfo pool { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
nullptr,
225 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to create descriptor pool");
230 if (!m_textureDescriptorsCreated)
233 VkDescriptorSetLayout layout = m_textureShader->GetDescSetLayout(1);
234 m_availableTextureDescriptors.clear();
238 VkDescriptorSetAllocateInfo alloc { };
239 alloc.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
240 alloc.descriptorPool = m_textureDescriptorPool;
241 alloc.descriptorSetCount = 1;
242 alloc.pSetLayouts = &layout;
243 VkResult res = m_vulkan->Funcs()->vkAllocateDescriptorSets(m_vulkan->Device(), &alloc, &descset);
244 if (res != VK_SUCCESS)
245 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Failed to allocate descriptor set");
246 m_availableTextureDescriptors.push_back(descset);
249 m_textureDescriptorsCreated =
true;
252 if (!m_textureSampler)
254 m_textureSampler = m_vulkan->Render()->CreateSampler(VK_FILTER_LINEAR, VK_FILTER_LINEAR);
255 if (!m_textureSampler)
279 static const int s_onehd = 1920 * 1080;
280 static const int s_basesize = 64;
283 int cpu = std::max(
static_cast<int>(hdscreens * s_basesize), s_basesize);
284 int gpu = cpu * 3 / 2;
314 texture->StagingFinished();
328 QEvent update(QEvent::UpdateRequest);
333 VkCommandBuffer currentcmdbuf =
m_vulkan->
Window()->currentCommandBuffer();
342 m_vulkan->
Funcs()->vkCmdBindDescriptorSets(currentcmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS,
348 m_vulkan->
Funcs()->vkCmdBindDescriptorSets(currentcmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS,
349 layout, 1, 1, &texture->m_descriptor, 0,
nullptr);
352 m_vulkan->
Funcs()->vkCmdPushConstants(currentcmdbuf, layout, VK_SHADER_STAGE_VERTEX_BIT,
401 LOG(VB_GENERAL, LOG_INFO,
"Clearing Vulkan painter cache.");
415 if (!(
Ready() && Image))
433 while (texture ==
nullptr)
438 if (texture !=
nullptr)
444 LOG(VB_GENERAL, LOG_ERR,
"Failed to create Vulkan texture.");
450 LOG(VB_GENERAL, LOG_NOTICE,
LOC + QString(
"Shrinking HW cache size to %1KB")
464 LOG(VB_GENERAL, LOG_ERR,
LOC +
"No descriptor pool?");
482 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"No texture descriptor available??");
492 VkWriteDescriptorSet
write { };
493 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
494 write.dstSet = descset;
495 write.dstBinding = 0;
496 write.dstArrayElement = 0;
497 write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
498 write.descriptorCount = 1;
499 write.pImageInfo = &imagedesc;
void PushData(const QMatrix4x4 &Transform, QRect Source, QRect Destination, int Alpha)
static const MythVulkan4F kDebugGreen
virtual void SetChanged(bool change=true)
ViewControls m_viewControl
void DeleteFormatImagePriv(MythImage *Image) override
MythImage * GetFormatImagePriv() override
Creates a reference counted image, call DecrRef() to delete.
MythUniformBufferVulkan * m_projectionUniform
QString GetName() override
void DrawImage(QRect Dest, MythImage *Image, QRect Source, int Alpha) override
QStack< QMatrix4x4 > m_transforms
MythTextureVulkan * GetTextureFromCache(MythImage *Image)
void Begin(QPaintDevice *) override
Begin painting.
bool SupportsAnimation() override
std::vector< VkDescriptorSet > m_availableTextureDescriptors
VkDescriptorPool m_textureDescriptorPool
void DoFreeResources()
Free resources before the render device is released.
void PopTransformation() override
VkDescriptorSet m_projectionDescriptor
MythPainterVulkan(MythRenderVulkan *VulkanRender, MythMainWindow *Parent)
bool SupportsAlpha() override
QMap< MythImage *, MythTextureVulkan * > m_imageToTextureMap
QVector< MythTextureVulkan * > m_texturesToDelete
std::vector< MythTextureVulkan * > m_queuedTextures
bool SupportsClipping() override
VkSampler m_textureSampler
std::vector< MythTextureVulkan * > m_stagedTextures
VkDescriptorPool m_projectionDescriptorPool
VkCommandBuffer m_textureUploadCmd
VkPipeline m_texturePipeline
std::list< MythImage * > m_imageExpire
void FreeResources() override
~MythPainterVulkan() override
MythVulkanObject * m_vulkan
MythShaderVulkan * m_textureShader
void PushTransformation(const UIEffects &Fx, QPointF Center=QPointF()) override
bool m_textureDescriptorsCreated
void CheckFormatImage(MythImage *im)
void SetMaximumCacheSizes(int hardware, int software)
int m_maxHardwareCacheSize
virtual void Teardown(void)
virtual void FreeResources(void)
MythWindowVulkan * GetVulkanWindow(void)
static MythRenderVulkan * GetVulkanRender(void)
void FinishSingleUseCommandBuffer(VkCommandBuffer &Buffer)
void EndDebugRegion(VkCommandBuffer CommandBuffer)
VkPipeline CreatePipeline(MythShaderVulkan *Shader, QRect Viewport, std::vector< VkDynamicState > Dynamic={ })
VkCommandBuffer CreateSingleUseCommandBuffer(void)
void SetFrameExpected(void)
void DoFreeResources(void)
void BeginDebugRegion(VkCommandBuffer CommandBuffer, const char *Name, MythVulkan4F Color)
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)
VkPipelineLayout GetPipelineLayout(void) const
VkDescriptorImageInfo GetDescriptorImage(void) const
void AddDescriptor(VkDescriptorSet Descriptor)
VkDescriptorSet TakeDescriptor(void)
static MythTextureVulkan * Create(MythVulkanObject *Vulkan, QImage *Image, VkSampler Sampler, VkCommandBuffer CommandBuffer=nullptr)
MythRenderVulkan * Render()
bool IsValidVulkan() const
MythWindowVulkan * Window()
QVulkanDeviceFunctions * Funcs()
static MythVulkanObject * Create(MythRenderVulkan *Render)
#define MYTH_PUSHBUFFER_SIZE
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
#define MAX_TEXTURE_COUNT
#define MYTH_NULL_DISPATCH
#define DefaultFragment450
def write(text, progress=True)