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