From 839af6545bf2f9a7406725e905ffa702731ddc10 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 19 Apr 2021 15:17:58 -0700 Subject: [PATCH] mesa: Replace _mesa_pack_ubyte_rgba_row() with pack_ubyte_rgba_8unorm(). The major thing that the codegen had was support for expanding integers from byte-per-channel to the target format's channel size. However, the format_utils.c caller never did that for integers, and swrast doesn't have support for integers, so that appears to be dead code. With this done, format_pack.py goes away entirely. I slightly changed the prototype of _mesa_pack_ubyte_rgba_row() to match up with the new function, which involved (mostly) dropping some manual casts from the callers to make their data match the old prototype. Reviewed-by: Ian Romanick Reviewed-by: Adam Jackson Part-of: --- src/mesa/Android.gen.mk | 12 -- src/mesa/Makefile.sources | 1 - src/mesa/main/format_pack.h | 8 +- src/mesa/main/format_pack.py | 196 --------------------------- src/mesa/main/format_utils.c | 5 +- src/mesa/main/tests/mesa_formats.cpp | 2 +- src/mesa/meson.build | 3 +- src/mesa/swrast/s_span.c | 5 +- 8 files changed, 12 insertions(+), 220 deletions(-) delete mode 100644 src/mesa/main/format_pack.py diff --git a/src/mesa/Android.gen.mk b/src/mesa/Android.gen.mk index ae79a7cc0d9..d6a6499628b 100644 --- a/src/mesa/Android.gen.mk +++ b/src/mesa/Android.gen.mk @@ -35,7 +35,6 @@ sources := \ main/api_exec.c \ main/dispatch.h \ main/format_fallback.c \ - main/format_pack.c \ main/format_info.h \ main/remap_helper.h \ main/get_hash.h \ @@ -176,14 +175,3 @@ $(intermediates)/main/format_info.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(FORMAT_ $(intermediates)/main/format_info.h: PRIVATE_XML := $(intermediates)/main/format_info.h: $(format_info_deps) $(call es-gen, $<) - -FORMAT_PACK := $(LOCAL_PATH)/main/format_pack.py -format_pack_deps := \ - $(LOCAL_PATH)/main/formats.csv \ - $(LOCAL_PATH)/main/format_parser.py \ - $(FORMAT_PACK) - -$(intermediates)/main/format_pack.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(FORMAT_PACK) -$(intermediates)/main/format_pack.c: PRIVATE_XML := -$(intermediates)/main/format_pack.c: $(format_pack_deps) - $(call es-gen, $<) diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources index c53a8a9ba1d..53242281db2 100644 --- a/src/mesa/Makefile.sources +++ b/src/mesa/Makefile.sources @@ -99,7 +99,6 @@ MAIN_FILES = \ main/format_fallback.c \ main/format_info.h \ main/format_pack.h \ - main/format_pack.c \ main/format_unpack.h \ main/formatquery.c \ main/formatquery.h \ diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h index fce4045ac36..76b1c6a9eea 100644 --- a/src/mesa/main/format_pack.h +++ b/src/mesa/main/format_pack.h @@ -41,9 +41,13 @@ _mesa_pack_float_rgba_row(mesa_format format, uint32_t n, util_format_pack_rgba(format, dst, src, n); } -extern void +static inline void _mesa_pack_ubyte_rgba_row(mesa_format format, uint32_t n, - const uint8_t src[][4], void *dst); + const uint8_t *src, void *dst) +{ + const struct util_format_pack_description *pack = util_format_pack_description(format); + pack->pack_rgba_8unorm((uint8_t *)dst, 0, src, 0, n, 1); +} static inline void _mesa_pack_uint_rgba_row(mesa_format format, uint32_t n, diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py deleted file mode 100644 index c8df4b3ec73..00000000000 --- a/src/mesa/main/format_pack.py +++ /dev/null @@ -1,196 +0,0 @@ -from __future__ import print_function - -from mako.template import Template -from sys import argv - -string = """/* - * Mesa 3-D graphics library - * - * Copyright (c) 2011 VMware, Inc. - * Copyright (c) 2014 Intel Corporation. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/** - * Color, depth, stencil packing functions. - * Used to pack basic color, depth and stencil formats to specific - * hardware formats. - * - * There are both per-pixel and per-row packing functions: - * - The former will be used by swrast to write values to the color, depth, - * stencil buffers when drawing points, lines and masked spans. - * - The later will be used for image-oriented functions like glDrawPixels, - * glAccum, and glTexImage. - */ - -#include - -#include "format_pack.h" -#include "format_utils.h" -#include "macros.h" -#include "util/format_rgb9e5.h" -#include "util/format_r11g11b10f.h" -#include "util/format_srgb.h" - -#define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS)) -#define PACK(SRC, OFFSET, BITS) (((SRC) & MAX_UINT(BITS)) << (OFFSET)) - -<% -import format_parser as parser - -formats = parser.parse(argv[1]) - -rgb_formats = [] -for f in formats: - if f.name == 'MESA_FORMAT_NONE': - continue - if f.colorspace not in ('rgb', 'srgb'): - continue - - rgb_formats.append(f) -%> - -/* ubyte packing functions */ - -%for f in rgb_formats: - %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'): - <% continue %> - %elif f.is_compressed(): - <% continue %> - %endif - -static inline void -pack_ubyte_${f.short_name()}(const uint8_t src[4], void *dst) -{ - %for (i, c) in enumerate(f.channels): - <% i = f.swizzle.inverse()[i] %> - %if c.type == 'x': - <% continue %> - %endif - - ${c.datatype()} ${c.name} = - %if not f.is_normalized() and f.is_int(): - %if c.type == parser.SIGNED: - _mesa_unsigned_to_signed(src[${i}], ${c.size}); - %else: - _mesa_unsigned_to_unsigned(src[${i}], ${c.size}); - %endif - %elif c.type == parser.UNSIGNED: - %if f.colorspace == 'srgb' and c.name in 'rgb': - <% assert c.size == 8 %> - util_format_linear_to_srgb_8unorm(src[${i}]); - %else: - _mesa_unorm_to_unorm(src[${i}], 8, ${c.size}); - %endif - %elif c.type == parser.SIGNED: - _mesa_unorm_to_snorm(src[${i}], 8, ${c.size}); - %elif c.type == parser.FLOAT: - %if c.size == 32: - _mesa_unorm_to_float(src[${i}], 8); - %elif c.size == 16: - _mesa_unorm_to_half(src[${i}], 8); - %else: - <% assert False %> - %endif - %else: - <% assert False %> - %endif - %endfor - - %if f.layout == parser.ARRAY: - ${f.datatype()} *d = (${f.datatype()} *)dst; - %for (i, c) in enumerate(f.channels): - %if c.type == 'x': - <% continue %> - %endif - d[${i}] = ${c.name}; - %endfor - %elif f.layout == parser.PACKED: - ${f.datatype()} d = 0; - %for (i, c) in enumerate(f.channels): - %if c.type == 'x': - <% continue %> - %endif - d |= PACK(${c.name}, ${c.shift}, ${c.size}); - %endfor - (*(${f.datatype()} *)dst) = d; - %else: - <% assert False %> - %endif -} -%endfor - -static inline void -pack_ubyte_r9g9b9e5_float(const uint8_t src[4], void *dst) -{ - uint32_t *d = (uint32_t *) dst; - float rgb[3]; - rgb[0] = _mesa_unorm_to_float(src[0], 8); - rgb[1] = _mesa_unorm_to_float(src[1], 8); - rgb[2] = _mesa_unorm_to_float(src[2], 8); - *d = float3_to_rgb9e5(rgb); -} - -static inline void -pack_ubyte_r11g11b10_float(const uint8_t src[4], void *dst) -{ - uint32_t *d = (uint32_t *) dst; - float rgb[3]; - rgb[0] = _mesa_unorm_to_float(src[0], 8); - rgb[1] = _mesa_unorm_to_float(src[1], 8); - rgb[2] = _mesa_unorm_to_float(src[2], 8); - *d = float3_to_r11g11b10f(rgb); -} - - -/** - * Pack a row of uint8_t rgba[4] values to the destination. - */ -void -_mesa_pack_ubyte_rgba_row(mesa_format format, uint32_t n, - const uint8_t src[][4], void *dst) -{ - uint32_t i; - uint8_t *d = dst; - - switch (format) { -%for f in rgb_formats: - %if f.is_compressed(): - <% continue %> - %endif - - case ${f.name}: - for (i = 0; i < n; ++i) { - pack_ubyte_${f.short_name()}(src[i], d); - d += ${f.block_size() // 8}; - } - break; -%endfor - default: - assert(!"Invalid format"); - } -} - -""" - -template = Template(string, future_imports=['division']) - -print(template.render(argv=argv[0:])) diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c index 1ac1cf36bc8..75f6b67ec53 100644 --- a/src/mesa/main/format_utils.c +++ b/src/mesa/main/format_utils.c @@ -393,8 +393,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, } else { for (row = 0; row < height; ++row) { - _mesa_pack_ubyte_rgba_row(dst_format, width, - (const uint8_t (*)[4])src, dst); + _mesa_pack_ubyte_rgba_row(dst_format, width, src, dst); src += src_stride; dst += dst_stride; } @@ -653,7 +652,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, } else { for (row = 0; row < height; ++row) { _mesa_pack_ubyte_rgba_row(dst_format, width, - (const uint8_t (*)[4])tmp_ubyte + row * width, dst); + (const uint8_t *)(tmp_ubyte + row * width), dst); dst += dst_stride; } } diff --git a/src/mesa/main/tests/mesa_formats.cpp b/src/mesa/main/tests/mesa_formats.cpp index 6d81ce67c5b..ae59c438b32 100644 --- a/src/mesa/main/tests/mesa_formats.cpp +++ b/src/mesa/main/tests/mesa_formats.cpp @@ -278,7 +278,7 @@ TEST(MesaFormatsTest, PackUbyteRGBARounding) for (int i = 0; i <= 255; i++) { uint8_t val[4] = {(uint8_t)i, 0, 0, 0}; uint16_t result; - _mesa_pack_ubyte_rgba_row(MESA_FORMAT_R5G6B5_UNORM, 1, &val, &result); + _mesa_pack_ubyte_rgba_row(MESA_FORMAT_R5G6B5_UNORM, 1, val, &result); EXPECT_EQ(result, (i * 31 + 127) / 255); } } diff --git a/src/mesa/meson.build b/src/mesa/meson.build index a3837e47a7b..05818f09654 100644 --- a/src/mesa/meson.build +++ b/src/mesa/meson.build @@ -667,8 +667,7 @@ get_hash_h = custom_target( capture : true, ) -foreach x : [['format_info.h', 'format_info.py'], - ['format_pack.c', 'format_pack.py']] +foreach x : [['format_info.h', 'format_info.py']] files_libmesa_common += custom_target( x[0], input : ['main/@0@'.format(x[1]), 'main/formats.csv'], diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index d20cea5eaa3..cba2ddcb4c3 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -1075,8 +1075,7 @@ _swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb, if (!mask) { if (datatype == GL_UNSIGNED_BYTE) { - _mesa_pack_ubyte_rgba_row(rb->Format, count, - (const GLubyte (*)[4]) values, dst); + _mesa_pack_ubyte_rgba_row(rb->Format, count, values, dst); } else { assert(datatype == GL_FLOAT); @@ -1103,7 +1102,7 @@ _swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb, if (runLen > 0) { if (datatype == GL_UNSIGNED_BYTE) { _mesa_pack_ubyte_rgba_row(rb->Format, runLen, - (const GLubyte (*)[4]) values + runStart, + (uint8_t *)values + runStart, dst + runStart * bpp); } else {