Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 58 additions & 14 deletions specs/language/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
typename-specifier braced-init-list\br
postfix-expression \terminal{.} \opt{\terminal{template}} id-expression\br
postfix-expression \terminal{.} vector-swizzle-component-sequence\br
postfix-expression \terminal{.} matrix-swizzle-component-sequence\br
postfix-expression \terminal{++}\br
postfix-expression \terminal{--}
\end{grammar}
Expand All @@ -173,7 +174,19 @@
elements in the vector, the program is ill-formed. If the value is outside the
range at runtime, the behavior is undefined.

\Sec{Vector Swizzle}{Expr.Post.VectorSwizzle}
\Sec{Swizzle}{Expr.Post.Swizzle}
\p A \textit{postfix-expression} followed by a dot (\texttt{.}) and a sequence
of one or more \textit{swizzle-components} is a postfix expression. The
postfix expression before the dot is evaluated and must be of vector or matrix type.
If the postfix expression before the dot is an lvalue, the swizzle expression may
produce either an lvalue or a prvalue; otherwise it produces a prvalue.


\p If the postfix expression before the dot is
an lvalue and the \textit{swizzle-component-sequence} contains no repeated
components, the swizzle expression is an lvalue; otherwise it is a prvalue.

\Sec{Vector Swizzle}{Expr.Post.Swizzle.Vector}

\begin{grammar}
\define{vector-swizzle-component-sequence}\br
Expand All @@ -195,23 +208,14 @@
\terminal{x y z w}
\end{grammar}

\p A \textit{postfix-expression} followed by a dot (\texttt{.}) and a sequence
of one or more \textit{swizzle-components} is a postfix expression. The
postfix expression before the dot is evaluated and must be of vector type. If
the postfix expression before the dot is an lvalue, the swizzle expression may
produce either an lvalue or a prvalue; otherwise it produces a prvalue.

\p A \textit{swizzle-component-sequence} is a sequence of one or more swizzle
\p A \textit{vector-swizzle-component-sequence} is a sequence of one or more swizzle
components of either the \textit{swizzle-component-rgba} or
\textit{swizzle-component-xyzw} forms; the two forms may not be mixed in the
same \textit{swizzle-component-sequence}. The type of a swizzle expression is a
same \textit{vector-swizzle-component-sequence}. The type of a swizzle expression is a
vector of the same element type as the postfix expression before the dot, with a
number of elements equal to the number of components in the
\textit{swizzle-component-sequence}. If the postfix expression before the dot is
an lvalue and the \textit{swizzle-component-sequence} contains no repeated
components, the swizzle expression is an lvalue; otherwise it is a prvalue.
number of elements equal to the number of components in the \textit{vector-swizzle-component-sequence}.

\p Swizzle components map to elements of the vector in the following way:
\p Vector swizzle components map to elements of the vector in the following way:

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

\Sec{Matrix Swizzle}{Expr.Post.Swizzle.Matrix}
\begin{grammar}
\define{matrix-swizzle-component-sequence}\br
matrix-zero-indexed-swizzle-sequence\br
matrix-one-indexed-swizzle-sequence\br
Comment on lines +239 to +241
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llvm-beanz One unique thing I was thinking about indicating is that a matrix swizzle can not be more than 4 elements. That seems to be implied later when we indicate that a swizzle expression is a vector. However, with long vectors coming in SM 6.9 does this 4 element limitation on matrix swizzles go away? https://hlsl.godbolt.org/z/r9o5PKPWr because I am still seeing it in godbolt: https://hlsl.godbolt.org/z/fdnWqq7cK.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also don't allow vector swizzles to be more than 4 elements. I think we should keep the 4 element restriction.


\define{matrix-zero-indexed-swizzle-sequence}\br
matrix-zero-indexed-swizzle\br
matrix-zero-indexed-swizzle-sequence matrix-zero-indexed-swizzle\br

\define{matrix-zero-indexed-swizzle}\br
\terminal{\_m} zero-index-value\br

\define{zero-index-value} \textnormal{one of}\br
\terminal{0 1 2 3 }\br

\define{matrix-one-indexed-swizzle-sequence}\br
matrix-one-indexed-swizzle\br
matrix-one-indexed-swizzle-sequence matrix-one-indexed-swizzle\br

\define{matrix-one-indexed-swizzle}\br
\terminal{\_m} one-index-value\br

\define{one-index-value} \textnormal{one of}\br
\terminal{1 2 3 4 }\br
\end{grammar}
\begin{itemize}
\item \textbf{.\_} (math-style): subsequent subscripts use \textbf{1-based}
indexing for both row and column.
\item \textbf{.\_m} (memory-style): subsequent subscripts use \textbf{0-based}
indexing for both row and column.
\end{itemize}

\p A \textit{matrix-swizzle-component-sequence} is a sequence of one or more swizzle
components of either the \textit{matrix-zero-indexed-swizzle} or
\textit{matrix-one-indexed-swizzle} forms; the two forms may not be mixed in the
same \textit{matrix-swizzle-component-sequence}. The type of a swizzle expression is a
vector of the same element type as the postfix expression before the dot, with a
number of elements equal to the number of components in the \textit{matrix-swizzle-component-sequence}.

\Sec{Function Calls}{Expr.Post.Call}

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