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@amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6297>
This commit is contained in:
Eric Anholt 2019-11-07 14:16:30 -08:00 committed by Marge Bot
parent 85f237634c
commit 92e8e94ee9
6 changed files with 138 additions and 235 deletions

View file

@ -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, $<)

View file

@ -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 \

View file

@ -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',

View file

@ -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:]))

View file

@ -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");
}
}

View file

@ -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'],