2 #include "main/macros.h"
3 #include "main/mtypes.h"
4 #include "main/enums.h"
5 #include "main/bufferobj.h"
6 #include "main/context.h"
7 #include "main/formats.h"
8 #include "main/glformats.h"
9 #include "main/image.h"
11 #include "main/renderbuffer.h"
12 #include "main/texcompress.h"
13 #include "main/texgetimage.h"
14 #include "main/texobj.h"
15 #include "main/teximage.h"
16 #include "main/texstore.h"
18 #include "drivers/common/meta.h"
20 #include "intel_mipmap_tree.h"
21 #include "intel_buffer_objects.h"
22 #include "intel_batchbuffer.h"
23 #include "intel_tex.h"
24 #include "intel_blit.h"
25 #include "intel_fbo.h"
26 #include "intel_image.h"
27 #include "intel_tiled_memcpy.h"
28 #include "brw_context.h"
30 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
32 /* Make sure one doesn't end up shrinking base level zero unnecessarily.
33 * Determining the base level dimension by shifting higher level dimension
34 * ends up in off-by-one value in case base level has NPOT size (for example,
36 * Choose the original base level dimension when shifted dimensions agree.
37 * Otherwise assume real resize is intended and use the new shifted value.
40 get_base_dim(unsigned old_base_dim
, unsigned new_level_dim
, unsigned level
)
42 const unsigned old_level_dim
= old_base_dim
>> level
;
43 const unsigned new_base_dim
= new_level_dim
<< level
;
45 return old_level_dim
== new_level_dim
? old_base_dim
: new_base_dim
;
48 /* Work back from the specified level of the image to the baselevel and create a
49 * miptree of that size.
51 struct intel_mipmap_tree
*
52 intel_miptree_create_for_teximage(struct brw_context
*brw
,
53 struct intel_texture_object
*intelObj
,
54 struct intel_texture_image
*intelImage
,
55 uint32_t layout_flags
)
58 int width
, height
, depth
;
59 unsigned old_width
= 0, old_height
= 0, old_depth
= 0;
60 const struct intel_mipmap_tree
*old_mt
= intelObj
->mt
;
61 const unsigned level
= intelImage
->base
.Base
.Level
;
63 intel_get_image_dims(&intelImage
->base
.Base
, &width
, &height
, &depth
);
65 if (old_mt
&& old_mt
->surf
.size
> 0) {
66 old_width
= old_mt
->surf
.logical_level0_px
.width
;
67 old_height
= old_mt
->surf
.logical_level0_px
.height
;
68 old_depth
= old_mt
->surf
.dim
== ISL_SURF_DIM_3D
?
69 old_mt
->surf
.logical_level0_px
.depth
:
70 old_mt
->surf
.logical_level0_px
.array_len
;
72 old_width
= old_mt
->logical_width0
;
73 old_height
= old_mt
->logical_height0
;
74 old_depth
= old_mt
->logical_depth0
;
77 DBG("%s\n", __func__
);
79 /* Figure out image dimensions at start level. */
80 switch(intelObj
->base
.Target
) {
81 case GL_TEXTURE_2D_MULTISAMPLE
:
82 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
83 case GL_TEXTURE_RECTANGLE
:
84 case GL_TEXTURE_EXTERNAL_OES
:
88 depth
= old_mt
? get_base_dim(old_depth
, depth
, level
) :
92 case GL_TEXTURE_2D_ARRAY
:
93 case GL_TEXTURE_CUBE_MAP
:
94 case GL_TEXTURE_CUBE_MAP_ARRAY
:
95 height
= old_mt
? get_base_dim(old_height
, height
, level
) :
99 case GL_TEXTURE_1D_ARRAY
:
100 width
= old_mt
? get_base_dim(old_width
, width
, level
) :
104 unreachable("Unexpected target");
107 /* Guess a reasonable value for lastLevel. This is probably going
108 * to be wrong fairly often and might mean that we have to look at
109 * resizable buffers, or require that buffers implement lazy
110 * pagetable arrangements.
112 if ((intelObj
->base
.Sampler
.MinFilter
== GL_NEAREST
||
113 intelObj
->base
.Sampler
.MinFilter
== GL_LINEAR
) &&
114 intelImage
->base
.Base
.Level
== 0 &&
115 !intelObj
->base
.GenerateMipmap
) {
118 lastLevel
= _mesa_get_tex_max_num_levels(intelObj
->base
.Target
,
119 width
, height
, depth
) - 1;
122 return intel_miptree_create(brw
,
123 intelObj
->base
.Target
,
124 intelImage
->base
.Base
.TexFormat
,
130 intelImage
->base
.Base
.NumSamples
,
131 layout_flags
| MIPTREE_LAYOUT_TILING_ANY
);
135 intelTexImage(struct gl_context
* ctx
,
137 struct gl_texture_image
*texImage
,
138 GLenum format
, GLenum type
, const void *pixels
,
139 const struct gl_pixelstore_attrib
*unpack
)
141 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
144 bool tex_busy
= intelImage
->mt
&& brw_bo_busy(intelImage
->mt
->bo
);
146 DBG("%s mesa_format %s target %s format %s type %s level %d %dx%dx%d\n",
147 __func__
, _mesa_get_format_name(texImage
->TexFormat
),
148 _mesa_enum_to_string(texImage
->TexObject
->Target
),
149 _mesa_enum_to_string(format
), _mesa_enum_to_string(type
),
150 texImage
->Level
, texImage
->Width
, texImage
->Height
, texImage
->Depth
);
152 /* Allocate storage for texture data. */
153 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
)) {
154 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
158 assert(intelImage
->mt
);
160 if (intelImage
->mt
->format
== MESA_FORMAT_S_UINT8
)
161 intelImage
->mt
->r8stencil_needs_update
= true;
163 ok
= _mesa_meta_pbo_TexSubImage(ctx
, dims
, texImage
, 0, 0, 0,
164 texImage
->Width
, texImage
->Height
,
166 format
, type
, pixels
,
171 ok
= intel_texsubimage_tiled_memcpy(ctx
, dims
, texImage
,
172 0, 0, 0, /*x,y,z offsets*/
176 format
, type
, pixels
, unpack
,
177 false /*allocate_storage*/);
181 DBG("%s: upload image %dx%dx%d pixels %p\n",
182 __func__
, texImage
->Width
, texImage
->Height
, texImage
->Depth
,
185 _mesa_store_teximage(ctx
, dims
, texImage
,
186 format
, type
, pixels
, unpack
);
191 intel_set_texture_image_mt(struct brw_context
*brw
,
192 struct gl_texture_image
*image
,
193 GLenum internal_format
,
194 struct intel_mipmap_tree
*mt
)
197 struct gl_texture_object
*texobj
= image
->TexObject
;
198 struct intel_texture_object
*intel_texobj
= intel_texture_object(texobj
);
199 struct intel_texture_image
*intel_image
= intel_texture_image(image
);
201 _mesa_init_teximage_fields(&brw
->ctx
, image
,
202 mt
->logical_width0
, mt
->logical_height0
, 1,
203 0, internal_format
, mt
->format
);
205 brw
->ctx
.Driver
.FreeTextureImageBuffer(&brw
->ctx
, image
);
207 intel_texobj
->needs_validate
= true;
208 intel_image
->base
.RowStride
= mt
->pitch
/ mt
->cpp
;
209 assert(mt
->pitch
% mt
->cpp
== 0);
211 intel_miptree_reference(&intel_image
->mt
, mt
);
213 /* Immediately validate the image to the object. */
214 intel_miptree_reference(&intel_texobj
->mt
, mt
);
217 static struct intel_mipmap_tree
*
218 create_mt_for_planar_dri_image(struct brw_context
*brw
,
219 GLenum target
, __DRIimage
*image
)
221 struct intel_image_format
*f
= image
->planar_format
;
222 struct intel_mipmap_tree
*planar_mt
;
224 for (int i
= 0; i
< f
->nplanes
; i
++) {
225 const int index
= f
->planes
[i
].buffer_index
;
226 const uint32_t dri_format
= f
->planes
[i
].dri_format
;
227 const mesa_format format
= driImageFormatToGLFormat(dri_format
);
228 const uint32_t width
= image
->width
>> f
->planes
[i
].width_shift
;
229 const uint32_t height
= image
->height
>> f
->planes
[i
].height_shift
;
231 /* Disable creation of the texture's aux buffers because the driver
232 * exposes no EGL API to manage them. That is, there is no API for
233 * resolving the aux buffer's content to the main buffer nor for
234 * invalidating the aux buffer's content.
236 struct intel_mipmap_tree
*mt
=
237 intel_miptree_create_for_bo(brw
, image
->bo
, format
,
238 image
->offsets
[index
],
240 image
->strides
[index
],
241 MIPTREE_LAYOUT_DISABLE_AUX
);
246 mt
->total_width
= width
;
247 mt
->total_height
= height
;
252 planar_mt
->plane
[i
- 1] = mt
;
259 * Binds a BO to a texture image, as if it was uploaded by glTexImage2D().
261 * Used for GLX_EXT_texture_from_pixmap and EGL image extensions,
263 static struct intel_mipmap_tree
*
264 create_mt_for_dri_image(struct brw_context
*brw
,
265 GLenum target
, __DRIimage
*image
)
267 struct gl_context
*ctx
= &brw
->ctx
;
268 struct intel_mipmap_tree
*mt
;
269 uint32_t draw_x
, draw_y
;
270 mesa_format format
= image
->format
;
272 if (!ctx
->TextureFormatSupported
[format
]) {
273 /* The texture storage paths in core Mesa detect if the driver does not
274 * support the user-requested format, and then searches for a
275 * fallback format. The DRIimage code bypasses core Mesa, though. So we
276 * do the fallbacks here for important formats.
278 * We must support DRM_FOURCC_XBGR8888 textures because the Android
279 * framework produces HAL_PIXEL_FORMAT_RGBX8888 winsys surfaces, which
280 * the Chrome OS compositor consumes as dma_buf EGLImages.
282 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
285 if (!ctx
->TextureFormatSupported
[format
])
288 /* Disable creation of the texture's aux buffers because the driver exposes
289 * no EGL API to manage them. That is, there is no API for resolving the aux
290 * buffer's content to the main buffer nor for invalidating the aux buffer's
293 mt
= intel_miptree_create_for_bo(brw
, image
->bo
, format
,
294 0, image
->width
, image
->height
, 1,
296 MIPTREE_LAYOUT_DISABLE_AUX
);
301 mt
->total_width
= image
->width
;
302 mt
->total_height
= image
->height
;
303 mt
->level
[0].slice
[0].x_offset
= image
->tile_x
;
304 mt
->level
[0].slice
[0].y_offset
= image
->tile_y
;
306 intel_miptree_get_tile_offsets(mt
, 0, 0, &draw_x
, &draw_y
);
308 /* From "OES_EGL_image" error reporting. We report GL_INVALID_OPERATION
309 * for EGL images from non-tile aligned sufaces in gen4 hw and earlier which has
310 * trouble resolving back to destination image due to alignment issues.
312 if (!brw
->has_surface_tile_offset
&&
313 (draw_x
!= 0 || draw_y
!= 0)) {
314 _mesa_error(&brw
->ctx
, GL_INVALID_OPERATION
, __func__
);
315 intel_miptree_release(&mt
);
319 mt
->offset
= image
->offset
;
325 intelSetTexBuffer2(__DRIcontext
*pDRICtx
, GLint target
,
326 GLint texture_format
,
327 __DRIdrawable
*dPriv
)
329 struct gl_framebuffer
*fb
= dPriv
->driverPrivate
;
330 struct brw_context
*brw
= pDRICtx
->driverPrivate
;
331 struct gl_context
*ctx
= &brw
->ctx
;
332 struct intel_renderbuffer
*rb
;
333 struct gl_texture_object
*texObj
;
334 struct gl_texture_image
*texImage
;
335 mesa_format texFormat
= MESA_FORMAT_NONE
;
336 struct intel_mipmap_tree
*mt
;
337 GLenum internal_format
= 0;
339 texObj
= _mesa_get_current_tex_object(ctx
, target
);
344 if (dPriv
->lastStamp
!= dPriv
->dri2
.stamp
||
345 !pDRICtx
->driScreenPriv
->dri2
.useInvalidate
)
346 intel_update_renderbuffers(pDRICtx
, dPriv
);
348 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
349 /* If the miptree isn't set, then intel_update_renderbuffers was unable
350 * to get the BO for the drawable from the window system.
355 if (rb
->mt
->cpp
== 4) {
356 if (texture_format
== __DRI_TEXTURE_FORMAT_RGB
) {
357 internal_format
= GL_RGB
;
358 texFormat
= MESA_FORMAT_B8G8R8X8_UNORM
;
361 internal_format
= GL_RGBA
;
362 texFormat
= MESA_FORMAT_B8G8R8A8_UNORM
;
364 } else if (rb
->mt
->cpp
== 2) {
365 internal_format
= GL_RGB
;
366 texFormat
= MESA_FORMAT_B5G6R5_UNORM
;
369 intel_miptree_make_shareable(brw
, rb
->mt
);
370 mt
= intel_miptree_create_for_bo(brw
, rb
->mt
->bo
, texFormat
, 0,
372 rb
->Base
.Base
.Height
,
373 1, rb
->mt
->pitch
, 0);
377 mt
->total_width
= rb
->Base
.Base
.Width
;
378 mt
->total_height
= rb
->Base
.Base
.Height
;
380 _mesa_lock_texture(&brw
->ctx
, texObj
);
381 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
382 intel_set_texture_image_mt(brw
, texImage
, internal_format
, mt
);
383 intel_miptree_release(&mt
);
384 _mesa_unlock_texture(&brw
->ctx
, texObj
);
388 intel_bind_renderbuffer_tex_image(struct gl_context
*ctx
,
389 struct gl_renderbuffer
*rb
,
390 struct gl_texture_image
*image
)
392 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
393 struct intel_texture_image
*intel_image
= intel_texture_image(image
);
394 struct gl_texture_object
*texobj
= image
->TexObject
;
395 struct intel_texture_object
*intel_texobj
= intel_texture_object(texobj
);
397 /* We can only handle RB allocated with AllocRenderbufferStorage, or
398 * window-system renderbuffers.
400 assert(!rb
->TexImage
);
405 _mesa_lock_texture(ctx
, texobj
);
406 _mesa_init_teximage_fields(ctx
, image
,
407 rb
->Width
, rb
->Height
, 1,
408 0, rb
->InternalFormat
, rb
->Format
);
409 image
->NumSamples
= rb
->NumSamples
;
411 intel_miptree_reference(&intel_image
->mt
, irb
->mt
);
413 /* Immediately validate the image to the object. */
414 intel_miptree_reference(&intel_texobj
->mt
, intel_image
->mt
);
416 intel_texobj
->needs_validate
= true;
417 _mesa_unlock_texture(ctx
, texobj
);
423 intelSetTexBuffer(__DRIcontext
*pDRICtx
, GLint target
, __DRIdrawable
*dPriv
)
425 /* The old interface didn't have the format argument, so copy our
426 * implementation's behavior at the time.
428 intelSetTexBuffer2(pDRICtx
, target
, __DRI_TEXTURE_FORMAT_RGBA
, dPriv
);
432 intel_image_target_texture_2d(struct gl_context
*ctx
, GLenum target
,
433 struct gl_texture_object
*texObj
,
434 struct gl_texture_image
*texImage
,
435 GLeglImageOES image_handle
)
437 struct brw_context
*brw
= brw_context(ctx
);
438 struct intel_mipmap_tree
*mt
;
439 __DRIscreen
*dri_screen
= brw
->screen
->driScrnPriv
;
442 image
= dri_screen
->dri2
.image
->lookupEGLImage(dri_screen
, image_handle
,
443 dri_screen
->loaderPrivate
);
447 /* We support external textures only for EGLImages created with
448 * EGL_EXT_image_dma_buf_import. We may lift that restriction in the future.
450 if (target
== GL_TEXTURE_EXTERNAL_OES
&& !image
->dma_buf_imported
) {
451 _mesa_error(ctx
, GL_INVALID_OPERATION
,
452 "glEGLImageTargetTexture2DOES(external target is enabled only "
453 "for images created with EGL_EXT_image_dma_buf_import");
457 /* Disallow depth/stencil textures: we don't have a way to pass the
458 * separate stencil miptree of a GL_DEPTH_STENCIL texture through.
460 if (image
->has_depthstencil
) {
461 _mesa_error(ctx
, GL_INVALID_OPERATION
, __func__
);
465 if (image
->planar_format
&& image
->planar_format
->nplanes
> 0)
466 mt
= create_mt_for_planar_dri_image(brw
, target
, image
);
468 mt
= create_mt_for_dri_image(brw
, target
, image
);
472 struct intel_texture_object
*intel_texobj
= intel_texture_object(texObj
);
473 intel_texobj
->planar_format
= image
->planar_format
;
475 const GLenum internal_format
=
476 image
->internal_format
!= 0 ?
477 image
->internal_format
: _mesa_get_format_base_format(mt
->format
);
478 intel_set_texture_image_mt(brw
, texImage
, internal_format
, mt
);
479 intel_miptree_release(&mt
);
483 * \brief A fast path for glGetTexImage.
485 * \see intel_readpixels_tiled_memcpy()
488 intel_gettexsubimage_tiled_memcpy(struct gl_context
*ctx
,
489 struct gl_texture_image
*texImage
,
490 GLint xoffset
, GLint yoffset
,
491 GLsizei width
, GLsizei height
,
492 GLenum format
, GLenum type
,
494 const struct gl_pixelstore_attrib
*packing
)
496 struct brw_context
*brw
= brw_context(ctx
);
497 struct intel_texture_image
*image
= intel_texture_image(texImage
);
500 /* The miptree's buffer. */
504 mem_copy_fn mem_copy
= NULL
;
506 /* This fastpath is restricted to specific texture types:
507 * a 2D BGRA, RGBA, L8 or A8 texture. It could be generalized to support
510 * FINISHME: The restrictions below on packing alignment and packing row
511 * length are likely unneeded now because we calculate the destination stride
512 * with _mesa_image_row_stride. However, before removing the restrictions
516 !(type
== GL_UNSIGNED_BYTE
|| type
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
517 !(texImage
->TexObject
->Target
== GL_TEXTURE_2D
||
518 texImage
->TexObject
->Target
== GL_TEXTURE_RECTANGLE
) ||
520 _mesa_is_bufferobj(packing
->BufferObj
) ||
521 packing
->Alignment
> 4 ||
522 packing
->SkipPixels
> 0 ||
523 packing
->SkipRows
> 0 ||
524 (packing
->RowLength
!= 0 && packing
->RowLength
!= width
) ||
525 packing
->SwapBytes
||
530 /* We can't handle copying from RGBX or BGRX because the tiled_memcpy
531 * function doesn't set the last channel to 1. Note this checks BaseFormat
532 * rather than TexFormat in case the RGBX format is being simulated with an
535 if (texImage
->_BaseFormat
== GL_RGB
)
538 if (!intel_get_memcpy(texImage
->TexFormat
, format
, type
, &mem_copy
, &cpp
))
541 /* If this is a nontrivial texture view, let another path handle it instead. */
542 if (texImage
->TexObject
->MinLayer
)
546 (image
->mt
->tiling
!= I915_TILING_X
&&
547 image
->mt
->tiling
!= I915_TILING_Y
)) {
548 /* The algorithm is written only for X- or Y-tiled memory. */
552 /* tiled_to_linear() assumes that if the object is swizzled, it is using
553 * I915_BIT6_SWIZZLE_9_10 for X and I915_BIT6_SWIZZLE_9 for Y. This is only
554 * true on gen5 and above.
556 * The killer on top is that some gen4 have an L-shaped swizzle mode, where
557 * parts of the memory aren't swizzled at all. Userspace just can't handle
560 if (brw
->gen
< 5 && brw
->has_swizzling
)
563 int level
= texImage
->Level
+ texImage
->TexObject
->MinLevel
;
565 /* Since we are going to write raw data to the miptree, we need to resolve
566 * any pending fast color clears before we start.
568 assert(image
->mt
->logical_depth0
== 1);
569 intel_miptree_access_raw(brw
, image
->mt
, level
, 0, true);
573 if (brw_batch_references(&brw
->batch
, bo
)) {
574 perf_debug("Flushing before mapping a referenced bo.\n");
575 intel_batchbuffer_flush(brw
);
578 void *map
= brw_bo_map(brw
, bo
, MAP_READ
| MAP_RAW
);
580 DBG("%s: failed to map bo\n", __func__
);
584 dst_pitch
= _mesa_image_row_stride(packing
, width
, format
, type
);
586 DBG("%s: level=%d x,y=(%d,%d) (w,h)=(%d,%d) format=0x%x type=0x%x "
587 "mesa_format=0x%x tiling=%d "
588 "packing=(alignment=%d row_length=%d skip_pixels=%d skip_rows=%d)\n",
589 __func__
, texImage
->Level
, xoffset
, yoffset
, width
, height
,
590 format
, type
, texImage
->TexFormat
, image
->mt
->tiling
,
591 packing
->Alignment
, packing
->RowLength
, packing
->SkipPixels
,
594 /* Adjust x and y offset based on miplevel */
595 xoffset
+= image
->mt
->level
[level
].level_x
;
596 yoffset
+= image
->mt
->level
[level
].level_y
;
599 xoffset
* cpp
, (xoffset
+ width
) * cpp
,
600 yoffset
, yoffset
+ height
,
601 pixels
- (ptrdiff_t) yoffset
* dst_pitch
- (ptrdiff_t) xoffset
* cpp
,
603 dst_pitch
, image
->mt
->pitch
,
614 intel_get_tex_sub_image(struct gl_context
*ctx
,
615 GLint xoffset
, GLint yoffset
, GLint zoffset
,
616 GLsizei width
, GLsizei height
, GLint depth
,
617 GLenum format
, GLenum type
, GLvoid
*pixels
,
618 struct gl_texture_image
*texImage
)
620 struct brw_context
*brw
= brw_context(ctx
);
623 DBG("%s\n", __func__
);
625 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
626 if (_mesa_meta_pbo_GetTexSubImage(ctx
, 3, texImage
,
627 xoffset
, yoffset
, zoffset
,
628 width
, height
, depth
, format
, type
,
629 pixels
, &ctx
->Pack
)) {
630 /* Flush to guarantee coherency between the render cache and other
631 * caches the PBO could potentially be bound to after this point.
632 * See the related comment in intelReadPixels() for a more detailed
635 brw_emit_mi_flush(brw
);
639 perf_debug("%s: fallback to CPU mapping in PBO case\n", __func__
);
642 ok
= intel_gettexsubimage_tiled_memcpy(ctx
, texImage
, xoffset
, yoffset
,
644 format
, type
, pixels
, &ctx
->Pack
);
649 _mesa_meta_GetTexSubImage(ctx
, xoffset
, yoffset
, zoffset
,
650 width
, height
, depth
,
651 format
, type
, pixels
, texImage
);
653 DBG("%s - DONE\n", __func__
);
657 flush_astc_denorms(struct gl_context
*ctx
, GLuint dims
,
658 struct gl_texture_image
*texImage
,
659 GLint xoffset
, GLint yoffset
, GLint zoffset
,
660 GLsizei width
, GLsizei height
, GLsizei depth
)
662 struct compressed_pixelstore store
;
663 _mesa_compute_compressed_pixelstore(dims
, texImage
->TexFormat
,
664 width
, height
, depth
,
665 &ctx
->Unpack
, &store
);
667 for (int slice
= 0; slice
< store
.CopySlices
; slice
++) {
669 /* Map dest texture buffer */
672 ctx
->Driver
.MapTextureImage(ctx
, texImage
, slice
+ zoffset
,
673 xoffset
, yoffset
, width
, height
,
674 GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
,
675 &dstMap
, &dstRowStride
);
679 for (int i
= 0; i
< store
.CopyRowsPerSlice
; i
++) {
681 /* An ASTC block is stored in little endian mode. The byte that
682 * contains bits 0..7 is stored at the lower address in memory.
684 struct astc_void_extent
{
685 uint16_t header
: 12;
686 uint16_t dontcare
[3];
691 } *blocks
= (struct astc_void_extent
*) dstMap
;
693 /* Iterate over every copied block in the row */
694 for (int j
= 0; j
< store
.CopyBytesPerRow
/ 16; j
++) {
696 /* Check if the header matches that of an LDR void-extent block */
697 if (blocks
[j
].header
== 0xDFC) {
699 /* Flush UNORM16 values that would be denormalized */
700 if (blocks
[j
].A
< 4) blocks
[j
].A
= 0;
701 if (blocks
[j
].B
< 4) blocks
[j
].B
= 0;
702 if (blocks
[j
].G
< 4) blocks
[j
].G
= 0;
703 if (blocks
[j
].R
< 4) blocks
[j
].R
= 0;
707 dstMap
+= dstRowStride
;
710 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ zoffset
);
716 intelCompressedTexSubImage(struct gl_context
*ctx
, GLuint dims
,
717 struct gl_texture_image
*texImage
,
718 GLint xoffset
, GLint yoffset
, GLint zoffset
,
719 GLsizei width
, GLsizei height
, GLsizei depth
,
721 GLsizei imageSize
, const GLvoid
*data
)
723 /* Upload the compressed data blocks */
724 _mesa_store_compressed_texsubimage(ctx
, dims
, texImage
,
725 xoffset
, yoffset
, zoffset
,
726 width
, height
, depth
,
727 format
, imageSize
, data
);
729 /* Fix up copied ASTC blocks if necessary */
730 GLenum gl_format
= _mesa_compressed_format_to_glenum(ctx
,
731 texImage
->TexFormat
);
732 bool is_linear_astc
= _mesa_is_astc_format(gl_format
) &&
733 !_mesa_is_srgb_format(gl_format
);
734 struct brw_context
*brw
= (struct brw_context
*) ctx
;
735 if (brw
->gen
== 9 && is_linear_astc
)
736 flush_astc_denorms(ctx
, dims
, texImage
,
737 xoffset
, yoffset
, zoffset
,
738 width
, height
, depth
);
742 intelInitTextureImageFuncs(struct dd_function_table
*functions
)
744 functions
->TexImage
= intelTexImage
;
745 functions
->CompressedTexSubImage
= intelCompressedTexSubImage
;
746 functions
->EGLImageTargetTexture2D
= intel_image_target_texture_2d
;
747 functions
->BindRenderbufferTexImage
= intel_bind_renderbuffer_tex_image
;
748 functions
->GetTexSubImage
= intel_get_tex_sub_image
;