diff --git a/crates/reims-vgpu/src/graphics/device_info.rs b/crates/reims-vgpu/src/graphics/device_info.rs index e1aea336b..f6e4b1076 100644 --- a/crates/reims-vgpu/src/graphics/device_info.rs +++ b/crates/reims-vgpu/src/graphics/device_info.rs @@ -20,7 +20,7 @@ use reims_vgpu_graphics::wire::{ }; use reims_vgpu_vulkan::core::platform::caps::{ COUNTER_SAMPLING_POINTS, DeviceCaps, FAMILIES, FEATURE_SETS, Flags, FormatAnswers, - IdentityCaps, Limits, SDK_FAMILIES, SDK_PIXEL_FORMATS, SPARSE_PAGE_SIZES, SPARSE_SAMPLE_COUNTS, + IdentityCaps, SDK_FAMILIES, SDK_PIXEL_FORMATS, SPARSE_PAGE_SIZES, SPARSE_SAMPLE_COUNTS, feature_set_family, }; use reims_vgpu_vulkan::core::raise::RaiseResult; @@ -302,7 +302,6 @@ fn cap_apple_families(identity: &mut IdentityCaps, wired: &[Piece]) { /// | `maximumConcurrentCompilationTaskCount` | the device's compile threads, which run its pipeline compiles | nothing: the device's own answer | /// | `recommendedMaxWorkingSetSize` | on a GPU that shares the CPU's memory, three quarters of the guest's RAM rounded down to 16 KiB, or the platform's where that is less or the host maps no RAM; on a GPU of its own memory the platform's ([`lane_working_set`]) | nothing: a choice | /// | `maxBufferLength` | the platform's, but at most three quarters of `recommendedMaxWorkingSetSize`, rounded down to 16 KiB ([`lane_max_buffer_length`]) | nothing: a choice | -/// | `minimumLinearTextureAlignmentForPixelFormat:` and the SPI `linearTextureAlignmentBytes` and `deviceLinearTextureAlignmentBytes` | 256 bytes, or the platform's where larger ([`LANE_LINEAR_TEXTURE_ALIGNMENT`]) | nothing: a choice | /// | `isFramebufferReadSupported` (SPI) | no for an x86-64 guest; the platform's for an arm64 guest ([`lane_flags`]) | nothing: a choice | /// | `supportsTileShaders`, `supportsNonSquareTileShaders`, `supportsImageBlocks` (SPI) | no ([`lane_flags`]) | tile pipelines, their non-square dispatch and imageblocks, Apple4's and Apple5's pieces | /// @@ -311,6 +310,40 @@ fn cap_apple_families(identity: &mut IdentityCaps, wired: &[Piece]) { /// /// `hasUnifiedMemory` is the platform's: the decoder keeps `Managed` resources in one copy or two /// by the same answer (docs/graphics-kext/design.md, Decided 4). +/// +/// `minimumLinearTextureAlignmentForPixelFormat:` and the SPI `linearTextureAlignmentBytes` and +/// `deviceLinearTextureAlignmentBytes` are the platform's too, as each Mac answers its own GPU's +/// (256 bytes on an AMD Radeon Pro 5300M and an Intel UHD 630, 16 on an Apple M3 Max, macOS +/// 26.7.1): the alignment of a texture's offset and rows in a buffer at which the host GPU's +/// linear images hold it in place, the largest of the formats a buffer backs +/// (`Device::minimum_linear_texture_alignment_for_pixel_format` of the runtime, which asks the +/// driver whether its images take a texture's reads, renders and shader writes in place, and +/// answers at least the device's `nonCoherentAtomSize`: 256 on RADV and 128 on NVIDIA's driver, +/// read from its records on the hosts, 2026-11-12; 64 on ANV, whose stores write back a row's +/// last 64-byte line whole, and on lavapipe; 16 on MoltenVK). The guest's frameworks lay the +/// rows of a texture over a buffer out at a multiple of it, and its device answers nil to one off +/// it, as the 5300M's does (`RgfxBuffer.mm`): over a cold boot and a 15 s Safari scroll of a +/// macOS 11.7.11 guest on a Radeon 780M, 1399 textures were shadows for their pitch with the +/// device answering 16 (A8 rows of 64 and 128 bytes, a BGRA8 surface 463 pixels wide at 1856), +/// and 11 with it answering 512. A layout at the GPU's own pitch is one the runtime takes in +/// place: on NVIDIA's driver only that pitch is (the tight row rounded up to 128), so rows at +/// another multiple of 128, such as the tight row rounded up to 256, are the runtime's shadow. +/// +/// An IOSurface's rows follow two other answers. A surface made with no pitch named +/// (`IOSurfaceCreate`, and CoreVideo's buffers and pools) takes rows at IOSurface's own +/// alignment, `IOSurfaceGetPropertyAlignment(kIOSurfaceBytesPerRow)`: 64 bytes on the 5300M's Mac +/// (macOS 26.7.1), and here the device info's `linear_row_alignment` where the guest's kext raises +/// it to that. CoreAnimation names the rows of its backing stores' surfaces itself, rounded to the +/// device's `iosurfaceTextureAlignmentBytes` and to no less than 64 bytes, and IOSurface keeps +/// them. The guest's device answers Metal's 16 for `iosurfaceTextureAlignmentBytes` and +/// `iosurfaceReadOnlyTextureAlignmentBytes` (the 5300M, the 630 and the M3 Max answer the first +/// 16), not the platform's answers this info carries: CoreAnimation makes no texture of a surface +/// whose rows are not at a multiple of the answer, and other code's surfaces keep IOSurface's own +/// rows (the bundle's `kRgfxIOSurfaceTextureAlignmentBytes`; macOS 26.7.2 guests answering an +/// RTX 3090's and an RTX 2080's 128 drew Safari's pages blank). So a texture over a backing store +/// at a pitch that is not the GPU's is the runtime's shadow. metal2vulkan measured a macOS 26.7.2 +/// guest's surfaces on RADV at 4032 bytes for 1001 `BGRA` pixels, 7360 for 1831 and 14656 for +/// 3662, IOSurface's 64-byte rows, before the kext raised them. fn lane(mut identity: IdentityCaps, compile_threads: u64, guest_ram: Option) -> IdentityCaps { cap_apple_families(&mut identity, WIRED); identity.families[at(MTL_GPU_FAMILY_METAL4)] = Some(false); @@ -389,49 +422,6 @@ fn lane_max_buffer_length(platform: Option, working_set: Option) -> Op } } -/// `minimumLinearTextureAlignmentForPixelFormat:` of every format a buffer can back, and the SPI -/// `linearTextureAlignmentBytes` and `deviceLinearTextureAlignmentBytes`: 256 bytes, as an AMD -/// Radeon Pro 5300M and an Intel UHD 630 answer (macOS 26.7.1; an Apple M3 Max answers 16), or -/// the platform's where it needs more. A guest lays a texture's rows out in its buffer at a -/// multiple of this alignment. The Vulkan platform on RADV takes a texture over a buffer's -/// dma-buf pages in place only with its rows a multiple of 256 bytes apart (metal2vulkan's -/// `dma_buf.rs`, measured on Mesa 26.0.8 and 26.2.4), and shadows one at any other pitch; how many -/// of a guest's textures this moves in place is unmeasured. Any 256-byte layout is one the -/// platform's 16 takes too. An IOSurface's rows follow two other answers. A surface made with no -/// pitch named (`IOSurfaceCreate`, and CoreVideo's buffers and pools) takes rows at IOSurface's own -/// alignment, `IOSurfaceGetPropertyAlignment(kIOSurfaceBytesPerRow)`: 64 bytes on the 5300M's Mac -/// (macOS 26.7.1), and here the device info's `linear_row_alignment` where the guest's kext raises -/// it to that (256 bytes in macOS 11.7.11 and 14.8.9 guests on a Radeon 780M). CoreAnimation names -/// the rows of its backing stores' surfaces itself, rounded to the device's -/// `iosurfaceTextureAlignmentBytes` and to no less than 64 bytes, and IOSurface keeps them. The -/// guest's device answers Metal's 16 for `iosurfaceTextureAlignmentBytes` and -/// `iosurfaceReadOnlyTextureAlignmentBytes` (the 5300M, the 630 and the M3 Max answer the first -/// 16), not the platform's answers this info carries: CoreAnimation makes no texture of a surface whose rows -/// are not at a multiple of the answer, and other code's surfaces keep IOSurface's own 64-byte -/// rows (the bundle's `kRgfxIOSurfaceTextureAlignmentBytes`; macOS 26.7.2 guests answering an -/// RTX 3090's and an RTX 2080's 128 drew Safari's pages blank). So on RADV a texture over a -/// backing store at a pitch that is not a multiple of 256 is the runtime's shadow (its refused -/// pitch): over a cold boot and a 15 s Safari scroll of a macOS 11.7.11 guest on a Radeon 780M, -/// 1399 textures were shadows for their pitch answering 16 (A8 rows of 64 and 128 bytes, a BGRA8 -/// surface 463 pixels wide at 1856), and 11 with the guest's device answering 512 there instead. -/// metal2vulkan measured a macOS 26.7.2 guest's surfaces on RADV at 4032 bytes for 1001 `BGRA` -/// pixels, 7360 for 1831 and 14656 for 3662, and in two cold boots of that guest on a Radeon 780M -/// 583 and 639 textures over the guest's pages were shadows for their pitch, against 532 and 503 -/// in place. -pub const LANE_LINEAR_TEXTURE_ALIGNMENT: u64 = 256; - -/// The device's `NSUInteger` SPI answers where the lane's differ from the platform's: the linear -/// texture alignments, at least [`LANE_LINEAR_TEXTURE_ALIGNMENT`]. -fn lane_limits(mut limits: Limits) -> Limits { - for align in [ - &mut limits.linear_texture_alignment_bytes, - &mut limits.device_linear_texture_alignment_bytes, - ] { - *align = (*align).max(LANE_LINEAR_TEXTURE_ALIGNMENT); - } - limits -} - /// The device's `BOOL` SPI answers where the lane's differ from the platform's, for a guest of /// `guest`'s architecture: /// - `isFramebufferReadSupported`, for an x86-64 guest no, as an AMD Radeon Pro 5300M answers, @@ -496,7 +486,7 @@ pub fn device_info( let t = caps.max_threads_per_threadgroup; info.max_threads_per_threadgroup = [t.width, t.height, t.depth]; - let l = &lane_limits(caps.limits); + let l = &caps.limits; // In the host `Limits` field order; the bundle reads them in this order. info.limits = [ l.device_linear_texture_alignment_bytes, @@ -938,11 +928,11 @@ mod tests { /// `maxBufferLength` is three quarters of the working set rounded down to 16 KiB where that is /// below the platform's answer, as the 5300M's and the M3 Max's answers are of theirs, and the - /// platform's otherwise; the linear texture alignments are 256 bytes, or the platform's where - /// larger; for an x86-64 guest the framebuffer read, tile shader and imageblock answers are + /// platform's otherwise; the linear texture alignments are the platform's, below 256 bytes as + /// past it; for an x86-64 guest the framebuffer read, tile shader and imageblock answers are /// no, whatever the platform's, and the other SPI flags the platform's. #[test] - fn the_lanes_buffer_length_alignments_and_spi_flags() { + fn the_lanes_buffer_length_and_spi_flags_and_the_platforms_linear_alignments() { // An RTX 5080 on the Vulkan platform: a terabyte against 17094934528 bytes of VRAM. assert_eq!( lane_max_buffer_length(Some(1 << 40), Some(17_094_934_528)), @@ -973,9 +963,10 @@ mod tests { // The fake answers 16 for both alignments, and yes for every SPI flag. let info = device_info(&caps, identity.clone(), 4, GuestArch::X86_64, None); assert_eq!(info.sizes[7], 12_821_200_896); - // device_linear_texture_alignment_bytes first, linear_texture_alignment_bytes fourth. - assert_eq!(info.limits[0], 256); - assert_eq!(info.limits[3], 256); + // device_linear_texture_alignment_bytes first, linear_texture_alignment_bytes fourth: the + // fake's 16, as an M3 Max answers. + assert_eq!(info.limits[0], 16); + assert_eq!(info.limits[3], 16); // is_framebuffer_read_supported (2), supports_image_blocks (14), // supports_non_square_tile_shaders (17) and supports_tile_shaders (24) no; the others // the platform's, all yes on the fake but is_depth24_stencil8_pixel_format_supported (1). @@ -983,7 +974,13 @@ mod tests { let want = !matches!(k, 1 | 2 | 14 | 17 | 24); assert_eq!(flag, u8::from(want), "flag {k}"); } - // A platform that needs more than 256 bytes keeps its own. + // NVIDIA's driver's 128 stays 128, not the 5300M's 256; a platform that needs more than + // 256 bytes keeps its own as well. + caps.limits.linear_texture_alignment_bytes = 128; + caps.limits.device_linear_texture_alignment_bytes = 128; + let info = device_info(&caps, identity.clone(), 4, GuestArch::X86_64, None); + assert_eq!(info.limits[0], 128); + assert_eq!(info.limits[3], 128); caps.limits.linear_texture_alignment_bytes = 512; caps.limits.device_linear_texture_alignment_bytes = 1024; let info = device_info(&caps, identity, 4, GuestArch::X86_64, None); diff --git a/docs/accuracy-ledger.md b/docs/accuracy-ledger.md index e2cd489a1..38c6cff0c 100644 --- a/docs/accuracy-ledger.md +++ b/docs/accuracy-ledger.md @@ -53,7 +53,7 @@ samplers, the default filter, `YCBCR10_420_2P` under every mode). | Fast default | Accurate switch | Bound of the fast form | Cost of the accurate form (5080) | |---|---|---|---| | Batches of one queue ordered by their ends on a driver measured to start no kernel submission of a queue before the one before it completed (ANV, RADV, NVIDIA): each ends with a barrier before every later command of its queue, so a dependent batch begins with no barrier of its own | `batch_order` (a barrier for each access a batch's work depends on in an earlier batch's) | none: on those drivers each batch starts once the one before it completed under either form, so order, results and GPU times are the same. Not announced | UHD 770 (ANV), 67 command buffers a frame over 520 host imports: 67 command buffers submitted a frame against 129, a frame through completion 2.13-2.22 ms against 2.27-2.38 ms | -| A texture over the guest's pages that samples, reads, renders into them or is written through a shader (`ShaderWrite` or `ShaderAtomic`, of texels of 4, 8 or 16 bytes) held as a linear image over the pages, on a device whose own check, run once per driver and release, finds that the operations Vulkan lets read and write every byte bound to the image (its first move; a render pass's load and store; a kernel's storage writes) leave every byte alone while the CPU writes beside it, each access checked apart, and apart for texels that share a line of the device's memory (`nonCoherentAtomSize`) with bytes beside them and for texels that share none: the Iris Xe (ANV, Mesa 26.2.6), whose clear, store and draws write back whole the 64-byte line that holds a row's last texels, keeps the shadow for a texture it renders or writes whose rows end inside a line, and takes in place one whose rows start and end on lines, a 3840x2160 `BGRA8Unorm` surface's among them (the owner's rulings, 2026-10-26, 2026-10-27 and 2026-11-07: in place, trusting the driver) | `host_page_textures` (a shadow: the texels copied in at each command buffer's first use and merged back after each write, on every device) | none on a device whose check passes: Vulkan lets an imported image's first layout transition read and write every byte bound to it (`VUID-VkImageCreateInfo-pNext-01443`), which would undo a CPU write made beside it; the check shows the driver does not, and a texture made before its verdict is a shadow. A texture whose pitch the driver refuses for a linear image is a shadow under either form: on RADV, rows not a multiple of 256 bytes, which a guest's IOSurfaces have, their rows at IOSurface's own 64-byte alignment, as on an AMD Radeon Pro 5300M Mac, with no device answer that moves them (`LANE_LINEAR_TEXTURE_ALIGNMENT`, `crates/reims-vgpu/src/graphics/device_info.rs`) | the copy-in at each command buffer's first use: Safari on testufo.com at 1680x1050 and 120 Hz read about 45 MB a frame from host memory over PCIe on the RTX 5080, against a 7 MB framebuffer (SM 24-34%, metal2vulkan f6a96b7da8) | +| A texture over the guest's pages that samples, reads, renders into them or is written through a shader (`ShaderWrite` or `ShaderAtomic`, of texels of 4, 8 or 16 bytes) held as a linear image over the pages, on a device whose own check, run once per driver and release, finds that the operations Vulkan lets read and write every byte bound to the image (its first move; a render pass's load and store; a kernel's storage writes) leave every byte alone while the CPU writes beside it, each access checked apart, and apart for texels that share a line of the device's memory (`nonCoherentAtomSize`) with bytes beside them and for texels that share none: the Iris Xe (ANV, Mesa 26.2.6), whose clear, store and draws write back whole the 64-byte line that holds a row's last texels, keeps the shadow for a texture it renders or writes whose rows end inside a line, and takes in place one whose rows start and end on lines, a 3840x2160 `BGRA8Unorm` surface's among them (the owner's rulings, 2026-10-26, 2026-10-27 and 2026-11-07: in place, trusting the driver) | `host_page_textures` (a shadow: the texels copied in at each command buffer's first use and merged back after each write, on every device) | none on a device whose check passes: Vulkan lets an imported image's first layout transition read and write every byte bound to it (`VUID-VkImageCreateInfo-pNext-01443`), which would undo a CPU write made beside it; the check shows the driver does not, and a texture made before its verdict is a shadow. A texture whose pitch the driver refuses for a linear image is a shadow under either form: on RADV, rows not a multiple of 256 bytes, and on NVIDIA's driver rows other than the tight row rounded up to 128; a guest's IOSurfaces lay their rows out at the device info's `linear_row_alignment`, to which the guest's kext raises IOSurface's own 64-byte alignment (an AMD Radeon Pro 5300M Mac's), and its frameworks lay out textures over buffers at the platform's linear texture alignment, but a client that names its rows keeps them (`crates/reims-vgpu/src/graphics/device_info.rs`) | the copy-in at each command buffer's first use: Safari on testufo.com at 1680x1050 and 120 Hz read about 45 MB a frame from host memory over PCIe on the RTX 5080, against a 7 MB framebuffer (SM 24-34%, metal2vulkan f6a96b7da8) | | A chain of `half` additions, subtractions and products under fast math, on a device without `shaderFloat16`, held at `float` precision and rounded where a value leaves it (`FastMathRewrites`) | `half_chains` (each operation rounded where it is computed, by the device's `OpQuantizeToF16`) | the roundings the chain skips, and a value past `half`'s range inside the chain stays finite | not measured | | A draw's or dispatch's pipeline still being made 4.5 s after its command buffer's commit: the command runs nothing in that command buffer, and later ones run it once made; a state's creation returns after 4.5 s with its predicted pipeline still being made | `pipeline_waits` (each creation makes its predicted pipeline before it returns, and a command buffer waits for each pipeline until it is made; a strict process takes it whatever the switch says) | a draw or dispatch dropped from the command buffers committed before its compile lands, announced (`draw-dropped-still-making`, `dispatch-dropped-still-making`): the slowest render state's compile on an M2 Pro's cold boot under MoltenVK took 11.59 s (metal2vulkan's FAST-PATHS) | no GPU cost; the creating thread and the command buffer held for the whole compile, up to 11.59 s on that M2 Pro boot | | A line `setLineWidth:` widens (a width other than 1, `floor(16 w) / 16` as Metal draws it), a triangle's edges in fill mode `Lines` and a mesh draw's lines drawn by the device's own lines at the width, wherever the device draws it (`wideLines`, the width in its `lineWidthRange`), where they differ from Metal's parallelogram: a strict device's rectangle (NVIDIA, lavapipe), lines Vulkan does not state as parallelograms (ANV, and every width below 1), a width off the device's `lineWidthGranularity`. Announced (`device-wide-lines`). MoltenVK has no wide lines: on the Mac the band below draws lines at every such width under either form. Where neither the device's lines nor the band draws the width (a mesh draw's lines on MoltenVK, a line or a triangle's edges without `tessellationShader` or in a pipeline whose band the translator refuses, an execution's lines, lines in a rate-mapped pass), the device's lines draw at the nearest width they draw, 1 pixel without wide lines, announced (`lines-at-nearest-width`) | `wide_lines` (each such line two triangles over Metal's parallelogram, the pipeline's band variant, on a device with `tessellationShader`; a triangle's edges too, each edge the line's parallelogram, except that a depth bias applies by each band triangle's own slope where Metal's applies by the triangle's, announced (`wide-edge-depth-bias`); a mesh draw's lines stay the device's; and on a driver not measured to snap a vertex half a 1/256-pixel step off its grid up, as Metal snaps a line's endpoint (every driver but MoltenVK on the M3 Max), the band's corners snapped by the device's rasterizer, so a line whose endpoint lies half a step off the grid can draw a row or a column from Metal's (NVIDIA and lavapipe round the half step down), announced (`device-subpixel-snap`)) | up to half the width past each end (square ends), and the width rounded to the granularity | not measured: a second pipeline variant made for each render state that draws such lines, and each line tessellated into four corners | diff --git a/docs/graphics-kext/dgpu-oracle.md b/docs/graphics-kext/dgpu-oracle.md index 132a6623b..e5d99b753 100644 --- a/docs/graphics-kext/dgpu-oracle.md +++ b/docs/graphics-kext/dgpu-oracle.md @@ -447,7 +447,7 @@ Probe: `oracle_caps DEVICE`. Where the x86 GPUs' answers differ from the M3's or | `maxThreadgroupMemoryLength` | 65536 | 65536 | 32768 | 32768 | | `maxArgumentBufferSamplerCount` | 2048 | 2048 | 500000 | 0 | | `readWriteTextureSupport` | 2 | 1 | 2 | 2 | -| `minimumLinearTextureAlignmentForPixelFormat:`, `linearTextureAlignmentBytes` | 256 | 256 | 16 | 256 (4a329e614) | +| `minimumLinearTextureAlignmentForPixelFormat:`, `linearTextureAlignmentBytes` | 256 | 256 | 16 | 128, the platform's on the 5080's driver (256 from 4a329e614 to 2026-11-12) | | `iosurfaceTextureAlignmentBytes` | 16 | 16 | 16 | | | `isDepth24Stencil8PixelFormatSupported` | 1 | 0 | 0 | 0 | | `supports32BitMSAA`, `supportsPullModelInterpolation` | 1, 1 | 1, 1 | 1, 1 | the runtime's: 1, 1 on the 5080 (metal2vulkan 7da81ee3d8; 0, 0 before) | @@ -474,11 +474,15 @@ process at every other (compressed, depth and stencil, else MTLPixelFormatInvali are depth on AMD, Invalid on Intel); ours does the same, D24S8 as Intel. Our device makes ASTC and the packed formats (m2v), which no x86 Mac does; with no Apple family claimed, frameworks should not ask for them. -**Relaxation: none** for performance. Two answers help the host, and the lane gives both, as -choices inside the envelope *(class 2)*: `minimumLinearTextureAlignmentForPixelFormat:` and the -SPI linear alignments 256 for every format they answer, as both x86 GPUs answer, which suits the Vulkan -hosts' linear images (4ee4bcaf0, 4a329e614); and `maxBufferLength` at most three quarters of +**Relaxation: none** for performance. One answer helps the host, and the lane gives it, as a +choice inside the envelope *(class 2)*: `maxBufferLength` at most three quarters of `recommendedMaxWorkingSetSize`, the rule the 5300M and the M3 answer by (4ee4bcaf0). +`minimumLinearTextureAlignmentForPixelFormat:` and the SPI linear alignments describe the GPU, +each Mac answering its own, so the device answers the host GPU's: the platform's, 256 on RADV +and 128 on NVIDIA's driver (`device_info.rs`). The lane answered 256 for every format from +4ee4bcaf0 and 4a329e614, as both x86 GPUs answer, while the platform answered Metal's 16 on +every host; on NVIDIA's driver, which takes a linear image in place only at its own pitch, rows +at 256 bytes were shadows wherever that pitch is not one. ## Q10: runtime source compile