What changes for the guest: on a host whose surfaces lie in place in their pages and whose GPU lays a linear image's rows at more than 64 bytes, the default IOSurface bytesPerRow becomes aligned to that GPU's alignment: 256 bytes on RADV hosts. The host says it in a new device-info field, linear_row_alignment (the runtime's minimum_linear_texture_alignment_for_pixel_format of BGRA8, written where the GPU shares the CPU's memory, else 0), and the kext has IOSurface align the bytes per row it works out to it at the accelerator's start (IOSurfaceRoot::updateLimits, as a GPU's accelerator does), which IOSurfaceGetPropertyAlignment then answers to the processes too. ANV and MoltenVK hosts, which answer 64 or less, hosts whose GPU has memory of its own, and older sets keep today's 64. It stays inside what Macs answer: an x86 Mac answers 64 for IOSurfaceGetPropertyAlignment of bytesPerRow and the M3 128, and the x86 GPUs' own minimumLinearTextureAlignment of BGRA8 is 256 (m2v probe jobs 7349 and 7356). What it removes: the runtime's Refusal::Pitch shadows on RADV. On the 780M a 3840x2160 surface at 15360-byte rows in place takes 1.02-1.14 ms a frame against 2.79-3.10 ms shadowed, and the guest's 3662x2039 surface at 14656-byte rows was shadowed (2.5-2.9 ms): the 256-byte pitch saves about 1.7-2.8 ms a frame (m2v job 7389, Mesa 26.2.6). Measured on a cold boot of macOS 26.7.2 on the 780M: IOSurfaceGetPropertyAlignment of bytesPerRow answers 256 (a 3662-pixel surface's rows are 14848 bytes), and the run's refused-pitch shadows went from 1032 to 14. guest/prebuilt and the option ROM's record are rebuilt; the ROM's bytes are unchanged.
55 lines
1.9 KiB
C++
55 lines
1.9 KiB
C++
// The native test of RgfxSurfaceRows.hpp: the alignment the kext has IOSurface give the bytes per
|
|
// row it works out, from the host's answer in the device info.
|
|
#include "RgfxSurfaceRows.hpp"
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
|
|
static_assert(offsetof(RgfxDeviceInfo, linear_row_alignment) == 0x454, "linear_row_alignment");
|
|
|
|
namespace {
|
|
int checks = 0;
|
|
|
|
void check(bool ok, const char *what)
|
|
{
|
|
checks++;
|
|
if (!ok) {
|
|
std::fprintf(stderr, "surface_rows_test: FAILED: %s\n", what);
|
|
std::exit(1);
|
|
}
|
|
}
|
|
|
|
// The alignment as the kext reads it: out of a whole device info's bytes, the host's layout.
|
|
uint32_t fromDeviceInfo(uint32_t host)
|
|
{
|
|
static RgfxDeviceInfo info;
|
|
std::memset(&info, 0xa5, sizeof(info));
|
|
info.linear_row_alignment = host;
|
|
return rgfxSurfaceRowAlignmentFrom(reinterpret_cast<const uint8_t *>(&info) + kRgfxSurfaceRowsFirst);
|
|
}
|
|
} // namespace
|
|
|
|
int main()
|
|
{
|
|
// RADV's 256 bytes: IOSurface's rows at 256.
|
|
check(rgfxSurfaceRowAlignment(256) == 256, "RADV's 256 bytes");
|
|
check(fromDeviceInfo(256) == 256, "RADV's 256 bytes, out of the device info");
|
|
// A host that answers none (an older host, a GPU of its own memory) or no more than IOSurface's
|
|
// own 64: IOSurface's 64.
|
|
check(rgfxSurfaceRowAlignment(0) == 64, "no answer");
|
|
check(fromDeviceInfo(0) == 64, "no answer, out of the device info");
|
|
check(rgfxSurfaceRowAlignment(16) == 64, "MoltenVK's 16 bytes");
|
|
check(rgfxSurfaceRowAlignment(64) == 64, "64 bytes");
|
|
// Up to a page.
|
|
check(rgfxSurfaceRowAlignment(128) == 128, "128 bytes");
|
|
check(rgfxSurfaceRowAlignment(4096) == 4096, "a page");
|
|
// No power of two, or past a page: IOSurface's 64.
|
|
check(rgfxSurfaceRowAlignment(192) == 64, "192 bytes");
|
|
check(rgfxSurfaceRowAlignment(8192) == 64, "two pages");
|
|
check(fromDeviceInfo(0x80000000u) == 64, "2 GiB, out of the device info");
|
|
|
|
std::printf("surface_rows_test: OK (%d checks)\n", checks);
|
|
return 0;
|
|
}
|