Commit 7e548d05 authored by Marek Olšák's avatar Marek Olšák

mesa: add storage flags parameter to Driver.BufferData

It will be used by glBufferStorage. The parameters are chosen according
to ARB_buffer_storage.
Reviewed-by: Fredrik Höglund's avatarFredrik Höglund <fredrik@kde.org>
parent aea49332
......@@ -116,13 +116,16 @@ intel_bufferobj_data(struct gl_context * ctx,
GLenum target,
GLsizeiptrARB size,
const GLvoid * data,
GLenum usage, struct gl_buffer_object *obj)
GLenum usage,
GLbitfield storageFlags,
struct gl_buffer_object *obj)
{
struct intel_context *intel = intel_context(ctx);
struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
intel_obj->Base.Size = size;
intel_obj->Base.Usage = usage;
intel_obj->Base.StorageFlags = storageFlags;
assert(!obj->Pointer); /* Mesa should have unmapped it */
......
......@@ -182,7 +182,9 @@ intel_bufferobj_data(struct gl_context * ctx,
GLenum target,
GLsizeiptrARB size,
const GLvoid * data,
GLenum usage, struct gl_buffer_object *obj)
GLenum usage,
GLbitfield storageFlags,
struct gl_buffer_object *obj)
{
struct brw_context *brw = brw_context(ctx);
struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
......@@ -193,6 +195,7 @@ intel_bufferobj_data(struct gl_context * ctx,
intel_obj->Base.Size = size;
intel_obj->Base.Usage = usage;
intel_obj->Base.StorageFlags = storageFlags;
assert(!obj->Pointer); /* Mesa should have unmapped it */
......
......@@ -73,7 +73,7 @@ nouveau_bufferobj_del(struct gl_context *ctx, struct gl_buffer_object *obj)
static GLboolean
nouveau_bufferobj_data(struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
const GLvoid *data, GLenum usage,
const GLvoid *data, GLenum usage, GLbitfield storageFlags,
struct gl_buffer_object *obj)
{
struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
......@@ -81,6 +81,7 @@ nouveau_bufferobj_data(struct gl_context *ctx, GLenum target, GLsizeiptrARB size
obj->Size = size;
obj->Usage = usage;
obj->StorageFlags = storageFlags;
/* Free previous storage */
nouveau_bo_ref(NULL, &nbo->bo);
......
......@@ -86,6 +86,7 @@ radeonBufferData(struct gl_context * ctx,
GLsizeiptrARB size,
const GLvoid * data,
GLenum usage,
GLbitfield storageFlags,
struct gl_buffer_object *obj)
{
radeonContextPtr radeon = RADEON_CONTEXT(ctx);
......@@ -93,6 +94,7 @@ radeonBufferData(struct gl_context * ctx,
radeon_obj->Base.Size = size;
radeon_obj->Base.Usage = usage;
radeon_obj->Base.StorageFlags = storageFlags;
if (radeon_obj->bo != NULL) {
radeon_bo_unref(radeon_obj->bo);
......
......@@ -555,7 +555,7 @@ _mesa_total_buffer_object_memory(struct gl_context *ctx)
*/
static GLboolean
_mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
const GLvoid * data, GLenum usage,
const GLvoid * data, GLenum usage, GLenum storageFlags,
struct gl_buffer_object * bufObj )
{
void * new_data;
......@@ -569,6 +569,7 @@ _mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
bufObj->Data = (GLubyte *) new_data;
bufObj->Size = size;
bufObj->Usage = usage;
bufObj->StorageFlags = storageFlags;
if (data) {
memcpy( bufObj->Data, data, size );
......@@ -1305,7 +1306,11 @@ _mesa_BufferData(GLenum target, GLsizeiptrARB size,
#endif
ASSERT(ctx->Driver.BufferData);
if (!ctx->Driver.BufferData( ctx, target, size, data, usage, bufObj )) {
if (!ctx->Driver.BufferData(ctx, target, size, data, usage,
GL_MAP_READ_BIT |
GL_MAP_WRITE_BIT |
GL_DYNAMIC_STORAGE_BIT,
bufObj)) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBufferDataARB()");
}
}
......
......@@ -578,7 +578,7 @@ struct dd_function_table {
GLboolean (*BufferData)(struct gl_context *ctx, GLenum target,
GLsizeiptrARB size, const GLvoid *data, GLenum usage,
struct gl_buffer_object *obj);
GLenum storageFlags, struct gl_buffer_object *obj);
void (*BufferSubData)( struct gl_context *ctx, GLintptrARB offset,
GLsizeiptrARB size, const GLvoid *data,
......
......@@ -1449,6 +1449,7 @@ struct gl_buffer_object
GLuint Name;
GLchar *Label; /**< GL_KHR_debug */
GLenum Usage; /**< GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, etc. */
GLbitfield StorageFlags; /**< GL_MAP_PERSISTENT_BIT, etc. */
GLsizeiptrARB Size; /**< Size of buffer storage in bytes */
GLubyte *Data; /**< Location of storage either in RAM or VRAM. */
/** Fields describing a mapped buffer */
......
......@@ -176,6 +176,7 @@ st_bufferobj_data(struct gl_context *ctx,
GLsizeiptrARB size,
const GLvoid * data,
GLenum usage,
GLbitfield storageFlags,
struct gl_buffer_object *obj)
{
struct st_context *st = st_context(ctx);
......@@ -184,7 +185,9 @@ st_bufferobj_data(struct gl_context *ctx,
unsigned bind, pipe_usage;
if (size && data && st_obj->buffer &&
st_obj->Base.Size == size && st_obj->Base.Usage == usage) {
st_obj->Base.Size == size &&
st_obj->Base.Usage == usage &&
st_obj->Base.StorageFlags == storageFlags) {
/* Just discard the old contents and write new data.
* This should be the same as creating a new buffer, but we avoid
* a lot of validation in Mesa.
......@@ -200,6 +203,7 @@ st_bufferobj_data(struct gl_context *ctx,
st_obj->Base.Size = size;
st_obj->Base.Usage = usage;
st_obj->Base.StorageFlags = storageFlags;
switch (target) {
case GL_PIXEL_PACK_BUFFER_ARB:
......
......@@ -998,7 +998,11 @@ void vbo_use_buffer_objects(struct gl_context *ctx)
/* Allocate a real buffer object now */
_mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
exec->vtx.bufferobj = ctx->Driver.NewBufferObject(ctx, bufName, target);
if (!ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj)) {
if (!ctx->Driver.BufferData(ctx, target, size, NULL, usage,
GL_MAP_WRITE_BIT |
GL_DYNAMIC_STORAGE_BIT |
GL_CLIENT_STORAGE_BIT,
exec->vtx.bufferobj)) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "VBO allocation");
}
}
......
......@@ -325,8 +325,12 @@ vbo_exec_vtx_map( struct vbo_exec_context *exec )
exec->vtx.buffer_used = 0;
if (ctx->Driver.BufferData(ctx, GL_ARRAY_BUFFER_ARB,
VBO_VERT_BUFFER_SIZE,
NULL, usage, exec->vtx.bufferobj)) {
VBO_VERT_BUFFER_SIZE,
NULL, usage,
GL_MAP_WRITE_BIT |
GL_DYNAMIC_STORAGE_BIT |
GL_CLIENT_STORAGE_BIT,
exec->vtx.bufferobj)) {
/* buffer allocation worked, now map the buffer */
exec->vtx.buffer_map =
(GLfloat *)ctx->Driver.MapBufferRange(ctx,
......
......@@ -200,6 +200,8 @@ alloc_vertex_store(struct gl_context *ctx)
GL_ARRAY_BUFFER_ARB,
VBO_SAVE_BUFFER_SIZE * sizeof(GLfloat),
NULL, GL_STATIC_DRAW_ARB,
GL_MAP_WRITE_BIT |
GL_DYNAMIC_STORAGE_BIT,
vertex_store->bufferobj);
}
else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment