edb16087410b9f78032a0282891a93799cfa2c06
2 * Copyright © 2011 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 DEALINGS
27 * This file computes the "VUE map" for a (non-fragment) shader stage, which
28 * describes the layout of its output varyings. The VUE map is used to match
29 * outputs from one stage with the inputs of the next.
31 * Largely, varyings can be placed however we like - producers/consumers simply
32 * have to agree on the layout. However, there is also a "VUE Header" that
33 * prescribes a fixed-layout for items that interact with fixed function
34 * hardware, such as the clipper and rasterizer.
37 * Paul Berry <stereotype441@gmail.com>
38 * Chris Forbes <chrisf@ijw.co.nz>
39 * Eric Anholt <eric@anholt.net>
43 #include "main/compiler.h"
44 #include "brw_context.h"
47 assign_vue_slot(struct brw_vue_map
*vue_map
, int varying
, int slot
)
49 /* Make sure this varying hasn't been assigned a slot already */
50 assert (vue_map
->varying_to_slot
[varying
] == -1);
52 vue_map
->varying_to_slot
[varying
] = slot
;
53 vue_map
->slot_to_varying
[slot
] = varying
;
57 * Compute the VUE map for a shader stage.
60 brw_compute_vue_map(const struct brw_device_info
*devinfo
,
61 struct brw_vue_map
*vue_map
,
62 GLbitfield64 slots_valid
,
65 /* Keep using the packed/contiguous layout on old hardware - we only need
66 * the SSO layout when using geometry/tessellation shaders or 32 FS input
67 * varyings, which only exist on Gen >= 6. It's also a bit more efficient.
72 vue_map
->slots_valid
= slots_valid
;
73 vue_map
->separate
= separate
;
75 /* gl_Layer and gl_ViewportIndex don't get their own varying slots -- they
76 * are stored in the first VUE slot (VARYING_SLOT_PSIZ).
78 slots_valid
&= ~(VARYING_BIT_LAYER
| VARYING_BIT_VIEWPORT
);
80 /* Make sure that the values we store in vue_map->varying_to_slot and
81 * vue_map->slot_to_varying won't overflow the signed chars that are used
82 * to store them. Note that since vue_map->slot_to_varying sometimes holds
83 * values equal to BRW_VARYING_SLOT_COUNT, we need to ensure that
84 * BRW_VARYING_SLOT_COUNT is <= 127, not 128.
86 STATIC_ASSERT(BRW_VARYING_SLOT_COUNT
<= 127);
88 for (int i
= 0; i
< BRW_VARYING_SLOT_COUNT
; ++i
) {
89 vue_map
->varying_to_slot
[i
] = -1;
90 vue_map
->slot_to_varying
[i
] = BRW_VARYING_SLOT_PAD
;
95 /* VUE header: format depends on chip generation and whether clipping is
98 * See the Sandybridge PRM, Volume 2 Part 1, section 1.5.1 (page 30),
99 * "Vertex URB Entry (VUE) Formats" which describes the VUE header layout.
101 if (devinfo
->gen
< 6) {
102 /* There are 8 dwords in VUE header pre-Ironlake:
103 * dword 0-3 is indices, point width, clip flags.
104 * dword 4-7 is ndc position
105 * dword 8-11 is the first vertex data.
107 * On Ironlake the VUE header is nominally 20 dwords, but the hardware
108 * will accept the same header layout as Gen4 [and should be a bit faster]
110 assign_vue_slot(vue_map
, VARYING_SLOT_PSIZ
, slot
++);
111 assign_vue_slot(vue_map
, BRW_VARYING_SLOT_NDC
, slot
++);
112 assign_vue_slot(vue_map
, VARYING_SLOT_POS
, slot
++);
114 /* There are 8 or 16 DWs (D0-D15) in VUE header on Sandybridge:
115 * dword 0-3 of the header is indices, point width, clip flags.
116 * dword 4-7 is the 4D space position
117 * dword 8-15 of the vertex header is the user clip distance if
119 * dword 8-11 or 16-19 is the first vertex element data we fill.
121 assign_vue_slot(vue_map
, VARYING_SLOT_PSIZ
, slot
++);
122 assign_vue_slot(vue_map
, VARYING_SLOT_POS
, slot
++);
123 if (slots_valid
& BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST0
))
124 assign_vue_slot(vue_map
, VARYING_SLOT_CLIP_DIST0
, slot
++);
125 if (slots_valid
& BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST1
))
126 assign_vue_slot(vue_map
, VARYING_SLOT_CLIP_DIST1
, slot
++);
128 /* front and back colors need to be consecutive so that we can use
129 * ATTRIBUTE_SWIZZLE_INPUTATTR_FACING to swizzle them when doing
132 if (slots_valid
& BITFIELD64_BIT(VARYING_SLOT_COL0
))
133 assign_vue_slot(vue_map
, VARYING_SLOT_COL0
, slot
++);
134 if (slots_valid
& BITFIELD64_BIT(VARYING_SLOT_BFC0
))
135 assign_vue_slot(vue_map
, VARYING_SLOT_BFC0
, slot
++);
136 if (slots_valid
& BITFIELD64_BIT(VARYING_SLOT_COL1
))
137 assign_vue_slot(vue_map
, VARYING_SLOT_COL1
, slot
++);
138 if (slots_valid
& BITFIELD64_BIT(VARYING_SLOT_BFC1
))
139 assign_vue_slot(vue_map
, VARYING_SLOT_BFC1
, slot
++);
142 /* The hardware doesn't care about the rest of the vertex outputs, so we
143 * can assign them however we like. For normal programs, we simply assign
146 * For separate shader pipelines, we first assign built-in varyings
147 * contiguous slots. This works because ARB_separate_shader_objects
148 * requires that all shaders have matching built-in varying interface
149 * blocks. Next, we assign generic varyings based on their location
150 * (either explicit or linker assigned). This guarantees a fixed layout.
152 * We generally don't need to assign a slot for VARYING_SLOT_CLIP_VERTEX,
153 * since it's encoded as the clip distances by emit_clip_distances().
154 * However, it may be output by transform feedback, and we'd rather not
155 * recompute state when TF changes, so we just always include it.
157 GLbitfield64 builtins
= slots_valid
& BITFIELD64_MASK(VARYING_SLOT_VAR0
);
158 while (builtins
!= 0) {
159 const int varying
= ffsll(builtins
) - 1;
160 if (vue_map
->varying_to_slot
[varying
] == -1) {
161 assign_vue_slot(vue_map
, varying
, slot
++);
163 builtins
&= ~BITFIELD64_BIT(varying
);
166 const int first_generic_slot
= slot
;
167 GLbitfield64 generics
= slots_valid
& ~BITFIELD64_MASK(VARYING_SLOT_VAR0
);
168 while (generics
!= 0) {
169 const int varying
= ffsll(generics
) - 1;
171 slot
= first_generic_slot
+ varying
- VARYING_SLOT_VAR0
;
172 assign_vue_slot(vue_map
, varying
, slot
);
174 assign_vue_slot(vue_map
, varying
, slot
++);
176 generics
&= ~BITFIELD64_BIT(varying
);
179 vue_map
->num_slots
= separate
? slot
+ 1 : slot
;
183 varying_name(brw_varying_slot slot
)
185 if (slot
< VARYING_SLOT_MAX
)
186 return gl_varying_slot_name(slot
);
188 static const char *brw_names
[] = {
189 [BRW_VARYING_SLOT_NDC
- VARYING_SLOT_MAX
] = "BRW_VARYING_SLOT_NDC",
190 [BRW_VARYING_SLOT_PAD
- VARYING_SLOT_MAX
] = "BRW_VARYING_SLOT_PAD",
191 [BRW_VARYING_SLOT_PNTC
- VARYING_SLOT_MAX
] = "BRW_VARYING_SLOT_PNTC",
194 return brw_names
[slot
- VARYING_SLOT_MAX
];
198 brw_print_vue_map(FILE *fp
, const struct brw_vue_map
*vue_map
)
200 fprintf(fp
, "VUE map (%d slots, %s)\n",
201 vue_map
->num_slots
, vue_map
->separate
? "SSO" : "non-SSO");
202 for (int i
= 0; i
< vue_map
->num_slots
; i
++) {
203 fprintf(fp
, " [%d] %s\n", i
,
204 varying_name(vue_map
->slot_to_varying
[i
]));