Debug visualization for the Vulkan memory allocator. Shows some interesting behaviour.

This commit is contained in:
Henrik Rydgård committed 2018-01-29 19:38:10 +01:00
1 parent 2ae2dd7d40
commit c60c8ed68a
18 files changed
+168 -15

No files matched your search

+3 -1
View File
@@ -256,6 +256,7 @@
<ClInclude Include="Software\SoftGpu.h" />
<ClInclude Include="Software\TransformUnit.h" />
<ClInclude Include="Common\TextureDecoder.h" />
<ClInclude Include="Vulkan\DebugVisVulkan.h" />
<ClInclude Include="Vulkan\DepalettizeShaderVulkan.h" />
<ClInclude Include="Vulkan\DrawEngineVulkan.h" />
<ClInclude Include="Vulkan\FragmentShaderGeneratorVulkan.h" />
@@ -360,6 +361,7 @@
<ClCompile Include="Software\SoftGpu.cpp" />
<ClCompile Include="Software\TransformUnit.cpp" />
<ClCompile Include="Common\TextureDecoder.cpp" />
<ClCompile Include="Vulkan\DebugVisVulkan.cpp" />
<ClCompile Include="Vulkan\DepalettizeShaderVulkan.cpp" />
<ClCompile Include="Vulkan\DrawEngineVulkan.cpp" />
<ClCompile Include="Vulkan\FragmentShaderGeneratorVulkan.cpp" />
@@ -385,4 +387,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
+3 -1
View File
@@ -270,6 +270,7 @@
<ClInclude Include="D3D11\StateMappingD3D11.h">
<Filter>D3D11</Filter>
</ClInclude>
<ClInclude Include="Vulkan\DebugVisVulkan.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Math3D.cpp">
@@ -536,5 +537,6 @@
<ClCompile Include="Common\StencilCommon.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Vulkan\DebugVisVulkan.cpp" />
</ItemGroup>
</Project>
</Project>
+93
View File
@@ -0,0 +1,93 @@
// Copyright (c) 2016- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "DebugVisVulkan.h"
#include "Common/Vulkan/VulkanMemory.h"
#include "Common/Vulkan/VulkanImage.h"
#include "GPU/Vulkan/GPU_Vulkan.h"
#include "GPU/Vulkan/VulkanUtil.h"
#include "gfx_es2/draw_buffer.h"
#include "thin3d/thin3d.h"
#include "ui/ui_context.h"
#include "ui/view.h"
void DrawAllocatorVis(UIContext *ui, GPUInterface *gpu) {
if (!gpu) {
return;
}
using namespace Draw;
const int padding = 10;
const int columnWidth = 256;
const int starty = padding * 8;
int x = padding;
int y = starty;
int w = columnWidth; // We will double this when actually drawing to make the pixels visible.
ui->End();
ui->Begin();
GPU_Vulkan *gpuVulkan = static_cast<GPU_Vulkan *>(gpu);
VulkanDeviceAllocator *alloc = gpuVulkan->GetTextureCache()->GetAllocator();
std::vector<Draw::Texture *> texturesToDelete;
for (int i = 0; i < alloc->GetSlabCount(); i++) {
std::vector<uint8_t> usage = alloc->GetSlabUsage(i);
int h = ((int)usage.size() + w - 1) / w;
if (y + h + padding > ui->GetBounds().h) {
y = starty;
x += columnWidth + padding;
}
std::vector<uint8_t> initData(w * h * 4);
uint32_t *wideData = (uint32_t *)initData.data();
// Convert to nice colors. If we really wanted to save on memory, we could use a 16-bit texture...
for (int j = 0; j < usage.size(); j++) {
switch (usage[j]) {
case 0: wideData[j] = 0xFF333333; break;
case 1: wideData[j] = 0xFF33FF33; break;
case 2: wideData[j] = 0xFF3333FF; break;
default: wideData[j] = 0xFFFF00FF; break; // Magenta - if you see this, need to add more cases.
}
}
Draw::TextureDesc desc{};
desc.width = w;
desc.height = h;
desc.depth = 1;
desc.format = Draw::DataFormat::R8G8B8A8_UNORM;
desc.mipLevels = 1;
desc.type = Draw::TextureType::LINEAR2D;
desc.initData.push_back(initData.data());
Draw::DrawContext *draw = ui->GetDrawContext();
Draw::Texture *tex = draw->CreateTexture(desc);
UI::Drawable white(0xFFFFFFFF);
draw->BindTexture(0, tex);
ui->Draw()->Rect(x, y, w, h, 0xFFFFFFFF);
ui->Flush();
texturesToDelete.push_back(tex);
y += h + padding;
}
ui->Flush();
for (auto iter : texturesToDelete)
iter->Release();
}
+26
View File
@@ -0,0 +1,26 @@
// Copyright (c) 2016- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include "thin3d/thin3d.h"
class GPUInterface;
class UIContext;
// gpu MUST be an instance of GPU_Vulkan. If not, will definitely crash.
void DrawAllocatorVis(UIContext *ui, GPUInterface *gpu);
+4
View File
@@ -78,6 +78,10 @@ public:
std::vector<std::string> DebugGetShaderIDs(DebugShaderType shader) override;
std::string DebugGetShaderString(std::string id, DebugShaderType shader, DebugShaderStringType stringType) override;
TextureCacheVulkan *GetTextureCache() {
return textureCacheVulkan_;
}
protected:
void FastRunLoop(DisplayList &list) override;
void FinishDeferred() override;
+1 -1
View File
@@ -845,7 +845,7 @@ bool TextureCacheVulkan::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int leve
void TextureCacheVulkan::GetStats(char *ptr, size_t size) {
snprintf(ptr, size, "Alloc: %d slabs\nSlab min/max: %d/%d\nAlloc usage: %d%%",
allocator_->GetBlockCount(), allocator_->GetMinSlabSize(), allocator_->GetMaxSlabSize(), allocator_->ComputeUsagePercent());
allocator_->GetSlabCount(), allocator_->GetMinSlabSize(), allocator_->GetMaxSlabSize(), allocator_->ComputeUsagePercent());
}
std::vector<std::string> TextureCacheVulkan::DebugGetSamplerIDs() const {
+2
View File
@@ -54,6 +54,8 @@ public:
Vulkan2D(VulkanContext *vulkan);
~Vulkan2D();
VulkanContext *GetVulkanContext() const { return vulkan_; }
void DeviceLost();
void DeviceRestore(VulkanContext *vulkan);
void Shutdown();