2 * Copyright 2013 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "svga_context.h"
27 #include "svga_link.h"
29 #include "tgsi/tgsi_strings.h"
32 #define INVALID_INDEX 255
36 * Examine input and output shaders info to link outputs from the
37 * output shader to inputs from the input shader.
38 * Basically, we'll remap input shader's input slots to new numbers
39 * based on semantic name/index of the outputs from the output shader.
42 svga_link_shaders(const struct tgsi_shader_info
*outshader_info
,
43 const struct tgsi_shader_info
*inshader_info
,
44 struct shader_linkage
*linkage
)
46 unsigned i
, free_slot
;
48 for (i
= 0; i
< Elements(linkage
->input_map
); i
++) {
49 linkage
->input_map
[i
] = INVALID_INDEX
;
52 /* Assign input slots for input shader inputs.
53 * Basically, we want to use the same index for the output shader's outputs
54 * and the input shader's inputs that should be linked together.
55 * We'll modify the input shader's inputs to match the output shader.
57 assert(inshader_info
->num_inputs
<=
58 Elements(inshader_info
->input_semantic_name
));
60 /* free register index that can be used for built-in varyings */
61 free_slot
= outshader_info
->num_outputs
+ 1;
63 for (i
= 0; i
< inshader_info
->num_inputs
; i
++) {
64 unsigned sem_name
= inshader_info
->input_semantic_name
[i
];
65 unsigned sem_index
= inshader_info
->input_semantic_index
[i
];
68 * Get the clip distance inputs from the output shader's
69 * clip distance shadow copy.
71 if (sem_name
== TGSI_SEMANTIC_CLIPDIST
) {
72 linkage
->input_map
[i
] = outshader_info
->num_outputs
+ 1 + sem_index
;
73 /* make sure free_slot includes this extra output */
74 free_slot
= MAX2(free_slot
, linkage
->input_map
[i
] + 1);
77 /* search output shader outputs for same item */
78 for (j
= 0; j
< outshader_info
->num_outputs
; j
++) {
79 assert(j
< Elements(outshader_info
->output_semantic_name
));
80 if (outshader_info
->output_semantic_name
[j
] == sem_name
&&
81 outshader_info
->output_semantic_index
[j
] == sem_index
) {
82 linkage
->input_map
[i
] = j
;
89 linkage
->num_inputs
= inshader_info
->num_inputs
;
91 /* Things like the front-face register are handled here */
92 for (i
= 0; i
< inshader_info
->num_inputs
; i
++) {
93 if (linkage
->input_map
[i
] == INVALID_INDEX
) {
94 unsigned j
= free_slot
++;
95 linkage
->input_map
[i
] = j
;
102 for (i
= 0; i
< linkage
->num_inputs
; i
++) {
104 assert(linkage
->input_map
[i
] != INVALID_INDEX
);
106 debug_printf("input shader input[%d] slot %u %s %u %s\n",
108 linkage
->input_map
[i
],
109 tgsi_semantic_names
[inshader_info
->input_semantic_name
[i
]],
110 inshader_info
->input_semantic_index
[i
],
111 tgsi_interpolate_names
[inshader_info
->input_interpolate
[i
]]);
113 /* make sure no repeating register index */
114 if (reg
& 1 << linkage
->input_map
[i
]) {
117 reg
|= 1 << linkage
->input_map
[i
];