Attach TextureView to FenceCycle

The lifetime of `TextureView` objects wasn't correctly managed as they weren't being attached the the `FenceCycle` in `AttachTexture`, this led to them getting deleted and causing all sorts of UB.
This commit is contained in:
PixelyIon 2022-07-09 19:49:09 +05:30
parent ffaefc82d3
commit cb7c3602e7
No known key found for this signature in database
GPG Key ID: 11BC6C3201BC2C05
2 changed files with 6 additions and 4 deletions

View File

@ -46,7 +46,7 @@ namespace skyline::gpu::interconnect {
lastSubpassDepthStencilAttachment = depthStencilAttachment; lastSubpassDepthStencilAttachment = depthStencilAttachment;
}}; }};
if (renderPass == nullptr || (renderPass && (renderPass->renderArea != renderArea || subpassCount >= gpu.traits.quirks.maxSubpassCount))) { if (renderPass == nullptr || renderPass->renderArea != renderArea || subpassCount >= gpu.traits.quirks.maxSubpassCount) {
// We need to create a render pass if one doesn't already exist or the current one isn't compatible // We need to create a render pass if one doesn't already exist or the current one isn't compatible
if (renderPass != nullptr) if (renderPass != nullptr)
nodes.emplace_back(std::in_place_type_t<node::RenderPassEndNode>()); nodes.emplace_back(std::in_place_type_t<node::RenderPassEndNode>());
@ -101,6 +101,8 @@ namespace skyline::gpu::interconnect {
// Avoids a potential deadlock with this resource being locked while acquiring the TextureManager lock while the thread owning it tries to acquire a lock on this texture // Avoids a potential deadlock with this resource being locked while acquiring the TextureManager lock while the thread owning it tries to acquire a lock on this texture
textureManagerLock.emplace(gpu.texture); textureManagerLock.emplace(gpu.texture);
cycle->AttachObject(view->shared_from_this());
bool didLock{view->LockWithTag(tag)}; bool didLock{view->LockWithTag(tag)};
if (didLock) if (didLock)
attachedTextures.emplace_back(view->texture); attachedTextures.emplace_back(view->texture);
@ -286,7 +288,7 @@ namespace skyline::gpu::interconnect {
nodes.clear(); nodes.clear();
for (const auto &attachedTexture : attachedTextures) { for (const auto &attachedTexture : attachedTextures) {
cycle->AttachObject(attachedTexture.texture); // We don't need to attach the Texture to the cycle as a TextureView will already be attached
cycle->ChainCycle(attachedTexture->cycle); cycle->ChainCycle(attachedTexture->cycle);
attachedTexture->cycle = cycle; attachedTexture->cycle = cycle;
} }

View File

@ -809,7 +809,7 @@ namespace skyline::gpu {
if (source->layout != vk::ImageLayout::eTransferSrcOptimal) { if (source->layout != vk::ImageLayout::eTransferSrcOptimal) {
commandBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eTopOfPipe, vk::PipelineStageFlagBits::eTransfer, {}, {}, {}, vk::ImageMemoryBarrier{ commandBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eTopOfPipe, vk::PipelineStageFlagBits::eTransfer, {}, {}, {}, vk::ImageMemoryBarrier{
.image = sourceBacking, .image = sourceBacking,
.srcAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, .srcAccessMask = vk::AccessFlagBits::eMemoryWrite,
.dstAccessMask = vk::AccessFlagBits::eTransferRead, .dstAccessMask = vk::AccessFlagBits::eTransferRead,
.oldLayout = source->layout, .oldLayout = source->layout,
.newLayout = vk::ImageLayout::eTransferSrcOptimal, .newLayout = vk::ImageLayout::eTransferSrcOptimal,
@ -823,7 +823,7 @@ namespace skyline::gpu {
if (layout != vk::ImageLayout::eTransferDstOptimal) { if (layout != vk::ImageLayout::eTransferDstOptimal) {
commandBuffer.pipelineBarrier(layout != vk::ImageLayout::eUndefined ? vk::PipelineStageFlagBits::eTopOfPipe : vk::PipelineStageFlagBits::eBottomOfPipe, vk::PipelineStageFlagBits::eTransfer, {}, {}, {}, vk::ImageMemoryBarrier{ commandBuffer.pipelineBarrier(layout != vk::ImageLayout::eUndefined ? vk::PipelineStageFlagBits::eTopOfPipe : vk::PipelineStageFlagBits::eBottomOfPipe, vk::PipelineStageFlagBits::eTransfer, {}, {}, {}, vk::ImageMemoryBarrier{
.image = destinationBacking, .image = destinationBacking,
.srcAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, .srcAccessMask = vk::AccessFlagBits::eMemoryRead,
.dstAccessMask = vk::AccessFlagBits::eTransferWrite, .dstAccessMask = vk::AccessFlagBits::eTransferWrite,
.oldLayout = layout, .oldLayout = layout,
.newLayout = vk::ImageLayout::eTransferDstOptimal, .newLayout = vk::ImageLayout::eTransferDstOptimal,