Ask Metal for its heap texture sizes instead of quoting them

The steps this packet landed as, in order:
- Measure Metal's heap sizes and its queue slot limit, and record them

Content: the tree of `development` at 108ab95ce1, unchanged.
This commit is contained in:
Anees Iqbal committed 2026-10-26 13:19:08 +02:00
1 parent 2deb7567e5
commit 0deb8a3852
18 files changed
+10160 -1

No files matched your search

@@ -0,0 +1,258 @@
{
"format": 1,
"case": "command-queue-slots",
"suite_version": 1,
"answers": [
{
"key": {
"chip": "apple-m3-max",
"os_version": "27.0.1",
"os_build": "26A434",
"metal_level": "27.0.1"
},
"provenance": "metal_run",
"device": "Apple M3 Max",
"runs": 5,
"outcomes": [
{
"runs": 5,
"transcript": {
"root": {
"name": "case",
"observed": {
"value": "absent"
},
"children": [
{
"name": "inputs",
"observed": {
"value": "absent"
},
"children": [
{
"name": "queues",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "2ac3b6d0a386d0232917bf5efc2bb6f49ac14dc2f768ff4f39d8a5b5bdcf8f47"
}
}
},
{
"name": "blocked-window-millis",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "1e7be6b7b822671624a11e5bad13b99f401945b10fce09c9b3a6e746970c1ad3"
}
}
}
]
},
{
"name": "default-count",
"observed": {
"value": "absent"
},
"children": [
{
"name": "answered-at-once",
"observed": {
"value": {
"uint": 64
}
}
},
{
"name": "next-make",
"observed": {
"value": {
"variant": {
"name": "Blocked",
"payload": "absent"
}
}
}
},
{
"name": "answered-once-a-slot-came-back",
"observed": {
"value": {
"bool": true
}
}
},
{
"name": "another-queue-went-on",
"observed": {
"value": {
"bool": true
}
}
}
]
},
{
"name": "max-1",
"observed": {
"value": "absent"
},
"children": [
{
"name": "answered-at-once",
"observed": {
"value": {
"uint": 1
}
}
},
{
"name": "next-make",
"observed": {
"value": {
"variant": {
"name": "Blocked",
"payload": "absent"
}
}
}
},
{
"name": "answered-once-a-slot-came-back",
"observed": {
"value": {
"bool": true
}
}
},
{
"name": "another-queue-went-on",
"observed": {
"value": {
"bool": true
}
}
}
]
},
{
"name": "max-4",
"observed": {
"value": "absent"
},
"children": [
{
"name": "answered-at-once",
"observed": {
"value": {
"uint": 4
}
}
},
{
"name": "next-make",
"observed": {
"value": {
"variant": {
"name": "Blocked",
"payload": "absent"
}
}
}
},
{
"name": "answered-once-a-slot-came-back",
"observed": {
"value": {
"bool": true
}
}
},
{
"name": "another-queue-went-on",
"observed": {
"value": {
"bool": true
}
}
}
]
},
{
"name": "max-65",
"observed": {
"value": "absent"
},
"children": [
{
"name": "answered-at-once",
"observed": {
"value": {
"uint": 65
}
}
},
{
"name": "next-make",
"observed": {
"value": {
"variant": {
"name": "Blocked",
"payload": "absent"
}
}
}
},
{
"name": "answered-once-a-slot-came-back",
"observed": {
"value": {
"bool": true
}
}
},
{
"name": "another-queue-went-on",
"observed": {
"value": {
"bool": true
}
}
}
]
},
{
"name": "notices",
"observed": {
"value": "absent"
},
"children": [
{
"name": "set",
"observed": {
"value": {
"nothing": "announced_nothing"
}
}
},
{
"name": "counts",
"observed": {
"value": {
"fields": {}
}
}
}
]
}
]
}
}
}
],
"validated": "ran"
}
]
}
@@ -0,0 +1,646 @@
{
"format": 1,
"case": "heap-sizes-422",
"suite_version": 1,
"answers": [
{
"key": {
"chip": "apple-m3-max",
"os_version": "27.0.1",
"os_build": "26A434",
"metal_level": "27.0.1"
},
"provenance": "metal_run",
"device": "Apple M3 Max",
"runs": 3,
"outcomes": [
{
"runs": 3,
"transcript": {
"root": {
"name": "case",
"observed": {
"value": "absent"
},
"children": [
{
"name": "inputs",
"observed": {
"value": "absent"
},
"children": [
{
"name": "descriptors",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "f86b2fe73fc6de659b92c3b56356700f109613d9c94833cb5826f28cc02fe2a6"
}
}
},
{
"name": "asks",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "5ad9f1c7d777f325c170b05463244fe8a9226b75870e819241dd1883aba65872"
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/64x32x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 4096
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/64x32x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 4096
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/8x8x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 128
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/8x8x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 128
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/6x3x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 44
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/6x3x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 44
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/10x5x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 148
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/10x5x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 148
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/1000x3x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 6000
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatGBGR422/Type2D/1000x3x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 6000
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/64x32x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 4096
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/64x32x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 4096
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/8x8x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 128
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/8x8x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 128
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/6x3x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 44
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/6x3x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 44
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/10x5x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 148
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/10x5x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 148
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/1000x3x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 6000
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRG422/Type2D/1000x3x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 6000
}
}
}
}
}
}
}
]
},
{
"name": "notices",
"observed": {
"value": "absent"
},
"children": [
{
"name": "set",
"observed": {
"value": {
"nothing": "announced_nothing"
}
}
},
{
"name": "counts",
"observed": {
"value": {
"fields": {}
}
}
}
]
}
]
}
}
}
],
"validated": "ran"
}
]
}
@@ -0,0 +1,982 @@
{
"format": 1,
"case": "heap-sizes-block-writes-only",
"suite_version": 1,
"answers": [
{
"key": {
"chip": "apple-m3-max",
"os_version": "27.0.1",
"os_build": "26A434",
"metal_level": "27.0.1"
},
"provenance": "metal_run",
"device": "Apple M3 Max",
"runs": 3,
"outcomes": [
{
"runs": 3,
"transcript": {
"root": {
"name": "case",
"observed": {
"value": "absent"
},
"children": [
{
"name": "inputs",
"observed": {
"value": "absent"
},
"children": [
{
"name": "descriptors",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "7f3e8903d1542f745c42c082bcc3e3e2d5b2c9502051de6e69ff21b315a4d6cc"
}
}
},
{
"name": "asks",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "5ad9f1c7d777f325c170b05463244fe8a9226b75870e819241dd1883aba65872"
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2D/16x16x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 1152
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2D/16x16x1/levels-1/samples-1/slices-1/usage-0x10001/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 1152
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2D/16x16x1/levels-1/samples-1/slices-1/usage-0x5/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 1152
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2D/16x16x1/levels-1/samples-1/slices-1/usage-0x10005/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 1152
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2D/16x16x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 1152
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2D/16x16x1/levels-1/samples-1/slices-1/usage-0x10001/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 1152
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2D/16x16x1/levels-1/samples-1/slices-1/usage-0x5/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 1152
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2D/16x16x1/levels-1/samples-1/slices-1/usage-0x10005/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 1152
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA8Unorm/Type2D/100x37x1/levels-1/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 33024
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA8Unorm/Type2D/100x37x1/levels-1/samples-1/slices-1/usage-0x10001/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 33024
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA8Unorm/Type2D/100x37x1/levels-1/samples-1/slices-1/usage-0x5/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 33024
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA8Unorm/Type2D/100x37x1/levels-1/samples-1/slices-1/usage-0x10005/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 33024
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA8Unorm/Type2D/100x37x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 33024
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA8Unorm/Type2D/100x37x1/levels-1/samples-1/slices-1/usage-0x10001/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 33024
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA8Unorm/Type2D/100x37x1/levels-1/samples-1/slices-1/usage-0x5/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 33024
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA8Unorm/Type2D/100x37x1/levels-1/samples-1/slices-1/usage-0x10005/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 33024
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA16Float/Type2D/256x256x1/levels-9/samples-1/slices-1/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 702208
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA16Float/Type2D/256x256x1/levels-9/samples-1/slices-1/usage-0x10001/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 702208
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA16Float/Type2D/256x256x1/levels-9/samples-1/slices-1/usage-0x5/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 702208
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA16Float/Type2D/256x256x1/levels-9/samples-1/slices-1/usage-0x10005/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 702208
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA16Float/Type2D/256x256x1/levels-9/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 702208
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA16Float/Type2D/256x256x1/levels-9/samples-1/slices-1/usage-0x10001/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 702208
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA16Float/Type2D/256x256x1/levels-9/samples-1/slices-1/usage-0x5/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 702208
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGBA16Float/Type2D/256x256x1/levels-9/samples-1/slices-1/usage-0x10005/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 702208
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2DArray/64x64x1/levels-1/samples-1/slices-4/usage-0x1/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16384
},
"size": {
"uint": 66048
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2DArray/64x64x1/levels-1/samples-1/slices-4/usage-0x10001/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16384
},
"size": {
"uint": 66048
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2DArray/64x64x1/levels-1/samples-1/slices-4/usage-0x5/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16384
},
"size": {
"uint": 66048
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2DArray/64x64x1/levels-1/samples-1/slices-4/usage-0x10005/shared",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16384
},
"size": {
"uint": 66048
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2DArray/64x64x1/levels-1/samples-1/slices-4/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16384
},
"size": {
"uint": 66048
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2DArray/64x64x1/levels-1/samples-1/slices-4/usage-0x10001/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16384
},
"size": {
"uint": 66048
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2DArray/64x64x1/levels-1/samples-1/slices-4/usage-0x5/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16384
},
"size": {
"uint": 66048
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatBGRA8Unorm/Type2DArray/64x64x1/levels-1/samples-1/slices-4/usage-0x10005/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16384
},
"size": {
"uint": 66048
}
}
}
}
}
}
}
]
},
{
"name": "notices",
"observed": {
"value": "absent"
},
"children": [
{
"name": "set",
"observed": {
"value": {
"nothing": "announced_nothing"
}
}
},
{
"name": "counts",
"observed": {
"value": {
"fields": {}
}
}
}
]
}
]
}
}
}
],
"validated": "ran"
}
]
}
@@ -0,0 +1,250 @@
{
"format": 1,
"case": "heap-sizes-two-plane-cubes",
"suite_version": 1,
"answers": [
{
"key": {
"chip": "apple-m3-max",
"os_version": "27.0.1",
"os_build": "26A434",
"metal_level": "27.0.1"
},
"provenance": "metal_run",
"device": "Apple M3 Max",
"runs": 3,
"outcomes": [
{
"runs": 3,
"transcript": {
"root": {
"name": "case",
"observed": {
"value": "absent"
},
"children": [
{
"name": "inputs",
"observed": {
"value": "absent"
},
"children": [
{
"name": "descriptors",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "68003b6b0bbb5517c21ee3c31064eafd7b95d3d9019de7e71805cec4cb64d7bf"
}
}
},
{
"name": "asks",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "2982767eac54020323467b76110615acbd2ab691ea26dd8994e183659ee35d12"
}
}
}
]
},
{
"name": "MTLPixelFormatRGB10A8_2P_XR10/Cube/32x32x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 0
}
}
}
}
}
}
},
{
"name": "makes-texture",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"bool": false
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGB10A8_2P_XR10/CubeArray/32x32x1/levels-1/samples-1/slices-2/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 0
}
}
}
}
}
}
},
{
"name": "makes-texture",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"bool": false
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGB10A8_2P_XR10_sRGB/Cube/32x32x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 0
}
}
}
}
}
}
},
{
"name": "makes-texture",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"bool": false
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatRGB10A8_2P_XR10_sRGB/CubeArray/32x32x1/levels-1/samples-1/slices-2/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 16
},
"size": {
"uint": 0
}
}
}
}
}
}
},
{
"name": "makes-texture",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"bool": false
}
}
}
}
}
]
},
{
"name": "notices",
"observed": {
"value": "absent"
},
"children": [
{
"name": "set",
"observed": {
"value": {
"nothing": "announced_nothing"
}
}
},
{
"name": "counts",
"observed": {
"value": {
"fields": {}
}
}
}
]
}
]
}
}
}
],
"validated": "ran"
}
]
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,422 @@
{
"format": 1,
"case": "heap-sizes-x32-stencil8",
"suite_version": 1,
"answers": [
{
"key": {
"chip": "apple-m3-max",
"os_version": "27.0.1",
"os_build": "26A434",
"metal_level": "27.0.1"
},
"provenance": "metal_run",
"device": "Apple M3 Max",
"runs": 3,
"outcomes": [
{
"runs": 3,
"transcript": {
"root": {
"name": "case",
"observed": {
"value": "absent"
},
"children": [
{
"name": "inputs",
"observed": {
"value": "absent"
},
"children": [
{
"name": "descriptors",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "d3b65d1334617b816812b79bb42a151bfa154a2c0036772005b4ab39d14488e4"
}
}
},
{
"name": "asks",
"observed": {
"value": "absent",
"digest": {
"kind": "sha256",
"hex": "5ad9f1c7d777f325c170b05463244fe8a9226b75870e819241dd1883aba65872"
}
}
}
]
},
{
"name": "MTLPixelFormatX32_Stencil8/Type2D/64x32x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 2176
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatX32_Stencil8/Type2D/6x3x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 128
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatX32_Stencil8/Type2D/1000x3x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 4096
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatX32_Stencil8/Type2D/64x64x1/levels-7/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 6272
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatX32_Stencil8/Type2DArray/64x64x1/levels-1/samples-1/slices-3/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 12672
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatX32_Stencil8/Cube/32x32x1/levels-6/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 12288
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatStencil8/Type2D/64x32x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 2176
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatStencil8/Type2D/6x3x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 128
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatStencil8/Type2D/1000x3x1/levels-1/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 4096
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatStencil8/Type2D/64x64x1/levels-7/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 6272
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatStencil8/Type2DArray/64x64x1/levels-1/samples-1/slices-3/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 12672
}
}
}
}
}
}
}
]
},
{
"name": "MTLPixelFormatStencil8/Cube/32x32x1/levels-6/samples-1/slices-1/usage-0x1/private",
"observed": {
"value": "absent"
},
"children": [
{
"name": "size-and-align",
"observed": {
"value": {
"variant": {
"name": "Ok",
"payload": {
"fields": {
"align": {
"uint": 128
},
"size": {
"uint": 12288
}
}
}
}
}
}
}
]
},
{
"name": "notices",
"observed": {
"value": "absent"
},
"children": [
{
"name": "set",
"observed": {
"value": {
"nothing": "announced_nothing"
}
}
},
{
"name": "counts",
"observed": {
"value": {
"fields": {}
}
}
}
]
}
]
}
}
}
],
"validated": "ran"
}
]
}
@@ -676,6 +676,54 @@ pub trait Side {
let _ = (targets, tile, steps);
Err(Failure::unavailable("tile_pass"))
}
/// `heapTextureSizeAndAlignWithDescriptor:` of the descriptor `query` names
/// ([`crate::texture_query`]).
///
/// A pure getter: it compiles nothing, allocates nothing and reaches no GPU, so a case over it
/// is safe on every device and its answer can be re-measured on the oracle as often as anybody
/// asks.
fn heap_texture_size_and_align(
&mut self,
query: &crate::texture_query::HeapTextureQuery,
) -> Answer<crate::texture_query::SizeAndAlign> {
let _ = query;
Err(Failure::unavailable("heap_texture_size_and_align"))
}
/// Whether `newTextureWithDescriptor:` of the descriptor `query` names answers a texture.
///
/// The answer is a **fact about the descriptor**, not about the object: Metal answers nil for a
/// descriptor it describes no texture of, and the runtime answers a typed `Nil` error for the
/// same descriptor, which is the same fact in the two APIs' spellings. So both sides answer
/// `false` there, and a side that refuses the call for any other reason answers its typed
/// error, which compares as a refusal.
///
/// A case asks this only of descriptors Metal makes no texture of, so nothing is allocated.
fn makes_texture(&mut self, query: &crate::texture_query::HeapTextureQuery) -> Answer<bool> {
let _ = query;
Err(Failure::unavailable("makes_texture"))
}
/// A command queue's limit on uncompleted command buffers, by the probe both sides run
/// ([`crate::queue_slots`]): the queue is made with `max` as its
/// `maxCommandBufferCount` (`newCommandQueue` where `max` is `None`), and at most `cap` command
/// buffers are made on a thread of its own.
///
/// The whole experiment is one call because what it observes is an **order of events** — a make
/// that did not return, another queue's make that did, and the first one answering once a slot
/// came back — and a case cannot state that as a sequence of independent calls.
///
/// Nothing is committed, so nothing reaches the GPU, and no make can be left unanswered: the
/// probe releases a blocked make by dropping a command buffer held uncommitted.
fn queue_slots(
&mut self,
max: Option<u32>,
cap: u32,
) -> Answer<crate::queue_slots::QueueSlots> {
let _ = (max, cap);
Err(Failure::unavailable("queue_slots"))
}
}
/// A tile render pipeline a case makes: `MTLTileRenderPipelineDescriptor`'s facts the cases state.
@@ -17,9 +17,11 @@
//!
//! No case here can fault a GPU, hang it, trip its watchdog or end Metal's process.
pub mod command_queues;
pub mod depth_texel_reads;
pub mod extended_range_planes;
pub mod extended_range_two_planes;
pub mod heap_metal_sizes;
pub mod indirect_private_types;
pub mod math_routines;
pub mod mesh_barriers;
@@ -94,6 +96,10 @@ pub fn all() -> Vec<Box<dyn Case>> {
for case in tile_threadgroups::all() {
cases.push(Box::new(case));
}
for case in heap_metal_sizes::all() {
cases.push(Box::new(case));
}
cases.push(Box::new(command_queues::queue_slots()));
cases
}
@@ -0,0 +1,109 @@
//! A command queue's limit on uncompleted command buffers: the first case whose subject is a call
//! that **did not return**.
//!
//! Metal's `commandBuffer` blocks once a queue holds `maxCommandBufferCount` uncompleted command
//! buffers, and answers once one of them is dropped uncommitted or completes. The case records four
//! facts per queue ([`crate::queue_slots::QueueSlots`]): how many makes answered at once, that the
//! next one did not, that it answered once a slot came back, and that another queue's make went on
//! meanwhile.
//!
//! # What it pulls forward
//!
//! `runtime_lane::command_queues` holds Metal's default count as `METAL_DEFAULT: usize = 64`, a
//! constant with the word "measured" beside it and no run behind it. The first row here measures it
//! on the oracle: the default queue's probe makes command buffers until one blocks, up to a cap
//! above 64, so the number in the recording is the number Metal answered rather than the number
//! somebody wrote down. A release where Apple changes it fails the case.
//!
//! # Why it is safe
//!
//! Nothing is committed, so nothing reaches the GPU: the probe makes command buffers, holds them,
//! and drops them. Every make runs on a thread of its own and a blocked one is released by the
//! probe, so no wait here can hang ([`crate::queue_slots::probe`]).
//!
//! **A count of 0 is deliberately not a row.** Metal's own validation ends the process on
//! `maxCommandBufferCount:0` — the runtime says so by answering `Invalid` rather than `Nil` — so no
//! case may ask Metal for it. The runtime's typed refusal of a count of 0 stays a `runtime_lane`
//! assertion, where no Metal run is involved.
use crate::case::{Abort, Case, Input, MetalSource, Side};
use crate::transcript::{Node, Observed, Sites};
/// The case's name.
pub const QUEUE_SLOTS: &str = "command-queue-slots";
/// The queues the case probes: the `maxCommandBufferCount` it is made with, and how many makes the
/// probe tries before it gives up on finding a limit.
///
/// The default queue's cap is above Metal's measured 64 on purpose: the probe is **discovering** the
/// limit, not confirming one, so a release that raised it would be recorded rather than mistaken for
/// a block at 64. The stated counts need one make past their own count and no more.
const QUEUES: [(Option<u32>, u32); 4] = [(None, 70), (Some(1), 2), (Some(4), 5), (Some(65), 66)];
/// A case over the slot limits of a few command queues.
pub struct CommandQueueSlots {
name: &'static str,
}
/// The case.
pub fn queue_slots() -> CommandQueueSlots {
CommandQueueSlots { name: QUEUE_SLOTS }
}
/// The site one queue's row sits at.
fn row(max: Option<u32>) -> String {
match max {
None => "default-count".to_owned(),
Some(max) => format!("max-{max}"),
}
}
impl Case for CommandQueueSlots {
fn name(&self) -> &'static str {
self.name
}
fn metal_source(&self) -> MetalSource {
MetalSource::Run
}
fn inputs(&self) -> Result<Vec<Input>, String> {
// What the case feeds: each queue's stated count and the probe's cap, in order, and the
// window a make must stay unanswered to count as blocked. The window is an input because
// it decides what the answer means.
let mut words = Vec::new();
for (max, cap) in QUEUES {
words.extend(max.unwrap_or(u32::MAX).to_le_bytes());
words.extend(cap.to_le_bytes());
}
Ok(vec![
Input::bytes("queues", &words),
Input::bytes(
"blocked-window-millis",
&(crate::queue_slots::BLOCKED.as_millis() as u64).to_le_bytes(),
),
])
}
fn record_runs(&self) -> u32 {
// A probe that reads a timeout is reading a race, however wide the window: a make slowed by
// the machine rather than by the queue's limit would read as blocked. More runs do not
// remove that, but they record it — the recording holds the set of outcomes with their
// frequencies, so a row that flaps says so instead of passing as whichever run came last.
5
}
fn run(&self, side: &mut dyn Side, sites: &mut Sites) -> Result<(), Abort> {
for (max, cap) in QUEUES {
let at = row(max);
match side.queue_slots(max, cap) {
Ok(slots) => sites.push(slots.node(at)),
// A queue the side could not make, or a make that answered an error, is recorded at
// the row and the sweep goes on: the other queues' answers stay readable, and a
// refusal where Metal answered compares as a refusal at that one row.
Err(failure) => sites.push(Node::leaf(at, Observed::value(failure.value))),
}
}
Ok(())
}
}
@@ -0,0 +1,466 @@
//! `heapTextureSizeAndAlignWithDescriptor:`: Metal's own layout arithmetic, asked directly.
//!
//! This family is the suite's first **pure getter sweep**. Each case holds a table of descriptors
//! ([`crate::texture_query::HeapTextureQuery`]) and records, per descriptor, the two numbers Metal
//! answers; some also record whether `newTextureWithDescriptor:` answers a texture at all, which is
//! the fact that makes a 0-byte answer mean something.
//!
//! # Why this family came first
//!
//! `runtime_lane`'s `heap_metal_sizes` carries the numbers these cases measure — 44 bytes for a
//! 6 x 3 4:2:2 texture, 20480 for a 64 x 64 two-plane extended-range one, and some 240 more — and
//! until now nothing tied them to a Metal run: they were taken on an Apple M4 by hand, written into
//! assertions, and the probe was thrown away. The runtime answers them from a **model** of Metal's
//! arithmetic (`texture/heap_tiled.rs`) that is the same on every device at one Metal level, so the
//! numbers are a contract with Metal and with nothing else, and the only thing that can check them
//! is Metal. Record mode now does, on the oracle, as often as anybody asks.
//!
//! # Why every case here is safe
//!
//! The query compiles nothing, allocates nothing and reaches no GPU: it is CPU arithmetic over a
//! descriptor. `newTextureWithDescriptor:` is asked **only of descriptors Metal answers nil for**,
//! so it allocates nothing either.
//!
//! The one real hazard is the descriptors Metal's own validation stops, which **end Metal's
//! process** — the runtime spells that distinction out: `Error::Nil` is "plain Metal answers nil,
//! the process going on", while `Error::Invalid` is "Metal's validation stops it, ending the
//! process". Every such descriptor is left out of this family by construction, and the exclusions
//! are named where they are made:
//!
//! - `ShaderAtomic` usage of any format but `R32Uint` (a failed assertion without the debug layer
//! too), so no case here sets that bit;
//! - a multisample descriptor of a format Metal describes no texture of;
//! - a one-dimensional, 3D or buffer descriptor of `AnyDepth` or `AnyStencil`;
//! - an extent of 0 and a side past 16384.
//!
//! The order of work is what keeps that honest rather than hopeful: a new descriptor is replayed on
//! the runtime first, where an `Invalid` answer is a recorded value and nothing else, and only a
//! table that answers no `Invalid` anywhere is ever handed to Metal.
use crate::case::{Abort, Case, Input, MetalSource, Side};
use crate::texture_query::{HeapTextureQuery as Q, Storage};
use crate::transcript::{Node, Observed, Sites, Value};
use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage};
/// The two storage modes every case of the family sweeps.
const BOTH_STORAGE: [Storage; 2] = [Storage::Shared, Storage::Private];
/// The case names, as the report and the recordings spell them.
pub const FOUR_TWO_TWO: &str = "heap-sizes-422";
pub const X32_STENCIL8: &str = "heap-sizes-x32-stencil8";
pub const TWO_PLANE: &str = "heap-sizes-two-plane-extended-range";
pub const TWO_PLANE_CUBES: &str = "heap-sizes-two-plane-cubes";
pub const UNSPECIALIZED: &str = "heap-sizes-unspecialized";
pub const NO_TEXTURE_FORMATS: &str = "heap-sizes-formats-without-textures";
pub const BLOCK_WRITES_ONLY: &str = "heap-sizes-block-writes-only";
/// The site a descriptor's two answers sit under.
mod site {
/// The heap size query's answer.
pub const QUERY: &str = "size-and-align";
/// Whether `newTextureWithDescriptor:` answered a texture.
pub const TEXTURE: &str = "makes-texture";
}
/// A case over one table of descriptors: the heap size query's answer for each, and for a table of
/// descriptors Metal makes no texture of, that fact too.
pub struct HeapSizeCase {
name: &'static str,
queries: Vec<Q>,
/// Whether the case also asks `newTextureWithDescriptor:`.
///
/// True only for a table of descriptors Metal answers **nil** for, so the call allocates
/// nothing and cannot end Metal's process.
asks_texture: bool,
}
/// Every case of the family.
pub fn all() -> Vec<HeapSizeCase> {
vec![
four_two_two(),
x32_stencil8(),
two_plane(),
two_plane_cubes(),
unspecialized(),
formats_without_textures(),
block_writes_only(),
]
}
/// Metal's answer for a 4:2:2 texture, whose rows of two-byte texels Metal pads to a multiple of
/// 16 bytes with the last row unpadded, at an alignment of 16.
///
/// The five shapes are the ones whose arithmetic the padding rule shows: a power-of-two extent, a
/// small one, two whose rows need padding, and one 1000 texels wide.
fn four_two_two() -> HeapSizeCase {
let mut queries = Vec::new();
for format in [PixelFormat::GBGR422, PixelFormat::BGRG422] {
for size in [[64, 32], [8, 8], [6, 3], [10, 5], [1000, 3]] {
for storage in BOTH_STORAGE {
queries.push(Q::texture_2d(format, size, storage));
}
}
}
HeapSizeCase {
name: FOUR_TWO_TWO,
queries,
asks_texture: false,
}
}
/// `X32_Stencil8` beside `Stencil8` over one set of shapes: both answers are recorded, so the
/// relation the runtime lane asserts — that the two descriptors answer alike — is a fact a reader
/// of the recording can check, and a release where Apple parts them fails the case rather than
/// passing under a rule nobody re-measured.
fn x32_stencil8() -> HeapSizeCase {
let mut queries = Vec::new();
for format in [PixelFormat::X32Stencil8, PixelFormat::Stencil8] {
for (texture_type, size, levels, slices) in [
(TextureType::Type2D, [64, 32], 1, 1),
(TextureType::Type2D, [6, 3], 1, 1),
(TextureType::Type2D, [1000, 3], 1, 1),
(TextureType::Type2D, [64, 64], 7, 1),
(TextureType::Type2DArray, [64, 64], 1, 3),
(TextureType::Cube, [32, 32], 6, 1),
] {
queries.push(
Q::texture_2d(format, size, Storage::Private)
.of_type(texture_type, 1, slices)
.with_levels(levels),
);
}
}
HeapSizeCase {
name: X32_STENCIL8,
queries,
asks_texture: false,
}
}
/// A two-plane extended-range texture in every texture type Metal makes one of, in both storage
/// modes: the family whose answers the consumer's video path depends on, and the one whose numbers
/// are least guessable (a 1 x 1 texture answers 16385 bytes).
fn two_plane() -> HeapSizeCase {
let mut queries = Vec::new();
let usage = TextureUsage::SHADER_READ.union(TextureUsage::SHADER_WRITE);
for format in [PixelFormat::RGB10A82PXR10, PixelFormat::RGB10A82PXR10SRGB] {
for (texture_type, size, levels, slices) in [
(TextureType::Type2D, [64, 64, 1], 1, 1),
(TextureType::Type2D, [1, 1, 1], 1, 1),
(TextureType::Type2D, [7, 3, 1], 1, 1),
(TextureType::Type2D, [1000, 3, 1], 1, 1),
(TextureType::Type2D, [64, 65, 1], 1, 1),
(TextureType::Type2D, [7, 600, 1], 1, 1),
(TextureType::Type2D, [1920, 1080, 1], 1, 1),
(TextureType::Type2D, [64, 64, 1], 7, 1),
(TextureType::Type2D, [17, 9, 1], 5, 1),
(TextureType::Type2DArray, [64, 64, 1], 1, 3),
(TextureType::Type2DArray, [7, 3, 1], 1, 5),
(TextureType::Type2DArray, [64, 65, 1], 1, 2),
(TextureType::Type2DArray, [17, 9, 1], 3, 2),
(TextureType::Type1D, [64, 1, 1], 1, 1),
(TextureType::Type1D, [5000, 1, 1], 1, 1),
(TextureType::Type1DArray, [7, 1, 1], 1, 5),
(TextureType::Type1DArray, [5000, 1, 1], 1, 4),
(TextureType::Type3D, [64, 64, 4], 1, 1),
(TextureType::Type3D, [32, 32, 20], 1, 1),
(TextureType::Type3D, [64, 64, 4], 3, 1),
] {
for storage in BOTH_STORAGE {
queries.push(
Q::texture_2d(format, [size[0], size[1]], storage)
.of_type(texture_type, size[2], slices)
.with_levels(levels)
.with_usage(usage),
);
}
}
}
HeapSizeCase {
name: TWO_PLANE,
queries,
asks_texture: false,
}
}
/// A two-plane extended-range cube and cube array: 0 bytes at an alignment of 16, and no texture.
///
/// Its own case rather than a row of [`two_plane`], because it is the one shape of the family where
/// the 0-byte answer only means something beside the second fact: a descriptor Metal describes no
/// texture of.
fn two_plane_cubes() -> HeapSizeCase {
let mut queries = Vec::new();
for format in [PixelFormat::RGB10A82PXR10, PixelFormat::RGB10A82PXR10SRGB] {
for (texture_type, slices) in [(TextureType::Cube, 1), (TextureType::CubeArray, 2)] {
queries.push(Q::texture_2d(format, [32, 32], Storage::Private).of_type(
texture_type,
1,
slices,
));
}
}
HeapSizeCase {
name: TWO_PLANE_CUBES,
queries,
asks_texture: true,
}
}
/// The eight texture types a descriptor of a format with no texture is asked in, with the depth and
/// slice count each type takes. The two multisample types are left out of every such case: Metal's
/// validation stops a multisample descriptor of a format it describes no texture of, which ends its
/// process.
const STACKABLE_TYPES: [(TextureType, u32, u32); 8] = [
(TextureType::Type1D, 1, 1),
(TextureType::Type1DArray, 1, 2),
(TextureType::Type2D, 1, 1),
(TextureType::Type2DArray, 1, 2),
(TextureType::Cube, 1, 1),
(TextureType::CubeArray, 1, 2),
(TextureType::Type3D, 2, 1),
(TextureType::TextureBuffer, 1, 1),
];
/// `Unspecialized`, Apple's private format: 0 bytes at the alignment of its texture type, and no
/// texture from any creator.
///
/// The alignment is the subject. It is a Metal-level fact — 16 KiB for the stacked types under
/// macOS 26.7, 128 under 27.0.1 — which is exactly the kind of answer a recording keyed by Metal
/// level exists to hold, and exactly the kind a comment cannot.
///
/// `ShaderAtomic` is not among the usages, and must not be: Metal ends its own process on it.
fn unspecialized() -> HeapSizeCase {
let mut queries = Vec::new();
for storage in BOTH_STORAGE {
for (texture_type, depth, slices) in STACKABLE_TYPES {
for usage in [
TextureUsage::SHADER_READ,
TextureUsage::SHADER_READ.union(TextureUsage::SHADER_WRITE),
TextureUsage::RENDER_TARGET,
] {
queries.push(
Q::texture_2d(PixelFormat::Unspecialized, [16, 16], storage)
.of_type(texture_type, depth, slices)
.with_usage(usage),
);
}
}
}
HeapSizeCase {
name: UNSPECIALIZED,
queries,
asks_texture: true,
}
}
/// The formats Metal describes no texture of alone: `RGBA16Float_XR`, `AnyDepth`, `AnyStencil` and
/// a two-plane YCbCr format. Each answers 0 bytes at its texture type's alignment, and no texture.
///
/// `AnyDepth` and `AnyStencil` are asked in the 2D and cube types alone: Metal's validation stops a
/// one-dimensional, 3D or buffer descriptor of either, which ends its process.
fn formats_without_textures() -> HeapSizeCase {
let mut queries = Vec::new();
for format in [
PixelFormat::RGBA16FloatXR,
PixelFormat::AnyDepth,
PixelFormat::AnyStencil,
PixelFormat::YCBCR84202P,
] {
let any_depth = matches!(format, PixelFormat::AnyDepth | PixelFormat::AnyStencil);
for (texture_type, depth, slices) in STACKABLE_TYPES {
let one_dimensional =
matches!(texture_type, TextureType::Type1D | TextureType::Type1DArray);
let volume_or_buffer = matches!(
texture_type,
TextureType::Type3D | TextureType::TextureBuffer
);
if any_depth && (one_dimensional || volume_or_buffer) {
continue;
}
for storage in BOTH_STORAGE {
queries.push(Q::texture_2d(format, [64, 64], storage).of_type(
texture_type,
depth,
slices,
));
}
}
}
HeapSizeCase {
name: NO_TEXTURE_FORMATS,
queries,
asks_texture: true,
}
}
/// Apple's private `BlockWritesOnly` usage bit (0x10000) beside the same descriptor without it:
/// both answers are recorded, so the relation the runtime lane asserts — that the bit changes no
/// heap answer — is a fact a reader can check rather than a rule.
fn block_writes_only() -> HeapSizeCase {
let mut queries = Vec::new();
for (format, texture_type, size, levels, slices) in [
(PixelFormat::BGRA8Unorm, TextureType::Type2D, [16, 16], 1, 1),
(
PixelFormat::RGBA8Unorm,
TextureType::Type2D,
[100, 37],
1,
1,
),
(
PixelFormat::RGBA16Float,
TextureType::Type2D,
[256, 256],
9,
1,
),
(
PixelFormat::BGRA8Unorm,
TextureType::Type2DArray,
[64, 64],
1,
4,
),
] {
for storage in BOTH_STORAGE {
for base in [
TextureUsage::SHADER_READ,
TextureUsage::SHADER_READ.union(TextureUsage::RENDER_TARGET),
] {
for usage in [base, base.union(TextureUsage::BLOCK_WRITES_ONLY)] {
queries.push(
Q::texture_2d(format, size, storage)
.of_type(texture_type, 1, slices)
.with_levels(levels)
.with_usage(usage),
);
}
}
}
}
HeapSizeCase {
name: BLOCK_WRITES_ONLY,
queries,
asks_texture: false,
}
}
impl Case for HeapSizeCase {
fn name(&self) -> &'static str {
self.name
}
fn metal_source(&self) -> MetalSource {
MetalSource::Run
}
fn inputs(&self) -> Result<Vec<Input>, String> {
// The descriptors are the whole of what the case feeds, and the order it asks them in: a
// table that gains, loses or re-points a row is a change to the case's inputs, so a
// recording cannot decay into the answers of descriptors nobody asked about.
let mut words = Vec::new();
for query in &self.queries {
words.extend(query.words());
}
Ok(vec![
Input::bytes("descriptors", &words),
Input::bytes(
"asks",
if self.asks_texture {
b"heapTextureSizeAndAlign,newTextureWithDescriptor".as_slice()
} else {
b"heapTextureSizeAndAlign".as_slice()
},
),
])
}
fn run(&self, side: &mut dyn Side, sites: &mut Sites) -> Result<(), Abort> {
for query in &self.queries {
let mut node = Node::branch(query.site(), Vec::new());
// Each descriptor's answer is a site of its own, and a call that did not answer is
// recorded at its site and the sweep goes on: one descriptor the runtime refuses
// compares as a refusal at that one site, and the other 200 answers stay readable
// instead of being lost behind an abort.
let answered = match side.heap_texture_size_and_align(query) {
Ok(answered) => Value::ok(answered.value()),
Err(failure) => failure.value,
};
node = node.with(Node::leaf(site::QUERY, Observed::value(answered)));
if self.asks_texture {
let made = match side.makes_texture(query) {
Ok(made) => Value::ok(Value::Bool(made)),
Err(failure) => failure.value,
};
node = node.with(Node::leaf(site::TEXTURE, Observed::value(made)));
}
sites.push(node);
}
Ok(())
}
}
/// The safety guard this family rests on, run on a device.
///
/// Record mode hands every descriptor of these tables to Metal. A descriptor Metal's own validation
/// stops **ends Metal's process**, and the runtime's model is what tells the two apart:
/// `Error::Invalid` is "Metal's validation stops it, ending the process", while `Error::Nil` is
/// "plain Metal answers nil, the process going on". So a table that makes the runtime answer
/// `Invalid` anywhere is a table that must never be recorded, and this is the check that says so
/// before anybody runs `conformance record`.
///
/// It is also the check that would catch a table growing a row somebody assumed was harmless. Its
/// failure mode was exercised while writing it: a 2D descriptor of width 0 added to one table fails
/// here, naming the descriptor and the problem.
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
mod tests {
use super::*;
use crate::device::{self, Notices, ScratchCache, Venues};
use crate::runtime_side::RuntimeSide;
/// The venue the guard opens: a GPU where the tests are built for one, else a CPU ICD.
const VENUE: Venues = if cfg!(m2v_gpu) {
Venues::Gpu
} else {
Venues::Cpu
};
#[test]
fn no_descriptor_of_the_family_is_one_metals_validation_stops() {
let notices = Notices::default();
let cache = ScratchCache::new().unwrap();
let runtime = device::open(VENUE, &notices, &cache).unwrap();
let taker = notices.clone();
let mut side = RuntimeSide::new(&runtime, move || taker.take());
let mut stopped = Vec::new();
for case in all() {
for query in &case.queries {
let answer = side.heap_texture_size_and_align(query);
if let Err(failure) = &answer {
stopped.push(format!(
"{} {}: {:?}",
case.name,
query.site(),
failure.value
));
}
if case.asks_texture {
if let Err(failure) = side.makes_texture(query) {
stopped.push(format!(
"{} {} makes_texture: {:?}",
case.name,
query.site(),
failure.value
));
}
}
}
}
assert!(
stopped.is_empty(),
"these descriptors do not answer on the runtime, so Metal's validation may stop them \
and record mode would end Metal's process; take them out of the table:\n{}",
stopped.join("\n")
);
}
}
@@ -46,6 +46,7 @@ pub mod diff;
pub mod fixture;
pub mod known_refusals;
pub mod measured;
pub mod queue_slots;
pub mod record;
pub mod recording;
pub mod replay;
@@ -53,6 +54,7 @@ pub mod report;
pub mod run;
pub mod runtime_side;
pub mod runtime_work;
pub mod texture_query;
pub mod transcript;
pub mod validated;
pub mod verdict;
@@ -17,6 +17,8 @@ use crate::case::{
PassOutcome, RateMapFacts, RateMapRequest, SamplerSpec, ShaderSource, Side, StageInRegion,
StageInput, TextureRole, TextureSpec, TileFacts, TilePipelineSpec, TileStep, Venue,
};
use crate::queue_slots::QueueSlots;
use crate::texture_query::{HeapTextureQuery, SizeAndAlign, Storage};
use crate::transcript::Value;
use metal2vulkan::metal::PixelFormat;
use objc2::rc::Retained;
@@ -35,7 +37,7 @@ use objc2_metal::{
MTLRenderPipelineState, MTLRenderStages, MTLResource, MTLResourceOptions, MTLResourceUsage,
MTLSamplerAddressMode, MTLSamplerBorderColor, MTLSamplerDescriptor, MTLSamplerMinMagFilter,
MTLSamplerState, MTLSize, MTLStageInputOutputDescriptor, MTLStepFunction, MTLStorageMode,
MTLStoreAction, MTLTexture, MTLTextureDescriptor, MTLTextureUsage,
MTLStoreAction, MTLTexture, MTLTextureDescriptor, MTLTextureType, MTLTextureUsage,
MTLTileRenderPipelineDescriptor,
};
@@ -1052,6 +1054,94 @@ impl Side for MetalSide {
error,
})
}
fn heap_texture_size_and_align(&mut self, query: &HeapTextureQuery) -> Answer<SizeAndAlign> {
let descriptor = queried_descriptor(query);
let answered = self
.device
.heapTextureSizeAndAlignWithDescriptor(&descriptor);
Ok(SizeAndAlign {
size: answered.size as u64,
align: answered.align as u64,
})
}
fn queue_slots(&mut self, max: Option<u32>, cap: u32) -> Answer<QueueSlots> {
let queue = match max {
None => self.device.newCommandQueue(),
Some(max) => self
.device
.newCommandQueueWithMaxCommandBufferCount(max as usize),
}
.ok_or_else(|| Failure::named("NewCommandQueue", format!("{max:?} returned nil")))?;
let other = self
.device
.newCommandQueue()
.ok_or_else(|| Failure::named("NewCommandQueue", "the second queue returned nil"))?;
crate::queue_slots::probe(
cap,
move || {
// Each make gets an autorelease pool of its own, and that is load-bearing rather
// than tidy. `commandBuffer` answers an autoreleased object; the `Retained` is a
// second reference, so without a pool that drains, the probe's own release frees
// nothing, the slot never comes back, and the blocked make it is meant to release
// stays blocked (measured: the whole probe timed out). A worker thread has no pool
// of its own, so one is made here.
objc2::rc::autoreleasepool(|_| {
queue
.commandBuffer()
.map(Made)
.ok_or_else(|| Failure::named("CommandBuffer", "returned nil".to_owned()))
})
},
|| objc2::rc::autoreleasepool(|_| other.commandBuffer().is_some()),
)
}
fn makes_texture(&mut self, query: &HeapTextureQuery) -> Answer<bool> {
let descriptor = queried_descriptor(query);
// The texture, where Metal makes one, is released as this statement ends: the case asks
// this only of descriptors Metal makes none of, and nothing here keeps a handle, so no
// sweep of the family holds a texture it does not read.
Ok(self.device.newTextureWithDescriptor(&descriptor).is_some())
}
}
/// A command buffer the slot probe holds, so the thread that frees a slot need not be the thread
/// that made it.
///
/// `objc2` gives `MTLCommandBuffer` no `Send`, because Metal documents a command buffer as unsafe
/// to *encode into* from more than one thread. The probe encodes into none: it makes each command
/// buffer on one thread and only ever releases it from another, and releasing an Objective-C object
/// off the thread that made it is sound, since the retain count is atomic.
pub struct Made(pub Retained<ProtocolObject<dyn MTLCommandBuffer>>);
// SAFETY: as the type's documentation states: the probe never encodes into a held command buffer,
// and the only operation that crosses threads is the release.
unsafe impl Send for Made {}
/// Metal's descriptor for a queried one: every field the case names, by its raw ordinal, so a
/// private format and a private usage bit reach Metal as readily as a public one.
fn queried_descriptor(query: &HeapTextureQuery) -> Retained<MTLTextureDescriptor> {
let descriptor = MTLTextureDescriptor::new();
descriptor.setTextureType(MTLTextureType(query.texture_type.as_raw() as usize));
descriptor.setPixelFormat(MTLPixelFormat(query.format.as_raw() as usize));
// SAFETY: each extent, count and index is a case's own, and the setters read nothing but the
// value they are given.
unsafe {
descriptor.setWidth(query.size[0] as usize);
descriptor.setHeight(query.size[1] as usize);
descriptor.setDepth(query.size[2] as usize);
descriptor.setMipmapLevelCount(query.levels as usize);
descriptor.setSampleCount(query.samples as usize);
descriptor.setArrayLength(query.array_length as usize);
}
descriptor.setUsage(MTLTextureUsage(query.usage.as_raw() as usize));
descriptor.setStorageMode(match query.storage {
Storage::Shared => MTLStorageMode::Shared,
Storage::Private => MTLStorageMode::Private,
});
descriptor
}
/// The pixel format [`crate::case::TARGET_FORMAT`] names, as Metal spells it.
@@ -0,0 +1,174 @@
//! A command queue's limit on uncompleted command buffers, as a probe both sides run.
//!
//! Metal's `commandBuffer` **blocks** once a queue holds `maxCommandBufferCount` uncompleted
//! command buffers, and answers once one of them completes or is dropped uncommitted. It never
//! answers nil. That is a behaviour nothing in the suite could state before: the fact under test is
//! that a call *did not return*, and then that it did once a slot came back.
//!
//! `runtime_lane::command_queues` holds the number — `METAL_DEFAULT: usize = 64` — as a constant
//! with the word "measured" beside it. A case over this probe measures it instead, on the oracle,
//! and records it keyed to the oracle.
//!
//! # Why no wait here can hang
//!
//! Every make runs on a thread of its own, and the command buffers it makes go into a shared list
//! the probe's own thread can drain. So a make that blocks is always released by the probe dropping
//! one held command buffer, and the worker is told to stop as soon as the probe has its answer: the
//! worker makes at most one command buffer after the probe is done with it, and is joined. Nothing
//! is committed, so nothing reaches the GPU and no wait is for the device.
//!
//! # What is deliberately not here
//!
//! `maxCommandBufferCount:` of **0**. Metal's own validation ends the process on it (the runtime
//! answers `Invalid`, which is its word for exactly that), so no case may ask Metal for it. The
//! runtime's typed refusal of a count of 0 stays a `runtime_lane` assertion.
use crate::transcript::{Negative, Node, Observed, Value};
use std::time::Duration;
/// How long a make must stay unanswered to count as blocked.
///
/// Long enough that a make slowed by something other than the queue's limit — a queue's first use,
/// a loaded machine — is not read as blocked, and short enough that a case of four rows is quick.
/// A run where it is read wrong does not pass quietly: the recording holds the **set** of outcomes
/// over its runs, so a flapping row records as two outcomes and says so.
pub const BLOCKED: Duration = Duration::from_millis(400);
/// The longest the probe waits for a make it has just released.
pub const RELEASED: Duration = Duration::from_secs(30);
/// What one queue's slot probe observed.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct QueueSlots {
/// Makes that answered without blocking, from the queue's first: the queue's limit, where the
/// next one blocked.
pub answered_at_once: u32,
/// Whether the make past them stayed unanswered for [`BLOCKED`].
pub next_blocked: bool,
/// Whether that make answered once one held command buffer was dropped uncommitted.
///
/// `false` where it never blocked, since there was nothing to release.
pub answered_once_a_slot_came_back: bool,
/// Whether another queue's make answered while that one was blocked.
///
/// `false` where it never blocked. The fact is that one queue's limit is one queue's: a
/// runtime that took a device-wide lock would fail here.
pub other_queue_answered: bool,
}
impl QueueSlots {
/// The probe's observations as the sites a case emits under one node, so both sides emit one
/// shape.
pub fn node(&self, name: impl Into<crate::transcript::NodeName>) -> Node {
// "Did not block" is a fact of its own, not an absent field: a make that returned and a
// make nobody timed must read differently, and this is the record kind that says so.
let blocked = if self.next_blocked {
Value::unit_variant("Blocked")
} else {
Value::Nothing(Negative::DidNotBlock)
};
Node::branch(name, Vec::new())
.with(Node::leaf(
"answered-at-once",
Observed::value(Value::Uint(u64::from(self.answered_at_once))),
))
.with(Node::leaf("next-make", Observed::value(blocked)))
.with(Node::leaf(
"answered-once-a-slot-came-back",
Observed::value(Value::Bool(self.answered_once_a_slot_came_back)),
))
.with(Node::leaf(
"another-queue-went-on",
Observed::value(Value::Bool(self.other_queue_answered)),
))
}
}
/// Run the slot probe over at most `cap` makes of one queue: `make` makes the queue's next command
/// buffer, and `other_make` makes one on a second queue and says whether it answered.
///
/// The probe is shared by both sides so neither can drift into a different experiment. `make` runs
/// on a worker thread, because the fact under test is that it does not return; the command buffers
/// it makes go into a list this thread can drain, which is how a blocked make is released. Nothing
/// is committed.
pub fn probe<C: Send + 'static>(
cap: u32,
make: impl Fn() -> Result<C, crate::case::Failure> + Send + 'static,
other_make: impl Fn() -> bool,
) -> Result<QueueSlots, crate::case::Failure> {
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{mpsc, Arc, Mutex};
let held: Arc<Mutex<Vec<C>>> = Arc::new(Mutex::new(Vec::new()));
let stop = Arc::new(AtomicBool::new(false));
let (made, answers) = mpsc::channel();
let worker = {
let (held, stop) = (Arc::clone(&held), Arc::clone(&stop));
std::thread::spawn(move || {
for _ in 0..cap {
if stop.load(Ordering::SeqCst) {
break;
}
match make() {
Ok(command_buffer) => {
if let Ok(mut held) = held.lock() {
held.push(command_buffer);
}
if made.send(Ok(())).is_err() {
break;
}
}
Err(failure) => {
let _ = made.send(Err(failure));
break;
}
}
}
})
};
let mut slots = QueueSlots {
answered_at_once: 0,
next_blocked: false,
answered_once_a_slot_came_back: false,
other_queue_answered: false,
};
let mut refused = None;
for _ in 0..cap {
match answers.recv_timeout(BLOCKED) {
Ok(Ok(())) => slots.answered_at_once += 1,
Ok(Err(failure)) => {
refused = Some(failure);
break;
}
Err(mpsc::RecvTimeoutError::Timeout) => {
slots.next_blocked = true;
// One queue's limit is one queue's: another queue's make answers meanwhile.
slots.other_queue_answered = other_make();
// Release one slot by dropping a command buffer held uncommitted, which is what
// lets the blocked make answer.
let one = held.lock().ok().and_then(|mut held| held.pop());
drop(one);
slots.answered_once_a_slot_came_back =
matches!(answers.recv_timeout(RELEASED), Ok(Ok(())));
break;
}
Err(mpsc::RecvTimeoutError::Disconnected) => break,
}
}
stop.store(true, Ordering::SeqCst);
// Every slot is released, so a make still in flight answers and the worker then sees the stop.
if let Ok(mut held) = held.lock() {
held.clear();
}
if slots.next_blocked && !slots.answered_once_a_slot_came_back {
// A make the probe released and that still did not answer is a divergence, and the row
// says so. The worker is left to finish on its own rather than joined, so no case of the
// suite can hang waiting for it.
} else {
let _ = worker.join();
}
match refused {
Some(failure) => Err(failure),
None => Ok(slots),
}
}
@@ -13,6 +13,8 @@ use crate::case::{
ShaderSource, Side, StageInRegion, StageInput, TextureRole, TextureSpec, TileFacts,
TilePipelineSpec, TileStep, Venue,
};
use crate::queue_slots::QueueSlots;
use crate::texture_query::{HeapTextureQuery, SizeAndAlign, Storage};
use crate::transcript::{Negative, Value};
use metal2vulkan::bind::{RateMapDescriptor, RateMapLayerDescriptor, SamplerDescriptor};
use metal2vulkan::metal::{
@@ -1231,6 +1233,68 @@ impl Side for RuntimeSide<'_> {
.map(|error| Value::unit_variant(format!("{error:?}"))),
})
}
fn heap_texture_size_and_align(&mut self, query: &HeapTextureQuery) -> Answer<SizeAndAlign> {
let answered = self
.device
.heap_texture_size_and_align(&queried_descriptor(query))
.map_err(Failure::from_error)?;
Ok(SizeAndAlign {
size: answered.size,
align: answered.align,
})
}
fn queue_slots(&mut self, max: Option<u32>, cap: u32) -> Answer<QueueSlots> {
let queue = match max {
None => self.device.new_command_queue(),
Some(max) => self
.device
.new_command_queue_with_max_command_buffer_count(max as usize),
}
.map_err(Failure::from_error)?;
let other = self
.device
.new_command_queue()
.map_err(Failure::from_error)?;
let making = queue.clone();
crate::queue_slots::probe(
cap,
move || making.command_buffer().map_err(Failure::from_error),
|| other.command_buffer().is_ok(),
)
}
fn makes_texture(&mut self, query: &HeapTextureQuery) -> Answer<bool> {
match self.device.new_texture(&queried_descriptor(query)) {
Ok(_) => Ok(true),
// Metal answers nil for a descriptor it describes no texture of, and the runtime
// answers the typed `Nil` for the same descriptor: the same fact, so both sides answer
// `false`. Anything else is our own refusal and is recorded as one.
Err(metal2vulkan_runtime::Error::Nil(_)) => Ok(false),
Err(error) => Err(Failure::of(&error)),
}
}
}
/// The runtime's descriptor for a queried one: the case's vocabulary is Metal's own, so every
/// field reaches the descriptor unchanged.
fn queried_descriptor(query: &HeapTextureQuery) -> TextureDescriptor {
let mut descriptor = TextureDescriptor::default();
descriptor.texture_type = query.texture_type;
descriptor.pixel_format = query.format;
descriptor.width = u64::from(query.size[0]);
descriptor.height = u64::from(query.size[1]);
descriptor.depth = u64::from(query.size[2]);
descriptor.mipmap_level_count = u64::from(query.levels);
descriptor.sample_count = u64::from(query.samples);
descriptor.array_length = u64::from(query.array_length);
descriptor.usage = query.usage;
descriptor.resource_options = match query.storage {
Storage::Shared => ResourceOptions::shared(),
Storage::Private => ResourceOptions::private(),
};
descriptor
}
/// The pixel format [`crate::case::TARGET_FORMAT`] names, as the runtime spells it.
@@ -0,0 +1,176 @@
//! A texture descriptor as both sides take it, for the calls that only *ask* about one.
//!
//! `MTLDevice`'s `heapTextureSizeAndAlignWithDescriptor:` is a pure getter: it compiles nothing,
//! allocates nothing and reaches no GPU, and its answer is Metal's own layout arithmetic. That is
//! exactly the shape a conformance case wants — the whole descriptor space is reachable from the
//! CPU, every answer is two numbers, and the whole family can be re-measured on the oracle as often
//! as anybody asks.
//!
//! It is also the family whose numbers were, until now, held by a comment: `runtime_lane`'s
//! `heap_metal_sizes` carries tables of what an Apple M4 answered, with nothing mechanical tying
//! them to a Metal run. A case over this type takes the answer from Metal.
//!
//! The vocabulary is Metal's own enumerations as the translator's public API names them, so a value
//! a case writes reaches `MTLTextureType`, `MTLPixelFormat` and `MTLTextureUsage` by its raw
//! ordinal and reaches the runtime's descriptor unchanged. A case may therefore name one of Apple's
//! private formats (`Unspecialized`, the 4:2:2 pair, the two-plane extended-range pair) and one of
//! Apple's private usage bits as readily as a public one.
use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage};
/// The storage a queried descriptor asks for. Two of Metal's four modes, because they are the two
/// every case of this family sweeps and the two every device has.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Storage {
/// `MTLStorageModeShared`.
Shared,
/// `MTLStorageModePrivate`.
Private,
}
impl Storage {
/// The word the site's name carries.
pub fn word(self) -> &'static str {
match self {
Storage::Shared => "shared",
Storage::Private => "private",
}
}
}
/// A descriptor a case asks Metal about: every `MTLTextureDescriptor` field the heap size query
/// reads.
///
/// `allowGPUOptimizedContents` is deliberately **not** a field. It is left at Metal's default, on,
/// in every case of the family: with it off the runtime announces `optimized-depth-stencil-texture`
/// on MoltenVK for a depth or stencil texture, and a case whose subject is Metal's arithmetic
/// should not be carrying a device's announcement as well. A case that wants the property off is a
/// case of its own, and will say so by growing this type.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HeapTextureQuery {
pub texture_type: TextureType,
pub format: PixelFormat,
/// `width`, `height` and `depth`, in texels.
pub size: [u32; 3],
/// `mipmapLevelCount`.
pub levels: u32,
/// `sampleCount`.
pub samples: u32,
/// `arrayLength`.
pub array_length: u32,
pub usage: TextureUsage,
pub storage: Storage,
}
impl HeapTextureQuery {
/// A 2D descriptor of `format`, `width` by `height`, one level, one sample, one slice, read by
/// shaders, of `storage`.
pub const fn texture_2d(format: PixelFormat, size: [u32; 2], storage: Storage) -> Self {
Self {
texture_type: TextureType::Type2D,
format,
size: [size[0], size[1], 1],
levels: 1,
samples: 1,
array_length: 1,
usage: TextureUsage::SHADER_READ,
storage,
}
}
/// The descriptor with `texture_type`, and the `height`, `depth` and `arrayLength` that type
/// takes: a 1D or buffer texture one row tall, an array type `slices` slices, a 3D texture
/// `depth` texels deep.
#[must_use]
pub const fn of_type(mut self, texture_type: TextureType, depth: u32, slices: u32) -> Self {
self.texture_type = texture_type;
match texture_type {
TextureType::Type1D | TextureType::Type1DArray | TextureType::TextureBuffer => {
self.size[1] = 1;
}
TextureType::Type3D => self.size[2] = depth,
_ => {}
}
self.array_length = slices;
self
}
/// The descriptor with `levels` mipmap levels.
#[must_use]
pub const fn with_levels(mut self, levels: u32) -> Self {
self.levels = levels;
self
}
/// The descriptor with `usage`.
#[must_use]
pub const fn with_usage(mut self, usage: TextureUsage) -> Self {
self.usage = usage;
self
}
/// The descriptor with `samples` samples.
#[must_use]
pub const fn with_samples(mut self, samples: u32) -> Self {
self.samples = samples;
self
}
/// The site name the query's answer sits at: every field that can change the answer, so two
/// descriptors of one family never share a site and a reader of a diff knows which descriptor
/// moved without counting rows.
pub fn site(&self) -> String {
format!(
"{}/{:?}/{}x{}x{}/levels-{}/samples-{}/slices-{}/usage-{:#x}/{}",
self.format.name(),
self.texture_type,
self.size[0],
self.size[1],
self.size[2],
self.levels,
self.samples,
self.array_length,
self.usage.as_raw(),
self.storage.word(),
)
}
/// The words the descriptor fingerprints as, for a case's input fingerprint: every field, so a
/// descriptor that moves is a change to the case's inputs rather than a silent re-point of the
/// recording.
pub fn words(&self) -> Vec<u8> {
let mut out = Vec::new();
out.extend(self.texture_type.as_raw().to_le_bytes());
out.extend(self.format.as_raw().to_le_bytes());
for axis in self.size {
out.extend(axis.to_le_bytes());
}
out.extend(self.levels.to_le_bytes());
out.extend(self.samples.to_le_bytes());
out.extend(self.array_length.to_le_bytes());
out.extend(self.usage.as_raw().to_le_bytes());
out.extend(match self.storage {
Storage::Shared => [0u8],
Storage::Private => [1u8],
});
out
}
}
/// `MTLSizeAndAlign`: what the heap size query answers.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SizeAndAlign {
pub size: u64,
pub align: u64,
}
impl SizeAndAlign {
/// The answer as the fields a site records: both numbers, so a diff names which of the two
/// moved.
pub fn value(&self) -> crate::transcript::Value {
crate::transcript::Value::fields([
("size", crate::transcript::Value::Uint(self.size)),
("align", crate::transcript::Value::Uint(self.align)),
])
}
}
@@ -432,4 +432,26 @@ impl<S: Side> Side for Announcing<S> {
self.at("tile_pass");
self.inner.tile_pass(targets, tile, steps)
}
fn heap_texture_size_and_align(
&mut self,
query: &crate::texture_query::HeapTextureQuery,
) -> Answer<crate::texture_query::SizeAndAlign> {
self.at("heap_texture_size_and_align");
self.inner.heap_texture_size_and_align(query)
}
fn makes_texture(&mut self, query: &crate::texture_query::HeapTextureQuery) -> Answer<bool> {
self.at("makes_texture");
self.inner.makes_texture(query)
}
fn queue_slots(
&mut self,
max: Option<u32>,
cap: u32,
) -> Answer<crate::queue_slots::QueueSlots> {
self.at("queue_slots");
self.inner.queue_slots(max, cap)
}
}