[Piglit] [PATCH 2/2] arb_vertex_type_10f_10f_11f_rev: add test for draw-vertices

Eric Anholt eric at anholt.net
Thu Nov 7 11:11:42 PST 2013


Chris Forbes <chrisf at ijw.co.nz> writes:

> diff --git a/tests/spec/arb_vertex_type_10f_11f_11f_rev/draw-vertices.c b/tests/spec/arb_vertex_type_10f_11f_11f_rev/draw-vertices.c
> new file mode 100644
> index 0000000..1019777
> --- /dev/null
> +++ b/tests/spec/arb_vertex_type_10f_11f_11f_rev/draw-vertices.c
> @@ -0,0 +1,252 @@
> +/**
> + * \file api-errors.c

filename

> + * This tests a few error conditions from the ARB_vertex_type_10f_11f_11f_rev extension.
> + *
> + * UF10/UF11 packing code based on The OpenGL Programming Guide / 7th Edition, Appendix J,
> + * with bugfix from gallium source.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +	config.supports_gl_compat_version = 30;
> +	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
> +	config.window_width = 128;
> +	config.window_height = 128;
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +
> +#define UF11(e, m)           ((e << 6) | (m))
> +#define UF11_EXPONENT_BIAS   15
> +#define UF11_EXPONENT_BITS   0x1F
> +#define UF11_EXPONENT_SHIFT  6
> +#define UF11_MANTISSA_BITS   0x3F
> +#define UF11_MANTISSA_SHIFT  (23 - UF11_EXPONENT_SHIFT)
> +#define UF11_MAX_EXPONENT    (UF11_EXPONENT_BITS << UF11_EXPONENT_SHIFT)
> +
> +#define UF10(e, m)           ((e << 5) | (m))
> +#define UF10_EXPONENT_BIAS   15
> +#define UF10_EXPONENT_BITS   0x1F
> +#define UF10_EXPONENT_SHIFT  5
> +#define UF10_MANTISSA_BITS   0x1F
> +#define UF10_MANTISSA_SHIFT  (23 - UF10_EXPONENT_SHIFT)
> +#define UF10_MAX_EXPONENT    (UF10_EXPONENT_BITS << UF10_EXPONENT_SHIFT)
> +
> +#define F32_INFINITY         0x7f800000
> +
> +static unsigned f32_to_uf11(float val)
> +{
> +   union {
> +      float f;
> +      uint32_t ui;
> +   } f32 = {val};
> +
> +   uint16_t uf11 = 0;
> +
> +   /* Decode little-endian 32-bit floating-point value */
> +   int sign = (f32.ui >> 16) & 0x8000;
> +   /* Map exponent to the range [-127,128] */
> +   int exponent = ((f32.ui >> 23) & 0xff) - 127;
> +   int mantissa = f32.ui & 0x007fffff;
> +
> +   if (exponent == 128) { /* Infinity or NaN */
> +      /* From the GL_EXT_packed_float spec:
> +       *
> +       *     "Additionally: negative infinity is converted to zero; positive
> +       *      infinity is converted to positive infinity; and both positive and
> +       *      negative NaN are converted to positive NaN."
> +       */
> +      uf11 = UF11_MAX_EXPONENT;
> +      if (mantissa) {
> +         uf11 |= 1; /* NaN */
> +      } else {
> +         if (sign)
> +            uf11 = 0; /* 0.0 */
> +      }
> +   } else if (sign) {
> +      return 0;
> +   } else if (val > 65024.0f) {
> +      /* From the GL_EXT_packed_float spec:
> +       *
> +       *     "Likewise, finite positive values greater than 65024 (the maximum
> +       *      finite representable unsigned 11-bit floating-point value) are
> +       *      converted to 65024."
> +       */
> +      uf11 = UF11(30, 63);
> +   }
> +   else if (exponent > -15) { /* Representable value */
> +      exponent += UF11_EXPONENT_BIAS;
> +      mantissa >>= UF11_MANTISSA_SHIFT;
> +      uf11 = exponent << UF11_EXPONENT_SHIFT | mantissa;
> +   }
> +
> +   return uf11;
> +}
> +
> +static unsigned f32_to_uf10(float val)
> +{
> +   union {
> +      float f;
> +      uint32_t ui;
> +   } f32 = {val};
> +
> +   uint16_t uf10 = 0;
> +
> +   /* Decode little-endian 32-bit floating-point value */
> +   int sign = (f32.ui >> 16) & 0x8000;
> +   /* Map exponent to the range [-127,128] */
> +   int exponent = ((f32.ui >> 23) & 0xff) - 127;
> +   int mantissa = f32.ui & 0x007fffff;
> +
> +   if (exponent == 128) {
> +      /* From the GL_EXT_packed_float spec:
> +       *
> +       *     "Additionally: negative infinity is converted to zero; positive
> +       *      infinity is converted to positive infinity; and both positive and
> +       *      negative NaN are converted to positive NaN."
> +       */
> +      uf10 = UF10_MAX_EXPONENT;
> +      if (mantissa) {
> +         uf10 |= 1; /* NaN */
> +      } else {
> +         if (sign)
> +            uf10 = 0; /* 0.0 */
> +      }
> +   } else if (sign) {
> +      return 0;
> +   } else if (val > 64512.0f) {
> +      /* From the GL_EXT_packed_float spec:
> +       *
> +       *     "Likewise, finite positive values greater than 64512 (the maximum
> +       *      finite representable unsigned 10-bit floating-point value) are
> +       *      converted to 64512."
> +       */
> +      uf10 = UF10(30, 31);
> +   }
> +   else if (exponent > -15) { /* Representable value */
> +      exponent += UF10_EXPONENT_BIAS;
> +      mantissa >>= UF10_MANTISSA_SHIFT;
> +      uf10 = exponent << UF10_EXPONENT_SHIFT | mantissa;
> +   }
> +
> +   return uf10;
> +}
> +
> +static unsigned float3_to_r11g11b10f(const float rgb[3])
> +{
> +   return ( f32_to_uf11(rgb[0]) & 0x7ff) |
> +          ((f32_to_uf11(rgb[1]) & 0x7ff) << 11) |
> +          ((f32_to_uf10(rgb[2]) & 0x3ff) << 22);
> +}

I'd rather see the f32_to_uf11 and friends live in tests/util/ like
rgb9e5.h, since it seems like we ought to use it from other tests, too.

> +static float unpacked_pos[][2] = {
> +	{ -1, 0 },
> +	{ -0.5f, 0 },
> +	{ -1, 0.5f },
> +
> +	{ -0.5f, 0 },
> +	{ 0, 0 },
> +	{ -0.5f, 0.5f },
> +
> +	{ 0, 0 },
> +	{ 0.5f, 0 },
> +	{ 0, 0.5f },
> +
> +	{ 0.5f, 0 },
> +	{ 1, 0 },
> +	{ 0.5f, 0.5f },
> +};
> +
> +static float unpacked_colors[][3] = {
> +	{ 0.5, 0, 1 },
> +	{ 0.5, 0, 0 },
> +	{ 0, 0.5, 0 },
> +	{ 1, 0.5, 0 },
> +};
> +
> +enum piglit_result
> +piglit_display()
> +{
> +	bool pass = true;
> +	glClearColor(0, 0, 1, 0);
> +	glClear(GL_COLOR_BUFFER_BIT);
> +	glDrawArrays(GL_TRIANGLES, 0, 12);
> +
> +	piglit_present_results();
> +
> +	pass = piglit_probe_pixel_rgb(8, 70, unpacked_colors[0]) && pass;
> +	pass = piglit_probe_pixel_rgb(40, 70, unpacked_colors[1]) && pass;
> +	pass = piglit_probe_pixel_rgb(72, 70, unpacked_colors[2]) && pass;
> +	pass = piglit_probe_pixel_rgb(104, 70, unpacked_colors[3]) && pass;

As usual, I'd prefer quads covering the whole window and probe_rect_rgba
(actually, "rgba" is particularly interesting to make sure the right
alpha value comes through).  The window size and clear could be dropped,
in that case.

> +void
> +piglit_init(int argc, char **argv)
> +{
> +	GLuint bo_pos, bo_color, prog;
> +	unsigned int verts[12];
> +	int n;
> +
> +	for (n = 0; n < 12; n++)
> +		verts[n] = float3_to_r11g11b10f(unpacked_colors[n/3]);
> +
> +	piglit_require_extension("GL_ARB_vertex_type_2_10_10_10_rev");
> +	piglit_require_extension("GL_ARB_vertex_type_10f_11f_11f_rev");

Also require explicit_attrib_location since you're using it.  (and
drop 2_10_10_10 again)

> +	glGenBuffers(1, &bo_pos);
> +	glBindBuffer(GL_ARRAY_BUFFER, bo_pos);
> +	glBufferData(GL_ARRAY_BUFFER, sizeof(unpacked_pos), unpacked_pos, GL_STATIC_DRAW);
> +
> +	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid const *)0);
> +	glEnableVertexAttribArray(0);
> +
> +	glGenBuffers(1, &bo_color);
> +	glBindBuffer(GL_ARRAY_BUFFER, bo_color);
> +	glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);

Instead of "verts", call it "colors" since it doesn't contain vertex
locations?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20131107/f4eed0b2/attachment.pgp>


More information about the Piglit mailing list