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 "util/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 glsl_type_singleton_init_or_ref();
59 this->mem_ctx
= ralloc_context(NULL
);
63 copy_constant_to_storage::TearDown()
65 ralloc_free(this->mem_ctx
);
68 glsl_type_singleton_decref();
72 copy_constant_to_storage::int_test(unsigned rows
)
75 generate_data(mem_ctx
, GLSL_TYPE_INT
, 1, rows
, val
);
77 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
78 fill_storage_array_with_sentinels(storage
,
79 val
->type
->components(),
82 linker::copy_constant_to_storage(storage
,
85 val
->type
->components(),
88 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
92 copy_constant_to_storage::uint_test(unsigned rows
)
95 generate_data(mem_ctx
, GLSL_TYPE_UINT
, 1, rows
, val
);
97 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
98 fill_storage_array_with_sentinels(storage
,
99 val
->type
->components(),
102 linker::copy_constant_to_storage(storage
,
104 val
->type
->base_type
,
105 val
->type
->components(),
108 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
112 copy_constant_to_storage::float_test(unsigned columns
, unsigned rows
)
115 generate_data(mem_ctx
, GLSL_TYPE_FLOAT
, columns
, rows
, val
);
117 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
118 fill_storage_array_with_sentinels(storage
,
119 val
->type
->components(),
122 linker::copy_constant_to_storage(storage
,
124 val
->type
->base_type
,
125 val
->type
->components(),
128 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
132 copy_constant_to_storage::bool_test(unsigned rows
)
135 generate_data(mem_ctx
, GLSL_TYPE_BOOL
, 1, rows
, val
);
137 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
138 fill_storage_array_with_sentinels(storage
,
139 val
->type
->components(),
142 linker::copy_constant_to_storage(storage
,
144 val
->type
->base_type
,
145 val
->type
->components(),
148 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
152 * The only difference between this test and int_test is that the base type
153 * passed to \c linker::copy_constant_to_storage is hard-coded to \c
154 * GLSL_TYPE_SAMPLER instead of using the base type from the constant.
157 copy_constant_to_storage::sampler_test(void)
160 generate_data(mem_ctx
, GLSL_TYPE_INT
, 1, 1, val
);
162 const unsigned red_zone_size
= ARRAY_SIZE(storage
) - val
->type
->components();
163 fill_storage_array_with_sentinels(storage
,
164 val
->type
->components(),
167 linker::copy_constant_to_storage(storage
,
170 val
->type
->components(),
173 verify_data(storage
, 0, val
, red_zone_size
, 0xF00F);
176 TEST_F(copy_constant_to_storage
, bool_uniform
)
181 TEST_F(copy_constant_to_storage
, bvec2_uniform
)
186 TEST_F(copy_constant_to_storage
, bvec3_uniform
)
191 TEST_F(copy_constant_to_storage
, bvec4_uniform
)
196 TEST_F(copy_constant_to_storage
, int_uniform
)
201 TEST_F(copy_constant_to_storage
, ivec2_uniform
)
206 TEST_F(copy_constant_to_storage
, ivec3_uniform
)
211 TEST_F(copy_constant_to_storage
, ivec4_uniform
)
216 TEST_F(copy_constant_to_storage
, uint_uniform
)
221 TEST_F(copy_constant_to_storage
, uvec2_uniform
)
226 TEST_F(copy_constant_to_storage
, uvec3_uniform
)
231 TEST_F(copy_constant_to_storage
, uvec4_uniform
)
236 TEST_F(copy_constant_to_storage
, float_uniform
)
241 TEST_F(copy_constant_to_storage
, vec2_uniform
)
246 TEST_F(copy_constant_to_storage
, vec3_uniform
)
251 TEST_F(copy_constant_to_storage
, vec4_uniform
)
256 TEST_F(copy_constant_to_storage
, mat2x2_uniform
)
261 TEST_F(copy_constant_to_storage
, mat2x3_uniform
)
266 TEST_F(copy_constant_to_storage
, mat2x4_uniform
)
271 TEST_F(copy_constant_to_storage
, mat3x2_uniform
)
276 TEST_F(copy_constant_to_storage
, mat3x3_uniform
)
281 TEST_F(copy_constant_to_storage
, mat3x4_uniform
)
286 TEST_F(copy_constant_to_storage
, mat4x2_uniform
)
291 TEST_F(copy_constant_to_storage
, mat4x3_uniform
)
296 TEST_F(copy_constant_to_storage
, mat4x4_uniform
)
301 TEST_F(copy_constant_to_storage
, sampler_uniform
)