Graphics Reference
In-Depth Information
using glReadBuffer() . Unfortunately, reading buffers from GPU memory is usually a
very slow operation, making buffer readbacks unappealing. There are several reasons
these operations are slow. To read data back, all operations in the graphics pipeline
must be completed, and no rendering to the read area can be allowed while the read
is in progress. Effectively, the rendering pipeline stalls during the readback. In addi-
tion, because a GPU is primarily an output device bus transfer is usually optimized
for sending data to the card (not for fetching data back). Finally, once the data arrives
back in main memory the data might additionally need massaging by the driver to
match the desired format specified in the read request. If buffer readbacks are used,
it is therefore important to try to reduce both the number of readbacks issued and
the amount of data read back.
Some have suggested using histogram queries to get data back from the GPU, such
as through the OpenGL extension EXT_histogram [Boyles99]. Unfortunately, even
when available histogram extensions are unlikely to be faster than buffer readbacks,
in that they are typically implemented as buffer readbacks in the graphics card driver
and are performed on the CPU (rather than being natively hardware accelerated).
Where available, one way of reducing the data readback is to trade fill rate for
transfer bandwidth by downsampling the transfer area to quarter size using bilinear
filtering. For example, assume the purpose of the readback is to detect the presence of
white (255, 255, 255) 24-bit pixels on an otherwise black (0, 0, 0) background. After one
round of downsampling, pixels can have values of (0, 0, 0), (64, 64, 64), (128, 128, 128),
or (191, 191, 191), assuming rounding to nearest value. Any nonblack pixels indicate a
white pixel present in the original image. In this scenario, the downsampling process
can be performed four times before the ability to discern white pixels in the original
image is lost (Figure 10.1). After four rounds of downsampling it is only necessary to
read back 1/256 of the original image to main memory, thereby greatly reducing the
time required to perform the transfer. Accumulating several downsampled buffers
— concatenated into a single contiguous area — before reading data back to main
memory also allows the number of readbacks to be reduced.
(1,1,1)
(4,4,4)
(16,16,16)
(64,64,64)
(255,255,255)
Figure 10.1 The presence of one or more white pixels on an otherwise black background
remains detectable after (at most) four bilinear downsampling passes of an image. Numbers
designate the RGB value of the nonblack pixel. Black pixels have an RGB value of (0,0,0).
 
Search WWH ::




Custom Search