mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-15 00:41:57 +00:00
- transition image layouts and setup pipeline barriers (fixes some errors reported by RenderDoc)
This commit is contained in:
parent
f8aa48d053
commit
b1f161040d
5 changed files with 25 additions and 8 deletions
|
@ -53,6 +53,11 @@ void VkRenderPassManager::BeginFrame()
|
||||||
|
|
||||||
viewbuilder.setImage(SceneDepthStencil.get(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_ASPECT_DEPTH_BIT);
|
viewbuilder.setImage(SceneDepthStencil.get(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_ASPECT_DEPTH_BIT);
|
||||||
SceneDepthView = viewbuilder.create(fb->device);
|
SceneDepthView = viewbuilder.create(fb->device);
|
||||||
|
|
||||||
|
PipelineBarrier barrier;
|
||||||
|
barrier.addImage(SceneColor.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
|
||||||
|
barrier.addImage(SceneDepthStencil.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||||
|
barrier.execute(fb->GetDrawCommands(), 0, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,11 +172,11 @@ VkRenderPassSetup::VkRenderPassSetup(const VkRenderPassKey &key)
|
||||||
void VkRenderPassSetup::CreateRenderPass(const VkRenderPassKey &key)
|
void VkRenderPassSetup::CreateRenderPass(const VkRenderPassKey &key)
|
||||||
{
|
{
|
||||||
RenderPassBuilder builder;
|
RenderPassBuilder builder;
|
||||||
builder.addRgba16fAttachment(false, VK_IMAGE_LAYOUT_GENERAL);
|
builder.addRgba16fAttachment(false, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||||
if (key.DepthTest || key.DepthWrite)
|
if (key.DepthTest || key.DepthWrite)
|
||||||
builder.addDepthStencilAttachment(false, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
builder.addDepthStencilAttachment(false, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||||
builder.addSubpass();
|
builder.addSubpass();
|
||||||
builder.addSubpassColorAttachmentRef(0, VK_IMAGE_LAYOUT_GENERAL);
|
builder.addSubpassColorAttachmentRef(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||||
if (key.DepthTest || key.DepthWrite)
|
if (key.DepthTest || key.DepthWrite)
|
||||||
{
|
{
|
||||||
builder.addSubpassDepthStencilAttachmentRef(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
builder.addSubpassDepthStencilAttachmentRef(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||||
|
|
|
@ -213,7 +213,7 @@ void VkRenderState::Apply(int dt)
|
||||||
passKey.VertexFormat = static_cast<VKVertexBuffer*>(mVertexBuffer)->VertexFormat;
|
passKey.VertexFormat = static_cast<VKVertexBuffer*>(mVertexBuffer)->VertexFormat;
|
||||||
passKey.RenderStyle = mRenderStyle;
|
passKey.RenderStyle = mRenderStyle;
|
||||||
passKey.DepthTest = mDepthTest;
|
passKey.DepthTest = mDepthTest;
|
||||||
passKey.DepthWrite = mDepthWrite;
|
passKey.DepthWrite = mDepthTest && mDepthWrite;
|
||||||
if (mSpecialEffect > EFF_NONE)
|
if (mSpecialEffect > EFF_NONE)
|
||||||
{
|
{
|
||||||
passKey.SpecialEffect = mSpecialEffect;
|
passKey.SpecialEffect = mSpecialEffect;
|
||||||
|
|
|
@ -280,6 +280,7 @@ public:
|
||||||
void addBuffer(VulkanBuffer *buffer, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask);
|
void addBuffer(VulkanBuffer *buffer, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask);
|
||||||
void addBuffer(VulkanBuffer *buffer, VkDeviceSize offset, VkDeviceSize size, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask);
|
void addBuffer(VulkanBuffer *buffer, VkDeviceSize offset, VkDeviceSize size, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask);
|
||||||
void addImage(VulkanImage *image, VkImageLayout oldLayout, VkImageLayout newLayout, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, int baseMipLevel = 0, int levelCount = 1);
|
void addImage(VulkanImage *image, VkImageLayout oldLayout, VkImageLayout newLayout, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, int baseMipLevel = 0, int levelCount = 1);
|
||||||
|
void addImage(VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, int baseMipLevel = 0, int levelCount = 1);
|
||||||
|
|
||||||
void execute(VulkanCommandBuffer *commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags = 0);
|
void execute(VulkanCommandBuffer *commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags = 0);
|
||||||
|
|
||||||
|
@ -1041,6 +1042,11 @@ inline void PipelineBarrier::addBuffer(VulkanBuffer *buffer, VkDeviceSize offset
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void PipelineBarrier::addImage(VulkanImage *image, VkImageLayout oldLayout, VkImageLayout newLayout, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageAspectFlags aspectMask, int baseMipLevel, int levelCount)
|
inline void PipelineBarrier::addImage(VulkanImage *image, VkImageLayout oldLayout, VkImageLayout newLayout, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageAspectFlags aspectMask, int baseMipLevel, int levelCount)
|
||||||
|
{
|
||||||
|
addImage(image->image, oldLayout, newLayout, srcAccessMask, dstAccessMask, aspectMask, baseMipLevel, levelCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void PipelineBarrier::addImage(VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageAspectFlags aspectMask, int baseMipLevel, int levelCount)
|
||||||
{
|
{
|
||||||
VkImageMemoryBarrier barrier = { };
|
VkImageMemoryBarrier barrier = { };
|
||||||
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
|
@ -1050,7 +1056,7 @@ inline void PipelineBarrier::addImage(VulkanImage *image, VkImageLayout oldLayou
|
||||||
barrier.newLayout = newLayout;
|
barrier.newLayout = newLayout;
|
||||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
barrier.image = image->image;
|
barrier.image = image;
|
||||||
barrier.subresourceRange.aspectMask = aspectMask;
|
barrier.subresourceRange.aspectMask = aspectMask;
|
||||||
barrier.subresourceRange.baseMipLevel = baseMipLevel;
|
barrier.subresourceRange.baseMipLevel = baseMipLevel;
|
||||||
barrier.subresourceRange.levelCount = levelCount;
|
barrier.subresourceRange.levelCount = levelCount;
|
||||||
|
|
|
@ -144,7 +144,8 @@ void VulkanFrameBuffer::Update()
|
||||||
auto sceneColor = mRenderPassManager->SceneColor.get();
|
auto sceneColor = mRenderPassManager->SceneColor.get();
|
||||||
|
|
||||||
PipelineBarrier barrier0;
|
PipelineBarrier barrier0;
|
||||||
barrier0.addImage(sceneColor, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
barrier0.addImage(sceneColor, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||||
|
barrier0.addImage(device->swapChain->swapChainImages[device->presentImageIndex], VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||||
barrier0.execute(GetDrawCommands(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
|
barrier0.execute(GetDrawCommands(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||||
|
|
||||||
VkImageBlit blit = {};
|
VkImageBlit blit = {};
|
||||||
|
@ -161,9 +162,14 @@ void VulkanFrameBuffer::Update()
|
||||||
blit.dstSubresource.baseArrayLayer = 0;
|
blit.dstSubresource.baseArrayLayer = 0;
|
||||||
blit.dstSubresource.layerCount = 1;
|
blit.dstSubresource.layerCount = 1;
|
||||||
GetDrawCommands()->blitImage(
|
GetDrawCommands()->blitImage(
|
||||||
sceneColor->image, VK_IMAGE_LAYOUT_GENERAL,
|
sceneColor->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||||
device->swapChain->swapChainImages[device->presentImageIndex], VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR,
|
device->swapChain->swapChainImages[device->presentImageIndex], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||||
1, &blit, VK_FILTER_NEAREST);
|
1, &blit, VK_FILTER_NEAREST);
|
||||||
|
|
||||||
|
PipelineBarrier barrier1;
|
||||||
|
barrier1.addImage(sceneColor, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
|
||||||
|
barrier1.addImage(device->swapChain->swapChainImages[device->presentImageIndex], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
|
||||||
|
barrier1.execute(GetDrawCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
mDrawCommands->end();
|
mDrawCommands->end();
|
||||||
|
|
|
@ -85,7 +85,7 @@ VulkanSwapChain::VulkanSwapChain(VulkanDevice *device, int width, int height, bo
|
||||||
swapChainCreateInfo.imageColorSpace = swapChainFormat.colorSpace;
|
swapChainCreateInfo.imageColorSpace = swapChainFormat.colorSpace;
|
||||||
swapChainCreateInfo.imageExtent = actualExtent;
|
swapChainCreateInfo.imageExtent = actualExtent;
|
||||||
swapChainCreateInfo.imageArrayLayers = 1;
|
swapChainCreateInfo.imageArrayLayers = 1;
|
||||||
swapChainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
swapChainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||||
|
|
||||||
uint32_t queueFamilyIndices[] = { (uint32_t)device->graphicsFamily, (uint32_t)device->presentFamily };
|
uint32_t queueFamilyIndices[] = { (uint32_t)device->graphicsFamily, (uint32_t)device->presentFamily };
|
||||||
if (device->graphicsFamily != device->presentFamily)
|
if (device->graphicsFamily != device->presentFamily)
|
||||||
|
|
Loading…
Reference in a new issue