From 399e1fac2a58b694c9b050b7d32d2e162acdc4e7 Mon Sep 17 00:00:00 2001 From: DrChat Date: Fri, 13 Apr 2018 21:09:21 -0500 Subject: [PATCH] [Vulkan] Gracefully fail on copy if a target format is unsupported --- src/xenia/gpu/vulkan/texture_cache.cc | 8 +++----- src/xenia/gpu/vulkan/texture_cache.h | 1 + src/xenia/gpu/vulkan/vulkan_command_processor.cc | 12 +++++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/xenia/gpu/vulkan/texture_cache.cc b/src/xenia/gpu/vulkan/texture_cache.cc index 558e796ba..9d433f6f1 100644 --- a/src/xenia/gpu/vulkan/texture_cache.cc +++ b/src/xenia/gpu/vulkan/texture_cache.cc @@ -277,7 +277,6 @@ TextureCache::Texture* TextureCache::AllocateTexture( static_cast(required_flags & ~props.optimalTilingFeatures)) .c_str()); - assert_always(); } if (texture_info.dimension != Dimension::kCube && @@ -331,6 +330,7 @@ TextureCache::Texture* TextureCache::AllocateTexture( texture->alloc = alloc; texture->alloc_info = vma_info; texture->framebuffer = nullptr; + texture->usage_flags = image_info.usage; texture->access_watch_handle = 0; texture->texture_info = texture_info; return texture; @@ -410,8 +410,7 @@ TextureCache::Texture* TextureCache::DemandResolveTexture( // No texture at this location. Make a new one. auto texture = AllocateTexture(texture_info, required_flags); if (!texture) { - // Failed to allocate texture (out of memory?) - assert_always(); + // Failed to allocate texture (out of memory) XELOGE("Vulkan Texture Cache: Failed to allocate texture!"); return nullptr; } @@ -463,8 +462,7 @@ TextureCache::Texture* TextureCache::Demand(const TextureInfo& texture_info, // Create a new texture and cache it. auto texture = AllocateTexture(texture_info); if (!texture) { - // Failed to allocate texture (out of memory?) - assert_always(); + // Failed to allocate texture (out of memory) XELOGE("Vulkan Texture Cache: Failed to allocate texture!"); return nullptr; } diff --git a/src/xenia/gpu/vulkan/texture_cache.h b/src/xenia/gpu/vulkan/texture_cache.h index af1e10447..6be4a6660 100644 --- a/src/xenia/gpu/vulkan/texture_cache.h +++ b/src/xenia/gpu/vulkan/texture_cache.h @@ -47,6 +47,7 @@ class TextureCache { VmaAllocation alloc; VmaAllocationInfo alloc_info; VkFramebuffer framebuffer; // Blit target frame buffer. + VkImageUsageFlags usage_flags; uintptr_t access_watch_handle; bool pending_invalidation; diff --git a/src/xenia/gpu/vulkan/vulkan_command_processor.cc b/src/xenia/gpu/vulkan/vulkan_command_processor.cc index 235aa81ff..b4020bea8 100644 --- a/src/xenia/gpu/vulkan/vulkan_command_processor.cc +++ b/src/xenia/gpu/vulkan/vulkan_command_processor.cc @@ -1024,7 +1024,17 @@ bool VulkanCommandProcessor::IssueCopy() { std::max(1u, dest_logical_height), &texture_info); auto texture = texture_cache_->DemandResolveTexture(texture_info); - assert_not_null(texture); + if (!texture) { + // Out of memory. + return false; + } + + if (!(texture->usage_flags & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT))) { + // Resolve image doesn't support drawing, and we don't support conversion. + return false; + } + texture->in_flight_fence = current_batch_fence_; // For debugging purposes only (trace viewer)