1e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri/**************************************************************************
2e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri *
3e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * Copyright 2010 Luca Barbieri
4e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri *
5e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * Permission is hereby granted, free of charge, to any person obtaining
6e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * a copy of this software and associated documentation files (the
7e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * "Software"), to deal in the Software without restriction, including
8e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * without limitation the rights to use, copy, modify, merge, publish,
9e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * distribute, sublicense, and/or sell copies of the Software, and to
10e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * permit persons to whom the Software is furnished to do so, subject to
11e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * the following conditions:
12e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri *
13e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * The above copyright notice and this permission notice (including the
14e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * next paragraph) shall be included in all copies or substantial
15e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * portions of the Software.
16e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri *
17e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri *
25e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri **************************************************************************/
26e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri
27e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri#ifndef U_LINKAGE_H_
28e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri#define U_LINKAGE_H_
29e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri
30e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri#include "pipe/p_compiler.h"
31e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri#include "pipe/p_shader_tokens.h"
32e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri
33e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieristruct util_semantic_set
34e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri{
35e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri   unsigned long masks[256 / 8 / sizeof(unsigned long)];
36e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri};
37e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri
385f2deba9f3f3f9230a9fdd2848e20c1e23e98b8fBrian Paulstatic INLINE boolean
39e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieriutil_semantic_set_contains(struct util_semantic_set *set, unsigned char value)
40e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri{
41e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri   return !!(set->masks[value / (sizeof(long) * 8)] & (1 << (value / (sizeof(long) * 8))));
42e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri}
43e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri
44e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieriunsigned util_semantic_set_from_program_file(struct util_semantic_set *set, const struct tgsi_token *tokens, enum tgsi_file_type file);
45e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri
46e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri/* efficient_slots is the number of slots such that hardware performance is
47e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * the same for using that amount, with holes, or less slots but with less
48e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * holes.
49e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri *
50e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri * num_slots is the size of the layout array and hardware limit instead.
51e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri *
52520521e3809a36201582fa48ee173eba12e97812Dylan Noblesmith * efficient_slots == 0 or efficient_slots == num_slots are typical settings.
53e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri */
54e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbierivoid util_semantic_layout_from_set(unsigned char *layout, const struct util_semantic_set *set, unsigned efficient_slots, unsigned num_slots);
55e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri
56e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieristatic INLINE void
57520521e3809a36201582fa48ee173eba12e97812Dylan Noblesmithutil_semantic_table_from_layout(unsigned char *table, size_t table_size, unsigned char *layout,
58520521e3809a36201582fa48ee173eba12e97812Dylan Noblesmith                                unsigned char first_slot_value, unsigned char num_slots)
59e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri{
60520521e3809a36201582fa48ee173eba12e97812Dylan Noblesmith   unsigned char i;
61520521e3809a36201582fa48ee173eba12e97812Dylan Noblesmith   memset(table, 0xff, table_size);
62e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri
634a6eb492e86f74434504766ec551130ac6306e6dVinson Lee   for(i = 0; i < num_slots; ++i)
64e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri      table[layout[i]] = first_slot_value + i;
65e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri}
66e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri
67e6ff995d14085caa447c4e8634bf069c8a94f0ecLuca Barbieri#endif /* U_LINKAGE_H_ */
68