Path: blob/21.2-virgl/src/gallium/drivers/svga/svga_pipe_gs.c
4570 views
/**********************************************************1* Copyright 2014 VMware, Inc. All rights reserved.2*3* Permission is hereby granted, free of charge, to any person4* obtaining a copy of this software and associated documentation5* files (the "Software"), to deal in the Software without6* restriction, including without limitation the rights to use, copy,7* modify, merge, publish, distribute, sublicense, and/or sell copies8* of the Software, and to permit persons to whom the Software is9* furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23**********************************************************/2425#include "draw/draw_context.h"26#include "util/u_inlines.h"27#include "util/u_memory.h"28#include "util/u_bitmask.h"29#include "tgsi/tgsi_parse.h"30#include "tgsi/tgsi_text.h"3132#include "svga_context.h"33#include "svga_cmd.h"34#include "svga_debug.h"35#include "svga_shader.h"36#include "svga_streamout.h"3738static void *39svga_create_gs_state(struct pipe_context *pipe,40const struct pipe_shader_state *templ)41{42struct svga_context *svga = svga_context(pipe);43struct svga_geometry_shader *gs = CALLOC_STRUCT(svga_geometry_shader);4445if (!gs)46return NULL;4748SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATEGS);4950gs->base.tokens = tgsi_dup_tokens(templ->tokens);5152/* Collect basic info that we'll need later:53*/54tgsi_scan_shader(gs->base.tokens, &gs->base.info);5556gs->draw_shader = draw_create_geometry_shader(svga->swtnl.draw, templ);5758gs->base.id = svga->debug.shader_id++;5960gs->generic_outputs = svga_get_generic_outputs_mask(&gs->base.info);6162/* check for any stream output declarations */63if (templ->stream_output.num_outputs) {64gs->base.stream_output = svga_create_stream_output(svga, &gs->base,65&templ->stream_output);66}6768SVGA_STATS_TIME_POP(svga_sws(svga));69return gs;70}717273static void74svga_bind_gs_state(struct pipe_context *pipe, void *shader)75{76struct svga_geometry_shader *gs = (struct svga_geometry_shader *)shader;77struct svga_context *svga = svga_context(pipe);7879svga->curr.user_gs = gs;80svga->dirty |= SVGA_NEW_GS;81}828384static void85svga_delete_gs_state(struct pipe_context *pipe, void *shader)86{87struct svga_context *svga = svga_context(pipe);88struct svga_geometry_shader *gs = (struct svga_geometry_shader *)shader;89struct svga_geometry_shader *next_gs;90struct svga_shader_variant *variant, *tmp;9192svga_hwtnl_flush_retry(svga);9394/* Start deletion from the original geometry shader state */95if (gs->base.parent != NULL)96gs = (struct svga_geometry_shader *)gs->base.parent;9798/* Free the list of geometry shaders */99while (gs) {100next_gs = (struct svga_geometry_shader *)gs->base.next;101102if (gs->base.stream_output != NULL)103svga_delete_stream_output(svga, gs->base.stream_output);104105draw_delete_geometry_shader(svga->swtnl.draw, gs->draw_shader);106107for (variant = gs->base.variants; variant; variant = tmp) {108tmp = variant->next;109110/* Check if deleting currently bound shader */111if (variant == svga->state.hw_draw.gs) {112SVGA_RETRY(svga, svga_set_shader(svga, SVGA3D_SHADERTYPE_GS, NULL));113svga->state.hw_draw.gs = NULL;114}115116svga_destroy_shader_variant(svga, variant);117}118119FREE((void *)gs->base.tokens);120FREE(gs);121gs = next_gs;122}123}124125126void127svga_init_gs_functions(struct svga_context *svga)128{129svga->pipe.create_gs_state = svga_create_gs_state;130svga->pipe.bind_gs_state = svga_bind_gs_state;131svga->pipe.delete_gs_state = svga_delete_gs_state;132}133134135