19 Commits

Author SHA1 Message Date
Finn Plummer
3dec46d9bf
[HLSL][RootSignature] Correct RootSignatureParser to use correct SourceLocation in diagnostics (#147084)
The `SourceLocation` of a `RootSignatureToken` is incorrectly set to be
the "offset" into the concatenated string that denotes the
rootsignature. This causes an issue when the `StringLiteral` is a
multi-line expansion macro, since the offset will not account for the
characters between `StringLiteral` tokens.

This pr resolves this by retaining the `SourceLocation` information that
is kept in `StringLiteral` and then converting the offset in the
concatenated string into the proper `SourceLocation` using the
`StringLiteral::getLocationOfByte` interface. To do so, we will need to
adjust the `RootSignatureToken` to only hold its offset into the root
signature string. Then when the parser will use the token, it will need
to compute its actual `SourceLocation`.

See linked issue for more context.

For example:

```
#define DemoRootSignature \
 "CBV(b0)," \
 "RootConstants(num32BitConstants = 3, b0, invalid)"
  expected caret location ---------------^
  actual caret location ------------^
```

The caret points 5 characters early because the current offset did not
account for the characters:
```
'"' ' ' '\' ' ' '"'
 1   2   3   4   5
```

- Updates `RootSignatureParser` to retain `SourceLocation` information
by retaining the `StringLiteral` and passing the underlying `StringRef`
to the `Lexer`
- Updates `RootSignatureLexer` so that the constructed tokens only
reflect an offset into the `StringRef`
- Updates `RootSignatureParser` to directly construct its used `Lexer`
so that the `StringLiteral` is directly tied with the string used in the
`RootSignatureLexer`
- Updates `RootSignatureParser` to use
`StringLiteral::getLocationOfByte` to get the actual token location for
diagnostics
- Updates `ParseHLSLRootSignatureTest` to construct a phony
`AST`/`StringLiteral` for the test cases
- Adds a test to `RootSignature-err.hlsl` showing that the
`SourceLocation` is correctly set for diagnostics in a multi-line macro
expansion

Resolves: https://github.com/llvm/llvm-project/issues/146967
2025-07-08 09:55:51 -07:00
Finn Plummer
5628bf5a1e
Reland "[HLSL][RootSignature] Add parsing of filter enum for StaticSampler" (#142441)
This relands https://github.com/llvm/llvm-project/pull/140294.

The initial naming of the enum class Filter and the Filter struct member
causes ambiguity when compiling with gcc.

This change addresses this my renaming `Filter` to `SamplerFilter`.

I have confirmed this builds locally using gcc.

Resolves https://github.com/llvm/llvm-project/issues/126574.
2025-06-02 13:22:21 -07:00
Finn Plummer
9bd63b1dc7
[HLSL][RootSignature] Add parsing of remaining enums to StaticSampler (#140305)
- defines in-memory reprsentation of `comparisonFunc` and `borderColor`
- defines parsing of the `ComparisonFunc` and `StaticBorderColor` enum
- integrates parsing of these number parameters with their respective
`parseComparisonFunc` and `parseStaticBorderColor`
- adds basic unit tests to demonstrate setting functionality

Part 6 of https://github.com/llvm/llvm-project/issues/126574
2025-05-30 13:24:01 -07:00
Finn Plummer
29d49de58a
Revert "[HLSL][RootSignature] Add parsing of filter enum for StaticSampler" (#142053)
The current naming of the `enum class Filter` and the Filter struct
member causes ambiguity.

This change will be reverted to be addressed by renaming the variable.

Reverts llvm/llvm-project#140294
2025-05-29 15:44:36 -07:00
Finn Plummer
dfc2c15f1c
[HLSL][RootSignature] Add parsing of filter enum for StaticSampler (#140294)
- defines in-memory reprsentation of `filter`
- defines parsing of the `Filter` enum
- integrates parsing of these number parameters with their respective,
`parseFilter`
 - adds basic unit tests to demonstrate setting functionality

Part 5 of https://github.com/llvm/llvm-project/issues/126574
2025-05-29 15:34:48 -07:00
Finn Plummer
2b5b8db9dc
[HLSL][RootSignature] Add parsing of address params in StaticSampler (#140293)
- defines in-memory reprsentation of `address[U|V|W]`
 - defines parsing of the `TextureAddressMode` enum
- integrates parsing of these number parameters with their respective,
`parseTextureAddressMode`
 - adds basic unit tests to demonstrate setting functionality

Part 4 of https://github.com/llvm/llvm-project/issues/126574
2025-05-29 15:03:49 -07:00
Finn Plummer
c8eb094902
[HLSL][RootSiganture] Add parsing of new number params in StaticSampler (#140291)
- defines in-memory reprsentation of `maxAnisotropy`, `minLOD` and
`maxLOD`
- integrates parsing of these number parameters with their respective,
`parseUInt` and `parseFloat` respectively
 - adds basic unit tests to demonstrate setting functionality

Part 3 of https://github.com/llvm/llvm-project/issues/126574
2025-05-29 13:30:38 -07:00
Finn Plummer
a926c61cc0
[HLSL][RootSignature] Add parsing of floats for StaticSampler (#140181)
- defines in-memory representaiton of MipLODBias to allow for testing of
a float parameter
- defines `handleInt` and `handleFloat` to handle converting a token's
`NumSpelling` into a valid float
- plugs this into `parseFloatParam` to fill in the MipLODBias param

The parsing of floats is required to match the behaviour of DXC. This
behaviour is outlined as follows:
- if the number is an integer then convert it using `_atoi64`, check for
overflow and static_cast this to a float
- if the number is a float then convert it using `strtod`, check for
float overflow and static_cast this to a float, this will implicitly
also check for double over/underflow and if the string is malformed then
it will return an error

This pr matches this behaviour by parsing as, uint/int accordingly and
then casting, or, by using the correct APFloat semantics/rounding mode
with `NumericLiteralParser`.

- adds testing of error diagnostics and valid float param values to
demonstrate functionality

Part 2 of https://github.com/llvm/llvm-project/issues/126574
2025-05-29 10:18:07 -07:00
Finn Plummer
02595417ce
[HLSL][RootSignature] Add parsing infastructure for StaticSampler (#140180)
- define StaticSampler in-memory representation
- implement the infastructure for parsing parameters of StaticSampler
- define and implement parsing of the `s` reg to demonstrate
functionality
- add unit tests

First part of https://github.com/llvm/llvm-project/issues/126574
2025-05-26 18:40:59 -07:00
Finn Plummer
b3963d30a3
[HLSL][RootSignature] Add parsing for RootFlags (#138055)
- defines the `RootFlags` in-memory enum
- defines `parseRootFlags` to parse the various flag enums into a single
`uint32_t`
- adds corresponding unit tests

- improves the diagnostic message for when we provide a non-zero integer
value to the flags

Resolves https://github.com/llvm/llvm-project/issues/126575
2025-05-09 12:40:14 -07:00
Finn Plummer
55517f5f44
[HLSL][RootSignature] Add parsing for empty RootConstants (#137999)
- defines the empty RootConstants in-memory struct
- adds test harness for testing it

- adds missing parameter keywords to the lexer (`RootConstants`,
`num32BitConstants`)

First part of implementing:
https://github.com/llvm/llvm-project/issues/126576
2025-05-08 08:24:47 -07:00
Finn Plummer
8e4dd21e63
[HLSL][RootSignature] Add lexing support for floating points (#137720)
- this takes care to add support to match the [behaviour of
DXC](34b6d0f91e/tools/clang/lib/Parse/HLSLRootSignature.cpp (L74))
acceptable floating point integers

Namely:
- Allow for specifying the decimal '.'
- Allow for specifying exponents with 'e' or 'E' and allow for 'f' to
denote an otherwise interpreted integer as a float

This pr is simply responsible of creating a token that could be
interpeted as a floating point integer by `NumericLiteralParser`. As
such, we are not required to validate that the special characters only
occur once and that 'f' is only at the end of the string. These will be
validated when invoking `NumericLiteralParser` during parsing.

Resolves #126565
2025-04-30 09:41:08 -07:00
Finn Plummer
9b74dce4a3
[HLSL][RootSignature] Add parsing of remaining Descriptor Table params (#137038)
- defines the special values for `DESCRIPTOR_RANGE_OFFSET_APPEND` and
`unbounded` for the `offset` and `numDescriptors` parameters
respectively

- adds these parmaters to the `DescriptorClause` struct and the params
struct

- plugs in parsing of `numDescriptors` and `offset` into
`parseDescriptorTableClauseParams`

- defines the `unbounded` enum keyword for the lexer to expose to the
parser

- adds corresponding unit tests

Part 5 of #126569
2025-04-25 14:38:02 -07:00
Finn Plummer
428fc2c887
[NFC][HLSL][RootSignature] Make the Lexer adhere to naming conventions (#134136)
- when developing the RootSignatureLexer library, we are creating new
files so we should set the standard to adhere to the coding conventions
for function naming
- this was missed in the initial review but caught in the review of the
parser pr
[here](https://github.com/llvm/llvm-project/pull/133302#discussion_r2017632092)

Co-authored-by: Finn Plummer <finnplummer@microsoft.com>
2025-04-04 13:43:45 -07:00
Finn Plummer
676755561d
Reland "[HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses" (#133958)
This pr relands https://github.com/llvm/llvm-project/pull/133302.

It resolves two issues:
- Linking error during build,
[here](https://github.com/llvm/llvm-project/pull/133302#issuecomment-2767259848).
There was a missing dependency for `clangLex` for the
`ParseHLSLRootSignatureTest.cpp` unit testing. This library was added to
the dependencies to resolve the error. It wasn't caught previously as
the library was transitively linked in most build environments
- Warning of unused declaration,
[here](https://github.com/llvm/llvm-project/pull/133302#issuecomment-2767091368).
There was a usability line in `LexHLSLRootSignature.h` of the form
`using TokenKind = enum RootSignatureToken::Kind` which causes this
error. The declaration is removed from the header file to be used
locally in the `.cpp` files that use it.
Notably, the original pr would also exposed `clang::hlsl::TokenKind` to
everywhere it was included, which had a name clash with
`tok::TokenKind`. This is another motivation to change to the proposed
resolution.

---------

Co-authored-by: Finn Plummer <finnplummer@microsoft.com>
2025-04-01 14:58:30 -07:00
Finn Plummer
5e2860a8d3
Revert "[HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses" (#133790)
Reverts llvm/llvm-project#133302

Reverting to inspect build failures that were introduced from use of the
`clang::Preprocessor` in unit testing, as well as, the warning about an
unused declaration. See linked issue for failures.
2025-03-31 13:38:09 -07:00
Finn Plummer
e4b9486056
[HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses (#133302)
- defines the Parser class and an initial set of helper methods to
support consuming tokens. functionality is demonstrated through a simple
empty descriptor table test case
- defines an initial in-memory representation of a DescriptorTable
- implements a test harness that will be used to validate the correct
diagnostics are generated. it will construct a dummy pre-processor with
diagnostics consumer to do so

Implements the first part of
https://github.com/llvm/llvm-project/issues/126569
2025-03-31 10:26:51 -07:00
Finn Plummer
83c4cb36aa
[HLSL][RootSignature] Make Root Signature lexer keywords case-insensitive (#132967)
From the corrections to the Root Signature specification here:
https://github.com/llvm/wg-hlsl/issues/192. It was denoted that keywords
are also case-insensitive in DXC.

This pr adjusts the lexer to adhere to the updated spec.

We also have a NFC to add a missing license to a file while in the area.

---------

Co-authored-by: Finn Plummer <finnplummer@microsoft.com>
2025-03-28 14:27:24 -07:00
Finn Plummer
b41b86a907
[HLSL][RootSignature] Implement Lexing of DescriptorTables (#122981)
For the sake of scope, we will let the lexing of floating literals be
deferred until needed for Static Samplers. Other than that this pr
should allow us to simply define new enumerations/keywords in
`RootSignatureTokenKinds.def` for when they are used in the parser. We
could have defined all of these keywords here, but for the sake of
correctness in review we will let them be split up.

- Define `RootSignatureLexer` and provide a public `LexToken` method for
external use
- Define the file `RootSignatureTokenKinds` to define required tokens
and allow for future custom keywords/enums
- Implement the internal methods required to parse the different types
of tokens (integers, flag enums, puncuators...)
- Add test harness for unit testing and the respective unit tests for
lexing the tokens

Resolves #126563

---------

Co-authored-by: Chris B <beanz@abolishcrlf.org>
2025-02-14 09:17:10 -08:00