Increase precision of SpotLight attenuation calculation to avoid driver bug on Intel devices #110363
+6
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On at least one intel integrated device (Intel Xe) I get a nasty precision bug when using the mobile renderer
I have tested on another device and the issue seems to be specific to this GPU. Most likely this is a shader code gen error in the driver (it could also be a bug with how FP16 is handled by Intel integrated GPUs).
We have two options:
I opted to avoid FP16 in this situation because I doubt that FP 16 is helping this specific code very much anyway.
This PR forces us to do 1 dot product, 1 max, operation, and 2 subtract operations in high precision that would normally be done at half precision. It also potentially adds an extra half register for most of this function. I say "potentially" since it's not guaranteed that a given compiler would pack
spot_dir
into a register with another variable anyway.As a trade off. This PR avoids 3 conversions from
vec3()
tohvec3()
, 1 conversion fromfloat
tohalf
, and 2 conversions fromhalf
tofloat
.Overall profiling doesn't reveal any obvious performance difference. So the impact on performance is inconclusive and likely it is highly device dependent.
Since the changes are minimal and the performance impact is inconclusive. I think we should go ahead with this PR. It is extremely bad for people to ship games and have them randomly look horrible on certain devices.
After this PR