Skip to content

Conversation

@farzonl
Copy link
Collaborator

@farzonl farzonl commented Oct 13, 2025

fixes #677

Moved the Vector Swizzle stuff that repeats with Matrix and moved it to a generic swizzle section.
image

The new Matrix Swizzle looks like this:
image

image

@github-actions github-actions bot added the language-spec Issue with completed spec label Oct 13, 2025
Comment on lines 175 to 176
postfix-expression \terminal{.\_<integer-literal><integer-literal>}\br
postfix-expression \terminal{.\_m<integer-literal><integer-literal>}\br
Copy link
Collaborator Author

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?

Copy link
Collaborator

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:

Suggested change
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

Copy link
Collaborator

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]+.

Copy link
Collaborator Author

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--181
  • Underfull \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.

Comment on lines 171 to 262
\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}
Copy link
Collaborator

@llvm-beanz llvm-beanz Oct 14, 2025

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.

Copy link
Collaborator Author

@farzonl farzonl Oct 14, 2025

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}
\]

Copy link
Collaborator

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.

Comment on lines +239 to +241
\define{matrix-swizzle-component-sequence}\br
matrix-zero-indexed-swizzle-sequence\br
matrix-one-indexed-swizzle-sequence\br
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.

Copy link
Collaborator

@llvm-beanz llvm-beanz left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

language-spec Issue with completed spec

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HLSL][Matrix] Document the ._<numeric><numeric> and ._m<numeric><numeric> accessors

2 participants