Mesa (master): mesa: Move the rest of format_unpack.py out of code generation.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jan 15 19:15:28 UTC 2021
Module: Mesa
Branch: master
Commit: 92e8e94ee9ff5bf584196bb9bce52f55b734fc78
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=92e8e94ee9ff5bf584196bb9bce52f55b734fc78
Author: Eric Anholt <eric at anholt.net>
Date: Thu Nov 7 14:16:30 2019 -0800
mesa: Move the rest of format_unpack.py out of code generation.
There's nothing conditional any more in the template, so just move it
to plain .c code at last.
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6297>
---
src/mesa/Android.gen.mk | 12 ---
src/mesa/Makefile.sources | 1 -
src/mesa/SConscript | 7 --
src/mesa/main/format_unpack.py | 213 -----------------------------------------
src/mesa/main/pack.c | 137 ++++++++++++++++++++++++++
src/mesa/meson.build | 3 +-
6 files changed, 138 insertions(+), 235 deletions(-)
diff --git a/src/mesa/Android.gen.mk b/src/mesa/Android.gen.mk
index f326143d791..ae79a7cc0d9 100644
--- a/src/mesa/Android.gen.mk
+++ b/src/mesa/Android.gen.mk
@@ -36,7 +36,6 @@ sources := \
main/dispatch.h \
main/format_fallback.c \
main/format_pack.c \
- main/format_unpack.c \
main/format_info.h \
main/remap_helper.h \
main/get_hash.h \
@@ -188,14 +187,3 @@ $(intermediates)/main/format_pack.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(FORMAT_
$(intermediates)/main/format_pack.c: PRIVATE_XML :=
$(intermediates)/main/format_pack.c: $(format_pack_deps)
$(call es-gen, $<)
-
-FORMAT_UNPACK := $(LOCAL_PATH)/main/format_unpack.py
-format_unpack_deps := \
- $(LOCAL_PATH)/main/formats.csv \
- $(LOCAL_PATH)/main/format_parser.py \
- $(FORMAT_UNPACK)
-
-$(intermediates)/main/format_unpack.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(FORMAT_UNPACK)
-$(intermediates)/main/format_unpack.c: PRIVATE_XML :=
-$(intermediates)/main/format_unpack.c: $(format_unpack_deps)
- $(call es-gen, $<)
diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index 3ec14d1607f..83addd8ac14 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -101,7 +101,6 @@ MAIN_FILES = \
main/format_pack.h \
main/format_pack.c \
main/format_unpack.h \
- main/format_unpack.c \
main/formatquery.c \
main/formatquery.h \
main/formats.c \
diff --git a/src/mesa/SConscript b/src/mesa/SConscript
index bba4101ea58..e238e0916db 100644
--- a/src/mesa/SConscript
+++ b/src/mesa/SConscript
@@ -67,13 +67,6 @@ format_pack = env.CodeGenerate(
command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
)
-format_unpack = env.CodeGenerate(
- target = 'main/format_unpack.c',
- script = 'main/format_unpack.py',
- source = 'main/formats.csv',
- command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
-)
-
format_fallback = env.CodeGenerate(
target = 'main/format_fallback.c',
script = 'main/format_fallback.py',
diff --git a/src/mesa/main/format_unpack.py b/src/mesa/main/format_unpack.py
deleted file mode 100644
index 878b81e152f..00000000000
--- a/src/mesa/main/format_unpack.py
+++ /dev/null
@@ -1,213 +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 <stdint.h>
-#include <stdlib.h>
-
-#include "format_unpack.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))
-
-<%
-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)
-%>
-
-
-/** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
-struct z32f_x24s8
-{
- float z;
- uint32_t x24s8;
-};
-
-
-static void
-unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const uint32_t *src, uint32_t *dst, uint32_t n)
-{
- uint32_t i;
-
- for (i = 0; i < n; i++) {
- uint32_t val = src[i];
- dst[i] = val >> 24 | val << 8;
- }
-}
-
-static void
-unpack_uint_24_8_depth_stencil_Z32_S8X24(const uint32_t *src,
- uint32_t *dst, uint32_t n)
-{
- uint32_t i;
-
- for (i = 0; i < n; i++) {
- /* 8 bytes per pixel (float + uint32) */
- float zf = ((float *) src)[i * 2 + 0];
- uint32_t z24 = (uint32_t) (zf * (float) 0xffffff);
- uint32_t s = src[i * 2 + 1] & 0xff;
- dst[i] = (z24 << 8) | s;
- }
-}
-
-static void
-unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(const uint32_t *src, uint32_t *dst, uint32_t n)
-{
- memcpy(dst, src, n * 4);
-}
-
-/**
- * Unpack depth/stencil returning as GL_UNSIGNED_INT_24_8.
- * \param format the source data format
- */
-void
-_mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, uint32_t n,
- const void *src, uint32_t *dst)
-{
- switch (format) {
- case MESA_FORMAT_S8_UINT_Z24_UNORM:
- unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(src, dst, n);
- break;
- case MESA_FORMAT_Z24_UNORM_S8_UINT:
- unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(src, dst, n);
- break;
- case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
- unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
- break;
- default:
- unreachable("bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row");
- }
-}
-
-static void
-unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const uint32_t *src,
- uint32_t *dst, uint32_t n)
-{
- uint32_t i;
- struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
- const double scale = 1.0 / (double) 0xffffff;
-
- for (i = 0; i < n; i++) {
- const uint32_t z24 = src[i] & 0xffffff;
- d[i].z = z24 * scale;
- d[i].x24s8 = src[i] >> 24;
- assert(d[i].z >= 0.0f);
- assert(d[i].z <= 1.0f);
- }
-}
-
-static void
-unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(const uint32_t *src,
- uint32_t *dst, uint32_t n)
-{
- memcpy(dst, src, n * sizeof(struct z32f_x24s8));
-}
-
-static void
-unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const uint32_t *src,
- uint32_t *dst, uint32_t n)
-{
- uint32_t i;
- struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
- const double scale = 1.0 / (double) 0xffffff;
-
- for (i = 0; i < n; i++) {
- const uint32_t z24 = src[i] >> 8;
- d[i].z = z24 * scale;
- d[i].x24s8 = src[i] & 0xff;
- assert(d[i].z >= 0.0f);
- assert(d[i].z <= 1.0f);
- }
-}
-
-/**
- * Unpack depth/stencil returning as GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
- * \param format the source data format
- *
- * In GL_FLOAT_32_UNSIGNED_INT_24_8_REV lower 4 bytes contain float
- * component and higher 4 bytes contain packed 24-bit and 8-bit
- * components.
- *
- * 31 30 29 28 ... 4 3 2 1 0 31 30 29 ... 9 8 7 6 5 ... 2 1 0
- * +-------------------------+ +--------------------------------+
- * | Float Component | | Unused | 8 bit stencil |
- * +-------------------------+ +--------------------------------+
- * lower 4 bytes higher 4 bytes
- */
-void
-_mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, uint32_t n,
- const void *src, uint32_t *dst)
-{
- switch (format) {
- case MESA_FORMAT_S8_UINT_Z24_UNORM:
- unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(src, dst, n);
- break;
- case MESA_FORMAT_Z24_UNORM_S8_UINT:
- unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(src, dst, n);
- break;
- case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
- unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(src, dst, n);
- break;
- default:
- unreachable("bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row");
- }
-}
-
-"""
-
-template = Template(string, future_imports=['division']);
-
-print(template.render(argv = argv[0:]))
diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 4cc843613a0..9d7d235d2e2 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -1694,3 +1694,140 @@ _mesa_unpack_rgba_block(mesa_format format,
unpack->unpack_rgba(dstRow, dstPixStride,
srcRow, srcRowStride, width, height);
}
+
+/** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
+struct z32f_x24s8
+{
+ float z;
+ uint32_t x24s8;
+};
+
+
+static void
+unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const uint32_t *src, uint32_t *dst, uint32_t n)
+{
+ uint32_t i;
+
+ for (i = 0; i < n; i++) {
+ uint32_t val = src[i];
+ dst[i] = val >> 24 | val << 8;
+ }
+}
+
+static void
+unpack_uint_24_8_depth_stencil_Z32_S8X24(const uint32_t *src,
+ uint32_t *dst, uint32_t n)
+{
+ uint32_t i;
+
+ for (i = 0; i < n; i++) {
+ /* 8 bytes per pixel (float + uint32) */
+ float zf = ((float *) src)[i * 2 + 0];
+ uint32_t z24 = (uint32_t) (zf * (float) 0xffffff);
+ uint32_t s = src[i * 2 + 1] & 0xff;
+ dst[i] = (z24 << 8) | s;
+ }
+}
+
+static void
+unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(const uint32_t *src, uint32_t *dst, uint32_t n)
+{
+ memcpy(dst, src, n * 4);
+}
+
+/**
+ * Unpack depth/stencil returning as GL_UNSIGNED_INT_24_8.
+ * \param format the source data format
+ */
+void
+_mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, uint32_t n,
+ const void *src, uint32_t *dst)
+{
+ switch (format) {
+ case MESA_FORMAT_S8_UINT_Z24_UNORM:
+ unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(src, dst, n);
+ break;
+ case MESA_FORMAT_Z24_UNORM_S8_UINT:
+ unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(src, dst, n);
+ break;
+ case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
+ unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
+ break;
+ default:
+ unreachable("bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row");
+ }
+}
+
+static void
+unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const uint32_t *src,
+ uint32_t *dst, uint32_t n)
+{
+ uint32_t i;
+ struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
+ const double scale = 1.0 / (double) 0xffffff;
+
+ for (i = 0; i < n; i++) {
+ const uint32_t z24 = src[i] & 0xffffff;
+ d[i].z = z24 * scale;
+ d[i].x24s8 = src[i] >> 24;
+ assert(d[i].z >= 0.0f);
+ assert(d[i].z <= 1.0f);
+ }
+}
+
+static void
+unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(const uint32_t *src,
+ uint32_t *dst, uint32_t n)
+{
+ memcpy(dst, src, n * sizeof(struct z32f_x24s8));
+}
+
+static void
+unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const uint32_t *src,
+ uint32_t *dst, uint32_t n)
+{
+ uint32_t i;
+ struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
+ const double scale = 1.0 / (double) 0xffffff;
+
+ for (i = 0; i < n; i++) {
+ const uint32_t z24 = src[i] >> 8;
+ d[i].z = z24 * scale;
+ d[i].x24s8 = src[i] & 0xff;
+ assert(d[i].z >= 0.0f);
+ assert(d[i].z <= 1.0f);
+ }
+}
+
+/**
+ * Unpack depth/stencil returning as GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
+ * \param format the source data format
+ *
+ * In GL_FLOAT_32_UNSIGNED_INT_24_8_REV lower 4 bytes contain float
+ * component and higher 4 bytes contain packed 24-bit and 8-bit
+ * components.
+ *
+ * 31 30 29 28 ... 4 3 2 1 0 31 30 29 ... 9 8 7 6 5 ... 2 1 0
+ * +-------------------------+ +--------------------------------+
+ * | Float Component | | Unused | 8 bit stencil |
+ * +-------------------------+ +--------------------------------+
+ * lower 4 bytes higher 4 bytes
+ */
+void
+_mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, uint32_t n,
+ const void *src, uint32_t *dst)
+{
+ switch (format) {
+ case MESA_FORMAT_S8_UINT_Z24_UNORM:
+ unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(src, dst, n);
+ break;
+ case MESA_FORMAT_Z24_UNORM_S8_UINT:
+ unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(src, dst, n);
+ break;
+ case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
+ unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(src, dst, n);
+ break;
+ default:
+ unreachable("bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row");
+ }
+}
diff --git a/src/mesa/meson.build b/src/mesa/meson.build
index 7c10b0ac108..d986a0a17a0 100644
--- a/src/mesa/meson.build
+++ b/src/mesa/meson.build
@@ -668,8 +668,7 @@ get_hash_h = custom_target(
)
foreach x : [['format_info.h', 'format_info.py'],
- ['format_pack.c', 'format_pack.py'],
- ['format_unpack.c', 'format_unpack.py']]
+ ['format_pack.c', 'format_pack.py']]
files_libmesa_common += custom_target(
x[0],
input : ['main/@0@'.format(x[1]), 'main/formats.csv'],
More information about the mesa-commit
mailing list