Commit 4be2d31
[VFX] Support CustomType & GraphicsBuffer in CustomHLSL
Initially code from [hackweek](https://drive.google.com/file/d/1g8j6nYsJwYIe80wRt4tBNlVbEayeGqom/view?usp=drive_link) project but made it clean because the improvement worth it and it fixes a couple of issue.
Fix some usage in CustomHLSL which is now allowing:
- `StructuredBuffer<CustomType>`: this is about UUM-64315
- `RWStructuredBuffer<float>`: Prevent usage of global buffer for this common case
- `StructuredBuffer<uint3>`: Even if we don't have `uint3` in VFX, we are allowing this kind of declaration in CustomHLSL
- `RWByteAddressBuffer`, `AppendStructuredBuffer`, `ConsumeStructuredBuffer`, `Buffer<>`, `RWBuffer<>`: I covered all common type of HLSL
🎁 Bonus, fix regression at https://github.cds.internal.unity3d.com/unity/unity/pull/45766/commits/ce1a39b236bcddaebfbc3cadb8c9e8ccdc6eaa0c which is simply a revert from https://github.cds.internal.unity3d.com/unity/unity/commit/517c85322917cc0ff86a75e2c5887d5685e2db04
## Behind the curtain
There was an illegal change of expression within custom hlsl, see this code in trunk (BuildExpression modifies parent expression):
https://github.cds.internal.unity3d.com/unity/unity/blob/eb1023001e78a637400bfa08cb0f8f4b287c381a/Packages/com.unity.visualeffectgraph/Editor/Models/Operators/Implementations/CustomHLSL.cs#L246
I changed the approach to use an intermediate expression which link the source graphicsBuffer to a usage.
The resolution of this issue has been done with this commit https://github.cds.internal.unity3d.com/unity/unity/pull/42668/commits/5f4581f13ee481f24aa27b3be8ccf1d5ac2d84ab
Here a sum up of the situation:

Let's take the example of this graph:

It will generates an expression graph like this:

_N.B.: In reality, if GraphicsBufferUsage are identical, expressions `1.` & `2.` are the same reference._
We are now going to track `VFXExpressionGraphicsBufferUsage` in compilation to associate every GraphicsBuffer with their future declaration.
The same approach is use in CustomHLSL block, operator but also with SampleBuffer.
## Known Limitation
- There is an issue regarding include in custom HLSL => UUM-64570, there is a repro in `026_CellularAutomaton` (which a workaround)
- Diverging usage of buffer can be marked as illegal when it's technically possible:

_N.B.: I think we can considered this limitation as a bug, we are gathering usage globally while it should be done only per context._ , this is an issue which can be fixed with UUM-66620 (this also an issue where usage should be computed per context)
- We aren't supporting `RWTexture2D<float>` and other, it would require the integration of texture usage pattern, I would like to explore this in the future.1 parent 351b3ea commit 4be2d31
File tree
40 files changed
+20563
-164
lines changed- Packages/com.unity.visualeffectgraph/Editor
- Compiler
- Core
- Expressions
- Models
- Blocks/Implementations/HLSL
- Operators/Implementations
- Types
- Tests/SRPTests
- Packages/com.unity.testing.visualeffectgraph
- Runtime
- Scenes
- Projects
- VisualEffectGraph_HDRP
- Assets/AllTests/Editor/Tests
- ProjectSettings
- VisualEffectGraph_URP/ProjectSettings
40 files changed
+20563
-164
lines changedLines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
466 | 466 | | |
467 | 467 | | |
468 | 468 | | |
469 | | - | |
| 469 | + | |
470 | 470 | | |
471 | | - | |
| 471 | + | |
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
| |||
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
700 | | - | |
| 700 | + | |
701 | 701 | | |
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
705 | 705 | | |
706 | 706 | | |
707 | 707 | | |
708 | | - | |
| 708 | + | |
709 | 709 | | |
710 | 710 | | |
711 | 711 | | |
| |||
978 | 978 | | |
979 | 979 | | |
980 | 980 | | |
981 | | - | |
| 981 | + | |
982 | 982 | | |
983 | 983 | | |
984 | 984 | | |
| |||
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
90 | | - | |
| 89 | + | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
| 297 | + | |
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | | - | |
| 302 | + | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
845 | | - | |
| 845 | + | |
846 | 846 | | |
847 | 847 | | |
848 | 848 | | |
| |||
Lines changed: 30 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | | - | |
| 306 | + | |
307 | 307 | | |
308 | | - | |
| 308 | + | |
309 | 309 | | |
| 310 | + | |
310 | 311 | | |
311 | 312 | | |
312 | 313 | | |
| |||
318 | 319 | | |
319 | 320 | | |
320 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
321 | 326 | | |
| 327 | + | |
322 | 328 | | |
323 | 329 | | |
324 | | - | |
| 330 | + | |
325 | 331 | | |
326 | 332 | | |
327 | 333 | | |
328 | 334 | | |
329 | | - | |
330 | | - | |
| 335 | + | |
331 | 336 | | |
332 | | - | |
| 337 | + | |
333 | 338 | | |
334 | 339 | | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
| 340 | + | |
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
497 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
498 | 510 | | |
499 | 511 | | |
500 | 512 | | |
| |||
505 | 517 | | |
506 | 518 | | |
507 | 519 | | |
508 | | - | |
509 | | - | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
510 | 523 | | |
511 | 524 | | |
512 | 525 | | |
| |||
544 | 557 | | |
545 | 558 | | |
546 | 559 | | |
547 | | - | |
| 560 | + | |
548 | 561 | | |
549 | 562 | | |
550 | 563 | | |
551 | 564 | | |
552 | 565 | | |
553 | | - | |
| 566 | + | |
554 | 567 | | |
555 | 568 | | |
556 | 569 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
182 | 198 | | |
183 | 199 | | |
184 | 200 | | |
| |||
Lines changed: 0 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | 170 | | |
186 | 171 | | |
187 | 172 | | |
| |||
Lines changed: 3 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
56 | | - | |
| 55 | + | |
57 | 56 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 57 | | |
65 | 58 | | |
66 | 59 | | |
| |||
74 | 67 | | |
75 | 68 | | |
76 | 69 | | |
77 | | - | |
| 70 | + | |
78 | 71 | | |
79 | 72 | | |
80 | 73 | | |
81 | 74 | | |
82 | 75 | | |
83 | | - | |
84 | 76 | | |
85 | 77 | | |
86 | 78 | | |
| |||
89 | 81 | | |
90 | 82 | | |
91 | 83 | | |
92 | | - | |
93 | 84 | | |
94 | 85 | | |
95 | 86 | | |
| |||
0 commit comments