Skip to content

Fix issue with register spilling in light list shaders #3016

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

Merged
merged 3 commits into from
Jan 14, 2021

Conversation

FrancescoC-unity
Copy link
Contributor

@FrancescoC-unity FrancescoC-unity commented Jan 7, 2021

On FXC using local arrays often causes the use of "indexable temp" which causes fairly awkward code gen and register spilling as consequence. This is horrible for performance, but most importantly on DX12 on Xbox register spilling is illegal in async, causing hard crashes.

This PR replaces those with LDS and that fixes the issue. On platforms that don't generate bad code like this MIGHT be slightly more expensive (doesn't look like it will be), but it is gonna be better on above mentioned platform... and it doesn't crash :)

For both case I tried to port the code as closely as possible to be using LDS instead of local arrays, not sure if we have more optimal ways, but did not want to introduce potentially more disruptive changes.

Fogbugz link: https://fogbugz.unity3d.com/f/cases/1296144/

@EvgeniiG
Copy link
Contributor

EvgeniiG commented Jan 7, 2021

What's the cost of doing this? Z-binning heavily uses the existing code. Is it 5% slower? 50%? You need to profile these changes in the z-binning branch.

@FrancescoC-unity
Copy link
Contributor Author

FrancescoC-unity commented Jan 7, 2021

What's the cost of doing this? Z-binning heavily uses the existing code. Is it 5% slower? 50%? You need to profile these changes in the z-binning branch.

I tried really briefly and the merging didn't go great, unfortunately don't have time to check on the zbinning branch (I am off from tonight).

On master the AABB part, I just tried and it is actually faster on PS4 too and I had a lot of lights; did not expect that so I guess bad code gen was made there too

@sebastienlagarde
Copy link
Contributor

sebastienlagarde commented Jan 7, 2021

What's the cost of doing this? Z-binning heavily uses the existing code. Is it 5% slower? 50%? You need to profile these changes in the z-binning branch.

Note that the current code crash on Xbox (d3d12) and is shipped with HDRP 10.x and 11.x. So we must fix it in all cases, it can't stay as it was and must be backport to current shipped verison. Mainline is the priority. We missed it as d3d12 xbox test have only been added recently on Yamato.

@EvgeniiG
Copy link
Contributor

EvgeniiG commented Jan 7, 2021

In the current version of the HDRP, the perf impact will be minimal for sure, so it is safe to merge. But in the new version, the perf impact may be unacceptable, so I don't know if it's a great long-term solution. Shared memory is generally far slower than registers (100 cycles to access). I must also note that this is an Xbox-specific bug, yet this change affects ALL platforms.

@FrancescoC-unity
Copy link
Contributor Author

FrancescoC-unity commented Jan 7, 2021

In the current version of the HDRP, the perf impact will be minimal for sure, so it is safe to merge. But in the new version, the perf impact may be unacceptable, so I don't know if it's a great long-term solution. Shared memory is generally far slower than registers (100 cycles to access).

Yes, but it spills on FXC, so it will be slower than LDS access in that case and it will explode VGPR usage. This is not xbox specific is FXC specific. It is just that xbox is more strict. Indeed worth checking what happens on other platforms and if bad then we make specific for fxc platforms.

The change can be made per platform, but it would pollute a fair bit the code given the type of change.

@EvgeniiG
Copy link
Contributor

EvgeniiG commented Jan 7, 2021

The spill is to LDS I assume. So the compiler is doing something like you did, just less aggressive.

@EvgeniiG
Copy link
Contributor

EvgeniiG commented Jan 7, 2021

I tried really briefly and the merging didn't go great, unfortunately don't have time to check on the zbinning branch (I am off from tonight).

On master the AABB part, I just tried and it is actually faster on PS4 too and I had a lot of lights; did not expect that so I guess bad code gen was made there too

OK, I will profile it for you.

@FrancescoC-unity
Copy link
Contributor Author

FrancescoC-unity commented Jan 7, 2021

The spill is to LDS I assume. So the compiler is doing something like you did, just less aggressive.

Sending message to slack. But no, it absolutely does not, it is going to be much slower (more detail privately).

@sebastienlagarde sebastienlagarde merged commit eb02048 into master Jan 14, 2021
@sebastienlagarde sebastienlagarde deleted the HDRP/fix-crash-on-xbox branch January 14, 2021 19:17
sebastienlagarde added a commit that referenced this pull request Mar 2, 2021
* Fix issue with register spilling in light list shaders #3016

* Fix a flickering issue related to moving shadow receivers (case 1302392) and a refactoring to avoid computing the same value for every effect. #3039

* Merge Hd/bugfix #3047

* [HDRP]Improvements and fixes on Volumes Components Inspectors #3072

* Fix XR depth copy and MSAA #3075

* [HDRP][Compositor] Fix issues with compositor's undo #3100

* Hdrp/docs/fix 1305538 (#3112)

* Added information about using recursive rendering and other effects

* Fixed formatting

* [HDRP] Merge Hd/bugfix #3120

* Formatting

Co-authored-by: FrancescoC-unity <43168857+FrancescoC-unity@users.noreply.github.com>
Co-authored-by: anisunity <42026998+anisunity@users.noreply.github.com>
Co-authored-by: alex-vazquez <76204843+alex-vazquez@users.noreply.github.com>
Co-authored-by: Fabien Houlmann <44069206+fabien-unity@users.noreply.github.com>
Co-authored-by: Pavlos Mavridis <pavlos.mavridis@unity3d.com>
Co-authored-by: Lewis Jordan <lewis.jordan@hotmail.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants