CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Vulkan/DebugVisVulkan.cpp
Views: 1401
// Copyright (c) 2016- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include <algorithm>18#include <sstream>19#include <cstring>2021#include "Common/Render/DrawBuffer.h"22#include "Common/GPU/thin3d.h"23#include "Common/GPU/Vulkan/VulkanContext.h"24#include "Common/UI/Context.h"25#include "Common/UI/View.h"26#include "Common/System/Display.h"27#include "Common/System/System.h"2829#include "ext/vma/vk_mem_alloc.h"3031#include "DebugVisVulkan.h"32#include "Common/GPU/GPUBackendCommon.h"33#include "Common/GPU/Vulkan/VulkanMemory.h"34#include "Common/GPU/Vulkan/VulkanImage.h"35#include "Common/Data/Text/Parsers.h"36#include "GPU/Vulkan/GPU_Vulkan.h"37#include "GPU/Vulkan/VulkanUtil.h"38#include "GPU/Vulkan/TextureCacheVulkan.h"3940#include "Core/Config.h"4142#undef DrawText4344bool comparePushBufferNames(const GPUMemoryManager *a, const GPUMemoryManager *b) {45return strcmp(a->Name(), b->Name()) < 0;46}4748void DrawGPUMemoryVis(UIContext *ui, GPUInterface *gpu) {49// This one will simply display stats.50Draw::DrawContext *draw = ui->GetDrawContext();5152std::stringstream str;5354VulkanContext *vulkan = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);55if (vulkan) {56VmaTotalStatistics vmaStats;57vmaCalculateStatistics(vulkan->Allocator(), &vmaStats);5859std::vector<VmaBudget> budgets;60budgets.resize(vulkan->GetMemoryProperties().memoryHeapCount);61vmaGetHeapBudgets(vulkan->Allocator(), &budgets[0]);6263size_t totalBudget = 0;64size_t totalUsedBytes = 0;65for (auto &budget : budgets) {66totalBudget += budget.budget;67totalUsedBytes += budget.usage;68}6970str << vulkan->GetPhysicalDeviceProperties().properties.deviceName << std::endl;71str << "Allocated " << NiceSizeFormat(vmaStats.total.statistics.allocationBytes) << " in " << vmaStats.total.statistics.allocationCount << " allocs" << std::endl;72// Note: The overall number includes stuff like descriptor sets pools and other things that are not directly visible as allocations.73str << "Overall " << NiceSizeFormat(totalUsedBytes) << " used out of " << NiceSizeFormat(totalBudget) << " available" << std::endl;74}7576str << "Push buffers:" << std::endl;7778// Now list the various push buffers.79auto managers = GetActiveGPUMemoryManagers();80std::sort(managers.begin(), managers.end(), comparePushBufferNames);8182char buffer[512];83for (auto manager : managers) {84manager->GetDebugString(buffer, sizeof(buffer));85str << " " << buffer << std::endl;86}8788const int padding = 10 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT);89const int starty = 50 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP);90int x = padding;91int y = starty;9293ui->SetFontScale(0.7f, 0.7f);94ui->DrawTextShadow(str.str().c_str(), x, y, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);95ui->SetFontScale(1.0f, 1.0f);96ui->Flush();97}9899void DrawGPUProfilerVis(UIContext *ui, GPUInterface *gpu) {100using namespace Draw;101const int padding = 10 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT);102const int starty = 50 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP);103int x = padding;104int y = starty;105106ui->Begin();107108float scale = 0.4f;109if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) {110// Don't have as much info, let's go bigger.111scale = 0.7f;112}113114std::string text = ui->GetDrawContext()->GetGpuProfileString();115116ui->SetFontScale(0.4f, 0.4f);117ui->DrawTextShadow(text.c_str(), x, y, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);118ui->SetFontScale(1.0f, 1.0f);119ui->Flush();120}121122123