Re: [Mesa-dev] [RFC PATCH 02/65] mesa: implement ARB_bindless_texture
On 26.05.2017 14:09, Samuel Pitoiset wrote: On 05/24/2017 12:10 PM, Nicolai Hähnle wrote: [snip] +static GLuint64 +get_texture_handle(struct gl_context *ctx, struct gl_texture_object *texObj, + struct gl_sampler_object *sampObj) +{ + struct gl_texture_handle_object *handleObj; + struct hash_entry *entry; + GLuint64 handle; + + handleObj = CALLOC_STRUCT(gl_texture_handle_object); + if (!handleObj) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexture*HandleARB()"); + return 0; + } + + handleObj->texObj = texObj; + if (>Sampler != sampObj) + handleObj->sampObj = sampObj; + + /* The ARB_bindless_texture spec says: +* +* "The handle for each texture or texture/sampler pair is unique; the same +* handle will be returned if GetTextureHandleARB is called multiple times +* for the same texture or if GetTextureSamplerHandleARB is called multiple +* times for the same texture/sampler pair." +*/ + mtx_lock(>Shared->HandlesMutex); + entry = _mesa_hash_table_search(texObj->SamplerHandles, handleObj); + if (entry) { + mtx_unlock(>Shared->HandlesMutex); + free(handleObj); + return (uint64_t)entry->data; + } + + /* Ask the driver for a new handle and store it. */ + handle = ctx->Driver.NewTextureHandle(ctx, texObj, sampObj); + if (!handle) { + mtx_unlock(>Shared->HandlesMutex); + free(handleObj); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexture*HandleARB()"); + return 0; + } + + _mesa_hash_table_insert(texObj->SamplerHandles, handleObj, (void *)handle); + + if (>Sampler != sampObj) { + _mesa_hash_table_insert(sampObj->Handles, handleObj, + (void *)handle); + } + + /* When referenced by one or more handles, texture objects are immutable. */ + texObj->HandleAllocated = true; + sampObj->HandleAllocated = true; + if (texObj->Target == GL_TEXTURE_BUFFER) + texObj->BufferObject->HandleAllocated = true; + + /* Store the handle in the shared state for all contexts. */ + _mesa_hash_table_insert(ctx->Shared->TextureHandles, + (void *)handle, handleObj); This won't work on 32-bit systems (same for image handles). Because the handle is 64-bit? Mmh... Right. [snip] +void +_mesa_make_texture_handles_non_resident(struct gl_context *ctx, +struct gl_texture_object *texObj) +{ + struct hash_entry *entry; + GLuint64 handle; + + mtx_lock(>Shared->HandlesMutex); + + hash_table_foreach(texObj->SamplerHandles, entry) { + struct gl_texture_handle_object *handleObj = + (struct gl_texture_handle_object *)entry->key; + + handle = (uint64_t)entry->data; + if (is_texture_handle_resident(ctx, handle)) + make_texture_handle_resident(ctx, handleObj, handle, false); + } + + hash_table_foreach(texObj->ImageHandles, entry) { + struct gl_image_handle_object *handleObj = + (struct gl_image_handle_object *)entry->key; + + handle = (uint64_t)entry->data; + if (is_image_handle_resident(ctx, handle)) + make_image_handle_resident(ctx, handleObj, handle, GL_READ_ONLY, false); + } So... this also needs to loop through all other contexts and make the handle non-resident in them, right? Otherwise you might end up with dangling pointers (or at least dangling handles). No. Resident handles are per-context. Though, I'm not very happy myself with the way I managed the handles. I'm open to any better suggestions. Right, resident handles are per-context, but the handles of a texture might be resident in multiple contexts simultaneously. What happens if they are, and then the texture object is deleted? The ARB_bindless_texture spec says: (7) What happens if you try to delete a texture or sampler object with a handle that is resident in another context? RESOLVED: Deleting the texture will remove the texture from the name space and make all handles using the texture non-resident in the current context. However, texture or image handles for a deleted texture are not deleted until the underlying texture or sampler object itself is deleted. That deletion won't happen until the object is not bound anywhere and there are no handles using the object that are resident in any context. Currently, my implementation does exactly this. I think the app should handle this. You're right, I missed that. This part is fine. Cheers, Nicolai It seems to me that right now, you end up with dangling resident handles in the "other" contexts. At the very least, this can cause incorrect errors when the handle is re-used by the driver for another texture, so *something* needs to loop over all contexts, it seems... Cheers, Nicolai -- Lerne, wie die Welt wirklich ist, Aber vergiss niemals, wie sie sein sollte. ___ mesa-dev mailing list
Re: [Mesa-dev] [RFC PATCH 02/65] mesa: implement ARB_bindless_texture
On 05/24/2017 12:10 PM, Nicolai Hähnle wrote: [snip] +static GLuint64 +get_texture_handle(struct gl_context *ctx, struct gl_texture_object *texObj, + struct gl_sampler_object *sampObj) +{ + struct gl_texture_handle_object *handleObj; + struct hash_entry *entry; + GLuint64 handle; + + handleObj = CALLOC_STRUCT(gl_texture_handle_object); + if (!handleObj) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexture*HandleARB()"); + return 0; + } + + handleObj->texObj = texObj; + if (>Sampler != sampObj) + handleObj->sampObj = sampObj; + + /* The ARB_bindless_texture spec says: +* +* "The handle for each texture or texture/sampler pair is unique; the same +* handle will be returned if GetTextureHandleARB is called multiple times +* for the same texture or if GetTextureSamplerHandleARB is called multiple +* times for the same texture/sampler pair." +*/ + mtx_lock(>Shared->HandlesMutex); + entry = _mesa_hash_table_search(texObj->SamplerHandles, handleObj); + if (entry) { + mtx_unlock(>Shared->HandlesMutex); + free(handleObj); + return (uint64_t)entry->data; + } + + /* Ask the driver for a new handle and store it. */ + handle = ctx->Driver.NewTextureHandle(ctx, texObj, sampObj); + if (!handle) { + mtx_unlock(>Shared->HandlesMutex); + free(handleObj); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexture*HandleARB()"); + return 0; + } + + _mesa_hash_table_insert(texObj->SamplerHandles, handleObj, (void *)handle); + + if (>Sampler != sampObj) { + _mesa_hash_table_insert(sampObj->Handles, handleObj, + (void *)handle); + } + + /* When referenced by one or more handles, texture objects are immutable. */ + texObj->HandleAllocated = true; + sampObj->HandleAllocated = true; + if (texObj->Target == GL_TEXTURE_BUFFER) + texObj->BufferObject->HandleAllocated = true; + + /* Store the handle in the shared state for all contexts. */ + _mesa_hash_table_insert(ctx->Shared->TextureHandles, + (void *)handle, handleObj); This won't work on 32-bit systems (same for image handles). Because the handle is 64-bit? Mmh... Right. [snip] +void +_mesa_make_texture_handles_non_resident(struct gl_context *ctx, +struct gl_texture_object *texObj) +{ + struct hash_entry *entry; + GLuint64 handle; + + mtx_lock(>Shared->HandlesMutex); + + hash_table_foreach(texObj->SamplerHandles, entry) { + struct gl_texture_handle_object *handleObj = + (struct gl_texture_handle_object *)entry->key; + + handle = (uint64_t)entry->data; + if (is_texture_handle_resident(ctx, handle)) + make_texture_handle_resident(ctx, handleObj, handle, false); + } + + hash_table_foreach(texObj->ImageHandles, entry) { + struct gl_image_handle_object *handleObj = + (struct gl_image_handle_object *)entry->key; + + handle = (uint64_t)entry->data; + if (is_image_handle_resident(ctx, handle)) + make_image_handle_resident(ctx, handleObj, handle, GL_READ_ONLY, false); + } So... this also needs to loop through all other contexts and make the handle non-resident in them, right? Otherwise you might end up with dangling pointers (or at least dangling handles). No. Resident handles are per-context. Though, I'm not very happy myself with the way I managed the handles. I'm open to any better suggestions. Right, resident handles are per-context, but the handles of a texture might be resident in multiple contexts simultaneously. What happens if they are, and then the texture object is deleted? The ARB_bindless_texture spec says: (7) What happens if you try to delete a texture or sampler object with a handle that is resident in another context? RESOLVED: Deleting the texture will remove the texture from the name space and make all handles using the texture non-resident in the current context. However, texture or image handles for a deleted texture are not deleted until the underlying texture or sampler object itself is deleted. That deletion won't happen until the object is not bound anywhere and there are no handles using the object that are resident in any context. Currently, my implementation does exactly this. I think the app should handle this. It seems to me that right now, you end up with dangling resident handles in the "other" contexts. At the very least, this can cause incorrect errors when the handle is re-used by the driver for another texture, so *something* needs to loop over all contexts, it seems... Cheers, Nicolai ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [RFC PATCH 02/65] mesa: implement ARB_bindless_texture
[snip] +static GLuint64 +get_texture_handle(struct gl_context *ctx, struct gl_texture_object *texObj, + struct gl_sampler_object *sampObj) +{ + struct gl_texture_handle_object *handleObj; + struct hash_entry *entry; + GLuint64 handle; + + handleObj = CALLOC_STRUCT(gl_texture_handle_object); + if (!handleObj) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexture*HandleARB()"); + return 0; + } + + handleObj->texObj = texObj; + if (>Sampler != sampObj) + handleObj->sampObj = sampObj; + + /* The ARB_bindless_texture spec says: +* +* "The handle for each texture or texture/sampler pair is unique; the same +* handle will be returned if GetTextureHandleARB is called multiple times +* for the same texture or if GetTextureSamplerHandleARB is called multiple +* times for the same texture/sampler pair." +*/ + mtx_lock(>Shared->HandlesMutex); + entry = _mesa_hash_table_search(texObj->SamplerHandles, handleObj); + if (entry) { + mtx_unlock(>Shared->HandlesMutex); + free(handleObj); + return (uint64_t)entry->data; + } + + /* Ask the driver for a new handle and store it. */ + handle = ctx->Driver.NewTextureHandle(ctx, texObj, sampObj); + if (!handle) { + mtx_unlock(>Shared->HandlesMutex); + free(handleObj); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexture*HandleARB()"); + return 0; + } + + _mesa_hash_table_insert(texObj->SamplerHandles, handleObj, (void *)handle); + + if (>Sampler != sampObj) { + _mesa_hash_table_insert(sampObj->Handles, handleObj, + (void *)handle); + } + + /* When referenced by one or more handles, texture objects are immutable. */ + texObj->HandleAllocated = true; + sampObj->HandleAllocated = true; + if (texObj->Target == GL_TEXTURE_BUFFER) + texObj->BufferObject->HandleAllocated = true; + + /* Store the handle in the shared state for all contexts. */ + _mesa_hash_table_insert(ctx->Shared->TextureHandles, + (void *)handle, handleObj); This won't work on 32-bit systems (same for image handles). Because the handle is 64-bit? Mmh... Right. [snip] +void +_mesa_make_texture_handles_non_resident(struct gl_context *ctx, +struct gl_texture_object *texObj) +{ + struct hash_entry *entry; + GLuint64 handle; + + mtx_lock(>Shared->HandlesMutex); + + hash_table_foreach(texObj->SamplerHandles, entry) { + struct gl_texture_handle_object *handleObj = + (struct gl_texture_handle_object *)entry->key; + + handle = (uint64_t)entry->data; + if (is_texture_handle_resident(ctx, handle)) + make_texture_handle_resident(ctx, handleObj, handle, false); + } + + hash_table_foreach(texObj->ImageHandles, entry) { + struct gl_image_handle_object *handleObj = + (struct gl_image_handle_object *)entry->key; + + handle = (uint64_t)entry->data; + if (is_image_handle_resident(ctx, handle)) + make_image_handle_resident(ctx, handleObj, handle, GL_READ_ONLY, false); + } So... this also needs to loop through all other contexts and make the handle non-resident in them, right? Otherwise you might end up with dangling pointers (or at least dangling handles). No. Resident handles are per-context. Though, I'm not very happy myself with the way I managed the handles. I'm open to any better suggestions. Right, resident handles are per-context, but the handles of a texture might be resident in multiple contexts simultaneously. What happens if they are, and then the texture object is deleted? It seems to me that right now, you end up with dangling resident handles in the "other" contexts. At the very least, this can cause incorrect errors when the handle is re-used by the driver for another texture, so *something* needs to loop over all contexts, it seems... Cheers, Nicolai -- Lerne, wie die Welt wirklich ist, Aber vergiss niemals, wie sie sein sollte. ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [RFC PATCH 02/65] mesa: implement ARB_bindless_texture
On 05/22/2017 12:43 PM, Nicolai Hähnle wrote: On 19.05.2017 18:52, Samuel Pitoiset wrote: Signed-off-by: Samuel Pitoiset--- src/mesa/main/context.c | 3 + src/mesa/main/dd.h | 17 + src/mesa/main/mtypes.h | 34 ++ src/mesa/main/samplerobj.c | 6 + src/mesa/main/shared.c | 12 + src/mesa/main/texobj.c | 12 + src/mesa/main/texturebindless.c | 827 +++- src/mesa/main/texturebindless.h | 28 ++ 8 files changed, 934 insertions(+), 5 deletions(-) diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 3570f94f5a..5321886a95 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -133,6 +133,7 @@ #include "varray.h" #include "version.h" #include "viewport.h" +#include "texturebindless.h" #include "program/program.h" #include "math/m_matrix.h" #include "main/dispatch.h" /* for _gloffset_COUNT */ @@ -855,6 +856,7 @@ init_attrib_groups(struct gl_context *ctx) _mesa_init_transform_feedback( ctx ); _mesa_init_varray( ctx ); _mesa_init_viewport( ctx ); + _mesa_init_resident_handles( ctx ); if (!_mesa_init_texture( ctx )) return GL_FALSE; @@ -1339,6 +1341,7 @@ _mesa_free_context_data( struct gl_context *ctx ) _mesa_free_transform_feedback(ctx); _mesa_free_performance_monitors(ctx); _mesa_free_performance_queries(ctx); + _mesa_free_resident_handles(ctx); _mesa_reference_buffer_object(ctx, >Pack.BufferObj, NULL); _mesa_reference_buffer_object(ctx, >Unpack.BufferObj, NULL); diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index a9ca43d69e..d830f5184d 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -1050,6 +1050,23 @@ struct dd_function_table { GLintptr offset, GLsizeiptr size, GLboolean commit); /*@}*/ + + /** +* \name GL_ARB_bindless_texture interface +*/ + /*@{*/ + GLuint64 (*NewTextureHandle)(struct gl_context *ctx, +struct gl_texture_object *texObj, +struct gl_sampler_object *sampObj); + void (*DeleteTextureHandle)(struct gl_context *ctx, GLuint64 handle); + void (*MakeTextureHandleResident)(struct gl_context *ctx, GLuint64 handle, + bool resident); + GLuint64 (*NewImageHandle)(struct gl_context *ctx, + struct gl_image_unit *imgObj); + void (*DeleteImageHandle)(struct gl_context *ctx, GLuint64 handle); + void (*MakeImageHandleResident)(struct gl_context *ctx, GLuint64 handle, + GLenum access, bool resident); + /*@}*/ }; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index efc6920254..70865b373d 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -987,6 +987,9 @@ struct gl_sampler_object GLenum CompareFunc;/**< GL_ARB_shadow */ GLenum sRGBDecode; /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */ GLboolean CubeMapSeamless; /**< GL_AMD_seamless_cubemap_per_texture */ + bool HandleAllocated;/**< GL_ARB_bindless_texture */ + + struct hash_table *Handles; }; @@ -1034,6 +1037,8 @@ struct gl_texture_object GLuint NumLevels; /**< GL_ARB_texture_view */ GLuint NumLayers; /**< GL_ARB_texture_view */ + GLboolean HandleAllocated; /**< GL_ARB_bindless_texture */ + /** Actual texture images, indexed by [cube face] and [mipmap level] */ struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS]; @@ -1051,6 +1056,10 @@ struct gl_texture_object /** GL_ARB_shader_image_load_store */ GLenum ImageFormatCompatibilityType; + + /** GL_ARB_bindless_texture */ + struct hash_table *SamplerHandles; + struct hash_table *ImageHandles; }; @@ -1390,6 +1399,7 @@ struct gl_buffer_object GLboolean Written; /**< Ever written to? (for debugging) */ GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */ GLboolean Immutable; /**< GL_ARB_buffer_storage */ + GLboolean HandleAllocated; /**< GL_ARB_bindless_texture */ Should be consistent with gl_sampler_object in terms of type (and gl_texture_object as well). Which type? Since the state is not API-visible, bool is justifiable. Correct. gl_buffer_usage UsageHistory; /**< How has this buffer been used so far? */ /** Counters used for buffer usage warnings */ @@ -3203,6 +3213,11 @@ struct gl_shared_state /** GL_ARB_sampler_objects */ struct _mesa_HashTable *SamplerObjects; + /* GL_ARB_bindless_texture */ + struct hash_table *TextureHandles; + struct hash_table *ImageHandles; + mtx_t HandlesMutex; /**< For texture/image handles safety */ + /** * Some context in this share group was affected by a GPU reset * @@ -4488,6 +4503,17 @@ struct gl_subroutine_index_binding GLuint *IndexPtr; };
Re: [Mesa-dev] [RFC PATCH 02/65] mesa: implement ARB_bindless_texture
On 19.05.2017 18:52, Samuel Pitoiset wrote: Signed-off-by: Samuel Pitoiset--- src/mesa/main/context.c | 3 + src/mesa/main/dd.h | 17 + src/mesa/main/mtypes.h | 34 ++ src/mesa/main/samplerobj.c | 6 + src/mesa/main/shared.c | 12 + src/mesa/main/texobj.c | 12 + src/mesa/main/texturebindless.c | 827 +++- src/mesa/main/texturebindless.h | 28 ++ 8 files changed, 934 insertions(+), 5 deletions(-) diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 3570f94f5a..5321886a95 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -133,6 +133,7 @@ #include "varray.h" #include "version.h" #include "viewport.h" +#include "texturebindless.h" #include "program/program.h" #include "math/m_matrix.h" #include "main/dispatch.h" /* for _gloffset_COUNT */ @@ -855,6 +856,7 @@ init_attrib_groups(struct gl_context *ctx) _mesa_init_transform_feedback( ctx ); _mesa_init_varray( ctx ); _mesa_init_viewport( ctx ); + _mesa_init_resident_handles( ctx ); if (!_mesa_init_texture( ctx )) return GL_FALSE; @@ -1339,6 +1341,7 @@ _mesa_free_context_data( struct gl_context *ctx ) _mesa_free_transform_feedback(ctx); _mesa_free_performance_monitors(ctx); _mesa_free_performance_queries(ctx); + _mesa_free_resident_handles(ctx); _mesa_reference_buffer_object(ctx, >Pack.BufferObj, NULL); _mesa_reference_buffer_object(ctx, >Unpack.BufferObj, NULL); diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index a9ca43d69e..d830f5184d 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -1050,6 +1050,23 @@ struct dd_function_table { GLintptr offset, GLsizeiptr size, GLboolean commit); /*@}*/ + + /** +* \name GL_ARB_bindless_texture interface +*/ + /*@{*/ + GLuint64 (*NewTextureHandle)(struct gl_context *ctx, +struct gl_texture_object *texObj, +struct gl_sampler_object *sampObj); + void (*DeleteTextureHandle)(struct gl_context *ctx, GLuint64 handle); + void (*MakeTextureHandleResident)(struct gl_context *ctx, GLuint64 handle, + bool resident); + GLuint64 (*NewImageHandle)(struct gl_context *ctx, + struct gl_image_unit *imgObj); + void (*DeleteImageHandle)(struct gl_context *ctx, GLuint64 handle); + void (*MakeImageHandleResident)(struct gl_context *ctx, GLuint64 handle, + GLenum access, bool resident); + /*@}*/ }; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index efc6920254..70865b373d 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -987,6 +987,9 @@ struct gl_sampler_object GLenum CompareFunc; /**< GL_ARB_shadow */ GLenum sRGBDecode; /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */ GLboolean CubeMapSeamless; /**< GL_AMD_seamless_cubemap_per_texture */ + bool HandleAllocated;/**< GL_ARB_bindless_texture */ + + struct hash_table *Handles; }; @@ -1034,6 +1037,8 @@ struct gl_texture_object GLuint NumLevels; /**< GL_ARB_texture_view */ GLuint NumLayers; /**< GL_ARB_texture_view */ + GLboolean HandleAllocated; /**< GL_ARB_bindless_texture */ + /** Actual texture images, indexed by [cube face] and [mipmap level] */ struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS]; @@ -1051,6 +1056,10 @@ struct gl_texture_object /** GL_ARB_shader_image_load_store */ GLenum ImageFormatCompatibilityType; + + /** GL_ARB_bindless_texture */ + struct hash_table *SamplerHandles; + struct hash_table *ImageHandles; }; @@ -1390,6 +1399,7 @@ struct gl_buffer_object GLboolean Written; /**< Ever written to? (for debugging) */ GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */ GLboolean Immutable; /**< GL_ARB_buffer_storage */ + GLboolean HandleAllocated; /**< GL_ARB_bindless_texture */ Should be consistent with gl_sampler_object in terms of type (and gl_texture_object as well). Which type? Since the state is not API-visible, bool is justifiable. gl_buffer_usage UsageHistory; /**< How has this buffer been used so far? */ /** Counters used for buffer usage warnings */ @@ -3203,6 +3213,11 @@ struct gl_shared_state /** GL_ARB_sampler_objects */ struct _mesa_HashTable *SamplerObjects; + /* GL_ARB_bindless_texture */ + struct hash_table *TextureHandles; + struct hash_table *ImageHandles; + mtx_t HandlesMutex; /**< For texture/image handles safety */ + /** * Some context in this share group was affected by a GPU reset * @@ -4488,6 +4503,17 @@ struct gl_subroutine_index_binding GLuint *IndexPtr; }; +struct gl_texture_handle_object +{ + struct gl_texture_object *texObj; +
[Mesa-dev] [RFC PATCH 02/65] mesa: implement ARB_bindless_texture
Signed-off-by: Samuel Pitoiset--- src/mesa/main/context.c | 3 + src/mesa/main/dd.h | 17 + src/mesa/main/mtypes.h | 34 ++ src/mesa/main/samplerobj.c | 6 + src/mesa/main/shared.c | 12 + src/mesa/main/texobj.c | 12 + src/mesa/main/texturebindless.c | 827 +++- src/mesa/main/texturebindless.h | 28 ++ 8 files changed, 934 insertions(+), 5 deletions(-) diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 3570f94f5a..5321886a95 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -133,6 +133,7 @@ #include "varray.h" #include "version.h" #include "viewport.h" +#include "texturebindless.h" #include "program/program.h" #include "math/m_matrix.h" #include "main/dispatch.h" /* for _gloffset_COUNT */ @@ -855,6 +856,7 @@ init_attrib_groups(struct gl_context *ctx) _mesa_init_transform_feedback( ctx ); _mesa_init_varray( ctx ); _mesa_init_viewport( ctx ); + _mesa_init_resident_handles( ctx ); if (!_mesa_init_texture( ctx )) return GL_FALSE; @@ -1339,6 +1341,7 @@ _mesa_free_context_data( struct gl_context *ctx ) _mesa_free_transform_feedback(ctx); _mesa_free_performance_monitors(ctx); _mesa_free_performance_queries(ctx); + _mesa_free_resident_handles(ctx); _mesa_reference_buffer_object(ctx, >Pack.BufferObj, NULL); _mesa_reference_buffer_object(ctx, >Unpack.BufferObj, NULL); diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index a9ca43d69e..d830f5184d 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -1050,6 +1050,23 @@ struct dd_function_table { GLintptr offset, GLsizeiptr size, GLboolean commit); /*@}*/ + + /** +* \name GL_ARB_bindless_texture interface +*/ + /*@{*/ + GLuint64 (*NewTextureHandle)(struct gl_context *ctx, +struct gl_texture_object *texObj, +struct gl_sampler_object *sampObj); + void (*DeleteTextureHandle)(struct gl_context *ctx, GLuint64 handle); + void (*MakeTextureHandleResident)(struct gl_context *ctx, GLuint64 handle, + bool resident); + GLuint64 (*NewImageHandle)(struct gl_context *ctx, + struct gl_image_unit *imgObj); + void (*DeleteImageHandle)(struct gl_context *ctx, GLuint64 handle); + void (*MakeImageHandleResident)(struct gl_context *ctx, GLuint64 handle, + GLenum access, bool resident); + /*@}*/ }; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index efc6920254..70865b373d 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -987,6 +987,9 @@ struct gl_sampler_object GLenum CompareFunc; /**< GL_ARB_shadow */ GLenum sRGBDecode; /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */ GLboolean CubeMapSeamless; /**< GL_AMD_seamless_cubemap_per_texture */ + bool HandleAllocated;/**< GL_ARB_bindless_texture */ + + struct hash_table *Handles; }; @@ -1034,6 +1037,8 @@ struct gl_texture_object GLuint NumLevels; /**< GL_ARB_texture_view */ GLuint NumLayers; /**< GL_ARB_texture_view */ + GLboolean HandleAllocated; /**< GL_ARB_bindless_texture */ + /** Actual texture images, indexed by [cube face] and [mipmap level] */ struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS]; @@ -1051,6 +1056,10 @@ struct gl_texture_object /** GL_ARB_shader_image_load_store */ GLenum ImageFormatCompatibilityType; + + /** GL_ARB_bindless_texture */ + struct hash_table *SamplerHandles; + struct hash_table *ImageHandles; }; @@ -1390,6 +1399,7 @@ struct gl_buffer_object GLboolean Written; /**< Ever written to? (for debugging) */ GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */ GLboolean Immutable; /**< GL_ARB_buffer_storage */ + GLboolean HandleAllocated; /**< GL_ARB_bindless_texture */ gl_buffer_usage UsageHistory; /**< How has this buffer been used so far? */ /** Counters used for buffer usage warnings */ @@ -3203,6 +3213,11 @@ struct gl_shared_state /** GL_ARB_sampler_objects */ struct _mesa_HashTable *SamplerObjects; + /* GL_ARB_bindless_texture */ + struct hash_table *TextureHandles; + struct hash_table *ImageHandles; + mtx_t HandlesMutex; /**< For texture/image handles safety */ + /** * Some context in this share group was affected by a GPU reset * @@ -4488,6 +4503,17 @@ struct gl_subroutine_index_binding GLuint *IndexPtr; }; +struct gl_texture_handle_object +{ + struct gl_texture_object *texObj; + struct gl_sampler_object *sampObj; +}; + +struct gl_image_handle_object +{ + struct gl_image_unit imgObj; +}; + /** * Mesa rendering context. * @@ -4842,6 +4868,14 @@ struct gl_context GLfloat