Translator: GPU-encoded indexed triangle draws into indirect command buffers under the identity domains

What: the first cut of Metal indirect command buffers, the translator's half.

- pipeline::IndirectDrawLayout (public): the record contract the runtime and the lowering share.
  A 24-byte header (capacity, vertex and fragment slot counts and stride as u32, then the reset
  index address as u64 at 16), then command i at 24 + i * stride, stride = 8 (Nv + Nf) + 40:
  the slot words (the buffer's address less 2^31, the word an execution pushes as the slot's
  SlotGuestBase), the index token's data, the sequence index and VkDrawIndexedIndirectCommand.
- lower/access/icb.rs: under the identity domains, a function's render_command
  set_vertex_buffer, set_fragment_buffer, draw_indexed_primitives of triangles and reset write
  the records through the gpuResourceID an argument buffer's command_buffer member holds, each
  only where the command's index is below the capacity (and a slot below its stage's count).
  Every other indirect-command operation stays Unsupported{GpuEncodedIndirectCommands,
  NotImplemented}; a vertex or fragment function without its stage's store feature and a device
  without device addresses refuse by name.
- LoweringInputs::indirect_range with PushField::IndirectRange, PushField::IndirectSequence and
  PushField::IndirectBase: a vertex function of a state made with supportIndirectCommandBuffers
  reads the execution's range and its command (the sequence index plus its part's first command)
  in its first block and draws nothing for a command outside the range, so an execution over a
  range a buffer holds runs at full capacity (one SEQUENCE_INDEX token), in parts. Such a state's
  vertex function pulls every attribute it reads.
- Fixture engine/icb_indexed_extras (MSL we wrote, regenerated by scripts/regen-air-fixtures):
  a reset kernel, a vertex function that reads before its buffer's address, and one of fourteen
  vertex buffers (a state of more tokens than lavapipe's 16). Inventory rows added by hand (the
  fourteen-buffer vertex function's thirteen constant buffers pass the runtime floor's twelve);
  the golden hash rows, the air_input printout and the old render descriptor key come with
  development's bless.
- SEMANTICS_VERSION 2252 and ARTIFACT_FORMAT_VERSION 586 are placeholders one above
  development's (2251 and 585); the lowering's emission and the encoded lowering inputs change.
- docs/API.md states the forms; docs/REFUSALS.md regenerated; api_surface and api_signatures
  carry IndirectDrawLayout.

Why: the cutover's guests encode indexed draws into indirect command buffers from kernels, which
the identity domains refused.

Verified: see the lane's report (compile gate and test jobs, the states-only play).
This commit is contained in:
Anees Iqbal committed 2026-11-21 01:50:00 -08:00
1 parent 7fc969bc16
commit d9ba8d0e72
30 files changed
+1651 -24

No files matched your search

@@ -164,6 +164,7 @@ fixture icb_copy_encode: metal: Apple metal version 32023.921 (metalfe-32023.921
fixture icb_depth_indexed_encode: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118)
fixture icb_imageblock_encode: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
fixture icb_imageblock_template: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425)
fixture icb_indexed_extras: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118)
fixture icb_inherited_dispatches: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118)
fixture icb_merged_arguments: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118)
fixture icb_merged_attributes: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118)
@@ -0,0 +1,257 @@
; Generated by scripts/regen-air-fixtures from icb_indexed_extras.metal (typed pointers; xcrun metal-as reassembles it). Do not edit.
; ModuleID = '-'
source_filename = "-"
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
target triple = "air64_v28-apple-macosx26.0.0"
%struct.ResetCommands = type { %"struct.metal::command_buffer" }
%"struct.metal::command_buffer" = type { %struct._command_buffer_t addrspace(1)* }
%struct._command_buffer_t = type opaque
; Function Attrs: mustprogress nounwind willreturn
define void @icb_extras_reset(%struct.ResetCommands addrspace(1)* nocapture noundef readonly align 8 dereferenceable(8) "air-buffer-no-alias" %0, i32 addrspace(2)* nocapture noundef readonly "air-buffer-no-alias" %1, i32 noundef %2) local_unnamed_addr #0 {
%4 = getelementptr inbounds %struct.ResetCommands, %struct.ResetCommands addrspace(1)* %0, i64 0, i32 0, i32 0
%5 = load %struct._command_buffer_t addrspace(1)*, %struct._command_buffer_t addrspace(1)* addrspace(1)* %4, align 8, !tbaa.struct !59, !alias.scope !64, !noalias !67
%6 = load i32, i32 addrspace(2)* %1, align 4, !tbaa !69, !alias.scope !67, !noalias !64
%7 = add i32 %6, %2
tail call void @air.reset_render_command(%struct._command_buffer_t addrspace(1)* nocapture %5, i32 %7) #6
ret void
}
; Function Attrs: argmemonly mustprogress nofree nosync nounwind readonly willreturn
define <{ <4 x float>, <4 x i32> }> @icb_extras_back_vertex(i32 noundef %0, i32 noundef %1, i32 addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %2, <4 x float> addrspace(2)* nocapture noundef readonly align 16 dereferenceable(16) "air-buffer-no-alias" %3, <2 x float> addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %4) local_unnamed_addr #1 {
%6 = add nsw i32 %0, -4
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds <2 x float>, <2 x float> addrspace(1)* %4, i64 %7
%9 = load <2 x float>, <2 x float> addrspace(1)* %8, align 8, !tbaa !71, !alias.scope !72, !noalias !75
%10 = tail call fast float @air.convert.f.f32.u.i32(i32 %1) #7
%11 = load <4 x float>, <4 x float> addrspace(2)* %3, align 16, !alias.scope !78, !noalias !79
%12 = extractelement <4 x float> %11, i64 2
%13 = fmul fast float %12, %10
%14 = insertelement <2 x float> <float 0.000000e+00, float poison>, float %13, i64 1
%15 = fadd fast <2 x float> %14, %9
%16 = extractelement <2 x float> %15, i64 0
%17 = fmul fast float %16, 2.000000e+00
%18 = extractelement <4 x float> %11, i64 0
%19 = fdiv fast float %17, %18
%20 = fadd fast float %19, -1.000000e+00
%21 = extractelement <2 x float> %15, i64 1
%22 = fmul fast float %21, 2.000000e+00
%23 = extractelement <4 x float> %11, i64 1
%24 = fdiv fast float %22, %23
%25 = fsub fast float 1.000000e+00, %24
%26 = insertelement <4 x float> <float poison, float poison, float 0.000000e+00, float 1.000000e+00>, float %20, i64 0
%27 = insertelement <4 x float> %26, float %25, i64 1
%28 = load i32, i32 addrspace(2)* %2, align 4, !tbaa !69, !alias.scope !80, !noalias !81
%29 = insertelement <4 x i32> <i32 poison, i32 poison, i32 poison, i32 0>, i32 %28, i64 0
%30 = insertelement <4 x i32> %29, i32 %0, i64 1
%31 = insertelement <4 x i32> %30, i32 %1, i64 2
%32 = insertvalue <{ <4 x float>, <4 x i32> }> undef, <4 x float> %27, 0
%33 = insertvalue <{ <4 x float>, <4 x i32> }> %32, <4 x i32> %31, 1
ret <{ <4 x float>, <4 x i32> }> %33
}
; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn
declare float @air.convert.f.f32.u.i32(i32) local_unnamed_addr #2
; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone willreturn
define <4 x i32> @icb_extras_back_fragment(<4 x float> %0, <4 x i32> %1, i32 addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %2) local_unnamed_addr #3 {
%4 = load i32, i32 addrspace(2)* %2, align 4, !tbaa !69, !alias.scope !82
%5 = insertelement <4 x i32> %1, i32 %4, i64 3
ret <4 x i32> %5
}
; Function Attrs: argmemonly mustprogress nofree norecurse nosync nounwind readonly willreturn
define <4 x float> @icb_extras_wide_vertex(i32 noundef %0, <2 x float> addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %1, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %2, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %3, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %4, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %5, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %6, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %7, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %8, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %9, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %10, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %11, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %12, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %13, float addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %14) local_unnamed_addr #4 {
%16 = load float, float addrspace(2)* %2, align 4, !tbaa !85, !alias.scope !87, !noalias !90
%17 = load float, float addrspace(2)* %3, align 4, !tbaa !85, !alias.scope !104, !noalias !105
%18 = fadd fast float %17, %16
%19 = load float, float addrspace(2)* %4, align 4, !tbaa !85, !alias.scope !106, !noalias !107
%20 = fadd fast float %18, %19
%21 = load float, float addrspace(2)* %5, align 4, !tbaa !85, !alias.scope !108, !noalias !109
%22 = fadd fast float %20, %21
%23 = load float, float addrspace(2)* %6, align 4, !tbaa !85, !alias.scope !110, !noalias !111
%24 = fadd fast float %22, %23
%25 = load float, float addrspace(2)* %7, align 4, !tbaa !85, !alias.scope !112, !noalias !113
%26 = fadd fast float %24, %25
%27 = load float, float addrspace(2)* %8, align 4, !tbaa !85, !alias.scope !114, !noalias !115
%28 = fadd fast float %26, %27
%29 = load float, float addrspace(2)* %9, align 4, !tbaa !85, !alias.scope !116, !noalias !117
%30 = fadd fast float %28, %29
%31 = load float, float addrspace(2)* %10, align 4, !tbaa !85, !alias.scope !118, !noalias !119
%32 = fadd fast float %30, %31
%33 = load float, float addrspace(2)* %11, align 4, !tbaa !85, !alias.scope !120, !noalias !121
%34 = fadd fast float %32, %33
%35 = load float, float addrspace(2)* %12, align 4, !tbaa !85, !alias.scope !122, !noalias !123
%36 = fadd fast float %34, %35
%37 = load float, float addrspace(2)* %13, align 4, !tbaa !85, !alias.scope !124, !noalias !125
%38 = fadd fast float %36, %37
%39 = load float, float addrspace(2)* %14, align 4, !tbaa !85, !alias.scope !126, !noalias !127
%40 = fadd fast float %38, %39
%41 = zext i32 %0 to i64
%42 = getelementptr inbounds <2 x float>, <2 x float> addrspace(1)* %1, i64 %41
%43 = load <2 x float>, <2 x float> addrspace(1)* %42, align 8, !tbaa !71, !alias.scope !128, !noalias !129
%44 = insertelement <2 x float> undef, float %40, i64 0
%45 = shufflevector <2 x float> %44, <2 x float> poison, <2 x i32> zeroinitializer
%46 = fadd fast <2 x float> %45, %43
%47 = shufflevector <2 x float> %46, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
%48 = shufflevector <4 x float> %47, <4 x float> <float poison, float poison, float 0.000000e+00, float 1.000000e+00>, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
ret <4 x float> %48
}
; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone willreturn
define <4 x i32> @icb_extras_fragment() local_unnamed_addr #3 {
ret <4 x i32> <i32 1, i32 1, i32 1, i32 1>
}
; Function Attrs: mustprogress nounwind willreturn
declare void @air.reset_render_command(%struct._command_buffer_t addrspace(1)* nocapture, i32) local_unnamed_addr #5
attributes #0 = { mustprogress nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #1 = { argmemonly mustprogress nofree nosync nounwind readonly willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #2 = { mustprogress nofree nosync nounwind readnone willreturn }
attributes #3 = { mustprogress nofree norecurse nosync nounwind readnone willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #4 = { argmemonly mustprogress nofree norecurse nosync nounwind readonly willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #5 = { mustprogress nounwind willreturn }
attributes #6 = { nounwind willreturn }
attributes #7 = { nounwind readnone willreturn }
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
!air.kernel = !{!9}
!air.vertex = !{!17, !27}
!air.fragment = !{!45, !52}
!air.compile_options = !{!53, !54, !55}
!llvm.ident = !{!56}
!air.version = !{!57}
!air.language_version = !{!58}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 7, !"frame-pointer", i32 2}
!3 = !{i32 7, !"air.max_device_buffers", i32 31}
!4 = !{i32 7, !"air.max_constant_buffers", i32 31}
!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31}
!6 = !{i32 7, !"air.max_textures", i32 128}
!7 = !{i32 7, !"air.max_read_write_textures", i32 8}
!8 = !{i32 7, !"air.max_samplers", i32 16}
!9 = !{void (%struct.ResetCommands addrspace(1)*, i32 addrspace(2)*, i32)* @icb_extras_reset, !10, !11}
!10 = !{}
!11 = !{!12, !15, !16}
!12 = !{i32 0, !"air.indirect_buffer", !"air.buffer_size", i32 8, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.struct_type_info", !13, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"ResetCommands", !"air.arg_name", !"encoder"}
!13 = !{i32 0, i32 8, i32 0, !"command_buffer", !"commands", !"air.indirect_argument", !14}
!14 = !{i32 0, !"air.command_buffer", !"air.location_index", i32 0, i32 1, !"air.arg_type_name", !"command_buffer", !"air.arg_name", !"commands"}
!15 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"params"}
!16 = !{i32 2, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"}
!17 = !{<{ <4 x float>, <4 x i32> }> (i32, i32, i32 addrspace(2)*, <4 x float> addrspace(2)*, <2 x float> addrspace(1)*)* @icb_extras_back_vertex, !18, !21}
!18 = !{!19, !20}
!19 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
!20 = !{!"air.vertex_output", !"generated(3idsDv4_j)", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"}
!21 = !{!22, !23, !24, !25, !26}
!22 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"}
!23 = !{i32 1, !"air.instance_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"}
!24 = !{i32 2, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"mark"}
!25 = !{i32 3, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 1, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"frame"}
!26 = !{i32 4, !"air.buffer", !"air.location_index", i32 2, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"float2", !"air.arg_name", !"xy"}
!27 = !{<4 x float> (i32, <2 x float> addrspace(1)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*, float addrspace(2)*)* @icb_extras_wide_vertex, !28, !30}
!28 = !{!29}
!29 = !{!"air.position", !"air.arg_type_name", !"float4"}
!30 = !{!22, !31, !32, !33, !34, !35, !36, !37, !38, !39, !40, !41, !42, !43, !44}
!31 = !{i32 1, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"float2", !"air.arg_name", !"xy"}
!32 = !{i32 2, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 2, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w2"}
!33 = !{i32 3, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 4, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w4"}
!34 = !{i32 4, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 6, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w6"}
!35 = !{i32 5, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 8, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w8"}
!36 = !{i32 6, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 10, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w10"}
!37 = !{i32 7, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 12, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w12"}
!38 = !{i32 8, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 14, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w14"}
!39 = !{i32 9, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 16, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w16"}
!40 = !{i32 10, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 18, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w18"}
!41 = !{i32 11, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 20, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w20"}
!42 = !{i32 12, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 22, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w22"}
!43 = !{i32 13, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 24, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w24"}
!44 = !{i32 14, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 26, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w26"}
!45 = !{<4 x i32> (<4 x float>, <4 x i32>, i32 addrspace(2)*)* @icb_extras_back_fragment, !46, !48}
!46 = !{!47}
!47 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"}
!48 = !{!49, !50, !51}
!49 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"}
!50 = !{i32 1, !"air.fragment_input", !"generated(3idsDv4_j)", !"air.flat", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"}
!51 = !{i32 2, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"tint"}
!52 = !{<4 x i32> ()* @icb_extras_fragment, !46, !10}
!53 = !{!"air.compile.denorms_disable"}
!54 = !{!"air.compile.fast_math_enable"}
!55 = !{!"air.compile.framebuffer_fetch_enable"}
!56 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"}
!57 = !{i32 2, i32 8, i32 0}
!58 = !{!"Metal", i32 4, i32 0, i32 0}
!59 = !{i64 0, i64 8, !60}
!60 = !{!61, !61, i64 0}
!61 = !{!"__metal_command_buffer_t", !62, i64 0}
!62 = !{!"omnipotent char", !63, i64 0}
!63 = !{!"Simple C++ TBAA"}
!64 = !{!65}
!65 = distinct !{!65, !66, !"air-alias-scope-arg(0)"}
!66 = distinct !{!66, !"air-alias-scopes(icb_extras_reset)"}
!67 = !{!68}
!68 = distinct !{!68, !66, !"air-alias-scope-arg(1)"}
!69 = !{!70, !70, i64 0}
!70 = !{!"int", !62, i64 0}
!71 = !{!62, !62, i64 0}
!72 = !{!73}
!73 = distinct !{!73, !74, !"air-alias-scope-arg(4)"}
!74 = distinct !{!74, !"air-alias-scopes(icb_extras_back_vertex)"}
!75 = !{!76, !77}
!76 = distinct !{!76, !74, !"air-alias-scope-arg(2)"}
!77 = distinct !{!77, !74, !"air-alias-scope-arg(3)"}
!78 = !{!77}
!79 = !{!76, !73}
!80 = !{!76}
!81 = !{!77, !73}
!82 = !{!83}
!83 = distinct !{!83, !84, !"air-alias-scope-arg(2)"}
!84 = distinct !{!84, !"air-alias-scopes(icb_extras_back_fragment)"}
!85 = !{!86, !86, i64 0}
!86 = !{!"float", !62, i64 0}
!87 = !{!88}
!88 = distinct !{!88, !89, !"air-alias-scope-arg(2)"}
!89 = distinct !{!89, !"air-alias-scopes(icb_extras_wide_vertex)"}
!90 = !{!91, !92, !93, !94, !95, !96, !97, !98, !99, !100, !101, !102, !103}
!91 = distinct !{!91, !89, !"air-alias-scope-arg(1)"}
!92 = distinct !{!92, !89, !"air-alias-scope-arg(3)"}
!93 = distinct !{!93, !89, !"air-alias-scope-arg(4)"}
!94 = distinct !{!94, !89, !"air-alias-scope-arg(5)"}
!95 = distinct !{!95, !89, !"air-alias-scope-arg(6)"}
!96 = distinct !{!96, !89, !"air-alias-scope-arg(7)"}
!97 = distinct !{!97, !89, !"air-alias-scope-arg(8)"}
!98 = distinct !{!98, !89, !"air-alias-scope-arg(9)"}
!99 = distinct !{!99, !89, !"air-alias-scope-arg(10)"}
!100 = distinct !{!100, !89, !"air-alias-scope-arg(11)"}
!101 = distinct !{!101, !89, !"air-alias-scope-arg(12)"}
!102 = distinct !{!102, !89, !"air-alias-scope-arg(13)"}
!103 = distinct !{!103, !89, !"air-alias-scope-arg(14)"}
!104 = !{!92}
!105 = !{!91, !88, !93, !94, !95, !96, !97, !98, !99, !100, !101, !102, !103}
!106 = !{!93}
!107 = !{!91, !88, !92, !94, !95, !96, !97, !98, !99, !100, !101, !102, !103}
!108 = !{!94}
!109 = !{!91, !88, !92, !93, !95, !96, !97, !98, !99, !100, !101, !102, !103}
!110 = !{!95}
!111 = !{!91, !88, !92, !93, !94, !96, !97, !98, !99, !100, !101, !102, !103}
!112 = !{!96}
!113 = !{!91, !88, !92, !93, !94, !95, !97, !98, !99, !100, !101, !102, !103}
!114 = !{!97}
!115 = !{!91, !88, !92, !93, !94, !95, !96, !98, !99, !100, !101, !102, !103}
!116 = !{!98}
!117 = !{!91, !88, !92, !93, !94, !95, !96, !97, !99, !100, !101, !102, !103}
!118 = !{!99}
!119 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !100, !101, !102, !103}
!120 = !{!100}
!121 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !99, !101, !102, !103}
!122 = !{!101}
!123 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !99, !100, !102, !103}
!124 = !{!102}
!125 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !99, !100, !101, !103}
!126 = !{!103}
!127 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !99, !100, !101, !102}
!128 = !{!91}
!129 = !{!88, !92, !93, !94, !95, !96, !97, !98, !99, !100, !101, !102, !103}
@@ -0,0 +1,256 @@
; Generated by scripts/regen-air-fixtures from icb_indexed_extras.metal (llvm-dis of icb_indexed_extras.air). Do not edit.
; ModuleID = '<stdin>'
source_filename = "-"
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32"
target triple = "air64_v28-apple-macosx26.0.0"
%struct.ResetCommands = type { %"struct.metal::command_buffer" }
%"struct.metal::command_buffer" = type { ptr addrspace(1) }
; Function Attrs: mustprogress nounwind willreturn
define void @icb_extras_reset(ptr addrspace(1) noundef readonly align 8 captures(none) dereferenceable(8) "air-buffer-no-alias" %0, ptr addrspace(2) noundef readonly captures(none) "air-buffer-no-alias" %1, i32 noundef %2) local_unnamed_addr #0 {
%4 = getelementptr inbounds %struct.ResetCommands, ptr addrspace(1) %0, i64 0, i32 0, i32 0
%5 = load ptr addrspace(1), ptr addrspace(1) %4, align 8, !tbaa.struct !59, !alias.scope !64, !noalias !67
%6 = load i32, ptr addrspace(2) %1, align 4, !tbaa !69, !alias.scope !67, !noalias !64
%7 = add i32 %6, %2
tail call void @air.reset_render_command(ptr addrspace(1) captures(none) %5, i32 %7) #6
ret void
}
; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(argmem: read)
define <{ <4 x float>, <4 x i32> }> @icb_extras_back_vertex(i32 noundef %0, i32 noundef %1, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %2, ptr addrspace(2) noundef readonly align 16 captures(none) dereferenceable(16) "air-buffer-no-alias" %3, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %4) local_unnamed_addr #1 {
%6 = add nsw i32 %0, -4
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds <2 x float>, ptr addrspace(1) %4, i64 %7
%9 = load <2 x float>, ptr addrspace(1) %8, align 8, !tbaa !71, !alias.scope !72, !noalias !75
%10 = tail call fast float @air.convert.f.f32.u.i32(i32 %1) #7
%11 = load <4 x float>, ptr addrspace(2) %3, align 16, !alias.scope !78, !noalias !79
%12 = extractelement <4 x float> %11, i64 2
%13 = fmul fast float %12, %10
%14 = insertelement <2 x float> <float 0.000000e+00, float poison>, float %13, i64 1
%15 = fadd fast <2 x float> %14, %9
%16 = extractelement <2 x float> %15, i64 0
%17 = fmul fast float %16, 2.000000e+00
%18 = extractelement <4 x float> %11, i64 0
%19 = fdiv fast float %17, %18
%20 = fadd fast float %19, -1.000000e+00
%21 = extractelement <2 x float> %15, i64 1
%22 = fmul fast float %21, 2.000000e+00
%23 = extractelement <4 x float> %11, i64 1
%24 = fdiv fast float %22, %23
%25 = fsub fast float 1.000000e+00, %24
%26 = insertelement <4 x float> <float poison, float poison, float 0.000000e+00, float 1.000000e+00>, float %20, i64 0
%27 = insertelement <4 x float> %26, float %25, i64 1
%28 = load i32, ptr addrspace(2) %2, align 4, !tbaa !69, !alias.scope !80, !noalias !81
%29 = insertelement <4 x i32> <i32 poison, i32 poison, i32 poison, i32 0>, i32 %28, i64 0
%30 = insertelement <4 x i32> %29, i32 %0, i64 1
%31 = insertelement <4 x i32> %30, i32 %1, i64 2
%32 = insertvalue <{ <4 x float>, <4 x i32> }> undef, <4 x float> %27, 0
%33 = insertvalue <{ <4 x float>, <4 x i32> }> %32, <4 x i32> %31, 1
ret <{ <4 x float>, <4 x i32> }> %33
}
; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare float @air.convert.f.f32.u.i32(i32) local_unnamed_addr #2
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
define <4 x i32> @icb_extras_back_fragment(<4 x float> %0, <4 x i32> %1, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %2) local_unnamed_addr #3 {
%4 = load i32, ptr addrspace(2) %2, align 4, !tbaa !69, !alias.scope !82
%5 = insertelement <4 x i32> %1, i32 %4, i64 3
ret <4 x i32> %5
}
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
define <4 x float> @icb_extras_wide_vertex(i32 noundef %0, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %1, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %2, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %3, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %4, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %5, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %6, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %7, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %8, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %9, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %10, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %11, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %12, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %13, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %14) local_unnamed_addr #4 {
%16 = load float, ptr addrspace(2) %2, align 4, !tbaa !85, !alias.scope !87, !noalias !90
%17 = load float, ptr addrspace(2) %3, align 4, !tbaa !85, !alias.scope !104, !noalias !105
%18 = fadd fast float %17, %16
%19 = load float, ptr addrspace(2) %4, align 4, !tbaa !85, !alias.scope !106, !noalias !107
%20 = fadd fast float %18, %19
%21 = load float, ptr addrspace(2) %5, align 4, !tbaa !85, !alias.scope !108, !noalias !109
%22 = fadd fast float %20, %21
%23 = load float, ptr addrspace(2) %6, align 4, !tbaa !85, !alias.scope !110, !noalias !111
%24 = fadd fast float %22, %23
%25 = load float, ptr addrspace(2) %7, align 4, !tbaa !85, !alias.scope !112, !noalias !113
%26 = fadd fast float %24, %25
%27 = load float, ptr addrspace(2) %8, align 4, !tbaa !85, !alias.scope !114, !noalias !115
%28 = fadd fast float %26, %27
%29 = load float, ptr addrspace(2) %9, align 4, !tbaa !85, !alias.scope !116, !noalias !117
%30 = fadd fast float %28, %29
%31 = load float, ptr addrspace(2) %10, align 4, !tbaa !85, !alias.scope !118, !noalias !119
%32 = fadd fast float %30, %31
%33 = load float, ptr addrspace(2) %11, align 4, !tbaa !85, !alias.scope !120, !noalias !121
%34 = fadd fast float %32, %33
%35 = load float, ptr addrspace(2) %12, align 4, !tbaa !85, !alias.scope !122, !noalias !123
%36 = fadd fast float %34, %35
%37 = load float, ptr addrspace(2) %13, align 4, !tbaa !85, !alias.scope !124, !noalias !125
%38 = fadd fast float %36, %37
%39 = load float, ptr addrspace(2) %14, align 4, !tbaa !85, !alias.scope !126, !noalias !127
%40 = fadd fast float %38, %39
%41 = zext i32 %0 to i64
%42 = getelementptr inbounds <2 x float>, ptr addrspace(1) %1, i64 %41
%43 = load <2 x float>, ptr addrspace(1) %42, align 8, !tbaa !71, !alias.scope !128, !noalias !129
%44 = insertelement <2 x float> undef, float %40, i64 0
%45 = shufflevector <2 x float> %44, <2 x float> poison, <2 x i32> zeroinitializer
%46 = fadd fast <2 x float> %45, %43
%47 = shufflevector <2 x float> %46, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
%48 = shufflevector <4 x float> %47, <4 x float> <float poison, float poison, float 0.000000e+00, float 1.000000e+00>, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
ret <4 x float> %48
}
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
define <4 x i32> @icb_extras_fragment() local_unnamed_addr #3 {
ret <4 x i32> splat (i32 1)
}
; Function Attrs: mustprogress nounwind willreturn
declare void @air.reset_render_command(ptr addrspace(1) captures(none), i32) local_unnamed_addr #5
attributes #0 = { mustprogress nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #1 = { mustprogress nofree nosync nounwind willreturn memory(argmem: read) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #2 = { mustprogress nofree nosync nounwind willreturn memory(none) }
attributes #3 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #4 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" }
attributes #5 = { mustprogress nounwind willreturn }
attributes #6 = { nounwind willreturn }
attributes #7 = { nounwind willreturn memory(none) }
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
!air.kernel = !{!9}
!air.vertex = !{!17, !27}
!air.fragment = !{!45, !52}
!air.compile_options = !{!53, !54, !55}
!llvm.ident = !{!56}
!air.version = !{!57}
!air.language_version = !{!58}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 7, !"frame-pointer", i32 2}
!3 = !{i32 7, !"air.max_device_buffers", i32 31}
!4 = !{i32 7, !"air.max_constant_buffers", i32 31}
!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31}
!6 = !{i32 7, !"air.max_textures", i32 128}
!7 = !{i32 7, !"air.max_read_write_textures", i32 8}
!8 = !{i32 7, !"air.max_samplers", i32 16}
!9 = !{ptr @icb_extras_reset, !10, !11}
!10 = !{}
!11 = !{!12, !15, !16}
!12 = !{i32 0, !"air.indirect_buffer", !"air.buffer_size", i32 8, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.struct_type_info", !13, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"ResetCommands", !"air.arg_name", !"encoder"}
!13 = !{i32 0, i32 8, i32 0, !"command_buffer", !"commands", !"air.indirect_argument", !14}
!14 = !{i32 0, !"air.command_buffer", !"air.location_index", i32 0, i32 1, !"air.arg_type_name", !"command_buffer", !"air.arg_name", !"commands"}
!15 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"params"}
!16 = !{i32 2, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"}
!17 = !{ptr @icb_extras_back_vertex, !18, !21}
!18 = !{!19, !20}
!19 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"}
!20 = !{!"air.vertex_output", !"generated(3idsDv4_j)", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"}
!21 = !{!22, !23, !24, !25, !26}
!22 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"}
!23 = !{i32 1, !"air.instance_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"}
!24 = !{i32 2, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"mark"}
!25 = !{i32 3, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 1, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"frame"}
!26 = !{i32 4, !"air.buffer", !"air.location_index", i32 2, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"float2", !"air.arg_name", !"xy"}
!27 = !{ptr @icb_extras_wide_vertex, !28, !30}
!28 = !{!29}
!29 = !{!"air.position", !"air.arg_type_name", !"float4"}
!30 = !{!22, !31, !32, !33, !34, !35, !36, !37, !38, !39, !40, !41, !42, !43, !44}
!31 = !{i32 1, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"float2", !"air.arg_name", !"xy"}
!32 = !{i32 2, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 2, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w2"}
!33 = !{i32 3, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 4, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w4"}
!34 = !{i32 4, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 6, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w6"}
!35 = !{i32 5, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 8, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w8"}
!36 = !{i32 6, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 10, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w10"}
!37 = !{i32 7, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 12, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w12"}
!38 = !{i32 8, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 14, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w14"}
!39 = !{i32 9, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 16, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w16"}
!40 = !{i32 10, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 18, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w18"}
!41 = !{i32 11, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 20, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w20"}
!42 = !{i32 12, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 22, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w22"}
!43 = !{i32 13, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 24, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w24"}
!44 = !{i32 14, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 26, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"float", !"air.arg_name", !"w26"}
!45 = !{ptr @icb_extras_back_fragment, !46, !48}
!46 = !{!47}
!47 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"}
!48 = !{!49, !50, !51}
!49 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"}
!50 = !{i32 1, !"air.fragment_input", !"generated(3idsDv4_j)", !"air.flat", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"}
!51 = !{i32 2, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"tint"}
!52 = !{ptr @icb_extras_fragment, !46, !10}
!53 = !{!"air.compile.denorms_disable"}
!54 = !{!"air.compile.fast_math_enable"}
!55 = !{!"air.compile.framebuffer_fetch_enable"}
!56 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"}
!57 = !{i32 2, i32 8, i32 0}
!58 = !{!"Metal", i32 4, i32 0, i32 0}
!59 = !{i64 0, i64 8, !60}
!60 = !{!61, !61, i64 0}
!61 = !{!"__metal_command_buffer_t", !62, i64 0}
!62 = !{!"omnipotent char", !63, i64 0}
!63 = !{!"Simple C++ TBAA"}
!64 = !{!65}
!65 = distinct !{!65, !66, !"air-alias-scope-arg(0)"}
!66 = distinct !{!66, !"air-alias-scopes(icb_extras_reset)"}
!67 = !{!68}
!68 = distinct !{!68, !66, !"air-alias-scope-arg(1)"}
!69 = !{!70, !70, i64 0}
!70 = !{!"int", !62, i64 0}
!71 = !{!62, !62, i64 0}
!72 = !{!73}
!73 = distinct !{!73, !74, !"air-alias-scope-arg(4)"}
!74 = distinct !{!74, !"air-alias-scopes(icb_extras_back_vertex)"}
!75 = !{!76, !77}
!76 = distinct !{!76, !74, !"air-alias-scope-arg(2)"}
!77 = distinct !{!77, !74, !"air-alias-scope-arg(3)"}
!78 = !{!77}
!79 = !{!76, !73}
!80 = !{!76}
!81 = !{!77, !73}
!82 = !{!83}
!83 = distinct !{!83, !84, !"air-alias-scope-arg(2)"}
!84 = distinct !{!84, !"air-alias-scopes(icb_extras_back_fragment)"}
!85 = !{!86, !86, i64 0}
!86 = !{!"float", !62, i64 0}
!87 = !{!88}
!88 = distinct !{!88, !89, !"air-alias-scope-arg(2)"}
!89 = distinct !{!89, !"air-alias-scopes(icb_extras_wide_vertex)"}
!90 = !{!91, !92, !93, !94, !95, !96, !97, !98, !99, !100, !101, !102, !103}
!91 = distinct !{!91, !89, !"air-alias-scope-arg(1)"}
!92 = distinct !{!92, !89, !"air-alias-scope-arg(3)"}
!93 = distinct !{!93, !89, !"air-alias-scope-arg(4)"}
!94 = distinct !{!94, !89, !"air-alias-scope-arg(5)"}
!95 = distinct !{!95, !89, !"air-alias-scope-arg(6)"}
!96 = distinct !{!96, !89, !"air-alias-scope-arg(7)"}
!97 = distinct !{!97, !89, !"air-alias-scope-arg(8)"}
!98 = distinct !{!98, !89, !"air-alias-scope-arg(9)"}
!99 = distinct !{!99, !89, !"air-alias-scope-arg(10)"}
!100 = distinct !{!100, !89, !"air-alias-scope-arg(11)"}
!101 = distinct !{!101, !89, !"air-alias-scope-arg(12)"}
!102 = distinct !{!102, !89, !"air-alias-scope-arg(13)"}
!103 = distinct !{!103, !89, !"air-alias-scope-arg(14)"}
!104 = !{!92}
!105 = !{!91, !88, !93, !94, !95, !96, !97, !98, !99, !100, !101, !102, !103}
!106 = !{!93}
!107 = !{!91, !88, !92, !94, !95, !96, !97, !98, !99, !100, !101, !102, !103}
!108 = !{!94}
!109 = !{!91, !88, !92, !93, !95, !96, !97, !98, !99, !100, !101, !102, !103}
!110 = !{!95}
!111 = !{!91, !88, !92, !93, !94, !96, !97, !98, !99, !100, !101, !102, !103}
!112 = !{!96}
!113 = !{!91, !88, !92, !93, !94, !95, !97, !98, !99, !100, !101, !102, !103}
!114 = !{!97}
!115 = !{!91, !88, !92, !93, !94, !95, !96, !98, !99, !100, !101, !102, !103}
!116 = !{!98}
!117 = !{!91, !88, !92, !93, !94, !95, !96, !97, !99, !100, !101, !102, !103}
!118 = !{!99}
!119 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !100, !101, !102, !103}
!120 = !{!100}
!121 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !99, !101, !102, !103}
!122 = !{!101}
!123 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !99, !100, !102, !103}
!124 = !{!102}
!125 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !99, !100, !101, !103}
!126 = !{!103}
!127 = !{!91, !88, !92, !93, !94, !95, !96, !97, !98, !99, !100, !101, !102}
!128 = !{!91}
!129 = !{!88, !92, !93, !94, !95, !96, !97, !98, !99, !100, !101, !102, !103}
@@ -0,0 +1,70 @@
// Owned fixture: what an indirect command buffer of indexed triangle draws (`icb_merged_indexed`)
// meets beside its encoding.
// - Thread `tid` of `icb_extras_reset` resets render command `params[0] + tid` of
// `encoder.commands`, as a guest's initialization kernels do; a reset command draws nothing.
// - `icb_extras_back_vertex` is `icb_merged_indexed`'s `icb_indexed_vertex` reading its position
// four elements before the vertex's own, `xy[int(vid) - 4]`: a command whose buffer 2 starts
// inside a buffer reads the bytes before its address. `icb_extras_back_fragment` returns what it
// carries, as `icb_indexed_fragment` does.
// - `icb_extras_wide_vertex` reads fourteen vertex buffers, at the even indices 0 to 26: vertex
// `vid` lies at `xy[vid]` of buffer 0 (clip space) moved by the sum of the thirteen others'
// words, which a test binds as zeros. A command binds each of the fourteen slots apart from the
// next, so each is a run of its own. `icb_extras_fragment` returns 1 in every channel.
// Written for this repository; no third-party source.
// Loop-free.
#include <metal_stdlib>
using namespace metal;
struct ResetCommands {
command_buffer commands;
};
struct ExtrasOut {
float4 position [[position]];
uint4 ids [[flat]];
};
kernel void icb_extras_reset(device const ResetCommands &encoder [[buffer(0)]],
constant uint *params [[buffer(1)]],
uint tid [[thread_position_in_grid]]) {
render_command command(encoder.commands, params[0] + tid);
command.reset();
}
vertex ExtrasOut icb_extras_back_vertex(uint vid [[vertex_id]], uint iid [[instance_id]],
constant uint &mark [[buffer(0)]],
constant float4 &frame [[buffer(1)]],
device const float2 *xy [[buffer(2)]]) {
float2 at = xy[int(vid) - 4] + float2(0.0, float(iid) * frame.z);
ExtrasOut out;
out.position = float4(2.0 * at.x / frame.x - 1.0, 1.0 - 2.0 * at.y / frame.y, 0.0, 1.0);
out.ids = uint4(mark, vid, iid, 0);
return out;
}
fragment uint4 icb_extras_back_fragment(ExtrasOut in [[stage_in]], constant uint &tint [[buffer(0)]]) {
return uint4(in.ids.x, in.ids.y, in.ids.z, tint);
}
vertex float4 icb_extras_wide_vertex(uint vid [[vertex_id]],
device const float2 *xy [[buffer(0)]],
constant float &w2 [[buffer(2)]],
constant float &w4 [[buffer(4)]],
constant float &w6 [[buffer(6)]],
constant float &w8 [[buffer(8)]],
constant float &w10 [[buffer(10)]],
constant float &w12 [[buffer(12)]],
constant float &w14 [[buffer(14)]],
constant float &w16 [[buffer(16)]],
constant float &w18 [[buffer(18)]],
constant float &w20 [[buffer(20)]],
constant float &w22 [[buffer(22)]],
constant float &w24 [[buffer(24)]],
constant float &w26 [[buffer(26)]]) {
float moved = w2 + w4 + w6 + w8 + w10 + w12 + w14 + w16 + w18 + w20 + w22 + w24 + w26;
return float4(xy[vid] + float2(moved, moved), 0.0, 1.0);
}
fragment uint4 icb_extras_fragment() {
return uint4(1);
}
+3
View File
@@ -907,6 +907,9 @@ codec_enum! {
ZeroAddress,
FetchedColor { color, texels },
TailWord,
IndirectRange,
IndirectSequence,
IndirectBase,
}
Symbol { Binding(f0), DescriptorSet(f0), Location(f0), Component(f0), SpecId(f0) }
}
+2 -2
View File
@@ -61,7 +61,7 @@ mod tests;
/// unchanged version, and its bless records the version. Independent of the crate's version and of
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
/// history.
pub const SEMANTICS_VERSION: u32 = 2251;
pub const SEMANTICS_VERSION: u32 = 2252;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
@@ -71,7 +71,7 @@ pub const SEMANTICS_VERSION: u32 = 2251;
/// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag
/// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that
/// bumps it says what changed; this comment keeps no history.
pub const ARTIFACT_FORMAT_VERSION: u32 = 585;
pub const ARTIFACT_FORMAT_VERSION: u32 = 586;
/// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding
/// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle
@@ -699,6 +699,7 @@ pub fn emit(
AccessStrategy::Cell(c) => super::cell::emit(cx, fb, vid, c),
AccessStrategy::Imageblock(i) => super::imageblock::emit(cx, fb, vid, i),
AccessStrategy::Encode(e) => super::encode::emit(cx, fb, vid, e),
AccessStrategy::Commands(c) => super::icb::emit(cx, fb, c),
AccessStrategy::FunctionTable(t) => super::function_table::emit(cx, fb, vid, t),
AccessStrategy::AbsentRead(a) => super::absent::emit(cx, fb, vid, a),
}
+441
View File
@@ -0,0 +1,441 @@
//! GPU-encoded indexed draws under the identity domains: a function's `render_command` buffer
//! setters, indexed draw and reset write the records of an indirect command buffer
//! (`pipeline::IndirectDrawLayout`) through its `gpuResourceID`, the records' device address,
//! which an argument buffer's `command_buffer` member holds (its handle load is `encode`'s object
//! word, a `u64`).
//!
//! Each operation reads the header's capacity, slot counts and stride, and writes only where the
//! command's index is below the capacity and, for a buffer setter, the slot below its stage's
//! count; any other write, which Metal leaves undefined, writes nothing. Every write is a plain
//! `PhysicalStorageBuffer` store at `address + HEADER_BYTES + index * stride + field`:
//!
//! - `set_vertex_buffer` and `set_fragment_buffer` write the buffer's Metal address less 2^31 (the
//! word an execution pushes as the slot's `SlotGuestBase`) at the slot's word. The attribute
//! stride form is lowered only for the constant all ones, the pipeline's own stride, as MSL's
//! plain setter spells it.
//! - `draw_indexed_primitives` of the constant triangle type writes the index token's data (the
//! indices' address, `count` indices' bytes and the index type of the overload) and
//! `VkDrawIndexedIndirectCommand` (`count`, the instances, first index 0, the base vertex and the
//! base instance). Another primitive type is refused: an execution draws one topology.
//! - `reset` writes the index token at the header's reset index address with no bytes and a draw
//! of nothing; the command's slot words stay.
//!
//! Every other indirect-command operation (compute commands, plain, patch and mesh draws,
//! pipeline and render state setters, barriers, copies) is
//! `Unsupported{GpuEncodedIndirectCommands, NotImplemented}`. A vertex or fragment function on a
//! device without its stage's store feature, and a device without device addresses, refuse every
//! operation, naming what they lack.
use std::borrow::Cow;
use crate::air::intrinsics::{AirIntrinsic, CommandStage, IndirectCommand};
use crate::air::ir::{Callee, Inst, InstKind, Value, ValueId};
use crate::budget::Meter;
use crate::device::profile::BufferAccess;
use crate::error::{
Capability, DiagName, Error, Feature, InternalError, InternalKind, Unsupported,
};
use crate::lower::arith::LoweredConst;
use crate::lower::emit::EmitCx;
use crate::lower::select::SelectCx;
use crate::memory::leaf::k32;
use crate::memory::provenance::Repr;
use crate::memory::roots::k64;
use crate::pipeline::IndirectDrawLayout as Records;
use crate::spirv::builder::constructs::{ArmEnd, ArmFn};
use crate::spirv::builder::FunctionBuilder;
use crate::spirv::error::BResult;
use crate::spirv::ids::Value as SValue;
use crate::spirv::ir::{BinOp, ConvOp, MemAccess, Type as SType};
use super::{buffer_roots, dynamic, operand, pointer, refuse, Target, SLOT_ADDRESS_BIAS};
/// One operation's writes into its command.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Command {
/// The command buffer's word: its records' device address.
pub records: ValueId,
/// The command's index (`i32`, read as unsigned).
pub index: ValueId,
pub write: Write,
}
/// What an operation writes.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Write {
/// A buffer's address at `slot` (`i32`) of the vertex slots, or of the fragment slots.
Buffer {
fragment: bool,
address: Address,
slot: ValueId,
},
/// An indexed draw of triangles: `count` indices of 16 or 32 bits (`wide`) at `indices`.
Draw {
count: ValueId,
indices: Address,
wide: bool,
instances: ValueId,
base_vertex: ValueId,
base_instance: ValueId,
},
/// A reset.
Reset,
}
/// A buffer pointer's Metal address.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Address {
/// The null pointer constant: 0.
Null,
/// A static-root fat pointer: its slot's address plus its displacement
/// (`dynamic::static_guest_address`).
Static { ptr: ValueId, targets: Vec<Target> },
/// A wide pointer: the address it carries (`dynamic::guest_address`).
Wide(ValueId),
}
/// SPIR-V words of an operation: the header's loads, the checks, its stores and the construct.
const WORDS: u32 = 400;
impl Command {
/// The census name (`access.commands.<op>`).
pub fn name(&self) -> Cow<'static, str> {
match self.write {
Write::Buffer {
fragment: false, ..
} => "access.commands.vertex_buffer".into(),
Write::Buffer { fragment: true, .. } => "access.commands.fragment_buffer".into(),
Write::Draw { .. } => "access.commands.draw_indexed".into(),
Write::Reset => "access.commands.reset".into(),
}
}
/// An upper estimate of the SPIR-V words one use emits.
pub fn words(&self) -> u32 {
WORDS
}
}
/// The integer bits of constant `v`, zero-extended from its width; `None` for any other value.
fn constant_bits(cx: &SelectCx<'_>, v: Value) -> Option<u64> {
match cx.constant(v)? {
LoweredConst::Scalar { bits, .. } => Some(bits),
_ => None,
}
}
/// A non-pointer operand: an instruction or parameter value, or a constant the arith family
/// materializes.
fn value(cx: &SelectCx<'_>, v: Value) -> Result<ValueId, Error> {
if matches!(v, Value::Const(_)) && cx.constant(v).is_none() {
return Err(refuse());
}
cx.values
.id(v)
.ok_or_else(|| cx.invariant("an encoder operand out of the value range"))
}
/// The Metal address of buffer pointer `v`, planned.
fn address(cx: &mut SelectCx<'_>, v: Value, m: &mut Meter) -> Result<Address, Error> {
if pointer::null_constant(cx, v) {
return Ok(Address::Null);
}
match cx.memory.repr(v) {
Some(Repr::BufPtr { wide: true, .. }) => Ok(Address::Wide(dynamic::plan_entry(cx, v)?)),
Some(Repr::BufPtr { wide: false, .. }) => {
let (targets, _, in_blob) = buffer_roots(cx, v, m)?;
// A pointer into the constant blob has no Metal address.
if in_blob {
return Err(refuse());
}
dynamic::plan_static_guest(cx, &targets, Feature::GpuEncodedIndirectCommands)?;
Ok(Address::Static {
ptr: operand(cx, v)?,
targets,
})
}
_ => Err(refuse()),
}
}
/// The refusal of every operation on a device that cannot write the records: one without device
/// addresses and `shaderInt64`, or a vertex or fragment function's without its stage's store
/// feature.
fn needs(cx: &SelectCx<'_>) -> Result<(), Error> {
let f = cx.profile.fields();
if f.buffer_access != BufferAccess::Addressed || !f.leaf.int64 {
return Err(Unsupported::needs_any_of(
Feature::GpuEncodedIndirectCommands,
vec![cx.profile.addressed_needs()],
)
.into());
}
let enabled = &f.enabled.features;
if let Some(feature) = dynamic::stage_stores(cx.stage).find(|f| !enabled.contains(f)) {
return Err(Unsupported::needs(
Feature::GpuEncodedIndirectCommands,
Capability::Feature(feature),
)
.into());
}
Ok(())
}
/// Select the strategy of `inst` under the identity domains: an indirect-command operation's
/// writes, or its refusal; `None` for any other instruction, or on another profile.
pub fn select(cx: &mut SelectCx<'_>, inst: &Inst, m: &mut Meter) -> Result<Option<Command>, Error> {
if !super::identity(cx.profile) {
return Ok(None);
}
let InstKind::Call(call) = &inst.kind else {
return Ok(None);
};
let Callee::Air {
op: AirIntrinsic::IndirectCommand(op),
..
} = call.callee
else {
return Ok(None);
};
let args = &call.args;
let arg = |i: usize| -> Result<Value, Error> {
args.get(i).copied().ok_or_else(|| {
Error::Internal(InternalError::new(
InternalKind::Invariant,
"an encoder operation without its operands",
))
})
};
// The command must be an object word: any other command handle is its family's refusal.
let records = arg(0)?;
if !matches!(records, Value::Inst(i) if cx.families.access.objects.contains(&i)) {
return Err(Unsupported::not_implemented(Feature::ArgumentBufferObjects).into());
}
let unbuilt =
|| -> Error { Unsupported::not_implemented(Feature::GpuEncodedIndirectCommands).into() };
let write = match op {
IndirectCommand::SetBuffer { stage, strided, .. }
if matches!(stage, CommandStage::Vertex | CommandStage::Fragment) =>
{
// The attribute stride form, lowered for the pipeline's own stride alone.
if strided && constant_bits(cx, arg(3)?) != Some(u64::MAX) {
return Err(unbuilt());
}
needs(cx)?;
Write::Buffer {
fragment: stage == CommandStage::Fragment,
address: address(cx, arg(2)?, m)?,
slot: value(cx, arg(if strided { 4 } else { 3 })?)?,
}
}
IndirectCommand::DrawIndexedPrimitives { wide, .. } => {
// `MTLPrimitiveTypeTriangle`: an execution draws a triangle list.
if constant_bits(cx, arg(2)?) != Some(3) {
return Err(
Unsupported::not_implemented(Feature::GpuEncodedIndirectCommands)
.naming(DiagName::new(
"a draw of another primitive type than triangles",
))
.into(),
);
}
needs(cx)?;
Write::Draw {
count: value(cx, arg(3)?)?,
indices: address(cx, arg(4)?, m)?,
wide,
instances: value(cx, arg(5)?)?,
base_vertex: value(cx, arg(6)?)?,
base_instance: value(cx, arg(7)?)?,
}
}
IndirectCommand::ResetRenderCommand => {
needs(cx)?;
Write::Reset
}
_ => return Err(unbuilt()),
};
Ok(Some(Command {
records: operand(cx, records)?,
index: value(cx, arg(1)?)?,
write,
}))
}
// ---- Emission ----
/// `x` (a `u32`) as a `u64`.
fn wide(fb: &mut FunctionBuilder<'_>, x: SValue) -> BResult<SValue> {
let u64_ = fb.module().ty(SType::Int {
width: 64,
signed: false,
})?;
fb.convert(ConvOp::UConvert, x, u64_)
}
/// The `u32` of the header at `records` (a `u64`) plus `at`.
fn header(fb: &mut FunctionBuilder<'_>, records: SValue, at: u32) -> BResult<SValue> {
let at = k64(fb, u64::from(at))?;
let p = fb.binary(BinOp::IAdd, records, at)?;
let u32_ = fb.module().ty(SType::Int {
width: 32,
signed: false,
})?;
let place = fb.device_place_read_only(p, u32_)?;
fb.load(
place,
MemAccess {
aligned: Some(4),
..MemAccess::default()
},
)
}
/// The Metal address of `a`, a `u64`.
fn emit_address(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, a: &Address) -> BResult<SValue> {
match a {
Address::Null => k64(fb, 0),
Address::Wide(p) => {
let p = cx.operand(fb, *p)?;
dynamic::guest_address(cx, fb, p)
}
Address::Static { ptr, targets } => {
let fat = cx.operand(fb, *ptr)?;
dynamic::static_guest_address(cx, fb, targets, fat)
}
}
}
/// Emit command `c`'s writes, where its index is below the capacity (and its slot below its
/// stage's count).
pub fn emit(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, c: &Command) -> BResult<()> {
let records = cx.operand(fb, c.records)?;
let capacity = header(fb, records, Records::CAPACITY_AT)?;
let vertex_slots = header(fb, records, Records::VERTEX_SLOTS_AT)?;
let fragment_slots = header(fb, records, Records::FRAGMENT_SLOTS_AT)?;
let stride = header(fb, records, Records::STRIDE_AT)?;
let index = cx.operand(fb, c.index)?;
let mut valid = fb.binary(BinOp::ULessThan, index, capacity)?;
// The command's first byte: the records past the header, `index` strides on.
let i = wide(fb, index)?;
let s = wide(fb, stride)?;
let scaled = fb.binary(BinOp::IMul, i, s)?;
let first = k64(fb, u64::from(Records::HEADER_BYTES))?;
let past = fb.binary(BinOp::IAdd, records, first)?;
let command = fb.binary(BinOp::IAdd, past, scaled)?;
let eight = k32(fb, Records::SLOT_BYTES)?;
let slots = fb.binary(BinOp::IAdd, vertex_slots, fragment_slots)?;
let index_at = fb.binary(BinOp::IMul, slots, eight)?;
let index_at = wide(fb, index_at)?;
let token = fb.binary(BinOp::IAdd, command, index_at)?;
// Each store: its address (a `u64`), its value, and its bytes (4 or 8).
let mut stores: Vec<(SValue, SValue, u8)> = Vec::new();
match &c.write {
Write::Buffer {
fragment,
address,
slot,
} => {
let slot = cx.operand(fb, *slot)?;
let (count, first) = match fragment {
false => (vertex_slots, None),
true => (fragment_slots, Some(vertex_slots)),
};
let bound = fb.binary(BinOp::ULessThan, slot, count)?;
valid = fb.binary(BinOp::LogicalAnd, valid, bound)?;
let at = match first {
None => slot,
Some(v) => fb.binary(BinOp::IAdd, v, slot)?,
};
let at = fb.binary(BinOp::IMul, at, eight)?;
let at = wide(fb, at)?;
let to = fb.binary(BinOp::IAdd, command, at)?;
let address = emit_address(cx, fb, address)?;
let bias = k64(fb, SLOT_ADDRESS_BIAS)?;
let word = fb.binary(BinOp::ISub, address, bias)?;
stores.push((to, word, 8));
}
Write::Draw {
count,
indices,
wide: wide_indices,
instances,
base_vertex,
base_instance,
} => {
let count = cx.operand(fb, *count)?;
let address = emit_address(cx, fb, indices)?;
stores.push((token, address, 8));
let (unit, ty) = match wide_indices {
true => (4, Records::INDEX_UINT32),
false => (2, Records::INDEX_UINT16),
};
let unit = k32(fb, unit)?;
let bytes = fb.binary(BinOp::IMul, count, unit)?;
let ty = k32(fb, ty)?;
let zero = k32(fb, 0)?;
let draw = [
count,
cx.operand(fb, *instances)?,
zero,
cx.operand(fb, *base_vertex)?,
cx.operand(fb, *base_instance)?,
];
let words = [(8, bytes), (12, ty)]
.into_iter()
.chain((draw.into_iter().enumerate()).map(|(word, x)| (20 + 4 * word as u32, x)));
for (at, x) in words {
let at = k64(fb, u64::from(at))?;
let to = fb.binary(BinOp::IAdd, token, at)?;
stores.push((to, x, 4));
}
}
Write::Reset => {
let at = k64(fb, u64::from(Records::RESET_INDEX_AT))?;
let at = fb.binary(BinOp::IAdd, records, at)?;
let u64_ = fb.module().ty(SType::Int {
width: 64,
signed: false,
})?;
let place = fb.device_place_read_only(at, u64_)?;
let reset = fb.load(
place,
MemAccess {
aligned: Some(8),
..MemAccess::default()
},
)?;
stores.push((token, reset, 8));
let ty = k32(fb, Records::INDEX_UINT32)?;
let zero = k32(fb, 0)?;
let words = [(8, zero), (12, ty)]
.into_iter()
.chain((0..5u32).map(|word| (20 + 4 * word, zero)));
for (at, x) in words {
let at = k64(fb, u64::from(at))?;
let to = fb.binary(BinOp::IAdd, token, at)?;
stores.push((to, x, 4));
}
}
}
let write: ArmFn<'_, ()> = Box::new(move |fb, _| {
for (to, x, bytes) in stores {
let ty = fb.module().ty(SType::Int {
width: 8 * bytes,
signed: false,
})?;
let place = fb.device_place(to, ty)?;
fb.store(
place,
x,
MemAccess {
aligned: Some(u32::from(bytes)),
..MemAccess::default()
},
)?;
}
Ok(ArmEnd::FallThrough(Vec::new()))
});
fb.if_(&mut (), valid, write, None)?;
Ok(())
}
@@ -104,6 +104,7 @@ mod emit;
pub mod encode;
pub mod function_table;
pub mod handle;
pub mod icb;
pub mod imageblock;
pub mod index;
pub mod local;
@@ -190,6 +191,9 @@ pub enum AccessStrategy {
Imageblock(imageblock::ImageblockStrategy),
/// An indirect-command object's word, or an encoder operation's record writes.
Encode(encode::EncodeStrategy),
/// An indirect-command operation's writes into its command's records under the identity
/// domains.
Commands(icb::Command),
/// A word of a visible-function table read by its resource id.
FunctionTable(function_table::TableWord),
/// A read of an argument the function constants removed.
@@ -537,6 +541,7 @@ impl FamilyStrategy for AccessStrategy {
AccessStrategy::Cell(c) => c.name().into(),
AccessStrategy::Imageblock(i) => i.name().into(),
AccessStrategy::Encode(e) => e.name(slots),
AccessStrategy::Commands(c) => c.name(),
AccessStrategy::FunctionTable(t) => t.name(),
AccessStrategy::AbsentRead(a) => a.name().into(),
}
@@ -561,6 +566,7 @@ impl FamilyStrategy for AccessStrategy {
AccessStrategy::Cell(c) => c.words(),
AccessStrategy::Imageblock(i) => i.words(),
AccessStrategy::Encode(e) => e.words(),
AccessStrategy::Commands(c) => c.words(),
AccessStrategy::FunctionTable(t) => t.words(),
AccessStrategy::AbsentRead(a) => a.words(),
}
@@ -2487,6 +2493,11 @@ pub fn select(
if let Some(s) = imageblock::select(cx, inst)? {
return Ok(AccessStrategy::Imageblock(s));
}
// Under the identity domains an indirect-command operation is `icb`'s; its object word's
// handle load stays `encode`'s.
if let Some(c) = icb::select(cx, inst, m)? {
return Ok(AccessStrategy::Commands(c));
}
if let Some(s) = encode::select(cx, at, inst, m)? {
return Ok(AccessStrategy::Encode(s));
}
+4 -2
View File
@@ -197,8 +197,10 @@ pub const fn shape(f: PushField) -> FieldShape {
// The bytes of a slot's buffer before its bind offset, and its length: each at most 2 GiB
// under the identity domains.
PushField::SlotBounds(_) => FieldShape::UVec2,
// The identity domains' zero range.
PushField::ZeroAddress => FieldShape::U64,
// The identity domains' zero range, and an indirect command buffer's execution range.
PushField::ZeroAddress | PushField::IndirectRange => FieldShape::U64,
// The command of an indirect command buffer's execution, and its part's first.
PushField::IndirectSequence | PushField::IndirectBase => FieldShape::U32,
// A texture's mipmap level count, an acceleration structure's instance count, the render
// encoder's viewport count, the render pass's array length, a kernel stage-in buffer's
// bound stride, a storage texture's integer channels' widths, a bicubic slot's format
+10 -5
View File
@@ -1935,11 +1935,13 @@ fn identity_unsourced(f: &RuntimeFact) -> bool {
/// fetch on a device with neither ordered form); the render pass's length, at or past which a
/// vertex function that writes `[[render_target_array_index]]` stores `Layer` 0
/// (`PushField::RenderTargetArrayLength`); the address of the runtime's memory that holds a
/// kernel's private arena past the floor (`PushField::PrivateArenaAddress`); and the draw's
/// viewport count, at or past which a vertex function that writes `[[viewport_array_index]]` stores
/// `ViewportIndex` 0 (`PushField::ViewportCount`). Its fields past the push window are a parameter
/// block, whose address the window holds. Its refusal names the first form the plan holds that
/// they do not lower ([`identity_refusal`]).
/// kernel's private arena past the floor (`PushField::PrivateArenaAddress`); the draw's viewport
/// count, at or past which a vertex function that writes `[[viewport_array_index]]` stores
/// `ViewportIndex` 0 (`PushField::ViewportCount`); and a vertex function's indirect command buffer
/// execution range and command (`PushField::IndirectRange`, `PushField::IndirectSequence`,
/// `PushField::IndirectBase`). Its
/// fields past the push window are a parameter block, whose address the window holds. Its refusal
/// names the first form the plan holds that they do not lower ([`identity_refusal`]).
fn identity_admits(plan: &Plan) -> Result<(), Error> {
match identity_refusal(plan) {
None => Ok(()),
@@ -1982,6 +1984,9 @@ fn identity_refusal(plan: &Plan) -> Option<String> {
| PushField::RenderTargetArrayLength
| PushField::PrivateArenaAddress
| PushField::ViewportCount
| PushField::IndirectRange
| PushField::IndirectSequence
| PushField::IndirectBase
),
});
if let Some(f) = field {
+71 -2
View File
@@ -164,7 +164,7 @@ use crate::lower::emit::EmitCx;
use crate::lower::select::{Plan, SelectCx};
use crate::pipeline::stage_io::{IoNumeric, StageIo};
use crate::pipeline::sym::{PushField, SpecKey, Stage, VaryingKey};
use crate::spirv::builder::constructs::KillForm;
use crate::spirv::builder::constructs::{ArmEnd, ArmFn, KillForm};
use crate::spirv::builder::{FunctionBuilder, ModuleBuilder};
use crate::spirv::error::BResult;
use crate::spirv::ids::{GlobalId, TypeId, Value as SValue};
@@ -379,6 +379,11 @@ pub struct StageIoPlan {
/// A vertex function compiled under `LoweringInputs::region_viewports` that returns outputs:
/// its `DrawIndex` input, which it stores to its `ViewportIndex` output at every return.
pub region_viewport: Option<RegionViewport>,
/// A vertex function compiled under `LoweringInputs::indirect_range`: its test of its command
/// against the execution range in its first block ([`emit_draw_entry`]), and its `Position`
/// object, where it returns one, which an invocation outside the range stores outside every
/// clip volume before it returns.
pub indirect_range: Option<Option<usize>>,
/// The color outputs a fragment function compiled under `LoweringInputs::zeroed_colors`
/// stores zero to at every return, one per such color.
pub zeroed: Vec<Link>,
@@ -1163,6 +1168,11 @@ fn metal_interpolated_constant(
/// vertex's search is a loop: the hooks after it emit in its merge block, which dominates every
/// block of the body.
pub fn emit_draw_entry(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>) -> BResult<()> {
// An invocation of a command outside the execution range draws nothing, before anything
// else the function reads or writes.
if let Some(position) = cx.plan.families.stage_io.indirect_range {
indirect_range(cx, fb, position)?;
}
// The de-indexed or private list form's raw index, read once in the first block, where it
// dominates every use, and the private list form's base vertex.
if let Some(c) = cx.plan.families.stage_io.captured_index {
@@ -1199,6 +1209,66 @@ pub fn emit_draw_entry(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>) -> BRe
Ok(())
}
/// The execution range test of a vertex function compiled under `LoweringInputs::indirect_range`:
/// the range's location and length, two `u32`s at `PushField::IndirectRange`, and where the
/// command (`PushField::IndirectSequence` plus `PushField::IndirectBase`) less the location is the
/// length or more, in `u32`, the
/// invocation stores `(2, 2, 2, 1)` as its `Position` object `position`, outside every clip volume
/// (`x > w`), the same at every vertex of the command, and returns. A command outside the range
/// draws no primitive and runs none of the body.
fn indirect_range(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
position: Option<usize>,
) -> BResult<()> {
let range = cx.push_field(fb, PushField::IndirectRange)?;
let sequence = cx.push_field(fb, PushField::IndirectSequence)?;
let base = cx.push_field(fb, PushField::IndirectBase)?;
let command = fb.binary(BinOp::IAdd, sequence, base)?;
let u32_ = fb.module().ty(SType::Int {
width: 32,
signed: false,
})?;
let read = MemAccess {
aligned: Some(4),
..MemAccess::default()
};
let at = fb.device_place_read_only(range, u32_)?;
let location = fb.load(at, read)?;
let four = crate::memory::roots::k64(fb, 4)?;
let next = fb.binary(BinOp::IAdd, range, four)?;
let at = fb.device_place_read_only(next, u32_)?;
let length = fb.load(at, read)?;
let into = fb.binary(BinOp::ISub, command, location)?;
let outside = fb.binary(BinOp::UGreaterThanEqual, into, length)?;
let position = match position {
Some(object) => Some(global(cx, object)?),
None => None,
};
let leave: ArmFn<'_, ()> = Box::new(move |fb, _| {
if let Some(g) = position {
let f32_ = fb.module().ty(SType::Float { width: 32 })?;
let mut lanes = [None; 4];
for (lane, x) in lanes.iter_mut().zip([2.0f32, 2.0, 2.0, 1.0]) {
let c = fb.module().constant(Constant::Scalar {
ty: f32_,
bits: ConstBits(u64::from(x.to_bits())),
})?;
*lane = Some(fb.module().const_value(c)?);
}
let vec4 = fb.module().ty(SType::Vector { elem: f32_, len: 4 })?;
let lanes: Vec<SValue> = lanes.into_iter().flatten().collect();
let v = fb.composite_construct(vec4, &lanes)?;
let p = fb.module().global_value(g)?;
fb.store(p, v, MemAccess::default())?;
}
fb.ret(None)?;
Ok(ArmEnd::Exits)
});
fb.if_(&mut (), outside, leave, None)?;
Ok(())
}
/// Fetch every pulled attribute at entry, after [`emit_draw_entry`] found what the invocation
/// draws and before the walk emits any instruction of the body, and hold each value for all its
/// uses. The block it emits in dominates every block, and the fetch is straight-line code, so each
@@ -1589,7 +1659,6 @@ pub fn read_at_every_sample(
plan: &Plan,
decls: &crate::lower::emit::FamilyDecls,
) -> Result<(), Error> {
use crate::spirv::builder::constructs::ArmEnd;
use crate::spirv::ir::GlslOp;
let Some(n) = plan
.families
@@ -2394,6 +2394,9 @@ pub fn entry(cx: &mut SelectCx<'_>) -> Result<(), Error> {
if cx.inputs.primitive_id_varying && cx.stage == Stage::Vertex {
primitive_id_output(cx)?;
}
if cx.inputs.indirect_range && cx.stage == Stage::Vertex {
indirect_range(cx)?;
}
// The pass's colors the pipeline lacks, which plain Metal zeroes where a draw covers them.
if cx.stage == Stage::Fragment {
let zeroed = cx.inputs.zeroed_colors.clone();
@@ -2468,6 +2471,27 @@ fn indices_feature(cx: &SelectCx<'_>) -> Feature {
}
}
/// Plan the execution range test of a vertex function compiled under
/// `LoweringInputs::indirect_range` ([`super::StageIoPlan::indirect_range`]): its range's address
/// and its command, pushed, and its `Position` output, where it has one. The range is read by
/// address: a device without device addresses refuses it.
fn indirect_range(cx: &mut SelectCx<'_>) -> Result<(), Error> {
let f = cx.profile.fields();
if f.buffer_access != crate::device::profile::BufferAccess::Addressed || !f.leaf.int64 {
return Err(Unsupported::needs_any_of(
Feature::GpuEncodedIndirectCommands,
vec![cx.profile.addressed_needs()],
)
.into());
}
cx.push.insert(PushField::IndirectRange);
cx.push.insert(PushField::IndirectSequence);
cx.push.insert(PushField::IndirectBase);
let sp = &mut cx.families.stage_io;
sp.indirect_range = Some(sp.invariant);
Ok(())
}
/// Refuse the de-indexed or private list form ([`indices_feature`]) on a device without device
/// addresses, naming what it needs: the indices are reached by address.
fn refuse_unaddressed(cx: &SelectCx<'_>) -> Result<(), Error> {
@@ -375,6 +375,7 @@ mod serde_round_trips {
primitive_id_indices: Some(crate::metal::IndexType::UInt16),
quad_primitive_ids: true,
private_list: true,
indirect_range: true,
color_writes: BTreeMap::from([
(
0,
+20 -8
View File
@@ -88,8 +88,17 @@ pub enum InputsFrom<'a> {
/// `maxVertexCallStackDepth` (the `u32`), whether the pipeline's fragment function reads
/// `[[primitive_id]]` where the device carries it through a varying
/// ([`reads_primitive_id_varying`]). A vertex function writes the primitive ID's varying where
/// the device cannot declare a fragment `PrimitiveId` (`LoweringInputs::primitive_id_varying`).
Vertex(Option<&'a VertexDescriptor>, &'a VariantKey, u32, bool),
/// the device cannot declare a fragment `PrimitiveId` (`LoweringInputs::primitive_id_varying`),
/// and whether the pipeline state is made for indirect command buffers
/// (`supportIndirectCommandBuffers`): a vertex function then pulls every attribute it reads
/// and tests its command against the execution range (`LoweringInputs::indirect_range`).
Vertex(
Option<&'a VertexDescriptor>,
&'a VariantKey,
u32,
bool,
bool,
),
/// The fragment stage of this render pipeline under a variant key: the key's fragment-stage
/// inputs, the attachments among the pipeline's color attachments that the specialized entry
/// writes and whose pixel format is a signed integer
@@ -221,7 +230,7 @@ impl<'a> InputsFrom<'a> {
fn call_stack_depth(&self) -> u32 {
match self {
InputsFrom::Given(i) => i.max_call_stack_depth.unwrap_or(1),
InputsFrom::Vertex(_, _, depth, _) => (*depth).max(1),
InputsFrom::Vertex(_, _, depth, ..) => (*depth).max(1),
InputsFrom::Fragment(pass, ..) => pass.max_call_stack_depth.max(1),
}
}
@@ -2770,7 +2779,7 @@ fn lower_inputs(
match inputs {
InputsFrom::Given(i) => Ok(given_inputs(spec, i)),
// A post-tessellation vertex function pulls every attribute it reads.
InputsFrom::Vertex(desc, variant, depth, primitive_id)
InputsFrom::Vertex(desc, variant, depth, primitive_id, _)
if matches!(spec.ep.stage, AbiStage::Vertex { patch: Some(_) }) =>
{
let attributes = crate::lower::tessellation::attributes_read(spec);
@@ -2784,11 +2793,13 @@ fn lower_inputs(
out.primitive_id_varying = primitive_id;
Ok(key::canonical_inputs(&out))
}
InputsFrom::Vertex(desc, variant, depth, primitive_id) => {
InputsFrom::Vertex(desc, variant, depth, primitive_id, indirect) => {
let attributes = declared_attributes(spec);
// The primitive ID's de-indexed form and the private list form pull every attribute,
// whatever the caller's projection would fetch in fixed function.
let pull_every = variant.primitive_id_indices.is_some() || variant.private_list;
// The primitive ID's de-indexed form, the private list form and a state made for
// indirect command buffers pull every attribute, whatever the caller's projection
// would fetch in fixed function: a command binds its vertex buffers by address alone.
let pull_every =
variant.primitive_id_indices.is_some() || variant.private_list || indirect;
let projection = crate::pipeline::link::vertex::vertex_fetch_projection_for(
desc,
&attributes,
@@ -2802,6 +2813,7 @@ fn lower_inputs(
// Only on a device that cannot declare a fragment `PrimitiveId`: elsewhere a plain
// vertex function's fragment function reads Vulkan's, Metal's there.
out.primitive_id_varying = primitive_id && primitive_id_varying_on(p);
out.indirect_range = indirect;
out.instanced_attributes = instanced_attributes(spec, &out, desc, m)?;
Ok(key::canonical_inputs(&out))
}
@@ -422,6 +422,7 @@ impl Device {
v,
d.max_vertex_call_stack_depth,
primitive_id,
d.support_indirect_command_buffers,
)
};
let (vertex, vertex_inputs, written, varyings, uniform, push_end) = match &d.vertex {
@@ -862,6 +863,7 @@ impl Device {
v,
d.max_vertex_call_stack_depth,
primitive_id,
d.support_indirect_command_buffers,
),
m,
)?;
@@ -161,7 +161,7 @@ impl DeviceProfile {
let mut m = Meter::new(budget);
let variant = VariantKey::new();
guarded(|| {
let r = d.request(InputsFrom::Vertex(vertex, &variant, 1, false));
let r = d.request(InputsFrom::Vertex(vertex, &variant, 1, false, false));
let spec = specialize_one(&r, &mut m)?.spec;
lower_inputs(&spec, r.inputs, self, &mut m)
})
@@ -345,6 +345,10 @@ pub fn function_key(
h.bytes(b"private-list");
}
// Appended only when set.
if inputs.indirect_range {
h.bytes(b"indirect-range");
}
// Appended only when set.
if let Some(d) = inputs.amplification_draws {
h.bytes(b"amplification-draws")
.u64(u64::from(d.layered))
@@ -685,6 +685,7 @@ fn the_inputs_encoding_is_the_earlier_derived_debug() {
.replace(", primitive_id_indices: None", "")
.replace(", quad_primitive_ids: false", "")
.replace(", private_list: false", "")
.replace(", indirect_range: false", "")
.replace(", amplification_draws: None", "")
.replace(", color_writes: {}", "")
.replace(", primitive_varyings: {}", "")
@@ -0,0 +1,230 @@
//! The records of an indirect command buffer of indexed draws under the identity domains: what a
//! kernel's encoding writes (the lowering of `render_command`'s setters, draw and reset) and what
//! a consumer's execution reads, one `VkIndirectCommandsLayoutEXT` sequence per command.
//!
//! The buffer's memory starts with a header of [`IndirectDrawLayout::HEADER_BYTES`]: its capacity, the vertex and the
//! fragment buffer slots each command holds, the stride (a `u32` each), and the index address a
//! reset command binds (a `u64`). Command `i` starts at `HEADER_BYTES + i * stride`, every field at
//! the offset its [`IndirectDrawLayout`] names: each slot's word (the `SlotGuestBase` form of the
//! buffer's address, the address less 2^31), the index buffer token's data
//! (`VkBindIndexBufferIndirectCommandEXT`: the indices' address, their bytes and their
//! `VkIndexType`), four bytes the sequence index token takes its place in, and the indexed draw's
//! `VkDrawIndexedIndirectCommand`. A buffer's `gpuResourceID` is the address of its header.
/// The index token's data, the sequence index's place and the draw's arguments.
const TAIL_BYTES: u32 = 16 + 4 + 20;
/// Where each field of a command lies, for a buffer of `vertex_slots` vertex and
/// `fragment_slots` fragment buffer slots per command (Metal's `maxVertexBufferBindCount` and
/// `maxFragmentBufferBindCount`).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct IndirectDrawLayout {
vertex_slots: u32,
fragment_slots: u32,
}
impl IndirectDrawLayout {
/// The header's bytes: the capacity at [`Self::CAPACITY_AT`], the vertex slots at
/// [`Self::VERTEX_SLOTS_AT`], the fragment slots at [`Self::FRAGMENT_SLOTS_AT`], the stride at [`Self::STRIDE_AT`]
/// (a `u32` each) and the reset index address at [`Self::RESET_INDEX_AT`] (a `u64`).
pub const HEADER_BYTES: u32 = 24;
/// The header's capacity: the commands the buffer holds.
pub const CAPACITY_AT: u32 = 0;
/// The header's vertex buffer slots per command.
pub const VERTEX_SLOTS_AT: u32 = 4;
/// The header's fragment buffer slots per command.
pub const FRAGMENT_SLOTS_AT: u32 = 8;
/// The header's stride: the bytes of one command.
pub const STRIDE_AT: u32 = 12;
/// The header's reset index address: a valid device address, a multiple of 4, that a reset
/// command's index buffer token binds with no bytes.
pub const RESET_INDEX_AT: u32 = 16;
/// The bytes of a slot's word.
pub const SLOT_BYTES: u32 = 8;
/// The most buffer slots of a stage a command holds: Metal's buffer indices below 31.
pub const MAX_SLOTS: u32 = 31;
/// `VkIndexType`'s `VK_INDEX_TYPE_UINT16` and `VK_INDEX_TYPE_UINT32`, as the index token holds them.
pub const INDEX_UINT16: u32 = 0;
/// See [`Self::INDEX_UINT16`].
pub const INDEX_UINT32: u32 = 1;
/// The layout of commands holding `vertex_slots` and `fragment_slots` slots; `None` past
/// [`Self::MAX_SLOTS`] of either.
pub fn new(vertex_slots: u32, fragment_slots: u32) -> Option<IndirectDrawLayout> {
(vertex_slots <= Self::MAX_SLOTS && fragment_slots <= Self::MAX_SLOTS).then_some(
IndirectDrawLayout {
vertex_slots,
fragment_slots,
},
)
}
/// The vertex buffer slots a command holds.
pub fn vertex_slots(self) -> u32 {
self.vertex_slots
}
/// The fragment buffer slots a command holds.
pub fn fragment_slots(self) -> u32 {
self.fragment_slots
}
/// The bytes of one command, a multiple of 8, at most 536.
pub fn stride(self) -> u32 {
self.index() + TAIL_BYTES
}
/// The offset in a command of vertex slot `slot`'s word.
pub fn vertex_slot(self, slot: u32) -> u32 {
Self::SLOT_BYTES * slot
}
/// The offset in a command of fragment slot `slot`'s word.
pub fn fragment_slot(self, slot: u32) -> u32 {
Self::SLOT_BYTES * (self.vertex_slots + slot)
}
/// The offset in a command of the index buffer token's data, a multiple of 8.
pub fn index(self) -> u32 {
Self::SLOT_BYTES * (self.vertex_slots + self.fragment_slots)
}
/// The offset in a command of the sequence index token's place, which holds nothing.
pub fn sequence(self) -> u32 {
self.index() + 16
}
/// The offset in a command of the indexed draw's `VkDrawIndexedIndirectCommand`.
pub fn draw(self) -> u32 {
self.index() + 20
}
/// The offset in the buffer's memory of command `command`.
pub fn command(self, command: u32) -> u64 {
u64::from(Self::HEADER_BYTES) + u64::from(command) * u64::from(self.stride())
}
/// The bytes of a buffer of `capacity` commands.
pub fn bytes(self, capacity: u32) -> u64 {
self.command(capacity)
}
/// The header of a buffer of `capacity` commands whose reset commands bind
/// `reset_index_address`.
pub fn header(
self,
capacity: u32,
reset_index_address: u64,
) -> [u8; Self::HEADER_BYTES as usize] {
let mut header = [0; Self::HEADER_BYTES as usize];
let words = [
capacity,
self.vertex_slots,
self.fragment_slots,
self.stride(),
];
for (at, word) in words.into_iter().enumerate() {
header[4 * at..4 * at + 4].copy_from_slice(&word.to_le_bytes());
}
let at = Self::RESET_INDEX_AT as usize;
header[at..at + 8].copy_from_slice(&reset_index_address.to_le_bytes());
header
}
/// A command as a reset leaves it: every slot's word `slot_word`, the index token binding
/// `reset_index_address` with no bytes, and a draw of no indices and no instances, which draws
/// nothing. A kernel's reset writes the index token and the draw alone.
pub fn reset_command(self, slot_word: u64, reset_index_address: u64) -> Vec<u8> {
let mut command = vec![0; self.stride() as usize];
for slot in 0..self.vertex_slots + self.fragment_slots {
let at = (Self::SLOT_BYTES * slot) as usize;
command[at..at + 8].copy_from_slice(&slot_word.to_le_bytes());
}
let at = self.index() as usize;
command[at..at + 8].copy_from_slice(&reset_index_address.to_le_bytes());
command[at + 12..at + 16].copy_from_slice(&Self::INDEX_UINT32.to_le_bytes());
command
}
}
#[cfg(test)]
mod tests {
use super::*;
/// Seven vertex and seven fragment slots: a command of 152 bytes, its fields in order and
/// every `u64` 8-aligned.
#[test]
fn a_command_places_its_fields_in_order() {
let layout = IndirectDrawLayout::new(7, 7).expect("a layout");
assert_eq!(layout.stride(), 152);
assert_eq!(
(
layout.vertex_slot(6),
layout.fragment_slot(0),
layout.fragment_slot(6)
),
(48, 56, 104)
);
assert_eq!(
(layout.index(), layout.sequence(), layout.draw()),
(112, 128, 132)
);
assert_eq!(layout.command(0), 24);
assert_eq!(layout.command(3), 24 + 3 * 152);
assert_eq!(layout.bytes(2), 24 + 2 * 152);
let widest =
IndirectDrawLayout::new(IndirectDrawLayout::MAX_SLOTS, IndirectDrawLayout::MAX_SLOTS)
.expect("a layout");
assert_eq!(widest.stride(), 536);
assert!(IndirectDrawLayout::new(IndirectDrawLayout::MAX_SLOTS + 1, 0).is_none());
assert!(IndirectDrawLayout::new(0, IndirectDrawLayout::MAX_SLOTS + 1).is_none());
let none = IndirectDrawLayout::new(0, 0).expect("a layout");
assert_eq!((none.stride(), none.index(), none.draw()), (40, 0, 20));
}
/// The header holds the capacity, the counts, the stride and the reset index address; a
/// reset command holds the slot word in every slot, the index token at that address with no
/// bytes, and a draw of nothing.
#[test]
fn the_header_and_a_reset_command_hold_their_words() {
let layout = IndirectDrawLayout::new(2, 1).expect("a layout");
let header = layout.header(9, 0x1234_5678_9abc_def0);
let word = |at: u32| u32::from_le_bytes(header[at as usize..][..4].try_into().unwrap());
assert_eq!(
(
word(IndirectDrawLayout::CAPACITY_AT),
word(IndirectDrawLayout::VERTEX_SLOTS_AT),
word(IndirectDrawLayout::FRAGMENT_SLOTS_AT),
word(IndirectDrawLayout::STRIDE_AT)
),
(9, 2, 1, 64)
);
let at = IndirectDrawLayout::RESET_INDEX_AT as usize;
assert_eq!(
u64::from_le_bytes(header[at..at + 8].try_into().unwrap()),
0x1234_5678_9abc_def0
);
let command = layout.reset_command(0xaaaa_bbbb_cccc_dddd, 0x40);
assert_eq!(command.len(), 64);
for slot in 0..3 {
let at = (8 * slot) as usize;
assert_eq!(
u64::from_le_bytes(command[at..at + 8].try_into().unwrap()),
0xaaaa_bbbb_cccc_dddd
);
}
let at = layout.index() as usize;
assert_eq!(
u64::from_le_bytes(command[at..at + 8].try_into().unwrap()),
0x40
);
assert_eq!(&command[at + 8..at + 12], &[0; 4]);
assert_eq!(
u32::from_le_bytes(command[at + 12..at + 16].try_into().unwrap()),
IndirectDrawLayout::INDEX_UINT32
);
assert!(command[layout.sequence() as usize..]
.iter()
.all(|&b| b == 0));
}
}
@@ -355,6 +355,18 @@ pub struct LoweringInputs {
/// as without it.
#[cfg_attr(feature = "serde", serde(default))]
pub private_list: bool,
/// The function's render pipeline state is made for indirect command buffers
/// (`supportIndirectCommandBuffers`): a vertex function reads the execution range at
/// `PushField::IndirectRange` and its command, `PushField::IndirectSequence` plus
/// `PushField::IndirectBase`, in its first block, and an invocation of a command outside the range (`command - location >= length`,
/// in `u32`) stores its `[[position]]` as `(2, 2, 2, 1)`, outside every clip volume, and
/// returns before the body, so its command draws nothing and writes no memory. A direct draw
/// of the state is pushed a range of every command. Refused on a device without device
/// addresses (`Feature::GpuEncodedIndirectCommands`). `Device::compile_render_pipeline` sets
/// it for a `Function` vertex stage of a descriptor that sets the flag, whose vertex function
/// then pulls every attribute it reads. Any other function compiles as without it.
#[cfg_attr(feature = "serde", serde(default))]
pub indirect_range: bool,
/// The function's render pipeline draws each vertex amplification as a draw of its own
/// (`VariantKey::amplification_draws`), where Vulkan multiview cannot draw the encoder's
/// mappings as Metal renders them. Under it a vertex or fragment function reads its
+2
View File
@@ -85,6 +85,7 @@ pub(crate) mod compile;
pub(crate) mod descriptor;
pub(crate) mod facts;
pub(crate) mod graphics;
mod indirect_draws;
pub(crate) mod interface;
pub(crate) mod layout;
pub(crate) mod link;
@@ -120,6 +121,7 @@ pub use graphics::{
ImageblockMechanism, InputAttachmentUse, LineBandState, ShadowStencilUse, StorageAttachmentUse,
StorageAttachmentView, TessellationState,
};
pub use indirect_draws::IndirectDrawLayout;
pub use interface::{
AccessSet, AttributeFetch, BufferForm, BufferKind, BufferSlot, CommandWrites, DescriptorView,
LevelReads, NumberedSampler, PatchDomain, PipelineInterface, PlacedField, PushLoc,
+21
View File
@@ -927,6 +927,27 @@ pub enum PushField {
/// `RootTableAddress`: a hole the consumer fills (`PushHole::MergedDrawAddress`), placed with
/// the other addresses. The merge passes read the header there too.
MergedDrawAddress,
/// Device address (`u64`) of the execution range (Metal's
/// `MTLIndirectCommandBufferExecutionRange`, a `u32` location then a `u32` length) a vertex
/// function compiled under `LoweringInputs::indirect_range` reads in its first block: an
/// invocation of a command outside it ([`PushField::IndirectSequence`]) returns before the
/// body, its `[[position]]` outside every clip volume, so the command draws nothing. The
/// binder points it at the range an execution reads from a buffer, and at a range of every
/// command (location 0, length `u32::MAX`) for a direct draw or an execution over a range
/// the CPU gives. Placed with the other addresses.
IndirectRange,
/// The command (`u32`) of an indirect command buffer's execution that the draw is, less its
/// part's first ([`PushField::IndirectBase`]), which a vertex function compiled under
/// `LoweringInputs::indirect_range` adds to it and tests against its
/// [`PushField::IndirectRange`]: the sequence index an execution's `SEQUENCE_INDEX` token
/// pushes there, 0 for a direct draw. Placed beside the addresses, so the vertex window always
/// holds it.
IndirectSequence,
/// The first command (`u32`) of the part of an indirect command buffer's execution that the
/// draw is: a consumer may run an execution's commands as several parts, each counting its
/// sequences ([`PushField::IndirectSequence`]) from 0, and pushes each part's first here. 0
/// for a direct draw. Placed beside the addresses, so the vertex window always holds it.
IndirectBase,
/// Which draw of a fragment function compiled under `LoweringInputs::snapshot_textures` runs
/// (`u32`): a hole the consumer fills (`PushHole::SnapshotPhase`), placed beside the addresses
/// so the fragment window always holds it. 1 in the draw that takes the snapshot, whose
@@ -0,0 +1,140 @@
//! Indirect command buffers under the identity domains: GPU-encoded indexed triangle draws.
//!
//! - The owned fixture `engine/icb_merged_indexed.ll`'s kernels, which bind three vertex buffers
//! and a fragment buffer of each command and draw indexed triangles of 16-bit and of 32-bit
//! indices, and `engine/icb_indexed_extras.ll`'s `icb_extras_reset`, which resets render
//! commands, compile and
//! validate on every profile with device addresses.
//! - A kernel's plain draw (`engine/icb_merged_draws.ll`'s `icb_merged_triangles`) is refused,
//! `Unsupported{GpuEncodedIndirectCommands, NotImplemented}`.
//! - The vertex function of a state made with `supportIndirectCommandBuffers` pushes the execution
//! range's address and its command (`PushField::IndirectRange`, `PushField::IndirectSequence`,
//! `PushField::IndirectBase`)
//! in its window; the same state made without it pushes neither. Both validate.
//!
//! `llvm-as` assembles the fixtures; without it a test skips visibly.
use crate::budget::Budget;
use crate::device::{Device, DevicePolicy, HandleDomain, PointerDomain};
use crate::error::{Error, Feature, Needs};
use crate::library::Library;
use crate::metal::PixelFormat;
use crate::pipeline::descriptor::{
ColorAttachmentDescriptor, FunctionDescriptor, RenderPipelineDescriptor, StageSource,
};
use crate::pipeline::interface::PushLoc;
use crate::pipeline::sym::PushField;
use crate::pipeline::testing::{
compile, description, engine_dir, link_and_validate, llvm_assemble, profile, AssembleError,
};
use crate::spirv::testing::check_words_valid;
/// Profiles with `bufferDeviceAddress` and `shaderInt64`.
const PROFILES: [&str; 2] = ["lavapipe", "moltenvk-m3"];
fn identity() -> DevicePolicy {
DevicePolicy {
pointer_domain: PointerDomain::Identity,
handle_domain: HandleDomain::Identity,
..DevicePolicy::default()
}
}
/// The bitcode of the engine fixture `name`, or `None` (printed) where `llvm-as` is missing.
fn assemble(name: &str) -> Option<Vec<u8>> {
match llvm_assemble(&engine_dir().join(format!("{name}.ll"))) {
Ok(bitcode) => Some(bitcode),
Err(AssembleError::Missing(why)) => {
eprintln!("SKIPPED: {why}");
None
}
Err(e) => panic!("{name}: {e:?}"),
}
}
/// Kernels that bind each command's buffers, draw indexed triangles of either index size, or
/// reset commands compile and validate under the identity domains on every profile.
#[test]
fn kernels_encode_indexed_triangle_draws_and_resets_under_the_identity_domains() {
let kernels = [
("icb_merged_indexed", "icb_indexed_16"),
("icb_merged_indexed", "icb_indexed_32"),
("icb_indexed_extras", "icb_extras_reset"),
];
for (fixture, entry) in kernels {
let Some(bc) = assemble(fixture) else {
return;
};
for stem in PROFILES {
let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}"));
let a = compile(&bc, entry, &p).unwrap_or_else(|e| panic!("{stem}: {entry}: {e:?}"));
link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{stem}: {entry}: {e}"));
}
}
}
/// A kernel's plain draw into an indirect command buffer is not built: the first cut draws
/// indexed triangles alone.
#[test]
fn a_kernels_plain_draw_into_commands_is_refused_under_the_identity_domains() {
let Some(bc) = assemble("icb_merged_draws") else {
return;
};
for stem in PROFILES {
let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}"));
match compile(&bc, "icb_merged_triangles", &p) {
Err(Error::Unsupported(u)) => assert_eq!(
(u.feature, u.needs),
(Feature::GpuEncodedIndirectCommands, Needs::NotImplemented),
"{stem}"
),
other => panic!("{stem}: {other:?}"),
}
}
}
/// The vertex function of a state for indirect command buffers pushes the execution range's
/// address and its command; the same state without the flag pushes neither.
#[test]
fn a_state_for_indirect_command_buffers_pushes_its_execution_range() {
let Some(bc) = assemble("icb_merged_indexed") else {
return;
};
let library = Library::from_air(&bc).expect("the library");
let function = |name| {
StageSource::Function(FunctionDescriptor::new(
library.function(name).expect("the function"),
))
};
for stem in PROFILES {
let desc = description(stem).unwrap_or_else(|e| panic!("{e}"));
let device = Device::from_queries(desc, identity()).unwrap_or_else(|e| panic!("{e}"));
for flagged in [false, true] {
let mut d = RenderPipelineDescriptor::new(function("icb_indexed_vertex"));
d.fragment = Some(function("icb_indexed_fragment"));
d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint));
d.support_indirect_command_buffers = flagged;
let p = (device.compile_render_pipeline(&d, &Budget::standard()))
.unwrap_or_else(|e| panic!("{stem}: {e:?}"));
let vertex = &p.interface.push[0];
let pushed = |field| {
(vertex.fields.iter())
.any(|f| f.field == field && matches!(f.loc, PushLoc::Push { .. }))
};
assert_eq!(
(
pushed(PushField::IndirectRange),
pushed(PushField::IndirectSequence),
pushed(PushField::IndirectBase)
),
(flagged, flagged, flagged),
"{stem}: flagged {flagged}"
);
for stage in &p.stages {
check_words_valid(&stage.spirv, &p.requirements, device.profile()).unwrap_or_else(
|e| panic!("{stem}: flagged {flagged}: {:?}: {e}", stage.stage),
);
}
}
}
}
+1
View File
@@ -82,6 +82,7 @@ mod engine_helper_threads;
mod engine_identity;
mod engine_identity_contain;
mod engine_identity_domain;
mod engine_identity_icb;
mod engine_identity_interlock;
mod engine_identity_pointers;
mod engine_identity_render;
@@ -214,6 +214,16 @@ assoc-const metal2vulkan::pipeline::CommandWrites::STAGE_IN_REGION pub const STA
assoc-const metal2vulkan::pipeline::CommandWrites::THREADGROUP_MEMORY pub const THREADGROUP_MEMORY: u32
assoc-const metal2vulkan::pipeline::FunctionHandle::NULL_WORD pub const NULL_WORD: u32
assoc-const metal2vulkan::pipeline::FunctionHandle::RESERVED_WORD pub const RESERVED_WORD: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::CAPACITY_AT pub const CAPACITY_AT: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::FRAGMENT_SLOTS_AT pub const FRAGMENT_SLOTS_AT: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::HEADER_BYTES pub const HEADER_BYTES: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::INDEX_UINT16 pub const INDEX_UINT16: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::INDEX_UINT32 pub const INDEX_UINT32: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::MAX_SLOTS pub const MAX_SLOTS: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::RESET_INDEX_AT pub const RESET_INDEX_AT: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::SLOT_BYTES pub const SLOT_BYTES: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::STRIDE_AT pub const STRIDE_AT: u32
assoc-const metal2vulkan::pipeline::IndirectDrawLayout::VERTEX_SLOTS_AT pub const VERTEX_SLOTS_AT: u32
assoc-const metal2vulkan::pipeline::KernelVariant::ALL pub const ALL: [KernelVariant; 3]
assoc-const metal2vulkan::pipeline::LineBandState::FRONT_FACE pub const FRONT_FACE: vk::FrontFace
assoc-const metal2vulkan::pipeline::LineBandState::PUSH_BYTES pub const PUSH_BYTES: u32
@@ -427,6 +437,16 @@ assoc-const-value metal2vulkan::pipeline::CommandWrites::STAGE_IN_REGION 1 <<11
assoc-const-value metal2vulkan::pipeline::CommandWrites::THREADGROUP_MEMORY 1 <<10
assoc-const-value metal2vulkan::pipeline::FunctionHandle::NULL_WORD 0
assoc-const-value metal2vulkan::pipeline::FunctionHandle::RESERVED_WORD 1
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::CAPACITY_AT 0
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::FRAGMENT_SLOTS_AT 8
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::HEADER_BYTES 24
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::INDEX_UINT16 0
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::INDEX_UINT32 1
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::MAX_SLOTS 31
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::RESET_INDEX_AT 16
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::SLOT_BYTES 8
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::STRIDE_AT 12
assoc-const-value metal2vulkan::pipeline::IndirectDrawLayout::VERTEX_SLOTS_AT 4
assoc-const-value metal2vulkan::pipeline::KernelVariant::ALL [KernelVariant::Plain, KernelVariant::PartialThreadgroups, KernelVariant::EmulatedSimdgroups]
assoc-const-value metal2vulkan::pipeline::LineBandState::FRONT_FACE crate::pipeline::link::band::LineBand::FRONT_FACE
assoc-const-value metal2vulkan::pipeline::LineBandState::PUSH_BYTES crate::pipeline::link::band::LineBand::PUSH_BYTES
@@ -2965,6 +2985,7 @@ field metal2vulkan::pipeline::LoweringInputs.extended_range_colors pub extended_
field metal2vulkan::pipeline::LoweringInputs.flat_grid pub flat_grid: bool
field metal2vulkan::pipeline::LoweringInputs.folded_groups pub folded_groups: bool
field metal2vulkan::pipeline::LoweringInputs.framebuffer_fetch pub framebuffer_fetch: Option<FramebufferFetchInputs>
field metal2vulkan::pipeline::LoweringInputs.indirect_range pub indirect_range: bool
field metal2vulkan::pipeline::LoweringInputs.instanced_attributes pub instanced_attributes: BTreeSet<u32>
field metal2vulkan::pipeline::LoweringInputs.kept_imageblock_bytes pub kept_imageblock_bytes: Option<u32>
field metal2vulkan::pipeline::LoweringInputs.logic_operation pub logic_operation: Option<vk::LogicOp>
@@ -7233,6 +7254,19 @@ method metal2vulkan::pipeline::GraphicsState::color_blend_attachments pub fn col
method metal2vulkan::pipeline::GraphicsState::new pub fn new(topology: vk::PrimitiveTopology, rasterization_samples: vk::SampleCountFlags) -> GraphicsState
method metal2vulkan::pipeline::HandleClass::sampler pub fn sampler(use_: crate::metal::sampler::SamplerUse) -> HandleClass
method metal2vulkan::pipeline::HandleClass::sampler_use pub fn sampler_use(self) -> Option<crate::metal::sampler::SamplerUse>
method metal2vulkan::pipeline::IndirectDrawLayout::bytes pub fn bytes(self, capacity: u32) -> u64
method metal2vulkan::pipeline::IndirectDrawLayout::command pub fn command(self, command: u32) -> u64
method metal2vulkan::pipeline::IndirectDrawLayout::draw pub fn draw(self) -> u32
method metal2vulkan::pipeline::IndirectDrawLayout::fragment_slot pub fn fragment_slot(self, slot: u32) -> u32
method metal2vulkan::pipeline::IndirectDrawLayout::fragment_slots pub fn fragment_slots(self) -> u32
method metal2vulkan::pipeline::IndirectDrawLayout::header pub fn header(self, capacity: u32, reset_index_address: u64) -> [u8; Self::HEADER_BYTES as usize]
method metal2vulkan::pipeline::IndirectDrawLayout::index pub fn index(self) -> u32
method metal2vulkan::pipeline::IndirectDrawLayout::new pub fn new(vertex_slots: u32, fragment_slots: u32) -> Option<IndirectDrawLayout>
method metal2vulkan::pipeline::IndirectDrawLayout::reset_command pub fn reset_command(self, slot_word: u64, reset_index_address: u64) -> Vec<u8>
method metal2vulkan::pipeline::IndirectDrawLayout::sequence pub fn sequence(self) -> u32
method metal2vulkan::pipeline::IndirectDrawLayout::stride pub fn stride(self) -> u32
method metal2vulkan::pipeline::IndirectDrawLayout::vertex_slot pub fn vertex_slot(self, slot: u32) -> u32
method metal2vulkan::pipeline::IndirectDrawLayout::vertex_slots pub fn vertex_slots(self) -> u32
method metal2vulkan::pipeline::InputAttachmentUse::new pub fn new(color_index: u32, input_attachment_index: u32, format_class: SampledType) -> InputAttachmentUse
method metal2vulkan::pipeline::LinkedFunction::name pub fn name(&self) -> &str
method metal2vulkan::pipeline::LinkedFunction::new pub fn new(function: Function) -> LinkedFunction
@@ -7824,6 +7858,7 @@ struct metal2vulkan::pipeline::FunctionDescriptor #[derive(Clone, Debug, Partial
struct metal2vulkan::pipeline::FunctionHandle #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct FunctionHandle(u32)
struct metal2vulkan::pipeline::GraphicsState #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub struct GraphicsState
struct metal2vulkan::pipeline::ImageHandleClass #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub struct ImageHandleClass
struct metal2vulkan::pipeline::IndirectDrawLayout #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct IndirectDrawLayout
struct metal2vulkan::pipeline::InputAttachmentUse #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub struct InputAttachmentUse
struct metal2vulkan::pipeline::LevelReads #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub struct LevelReads
struct metal2vulkan::pipeline::LineBandState #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub struct LineBandState
@@ -10915,6 +10950,9 @@ variant metal2vulkan::pipeline::PushField::ExecutionStatusAddress ExecutionStatu
variant metal2vulkan::pipeline::PushField::FetchedColor FetchedColor { color: u32, texels: SampledType }
variant metal2vulkan::pipeline::PushField::HalfBlendColor HalfBlendColor
variant metal2vulkan::pipeline::PushField::IndexCapacity IndexCapacity
variant metal2vulkan::pipeline::PushField::IndirectBase IndirectBase
variant metal2vulkan::pipeline::PushField::IndirectRange IndirectRange
variant metal2vulkan::pipeline::PushField::IndirectSequence IndirectSequence
variant metal2vulkan::pipeline::PushField::InstanceCount InstanceCount(SlotRef)
variant metal2vulkan::pipeline::PushField::LineBand LineBand
variant metal2vulkan::pipeline::PushField::MergedDrawAddress MergedDrawAddress
Can't render this file because it is too large.
+1
View File
@@ -408,6 +408,7 @@ surface! {
enum VertexFetch N;
struct VertexFetchProjection N;
struct FunctionHandle O;
struct IndirectDrawLayout O;
struct RenderPipelineKeys N;
enum Mechanism N;
enum RuntimeFact N;
@@ -1424,6 +1424,16 @@ engine/icb_imageblock_encode.air.ll icb_imageblock_encode ok ok ok ok ok ok ok o
engine/icb_imageblock_encode.ll icb_imageblock_encode ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_imageblock_template.air.ll icb_imageblock_template ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_imageblock_template.ll icb_imageblock_template ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_indexed_extras.air.ll icb_extras_reset ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_indexed_extras.air.ll icb_extras_back_vertex ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_indexed_extras.air.ll icb_extras_back_fragment ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_indexed_extras.air.ll icb_extras_wide_vertex ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok Unsupported{DescriptorCount; AnyOf[[Limit { limit: MaxPerStageDescriptorUniformBuffers, required: 13, available: 12 }]]}
engine/icb_indexed_extras.air.ll icb_extras_fragment ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_indexed_extras.ll icb_extras_reset ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_indexed_extras.ll icb_extras_back_vertex ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_indexed_extras.ll icb_extras_back_fragment ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_indexed_extras.ll icb_extras_wide_vertex ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok Unsupported{DescriptorCount; AnyOf[[Limit { limit: MaxPerStageDescriptorUniformBuffers, required: 13, available: 12 }]]}
engine/icb_indexed_extras.ll icb_extras_fragment ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_inherited_dispatches.air.ll cid_encode ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_inherited_dispatches.air.ll cid_count ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/icb_inherited_dispatches.ll cid_encode ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
Can't render this file because it is too large.
+12
View File
@@ -242,6 +242,18 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
An argument buffer's texture reads the element at its ID's index masked to its low 16 bits,
so a bad ID reads an element of the arrays ([RESOURCE-ID.md](RESOURCE-ID.md)); the change that
first lowers an argument buffer's sampler masks its index the same way.
A function writes an indirect command buffer's render commands, under the identity domains
alone, through the `gpuResourceID` an argument buffer's `command_buffer` member holds: the
device address of the buffer's records, laid out as `pipeline::IndirectDrawLayout` states. A
command's `set_vertex_buffer` and `set_fragment_buffer`, its `draw_indexed_primitives` of
triangles and its `reset` write them, each only where the command's index is below the
buffer's capacity; any other indirect-command operation is
`Unsupported{GpuEncodedIndirectCommands}`. A render pipeline state made with
`support_indirect_command_buffers` compiles its vertex function under
`LoweringInputs::indirect_range`: it reads the execution's range at `PushField::IndirectRange`
and its command, `PushField::IndirectSequence` (a part's sequence index) plus
`PushField::IndirectBase` (the part's first command), a command outside the range draws nothing,
and the function pulls every vertex attribute it reads.
Loops run as written: no execution bound is translated in.
+4 -4
View File
@@ -78,7 +78,7 @@ Columns:
| `SimdgroupMatrix16x16x16` | A 16x16x16 simdgroup matrix product (`air.simdgroup_matrix_16x16x16_[widening_]multiply_accumulate`), in any stage | every device (not implemented) | `ours` | 1: `crates/metal2vulkan/src/lower/simd/matrix.rs (select)` | `rare`: 16x16x16 simdgroup matrix products (Metal: Apple10 GPUs and later) |
| `ArgumentBufferPointers` | Argument buffers holding buffer pointers (dynamic roots) | devices without buffer device addresses (`addressed_needs`) | `device` | 1: `crates/metal2vulkan/src/device/metal.rs (unsupported_features)` | `app`: argument buffers holding buffer pointers |
| `ArgumentBufferTextures` | Argument buffers holding textures or samplers (handle domain) | devices without a capability the site computes (`gaps`); devices without a capability the site computes (`missing`); every device (not implemented) | `ours` | 15: `crates/metal2vulkan/src/bind/heap.rs (array)`, `crates/metal2vulkan/src/bind/heap.rs (member_texel_view, 2 sites)` (+8) | `app`: argument buffers holding textures and samplers (bindless) |
| `ArgumentBufferObjects` | Argument-buffer members that are pipeline states, ICBs, function tables, or acceleration structures | every device (not implemented) | `ours` | 5: `crates/metal2vulkan/src/lower/access/encode.rs (select_command, 3 sites)`, `crates/metal2vulkan/src/memory/provenance.rs (access)` (+1) | `rare`: pipeline states and ICBs in argument buffers |
| `ArgumentBufferObjects` | Argument-buffer members that are pipeline states, ICBs, function tables, or acceleration structures | every device (not implemented) | `ours` | 6: `crates/metal2vulkan/src/lower/access/encode.rs (select_command, 3 sites)`, `crates/metal2vulkan/src/lower/access/icb.rs (select)` (+2) | `rare`: pipeline states and ICBs in argument buffers |
| `DereferenceLoadedPointer` | Dereferencing a pointer loaded from memory or made from an integer | devices short of a Vulkan feature the site names; devices without buffer device addresses (`addressed_needs`); every device (no Vulkan mechanism) | `device` | 4: `crates/metal2vulkan/src/lower/access/dynamic.rs (plan_misses)`, `crates/metal2vulkan/src/lower/access/local.rs (access_ptr)` (+2) | `app`: pointers loaded from argument buffers |
| `PointerToInteger` | Storing a pointer or converting it to an integer | - | `-` | via a helper: 1: `crates/metal2vulkan/src/lower/access/dynamic.rs (require_addresses)` | `rare`: pointer to integer casts |
| `PointerCompare` | Comparing pointers with different roots | - | `-` | via a helper: 1: `crates/metal2vulkan/src/lower/access/copy.rs (addressed)` | `rare`: comparing pointers of different roots |
@@ -136,7 +136,7 @@ Columns:
| `RayTracing` | | devices without a capability the site computes (`missing`); every device (no Vulkan mechanism); every device (not implemented) | `ours` | 12: `crates/metal2vulkan/src/bind/acceleration.rs (instance_record, 2 sites)`, `crates/metal2vulkan/src/lower/raytracing/mod.rs (instance_count)` (+5) | `rare`: ray tracing (out of scope by ruling) |
| `Tensors` | | every device (not implemented) | `ours` | 2: `crates/metal2vulkan-air/src/canon/matmul2d/synth.rs (refuse)`, `crates/metal2vulkan/src/lower/select.rs (route_air)` | `rare`: shader tensors |
| `RasterizationRateMap` | | devices without VkFeature::MultiViewport; devices without VkFeature::ShaderDrawParameters; devices without VkFeature::ShaderOutputViewportIndex; every device (not implemented) | `ours` | 2: `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_viewport, 2 sites)` | `rare`: rasterization rate maps |
| `GpuEncodedIndirectCommands` | | devices short of a Vulkan feature the site names; devices without buffer device addresses (`addressed_needs`); every device (no Vulkan mechanism); every device (not implemented) | `ours` | 20: `crates/metal2vulkan/src/bind/replay.rs (preprocess)`, `crates/metal2vulkan/src/bind/replay.rs (replay_preprocess_module)` (+12) | `rare`: indirect command buffers encoded by a kernel |
| `GpuEncodedIndirectCommands` | | devices short of a Vulkan feature the site names; devices without buffer device addresses (`addressed_needs`); every device (no Vulkan mechanism); every device (not implemented) | `ours` | 25: `crates/metal2vulkan/src/bind/replay.rs (preprocess)`, `crates/metal2vulkan/src/bind/replay.rs (replay_preprocess_module)` (+15) | `rare`: indirect command buffers encoded by a kernel |
| `VulkanVersion` | The device's Vulkan version is below the 1.2 floor | devices without ApiVersion::V1_2 | `device` | 2: `crates/metal2vulkan/src/ash_interop/query.rs (query)`, `crates/metal2vulkan/src/device/derive.rs (from_queries)` | `none`: a device below Vulkan 1.2 |
| `PushWindow` | The device's `maxPushConstantsSize` is below the 256 bytes of the push window every stage is lowered for | devices without VkLimit::MaxPushConstantsSize | `device` | 1: `crates/metal2vulkan/src/device/derive.rs (from_queries)` | `none`: a device whose maxPushConstantsSize is below 256 bytes |
| `IdentityDomains` | The identity pointer and handle domains (`PointerDomain::Identity`, `HandleDomain::Identity`) | devices without a capability the site computes (`all`); every device (not implemented) | `ours` | 7: `crates/metal2vulkan/src/device/derive.rs (identity_domains)`, `crates/metal2vulkan/src/lower/sampler/anisotropic.rs (select)` (+5) | `none`: the identity domains, which the runtime alone takes and which lower only kernels over buffer slots, textures in slots or argument buffers, and runtime samplers, so far |
@@ -419,7 +419,7 @@ Each refusal's sites, with the function that builds it.
- `feature::SimdgroupMatrix16x16x16`: `crates/metal2vulkan/src/lower/simd/matrix.rs (select)`
- `feature::ArgumentBufferPointers`: `crates/metal2vulkan/src/device/metal.rs (unsupported_features)`
- `feature::ArgumentBufferTextures`: `crates/metal2vulkan/src/bind/heap.rs (array)`; `crates/metal2vulkan/src/bind/heap.rs (member_texel_view, 2 sites)`; `crates/metal2vulkan/src/bind/heap.rs (member_view, 4 sites)`; `crates/metal2vulkan/src/bind/heap.rs (new)`; `crates/metal2vulkan/src/lower/access/handle.rs (select)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_one)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_sampling)`; `crates/metal2vulkan/src/lower/texture/atomic.rs (select)`; `crates/metal2vulkan/src/lower/texture/slot.rs (declare_heap, 2 sites)`; `crates/metal2vulkan/src/pipeline/link.rs (heap_set)`
- `feature::ArgumentBufferObjects`: `crates/metal2vulkan/src/lower/access/encode.rs (select_command, 3 sites)`; `crates/metal2vulkan/src/memory/provenance.rs (access)`; `crates/metal2vulkan/src/memory/provenance.rs (classify)`
- `feature::ArgumentBufferObjects`: `crates/metal2vulkan/src/lower/access/encode.rs (select_command, 3 sites)`; `crates/metal2vulkan/src/lower/access/icb.rs (select)`; `crates/metal2vulkan/src/memory/provenance.rs (access)`; `crates/metal2vulkan/src/memory/provenance.rs (classify)`
- `feature::DereferenceLoadedPointer`: `crates/metal2vulkan/src/lower/access/dynamic.rs (plan_misses)`; `crates/metal2vulkan/src/lower/access/local.rs (access_ptr)`; `crates/metal2vulkan/src/lower/access/local.rs (threadgroup_constant_refusal)`; `crates/metal2vulkan/src/memory/plan.rs (analyze)`
- `feature::PointerToInteger`: `crates/metal2vulkan/src/lower/access/dynamic.rs (require_addresses)`
- `feature::PointerCompare`: `crates/metal2vulkan/src/lower/access/copy.rs (addressed)`
@@ -476,7 +476,7 @@ Each refusal's sites, with the function that builds it.
- `feature::RayTracing`: `crates/metal2vulkan/src/bind/acceleration.rs (instance_record, 2 sites)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (instance_count)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (intersect, 5 sites)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (primitive_data_read)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (select_param)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (slot_of)`; `crates/metal2vulkan/src/lower/select.rs (route_air)`
- `feature::Tensors`: `crates/metal2vulkan-air/src/canon/matmul2d/synth.rs (refuse)`; `crates/metal2vulkan/src/lower/select.rs (route_air)`
- `feature::RasterizationRateMap`: `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_viewport, 2 sites)`
- `feature::GpuEncodedIndirectCommands`: `crates/metal2vulkan/src/bind/replay.rs (preprocess)`; `crates/metal2vulkan/src/bind/replay.rs (replay_preprocess_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs (draw_replay_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs (draw_replay_preprocess)`; `crates/metal2vulkan/src/bind/replay/merged.rs (draw_merge_module)`; `crates/metal2vulkan/src/lower/access/encode.rs (needs, 3 sites)`; `crates/metal2vulkan/src/lower/access/encode.rs (select_command)`; `crates/metal2vulkan/src/lower/access/mod.rs (plan_replay, 3 sites)`; `crates/metal2vulkan/src/lower/mesh/mod.rs (plan_partial_groups)`; `crates/metal2vulkan/src/lower/select.rs (finish, 2 sites)`; `crates/metal2vulkan/src/lower/simd/divergent.rs (barriers)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (param)`; `crates/metal2vulkan/src/pipeline/compile.rs (analyze_one, 2 sites)`
- `feature::GpuEncodedIndirectCommands`: `crates/metal2vulkan/src/bind/replay.rs (preprocess)`; `crates/metal2vulkan/src/bind/replay.rs (replay_preprocess_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs (draw_replay_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs (draw_replay_preprocess)`; `crates/metal2vulkan/src/bind/replay/merged.rs (draw_merge_module)`; `crates/metal2vulkan/src/lower/access/encode.rs (needs, 3 sites)`; `crates/metal2vulkan/src/lower/access/encode.rs (select_command)`; `crates/metal2vulkan/src/lower/access/icb.rs (needs, 2 sites)`; `crates/metal2vulkan/src/lower/access/icb.rs (select, 2 sites)`; `crates/metal2vulkan/src/lower/access/mod.rs (plan_replay, 3 sites)`; `crates/metal2vulkan/src/lower/mesh/mod.rs (plan_partial_groups)`; `crates/metal2vulkan/src/lower/select.rs (finish, 2 sites)`; `crates/metal2vulkan/src/lower/simd/divergent.rs (barriers)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (indirect_range)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (param)`; `crates/metal2vulkan/src/pipeline/compile.rs (analyze_one, 2 sites)`
- `feature::VulkanVersion`: `crates/metal2vulkan/src/ash_interop/query.rs (query)`; `crates/metal2vulkan/src/device/derive.rs (from_queries)`
- `feature::PushWindow`: `crates/metal2vulkan/src/device/derive.rs (from_queries)`
- `feature::IdentityDomains`: `crates/metal2vulkan/src/device/derive.rs (identity_domains)`; `crates/metal2vulkan/src/lower/sampler/anisotropic.rs (select)`; `crates/metal2vulkan/src/lower/sampler/mod.rs (finish)`; `crates/metal2vulkan/src/lower/select.rs (identity_admits)`; `crates/metal2vulkan/src/lower/sync/barrier.rs (require_seq_cst)`; `crates/metal2vulkan/src/lower/texture/slot.rs (storage_format)`; `crates/metal2vulkan/src/pipeline/link.rs (identity_set)`