DPC_START/DPC_END a new buffer start/end address. The START_PENDING / END_PENDING bits in DPC_STATUS will be set to 1, signaling that a transfer is indeed pending. New writes to DPC_END will now update the pending transfer; in other words, after a new DMA transfer is pending, it is not possible to incrementally add more commands to the currently-running transfer.
=== Programming considerations ===
The choice between using XBUS or not is an open debate. There is no clear cut answer and it should be carefully considered depending on the expected performance implications:
* If commands are already in RDRAM (eg: a static display list of RDP commands, read from ROM), then it is obviously more efficient to send them directly from there, without copying them first to DMEM. Libultra does not support this (in libultra, all RDP commands are always passed through RSP as they were RSP commands first, causing a double memory bandwidth impact if they are then sent back to RDRAM for RDP DMA); in libdragon, this is supported via [https://github.com/DragonMinded/libdragon/blob/caf684a06096afa3e9fc8ec8e70dd6643dab419e/include/rdpq.h#L1346-L1364 rdpq_exec].
* Symmetrically, short display lists of RDP commands can be already available in RSP DMEM (as part of the data segment of a RSP microcode). In this case, pushing them directly to RDP via XBUS is surely the fastest option.
* If commands are generated by the RSP (eg: triangles at the end of a T&L pipeline), consider the following aspects:
** sending back all the commands to RDRAM will have an impact on memory bandwidth (first, to transfer them from DMEM to RDRAM, and later from RDRAM to RDP). Memory bandwidth is often a bottleneck on N64.
** on the other hand, RDRAM allows for much larger buffers. When the buffers are small (like they typically are in DMEM), it means that the RSP could be forced to wait for the RDP to process the commands before producing new ones (basically this is back-pressure from RDP to RSP), and in turns it could cause a back-pressure on the VR4300. Often, RDP is the slowest among the three, so a larger buffer allows for better pacing.
While preparing buffers on RDP commands, it is useful to take advantage of incremental transfers. This is a possible algorithm:
# Prepare two buffers (in either DMEM or RDRAM).
# Get ready to send the first buffer by setting DPC_START = DPC_END = pointer to the start of the first buffer. This will not actually transfer any byte (remember DPC_END is an ''exclusive'' bound, so if you set DPC_START = DPC_END, this means "0 byte buffer"), but will setup the DMA engine as such.
# Generate RDP commands into the first buffer (assuming this is RSP, depending whether you are using XBUS or not, either just write them to DMEM, or also DMA them to RDRAM into the first buffer). Any time a new command is added to the buffer, write DPC_END to point past it. This basically tells the RDP that there are more commands to run, as soon as it is ready.
# When the buffer is full, go back to point 2, switching to the next buffer. Notice that the RDP DMA on the first buffer will continue running until all commands have been fetched, so the new buffer will be effectively pending at this point. Anyway, you can continue working on the new buffer and keep writing DPC_END: this is totally race-free, whether the new transfer is still pending, is ongoing, or even if it is finished.
# Consider that the RDP can only have one transfer pending. So anytime you write DPC_START to switch to a new buffer, first check if another transfer is already pending (by checking if the START_PENDING bit is set in DPC_STATUS). If it is pending, then you will need to wait for it. This also makes sure you don't start pushing new commands into the first buffer again, before the previous contents have been fully consumed.
Another possible approach to push commands into the RDP is using a single buffer, and checking DPC_CURRENT to race against the DMA. The idea is using the buffer as a circular one, and have the DMA constantly trailing behind our write pointer.
# Prepare a single buffer (in either DMEM or RDRAM). Write DPC_START = DPC_END = pointer to the start of the buffer. Notice that, as soon as the RDP accepts these register writes, DPC_CURRENT will also point there when read.
# Generate RDP commands and write them into the buffer. Any time a new command is written, update DPC_END. At this point, there are no pending DMAs (START_PENDING = 0), and in general we will have that DPC_START <= DPC_CURRENT <= DPC_END. To visualize this, remember that DPC_CURRENT is basically the "read pointer", while DPC_END is our "write pointer", within the same circular buffer.
# When we reach the end of the buffer, schedule a new DMA transfer on the same buffer from the beginning (so again DPC_START = DPC_END = pointer to the start of the buffer). At this point, this second transfer will be pending (START_PENDING = 1), but the RDP DMA will probably be still going through the buffer on the first time. So at this point we have DPC_START <= DPC_END < DPC_CURRENT. Notice in fact that reading DPC_START and DPC_END will return the ''pending'' values (the new run on the buffer), while DPC_CURRENT will still report the currently running transfer, and will keep going until the end of the buffer.
# Keep writing commands from the start of the buffer. This time, though, make sure that you never write past the current value of DPC_CURRENT. If you need to write a command but you have reached the current value of DPC_CURRENT, it means that you risk overwriting commands that have not been sent to RDP yet. So in this case, you will need to throttle (wait) for a bit.
# As soon as the RDP has finished going through the buffer, it will run the pending transfer and thus start from the beginning of the buffer again. After this happens (you can check it with START_PENDING becoming 0), you can freely go through the buffer writing commands, without checking DPC_CURRENT anymore. In fact, at this point we are back to the initial situation in which DPC_START <= DPC_CURRENT <= DPC_END so it is possible to keep writing until the end of the buffer.
In general, the second algorithm is more complex and requires a bit more code to be implemented, but it allows for less throttling and more efficient use of the memory. In fact, in the first scenario, whenever we have filled the available memory (two buffers) and we throttle, we will need to wait until the RDP finishes processing the whole first buffer. In the second scenario, instead, throttling is much reduced because as soon as the RDP processes one command, we get room for one more command to write.
==RDP Interface Registers ==
The RDP interface registers are memory mapped into the VR4300 physical address space starting from 0x0410 0000. Normally, accesses are performed through the virtual uncached segment, so at 0xA410 0000.
The exact same physical registers are also exposed as COP0 registers to RSP itself, and can thus be accessed using the MTC0 / MFC0 opcodes. Since access to all registers is shared by VR4300 and RSP, special care must be taken while writing software to decide who is in charge of each different resource / feature. For instance, normally DMA operations are performed by either the CPU or the RSP only; if the software architecture requires both to issue DMA transfers, some kind of mutex protocol must be established (for instance, using either the SIG bits in the SP_STATUS register, or the SP_SEMAPHORE register).
{| class="wikitable"
|+
!VR4300 address
!RSP COP0 register
!Name
!Description
|-
| 0x0410 0000
| style="text-align: center;" |c8
|[[Reality Display Processor/Interface#DPC START|DPC_START]]
| Start address in RDRAM / DMEM for a DMA transfer of RDP commands
|-
| 0x0410 0004
| style="text-align: center;" |c9
|[[Reality Display Processor/Interface#DPC END|DPC_END]]
|End address in RDRAM / DMEM for a DMA transfer of RDP commands (exclusive bound)
|-
|0x0410 0008
| style="text-align: center;" |c10
|[[Reality Display Processor/Interface#DPC CURRENT|DPC_CURRENT]]
|Current address in RDRAM / DMEM being transferred by the DMA engine
|-
|0x0410 000C
| style="text-align: center;" |c11
|[[Reality Display Processor/Interface#DPC STATUS|DPC_STATUS]]
|Status register
|-
|0x0410 0010
| style="text-align: center;" |c12
|[[Reality Display Processor/Interface#DPC CLOCK|DPC_CLOCK]]
|
|-
|0x0410 0014
| style="text-align: center;" |c13
|[[Reality Display Processor/Interface#DPC BUF BUSY|DPC_BUF_BUSY]]
|
|-
|0x0410 0018
| style="text-align: center;" |c14
|[[Reality Display Processor/Interface#DPC PIPE BUSY|DPC_PIPE_BUSY]]
|
|-
|0x0410 001C
| style="text-align: center;" |c15
|[[Reality Display Processor/Interface#DPC TMEM BUSY|DPC_TMEM_BUSY]]
|
|}
The registers mirror every 0x20 bytes across the whole range 0x0410'0000 - 0x041F'FFFF.
====