xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/llvmpipe/lp_state_tess.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2019 Red Hat.
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 "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  **************************************************************************/
25 
26 #include "lp_context.h"
27 #include "lp_state.h"
28 #include "lp_texture.h"
29 #include "lp_debug.h"
30 
31 #include "pipe/p_defines.h"
32 #include "util/u_memory.h"
33 #include "util/u_inlines.h"
34 #include "draw/draw_context.h"
35 #include "draw/draw_tess.h"
36 #include "tgsi/tgsi_dump.h"
37 
38 
39 static void *
llvmpipe_create_tcs_state(struct pipe_context * pipe,const struct pipe_shader_state * templ)40 llvmpipe_create_tcs_state(struct pipe_context *pipe,
41                           const struct pipe_shader_state *templ)
42 {
43    llvmpipe_register_shader(pipe, templ);
44 
45    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
46    struct lp_tess_ctrl_shader *state;
47 
48    state = CALLOC_STRUCT(lp_tess_ctrl_shader);
49    if (!state)
50       goto no_state;
51 
52    /* debug */
53    if (LP_DEBUG & DEBUG_TGSI && templ->type == PIPE_SHADER_IR_TGSI) {
54       debug_printf("llvmpipe: Create tess ctrl shader %p:\n", (void *)state);
55       tgsi_dump(templ->tokens, 0);
56    }
57 
58    /* copy stream output info */
59    state->no_tokens = !templ->tokens;
60    memcpy(&state->stream_output, &templ->stream_output, sizeof state->stream_output);
61 
62    if (templ->tokens || templ->type == PIPE_SHADER_IR_NIR) {
63       state->dtcs = draw_create_tess_ctrl_shader(llvmpipe->draw, templ);
64       if (state->dtcs == NULL) {
65          goto no_dgs;
66       }
67    }
68 
69    return state;
70 
71 no_dgs:
72    FREE(state);
73 no_state:
74    return NULL;
75 }
76 
77 
78 static void
llvmpipe_bind_tcs_state(struct pipe_context * pipe,void * tcs)79 llvmpipe_bind_tcs_state(struct pipe_context *pipe, void *tcs)
80 {
81    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
82 
83    llvmpipe->tcs = (struct lp_tess_ctrl_shader *)tcs;
84 
85    draw_bind_tess_ctrl_shader(llvmpipe->draw,
86                               (llvmpipe->tcs ? llvmpipe->tcs->dtcs : NULL));
87 
88    llvmpipe->dirty |= LP_NEW_TCS;
89 }
90 
91 
92 static void
llvmpipe_delete_tcs_state(struct pipe_context * pipe,void * tcs)93 llvmpipe_delete_tcs_state(struct pipe_context *pipe, void *tcs)
94 {
95    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
96 
97    struct lp_tess_ctrl_shader *state =
98       (struct lp_tess_ctrl_shader *)tcs;
99 
100    if (!state) {
101       return;
102    }
103 
104    draw_delete_tess_ctrl_shader(llvmpipe->draw, state->dtcs);
105    FREE(state);
106 }
107 
108 
109 static void *
llvmpipe_create_tes_state(struct pipe_context * pipe,const struct pipe_shader_state * templ)110 llvmpipe_create_tes_state(struct pipe_context *pipe,
111                           const struct pipe_shader_state *templ)
112 {
113    llvmpipe_register_shader(pipe, templ);
114 
115    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
116    struct lp_tess_eval_shader *state;
117 
118    state = CALLOC_STRUCT(lp_tess_eval_shader);
119    if (!state)
120       goto no_state;
121 
122    /* debug */
123    if (LP_DEBUG & DEBUG_TGSI) {
124       debug_printf("llvmpipe: Create tess eval shader %p:\n", (void *)state);
125       tgsi_dump(templ->tokens, 0);
126    }
127 
128    /* copy stream output info */
129    state->no_tokens = !templ->tokens;
130    memcpy(&state->stream_output, &templ->stream_output, sizeof state->stream_output);
131 
132    if (templ->tokens || templ->type == PIPE_SHADER_IR_NIR) {
133       state->dtes = draw_create_tess_eval_shader(llvmpipe->draw, templ);
134       if (state->dtes == NULL) {
135          goto no_dgs;
136       }
137    }
138 
139    return state;
140 
141 no_dgs:
142    FREE(state);
143 no_state:
144    return NULL;
145 }
146 
147 
148 static void
llvmpipe_bind_tes_state(struct pipe_context * pipe,void * tes)149 llvmpipe_bind_tes_state(struct pipe_context *pipe, void *tes)
150 {
151    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
152 
153    llvmpipe->tes = (struct lp_tess_eval_shader *)tes;
154 
155    draw_bind_tess_eval_shader(llvmpipe->draw,
156                               (llvmpipe->tes ? llvmpipe->tes->dtes : NULL));
157 
158    llvmpipe->dirty |= LP_NEW_TES;
159 }
160 
161 
162 static void
llvmpipe_delete_tes_state(struct pipe_context * pipe,void * tes)163 llvmpipe_delete_tes_state(struct pipe_context *pipe, void *tes)
164 {
165    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
166 
167    struct lp_tess_eval_shader *state =
168       (struct lp_tess_eval_shader *)tes;
169 
170    if (!state) {
171       return;
172    }
173 
174    draw_delete_tess_eval_shader(llvmpipe->draw, state->dtes);
175    FREE(state);
176 }
177 
178 static void
llvmpipe_set_tess_state(struct pipe_context * pipe,const float default_outer_level[4],const float default_inner_level[2])179 llvmpipe_set_tess_state(struct pipe_context *pipe,
180                         const float default_outer_level[4],
181                         const float default_inner_level[2])
182 {
183    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
184    draw_set_tess_state(llvmpipe->draw, default_outer_level, default_inner_level);
185 }
186 
187 static void
llvmpipe_set_patch_vertices(struct pipe_context * pipe,uint8_t patch_vertices)188 llvmpipe_set_patch_vertices(struct pipe_context *pipe, uint8_t patch_vertices)
189 {
190    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
191 
192    llvmpipe->patch_vertices = patch_vertices;
193 }
194 
195 void
llvmpipe_init_tess_funcs(struct llvmpipe_context * llvmpipe)196 llvmpipe_init_tess_funcs(struct llvmpipe_context *llvmpipe)
197 {
198    llvmpipe->pipe.create_tcs_state = llvmpipe_create_tcs_state;
199    llvmpipe->pipe.bind_tcs_state   = llvmpipe_bind_tcs_state;
200    llvmpipe->pipe.delete_tcs_state = llvmpipe_delete_tcs_state;
201 
202    llvmpipe->pipe.create_tes_state = llvmpipe_create_tes_state;
203    llvmpipe->pipe.bind_tes_state   = llvmpipe_bind_tes_state;
204    llvmpipe->pipe.delete_tes_state = llvmpipe_delete_tes_state;
205 
206    llvmpipe->pipe.set_tess_state = llvmpipe_set_tess_state;
207    llvmpipe->pipe.set_patch_vertices = llvmpipe_set_patch_vertices;
208 }
209