2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 #include <gtest/gtest.h>
24 #include "main/compiler.h"
25 #include "main/mtypes.h"
26 #include "main/macros.h"
27 #include "util/ralloc.h"
28 #include "uniform_initializer_utils.h"
32 copy_constant_to_storage(union gl_constant_value
*storage
,
33 const ir_constant
*val
,
34 const enum glsl_base_type base_type
,
35 const unsigned int elements
,
36 unsigned int boolean_true
);
39 class copy_constant_to_storage
: public ::testing::Test
{
41 void int_test(unsigned rows
);
42 void uint_test(unsigned rows
);
43 void bool_test(unsigned rows
);
45 void float_test(unsigned columns
, unsigned rows
);
48 virtual void TearDown();
50 gl_constant_value storage
[17];
55 copy_constant_to_storage::SetUp()
57 this->mem_ctx
= ralloc_context(NULL
);
61 copy_constant_to_storage::TearDown()
63 ralloc_free(this->mem_ctx
);
68 copy_constant_to_storage::int_test(unsigned rows
)
71 generate_data(mem_ctx
, GLSL_TYPE_INT
, 1, rows
, val
);
73 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
74 fill_storage_array_with_sentinels(storage
,
75 val
->type
->components(),
78 linker::copy_constant_to_storage(storage
,
81 val
->type
->components(),
84 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
88 copy_constant_to_storage::uint_test(unsigned rows
)
91 generate_data(mem_ctx
, GLSL_TYPE_UINT
, 1, rows
, val
);
93 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
94 fill_storage_array_with_sentinels(storage
,
95 val
->type
->components(),
98 linker::copy_constant_to_storage(storage
,
100 val
->type
->base_type
,
101 val
->type
->components(),
104 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
108 copy_constant_to_storage::float_test(unsigned columns
, unsigned rows
)
111 generate_data(mem_ctx
, GLSL_TYPE_FLOAT
, columns
, rows
, val
);
113 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
114 fill_storage_array_with_sentinels(storage
,
115 val
->type
->components(),
118 linker::copy_constant_to_storage(storage
,
120 val
->type
->base_type
,
121 val
->type
->components(),
124 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
128 copy_constant_to_storage::bool_test(unsigned rows
)
131 generate_data(mem_ctx
, GLSL_TYPE_BOOL
, 1, rows
, val
);
133 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
134 fill_storage_array_with_sentinels(storage
,
135 val
->type
->components(),
138 linker::copy_constant_to_storage(storage
,
140 val
->type
->base_type
,
141 val
->type
->components(),
144 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
148 * The only difference between this test and int_test is that the base type
149 * passed to \c linker::copy_constant_to_storage is hard-coded to \c
150 * GLSL_TYPE_SAMPLER instead of using the base type from the constant.
153 copy_constant_to_storage::sampler_test(void)
156 generate_data(mem_ctx
, GLSL_TYPE_INT
, 1, 1, val
);
158 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
159 fill_storage_array_with_sentinels(storage
,
160 val
->type
->components(),
163 linker::copy_constant_to_storage(storage
,
166 val
->type
->components(),
169 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
172 TEST_F(copy_constant_to_storage
, bool_uniform
)
177 TEST_F(copy_constant_to_storage
, bvec2_uniform
)
182 TEST_F(copy_constant_to_storage
, bvec3_uniform
)
187 TEST_F(copy_constant_to_storage
, bvec4_uniform
)
192 TEST_F(copy_constant_to_storage
, int_uniform
)
197 TEST_F(copy_constant_to_storage
, ivec2_uniform
)
202 TEST_F(copy_constant_to_storage
, ivec3_uniform
)
207 TEST_F(copy_constant_to_storage
, ivec4_uniform
)
212 TEST_F(copy_constant_to_storage
, uint_uniform
)
217 TEST_F(copy_constant_to_storage
, uvec2_uniform
)
222 TEST_F(copy_constant_to_storage
, uvec3_uniform
)
227 TEST_F(copy_constant_to_storage
, uvec4_uniform
)
232 TEST_F(copy_constant_to_storage
, float_uniform
)
237 TEST_F(copy_constant_to_storage
, vec2_uniform
)
242 TEST_F(copy_constant_to_storage
, vec3_uniform
)
247 TEST_F(copy_constant_to_storage
, vec4_uniform
)
252 TEST_F(copy_constant_to_storage
, mat2x2_uniform
)
257 TEST_F(copy_constant_to_storage
, mat2x3_uniform
)
262 TEST_F(copy_constant_to_storage
, mat2x4_uniform
)
267 TEST_F(copy_constant_to_storage
, mat3x2_uniform
)
272 TEST_F(copy_constant_to_storage
, mat3x3_uniform
)
277 TEST_F(copy_constant_to_storage
, mat3x4_uniform
)
282 TEST_F(copy_constant_to_storage
, mat4x2_uniform
)
287 TEST_F(copy_constant_to_storage
, mat4x3_uniform
)
292 TEST_F(copy_constant_to_storage
, mat4x4_uniform
)
297 TEST_F(copy_constant_to_storage
, sampler_uniform
)