Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spirv-opt: debugprintf instrumentation reports "Mixed stage shader module not supported" #4892

Closed
natevm opened this issue Aug 11, 2022 · 3 comments

Comments

@natevm
Copy link

natevm commented Aug 11, 2022

This is a continuation of the issue over on the Vulkan Validation Layers repo here: KhronosGroup/Vulkan-ValidationLayers#4350

A quick summary is that I'd like to support printf with multiple entry points. This should be doable so long as no entry point calls a common function (which is true if --inline-entry-points-exhaustive is used, which is included by default as part of the -o0 flag).

I believe the code that needs changing is here:

bool InstrumentPass::InstProcessEntryPointCallTree(InstProcessFunction& pfn) {
// Make sure all entry points have the same execution model. Do not
// instrument if they do not.
// TODO(greg-lunarg): Handle mixed stages. Technically, a shader module
// can contain entry points with different execution models, although
// such modules will likely be rare as GLSL and HLSL are geared toward
// one model per module. In such cases we will need
// to clone any functions which are in the call trees of entrypoints
// with differing execution models.
uint32_t ecnt = 0;
uint32_t stage = SpvExecutionModelMax;
for (auto& e : get_module()->entry_points()) {
if (ecnt == 0)
stage = e.GetSingleWordInOperand(kEntryPointExecutionModelInIdx);
else if (e.GetSingleWordInOperand(kEntryPointExecutionModelInIdx) !=
stage) {
if (consumer()) {
std::string message = "Mixed stage shader module not supported";
consumer()(SPV_MSG_ERROR, 0, {0, 0, 0}, message.c_str());
}
return false;
}
++ecnt;
}

So, I believe the logic there should instead ask "do any entry points call a common function? if so, disable printf instrumentation."

@greg-lunarg does that seem right?

@natevm natevm changed the title Debug printf reports "Mixed stage shader module not supported" spirv-opt: debugprintf instrumentation reports "Mixed stage shader module not supported" Aug 11, 2022
@greg-lunarg
Copy link
Contributor

@greg-lunarg does that seem right?

Yes.

@natevm
Copy link
Author

natevm commented Aug 11, 2022

Okay, cool. Then I might poke around here and see if I can detect common function calls. I'm a little unfamiliar with the code here, but I figure I should be able to work it out. If I can get that working, I can open a PR here. :)

@greg-lunarg
Copy link
Contributor

There is a function that traverses the call tree of an entry point function. From that you can build a set of ids of functions that are called. From that, you can do an intersection on the function sets of two entry points.

jeremyg-lunarg added a commit to jeremyg-lunarg/SPIRV-Tools that referenced this issue Dec 1, 2023
Remove stage specific debug info that is only needed by GPU-AV.
This allows debug printfs to be used in multi stage shader modules.

Fixes KhronosGroup#4892
jeremyg-lunarg added a commit to jeremyg-lunarg/SPIRV-Tools that referenced this issue Dec 4, 2023
Remove stage specific debug info that is only needed by GPU-AV.
This allows debug printfs to be used in multi stage shader modules.

Fixes KhronosGroup#4892
jeremyg-lunarg added a commit to jeremyg-lunarg/SPIRV-Tools that referenced this issue Dec 4, 2023
Remove stage specific debug info that is only needed by GPU-AV.
This allows debug printfs to be used in multi-stage shader modules.

Fixes KhronosGroup#4892
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants