mesa/st: merge memoryobjects code from st into mesa
This takes all the memory object code from state tracker and merges it into mesa, cleaning it up on the way. Acked-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14327>
This commit is contained in:
@@ -50,8 +50,6 @@
|
||||
#include "api_exec_decl.h"
|
||||
#include "util/set.h"
|
||||
|
||||
#include "state_tracker/st_cb_memoryobjects.h"
|
||||
|
||||
#include "state_tracker/st_debug.h"
|
||||
#include "state_tracker/st_atom.h"
|
||||
#include "frontend/api.h"
|
||||
@@ -263,7 +261,6 @@ bufferobj_data(struct gl_context *ctx,
|
||||
{
|
||||
struct pipe_context *pipe = ctx->pipe;
|
||||
struct pipe_screen *screen = pipe->screen;
|
||||
struct st_memory_object *st_mem_obj = st_memory_object(memObj);
|
||||
bool is_mapped = _mesa_bufferobj_mapped(obj, MAP_USER);
|
||||
|
||||
if (size > UINT32_MAX || offset > UINT32_MAX) {
|
||||
@@ -334,10 +331,10 @@ bufferobj_data(struct gl_context *ctx,
|
||||
buffer.depth0 = 1;
|
||||
buffer.array_size = 1;
|
||||
|
||||
if (st_mem_obj) {
|
||||
if (memObj) {
|
||||
obj->buffer = screen->resource_from_memobj(screen, &buffer,
|
||||
st_mem_obj->memory,
|
||||
offset);
|
||||
memObj->memory,
|
||||
offset);
|
||||
}
|
||||
else if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {
|
||||
obj->buffer =
|
||||
|
||||
@@ -33,9 +33,52 @@
|
||||
#include "texstorage.h"
|
||||
#include "util/u_memory.h"
|
||||
|
||||
#include "state_tracker/st_cb_memoryobjects.h"
|
||||
#include "state_tracker/st_cb_semaphoreobjects.h"
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_screen.h"
|
||||
#include "api_exec_decl.h"
|
||||
#include "state_tracker/st_cb_semaphoreobjects.h"
|
||||
|
||||
#include "frontend/drm_driver.h"
|
||||
#ifdef HAVE_LIBDRM
|
||||
#include "drm-uapi/drm_fourcc.h"
|
||||
#endif
|
||||
|
||||
static struct gl_memory_object *
|
||||
memoryobj_alloc(struct gl_context *ctx, GLuint name)
|
||||
{
|
||||
struct gl_memory_object *obj = CALLOC_STRUCT(gl_memory_object);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
obj->Name = name;
|
||||
obj->Dedicated = GL_FALSE;
|
||||
return obj;
|
||||
}
|
||||
|
||||
static void
|
||||
import_memoryobj_fd(struct gl_context *ctx,
|
||||
struct gl_memory_object *obj,
|
||||
GLuint64 size,
|
||||
int fd)
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
struct pipe_screen *screen = ctx->pipe->screen;
|
||||
struct winsys_handle whandle = {
|
||||
.type = WINSYS_HANDLE_TYPE_FD,
|
||||
.handle = fd,
|
||||
#ifdef HAVE_LIBDRM
|
||||
.modifier = DRM_FORMAT_MOD_INVALID,
|
||||
#endif
|
||||
};
|
||||
|
||||
obj->memory = screen->memobj_create_from_handle(screen,
|
||||
&whandle,
|
||||
obj->Dedicated);
|
||||
|
||||
/* We own fd, but we no longer need it. So get rid of it */
|
||||
close(fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a memory object.
|
||||
@@ -45,23 +88,12 @@ void
|
||||
_mesa_delete_memory_object(struct gl_context *ctx,
|
||||
struct gl_memory_object *memObj)
|
||||
{
|
||||
struct pipe_screen *screen = ctx->pipe->screen;
|
||||
if (memObj->memory)
|
||||
screen->memobj_destroy(screen, memObj->memory);
|
||||
FREE(memObj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize a buffer object to default values.
|
||||
*/
|
||||
void
|
||||
_mesa_initialize_memory_object(struct gl_context *ctx,
|
||||
struct gl_memory_object *obj,
|
||||
GLuint name)
|
||||
{
|
||||
memset(obj, 0, sizeof(struct gl_memory_object));
|
||||
obj->Name = name;
|
||||
obj->Dedicated = GL_FALSE;
|
||||
}
|
||||
|
||||
void GLAPIENTRY
|
||||
_mesa_DeleteMemoryObjectsEXT(GLsizei n, const GLuint *memoryObjects)
|
||||
{
|
||||
@@ -95,7 +127,7 @@ _mesa_DeleteMemoryObjectsEXT(GLsizei n, const GLuint *memoryObjects)
|
||||
if (delObj) {
|
||||
_mesa_HashRemoveLocked(ctx->Shared->MemoryObjects,
|
||||
memoryObjects[i]);
|
||||
st_memoryobj_free(ctx, delObj);
|
||||
_mesa_delete_memory_object(ctx, delObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,7 +180,7 @@ _mesa_CreateMemoryObjectsEXT(GLsizei n, GLuint *memoryObjects)
|
||||
struct gl_memory_object *memObj;
|
||||
|
||||
/* allocate memory object */
|
||||
memObj = st_memoryobj_alloc(ctx, memoryObjects[i]);
|
||||
memObj = memoryobj_alloc(ctx, memoryObjects[i]);
|
||||
if (!memObj) {
|
||||
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s()", func);
|
||||
_mesa_HashUnlockMutex(ctx->Shared->MemoryObjects);
|
||||
@@ -856,7 +888,7 @@ _mesa_ImportMemoryFdEXT(GLuint memory,
|
||||
if (!memObj)
|
||||
return;
|
||||
|
||||
st_import_memoryobj_fd(ctx, memObj, size, fd);
|
||||
import_memoryobj_fd(ctx, memObj, size, fd);
|
||||
memObj->Immutable = GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,10 +77,6 @@ _mesa_lookup_semaphore_object_locked(struct gl_context *ctx, GLuint semaphore)
|
||||
_mesa_HashLookupLocked(ctx->Shared->SemaphoreObjects, semaphore);
|
||||
}
|
||||
|
||||
extern void
|
||||
_mesa_initialize_memory_object(struct gl_context *ctx,
|
||||
struct gl_memory_object *obj,
|
||||
GLuint name);
|
||||
extern void
|
||||
_mesa_delete_memory_object(struct gl_context *ctx,
|
||||
struct gl_memory_object *semObj);
|
||||
|
||||
@@ -2869,6 +2869,11 @@ struct gl_memory_object
|
||||
GLuint Name; /**< hash table ID/name */
|
||||
GLboolean Immutable; /**< denotes mutability state of parameters */
|
||||
GLboolean Dedicated; /**< import memory from a dedicated allocation */
|
||||
|
||||
struct pipe_memory_object *memory;
|
||||
|
||||
/* TEXTURE_TILING_EXT param from gl_texture_object */
|
||||
GLuint TextureTiling;
|
||||
};
|
||||
|
||||
struct gl_semaphore_object
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "shared.h"
|
||||
#include "program/program.h"
|
||||
#include "dlist.h"
|
||||
#include "externalobjects.h"
|
||||
#include "samplerobj.h"
|
||||
#include "shaderapi.h"
|
||||
#include "shaderobj.h"
|
||||
@@ -45,7 +46,6 @@
|
||||
#include "util/set.h"
|
||||
#include "util/u_memory.h"
|
||||
|
||||
#include "state_tracker/st_cb_memoryobjects.h"
|
||||
#include "state_tracker/st_cb_semaphoreobjects.h"
|
||||
#include "state_tracker/st_cb_texture.h"
|
||||
#include "state_tracker/st_cb_program.h"
|
||||
@@ -318,7 +318,7 @@ delete_memory_object_cb(void *data, void *userData)
|
||||
{
|
||||
struct gl_memory_object *memObj = (struct gl_memory_object *) data;
|
||||
struct gl_context *ctx = (struct gl_context *) userData;
|
||||
st_memoryobj_free(ctx, memObj);
|
||||
_mesa_delete_memory_object(ctx, memObj);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -344,8 +344,6 @@ files_libmesa = files(
|
||||
'state_tracker/st_cb_feedback.h',
|
||||
'state_tracker/st_cb_flush.c',
|
||||
'state_tracker/st_cb_flush.h',
|
||||
'state_tracker/st_cb_memoryobjects.c',
|
||||
'state_tracker/st_cb_memoryobjects.h',
|
||||
'state_tracker/st_cb_perfmon.c',
|
||||
'state_tracker/st_cb_perfmon.h',
|
||||
'state_tracker/st_cb_perfquery.c',
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2017 Red Hat.
|
||||
* Copyright © 2017 Valve Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "main/mtypes.h"
|
||||
|
||||
#include "main/externalobjects.h"
|
||||
|
||||
#include "util/u_memory.h"
|
||||
#include "st_context.h"
|
||||
#include "st_cb_memoryobjects.h"
|
||||
#include "st_util.h"
|
||||
|
||||
#include "frontend/drm_driver.h"
|
||||
#include "pipe/p_context.h"
|
||||
#include "pipe/p_screen.h"
|
||||
|
||||
#ifdef HAVE_LIBDRM
|
||||
#include "drm-uapi/drm_fourcc.h"
|
||||
#endif
|
||||
|
||||
struct gl_memory_object *
|
||||
st_memoryobj_alloc(struct gl_context *ctx, GLuint name)
|
||||
{
|
||||
struct st_memory_object *st_obj = CALLOC_STRUCT(st_memory_object);
|
||||
if (!st_obj)
|
||||
return NULL;
|
||||
|
||||
_mesa_initialize_memory_object(ctx, &st_obj->Base, name);
|
||||
return &st_obj->Base;
|
||||
}
|
||||
|
||||
void
|
||||
st_memoryobj_free(struct gl_context *ctx,
|
||||
struct gl_memory_object *obj)
|
||||
{
|
||||
struct st_memory_object *st_obj = st_memory_object(obj);
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct pipe_screen *screen = st->screen;
|
||||
|
||||
if (st_obj->memory)
|
||||
screen->memobj_destroy(screen, st_obj->memory);
|
||||
_mesa_delete_memory_object(ctx, obj);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
st_import_memoryobj_fd(struct gl_context *ctx,
|
||||
struct gl_memory_object *obj,
|
||||
GLuint64 size,
|
||||
int fd)
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
struct st_memory_object *st_obj = st_memory_object(obj);
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct pipe_screen *screen = st->screen;
|
||||
struct winsys_handle whandle = {
|
||||
.type = WINSYS_HANDLE_TYPE_FD,
|
||||
.handle = fd,
|
||||
#ifdef HAVE_LIBDRM
|
||||
.modifier = DRM_FORMAT_MOD_INVALID,
|
||||
#endif
|
||||
};
|
||||
|
||||
st_obj->memory = screen->memobj_create_from_handle(screen,
|
||||
&whandle,
|
||||
obj->Dedicated);
|
||||
|
||||
/* We own fd, but we no longer need it. So get rid of it */
|
||||
close(fd);
|
||||
#endif
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2017 Red Hat.
|
||||
* Copyright © 2017 Valve Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef ST_CB_MEMORYOBJECTS_H
|
||||
#define ST_CB_MEMORYOBJECTS_H
|
||||
|
||||
#include "main/mtypes.h"
|
||||
|
||||
struct pipe_screen;
|
||||
|
||||
struct st_memory_object
|
||||
{
|
||||
struct gl_memory_object Base;
|
||||
struct pipe_memory_object *memory;
|
||||
|
||||
/* TEXTURE_TILING_EXT param from gl_texture_object */
|
||||
GLuint TextureTiling;
|
||||
};
|
||||
|
||||
static inline struct st_memory_object *
|
||||
st_memory_object(struct gl_memory_object *obj)
|
||||
{
|
||||
return (struct st_memory_object *)obj;
|
||||
}
|
||||
|
||||
struct gl_memory_object *
|
||||
st_memoryobj_alloc(struct gl_context *ctx, GLuint name);
|
||||
|
||||
void
|
||||
st_memoryobj_free(struct gl_context *ctx,
|
||||
struct gl_memory_object *obj);
|
||||
void
|
||||
st_import_memoryobj_fd(struct gl_context *ctx,
|
||||
struct gl_memory_object *obj,
|
||||
GLuint64 size,
|
||||
int fd);
|
||||
#endif
|
||||
@@ -56,7 +56,6 @@
|
||||
#include "state_tracker/st_cb_fbo.h"
|
||||
#include "state_tracker/st_cb_flush.h"
|
||||
#include "state_tracker/st_cb_texture.h"
|
||||
#include "state_tracker/st_cb_memoryobjects.h"
|
||||
#include "state_tracker/st_format.h"
|
||||
#include "state_tracker/st_pbo.h"
|
||||
#include "state_tracker/st_texture.h"
|
||||
@@ -3192,7 +3191,7 @@ st_finalize_texture(struct gl_context *ctx,
|
||||
*/
|
||||
static struct pipe_resource *
|
||||
st_texture_create_from_memory(struct st_context *st,
|
||||
struct st_memory_object *memObj,
|
||||
struct gl_memory_object *memObj,
|
||||
GLuint64 offset,
|
||||
enum pipe_texture_target target,
|
||||
enum pipe_format format,
|
||||
@@ -3264,7 +3263,6 @@ st_texture_storage(struct gl_context *ctx,
|
||||
struct gl_texture_image *texImage = texObj->Image[0][0];
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct st_texture_object *stObj = st_texture_object(texObj);
|
||||
struct st_memory_object *smObj = st_memory_object(memObj);
|
||||
struct pipe_screen *screen = st->screen;
|
||||
unsigned ptWidth, bindings;
|
||||
uint16_t ptHeight, ptDepth, ptLayers;
|
||||
@@ -3280,8 +3278,8 @@ st_texture_storage(struct gl_context *ctx,
|
||||
|
||||
bindings = default_bindings(st, fmt);
|
||||
|
||||
if (smObj) {
|
||||
smObj->TextureTiling = texObj->TextureTiling;
|
||||
if (memObj) {
|
||||
memObj->TextureTiling = texObj->TextureTiling;
|
||||
bindings |= PIPE_BIND_SHARED;
|
||||
}
|
||||
|
||||
@@ -3320,9 +3318,9 @@ st_texture_storage(struct gl_context *ctx,
|
||||
|
||||
pipe_resource_reference(&stObj->pt, NULL);
|
||||
|
||||
if (smObj) {
|
||||
if (memObj) {
|
||||
stObj->pt = st_texture_create_from_memory(st,
|
||||
smObj,
|
||||
memObj,
|
||||
offset,
|
||||
gl_target_to_pipe(texObj->Target),
|
||||
fmt,
|
||||
|
||||
Reference in New Issue
Block a user