[Piglit] [PATCH 2/3 v2] arb_internalformat_query: Verify glGetInternalformativ doesn't over-run the buffer

Eric Anholt eric at anholt.net
Wed Dec 19 11:23:31 PST 2012


Ian Romanick <idr at freedesktop.org> writes:

> From: Ian Romanick <ian.d.romanick at intel.com>
>
> This test passes on NVIDIA's closed-source driver (version 304.64 on
> GTX 260).
>
> This test fails on AMD's closed-source driver (Catalyst 12.6 on HD
> 3650).  Queries of GL_NUM_SAMPLE_COUNTS merrily write data even when
> bufSize is zero.
>
> v2: Add some comments describing the non-obvious test method.  Use a
> fixed sentinal value instead of inverting a previous result.  Require
> compat version 3.0.  Based on review comments from Eric Anholt.
> +	/* Try GL_SAMPLES.
> +	 *
> +	 * Call it once with the full size buffer.  Smash the data in the
> +	 * buffer.  Call it again with a buffer size of 1.  Verify that all of
> +	 * the data after the first element is still the smashed data.
> +	 */
> +	memset(buffer, 0x7e, buffer_size_in_bytes);
> +
> +	glGetInternalformativ(GL_RENDERBUFFER,
> +			      format,
> +			      GL_SAMPLES,
> +			      buffer_size_in_elements,
> +			      buffer);
> +	pass = piglit_check_gl_error(0)
> +		&& pass;
> +
> +	for (i = 0; i < buffer_size_in_elements; i++) {
> +		buffer[i] = ~buffer[i];
> +		buffer_copy[i] = buffer[i];
> +	}
> +
> +	glGetInternalformativ(GL_RENDERBUFFER,
> +			      format,
> +			      GL_SAMPLES,
> +			      1,
> +			      buffer);
> +	pass = piglit_check_gl_error(0)
> +		&& pass;
> +
> +	for (i = 1; i < buffer_size_in_elements; i++) {
> +		if (buffer[i] != buffer_copy[i]) {
> +			fprintf(stderr,
> +				"pname = GL_SAMPLES, bufSize = 1 "
> +				"over-ran the buffer at element %u.\n",
> +				i);
> +			pass = false;
> +		}
> +	}


The code I'd been imagining:

	/* Try GL_SAMPLES.
	 *
	 * Call it once with a full size buffer.
	 *
	 * Then, memset another buffer to junk and call it with a buffer size of
	 * 1. Verify that all of the data after the first element is still the
	 * junk data.
	 */
	glGetInternalformativ(GL_RENDERBUFFER,
			      format,
			      GL_SAMPLES,
			      buffer_size_in_elements,
			      buffer_copy);
	pass = piglit_check_gl_error(0) && pass;

	memset(buffer, 0x7e, buffer_size_in_bytes);
	glGetInternalformativ(GL_RENDERBUFFER,
			      format,
			      GL_SAMPLES,
			      1,
			      buffer);
	pass = piglit_check_gl_error(0) && pass;

	if (buffer[0] != buffer_copy[0]) {
		fprintf(stderr,
			"pname = GL_SAMPLES, bufSize = 1 "
			"failed to write the first element.\n",
			i);
		pass = false;
	}

	for (i = 1; i < buffer_size_in_elements; i++) {
		if (buffer[i] != 0x7e7e7e7e) {
			fprintf(stderr,
				"pname = GL_SAMPLES, bufSize = 1 "
				"over-ran the buffer at element %u.\n",
				i);
			pass = false;
		}
	}

Either way though, I was at least able to follow the logic this time.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20121219/ae0119a3/attachment.pgp>


More information about the Piglit mailing list