mesa/st: merge texture obj/image alloc/free into mesa

This just drops the st wrappers for alloc/free of texture images
and objects.

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:
Dave Airlie 2021-12-21 14:59:00 +10:00
parent cd0961dce2
commit 4b8d84f71a
8 changed files with 70 additions and 117 deletions

View File

@ -41,6 +41,7 @@
#include "pack.h"
#include "pbo.h"
#include "teximage.h"
#include "texobj.h"
#include "varray.h"
#include "glthread_marshal.h"
@ -835,7 +836,7 @@ void
_mesa_delete_bitmap_atlas(struct gl_context *ctx, struct gl_bitmap_atlas *atlas)
{
if (atlas->texObj) {
st_DeleteTextureObject(ctx, atlas->texObj);
_mesa_delete_texture_object(ctx, atlas->texObj);
}
free(atlas->glyphs);
free(atlas);
@ -979,7 +980,7 @@ build_bitmap_atlas(struct gl_context *ctx, struct gl_bitmap_atlas *atlas,
}
/* Create atlas texture (texture ID is irrelevant) */
atlas->texObj = st_NewTextureObject(ctx, 999, GL_TEXTURE_RECTANGLE);
atlas->texObj = _mesa_new_texture_object(ctx, 999, GL_TEXTURE_RECTANGLE);
if (!atlas->texObj) {
goto out_of_memory;
}
@ -1058,7 +1059,7 @@ out_of_memory:
_mesa_error(ctx, GL_OUT_OF_MEMORY, "Display list bitmap atlas");
fail:
if (atlas->texObj) {
st_DeleteTextureObject(ctx, atlas->texObj);
_mesa_delete_texture_object(ctx, atlas->texObj);
}
free(atlas->glyphs);
atlas->glyphs = NULL;

View File

@ -40,13 +40,13 @@
#include "shaderapi.h"
#include "shaderobj.h"
#include "syncobj.h"
#include "texobj.h"
#include "texturebindless.h"
#include "util/hash_table.h"
#include "util/set.h"
#include "util/u_memory.h"
#include "state_tracker/st_cb_texture.h"
#include "state_tracker/st_cb_program.h"
static void
@ -120,7 +120,7 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
GL_TEXTURE_1D
};
STATIC_ASSERT(ARRAY_SIZE(targets) == NUM_TEXTURE_TARGETS);
shared->DefaultTex[i] = st_NewTextureObject(ctx, 0, targets[i]);
shared->DefaultTex[i] = _mesa_new_texture_object(ctx, 0, targets[i]);
/* Need to explicitly set/overwrite the TargetIndex field here since
* the call to _mesa_tex_target_to_index() in NewTextureObject() may
* fail if the texture target is not supported.
@ -180,7 +180,7 @@ delete_texture_cb(void *data, void *userData)
{
struct gl_texture_object *texObj = (struct gl_texture_object *) data;
struct gl_context *ctx = (struct gl_context *) userData;
st_DeleteTextureObject(ctx, texObj);
_mesa_delete_texture_object(ctx, texObj);
}
@ -351,7 +351,7 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared)
/* Free the dummy/fallback texture objects */
for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
if (shared->FallbackTex[i])
st_DeleteTextureObject(ctx, shared->FallbackTex[i]);
_mesa_delete_texture_object(ctx, shared->FallbackTex[i]);
}
/*
@ -437,7 +437,7 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared)
/* the default textures */
for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
if (shared->DefaultTex[i])
st_DeleteTextureObject(ctx, shared->DefaultTex[i]);
_mesa_delete_texture_object(ctx, shared->DefaultTex[i]);
}
/* all other textures */

View File

@ -394,7 +394,7 @@ _mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj,
texImage = _mesa_select_tex_image(texObj, target, level);
if (!texImage) {
texImage = st_NewTextureImage(ctx);
texImage = CALLOC_STRUCT(gl_texture_image);
if (!texImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation");
return NULL;
@ -461,7 +461,7 @@ get_proxy_tex_image(struct gl_context *ctx, GLenum target, GLint level)
texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level];
if (!texImage) {
texImage = st_NewTextureImage(ctx);
texImage = CALLOC_STRUCT(gl_texture_image);
if (!texImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
return NULL;
@ -2934,7 +2934,7 @@ lookup_texture_ext_dsa(struct gl_context *ctx, GLenum target, GLuint texture,
}
if (!texObj) {
texObj = st_NewTextureObject(ctx, texture, boundTarget);
texObj = _mesa_new_texture_object(ctx, texture, boundTarget);
if (!texObj) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
return NULL;

View File

@ -45,11 +45,14 @@
#include "program/prog_instruction.h"
#include "texturebindless.h"
#include "util/u_memory.h"
#include "util/u_inlines.h"
#include "api_exec_decl.h"
#include "state_tracker/st_cb_texture.h"
#include "state_tracker/st_format.h"
#include "state_tracker/st_cb_flush.h"
#include "state_tracker/st_texture.h"
#include "state_tracker/st_sampler_view.h"
/**********************************************************************/
/** \name Internal functions */
@ -258,39 +261,13 @@ _mesa_get_texobj_by_target_and_texunit(struct gl_context *ctx, GLenum target,
}
/**
* Allocate and initialize a new texture object. But don't put it into the
* texture object hash table.
*
* \param shared the shared GL state structure to contain the texture object
* \param name integer name for the texture object
* \param target either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
* GL_TEXTURE_CUBE_MAP or GL_TEXTURE_RECTANGLE_NV. zero is ok for the sake
* of GenTextures()
*
* \return pointer to new texture object.
*/
struct gl_texture_object *
_mesa_new_texture_object(struct gl_context *ctx, GLuint name, GLenum target)
{
struct gl_texture_object *obj;
obj = MALLOC_STRUCT(gl_texture_object);
if (!obj)
return NULL;
_mesa_initialize_texture_object(ctx, obj, name, target);
return obj;
}
/**
* Initialize a new texture object to default values.
* \param obj the texture object
* \param name the texture name
* \param target the texture target
*/
void
static bool
_mesa_initialize_texture_object( struct gl_context *ctx,
struct gl_texture_object *obj,
GLuint name, GLenum target )
@ -385,8 +362,50 @@ _mesa_initialize_texture_object( struct gl_context *ctx,
/* GL_ARB_bindless_texture */
_mesa_init_texture_handles(obj);
obj->level_override = -1;
obj->layer_override = -1;
simple_mtx_init(&obj->validate_mutex, mtx_plain);
obj->needs_validation = true;
/* Pre-allocate a sampler views container to save a branch in the
* fast path.
*/
obj->sampler_views = calloc(1, sizeof(struct st_sampler_views)
+ sizeof(struct st_sampler_view));
if (!obj->sampler_views) {
return false;
}
obj->sampler_views->max = 1;
return true;
}
/**
* Allocate and initialize a new texture object. But don't put it into the
* texture object hash table.
*
* \param shared the shared GL state structure to contain the texture object
* \param name integer name for the texture object
* \param target either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
* GL_TEXTURE_CUBE_MAP or GL_TEXTURE_RECTANGLE_NV. zero is ok for the sake
* of GenTextures()
*
* \return pointer to new texture object.
*/
struct gl_texture_object *
_mesa_new_texture_object(struct gl_context *ctx, GLuint name, GLenum target)
{
struct gl_texture_object *obj;
obj = MALLOC_STRUCT(gl_texture_object);
if (!obj)
return NULL;
if (!_mesa_initialize_texture_object(ctx, obj, name, target)) {
free(obj);
return NULL;
}
return obj;
}
/**
* Some texture initialization can't be finished until we know which
@ -456,11 +475,15 @@ _mesa_delete_texture_object(struct gl_context *ctx,
*/
texObj->Target = 0x99;
pipe_resource_reference(&texObj->pt, NULL);
st_delete_texture_sampler_views(ctx->st, texObj);
simple_mtx_destroy(&texObj->validate_mutex);
/* free the texture images */
for (face = 0; face < 6; face++) {
for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
if (texObj->Image[face][i]) {
st_DeleteTextureImage(ctx, texObj->Image[face][i]);
_mesa_delete_texture_image(ctx, texObj->Image[face][i]);
}
}
}
@ -567,7 +590,7 @@ _mesa_reference_texobj_(struct gl_texture_object **ptr,
*/
GET_CURRENT_CONTEXT(ctx);
if (ctx)
st_DeleteTextureObject(ctx, oldTex);
_mesa_delete_texture_object(ctx, oldTex);
else
_mesa_problem(NULL, "Unable to delete texture, no context");
}
@ -987,7 +1010,7 @@ _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex)
}
/* create texture object */
texObj = st_NewTextureObject(ctx, 0, target);
texObj = _mesa_new_texture_object(ctx, 0, target);
if (!texObj)
return NULL;
@ -1187,7 +1210,7 @@ create_textures(struct gl_context *ctx, GLenum target,
/* Allocate new, empty texture objects */
for (i = 0; i < n; i++) {
struct gl_texture_object *texObj;
texObj = st_NewTextureObject(ctx, textures[i], target);
texObj = _mesa_new_texture_object(ctx, textures[i], target);
if (!texObj) {
_mesa_HashUnlockMutex(ctx->Shared->TexObjects);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
@ -1675,7 +1698,7 @@ _mesa_lookup_or_create_texture(struct gl_context *ctx, GLenum target,
}
/* if this is a new texture id, allocate a texture object now */
newTexObj = st_NewTextureObject(ctx, texName, target);
newTexObj = _mesa_new_texture_object(ctx, texName, target);
if (!newTexObj) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
return NULL;

View File

@ -67,11 +67,6 @@ _mesa_get_texobj_by_target_and_texunit(struct gl_context *ctx, GLenum target,
extern struct gl_texture_object *
_mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target );
extern void
_mesa_initialize_texture_object( struct gl_context *ctx,
struct gl_texture_object *obj,
GLuint name, GLenum target );
extern int
_mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target);

View File

@ -1007,10 +1007,10 @@ alloc_proxy_textures( struct gl_context *ctx )
for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
if (!(ctx->Texture.ProxyTex[tgt]
= st_NewTextureObject(ctx, 0, targets[tgt]))) {
= _mesa_new_texture_object(ctx, 0, targets[tgt]))) {
/* out of memory, free what we did allocate */
while (--tgt >= 0) {
st_DeleteTextureObject(ctx, ctx->Texture.ProxyTex[tgt]);
_mesa_delete_texture_object(ctx, ctx->Texture.ProxyTex[tgt]);
}
return GL_FALSE;
}
@ -1134,7 +1134,7 @@ _mesa_free_texture_data(struct gl_context *ctx)
/* Free proxy texture objects */
for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++)
st_DeleteTextureObject(ctx, ctx->Texture.ProxyTex[tgt]);
_mesa_delete_texture_object(ctx, ctx->Texture.ProxyTex[tgt]);
/* GL_ARB_texture_buffer_object */
_mesa_reference_buffer_object(ctx, &ctx->Texture.BufferObject, NULL);

View File

@ -386,66 +386,6 @@ st_pbo_get_dst_format(struct gl_context *ctx, enum pipe_texture_target target,
return dst_format;
}
struct gl_texture_image *
st_NewTextureImage(struct gl_context * ctx)
{
DBG("%s\n", __func__);
(void) ctx;
return (struct gl_texture_image *) CALLOC_STRUCT(gl_texture_image);
}
void
st_DeleteTextureImage(struct gl_context * ctx, struct gl_texture_image *img)
{
/* nothing special (yet) for st_texture_image */
_mesa_delete_texture_image(ctx, img);
}
struct gl_texture_object *
st_NewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
{
struct gl_texture_object *obj = CALLOC_STRUCT(gl_texture_object);
if (!obj)
return NULL;
obj->level_override = -1;
obj->layer_override = -1;
/* Pre-allocate a sampler views container to save a branch in the
* fast path.
*/
obj->sampler_views = calloc(1, sizeof(struct st_sampler_views)
+ sizeof(struct st_sampler_view));
if (!obj->sampler_views) {
free(obj);
return NULL;
}
obj->sampler_views->max = 1;
DBG("%s\n", __func__);
_mesa_initialize_texture_object(ctx, obj, name, target);
simple_mtx_init(&obj->validate_mutex, mtx_plain);
obj->needs_validation = true;
return obj;
}
void
st_DeleteTextureObject(struct gl_context *ctx,
struct gl_texture_object *texObj)
{
struct st_context *st = st_context(ctx);
pipe_resource_reference(&texObj->pt, NULL);
st_delete_texture_sampler_views(st, texObj);
simple_mtx_destroy(&texObj->validate_mutex);
_mesa_delete_texture_object(ctx, texObj);
}
/**
* Called via ctx->Driver.TextureRemovedFromShared()
* When texture is removed from ctx->Shared->TexObjects we lose

View File

@ -55,12 +55,6 @@ st_finalize_texture(struct gl_context *ctx,
struct gl_texture_object *tObj,
GLuint cubeMapFace);
struct gl_texture_image *st_NewTextureImage(struct gl_context *ctx);
void st_DeleteTextureImage(struct gl_context *ctx, struct gl_texture_image *img);
struct gl_texture_object *st_NewTextureObject(struct gl_context *ctx,
GLuint name, GLenum target);
void st_DeleteTextureObject(struct gl_context *ctx,
struct gl_texture_object *texObj);
void st_TextureReleaseAllSamplerViews(struct gl_context *ctx,
struct gl_texture_object *texObj);
void st_FreeTextureImageBuffer(struct gl_context *ctx,