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
);
38 class copy_constant_to_storage
: public ::testing::Test
{
40 void int_test(unsigned rows
);
41 void uint_test(unsigned rows
);
42 void bool_test(unsigned rows
);
44 void float_test(unsigned columns
, unsigned rows
);
47 virtual void TearDown();
49 gl_constant_value storage
[17];
54 copy_constant_to_storage::SetUp()
56 this->mem_ctx
= ralloc_context(NULL
);
60 copy_constant_to_storage::TearDown()
62 ralloc_free(this->mem_ctx
);
67 copy_constant_to_storage::int_test(unsigned rows
)
70 generate_data(mem_ctx
, GLSL_TYPE_INT
, 1, rows
, val
);
72 const unsigned red_zone_size
= Elements(storage
) - val
->type
->components();
73 fill_storage_array_with_sentinels(storage
,
74 val
->type
->components(),
77 linker::copy_constant_to_storage(storage
,
80 val
->type
->components());
82 verify_data(storage
, 0, val
, red_zone_size
);
86 copy_constant_to_storage::uint_test(unsigned rows
)
89 generate_data(mem_ctx
, GLSL_TYPE_UINT
, 1, rows
, val
);
91 const unsigned red_zone_size
= Elements(storage
) - val
->type
->components();
92 fill_storage_array_with_sentinels(storage
,
93 val
->type
->components(),
96 linker::copy_constant_to_storage(storage
,
99 val
->type
->components());
101 verify_data(storage
, 0, val
, red_zone_size
);
105 copy_constant_to_storage::float_test(unsigned columns
, unsigned rows
)
108 generate_data(mem_ctx
, GLSL_TYPE_FLOAT
, columns
, rows
, val
);
110 const unsigned red_zone_size
= Elements(storage
) - val
->type
->components();
111 fill_storage_array_with_sentinels(storage
,
112 val
->type
->components(),
115 linker::copy_constant_to_storage(storage
,
117 val
->type
->base_type
,
118 val
->type
->components());
120 verify_data(storage
, 0, val
, red_zone_size
);
124 copy_constant_to_storage::bool_test(unsigned rows
)
127 generate_data(mem_ctx
, GLSL_TYPE_BOOL
, 1, rows
, val
);
129 const unsigned red_zone_size
= Elements(storage
) - val
->type
->components();
130 fill_storage_array_with_sentinels(storage
,
131 val
->type
->components(),
134 linker::copy_constant_to_storage(storage
,
136 val
->type
->base_type
,
137 val
->type
->components());
139 verify_data(storage
, 0, val
, red_zone_size
);
143 * The only difference between this test and int_test is that the base type
144 * passed to \c linker::copy_constant_to_storage is hard-coded to \c
145 * GLSL_TYPE_SAMPLER instead of using the base type from the constant.
148 copy_constant_to_storage::sampler_test(void)
151 generate_data(mem_ctx
, GLSL_TYPE_INT
, 1, 1, val
);
153 const unsigned red_zone_size
= Elements(storage
) - val
->type
->components();
154 fill_storage_array_with_sentinels(storage
,
155 val
->type
->components(),
158 linker::copy_constant_to_storage(storage
,
161 val
->type
->components());
163 verify_data(storage
, 0, val
, red_zone_size
);
166 TEST_F(copy_constant_to_storage
, bool_uniform
)
171 TEST_F(copy_constant_to_storage
, bvec2_uniform
)
176 TEST_F(copy_constant_to_storage
, bvec3_uniform
)
181 TEST_F(copy_constant_to_storage
, bvec4_uniform
)
186 TEST_F(copy_constant_to_storage
, int_uniform
)
191 TEST_F(copy_constant_to_storage
, ivec2_uniform
)
196 TEST_F(copy_constant_to_storage
, ivec3_uniform
)
201 TEST_F(copy_constant_to_storage
, ivec4_uniform
)
206 TEST_F(copy_constant_to_storage
, uint_uniform
)
211 TEST_F(copy_constant_to_storage
, uvec2_uniform
)
216 TEST_F(copy_constant_to_storage
, uvec3_uniform
)
221 TEST_F(copy_constant_to_storage
, uvec4_uniform
)
226 TEST_F(copy_constant_to_storage
, float_uniform
)
231 TEST_F(copy_constant_to_storage
, vec2_uniform
)
236 TEST_F(copy_constant_to_storage
, vec3_uniform
)
241 TEST_F(copy_constant_to_storage
, vec4_uniform
)
246 TEST_F(copy_constant_to_storage
, mat2x2_uniform
)
251 TEST_F(copy_constant_to_storage
, mat2x3_uniform
)
256 TEST_F(copy_constant_to_storage
, mat2x4_uniform
)
261 TEST_F(copy_constant_to_storage
, mat3x2_uniform
)
266 TEST_F(copy_constant_to_storage
, mat3x3_uniform
)
271 TEST_F(copy_constant_to_storage
, mat3x4_uniform
)
276 TEST_F(copy_constant_to_storage
, mat4x2_uniform
)
281 TEST_F(copy_constant_to_storage
, mat4x3_uniform
)
286 TEST_F(copy_constant_to_storage
, mat4x4_uniform
)
291 TEST_F(copy_constant_to_storage
, sampler_uniform
)