Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2012 Intel Corporation
  3.  *
  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:
  10.  *
  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
  13.  * Software.
  14.  *
  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.
  22.  */
  23. #include <gtest/gtest.h>
  24. #include "main/compiler.h"
  25. #include "main/mtypes.h"
  26. #include "main/macros.h"
  27. #include "ralloc.h"
  28. #include "uniform_initializer_utils.h"
  29.  
  30. namespace linker {
  31. extern void
  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. }
  37.  
  38. class copy_constant_to_storage : public ::testing::Test {
  39. public:
  40.    void int_test(unsigned rows);
  41.    void uint_test(unsigned rows);
  42.    void bool_test(unsigned rows);
  43.    void sampler_test();
  44.    void float_test(unsigned columns, unsigned rows);
  45.  
  46.    virtual void SetUp();
  47.    virtual void TearDown();
  48.  
  49.    gl_constant_value storage[17];
  50.    void *mem_ctx;
  51. };
  52.  
  53. void
  54. copy_constant_to_storage::SetUp()
  55. {
  56.    this->mem_ctx = ralloc_context(NULL);
  57. }
  58.  
  59. void
  60. copy_constant_to_storage::TearDown()
  61. {
  62.    ralloc_free(this->mem_ctx);
  63.    this->mem_ctx = NULL;
  64. }
  65.  
  66. void
  67. copy_constant_to_storage::int_test(unsigned rows)
  68. {
  69.    ir_constant *val;
  70.    generate_data(mem_ctx, GLSL_TYPE_INT, 1, rows, val);
  71.  
  72.    const unsigned red_zone_size = Elements(storage) - val->type->components();
  73.    fill_storage_array_with_sentinels(storage,
  74.                                      val->type->components(),
  75.                                      red_zone_size);
  76.  
  77.    linker::copy_constant_to_storage(storage,
  78.                                     val,
  79.                                     val->type->base_type,
  80.                                     val->type->components());
  81.  
  82.    verify_data(storage, 0, val, red_zone_size);
  83. }
  84.  
  85. void
  86. copy_constant_to_storage::uint_test(unsigned rows)
  87. {
  88.    ir_constant *val;
  89.    generate_data(mem_ctx, GLSL_TYPE_UINT, 1, rows, val);
  90.  
  91.    const unsigned red_zone_size = Elements(storage) - val->type->components();
  92.    fill_storage_array_with_sentinels(storage,
  93.                                      val->type->components(),
  94.                                      red_zone_size);
  95.  
  96.    linker::copy_constant_to_storage(storage,
  97.                                     val,
  98.                                     val->type->base_type,
  99.                                     val->type->components());
  100.  
  101.    verify_data(storage, 0, val, red_zone_size);
  102. }
  103.  
  104. void
  105. copy_constant_to_storage::float_test(unsigned columns, unsigned rows)
  106. {
  107.    ir_constant *val;
  108.    generate_data(mem_ctx, GLSL_TYPE_FLOAT, columns, rows, val);
  109.  
  110.    const unsigned red_zone_size = Elements(storage) - val->type->components();
  111.    fill_storage_array_with_sentinels(storage,
  112.                                      val->type->components(),
  113.                                      red_zone_size);
  114.  
  115.    linker::copy_constant_to_storage(storage,
  116.                                     val,
  117.                                     val->type->base_type,
  118.                                     val->type->components());
  119.  
  120.    verify_data(storage, 0, val, red_zone_size);
  121. }
  122.  
  123. void
  124. copy_constant_to_storage::bool_test(unsigned rows)
  125. {
  126.    ir_constant *val;
  127.    generate_data(mem_ctx, GLSL_TYPE_BOOL, 1, rows, val);
  128.  
  129.    const unsigned red_zone_size = Elements(storage) - val->type->components();
  130.    fill_storage_array_with_sentinels(storage,
  131.                                      val->type->components(),
  132.                                      red_zone_size);
  133.  
  134.    linker::copy_constant_to_storage(storage,
  135.                                     val,
  136.                                     val->type->base_type,
  137.                                     val->type->components());
  138.  
  139.    verify_data(storage, 0, val, red_zone_size);
  140. }
  141.  
  142. /**
  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.
  146.  */
  147. void
  148. copy_constant_to_storage::sampler_test(void)
  149. {
  150.    ir_constant *val;
  151.    generate_data(mem_ctx, GLSL_TYPE_INT, 1, 1, val);
  152.  
  153.    const unsigned red_zone_size = Elements(storage) - val->type->components();
  154.    fill_storage_array_with_sentinels(storage,
  155.                                      val->type->components(),
  156.                                      red_zone_size);
  157.  
  158.    linker::copy_constant_to_storage(storage,
  159.                                     val,
  160.                                     GLSL_TYPE_SAMPLER,
  161.                                     val->type->components());
  162.  
  163.    verify_data(storage, 0, val, red_zone_size);
  164. }
  165.  
  166. TEST_F(copy_constant_to_storage, bool_uniform)
  167. {
  168.    bool_test(1);
  169. }
  170.  
  171. TEST_F(copy_constant_to_storage, bvec2_uniform)
  172. {
  173.    bool_test(2);
  174. }
  175.  
  176. TEST_F(copy_constant_to_storage, bvec3_uniform)
  177. {
  178.    bool_test(3);
  179. }
  180.  
  181. TEST_F(copy_constant_to_storage, bvec4_uniform)
  182. {
  183.    bool_test(4);
  184. }
  185.  
  186. TEST_F(copy_constant_to_storage, int_uniform)
  187. {
  188.    int_test(1);
  189. }
  190.  
  191. TEST_F(copy_constant_to_storage, ivec2_uniform)
  192. {
  193.    int_test(2);
  194. }
  195.  
  196. TEST_F(copy_constant_to_storage, ivec3_uniform)
  197. {
  198.    int_test(3);
  199. }
  200.  
  201. TEST_F(copy_constant_to_storage, ivec4_uniform)
  202. {
  203.    int_test(4);
  204. }
  205.  
  206. TEST_F(copy_constant_to_storage, uint_uniform)
  207. {
  208.    uint_test(1);
  209. }
  210.  
  211. TEST_F(copy_constant_to_storage, uvec2_uniform)
  212. {
  213.    uint_test(2);
  214. }
  215.  
  216. TEST_F(copy_constant_to_storage, uvec3_uniform)
  217. {
  218.    uint_test(3);
  219. }
  220.  
  221. TEST_F(copy_constant_to_storage, uvec4_uniform)
  222. {
  223.    uint_test(4);
  224. }
  225.  
  226. TEST_F(copy_constant_to_storage, float_uniform)
  227. {
  228.    float_test(1, 1);
  229. }
  230.  
  231. TEST_F(copy_constant_to_storage, vec2_uniform)
  232. {
  233.    float_test(1, 2);
  234. }
  235.  
  236. TEST_F(copy_constant_to_storage, vec3_uniform)
  237. {
  238.    float_test(1, 3);
  239. }
  240.  
  241. TEST_F(copy_constant_to_storage, vec4_uniform)
  242. {
  243.    float_test(1, 4);
  244. }
  245.  
  246. TEST_F(copy_constant_to_storage, mat2x2_uniform)
  247. {
  248.    float_test(2, 2);
  249. }
  250.  
  251. TEST_F(copy_constant_to_storage, mat2x3_uniform)
  252. {
  253.    float_test(2, 3);
  254. }
  255.  
  256. TEST_F(copy_constant_to_storage, mat2x4_uniform)
  257. {
  258.    float_test(2, 4);
  259. }
  260.  
  261. TEST_F(copy_constant_to_storage, mat3x2_uniform)
  262. {
  263.    float_test(3, 2);
  264. }
  265.  
  266. TEST_F(copy_constant_to_storage, mat3x3_uniform)
  267. {
  268.    float_test(3, 3);
  269. }
  270.  
  271. TEST_F(copy_constant_to_storage, mat3x4_uniform)
  272. {
  273.    float_test(3, 4);
  274. }
  275.  
  276. TEST_F(copy_constant_to_storage, mat4x2_uniform)
  277. {
  278.    float_test(4, 2);
  279. }
  280.  
  281. TEST_F(copy_constant_to_storage, mat4x3_uniform)
  282. {
  283.    float_test(4, 3);
  284. }
  285.  
  286. TEST_F(copy_constant_to_storage, mat4x4_uniform)
  287. {
  288.    float_test(4, 4);
  289. }
  290.  
  291. TEST_F(copy_constant_to_storage, sampler_uniform)
  292. {
  293.    sampler_test();
  294. }
  295.