compiler/glsl: explicitly store NumUniformBlocks
[mesa.git] / src / mesa / main / format_unpack.py
index c8b1b24d16996b1fc30dd40eae052f8bebcb416f..161a402156733392f1113e3743acccf05218aa44 100644 (file)
@@ -1,3 +1,4 @@
+from __future__ import print_function
 
 from mako.template import Template
 from sys import argv
@@ -41,6 +42,7 @@ string = """/*
  */
 
 #include <stdint.h>
+#include <stdlib.h>
 
 #include "format_unpack.h"
 #include "format_utils.h"
@@ -78,7 +80,7 @@ for f in formats:
    %endif
 
 static inline void
-unpack_float_${f.short_name()}(const void *void_src, GLfloat dst[4])
+unpack_float_${f.short_name()}(const void *void_src, float dst[4])
 {
    ${f.datatype()} *src = (${f.datatype()} *)void_src;
    %if f.layout == parser.PACKED:
@@ -133,34 +135,34 @@ unpack_float_${f.short_name()}(const void *void_src, GLfloat dst[4])
 %endfor
 
 static void
-unpack_float_r9g9b9e5_float(const void *src, GLfloat dst[4])
+unpack_float_r9g9b9e5_float(const void *src, float dst[4])
 {
-   rgb9e5_to_float3(*(const GLuint *)src, dst);
+   rgb9e5_to_float3(*(const uint32_t *)src, dst);
    dst[3] = 1.0f;
 }
 
 static void
-unpack_float_r11g11b10_float(const void *src, GLfloat dst[4])
+unpack_float_r11g11b10_float(const void *src, float dst[4])
 {
-   r11g11b10f_to_float3(*(const GLuint *)src, dst);
+   r11g11b10f_to_float3(*(const uint32_t *)src, dst);
    dst[3] = 1.0f;
 }
 
 static void
-unpack_float_ycbcr(const void *src, GLfloat dst[][4], GLuint n)
+unpack_float_ycbcr(const void *src, float dst[][4], uint32_t n)
 {
-   GLuint i;
+   uint32_t i;
    for (i = 0; i < n; i++) {
-      const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
-      const GLushort *src1 = src0 + 1;         /* odd */
-      const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */
-      const GLubyte cb = *src0 & 0xff;         /* chroma U */
-      const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */
-      const GLubyte cr = *src1 & 0xff;         /* chroma V */
-      const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
-      GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
-      GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
-      GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
+      const uint16_t *src0 = ((const uint16_t *) src) + i * 2; /* even */
+      const uint16_t *src1 = src0 + 1;         /* odd */
+      const uint8_t y0 = (*src0 >> 8) & 0xff;  /* luminance */
+      const uint8_t cb = *src0 & 0xff;         /* chroma U */
+      const uint8_t y1 = (*src1 >> 8) & 0xff;  /* luminance */
+      const uint8_t cr = *src1 & 0xff;         /* chroma V */
+      const uint8_t y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
+      float r = 1.164F * (y - 16) + 1.596F * (cr - 128);
+      float g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
+      float b = 1.164F * (y - 16) + 2.018F * (cb - 128);
       r *= (1.0F / 255.0F);
       g *= (1.0F / 255.0F);
       b *= (1.0F / 255.0F);
@@ -172,20 +174,20 @@ unpack_float_ycbcr(const void *src, GLfloat dst[][4], GLuint n)
 }
 
 static void
-unpack_float_ycbcr_rev(const void *src, GLfloat dst[][4], GLuint n)
+unpack_float_ycbcr_rev(const void *src, float dst[][4], uint32_t n)
 {
-   GLuint i;
+   uint32_t i;
    for (i = 0; i < n; i++) {
-      const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
-      const GLushort *src1 = src0 + 1;         /* odd */
-      const GLubyte y0 = *src0 & 0xff;         /* luminance */
-      const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */
-      const GLubyte y1 = *src1 & 0xff;         /* luminance */
-      const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */
-      const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
-      GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
-      GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
-      GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
+      const uint16_t *src0 = ((const uint16_t *) src) + i * 2; /* even */
+      const uint16_t *src1 = src0 + 1;         /* odd */
+      const uint8_t y0 = *src0 & 0xff;         /* luminance */
+      const uint8_t cr = (*src0 >> 8) & 0xff;  /* chroma V */
+      const uint8_t y1 = *src1 & 0xff;         /* luminance */
+      const uint8_t cb = (*src1 >> 8) & 0xff;  /* chroma U */
+      const uint8_t y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
+      float r = 1.164F * (y - 16) + 1.596F * (cr - 128);
+      float g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
+      float b = 1.164F * (y - 16) + 2.018F * (cb - 128);
       r *= (1.0F / 255.0F);
       g *= (1.0F / 255.0F);
       b *= (1.0F / 255.0F);
@@ -204,7 +206,7 @@ unpack_float_ycbcr_rev(const void *src, GLfloat dst[][4], GLuint n)
    %endif
 
 static inline void
-unpack_ubyte_${f.short_name()}(const void *void_src, GLubyte dst[4])
+unpack_ubyte_${f.short_name()}(const void *void_src, uint8_t dst[4])
 {
    ${f.datatype()} *src = (${f.datatype()} *)void_src;
    %if f.layout == parser.PACKED:
@@ -268,7 +270,7 @@ unpack_ubyte_${f.short_name()}(const void *void_src, GLubyte dst[4])
    %endif
 
 static inline void
-unpack_int_${f.short_name()}(const void *void_src, GLuint dst[4])
+unpack_int_${f.short_name()}(const void *void_src, uint32_t dst[4])
 {
    ${f.datatype()} *src = (${f.datatype()} *)void_src;
    %if f.layout == parser.PACKED:
@@ -304,11 +306,11 @@ unpack_int_${f.short_name()}(const void *void_src, GLuint dst[4])
 
 
 void
-_mesa_unpack_rgba_row(mesa_format format, GLuint n,
-                      const void *src, GLfloat dst[][4])
+_mesa_unpack_rgba_row(mesa_format format, uint32_t n,
+                      const void *src, float dst[][4])
 {
-   GLubyte *s = (GLubyte *)src;
-   GLuint i;
+   uint8_t *s = (uint8_t *)src;
+   uint32_t i;
 
    switch (format) {
 %for f in rgb_formats:
@@ -320,7 +322,7 @@ _mesa_unpack_rgba_row(mesa_format format, GLuint n,
    case ${f.name}:
       for (i = 0; i < n; ++i) {
          unpack_float_${f.short_name()}(s, dst[i]);
-         s += ${f.block_size() / 8};
+         s += ${f.block_size() // 8};
       }
       break;
 %endfor
@@ -331,18 +333,16 @@ _mesa_unpack_rgba_row(mesa_format format, GLuint n,
       unpack_float_ycbcr_rev(src, dst, n);
       break;
    default:
-      _mesa_problem(NULL, "%s: bad format %s", __func__,
-                    _mesa_get_format_name(format));
-      return;
+      unreachable("bad format");
    }
 }
 
 void
-_mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n,
-                            const void *src, GLubyte dst[][4])
+_mesa_unpack_ubyte_rgba_row(mesa_format format, uint32_t n,
+                            const void *src, uint8_t dst[][4])
 {
-   GLubyte *s = (GLubyte *)src;
-   GLuint i;
+   uint8_t *s = (uint8_t *)src;
+   uint32_t i;
 
    switch (format) {
 %for f in rgb_formats:
@@ -353,17 +353,17 @@ _mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n,
    case ${f.name}:
       for (i = 0; i < n; ++i) {
          unpack_ubyte_${f.short_name()}(s, dst[i]);
-         s += ${f.block_size() / 8};
+         s += ${f.block_size() // 8};
       }
       break;
 %endfor
    default:
       /* get float values, convert to ubyte */
       {
-         GLfloat *tmp = malloc(n * 4 * sizeof(GLfloat));
+         float *tmp = malloc(n * 4 * sizeof(float));
          if (tmp) {
-            GLuint i;
-            _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
+            uint32_t i;
+            _mesa_unpack_rgba_row(format, n, src, (float (*)[4]) tmp);
             for (i = 0; i < n; i++) {
                dst[i][0] = _mesa_float_to_unorm(tmp[i*4+0], 8);
                dst[i][1] = _mesa_float_to_unorm(tmp[i*4+1], 8);
@@ -378,11 +378,11 @@ _mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n,
 }
 
 void
-_mesa_unpack_uint_rgba_row(mesa_format format, GLuint n,
-                           const void *src, GLuint dst[][4])
+_mesa_unpack_uint_rgba_row(mesa_format format, uint32_t n,
+                           const void *src, uint32_t dst[][4])
 {
-   GLubyte *s = (GLubyte *)src;
-   GLuint i;
+   uint8_t *s = (uint8_t *)src;
+   uint32_t i;
 
    switch (format) {
 %for f in rgb_formats:
@@ -395,14 +395,12 @@ _mesa_unpack_uint_rgba_row(mesa_format format, GLuint n,
    case ${f.name}:
       for (i = 0; i < n; ++i) {
          unpack_int_${f.short_name()}(s, dst[i]);
-         s += ${f.block_size() / 8};
+         s += ${f.block_size() // 8};
       }
       break;
 %endfor
    default:
-      _mesa_problem(NULL, "%s: bad format %s", __func__,
-                    _mesa_get_format_name(format));
-      return;
+      unreachable("bad format");
    }
 }
 
@@ -420,23 +418,23 @@ _mesa_unpack_uint_rgba_row(mesa_format format, GLuint n,
  */
 void
 _mesa_unpack_rgba_block(mesa_format format,
-                        const void *src, GLint srcRowStride,
-                        GLfloat dst[][4], GLint dstRowStride,
-                        GLuint x, GLuint y, GLuint width, GLuint height)
+                        const void *src, int32_t srcRowStride,
+                        float dst[][4], int32_t dstRowStride,
+                        uint32_t x, uint32_t y, uint32_t width, uint32_t height)
 {
-   const GLuint srcPixStride = _mesa_get_format_bytes(format);
-   const GLuint dstPixStride = 4 * sizeof(GLfloat);
-   const GLubyte *srcRow;
-   GLubyte *dstRow;
-   GLuint i;
+   const uint32_t srcPixStride = _mesa_get_format_bytes(format);
+   const uint32_t dstPixStride = 4 * sizeof(float);
+   const uint8_t *srcRow;
+   uint8_t *dstRow;
+   uint32_t i;
 
    /* XXX needs to be fixed for compressed formats */
 
-   srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
-   dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
+   srcRow = ((const uint8_t *) src) + srcRowStride * y + srcPixStride * x;
+   dstRow = ((uint8_t *) dst) + dstRowStride * y + dstPixStride * x;
 
    for (i = 0; i < height; i++) {
-      _mesa_unpack_rgba_row(format, width, srcRow, (GLfloat (*)[4]) dstRow);
+      _mesa_unpack_rgba_row(format, width, srcRow, (float (*)[4]) dstRow);
 
       dstRow += dstRowStride;
       srcRow += srcRowStride;
@@ -450,67 +448,67 @@ struct z32f_x24s8
    uint32_t x24s8;
 };
 
-typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
+typedef void (*unpack_float_z_func)(uint32_t n, const void *src, float *dst);
 
 static void
-unpack_float_z_X8_UINT_Z24_UNORM(GLuint n, const void *src, GLfloat *dst)
+unpack_float_z_X8_UINT_Z24_UNORM(uint32_t n, const void *src, float *dst)
 {
    /* only return Z, not stencil data */
-   const GLuint *s = ((const GLuint *) src);
-   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
-   GLuint i;
+   const uint32_t *s = ((const uint32_t *) src);
+   const double scale = 1.0 / (double) 0xffffff;
+   uint32_t i;
    for (i = 0; i < n; i++) {
-      dst[i] = (GLfloat) ((s[i] >> 8) * scale);
+      dst[i] = (float) ((s[i] >> 8) * scale);
       assert(dst[i] >= 0.0F);
       assert(dst[i] <= 1.0F);
    }
 }
 
 static void
-unpack_float_z_Z24_UNORM_X8_UINT(GLuint n, const void *src, GLfloat *dst)
+unpack_float_z_Z24_UNORM_X8_UINT(uint32_t n, const void *src, float *dst)
 {
    /* only return Z, not stencil data */
-   const GLuint *s = ((const GLuint *) src);
-   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
-   GLuint i;
+   const uint32_t *s = ((const uint32_t *) src);
+   const double scale = 1.0 / (double) 0xffffff;
+   uint32_t i;
    for (i = 0; i < n; i++) {
-      dst[i] = (GLfloat) ((s[i] & 0x00ffffff) * scale);
+      dst[i] = (float) ((s[i] & 0x00ffffff) * scale);
       assert(dst[i] >= 0.0F);
       assert(dst[i] <= 1.0F);
    }
 }
 
 static void
-unpack_float_Z_UNORM16(GLuint n, const void *src, GLfloat *dst)
+unpack_float_Z_UNORM16(uint32_t n, const void *src, float *dst)
 {
-   const GLushort *s = ((const GLushort *) src);
-   GLuint i;
+   const uint16_t *s = ((const uint16_t *) src);
+   uint32_t i;
    for (i = 0; i < n; i++) {
       dst[i] = s[i] * (1.0F / 65535.0F);
    }
 }
 
 static void
-unpack_float_Z_UNORM32(GLuint n, const void *src, GLfloat *dst)
+unpack_float_Z_UNORM32(uint32_t n, const void *src, float *dst)
 {
-   const GLuint *s = ((const GLuint *) src);
-   GLuint i;
+   const uint32_t *s = ((const uint32_t *) src);
+   uint32_t i;
    for (i = 0; i < n; i++) {
       dst[i] = s[i] * (1.0F / 0xffffffff);
    }
 }
 
 static void
-unpack_float_Z_FLOAT32(GLuint n, const void *src, GLfloat *dst)
+unpack_float_Z_FLOAT32(uint32_t n, const void *src, float *dst)
 {
    memcpy(dst, src, n * sizeof(float));
 }
 
 static void
-unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
+unpack_float_z_Z32X24S8(uint32_t n, const void *src, float *dst)
 {
    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
-   GLuint i;
+   uint32_t i;
    for (i = 0; i < n; i++) {
       dst[i] = s[i].z;
    }
@@ -523,8 +521,8 @@ unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
  * The returned values will always be in the range [0.0, 1.0].
  */
 void
-_mesa_unpack_float_z_row(mesa_format format, GLuint n,
-                         const void *src, GLfloat *dst)
+_mesa_unpack_float_z_row(mesa_format format, uint32_t n,
+                         const void *src, float *dst)
 {
    unpack_float_z_func unpack;
 
@@ -550,9 +548,7 @@ _mesa_unpack_float_z_row(mesa_format format, GLuint n,
       unpack = unpack_float_z_Z32X24S8;
       break;
    default:
-      _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
-                    _mesa_get_format_name(format));
-      return;
+      unreachable("bad format in _mesa_unpack_float_z_row");
    }
 
    unpack(n, src, dst);
@@ -560,61 +556,61 @@ _mesa_unpack_float_z_row(mesa_format format, GLuint n,
 
 
 
-typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
+typedef void (*unpack_uint_z_func)(const void *src, uint32_t *dst, uint32_t n);
 
 static void
-unpack_uint_z_X8_UINT_Z24_UNORM(const void *src, GLuint *dst, GLuint n)
+unpack_uint_z_X8_UINT_Z24_UNORM(const void *src, uint32_t *dst, uint32_t n)
 {
    /* only return Z, not stencil data */
-   const GLuint *s = ((const GLuint *) src);
-   GLuint i;
+   const uint32_t *s = ((const uint32_t *) src);
+   uint32_t i;
    for (i = 0; i < n; i++) {
       dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
    }
 }
 
 static void
-unpack_uint_z_Z24_UNORM_X8_UINT(const void *src, GLuint *dst, GLuint n)
+unpack_uint_z_Z24_UNORM_X8_UINT(const void *src, uint32_t *dst, uint32_t n)
 {
    /* only return Z, not stencil data */
-   const GLuint *s = ((const GLuint *) src);
-   GLuint i;
+   const uint32_t *s = ((const uint32_t *) src);
+   uint32_t i;
    for (i = 0; i < n; i++) {
       dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
    }
 }
 
 static void
-unpack_uint_Z_UNORM16(const void *src, GLuint *dst, GLuint n)
+unpack_uint_Z_UNORM16(const void *src, uint32_t *dst, uint32_t n)
 {
-   const GLushort *s = ((const GLushort *)src);
-   GLuint i;
+   const uint16_t *s = ((const uint16_t *)src);
+   uint32_t i;
    for (i = 0; i < n; i++) {
       dst[i] = (s[i] << 16) | s[i];
    }
 }
 
 static void
-unpack_uint_Z_UNORM32(const void *src, GLuint *dst, GLuint n)
+unpack_uint_Z_UNORM32(const void *src, uint32_t *dst, uint32_t n)
 {
-   memcpy(dst, src, n * sizeof(GLuint));
+   memcpy(dst, src, n * sizeof(uint32_t));
 }
 
 static void
-unpack_uint_Z_FLOAT32(const void *src, GLuint *dst, GLuint n)
+unpack_uint_Z_FLOAT32(const void *src, uint32_t *dst, uint32_t n)
 {
    const float *s = (const float *)src;
-   GLuint i;
+   uint32_t i;
    for (i = 0; i < n; i++) {
       dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
    }
 }
 
 static void
-unpack_uint_Z_FLOAT32_X24S8(const void *src, GLuint *dst, GLuint n)
+unpack_uint_Z_FLOAT32_X24S8(const void *src, uint32_t *dst, uint32_t n)
 {
    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
-   GLuint i;
+   uint32_t i;
 
    for (i = 0; i < n; i++) {
       dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
@@ -627,11 +623,11 @@ unpack_uint_Z_FLOAT32_X24S8(const void *src, GLuint *dst, GLuint n)
  * The returned values will always be in the range [0, 0xffffffff].
  */
 void
-_mesa_unpack_uint_z_row(mesa_format format, GLuint n,
-                        const void *src, GLuint *dst)
+_mesa_unpack_uint_z_row(mesa_format format, uint32_t n,
+                        const void *src, uint32_t *dst)
 {
    unpack_uint_z_func unpack;
-   const GLubyte *srcPtr = (GLubyte *) src;
+   const uint8_t *srcPtr = (uint8_t *) src;
 
    switch (format) {
    case MESA_FORMAT_S8_UINT_Z24_UNORM:
@@ -655,9 +651,7 @@ _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
       unpack = unpack_uint_Z_FLOAT32_X24S8;
       break;
    default:
-      _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
-                    _mesa_get_format_name(format));
-      return;
+      unreachable("bad format %s in _mesa_unpack_uint_z_row");
    }
 
    unpack(srcPtr, dst, n);
@@ -665,35 +659,35 @@ _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
 
 
 static void
-unpack_ubyte_s_S_UINT8(const void *src, GLubyte *dst, GLuint n)
+unpack_ubyte_s_S_UINT8(const void *src, uint8_t *dst, uint32_t n)
 {
    memcpy(dst, src, n);
 }
 
 static void
-unpack_ubyte_s_S8_UINT_Z24_UNORM(const void *src, GLubyte *dst, GLuint n)
+unpack_ubyte_s_S8_UINT_Z24_UNORM(const void *src, uint8_t *dst, uint32_t n)
 {
-   GLuint i;
-   const GLuint *src32 = src;
+   uint32_t i;
+   const uint32_t *src32 = src;
 
    for (i = 0; i < n; i++)
       dst[i] = src32[i] & 0xff;
 }
 
 static void
-unpack_ubyte_s_Z24_UNORM_S8_UINT(const void *src, GLubyte *dst, GLuint n)
+unpack_ubyte_s_Z24_UNORM_S8_UINT(const void *src, uint8_t *dst, uint32_t n)
 {
-   GLuint i;
-   const GLuint *src32 = src;
+   uint32_t i;
+   const uint32_t *src32 = src;
 
    for (i = 0; i < n; i++)
       dst[i] = src32[i] >> 24;
 }
 
 static void
-unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void *src, GLubyte *dst, GLuint n)
+unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void *src, uint8_t *dst, uint32_t n)
 {
-   GLuint i;
+   uint32_t i;
    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
 
    for (i = 0; i < n; i++)
@@ -701,8 +695,8 @@ unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void *src, GLubyte *dst, GLuint n)
 }
 
 void
-_mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
-                              const void *src, GLubyte *dst)
+_mesa_unpack_ubyte_stencil_row(mesa_format format, uint32_t n,
+                              const void *src, uint8_t *dst)
 {
    switch (format) {
    case MESA_FORMAT_S_UINT8:
@@ -718,40 +712,38 @@ _mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
       unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(src, dst, n);
       break;
    default:
-      _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
-                    _mesa_get_format_name(format));
-      return;
+      unreachable("bad format %s in _mesa_unpack_ubyte_s_row");
    }
 }
 
 static void
-unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const GLuint *src, GLuint *dst, GLuint n)
+unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const uint32_t *src, uint32_t *dst, uint32_t n)
 {
-   GLuint i;
+   uint32_t i;
 
    for (i = 0; i < n; i++) {
-      GLuint val = src[i];
+      uint32_t val = src[i];
       dst[i] = val >> 24 | val << 8;
    }
 }
 
 static void
-unpack_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
-                                         GLuint *dst, GLuint n)
+unpack_uint_24_8_depth_stencil_Z32_S8X24(const uint32_t *src,
+                                         uint32_t *dst, uint32_t n)
 {
-   GLuint i;
+   uint32_t i;
 
    for (i = 0; i < n; i++) {
       /* 8 bytes per pixel (float + uint32) */
-      GLfloat zf = ((GLfloat *) src)[i * 2 + 0];
-      GLuint z24 = (GLuint) (zf * (GLfloat) 0xffffff);
-      GLuint s = src[i * 2 + 1] & 0xff;
+      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 GLuint *src, GLuint *dst, GLuint n)
+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);
 }
@@ -761,8 +753,8 @@ unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(const GLuint *src, GLuint *dst,
  * \param format  the source data format
  */
 void
-_mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
-                                        const void *src, GLuint *dst)
+_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:
@@ -775,23 +767,20 @@ _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
       unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
       break;
    default:
-      _mesa_problem(NULL,
-                    "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
-                    _mesa_get_format_name(format));
-      return;
+      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 GLuint *src,
-                                            GLuint *dst, GLuint n)
+unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const uint32_t *src,
+                                            uint32_t *dst, uint32_t n)
 {
-   GLuint i;
+   uint32_t i;
    struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
-   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
+   const double scale = 1.0 / (double) 0xffffff;
 
    for (i = 0; i < n; i++) {
-      const GLuint z24 = src[i] & 0xffffff;
+      const uint32_t z24 = src[i] & 0xffffff;
       d[i].z = z24 * scale;
       d[i].x24s8 = src[i] >> 24;
       assert(d[i].z >= 0.0f);
@@ -800,22 +789,22 @@ unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const GLuint *src,
 }
 
 static void
-unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(const GLuint *src,
-                                               GLuint *dst, GLuint n)
+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 GLuint *src,
-                                            GLuint *dst, GLuint n)
+unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const uint32_t *src,
+                                            uint32_t *dst, uint32_t n)
 {
-   GLuint i;
+   uint32_t i;
    struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
-   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
+   const double scale = 1.0 / (double) 0xffffff;
 
    for (i = 0; i < n; i++) {
-      const GLuint z24 = src[i] >> 8;
+      const uint32_t z24 = src[i] >> 8;
       d[i].z = z24 * scale;
       d[i].x24s8 = src[i] & 0xff;
       assert(d[i].z >= 0.0f);
@@ -838,8 +827,8 @@ unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const GLuint *src,
  *          lower 4 bytes                  higher 4 bytes
  */
 void
-_mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
-                                                 const void *src, GLuint *dst)
+_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:
@@ -852,42 +841,12 @@ _mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
       unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(src, dst, n);
       break;
    default:
-      _mesa_problem(NULL,
-                    "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
-                    _mesa_get_format_name(format));
-      return;
+      unreachable("bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row");
    }
 }
 
-/**
- * Unpack depth/stencil
- * \param format  the source data format
- * \param type the destination data type
- */
-void
-_mesa_unpack_depth_stencil_row(mesa_format format, GLuint n,
-                              const void *src, GLenum type,
-                               GLuint *dst)
-{
-   assert(type == GL_UNSIGNED_INT_24_8 ||
-          type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
-
-   switch (type) {
-   case GL_UNSIGNED_INT_24_8:
-      _mesa_unpack_uint_24_8_depth_stencil_row(format, n, src, dst);
-      break;
-   case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
-      _mesa_unpack_float_32_uint_24_8_depth_stencil_row(format, n, src, dst);
-      break;
-   default:
-      _mesa_problem(NULL,
-                    "bad type 0x%x in _mesa_unpack_depth_stencil_row",
-                    type);
-      return;
-   }
-}
 """
 
-template = Template(string);
+template = Template(string, future_imports=['division']);
 
-print template.render(argv = argv[0:])
+print(template.render(argv = argv[0:]))