Skip to content

spv: minimal OpSpecConstantOp and OpConstantFunctionPointerINTEL support. #22

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

eddyb
Copy link
Collaborator

@eddyb eddyb commented Jul 31, 2025

(each commit should be reviewed separately)

Temporarily based on:


The OpSpecConstantOp support is pretty simple/limited (i.e. interpreting LiteralSpecConstantOpInteger operands as a SPIR-V opcode followed by all the operands an instruction with that opcode would need).

While OpSpecConstantOp can be used to do simple arithmetic on specialization constants (as its name may imply), it's also SPIR-V's equivalent of a LLVM ConstantExpr, so it includes the kind of pointer operations (e.g. OpAccessChain and OpBitcast) necessary to produce non-trivial pointer values for e.g. initializing globals.

Actually doing anything with such constants isn't implemented, but being able to load a SPIR-V module containing them is a prerequisite for generating them within Rust-GPU for better diagnostics and debuggability etc.


OTOH, OpConstantFunctionPointerINTEL support is far more involved, due to two related issues:

  • SPIR-T had no way to refer to a Func from a Const (ConstKind::PtrToFunc had to be added)
  • constants come before functions, so SPIR-V -> SPIR-T has to account for the forward reference
    (done by allocating a Func with a dummy declaration, later replaced by the actual function)

SPIR-T -> SPIR-V is much easier, just because all the IDs in the module get allocated early anyway.

On top of the constants themselves, function pointer types (i.e. using CodeSectionINTEL as the storage class) are intentionally ignored by qptr, as all plans for some kind of function pointer emulation (likely as part of recursion emulation) don't really fit the qptr framework and would work more like a disjoint address space (a la Harvard architectures).

But just like with OpSpecConstantOp, the main usecase right now is limited to diagnostics/debuggability.

@eddyb eddyb requested a review from a team July 31, 2025 17:47
@eddyb eddyb enabled auto-merge July 31, 2025 19:34
@eddyb eddyb marked this pull request as draft August 8, 2025 18:04
auto-merge was automatically disabled August 8, 2025 18:04

Pull request was converted to draft

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.

1 participant