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;