diff --git a/crates/reims-vgpu/src/graphics/device_info.rs b/crates/reims-vgpu/src/graphics/device_info.rs index d615f4bfe..b094ce0b4 100644 --- a/crates/reims-vgpu/src/graphics/device_info.rs +++ b/crates/reims-vgpu/src/graphics/device_info.rs @@ -359,16 +359,24 @@ fn lane_max_buffer_length(platform: Option, working_set: Option) -> Op /// 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 none of the device's 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), whose device answers this 256 and -/// `iosurfaceTextureAlignmentBytes` 16: 4032 bytes for 1001 `BGRA` pixels, 7360 for 1831 and 14656 -/// for 3662, the pitches metal2vulkan measured a macOS 26.7.2 guest's surfaces at on RADV. So on -/// RADV a texture over such a surface at a pitch that is not a multiple of 256 is the runtime's -/// shadow (its refused pitch), which no answer here moves in place: 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. +/// 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 +/// device answers the platform's `iosurfaceTextureAlignmentBytes` and +/// `iosurfaceReadOnlyTextureAlignmentBytes` unchanged (the 5300M, the 630 and the M3 Max answer +/// 16). So on RADV a texture over such a surface at a pitch that is not a multiple of 256 is the +/// runtime's shadow (its refused pitch) where the platform answers less than 256 there: 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 platform's 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 diff --git a/guest/bundle/src/RgfxMetalDevice.mm b/guest/bundle/src/RgfxMetalDevice.mm index 39d143821..1694fd65e 100644 --- a/guest/bundle/src/RgfxMetalDevice.mm +++ b/guest/bundle/src/RgfxMetalDevice.mm @@ -1269,6 +1269,25 @@ RGFX_LOG_UNRECOGNIZED return _caps.limit(kRgfxLimitDeviceLinearTextureAlignmentBytes); } +// The host's answers, the runtime's: the alignment its device takes a texture over an IOSurface's +// rows at. The AMD 5300M, the Intel 630 and the M3 Max answer 16. CoreAnimation rounds the rows of +// the IOSurfaces it makes for its backing stores to iosurfaceTextureAlignmentBytes, to no less +// than 64 bytes, and names those rows to IOSurface, which keeps them: so this answer, not +// IOSurface's own alignment, decides whether the host's GPU can take such a surface's texture in +// place. Measured in a macOS 11.7.11 guest on a Radeon 780M: answering 16, A8 backing stores 125 +// pixels wide had rows of 128 bytes and 45 wide rows of 64; answering 512, a 1200-pixel BGRA8 +// surface's rows went from 4800 bytes to 5120, and of 1399 textures the runtime shadowed for their +// rows over a 15 s scroll in Safari 11 were left. Left to the IOGPU base, these answered 16 there. +- (NSUInteger)iosurfaceTextureAlignmentBytes +{ + return _caps.limit(kRgfxLimitIOSurfaceTextureAlignmentBytes); +} + +- (NSUInteger)iosurfaceReadOnlyTextureAlignmentBytes +{ + return _caps.limit(kRgfxLimitIOSurfaceReadOnlyTextureAlignmentBytes); +} + - (MTLSize)sparseTileSizeWithTextureType:(MTLTextureType)textureType pixelFormat:(MTLPixelFormat)pixelFormat sampleCount:(NSUInteger)sampleCount diff --git a/guest/bundle/tests/protocol_members.txt b/guest/bundle/tests/protocol_members.txt index 9386c4d06..4222ce7e4 100644 --- a/guest/bundle/tests/protocol_members.txt +++ b/guest/bundle/tests/protocol_members.txt @@ -462,8 +462,8 @@ heapBufferSizeAndAlignWithLength:options: partial the host's heap buffer alignme heapTextureSizeAndAlignWithDescriptor: implemented indirectArgumentBufferCapabilities base %base-spi indirectArgumentBufferDecodingData base %base-spi -iosurfaceReadOnlyTextureAlignmentBytes base %base-spi -iosurfaceTextureAlignmentBytes base %base-spi +iosurfaceReadOnlyTextureAlignmentBytes implemented +iosurfaceTextureAlignmentBytes implemented isASTCPixelFormatsSupported base %base-spi isAnisoSampleFixSupported base %base-spi isBCTextureCompressionSupported base %base-spi diff --git a/guest/bundle/tests/serializer_tests.cpp b/guest/bundle/tests/serializer_tests.cpp index 2aefb9a94..d997de2ef 100644 --- a/guest/bundle/tests/serializer_tests.cpp +++ b/guest/bundle/tests/serializer_tests.cpp @@ -569,6 +569,8 @@ void test_caps() info.write_rounding_modes[1] = 1; // mode 2 info.limits[kRgfxLimitDeviceLinearTextureAlignmentBytes] = 64; info.limits[kRgfxLimitLinearTextureAlignmentBytes] = 256; + info.limits[kRgfxLimitIOSurfaceReadOnlyTextureAlignmentBytes] = 32; + info.limits[kRgfxLimitIOSurfaceTextureAlignmentBytes] = 128; info.limits[kRgfxLimitMaxViewportCount] = 16; // last by position info.flags[kRgfxFlagAreRasterOrderGroupsSupported] = 1; // first by position info.flags[kRgfxFlagSupportsTileShaders] = 1; // last by position @@ -628,6 +630,10 @@ void test_caps() CHECK(caps.supportsWriteRoundingMode(2)); CHECK(!caps.supportsWriteRoundingMode(1)); CHECK(caps.limit(kRgfxLimitDeviceLinearTextureAlignmentBytes) == 64); + // The IOSurface alignments the device answers, at their places between the linear ones. + CHECK(caps.limit(kRgfxLimitIOSurfaceReadOnlyTextureAlignmentBytes) == 32); + CHECK(caps.limit(kRgfxLimitIOSurfaceTextureAlignmentBytes) == 128); + CHECK(caps.limit(kRgfxLimitLinearTextureAlignmentBytes) == 256); CHECK(caps.limit(kRgfxLimitMaxViewportCount) == 16); CHECK(caps.flag(kRgfxFlagAreRasterOrderGroupsSupported)); CHECK(caps.flag(kRgfxFlagSupportsTileShaders));