gallium: use MAP_DIRECTLY to mean supression of DISCARD in buffer_subdata

This is needed to fix an issue with OpenGL when a buffer is mapped and
BufferSubData is called. In this case, we can't invalidate the buffer range.
This commit is contained in:
Marek Olšák 2019-07-03 18:51:24 -04:00
parent 5e76c99923
commit fc4302d1df
6 changed files with 34 additions and 21 deletions

View file

@ -1630,8 +1630,11 @@ tc_buffer_subdata(struct pipe_context *_pipe,
if (!size)
return;
usage |= PIPE_TRANSFER_WRITE |
PIPE_TRANSFER_DISCARD_RANGE;
usage |= PIPE_TRANSFER_WRITE;
/* PIPE_TRANSFER_MAP_DIRECTLY supresses implicit DISCARD_RANGE. */
if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY))
usage |= PIPE_TRANSFER_DISCARD_RANGE;
usage = tc_improve_map_buffer_flags(tc, tres, usage, offset, size);

View file

@ -18,11 +18,15 @@ void u_default_buffer_subdata(struct pipe_context *pipe,
/* the write flag is implicit by the nature of buffer_subdata */
usage |= PIPE_TRANSFER_WRITE;
/* buffer_subdata implicitly discards the rewritten buffer range */
if (offset == 0 && size == resource->width0) {
usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
} else {
usage |= PIPE_TRANSFER_DISCARD_RANGE;
/* buffer_subdata implicitly discards the rewritten buffer range.
* PIPE_TRANSFER_MAP_DIRECTLY supresses that.
*/
if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY)) {
if (offset == 0 && size == resource->width0) {
usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
} else {
usage |= PIPE_TRANSFER_DISCARD_RANGE;
}
}
u_box_1d(offset, size, &box);

View file

@ -545,12 +545,13 @@ void r600_buffer_subdata(struct pipe_context *ctx,
struct pipe_box box;
uint8_t *map = NULL;
usage |= PIPE_TRANSFER_WRITE;
if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY))
usage |= PIPE_TRANSFER_DISCARD_RANGE;
u_box_1d(offset, size, &box);
map = r600_buffer_transfer_map(ctx, buffer, 0,
PIPE_TRANSFER_WRITE |
PIPE_TRANSFER_DISCARD_RANGE |
usage,
&box, &transfer);
map = r600_buffer_transfer_map(ctx, buffer, 0, usage, &box, &transfer);
if (!map)
return;

View file

@ -637,12 +637,13 @@ static void si_buffer_subdata(struct pipe_context *ctx,
struct pipe_box box;
uint8_t *map = NULL;
usage |= PIPE_TRANSFER_WRITE;
if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY))
usage |= PIPE_TRANSFER_DISCARD_RANGE;
u_box_1d(offset, size, &box);
map = si_buffer_transfer_map(ctx, buffer, 0,
PIPE_TRANSFER_WRITE |
PIPE_TRANSFER_DISCARD_RANGE |
usage,
&box, &transfer);
map = si_buffer_transfer_map(ctx, buffer, 0, usage, &box, &transfer);
if (!map)
return;

View file

@ -588,10 +588,12 @@ static void virgl_buffer_subdata(struct pipe_context *pipe,
/* the write flag is implicit by the nature of buffer_subdata */
usage |= PIPE_TRANSFER_WRITE;
if (offset == 0 && size == resource->width0)
usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
else
usage |= PIPE_TRANSFER_DISCARD_RANGE;
if (!(usage & PIPE_TRANSFER_MAP_DIRECTLY)) {
if (offset == 0 && size == resource->width0)
usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
else
usage |= PIPE_TRANSFER_DISCARD_RANGE;
}
u_box_1d(offset, size, &box);

View file

@ -261,6 +261,8 @@ enum pipe_transfer_usage
* E.g. the state tracker could have a simpler path which maps textures and
* does read/modify/write cycles on them directly, and a more complicated
* path which uses minimal read and write transfers.
*
* This flag supresses implicit "DISCARD" for buffer_subdata.
*/
PIPE_TRANSFER_MAP_DIRECTLY = (1 << 2),