Skip to content

Generate and implement extended instruction handling for *all* extinst sets#273

Merged
MarijnS95 merged 6 commits into
masterfrom
extinst
Mar 13, 2026
Merged

Generate and implement extended instruction handling for *all* extinst sets#273
MarijnS95 merged 6 commits into
masterfrom
extinst

Conversation

@MarijnS95

@MarijnS95 MarijnS95 commented Mar 13, 2026

Copy link
Copy Markdown
Collaborator

Previous PRs made a mess out of extended instructions by adding some boilerplate for them but never updating it in ExtInstSetTracker making it impossible to be used in the binary parser. This generalizes Instruction and ExtendedInstruction a little bit to handle both cases.

Disclaimer: most commits were written by me, but I've asked claude to help me with the indefinite churn in the last two commits.

We already generate the `enum *Op` structures for these extensions;
reference them directly instead of hardcoding the number in these
instruction tables again.
@MarijnS95 MarijnS95 requested a review from cwfitzgerald March 13, 2026 14:15
MarijnS95 and others added 5 commits March 13, 2026 15:45
These were global zero-sized structures with getters that walk the
generated `INSTRUCTION_TABLE` lists, which share a very common pattern
that lends itself perfectly for being abstracted away to a single
implementation of the lookup
`autogen_nonsemantic_debugprintf.rs` was added in commit  267882d
("Unify extended instruction parsing and add `NonSemantic.DebugPrintF`
(#216)") but never `include!()`d making it unreachable.

It was also never made available in `ExtInstSetTracker`, somewhat
defeating the purpose of adding the extension in the first place.
Extensions like DebugInfo and OpenCL.debuginfo.100 define their own
operand kinds with potentially clashing names but different discriminant
values.  Generate a separate `ExtOperandKind` enum per extension module
and add wrapper variants (e.g. `OperandKind::DebugInfo(ExtOperandKind)`)
to the core `OperandKind` enum.

The `ext_inst!` macro gains a second arm disambiguated by a trailing
comma: the ident arm prepends `OperandKind::` for extensions without
own operand kinds, while the expr arm passes through pre-wrapped
`OperandKind::Variant(ExtOperandKind::Kind)` expressions.  All
extension tables are now wrapped in `pub mod` for consistent namespacing.
Instead of maintaining a hardcoded list of extended instruction sets,
automatically glob for all `extinst.*.grammar.json` files in the
SPIRV-Headers submodule.  Module names, op enum names, and table names
are derived systematically from the grammar filename.

The `ext_inst_table()` lookup normalises its input (lowercasing and
converting underscores to hyphens) so that any casing variant of the
canonical import name resolves correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MarijnS95

Copy link
Copy Markdown
Collaborator Author

In hindsight I'm unhappy that the extended instructions are generalized to a spirv::Word to save on generic complexity down the line, while the operands were added to the core enum OperandKind enum. That's something I'd like to flatten out.

Let claude fix that now, though in a slightly different way.

@MarijnS95

Copy link
Copy Markdown
Collaborator Author

@cwfitzgerald can you review this once more?

@cwfitzgerald cwfitzgerald left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just finished reviewing when you pushed - everything looks good and I understood the motivation behind the code very well, thank you for all the commentary on the commits. Please merge at will!

Also woooo more autogen!

@MarijnS95 MarijnS95 merged commit cde9bb9 into master Mar 13, 2026
18 checks passed
@MarijnS95 MarijnS95 deleted the extinst branch March 13, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants