Conversation
public/tracy/TracyC.h
Outdated
| struct ___tracy_gpu_zone_end_data { | ||
| uint16_t queryId; | ||
| uint8_t context; | ||
| uint32_t thread; |
There was a problem hiding this comment.
Some languages (like Swift) seem to rely on fibers/co-routines shenanigans under the hood, so it's possible for execution context to "zone begin" in one thread, and "zone end" in another thread.
There was a problem hiding this comment.
Yes, but I don't see any usage for this.
There was a problem hiding this comment.
I believe the behavior is a "crash" in the profiler because it leads to Gpu Zone End messages without a matching Gpu Zone Begin message. In the case of CPU zones, the workaround was to use Tracy Fibers to just manipulate (fake) the thread-ids explicitly and have things show up in the timeline. There's no fiber-equivalent for the GPU events.
(I'll ask for the exact error; at the moment I'm sort of playing a game of "Telephone" here relaying messages from people that are more actively involved with using Tracy in the context of other languages and scrips.)
There was a problem hiding this comment.
Ok... Ugh... It looks like the git patch I applied to create this PR was botched :/
(I can see now why you asked about the thread member specifically in ___tracy_gpu_zone_end_data, since it's not used. I'll get back to you once I get more context from the folks).
78a2637 to
e8ef021
Compare
|
Ok, so I looked at the other (C++ API) GPU back-ends, and noticed this:
tracy/public/tracy/TracyOpenGL.hpp Line 311 in aa30c61 But the other GPU back-ends set it to tracy/public/tracy/TracyOpenCL.hpp Line 347 in aa30c61 Vulkan: tracy/public/tracy/TracyVulkan.hpp Line 641 in aa30c61 D3D11: tracy/public/tracy/TracyD3D11.hpp Line 371 in aa30c61 D3D12: tracy/public/tracy/TracyD3D12.hpp Line 429 in aa30c61 Metal: tracy/public/tracy/TracyMetal.hmm Line 605 in aa30c61 So this is probably something that went on unnoticed for a long time. Then there's the matter of "gpu begin" messages only handling fibers in the OpenGL back-end: tracy/public/tracy/TracyOpenGL.hpp Lines 237 to 244 in aa30c61 Not sure which approach is right or wrong here... |
Not really. The OpenGL and Vulkan implementations are different, and for a reason. These two APIs are the only ones I touched. What happens for the other APIs I don't know. Now, I don't remember the details, so the analysis below is AI assisted (the input was your post above). ArchitectureThe server has two modes for GPU contexts (
→ This is in-line with what I vaguely remember. 1. Critical Bug: D3D11 (TracyD3D11.hpp:132)MemWrite( &item->gpuNewContext.thread, uint32_t(0) ); // #TODO: why not GetThreadHandle()?D3D11 is single-threaded like OpenGL but sets → I don't know about D3D11. If it's single-threaded like OpenGL, then it should follow OpenGL patterns. 2. Minor: OpenGL end message (TracyOpenGL.hpp:311)memset( &item->gpuZoneEnd.thread, 0, sizeof( item->gpuZoneEnd.thread ) );This is functionally harmless since OpenGL's → I think this answers your question. You can see this confirmed in 0f68e1e. Getting the thread id has a cost. 3. Potential Issue: Metal (TracyMetal.hmm:351)MemWrite(&item->gpuNewContext.thread, uint32_t(0)); // TODO: why not GetThreadHandle()?Metal uses → Again, I don't know anything about metal. 4. FIBERS: OpenGL-only with incomplete logicOnly OpenGL has → 733d267 I don't remember what this was about. |
|
Ok, spent a few minutes reviewing the server code for GPU zone processing. The So, the problem with the current GPU C API is that, when crating a new GPU context, there's no way to make it "thread-less": tracy/public/client/TracyProfiler.cpp Line 4697 in 80c849a tracy/public/client/TracyProfiler.cpp Line 4821 in 80c849a To accommodate for that, we'd need to add a thread field to Lines 184 to 190 in 80c849a Doing so would then necessitate a way to set the Lines 5920 to 5921 in aa30c61 Alternatively, we could add to Lines 5821 to 5838 in aa30c61 (not sure whether the comment "It still can be sent, because it may be needed for callstack collection purposes" above still has any practical use). Maybe we need both. This would make begin/end processing more consistent to each other, and would allow the Tracy C GPU API to be used in languages that implicitly rely on co-routines to manage/schedule threads around. |
Some new C interfaces to help integrate Tracy with other languages and scripting tools:
tracy::Profiler::GetTime()GpuNewContextmessages must be 0 (also in line with all other GPU backends)threadIdfor GPU Begin/End Zone messages (some languages rely on co-routines that can flow through execution threads)I am not sure how widespread the C API is for GPU out there.
Item 3 above could technically break existing clients (if the struct is not properly zero-initialized), but at the same time uses would have stumbled upon 2. above and being unable to use the GPU C API.