#include "glformats.h"
#include "texstore.h"
#include "transformfeedback.h"
+#include "varray.h"
/* Debug flags */
* Called by glBindBuffer() and other functions.
*/
static void
-bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer)
+bind_buffer_object(struct gl_context *ctx,
+ struct gl_buffer_object **bindTarget, GLuint buffer)
{
struct gl_buffer_object *oldBufObj;
struct gl_buffer_object *newBufObj = NULL;
- struct gl_buffer_object **bindTarget = NULL;
- bindTarget = get_buffer_target(ctx, target);
- if (!bindTarget) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target 0x%x)", target);
- return;
- }
+ assert(bindTarget);
/* Get pointer to old buffer object (to be unbound) */
oldBufObj = *bindTarget;
}
/* record usage history */
- switch (target) {
- case GL_PIXEL_PACK_BUFFER:
+ if (bindTarget == &ctx->Pack.BufferObj) {
newBufObj->UsageHistory |= USAGE_PIXEL_PACK_BUFFER;
- break;
- default:
- break;
}
/* bind new buffer */
/* Bind the NullBufferObj to remove references to those
* in the shared context hash table.
*/
- bind_buffer_object( ctx, GL_ARRAY_BUFFER_ARB, 0);
- bind_buffer_object( ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
- bind_buffer_object( ctx, GL_PIXEL_PACK_BUFFER_ARB, 0);
- bind_buffer_object( ctx, GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ bind_buffer_object(ctx, &ctx->Array.ArrayBufferObj, 0);
+ bind_buffer_object(ctx, &ctx->Array.VAO->IndexBufferObj, 0);
+ bind_buffer_object(ctx, &ctx->Pack.BufferObj, 0);
+ bind_buffer_object(ctx, &ctx->Unpack.BufferObj, 0);
}
struct gl_buffer_object *
_mesa_lookup_bufferobj_locked(struct gl_context *ctx, GLuint buffer)
{
- return (struct gl_buffer_object *)
- _mesa_HashLookupLocked(ctx->Shared->BufferObjects, buffer);
+ if (buffer == 0)
+ return NULL;
+ else
+ return (struct gl_buffer_object *)
+ _mesa_HashLookupLocked(ctx->Shared->BufferObjects, buffer);
}
/**
}
-void
-_mesa_begin_bufferobj_lookups(struct gl_context *ctx)
-{
- _mesa_HashLockMutex(ctx->Shared->BufferObjects);
-}
-
-
-void
-_mesa_end_bufferobj_lookups(struct gl_context *ctx)
-{
- _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
-}
-
-
/**
* Look up a buffer object for a multi-bind function.
*
* returns NULL.
*
* This function assumes that the caller has already locked the
- * hash table mutex by calling _mesa_begin_bufferobj_lookups().
+ * hash table mutex by calling
+ * _mesa_HashLockMutex(ctx->Shared->BufferObjects).
*/
struct gl_buffer_object *
_mesa_multi_bind_lookup_bufferobj(struct gl_context *ctx,
*/
static void
unbind(struct gl_context *ctx,
- struct gl_buffer_object **ptr,
+ struct gl_vertex_array_object *vao, unsigned index,
struct gl_buffer_object *obj)
{
- if (*ptr == obj) {
- _mesa_reference_buffer_object(ctx, ptr, ctx->Shared->NullBufferObj);
+ if (vao->BufferBinding[index].BufferObj == obj) {
+ _mesa_bind_vertex_buffer(ctx, vao, index, ctx->Shared->NullBufferObj,
+ vao->BufferBinding[index].Offset,
+ vao->BufferBinding[index].Stride);
}
}
_mesa_enum_to_string(target), buffer);
}
- bind_buffer_object(ctx, target, buffer);
+ struct gl_buffer_object **bindTarget = get_buffer_target(ctx, target);
+ if (!bindTarget) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target %s)",
+ _mesa_enum_to_string(target));
+ return;
+ }
+
+ bind_buffer_object(ctx, bindTarget, buffer);
}
return;
}
- mtx_lock(&ctx->Shared->Mutex);
+ _mesa_HashLockMutex(ctx->Shared->BufferObjects);
for (i = 0; i < n; i++) {
- struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, ids[i]);
+ struct gl_buffer_object *bufObj =
+ _mesa_lookup_bufferobj_locked(ctx, ids[i]);
if (bufObj) {
struct gl_vertex_array_object *vao = ctx->Array.VAO;
GLuint j;
_mesa_buffer_unmap_all_mappings(ctx, bufObj);
/* unbind any vertex pointers bound to this buffer */
- for (j = 0; j < ARRAY_SIZE(vao->VertexBinding); j++) {
- unbind(ctx, &vao->VertexBinding[j].BufferObj, bufObj);
+ for (j = 0; j < ARRAY_SIZE(vao->BufferBinding); j++) {
+ unbind(ctx, vao, j, bufObj);
}
if (ctx->Array.ArrayBufferObj == bufObj) {
- _mesa_BindBuffer( GL_ARRAY_BUFFER_ARB, 0 );
+ bind_buffer_object(ctx, &ctx->Array.ArrayBufferObj, 0);
}
if (vao->IndexBufferObj == bufObj) {
- _mesa_BindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );
+ bind_buffer_object(ctx, &vao->IndexBufferObj, 0);
}
/* unbind ARB_draw_indirect binding point */
if (ctx->DrawIndirectBuffer == bufObj) {
- _mesa_BindBuffer( GL_DRAW_INDIRECT_BUFFER, 0 );
+ bind_buffer_object(ctx, &ctx->DrawIndirectBuffer, 0);
}
/* unbind ARB_indirect_parameters binding point */
if (ctx->ParameterBuffer == bufObj) {
- _mesa_BindBuffer(GL_PARAMETER_BUFFER_ARB, 0);
+ bind_buffer_object(ctx, &ctx->ParameterBuffer, 0);
}
/* unbind ARB_compute_shader binding point */
if (ctx->DispatchIndirectBuffer == bufObj) {
- _mesa_BindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0);
+ bind_buffer_object(ctx, &ctx->DispatchIndirectBuffer, 0);
}
/* unbind ARB_copy_buffer binding points */
if (ctx->CopyReadBuffer == bufObj) {
- _mesa_BindBuffer( GL_COPY_READ_BUFFER, 0 );
+ bind_buffer_object(ctx, &ctx->CopyReadBuffer, 0);
}
if (ctx->CopyWriteBuffer == bufObj) {
- _mesa_BindBuffer( GL_COPY_WRITE_BUFFER, 0 );
+ bind_buffer_object(ctx, &ctx->CopyWriteBuffer, 0);
}
/* unbind transform feedback binding points */
if (ctx->TransformFeedback.CurrentBuffer == bufObj) {
- _mesa_BindBuffer( GL_TRANSFORM_FEEDBACK_BUFFER, 0 );
+ bind_buffer_object(ctx, &ctx->TransformFeedback.CurrentBuffer, 0);
}
for (j = 0; j < MAX_FEEDBACK_BUFFERS; j++) {
if (ctx->TransformFeedback.CurrentObject->Buffers[j] == bufObj) {
}
if (ctx->UniformBuffer == bufObj) {
- _mesa_BindBuffer( GL_UNIFORM_BUFFER, 0 );
+ bind_buffer_object(ctx, &ctx->UniformBuffer, 0);
}
/* unbind SSBO binding points */
}
if (ctx->ShaderStorageBuffer == bufObj) {
- _mesa_BindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
+ bind_buffer_object(ctx, &ctx->ShaderStorageBuffer, 0);
}
/* unbind Atomci Buffer binding points */
}
if (ctx->AtomicBuffer == bufObj) {
- _mesa_BindBuffer( GL_ATOMIC_COUNTER_BUFFER, 0 );
+ bind_buffer_object(ctx, &ctx->AtomicBuffer, 0);
}
/* unbind any pixel pack/unpack pointers bound to this buffer */
if (ctx->Pack.BufferObj == bufObj) {
- _mesa_BindBuffer( GL_PIXEL_PACK_BUFFER_EXT, 0 );
+ bind_buffer_object(ctx, &ctx->Pack.BufferObj, 0);
}
if (ctx->Unpack.BufferObj == bufObj) {
- _mesa_BindBuffer( GL_PIXEL_UNPACK_BUFFER_EXT, 0 );
+ bind_buffer_object(ctx, &ctx->Unpack.BufferObj, 0);
}
if (ctx->Texture.BufferObject == bufObj) {
- _mesa_BindBuffer( GL_TEXTURE_BUFFER, 0 );
+ bind_buffer_object(ctx, &ctx->Texture.BufferObject, 0);
}
if (ctx->ExternalVirtualMemoryBuffer == bufObj) {
- _mesa_BindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);
+ bind_buffer_object(ctx, &ctx->ExternalVirtualMemoryBuffer, 0);
}
/* unbind query buffer binding point */
if (ctx->QueryBuffer == bufObj) {
- _mesa_BindBuffer(GL_QUERY_BUFFER, 0);
+ bind_buffer_object(ctx, &ctx->QueryBuffer, 0);
}
/* The ID is immediately freed for re-use */
- _mesa_HashRemove(ctx->Shared->BufferObjects, ids[i]);
+ _mesa_HashRemoveLocked(ctx->Shared->BufferObjects, ids[i]);
/* Make sure we do not run into the classic ABA problem on bind.
* We don't want to allow re-binding a buffer object that's been
* "deleted" by glDeleteBuffers().
}
}
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
/*
* This must be atomic (generation and allocation of buffer object IDs)
*/
- mtx_lock(&ctx->Shared->Mutex);
+ _mesa_HashLockMutex(ctx->Shared->BufferObjects);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n);
buf = ctx->Driver.NewBufferObject(ctx, buffers[i]);
if (!buf) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
return;
}
}
else
buf = &DummyBufferObject;
- _mesa_HashInsert(ctx->Shared->BufferObjects, buffers[i], buf);
+ _mesa_HashInsertLocked(ctx->Shared->BufferObjects, buffers[i], buf);
}
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
/**
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
- mtx_lock(&ctx->Shared->Mutex);
bufObj = _mesa_lookup_bufferobj(ctx, id);
- mtx_unlock(&ctx->Shared->Mutex);
return bufObj && bufObj != &DummyBufferObject;
}
return;
}
- if (flags & ~(GL_MAP_READ_BIT |
- GL_MAP_WRITE_BIT |
- GL_MAP_PERSISTENT_BIT |
- GL_MAP_COHERENT_BIT |
- GL_DYNAMIC_STORAGE_BIT |
- GL_CLIENT_STORAGE_BIT)) {
+ GLbitfield valid_flags = GL_MAP_READ_BIT |
+ GL_MAP_WRITE_BIT |
+ GL_MAP_PERSISTENT_BIT |
+ GL_MAP_COHERENT_BIT |
+ GL_DYNAMIC_STORAGE_BIT |
+ GL_CLIENT_STORAGE_BIT;
+
+ if (ctx->Extensions.ARB_sparse_buffer)
+ valid_flags |= GL_SPARSE_STORAGE_BIT_ARB;
+
+ if (flags & ~valid_flags) {
_mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid flag bits set)", func);
return;
}
+ /* The Errors section of the GL_ARB_sparse_buffer spec says:
+ *
+ * "INVALID_VALUE is generated by BufferStorage if <flags> contains
+ * SPARSE_STORAGE_BIT_ARB and <flags> also contains any combination of
+ * MAP_READ_BIT or MAP_WRITE_BIT."
+ */
+ if (flags & GL_SPARSE_STORAGE_BIT_ARB &&
+ flags & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(SPARSE_STORAGE and READ/WRITE)", func);
+ return;
+ }
+
if (flags & GL_MAP_PERSISTENT_BIT &&
!(flags & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT))) {
_mesa_error(ctx, GL_INVALID_VALUE,
const char *func)
{
if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,
- false, func)) {
+ true, func)) {
/* error already recorded */
return;
}
const GLsizeiptr *sizes)
{
if (offsets[index] < 0) {
- /* The ARB_multi_bind spec says:
- *
- * "An INVALID_VALUE error is generated by BindBuffersRange if any
- * value in <offsets> is less than zero (per binding)."
- */
+ /* The ARB_multi_bind spec says:
+ *
+ * "An INVALID_VALUE error is generated by BindBuffersRange if any
+ * value in <offsets> is less than zero (per binding)."
+ */
_mesa_error(ctx, GL_INVALID_VALUE,
"glBindBuffersRange(offsets[%u]=%" PRId64 " < 0)",
index, (int64_t) offsets[index]);
}
if (sizes[index] <= 0) {
- /* The ARB_multi_bind spec says:
- *
- * "An INVALID_VALUE error is generated by BindBuffersRange if any
- * value in <sizes> is less than or equal to zero (per binding)."
- */
+ /* The ARB_multi_bind spec says:
+ *
+ * "An INVALID_VALUE error is generated by BindBuffersRange if any
+ * value in <sizes> is less than or equal to zero (per binding)."
+ */
_mesa_error(ctx, GL_INVALID_VALUE,
"glBindBuffersRange(sizes[%u]=%" PRId64 " <= 0)",
index, (int64_t) sizes[index]);
* parameters are valid and no other error occurs."
*/
- _mesa_begin_bufferobj_lookups(ctx);
+ _mesa_HashLockMutex(ctx->Shared->BufferObjects);
for (i = 0; i < count; i++) {
struct gl_uniform_buffer_binding *binding =
}
}
- _mesa_end_bufferobj_lookups(ctx);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
static void
* parameters are valid and no other error occurs."
*/
- _mesa_begin_bufferobj_lookups(ctx);
+ _mesa_HashLockMutex(ctx->Shared->BufferObjects);
for (i = 0; i < count; i++) {
struct gl_shader_storage_buffer_binding *binding =
}
}
- _mesa_end_bufferobj_lookups(ctx);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
static bool
* parameters are valid and no other error occurs."
*/
- _mesa_begin_bufferobj_lookups(ctx);
+ _mesa_HashLockMutex(ctx->Shared->BufferObjects);
for (i = 0; i < count; i++) {
const GLuint index = first + i;
offset, size);
}
- _mesa_end_bufferobj_lookups(ctx);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
static bool
* parameters are valid and no other error occurs."
*/
- _mesa_begin_bufferobj_lookups(ctx);
+ _mesa_HashLockMutex(ctx->Shared->BufferObjects);
for (i = 0; i < count; i++) {
struct gl_atomic_buffer_binding *binding =
set_atomic_buffer_binding(ctx, binding, bufObj, offset, size);
}
- _mesa_end_bufferobj_lookups(ctx);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
void GLAPIENTRY
bufObj = _mesa_lookup_bufferobj(ctx, buffer);
if (!bufObj || bufObj == &DummyBufferObject) {
_mesa_error(ctx, GL_INVALID_VALUE,
- "glInvalidateBufferSubData(name = 0x%x) invalid object",
+ "glInvalidateBufferSubData(name = %u) invalid object",
buffer);
return;
}
bufObj = _mesa_lookup_bufferobj(ctx, buffer);
if (!bufObj || bufObj == &DummyBufferObject) {
_mesa_error(ctx, GL_INVALID_VALUE,
- "glInvalidateBufferData(name = 0x%x) invalid object",
+ "glInvalidateBufferData(name = %u) invalid object",
buffer);
return;
}
if (ctx->Driver.InvalidateBufferSubData)
ctx->Driver.InvalidateBufferSubData(ctx, bufObj, 0, bufObj->Size);
}
+
+static void
+buffer_page_commitment(struct gl_context *ctx,
+ struct gl_buffer_object *bufferObj,
+ GLintptr offset, GLsizeiptr size,
+ GLboolean commit, const char *func)
+{
+ if (!(bufferObj->StorageFlags & GL_SPARSE_STORAGE_BIT_ARB)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(not a sparse buffer object)",
+ func);
+ return;
+ }
+
+ if (size < 0 || size > bufferObj->Size ||
+ offset < 0 || offset > bufferObj->Size - size) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(out of bounds)",
+ func);
+ return;
+ }
+
+ /* The GL_ARB_sparse_buffer extension specification says:
+ *
+ * "INVALID_VALUE is generated by BufferPageCommitmentARB if <offset> is
+ * not an integer multiple of SPARSE_BUFFER_PAGE_SIZE_ARB, or if <size>
+ * is not an integer multiple of SPARSE_BUFFER_PAGE_SIZE_ARB and does
+ * not extend to the end of the buffer's data store."
+ */
+ if (offset % ctx->Const.SparseBufferPageSize != 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset not aligned to page size)",
+ func);
+ return;
+ }
+
+ if (size % ctx->Const.SparseBufferPageSize != 0 &&
+ offset + size != bufferObj->Size) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(size not aligned to page size)",
+ func);
+ return;
+ }
+
+ ctx->Driver.BufferPageCommitment(ctx, bufferObj, offset, size, commit);
+}
+
+void GLAPIENTRY
+_mesa_BufferPageCommitmentARB(GLenum target, GLintptr offset, GLsizeiptr size,
+ GLboolean commit)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufferObj;
+
+ bufferObj = get_buffer(ctx, "glBufferPageCommitmentARB", target,
+ GL_INVALID_ENUM);
+ if (!bufferObj)
+ return;
+
+ buffer_page_commitment(ctx, bufferObj, offset, size, commit,
+ "glBufferPageCommitmentARB");
+}
+
+void GLAPIENTRY
+_mesa_NamedBufferPageCommitmentARB(GLuint buffer, GLintptr offset,
+ GLsizeiptr size, GLboolean commit)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufferObj;
+
+ bufferObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!bufferObj || bufferObj == &DummyBufferObject) {
+ /* Note: the extension spec is not clear about the excpected error value. */
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glNamedBufferPageCommitmentARB(name = %u) invalid object",
+ buffer);
+ return;
+ }
+
+ buffer_page_commitment(ctx, bufferObj, offset, size, commit,
+ "glNamedBufferPageCommitmentARB");
+}