101e04c3fSmrg/* 201e04c3fSmrg * Copyright 2014, 2015 Red Hat. 301e04c3fSmrg * 401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 501e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 601e04c3fSmrg * to deal in the Software without restriction, including without limitation 701e04c3fSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub 801e04c3fSmrg * license, and/or sell copies of the Software, and to permit persons to whom 901e04c3fSmrg * the Software is furnished to do so, subject to the following conditions: 1001e04c3fSmrg * 1101e04c3fSmrg * The above copyright notice and this permission notice (including the next 1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1301e04c3fSmrg * Software. 1401e04c3fSmrg * 1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 1801e04c3fSmrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 1901e04c3fSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2001e04c3fSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2101e04c3fSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 2201e04c3fSmrg */ 2301e04c3fSmrg 2401e04c3fSmrg#include "util/u_inlines.h" 2501e04c3fSmrg#include "util/u_memory.h" 2601e04c3fSmrg#include "virgl_context.h" 277ec681f3Smrg#include "virgl_encode.h" 2801e04c3fSmrg#include "virgl_resource.h" 2901e04c3fSmrg#include "virgl_screen.h" 3001e04c3fSmrg 317ec681f3Smrgvoid virgl_buffer_transfer_unmap(struct pipe_context *ctx, 327ec681f3Smrg struct pipe_transfer *transfer) 3301e04c3fSmrg{ 3401e04c3fSmrg struct virgl_context *vctx = virgl_context(ctx); 3501e04c3fSmrg struct virgl_transfer *trans = virgl_transfer(transfer); 367ec681f3Smrg bool persistent_coherent = trans->base.usage & (PIPE_MAP_PERSISTENT | 377ec681f3Smrg PIPE_MAP_COHERENT); 3801e04c3fSmrg 397ec681f3Smrg if ((trans->base.usage & PIPE_MAP_WRITE) && !persistent_coherent) { 407ec681f3Smrg if (transfer->usage & PIPE_MAP_FLUSH_EXPLICIT) { 419f464c52Smaya if (trans->range.end <= trans->range.start) { 427ec681f3Smrg virgl_resource_destroy_transfer(vctx, trans); 439f464c52Smaya return; 449f464c52Smaya } 459f464c52Smaya 469f464c52Smaya transfer->box.x += trans->range.start; 479f464c52Smaya transfer->box.width = trans->range.end - trans->range.start; 489f464c52Smaya trans->offset = transfer->box.x; 4901e04c3fSmrg } 5001e04c3fSmrg 517ec681f3Smrg if (trans->copy_src_hw_res) { 527ec681f3Smrg virgl_encode_copy_transfer(vctx, trans); 537ec681f3Smrg virgl_resource_destroy_transfer(vctx, trans); 547ec681f3Smrg } else { 557ec681f3Smrg virgl_transfer_queue_unmap(&vctx->queue, trans); 567ec681f3Smrg } 579f464c52Smaya } else 587ec681f3Smrg virgl_resource_destroy_transfer(vctx, trans); 5901e04c3fSmrg} 6001e04c3fSmrg 617ec681f3Smrgvoid virgl_buffer_transfer_flush_region(struct pipe_context *ctx, 627ec681f3Smrg struct pipe_transfer *transfer, 637ec681f3Smrg const struct pipe_box *box) 6401e04c3fSmrg{ 659f464c52Smaya struct virgl_transfer *trans = virgl_transfer(transfer); 6601e04c3fSmrg 679f464c52Smaya /* 689f464c52Smaya * FIXME: This is not optimal. For example, 699f464c52Smaya * 709f464c52Smaya * glMapBufferRange(.., 0, 100, GL_MAP_FLUSH_EXPLICIT_BIT) 719f464c52Smaya * glFlushMappedBufferRange(.., 25, 30) 729f464c52Smaya * glFlushMappedBufferRange(.., 65, 70) 739f464c52Smaya * 749f464c52Smaya * We'll end up flushing 25 --> 70. 759f464c52Smaya */ 767ec681f3Smrg util_range_add(transfer->resource, &trans->range, box->x, box->x + box->width); 7701e04c3fSmrg} 7801e04c3fSmrg 799f464c52Smayavoid virgl_buffer_init(struct virgl_resource *res) 8001e04c3fSmrg{ 8101e04c3fSmrg} 82