Path: blob/21.2-virgl/src/gallium/drivers/virgl/virgl_streamout.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*/22#include "util/u_inlines.h"23#include "util/u_memory.h"24#include "virgl_context.h"25#include "virgl_encode.h"26#include "virtio-gpu/virgl_protocol.h"27#include "virgl_resource.h"2829static struct pipe_stream_output_target *virgl_create_so_target(30struct pipe_context *ctx,31struct pipe_resource *buffer,32unsigned buffer_offset,33unsigned buffer_size)34{35struct virgl_context *vctx = virgl_context(ctx);36struct virgl_resource *res = virgl_resource(buffer);37struct virgl_so_target *t = CALLOC_STRUCT(virgl_so_target);38uint32_t handle;3940if (!t)41return NULL;42handle = virgl_object_assign_handle();4344t->base.reference.count = 1;45t->base.context = ctx;46pipe_resource_reference(&t->base.buffer, buffer);47t->base.buffer_offset = buffer_offset;48t->base.buffer_size = buffer_size;49t->handle = handle;5051res->bind_history |= PIPE_BIND_STREAM_OUTPUT;52util_range_add(&res->b, &res->valid_buffer_range, buffer_offset,53buffer_offset + buffer_size);54virgl_resource_dirty(res, 0);5556virgl_encoder_create_so_target(vctx, handle, res, buffer_offset, buffer_size);57return &t->base;58}5960static void virgl_destroy_so_target(struct pipe_context *ctx,61struct pipe_stream_output_target *target)62{63struct virgl_context *vctx = virgl_context(ctx);64struct virgl_so_target *t = virgl_so_target(target);6566pipe_resource_reference(&t->base.buffer, NULL);67virgl_encode_delete_object(vctx, t->handle, VIRGL_OBJECT_STREAMOUT_TARGET);68FREE(t);69}7071static void virgl_set_so_targets(struct pipe_context *ctx,72unsigned num_targets,73struct pipe_stream_output_target **targets,74const unsigned *offset)75{76struct virgl_context *vctx = virgl_context(ctx);77int i;78for (i = 0; i < num_targets; i++) {79if (targets[i]) {80struct virgl_winsys *vws = virgl_screen(vctx->base.screen)->vws;81struct virgl_resource *res = virgl_resource(targets[i]->buffer);8283pipe_resource_reference(&vctx->so_targets[i].base.buffer, targets[i]->buffer);8485vws->emit_res(vws, vctx->cbuf, res->hw_res, FALSE);86} else {87pipe_resource_reference(&vctx->so_targets[i].base.buffer, NULL);88}89}90for (i = num_targets; i < vctx->num_so_targets; i++)91pipe_resource_reference(&vctx->so_targets[i].base.buffer, NULL);92vctx->num_so_targets = num_targets;93virgl_encoder_set_so_targets(vctx, num_targets, targets, 0);//append_bitmask);94}9596void virgl_init_so_functions(struct virgl_context *vctx)97{98vctx->base.create_stream_output_target = virgl_create_so_target;99vctx->base.stream_output_target_destroy = virgl_destroy_so_target;100vctx->base.set_stream_output_targets = virgl_set_so_targets;101}102103104