xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/llvmpipe/lp_state_rasterizer.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 "pipe/p_defines.h"
29 #include "util/u_memory.h"
30 #include "lp_context.h"
31 #include "lp_state.h"
32 #include "lp_setup.h"
33 #include "draw/draw_context.h"
34 
35 
36 struct lp_rasterizer_state {
37    struct pipe_rasterizer_state lp_state;
38    struct pipe_rasterizer_state draw_state;
39 };
40 
41 
42 /* State which might be handled in either the draw module or locally.
43  * This function is used to turn that state off in one of the two
44  * places.
45  */
46 static void
clear_flags(struct pipe_rasterizer_state * rast)47 clear_flags(struct pipe_rasterizer_state *rast)
48 {
49    rast->light_twoside = 0;
50    rast->offset_tri = 0;
51    rast->offset_line = 0;
52    rast->offset_point = 0;
53    rast->offset_units = 0.0f;
54    rast->offset_scale = 0.0f;
55 }
56 
57 
58 static void *
llvmpipe_create_rasterizer_state(struct pipe_context * pipe,const struct pipe_rasterizer_state * rast)59 llvmpipe_create_rasterizer_state(struct pipe_context *pipe,
60                                  const struct pipe_rasterizer_state *rast)
61 {
62    bool need_pipeline;
63 
64    /* Partition rasterizer state into what we want the draw module to
65     * handle, and what we'll look after ourselves.
66     */
67    struct lp_rasterizer_state *state = MALLOC_STRUCT(lp_rasterizer_state);
68    if (!state)
69       return NULL;
70 
71    memcpy(&state->draw_state, rast, sizeof *rast);
72    memcpy(&state->lp_state, rast, sizeof *rast);
73 
74    /* We rely on draw module to do unfilled polygons, AA lines and
75     * points and stipple.
76     *
77     * Over time, reduce this list of conditions, and expand the list
78     * of flags which get cleared in clear_flags().
79     */
80    need_pipeline = (rast->fill_front != PIPE_POLYGON_MODE_FILL ||
81                     rast->fill_back != PIPE_POLYGON_MODE_FILL ||
82                     rast->point_smooth ||
83                     rast->line_smooth ||
84                     rast->line_stipple_enable ||
85                     rast->poly_stipple_enable);
86 
87    /* If not using the pipeline, clear out the flags which we can
88     * handle ourselves.  If we *are* using the pipeline, do everything
89     * on the pipeline and clear those flags on our internal copy of
90     * the state.
91     */
92    if (need_pipeline)
93       clear_flags(&state->lp_state);
94    else
95       clear_flags(&state->draw_state);
96 
97    return state;
98 }
99 
100 
101 static void
llvmpipe_bind_rasterizer_state(struct pipe_context * pipe,void * handle)102 llvmpipe_bind_rasterizer_state(struct pipe_context *pipe, void *handle)
103 {
104    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
105    const struct lp_rasterizer_state *state =
106       (const struct lp_rasterizer_state *) handle;
107 
108    if (state) {
109       llvmpipe->rasterizer = &state->lp_state;
110       draw_set_rasterizer_state(llvmpipe->draw, &state->draw_state, handle);
111       lp_setup_bind_rasterizer(llvmpipe->setup, &state->lp_state);
112    } else {
113       llvmpipe->rasterizer = NULL;
114       draw_set_rasterizer_state(llvmpipe->draw, NULL, handle);
115    }
116 
117    llvmpipe->dirty |= LP_NEW_RASTERIZER;
118 }
119 
120 
121 static void
llvmpipe_delete_rasterizer_state(struct pipe_context * pipe,void * rasterizer)122 llvmpipe_delete_rasterizer_state(struct pipe_context *pipe,
123                                  void *rasterizer)
124 {
125    FREE(rasterizer);
126 }
127 
128 
129 void
llvmpipe_init_rasterizer_funcs(struct llvmpipe_context * llvmpipe)130 llvmpipe_init_rasterizer_funcs(struct llvmpipe_context *llvmpipe)
131 {
132    llvmpipe->pipe.create_rasterizer_state = llvmpipe_create_rasterizer_state;
133    llvmpipe->pipe.bind_rasterizer_state   = llvmpipe_bind_rasterizer_state;
134    llvmpipe->pipe.delete_rasterizer_state = llvmpipe_delete_rasterizer_state;
135 }
136