-
Couldn't load subscription status.
- Fork 51
[HLSL] define the matrix element accessor semantics #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
specs/language/expressions.tex
Outdated
| postfix-expression \terminal{.\_<integer-literal><integer-literal>}\br | ||
| postfix-expression \terminal{.\_m<integer-literal><integer-literal>}\br |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the propper way in the grammar to specify that ._m and ._ can happen multiple times like in vector swizzle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want something like:
| postfix-expression \terminal{.\_<integer-literal><integer-literal>}\br | |
| postfix-expression \terminal{.\_m<integer-literal><integer-literal>}\br | |
| postfix-expression matrix-zero-indexed-accessor\br | |
| postfix-expression matrix-one-indexed-accessor\br | |
| \define{matrix-zero-indexed-accessor}\br | |
| \opt{matrix-zero-indexed-accessor} \terminal{_m} integer-literal\br | |
| \define{matrix-one-indexed-accessor}\br | |
| \opt{matrix-one-indexed-accessor} \terminal{_} integer-literal\br |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we also should not use integer-literal here, we should define separate index grammar elements because the valid characters are 0 1 2 3 and 1 2 3 4 not the full space of integer-literal which is more like [0-9]+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to escape the _ via \_ otherwise my latex compiler breaks.
As an asside I'm also seeing this warning everywhere
Underfull \hbox (badness 10000) in paragraph at lines 172--181Underfull \hbox (badness 10000) in paragraph at lines 129--131
Doesn't seem to impact spec generation so I'm going to ignore it for now.
| \begin{grammar} | ||
| \define{postfix-expression}\br | ||
| primary-expression\br | ||
| postfix-expression [ expression ][ expression ]\br % | ||
| postfix-expression matrix-zero-indexed-accessor\br | ||
| postfix-expression matrix-one-indexed-accessor\br | ||
| \define{matrix-zero-indexed-accessor}\br | ||
| \opt{matrix-zero-indexed-accessor} \terminal{\_m} integer-literal\br | ||
| \define{matrix-one-indexed-accessor}\br | ||
| \opt{matrix-one-indexed-accessor} \terminal{\_} integer-literal\br | ||
| \end{grammar} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I set you on the wrong path for the grammar. The grammar should probably be something more like:
\begin{grammar}
\define {matrix-accessor-sequence}\br
matrix-zero-indexed-accessor-sequence\br
matrix-one-indexed-accessor-sequence\br
\define{matrix-zero-indexed-accessor-sequence}\br
matrix-zero-indexed-accessor\br
matrix-zero-indexed-accessor-sequence matrix-zero-indexed-accessor\br
\define{matrix-zero-indexed-accessor}\br
\terminal{\_m} zero-index-value\br
\define{zero-index-value}\br
\terminal{0}\br \terminal{1}\br \terminal{2}\br \terminal{3}\br
\define{matrix-one-indexed-accessor-sequence}\br
matrix-one-indexed-accessor\br
matrix-one-indexed-accessor-sequence matrix-one-indexed-accessor\br
\define{matrix-one-indexed-accessor}\br
\terminal{\_m} one-index-value\br
\define{one-index-value}\br
\terminal{1}\br \terminal{2}\br \terminal{3}\br \terminal{4}\br
\end{grammar}
Two things to note:
(1) you're not defining postfix-expression, that's defined above, you should be adding a formulation something like postix-expression \terminal{.} matrix-accessor-sequence.
(2) We should describe subscripts on matrices separately because they behave quite differently, but you actually don't need to describe the grammar since it works recursively from the already defined [] grammars in Expr.Post.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we define zero-index-value and one-index-value in Lex.Literal.Int and reuse concepts like nonzero-digit
I had a thought to define it as
\define{one-index-value}\br
nonzero-dim-constraint-digit}\br
\[
\begin{array}{rcl}
\textit{nonzero-digit} &::=& 1 \mid 2 \mid 3 \mid 4 \mid 5 \mid 6 \mid 7 \mid 8 \mid 9 \\[4pt]
\textit{nonzero-dim-constraint-digit} &::=& \textit{nonzero-digit} \quad \text{where value} \le 4
\end{array}
\]There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't put them in the Lex chapter. They're only valid grammar constructs in this narrow space, and I think it's a lot simpler and clearer to read to just list the four possible values for each context.
148e920 to
f02f52f
Compare
| \define{matrix-swizzle-component-sequence}\br | ||
| matrix-zero-indexed-swizzle-sequence\br | ||
| matrix-one-indexed-swizzle-sequence\br |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions, but otherwise LGTM.
Co-authored-by: Chris B <[email protected]>
Co-authored-by: Chris B <[email protected]>
Co-authored-by: Chris B <[email protected]>
Co-authored-by: Chris B <[email protected]>
fixes #677
Moved the Vector Swizzle stuff that repeats with Matrix and moved it to a generic swizzle section.

The new Matrix Swizzle looks like this:
