|
152 | 152 | simple-type-specifier braced-init-list\br |
153 | 153 | typename-specifier braced-init-list\br |
154 | 154 | postfix-expression \terminal{.} \opt{\terminal{template}} id-expression\br |
155 | | - postfix-expression \terminal{->} \opt{\terminal{template}} id-expression\br |
| 155 | + postfix-expression \terminal{.} vector-swizzle-component-sequence\br |
156 | 156 | postfix-expression \terminal{++}\br |
157 | 157 | postfix-expression \terminal{--} |
158 | 158 | \end{grammar} |
|
167 | 167 | (\ref{Overload}).\footnote{HLSL does not support the base address of a subscript |
168 | 168 | operator being the expression inside the braces, which is valid in C and C++.} |
169 | 169 |
|
| 170 | +\p If the postfix expression \texttt{E1} is of vector type, the expression |
| 171 | +\textit{E2} must be a value of integer type. If the value is known at compile |
| 172 | +time to be outside the range \texttt{[0, N-1]} where \texttt{N} is the number of |
| 173 | +elements in the vector, the program is ill-formed. If the value is outside the |
| 174 | +range at runtime, the behavior is undefined. |
| 175 | + |
| 176 | +\Sec{Vector Swizzle}{Expr.Post.VectorSwizzle} |
| 177 | + |
| 178 | +\begin{grammar} |
| 179 | + \define{vector-swizzle-component-sequence}\br |
| 180 | + swizzle-component-sequence-rgba\br |
| 181 | + swizzle-component-sequence-xyzw\br |
| 182 | + |
| 183 | + \define{swizzle-component-sequence-rgba}\br |
| 184 | + swizzle-component-rgba\br |
| 185 | + swizzle-component-sequence-rgba swizzle-component-rgba\br |
| 186 | + |
| 187 | + \define{swizzle-component-sequence-xyzw}\br |
| 188 | + swizzle-component-xyzw\br |
| 189 | + swizzle-component-sequence-xyzw swizzle-component-xyzw\br |
| 190 | + |
| 191 | + \define{swizzle-component-rgba} \textnormal{one of}\br |
| 192 | + \terminal{r g b a}\br |
| 193 | + |
| 194 | + \define{swizzle-component-xyzw} \textnormal{one of}\br |
| 195 | + \terminal{x y z w} |
| 196 | +\end{grammar} |
| 197 | + |
| 198 | +\p A \textit{postfix-expression} followed by a dot (\texttt{.}) and a sequence |
| 199 | +of one or more \textit{swizzle-components} is a postfix expression. The |
| 200 | +postfix expression before the dot is evaluated and must be of vector type. If |
| 201 | +the postfix expression before the dot is an lvalue, the swizzle expression may |
| 202 | +produce either an lvalue or a prvalue; otherwise it produces a prvalue. |
| 203 | + |
| 204 | +\p A \textit{swizzle-component-sequence} is a sequence of one or more swizzle |
| 205 | +components of either the \textit{swizzle-component-rgba} or |
| 206 | +\textit{swizzle-component-xyzw} forms; the two forms may not be mixed in the |
| 207 | +same \textit{swizzle-component-sequence}. The type of a swizzle expression is a |
| 208 | +vector of the same element type as the postfix expression before the dot, with a |
| 209 | +number of elements equal to the number of components in the |
| 210 | +\textit{swizzle-component-sequence}. If the postfix expression before the dot is |
| 211 | +an lvalue and the \textit{swizzle-component-sequence} contains no repeated |
| 212 | +components, the swizzle expression is an lvalue; otherwise it is a prvalue. |
| 213 | + |
| 214 | +\p Swizzle components map to elements of the vector in the following way: |
| 215 | + |
| 216 | +\begin{center} |
| 217 | + \begin{tabular}{|| c | c | c ||} |
| 218 | + \hline |
| 219 | + Element Index & RGBA component & XYZW component \\ |
| 220 | + \hline |
| 221 | + 0 & r & x \\ |
| 222 | + 1 & g & y \\ |
| 223 | + 2 & b & z \\ |
| 224 | + 3 & a & w \\ |
| 225 | + \hline |
| 226 | + \end{tabular} |
| 227 | +\end{center} |
| 228 | + |
| 229 | +\p A program is ill-formed if any component in the \textit{swizzle-component-sequence} |
| 230 | +refers to an element index that is out of range of the vector type of the |
| 231 | +postfix expression before the dot. |
| 232 | + |
170 | 233 | \Sec{Function Calls}{Expr.Post.Call} |
171 | 234 |
|
172 | 235 | \p A function call may be an \textit{ordinary function}, or a \textit{member |
|
0 commit comments