Path: blob/21.2-virgl/src/gallium/drivers/virgl/virgl_buffer.c
4570 views
/*1* Copyright 2014, 2015 Red Hat.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223#include "util/u_inlines.h"24#include "util/u_memory.h"25#include "virgl_context.h"26#include "virgl_encode.h"27#include "virgl_resource.h"28#include "virgl_screen.h"2930void virgl_buffer_transfer_unmap(struct pipe_context *ctx,31struct pipe_transfer *transfer)32{33struct virgl_context *vctx = virgl_context(ctx);34struct virgl_transfer *trans = virgl_transfer(transfer);35bool persistent_coherent = trans->base.usage & (PIPE_MAP_PERSISTENT |36PIPE_MAP_COHERENT);3738if ((trans->base.usage & PIPE_MAP_WRITE) && !persistent_coherent) {39if (transfer->usage & PIPE_MAP_FLUSH_EXPLICIT) {40if (trans->range.end <= trans->range.start) {41virgl_resource_destroy_transfer(vctx, trans);42return;43}4445transfer->box.x += trans->range.start;46transfer->box.width = trans->range.end - trans->range.start;47trans->offset = transfer->box.x;48}4950if (trans->copy_src_hw_res) {51virgl_encode_copy_transfer(vctx, trans);52virgl_resource_destroy_transfer(vctx, trans);53} else {54virgl_transfer_queue_unmap(&vctx->queue, trans);55}56} else57virgl_resource_destroy_transfer(vctx, trans);58}5960void virgl_buffer_transfer_flush_region(struct pipe_context *ctx,61struct pipe_transfer *transfer,62const struct pipe_box *box)63{64struct virgl_transfer *trans = virgl_transfer(transfer);6566/*67* FIXME: This is not optimal. For example,68*69* glMapBufferRange(.., 0, 100, GL_MAP_FLUSH_EXPLICIT_BIT)70* glFlushMappedBufferRange(.., 25, 30)71* glFlushMappedBufferRange(.., 65, 70)72*73* We'll end up flushing 25 --> 70.74*/75util_range_add(transfer->resource, &trans->range, box->x, box->x + box->width);76}7778void virgl_buffer_init(struct virgl_resource *res)79{80}818283