Skip to content

Commit f02f52f

Browse files
committed
[HLSL] define the matrix element accessor semantics
fixes #677
1 parent 6cab4b4 commit f02f52f

File tree

1 file changed

+58
-14
lines changed

1 file changed

+58
-14
lines changed

specs/language/expressions.tex

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
typename-specifier braced-init-list\br
154154
postfix-expression \terminal{.} \opt{\terminal{template}} id-expression\br
155155
postfix-expression \terminal{.} vector-swizzle-component-sequence\br
156+
postfix-expression \terminal{.} matrix-swizzle-component-sequence\br
156157
postfix-expression \terminal{++}\br
157158
postfix-expression \terminal{--}
158159
\end{grammar}
@@ -173,7 +174,19 @@
173174
elements in the vector, the program is ill-formed. If the value is outside the
174175
range at runtime, the behavior is undefined.
175176

176-
\Sec{Vector Swizzle}{Expr.Post.VectorSwizzle}
177+
\Sec{Swizzle}{Expr.Post.Swizzle}
178+
\p A \textit{postfix-expression} followed by a dot (\texttt{.}) and a sequence
179+
of one or more \textit{swizzle-components} is a postfix expression. The
180+
postfix expression before the dot is evaluated and must be of vector or matrix type.
181+
If the postfix expression before the dot is an lvalue, the swizzle expression may
182+
produce either an lvalue or a prvalue; otherwise it produces a prvalue.
183+
184+
185+
\p If the postfix expression before the dot is
186+
an lvalue and the \textit{swizzle-component-sequence} contains no repeated
187+
components, the swizzle expression is an lvalue; otherwise it is a prvalue.
188+
189+
\Sec{Vector Swizzle}{Expr.Post.Swizzle.Vector}
177190

178191
\begin{grammar}
179192
\define{vector-swizzle-component-sequence}\br
@@ -195,23 +208,14 @@
195208
\terminal{x y z w}
196209
\end{grammar}
197210

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
211+
\p A \textit{vector-swizzle-component-sequence} is a sequence of one or more swizzle
205212
components of either the \textit{swizzle-component-rgba} or
206213
\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
214+
same \textit{vector-swizzle-component-sequence}. The type of a swizzle expression is a
208215
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.
216+
number of elements equal to the number of components in the \textit{vector-swizzle-component-sequence}.
213217

214-
\p Swizzle components map to elements of the vector in the following way:
218+
\p Vector swizzle components map to elements of the vector in the following way:
215219

216220
\begin{center}
217221
\begin{tabular}{|| c | c | c ||}
@@ -230,6 +234,46 @@
230234
refers to an element index that is out of range of the vector type of the
231235
postfix expression before the dot.
232236

237+
\Sec{Matrix Swizzle}{Expr.Post.Swizzle.Matrix}
238+
\begin{grammar}
239+
\define{matrix-swizzle-component-sequence}\br
240+
matrix-zero-indexed-swizzle-sequence\br
241+
matrix-one-indexed-swizzle-sequence\br
242+
243+
\define{matrix-zero-indexed-swizzle-sequence}\br
244+
matrix-zero-indexed-swizzle\br
245+
matrix-zero-indexed-swizzle-sequence matrix-zero-indexed-swizzle\br
246+
247+
\define{matrix-zero-indexed-swizzle}\br
248+
\terminal{\_m} zero-index-value\br
249+
250+
\define{zero-index-value} \textnormal{one of}\br
251+
\terminal{0 1 2 3 }\br
252+
253+
\define{matrix-one-indexed-swizzle-sequence}\br
254+
matrix-one-indexed-swizzle\br
255+
matrix-one-indexed-swizzle-sequence matrix-one-indexed-swizzle\br
256+
257+
\define{matrix-one-indexed-swizzle}\br
258+
\terminal{\_m} one-index-value\br
259+
260+
\define{one-index-value} \textnormal{one of}\br
261+
\terminal{1 2 3 4 }\br
262+
\end{grammar}
263+
\begin{itemize}
264+
\item \textbf{.\_} (math-style): subsequent subscripts use \textbf{1-based}
265+
indexing for both row and column.
266+
\item \textbf{.\_m} (memory-style): subsequent subscripts use \textbf{0-based}
267+
indexing for both row and column.
268+
\end{itemize}
269+
270+
\p A \textit{matrix-swizzle-component-sequence} is a sequence of one or more swizzle
271+
components of either the \textit{matrix-zero-indexed-swizzle} or
272+
\textit{matrix-one-indexed-swizzle} forms; the two forms may not be mixed in the
273+
same \textit{matrix-swizzle-component-sequence}. The type of a swizzle expression is a
274+
vector of the same element type as the postfix expression before the dot, with a
275+
number of elements equal to the number of components in the \textit{matrix-swizzle-component-sequence}.
276+
233277
\Sec{Function Calls}{Expr.Post.Call}
234278

235279
\p A function call may be an \textit{ordinary function}, or a \textit{member

0 commit comments

Comments
 (0)