glamor: Change to use system memory for write only access.

If the pixmap is write-only, then use a pbo mapping will not
get too much benefit. And even worse, when the software
rendering is access this mapped data range, it's much slower
than just using a system memory. From the glamor_prepare_access
glamor_finish_access view, we have two options here:

option 1:
1.0 create a pbo
1.1 copy texture to the pbo
1.2 map the pbo to va
1.3 access the va directly in software rendering.
1.4 bind the pbo as unpack buffer & draw it back to texture.

option 2:
2.0 allocate a block memory in system memory space.
2.1 read the texture memory to the system memory.
2.2 access the system memory and do rendering.
2.3 draw the system memory back to texture.

In general, 1.1 plush 1.2 is much faster than 2.1.
And 1.3 is slower than 2.2. 1.4 is faster than 2.3.

If the access mode is read only or read write, option 1
may be fater, but if the access mode is write only. Then
most of the time option 1 is much faster.

Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
This commit is contained in:
Zhigang Gong 2011-06-28 14:37:29 +08:00
parent 4afa9e4080
commit 9e4567afe6

View File

@ -387,15 +387,23 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access)
}
pixmap_priv->access_mode = access;
glamor_debug_output(GLAMOR_DEBUG_TEXTURE_DOWNLOAD,
"Downloading pixmap %p %dx%d depth%d\n",
pixmap,
pixmap->drawable.width,
pixmap->drawable.height,
pixmap->drawable.depth);
stride = pixmap->devKind;
switch (access) {
case GLAMOR_ACCESS_RO:
gl_access = GL_READ_ONLY_ARB;
gl_usage = GL_STREAM_READ_ARB;
break;
case GLAMOR_ACCESS_WO:
gl_access = GL_WRITE_ONLY_ARB;
gl_usage = GL_STREAM_DRAW_ARB;
data = malloc(stride * pixmap->drawable.height);
goto done;
break;
case GLAMOR_ACCESS_RW:
gl_access = GL_READ_WRITE_ARB;
@ -405,15 +413,7 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access)
ErrorF("Glamor: Invalid access code. %d\n", access);
assert(0);
}
glamor_debug_output(GLAMOR_DEBUG_TEXTURE_DOWNLOAD,
"Downloading pixmap %p %dx%d depth%d\n",
pixmap,
pixmap->drawable.width,
pixmap->drawable.height,
pixmap->drawable.depth);
stride = pixmap->devKind;
row_length = (stride * 8) / pixmap->drawable.bitsPerPixel;
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, pixmap_priv->fb);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
@ -429,8 +429,7 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access)
glBufferDataARB (GL_PIXEL_PACK_BUFFER_EXT,
stride * pixmap->drawable.height,
NULL, gl_usage);
if (access != GLAMOR_ACCESS_WO)
glReadPixels (0, 0,
glReadPixels (0, 0,
row_length, pixmap->drawable.height,
format, type, 0);
data = glMapBufferARB (GL_PIXEL_PACK_BUFFER_EXT, gl_access);
@ -438,7 +437,7 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access)
if (!glamor_priv->yInverted)
glPixelStorei(GL_PACK_INVERT_MESA, 0);
glBindBufferARB (GL_PIXEL_PACK_BUFFER_EXT, 0);
} else {
data = malloc(stride * pixmap->drawable.height);
assert(data);
@ -465,6 +464,7 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access)
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
done:
pixmap->devPrivate.ptr = data;
return TRUE;
}