Repository navigation
ati-vga: Radeon 7000 (R100) with 3D for Mac OS 9 - #35
Open
brunocastello wants to merge 6 commits into
Open
brunocastello wants to merge 6 commits into
brunocastello wants to merge 6 commits into
Conversation
Mac OS 9 ships Apple's own drivers for the Radeon 7000 (R100, PCI 1002:5144), including the RAVE/OpenGL accelerator, but the stock 2D-only ati-vga gives the guest no 3D at all. Add ati-vga,model=r100 so that a mac99 guest can use those drivers. The model adds: - a command processor (ring buffer, indirect buffers, packet0/2/3) in ati_cp.c, plus the GART aperture the drivers expect; - a 3D engine in ati_3d.c that decodes the packet3 draw/state stream into an ATIDrawState (render targets, textures, depth, blend, fog, scissor) and tracks guest surfaces that live in VRAM or GART; - a host renderer in ati_glr.c / ati_gl.c running on its own thread. ati_gl.c creates a CGL OpenGL 4.1 Core context on macOS (OpenGL.framework loaded with dlopen()) or a surfaceless EGL / GLES 3.0 context on Linux (libEGL/libGLESv2, dlopen()ed), so there is no link-time dependency on a host GL; QOM x-accel-stats / x-gl-renderer report whether 3D is available; - the 2D engine rework needed to share state with the 3D path (GUI master control, host-data blits, HOST_DATA registers in ati_dbg.c). Only machines that instantiate ati-vga are affected; the other ati-vga models keep their behaviour. Provenance: this is a port of the R100 model from RetroBoot 2.0.1 (emulator/patches/retroboot-ati-r100.patch, RetroBoot commit 432a43d4ba8502a7afeaa5dd25ecf959c23aed1c) as imported by amcchord/ClassicMac (ati/, commit bcee0a7d400312d3f37fb82d5abf19452416f3bb), including ClassicMac's CGL back end and its idle, texture-swap and cursor fixes. It was rebased by hand from QEMU 11.0.2 onto QEMU 10.0 (the physical_memory dirty test becomes memory_region_snapshot_*). ClassicMac's host-resize patch (needs its own display mailbox) is not ported. The originals are GPL-2.0-or-later like QEMU; the copyright headers of the original authors are kept. Details are in hw/display/ATI-R100-PROVENANCE.md, added later in this series. Signed-off-by: Bruno Castelló <bfcastello@gmail.com> Assisted-by: Claude:claude-opus-5-5
…C LUT With the R100 3D engine in place, Mac OS 9 and its games exposed several display problems. They all concern what the scanout and the blit engine believe about the framebuffer, so they are fixed together: - Mode changes: the scanout format was only applied by ati_vga_switch_mode(), which a few register writes never trigger (CNFG_CNTL, SURFACE_CNTL, display size written while the CRTC is off), so a switch to 16 bpp could keep the old 32 bpp format. The display update now compares a signature of those registers and re-applies the mode; the big-endian framebuffer also follows the SURFACE_CNTL aperture swap bits the Mac driver uses. - Render targets tracked for the old mode (e.g. the 32 bpp desktop) stayed GL-owned across a switch to 640x480x15 and were read back over the new framebuffer in their own format and pitch. Drop them, and the in-flight reads, when the scanout bpp, stride or size changes. - Below 32 bpp the big-endian framebuffer is converted into a shadow surface that was refreshed from the VGA dirty log only, so with 2D/3D engine writes the display froze on stale VRAM. Redraw the whole shadow on every update for Radeon at those depths. - A GUI_MASTER_CNTL with the SRC/DST_PITCH_OFFSET_CNTL bit clear overwrote SRC/DST_PITCH_OFFSET with the default. The Mac driver writes the blit source (the back buffer) once, so a later blit that selects it again read the front buffer itself and the frame never arrived. Save the guest's values at the overwrite and restore them when a later operation selects them again without rewriting them. The surface format is also read from the pixman image of the display surface. - The VGA core ignores the palette above 8 bpp, so DrawSprocket gamma fades had no effect. Apply the DAC LUT as a gamma ramp to the converted shadow surface in 15/16 bpp direct colour once the guest loaded one. - Mac OS's RAVE presents by copying the GL back buffer to the front buffer with the CPU through the aperture, which read stale VRAM. The vblank readback now covers every GL-owned target drawn since its last landing, not only the scanout. - Trace each unhandled CP packet3 opcode once. New trace events (scanout mode, display surface, DAC LUT, CRTC offset, front-buffer changes, 2D op/source, 3D target/texture/readback) came with these fixes and are the way to diagnose the next display problem. Signed-off-by: Bruno Castelló <bfcastello@gmail.com> Assisted-by: Claude:claude-opus-5-5
Mac OS 9's OpenGL renderer (OpenGLRendererATI) draws with the chip's transform-and-lighting unit: SE_CNTL_STATUS bit 8 (TCL bypass) is clear and the vertices arrive in object space. Only RAVE sets the bypass bit and sends window-space vertices, which is the only path the model handled, so every OpenGL draw landed in the wrong place. Implement the TCL unit in ati_3d.c, written from the public Mesa r100 driver and the Linux radeon DRM sources (see ATI-R100-TCL.md): - T1: load the vector/scalar parameter memory through the SE_TCL_*_INDX/DATA ports (0x2200-0x220c), pick the model-view-projection matrix and viewport, transform positions to window space. - T2: texture matrices and texgen. - T3: lighting (ambient, diffuse, specular, spot, attenuation) and vertex colour sources. - T4: fog and user clip planes. The window-space path used by RAVE is unchanged. The vertex shader in ati_glr.c gets a "tcl" uniform: after the transform 1/rhw is the clip-space w, which can be negative behind the eye, so GL has to clip instead of clamping. Primitives without VF_CNTL.TCL_ENABLE are still treated as window-space. T1 was checked against Mac OS 9; T2-T4 were implemented from the register documentation only. Signed-off-by: Bruno Castelló <bfcastello@gmail.com> Assisted-by: Claude:claude-opus-5-5
… honour ALPHA_IN_MAP Two behaviours of ATI's Mac OS drivers that the model got wrong: - 3D_CLEAR_ZMASK: the OpenGL driver issues it with first tile 0 and tile count 0 for every depth glClear (Quake III). The model computed an empty range and cleared nothing, so depth kept the nearest values ever drawn and the world failed the depth test (HUD only, old frames left on screen). Count 0 now clears the whole depth surface. - PP_TXFORMAT ALPHA_IN_MAP: the RAVE engine leaves the bit clear for 16-bit GWorld textures whose top bit is not alpha. The model used that bit as alpha, so translucent sprites blended with (ONE, ONE_MINUS_SRC_ALPHA) came out additive. When the bit is clear the sampler now returns alpha 1; the renderer forces it per unit through tex_en bits 4-6. Signed-off-by: Bruno Castelló <bfcastello@gmail.com> Assisted-by: Claude:claude-opus-5-5
The emulated Radeon 7000 has no FCode ROM, so the stock OpenBIOS neither sets a boot mode on it (the Bochs VBE registers its VGA FCode uses do not exist on the R100) nor publishes the Radeon device properties Mac OS looks for. Ship two OpenBIOS builds that handle it: - openbios-ppc-r100: OpenBIOS e1e703ac (the tree openbios-ppc comes from) plus ClassicMac/RetroBoot's openbios-ati-radeon patch. - openbios-ppc-r100-retail: the same, with the node named ATY,RADEONp and the retail Radeon Mac Edition ROM properties. The patches and the exact build recipe (builder container digest, OpenBIOS commit, reproducible banner date) are kept in roms/openbios-ati-r100/ so the binaries can be rebuilt, in line with how pc-bios/ blobs are normally accompanied by their sources. They carry the OpenBIOS licence of the files they patch; the originals come from the same RetroBoot/ClassicMac sources as the device model. ClassicMac's Mac OS 8/9 profile patch is kept for reference but is not built into pc-bios. Signed-off-by: Bruno Castelló <bfcastello@gmail.com> Assisted-by: Claude:claude-opus-5-5
Document the R100 work for reviewers and future maintainers: - ATI-R100-PROVENANCE.md records the upstream sources of the model (RetroBoot 2.0.1 at 432a43d4ba85, as imported by ClassicMac at bcee0a7d400, with the SHA-256 of the patch), which ClassicMac patches were taken or left out, the licence (GPL-2.0-or-later), what had to change to move from QEMU 11.0.2 to 10.0, the firmware used and a sample command line. - ATI-R100-TCL.md documents the hardware TCL emulation: registers, vector/scalar state maps, the vertex format, the T1 pipeline and the T2-T4 stages, what is deliberately not emulated, and which guesses have not been confirmed against ATI's driver. Signed-off-by: Bruno Castelló <bfcastello@gmail.com> Assisted-by: Claude:claude-opus-5-5
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds an ATI Radeon 7000 (R100) model to
ati-vga(-device ati-vga,model=r100) with working 3D, so Mac OS 9 can use ATI's own drivers for OpenGL and RAVE. With ATI's January 2005 Mac OS 9 drivers, GLQuake, Quake III, Nanosaur and Blokz RAVE run accelerated on the host GPU.The model is ported from RetroBoot 2.0.1 via amcchord/ClassicMac (GPL-2.0-or-later; original copyright headers kept, details in
hw/display/ATI-R100-PROVENANCE.md) and rebased from QEMU 11 to 10.0.Changes
hw/display/ATI-R100-TCL.md).CLEAR_ZMASKwith a tile count of 0 clears the whole surface (Quake III clears depth that way), andALPHA_IN_MAPis honoured (16-bit textures without alpha).openbios-ppc-r100andopenbios-ppc-r100-retail(the latter names the cardATY,RADEONpso ATI's retail drivers attach), with the patches and build recipe inroms/openbios-ati-r100/.Testing
The two OpenBIOS images are ~700 KB each; I can split them out or drop them if you'd rather build them elsewhere. UTM's side (a "ATI Radeon 7000" display option) will be a separate PR.
To be upfront: I built this with Claude (Anthropic) through Claude Code. The port, fixes and analysis are largely Claude's work; I directed it and tested it in my own VMs. Please review it with that in mind, and I'm happy to change anything.