1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "main/bufferobj.h"
30 #include "main/enums.h"
31 #include "main/fbobject.h"
32 #include "main/formats.h"
33 #include "main/format_utils.h"
34 #include "main/glformats.h"
35 #include "main/image.h"
36 #include "main/imports.h"
37 #include "main/macros.h"
38 #include "main/mipmap.h"
39 #include "main/pack.h"
41 #include "main/pixeltransfer.h"
42 #include "main/texcompress.h"
43 #include "main/texcompress_etc.h"
44 #include "main/texgetimage.h"
45 #include "main/teximage.h"
46 #include "main/texobj.h"
47 #include "main/texstore.h"
49 #include "state_tracker/st_debug.h"
50 #include "state_tracker/st_context.h"
51 #include "state_tracker/st_cb_fbo.h"
52 #include "state_tracker/st_cb_flush.h"
53 #include "state_tracker/st_cb_texture.h"
54 #include "state_tracker/st_cb_bufferobjects.h"
55 #include "state_tracker/st_format.h"
56 #include "state_tracker/st_pbo.h"
57 #include "state_tracker/st_texture.h"
58 #include "state_tracker/st_gen_mipmap.h"
59 #include "state_tracker/st_atom.h"
61 #include "pipe/p_context.h"
62 #include "pipe/p_defines.h"
63 #include "util/u_inlines.h"
64 #include "util/u_upload_mgr.h"
65 #include "pipe/p_shader_tokens.h"
66 #include "util/u_tile.h"
67 #include "util/u_format.h"
68 #include "util/u_surface.h"
69 #include "util/u_sampler.h"
70 #include "util/u_math.h"
71 #include "util/u_box.h"
72 #include "util/u_simple_shaders.h"
73 #include "cso_cache/cso_context.h"
74 #include "tgsi/tgsi_ureg.h"
76 #define DBG if (0) printf
79 enum pipe_texture_target
80 gl_target_to_pipe(GLenum target
)
84 case GL_PROXY_TEXTURE_1D
:
85 return PIPE_TEXTURE_1D
;
87 case GL_PROXY_TEXTURE_2D
:
88 case GL_TEXTURE_EXTERNAL_OES
:
89 case GL_TEXTURE_2D_MULTISAMPLE
:
90 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
91 return PIPE_TEXTURE_2D
;
92 case GL_TEXTURE_RECTANGLE_NV
:
93 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
94 return PIPE_TEXTURE_RECT
;
96 case GL_PROXY_TEXTURE_3D
:
97 return PIPE_TEXTURE_3D
;
98 case GL_TEXTURE_CUBE_MAP_ARB
:
99 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
100 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
101 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
102 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
103 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
104 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
105 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
106 return PIPE_TEXTURE_CUBE
;
107 case GL_TEXTURE_1D_ARRAY_EXT
:
108 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
109 return PIPE_TEXTURE_1D_ARRAY
;
110 case GL_TEXTURE_2D_ARRAY_EXT
:
111 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
112 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
113 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
114 return PIPE_TEXTURE_2D_ARRAY
;
115 case GL_TEXTURE_BUFFER
:
117 case GL_TEXTURE_CUBE_MAP_ARRAY
:
118 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
119 return PIPE_TEXTURE_CUBE_ARRAY
;
127 /** called via ctx->Driver.NewTextureImage() */
128 static struct gl_texture_image
*
129 st_NewTextureImage(struct gl_context
* ctx
)
131 DBG("%s\n", __func__
);
133 return (struct gl_texture_image
*) ST_CALLOC_STRUCT(st_texture_image
);
137 /** called via ctx->Driver.DeleteTextureImage() */
139 st_DeleteTextureImage(struct gl_context
* ctx
, struct gl_texture_image
*img
)
141 /* nothing special (yet) for st_texture_image */
142 _mesa_delete_texture_image(ctx
, img
);
146 /** called via ctx->Driver.NewTextureObject() */
147 static struct gl_texture_object
*
148 st_NewTextureObject(struct gl_context
* ctx
, GLuint name
, GLenum target
)
150 struct st_texture_object
*obj
= ST_CALLOC_STRUCT(st_texture_object
);
152 DBG("%s\n", __func__
);
153 _mesa_initialize_texture_object(ctx
, &obj
->base
, name
, target
);
158 /** called via ctx->Driver.DeleteTextureObject() */
160 st_DeleteTextureObject(struct gl_context
*ctx
,
161 struct gl_texture_object
*texObj
)
163 struct st_context
*st
= st_context(ctx
);
164 struct st_texture_object
*stObj
= st_texture_object(texObj
);
166 pipe_resource_reference(&stObj
->pt
, NULL
);
167 st_texture_release_all_sampler_views(st
, stObj
);
168 st_texture_free_sampler_views(stObj
);
169 _mesa_delete_texture_object(ctx
, texObj
);
173 /** called via ctx->Driver.FreeTextureImageBuffer() */
175 st_FreeTextureImageBuffer(struct gl_context
*ctx
,
176 struct gl_texture_image
*texImage
)
178 struct st_texture_image
*stImage
= st_texture_image(texImage
);
180 DBG("%s\n", __func__
);
183 pipe_resource_reference(&stImage
->pt
, NULL
);
186 free(stImage
->transfer
);
187 stImage
->transfer
= NULL
;
188 stImage
->num_transfers
= 0;
192 /** called via ctx->Driver.MapTextureImage() */
194 st_MapTextureImage(struct gl_context
*ctx
,
195 struct gl_texture_image
*texImage
,
196 GLuint slice
, GLuint x
, GLuint y
, GLuint w
, GLuint h
,
198 GLubyte
**mapOut
, GLint
*rowStrideOut
)
200 struct st_context
*st
= st_context(ctx
);
201 struct st_texture_image
*stImage
= st_texture_image(texImage
);
204 struct pipe_transfer
*transfer
;
207 if (mode
& GL_MAP_READ_BIT
)
208 pipeMode
|= PIPE_TRANSFER_READ
;
209 if (mode
& GL_MAP_WRITE_BIT
)
210 pipeMode
|= PIPE_TRANSFER_WRITE
;
211 if (mode
& GL_MAP_INVALIDATE_RANGE_BIT
)
212 pipeMode
|= PIPE_TRANSFER_DISCARD_RANGE
;
214 map
= st_texture_image_map(st
, stImage
, pipeMode
, x
, y
, slice
, w
, h
, 1,
217 if ((_mesa_is_format_etc2(texImage
->TexFormat
) && !st
->has_etc2
) ||
218 (texImage
->TexFormat
== MESA_FORMAT_ETC1_RGB8
&& !st
->has_etc1
)) {
219 /* ETC isn't supported by gallium and it's represented
220 * by uncompressed formats. Only write transfers with precompressed
221 * data are supported by ES3, which makes this really simple.
223 * Just create a temporary storage where the ETC texture will
224 * be stored. It will be decompressed in the Unmap function.
226 unsigned z
= transfer
->box
.z
;
227 struct st_texture_image_transfer
*itransfer
= &stImage
->transfer
[z
];
229 itransfer
->temp_data
=
230 malloc(_mesa_format_image_size(texImage
->TexFormat
, w
, h
, 1));
231 itransfer
->temp_stride
=
232 _mesa_format_row_stride(texImage
->TexFormat
, w
);
233 itransfer
->map
= map
;
235 *mapOut
= itransfer
->temp_data
;
236 *rowStrideOut
= itransfer
->temp_stride
;
239 /* supported mapping */
241 *rowStrideOut
= transfer
->stride
;
251 /** called via ctx->Driver.UnmapTextureImage() */
253 st_UnmapTextureImage(struct gl_context
*ctx
,
254 struct gl_texture_image
*texImage
,
257 struct st_context
*st
= st_context(ctx
);
258 struct st_texture_image
*stImage
= st_texture_image(texImage
);
260 if ((_mesa_is_format_etc2(texImage
->TexFormat
) && !st
->has_etc2
) ||
261 (texImage
->TexFormat
== MESA_FORMAT_ETC1_RGB8
&& !st
->has_etc1
)) {
262 /* Decompress the ETC texture to the mapped one. */
263 unsigned z
= slice
+ stImage
->base
.Face
;
264 struct st_texture_image_transfer
*itransfer
= &stImage
->transfer
[z
];
265 struct pipe_transfer
*transfer
= itransfer
->transfer
;
267 assert(z
== transfer
->box
.z
);
269 if (texImage
->TexFormat
== MESA_FORMAT_ETC1_RGB8
) {
270 _mesa_etc1_unpack_rgba8888(itransfer
->map
, transfer
->stride
,
271 itransfer
->temp_data
,
272 itransfer
->temp_stride
,
273 transfer
->box
.width
, transfer
->box
.height
);
276 _mesa_unpack_etc2_format(itransfer
->map
, transfer
->stride
,
277 itransfer
->temp_data
, itransfer
->temp_stride
,
278 transfer
->box
.width
, transfer
->box
.height
,
279 texImage
->TexFormat
);
282 free(itransfer
->temp_data
);
283 itransfer
->temp_data
= NULL
;
284 itransfer
->temp_stride
= 0;
288 st_texture_image_unmap(st
, stImage
, slice
);
293 * Return default texture resource binding bitmask for the given format.
296 default_bindings(struct st_context
*st
, enum pipe_format format
)
298 struct pipe_screen
*screen
= st
->pipe
->screen
;
299 const unsigned target
= PIPE_TEXTURE_2D
;
302 if (util_format_is_depth_or_stencil(format
))
303 bindings
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_DEPTH_STENCIL
;
305 bindings
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
307 if (screen
->is_format_supported(screen
, format
, target
, 0, bindings
))
311 format
= util_format_linear(format
);
313 if (screen
->is_format_supported(screen
, format
, target
, 0, bindings
))
316 return PIPE_BIND_SAMPLER_VIEW
;
322 * Given the size of a mipmap image, try to compute the size of the level=0
325 * Note that this isn't always accurate for odd-sized, non-POW textures.
326 * For example, if level=1 and width=40 then the level=0 width may be 80 or 81.
328 * \return GL_TRUE for success, GL_FALSE for failure
331 guess_base_level_size(GLenum target
,
332 GLuint width
, GLuint height
, GLuint depth
, GLuint level
,
333 GLuint
*width0
, GLuint
*height0
, GLuint
*depth0
)
340 /* Guess the size of the base level.
341 * Depending on the image's size, we can't always make a guess here.
345 case GL_TEXTURE_1D_ARRAY
:
350 case GL_TEXTURE_2D_ARRAY
:
351 /* We can't make a good guess here, because the base level dimensions
354 if (width
== 1 || height
== 1) {
361 case GL_TEXTURE_CUBE_MAP
:
362 case GL_TEXTURE_CUBE_MAP_ARRAY
:
368 /* We can't make a good guess here, because the base level dimensions
371 if (width
== 1 || height
== 1 || depth
== 1) {
379 case GL_TEXTURE_RECTANGLE
:
396 * Try to determine whether we should allocate memory for a full texture
397 * mipmap. The problem is when we get a glTexImage(level=0) call, we
398 * can't immediately know if other mipmap levels are coming next. Here
399 * we try to guess whether to allocate memory for a mipmap or just the
402 * If we guess incorrectly here we'll later reallocate the right amount of
403 * memory either in st_AllocTextureImageBuffer() or st_finalize_texture().
405 * \param stObj the texture object we're going to allocate memory for.
406 * \param stImage describes the incoming image which we need to store.
409 allocate_full_mipmap(const struct st_texture_object
*stObj
,
410 const struct st_texture_image
*stImage
)
412 switch (stObj
->base
.Target
) {
413 case GL_TEXTURE_RECTANGLE_NV
:
414 case GL_TEXTURE_BUFFER
:
415 case GL_TEXTURE_EXTERNAL_OES
:
416 case GL_TEXTURE_2D_MULTISAMPLE
:
417 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
418 /* these texture types cannot be mipmapped */
422 if (stImage
->base
.Level
> 0 || stObj
->base
.GenerateMipmap
)
425 if (stImage
->base
._BaseFormat
== GL_DEPTH_COMPONENT
||
426 stImage
->base
._BaseFormat
== GL_DEPTH_STENCIL_EXT
)
427 /* depth/stencil textures are seldom mipmapped */
430 if (stObj
->base
.BaseLevel
== 0 && stObj
->base
.MaxLevel
== 0)
433 if (stObj
->base
.Sampler
.MinFilter
== GL_NEAREST
||
434 stObj
->base
.Sampler
.MinFilter
== GL_LINEAR
)
435 /* not a mipmap minification filter */
438 if (stObj
->base
.Target
== GL_TEXTURE_3D
)
439 /* 3D textures are seldom mipmapped */
447 * Try to allocate a pipe_resource object for the given st_texture_object.
449 * We use the given st_texture_image as a clue to determine the size of the
450 * mipmap image at level=0.
452 * \return GL_TRUE for success, GL_FALSE if out of memory.
455 guess_and_alloc_texture(struct st_context
*st
,
456 struct st_texture_object
*stObj
,
457 const struct st_texture_image
*stImage
)
459 GLuint lastLevel
, width
, height
, depth
;
461 GLuint ptWidth
, ptHeight
, ptDepth
, ptLayers
;
462 enum pipe_format fmt
;
464 DBG("%s\n", __func__
);
468 if (!guess_base_level_size(stObj
->base
.Target
,
469 stImage
->base
.Width2
,
470 stImage
->base
.Height2
,
471 stImage
->base
.Depth2
,
473 &width
, &height
, &depth
)) {
474 /* we can't determine the image size at level=0 */
475 /* this is not an out of memory error */
479 /* At this point, (width x height x depth) is the expected size of
480 * the level=0 mipmap image.
483 /* Guess a reasonable value for lastLevel. With OpenGL we have no
484 * idea how many mipmap levels will be in a texture until we start
485 * to render with it. Make an educated guess here but be prepared
486 * to re-allocating a texture buffer with space for more (or fewer)
487 * mipmap levels later.
489 if (allocate_full_mipmap(stObj
, stImage
)) {
490 /* alloc space for a full mipmap */
491 lastLevel
= _mesa_get_tex_max_num_levels(stObj
->base
.Target
,
492 width
, height
, depth
) - 1;
495 /* only alloc space for a single mipmap level */
499 fmt
= st_mesa_format_to_pipe_format(st
, stImage
->base
.TexFormat
);
501 bindings
= default_bindings(st
, fmt
);
503 st_gl_texture_dims_to_pipe_dims(stObj
->base
.Target
,
504 width
, height
, depth
,
505 &ptWidth
, &ptHeight
, &ptDepth
, &ptLayers
);
507 stObj
->pt
= st_texture_create(st
,
508 gl_target_to_pipe(stObj
->base
.Target
),
517 stObj
->lastLevel
= lastLevel
;
519 DBG("%s returning %d\n", __func__
, (stObj
->pt
!= NULL
));
521 return stObj
->pt
!= NULL
;
526 * Called via ctx->Driver.AllocTextureImageBuffer().
527 * If the texture object/buffer already has space for the indicated image,
528 * we're done. Otherwise, allocate memory for the new texture image.
531 st_AllocTextureImageBuffer(struct gl_context
*ctx
,
532 struct gl_texture_image
*texImage
)
534 struct st_context
*st
= st_context(ctx
);
535 struct st_texture_image
*stImage
= st_texture_image(texImage
);
536 struct st_texture_object
*stObj
= st_texture_object(texImage
->TexObject
);
537 const GLuint level
= texImage
->Level
;
538 GLuint width
= texImage
->Width
;
539 GLuint height
= texImage
->Height
;
540 GLuint depth
= texImage
->Depth
;
542 DBG("%s\n", __func__
);
544 assert(!stImage
->pt
); /* xxx this might be wrong */
546 /* Look if the parent texture object has space for this image */
548 level
<= stObj
->pt
->last_level
&&
549 st_texture_match_image(st
, stObj
->pt
, texImage
)) {
550 /* this image will fit in the existing texture object's memory */
551 pipe_resource_reference(&stImage
->pt
, stObj
->pt
);
555 /* The parent texture object does not have space for this image */
557 pipe_resource_reference(&stObj
->pt
, NULL
);
558 st_texture_release_all_sampler_views(st
, stObj
);
560 if (!guess_and_alloc_texture(st
, stObj
, stImage
)) {
561 /* Probably out of memory.
562 * Try flushing any pending rendering, then retry.
565 if (!guess_and_alloc_texture(st
, stObj
, stImage
)) {
566 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
572 st_texture_match_image(st
, stObj
->pt
, texImage
)) {
573 /* The image will live in the object's mipmap memory */
574 pipe_resource_reference(&stImage
->pt
, stObj
->pt
);
579 /* Create a new, temporary texture/resource/buffer to hold this
580 * one texture image. Note that when we later access this image
581 * (either for mapping or copying) we'll want to always specify
582 * mipmap level=0, even if the image represents some other mipmap
585 enum pipe_format format
=
586 st_mesa_format_to_pipe_format(st
, texImage
->TexFormat
);
587 GLuint bindings
= default_bindings(st
, format
);
588 GLuint ptWidth
, ptHeight
, ptDepth
, ptLayers
;
590 st_gl_texture_dims_to_pipe_dims(stObj
->base
.Target
,
591 width
, height
, depth
,
592 &ptWidth
, &ptHeight
, &ptDepth
, &ptLayers
);
594 stImage
->pt
= st_texture_create(st
,
595 gl_target_to_pipe(stObj
->base
.Target
),
603 return stImage
->pt
!= NULL
;
609 * Preparation prior to glTexImage. Basically check the 'surface_based'
610 * field and switch to a "normal" tex image if necessary.
613 prep_teximage(struct gl_context
*ctx
, struct gl_texture_image
*texImage
,
614 GLenum format
, GLenum type
)
616 struct gl_texture_object
*texObj
= texImage
->TexObject
;
617 struct st_texture_object
*stObj
= st_texture_object(texObj
);
619 /* switch to "normal" */
620 if (stObj
->surface_based
) {
621 const GLenum target
= texObj
->Target
;
622 const GLuint level
= texImage
->Level
;
623 mesa_format texFormat
;
625 _mesa_clear_texture_object(ctx
, texObj
);
626 pipe_resource_reference(&stObj
->pt
, NULL
);
628 /* oops, need to init this image again */
629 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
630 texImage
->InternalFormat
, format
,
633 _mesa_init_teximage_fields(ctx
, texImage
,
634 texImage
->Width
, texImage
->Height
,
635 texImage
->Depth
, texImage
->Border
,
636 texImage
->InternalFormat
, texFormat
);
638 stObj
->surface_based
= GL_FALSE
;
644 * Return a writemask for the gallium blit. The parameters can be base
645 * formats or "format" from glDrawPixels/glTexImage/glGetTexImage.
648 st_get_blit_mask(GLenum srcFormat
, GLenum dstFormat
)
651 case GL_DEPTH_STENCIL
:
653 case GL_DEPTH_STENCIL
:
655 case GL_DEPTH_COMPONENT
:
657 case GL_STENCIL_INDEX
:
664 case GL_DEPTH_COMPONENT
:
666 case GL_DEPTH_STENCIL
:
667 case GL_DEPTH_COMPONENT
:
674 case GL_STENCIL_INDEX
:
676 case GL_STENCIL_INDEX
:
684 return PIPE_MASK_RGBA
;
689 * Converts format to a format with the same components, types
690 * and sizes, but with the components in RGBA order.
692 static enum pipe_format
693 unswizzle_format(enum pipe_format format
)
697 case PIPE_FORMAT_B8G8R8A8_UNORM
:
698 case PIPE_FORMAT_A8R8G8B8_UNORM
:
699 case PIPE_FORMAT_A8B8G8R8_UNORM
:
700 return PIPE_FORMAT_R8G8B8A8_UNORM
;
702 case PIPE_FORMAT_B10G10R10A2_UNORM
:
703 return PIPE_FORMAT_R10G10B10A2_UNORM
;
705 case PIPE_FORMAT_B10G10R10A2_SNORM
:
706 return PIPE_FORMAT_R10G10B10A2_SNORM
;
708 case PIPE_FORMAT_B10G10R10A2_UINT
:
709 return PIPE_FORMAT_R10G10B10A2_UINT
;
717 * Converts PIPE_FORMAT_A* to PIPE_FORMAT_R*.
719 static enum pipe_format
720 alpha_to_red(enum pipe_format format
)
724 case PIPE_FORMAT_A8_UNORM
:
725 return PIPE_FORMAT_R8_UNORM
;
726 case PIPE_FORMAT_A8_SNORM
:
727 return PIPE_FORMAT_R8_SNORM
;
728 case PIPE_FORMAT_A8_UINT
:
729 return PIPE_FORMAT_R8_UINT
;
730 case PIPE_FORMAT_A8_SINT
:
731 return PIPE_FORMAT_R8_SINT
;
733 case PIPE_FORMAT_A16_UNORM
:
734 return PIPE_FORMAT_R16_UNORM
;
735 case PIPE_FORMAT_A16_SNORM
:
736 return PIPE_FORMAT_R16_SNORM
;
737 case PIPE_FORMAT_A16_UINT
:
738 return PIPE_FORMAT_R16_UINT
;
739 case PIPE_FORMAT_A16_SINT
:
740 return PIPE_FORMAT_R16_SINT
;
741 case PIPE_FORMAT_A16_FLOAT
:
742 return PIPE_FORMAT_R16_FLOAT
;
744 case PIPE_FORMAT_A32_UINT
:
745 return PIPE_FORMAT_R32_UINT
;
746 case PIPE_FORMAT_A32_SINT
:
747 return PIPE_FORMAT_R32_SINT
;
748 case PIPE_FORMAT_A32_FLOAT
:
749 return PIPE_FORMAT_R32_FLOAT
;
757 * Converts PIPE_FORMAT_R*A* to PIPE_FORMAT_R*G*.
759 static enum pipe_format
760 red_alpha_to_red_green(enum pipe_format format
)
764 case PIPE_FORMAT_R8A8_UNORM
:
765 return PIPE_FORMAT_R8G8_UNORM
;
766 case PIPE_FORMAT_R8A8_SNORM
:
767 return PIPE_FORMAT_R8G8_SNORM
;
768 case PIPE_FORMAT_R8A8_UINT
:
769 return PIPE_FORMAT_R8G8_UINT
;
770 case PIPE_FORMAT_R8A8_SINT
:
771 return PIPE_FORMAT_R8G8_SINT
;
773 case PIPE_FORMAT_R16A16_UNORM
:
774 return PIPE_FORMAT_R16G16_UNORM
;
775 case PIPE_FORMAT_R16A16_SNORM
:
776 return PIPE_FORMAT_R16G16_SNORM
;
777 case PIPE_FORMAT_R16A16_UINT
:
778 return PIPE_FORMAT_R16G16_UINT
;
779 case PIPE_FORMAT_R16A16_SINT
:
780 return PIPE_FORMAT_R16G16_SINT
;
781 case PIPE_FORMAT_R16A16_FLOAT
:
782 return PIPE_FORMAT_R16G16_FLOAT
;
784 case PIPE_FORMAT_R32A32_UINT
:
785 return PIPE_FORMAT_R32G32_UINT
;
786 case PIPE_FORMAT_R32A32_SINT
:
787 return PIPE_FORMAT_R32G32_SINT
;
788 case PIPE_FORMAT_R32A32_FLOAT
:
789 return PIPE_FORMAT_R32G32_FLOAT
;
797 * Converts PIPE_FORMAT_L*A* to PIPE_FORMAT_R*G*.
799 static enum pipe_format
800 luminance_alpha_to_red_green(enum pipe_format format
)
804 case PIPE_FORMAT_L8A8_UNORM
:
805 return PIPE_FORMAT_R8G8_UNORM
;
806 case PIPE_FORMAT_L8A8_SNORM
:
807 return PIPE_FORMAT_R8G8_SNORM
;
808 case PIPE_FORMAT_L8A8_UINT
:
809 return PIPE_FORMAT_R8G8_UINT
;
810 case PIPE_FORMAT_L8A8_SINT
:
811 return PIPE_FORMAT_R8G8_SINT
;
813 case PIPE_FORMAT_L16A16_UNORM
:
814 return PIPE_FORMAT_R16G16_UNORM
;
815 case PIPE_FORMAT_L16A16_SNORM
:
816 return PIPE_FORMAT_R16G16_SNORM
;
817 case PIPE_FORMAT_L16A16_UINT
:
818 return PIPE_FORMAT_R16G16_UINT
;
819 case PIPE_FORMAT_L16A16_SINT
:
820 return PIPE_FORMAT_R16G16_SINT
;
821 case PIPE_FORMAT_L16A16_FLOAT
:
822 return PIPE_FORMAT_R16G16_FLOAT
;
824 case PIPE_FORMAT_L32A32_UINT
:
825 return PIPE_FORMAT_R32G32_UINT
;
826 case PIPE_FORMAT_L32A32_SINT
:
827 return PIPE_FORMAT_R32G32_SINT
;
828 case PIPE_FORMAT_L32A32_FLOAT
:
829 return PIPE_FORMAT_R32G32_FLOAT
;
837 * Returns true if format is a PIPE_FORMAT_A* format, and false otherwise.
840 format_is_alpha(enum pipe_format format
)
842 const struct util_format_description
*desc
= util_format_description(format
);
844 if (desc
->nr_channels
== 1 &&
845 desc
->swizzle
[0] == PIPE_SWIZZLE_0
&&
846 desc
->swizzle
[1] == PIPE_SWIZZLE_0
&&
847 desc
->swizzle
[2] == PIPE_SWIZZLE_0
&&
848 desc
->swizzle
[3] == PIPE_SWIZZLE_X
)
855 * Returns true if format is a PIPE_FORMAT_R* format, and false otherwise.
858 format_is_red(enum pipe_format format
)
860 const struct util_format_description
*desc
= util_format_description(format
);
862 if (desc
->nr_channels
== 1 &&
863 desc
->swizzle
[0] == PIPE_SWIZZLE_X
&&
864 desc
->swizzle
[1] == PIPE_SWIZZLE_0
&&
865 desc
->swizzle
[2] == PIPE_SWIZZLE_0
&&
866 desc
->swizzle
[3] == PIPE_SWIZZLE_1
)
874 * Returns true if format is a PIPE_FORMAT_L* format, and false otherwise.
877 format_is_luminance(enum pipe_format format
)
879 const struct util_format_description
*desc
= util_format_description(format
);
881 if (desc
->nr_channels
== 1 &&
882 desc
->swizzle
[0] == PIPE_SWIZZLE_X
&&
883 desc
->swizzle
[1] == PIPE_SWIZZLE_X
&&
884 desc
->swizzle
[2] == PIPE_SWIZZLE_X
&&
885 desc
->swizzle
[3] == PIPE_SWIZZLE_1
)
892 * Returns true if format is a PIPE_FORMAT_R*A* format, and false otherwise.
895 format_is_red_alpha(enum pipe_format format
)
897 const struct util_format_description
*desc
= util_format_description(format
);
899 if (desc
->nr_channels
== 2 &&
900 desc
->swizzle
[0] == PIPE_SWIZZLE_X
&&
901 desc
->swizzle
[1] == PIPE_SWIZZLE_0
&&
902 desc
->swizzle
[2] == PIPE_SWIZZLE_0
&&
903 desc
->swizzle
[3] == PIPE_SWIZZLE_Y
)
910 format_is_swizzled_rgba(enum pipe_format format
)
912 const struct util_format_description
*desc
= util_format_description(format
);
914 if ((desc
->swizzle
[0] == TGSI_SWIZZLE_X
|| desc
->swizzle
[0] == PIPE_SWIZZLE_0
) &&
915 (desc
->swizzle
[1] == TGSI_SWIZZLE_Y
|| desc
->swizzle
[1] == PIPE_SWIZZLE_0
) &&
916 (desc
->swizzle
[2] == TGSI_SWIZZLE_Z
|| desc
->swizzle
[2] == PIPE_SWIZZLE_0
) &&
917 (desc
->swizzle
[3] == TGSI_SWIZZLE_W
|| desc
->swizzle
[3] == PIPE_SWIZZLE_1
))
925 unsigned char swizzle
[4];
926 enum pipe_format format
;
929 static const struct format_table table_8888_unorm
[] = {
930 { { 0, 1, 2, 3 }, PIPE_FORMAT_R8G8B8A8_UNORM
},
931 { { 2, 1, 0, 3 }, PIPE_FORMAT_B8G8R8A8_UNORM
},
932 { { 3, 0, 1, 2 }, PIPE_FORMAT_A8R8G8B8_UNORM
},
933 { { 3, 2, 1, 0 }, PIPE_FORMAT_A8B8G8R8_UNORM
}
936 static const struct format_table table_1010102_unorm
[] = {
937 { { 0, 1, 2, 3 }, PIPE_FORMAT_R10G10B10A2_UNORM
},
938 { { 2, 1, 0, 3 }, PIPE_FORMAT_B10G10R10A2_UNORM
}
941 static const struct format_table table_1010102_snorm
[] = {
942 { { 0, 1, 2, 3 }, PIPE_FORMAT_R10G10B10A2_SNORM
},
943 { { 2, 1, 0, 3 }, PIPE_FORMAT_B10G10R10A2_SNORM
}
946 static const struct format_table table_1010102_uint
[] = {
947 { { 0, 1, 2, 3 }, PIPE_FORMAT_R10G10B10A2_UINT
},
948 { { 2, 1, 0, 3 }, PIPE_FORMAT_B10G10R10A2_UINT
}
951 static enum pipe_format
952 swizzle_format(enum pipe_format format
, const int * const swizzle
)
957 case PIPE_FORMAT_R8G8B8A8_UNORM
:
958 case PIPE_FORMAT_B8G8R8A8_UNORM
:
959 case PIPE_FORMAT_A8R8G8B8_UNORM
:
960 case PIPE_FORMAT_A8B8G8R8_UNORM
:
961 for (i
= 0; i
< ARRAY_SIZE(table_8888_unorm
); i
++) {
962 if (swizzle
[0] == table_8888_unorm
[i
].swizzle
[0] &&
963 swizzle
[1] == table_8888_unorm
[i
].swizzle
[1] &&
964 swizzle
[2] == table_8888_unorm
[i
].swizzle
[2] &&
965 swizzle
[3] == table_8888_unorm
[i
].swizzle
[3])
966 return table_8888_unorm
[i
].format
;
970 case PIPE_FORMAT_R10G10B10A2_UNORM
:
971 case PIPE_FORMAT_B10G10R10A2_UNORM
:
972 for (i
= 0; i
< ARRAY_SIZE(table_1010102_unorm
); i
++) {
973 if (swizzle
[0] == table_1010102_unorm
[i
].swizzle
[0] &&
974 swizzle
[1] == table_1010102_unorm
[i
].swizzle
[1] &&
975 swizzle
[2] == table_1010102_unorm
[i
].swizzle
[2] &&
976 swizzle
[3] == table_1010102_unorm
[i
].swizzle
[3])
977 return table_1010102_unorm
[i
].format
;
981 case PIPE_FORMAT_R10G10B10A2_SNORM
:
982 case PIPE_FORMAT_B10G10R10A2_SNORM
:
983 for (i
= 0; i
< ARRAY_SIZE(table_1010102_snorm
); i
++) {
984 if (swizzle
[0] == table_1010102_snorm
[i
].swizzle
[0] &&
985 swizzle
[1] == table_1010102_snorm
[i
].swizzle
[1] &&
986 swizzle
[2] == table_1010102_snorm
[i
].swizzle
[2] &&
987 swizzle
[3] == table_1010102_snorm
[i
].swizzle
[3])
988 return table_1010102_snorm
[i
].format
;
992 case PIPE_FORMAT_R10G10B10A2_UINT
:
993 case PIPE_FORMAT_B10G10R10A2_UINT
:
994 for (i
= 0; i
< ARRAY_SIZE(table_1010102_uint
); i
++) {
995 if (swizzle
[0] == table_1010102_uint
[i
].swizzle
[0] &&
996 swizzle
[1] == table_1010102_uint
[i
].swizzle
[1] &&
997 swizzle
[2] == table_1010102_uint
[i
].swizzle
[2] &&
998 swizzle
[3] == table_1010102_uint
[i
].swizzle
[3])
999 return table_1010102_uint
[i
].format
;
1007 return PIPE_FORMAT_NONE
;
1011 reinterpret_formats(enum pipe_format
*src_format
, enum pipe_format
*dst_format
)
1013 enum pipe_format src
= *src_format
;
1014 enum pipe_format dst
= *dst_format
;
1016 /* Note: dst_format has already been transformed from luminance/intensity
1017 * to red when this function is called. The source format will never
1018 * be an intensity format, because GL_INTENSITY is not a legal value
1019 * for the format parameter in glTex(Sub)Image(). */
1021 if (format_is_alpha(src
)) {
1022 if (!format_is_alpha(dst
))
1025 src
= alpha_to_red(src
);
1026 dst
= alpha_to_red(dst
);
1027 } else if (format_is_luminance(src
)) {
1028 if (!format_is_red(dst
) && !format_is_red_alpha(dst
))
1031 src
= util_format_luminance_to_red(src
);
1032 } else if (util_format_is_luminance_alpha(src
)) {
1033 src
= luminance_alpha_to_red_green(src
);
1035 if (format_is_red_alpha(dst
)) {
1036 dst
= red_alpha_to_red_green(dst
);
1037 } else if (!format_is_red(dst
))
1039 } else if (format_is_swizzled_rgba(src
)) {
1040 const struct util_format_description
*src_desc
= util_format_description(src
);
1041 const struct util_format_description
*dst_desc
= util_format_description(dst
);
1045 /* Make sure the format is an RGBA and not an RGBX format */
1046 if (src_desc
->nr_channels
!= 4 || src_desc
->swizzle
[3] == PIPE_SWIZZLE_1
)
1049 if (dst_desc
->nr_channels
!= 4 || dst_desc
->swizzle
[3] == PIPE_SWIZZLE_1
)
1052 for (i
= 0; i
< 4; i
++)
1053 swizzle
[i
] = dst_desc
->swizzle
[src_desc
->swizzle
[i
]];
1055 dst
= swizzle_format(dst
, swizzle
);
1056 if (dst
== PIPE_FORMAT_NONE
)
1059 src
= unswizzle_format(src
);
1068 try_pbo_upload_common(struct gl_context
*ctx
,
1069 struct pipe_surface
*surface
,
1070 const struct st_pbo_addresses
*addr
,
1071 enum pipe_format src_format
)
1073 struct st_context
*st
= st_context(ctx
);
1074 struct cso_context
*cso
= st
->cso_context
;
1075 struct pipe_context
*pipe
= st
->pipe
;
1076 bool success
= false;
1078 /* Create fragment shader */
1079 if (!st
->pbo
.upload_fs
) {
1080 st
->pbo
.upload_fs
= st_pbo_create_upload_fs(st
);
1081 if (!st
->pbo
.upload_fs
)
1085 cso_save_state(cso
, (CSO_BIT_FRAGMENT_SAMPLER_VIEWS
|
1086 CSO_BIT_FRAGMENT_SAMPLERS
|
1087 CSO_BIT_VERTEX_ELEMENTS
|
1088 CSO_BIT_AUX_VERTEX_BUFFER_SLOT
|
1089 CSO_BIT_FRAMEBUFFER
|
1092 CSO_BIT_DEPTH_STENCIL_ALPHA
|
1093 CSO_BIT_RASTERIZER
|
1094 CSO_BIT_STREAM_OUTPUTS
|
1095 CSO_BIT_PAUSE_QUERIES
|
1096 CSO_BITS_ALL_SHADERS
));
1097 cso_save_constant_buffer_slot0(cso
, PIPE_SHADER_FRAGMENT
);
1100 /* Set up the sampler_view */
1102 struct pipe_sampler_view templ
;
1103 struct pipe_sampler_view
*sampler_view
;
1104 struct pipe_sampler_state sampler
= {0};
1105 const struct pipe_sampler_state
*samplers
[1] = {&sampler
};
1107 memset(&templ
, 0, sizeof(templ
));
1108 templ
.target
= PIPE_BUFFER
;
1109 templ
.format
= src_format
;
1110 templ
.u
.buf
.first_element
= addr
->first_element
;
1111 templ
.u
.buf
.last_element
= addr
->last_element
;
1112 templ
.swizzle_r
= PIPE_SWIZZLE_X
;
1113 templ
.swizzle_g
= PIPE_SWIZZLE_Y
;
1114 templ
.swizzle_b
= PIPE_SWIZZLE_Z
;
1115 templ
.swizzle_a
= PIPE_SWIZZLE_W
;
1117 sampler_view
= pipe
->create_sampler_view(pipe
, addr
->buffer
, &templ
);
1118 if (sampler_view
== NULL
)
1121 cso_set_sampler_views(cso
, PIPE_SHADER_FRAGMENT
, 1, &sampler_view
);
1123 pipe_sampler_view_reference(&sampler_view
, NULL
);
1125 cso_set_samplers(cso
, PIPE_SHADER_FRAGMENT
, 1, samplers
);
1128 /* Framebuffer_state */
1130 struct pipe_framebuffer_state fb
;
1131 memset(&fb
, 0, sizeof(fb
));
1132 fb
.width
= surface
->width
;
1133 fb
.height
= surface
->height
;
1135 pipe_surface_reference(&fb
.cbufs
[0], surface
);
1137 cso_set_framebuffer(cso
, &fb
);
1139 pipe_surface_reference(&fb
.cbufs
[0], NULL
);
1142 cso_set_viewport_dims(cso
, surface
->width
, surface
->height
, FALSE
);
1145 cso_set_blend(cso
, &st
->pbo
.upload_blend
);
1147 /* Depth/stencil/alpha state */
1149 struct pipe_depth_stencil_alpha_state dsa
;
1150 memset(&dsa
, 0, sizeof(dsa
));
1151 cso_set_depth_stencil_alpha(cso
, &dsa
);
1154 /* Set up the fragment shader */
1155 cso_set_fragment_shader_handle(cso
, st
->pbo
.upload_fs
);
1157 success
= st_pbo_draw(st
, addr
, surface
->width
, surface
->height
);
1160 cso_restore_state(cso
);
1161 cso_restore_constant_buffer_slot0(cso
, PIPE_SHADER_FRAGMENT
);
1167 try_pbo_upload(struct gl_context
*ctx
, GLuint dims
,
1168 struct gl_texture_image
*texImage
,
1169 GLenum format
, GLenum type
,
1170 enum pipe_format dst_format
,
1171 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1172 GLint width
, GLint height
, GLint depth
,
1174 const struct gl_pixelstore_attrib
*unpack
)
1176 struct st_context
*st
= st_context(ctx
);
1177 struct st_texture_image
*stImage
= st_texture_image(texImage
);
1178 struct st_texture_object
*stObj
= st_texture_object(texImage
->TexObject
);
1179 struct pipe_resource
*texture
= stImage
->pt
;
1180 struct pipe_context
*pipe
= st
->pipe
;
1181 struct pipe_screen
*screen
= pipe
->screen
;
1182 struct pipe_surface
*surface
= NULL
;
1183 struct st_pbo_addresses addr
;
1184 enum pipe_format src_format
;
1185 const struct util_format_description
*desc
;
1186 GLenum gl_target
= texImage
->TexObject
->Target
;
1189 if (!st
->pbo
.upload_enabled
)
1192 /* From now on, we need the gallium representation of dimensions. */
1193 if (gl_target
== GL_TEXTURE_1D_ARRAY
) {
1200 if (depth
!= 1 && !st
->pbo
.layers
)
1203 /* Choose the source format. Initially, we do so without checking driver
1204 * support at all because of the remapping we later perform and because
1205 * at least the Radeon driver actually supports some formats for texture
1206 * buffers which it doesn't support for regular textures. */
1207 src_format
= st_choose_matching_format(st
, 0, format
, type
, unpack
->SwapBytes
);
1212 src_format
= util_format_linear(src_format
);
1213 desc
= util_format_description(src_format
);
1215 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
)
1218 if (desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_RGB
)
1221 if (st
->pbo
.rgba_only
) {
1222 enum pipe_format orig_dst_format
= dst_format
;
1224 if (!reinterpret_formats(&src_format
, &dst_format
)) {
1228 if (dst_format
!= orig_dst_format
&&
1229 !screen
->is_format_supported(screen
, dst_format
, PIPE_TEXTURE_2D
, 0,
1230 PIPE_BIND_RENDER_TARGET
)) {
1236 !screen
->is_format_supported(screen
, src_format
, PIPE_BUFFER
, 0,
1237 PIPE_BIND_SAMPLER_VIEW
)) {
1241 /* Compute buffer addresses */
1242 addr
.xoffset
= xoffset
;
1243 addr
.yoffset
= yoffset
;
1245 addr
.height
= height
;
1247 addr
.bytes_per_pixel
= desc
->block
.bits
/ 8;
1249 if (!st_pbo_addresses_pixelstore(st
, gl_target
, dims
== 3, unpack
, pixels
,
1253 /* Set up the surface */
1255 unsigned level
= stObj
->pt
!= stImage
->pt
? 0 : texImage
->TexObject
->MinLevel
+ texImage
->Level
;
1256 unsigned max_layer
= util_max_layer(texture
, level
);
1258 zoffset
+= texImage
->Face
+ texImage
->TexObject
->MinLayer
;
1260 struct pipe_surface templ
;
1261 memset(&templ
, 0, sizeof(templ
));
1262 templ
.format
= dst_format
;
1263 templ
.u
.tex
.level
= level
;
1264 templ
.u
.tex
.first_layer
= MIN2(zoffset
, max_layer
);
1265 templ
.u
.tex
.last_layer
= MIN2(zoffset
+ depth
- 1, max_layer
);
1267 surface
= pipe
->create_surface(pipe
, texture
, &templ
);
1272 success
= try_pbo_upload_common(ctx
, surface
, &addr
, src_format
);
1274 pipe_surface_reference(&surface
, NULL
);
1280 st_TexSubImage(struct gl_context
*ctx
, GLuint dims
,
1281 struct gl_texture_image
*texImage
,
1282 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1283 GLint width
, GLint height
, GLint depth
,
1284 GLenum format
, GLenum type
, const void *pixels
,
1285 const struct gl_pixelstore_attrib
*unpack
)
1287 struct st_context
*st
= st_context(ctx
);
1288 struct st_texture_image
*stImage
= st_texture_image(texImage
);
1289 struct st_texture_object
*stObj
= st_texture_object(texImage
->TexObject
);
1290 struct pipe_context
*pipe
= st
->pipe
;
1291 struct pipe_screen
*screen
= pipe
->screen
;
1292 struct pipe_resource
*dst
= stImage
->pt
;
1293 struct pipe_resource
*src
= NULL
;
1294 struct pipe_resource src_templ
;
1295 struct pipe_transfer
*transfer
;
1296 struct pipe_blit_info blit
;
1297 enum pipe_format src_format
, dst_format
;
1298 mesa_format mesa_src_format
;
1299 GLenum gl_target
= texImage
->TexObject
->Target
;
1302 unsigned dstz
= texImage
->Face
+ texImage
->TexObject
->MinLayer
;
1303 unsigned dst_level
= 0;
1305 if (stObj
->pt
== stImage
->pt
)
1306 dst_level
= texImage
->TexObject
->MinLevel
+ texImage
->Level
;
1308 assert(!_mesa_is_format_etc2(texImage
->TexFormat
) &&
1309 texImage
->TexFormat
!= MESA_FORMAT_ETC1_RGB8
);
1314 /* Try transfer_inline_write, which should be the fastest memcpy path. */
1316 !_mesa_is_bufferobj(unpack
->BufferObj
) &&
1317 _mesa_texstore_can_use_memcpy(ctx
, texImage
->_BaseFormat
,
1318 texImage
->TexFormat
, format
, type
,
1320 struct pipe_box box
;
1321 unsigned stride
, layer_stride
;
1324 stride
= _mesa_image_row_stride(unpack
, width
, format
, type
);
1325 layer_stride
= _mesa_image_image_stride(unpack
, width
, height
, format
,
1327 data
= _mesa_image_address(dims
, unpack
, pixels
, width
, height
, format
,
1330 /* Convert to Gallium coordinates. */
1331 if (gl_target
== GL_TEXTURE_1D_ARRAY
) {
1336 layer_stride
= stride
;
1339 u_box_3d(xoffset
, yoffset
, zoffset
+ dstz
, width
, height
, depth
, &box
);
1340 pipe
->transfer_inline_write(pipe
, dst
, dst_level
, 0,
1341 &box
, data
, stride
, layer_stride
);
1345 if (!st
->prefer_blit_based_texture_transfer
) {
1349 /* XXX Fallback for depth-stencil formats due to an incomplete stencil
1350 * blit implementation in some drivers. */
1351 if (format
== GL_DEPTH_STENCIL
) {
1355 /* If the base internal format and the texture format don't match,
1356 * we can't use blit-based TexSubImage. */
1357 if (texImage
->_BaseFormat
!=
1358 _mesa_get_format_base_format(texImage
->TexFormat
)) {
1363 /* See if the destination format is supported. */
1364 if (format
== GL_DEPTH_COMPONENT
|| format
== GL_DEPTH_STENCIL
)
1365 bind
= PIPE_BIND_DEPTH_STENCIL
;
1367 bind
= PIPE_BIND_RENDER_TARGET
;
1369 /* For luminance and intensity, only the red channel is stored
1370 * in the destination. */
1371 dst_format
= util_format_linear(dst
->format
);
1372 dst_format
= util_format_luminance_to_red(dst_format
);
1373 dst_format
= util_format_intensity_to_red(dst_format
);
1376 !screen
->is_format_supported(screen
, dst_format
, dst
->target
,
1377 dst
->nr_samples
, bind
)) {
1381 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
1382 if (try_pbo_upload(ctx
, dims
, texImage
, format
, type
, dst_format
,
1383 xoffset
, yoffset
, zoffset
,
1384 width
, height
, depth
, pixels
, unpack
))
1388 /* See if the texture format already matches the format and type,
1389 * in which case the memcpy-based fast path will likely be used and
1390 * we don't have to blit. */
1391 if (_mesa_format_matches_format_and_type(texImage
->TexFormat
, format
,
1392 type
, unpack
->SwapBytes
, NULL
)) {
1396 /* Choose the source format. */
1397 src_format
= st_choose_matching_format(st
, PIPE_BIND_SAMPLER_VIEW
,
1398 format
, type
, unpack
->SwapBytes
);
1403 mesa_src_format
= st_pipe_format_to_mesa_format(src_format
);
1405 /* There is no reason to do this if we cannot use memcpy for the temporary
1406 * source texture at least. This also takes transfer ops into account,
1408 if (!_mesa_texstore_can_use_memcpy(ctx
,
1409 _mesa_get_format_base_format(mesa_src_format
),
1410 mesa_src_format
, format
, type
, unpack
)) {
1414 /* TexSubImage only sets a single cubemap face. */
1415 if (gl_target
== GL_TEXTURE_CUBE_MAP
) {
1416 gl_target
= GL_TEXTURE_2D
;
1418 /* TexSubImage can specify subsets of cube map array faces
1419 * so we need to upload via 2D array instead */
1420 if (gl_target
== GL_TEXTURE_CUBE_MAP_ARRAY
) {
1421 gl_target
= GL_TEXTURE_2D_ARRAY
;
1424 /* Initialize the source texture description. */
1425 memset(&src_templ
, 0, sizeof(src_templ
));
1426 src_templ
.target
= gl_target_to_pipe(gl_target
);
1427 src_templ
.format
= src_format
;
1428 src_templ
.bind
= PIPE_BIND_SAMPLER_VIEW
;
1429 src_templ
.usage
= PIPE_USAGE_STAGING
;
1431 st_gl_texture_dims_to_pipe_dims(gl_target
, width
, height
, depth
,
1432 &src_templ
.width0
, &src_templ
.height0
,
1433 &src_templ
.depth0
, &src_templ
.array_size
);
1435 /* Check for NPOT texture support. */
1436 if (!screen
->get_param(screen
, PIPE_CAP_NPOT_TEXTURES
) &&
1437 (!util_is_power_of_two(src_templ
.width0
) ||
1438 !util_is_power_of_two(src_templ
.height0
) ||
1439 !util_is_power_of_two(src_templ
.depth0
))) {
1443 /* Create the source texture. */
1444 src
= screen
->resource_create(screen
, &src_templ
);
1449 /* Map source pixels. */
1450 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
1451 format
, type
, pixels
, unpack
,
1454 /* This is a GL error. */
1455 pipe_resource_reference(&src
, NULL
);
1459 /* From now on, we need the gallium representation of dimensions. */
1460 if (gl_target
== GL_TEXTURE_1D_ARRAY
) {
1467 map
= pipe_transfer_map_3d(pipe
, src
, 0, PIPE_TRANSFER_WRITE
, 0, 0, 0,
1468 width
, height
, depth
, &transfer
);
1470 _mesa_unmap_teximage_pbo(ctx
, unpack
);
1471 pipe_resource_reference(&src
, NULL
);
1475 /* Upload pixels (just memcpy). */
1477 const uint bytesPerRow
= width
* util_format_get_blocksize(src_format
);
1480 for (slice
= 0; slice
< (unsigned) depth
; slice
++) {
1481 if (gl_target
== GL_TEXTURE_1D_ARRAY
) {
1482 /* 1D array textures.
1483 * We need to convert gallium coords to GL coords.
1485 void *src
= _mesa_image_address2d(unpack
, pixels
,
1486 width
, depth
, format
,
1488 memcpy(map
, src
, bytesPerRow
);
1491 ubyte
*slice_map
= map
;
1493 for (row
= 0; row
< (unsigned) height
; row
++) {
1494 void *src
= _mesa_image_address(dims
, unpack
, pixels
,
1495 width
, height
, format
,
1496 type
, slice
, row
, 0);
1497 memcpy(slice_map
, src
, bytesPerRow
);
1498 slice_map
+= transfer
->stride
;
1501 map
+= transfer
->layer_stride
;
1505 pipe_transfer_unmap(pipe
, transfer
);
1506 _mesa_unmap_teximage_pbo(ctx
, unpack
);
1509 memset(&blit
, 0, sizeof(blit
));
1510 blit
.src
.resource
= src
;
1512 blit
.src
.format
= src_format
;
1513 blit
.dst
.resource
= dst
;
1514 blit
.dst
.level
= dst_level
;
1515 blit
.dst
.format
= dst_format
;
1516 blit
.src
.box
.x
= blit
.src
.box
.y
= blit
.src
.box
.z
= 0;
1517 blit
.dst
.box
.x
= xoffset
;
1518 blit
.dst
.box
.y
= yoffset
;
1519 blit
.dst
.box
.z
= zoffset
+ dstz
;
1520 blit
.src
.box
.width
= blit
.dst
.box
.width
= width
;
1521 blit
.src
.box
.height
= blit
.dst
.box
.height
= height
;
1522 blit
.src
.box
.depth
= blit
.dst
.box
.depth
= depth
;
1523 blit
.mask
= st_get_blit_mask(format
, texImage
->_BaseFormat
);
1524 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1525 blit
.scissor_enable
= FALSE
;
1527 st
->pipe
->blit(st
->pipe
, &blit
);
1529 pipe_resource_reference(&src
, NULL
);
1533 _mesa_store_texsubimage(ctx
, dims
, texImage
, xoffset
, yoffset
, zoffset
,
1534 width
, height
, depth
, format
, type
, pixels
,
1539 st_TexImage(struct gl_context
* ctx
, GLuint dims
,
1540 struct gl_texture_image
*texImage
,
1541 GLenum format
, GLenum type
, const void *pixels
,
1542 const struct gl_pixelstore_attrib
*unpack
)
1544 assert(dims
== 1 || dims
== 2 || dims
== 3);
1546 prep_teximage(ctx
, texImage
, format
, type
);
1548 if (texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
1551 /* allocate storage for texture data */
1552 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
)) {
1553 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
1557 st_TexSubImage(ctx
, dims
, texImage
, 0, 0, 0,
1558 texImage
->Width
, texImage
->Height
, texImage
->Depth
,
1559 format
, type
, pixels
, unpack
);
1564 st_CompressedTexSubImage(struct gl_context
*ctx
, GLuint dims
,
1565 struct gl_texture_image
*texImage
,
1566 GLint x
, GLint y
, GLint z
,
1567 GLsizei w
, GLsizei h
, GLsizei d
,
1568 GLenum format
, GLsizei imageSize
, const void *data
)
1570 struct st_context
*st
= st_context(ctx
);
1571 struct st_texture_image
*stImage
= st_texture_image(texImage
);
1572 struct st_texture_object
*stObj
= st_texture_object(texImage
->TexObject
);
1573 struct pipe_resource
*texture
= stImage
->pt
;
1574 struct pipe_context
*pipe
= st
->pipe
;
1575 struct pipe_screen
*screen
= pipe
->screen
;
1576 struct pipe_resource
*dst
= stImage
->pt
;
1577 struct pipe_surface
*surface
= NULL
;
1578 struct compressed_pixelstore store
;
1579 struct st_pbo_addresses addr
;
1580 enum pipe_format copy_format
;
1582 intptr_t buf_offset
;
1583 bool success
= false;
1585 /* Check basic pre-conditions for PBO upload */
1586 if (!st
->prefer_blit_based_texture_transfer
) {
1590 if (!_mesa_is_bufferobj(ctx
->Unpack
.BufferObj
))
1593 if ((_mesa_is_format_etc2(texImage
->TexFormat
) && !st
->has_etc2
) ||
1594 (texImage
->TexFormat
== MESA_FORMAT_ETC1_RGB8
&& !st
->has_etc1
)) {
1595 /* ETC isn't supported and is represented by uncompressed formats. */
1603 if (!st
->pbo
.upload_enabled
||
1604 !screen
->get_param(screen
, PIPE_CAP_SURFACE_REINTERPRET_BLOCKS
)) {
1608 /* Choose the pipe format for the upload. */
1609 addr
.bytes_per_pixel
= util_format_get_blocksize(dst
->format
);
1610 bw
= util_format_get_blockwidth(dst
->format
);
1611 bh
= util_format_get_blockheight(dst
->format
);
1613 switch (addr
.bytes_per_pixel
) {
1615 copy_format
= PIPE_FORMAT_R16G16B16A16_UINT
;
1618 copy_format
= PIPE_FORMAT_R32G32B32A32_UINT
;
1624 if (!screen
->is_format_supported(screen
, copy_format
, PIPE_BUFFER
, 0,
1625 PIPE_BIND_SAMPLER_VIEW
)) {
1629 if (!screen
->is_format_supported(screen
, copy_format
, dst
->target
,
1630 dst
->nr_samples
, PIPE_BIND_RENDER_TARGET
)) {
1634 /* Interpret the pixelstore settings. */
1635 _mesa_compute_compressed_pixelstore(dims
, texImage
->TexFormat
, w
, h
, d
,
1636 &ctx
->Unpack
, &store
);
1637 assert(store
.CopyBytesPerRow
% addr
.bytes_per_pixel
== 0);
1638 assert(store
.SkipBytes
% addr
.bytes_per_pixel
== 0);
1640 /* Compute the offset into the buffer */
1641 buf_offset
= (intptr_t)data
+ store
.SkipBytes
;
1643 if (buf_offset
% addr
.bytes_per_pixel
) {
1647 buf_offset
= buf_offset
/ addr
.bytes_per_pixel
;
1649 addr
.xoffset
= x
/ bw
;
1650 addr
.yoffset
= y
/ bh
;
1651 addr
.width
= store
.CopyBytesPerRow
/ addr
.bytes_per_pixel
;
1652 addr
.height
= store
.CopyRowsPerSlice
;
1654 addr
.pixels_per_row
= store
.TotalBytesPerRow
/ addr
.bytes_per_pixel
;
1655 addr
.image_height
= store
.TotalRowsPerSlice
;
1657 if (!st_pbo_addresses_setup(st
, st_buffer_object(ctx
->Unpack
.BufferObj
)->buffer
,
1661 /* Set up the surface. */
1663 unsigned level
= stObj
->pt
!= stImage
->pt
? 0 : texImage
->TexObject
->MinLevel
+ texImage
->Level
;
1664 unsigned max_layer
= util_max_layer(texture
, level
);
1666 z
+= texImage
->Face
+ texImage
->TexObject
->MinLayer
;
1668 struct pipe_surface templ
;
1669 memset(&templ
, 0, sizeof(templ
));
1670 templ
.format
= copy_format
;
1671 templ
.u
.tex
.level
= level
;
1672 templ
.u
.tex
.first_layer
= MIN2(z
, max_layer
);
1673 templ
.u
.tex
.last_layer
= MIN2(z
+ d
- 1, max_layer
);
1675 surface
= pipe
->create_surface(pipe
, texture
, &templ
);
1680 success
= try_pbo_upload_common(ctx
, surface
, &addr
, copy_format
);
1682 pipe_surface_reference(&surface
, NULL
);
1688 _mesa_store_compressed_texsubimage(ctx
, dims
, texImage
,
1690 format
, imageSize
, data
);
1694 st_CompressedTexImage(struct gl_context
*ctx
, GLuint dims
,
1695 struct gl_texture_image
*texImage
,
1696 GLsizei imageSize
, const void *data
)
1698 prep_teximage(ctx
, texImage
, GL_NONE
, GL_NONE
);
1700 /* only 2D and 3D compressed images are supported at this time */
1702 _mesa_problem(ctx
, "Unexpected glCompressedTexImage1D call");
1706 /* This is pretty simple, because unlike the general texstore path we don't
1707 * have to worry about the usual image unpacking or image transfer
1711 assert(texImage
->Width
> 0);
1712 assert(texImage
->Height
> 0);
1713 assert(texImage
->Depth
> 0);
1715 /* allocate storage for texture data */
1716 if (!st_AllocTextureImageBuffer(ctx
, texImage
)) {
1717 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage%uD", dims
);
1721 st_CompressedTexSubImage(ctx
, dims
, texImage
,
1723 texImage
->Width
, texImage
->Height
, texImage
->Depth
,
1724 texImage
->TexFormat
,
1732 * Called via ctx->Driver.GetTexSubImage()
1734 * This uses a blit to copy the texture to a texture format which matches
1735 * the format and type combo and then a fast read-back is done using memcpy.
1736 * We can do arbitrary X/Y/Z/W/0/1 swizzling here as long as there is
1737 * a format which matches the swizzling.
1739 * If such a format isn't available, it falls back to _mesa_GetTexImage_sw.
1741 * NOTE: Drivers usually do a blit to convert between tiled and linear
1742 * texture layouts during texture uploads/downloads, so the blit
1743 * we do here should be free in such cases.
1746 st_GetTexSubImage(struct gl_context
* ctx
,
1747 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1748 GLsizei width
, GLsizei height
, GLint depth
,
1749 GLenum format
, GLenum type
, void * pixels
,
1750 struct gl_texture_image
*texImage
)
1752 struct st_context
*st
= st_context(ctx
);
1753 struct pipe_context
*pipe
= st
->pipe
;
1754 struct pipe_screen
*screen
= pipe
->screen
;
1755 struct st_texture_image
*stImage
= st_texture_image(texImage
);
1756 struct st_texture_object
*stObj
= st_texture_object(texImage
->TexObject
);
1757 struct pipe_resource
*src
= stObj
->pt
;
1758 struct pipe_resource
*dst
= NULL
;
1759 struct pipe_resource dst_templ
;
1760 enum pipe_format dst_format
, src_format
;
1761 mesa_format mesa_format
;
1762 GLenum gl_target
= texImage
->TexObject
->Target
;
1763 enum pipe_texture_target pipe_target
;
1764 struct pipe_blit_info blit
;
1765 unsigned bind
= PIPE_BIND_TRANSFER_READ
;
1766 struct pipe_transfer
*tex_xfer
;
1768 boolean done
= FALSE
;
1770 assert(!_mesa_is_format_etc2(texImage
->TexFormat
) &&
1771 texImage
->TexFormat
!= MESA_FORMAT_ETC1_RGB8
);
1773 if (!st
->prefer_blit_based_texture_transfer
&&
1774 !_mesa_is_format_compressed(texImage
->TexFormat
)) {
1775 /* Try to avoid the fallback if we're doing texture decompression here */
1779 /* Handle non-finalized textures. */
1780 if (!stImage
->pt
|| stImage
->pt
!= stObj
->pt
|| !src
) {
1784 /* XXX Fallback to _mesa_GetTexImage_sw for depth-stencil formats
1785 * due to an incomplete stencil blit implementation in some drivers. */
1786 if (format
== GL_DEPTH_STENCIL
|| format
== GL_STENCIL_INDEX
) {
1790 /* If the base internal format and the texture format don't match, we have
1791 * to fall back to _mesa_GetTexImage_sw. */
1792 if (texImage
->_BaseFormat
!=
1793 _mesa_get_format_base_format(texImage
->TexFormat
)) {
1797 /* See if the texture format already matches the format and type,
1798 * in which case the memcpy-based fast path will be used. */
1799 if (_mesa_format_matches_format_and_type(texImage
->TexFormat
, format
,
1800 type
, ctx
->Pack
.SwapBytes
, NULL
)) {
1804 /* Convert the source format to what is expected by GetTexImage
1805 * and see if it's supported.
1807 * This only applies to glGetTexImage:
1808 * - Luminance must be returned as (L,0,0,1).
1809 * - Luminance alpha must be returned as (L,0,0,A).
1810 * - Intensity must be returned as (I,0,0,1)
1812 if (stObj
->surface_based
)
1813 src_format
= util_format_linear(stObj
->surface_format
);
1815 src_format
= util_format_linear(src
->format
);
1816 src_format
= util_format_luminance_to_red(src_format
);
1817 src_format
= util_format_intensity_to_red(src_format
);
1820 !screen
->is_format_supported(screen
, src_format
, src
->target
,
1822 PIPE_BIND_SAMPLER_VIEW
)) {
1826 if (format
== GL_DEPTH_COMPONENT
|| format
== GL_DEPTH_STENCIL
)
1827 bind
|= PIPE_BIND_DEPTH_STENCIL
;
1829 bind
|= PIPE_BIND_RENDER_TARGET
;
1831 /* GetTexImage only returns a single face for cubemaps. */
1832 if (gl_target
== GL_TEXTURE_CUBE_MAP
) {
1833 gl_target
= GL_TEXTURE_2D
;
1835 pipe_target
= gl_target_to_pipe(gl_target
);
1837 /* Choose the destination format by finding the best match
1838 * for the format+type combo. */
1839 dst_format
= st_choose_matching_format(st
, bind
, format
, type
,
1840 ctx
->Pack
.SwapBytes
);
1842 if (dst_format
== PIPE_FORMAT_NONE
) {
1843 GLenum dst_glformat
;
1845 /* Fall back to _mesa_GetTexImage_sw except for compressed formats,
1846 * where decompression with a blit is always preferred. */
1847 if (!util_format_is_compressed(src
->format
)) {
1851 /* Set the appropriate format for the decompressed texture.
1852 * Luminance and sRGB formats shouldn't appear here.*/
1853 switch (src_format
) {
1854 case PIPE_FORMAT_DXT1_RGB
:
1855 case PIPE_FORMAT_DXT1_RGBA
:
1856 case PIPE_FORMAT_DXT3_RGBA
:
1857 case PIPE_FORMAT_DXT5_RGBA
:
1858 case PIPE_FORMAT_RGTC1_UNORM
:
1859 case PIPE_FORMAT_RGTC2_UNORM
:
1860 case PIPE_FORMAT_ETC1_RGB8
:
1861 case PIPE_FORMAT_BPTC_RGBA_UNORM
:
1862 dst_glformat
= GL_RGBA8
;
1864 case PIPE_FORMAT_RGTC1_SNORM
:
1865 case PIPE_FORMAT_RGTC2_SNORM
:
1866 if (!ctx
->Extensions
.EXT_texture_snorm
)
1868 dst_glformat
= GL_RGBA8_SNORM
;
1870 case PIPE_FORMAT_BPTC_RGB_FLOAT
:
1871 case PIPE_FORMAT_BPTC_RGB_UFLOAT
:
1872 if (!ctx
->Extensions
.ARB_texture_float
)
1874 dst_glformat
= GL_RGBA32F
;
1881 dst_format
= st_choose_format(st
, dst_glformat
, format
, type
,
1882 pipe_target
, 0, bind
, FALSE
);
1884 if (dst_format
== PIPE_FORMAT_NONE
) {
1885 /* unable to get an rgba format!?! */
1890 /* create the destination texture of size (width X height X depth) */
1891 memset(&dst_templ
, 0, sizeof(dst_templ
));
1892 dst_templ
.target
= pipe_target
;
1893 dst_templ
.format
= dst_format
;
1894 dst_templ
.bind
= bind
;
1895 dst_templ
.usage
= PIPE_USAGE_STAGING
;
1897 st_gl_texture_dims_to_pipe_dims(gl_target
, width
, height
, depth
,
1898 &dst_templ
.width0
, &dst_templ
.height0
,
1899 &dst_templ
.depth0
, &dst_templ
.array_size
);
1901 dst
= screen
->resource_create(screen
, &dst_templ
);
1906 /* From now on, we need the gallium representation of dimensions. */
1907 if (gl_target
== GL_TEXTURE_1D_ARRAY
) {
1914 assert(texImage
->Face
== 0 ||
1915 texImage
->TexObject
->MinLayer
== 0 ||
1918 memset(&blit
, 0, sizeof(blit
));
1919 blit
.src
.resource
= src
;
1920 blit
.src
.level
= texImage
->Level
+ texImage
->TexObject
->MinLevel
;
1921 blit
.src
.format
= src_format
;
1922 blit
.dst
.resource
= dst
;
1924 blit
.dst
.format
= dst
->format
;
1925 blit
.src
.box
.x
= xoffset
;
1927 blit
.src
.box
.y
= yoffset
;
1929 blit
.src
.box
.z
= texImage
->Face
+ texImage
->TexObject
->MinLayer
+ zoffset
;
1931 blit
.src
.box
.width
= blit
.dst
.box
.width
= width
;
1932 blit
.src
.box
.height
= blit
.dst
.box
.height
= height
;
1933 blit
.src
.box
.depth
= blit
.dst
.box
.depth
= depth
;
1934 blit
.mask
= st_get_blit_mask(texImage
->_BaseFormat
, format
);
1935 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1936 blit
.scissor_enable
= FALSE
;
1938 /* blit/render/decompress */
1939 st
->pipe
->blit(st
->pipe
, &blit
);
1941 pixels
= _mesa_map_pbo_dest(ctx
, &ctx
->Pack
, pixels
);
1943 map
= pipe_transfer_map_3d(pipe
, dst
, 0, PIPE_TRANSFER_READ
,
1944 0, 0, 0, width
, height
, depth
, &tex_xfer
);
1949 mesa_format
= st_pipe_format_to_mesa_format(dst_format
);
1951 /* copy/pack data into user buffer */
1952 if (_mesa_format_matches_format_and_type(mesa_format
, format
, type
,
1953 ctx
->Pack
.SwapBytes
, NULL
)) {
1955 const uint bytesPerRow
= width
* util_format_get_blocksize(dst_format
);
1958 for (slice
= 0; slice
< depth
; slice
++) {
1959 if (gl_target
== GL_TEXTURE_1D_ARRAY
) {
1960 /* 1D array textures.
1961 * We need to convert gallium coords to GL coords.
1963 void *dest
= _mesa_image_address3d(&ctx
->Pack
, pixels
,
1964 width
, depth
, format
,
1966 memcpy(dest
, map
, bytesPerRow
);
1969 ubyte
*slice_map
= map
;
1971 for (row
= 0; row
< height
; row
++) {
1972 void *dest
= _mesa_image_address3d(&ctx
->Pack
, pixels
,
1973 width
, height
, format
,
1974 type
, slice
, row
, 0);
1975 memcpy(dest
, slice_map
, bytesPerRow
);
1976 slice_map
+= tex_xfer
->stride
;
1979 map
+= tex_xfer
->layer_stride
;
1983 /* format translation via floats */
1986 uint32_t dstMesaFormat
;
1987 int dstStride
, srcStride
;
1989 assert(util_format_is_compressed(src
->format
));
1991 rgba
= malloc(width
* 4 * sizeof(GLfloat
));
1996 if (ST_DEBUG
& DEBUG_FALLBACK
)
1997 debug_printf("%s: fallback format translation\n", __func__
);
1999 dstMesaFormat
= _mesa_format_from_format_and_type(format
, type
);
2000 dstStride
= _mesa_image_row_stride(&ctx
->Pack
, width
, format
, type
);
2001 srcStride
= 4 * width
* sizeof(GLfloat
);
2002 for (slice
= 0; slice
< depth
; slice
++) {
2003 if (gl_target
== GL_TEXTURE_1D_ARRAY
) {
2004 /* 1D array textures.
2005 * We need to convert gallium coords to GL coords.
2007 void *dest
= _mesa_image_address3d(&ctx
->Pack
, pixels
,
2008 width
, depth
, format
,
2011 /* get float[4] rgba row from surface */
2012 pipe_get_tile_rgba_format(tex_xfer
, map
, 0, 0, width
, 1,
2015 _mesa_format_convert(dest
, dstMesaFormat
, dstStride
,
2016 rgba
, RGBA32_FLOAT
, srcStride
,
2020 for (row
= 0; row
< height
; row
++) {
2021 void *dest
= _mesa_image_address3d(&ctx
->Pack
, pixels
,
2022 width
, height
, format
,
2023 type
, slice
, row
, 0);
2025 /* get float[4] rgba row from surface */
2026 pipe_get_tile_rgba_format(tex_xfer
, map
, 0, row
, width
, 1,
2029 _mesa_format_convert(dest
, dstMesaFormat
, dstStride
,
2030 rgba
, RGBA32_FLOAT
, srcStride
,
2034 map
+= tex_xfer
->layer_stride
;
2043 pipe_transfer_unmap(pipe
, tex_xfer
);
2045 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
2046 pipe_resource_reference(&dst
, NULL
);
2050 _mesa_GetTexSubImage_sw(ctx
, xoffset
, yoffset
, zoffset
,
2051 width
, height
, depth
,
2052 format
, type
, pixels
, texImage
);
2058 * Do a CopyTexSubImage operation using a read transfer from the source,
2059 * a write transfer to the destination and get_tile()/put_tile() to access
2060 * the pixels/texels.
2062 * Note: srcY=0=TOP of renderbuffer
2065 fallback_copy_texsubimage(struct gl_context
*ctx
,
2066 struct st_renderbuffer
*strb
,
2067 struct st_texture_image
*stImage
,
2069 GLint destX
, GLint destY
, GLint slice
,
2070 GLint srcX
, GLint srcY
,
2071 GLsizei width
, GLsizei height
)
2073 struct st_context
*st
= st_context(ctx
);
2074 struct pipe_context
*pipe
= st
->pipe
;
2075 struct pipe_transfer
*src_trans
;
2077 enum pipe_transfer_usage transfer_usage
;
2079 unsigned dst_width
= width
;
2080 unsigned dst_height
= height
;
2081 unsigned dst_depth
= 1;
2082 struct pipe_transfer
*transfer
;
2084 if (ST_DEBUG
& DEBUG_FALLBACK
)
2085 debug_printf("%s: fallback processing\n", __func__
);
2087 if (st_fb_orientation(ctx
->ReadBuffer
) == Y_0_TOP
) {
2088 srcY
= strb
->Base
.Height
- srcY
- height
;
2091 map
= pipe_transfer_map(pipe
,
2093 strb
->surface
->u
.tex
.level
,
2094 strb
->surface
->u
.tex
.first_layer
,
2097 width
, height
, &src_trans
);
2099 if ((baseFormat
== GL_DEPTH_COMPONENT
||
2100 baseFormat
== GL_DEPTH_STENCIL
) &&
2101 util_format_is_depth_and_stencil(stImage
->pt
->format
))
2102 transfer_usage
= PIPE_TRANSFER_READ_WRITE
;
2104 transfer_usage
= PIPE_TRANSFER_WRITE
;
2106 texDest
= st_texture_image_map(st
, stImage
, transfer_usage
,
2107 destX
, destY
, slice
,
2108 dst_width
, dst_height
, dst_depth
,
2111 if (baseFormat
== GL_DEPTH_COMPONENT
||
2112 baseFormat
== GL_DEPTH_STENCIL
) {
2113 const GLboolean scaleOrBias
= (ctx
->Pixel
.DepthScale
!= 1.0F
||
2114 ctx
->Pixel
.DepthBias
!= 0.0F
);
2118 /* determine bottom-to-top vs. top-to-bottom order for src buffer */
2119 if (st_fb_orientation(ctx
->ReadBuffer
) == Y_0_TOP
) {
2128 data
= malloc(width
* sizeof(uint
));
2131 /* To avoid a large temp memory allocation, do copy row by row */
2132 for (row
= 0; row
< height
; row
++, srcY
+= yStep
) {
2133 pipe_get_tile_z(src_trans
, map
, 0, srcY
, width
, 1, data
);
2135 _mesa_scale_and_bias_depth_uint(ctx
, width
, data
);
2138 if (stImage
->pt
->target
== PIPE_TEXTURE_1D_ARRAY
) {
2139 pipe_put_tile_z(transfer
, texDest
+ row
*transfer
->layer_stride
,
2140 0, 0, width
, 1, data
);
2143 pipe_put_tile_z(transfer
, texDest
, 0, row
, width
, 1, data
);
2148 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage()");
2156 malloc(width
* height
* 4 * sizeof(GLfloat
));
2158 if (tempSrc
&& texDest
) {
2159 const GLint dims
= 2;
2161 struct gl_texture_image
*texImage
= &stImage
->base
;
2162 struct gl_pixelstore_attrib unpack
= ctx
->DefaultPacking
;
2164 if (st_fb_orientation(ctx
->ReadBuffer
) == Y_0_TOP
) {
2165 unpack
.Invert
= GL_TRUE
;
2168 if (stImage
->pt
->target
== PIPE_TEXTURE_1D_ARRAY
) {
2169 dstRowStride
= transfer
->layer_stride
;
2172 dstRowStride
= transfer
->stride
;
2175 /* get float/RGBA image from framebuffer */
2176 /* XXX this usually involves a lot of int/float conversion.
2177 * try to avoid that someday.
2179 pipe_get_tile_rgba_format(src_trans
, map
, 0, 0, width
, height
,
2180 util_format_linear(strb
->texture
->format
),
2183 /* Store into texture memory.
2184 * Note that this does some special things such as pixel transfer
2185 * ops and format conversion. In particular, if the dest tex format
2186 * is actually RGBA but the user created the texture as GL_RGB we
2187 * need to fill-in/override the alpha channel with 1.0.
2189 _mesa_texstore(ctx
, dims
,
2190 texImage
->_BaseFormat
,
2191 texImage
->TexFormat
,
2195 GL_RGBA
, GL_FLOAT
, tempSrc
, /* src */
2199 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage");
2205 st_texture_image_unmap(st
, stImage
, slice
);
2206 pipe
->transfer_unmap(pipe
, src_trans
);
2211 * Do a CopyTex[Sub]Image1/2/3D() using a hardware (blit) path if possible.
2212 * Note that the region to copy has already been clipped so we know we
2213 * won't read from outside the source renderbuffer's bounds.
2215 * Note: srcY=0=Bottom of renderbuffer (GL convention)
2218 st_CopyTexSubImage(struct gl_context
*ctx
, GLuint dims
,
2219 struct gl_texture_image
*texImage
,
2220 GLint destX
, GLint destY
, GLint slice
,
2221 struct gl_renderbuffer
*rb
,
2222 GLint srcX
, GLint srcY
, GLsizei width
, GLsizei height
)
2224 struct st_texture_image
*stImage
= st_texture_image(texImage
);
2225 struct st_texture_object
*stObj
= st_texture_object(texImage
->TexObject
);
2226 struct st_renderbuffer
*strb
= st_renderbuffer(rb
);
2227 struct st_context
*st
= st_context(ctx
);
2228 struct pipe_context
*pipe
= st
->pipe
;
2229 struct pipe_screen
*screen
= pipe
->screen
;
2230 struct pipe_blit_info blit
;
2231 enum pipe_format dst_format
;
2232 GLboolean do_flip
= (st_fb_orientation(ctx
->ReadBuffer
) == Y_0_TOP
);
2236 assert(!_mesa_is_format_etc2(texImage
->TexFormat
) &&
2237 texImage
->TexFormat
!= MESA_FORMAT_ETC1_RGB8
);
2239 if (!strb
|| !strb
->surface
|| !stImage
->pt
) {
2240 debug_printf("%s: null strb or stImage\n", __func__
);
2244 if (_mesa_texstore_needs_transfer_ops(ctx
, texImage
->_BaseFormat
,
2245 texImage
->TexFormat
)) {
2249 /* The base internal format must match the mesa format, so make sure
2250 * e.g. an RGB internal format is really allocated as RGB and not as RGBA.
2252 if (texImage
->_BaseFormat
!=
2253 _mesa_get_format_base_format(texImage
->TexFormat
) ||
2254 rb
->_BaseFormat
!= _mesa_get_format_base_format(rb
->Format
)) {
2258 /* Choose the destination format to match the TexImage behavior. */
2259 dst_format
= util_format_linear(stImage
->pt
->format
);
2260 dst_format
= util_format_luminance_to_red(dst_format
);
2261 dst_format
= util_format_intensity_to_red(dst_format
);
2263 /* See if the destination format is supported. */
2264 if (texImage
->_BaseFormat
== GL_DEPTH_STENCIL
||
2265 texImage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2266 bind
= PIPE_BIND_DEPTH_STENCIL
;
2269 bind
= PIPE_BIND_RENDER_TARGET
;
2273 !screen
->is_format_supported(screen
, dst_format
, stImage
->pt
->target
,
2274 stImage
->pt
->nr_samples
, bind
)) {
2278 /* Y flipping for the main framebuffer. */
2280 srcY1
= strb
->Base
.Height
- srcY
- height
;
2281 srcY0
= srcY1
+ height
;
2285 srcY1
= srcY0
+ height
;
2288 /* Blit the texture.
2289 * This supports flipping, format conversions, and downsampling.
2291 memset(&blit
, 0, sizeof(blit
));
2292 blit
.src
.resource
= strb
->texture
;
2293 blit
.src
.format
= util_format_linear(strb
->surface
->format
);
2294 blit
.src
.level
= strb
->surface
->u
.tex
.level
;
2295 blit
.src
.box
.x
= srcX
;
2296 blit
.src
.box
.y
= srcY0
;
2297 blit
.src
.box
.z
= strb
->surface
->u
.tex
.first_layer
;
2298 blit
.src
.box
.width
= width
;
2299 blit
.src
.box
.height
= srcY1
- srcY0
;
2300 blit
.src
.box
.depth
= 1;
2301 blit
.dst
.resource
= stImage
->pt
;
2302 blit
.dst
.format
= dst_format
;
2303 blit
.dst
.level
= stObj
->pt
!= stImage
->pt
? 0 : texImage
->Level
+ texImage
->TexObject
->MinLevel
;
2304 blit
.dst
.box
.x
= destX
;
2305 blit
.dst
.box
.y
= destY
;
2306 blit
.dst
.box
.z
= stImage
->base
.Face
+ slice
+ texImage
->TexObject
->MinLayer
;
2307 blit
.dst
.box
.width
= width
;
2308 blit
.dst
.box
.height
= height
;
2309 blit
.dst
.box
.depth
= 1;
2310 blit
.mask
= st_get_blit_mask(rb
->_BaseFormat
, texImage
->_BaseFormat
);
2311 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
2312 pipe
->blit(pipe
, &blit
);
2316 /* software fallback */
2317 fallback_copy_texsubimage(ctx
,
2318 strb
, stImage
, texImage
->_BaseFormat
,
2319 destX
, destY
, slice
,
2320 srcX
, srcY
, width
, height
);
2325 * Copy image data from stImage into the texture object 'stObj' at level
2329 copy_image_data_to_texture(struct st_context
*st
,
2330 struct st_texture_object
*stObj
,
2332 struct st_texture_image
*stImage
)
2336 const struct gl_texture_image
*dstImage
=
2337 stObj
->base
.Image
[stImage
->base
.Face
][dstLevel
];
2339 assert(dstImage
->Width
== stImage
->base
.Width
);
2340 assert(dstImage
->Height
== stImage
->base
.Height
);
2341 assert(dstImage
->Depth
== stImage
->base
.Depth
);
2345 /* Copy potentially with the blitter:
2348 if (stImage
->pt
->last_level
== 0)
2351 src_level
= stImage
->base
.Level
;
2353 assert(src_level
<= stImage
->pt
->last_level
);
2354 assert(u_minify(stImage
->pt
->width0
, src_level
) == stImage
->base
.Width
);
2355 assert(stImage
->pt
->target
== PIPE_TEXTURE_1D_ARRAY
||
2356 u_minify(stImage
->pt
->height0
, src_level
) == stImage
->base
.Height
);
2357 assert(stImage
->pt
->target
== PIPE_TEXTURE_2D_ARRAY
||
2358 stImage
->pt
->target
== PIPE_TEXTURE_CUBE_ARRAY
||
2359 u_minify(stImage
->pt
->depth0
, src_level
) == stImage
->base
.Depth
);
2361 st_texture_image_copy(st
->pipe
,
2362 stObj
->pt
, dstLevel
, /* dest texture, level */
2363 stImage
->pt
, src_level
, /* src texture, level */
2364 stImage
->base
.Face
);
2366 pipe_resource_reference(&stImage
->pt
, NULL
);
2368 pipe_resource_reference(&stImage
->pt
, stObj
->pt
);
2373 * Called during state validation. When this function is finished,
2374 * the texture object should be ready for rendering.
2375 * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
2378 st_finalize_texture(struct gl_context
*ctx
,
2379 struct pipe_context
*pipe
,
2380 struct gl_texture_object
*tObj
)
2382 struct st_context
*st
= st_context(ctx
);
2383 struct st_texture_object
*stObj
= st_texture_object(tObj
);
2384 const GLuint nr_faces
= _mesa_num_tex_faces(stObj
->base
.Target
);
2386 const struct st_texture_image
*firstImage
;
2387 enum pipe_format firstImageFormat
;
2388 GLuint ptWidth
, ptHeight
, ptDepth
, ptLayers
, ptNumSamples
;
2390 if (tObj
->Immutable
)
2393 if (_mesa_is_texture_complete(tObj
, &tObj
->Sampler
)) {
2394 /* The texture is complete and we know exactly how many mipmap levels
2395 * are present/needed. This is conditional because we may be called
2396 * from the st_generate_mipmap() function when the texture object is
2397 * incomplete. In that case, we'll have set stObj->lastLevel before
2400 if (stObj
->base
.Sampler
.MinFilter
== GL_LINEAR
||
2401 stObj
->base
.Sampler
.MinFilter
== GL_NEAREST
)
2402 stObj
->lastLevel
= stObj
->base
.BaseLevel
;
2404 stObj
->lastLevel
= stObj
->base
._MaxLevel
;
2407 if (tObj
->Target
== GL_TEXTURE_BUFFER
) {
2408 struct st_buffer_object
*st_obj
= st_buffer_object(tObj
->BufferObject
);
2411 pipe_resource_reference(&stObj
->pt
, NULL
);
2412 st_texture_release_all_sampler_views(st
, stObj
);
2416 if (st_obj
->buffer
!= stObj
->pt
) {
2417 pipe_resource_reference(&stObj
->pt
, st_obj
->buffer
);
2418 st_texture_release_all_sampler_views(st
, stObj
);
2424 firstImage
= st_texture_image_const(_mesa_base_tex_image(&stObj
->base
));
2427 /* If both firstImage and stObj point to a texture which can contain
2428 * all active images, favour firstImage. Note that because of the
2429 * completeness requirement, we know that the image dimensions
2432 if (firstImage
->pt
&&
2433 firstImage
->pt
!= stObj
->pt
&&
2434 (!stObj
->pt
|| firstImage
->pt
->last_level
>= stObj
->pt
->last_level
)) {
2435 pipe_resource_reference(&stObj
->pt
, firstImage
->pt
);
2436 st_texture_release_all_sampler_views(st
, stObj
);
2439 /* If this texture comes from a window system, there is nothing else to do. */
2440 if (stObj
->surface_based
) {
2444 /* Find gallium format for the Mesa texture */
2446 st_mesa_format_to_pipe_format(st
, firstImage
->base
.TexFormat
);
2448 /* Find size of level=0 Gallium mipmap image, plus number of texture layers */
2450 GLuint width
, height
, depth
;
2452 st_gl_texture_dims_to_pipe_dims(stObj
->base
.Target
,
2453 firstImage
->base
.Width2
,
2454 firstImage
->base
.Height2
,
2455 firstImage
->base
.Depth2
,
2456 &width
, &height
, &depth
, &ptLayers
);
2458 /* If we previously allocated a pipe texture and its sizes are
2459 * compatible, use them.
2462 u_minify(stObj
->pt
->width0
, firstImage
->base
.Level
) == width
&&
2463 u_minify(stObj
->pt
->height0
, firstImage
->base
.Level
) == height
&&
2464 u_minify(stObj
->pt
->depth0
, firstImage
->base
.Level
) == depth
) {
2465 ptWidth
= stObj
->pt
->width0
;
2466 ptHeight
= stObj
->pt
->height0
;
2467 ptDepth
= stObj
->pt
->depth0
;
2469 /* Otherwise, compute a new level=0 size that is compatible with the
2472 ptWidth
= width
> 1 ? width
<< firstImage
->base
.Level
: 1;
2473 ptHeight
= height
> 1 ? height
<< firstImage
->base
.Level
: 1;
2474 ptDepth
= depth
> 1 ? depth
<< firstImage
->base
.Level
: 1;
2476 /* If the base level image is 1x1x1, we still need to ensure that the
2477 * resulting pipe texture ends up with the required number of levels
2480 if (ptWidth
== 1 && ptHeight
== 1 && ptDepth
== 1) {
2481 ptWidth
<<= firstImage
->base
.Level
;
2483 if (stObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
||
2484 stObj
->base
.Target
== GL_TEXTURE_CUBE_MAP_ARRAY
)
2489 ptNumSamples
= firstImage
->base
.NumSamples
;
2492 /* If we already have a gallium texture, check that it matches the texture
2493 * object's format, target, size, num_levels, etc.
2496 if (stObj
->pt
->target
!= gl_target_to_pipe(stObj
->base
.Target
) ||
2497 stObj
->pt
->format
!= firstImageFormat
||
2498 stObj
->pt
->last_level
< stObj
->lastLevel
||
2499 stObj
->pt
->width0
!= ptWidth
||
2500 stObj
->pt
->height0
!= ptHeight
||
2501 stObj
->pt
->depth0
!= ptDepth
||
2502 stObj
->pt
->nr_samples
!= ptNumSamples
||
2503 stObj
->pt
->array_size
!= ptLayers
)
2505 /* The gallium texture does not match the Mesa texture so delete the
2506 * gallium texture now. We'll make a new one below.
2508 pipe_resource_reference(&stObj
->pt
, NULL
);
2509 st_texture_release_all_sampler_views(st
, stObj
);
2510 st
->dirty
.st
|= ST_NEW_FRAMEBUFFER
;
2514 /* May need to create a new gallium texture:
2517 GLuint bindings
= default_bindings(st
, firstImageFormat
);
2519 stObj
->pt
= st_texture_create(st
,
2520 gl_target_to_pipe(stObj
->base
.Target
),
2526 ptLayers
, ptNumSamples
,
2530 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
2535 /* Pull in any images not in the object's texture:
2537 for (face
= 0; face
< nr_faces
; face
++) {
2539 for (level
= stObj
->base
.BaseLevel
; level
<= stObj
->lastLevel
; level
++) {
2540 struct st_texture_image
*stImage
=
2541 st_texture_image(stObj
->base
.Image
[face
][level
]);
2543 /* Need to import images in main memory or held in other textures.
2545 if (stImage
&& stObj
->pt
!= stImage
->pt
) {
2549 if (stObj
->base
.Target
!= GL_TEXTURE_1D_ARRAY
)
2550 height
= u_minify(ptHeight
, level
);
2554 if (stObj
->base
.Target
== GL_TEXTURE_3D
)
2555 depth
= u_minify(ptDepth
, level
);
2556 else if (stObj
->base
.Target
== GL_TEXTURE_CUBE_MAP
)
2562 (stImage
->base
.Width
== u_minify(ptWidth
, level
) &&
2563 stImage
->base
.Height
== height
&&
2564 stImage
->base
.Depth
== depth
)) {
2565 /* src image fits expected dest mipmap level size */
2566 copy_image_data_to_texture(st
, stObj
, level
, stImage
);
2577 * Called via ctx->Driver.AllocTextureStorage() to allocate texture memory
2578 * for a whole mipmap stack.
2581 st_AllocTextureStorage(struct gl_context
*ctx
,
2582 struct gl_texture_object
*texObj
,
2583 GLsizei levels
, GLsizei width
,
2584 GLsizei height
, GLsizei depth
)
2586 const GLuint numFaces
= _mesa_num_tex_faces(texObj
->Target
);
2587 struct gl_texture_image
*texImage
= texObj
->Image
[0][0];
2588 struct st_context
*st
= st_context(ctx
);
2589 struct st_texture_object
*stObj
= st_texture_object(texObj
);
2590 struct pipe_screen
*screen
= st
->pipe
->screen
;
2591 GLuint ptWidth
, ptHeight
, ptDepth
, ptLayers
, bindings
;
2592 enum pipe_format fmt
;
2594 GLuint num_samples
= texImage
->NumSamples
;
2598 stObj
->lastLevel
= levels
- 1;
2600 fmt
= st_mesa_format_to_pipe_format(st
, texImage
->TexFormat
);
2602 bindings
= default_bindings(st
, fmt
);
2604 /* Raise the sample count if the requested one is unsupported. */
2605 if (num_samples
> 1) {
2606 boolean found
= FALSE
;
2608 for (; num_samples
<= ctx
->Const
.MaxSamples
; num_samples
++) {
2609 if (screen
->is_format_supported(screen
, fmt
, PIPE_TEXTURE_2D
,
2611 PIPE_BIND_SAMPLER_VIEW
)) {
2612 /* Update the sample count in gl_texture_image as well. */
2613 texImage
->NumSamples
= num_samples
;
2624 st_gl_texture_dims_to_pipe_dims(texObj
->Target
,
2625 width
, height
, depth
,
2626 &ptWidth
, &ptHeight
, &ptDepth
, &ptLayers
);
2628 stObj
->pt
= st_texture_create(st
,
2629 gl_target_to_pipe(texObj
->Target
),
2635 ptLayers
, num_samples
,
2640 /* Set image resource pointers */
2641 for (level
= 0; level
< levels
; level
++) {
2643 for (face
= 0; face
< numFaces
; face
++) {
2644 struct st_texture_image
*stImage
=
2645 st_texture_image(texObj
->Image
[face
][level
]);
2646 pipe_resource_reference(&stImage
->pt
, stObj
->pt
);
2655 st_TestProxyTexImage(struct gl_context
*ctx
, GLenum target
,
2656 GLint level
, mesa_format format
,
2657 GLint width
, GLint height
,
2658 GLint depth
, GLint border
)
2660 struct st_context
*st
= st_context(ctx
);
2661 struct pipe_context
*pipe
= st
->pipe
;
2663 if (width
== 0 || height
== 0 || depth
== 0) {
2664 /* zero-sized images are legal, and always fit! */
2668 if (pipe
->screen
->can_create_resource
) {
2669 /* Ask the gallium driver if the texture is too large */
2670 struct gl_texture_object
*texObj
=
2671 _mesa_get_current_tex_object(ctx
, target
);
2672 struct pipe_resource pt
;
2674 /* Setup the pipe_resource object
2676 memset(&pt
, 0, sizeof(pt
));
2678 pt
.target
= gl_target_to_pipe(target
);
2679 pt
.format
= st_mesa_format_to_pipe_format(st
, format
);
2681 st_gl_texture_dims_to_pipe_dims(target
,
2682 width
, height
, depth
,
2683 &pt
.width0
, &pt
.height0
,
2684 &pt
.depth0
, &pt
.array_size
);
2686 if (level
== 0 && (texObj
->Sampler
.MinFilter
== GL_LINEAR
||
2687 texObj
->Sampler
.MinFilter
== GL_NEAREST
)) {
2688 /* assume just one mipmap level */
2692 /* assume a full set of mipmaps */
2693 pt
.last_level
= _mesa_logbase2(MAX3(width
, height
, depth
));
2696 return pipe
->screen
->can_create_resource(pipe
->screen
, &pt
);
2699 /* Use core Mesa fallback */
2700 return _mesa_test_proxy_teximage(ctx
, target
, level
, format
,
2701 width
, height
, depth
, border
);
2706 st_TextureView(struct gl_context
*ctx
,
2707 struct gl_texture_object
*texObj
,
2708 struct gl_texture_object
*origTexObj
)
2710 struct st_texture_object
*orig
= st_texture_object(origTexObj
);
2711 struct st_texture_object
*tex
= st_texture_object(texObj
);
2712 struct gl_texture_image
*image
= texObj
->Image
[0][0];
2714 const int numFaces
= _mesa_num_tex_faces(texObj
->Target
);
2715 const int numLevels
= texObj
->NumLevels
;
2720 pipe_resource_reference(&tex
->pt
, orig
->pt
);
2722 /* Set image resource pointers */
2723 for (level
= 0; level
< numLevels
; level
++) {
2724 for (face
= 0; face
< numFaces
; face
++) {
2725 struct st_texture_image
*stImage
=
2726 st_texture_image(texObj
->Image
[face
][level
]);
2727 pipe_resource_reference(&stImage
->pt
, tex
->pt
);
2731 tex
->surface_based
= GL_TRUE
;
2732 tex
->surface_format
=
2733 st_mesa_format_to_pipe_format(st_context(ctx
), image
->TexFormat
);
2735 tex
->lastLevel
= numLevels
- 1;
2741 st_ClearTexSubImage(struct gl_context
*ctx
,
2742 struct gl_texture_image
*texImage
,
2743 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2744 GLsizei width
, GLsizei height
, GLsizei depth
,
2745 const void *clearValue
)
2747 static const char zeros
[16] = {0};
2748 struct st_texture_image
*stImage
= st_texture_image(texImage
);
2749 struct pipe_resource
*pt
= stImage
->pt
;
2750 struct st_context
*st
= st_context(ctx
);
2751 struct pipe_context
*pipe
= st
->pipe
;
2752 unsigned level
= texImage
->Level
;
2753 struct pipe_box box
;
2758 u_box_3d(xoffset
, yoffset
, zoffset
+ texImage
->Face
,
2759 width
, height
, depth
, &box
);
2760 if (texImage
->TexObject
->Immutable
) {
2761 level
+= texImage
->TexObject
->MinLevel
;
2762 box
.z
+= texImage
->TexObject
->MinLayer
;
2765 pipe
->clear_texture(pipe
, pt
, level
, &box
, clearValue
? clearValue
: zeros
);
2769 st_init_texture_functions(struct dd_function_table
*functions
)
2771 functions
->ChooseTextureFormat
= st_ChooseTextureFormat
;
2772 functions
->QueryInternalFormat
= st_QueryInternalFormat
;
2773 functions
->TexImage
= st_TexImage
;
2774 functions
->TexSubImage
= st_TexSubImage
;
2775 functions
->CompressedTexSubImage
= st_CompressedTexSubImage
;
2776 functions
->CopyTexSubImage
= st_CopyTexSubImage
;
2777 functions
->GenerateMipmap
= st_generate_mipmap
;
2779 functions
->GetTexSubImage
= st_GetTexSubImage
;
2781 /* compressed texture functions */
2782 functions
->CompressedTexImage
= st_CompressedTexImage
;
2783 functions
->GetCompressedTexSubImage
= _mesa_GetCompressedTexSubImage_sw
;
2785 functions
->NewTextureObject
= st_NewTextureObject
;
2786 functions
->NewTextureImage
= st_NewTextureImage
;
2787 functions
->DeleteTextureImage
= st_DeleteTextureImage
;
2788 functions
->DeleteTexture
= st_DeleteTextureObject
;
2789 functions
->AllocTextureImageBuffer
= st_AllocTextureImageBuffer
;
2790 functions
->FreeTextureImageBuffer
= st_FreeTextureImageBuffer
;
2791 functions
->MapTextureImage
= st_MapTextureImage
;
2792 functions
->UnmapTextureImage
= st_UnmapTextureImage
;
2794 /* XXX Temporary until we can query pipe's texture sizes */
2795 functions
->TestProxyTexImage
= st_TestProxyTexImage
;
2797 functions
->AllocTextureStorage
= st_AllocTextureStorage
;
2798 functions
->TextureView
= st_TextureView
;
2799 functions
->ClearTexSubImage
= st_ClearTexSubImage
;