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