Skip to content

Commit 5d9c33b

Browse files
committed
Update for rspirv sdk-update branch API changes
Adapt to changes in rspirv 0.12.0+sdk-1.4.335.0: - Replace `rspirv::grammar::reflect::is_type(op)` with `op.is_type()` - Replace `rspirv::grammar::reflect::is_constant(op)` with `op.is_constant()` - Update `type_float_id` to include FPEncoding parameter (None) - Change `MemorySemantics::NONE` to `MemorySemantics::RELAXED` - Change `Decoration::UserTypeGOOGLE` to `Decoration::UserSemantic` - Update ExecutionMode NV suffixes to EXT/KHR (OutputLinesNV → OutputLinesEXT, etc.) - Add aliases for DemoteToHelperInvocationEXT and IsHelperInvocationEXT - Update ImageOperands and MemorySemantics KHR constants (now unified) - Add stubs for new operand kinds (RawAccessChainOperands, CooperativeMatrixReduce, etc.) - Update renamed ops (FinalizeNodePayloadsAMDX → EnqueueNodePayloadsAMDX, etc.) - Add catch-all for new ops in spirv_type_constraints
1 parent 49437a5 commit 5d9c33b

9 files changed

Lines changed: 73 additions & 28 deletions

File tree

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
341341
fn ordering_to_semantics_def(&mut self, ordering: AtomicOrdering) -> SpirvValue {
342342
let mut invalid_seq_cst = false;
343343
let semantics = match ordering {
344-
AtomicOrdering::Relaxed => MemorySemantics::NONE,
344+
AtomicOrdering::Relaxed => MemorySemantics::RELAXED,
345345
AtomicOrdering::Acquire => MemorySemantics::MAKE_VISIBLE | MemorySemantics::ACQUIRE,
346346
AtomicOrdering::Release => MemorySemantics::MAKE_AVAILABLE | MemorySemantics::RELEASE,
347347
AtomicOrdering::AcqRel => {

crates/rustc_codegen_spirv/src/builder/spirv_asm.rs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,23 @@ pub struct InstructionTable {
3232

3333
impl InstructionTable {
3434
pub fn new() -> Self {
35-
let table = rspirv::grammar::CoreInstructionTable::iter()
35+
let mut table: FxHashMap<_, _> = rspirv::grammar::CoreInstructionTable::iter()
3636
.map(|inst| (inst.opname, inst))
3737
.collect();
38+
39+
// Add aliases for EXT/KHR instructions whose suffixes were removed
40+
for inst in rspirv::grammar::CoreInstructionTable::iter() {
41+
match inst.opname {
42+
"DemoteToHelperInvocation" => {
43+
table.insert("DemoteToHelperInvocationEXT", inst);
44+
}
45+
"IsHelperInvocation" => {
46+
table.insert("IsHelperInvocationEXT", inst);
47+
}
48+
_ => {}
49+
}
50+
}
51+
3852
Self { table }
3953
}
4054
}
@@ -1529,6 +1543,32 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
15291543
Ok(x) => inst.operands.push(dr::Operand::StoreCacheControl(x)),
15301544
Err(()) => self.err(format!("unknown StoreCacheControl {word}")),
15311545
},
1546+
// New operand kinds added in newer SPIR-V versions - not yet supported in inline asm
1547+
(OperandKind::RawAccessChainOperands, Some(word)) => {
1548+
self.err(format!("RawAccessChainOperands not yet supported: {word}"));
1549+
}
1550+
(OperandKind::CooperativeMatrixReduce, Some(word)) => {
1551+
self.err(format!("CooperativeMatrixReduce not yet supported: {word}"));
1552+
}
1553+
(OperandKind::TensorClampMode, Some(word)) => {
1554+
self.err(format!("TensorClampMode not yet supported: {word}"));
1555+
}
1556+
(OperandKind::TensorAddressingOperands, Some(word)) => {
1557+
self.err(format!("TensorAddressingOperands not yet supported: {word}"));
1558+
}
1559+
(OperandKind::FPEncoding, Some(word)) => {
1560+
self.err(format!("FPEncoding not yet supported: {word}"));
1561+
}
1562+
(OperandKind::NamedMaximumNumberOfRegisters, Some(word)) => {
1563+
self.err(format!("NamedMaximumNumberOfRegisters not yet supported: {word}"));
1564+
}
1565+
(OperandKind::MatrixMultiplyAccumulateOperands, Some(word)) => {
1566+
self.err(format!("MatrixMultiplyAccumulateOperands not yet supported: {word}"));
1567+
}
1568+
// Catch-all for any other new operand kinds
1569+
(kind, Some(word)) => {
1570+
self.err(format!("unsupported operand kind {kind:?}: {word}"));
1571+
}
15321572
(kind, None) => match token {
15331573
Token::Word(_) => bug!(),
15341574
Token::String(_) => {
@@ -1565,14 +1605,14 @@ pub const IMAGE_OPERANDS: &[(&str, ImageOperands)] = &[
15651605
("MakeTexelAvailable", ImageOperands::MAKE_TEXEL_AVAILABLE),
15661606
(
15671607
"MakeTexelAvailableKHR",
1568-
ImageOperands::MAKE_TEXEL_AVAILABLE_KHR,
1608+
ImageOperands::MAKE_TEXEL_AVAILABLE,
15691609
),
15701610
("MakeTexelVisible", ImageOperands::MAKE_TEXEL_VISIBLE),
1571-
("MakeTexelVisibleKHR", ImageOperands::MAKE_TEXEL_VISIBLE_KHR),
1611+
("MakeTexelVisibleKHR", ImageOperands::MAKE_TEXEL_VISIBLE),
15721612
("NonPrivateTexel", ImageOperands::NON_PRIVATE_TEXEL),
1573-
("NonPrivateTexelKHR", ImageOperands::NON_PRIVATE_TEXEL_KHR),
1613+
("NonPrivateTexelKHR", ImageOperands::NON_PRIVATE_TEXEL),
15741614
("VolatileTexel", ImageOperands::VOLATILE_TEXEL),
1575-
("VolatileTexelKHR", ImageOperands::VOLATILE_TEXEL_KHR),
1615+
("VolatileTexelKHR", ImageOperands::VOLATILE_TEXEL),
15761616
("SignExtend", ImageOperands::SIGN_EXTEND),
15771617
("ZeroExtend", ImageOperands::ZERO_EXTEND),
15781618
];
@@ -1610,7 +1650,7 @@ pub const FUNCTION_CONTROL: &[(&str, FunctionControl)] = &[
16101650
];
16111651
pub const MEMORY_SEMANTICS: &[(&str, MemorySemantics)] = &[
16121652
("Relaxed", MemorySemantics::RELAXED),
1613-
("None", MemorySemantics::NONE),
1653+
("None", MemorySemantics::RELAXED),
16141654
("Acquire", MemorySemantics::ACQUIRE),
16151655
("Release", MemorySemantics::RELEASE),
16161656
("AcquireRelease", MemorySemantics::ACQUIRE_RELEASE),
@@ -1631,11 +1671,11 @@ pub const MEMORY_SEMANTICS: &[(&str, MemorySemantics)] = &[
16311671
),
16321672
("ImageMemory", MemorySemantics::IMAGE_MEMORY),
16331673
("OutputMemory", MemorySemantics::OUTPUT_MEMORY),
1634-
("OutputMemoryKHR", MemorySemantics::OUTPUT_MEMORY_KHR),
1674+
("OutputMemoryKHR", MemorySemantics::OUTPUT_MEMORY),
16351675
("MakeAvailable", MemorySemantics::MAKE_AVAILABLE),
1636-
("MakeAvailableKHR", MemorySemantics::MAKE_AVAILABLE_KHR),
1676+
("MakeAvailableKHR", MemorySemantics::MAKE_AVAILABLE),
16371677
("MakeVisible", MemorySemantics::MAKE_VISIBLE),
1638-
("MakeVisibleKHR", MemorySemantics::MAKE_VISIBLE_KHR),
1678+
("MakeVisibleKHR", MemorySemantics::MAKE_VISIBLE),
16391679
("Volatile", MemorySemantics::VOLATILE),
16401680
];
16411681
pub const MEMORY_ACCESS: &[(&str, MemoryAccess)] = &[
@@ -1646,17 +1686,17 @@ pub const MEMORY_ACCESS: &[(&str, MemoryAccess)] = &[
16461686
("MakePointerAvailable", MemoryAccess::MAKE_POINTER_AVAILABLE),
16471687
(
16481688
"MakePointerAvailableKHR",
1649-
MemoryAccess::MAKE_POINTER_AVAILABLE_KHR,
1689+
MemoryAccess::MAKE_POINTER_AVAILABLE,
16501690
),
16511691
("MakePointerVisible", MemoryAccess::MAKE_POINTER_VISIBLE),
16521692
(
16531693
"MakePointerVisibleKHR",
1654-
MemoryAccess::MAKE_POINTER_VISIBLE_KHR,
1694+
MemoryAccess::MAKE_POINTER_VISIBLE,
16551695
),
16561696
("NonPrivatePointer", MemoryAccess::NON_PRIVATE_POINTER),
16571697
(
16581698
"NonPrivatePointerKHR",
1659-
MemoryAccess::NON_PRIVATE_POINTER_KHR,
1699+
MemoryAccess::NON_PRIVATE_POINTER,
16601700
),
16611701
];
16621702
pub const KERNEL_PROFILING_INFO: &[(&str, KernelProfilingInfo)] = &[

crates/rustc_codegen_spirv/src/custom_decorations.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::{fmt, iter, slice, str};
1818

1919
/// Decorations not native to SPIR-V require some form of encoding into existing
2020
/// SPIR-V constructs, for which we use `OpDecorateString` with decoration type
21-
/// `UserTypeGOOGLE` and some encoded Rust value as the decoration string.
21+
/// `UserSemantic` and some encoded Rust value as the decoration string.
2222
///
2323
/// Each decoration type has to implement this trait, and use a different
2424
/// `ENCODING_PREFIX` from any other decoration type, to disambiguate them.
@@ -27,7 +27,10 @@ use std::{fmt, iter, slice, str};
2727
/// ideally as soon as they're no longer needed, because no other tools
2828
/// processing the SPIR-V would understand them correctly.
2929
///
30-
/// TODO: uses `non_semantic` instead of piggybacking off of `UserTypeGOOGLE`
30+
/// Custom decorations are encoded using `OpDecorateString` with `UserSemantic`,
31+
/// which is a standard SPIR-V decoration that doesn't require any extension.
32+
///
33+
/// TODO: consider using `non_semantic` instead for even cleaner separation
3134
/// <https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/KHR/SPV_KHR_non_semantic_info.html>
3235
pub trait CustomDecoration<'a>: Sized {
3336
const ENCODING_PREFIX: &'static str;
@@ -45,15 +48,15 @@ pub trait CustomDecoration<'a>: Sized {
4548
None,
4649
vec![
4750
Operand::IdRef(id),
48-
Operand::Decoration(Decoration::UserTypeGOOGLE),
51+
Operand::Decoration(Decoration::UserSemantic),
4952
Operand::LiteralString(encoded),
5053
],
5154
)
5255
}
5356

5457
fn try_decode_from_inst(inst: &Instruction) -> Option<(Word, LazilyDecoded<'_, Self>)> {
5558
if inst.class.opcode == Op::DecorateString
56-
&& inst.operands[1].unwrap_decoration() == Decoration::UserTypeGOOGLE
59+
&& inst.operands[1].unwrap_decoration() == Decoration::UserSemantic
5760
{
5861
let id = inst.operands[0].unwrap_id_ref();
5962
let prefixed_encoded = inst.operands[2].unwrap_literal_string();

crates/rustc_codegen_spirv/src/linker/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ impl LegalGlobal {
298298
let global = match inst.class.opcode {
299299
Op::TypePointer => Self::TypePointer(inst.operands[0].unwrap_storage_class()),
300300
Op::Variable => Self::Variable,
301-
op if rspirv::grammar::reflect::is_type(op) => Self::TypeNonPointer,
302-
op if rspirv::grammar::reflect::is_constant(op) => Self::Const,
301+
op if op.is_type() => Self::TypeNonPointer,
302+
op if op.is_constant() => Self::Const,
303303

304304
// FIXME(eddyb) should this be `unreachable!()`?
305305
_ => continue,

crates/rustc_codegen_spirv/src/linker/spirt_passes/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn try_decode_custom_decoration<'a, D: CustomDecoration<'a>>(
128128
};
129129
let str_imms = spv_inst
130130
.imms
131-
.strip_prefix(&[spv::Imm::Short(wk.Decoration, wk.UserTypeGOOGLE)])?;
131+
.strip_prefix(&[spv::Imm::Short(wk.Decoration, wk.UserSemantic)])?;
132132

133133
decode_spv_lit_str_with(str_imms, |prefixed_encoded| {
134134
let encoded = prefixed_encoded.strip_prefix(D::ENCODING_PREFIX)?;

crates/rustc_codegen_spirv/src/linker/spirt_passes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def_spv_spec_with_extra_well_known! {
113113
MemoryAccess,
114114
],
115115
decoration: u32 = [
116-
UserTypeGOOGLE,
116+
UserSemantic,
117117
MatrixStride,
118118
],
119119
storage_class: u32 = [

crates/rustc_codegen_spirv/src/spirv_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl SpirvType<'_> {
104104
Self::Void => cx.emit_global().type_void_id(id),
105105
Self::Bool => cx.emit_global().type_bool_id(id),
106106
Self::Integer(width, signed) => cx.emit_global().type_int_id(id, width, signed as u32),
107-
Self::Float(width) => cx.emit_global().type_float_id(id, width),
107+
Self::Float(width) => cx.emit_global().type_float_id(id, width, None),
108108
Self::Adt {
109109
def_id: _,
110110
align: _,

crates/rustc_codegen_spirv/src/spirv_type_constraints.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,9 +1096,9 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
10961096
| Op::ImageBlockMatchSSDQCOM
10971097
| Op::ImageBlockMatchSADQCOM => reserved!(SPV_QCOM_image_processing),
10981098
// SPV_AMDX_shader_enqueue
1099-
Op::FinalizeNodePayloadsAMDX
1099+
Op::EnqueueNodePayloadsAMDX
11001100
| Op::FinishWritingNodePayloadAMDX
1101-
| Op::InitializeNodePayloadsAMDX => reserved!(SPV_AMDX_shader_enqueue),
1101+
| Op::AllocateNodePayloadsAMDX => reserved!(SPV_AMDX_shader_enqueue),
11021102
// SPV_NV_displacement_micromap
11031103
Op::FetchMicroTriangleVertexPositionNV | Op::FetchMicroTriangleVertexBarycentricNV => {
11041104
reserved!(SPV_NV_displacement_micromap)
@@ -1124,6 +1124,8 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
11241124
| Op::SpecConstantCompositeContinuedINTEL
11251125
| Op::ControlBarrierArriveINTEL
11261126
| Op::ControlBarrierWaitINTEL => reserved!(unknown_extension_INTEL),
1127+
// Catch-all for any new ops added in newer SPIR-V versions
1128+
_ => return None,
11271129
}
11281130

11291131
None

crates/rustc_codegen_spirv/src/symbols.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ const EXECUTION_MODES: &[(&str, ExecutionMode, ExecutionModeExtraDim)] = {
271271
("rounding_mode_rte", RoundingModeRTE, Value),
272272
("rounding_mode_rtz", RoundingModeRTZ, Value),
273273
("stencil_ref_replacing_ext", StencilRefReplacingEXT, None),
274-
("output_lines_nv", OutputLinesNV, None),
275-
("output_primitives_nv", OutputPrimitivesNV, Value),
276-
("derivative_group_quads_nv", DerivativeGroupQuadsNV, None),
277-
("output_triangles_nv", OutputTrianglesNV, None),
274+
("output_lines_nv", OutputLinesEXT, None),
275+
("output_primitives_nv", OutputPrimitivesEXT, Value),
276+
("derivative_group_quads_nv", DerivativeGroupQuadsKHR, None),
277+
("output_triangles_nv", OutputTrianglesEXT, None),
278278
("output_lines_ext", ExecutionMode::OutputLinesEXT, None),
279279
(
280280
"output_triangles_ext",

0 commit comments

Comments
 (0)