psx.wiki

GP0 Transfer and Other Commands

Frame buffer fill, copy and transfer commands and the other GP0 commands.

Summary

The transfer commands of GP0 make the GPU move image data between main memory and the frame buffer and within the frame buffer. Sony lists three image transfers among the GPU drawing functions: CPU to frame buffer, frame buffer to CPU and frame buffer to frame buffer.1 These are command groups 4, 5 and 6. The fill and cache commands belong to group 0, and GP0 Drawing Commands lists all the groups. For groups 4 to 6 the GPU ignores the lower 29 bits of the command word, so any value may be placed there.2

Table 1: Transfer and other commands
Command Purpose Words libgpu function
GP0(01h) Clear texture cache 1
GP0(02h) Fill a rectangle in the frame buffer 3 ClearImage()
GP0(80h) VRAM-to-VRAM copy 4 MoveImage()
GP0(A0h) CPU-to-VRAM transfer 3 and data LoadImage()
GP0(C0h) VRAM-to-CPU transfer 3 and data StoreImage()
GP0(1Fh) Interrupt request (IRQ1) 1
GP0(00h) No operation 1

The libgpu functions in the table are those that access the frame buffer directly.3 ClearImage() sets a rectangle of the frame buffer to one RGB color and is not affected by the clip and offset of the drawing environment. In interlace mode ClearImage() clears only one field, so ClearImage2() must be used to clear both.4

Frame Buffer Transfers in libgpu

LoadImage(), StoreImage() and MoveImage() are non-blocking functions. Each returns before the transfer is complete, and the transfer proceeds in the background; consequently, the end of the transfer must be detected with DrawSync(). Up to 64 non-blocking requests may wait in the queue, and a 65th request blocks until a place in the queue is free.35

The rectangle given to these functions is in frame buffer coordinates of 16-bit pixels. For a 4-bit texture the width in texels must therefore be divided by 4, and for an 8-bit texture by 2; a 4-bit texture must be a multiple of 4 pixels wide and an 8-bit texture a multiple of 2.6

GP0(01h) - Clear Cache

GP0(01h) flushes the texture cache. It is used after the frame buffer is changed, in the same way that the CPU instruction cache must be flushed after new code is written. psx-spx reports that demos can make the GPU draw stale cached texels by changing VRAM without this command, but that games do not do this.7

GP0(02h) - Fill Rectangle in VRAM

GP0(02h) fills a rectangle of the frame buffer with one color. It is faster than an equivalent rectangle drawing command and is therefore used to clear the screen. The command is 3 words:8

Table 2: GP0(02h) words
Word Format Content
1 02BBGGRRh Command and 24-bit RGB color
2 YyyyXxxxh Top left corner, X in halfwords in steps of 10h
3 YsizXsizh Width and height, width in halfwords in steps of 10h

The GPU converts the 24-bit color to 15 bits by dropping the lower 3 bits of each component, and it writes bit 15 (the mask bit) as 0. The fill ignores the GP0(E6h) mask setting and behaves as if both of its bits were 0. Horizontally the fill works in units of 16 pixels (32 bytes), so the parameters are rounded as follows:89

Table 3: GP0(02h) parameter rounding
Parameter Rounding Range
Xpos Xpos AND 3F0h 0 to 3F0h in steps of 10h
Ypos Ypos AND 1FFh 0 to 1FFh
Xsiz ((Xsiz AND 3FFh) + 0Fh) AND (NOT 0Fh) 0 to 400h in steps of 10h
Ysiz Ysiz AND 1FFh 0 to 1FFh

No fill takes place when Xsiz or Ysiz is 0. Because of the masking a parameter of 400h becomes a width of 0. A parameter from 3F1h to 3FFh, however, rounds up to a width of 400h. A single fill command therefore covers at most 511 lines, and a fill with the full height of 512 lines does nothing because its height is masked to 0.9

The v0 GPU has a defect in this command. When bits 0 to 3 of the X coordinate are all set, it writes every second pixel to the wrong address; the v2 GPU ignores these bits as intended. Software should therefore always set them to 0.10

GP0(80h) - Copy Rectangle VRAM to VRAM

GP0(80h) copies a rectangle within the frame buffer. The command is 4 words:11

Table 4: GP0(80h) words
Word Format Content
1 80000000h Command
2 YyyyXxxxh Source coordinates, X in halfwords
3 YyyyXxxxh Destination coordinates, X in halfwords
4 YsizXsizh Width and height, width in halfwords

The copy is affected by the mask setting of GP0(E6h).11

GP0(A0h) - Copy Rectangle CPU to VRAM

GP0(A0h) transfers image data from the CPU to the frame buffer. After the 3 command words the data follows as 32-bit words, which are normally sent by DMA:12

Table 5: GP0(A0h) words
Word Format Content
1 A0000000h Command
2 YyyyXxxxh Destination coordinates, X in halfwords
3 YsizXsizh Width and height, width in halfwords
4 and later Data, two halfwords per word

Because the data is sent in 32-bit words, an odd number of halfwords is padded with one extra halfword. The transfer is affected by the mask setting of GP0(E6h).12

GP0(C0h) - Copy Rectangle VRAM to CPU

GP0(C0h) transfers image data from the frame buffer to the CPU. The CPU writes the 3 command words to GP0 and then reads the data from the GP0 port, or by DMA:13

Table 6: GP0(C0h) words
Word Direction Content
1 Write Command (C0000000h)
2 Write Source coordinates, X in halfwords
3 Write Width and height, width in halfwords
4 and later Read Data, two halfwords per word

The CPU must wait until bit 27 of GPUSTAT is set before it reads the data. As with GP0(A0h), an odd number of halfwords ends with one extra halfword.13

Copy Parameters

The copy commands clip their parameters to 10 and 9 bits. The only special case is a size of 0, which means the maximum size:14

Table 7: Copy parameter masking
Parameter Masking Range
Xpos Xpos AND 3FFh 0 to 3FFh
Ypos Ypos AND 1FFh 0 to 1FFh
Xsiz ((Xsiz - 1) AND 3FFh) + 1 1 to 400h
Ysiz ((Ysiz - 1) AND 1FFh) + 1 1 to 200h

The coordinates of all transfer commands are absolute frame buffer addresses. The drawing offset is not added and the drawing area does not clip them. When a source or destination rectangle extends past the 1024 x 512 frame buffer, the copy or fill wraps to the opposite edge. There is no carry from X into Y or from Y into X.1516

A transfer command differs from a textured rectangle in three ways: it is not clipped to the drawing area, it does not treat any texel as transparent or semi-transparent, and it does not convert color depth. A 4-bit texture copied with GP0(80h) is therefore not expanded to 16-bit pixels.17

psx-spx reports that a continuous DMA transfer to or from VRAM works only during vertical blanking on the GPU it tested, and that parts of the data are skipped at other times. Transfers by the CPU are not affected, and neither is the DMA list mode that sends an ordering table.15

GP0(1Fh) - Interrupt Request

GP0(1Fh) requests interrupt IRQ1 and sets bit 24 of GPUSTAT. The interrupt is acknowledged with GP1(02h). psx-spx describes the command as rarely used.18

GP0(00h) - NOP

GP0(00h) does not take up space in the command FIFO. Dozens of GP0(00h) words can be sent while a VRAM-to-VRAM copy is still busy without filling the FIFO. Consequently the command is either ignored or executed at once.19

GP0(04h) to GP0(1Eh), GP0(E0h) and GP0(E7h) to GP0(EFh) behave the same way. However, the drawing area and offset commands also take no FIFO space, so this alone does not prove that these commands have no function. GP0(03h), by contrast, does take a FIFO entry, and its purpose is unknown.2021

References


  1. ^ Sony Computer Entertainment Inc. PlayStation Hardware. August 1998. Page 3-5, Figure 3-2.

  2. ^ psx-spx. Graphics Processing Unit (GPU), GPU Memory Transfer Commands. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-memory-transfer-commands

  3. ^ a b Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 8-8.

  4. ^ Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Pages 7-38 to 7-39, ClearImage and ClearImage2.

  5. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 8-9.

  6. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 8-23.

  7. ^ psx-spx. Graphics Processing Unit (GPU), Clear Cache. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-io-ports-dma-channels-commands-vram

  8. ^ a b psx-spx. Graphics Processing Unit (GPU), Quick Rectangle Fill. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-io-ports-dma-channels-commands-vram

  9. ^ a b psx-spx. Graphics Processing Unit (GPU), Masking and Rounding for FILL Command parameters. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-memory-transfer-commands

  10. ^ psx-spx. Graphics Processing Unit (GPU), GP0(02h) FillVram. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-versions

  11. ^ a b psx-spx. Graphics Processing Unit (GPU), VRAM to VRAM blitting - command 4 (100). https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-memory-transfer-commands

  12. ^ a b psx-spx. Graphics Processing Unit (GPU), CPU to VRAM blitting - command 5 (101). https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-memory-transfer-commands

  13. ^ a b psx-spx. Graphics Processing Unit (GPU), VRAM to CPU blitting - command 6 (110). https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-memory-transfer-commands

  14. ^ psx-spx. Graphics Processing Unit (GPU), Masking for COPY Commands parameters. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-memory-transfer-commands

  15. ^ a b psx-spx. Graphics Processing Unit (GPU), GPU Memory Transfer Commands, Notes. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-memory-transfer-commands

  16. ^ psx-spx. Graphics Processing Unit (GPU), GPU Memory Transfer Commands, Wrapping. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-memory-transfer-commands

  17. ^ psx-spx. Graphics Processing Unit (GPU), GPU Render Rectangle Commands, Note. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-render-rectangle-commands

  18. ^ psx-spx. Graphics Processing Unit (GPU), GP0(1Fh) - Interrupt Request (IRQ1). https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-other-commands

  19. ^ psx-spx. Graphics Processing Unit (GPU), GP0(00h) - NOP (?). https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-other-commands

  20. ^ psx-spx. Graphics Processing Unit (GPU), GP0(04h..1Eh,E0h,E7h..EFh) - Mirrors of GP0(00h) - NOP (?). https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-other-commands

  21. ^ psx-spx. Graphics Processing Unit (GPU), GP0(03h) - Unknown?. https://psx-spx.consoledev.net/graphicsprocessingunitgpu/#gpu-other-commands

Categories: Hardware · GPU