svga: Avoid bouncing buffer data in malloced buffers

Some constant- and texture upload buffer data may bounce in malloced
buffers before being transferred to hardware buffers. In the case of
texture upload buffers this seems to be an oversight. In the case of
constant buffers, code comments indicate that we want to avoid mapping
hardware buffers for reading when copying out of buffers that need
modification before being passed to hardware. In this case we avoid
data bouncing for upload manager buffers but make sure buffers that
we read out from stay in malloced memory.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Thomas Hellstrom
2019-04-02 12:36:34 +02:00
parent 5961189f4e
commit 978d66e4d5
3 changed files with 36 additions and 13 deletions
+2 -1
View File
@@ -230,7 +230,8 @@ svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags)
svga->const0_upload = u_upload_create(&svga->pipe,
CONST0_UPLOAD_DEFAULT_SIZE,
PIPE_BIND_CONSTANT_BUFFER,
PIPE_BIND_CONSTANT_BUFFER |
PIPE_BIND_CUSTOM,
PIPE_USAGE_STREAM, 0);
if (!svga->const0_upload)
goto cleanup;
+33 -11
View File
@@ -42,16 +42,37 @@
/**
* Vertex and index buffers need hardware backing. Constant buffers
* do not. No other types of buffers currently supported.
* Determine what buffers eventually need hardware backing.
*
* Vertex- and index buffers need hardware backing. Constant buffers
* do on vgpu10. Staging texture-upload buffers do when they are
* supported.
*/
static inline boolean
svga_buffer_needs_hw_storage(unsigned usage)
svga_buffer_needs_hw_storage(const struct svga_screen *ss,
const struct pipe_resource *template)
{
return (usage & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER |
PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_STREAM_OUTPUT)) != 0;
}
unsigned bind_mask = (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER |
PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_STREAM_OUTPUT);
if (ss->sws->have_vgpu10) {
/*
* Driver-created upload const0- and staging texture upload buffers
* tagged with PIPE_BIND_CUSTOM
*/
bind_mask |= PIPE_BIND_CUSTOM;
/* Uniform buffer objects.
* Make sure we don't create hardware storage for state-tracker
* const0 buffers, because we frequently map them for reading.
* They are distinguished by having PIPE_USAGE_STREAM, but not
* PIPE_BIND_CUSTOM.
*/
if (template->usage != PIPE_USAGE_STREAM)
bind_mask |= PIPE_BIND_CONSTANT_BUFFER;
}
return !!(template->bind & bind_mask);
}
/**
* Create a buffer transfer.
@@ -411,7 +432,7 @@ svga_buffer_create(struct pipe_screen *screen,
sbuf->b.vtbl = &svga_buffer_vtbl;
pipe_reference_init(&sbuf->b.b.reference, 1);
sbuf->b.b.screen = screen;
bind_flags = template->bind;
bind_flags = template->bind & ~PIPE_BIND_CUSTOM;
LIST_INITHEAD(&sbuf->surfaces);
@@ -430,7 +451,7 @@ svga_buffer_create(struct pipe_screen *screen,
*/
sbuf->b.b.width0 = align(sbuf->b.b.width0, 16);
if (svga_buffer_needs_hw_storage(bind_flags)) {
if (svga_buffer_needs_hw_storage(ss, template)) {
/* If the buffer is not used for constant buffer, set
* the vertex/index bind flags as well so that the buffer will be
@@ -442,9 +463,10 @@ svga_buffer_create(struct pipe_screen *screen,
* bind flag since streamout buffer is an output buffer and
* might have performance implication.
*/
if (!(template->bind & PIPE_BIND_CONSTANT_BUFFER)) {
/* Not a constant buffer. The buffer may be used for vertex data
* or indexes.
if (!(template->bind & PIPE_BIND_CONSTANT_BUFFER) &&
!(template->bind & PIPE_BIND_CUSTOM)) {
/* Not a constant- or staging buffer.
* The buffer may be used for vertex data or indexes.
*/
bind_flags |= (PIPE_BIND_VERTEX_BUFFER |
PIPE_BIND_INDEX_BUFFER);
@@ -1335,7 +1335,7 @@ boolean
svga_texture_transfer_map_upload_create(struct svga_context *svga)
{
svga->tex_upload = u_upload_create(&svga->pipe, TEX_UPLOAD_DEFAULT_SIZE,
0, PIPE_USAGE_STAGING, 0);
PIPE_BIND_CUSTOM, PIPE_USAGE_STAGING, 0);
return svga->tex_upload != NULL;
}