google / gapid

Graphics API Debugger
https://gapid.dev
Apache License 2.0
2.2k stars 327 forks source link

API for scripting #2943

Open pemgithub opened 5 years ago

pemgithub commented 5 years ago

Are there any plans to add an API to view/edit a trace file (*.gfxtrace) (eg in C++/Python)? Or does such an API already exist? Basically an API that lets you do everything that you can do in the gapid GUI and gapit CLI (view/edit, record/replay), except through a C++/Python API.

Background. I wrote an internal tool (at a GPU company) that's similar to GAPID, except the traces are closer to the metal - it records what the GPU driver submits to the GPU (command buffers, GPU state). Like GAPID, the internal tool has a GUI where you can view/edit GPU state. For example, GUI lets you view shaders (memory or diasm string) and edit shaders (except the shaders are ASIC-specific disassembly rather than GLSL or SPIR-V).

In addition to the trace editor GUI, there's a C++/Python API (Python support via SWIG) that lets you walk through the trace's command buffer tree (the same one that's displayed in the GUI), and read or modify GPU state. Such that everything you can do in the GUI (view, edit) can also be done via the API.

For example, you can write a Python script to search the trace for shader programs, and collect information on the shader programs (eg count how many times a particular instruction is used). Or you can write a Python script to conditionally edit shader programs (if the new shader program consumes more memory than the old shader, then the editor automatically moves it to a new capture-time address range). Or to gather arbitrary stats on geometry, textures, texture formats used, etc.

For GAPID to have a similar API, this would mean a C++/Python API to read a GAPID trace's commands, framebuffer, textures, geometry, shaders, report, state, memory (as seen in GAPID GUI). And to allow editing, such as GUI's Push Changes to edit a shader program. And, more broadly, to do anything via the API that you can do via the GUI and CLI.

I see that gapit ( https://gapid.dev/cli/ ) does some of this. Eg gapit commands, gapit state, gapit dump_resources. Though CLI is limited vs API, and I think the things you can do via GUI vs CLI are not in sync (though there is overlap).

Partly just sharing the API idea in case it's useful, and making sure I didn't miss something... thank you

AWoloszyn commented 5 years ago

Thanks for the interest. I will give you a quick answer here, and provide a more complete one when I have a bit more time.

The quick answer is: gapid is divided into a server and a client. The Client (gapit, the GUI) talk to the server over GRPC.

That means in ANY language you can talk to the server, and load traces, and interact.

gapis/service/service.proto defines the GRPC api that you can talk to. Python has very easy to use bindings, and C++ works fine as well. I will describe this a bit more in detail when I get a chance.