xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/llvmpipe/lp_state_gs.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2007 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #include "lp_context.h"
29 #include "lp_state.h"
30 #include "lp_texture.h"
31 #include "lp_debug.h"
32 
33 #include "pipe/p_defines.h"
34 #include "util/u_memory.h"
35 #include "util/u_inlines.h"
36 #include "draw/draw_context.h"
37 #include "draw/draw_gs.h"
38 #include "tgsi/tgsi_dump.h"
39 
40 
41 static void *
llvmpipe_create_gs_state(struct pipe_context * pipe,const struct pipe_shader_state * templ)42 llvmpipe_create_gs_state(struct pipe_context *pipe,
43                          const struct pipe_shader_state *templ)
44 {
45    llvmpipe_register_shader(pipe, templ);
46 
47    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
48    struct lp_geometry_shader *state;
49 
50    state = CALLOC_STRUCT(lp_geometry_shader);
51    if (!state)
52       goto no_state;
53 
54    /* debug */
55    if (LP_DEBUG & DEBUG_TGSI && templ->type == PIPE_SHADER_IR_TGSI) {
56       debug_printf("llvmpipe: Create geometry shader %p:\n", (void *)state);
57       tgsi_dump(templ->tokens, 0);
58    }
59 
60    /* copy stream output info */
61    if (templ->type == PIPE_SHADER_IR_TGSI)
62       state->no_tokens = !templ->tokens;
63    else
64       state->no_tokens = false;
65    memcpy(&state->stream_output, &templ->stream_output, sizeof state->stream_output);
66 
67    if (templ->tokens || templ->type == PIPE_SHADER_IR_NIR) {
68       state->dgs = draw_create_geometry_shader(llvmpipe->draw, templ);
69       if (state->dgs == NULL) {
70          goto no_dgs;
71       }
72    }
73 
74    return state;
75 
76 no_dgs:
77    FREE(state);
78 no_state:
79    return NULL;
80 }
81 
82 
83 static void
llvmpipe_bind_gs_state(struct pipe_context * pipe,void * gs)84 llvmpipe_bind_gs_state(struct pipe_context *pipe, void *gs)
85 {
86    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
87 
88    llvmpipe->gs = (struct lp_geometry_shader *)gs;
89 
90    draw_bind_geometry_shader(llvmpipe->draw,
91                              (llvmpipe->gs ? llvmpipe->gs->dgs : NULL));
92 
93    llvmpipe->dirty |= LP_NEW_GS;
94 }
95 
96 
97 static void
llvmpipe_delete_gs_state(struct pipe_context * pipe,void * gs)98 llvmpipe_delete_gs_state(struct pipe_context *pipe, void *gs)
99 {
100    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
101 
102    struct lp_geometry_shader *state =
103       (struct lp_geometry_shader *)gs;
104 
105    if (!state) {
106       return;
107    }
108 
109    draw_delete_geometry_shader(llvmpipe->draw, state->dgs);
110    FREE(state);
111 }
112 
113 
114 void
llvmpipe_init_gs_funcs(struct llvmpipe_context * llvmpipe)115 llvmpipe_init_gs_funcs(struct llvmpipe_context *llvmpipe)
116 {
117    llvmpipe->pipe.create_gs_state = llvmpipe_create_gs_state;
118    llvmpipe->pipe.bind_gs_state   = llvmpipe_bind_gs_state;
119    llvmpipe->pipe.delete_gs_state = llvmpipe_delete_gs_state;
120 }
121