2 * Copyright © 2017 Valve Corporation.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
30 #include "shaderimage.h"
33 #include "texturebindless.h"
35 #include "util/hash_table.h"
38 * Return the gl_texture_handle_object for a given 64-bit handle.
40 static struct gl_texture_handle_object
*
41 lookup_texture_handle(struct gl_context
*ctx
, GLuint64 id
)
43 struct gl_texture_handle_object
*texHandleObj
;
45 mtx_lock(&ctx
->Shared
->HandlesMutex
);
46 texHandleObj
= (struct gl_texture_handle_object
*)
47 _mesa_hash_table_u64_search(ctx
->Shared
->TextureHandles
, id
);
48 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
54 * Return the gl_image_handle_object for a given 64-bit handle.
56 static struct gl_image_handle_object
*
57 lookup_image_handle(struct gl_context
*ctx
, GLuint64 id
)
59 struct gl_image_handle_object
*imgHandleObj
;
61 mtx_lock(&ctx
->Shared
->HandlesMutex
);
62 imgHandleObj
= (struct gl_image_handle_object
*)
63 _mesa_hash_table_u64_search(ctx
->Shared
->ImageHandles
, id
);
64 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
70 * Delete a texture handle in the shared state.
73 delete_texture_handle(struct gl_context
*ctx
, GLuint64 id
)
75 mtx_lock(&ctx
->Shared
->HandlesMutex
);
76 _mesa_hash_table_u64_remove(ctx
->Shared
->TextureHandles
, id
);
77 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
79 ctx
->Driver
.DeleteTextureHandle(ctx
, id
);
83 * Delete an image handle in the shared state.
86 delete_image_handle(struct gl_context
*ctx
, GLuint64 id
)
88 mtx_lock(&ctx
->Shared
->HandlesMutex
);
89 _mesa_hash_table_u64_remove(ctx
->Shared
->ImageHandles
, id
);
90 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
92 ctx
->Driver
.DeleteImageHandle(ctx
, id
);
96 * Return TRUE if the texture handle is resident in the current context.
99 is_texture_handle_resident(struct gl_context
*ctx
, GLuint64 handle
)
101 return _mesa_hash_table_u64_search(ctx
->ResidentTextureHandles
,
106 * Return TRUE if the image handle is resident in the current context.
109 is_image_handle_resident(struct gl_context
*ctx
, GLuint64 handle
)
111 return _mesa_hash_table_u64_search(ctx
->ResidentImageHandles
,
116 * Make a texture handle resident/non-resident in the current context.
119 make_texture_handle_resident(struct gl_context
*ctx
,
120 struct gl_texture_handle_object
*texHandleObj
,
123 struct gl_sampler_object
*sampObj
= NULL
;
124 struct gl_texture_object
*texObj
= NULL
;
125 GLuint64 handle
= texHandleObj
->handle
;
128 assert(!is_texture_handle_resident(ctx
, handle
));
130 _mesa_hash_table_u64_insert(ctx
->ResidentTextureHandles
, handle
,
133 ctx
->Driver
.MakeTextureHandleResident(ctx
, handle
, GL_TRUE
);
135 /* Reference the texture object (and the separate sampler if needed) to
136 * be sure it won't be deleted until it is not bound anywhere and there
137 * are no handles using the object that are resident in any context.
139 _mesa_reference_texobj(&texObj
, texHandleObj
->texObj
);
140 if (texHandleObj
->sampObj
)
141 _mesa_reference_sampler_object(ctx
, &sampObj
, texHandleObj
->sampObj
);
143 assert(is_texture_handle_resident(ctx
, handle
));
145 _mesa_hash_table_u64_remove(ctx
->ResidentTextureHandles
, handle
);
147 ctx
->Driver
.MakeTextureHandleResident(ctx
, handle
, GL_FALSE
);
149 /* Unreference the texture object but keep the pointer intact, if
150 * refcount hits zero, the texture and all handles will be deleted.
152 texObj
= texHandleObj
->texObj
;
153 _mesa_reference_texobj(&texObj
, NULL
);
155 /* Unreference the separate sampler object but keep the pointer intact,
156 * if refcount hits zero, the sampler and all handles will be deleted.
158 if (texHandleObj
->sampObj
) {
159 sampObj
= texHandleObj
->sampObj
;
160 _mesa_reference_sampler_object(ctx
, &sampObj
, NULL
);
166 * Make an image handle resident/non-resident in the current context.
169 make_image_handle_resident(struct gl_context
*ctx
,
170 struct gl_image_handle_object
*imgHandleObj
,
171 GLenum access
, bool resident
)
173 struct gl_texture_object
*texObj
= NULL
;
174 GLuint64 handle
= imgHandleObj
->handle
;
177 assert(!is_image_handle_resident(ctx
, handle
));
179 _mesa_hash_table_u64_insert(ctx
->ResidentImageHandles
, handle
,
182 ctx
->Driver
.MakeImageHandleResident(ctx
, handle
, access
, GL_TRUE
);
184 /* Reference the texture object to be sure it won't be deleted until it
185 * is not bound anywhere and there are no handles using the object that
186 * are resident in any context.
188 _mesa_reference_texobj(&texObj
, imgHandleObj
->imgObj
.TexObj
);
190 assert(is_image_handle_resident(ctx
, handle
));
192 _mesa_hash_table_u64_remove(ctx
->ResidentImageHandles
, handle
);
194 ctx
->Driver
.MakeImageHandleResident(ctx
, handle
, access
, GL_FALSE
);
196 /* Unreference the texture object but keep the pointer intact, if
197 * refcount hits zero, the texture and all handles will be deleted.
199 texObj
= imgHandleObj
->imgObj
.TexObj
;
200 _mesa_reference_texobj(&texObj
, NULL
);
204 static struct gl_texture_handle_object
*
205 find_texhandleobj(struct gl_texture_object
*texObj
,
206 struct gl_sampler_object
*sampObj
)
208 util_dynarray_foreach(&texObj
->SamplerHandles
,
209 struct gl_texture_handle_object
*, texHandleObj
) {
210 if ((*texHandleObj
)->sampObj
== sampObj
)
211 return *texHandleObj
;
217 get_texture_handle(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
218 struct gl_sampler_object
*sampObj
)
220 bool separate_sampler
= &texObj
->Sampler
!= sampObj
;
221 struct gl_texture_handle_object
*texHandleObj
;
224 /* The ARB_bindless_texture spec says:
226 * "The handle for each texture or texture/sampler pair is unique; the same
227 * handle will be returned if GetTextureHandleARB is called multiple times
228 * for the same texture or if GetTextureSamplerHandleARB is called multiple
229 * times for the same texture/sampler pair."
231 mtx_lock(&ctx
->Shared
->HandlesMutex
);
232 texHandleObj
= find_texhandleobj(texObj
, separate_sampler
? sampObj
: NULL
);
234 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
235 return texHandleObj
->handle
;
238 /* Request a new texture handle from the driver. */
239 handle
= ctx
->Driver
.NewTextureHandle(ctx
, texObj
, sampObj
);
241 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
242 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexture*HandleARB()");
246 texHandleObj
= CALLOC_STRUCT(gl_texture_handle_object
);
248 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
249 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexture*HandleARB()");
253 /* Store the handle into the texture object. */
254 texHandleObj
->texObj
= texObj
;
255 texHandleObj
->sampObj
= separate_sampler
? sampObj
: NULL
;
256 texHandleObj
->handle
= handle
;
257 util_dynarray_append(&texObj
->SamplerHandles
,
258 struct gl_texture_handle_object
*, texHandleObj
);
260 if (separate_sampler
) {
261 /* Store the handle into the separate sampler if needed. */
262 util_dynarray_append(&sampObj
->Handles
,
263 struct gl_texture_handle_object
*, texHandleObj
);
266 /* When referenced by one or more handles, texture objects are immutable. */
267 texObj
->HandleAllocated
= true;
268 if (texObj
->Target
== GL_TEXTURE_BUFFER
)
269 texObj
->BufferObject
->HandleAllocated
= true;
270 sampObj
->HandleAllocated
= true;
272 /* Store the handle in the shared state for all contexts. */
273 _mesa_hash_table_u64_insert(ctx
->Shared
->TextureHandles
, handle
,
275 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
280 static struct gl_image_handle_object
*
281 find_imghandleobj(struct gl_texture_object
*texObj
, GLint level
,
282 GLboolean layered
, GLint layer
, GLenum format
)
284 util_dynarray_foreach(&texObj
->ImageHandles
,
285 struct gl_image_handle_object
*, imgHandleObj
) {
286 struct gl_image_unit
*u
= &(*imgHandleObj
)->imgObj
;
288 if (u
->TexObj
== texObj
&& u
->Level
== level
&& u
->Layered
== layered
&&
289 u
->Layer
== layer
&& u
->Format
== format
)
290 return *imgHandleObj
;
296 get_image_handle(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
297 GLint level
, GLboolean layered
, GLint layer
, GLenum format
)
299 struct gl_image_handle_object
*imgHandleObj
;
300 struct gl_image_unit imgObj
;
303 /* The ARB_bindless_texture spec says:
305 * "The handle returned for each combination of <texture>, <level>,
306 * <layered>, <layer>, and <format> is unique; the same handle will be
307 * returned if GetImageHandleARB is called multiple times with the same
310 mtx_lock(&ctx
->Shared
->HandlesMutex
);
311 imgHandleObj
= find_imghandleobj(texObj
, level
, layered
, layer
, format
);
313 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
314 return imgHandleObj
->handle
;
317 imgObj
.TexObj
= texObj
; /* weak reference */
318 imgObj
.Level
= level
;
319 imgObj
.Access
= GL_READ_WRITE
;
320 imgObj
.Format
= format
;
321 imgObj
._ActualFormat
= _mesa_get_shader_image_format(format
);
323 if (_mesa_tex_target_is_layered(texObj
->Target
)) {
324 imgObj
.Layered
= layered
;
325 imgObj
.Layer
= layer
;
326 imgObj
._Layer
= (imgObj
.Layered
? 0 : imgObj
.Layer
);
328 imgObj
.Layered
= GL_FALSE
;
332 /* Request a new image handle from the driver. */
333 handle
= ctx
->Driver
.NewImageHandle(ctx
, &imgObj
);
335 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
336 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetImageHandleARB()");
340 imgHandleObj
= CALLOC_STRUCT(gl_image_handle_object
);
342 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
343 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetImageHandleARB()");
347 /* Store the handle into the texture object. */
348 memcpy(&imgHandleObj
->imgObj
, &imgObj
, sizeof(struct gl_image_unit
));
349 imgHandleObj
->handle
= handle
;
350 util_dynarray_append(&texObj
->ImageHandles
,
351 struct gl_image_handle_object
*, imgHandleObj
);
353 /* When referenced by one or more handles, texture objects are immutable. */
354 texObj
->HandleAllocated
= true;
355 if (texObj
->Target
== GL_TEXTURE_BUFFER
)
356 texObj
->BufferObject
->HandleAllocated
= true;
357 texObj
->Sampler
.HandleAllocated
= true;
359 /* Store the handle in the shared state for all contexts. */
360 _mesa_hash_table_u64_insert(ctx
->Shared
->ImageHandles
, handle
, imgHandleObj
);
361 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
367 * Init/free per-context resident handles.
370 _mesa_init_resident_handles(struct gl_context
*ctx
)
372 ctx
->ResidentTextureHandles
= _mesa_hash_table_u64_create(NULL
);
373 ctx
->ResidentImageHandles
= _mesa_hash_table_u64_create(NULL
);
377 _mesa_free_resident_handles(struct gl_context
*ctx
)
379 _mesa_hash_table_u64_destroy(ctx
->ResidentTextureHandles
, NULL
);
380 _mesa_hash_table_u64_destroy(ctx
->ResidentImageHandles
, NULL
);
384 * Init/free shared allocated handles.
387 _mesa_init_shared_handles(struct gl_shared_state
*shared
)
389 shared
->TextureHandles
= _mesa_hash_table_u64_create(NULL
);
390 shared
->ImageHandles
= _mesa_hash_table_u64_create(NULL
);
391 mtx_init(&shared
->HandlesMutex
, mtx_recursive
);
395 _mesa_free_shared_handles(struct gl_shared_state
*shared
)
397 _mesa_hash_table_u64_destroy(shared
->TextureHandles
, NULL
);
398 _mesa_hash_table_u64_destroy(shared
->ImageHandles
, NULL
);
399 mtx_destroy(&shared
->HandlesMutex
);
403 * Init/free texture/image handles per-texture object.
406 _mesa_init_texture_handles(struct gl_texture_object
*texObj
)
408 util_dynarray_init(&texObj
->SamplerHandles
, NULL
);
409 util_dynarray_init(&texObj
->ImageHandles
, NULL
);
413 _mesa_make_texture_handles_non_resident(struct gl_context
*ctx
,
414 struct gl_texture_object
*texObj
)
416 mtx_lock(&ctx
->Shared
->HandlesMutex
);
418 /* Texture handles */
419 util_dynarray_foreach(&texObj
->SamplerHandles
,
420 struct gl_texture_handle_object
*, texHandleObj
) {
421 if (is_texture_handle_resident(ctx
, (*texHandleObj
)->handle
))
422 make_texture_handle_resident(ctx
, *texHandleObj
, false);
426 util_dynarray_foreach(&texObj
->ImageHandles
,
427 struct gl_image_handle_object
*, imgHandleObj
) {
428 if (is_image_handle_resident(ctx
, (*imgHandleObj
)->handle
))
429 make_image_handle_resident(ctx
, *imgHandleObj
, GL_READ_ONLY
, false);
432 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
436 _mesa_delete_texture_handles(struct gl_context
*ctx
,
437 struct gl_texture_object
*texObj
)
439 /* Texture handles */
440 util_dynarray_foreach(&texObj
->SamplerHandles
,
441 struct gl_texture_handle_object
*, texHandleObj
) {
442 struct gl_sampler_object
*sampObj
= (*texHandleObj
)->sampObj
;
445 /* Delete the handle in the separate sampler object. */
446 util_dynarray_delete_unordered(&sampObj
->Handles
,
447 struct gl_texture_handle_object
*,
450 delete_texture_handle(ctx
, (*texHandleObj
)->handle
);
453 util_dynarray_fini(&texObj
->SamplerHandles
);
456 util_dynarray_foreach(&texObj
->ImageHandles
,
457 struct gl_image_handle_object
*, imgHandleObj
) {
458 delete_image_handle(ctx
, (*imgHandleObj
)->handle
);
461 util_dynarray_fini(&texObj
->ImageHandles
);
465 * Init/free texture handles per-sampler object.
468 _mesa_init_sampler_handles(struct gl_sampler_object
*sampObj
)
470 util_dynarray_init(&sampObj
->Handles
, NULL
);
474 _mesa_delete_sampler_handles(struct gl_context
*ctx
,
475 struct gl_sampler_object
*sampObj
)
477 util_dynarray_foreach(&sampObj
->Handles
,
478 struct gl_texture_handle_object
*, texHandleObj
) {
479 struct gl_texture_object
*texObj
= (*texHandleObj
)->texObj
;
481 /* Delete the handle in the texture object. */
482 util_dynarray_delete_unordered(&texObj
->SamplerHandles
,
483 struct gl_texture_handle_object
*,
486 delete_texture_handle(ctx
, (*texHandleObj
)->handle
);
489 util_dynarray_fini(&sampObj
->Handles
);
493 is_sampler_border_color_valid(struct gl_sampler_object
*samp
)
495 static const GLfloat valid_float_border_colors
[4][4] = {
496 { 0.0, 0.0, 0.0, 0.0 },
497 { 0.0, 0.0, 0.0, 1.0 },
498 { 1.0, 1.0, 1.0, 0.0 },
499 { 1.0, 1.0, 1.0, 1.0 },
501 static const GLint valid_integer_border_colors
[4][4] = {
507 size_t size
= sizeof(samp
->BorderColor
.ui
);
509 /* The ARB_bindless_texture spec says:
511 * "The error INVALID_OPERATION is generated if the border color (taken from
512 * the embedded sampler for GetTextureHandleARB or from the <sampler> for
513 * GetTextureSamplerHandleARB) is not one of the following allowed values.
514 * If the texture's base internal format is signed or unsigned integer,
515 * allowed values are (0,0,0,0), (0,0,0,1), (1,1,1,0), and (1,1,1,1). If
516 * the base internal format is not integer, allowed values are
517 * (0.0,0.0,0.0,0.0), (0.0,0.0,0.0,1.0), (1.0,1.0,1.0,0.0), and
518 * (1.0,1.0,1.0,1.0)."
520 if (!memcmp(samp
->BorderColor
.f
, valid_float_border_colors
[0], size
) ||
521 !memcmp(samp
->BorderColor
.f
, valid_float_border_colors
[1], size
) ||
522 !memcmp(samp
->BorderColor
.f
, valid_float_border_colors
[2], size
) ||
523 !memcmp(samp
->BorderColor
.f
, valid_float_border_colors
[3], size
))
526 if (!memcmp(samp
->BorderColor
.ui
, valid_integer_border_colors
[0], size
) ||
527 !memcmp(samp
->BorderColor
.ui
, valid_integer_border_colors
[1], size
) ||
528 !memcmp(samp
->BorderColor
.ui
, valid_integer_border_colors
[2], size
) ||
529 !memcmp(samp
->BorderColor
.ui
, valid_integer_border_colors
[3], size
))
536 _mesa_GetTextureHandleARB_no_error(GLuint texture
)
538 struct gl_texture_object
*texObj
;
540 GET_CURRENT_CONTEXT(ctx
);
542 texObj
= _mesa_lookup_texture(ctx
, texture
);
543 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
))
544 _mesa_test_texobj_completeness(ctx
, texObj
);
546 return get_texture_handle(ctx
, texObj
, &texObj
->Sampler
);
550 _mesa_GetTextureHandleARB(GLuint texture
)
552 struct gl_texture_object
*texObj
= NULL
;
554 GET_CURRENT_CONTEXT(ctx
);
556 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
557 _mesa_error(ctx
, GL_INVALID_OPERATION
,
558 "glGetTextureHandleARB(unsupported)");
562 /* The ARB_bindless_texture spec says:
564 * "The error INVALID_VALUE is generated by GetTextureHandleARB or
565 * GetTextureSamplerHandleARB if <texture> is zero or not the name of an
566 * existing texture object."
569 texObj
= _mesa_lookup_texture(ctx
, texture
);
572 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetTextureHandleARB(texture)");
576 /* The ARB_bindless_texture spec says:
578 * "The error INVALID_OPERATION is generated by GetTextureHandleARB or
579 * GetTextureSamplerHandleARB if the texture object specified by <texture>
582 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
)) {
583 _mesa_test_texobj_completeness(ctx
, texObj
);
584 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
)) {
585 _mesa_error(ctx
, GL_INVALID_OPERATION
,
586 "glGetTextureHandleARB(incomplete texture)");
591 if (!is_sampler_border_color_valid(&texObj
->Sampler
)) {
592 _mesa_error(ctx
, GL_INVALID_OPERATION
,
593 "glGetTextureHandleARB(invalid border color)");
597 return get_texture_handle(ctx
, texObj
, &texObj
->Sampler
);
601 _mesa_GetTextureSamplerHandleARB_no_error(GLuint texture
, GLuint sampler
)
603 struct gl_texture_object
*texObj
;
604 struct gl_sampler_object
*sampObj
;
606 GET_CURRENT_CONTEXT(ctx
);
608 texObj
= _mesa_lookup_texture(ctx
, texture
);
609 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
611 if (!_mesa_is_texture_complete(texObj
, sampObj
))
612 _mesa_test_texobj_completeness(ctx
, texObj
);
614 return get_texture_handle(ctx
, texObj
, sampObj
);
618 _mesa_GetTextureSamplerHandleARB(GLuint texture
, GLuint sampler
)
620 struct gl_texture_object
*texObj
= NULL
;
621 struct gl_sampler_object
*sampObj
;
623 GET_CURRENT_CONTEXT(ctx
);
625 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
626 _mesa_error(ctx
, GL_INVALID_OPERATION
,
627 "glGetTextureSamplerHandleARB(unsupported)");
631 /* The ARB_bindless_texture spec says:
633 * "The error INVALID_VALUE is generated by GetTextureHandleARB or
634 * GetTextureSamplerHandleARB if <texture> is zero or not the name of an
635 * existing texture object."
638 texObj
= _mesa_lookup_texture(ctx
, texture
);
641 _mesa_error(ctx
, GL_INVALID_VALUE
,
642 "glGetTextureSamplerHandleARB(texture)");
646 /* The ARB_bindless_texture spec says:
648 * "The error INVALID_VALUE is generated by GetTextureSamplerHandleARB if
649 * <sampler> is zero or is not the name of an existing sampler object."
651 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
653 _mesa_error(ctx
, GL_INVALID_VALUE
,
654 "glGetTextureSamplerHandleARB(sampler)");
658 /* The ARB_bindless_texture spec says:
660 * "The error INVALID_OPERATION is generated by GetTextureHandleARB or
661 * GetTextureSamplerHandleARB if the texture object specified by <texture>
664 if (!_mesa_is_texture_complete(texObj
, sampObj
)) {
665 _mesa_test_texobj_completeness(ctx
, texObj
);
666 if (!_mesa_is_texture_complete(texObj
, sampObj
)) {
667 _mesa_error(ctx
, GL_INVALID_OPERATION
,
668 "glGetTextureSamplerHandleARB(incomplete texture)");
673 if (!is_sampler_border_color_valid(sampObj
)) {
674 _mesa_error(ctx
, GL_INVALID_OPERATION
,
675 "glGetTextureSamplerHandleARB(invalid border color)");
679 return get_texture_handle(ctx
, texObj
, sampObj
);
683 _mesa_MakeTextureHandleResidentARB_no_error(GLuint64 handle
)
685 struct gl_texture_handle_object
*texHandleObj
;
687 GET_CURRENT_CONTEXT(ctx
);
689 texHandleObj
= lookup_texture_handle(ctx
, handle
);
690 make_texture_handle_resident(ctx
, texHandleObj
, true);
694 _mesa_MakeTextureHandleResidentARB(GLuint64 handle
)
696 struct gl_texture_handle_object
*texHandleObj
;
698 GET_CURRENT_CONTEXT(ctx
);
700 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
701 _mesa_error(ctx
, GL_INVALID_OPERATION
,
702 "glMakeTextureHandleResidentARB(unsupported)");
706 /* The ARB_bindless_texture spec says:
708 * "The error INVALID_OPERATION is generated by MakeTextureHandleResidentARB
709 * if <handle> is not a valid texture handle, or if <handle> is already
710 * resident in the current GL context."
712 texHandleObj
= lookup_texture_handle(ctx
, handle
);
714 _mesa_error(ctx
, GL_INVALID_OPERATION
,
715 "glMakeTextureHandleResidentARB(handle)");
719 if (is_texture_handle_resident(ctx
, handle
)) {
720 _mesa_error(ctx
, GL_INVALID_OPERATION
,
721 "glMakeTextureHandleResidentARB(already resident)");
725 make_texture_handle_resident(ctx
, texHandleObj
, true);
729 _mesa_MakeTextureHandleNonResidentARB_no_error(GLuint64 handle
)
731 struct gl_texture_handle_object
*texHandleObj
;
733 GET_CURRENT_CONTEXT(ctx
);
735 texHandleObj
= lookup_texture_handle(ctx
, handle
);
736 make_texture_handle_resident(ctx
, texHandleObj
, false);
740 _mesa_MakeTextureHandleNonResidentARB(GLuint64 handle
)
742 struct gl_texture_handle_object
*texHandleObj
;
744 GET_CURRENT_CONTEXT(ctx
);
746 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
747 _mesa_error(ctx
, GL_INVALID_OPERATION
,
748 "glMakeTextureHandleNonResidentARB(unsupported)");
752 /* The ARB_bindless_texture spec says:
754 * "The error INVALID_OPERATION is generated by
755 * MakeTextureHandleNonResidentARB if <handle> is not a valid texture
756 * handle, or if <handle> is not resident in the current GL context."
758 texHandleObj
= lookup_texture_handle(ctx
, handle
);
760 _mesa_error(ctx
, GL_INVALID_OPERATION
,
761 "glMakeTextureHandleNonResidentARB(handle)");
765 if (!is_texture_handle_resident(ctx
, handle
)) {
766 _mesa_error(ctx
, GL_INVALID_OPERATION
,
767 "glMakeTextureHandleNonResidentARB(not resident)");
771 make_texture_handle_resident(ctx
, texHandleObj
, false);
775 _mesa_GetImageHandleARB_no_error(GLuint texture
, GLint level
, GLboolean layered
,
776 GLint layer
, GLenum format
)
778 struct gl_texture_object
*texObj
;
780 GET_CURRENT_CONTEXT(ctx
);
782 texObj
= _mesa_lookup_texture(ctx
, texture
);
783 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
))
784 _mesa_test_texobj_completeness(ctx
, texObj
);
786 return get_image_handle(ctx
, texObj
, level
, layered
, layer
, format
);
790 _mesa_GetImageHandleARB(GLuint texture
, GLint level
, GLboolean layered
,
791 GLint layer
, GLenum format
)
793 struct gl_texture_object
*texObj
= NULL
;
795 GET_CURRENT_CONTEXT(ctx
);
797 if (!_mesa_has_ARB_bindless_texture(ctx
) ||
798 !_mesa_has_ARB_shader_image_load_store(ctx
)) {
799 _mesa_error(ctx
, GL_INVALID_OPERATION
,
800 "glGetImageHandleARB(unsupported)");
804 /* The ARB_bindless_texture spec says:
806 * "The error INVALID_VALUE is generated by GetImageHandleARB if <texture>
807 * is zero or not the name of an existing texture object, if the image for
808 * <level> does not existing in <texture>, or if <layered> is FALSE and
809 * <layer> is greater than or equal to the number of layers in the image at
813 texObj
= _mesa_lookup_texture(ctx
, texture
);
816 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetImageHandleARB(texture)");
820 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
)) {
821 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetImageHandleARB(level)");
825 if (!layered
&& layer
> _mesa_get_texture_layers(texObj
, level
)) {
826 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetImageHandleARB(layer)");
830 if (!_mesa_is_shader_image_format_supported(ctx
, format
)) {
831 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetImageHandleARB(format)");
835 /* The ARB_bindless_texture spec says:
837 * "The error INVALID_OPERATION is generated by GetImageHandleARB if the
838 * texture object <texture> is not complete or if <layered> is TRUE and
839 * <texture> is not a three-dimensional, one-dimensional array, two
840 * dimensional array, cube map, or cube map array texture."
842 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
)) {
843 _mesa_test_texobj_completeness(ctx
, texObj
);
844 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
)) {
845 _mesa_error(ctx
, GL_INVALID_OPERATION
,
846 "glGetImageHandleARB(incomplete texture)");
851 if (layered
&& !_mesa_tex_target_is_layered(texObj
->Target
)) {
852 _mesa_error(ctx
, GL_INVALID_OPERATION
,
853 "glGetImageHandleARB(not layered)");
857 return get_image_handle(ctx
, texObj
, level
, layered
, layer
, format
);
861 _mesa_MakeImageHandleResidentARB_no_error(GLuint64 handle
, GLenum access
)
863 struct gl_image_handle_object
*imgHandleObj
;
865 GET_CURRENT_CONTEXT(ctx
);
867 imgHandleObj
= lookup_image_handle(ctx
, handle
);
868 make_image_handle_resident(ctx
, imgHandleObj
, access
, true);
872 _mesa_MakeImageHandleResidentARB(GLuint64 handle
, GLenum access
)
874 struct gl_image_handle_object
*imgHandleObj
;
876 GET_CURRENT_CONTEXT(ctx
);
878 if (!_mesa_has_ARB_bindless_texture(ctx
) ||
879 !_mesa_has_ARB_shader_image_load_store(ctx
)) {
880 _mesa_error(ctx
, GL_INVALID_OPERATION
,
881 "glMakeImageHandleResidentARB(unsupported)");
885 if (access
!= GL_READ_ONLY
&&
886 access
!= GL_WRITE_ONLY
&&
887 access
!= GL_READ_WRITE
) {
888 _mesa_error(ctx
, GL_INVALID_ENUM
,
889 "glMakeImageHandleResidentARB(access)");
893 /* The ARB_bindless_texture spec says:
895 * "The error INVALID_OPERATION is generated by MakeImageHandleResidentARB
896 * if <handle> is not a valid image handle, or if <handle> is already
897 * resident in the current GL context."
899 imgHandleObj
= lookup_image_handle(ctx
, handle
);
901 _mesa_error(ctx
, GL_INVALID_OPERATION
,
902 "glMakeImageHandleResidentARB(handle)");
906 if (is_image_handle_resident(ctx
, handle
)) {
907 _mesa_error(ctx
, GL_INVALID_OPERATION
,
908 "glMakeImageHandleResidentARB(already resident)");
912 make_image_handle_resident(ctx
, imgHandleObj
, access
, true);
916 _mesa_MakeImageHandleNonResidentARB_no_error(GLuint64 handle
)
918 struct gl_image_handle_object
*imgHandleObj
;
920 GET_CURRENT_CONTEXT(ctx
);
922 imgHandleObj
= lookup_image_handle(ctx
, handle
);
923 make_image_handle_resident(ctx
, imgHandleObj
, GL_READ_ONLY
, false);
927 _mesa_MakeImageHandleNonResidentARB(GLuint64 handle
)
929 struct gl_image_handle_object
*imgHandleObj
;
931 GET_CURRENT_CONTEXT(ctx
);
933 if (!_mesa_has_ARB_bindless_texture(ctx
) ||
934 !_mesa_has_ARB_shader_image_load_store(ctx
)) {
935 _mesa_error(ctx
, GL_INVALID_OPERATION
,
936 "glMakeImageHandleNonResidentARB(unsupported)");
940 /* The ARB_bindless_texture spec says:
942 * "The error INVALID_OPERATION is generated by
943 * MakeImageHandleNonResidentARB if <handle> is not a valid image handle,
944 * or if <handle> is not resident in the current GL context."
946 imgHandleObj
= lookup_image_handle(ctx
, handle
);
948 _mesa_error(ctx
, GL_INVALID_OPERATION
,
949 "glMakeImageHandleNonResidentARB(handle)");
953 if (!is_image_handle_resident(ctx
, handle
)) {
954 _mesa_error(ctx
, GL_INVALID_OPERATION
,
955 "glMakeImageHandleNonResidentARB(not resident)");
959 make_image_handle_resident(ctx
, imgHandleObj
, GL_READ_ONLY
, false);
963 _mesa_IsTextureHandleResidentARB_no_error(GLuint64 handle
)
965 GET_CURRENT_CONTEXT(ctx
);
966 return is_texture_handle_resident(ctx
, handle
);
970 _mesa_IsTextureHandleResidentARB(GLuint64 handle
)
972 GET_CURRENT_CONTEXT(ctx
);
974 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
975 _mesa_error(ctx
, GL_INVALID_OPERATION
,
976 "glIsTextureHandleResidentARB(unsupported)");
980 /* The ARB_bindless_texture spec says:
982 * "The error INVALID_OPERATION will be generated by
983 * IsTextureHandleResidentARB and IsImageHandleResidentARB if <handle> is
984 * not a valid texture or image handle, respectively."
986 if (!lookup_texture_handle(ctx
, handle
)) {
987 _mesa_error(ctx
, GL_INVALID_OPERATION
,
988 "glIsTextureHandleResidentARB(handle)");
992 return is_texture_handle_resident(ctx
, handle
);
996 _mesa_IsImageHandleResidentARB_no_error(GLuint64 handle
)
998 GET_CURRENT_CONTEXT(ctx
);
999 return is_image_handle_resident(ctx
, handle
);
1002 GLboolean GLAPIENTRY
1003 _mesa_IsImageHandleResidentARB(GLuint64 handle
)
1005 GET_CURRENT_CONTEXT(ctx
);
1007 if (!_mesa_has_ARB_bindless_texture(ctx
) ||
1008 !_mesa_has_ARB_shader_image_load_store(ctx
)) {
1009 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1010 "glIsImageHandleResidentARB(unsupported)");
1014 /* The ARB_bindless_texture spec says:
1016 * "The error INVALID_OPERATION will be generated by
1017 * IsTextureHandleResidentARB and IsImageHandleResidentARB if <handle> is
1018 * not a valid texture or image handle, respectively."
1020 if (!lookup_image_handle(ctx
, handle
)) {
1021 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1022 "glIsImageHandleResidentARB(handle)");
1026 return is_image_handle_resident(ctx
, handle
);