Skip to content

Commit

Permalink
Shaders can now have #else ifdef chains (#7431)
Browse files Browse the repository at this point in the history
# Objective

Currently, shaders may only have syntax such as

```wgsl
#ifdef FOO
// foo code
#else
#ifdef BAR
// bar code
#else
#ifdef BAZ
// baz code
#else
// fallback code
#endif
#endif
#endif
```

This is hard to read and follow.
Add a way to allow writing `#else ifdef DEFINE` to reduce the number of scopes introduced and to increase readability.

## Solution

Refactor the current preprocessing a bit and add logic to allow `#else ifdef DEFINE`.
This includes per-scope tracking of whether a branch has been accepted.
Add a few tests for this feature.

With these changes we may now write:

```wgsl
#ifdef FOO
// foo code
#else ifdef BAR
// bar code
#else ifdef BAZ
// baz code
#else
// fallback code
#endif
```

instead.

---

## Changelog

- Add `#else ifdef` to shader preprocessing.
  • Loading branch information
torsteingrindvik committed Feb 4, 2023
1 parent 3af6179 commit 12f30f5
Showing 1 changed file with 493 additions and 12 deletions.
Loading

0 comments on commit 12f30f5

Please sign in to comment.