Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

layer: add DeviceNotToTrace guards in GetDeviceQueue and QueueSubmit - #51

Merged
rjodinchr merged 2 commits into
rjodinchr:mainfrom
mattst88:DeviceNotToTrace-guards
Mar 14, 2026
Merged

layer: add DeviceNotToTrace guards in GetDeviceQueue and QueueSubmit#51
rjodinchr merged 2 commits into
rjodinchr:mainfrom
mattst88:DeviceNotToTrace-guards

Conversation

@mattst88

Copy link
Copy Markdown
Collaborator

If a device was marked as non-traceable (e.g., due to a missing function), GetDeviceQueue would still allocate tracing infrastructure and QueueSubmit would dereference uninitialized state. Add early-out checks for DeviceNotToTrace in both functions, and move the QueueToDevice assignment before the guard so the queue-to-device mapping is always available for QueueSubmit's passthrough path.

@mattst88

Copy link
Copy Markdown
Collaborator Author

This was just something I noticed :)

@rjodinchr rjodinchr left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with most of it.

I think that we still want to keep the TRACE_EVENT even when we do not trace the device.

I believe "DeviceNotToTrace" represents a device where we cannot track the submissions but no reason not to have perfetto traces for the call to those functions.

Maybe we would also want to add a field in the trace to mention that the device will not be traced (meaning, we will not follow each submission).

What do you think?

@mattst88
mattst88 force-pushed the DeviceNotToTrace-guards branch from 44f88b5 to 68e6b43 Compare March 12, 2026 18:23
@mattst88

Copy link
Copy Markdown
Collaborator Author

I've moved the TRACE_EVENT back to its original location, which is what I think you suggested.

I'll push a second update to the commit that implements the additional field in the trace.

@mattst88
mattst88 force-pushed the DeviceNotToTrace-guards branch from 68e6b43 to b2144d4 Compare March 12, 2026 18:43
Previously, devices with missing dispatch table entries were added to
DeviceNotToTrace and vksp_GetDeviceProcAddr would skip returning the
layer's intercepted functions for them, meaning no Perfetto traces were
emitted at all. Instead, always return the layer's intercepted functions
so that Perfetto traces are emitted for all devices.

Add a trace event at device creation to indicate when a device will not
have its submissions tracked.

Guard submission-tracking setup in vksp_GetDeviceQueue and
vksp_QueueSubmit so they skip the timeline semaphore thread machinery
for DeviceNotToTrace devices, avoiding null function pointer crashes.
@mattst88
mattst88 force-pushed the DeviceNotToTrace-guards branch from b2144d4 to 060337d Compare March 12, 2026 18:58
Comment thread layer/layer.cpp
{
std::lock_guard<std::mutex> lock(glock);

if (DeviceNotToTrace.count(device) == 0) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that even if we don't want to follow the submissions, we still want to trace as much as possible.

But what would happen if vksp_GetDeviceProcAddr is looking for something we don't have. It feels like, it will call the vksp_<X> function, which itself will try to call the function from the dispatch table which has not been filled. So a potential segfault could occur.

Am I missing something? Should we protect against that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch. Yes. I've added a commit that should protect against that.

Only return the vksp_* wrapper from GetDeviceProcAddr when the
corresponding dispatch table entry is non-null. If a function was
missing during device creation (causing the device to be added to
DeviceNotToTrace), fall through to the real driver's GetDeviceProcAddr
instead of returning a wrapper that would segfault.
@rjodinchr
rjodinchr merged commit 9916eca into rjodinchr:main Mar 14, 2026
3 checks passed
@mattst88
mattst88 deleted the DeviceNotToTrace-guards branch March 17, 2026 16:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants