#include "glheader.h"
#include "enums.h"
#include "hash.h"
-#include "imports.h"
+#include "util/imports.h"
#include "context.h"
#include "bufferobj.h"
+#include "externalobjects.h"
#include "mtypes.h"
#include "teximage.h"
#include "glformats.h"
#include "texstore.h"
#include "transformfeedback.h"
#include "varray.h"
+#include "util/u_atomic.h"
/* Debug flags */
va_list args;
va_start(args, fmt);
- _mesa_gl_vdebug(ctx, id,
- MESA_DEBUG_SOURCE_API,
- MESA_DEBUG_TYPE_PERFORMANCE,
- MESA_DEBUG_SEVERITY_MEDIUM,
- fmt, args);
+ _mesa_gl_vdebugf(ctx, id,
+ MESA_DEBUG_SOURCE_API,
+ MESA_DEBUG_TYPE_PERFORMANCE,
+ MESA_DEBUG_SEVERITY_MEDIUM,
+ fmt, args);
va_end(args);
}
static inline struct gl_buffer_object **
get_buffer_target(struct gl_context *ctx, GLenum target)
{
- /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0.
- */
- if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)
- && target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER)
- return NULL;
+ /* Other targets are only supported in desktop OpenGL and OpenGL ES 3.0. */
+ if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) {
+ switch (target) {
+ case GL_ARRAY_BUFFER:
+ case GL_ELEMENT_ARRAY_BUFFER:
+ break;
+ case GL_PIXEL_PACK_BUFFER:
+ case GL_PIXEL_UNPACK_BUFFER:
+ if (!ctx->Extensions.EXT_pixel_buffer_object)
+ return NULL;
+ break;
+ default:
+ return NULL;
+ }
+ }
switch (target) {
case GL_ARRAY_BUFFER_ARB:
+ if (ctx->Array.ArrayBufferObj)
+ ctx->Array.ArrayBufferObj->UsageHistory |= USAGE_ARRAY_BUFFER;
return &ctx->Array.ArrayBufferObj;
case GL_ELEMENT_ARRAY_BUFFER_ARB:
+ if (ctx->Array.VAO->IndexBufferObj)
+ ctx->Array.VAO->IndexBufferObj->UsageHistory
+ |= USAGE_ELEMENT_ARRAY_BUFFER;
return &ctx->Array.VAO->IndexBufferObj;
case GL_PIXEL_PACK_BUFFER_EXT:
return &ctx->Pack.BufferObj;
return &ctx->QueryBuffer;
break;
case GL_DRAW_INDIRECT_BUFFER:
- if ((ctx->API == API_OPENGL_CORE &&
- ctx->Extensions.ARB_draw_indirect) ||
+ if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_draw_indirect) ||
_mesa_is_gles31(ctx)) {
return &ctx->DrawIndirectBuffer;
}
return NULL;
}
- if (!_mesa_is_bufferobj(*bufObj)) {
+ if (!*bufObj) {
_mesa_error(ctx, error, "%s(no buffer bound)", func);
return NULL;
}
/**
* Test the format and type parameters and set the GL error code for
- * \c glClearBufferData and \c glClearBufferSubData.
+ * \c glClearBufferData, \c glClearNamedBufferData, \c glClearBufferSubData
+ * and \c glClearNamedBufferSubData.
*
* \param ctx GL context.
* \param internalformat Format to which the data is to be converted.
* \return If internalformat, format and type are legal the mesa_format
* corresponding to internalformat, otherwise MESA_FORMAT_NONE.
*
- * \sa glClearBufferData and glClearBufferSubData
+ * \sa glClearBufferData, glClearNamedBufferData, glClearBufferSubData and
+ * glClearNamedBufferSubData.
*/
static mesa_format
validate_clear_buffer_format(struct gl_context *ctx,
}
if (!_mesa_is_color_format(format)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
+ _mesa_error(ctx, GL_INVALID_VALUE,
"%s(format is not a color format)", caller);
return MESA_FORMAT_NONE;
}
errorFormatType = _mesa_error_check_format_and_type(ctx, format, type);
if (errorFormatType != GL_NO_ERROR) {
- _mesa_error(ctx, GL_INVALID_ENUM,
+ _mesa_error(ctx, GL_INVALID_VALUE,
"%s(invalid format or type)", caller);
return MESA_FORMAT_NONE;
}
static struct gl_buffer_object *
_mesa_new_buffer_object(struct gl_context *ctx, GLuint name)
{
- struct gl_buffer_object *obj;
-
- (void) ctx;
+ struct gl_buffer_object *obj = MALLOC_STRUCT(gl_buffer_object);
+ if (!obj)
+ return NULL;
- obj = MALLOC_STRUCT(gl_buffer_object);
_mesa_initialize_buffer_object(ctx, obj, name);
return obj;
}
bufObj->RefCount = -1000;
bufObj->Name = ~0;
- mtx_destroy(&bufObj->Mutex);
+ simple_mtx_destroy(&bufObj->MinMaxCacheMutex);
free(bufObj->Label);
free(bufObj);
}
{
if (*ptr) {
/* Unreference the old buffer */
- GLboolean deleteFlag = GL_FALSE;
struct gl_buffer_object *oldObj = *ptr;
- mtx_lock(&oldObj->Mutex);
- assert(oldObj->RefCount > 0);
- oldObj->RefCount--;
- deleteFlag = (oldObj->RefCount == 0);
- mtx_unlock(&oldObj->Mutex);
-
- if (deleteFlag) {
+ if (p_atomic_dec_zero(&oldObj->RefCount)) {
assert(ctx->Driver.DeleteBuffer);
ctx->Driver.DeleteBuffer(ctx, oldObj);
}
if (bufObj) {
/* reference new buffer */
- mtx_lock(&bufObj->Mutex);
- assert(bufObj->RefCount > 0);
-
- bufObj->RefCount++;
+ p_atomic_inc(&bufObj->RefCount);
*ptr = bufObj;
- mtx_unlock(&bufObj->Mutex);
}
}
GLuint name)
{
memset(obj, 0, sizeof(struct gl_buffer_object));
- mtx_init(&obj->Mutex, mtx_plain);
obj->RefCount = 1;
obj->Name = name;
obj->Usage = GL_STATIC_DRAW_ARB;
+ simple_mtx_init(&obj->MinMaxCacheMutex, mtx_plain);
if (get_no_minmax_cache())
obj->UsageHistory |= USAGE_DISABLE_MINMAX_CACHE;
}
* \sa glBufferDataARB, dd_function_table::BufferData.
*/
static GLboolean
-buffer_data_fallback(struct gl_context *ctx, GLenum target, GLsizeiptr size,
+buffer_data_fallback(struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
const GLvoid *data, GLenum usage, GLenum storageFlags,
struct gl_buffer_object *bufObj)
{
* \sa glBufferSubDataARB, dd_function_table::BufferSubData.
*/
static void
-buffer_sub_data_fallback(struct gl_context *ctx, GLintptr offset,
- GLsizeiptr size, const GLvoid *data,
+buffer_sub_data_fallback(struct gl_context *ctx, GLintptrARB offset,
+ GLsizeiptrARB size, const GLvoid *data,
struct gl_buffer_object *bufObj)
{
(void) ctx;
GLuint i;
memset(&DummyBufferObject, 0, sizeof(DummyBufferObject));
- mtx_init(&DummyBufferObject.Mutex, mtx_plain);
+ simple_mtx_init(&DummyBufferObject.MinMaxCacheMutex, mtx_plain);
DummyBufferObject.RefCount = 1000*1000*1000; /* never delete */
- _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj,
- ctx->Shared->NullBufferObj);
-
- _mesa_reference_buffer_object(ctx, &ctx->CopyReadBuffer,
- ctx->Shared->NullBufferObj);
- _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer,
- ctx->Shared->NullBufferObj);
-
- _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer,
- ctx->Shared->NullBufferObj);
-
- _mesa_reference_buffer_object(ctx, &ctx->ShaderStorageBuffer,
- ctx->Shared->NullBufferObj);
-
- _mesa_reference_buffer_object(ctx, &ctx->AtomicBuffer,
- ctx->Shared->NullBufferObj);
-
- _mesa_reference_buffer_object(ctx, &ctx->DrawIndirectBuffer,
- ctx->Shared->NullBufferObj);
-
- _mesa_reference_buffer_object(ctx, &ctx->ParameterBuffer,
- ctx->Shared->NullBufferObj);
-
- _mesa_reference_buffer_object(ctx, &ctx->DispatchIndirectBuffer,
- ctx->Shared->NullBufferObj);
-
- _mesa_reference_buffer_object(ctx, &ctx->QueryBuffer,
- ctx->Shared->NullBufferObj);
-
for (i = 0; i < MAX_COMBINED_UNIFORM_BUFFERS; i++) {
_mesa_reference_buffer_object(ctx,
&ctx->UniformBufferBindings[i].BufferObject,
- ctx->Shared->NullBufferObj);
+ NULL);
ctx->UniformBufferBindings[i].Offset = -1;
ctx->UniformBufferBindings[i].Size = -1;
}
for (i = 0; i < MAX_COMBINED_SHADER_STORAGE_BUFFERS; i++) {
_mesa_reference_buffer_object(ctx,
&ctx->ShaderStorageBufferBindings[i].BufferObject,
- ctx->Shared->NullBufferObj);
+ NULL);
ctx->ShaderStorageBufferBindings[i].Offset = -1;
ctx->ShaderStorageBufferBindings[i].Size = -1;
}
for (i = 0; i < MAX_COMBINED_ATOMIC_BUFFERS; i++) {
_mesa_reference_buffer_object(ctx,
&ctx->AtomicBufferBindings[i].BufferObject,
- ctx->Shared->NullBufferObj);
+ NULL);
ctx->AtomicBufferBindings[i].Offset = 0;
ctx->AtomicBufferBindings[i].Size = 0;
}
/* If this is a new buffer object id, or one which was generated but
* never used before, allocate a buffer object now.
*/
- assert(ctx->Driver.NewBufferObject);
buf = ctx->Driver.NewBufferObject(ctx, buffer);
if (!buf) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
/* Get pointer to old buffer object (to be unbound) */
oldBufObj = *bindTarget;
- if (oldBufObj && oldBufObj->Name == buffer && !oldBufObj->DeletePending)
+ if ((oldBufObj && oldBufObj->Name == buffer && !oldBufObj->DeletePending) ||
+ (!oldBufObj && buffer == 0))
return; /* rebinding the same buffer object- no change */
/*
* Get pointer to new buffer object (newBufObj)
*/
- if (buffer == 0) {
- /* The spec says there's not a buffer object named 0, but we use
- * one internally because it simplifies things.
- */
- newBufObj = ctx->Shared->NullBufferObj;
- }
- else {
+ if (buffer != 0) {
/* non-default buffer object */
newBufObj = _mesa_lookup_bufferobj(ctx, buffer);
if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
&newBufObj, "glBindBuffer"))
return;
- }
- /* record usage history */
- if (bindTarget == &ctx->Pack.BufferObj) {
- newBufObj->UsageHistory |= USAGE_PIXEL_PACK_BUFFER;
+ /* record usage history */
+ if (bindTarget == &ctx->Pack.BufferObj)
+ newBufObj->UsageHistory |= USAGE_PIXEL_PACK_BUFFER;
}
/* bind new buffer */
void
_mesa_update_default_objects_buffer_objects(struct gl_context *ctx)
{
- /* Bind the NullBufferObj to remove references to those
- * in the shared context hash table.
- */
+ /* Bind 0 to remove references to those in the shared context hash table. */
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);
* of an existing buffer object.
*
* If the buffer ID refers to an existing buffer object, a pointer
- * to the buffer object is returned. If the ID is zero, a pointer
- * to the shared NullBufferObj is returned. If the ID is not zero
- * and does not refer to a valid buffer object, this function
- * returns NULL.
+ * to the buffer object is returned. If the ID is zero, NULL is returned.
+ * If the ID is not zero and does not refer to a valid buffer object, this
+ * function returns NULL.
*
* This function assumes that the caller has already locked the
* hash table mutex by calling
struct gl_buffer_object *
_mesa_multi_bind_lookup_bufferobj(struct gl_context *ctx,
const GLuint *buffers,
- GLuint index, const char *caller)
+ GLuint index, const char *caller,
+ bool *error)
{
- struct gl_buffer_object *bufObj;
+ struct gl_buffer_object *bufObj = NULL;
+
+ *error = false;
if (buffers[index] != 0) {
bufObj = _mesa_lookup_bufferobj_locked(ctx, buffers[index]);
when they don't exist. */
if (bufObj == &DummyBufferObject)
bufObj = NULL;
- } else
- bufObj = ctx->Shared->NullBufferObj;
- if (!bufObj) {
- /* The ARB_multi_bind spec says:
- *
- * "An INVALID_OPERATION error is generated if any value
- * in <buffers> is not zero or the name of an existing
- * buffer object (per binding)."
- */
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(buffers[%u]=%u is not zero or the name "
- "of an existing buffer object)",
- caller, index, buffers[index]);
+ if (!bufObj) {
+ /* The ARB_multi_bind spec says:
+ *
+ * "An INVALID_OPERATION error is generated if any value
+ * in <buffers> is not zero or the name of an existing
+ * buffer object (per binding)."
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(buffers[%u]=%u is not zero or the name "
+ "of an existing buffer object)",
+ caller, index, buffers[index]);
+ *error = true;
+ }
}
return bufObj;
struct gl_buffer_object *obj)
{
if (vao->BufferBinding[index].BufferObj == obj) {
- _mesa_bind_vertex_buffer(ctx, vao, index, ctx->Shared->NullBufferObj,
+ _mesa_bind_vertex_buffer(ctx, vao, index, NULL,
vao->BufferBinding[index].Offset,
vao->BufferBinding[index].Stride);
}
_mesa_buffer_unmap_all_mappings(struct gl_context *ctx,
struct gl_buffer_object *bufObj)
{
- int i;
-
- for (i = 0; i < MAP_COUNT; i++) {
+ for (int i = 0; i < MAP_COUNT; i++) {
if (_mesa_bufferobj_mapped(bufObj, i)) {
ctx->Driver.UnmapBuffer(ctx, bufObj, i);
assert(bufObj->Mappings[i].Pointer == NULL);
/* API Functions */
/**********************************************************************/
+void GLAPIENTRY
+_mesa_BindBuffer_no_error(GLenum target, GLuint buffer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object **bindTarget = get_buffer_target(ctx, target);
+ bind_buffer_object(ctx, bindTarget, buffer);
+}
+
+
void GLAPIENTRY
_mesa_BindBuffer(GLenum target, GLuint buffer)
{
bind_buffer_object(ctx, bindTarget, buffer);
}
+/**
+ * Binds a buffer object to a binding point.
+ *
+ * The caller is responsible for validating the offset,
+ * flushing the vertices and updating NewDriverState.
+ */
+static void
+set_buffer_binding(struct gl_context *ctx,
+ struct gl_buffer_binding *binding,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset,
+ GLsizeiptr size,
+ bool autoSize, gl_buffer_usage usage)
+{
+ _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
+
+ binding->Offset = offset;
+ binding->Size = size;
+ binding->AutomaticSize = autoSize;
+
+ /* If this is a real buffer object, mark it has having been used
+ * at some point as an atomic counter buffer.
+ */
+ if (size >= 0)
+ bufObj->UsageHistory |= usage;
+}
+
+static void
+set_buffer_multi_binding(struct gl_context *ctx,
+ const GLuint *buffers,
+ int idx,
+ const char *caller,
+ struct gl_buffer_binding *binding,
+ GLintptr offset,
+ GLsizeiptr size,
+ bool range,
+ gl_buffer_usage usage)
+{
+ struct gl_buffer_object *bufObj;
+
+ if (binding->BufferObject && binding->BufferObject->Name == buffers[idx])
+ bufObj = binding->BufferObject;
+ else {
+ bool error;
+ bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, idx, caller,
+ &error);
+ if (error)
+ return;
+ }
+
+ if (!bufObj)
+ set_buffer_binding(ctx, binding, bufObj, -1, -1, !range, usage);
+ else
+ set_buffer_binding(ctx, binding, bufObj, offset, size, !range, usage);
+}
+
+static void
+bind_buffer(struct gl_context *ctx,
+ struct gl_buffer_binding *binding,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset,
+ GLsizeiptr size,
+ GLboolean autoSize,
+ uint64_t driver_state,
+ gl_buffer_usage usage)
+{
+ if (binding->BufferObject == bufObj &&
+ binding->Offset == offset &&
+ binding->Size == size &&
+ binding->AutomaticSize == autoSize) {
+ return;
+ }
+
+ FLUSH_VERTICES(ctx, 0);
+ ctx->NewDriverState |= driver_state;
+
+ set_buffer_binding(ctx, binding, bufObj, offset, size, autoSize, usage);
+}
+
+/**
+ * Binds a buffer object to a uniform buffer binding point.
+ *
+ * Unlike set_buffer_binding(), this function also flushes vertices
+ * and updates NewDriverState. It also checks if the binding
+ * has actually changed before updating it.
+ */
+static void
+bind_uniform_buffer(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset,
+ GLsizeiptr size,
+ GLboolean autoSize)
+{
+ bind_buffer(ctx, &ctx->UniformBufferBindings[index],
+ bufObj, offset, size, autoSize,
+ ctx->DriverFlags.NewUniformBuffer,
+ USAGE_UNIFORM_BUFFER);
+}
+
+/**
+ * Binds a buffer object to a shader storage buffer binding point.
+ *
+ * Unlike set_ssbo_binding(), this function also flushes vertices
+ * and updates NewDriverState. It also checks if the binding
+ * has actually changed before updating it.
+ */
+static void
+bind_shader_storage_buffer(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset,
+ GLsizeiptr size,
+ GLboolean autoSize)
+{
+ bind_buffer(ctx, &ctx->ShaderStorageBufferBindings[index],
+ bufObj, offset, size, autoSize,
+ ctx->DriverFlags.NewShaderStorageBuffer,
+ USAGE_SHADER_STORAGE_BUFFER);
+}
+
+/**
+ * Binds a buffer object to an atomic buffer binding point.
+ *
+ * Unlike set_atomic_binding(), this function also flushes vertices
+ * and updates NewDriverState. It also checks if the binding
+ * has actually changed before updating it.
+ */
+static void
+bind_atomic_buffer(struct gl_context *ctx, unsigned index,
+ struct gl_buffer_object *bufObj, GLintptr offset,
+ GLsizeiptr size, GLboolean autoSize)
+{
+ bind_buffer(ctx, &ctx->AtomicBufferBindings[index],
+ bufObj, offset, size, autoSize,
+ ctx->DriverFlags.NewAtomicBuffer,
+ USAGE_ATOMIC_COUNTER_BUFFER);
+}
+
+/**
+ * Bind a buffer object to a uniform block binding point.
+ * As above, but offset = 0.
+ */
+static void
+bind_buffer_base_uniform_buffer(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj)
+{
+ if (index >= ctx->Const.MaxUniformBufferBindings) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferBase(index=%d)", index);
+ return;
+ }
+
+ _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, bufObj);
+
+ if (!bufObj)
+ bind_uniform_buffer(ctx, index, bufObj, -1, -1, GL_TRUE);
+ else
+ bind_uniform_buffer(ctx, index, bufObj, 0, 0, GL_TRUE);
+}
+
+/**
+ * Bind a buffer object to a shader storage block binding point.
+ * As above, but offset = 0.
+ */
+static void
+bind_buffer_base_shader_storage_buffer(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj)
+{
+ if (index >= ctx->Const.MaxShaderStorageBufferBindings) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferBase(index=%d)", index);
+ return;
+ }
+
+ _mesa_reference_buffer_object(ctx, &ctx->ShaderStorageBuffer, bufObj);
+
+ if (!bufObj)
+ bind_shader_storage_buffer(ctx, index, bufObj, -1, -1, GL_TRUE);
+ else
+ bind_shader_storage_buffer(ctx, index, bufObj, 0, 0, GL_TRUE);
+}
+
+/**
+ * Bind a buffer object to a shader storage block binding point.
+ * As above, but offset = 0.
+ */
+static void
+bind_buffer_base_atomic_buffer(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj)
+{
+ if (index >= ctx->Const.MaxAtomicBufferBindings) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferBase(index=%d)", index);
+ return;
+ }
+
+ _mesa_reference_buffer_object(ctx, &ctx->AtomicBuffer, bufObj);
+
+ if (!bufObj)
+ bind_atomic_buffer(ctx, index, bufObj, -1, -1, GL_TRUE);
+ else
+ bind_atomic_buffer(ctx, index, bufObj, 0, 0, GL_TRUE);
+}
/**
* Delete a set of buffer objects.
* \param n Number of buffer objects to delete.
* \param ids Array of \c n buffer object IDs.
*/
-void GLAPIENTRY
-_mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
+static void
+delete_buffers(struct gl_context *ctx, GLsizei n, const GLuint *ids)
{
- GET_CURRENT_CONTEXT(ctx);
- GLsizei i;
FLUSH_VERTICES(ctx, 0);
- if (n < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteBuffersARB(n)");
- return;
- }
-
_mesa_HashLockMutex(ctx->Shared->BufferObjects);
- for (i = 0; i < n; i++) {
+ for (GLsizei i = 0; i < n; i++) {
struct gl_buffer_object *bufObj =
_mesa_lookup_bufferobj_locked(ctx, ids[i]);
if (bufObj) {
}
for (j = 0; j < MAX_FEEDBACK_BUFFERS; j++) {
if (ctx->TransformFeedback.CurrentObject->Buffers[j] == bufObj) {
- _mesa_BindBufferBase( GL_TRANSFORM_FEEDBACK_BUFFER, j, 0 );
+ _mesa_bind_buffer_base_transform_feedback(ctx,
+ ctx->TransformFeedback.CurrentObject,
+ j, NULL, false);
}
}
/* unbind UBO binding points */
for (j = 0; j < ctx->Const.MaxUniformBufferBindings; j++) {
if (ctx->UniformBufferBindings[j].BufferObject == bufObj) {
- _mesa_BindBufferBase( GL_UNIFORM_BUFFER, j, 0 );
+ bind_buffer_base_uniform_buffer(ctx, j, NULL);
}
}
/* unbind SSBO binding points */
for (j = 0; j < ctx->Const.MaxShaderStorageBufferBindings; j++) {
if (ctx->ShaderStorageBufferBindings[j].BufferObject == bufObj) {
- _mesa_BindBufferBase(GL_SHADER_STORAGE_BUFFER, j, 0);
+ bind_buffer_base_shader_storage_buffer(ctx, j, NULL);
}
}
/* unbind Atomci Buffer binding points */
for (j = 0; j < ctx->Const.MaxAtomicBufferBindings; j++) {
if (ctx->AtomicBufferBindings[j].BufferObject == bufObj) {
- _mesa_BindBufferBase( GL_ATOMIC_COUNTER_BUFFER, j, 0 );
+ bind_buffer_base_atomic_buffer(ctx, j, NULL);
}
}
}
+void GLAPIENTRY
+_mesa_DeleteBuffers_no_error(GLsizei n, const GLuint *ids)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ delete_buffers(ctx, n, ids);
+}
+
+
+void GLAPIENTRY
+_mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteBuffersARB(n)");
+ return;
+ }
+
+ delete_buffers(ctx, n, ids);
+}
+
+
/**
* This is the implementation for glGenBuffers and glCreateBuffers. It is not
* exposed to the rest of Mesa to encourage the use of nameless buffers in
* driver internals.
*/
static void
-create_buffers(GLsizei n, GLuint *buffers, bool dsa)
+create_buffers(struct gl_context *ctx, GLsizei n, GLuint *buffers, bool dsa)
{
- GET_CURRENT_CONTEXT(ctx);
GLuint first;
- GLint i;
struct gl_buffer_object *buf;
- const char *func = dsa ? "glCreateBuffers" : "glGenBuffers";
-
- if (MESA_VERBOSE & VERBOSE_API)
- _mesa_debug(ctx, "%s(%d)\n", func, n);
-
- if (n < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(n %d < 0)", func, n);
- return;
- }
-
- if (!buffers) {
+ if (!buffers)
return;
- }
/*
* This must be atomic (generation and allocation of buffer object IDs)
* DummyBufferObject. Otherwise, create a new buffer object and insert
* it.
*/
- for (i = 0; i < n; i++) {
+ for (int i = 0; i < n; i++) {
buffers[i] = first + i;
if (dsa) {
assert(ctx->Driver.NewBufferObject);
buf = ctx->Driver.NewBufferObject(ctx, buffers[i]);
if (!buf) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCreateBuffers");
_mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
return;
}
_mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
-/**
- * Generate a set of unique buffer object IDs and store them in \c buffers.
- *
- * \param n Number of IDs to generate.
- * \param buffers Array of \c n locations to store the IDs.
- */
-void GLAPIENTRY
-_mesa_GenBuffers(GLsizei n, GLuint *buffers)
-{
- create_buffers(n, buffers, false);
-}
-/**
+static void
+create_buffers_err(struct gl_context *ctx, GLsizei n, GLuint *buffers, bool dsa)
+{
+ const char *func = dsa ? "glCreateBuffers" : "glGenBuffers";
+
+ if (MESA_VERBOSE & VERBOSE_API)
+ _mesa_debug(ctx, "%s(%d)\n", func, n);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(n %d < 0)", func, n);
+ return;
+ }
+
+ create_buffers(ctx, n, buffers, dsa);
+}
+
+/**
+ * Generate a set of unique buffer object IDs and store them in \c buffers.
+ *
+ * \param n Number of IDs to generate.
+ * \param buffers Array of \c n locations to store the IDs.
+ */
+void GLAPIENTRY
+_mesa_GenBuffers_no_error(GLsizei n, GLuint *buffers)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ create_buffers(ctx, n, buffers, false);
+}
+
+
+void GLAPIENTRY
+_mesa_GenBuffers(GLsizei n, GLuint *buffers)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ create_buffers_err(ctx, n, buffers, false);
+}
+
+/**
* Create a set of buffer objects and store their unique IDs in \c buffers.
*
* \param n Number of IDs to generate.
* \param buffers Array of \c n locations to store the IDs.
*/
+void GLAPIENTRY
+_mesa_CreateBuffers_no_error(GLsizei n, GLuint *buffers)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ create_buffers(ctx, n, buffers, true);
+}
+
+
void GLAPIENTRY
_mesa_CreateBuffers(GLsizei n, GLuint *buffers)
{
- create_buffers(n, buffers, true);
+ GET_CURRENT_CONTEXT(ctx);
+ create_buffers_err(ctx, n, buffers, true);
}
}
-static void
-buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
- GLenum target, GLsizeiptr size, const GLvoid *data,
- GLbitfield flags, const char *func)
+static bool
+validate_buffer_storage(struct gl_context *ctx,
+ struct gl_buffer_object *bufObj, GLsizeiptr size,
+ GLbitfield flags, const char *func)
{
if (size <= 0) {
_mesa_error(ctx, GL_INVALID_VALUE, "%s(size <= 0)", func);
- return;
+ return false;
}
GLbitfield valid_flags = GL_MAP_READ_BIT |
if (flags & ~valid_flags) {
_mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid flag bits set)", func);
- return;
+ return false;
}
/* The Errors section of the GL_ARB_sparse_buffer spec says:
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;
+ return false;
}
if (flags & GL_MAP_PERSISTENT_BIT &&
!(flags & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT))) {
_mesa_error(ctx, GL_INVALID_VALUE,
"%s(PERSISTENT and flags!=READ/WRITE)", func);
- return;
+ return false;
}
if (flags & GL_MAP_COHERENT_BIT && !(flags & GL_MAP_PERSISTENT_BIT)) {
_mesa_error(ctx, GL_INVALID_VALUE,
"%s(COHERENT and flags!=PERSISTENT)", func);
- return;
+ return false;
}
- if (bufObj->Immutable) {
+ if (bufObj->Immutable || bufObj->HandleAllocated) {
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(immutable)", func);
- return;
+ return false;
}
+ return true;
+}
+
+
+static void
+buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+ struct gl_memory_object *memObj, GLenum target,
+ GLsizeiptr size, const GLvoid *data, GLbitfield flags,
+ GLuint64 offset, const char *func)
+{
+ GLboolean res;
+
/* Unmap the existing buffer. We'll replace it now. Not an error. */
_mesa_buffer_unmap_all_mappings(ctx, bufObj);
- FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
+ FLUSH_VERTICES(ctx, 0);
bufObj->Written = GL_TRUE;
bufObj->Immutable = GL_TRUE;
bufObj->MinMaxCacheDirty = true;
- assert(ctx->Driver.BufferData);
- if (!ctx->Driver.BufferData(ctx, target, size, data, GL_DYNAMIC_DRAW,
- flags, bufObj)) {
+ if (memObj) {
+ assert(ctx->Driver.BufferDataMem);
+ res = ctx->Driver.BufferDataMem(ctx, target, size, memObj, offset,
+ GL_DYNAMIC_DRAW, bufObj);
+ }
+ else {
+ assert(ctx->Driver.BufferData);
+ res = ctx->Driver.BufferData(ctx, target, size, data, GL_DYNAMIC_DRAW,
+ flags, bufObj);
+ }
+
+ if (!res) {
if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {
/* Even though the interaction between AMD_pinned_memory and
* glBufferStorage is not described in the spec, Graham Sellers
}
}
+
+static ALWAYS_INLINE void
+inlined_buffer_storage(GLenum target, GLuint buffer, GLsizeiptr size,
+ const GLvoid *data, GLbitfield flags,
+ GLuint memory, GLuint64 offset,
+ bool dsa, bool mem, bool no_error, const char *func)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ struct gl_memory_object *memObj = NULL;
+
+ if (mem) {
+ if (!no_error) {
+ if (!ctx->Extensions.EXT_memory_object) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
+ return;
+ }
+
+ /* From the EXT_external_objects spec:
+ *
+ * "An INVALID_VALUE error is generated by BufferStorageMemEXT and
+ * NamedBufferStorageMemEXT if <memory> is 0, or ..."
+ */
+ if (memory == 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(memory == 0)", func);
+ }
+ }
+
+ memObj = _mesa_lookup_memory_object(ctx, memory);
+ if (!memObj)
+ return;
+
+ /* From the EXT_external_objects spec:
+ *
+ * "An INVALID_OPERATION error is generated if <memory> names a
+ * valid memory object which has no associated memory."
+ */
+ if (!no_error && !memObj->Immutable) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no associated memory)",
+ func);
+ return;
+ }
+ }
+
+ if (dsa) {
+ if (no_error) {
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ } else {
+ bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, func);
+ if (!bufObj)
+ return;
+ }
+ } else {
+ if (no_error) {
+ struct gl_buffer_object **bufObjPtr = get_buffer_target(ctx, target);
+ bufObj = *bufObjPtr;
+ } else {
+ bufObj = get_buffer(ctx, func, target, GL_INVALID_OPERATION);
+ if (!bufObj)
+ return;
+ }
+ }
+
+ if (no_error || validate_buffer_storage(ctx, bufObj, size, flags, func))
+ buffer_storage(ctx, bufObj, memObj, target, size, data, flags, offset, func);
+}
+
+
+void GLAPIENTRY
+_mesa_BufferStorage_no_error(GLenum target, GLsizeiptr size,
+ const GLvoid *data, GLbitfield flags)
+{
+ inlined_buffer_storage(target, 0, size, data, flags, GL_NONE, 0,
+ false, false, true, "glBufferStorage");
+}
+
+
void GLAPIENTRY
_mesa_BufferStorage(GLenum target, GLsizeiptr size, const GLvoid *data,
GLbitfield flags)
+{
+ inlined_buffer_storage(target, 0, size, data, flags, GL_NONE, 0,
+ false, false, false, "glBufferStorage");
+}
+
+void GLAPIENTRY
+_mesa_NamedBufferStorageEXT(GLuint buffer, GLsizeiptr size,
+ const GLvoid *data, GLbitfield flags)
{
GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
- bufObj = get_buffer(ctx, "glBufferStorage", target, GL_INVALID_OPERATION);
- if (!bufObj)
+ struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glNamedBufferStorageEXT"))
return;
- buffer_storage(ctx, bufObj, target, size, data, flags, "glBufferStorage");
+ inlined_buffer_storage(GL_NONE, buffer, size, data, flags, GL_NONE, 0,
+ true, false, false, "glNamedBufferStorageEXT");
}
+
+void GLAPIENTRY
+_mesa_BufferStorageMemEXT(GLenum target, GLsizeiptr size,
+ GLuint memory, GLuint64 offset)
+{
+ inlined_buffer_storage(target, 0, size, NULL, 0, memory, offset,
+ false, true, false, "glBufferStorageMemEXT");
+}
+
+
+void GLAPIENTRY
+_mesa_BufferStorageMemEXT_no_error(GLenum target, GLsizeiptr size,
+ GLuint memory, GLuint64 offset)
+{
+ inlined_buffer_storage(target, 0, size, NULL, 0, memory, offset,
+ false, true, true, "glBufferStorageMemEXT");
+}
+
+
+void GLAPIENTRY
+_mesa_NamedBufferStorage_no_error(GLuint buffer, GLsizeiptr size,
+ const GLvoid *data, GLbitfield flags)
+{
+ /* In direct state access, buffer objects have an unspecified target
+ * since they are not required to be bound.
+ */
+ inlined_buffer_storage(GL_NONE, buffer, size, data, flags, GL_NONE, 0,
+ true, false, true, "glNamedBufferStorage");
+}
+
+
void GLAPIENTRY
_mesa_NamedBufferStorage(GLuint buffer, GLsizeiptr size, const GLvoid *data,
GLbitfield flags)
{
- GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
+ /* In direct state access, buffer objects have an unspecified target
+ * since they are not required to be bound.
+ */
+ inlined_buffer_storage(GL_NONE, buffer, size, data, flags, GL_NONE, 0,
+ true, false, false, "glNamedBufferStorage");
+}
- bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glNamedBufferStorage");
- if (!bufObj)
- return;
+void GLAPIENTRY
+_mesa_NamedBufferStorageMemEXT(GLuint buffer, GLsizeiptr size,
+ GLuint memory, GLuint64 offset)
+{
+ inlined_buffer_storage(GL_NONE, buffer, size, GL_NONE, 0, memory, offset,
+ true, true, false, "glNamedBufferStorageMemEXT");
+}
- /*
- * In direct state access, buffer objects have an unspecified target since
- * they are not required to be bound.
- */
- buffer_storage(ctx, bufObj, GL_NONE, size, data, flags,
- "glNamedBufferStorage");
+
+void GLAPIENTRY
+_mesa_NamedBufferStorageMemEXT_no_error(GLuint buffer, GLsizeiptr size,
+ GLuint memory, GLuint64 offset)
+{
+ inlined_buffer_storage(GL_NONE, buffer, size, GL_NONE, 0, memory, offset,
+ true, true, true, "glNamedBufferStorageMemEXT");
}
-void
-_mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
- GLenum target, GLsizeiptr size, const GLvoid *data,
- GLenum usage, const char *func)
+static ALWAYS_INLINE void
+buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+ GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage,
+ const char *func, bool no_error)
{
bool valid_usage;
_mesa_enum_to_string(usage));
}
- if (size < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(size < 0)", func);
- return;
- }
-
- switch (usage) {
- case GL_STREAM_DRAW_ARB:
- valid_usage = (ctx->API != API_OPENGLES);
- break;
-
- case GL_STATIC_DRAW_ARB:
- case GL_DYNAMIC_DRAW_ARB:
- valid_usage = true;
- break;
-
- case GL_STREAM_READ_ARB:
- case GL_STREAM_COPY_ARB:
- case GL_STATIC_READ_ARB:
- case GL_STATIC_COPY_ARB:
- case GL_DYNAMIC_READ_ARB:
- case GL_DYNAMIC_COPY_ARB:
- valid_usage = _mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx);
- break;
+ if (!no_error) {
+ if (size < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(size < 0)", func);
+ return;
+ }
- default:
- valid_usage = false;
- break;
- }
+ switch (usage) {
+ case GL_STREAM_DRAW_ARB:
+ valid_usage = (ctx->API != API_OPENGLES);
+ break;
+ case GL_STATIC_DRAW_ARB:
+ case GL_DYNAMIC_DRAW_ARB:
+ valid_usage = true;
+ break;
+ case GL_STREAM_READ_ARB:
+ case GL_STREAM_COPY_ARB:
+ case GL_STATIC_READ_ARB:
+ case GL_STATIC_COPY_ARB:
+ case GL_DYNAMIC_READ_ARB:
+ case GL_DYNAMIC_COPY_ARB:
+ valid_usage = _mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx);
+ break;
+ default:
+ valid_usage = false;
+ break;
+ }
- if (!valid_usage) {
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid usage: %s)", func,
- _mesa_enum_to_string(usage));
- return;
- }
+ if (!valid_usage) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid usage: %s)", func,
+ _mesa_enum_to_string(usage));
+ return;
+ }
- if (bufObj->Immutable) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s(immutable)", func);
- return;
+ if (bufObj->Immutable || bufObj->HandleAllocated) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(immutable)", func);
+ return;
+ }
}
/* Unmap the existing buffer. We'll replace it now. Not an error. */
_mesa_buffer_unmap_all_mappings(ctx, bufObj);
- FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
+ FLUSH_VERTICES(ctx, 0);
bufObj->Written = GL_TRUE;
bufObj->MinMaxCacheDirty = true;
GL_DYNAMIC_STORAGE_BIT,
bufObj)) {
if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {
- /* From GL_AMD_pinned_memory:
- *
- * INVALID_OPERATION is generated by BufferData if <target> is
- * EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, and the store cannot be
- * mapped to the GPU address space.
- */
- _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
- }
- else {
+ if (!no_error) {
+ /* From GL_AMD_pinned_memory:
+ *
+ * INVALID_OPERATION is generated by BufferData if <target> is
+ * EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, and the store cannot be
+ * mapped to the GPU address space.
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
+ }
+ } else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
}
}
}
+static void
+buffer_data_error(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+ GLenum target, GLsizeiptr size, const GLvoid *data,
+ GLenum usage, const char *func)
+{
+ buffer_data(ctx, bufObj, target, size, data, usage, func, false);
+}
+
+static void
+buffer_data_no_error(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+ GLenum target, GLsizeiptr size, const GLvoid *data,
+ GLenum usage, const char *func)
+{
+ buffer_data(ctx, bufObj, target, size, data, usage, func, true);
+}
+
+void
+_mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+ GLenum target, GLsizeiptr size, const GLvoid *data,
+ GLenum usage, const char *func)
+{
+ buffer_data_error(ctx, bufObj, target, size, data, usage, func);
+}
+
+void GLAPIENTRY
+_mesa_BufferData_no_error(GLenum target, GLsizeiptr size, const GLvoid *data,
+ GLenum usage)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object **bufObj = get_buffer_target(ctx, target);
+ buffer_data_no_error(ctx, *bufObj, target, size, data, usage,
+ "glBufferData");
+}
+
void GLAPIENTRY
_mesa_BufferData(GLenum target, GLsizeiptr size,
const GLvoid *data, GLenum usage)
"glBufferData");
}
+void GLAPIENTRY
+_mesa_NamedBufferData_no_error(GLuint buffer, GLsizeiptr size,
+ const GLvoid *data, GLenum usage)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ buffer_data_no_error(ctx, bufObj, GL_NONE, size, data, usage,
+ "glNamedBufferData");
+}
+
void GLAPIENTRY
_mesa_NamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid *data,
GLenum usage)
"glNamedBufferData");
}
+void GLAPIENTRY
+_mesa_NamedBufferDataEXT(GLuint buffer, GLsizeiptr size, const GLvoid *data,
+ GLenum usage)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
-/**
- * Implementation for glBufferSubData and glNamedBufferSubData.
- *
- * \param ctx GL context.
- * \param bufObj The buffer object.
- * \param offset Offset of the first byte of the subdata range.
- * \param size Size, in bytes, of the subdata range.
- * \param data The data store.
- * \param func Name of calling function for recording errors.
- *
- */
-void
-_mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
- GLintptr offset, GLsizeiptr size, const GLvoid *data,
- const char *func)
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glNamedBufferDataEXT(buffer=0)");
+ return;
+ }
+
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glNamedBufferDataEXT"))
+ return;
+
+ _mesa_buffer_data(ctx, bufObj, GL_NONE, size, data, usage,
+ "glNamedBufferDataEXT");
+}
+
+static bool
+validate_buffer_sub_data(struct gl_context *ctx,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size,
+ const char *func)
{
if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,
true, func)) {
/* error already recorded */
- return;
+ return false;
}
if (bufObj->Immutable &&
!(bufObj->StorageFlags & GL_DYNAMIC_STORAGE_BIT)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
- return;
+ return false;
}
- if (size == 0)
- return;
-
- bufObj->NumSubDataCalls++;
-
if ((bufObj->Usage == GL_STATIC_DRAW ||
bufObj->Usage == GL_STATIC_COPY) &&
- bufObj->NumSubDataCalls >= BUFFER_WARNING_CALL_COUNT) {
+ bufObj->NumSubDataCalls >= BUFFER_WARNING_CALL_COUNT - 1) {
/* If the application declared the buffer as static draw/copy or stream
* draw, it should not be frequently modified with glBufferSubData.
*/
_mesa_enum_to_string(bufObj->Usage));
}
+ return true;
+}
+
+
+/**
+ * Implementation for glBufferSubData and glNamedBufferSubData.
+ *
+ * \param ctx GL context.
+ * \param bufObj The buffer object.
+ * \param offset Offset of the first byte of the subdata range.
+ * \param size Size, in bytes, of the subdata range.
+ * \param data The data store.
+ * \param func Name of calling function for recording errors.
+ *
+ */
+void
+_mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size, const GLvoid *data)
+{
+ if (size == 0)
+ return;
+
+ bufObj->NumSubDataCalls++;
bufObj->Written = GL_TRUE;
bufObj->MinMaxCacheDirty = true;
ctx->Driver.BufferSubData(ctx, offset, size, data, bufObj);
}
-void GLAPIENTRY
-_mesa_BufferSubData(GLenum target, GLintptr offset,
- GLsizeiptr size, const GLvoid *data)
+
+static ALWAYS_INLINE void
+buffer_sub_data(GLenum target, GLuint buffer, GLintptr offset,
+ GLsizeiptr size, const GLvoid *data,
+ bool dsa, bool no_error, const char *func)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
- bufObj = get_buffer(ctx, "glBufferSubData", target, GL_INVALID_OPERATION);
- if (!bufObj)
- return;
+ if (dsa) {
+ if (no_error) {
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ } else {
+ bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, func);
+ if (!bufObj)
+ return;
+ }
+ } else {
+ if (no_error) {
+ struct gl_buffer_object **bufObjPtr = get_buffer_target(ctx, target);
+ bufObj = *bufObjPtr;
+ } else {
+ bufObj = get_buffer(ctx, func, target, GL_INVALID_OPERATION);
+ if (!bufObj)
+ return;
+ }
+ }
- _mesa_buffer_sub_data(ctx, bufObj, offset, size, data, "glBufferSubData");
+ if (no_error || validate_buffer_sub_data(ctx, bufObj, offset, size, func))
+ _mesa_buffer_sub_data(ctx, bufObj, offset, size, data);
+}
+
+
+void GLAPIENTRY
+_mesa_BufferSubData_no_error(GLenum target, GLintptr offset,
+ GLsizeiptr size, const GLvoid *data)
+{
+ buffer_sub_data(target, 0, offset, size, data, false, true,
+ "glBufferSubData");
+}
+
+
+void GLAPIENTRY
+_mesa_BufferSubData(GLenum target, GLintptr offset,
+ GLsizeiptr size, const GLvoid *data)
+{
+ buffer_sub_data(target, 0, offset, size, data, false, false,
+ "glBufferSubData");
+}
+
+void GLAPIENTRY
+_mesa_NamedBufferSubData_no_error(GLuint buffer, GLintptr offset,
+ GLsizeiptr size, const GLvoid *data)
+{
+ buffer_sub_data(0, buffer, offset, size, data, true, true,
+ "glNamedBufferSubData");
}
void GLAPIENTRY
_mesa_NamedBufferSubData(GLuint buffer, GLintptr offset,
GLsizeiptr size, const GLvoid *data)
+{
+ buffer_sub_data(0, buffer, offset, size, data, true, false,
+ "glNamedBufferSubData");
+}
+
+void GLAPIENTRY
+_mesa_NamedBufferSubDataEXT(GLuint buffer, GLintptr offset,
+ GLsizeiptr size, const GLvoid *data)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
- bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glNamedBufferSubData");
- if (!bufObj)
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glNamedBufferSubDataEXT(buffer=0)");
return;
+ }
- _mesa_buffer_sub_data(ctx, bufObj, offset, size, data,
- "glNamedBufferSubData");
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glNamedBufferSubDataEXT"))
+ return;
+
+ if (validate_buffer_sub_data(ctx, bufObj, offset, size,
+ "glNamedBufferSubDataEXT")) {
+ _mesa_buffer_sub_data(ctx, bufObj, offset, size, data);
+ }
}
}
+void GLAPIENTRY
+_mesa_GetNamedBufferSubDataEXT(GLuint buffer, GLintptr offset,
+ GLsizeiptr size, GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetNamedBufferSubDataEXT(buffer=0)");
+ return;
+ }
+
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glGetNamedBufferSubDataEXT"))
+ return;
+
+ if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size, false,
+ "glGetNamedBufferSubDataEXT")) {
+ return;
+ }
+
+ assert(ctx->Driver.GetBufferSubData);
+ ctx->Driver.GetBufferSubData(ctx, offset, size, data, bufObj);
+}
+
/**
* \param subdata true if caller is *SubData, false if *Data
*/
-static void
+static ALWAYS_INLINE void
clear_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
GLenum internalformat, GLintptr offset, GLsizeiptr size,
GLenum format, GLenum type, const GLvoid *data,
- const char *func, bool subdata)
+ const char *func, bool subdata, bool no_error)
{
mesa_format mesaFormat;
GLubyte clearValue[MAX_PIXEL_BYTES];
GLsizeiptr clearValueSize;
/* This checks for disallowed mappings. */
- if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,
- subdata, func)) {
+ if (!no_error && !buffer_object_subdata_range_good(ctx, bufObj, offset, size,
+ subdata, func)) {
return;
}
- mesaFormat = validate_clear_buffer_format(ctx, internalformat,
- format, type, func);
+ if (no_error) {
+ mesaFormat = _mesa_get_texbuffer_format(ctx, internalformat);
+ } else {
+ mesaFormat = validate_clear_buffer_format(ctx, internalformat,
+ format, type, func);
+ }
- if (mesaFormat == MESA_FORMAT_NONE) {
+ if (mesaFormat == MESA_FORMAT_NONE)
return;
- }
clearValueSize = _mesa_get_format_bytes(mesaFormat);
- if (offset % clearValueSize != 0 || size % clearValueSize != 0) {
+ if (!no_error &&
+ (offset % clearValueSize != 0 || size % clearValueSize != 0)) {
_mesa_error(ctx, GL_INVALID_VALUE,
"%s(offset or size is not a multiple of "
"internalformat size)", func);
return;
}
- if (!convert_clear_buffer_data(ctx, mesaFormat, clearValue,
- format, type, data, func)) {
- return;
- }
+ if (!convert_clear_buffer_data(ctx, mesaFormat, clearValue,
+ format, type, data, func)) {
+ return;
+ }
+
+ ctx->Driver.ClearBufferSubData(ctx, offset, size,
+ clearValue, clearValueSize, bufObj);
+}
+
+static void
+clear_buffer_sub_data_error(struct gl_context *ctx,
+ struct gl_buffer_object *bufObj,
+ GLenum internalformat, GLintptr offset,
+ GLsizeiptr size, GLenum format, GLenum type,
+ const GLvoid *data, const char *func, bool subdata)
+{
+ clear_buffer_sub_data(ctx, bufObj, internalformat, offset, size, format,
+ type, data, func, subdata, false);
+}
+
+
+static void
+clear_buffer_sub_data_no_error(struct gl_context *ctx,
+ struct gl_buffer_object *bufObj,
+ GLenum internalformat, GLintptr offset,
+ GLsizeiptr size, GLenum format, GLenum type,
+ const GLvoid *data, const char *func,
+ bool subdata)
+{
+ clear_buffer_sub_data(ctx, bufObj, internalformat, offset, size, format,
+ type, data, func, subdata, true);
+}
+
- ctx->Driver.ClearBufferSubData(ctx, offset, size,
- clearValue, clearValueSize, bufObj);
+void GLAPIENTRY
+_mesa_ClearBufferData_no_error(GLenum target, GLenum internalformat,
+ GLenum format, GLenum type, const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object **bufObj = get_buffer_target(ctx, target);
+ clear_buffer_sub_data_no_error(ctx, *bufObj, internalformat, 0,
+ (*bufObj)->Size, format, type, data,
+ "glClearBufferData", false);
}
+
void GLAPIENTRY
_mesa_ClearBufferData(GLenum target, GLenum internalformat, GLenum format,
GLenum type, const GLvoid *data)
if (!bufObj)
return;
- clear_buffer_sub_data(ctx, bufObj, internalformat, 0, bufObj->Size,
- format, type, data, "glClearBufferData", false);
+ clear_buffer_sub_data_error(ctx, bufObj, internalformat, 0, bufObj->Size,
+ format, type, data, "glClearBufferData", false);
+}
+
+
+void GLAPIENTRY
+_mesa_ClearNamedBufferData_no_error(GLuint buffer, GLenum internalformat,
+ GLenum format, GLenum type,
+ const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ clear_buffer_sub_data_no_error(ctx, bufObj, internalformat, 0, bufObj->Size,
+ format, type, data, "glClearNamedBufferData",
+ false);
}
+
void GLAPIENTRY
_mesa_ClearNamedBufferData(GLuint buffer, GLenum internalformat,
GLenum format, GLenum type, const GLvoid *data)
if (!bufObj)
return;
- clear_buffer_sub_data(ctx, bufObj, internalformat, 0, bufObj->Size,
- format, type, data, "glClearNamedBufferData", false);
+ clear_buffer_sub_data_error(ctx, bufObj, internalformat, 0, bufObj->Size,
+ format, type, data, "glClearNamedBufferData",
+ false);
+}
+
+
+void GLAPIENTRY
+_mesa_ClearNamedBufferDataEXT(GLuint buffer, GLenum internalformat,
+ GLenum format, GLenum type, const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glClearNamedBufferDataEXT"))
+ return;
+
+ clear_buffer_sub_data_error(ctx, bufObj, internalformat, 0, bufObj->Size,
+ format, type, data, "glClearNamedBufferDataEXT",
+ false);
+}
+
+
+void GLAPIENTRY
+_mesa_ClearBufferSubData_no_error(GLenum target, GLenum internalformat,
+ GLintptr offset, GLsizeiptr size,
+ GLenum format, GLenum type,
+ const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object **bufObj = get_buffer_target(ctx, target);
+ clear_buffer_sub_data_no_error(ctx, *bufObj, internalformat, offset, size,
+ format, type, data, "glClearBufferSubData",
+ true);
}
if (!bufObj)
return;
- clear_buffer_sub_data(ctx, bufObj, internalformat, offset, size,
- format, type, data, "glClearBufferSubData", true);
+ clear_buffer_sub_data_error(ctx, bufObj, internalformat, offset, size,
+ format, type, data, "glClearBufferSubData",
+ true);
+}
+
+
+void GLAPIENTRY
+_mesa_ClearNamedBufferSubData_no_error(GLuint buffer, GLenum internalformat,
+ GLintptr offset, GLsizeiptr size,
+ GLenum format, GLenum type,
+ const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ clear_buffer_sub_data_no_error(ctx, bufObj, internalformat, offset, size,
+ format, type, data,
+ "glClearNamedBufferSubData", true);
}
+
void GLAPIENTRY
_mesa_ClearNamedBufferSubData(GLuint buffer, GLenum internalformat,
GLintptr offset, GLsizeiptr size,
if (!bufObj)
return;
- clear_buffer_sub_data(ctx, bufObj, internalformat, offset, size, format,
- type, data, "glClearNamedBufferSubData", true);
+ clear_buffer_sub_data_error(ctx, bufObj, internalformat, offset, size,
+ format, type, data, "glClearNamedBufferSubData",
+ true);
+}
+
+void GLAPIENTRY
+_mesa_ClearNamedBufferSubDataEXT(GLuint buffer, GLenum internalformat,
+ GLintptr offset, GLsizeiptr size,
+ GLenum format, GLenum type,
+ const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glClearNamedBufferSubDataEXT"))
+ return;
+
+ clear_buffer_sub_data_error(ctx, bufObj, internalformat, offset, size,
+ format, type, data, "glClearNamedBufferSubDataEXT",
+ true);
}
static GLboolean
}
GLboolean GLAPIENTRY
-_mesa_UnmapNamedBuffer_no_error(GLuint buffer)
+_mesa_UnmapNamedBufferEXT_no_error(GLuint buffer)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
}
GLboolean GLAPIENTRY
-_mesa_UnmapNamedBuffer(GLuint buffer)
+_mesa_UnmapNamedBufferEXT(GLuint buffer)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glUnmapNamedBufferEXT(buffer=0)");
+ return GL_FALSE;
+ }
+
bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glUnmapNamedBuffer");
if (!bufObj)
return GL_FALSE;
*params = (GLint) parameter;
}
+void GLAPIENTRY
+_mesa_GetNamedBufferParameterivEXT(GLuint buffer, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+ GLint64 parameter;
+
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetNamedBufferParameterivEXT: buffer=0");
+ return;
+ }
+
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glGetNamedBufferParameterivEXT"))
+ return;
+
+ if (!get_buffer_parameter(ctx, bufObj, pname, ¶meter,
+ "glGetNamedBufferParameterivEXT"))
+ return; /* Error already recorded. */
+
+ *params = (GLint) parameter;
+}
+
void GLAPIENTRY
_mesa_GetNamedBufferParameteri64v(GLuint buffer, GLenum pname,
GLint64 *params)
*params = bufObj->Mappings[MAP_USER].Pointer;
}
+void GLAPIENTRY
+_mesa_GetNamedBufferPointervEXT(GLuint buffer, GLenum pname, GLvoid **params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetNamedBufferPointervEXT(buffer=0)");
+ return;
+ }
+ if (pname != GL_BUFFER_MAP_POINTER) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetNamedBufferPointervEXT(pname != "
+ "GL_BUFFER_MAP_POINTER)");
+ return;
+ }
+
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glGetNamedBufferPointervEXT"))
+ return;
+
+ *params = bufObj->Mappings[MAP_USER].Pointer;
+}
static void
copy_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *src,
ctx->Driver.CopyBufferSubData(ctx, src, dst, readOffset, writeOffset, size);
}
+void GLAPIENTRY
+_mesa_CopyBufferSubData_no_error(GLenum readTarget, GLenum writeTarget,
+ GLintptr readOffset, GLintptr writeOffset,
+ GLsizeiptr size)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object **src_ptr = get_buffer_target(ctx, readTarget);
+ struct gl_buffer_object *src = *src_ptr;
+
+ struct gl_buffer_object **dst_ptr = get_buffer_target(ctx, writeTarget);
+ struct gl_buffer_object *dst = *dst_ptr;
+
+ dst->MinMaxCacheDirty = true;
+ ctx->Driver.CopyBufferSubData(ctx, src, dst, readOffset, writeOffset,
+ size);
+}
+
void GLAPIENTRY
_mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
GLintptr readOffset, GLintptr writeOffset,
"glCopyBufferSubData");
}
+void GLAPIENTRY
+_mesa_NamedCopyBufferSubDataEXT(GLuint readBuffer, GLuint writeBuffer,
+ GLintptr readOffset, GLintptr writeOffset,
+ GLsizeiptr size)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *src, *dst;
+
+ src = _mesa_lookup_bufferobj(ctx, readBuffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, readBuffer,
+ &src,
+ "glNamedCopyBufferSubDataEXT"))
+ return;
+
+ dst = _mesa_lookup_bufferobj(ctx, writeBuffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, writeBuffer,
+ &dst,
+ "glNamedCopyBufferSubDataEXT"))
+ return;
+
+ copy_buffer_sub_data(ctx, src, dst, readOffset, writeOffset, size,
+ "glNamedCopyBufferSubDataEXT");
+}
+
+void GLAPIENTRY
+_mesa_CopyNamedBufferSubData_no_error(GLuint readBuffer, GLuint writeBuffer,
+ GLintptr readOffset,
+ GLintptr writeOffset, GLsizeiptr size)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object *src = _mesa_lookup_bufferobj(ctx, readBuffer);
+ struct gl_buffer_object *dst = _mesa_lookup_bufferobj(ctx, writeBuffer);
+
+ dst->MinMaxCacheDirty = true;
+ ctx->Driver.CopyBufferSubData(ctx, src, dst, readOffset, writeOffset,
+ size);
+}
+
void GLAPIENTRY
_mesa_CopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer,
GLintptr readOffset, GLintptr writeOffset,
"glMapNamedBufferRange");
}
-void * GLAPIENTRY
-_mesa_MapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length,
- GLbitfield access)
+static void *
+map_named_buffer_range(GLuint buffer, GLintptr offset, GLsizeiptr length,
+ GLbitfield access, bool dsa_ext, const char *func)
{
GET_CURRENT_CONTEXT(ctx);
- struct gl_buffer_object *bufObj;
+ struct gl_buffer_object *bufObj = NULL;
if (!ctx->Extensions.ARB_map_buffer_range) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glMapNamedBufferRange("
- "ARB_map_buffer_range not supported)");
+ "%s(ARB_map_buffer_range not supported)", func);
return NULL;
}
- bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glMapNamedBufferRange");
- if (!bufObj)
+ if (dsa_ext) {
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &bufObj, func))
+ return NULL;
+ } else {
+ bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, func);
+ if (!bufObj)
+ return NULL;
+ }
+
+ if (!validate_map_buffer_range(ctx, bufObj, offset, length, access, func))
return NULL;
- if (!validate_map_buffer_range(ctx, bufObj, offset, length, access,
- "glMapNamedBufferRange"))
+ return map_buffer_range(ctx, bufObj, offset, length, access, func);
+}
+
+void * GLAPIENTRY
+_mesa_MapNamedBufferRangeEXT(GLuint buffer, GLintptr offset, GLsizeiptr length,
+ GLbitfield access)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapNamedBufferRangeEXT(buffer=0)");
return NULL;
+ }
+ return map_named_buffer_range(buffer, offset, length, access, true,
+ "glMapNamedBufferRangeEXT");
+}
- return map_buffer_range(ctx, bufObj, offset, length, access,
- "glMapNamedBufferRange");
+void * GLAPIENTRY
+_mesa_MapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length,
+ GLbitfield access)
+{
+ return map_named_buffer_range(buffer, offset, length, access, false,
+ "glMapNamedBufferRange");
}
/**
*flags = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
return _mesa_is_desktop_gl(ctx);
default:
+ *flags = 0;
return false;
}
}
"glMapNamedBuffer");
}
+void * GLAPIENTRY
+_mesa_MapNamedBufferEXT(GLuint buffer, GLenum access)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ GLbitfield accessFlags;
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapNamedBufferEXT(buffer=0)");
+ return NULL;
+ }
+ if (!get_map_buffer_access_flags(ctx, access, &accessFlags)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glMapNamedBufferEXT(invalid access)");
+ return NULL;
+ }
+
+ struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glMapNamedBufferEXT"))
+ return NULL;
+
+ if (!validate_map_buffer_range(ctx, bufObj, 0, bufObj->Size, accessFlags,
+ "glMapNamedBufferEXT"))
+ return NULL;
+
+ return map_buffer_range(ctx, bufObj, 0, bufObj->Size, accessFlags,
+ "glMapNamedBufferEXT");
+}
static void
flush_mapped_buffer_range(struct gl_context *ctx,
flush_mapped_buffer_range(ctx, bufObj, offset, length,
"glFlushMappedNamedBufferRange");
}
-
-
-/**
- * Binds a buffer object to a uniform buffer binding point.
- *
- * The caller is responsible for flushing vertices and updating
- * NewDriverState.
- */
-static void
-set_ubo_binding(struct gl_context *ctx,
- struct gl_uniform_buffer_binding *binding,
- struct gl_buffer_object *bufObj,
- GLintptr offset,
- GLsizeiptr size,
- GLboolean autoSize)
-{
- _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
-
- binding->Offset = offset;
- binding->Size = size;
- binding->AutomaticSize = autoSize;
-
- /* If this is a real buffer object, mark it has having been used
- * at some point as a UBO.
- */
- if (size >= 0)
- bufObj->UsageHistory |= USAGE_UNIFORM_BUFFER;
-}
-
-/**
- * Binds a buffer object to a shader storage buffer binding point.
- *
- * The caller is responsible for flushing vertices and updating
- * NewDriverState.
- */
-static void
-set_ssbo_binding(struct gl_context *ctx,
- struct gl_shader_storage_buffer_binding *binding,
- struct gl_buffer_object *bufObj,
- GLintptr offset,
- GLsizeiptr size,
- GLboolean autoSize)
-{
- _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
-
- binding->Offset = offset;
- binding->Size = size;
- binding->AutomaticSize = autoSize;
-
- /* If this is a real buffer object, mark it has having been used
- * at some point as a SSBO.
- */
- if (size >= 0)
- bufObj->UsageHistory |= USAGE_SHADER_STORAGE_BUFFER;
-}
-
-/**
- * Binds a buffer object to a uniform buffer binding point.
- *
- * Unlike set_ubo_binding(), this function also flushes vertices
- * and updates NewDriverState. It also checks if the binding
- * has actually changed before updating it.
- */
-static void
-bind_uniform_buffer(struct gl_context *ctx,
- GLuint index,
- struct gl_buffer_object *bufObj,
- GLintptr offset,
- GLsizeiptr size,
- GLboolean autoSize)
-{
- struct gl_uniform_buffer_binding *binding =
- &ctx->UniformBufferBindings[index];
-
- if (binding->BufferObject == bufObj &&
- binding->Offset == offset &&
- binding->Size == size &&
- binding->AutomaticSize == autoSize) {
- return;
- }
-
- FLUSH_VERTICES(ctx, 0);
- ctx->NewDriverState |= ctx->DriverFlags.NewUniformBuffer;
-
- set_ubo_binding(ctx, binding, bufObj, offset, size, autoSize);
-}
-
-/**
- * Binds a buffer object to a shader storage buffer binding point.
- *
- * Unlike set_ssbo_binding(), this function also flushes vertices
- * and updates NewDriverState. It also checks if the binding
- * has actually changed before updating it.
- */
-static void
-bind_shader_storage_buffer(struct gl_context *ctx,
- GLuint index,
- struct gl_buffer_object *bufObj,
- GLintptr offset,
- GLsizeiptr size,
- GLboolean autoSize)
+
+void GLAPIENTRY
+_mesa_FlushMappedNamedBufferRangeEXT(GLuint buffer, GLintptr offset,
+ GLsizeiptr length)
{
- struct gl_shader_storage_buffer_binding *binding =
- &ctx->ShaderStorageBufferBindings[index];
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
- if (binding->BufferObject == bufObj &&
- binding->Offset == offset &&
- binding->Size == size &&
- binding->AutomaticSize == autoSize) {
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFlushMappedNamedBufferRangeEXT(buffer=0)");
return;
}
- FLUSH_VERTICES(ctx, 0);
- ctx->NewDriverState |= ctx->DriverFlags.NewShaderStorageBuffer;
+ bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glFlushMappedNamedBufferRangeEXT"))
+ return;
+
+ flush_mapped_buffer_range(ctx, bufObj, offset, length,
+ "glFlushMappedNamedBufferRangeEXT");
+}
+
+static void
+bind_buffer_range_uniform_buffer(struct gl_context *ctx, GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size)
+{
+ if (!bufObj) {
+ offset = -1;
+ size = -1;
+ }
- set_ssbo_binding(ctx, binding, bufObj, offset, size, autoSize);
+ _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, bufObj);
+ bind_uniform_buffer(ctx, index, bufObj, offset, size, GL_FALSE);
}
/**
* \param size size of the buffer object region
*/
static void
-bind_buffer_range_uniform_buffer(struct gl_context *ctx,
- GLuint index,
- struct gl_buffer_object *bufObj,
- GLintptr offset,
- GLsizeiptr size)
+bind_buffer_range_uniform_buffer_err(struct gl_context *ctx, GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size)
{
if (index >= ctx->Const.MaxUniformBufferBindings) {
_mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(index=%d)", index);
return;
}
- if (bufObj == ctx->Shared->NullBufferObj) {
+ bind_buffer_range_uniform_buffer(ctx, index, bufObj, offset, size);
+}
+
+static void
+bind_buffer_range_shader_storage_buffer(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset,
+ GLsizeiptr size)
+{
+ if (!bufObj) {
offset = -1;
size = -1;
}
- _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, bufObj);
- bind_uniform_buffer(ctx, index, bufObj, offset, size, GL_FALSE);
+ _mesa_reference_buffer_object(ctx, &ctx->ShaderStorageBuffer, bufObj);
+ bind_shader_storage_buffer(ctx, index, bufObj, offset, size, GL_FALSE);
}
/**
* \param size size of the buffer object region
*/
static void
-bind_buffer_range_shader_storage_buffer(struct gl_context *ctx,
- GLuint index,
- struct gl_buffer_object *bufObj,
- GLintptr offset,
- GLsizeiptr size)
+bind_buffer_range_shader_storage_buffer_err(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size)
{
if (index >= ctx->Const.MaxShaderStorageBufferBindings) {
_mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(index=%d)", index);
return;
}
- if (bufObj == ctx->Shared->NullBufferObj) {
- offset = -1;
- size = -1;
- }
-
- _mesa_reference_buffer_object(ctx, &ctx->ShaderStorageBuffer, bufObj);
- bind_shader_storage_buffer(ctx, index, bufObj, offset, size, GL_FALSE);
-}
-
-/**
- * Bind a buffer object to a uniform block binding point.
- * As above, but offset = 0.
- */
-static void
-bind_buffer_base_uniform_buffer(struct gl_context *ctx,
- GLuint index,
- struct gl_buffer_object *bufObj)
-{
- if (index >= ctx->Const.MaxUniformBufferBindings) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferBase(index=%d)", index);
- return;
- }
-
- _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, bufObj);
-
- if (bufObj == ctx->Shared->NullBufferObj)
- bind_uniform_buffer(ctx, index, bufObj, -1, -1, GL_TRUE);
- else
- bind_uniform_buffer(ctx, index, bufObj, 0, 0, GL_TRUE);
+ bind_buffer_range_shader_storage_buffer(ctx, index, bufObj, offset, size);
}
-/**
- * Bind a buffer object to a shader storage block binding point.
- * As above, but offset = 0.
- */
static void
-bind_buffer_base_shader_storage_buffer(struct gl_context *ctx,
- GLuint index,
- struct gl_buffer_object *bufObj)
+bind_buffer_range_atomic_buffer(struct gl_context *ctx, GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size)
{
- if (index >= ctx->Const.MaxShaderStorageBufferBindings) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferBase(index=%d)", index);
- return;
+ if (!bufObj) {
+ offset = -1;
+ size = -1;
}
- _mesa_reference_buffer_object(ctx, &ctx->ShaderStorageBuffer, bufObj);
-
- if (bufObj == ctx->Shared->NullBufferObj)
- bind_shader_storage_buffer(ctx, index, bufObj, -1, -1, GL_TRUE);
- else
- bind_shader_storage_buffer(ctx, index, bufObj, 0, 0, GL_TRUE);
-}
-
-/**
- * Binds a buffer object to an atomic buffer binding point.
- *
- * The caller is responsible for validating the offset,
- * flushing the vertices and updating NewDriverState.
- */
-static void
-set_atomic_buffer_binding(struct gl_context *ctx,
- struct gl_atomic_buffer_binding *binding,
- struct gl_buffer_object *bufObj,
- GLintptr offset,
- GLsizeiptr size)
-{
- _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
-
- if (bufObj == ctx->Shared->NullBufferObj) {
- binding->Offset = 0;
- binding->Size = 0;
- } else {
- binding->Offset = offset;
- binding->Size = size;
- bufObj->UsageHistory |= USAGE_ATOMIC_COUNTER_BUFFER;
- }
+ _mesa_reference_buffer_object(ctx, &ctx->AtomicBuffer, bufObj);
+ bind_atomic_buffer(ctx, index, bufObj, offset, size, GL_FALSE);
}
/**
- * Binds a buffer object to an atomic buffer binding point.
- *
- * Unlike set_atomic_buffer_binding(), this function also validates the
- * index and offset, flushes vertices, and updates NewDriverState.
- * It also checks if the binding has actually changing before
- * updating it.
+ * Bind a region of a buffer object to an atomic storage block binding point.
+ * \param index the shader storage buffer binding point index
+ * \param bufObj the buffer object
+ * \param offset offset to the start of buffer object region
+ * \param size size of the buffer object region
*/
static void
-bind_atomic_buffer(struct gl_context *ctx,
- unsigned index,
- struct gl_buffer_object *bufObj,
- GLintptr offset,
- GLsizeiptr size,
- const char *name)
+bind_buffer_range_atomic_buffer_err(struct gl_context *ctx,
+ GLuint index,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size)
{
- struct gl_atomic_buffer_binding *binding;
-
if (index >= ctx->Const.MaxAtomicBufferBindings) {
- _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%d)", name, index);
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(index=%d)", index);
return;
}
if (offset & (ATOMIC_COUNTER_SIZE - 1)) {
_mesa_error(ctx, GL_INVALID_VALUE,
- "%s(offset misaligned %d/%d)", name, (int) offset,
- ATOMIC_COUNTER_SIZE);
- return;
- }
-
- _mesa_reference_buffer_object(ctx, &ctx->AtomicBuffer, bufObj);
-
- binding = &ctx->AtomicBufferBindings[index];
- if (binding->BufferObject == bufObj &&
- binding->Offset == offset &&
- binding->Size == size) {
+ "glBindBufferRange(offset misaligned %d/%d)", (int) offset,
+ ATOMIC_COUNTER_SIZE);
return;
}
- FLUSH_VERTICES(ctx, 0);
- ctx->NewDriverState |= ctx->DriverFlags.NewAtomicBuffer;
-
- set_atomic_buffer_binding(ctx, binding, bufObj, offset, size);
+ bind_buffer_range_atomic_buffer(ctx, index, bufObj, offset, size);
}
static inline bool
static void
unbind_uniform_buffers(struct gl_context *ctx, GLuint first, GLsizei count)
{
- struct gl_buffer_object *bufObj = ctx->Shared->NullBufferObj;
- GLint i;
-
- for (i = 0; i < count; i++)
- set_ubo_binding(ctx, &ctx->UniformBufferBindings[first + i],
- bufObj, -1, -1, GL_TRUE);
+ for (int i = 0; i < count; i++)
+ set_buffer_binding(ctx, &ctx->UniformBufferBindings[first + i],
+ NULL, -1, -1, GL_TRUE, 0);
}
/**
unbind_shader_storage_buffers(struct gl_context *ctx, GLuint first,
GLsizei count)
{
- struct gl_buffer_object *bufObj = ctx->Shared->NullBufferObj;
- GLint i;
-
- for (i = 0; i < count; i++)
- set_ssbo_binding(ctx, &ctx->ShaderStorageBufferBindings[first + i],
- bufObj, -1, -1, GL_TRUE);
+ for (int i = 0; i < count; i++)
+ set_buffer_binding(ctx, &ctx->ShaderStorageBufferBindings[first + i],
+ NULL, -1, -1, GL_TRUE, 0);
}
static void
const GLintptr *offsets, const GLsizeiptr *sizes,
const char *caller)
{
- GLint i;
-
if (!error_check_bind_uniform_buffers(ctx, first, count, caller))
return;
_mesa_HashLockMutex(ctx->Shared->BufferObjects);
- for (i = 0; i < count; i++) {
- struct gl_uniform_buffer_binding *binding =
+ for (int i = 0; i < count; i++) {
+ struct gl_buffer_binding *binding =
&ctx->UniformBufferBindings[first + i];
- struct gl_buffer_object *bufObj;
GLintptr offset = 0;
GLsizeiptr size = 0;
size = sizes[i];
}
- if (binding->BufferObject && binding->BufferObject->Name == buffers[i])
- bufObj = binding->BufferObject;
- else
- bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, caller);
-
- if (bufObj) {
- if (bufObj == ctx->Shared->NullBufferObj)
- set_ubo_binding(ctx, binding, bufObj, -1, -1, !range);
- else
- set_ubo_binding(ctx, binding, bufObj, offset, size, !range);
- }
+ set_buffer_multi_binding(ctx, buffers, i, caller,
+ binding, offset, size, range,
+ USAGE_UNIFORM_BUFFER);
}
_mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
const GLsizeiptr *sizes,
const char *caller)
{
- GLint i;
-
if (!error_check_bind_shader_storage_buffers(ctx, first, count, caller))
return;
_mesa_HashLockMutex(ctx->Shared->BufferObjects);
- for (i = 0; i < count; i++) {
- struct gl_shader_storage_buffer_binding *binding =
+ for (int i = 0; i < count; i++) {
+ struct gl_buffer_binding *binding =
&ctx->ShaderStorageBufferBindings[first + i];
- struct gl_buffer_object *bufObj;
GLintptr offset = 0;
GLsizeiptr size = 0;
size = sizes[i];
}
- if (binding->BufferObject && binding->BufferObject->Name == buffers[i])
- bufObj = binding->BufferObject;
- else
- bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, caller);
-
- if (bufObj) {
- if (bufObj == ctx->Shared->NullBufferObj)
- set_ssbo_binding(ctx, binding, bufObj, -1, -1, !range);
- else
- set_ssbo_binding(ctx, binding, bufObj, offset, size, !range);
- }
+ set_buffer_multi_binding(ctx, buffers, i, caller,
+ binding, offset, size, range,
+ USAGE_SHADER_STORAGE_BUFFER);
}
_mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
struct gl_transform_feedback_object *tfObj,
GLuint first, GLsizei count)
{
- struct gl_buffer_object * const bufObj = ctx->Shared->NullBufferObj;
- GLint i;
-
- for (i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
_mesa_set_transform_feedback_binding(ctx, tfObj, first + i,
- bufObj, 0, 0);
+ NULL, 0, 0);
}
static void
{
struct gl_transform_feedback_object *tfObj =
ctx->TransformFeedback.CurrentObject;
- GLint i;
if (!error_check_bind_xfb_buffers(ctx, tfObj, first, count, caller))
return;
_mesa_HashLockMutex(ctx->Shared->BufferObjects);
- for (i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
const GLuint index = first + i;
struct gl_buffer_object * const boundBufObj = tfObj->Buffers[index];
struct gl_buffer_object *bufObj;
GLsizeiptr size = 0;
if (range) {
- offset = offsets[i];
- size = sizes[i];
-
if (!bind_buffers_check_offset_and_size(ctx, i, offsets, sizes))
continue;
if (boundBufObj && boundBufObj->Name == buffers[i])
bufObj = boundBufObj;
- else
- bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, caller);
+ else {
+ bool error;
+ bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, caller,
+ &error);
+ if (error)
+ continue;
+ }
- if (bufObj)
- _mesa_set_transform_feedback_binding(ctx, tfObj, index, bufObj,
- offset, size);
+ _mesa_set_transform_feedback_binding(ctx, tfObj, index, bufObj,
+ offset, size);
}
_mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
static void
unbind_atomic_buffers(struct gl_context *ctx, GLuint first, GLsizei count)
{
- struct gl_buffer_object * const bufObj = ctx->Shared->NullBufferObj;
- GLint i;
-
- for (i = 0; i < count; i++)
- set_atomic_buffer_binding(ctx, &ctx->AtomicBufferBindings[first + i],
- bufObj, -1, -1);
+ for (int i = 0; i < count; i++)
+ set_buffer_binding(ctx, &ctx->AtomicBufferBindings[first + i],
+ NULL, -1, -1, GL_TRUE, 0);
}
static void
const GLsizeiptr *sizes,
const char *caller)
{
- GLint i;
-
if (!error_check_bind_atomic_buffers(ctx, first, count, caller))
return;
_mesa_HashLockMutex(ctx->Shared->BufferObjects);
- for (i = 0; i < count; i++) {
- struct gl_atomic_buffer_binding *binding =
+ for (int i = 0; i < count; i++) {
+ struct gl_buffer_binding *binding =
&ctx->AtomicBufferBindings[first + i];
- struct gl_buffer_object *bufObj;
GLintptr offset = 0;
GLsizeiptr size = 0;
size = sizes[i];
}
- if (binding->BufferObject && binding->BufferObject->Name == buffers[i])
- bufObj = binding->BufferObject;
- else
- bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, caller);
-
- if (bufObj)
- set_atomic_buffer_binding(ctx, binding, bufObj, offset, size);
+ set_buffer_multi_binding(ctx, buffers, i, caller,
+ binding, offset, size, range,
+ USAGE_ATOMIC_COUNTER_BUFFER);
}
_mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
-void GLAPIENTRY
-_mesa_BindBufferRange(GLenum target, GLuint index,
- GLuint buffer, GLintptr offset, GLsizeiptr size)
+static ALWAYS_INLINE void
+bind_buffer_range(GLenum target, GLuint index, GLuint buffer, GLintptr offset,
+ GLsizeiptr size, bool no_error)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
}
if (buffer == 0) {
- bufObj = ctx->Shared->NullBufferObj;
+ bufObj = NULL;
} else {
bufObj = _mesa_lookup_bufferobj(ctx, buffer);
- }
- if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
- &bufObj, "glBindBufferRange"))
- return;
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glBindBufferRange"))
+ return;
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBindBufferRange(invalid buffer=%u)", buffer);
- return;
+ if (!no_error && !bufObj) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBindBufferRange(invalid buffer=%u)", buffer);
+ return;
+ }
}
- if (buffer != 0) {
- if (size <= 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size=%d)",
- (int) size);
+ if (no_error) {
+ switch (target) {
+ case GL_TRANSFORM_FEEDBACK_BUFFER:
+ _mesa_bind_buffer_range_xfb(ctx, ctx->TransformFeedback.CurrentObject,
+ index, bufObj, offset, size);
+ return;
+ case GL_UNIFORM_BUFFER:
+ bind_buffer_range_uniform_buffer(ctx, index, bufObj, offset, size);
+ return;
+ case GL_SHADER_STORAGE_BUFFER:
+ bind_buffer_range_shader_storage_buffer(ctx, index, bufObj, offset,
+ size);
+ return;
+ case GL_ATOMIC_COUNTER_BUFFER:
+ bind_buffer_range_atomic_buffer(ctx, index, bufObj, offset, size);
return;
+ default:
+ unreachable("invalid BindBufferRange target with KHR_no_error");
+ }
+ } else {
+ if (buffer != 0) {
+ if (size <= 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size=%d)",
+ (int) size);
+ return;
+ }
}
- }
- switch (target) {
- case GL_TRANSFORM_FEEDBACK_BUFFER:
- _mesa_bind_buffer_range_transform_feedback(ctx,
- ctx->TransformFeedback.CurrentObject,
- index, bufObj, offset, size,
- false);
- return;
- case GL_UNIFORM_BUFFER:
- bind_buffer_range_uniform_buffer(ctx, index, bufObj, offset, size);
- return;
- case GL_SHADER_STORAGE_BUFFER:
- bind_buffer_range_shader_storage_buffer(ctx, index, bufObj, offset, size);
- return;
- case GL_ATOMIC_COUNTER_BUFFER:
- bind_atomic_buffer(ctx, index, bufObj, offset, size,
- "glBindBufferRange");
- return;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferRange(target)");
- return;
+ switch (target) {
+ case GL_TRANSFORM_FEEDBACK_BUFFER:
+ if (!_mesa_validate_buffer_range_xfb(ctx,
+ ctx->TransformFeedback.CurrentObject,
+ index, bufObj, offset, size,
+ false))
+ return;
+
+ _mesa_bind_buffer_range_xfb(ctx, ctx->TransformFeedback.CurrentObject,
+ index, bufObj, offset, size);
+ return;
+ case GL_UNIFORM_BUFFER:
+ bind_buffer_range_uniform_buffer_err(ctx, index, bufObj, offset,
+ size);
+ return;
+ case GL_SHADER_STORAGE_BUFFER:
+ bind_buffer_range_shader_storage_buffer_err(ctx, index, bufObj,
+ offset, size);
+ return;
+ case GL_ATOMIC_COUNTER_BUFFER:
+ bind_buffer_range_atomic_buffer_err(ctx, index, bufObj,
+ offset, size);
+ return;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferRange(target)");
+ return;
+ }
}
}
+void GLAPIENTRY
+_mesa_BindBufferRange_no_error(GLenum target, GLuint index, GLuint buffer,
+ GLintptr offset, GLsizeiptr size)
+{
+ bind_buffer_range(target, index, buffer, offset, size, true);
+}
+
+void GLAPIENTRY
+_mesa_BindBufferRange(GLenum target, GLuint index,
+ GLuint buffer, GLintptr offset, GLsizeiptr size)
+{
+ bind_buffer_range(target, index, buffer, offset, size, false);
+}
+
void GLAPIENTRY
_mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer)
{
}
if (buffer == 0) {
- bufObj = ctx->Shared->NullBufferObj;
+ bufObj = NULL;
} else {
bufObj = _mesa_lookup_bufferobj(ctx, buffer);
- }
- if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
- &bufObj, "glBindBufferBase"))
- return;
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glBindBufferBase"))
+ return;
- if (!bufObj) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBindBufferBase(invalid buffer=%u)", buffer);
- return;
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBindBufferBase(invalid buffer=%u)", buffer);
+ return;
+ }
}
/* Note that there's some oddness in the GL 3.1-GL 3.3 specifications with
bind_buffer_base_shader_storage_buffer(ctx, index, bufObj);
return;
case GL_ATOMIC_COUNTER_BUFFER:
- bind_atomic_buffer(ctx, index, bufObj, 0, 0,
- "glBindBufferBase");
+ bind_buffer_base_atomic_buffer(ctx, index, bufObj);
return;
default:
_mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferBase(target)");
}
}
+static ALWAYS_INLINE void
+invalidate_buffer_subdata(struct gl_context *ctx,
+ struct gl_buffer_object *bufObj, GLintptr offset,
+ GLsizeiptr length)
+{
+ if (ctx->Driver.InvalidateBufferSubData)
+ ctx->Driver.InvalidateBufferSubData(ctx, bufObj, offset, length);
+}
+
+void GLAPIENTRY
+_mesa_InvalidateBufferSubData_no_error(GLuint buffer, GLintptr offset,
+ GLsizeiptr length)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+ invalidate_buffer_subdata(ctx, bufObj, offset, length);
+}
+
void GLAPIENTRY
_mesa_InvalidateBufferSubData(GLuint buffer, GLintptr offset,
GLsizeiptr length)
return;
}
- if (ctx->Driver.InvalidateBufferSubData)
- ctx->Driver.InvalidateBufferSubData(ctx, bufObj, offset, length);
+ invalidate_buffer_subdata(ctx, bufObj, offset, length);
+}
+
+void GLAPIENTRY
+_mesa_InvalidateBufferData_no_error(GLuint buffer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+
+ struct gl_buffer_object *bufObj =_mesa_lookup_bufferobj(ctx, buffer);
+ invalidate_buffer_subdata(ctx, bufObj, 0, bufObj->Size);
}
void GLAPIENTRY
return;
}
- if (ctx->Driver.InvalidateBufferSubData)
- ctx->Driver.InvalidateBufferSubData(ctx, bufObj, 0, bufObj->Size);
+ invalidate_buffer_subdata(ctx, bufObj, 0, bufObj->Size);
}
static void
buffer_page_commitment(ctx, bufferObj, offset, size, commit,
"glNamedBufferPageCommitmentARB");
}
+
+void GLAPIENTRY
+_mesa_NamedBufferPageCommitmentEXT(GLuint buffer, GLintptr offset,
+ GLsizeiptr size, GLboolean commit)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufferObj;
+
+ /* Use NamedBuffer* functions logic from EXT_direct_state_access */
+ if (buffer != 0) {
+ bufferObj = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &bufferObj,
+ "glNamedBufferPageCommitmentEXT"))
+ return;
+ } else {
+ /* GL_EXT_direct_state_access says about NamedBuffer* functions:
+ *
+ * There is no buffer corresponding to the name zero, these commands
+ * generate the INVALID_OPERATION error if the buffer parameter is
+ * zero.
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glNamedBufferPageCommitmentEXT(buffer = 0)");
+ return;
+ }
+ buffer_page_commitment(ctx, bufferObj, offset, size, commit,
+ "glNamedBufferPageCommitmentEXT");
+}