Looking to attempt GPU passthrough - Which card to get?

About Qemu-system-ppc, a PPC Mac emulator for Windows, macOS and Linux that can run Mac OS 9.0 up to Mac OS X 10.5

Moderators: Cat_7, Ronald P. Regensburg

Post Reply
ajshell1
Student Driver
Posts: 10
Joined: Tue Jul 13, 2021 3:45 pm

Looking to attempt GPU passthrough - Which card to get?

Post by ajshell1 »

Recently, I saw this post which showed a person using QEMU to pass a physical ATI Rage to a OS X 10.4 VM: https://forums.macrumors.com/threads/qe ... h.2229861/

At first, my thought was "This is kind of pointless. QEMU already has the Rage 128 as an emulated device. Sure, I can't seem to get it working right, but eventually it will work."

That's when it hit me: I could use the same technique as him, except with a better GPU!

I use Linux on all my machines at home, and I've successfully done GPU passthrough before, so I figure that as long as I can get the right hardware, I can get this working.

This begs the question: what is the right hardware? I'm thinking of a Radeon 9000 series card, but I'm not sure which to get.

I'm also not sure if I should just buy a cheap Windows-oriented Radeon card and flash it, or if I should pay extra for an explicitly Mac version.

Ideally, I'd like a card that could be used for both Windows and Mac. I think it would be cool if I could also use that card for GPU Passthrough to a Windows VM. Similarly, I'd like to use that card for MorphOS or AmigaOS 4.1 FE on QEMU.

Let me know what you think, and I'll be sure to post updates.
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: Looking to attempt GPU passthrough - Which card to get?

Post by adespoton »

Interesting idea!
https://en.wikipedia.org/wiki/Core_Image provides a list of GPUs that support Core Image on 10.4 -- so I'd guess one of them should work in passthrough? One thing to remember is that the Mac firmware differs from the PC firmware. Also, that includes GPUs that are probably only supported by 10.4.7+ x86; I can't imagine the Intel chips passing through correctly to PPC Tiger (although that'd be an interesting experiment).

Also, as far as the Rage 128 support goes: I believe current support is limited to presenting and loading the stub: there's no actual emulation or passthrough happening yet. This is often enough to get old games running that can fall back to software rendering but have a check for the Rage 128, which is why it is included as-is, if I recall discussions correctly.

Something on my personal back-burner is to figure out if there's a way to pass a modern GPU through with a fake mapping to an older card -- since modern GPUs should be more than capable of handling all the old APIs, even if the inputs might have shifted a bit.
ajshell1
Student Driver
Posts: 10
Joined: Tue Jul 13, 2021 3:45 pm

Re: Looking to attempt GPU passthrough - Which card to get?

Post by ajshell1 »

So, here are some of my options I'm considering so far:

First of all, I can't seem to find an adaptor that allows AGP cards to connect to a PCI-E slot, so I'm limited to PCI.

At least, that's what I thought at first. It turns out that the final revision of the PowerMac G5 had PCI-E slots, and that ATI Radeon X1900 cards were made for this model specifically.

For whatever reason, those cards seem to be rather plentiful on eBay, and they seem to be quite cheap, as I can see several around $50-$70. And there seem to be a lot of forum posts on various sites discussing how to flash it PC firmware, so I shouldn't worry that much about flashing it to PC if needed. Luckily, this card also seems to be compatible with MorphOS and Amiga OS 4.1 FE (which are also PPC-based operating systems I like to emulate with QEMU).

And since it's a PCI-E card, I won't need to bother with a PCI to PCI-E adapters. It should just fit into my main PC case and work.

That said, there seem to be two versions of the card: one built for the G5, the other for Intel Macs. I think I should get the G5 model if I can find it, but I'm not 100% sure which is which. Hopefully I would be able to flash the firmware if things don't go well, but I'd rather not take that risk.

Fortunately, I have a use case in mind in the event that card only ends up working on Intel systems: use it with qemu-system-x86_64 to make a virtualized Hackintosh.

As for alternatives, I think most cards before the X1900 were AGP, which isn't an option for me unless I find an adapter. The big one that stuck out to me was the ATI Radeon 9200. I can find two Mac edition 9200 cards on ebay right now. They are both PCI, so I'd either need an adapter, or I'd need to use them with an older disused case of mine which still has a PCI slot (it's an FM2+ board with an A8-7600. So if I do go that route, there will be a SUBSTANTIAL performance decrease compared to my Ryzen 7 3700X).

Of course, as far as I can tell, QEMU can't emulate a G5 yet, but it can do a G4 or G3. So I'd end up emulating a fantasy Mac that has both a G4 and PCI-E slots. I'm not sure if that would cause things to break or not.

Also, I'm using QEMU from the Arch Linux repositories (that is, QEMU 6.0.0), and I can't get sound to work on the "mac99" platform to save my life. It seems as though Morphos and MacOS (X) fail to detect any sound hardware. Has any one else noticed the same problem?
Last edited by ajshell1 on Wed Jul 14, 2021 4:46 pm, edited 1 time in total.
User avatar
Cat_7
Expert User
Posts: 6145
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Looking to attempt GPU passthrough - Which card to get?

Post by Cat_7 »

Hi,

Audio support is only available when you build your own Qemu from this repository (and use the included openbios-ppc):
https://github.com/mcayland/qemu/tree/screamer

Best,
Cat_7
ajshell1
Student Driver
Posts: 10
Joined: Tue Jul 13, 2021 3:45 pm

Re: Looking to attempt GPU passthrough - Which card to get?

Post by ajshell1 »

Cat_7 wrote: Wed Jul 14, 2021 4:53 pm Hi,

Audio support is only available when you build your own Qemu from this repository (and use the included openbios-ppc):
https://github.com/mcayland/qemu/tree/screamer

Best,
Cat_7
Ah, thanks.

I'm confident that I'm capable of compiling that for myself, and I'm hopeful that I'll be able to figure out a way to use that while the normal version of QEMU is also installed on my system.

Regardless, I've decided to buy an X1900 GT. I'll find one use for it, one way or another.
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: Looking to attempt GPU passthrough - Which card to get?

Post by adespoton »

You may be able to use usb-audio as a short-term workaround, but using the screamer fork with the custom openbios will be much more useful for what you're doing. Just be warned that snapshotting is incompatible with the screamer fork -- which is why it's not in the mainline build yet.
ajshell1
Student Driver
Posts: 10
Joined: Tue Jul 13, 2021 3:45 pm

Re: Looking to attempt GPU passthrough - Which card to get?

Post by ajshell1 »

Sound is now working for me with that special QEMU fork. Hopefully these changes will get merged upstream at some point.

As for the X1900 GT, it's expected to arrive on July 19th. I'll post an update here when it arrives.
ajshell1
Student Driver
Posts: 10
Joined: Tue Jul 13, 2021 3:45 pm

Re: Looking to attempt GPU passthrough - Which card to get?

Post by ajshell1 »

Bad news. I just got the card today. I plugged it into two different motherboards. Each time, I didn't get any video and it beeped at me five times.

I'm not sure this is going to work. You guys have any ideas?

Maybe I could try one of those USB to PCI-E risesr. You know, the type that coin miners use.
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: Looking to attempt GPU passthrough - Which card to get?

Post by adespoton »

5 beeps means the system isn't detecting the GPU. Possibly someone already flashed it?
ajshell1
Student Driver
Posts: 10
Joined: Tue Jul 13, 2021 3:45 pm

Re: Looking to attempt GPU passthrough - Which card to get?

Post by ajshell1 »

adespoton wrote: Fri Jul 16, 2021 10:25 pm 5 beeps means the system isn't detecting the GPU. Possibly someone already flashed it?
I was under the impression that this was sold as a Mac card for Macs, and the seller listed it as tested working.

I'd deduce that this Mac card simply doesn't want to play nice with my non-Apple PC.

Do you guys think I should try a PC-based card?
ajshell1
Student Driver
Posts: 10
Joined: Tue Jul 13, 2021 3:45 pm

Re: Looking to attempt GPU passthrough - Which card to get?

Post by ajshell1 »

I just tested it on my SuperMicro X10SL7-F motherboard.

It boots! https://cdn.discordapp.com/attachments/ ... 7-0400.png

Let's see if I can get it working in a VM!

Update at 21:52 PM:

I think I've successfully gotten the passthrough part working.

https://cdn.discordapp.com/attachments/ ... 6-0400.png

Running "lspci -vnn" on the host shows this:

01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] R580+ [Radeon X1950 XTX] [1002:7240] (prog-if 00 [VGA controller])
Subsystem: Advanced Micro Devices, Inc. [AMD/ATI] R580+ [Radeon X1950 XTX] [1002:7240]

Note "1002:7240". That also appears in the screenshot.

But, I'm not sure how to boot it now.

The guy in the macrumors thread I posted earlier stated that he used a specific command that required a rage 128-specific bios elf file , and then he has to run some other commands to get it to boot. I don't know much about OpenBIOS stuff, so I'm entirely reliant on your help here. Please. I'm so close to getting it to work.

EDIT: Also, my SuperMicro board is a headless server, so currently that X1900 GT is plugged into an old monitor. My experience with GPU passthrough says that if it's working, something will show up on the monitor.
User avatar
Cat_7
Expert User
Posts: 6145
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Looking to attempt GPU passthrough - Which card to get?

Post by Cat_7 »

Hi,

On a real mac you could type "boot" and openbios would then execute the boot sequence up to the point where it hands over control to the Mac OS.
Part of that execution is the load the rom file (written in fcode) contained on the Apple graphics card and to populate the device tree and load the driver so Mac OS can use the card.
That is the tricky bit, as openbios is not complete enough to provide all methods (words) needed to execute the fcode loaded from the card.

The solution to this is to extend openbios' capabitities by defining additional words and to pre-set some properties on the device tree entry for the card so Mac OS can see the card. (This last part would not be required if openbios would allow full execution of the bios so those things would be set during boot). The custom elf file you refer to has some of those properties set in the file already.

Best,
Cat_7
ajshell1
Student Driver
Posts: 10
Joined: Tue Jul 13, 2021 3:45 pm

Re: Looking to attempt GPU passthrough - Which card to get?

Post by ajshell1 »

Okay, so in the macrumors thread I linked to earlier, the OP mentions having to run these commands to get it to work:

dev /pci ls
dev /pci/@10
load hd:,\ppc\ragepci
" /pci/@10" select-dev
400003f 1 byte-load
boot

I know that I need to run "dev /pci/@f" instead of "@10", but I'm not sure how he arrives at "400003f". Do you guys have any insight?

EDIT: Also, I can't seem to install the drivers for the X1900 GT because it says it requires a G5. Do you think it would be possible to bypass this, since QEMU seems to only be able to emulate the G3 and G4?
User avatar
Cat_7
Expert User
Posts: 6145
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Looking to attempt GPU passthrough - Which card to get?

Post by Cat_7 »

That is the address where the rom file will be loaded.
You'd have to find out where yours should go.

For initial boot you do not need to install the card drivers in Mac OS. The fcode on the card will contain a basic driver.

Best,
Cat_7
ajshell1
Student Driver
Posts: 10
Joined: Tue Jul 13, 2021 3:45 pm

Re: Looking to attempt GPU passthrough - Which card to get?

Post by ajshell1 »

Cat_7 wrote: Sat Jul 17, 2021 4:07 pm That is the address where the rom file will be loaded.
You'd have to find out where yours should go.

For initial boot you do not need to install the card drivers in Mac OS. The fcode on the card will contain a basic driver.

Best,
Cat_7

And how exactly do I find that out? I don't have the slightest clue where to start looking.


EDIT: also, here is the command I'm currently using:

Code: Select all

#!/bin/bash
/opt/qemu/build/qemu-system-ppc \
-L /opt/qemu/pc-bios \
-M mac99,via=pmu \
-cpu G4 \
-m 1024 \
-boot c \
-bios /opt/qemu/pc-bios/openbios-ppc \
-prom-env 'vga-ndrv?=false' \
-prom-env 'boot-args=-v debug=0xffe kdp=2' \
-prom-env 'auto-boot?=false' \
-drive if=none,id=hd,file=hd-osx104.qcow2,format=qcow2 -device ide-hd,drive=hd,bus=ide.0 \
-drive if=none,id=cd -device ide-cd,drive=cd,bus=ide.1 \
-device sungem,netdev=network01 -netdev user,id=network01 \
-device vfio-pci,host=01:00.0,multifunction=on,rombar=1,romfile="x1900gt.rom" \
-vnc 0.0.0.0:0 \
#-vga none -nographic
I have not managed to get OS X to display anything through that card yet. However, it clearly isn't broken, because I've seen MorphOS on the Mac99 platform displaying video through it. Sometimes I'll uncomment "-vga none -nographic" and comment out the "vnc" line to see if it works with the PCI-E card as the only display. However, since the card doesn't display anything, I can't tell what's going on.


Also, I can't find that card listed anywhere in "about this Mac" menu when passing through that card while VNC is enabled (this is a headless server, so this is required).
User avatar
Cat_7
Expert User
Posts: 6145
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Looking to attempt GPU passthrough - Which card to get?

Post by Cat_7 »

Hi,

Here are some pointers and a good explanation of the issue to be addressed by one of the programmers that put considerate effort into getting a card to work:

Zoltan says:
"One important point that was not mentioned that it will never work with
the OpenBIOS that comes with QEMU because that still does not have all the
patches needed to run FCode ROM even if you load and run it manually
becuase all the missing words and bugs we've found when trying the ATI
ROM. So first you need the patched OpenBIOS we were using before otherwise
the ROM will just not run correctly even if you managed to load it. I
think this was in another thread somewhere but I can't find that.

Then it's not clear if the card is actually a Mac card (that has an FCode
ROM that should work) or a PC card that needs an external ROM image
compatible with it. If not using the ROM from the card then does the ROM
matches the card? Just trying to load a random ROM image will not
correctly set up and operate the card, it has to be compatible with it so
if it's a PC card first ensure it can be flashed to work with Mac and the
ROM is correct for the card. If it's a Mac card ensure it has an FCode ROM
that works on a real Mac before trying to run it on an emulated one.
(Otherwise if it does not work you won't know it's not working because
emulation is not correct or it's not working becuase it would not work on
real hardware so we just get the same in emulated hardware.)

Seeing the card appear in the device tree is one thing but we did not get
a .properties output from it. If you see an NDRV added by OpenBIOS in
there then use -prom-env "vga-ndrv?=false" to prevent OpenBIOS trying to
patch the device node as that would just break it. You need the
correct card ROM, then enable fcode-debug? and try to run the ROM. If the
device node changes after that then it may work (I think the ATI ROMs
rename the node to aty or something like that and add some version numbers
and other info so if you don't see those then card ROM did not run
correctly.

I think the address should be 4000040 if you load the ROM from file which
is actually "load-address 40 +" that is hex 40 bytes from load-address
written in Forth where load-address is by default 4000000 in OpenBIOS that
is the address where it loads stuff. This is because the start address of
an FCode ROM is after the hex 40 bytes header. If you have a Mac ROM then
you could map the card ROM and run that instead of loading the ROM from
disk, then the address will be where the ROM is mapped. OpenBIOS may map
the ROM or there may be a way to do that but I forgot how to do it; the
address should be in one of the .properties (addresses or
assigned-addresses) if the ROM is mapped. The ROM is BAR 6, usually the
last of the ones listed. It helps to know these stuff if you want to debug
it, here's some reference: https://pve.proxmox.com/wiki/Pci_passthrough
including how to dump ROM from card to see if it's PC or Mac ROM and to
make sure you're using the right ROM. If you have the ROM it may be enough
to extract NDRV from it (probably cut the part starting from Pef! or
something like that, I forgot the details) and add that NDRV with romfile
which OpenBIOS will attach to the device tree when its own NDRV is
disabled that might be enough if no other initialisation is needed by the
ROM.

Then I'm also aware of this comment in QEMU sources that may or may not be
relevant for these cards:

https://git.qemu.org/?p=qemu.git;a=blob ... =HEAD#l243

and similiar ones in same file which suggests pass through may only be
tested with Radeon HD and newer and older cards may have problems. I'd
suggest to try booting a Linux guest first because you'd get better
debugging output and once that works you can try MacOS and then sort out
what else that may need.

The approach of the OP saying: "Please. I'm so close to getting it to
work." is wrong. You never know how close you are because you only see the
next problem and don't know how many more and how big are waiting behind
that one. I know this well getting the machines work with QEMU. I always
focus on the next problem but this could be the last one or there could be
50 more after it. You'll only find out once you get past this one and even
then you'll only find the next problem and don't know how many more are
still there after that. Knowing this helps to not get disappointed and
give up too soon, just be prepared there could be more problems and if
you're lucky to have only one then you'll get it working faster but you
may need to keep experimenting and get past more problems before you get
it working.

About your current command line:
At least vga-ndrv?=false is there and MorphOS seems to work (that has its own
driver so as long as it finds the card in the device tree it will init it
itself without relying on the ROM or device tree) so that suggests
pass-through itself works but the ROM is not adding the necessary info to
device tree needed for MacOS probably because it's not running correctly
due to wrong OpenBIOS version missing needed words. But maybe I'm not
aware of some other discussion going on outside the forum so these are
just some random thoughts I had that hopefully help. In any case if he
manages to make it work with MorphOS he could post some instructions on my
site or some other Amiga forum to help others who may be interested."
User avatar
Cat_7
Expert User
Posts: 6145
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Looking to attempt GPU passthrough - Which card to get?

Post by Cat_7 »

I case you cannot create your own openbios, a more or less suitable openbios containing some patches to allow loading/executing a rom file is in the download here:

https://surfdrive.surf.nl/files/index.p ... z/download

It also contains a readme on how to get things going with Mac OS 9.2.

The patches come from here: https://mail.coreboot.org/hyperkitty/li ... 56SFUCPLX/

Best,
Cat_7
Post Reply