diff --git a/crates/metal2vulkan-conformance/probes/rate_map_integer_overloads.m b/crates/metal2vulkan-conformance/probes/rate_map_integer_overloads.m new file mode 100644 index 000000000..7adacf82c --- /dev/null +++ b/crates/metal2vulkan-conformance/probes/rate_map_integer_overloads.m @@ -0,0 +1,182 @@ +// What plain Metal answers for the `uint2` overloads of `rasterization_rate_map_decoder`'s +// `map_screen_to_physical_coordinates` and `map_physical_to_screen_coordinates`, beside the `float2` +// ones at the same coordinates and the map's own CPU answers, along each axis of four maps: 64 by 64 +// of quality 1; 256 by 128 falling to 0.25; 200 by 96 of two layers; 3648 by 1734 falling to 0.3. +// Each axis is walked at every integer coordinate from 0 to 48 past the larger of its screen and +// physical extents (the other axis held at a third of its screen), at each of the map's layers and +// two past them, which read their horizontal tables unclamped. +// +// Build (no cargo target needed): +// clang -fobjc-arc -O1 -fmodules -o rate_map_integer_overloads rate_map_integer_overloads.m \ +// -framework Foundation -framework Metal +// +// Run without `MTL_DEBUG_LAYER`. It prints the device and release, then per map a line +// `MAP x layers layer physical x size ` per layer, the parameter +// data's six tables of 1026 words (`WORDS : `, hex), and per layer, axis +// and coordinate `c`: +// +// ROW | | | +// | | | | cpu | +// +// `crates/metal2vulkan/src/bind/rate_map/apple_integer_vectors.txt` is a sample of its output on an +// Apple M3 Max under macOS 27.0.1. The reading it measured (`rate_map_data`, **Decoding**): the +// `uint2` screen-to-physical answer is the `float2` decoder's at `c + 1/2`, converted to `uint`; +// the `uint2` physical-to-screen answer is the bits of the `float` `(0 - offset) * reciprocal` of +// the entry of granule `c >> 5`, the coordinate's value unread. + +#import +#import +#include + +static NSString *const kSource = @ + "#include \n" + "using namespace metal;\n" + "kernel void probe(constant rasterization_rate_map_data &map [[buffer(0)]],\n" + " device uint *out [[buffer(1)]],\n" + " constant uint4 &args [[buffer(2)]],\n" + " uint tid [[thread_position_in_grid]]) {\n" + " rasterization_rate_map_decoder d(map);\n" + " uint2 c = args.z == 0 ? uint2(tid, args.y) : uint2(args.x, tid);\n" + " uint2 a = d.map_screen_to_physical_coordinates(c, args.w);\n" + " uint2 b = d.map_physical_to_screen_coordinates(c, args.w);\n" + " float2 fc = float2(c);\n" + " float2 f0 = d.map_screen_to_physical_coordinates(fc + 0.5f, args.w);\n" + " float2 f1 = d.map_physical_to_screen_coordinates(fc + 0.5f, args.w);\n" + " float2 f2 = d.map_physical_to_screen_coordinates(fc, args.w);\n" + " float2 f3 = d.map_screen_to_physical_coordinates(fc, args.w);\n" + " device uint *o = out + tid * 12;\n" + " o[0] = a.x; o[1] = a.y; o[2] = b.x; o[3] = b.y;\n" + " o[4] = as_type(f0.x); o[5] = as_type(f0.y);\n" + " o[6] = as_type(f1.x); o[7] = as_type(f1.y);\n" + " o[8] = as_type(f2.x); o[9] = as_type(f2.y);\n" + " o[10] = as_type(f3.x); o[11] = as_type(f3.y);\n" + "}\n"; + +static float bits(uint32_t w) { + float f; + memcpy(&f, &w, 4); + return f; +} + +typedef struct { + const char *name; + NSUInteger w, h; + int layers; + int hn[2], vn[2]; + float hq[2][8], vq[2][8]; +} MapSpec; + +static void run(id dev, id pso, id q, + const MapSpec *spec) { + NSMutableArray *layers = [NSMutableArray array]; + for (int l = 0; l < spec->layers; l++) { + MTLRasterizationRateLayerDescriptor *ld = [[MTLRasterizationRateLayerDescriptor alloc] + initWithSampleCount:MTLSizeMake(spec->hn[l], spec->vn[l], 0)]; + for (int i = 0; i < spec->hn[l]; i++) ld.horizontalSampleStorage[i] = spec->hq[l][i]; + for (int i = 0; i < spec->vn[l]; i++) ld.verticalSampleStorage[i] = spec->vq[l][i]; + [layers addObject:ld]; + } + // The array form wants a C array of pointers. + MTLRasterizationRateLayerDescriptor *arr[2] = {nil, nil}; + for (int l = 0; l < spec->layers; l++) arr[l] = layers[l]; + MTLRasterizationRateMapDescriptor *d = [MTLRasterizationRateMapDescriptor rasterizationRateMapDescriptorWithScreenSize: + MTLSizeMake(spec->w, spec->h, 1) + layerCount:spec->layers + layers:arr]; + id map = [dev newRasterizationRateMapWithDescriptor:d]; + if (!map) { + printf("MAP %s nil\n", spec->name); + return; + } + MTLSizeAndAlign sa = map.parameterBufferSizeAndAlign; + id params = [dev newBufferWithLength:sa.size options:MTLResourceStorageModeShared]; + [map copyParameterDataToBuffer:params offset:0]; + for (int l = 0; l < spec->layers; l++) { + MTLSize p = [map physicalSizeForLayer:l]; + printf("MAP %s %lux%lu layers %d layer %d physical %lux%lu size %lu\n", spec->name, + (unsigned long)spec->w, (unsigned long)spec->h, spec->layers, l, + (unsigned long)p.width, (unsigned long)p.height, (unsigned long)sa.size); + } + const uint32_t *words = params.contents; + NSUInteger nwords = sa.size / 4; + // Each table, of 1026 words. + for (NSUInteger t = 0; t < 6; t++) { + NSUInteger at = t * 1026; + printf("WORDS %s %lu:", spec->name, (unsigned long)at); + for (NSUInteger i = 0; i < 1026 && at + i < nwords; i++) printf(" %08x", words[at + i]); + printf("\n"); + } + // Two layers past the map's too: the decoders read their horizontal tables unclamped. + for (int l = 0; l < spec->layers + 2; l++) { + MTLSize phys = [map physicalSizeForLayer:(l < spec->layers ? l : 0)]; + for (uint32_t axis = 0; axis < 2; axis++) { + NSUInteger extent = axis == 0 ? spec->w : spec->h; + NSUInteger pext = axis == 0 ? phys.width : phys.height; + NSUInteger n = (extent > pext ? extent : pext) + 48; + uint32_t other = axis == 0 ? (uint32_t)(spec->h / 3) : (uint32_t)(spec->w / 3); + uint32_t args[4] = {other, other, axis, (uint32_t)l}; + id out = [dev newBufferWithLength:n * 12 * 4 options:MTLResourceStorageModeShared]; + memset(out.contents, 0xab, n * 12 * 4); + id cb = [q commandBuffer]; + id e = [cb computeCommandEncoder]; + [e setComputePipelineState:pso]; + [e setBuffer:params offset:0 atIndex:0]; + [e setBuffer:out offset:0 atIndex:1]; + [e setBytes:args length:sizeof args atIndex:2]; + [e dispatchThreads:MTLSizeMake(n, 1, 1) threadsPerThreadgroup:MTLSizeMake(32, 1, 1)]; + [e endEncoding]; + [cb commit]; + [cb waitUntilCompleted]; + if (cb.error) { + printf("ERROR %s\n", cb.error.localizedDescription.UTF8String); + return; + } + const uint32_t *o = out.contents; + for (NSUInteger c = 0; c < n; c++) { + const uint32_t *r = o + c * 12; + MTLCoordinate2D sc = MTLCoordinate2DMake(axis == 0 ? c + 0.5f : other + 0.5f, + axis == 0 ? other + 0.5f : c + 0.5f); + int cl = l < spec->layers ? l : 0; + MTLCoordinate2D cs = [map mapScreenToPhysicalCoordinates:sc forLayer:cl]; + MTLCoordinate2D cp = [map mapPhysicalToScreenCoordinates:sc forLayer:cl]; + printf("ROW %s %d %u %lu | %u %u | %u %u | %.9g %.9g | %.9g %.9g | %.9g %.9g | %.9g " + "%.9g | cpu %.9g %.9g | %.9g %.9g\n", + spec->name, l, axis, (unsigned long)c, r[0], r[1], r[2], r[3], bits(r[4]), + bits(r[5]), bits(r[6]), bits(r[7]), bits(r[8]), bits(r[9]), bits(r[10]), + bits(r[11]), cs.x, cs.y, cp.x, cp.y); + } + } + } +} + +int main(void) { + @autoreleasepool { + id dev = MTLCreateSystemDefaultDevice(); + printf("DEVICE %s / RELEASE %s\n", dev.name.UTF8String, + NSProcessInfo.processInfo.operatingSystemVersionString.UTF8String); + NSError *err = nil; + id lib = [dev newLibraryWithSource:kSource options:nil error:&err]; + if (!lib) { + printf("COMPILE %s\n", err.localizedDescription.UTF8String); + return 1; + } + id pso = + [dev newComputePipelineStateWithFunction:[lib newFunctionWithName:@"probe"] error:&err]; + if (!pso) { + printf("PIPELINE %s\n", err.localizedDescription.UTF8String); + return 1; + } + id q = [dev newCommandQueue]; + MapSpec specs[] = { + {"uniform", 64, 64, 1, {1, 0}, {1, 0}, {{1.0f}}, {{1.0f}}}, + {"falling", 256, 128, 1, {4, 0}, {2, 0}, {{1.0f, 0.5f, 0.25f, 0.5f}}, {{0.5f, 1.0f}}}, + {"twolayer", 200, 96, 2, {2, 3}, {2, 2}, + {{1.0f, 0.3f}, {0.3f, 1.0f, 0.6f}}, {{1.0f, 0.4f}, {0.7f, 0.2f}}}, + {"large", 3648, 1734, 1, {5, 0}, {5, 0}, {{0.3f, 0.6f, 1.0f, 0.6f, 0.3f}}, + {{0.3f, 0.6f, 1.0f, 0.6f, 0.3f}}}, + }; + for (size_t i = 0; i < sizeof specs / sizeof specs[0]; i++) run(dev, pso, q, &specs[i]); + printf("DONE\n"); + } + return 0; +} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN index 4add4b0ff..c63750e90 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN +++ b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN @@ -277,6 +277,7 @@ fixture psc_sample_coverage: metal: Apple metal version 32023.921 (metalfe-32023 fixture pull_model_interpolants: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture px_edges: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture px_samplers: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) +fixture rate_map_integer: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture rch_guarded_effects: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture rch_helper_branch: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture rch_helper_select: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/rate_map_integer.air.ll b/crates/metal2vulkan-validation/fixtures/public/engine/rate_map_integer.air.ll new file mode 100644 index 000000000..a086b6d98 --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/rate_map_integer.air.ll @@ -0,0 +1,112 @@ +; Generated by scripts/regen-air-fixtures from rate_map_integer.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.metal::rasterization_rate_map_data" = type opaque + +; Function Attrs: argmemonly mustprogress nofree nounwind willreturn +define void @rate_map_integer(%"struct.metal::rasterization_rate_map_data" addrspace(2)* noundef align 1 "air-buffer-no-alias" %0, <2 x i32> addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %1, <4 x i32> addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %2, i32 addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %3, i32 noundef %4) local_unnamed_addr #0 { + %6 = zext i32 %4 to i64 + %7 = getelementptr inbounds <2 x i32>, <2 x i32> addrspace(1)* %1, i64 %6 + %8 = load <2 x i32>, <2 x i32> addrspace(1)* %7, align 8, !tbaa !30, !alias.scope !33, !noalias !36 + %9 = load i32, i32 addrspace(2)* %3, align 4, !tbaa !40, !alias.scope !42, !noalias !43 + %10 = bitcast %"struct.metal::rasterization_rate_map_data" addrspace(2)* %0 to i8 addrspace(2)* + %11 = tail call <2 x i32> @air.map_screen_to_physical_coordinates.v2i32.p2i8.i32(<2 x i32> %8, i8 addrspace(2)* nocapture readonly %10, i32 %9) #4, !alias.scope !44, !noalias !45 + %12 = tail call <2 x i32> @air.map_physical_to_screen_coordinates.v2i32.p2i8.i32(<2 x i32> %8, i8 addrspace(2)* nocapture readonly %10, i32 %9) #4, !alias.scope !44, !noalias !45 + %13 = shufflevector <2 x i32> %11, <2 x i32> %12, <4 x i32> + %14 = getelementptr inbounds <4 x i32>, <4 x i32> addrspace(1)* %2, i64 %6 + store <4 x i32> %13, <4 x i32> addrspace(1)* %14, align 16, !tbaa !30, !alias.scope !46, !noalias !47 + ret void +} + +; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn +define <4 x i32> @rate_map_integer_pixel(<4 x float> noundef %0, %"struct.metal::rasterization_rate_map_data" addrspace(2)* noundef align 1 "air-buffer-no-alias" %1, i32 addrspace(2)* nocapture noundef readonly align 4 dereferenceable(4) "air-buffer-no-alias" %2) local_unnamed_addr #1 { + %4 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> + %5 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %4) #5 + %6 = load i32, i32 addrspace(2)* %2, align 4, !tbaa !40, !alias.scope !48, !noalias !51 + %7 = bitcast %"struct.metal::rasterization_rate_map_data" addrspace(2)* %1 to i8 addrspace(2)* + %8 = tail call <2 x i32> @air.map_screen_to_physical_coordinates.v2i32.p2i8.i32(<2 x i32> %5, i8 addrspace(2)* nocapture readonly %7, i32 %6) #4, !alias.scope !51, !noalias !48 + %9 = tail call <2 x i32> @air.map_physical_to_screen_coordinates.v2i32.p2i8.i32(<2 x i32> %5, i8 addrspace(2)* nocapture readonly %7, i32 %6) #4, !alias.scope !51, !noalias !48 + %10 = shufflevector <2 x i32> %8, <2 x i32> %9, <4 x i32> + ret <4 x i32> %10 +} + +; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn +declare <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float>) local_unnamed_addr #2 + +; Function Attrs: argmemonly mustprogress nofree nounwind readonly willreturn +declare <2 x i32> @air.map_screen_to_physical_coordinates.v2i32.p2i8.i32(<2 x i32>, i8 addrspace(2)* nocapture readonly, i32) local_unnamed_addr #3 + +; Function Attrs: argmemonly mustprogress nofree nounwind readonly willreturn +declare <2 x i32> @air.map_physical_to_screen_coordinates.v2i32.p2i8.i32(<2 x i32>, i8 addrspace(2)* nocapture readonly, i32) local_unnamed_addr #3 + +attributes #0 = { argmemonly mustprogress nofree nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="64" "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 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 #2 = { mustprogress nofree nosync nounwind readnone willreturn } +attributes #3 = { argmemonly mustprogress nofree nounwind readonly willreturn } +attributes #4 = { argmemonly nounwind readonly willreturn } +attributes #5 = { nounwind readnone willreturn } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.kernel = !{!9} +!air.fragment = !{!17} +!air.compile_options = !{!24, !25, !26} +!llvm.ident = !{!27} +!air.version = !{!28} +!air.language_version = !{!29} + +!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.metal::rasterization_rate_map_data" addrspace(2)*, <2 x i32> addrspace(1)*, <4 x i32> addrspace(1)*, i32 addrspace(2)*, i32)* @rate_map_integer, !10, !11} +!10 = !{} +!11 = !{!12, !13, !14, !15, !16} +!12 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_name", !"metal::rasterization_rate_map_data", !"air.arg_name", !"map"} +!13 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, 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", !"uint2", !"air.arg_name", !"in"} +!14 = !{i32 2, !"air.buffer", !"air.location_index", i32 2, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"uint4", !"air.arg_name", !"out"} +!15 = !{i32 3, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 3, 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", !"layer"} +!16 = !{i32 4, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} +!17 = !{<4 x i32> (<4 x float>, %"struct.metal::rasterization_rate_map_data" addrspace(2)*, i32 addrspace(2)*)* @rate_map_integer_pixel, !18, !20} +!18 = !{!19} +!19 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"} +!20 = !{!21, !22, !23} +!21 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!22 = !{i32 1, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_name", !"metal::rasterization_rate_map_data", !"air.arg_name", !"map"} +!23 = !{i32 2, !"air.buffer", !"air.buffer_size", i32 4, !"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", !"layer"} +!24 = !{!"air.compile.denorms_disable"} +!25 = !{!"air.compile.fast_math_enable"} +!26 = !{!"air.compile.framebuffer_fetch_enable"} +!27 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!28 = !{i32 2, i32 8, i32 0} +!29 = !{!"Metal", i32 4, i32 0, i32 0} +!30 = !{!31, !31, i64 0} +!31 = !{!"omnipotent char", !32, i64 0} +!32 = !{!"Simple C++ TBAA"} +!33 = !{!34} +!34 = distinct !{!34, !35, !"air-alias-scope-arg(1)"} +!35 = distinct !{!35, !"air-alias-scopes(rate_map_integer)"} +!36 = !{!37, !38, !39} +!37 = distinct !{!37, !35, !"air-alias-scope-arg(0)"} +!38 = distinct !{!38, !35, !"air-alias-scope-arg(2)"} +!39 = distinct !{!39, !35, !"air-alias-scope-arg(3)"} +!40 = !{!41, !41, i64 0} +!41 = !{!"int", !31, i64 0} +!42 = !{!39} +!43 = !{!37, !34, !38} +!44 = !{!37} +!45 = !{!34, !38, !39} +!46 = !{!38} +!47 = !{!37, !34, !39} +!48 = !{!49} +!49 = distinct !{!49, !50, !"air-alias-scope-arg(2)"} +!50 = distinct !{!50, !"air-alias-scopes(rate_map_integer_pixel)"} +!51 = !{!52} +!52 = distinct !{!52, !50, !"air-alias-scope-arg(1)"} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/rate_map_integer.ll b/crates/metal2vulkan-validation/fixtures/public/engine/rate_map_integer.ll new file mode 100644 index 000000000..b1910035a --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/rate_map_integer.ll @@ -0,0 +1,110 @@ +; Generated by scripts/regen-air-fixtures from rate_map_integer.metal (llvm-dis of rate_map_integer.air). 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" + +; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite) +define void @rate_map_integer(ptr addrspace(2) noundef align 1 "air-buffer-no-alias" %0, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %1, ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %2, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %3, i32 noundef %4) local_unnamed_addr #0 { + %6 = zext i32 %4 to i64 + %7 = getelementptr inbounds <2 x i32>, ptr addrspace(1) %1, i64 %6 + %8 = load <2 x i32>, ptr addrspace(1) %7, align 8, !tbaa !30, !alias.scope !33, !noalias !36 + %9 = load i32, ptr addrspace(2) %3, align 4, !tbaa !40, !alias.scope !42, !noalias !43 + %10 = bitcast ptr addrspace(2) %0 to ptr addrspace(2) + %11 = tail call <2 x i32> @air.map_screen_to_physical_coordinates.v2i32.p2i8.i32(<2 x i32> %8, ptr addrspace(2) readonly captures(none) %10, i32 %9) #4, !alias.scope !44, !noalias !45 + %12 = tail call <2 x i32> @air.map_physical_to_screen_coordinates.v2i32.p2i8.i32(<2 x i32> %8, ptr addrspace(2) readonly captures(none) %10, i32 %9) #4, !alias.scope !44, !noalias !45 + %13 = shufflevector <2 x i32> %11, <2 x i32> %12, <4 x i32> + %14 = getelementptr inbounds <4 x i32>, ptr addrspace(1) %2, i64 %6 + store <4 x i32> %13, ptr addrspace(1) %14, align 16, !tbaa !30, !alias.scope !46, !noalias !47 + ret void +} + +; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) +define <4 x i32> @rate_map_integer_pixel(<4 x float> noundef %0, ptr addrspace(2) noundef align 1 "air-buffer-no-alias" %1, ptr addrspace(2) noundef readonly align 4 captures(none) dereferenceable(4) "air-buffer-no-alias" %2) local_unnamed_addr #1 { + %4 = shufflevector <4 x float> %0, <4 x float> poison, <2 x i32> + %5 = tail call <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float> %4) #5 + %6 = load i32, ptr addrspace(2) %2, align 4, !tbaa !40, !alias.scope !48, !noalias !51 + %7 = bitcast ptr addrspace(2) %1 to ptr addrspace(2) + %8 = tail call <2 x i32> @air.map_screen_to_physical_coordinates.v2i32.p2i8.i32(<2 x i32> %5, ptr addrspace(2) readonly captures(none) %7, i32 %6) #4, !alias.scope !51, !noalias !48 + %9 = tail call <2 x i32> @air.map_physical_to_screen_coordinates.v2i32.p2i8.i32(<2 x i32> %5, ptr addrspace(2) readonly captures(none) %7, i32 %6) #4, !alias.scope !51, !noalias !48 + %10 = shufflevector <2 x i32> %8, <2 x i32> %9, <4 x i32> + ret <4 x i32> %10 +} + +; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) +declare <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float>) local_unnamed_addr #2 + +; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read) +declare <2 x i32> @air.map_screen_to_physical_coordinates.v2i32.p2i8.i32(<2 x i32>, ptr addrspace(2) readonly captures(none), i32) local_unnamed_addr #3 + +; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read) +declare <2 x i32> @air.map_physical_to_screen_coordinates.v2i32.p2i8.i32(<2 x i32>, ptr addrspace(2) readonly captures(none), i32) local_unnamed_addr #3 + +attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="64" "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(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 #2 = { mustprogress nofree nosync nounwind willreturn memory(none) } +attributes #3 = { mustprogress nofree nounwind willreturn memory(argmem: read) } +attributes #4 = { nounwind willreturn memory(argmem: read) } +attributes #5 = { nounwind willreturn memory(none) } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.kernel = !{!9} +!air.fragment = !{!17} +!air.compile_options = !{!24, !25, !26} +!llvm.ident = !{!27} +!air.version = !{!28} +!air.language_version = !{!29} + +!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 @rate_map_integer, !10, !11} +!10 = !{} +!11 = !{!12, !13, !14, !15, !16} +!12 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_name", !"metal::rasterization_rate_map_data", !"air.arg_name", !"map"} +!13 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, 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", !"uint2", !"air.arg_name", !"in"} +!14 = !{i32 2, !"air.buffer", !"air.location_index", i32 2, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"uint4", !"air.arg_name", !"out"} +!15 = !{i32 3, !"air.buffer", !"air.buffer_size", i32 4, !"air.location_index", i32 3, 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", !"layer"} +!16 = !{i32 4, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} +!17 = !{ptr @rate_map_integer_pixel, !18, !20} +!18 = !{!19} +!19 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"uint4"} +!20 = !{!21, !22, !23} +!21 = !{i32 0, !"air.position", !"air.center", !"air.no_perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!22 = !{i32 1, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.arg_type_name", !"metal::rasterization_rate_map_data", !"air.arg_name", !"map"} +!23 = !{i32 2, !"air.buffer", !"air.buffer_size", i32 4, !"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", !"layer"} +!24 = !{!"air.compile.denorms_disable"} +!25 = !{!"air.compile.fast_math_enable"} +!26 = !{!"air.compile.framebuffer_fetch_enable"} +!27 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!28 = !{i32 2, i32 8, i32 0} +!29 = !{!"Metal", i32 4, i32 0, i32 0} +!30 = !{!31, !31, i64 0} +!31 = !{!"omnipotent char", !32, i64 0} +!32 = !{!"Simple C++ TBAA"} +!33 = !{!34} +!34 = distinct !{!34, !35, !"air-alias-scope-arg(1)"} +!35 = distinct !{!35, !"air-alias-scopes(rate_map_integer)"} +!36 = !{!37, !38, !39} +!37 = distinct !{!37, !35, !"air-alias-scope-arg(0)"} +!38 = distinct !{!38, !35, !"air-alias-scope-arg(2)"} +!39 = distinct !{!39, !35, !"air-alias-scope-arg(3)"} +!40 = !{!41, !41, i64 0} +!41 = !{!"int", !31, i64 0} +!42 = !{!39} +!43 = !{!37, !34, !38} +!44 = !{!37} +!45 = !{!34, !38, !39} +!46 = !{!38} +!47 = !{!37, !34, !39} +!48 = !{!49} +!49 = distinct !{!49, !50, !"air-alias-scope-arg(2)"} +!50 = distinct !{!50, !"air-alias-scopes(rate_map_integer_pixel)"} +!51 = !{!52} +!52 = distinct !{!52, !50, !"air-alias-scope-arg(1)"} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/rate_map_integer.metal b/crates/metal2vulkan-validation/fixtures/public/engine/rate_map_integer.metal new file mode 100644 index 000000000..6658c9c1a --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/rate_map_integer.metal @@ -0,0 +1,34 @@ +// The `uint2` overloads of `rasterization_rate_map_decoder`, both directions: a kernel over +// coordinates a buffer holds, and a fragment function over its own pixel. +// +// `rate_map_integer` maps `in[tid]` at the layer buffer 3 holds and writes the screen-to-physical +// answer and the physical-to-screen answer as one `uint4`. `rate_map_integer_pixel` maps its +// pixel (the integer part of its position) at the layer buffer 1 holds and returns both answers +// as its colour. +// +// Plain Metal's answers, measured on an Apple M3 Max under macOS 27.0.1 (the conformance probe +// `rate_map_integer_overloads`): the screen-to-physical answer is the `float2` decoder's at the +// pixel's centre, `c + 1/2`, converted to `uint`; the physical-to-screen answer is the bits of the +// `float` `(0 - offset) * reciprocal` of the entry of granule `c >> 5`, the coordinate's own value +// not read, so it is a `float`'s bits and not a screen coordinate. +#include +using namespace metal; + +kernel void rate_map_integer(constant rasterization_rate_map_data &map [[buffer(0)]], + device const uint2 *in [[buffer(1)]], + device uint4 *out [[buffer(2)]], + constant uint &layer [[buffer(3)]], + uint tid [[thread_position_in_grid]]) { + rasterization_rate_map_decoder decoder(map); + out[tid] = uint4(decoder.map_screen_to_physical_coordinates(in[tid], layer), + decoder.map_physical_to_screen_coordinates(in[tid], layer)); +} + +fragment uint4 rate_map_integer_pixel(float4 position [[position]], + constant rasterization_rate_map_data &map [[buffer(0)]], + constant uint &layer [[buffer(1)]]) { + rasterization_rate_map_decoder decoder(map); + uint2 pixel = uint2(position.xy); + return uint4(decoder.map_screen_to_physical_coordinates(pixel, layer), + decoder.map_physical_to_screen_coordinates(pixel, layer)); +} diff --git a/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv b/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv index 726f0a32d..bfe28d6fe 100644 --- a/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv +++ b/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv @@ -2194,6 +2194,10 @@ engine/px_samplers.ll px_const_linear_zero ok ok ok ok ok ok ok ok ok ok ok ok o engine/px_samplers.ll px_const_linear_border ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/quad_shuffle.air.ll quad_shuffle_rotate ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/quad_shuffle.ll quad_shuffle_rotate ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/rate_map_integer.air.ll rate_map_integer Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} +engine/rate_map_integer.air.ll rate_map_integer_pixel Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} +engine/rate_map_integer.ll rate_map_integer Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} +engine/rate_map_integer.ll rate_map_integer_pixel Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} Unsupported{RasterizationRateMap; NotImplemented} engine/rch_guarded_effects.air.ll rch_guarded_vertex ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/rch_guarded_effects.air.ll rch_guarded_store ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok Unsupported{StageStoresAndAtomics; AnyOf[[Feature(FragmentStoresAndAtomics)]]} engine/rch_guarded_effects.air.ll rch_guarded_atomic ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok Unsupported{StageStoresAndAtomics; AnyOf[[Feature(FragmentStoresAndAtomics)]]}