From fc32a7b24efb7a80651d261d643201d9fae8e622 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 5 Nov 2017 18:04:56 -0800 Subject: [PATCH] Vulkan: Show textures in GE debugger. --- Common/Vulkan/VulkanImage.h | 3 +- GPU/Vulkan/TextureCacheVulkan.cpp | 60 +++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Common/Vulkan/VulkanImage.h b/Common/Vulkan/VulkanImage.h index cc303a7460..b84913c0d0 100644 --- a/Common/Vulkan/VulkanImage.h +++ b/Common/Vulkan/VulkanImage.h @@ -35,7 +35,6 @@ public: void UploadMip(VkCommandBuffer cmd, int mip, int mipWidth, int mipHeight, VkBuffer buffer, uint32_t offset, size_t rowLength); // rowLength is in pixels void EndCreate(VkCommandBuffer cmd); - int GetNumMips() const { return numMips_; } void Destroy(); // Used in image copies, etc. @@ -46,6 +45,8 @@ public: int32_t GetWidth() const { return tex_width; } int32_t GetHeight() const { return tex_height; } + int32_t GetNumMips() const { return numMips_; } + VkFormat GetFormat() const { return format_; } private: void CreateMappableImage(); diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 8826278327..20664c7831 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -809,6 +809,62 @@ void TextureCacheVulkan::LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePt } bool TextureCacheVulkan::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { - // TODO - return false; + ApplyTexture(); + SetTexture(false); + if (!nextTexture_) + return false; + + // TODO: Centralize? + if (nextTexture_->framebuffer) { + VirtualFramebuffer *vfb = nextTexture_->framebuffer; + bool flipY = g_Config.iGPUBackend == GPU_BACKEND_OPENGL && g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; + buffer.Allocate(vfb->bufferWidth, vfb->bufferHeight, GPU_DBG_FORMAT_8888, flipY); + bool retval = draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_COLOR_BIT, 0, 0, vfb->bufferWidth, vfb->bufferHeight, Draw::DataFormat::R8G8B8A8_UNORM, buffer.GetData(), vfb->bufferWidth); + // Vulkan requires us to re-apply all dynamic state for each command buffer, and the above will cause us to start a new cmdbuf. + // So let's dirty the things that are involved in Vulkan dynamic state. Readbacks are not frequent so this won't hurt other backends. + gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); + // We may have blitted to a temp FBO. + framebufferManager_->RebindFramebuffer(); + return retval; + } + + if (!nextTexture_->vkTex || !nextTexture_->vkTex->texture_) + return false; + VulkanTexture *texture = nextTexture_->vkTex->texture_; + VulkanRenderManager *renderManager = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); + + GPUDebugBufferFormat bufferFormat; + Draw::DataFormat drawFormat; + switch (texture->GetFormat()) { + case VULKAN_565_FORMAT: + bufferFormat = GPU_DBG_FORMAT_565; + drawFormat = Draw::DataFormat::B5G6R5_UNORM_PACK16; + break; + case VULKAN_1555_FORMAT: + bufferFormat = GPU_DBG_FORMAT_5551; + drawFormat = Draw::DataFormat::B5G5R5A1_UNORM_PACK16; + break; + case VULKAN_4444_FORMAT: + bufferFormat = GPU_DBG_FORMAT_4444; + drawFormat = Draw::DataFormat::B4G4R4A4_UNORM_PACK16; + break; + case VULKAN_8888_FORMAT: + default: + bufferFormat = GPU_DBG_FORMAT_8888; + drawFormat = Draw::DataFormat::R8G8B8A8_UNORM; + break; + } + + int w = texture->GetWidth(); + int h = texture->GetHeight(); + buffer.Allocate(w, h, bufferFormat); + + renderManager->CopyImageToMemorySync(texture->GetImage(), level, 0, 0, w, h, drawFormat, (uint8_t *)buffer.GetData(), w); + + // Vulkan requires us to re-apply all dynamic state for each command buffer, and the above will cause us to start a new cmdbuf. + // So let's dirty the things that are involved in Vulkan dynamic state. Readbacks are not frequent so this won't hurt other backends. + gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); + framebufferManager_->RebindFramebuffer(); + + return true; }