diff --git a/crates/metal2vulkan-conformance/probes/no_attachment_passes.m b/crates/metal2vulkan-conformance/probes/no_attachment_passes.m new file mode 100644 index 000000000..ca29126fa --- /dev/null +++ b/crates/metal2vulkan-conformance/probes/no_attachment_passes.m @@ -0,0 +1,150 @@ +// Plain Metal's answer, with the API validation layer OFF, for a render pass with no attachment +// at each `renderTargetWidth`, `renderTargetHeight` and `defaultRasterSampleCount` the runtime's +// `Refusal::NoAttachmentPass` names (a side of 0, a count of 0, Metal's default), beside the legal +// neighbour of each. One shape per process, so a process that ends is attributable to the shape +// that ended it; every process prints the device and the release first. +// +// Build (no GPU needed): +// +// clang -fobjc-arc -fmodules -framework Metal -framework Foundation \ +// -o no_attachment_passes no_attachment_passes.m +// +// Run one shape per process, WITHOUT MTL_DEBUG_LAYER: +// +// ./no_attachment_passes +// ./no_attachment_passes --list +// +// A shape `pass---` makes the pass's encoder and ends it. A shape +// `draw----` also draws, in that pass, the fullscreen triangle +// through a pipeline state of `` raster samples and no attachment, whose fragment function +// counts its runs: the count says how many pixels and samples the pass drew at. Every shape prints +// `DEVICE `, `RELEASE `, then `READ ` lines, then `DONE `. A shape +// whose process Metal ends prints no `DONE`, and its exit status is the reading. +// +// WHAT IT MEASURED, Apple M3 Max, macOS 27.0.1 (Build 26A434), job m3-max-62174: +// +// - a new descriptor's `defaultRasterSampleCount` is 0; +// - `pass-64-64-1` makes its encoder; `pass-0-64-1`, `pass-64-0-1` and `pass-0-0-1` make none +// (nil), and their command buffers complete; +// - `pass-64-64-0` and `draw-4-4-0-1` end the process at the encoder (SIGABRT, exit 134); +// - `draw-4-4-1-1` runs its fragment function 16 times, and `draw-4-4-4-4` 64 times, once per +// sample of each pixel, as a memory-writing function runs at 4 samples on this device. + +#import +#import +#include +#include +#include + +static id gDevice = nil; +static id gQueue = nil; + +static void readv(const char *key, const char *fmt, ...) { + printf("READ %s ", key); + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + printf("\n"); + fflush(stdout); +} + +static NSString *kSource = + @"#include \n" + "using namespace metal;\n" + "struct P { float4 position [[position]]; };\n" + "vertex P na_cover(uint id [[vertex_id]]) {\n" + " float2 a = float2(float(id & 1u), float(id >> 1));\n" + " return P { float4(4.0 * a - 1.0, 0.0, 1.0) };\n" + "}\n" + "fragment void na_count(P in [[stage_in]], device atomic_uint *runs [[buffer(0)]]) {\n" + " atomic_fetch_add_explicit(runs, 1u, memory_order_relaxed);\n" + "}\n"; + +static const char *kShapes[] = { + "pass-64-64-1", "pass-0-64-1", "pass-64-0-1", "pass-0-0-1", "pass-64-64-0", + "draw-4-4-1-1", "draw-4-4-4-4", "draw-4-4-0-1", +}; + +static int run(const char *shape) { + unsigned long width = 0, height = 0, count = 0, samples = 0; + BOOL draws = strncmp(shape, "draw-", 5) == 0; + int parsed = draws ? sscanf(shape, "draw-%lu-%lu-%lu-%lu", &width, &height, &count, &samples) + : sscanf(shape, "pass-%lu-%lu-%lu", &width, &height, &count); + if (parsed != (draws ? 4 : 3)) { + fprintf(stderr, "unknown shape %s\n", shape); + return 2; + } + id state = nil; + id runs = nil; + if (draws) { + NSError *error = nil; + id library = [gDevice newLibraryWithSource:kSource options:nil error:&error]; + if (library == nil) { + readv("library", "nil %s", error.localizedDescription.UTF8String); + return 3; + } + MTLRenderPipelineDescriptor *d = [MTLRenderPipelineDescriptor new]; + d.vertexFunction = [library newFunctionWithName:@"na_cover"]; + d.fragmentFunction = [library newFunctionWithName:@"na_count"]; + d.rasterSampleCount = samples; + state = [gDevice newRenderPipelineStateWithDescriptor:d error:&error]; + readv("state", "%s", state ? "made" : error.localizedDescription.UTF8String); + if (state == nil) { + return 3; + } + runs = [gDevice newBufferWithLength:4 options:MTLResourceStorageModeShared]; + memset(runs.contents, 0, 4); + } + MTLRenderPassDescriptor *rp = [MTLRenderPassDescriptor renderPassDescriptor]; + readv("default", "defaultRasterSampleCount %lu", (unsigned long)rp.defaultRasterSampleCount); + rp.renderTargetWidth = width; + rp.renderTargetHeight = height; + rp.defaultRasterSampleCount = count; + readv("descriptor", "%lu by %lu at %lu", width, height, count); + id cb = [gQueue commandBuffer]; + id enc = [cb renderCommandEncoderWithDescriptor:rp]; + readv("encoder", "made %s", enc ? "yes" : "nil"); + if (enc != nil && draws) { + [enc setRenderPipelineState:state]; + [enc setFragmentBuffer:runs offset:0 atIndex:0]; + [enc drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:3]; + } + [enc endEncoding]; + [cb commit]; + [cb waitUntilCompleted]; + readv("command-buffer", "status %ld error %s", (long)cb.status, + cb.error ? cb.error.localizedDescription.UTF8String : "(none)"); + if (draws) { + readv("runs", "%u", *(const unsigned *)runs.contents); + } + printf("DONE %s\n", shape); + fflush(stdout); + return 0; +} + +int main(int argc, const char *argv[]) { + if (argc == 2 && strcmp(argv[1], "--list") == 0) { + for (size_t i = 0; i < sizeof(kShapes) / sizeof(kShapes[0]); i++) { + printf("%s\n", kShapes[i]); + } + return 0; + } + if (argc != 2) { + fprintf(stderr, "usage: %s |--list\n", argv[0]); + return 2; + } + @autoreleasepool { + gDevice = MTLCreateSystemDefaultDevice(); + if (gDevice == nil) { + fprintf(stderr, "no Metal device\n"); + return 2; + } + gQueue = [gDevice newCommandQueue]; + printf("DEVICE %s\n", gDevice.name.UTF8String); + printf("RELEASE %s\n", NSProcessInfo.processInfo.operatingSystemVersionString.UTF8String); + printf("SHAPE %s\n", argv[1]); + fflush(stdout); + return run(argv[1]); + } +} diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index f3750072f..acff70767 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -2992,8 +2992,9 @@ or does not check is rebuilt from the generations' names, with young counted ful `defaultRasterSampleCount` samples: one dynamic rendering of no attachment, whose draws' pipeline states have that `rasterSampleCount` and no attachment format, and write their answers to memory. Vulkan takes the samples from the pipeline (`framebufferNoAttachmentsSampleCounts` - the translator's query for its state). A side of 0 or a count that is no sample count, Metal's - default 0 included, is `Refusal::NoAttachmentPass`; a side past the device's + the translator's query for its state). A side of 0 or a count of 0, Metal's default, is + `Refusal::NoAttachmentPass`, as plain Metal makes no encoder of either (an Apple M3 Max, job + m3-max-62174: nil for a side of 0, the process ended for a count of 0); a side past the device's `maxFramebufferWidth` or `maxFramebufferHeight`, `Gap::RenderPass` of `NoAttachment` (every venue dumped reports 16384 or more, Metal's largest side). - A pass of `renderTargetArrayLength` N of 2 or more is one rendering of `layerCount` N: every diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index ea6271764..9d1b98159 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -854,11 +854,12 @@ pub enum Refusal { pixel_format: PixelFormat, }, /// A render pass with no attachment whose `renderTargetWidth` or `renderTargetHeight` is 0, - /// or whose `defaultRasterSampleCount` is no sample count, a power of two up to 64 (Metal's - /// default 0 included). + /// or whose `defaultRasterSampleCount` is 0, Metal's default. /// - /// Basis: ours (such a pass has no area or no samples to render at, and Vulkan's rendering - /// has an area, VUID-VkRenderingInfo-None-08994 and -08995). + /// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1, the API validation layer off, + /// m3-max-62174, `probes/no_attachment_passes.m`: a side of 0 makes no encoder, nil, and a + /// count of 0 ends the process at the encoder, SIGABRT, where 64 by 64 pixels at 1 sample + /// makes one). NoAttachmentPass { /// `renderTargetWidth`. width: u32, diff --git a/crates/metal2vulkan-runtime/src/pass.rs b/crates/metal2vulkan-runtime/src/pass.rs index 78187b445..86ca51cfc 100644 --- a/crates/metal2vulkan-runtime/src/pass.rs +++ b/crates/metal2vulkan-runtime/src/pass.rs @@ -363,7 +363,8 @@ pub struct RenderPassDescriptor { /// attachment is that tall. pub render_target_height: u32, /// `defaultRasterSampleCount`: the samples of a pass with no attachment, 0 by default as in - /// Metal. Such a pass draws with pipeline states of that `raster_sample_count` + /// Metal, where such a pass is refused. It draws with pipeline states of that + /// `raster_sample_count` /// ([`DrawKind::AttachmentFormats`](crate::DrawKind::AttachmentFormats) otherwise), which /// reach their answers through memory alone. A pass with an attachment takes its /// attachments' samples and reads none of this, as Metal's does. @@ -931,7 +932,7 @@ impl Pass { // rendering of no attachment takes the pipeline's samples alone. let size = [d.render_target_width, d.render_target_height]; let count = d.default_raster_sample_count; - if size.contains(&0) || !(count.is_power_of_two() && count <= 64) { + if size.contains(&0) || count == 0 { return Err(Error::Refused(Refusal::NoAttachmentPass { width: size[0], height: size[1], diff --git a/crates/metal2vulkan-runtime/src/tests/no_attachment.rs b/crates/metal2vulkan-runtime/src/tests/no_attachment.rs index cb0f124e6..e799cc315 100644 --- a/crates/metal2vulkan-runtime/src/tests/no_attachment.rs +++ b/crates/metal2vulkan-runtime/src/tests/no_attachment.rs @@ -10,7 +10,7 @@ //! holds every sample and the count is 4 times the samples, Metal's answer. `rt6_mark_coverage` //! runs as the device runs it: every pixel's word holds every sample, and it ran at least once //! a pixel. -//! - A pass of no area or of no sample count is `Refusal::NoAttachmentPass`, one past the device's +//! - A pass of no area or of 0 samples is `Refusal::NoAttachmentPass`, one past the device's //! `maxFramebufferWidth` is `Gap::RenderPass` of `NoAttachment`, and a draw of a pipeline state //! of another sample count than the pass's is `DrawKind::AttachmentFormats`. @@ -110,7 +110,6 @@ mod on_device { (pass(0, 2, 1), "no width"), (pass(2, 0, 1), "no height"), (pass(2, 2, 0), "Metal's default count"), - (pass(2, 2, 3), "3 samples"), ]; for (d, what) in refused { match command_buffer.render_command_encoder(&d) { @@ -141,7 +140,7 @@ mod on_device { run(name, &command_buffer); println!( "{name}: (fragment, samples, runs) {runs:?}; every pixel's every sample marked; \ - another state's count, no area, no count and past the device's width refused" + another state's count, no area, 0 samples and past the device's width refused" ); }); } diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 08b2e453e..fda99ed71 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -46,7 +46,7 @@ Columns: | 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 | | Devices below the runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 | -| The runtime's `Refusal` | 21 | 20 | 0 | 0 | 36 | 0 | 0 | 0 | +| The runtime's `Refusal` | 22 | 20 | 0 | 0 | 35 | 0 | 0 | 0 | | The runtime's `Limit` | 0 | 0 | 0 | 13 | 4 | 0 | 0 | 0 | | The runtime's `Gap` | 0 | 0 | 0 | 2 | 28 | 0 | 0 | 0 | @@ -326,7 +326,7 @@ Columns: | `ResolveFormat` | A resolve of a render pass color attachment of an integer pixel format | every device (a public call's own check of its arguments) | `metal-documented`: Metal's validation asserts that an integer color format "cannot be a MSAA resolve target", and plain Metal writes values no sample holds | 1: `crates/metal2vulkan-runtime/src/pass.rs (check)` | `-` | | `AttachmentPlace` | A render pass attachment or resolve texture of a level or slice past its texture's | every device (a public call's own check of its arguments) | `ours`: no texel of the texture is there to render into | 2: `crates/metal2vulkan-runtime/src/texture.rs (attachment_view, 2 sites)` | `-` | | `AttachmentFormat` | A render pass color attachment of a depth or stencil pixel format, a depth attachment of a format without depth, or a stencil attachment of a... | every device (a public call's own check of its arguments) | `metal-documented`: a color attachment takes a color-renderable format, a depth attachment a format with depth and a stencil attachment a format with stencil; Metal's validation stops the descriptor | 3: `crates/metal2vulkan-runtime/src/pass.rs (check, 3 sites)` | `-` | -| `NoAttachmentPass` | A render pass with no attachment whose `renderTargetWidth` or `renderTargetHeight` is 0, or whose `defaultRasterSampleCount` is no sample count, a... | every device (a public call's own check of its arguments) | `ours`: such a pass has no area or no samples to render at, and Vulkan's rendering has an area, VUID-VkRenderingInfo-None-08994 and -08995 | 1: `crates/metal2vulkan-runtime/src/pass.rs (check)` | `-` | +| `NoAttachmentPass` | A render pass with no attachment whose `renderTargetWidth` or `renderTargetHeight` is 0, or whose `defaultRasterSampleCount` is 0, Metal's default | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, the API validation layer off, m3-max-62174, `probes/no_attachment_passes.m`: a side of 0 makes no encoder, nil, and a count of 0 ends the process at the encoder, SIGABRT, where 64 by 64 pixels at 1 sample makes one | 1: `crates/metal2vulkan-runtime/src/pass.rs (check)` | `-` | | `VertexBufferOffset` | A draw whose vertex descriptor reads a vertex buffer at an offset at or past the buffer's length | every device (a public call's own check of its arguments) | `metal-documented`: a buffer's offset lies inside it; Metal's validation stops the bind | 1: `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` | `-` | | `IndexBufferOffset` | An indexed draw whose index buffer offset is not a multiple of the index size, or whose indices leave the buffer | every device (a public call's own check of its arguments) | `metal-documented`: the offset is a multiple of the index size and the indices lie in the buffer; Metal's validation stops the draw | 1: `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` | `-` | | `TessellationFactorOffset` | A tessellation factor buffer whose factors, at its address plus the offset, start at an odd byte | every device (a public call's own check of its arguments) | `metal-documented`: `setTessellationFactorBuffer:offset:instanceStride:`'s offset is a multiple of 4; Metal's validation stops a patch draw with any other | 1: `crates/metal2vulkan-runtime/src/render_encoder.rs (set_tessellation_factor_buffer)` | `-` |