CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Vulkan/DebugVisVulkan.cpp
Views: 1401
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/UI/View.h"
27
#include "Common/System/Display.h"
28
#include "Common/System/System.h"
29
30
#include "ext/vma/vk_mem_alloc.h"
31
32
#include "DebugVisVulkan.h"
33
#include "Common/GPU/GPUBackendCommon.h"
34
#include "Common/GPU/Vulkan/VulkanMemory.h"
35
#include "Common/GPU/Vulkan/VulkanImage.h"
36
#include "Common/Data/Text/Parsers.h"
37
#include "GPU/Vulkan/GPU_Vulkan.h"
38
#include "GPU/Vulkan/VulkanUtil.h"
39
#include "GPU/Vulkan/TextureCacheVulkan.h"
40
41
#include "Core/Config.h"
42
43
#undef DrawText
44
45
bool comparePushBufferNames(const GPUMemoryManager *a, const GPUMemoryManager *b) {
46
return strcmp(a->Name(), b->Name()) < 0;
47
}
48
49
void DrawGPUMemoryVis(UIContext *ui, GPUInterface *gpu) {
50
// This one will simply display stats.
51
Draw::DrawContext *draw = ui->GetDrawContext();
52
53
std::stringstream str;
54
55
VulkanContext *vulkan = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
56
if (vulkan) {
57
VmaTotalStatistics vmaStats;
58
vmaCalculateStatistics(vulkan->Allocator(), &vmaStats);
59
60
std::vector<VmaBudget> budgets;
61
budgets.resize(vulkan->GetMemoryProperties().memoryHeapCount);
62
vmaGetHeapBudgets(vulkan->Allocator(), &budgets[0]);
63
64
size_t totalBudget = 0;
65
size_t totalUsedBytes = 0;
66
for (auto &budget : budgets) {
67
totalBudget += budget.budget;
68
totalUsedBytes += budget.usage;
69
}
70
71
str << vulkan->GetPhysicalDeviceProperties().properties.deviceName << std::endl;
72
str << "Allocated " << NiceSizeFormat(vmaStats.total.statistics.allocationBytes) << " in " << vmaStats.total.statistics.allocationCount << " allocs" << std::endl;
73
// Note: The overall number includes stuff like descriptor sets pools and other things that are not directly visible as allocations.
74
str << "Overall " << NiceSizeFormat(totalUsedBytes) << " used out of " << NiceSizeFormat(totalBudget) << " available" << std::endl;
75
}
76
77
str << "Push buffers:" << std::endl;
78
79
// Now list the various push buffers.
80
auto managers = GetActiveGPUMemoryManagers();
81
std::sort(managers.begin(), managers.end(), comparePushBufferNames);
82
83
char buffer[512];
84
for (auto manager : managers) {
85
manager->GetDebugString(buffer, sizeof(buffer));
86
str << " " << buffer << std::endl;
87
}
88
89
const int padding = 10 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT);
90
const int starty = 50 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP);
91
int x = padding;
92
int y = starty;
93
94
ui->SetFontScale(0.7f, 0.7f);
95
ui->DrawTextShadow(str.str().c_str(), x, y, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);
96
ui->SetFontScale(1.0f, 1.0f);
97
ui->Flush();
98
}
99
100
void DrawGPUProfilerVis(UIContext *ui, GPUInterface *gpu) {
101
using namespace Draw;
102
const int padding = 10 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT);
103
const int starty = 50 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP);
104
int x = padding;
105
int y = starty;
106
107
ui->Begin();
108
109
float scale = 0.4f;
110
if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) {
111
// Don't have as much info, let's go bigger.
112
scale = 0.7f;
113
}
114
115
std::string text = ui->GetDrawContext()->GetGpuProfileString();
116
117
ui->SetFontScale(0.4f, 0.4f);
118
ui->DrawTextShadow(text.c_str(), x, y, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);
119
ui->SetFontScale(1.0f, 1.0f);
120
ui->Flush();
121
}
122
123