From 7cd885ea5b92d23db5e63932839a2a0de0437c1d Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 12 Nov 2026 07:20:14 -0800 Subject: [PATCH] runtime_lane::render_merged_attributes: stage_in states' executions run on the GPU alone The lane test of executions whose inherited state's vertex function reads [[stage_in]] attributes now states the GPU form, against the host step's pixels (a barrier the CPU set and cleared), for a kernel-written ICB of triangle draws and indexed draws (merged) and triangle strips (one draw per command), each command binding its own positions and per-instance marks at its own offsets, first/base vertex and base instance: - pulled_attributes_of_executed_draws_fetch_their_commands_elements: strides 10 and 6, which the shader fetches anyway (merged draws read the command's vertex and instance, not the merged draw's corner indices); - fixed_function_layouts_of_executed_draws_are_pulled: strides 8 and 4, marks at step rates 1 and 2, no vertex buffer bound at the encoder; - a_layout_of_a_stride_set_per_bind_keeps_the_host_step: a dynamic-stride position layout the commands bind at their own stride takes the host step, whose notice names the rule. The fixture gains ima_strips (a triangle strip writer). docs/API.md states the attribute rule in the indirect command buffer section and in the GPU form's list; api_signatures.tsv and api_surface.rs list draw_replay_vertex_layouts. --- .../engine/icb_merged_attributes.air.ll | 252 ++++++------ .../public/engine/icb_merged_attributes.ll | 252 ++++++------ .../public/engine/icb_merged_attributes.metal | 24 +- .../runtime_lane/render_merged_attributes.rs | 360 ++++++++++++------ crates/metal2vulkan/tests/api_signatures.tsv | 1 + crates/metal2vulkan/tests/api_surface.rs | 1 + docs/API.md | 11 +- 7 files changed, 561 insertions(+), 340 deletions(-) diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.air.ll b/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.air.ll index e1eec03ff..83ca4c609 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.air.ll +++ b/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.air.ll @@ -12,20 +12,20 @@ target triple = "air64_v28-apple-macosx26.0.0" ; Function Attrs: mustprogress nounwind willreturn define void @ima_draws(%struct.ImaCommands addrspace(1)* nocapture noundef readonly align 8 dereferenceable(8) "air-buffer-no-alias" %0, %struct.ImaDraw addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %1, i8 addrspace(1)* noundef "air-buffer-no-alias" %2, i8 addrspace(1)* noundef "air-buffer-no-alias" %3, <4 x float> addrspace(2)* noundef "air-buffer-no-alias" %4, i32 noundef %5) local_unnamed_addr #0 { %7 = getelementptr inbounds %struct.ImaCommands, %struct.ImaCommands addrspace(1)* %0, i64 0, i32 0, i32 0 - %8 = load %struct._command_buffer_t addrspace(1)*, %struct._command_buffer_t addrspace(1)* addrspace(1)* %7, align 8, !tbaa.struct !48, !alias.scope !53, !noalias !56 + %8 = load %struct._command_buffer_t addrspace(1)*, %struct._command_buffer_t addrspace(1)* addrspace(1)* %7, align 8, !tbaa.struct !49, !alias.scope !54, !noalias !57 %9 = zext i32 %5 to i64 %10 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 0 - %11 = load i32, i32 addrspace(1)* %10, align 4, !tbaa.struct !61, !alias.scope !64, !noalias !65 + %11 = load i32, i32 addrspace(1)* %10, align 4, !tbaa.struct !62, !alias.scope !65, !noalias !66 %12 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 1 - %13 = load i32, i32 addrspace(1)* %12, align 4, !tbaa.struct !66, !alias.scope !64, !noalias !65 + %13 = load i32, i32 addrspace(1)* %12, align 4, !tbaa.struct !67, !alias.scope !65, !noalias !66 %14 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 2 - %15 = load i32, i32 addrspace(1)* %14, align 4, !tbaa.struct !67, !alias.scope !64, !noalias !65 + %15 = load i32, i32 addrspace(1)* %14, align 4, !tbaa.struct !68, !alias.scope !65, !noalias !66 %16 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 4 - %17 = load i32, i32 addrspace(1)* %16, align 4, !tbaa.struct !68, !alias.scope !64, !noalias !65 + %17 = load i32, i32 addrspace(1)* %16, align 4, !tbaa.struct !69, !alias.scope !65, !noalias !66 %18 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 5 - %19 = load i32, i32 addrspace(1)* %18, align 4, !tbaa.struct !69, !alias.scope !64, !noalias !65 + %19 = load i32, i32 addrspace(1)* %18, align 4, !tbaa.struct !70, !alias.scope !65, !noalias !66 %20 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 6 - %21 = load i32, i32 addrspace(1)* %20, align 4, !tbaa.struct !70, !alias.scope !64, !noalias !65 + %21 = load i32, i32 addrspace(1)* %20, align 4, !tbaa.struct !71, !alias.scope !65, !noalias !66 %22 = zext i32 %19 to i64 %23 = getelementptr inbounds i8, i8 addrspace(1)* %2, i64 %22 tail call void @air.set_vertex_buffer_render_command.p1i8(%struct._command_buffer_t addrspace(1)* nocapture %8, i32 %5, i8 addrspace(1)* %23, i64 -1, i32 0) #5 @@ -38,25 +38,54 @@ define void @ima_draws(%struct.ImaCommands addrspace(1)* nocapture noundef reado ret void } +; Function Attrs: mustprogress nounwind willreturn +define void @ima_strips(%struct.ImaCommands addrspace(1)* nocapture noundef readonly align 8 dereferenceable(8) "air-buffer-no-alias" %0, %struct.ImaDraw addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %1, i8 addrspace(1)* noundef "air-buffer-no-alias" %2, i8 addrspace(1)* noundef "air-buffer-no-alias" %3, <4 x float> addrspace(2)* noundef "air-buffer-no-alias" %4, i32 noundef %5) local_unnamed_addr #0 { + %7 = getelementptr inbounds %struct.ImaCommands, %struct.ImaCommands addrspace(1)* %0, i64 0, i32 0, i32 0 + %8 = load %struct._command_buffer_t addrspace(1)*, %struct._command_buffer_t addrspace(1)* addrspace(1)* %7, align 8, !tbaa.struct !49, !alias.scope !72, !noalias !75 + %9 = zext i32 %5 to i64 + %10 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 0 + %11 = load i32, i32 addrspace(1)* %10, align 4, !tbaa.struct !62, !alias.scope !80, !noalias !81 + %12 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 1 + %13 = load i32, i32 addrspace(1)* %12, align 4, !tbaa.struct !67, !alias.scope !80, !noalias !81 + %14 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 2 + %15 = load i32, i32 addrspace(1)* %14, align 4, !tbaa.struct !68, !alias.scope !80, !noalias !81 + %16 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 4 + %17 = load i32, i32 addrspace(1)* %16, align 4, !tbaa.struct !69, !alias.scope !80, !noalias !81 + %18 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 5 + %19 = load i32, i32 addrspace(1)* %18, align 4, !tbaa.struct !70, !alias.scope !80, !noalias !81 + %20 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 6 + %21 = load i32, i32 addrspace(1)* %20, align 4, !tbaa.struct !71, !alias.scope !80, !noalias !81 + %22 = zext i32 %19 to i64 + %23 = getelementptr inbounds i8, i8 addrspace(1)* %2, i64 %22 + tail call void @air.set_vertex_buffer_render_command.p1i8(%struct._command_buffer_t addrspace(1)* nocapture %8, i32 %5, i8 addrspace(1)* %23, i64 -1, i32 0) #5 + %24 = zext i32 %21 to i64 + %25 = getelementptr inbounds i8, i8 addrspace(1)* %3, i64 %24 + tail call void @air.set_vertex_buffer_render_command.p1i8(%struct._command_buffer_t addrspace(1)* nocapture %8, i32 %5, i8 addrspace(1)* %25, i64 -1, i32 1) #5 + %26 = bitcast <4 x float> addrspace(2)* %4 to i8 addrspace(2)* + tail call void @air.set_vertex_buffer_render_command.p2i8(%struct._command_buffer_t addrspace(1)* nocapture %8, i32 %5, i8 addrspace(2)* %26, i64 -1, i32 2) #5 + tail call void @air.draw_primitives_render_command(%struct._command_buffer_t addrspace(1)* nocapture %8, i32 %5, i32 4, i32 %11, i32 %13, i32 %15, i32 %17) #5 + ret void +} + ; Function Attrs: mustprogress nounwind willreturn define void @ima_indexed(%struct.ImaCommands addrspace(1)* nocapture noundef readonly align 8 dereferenceable(8) "air-buffer-no-alias" %0, %struct.ImaDraw addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %1, i8 addrspace(1)* noundef "air-buffer-no-alias" %2, i8 addrspace(1)* noundef "air-buffer-no-alias" %3, <4 x float> addrspace(2)* noundef "air-buffer-no-alias" %4, i32 addrspace(1)* noundef "air-buffer-no-alias" %5, i32 noundef %6) local_unnamed_addr #0 { %8 = getelementptr inbounds %struct.ImaCommands, %struct.ImaCommands addrspace(1)* %0, i64 0, i32 0, i32 0 - %9 = load %struct._command_buffer_t addrspace(1)*, %struct._command_buffer_t addrspace(1)* addrspace(1)* %8, align 8, !tbaa.struct !48, !alias.scope !71, !noalias !74 + %9 = load %struct._command_buffer_t addrspace(1)*, %struct._command_buffer_t addrspace(1)* addrspace(1)* %8, align 8, !tbaa.struct !49, !alias.scope !82, !noalias !85 %10 = zext i32 %6 to i64 %11 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %10, i32 0 - %12 = load i32, i32 addrspace(1)* %11, align 4, !tbaa.struct !61, !alias.scope !80, !noalias !81 + %12 = load i32, i32 addrspace(1)* %11, align 4, !tbaa.struct !62, !alias.scope !91, !noalias !92 %13 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %10, i32 1 - %14 = load i32, i32 addrspace(1)* %13, align 4, !tbaa.struct !66, !alias.scope !80, !noalias !81 + %14 = load i32, i32 addrspace(1)* %13, align 4, !tbaa.struct !67, !alias.scope !91, !noalias !92 %15 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %10, i32 2 - %16 = load i32, i32 addrspace(1)* %15, align 4, !tbaa.struct !67, !alias.scope !80, !noalias !81 + %16 = load i32, i32 addrspace(1)* %15, align 4, !tbaa.struct !68, !alias.scope !91, !noalias !92 %17 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %10, i32 3 - %18 = load i32, i32 addrspace(1)* %17, align 4, !tbaa.struct !82, !alias.scope !80, !noalias !81 + %18 = load i32, i32 addrspace(1)* %17, align 4, !tbaa.struct !93, !alias.scope !91, !noalias !92 %19 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %10, i32 4 - %20 = load i32, i32 addrspace(1)* %19, align 4, !tbaa.struct !68, !alias.scope !80, !noalias !81 + %20 = load i32, i32 addrspace(1)* %19, align 4, !tbaa.struct !69, !alias.scope !91, !noalias !92 %21 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %10, i32 5 - %22 = load i32, i32 addrspace(1)* %21, align 4, !tbaa.struct !69, !alias.scope !80, !noalias !81 + %22 = load i32, i32 addrspace(1)* %21, align 4, !tbaa.struct !70, !alias.scope !91, !noalias !92 %23 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %10, i32 6 - %24 = load i32, i32 addrspace(1)* %23, align 4, !tbaa.struct !70, !alias.scope !80, !noalias !81 + %24 = load i32, i32 addrspace(1)* %23, align 4, !tbaa.struct !71, !alias.scope !91, !noalias !92 %25 = zext i32 %22 to i64 %26 = getelementptr inbounds i8, i8 addrspace(1)* %2, i64 %25 tail call void @air.set_vertex_buffer_render_command.p1i8(%struct._command_buffer_t addrspace(1)* nocapture %9, i32 %6, i8 addrspace(1)* %26, i64 -1, i32 0) #5 @@ -74,22 +103,22 @@ define void @ima_indexed(%struct.ImaCommands addrspace(1)* nocapture noundef rea ; Function Attrs: mustprogress nounwind willreturn define void @ima_strided(%struct.ImaCommands addrspace(1)* nocapture noundef readonly align 8 dereferenceable(8) "air-buffer-no-alias" %0, %struct.ImaDraw addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %1, i8 addrspace(1)* noundef "air-buffer-no-alias" %2, i8 addrspace(1)* noundef "air-buffer-no-alias" %3, <4 x float> addrspace(2)* noundef "air-buffer-no-alias" %4, i32 noundef %5) local_unnamed_addr #0 { %7 = getelementptr inbounds %struct.ImaCommands, %struct.ImaCommands addrspace(1)* %0, i64 0, i32 0, i32 0 - %8 = load %struct._command_buffer_t addrspace(1)*, %struct._command_buffer_t addrspace(1)* addrspace(1)* %7, align 8, !tbaa.struct !48, !alias.scope !83, !noalias !86 + %8 = load %struct._command_buffer_t addrspace(1)*, %struct._command_buffer_t addrspace(1)* addrspace(1)* %7, align 8, !tbaa.struct !49, !alias.scope !94, !noalias !97 %9 = zext i32 %5 to i64 %10 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 0 - %11 = load i32, i32 addrspace(1)* %10, align 4, !tbaa.struct !61, !alias.scope !91, !noalias !92 + %11 = load i32, i32 addrspace(1)* %10, align 4, !tbaa.struct !62, !alias.scope !102, !noalias !103 %12 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 1 - %13 = load i32, i32 addrspace(1)* %12, align 4, !tbaa.struct !66, !alias.scope !91, !noalias !92 + %13 = load i32, i32 addrspace(1)* %12, align 4, !tbaa.struct !67, !alias.scope !102, !noalias !103 %14 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 2 - %15 = load i32, i32 addrspace(1)* %14, align 4, !tbaa.struct !67, !alias.scope !91, !noalias !92 + %15 = load i32, i32 addrspace(1)* %14, align 4, !tbaa.struct !68, !alias.scope !102, !noalias !103 %16 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 4 - %17 = load i32, i32 addrspace(1)* %16, align 4, !tbaa.struct !68, !alias.scope !91, !noalias !92 + %17 = load i32, i32 addrspace(1)* %16, align 4, !tbaa.struct !69, !alias.scope !102, !noalias !103 %18 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 5 - %19 = load i32, i32 addrspace(1)* %18, align 4, !tbaa.struct !69, !alias.scope !91, !noalias !92 + %19 = load i32, i32 addrspace(1)* %18, align 4, !tbaa.struct !70, !alias.scope !102, !noalias !103 %20 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 6 - %21 = load i32, i32 addrspace(1)* %20, align 4, !tbaa.struct !70, !alias.scope !91, !noalias !92 + %21 = load i32, i32 addrspace(1)* %20, align 4, !tbaa.struct !71, !alias.scope !102, !noalias !103 %22 = getelementptr inbounds %struct.ImaDraw, %struct.ImaDraw addrspace(1)* %1, i64 %9, i32 7 - %23 = load i32, i32 addrspace(1)* %22, align 4, !tbaa.struct !93, !alias.scope !91, !noalias !92 + %23 = load i32, i32 addrspace(1)* %22, align 4, !tbaa.struct !104, !alias.scope !102, !noalias !103 %24 = zext i32 %19 to i64 %25 = getelementptr inbounds i8, i8 addrspace(1)* %2, i64 %24 %26 = zext i32 %23 to i64 @@ -106,7 +135,7 @@ define void @ima_strided(%struct.ImaCommands addrspace(1)* nocapture noundef rea ; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn define <{ <4 x float>, <4 x i32> }> @ima_vertex(<2 x float> %0, i32 %1, i32 noundef %2, i32 noundef %3, <4 x float> addrspace(2)* nocapture noundef readonly align 16 dereferenceable(16) "air-buffer-no-alias" %4) local_unnamed_addr #1 { %6 = tail call fast float @air.convert.f.f32.u.i32(i32 %3) #6 - %7 = load <4 x float>, <4 x float> addrspace(2)* %4, align 16, !alias.scope !94 + %7 = load <4 x float>, <4 x float> addrspace(2)* %4, align 16, !alias.scope !105 %8 = extractelement <4 x float> %7, i64 2 %9 = fmul fast float %8, %6 %10 = insertelement <2 x float> , float %9, i64 1 @@ -160,13 +189,13 @@ attributes #5 = { nounwind willreturn } attributes #6 = { nounwind readnone willreturn } !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} -!air.kernel = !{!9, !21, !25} -!air.vertex = !{!26} -!air.fragment = !{!36} -!air.compile_options = !{!42, !43, !44} -!llvm.ident = !{!45} -!air.version = !{!46} -!air.language_version = !{!47} +!air.kernel = !{!9, !21, !22, !26} +!air.vertex = !{!27} +!air.fragment = !{!37} +!air.compile_options = !{!43, !44, !45} +!llvm.ident = !{!46} +!air.version = !{!47} +!air.language_version = !{!48} !0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} !1 = !{i32 1, !"wchar_size", i32 4} @@ -189,79 +218,90 @@ attributes #6 = { nounwind readnone willreturn } !18 = !{i32 3, !"air.buffer", !"air.location_index", i32 3, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 1, !"air.arg_type_align_size", i32 1, !"air.arg_type_name", !"uchar", !"air.arg_name", !"marks"} !19 = !{i32 4, !"air.buffer", !"air.location_index", i32 4, 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"} !20 = !{i32 5, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} -!21 = !{void (%struct.ImaCommands addrspace(1)*, %struct.ImaDraw addrspace(1)*, i8 addrspace(1)*, i8 addrspace(1)*, <4 x float> addrspace(2)*, i32 addrspace(1)*, i32)* @ima_indexed, !10, !22} -!22 = !{!12, !15, !17, !18, !19, !23, !24} -!23 = !{i32 5, !"air.buffer", !"air.location_index", i32 5, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"indices"} -!24 = !{i32 6, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} -!25 = !{void (%struct.ImaCommands addrspace(1)*, %struct.ImaDraw addrspace(1)*, i8 addrspace(1)*, i8 addrspace(1)*, <4 x float> addrspace(2)*, i32)* @ima_strided, !10, !11} -!26 = !{<{ <4 x float>, <4 x i32> }> (<2 x float>, i32, i32, i32, <4 x float> addrspace(2)*)* @ima_vertex, !27, !30} -!27 = !{!28, !29} -!28 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} -!29 = !{!"air.vertex_output", !"generated(3idsDv4_j)", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"} -!30 = !{!31, !32, !33, !34, !35} -!31 = !{i32 0, !"air.vertex_input", !"air.location_index", i32 0, i32 1, !"air.arg_type_name", !"float2", !"air.arg_name", !"xy"} -!32 = !{i32 1, !"air.vertex_input", !"air.location_index", i32 1, i32 1, !"air.arg_type_name", !"uint", !"air.arg_name", !"mark"} -!33 = !{i32 2, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"} -!34 = !{i32 3, !"air.instance_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} -!35 = !{i32 4, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 2, 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"} -!36 = !{<4 x i32> (<4 x float>, <4 x i32>)* @ima_fragment, !37, !39} -!37 = !{!38} -!38 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"} -!39 = !{!40, !41} -!40 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"} -!41 = !{i32 1, !"air.fragment_input", !"generated(3idsDv4_j)", !"air.flat", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"} -!42 = !{!"air.compile.denorms_disable"} -!43 = !{!"air.compile.fast_math_enable"} -!44 = !{!"air.compile.framebuffer_fetch_enable"} -!45 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} -!46 = !{i32 2, i32 8, i32 0} -!47 = !{!"Metal", i32 4, i32 0, i32 0} -!48 = !{i64 0, i64 8, !49} -!49 = !{!50, !50, i64 0} -!50 = !{!"__metal_command_buffer_t", !51, i64 0} -!51 = !{!"omnipotent char", !52, i64 0} -!52 = !{!"Simple C++ TBAA"} -!53 = !{!54} -!54 = distinct !{!54, !55, !"air-alias-scope-arg(0)"} -!55 = distinct !{!55, !"air-alias-scopes(ima_draws)"} -!56 = !{!57, !58, !59, !60} -!57 = distinct !{!57, !55, !"air-alias-scope-arg(1)"} -!58 = distinct !{!58, !55, !"air-alias-scope-arg(2)"} -!59 = distinct !{!59, !55, !"air-alias-scope-arg(3)"} -!60 = distinct !{!60, !55, !"air-alias-scope-arg(4)"} -!61 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62, i64 16, i64 4, !62, i64 20, i64 4, !62, i64 24, i64 4, !62, i64 28, i64 4, !62} -!62 = !{!63, !63, i64 0} -!63 = !{!"int", !51, i64 0} -!64 = !{!57} -!65 = !{!54, !58, !59, !60} -!66 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62, i64 16, i64 4, !62, i64 20, i64 4, !62, i64 24, i64 4, !62} -!67 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62, i64 16, i64 4, !62, i64 20, i64 4, !62} -!68 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62} -!69 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62} -!70 = !{i64 0, i64 4, !62, i64 4, i64 4, !62} -!71 = !{!72} -!72 = distinct !{!72, !73, !"air-alias-scope-arg(0)"} -!73 = distinct !{!73, !"air-alias-scopes(ima_indexed)"} -!74 = !{!75, !76, !77, !78, !79} -!75 = distinct !{!75, !73, !"air-alias-scope-arg(1)"} -!76 = distinct !{!76, !73, !"air-alias-scope-arg(2)"} -!77 = distinct !{!77, !73, !"air-alias-scope-arg(3)"} -!78 = distinct !{!78, !73, !"air-alias-scope-arg(4)"} -!79 = distinct !{!79, !73, !"air-alias-scope-arg(5)"} -!80 = !{!75} -!81 = !{!72, !76, !77, !78, !79} -!82 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62, i64 16, i64 4, !62} -!83 = !{!84} -!84 = distinct !{!84, !85, !"air-alias-scope-arg(0)"} -!85 = distinct !{!85, !"air-alias-scopes(ima_strided)"} -!86 = !{!87, !88, !89, !90} -!87 = distinct !{!87, !85, !"air-alias-scope-arg(1)"} -!88 = distinct !{!88, !85, !"air-alias-scope-arg(2)"} -!89 = distinct !{!89, !85, !"air-alias-scope-arg(3)"} -!90 = distinct !{!90, !85, !"air-alias-scope-arg(4)"} -!91 = !{!87} -!92 = !{!84, !88, !89, !90} -!93 = !{i64 0, i64 4, !62} +!21 = !{void (%struct.ImaCommands addrspace(1)*, %struct.ImaDraw addrspace(1)*, i8 addrspace(1)*, i8 addrspace(1)*, <4 x float> addrspace(2)*, i32)* @ima_strips, !10, !11} +!22 = !{void (%struct.ImaCommands addrspace(1)*, %struct.ImaDraw addrspace(1)*, i8 addrspace(1)*, i8 addrspace(1)*, <4 x float> addrspace(2)*, i32 addrspace(1)*, i32)* @ima_indexed, !10, !23} +!23 = !{!12, !15, !17, !18, !19, !24, !25} +!24 = !{i32 5, !"air.buffer", !"air.location_index", i32 5, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"indices"} +!25 = !{i32 6, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} +!26 = !{void (%struct.ImaCommands addrspace(1)*, %struct.ImaDraw addrspace(1)*, i8 addrspace(1)*, i8 addrspace(1)*, <4 x float> addrspace(2)*, i32)* @ima_strided, !10, !11} +!27 = !{<{ <4 x float>, <4 x i32> }> (<2 x float>, i32, i32, i32, <4 x float> addrspace(2)*)* @ima_vertex, !28, !31} +!28 = !{!29, !30} +!29 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!30 = !{!"air.vertex_output", !"generated(3idsDv4_j)", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"} +!31 = !{!32, !33, !34, !35, !36} +!32 = !{i32 0, !"air.vertex_input", !"air.location_index", i32 0, i32 1, !"air.arg_type_name", !"float2", !"air.arg_name", !"xy"} +!33 = !{i32 1, !"air.vertex_input", !"air.location_index", i32 1, i32 1, !"air.arg_type_name", !"uint", !"air.arg_name", !"mark"} +!34 = !{i32 2, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"} +!35 = !{i32 3, !"air.instance_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} +!36 = !{i32 4, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 2, 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"} +!37 = !{<4 x i32> (<4 x float>, <4 x i32>)* @ima_fragment, !38, !40} +!38 = !{!39} +!39 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"} +!40 = !{!41, !42} +!41 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"} +!42 = !{i32 1, !"air.fragment_input", !"generated(3idsDv4_j)", !"air.flat", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"} +!43 = !{!"air.compile.denorms_disable"} +!44 = !{!"air.compile.fast_math_enable"} +!45 = !{!"air.compile.framebuffer_fetch_enable"} +!46 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!47 = !{i32 2, i32 8, i32 0} +!48 = !{!"Metal", i32 4, i32 0, i32 0} +!49 = !{i64 0, i64 8, !50} +!50 = !{!51, !51, i64 0} +!51 = !{!"__metal_command_buffer_t", !52, i64 0} +!52 = !{!"omnipotent char", !53, i64 0} +!53 = !{!"Simple C++ TBAA"} +!54 = !{!55} +!55 = distinct !{!55, !56, !"air-alias-scope-arg(0)"} +!56 = distinct !{!56, !"air-alias-scopes(ima_draws)"} +!57 = !{!58, !59, !60, !61} +!58 = distinct !{!58, !56, !"air-alias-scope-arg(1)"} +!59 = distinct !{!59, !56, !"air-alias-scope-arg(2)"} +!60 = distinct !{!60, !56, !"air-alias-scope-arg(3)"} +!61 = distinct !{!61, !56, !"air-alias-scope-arg(4)"} +!62 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63, i64 16, i64 4, !63, i64 20, i64 4, !63, i64 24, i64 4, !63, i64 28, i64 4, !63} +!63 = !{!64, !64, i64 0} +!64 = !{!"int", !52, i64 0} +!65 = !{!58} +!66 = !{!55, !59, !60, !61} +!67 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63, i64 16, i64 4, !63, i64 20, i64 4, !63, i64 24, i64 4, !63} +!68 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63, i64 16, i64 4, !63, i64 20, i64 4, !63} +!69 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63} +!70 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63} +!71 = !{i64 0, i64 4, !63, i64 4, i64 4, !63} +!72 = !{!73} +!73 = distinct !{!73, !74, !"air-alias-scope-arg(0)"} +!74 = distinct !{!74, !"air-alias-scopes(ima_strips)"} +!75 = !{!76, !77, !78, !79} +!76 = distinct !{!76, !74, !"air-alias-scope-arg(1)"} +!77 = distinct !{!77, !74, !"air-alias-scope-arg(2)"} +!78 = distinct !{!78, !74, !"air-alias-scope-arg(3)"} +!79 = distinct !{!79, !74, !"air-alias-scope-arg(4)"} +!80 = !{!76} +!81 = !{!73, !77, !78, !79} +!82 = !{!83} +!83 = distinct !{!83, !84, !"air-alias-scope-arg(0)"} +!84 = distinct !{!84, !"air-alias-scopes(ima_indexed)"} +!85 = !{!86, !87, !88, !89, !90} +!86 = distinct !{!86, !84, !"air-alias-scope-arg(1)"} +!87 = distinct !{!87, !84, !"air-alias-scope-arg(2)"} +!88 = distinct !{!88, !84, !"air-alias-scope-arg(3)"} +!89 = distinct !{!89, !84, !"air-alias-scope-arg(4)"} +!90 = distinct !{!90, !84, !"air-alias-scope-arg(5)"} +!91 = !{!86} +!92 = !{!83, !87, !88, !89, !90} +!93 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63, i64 16, i64 4, !63} !94 = !{!95} -!95 = distinct !{!95, !96, !"air-alias-scope-arg(4)"} -!96 = distinct !{!96, !"air-alias-scopes(ima_vertex)"} +!95 = distinct !{!95, !96, !"air-alias-scope-arg(0)"} +!96 = distinct !{!96, !"air-alias-scopes(ima_strided)"} +!97 = !{!98, !99, !100, !101} +!98 = distinct !{!98, !96, !"air-alias-scope-arg(1)"} +!99 = distinct !{!99, !96, !"air-alias-scope-arg(2)"} +!100 = distinct !{!100, !96, !"air-alias-scope-arg(3)"} +!101 = distinct !{!101, !96, !"air-alias-scope-arg(4)"} +!102 = !{!98} +!103 = !{!95, !99, !100, !101} +!104 = !{i64 0, i64 4, !63} +!105 = !{!106} +!106 = distinct !{!106, !107, !"air-alias-scope-arg(4)"} +!107 = distinct !{!107, !"air-alias-scopes(ima_vertex)"} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.ll b/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.ll index c17c5c8f3..d2519f79c 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.ll +++ b/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.ll @@ -11,20 +11,20 @@ target triple = "air64_v28-apple-macosx26.0.0" ; Function Attrs: mustprogress nounwind willreturn define void @ima_draws(ptr addrspace(1) noundef readonly align 8 captures(none) dereferenceable(8) "air-buffer-no-alias" %0, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %1, ptr addrspace(1) noundef "air-buffer-no-alias" %2, ptr addrspace(1) noundef "air-buffer-no-alias" %3, ptr addrspace(2) noundef "air-buffer-no-alias" %4, i32 noundef %5) local_unnamed_addr #0 { %7 = getelementptr inbounds %struct.ImaCommands, ptr addrspace(1) %0, i64 0, i32 0, i32 0 - %8 = load ptr addrspace(1), ptr addrspace(1) %7, align 8, !tbaa.struct !48, !alias.scope !53, !noalias !56 + %8 = load ptr addrspace(1), ptr addrspace(1) %7, align 8, !tbaa.struct !49, !alias.scope !54, !noalias !57 %9 = zext i32 %5 to i64 %10 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 0 - %11 = load i32, ptr addrspace(1) %10, align 4, !tbaa.struct !61, !alias.scope !64, !noalias !65 + %11 = load i32, ptr addrspace(1) %10, align 4, !tbaa.struct !62, !alias.scope !65, !noalias !66 %12 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 1 - %13 = load i32, ptr addrspace(1) %12, align 4, !tbaa.struct !66, !alias.scope !64, !noalias !65 + %13 = load i32, ptr addrspace(1) %12, align 4, !tbaa.struct !67, !alias.scope !65, !noalias !66 %14 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 2 - %15 = load i32, ptr addrspace(1) %14, align 4, !tbaa.struct !67, !alias.scope !64, !noalias !65 + %15 = load i32, ptr addrspace(1) %14, align 4, !tbaa.struct !68, !alias.scope !65, !noalias !66 %16 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 4 - %17 = load i32, ptr addrspace(1) %16, align 4, !tbaa.struct !68, !alias.scope !64, !noalias !65 + %17 = load i32, ptr addrspace(1) %16, align 4, !tbaa.struct !69, !alias.scope !65, !noalias !66 %18 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 5 - %19 = load i32, ptr addrspace(1) %18, align 4, !tbaa.struct !69, !alias.scope !64, !noalias !65 + %19 = load i32, ptr addrspace(1) %18, align 4, !tbaa.struct !70, !alias.scope !65, !noalias !66 %20 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 6 - %21 = load i32, ptr addrspace(1) %20, align 4, !tbaa.struct !70, !alias.scope !64, !noalias !65 + %21 = load i32, ptr addrspace(1) %20, align 4, !tbaa.struct !71, !alias.scope !65, !noalias !66 %22 = zext i32 %19 to i64 %23 = getelementptr inbounds i8, ptr addrspace(1) %2, i64 %22 tail call void @air.set_vertex_buffer_render_command.p1i8(ptr addrspace(1) captures(none) %8, i32 %5, ptr addrspace(1) %23, i64 -1, i32 0) #5 @@ -37,25 +37,54 @@ define void @ima_draws(ptr addrspace(1) noundef readonly align 8 captures(none) ret void } +; Function Attrs: mustprogress nounwind willreturn +define void @ima_strips(ptr addrspace(1) noundef readonly align 8 captures(none) dereferenceable(8) "air-buffer-no-alias" %0, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %1, ptr addrspace(1) noundef "air-buffer-no-alias" %2, ptr addrspace(1) noundef "air-buffer-no-alias" %3, ptr addrspace(2) noundef "air-buffer-no-alias" %4, i32 noundef %5) local_unnamed_addr #0 { + %7 = getelementptr inbounds %struct.ImaCommands, ptr addrspace(1) %0, i64 0, i32 0, i32 0 + %8 = load ptr addrspace(1), ptr addrspace(1) %7, align 8, !tbaa.struct !49, !alias.scope !72, !noalias !75 + %9 = zext i32 %5 to i64 + %10 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 0 + %11 = load i32, ptr addrspace(1) %10, align 4, !tbaa.struct !62, !alias.scope !80, !noalias !81 + %12 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 1 + %13 = load i32, ptr addrspace(1) %12, align 4, !tbaa.struct !67, !alias.scope !80, !noalias !81 + %14 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 2 + %15 = load i32, ptr addrspace(1) %14, align 4, !tbaa.struct !68, !alias.scope !80, !noalias !81 + %16 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 4 + %17 = load i32, ptr addrspace(1) %16, align 4, !tbaa.struct !69, !alias.scope !80, !noalias !81 + %18 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 5 + %19 = load i32, ptr addrspace(1) %18, align 4, !tbaa.struct !70, !alias.scope !80, !noalias !81 + %20 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 6 + %21 = load i32, ptr addrspace(1) %20, align 4, !tbaa.struct !71, !alias.scope !80, !noalias !81 + %22 = zext i32 %19 to i64 + %23 = getelementptr inbounds i8, ptr addrspace(1) %2, i64 %22 + tail call void @air.set_vertex_buffer_render_command.p1i8(ptr addrspace(1) captures(none) %8, i32 %5, ptr addrspace(1) %23, i64 -1, i32 0) #5 + %24 = zext i32 %21 to i64 + %25 = getelementptr inbounds i8, ptr addrspace(1) %3, i64 %24 + tail call void @air.set_vertex_buffer_render_command.p1i8(ptr addrspace(1) captures(none) %8, i32 %5, ptr addrspace(1) %25, i64 -1, i32 1) #5 + %26 = bitcast ptr addrspace(2) %4 to ptr addrspace(2) + tail call void @air.set_vertex_buffer_render_command.p2i8(ptr addrspace(1) captures(none) %8, i32 %5, ptr addrspace(2) %26, i64 -1, i32 2) #5 + tail call void @air.draw_primitives_render_command(ptr addrspace(1) captures(none) %8, i32 %5, i32 4, i32 %11, i32 %13, i32 %15, i32 %17) #5 + ret void +} + ; Function Attrs: mustprogress nounwind willreturn define void @ima_indexed(ptr addrspace(1) noundef readonly align 8 captures(none) dereferenceable(8) "air-buffer-no-alias" %0, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %1, ptr addrspace(1) noundef "air-buffer-no-alias" %2, ptr addrspace(1) noundef "air-buffer-no-alias" %3, ptr addrspace(2) noundef "air-buffer-no-alias" %4, ptr addrspace(1) noundef "air-buffer-no-alias" %5, i32 noundef %6) local_unnamed_addr #0 { %8 = getelementptr inbounds %struct.ImaCommands, ptr addrspace(1) %0, i64 0, i32 0, i32 0 - %9 = load ptr addrspace(1), ptr addrspace(1) %8, align 8, !tbaa.struct !48, !alias.scope !71, !noalias !74 + %9 = load ptr addrspace(1), ptr addrspace(1) %8, align 8, !tbaa.struct !49, !alias.scope !82, !noalias !85 %10 = zext i32 %6 to i64 %11 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %10, i32 0 - %12 = load i32, ptr addrspace(1) %11, align 4, !tbaa.struct !61, !alias.scope !80, !noalias !81 + %12 = load i32, ptr addrspace(1) %11, align 4, !tbaa.struct !62, !alias.scope !91, !noalias !92 %13 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %10, i32 1 - %14 = load i32, ptr addrspace(1) %13, align 4, !tbaa.struct !66, !alias.scope !80, !noalias !81 + %14 = load i32, ptr addrspace(1) %13, align 4, !tbaa.struct !67, !alias.scope !91, !noalias !92 %15 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %10, i32 2 - %16 = load i32, ptr addrspace(1) %15, align 4, !tbaa.struct !67, !alias.scope !80, !noalias !81 + %16 = load i32, ptr addrspace(1) %15, align 4, !tbaa.struct !68, !alias.scope !91, !noalias !92 %17 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %10, i32 3 - %18 = load i32, ptr addrspace(1) %17, align 4, !tbaa.struct !82, !alias.scope !80, !noalias !81 + %18 = load i32, ptr addrspace(1) %17, align 4, !tbaa.struct !93, !alias.scope !91, !noalias !92 %19 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %10, i32 4 - %20 = load i32, ptr addrspace(1) %19, align 4, !tbaa.struct !68, !alias.scope !80, !noalias !81 + %20 = load i32, ptr addrspace(1) %19, align 4, !tbaa.struct !69, !alias.scope !91, !noalias !92 %21 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %10, i32 5 - %22 = load i32, ptr addrspace(1) %21, align 4, !tbaa.struct !69, !alias.scope !80, !noalias !81 + %22 = load i32, ptr addrspace(1) %21, align 4, !tbaa.struct !70, !alias.scope !91, !noalias !92 %23 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %10, i32 6 - %24 = load i32, ptr addrspace(1) %23, align 4, !tbaa.struct !70, !alias.scope !80, !noalias !81 + %24 = load i32, ptr addrspace(1) %23, align 4, !tbaa.struct !71, !alias.scope !91, !noalias !92 %25 = zext i32 %22 to i64 %26 = getelementptr inbounds i8, ptr addrspace(1) %2, i64 %25 tail call void @air.set_vertex_buffer_render_command.p1i8(ptr addrspace(1) captures(none) %9, i32 %6, ptr addrspace(1) %26, i64 -1, i32 0) #5 @@ -73,22 +102,22 @@ define void @ima_indexed(ptr addrspace(1) noundef readonly align 8 captures(none ; Function Attrs: mustprogress nounwind willreturn define void @ima_strided(ptr addrspace(1) noundef readonly align 8 captures(none) dereferenceable(8) "air-buffer-no-alias" %0, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %1, ptr addrspace(1) noundef "air-buffer-no-alias" %2, ptr addrspace(1) noundef "air-buffer-no-alias" %3, ptr addrspace(2) noundef "air-buffer-no-alias" %4, i32 noundef %5) local_unnamed_addr #0 { %7 = getelementptr inbounds %struct.ImaCommands, ptr addrspace(1) %0, i64 0, i32 0, i32 0 - %8 = load ptr addrspace(1), ptr addrspace(1) %7, align 8, !tbaa.struct !48, !alias.scope !83, !noalias !86 + %8 = load ptr addrspace(1), ptr addrspace(1) %7, align 8, !tbaa.struct !49, !alias.scope !94, !noalias !97 %9 = zext i32 %5 to i64 %10 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 0 - %11 = load i32, ptr addrspace(1) %10, align 4, !tbaa.struct !61, !alias.scope !91, !noalias !92 + %11 = load i32, ptr addrspace(1) %10, align 4, !tbaa.struct !62, !alias.scope !102, !noalias !103 %12 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 1 - %13 = load i32, ptr addrspace(1) %12, align 4, !tbaa.struct !66, !alias.scope !91, !noalias !92 + %13 = load i32, ptr addrspace(1) %12, align 4, !tbaa.struct !67, !alias.scope !102, !noalias !103 %14 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 2 - %15 = load i32, ptr addrspace(1) %14, align 4, !tbaa.struct !67, !alias.scope !91, !noalias !92 + %15 = load i32, ptr addrspace(1) %14, align 4, !tbaa.struct !68, !alias.scope !102, !noalias !103 %16 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 4 - %17 = load i32, ptr addrspace(1) %16, align 4, !tbaa.struct !68, !alias.scope !91, !noalias !92 + %17 = load i32, ptr addrspace(1) %16, align 4, !tbaa.struct !69, !alias.scope !102, !noalias !103 %18 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 5 - %19 = load i32, ptr addrspace(1) %18, align 4, !tbaa.struct !69, !alias.scope !91, !noalias !92 + %19 = load i32, ptr addrspace(1) %18, align 4, !tbaa.struct !70, !alias.scope !102, !noalias !103 %20 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 6 - %21 = load i32, ptr addrspace(1) %20, align 4, !tbaa.struct !70, !alias.scope !91, !noalias !92 + %21 = load i32, ptr addrspace(1) %20, align 4, !tbaa.struct !71, !alias.scope !102, !noalias !103 %22 = getelementptr inbounds %struct.ImaDraw, ptr addrspace(1) %1, i64 %9, i32 7 - %23 = load i32, ptr addrspace(1) %22, align 4, !tbaa.struct !93, !alias.scope !91, !noalias !92 + %23 = load i32, ptr addrspace(1) %22, align 4, !tbaa.struct !104, !alias.scope !102, !noalias !103 %24 = zext i32 %19 to i64 %25 = getelementptr inbounds i8, ptr addrspace(1) %2, i64 %24 %26 = zext i32 %23 to i64 @@ -105,7 +134,7 @@ define void @ima_strided(ptr addrspace(1) noundef readonly align 8 captures(none ; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) define <{ <4 x float>, <4 x i32> }> @ima_vertex(<2 x float> %0, i32 %1, i32 noundef %2, i32 noundef %3, ptr addrspace(2) noundef readonly align 16 captures(none) dereferenceable(16) "air-buffer-no-alias" %4) local_unnamed_addr #1 { %6 = tail call fast float @air.convert.f.f32.u.i32(i32 %3) #6 - %7 = load <4 x float>, ptr addrspace(2) %4, align 16, !alias.scope !94 + %7 = load <4 x float>, ptr addrspace(2) %4, align 16, !alias.scope !105 %8 = extractelement <4 x float> %7, i64 2 %9 = fmul fast float %8, %6 %10 = insertelement <2 x float> , float %9, i64 1 @@ -159,13 +188,13 @@ attributes #5 = { nounwind willreturn } attributes #6 = { nounwind willreturn memory(none) } !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} -!air.kernel = !{!9, !21, !25} -!air.vertex = !{!26} -!air.fragment = !{!36} -!air.compile_options = !{!42, !43, !44} -!llvm.ident = !{!45} -!air.version = !{!46} -!air.language_version = !{!47} +!air.kernel = !{!9, !21, !22, !26} +!air.vertex = !{!27} +!air.fragment = !{!37} +!air.compile_options = !{!43, !44, !45} +!llvm.ident = !{!46} +!air.version = !{!47} +!air.language_version = !{!48} !0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} !1 = !{i32 1, !"wchar_size", i32 4} @@ -188,79 +217,90 @@ attributes #6 = { nounwind willreturn memory(none) } !18 = !{i32 3, !"air.buffer", !"air.location_index", i32 3, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 1, !"air.arg_type_align_size", i32 1, !"air.arg_type_name", !"uchar", !"air.arg_name", !"marks"} !19 = !{i32 4, !"air.buffer", !"air.location_index", i32 4, 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"} !20 = !{i32 5, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} -!21 = !{ptr @ima_indexed, !10, !22} -!22 = !{!12, !15, !17, !18, !19, !23, !24} -!23 = !{i32 5, !"air.buffer", !"air.location_index", i32 5, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"indices"} -!24 = !{i32 6, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} -!25 = !{ptr @ima_strided, !10, !11} -!26 = !{ptr @ima_vertex, !27, !30} -!27 = !{!28, !29} -!28 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} -!29 = !{!"air.vertex_output", !"generated(3idsDv4_j)", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"} -!30 = !{!31, !32, !33, !34, !35} -!31 = !{i32 0, !"air.vertex_input", !"air.location_index", i32 0, i32 1, !"air.arg_type_name", !"float2", !"air.arg_name", !"xy"} -!32 = !{i32 1, !"air.vertex_input", !"air.location_index", i32 1, i32 1, !"air.arg_type_name", !"uint", !"air.arg_name", !"mark"} -!33 = !{i32 2, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"} -!34 = !{i32 3, !"air.instance_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} -!35 = !{i32 4, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 2, 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"} -!36 = !{ptr @ima_fragment, !37, !39} -!37 = !{!38} -!38 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"} -!39 = !{!40, !41} -!40 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"} -!41 = !{i32 1, !"air.fragment_input", !"generated(3idsDv4_j)", !"air.flat", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"} -!42 = !{!"air.compile.denorms_disable"} -!43 = !{!"air.compile.fast_math_enable"} -!44 = !{!"air.compile.framebuffer_fetch_enable"} -!45 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} -!46 = !{i32 2, i32 8, i32 0} -!47 = !{!"Metal", i32 4, i32 0, i32 0} -!48 = !{i64 0, i64 8, !49} -!49 = !{!50, !50, i64 0} -!50 = !{!"__metal_command_buffer_t", !51, i64 0} -!51 = !{!"omnipotent char", !52, i64 0} -!52 = !{!"Simple C++ TBAA"} -!53 = !{!54} -!54 = distinct !{!54, !55, !"air-alias-scope-arg(0)"} -!55 = distinct !{!55, !"air-alias-scopes(ima_draws)"} -!56 = !{!57, !58, !59, !60} -!57 = distinct !{!57, !55, !"air-alias-scope-arg(1)"} -!58 = distinct !{!58, !55, !"air-alias-scope-arg(2)"} -!59 = distinct !{!59, !55, !"air-alias-scope-arg(3)"} -!60 = distinct !{!60, !55, !"air-alias-scope-arg(4)"} -!61 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62, i64 16, i64 4, !62, i64 20, i64 4, !62, i64 24, i64 4, !62, i64 28, i64 4, !62} -!62 = !{!63, !63, i64 0} -!63 = !{!"int", !51, i64 0} -!64 = !{!57} -!65 = !{!54, !58, !59, !60} -!66 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62, i64 16, i64 4, !62, i64 20, i64 4, !62, i64 24, i64 4, !62} -!67 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62, i64 16, i64 4, !62, i64 20, i64 4, !62} -!68 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62} -!69 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62} -!70 = !{i64 0, i64 4, !62, i64 4, i64 4, !62} -!71 = !{!72} -!72 = distinct !{!72, !73, !"air-alias-scope-arg(0)"} -!73 = distinct !{!73, !"air-alias-scopes(ima_indexed)"} -!74 = !{!75, !76, !77, !78, !79} -!75 = distinct !{!75, !73, !"air-alias-scope-arg(1)"} -!76 = distinct !{!76, !73, !"air-alias-scope-arg(2)"} -!77 = distinct !{!77, !73, !"air-alias-scope-arg(3)"} -!78 = distinct !{!78, !73, !"air-alias-scope-arg(4)"} -!79 = distinct !{!79, !73, !"air-alias-scope-arg(5)"} -!80 = !{!75} -!81 = !{!72, !76, !77, !78, !79} -!82 = !{i64 0, i64 4, !62, i64 4, i64 4, !62, i64 8, i64 4, !62, i64 12, i64 4, !62, i64 16, i64 4, !62} -!83 = !{!84} -!84 = distinct !{!84, !85, !"air-alias-scope-arg(0)"} -!85 = distinct !{!85, !"air-alias-scopes(ima_strided)"} -!86 = !{!87, !88, !89, !90} -!87 = distinct !{!87, !85, !"air-alias-scope-arg(1)"} -!88 = distinct !{!88, !85, !"air-alias-scope-arg(2)"} -!89 = distinct !{!89, !85, !"air-alias-scope-arg(3)"} -!90 = distinct !{!90, !85, !"air-alias-scope-arg(4)"} -!91 = !{!87} -!92 = !{!84, !88, !89, !90} -!93 = !{i64 0, i64 4, !62} +!21 = !{ptr @ima_strips, !10, !11} +!22 = !{ptr @ima_indexed, !10, !23} +!23 = !{!12, !15, !17, !18, !19, !24, !25} +!24 = !{i32 5, !"air.buffer", !"air.location_index", i32 5, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"indices"} +!25 = !{i32 6, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} +!26 = !{ptr @ima_strided, !10, !11} +!27 = !{ptr @ima_vertex, !28, !31} +!28 = !{!29, !30} +!29 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!30 = !{!"air.vertex_output", !"generated(3idsDv4_j)", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"} +!31 = !{!32, !33, !34, !35, !36} +!32 = !{i32 0, !"air.vertex_input", !"air.location_index", i32 0, i32 1, !"air.arg_type_name", !"float2", !"air.arg_name", !"xy"} +!33 = !{i32 1, !"air.vertex_input", !"air.location_index", i32 1, i32 1, !"air.arg_type_name", !"uint", !"air.arg_name", !"mark"} +!34 = !{i32 2, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"} +!35 = !{i32 3, !"air.instance_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"iid"} +!36 = !{i32 4, !"air.buffer", !"air.buffer_size", i32 16, !"air.location_index", i32 2, 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"} +!37 = !{ptr @ima_fragment, !38, !40} +!38 = !{!39} +!39 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"} +!40 = !{!41, !42} +!41 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position", !"air.arg_unused"} +!42 = !{i32 1, !"air.fragment_input", !"generated(3idsDv4_j)", !"air.flat", !"air.arg_type_name", !"uint4", !"air.arg_name", !"ids"} +!43 = !{!"air.compile.denorms_disable"} +!44 = !{!"air.compile.fast_math_enable"} +!45 = !{!"air.compile.framebuffer_fetch_enable"} +!46 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!47 = !{i32 2, i32 8, i32 0} +!48 = !{!"Metal", i32 4, i32 0, i32 0} +!49 = !{i64 0, i64 8, !50} +!50 = !{!51, !51, i64 0} +!51 = !{!"__metal_command_buffer_t", !52, i64 0} +!52 = !{!"omnipotent char", !53, i64 0} +!53 = !{!"Simple C++ TBAA"} +!54 = !{!55} +!55 = distinct !{!55, !56, !"air-alias-scope-arg(0)"} +!56 = distinct !{!56, !"air-alias-scopes(ima_draws)"} +!57 = !{!58, !59, !60, !61} +!58 = distinct !{!58, !56, !"air-alias-scope-arg(1)"} +!59 = distinct !{!59, !56, !"air-alias-scope-arg(2)"} +!60 = distinct !{!60, !56, !"air-alias-scope-arg(3)"} +!61 = distinct !{!61, !56, !"air-alias-scope-arg(4)"} +!62 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63, i64 16, i64 4, !63, i64 20, i64 4, !63, i64 24, i64 4, !63, i64 28, i64 4, !63} +!63 = !{!64, !64, i64 0} +!64 = !{!"int", !52, i64 0} +!65 = !{!58} +!66 = !{!55, !59, !60, !61} +!67 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63, i64 16, i64 4, !63, i64 20, i64 4, !63, i64 24, i64 4, !63} +!68 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63, i64 16, i64 4, !63, i64 20, i64 4, !63} +!69 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63} +!70 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63} +!71 = !{i64 0, i64 4, !63, i64 4, i64 4, !63} +!72 = !{!73} +!73 = distinct !{!73, !74, !"air-alias-scope-arg(0)"} +!74 = distinct !{!74, !"air-alias-scopes(ima_strips)"} +!75 = !{!76, !77, !78, !79} +!76 = distinct !{!76, !74, !"air-alias-scope-arg(1)"} +!77 = distinct !{!77, !74, !"air-alias-scope-arg(2)"} +!78 = distinct !{!78, !74, !"air-alias-scope-arg(3)"} +!79 = distinct !{!79, !74, !"air-alias-scope-arg(4)"} +!80 = !{!76} +!81 = !{!73, !77, !78, !79} +!82 = !{!83} +!83 = distinct !{!83, !84, !"air-alias-scope-arg(0)"} +!84 = distinct !{!84, !"air-alias-scopes(ima_indexed)"} +!85 = !{!86, !87, !88, !89, !90} +!86 = distinct !{!86, !84, !"air-alias-scope-arg(1)"} +!87 = distinct !{!87, !84, !"air-alias-scope-arg(2)"} +!88 = distinct !{!88, !84, !"air-alias-scope-arg(3)"} +!89 = distinct !{!89, !84, !"air-alias-scope-arg(4)"} +!90 = distinct !{!90, !84, !"air-alias-scope-arg(5)"} +!91 = !{!86} +!92 = !{!83, !87, !88, !89, !90} +!93 = !{i64 0, i64 4, !63, i64 4, i64 4, !63, i64 8, i64 4, !63, i64 12, i64 4, !63, i64 16, i64 4, !63} !94 = !{!95} -!95 = distinct !{!95, !96, !"air-alias-scope-arg(4)"} -!96 = distinct !{!96, !"air-alias-scopes(ima_vertex)"} +!95 = distinct !{!95, !96, !"air-alias-scope-arg(0)"} +!96 = distinct !{!96, !"air-alias-scopes(ima_strided)"} +!97 = !{!98, !99, !100, !101} +!98 = distinct !{!98, !96, !"air-alias-scope-arg(1)"} +!99 = distinct !{!99, !96, !"air-alias-scope-arg(2)"} +!100 = distinct !{!100, !96, !"air-alias-scope-arg(3)"} +!101 = distinct !{!101, !96, !"air-alias-scope-arg(4)"} +!102 = !{!98} +!103 = !{!95, !99, !100, !101} +!104 = !{i64 0, i64 4, !63} +!105 = !{!106} +!106 = distinct !{!106, !107, !"air-alias-scope-arg(4)"} +!107 = distinct !{!107, !"air-alias-scopes(ima_vertex)"} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.metal b/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.metal index 05ec56c1a..1cb7d2782 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.metal +++ b/crates/metal2vulkan-validation/fixtures/public/engine/icb_merged_attributes.metal @@ -2,10 +2,11 @@ // a kernel encodes into an indirect command buffer and a render pass executes. Each kernel encodes // command `tid` from `draws[tid]`: vertex buffer 0 the vertices' pixel positions from byte // `xy_at` of `xy`, vertex buffer 1 the marks from byte `mark_at` of `marks`, vertex buffer 2 the -// frame, then a triangle draw: `ima_draws` of `count` vertices from vertex `first`, -// `ima_indexed` of `count` 32-bit indices from index `first` at base vertex `base_vertex`, and -// `ima_strided` as `ima_draws` with vertex buffer 0 bound at attribute stride `stride`; each of -// `instances` instances from base instance `base_instance`. The case's vertex descriptor places +// frame, then a draw: `ima_draws` of triangles, `count` vertices from vertex `first`, +// `ima_strips` the same as a triangle strip, `ima_indexed` of triangles, `count` 32-bit indices +// from index `first` at base vertex `base_vertex`, and `ima_strided` as `ima_draws` with vertex +// buffer 0 bound at attribute stride `stride`; each of `instances` instances from base instance +// `base_instance`. The case's vertex descriptor places // attribute 0 (a `float2` pixel position) in layout 0 and attribute 1 (a `uint` mark) in layout 1. // Vertex `vid` of instance `iid` lies at its position moved down `iid` rows of `frame.z` pixels // (`frame` is the target's width, height and row stride in pixels) and carries its mark, `vid` @@ -56,6 +57,21 @@ kernel void ima_draws(device const ImaCommands &encoder [[buffer(0)]], d.base_instance); } +kernel void ima_strips(device const ImaCommands &encoder [[buffer(0)]], + device const ImaDraw *draws [[buffer(1)]], + device const uchar *xy [[buffer(2)]], + device const uchar *marks [[buffer(3)]], + constant float4 *frame [[buffer(4)]], + uint tid [[thread_position_in_grid]]) { + render_command command(encoder.commands, tid); + ImaDraw d = draws[tid]; + command.set_vertex_buffer(xy + d.xy_at, 0); + command.set_vertex_buffer(marks + d.mark_at, 1); + command.set_vertex_buffer(frame, 2); + command.draw_primitives(primitive_type::triangle_strip, d.first, d.count, d.instances, + d.base_instance); +} + kernel void ima_indexed(device const ImaCommands &encoder [[buffer(0)]], device const ImaDraw *draws [[buffer(1)]], device const uchar *xy [[buffer(2)]], diff --git a/crates/metal2vulkan-validation/src/runtime_lane/render_merged_attributes.rs b/crates/metal2vulkan-validation/src/runtime_lane/render_merged_attributes.rs index 44b2514a6..ed0015f56 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/render_merged_attributes.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/render_merged_attributes.rs @@ -7,11 +7,14 @@ //! the mark, `vid` and `iid` flat into a `RGBA32Uint` target, and writes no memory, and its //! fragment function reads no buffer. //! -//! - Where every attribute is fetched in the shader (each layout's stride one fixed-function input -//! cannot align), draws and indexed draws of triangles draw what the host step draws of them, -//! which a barrier the CPU set and cleared sends them to: each vertex its command's own vertex -//! and instance, from its command's own buffers. The replay variant refuses a vertex function -//! that fetches attributes (`LoweringInputs::replay_bindings`), so both take the host step. +//! A draw replay pulls every layout fixed-function input would fetch +//! (`bind::draw_replay_vertex_layouts`), and a pulled attribute reads its command's buffer, so +//! draws and indexed draws of triangles run as one merged draw and triangle strips as one draw +//! per command, on the GPU alone, and draw what the host step draws of them (a barrier the CPU +//! set and cleared sends them there): each vertex its command's own vertex and instance, from its +//! command's own buffers. So do layouts whose strides fixed-function input cannot align, which +//! the shader fetches anyway, and a per-instance layout of a step rate of 2. A layout whose stride +//! is set per bind, which each command binds at its own, keeps the host step. use super::degrade_notices::{counts, on_device_with}; use super::indirect_host_steps::{complete, HOST_STEPS}; @@ -29,8 +32,8 @@ use metal2vulkan::pipeline::{ }; use metal2vulkan_devtools::{engine_dir, llvm_assemble}; use metal2vulkan_runtime::{ - Buffer, ClearColor, ComputePipelineState, Device, IndirectCommandBufferDescriptor, Library, - LoadAction, PipelineOptions, Region, RenderPassDescriptor, RenderPipelineState, + Buffer, ClearColor, ComputePipelineState, Degradation, Device, IndirectCommandBufferDescriptor, + Library, LoadAction, PipelineOptions, Region, RenderPassDescriptor, RenderPipelineState, ResourceOptions, Size, StoreAction, Texture, TextureDescriptor, }; use std::collections::BTreeSet; @@ -41,9 +44,55 @@ const H: u64 = 48; const ROW: f32 = 8.0; /// The buffer's commands. const COMMANDS: u64 = 4; -/// A stride of layout 0 (a `float2` position) and of layout 1 (a `uint` mark) that -/// fixed-function input cannot align: the shader fetches both attributes. -const PULLED_STRIDES: (u32, u32) = (10, 6); + +/// The state's vertex layouts and how the buffers lay their elements out. +#[derive(Clone, Copy, Debug)] +struct Layouts { + /// Layout 0's stride, a `float2` position (`None`: set per bind, which `ima_strided` binds at + /// `xy`). + positions: Option, + /// The bytes from one position to the next. + xy: u32, + /// Layout 1's stride, a `uint` mark per instance, and its step rate. + marks: u32, + rate: u32, +} + +/// Strides fixed-function input cannot align: the shader fetches both attributes. +const PULLED: Layouts = Layouts { + positions: Some(10), + xy: 10, + marks: 6, + rate: 1, +}; + +/// Strides fixed-function input fetches, marks at step rate `rate`. +const fn fixed(rate: u32) -> Layouts { + Layouts { + positions: Some(8), + xy: 8, + marks: 4, + rate, + } +} + +/// Positions at a stride each command binds at its own. +const PER_BIND: Layouts = Layouts { + positions: None, + xy: 8, + marks: 4, + rate: 1, +}; + +/// A writer kernel: its name, the commands' type, whether it draws indexed, and whether its +/// commands merge into one draw (a list type) or draw one draw each (a strip). +type Kernel = (&'static str, IndirectCommandType, bool, bool); + +const KERNELS: [Kernel; 3] = [ + ("ima_draws", IndirectCommandType::DRAW, false, true), + ("ima_strips", IndirectCommandType::DRAW, false, false), + ("ima_indexed", IndirectCommandType::DRAW_INDEXED, true, true), +]; /// A command's draw: first vertex (or first index), vertex (or index) count, instance count, base /// vertex, base instance, the byte offsets of its positions and its marks, and the stride its @@ -71,14 +120,14 @@ fn writer(device: &Device, library: &Library, name: &str) -> ComputePipelineStat .unwrap() } -/// The vertex descriptor of positions at stride `strides.0` and per-instance marks at stride -/// `strides.1`, each at offset 0 of its layout. -fn vertex_descriptor(strides: (u32, u32)) -> VertexDescriptor { +/// The vertex descriptor of `layouts`, each attribute at offset 0 of its layout. +fn vertex_descriptor(layouts: Layouts) -> VertexDescriptor { let mut v = VertexDescriptor::new(); v.layouts - .insert(0, VertexBufferLayoutDescriptor::new(Some(strides.0))); - let mut marks = VertexBufferLayoutDescriptor::new(Some(strides.1)); + .insert(0, VertexBufferLayoutDescriptor::new(layouts.positions)); + let mut marks = VertexBufferLayoutDescriptor::new(Some(layouts.marks)); marks.step_function = VertexStepFunction::PerInstance; + marks.step_rate = layouts.rate; v.layouts.insert(1, marks); v.attributes.insert( 0, @@ -89,15 +138,17 @@ fn vertex_descriptor(strides: (u32, u32)) -> VertexDescriptor { v } -/// The descriptor of the commands' state, with `supportIndirectCommandBuffers`. -fn state_descriptor(library: &Library, strides: (u32, u32)) -> RenderPipelineDescriptor { +/// The commands' state of `layouts`, with `supportIndirectCommandBuffers`. +fn state(device: &Device, library: &Library, layouts: Layouts) -> RenderPipelineState { let stage = |name: &str| StageSource::Function(function(library, name)); let mut descriptor = RenderPipelineDescriptor::new(stage("ima_vertex")); descriptor.fragment = Some(stage("ima_fragment")); descriptor.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); - descriptor.vertex_descriptor = Some(vertex_descriptor(strides)); + descriptor.vertex_descriptor = Some(vertex_descriptor(layouts)); descriptor.support_indirect_command_buffers = true; - descriptor + device + .new_render_pipeline_state(&descriptor, &PipelineOptions::default()) + .unwrap() } /// Draws of `command_types` of three vertex buffers that inherit the encoder's state. @@ -172,14 +223,63 @@ fn pixels(target: &Texture) -> Vec<[u32; 4]> { .collect() } +/// The commands' rows: first vertex, count, instances, base vertex (indexed), base instance, the +/// positions' element offset, the marks' element offset. Triangle 0; triangle 3 in two instances +/// from 1; triangles 5 and 6 at instance 3; triangle 7 in two instances. Each command's positions +/// and marks start at its own offset, so its first vertex, base vertex and base instance name +/// elements past them; no two commands' pixels meet. +const ROWS: [[u32; 7]; COMMANDS as usize] = [ + [0, 3, 1, 0, 0, 0, 0], + [7, 3, 2, 4, 1, 2, 0], + [9, 6, 1, 0, 3, 6, 2], + [21, 3, 2, 6, 0, 0, 6], +]; + +/// The draws of [`ROWS`] laid out as `layouts` lays the buffers out. Indexed (`indexed`), the +/// indices count from 0 and a command's first index and base vertex add to the vertex start of +/// its draw without indices. +fn draws(indexed: bool, layouts: Layouts) -> Vec { + ROWS.iter() + .map( + |&[first, count, instances, base_vertex, base_instance, xy_at, mark_at]| { + let (first, base_vertex) = match indexed { + true => (first - base_vertex, base_vertex), + false => (first, 0), + }; + [ + first, + count, + instances, + base_vertex, + base_instance, + xy_at * layouts.xy, + mark_at * layouts.marks, + layouts.xy, + ] + }, + ) + .collect() +} + +/// The marks [`ROWS`]' instances fetch at step rate `rate`: Metal's element `base + (instance - +/// base) / rate` of each command's marks, mark `100 + j` at element `j` of the buffer. +fn marks(rate: u32) -> BTreeSet { + ROWS.iter() + .flat_map(|&[_, _, instances, _, base, _, mark_at]| { + (0..instances).map(move |i| 100 + mark_at + base + i / rate) + }) + .collect() +} + /// Run `writer` writing `draws` (of `command_types`) into a new buffer of [`COMMANDS`] commands (a /// barrier the CPU set and cleared in its last command where `host_step`), positions and marks -/// laid out at `strides`, then a pass that executes all of them: the target's pixels, and the -/// merged draws' commands, the GPU form's and the records the host read across the run. +/// laid out as `layouts` lays them, then a pass of `state` that executes all of them: the +/// target's pixels, and the merged draws' commands, the GPU form's and the records the host read +/// across the run. fn run( device: &Device, (writer, state): (&ComputePipelineState, &RenderPipelineState), - (command_types, draws, strides, host_step): (IndirectCommandType, &[Draw], (u32, u32), bool), + (command_types, draws, layouts, host_step): (IndirectCommandType, &[Draw], Layouts, bool), ) -> (Vec<[u32; 4]>, (u64, u64, u64)) { let icb = icb(device, &inheriting(command_types), COMMANDS); if host_step { @@ -192,8 +292,8 @@ fn run( let buffers: [Buffer; 6] = [ buffer_with(device, &icb.gpu_resource_id().0.to_le_bytes()).unwrap(), buffer_with(device, &words(draws.iter().flatten().copied())).unwrap(), - buffer_with(device, &strided(positions, strides.0)).unwrap(), - buffer_with(device, &strided(marks, strides.1)).unwrap(), + buffer_with(device, &strided(positions, layouts.xy)).unwrap(), + buffer_with(device, &strided(marks, layouts.marks)).unwrap(), buffer_with(device, &floats([W as f32, H as f32, ROW, 0.0])).unwrap(), buffer_with(device, &words(0..48)).unwrap(), ]; @@ -244,109 +344,125 @@ fn run( (pixels(&target), counted) } -/// The draws of [`run`]: triangle 0; triangle 3 in two instances from 1; triangles 5 and 6 at -/// instance 3; triangle 7 in two instances. Each command's positions and marks start at its own -/// offset, so its first vertex, base vertex and base instance name elements past them; no two -/// commands' pixels meet. Indexed (`indexed`), the indices count from 0 and a command's first -/// index and base vertex add to the vertex start of its draw without indices. -fn draws(indexed: bool, strides: (u32, u32)) -> Vec { - let (xy, mark) = strides; - // First vertex, count, instances, base vertex (indexed), base instance, the positions' - // element offset, the marks' element offset. - let rows: [[u32; 7]; COMMANDS as usize] = [ - [0, 3, 1, 0, 0, 0, 0], - [7, 3, 2, 4, 1, 2, 0], - [9, 6, 1, 0, 3, 6, 2], - [21, 3, 2, 6, 0, 0, 6], - ]; - rows.iter() - .map( - |&[first, count, instances, base_vertex, base_instance, xy_at, mark_at]| { - let (first, base_vertex) = match indexed { - true => (first - base_vertex, base_vertex), - false => (first, 0), - }; - [ - first, - count, - instances, - base_vertex, - base_instance, - xy_at * xy, - mark_at * mark, - xy, - ] - }, - ) - .collect() +/// The marks the covered pixels of `drawn` carry. +fn drawn_marks(drawn: &[[u32; 4]]) -> BTreeSet { + drawn.iter().map(|p| p[0]).filter(|&m| m != 0).collect() } -/// The marks of [`draws`]' instances: element `base instance + instance` of each command's marks. -const MARKS: [u32; 6] = [100, 101, 102, 105, 106, 107]; - -/// Draws and indexed draws of triangles whose vertex function fetches both its attributes in the -/// shader, positions per vertex and marks per instance (each layout's stride one fixed-function -/// input cannot align, so no layout is bound in fixed function), draw what the host step draws of -/// them: each vertex fetches its command's own vertex (its vertex start or its index plus its base -/// vertex) and instance (its base instance plus the instance), from its command's own buffers. -/// Both take the host step: the replay variant refuses a vertex function that fetches attributes. -#[test] -fn pulled_attributes_of_executed_draws_draw_what_the_host_step_draws() { - on_device_with(at_plan, |device, messages| { - let library = library(device); - let state = device - .new_render_pipeline_state( - &state_descriptor(&library, PULLED_STRIDES), - &PipelineOptions::default(), - ) - .unwrap(); - for (kernel, command_types, indexed) in [ - ("ima_draws", IndirectCommandType::DRAW, false), - ("ima_indexed", IndirectCommandType::DRAW_INDEXED, true), - ] { - let writer = writer(device, &library, kernel); - let draws = draws(indexed, PULLED_STRIDES); - let mut outputs = Vec::new(); - let mut forms = Vec::new(); - for host_step in [false, true] { - let (drawn, counted) = run( - device, - (&writer, &state), - (command_types, &draws, PULLED_STRIDES, host_step), - ); - outputs.push(drawn); - forms.push(counted); - } - let marks: BTreeSet = outputs[1] +/// Each of [`KERNELS`] under the state of `layouts` on `device`: its execution runs on the GPU +/// alone (merged, or one draw per command), the host reading no record, and draws what the host +/// step draws of it, each instance its own mark. +fn replayed_as_the_host_step_draws(device: &Device, layouts: Layouts) { + let library = library(device); + let state = state(device, &library, layouts); + for (kernel, command_types, indexed, merges) in KERNELS { + let writer = writer(device, &library, kernel); + let draws = draws(indexed, layouts); + let mut outputs = Vec::new(); + let mut forms = Vec::new(); + for host_step in [false, true] { + let (drawn, counted) = run( + device, + (&writer, &state), + (command_types, &draws, layouts, host_step), + ); + outputs.push(drawn); + forms.push(counted); + } + let what = format!("{kernel} {layouts:?}"); + assert_eq!( + drawn_marks(&outputs[1]), + marks(layouts.rate), + "{what}: each instance's own mark in the host step" + ); + assert!( + outputs[0] == outputs[1], + "{what}: the execution ({:?}) against the host step: {:?}", + forms[0], + outputs[0] .iter() - .map(|p| p[0]) - .filter(|&m| m != 0) - .collect(); - assert_eq!( - marks, - BTreeSet::from(MARKS), - "{kernel}: each instance's own mark in the host step" - ); - assert!( - outputs[0] == outputs[1], - "{kernel}: the execution ({:?}) against the host step: {:?}", - forms[0], - outputs[0] - .iter() - .zip(&outputs[1]) - .enumerate() - .filter(|(_, (m, h))| m != h) - .take(8) - .collect::>() - ); - for &(merged, gpu, read) in &forms { - assert!( - merged == 0 && gpu == 0 && read >= COMMANDS, - "{kernel}: the host step {forms:?}" - ); - } + .zip(&outputs[1]) + .enumerate() + .filter(|(_, (m, h))| m != h) + .take(8) + .collect::>() + ); + let merged = if merges { COMMANDS } else { 0 }; + assert_eq!(forms[0], (merged, COMMANDS, 0), "{what}: on the GPU alone"); + let (merged, gpu, read) = forms[1]; + assert!( + merged == 0 && gpu == 0 && read >= COMMANDS, + "{what}: the host step {:?}", + forms[1] + ); + } +} + +/// Draws, strips and indexed draws whose vertex function fetches both its attributes in the +/// shader, positions per vertex and marks per instance (each layout's stride one fixed-function +/// input cannot align), run on the GPU alone and draw what the host step draws of them: each +/// vertex fetches its command's own vertex (its vertex start or its index plus its base vertex) +/// and instance (its base instance plus the instance), from its command's own buffers, merged +/// draws included, whose own vertex and instance indices count the merged draw's corners. +#[test] +fn pulled_attributes_of_executed_draws_fetch_their_commands_elements() { + on_device_with(at_plan, |device, messages| { + replayed_as_the_host_step_draws(device, PULLED); + let notices = counts(&messages.take_notices()); + assert!(notices.contains_key(&HOST_STEPS[0]), "{notices:?}"); + }); +} + +/// Layouts fixed-function input would fetch, marks at step rates 1 and 2, are pulled in a draw +/// replay (`bind::draw_replay_vertex_layouts`) with no vertex buffer bound at the encoder: the +/// executions run on the GPU alone and draw what the host step draws of them, a rate of 2 +/// dividing each command's instances from its base instance. +#[test] +fn fixed_function_layouts_of_executed_draws_are_pulled() { + on_device_with(at_plan, |device, messages| { + for rate in [1, 2] { + replayed_as_the_host_step_draws(device, fixed(rate)); } let notices = counts(&messages.take_notices()); assert!(notices.contains_key(&HOST_STEPS[0]), "{notices:?}"); }); } + +/// A layout whose stride is set per bind, which each command binds at its own (`ima_strided`), +/// keeps its execution from the GPU: the host step draws it, each instance its own mark, and the +/// device's notice names the rule (`DrawReplayRule::VertexAttributes`). +#[test] +fn a_layout_of_a_stride_set_per_bind_keeps_the_host_step() { + on_device_with(at_plan, |device, messages| { + let library = library(device); + let state = state(device, &library, PER_BIND); + let writer = writer(device, &library, "ima_strided"); + let draws = draws(false, PER_BIND); + let (drawn, (merged, gpu, read)) = run( + device, + (&writer, &state), + (IndirectCommandType::DRAW, &draws, PER_BIND, false), + ); + assert!( + merged == 0 && gpu == 0 && read >= COMMANDS, + "the host step: {merged} {gpu} {read}" + ); + assert_eq!(drawn_marks(&drawn), marks(1)); + let notices = messages.take_notices(); + let host_step = notices + .iter() + .find(|m| { + m.degradation + .as_ref() + .is_some_and(|d| d.degradation == Degradation::HostReplayedIndirectCommands) + }) + .expect("the host step's notice"); + assert!( + host_step + .text + .contains("vertex function fetches attributes at a stride set per bind"), + "{}", + host_step.text + ); + }); +} diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 85a07ac2a..ab8b38f42 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -5162,6 +5162,7 @@ fn metal2vulkan::bind::draw_replay_preprocess pub fn draw_replay_preprocess(devi fn metal2vulkan::bind::draw_replay_primitive_type pub fn draw_replay_primitive_type(command_types: IndirectCommandType, (inherit_pipeline_state, inherit_buffers): (bool, bool), written: CommandWrites) -> Result fn metal2vulkan::bind::draw_replay_slots pub fn draw_replay_slots(interface: &PipelineInterface) -> (u32, u32) fn metal2vulkan::bind::draw_replay_state pub fn draw_replay_state(graphics: &GraphicsState, merged: bool) -> Result<(), DrawReplayRule> +fn metal2vulkan::bind::draw_replay_vertex_layouts pub fn draw_replay_vertex_layouts(input: &VertexInputState) -> Result, DrawReplayRule> fn metal2vulkan::bind::dynamic_views_module pub fn dynamic_views_module(device: &Device) -> Result fn metal2vulkan::bind::etc_decode_module pub fn etc_decode_module(device: &Device, decode: EtcDecode, texels: EtcTexels) -> Result fn metal2vulkan::bind::extended_canonical_module pub fn extended_canonical_module(device: &Device) -> Result diff --git a/crates/metal2vulkan/tests/api_surface.rs b/crates/metal2vulkan/tests/api_surface.rs index c60d23217..e4022267b 100644 --- a/crates/metal2vulkan/tests/api_surface.rs +++ b/crates/metal2vulkan/tests/api_surface.rs @@ -605,6 +605,7 @@ surface! { fn draw_replay_primitive_type; fn draw_replay_slots; fn draw_replay_state; + fn draw_replay_vertex_layouts; enum DrawReplayRule N; const DRAW_REPLAY_WRITES; fn draw_merge_module; diff --git a/docs/API.md b/docs/API.md index c9683ff0e..3151cbbaf 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1563,7 +1563,12 @@ the device has it (`replay_preprocess_generated`). Draws of primitives under the pipeline replay on the device through `draw_replay_preprocess`: one indirect draw per command and primitive type the execution names, the pipeline compiled as its replay variant (`VariantKey::replay_bindings`), whose vertex and fragment functions read each command's buffers -from the slot tables the preprocess writes. Draws of one list type or points whose fragment function +from the slot tables the preprocess writes. The variant pulls every layout fixed-function vertex +input would fetch (`draw_replay_vertex_layouts`, named in the shape's `far_vertex_buffers`: the +pulled-vertex-buffer variant, no buffer bound there), so each attribute reads its command's buffer +at the command's own vertex and instance; a layout whose stride is set per bind keeps an +execution off the device (`DrawReplayRule::VertexAttributes`), since each command binds its own +stride. Draws of one list type or points whose fragment function reads no buffer and no `[[primitive_id]]` may instead merge into one draw (`DrawReplay::merged`): two merge passes (`draw_merge_module`) write each command's first vertex in the merged draw, and the vertex function, compiled as its merged variant (`VariantKey::merged_draws`), finds its @@ -4838,7 +4843,9 @@ each item named states the rule in full. - **Render commands the GPU may write run on the GPU alone** where the commit can tell from what the records may hold (`IndirectCommandBuffer::command_writes`) that every command is a draw of one primitive type under the encoder's pipeline state, which the buffer inherits with none of its - buffers: one indirect draw per command, in order, from what a preprocess wrote; and where the + buffers, and whose vertex function fetches no attribute of a layout whose stride is set per bind + (the commands bind their own buffers, which the GPU form fetches each attribute from in the + shader): one indirect draw per command, in order, from what a preprocess wrote; and where the commands draw points, lines or triangles, the state's vertex function writes no memory and its fragment function reads no buffer and no `[[primitive_id]]`, one merged draw for the whole range, in the commands' order, whatever its count (`WorkCounts::merged_draw_commands`). Otherwise, and