xref: /aosp_15_r20/external/mesa3d/src/gallium/auxiliary/draw/draw_pipe_util.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  /*
29   * Authors:
30   *   Keith Whitwell <[email protected]>
31   */
32 
33 #include "util/u_memory.h"
34 #include "draw/draw_private.h"
35 #include "draw/draw_pipe.h"
36 
37 
38 
39 void
draw_pipe_passthrough_point(struct draw_stage * stage,struct prim_header * header)40 draw_pipe_passthrough_point(struct draw_stage *stage, struct prim_header *header)
41 {
42    stage->next->point(stage->next, header);
43 }
44 
45 
46 void
draw_pipe_passthrough_line(struct draw_stage * stage,struct prim_header * header)47 draw_pipe_passthrough_line(struct draw_stage *stage, struct prim_header *header)
48 {
49    stage->next->line(stage->next, header);
50 }
51 
52 
53 void
draw_pipe_passthrough_tri(struct draw_stage * stage,struct prim_header * header)54 draw_pipe_passthrough_tri(struct draw_stage *stage, struct prim_header *header)
55 {
56    stage->next->tri(stage->next, header);
57 }
58 
59 /* This is only used for temporary verts.
60  */
61 #define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float))
62 
63 
64 /**
65  * Allocate space for temporary post-transform vertices, such as for clipping.
66  */
67 bool
draw_alloc_temp_verts(struct draw_stage * stage,unsigned nr)68 draw_alloc_temp_verts(struct draw_stage *stage, unsigned nr)
69 {
70    assert(!stage->tmp);
71 
72    stage->tmp = NULL;
73    stage->nr_tmps = nr;
74 
75    if (nr != 0) {
76       uint8_t *store = (uint8_t *) MALLOC(MAX_VERTEX_SIZE * nr +
77                                        DRAW_EXTRA_VERTICES_PADDING);
78       if (!store)
79          return false;
80 
81       stage->tmp = (struct vertex_header **) MALLOC(sizeof(struct vertex_header *) * nr);
82       if (stage->tmp == NULL) {
83          FREE(store);
84          return false;
85       }
86 
87       for (unsigned i = 0; i < nr; i++)
88          stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE);
89    }
90 
91    return true;
92 }
93 
94 
95 void
draw_free_temp_verts(struct draw_stage * stage)96 draw_free_temp_verts(struct draw_stage *stage)
97 {
98    if (stage->tmp) {
99       FREE(stage->tmp[0]);
100       FREE(stage->tmp);
101       stage->tmp = NULL;
102    }
103 }
104 
105 
106 /* Reset vertex ids.  This is basically a type of flush.
107  *
108  * Called only from draw_pipe_vbuf.c
109  */
110 void
draw_reset_vertex_ids(struct draw_context * draw)111 draw_reset_vertex_ids(struct draw_context *draw)
112 {
113    struct draw_stage *stage = draw->pipeline.first;
114 
115    while (stage) {
116       for (unsigned i = 0; i < stage->nr_tmps; i++)
117          stage->tmp[i]->vertex_id = UNDEFINED_VERTEX_ID;
118 
119       stage = stage->next;
120    }
121 
122    if (draw->pipeline.verts) {
123       char *verts = draw->pipeline.verts;
124       unsigned stride = draw->pipeline.vertex_stride;
125 
126       for (unsigned i = 0; i < draw->pipeline.vertex_count; i++) {
127          ((struct vertex_header *)verts)->vertex_id = UNDEFINED_VERTEX_ID;
128          verts += stride;
129       }
130    }
131 }
132 
133