#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 "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);
}
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;
}
/**
* 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;
}
bufObj->RefCount = -1000;
bufObj->Name = ~0;
- simple_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;
- simple_mtx_lock(&oldObj->Mutex);
- assert(oldObj->RefCount > 0);
- oldObj->RefCount--;
- deleteFlag = (oldObj->RefCount == 0);
- simple_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 */
- simple_mtx_lock(&bufObj->Mutex);
- assert(bufObj->RefCount > 0);
-
- bufObj->RefCount++;
+ p_atomic_inc(&bufObj->RefCount);
*ptr = bufObj;
- simple_mtx_unlock(&bufObj->Mutex);
}
}
GLuint name)
{
memset(obj, 0, sizeof(struct gl_buffer_object));
- simple_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));
- simple_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,
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);
}
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 = _mesa_lookup_bufferobj(ctx, buffer);
+ if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+ &bufObj, "glNamedBufferStorageEXT"))
+ return;
+
+ inlined_buffer_storage(GL_NONE, buffer, size, data, flags, GL_NONE, 0,
+ true, false, false, "glNamedBufferStorageEXT");
+}
+
void GLAPIENTRY
_mesa_BufferStorageMemEXT(GLenum target, GLsizeiptr size,
"glNamedBufferData");
}
+void GLAPIENTRY
+_mesa_NamedBufferDataEXT(GLuint buffer, GLsizeiptr size, const GLvoid *data,
+ GLenum usage)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+
+ 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,
"glNamedBufferSubData");
}
+void GLAPIENTRY
+_mesa_NamedBufferSubDataEXT(GLuint buffer, GLintptr offset,
+ GLsizeiptr size, const GLvoid *data)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glNamedBufferSubDataEXT(buffer=0)");
+ return;
+ }
+
+ 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_GetBufferSubData(GLenum target, GLintptr offset,
}
+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
*/
}
+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,
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
unmap_buffer(struct gl_context *ctx, struct gl_buffer_object *bufObj)
{
}
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,
"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,
"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");
}
/**
"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,
"glFlushMappedNamedBufferRange");
}
+void GLAPIENTRY
+_mesa_FlushMappedNamedBufferRangeEXT(GLuint buffer, GLintptr offset,
+ GLsizeiptr length)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_buffer_object *bufObj;
+
+ if (!buffer) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glFlushMappedNamedBufferRangeEXT(buffer=0)");
+ return;
+ }
+
+ 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,
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 {
+ bufferObj = ctx->Shared->NullBufferObj;
+ }
+ buffer_page_commitment(ctx, bufferObj, offset, size, commit,
+ "glNamedBufferPageCommitmentEXT");
+}