Looking at PowerVR's PPP definitions in tree in Mesa (src/imagination/csbgen/), we find that AGX's "tagged" data structures are actually sequences of state items prefixed by a header specifying which state follows. Rather than hardcoding the sequences in which Apple's driver chooses to bundle state, we need the XML to be flexible enough to encode or decode any valid combination of state. That means reworking the XML. While doing so, we find a number of fields that are identical between RGX and AGX, and fix the names while at it (for example, the W Clamp floating point). Names are from the PowerVR code in Mesa where sensible. Once we've reworked the XML, we need to rework the decoder. Instead of reading tags and printing the combined state packets, the decoder now must unpack the header and print the individual state items specified by the header, with slightly more complicated bounds checking. Finally, state emission in the driver becomes much more flexible. To prove the flexibility actually works, we now emit all PPP state (except for viewport and scissor state) as a single PPP update. This works. After this we can move onto more interesting arrangements of state for lower driver overhead. Now that we have fine grained state emit code, let's use it to reduce driver overhead. Dirty tracking is delicate: while this seems to work, I've also added an ASAHI_MESA_DEBUG=dirty option in debug builds to disable the optimizations here for future debug.