X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fsvga%2Fsvga_pipe_vs.c;h=ba87cb43e8f28487e0ceaa602eaffab8def88029;hb=49428c8d61274b452dc4885b44e4954d8634358e;hp=c4ac5304ac6ae758f33133090cb2726067e0471c;hpb=782b6885c2573e1f004d9572eb386d9e1f392254;p=mesa.git diff --git a/src/gallium/drivers/svga/svga_pipe_vs.c b/src/gallium/drivers/svga/svga_pipe_vs.c index c4ac5304ac6..ba87cb43e8f 100644 --- a/src/gallium/drivers/svga/svga_pipe_vs.c +++ b/src/gallium/drivers/svga/svga_pipe_vs.c @@ -24,30 +24,32 @@ **********************************************************/ #include "draw/draw_context.h" -#include "pipe/p_inlines.h" +#include "util/u_inlines.h" #include "util/u_math.h" #include "util/u_memory.h" #include "util/u_bitmask.h" #include "tgsi/tgsi_parse.h" #include "tgsi/tgsi_text.h" -#include "svga_screen.h" #include "svga_context.h" -#include "svga_tgsi.h" #include "svga_hw_reg.h" #include "svga_cmd.h" #include "svga_debug.h" +#include "svga_shader.h" +#include "svga_streamout.h" -static const struct tgsi_token *substitute_vs( - unsigned shader_id, - const struct tgsi_token *old_tokens ) +/** + * Substitute a debug shader. + */ +static const struct tgsi_token * +substitute_vs(unsigned shader_id, const struct tgsi_token *old_tokens) { #if 0 if (shader_id == 12) { static struct tgsi_token tokens[300]; - const char *text = + const char *text = "VERT\n" "DCL IN[0]\n" "DCL IN[1]\n" @@ -76,9 +78,9 @@ static const struct tgsi_token *substitute_vs( " MOV OUT[0], TEMP[4]\n" " END\n"; - if (!tgsi_text_translate( text, + if (!tgsi_text_translate(text, tokens, - Elements(tokens) )) + ARRAY_SIZE(tokens))) { assert(0); return NULL; @@ -92,26 +94,23 @@ static const struct tgsi_token *substitute_vs( } -/*********************************************************************** - * Vertex shaders - */ - static void * svga_create_vs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct svga_context *svga = svga_context(pipe); - struct svga_screen *svgascreen = svga_screen(pipe->screen); struct svga_vertex_shader *vs = CALLOC_STRUCT(svga_vertex_shader); + if (!vs) return NULL; + SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATEVS); + /* substitute a debug shader? */ vs->base.tokens = tgsi_dup_tokens(substitute_vs(svga->debug.shader_id, templ->tokens)); - /* Collect basic info that we'll need later: */ tgsi_scan_shader(vs->base.tokens, &vs->base.info); @@ -126,62 +125,86 @@ svga_create_vs_state(struct pipe_context *pipe, } vs->base.id = svga->debug.shader_id++; - vs->base.use_sm30 = svgascreen->use_vs30; - if (SVGA_DEBUG & DEBUG_TGSI || 0) { - debug_printf("%s id: %u, inputs: %u, outputs: %u\n", - __FUNCTION__, vs->base.id, - vs->base.info.num_inputs, vs->base.info.num_outputs); + vs->generic_outputs = svga_get_generic_outputs_mask(&vs->base.info); + + /* check for any stream output declarations */ + if (templ->stream_output.num_outputs) { + vs->base.stream_output = svga_create_stream_output(svga, &vs->base, + &templ->stream_output); } + SVGA_STATS_TIME_POP(svga_sws(svga)); return vs; } -static void svga_bind_vs_state(struct pipe_context *pipe, void *shader) + +static void +svga_bind_vs_state(struct pipe_context *pipe, void *shader) { struct svga_vertex_shader *vs = (struct svga_vertex_shader *)shader; struct svga_context *svga = svga_context(pipe); + if (vs == svga->curr.vs) + return; + + /* If the currently bound vertex shader has a generated geometry shader, + * then unbind the geometry shader before binding a new vertex shader. + * We need to unbind the geometry shader here because there is no + * pipe_shader associated with the generated geometry shader. + */ + if (svga->curr.vs != NULL && svga->curr.vs->gs != NULL) + svga->pipe.bind_gs_state(&svga->pipe, NULL); + svga->curr.vs = vs; svga->dirty |= SVGA_NEW_VS; } -static void svga_delete_vs_state(struct pipe_context *pipe, void *shader) +static void +svga_delete_vs_state(struct pipe_context *pipe, void *shader) { struct svga_context *svga = svga_context(pipe); struct svga_vertex_shader *vs = (struct svga_vertex_shader *)shader; - struct svga_shader_result *result, *tmp; + struct svga_shader_variant *variant, *tmp; enum pipe_error ret; - svga_hwtnl_flush_retry( svga ); + svga_hwtnl_flush_retry(svga); - draw_delete_vertex_shader(svga->swtnl.draw, vs->draw_shader); - - for (result = vs->base.results; result; result = tmp ) { - tmp = result->next; - - ret = SVGA3D_DestroyShader(svga->swc, - result->id, - SVGA3D_SHADERTYPE_VS ); - if(ret != PIPE_OK) { - svga_context_flush(svga, NULL); - ret = SVGA3D_DestroyShader(svga->swc, - result->id, - SVGA3D_SHADERTYPE_VS ); - assert(ret == PIPE_OK); - } + assert(vs->base.parent == NULL); - util_bitmask_clear( svga->vs_bm, result->id ); + /* Check if there is a generated geometry shader to go with this + * vertex shader. If there is, then delete the geometry shader as well. + */ + if (vs->gs != NULL) { + svga->pipe.delete_gs_state(&svga->pipe, vs->gs); + } - svga_destroy_shader_result( result ); + if (vs->base.stream_output != NULL) + svga_delete_stream_output(svga, vs->base.stream_output); - /* - * Remove stale references to this result to ensure a new result on the - * same address will be detected as a change. - */ - if(result == svga->state.hw_draw.vs) + draw_delete_vertex_shader(svga->swtnl.draw, vs->draw_shader); + + for (variant = vs->base.variants; variant; variant = tmp) { + tmp = variant->next; + + /* Check if deleting currently bound shader */ + if (variant == svga->state.hw_draw.vs) { + ret = svga_set_shader(svga, SVGA3D_SHADERTYPE_VS, NULL); + if (ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = svga_set_shader(svga, SVGA3D_SHADERTYPE_VS, NULL); + assert(ret == PIPE_OK); + } svga->state.hw_draw.vs = NULL; + } + + ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant); + if (ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant); + assert(ret == PIPE_OK); + } } FREE((void *)vs->base.tokens); @@ -189,7 +212,8 @@ static void svga_delete_vs_state(struct pipe_context *pipe, void *shader) } -void svga_init_vs_functions( struct svga_context *svga ) +void +svga_init_vs_functions(struct svga_context *svga) { svga->pipe.create_vs_state = svga_create_vs_state; svga->pipe.bind_vs_state = svga_bind_vs_state;