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"
36 #include "util/u_memory.h"
39 * Return the gl_texture_handle_object for a given 64-bit handle.
41 static struct gl_texture_handle_object
*
42 lookup_texture_handle(struct gl_context
*ctx
, GLuint64 id
)
44 struct gl_texture_handle_object
*texHandleObj
;
46 mtx_lock(&ctx
->Shared
->HandlesMutex
);
47 texHandleObj
= (struct gl_texture_handle_object
*)
48 _mesa_hash_table_u64_search(ctx
->Shared
->TextureHandles
, id
);
49 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
55 * Return the gl_image_handle_object for a given 64-bit handle.
57 static struct gl_image_handle_object
*
58 lookup_image_handle(struct gl_context
*ctx
, GLuint64 id
)
60 struct gl_image_handle_object
*imgHandleObj
;
62 mtx_lock(&ctx
->Shared
->HandlesMutex
);
63 imgHandleObj
= (struct gl_image_handle_object
*)
64 _mesa_hash_table_u64_search(ctx
->Shared
->ImageHandles
, id
);
65 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
71 * Delete a texture handle in the shared state.
74 delete_texture_handle(struct gl_context
*ctx
, GLuint64 id
)
76 mtx_lock(&ctx
->Shared
->HandlesMutex
);
77 _mesa_hash_table_u64_remove(ctx
->Shared
->TextureHandles
, id
);
78 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
80 ctx
->Driver
.DeleteTextureHandle(ctx
, id
);
84 * Delete an image handle in the shared state.
87 delete_image_handle(struct gl_context
*ctx
, GLuint64 id
)
89 mtx_lock(&ctx
->Shared
->HandlesMutex
);
90 _mesa_hash_table_u64_remove(ctx
->Shared
->ImageHandles
, id
);
91 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
93 ctx
->Driver
.DeleteImageHandle(ctx
, id
);
97 * Return TRUE if the texture handle is resident in the current context.
100 is_texture_handle_resident(struct gl_context
*ctx
, GLuint64 handle
)
102 return _mesa_hash_table_u64_search(ctx
->ResidentTextureHandles
,
107 * Return TRUE if the image handle is resident in the current context.
110 is_image_handle_resident(struct gl_context
*ctx
, GLuint64 handle
)
112 return _mesa_hash_table_u64_search(ctx
->ResidentImageHandles
,
117 * Make a texture handle resident/non-resident in the current context.
120 make_texture_handle_resident(struct gl_context
*ctx
,
121 struct gl_texture_handle_object
*texHandleObj
,
124 struct gl_sampler_object
*sampObj
= NULL
;
125 struct gl_texture_object
*texObj
= NULL
;
126 GLuint64 handle
= texHandleObj
->handle
;
129 assert(!is_texture_handle_resident(ctx
, handle
));
131 _mesa_hash_table_u64_insert(ctx
->ResidentTextureHandles
, handle
,
134 ctx
->Driver
.MakeTextureHandleResident(ctx
, handle
, GL_TRUE
);
136 /* Reference the texture object (and the separate sampler if needed) to
137 * be sure it won't be deleted until it is not bound anywhere and there
138 * are no handles using the object that are resident in any context.
140 _mesa_reference_texobj(&texObj
, texHandleObj
->texObj
);
141 if (texHandleObj
->sampObj
)
142 _mesa_reference_sampler_object(ctx
, &sampObj
, texHandleObj
->sampObj
);
144 assert(is_texture_handle_resident(ctx
, handle
));
146 _mesa_hash_table_u64_remove(ctx
->ResidentTextureHandles
, handle
);
148 ctx
->Driver
.MakeTextureHandleResident(ctx
, handle
, GL_FALSE
);
150 /* Unreference the texture object but keep the pointer intact, if
151 * refcount hits zero, the texture and all handles will be deleted.
153 texObj
= texHandleObj
->texObj
;
154 _mesa_reference_texobj(&texObj
, NULL
);
156 /* Unreference the separate sampler object but keep the pointer intact,
157 * if refcount hits zero, the sampler and all handles will be deleted.
159 if (texHandleObj
->sampObj
) {
160 sampObj
= texHandleObj
->sampObj
;
161 _mesa_reference_sampler_object(ctx
, &sampObj
, NULL
);
167 * Make an image handle resident/non-resident in the current context.
170 make_image_handle_resident(struct gl_context
*ctx
,
171 struct gl_image_handle_object
*imgHandleObj
,
172 GLenum access
, bool resident
)
174 struct gl_texture_object
*texObj
= NULL
;
175 GLuint64 handle
= imgHandleObj
->handle
;
178 assert(!is_image_handle_resident(ctx
, handle
));
180 _mesa_hash_table_u64_insert(ctx
->ResidentImageHandles
, handle
,
183 ctx
->Driver
.MakeImageHandleResident(ctx
, handle
, access
, GL_TRUE
);
185 /* Reference the texture object to be sure it won't be deleted until it
186 * is not bound anywhere and there are no handles using the object that
187 * are resident in any context.
189 _mesa_reference_texobj(&texObj
, imgHandleObj
->imgObj
.TexObj
);
191 assert(is_image_handle_resident(ctx
, handle
));
193 _mesa_hash_table_u64_remove(ctx
->ResidentImageHandles
, handle
);
195 ctx
->Driver
.MakeImageHandleResident(ctx
, handle
, access
, GL_FALSE
);
197 /* Unreference the texture object but keep the pointer intact, if
198 * refcount hits zero, the texture and all handles will be deleted.
200 texObj
= imgHandleObj
->imgObj
.TexObj
;
201 _mesa_reference_texobj(&texObj
, NULL
);
205 static struct gl_texture_handle_object
*
206 find_texhandleobj(struct gl_texture_object
*texObj
,
207 struct gl_sampler_object
*sampObj
)
209 util_dynarray_foreach(&texObj
->SamplerHandles
,
210 struct gl_texture_handle_object
*, texHandleObj
) {
211 if ((*texHandleObj
)->sampObj
== sampObj
)
212 return *texHandleObj
;
218 get_texture_handle(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
219 struct gl_sampler_object
*sampObj
)
221 bool separate_sampler
= &texObj
->Sampler
!= sampObj
;
222 struct gl_texture_handle_object
*texHandleObj
;
225 /* The ARB_bindless_texture spec says:
227 * "The handle for each texture or texture/sampler pair is unique; the same
228 * handle will be returned if GetTextureHandleARB is called multiple times
229 * for the same texture or if GetTextureSamplerHandleARB is called multiple
230 * times for the same texture/sampler pair."
232 mtx_lock(&ctx
->Shared
->HandlesMutex
);
233 texHandleObj
= find_texhandleobj(texObj
, separate_sampler
? sampObj
: NULL
);
235 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
236 return texHandleObj
->handle
;
239 /* Request a new texture handle from the driver. */
240 handle
= ctx
->Driver
.NewTextureHandle(ctx
, texObj
, sampObj
);
242 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
243 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexture*HandleARB()");
247 texHandleObj
= CALLOC_STRUCT(gl_texture_handle_object
);
249 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
250 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexture*HandleARB()");
254 /* Store the handle into the texture object. */
255 texHandleObj
->texObj
= texObj
;
256 texHandleObj
->sampObj
= separate_sampler
? sampObj
: NULL
;
257 texHandleObj
->handle
= handle
;
258 util_dynarray_append(&texObj
->SamplerHandles
,
259 struct gl_texture_handle_object
*, texHandleObj
);
261 if (separate_sampler
) {
262 /* Store the handle into the separate sampler if needed. */
263 util_dynarray_append(&sampObj
->Handles
,
264 struct gl_texture_handle_object
*, texHandleObj
);
267 /* When referenced by one or more handles, texture objects are immutable. */
268 texObj
->HandleAllocated
= true;
269 if (texObj
->Target
== GL_TEXTURE_BUFFER
)
270 texObj
->BufferObject
->HandleAllocated
= true;
271 sampObj
->HandleAllocated
= true;
273 /* Store the handle in the shared state for all contexts. */
274 _mesa_hash_table_u64_insert(ctx
->Shared
->TextureHandles
, handle
,
276 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
281 static struct gl_image_handle_object
*
282 find_imghandleobj(struct gl_texture_object
*texObj
, GLint level
,
283 GLboolean layered
, GLint layer
, GLenum format
)
285 util_dynarray_foreach(&texObj
->ImageHandles
,
286 struct gl_image_handle_object
*, imgHandleObj
) {
287 struct gl_image_unit
*u
= &(*imgHandleObj
)->imgObj
;
289 if (u
->TexObj
== texObj
&& u
->Level
== level
&& u
->Layered
== layered
&&
290 u
->Layer
== layer
&& u
->Format
== format
)
291 return *imgHandleObj
;
297 get_image_handle(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
298 GLint level
, GLboolean layered
, GLint layer
, GLenum format
)
300 struct gl_image_handle_object
*imgHandleObj
;
301 struct gl_image_unit imgObj
;
304 /* The ARB_bindless_texture spec says:
306 * "The handle returned for each combination of <texture>, <level>,
307 * <layered>, <layer>, and <format> is unique; the same handle will be
308 * returned if GetImageHandleARB is called multiple times with the same
311 mtx_lock(&ctx
->Shared
->HandlesMutex
);
312 imgHandleObj
= find_imghandleobj(texObj
, level
, layered
, layer
, format
);
314 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
315 return imgHandleObj
->handle
;
318 imgObj
.TexObj
= texObj
; /* weak reference */
319 imgObj
.Level
= level
;
320 imgObj
.Access
= GL_READ_WRITE
;
321 imgObj
.Format
= format
;
322 imgObj
._ActualFormat
= _mesa_get_shader_image_format(format
);
324 if (_mesa_tex_target_is_layered(texObj
->Target
)) {
325 imgObj
.Layered
= layered
;
326 imgObj
.Layer
= layer
;
327 imgObj
._Layer
= (imgObj
.Layered
? 0 : imgObj
.Layer
);
329 imgObj
.Layered
= GL_FALSE
;
334 /* Request a new image handle from the driver. */
335 handle
= ctx
->Driver
.NewImageHandle(ctx
, &imgObj
);
337 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
338 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetImageHandleARB()");
342 imgHandleObj
= CALLOC_STRUCT(gl_image_handle_object
);
344 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
345 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetImageHandleARB()");
349 /* Store the handle into the texture object. */
350 memcpy(&imgHandleObj
->imgObj
, &imgObj
, sizeof(struct gl_image_unit
));
351 imgHandleObj
->handle
= handle
;
352 util_dynarray_append(&texObj
->ImageHandles
,
353 struct gl_image_handle_object
*, imgHandleObj
);
355 /* When referenced by one or more handles, texture objects are immutable. */
356 texObj
->HandleAllocated
= true;
357 if (texObj
->Target
== GL_TEXTURE_BUFFER
)
358 texObj
->BufferObject
->HandleAllocated
= true;
359 texObj
->Sampler
.HandleAllocated
= true;
361 /* Store the handle in the shared state for all contexts. */
362 _mesa_hash_table_u64_insert(ctx
->Shared
->ImageHandles
, handle
, imgHandleObj
);
363 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
369 * Init/free per-context resident handles.
372 _mesa_init_resident_handles(struct gl_context
*ctx
)
374 ctx
->ResidentTextureHandles
= _mesa_hash_table_u64_create(NULL
);
375 ctx
->ResidentImageHandles
= _mesa_hash_table_u64_create(NULL
);
379 _mesa_free_resident_handles(struct gl_context
*ctx
)
381 _mesa_hash_table_u64_destroy(ctx
->ResidentTextureHandles
, NULL
);
382 _mesa_hash_table_u64_destroy(ctx
->ResidentImageHandles
, NULL
);
386 * Init/free shared allocated handles.
389 _mesa_init_shared_handles(struct gl_shared_state
*shared
)
391 shared
->TextureHandles
= _mesa_hash_table_u64_create(NULL
);
392 shared
->ImageHandles
= _mesa_hash_table_u64_create(NULL
);
393 mtx_init(&shared
->HandlesMutex
, mtx_recursive
);
397 _mesa_free_shared_handles(struct gl_shared_state
*shared
)
399 if (shared
->TextureHandles
)
400 _mesa_hash_table_u64_destroy(shared
->TextureHandles
, NULL
);
402 if (shared
->ImageHandles
)
403 _mesa_hash_table_u64_destroy(shared
->ImageHandles
, NULL
);
405 mtx_destroy(&shared
->HandlesMutex
);
409 * Init/free texture/image handles per-texture object.
412 _mesa_init_texture_handles(struct gl_texture_object
*texObj
)
414 util_dynarray_init(&texObj
->SamplerHandles
, NULL
);
415 util_dynarray_init(&texObj
->ImageHandles
, NULL
);
419 _mesa_make_texture_handles_non_resident(struct gl_context
*ctx
,
420 struct gl_texture_object
*texObj
)
422 mtx_lock(&ctx
->Shared
->HandlesMutex
);
424 /* Texture handles */
425 util_dynarray_foreach(&texObj
->SamplerHandles
,
426 struct gl_texture_handle_object
*, texHandleObj
) {
427 if (is_texture_handle_resident(ctx
, (*texHandleObj
)->handle
))
428 make_texture_handle_resident(ctx
, *texHandleObj
, false);
432 util_dynarray_foreach(&texObj
->ImageHandles
,
433 struct gl_image_handle_object
*, imgHandleObj
) {
434 if (is_image_handle_resident(ctx
, (*imgHandleObj
)->handle
))
435 make_image_handle_resident(ctx
, *imgHandleObj
, GL_READ_ONLY
, false);
438 mtx_unlock(&ctx
->Shared
->HandlesMutex
);
442 _mesa_delete_texture_handles(struct gl_context
*ctx
,
443 struct gl_texture_object
*texObj
)
445 /* Texture handles */
446 util_dynarray_foreach(&texObj
->SamplerHandles
,
447 struct gl_texture_handle_object
*, texHandleObj
) {
448 struct gl_sampler_object
*sampObj
= (*texHandleObj
)->sampObj
;
451 /* Delete the handle in the separate sampler object. */
452 util_dynarray_delete_unordered(&sampObj
->Handles
,
453 struct gl_texture_handle_object
*,
456 delete_texture_handle(ctx
, (*texHandleObj
)->handle
);
459 util_dynarray_fini(&texObj
->SamplerHandles
);
462 util_dynarray_foreach(&texObj
->ImageHandles
,
463 struct gl_image_handle_object
*, imgHandleObj
) {
464 delete_image_handle(ctx
, (*imgHandleObj
)->handle
);
467 util_dynarray_fini(&texObj
->ImageHandles
);
471 * Init/free texture handles per-sampler object.
474 _mesa_init_sampler_handles(struct gl_sampler_object
*sampObj
)
476 util_dynarray_init(&sampObj
->Handles
, NULL
);
480 _mesa_delete_sampler_handles(struct gl_context
*ctx
,
481 struct gl_sampler_object
*sampObj
)
483 util_dynarray_foreach(&sampObj
->Handles
,
484 struct gl_texture_handle_object
*, texHandleObj
) {
485 struct gl_texture_object
*texObj
= (*texHandleObj
)->texObj
;
487 /* Delete the handle in the texture object. */
488 util_dynarray_delete_unordered(&texObj
->SamplerHandles
,
489 struct gl_texture_handle_object
*,
492 delete_texture_handle(ctx
, (*texHandleObj
)->handle
);
495 util_dynarray_fini(&sampObj
->Handles
);
499 is_sampler_border_color_valid(struct gl_sampler_object
*samp
)
501 static const GLfloat valid_float_border_colors
[4][4] = {
502 { 0.0, 0.0, 0.0, 0.0 },
503 { 0.0, 0.0, 0.0, 1.0 },
504 { 1.0, 1.0, 1.0, 0.0 },
505 { 1.0, 1.0, 1.0, 1.0 },
507 static const GLint valid_integer_border_colors
[4][4] = {
513 size_t size
= sizeof(samp
->BorderColor
.ui
);
515 /* The ARB_bindless_texture spec says:
517 * "The error INVALID_OPERATION is generated if the border color (taken from
518 * the embedded sampler for GetTextureHandleARB or from the <sampler> for
519 * GetTextureSamplerHandleARB) is not one of the following allowed values.
520 * If the texture's base internal format is signed or unsigned integer,
521 * allowed values are (0,0,0,0), (0,0,0,1), (1,1,1,0), and (1,1,1,1). If
522 * the base internal format is not integer, allowed values are
523 * (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
524 * (1.0,1.0,1.0,1.0)."
526 if (!memcmp(samp
->BorderColor
.f
, valid_float_border_colors
[0], size
) ||
527 !memcmp(samp
->BorderColor
.f
, valid_float_border_colors
[1], size
) ||
528 !memcmp(samp
->BorderColor
.f
, valid_float_border_colors
[2], size
) ||
529 !memcmp(samp
->BorderColor
.f
, valid_float_border_colors
[3], size
))
532 if (!memcmp(samp
->BorderColor
.ui
, valid_integer_border_colors
[0], size
) ||
533 !memcmp(samp
->BorderColor
.ui
, valid_integer_border_colors
[1], size
) ||
534 !memcmp(samp
->BorderColor
.ui
, valid_integer_border_colors
[2], size
) ||
535 !memcmp(samp
->BorderColor
.ui
, valid_integer_border_colors
[3], size
))
542 _mesa_GetTextureHandleARB_no_error(GLuint texture
)
544 struct gl_texture_object
*texObj
;
546 GET_CURRENT_CONTEXT(ctx
);
548 texObj
= _mesa_lookup_texture(ctx
, texture
);
549 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
,
550 ctx
->Const
.ForceIntegerTexNearest
))
551 _mesa_test_texobj_completeness(ctx
, texObj
);
553 return get_texture_handle(ctx
, texObj
, &texObj
->Sampler
);
557 _mesa_GetTextureHandleARB(GLuint texture
)
559 struct gl_texture_object
*texObj
= NULL
;
561 GET_CURRENT_CONTEXT(ctx
);
563 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
564 _mesa_error(ctx
, GL_INVALID_OPERATION
,
565 "glGetTextureHandleARB(unsupported)");
569 /* The ARB_bindless_texture spec says:
571 * "The error INVALID_VALUE is generated by GetTextureHandleARB or
572 * GetTextureSamplerHandleARB if <texture> is zero or not the name of an
573 * existing texture object."
576 texObj
= _mesa_lookup_texture(ctx
, texture
);
579 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetTextureHandleARB(texture)");
583 /* The ARB_bindless_texture spec says:
585 * "The error INVALID_OPERATION is generated by GetTextureHandleARB or
586 * GetTextureSamplerHandleARB if the texture object specified by <texture>
589 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
,
590 ctx
->Const
.ForceIntegerTexNearest
)) {
591 _mesa_test_texobj_completeness(ctx
, texObj
);
592 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
,
593 ctx
->Const
.ForceIntegerTexNearest
)) {
594 _mesa_error(ctx
, GL_INVALID_OPERATION
,
595 "glGetTextureHandleARB(incomplete texture)");
600 if (!is_sampler_border_color_valid(&texObj
->Sampler
)) {
601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
602 "glGetTextureHandleARB(invalid border color)");
606 return get_texture_handle(ctx
, texObj
, &texObj
->Sampler
);
610 _mesa_GetTextureSamplerHandleARB_no_error(GLuint texture
, GLuint sampler
)
612 struct gl_texture_object
*texObj
;
613 struct gl_sampler_object
*sampObj
;
615 GET_CURRENT_CONTEXT(ctx
);
617 texObj
= _mesa_lookup_texture(ctx
, texture
);
618 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
620 if (!_mesa_is_texture_complete(texObj
, sampObj
,
621 ctx
->Const
.ForceIntegerTexNearest
))
622 _mesa_test_texobj_completeness(ctx
, texObj
);
624 return get_texture_handle(ctx
, texObj
, sampObj
);
628 _mesa_GetTextureSamplerHandleARB(GLuint texture
, GLuint sampler
)
630 struct gl_texture_object
*texObj
= NULL
;
631 struct gl_sampler_object
*sampObj
;
633 GET_CURRENT_CONTEXT(ctx
);
635 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
636 _mesa_error(ctx
, GL_INVALID_OPERATION
,
637 "glGetTextureSamplerHandleARB(unsupported)");
641 /* The ARB_bindless_texture spec says:
643 * "The error INVALID_VALUE is generated by GetTextureHandleARB or
644 * GetTextureSamplerHandleARB if <texture> is zero or not the name of an
645 * existing texture object."
648 texObj
= _mesa_lookup_texture(ctx
, texture
);
651 _mesa_error(ctx
, GL_INVALID_VALUE
,
652 "glGetTextureSamplerHandleARB(texture)");
656 /* The ARB_bindless_texture spec says:
658 * "The error INVALID_VALUE is generated by GetTextureSamplerHandleARB if
659 * <sampler> is zero or is not the name of an existing sampler object."
661 sampObj
= _mesa_lookup_samplerobj(ctx
, sampler
);
663 _mesa_error(ctx
, GL_INVALID_VALUE
,
664 "glGetTextureSamplerHandleARB(sampler)");
668 /* The ARB_bindless_texture spec says:
670 * "The error INVALID_OPERATION is generated by GetTextureHandleARB or
671 * GetTextureSamplerHandleARB if the texture object specified by <texture>
674 if (!_mesa_is_texture_complete(texObj
, sampObj
,
675 ctx
->Const
.ForceIntegerTexNearest
)) {
676 _mesa_test_texobj_completeness(ctx
, texObj
);
677 if (!_mesa_is_texture_complete(texObj
, sampObj
,
678 ctx
->Const
.ForceIntegerTexNearest
)) {
679 _mesa_error(ctx
, GL_INVALID_OPERATION
,
680 "glGetTextureSamplerHandleARB(incomplete texture)");
685 if (!is_sampler_border_color_valid(sampObj
)) {
686 _mesa_error(ctx
, GL_INVALID_OPERATION
,
687 "glGetTextureSamplerHandleARB(invalid border color)");
691 return get_texture_handle(ctx
, texObj
, sampObj
);
695 _mesa_MakeTextureHandleResidentARB_no_error(GLuint64 handle
)
697 struct gl_texture_handle_object
*texHandleObj
;
699 GET_CURRENT_CONTEXT(ctx
);
701 texHandleObj
= lookup_texture_handle(ctx
, handle
);
702 make_texture_handle_resident(ctx
, texHandleObj
, true);
706 _mesa_MakeTextureHandleResidentARB(GLuint64 handle
)
708 struct gl_texture_handle_object
*texHandleObj
;
710 GET_CURRENT_CONTEXT(ctx
);
712 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
713 _mesa_error(ctx
, GL_INVALID_OPERATION
,
714 "glMakeTextureHandleResidentARB(unsupported)");
718 /* The ARB_bindless_texture spec says:
720 * "The error INVALID_OPERATION is generated by MakeTextureHandleResidentARB
721 * if <handle> is not a valid texture handle, or if <handle> is already
722 * resident in the current GL context."
724 texHandleObj
= lookup_texture_handle(ctx
, handle
);
726 _mesa_error(ctx
, GL_INVALID_OPERATION
,
727 "glMakeTextureHandleResidentARB(handle)");
731 if (is_texture_handle_resident(ctx
, handle
)) {
732 _mesa_error(ctx
, GL_INVALID_OPERATION
,
733 "glMakeTextureHandleResidentARB(already resident)");
737 make_texture_handle_resident(ctx
, texHandleObj
, true);
741 _mesa_MakeTextureHandleNonResidentARB_no_error(GLuint64 handle
)
743 struct gl_texture_handle_object
*texHandleObj
;
745 GET_CURRENT_CONTEXT(ctx
);
747 texHandleObj
= lookup_texture_handle(ctx
, handle
);
748 make_texture_handle_resident(ctx
, texHandleObj
, false);
752 _mesa_MakeTextureHandleNonResidentARB(GLuint64 handle
)
754 struct gl_texture_handle_object
*texHandleObj
;
756 GET_CURRENT_CONTEXT(ctx
);
758 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
759 _mesa_error(ctx
, GL_INVALID_OPERATION
,
760 "glMakeTextureHandleNonResidentARB(unsupported)");
764 /* The ARB_bindless_texture spec says:
766 * "The error INVALID_OPERATION is generated by
767 * MakeTextureHandleNonResidentARB if <handle> is not a valid texture
768 * handle, or if <handle> is not resident in the current GL context."
770 texHandleObj
= lookup_texture_handle(ctx
, handle
);
772 _mesa_error(ctx
, GL_INVALID_OPERATION
,
773 "glMakeTextureHandleNonResidentARB(handle)");
777 if (!is_texture_handle_resident(ctx
, handle
)) {
778 _mesa_error(ctx
, GL_INVALID_OPERATION
,
779 "glMakeTextureHandleNonResidentARB(not resident)");
783 make_texture_handle_resident(ctx
, texHandleObj
, false);
787 _mesa_GetImageHandleARB_no_error(GLuint texture
, GLint level
, GLboolean layered
,
788 GLint layer
, GLenum format
)
790 struct gl_texture_object
*texObj
;
792 GET_CURRENT_CONTEXT(ctx
);
794 texObj
= _mesa_lookup_texture(ctx
, texture
);
795 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
,
796 ctx
->Const
.ForceIntegerTexNearest
))
797 _mesa_test_texobj_completeness(ctx
, texObj
);
799 return get_image_handle(ctx
, texObj
, level
, layered
, layer
, format
);
803 _mesa_GetImageHandleARB(GLuint texture
, GLint level
, GLboolean layered
,
804 GLint layer
, GLenum format
)
806 struct gl_texture_object
*texObj
= NULL
;
808 GET_CURRENT_CONTEXT(ctx
);
810 if (!_mesa_has_ARB_bindless_texture(ctx
) ||
811 !_mesa_has_ARB_shader_image_load_store(ctx
)) {
812 _mesa_error(ctx
, GL_INVALID_OPERATION
,
813 "glGetImageHandleARB(unsupported)");
817 /* The ARB_bindless_texture spec says:
819 * "The error INVALID_VALUE is generated by GetImageHandleARB if <texture>
820 * is zero or not the name of an existing texture object, if the image for
821 * <level> does not existing in <texture>, or if <layered> is FALSE and
822 * <layer> is greater than or equal to the number of layers in the image at
826 texObj
= _mesa_lookup_texture(ctx
, texture
);
829 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetImageHandleARB(texture)");
833 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, texObj
->Target
)) {
834 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetImageHandleARB(level)");
838 if (!layered
&& layer
> _mesa_get_texture_layers(texObj
, level
)) {
839 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetImageHandleARB(layer)");
843 if (!_mesa_is_shader_image_format_supported(ctx
, format
)) {
844 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetImageHandleARB(format)");
848 /* The ARB_bindless_texture spec says:
850 * "The error INVALID_OPERATION is generated by GetImageHandleARB if the
851 * texture object <texture> is not complete or if <layered> is TRUE and
852 * <texture> is not a three-dimensional, one-dimensional array, two
853 * dimensional array, cube map, or cube map array texture."
855 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
,
856 ctx
->Const
.ForceIntegerTexNearest
)) {
857 _mesa_test_texobj_completeness(ctx
, texObj
);
858 if (!_mesa_is_texture_complete(texObj
, &texObj
->Sampler
,
859 ctx
->Const
.ForceIntegerTexNearest
)) {
860 _mesa_error(ctx
, GL_INVALID_OPERATION
,
861 "glGetImageHandleARB(incomplete texture)");
866 if (layered
&& !_mesa_tex_target_is_layered(texObj
->Target
)) {
867 _mesa_error(ctx
, GL_INVALID_OPERATION
,
868 "glGetImageHandleARB(not layered)");
872 return get_image_handle(ctx
, texObj
, level
, layered
, layer
, format
);
876 _mesa_MakeImageHandleResidentARB_no_error(GLuint64 handle
, GLenum access
)
878 struct gl_image_handle_object
*imgHandleObj
;
880 GET_CURRENT_CONTEXT(ctx
);
882 imgHandleObj
= lookup_image_handle(ctx
, handle
);
883 make_image_handle_resident(ctx
, imgHandleObj
, access
, true);
887 _mesa_MakeImageHandleResidentARB(GLuint64 handle
, GLenum access
)
889 struct gl_image_handle_object
*imgHandleObj
;
891 GET_CURRENT_CONTEXT(ctx
);
893 if (!_mesa_has_ARB_bindless_texture(ctx
) ||
894 !_mesa_has_ARB_shader_image_load_store(ctx
)) {
895 _mesa_error(ctx
, GL_INVALID_OPERATION
,
896 "glMakeImageHandleResidentARB(unsupported)");
900 if (access
!= GL_READ_ONLY
&&
901 access
!= GL_WRITE_ONLY
&&
902 access
!= GL_READ_WRITE
) {
903 _mesa_error(ctx
, GL_INVALID_ENUM
,
904 "glMakeImageHandleResidentARB(access)");
908 /* The ARB_bindless_texture spec says:
910 * "The error INVALID_OPERATION is generated by MakeImageHandleResidentARB
911 * if <handle> is not a valid image handle, or if <handle> is already
912 * resident in the current GL context."
914 imgHandleObj
= lookup_image_handle(ctx
, handle
);
916 _mesa_error(ctx
, GL_INVALID_OPERATION
,
917 "glMakeImageHandleResidentARB(handle)");
921 if (is_image_handle_resident(ctx
, handle
)) {
922 _mesa_error(ctx
, GL_INVALID_OPERATION
,
923 "glMakeImageHandleResidentARB(already resident)");
927 make_image_handle_resident(ctx
, imgHandleObj
, access
, true);
931 _mesa_MakeImageHandleNonResidentARB_no_error(GLuint64 handle
)
933 struct gl_image_handle_object
*imgHandleObj
;
935 GET_CURRENT_CONTEXT(ctx
);
937 imgHandleObj
= lookup_image_handle(ctx
, handle
);
938 make_image_handle_resident(ctx
, imgHandleObj
, GL_READ_ONLY
, false);
942 _mesa_MakeImageHandleNonResidentARB(GLuint64 handle
)
944 struct gl_image_handle_object
*imgHandleObj
;
946 GET_CURRENT_CONTEXT(ctx
);
948 if (!_mesa_has_ARB_bindless_texture(ctx
) ||
949 !_mesa_has_ARB_shader_image_load_store(ctx
)) {
950 _mesa_error(ctx
, GL_INVALID_OPERATION
,
951 "glMakeImageHandleNonResidentARB(unsupported)");
955 /* The ARB_bindless_texture spec says:
957 * "The error INVALID_OPERATION is generated by
958 * MakeImageHandleNonResidentARB if <handle> is not a valid image handle,
959 * or if <handle> is not resident in the current GL context."
961 imgHandleObj
= lookup_image_handle(ctx
, handle
);
963 _mesa_error(ctx
, GL_INVALID_OPERATION
,
964 "glMakeImageHandleNonResidentARB(handle)");
968 if (!is_image_handle_resident(ctx
, handle
)) {
969 _mesa_error(ctx
, GL_INVALID_OPERATION
,
970 "glMakeImageHandleNonResidentARB(not resident)");
974 make_image_handle_resident(ctx
, imgHandleObj
, GL_READ_ONLY
, false);
978 _mesa_IsTextureHandleResidentARB_no_error(GLuint64 handle
)
980 GET_CURRENT_CONTEXT(ctx
);
981 return is_texture_handle_resident(ctx
, handle
);
985 _mesa_IsTextureHandleResidentARB(GLuint64 handle
)
987 GET_CURRENT_CONTEXT(ctx
);
989 if (!_mesa_has_ARB_bindless_texture(ctx
)) {
990 _mesa_error(ctx
, GL_INVALID_OPERATION
,
991 "glIsTextureHandleResidentARB(unsupported)");
995 /* The ARB_bindless_texture spec says:
997 * "The error INVALID_OPERATION will be generated by
998 * IsTextureHandleResidentARB and IsImageHandleResidentARB if <handle> is
999 * not a valid texture or image handle, respectively."
1001 if (!lookup_texture_handle(ctx
, handle
)) {
1002 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1003 "glIsTextureHandleResidentARB(handle)");
1007 return is_texture_handle_resident(ctx
, handle
);
1010 GLboolean GLAPIENTRY
1011 _mesa_IsImageHandleResidentARB_no_error(GLuint64 handle
)
1013 GET_CURRENT_CONTEXT(ctx
);
1014 return is_image_handle_resident(ctx
, handle
);
1017 GLboolean GLAPIENTRY
1018 _mesa_IsImageHandleResidentARB(GLuint64 handle
)
1020 GET_CURRENT_CONTEXT(ctx
);
1022 if (!_mesa_has_ARB_bindless_texture(ctx
) ||
1023 !_mesa_has_ARB_shader_image_load_store(ctx
)) {
1024 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1025 "glIsImageHandleResidentARB(unsupported)");
1029 /* The ARB_bindless_texture spec says:
1031 * "The error INVALID_OPERATION will be generated by
1032 * IsTextureHandleResidentARB and IsImageHandleResidentARB if <handle> is
1033 * not a valid texture or image handle, respectively."
1035 if (!lookup_image_handle(ctx
, handle
)) {
1036 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1037 "glIsImageHandleResidentARB(handle)");
1041 return is_image_handle_resident(ctx
, handle
);