Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
| 3 | * |
| 4 | * Copyright (C) 2010 VMware, Inc. 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 |
Kenneth Graunke | 3d8d5b2 | 2013-04-21 13:46:48 -0700 | [diff] [blame] | 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | |
| 26 | /* |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 27 | * Transform feedback support. |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 28 | * |
| 29 | * Authors: |
| 30 | * Brian Paul |
| 31 | */ |
| 32 | |
| 33 | |
| 34 | #include "buffers.h" |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 35 | #include "context.h" |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 36 | #include "hash.h" |
Paul Berry | 3870f29 | 2012-12-12 14:14:12 -0800 | [diff] [blame] | 37 | #include "macros.h" |
Vinson Lee | 0117da4 | 2011-01-05 23:11:54 -0800 | [diff] [blame] | 38 | #include "mtypes.h" |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 39 | #include "transformfeedback.h" |
Brian Paul | a37b221 | 2010-06-10 20:23:03 -0600 | [diff] [blame] | 40 | #include "shaderapi.h" |
| 41 | #include "shaderobj.h" |
Chia-I Wu | b093016 | 2010-05-11 13:20:40 +0800 | [diff] [blame] | 42 | #include "main/dispatch.h" |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 43 | |
Brian Paul | ec2b92f | 2010-06-10 23:02:41 -0600 | [diff] [blame] | 44 | #include "program/prog_parameter.h" |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 45 | |
Kenneth Graunke | 2b71b3d | 2013-09-06 15:41:19 -0700 | [diff] [blame] | 46 | struct using_program_tuple |
| 47 | { |
Timothy Arceri | 3177eef | 2016-11-03 14:35:08 +1100 | [diff] [blame] | 48 | struct gl_program *prog; |
Kenneth Graunke | 2b71b3d | 2013-09-06 15:41:19 -0700 | [diff] [blame] | 49 | bool found; |
| 50 | }; |
| 51 | |
| 52 | static void |
| 53 | active_xfb_object_references_program(GLuint key, void *data, void *user_data) |
| 54 | { |
| 55 | struct using_program_tuple *callback_data = user_data; |
| 56 | struct gl_transform_feedback_object *obj = data; |
Timothy Arceri | 3177eef | 2016-11-03 14:35:08 +1100 | [diff] [blame] | 57 | if (obj->Active && obj->program == callback_data->prog) |
Kenneth Graunke | 2b71b3d | 2013-09-06 15:41:19 -0700 | [diff] [blame] | 58 | callback_data->found = true; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Return true if any active transform feedback object is using a program. |
| 63 | */ |
| 64 | bool |
| 65 | _mesa_transform_feedback_is_using_program(struct gl_context *ctx, |
| 66 | struct gl_shader_program *shProg) |
| 67 | { |
Timothy Arceri | f86d15e | 2016-11-20 21:44:29 +1100 | [diff] [blame] | 68 | if (!shProg->last_vert_prog) |
| 69 | return false; |
| 70 | |
Kenneth Graunke | 2b71b3d | 2013-09-06 15:41:19 -0700 | [diff] [blame] | 71 | struct using_program_tuple callback_data; |
Kenneth Graunke | 2b71b3d | 2013-09-06 15:41:19 -0700 | [diff] [blame] | 72 | callback_data.found = false; |
Timothy Arceri | f86d15e | 2016-11-20 21:44:29 +1100 | [diff] [blame] | 73 | callback_data.prog = shProg->last_vert_prog; |
Kenneth Graunke | 2b71b3d | 2013-09-06 15:41:19 -0700 | [diff] [blame] | 74 | |
Timothy Arceri | 347fe24 | 2017-04-24 15:59:24 +1000 | [diff] [blame] | 75 | _mesa_HashWalkLocked(ctx->TransformFeedback.Objects, |
| 76 | active_xfb_object_references_program, &callback_data); |
Kenneth Graunke | 2b71b3d | 2013-09-06 15:41:19 -0700 | [diff] [blame] | 77 | |
| 78 | /* Also check DefaultObject, as it's not in the Objects hash table. */ |
| 79 | active_xfb_object_references_program(0, ctx->TransformFeedback.DefaultObject, |
| 80 | &callback_data); |
| 81 | |
| 82 | return callback_data.found; |
| 83 | } |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 84 | |
| 85 | /** |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 86 | * Do reference counting of transform feedback buffers. |
| 87 | */ |
| 88 | static void |
| 89 | reference_transform_feedback_object(struct gl_transform_feedback_object **ptr, |
| 90 | struct gl_transform_feedback_object *obj) |
| 91 | { |
| 92 | if (*ptr == obj) |
| 93 | return; |
| 94 | |
| 95 | if (*ptr) { |
| 96 | /* Unreference the old object */ |
| 97 | struct gl_transform_feedback_object *oldObj = *ptr; |
| 98 | |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 99 | assert(oldObj->RefCount > 0); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 100 | oldObj->RefCount--; |
| 101 | |
| 102 | if (oldObj->RefCount == 0) { |
| 103 | GET_CURRENT_CONTEXT(ctx); |
| 104 | if (ctx) |
| 105 | ctx->Driver.DeleteTransformFeedback(ctx, oldObj); |
| 106 | } |
| 107 | |
| 108 | *ptr = NULL; |
| 109 | } |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 110 | assert(!*ptr); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 111 | |
| 112 | if (obj) { |
Timothy Arceri | 622a68e | 2017-04-21 13:29:46 +1000 | [diff] [blame] | 113 | assert(obj->RefCount > 0); |
| 114 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 115 | /* reference new object */ |
Timothy Arceri | 622a68e | 2017-04-21 13:29:46 +1000 | [diff] [blame] | 116 | obj->RefCount++; |
| 117 | obj->EverBound = GL_TRUE; |
| 118 | *ptr = obj; |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /** |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 124 | * Per-context init for transform feedback. |
| 125 | */ |
| 126 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 127 | _mesa_init_transform_feedback(struct gl_context *ctx) |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 128 | { |
Chia-I Wu | 32a9b27 | 2010-07-06 16:27:20 +0800 | [diff] [blame] | 129 | /* core mesa expects this, even a dummy one, to be available */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 130 | assert(ctx->Driver.NewTransformFeedback); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 131 | |
| 132 | ctx->TransformFeedback.DefaultObject = |
| 133 | ctx->Driver.NewTransformFeedback(ctx, 0); |
| 134 | |
| 135 | assert(ctx->TransformFeedback.DefaultObject->RefCount == 1); |
| 136 | |
| 137 | reference_transform_feedback_object(&ctx->TransformFeedback.CurrentObject, |
| 138 | ctx->TransformFeedback.DefaultObject); |
| 139 | |
| 140 | assert(ctx->TransformFeedback.DefaultObject->RefCount == 2); |
| 141 | |
| 142 | ctx->TransformFeedback.Objects = _mesa_NewHashTable(); |
| 143 | |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 144 | _mesa_reference_buffer_object(ctx, |
| 145 | &ctx->TransformFeedback.CurrentBuffer, |
| 146 | ctx->Shared->NullBufferObj); |
| 147 | } |
| 148 | |
| 149 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * Callback for _mesa_HashDeleteAll(). |
| 153 | */ |
| 154 | static void |
| 155 | delete_cb(GLuint key, void *data, void *userData) |
| 156 | { |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 157 | struct gl_context *ctx = (struct gl_context *) userData; |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 158 | struct gl_transform_feedback_object *obj = |
| 159 | (struct gl_transform_feedback_object *) data; |
| 160 | |
| 161 | ctx->Driver.DeleteTransformFeedback(ctx, obj); |
| 162 | } |
| 163 | |
| 164 | |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 165 | /** |
| 166 | * Per-context free/clean-up for transform feedback. |
| 167 | */ |
| 168 | void |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 169 | _mesa_free_transform_feedback(struct gl_context *ctx) |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 170 | { |
Chia-I Wu | 32a9b27 | 2010-07-06 16:27:20 +0800 | [diff] [blame] | 171 | /* core mesa expects this, even a dummy one, to be available */ |
Matt Turner | bfcdb84 | 2015-02-20 20:18:47 -0800 | [diff] [blame] | 172 | assert(ctx->Driver.NewTransformFeedback); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 173 | |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 174 | _mesa_reference_buffer_object(ctx, |
| 175 | &ctx->TransformFeedback.CurrentBuffer, |
| 176 | NULL); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 177 | |
| 178 | /* Delete all feedback objects */ |
| 179 | _mesa_HashDeleteAll(ctx->TransformFeedback.Objects, delete_cb, ctx); |
Brian Paul | 5b90f83 | 2010-07-01 11:07:32 -0600 | [diff] [blame] | 180 | _mesa_DeleteHashTable(ctx->TransformFeedback.Objects); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 181 | |
| 182 | /* Delete the default feedback object */ |
| 183 | assert(ctx->Driver.DeleteTransformFeedback); |
Brian Paul | 39c13a1 | 2010-05-14 08:03:42 -0600 | [diff] [blame] | 184 | ctx->Driver.DeleteTransformFeedback(ctx, |
| 185 | ctx->TransformFeedback.DefaultObject); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 186 | |
| 187 | ctx->TransformFeedback.CurrentObject = NULL; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | |
Kenneth Graunke | f02ee30 | 2013-10-25 15:54:10 -0700 | [diff] [blame] | 191 | /** Initialize the fields of a gl_transform_feedback_object. */ |
| 192 | void |
| 193 | _mesa_init_transform_feedback_object(struct gl_transform_feedback_object *obj, |
| 194 | GLuint name) |
| 195 | { |
Kenneth Graunke | f02ee30 | 2013-10-25 15:54:10 -0700 | [diff] [blame] | 196 | obj->Name = name; |
| 197 | obj->RefCount = 1; |
| 198 | obj->EverBound = GL_FALSE; |
| 199 | } |
| 200 | |
| 201 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 202 | /** Default fallback for ctx->Driver.NewTransformFeedback() */ |
| 203 | static struct gl_transform_feedback_object * |
Samuel Pitoiset | c7b201a | 2017-08-24 13:43:21 +0200 | [diff] [blame] | 204 | new_transform_feedback_fallback(struct gl_context *ctx, GLuint name) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 205 | { |
| 206 | struct gl_transform_feedback_object *obj; |
Samuel Pitoiset | 41c7c2d | 2017-08-24 13:43:19 +0200 | [diff] [blame] | 207 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 208 | obj = CALLOC_STRUCT(gl_transform_feedback_object); |
Samuel Pitoiset | 41c7c2d | 2017-08-24 13:43:19 +0200 | [diff] [blame] | 209 | if (!obj) |
| 210 | return NULL; |
| 211 | |
Kenneth Graunke | f02ee30 | 2013-10-25 15:54:10 -0700 | [diff] [blame] | 212 | _mesa_init_transform_feedback_object(obj, name); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 213 | return obj; |
| 214 | } |
| 215 | |
| 216 | /** Default fallback for ctx->Driver.DeleteTransformFeedback() */ |
| 217 | static void |
Samuel Pitoiset | c7b201a | 2017-08-24 13:43:21 +0200 | [diff] [blame] | 218 | delete_transform_feedback_fallback(struct gl_context *ctx, |
| 219 | struct gl_transform_feedback_object *obj) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 220 | { |
| 221 | GLuint i; |
| 222 | |
Brian Paul | c2e130f | 2015-02-28 08:57:11 -0700 | [diff] [blame] | 223 | for (i = 0; i < ARRAY_SIZE(obj->Buffers); i++) { |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 224 | _mesa_reference_buffer_object(ctx, &obj->Buffers[i], NULL); |
| 225 | } |
| 226 | |
Timothy Arceri | 6d8dd59 | 2013-08-26 17:16:08 +1000 | [diff] [blame] | 227 | free(obj->Label); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 228 | free(obj); |
| 229 | } |
| 230 | |
Chia-I Wu | 32a9b27 | 2010-07-06 16:27:20 +0800 | [diff] [blame] | 231 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 232 | /** Default fallback for ctx->Driver.BeginTransformFeedback() */ |
| 233 | static void |
Samuel Pitoiset | c7b201a | 2017-08-24 13:43:21 +0200 | [diff] [blame] | 234 | begin_transform_feedback_fallback(struct gl_context *ctx, GLenum mode, |
| 235 | struct gl_transform_feedback_object *obj) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 236 | { |
| 237 | /* nop */ |
| 238 | } |
| 239 | |
| 240 | /** Default fallback for ctx->Driver.EndTransformFeedback() */ |
| 241 | static void |
Samuel Pitoiset | c7b201a | 2017-08-24 13:43:21 +0200 | [diff] [blame] | 242 | end_transform_feedback_fallback(struct gl_context *ctx, |
| 243 | struct gl_transform_feedback_object *obj) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 244 | { |
| 245 | /* nop */ |
| 246 | } |
| 247 | |
| 248 | /** Default fallback for ctx->Driver.PauseTransformFeedback() */ |
| 249 | static void |
Samuel Pitoiset | c7b201a | 2017-08-24 13:43:21 +0200 | [diff] [blame] | 250 | pause_transform_feedback_fallback(struct gl_context *ctx, |
| 251 | struct gl_transform_feedback_object *obj) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 252 | { |
| 253 | /* nop */ |
| 254 | } |
| 255 | |
| 256 | /** Default fallback for ctx->Driver.ResumeTransformFeedback() */ |
| 257 | static void |
Samuel Pitoiset | c7b201a | 2017-08-24 13:43:21 +0200 | [diff] [blame] | 258 | resume_transform_feedback_fallback(struct gl_context *ctx, |
| 259 | struct gl_transform_feedback_object *obj) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 260 | { |
| 261 | /* nop */ |
| 262 | } |
| 263 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 264 | |
| 265 | /** |
| 266 | * Plug in default device driver functions for transform feedback. |
| 267 | * Most drivers will override some/all of these. |
| 268 | */ |
| 269 | void |
| 270 | _mesa_init_transform_feedback_functions(struct dd_function_table *driver) |
| 271 | { |
Samuel Pitoiset | c7b201a | 2017-08-24 13:43:21 +0200 | [diff] [blame] | 272 | driver->NewTransformFeedback = new_transform_feedback_fallback; |
| 273 | driver->DeleteTransformFeedback = delete_transform_feedback_fallback; |
| 274 | driver->BeginTransformFeedback = begin_transform_feedback_fallback; |
| 275 | driver->EndTransformFeedback = end_transform_feedback_fallback; |
| 276 | driver->PauseTransformFeedback = pause_transform_feedback_fallback; |
| 277 | driver->ResumeTransformFeedback = resume_transform_feedback_fallback; |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 281 | /** |
Paul Berry | 1ad5162 | 2012-12-15 13:06:10 -0800 | [diff] [blame] | 282 | * Fill in the correct Size value for each buffer in \c obj. |
| 283 | * |
| 284 | * From the GL 4.3 spec, section 6.1.1 ("Binding Buffer Objects to Indexed |
| 285 | * Targets"): |
| 286 | * |
| 287 | * BindBufferBase binds the entire buffer, even when the size of the buffer |
| 288 | * is changed after the binding is established. It is equivalent to calling |
| 289 | * BindBufferRange with offset zero, while size is determined by the size of |
| 290 | * the bound buffer at the time the binding is used. |
| 291 | * |
| 292 | * Regardless of the size specified with BindBufferRange, or indirectly with |
| 293 | * BindBufferBase, the GL will never read or write beyond the end of a bound |
| 294 | * buffer. In some cases this constraint may result in visibly different |
| 295 | * behavior when a buffer overflow would otherwise result, such as described |
| 296 | * for transform feedback operations in section 13.2.2. |
| 297 | */ |
| 298 | static void |
| 299 | compute_transform_feedback_buffer_sizes( |
| 300 | struct gl_transform_feedback_object *obj) |
| 301 | { |
| 302 | unsigned i = 0; |
| 303 | for (i = 0; i < MAX_FEEDBACK_BUFFERS; ++i) { |
| 304 | GLintptr offset = obj->Offset[i]; |
| 305 | GLsizeiptr buffer_size |
| 306 | = obj->Buffers[i] == NULL ? 0 : obj->Buffers[i]->Size; |
| 307 | GLsizeiptr available_space |
| 308 | = buffer_size <= offset ? 0 : buffer_size - offset; |
| 309 | GLsizeiptr computed_size; |
| 310 | if (obj->RequestedSize[i] == 0) { |
| 311 | /* No size was specified at the time the buffer was bound, so allow |
| 312 | * writing to all available space in the buffer. |
| 313 | */ |
| 314 | computed_size = available_space; |
| 315 | } else { |
| 316 | /* A size was specified at the time the buffer was bound, however |
| 317 | * it's possible that the buffer has shrunk since then. So only |
| 318 | * allow writing to the minimum of the specified size and the space |
| 319 | * available. |
| 320 | */ |
| 321 | computed_size = MIN2(available_space, obj->RequestedSize[i]); |
| 322 | } |
| 323 | |
| 324 | /* Legal sizes must be multiples of four, so round down if necessary. */ |
| 325 | obj->Size[i] = computed_size & ~0x3; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | |
| 330 | /** |
Paul Berry | 3870f29 | 2012-12-12 14:14:12 -0800 | [diff] [blame] | 331 | * Compute the maximum number of vertices that can be written to the currently |
| 332 | * enabled transform feedback buffers without overflowing any of them. |
| 333 | */ |
| 334 | unsigned |
Timothy Arceri | 258299d | 2016-03-03 13:20:01 +1100 | [diff] [blame] | 335 | _mesa_compute_max_transform_feedback_vertices(struct gl_context *ctx, |
Paul Berry | 3870f29 | 2012-12-12 14:14:12 -0800 | [diff] [blame] | 336 | const struct gl_transform_feedback_object *obj, |
| 337 | const struct gl_transform_feedback_info *info) |
| 338 | { |
| 339 | unsigned max_index = 0xffffffff; |
| 340 | unsigned i; |
| 341 | |
Timothy Arceri | 258299d | 2016-03-03 13:20:01 +1100 | [diff] [blame] | 342 | for (i = 0; i < ctx->Const.MaxTransformFeedbackBuffers; i++) { |
| 343 | if ((info->ActiveBuffers >> i) & 1) { |
Timothy Arceri | cf039a3 | 2016-03-10 15:00:00 +1100 | [diff] [blame] | 344 | unsigned stride = info->Buffers[i].Stride; |
Timothy Arceri | 258299d | 2016-03-03 13:20:01 +1100 | [diff] [blame] | 345 | unsigned max_for_this_buffer; |
Paul Berry | 3870f29 | 2012-12-12 14:14:12 -0800 | [diff] [blame] | 346 | |
Timothy Arceri | 258299d | 2016-03-03 13:20:01 +1100 | [diff] [blame] | 347 | /* Skip any inactive buffers, which have a stride of 0. */ |
| 348 | if (stride == 0) |
| 349 | continue; |
Paul Berry | 3870f29 | 2012-12-12 14:14:12 -0800 | [diff] [blame] | 350 | |
Timothy Arceri | 258299d | 2016-03-03 13:20:01 +1100 | [diff] [blame] | 351 | max_for_this_buffer = obj->Size[i] / (4 * stride); |
| 352 | max_index = MIN2(max_index, max_for_this_buffer); |
| 353 | } |
Paul Berry | 3870f29 | 2012-12-12 14:14:12 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | return max_index; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | /** |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 361 | ** Begin API functions |
| 362 | **/ |
| 363 | |
| 364 | |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 365 | /** |
| 366 | * Figure out which stage of the pipeline is the source of transform feedback |
Timothy Arceri | 3177eef | 2016-11-03 14:35:08 +1100 | [diff] [blame] | 367 | * data given the current context state, and return its gl_program. |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 368 | * |
| 369 | * If no active program can generate transform feedback data (i.e. no vertex |
| 370 | * shader is active), returns NULL. |
| 371 | */ |
Timothy Arceri | 3177eef | 2016-11-03 14:35:08 +1100 | [diff] [blame] | 372 | static struct gl_program * |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 373 | get_xfb_source(struct gl_context *ctx) |
| 374 | { |
| 375 | int i; |
| 376 | for (i = MESA_SHADER_GEOMETRY; i >= MESA_SHADER_VERTEX; i--) { |
Gregory Hainaut | c034770 | 2013-05-03 19:44:10 +0200 | [diff] [blame] | 377 | if (ctx->_Shader->CurrentProgram[i] != NULL) |
Timothy Arceri | c505d6d | 2016-10-31 22:39:17 +1100 | [diff] [blame] | 378 | return ctx->_Shader->CurrentProgram[i]; |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 379 | } |
| 380 | return NULL; |
| 381 | } |
| 382 | |
| 383 | |
Samuel Pitoiset | 088d5cb | 2017-08-24 11:55:44 +0200 | [diff] [blame] | 384 | static ALWAYS_INLINE void |
| 385 | begin_transform_feedback(struct gl_context *ctx, GLenum mode, bool no_error) |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 386 | { |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 387 | struct gl_transform_feedback_object *obj; |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 388 | struct gl_transform_feedback_info *info = NULL; |
Samuel Pitoiset | 088d5cb | 2017-08-24 11:55:44 +0200 | [diff] [blame] | 389 | struct gl_program *source; |
Brian Paul | 8e45e38 | 2012-10-27 08:58:19 -0600 | [diff] [blame] | 390 | GLuint i; |
Paul Berry | b87e65c | 2012-12-13 09:30:09 -0800 | [diff] [blame] | 391 | unsigned vertices_per_prim; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 392 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 393 | obj = ctx->TransformFeedback.CurrentObject; |
Paul Berry | 86bb45f | 2011-12-30 10:14:35 -0800 | [diff] [blame] | 394 | |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 395 | /* Figure out what pipeline stage is the source of data for transform |
| 396 | * feedback. |
| 397 | */ |
Samuel Pitoiset | 088d5cb | 2017-08-24 11:55:44 +0200 | [diff] [blame] | 398 | source = get_xfb_source(ctx); |
| 399 | if (!no_error && source == NULL) { |
Paul Berry | 86bb45f | 2011-12-30 10:14:35 -0800 | [diff] [blame] | 400 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 401 | "glBeginTransformFeedback(no program active)"); |
| 402 | return; |
| 403 | } |
| 404 | |
Timothy Arceri | 3177eef | 2016-11-03 14:35:08 +1100 | [diff] [blame] | 405 | info = source->sh.LinkedTransformFeedback; |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 406 | |
Samuel Pitoiset | 088d5cb | 2017-08-24 11:55:44 +0200 | [diff] [blame] | 407 | if (!no_error && info->NumOutputs == 0) { |
Paul Berry | 86bb45f | 2011-12-30 10:14:35 -0800 | [diff] [blame] | 408 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 409 | "glBeginTransformFeedback(no varyings to record)"); |
| 410 | return; |
| 411 | } |
| 412 | |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 413 | switch (mode) { |
| 414 | case GL_POINTS: |
Paul Berry | b87e65c | 2012-12-13 09:30:09 -0800 | [diff] [blame] | 415 | vertices_per_prim = 1; |
| 416 | break; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 417 | case GL_LINES: |
Paul Berry | b87e65c | 2012-12-13 09:30:09 -0800 | [diff] [blame] | 418 | vertices_per_prim = 2; |
| 419 | break; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 420 | case GL_TRIANGLES: |
Paul Berry | b87e65c | 2012-12-13 09:30:09 -0800 | [diff] [blame] | 421 | vertices_per_prim = 3; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 422 | break; |
| 423 | default: |
Samuel Pitoiset | 088d5cb | 2017-08-24 11:55:44 +0200 | [diff] [blame] | 424 | if (!no_error) { |
| 425 | _mesa_error(ctx, GL_INVALID_ENUM, "glBeginTransformFeedback(mode)"); |
| 426 | return; |
| 427 | } else { |
| 428 | /* Stop compiler warnings */ |
| 429 | unreachable("Error in API use when using KHR_no_error"); |
| 430 | } |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 431 | } |
| 432 | |
Samuel Pitoiset | 088d5cb | 2017-08-24 11:55:44 +0200 | [diff] [blame] | 433 | if (!no_error) { |
| 434 | if (obj->Active) { |
| 435 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 436 | "glBeginTransformFeedback(already active)"); |
| 437 | return; |
| 438 | } |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 439 | |
Samuel Pitoiset | 088d5cb | 2017-08-24 11:55:44 +0200 | [diff] [blame] | 440 | for (i = 0; i < ctx->Const.MaxTransformFeedbackBuffers; i++) { |
| 441 | if ((info->ActiveBuffers >> i) & 1) { |
| 442 | if (obj->BufferNames[i] == 0) { |
| 443 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 444 | "glBeginTransformFeedback(binding point %d does not " |
| 445 | "have a buffer object bound)", i); |
| 446 | return; |
| 447 | } |
Timothy Arceri | 258299d | 2016-03-03 13:20:01 +1100 | [diff] [blame] | 448 | } |
Paul Berry | ebfad9f | 2011-12-29 15:55:01 -0800 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
Marek Olšák | b95cbe5 | 2013-04-15 00:50:20 +0200 | [diff] [blame] | 452 | FLUSH_VERTICES(ctx, 0); |
| 453 | ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback; |
| 454 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 455 | obj->Active = GL_TRUE; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 456 | ctx->TransformFeedback.Mode = mode; |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 457 | |
Paul Berry | 1ad5162 | 2012-12-15 13:06:10 -0800 | [diff] [blame] | 458 | compute_transform_feedback_buffer_sizes(obj); |
| 459 | |
Paul Berry | b87e65c | 2012-12-13 09:30:09 -0800 | [diff] [blame] | 460 | if (_mesa_is_gles3(ctx)) { |
| 461 | /* In GLES3, we are required to track the usage of the transform |
| 462 | * feedback buffer and report INVALID_OPERATION if a draw call tries to |
| 463 | * exceed it. So compute the maximum number of vertices that we can |
| 464 | * write without overflowing any of the buffers currently being used for |
| 465 | * feedback. |
| 466 | */ |
| 467 | unsigned max_vertices |
Timothy Arceri | 258299d | 2016-03-03 13:20:01 +1100 | [diff] [blame] | 468 | = _mesa_compute_max_transform_feedback_vertices(ctx, obj, info); |
Paul Berry | b87e65c | 2012-12-13 09:30:09 -0800 | [diff] [blame] | 469 | obj->GlesRemainingPrims = max_vertices / vertices_per_prim; |
| 470 | } |
| 471 | |
Timothy Arceri | 3177eef | 2016-11-03 14:35:08 +1100 | [diff] [blame] | 472 | if (obj->program != source) { |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 473 | ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedbackProg; |
Timothy Arceri | 3177eef | 2016-11-03 14:35:08 +1100 | [diff] [blame] | 474 | obj->program = source; |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 475 | } |
Kenneth Graunke | c732f68 | 2013-09-06 14:47:19 -0700 | [diff] [blame] | 476 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 477 | assert(ctx->Driver.BeginTransformFeedback); |
| 478 | ctx->Driver.BeginTransformFeedback(ctx, mode, obj); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | |
| 482 | void GLAPIENTRY |
Samuel Pitoiset | 3906e8a | 2017-08-24 11:57:55 +0200 | [diff] [blame] | 483 | _mesa_BeginTransformFeedback_no_error(GLenum mode) |
| 484 | { |
| 485 | GET_CURRENT_CONTEXT(ctx); |
| 486 | begin_transform_feedback(ctx, mode, true); |
| 487 | } |
| 488 | |
| 489 | |
| 490 | void GLAPIENTRY |
Samuel Pitoiset | 088d5cb | 2017-08-24 11:55:44 +0200 | [diff] [blame] | 491 | _mesa_BeginTransformFeedback(GLenum mode) |
| 492 | { |
| 493 | GET_CURRENT_CONTEXT(ctx); |
| 494 | begin_transform_feedback(ctx, mode, false); |
| 495 | } |
| 496 | |
| 497 | |
Samuel Pitoiset | 6545876 | 2017-08-24 12:01:27 +0200 | [diff] [blame] | 498 | static void |
| 499 | end_transform_feedback(struct gl_context *ctx, |
| 500 | struct gl_transform_feedback_object *obj) |
| 501 | { |
| 502 | FLUSH_VERTICES(ctx, 0); |
| 503 | ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback; |
| 504 | |
| 505 | assert(ctx->Driver.EndTransformFeedback); |
| 506 | ctx->Driver.EndTransformFeedback(ctx, obj); |
| 507 | |
| 508 | ctx->TransformFeedback.CurrentObject->Active = GL_FALSE; |
| 509 | ctx->TransformFeedback.CurrentObject->Paused = GL_FALSE; |
| 510 | ctx->TransformFeedback.CurrentObject->EndedAnytime = GL_TRUE; |
| 511 | } |
| 512 | |
| 513 | |
Samuel Pitoiset | 088d5cb | 2017-08-24 11:55:44 +0200 | [diff] [blame] | 514 | void GLAPIENTRY |
Samuel Pitoiset | 08cecec | 2017-08-24 12:02:40 +0200 | [diff] [blame] | 515 | _mesa_EndTransformFeedback_no_error(void) |
| 516 | { |
| 517 | GET_CURRENT_CONTEXT(ctx); |
| 518 | end_transform_feedback(ctx, ctx->TransformFeedback.CurrentObject); |
| 519 | } |
| 520 | |
| 521 | |
| 522 | void GLAPIENTRY |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 523 | _mesa_EndTransformFeedback(void) |
| 524 | { |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 525 | struct gl_transform_feedback_object *obj; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 526 | GET_CURRENT_CONTEXT(ctx); |
| 527 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 528 | obj = ctx->TransformFeedback.CurrentObject; |
| 529 | |
| 530 | if (!obj->Active) { |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 531 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 532 | "glEndTransformFeedback(not active)"); |
| 533 | return; |
| 534 | } |
| 535 | |
Samuel Pitoiset | 6545876 | 2017-08-24 12:01:27 +0200 | [diff] [blame] | 536 | end_transform_feedback(ctx, obj); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
| 540 | /** |
| 541 | * Helper used by BindBufferRange() and BindBufferBase(). |
| 542 | */ |
| 543 | static void |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 544 | bind_buffer_range(struct gl_context *ctx, |
| 545 | struct gl_transform_feedback_object *obj, |
| 546 | GLuint index, |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 547 | struct gl_buffer_object *bufObj, |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 548 | GLintptr offset, GLsizeiptr size, |
| 549 | bool dsa) |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 550 | { |
Marek Olšák | b95cbe5 | 2013-04-15 00:50:20 +0200 | [diff] [blame] | 551 | /* Note: no need to FLUSH_VERTICES or flag NewTransformFeedback, because |
Paul Berry | 291ae4e | 2011-12-16 13:55:37 -0800 | [diff] [blame] | 552 | * transform feedback buffers can't be changed while transform feedback is |
| 553 | * active. |
| 554 | */ |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 555 | |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 556 | if (!dsa) { |
| 557 | /* The general binding point */ |
| 558 | _mesa_reference_buffer_object(ctx, |
| 559 | &ctx->TransformFeedback.CurrentBuffer, |
| 560 | bufObj); |
| 561 | } |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 562 | |
| 563 | /* The per-attribute binding point */ |
Fredrik Höglund | 835abfa | 2013-11-15 19:53:29 +0100 | [diff] [blame] | 564 | _mesa_set_transform_feedback_binding(ctx, obj, index, bufObj, offset, size); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | |
| 568 | /** |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 569 | * Validate the buffer object to receive transform feedback results. Plus, |
| 570 | * validate the starting offset to place the results, and max size. |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 571 | * Called from the glBindBufferRange() and glTransformFeedbackBufferRange |
| 572 | * functions. |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 573 | */ |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 574 | bool |
| 575 | _mesa_validate_buffer_range_xfb(struct gl_context *ctx, |
| 576 | struct gl_transform_feedback_object *obj, |
| 577 | GLuint index, struct gl_buffer_object *bufObj, |
| 578 | GLintptr offset, GLsizeiptr size, bool dsa) |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 579 | { |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 580 | const char *gl_methd_name; |
| 581 | if (dsa) |
| 582 | gl_methd_name = "glTransformFeedbackBufferRange"; |
| 583 | else |
| 584 | gl_methd_name = "glBindBufferRange"; |
| 585 | |
| 586 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 587 | if (obj->Active) { |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 588 | _mesa_error(ctx, GL_INVALID_OPERATION, "%s(transform feedback active)", |
| 589 | gl_methd_name); |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 590 | return false; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 591 | } |
| 592 | |
Marek Olšák | 15ac66e | 2011-12-18 02:13:17 +0100 | [diff] [blame] | 593 | if (index >= ctx->Const.MaxTransformFeedbackBuffers) { |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 594 | /* OpenGL 4.5 core profile, 6.1, pdf page 82: "An INVALID_VALUE error is |
| 595 | * generated if index is greater than or equal to the number of binding |
| 596 | * points for transform feedback, as described in section 6.7.1." |
| 597 | */ |
| 598 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%d out of bounds)", |
| 599 | gl_methd_name, index); |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 600 | return false; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 601 | } |
| 602 | |
Eric Anholt | b82c472 | 2012-06-14 16:55:56 -0700 | [diff] [blame] | 603 | if (size & 0x3) { |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 604 | /* OpenGL 4.5 core profile, 6.7, pdf page 103: multiple of 4 */ |
| 605 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d must be a multiple of " |
| 606 | "four)", gl_methd_name, (int) size); |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 607 | return false; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | if (offset & 0x3) { |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 611 | /* OpenGL 4.5 core profile, 6.7, pdf page 103: multiple of 4 */ |
| 612 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset=%d must be a multiple " |
| 613 | "of four)", gl_methd_name, (int) offset); |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 614 | return false; |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 615 | } |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 616 | |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 617 | if (offset < 0) { |
| 618 | /* OpenGL 4.5 core profile, 6.1, pdf page 82: "An INVALID_VALUE error is |
| 619 | * generated by BindBufferRange if offset is negative." |
| 620 | * |
| 621 | * OpenGL 4.5 core profile, 13.2, pdf page 445: "An INVALID_VALUE error |
| 622 | * is generated by TransformFeedbackBufferRange if offset is negative." |
| 623 | */ |
| 624 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset=%d must be >= 0)", |
| 625 | gl_methd_name, |
| 626 | (int) offset); |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 627 | return false; |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | if (size <= 0 && (dsa || bufObj != ctx->Shared->NullBufferObj)) { |
| 631 | /* OpenGL 4.5 core profile, 6.1, pdf page 82: "An INVALID_VALUE error is |
| 632 | * generated by BindBufferRange if buffer is non-zero and size is less |
| 633 | * than or equal to zero." |
| 634 | * |
| 635 | * OpenGL 4.5 core profile, 13.2, pdf page 445: "An INVALID_VALUE error |
| 636 | * is generated by TransformFeedbackBufferRange if size is less than or |
| 637 | * equal to zero." |
| 638 | */ |
| 639 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d must be > 0)", |
| 640 | gl_methd_name, (int) size); |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 641 | return false; |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 642 | } |
| 643 | |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 644 | return true; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | |
| 648 | /** |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 649 | * Specify a buffer object to receive transform feedback results. |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 650 | * As above, but start at offset = 0. |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 651 | * Called from the glBindBufferBase() and glTransformFeedbackBufferBase() |
| 652 | * functions. |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 653 | */ |
Eric Anholt | b82c472 | 2012-06-14 16:55:56 -0700 | [diff] [blame] | 654 | void |
| 655 | _mesa_bind_buffer_base_transform_feedback(struct gl_context *ctx, |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 656 | struct gl_transform_feedback_object *obj, |
| 657 | GLuint index, |
| 658 | struct gl_buffer_object *bufObj, |
| 659 | bool dsa) |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 660 | { |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 661 | if (obj->Active) { |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 662 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 663 | "%s(transform feedback active)", |
| 664 | dsa ? "glTransformFeedbackBufferBase" : "glBindBufferBase"); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 665 | return; |
| 666 | } |
| 667 | |
Marek Olšák | 15ac66e | 2011-12-18 02:13:17 +0100 | [diff] [blame] | 668 | if (index >= ctx->Const.MaxTransformFeedbackBuffers) { |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 669 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%d out of bounds)", |
| 670 | dsa ? "glTransformFeedbackBufferBase" : "glBindBufferBase", |
| 671 | index); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 672 | return; |
| 673 | } |
| 674 | |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 675 | bind_buffer_range(ctx, obj, index, bufObj, 0, 0, dsa); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 676 | } |
| 677 | |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 678 | /** |
| 679 | * Wrapper around lookup_transform_feedback_object that throws |
| 680 | * GL_INVALID_OPERATION if id is not in the hash table. After calling |
| 681 | * _mesa_error, it returns NULL. |
| 682 | */ |
| 683 | static struct gl_transform_feedback_object * |
| 684 | lookup_transform_feedback_object_err(struct gl_context *ctx, |
| 685 | GLuint xfb, const char* func) |
| 686 | { |
| 687 | struct gl_transform_feedback_object *obj; |
| 688 | |
| 689 | obj = _mesa_lookup_transform_feedback_object(ctx, xfb); |
| 690 | if (!obj) { |
| 691 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 692 | "%s(xfb=%u: non-generated object name)", func, xfb); |
| 693 | } |
| 694 | |
| 695 | return obj; |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Wrapper around _mesa_lookup_bufferobj that throws GL_INVALID_VALUE if id |
| 700 | * is not in the hash table. Specialised version for the |
| 701 | * transform-feedback-related functions. After calling _mesa_error, it |
| 702 | * returns NULL. |
| 703 | */ |
| 704 | static struct gl_buffer_object * |
| 705 | lookup_transform_feedback_bufferobj_err(struct gl_context *ctx, |
| 706 | GLuint buffer, const char* func) |
| 707 | { |
| 708 | struct gl_buffer_object *bufObj; |
| 709 | |
| 710 | /* OpenGL 4.5 core profile, 13.2, pdf page 444: buffer must be zero or the |
| 711 | * name of an existing buffer object. |
| 712 | */ |
| 713 | if (buffer == 0) { |
| 714 | bufObj = ctx->Shared->NullBufferObj; |
| 715 | } else { |
| 716 | bufObj = _mesa_lookup_bufferobj(ctx, buffer); |
| 717 | if (!bufObj) { |
| 718 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid buffer=%u)", func, |
| 719 | buffer); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | return bufObj; |
| 724 | } |
| 725 | |
| 726 | void GLAPIENTRY |
| 727 | _mesa_TransformFeedbackBufferBase(GLuint xfb, GLuint index, GLuint buffer) |
| 728 | { |
| 729 | GET_CURRENT_CONTEXT(ctx); |
| 730 | struct gl_transform_feedback_object *obj; |
| 731 | struct gl_buffer_object *bufObj; |
| 732 | |
| 733 | obj = lookup_transform_feedback_object_err(ctx, xfb, |
| 734 | "glTransformFeedbackBufferBase"); |
| 735 | if(!obj) { |
| 736 | return; |
| 737 | } |
| 738 | |
| 739 | bufObj = lookup_transform_feedback_bufferobj_err(ctx, buffer, |
| 740 | "glTransformFeedbackBufferBase"); |
| 741 | if(!bufObj) { |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | _mesa_bind_buffer_base_transform_feedback(ctx, obj, index, bufObj, true); |
| 746 | } |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 747 | |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 748 | void GLAPIENTRY |
| 749 | _mesa_TransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, |
| 750 | GLintptr offset, GLsizeiptr size) |
| 751 | { |
| 752 | GET_CURRENT_CONTEXT(ctx); |
| 753 | struct gl_transform_feedback_object *obj; |
| 754 | struct gl_buffer_object *bufObj; |
| 755 | |
| 756 | obj = lookup_transform_feedback_object_err(ctx, xfb, |
| 757 | "glTransformFeedbackBufferRange"); |
| 758 | if(!obj) { |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | bufObj = lookup_transform_feedback_bufferobj_err(ctx, buffer, |
| 763 | "glTransformFeedbackBufferRange"); |
| 764 | if(!bufObj) { |
| 765 | return; |
| 766 | } |
| 767 | |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 768 | if (!_mesa_validate_buffer_range_xfb(ctx, obj, index, bufObj, offset, |
| 769 | size, true)) |
| 770 | return; |
| 771 | |
| 772 | /* The per-attribute binding point */ |
| 773 | _mesa_set_transform_feedback_binding(ctx, obj, index, bufObj, offset, |
| 774 | size); |
Martin Peres | 296d823 | 2015-01-21 12:22:11 +0200 | [diff] [blame] | 775 | } |
| 776 | |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 777 | /** |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 778 | * Specify a buffer object to receive transform feedback results, plus the |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 779 | * offset in the buffer to start placing results. |
| 780 | * This function is part of GL_EXT_transform_feedback, but not GL3. |
| 781 | */ |
| 782 | void GLAPIENTRY |
| 783 | _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer, |
| 784 | GLintptr offset) |
| 785 | { |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 786 | struct gl_transform_feedback_object *obj; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 787 | struct gl_buffer_object *bufObj; |
| 788 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 789 | |
| 790 | if (target != GL_TRANSFORM_FEEDBACK_BUFFER) { |
| 791 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferOffsetEXT(target)"); |
| 792 | return; |
| 793 | } |
| 794 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 795 | obj = ctx->TransformFeedback.CurrentObject; |
| 796 | |
| 797 | if (obj->Active) { |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 798 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Brian Paul | 2be2e1d | 2011-04-29 12:03:28 -0600 | [diff] [blame] | 799 | "glBindBufferOffsetEXT(transform feedback active)"); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 800 | return; |
| 801 | } |
| 802 | |
Marek Olšák | 15ac66e | 2011-12-18 02:13:17 +0100 | [diff] [blame] | 803 | if (index >= ctx->Const.MaxTransformFeedbackBuffers) { |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 804 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 805 | "glBindBufferOffsetEXT(index=%d)", index); |
| 806 | return; |
| 807 | } |
| 808 | |
Paul Berry | 86bb45f | 2011-12-30 10:14:35 -0800 | [diff] [blame] | 809 | if (offset & 0x3) { |
| 810 | /* must be multiple of four */ |
| 811 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 812 | "glBindBufferOffsetEXT(offset=%d)", (int) offset); |
| 813 | return; |
| 814 | } |
| 815 | |
Kenneth Graunke | 05b086c | 2012-06-04 00:48:23 -0700 | [diff] [blame] | 816 | if (buffer == 0) { |
| 817 | bufObj = ctx->Shared->NullBufferObj; |
| 818 | } else { |
| 819 | bufObj = _mesa_lookup_bufferobj(ctx, buffer); |
Samuel Pitoiset | 08ee28b | 2017-08-24 13:44:21 +0200 | [diff] [blame] | 820 | if (!bufObj) { |
| 821 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 822 | "glBindBufferOffsetEXT(invalid buffer=%u)", buffer); |
| 823 | return; |
| 824 | } |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 825 | } |
| 826 | |
Timothy Arceri | 3eb6d34 | 2017-05-22 15:47:00 +1000 | [diff] [blame] | 827 | _mesa_bind_buffer_range_xfb(ctx, obj, index, bufObj, offset, 0); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | |
| 831 | /** |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 832 | * This function specifies the transform feedback outputs to be written |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 833 | * to the feedback buffer(s), and in what order. |
| 834 | */ |
Samuel Pitoiset | a5319d9 | 2017-08-24 14:47:15 +0200 | [diff] [blame] | 835 | static ALWAYS_INLINE void |
| 836 | transform_feedback_varyings(struct gl_context *ctx, |
| 837 | struct gl_shader_program *shProg, GLsizei count, |
| 838 | const GLchar *const *varyings, GLenum bufferMode) |
| 839 | { |
| 840 | GLint i; |
| 841 | |
| 842 | /* free existing varyings, if any */ |
| 843 | for (i = 0; i < (GLint) shProg->TransformFeedback.NumVarying; i++) { |
| 844 | free(shProg->TransformFeedback.VaryingNames[i]); |
| 845 | } |
| 846 | free(shProg->TransformFeedback.VaryingNames); |
| 847 | |
| 848 | /* allocate new memory for varying names */ |
| 849 | shProg->TransformFeedback.VaryingNames = |
| 850 | malloc(count * sizeof(GLchar *)); |
| 851 | |
| 852 | if (!shProg->TransformFeedback.VaryingNames) { |
| 853 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTransformFeedbackVaryings()"); |
| 854 | return; |
| 855 | } |
| 856 | |
| 857 | /* Save the new names and the count */ |
| 858 | for (i = 0; i < count; i++) { |
| 859 | shProg->TransformFeedback.VaryingNames[i] = strdup(varyings[i]); |
| 860 | } |
| 861 | shProg->TransformFeedback.NumVarying = count; |
| 862 | |
| 863 | shProg->TransformFeedback.BufferMode = bufferMode; |
| 864 | |
| 865 | /* No need to invoke FLUSH_VERTICES or flag NewTransformFeedback since |
| 866 | * the varyings won't be used until shader link time. |
| 867 | */ |
| 868 | } |
| 869 | |
| 870 | |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 871 | void GLAPIENTRY |
Samuel Pitoiset | 83690d4 | 2017-08-24 14:50:11 +0200 | [diff] [blame^] | 872 | _mesa_TransformFeedbackVaryings_no_error(GLuint program, GLsizei count, |
| 873 | const GLchar *const *varyings, |
| 874 | GLenum bufferMode) |
| 875 | { |
| 876 | GET_CURRENT_CONTEXT(ctx); |
| 877 | |
| 878 | struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, program); |
| 879 | transform_feedback_varyings(ctx, shProg, count, varyings, bufferMode); |
| 880 | } |
| 881 | |
| 882 | void GLAPIENTRY |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 883 | _mesa_TransformFeedbackVaryings(GLuint program, GLsizei count, |
Paul Berry | bb3db38 | 2012-11-06 07:26:56 -0800 | [diff] [blame] | 884 | const GLchar * const *varyings, |
| 885 | GLenum bufferMode) |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 886 | { |
| 887 | struct gl_shader_program *shProg; |
Brian Paul | 8e45e38 | 2012-10-27 08:58:19 -0600 | [diff] [blame] | 888 | GLint i; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 889 | GET_CURRENT_CONTEXT(ctx); |
| 890 | |
Kenneth Graunke | a7d616d | 2013-09-06 12:38:12 -0700 | [diff] [blame] | 891 | /* From the ARB_transform_feedback2 specification: |
| 892 | * "The error INVALID_OPERATION is generated by TransformFeedbackVaryings |
| 893 | * if the current transform feedback object is active, even if paused." |
| 894 | */ |
| 895 | if (ctx->TransformFeedback.CurrentObject->Active) { |
| 896 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 897 | "glTransformFeedbackVaryings(current object is active)"); |
| 898 | return; |
| 899 | } |
| 900 | |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 901 | switch (bufferMode) { |
| 902 | case GL_INTERLEAVED_ATTRIBS: |
| 903 | break; |
| 904 | case GL_SEPARATE_ATTRIBS: |
| 905 | break; |
| 906 | default: |
| 907 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 908 | "glTransformFeedbackVaryings(bufferMode)"); |
| 909 | return; |
| 910 | } |
| 911 | |
Marek Olšák | f77aa27 | 2011-10-24 02:21:48 +0200 | [diff] [blame] | 912 | if (count < 0 || |
| 913 | (bufferMode == GL_SEPARATE_ATTRIBS && |
Marek Olšák | 15ac66e | 2011-12-18 02:13:17 +0100 | [diff] [blame] | 914 | (GLuint) count > ctx->Const.MaxTransformFeedbackBuffers)) { |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 915 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 916 | "glTransformFeedbackVaryings(count=%d)", count); |
| 917 | return; |
| 918 | } |
| 919 | |
Tapani Pälli | fc8b358 | 2016-10-10 09:49:36 +0300 | [diff] [blame] | 920 | shProg = _mesa_lookup_shader_program_err(ctx, program, |
| 921 | "glTransformFeedbackVaryings"); |
| 922 | if (!shProg) |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 923 | return; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 924 | |
Marek Olšák | 375e73d | 2011-12-18 02:43:31 +0100 | [diff] [blame] | 925 | if (ctx->Extensions.ARB_transform_feedback3) { |
| 926 | if (bufferMode == GL_INTERLEAVED_ATTRIBS) { |
| 927 | unsigned buffers = 1; |
| 928 | |
| 929 | for (i = 0; i < count; i++) { |
| 930 | if (strcmp(varyings[i], "gl_NextBuffer") == 0) |
| 931 | buffers++; |
| 932 | } |
| 933 | |
| 934 | if (buffers > ctx->Const.MaxTransformFeedbackBuffers) { |
| 935 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 936 | "glTransformFeedbackVaryings(too many gl_NextBuffer " |
Andreas Boll | c83e161 | 2015-12-09 17:10:33 +0100 | [diff] [blame] | 937 | "occurrences)"); |
Marek Olšák | 375e73d | 2011-12-18 02:43:31 +0100 | [diff] [blame] | 938 | return; |
| 939 | } |
| 940 | } else { |
| 941 | for (i = 0; i < count; i++) { |
| 942 | if (strcmp(varyings[i], "gl_NextBuffer") == 0 || |
| 943 | strcmp(varyings[i], "gl_SkipComponents1") == 0 || |
| 944 | strcmp(varyings[i], "gl_SkipComponents2") == 0 || |
| 945 | strcmp(varyings[i], "gl_SkipComponents3") == 0 || |
| 946 | strcmp(varyings[i], "gl_SkipComponents4") == 0) { |
| 947 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 948 | "glTransformFeedbackVaryings(SEPARATE_ATTRIBS," |
| 949 | "varying=%s)", |
| 950 | varyings[i]); |
| 951 | return; |
| 952 | } |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | |
Samuel Pitoiset | a5319d9 | 2017-08-24 14:47:15 +0200 | [diff] [blame] | 957 | transform_feedback_varyings(ctx, shProg, count, varyings, bufferMode); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | |
| 961 | /** |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 962 | * Get info about the transform feedback outputs which are to be written |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 963 | * to the feedback buffer(s). |
| 964 | */ |
| 965 | void GLAPIENTRY |
| 966 | _mesa_GetTransformFeedbackVarying(GLuint program, GLuint index, |
| 967 | GLsizei bufSize, GLsizei *length, |
| 968 | GLsizei *size, GLenum *type, GLchar *name) |
| 969 | { |
| 970 | const struct gl_shader_program *shProg; |
Tapani Pälli | dc39d84 | 2015-03-12 12:08:56 +0200 | [diff] [blame] | 971 | struct gl_program_resource *res; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 972 | GET_CURRENT_CONTEXT(ctx); |
| 973 | |
Tapani Pälli | fc8b358 | 2016-10-10 09:49:36 +0300 | [diff] [blame] | 974 | shProg = _mesa_lookup_shader_program_err(ctx, program, |
| 975 | "glGetTransformFeedbackVarying"); |
| 976 | if (!shProg) |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 977 | return; |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 978 | |
Tapani Pälli | dc39d84 | 2015-03-12 12:08:56 +0200 | [diff] [blame] | 979 | res = _mesa_program_resource_find_index((struct gl_shader_program *) shProg, |
| 980 | GL_TRANSFORM_FEEDBACK_VARYING, |
| 981 | index); |
| 982 | if (!res) { |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 983 | _mesa_error(ctx, GL_INVALID_VALUE, |
Matt Turner | 8f3570e | 2012-11-22 00:06:03 -0800 | [diff] [blame] | 984 | "glGetTransformFeedbackVarying(index=%u)", index); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 985 | return; |
| 986 | } |
| 987 | |
Eric Anholt | 9d36c96 | 2012-01-02 17:08:13 -0800 | [diff] [blame] | 988 | /* return the varying's name and length */ |
Tapani Pälli | dc39d84 | 2015-03-12 12:08:56 +0200 | [diff] [blame] | 989 | _mesa_copy_string(name, bufSize, length, _mesa_program_resource_name(res)); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 990 | |
Eric Anholt | 9d36c96 | 2012-01-02 17:08:13 -0800 | [diff] [blame] | 991 | /* return the datatype and value's size (in datatype units) */ |
| 992 | if (type) |
Tapani Pälli | dc39d84 | 2015-03-12 12:08:56 +0200 | [diff] [blame] | 993 | _mesa_program_resource_prop((struct gl_shader_program *) shProg, |
| 994 | res, index, GL_TYPE, (GLint*) type, |
| 995 | "glGetTransformFeedbackVarying"); |
Eric Anholt | 9d36c96 | 2012-01-02 17:08:13 -0800 | [diff] [blame] | 996 | if (size) |
Tapani Pälli | dc39d84 | 2015-03-12 12:08:56 +0200 | [diff] [blame] | 997 | _mesa_program_resource_prop((struct gl_shader_program *) shProg, |
| 998 | res, index, GL_ARRAY_SIZE, (GLint*) size, |
| 999 | "glGetTransformFeedbackVarying"); |
Brian Paul | de8530e | 2010-03-30 19:50:11 -0600 | [diff] [blame] | 1000 | } |
| 1001 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1002 | |
| 1003 | |
Marek Olšák | 14bb957 | 2011-12-09 17:00:23 +0100 | [diff] [blame] | 1004 | struct gl_transform_feedback_object * |
| 1005 | _mesa_lookup_transform_feedback_object(struct gl_context *ctx, GLuint name) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1006 | { |
Martin Peres | a5d165a | 2015-01-20 16:30:32 +0200 | [diff] [blame] | 1007 | /* OpenGL 4.5 core profile, 13.2 pdf page 444: "xfb must be zero, indicating |
| 1008 | * the default transform feedback object, or the name of an existing |
| 1009 | * transform feedback object." |
| 1010 | */ |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1011 | if (name == 0) { |
| 1012 | return ctx->TransformFeedback.DefaultObject; |
| 1013 | } |
| 1014 | else |
| 1015 | return (struct gl_transform_feedback_object *) |
Timothy Arceri | 918cec8 | 2017-04-07 11:40:40 +1000 | [diff] [blame] | 1016 | _mesa_HashLookupLocked(ctx->TransformFeedback.Objects, name); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1017 | } |
| 1018 | |
Martin Peres | c86cb2d | 2015-01-14 18:17:21 +0200 | [diff] [blame] | 1019 | static void |
| 1020 | create_transform_feedbacks(struct gl_context *ctx, GLsizei n, GLuint *ids, |
| 1021 | bool dsa) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1022 | { |
| 1023 | GLuint first; |
Martin Peres | c86cb2d | 2015-01-14 18:17:21 +0200 | [diff] [blame] | 1024 | const char* func; |
| 1025 | |
| 1026 | if (dsa) |
| 1027 | func = "glCreateTransformFeedbacks"; |
| 1028 | else |
| 1029 | func = "glGenTransformFeedbacks"; |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1030 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1031 | if (n < 0) { |
Martin Peres | c86cb2d | 2015-01-14 18:17:21 +0200 | [diff] [blame] | 1032 | _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1033 | return; |
| 1034 | } |
| 1035 | |
Martin Peres | c86cb2d | 2015-01-14 18:17:21 +0200 | [diff] [blame] | 1036 | if (!ids) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1037 | return; |
| 1038 | |
| 1039 | /* we don't need contiguous IDs, but this might be faster */ |
| 1040 | first = _mesa_HashFindFreeKeyBlock(ctx->TransformFeedback.Objects, n); |
| 1041 | if (first) { |
| 1042 | GLsizei i; |
| 1043 | for (i = 0; i < n; i++) { |
| 1044 | struct gl_transform_feedback_object *obj |
| 1045 | = ctx->Driver.NewTransformFeedback(ctx, first + i); |
| 1046 | if (!obj) { |
Martin Peres | c86cb2d | 2015-01-14 18:17:21 +0200 | [diff] [blame] | 1047 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1048 | return; |
| 1049 | } |
Martin Peres | c86cb2d | 2015-01-14 18:17:21 +0200 | [diff] [blame] | 1050 | ids[i] = first + i; |
Timothy Arceri | 918cec8 | 2017-04-07 11:40:40 +1000 | [diff] [blame] | 1051 | _mesa_HashInsertLocked(ctx->TransformFeedback.Objects, first + i, |
| 1052 | obj); |
Martin Peres | c86cb2d | 2015-01-14 18:17:21 +0200 | [diff] [blame] | 1053 | if (dsa) { |
| 1054 | /* this is normally done at bind time in the non-dsa case */ |
| 1055 | obj->EverBound = GL_TRUE; |
| 1056 | } |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | else { |
Martin Peres | c86cb2d | 2015-01-14 18:17:21 +0200 | [diff] [blame] | 1060 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1061 | } |
| 1062 | } |
| 1063 | |
Martin Peres | c86cb2d | 2015-01-14 18:17:21 +0200 | [diff] [blame] | 1064 | /** |
| 1065 | * Create new transform feedback objects. Transform feedback objects |
| 1066 | * encapsulate the state related to transform feedback to allow quickly |
| 1067 | * switching state (and drawing the results, below). |
| 1068 | * Part of GL_ARB_transform_feedback2. |
| 1069 | */ |
| 1070 | void GLAPIENTRY |
| 1071 | _mesa_GenTransformFeedbacks(GLsizei n, GLuint *names) |
| 1072 | { |
| 1073 | GET_CURRENT_CONTEXT(ctx); |
| 1074 | |
| 1075 | /* GenTransformFeedbacks should just reserve the object names that a |
| 1076 | * subsequent call to BindTransformFeedback should actively create. For |
| 1077 | * the sake of simplicity, we reserve the names and create the objects |
| 1078 | * straight away. |
| 1079 | */ |
| 1080 | |
| 1081 | create_transform_feedbacks(ctx, n, names, false); |
| 1082 | } |
| 1083 | |
| 1084 | /** |
| 1085 | * Create new transform feedback objects. Transform feedback objects |
| 1086 | * encapsulate the state related to transform feedback to allow quickly |
| 1087 | * switching state (and drawing the results, below). |
| 1088 | * Part of GL_ARB_direct_state_access. |
| 1089 | */ |
| 1090 | void GLAPIENTRY |
| 1091 | _mesa_CreateTransformFeedbacks(GLsizei n, GLuint *names) |
| 1092 | { |
| 1093 | GET_CURRENT_CONTEXT(ctx); |
| 1094 | |
| 1095 | create_transform_feedbacks(ctx, n, names, true); |
| 1096 | } |
| 1097 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1098 | |
| 1099 | /** |
| 1100 | * Is the given ID a transform feedback object? |
| 1101 | * Part of GL_ARB_transform_feedback2. |
| 1102 | */ |
| 1103 | GLboolean GLAPIENTRY |
| 1104 | _mesa_IsTransformFeedback(GLuint name) |
| 1105 | { |
Matt Turner | fd93d55 | 2012-12-19 13:43:31 -0800 | [diff] [blame] | 1106 | struct gl_transform_feedback_object *obj; |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1107 | GET_CURRENT_CONTEXT(ctx); |
| 1108 | |
| 1109 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); |
| 1110 | |
Matt Turner | fd93d55 | 2012-12-19 13:43:31 -0800 | [diff] [blame] | 1111 | if (name == 0) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1112 | return GL_FALSE; |
Matt Turner | fd93d55 | 2012-12-19 13:43:31 -0800 | [diff] [blame] | 1113 | |
| 1114 | obj = _mesa_lookup_transform_feedback_object(ctx, name); |
| 1115 | if (obj == NULL) |
| 1116 | return GL_FALSE; |
| 1117 | |
| 1118 | return obj->EverBound; |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | /** |
| 1123 | * Bind the given transform feedback object. |
| 1124 | * Part of GL_ARB_transform_feedback2. |
| 1125 | */ |
Samuel Pitoiset | efb9811 | 2017-08-24 11:39:59 +0200 | [diff] [blame] | 1126 | static ALWAYS_INLINE void |
| 1127 | bind_transform_feedback(struct gl_context *ctx, GLuint name, bool no_error) |
| 1128 | { |
| 1129 | struct gl_transform_feedback_object *obj; |
| 1130 | |
| 1131 | obj = _mesa_lookup_transform_feedback_object(ctx, name); |
| 1132 | if (!no_error && !obj) { |
| 1133 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1134 | "glBindTransformFeedback(name=%u)", name); |
| 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | reference_transform_feedback_object(&ctx->TransformFeedback.CurrentObject, |
| 1139 | obj); |
| 1140 | } |
| 1141 | |
| 1142 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1143 | void GLAPIENTRY |
Samuel Pitoiset | b0590ac | 2017-08-24 11:41:15 +0200 | [diff] [blame] | 1144 | _mesa_BindTransformFeedback_no_error(GLenum target, GLuint name) |
| 1145 | { |
| 1146 | GET_CURRENT_CONTEXT(ctx); |
| 1147 | bind_transform_feedback(ctx, name, true); |
| 1148 | } |
| 1149 | |
| 1150 | |
| 1151 | void GLAPIENTRY |
Vinson Lee | d74f525 | 2010-05-10 22:58:23 -0700 | [diff] [blame] | 1152 | _mesa_BindTransformFeedback(GLenum target, GLuint name) |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1153 | { |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1154 | GET_CURRENT_CONTEXT(ctx); |
| 1155 | |
| 1156 | if (target != GL_TRANSFORM_FEEDBACK) { |
| 1157 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindTransformFeedback(target)"); |
| 1158 | return; |
| 1159 | } |
| 1160 | |
Paul Berry | 5b7099c | 2012-12-15 14:21:32 -0800 | [diff] [blame] | 1161 | if (_mesa_is_xfb_active_and_unpaused(ctx)) { |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1162 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Brian Paul | 39c13a1 | 2010-05-14 08:03:42 -0600 | [diff] [blame] | 1163 | "glBindTransformFeedback(transform is active, or not paused)"); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1164 | return; |
| 1165 | } |
| 1166 | |
Samuel Pitoiset | efb9811 | 2017-08-24 11:39:59 +0200 | [diff] [blame] | 1167 | bind_transform_feedback(ctx, name, false); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | |
| 1171 | /** |
| 1172 | * Delete the given transform feedback objects. |
| 1173 | * Part of GL_ARB_transform_feedback2. |
| 1174 | */ |
| 1175 | void GLAPIENTRY |
| 1176 | _mesa_DeleteTransformFeedbacks(GLsizei n, const GLuint *names) |
| 1177 | { |
| 1178 | GLint i; |
| 1179 | GET_CURRENT_CONTEXT(ctx); |
| 1180 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1181 | if (n < 0) { |
| 1182 | _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteTransformFeedbacks(n < 0)"); |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | if (!names) |
| 1187 | return; |
| 1188 | |
| 1189 | for (i = 0; i < n; i++) { |
| 1190 | if (names[i] > 0) { |
| 1191 | struct gl_transform_feedback_object *obj |
Marek Olšák | 14bb957 | 2011-12-09 17:00:23 +0100 | [diff] [blame] | 1192 | = _mesa_lookup_transform_feedback_object(ctx, names[i]); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1193 | if (obj) { |
| 1194 | if (obj->Active) { |
| 1195 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1196 | "glDeleteTransformFeedbacks(object %u is active)", |
| 1197 | names[i]); |
| 1198 | return; |
| 1199 | } |
Timothy Arceri | 918cec8 | 2017-04-07 11:40:40 +1000 | [diff] [blame] | 1200 | _mesa_HashRemoveLocked(ctx->TransformFeedback.Objects, names[i]); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1201 | /* unref, but object may not be deleted until later */ |
Ilia Mirkin | 0941ef3 | 2016-03-06 12:36:19 -0500 | [diff] [blame] | 1202 | if (obj == ctx->TransformFeedback.CurrentObject) { |
| 1203 | reference_transform_feedback_object( |
| 1204 | &ctx->TransformFeedback.CurrentObject, |
| 1205 | ctx->TransformFeedback.DefaultObject); |
| 1206 | } |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1207 | reference_transform_feedback_object(&obj, NULL); |
| 1208 | } |
| 1209 | } |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | |
| 1214 | /** |
| 1215 | * Pause transform feedback. |
| 1216 | * Part of GL_ARB_transform_feedback2. |
| 1217 | */ |
Samuel Pitoiset | 061a1ee | 2017-08-24 12:29:50 +0200 | [diff] [blame] | 1218 | static void |
| 1219 | pause_transform_feedback(struct gl_context *ctx, |
| 1220 | struct gl_transform_feedback_object *obj) |
| 1221 | { |
| 1222 | FLUSH_VERTICES(ctx, 0); |
| 1223 | ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback; |
| 1224 | |
| 1225 | assert(ctx->Driver.PauseTransformFeedback); |
| 1226 | ctx->Driver.PauseTransformFeedback(ctx, obj); |
| 1227 | |
| 1228 | obj->Paused = GL_TRUE; |
| 1229 | } |
| 1230 | |
| 1231 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1232 | void GLAPIENTRY |
Samuel Pitoiset | 1c88ed9 | 2017-08-24 12:06:26 +0200 | [diff] [blame] | 1233 | _mesa_PauseTransformFeedback_no_error(void) |
| 1234 | { |
| 1235 | GET_CURRENT_CONTEXT(ctx); |
| 1236 | pause_transform_feedback(ctx, ctx->TransformFeedback.CurrentObject); |
| 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | void GLAPIENTRY |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1241 | _mesa_PauseTransformFeedback(void) |
| 1242 | { |
| 1243 | struct gl_transform_feedback_object *obj; |
| 1244 | GET_CURRENT_CONTEXT(ctx); |
| 1245 | |
| 1246 | obj = ctx->TransformFeedback.CurrentObject; |
| 1247 | |
Paul Berry | 5b7099c | 2012-12-15 14:21:32 -0800 | [diff] [blame] | 1248 | if (!_mesa_is_xfb_active_and_unpaused(ctx)) { |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1249 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 1250 | "glPauseTransformFeedback(feedback not active or already paused)"); |
| 1251 | return; |
| 1252 | } |
| 1253 | |
Samuel Pitoiset | 061a1ee | 2017-08-24 12:29:50 +0200 | [diff] [blame] | 1254 | pause_transform_feedback(ctx, obj); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | |
| 1258 | /** |
| 1259 | * Resume transform feedback. |
| 1260 | * Part of GL_ARB_transform_feedback2. |
| 1261 | */ |
Samuel Pitoiset | f0476e0 | 2017-08-24 12:09:23 +0200 | [diff] [blame] | 1262 | static void |
| 1263 | resume_transform_feedback(struct gl_context *ctx, |
| 1264 | struct gl_transform_feedback_object *obj) |
| 1265 | { |
| 1266 | FLUSH_VERTICES(ctx, 0); |
| 1267 | ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback; |
| 1268 | |
| 1269 | obj->Paused = GL_FALSE; |
| 1270 | |
| 1271 | assert(ctx->Driver.ResumeTransformFeedback); |
| 1272 | ctx->Driver.ResumeTransformFeedback(ctx, obj); |
| 1273 | } |
| 1274 | |
| 1275 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1276 | void GLAPIENTRY |
Samuel Pitoiset | 4b5140d | 2017-08-24 12:10:57 +0200 | [diff] [blame] | 1277 | _mesa_ResumeTransformFeedback_no_error(void) |
| 1278 | { |
| 1279 | GET_CURRENT_CONTEXT(ctx); |
| 1280 | resume_transform_feedback(ctx, ctx->TransformFeedback.CurrentObject); |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | void GLAPIENTRY |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1285 | _mesa_ResumeTransformFeedback(void) |
| 1286 | { |
| 1287 | struct gl_transform_feedback_object *obj; |
| 1288 | GET_CURRENT_CONTEXT(ctx); |
| 1289 | |
| 1290 | obj = ctx->TransformFeedback.CurrentObject; |
| 1291 | |
| 1292 | if (!obj->Active || !obj->Paused) { |
| 1293 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Brian Paul | 076bd11 | 2011-04-29 18:42:09 -0600 | [diff] [blame] | 1294 | "glResumeTransformFeedback(feedback not active or not paused)"); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1295 | return; |
| 1296 | } |
| 1297 | |
Kenneth Graunke | 9cc74c9 | 2013-09-06 14:51:26 -0700 | [diff] [blame] | 1298 | /* From the ARB_transform_feedback2 specification: |
| 1299 | * "The error INVALID_OPERATION is generated by ResumeTransformFeedback if |
| 1300 | * the program object being used by the current transform feedback object |
| 1301 | * is not active." |
| 1302 | */ |
Timothy Arceri | 3177eef | 2016-11-03 14:35:08 +1100 | [diff] [blame] | 1303 | if (obj->program != get_xfb_source(ctx)) { |
Kenneth Graunke | 9cc74c9 | 2013-09-06 14:51:26 -0700 | [diff] [blame] | 1304 | _mesa_error(ctx, GL_INVALID_OPERATION, |
Paul Berry | e190709 | 2014-01-22 05:14:48 -0800 | [diff] [blame] | 1305 | "glResumeTransformFeedback(wrong program bound)"); |
Kenneth Graunke | 9cc74c9 | 2013-09-06 14:51:26 -0700 | [diff] [blame] | 1306 | return; |
| 1307 | } |
| 1308 | |
Samuel Pitoiset | f0476e0 | 2017-08-24 12:09:23 +0200 | [diff] [blame] | 1309 | resume_transform_feedback(ctx, obj); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 1310 | } |
Martin Peres | e59d243 | 2015-02-16 16:13:58 +0200 | [diff] [blame] | 1311 | |
| 1312 | extern void GLAPIENTRY |
| 1313 | _mesa_GetTransformFeedbackiv(GLuint xfb, GLenum pname, GLint *param) |
| 1314 | { |
| 1315 | struct gl_transform_feedback_object *obj; |
| 1316 | GET_CURRENT_CONTEXT(ctx); |
| 1317 | |
| 1318 | obj = lookup_transform_feedback_object_err(ctx, xfb, |
| 1319 | "glGetTransformFeedbackiv"); |
| 1320 | if(!obj) { |
| 1321 | return; |
| 1322 | } |
| 1323 | |
| 1324 | switch(pname) { |
| 1325 | case GL_TRANSFORM_FEEDBACK_PAUSED: |
| 1326 | *param = obj->Paused; |
| 1327 | break; |
| 1328 | case GL_TRANSFORM_FEEDBACK_ACTIVE: |
| 1329 | *param = obj->Active; |
| 1330 | break; |
| 1331 | default: |
| 1332 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1333 | "glGetTransformFeedbackiv(pname=%i)", pname); |
| 1334 | } |
| 1335 | } |
Martin Peres | 8799ecd | 2015-02-16 16:13:59 +0200 | [diff] [blame] | 1336 | |
| 1337 | extern void GLAPIENTRY |
| 1338 | _mesa_GetTransformFeedbacki_v(GLuint xfb, GLenum pname, GLuint index, |
| 1339 | GLint *param) |
| 1340 | { |
| 1341 | struct gl_transform_feedback_object *obj; |
| 1342 | GET_CURRENT_CONTEXT(ctx); |
| 1343 | |
| 1344 | obj = lookup_transform_feedback_object_err(ctx, xfb, |
| 1345 | "glGetTransformFeedbacki_v"); |
| 1346 | if(!obj) { |
| 1347 | return; |
| 1348 | } |
| 1349 | |
| 1350 | if (index >= ctx->Const.MaxTransformFeedbackBuffers) { |
| 1351 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1352 | "glGetTransformFeedbacki_v(index=%i)", index); |
| 1353 | return; |
| 1354 | } |
| 1355 | |
| 1356 | switch(pname) { |
| 1357 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 1358 | *param = obj->BufferNames[index]; |
| 1359 | break; |
| 1360 | default: |
| 1361 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1362 | "glGetTransformFeedbacki_v(pname=%i)", pname); |
| 1363 | } |
| 1364 | } |
Martin Peres | 6ead10d | 2015-01-22 16:55:29 +0200 | [diff] [blame] | 1365 | |
| 1366 | extern void GLAPIENTRY |
| 1367 | _mesa_GetTransformFeedbacki64_v(GLuint xfb, GLenum pname, GLuint index, |
| 1368 | GLint64 *param) |
| 1369 | { |
| 1370 | struct gl_transform_feedback_object *obj; |
| 1371 | GET_CURRENT_CONTEXT(ctx); |
| 1372 | |
| 1373 | obj = lookup_transform_feedback_object_err(ctx, xfb, |
| 1374 | "glGetTransformFeedbacki64_v"); |
| 1375 | if(!obj) { |
| 1376 | return; |
| 1377 | } |
| 1378 | |
| 1379 | if (index >= ctx->Const.MaxTransformFeedbackBuffers) { |
| 1380 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 1381 | "glGetTransformFeedbacki64_v(index=%i)", index); |
| 1382 | return; |
| 1383 | } |
| 1384 | |
Dave Airlie | bac39dd | 2016-05-30 06:56:52 +1000 | [diff] [blame] | 1385 | compute_transform_feedback_buffer_sizes(obj); |
Martin Peres | 6ead10d | 2015-01-22 16:55:29 +0200 | [diff] [blame] | 1386 | switch(pname) { |
| 1387 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
| 1388 | *param = obj->Offset[index]; |
| 1389 | break; |
| 1390 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
Dave Airlie | bac39dd | 2016-05-30 06:56:52 +1000 | [diff] [blame] | 1391 | *param = obj->Size[index]; |
Martin Peres | 6ead10d | 2015-01-22 16:55:29 +0200 | [diff] [blame] | 1392 | break; |
| 1393 | default: |
| 1394 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 1395 | "glGetTransformFeedbacki64_v(pname=%i)", pname); |
| 1396 | } |
| 1397 | } |