Path: blob/21.2-virgl/src/gallium/drivers/svga/svga_pipe_ts.c
4570 views
/**********************************************************1* Copyright 2018-2020 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 "pipe/p_context.h"26#include "util/u_memory.h"27#include "tgsi/tgsi_parse.h"2829#include "svga_context.h"30#include "svga_shader.h"3132static void33svga_set_tess_state(struct pipe_context *pipe,34const float default_outer_level[4],35const float default_inner_level[2])36{37struct svga_context *svga = svga_context(pipe);38unsigned i;3940for (i = 0; i < 4; i++) {41svga->curr.default_tesslevels[i] = default_outer_level[i];42}43for (i = 0; i < 2; i++) {44svga->curr.default_tesslevels[i + 4] = default_inner_level[i];45}46}474849static void *50svga_create_tcs_state(struct pipe_context *pipe,51const struct pipe_shader_state *templ)52{53struct svga_context *svga = svga_context(pipe);54struct svga_tcs_shader *tcs;5556tcs = CALLOC_STRUCT(svga_tcs_shader);57if (!tcs)58return NULL;5960SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATETCS);6162tcs->base.tokens = tgsi_dup_tokens(templ->tokens);6364/* Collect basic info that we'll need later:65*/66tgsi_scan_shader(tcs->base.tokens, &tcs->base.info);6768tcs->base.id = svga->debug.shader_id++;6970tcs->generic_outputs = svga_get_generic_outputs_mask(&tcs->base.info);7172SVGA_STATS_TIME_POP(svga_sws(svga));73return tcs;74}757677static void78svga_bind_tcs_state(struct pipe_context *pipe, void *shader)79{80struct svga_tcs_shader *tcs = (struct svga_tcs_shader *) shader;81struct svga_context *svga = svga_context(pipe);8283if (tcs == svga->curr.tcs)84return;8586svga->curr.tcs = tcs;87svga->dirty |= SVGA_NEW_TCS;88}899091static void92svga_delete_tcs_state(struct pipe_context *pipe, void *shader)93{94struct svga_context *svga = svga_context(pipe);95struct svga_tcs_shader *tcs = (struct svga_tcs_shader *) shader;96struct svga_tcs_shader *next_tcs;97struct svga_shader_variant *variant, *tmp;9899svga_hwtnl_flush_retry(svga);100101assert(tcs->base.parent == NULL);102103while (tcs) {104next_tcs = (struct svga_tcs_shader *)tcs->base.next;105for (variant = tcs->base.variants; variant; variant = tmp) {106tmp = variant->next;107108/* Check if deleting currently bound shader */109if (variant == svga->state.hw_draw.tcs) {110SVGA_RETRY(svga, svga_set_shader(svga, SVGA3D_SHADERTYPE_HS, NULL));111svga->state.hw_draw.tcs = NULL;112}113114svga_destroy_shader_variant(svga, variant);115}116117FREE((void *)tcs->base.tokens);118FREE(tcs);119tcs = next_tcs;120}121}122123124void125svga_cleanup_tcs_state(struct svga_context *svga)126{127if (svga->tcs.passthrough_tcs) {128svga_delete_tcs_state(&svga->pipe, svga->tcs.passthrough_tcs);129}130}131132133static void *134svga_create_tes_state(struct pipe_context *pipe,135const struct pipe_shader_state *templ)136{137struct svga_context *svga = svga_context(pipe);138struct svga_tes_shader *tes;139140tes = CALLOC_STRUCT(svga_tes_shader);141if (!tes)142return NULL;143144SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATETES);145146tes->base.tokens = tgsi_dup_tokens(templ->tokens);147148/* Collect basic info that we'll need later:149*/150tgsi_scan_shader(tes->base.tokens, &tes->base.info);151152tes->base.id = svga->debug.shader_id++;153154tes->generic_inputs = svga_get_generic_inputs_mask(&tes->base.info);155156SVGA_STATS_TIME_POP(svga_sws(svga));157return tes;158}159160161static void162svga_bind_tes_state(struct pipe_context *pipe, void *shader)163{164struct svga_tes_shader *tes = (struct svga_tes_shader *) shader;165struct svga_context *svga = svga_context(pipe);166167if (tes == svga->curr.tes)168return;169170svga->curr.tes = tes;171svga->dirty |= SVGA_NEW_TES;172}173174175static void176svga_delete_tes_state(struct pipe_context *pipe, void *shader)177{178struct svga_context *svga = svga_context(pipe);179struct svga_tes_shader *tes = (struct svga_tes_shader *) shader;180struct svga_tes_shader *next_tes;181struct svga_shader_variant *variant, *tmp;182183svga_hwtnl_flush_retry(svga);184185assert(tes->base.parent == NULL);186187while (tes) {188next_tes = (struct svga_tes_shader *)tes->base.next;189for (variant = tes->base.variants; variant; variant = tmp) {190tmp = variant->next;191192/* Check if deleting currently bound shader */193if (variant == svga->state.hw_draw.tes) {194SVGA_RETRY(svga, svga_set_shader(svga, SVGA3D_SHADERTYPE_DS, NULL));195svga->state.hw_draw.tes = NULL;196}197198svga_destroy_shader_variant(svga, variant);199}200201FREE((void *)tes->base.tokens);202FREE(tes);203tes = next_tes;204}205}206207208void209svga_init_ts_functions(struct svga_context *svga)210{211svga->pipe.set_tess_state = svga_set_tess_state;212svga->pipe.create_tcs_state = svga_create_tcs_state;213svga->pipe.bind_tcs_state = svga_bind_tcs_state;214svga->pipe.delete_tcs_state = svga_delete_tcs_state;215svga->pipe.create_tes_state = svga_create_tes_state;216svga->pipe.bind_tes_state = svga_bind_tes_state;217svga->pipe.delete_tes_state = svga_delete_tes_state;218}219220221