From: Nicolai Hähnle <nicolai.haeh...@amd.com> Reviewed-by: Ian Romanick <ian.d.roman...@intel.com> Reviewed-by: Marek Olšák <marek.ol...@amd.com> --- src/mesa/main/bufferobj.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ src/mesa/main/dd.h | 10 +++++++ 2 files changed, 76 insertions(+)
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index a4ccf8c..27eaf77 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -4054,21 +4054,87 @@ _mesa_InvalidateBufferData(GLuint buffer) _mesa_error(ctx, GL_INVALID_OPERATION, "glInvalidateBufferData(intersection with mapped " "range)"); return; } if (ctx->Driver.InvalidateBufferSubData) ctx->Driver.InvalidateBufferSubData(ctx, bufObj, 0, bufObj->Size); } +static void +buffer_page_commitment(struct gl_context *ctx, + struct gl_buffer_object *bufferObj, + GLintptr offset, GLsizeiptr size, + GLboolean commit, const char *func) +{ + if (!(bufferObj->StorageFlags & GL_SPARSE_STORAGE_BIT_ARB)) { + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(not a sparse buffer object)", + func); + return; + } + + if (size < 0 || size > bufferObj->Size || + offset < 0 || offset > bufferObj->Size - size) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s(out of bounds)", + func); + return; + } + + /* The GL_ARB_sparse_buffer extension specification says: + * + * "INVALID_VALUE is generated by BufferPageCommitmentARB if <offset> is + * not an integer multiple of SPARSE_BUFFER_PAGE_SIZE_ARB, or if <size> + * is not an integer multiple of SPARSE_BUFFER_PAGE_SIZE_ARB and does + * not extend to the end of the buffer's data store." + */ + if (offset % ctx->Const.SparseBufferPageSize != 0) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset not aligned to page size)", + func); + return; + } + + if (size % ctx->Const.SparseBufferPageSize != 0 && + offset + size != bufferObj->Size) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s(size not aligned to page size)", + func); + return; + } + + ctx->Driver.BufferPageCommitment(ctx, bufferObj, offset, size, commit); +} + void GLAPIENTRY _mesa_BufferPageCommitmentARB(GLenum target, GLintptr offset, GLsizeiptr size, GLboolean commit) { + GET_CURRENT_CONTEXT(ctx); + struct gl_buffer_object *bufferObj; + + bufferObj = get_buffer(ctx, "glBufferPageCommitmentARB", target, + GL_INVALID_ENUM); + if (!bufferObj) + return; + + buffer_page_commitment(ctx, bufferObj, offset, size, commit, + "glBufferPageCommitmentARB"); } void GLAPIENTRY _mesa_NamedBufferPageCommitmentARB(GLuint buffer, GLintptr offset, GLsizeiptr size, GLboolean commit) { + GET_CURRENT_CONTEXT(ctx); + struct gl_buffer_object *bufferObj; + + bufferObj = _mesa_lookup_bufferobj(ctx, buffer); + if (!bufferObj || bufferObj == &DummyBufferObject) { + /* Note: the extension spec is not clear about the excpected error value. */ + _mesa_error(ctx, GL_INVALID_VALUE, + "glNamedBufferPageCommitmentARB(name = %u) invalid object", + buffer); + return; + } + + buffer_page_commitment(ctx, bufferObj, offset, size, commit, + "glNamedBufferPageCommitmentARB"); } diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index f300ad6..ce3a1e4 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -1036,20 +1036,30 @@ struct dd_function_table { * perform drawing on behalf of multiple contexts. * * Mesa may sometimes call this function from a non-background thread * (i.e. a thread that has already been bound to a context using * __DriverAPIRec::MakeCurrent()); when this happens, ctx will be equal to * the context that is bound to this thread. * * Mesa will only call this function if GL multithreading is enabled. */ void (*SetBackgroundContext)(struct gl_context *ctx); + + /** + * \name GL_ARB_sparse_buffer interface + */ + /*@{*/ + void (*BufferPageCommitment)(struct gl_context *ctx, + struct gl_buffer_object *bufferObj, + GLintptr offset, GLsizeiptr size, + GLboolean commit); + /*@}*/ }; /** * Per-vertex functions. * * These are the functions which can appear between glBegin and glEnd. * Depending on whether we're inside or outside a glBegin/End pair * and whether we're in immediate mode or building a display list, these * functions behave differently. This structure allows us to switch -- 2.9.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev