spv: minimal OpSpecConstantOp
and OpConstantFunctionPointerINTEL
support.
#22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(each commit should be reviewed separately)
Temporarily based on:
mem
module (for "memory" ops/passes/etc.), out ofqptr
. #25The
OpSpecConstantOp
support is pretty simple/limited (i.e. interpretingLiteralSpecConstantOpInteger
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 LLVMConstantExpr
, so it includes the kind of pointer operations (e.g.OpAccessChain
andOpBitcast
) 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:Func
from aConst
(ConstKind::PtrToFunc
had to be added)(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 byqptr
, as all plans for some kind of function pointer emulation (likely as part of recursion emulation) don't really fit theqptr
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.