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 "svga_cmd.h" |
| 27 | |
José Fonseca | 2848688 | 2010-02-02 14:42:17 +0000 | [diff] [blame] | 28 | #include "util/u_inlines.h" |
Brian Paul | 32a6e08 | 2015-12-04 12:26:35 -0700 | [diff] [blame] | 29 | #include "util/u_prim.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 30 | #include "indices/u_indices.h" |
| 31 | |
| 32 | #include "svga_hw_reg.h" |
| 33 | #include "svga_draw.h" |
| 34 | #include "svga_draw_private.h" |
| 35 | #include "svga_context.h" |
Brian Paul | 129d34d | 2015-10-16 16:12:19 -0600 | [diff] [blame] | 36 | #include "svga_shader.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 37 | |
| 38 | |
| 39 | #define DBG 0 |
| 40 | |
| 41 | |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 42 | static enum pipe_error |
| 43 | generate_indices(struct svga_hwtnl *hwtnl, |
| 44 | unsigned nr, |
| 45 | unsigned index_size, |
| 46 | u_generate_func generate, struct pipe_resource **out_buf) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 47 | { |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 48 | struct pipe_context *pipe = &hwtnl->svga->pipe; |
| 49 | struct pipe_transfer *transfer; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 50 | unsigned size = index_size * nr; |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 51 | struct pipe_resource *dst = NULL; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 52 | void *dst_map = NULL; |
| 53 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 54 | dst = pipe_buffer_create(pipe->screen, PIPE_BIND_INDEX_BUFFER, |
| 55 | PIPE_USAGE_IMMUTABLE, size); |
Edward O'Callaghan | 13eb5f5 | 2015-12-04 22:08:22 +1100 | [diff] [blame] | 56 | if (!dst) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 57 | goto fail; |
| 58 | |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 59 | dst_map = pipe_buffer_map(pipe, dst, PIPE_TRANSFER_WRITE, &transfer); |
Edward O'Callaghan | 13eb5f5 | 2015-12-04 22:08:22 +1100 | [diff] [blame] | 60 | if (!dst_map) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 61 | goto fail; |
| 62 | |
Rob Clark | 28f3f8d | 2013-10-25 15:22:06 -0400 | [diff] [blame] | 63 | generate(0, nr, dst_map); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 64 | |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 65 | pipe_buffer_unmap(pipe, transfer); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 66 | |
| 67 | *out_buf = dst; |
| 68 | return PIPE_OK; |
| 69 | |
| 70 | fail: |
| 71 | if (dst_map) |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 72 | pipe_buffer_unmap(pipe, transfer); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 73 | |
| 74 | if (dst) |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 75 | pipe->screen->resource_destroy(pipe->screen, dst); |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 76 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 77 | return PIPE_ERROR_OUT_OF_MEMORY; |
| 78 | } |
| 79 | |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 80 | |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 81 | static boolean |
| 82 | compare(unsigned cached_nr, unsigned nr, unsigned type) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 83 | { |
| 84 | if (type == U_GENERATE_REUSABLE) |
| 85 | return cached_nr >= nr; |
| 86 | else |
| 87 | return cached_nr == nr; |
| 88 | } |
| 89 | |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 90 | |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 91 | static enum pipe_error |
| 92 | retrieve_or_generate_indices(struct svga_hwtnl *hwtnl, |
Brian Paul | d21a309 | 2016-05-25 16:52:34 -0600 | [diff] [blame] | 93 | enum pipe_prim_type prim, |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 94 | unsigned gen_type, |
| 95 | unsigned gen_nr, |
| 96 | unsigned gen_size, |
| 97 | u_generate_func generate, |
| 98 | struct pipe_resource **out_buf) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 99 | { |
| 100 | enum pipe_error ret = PIPE_OK; |
| 101 | int i; |
| 102 | |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 103 | SVGA_STATS_TIME_PUSH(svga_sws(hwtnl->svga), SVGA_STATS_TIME_GENERATEINDICES); |
| 104 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 105 | for (i = 0; i < IDX_CACHE_MAX; i++) { |
| 106 | if (hwtnl->index_cache[prim][i].buffer != NULL && |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 107 | hwtnl->index_cache[prim][i].generate == generate) { |
| 108 | if (compare(hwtnl->index_cache[prim][i].gen_nr, gen_nr, gen_type)) { |
| 109 | pipe_resource_reference(out_buf, |
| 110 | hwtnl->index_cache[prim][i].buffer); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 111 | |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 112 | if (DBG) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 113 | debug_printf("%s retrieve %d/%d\n", __FUNCTION__, i, gen_nr); |
| 114 | |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 115 | goto done; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 116 | } |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 117 | else if (gen_type == U_GENERATE_REUSABLE) { |
| 118 | pipe_resource_reference(&hwtnl->index_cache[prim][i].buffer, |
| 119 | NULL); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 120 | |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 121 | if (DBG) |
| 122 | debug_printf("%s discard %d/%d\n", __FUNCTION__, |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 123 | i, hwtnl->index_cache[prim][i].gen_nr); |
| 124 | |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 130 | if (i == IDX_CACHE_MAX) { |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 131 | unsigned smallest = 0; |
| 132 | unsigned smallest_size = ~0; |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 133 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 134 | for (i = 0; i < IDX_CACHE_MAX && smallest_size; i++) { |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 135 | if (hwtnl->index_cache[prim][i].buffer == NULL) { |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 136 | smallest = i; |
| 137 | smallest_size = 0; |
| 138 | } |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 139 | else if (hwtnl->index_cache[prim][i].gen_nr < smallest) { |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 140 | smallest = i; |
| 141 | smallest_size = hwtnl->index_cache[prim][i].gen_nr; |
| 142 | } |
| 143 | } |
| 144 | |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 145 | assert(smallest != IDX_CACHE_MAX); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 146 | |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 147 | pipe_resource_reference(&hwtnl->index_cache[prim][smallest].buffer, |
| 148 | NULL); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 149 | |
| 150 | if (DBG) |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 151 | debug_printf("%s discard smallest %d/%d\n", __FUNCTION__, |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 152 | smallest, smallest_size); |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 153 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 154 | i = smallest; |
| 155 | } |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 156 | |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 157 | ret = generate_indices(hwtnl, gen_nr, gen_size, generate, out_buf); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 158 | if (ret != PIPE_OK) |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 159 | goto done; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 160 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 161 | hwtnl->index_cache[prim][i].generate = generate; |
| 162 | hwtnl->index_cache[prim][i].gen_nr = gen_nr; |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 163 | pipe_resource_reference(&hwtnl->index_cache[prim][i].buffer, *out_buf); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 164 | |
| 165 | if (DBG) |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 166 | debug_printf("%s cache %d/%d\n", __FUNCTION__, |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 167 | i, hwtnl->index_cache[prim][i].gen_nr); |
| 168 | |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 169 | done: |
| 170 | SVGA_STATS_TIME_POP(svga_sws(hwtnl->svga)); |
| 171 | return ret; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 175 | static enum pipe_error |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 176 | simple_draw_arrays(struct svga_hwtnl *hwtnl, |
Brian Paul | d21a309 | 2016-05-25 16:52:34 -0600 | [diff] [blame] | 177 | enum pipe_prim_type prim, unsigned start, unsigned count, |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 178 | unsigned start_instance, unsigned instance_count) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 179 | { |
| 180 | SVGA3dPrimitiveRange range; |
| 181 | unsigned hw_prim; |
| 182 | unsigned hw_count; |
| 183 | |
| 184 | hw_prim = svga_translate_prim(prim, count, &hw_count); |
| 185 | if (hw_count == 0) |
| 186 | return PIPE_ERROR_BAD_INPUT; |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 187 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 188 | range.primType = hw_prim; |
| 189 | range.primitiveCount = hw_count; |
| 190 | range.indexArray.surfaceId = SVGA3D_INVALID_ID; |
| 191 | range.indexArray.offset = 0; |
| 192 | range.indexArray.stride = 0; |
| 193 | range.indexWidth = 0; |
| 194 | range.indexBias = start; |
| 195 | |
| 196 | /* Min/max index should be calculated prior to applying bias, so we |
| 197 | * end up with min_index = 0, max_index = count - 1 and everybody |
| 198 | * looking at those numbers knows to adjust them by |
| 199 | * range.indexBias. |
| 200 | */ |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 201 | return svga_hwtnl_prim(hwtnl, &range, count, |
| 202 | 0, count - 1, NULL, |
| 203 | start_instance, instance_count); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 207 | enum pipe_error |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 208 | svga_hwtnl_draw_arrays(struct svga_hwtnl *hwtnl, |
Brian Paul | d21a309 | 2016-05-25 16:52:34 -0600 | [diff] [blame] | 209 | enum pipe_prim_type prim, unsigned start, unsigned count, |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 210 | unsigned start_instance, unsigned instance_count) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 211 | { |
Brian Paul | a25ae48 | 2016-05-26 07:12:59 -0600 | [diff] [blame] | 212 | enum pipe_prim_type gen_prim; |
| 213 | unsigned gen_size, gen_nr; |
Brian Paul | 3f98c81 | 2015-10-31 07:44:49 -0600 | [diff] [blame] | 214 | enum indices_mode gen_type; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 215 | u_generate_func gen_func; |
| 216 | enum pipe_error ret = PIPE_OK; |
Brian Paul | 129d34d | 2015-10-16 16:12:19 -0600 | [diff] [blame] | 217 | unsigned api_pv = hwtnl->api_pv; |
| 218 | struct svga_context *svga = hwtnl->svga; |
| 219 | |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 220 | SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_HWTNLDRAWARRAYS); |
| 221 | |
Brian Paul | 90afd7b | 2016-05-25 12:42:55 -0600 | [diff] [blame] | 222 | if (svga->curr.rast->templ.fill_front != |
| 223 | svga->curr.rast->templ.fill_back) { |
| 224 | assert(hwtnl->api_fillmode == PIPE_POLYGON_MODE_FILL); |
| 225 | } |
| 226 | |
Brian Paul | 129d34d | 2015-10-16 16:12:19 -0600 | [diff] [blame] | 227 | if (svga->curr.rast->templ.flatshade && |
| 228 | svga->state.hw_draw.fs->constant_color_output) { |
| 229 | /* The fragment color is a constant, not per-vertex so the whole |
| 230 | * primitive will be the same color (except for possible blending). |
| 231 | * We can ignore the current provoking vertex state and use whatever |
| 232 | * the hardware wants. |
| 233 | */ |
| 234 | api_pv = hwtnl->hw_pv; |
Brian Paul | 99effaa | 2015-10-16 16:14:46 -0600 | [diff] [blame] | 235 | |
| 236 | if (hwtnl->api_fillmode == PIPE_POLYGON_MODE_FILL) { |
| 237 | /* Do some simple primitive conversions to avoid index buffer |
| 238 | * generation below. Note that polygons and quads are not directly |
| 239 | * supported by the svga device. Also note, we can only do this |
| 240 | * for flat/constant-colored rendering because of provoking vertex. |
| 241 | */ |
| 242 | if (prim == PIPE_PRIM_POLYGON) { |
| 243 | prim = PIPE_PRIM_TRIANGLE_FAN; |
| 244 | } |
| 245 | else if (prim == PIPE_PRIM_QUADS && count == 4) { |
| 246 | prim = PIPE_PRIM_TRIANGLE_FAN; |
| 247 | } |
| 248 | } |
Brian Paul | 129d34d | 2015-10-16 16:12:19 -0600 | [diff] [blame] | 249 | } |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 250 | |
Brian Paul | 90afd7b | 2016-05-25 12:42:55 -0600 | [diff] [blame] | 251 | if (svga_need_unfilled_fallback(hwtnl, prim)) { |
Brian Paul | 1e16e48 | 2013-06-19 10:39:43 -0600 | [diff] [blame] | 252 | /* Convert unfilled polygons into points, lines, triangles */ |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 253 | gen_type = u_unfilled_generator(prim, |
| 254 | start, |
| 255 | count, |
| 256 | hwtnl->api_fillmode, |
| 257 | &gen_prim, |
| 258 | &gen_size, &gen_nr, &gen_func); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 259 | } |
| 260 | else { |
Brian Paul | 1e16e48 | 2013-06-19 10:39:43 -0600 | [diff] [blame] | 261 | /* Convert PIPE_PRIM_LINE_LOOP to PIPE_PRIM_LINESTRIP, |
| 262 | * convert PIPE_PRIM_POLYGON to PIPE_PRIM_TRIANGLE_FAN, |
| 263 | * etc, if needed (as determined by svga_hw_prims mask). |
| 264 | */ |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 265 | gen_type = u_index_generator(svga_hw_prims, |
| 266 | prim, |
| 267 | start, |
| 268 | count, |
Brian Paul | 129d34d | 2015-10-16 16:12:19 -0600 | [diff] [blame] | 269 | api_pv, |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 270 | hwtnl->hw_pv, |
| 271 | &gen_prim, &gen_size, &gen_nr, &gen_func); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | if (gen_type == U_GENERATE_LINEAR) { |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 275 | ret = simple_draw_arrays(hwtnl, gen_prim, start, count, |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 276 | start_instance, instance_count); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 277 | } |
| 278 | else { |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 279 | struct pipe_resource *gen_buf = NULL; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 280 | |
Brian Paul | 1284543 | 2012-10-16 17:54:37 -0600 | [diff] [blame] | 281 | /* Need to draw as indexed primitive. |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 282 | * Potentially need to run the gen func to build an index buffer. |
| 283 | */ |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 284 | ret = retrieve_or_generate_indices(hwtnl, |
| 285 | prim, |
| 286 | gen_type, |
| 287 | gen_nr, |
| 288 | gen_size, gen_func, &gen_buf); |
Brian Paul | 4d2b21a | 2017-08-18 21:18:47 -0600 | [diff] [blame] | 289 | if (ret == PIPE_OK) { |
| 290 | pipe_debug_message(&svga->debug.callback, PERF_INFO, |
| 291 | "generating temporary index buffer for drawing %s", |
| 292 | u_prim_name(prim)); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 293 | |
Brian Paul | 4d2b21a | 2017-08-18 21:18:47 -0600 | [diff] [blame] | 294 | ret = svga_hwtnl_simple_draw_range_elements(hwtnl, |
| 295 | gen_buf, |
| 296 | gen_size, |
| 297 | start, |
| 298 | 0, |
| 299 | count - 1, |
| 300 | gen_prim, 0, gen_nr, |
| 301 | start_instance, |
| 302 | instance_count); |
| 303 | } |
Brian Paul | 32a6e08 | 2015-12-04 12:26:35 -0700 | [diff] [blame] | 304 | |
Brian Paul | 4d2b21a | 2017-08-18 21:18:47 -0600 | [diff] [blame] | 305 | if (gen_buf) { |
Brian Paul | ea9fe9e | 2013-10-28 09:43:08 -0600 | [diff] [blame] | 306 | pipe_resource_reference(&gen_buf, NULL); |
Brian Paul | 4d2b21a | 2017-08-18 21:18:47 -0600 | [diff] [blame] | 307 | } |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 308 | } |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 309 | |
| 310 | SVGA_STATS_TIME_POP(svga_sws(svga)); |
| 311 | return ret; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 312 | } |