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
318
319
320
321
322
323
324
325
326
327
|
/*
* Copyright © 2015 Ilia Mirkin
*
* 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.
*
* Heavily based on textureSize.c
*/
/**
* \file textureSamples.c
*
* Tests the ARB_shader_texture_image_samples textureSamples() built-in.
*
* The test covers:
* - All pipeline stages (VS, GS, FS)
* - Sampler data types (floating point, signed integer, unsigned integer)
* - Sampler dimensionality (2DMS, 2DMSArray)
*
* The "textureSamples" binary takes three arguments:
* shader stage
* sampler type
* number of samples
*
* For example:
* ./bin/textureSamples fs sampler2DMS 4
* ./bin/textureSamples vs usampler2DMSArray 2
*/
#include "common.h"
void
parse_args(int argc, char **argv);
static enum shader_target test_stage = UNKNOWN;
PIGLIT_GL_TEST_CONFIG_BEGIN
config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
piglit_gl_process_args(&argc, argv, &config);
parse_args(argc, argv);
if (test_stage == GS) {
config.supports_gl_compat_version = 32;
config.supports_gl_core_version = 32;
} else {
config.supports_gl_compat_version = 30;
config.supports_gl_core_version = 31;
}
PIGLIT_GL_TEST_CONFIG_END
enum piglit_result
piglit_display()
{
bool pass = true;
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
float expected_color[4] = {0, 1, 0};
glViewport(0, 0, piglit_width, piglit_height);
piglit_draw_rect(-1, -1, 2, 2);
pass &= piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height,
expected_color);
piglit_present_results();
return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
void
generate_texture()
{
GLuint tex;
GLint samples = 0;
GLenum target = sampler.target;
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &tex);
glBindTexture(target, tex);
if (target == GL_TEXTURE_2D_MULTISAMPLE)
glTexImage2DMultisample(target, sample_count, GL_RGBA8,
32, 32, GL_TRUE);
else
glTexImage3DMultisample(target, sample_count, GL_RGBA8,
32, 32, 32, GL_TRUE);
glGetTexLevelParameteriv(
target, 0, GL_TEXTURE_SAMPLES, &samples);
if (samples != sample_count) {
printf("Sample count of %d not supported, "
"got %d samples\n",
sample_count, samples);
piglit_report_result(PIGLIT_SKIP);
}
}
int
generate_GLSL(enum shader_target test_stage)
{
int vs, gs = 0, fs;
int prog;
static char *vs_code;
static char *gs_code = NULL;
static char *fs_code;
switch (test_stage) {
case VS:
(void)!asprintf(&vs_code,
"#version %d\n"
"#extension GL_ARB_texture_multisample: enable\n"
"#extension GL_ARB_shader_texture_image_samples: enable\n"
"uniform %s tex;\n"
"in vec4 piglit_vertex;\n"
"flat out int samples;\n"
"void main()\n"
"{\n"
" samples = textureSamples(tex);\n"
" gl_Position = piglit_vertex;\n"
"}\n",
shader_version, sampler.name);
break;
case GS:
(void)!asprintf(&vs_code,
"#version %d\n"
"in vec4 piglit_vertex;\n"
"out vec4 pos_to_gs;\n"
"void main()\n"
"{\n"
" pos_to_gs = piglit_vertex;\n"
"}\n",
shader_version);
(void)!asprintf(&gs_code,
"#version %d\n"
"#extension GL_ARB_texture_multisample: enable\n"
"#extension GL_ARB_shader_texture_image_samples: enable\n"
"layout(triangles) in;\n"
"layout(triangle_strip, max_vertices = 3) out;\n"
"uniform %s tex;\n"
"in vec4 pos_to_gs[3];\n"
"flat out int samples;\n"
"void main()\n"
"{\n"
" for (int i = 0; i < 3; i++) {\n"
" samples = textureSamples(tex);\n"
" gl_Position = pos_to_gs[i];\n"
" EmitVertex();\n"
" }\n"
"}\n",
shader_version, sampler.name);
break;
case FS:
(void)!asprintf(&vs_code,
"#version %d\n"
"in vec4 piglit_vertex;\n"
"void main()\n"
"{\n"
" gl_Position = piglit_vertex;\n"
"}\n",
shader_version);
(void)!asprintf(&fs_code,
"#version %d\n"
"#extension GL_ARB_texture_multisample: enable\n"
"#extension GL_ARB_shader_texture_image_samples: enable\n"
"uniform %s tex;\n"
"out vec4 color;\n"
"void main()\n"
"{\n"
" if (textureSamples(tex) == %d) color = vec4(0,1,0,1);\n"
" else color = vec4(1,0,0,1);\n"
"}\n",
shader_version, sampler.name, sample_count);
break;
default:
assert(!"Should not get here.");
break;
}
switch (test_stage) {
case VS:
case GS:
(void)!asprintf(&fs_code,
"#version %d\n"
"flat in int samples;\n"
"out vec4 color;\n"
"void main()\n"
"{\n"
" if (samples == %d) color = vec4(0,1,0,1);\n"
" else color = vec4(1,0,0,1);\n"
"}\n",
shader_version, sample_count);
break;
default:
break;
}
vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);
if (gs_code) {
gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_code);
}
fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);
if (!vs || (gs_code && !gs) || !fs)
return 0;
prog = glCreateProgram();
glAttachShader(prog, vs);
if (gs_code)
glAttachShader(prog, gs);
glAttachShader(prog, fs);
glLinkProgram(prog);
if (!piglit_link_check_status(prog))
piglit_report_result(PIGLIT_FAIL);
return prog;
}
void
fail_and_show_usage()
{
printf("Usage: textureSize <vs|gs|fs> <sampler type> <sample_count> [piglit args...]\n");
piglit_report_result(PIGLIT_SKIP);
}
void
parse_args(int argc, char **argv)
{
int i;
bool sampler_found = false;
for (i = 1; i < argc; i++) {
if (test_stage == UNKNOWN) {
/* Maybe it's the shader stage? */
if (strcmp(argv[i], "vs") == 0) {
test_stage = VS;
continue;
} else if (strcmp(argv[i], "gs") == 0) {
test_stage = GS;
continue;
} else if (strcmp(argv[i], "fs") == 0) {
test_stage = FS;
continue;
}
}
/* Maybe it's the sampler type? */
if (!sampler_found && (sampler_found = select_sampler(argv[i])))
continue;
/* Maybe it's the sample count? */
if (sampler_found && !sample_count) {
sample_count = atoi(argv[i]);
continue;
}
fail_and_show_usage();
}
if (test_stage == UNKNOWN || !sampler_found)
fail_and_show_usage();
if (test_stage == GS && shader_version < 150)
shader_version = 150;
}
void
piglit_init(int argc, char **argv)
{
int prog;
piglit_require_extension("GL_ARB_shader_texture_image_samples");
require_GL_features(test_stage);
if (sample_count > 1) {
/* check it */
GLint max_samples;
if (sampler.data_type == GL_INT ||
sampler.data_type == GL_UNSIGNED_INT) {
glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &max_samples);
if (sample_count > max_samples) {
printf("Sample count of %d not supported,"
" >MAX_INTEGER_SAMPLES\n",
sample_count);
piglit_report_result(PIGLIT_SKIP);
}
} else {
glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
if (sample_count > max_samples) {
printf("Sample count of %d not supported,"
" >MAX_SAMPLES\n",
sample_count);
piglit_report_result(PIGLIT_SKIP);
}
}
} else {
sample_count = 1;
}
prog = generate_GLSL(test_stage);
if (!prog)
piglit_report_result(PIGLIT_FAIL);
glUseProgram(prog);
generate_texture();
}
|