Skip to content
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

Implement 'half' floating point precision #262

Merged
merged 23 commits into from
Jan 27, 2022
Merged

Implement 'half' floating point precision #262

merged 23 commits into from
Jan 27, 2022

Conversation

darksylinc
Copy link
Member

This PR adds Hlms::setPrecisionMode with the following options:

  • PrecisionFull32
    • midf datatype maps to float (i.e. 32-bit)
    • This setting is always supported
  • PrecisionMidf16
    • midf datatype maps to float16_t (i.e. forced 16-bit)
    • It forces the driver to produce 16-bit code, even if unoptimal
    • Great for testing quality downgrades caused by 16-bit support
    • This depends on RSC_SHADER_FLOAT16
    • If unsupported, we fallback to PrecisionRelaxed
    • If unsupported, we then fallback to PrecisionFull32
  • PrecisionRelaxed
    • midf datatype maps to mediump float / min16float
    • The driver is allowed to work in either 16-bit or 32-bit code
    • This depends on RSC_SHADER_RELAXED_FLOAT
    • If unsupported, we fallback to PrecisionMidf16
    • If unsupported, we then fallback to PrecisionFull32

We use the keyword "midf" because "half" is already taken on Metal.

The default is PrecisionFull32 which always works and ensures no quality problems.

PrecisionMidf16 & PrecisionRelaxed may need more testing but may help with either performance or battery usage in mobile.

PrecisionRelaxed is supported by D3D11 however it's force-disabled because of fxc bugs.

Only Vulkan and Metal can currently take advantage of these settings and is likely to stay that way.

Support is very new: I've encountered various bugs (in drivers, in spirv-reflect, in fxc, in RenderDoc) so users are advised to test this option thoroughly before deploying it.

Metal is likely the API with best half 16-bit support at the moment.

HlmsDiskCache now accounts for some misc flags for invalidation
Add support for relaxed precision mode, not just forced half16
At least RADV (possibly others) assume input data is already in ushort16
if the input is declared as half.

If declared as float, it will autoconvert.
This is consistent with the behavior of uint, so it's possibly not a
driver bug but rather by spec.
Add RSC_SHADER_RELAXED_FLOAT
Disable relaxed mode in D3D11. It's buggy
Support D3D11 unit tests from within Linux/Wine
@darksylinc darksylinc added the enhancement New feature or request label Jan 27, 2022
@darksylinc darksylinc self-assigned this Jan 27, 2022
@darksylinc darksylinc merged commit 68d0db0 into master Jan 27, 2022
@darksylinc darksylinc deleted the half_fp16 branch January 27, 2022 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant