PDA

View Full Version : Slow access to VRAM




mif
Aug 22, 2013, 08:51 PM
I am wondering what have changed in Mountain Lion? I found a way to draw directly to the screen but it is much slower than in Snow Leopard. 8 fps versus 145 fps.

unsigned char *get_display_base_address()
{
kern_return_t kr;
io_connect_t framebuffer;
io_iterator_t iter;
io_service_t ioServicePort;
mach_vm_address_t vram = 0;
mach_vm_size_t shmemSize;
mach_port_t masterPort;

kr = IOMasterPort(bootstrap_port, &masterPort);
if (kr == KERN_SUCCESS)
{
kr = IOServiceGetMatchingServices(masterPort, IOServiceMatching(IOFRAMEBUFFER_CONFORMSTO), &iter);
if (kr == KERN_SUCCESS)
{
ioServicePort = IOIteratorNext(iter);
IOObjectRelease(iter);
kr = IOServiceOpen(ioServicePort, mach_task_self(), kIOFBSharedConnectType, &framebuffer);
IOObjectRelease(ioServicePort);
if (kr == KERN_SUCCESS)
{
kr = IOConnectMapMemory(framebuffer, 110, mach_task_self(), &vram, &shmemSize, kIOMapAnywhere);
IOServiceClose(framebuffer);
}
}
}
return (unsigned char *)vram + 0x180000; //return (unsigned char *)CGDisplayBaseAddress(CGMainDisplayID());
}



Catfish_Man
Aug 23, 2013, 12:17 PM
I am wondering what have changed in Mountain Lion? I found a way to draw directly to the screen but it is much slower than in Snow Leopard. 8 fps versus 145 fps.

unsigned char *get_display_base_address()
{
kern_return_t kr;
io_connect_t framebuffer;
io_iterator_t iter;
io_service_t ioServicePort;
mach_vm_address_t vram = 0;
mach_vm_size_t shmemSize;
mach_port_t masterPort;

kr = IOMasterPort(bootstrap_port, &masterPort);
if (kr == KERN_SUCCESS)
{
kr = IOServiceGetMatchingServices(masterPort, IOServiceMatching(IOFRAMEBUFFER_CONFORMSTO), &iter);
if (kr == KERN_SUCCESS)
{
ioServicePort = IOIteratorNext(iter);
IOObjectRelease(iter);
kr = IOServiceOpen(ioServicePort, mach_task_self(), kIOFBSharedConnectType, &framebuffer);
IOObjectRelease(ioServicePort);
if (kr == KERN_SUCCESS)
{
kr = IOConnectMapMemory(framebuffer, 110, mach_task_self(), &vram, &shmemSize, kIOMapAnywhere);
IOServiceClose(framebuffer);
}
}
}
return (unsigned char *)vram + 0x180000; //return (unsigned char *)CGDisplayBaseAddress(CGMainDisplayID());
}

Mountain Lion's window server uses a 'page flipping' design for double buffering. This is much faster in general, but tends to mess up direct access.

mif
Aug 27, 2013, 12:11 AM
Thanks, i did not know that.