Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Vulkan/DebugVisVulkan.cpp
3186 views
1
// Copyright (c) 2016- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include <algorithm>
19
#include <sstream>
20
#include <cstring>
21
22
#include "Common/Render/DrawBuffer.h"
23
#include "Common/GPU/thin3d.h"
24
#include "Common/GPU/Vulkan/VulkanContext.h"
25
#include "Common/UI/Context.h"
26
#include "Common/System/System.h"
27
28
#include "ext/vma/vk_mem_alloc.h"
29
30
#include "DebugVisVulkan.h"
31
#include "Common/GPU/GPUBackendCommon.h"
32
#include "Common/GPU/Vulkan/VulkanMemory.h"
33
#include "Common/Data/Text/Parsers.h"
34
#include "GPU/Vulkan/VulkanUtil.h"
35
#include "GPU/Vulkan/TextureCacheVulkan.h"
36
37
#include "Core/Config.h"
38
39
#undef DrawText
40
41
bool comparePushBufferNames(const GPUMemoryManager *a, const GPUMemoryManager *b) {
42
return strcmp(a->Name(), b->Name()) < 0;
43
}
44
45
void DrawGPUMemoryVis(UIContext *ui, GPUDebugInterface *gpu) {
46
// This one will simply display stats.
47
Draw::DrawContext *draw = ui->GetDrawContext();
48
49
std::stringstream str;
50
51
VulkanContext *vulkan = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
52
if (vulkan) {
53
VmaTotalStatistics vmaStats;
54
vmaCalculateStatistics(vulkan->Allocator(), &vmaStats);
55
56
std::vector<VmaBudget> budgets;
57
budgets.resize(vulkan->GetMemoryProperties().memoryHeapCount);
58
vmaGetHeapBudgets(vulkan->Allocator(), &budgets[0]);
59
60
size_t totalBudget = 0;
61
size_t totalUsedBytes = 0;
62
for (auto &budget : budgets) {
63
totalBudget += budget.budget;
64
totalUsedBytes += budget.usage;
65
}
66
67
str << vulkan->GetPhysicalDeviceProperties().properties.deviceName << std::endl;
68
str << "Allocated " << NiceSizeFormat(vmaStats.total.statistics.allocationBytes) << " in " << vmaStats.total.statistics.allocationCount << " allocs" << std::endl;
69
// Note: The overall number includes stuff like descriptor sets pools and other things that are not directly visible as allocations.
70
str << "Overall " << NiceSizeFormat(totalUsedBytes) << " used out of " << NiceSizeFormat(totalBudget) << " available" << std::endl;
71
}
72
73
str << "Push buffers:" << std::endl;
74
75
// Now list the various push buffers.
76
auto managers = GetActiveGPUMemoryManagers();
77
std::sort(managers.begin(), managers.end(), comparePushBufferNames);
78
79
char buffer[512];
80
for (auto manager : managers) {
81
manager->GetDebugString(buffer, sizeof(buffer));
82
str << " " << buffer << std::endl;
83
}
84
85
const int padding = 10 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT);
86
const int starty = 50 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP);
87
int x = padding;
88
int y = starty;
89
90
ui->SetFontScale(0.7f, 0.7f);
91
ui->DrawTextShadow(str.str(), x, y, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);
92
ui->SetFontScale(1.0f, 1.0f);
93
ui->Flush();
94
}
95
96
void DrawGPUProfilerVis(UIContext *ui, GPUDebugInterface *gpu) {
97
using namespace Draw;
98
const int padding = 10 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT);
99
const int starty = 50 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP);
100
int x = padding;
101
int y = starty;
102
103
ui->Begin();
104
105
float scale = 0.4f;
106
if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) {
107
// Don't have as much info, let's go bigger.
108
scale = 0.7f;
109
}
110
111
std::string text = ui->GetDrawContext()->GetGpuProfileString();
112
113
ui->SetFontScale(0.4f, 0.4f);
114
ui->DrawTextShadow(text, x, y, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);
115
ui->SetFontScale(1.0f, 1.0f);
116
ui->Flush();
117
}
118
119