GPUOpen-LibrariesAndSDKs / VulkanMemoryAllocator

Easy to integrate Vulkan memory allocation library
MIT License
2.61k stars 355 forks source link

Added a Perfetto python dump #382

Open alecazam opened 11 months ago

alecazam commented 11 months ago

This uses the Catapult flame chart json format for timings. This can then be imported into Perfetto.

Allocations are displayed in tracks just like in the png, but with names, and the values can be zoomed in-out and scrolled through. Perfetto seems to keep trying to kill off this json, without offering an alternative, but it works okay for this.

Timestamp is the offset, and duration correspond to size. These are all displayed as timings (either ns or ms), but should all be drawn with rect corresponding to the sizes. Perfetto still doesn't have hover over the values to expand name/duration, but that would help here.

https://github.com/alecazam/kram/blob/main/scripts/GpuMemDumpPerfetto.py

Here's a screenshot of Perfetto with the default dump. "M" indicates free blocks, since empty string seems to break Perfetto. And I can't specify colors either. But unique names each get pseudo-colored in a block track.

image
alecazam commented 11 months ago

Here's the output from the Sample.json file. This can be dropped onto the trace viewer at perfetto.dev.

GpuMemDumpSample.trace.zip

alecazam commented 11 months ago

In Perfetto, hit ctrl+shift+P, set_timestamp_format to seconds. Then the seconds represent MB, and have vertical lines. Reading the values in seconds provides MB values when blocks are selected. This works great when all allocations have names, but this Sample.json barely has any. It's not a real example of a game capture which would have these details present.

adam-sawicki-a commented 11 months ago

This is an interesting development. Thank you for sharing this. Although, one could say that using a profiler like this to visualize memory allocations, with allocation sizes faked into time units, is a bit hacky.

alecazam commented 11 months ago

It's really no less of a hack than using a static png image to display what should be an interactive display that leaves out the blocks names of a heap. There's AMD Memory Visualizer and it curiously skips importing dump files from VMA. So that would be the next target I would say for a real UI.

Also Perfetto has a generic trace event api, but there's no Python API to it. But a C++ app could be built to call and build events that way. There is a heap profiler that feeds into Perfetto, so it's not just timings.

Also I think tagging aliasing in blocks would be useful for this (could skip) or draw them differently. Also for the MemVis to png.

adam-sawicki-a commented 11 months ago

Yes, I agree, it would be best to develop an interactive GUI tools for browsing VMA JSON dumps.

Radeon Memory Visualizer is a completely different tool with different purpose and has nothing to do with VMA. It captures memory allocation events as made by DX12/Vulkan app on low level, directly from AMD graphics driver.

alecazam commented 11 months ago

Sure, but RMV has many of the same visualizers. I will say that seeing unnamed blocks in the PNG was useful, but being able to see allocation names and sizes is a game changer. We used to just draw all this stuff in games using the gpu, and could bring it up in any game. There are apps like Tracy, Superluminal, etc that do this. But the code is pretty easy to write so long as it's not written using Vulkan.

image