diff --git a/crates/metal2vulkan-conformance/probes/undefined_function_constant_values.m b/crates/metal2vulkan-conformance/probes/undefined_function_constant_values.m index 202936661..96e2ebfdb 100644 --- a/crates/metal2vulkan-conformance/probes/undefined_function_constant_values.m +++ b/crates/metal2vulkan-conformance/probes/undefined_function_constant_values.m @@ -1,7 +1,8 @@ // What plain Metal reads for a function constant the function's constant values leave undefined: // read directly, of each scalar and vector type, and through program-scope constants derived from // it (which Metal's compiler computes in the module's static initializer), for a constant Metal -// reports required and for one it reports optional (read guarded somewhere as well). +// reports required and for one it reports optional (read guarded somewhere as well); and which +// stage functions made without constant values Metal makes a pipeline state of. // // Measured on an Apple M3 Max under macOS 27.0.1, `MTL_DEBUG_LAYER` out of the environment, one // case a process; docs/API.md's accepted differences ("Function constants") quote the answers. @@ -16,9 +17,45 @@ // (the buffer is filled with 0xAB first). Case `gate` makes kernel `kg`, whose buffer 1 is gated // on `!g_flag` and on `g_flag` (buffers 1 and 2) with `g_flag` undefined, and prints the buffers // its pipeline's reflection binds and the words it stores. +// +// Cases `:` make a pipeline state of a stage function made `how`: `by-name` +// (`newFunctionWithName:`), `empty` (`newFunctionWithName:constantValues:` with no value) or +// `descriptor` (`newFunctionWithDescriptor:`, `constantValues` nil). Each prints every function's +// `functionConstantsDictionary` count, then the creation. Shapes: kernels `ko` (reads the optional +// `o_opt` only where `is_function_constant_defined`), `kn` (reads no constant), `kg` (the gate +// case's kernel: `g_flag` gates its arguments) and `k`, each a compute state, dispatched once +// where made (word 0 printed); `vertex` (`vc` reads `v_scale`, made `how`; `fp` by name), +// `fragment` (`vp` by name; `fc` reads `f_tint`, made `how`) and `plain` (`vp` and `fp`, which read +// none, made `how`), each a render state; `tile` (`tc` reads `t_tint`) and `tile-plain` (`tp` reads +// none), a tile state's function; `mesh` (`mc` reads `m_scale`, made `how`; `fp` by name), +// `object` (`oc` reads `o_count`, made `how`; `mp` and `fp` by name) and `mesh-plain` (`mp` made +// `how`, `fp` by name), each a mesh render state. +// +// WHAT IT MEASURED (an Apple M3 Max, macOS 27.0.1): +// - `by-name` of a function that declares a constant (its dictionary's count 1, `k`'s 8): the +// creation ends the process (exit 134, `MTL_DEBUG_LAYER` unset) at Metal's descriptor +// validation, for every stage, an optional guarded constant (`ko`) and a constant gating only +// arguments (`kg`) alike: +// `ko`, `kg`, `k`: "validateWithDevice:1623: failed assertion `Compute Pipeline Descriptor +// Validation / function ko cannot be used to build a pipeline state. Use +// newFunctionWithName:constantValues:... to get the specialized function"; +// `vertex`, `fragment`: "validateWithDevice:5101: failed assertion `Render Pipeline +// Descriptor Validation / vertexFunction vc cannot be used ..." ("fragmentFunction fc"); +// `tile`: "validateWithDevice:1177: failed assertion `Tile Render Pipeline Descriptor +// Validation / function tc cannot be used to build a pipeline state without setting constant +// values first."; +// `mesh`, `object`: "validateWithDevice:1956: failed assertion `Mesh Render Pipeline +// Descriptor Validation / meshFunction mc cannot be used ..." ("objectFunction oc"). +// The `none` case is `by-name:k`'s and ends the same way. +// - `by-name` of a function that declares none (`kn`, `plain`, `tile-plain`, `mesh-plain`): made; +// `kn` stores 9. +// - `empty` and `descriptor`, every shape: every function answers count 0, and the state is made; +// `ko` stores 7 (`o_opt` undefined), `kn` 9, `k` 0, and `kg` leaves word 0 as filled +// (0xabababab). #import #import #include +#include #include static const char *SRC = "#include \nusing namespace metal;\n" @@ -49,7 +86,119 @@ static const char *SRC = " device uint *on_flag [[buffer(2), function_constant(g_flag)]], uint t [[thread_position_in_grid]]) {\n" " if (t != 0) return;\n" " out[0] = g_not ? on_not[0] : 2; out[1] = g_flag ? on_flag[0] : 4; out[2] = g_not; out[3] = g_flag;\n" -"}\n"; +"}\n" +"constant uchar o_opt [[function_constant(30)]];\n" +"kernel void ko(device uint *out [[buffer(0)]], uint t [[thread_position_in_grid]]) {\n" +" if (t != 0) return;\n" +" out[0] = is_function_constant_defined(o_opt) ? o_opt : 7;\n" +"}\n" +"kernel void kn(device uint *out [[buffer(0)]], uint t [[thread_position_in_grid]]) {\n" +" if (t != 0) return;\n" +" out[0] = 9;\n" +"}\n" +"constant float v_scale [[function_constant(31)]];\n" +"vertex float4 vc(uint v [[vertex_id]]) { return float4(float(v & 1) * v_scale, float(v >> 1), 0, 1); }\n" +"vertex float4 vp(uint v [[vertex_id]]) { return float4(float(v & 1), float(v >> 1), 0, 1); }\n" +"constant float f_tint [[function_constant(32)]];\n" +"fragment float4 fc() { return float4(f_tint, 0, 0, 1); }\n" +"fragment float4 fp() { return float4(1, 0, 0, 1); }\n" +"struct TB { half4 c [[color(0)]]; };\n" +"constant half t_tint [[function_constant(33)]];\n" +"kernel void tc(imageblock b, ushort2 l [[thread_position_in_threadgroup]]) {\n" +" TB v = b.read(l); v.c *= t_tint; b.write(v, l);\n" +"}\n" +"kernel void tp(imageblock b, ushort2 l [[thread_position_in_threadgroup]]) {\n" +" TB v = b.read(l); v.c *= 0.5h; b.write(v, l);\n" +"}\n" +"struct MV { float4 position [[position]]; };\n" +"using M = metal::mesh;\n" +"constant float m_scale [[function_constant(34)]];\n" +"[[mesh]] void mc(M m, uint t [[thread_index_in_threadgroup]]) {\n" +" if (t == 0) { m.set_primitive_count(1); m.set_index(0, 0); m.set_index(1, 1); m.set_index(2, 2); }\n" +" if (t < 3) { MV v; v.position = float4(float(t & 1) * m_scale, float(t >> 1), 0, 1); m.set_vertex(t, v); }\n" +"}\n" +"[[mesh]] void mp(M m, uint t [[thread_index_in_threadgroup]]) {\n" +" if (t == 0) { m.set_primitive_count(1); m.set_index(0, 0); m.set_index(1, 1); m.set_index(2, 2); }\n" +" if (t < 3) { MV v; v.position = float4(float(t & 1), float(t >> 1), 0, 1); m.set_vertex(t, v); }\n" +"}\n" +"constant uint o_count [[function_constant(35)]];\n" +"[[object]] void oc(mesh_grid_properties g) { g.set_threadgroups_per_grid(uint3(o_count + 1, 1, 1)); }\n"; + +// `how` of `name`: `by-name` (`newFunctionWithName:`), `empty` +// (`newFunctionWithName:constantValues:` with no value), `descriptor` (`newFunctionWithDescriptor:` +// with nil `constantValues`). Prints the function's `functionConstantsDictionary` count. +static id made_as(id L, const char *how, NSString *name) { + NSError *e = nil; + id f = nil; + if (strcmp(how, "by-name") == 0) { + f = [L newFunctionWithName:name]; + } else if (strcmp(how, "empty") == 0) { + f = [L newFunctionWithName:name constantValues:[MTLFunctionConstantValues new] error:&e]; + } else { + MTLFunctionDescriptor *d = [MTLFunctionDescriptor functionDescriptor]; + d.name = name; + f = [L newFunctionWithDescriptor:d error:&e]; + } + if (!f) { printf("RESULT function %s error %s\n", name.UTF8String, e.localizedDescription.UTF8String); exit(0); } + printf("RESULT function %s %s constants=%lu\n", name.UTF8String, how, (unsigned long)f.functionConstantsDictionary.count); + fflush(stdout); + return f; +} + +// Case `:`: a kernel shape (`ko`, `kn`, `kg`, `k`) made `how` and its compute state, +// dispatched once where made (word 0 printed), or a render shape: `vertex` (`vc` made `how`, `fp` +// by name), `fragment` (`vp` by name, `fc` made `how`), `plain` (`vp` and `fp` made `how`) and its +// render state. +static int stage_case(id D, id Q, id L, const char *how, const char *shape) { + NSError *e = nil; + if (shape[0] == 'k') { + id f = made_as(L, how, [NSString stringWithUTF8String:shape]); + id ps = [D newComputePipelineStateWithFunction:f error:&e]; + if (!ps) { printf("RESULT pipeline error %s\n", e.localizedDescription.UTF8String); return 0; } + id out = [D newBufferWithLength:64 options:MTLResourceStorageModeShared]; + id one = [D newBufferWithLength:64 options:MTLResourceStorageModeShared]; + memset(out.contents, 0xAB, 64); + id cb = [Q commandBuffer]; + id ce = [cb computeCommandEncoder]; + [ce setComputePipelineState:ps]; + [ce setBuffer:out offset:0 atIndex:0]; [ce setBuffer:one offset:0 atIndex:1]; [ce setBuffer:one offset:0 atIndex:2]; + [ce dispatchThreads:MTLSizeMake(1, 1, 1) threadsPerThreadgroup:MTLSizeMake(1, 1, 1)]; + [ce endEncoding]; [cb commit]; [cb waitUntilCompleted]; + printf("RESULT pipeline made status=%ld word0 %08x\n", (long)cb.status, ((const uint32_t *)out.contents)[0]); + return 0; + } + if (strcmp(shape, "tile") == 0 || strcmp(shape, "tile-plain") == 0) { + MTLTileRenderPipelineDescriptor *t = [MTLTileRenderPipelineDescriptor new]; + t.colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm; + t.threadgroupSizeMatchesTileSize = YES; + t.tileFunction = made_as(L, how, strcmp(shape, "tile") == 0 ? @"tc" : @"tp"); + id ps = [D newRenderPipelineStateWithTileDescriptor:t options:MTLPipelineOptionNone reflection:nil error:&e]; + if (!ps) { printf("RESULT pipeline error %s\n", e.localizedDescription.UTF8String); return 0; } + printf("RESULT pipeline made\n"); + return 0; + } + if (strncmp(shape, "mesh", 4) == 0 || strcmp(shape, "object") == 0) { + MTLMeshRenderPipelineDescriptor *m = [MTLMeshRenderPipelineDescriptor new]; + m.colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm; + if (strcmp(shape, "object") == 0) m.objectFunction = made_as(L, how, @"oc"); + m.meshFunction = made_as(L, strcmp(shape, "object") == 0 ? "by-name" : how, strcmp(shape, "mesh") == 0 ? @"mc" : @"mp"); + m.fragmentFunction = made_as(L, "by-name", @"fp"); + id ps = [D newRenderPipelineStateWithMeshDescriptor:m options:MTLPipelineOptionNone reflection:nil error:&e]; + if (!ps) { printf("RESULT pipeline error %s\n", e.localizedDescription.UTF8String); return 0; } + printf("RESULT pipeline made\n"); + return 0; + } + MTLRenderPipelineDescriptor *d = [MTLRenderPipelineDescriptor new]; + d.colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm; + const char *v = strcmp(shape, "fragment") == 0 ? "by-name" : how; + const char *fr = strcmp(shape, "vertex") == 0 ? "by-name" : how; + d.vertexFunction = made_as(L, v, strcmp(shape, "vertex") == 0 ? @"vc" : @"vp"); + d.fragmentFunction = made_as(L, fr, strcmp(shape, "fragment") == 0 ? @"fc" : @"fp"); + id ps = [D newRenderPipelineStateWithDescriptor:d error:&e]; + if (!ps) { printf("RESULT pipeline error %s\n", e.localizedDescription.UTF8String); return 0; } + printf("RESULT pipeline made\n"); + return 0; +} int main(int argc, char **argv) { if (argc < 2) return 2; @@ -61,6 +210,12 @@ int main(int argc, char **argv) { NSError *e = nil; id L = [D newLibraryWithSource:[NSString stringWithUTF8String:SRC] options:nil error:&e]; if (!L) { printf("RESULT library error %s\n", e.localizedDescription.UTF8String); return 1; } + const char *colon = strchr(c, ':'); + if (colon) { + char how[32] = {0}; + strncpy(how, c, (size_t)(colon - c) < sizeof how - 1 ? (size_t)(colon - c) : sizeof how - 1); + return stage_case(D, Q, L, how, colon + 1); + } if (strcmp(c, "gate") == 0) { MTLFunctionConstantValues *v = [MTLFunctionConstantValues new]; id g = [L newFunctionWithName:@"kg" constantValues:v error:&e]; diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 38bdceb76..4f927c26d 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -87,7 +87,12 @@ command_buffer.wait_until_completed()?; ``` Creating a pipeline state translates its functions, each under the 20-second translation budget. -A function the device cannot run exactly is refused there, typed, naming what is missing. +A function the device cannot run exactly is refused there, typed, naming what is missing. A stage +function made by `Library::new_function_with_name` whose function declares function constants is +refused before anything is translated (`Invalid`, `Problem::UnspecializedFunction`), as Metal ends +its process for it; make it with `new_function_with_name_constant_values` (no values are needed) +or `new_function_with_descriptor`, and a constant without a value is undefined (read as +[docs/API.md](../../docs/API.md)'s accepted differences, "Function constants", say). A `[[visible]]` function a stage calls but does not define comes from the functions it links: `Function::linked_function` of each, in the stage's `LinkedFunctions` diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 947835a6c..6c72d35bc 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -760,6 +760,27 @@ pub enum Problem { /// /// Basis: ours (this crate's already-compiled stage: Metal's descriptor takes a function). CompiledKernel, + /// `new_compute_pipeline_state`, `new_render_pipeline_state`, `new_tile_render_pipeline_state` + /// and `new_mesh_render_pipeline_state`: a stage function made by `newFunctionWithName:`, not + /// specialized (`FunctionDescriptor::specialized`), whose function declares function constants + /// (its `functionConstantsDictionary` is not empty), whether each is required, or optional and + /// read only where `is_function_constant_defined` says, or only gates an argument. Plain Metal's + /// creation ends its process at its descriptor validation ("Compute Pipeline Descriptor + /// Validation / function ko cannot be used to build a pipeline state. Use + /// newFunctionWithName:constantValues:... to get the specialized function"; a render or mesh + /// state's names `vertexFunction`, `fragmentFunction`, `objectFunction` or `meshFunction`, and + /// a tile state's says "without setting constant values first"). The function made with + /// constant values, none among them too, or by `newFunctionWithDescriptor:`, is made + /// (`pipeline/unspecialized.rs`). + /// + /// Basis: metal-measured (an M3 Max, macOS 27.0.1: plain Metal ends its process at a compute, + /// render, tile and mesh state of each stage, `MTL_DEBUG_LAYER` unset). + UnspecializedFunction { + /// The function's stage: `Kernel` for a compute or tile state's. + stage: Stage, + /// The function's name. + name: String, + }, /// `new_compute_pipeline_state`: the kernel's linked `functions`, or its `binary_functions`, /// list this name twice, or both lists hold it for two different functions. Metal's API /// validation stops every repeat ("All linked functions must have unique names"); plain diff --git a/crates/metal2vulkan-runtime/src/library.rs b/crates/metal2vulkan-runtime/src/library.rs index eb7491c98..bc15867ec 100644 --- a/crates/metal2vulkan-runtime/src/library.rs +++ b/crates/metal2vulkan-runtime/src/library.rs @@ -520,12 +520,18 @@ impl Function { /// linked functions (`FunctionDescriptor::with_linked` adds them): a stage of a /// [`RenderPipelineDescriptor`] or the kernel of a [`ComputePipelineDescriptor`] as /// `StageSource::Function` (`MTLRenderPipelineDescriptor.vertexFunction` and - /// `.fragmentFunction`, `MTLComputePipelineDescriptor.computeFunction`). + /// `.fragmentFunction`, `MTLComputePipelineDescriptor.computeFunction`). It is specialized + /// (`FunctionDescriptor::specialized`) where the function was made with constant values or by + /// [`Library::new_function_with_descriptor`]; a pipeline state of one made by + /// [`Library::new_function_with_name`] whose function declares function constants is refused + /// (`Invalid` with [`Problem::UnspecializedFunction`](crate::Problem::UnspecializedFunction)), + /// as plain Metal ends its process at the creation. /// /// [`RenderPipelineDescriptor`]: metal2vulkan::pipeline::RenderPipelineDescriptor /// [`ComputePipelineDescriptor`]: metal2vulkan::pipeline::ComputePipelineDescriptor pub fn function_descriptor(&self) -> StageFunction { - let mut descriptor = StageFunction::new(self.function.clone()); + let mut descriptor = StageFunction::new(self.function.clone()) + .with_specialized(self.specialized || self.by_descriptor); descriptor.constants = self.constants.clone(); descriptor } diff --git a/crates/metal2vulkan-runtime/src/pipeline/mod.rs b/crates/metal2vulkan-runtime/src/pipeline/mod.rs index 02a0664d8..c4f4d02d1 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/mod.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/mod.rs @@ -70,6 +70,7 @@ pub(super) mod stand_in; mod texture_access; mod tile; mod unrasterized; +mod unspecialized; pub use additions::{ BinaryFunctionProblem, BinaryFunctionStage, RenderPipelineFunctionsDescriptor, @@ -549,7 +550,10 @@ impl Device { /// another device (`Invalid(ForeignObject)`). Under `FAIL_ON_BINARY_ARCHIVE_MISS`, a pipeline /// no listed archive holds is `BinaryArchiveMiss`. What the compile refuses is `Compile` or /// `Unsupported`: constant values that do not fit the function's constants, and a call to a - /// visible function no linked function supplies, among it. A kernel that sets a render state on + /// visible function no linked function supplies, among it. A kernel made by + /// [`Library::new_function_with_name`](crate::Library::new_function_with_name) whose function + /// declares function constants is `Invalid(UnspecializedFunction)`, as plain Metal ends its + /// process at its creation. A kernel that sets a render state on /// a render command is `Unsupported{IndirectRenderState}` with `Needs::MetalGpuFamily` of /// Apple10 on a device that does not claim Apple10, as Metal's compiler refuses it on an M4 and /// an M3 Max, and `NotImplemented(IndirectRenderCommands)` on one that does. @@ -691,6 +695,13 @@ impl ComputePipelineState { if let Some(name) = duplicate_linked_name(&function.linked) { return Err(invalid(call, Problem::DuplicateLinkedFunction { name })); } + unspecialized::check( + device, + call, + Stage::Kernel, + kernel.stage(), + &options.budget(), + )?; additions::check_kernel(device, &kernel, function, call)?; // A tile pipeline's descriptor has no `supportIndirectCommandBuffers`, and no // `resourceIndex`. diff --git a/crates/metal2vulkan-runtime/src/pipeline/render.rs b/crates/metal2vulkan-runtime/src/pipeline/render.rs index e32392b8b..caea8a5e4 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/render.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/render.rs @@ -75,8 +75,8 @@ use metal2vulkan::library::{CompiledFunction, FunctionCompileKey}; use metal2vulkan::metal::{BindingAccess, PixelFormat, PrimitiveTopologyClass, RenderStages}; use metal2vulkan::pipeline::{ ColorAttachmentDescriptor, CommandWrites, MeshPipelineDescriptor, PipelineInterface, - RenderPipeline, RenderPipelineDescriptor, RuntimeFact, SpecKey, StageEntries, StageModule, - StageSource, TessellationDescriptor, + RenderPipeline, RenderPipelineDescriptor, RuntimeFact, SpecKey, Stage, StageEntries, + StageModule, StageSource, TessellationDescriptor, }; use metal2vulkan::reflection::{LinkedUseAnswers, RenderPipelineReflection}; use std::any::Any; @@ -567,7 +567,10 @@ impl Device { /// ([`Device::new_compute_pipeline_state`]). A fragment function that reads a program-scope /// `thread_index_in_quadgroup` is `Unsupported{GlobalBuiltinInFragment}` with /// `Needs::MetalRefuses` (an M3 Max and an M4) on a device that does not claim Apple10, as - /// Metal's creation refuses it there, and `NotImplemented` on one that does. + /// Metal's creation refuses it there, and `NotImplemented` on one that does. A vertex or + /// fragment function made by `Library::new_function_with_name` whose function declares + /// function constants is `Invalid(UnspecializedFunction)`, as plain Metal ends its process at + /// its creation. pub fn new_render_pipeline_state( &self, descriptor: &RenderPipelineDescriptor, @@ -628,7 +631,10 @@ impl Device { /// `Compile` or `Unsupported`, as [`Device::new_render_pipeline_state`] says, and so is an /// archive of another device; no binary archive holds a mesh render pipeline, so /// `FAIL_ON_BINARY_ARCHIVE_MISS` with archives listed is `BinaryArchiveMiss`. Each stage's - /// imports come from its own dynamic libraries, as a render state's do. + /// imports come from its own dynamic libraries, as a render state's do. An object, mesh or + /// fragment function made by `Library::new_function_with_name` whose function declares + /// function constants is `Invalid(UnspecializedFunction)`, as plain Metal ends its process at + /// its creation, before the device's mesh shading is asked. /// /// [`RenderCommandEncoder::draw_mesh_threadgroups`]: crate::RenderCommandEncoder::draw_mesh_threadgroups pub fn new_mesh_render_pipeline_state( @@ -1285,6 +1291,25 @@ impl GraphicsState { // Metal answers nil for a `rasterSampleCount` an Apple GPU does not take, whatever the // device rasterizes (`raster_samples.rs`). super::raster_samples::check("new_render_pipeline_state", descriptor.raster_sample_count)?; + // Metal's descriptor validation ends the process for a stage function made by name whose + // function declares function constants (`unspecialized.rs`). + let budget = options.budget(); + super::unspecialized::check( + device, + "new_render_pipeline_state", + Stage::Vertex, + &descriptor.vertex, + &budget, + )?; + if let Some(fragment) = &descriptor.fragment { + super::unspecialized::check( + device, + "new_render_pipeline_state", + Stage::Fragment, + fragment, + &budget, + )?; + } let scaled = descriptor .tessellation .as_ref() @@ -1614,6 +1639,16 @@ impl GraphicsState { descriptor.stencil_format, )?; super::raster_samples::check(CALL, descriptor.raster_sample_count)?; + // Metal's descriptor validation ends the process for a stage function made by name whose + // function declares function constants (`unspecialized.rs`). + let budget = options.budget(); + if let Some(object) = &descriptor.object { + super::unspecialized::check(device, CALL, Stage::Object, object, &budget)?; + } + super::unspecialized::check(device, CALL, Stage::Mesh, &descriptor.mesh, &budget)?; + if let Some(fragment) = &descriptor.fragment { + super::unspecialized::check(device, CALL, Stage::Fragment, fragment, &budget)?; + } // A state an indirect command buffer's commands may set takes its ID where the options // place it, as a render state's does. let placement = if descriptor.support_indirect_command_buffers { @@ -1638,7 +1673,6 @@ impl GraphicsState { binary_archive::check(device, options, CALL, ArchivedPipeline::Render, |_, _| { Some(&descriptor.mesh) })?; - let budget = options.budget(); // As a render state's, in Metal's order: a fragment function writing // depth without a depth attachment, the indirect command buffers' refusal, then the // fragment function's stage inputs the linking keeps that the mesh function does not diff --git a/crates/metal2vulkan-runtime/src/pipeline/tile.rs b/crates/metal2vulkan-runtime/src/pipeline/tile.rs index c18dc894b..01cc6457a 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/tile.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/tile.rs @@ -56,7 +56,9 @@ impl Device { /// `FAIL_ON_BINARY_ARCHIVE_MISS`, a pipeline no listed archive holds is `BinaryArchiveMiss` /// (a tile pipeline's archive key). What the compile refuses is `Compile` or `Unsupported`. The /// tile function's imports come from its dynamic libraries, as a compute state's do - /// ([`Device::new_compute_pipeline_state`]). + /// ([`Device::new_compute_pipeline_state`]). A tile function made by + /// `Library::new_function_with_name` whose function declares function constants is + /// `Invalid(UnspecializedFunction)`, as plain Metal ends its process at its creation. pub fn new_tile_render_pipeline_state( &self, descriptor: &TileRenderPipelineDescriptor, diff --git a/crates/metal2vulkan-runtime/src/pipeline/unspecialized.rs b/crates/metal2vulkan-runtime/src/pipeline/unspecialized.rs new file mode 100644 index 000000000..93e500562 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/pipeline/unspecialized.rs @@ -0,0 +1,59 @@ +//! Metal's refusal of a pipeline state of a stage function made by `newFunctionWithName:` whose +//! function declares function constants. +//! +//! - **What Metal answers** (an Apple M3 Max under macOS 27.0.1, `MTL_DEBUG_LAYER` unset; the +//! conformance crate's probe `undefined_function_constant_values.m`). A function made by +//! `newFunctionWithName:` whose `functionConstantsDictionary` is not empty ends the process at +//! every pipeline creator's descriptor validation, whether its constant is required, or optional +//! and read only where `is_function_constant_defined` says, or only gates an argument: a compute +//! state's ("Compute Pipeline Descriptor Validation / function ko cannot be used to build a +//! pipeline state. Use newFunctionWithName:constantValues:... to get the specialized +//! function"), a render state's vertex and fragment functions' (`vertexFunction`, +//! `fragmentFunction`), a tile state's ("function tc cannot be used to build a pipeline state +//! without setting constant values first.") and a mesh render state's object and mesh +//! functions' (`objectFunction`, `meshFunction`). One made by name that declares none is made, +//! and so is every function made with constant values, none among them too, or by +//! `newFunctionWithDescriptor:` without them, its constants without a value undefined. +//! - **The answer.** [`Error::Invalid`] with [`Problem::UnspecializedFunction`], before anything is +//! compiled. Whether a stage is specialized is its descriptor's +//! (`FunctionDescriptor::specialized`, which [`Function::function_descriptor`] sets; one with +//! constant values is specialized whatever it says), and whether it declares constants is the +//! compile layer's answer (`FunctionDescriptor::needs_specialization`), read through the +//! device's stage entries, whose module decode the stage's compile then copies. What that answer +//! refuses refuses the creation. A linked function keeps its own rule +//! (`LinkProblem::UnresolvedConstant`, `Function::linked_function`). +//! +//! [`Function::function_descriptor`]: crate::Function::function_descriptor + +use super::Device; +use crate::device::device_error; +use crate::error::{invalid, Error, Problem}; +use metal2vulkan::pipeline::{Stage, StageSource}; +use metal2vulkan::Budget; + +/// Refused in `call` (the module docs): `source`, the function of `stage` (`Kernel` for a compute +/// or tile state's), where it is not specialized and declares function constants. A stage the +/// compile layer already compiled is no function, and is not refused here. +pub(super) fn check( + device: &Device, + call: &'static str, + stage: Stage, + source: &StageSource, + budget: &Budget, +) -> Result<(), Error> { + let StageSource::Function(f) = source else { + return Ok(()); + }; + let entries = device.shared().shader_cache.memo.stage_entries(); + match f.needs_specialization(budget, entries) { + Ok(false) => Ok(()), + Ok(true) => Err(invalid( + call, + Problem::UnspecializedFunction { + stage, + name: f.function.info().name.to_owned(), + }, + )), + Err(e) => Err(device_error(e)), + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/warm_record.rs b/crates/metal2vulkan-runtime/src/tests/warm_record.rs index 48d93fa4b..2d1f70e5b 100644 --- a/crates/metal2vulkan-runtime/src/tests/warm_record.rs +++ b/crates/metal2vulkan-runtime/src/tests/warm_record.rs @@ -45,8 +45,8 @@ fn constants() -> FunctionConstantValues { ) } -/// A stage of `f` with constants and linked functions in every list and a group, one under a -/// specialized name. +/// A stage of `f`, specialized, with constants and linked functions in every list and a group, +/// one under a specialized name. fn stage(f: Function) -> StageSource { let linked = function("ob3_texture_array", "ob3_texture_array"); let mut functions = LinkedFunctions::new() @@ -59,7 +59,7 @@ fn stage(f: Function) -> StageSource { functions .groups .insert("group".into(), vec![LinkedFunction::new(linked)]); - let mut descriptor = FunctionDescriptor::new(f); + let mut descriptor = FunctionDescriptor::new(f).with_specialized(true); descriptor.constants = constants(); descriptor.linked = functions; StageSource::Function(descriptor) diff --git a/crates/metal2vulkan-runtime/src/warm/codec.rs b/crates/metal2vulkan-runtime/src/warm/codec.rs index c7590a3e0..1ec2389d1 100644 --- a/crates/metal2vulkan-runtime/src/warm/codec.rs +++ b/crates/metal2vulkan-runtime/src/warm/codec.rs @@ -42,7 +42,7 @@ use std::collections::{BTreeMap, HashMap}; pub(crate) const MAGIC: &[u8; 8] = b"M2VPREC\0"; /// The record format: bumped whenever a record's bytes change meaning (the module docs). -pub(crate) const RECORD_FORMAT: u32 = 2; +pub(crate) const RECORD_FORMAT: u32 = 3; /// The length of a record's header (magic and format) and of its checksum. const HEADER: usize = 8 + 4; @@ -326,6 +326,7 @@ impl Writer { }; self.function(&f.function)?; self.constants(&f.constants)?; + self.bool(f.specialized); self.linked(&f.linked)?; self.dynamic(&f.libraries) } @@ -713,6 +714,7 @@ impl<'a> Reader<'a> { fn stage(&mut self) -> Result { let mut f = FunctionDescriptor::new(self.function()?); f.constants = self.constants()?; + f.specialized = self.bool()?; f.linked = self.linked()?; f.libraries = self.dynamic()?; Ok(StageSource::Function(f)) diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN index 191fe2793..79b63d03a 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN +++ b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN @@ -331,6 +331,7 @@ fixture unk_size_queries: metal: Apple metal version 32023.921 (metalfe-32023.92 fixture unk_ulong_atomics: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture unk_ulong_rw: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture unmeasured_speculation: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) +fixture unspecialized_stage_functions: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture unv_runtime_levels: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture vft_tile_caller: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture vft_vertex_caller: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/unspecialized_stage_functions.air.ll b/crates/metal2vulkan-validation/fixtures/public/engine/unspecialized_stage_functions.air.ll new file mode 100644 index 000000000..ffaa1c8bd --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/unspecialized_stage_functions.air.ll @@ -0,0 +1,345 @@ +; Generated by scripts/regen-air-fixtures from unspecialized_stage_functions.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::_imageblock_base" = type { %struct._imageblock_t addrspace(4)* } +%struct._imageblock_t = type opaque +%struct._mesh_t = type opaque +%struct._mesh_grid_properties_t = type opaque + +@_ZL14optional_count = internal unnamed_addr addrspace(2) global i32 undef, align 4 +@_Z14optional_count.MTL_FC_INIT_0_j = linkonce_odr hidden addrspace(2) externally_initialized constant i32 undef, section "air.fc_initializer", align 4 +@_ZL9has_extra = internal unnamed_addr addrspace(2) global i8 undef, align 1 +@_Z9has_extra.MTL_FC_INIT_1_b = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant i8 undef, section "air.fc_initializer", align 1 +@_ZL12vertex_scale = internal unnamed_addr addrspace(2) global float undef, align 4 +@_Z12vertex_scale.MTL_FC_INIT_2_f = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant float undef, section "air.fc_initializer", align 4 +@_ZL13fragment_tint = internal unnamed_addr addrspace(2) global float undef, align 4 +@_Z13fragment_tint.MTL_FC_INIT_3_f = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant float undef, section "air.fc_initializer", align 4 +@_ZL9tile_tint = internal unnamed_addr addrspace(2) global half undef, align 2 +@_Z9tile_tint.MTL_FC_INIT_4_Dh = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant half undef, section "air.fc_initializer", align 2 +@_ZL10mesh_scale = internal unnamed_addr addrspace(2) global float undef, align 4 +@_Z10mesh_scale.MTL_FC_INIT_5_f = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant float undef, section "air.fc_initializer", align 4 +@_ZL12object_count = internal unnamed_addr addrspace(2) global i32 undef, align 4 +@_Z12object_count.MTL_FC_INIT_6_j = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant i32 undef, section "air.fc_initializer", align 4 +@__metal_implicit_fc_pred_0 = internal addrspace(2) global i8 0, align 1 +@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I__, i8* null }] +@llvm.compiler.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(2)* @__metal_implicit_fc_pred_0 to i8*)], section "llvm.metadata" + +; Function Attrs: mustprogress nofree nosync nounwind willreturn +define void @unspecialized_guarded(i32 addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %0, i32 noundef %1) local_unnamed_addr #0 { + %3 = tail call i1 @air.is_function_constant_defined(i8 addrspace(2)* nocapture bitcast (i32 addrspace(2)* @_Z14optional_count.MTL_FC_INIT_0_j to i8 addrspace(2)*)) #14 + %4 = load i32, i32 addrspace(2)* @_ZL14optional_count, align 4 + %5 = select i1 %3, i32 %4, i32 7 + %6 = zext i32 %1 to i64 + %7 = getelementptr inbounds i32, i32 addrspace(1)* %0, i64 %6 + store i32 %5, i32 addrspace(1)* %7, align 4, !tbaa !59, !alias.scope !63 + ret void +} + +; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn +declare i1 @air.is_function_constant_defined(i8 addrspace(2)* nocapture) local_unnamed_addr #1 + +; Function Attrs: argmemonly mustprogress nofree norecurse nosync nounwind willreturn writeonly +define void @unspecialized_free(i32 addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %0, i32 noundef %1) local_unnamed_addr #2 { + %3 = zext i32 %1 to i64 + %4 = getelementptr inbounds i32, i32 addrspace(1)* %0, i64 %3 + store i32 9, i32 addrspace(1)* %4, align 4, !tbaa !59, !alias.scope !66 + ret void +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn +define void @unspecialized_gate(i32 addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %0, i32 addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %1, i32 noundef %2) local_unnamed_addr #3 { + %4 = load i8, i8 addrspace(2)* @_ZL9has_extra, align 1, !tbaa !69, !range !71 + %5 = icmp eq i8 %4, 0 + %6 = zext i32 %2 to i64 + br i1 %5, label %10, label %7 + +7: ; preds = %3 + %8 = getelementptr inbounds i32, i32 addrspace(1)* %1, i64 %6 + %9 = load i32, i32 addrspace(1)* %8, align 4, !tbaa !59, !alias.scope !72, !noalias !75 + br label %10 + +10: ; preds = %3, %7 + %11 = phi i32 [ %9, %7 ], [ 2, %3 ] + %12 = getelementptr inbounds i32, i32 addrspace(1)* %0, i64 %6 + store i32 %11, i32 addrspace(1)* %12, align 4, !tbaa !59, !alias.scope !75, !noalias !72 + ret void +} + +; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn +declare i8 @air.normalize_function_constant_predicate.i8(i8) local_unnamed_addr #1 + +; Function Attrs: mustprogress nofree nosync nounwind readonly willreturn +define <4 x float> @unspecialized_vertex(i32 noundef %0) local_unnamed_addr #4 { + %2 = and i32 %0, 1 + %3 = tail call fast float @air.convert.f.f32.u.i32(i32 %2) #14 + %4 = load float, float addrspace(2)* @_ZL12vertex_scale, align 4, !tbaa !77 + %5 = fmul fast float %4, %3 + %6 = lshr i32 %0, 1 + %7 = tail call fast float @air.convert.f.f32.u.i32(i32 %6) #14 + %8 = insertelement <4 x float> , float %5, i64 0 + %9 = insertelement <4 x float> %8, float %7, i64 1 + ret <4 x float> %9 +} + +; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn +declare float @air.convert.f.f32.u.i32(i32) local_unnamed_addr #1 + +; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn +define <4 x float> @unspecialized_vertex_free(i32 noundef %0) local_unnamed_addr #5 { + %2 = and i32 %0, 1 + %3 = tail call fast float @air.convert.f.f32.u.i32(i32 %2) #14 + %4 = lshr i32 %0, 1 + %5 = tail call fast float @air.convert.f.f32.u.i32(i32 %4) #14 + %6 = insertelement <4 x float> , float %3, i64 0 + %7 = insertelement <4 x float> %6, float %5, i64 1 + ret <4 x float> %7 +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind readonly willreturn +define <4 x float> @unspecialized_fragment() local_unnamed_addr #6 { + %1 = load float, float addrspace(2)* @_ZL13fragment_tint, align 4, !tbaa !77 + %2 = insertelement <4 x float> , float %1, i64 0 + ret <4 x float> %2 +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone willreturn +define <4 x float> @unspecialized_fragment_free() local_unnamed_addr #7 { + ret <4 x float> +} + +; Function Attrs: mustprogress nounwind willreturn +define void @unspecialized_tile(%"struct.metal::_imageblock_base" %0, <2 x i16> noundef %1) local_unnamed_addr #8 { + %3 = tail call fast <4 x half> @air.load.implicit_imageblock.v4f16(i32 0, <2 x i16> %1, i32 0, i16 0) #15 + %4 = load half, half addrspace(2)* @_ZL9tile_tint, align 2, !tbaa !79 + %5 = insertelement <4 x half> poison, half %4, i64 0 + %6 = shufflevector <4 x half> %5, <4 x half> poison, <4 x i32> zeroinitializer + %7 = fmul fast <4 x half> %6, %3 + tail call void @air.store.implicit_imageblock.v4f16(<4 x half> %7, i32 0, <2 x i16> %1, i32 0, i16 0) #16 + ret void +} + +; Function Attrs: mustprogress nounwind willreturn +define void @unspecialized_mesh(%struct._mesh_t addrspace(7)* %0, i32 noundef %1) local_unnamed_addr #9 { + %3 = icmp eq i32 %1, 0 + br i1 %3, label %4, label %5 + +4: ; preds = %2 + tail call void @air.set_primitive_count_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 1) #17 + tail call void @air.set_index_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 0, i8 0) #17 + tail call void @air.set_index_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 1, i8 1) #17 + tail call void @air.set_index_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 2, i8 2) #17 + br label %5 + +5: ; preds = %4, %2 + %6 = icmp ult i32 %1, 3 + br i1 %6, label %7, label %16 + +7: ; preds = %5 + %8 = and i32 %1, 1 + %9 = tail call fast float @air.convert.f.f32.u.i32(i32 %8) #14 + %10 = load float, float addrspace(2)* @_ZL10mesh_scale, align 4, !tbaa !77 + %11 = fmul fast float %10, %9 + %12 = lshr i32 %1, 1 + %13 = tail call fast float @air.convert.f.f32.u.i32(i32 %12) #14 + %14 = insertelement <4 x float> , float %11, i64 0 + %15 = insertelement <4 x float> %14, float %13, i64 1 + tail call void @air.set_position_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 %1, <4 x float> %15) #17 + br label %16 + +16: ; preds = %7, %5 + ret void +} + +; Function Attrs: mustprogress nounwind willreturn +define void @unspecialized_mesh_free(%struct._mesh_t addrspace(7)* %0, i32 noundef %1) local_unnamed_addr #9 { + %3 = icmp eq i32 %1, 0 + br i1 %3, label %4, label %5 + +4: ; preds = %2 + tail call void @air.set_primitive_count_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 1) #17 + tail call void @air.set_index_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 0, i8 0) #17 + tail call void @air.set_index_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 1, i8 1) #17 + tail call void @air.set_index_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 2, i8 2) #17 + br label %5 + +5: ; preds = %4, %2 + %6 = icmp ult i32 %1, 3 + br i1 %6, label %7, label %14 + +7: ; preds = %5 + %8 = and i32 %1, 1 + %9 = tail call fast float @air.convert.f.f32.u.i32(i32 %8) #14 + %10 = lshr i32 %1, 1 + %11 = tail call fast float @air.convert.f.f32.u.i32(i32 %10) #14 + %12 = insertelement <4 x float> , float %9, i64 0 + %13 = insertelement <4 x float> %12, float %11, i64 1 + tail call void @air.set_position_mesh(%struct._mesh_t addrspace(7)* nocapture %0, i32 %1, <4 x float> %13) #17 + br label %14 + +14: ; preds = %7, %5 + ret void +} + +; Function Attrs: mustprogress nounwind willreturn +define void @unspecialized_object(%struct._mesh_grid_properties_t addrspace(3)* nocapture %0) local_unnamed_addr #10 { + %2 = load i32, i32 addrspace(2)* @_ZL12object_count, align 4, !tbaa !59 + %3 = add i32 %2, 1 + %4 = insertelement <3 x i32> , i32 %3, i64 0 + tail call void @air.set_threadgroups_per_grid_mesh_properties(%struct._mesh_grid_properties_t addrspace(3)* nocapture %0, <3 x i32> %4) #17 + ret void +} + +; Function Attrs: argmemonly mustprogress nounwind willreturn +declare void @air.set_threadgroups_per_grid_mesh_properties(%struct._mesh_grid_properties_t addrspace(3)* nocapture, <3 x i32>) local_unnamed_addr #11 + +; Function Attrs: mustprogress nofree nounwind readonly willreturn +declare <4 x half> @air.load.implicit_imageblock.v4f16(i32, <2 x i16>, i32, i16) local_unnamed_addr #12 + +; Function Attrs: mustprogress nounwind willreturn writeonly +declare void @air.store.implicit_imageblock.v4f16(<4 x half>, i32, <2 x i16>, i32, i16) local_unnamed_addr #13 + +; Function Attrs: argmemonly mustprogress nounwind willreturn +declare void @air.set_primitive_count_mesh(%struct._mesh_t addrspace(7)* nocapture, i32) local_unnamed_addr #11 + +; Function Attrs: argmemonly mustprogress nounwind willreturn +declare void @air.set_index_mesh(%struct._mesh_t addrspace(7)* nocapture, i32, i8) local_unnamed_addr #11 + +; Function Attrs: argmemonly mustprogress nounwind willreturn +declare void @air.set_position_mesh(%struct._mesh_t addrspace(7)* nocapture, i32, <4 x float>) local_unnamed_addr #11 + +; Function Attrs: mustprogress nofree nosync nounwind willreturn +define internal void @_GLOBAL__sub_I__() #0 section "air.static_init" { + %1 = load i32, i32 addrspace(2)* @_Z14optional_count.MTL_FC_INIT_0_j, align 4, !tbaa !59 + store i32 %1, i32 addrspace(2)* @_ZL14optional_count, align 4, !tbaa !59 + %2 = load i8, i8 addrspace(2)* @_Z9has_extra.MTL_FC_INIT_1_b, align 1, !tbaa !69, !range !71 + store i8 %2, i8 addrspace(2)* @_ZL9has_extra, align 1, !tbaa !69 + %3 = load float, float addrspace(2)* @_Z12vertex_scale.MTL_FC_INIT_2_f, align 4, !tbaa !77 + store float %3, float addrspace(2)* @_ZL12vertex_scale, align 4, !tbaa !77 + %4 = load float, float addrspace(2)* @_Z13fragment_tint.MTL_FC_INIT_3_f, align 4, !tbaa !77 + store float %4, float addrspace(2)* @_ZL13fragment_tint, align 4, !tbaa !77 + %5 = load half, half addrspace(2)* @_Z9tile_tint.MTL_FC_INIT_4_Dh, align 2, !tbaa !79 + store half %5, half addrspace(2)* @_ZL9tile_tint, align 2, !tbaa !79 + %6 = load float, float addrspace(2)* @_Z10mesh_scale.MTL_FC_INIT_5_f, align 4, !tbaa !77 + store float %6, float addrspace(2)* @_ZL10mesh_scale, align 4, !tbaa !77 + %7 = load i32, i32 addrspace(2)* @_Z12object_count.MTL_FC_INIT_6_j, align 4, !tbaa !59 + store i32 %7, i32 addrspace(2)* @_ZL12object_count, align 4, !tbaa !59 + %8 = tail call i8 @air.normalize_function_constant_predicate.i8(i8 %2) #14 + store i8 %8, i8 addrspace(2)* @__metal_implicit_fc_pred_0, align 1 + ret void +} + +attributes #0 = { mustprogress nofree nosync nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #1 = { mustprogress nofree nosync nounwind readnone willreturn } +attributes #2 = { argmemonly mustprogress nofree norecurse nosync nounwind willreturn writeonly "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #3 = { mustprogress nofree norecurse nosync nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #4 = { mustprogress nofree nosync nounwind readonly willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #5 = { mustprogress 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 #6 = { mustprogress nofree norecurse nosync nounwind readonly willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #7 = { mustprogress nofree norecurse nosync nounwind readnone willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #8 = { mustprogress 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 #9 = { mustprogress nounwind 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 #10 = { mustprogress nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="96" "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 #11 = { argmemonly mustprogress nounwind willreturn } +attributes #12 = { mustprogress nofree nounwind readonly willreturn } +attributes #13 = { mustprogress nounwind willreturn writeonly } +attributes #14 = { nounwind readnone willreturn } +attributes #15 = { nounwind readonly willreturn } +attributes #16 = { nounwind willreturn writeonly } +attributes #17 = { argmemonly nounwind willreturn } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.kernel = !{!9, !14, !15, !20} +!air.vertex = !{!25, !30} +!air.fragment = !{!31, !34} +!air.mesh = !{!35, !42} +!air.object = !{!43} +!air.compile_options = !{!46, !47, !48} +!air.function_constants = !{!49, !50, !51, !52, !53, !54, !55} +!llvm.ident = !{!56} +!air.version = !{!57} +!air.language_version = !{!58} + +!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} +!1 = !{i32 1, !"wchar_size", i32 4} +!2 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{i32 7, !"air.max_device_buffers", i32 31} +!4 = !{i32 7, !"air.max_constant_buffers", i32 31} +!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31} +!6 = !{i32 7, !"air.max_textures", i32 128} +!7 = !{i32 7, !"air.max_read_write_textures", i32 8} +!8 = !{i32 7, !"air.max_samplers", i32 16} +!9 = !{void (i32 addrspace(1)*, i32)* @unspecialized_guarded, !10, !11} +!10 = !{} +!11 = !{!12, !13} +!12 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read_write", !"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", !"out"} +!13 = !{i32 1, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} +!14 = !{void (i32 addrspace(1)*, i32)* @unspecialized_free, !10, !11} +!15 = !{void (i32 addrspace(1)*, i32 addrspace(1)*, i32)* @unspecialized_gate, !10, !16} +!16 = !{!12, !17, !19} +!17 = !{i32 1, !"air.function_constant", !18, !"air.buffer", !"air.location_index", i32 1, 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", !"extra"} +!18 = !{i8 addrspace(2)* @__metal_implicit_fc_pred_0, !"bool", !"has_extra"} +!19 = !{i32 2, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} +!20 = !{void (%"struct.metal::_imageblock_base", <2 x i16>)* @unspecialized_tile, !10, !21} +!21 = !{!22, !24} +!22 = !{i32 0, !"air.imageblock", !"implicit", !"air.struct_type_info", !23, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"imageblock", !"air.arg_name", !"block"} +!23 = !{i32 0, i32 8, i32 0, !"half4", !"color", !"air.render_target", i32 0} +!24 = !{i32 1, !"air.thread_position_in_threadgroup", !"air.arg_type_name", !"ushort2", !"air.arg_name", !"lid"} +!25 = !{<4 x float> (i32)* @unspecialized_vertex, !26, !28} +!26 = !{!27} +!27 = !{!"air.position", !"air.arg_type_name", !"float4"} +!28 = !{!29} +!29 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"} +!30 = !{<4 x float> (i32)* @unspecialized_vertex_free, !26, !28} +!31 = !{<4 x float> ()* @unspecialized_fragment, !32, !10} +!32 = !{!33} +!33 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"float4"} +!34 = !{<4 x float> ()* @unspecialized_fragment_free, !32, !10} +!35 = !{void (%struct._mesh_t addrspace(7)*, i32)* @unspecialized_mesh, !10, !36} +!36 = !{!37, !41} +!37 = !{i32 0, !"air.mesh", !38, !"air.arg_type_name", !"mesh", !"air.arg_name", !"m"} +!38 = !{!"air.mesh_type_info", !39, !10, i32 3, i32 1, !"air.triangle"} +!39 = !{!40} +!40 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!41 = !{i32 1, !"air.thread_index_in_threadgroup", !"air.arg_type_name", !"uint", !"air.arg_name", !"t"} +!42 = !{void (%struct._mesh_t addrspace(7)*, i32)* @unspecialized_mesh_free, !10, !36} +!43 = !{void (%struct._mesh_grid_properties_t addrspace(3)*)* @unspecialized_object, !10, !44} +!44 = !{!45} +!45 = !{i32 0, !"air.mesh_grid_properties", !"air.arg_type_name", !"mesh_grid_properties", !"air.arg_name", !"grid"} +!46 = !{!"air.compile.denorms_disable"} +!47 = !{!"air.compile.fast_math_enable"} +!48 = !{!"air.compile.framebuffer_fetch_enable"} +!49 = !{i32 addrspace(2)* @_Z14optional_count.MTL_FC_INIT_0_j, !"uint", !"optional_count", i32 0} +!50 = !{i8 addrspace(2)* @_Z9has_extra.MTL_FC_INIT_1_b, !"bool", !"has_extra", i32 1} +!51 = !{float addrspace(2)* @_Z12vertex_scale.MTL_FC_INIT_2_f, !"float", !"vertex_scale", i32 2} +!52 = !{float addrspace(2)* @_Z13fragment_tint.MTL_FC_INIT_3_f, !"float", !"fragment_tint", i32 3} +!53 = !{half addrspace(2)* @_Z9tile_tint.MTL_FC_INIT_4_Dh, !"half", !"tile_tint", i32 4} +!54 = !{float addrspace(2)* @_Z10mesh_scale.MTL_FC_INIT_5_f, !"float", !"mesh_scale", i32 5} +!55 = !{i32 addrspace(2)* @_Z12object_count.MTL_FC_INIT_6_j, !"uint", !"object_count", i32 6} +!56 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!57 = !{i32 2, i32 8, i32 0} +!58 = !{!"Metal", i32 4, i32 0, i32 0} +!59 = !{!60, !60, i64 0} +!60 = !{!"int", !61, i64 0} +!61 = !{!"omnipotent char", !62, i64 0} +!62 = !{!"Simple C++ TBAA"} +!63 = !{!64} +!64 = distinct !{!64, !65, !"air-alias-scope-arg(0)"} +!65 = distinct !{!65, !"air-alias-scopes(unspecialized_guarded)"} +!66 = !{!67} +!67 = distinct !{!67, !68, !"air-alias-scope-arg(0)"} +!68 = distinct !{!68, !"air-alias-scopes(unspecialized_free)"} +!69 = !{!70, !70, i64 0} +!70 = !{!"bool", !61, i64 0} +!71 = !{i8 0, i8 2} +!72 = !{!73} +!73 = distinct !{!73, !74, !"air-alias-scope-arg(1)"} +!74 = distinct !{!74, !"air-alias-scopes(unspecialized_gate)"} +!75 = !{!76} +!76 = distinct !{!76, !74, !"air-alias-scope-arg(0)"} +!77 = !{!78, !78, i64 0} +!78 = !{!"float", !61, i64 0} +!79 = !{!80, !80, i64 0} +!80 = !{!"half", !61, i64 0} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/unspecialized_stage_functions.ll b/crates/metal2vulkan-validation/fixtures/public/engine/unspecialized_stage_functions.ll new file mode 100644 index 000000000..3f6e88778 --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/unspecialized_stage_functions.ll @@ -0,0 +1,342 @@ +; Generated by scripts/regen-air-fixtures from unspecialized_stage_functions.metal (llvm-dis of unspecialized_stage_functions.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" + +%"struct.metal::_imageblock_base" = type { ptr addrspace(4) } + +@_ZL14optional_count = internal unnamed_addr addrspace(2) global i32 undef, align 4 +@_Z14optional_count.MTL_FC_INIT_0_j = linkonce_odr hidden addrspace(2) externally_initialized constant i32 undef, section "air.fc_initializer", align 4 +@_ZL9has_extra = internal unnamed_addr addrspace(2) global i8 undef, align 1 +@_Z9has_extra.MTL_FC_INIT_1_b = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant i8 undef, section "air.fc_initializer", align 1 +@_ZL12vertex_scale = internal unnamed_addr addrspace(2) global float undef, align 4 +@_Z12vertex_scale.MTL_FC_INIT_2_f = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant float undef, section "air.fc_initializer", align 4 +@_ZL13fragment_tint = internal unnamed_addr addrspace(2) global float undef, align 4 +@_Z13fragment_tint.MTL_FC_INIT_3_f = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant float undef, section "air.fc_initializer", align 4 +@_ZL9tile_tint = internal unnamed_addr addrspace(2) global half undef, align 2 +@_Z9tile_tint.MTL_FC_INIT_4_Dh = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant half undef, section "air.fc_initializer", align 2 +@_ZL10mesh_scale = internal unnamed_addr addrspace(2) global float undef, align 4 +@_Z10mesh_scale.MTL_FC_INIT_5_f = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant float undef, section "air.fc_initializer", align 4 +@_ZL12object_count = internal unnamed_addr addrspace(2) global i32 undef, align 4 +@_Z12object_count.MTL_FC_INIT_6_j = linkonce_odr hidden local_unnamed_addr addrspace(2) externally_initialized constant i32 undef, section "air.fc_initializer", align 4 +@__metal_implicit_fc_pred_0 = internal addrspace(2) global i8 0, align 1 +@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I__, ptr null }] +@llvm.compiler.used = appending global [1 x ptr] [ptr addrspacecast (ptr addrspace(2) @__metal_implicit_fc_pred_0 to ptr)], section "llvm.metadata" + +; Function Attrs: mustprogress nofree nosync nounwind willreturn +define void @unspecialized_guarded(ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %0, i32 noundef %1) local_unnamed_addr #0 { + %3 = tail call i1 @air.is_function_constant_defined(ptr addrspace(2) captures(none) @_Z14optional_count.MTL_FC_INIT_0_j) #14 + %4 = load i32, ptr addrspace(2) @_ZL14optional_count, align 4 + %5 = select i1 %3, i32 %4, i32 7 + %6 = zext i32 %1 to i64 + %7 = getelementptr inbounds i32, ptr addrspace(1) %0, i64 %6 + store i32 %5, ptr addrspace(1) %7, align 4, !tbaa !59, !alias.scope !63 + ret void +} + +; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) +declare i1 @air.is_function_constant_defined(ptr addrspace(2) captures(none)) local_unnamed_addr #1 + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) +define void @unspecialized_free(ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %0, i32 noundef %1) local_unnamed_addr #2 { + %3 = zext i32 %1 to i64 + %4 = getelementptr inbounds i32, ptr addrspace(1) %0, i64 %3 + store i32 9, ptr addrspace(1) %4, align 4, !tbaa !59, !alias.scope !66 + ret void +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn +define void @unspecialized_gate(ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %0, ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %1, i32 noundef %2) local_unnamed_addr #3 { + %4 = load i8, ptr addrspace(2) @_ZL9has_extra, align 1, !tbaa !69, !range !71 + %5 = icmp eq i8 %4, 0 + %6 = zext i32 %2 to i64 + br i1 %5, label %10, label %7 + +7: ; preds = %3 + %8 = getelementptr inbounds i32, ptr addrspace(1) %1, i64 %6 + %9 = load i32, ptr addrspace(1) %8, align 4, !tbaa !59, !alias.scope !72, !noalias !75 + br label %10 + +10: ; preds = %7, %3 + %11 = phi i32 [ %9, %7 ], [ 2, %3 ] + %12 = getelementptr inbounds i32, ptr addrspace(1) %0, i64 %6 + store i32 %11, ptr addrspace(1) %12, align 4, !tbaa !59, !alias.scope !75, !noalias !72 + ret void +} + +; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) +declare i8 @air.normalize_function_constant_predicate.i8(i8) local_unnamed_addr #1 + +; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read) +define <4 x float> @unspecialized_vertex(i32 noundef %0) local_unnamed_addr #4 { + %2 = and i32 %0, 1 + %3 = tail call fast float @air.convert.f.f32.u.i32(i32 %2) #14 + %4 = load float, ptr addrspace(2) @_ZL12vertex_scale, align 4, !tbaa !77 + %5 = fmul fast float %4, %3 + %6 = lshr i32 %0, 1 + %7 = tail call fast float @air.convert.f.f32.u.i32(i32 %6) #14 + %8 = insertelement <4 x float> , float %5, i64 0 + %9 = insertelement <4 x float> %8, float %7, i64 1 + ret <4 x float> %9 +} + +; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) +declare float @air.convert.f.f32.u.i32(i32) local_unnamed_addr #1 + +; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) +define <4 x float> @unspecialized_vertex_free(i32 noundef %0) local_unnamed_addr #5 { + %2 = and i32 %0, 1 + %3 = tail call fast float @air.convert.f.f32.u.i32(i32 %2) #14 + %4 = lshr i32 %0, 1 + %5 = tail call fast float @air.convert.f.f32.u.i32(i32 %4) #14 + %6 = insertelement <4 x float> , float %3, i64 0 + %7 = insertelement <4 x float> %6, float %5, i64 1 + ret <4 x float> %7 +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read) +define <4 x float> @unspecialized_fragment() local_unnamed_addr #6 { + %1 = load float, ptr addrspace(2) @_ZL13fragment_tint, align 4, !tbaa !77 + %2 = insertelement <4 x float> , float %1, i64 0 + ret <4 x float> %2 +} + +; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) +define <4 x float> @unspecialized_fragment_free() local_unnamed_addr #7 { + ret <4 x float> +} + +; Function Attrs: mustprogress nounwind willreturn +define void @unspecialized_tile(%"struct.metal::_imageblock_base" %0, <2 x i16> noundef %1) local_unnamed_addr #8 { + %3 = tail call fast <4 x half> @air.load.implicit_imageblock.v4f16(i32 0, <2 x i16> %1, i32 0, i16 0) #15 + %4 = load half, ptr addrspace(2) @_ZL9tile_tint, align 2, !tbaa !79 + %5 = insertelement <4 x half> poison, half %4, i64 0 + %6 = shufflevector <4 x half> %5, <4 x half> poison, <4 x i32> zeroinitializer + %7 = fmul fast <4 x half> %6, %3 + tail call void @air.store.implicit_imageblock.v4f16(<4 x half> %7, i32 0, <2 x i16> %1, i32 0, i16 0) #16 + ret void +} + +; Function Attrs: mustprogress nounwind willreturn +define void @unspecialized_mesh(ptr addrspace(7) %0, i32 noundef %1) local_unnamed_addr #9 { + %3 = icmp eq i32 %1, 0 + br i1 %3, label %4, label %5 + +4: ; preds = %2 + tail call void @air.set_primitive_count_mesh(ptr addrspace(7) captures(none) %0, i32 1) #17 + tail call void @air.set_index_mesh(ptr addrspace(7) captures(none) %0, i32 0, i8 0) #17 + tail call void @air.set_index_mesh(ptr addrspace(7) captures(none) %0, i32 1, i8 1) #17 + tail call void @air.set_index_mesh(ptr addrspace(7) captures(none) %0, i32 2, i8 2) #17 + br label %5 + +5: ; preds = %4, %2 + %6 = icmp ult i32 %1, 3 + br i1 %6, label %7, label %16 + +7: ; preds = %5 + %8 = and i32 %1, 1 + %9 = tail call fast float @air.convert.f.f32.u.i32(i32 %8) #14 + %10 = load float, ptr addrspace(2) @_ZL10mesh_scale, align 4, !tbaa !77 + %11 = fmul fast float %10, %9 + %12 = lshr i32 %1, 1 + %13 = tail call fast float @air.convert.f.f32.u.i32(i32 %12) #14 + %14 = insertelement <4 x float> , float %11, i64 0 + %15 = insertelement <4 x float> %14, float %13, i64 1 + tail call void @air.set_position_mesh(ptr addrspace(7) captures(none) %0, i32 %1, <4 x float> %15) #17 + br label %16 + +16: ; preds = %7, %5 + ret void +} + +; Function Attrs: mustprogress nounwind willreturn +define void @unspecialized_mesh_free(ptr addrspace(7) %0, i32 noundef %1) local_unnamed_addr #9 { + %3 = icmp eq i32 %1, 0 + br i1 %3, label %4, label %5 + +4: ; preds = %2 + tail call void @air.set_primitive_count_mesh(ptr addrspace(7) captures(none) %0, i32 1) #17 + tail call void @air.set_index_mesh(ptr addrspace(7) captures(none) %0, i32 0, i8 0) #17 + tail call void @air.set_index_mesh(ptr addrspace(7) captures(none) %0, i32 1, i8 1) #17 + tail call void @air.set_index_mesh(ptr addrspace(7) captures(none) %0, i32 2, i8 2) #17 + br label %5 + +5: ; preds = %4, %2 + %6 = icmp ult i32 %1, 3 + br i1 %6, label %7, label %14 + +7: ; preds = %5 + %8 = and i32 %1, 1 + %9 = tail call fast float @air.convert.f.f32.u.i32(i32 %8) #14 + %10 = lshr i32 %1, 1 + %11 = tail call fast float @air.convert.f.f32.u.i32(i32 %10) #14 + %12 = insertelement <4 x float> , float %9, i64 0 + %13 = insertelement <4 x float> %12, float %11, i64 1 + tail call void @air.set_position_mesh(ptr addrspace(7) captures(none) %0, i32 %1, <4 x float> %13) #17 + br label %14 + +14: ; preds = %7, %5 + ret void +} + +; Function Attrs: mustprogress nounwind willreturn +define void @unspecialized_object(ptr addrspace(3) captures(none) %0) local_unnamed_addr #10 { + %2 = load i32, ptr addrspace(2) @_ZL12object_count, align 4, !tbaa !59 + %3 = add i32 %2, 1 + %4 = insertelement <3 x i32> , i32 %3, i64 0 + tail call void @air.set_threadgroups_per_grid_mesh_properties(ptr addrspace(3) captures(none) %0, <3 x i32> %4) #17 + ret void +} + +; Function Attrs: mustprogress nounwind willreturn memory(argmem: readwrite) +declare void @air.set_threadgroups_per_grid_mesh_properties(ptr addrspace(3) captures(none), <3 x i32>) local_unnamed_addr #11 + +; Function Attrs: mustprogress nofree nounwind willreturn memory(read) +declare <4 x half> @air.load.implicit_imageblock.v4f16(i32, <2 x i16>, i32, i16) local_unnamed_addr #12 + +; Function Attrs: mustprogress nounwind willreturn memory(write) +declare void @air.store.implicit_imageblock.v4f16(<4 x half>, i32, <2 x i16>, i32, i16) local_unnamed_addr #13 + +; Function Attrs: mustprogress nounwind willreturn memory(argmem: readwrite) +declare void @air.set_primitive_count_mesh(ptr addrspace(7) captures(none), i32) local_unnamed_addr #11 + +; Function Attrs: mustprogress nounwind willreturn memory(argmem: readwrite) +declare void @air.set_index_mesh(ptr addrspace(7) captures(none), i32, i8) local_unnamed_addr #11 + +; Function Attrs: mustprogress nounwind willreturn memory(argmem: readwrite) +declare void @air.set_position_mesh(ptr addrspace(7) captures(none), i32, <4 x float>) local_unnamed_addr #11 + +; Function Attrs: mustprogress nofree nosync nounwind willreturn +define internal void @_GLOBAL__sub_I__() #0 section "air.static_init" { + %1 = load i32, ptr addrspace(2) @_Z14optional_count.MTL_FC_INIT_0_j, align 4, !tbaa !59 + store i32 %1, ptr addrspace(2) @_ZL14optional_count, align 4, !tbaa !59 + %2 = load i8, ptr addrspace(2) @_Z9has_extra.MTL_FC_INIT_1_b, align 1, !tbaa !69, !range !71 + store i8 %2, ptr addrspace(2) @_ZL9has_extra, align 1, !tbaa !69 + %3 = load float, ptr addrspace(2) @_Z12vertex_scale.MTL_FC_INIT_2_f, align 4, !tbaa !77 + store float %3, ptr addrspace(2) @_ZL12vertex_scale, align 4, !tbaa !77 + %4 = load float, ptr addrspace(2) @_Z13fragment_tint.MTL_FC_INIT_3_f, align 4, !tbaa !77 + store float %4, ptr addrspace(2) @_ZL13fragment_tint, align 4, !tbaa !77 + %5 = load half, ptr addrspace(2) @_Z9tile_tint.MTL_FC_INIT_4_Dh, align 2, !tbaa !79 + store half %5, ptr addrspace(2) @_ZL9tile_tint, align 2, !tbaa !79 + %6 = load float, ptr addrspace(2) @_Z10mesh_scale.MTL_FC_INIT_5_f, align 4, !tbaa !77 + store float %6, ptr addrspace(2) @_ZL10mesh_scale, align 4, !tbaa !77 + %7 = load i32, ptr addrspace(2) @_Z12object_count.MTL_FC_INIT_6_j, align 4, !tbaa !59 + store i32 %7, ptr addrspace(2) @_ZL12object_count, align 4, !tbaa !59 + %8 = tail call i8 @air.normalize_function_constant_predicate.i8(i8 %2) #14 + store i8 %8, ptr addrspace(2) @__metal_implicit_fc_pred_0, align 1 + ret void +} + +attributes #0 = { mustprogress nofree nosync nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #1 = { mustprogress nofree nosync nounwind willreturn memory(none) } +attributes #2 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #3 = { mustprogress nofree norecurse nosync nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #4 = { mustprogress nofree nosync nounwind willreturn memory(read) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #5 = { mustprogress 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 #6 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #7 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="128" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #8 = { mustprogress 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 #9 = { mustprogress nounwind 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 #10 = { mustprogress nounwind willreturn "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="96" "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 #11 = { mustprogress nounwind willreturn memory(argmem: readwrite) } +attributes #12 = { mustprogress nofree nounwind willreturn memory(read) } +attributes #13 = { mustprogress nounwind willreturn memory(write) } +attributes #14 = { nounwind willreturn memory(none) } +attributes #15 = { nounwind willreturn memory(read) } +attributes #16 = { nounwind willreturn memory(write) } +attributes #17 = { nounwind willreturn memory(argmem: readwrite) } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.kernel = !{!9, !14, !15, !20} +!air.vertex = !{!25, !30} +!air.fragment = !{!31, !34} +!air.mesh = !{!35, !42} +!air.object = !{!43} +!air.compile_options = !{!46, !47, !48} +!air.function_constants = !{!49, !50, !51, !52, !53, !54, !55} +!llvm.ident = !{!56} +!air.version = !{!57} +!air.language_version = !{!58} + +!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} +!1 = !{i32 1, !"wchar_size", i32 4} +!2 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{i32 7, !"air.max_device_buffers", i32 31} +!4 = !{i32 7, !"air.max_constant_buffers", i32 31} +!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31} +!6 = !{i32 7, !"air.max_textures", i32 128} +!7 = !{i32 7, !"air.max_read_write_textures", i32 8} +!8 = !{i32 7, !"air.max_samplers", i32 16} +!9 = !{ptr @unspecialized_guarded, !10, !11} +!10 = !{} +!11 = !{!12, !13} +!12 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read_write", !"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", !"out"} +!13 = !{i32 1, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} +!14 = !{ptr @unspecialized_free, !10, !11} +!15 = !{ptr @unspecialized_gate, !10, !16} +!16 = !{!12, !17, !19} +!17 = !{i32 1, !"air.function_constant", !18, !"air.buffer", !"air.location_index", i32 1, 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", !"extra"} +!18 = !{ptr addrspace(2) @__metal_implicit_fc_pred_0, !"bool", !"has_extra"} +!19 = !{i32 2, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"tid"} +!20 = !{ptr @unspecialized_tile, !10, !21} +!21 = !{!22, !24} +!22 = !{i32 0, !"air.imageblock", !"implicit", !"air.struct_type_info", !23, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"imageblock", !"air.arg_name", !"block"} +!23 = !{i32 0, i32 8, i32 0, !"half4", !"color", !"air.render_target", i32 0} +!24 = !{i32 1, !"air.thread_position_in_threadgroup", !"air.arg_type_name", !"ushort2", !"air.arg_name", !"lid"} +!25 = !{ptr @unspecialized_vertex, !26, !28} +!26 = !{!27} +!27 = !{!"air.position", !"air.arg_type_name", !"float4"} +!28 = !{!29} +!29 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"} +!30 = !{ptr @unspecialized_vertex_free, !26, !28} +!31 = !{ptr @unspecialized_fragment, !32, !10} +!32 = !{!33} +!33 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"float4"} +!34 = !{ptr @unspecialized_fragment_free, !32, !10} +!35 = !{ptr @unspecialized_mesh, !10, !36} +!36 = !{!37, !41} +!37 = !{i32 0, !"air.mesh", !38, !"air.arg_type_name", !"mesh", !"air.arg_name", !"m"} +!38 = !{!"air.mesh_type_info", !39, !10, i32 3, i32 1, !"air.triangle"} +!39 = !{!40} +!40 = !{!"air.position", !"air.arg_type_name", !"float4", !"air.arg_name", !"position"} +!41 = !{i32 1, !"air.thread_index_in_threadgroup", !"air.arg_type_name", !"uint", !"air.arg_name", !"t"} +!42 = !{ptr @unspecialized_mesh_free, !10, !36} +!43 = !{ptr @unspecialized_object, !10, !44} +!44 = !{!45} +!45 = !{i32 0, !"air.mesh_grid_properties", !"air.arg_type_name", !"mesh_grid_properties", !"air.arg_name", !"grid"} +!46 = !{!"air.compile.denorms_disable"} +!47 = !{!"air.compile.fast_math_enable"} +!48 = !{!"air.compile.framebuffer_fetch_enable"} +!49 = !{ptr addrspace(2) @_Z14optional_count.MTL_FC_INIT_0_j, !"uint", !"optional_count", i32 0} +!50 = !{ptr addrspace(2) @_Z9has_extra.MTL_FC_INIT_1_b, !"bool", !"has_extra", i32 1} +!51 = !{ptr addrspace(2) @_Z12vertex_scale.MTL_FC_INIT_2_f, !"float", !"vertex_scale", i32 2} +!52 = !{ptr addrspace(2) @_Z13fragment_tint.MTL_FC_INIT_3_f, !"float", !"fragment_tint", i32 3} +!53 = !{ptr addrspace(2) @_Z9tile_tint.MTL_FC_INIT_4_Dh, !"half", !"tile_tint", i32 4} +!54 = !{ptr addrspace(2) @_Z10mesh_scale.MTL_FC_INIT_5_f, !"float", !"mesh_scale", i32 5} +!55 = !{ptr addrspace(2) @_Z12object_count.MTL_FC_INIT_6_j, !"uint", !"object_count", i32 6} +!56 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!57 = !{i32 2, i32 8, i32 0} +!58 = !{!"Metal", i32 4, i32 0, i32 0} +!59 = !{!60, !60, i64 0} +!60 = !{!"int", !61, i64 0} +!61 = !{!"omnipotent char", !62, i64 0} +!62 = !{!"Simple C++ TBAA"} +!63 = !{!64} +!64 = distinct !{!64, !65, !"air-alias-scope-arg(0)"} +!65 = distinct !{!65, !"air-alias-scopes(unspecialized_guarded)"} +!66 = !{!67} +!67 = distinct !{!67, !68, !"air-alias-scope-arg(0)"} +!68 = distinct !{!68, !"air-alias-scopes(unspecialized_free)"} +!69 = !{!70, !70, i64 0} +!70 = !{!"bool", !61, i64 0} +!71 = !{i8 0, i8 2} +!72 = !{!73} +!73 = distinct !{!73, !74, !"air-alias-scope-arg(1)"} +!74 = distinct !{!74, !"air-alias-scopes(unspecialized_gate)"} +!75 = !{!76} +!76 = distinct !{!76, !74, !"air-alias-scope-arg(0)"} +!77 = !{!78, !78, i64 0} +!78 = !{!"float", !61, i64 0} +!79 = !{!80, !80, i64 0} +!80 = !{!"half", !61, i64 0} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/unspecialized_stage_functions.metal b/crates/metal2vulkan-validation/fixtures/public/engine/unspecialized_stage_functions.metal new file mode 100644 index 000000000..44a873b8b --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/unspecialized_stage_functions.metal @@ -0,0 +1,93 @@ +// Owned MSL: stage functions of every kind a pipeline state takes, each declaring a function +// constant or none, the shapes of the probe `undefined_function_constant_values.m`. Metal makes no +// state of a function made by `newFunctionWithName:` that declares a constant, whether it reads it +// only where `is_function_constant_defined` says (`unspecialized_guarded`) or the constant gates an +// argument (`unspecialized_gate`), and makes one of each made with constant values, none among +// them too. The `_free` functions declare none. Loop-free. +#include +using namespace metal; + +constant uint optional_count [[function_constant(0)]]; +constant bool has_extra [[function_constant(1)]]; +constant float vertex_scale [[function_constant(2)]]; +constant float fragment_tint [[function_constant(3)]]; +constant half tile_tint [[function_constant(4)]]; +constant float mesh_scale [[function_constant(5)]]; +constant uint object_count [[function_constant(6)]]; + +kernel void unspecialized_guarded(device uint *out [[buffer(0)]], + uint tid [[thread_position_in_grid]]) { + out[tid] = is_function_constant_defined(optional_count) ? optional_count : 7u; +} + +kernel void unspecialized_free(device uint *out [[buffer(0)]], + uint tid [[thread_position_in_grid]]) { + out[tid] = 9u; +} + +kernel void unspecialized_gate(device uint *out [[buffer(0)]], + device const uint *extra [[buffer(1), function_constant(has_extra)]], + uint tid [[thread_position_in_grid]]) { + out[tid] = has_extra ? extra[tid] : 2u; +} + +vertex float4 unspecialized_vertex(uint vid [[vertex_id]]) { + return float4(float(vid & 1u) * vertex_scale, float(vid >> 1), 0.0f, 1.0f); +} + +vertex float4 unspecialized_vertex_free(uint vid [[vertex_id]]) { + return float4(float(vid & 1u), float(vid >> 1), 0.0f, 1.0f); +} + +fragment float4 unspecialized_fragment() { return float4(fragment_tint, 0.0f, 0.0f, 1.0f); } + +fragment float4 unspecialized_fragment_free() { return float4(1.0f, 0.0f, 0.0f, 1.0f); } + +struct TileColor { + half4 color [[color(0)]]; +}; + +kernel void unspecialized_tile(imageblock block, + ushort2 lid [[thread_position_in_threadgroup]]) { + TileColor v = block.read(lid); + v.color *= tile_tint; + block.write(v, lid); +} + +struct MeshVertex { + float4 position [[position]]; +}; + +using Triangle = metal::mesh; + +[[mesh]] void unspecialized_mesh(Triangle m, uint t [[thread_index_in_threadgroup]]) { + if (t == 0u) { + m.set_primitive_count(1u); + m.set_index(0u, 0u); + m.set_index(1u, 1u); + m.set_index(2u, 2u); + } + if (t < 3u) { + MeshVertex v; + v.position = float4(float(t & 1u) * mesh_scale, float(t >> 1), 0.0f, 1.0f); + m.set_vertex(t, v); + } +} + +[[mesh]] void unspecialized_mesh_free(Triangle m, uint t [[thread_index_in_threadgroup]]) { + if (t == 0u) { + m.set_primitive_count(1u); + m.set_index(0u, 0u); + m.set_index(1u, 1u); + m.set_index(2u, 2u); + } + if (t < 3u) { + MeshVertex v; + v.position = float4(float(t & 1u), float(t >> 1), 0.0f, 1.0f); + m.set_vertex(t, v); + } +} + +[[object]] void unspecialized_object(mesh_grid_properties grid) { + grid.set_threadgroups_per_grid(uint3(object_count + 1u, 1u, 1u)); +} diff --git a/crates/metal2vulkan-validation/src/runtime_lane.rs b/crates/metal2vulkan-validation/src/runtime_lane.rs index 999d099ed..64c9a1131 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane.rs @@ -839,6 +839,8 @@ mod uniform_varyings; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod unorm_depth_bias; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] +mod unspecialized_functions; +#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod used_resources; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod vertex_cost; diff --git a/crates/metal2vulkan-validation/src/runtime_lane/unspecialized_functions.rs b/crates/metal2vulkan-validation/src/runtime_lane/unspecialized_functions.rs new file mode 100644 index 000000000..8345fafbf --- /dev/null +++ b/crates/metal2vulkan-validation/src/runtime_lane/unspecialized_functions.rs @@ -0,0 +1,263 @@ +//! Pipeline states of stage functions made by name or specialized, through the runtime on the +//! device the cfg selects, under the validation layer, against what the probe +//! `undefined_function_constant_values.m` (the conformance crate's `probes/`) measured on an +//! Apple M3 Max under macOS 27.0.1: plain Metal ends its process at a state of a function made by +//! `newFunctionWithName:` that declares a function constant, at every stage, and makes one of a +//! function made by name that declares none, and of every function made with constant values, +//! none among them too, or by `newFunctionWithDescriptor:`. +//! +//! The library is the owned fixture `unspecialized_stage_functions`: kernels +//! `unspecialized_guarded` (stores its optional constant where it is defined, else 7: the probe's +//! `ko`), `unspecialized_gate` (a constant gates its buffer 1, which it reads where the constant is +//! true) and `unspecialized_free` (stores 9: the probe's `kn`); vertex, +//! fragment, tile, mesh and object functions reading a constant, and vertex, fragment and mesh +//! functions reading none (`_free`). + +use super::host_memory::{on_device, run}; +use super::read_buffer; +use crate::air_library::AirLibrary; +use metal2vulkan::library::FunctionConstantValues; +use metal2vulkan::metal::PixelFormat; +use metal2vulkan::pipeline::{ + ColorAttachmentDescriptor, MeshPipelineDescriptor, RenderPipelineDescriptor, Stage, + StageSource, TileRenderPipelineDescriptor, +}; +use metal2vulkan_devtools::{engine_dir, llvm_assemble}; +use metal2vulkan_runtime::{ + Device, Error, Function, FunctionDescriptor, Invalid, Library, PipelineOptions, Problem, + ResourceOptions, Size, +}; + +/// How a function is made. +#[derive(Clone, Copy, Debug)] +enum Made { + /// `newFunctionWithName:`. + ByName, + /// `newFunctionWithName:constantValues:` with no value. + Empty, + /// `newFunctionWithDescriptor:` with no constant values. + Descriptor, +} + +/// The fixture's library. +fn library(device: &Device) -> Library { + let air = llvm_assemble(&engine_dir().join("unspecialized_stage_functions.ll")).unwrap(); + device.new_library_with_air(&air).unwrap() +} + +/// Function `name` of `library`, made `how`. +fn made(library: &Library, name: &str, how: Made) -> Function { + match how { + Made::ByName => library.new_function_with_name(name), + Made::Empty => library + .new_function_with_name_constant_values(name, &FunctionConstantValues::defaults()), + Made::Descriptor => library.new_function_with_descriptor(&FunctionDescriptor::new(name)), + } + .unwrap() +} + +/// The refusal in `call` of the function `name` of `stage`. +fn unspecialized(call: &'static str, stage: Stage, name: &str) -> Error { + Error::Invalid(Invalid::new( + call, + Problem::UnspecializedFunction { + stage, + name: name.to_owned(), + }, + )) +} + +/// Whether `made` is the refusal of an unspecialized function. +fn refused_unspecialized(made: &Result) -> bool { + matches!(made, Err(Error::Invalid(i)) + if matches!(i.problem, Problem::UnspecializedFunction { .. })) +} + +/// The word kernel `f`'s compute state stores at thread 0, buffers 0 and 1 bound, or the +/// creation's refusal. +fn word(device: &Device, f: &Function) -> Result { + let state = device.new_compute_pipeline_state_with_function(f, &PipelineOptions::default())?; + let out = device.new_buffer(16, ResourceOptions::shared()).unwrap(); + let extra = device.new_buffer(16, ResourceOptions::shared()).unwrap(); + let queue = device.new_command_queue().unwrap(); + let command_buffer = queue.command_buffer().unwrap(); + let mut encoder = command_buffer.compute_command_encoder().unwrap(); + encoder.set_compute_pipeline_state(&state).unwrap(); + encoder.set_buffer(Some(&out), 0, 0).unwrap(); + encoder.set_buffer(Some(&extra), 0, 1).unwrap(); + encoder + .dispatch_threads(Size::new(1, 1, 1), Size::new(1, 1, 1)) + .unwrap(); + encoder.end_encoding().unwrap(); + run(&command_buffer); + let bytes = read_buffer(&out, 0, 4).unwrap(); + Ok(u32::from_le_bytes(bytes[..4].try_into().unwrap())) +} + +/// The render state of `vertex` and `fragment` into one BGRA8Unorm attachment, made or refused. +fn render(device: &Device, vertex: &Function, fragment: &Function) -> Result<(), Error> { + let mut d = RenderPipelineDescriptor::new(StageSource::Function(vertex.function_descriptor())); + d.fragment = Some(StageSource::Function(fragment.function_descriptor())); + d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::BGRA8Unorm)); + device + .new_render_pipeline_state(&d, &PipelineOptions::default()) + .map(|_| ()) +} + +/// The tile state of `tile` over one BGRA8Unorm color, made or refused. +fn tile(device: &Device, tile: &Function) -> Result<(), Error> { + let mut d = + TileRenderPipelineDescriptor::new(StageSource::Function(tile.function_descriptor())); + d.color_attachment_formats[0] = Some(PixelFormat::BGRA8Unorm); + d.threadgroup_size_matches_tile_size = true; + device + .new_tile_render_pipeline_state(&d, &PipelineOptions::default()) + .map(|_| ()) +} + +/// The mesh render state of `object` where given, `mesh` and `fragment`, into one BGRA8Unorm +/// attachment, made or refused. +fn mesh( + device: &Device, + object: Option<&Function>, + mesh: &Function, + fragment: &Function, +) -> Result<(), Error> { + let mut d = MeshPipelineDescriptor::new(StageSource::Function(mesh.function_descriptor())); + d.object = object.map(|f| StageSource::Function(f.function_descriptor())); + d.fragment = Some(StageSource::Function(fragment.function_descriptor())); + d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::BGRA8Unorm)); + device + .new_mesh_render_pipeline_state(&d, &PipelineOptions::default()) + .map(|_| ()) +} + +/// A kernel made by name that declares a constant makes no compute state, whether it reads the +/// constant only where it is defined or the constant gates its argument (the probe's `by-name:ko` +/// and `by-name:kg`); one that declares none stores 9 (`by-name:kn`). Made with no constant value +/// or by descriptor, each is made: the guarded kernel stores 7, as Metal's `ko` stored, and the +/// gated one what its undefined constant reads (docs/API.md, "Function constants"; Metal's `kg` +/// stored nothing). +#[test] +fn a_kernel_made_by_name_that_declares_a_constant_makes_no_compute_state() { + on_device(|device| { + let library = library(device); + let call = "new_compute_pipeline_state"; + for name in ["unspecialized_guarded", "unspecialized_gate"] { + assert_eq!( + word(device, &made(&library, name, Made::ByName)), + Err(unspecialized(call, Stage::Kernel, name)), + "{name}" + ); + } + let free = "unspecialized_free"; + assert_eq!(word(device, &made(&library, free, Made::ByName)), Ok(9)); + for how in [Made::Empty, Made::Descriptor] { + let guarded = made(&library, "unspecialized_guarded", how); + assert_eq!(word(device, &guarded), Ok(7), "{how:?}"); + let gate = made(&library, "unspecialized_gate", how); + let gated = word(device, &gate); + assert!(gated.is_ok(), "{how:?}: {gated:?}"); + assert_eq!(word(device, &made(&library, free, how)), Ok(9), "{how:?}"); + } + }); +} + +/// A vertex or fragment function made by name that declares a constant makes no render state, +/// beside a function made by name that declares none (the probe's `by-name:vertex` and +/// `by-name:fragment`); two that declare none make one (`by-name:plain`), and so does each made +/// with no constant value or by descriptor (`empty:*`, `descriptor:*`). +#[test] +fn a_render_function_made_by_name_that_declares_a_constant_makes_no_render_state() { + on_device(|device| { + let library = library(device); + let call = "new_render_pipeline_state"; + let f = |name, how| made(&library, name, how); + let vertex_free = f("unspecialized_vertex_free", Made::ByName); + let fragment_free = f("unspecialized_fragment_free", Made::ByName); + assert_eq!( + render( + device, + &f("unspecialized_vertex", Made::ByName), + &fragment_free + ), + Err(unspecialized(call, Stage::Vertex, "unspecialized_vertex")) + ); + assert_eq!( + render( + device, + &vertex_free, + &f("unspecialized_fragment", Made::ByName) + ), + Err(unspecialized( + call, + Stage::Fragment, + "unspecialized_fragment" + )) + ); + assert_eq!(render(device, &vertex_free, &fragment_free), Ok(())); + for how in [Made::Empty, Made::Descriptor] { + let vertex = f("unspecialized_vertex", how); + assert_eq!(render(device, &vertex, &fragment_free), Ok(()), "{how:?}"); + let fragment = f("unspecialized_fragment", how); + assert_eq!(render(device, &vertex_free, &fragment), Ok(()), "{how:?}"); + } + }); +} + +/// A tile, mesh or object function made by name that declares a constant makes no state (the +/// probe's `by-name:tile`, `by-name:mesh` and `by-name:object`), before anything the device lacks +/// for it is asked. Made with no constant value or by descriptor, or made by name declaring none, +/// none is refused as unspecialized; the device may refuse such a state for what it lacks (tile or +/// mesh shading). +#[test] +fn a_tile_mesh_or_object_function_made_by_name_that_declares_a_constant_makes_no_state() { + on_device(|device| { + let library = library(device); + let f = |name, how| made(&library, name, how); + let mesh_free = f("unspecialized_mesh_free", Made::ByName); + let fragment_free = f("unspecialized_fragment_free", Made::ByName); + assert_eq!( + tile(device, &f("unspecialized_tile", Made::ByName)), + Err(unspecialized( + "new_tile_render_pipeline_state", + Stage::Kernel, + "unspecialized_tile" + )) + ); + let call = "new_mesh_render_pipeline_state"; + assert_eq!( + mesh( + device, + None, + &f("unspecialized_mesh", Made::ByName), + &fragment_free + ), + Err(unspecialized(call, Stage::Mesh, "unspecialized_mesh")) + ); + let object = f("unspecialized_object", Made::ByName); + assert_eq!( + mesh(device, Some(&object), &mesh_free, &fragment_free), + Err(unspecialized(call, Stage::Object, "unspecialized_object")) + ); + assert!(!refused_unspecialized(&mesh( + device, + None, + &mesh_free, + &fragment_free + ))); + for how in [Made::Empty, Made::Descriptor] { + let made_tile = tile(device, &f("unspecialized_tile", how)); + assert!(!refused_unspecialized(&made_tile), "{how:?}: {made_tile:?}"); + let mesh_constant = f("unspecialized_mesh", how); + let made_mesh = mesh(device, None, &mesh_constant, &fragment_free); + assert!(!refused_unspecialized(&made_mesh), "{how:?}: {made_mesh:?}"); + let object = f("unspecialized_object", how); + let made_object = mesh(device, Some(&object), &mesh_free, &fragment_free); + assert!( + !refused_unspecialized(&made_object), + "{how:?}: {made_object:?}" + ); + } + }); +} diff --git a/crates/metal2vulkan/src/library/function.rs b/crates/metal2vulkan/src/library/function.rs index a99ef701c..70eec3512 100644 --- a/crates/metal2vulkan/src/library/function.rs +++ b/crates/metal2vulkan/src/library/function.rs @@ -566,6 +566,17 @@ impl Function { /// takes); and the decode's own errors. pub fn function_constants_dictionary( &self, + ) -> Result, Error> { + let mut m = Meter::new(&Budget::standard()); + self.constants_dictionary_with(|bitcode, m| Ok(crate::air::decode(bitcode, m)?), &mut m) + } + + /// [`Function::function_constants_dictionary`] under `m`, a module function's AIR decoded by + /// `decode` (`pipeline::compile`'s stage entries copy a decode they keep). + pub(crate) fn constants_dictionary_with( + &self, + decode: impl FnOnce(&[u8], &mut Meter) -> Result, + m: &mut Meter, ) -> Result, Error> { let e = self.entry()?; let index = match &e.source { @@ -576,9 +587,8 @@ impl Function { EntrySource::Module { index } | EntrySource::Visible { index } => *index, }; let bitcode = self.bitcode()?; - let mut m = Meter::new(&Budget::standard()); crate::pipeline::compile::guarded(|| { - let decoded = crate::air::decode(bitcode, &mut m)?; + let decoded = decode(bitcode, m)?; let abi = &decoded.abi; let i = usize::try_from(index).ok(); let func = match &e.source { @@ -588,7 +598,7 @@ impl Function { _ => i.and_then(|i| abi.entries.get(i)).map(|ep| ep.func), } .ok_or_else(|| invariant("a library function outside its module"))?; - crate::reflection::module_constants(&decoded.module, abi, func, &e.name, &mut m) + crate::reflection::module_constants(&decoded.module, abi, func, &e.name, m) }) } @@ -708,8 +718,13 @@ pub struct FunctionConstant { /// Function-constant values supplied with a function (`MTLFunctionConstantValues`), by index or by /// name. A constant with no value is "not defined": `is_function_constant_defined` folds to false, /// arguments gated on it are absent, a branch or `select` on it takes its false way, and a value -/// computed from it alone is its type's zero. Plain Metal makes such a function's pipeline too, and -/// its own reads of the constant vary from read to read (docs/API.md, "Accepted differences"). +/// computed from it alone is its type's zero. It compiles for a specialized function (made with +/// constant values, none among them too, or by `newFunctionWithDescriptor:`), whose pipeline plain +/// Metal makes too, its own reads of the constant varying from read to read (docs/API.md, +/// "Accepted differences"). Metal makes no pipeline state of a function made by +/// `newFunctionWithName:` whose function declares a constant: its creation ends the process +/// ([`FunctionDescriptor::needs_specialization`](crate::pipeline::FunctionDescriptor::needs_specialization)), +/// and the runtime refuses it as Metal does. #[non_exhaustive] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index 1f4fc21b5..7e77bc686 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -1154,6 +1154,23 @@ pub(crate) fn stage_returns_value( entries.returns_value(fd, |shared| stage_returns_value_read(fd, shared, m)) } +/// [`FunctionDescriptor::needs_specialization`] under `m`: a module function's constants read +/// through `entries`' module decodes, which a compile of the stage through the same object copies. +pub(crate) fn stage_needs_specialization( + fd: &FunctionDescriptor, + entries: &StageEntries, + m: &mut Meter, +) -> Result { + if fd.specialized || !fd.constants.is_empty() { + return Ok(false); + } + let air_hash = fd.function.info().air_hash; + let constants = fd + .function + .constants_dictionary_with(|bitcode, m| entries.module(&air_hash, bitcode, m), m)?; + Ok(!constants.is_empty()) +} + /// [`stage_returns_value`]'s own read of the AIR, which [`StageEntries`] keeps the answer of. It /// reads the module's decode from `shared`, the same object, so the answer and the stage's entry /// decode the module once between them. diff --git a/crates/metal2vulkan/src/pipeline/descriptor.rs b/crates/metal2vulkan/src/pipeline/descriptor.rs index 2ca88a312..fbcf117c1 100644 --- a/crates/metal2vulkan/src/pipeline/descriptor.rs +++ b/crates/metal2vulkan/src/pipeline/descriptor.rs @@ -10,10 +10,13 @@ use std::collections::BTreeMap; +use crate::budget::{Budget, Meter}; +use crate::error::Error; use crate::library::compiled::CompiledFunction; use crate::library::dynamic::DynamicLibrary; use crate::library::function::{Function, FunctionConstantValues}; use crate::metal; +use crate::pipeline::compile::StageEntries; /// A function plus its constant values and the functions its pipeline links /// (`MTLFunctionDescriptor` and the stage's `MTLLinkedFunctions`). @@ -22,6 +25,14 @@ use crate::metal; pub struct FunctionDescriptor { pub function: Function, pub constants: FunctionConstantValues, + /// Whether the function is specialized: made with constant values + /// (`newFunctionWithName:constantValues:error:`, none among them too) or by + /// `newFunctionWithDescriptor:error:`; `false`, the default, for one made by + /// `newFunctionWithName:`. A descriptor with `constants` is specialized whatever this says. + /// The compile is the same either way, a constant without a value undefined; Metal makes no + /// pipeline state of an unspecialized function that declares constants + /// ([`FunctionDescriptor::needs_specialization`]). + pub specialized: bool, /// The functions the stage links: each visible-function reference of `function` (and of each /// linked function) calls the linked function of the name it references. pub linked: LinkedFunctions, @@ -36,11 +47,38 @@ impl FunctionDescriptor { FunctionDescriptor { function, constants: FunctionConstantValues::defaults(), + specialized: false, linked: LinkedFunctions::default(), libraries: DynamicLibraries::default(), } } + /// This descriptor with `specialized` as whether its function is specialized + /// ([`FunctionDescriptor::specialized`]). + pub fn with_specialized(mut self, specialized: bool) -> FunctionDescriptor { + self.specialized = specialized; + self + } + + /// Whether Metal makes no pipeline state of this stage: its function is not specialized + /// ([`specialized`](Self::specialized) false, and no `constants`) and declares function + /// constants (its [`Function::function_constants_dictionary`] is not empty), whether each is + /// required or optional, read or only gating an argument. Plain Metal's creation ends its + /// process for one at its descriptor validation, at every pipeline creator ("function ko + /// cannot be used to build a pipeline state. Use newFunctionWithName:constantValues:... to get + /// the specialized function", an M3 Max under macOS 27.0.1). A module function's constants are + /// read of its AIR under `budget` through `entries`' module decodes, which a compile of the + /// stage through the same object copies; refused as + /// [`Function::function_constants_dictionary`] refuses. + pub fn needs_specialization( + &self, + budget: &Budget, + entries: &StageEntries, + ) -> Result { + let mut m = Meter::new(budget); + crate::pipeline::compile::stage_needs_specialization(self, entries, &mut m) + } + /// This descriptor with `linked` as its linked functions. pub fn with_linked(mut self, linked: LinkedFunctions) -> FunctionDescriptor { self.linked = linked; diff --git a/crates/metal2vulkan/src/tests/engine_unspecialized.rs b/crates/metal2vulkan/src/tests/engine_unspecialized.rs new file mode 100644 index 000000000..fd17a8b22 --- /dev/null +++ b/crates/metal2vulkan/src/tests/engine_unspecialized.rs @@ -0,0 +1,98 @@ +//! Whether Metal makes no pipeline state of a stage function made unspecialized +//! (`FunctionDescriptor::needs_specialization`), against what the probe +//! `undefined_function_constant_values.m` (the conformance crate's `probes/`) measured on an Apple +//! M3 Max under macOS 27.0.1: none of a function made by `newFunctionWithName:` that declares a +//! function constant, at every stage, and one of every function made with constant values, none +//! among them too, or by `newFunctionWithDescriptor:`. +//! +//! The owned fixture `engine/unspecialized_stage_functions`: a kernel reading its optional constant +//! only where it is defined, a kernel whose constant gates an argument, and vertex, fragment, tile, +//! mesh and object functions reading one, beside kernel, vertex, fragment and mesh functions that +//! declare none, in one module. `llvm-as` assembles it; a missing tool skips visibly. + +use crate::budget::Budget; +use crate::library::{FunctionConstantValue, FunctionConstantValues, Library}; +use crate::metal::DataType; +use crate::pipeline::testing::{engine_dir, llvm_assemble, AssembleError}; +use crate::pipeline::{FunctionDescriptor, StageEntries}; + +/// The functions that declare a constant: the probe's `ko`, `kg`, `vertex`, `fragment`, `tile`, +/// `mesh` and `object` shapes. +const DECLARING: [&str; 7] = [ + "unspecialized_guarded", + "unspecialized_gate", + "unspecialized_vertex", + "unspecialized_fragment", + "unspecialized_tile", + "unspecialized_mesh", + "unspecialized_object", +]; + +/// The functions that declare none: the probe's `kn`, `plain` and `mesh-plain` shapes. +const FREE: [&str; 4] = [ + "unspecialized_free", + "unspecialized_vertex_free", + "unspecialized_fragment_free", + "unspecialized_mesh_free", +]; + +/// The fixture's library, or `None` (skipped) without `llvm-as`. +fn library() -> Option { + let path = engine_dir().join("unspecialized_stage_functions.ll"); + match llvm_assemble(&path) { + Ok(bitcode) => Some(Library::from_air(&bitcode).expect("a library")), + Err(AssembleError::Missing(why)) => { + eprintln!("SKIPPED: {why}"); + None + } + Err(AssembleError::Rejected(why)) => panic!("llvm-as rejected the fixture: {why}"), + } +} + +/// Whether `descriptor` needs specialization, read through `entries`. +fn needs(descriptor: &FunctionDescriptor, entries: &StageEntries) -> bool { + descriptor + .needs_specialization(&Budget::standard(), entries) + .expect("an answer") +} + +/// A function made by name that declares a constant needs specialization at every stage, whether +/// it reads its constant only where it is defined or the constant gates an argument; one that +/// declares none does not (the probe's `by-name` cases). Every answer reads the one module decode +/// the first made. +#[test] +fn a_function_made_by_name_that_declares_a_constant_needs_specialization() { + let Some(library) = library() else { return }; + let entries = StageEntries::new(); + for name in DECLARING { + let by_name = FunctionDescriptor::new(library.function(name).unwrap()); + assert!(needs(&by_name, &entries), "{name}"); + } + for name in FREE { + let by_name = FunctionDescriptor::new(library.function(name).unwrap()); + assert!(!needs(&by_name, &entries), "{name}"); + } + assert_eq!(entries.decodes(), (1, 10)); +} + +/// No specialized function needs it: made with no constant value, by descriptor +/// (`specialized`), or with a value, whatever `specialized` says (the probe's `empty` and +/// `descriptor` cases). Decided without decoding anything. +#[test] +fn a_specialized_function_needs_no_specialization() { + let Some(library) = library() else { return }; + let entries = StageEntries::new(); + let valued = FunctionConstantValues::defaults().with_index( + 0, + FunctionConstantValue::new(DataType::UInt, 3u32.to_le_bytes()), + ); + for name in DECLARING.iter().chain(&FREE) { + let function = library.function(name).unwrap(); + let specialized = FunctionDescriptor::new(function.clone()).with_specialized(true); + assert!(!needs(&specialized, &entries), "{name}"); + let mut with_values = FunctionDescriptor::new(function); + with_values.constants = valued.clone(); + assert!(!needs(&with_values, &entries), "{name} with a value"); + } + assert_eq!(entries.decodes(), (0, 0)); +} diff --git a/crates/metal2vulkan/src/tests/mod.rs b/crates/metal2vulkan/src/tests/mod.rs index c14470fb8..492968613 100644 --- a/crates/metal2vulkan/src/tests/mod.rs +++ b/crates/metal2vulkan/src/tests/mod.rs @@ -161,6 +161,7 @@ mod engine_typed_clamp; mod engine_typed_threadgroup; mod engine_uniform_varyings; mod engine_unmeasured_speculation; +mod engine_unspecialized; mod engine_vertex_fetch; mod engine_vertex_variants; mod engine_viewport_compensation; diff --git a/crates/metal2vulkan/tests/air_input/unspecialized_stage_functions.txt b/crates/metal2vulkan/tests/air_input/unspecialized_stage_functions.txt new file mode 100644 index 000000000..0882ed3dd --- /dev/null +++ b/crates/metal2vulkan/tests/air_input/unspecialized_stage_functions.txt @@ -0,0 +1,420 @@ +target triple = "air64_v28-apple-macosx26.0.0" +source_filename = "-" +; datalayout DataLayout { endian: Little, pointers: {0: PointerSpec { size_bits: 64, abi_bits: 64, pref_bits: 64, index_bits: 64 }}, ints: {1: AlignSpec { abi_bits: 8, pref_bits: 8 }, 8: AlignSpec { abi_bits: 8, pref_bits: 8 }, 16: AlignSpec { abi_bits: 16, pref_bits: 16 }, 32: AlignSpec { abi_bits: 32, pref_bits: 32 }, 64: AlignSpec { abi_bits: 64, pref_bits: 64 }}, floats: {16: AlignSpec { abi_bits: 16, pref_bits: 16 }, 32: AlignSpec { abi_bits: 32, pref_bits: 32 }, 64: AlignSpec { abi_bits: 64, pref_bits: 64 }, 128: AlignSpec { abi_bits: 128, pref_bits: 128 }}, vectors: {16: AlignSpec { abi_bits: 16, pref_bits: 16 }, 24: AlignSpec { abi_bits: 32, pref_bits: 32 }, 32: AlignSpec { abi_bits: 32, pref_bits: 32 }, 48: AlignSpec { abi_bits: 64, pref_bits: 64 }, 64: AlignSpec { abi_bits: 64, pref_bits: 64 }, 96: AlignSpec { abi_bits: 128, pref_bits: 128 }, 128: AlignSpec { abi_bits: 128, pref_bits: 128 }, 192: AlignSpec { abi_bits: 256, pref_bits: 256 }, 256: AlignSpec { abi_bits: 256, pref_bits: 256 }, 512: AlignSpec { abi_bits: 512, pref_bits: 512 }, 1024: AlignSpec { abi_bits: 1024, pref_bits: 1024 }}, aggregate: AlignSpec { abi_bits: 0, pref_bits: 64 }, native_ints: [8, 16, 32], stack_align_bits: None, alloca_space: 0, program_space: 0, globals_space: 0, mangling: None, fn_ptr_align: None, non_integral: [] } +%t6 = type { i32, ptr addrspace(0), ptr addrspace(0) } +%t7 = type [1 x %t6] +%t8 = type [1 x ptr addrspace(0)] +%t11 = type void (ptr addrspace(1), i32) +%t13 = type i1 (ptr addrspace(2)) +%t14 = type void (ptr addrspace(1), ptr addrspace(1), i32) +%t15 = type i8 (i8) +%t17 = type <4 x float> (i32) +%t18 = type float (i32) +%t19 = type <4 x float> () +%t21 = type { ptr addrspace(4) } ; "struct.metal::_imageblock_base" +%t24 = type void (%t21, <2 x i16>) +%t26 = type void (ptr addrspace(7), i32) +%t28 = type void (ptr addrspace(3)) +%t30 = type void (ptr addrspace(3), <3 x i32>) +%t32 = type <4 x half> (i32, <2 x i16>, i32, i16) +%t33 = type void (<4 x half>, i32, <2 x i16>, i32, i16) +%t34 = type void (ptr addrspace(7), i32, i8) +%t35 = type void (ptr addrspace(7), i32, <4 x float>) +%t36 = type void () +%t38 = type [2 x i32] +c47 = %t6 [65535, @f20, zeroinitializer] +c48 = %t7 [c47] +c49 = ptr addrspace(0) addrspacecast (@g14) +c50 = %t8 [c49] +c51 = %t38 [27, 2] +c69 = <4 x float> [poison, poison, 0x0, 0x3F800000] +c71 = <4 x float> [poison, 0x0, 0x0, 0x3F800000] +c72 = <4 x float> [0x3F800000, 0x0, 0x0, 0x3F800000] +c78 = <3 x i32> [poison, 1, 1] +@g0 "_ZL14optional_count" = internal addrspace(2) global i32 undef, align 4 +@g1 "_Z14optional_count.MTL_FC_INIT_0_j" = linkonce_odr externally_initialized addrspace(2) constant i32 undef, align 4, section air.fc_initializer +@g2 "_ZL9has_extra" = internal addrspace(2) global i8 undef, align 1 +@g3 "_Z9has_extra.MTL_FC_INIT_1_b" = linkonce_odr externally_initialized addrspace(2) constant i8 undef, align 1, section air.fc_initializer +@g4 "_ZL12vertex_scale" = internal addrspace(2) global float undef, align 4 +@g5 "_Z12vertex_scale.MTL_FC_INIT_2_f" = linkonce_odr externally_initialized addrspace(2) constant float undef, align 4, section air.fc_initializer +@g6 "_ZL13fragment_tint" = internal addrspace(2) global float undef, align 4 +@g7 "_Z13fragment_tint.MTL_FC_INIT_3_f" = linkonce_odr externally_initialized addrspace(2) constant float undef, align 4, section air.fc_initializer +@g8 "_ZL9tile_tint" = internal addrspace(2) global half undef, align 2 +@g9 "_Z9tile_tint.MTL_FC_INIT_4_Dh" = linkonce_odr externally_initialized addrspace(2) constant half undef, align 2, section air.fc_initializer +@g10 "_ZL10mesh_scale" = internal addrspace(2) global float undef, align 4 +@g11 "_Z10mesh_scale.MTL_FC_INIT_5_f" = linkonce_odr externally_initialized addrspace(2) constant float undef, align 4, section air.fc_initializer +@g12 "_ZL12object_count" = internal addrspace(2) global i32 undef, align 4 +@g13 "_Z12object_count.MTL_FC_INIT_6_j" = linkonce_odr externally_initialized addrspace(2) constant i32 undef, align 4, section air.fc_initializer +@g14 "__metal_implicit_fc_pred_0" = internal addrspace(2) global i8 0, align 1 +@g15 "llvm.global_ctors" = appending addrspace(0) global %t7 c48 +@g16 "llvm.compiler.used" = appending addrspace(0) global %t8 c50, section "llvm.metadata" + +define %t11 @f0 "unspecialized_guarded" "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins"="" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" %a0( Mod nocapture "air-buffer-no-alias"="" ) { +bb0: + %i0 = tail call i1 @f1 [air FunctionConstant(IsDefined)](ptr addrspace(2) @g1) arg0( nocapture ) + %i1 = load i32, ptr addrspace(2) @g0, align 4 + %i2 = select i32 %i0, %i1, i32 7 + %i3 = zext %a1 to i64 + %i4 = getelementptr inbounds i32, %a0, %i3 + store %i2, %i4, align 4 + ret void +} + +declare %t13 @f1 "air.is_function_constant_defined" memory(NoModRef, NoModRef, NoModRef) %a0( nocapture ) + +define %t11 @f2 "unspecialized_free" memory(Mod, NoModRef, NoModRef) "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins"="" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" %a0( Mod nocapture "air-buffer-no-alias"="" ) { +bb0: + %i0 = zext %a1 to i64 + %i1 = getelementptr inbounds i32, %a0, %i0 + store i32 9, %i1, align 4 + ret void +} + +define %t14 @f3 "unspecialized_gate" "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins"="" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" %a0( Mod nocapture "air-buffer-no-alias"="" ) %a1( Ref nocapture "air-buffer-no-alias"="" ) { +bb0: + %i0 = load i8, ptr addrspace(2) @g2, align 1, !range [(0, 2)] + %i1 = icmp eq %i0, i8 0 + %i2 = zext %a2 to i64 + br %i1, bb2, bb1 +bb1: + %i4 = getelementptr inbounds i32, %a1, %i2 + %i5 = load i32, %i4, align 4 + br bb2 +bb2: + %i7 = phi i32 [%i5, bb1], [i32 2, bb0] + %i8 = getelementptr inbounds i32, %a0, %i2 + store %i7, %i8, align 4 + ret void +} + +declare %t15 @f4 "air.normalize_function_constant_predicate.i8" memory(NoModRef, NoModRef, NoModRef) + +define %t17 @f5 "unspecialized_vertex" memory(Ref, Ref, Ref) "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" { +bb0: + %i0 = and i32 %a0, i32 1 + %i1 = tail call reassoc nnan ninf nsz arcp contract afn float @f6 [air Convert(Convert { dst: NumTy { elem: F32, lanes: 1 }, dst_kind: Float, src: NumTy { elem: I32, lanes: 1 }, src_kind: Unsigned, src_fp8: None })](%i0) + %i2 = load float, ptr addrspace(2) @g4, align 4 + %i3 = fmul reassoc nnan ninf nsz arcp contract afn float %i2, %i1 + %i4 = lshr i32 %a0, i32 1 + %i5 = tail call reassoc nnan ninf nsz arcp contract afn float @f6 [air Convert(Convert { dst: NumTy { elem: F32, lanes: 1 }, dst_kind: Float, src: NumTy { elem: I32, lanes: 1 }, src_kind: Unsigned, src_fp8: None })](%i4) + %i6 = insertelement <4 x float> c69, %i3, i64 0 + %i7 = insertelement %i6, %i5, i64 1 + ret %i7 +} + +declare %t18 @f6 "air.convert.f.f32.u.i32" memory(NoModRef, NoModRef, NoModRef) + +define %t17 @f7 "unspecialized_vertex_free" memory(NoModRef, NoModRef, NoModRef) "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" { +bb0: + %i0 = and i32 %a0, i32 1 + %i1 = tail call reassoc nnan ninf nsz arcp contract afn float @f6 [air Convert(Convert { dst: NumTy { elem: F32, lanes: 1 }, dst_kind: Float, src: NumTy { elem: I32, lanes: 1 }, src_kind: Unsigned, src_fp8: None })](%i0) + %i2 = lshr i32 %a0, i32 1 + %i3 = tail call reassoc nnan ninf nsz arcp contract afn float @f6 [air Convert(Convert { dst: NumTy { elem: F32, lanes: 1 }, dst_kind: Float, src: NumTy { elem: I32, lanes: 1 }, src_kind: Unsigned, src_fp8: None })](%i2) + %i4 = insertelement <4 x float> c69, %i1, i64 0 + %i5 = insertelement %i4, %i3, i64 1 + ret %i5 +} + +define %t19 @f8 "unspecialized_fragment" memory(Ref, Ref, Ref) "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" { +bb0: + %i0 = load float, ptr addrspace(2) @g6, align 4 + %i1 = insertelement <4 x float> c71, %i0, i64 0 + ret %i1 +} + +define %t19 @f9 "unspecialized_fragment_free" memory(NoModRef, NoModRef, NoModRef) "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" { +bb0: + ret <4 x float> c72 +} + +define %t24 @f10 "unspecialized_tile" "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" { +bb0: + %i0 = tail call reassoc nnan ninf nsz arcp contract afn <4 x half> @f15 [air Imageblock(Load(NumTy { elem: F16, lanes: 4 }))](i32 0, %a1, i32 0, i16 0) + %i1 = load half, ptr addrspace(2) @g8, align 2 + %i2 = insertelement <4 x half> poison, %i1, i64 0 + %i3 = shufflevector <4 x half> %i2, <4 x half> poison, <0, 0, 0, 0> + %i4 = fmul reassoc nnan ninf nsz arcp contract afn <4 x half> %i3, %i0 + tail call void @f16 [air Imageblock(Store(NumTy { elem: F16, lanes: 4 }))](%i4, i32 0, %a1, i32 0, i16 0) + ret void +} + +define %t26 @f11 "unspecialized_mesh" "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" { +bb0: + %i0 = icmp eq %a1, i32 0 + br %i0, bb1, bb2 +bb1: + tail call void @f17 [air Mesh(PrimitiveCount)](%a0, i32 1) arg0( nocapture ) + tail call void @f18 [air Mesh(Index)](%a0, i32 0, i8 0) arg0( nocapture ) + tail call void @f18 [air Mesh(Index)](%a0, i32 1, i8 1) arg0( nocapture ) + tail call void @f18 [air Mesh(Index)](%a0, i32 2, i8 2) arg0( nocapture ) + br bb2 +bb2: + %i7 = icmp ult %a1, i32 3 + br %i7, bb3, bb4 +bb3: + %i9 = and i32 %a1, i32 1 + %i10 = tail call reassoc nnan ninf nsz arcp contract afn float @f6 [air Convert(Convert { dst: NumTy { elem: F32, lanes: 1 }, dst_kind: Float, src: NumTy { elem: I32, lanes: 1 }, src_kind: Unsigned, src_fp8: None })](%i9) + %i11 = load float, ptr addrspace(2) @g10, align 4 + %i12 = fmul reassoc nnan ninf nsz arcp contract afn float %i11, %i10 + %i13 = lshr i32 %a1, i32 1 + %i14 = tail call reassoc nnan ninf nsz arcp contract afn float @f6 [air Convert(Convert { dst: NumTy { elem: F32, lanes: 1 }, dst_kind: Float, src: NumTy { elem: I32, lanes: 1 }, src_kind: Unsigned, src_fp8: None })](%i13) + %i15 = insertelement <4 x float> c69, %i12, i64 0 + %i16 = insertelement %i15, %i14, i64 1 + tail call void @f19 [air Mesh(Position)](%a0, %a1, %i16) arg0( nocapture ) + br bb4 +bb4: + ret void +} + +define %t26 @f12 "unspecialized_mesh_free" "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" { +bb0: + %i0 = icmp eq %a1, i32 0 + br %i0, bb1, bb2 +bb1: + tail call void @f17 [air Mesh(PrimitiveCount)](%a0, i32 1) arg0( nocapture ) + tail call void @f18 [air Mesh(Index)](%a0, i32 0, i8 0) arg0( nocapture ) + tail call void @f18 [air Mesh(Index)](%a0, i32 1, i8 1) arg0( nocapture ) + tail call void @f18 [air Mesh(Index)](%a0, i32 2, i8 2) arg0( nocapture ) + br bb2 +bb2: + %i7 = icmp ult %a1, i32 3 + br %i7, bb3, bb4 +bb3: + %i9 = and i32 %a1, i32 1 + %i10 = tail call reassoc nnan ninf nsz arcp contract afn float @f6 [air Convert(Convert { dst: NumTy { elem: F32, lanes: 1 }, dst_kind: Float, src: NumTy { elem: I32, lanes: 1 }, src_kind: Unsigned, src_fp8: None })](%i9) + %i11 = lshr i32 %a1, i32 1 + %i12 = tail call reassoc nnan ninf nsz arcp contract afn float @f6 [air Convert(Convert { dst: NumTy { elem: F32, lanes: 1 }, dst_kind: Float, src: NumTy { elem: I32, lanes: 1 }, src_kind: Unsigned, src_fp8: None })](%i11) + %i13 = insertelement <4 x float> c69, %i10, i64 0 + %i14 = insertelement %i13, %i12, i64 1 + tail call void @f19 [air Mesh(Position)](%a0, %a1, %i14) arg0( nocapture ) + br bb4 +bb4: + ret void +} + +define %t28 @f13 "unspecialized_object" "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="96" "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" %a0( nocapture ) { +bb0: + %i0 = load i32, ptr addrspace(2) @g12, align 4 + %i1 = add i32 %i0, i32 1 + %i2 = insertelement <3 x i32> c78, %i1, i64 0 + tail call void @f14 [air Mesh(ThreadgroupsPerGrid)](%a0, %i2) arg0( nocapture ) + ret void +} + +declare %t30 @f14 "air.set_threadgroups_per_grid_mesh_properties" memory(ModRef, NoModRef, NoModRef) %a0( nocapture ) + +declare %t32 @f15 "air.load.implicit_imageblock.v4f16" memory(Ref, Ref, Ref) + +declare %t33 @f16 "air.store.implicit_imageblock.v4f16" memory(Mod, Mod, Mod) + +declare %t26 @f17 "air.set_primitive_count_mesh" memory(ModRef, NoModRef, NoModRef) %a0( nocapture ) + +declare %t34 @f18 "air.set_index_mesh" memory(ModRef, NoModRef, NoModRef) %a0( nocapture ) + +declare %t35 @f19 "air.set_position_mesh" memory(ModRef, NoModRef, NoModRef) %a0( nocapture ) + +define internal %t36 @f20 "_GLOBAL__sub_I__" "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins"="" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true", section air.static_init { +bb0: + %i0 = load i32, ptr addrspace(2) @g1, align 4 + store %i0, ptr addrspace(2) @g0, align 4 + %i2 = load i8, ptr addrspace(2) @g3, align 1, !range [(0, 2)] + store %i2, ptr addrspace(2) @g2, align 1 + %i4 = load float, ptr addrspace(2) @g5, align 4 + store %i4, ptr addrspace(2) @g4, align 4 + %i6 = load float, ptr addrspace(2) @g7, align 4 + store %i6, ptr addrspace(2) @g6, align 4 + %i8 = load half, ptr addrspace(2) @g9, align 2 + store %i8, ptr addrspace(2) @g8, align 2 + %i10 = load float, ptr addrspace(2) @g11, align 4 + store %i10, ptr addrspace(2) @g10, align 4 + %i12 = load i32, ptr addrspace(2) @g13, align 4 + store %i12, ptr addrspace(2) @g12, align 4 + %i14 = tail call i8 @f4 [air FunctionConstant(NormalizePredicate(I8))](%i2) + store %i14, ptr addrspace(2) @g14, align 1 + ret void +} +!md0 = !"SDK Version" +!md1 = !"wchar_size" +!md2 = !"frame-pointer" +!md3 = !"air.max_device_buffers" +!md4 = !"air.max_constant_buffers" +!md5 = !"air.max_threadgroup_buffers" +!md6 = !"air.max_textures" +!md7 = !"air.max_read_write_textures" +!md8 = !"air.max_samplers" +!md9 = !"air.buffer" +!md10 = !"air.location_index" +!md11 = !"air.read_write" +!md12 = !"air.address_space" +!md13 = !"air.arg_type_size" +!md14 = !"air.arg_type_align_size" +!md15 = !"air.arg_type_name" +!md16 = !"uint" +!md17 = !"air.arg_name" +!md18 = !"out" +!md19 = !"air.thread_position_in_grid" +!md20 = !"tid" +!md21 = !"air.function_constant" +!md22 = !"bool" +!md23 = !"has_extra" +!md24 = !"air.read" +!md25 = !"extra" +!md26 = !"air.imageblock" +!md27 = !"implicit" +!md28 = !"air.struct_type_info" +!md29 = !"half4" +!md30 = !"color" +!md31 = !"air.render_target" +!md32 = !"imageblock" +!md33 = !"block" +!md34 = !"air.thread_position_in_threadgroup" +!md35 = !"ushort2" +!md36 = !"lid" +!md37 = !"air.position" +!md38 = !"float4" +!md39 = !"air.vertex_id" +!md40 = !"vid" +!md41 = !"air.mesh" +!md42 = !"air.mesh_type_info" +!md43 = !"position" +!md44 = !"air.triangle" +!md45 = !"mesh" +!md46 = !"m" +!md47 = !"air.thread_index_in_threadgroup" +!md48 = !"t" +!md49 = !"air.mesh_grid_properties" +!md50 = !"mesh_grid_properties" +!md51 = !"grid" +!md52 = !"air.compile.denorms_disable" +!md53 = !"air.compile.fast_math_enable" +!md54 = !"air.compile.framebuffer_fetch_enable" +!md55 = !"optional_count" +!md56 = !"float" +!md57 = !"vertex_scale" +!md58 = !"fragment_tint" +!md59 = !"half" +!md60 = !"tile_tint" +!md61 = !"mesh_scale" +!md62 = !"object_count" +!md63 = !"Apple metal version 32023.922 (metalfe-32023.922.4)" +!md64 = !"Metal" +!md65 = !"int" +!md66 = !"omnipotent char" +!md67 = !"Simple C++ TBAA" +!md68 = !"air-alias-scope-arg(0)" +!md69 = i32 2 +!md70 = %t38 c51 +!md71 = i32 1 +!md72 = i32 4 +!md73 = i32 7 +!md74 = i32 31 +!md75 = i32 128 +!md76 = i32 8 +!md77 = i32 16 +!md78 = ptr addrspace(0) @f0 +!md79 = i32 0 +!md80 = ptr addrspace(0) @f2 +!md81 = ptr addrspace(0) @f3 +!md82 = ptr addrspace(2) @g14 +!md83 = ptr addrspace(0) @f10 +!md84 = ptr addrspace(0) @f5 +!md85 = ptr addrspace(0) @f7 +!md86 = ptr addrspace(0) @f8 +!md87 = ptr addrspace(0) @f9 +!md88 = ptr addrspace(0) @f11 +!md89 = i32 3 +!md90 = ptr addrspace(0) @f12 +!md91 = ptr addrspace(0) @f13 +!md92 = ptr addrspace(2) @g1 +!md93 = ptr addrspace(2) @g3 +!md94 = ptr addrspace(2) @g5 +!md95 = ptr addrspace(2) @g7 +!md96 = ptr addrspace(2) @g9 +!md97 = ptr addrspace(2) @g11 +!md98 = i32 5 +!md99 = ptr addrspace(2) @g13 +!md100 = i32 6 +!md101 = i64 0 +!md102 = i8 0 +!md103 = i8 2 +!md104 = !{!md69, !md0, !md70} +!md105 = !{!md71, !md1, !md72} +!md106 = !{!md73, !md2, !md69} +!md107 = !{!md73, !md3, !md74} +!md108 = !{!md73, !md4, !md74} +!md109 = !{!md73, !md5, !md74} +!md110 = !{!md73, !md6, !md75} +!md111 = !{!md73, !md7, !md76} +!md112 = !{!md73, !md8, !md77} +!md113 = !{} +!md114 = !{!md79, !md9, !md10, !md79, !md71, !md11, !md12, !md71, !md13, !md72, !md14, !md72, !md15, !md16, !md17, !md18} +!md115 = !{!md71, !md19, !md15, !md16, !md17, !md20} +!md116 = !{!md114, !md115} +!md117 = !{!md78, !md113, !md116} +!md118 = !{!md80, !md113, !md116} +!md119 = !{!md82, !md22, !md23} +!md120 = !{!md71, !md21, !md119, !md9, !md10, !md71, !md71, !md24, !md12, !md71, !md13, !md72, !md14, !md72, !md15, !md16, !md17, !md25} +!md121 = !{!md69, !md19, !md15, !md16, !md17, !md20} +!md122 = !{!md114, !md120, !md121} +!md123 = !{!md81, !md113, !md122} +!md124 = !{!md79, !md76, !md79, !md29, !md30, !md31, !md79} +!md125 = !{!md79, !md26, !md27, !md28, !md124, !md14, !md76, !md15, !md32, !md17, !md33} +!md126 = !{!md71, !md34, !md15, !md35, !md17, !md36} +!md127 = !{!md125, !md126} +!md128 = !{!md83, !md113, !md127} +!md129 = !{!md37, !md15, !md38} +!md130 = !{!md129} +!md131 = !{!md79, !md39, !md15, !md16, !md17, !md40} +!md132 = !{!md131} +!md133 = !{!md84, !md130, !md132} +!md134 = !{!md85, !md130, !md132} +!md135 = !{!md31, !md79, !md79, !md15, !md38} +!md136 = !{!md135} +!md137 = !{!md86, !md136, !md113} +!md138 = !{!md87, !md136, !md113} +!md139 = !{!md37, !md15, !md38, !md17, !md43} +!md140 = !{!md139} +!md141 = !{!md42, !md140, !md113, !md89, !md71, !md44} +!md142 = !{!md79, !md41, !md141, !md15, !md45, !md17, !md46} +!md143 = !{!md71, !md47, !md15, !md16, !md17, !md48} +!md144 = !{!md142, !md143} +!md145 = !{!md88, !md113, !md144} +!md146 = !{!md90, !md113, !md144} +!md147 = !{!md79, !md49, !md15, !md50, !md17, !md51} +!md148 = !{!md147} +!md149 = !{!md91, !md113, !md148} +!md150 = !{!md52} +!md151 = !{!md53} +!md152 = !{!md54} +!md153 = !{!md92, !md16, !md55, !md79} +!md154 = !{!md93, !md22, !md23, !md71} +!md155 = !{!md94, !md56, !md57, !md69} +!md156 = !{!md95, !md56, !md58, !md89} +!md157 = !{!md96, !md59, !md60, !md72} +!md158 = !{!md97, !md56, !md61, !md98} +!md159 = !{!md99, !md16, !md62, !md100} +!md160 = !{!md63} +!md161 = !{!md69, !md76, !md79} +!md162 = !{!md64, !md72, !md79, !md79} +!md163 = !{!md67} +!md164 = !{!md66, !md163, !md101} +!md165 = !{!md65, !md164, !md101} +!md166 = !{!md165, !md165, !md101} +!md167 = !{!md22, !md164, !md101} +!md168 = !{!md167, !md167, !md101} +!md169 = !{!md102, !md103} +!md170 = !{!md56, !md164, !md101} +!md171 = !{!md170, !md170, !md101} +!md172 = !{!md59, !md164, !md101} +!md173 = !{!md172, !md172, !md101} +!"llvm.module.flags" = !{!md104, !md105, !md106, !md107, !md108, !md109, !md110, !md111, !md112} +!"air.kernel" = !{!md117, !md118, !md123, !md128} +!"air.vertex" = !{!md133, !md134} +!"air.fragment" = !{!md137, !md138} +!"air.mesh" = !{!md145, !md146} +!"air.object" = !{!md149} +!"air.compile_options" = !{!md150, !md151, !md152} +!"air.function_constants" = !{!md153, !md154, !md155, !md156, !md157, !md158, !md159} +!"llvm.ident" = !{!md160} +!"air.version" = !{!md161} +!"air.language_version" = !{!md162} diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index d8bdf1c45..f846cd5d8 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -4089,6 +4089,7 @@ field metal2vulkan::pipeline::FunctionDescriptor.constants pub constants: Functi field metal2vulkan::pipeline::FunctionDescriptor.function pub function: Function field metal2vulkan::pipeline::FunctionDescriptor.libraries pub libraries: DynamicLibraries field metal2vulkan::pipeline::FunctionDescriptor.linked pub linked: LinkedFunctions +field metal2vulkan::pipeline::FunctionDescriptor.specialized pub specialized: bool field metal2vulkan::pipeline::GraphicsState.alpha_to_coverage pub alpha_to_coverage: bool field metal2vulkan::pipeline::GraphicsState.alpha_to_one pub alpha_to_one: bool field metal2vulkan::pipeline::GraphicsState.clip_distances pub clip_distances: u32 @@ -8930,10 +8931,12 @@ method metal2vulkan::pipeline::EntryDescriptor::new pub fn new(bitcode: &'a [u8] method metal2vulkan::pipeline::ExtendedRangeColor::new pub fn new(form: metal::format::ExtendedRange, blended: bool) -> ExtendedRangeColor method metal2vulkan::pipeline::ExtendedRangeColor::with_rounding pub fn with_rounding(self, rounding: metal::TextureWriteRoundingMode) -> ExtendedRangeColor method metal2vulkan::pipeline::FramebufferFetchInputs::of pub fn of(read: impl IntoIterator, colors: &[Option], depth_or_stencil: bool, alpha_to_coverage: bool, max_vertex_amplification_count: u32) -> FramebufferFetchInputs +method metal2vulkan::pipeline::FunctionDescriptor::needs_specialization pub fn needs_specialization(&self, budget: &Budget, entries: &StageEntries) -> Result method metal2vulkan::pipeline::FunctionDescriptor::new pub fn new(function: Function) -> FunctionDescriptor method metal2vulkan::pipeline::FunctionDescriptor::with_libraries pub fn with_libraries(mut self, libraries: DynamicLibraries) -> FunctionDescriptor method metal2vulkan::pipeline::FunctionDescriptor::with_linked pub fn with_linked(mut self, linked: LinkedFunctions) -> FunctionDescriptor method metal2vulkan::pipeline::FunctionDescriptor::with_loaded_dependencies pub fn with_loaded_dependencies(mut self, mut load: impl FnMut(&str) -> Option) -> FunctionDescriptor +method metal2vulkan::pipeline::FunctionDescriptor::with_specialized pub fn with_specialized(mut self, specialized: bool) -> FunctionDescriptor method metal2vulkan::pipeline::FunctionHandle::word pub fn word(self) -> u32 method metal2vulkan::pipeline::GraphicsState::color_blend_attachments pub fn color_blend_attachments(&self) -> Vec<(vk::ColorComponentFlags, Option)> method metal2vulkan::pipeline::GraphicsState::new pub fn new(topology: vk::PrimitiveTopology, rasterization_samples: vk::SampleCountFlags) -> GraphicsState @@ -11713,6 +11716,7 @@ variant metal2vulkan-runtime::Problem::Texture Texture(TextureProblem) variant metal2vulkan-runtime::Problem::TextureView TextureView(ViewProblem) variant metal2vulkan-runtime::Problem::UndefinedValue UndefinedValue { ty: &'static str, raw: u64 } variant metal2vulkan-runtime::Problem::UnrasterizedVertexReturn UnrasterizedVertexReturn +variant metal2vulkan-runtime::Problem::UnspecializedFunction UnspecializedFunction { stage: Stage, name: String } variant metal2vulkan-runtime::Problem::UnwrittenFragmentInputs UnwrittenFragmentInputs { inputs: Box<[String]> } variant metal2vulkan-runtime::Problem::UnwrittenFragmentInputsUnproven UnwrittenFragmentInputsUnproven { inputs: Box<[String]>, reason: LinkedUseGap } variant metal2vulkan-runtime::Problem::Visibility Visibility(VisibilityProblem) diff --git a/crates/metal2vulkan/tests/golden_hashes.tsv b/crates/metal2vulkan/tests/golden_hashes.tsv index 9bc1bc012..2ab4348a5 100644 --- a/crates/metal2vulkan/tests/golden_hashes.tsv +++ b/crates/metal2vulkan/tests/golden_hashes.tsv @@ -2433,6 +2433,28 @@ engine/unmeasured_speculation.air.ll c5e55d04f4f8307c quad_first_in_an_unmeasure engine/unmeasured_speculation.air.ll c5e55d04f4f8307c sin_in_an_unmeasured_arm 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 engine/unmeasured_speculation.ll 3e440dc301b0ee3a quad_first_in_an_unmeasured_arm 2bb7c742c8881665 2bb7c742c8881665 2bb7c742c8881665 2bb7c742c8881665 977bfe474afa5cec 977bfe474afa5cec 2bb7c742c8881665 2bb7c742c8881665 2bb7c742c8881665 2bb7c742c8881665 977bfe474afa5cec 977bfe474afa5cec 2bb7c742c8881665 e2b3dc1313816472 2bb7c742c8881665 2bb7c742c8881665 977bfe474afa5cec 977bfe474afa5cec 977bfe474afa5cec engine/unmeasured_speculation.ll 3e440dc301b0ee3a sin_in_an_unmeasured_arm 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 5c3c8083d5f94258 +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_fragment 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_fragment_free 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_free a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_gate 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_guarded 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_mesh c3515080b213f36d c3515080b213f36d c3515080b213f36d c3515080b213f36d 286dd6db36a77fa8 286dd6db36a77fa8 c3515080b213f36d 8b88831e2adac394 8b88831e2adac394 8b88831e2adac394 286dd6db36a77fa8 8b88831e2adac394 b36824c7726f9070 8b88831e2adac394 c3515080b213f36d c3515080b213f36d 8b88831e2adac394 8b88831e2adac394 8b88831e2adac394 +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_mesh_free 437172098ceb4018 437172098ceb4018 437172098ceb4018 437172098ceb4018 3d7d09d2783e67b2 3d7d09d2783e67b2 437172098ceb4018 99219712f99cac70 99219712f99cac70 99219712f99cac70 3d7d09d2783e67b2 99219712f99cac70 69d69b42a023301a 99219712f99cac70 437172098ceb4018 437172098ceb4018 99219712f99cac70 99219712f99cac70 99219712f99cac70 +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_object 185d97bc52812902 185d97bc52812902 185d97bc52812902 185d97bc52812902 185d97bc52812902 185d97bc52812902 185d97bc52812902 96337fa5a12e71e2 96337fa5a12e71e2 96337fa5a12e71e2 185d97bc52812902 96337fa5a12e71e2 b623cc4387c781c3 96337fa5a12e71e2 185d97bc52812902 185d97bc52812902 96337fa5a12e71e2 96337fa5a12e71e2 96337fa5a12e71e2 +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_tile NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_vertex c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c +engine/unspecialized_stage_functions.air.ll 23a968a33f36708c unspecialized_vertex_free 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_fragment 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 20e7da719fc7faf5 +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_fragment_free 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 64dc330ba3eaf5e7 +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_free a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb a8376e3b501987eb +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_gate 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd 9d3bb457a3e349bd +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_guarded 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 28d7fe80f0702c99 +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_mesh c3515080b213f36d c3515080b213f36d c3515080b213f36d c3515080b213f36d 286dd6db36a77fa8 286dd6db36a77fa8 c3515080b213f36d 8b88831e2adac394 8b88831e2adac394 8b88831e2adac394 286dd6db36a77fa8 8b88831e2adac394 b36824c7726f9070 8b88831e2adac394 c3515080b213f36d c3515080b213f36d 8b88831e2adac394 8b88831e2adac394 8b88831e2adac394 +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_mesh_free 437172098ceb4018 437172098ceb4018 437172098ceb4018 437172098ceb4018 3d7d09d2783e67b2 3d7d09d2783e67b2 437172098ceb4018 99219712f99cac70 99219712f99cac70 99219712f99cac70 3d7d09d2783e67b2 99219712f99cac70 69d69b42a023301a 99219712f99cac70 437172098ceb4018 437172098ceb4018 99219712f99cac70 99219712f99cac70 99219712f99cac70 +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_object 185d97bc52812902 185d97bc52812902 185d97bc52812902 185d97bc52812902 185d97bc52812902 185d97bc52812902 185d97bc52812902 96337fa5a12e71e2 96337fa5a12e71e2 96337fa5a12e71e2 185d97bc52812902 96337fa5a12e71e2 b623cc4387c781c3 96337fa5a12e71e2 185d97bc52812902 185d97bc52812902 96337fa5a12e71e2 96337fa5a12e71e2 96337fa5a12e71e2 +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_tile NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_vertex c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c c72d94003d6bff1c +engine/unspecialized_stage_functions.ll 0a2b2b6f9e9b585c unspecialized_vertex_free 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 46ba198a2a2ab2a2 engine/unv_runtime_levels.air.ll a38c4149697919e4 unv_rlvl2d 9241cefa3b5627fe 9241cefa3b5627fe 9241cefa3b5627fe 9241cefa3b5627fe 9241cefa3b5627fe 9241cefa3b5627fe 88804523dba72209 88804523dba72209 88804523dba72209 88804523dba72209 9241cefa3b5627fe 3c811f93ab78b96a 3eff816e28487b09 a73c923971c2fd9b 88804523dba72209 88804523dba72209 3c811f93ab78b96a 3c811f93ab78b96a Unsupported{ArgumentBufferTextures; AnyOf[[Feature(RuntimeDescriptorArray), Feature(DescriptorBindingPartiallyBound), Feature(ShaderSampledImageArrayNonUniformIndexing), Feature(DescriptorBindingSampledImageUpdateAfterBind)]]} engine/unv_runtime_levels.air.ll a38c4149697919e4 unv_rpos2d dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 3a7748d0c3ba1555 3a7748d0c3ba1555 dacad5f25b52dbc5 dacad5f25b52dbc5 dacad5f25b52dbc5 3a7748d0c3ba1555 3a7748d0c3ba1555 3a7748d0c3ba1555 engine/unv_runtime_levels.ll 62b9e4a266ccd8fb unv_rlvl2d 9241cefa3b5627fe 9241cefa3b5627fe 9241cefa3b5627fe 9241cefa3b5627fe 9241cefa3b5627fe 9241cefa3b5627fe 88804523dba72209 88804523dba72209 88804523dba72209 88804523dba72209 9241cefa3b5627fe 3c811f93ab78b96a 3eff816e28487b09 a73c923971c2fd9b 88804523dba72209 88804523dba72209 3c811f93ab78b96a 3c811f93ab78b96a Unsupported{ArgumentBufferTextures; AnyOf[[Feature(RuntimeDescriptorArray), Feature(DescriptorBindingPartiallyBound), Feature(ShaderSampledImageArrayNonUniformIndexing), Feature(DescriptorBindingSampledImageUpdateAfterBind)]]} diff --git a/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv b/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv index 2358b09c8..cee2bd368 100644 --- a/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv +++ b/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv @@ -2551,6 +2551,28 @@ engine/unmeasured_speculation.air.ll quad_first_in_an_unmeasured_arm ok ok ok ok engine/unmeasured_speculation.air.ll sin_in_an_unmeasured_arm ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/unmeasured_speculation.ll quad_first_in_an_unmeasured_arm ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/unmeasured_speculation.ll sin_in_an_unmeasured_arm ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_guarded ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_free ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_gate ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_tile NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} +engine/unspecialized_stage_functions.air.ll unspecialized_vertex ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_vertex_free ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_fragment ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_fragment_free ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_object ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_mesh ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.air.ll unspecialized_mesh_free ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_guarded ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_free ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_gate ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_tile NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} NeedsInput{TileAttachments} +engine/unspecialized_stage_functions.ll unspecialized_vertex ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_vertex_free ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_fragment ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_fragment_free ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_object ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_mesh ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/unspecialized_stage_functions.ll unspecialized_mesh_free ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/unv_runtime_levels.air.ll unv_rlvl2d ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok Unsupported{ArgumentBufferTextures; AnyOf[[Feature(RuntimeDescriptorArray), Feature(DescriptorBindingPartiallyBound), Feature(ShaderSampledImageArrayNonUniformIndexing), Feature(DescriptorBindingSampledImageUpdateAfterBind)]]} engine/unv_runtime_levels.air.ll unv_rpos2d ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/unv_runtime_levels.ll unv_rlvl2d ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok Unsupported{ArgumentBufferTextures; AnyOf[[Feature(RuntimeDescriptorArray), Feature(DescriptorBindingPartiallyBound), Feature(ShaderSampledImageArrayNonUniformIndexing), Feature(DescriptorBindingSampledImageUpdateAfterBind)]]} diff --git a/docs/API.md b/docs/API.md index d58c1d763..b33fca3c2 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3696,9 +3696,19 @@ each item named states the rule in full. alone is its type's zero (an `and`, `or` or `mul` with a constant that decides it is that constant), and a branch or `select` on one takes its false way; a value it meets with one the run computes is computed with that zero. As Metal's, `is_function_constant_defined` is false for - it and an argument gated on it, negated or not, is absent. Metal makes the same pipeline, and its - reads of the constant vary from read to read: on an M3 Max under macOS 27.0.1 it read `u + 3` as - 0, `u * 7 + 1` as 1, `u == 0 ? 111 : 222` as 222 and `b ? 5 : 6` as 5. + it and an argument gated on it, negated or not, is absent. Metal makes the same pipeline of a + specialized function (made with constant values, none among them too, or by + `newFunctionWithDescriptor:`), and its reads of the constant vary from read to read: on an M3 + Max under macOS 27.0.1 it read `u + 3` as 0, `u * 7 + 1` as 1, `u == 0 ? 111 : 222` as 222 and + `b ? 5 : 6` as 5. The compile is the same for a function made by `newFunctionWithName:`, which + Metal makes no pipeline state of where its function declares a constant: its creation ends the + process at every stage ("function ko cannot be used to build a pipeline state. Use + newFunctionWithName:constantValues:... to get the specialized function"), whether the constant + is required, read only where `is_function_constant_defined` says, or only gates an argument. + `FunctionDescriptor::needs_specialization` answers it (`FunctionDescriptor::specialized` and the + function's `function_constants_dictionary`), and the runtime refuses such a state as Metal does + (`Invalid` with `Problem::UnspecializedFunction`). A linked function keeps its own rule (section + 3, "Linked functions: names and constants"). - **A linked function's constant without a value reads as zero too**, where the function was made specialized (section 3, "Linked functions: names and constants"). Metal makes that pipeline, and its read is undefined: a kernel storing `x * scale + 1` of such a function stored nothing on diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 1e151297a..6cb1fd03e 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -34,7 +34,7 @@ Columns: | Translation caps | 14 | 14 | 0 | 0 | 7 | 7 | 0 | | Rate maps the compile layer does not compile | 5 | 5 | 0 | 0 | 4 | 1 | 0 | | The translation deadline | 1 | 1 | 0 | 0 | 0 | 1 | 0 | -| What a call did wrong | 64 | 64 | 0 | 0 | 0 | 0 | 0 | +| What a call did wrong | 65 | 65 | 0 | 0 | 0 | 0 | 0 | | What a call did wrong, in detail | 164 | 149 | 0 | 0 | 0 | 0 | 0 | ## Totals by basis @@ -48,7 +48,7 @@ Columns: | Translation caps | 0 | 0 | 0 | 0 | 14 | 0 | 0 | 0 | | Rate maps the compile layer does not compile | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | | The translation deadline | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | -| What a call did wrong | 20 | 3 | 5 | 0 | 11 | 8 | 17 | 0 | +| What a call did wrong | 21 | 3 | 5 | 0 | 11 | 8 | 17 | 0 | | What a call did wrong, in detail | 57 | 27 | 23 | 0 | 31 | 26 | 0 | 0 | ## 1. Translator and front-end refusals (`Unsupported`: a `Feature` and its `Needs`) @@ -356,6 +356,7 @@ Columns: | `PointSizeTopology` | `new_render_pipeline_state` | every device (a public call's own check of its arguments) | `metal-measured`: an M3 Max and an M4: Metal's pipeline creation answers an error, with and without API validation | 1: `crates/metal2vulkan-runtime/src/pipeline/render.rs (create_checked)` | `-` | | `IndirectScaledTessellation` | `new_render_pipeline_state` | every device (a public call's own check of its arguments) | `metal-measured`: an M3 Max, macOS 27.0.1: plain Metal ends its process, the API validation layer off | 1: `crates/metal2vulkan-runtime/src/pipeline/render.rs (create_reflecting)` | `-` | | `CompiledKernel` | `new_compute_pipeline_state` | every device (a public call's own check of its arguments) | `ours`: this crate's already-compiled stage: Metal's descriptor takes a function | 1: `crates/metal2vulkan-runtime/src/pipeline/mod.rs (of_kernel)` | `-` | +| `UnspecializedFunction` | `new_compute_pipeline_state`, `new_render_pipeline_state`, `new_tile_render_pipeline_state` and `new_mesh_render_pipeline_state` | every device (a public call's own check of its arguments) | `metal-measured`: an M3 Max, macOS 27.0.1: plain Metal ends its process at a compute, render, tile and mesh state of each stage, `MTL_DEBUG_LAYER` unset | 1: `crates/metal2vulkan-runtime/src/pipeline/unspecialized.rs (check)` | `-` | | `DuplicateLinkedFunction` | `new_compute_pipeline_state` | every device (a public call's own check of its arguments) | `metal-measured`: an M3 Max and an M4: plain Metal's creation fails on a name the linked functions repeat | 1: `crates/metal2vulkan-runtime/src/pipeline/mod.rs (of_kernel)` | `-` | | `RenderState` | A viewport, scissor rectangle or other render encoder state Metal stops at its setter | every device (a public call's own check of its arguments) | `delegated`: RenderStateProblem, section 9 | 3: `crates/metal2vulkan-runtime/src/render_state.rs (check_count)`, `crates/metal2vulkan-runtime/src/render_state.rs (set_scissors)` (+1) | `-` | | `Visibility` | A `set_visibility_result_mode` Metal stops | every device (a public call's own check of its arguments) | `delegated`: VisibilityProblem, section 9 | 1: `crates/metal2vulkan-runtime/src/visibility.rs (check_mode)` | `-` | @@ -823,6 +824,7 @@ Each refusal's sites, with the function that builds it. - `invalid::PointSizeTopology`: `crates/metal2vulkan-runtime/src/pipeline/render.rs (create_checked)` - `invalid::IndirectScaledTessellation`: `crates/metal2vulkan-runtime/src/pipeline/render.rs (create_reflecting)` - `invalid::CompiledKernel`: `crates/metal2vulkan-runtime/src/pipeline/mod.rs (of_kernel)` +- `invalid::UnspecializedFunction`: `crates/metal2vulkan-runtime/src/pipeline/unspecialized.rs (check)` - `invalid::DuplicateLinkedFunction`: `crates/metal2vulkan-runtime/src/pipeline/mod.rs (of_kernel)` - `invalid::RenderState`: `crates/metal2vulkan-runtime/src/render_state.rs (check_count)`; `crates/metal2vulkan-runtime/src/render_state.rs (set_scissors)`; `crates/metal2vulkan-runtime/src/render_state.rs (set_viewports)` - `invalid::Visibility`: `crates/metal2vulkan-runtime/src/visibility.rs (check_mode)`