summaryrefslogtreecommitdiff
path: root/tests/spec/arb_copy_image/api_errors.c
blob: 75cd274393d7ce6e27930dbd7a8dc8a585cda14c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
 * Copyright 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 (including the next
 * paragraph) 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.
 */

/** @file simple.c
 *
 * A simple test of glCopyImageSubData that copies a square from one
 * 2D texture to another and back.  This test exercises texture to texture,
 * texture to renderbuffer, renderbuffer to texture, and renderbuffer to
 * renderbuffer copies.
 */
#include "piglit-util-gl.h"

PIGLIT_GL_TEST_CONFIG_BEGIN

	config.supports_gl_compat_version = 13;
	config.khr_no_error_support = PIGLIT_HAS_ERRORS;

PIGLIT_GL_TEST_CONFIG_END

#define ARRAY_LENGTH(X) (sizeof(X)/sizeof(*(X)))

void
piglit_init(int argc, char **argv)
{
	piglit_require_extension("GL_ARB_copy_image");
	piglit_require_extension("GL_EXT_framebuffer_object");
}

static GLuint
image_create(GLenum target)
{
	GLuint name;
	if (target == GL_RENDERBUFFER_EXT)
		glGenRenderbuffers(1, &name);
	else
		glGenTextures(1, &name);
	return name;
}

static void
image_delete(GLenum target, GLuint name)
{
	if (target == GL_RENDERBUFFER_EXT)
		glDeleteRenderbuffers(1, &name);
	else
		glDeleteTextures(1, &name);
}

static void
image_storage(GLenum target, GLuint name, GLenum internal_format,
	      GLsizei width, GLsizei height)
{
	if (target == GL_RENDERBUFFER_EXT) {
		glBindRenderbuffer(target, name);
		glRenderbufferStorage(target, internal_format, width, height);
	} else {
		glBindTexture(target, name);
		glTexStorage2D(target, 4, internal_format, width, height);
	}
}

/* only testing legal targets below */
static const GLenum targets[] = {
	GL_TEXTURE_1D,
	GL_TEXTURE_1D_ARRAY,
	GL_TEXTURE_2D,
	GL_TEXTURE_RECTANGLE,
	GL_TEXTURE_2D_ARRAY,
	GL_TEXTURE_2D_MULTISAMPLE,
	GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
	GL_TEXTURE_CUBE_MAP,
	GL_TEXTURE_CUBE_MAP_ARRAY,
	GL_TEXTURE_3D
};

static bool
test_simple_errors(GLenum src_target, GLenum dst_target)
{
	bool pass = true;
	GLuint i, src, src2, dst;

	src = image_create(src_target);
	dst = image_create(dst_target);

	/* Test all three combinations of incomplete src or dst  */
	glCopyImageSubData(src, src_target, 0, 0, 0, 0,
			   dst, dst_target, 0, 0, 0, 0, 0, 0, 0);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	image_storage(src_target, src, GL_RGBA8, 32, 32);
	assert(piglit_check_gl_error(GL_NO_ERROR));

	glCopyImageSubData(src, src_target, 0, 0, 0, 0,
			   dst, dst_target, 0, 0, 0, 0, 0, 0, 0);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	image_storage(dst_target, dst, GL_RGBA8, 32, 32);
	assert(piglit_check_gl_error(GL_NO_ERROR));

	/* We want to test with empty src but valid dst */
	src2 = image_create(src_target);

	glCopyImageSubData(src2, src_target, 0, 0, 0, 0,
			   dst, dst_target, 0, 0, 0, 0, 0, 0, 0);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	/* This is no longer needed */
	image_delete(src_target, src2);

	/* Section 18.3.2 (Copying Between Images) of the OpenGL 4.5 Core
	 * Profile spec says:
	 *
	 *     "An INVALID_ENUM error is generated if either target is
	 *      not RENDERBUFFER or a valid non-proxy texture target;
	 *      is TEXTURE_BUFFER or one of the cubemap face selectors
	 *      described in table 8.18; or if the target does not
	 *      match the type of the object."
	 */
	if (src_target != GL_RENDERBUFFER_EXT) {
		for (i = 0; i < ARRAY_LENGTH(targets); ++i) {
			if (targets[i] == src_target)
				continue;

			/* here, targets[i] doesn't match src object's target */
			glCopyImageSubData(src, targets[i], 0, 0, 0, 0,
					   dst, dst_target, 0, 0, 0, 0,
					   0, 0, 0);
			pass &= piglit_check_gl_error(GL_INVALID_ENUM);
			if (!pass)
				return false;
		}
	}

	/* Section 18.3.2 (Copying Between Images) of the OpenGL 4.5 Core
	 * Profile spec says:
	 *
	 *     "An INVALID_ENUM error is generated if either target is
	 *      not RENDERBUFFER or a valid non-proxy texture target;
	 *      is TEXTURE_BUFFER or one of the cubemap face selectors
	 *      described in table 8.18; or if the target does not
	 *      match the type of the object."
	 */
	if (dst_target != GL_RENDERBUFFER_EXT) {
		for (i = 0; i < ARRAY_LENGTH(targets); ++i) {
			if (targets[i] == dst_target)
				continue;

			/* here, targets[i] doesn't match dst object's target */
			glCopyImageSubData(src, src_target, 0, 0, 0, 0,
					   dst, targets[i], 0, 0, 0, 0,
					   0, 0, 0);
			pass &= piglit_check_gl_error(GL_INVALID_ENUM);
			if (!pass)
				return false;
		}
	}

	/* Section 18.3.2 (Copying Between Images) of the OpenGL 4.5 Core
	 * Profile spec says:
	 *
	 *     "An INVALID_VALUE error is generated if either name does not
	 *     correspond to a valid renderbuffer or texture object according
	 *     to the corresponding target parameter."
	 */
	/* 4523 should be a bogus renderbuffer/texture */
	glCopyImageSubData(4523, src_target, 0, 0, 0, 0,
			   dst, dst_target, 0, 0, 0, 0, 0, 0, 0);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	glCopyImageSubData(src, src_target, 0, 0, 0, 0,
			   4523, dst_target, 0, 0, 0, 0, 0, 0, 0);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);

	/* Invalid level */
	glCopyImageSubData(src, src_target, 5, 0, 0, 0,
			   dst, dst_target, 0, 0, 0, 0, 0, 0, 0);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	glCopyImageSubData(src, src_target, 0, 0, 0, 0,
			   dst, dst_target, 5, 0, 0, 0, 0, 0, 0);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);

	/* Region out of bounds */
	glCopyImageSubData(src, src_target, 0, 7, 5, 2,
			   dst, dst_target, 0, 0, 0, 0, 26, 25, 20);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	glCopyImageSubData(src, src_target, 0, 7, 5, 2,
			   dst, dst_target, 0, 0, 0, 0, 25, 30, 20);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	glCopyImageSubData(src, src_target, 0, 7, 5, 2,
			   dst, dst_target, 0, 0, 0, 0, 25, 24, 31);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	glCopyImageSubData(src, src_target, 0, 0, 0, 0,
			   dst, dst_target, 0, 7, 5, 2, 26, 25, 20);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	glCopyImageSubData(src, src_target, 0, 0, 0, 0,
			   dst, dst_target, 0, 7, 5, 2, 25, 30, 20);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	glCopyImageSubData(src, src_target, 0, 0, 0, 0,
			   dst, dst_target, 0, 7, 5, 2, 25, 24, 31);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);

	image_delete(src_target, src);
	image_delete(dst_target, dst);

	return pass;
}

static bool
test_compressed_alignment_errors()
{
	bool pass = true;
	GLuint tex[4];

	glGenTextures(4, tex);

	glBindTexture(GL_TEXTURE_2D, tex[0]);
	glTexStorage2D(GL_TEXTURE_2D, 1,
		       GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 128, 128);
	glBindTexture(GL_TEXTURE_2D, tex[1]);
	glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA16UI, 32, 32);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
			GL_NEAREST_MIPMAP_NEAREST);

	/* Check for alignment constaints */
	/* bad width = 21 */
	glCopyImageSubData(tex[0], GL_TEXTURE_2D, 0, 0, 0, 0,
			   tex[1], GL_TEXTURE_2D, 0, 0, 0, 0, 21, 24, 1);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	/* bad height = 22 */
	glCopyImageSubData(tex[0], GL_TEXTURE_2D, 0, 0, 0, 0,
			   tex[1], GL_TEXTURE_2D, 0, 0, 0, 0, 20, 22, 1);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	/* bad srcX = 2 */
	glCopyImageSubData(tex[0], GL_TEXTURE_2D, 0, 2, 0, 0,
			   tex[1], GL_TEXTURE_2D, 0, 0, 0, 0, 20, 24, 1);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
	/* bad srcY = 1 */
	glCopyImageSubData(tex[0], GL_TEXTURE_2D, 0, 0, 1, 0,
			   tex[1], GL_TEXTURE_2D, 0, 0, 0, 0, 20, 24, 1);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);

	/* Section 18.3.2 (Copying Between Images) of the OpenGL 4.5 Core
	 * Profile spec says:
	 *
	 *     "An INVALID_OPERATION error is generated if the texel size of
	 *     the uncompressed image is not equal to the block size of the
	 *     compressed image."
	 */
	glBindTexture(GL_TEXTURE_2D, tex[2]);
	glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB16UI, 32, 32);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
			GL_NEAREST_MIPMAP_NEAREST);
	glCopyImageSubData(tex[0], GL_TEXTURE_2D, 0, 0, 0, 0,
			   tex[2], GL_TEXTURE_2D, 0, 0, 0, 0, 20, 20, 1);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	/* Section 18.3.2 (Copying Between Images) of the OpenGL 4.5 Core
	 * Profile spec says:
	 *
	 *     "An INVALID_OPERATION error is generated if the formats are
	 *     not compatible."
	 *
	 * The definition of compatible refers back to table 8.22 "Compatible
	 * internal formats for TextureView."  This table does not contain
	 * S3TC formats because they are from an older extension.  Given the
	 * different encodings of DXT1 and DXT3 textures, it is reasonable to
	 * assume they would not be compatible for texture views, and this
	 * matches at least NVIDIA's implementation.
	 */
	glBindTexture(GL_TEXTURE_2D, tex[3]);
	glTexStorage2D(GL_TEXTURE_2D, 1,
		       GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 32, 32);
	glCopyImageSubData(tex[0], GL_TEXTURE_2D, 0, 0, 0, 0,
			   tex[3], GL_TEXTURE_2D, 0, 0, 0, 0, 20, 20, 1);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	glDeleteTextures(4, tex);

	return pass;
}

enum piglit_result
piglit_display(void)
{
	bool pass = true;

	pass &= test_simple_errors(GL_TEXTURE_2D, GL_TEXTURE_2D);
	pass &= test_simple_errors(GL_RENDERBUFFER, GL_TEXTURE_2D);
	pass &= test_simple_errors(GL_TEXTURE_2D, GL_RENDERBUFFER);
	pass &= test_simple_errors(GL_RENDERBUFFER, GL_RENDERBUFFER);
	if (piglit_is_extension_supported("GL_EXT_texture_compression_s3tc")) {
		pass &= test_compressed_alignment_errors();
	}

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}