Field of the Invention
The present invention relates to graphics accelerators for use with digital computer systems, and more particularly to a logical component architecture and method of operation for a fast graphics accelerator chip.
Background of the Invention
Designers of computer systems continually strive to increase the performance of their systems through innovative system and semiconductor design. This is particularly true in the field of computer graphics systems, where a large amount of information must typically be processed and displayed to a user on a raster device. Raster devices use a rectangular matrix of individually addressable points called "pixels" which, when turned on or off, are used to display a picture on a standard computer monitor. Even for modest sized displays, the number of pixels can range from the hundreds of thousands to well into the millions.
To manipulate such a large number of pixels, graphics systems designers have developed special purpose graphics processors which are very efficient at drawing figures and moving, rotating, and scaling the image on the computer screen. These graphics processors work in cooperation with a computer system's existing central processing unit (CPU) and can relieve the CPU of many of the tasks it would normally be called upon to do when displaying information on a computer screen to a user. This offloading of some portion of the graphics processing functions from the CPU to a graphics processor can substantially increase the speed with which any particular computer system is able to process graphics information.
However, because the CPU and graphics processor are typically separate components within a computer system, they must communicate with each other through an intermediate data bus. The CPU typically sends information in the form of graphics commands and data to the graphics processor, which in turn interprets the commands and data and performs the appropriate graphics function in response. A graphics command is usually sent across the data bus by the CPU each time a graphics instruction is to be performed, along with the accompanying data for the instruction. If there are a large number of graphics instructions which are being sent from the CPU to the graphics processor, the amount of information sent across the data bus typically causes a bottleneck and slows down the overall performance of the system. Such a bottleneck can be reduced, and overall system speed therefore improved, by finding ways to reduce the amount of information sent across the data bus to the graphics processor by the CPU.
Therefore, there is a need to increase the speed of performing graphics operations in a computer system having a graphics processor by reducing the amount of information sent from the system CPU to the graphics processor. There is a further need to improve the efficiency of the graphics processor in terms of speed and memory usage when performing graphics commands.
Summary of the Invention
The present invention provides for a graphics accelerator chip which interprets instructions and data transferred from a microprocessor via an external data bus logically coupled to the microprocessor. A host logic interface buffers the information received from the microprocessor with an on-chip first-in first-out (FIFO) random-access memory (RAM) which has an address space mapped onto a contiguous sequential address space of the microprocessor. A state machine having a temporary memory receives and interprets instructions and data from the FIFO RAM, and routes them to a graphics register set which performs logical graphics operations based upon the graphics instructions and data. The temporary memory stores the last primitive command received, allowing the chip to perform multiple graphics operations where a primitive command is received from the microprocessor only once. A separate data bus from the host logic interface to the graphics register set enables direct access to the graphics registers from the microprocessor.
Brief Description of the Drawings
FIG. 1 is a schematic diagram of the logical components of a graphics accelerator chip according to the present invention.
FIG. 2 is a schematic diagram of the logical graphics processing components of a graphics accelerator chip according to the present invention.
FIG. 3 is a block diagram of the source and destination coordinates for a bit-block-transfer (BIT BLT) according to the present invention.
FIG. 4 is a block diagram of a DRAWSTRING graphics operation according to the present invention.
FIG. 5 is a block diagram illustrating a method of drawing a convex polygon with trapezoids according to the present invention.
FIG. 6 is a flow diagram of exchanging two pixel areas according to the present invention.
FIG. 7 is a block diagram of a horizontal flip of a pixel area according to the present invention.
FIG. 8 is a block diagram of a vertical flip of a pixel area according to the present invention.
FIG. 9 is a block diagram of a diagonal flip of a pixel area according to the present invention.
FIG. 10 is a block diagram of a 180.degree. rotation of a pixel area according to the present invention.
FIG. 11 is a block diagram of a 90.degree. rotation of equal blocks of a pixel area according to the present invention.
FIG. 12 is a block diagram of a 90.degree. rotation of unequal blocks of a pixel area according to the present invention.
Detailed Description of the Preferred Embodiments
A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by any one of the patent disclosure, as it appears in the Patent and Trademark Office patent files or records, but otherwise reserves all copyright rights whatsoever.
In the following detailed description of the preferred embodiments, reference is made to the accompanying drawings which form a part hereof, and in which is shown by way of illustration specific embodiments in which the invention may be practiced. It is to be understood that other embodiments may be utilized and structural changes may be made without departing from the scope of the present invention. Throughout this specification, reference is made to the 3GA Graphics Accelerator Preliminary Reference Manual, published by Artist Graphics, St. Paul, Minn., which is herein incorporated by reference.
The preferred embodiment of the present invention provides for a graphics accelerator chip which interprets instructions and data transferred from a microprocessor via an external data bus logically coupled to the microprocessor. A host logic interface buffers the information received from the microprocessor with a on-chip FIFO RAM which has an address space mapped onto a contiguous sequential address space of the microprocessor. A temporary memory stores the last primitive command received, allowing the chip to perform multiple graphics operations where a primitive command is received from the microprocessor only once.
FIG. 1 shows a schematic diagram of the logical components of a preferred graphics accelerator chip. A host logic block 103 provides a portion of the interface to a standard computer data bus. The computer data bus may include such busses as ISA, EISA, VL, PCI, and MCA type busses, but it will be recognized that other data busses may be used with the present invention without loss of generality. For the purposes of this disclosure it will be assumed the host personal computer (PC) bus connection 101 has an address line of 32 bits and a data line of 32 bits, but it will be recognized that other data widths for the address and data lines may be substituted by one of ordinary skill in the art. The host logic block 103 uses a decoder 105 to provide multiple successive address decodes for a FIFO RAM 115, which preferably is mapped into the PC address memory space. Assuming an address line which is 32 bits wide, the number of successive address locations decoded by the decoder 105 ranges from 2 to 2.sup.32 .
Having the write port 107 to the FIFO RAM 115 appear at successive PC address locations allows software running on the PC to use fast data transfer commands such as a REP MOV or a BLOCK MOVE command to move data from memory located on the PC to the FIFO RAM 115. When such fast data transfer commands are executed, they are typically executed through a burst transfer mode on the data bus. Burst transfers are normally part of a PC bus specification, and provide higher throughput than normal data transfer modes. Comparing burst transfer rates to non-burst transfer rates shows a significant performance improvement for burst operations. An example is given below in Table 1:
The burst transfer mode as given above shows a 50% performance improvement in the data transfer rate from the host PC microprocessor or memory to the FIFO RAM 115 of the graphics chip. The mapping of the FIFO RAM 115 address space onto successive address locations within PC memory allows the faster data bus burst transfer mode to be used with the present invention.
The PC microprocessor sends a combination of primitive commands and data to the graphics processor of the present invention. A primitive command is a binary pattern specifying a type of graphics operation to be performed by the graphics processor. Examples using hexadecimal values include, 0x82000000--draw a line, and 0x88000000--draw a trapezoid. A primitive command is also known as an operational code or OPCODE. A primitive register is a register located in the graphics processor, which, when written with a primitive command, causes the graphics processor to execute the specified primitive and perform the associated graphics operation.
A FIFO graphics engine 113 is responsible for routing primitive commands and data from the PC microprocessor and memory to the graphics registers 143. The preferred FIFO graphics engine 113 contains the FIFO RAM 115, a temporary storage location 119, a state machine 121, and a multiplexer (MUX) 123. The FIFO RAM 115 provides N storage locations, M bits wide. The temporary storage location 119 is used to hold a primitive command. The temporary storage location 119 is preferably implemented as a transistor flip-flop (FF) M bits wide, but it will be recognized that other implementations may be substituted by one of ordinary skill in the art without loss of generality. The preferred state machine 121 contains the logic to implement a data flow algorithm corresponding to the graphics commands that the graphics processor is able to perform. The MUX 123 allows the routing of data from the output port 117 of the FIFO RAM 115 or the temporary storage location 119 to the graphics registers 143. A MUX 129, controlled by control line 133, is used to route data from the FIFO graphics engine data output 125 or PC data line 109 to the graphics registers 143 via data bus 131. A MUX 139, controlled by control line 133, is used to route address information from the state machine address output 135 or PC address line 111 to the graphics registers 143 via address bus 141.
Prior implementations of graphics processors have, for example, used the following four steps to draw successive disconnected line segments:
1) Write a primitive command to a FIFO RAM;
2) Write a starting point to the FIFO RAM;
3) Write an ending point to the FIFO RAM; and
4) Return to step 1 for the next line segment.
The preferred embodiment of the present graphics processor uses the following four steps to draw successive disconnected line segments:
1) Write a primitive command to a FIFO RAM;
2) Write a starting point to the FIFO RAM;
3) Write an ending point to the FIFO RAM; and
4) Return to step 2 for the next line segment.
It will be noted that with the steps used with the present graphics processor, the primitive command is only sent once. In the case described above for drawing disconnected line segments, this process results in a net reduction of 25% in the number of data transfers from the PC microprocessor or memory to the graphics chip. The set of steps used with the present graphics processor can be generalized as follows:
1) Write a new primitive command to the FIFO RAM;
2) Write the geometry/data required for the primitive command;
3) If the next primitive command is the same as the previous primitive command return to step 2, otherwise return to step 1.
The preferred algorithm implemented in the state machine 121 in the FIFO graphics engine 113 is given below:
The preferred state machine algorithm given above enables software running on the PC to only send the primitive command when necessary.
Many graphics chips have a section of logic dedicated to computing the values required by graphics engines. Typical operations include line drawing and bit-block-transfers, commonly called BIT BLTS. BIT BLTS are typically used for scrolling and text drawing operations, among other uses.
The preferred graphics processor of the present invention uses the BIT BLT feature to provide a draw string function for drawing text that requires very little data be sent over the host PC bus to the graphics processor. A normal BIT BLT operation copies pixels in a rectangular fashion from one location in memory to another location, and requires as inputs the coordinates of a source point and the coordinates of a destination rectangle. As shown by bitmap A 301 in FIG. 3, the destination rectangle 303 is preferably specified by YOXO and Y1X1, also known as the opposing corners of the BLT. The destination rectangle 303 is tracked by the graphics engine 213 (shown in FIG. 2) as pixels are copied from the source rectangle 307 in bitmap B 305. The source point is specified by Y2X2, which defines the starting point of source pixels in the source rectangle 307.
For a BIT BLT operation, the preferred initialization routine of the present graphics processor computes the following:
PRIM'=PRIMITIVE ( =BIT ELT)
Y0'X0'=Y0X0
DX1=abs (X1-X0)
DY1=abs (Y1-Y0)
Y2'X2'=Y2X0
The computed information given above provides the data necessary for the graphics engine 213 to perform a BIT BLT operation. The initialization routine subsequently asserts GR.sub.-- ENABLE to start the BIT BLT operation.
The hardware drawstring function uses the Y2X2 graphics register shown in FIG. 2. Prior to using the drawstring function, an off-screen memory font bitmap has previously been cached. The font bitmap preferably is a rectangular array of characters, organized in J rows by K columns. The size in pixel coordinates of each cell is defined by the FONTHEIGHT and FONTWIDTH GRAPHICS REGISTERS shown in FIG. 2. The drawstring function preferably defines two character codes in the redefined Y2X2 GRAPHICS REGISTER as follows:
FX1=font table x index for character 1
FY1=font table y index for character 1
DX1=amount to move right after drawing character 1
FX2=font table x index for character 2
FY2=font table y index for character 2
DX2=amount to move right after drawing character 2
or 0XFF if there is only a single character.
The initialization state machine algorithm for the drawstring graphics operation is given below:
As shown in FIG. 2, the preferred setup component 203 of the graphics processor of the present invention contains a state machine 205, and arithmetic logic unit (ALU) 207, and a temporary register TempXO 209.
To instruct the present graphics processor to perform a drawstring operation, the software running on the PC preferably uses the following five steps:
1) Write a drawstring command to the FIFO RAM 115;
2) Write Y0X0, which is the first opposing destination rectangle point;
3) Write Y1X1, which is the second opposing destination rectangle point;
4) Write a character code value for one or two characters in Y2X2;
5) Return to step 4 until the character string is drawn.
A graphical representation for a two character drawstring is shown in FIG. 4. The drawstring function uses multiple address decode operations to transfer data in burst mode from the PC microprocessor or memory to the FIFO RAM 115. The FIFO ENGINE 113 requires that only Y2X2 information be sent for each two characters to be drawn. The setup state machine 205 then typically processes each of these character codes to draw a horizontal string of characters.
The preferred embodiment of the present invention implements the fields widths of Y2X2 REGISTER as:
The FY1, FX1, FY2, FX2 values preferably realize a 16.times.16 square of characters with the character cell defined as given below in Table 2:
In order to provide smooth shading and give the appearance of an even graduation of colors on a shaded object, the preferred embodiment of the present invention uses dithering during the Gouraud shading process. Each pixel of a shaded object normally has a coordinate (Y,X) and a color value. The color value is preferably represented in a fixpoint notation such as fpI.fpF, where fpI is the integer portion of the color value and fpF is the fractional part of the color value. The value of fpI is the value that is written to display memory. Both fpI and fpF are preferably maintained internally in the present graphics processor in a storage location. As a shaded object is rendered, the color value for each (Y,X) coordinate is preferably calculated as V +VInc, where both V and VInc are in fpI.fpF format. An example using hexadecimal values is given below: ##EQU1##
In the non-dithered case, the resulting integer value of the ADD operation in the above example (e.g. "36") would be placed in memory. This may produce a visually undesirable effect of banding when drawing at 8 or 16 bits/pixel. Dithering is a technique for introducing "noise" into the above calculation. This noise essentially consists of an additional calculation performed after the ADD operation using the coordinates of the current pixel. The noise value may cause the integer portion of the post ADD value to be incremented (e.g. in the above example, 36 +1=37). Because the calculation is not random but based upon the pixel coordinates and the fractional portion of the color value, it is called an ordered Dither.
The preferred ordered dither algorithm uses the least significant bits of the X and Y coordinates for each pixel to be drawn. In the preferred graphics processor of the present invention, the least significant two bits are used to create a matrix value as given below in Table 3:
The matrix value is preferably compared to the fractional portion of the post ADD color value from the interpolator logic. If the matrix value is greater than the post ADD fractional value, the post ADD integer value is incremented as shown below:
This process produces a marked smoothing effect of the shaded image most noticeable at 8 and 16 bits/pixel.
A well-known method of drawing polygons using spans is called an edge coherence algorithm. This is described in Computer Graphics: Principles and Practice, 2nd edition, by James D. Foley, Andries van Dam, Steven K. Feiner, and John F. Hughes, 1990, Addison-Wesley, pp. 92-99, which is herein incorporation by reference. An advantage of this algorithm is that all of the pixels in a span can be processed together by the underlying hardware. The present invention provides an improved method by drawing the polygon with trapezoids, which can be easily implemented in hardware.
The preferred polygon drawing method of the present invention draws a convex polygon by breaking it up into trapezoids which have a flat (horizontal) bottom and top, using hardware that draws trapezoids. The method utilizes the slope of the sides of each trapezoid. It will be recognized that this method may be extended by one of ordinary skill in the art to Gouraud shaded (smooth shaded), z-buffered, and texture mapped polygons without loss of generality.
As shown in FIG. 5., the preferred polygon drawing method of the present invention begins at a topmost vertex (lowest y-value), and checks an array of vertices representing the polygon for a next left and right vertices. Each trapezoid may be divided into one of three cases:1) the left and right vertices are at the same level, 2) the right vertex is higher than the left vertex, or 3) the left vertex is higher than the right vertex. It will be recognized that although the terms "left" and "right" are used in this description, they apply only if the array of vertices is given in a clockwise order. If the polygon is given by an array of vertices in counter-clockwise order, left and right are reversed. It will also be recognized that reversal of the directions of left and right for vertices in counter-clockwise order is not necessary if the underlying hardware implementation of drawing trapezoids is not direction sensitive.
The preferred polygon drawing method of the present invention uses the following hardware functions:
1. Draw.sub.-- Span (x0, x1, y0). This function draws a horizontal line from (x0, y0) to (x1, y0).
2. Draw.sub.-- Trap (x0, x1, dx0, dx1, y0, y1). This function draws a trapezoid with flat top and bottom, where "y0" and "y1" are the starting and ending y value, "x0" and "x1" are the starting coordinates for the sides (at "y0"), and "dx0" and "dx1" are the slopes of the sides.
3. Draw.sub.-- Poly (dx0, dx1, y1). This function draws another trapezoid, continuing after the ending y coordinate of the previous Draw.sub.-- Trap or Draw.sub.-- Poly, with new side slopes dx0 and dx1, and new ending y1.
The preferred polygon drawing method of the present invention is given below in pseudo-code:
The preferred embodiment of the present graphics processor also implements a method which flips or rotates bitmaps in place within a frame buffer, without using extra memory. It will be recognized that this method may be implemented by one of ordinary skill with any computer processor which can perform raster operations with logical functions. The method is based upon a technique of exchanging the values of two memory locations using three exclusive-or (XOR) logical operations. The truth table for a logical XOR operation is given below in Table 4:
For example, to exchange the values of two variables A and B, the following method performs the exchange without using a intermediate storage variable:
Step 1. A=A XOR B.
Contents of A after this step: A XOR B.
Step 2. B=A XOR B
Contents of B after this step: B XOR A XOR B, which simplifies to A.
Step 3. A=A XOR B
Contents of A after this: A XOR B XOR A, which simplifies to B.
As shown in FIG. 7., the preferred horizontal flip method of the present invention first divides a rectangular bitmap which is to be flipped into two areas A and B. FIG. 7 uses the number 0-3 to designate corners of the areas A and B which line up with each other. Second, B is copied onto A using texture mapping and the XOR logical raster operation, then A is copied onto B using XOR, and finally B is copied onto A again using XOR.
A raster operation is a typical function in many graphics processors which applies a logical combination of source pixel, destination pixel, and a pattern. The XOR raster operation referenced above is applied as: DEST XOR SOURCE. Texture mapping is a further operation that typically copies pixanother arbitrary pol polygon to another arbitrary polygon, distorting the pixels as needed to match the destination polygon. The areas A and B chosen in the method given above must be in one-to-one correspondence to ensure that pixels are not lost during the flip operation.
FIG. 6 gives a general program flow of a bitmap flip method of the present invention. At 601, the bitmap is divided into polygons A and B, and at 603 the raster operation is set to XOR. At 605, A is copied to B, at 607 B is copied to A, and at 609 A is copied back to B.
FIG. 7 shows the rectangles to use for a horizontal flip, and FIG. 8 shows the rectangles for a vertical flip. It will be noted that if the width (or the height, for vertical flip) is odd, there is a column (or row) of pixels that do not need to be moved. The number of pixels that have to be moved with this method is typically 1.5 times the number of pixels in the region, minus the height (or width) if the width (or height) is odd. A traditional method of flipping a bitmap using off-screen memory requires that two times the number of pixels in the bitmap be moved.
A diagonal flip of a bitmap region may be performed with three triangular texture mappings as shown in FIG. 9. It will be noted that the bitmap region is required to be square, and that the pixels on the diagonal do not need to be moved. The number of pixels that have to be moved with this method is typically 1.5 times the number of pixels in the region, minus the width. The traditional method of flipping a bitmap using off-screen memory requires that two times the number of pixels in the bitmap be moved.
A 180.degree. rotation of a bitmap region may be performed in a manner very similar to that of a vertical flip, as shown in FIG. 10. It will be noted that the order of the vertices of the corners of areas A and B is different from that shown in FIG. 8 for a vertical flip, and that if the height of the bitmap area is odd, then the middle row of pixels is required to be flipped left to right. As with a vertical flip, the number of pixels that have to be moved with this method is typically 1.5 times the number of pixels in the region.
A simple way to perform a 90.degree. rotation of a bitmap region is to perform a diagonal flip followed by a horizontal or vertical flip. A 90.degree. right rotation (clockwise) is performed with diagonal flip and then a horizontal flip, and a 90.degree. left rotation (counter clockwise) is performed with a diagonal flip and then a vertical flip. It will be noted that the bitmap region is required to be square. However, this method of rotating moves approximately three times the number of pixels in the region, which is not efficient. An improved way to rotate a region by 90.degree. with the present invention is given in FIG. 11. The bitmap region is divided into four rectangles, which are swapped in pairs using three XOR texture mappings. FIG. 6 shows the polygons used for the method. This preferred requires that approximately 2.25 times the number of pixels be moved, which, while not quite as fast as using off-screen memory, saves the use of off-screen memory without sacrificing much additional time. The swap sequence for a 90.degree. left rotation is swap A and B, then swap B and C, and finally swap C and D. The order is reversed for a right rotation.
If the width of the region is odd, then an extra column and a row are left over that may be handled by selecting the four areas as shown in FIG. 12. It will be noted that there is one pixel in the middle of the bitmap regions which does not need to be moved.
The present invention is to be limited only in accordance with the scope of the appended claims, since others skilled in the art may devise other embodiments still within the limits of the claims.