Skip to main content

naga/back/spv/
instructions.rs

1use alloc::{vec, vec::Vec};
2
3use spirv::{Op, Word};
4
5use super::{block::DebugInfoInner, helpers};
6
7pub(super) enum Signedness {
8    Unsigned = 0,
9    Signed = 1,
10}
11
12pub(super) enum SampleLod {
13    Explicit,
14    Implicit,
15}
16
17pub(super) struct Case {
18    pub value: Word,
19    pub label_id: Word,
20}
21
22impl super::Instruction {
23    //
24    //  Debug Instructions
25    //
26
27    pub(super) fn string(name: &str, id: Word) -> Self {
28        let mut instruction = Self::new(Op::String);
29        instruction.set_result(id);
30        instruction.add_operands(helpers::string_to_words(name));
31        instruction
32    }
33
34    pub(super) fn source(
35        source_language: spirv::SourceLanguage,
36        version: u32,
37        source: &Option<DebugInfoInner>,
38    ) -> Self {
39        let mut instruction = Self::new(Op::Source);
40        instruction.add_operand(source_language as u32);
41        instruction.add_operands(helpers::bytes_to_words(&version.to_le_bytes()));
42        if let Some(source) = source.as_ref() {
43            instruction.add_operand(source.source_file_id);
44            instruction.add_operands(helpers::string_to_words(source.source_code));
45        }
46        instruction
47    }
48
49    pub(super) fn source_continued(source: &[u8]) -> Self {
50        let mut instruction = Self::new(Op::SourceContinued);
51        instruction.add_operands(helpers::debug_str_bytes_to_words(source));
52        instruction
53    }
54
55    pub(super) fn source_auto_continued(
56        source_language: spirv::SourceLanguage,
57        version: u32,
58        source: &Option<DebugInfoInner>,
59    ) -> Vec<Self> {
60        let mut instructions = vec![];
61
62        let with_continue = source.as_ref().and_then(|debug_info| {
63            (debug_info.source_code.len() > u16::MAX as usize).then_some(debug_info)
64        });
65        if let Some(debug_info) = with_continue {
66            let mut instruction = Self::new(Op::Source);
67            instruction.add_operand(source_language as u32);
68            instruction.add_operands(helpers::bytes_to_words(&version.to_le_bytes()));
69
70            let words = helpers::string_to_byte_chunks(debug_info.source_code, u16::MAX as usize);
71            instruction.add_operand(debug_info.source_file_id);
72            instruction.add_operands(helpers::debug_str_bytes_to_words(words[0]));
73            instructions.push(instruction);
74            for word_bytes in words[1..].iter() {
75                let instruction_continue = Self::source_continued(word_bytes);
76                instructions.push(instruction_continue);
77            }
78        } else {
79            let instruction = Self::source(source_language, version, source);
80            instructions.push(instruction);
81        }
82        instructions
83    }
84
85    pub(super) fn name(target_id: Word, name: &str) -> Self {
86        let mut instruction = Self::new(Op::Name);
87        instruction.add_operand(target_id);
88        instruction.add_operands(helpers::string_to_words(name));
89        instruction
90    }
91
92    pub(super) fn member_name(target_id: Word, member: Word, name: &str) -> Self {
93        let mut instruction = Self::new(Op::MemberName);
94        instruction.add_operand(target_id);
95        instruction.add_operand(member);
96        instruction.add_operands(helpers::string_to_words(name));
97        instruction
98    }
99
100    pub(super) fn line(file: Word, line: Word, column: Word) -> Self {
101        let mut instruction = Self::new(Op::Line);
102        instruction.add_operand(file);
103        instruction.add_operand(line);
104        instruction.add_operand(column);
105        instruction
106    }
107
108    //
109    //  Annotation Instructions
110    //
111
112    pub(super) fn decorate(
113        target_id: Word,
114        decoration: spirv::Decoration,
115        operands: &[Word],
116    ) -> Self {
117        let mut instruction = Self::new(Op::Decorate);
118        instruction.add_operand(target_id);
119        instruction.add_operand(decoration as u32);
120        for operand in operands {
121            instruction.add_operand(*operand)
122        }
123        instruction
124    }
125
126    pub(super) fn member_decorate(
127        target_id: Word,
128        member_index: Word,
129        decoration: spirv::Decoration,
130        operands: &[Word],
131    ) -> Self {
132        let mut instruction = Self::new(Op::MemberDecorate);
133        instruction.add_operand(target_id);
134        instruction.add_operand(member_index);
135        instruction.add_operand(decoration as u32);
136        for operand in operands {
137            instruction.add_operand(*operand)
138        }
139        instruction
140    }
141
142    //
143    //  Extension Instructions
144    //
145
146    pub(super) fn extension(name: &str) -> Self {
147        let mut instruction = Self::new(Op::Extension);
148        instruction.add_operands(helpers::string_to_words(name));
149        instruction
150    }
151
152    pub(super) fn ext_inst_import(id: Word, name: &str) -> Self {
153        let mut instruction = Self::new(Op::ExtInstImport);
154        instruction.set_result(id);
155        instruction.add_operands(helpers::string_to_words(name));
156        instruction
157    }
158
159    pub(super) fn ext_inst_gl_op(
160        set_id: Word,
161        op: spirv::GlslStd450Op,
162        result_type_id: Word,
163        id: Word,
164        operands: &[Word],
165    ) -> Self {
166        Self::ext_inst(set_id, op as u32, result_type_id, id, operands)
167    }
168
169    pub(super) fn ext_inst(
170        set_id: Word,
171        op: u32,
172        result_type_id: Word,
173        id: Word,
174        operands: &[Word],
175    ) -> Self {
176        let mut instruction = Self::new(Op::ExtInst);
177        instruction.set_type(result_type_id);
178        instruction.set_result(id);
179        instruction.add_operand(set_id);
180        instruction.add_operand(op);
181        for operand in operands {
182            instruction.add_operand(*operand)
183        }
184        instruction
185    }
186
187    //
188    //  Mode-Setting Instructions
189    //
190
191    pub(super) fn memory_model(
192        addressing_model: spirv::AddressingModel,
193        memory_model: spirv::MemoryModel,
194    ) -> Self {
195        let mut instruction = Self::new(Op::MemoryModel);
196        instruction.add_operand(addressing_model as u32);
197        instruction.add_operand(memory_model as u32);
198        instruction
199    }
200
201    pub(super) fn entry_point(
202        execution_model: spirv::ExecutionModel,
203        entry_point_id: Word,
204        name: &str,
205        interface_ids: &[Word],
206    ) -> Self {
207        let mut instruction = Self::new(Op::EntryPoint);
208        instruction.add_operand(execution_model as u32);
209        instruction.add_operand(entry_point_id);
210        instruction.add_operands(helpers::string_to_words(name));
211
212        for interface_id in interface_ids {
213            instruction.add_operand(*interface_id);
214        }
215
216        instruction
217    }
218
219    pub(super) fn execution_mode(
220        entry_point_id: Word,
221        execution_mode: spirv::ExecutionMode,
222        args: &[Word],
223    ) -> Self {
224        let mut instruction = Self::new(Op::ExecutionMode);
225        instruction.add_operand(entry_point_id);
226        instruction.add_operand(execution_mode as u32);
227        for arg in args {
228            instruction.add_operand(*arg);
229        }
230        instruction
231    }
232
233    pub(super) fn capability(capability: spirv::Capability) -> Self {
234        let mut instruction = Self::new(Op::Capability);
235        instruction.add_operand(capability as u32);
236        instruction
237    }
238
239    //
240    //  Type-Declaration Instructions
241    //
242
243    pub(super) fn type_void(id: Word) -> Self {
244        let mut instruction = Self::new(Op::TypeVoid);
245        instruction.set_result(id);
246        instruction
247    }
248
249    pub(super) fn type_bool(id: Word) -> Self {
250        let mut instruction = Self::new(Op::TypeBool);
251        instruction.set_result(id);
252        instruction
253    }
254
255    pub(super) fn type_int(id: Word, width: Word, signedness: Signedness) -> Self {
256        let mut instruction = Self::new(Op::TypeInt);
257        instruction.set_result(id);
258        instruction.add_operand(width);
259        instruction.add_operand(signedness as u32);
260        instruction
261    }
262
263    pub(super) fn type_float(id: Word, width: Word) -> Self {
264        let mut instruction = Self::new(Op::TypeFloat);
265        instruction.set_result(id);
266        instruction.add_operand(width);
267        instruction
268    }
269
270    pub(super) fn type_vector(
271        id: Word,
272        component_type_id: Word,
273        component_count: crate::VectorSize,
274    ) -> Self {
275        let mut instruction = Self::new(Op::TypeVector);
276        instruction.set_result(id);
277        instruction.add_operand(component_type_id);
278        instruction.add_operand(component_count as u32);
279        instruction
280    }
281
282    pub(super) fn type_matrix(
283        id: Word,
284        column_type_id: Word,
285        column_count: crate::VectorSize,
286    ) -> Self {
287        let mut instruction = Self::new(Op::TypeMatrix);
288        instruction.set_result(id);
289        instruction.add_operand(column_type_id);
290        instruction.add_operand(column_count as u32);
291        instruction
292    }
293
294    pub(super) fn type_coop_matrix(
295        id: Word,
296        scalar_type_id: Word,
297        scope_id: Word,
298        row_count_id: Word,
299        column_count_id: Word,
300        matrix_use_id: Word,
301    ) -> Self {
302        let mut instruction = Self::new(Op::TypeCooperativeMatrixKHR);
303        instruction.set_result(id);
304        instruction.add_operand(scalar_type_id);
305        instruction.add_operand(scope_id);
306        instruction.add_operand(row_count_id);
307        instruction.add_operand(column_count_id);
308        instruction.add_operand(matrix_use_id);
309        instruction
310    }
311
312    pub(super) fn type_image(
313        id: Word,
314        sampled_type_id: Word,
315        dim: spirv::Dim,
316        flags: super::ImageTypeFlags,
317        image_format: spirv::ImageFormat,
318    ) -> Self {
319        let mut instruction = Self::new(Op::TypeImage);
320        instruction.set_result(id);
321        instruction.add_operand(sampled_type_id);
322        instruction.add_operand(dim as u32);
323        instruction.add_operand(flags.contains(super::ImageTypeFlags::DEPTH) as u32);
324        instruction.add_operand(flags.contains(super::ImageTypeFlags::ARRAYED) as u32);
325        instruction.add_operand(flags.contains(super::ImageTypeFlags::MULTISAMPLED) as u32);
326        instruction.add_operand(if flags.contains(super::ImageTypeFlags::SAMPLED) {
327            1
328        } else {
329            2
330        });
331        instruction.add_operand(image_format as u32);
332        instruction
333    }
334
335    pub(super) fn type_sampler(id: Word) -> Self {
336        let mut instruction = Self::new(Op::TypeSampler);
337        instruction.set_result(id);
338        instruction
339    }
340
341    pub(super) fn type_acceleration_structure(id: Word) -> Self {
342        let mut instruction = Self::new(Op::TypeAccelerationStructureKHR);
343        instruction.set_result(id);
344        instruction
345    }
346
347    pub(super) fn type_ray_query(id: Word) -> Self {
348        let mut instruction = Self::new(Op::TypeRayQueryKHR);
349        instruction.set_result(id);
350        instruction
351    }
352
353    pub(super) fn type_hit_object(id: Word) -> Self {
354        let mut instruction = Self::new(Op::TypeHitObjectEXT);
355        instruction.set_result(id);
356        instruction
357    }
358
359    pub(super) fn type_sampled_image(id: Word, image_type_id: Word) -> Self {
360        let mut instruction = Self::new(Op::TypeSampledImage);
361        instruction.set_result(id);
362        instruction.add_operand(image_type_id);
363        instruction
364    }
365
366    pub(super) fn type_array(id: Word, element_type_id: Word, length_id: Word) -> Self {
367        let mut instruction = Self::new(Op::TypeArray);
368        instruction.set_result(id);
369        instruction.add_operand(element_type_id);
370        instruction.add_operand(length_id);
371        instruction
372    }
373
374    pub(super) fn type_runtime_array(id: Word, element_type_id: Word) -> Self {
375        let mut instruction = Self::new(Op::TypeRuntimeArray);
376        instruction.set_result(id);
377        instruction.add_operand(element_type_id);
378        instruction
379    }
380
381    pub(super) fn type_struct(id: Word, member_ids: &[Word]) -> Self {
382        let mut instruction = Self::new(Op::TypeStruct);
383        instruction.set_result(id);
384
385        for member_id in member_ids {
386            instruction.add_operand(*member_id)
387        }
388
389        instruction
390    }
391
392    pub(super) fn type_pointer(
393        id: Word,
394        storage_class: spirv::StorageClass,
395        type_id: Word,
396    ) -> Self {
397        let mut instruction = Self::new(Op::TypePointer);
398        instruction.set_result(id);
399        instruction.add_operand(storage_class as u32);
400        instruction.add_operand(type_id);
401        instruction
402    }
403
404    pub(super) fn type_function(id: Word, return_type_id: Word, parameter_ids: &[Word]) -> Self {
405        let mut instruction = Self::new(Op::TypeFunction);
406        instruction.set_result(id);
407        instruction.add_operand(return_type_id);
408
409        for parameter_id in parameter_ids {
410            instruction.add_operand(*parameter_id);
411        }
412
413        instruction
414    }
415
416    //
417    //  Constant-Creation Instructions
418    //
419
420    pub(super) fn constant_null(result_type_id: Word, id: Word) -> Self {
421        let mut instruction = Self::new(Op::ConstantNull);
422        instruction.set_type(result_type_id);
423        instruction.set_result(id);
424        instruction
425    }
426
427    pub(super) fn constant_true(result_type_id: Word, id: Word) -> Self {
428        let mut instruction = Self::new(Op::ConstantTrue);
429        instruction.set_type(result_type_id);
430        instruction.set_result(id);
431        instruction
432    }
433
434    pub(super) fn constant_false(result_type_id: Word, id: Word) -> Self {
435        let mut instruction = Self::new(Op::ConstantFalse);
436        instruction.set_type(result_type_id);
437        instruction.set_result(id);
438        instruction
439    }
440
441    pub(super) fn constant_16bit(result_type_id: Word, id: Word, low: Word) -> Self {
442        Self::constant(result_type_id, id, &[low])
443    }
444
445    pub(super) fn constant_32bit(result_type_id: Word, id: Word, value: Word) -> Self {
446        Self::constant(result_type_id, id, &[value])
447    }
448
449    pub(super) fn constant_64bit(result_type_id: Word, id: Word, low: Word, high: Word) -> Self {
450        Self::constant(result_type_id, id, &[low, high])
451    }
452
453    pub(super) fn constant(result_type_id: Word, id: Word, values: &[Word]) -> Self {
454        let mut instruction = Self::new(Op::Constant);
455        instruction.set_type(result_type_id);
456        instruction.set_result(id);
457
458        for value in values {
459            instruction.add_operand(*value);
460        }
461
462        instruction
463    }
464
465    pub(super) fn constant_composite(
466        result_type_id: Word,
467        id: Word,
468        constituent_ids: &[Word],
469    ) -> Self {
470        let mut instruction = Self::new(Op::ConstantComposite);
471        instruction.set_type(result_type_id);
472        instruction.set_result(id);
473
474        for constituent_id in constituent_ids {
475            instruction.add_operand(*constituent_id);
476        }
477
478        instruction
479    }
480
481    //
482    //  Memory Instructions
483    //
484
485    pub(super) fn variable(
486        result_type_id: Word,
487        id: Word,
488        storage_class: spirv::StorageClass,
489        initializer_id: Option<Word>,
490    ) -> Self {
491        let mut instruction = Self::new(Op::Variable);
492        instruction.set_type(result_type_id);
493        instruction.set_result(id);
494        instruction.add_operand(storage_class as u32);
495
496        if let Some(initializer_id) = initializer_id {
497            instruction.add_operand(initializer_id);
498        }
499
500        instruction
501    }
502
503    pub(super) fn load(
504        result_type_id: Word,
505        id: Word,
506        pointer_id: Word,
507        memory_access: Option<spirv::MemoryAccess>,
508    ) -> Self {
509        let mut instruction = Self::new(Op::Load);
510        instruction.set_type(result_type_id);
511        instruction.set_result(id);
512        instruction.add_operand(pointer_id);
513
514        if let Some(memory_access) = memory_access {
515            instruction.add_operand(memory_access.bits());
516        }
517
518        instruction
519    }
520
521    pub(super) fn atomic_load(
522        result_type_id: Word,
523        id: Word,
524        pointer_id: Word,
525        scope_id: Word,
526        semantics_id: Word,
527    ) -> Self {
528        let mut instruction = Self::new(Op::AtomicLoad);
529        instruction.set_type(result_type_id);
530        instruction.set_result(id);
531        instruction.add_operand(pointer_id);
532        instruction.add_operand(scope_id);
533        instruction.add_operand(semantics_id);
534        instruction
535    }
536
537    pub(super) fn store(
538        pointer_id: Word,
539        value_id: Word,
540        memory_access: Option<spirv::MemoryAccess>,
541    ) -> Self {
542        let mut instruction = Self::new(Op::Store);
543        instruction.add_operand(pointer_id);
544        instruction.add_operand(value_id);
545
546        if let Some(memory_access) = memory_access {
547            instruction.add_operand(memory_access.bits());
548        }
549
550        instruction
551    }
552
553    pub(super) fn atomic_store(
554        pointer_id: Word,
555        scope_id: Word,
556        semantics_id: Word,
557        value_id: Word,
558    ) -> Self {
559        let mut instruction = Self::new(Op::AtomicStore);
560        instruction.add_operand(pointer_id);
561        instruction.add_operand(scope_id);
562        instruction.add_operand(semantics_id);
563        instruction.add_operand(value_id);
564        instruction
565    }
566
567    pub(super) fn access_chain(
568        result_type_id: Word,
569        id: Word,
570        base_id: Word,
571        index_ids: &[Word],
572    ) -> Self {
573        let mut instruction = Self::new(Op::AccessChain);
574        instruction.set_type(result_type_id);
575        instruction.set_result(id);
576        instruction.add_operand(base_id);
577
578        for index_id in index_ids {
579            instruction.add_operand(*index_id);
580        }
581
582        instruction
583    }
584
585    pub(super) fn array_length(
586        result_type_id: Word,
587        id: Word,
588        structure_id: Word,
589        array_member: Word,
590    ) -> Self {
591        let mut instruction = Self::new(Op::ArrayLength);
592        instruction.set_type(result_type_id);
593        instruction.set_result(id);
594        instruction.add_operand(structure_id);
595        instruction.add_operand(array_member);
596        instruction
597    }
598
599    //
600    //  Function Instructions
601    //
602
603    pub(super) fn function(
604        return_type_id: Word,
605        id: Word,
606        function_control: spirv::FunctionControl,
607        function_type_id: Word,
608    ) -> Self {
609        let mut instruction = Self::new(Op::Function);
610        instruction.set_type(return_type_id);
611        instruction.set_result(id);
612        instruction.add_operand(function_control.bits());
613        instruction.add_operand(function_type_id);
614        instruction
615    }
616
617    pub(super) fn function_parameter(result_type_id: Word, id: Word) -> Self {
618        let mut instruction = Self::new(Op::FunctionParameter);
619        instruction.set_type(result_type_id);
620        instruction.set_result(id);
621        instruction
622    }
623
624    pub(super) const fn function_end() -> Self {
625        Self::new(Op::FunctionEnd)
626    }
627
628    pub(super) fn function_call(
629        result_type_id: Word,
630        id: Word,
631        function_id: Word,
632        argument_ids: &[Word],
633    ) -> Self {
634        let mut instruction = Self::new(Op::FunctionCall);
635        instruction.set_type(result_type_id);
636        instruction.set_result(id);
637        instruction.add_operand(function_id);
638
639        for argument_id in argument_ids {
640            instruction.add_operand(*argument_id);
641        }
642
643        instruction
644    }
645
646    //
647    //  Image Instructions
648    //
649
650    pub(super) fn sampled_image(
651        result_type_id: Word,
652        id: Word,
653        image: Word,
654        sampler: Word,
655    ) -> Self {
656        let mut instruction = Self::new(Op::SampledImage);
657        instruction.set_type(result_type_id);
658        instruction.set_result(id);
659        instruction.add_operand(image);
660        instruction.add_operand(sampler);
661        instruction
662    }
663
664    pub(super) fn image_sample(
665        result_type_id: Word,
666        id: Word,
667        lod: SampleLod,
668        sampled_image: Word,
669        coordinates: Word,
670        depth_ref: Option<Word>,
671    ) -> Self {
672        let op = match (lod, depth_ref) {
673            (SampleLod::Explicit, None) => Op::ImageSampleExplicitLod,
674            (SampleLod::Implicit, None) => Op::ImageSampleImplicitLod,
675            (SampleLod::Explicit, Some(_)) => Op::ImageSampleDrefExplicitLod,
676            (SampleLod::Implicit, Some(_)) => Op::ImageSampleDrefImplicitLod,
677        };
678
679        let mut instruction = Self::new(op);
680        instruction.set_type(result_type_id);
681        instruction.set_result(id);
682        instruction.add_operand(sampled_image);
683        instruction.add_operand(coordinates);
684        if let Some(dref) = depth_ref {
685            instruction.add_operand(dref);
686        }
687
688        instruction
689    }
690
691    pub(super) fn image_gather(
692        result_type_id: Word,
693        id: Word,
694        sampled_image: Word,
695        coordinates: Word,
696        component_id: Word,
697        depth_ref: Option<Word>,
698    ) -> Self {
699        let op = match depth_ref {
700            None => Op::ImageGather,
701            Some(_) => Op::ImageDrefGather,
702        };
703
704        let mut instruction = Self::new(op);
705        instruction.set_type(result_type_id);
706        instruction.set_result(id);
707        instruction.add_operand(sampled_image);
708        instruction.add_operand(coordinates);
709        if let Some(dref) = depth_ref {
710            instruction.add_operand(dref);
711        } else {
712            instruction.add_operand(component_id);
713        }
714
715        instruction
716    }
717
718    pub(super) fn image_fetch_or_read(
719        op: Op,
720        result_type_id: Word,
721        id: Word,
722        image: Word,
723        coordinates: Word,
724    ) -> Self {
725        let mut instruction = Self::new(op);
726        instruction.set_type(result_type_id);
727        instruction.set_result(id);
728        instruction.add_operand(image);
729        instruction.add_operand(coordinates);
730        instruction
731    }
732
733    pub(super) fn image_write(image: Word, coordinates: Word, value: Word) -> Self {
734        let mut instruction = Self::new(Op::ImageWrite);
735        instruction.add_operand(image);
736        instruction.add_operand(coordinates);
737        instruction.add_operand(value);
738        instruction
739    }
740
741    pub(super) fn image_texel_pointer(
742        result_type_id: Word,
743        id: Word,
744        image: Word,
745        coordinates: Word,
746        sample: Word,
747    ) -> Self {
748        let mut instruction = Self::new(Op::ImageTexelPointer);
749        instruction.set_type(result_type_id);
750        instruction.set_result(id);
751        instruction.add_operand(image);
752        instruction.add_operand(coordinates);
753        instruction.add_operand(sample);
754        instruction
755    }
756
757    pub(super) fn image_atomic(
758        op: Op,
759        result_type_id: Word,
760        id: Word,
761        pointer: Word,
762        scope_id: Word,
763        semantics_id: Word,
764        value: Word,
765    ) -> Self {
766        let mut instruction = Self::new(op);
767        instruction.set_type(result_type_id);
768        instruction.set_result(id);
769        instruction.add_operand(pointer);
770        instruction.add_operand(scope_id);
771        instruction.add_operand(semantics_id);
772        instruction.add_operand(value);
773        instruction
774    }
775
776    pub(super) fn image_query(op: Op, result_type_id: Word, id: Word, image: Word) -> Self {
777        let mut instruction = Self::new(op);
778        instruction.set_type(result_type_id);
779        instruction.set_result(id);
780        instruction.add_operand(image);
781        instruction
782    }
783
784    //
785    //  Ray Query Instructions
786    //
787    #[allow(clippy::too_many_arguments)]
788    pub(super) fn ray_query_initialize(
789        query: Word,
790        acceleration_structure: Word,
791        ray_flags: Word,
792        cull_mask: Word,
793        ray_origin: Word,
794        ray_tmin: Word,
795        ray_dir: Word,
796        ray_tmax: Word,
797    ) -> Self {
798        let mut instruction = Self::new(Op::RayQueryInitializeKHR);
799        instruction.add_operand(query);
800        instruction.add_operand(acceleration_structure);
801        instruction.add_operand(ray_flags);
802        instruction.add_operand(cull_mask);
803        instruction.add_operand(ray_origin);
804        instruction.add_operand(ray_tmin);
805        instruction.add_operand(ray_dir);
806        instruction.add_operand(ray_tmax);
807        instruction
808    }
809
810    pub(super) fn ray_query_proceed(result_type_id: Word, id: Word, query: Word) -> Self {
811        let mut instruction = Self::new(Op::RayQueryProceedKHR);
812        instruction.set_type(result_type_id);
813        instruction.set_result(id);
814        instruction.add_operand(query);
815        instruction
816    }
817
818    pub(super) fn ray_query_generate_intersection(query: Word, hit: Word) -> Self {
819        let mut instruction = Self::new(Op::RayQueryGenerateIntersectionKHR);
820        instruction.add_operand(query);
821        instruction.add_operand(hit);
822        instruction
823    }
824
825    pub(super) fn ray_query_confirm_intersection(query: Word) -> Self {
826        let mut instruction = Self::new(Op::RayQueryConfirmIntersectionKHR);
827        instruction.add_operand(query);
828        instruction
829    }
830
831    pub(super) fn ray_query_return_vertex_position(
832        result_type_id: Word,
833        id: Word,
834        query: Word,
835        intersection: Word,
836    ) -> Self {
837        let mut instruction = Self::new(Op::RayQueryGetIntersectionTriangleVertexPositionsKHR);
838        instruction.set_type(result_type_id);
839        instruction.set_result(id);
840        instruction.add_operand(query);
841        instruction.add_operand(intersection);
842        instruction
843    }
844
845    pub(super) fn ray_query_get_intersection(
846        op: Op,
847        result_type_id: Word,
848        id: Word,
849        query: Word,
850        intersection: Word,
851    ) -> Self {
852        let mut instruction = Self::new(op);
853        instruction.set_type(result_type_id);
854        instruction.set_result(id);
855        instruction.add_operand(query);
856        instruction.add_operand(intersection);
857        instruction
858    }
859
860    pub(super) fn ray_query_get_t_min(result_type_id: Word, id: Word, query: Word) -> Self {
861        Self::ray_query_get(Op::RayQueryGetRayTMinKHR, result_type_id, id, query)
862    }
863
864    /// Any of the `OpRayQueryGet*KHR` instructions that describe the ray
865    /// itself rather than an intersection, and so take only the ray query.
866    pub(super) fn ray_query_get(op: Op, result_type_id: Word, id: Word, query: Word) -> Self {
867        let mut instruction = Self::new(op);
868        instruction.set_type(result_type_id);
869        instruction.set_result(id);
870        instruction.add_operand(query);
871        instruction
872    }
873
874    pub(super) fn ray_query_terminate(query: Word) -> Self {
875        let mut instruction = Self::new(Op::RayQueryTerminateKHR);
876        instruction.add_operand(query);
877        instruction
878    }
879
880    //
881    //  Ray Tracing Pipeline Instructions
882    //
883
884    #[expect(clippy::too_many_arguments)]
885    pub(super) fn trace_ray(
886        acceleration_structure: Word,
887        ray_flags: Word,
888        cull_mask: Word,
889        sbt_offset: Word,
890        sbt_stride: Word,
891        miss_idx: Word,
892        ray_origin: Word,
893        ray_tmin: Word,
894        ray_dir: Word,
895        ray_tmax: Word,
896        payload: Word,
897    ) -> Self {
898        let mut instruction = Self::new(Op::TraceRayKHR);
899        instruction.add_operand(acceleration_structure);
900        instruction.add_operand(ray_flags);
901        instruction.add_operand(cull_mask);
902        instruction.add_operand(sbt_offset);
903        instruction.add_operand(sbt_stride);
904        instruction.add_operand(miss_idx);
905        instruction.add_operand(ray_origin);
906        instruction.add_operand(ray_tmin);
907        instruction.add_operand(ray_dir);
908        instruction.add_operand(ray_tmax);
909        instruction.add_operand(payload);
910        instruction
911    }
912
913    //
914    //  Ray Tracing Invocation Reorder Instructions
915    //
916
917    #[expect(clippy::too_many_arguments)]
918    pub(super) fn hit_object_trace_ray(
919        hit_object: Word,
920        acceleration_structure: Word,
921        ray_flags: Word,
922        cull_mask: Word,
923        sbt_offset: Word,
924        sbt_stride: Word,
925        miss_idx: Word,
926        ray_origin: Word,
927        ray_tmin: Word,
928        ray_dir: Word,
929        ray_tmax: Word,
930        payload: Word,
931    ) -> Self {
932        let mut instruction = Self::new(Op::HitObjectTraceRayEXT);
933        instruction.add_operand(hit_object);
934        instruction.add_operand(acceleration_structure);
935        instruction.add_operand(ray_flags);
936        instruction.add_operand(cull_mask);
937        instruction.add_operand(sbt_offset);
938        instruction.add_operand(sbt_stride);
939        instruction.add_operand(miss_idx);
940        instruction.add_operand(ray_origin);
941        instruction.add_operand(ray_tmin);
942        instruction.add_operand(ray_dir);
943        instruction.add_operand(ray_tmax);
944        instruction.add_operand(payload);
945        instruction
946    }
947
948    pub(super) fn hit_object_record_miss(
949        hit_object: Word,
950        ray_flags: Word,
951        miss_idx: Word,
952        ray_origin: Word,
953        ray_tmin: Word,
954        ray_dir: Word,
955        ray_tmax: Word,
956    ) -> Self {
957        let mut instruction = Self::new(Op::HitObjectRecordMissEXT);
958        instruction.add_operand(hit_object);
959        instruction.add_operand(ray_flags);
960        instruction.add_operand(miss_idx);
961        instruction.add_operand(ray_origin);
962        instruction.add_operand(ray_tmin);
963        instruction.add_operand(ray_dir);
964        instruction.add_operand(ray_tmax);
965        instruction
966    }
967
968    /// `OpHitObjectRecordFromQueryEXT`.
969    ///
970    /// The `Hit Kind` operand is optional in SPIR-V. Revision 3 of
971    /// `SPV_EXT_shader_invocation_reorder` requires it whenever the ray
972    /// query's committed intersection is a procedural (AABB) one, and ignores
973    /// it for triangle intersections, whose hit kind is taken from the ray
974    /// query.
975    pub(super) fn hit_object_record_from_query(
976        hit_object: Word,
977        ray_query: Word,
978        sbt_index: Word,
979        attributes: Word,
980        hit_kind: Option<Word>,
981    ) -> Self {
982        let mut instruction = Self::new(Op::HitObjectRecordFromQueryEXT);
983        instruction.add_operand(hit_object);
984        instruction.add_operand(ray_query);
985        instruction.add_operand(sbt_index);
986        instruction.add_operand(attributes);
987        if let Some(hit_kind) = hit_kind {
988            instruction.add_operand(hit_kind);
989        }
990        instruction
991    }
992
993    pub(super) fn hit_object_record_empty(hit_object: Word) -> Self {
994        let mut instruction = Self::new(Op::HitObjectRecordEmptyEXT);
995        instruction.add_operand(hit_object);
996        instruction
997    }
998
999    pub(super) fn hit_object_execute_shader(hit_object: Word, payload: Word) -> Self {
1000        let mut instruction = Self::new(Op::HitObjectExecuteShaderEXT);
1001        instruction.add_operand(hit_object);
1002        instruction.add_operand(payload);
1003        instruction
1004    }
1005
1006    /// Any of the `OpHitObjectGet*EXT` / `OpHitObjectIs*EXT` instructions,
1007    /// which all take a single hit object operand and produce a result.
1008    pub(super) fn hit_object_get(op: Op, result_type_id: Word, id: Word, hit_object: Word) -> Self {
1009        let mut instruction = Self::new(op);
1010        instruction.set_type(result_type_id);
1011        instruction.set_result(id);
1012        instruction.add_operand(hit_object);
1013        instruction
1014    }
1015
1016    pub(super) fn hit_object_get_attributes(hit_object: Word, attributes: Word) -> Self {
1017        let mut instruction = Self::new(Op::HitObjectGetAttributesEXT);
1018        instruction.add_operand(hit_object);
1019        instruction.add_operand(attributes);
1020        instruction
1021    }
1022
1023    pub(super) fn reorder_thread_with_hint(hint: Word, bits: Word) -> Self {
1024        let mut instruction = Self::new(Op::ReorderThreadWithHintEXT);
1025        instruction.add_operand(hint);
1026        instruction.add_operand(bits);
1027        instruction
1028    }
1029
1030    pub(super) fn reorder_thread_with_hit_object(
1031        hit_object: Word,
1032        hint: Option<(Word, Word)>,
1033    ) -> Self {
1034        let mut instruction = Self::new(Op::ReorderThreadWithHitObjectEXT);
1035        instruction.add_operand(hit_object);
1036        if let Some((hint, bits)) = hint {
1037            instruction.add_operand(hint);
1038            instruction.add_operand(bits);
1039        }
1040        instruction
1041    }
1042
1043    //
1044    //  Conversion Instructions
1045    //
1046    pub(super) fn unary(op: Op, result_type_id: Word, id: Word, value: Word) -> Self {
1047        let mut instruction = Self::new(op);
1048        instruction.set_type(result_type_id);
1049        instruction.set_result(id);
1050        instruction.add_operand(value);
1051        instruction
1052    }
1053
1054    //
1055    //  Composite Instructions
1056    //
1057
1058    pub(super) fn composite_construct(
1059        result_type_id: Word,
1060        id: Word,
1061        constituent_ids: &[Word],
1062    ) -> Self {
1063        let mut instruction = Self::new(Op::CompositeConstruct);
1064        instruction.set_type(result_type_id);
1065        instruction.set_result(id);
1066
1067        for constituent_id in constituent_ids {
1068            instruction.add_operand(*constituent_id);
1069        }
1070
1071        instruction
1072    }
1073
1074    pub(super) fn composite_extract(
1075        result_type_id: Word,
1076        id: Word,
1077        composite_id: Word,
1078        indices: &[Word],
1079    ) -> Self {
1080        let mut instruction = Self::new(Op::CompositeExtract);
1081        instruction.set_type(result_type_id);
1082        instruction.set_result(id);
1083
1084        instruction.add_operand(composite_id);
1085        for index in indices {
1086            instruction.add_operand(*index);
1087        }
1088
1089        instruction
1090    }
1091
1092    pub(super) fn vector_extract_dynamic(
1093        result_type_id: Word,
1094        id: Word,
1095        vector_id: Word,
1096        index_id: Word,
1097    ) -> Self {
1098        let mut instruction = Self::new(Op::VectorExtractDynamic);
1099        instruction.set_type(result_type_id);
1100        instruction.set_result(id);
1101
1102        instruction.add_operand(vector_id);
1103        instruction.add_operand(index_id);
1104
1105        instruction
1106    }
1107
1108    pub(super) fn vector_shuffle(
1109        result_type_id: Word,
1110        id: Word,
1111        v1_id: Word,
1112        v2_id: Word,
1113        components: &[Word],
1114    ) -> Self {
1115        let mut instruction = Self::new(Op::VectorShuffle);
1116        instruction.set_type(result_type_id);
1117        instruction.set_result(id);
1118        instruction.add_operand(v1_id);
1119        instruction.add_operand(v2_id);
1120
1121        for &component in components {
1122            instruction.add_operand(component);
1123        }
1124
1125        instruction
1126    }
1127
1128    //
1129    // Arithmetic Instructions
1130    //
1131    pub(super) fn binary(
1132        op: Op,
1133        result_type_id: Word,
1134        id: Word,
1135        operand_1: Word,
1136        operand_2: Word,
1137    ) -> Self {
1138        let mut instruction = Self::new(op);
1139        instruction.set_type(result_type_id);
1140        instruction.set_result(id);
1141        instruction.add_operand(operand_1);
1142        instruction.add_operand(operand_2);
1143        instruction
1144    }
1145
1146    pub(super) fn ternary(
1147        op: Op,
1148        result_type_id: Word,
1149        id: Word,
1150        operand_1: Word,
1151        operand_2: Word,
1152        operand_3: Word,
1153    ) -> Self {
1154        let mut instruction = Self::new(op);
1155        instruction.set_type(result_type_id);
1156        instruction.set_result(id);
1157        instruction.add_operand(operand_1);
1158        instruction.add_operand(operand_2);
1159        instruction.add_operand(operand_3);
1160        instruction
1161    }
1162
1163    pub(super) fn quaternary(
1164        op: Op,
1165        result_type_id: Word,
1166        id: Word,
1167        operand_1: Word,
1168        operand_2: Word,
1169        operand_3: Word,
1170        operand_4: Word,
1171    ) -> Self {
1172        let mut instruction = Self::new(op);
1173        instruction.set_type(result_type_id);
1174        instruction.set_result(id);
1175        instruction.add_operand(operand_1);
1176        instruction.add_operand(operand_2);
1177        instruction.add_operand(operand_3);
1178        instruction.add_operand(operand_4);
1179        instruction
1180    }
1181
1182    pub(super) fn relational(op: Op, result_type_id: Word, id: Word, expr_id: Word) -> Self {
1183        let mut instruction = Self::new(op);
1184        instruction.set_type(result_type_id);
1185        instruction.set_result(id);
1186        instruction.add_operand(expr_id);
1187        instruction
1188    }
1189
1190    pub(super) fn atomic_binary(
1191        op: Op,
1192        result_type_id: Word,
1193        id: Word,
1194        pointer: Word,
1195        scope_id: Word,
1196        semantics_id: Word,
1197        value: Word,
1198    ) -> Self {
1199        let mut instruction = Self::new(op);
1200        instruction.set_type(result_type_id);
1201        instruction.set_result(id);
1202        instruction.add_operand(pointer);
1203        instruction.add_operand(scope_id);
1204        instruction.add_operand(semantics_id);
1205        instruction.add_operand(value);
1206        instruction
1207    }
1208
1209    //
1210    // Bit Instructions
1211    //
1212
1213    //
1214    // Relational and Logical Instructions
1215    //
1216
1217    //
1218    // Derivative Instructions
1219    //
1220
1221    pub(super) fn derivative(op: Op, result_type_id: Word, id: Word, expr_id: Word) -> Self {
1222        let mut instruction = Self::new(op);
1223        instruction.set_type(result_type_id);
1224        instruction.set_result(id);
1225        instruction.add_operand(expr_id);
1226        instruction
1227    }
1228
1229    //
1230    // Control-Flow Instructions
1231    //
1232
1233    pub(super) fn phi(
1234        result_type_id: Word,
1235        result_id: Word,
1236        var_parent_pairs: &[(Word, Word)],
1237    ) -> Self {
1238        let mut instruction = Self::new(Op::Phi);
1239        instruction.add_operand(result_type_id);
1240        instruction.add_operand(result_id);
1241        for &(variable, parent) in var_parent_pairs {
1242            instruction.add_operand(variable);
1243            instruction.add_operand(parent);
1244        }
1245        instruction
1246    }
1247
1248    pub(super) fn selection_merge(
1249        merge_id: Word,
1250        selection_control: spirv::SelectionControl,
1251    ) -> Self {
1252        let mut instruction = Self::new(Op::SelectionMerge);
1253        instruction.add_operand(merge_id);
1254        instruction.add_operand(selection_control.bits());
1255        instruction
1256    }
1257
1258    pub(super) fn loop_merge(
1259        merge_id: Word,
1260        continuing_id: Word,
1261        selection_control: spirv::SelectionControl,
1262    ) -> Self {
1263        let mut instruction = Self::new(Op::LoopMerge);
1264        instruction.add_operand(merge_id);
1265        instruction.add_operand(continuing_id);
1266        instruction.add_operand(selection_control.bits());
1267        instruction
1268    }
1269
1270    pub(super) fn label(id: Word) -> Self {
1271        let mut instruction = Self::new(Op::Label);
1272        instruction.set_result(id);
1273        instruction
1274    }
1275
1276    pub(super) fn branch(id: Word) -> Self {
1277        let mut instruction = Self::new(Op::Branch);
1278        instruction.add_operand(id);
1279        instruction
1280    }
1281
1282    // TODO Branch Weights not implemented.
1283    pub(super) fn branch_conditional(
1284        condition_id: Word,
1285        true_label: Word,
1286        false_label: Word,
1287    ) -> Self {
1288        let mut instruction = Self::new(Op::BranchConditional);
1289        instruction.add_operand(condition_id);
1290        instruction.add_operand(true_label);
1291        instruction.add_operand(false_label);
1292        instruction
1293    }
1294
1295    pub(super) fn switch(selector_id: Word, default_id: Word, cases: &[Case]) -> Self {
1296        let mut instruction = Self::new(Op::Switch);
1297        instruction.add_operand(selector_id);
1298        instruction.add_operand(default_id);
1299        for case in cases {
1300            instruction.add_operand(case.value);
1301            instruction.add_operand(case.label_id);
1302        }
1303        instruction
1304    }
1305
1306    pub(super) fn select(
1307        result_type_id: Word,
1308        id: Word,
1309        condition_id: Word,
1310        accept_id: Word,
1311        reject_id: Word,
1312    ) -> Self {
1313        let mut instruction = Self::new(Op::Select);
1314        instruction.add_operand(result_type_id);
1315        instruction.add_operand(id);
1316        instruction.add_operand(condition_id);
1317        instruction.add_operand(accept_id);
1318        instruction.add_operand(reject_id);
1319        instruction
1320    }
1321
1322    pub(super) const fn kill() -> Self {
1323        Self::new(Op::Kill)
1324    }
1325
1326    pub(super) const fn return_void() -> Self {
1327        Self::new(Op::Return)
1328    }
1329
1330    pub(super) fn return_value(value_id: Word) -> Self {
1331        let mut instruction = Self::new(Op::ReturnValue);
1332        instruction.add_operand(value_id);
1333        instruction
1334    }
1335
1336    //
1337    //  Atomic Instructions
1338    //
1339
1340    //
1341    //  Primitive Instructions
1342    //
1343
1344    // Barriers
1345
1346    pub(super) fn control_barrier(
1347        exec_scope_id: Word,
1348        mem_scope_id: Word,
1349        semantics_id: Word,
1350    ) -> Self {
1351        let mut instruction = Self::new(Op::ControlBarrier);
1352        instruction.add_operand(exec_scope_id);
1353        instruction.add_operand(mem_scope_id);
1354        instruction.add_operand(semantics_id);
1355        instruction
1356    }
1357    pub(super) fn memory_barrier(mem_scope_id: Word, semantics_id: Word) -> Self {
1358        let mut instruction = Self::new(Op::MemoryBarrier);
1359        instruction.add_operand(mem_scope_id);
1360        instruction.add_operand(semantics_id);
1361        instruction
1362    }
1363
1364    // Group Instructions
1365
1366    pub(super) fn group_non_uniform_ballot(
1367        result_type_id: Word,
1368        id: Word,
1369        exec_scope_id: Word,
1370        predicate: Word,
1371    ) -> Self {
1372        let mut instruction = Self::new(Op::GroupNonUniformBallot);
1373        instruction.set_type(result_type_id);
1374        instruction.set_result(id);
1375        instruction.add_operand(exec_scope_id);
1376        instruction.add_operand(predicate);
1377
1378        instruction
1379    }
1380    pub(super) fn group_non_uniform_broadcast_first(
1381        result_type_id: Word,
1382        id: Word,
1383        exec_scope_id: Word,
1384        value: Word,
1385    ) -> Self {
1386        let mut instruction = Self::new(Op::GroupNonUniformBroadcastFirst);
1387        instruction.set_type(result_type_id);
1388        instruction.set_result(id);
1389        instruction.add_operand(exec_scope_id);
1390        instruction.add_operand(value);
1391
1392        instruction
1393    }
1394    pub(super) fn group_non_uniform_ballot_find_bit(
1395        op: Op,
1396        result_type_id: Word,
1397        id: Word,
1398        exec_scope_id: Word,
1399        value: Word,
1400    ) -> Self {
1401        let mut instruction = Self::new(op);
1402        instruction.set_type(result_type_id);
1403        instruction.set_result(id);
1404        instruction.add_operand(exec_scope_id);
1405        instruction.add_operand(value);
1406
1407        instruction
1408    }
1409    pub(super) fn group_non_uniform_gather(
1410        op: Op,
1411        result_type_id: Word,
1412        id: Word,
1413        exec_scope_id: Word,
1414        value: Word,
1415        index: Word,
1416    ) -> Self {
1417        let mut instruction = Self::new(op);
1418        instruction.set_type(result_type_id);
1419        instruction.set_result(id);
1420        instruction.add_operand(exec_scope_id);
1421        instruction.add_operand(value);
1422        instruction.add_operand(index);
1423
1424        instruction
1425    }
1426    pub(super) fn group_non_uniform_arithmetic(
1427        op: Op,
1428        result_type_id: Word,
1429        id: Word,
1430        exec_scope_id: Word,
1431        group_op: Option<spirv::GroupOperation>,
1432        value: Word,
1433    ) -> Self {
1434        let mut instruction = Self::new(op);
1435        instruction.set_type(result_type_id);
1436        instruction.set_result(id);
1437        instruction.add_operand(exec_scope_id);
1438        if let Some(group_op) = group_op {
1439            instruction.add_operand(group_op as u32);
1440        }
1441        instruction.add_operand(value);
1442
1443        instruction
1444    }
1445    pub(super) fn group_non_uniform_quad_swap(
1446        result_type_id: Word,
1447        id: Word,
1448        exec_scope_id: Word,
1449        value: Word,
1450        direction: Word,
1451    ) -> Self {
1452        let mut instruction = Self::new(Op::GroupNonUniformQuadSwap);
1453        instruction.set_type(result_type_id);
1454        instruction.set_result(id);
1455        instruction.add_operand(exec_scope_id);
1456        instruction.add_operand(value);
1457        instruction.add_operand(direction);
1458
1459        instruction
1460    }
1461
1462    // Cooperative operations
1463    pub(super) fn coop_load(
1464        result_type_id: Word,
1465        id: Word,
1466        pointer_id: Word,
1467        layout_id: Word,
1468        stride_id: Word,
1469    ) -> Self {
1470        let mut instruction = Self::new(Op::CooperativeMatrixLoadKHR);
1471        instruction.set_type(result_type_id);
1472        instruction.set_result(id);
1473        instruction.add_operand(pointer_id);
1474        instruction.add_operand(layout_id);
1475        instruction.add_operand(stride_id);
1476        instruction
1477    }
1478    pub(super) fn coop_store(id: Word, pointer_id: Word, layout_id: Word, stride_id: Word) -> Self {
1479        let mut instruction = Self::new(Op::CooperativeMatrixStoreKHR);
1480        instruction.add_operand(pointer_id);
1481        instruction.add_operand(id);
1482        instruction.add_operand(layout_id);
1483        instruction.add_operand(stride_id);
1484        instruction
1485    }
1486    pub(super) fn coop_mul_add(result_type_id: Word, id: Word, a: Word, b: Word, c: Word) -> Self {
1487        let mut instruction = Self::new(Op::CooperativeMatrixMulAddKHR);
1488        instruction.set_type(result_type_id);
1489        instruction.set_result(id);
1490        instruction.add_operand(a);
1491        instruction.add_operand(b);
1492        instruction.add_operand(c);
1493
1494        instruction
1495    }
1496}
1497
1498impl From<crate::StorageFormat> for spirv::ImageFormat {
1499    fn from(format: crate::StorageFormat) -> Self {
1500        use crate::StorageFormat as Sf;
1501        match format {
1502            Sf::R8Unorm => Self::R8,
1503            Sf::R8Snorm => Self::R8Snorm,
1504            Sf::R8Uint => Self::R8ui,
1505            Sf::R8Sint => Self::R8i,
1506            Sf::R16Uint => Self::R16ui,
1507            Sf::R16Sint => Self::R16i,
1508            Sf::R16Float => Self::R16f,
1509            Sf::Rg8Unorm => Self::Rg8,
1510            Sf::Rg8Snorm => Self::Rg8Snorm,
1511            Sf::Rg8Uint => Self::Rg8ui,
1512            Sf::Rg8Sint => Self::Rg8i,
1513            Sf::R32Uint => Self::R32ui,
1514            Sf::R32Sint => Self::R32i,
1515            Sf::R32Float => Self::R32f,
1516            Sf::Rg16Uint => Self::Rg16ui,
1517            Sf::Rg16Sint => Self::Rg16i,
1518            Sf::Rg16Float => Self::Rg16f,
1519            Sf::Rgba8Unorm => Self::Rgba8,
1520            Sf::Rgba8Snorm => Self::Rgba8Snorm,
1521            Sf::Rgba8Uint => Self::Rgba8ui,
1522            Sf::Rgba8Sint => Self::Rgba8i,
1523            Sf::Bgra8Unorm => Self::Unknown,
1524            Sf::Rgb10a2Uint => Self::Rgb10a2ui,
1525            Sf::Rgb10a2Unorm => Self::Rgb10A2,
1526            Sf::Rg11b10Ufloat => Self::R11fG11fB10f,
1527            Sf::R64Uint => Self::R64ui,
1528            Sf::Rg32Uint => Self::Rg32ui,
1529            Sf::Rg32Sint => Self::Rg32i,
1530            Sf::Rg32Float => Self::Rg32f,
1531            Sf::Rgba16Uint => Self::Rgba16ui,
1532            Sf::Rgba16Sint => Self::Rgba16i,
1533            Sf::Rgba16Float => Self::Rgba16f,
1534            Sf::Rgba32Uint => Self::Rgba32ui,
1535            Sf::Rgba32Sint => Self::Rgba32i,
1536            Sf::Rgba32Float => Self::Rgba32f,
1537            Sf::R16Unorm => Self::R16,
1538            Sf::R16Snorm => Self::R16Snorm,
1539            Sf::Rg16Unorm => Self::Rg16,
1540            Sf::Rg16Snorm => Self::Rg16Snorm,
1541            Sf::Rgba16Unorm => Self::Rgba16,
1542            Sf::Rgba16Snorm => Self::Rgba16Snorm,
1543        }
1544    }
1545}
1546
1547impl From<crate::ImageDimension> for spirv::Dim {
1548    fn from(dim: crate::ImageDimension) -> Self {
1549        use crate::ImageDimension as Id;
1550        match dim {
1551            Id::D1 => Self::Dim1D,
1552            Id::D2 => Self::Dim2D,
1553            Id::D3 => Self::Dim3D,
1554            Id::Cube => Self::DimCube,
1555        }
1556    }
1557}
1558
1559impl From<crate::CooperativeRole> for spirv::CooperativeMatrixUse {
1560    fn from(role: crate::CooperativeRole) -> Self {
1561        match role {
1562            crate::CooperativeRole::A => Self::MatrixAKHR,
1563            crate::CooperativeRole::B => Self::MatrixBKHR,
1564            crate::CooperativeRole::C => Self::MatrixAccumulatorKHR,
1565        }
1566    }
1567}