i965: Initial implementation for EXT_memory_object_*
Signed-off-by: Rohan Garg <rohan.garg@collabora.com> Reviewed-by: Eleni Maria Stea <estea@igalia.com> Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5594>
This commit is contained in:
parent
62b51bb43b
commit
f73aeca0ce
|
@ -127,4 +127,15 @@ brw_buffer_object(struct gl_buffer_object *obj)
|
|||
return (struct brw_buffer_object *) obj;
|
||||
}
|
||||
|
||||
struct brw_memory_object {
|
||||
struct gl_memory_object Base;
|
||||
struct brw_bo *bo;
|
||||
};
|
||||
|
||||
static inline struct brw_memory_object *
|
||||
brw_memory_object(struct gl_memory_object *obj)
|
||||
{
|
||||
return (struct brw_memory_object *)obj;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "main/stencil.h"
|
||||
#include "main/state.h"
|
||||
#include "main/spirv_extensions.h"
|
||||
#include "main/externalobjects.h"
|
||||
|
||||
#include "vbo/vbo.h"
|
||||
|
||||
|
@ -158,6 +159,29 @@ brw_set_background_context(struct gl_context *ctx,
|
|||
backgroundCallable->setBackgroundContext(driContext->loaderPrivate);
|
||||
}
|
||||
|
||||
static void
|
||||
brw_delete_memoryobj(struct gl_context *ctx, struct gl_memory_object *memObj)
|
||||
{
|
||||
struct brw_memory_object *memory_object = brw_memory_object(memObj);
|
||||
brw_bo_unreference(memory_object->bo);
|
||||
_mesa_delete_memory_object(ctx, memObj);
|
||||
}
|
||||
|
||||
static void
|
||||
brw_import_memoryobj_fd(struct gl_context *ctx,
|
||||
struct gl_memory_object *obj,
|
||||
GLuint64 size,
|
||||
int fd)
|
||||
{
|
||||
struct brw_context *brw = brw_context(ctx);
|
||||
struct brw_memory_object *memory_object = brw_memory_object(obj);
|
||||
|
||||
memory_object->bo = brw_bo_gem_create_from_prime(brw->bufmgr, fd);
|
||||
brw_bo_reference(memory_object->bo);
|
||||
assert(memory_object->bo->size >= size);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
brw_viewport(struct gl_context *ctx)
|
||||
{
|
||||
|
@ -437,6 +461,8 @@ brw_init_driver_functions(struct brw_context *brw,
|
|||
|
||||
functions->SetBackgroundContext = brw_set_background_context;
|
||||
|
||||
functions->DeleteMemoryObject = brw_delete_memoryobj;
|
||||
functions->ImportMemoryObjectFd = brw_import_memoryobj_fd;
|
||||
functions->GetDeviceUuid = brw_get_device_uuid;
|
||||
functions->GetDriverUuid = brw_get_driver_uuid;
|
||||
}
|
||||
|
|
|
@ -197,6 +197,7 @@ brw_isl_format_for_mesa_format(mesa_format mesa_format)
|
|||
[MESA_FORMAT_RGBX_UNORM16] = ISL_FORMAT_R16G16B16X16_UNORM,
|
||||
[MESA_FORMAT_RGBX_FLOAT16] = ISL_FORMAT_R16G16B16X16_FLOAT,
|
||||
[MESA_FORMAT_RGBX_FLOAT32] = ISL_FORMAT_R32G32B32X32_FLOAT,
|
||||
[MESA_FORMAT_Z_UNORM16] = ISL_FORMAT_R16_UNORM,
|
||||
};
|
||||
|
||||
assert(mesa_format < MESA_FORMAT_COUNT);
|
||||
|
@ -224,6 +225,12 @@ brw_screen_init_surface_formats(struct brw_screen *screen)
|
|||
|
||||
render = texture = brw_isl_format_for_mesa_format(format);
|
||||
|
||||
/* Only exposed with EXT_memory_object_* support which
|
||||
* is not for older gens.
|
||||
*/
|
||||
if (gen < 70 && format == MESA_FORMAT_Z_UNORM16)
|
||||
continue;
|
||||
|
||||
if (texture == ISL_FORMAT_UNSUPPORTED)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "brw_mipmap_tree.h"
|
||||
#include "brw_tex.h"
|
||||
#include "brw_fbo.h"
|
||||
#include "brw_state.h"
|
||||
#include "util/u_memory.h"
|
||||
|
||||
#define FILE_DEBUG_FLAG DEBUG_TEXTURE
|
||||
|
@ -321,6 +322,77 @@ brw_texture_barrier(struct gl_context *ctx)
|
|||
}
|
||||
}
|
||||
|
||||
/* Return the usual surface usage flags for the given format. */
|
||||
static isl_surf_usage_flags_t
|
||||
isl_surf_usage(mesa_format format)
|
||||
{
|
||||
switch(_mesa_get_format_base_format(format)) {
|
||||
case GL_DEPTH_COMPONENT:
|
||||
return ISL_SURF_USAGE_DEPTH_BIT | ISL_SURF_USAGE_TEXTURE_BIT;
|
||||
case GL_DEPTH_STENCIL:
|
||||
return ISL_SURF_USAGE_DEPTH_BIT | ISL_SURF_USAGE_STENCIL_BIT |
|
||||
ISL_SURF_USAGE_TEXTURE_BIT;
|
||||
case GL_STENCIL_INDEX:
|
||||
return ISL_SURF_USAGE_STENCIL_BIT | ISL_SURF_USAGE_TEXTURE_BIT;
|
||||
default:
|
||||
return ISL_SURF_USAGE_RENDER_TARGET_BIT | ISL_SURF_USAGE_TEXTURE_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
static GLboolean
|
||||
intel_texture_for_memory_object(struct gl_context *ctx,
|
||||
struct gl_texture_object *tex_obj,
|
||||
struct gl_memory_object *mem_obj,
|
||||
GLsizei levels, GLsizei width,
|
||||
GLsizei height, GLsizei depth,
|
||||
GLuint64 offset)
|
||||
{
|
||||
struct brw_context *brw = brw_context(ctx);
|
||||
struct brw_memory_object *intel_memobj = brw_memory_object(mem_obj);
|
||||
struct brw_texture_object *intel_texobj = brw_texture_object(tex_obj);
|
||||
struct gl_texture_image *image = tex_obj->Image[0][0];
|
||||
struct isl_surf surf;
|
||||
|
||||
isl_tiling_flags_t tiling_flags = ISL_TILING_ANY_MASK;
|
||||
if (tex_obj->TextureTiling == GL_LINEAR_TILING_EXT)
|
||||
tiling_flags = ISL_TILING_LINEAR_BIT;
|
||||
|
||||
UNUSED const bool isl_surf_created_successfully =
|
||||
isl_surf_init(&brw->screen->isl_dev, &surf,
|
||||
.dim = get_isl_surf_dim(tex_obj->Target),
|
||||
.format = brw_isl_format_for_mesa_format(image->TexFormat),
|
||||
.width = width,
|
||||
.height = height,
|
||||
.depth = depth,
|
||||
.levels = levels,
|
||||
.array_len = tex_obj->Target == GL_TEXTURE_3D ? 1 : depth,
|
||||
.samples = MAX2(image->NumSamples, 1),
|
||||
.usage = isl_surf_usage(image->TexFormat),
|
||||
.tiling_flags = tiling_flags);
|
||||
|
||||
assert(isl_surf_created_successfully);
|
||||
|
||||
intel_texobj->mt = brw_miptree_create_for_bo(brw,
|
||||
intel_memobj->bo,
|
||||
image->TexFormat,
|
||||
offset,
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
surf.row_pitch_B,
|
||||
surf.tiling,
|
||||
MIPTREE_CREATE_NO_AUX);
|
||||
assert(intel_texobj->mt);
|
||||
brw_alloc_texture_image_buffer(ctx, image);
|
||||
|
||||
intel_texobj->needs_validate = false;
|
||||
intel_texobj->validated_first_level = 0;
|
||||
intel_texobj->validated_last_level = levels - 1;
|
||||
intel_texobj->_Format = image->TexFormat;
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
brw_init_texture_functions(struct dd_function_table *functions)
|
||||
{
|
||||
|
@ -335,4 +407,5 @@ brw_init_texture_functions(struct dd_function_table *functions)
|
|||
functions->UnmapTextureImage = brw_unmap_texture_image;
|
||||
functions->TextureView = brw_texture_view;
|
||||
functions->TextureBarrier = brw_texture_barrier;
|
||||
functions->SetTextureStorageForMemoryObject = intel_texture_for_memory_object;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue