[Mesa-dev] [PATCH 2/7] st/mesa: generalize st_etc_fallback -> st_compressed_format_fallback
Marek Olšák
maraeo at gmail.com
Mon Jul 23 23:52:02 UTC 2018
From: Marek Olšák <marek.olsak at amd.com>
for ASTC support later
---
src/mesa/state_tracker/st_cb_copyimage.c | 4 ++--
src/mesa/state_tracker/st_cb_texture.c | 24 ++++++++++++++----------
src/mesa/state_tracker/st_texture.h | 2 +-
3 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/src/mesa/state_tracker/st_cb_copyimage.c b/src/mesa/state_tracker/st_cb_copyimage.c
index d160c8c8d30..5230b61877f 100644
--- a/src/mesa/state_tracker/st_cb_copyimage.c
+++ b/src/mesa/state_tracker/st_cb_copyimage.c
@@ -661,22 +661,22 @@ st_CopyImageSubData(struct gl_context *ctx,
dst_z += dst_image->TexObject->MinLayer;
}
} else {
struct st_renderbuffer *dst = st_renderbuffer(dst_renderbuffer);
dst_res = dst->texture;
dst_level = 0;
}
u_box_2d_zslice(src_x, src_y, src_z, src_width, src_height, &box);
- if ((src_image && st_etc_fallback(st, src_image)) ||
- (dst_image && st_etc_fallback(st, dst_image))) {
+ if ((src_image && st_compressed_format_fallback(st, src_image->TexFormat)) ||
+ (dst_image && st_compressed_format_fallback(st, dst_image->TexFormat))) {
fallback_copy_image(st, dst_image, dst_res, dst_x, dst_y, orig_dst_z,
src_image, src_res, src_x, src_y, orig_src_z,
src_width, src_height);
} else {
copy_image(pipe, dst_res, dst_level, dst_x, dst_y, dst_z,
src_res, src_level, &box);
}
}
void
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 99209abcd62..b345b2c6d8b 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -212,32 +212,37 @@ st_FreeTextureImageBuffer(struct gl_context *ctx,
stImage->etc_data = NULL;
}
/* if the texture image is being deallocated, the structure of the
* texture is changing so we'll likely need a new sampler view.
*/
st_texture_release_all_sampler_views(st, stObj);
}
bool
-st_etc_fallback(struct st_context *st, struct gl_texture_image *texImage)
+st_compressed_format_fallback(struct st_context *st, mesa_format format)
{
- return (_mesa_is_format_etc2(texImage->TexFormat) && !st->has_etc2) ||
- (texImage->TexFormat == MESA_FORMAT_ETC1_RGB8 && !st->has_etc1);
+ if (format == MESA_FORMAT_ETC1_RGB8)
+ return !st->has_etc1;
+
+ if (_mesa_is_format_etc2(format))
+ return !st->has_etc2;
+
+ return false;
}
static void
etc_fallback_allocate(struct st_context *st, struct st_texture_image *stImage)
{
struct gl_texture_image *texImage = &stImage->base;
- if (!st_etc_fallback(st, texImage))
+ if (!st_compressed_format_fallback(st, texImage->TexFormat))
return;
if (stImage->etc_data)
free(stImage->etc_data);
unsigned data_size = _mesa_format_image_size(texImage->TexFormat,
texImage->Width2,
texImage->Height2,
texImage->Depth2);
@@ -262,21 +267,21 @@ st_MapTextureImage(struct gl_context *ctx,
assert((mode & ~(GL_MAP_READ_BIT |
GL_MAP_WRITE_BIT |
GL_MAP_INVALIDATE_RANGE_BIT)) == 0);
const enum pipe_transfer_usage transfer_flags =
st_access_flags_to_transfer_flags(mode, false);
map = st_texture_image_map(st, stImage, transfer_flags, x, y, slice, w, h, 1,
&transfer);
if (map) {
- if (st_etc_fallback(st, texImage)) {
+ if (st_compressed_format_fallback(st, texImage->TexFormat)) {
/* ETC isn't supported by all gallium drivers, where it's represented
* by uncompressed formats. We store the compressed data (as it's
* needed for image copies in OES_copy_image), and decompress as
* necessary in Unmap.
*
* Note: all ETC1/ETC2 formats have 4x4 block sizes.
*/
unsigned z = transfer->box.z;
struct st_texture_image_transfer *itransfer = &stImage->transfer[z];
@@ -303,22 +308,23 @@ st_MapTextureImage(struct gl_context *ctx,
/** called via ctx->Driver.UnmapTextureImage() */
static void
st_UnmapTextureImage(struct gl_context *ctx,
struct gl_texture_image *texImage,
GLuint slice)
{
struct st_context *st = st_context(ctx);
struct st_texture_image *stImage = st_texture_image(texImage);
- if (st_etc_fallback(st, texImage)) {
- /* Decompress the ETC texture to the mapped one. */
+ if (st_compressed_format_fallback(st, texImage->TexFormat)) {
+ /* Decompress the compressed image on upload if the driver doesn't
+ * support the compressed format. */
unsigned z = slice + stImage->base.Face;
struct st_texture_image_transfer *itransfer = &stImage->transfer[z];
struct pipe_transfer *transfer = itransfer->transfer;
assert(z == transfer->box.z);
if (transfer->usage & PIPE_TRANSFER_WRITE) {
if (texImage->TexFormat == MESA_FORMAT_ETC1_RGB8) {
_mesa_etc1_unpack_rgba8888(itransfer->map, transfer->stride,
itransfer->temp_data,
@@ -1679,24 +1685,22 @@ st_CompressedTexSubImage(struct gl_context *ctx, GLuint dims,
bool success = false;
/* Check basic pre-conditions for PBO upload */
if (!st->prefer_blit_based_texture_transfer) {
goto fallback;
}
if (!_mesa_is_bufferobj(ctx->Unpack.BufferObj))
goto fallback;
- if (st_etc_fallback(st, texImage)) {
- /* ETC isn't supported and is represented by uncompressed formats. */
+ if (st_compressed_format_fallback(st, texImage->TexFormat))
goto fallback;
- }
if (!dst) {
goto fallback;
}
if (!st->pbo.upload_enabled ||
!screen->get_param(screen, PIPE_CAP_SURFACE_REINTERPRET_BLOCKS)) {
goto fallback;
}
diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h
index c10a2753104..82a5bc7797c 100644
--- a/src/mesa/state_tracker/st_texture.h
+++ b/src/mesa/state_tracker/st_texture.h
@@ -308,21 +308,21 @@ st_texture_image_copy(struct pipe_context *pipe,
extern struct pipe_resource *
st_create_color_map_texture(struct gl_context *ctx);
void
st_destroy_bound_texture_handles(struct st_context *st);
void
st_destroy_bound_image_handles(struct st_context *st);
bool
-st_etc_fallback(struct st_context *st, struct gl_texture_image *texImage);
+st_compressed_format_fallback(struct st_context *st, mesa_format format);
void
st_convert_image(const struct st_context *st, const struct gl_image_unit *u,
struct pipe_image_view *img);
void
st_convert_image_from_unit(const struct st_context *st,
struct pipe_image_view *img,
GLuint imgUnit);
--
2.17.1
More information about the mesa-dev
mailing list