Path: blob/21.2-virgl/src/gallium/drivers/softpipe/sp_state_so.c
4570 views
/**************************************************************************1*2* Copyright 2010 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "sp_context.h"28#include "sp_state.h"29#include "sp_texture.h"3031#include "util/format/u_format.h"32#include "util/u_memory.h"33#include "draw/draw_context.h"34#include "pipebuffer/pb_buffer.h"3536static struct pipe_stream_output_target *37softpipe_create_so_target(struct pipe_context *pipe,38struct pipe_resource *buffer,39unsigned buffer_offset,40unsigned buffer_size)41{42struct draw_so_target *t;4344t = CALLOC_STRUCT(draw_so_target);45t->target.context = pipe;46t->target.reference.count = 1;47pipe_resource_reference(&t->target.buffer, buffer);48t->target.buffer_offset = buffer_offset;49t->target.buffer_size = buffer_size;50return &t->target;51}5253static void54softpipe_so_target_destroy(struct pipe_context *pipe,55struct pipe_stream_output_target *target)56{57pipe_resource_reference(&target->buffer, NULL);58FREE(target);59}6061static void62softpipe_set_so_targets(struct pipe_context *pipe,63unsigned num_targets,64struct pipe_stream_output_target **targets,65const unsigned *offsets)66{67struct softpipe_context *softpipe = softpipe_context(pipe);68unsigned i;6970for (i = 0; i < num_targets; i++) {71pipe_so_target_reference((struct pipe_stream_output_target **)&softpipe->so_targets[i], targets[i]);7273if (targets[i]) {74void *buf = softpipe_resource(targets[i]->buffer)->data;75softpipe->so_targets[i]->mapping = buf;76}77}7879for (; i < softpipe->num_so_targets; i++) {80pipe_so_target_reference((struct pipe_stream_output_target **)&softpipe->so_targets[i], NULL);81}8283softpipe->num_so_targets = num_targets;8485draw_set_mapped_so_targets(softpipe->draw, softpipe->num_so_targets,86softpipe->so_targets);87}8889void90softpipe_init_streamout_funcs(struct pipe_context *pipe)91{92pipe->create_stream_output_target = softpipe_create_so_target;93pipe->stream_output_target_destroy = softpipe_so_target_destroy;94pipe->set_stream_output_targets = softpipe_set_so_targets;95}969798