Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 1 | /********************************************************** |
| 2 | * Copyright 2008-2009 VMware, Inc. All rights reserved. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person |
| 5 | * obtaining a copy of this software and associated documentation |
| 6 | * files (the "Software"), to deal in the Software without |
| 7 | * restriction, including without limitation the rights to use, copy, |
| 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
| 9 | * of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | * |
| 24 | **********************************************************/ |
| 25 | |
| 26 | #include "draw/draw_context.h" |
| 27 | #include "draw/draw_vbuf.h" |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 28 | #include "util/u_bitmask.h" |
José Fonseca | 2848688 | 2010-02-02 14:42:17 +0000 | [diff] [blame] | 29 | #include "util/u_inlines.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 30 | #include "pipe/p_state.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 31 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 32 | #include "svga_cmd.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 33 | #include "svga_context.h" |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 34 | #include "svga_shader.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 35 | #include "svga_swtnl.h" |
| 36 | #include "svga_state.h" |
Brian Paul | 58ea42b | 2011-11-03 17:40:56 -0600 | [diff] [blame] | 37 | #include "svga_tgsi.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 38 | #include "svga_swtnl_private.h" |
| 39 | |
| 40 | |
Brian Paul | ffbac58 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 41 | #define SVGA_POINT_ADJ_X -0.375f |
| 42 | #define SVGA_POINT_ADJ_Y -0.5f |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 43 | |
Brian Paul | ffbac58 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 44 | #define SVGA_LINE_ADJ_X -0.5f |
| 45 | #define SVGA_LINE_ADJ_Y -0.5f |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 46 | |
Brian Paul | ffbac58 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 47 | #define SVGA_TRIANGLE_ADJ_X -0.375f |
| 48 | #define SVGA_TRIANGLE_ADJ_Y -0.5f |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 49 | |
| 50 | |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 51 | static void |
| 52 | set_draw_viewport(struct svga_context *svga) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 53 | { |
| 54 | struct pipe_viewport_state vp = svga->curr.viewport; |
Brian Paul | ffbac58 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 55 | float adjx = 0.0f; |
| 56 | float adjy = 0.0f; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 57 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 58 | if (svga_have_vgpu10(svga)) { |
| 59 | if (svga->curr.reduced_prim == PIPE_PRIM_TRIANGLES) { |
| 60 | adjy = 0.25; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 61 | } |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 62 | } |
| 63 | else { |
| 64 | switch (svga->curr.reduced_prim) { |
| 65 | case PIPE_PRIM_POINTS: |
| 66 | adjx = SVGA_POINT_ADJ_X; |
| 67 | adjy = SVGA_POINT_ADJ_Y; |
| 68 | break; |
| 69 | case PIPE_PRIM_LINES: |
| 70 | /* XXX: This is to compensate for the fact that wide lines are |
| 71 | * going to be drawn with triangles, but we're not catching all |
| 72 | * cases where that will happen. |
| 73 | */ |
| 74 | if (svga->curr.rast->need_pipeline & SVGA_PIPELINE_FLAG_LINES) |
| 75 | { |
| 76 | adjx = SVGA_LINE_ADJ_X + 0.175f; |
| 77 | adjy = SVGA_LINE_ADJ_Y - 0.175f; |
| 78 | } |
| 79 | else { |
| 80 | adjx = SVGA_LINE_ADJ_X; |
| 81 | adjy = SVGA_LINE_ADJ_Y; |
| 82 | } |
| 83 | break; |
| 84 | case PIPE_PRIM_TRIANGLES: |
| 85 | adjx += SVGA_TRIANGLE_ADJ_X; |
| 86 | adjy += SVGA_TRIANGLE_ADJ_Y; |
| 87 | break; |
Brian Paul | 69fb8f3 | 2017-03-01 14:52:46 -0700 | [diff] [blame] | 88 | default: |
| 89 | /* nothing */ |
| 90 | break; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 91 | } |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | vp.translate[0] += adjx; |
| 95 | vp.translate[1] += adjy; |
| 96 | |
Zack Rusin | eaabb4e | 2013-05-24 16:08:39 -0400 | [diff] [blame] | 97 | draw_set_viewport_states(svga->swtnl.draw, 0, 1, &vp); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 98 | } |
| 99 | |
José Fonseca | e8f646f | 2011-11-02 10:32:20 +0000 | [diff] [blame] | 100 | static enum pipe_error |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 101 | update_swtnl_draw(struct svga_context *svga, unsigned dirty) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 102 | { |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 103 | SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_SWTNLUPDATEDRAW); |
| 104 | |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 105 | draw_flush(svga->swtnl.draw); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 106 | |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 107 | if (dirty & SVGA_NEW_VS) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 108 | draw_bind_vertex_shader(svga->swtnl.draw, |
| 109 | svga->curr.vs->draw_shader); |
| 110 | |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 111 | if (dirty & SVGA_NEW_FS) |
Brian Paul | 022e270 | 2011-11-03 17:40:56 -0600 | [diff] [blame] | 112 | draw_bind_fragment_shader(svga->swtnl.draw, |
| 113 | svga->curr.fs->draw_shader); |
| 114 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 115 | if (dirty & SVGA_NEW_VBUFFER) |
Marek Olšák | e73bf3b | 2012-03-29 17:51:50 +0200 | [diff] [blame] | 116 | draw_set_vertex_buffers(svga->swtnl.draw, 0, |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 117 | svga->curr.num_vertex_buffers, |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 118 | svga->curr.vb); |
| 119 | |
| 120 | if (dirty & SVGA_NEW_VELEMENT) |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 121 | draw_set_vertex_elements(svga->swtnl.draw, |
| 122 | svga->curr.velems->count, |
| 123 | svga->curr.velems->velem); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 124 | |
| 125 | if (dirty & SVGA_NEW_CLIP) |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 126 | draw_set_clip_state(svga->swtnl.draw, |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 127 | &svga->curr.clip); |
| 128 | |
| 129 | if (dirty & (SVGA_NEW_VIEWPORT | |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 130 | SVGA_NEW_REDUCED_PRIMITIVE | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 131 | SVGA_NEW_RAST)) |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 132 | set_draw_viewport(svga); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 133 | |
| 134 | if (dirty & SVGA_NEW_RAST) |
| 135 | draw_set_rasterizer_state(svga->swtnl.draw, |
Brian Paul | e3a34cc | 2010-04-19 08:35:53 -0600 | [diff] [blame] | 136 | &svga->curr.rast->templ, |
| 137 | (void *) svga->curr.rast); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 138 | |
Matthew McClure | f9e2c24 | 2013-10-29 13:36:41 -0700 | [diff] [blame] | 139 | /* Tell the draw module how deep the Z/depth buffer is. |
| 140 | * |
| 141 | * If no depth buffer is bound, send the utility function the |
| 142 | * format for no bound depth (PIPE_FORMAT_NONE). |
| 143 | */ |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 144 | if (dirty & SVGA_NEW_FRAME_BUFFER) |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 145 | draw_set_zs_format(svga->swtnl.draw, |
Matthew McClure | f9e2c24 | 2013-10-29 13:36:41 -0700 | [diff] [blame] | 146 | (svga->curr.framebuffer.zsbuf) ? |
| 147 | svga->curr.framebuffer.zsbuf->format : PIPE_FORMAT_NONE); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 148 | |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 149 | SVGA_STATS_TIME_POP(svga_sws(svga)); |
Brian Paul | 92cbfde | 2013-08-26 15:49:16 -0600 | [diff] [blame] | 150 | return PIPE_OK; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | |
| 154 | struct svga_tracked_state svga_update_swtnl_draw = |
| 155 | { |
| 156 | "update draw module state", |
| 157 | (SVGA_NEW_VS | |
| 158 | SVGA_NEW_VBUFFER | |
| 159 | SVGA_NEW_VELEMENT | |
| 160 | SVGA_NEW_CLIP | |
| 161 | SVGA_NEW_VIEWPORT | |
| 162 | SVGA_NEW_RAST | |
| 163 | SVGA_NEW_FRAME_BUFFER | |
Roland Scheidegger | 429f0e3 | 2009-12-19 00:18:43 +0100 | [diff] [blame] | 164 | SVGA_NEW_REDUCED_PRIMITIVE), |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 165 | update_swtnl_draw |
| 166 | }; |
| 167 | |
| 168 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 169 | static SVGA3dSurfaceFormat |
| 170 | translate_vertex_format(SVGA3dDeclType format) |
| 171 | { |
| 172 | switch (format) { |
| 173 | case SVGA3D_DECLTYPE_FLOAT1: |
| 174 | return SVGA3D_R32_FLOAT; |
| 175 | case SVGA3D_DECLTYPE_FLOAT2: |
| 176 | return SVGA3D_R32G32_FLOAT; |
| 177 | case SVGA3D_DECLTYPE_FLOAT3: |
| 178 | return SVGA3D_R32G32B32_FLOAT; |
| 179 | case SVGA3D_DECLTYPE_FLOAT4: |
| 180 | return SVGA3D_R32G32B32A32_FLOAT; |
| 181 | default: |
| 182 | assert(!"Unexpected format in translate_vertex_format()"); |
| 183 | return SVGA3D_R32G32B32A32_FLOAT; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | |
| 188 | static SVGA3dElementLayoutId |
| 189 | svga_vdecl_to_input_element(struct svga_context *svga, |
| 190 | const SVGA3dVertexDecl *vdecl, unsigned num_decls) |
| 191 | { |
| 192 | SVGA3dElementLayoutId id; |
| 193 | SVGA3dInputElementDesc elements[PIPE_MAX_ATTRIBS]; |
| 194 | enum pipe_error ret; |
| 195 | unsigned i; |
| 196 | |
| 197 | assert(num_decls <= PIPE_MAX_ATTRIBS); |
| 198 | assert(svga_have_vgpu10(svga)); |
| 199 | |
| 200 | for (i = 0; i < num_decls; i++) { |
| 201 | elements[i].inputSlot = 0; /* vertex buffer index */ |
| 202 | elements[i].alignedByteOffset = vdecl[i].array.offset; |
| 203 | elements[i].format = translate_vertex_format(vdecl[i].identity.type); |
| 204 | elements[i].inputSlotClass = SVGA3D_INPUT_PER_VERTEX_DATA; |
| 205 | elements[i].instanceDataStepRate = 0; |
| 206 | elements[i].inputRegister = i; |
| 207 | } |
| 208 | |
| 209 | id = util_bitmask_add(svga->input_element_object_id_bm); |
| 210 | |
| 211 | ret = SVGA3D_vgpu10_DefineElementLayout(svga->swc, num_decls, id, elements); |
| 212 | if (ret != PIPE_OK) { |
| 213 | svga_context_flush(svga, NULL); |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 214 | ret = SVGA3D_vgpu10_DefineElementLayout(svga->swc, num_decls, |
| 215 | id, elements); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 216 | assert(ret == PIPE_OK); |
| 217 | } |
| 218 | |
| 219 | return id; |
| 220 | } |
| 221 | |
| 222 | |
José Fonseca | e8f646f | 2011-11-02 10:32:20 +0000 | [diff] [blame] | 223 | enum pipe_error |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 224 | svga_swtnl_update_vdecl(struct svga_context *svga) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 225 | { |
| 226 | struct svga_vbuf_render *svga_render = svga_vbuf_render(svga->swtnl.backend); |
| 227 | struct draw_context *draw = svga->swtnl.draw; |
| 228 | struct vertex_info *vinfo = &svga_render->vertex_info; |
| 229 | SVGA3dVertexDecl vdecl[PIPE_MAX_ATTRIBS]; |
Brian Paul | 1ca48b3 | 2011-11-04 14:36:59 -0600 | [diff] [blame] | 230 | struct svga_fragment_shader *fs = svga->curr.fs; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 231 | int offset = 0; |
| 232 | int nr_decls = 0; |
Brian Paul | 25cd2c2 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 233 | int src; |
| 234 | unsigned i; |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 235 | int any_change; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 236 | |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 237 | SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_SWTNLUPDATEVDECL); |
| 238 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 239 | memset(vinfo, 0, sizeof(*vinfo)); |
| 240 | memset(vdecl, 0, sizeof(vdecl)); |
| 241 | |
Zack Rusin | d6b3a19 | 2013-07-31 07:34:49 -0400 | [diff] [blame] | 242 | draw_prepare_shader_outputs(draw); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 243 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 244 | /* always add position */ |
Zack Rusin | b057515 | 2009-12-19 13:54:53 -0500 | [diff] [blame] | 245 | src = draw_find_shader_output(draw, TGSI_SEMANTIC_POSITION, 0); |
Roland Scheidegger | 2dbc20e | 2015-12-19 03:43:14 +0100 | [diff] [blame] | 246 | draw_emit_vertex_attr(vinfo, EMIT_4F, src); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 247 | vinfo->attrib[0].emit = EMIT_4F; |
| 248 | vdecl[0].array.offset = offset; |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 249 | vdecl[0].identity.method = SVGA3D_DECLMETHOD_DEFAULT; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 250 | vdecl[0].identity.type = SVGA3D_DECLTYPE_FLOAT4; |
| 251 | vdecl[0].identity.usage = SVGA3D_DECLUSAGE_POSITIONT; |
| 252 | vdecl[0].identity.usageIndex = 0; |
| 253 | offset += 16; |
| 254 | nr_decls++; |
| 255 | |
| 256 | for (i = 0; i < fs->base.info.num_inputs; i++) { |
Brian Paul | 1b5e88b | 2017-07-10 14:03:48 -0600 | [diff] [blame] | 257 | const enum tgsi_semantic sem_name = fs->base.info.input_semantic_name[i]; |
Brian Paul | 58ea42b | 2011-11-03 17:40:56 -0600 | [diff] [blame] | 258 | const unsigned sem_index = fs->base.info.input_semantic_index[i]; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 259 | |
Brian Paul | 58ea42b | 2011-11-03 17:40:56 -0600 | [diff] [blame] | 260 | src = draw_find_shader_output(draw, sem_name, sem_index); |
| 261 | |
| 262 | vdecl[nr_decls].array.offset = offset; |
| 263 | vdecl[nr_decls].identity.usageIndex = sem_index; |
| 264 | |
| 265 | switch (sem_name) { |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 266 | case TGSI_SEMANTIC_COLOR: |
Roland Scheidegger | 2dbc20e | 2015-12-19 03:43:14 +0100 | [diff] [blame] | 267 | draw_emit_vertex_attr(vinfo, EMIT_4F, src); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 268 | vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_COLOR; |
| 269 | vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT4; |
| 270 | offset += 16; |
| 271 | nr_decls++; |
| 272 | break; |
| 273 | case TGSI_SEMANTIC_GENERIC: |
Roland Scheidegger | 2dbc20e | 2015-12-19 03:43:14 +0100 | [diff] [blame] | 274 | draw_emit_vertex_attr(vinfo, EMIT_4F, src); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 275 | vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_TEXCOORD; |
| 276 | vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT4; |
Brian Paul | 58ea42b | 2011-11-03 17:40:56 -0600 | [diff] [blame] | 277 | vdecl[nr_decls].identity.usageIndex = |
| 278 | svga_remap_generic_index(fs->generic_remap_table, sem_index); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 279 | offset += 16; |
| 280 | nr_decls++; |
| 281 | break; |
| 282 | case TGSI_SEMANTIC_FOG: |
Roland Scheidegger | 2dbc20e | 2015-12-19 03:43:14 +0100 | [diff] [blame] | 283 | draw_emit_vertex_attr(vinfo, EMIT_1F, src); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 284 | vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_TEXCOORD; |
| 285 | vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT1; |
| 286 | assert(vdecl[nr_decls].identity.usageIndex == 0); |
| 287 | offset += 4; |
| 288 | nr_decls++; |
| 289 | break; |
| 290 | case TGSI_SEMANTIC_POSITION: |
| 291 | /* generated internally, not a vertex shader output */ |
| 292 | break; |
| 293 | default: |
| 294 | assert(0); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | draw_compute_vertex_size(vinfo); |
| 299 | |
| 300 | svga_render->vdecl_count = nr_decls; |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 301 | for (i = 0; i < svga_render->vdecl_count; i++) { |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 302 | vdecl[i].array.stride = offset; |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 303 | } |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 304 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 305 | any_change = memcmp(svga_render->vdecl, vdecl, sizeof(vdecl)); |
| 306 | |
| 307 | if (svga_have_vgpu10(svga)) { |
| 308 | enum pipe_error ret; |
| 309 | |
| 310 | if (!any_change && svga_render->layout_id != SVGA3D_INVALID_ID) { |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 311 | goto done; |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | if (svga_render->layout_id != SVGA3D_INVALID_ID) { |
| 315 | /* destroy old */ |
| 316 | ret = SVGA3D_vgpu10_DestroyElementLayout(svga->swc, |
| 317 | svga_render->layout_id); |
| 318 | if (ret != PIPE_OK) { |
| 319 | svga_context_flush(svga, NULL); |
| 320 | ret = SVGA3D_vgpu10_DestroyElementLayout(svga->swc, |
| 321 | svga_render->layout_id); |
| 322 | assert(ret == PIPE_OK); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * reset current layout id state after the element layout is |
| 327 | * destroyed, so that if a new layout has the same layout id, we |
| 328 | * will know to re-issue the SetInputLayout command. |
| 329 | */ |
| 330 | if (svga->state.hw_draw.layout_id == svga_render->layout_id) |
| 331 | svga->state.hw_draw.layout_id = SVGA3D_INVALID_ID; |
| 332 | |
| 333 | util_bitmask_clear(svga->input_element_object_id_bm, |
| 334 | svga_render->layout_id); |
| 335 | } |
| 336 | |
| 337 | svga_render->layout_id = |
| 338 | svga_vdecl_to_input_element(svga, vdecl, nr_decls); |
| 339 | |
| 340 | /* bind new */ |
| 341 | if (svga->state.hw_draw.layout_id != svga_render->layout_id) { |
| 342 | ret = SVGA3D_vgpu10_SetInputLayout(svga->swc, svga_render->layout_id); |
| 343 | if (ret != PIPE_OK) { |
| 344 | svga_context_flush(svga, NULL); |
| 345 | ret = SVGA3D_vgpu10_SetInputLayout(svga->swc, |
| 346 | svga_render->layout_id); |
| 347 | assert(ret == PIPE_OK); |
| 348 | } |
| 349 | |
| 350 | svga->state.hw_draw.layout_id = svga_render->layout_id; |
| 351 | } |
| 352 | } |
| 353 | else { |
| 354 | if (!any_change) |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 355 | goto done; |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 356 | } |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 357 | |
| 358 | memcpy(svga_render->vdecl, vdecl, sizeof(vdecl)); |
| 359 | svga->swtnl.new_vdecl = TRUE; |
| 360 | |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 361 | done: |
| 362 | SVGA_STATS_TIME_POP(svga_sws(svga)); |
| 363 | return PIPE_OK; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | |
José Fonseca | e8f646f | 2011-11-02 10:32:20 +0000 | [diff] [blame] | 367 | static enum pipe_error |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 368 | update_swtnl_vdecl(struct svga_context *svga, unsigned dirty) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 369 | { |
Brian Paul | 183d419 | 2017-07-12 10:24:11 -0600 | [diff] [blame] | 370 | return svga_swtnl_update_vdecl(svga); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | |
| 374 | struct svga_tracked_state svga_update_swtnl_vdecl = |
| 375 | { |
| 376 | "update draw module vdecl", |
| 377 | (SVGA_NEW_VS | |
| 378 | SVGA_NEW_FS), |
| 379 | update_swtnl_vdecl |
| 380 | }; |