• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014, 2015 Red Hat.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include "util/u_inlines.h"
25 #include "util/u_memory.h"
26 #include "virgl_context.h"
27 #include "virgl_encode.h"
28 #include "virgl_resource.h"
29 #include "virgl_screen.h"
30 
virgl_buffer_transfer_unmap(struct pipe_context * ctx,struct pipe_transfer * transfer)31 void virgl_buffer_transfer_unmap(struct pipe_context *ctx,
32                                  struct pipe_transfer *transfer)
33 {
34    struct virgl_context *vctx = virgl_context(ctx);
35    struct virgl_transfer *trans = virgl_transfer(transfer);
36    bool persistent_coherent = trans->base.usage & (PIPE_MAP_PERSISTENT |
37                                                    PIPE_MAP_COHERENT);
38 
39    if ((trans->base.usage & PIPE_MAP_WRITE) && !persistent_coherent) {
40       if (transfer->usage & PIPE_MAP_FLUSH_EXPLICIT) {
41          if (trans->range.end <= trans->range.start) {
42             virgl_resource_destroy_transfer(vctx, trans);
43             return;
44          }
45 
46          transfer->box.x += trans->range.start;
47          transfer->box.width = trans->range.end - trans->range.start;
48          trans->offset = transfer->box.x;
49       }
50 
51       if (trans->copy_src_hw_res && trans->direction == VIRGL_TRANSFER_TO_HOST) {
52          virgl_encode_copy_transfer(vctx, trans);
53          virgl_resource_destroy_transfer(vctx, trans);
54       } else if (trans->copy_src_hw_res && trans->direction == VIRGL_TRANSFER_FROM_HOST) {
55          // if it is readback, then we have already encoded transfer
56          virgl_resource_destroy_transfer(vctx, trans);
57       } else {
58          virgl_transfer_queue_unmap(&vctx->queue, trans);
59       }
60    } else
61       virgl_resource_destroy_transfer(vctx, trans);
62 }
63 
virgl_buffer_transfer_flush_region(struct pipe_context * ctx,struct pipe_transfer * transfer,const struct pipe_box * box)64 void virgl_buffer_transfer_flush_region(struct pipe_context *ctx,
65                                         struct pipe_transfer *transfer,
66                                         const struct pipe_box *box)
67 {
68    struct virgl_transfer *trans = virgl_transfer(transfer);
69 
70    /*
71     * FIXME: This is not optimal.  For example,
72     *
73     * glMapBufferRange(.., 0, 100, GL_MAP_FLUSH_EXPLICIT_BIT)
74     * glFlushMappedBufferRange(.., 25, 30)
75     * glFlushMappedBufferRange(.., 65, 70)
76     *
77     * We'll end up flushing 25 --> 70.
78     */
79    util_range_add(transfer->resource, &trans->range, box->x, box->x + box->width);
80 }
81 
virgl_buffer_init(struct virgl_resource * res)82 void virgl_buffer_init(struct virgl_resource *res)
83 {
84 }
85