vk: CommandPool size must be 2. Fix lightgun xhair validation error

This commit is contained in:
Flyinghead 2021-09-27 11:19:50 +02:00
parent 4e019cc233
commit fb40bb22df
3 changed files with 19 additions and 16 deletions

View File

@ -26,26 +26,24 @@ class CommandPool
public:
void Init()
{
size_t size = VulkanContext::Instance()->GetSwapChainSize();
if (commandPools.size() > size)
if (commandPools.size() > chainSize)
{
commandPools.resize(size);
fences.resize(size);
commandPools.resize(chainSize);
fences.resize(chainSize);
}
else
{
while (commandPools.size() < size)
while (commandPools.size() < chainSize)
{
commandPools.push_back(VulkanContext::Instance()->GetDevice().createCommandPoolUnique(
vk::CommandPoolCreateInfo(vk::CommandPoolCreateFlagBits::eTransient, VulkanContext::Instance()->GetGraphicsQueueFamilyIndex())));
fences.push_back(VulkanContext::Instance()->GetDevice().createFenceUnique(vk::FenceCreateInfo(vk::FenceCreateFlagBits::eSignaled)));
}
}
if (freeBuffers.size() != size)
freeBuffers.resize(size);
if (inFlightBuffers.size() != size)
inFlightBuffers.resize(size);
if (freeBuffers.size() != chainSize)
freeBuffers.resize(chainSize);
if (inFlightBuffers.size() != chainSize)
inFlightBuffers.resize(chainSize);
}
void Term()
@ -64,7 +62,7 @@ public:
void BeginFrame()
{
index = (index + 1) % VulkanContext::Instance()->GetSwapChainSize();
index = (index + 1) % chainSize;
VulkanContext::Instance()->GetDevice().waitForFences(1, &fences[index].get(), true, UINT64_MAX);
VulkanContext::Instance()->GetDevice().resetFences(1, &fences[index].get());
std::vector<vk::UniqueCommandBuffer>& inFlight = inFlightBuffers[index];
@ -106,4 +104,6 @@ private:
std::vector<std::vector<vk::UniqueCommandBuffer>> inFlightBuffers;
std::vector<vk::UniqueCommandPool> commandPools;
std::vector<vk::UniqueFence> fences;
// size should be the same as used by client: 2 for renderer (texCommandPool)
static constexpr size_t chainSize = 2;
};

View File

@ -197,7 +197,7 @@ void VulkanOverlay::Draw(vk::CommandBuffer commandBuffer, vk::Extent2D viewport,
((color >> 16) & 0xff) / 255.f,
((color >> 24) & 0xff) / 255.f
};
xhairDrawer->Draw(commandBuffer, xhairTexture->GetImageView(), vtx, true, xhairColor);
xhairDrawer->Draw(commandBuffer, i == 0 ? xhairTexture->GetImageView() : vk::ImageView(), vtx, true, xhairColor);
}
}
}

View File

@ -197,10 +197,13 @@ void QuadDrawer::Draw(vk::CommandBuffer commandBuffer, vk::ImageView imageView,
descSet = std::move(context->GetDevice().allocateDescriptorSetsUnique(
vk::DescriptorSetAllocateInfo(context->GetDescriptorPool(), 1, &layout)).front());
}
vk::DescriptorImageInfo imageInfo(nearestFilter ? pipeline->GetNearestSampler() : pipeline->GetLinearSampler(), imageView, vk::ImageLayout::eShaderReadOnlyOptimal);
std::vector<vk::WriteDescriptorSet> writeDescriptorSets;
writeDescriptorSets.emplace_back(*descSet, 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr);
context->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr);
if (imageView)
{
vk::DescriptorImageInfo imageInfo(nearestFilter ? pipeline->GetNearestSampler() : pipeline->GetLinearSampler(), imageView, vk::ImageLayout::eShaderReadOnlyOptimal);
std::vector<vk::WriteDescriptorSet> writeDescriptorSets;
writeDescriptorSets.emplace_back(*descSet, 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr);
context->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr);
}
commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline->GetPipelineLayout(), 0, 1, &descSet.get(), 0, nullptr);
buffer->Update(vertices);