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 328 329 330 331 332 333 334 335 336 337 338
|
#!/usr/bin/env python
# coding=utf-8
#
# Copyright © 2014 The Piglit Project
#
# 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.
"""Test passing variables from the tessellation control shader to the
tessellation evaluation shader.
For every combination of varying type as scalar and as two element array and
per-vertex or per-patch varying create a test that that passes said variable
between the tessellation shader stages.
Copy a uniform value to the varying in the tessellation control shader and
compare the varying to the same uniform in the tessellation evaluation
shader.
If the values are equal draw the screen green, red otherwise.
Draw for tessellated quads. Each should cover one quarter of the screen.
This script outputs, to stdout, the name of each file it generates.
"""
from __future__ import print_function, absolute_import, division
import os
import sys
import random
import textwrap
from six.moves import range
class Test(object):
def __init__(self, type_name, array, patch_in, name):
"""Creates a test.
type_name -- varying type to test (e.g.: vec4, mat3x2, int, ...)
array -- number of array elements to test, None for no array
patch_in -- true for per-patch varying, false for per-vertex varying
name -- name of the variable to test
"""
self.var_name = name or 'var'
self.use_block = 0 if patch_in else 1
if self.var_name == 'gl_Position':
self.var_type = 'vec4'
self.var_array = None
self.patch_in = False
elif self.var_name == 'gl_PointSize':
self.var_type = 'float'
self.var_array = None
self.patch_in = False
elif self.var_name == 'gl_ClipDistance':
self.var_type = 'float'
self.var_array = 8
self.patch_in = False
else:
self.var_type = type_name
self.var_array = array
self.patch_in = patch_in
if self.built_in:
self.interface_name = 'gl_PerVertex'
self.interface_tcs_instance = 'gl_out'
self.interface_tes_instance = 'gl_in'
else:
self.interface_name = 'tc2te_interface'
self.interface_tcs_instance = '' if self.patch_in else 'tc2te'
self.interface_tes_instance = '' if self.patch_in else 'tc2te'
if self.var_array:
self.var_type_full = self.var_type + '[{0}]'.format(self.var_array)
else:
self.var_type_full = self.var_type
if self.patch_in:
self.interface_prefix = 'patch '
self.interface_postfix = ''
else:
self.interface_prefix = ''
self.interface_postfix = '[]'
@property
def built_in(self):
return self.var_name.startswith('gl_')
@property
def tcs_var_ref(self):
return '[gl_InvocationID].' + self.var_name if self.interface_tcs_instance else self.var_name
@property
def tes_var_ref(self):
return '[i].' + self.var_name if self.interface_tes_instance else self.var_name
@property
def tcs_reference_index(self):
return 'gl_PrimitiveID' if self.patch_in else 'gl_PrimitiveID * vertices_in + gl_InvocationID'
@property
def tes_reference_index(self):
return 'gl_PrimitiveID' if self.patch_in else 'gl_PrimitiveID * vertices_in + i'
@property
def reference_size(self):
return 4 if self.patch_in else 12
@property
def uniform_string(self):
"""Returns string for loading uniform data by the shader_runner."""
data = self.test_data()
uniforms = ''
if self.var_array:
for i in range(self.reference_size):
for j in range(self.var_array):
uniforms += 'uniform {0} reference[{1}].v[{2}] {3}\n'.format(
self.var_type, i, j, data[i*j])
else:
for i in range(self.reference_size):
uniforms += 'uniform {0} reference[{1}].v {2}\n'.format(
self.var_type,
i,
data[i])
#strip last newline
return uniforms[:-1]
def components(self):
"""Returns the number of scalar components of the used data type."""
n = 1
if self.var_type.startswith('mat'):
if 'x' in self.var_type:
n *= int(self.var_type[-1])
n *= int(self.var_type[-3])
else:
n *= int(self.var_type[-1])
n *= int(self.var_type[-1])
elif 'vec' in self.var_type:
n *= int(self.var_type[-1])
return n
def test_data(self):
"""Returns random but deterministic data as a list of strings.
n strings are returned containing c random values, each.
Where n is the number of vertices times the array length and
c is the number of components in the tested scalar data type.
"""
random.seed(17)
if self.var_array:
n = self.var_array * self.reference_size
else:
n = self.reference_size
if self.var_type.startswith('i'):
rand = lambda: random.randint(-0x80000000, 0x7fffffff)
elif self.var_type.startswith('u'):
rand = lambda: random.randint(0, 0xffffffff)
else:
rand = lambda: ((-1 + 2 * random.randint(0, 1)) *
random.randint(0, 2**23-1) *
2.0**(random.randint(-126, 127)))
c = self.components()
ret = []
for _ in range(n):
ret.append(" ".join(str(rand()) for _ in range(c)))
return ret
def filename(self):
"""Returns the file name (including path) for the test."""
if self.built_in:
name = self.var_name
elif self.var_array:
name = self.var_type + '_{0}'.format(self.var_array)
else:
name = self.var_type
if self.patch_in:
name = 'patch-' + name
return os.path.join('spec',
'arb_tessellation_shader',
'execution',
'tes-input',
'tes-input-{0}.shader_test'.format(name))
def generate(self):
"""Generates and writes the test to disc."""
test = textwrap.dedent("""\
# Test generated by:
# {generator_command}
# Test tessellation evaluation shader inputs
[require]
GLSL >= 1.50
GL_ARB_tessellation_shader
[vertex shader]
void main()
{{
gl_Position = vec4(0);
}}
[tessellation control shader]
#extension GL_ARB_tessellation_shader : require
layout(vertices = 3) out;
uniform struct S0 {{
{self.var_type_full} v;
}} reference[12];
#if {self.use_block}
{self.interface_prefix}out {self.interface_name} {{
{self.var_type_full} {self.var_name};
}} {self.interface_tcs_instance}{self.interface_postfix};
#else
{self.interface_prefix}out {self.var_type_full} {self.var_name};
#endif
void main()
{{
const int vertices_in = 3;
{self.interface_tcs_instance}{self.tcs_var_ref} = reference[{self.tcs_reference_index}].v;
gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);
gl_TessLevelInner = float[2](1.0, 1.0);
}}
[tessellation evaluation shader]
#extension GL_ARB_tessellation_shader : require
layout(quads) in;
uniform struct S0 {{
{self.var_type_full} v;
}} reference[12];
#if {self.use_block}
{self.interface_prefix}in {self.interface_name} {{
{self.var_type_full} {self.var_name};
}} {self.interface_tes_instance}{self.interface_postfix};
#else
{self.interface_prefix}in {self.var_type_full} {self.var_name};
#endif
out vec4 vert_color;
void main()
{{
const int vertices_in = 3;
const vec4 red = vec4(1, 0, 0, 1);
const vec4 green = vec4(0, 1, 0, 1);
vert_color = green;
for (int i = 0; i < vertices_in; ++i)
if ({self.interface_tes_instance}{self.tes_var_ref} != reference[{self.tes_reference_index}].v)
vert_color = red;
vec2[3] position = vec2[3](
vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 1.0),
vec2(float(gl_PrimitiveID / 2) - 0.0, float(gl_PrimitiveID % 2) - 1.0),
vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 0.0)
);
gl_Position = vec4(position[0]
+ (position[1] - position[0]) * gl_TessCoord[0]
+ (position[2] - position[0]) * gl_TessCoord[1], 0.0, 1.0);
}}
[fragment shader]
in vec4 vert_color;
out vec4 frag_color;
void main()
{{
frag_color = vert_color;
}}
[test]
{self.uniform_string}
draw arrays GL_PATCHES 0 12
relative probe rgb (0.25, 0.25) (0.0, 1.0, 0.0)
relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
relative probe rgb (0.25, 0.75) (0.0, 1.0, 0.0)
relative probe rgb (0.75, 0.75) (0.0, 1.0, 0.0)
""")
test = test.format(self=self, generator_command=" ".join(sys.argv))
filename = self.filename()
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
os.makedirs(dirname)
with open(filename, 'w') as f:
f.write(test)
def all_tests():
for type_name in ['float', 'vec2', 'vec3', 'vec4',
'mat2', 'mat3', 'mat4',
'mat2x3', 'mat2x4', 'mat3x2',
'mat3x4', 'mat4x2', 'mat4x3',
'int', 'ivec2', 'ivec3', 'ivec4',
'uint', 'uvec2', 'uvec3', 'uvec4']:
for array in [None, 2]:
for patch_in in [True, False]:
yield Test(type_name, array, patch_in, name=None)
for var in ['gl_Position', 'gl_PointSize', 'gl_ClipDistance']:
yield Test(type_name=None, array=None, patch_in=False, name=var)
def main():
for test in all_tests():
test.generate()
print(test.filename())
if __name__ == '__main__':
main()
|