2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * \brief Functions for the GL_ARB_vertex/pixel_buffer_object extensions.
30 * \author Brian Paul, Ian Romanick
34 #include <inttypes.h> /* for PRId64 macro */
35 #include "util/debug.h"
41 #include "bufferobj.h"
44 #include "glformats.h"
46 #include "transformfeedback.h"
52 /*#define BOUNDS_CHECK*/
56 * We count the number of buffer modification calls to check for
57 * inefficient buffer use. This is the number of such calls before we
60 #define BUFFER_WARNING_CALL_COUNT 4
64 * Helper to warn of possible performance issues, such as frequently
65 * updating a buffer created with GL_STATIC_DRAW. Called via the macro
69 buffer_usage_warning(struct gl_context
*ctx
, GLuint
*id
, const char *fmt
, ...)
74 _mesa_gl_vdebug(ctx
, id
,
75 MESA_DEBUG_SOURCE_API
,
76 MESA_DEBUG_TYPE_PERFORMANCE
,
77 MESA_DEBUG_SEVERITY_MEDIUM
,
82 #define BUFFER_USAGE_WARNING(CTX, FMT, ...) \
84 static GLuint id = 0; \
85 buffer_usage_warning(CTX, &id, FMT, ##__VA_ARGS__); \
90 * Used as a placeholder for buffer objects between glGenBuffers() and
91 * glBindBuffer() so that glIsBuffer() can work correctly.
93 static struct gl_buffer_object DummyBufferObject
;
97 * Return pointer to address of a buffer object target.
98 * \param ctx the GL context
99 * \param target the buffer object target to be retrieved.
100 * \return pointer to pointer to the buffer object bound to \c target in the
101 * specified context or \c NULL if \c target is invalid.
103 static inline struct gl_buffer_object
**
104 get_buffer_target(struct gl_context
*ctx
, GLenum target
)
106 /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0.
108 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
)
109 && target
!= GL_ARRAY_BUFFER
&& target
!= GL_ELEMENT_ARRAY_BUFFER
)
113 case GL_ARRAY_BUFFER_ARB
:
114 return &ctx
->Array
.ArrayBufferObj
;
115 case GL_ELEMENT_ARRAY_BUFFER_ARB
:
116 return &ctx
->Array
.VAO
->IndexBufferObj
;
117 case GL_PIXEL_PACK_BUFFER_EXT
:
118 return &ctx
->Pack
.BufferObj
;
119 case GL_PIXEL_UNPACK_BUFFER_EXT
:
120 return &ctx
->Unpack
.BufferObj
;
121 case GL_COPY_READ_BUFFER
:
122 return &ctx
->CopyReadBuffer
;
123 case GL_COPY_WRITE_BUFFER
:
124 return &ctx
->CopyWriteBuffer
;
125 case GL_QUERY_BUFFER
:
126 if (_mesa_has_ARB_query_buffer_object(ctx
))
127 return &ctx
->QueryBuffer
;
129 case GL_DRAW_INDIRECT_BUFFER
:
130 if ((ctx
->API
== API_OPENGL_CORE
&&
131 ctx
->Extensions
.ARB_draw_indirect
) ||
132 _mesa_is_gles31(ctx
)) {
133 return &ctx
->DrawIndirectBuffer
;
136 case GL_PARAMETER_BUFFER_ARB
:
137 if (_mesa_has_ARB_indirect_parameters(ctx
)) {
138 return &ctx
->ParameterBuffer
;
141 case GL_DISPATCH_INDIRECT_BUFFER
:
142 if (_mesa_has_compute_shaders(ctx
)) {
143 return &ctx
->DispatchIndirectBuffer
;
146 case GL_TRANSFORM_FEEDBACK_BUFFER
:
147 if (ctx
->Extensions
.EXT_transform_feedback
) {
148 return &ctx
->TransformFeedback
.CurrentBuffer
;
151 case GL_TEXTURE_BUFFER
:
152 if (_mesa_has_ARB_texture_buffer_object(ctx
) ||
153 _mesa_has_OES_texture_buffer(ctx
)) {
154 return &ctx
->Texture
.BufferObject
;
157 case GL_UNIFORM_BUFFER
:
158 if (ctx
->Extensions
.ARB_uniform_buffer_object
) {
159 return &ctx
->UniformBuffer
;
162 case GL_SHADER_STORAGE_BUFFER
:
163 if (ctx
->Extensions
.ARB_shader_storage_buffer_object
) {
164 return &ctx
->ShaderStorageBuffer
;
167 case GL_ATOMIC_COUNTER_BUFFER
:
168 if (ctx
->Extensions
.ARB_shader_atomic_counters
) {
169 return &ctx
->AtomicBuffer
;
172 case GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
:
173 if (ctx
->Extensions
.AMD_pinned_memory
) {
174 return &ctx
->ExternalVirtualMemoryBuffer
;
185 * Get the buffer object bound to the specified target in a GL context.
186 * \param ctx the GL context
187 * \param target the buffer object target to be retrieved.
188 * \param error the GL error to record if target is illegal.
189 * \return pointer to the buffer object bound to \c target in the
190 * specified context or \c NULL if \c target is invalid.
192 static inline struct gl_buffer_object
*
193 get_buffer(struct gl_context
*ctx
, const char *func
, GLenum target
,
196 struct gl_buffer_object
**bufObj
= get_buffer_target(ctx
, target
);
199 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
203 if (!_mesa_is_bufferobj(*bufObj
)) {
204 _mesa_error(ctx
, error
, "%s(no buffer bound)", func
);
213 * Convert a GLbitfield describing the mapped buffer access flags
214 * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
217 simplified_access_mode(struct gl_context
*ctx
, GLbitfield access
)
219 const GLbitfield rwFlags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
220 if ((access
& rwFlags
) == rwFlags
)
221 return GL_READ_WRITE
;
222 if ((access
& GL_MAP_READ_BIT
) == GL_MAP_READ_BIT
)
224 if ((access
& GL_MAP_WRITE_BIT
) == GL_MAP_WRITE_BIT
)
225 return GL_WRITE_ONLY
;
227 /* Otherwise, AccessFlags is zero (the default state).
229 * Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
231 * Name Type Initial Value Legal Values
233 * BUFFER_ACCESS enum READ_WRITE READ_ONLY, WRITE_ONLY
236 * However, table 6.8 in the GL_OES_mapbuffer extension says:
238 * Get Value Type Get Command Value Description
239 * --------- ---- ----------- ----- -----------
240 * BUFFER_ACCESS_OES Z1 GetBufferParameteriv WRITE_ONLY_OES buffer map flag
242 * The difference is because GL_OES_mapbuffer only supports mapping buffers
247 return _mesa_is_gles(ctx
) ? GL_WRITE_ONLY
: GL_READ_WRITE
;
252 * Test if the buffer is mapped, and if so, if the mapped range overlaps the
254 * The regions do not overlap if and only if the end of the given
255 * region is before the mapped region or the start of the given region
256 * is after the mapped region.
258 * \param obj Buffer object target on which to operate.
259 * \param offset Offset of the first byte of the subdata range.
260 * \param size Size, in bytes, of the subdata range.
261 * \return true if ranges overlap, false otherwise
265 bufferobj_range_mapped(const struct gl_buffer_object
*obj
,
266 GLintptr offset
, GLsizeiptr size
)
268 if (_mesa_bufferobj_mapped(obj
, MAP_USER
)) {
269 const GLintptr end
= offset
+ size
;
270 const GLintptr mapEnd
= obj
->Mappings
[MAP_USER
].Offset
+
271 obj
->Mappings
[MAP_USER
].Length
;
273 if (!(end
<= obj
->Mappings
[MAP_USER
].Offset
|| offset
>= mapEnd
)) {
282 * Tests the subdata range parameters and sets the GL error code for
283 * \c glBufferSubDataARB, \c glGetBufferSubDataARB and
284 * \c glClearBufferSubData.
286 * \param ctx GL context.
287 * \param bufObj The buffer object.
288 * \param offset Offset of the first byte of the subdata range.
289 * \param size Size, in bytes, of the subdata range.
290 * \param mappedRange If true, checks if an overlapping range is mapped.
291 * If false, checks if buffer is mapped.
292 * \param caller Name of calling function for recording errors.
293 * \return false if error, true otherwise
295 * \sa glBufferSubDataARB, glGetBufferSubDataARB, glClearBufferSubData
298 buffer_object_subdata_range_good(struct gl_context
*ctx
,
299 const struct gl_buffer_object
*bufObj
,
300 GLintptr offset
, GLsizeiptr size
,
301 bool mappedRange
, const char *caller
)
304 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", caller
);
309 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset < 0)", caller
);
313 if (offset
+ size
> bufObj
->Size
) {
314 _mesa_error(ctx
, GL_INVALID_VALUE
,
315 "%s(offset %lu + size %lu > buffer size %lu)", caller
,
316 (unsigned long) offset
,
317 (unsigned long) size
,
318 (unsigned long) bufObj
->Size
);
322 if (bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
)
326 if (bufferobj_range_mapped(bufObj
, offset
, size
)) {
327 _mesa_error(ctx
, GL_INVALID_OPERATION
,
328 "%s(range is mapped without persistent bit)",
334 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
335 _mesa_error(ctx
, GL_INVALID_OPERATION
,
336 "%s(buffer is mapped without persistent bit)",
347 * Test the format and type parameters and set the GL error code for
348 * \c glClearBufferData and \c glClearBufferSubData.
350 * \param ctx GL context.
351 * \param internalformat Format to which the data is to be converted.
352 * \param format Format of the supplied data.
353 * \param type Type of the supplied data.
354 * \param caller Name of calling function for recording errors.
355 * \return If internalformat, format and type are legal the mesa_format
356 * corresponding to internalformat, otherwise MESA_FORMAT_NONE.
358 * \sa glClearBufferData and glClearBufferSubData
361 validate_clear_buffer_format(struct gl_context
*ctx
,
362 GLenum internalformat
,
363 GLenum format
, GLenum type
,
366 mesa_format mesaFormat
;
367 GLenum errorFormatType
;
369 mesaFormat
= _mesa_validate_texbuffer_format(ctx
, internalformat
);
370 if (mesaFormat
== MESA_FORMAT_NONE
) {
371 _mesa_error(ctx
, GL_INVALID_ENUM
,
372 "%s(invalid internalformat)", caller
);
373 return MESA_FORMAT_NONE
;
376 /* NOTE: not mentioned in ARB_clear_buffer_object but according to
377 * EXT_texture_integer there is no conversion between integer and
378 * non-integer formats
380 if (_mesa_is_enum_format_signed_int(format
) !=
381 _mesa_is_format_integer_color(mesaFormat
)) {
382 _mesa_error(ctx
, GL_INVALID_OPERATION
,
383 "%s(integer vs non-integer)", caller
);
384 return MESA_FORMAT_NONE
;
387 if (!_mesa_is_color_format(format
)) {
388 _mesa_error(ctx
, GL_INVALID_ENUM
,
389 "%s(format is not a color format)", caller
);
390 return MESA_FORMAT_NONE
;
393 errorFormatType
= _mesa_error_check_format_and_type(ctx
, format
, type
);
394 if (errorFormatType
!= GL_NO_ERROR
) {
395 _mesa_error(ctx
, GL_INVALID_ENUM
,
396 "%s(invalid format or type)", caller
);
397 return MESA_FORMAT_NONE
;
405 * Convert user-specified clear value to the specified internal format.
407 * \param ctx GL context.
408 * \param internalformat Format to which the data is converted.
409 * \param clearValue Points to the converted clear value.
410 * \param format Format of the supplied data.
411 * \param type Type of the supplied data.
412 * \param data Data which is to be converted to internalformat.
413 * \param caller Name of calling function for recording errors.
414 * \return true if data could be converted, false otherwise.
416 * \sa glClearBufferData, glClearBufferSubData
419 convert_clear_buffer_data(struct gl_context
*ctx
,
420 mesa_format internalformat
,
421 GLubyte
*clearValue
, GLenum format
, GLenum type
,
422 const GLvoid
*data
, const char *caller
)
424 GLenum internalformatBase
= _mesa_get_format_base_format(internalformat
);
426 if (_mesa_texstore(ctx
, 1, internalformatBase
, internalformat
,
427 0, &clearValue
, 1, 1, 1,
428 format
, type
, data
, &ctx
->Unpack
)) {
432 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
439 * Allocate and initialize a new buffer object.
441 * Default callback for the \c dd_function_table::NewBufferObject() hook.
443 static struct gl_buffer_object
*
444 _mesa_new_buffer_object(struct gl_context
*ctx
, GLuint name
)
446 struct gl_buffer_object
*obj
;
450 obj
= MALLOC_STRUCT(gl_buffer_object
);
451 _mesa_initialize_buffer_object(ctx
, obj
, name
);
457 * Delete a buffer object.
459 * Default callback for the \c dd_function_table::DeleteBuffer() hook.
462 _mesa_delete_buffer_object(struct gl_context
*ctx
,
463 struct gl_buffer_object
*bufObj
)
467 vbo_delete_minmax_cache(bufObj
);
468 _mesa_align_free(bufObj
->Data
);
470 /* assign strange values here to help w/ debugging */
471 bufObj
->RefCount
= -1000;
474 mtx_destroy(&bufObj
->Mutex
);
482 * Set ptr to bufObj w/ reference counting.
483 * This is normally only called from the _mesa_reference_buffer_object() macro
484 * when there's a real pointer change.
487 _mesa_reference_buffer_object_(struct gl_context
*ctx
,
488 struct gl_buffer_object
**ptr
,
489 struct gl_buffer_object
*bufObj
)
492 /* Unreference the old buffer */
493 GLboolean deleteFlag
= GL_FALSE
;
494 struct gl_buffer_object
*oldObj
= *ptr
;
496 mtx_lock(&oldObj
->Mutex
);
497 assert(oldObj
->RefCount
> 0);
499 deleteFlag
= (oldObj
->RefCount
== 0);
500 mtx_unlock(&oldObj
->Mutex
);
503 assert(ctx
->Driver
.DeleteBuffer
);
504 ctx
->Driver
.DeleteBuffer(ctx
, oldObj
);
512 /* reference new buffer */
513 mtx_lock(&bufObj
->Mutex
);
514 assert(bufObj
->RefCount
> 0);
518 mtx_unlock(&bufObj
->Mutex
);
524 * Get the value of MESA_NO_MINMAX_CACHE.
527 get_no_minmax_cache()
529 static bool read
= false;
530 static bool disable
= false;
533 disable
= env_var_as_boolean("MESA_NO_MINMAX_CACHE", false);
542 * Initialize a buffer object to default values.
545 _mesa_initialize_buffer_object(struct gl_context
*ctx
,
546 struct gl_buffer_object
*obj
,
549 memset(obj
, 0, sizeof(struct gl_buffer_object
));
550 mtx_init(&obj
->Mutex
, mtx_plain
);
553 obj
->Usage
= GL_STATIC_DRAW_ARB
;
555 if (get_no_minmax_cache())
556 obj
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
562 * Callback called from _mesa_HashWalk()
565 count_buffer_size(GLuint key
, void *data
, void *userData
)
567 const struct gl_buffer_object
*bufObj
=
568 (const struct gl_buffer_object
*) data
;
569 GLuint
*total
= (GLuint
*) userData
;
572 *total
= *total
+ bufObj
->Size
;
577 * Compute total size (in bytes) of all buffer objects for the given context.
578 * For debugging purposes.
581 _mesa_total_buffer_object_memory(struct gl_context
*ctx
)
585 _mesa_HashWalk(ctx
->Shared
->BufferObjects
, count_buffer_size
, &total
);
592 * Allocate space for and store data in a buffer object. Any data that was
593 * previously stored in the buffer object is lost. If \c data is \c NULL,
594 * memory will be allocated, but no copy will occur.
596 * This is the default callback for \c dd_function_table::BufferData()
597 * Note that all GL error checking will have been done already.
599 * \param ctx GL context.
600 * \param target Buffer object target on which to operate.
601 * \param size Size, in bytes, of the new data store.
602 * \param data Pointer to the data to store in the buffer object. This
603 * pointer may be \c NULL.
604 * \param usage Hints about how the data will be used.
605 * \param bufObj Object to be used.
607 * \return GL_TRUE for success, GL_FALSE for failure
608 * \sa glBufferDataARB, dd_function_table::BufferData.
611 buffer_data_fallback(struct gl_context
*ctx
, GLenum target
, GLsizeiptr size
,
612 const GLvoid
*data
, GLenum usage
, GLenum storageFlags
,
613 struct gl_buffer_object
*bufObj
)
619 _mesa_align_free( bufObj
->Data
);
621 new_data
= _mesa_align_malloc( size
, ctx
->Const
.MinMapBufferAlignment
);
623 bufObj
->Data
= (GLubyte
*) new_data
;
625 bufObj
->Usage
= usage
;
626 bufObj
->StorageFlags
= storageFlags
;
629 memcpy( bufObj
->Data
, data
, size
);
641 * Replace data in a subrange of buffer object. If the data range
642 * specified by \c size + \c offset extends beyond the end of the buffer or
643 * if \c data is \c NULL, no copy is performed.
645 * This is the default callback for \c dd_function_table::BufferSubData()
646 * Note that all GL error checking will have been done already.
648 * \param ctx GL context.
649 * \param offset Offset of the first byte to be modified.
650 * \param size Size, in bytes, of the data range.
651 * \param data Pointer to the data to store in the buffer object.
652 * \param bufObj Object to be used.
654 * \sa glBufferSubDataARB, dd_function_table::BufferSubData.
657 buffer_sub_data_fallback(struct gl_context
*ctx
, GLintptr offset
,
658 GLsizeiptr size
, const GLvoid
*data
,
659 struct gl_buffer_object
*bufObj
)
663 /* this should have been caught in _mesa_BufferSubData() */
664 assert(size
+ offset
<= bufObj
->Size
);
667 memcpy( (GLubyte
*) bufObj
->Data
+ offset
, data
, size
);
673 * Retrieve data from a subrange of buffer object. If the data range
674 * specified by \c size + \c offset extends beyond the end of the buffer or
675 * if \c data is \c NULL, no copy is performed.
677 * This is the default callback for \c dd_function_table::GetBufferSubData()
678 * Note that all GL error checking will have been done already.
680 * \param ctx GL context.
681 * \param target Buffer object target on which to operate.
682 * \param offset Offset of the first byte to be fetched.
683 * \param size Size, in bytes, of the data range.
684 * \param data Destination for data
685 * \param bufObj Object to be used.
687 * \sa glBufferGetSubDataARB, dd_function_table::GetBufferSubData.
690 buffer_get_subdata(struct gl_context
*ctx
, GLintptrARB offset
,
691 GLsizeiptrARB size
, GLvoid
*data
,
692 struct gl_buffer_object
*bufObj
)
696 if (bufObj
->Data
&& ((GLsizeiptrARB
) (size
+ offset
) <= bufObj
->Size
)) {
697 memcpy( data
, (GLubyte
*) bufObj
->Data
+ offset
, size
);
703 * Clear a subrange of the buffer object with copies of the supplied data.
704 * If data is NULL the buffer is filled with zeros.
706 * This is the default callback for \c dd_function_table::ClearBufferSubData()
707 * Note that all GL error checking will have been done already.
709 * \param ctx GL context.
710 * \param offset Offset of the first byte to be cleared.
711 * \param size Size, in bytes, of the to be cleared range.
712 * \param clearValue Source of the data.
713 * \param clearValueSize Size, in bytes, of the supplied data.
714 * \param bufObj Object to be cleared.
716 * \sa glClearBufferSubData, glClearBufferData and
717 * dd_function_table::ClearBufferSubData.
720 _mesa_ClearBufferSubData_sw(struct gl_context
*ctx
,
721 GLintptr offset
, GLsizeiptr size
,
722 const GLvoid
*clearValue
,
723 GLsizeiptr clearValueSize
,
724 struct gl_buffer_object
*bufObj
)
729 assert(ctx
->Driver
.MapBufferRange
);
730 dest
= ctx
->Driver
.MapBufferRange(ctx
, offset
, size
,
732 GL_MAP_INVALIDATE_RANGE_BIT
,
733 bufObj
, MAP_INTERNAL
);
736 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glClearBuffer[Sub]Data");
740 if (clearValue
== NULL
) {
741 /* Clear with zeros, per the spec */
742 memset(dest
, 0, size
);
743 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
747 for (i
= 0; i
< size
/clearValueSize
; ++i
) {
748 memcpy(dest
, clearValue
, clearValueSize
);
749 dest
+= clearValueSize
;
752 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_INTERNAL
);
757 * Default fallback for \c dd_function_table::MapBufferRange().
758 * Called via glMapBufferRange().
761 map_buffer_range_fallback(struct gl_context
*ctx
, GLintptr offset
,
762 GLsizeiptr length
, GLbitfield access
,
763 struct gl_buffer_object
*bufObj
,
764 gl_map_buffer_index index
)
767 assert(!_mesa_bufferobj_mapped(bufObj
, index
));
768 /* Just return a direct pointer to the data */
769 bufObj
->Mappings
[index
].Pointer
= bufObj
->Data
+ offset
;
770 bufObj
->Mappings
[index
].Length
= length
;
771 bufObj
->Mappings
[index
].Offset
= offset
;
772 bufObj
->Mappings
[index
].AccessFlags
= access
;
773 return bufObj
->Mappings
[index
].Pointer
;
778 * Default fallback for \c dd_function_table::FlushMappedBufferRange().
779 * Called via glFlushMappedBufferRange().
782 flush_mapped_buffer_range_fallback(struct gl_context
*ctx
,
783 GLintptr offset
, GLsizeiptr length
,
784 struct gl_buffer_object
*obj
,
785 gl_map_buffer_index index
)
797 * Default callback for \c dd_function_table::UnmapBuffer().
799 * The input parameters will have been already tested for errors.
801 * \sa glUnmapBufferARB, dd_function_table::UnmapBuffer
804 unmap_buffer_fallback(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
805 gl_map_buffer_index index
)
808 /* XXX we might assert here that bufObj->Pointer is non-null */
809 bufObj
->Mappings
[index
].Pointer
= NULL
;
810 bufObj
->Mappings
[index
].Length
= 0;
811 bufObj
->Mappings
[index
].Offset
= 0;
812 bufObj
->Mappings
[index
].AccessFlags
= 0x0;
818 * Default fallback for \c dd_function_table::CopyBufferSubData().
819 * Called via glCopyBufferSubData().
822 copy_buffer_sub_data_fallback(struct gl_context
*ctx
,
823 struct gl_buffer_object
*src
,
824 struct gl_buffer_object
*dst
,
825 GLintptr readOffset
, GLintptr writeOffset
,
828 GLubyte
*srcPtr
, *dstPtr
;
831 srcPtr
= dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, 0, src
->Size
,
833 GL_MAP_WRITE_BIT
, src
,
839 srcPtr
+= readOffset
;
840 dstPtr
+= writeOffset
;
842 srcPtr
= ctx
->Driver
.MapBufferRange(ctx
, readOffset
, size
,
843 GL_MAP_READ_BIT
, src
,
845 dstPtr
= ctx
->Driver
.MapBufferRange(ctx
, writeOffset
, size
,
847 GL_MAP_INVALIDATE_RANGE_BIT
), dst
,
851 /* Note: the src and dst regions will never overlap. Trying to do so
852 * would generate GL_INVALID_VALUE earlier.
854 if (srcPtr
&& dstPtr
)
855 memcpy(dstPtr
, srcPtr
, size
);
857 ctx
->Driver
.UnmapBuffer(ctx
, src
, MAP_INTERNAL
);
859 ctx
->Driver
.UnmapBuffer(ctx
, dst
, MAP_INTERNAL
);
865 * Initialize the state associated with buffer objects
868 _mesa_init_buffer_objects( struct gl_context
*ctx
)
872 memset(&DummyBufferObject
, 0, sizeof(DummyBufferObject
));
873 mtx_init(&DummyBufferObject
.Mutex
, mtx_plain
);
874 DummyBufferObject
.RefCount
= 1000*1000*1000; /* never delete */
876 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
,
877 ctx
->Shared
->NullBufferObj
);
879 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
,
880 ctx
->Shared
->NullBufferObj
);
881 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
,
882 ctx
->Shared
->NullBufferObj
);
884 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
,
885 ctx
->Shared
->NullBufferObj
);
887 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
,
888 ctx
->Shared
->NullBufferObj
);
890 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
,
891 ctx
->Shared
->NullBufferObj
);
893 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
,
894 ctx
->Shared
->NullBufferObj
);
896 _mesa_reference_buffer_object(ctx
, &ctx
->ParameterBuffer
,
897 ctx
->Shared
->NullBufferObj
);
899 _mesa_reference_buffer_object(ctx
, &ctx
->DispatchIndirectBuffer
,
900 ctx
->Shared
->NullBufferObj
);
902 _mesa_reference_buffer_object(ctx
, &ctx
->QueryBuffer
,
903 ctx
->Shared
->NullBufferObj
);
905 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
906 _mesa_reference_buffer_object(ctx
,
907 &ctx
->UniformBufferBindings
[i
].BufferObject
,
908 ctx
->Shared
->NullBufferObj
);
909 ctx
->UniformBufferBindings
[i
].Offset
= -1;
910 ctx
->UniformBufferBindings
[i
].Size
= -1;
913 for (i
= 0; i
< MAX_COMBINED_SHADER_STORAGE_BUFFERS
; i
++) {
914 _mesa_reference_buffer_object(ctx
,
915 &ctx
->ShaderStorageBufferBindings
[i
].BufferObject
,
916 ctx
->Shared
->NullBufferObj
);
917 ctx
->ShaderStorageBufferBindings
[i
].Offset
= -1;
918 ctx
->ShaderStorageBufferBindings
[i
].Size
= -1;
921 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
922 _mesa_reference_buffer_object(ctx
,
923 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
924 ctx
->Shared
->NullBufferObj
);
925 ctx
->AtomicBufferBindings
[i
].Offset
= 0;
926 ctx
->AtomicBufferBindings
[i
].Size
= 0;
932 _mesa_free_buffer_objects( struct gl_context
*ctx
)
936 _mesa_reference_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, NULL
);
938 _mesa_reference_buffer_object(ctx
, &ctx
->CopyReadBuffer
, NULL
);
939 _mesa_reference_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, NULL
);
941 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, NULL
);
943 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, NULL
);
945 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, NULL
);
947 _mesa_reference_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
, NULL
);
949 _mesa_reference_buffer_object(ctx
, &ctx
->ParameterBuffer
, NULL
);
951 _mesa_reference_buffer_object(ctx
, &ctx
->DispatchIndirectBuffer
, NULL
);
953 _mesa_reference_buffer_object(ctx
, &ctx
->QueryBuffer
, NULL
);
955 for (i
= 0; i
< MAX_COMBINED_UNIFORM_BUFFERS
; i
++) {
956 _mesa_reference_buffer_object(ctx
,
957 &ctx
->UniformBufferBindings
[i
].BufferObject
,
961 for (i
= 0; i
< MAX_COMBINED_SHADER_STORAGE_BUFFERS
; i
++) {
962 _mesa_reference_buffer_object(ctx
,
963 &ctx
->ShaderStorageBufferBindings
[i
].BufferObject
,
967 for (i
= 0; i
< MAX_COMBINED_ATOMIC_BUFFERS
; i
++) {
968 _mesa_reference_buffer_object(ctx
,
969 &ctx
->AtomicBufferBindings
[i
].BufferObject
,
976 _mesa_handle_bind_buffer_gen(struct gl_context
*ctx
,
978 struct gl_buffer_object
**buf_handle
,
981 struct gl_buffer_object
*buf
= *buf_handle
;
983 if (!buf
&& (ctx
->API
== API_OPENGL_CORE
)) {
984 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", caller
);
988 if (!buf
|| buf
== &DummyBufferObject
) {
989 /* If this is a new buffer object id, or one which was generated but
990 * never used before, allocate a buffer object now.
992 assert(ctx
->Driver
.NewBufferObject
);
993 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffer
);
995 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
998 _mesa_HashInsert(ctx
->Shared
->BufferObjects
, buffer
, buf
);
1006 * Bind the specified target to buffer for the specified context.
1007 * Called by glBindBuffer() and other functions.
1010 bind_buffer_object(struct gl_context
*ctx
,
1011 struct gl_buffer_object
**bindTarget
, GLuint buffer
)
1013 struct gl_buffer_object
*oldBufObj
;
1014 struct gl_buffer_object
*newBufObj
= NULL
;
1018 /* Get pointer to old buffer object (to be unbound) */
1019 oldBufObj
= *bindTarget
;
1020 if (oldBufObj
&& oldBufObj
->Name
== buffer
&& !oldBufObj
->DeletePending
)
1021 return; /* rebinding the same buffer object- no change */
1024 * Get pointer to new buffer object (newBufObj)
1027 /* The spec says there's not a buffer object named 0, but we use
1028 * one internally because it simplifies things.
1030 newBufObj
= ctx
->Shared
->NullBufferObj
;
1033 /* non-default buffer object */
1034 newBufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
1035 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
,
1036 &newBufObj
, "glBindBuffer"))
1040 /* record usage history */
1041 if (bindTarget
== &ctx
->Pack
.BufferObj
) {
1042 newBufObj
->UsageHistory
|= USAGE_PIXEL_PACK_BUFFER
;
1045 /* bind new buffer */
1046 _mesa_reference_buffer_object(ctx
, bindTarget
, newBufObj
);
1051 * Update the default buffer objects in the given context to reference those
1052 * specified in the shared state and release those referencing the old
1056 _mesa_update_default_objects_buffer_objects(struct gl_context
*ctx
)
1058 /* Bind the NullBufferObj to remove references to those
1059 * in the shared context hash table.
1061 bind_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, 0);
1062 bind_buffer_object(ctx
, &ctx
->Array
.VAO
->IndexBufferObj
, 0);
1063 bind_buffer_object(ctx
, &ctx
->Pack
.BufferObj
, 0);
1064 bind_buffer_object(ctx
, &ctx
->Unpack
.BufferObj
, 0);
1070 * Return the gl_buffer_object for the given ID.
1071 * Always return NULL for ID 0.
1073 struct gl_buffer_object
*
1074 _mesa_lookup_bufferobj(struct gl_context
*ctx
, GLuint buffer
)
1079 return (struct gl_buffer_object
*)
1080 _mesa_HashLookup(ctx
->Shared
->BufferObjects
, buffer
);
1084 struct gl_buffer_object
*
1085 _mesa_lookup_bufferobj_locked(struct gl_context
*ctx
, GLuint buffer
)
1090 return (struct gl_buffer_object
*)
1091 _mesa_HashLookupLocked(ctx
->Shared
->BufferObjects
, buffer
);
1095 * A convenience function for direct state access functions that throws
1096 * GL_INVALID_OPERATION if buffer is not the name of an existing
1099 struct gl_buffer_object
*
1100 _mesa_lookup_bufferobj_err(struct gl_context
*ctx
, GLuint buffer
,
1103 struct gl_buffer_object
*bufObj
;
1105 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
1106 if (!bufObj
|| bufObj
== &DummyBufferObject
) {
1107 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1108 "%s(non-existent buffer object %u)", caller
, buffer
);
1117 * Look up a buffer object for a multi-bind function.
1119 * Unlike _mesa_lookup_bufferobj(), this function also takes care
1120 * of generating an error if the buffer ID is not zero or the name
1121 * of an existing buffer object.
1123 * If the buffer ID refers to an existing buffer object, a pointer
1124 * to the buffer object is returned. If the ID is zero, a pointer
1125 * to the shared NullBufferObj is returned. If the ID is not zero
1126 * and does not refer to a valid buffer object, this function
1129 * This function assumes that the caller has already locked the
1130 * hash table mutex by calling
1131 * _mesa_HashLockMutex(ctx->Shared->BufferObjects).
1133 struct gl_buffer_object
*
1134 _mesa_multi_bind_lookup_bufferobj(struct gl_context
*ctx
,
1135 const GLuint
*buffers
,
1136 GLuint index
, const char *caller
)
1138 struct gl_buffer_object
*bufObj
;
1140 if (buffers
[index
] != 0) {
1141 bufObj
= _mesa_lookup_bufferobj_locked(ctx
, buffers
[index
]);
1143 /* The multi-bind functions don't create the buffer objects
1144 when they don't exist. */
1145 if (bufObj
== &DummyBufferObject
)
1148 bufObj
= ctx
->Shared
->NullBufferObj
;
1151 /* The ARB_multi_bind spec says:
1153 * "An INVALID_OPERATION error is generated if any value
1154 * in <buffers> is not zero or the name of an existing
1155 * buffer object (per binding)."
1157 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1158 "%s(buffers[%u]=%u is not zero or the name "
1159 "of an existing buffer object)",
1160 caller
, index
, buffers
[index
]);
1168 * If *ptr points to obj, set ptr = the Null/default buffer object.
1169 * This is a helper for buffer object deletion.
1170 * The GL spec says that deleting a buffer object causes it to get
1171 * unbound from all arrays in the current context.
1174 unbind(struct gl_context
*ctx
,
1175 struct gl_vertex_array_object
*vao
, unsigned index
,
1176 struct gl_buffer_object
*obj
)
1178 if (vao
->BufferBinding
[index
].BufferObj
== obj
) {
1179 _mesa_bind_vertex_buffer(ctx
, vao
, index
, ctx
->Shared
->NullBufferObj
,
1180 vao
->BufferBinding
[index
].Offset
,
1181 vao
->BufferBinding
[index
].Stride
);
1187 * Plug default/fallback buffer object functions into the device
1191 _mesa_init_buffer_object_functions(struct dd_function_table
*driver
)
1193 /* GL_ARB_vertex/pixel_buffer_object */
1194 driver
->NewBufferObject
= _mesa_new_buffer_object
;
1195 driver
->DeleteBuffer
= _mesa_delete_buffer_object
;
1196 driver
->BufferData
= buffer_data_fallback
;
1197 driver
->BufferSubData
= buffer_sub_data_fallback
;
1198 driver
->GetBufferSubData
= buffer_get_subdata
;
1199 driver
->UnmapBuffer
= unmap_buffer_fallback
;
1201 /* GL_ARB_clear_buffer_object */
1202 driver
->ClearBufferSubData
= _mesa_ClearBufferSubData_sw
;
1204 /* GL_ARB_map_buffer_range */
1205 driver
->MapBufferRange
= map_buffer_range_fallback
;
1206 driver
->FlushMappedBufferRange
= flush_mapped_buffer_range_fallback
;
1208 /* GL_ARB_copy_buffer */
1209 driver
->CopyBufferSubData
= copy_buffer_sub_data_fallback
;
1214 _mesa_buffer_unmap_all_mappings(struct gl_context
*ctx
,
1215 struct gl_buffer_object
*bufObj
)
1217 for (int i
= 0; i
< MAP_COUNT
; i
++) {
1218 if (_mesa_bufferobj_mapped(bufObj
, i
)) {
1219 ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, i
);
1220 assert(bufObj
->Mappings
[i
].Pointer
== NULL
);
1221 bufObj
->Mappings
[i
].AccessFlags
= 0;
1227 /**********************************************************************/
1229 /**********************************************************************/
1232 _mesa_BindBuffer(GLenum target
, GLuint buffer
)
1234 GET_CURRENT_CONTEXT(ctx
);
1236 if (MESA_VERBOSE
& VERBOSE_API
) {
1237 _mesa_debug(ctx
, "glBindBuffer(%s, %u)\n",
1238 _mesa_enum_to_string(target
), buffer
);
1241 struct gl_buffer_object
**bindTarget
= get_buffer_target(ctx
, target
);
1243 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferARB(target %s)",
1244 _mesa_enum_to_string(target
));
1248 bind_buffer_object(ctx
, bindTarget
, buffer
);
1253 * Delete a set of buffer objects.
1255 * \param n Number of buffer objects to delete.
1256 * \param ids Array of \c n buffer object IDs.
1259 _mesa_DeleteBuffers(GLsizei n
, const GLuint
*ids
)
1261 GET_CURRENT_CONTEXT(ctx
);
1263 FLUSH_VERTICES(ctx
, 0);
1266 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteBuffersARB(n)");
1270 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
1272 for (i
= 0; i
< n
; i
++) {
1273 struct gl_buffer_object
*bufObj
=
1274 _mesa_lookup_bufferobj_locked(ctx
, ids
[i
]);
1276 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
1279 assert(bufObj
->Name
== ids
[i
] || bufObj
== &DummyBufferObject
);
1281 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1283 /* unbind any vertex pointers bound to this buffer */
1284 for (j
= 0; j
< ARRAY_SIZE(vao
->BufferBinding
); j
++) {
1285 unbind(ctx
, vao
, j
, bufObj
);
1288 if (ctx
->Array
.ArrayBufferObj
== bufObj
) {
1289 bind_buffer_object(ctx
, &ctx
->Array
.ArrayBufferObj
, 0);
1291 if (vao
->IndexBufferObj
== bufObj
) {
1292 bind_buffer_object(ctx
, &vao
->IndexBufferObj
, 0);
1295 /* unbind ARB_draw_indirect binding point */
1296 if (ctx
->DrawIndirectBuffer
== bufObj
) {
1297 bind_buffer_object(ctx
, &ctx
->DrawIndirectBuffer
, 0);
1300 /* unbind ARB_indirect_parameters binding point */
1301 if (ctx
->ParameterBuffer
== bufObj
) {
1302 bind_buffer_object(ctx
, &ctx
->ParameterBuffer
, 0);
1305 /* unbind ARB_compute_shader binding point */
1306 if (ctx
->DispatchIndirectBuffer
== bufObj
) {
1307 bind_buffer_object(ctx
, &ctx
->DispatchIndirectBuffer
, 0);
1310 /* unbind ARB_copy_buffer binding points */
1311 if (ctx
->CopyReadBuffer
== bufObj
) {
1312 bind_buffer_object(ctx
, &ctx
->CopyReadBuffer
, 0);
1314 if (ctx
->CopyWriteBuffer
== bufObj
) {
1315 bind_buffer_object(ctx
, &ctx
->CopyWriteBuffer
, 0);
1318 /* unbind transform feedback binding points */
1319 if (ctx
->TransformFeedback
.CurrentBuffer
== bufObj
) {
1320 bind_buffer_object(ctx
, &ctx
->TransformFeedback
.CurrentBuffer
, 0);
1322 for (j
= 0; j
< MAX_FEEDBACK_BUFFERS
; j
++) {
1323 if (ctx
->TransformFeedback
.CurrentObject
->Buffers
[j
] == bufObj
) {
1324 _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER
, j
, 0 );
1328 /* unbind UBO binding points */
1329 for (j
= 0; j
< ctx
->Const
.MaxUniformBufferBindings
; j
++) {
1330 if (ctx
->UniformBufferBindings
[j
].BufferObject
== bufObj
) {
1331 _mesa_BindBufferBase( GL_UNIFORM_BUFFER
, j
, 0 );
1335 if (ctx
->UniformBuffer
== bufObj
) {
1336 bind_buffer_object(ctx
, &ctx
->UniformBuffer
, 0);
1339 /* unbind SSBO binding points */
1340 for (j
= 0; j
< ctx
->Const
.MaxShaderStorageBufferBindings
; j
++) {
1341 if (ctx
->ShaderStorageBufferBindings
[j
].BufferObject
== bufObj
) {
1342 _mesa_BindBufferBase(GL_SHADER_STORAGE_BUFFER
, j
, 0);
1346 if (ctx
->ShaderStorageBuffer
== bufObj
) {
1347 bind_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, 0);
1350 /* unbind Atomci Buffer binding points */
1351 for (j
= 0; j
< ctx
->Const
.MaxAtomicBufferBindings
; j
++) {
1352 if (ctx
->AtomicBufferBindings
[j
].BufferObject
== bufObj
) {
1353 _mesa_BindBufferBase( GL_ATOMIC_COUNTER_BUFFER
, j
, 0 );
1357 if (ctx
->AtomicBuffer
== bufObj
) {
1358 bind_buffer_object(ctx
, &ctx
->AtomicBuffer
, 0);
1361 /* unbind any pixel pack/unpack pointers bound to this buffer */
1362 if (ctx
->Pack
.BufferObj
== bufObj
) {
1363 bind_buffer_object(ctx
, &ctx
->Pack
.BufferObj
, 0);
1365 if (ctx
->Unpack
.BufferObj
== bufObj
) {
1366 bind_buffer_object(ctx
, &ctx
->Unpack
.BufferObj
, 0);
1369 if (ctx
->Texture
.BufferObject
== bufObj
) {
1370 bind_buffer_object(ctx
, &ctx
->Texture
.BufferObject
, 0);
1373 if (ctx
->ExternalVirtualMemoryBuffer
== bufObj
) {
1374 bind_buffer_object(ctx
, &ctx
->ExternalVirtualMemoryBuffer
, 0);
1377 /* unbind query buffer binding point */
1378 if (ctx
->QueryBuffer
== bufObj
) {
1379 bind_buffer_object(ctx
, &ctx
->QueryBuffer
, 0);
1382 /* The ID is immediately freed for re-use */
1383 _mesa_HashRemoveLocked(ctx
->Shared
->BufferObjects
, ids
[i
]);
1384 /* Make sure we do not run into the classic ABA problem on bind.
1385 * We don't want to allow re-binding a buffer object that's been
1386 * "deleted" by glDeleteBuffers().
1388 * The explicit rebinding to the default object in the current context
1389 * prevents the above in the current context, but another context
1390 * sharing the same objects might suffer from this problem.
1391 * The alternative would be to do the hash lookup in any case on bind
1392 * which would introduce more runtime overhead than this.
1394 bufObj
->DeletePending
= GL_TRUE
;
1395 _mesa_reference_buffer_object(ctx
, &bufObj
, NULL
);
1399 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
1404 * This is the implementation for glGenBuffers and glCreateBuffers. It is not
1405 * exposed to the rest of Mesa to encourage the use of nameless buffers in
1409 create_buffers(GLsizei n
, GLuint
*buffers
, bool dsa
)
1411 GET_CURRENT_CONTEXT(ctx
);
1413 struct gl_buffer_object
*buf
;
1415 const char *func
= dsa
? "glCreateBuffers" : "glGenBuffers";
1417 if (MESA_VERBOSE
& VERBOSE_API
)
1418 _mesa_debug(ctx
, "%s(%d)\n", func
, n
);
1421 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n %d < 0)", func
, n
);
1430 * This must be atomic (generation and allocation of buffer object IDs)
1432 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
1434 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->BufferObjects
, n
);
1436 /* Insert the ID and pointer into the hash table. If non-DSA, insert a
1437 * DummyBufferObject. Otherwise, create a new buffer object and insert
1440 for (int i
= 0; i
< n
; i
++) {
1441 buffers
[i
] = first
+ i
;
1443 assert(ctx
->Driver
.NewBufferObject
);
1444 buf
= ctx
->Driver
.NewBufferObject(ctx
, buffers
[i
]);
1446 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1447 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
1452 buf
= &DummyBufferObject
;
1454 _mesa_HashInsertLocked(ctx
->Shared
->BufferObjects
, buffers
[i
], buf
);
1457 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
1461 * Generate a set of unique buffer object IDs and store them in \c buffers.
1463 * \param n Number of IDs to generate.
1464 * \param buffers Array of \c n locations to store the IDs.
1467 _mesa_GenBuffers(GLsizei n
, GLuint
*buffers
)
1469 create_buffers(n
, buffers
, false);
1473 * Create a set of buffer objects and store their unique IDs in \c buffers.
1475 * \param n Number of IDs to generate.
1476 * \param buffers Array of \c n locations to store the IDs.
1479 _mesa_CreateBuffers(GLsizei n
, GLuint
*buffers
)
1481 create_buffers(n
, buffers
, true);
1486 * Determine if ID is the name of a buffer object.
1488 * \param id ID of the potential buffer object.
1489 * \return \c GL_TRUE if \c id is the name of a buffer object,
1490 * \c GL_FALSE otherwise.
1492 GLboolean GLAPIENTRY
1493 _mesa_IsBuffer(GLuint id
)
1495 struct gl_buffer_object
*bufObj
;
1496 GET_CURRENT_CONTEXT(ctx
);
1497 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1499 bufObj
= _mesa_lookup_bufferobj(ctx
, id
);
1501 return bufObj
&& bufObj
!= &DummyBufferObject
;
1506 validate_buffer_storage(struct gl_context
*ctx
,
1507 struct gl_buffer_object
*bufObj
, GLsizeiptr size
,
1508 GLbitfield flags
, const char *func
)
1511 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size <= 0)", func
);
1515 GLbitfield valid_flags
= GL_MAP_READ_BIT
|
1517 GL_MAP_PERSISTENT_BIT
|
1518 GL_MAP_COHERENT_BIT
|
1519 GL_DYNAMIC_STORAGE_BIT
|
1520 GL_CLIENT_STORAGE_BIT
;
1522 if (ctx
->Extensions
.ARB_sparse_buffer
)
1523 valid_flags
|= GL_SPARSE_STORAGE_BIT_ARB
;
1525 if (flags
& ~valid_flags
) {
1526 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(invalid flag bits set)", func
);
1530 /* The Errors section of the GL_ARB_sparse_buffer spec says:
1532 * "INVALID_VALUE is generated by BufferStorage if <flags> contains
1533 * SPARSE_STORAGE_BIT_ARB and <flags> also contains any combination of
1534 * MAP_READ_BIT or MAP_WRITE_BIT."
1536 if (flags
& GL_SPARSE_STORAGE_BIT_ARB
&&
1537 flags
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) {
1538 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(SPARSE_STORAGE and READ/WRITE)", func
);
1542 if (flags
& GL_MAP_PERSISTENT_BIT
&&
1543 !(flags
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
))) {
1544 _mesa_error(ctx
, GL_INVALID_VALUE
,
1545 "%s(PERSISTENT and flags!=READ/WRITE)", func
);
1549 if (flags
& GL_MAP_COHERENT_BIT
&& !(flags
& GL_MAP_PERSISTENT_BIT
)) {
1550 _mesa_error(ctx
, GL_INVALID_VALUE
,
1551 "%s(COHERENT and flags!=PERSISTENT)", func
);
1555 if (bufObj
->Immutable
) {
1556 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
1565 buffer_storage(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1566 GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1567 GLbitfield flags
, const char *func
)
1569 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1570 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1572 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1574 bufObj
->Written
= GL_TRUE
;
1575 bufObj
->Immutable
= GL_TRUE
;
1576 bufObj
->MinMaxCacheDirty
= true;
1578 assert(ctx
->Driver
.BufferData
);
1579 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, GL_DYNAMIC_DRAW
,
1581 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1582 /* Even though the interaction between AMD_pinned_memory and
1583 * glBufferStorage is not described in the spec, Graham Sellers
1584 * said that it should behave the same as glBufferData.
1586 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1589 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1595 static ALWAYS_INLINE
void
1596 inlined_buffer_storage(GLenum target
, GLuint buffer
, GLsizeiptr size
,
1597 const GLvoid
*data
, GLbitfield flags
, bool dsa
,
1598 bool no_error
, const char *func
)
1600 GET_CURRENT_CONTEXT(ctx
);
1601 struct gl_buffer_object
*bufObj
;
1605 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
1607 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, func
);
1613 struct gl_buffer_object
**bufObjPtr
= get_buffer_target(ctx
, target
);
1614 bufObj
= *bufObjPtr
;
1616 bufObj
= get_buffer(ctx
, func
, target
, GL_INVALID_OPERATION
);
1622 if (no_error
|| validate_buffer_storage(ctx
, bufObj
, size
, flags
, func
))
1623 buffer_storage(ctx
, bufObj
, target
, size
, data
, flags
, func
);
1628 _mesa_BufferStorage_no_error(GLenum target
, GLsizeiptr size
,
1629 const GLvoid
*data
, GLbitfield flags
)
1631 inlined_buffer_storage(target
, 0, size
, data
, flags
, false, true,
1637 _mesa_BufferStorage(GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1640 inlined_buffer_storage(target
, 0, size
, data
, flags
, false, false,
1646 _mesa_NamedBufferStorage_no_error(GLuint buffer
, GLsizeiptr size
,
1647 const GLvoid
*data
, GLbitfield flags
)
1649 /* In direct state access, buffer objects have an unspecified target
1650 * since they are not required to be bound.
1652 inlined_buffer_storage(GL_NONE
, buffer
, size
, data
, flags
, true, true,
1653 "glNamedBufferStorage");
1658 _mesa_NamedBufferStorage(GLuint buffer
, GLsizeiptr size
, const GLvoid
*data
,
1661 /* In direct state access, buffer objects have an unspecified target
1662 * since they are not required to be bound.
1664 inlined_buffer_storage(GL_NONE
, buffer
, size
, data
, flags
, true, false,
1665 "glNamedBufferStorage");
1670 _mesa_buffer_data(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1671 GLenum target
, GLsizeiptr size
, const GLvoid
*data
,
1672 GLenum usage
, const char *func
)
1676 if (MESA_VERBOSE
& VERBOSE_API
) {
1677 _mesa_debug(ctx
, "%s(%s, %ld, %p, %s)\n",
1679 _mesa_enum_to_string(target
),
1680 (long int) size
, data
,
1681 _mesa_enum_to_string(usage
));
1685 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size < 0)", func
);
1690 case GL_STREAM_DRAW_ARB
:
1691 valid_usage
= (ctx
->API
!= API_OPENGLES
);
1694 case GL_STATIC_DRAW_ARB
:
1695 case GL_DYNAMIC_DRAW_ARB
:
1699 case GL_STREAM_READ_ARB
:
1700 case GL_STREAM_COPY_ARB
:
1701 case GL_STATIC_READ_ARB
:
1702 case GL_STATIC_COPY_ARB
:
1703 case GL_DYNAMIC_READ_ARB
:
1704 case GL_DYNAMIC_COPY_ARB
:
1705 valid_usage
= _mesa_is_desktop_gl(ctx
) || _mesa_is_gles3(ctx
);
1709 valid_usage
= false;
1714 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid usage: %s)", func
,
1715 _mesa_enum_to_string(usage
));
1719 if (bufObj
->Immutable
) {
1720 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
1724 /* Unmap the existing buffer. We'll replace it now. Not an error. */
1725 _mesa_buffer_unmap_all_mappings(ctx
, bufObj
);
1727 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
1729 bufObj
->Written
= GL_TRUE
;
1730 bufObj
->MinMaxCacheDirty
= true;
1733 printf("glBufferDataARB(%u, sz %ld, from %p, usage 0x%x)\n",
1734 bufObj
->Name
, size
, data
, usage
);
1741 assert(ctx
->Driver
.BufferData
);
1742 if (!ctx
->Driver
.BufferData(ctx
, target
, size
, data
, usage
,
1745 GL_DYNAMIC_STORAGE_BIT
,
1747 if (target
== GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
) {
1748 /* From GL_AMD_pinned_memory:
1750 * INVALID_OPERATION is generated by BufferData if <target> is
1751 * EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, and the store cannot be
1752 * mapped to the GPU address space.
1754 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1757 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1763 _mesa_BufferData(GLenum target
, GLsizeiptr size
,
1764 const GLvoid
*data
, GLenum usage
)
1766 GET_CURRENT_CONTEXT(ctx
);
1767 struct gl_buffer_object
*bufObj
;
1769 bufObj
= get_buffer(ctx
, "glBufferData", target
, GL_INVALID_OPERATION
);
1773 _mesa_buffer_data(ctx
, bufObj
, target
, size
, data
, usage
,
1778 _mesa_NamedBufferData(GLuint buffer
, GLsizeiptr size
, const GLvoid
*data
,
1781 GET_CURRENT_CONTEXT(ctx
);
1782 struct gl_buffer_object
*bufObj
;
1784 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glNamedBufferData");
1788 /* In direct state access, buffer objects have an unspecified target since
1789 * they are not required to be bound.
1791 _mesa_buffer_data(ctx
, bufObj
, GL_NONE
, size
, data
, usage
,
1792 "glNamedBufferData");
1797 validate_buffer_sub_data(struct gl_context
*ctx
,
1798 struct gl_buffer_object
*bufObj
,
1799 GLintptr offset
, GLsizeiptr size
,
1802 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
,
1804 /* error already recorded */
1808 if (bufObj
->Immutable
&&
1809 !(bufObj
->StorageFlags
& GL_DYNAMIC_STORAGE_BIT
)) {
1810 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", func
);
1814 if ((bufObj
->Usage
== GL_STATIC_DRAW
||
1815 bufObj
->Usage
== GL_STATIC_COPY
) &&
1816 bufObj
->NumSubDataCalls
>= BUFFER_WARNING_CALL_COUNT
- 1) {
1817 /* If the application declared the buffer as static draw/copy or stream
1818 * draw, it should not be frequently modified with glBufferSubData.
1820 BUFFER_USAGE_WARNING(ctx
,
1821 "using %s(buffer %u, offset %u, size %u) to "
1822 "update a %s buffer",
1823 func
, bufObj
->Name
, offset
, size
,
1824 _mesa_enum_to_string(bufObj
->Usage
));
1832 * Implementation for glBufferSubData and glNamedBufferSubData.
1834 * \param ctx GL context.
1835 * \param bufObj The buffer object.
1836 * \param offset Offset of the first byte of the subdata range.
1837 * \param size Size, in bytes, of the subdata range.
1838 * \param data The data store.
1839 * \param func Name of calling function for recording errors.
1843 _mesa_buffer_sub_data(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1844 GLintptr offset
, GLsizeiptr size
, const GLvoid
*data
)
1849 bufObj
->NumSubDataCalls
++;
1850 bufObj
->Written
= GL_TRUE
;
1851 bufObj
->MinMaxCacheDirty
= true;
1853 assert(ctx
->Driver
.BufferSubData
);
1854 ctx
->Driver
.BufferSubData(ctx
, offset
, size
, data
, bufObj
);
1858 static ALWAYS_INLINE
void
1859 buffer_sub_data(GLenum target
, GLuint buffer
, GLintptr offset
,
1860 GLsizeiptr size
, const GLvoid
*data
,
1861 bool dsa
, bool no_error
, const char *func
)
1863 GET_CURRENT_CONTEXT(ctx
);
1864 struct gl_buffer_object
*bufObj
;
1868 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
1870 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, func
);
1875 bufObj
= get_buffer(ctx
, func
, target
, GL_INVALID_OPERATION
);
1880 if (no_error
|| validate_buffer_sub_data(ctx
, bufObj
, offset
, size
, func
))
1881 _mesa_buffer_sub_data(ctx
, bufObj
, offset
, size
, data
);
1886 _mesa_BufferSubData(GLenum target
, GLintptr offset
,
1887 GLsizeiptr size
, const GLvoid
*data
)
1889 buffer_sub_data(target
, 0, offset
, size
, data
, false, false,
1894 _mesa_NamedBufferSubData_no_error(GLuint buffer
, GLintptr offset
,
1895 GLsizeiptr size
, const GLvoid
*data
)
1897 buffer_sub_data(0, buffer
, offset
, size
, data
, true, true,
1898 "glNamedBufferSubData");
1902 _mesa_NamedBufferSubData(GLuint buffer
, GLintptr offset
,
1903 GLsizeiptr size
, const GLvoid
*data
)
1905 buffer_sub_data(0, buffer
, offset
, size
, data
, true, false,
1906 "glNamedBufferSubData");
1911 _mesa_GetBufferSubData(GLenum target
, GLintptr offset
,
1912 GLsizeiptr size
, GLvoid
*data
)
1914 GET_CURRENT_CONTEXT(ctx
);
1915 struct gl_buffer_object
*bufObj
;
1917 bufObj
= get_buffer(ctx
, "glGetBufferSubData", target
,
1918 GL_INVALID_OPERATION
);
1922 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
, false,
1923 "glGetBufferSubData")) {
1927 assert(ctx
->Driver
.GetBufferSubData
);
1928 ctx
->Driver
.GetBufferSubData(ctx
, offset
, size
, data
, bufObj
);
1932 _mesa_GetNamedBufferSubData(GLuint buffer
, GLintptr offset
,
1933 GLsizeiptr size
, GLvoid
*data
)
1935 GET_CURRENT_CONTEXT(ctx
);
1936 struct gl_buffer_object
*bufObj
;
1938 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
1939 "glGetNamedBufferSubData");
1943 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
, false,
1944 "glGetNamedBufferSubData")) {
1948 assert(ctx
->Driver
.GetBufferSubData
);
1949 ctx
->Driver
.GetBufferSubData(ctx
, offset
, size
, data
, bufObj
);
1954 * \param subdata true if caller is *SubData, false if *Data
1957 clear_buffer_sub_data(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
1958 GLenum internalformat
, GLintptr offset
, GLsizeiptr size
,
1959 GLenum format
, GLenum type
, const GLvoid
*data
,
1960 const char *func
, bool subdata
)
1962 mesa_format mesaFormat
;
1963 GLubyte clearValue
[MAX_PIXEL_BYTES
];
1964 GLsizeiptr clearValueSize
;
1966 /* This checks for disallowed mappings. */
1967 if (!buffer_object_subdata_range_good(ctx
, bufObj
, offset
, size
,
1972 mesaFormat
= validate_clear_buffer_format(ctx
, internalformat
,
1973 format
, type
, func
);
1975 if (mesaFormat
== MESA_FORMAT_NONE
) {
1979 clearValueSize
= _mesa_get_format_bytes(mesaFormat
);
1980 if (offset
% clearValueSize
!= 0 || size
% clearValueSize
!= 0) {
1981 _mesa_error(ctx
, GL_INVALID_VALUE
,
1982 "%s(offset or size is not a multiple of "
1983 "internalformat size)", func
);
1987 /* Bail early. Negative size has already been checked. */
1991 bufObj
->MinMaxCacheDirty
= true;
1994 /* clear to zeros, per the spec */
1995 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
1996 NULL
, clearValueSize
, bufObj
);
2000 if (!convert_clear_buffer_data(ctx
, mesaFormat
, clearValue
,
2001 format
, type
, data
, func
)) {
2005 ctx
->Driver
.ClearBufferSubData(ctx
, offset
, size
,
2006 clearValue
, clearValueSize
, bufObj
);
2010 _mesa_ClearBufferData(GLenum target
, GLenum internalformat
, GLenum format
,
2011 GLenum type
, const GLvoid
*data
)
2013 GET_CURRENT_CONTEXT(ctx
);
2014 struct gl_buffer_object
*bufObj
;
2016 bufObj
= get_buffer(ctx
, "glClearBufferData", target
, GL_INVALID_VALUE
);
2020 clear_buffer_sub_data(ctx
, bufObj
, internalformat
, 0, bufObj
->Size
,
2021 format
, type
, data
, "glClearBufferData", false);
2025 _mesa_ClearNamedBufferData(GLuint buffer
, GLenum internalformat
,
2026 GLenum format
, GLenum type
, const GLvoid
*data
)
2028 GET_CURRENT_CONTEXT(ctx
);
2029 struct gl_buffer_object
*bufObj
;
2031 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glClearNamedBufferData");
2035 clear_buffer_sub_data(ctx
, bufObj
, internalformat
, 0, bufObj
->Size
,
2036 format
, type
, data
, "glClearNamedBufferData", false);
2041 _mesa_ClearBufferSubData(GLenum target
, GLenum internalformat
,
2042 GLintptr offset
, GLsizeiptr size
,
2043 GLenum format
, GLenum type
,
2046 GET_CURRENT_CONTEXT(ctx
);
2047 struct gl_buffer_object
*bufObj
;
2049 bufObj
= get_buffer(ctx
, "glClearBufferSubData", target
, GL_INVALID_VALUE
);
2053 clear_buffer_sub_data(ctx
, bufObj
, internalformat
, offset
, size
,
2054 format
, type
, data
, "glClearBufferSubData", true);
2058 _mesa_ClearNamedBufferSubData(GLuint buffer
, GLenum internalformat
,
2059 GLintptr offset
, GLsizeiptr size
,
2060 GLenum format
, GLenum type
,
2063 GET_CURRENT_CONTEXT(ctx
);
2064 struct gl_buffer_object
*bufObj
;
2066 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2067 "glClearNamedBufferSubData");
2071 clear_buffer_sub_data(ctx
, bufObj
, internalformat
, offset
, size
, format
,
2072 type
, data
, "glClearNamedBufferSubData", true);
2076 unmap_buffer(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
)
2078 GLboolean status
= ctx
->Driver
.UnmapBuffer(ctx
, bufObj
, MAP_USER
);
2079 bufObj
->Mappings
[MAP_USER
].AccessFlags
= 0;
2080 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== NULL
);
2081 assert(bufObj
->Mappings
[MAP_USER
].Offset
== 0);
2082 assert(bufObj
->Mappings
[MAP_USER
].Length
== 0);
2088 validate_and_unmap_buffer(struct gl_context
*ctx
,
2089 struct gl_buffer_object
*bufObj
,
2092 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
2094 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2095 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2096 "%s(buffer is not mapped)", func
);
2101 if (bufObj
->Access
!= GL_READ_ONLY_ARB
) {
2102 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
2104 /* check that last 100 bytes are still = magic value */
2105 for (i
= 0; i
< 100; i
++) {
2106 GLuint pos
= bufObj
->Size
- i
- 1;
2107 if (buf
[pos
] != 123) {
2108 _mesa_warning(ctx
, "Out of bounds buffer object write detected"
2109 " at position %d (value = %u)\n",
2117 if (bufObj
->AccessFlags
& GL_MAP_WRITE_BIT
) {
2118 GLuint i
, unchanged
= 0;
2119 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
2121 /* check which bytes changed */
2122 for (i
= 0; i
< bufObj
->Size
- 1; i
++) {
2123 if (b
[i
] == (i
& 0xff) && b
[i
+1] == ((i
+1) & 0xff)) {
2130 printf("glUnmapBufferARB(%u): %u of %ld unchanged, starting at %d\n",
2131 bufObj
->Name
, unchanged
, bufObj
->Size
, pos
);
2136 return unmap_buffer(ctx
, bufObj
);
2139 GLboolean GLAPIENTRY
2140 _mesa_UnmapBuffer_no_error(GLenum target
)
2142 GET_CURRENT_CONTEXT(ctx
);
2143 struct gl_buffer_object
**bufObjPtr
= get_buffer_target(ctx
, target
);
2144 struct gl_buffer_object
*bufObj
= *bufObjPtr
;
2146 return unmap_buffer(ctx
, bufObj
);
2149 GLboolean GLAPIENTRY
2150 _mesa_UnmapBuffer(GLenum target
)
2152 GET_CURRENT_CONTEXT(ctx
);
2153 struct gl_buffer_object
*bufObj
;
2155 bufObj
= get_buffer(ctx
, "glUnmapBuffer", target
, GL_INVALID_OPERATION
);
2159 return validate_and_unmap_buffer(ctx
, bufObj
, "glUnmapBuffer");
2162 GLboolean GLAPIENTRY
2163 _mesa_UnmapNamedBuffer_no_error(GLuint buffer
)
2165 GET_CURRENT_CONTEXT(ctx
);
2166 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2168 return unmap_buffer(ctx
, bufObj
);
2171 GLboolean GLAPIENTRY
2172 _mesa_UnmapNamedBuffer(GLuint buffer
)
2174 GET_CURRENT_CONTEXT(ctx
);
2175 struct gl_buffer_object
*bufObj
;
2177 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glUnmapNamedBuffer");
2181 return validate_and_unmap_buffer(ctx
, bufObj
, "glUnmapNamedBuffer");
2186 get_buffer_parameter(struct gl_context
*ctx
,
2187 struct gl_buffer_object
*bufObj
, GLenum pname
,
2188 GLint64
*params
, const char *func
)
2191 case GL_BUFFER_SIZE_ARB
:
2192 *params
= bufObj
->Size
;
2194 case GL_BUFFER_USAGE_ARB
:
2195 *params
= bufObj
->Usage
;
2197 case GL_BUFFER_ACCESS_ARB
:
2198 *params
= simplified_access_mode(ctx
,
2199 bufObj
->Mappings
[MAP_USER
].AccessFlags
);
2201 case GL_BUFFER_MAPPED_ARB
:
2202 *params
= _mesa_bufferobj_mapped(bufObj
, MAP_USER
);
2204 case GL_BUFFER_ACCESS_FLAGS
:
2205 if (!ctx
->Extensions
.ARB_map_buffer_range
)
2207 *params
= bufObj
->Mappings
[MAP_USER
].AccessFlags
;
2209 case GL_BUFFER_MAP_OFFSET
:
2210 if (!ctx
->Extensions
.ARB_map_buffer_range
)
2212 *params
= bufObj
->Mappings
[MAP_USER
].Offset
;
2214 case GL_BUFFER_MAP_LENGTH
:
2215 if (!ctx
->Extensions
.ARB_map_buffer_range
)
2217 *params
= bufObj
->Mappings
[MAP_USER
].Length
;
2219 case GL_BUFFER_IMMUTABLE_STORAGE
:
2220 if (!ctx
->Extensions
.ARB_buffer_storage
)
2222 *params
= bufObj
->Immutable
;
2224 case GL_BUFFER_STORAGE_FLAGS
:
2225 if (!ctx
->Extensions
.ARB_buffer_storage
)
2227 *params
= bufObj
->StorageFlags
;
2236 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid pname: %s)", func
,
2237 _mesa_enum_to_string(pname
));
2242 _mesa_GetBufferParameteriv(GLenum target
, GLenum pname
, GLint
*params
)
2244 GET_CURRENT_CONTEXT(ctx
);
2245 struct gl_buffer_object
*bufObj
;
2248 bufObj
= get_buffer(ctx
, "glGetBufferParameteriv", target
,
2249 GL_INVALID_OPERATION
);
2253 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2254 "glGetBufferParameteriv"))
2255 return; /* Error already recorded. */
2257 *params
= (GLint
) parameter
;
2261 _mesa_GetBufferParameteri64v(GLenum target
, GLenum pname
, GLint64
*params
)
2263 GET_CURRENT_CONTEXT(ctx
);
2264 struct gl_buffer_object
*bufObj
;
2267 bufObj
= get_buffer(ctx
, "glGetBufferParameteri64v", target
,
2268 GL_INVALID_OPERATION
);
2272 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2273 "glGetBufferParameteri64v"))
2274 return; /* Error already recorded. */
2276 *params
= parameter
;
2280 _mesa_GetNamedBufferParameteriv(GLuint buffer
, GLenum pname
, GLint
*params
)
2282 GET_CURRENT_CONTEXT(ctx
);
2283 struct gl_buffer_object
*bufObj
;
2286 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2287 "glGetNamedBufferParameteriv");
2291 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2292 "glGetNamedBufferParameteriv"))
2293 return; /* Error already recorded. */
2295 *params
= (GLint
) parameter
;
2299 _mesa_GetNamedBufferParameteri64v(GLuint buffer
, GLenum pname
,
2302 GET_CURRENT_CONTEXT(ctx
);
2303 struct gl_buffer_object
*bufObj
;
2306 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2307 "glGetNamedBufferParameteri64v");
2311 if (!get_buffer_parameter(ctx
, bufObj
, pname
, ¶meter
,
2312 "glGetNamedBufferParameteri64v"))
2313 return; /* Error already recorded. */
2315 *params
= parameter
;
2320 _mesa_GetBufferPointerv(GLenum target
, GLenum pname
, GLvoid
**params
)
2322 GET_CURRENT_CONTEXT(ctx
);
2323 struct gl_buffer_object
*bufObj
;
2325 if (pname
!= GL_BUFFER_MAP_POINTER
) {
2326 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetBufferPointerv(pname != "
2327 "GL_BUFFER_MAP_POINTER)");
2331 bufObj
= get_buffer(ctx
, "glGetBufferPointerv", target
,
2332 GL_INVALID_OPERATION
);
2336 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
2340 _mesa_GetNamedBufferPointerv(GLuint buffer
, GLenum pname
, GLvoid
**params
)
2342 GET_CURRENT_CONTEXT(ctx
);
2343 struct gl_buffer_object
*bufObj
;
2345 if (pname
!= GL_BUFFER_MAP_POINTER
) {
2346 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetNamedBufferPointerv(pname != "
2347 "GL_BUFFER_MAP_POINTER)");
2351 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2352 "glGetNamedBufferPointerv");
2356 *params
= bufObj
->Mappings
[MAP_USER
].Pointer
;
2361 copy_buffer_sub_data(struct gl_context
*ctx
, struct gl_buffer_object
*src
,
2362 struct gl_buffer_object
*dst
, GLintptr readOffset
,
2363 GLintptr writeOffset
, GLsizeiptr size
, const char *func
)
2365 if (_mesa_check_disallowed_mapping(src
)) {
2366 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2367 "%s(readBuffer is mapped)", func
);
2371 if (_mesa_check_disallowed_mapping(dst
)) {
2372 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2373 "%s(writeBuffer is mapped)", func
);
2377 if (readOffset
< 0) {
2378 _mesa_error(ctx
, GL_INVALID_VALUE
,
2379 "%s(readOffset %d < 0)", func
, (int) readOffset
);
2383 if (writeOffset
< 0) {
2384 _mesa_error(ctx
, GL_INVALID_VALUE
,
2385 "%s(writeOffset %d < 0)", func
, (int) writeOffset
);
2390 _mesa_error(ctx
, GL_INVALID_VALUE
,
2391 "%s(size %d < 0)", func
, (int) size
);
2395 if (readOffset
+ size
> src
->Size
) {
2396 _mesa_error(ctx
, GL_INVALID_VALUE
,
2397 "%s(readOffset %d + size %d > src_buffer_size %d)", func
,
2398 (int) readOffset
, (int) size
, (int) src
->Size
);
2402 if (writeOffset
+ size
> dst
->Size
) {
2403 _mesa_error(ctx
, GL_INVALID_VALUE
,
2404 "%s(writeOffset %d + size %d > dst_buffer_size %d)", func
,
2405 (int) writeOffset
, (int) size
, (int) dst
->Size
);
2410 if (readOffset
+ size
<= writeOffset
) {
2413 else if (writeOffset
+ size
<= readOffset
) {
2417 /* overlapping src/dst is illegal */
2418 _mesa_error(ctx
, GL_INVALID_VALUE
,
2419 "%s(overlapping src/dst)", func
);
2424 dst
->MinMaxCacheDirty
= true;
2426 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
, size
);
2430 _mesa_CopyBufferSubData_no_error(GLenum readTarget
, GLenum writeTarget
,
2431 GLintptr readOffset
, GLintptr writeOffset
,
2434 GET_CURRENT_CONTEXT(ctx
);
2436 struct gl_buffer_object
**src_ptr
= get_buffer_target(ctx
, readTarget
);
2437 struct gl_buffer_object
*src
= *src_ptr
;
2439 struct gl_buffer_object
**dst_ptr
= get_buffer_target(ctx
, writeTarget
);
2440 struct gl_buffer_object
*dst
= *dst_ptr
;
2442 dst
->MinMaxCacheDirty
= true;
2443 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
,
2448 _mesa_CopyBufferSubData(GLenum readTarget
, GLenum writeTarget
,
2449 GLintptr readOffset
, GLintptr writeOffset
,
2452 GET_CURRENT_CONTEXT(ctx
);
2453 struct gl_buffer_object
*src
, *dst
;
2455 src
= get_buffer(ctx
, "glCopyBufferSubData", readTarget
,
2456 GL_INVALID_OPERATION
);
2460 dst
= get_buffer(ctx
, "glCopyBufferSubData", writeTarget
,
2461 GL_INVALID_OPERATION
);
2465 copy_buffer_sub_data(ctx
, src
, dst
, readOffset
, writeOffset
, size
,
2466 "glCopyBufferSubData");
2470 _mesa_CopyNamedBufferSubData_no_error(GLuint readBuffer
, GLuint writeBuffer
,
2471 GLintptr readOffset
,
2472 GLintptr writeOffset
, GLsizeiptr size
)
2474 GET_CURRENT_CONTEXT(ctx
);
2476 struct gl_buffer_object
*src
= _mesa_lookup_bufferobj(ctx
, readBuffer
);
2477 struct gl_buffer_object
*dst
= _mesa_lookup_bufferobj(ctx
, writeBuffer
);
2479 dst
->MinMaxCacheDirty
= true;
2480 ctx
->Driver
.CopyBufferSubData(ctx
, src
, dst
, readOffset
, writeOffset
,
2485 _mesa_CopyNamedBufferSubData(GLuint readBuffer
, GLuint writeBuffer
,
2486 GLintptr readOffset
, GLintptr writeOffset
,
2489 GET_CURRENT_CONTEXT(ctx
);
2490 struct gl_buffer_object
*src
, *dst
;
2492 src
= _mesa_lookup_bufferobj_err(ctx
, readBuffer
,
2493 "glCopyNamedBufferSubData");
2497 dst
= _mesa_lookup_bufferobj_err(ctx
, writeBuffer
,
2498 "glCopyNamedBufferSubData");
2502 copy_buffer_sub_data(ctx
, src
, dst
, readOffset
, writeOffset
, size
,
2503 "glCopyNamedBufferSubData");
2507 validate_map_buffer_range(struct gl_context
*ctx
,
2508 struct gl_buffer_object
*bufObj
, GLintptr offset
,
2509 GLsizeiptr length
, GLbitfield access
,
2512 GLbitfield allowed_access
;
2514 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, false);
2517 _mesa_error(ctx
, GL_INVALID_VALUE
,
2518 "%s(offset %ld < 0)", func
, (long) offset
);
2523 _mesa_error(ctx
, GL_INVALID_VALUE
,
2524 "%s(length %ld < 0)", func
, (long) length
);
2528 /* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
2530 * "An INVALID_OPERATION error is generated for any of the following
2533 * * <length> is zero."
2535 * Additionally, page 94 of the PDF of the OpenGL 4.5 core spec
2536 * (30.10.2014) also says this, so it's no longer allowed for desktop GL,
2540 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(length = 0)", func
);
2544 allowed_access
= GL_MAP_READ_BIT
|
2546 GL_MAP_INVALIDATE_RANGE_BIT
|
2547 GL_MAP_INVALIDATE_BUFFER_BIT
|
2548 GL_MAP_FLUSH_EXPLICIT_BIT
|
2549 GL_MAP_UNSYNCHRONIZED_BIT
;
2551 if (ctx
->Extensions
.ARB_buffer_storage
) {
2552 allowed_access
|= GL_MAP_PERSISTENT_BIT
|
2553 GL_MAP_COHERENT_BIT
;
2556 if (access
& ~allowed_access
) {
2557 /* generate an error if any bits other than those allowed are set */
2558 _mesa_error(ctx
, GL_INVALID_VALUE
,
2559 "%s(access has undefined bits set)", func
);
2563 if ((access
& (GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
)) == 0) {
2564 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2565 "%s(access indicates neither read or write)", func
);
2569 if ((access
& GL_MAP_READ_BIT
) &&
2570 (access
& (GL_MAP_INVALIDATE_RANGE_BIT
|
2571 GL_MAP_INVALIDATE_BUFFER_BIT
|
2572 GL_MAP_UNSYNCHRONIZED_BIT
))) {
2573 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2574 "%s(read access with disallowed bits)", func
);
2578 if ((access
& GL_MAP_FLUSH_EXPLICIT_BIT
) &&
2579 ((access
& GL_MAP_WRITE_BIT
) == 0)) {
2580 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2581 "%s(access has flush explicit without write)", func
);
2585 if (access
& GL_MAP_READ_BIT
&&
2586 !(bufObj
->StorageFlags
& GL_MAP_READ_BIT
)) {
2587 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2588 "%s(buffer does not allow read access)", func
);
2592 if (access
& GL_MAP_WRITE_BIT
&&
2593 !(bufObj
->StorageFlags
& GL_MAP_WRITE_BIT
)) {
2594 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2595 "%s(buffer does not allow write access)", func
);
2599 if (access
& GL_MAP_COHERENT_BIT
&&
2600 !(bufObj
->StorageFlags
& GL_MAP_COHERENT_BIT
)) {
2601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2602 "%s(buffer does not allow coherent access)", func
);
2606 if (access
& GL_MAP_PERSISTENT_BIT
&&
2607 !(bufObj
->StorageFlags
& GL_MAP_PERSISTENT_BIT
)) {
2608 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2609 "%s(buffer does not allow persistent access)", func
);
2613 if (offset
+ length
> bufObj
->Size
) {
2614 _mesa_error(ctx
, GL_INVALID_VALUE
,
2615 "%s(offset %lu + length %lu > buffer_size %lu)", func
,
2616 (unsigned long) offset
, (unsigned long) length
,
2617 (unsigned long) bufObj
->Size
);
2621 if (_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2622 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2623 "%s(buffer already mapped)", func
);
2627 if (access
& GL_MAP_WRITE_BIT
) {
2628 bufObj
->NumMapBufferWriteCalls
++;
2629 if ((bufObj
->Usage
== GL_STATIC_DRAW
||
2630 bufObj
->Usage
== GL_STATIC_COPY
) &&
2631 bufObj
->NumMapBufferWriteCalls
>= BUFFER_WARNING_CALL_COUNT
) {
2632 BUFFER_USAGE_WARNING(ctx
,
2633 "using %s(buffer %u, offset %u, length %u) to "
2634 "update a %s buffer",
2635 func
, bufObj
->Name
, offset
, length
,
2636 _mesa_enum_to_string(bufObj
->Usage
));
2644 map_buffer_range(struct gl_context
*ctx
, struct gl_buffer_object
*bufObj
,
2645 GLintptr offset
, GLsizeiptr length
, GLbitfield access
,
2648 if (!bufObj
->Size
) {
2649 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(buffer size = 0)", func
);
2653 assert(ctx
->Driver
.MapBufferRange
);
2654 void *map
= ctx
->Driver
.MapBufferRange(ctx
, offset
, length
, access
, bufObj
,
2657 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(map failed)", func
);
2660 /* The driver callback should have set all these fields.
2661 * This is important because other modules (like VBO) might call
2662 * the driver function directly.
2664 assert(bufObj
->Mappings
[MAP_USER
].Pointer
== map
);
2665 assert(bufObj
->Mappings
[MAP_USER
].Length
== length
);
2666 assert(bufObj
->Mappings
[MAP_USER
].Offset
== offset
);
2667 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
== access
);
2670 if (access
& GL_MAP_WRITE_BIT
) {
2671 bufObj
->Written
= GL_TRUE
;
2672 bufObj
->MinMaxCacheDirty
= true;
2676 if (strstr(func
, "Range") == NULL
) { /* If not MapRange */
2677 printf("glMapBuffer(%u, sz %ld, access 0x%x)\n",
2678 bufObj
->Name
, bufObj
->Size
, access
);
2679 /* Access must be write only */
2680 if ((access
& GL_MAP_WRITE_BIT
) && (!(access
& ~GL_MAP_WRITE_BIT
))) {
2682 GLubyte
*b
= (GLubyte
*) bufObj
->Pointer
;
2683 for (i
= 0; i
< bufObj
->Size
; i
++)
2690 if (strstr(func
, "Range") == NULL
) { /* If not MapRange */
2691 GLubyte
*buf
= (GLubyte
*) bufObj
->Pointer
;
2693 /* buffer is 100 bytes larger than requested, fill with magic value */
2694 for (i
= 0; i
< 100; i
++) {
2695 buf
[bufObj
->Size
- i
- 1] = 123;
2704 _mesa_MapBufferRange_no_error(GLenum target
, GLintptr offset
,
2705 GLsizeiptr length
, GLbitfield access
)
2707 GET_CURRENT_CONTEXT(ctx
);
2709 struct gl_buffer_object
**bufObjPtr
= get_buffer_target(ctx
, target
);
2710 struct gl_buffer_object
*bufObj
= *bufObjPtr
;
2712 return map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2713 "glMapBufferRange");
2717 _mesa_MapBufferRange(GLenum target
, GLintptr offset
, GLsizeiptr length
,
2720 GET_CURRENT_CONTEXT(ctx
);
2721 struct gl_buffer_object
*bufObj
;
2723 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2724 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2725 "glMapBufferRange(ARB_map_buffer_range not supported)");
2729 bufObj
= get_buffer(ctx
, "glMapBufferRange", target
, GL_INVALID_OPERATION
);
2733 if (!validate_map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2734 "glMapBufferRange"))
2737 return map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2738 "glMapBufferRange");
2742 _mesa_MapNamedBufferRange_no_error(GLuint buffer
, GLintptr offset
,
2743 GLsizeiptr length
, GLbitfield access
)
2745 GET_CURRENT_CONTEXT(ctx
);
2746 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2748 return map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2749 "glMapNamedBufferRange");
2753 _mesa_MapNamedBufferRange(GLuint buffer
, GLintptr offset
, GLsizeiptr length
,
2756 GET_CURRENT_CONTEXT(ctx
);
2757 struct gl_buffer_object
*bufObj
;
2759 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2760 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2761 "glMapNamedBufferRange("
2762 "ARB_map_buffer_range not supported)");
2766 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glMapNamedBufferRange");
2770 if (!validate_map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2771 "glMapNamedBufferRange"))
2774 return map_buffer_range(ctx
, bufObj
, offset
, length
, access
,
2775 "glMapNamedBufferRange");
2779 * Converts GLenum access from MapBuffer and MapNamedBuffer into
2780 * flags for input to map_buffer_range.
2782 * \return true if the type of requested access is permissible.
2785 get_map_buffer_access_flags(struct gl_context
*ctx
, GLenum access
,
2789 case GL_READ_ONLY_ARB
:
2790 *flags
= GL_MAP_READ_BIT
;
2791 return _mesa_is_desktop_gl(ctx
);
2792 case GL_WRITE_ONLY_ARB
:
2793 *flags
= GL_MAP_WRITE_BIT
;
2795 case GL_READ_WRITE_ARB
:
2796 *flags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
2797 return _mesa_is_desktop_gl(ctx
);
2804 _mesa_MapBuffer_no_error(GLenum target
, GLenum access
)
2806 GET_CURRENT_CONTEXT(ctx
);
2808 GLbitfield accessFlags
;
2809 get_map_buffer_access_flags(ctx
, access
, &accessFlags
);
2811 struct gl_buffer_object
**bufObjPtr
= get_buffer_target(ctx
, target
);
2812 struct gl_buffer_object
*bufObj
= *bufObjPtr
;
2814 return map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2819 _mesa_MapBuffer(GLenum target
, GLenum access
)
2821 GET_CURRENT_CONTEXT(ctx
);
2822 struct gl_buffer_object
*bufObj
;
2823 GLbitfield accessFlags
;
2825 if (!get_map_buffer_access_flags(ctx
, access
, &accessFlags
)) {
2826 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapBuffer(invalid access)");
2830 bufObj
= get_buffer(ctx
, "glMapBuffer", target
, GL_INVALID_OPERATION
);
2834 if (!validate_map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2838 return map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2843 _mesa_MapNamedBuffer_no_error(GLuint buffer
, GLenum access
)
2845 GET_CURRENT_CONTEXT(ctx
);
2847 GLbitfield accessFlags
;
2848 get_map_buffer_access_flags(ctx
, access
, &accessFlags
);
2850 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2852 return map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2853 "glMapNamedBuffer");
2857 _mesa_MapNamedBuffer(GLuint buffer
, GLenum access
)
2859 GET_CURRENT_CONTEXT(ctx
);
2860 struct gl_buffer_object
*bufObj
;
2861 GLbitfield accessFlags
;
2863 if (!get_map_buffer_access_flags(ctx
, access
, &accessFlags
)) {
2864 _mesa_error(ctx
, GL_INVALID_ENUM
, "glMapNamedBuffer(invalid access)");
2868 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glMapNamedBuffer");
2872 if (!validate_map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2873 "glMapNamedBuffer"))
2876 return map_buffer_range(ctx
, bufObj
, 0, bufObj
->Size
, accessFlags
,
2877 "glMapNamedBuffer");
2882 flush_mapped_buffer_range(struct gl_context
*ctx
,
2883 struct gl_buffer_object
*bufObj
,
2884 GLintptr offset
, GLsizeiptr length
,
2887 if (!ctx
->Extensions
.ARB_map_buffer_range
) {
2888 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2889 "%s(ARB_map_buffer_range not supported)", func
);
2894 _mesa_error(ctx
, GL_INVALID_VALUE
,
2895 "%s(offset %ld < 0)", func
, (long) offset
);
2900 _mesa_error(ctx
, GL_INVALID_VALUE
,
2901 "%s(length %ld < 0)", func
, (long) length
);
2905 if (!_mesa_bufferobj_mapped(bufObj
, MAP_USER
)) {
2906 /* buffer is not mapped */
2907 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2908 "%s(buffer is not mapped)", func
);
2912 if ((bufObj
->Mappings
[MAP_USER
].AccessFlags
&
2913 GL_MAP_FLUSH_EXPLICIT_BIT
) == 0) {
2914 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2915 "%s(GL_MAP_FLUSH_EXPLICIT_BIT not set)", func
);
2919 if (offset
+ length
> bufObj
->Mappings
[MAP_USER
].Length
) {
2920 _mesa_error(ctx
, GL_INVALID_VALUE
,
2921 "%s(offset %ld + length %ld > mapped length %ld)", func
,
2922 (long) offset
, (long) length
,
2923 (long) bufObj
->Mappings
[MAP_USER
].Length
);
2927 assert(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_WRITE_BIT
);
2929 if (ctx
->Driver
.FlushMappedBufferRange
)
2930 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
,
2935 _mesa_FlushMappedBufferRange_no_error(GLenum target
, GLintptr offset
,
2938 GET_CURRENT_CONTEXT(ctx
);
2939 struct gl_buffer_object
**bufObjPtr
= get_buffer_target(ctx
, target
);
2940 struct gl_buffer_object
*bufObj
= *bufObjPtr
;
2942 if (ctx
->Driver
.FlushMappedBufferRange
)
2943 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
,
2948 _mesa_FlushMappedBufferRange(GLenum target
, GLintptr offset
,
2951 GET_CURRENT_CONTEXT(ctx
);
2952 struct gl_buffer_object
*bufObj
;
2954 bufObj
= get_buffer(ctx
, "glFlushMappedBufferRange", target
,
2955 GL_INVALID_OPERATION
);
2959 flush_mapped_buffer_range(ctx
, bufObj
, offset
, length
,
2960 "glFlushMappedBufferRange");
2964 _mesa_FlushMappedNamedBufferRange_no_error(GLuint buffer
, GLintptr offset
,
2967 GET_CURRENT_CONTEXT(ctx
);
2968 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
2970 if (ctx
->Driver
.FlushMappedBufferRange
)
2971 ctx
->Driver
.FlushMappedBufferRange(ctx
, offset
, length
, bufObj
,
2976 _mesa_FlushMappedNamedBufferRange(GLuint buffer
, GLintptr offset
,
2979 GET_CURRENT_CONTEXT(ctx
);
2980 struct gl_buffer_object
*bufObj
;
2982 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
2983 "glFlushMappedNamedBufferRange");
2987 flush_mapped_buffer_range(ctx
, bufObj
, offset
, length
,
2988 "glFlushMappedNamedBufferRange");
2993 * Binds a buffer object to a uniform buffer binding point.
2995 * The caller is responsible for flushing vertices and updating
2999 set_ubo_binding(struct gl_context
*ctx
,
3000 struct gl_uniform_buffer_binding
*binding
,
3001 struct gl_buffer_object
*bufObj
,
3006 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
3008 binding
->Offset
= offset
;
3009 binding
->Size
= size
;
3010 binding
->AutomaticSize
= autoSize
;
3012 /* If this is a real buffer object, mark it has having been used
3013 * at some point as a UBO.
3016 bufObj
->UsageHistory
|= USAGE_UNIFORM_BUFFER
;
3020 * Binds a buffer object to a shader storage buffer binding point.
3022 * The caller is responsible for flushing vertices and updating
3026 set_ssbo_binding(struct gl_context
*ctx
,
3027 struct gl_shader_storage_buffer_binding
*binding
,
3028 struct gl_buffer_object
*bufObj
,
3033 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
3035 binding
->Offset
= offset
;
3036 binding
->Size
= size
;
3037 binding
->AutomaticSize
= autoSize
;
3039 /* If this is a real buffer object, mark it has having been used
3040 * at some point as a SSBO.
3043 bufObj
->UsageHistory
|= USAGE_SHADER_STORAGE_BUFFER
;
3047 * Binds a buffer object to a uniform buffer binding point.
3049 * Unlike set_ubo_binding(), this function also flushes vertices
3050 * and updates NewDriverState. It also checks if the binding
3051 * has actually changed before updating it.
3054 bind_uniform_buffer(struct gl_context
*ctx
,
3056 struct gl_buffer_object
*bufObj
,
3061 struct gl_uniform_buffer_binding
*binding
=
3062 &ctx
->UniformBufferBindings
[index
];
3064 if (binding
->BufferObject
== bufObj
&&
3065 binding
->Offset
== offset
&&
3066 binding
->Size
== size
&&
3067 binding
->AutomaticSize
== autoSize
) {
3071 FLUSH_VERTICES(ctx
, 0);
3072 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3074 set_ubo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
3078 * Binds a buffer object to a shader storage buffer binding point.
3080 * Unlike set_ssbo_binding(), this function also flushes vertices
3081 * and updates NewDriverState. It also checks if the binding
3082 * has actually changed before updating it.
3085 bind_shader_storage_buffer(struct gl_context
*ctx
,
3087 struct gl_buffer_object
*bufObj
,
3092 struct gl_shader_storage_buffer_binding
*binding
=
3093 &ctx
->ShaderStorageBufferBindings
[index
];
3095 if (binding
->BufferObject
== bufObj
&&
3096 binding
->Offset
== offset
&&
3097 binding
->Size
== size
&&
3098 binding
->AutomaticSize
== autoSize
) {
3102 FLUSH_VERTICES(ctx
, 0);
3103 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewShaderStorageBuffer
;
3105 set_ssbo_binding(ctx
, binding
, bufObj
, offset
, size
, autoSize
);
3109 * Bind a region of a buffer object to a uniform block binding point.
3110 * \param index the uniform buffer binding point index
3111 * \param bufObj the buffer object
3112 * \param offset offset to the start of buffer object region
3113 * \param size size of the buffer object region
3116 bind_buffer_range_uniform_buffer(struct gl_context
*ctx
,
3118 struct gl_buffer_object
*bufObj
,
3122 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
3123 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
3127 if (offset
& (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3128 _mesa_error(ctx
, GL_INVALID_VALUE
,
3129 "glBindBufferRange(offset misaligned %d/%d)", (int) offset
,
3130 ctx
->Const
.UniformBufferOffsetAlignment
);
3134 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
3139 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
3140 bind_uniform_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
3144 * Bind a region of a buffer object to a shader storage block binding point.
3145 * \param index the shader storage buffer binding point index
3146 * \param bufObj the buffer object
3147 * \param offset offset to the start of buffer object region
3148 * \param size size of the buffer object region
3151 bind_buffer_range_shader_storage_buffer(struct gl_context
*ctx
,
3153 struct gl_buffer_object
*bufObj
,
3157 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
) {
3158 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(index=%d)", index
);
3162 if (offset
& (ctx
->Const
.ShaderStorageBufferOffsetAlignment
- 1)) {
3163 _mesa_error(ctx
, GL_INVALID_VALUE
,
3164 "glBindBufferRange(offset misaligned %d/%d)", (int) offset
,
3165 ctx
->Const
.ShaderStorageBufferOffsetAlignment
);
3169 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
3174 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, bufObj
);
3175 bind_shader_storage_buffer(ctx
, index
, bufObj
, offset
, size
, GL_FALSE
);
3179 * Bind a buffer object to a uniform block binding point.
3180 * As above, but offset = 0.
3183 bind_buffer_base_uniform_buffer(struct gl_context
*ctx
,
3185 struct gl_buffer_object
*bufObj
)
3187 if (index
>= ctx
->Const
.MaxUniformBufferBindings
) {
3188 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
3192 _mesa_reference_buffer_object(ctx
, &ctx
->UniformBuffer
, bufObj
);
3194 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3195 bind_uniform_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
3197 bind_uniform_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
3201 * Bind a buffer object to a shader storage block binding point.
3202 * As above, but offset = 0.
3205 bind_buffer_base_shader_storage_buffer(struct gl_context
*ctx
,
3207 struct gl_buffer_object
*bufObj
)
3209 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
) {
3210 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferBase(index=%d)", index
);
3214 _mesa_reference_buffer_object(ctx
, &ctx
->ShaderStorageBuffer
, bufObj
);
3216 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3217 bind_shader_storage_buffer(ctx
, index
, bufObj
, -1, -1, GL_TRUE
);
3219 bind_shader_storage_buffer(ctx
, index
, bufObj
, 0, 0, GL_TRUE
);
3223 * Binds a buffer object to an atomic buffer binding point.
3225 * The caller is responsible for validating the offset,
3226 * flushing the vertices and updating NewDriverState.
3229 set_atomic_buffer_binding(struct gl_context
*ctx
,
3230 struct gl_atomic_buffer_binding
*binding
,
3231 struct gl_buffer_object
*bufObj
,
3235 _mesa_reference_buffer_object(ctx
, &binding
->BufferObject
, bufObj
);
3237 if (bufObj
== ctx
->Shared
->NullBufferObj
) {
3238 binding
->Offset
= 0;
3241 binding
->Offset
= offset
;
3242 binding
->Size
= size
;
3243 bufObj
->UsageHistory
|= USAGE_ATOMIC_COUNTER_BUFFER
;
3248 * Binds a buffer object to an atomic buffer binding point.
3250 * Unlike set_atomic_buffer_binding(), this function also validates the
3251 * index and offset, flushes vertices, and updates NewDriverState.
3252 * It also checks if the binding has actually changing before
3256 bind_atomic_buffer(struct gl_context
*ctx
,
3258 struct gl_buffer_object
*bufObj
,
3263 struct gl_atomic_buffer_binding
*binding
;
3265 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
) {
3266 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%d)", name
, index
);
3270 if (offset
& (ATOMIC_COUNTER_SIZE
- 1)) {
3271 _mesa_error(ctx
, GL_INVALID_VALUE
,
3272 "%s(offset misaligned %d/%d)", name
, (int) offset
,
3273 ATOMIC_COUNTER_SIZE
);
3277 _mesa_reference_buffer_object(ctx
, &ctx
->AtomicBuffer
, bufObj
);
3279 binding
= &ctx
->AtomicBufferBindings
[index
];
3280 if (binding
->BufferObject
== bufObj
&&
3281 binding
->Offset
== offset
&&
3282 binding
->Size
== size
) {
3286 FLUSH_VERTICES(ctx
, 0);
3287 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3289 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offset
, size
);
3293 bind_buffers_check_offset_and_size(struct gl_context
*ctx
,
3295 const GLintptr
*offsets
,
3296 const GLsizeiptr
*sizes
)
3298 if (offsets
[index
] < 0) {
3299 /* The ARB_multi_bind spec says:
3301 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3302 * value in <offsets> is less than zero (per binding)."
3304 _mesa_error(ctx
, GL_INVALID_VALUE
,
3305 "glBindBuffersRange(offsets[%u]=%" PRId64
" < 0)",
3306 index
, (int64_t) offsets
[index
]);
3310 if (sizes
[index
] <= 0) {
3311 /* The ARB_multi_bind spec says:
3313 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3314 * value in <sizes> is less than or equal to zero (per binding)."
3316 _mesa_error(ctx
, GL_INVALID_VALUE
,
3317 "glBindBuffersRange(sizes[%u]=%" PRId64
" <= 0)",
3318 index
, (int64_t) sizes
[index
]);
3326 error_check_bind_uniform_buffers(struct gl_context
*ctx
,
3327 GLuint first
, GLsizei count
,
3330 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
3331 _mesa_error(ctx
, GL_INVALID_ENUM
,
3332 "%s(target=GL_UNIFORM_BUFFER)", caller
);
3336 /* The ARB_multi_bind_spec says:
3338 * "An INVALID_OPERATION error is generated if <first> + <count> is
3339 * greater than the number of target-specific indexed binding points,
3340 * as described in section 6.7.1."
3342 if (first
+ count
> ctx
->Const
.MaxUniformBufferBindings
) {
3343 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3344 "%s(first=%u + count=%d > the value of "
3345 "GL_MAX_UNIFORM_BUFFER_BINDINGS=%u)",
3346 caller
, first
, count
,
3347 ctx
->Const
.MaxUniformBufferBindings
);
3355 error_check_bind_shader_storage_buffers(struct gl_context
*ctx
,
3356 GLuint first
, GLsizei count
,
3359 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
) {
3360 _mesa_error(ctx
, GL_INVALID_ENUM
,
3361 "%s(target=GL_SHADER_STORAGE_BUFFER)", caller
);
3365 /* The ARB_multi_bind_spec says:
3367 * "An INVALID_OPERATION error is generated if <first> + <count> is
3368 * greater than the number of target-specific indexed binding points,
3369 * as described in section 6.7.1."
3371 if (first
+ count
> ctx
->Const
.MaxShaderStorageBufferBindings
) {
3372 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3373 "%s(first=%u + count=%d > the value of "
3374 "GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS=%u)",
3375 caller
, first
, count
,
3376 ctx
->Const
.MaxShaderStorageBufferBindings
);
3384 * Unbind all uniform buffers in the range
3385 * <first> through <first>+<count>-1
3388 unbind_uniform_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
3390 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
3392 for (int i
= 0; i
< count
; i
++)
3393 set_ubo_binding(ctx
, &ctx
->UniformBufferBindings
[first
+ i
],
3394 bufObj
, -1, -1, GL_TRUE
);
3398 * Unbind all shader storage buffers in the range
3399 * <first> through <first>+<count>-1
3402 unbind_shader_storage_buffers(struct gl_context
*ctx
, GLuint first
,
3405 struct gl_buffer_object
*bufObj
= ctx
->Shared
->NullBufferObj
;
3407 for (int i
= 0; i
< count
; i
++)
3408 set_ssbo_binding(ctx
, &ctx
->ShaderStorageBufferBindings
[first
+ i
],
3409 bufObj
, -1, -1, GL_TRUE
);
3413 bind_uniform_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
,
3414 const GLuint
*buffers
,
3416 const GLintptr
*offsets
, const GLsizeiptr
*sizes
,
3419 if (!error_check_bind_uniform_buffers(ctx
, first
, count
, caller
))
3422 /* Assume that at least one binding will be changed */
3423 FLUSH_VERTICES(ctx
, 0);
3424 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
3427 /* The ARB_multi_bind spec says:
3429 * "If <buffers> is NULL, all bindings from <first> through
3430 * <first>+<count>-1 are reset to their unbound (zero) state.
3431 * In this case, the offsets and sizes associated with the
3432 * binding points are set to default values, ignoring
3433 * <offsets> and <sizes>."
3435 unbind_uniform_buffers(ctx
, first
, count
);
3439 /* Note that the error semantics for multi-bind commands differ from
3440 * those of other GL commands.
3442 * The Issues section in the ARB_multi_bind spec says:
3444 * "(11) Typically, OpenGL specifies that if an error is generated by a
3445 * command, that command has no effect. This is somewhat
3446 * unfortunate for multi-bind commands, because it would require a
3447 * first pass to scan the entire list of bound objects for errors
3448 * and then a second pass to actually perform the bindings.
3449 * Should we have different error semantics?
3451 * RESOLVED: Yes. In this specification, when the parameters for
3452 * one of the <count> binding points are invalid, that binding point
3453 * is not updated and an error will be generated. However, other
3454 * binding points in the same command will be updated if their
3455 * parameters are valid and no other error occurs."
3458 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
3460 for (int i
= 0; i
< count
; i
++) {
3461 struct gl_uniform_buffer_binding
*binding
=
3462 &ctx
->UniformBufferBindings
[first
+ i
];
3463 struct gl_buffer_object
*bufObj
;
3464 GLintptr offset
= 0;
3465 GLsizeiptr size
= 0;
3468 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3471 /* The ARB_multi_bind spec says:
3473 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3474 * pair of values in <offsets> and <sizes> does not respectively
3475 * satisfy the constraints described for those parameters for the
3476 * specified target, as described in section 6.7.1 (per binding)."
3478 * Section 6.7.1 refers to table 6.5, which says:
3480 * "┌───────────────────────────────────────────────────────────────┐
3481 * │ Uniform buffer array bindings (see sec. 7.6) │
3482 * ├─────────────────────┬─────────────────────────────────────────┤
3484 * │ offset restriction │ multiple of value of UNIFORM_BUFFER_- │
3485 * │ │ OFFSET_ALIGNMENT │
3487 * │ size restriction │ none │
3488 * └─────────────────────┴─────────────────────────────────────────┘"
3490 if (offsets
[i
] & (ctx
->Const
.UniformBufferOffsetAlignment
- 1)) {
3491 _mesa_error(ctx
, GL_INVALID_VALUE
,
3492 "glBindBuffersRange(offsets[%u]=%" PRId64
3493 " is misaligned; it must be a multiple of the value of "
3494 "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT=%u when "
3495 "target=GL_UNIFORM_BUFFER)",
3496 i
, (int64_t) offsets
[i
],
3497 ctx
->Const
.UniformBufferOffsetAlignment
);
3501 offset
= offsets
[i
];
3505 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3506 bufObj
= binding
->BufferObject
;
3508 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, caller
);
3511 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3512 set_ubo_binding(ctx
, binding
, bufObj
, -1, -1, !range
);
3514 set_ubo_binding(ctx
, binding
, bufObj
, offset
, size
, !range
);
3518 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
3522 bind_shader_storage_buffers(struct gl_context
*ctx
, GLuint first
,
3523 GLsizei count
, const GLuint
*buffers
,
3525 const GLintptr
*offsets
,
3526 const GLsizeiptr
*sizes
,
3529 if (!error_check_bind_shader_storage_buffers(ctx
, first
, count
, caller
))
3532 /* Assume that at least one binding will be changed */
3533 FLUSH_VERTICES(ctx
, 0);
3534 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewShaderStorageBuffer
;
3537 /* The ARB_multi_bind spec says:
3539 * "If <buffers> is NULL, all bindings from <first> through
3540 * <first>+<count>-1 are reset to their unbound (zero) state.
3541 * In this case, the offsets and sizes associated with the
3542 * binding points are set to default values, ignoring
3543 * <offsets> and <sizes>."
3545 unbind_shader_storage_buffers(ctx
, first
, count
);
3549 /* Note that the error semantics for multi-bind commands differ from
3550 * those of other GL commands.
3552 * The Issues section in the ARB_multi_bind spec says:
3554 * "(11) Typically, OpenGL specifies that if an error is generated by a
3555 * command, that command has no effect. This is somewhat
3556 * unfortunate for multi-bind commands, because it would require a
3557 * first pass to scan the entire list of bound objects for errors
3558 * and then a second pass to actually perform the bindings.
3559 * Should we have different error semantics?
3561 * RESOLVED: Yes. In this specification, when the parameters for
3562 * one of the <count> binding points are invalid, that binding point
3563 * is not updated and an error will be generated. However, other
3564 * binding points in the same command will be updated if their
3565 * parameters are valid and no other error occurs."
3568 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
3570 for (int i
= 0; i
< count
; i
++) {
3571 struct gl_shader_storage_buffer_binding
*binding
=
3572 &ctx
->ShaderStorageBufferBindings
[first
+ i
];
3573 struct gl_buffer_object
*bufObj
;
3574 GLintptr offset
= 0;
3575 GLsizeiptr size
= 0;
3578 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3581 /* The ARB_multi_bind spec says:
3583 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3584 * pair of values in <offsets> and <sizes> does not respectively
3585 * satisfy the constraints described for those parameters for the
3586 * specified target, as described in section 6.7.1 (per binding)."
3588 * Section 6.7.1 refers to table 6.5, which says:
3590 * "┌───────────────────────────────────────────────────────────────┐
3591 * │ Shader storage buffer array bindings (see sec. 7.8) │
3592 * ├─────────────────────┬─────────────────────────────────────────┤
3594 * │ offset restriction │ multiple of value of SHADER_STORAGE_- │
3595 * │ │ BUFFER_OFFSET_ALIGNMENT │
3597 * │ size restriction │ none │
3598 * └─────────────────────┴─────────────────────────────────────────┘"
3600 if (offsets
[i
] & (ctx
->Const
.ShaderStorageBufferOffsetAlignment
- 1)) {
3601 _mesa_error(ctx
, GL_INVALID_VALUE
,
3602 "glBindBuffersRange(offsets[%u]=%" PRId64
3603 " is misaligned; it must be a multiple of the value of "
3604 "GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT=%u when "
3605 "target=GL_SHADER_STORAGE_BUFFER)",
3606 i
, (int64_t) offsets
[i
],
3607 ctx
->Const
.ShaderStorageBufferOffsetAlignment
);
3611 offset
= offsets
[i
];
3615 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3616 bufObj
= binding
->BufferObject
;
3618 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, caller
);
3621 if (bufObj
== ctx
->Shared
->NullBufferObj
)
3622 set_ssbo_binding(ctx
, binding
, bufObj
, -1, -1, !range
);
3624 set_ssbo_binding(ctx
, binding
, bufObj
, offset
, size
, !range
);
3628 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
3632 error_check_bind_xfb_buffers(struct gl_context
*ctx
,
3633 struct gl_transform_feedback_object
*tfObj
,
3634 GLuint first
, GLsizei count
, const char *caller
)
3636 if (!ctx
->Extensions
.EXT_transform_feedback
) {
3637 _mesa_error(ctx
, GL_INVALID_ENUM
,
3638 "%s(target=GL_TRANSFORM_FEEDBACK_BUFFER)", caller
);
3642 /* Page 398 of the PDF of the OpenGL 4.4 (Core Profile) spec says:
3644 * "An INVALID_OPERATION error is generated :
3647 * • by BindBufferRange or BindBufferBase if target is TRANSFORM_-
3648 * FEEDBACK_BUFFER and transform feedback is currently active."
3650 * We assume that this is also meant to apply to BindBuffersRange
3651 * and BindBuffersBase.
3653 if (tfObj
->Active
) {
3654 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3655 "%s(Changing transform feedback buffers while "
3656 "transform feedback is active)", caller
);
3660 /* The ARB_multi_bind_spec says:
3662 * "An INVALID_OPERATION error is generated if <first> + <count> is
3663 * greater than the number of target-specific indexed binding points,
3664 * as described in section 6.7.1."
3666 if (first
+ count
> ctx
->Const
.MaxTransformFeedbackBuffers
) {
3667 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3668 "%s(first=%u + count=%d > the value of "
3669 "GL_MAX_TRANSFORM_FEEDBACK_BUFFERS=%u)",
3670 caller
, first
, count
,
3671 ctx
->Const
.MaxTransformFeedbackBuffers
);
3679 * Unbind all transform feedback buffers in the range
3680 * <first> through <first>+<count>-1
3683 unbind_xfb_buffers(struct gl_context
*ctx
,
3684 struct gl_transform_feedback_object
*tfObj
,
3685 GLuint first
, GLsizei count
)
3687 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3689 for (int i
= 0; i
< count
; i
++)
3690 _mesa_set_transform_feedback_binding(ctx
, tfObj
, first
+ i
,
3695 bind_xfb_buffers(struct gl_context
*ctx
,
3696 GLuint first
, GLsizei count
,
3697 const GLuint
*buffers
,
3699 const GLintptr
*offsets
,
3700 const GLsizeiptr
*sizes
,
3703 struct gl_transform_feedback_object
*tfObj
=
3704 ctx
->TransformFeedback
.CurrentObject
;
3706 if (!error_check_bind_xfb_buffers(ctx
, tfObj
, first
, count
, caller
))
3709 /* Assume that at least one binding will be changed */
3710 FLUSH_VERTICES(ctx
, 0);
3711 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTransformFeedback
;
3714 /* The ARB_multi_bind spec says:
3716 * "If <buffers> is NULL, all bindings from <first> through
3717 * <first>+<count>-1 are reset to their unbound (zero) state.
3718 * In this case, the offsets and sizes associated with the
3719 * binding points are set to default values, ignoring
3720 * <offsets> and <sizes>."
3722 unbind_xfb_buffers(ctx
, tfObj
, first
, count
);
3726 /* Note that the error semantics for multi-bind commands differ from
3727 * those of other GL commands.
3729 * The Issues section in the ARB_multi_bind spec says:
3731 * "(11) Typically, OpenGL specifies that if an error is generated by a
3732 * command, that command has no effect. This is somewhat
3733 * unfortunate for multi-bind commands, because it would require a
3734 * first pass to scan the entire list of bound objects for errors
3735 * and then a second pass to actually perform the bindings.
3736 * Should we have different error semantics?
3738 * RESOLVED: Yes. In this specification, when the parameters for
3739 * one of the <count> binding points are invalid, that binding point
3740 * is not updated and an error will be generated. However, other
3741 * binding points in the same command will be updated if their
3742 * parameters are valid and no other error occurs."
3745 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
3747 for (int i
= 0; i
< count
; i
++) {
3748 const GLuint index
= first
+ i
;
3749 struct gl_buffer_object
* const boundBufObj
= tfObj
->Buffers
[index
];
3750 struct gl_buffer_object
*bufObj
;
3751 GLintptr offset
= 0;
3752 GLsizeiptr size
= 0;
3755 offset
= offsets
[i
];
3758 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3761 /* The ARB_multi_bind spec says:
3763 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3764 * pair of values in <offsets> and <sizes> does not respectively
3765 * satisfy the constraints described for those parameters for the
3766 * specified target, as described in section 6.7.1 (per binding)."
3768 * Section 6.7.1 refers to table 6.5, which says:
3770 * "┌───────────────────────────────────────────────────────────────┐
3771 * │ Transform feedback array bindings (see sec. 13.2.2) │
3772 * ├───────────────────────┬───────────────────────────────────────┤
3774 * │ offset restriction │ multiple of 4 │
3776 * │ size restriction │ multiple of 4 │
3777 * └───────────────────────┴───────────────────────────────────────┘"
3779 if (offsets
[i
] & 0x3) {
3780 _mesa_error(ctx
, GL_INVALID_VALUE
,
3781 "glBindBuffersRange(offsets[%u]=%" PRId64
3782 " is misaligned; it must be a multiple of 4 when "
3783 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3784 i
, (int64_t) offsets
[i
]);
3788 if (sizes
[i
] & 0x3) {
3789 _mesa_error(ctx
, GL_INVALID_VALUE
,
3790 "glBindBuffersRange(sizes[%u]=%" PRId64
3791 " is misaligned; it must be a multiple of 4 when "
3792 "target=GL_TRANSFORM_FEEDBACK_BUFFER)",
3793 i
, (int64_t) sizes
[i
]);
3797 offset
= offsets
[i
];
3801 if (boundBufObj
&& boundBufObj
->Name
== buffers
[i
])
3802 bufObj
= boundBufObj
;
3804 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, caller
);
3807 _mesa_set_transform_feedback_binding(ctx
, tfObj
, index
, bufObj
,
3811 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
3815 error_check_bind_atomic_buffers(struct gl_context
*ctx
,
3816 GLuint first
, GLsizei count
,
3819 if (!ctx
->Extensions
.ARB_shader_atomic_counters
) {
3820 _mesa_error(ctx
, GL_INVALID_ENUM
,
3821 "%s(target=GL_ATOMIC_COUNTER_BUFFER)", caller
);
3825 /* The ARB_multi_bind_spec says:
3827 * "An INVALID_OPERATION error is generated if <first> + <count> is
3828 * greater than the number of target-specific indexed binding points,
3829 * as described in section 6.7.1."
3831 if (first
+ count
> ctx
->Const
.MaxAtomicBufferBindings
) {
3832 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3833 "%s(first=%u + count=%d > the value of "
3834 "GL_MAX_ATOMIC_BUFFER_BINDINGS=%u)",
3835 caller
, first
, count
, ctx
->Const
.MaxAtomicBufferBindings
);
3843 * Unbind all atomic counter buffers in the range
3844 * <first> through <first>+<count>-1
3847 unbind_atomic_buffers(struct gl_context
*ctx
, GLuint first
, GLsizei count
)
3849 struct gl_buffer_object
* const bufObj
= ctx
->Shared
->NullBufferObj
;
3851 for (int i
= 0; i
< count
; i
++)
3852 set_atomic_buffer_binding(ctx
, &ctx
->AtomicBufferBindings
[first
+ i
],
3857 bind_atomic_buffers(struct gl_context
*ctx
,
3860 const GLuint
*buffers
,
3862 const GLintptr
*offsets
,
3863 const GLsizeiptr
*sizes
,
3866 if (!error_check_bind_atomic_buffers(ctx
, first
, count
, caller
))
3869 /* Assume that at least one binding will be changed */
3870 FLUSH_VERTICES(ctx
, 0);
3871 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAtomicBuffer
;
3874 /* The ARB_multi_bind spec says:
3876 * "If <buffers> is NULL, all bindings from <first> through
3877 * <first>+<count>-1 are reset to their unbound (zero) state.
3878 * In this case, the offsets and sizes associated with the
3879 * binding points are set to default values, ignoring
3880 * <offsets> and <sizes>."
3882 unbind_atomic_buffers(ctx
, first
, count
);
3886 /* Note that the error semantics for multi-bind commands differ from
3887 * those of other GL commands.
3889 * The Issues section in the ARB_multi_bind spec says:
3891 * "(11) Typically, OpenGL specifies that if an error is generated by a
3892 * command, that command has no effect. This is somewhat
3893 * unfortunate for multi-bind commands, because it would require a
3894 * first pass to scan the entire list of bound objects for errors
3895 * and then a second pass to actually perform the bindings.
3896 * Should we have different error semantics?
3898 * RESOLVED: Yes. In this specification, when the parameters for
3899 * one of the <count> binding points are invalid, that binding point
3900 * is not updated and an error will be generated. However, other
3901 * binding points in the same command will be updated if their
3902 * parameters are valid and no other error occurs."
3905 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
3907 for (int i
= 0; i
< count
; i
++) {
3908 struct gl_atomic_buffer_binding
*binding
=
3909 &ctx
->AtomicBufferBindings
[first
+ i
];
3910 struct gl_buffer_object
*bufObj
;
3911 GLintptr offset
= 0;
3912 GLsizeiptr size
= 0;
3915 if (!bind_buffers_check_offset_and_size(ctx
, i
, offsets
, sizes
))
3918 /* The ARB_multi_bind spec says:
3920 * "An INVALID_VALUE error is generated by BindBuffersRange if any
3921 * pair of values in <offsets> and <sizes> does not respectively
3922 * satisfy the constraints described for those parameters for the
3923 * specified target, as described in section 6.7.1 (per binding)."
3925 * Section 6.7.1 refers to table 6.5, which says:
3927 * "┌───────────────────────────────────────────────────────────────┐
3928 * │ Atomic counter array bindings (see sec. 7.7.2) │
3929 * ├───────────────────────┬───────────────────────────────────────┤
3931 * │ offset restriction │ multiple of 4 │
3933 * │ size restriction │ none │
3934 * └───────────────────────┴───────────────────────────────────────┘"
3936 if (offsets
[i
] & (ATOMIC_COUNTER_SIZE
- 1)) {
3937 _mesa_error(ctx
, GL_INVALID_VALUE
,
3938 "glBindBuffersRange(offsets[%u]=%" PRId64
3939 " is misaligned; it must be a multiple of %d when "
3940 "target=GL_ATOMIC_COUNTER_BUFFER)",
3941 i
, (int64_t) offsets
[i
], ATOMIC_COUNTER_SIZE
);
3945 offset
= offsets
[i
];
3949 if (binding
->BufferObject
&& binding
->BufferObject
->Name
== buffers
[i
])
3950 bufObj
= binding
->BufferObject
;
3952 bufObj
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, caller
);
3955 set_atomic_buffer_binding(ctx
, binding
, bufObj
, offset
, size
);
3958 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
3962 _mesa_BindBufferRange(GLenum target
, GLuint index
,
3963 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
3965 GET_CURRENT_CONTEXT(ctx
);
3966 struct gl_buffer_object
*bufObj
;
3968 if (MESA_VERBOSE
& VERBOSE_API
) {
3969 _mesa_debug(ctx
, "glBindBufferRange(%s, %u, %u, %lu, %lu)\n",
3970 _mesa_enum_to_string(target
), index
, buffer
,
3971 (unsigned long) offset
, (unsigned long) size
);
3975 bufObj
= ctx
->Shared
->NullBufferObj
;
3977 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3979 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
,
3980 &bufObj
, "glBindBufferRange"))
3984 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3985 "glBindBufferRange(invalid buffer=%u)", buffer
);
3991 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindBufferRange(size=%d)",
3998 case GL_TRANSFORM_FEEDBACK_BUFFER
:
3999 _mesa_bind_buffer_range_transform_feedback(ctx
,
4000 ctx
->TransformFeedback
.CurrentObject
,
4001 index
, bufObj
, offset
, size
,
4004 case GL_UNIFORM_BUFFER
:
4005 bind_buffer_range_uniform_buffer(ctx
, index
, bufObj
, offset
, size
);
4007 case GL_SHADER_STORAGE_BUFFER
:
4008 bind_buffer_range_shader_storage_buffer(ctx
, index
, bufObj
, offset
, size
);
4010 case GL_ATOMIC_COUNTER_BUFFER
:
4011 bind_atomic_buffer(ctx
, index
, bufObj
, offset
, size
,
4012 "glBindBufferRange");
4015 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferRange(target)");
4021 _mesa_BindBufferBase(GLenum target
, GLuint index
, GLuint buffer
)
4023 GET_CURRENT_CONTEXT(ctx
);
4024 struct gl_buffer_object
*bufObj
;
4026 if (MESA_VERBOSE
& VERBOSE_API
) {
4027 _mesa_debug(ctx
, "glBindBufferBase(%s, %u, %u)\n",
4028 _mesa_enum_to_string(target
), index
, buffer
);
4032 bufObj
= ctx
->Shared
->NullBufferObj
;
4034 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4036 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
,
4037 &bufObj
, "glBindBufferBase"))
4041 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4042 "glBindBufferBase(invalid buffer=%u)", buffer
);
4046 /* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
4047 * regards to BindBufferBase. It says (GL 3.1 core spec, page 63):
4049 * "BindBufferBase is equivalent to calling BindBufferRange with offset
4050 * zero and size equal to the size of buffer."
4052 * but it says for glGetIntegeri_v (GL 3.1 core spec, page 230):
4054 * "If the parameter (starting offset or size) was not specified when the
4055 * buffer object was bound, zero is returned."
4057 * What happens if the size of the buffer changes? Does the size of the
4058 * buffer at the moment glBindBufferBase was called still play a role, like
4059 * the first quote would imply, or is the size meaningless in the
4060 * glBindBufferBase case like the second quote would suggest? The GL 4.1
4061 * core spec page 45 says:
4063 * "It is equivalent to calling BindBufferRange with offset zero, while
4064 * size is determined by the size of the bound buffer at the time the
4067 * My interpretation is that the GL 4.1 spec was a clarification of the
4068 * behavior, not a change. In particular, this choice will only make
4069 * rendering work in cases where it would have had undefined results.
4073 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4074 _mesa_bind_buffer_base_transform_feedback(ctx
,
4075 ctx
->TransformFeedback
.CurrentObject
,
4076 index
, bufObj
, false);
4078 case GL_UNIFORM_BUFFER
:
4079 bind_buffer_base_uniform_buffer(ctx
, index
, bufObj
);
4081 case GL_SHADER_STORAGE_BUFFER
:
4082 bind_buffer_base_shader_storage_buffer(ctx
, index
, bufObj
);
4084 case GL_ATOMIC_COUNTER_BUFFER
:
4085 bind_atomic_buffer(ctx
, index
, bufObj
, 0, 0,
4086 "glBindBufferBase");
4089 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBufferBase(target)");
4095 _mesa_BindBuffersRange(GLenum target
, GLuint first
, GLsizei count
,
4096 const GLuint
*buffers
,
4097 const GLintptr
*offsets
, const GLsizeiptr
*sizes
)
4099 GET_CURRENT_CONTEXT(ctx
);
4101 if (MESA_VERBOSE
& VERBOSE_API
) {
4102 _mesa_debug(ctx
, "glBindBuffersRange(%s, %u, %d, %p, %p, %p)\n",
4103 _mesa_enum_to_string(target
), first
, count
,
4104 buffers
, offsets
, sizes
);
4108 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4109 bind_xfb_buffers(ctx
, first
, count
, buffers
, true, offsets
, sizes
,
4110 "glBindBuffersRange");
4112 case GL_UNIFORM_BUFFER
:
4113 bind_uniform_buffers(ctx
, first
, count
, buffers
, true, offsets
, sizes
,
4114 "glBindBuffersRange");
4116 case GL_SHADER_STORAGE_BUFFER
:
4117 bind_shader_storage_buffers(ctx
, first
, count
, buffers
, true, offsets
, sizes
,
4118 "glBindBuffersRange");
4120 case GL_ATOMIC_COUNTER_BUFFER
:
4121 bind_atomic_buffers(ctx
, first
, count
, buffers
, true, offsets
, sizes
,
4122 "glBindBuffersRange");
4125 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersRange(target=%s)",
4126 _mesa_enum_to_string(target
));
4132 _mesa_BindBuffersBase(GLenum target
, GLuint first
, GLsizei count
,
4133 const GLuint
*buffers
)
4135 GET_CURRENT_CONTEXT(ctx
);
4137 if (MESA_VERBOSE
& VERBOSE_API
) {
4138 _mesa_debug(ctx
, "glBindBuffersBase(%s, %u, %d, %p)\n",
4139 _mesa_enum_to_string(target
), first
, count
, buffers
);
4143 case GL_TRANSFORM_FEEDBACK_BUFFER
:
4144 bind_xfb_buffers(ctx
, first
, count
, buffers
, false, NULL
, NULL
,
4145 "glBindBuffersBase");
4147 case GL_UNIFORM_BUFFER
:
4148 bind_uniform_buffers(ctx
, first
, count
, buffers
, false, NULL
, NULL
,
4149 "glBindBuffersBase");
4151 case GL_SHADER_STORAGE_BUFFER
:
4152 bind_shader_storage_buffers(ctx
, first
, count
, buffers
, false, NULL
, NULL
,
4153 "glBindBuffersBase");
4155 case GL_ATOMIC_COUNTER_BUFFER
:
4156 bind_atomic_buffers(ctx
, first
, count
, buffers
, false, NULL
, NULL
,
4157 "glBindBuffersBase");
4160 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindBuffersBase(target=%s)",
4161 _mesa_enum_to_string(target
));
4167 _mesa_InvalidateBufferSubData(GLuint buffer
, GLintptr offset
,
4170 GET_CURRENT_CONTEXT(ctx
);
4171 struct gl_buffer_object
*bufObj
;
4172 const GLintptr end
= offset
+ length
;
4174 /* Section 6.5 (Invalidating Buffer Data) of the OpenGL 4.5 (Compatibility
4175 * Profile) spec says:
4177 * "An INVALID_VALUE error is generated if buffer is zero or is not the
4178 * name of an existing buffer object."
4180 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4181 if (!bufObj
|| bufObj
== &DummyBufferObject
) {
4182 _mesa_error(ctx
, GL_INVALID_VALUE
,
4183 "glInvalidateBufferSubData(name = %u) invalid object",
4188 /* The GL_ARB_invalidate_subdata spec says:
4190 * "An INVALID_VALUE error is generated if <offset> or <length> is
4191 * negative, or if <offset> + <length> is greater than the value of
4194 if (offset
< 0 || length
< 0 || end
> bufObj
->Size
) {
4195 _mesa_error(ctx
, GL_INVALID_VALUE
,
4196 "glInvalidateBufferSubData(invalid offset or length)");
4200 /* The OpenGL 4.4 (Core Profile) spec says:
4202 * "An INVALID_OPERATION error is generated if buffer is currently
4203 * mapped by MapBuffer or if the invalidate range intersects the range
4204 * currently mapped by MapBufferRange, unless it was mapped
4205 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
4207 if (!(bufObj
->Mappings
[MAP_USER
].AccessFlags
& GL_MAP_PERSISTENT_BIT
) &&
4208 bufferobj_range_mapped(bufObj
, offset
, length
)) {
4209 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4210 "glInvalidateBufferSubData(intersection with mapped "
4215 if (ctx
->Driver
.InvalidateBufferSubData
)
4216 ctx
->Driver
.InvalidateBufferSubData(ctx
, bufObj
, offset
, length
);
4220 _mesa_InvalidateBufferData(GLuint buffer
)
4222 GET_CURRENT_CONTEXT(ctx
);
4223 struct gl_buffer_object
*bufObj
;
4225 /* Section 6.5 (Invalidating Buffer Data) of the OpenGL 4.5 (Compatibility
4226 * Profile) spec says:
4228 * "An INVALID_VALUE error is generated if buffer is zero or is not the
4229 * name of an existing buffer object."
4231 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4232 if (!bufObj
|| bufObj
== &DummyBufferObject
) {
4233 _mesa_error(ctx
, GL_INVALID_VALUE
,
4234 "glInvalidateBufferData(name = %u) invalid object",
4239 /* The OpenGL 4.4 (Core Profile) spec says:
4241 * "An INVALID_OPERATION error is generated if buffer is currently
4242 * mapped by MapBuffer or if the invalidate range intersects the range
4243 * currently mapped by MapBufferRange, unless it was mapped
4244 * with MAP_PERSISTENT_BIT set in the MapBufferRange access flags."
4246 if (_mesa_check_disallowed_mapping(bufObj
)) {
4247 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4248 "glInvalidateBufferData(intersection with mapped "
4253 if (ctx
->Driver
.InvalidateBufferSubData
)
4254 ctx
->Driver
.InvalidateBufferSubData(ctx
, bufObj
, 0, bufObj
->Size
);
4258 buffer_page_commitment(struct gl_context
*ctx
,
4259 struct gl_buffer_object
*bufferObj
,
4260 GLintptr offset
, GLsizeiptr size
,
4261 GLboolean commit
, const char *func
)
4263 if (!(bufferObj
->StorageFlags
& GL_SPARSE_STORAGE_BIT_ARB
)) {
4264 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(not a sparse buffer object)",
4269 if (size
< 0 || size
> bufferObj
->Size
||
4270 offset
< 0 || offset
> bufferObj
->Size
- size
) {
4271 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(out of bounds)",
4276 /* The GL_ARB_sparse_buffer extension specification says:
4278 * "INVALID_VALUE is generated by BufferPageCommitmentARB if <offset> is
4279 * not an integer multiple of SPARSE_BUFFER_PAGE_SIZE_ARB, or if <size>
4280 * is not an integer multiple of SPARSE_BUFFER_PAGE_SIZE_ARB and does
4281 * not extend to the end of the buffer's data store."
4283 if (offset
% ctx
->Const
.SparseBufferPageSize
!= 0) {
4284 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset not aligned to page size)",
4289 if (size
% ctx
->Const
.SparseBufferPageSize
!= 0 &&
4290 offset
+ size
!= bufferObj
->Size
) {
4291 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size not aligned to page size)",
4296 ctx
->Driver
.BufferPageCommitment(ctx
, bufferObj
, offset
, size
, commit
);
4300 _mesa_BufferPageCommitmentARB(GLenum target
, GLintptr offset
, GLsizeiptr size
,
4303 GET_CURRENT_CONTEXT(ctx
);
4304 struct gl_buffer_object
*bufferObj
;
4306 bufferObj
= get_buffer(ctx
, "glBufferPageCommitmentARB", target
,
4311 buffer_page_commitment(ctx
, bufferObj
, offset
, size
, commit
,
4312 "glBufferPageCommitmentARB");
4316 _mesa_NamedBufferPageCommitmentARB(GLuint buffer
, GLintptr offset
,
4317 GLsizeiptr size
, GLboolean commit
)
4319 GET_CURRENT_CONTEXT(ctx
);
4320 struct gl_buffer_object
*bufferObj
;
4322 bufferObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4323 if (!bufferObj
|| bufferObj
== &DummyBufferObject
) {
4324 /* Note: the extension spec is not clear about the excpected error value. */
4325 _mesa_error(ctx
, GL_INVALID_VALUE
,
4326 "glNamedBufferPageCommitmentARB(name = %u) invalid object",
4331 buffer_page_commitment(ctx
, bufferObj
, offset
, size
, commit
,
4332 "glNamedBufferPageCommitmentARB");