-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow customization of DXC executable
Resolves o3de#17148 (DXC should be customizable via Settings Registry) Which enables working around this bug: o3de/o3de-extras#625 Developers can now pick a custom version of the DXC executable via the Settings Registry Key: `/O3DE/Atom/DxcOverridePath`. Also, introduced the macro `PRE_HLSL_2021`, along with an explanation in the following file: /o3de/Gems/Atom/Feature/Common/Assets/ShaderLib/PRE_HLSL_2021.md TL;DR: If a game project uses a DXC executable that doesn't conform to the HLSL 2021 standard, then they should globally define the macro PRE_HLSL_2021 when compiling shaders. The O3DE default version of DXC is 1.7.2308 which conforms to HLSL 2021. The problem is that some shaders get compiled to versions of SPIRV not supported by Adreno GPU drivers. This commit gives the option to use a different DXC and avoid this issue. Removed redundant LinearToSRGB conversion functions. Signed-off-by: galibzon <[email protected]>
- Loading branch information
Showing
13 changed files
with
185 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Gems/Atom/Feature/Common/Assets/ShaderLib/PRE_HLSL_2021.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# About the macro PRE_HLSL_2021 | ||
|
||
The macro PRE_HLSL_2021 was introduced since this bug: https://github.com/o3de/o3de-extras/issues/625. | ||
|
||
The workaround to the bug mentioned above was to use an older version of DXC 1.6.2112, instead of DXC 1.7.2308. DXC 1.7.2308 conforms to HLSL 2021 which doesn't support the ternary conditional operator (`(cond) ? true_statement : false_statement`) for vectors. HLSL 2021 only supports ternary conditional operator for scalars. Starting HLSL 2021, to achieve an equivalent behavior for ternary conditional operator for vectors, the `select()` intrinsic was introduced. See more details here: | ||
https://devblogs.microsoft.com/directx/announcing-hlsl-2021/ | ||
|
||
This is why you'll find now code like this in some *.azsli or *.azsl files: | ||
```hlsl | ||
#ifdef PRE_HLSL_2021 | ||
return (color.xyz < 0.04045) ? color.xyz / 12.92h : pow((color.xyz + real3(0.055, 0.055, 0.055)) / real3(1.055, 1.055, 1.055), 2.4); | ||
#else | ||
return select((color.xyz < 0.04045), color.xyz / 12.92h, pow((color.xyz + real3(0.055, 0.055, 0.055)) / real3(1.055, 1.055, 1.055), 2.4)); | ||
#endif | ||
``` | ||
|
||
By default the macro `PRE_HLSL_2021` is not defined, and the shaders will use the `and`, `or` and `select` intrinsics. | ||
|
||
## When should the developer define the PRE_HLSL_2021 macro? | ||
Defining the PRE_HLSL_2021 is required if the developer customizes the DXC executable to version pre-HLSL 2021 like DXC 1.6.2112. | ||
|
||
The DXC executable can be customized via the Settings Registry Key: | ||
`/O3DE/Atom/DxcOverridePath`. | ||
Here is a customization example in a *.setreg file: | ||
```json | ||
{ | ||
"O3DE": { | ||
"Atom": { | ||
"DxcOverridePath": "C:\\Users\\galib\\.o3de\\3rdParty\\packages\\DirectXShaderCompilerDxc-1.6.2112-o3de-rev1-windows\\DirectXShaderCompilerDxc\\bin\\Release\\dxc.exe" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## How to globally define the PRE_HLSL_2021 macro when compiling all shaders? | ||
Customization of command line arguments for shader compilation tools is described here: | ||
https://github.com/o3de/o3de/wiki/%5BAtom%5D-Developer-Guide:-Shader-Build-Arguments-Customization | ||
|
||
In particular if you don't want to mess with engine files, in your game project: | ||
1- Define an alternate location for `shader_build_options.json` using the registry key: `/O3DE/Atom/Shaders/Build/ConfigPath`. | ||
2- Your new `shader_build_options.json` should be a copy of engine original located at `C:\GIT\o3de\Gems\Atom\Asset\Shader\Config\shader_build_options.json` with the addition of: | ||
```json | ||
"Definitions": [ "PRE_HLSL_2021" ], // Needed when using DXC 1.6.2112 | ||
``` | ||
Complete example of customized shader_build_options.json: | ||
```json | ||
{ | ||
"Definitions": [ "PRE_HLSL_2021" ], // Needed when using DXC 1.6.2112 | ||
"AddBuildArguments": { | ||
"debug": false, | ||
"preprocessor": ["-C" // Preserve comments | ||
, "-+" // C++ mode | ||
], | ||
"azslc": ["--full" // Always generate the *.json files with SRG and reflection info. | ||
, "--Zpr" // Row major matrices. | ||
, "--W1" // Warning Level 1 | ||
, "--strip-unused-srgs" // Remove unreferenced SRGs. | ||
, "--root-const=128" | ||
], | ||
"dxc": ["-Zpr" // Row major matrices. | ||
], | ||
// The following apply for all Metal based platforms. | ||
"spirv-cross": ["--msl" | ||
, "--msl-version" | ||
, "20100" | ||
, "--msl-invariant-float-math" | ||
, "--msl-argument-buffers" | ||
, "--msl-decoration-binding" | ||
, "--msl-texture-buffer-native" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
Finally, if not done already you'd have to restart the AssetProcessor so it picks the changes from the Settings Registry. |
Oops, something went wrong.