+++ /dev/null
-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:]))
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");
+ }
+}