Path: blob/21.2-virgl/src/gallium/drivers/svga/svga_pipe_fs.c
4570 views
/**********************************************************1* Copyright 2008-2009 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 "util/u_inlines.h"26#include "util/u_math.h"27#include "util/u_memory.h"28#include "util/u_bitmask.h"29#include "tgsi/tgsi_parse.h"30#include "draw/draw_context.h"3132#include "svga_context.h"33#include "svga_hw_reg.h"34#include "svga_cmd.h"35#include "svga_debug.h"36#include "svga_shader.h"373839void *40svga_create_fs_state(struct pipe_context *pipe,41const struct pipe_shader_state *templ)42{43struct svga_context *svga = svga_context(pipe);44struct svga_fragment_shader *fs;4546fs = CALLOC_STRUCT(svga_fragment_shader);47if (!fs)48return NULL;4950SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATEFS);5152fs->base.tokens = tgsi_dup_tokens(templ->tokens);5354/* Collect basic info that we'll need later:55*/56tgsi_scan_shader(fs->base.tokens, &fs->base.info);5758fs->base.id = svga->debug.shader_id++;5960fs->generic_inputs = svga_get_generic_inputs_mask(&fs->base.info);6162svga_remap_generics(fs->generic_inputs, fs->generic_remap_table);6364fs->draw_shader = draw_create_fragment_shader(svga->swtnl.draw, templ);6566SVGA_STATS_TIME_POP(svga_sws(svga));67return fs;68}697071void72svga_bind_fs_state(struct pipe_context *pipe, void *shader)73{74struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;75struct svga_context *svga = svga_context(pipe);7677svga->curr.fs = fs;78svga->dirty |= SVGA_NEW_FS;79}808182static void83svga_delete_fs_state(struct pipe_context *pipe, void *shader)84{85struct svga_context *svga = svga_context(pipe);86struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader;87struct svga_fragment_shader *next_fs;88struct svga_shader_variant *variant, *tmp;8990svga_hwtnl_flush_retry(svga);9192assert(fs->base.parent == NULL);9394while (fs) {95next_fs = (struct svga_fragment_shader *) fs->base.next;9697draw_delete_fragment_shader(svga->swtnl.draw, fs->draw_shader);9899for (variant = fs->base.variants; variant; variant = tmp) {100tmp = variant->next;101102/* Check if deleting currently bound shader */103if (variant == svga->state.hw_draw.fs) {104SVGA_RETRY(svga, svga_set_shader(svga, SVGA3D_SHADERTYPE_PS, NULL));105svga->state.hw_draw.fs = NULL;106}107108svga_destroy_shader_variant(svga, variant);109}110111FREE((void *)fs->base.tokens);112FREE(fs);113fs = next_fs;114}115}116117118void119svga_init_fs_functions(struct svga_context *svga)120{121svga->pipe.create_fs_state = svga_create_fs_state;122svga->pipe.bind_fs_state = svga_bind_fs_state;123svga->pipe.delete_fs_state = svga_delete_fs_state;124}125126127