This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Перейти к файлу
Zhengxing Li b052e1b244 More aggressive reassociations
Although DXC applied the upstream change, Reassociate: add global reassociation algorithm (llvm/llvm-project@b8a330c) in this PR (https://github.com/microsoft/DirectXShaderCompiler/pull/6598), it still might overlook some obvious common factors.

One case has been observed is:
  %Float4_0   = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %1, i32 1)
  %Float4_0.w = extractvalue %dx.types.CBufRet.f32 %Float4_0, 3
  %Float2_0   = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %1, i32 0)
  %Float2_0.y = extractvalue %dx.types.CBufRet.f32 %Float2_0, 1

  /* %Float4_1 is redundant with %Float4_0 since they invokes cbufferLoadLegacy with same parameters */
  %Float4_1   = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %1, i32 1)

  /* %Float4_1.w is redundant with %Float4_0.w */
  %Float4_1.w = extractvalue %dx.types.CBufRet.f32 %Float4_1, 3

  /* %Float2_1 is redundant with %Float2_0 since they invokes cbufferLoadLegacy with same parameters */
  %Float2_1   = call %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %1, i32 0)

  /* %Float2_1.y is redundant with %Float2_0.y */
  %Float2_1.y = extractvalue %dx.types.CBufRet.f32 %Float2_1, 1

  ....
  %11 = fmul fast float %Float4_0.w, %10
  %12 = fmul fast float %11, %Float2_0.y
  ....
  %14 = fmul fast float %Float4_1.w, %13
  %15 = fmul fast float %14, %Float2_1.y

(%Float4_0.w * %Float2_0.y) equals to (%Float4_1.w * %Float2_1.y), they should be reassociated to a common factor

The upstream change can't identify this common factor because DXC doesn't know (%Float4_0.w, %Float4_1.w) and (%Float2_0.y, %Float2_1.y) are redundant when running Reassociate pass. Those redundancies will be eliminated in GVN pass.

For DXC can identify more common factors, this PR will aggressively run Reassociate pass again after GVN pass and then run GVN pass again to remove the redundancies generared in this run of Reassociate pass.

Changing the order of floating point operations causes the precision issue. In case some shaders get unexpected results due to this PR, use "-opt-disable aggressive-reassociation" to disable this PR and roll back.

This is part 3 of the fix for #6593.
2024-05-21 13:47:45 -07:00
.github Add CODEOWNERS to main (#6520) 2024-04-10 18:29:05 -05:00
autoconf Added e2k support (MCST Elbrus 2000) (#5222) 2023-09-11 14:09:48 -07:00
azure-pipelines Remove DXC.Release pipeline (#5073) 2023-03-01 17:56:34 -08:00
cmake azure-pipelines: Fix the fact that neither asan+ubsan were not actually enabled (#6428) 2024-03-22 17:49:37 -04:00
docs [SPIR-V] Implement WaveMutliPrefix* (#6608) 2024-05-17 09:59:35 -04:00
examples Clean up mistakes made when fixing copyright banners. 2017-01-25 14:36:50 -08:00
external Bump submodules (#6577) 2024-05-02 17:03:11 +00:00
gcp-pipelines Enable lit by default. (#5133) 2023-06-05 10:35:24 -07:00
include Add a flag for the upstream global reassociation algorithm change (#6625) 2024-05-21 13:45:38 -07:00
lib More aggressive reassociations 2024-05-21 13:47:45 -07:00
projects Update locale setting logic to support UTF-8 only for Apple and Linux distros (#6488) 2024-04-10 10:04:32 -07:00
resources Generate new version for each DX Compiler build (#2200) 2019-06-28 15:16:34 -07:00
test Reassociate: add global reassociation algorithm (#6598) 2024-05-21 11:55:40 -07:00
tools More aggressive reassociations 2024-05-21 13:47:45 -07:00
unittests Fix false positive assert in SuccIterator::operator+= (#6623) 2024-05-16 21:10:34 -04:00
utils Add a flag for the upstream global reassociation algorithm change (#6625) 2024-05-21 13:45:38 -07:00
.clang-format first commit 2016-12-28 11:52:27 -08:00
.clang-tidy first commit 2016-12-28 11:52:27 -08:00
.gitattributes Adding line ending settings to .gitattributes (#4026) 2021-10-20 20:58:43 -05:00
.gitignore Update build to Visual Studio 2022 (new default); remove VS 2017 support (#4726) 2022-10-17 18:49:35 -07:00
.gitmodules [lit][SPIRV] convert runCodeTest to lit and remove dependence on effcee (#6077) 2023-12-14 06:50:32 -08:00
CMakeLists.txt CMake dxc as subproject fixes (#6050) 2023-11-22 14:33:09 -05:00
CMakeSettings.json [BUILD] add clang-cl to CMakeSettings (#5596) 2023-08-28 20:13:06 +00:00
CONTRIBUTING.md [Docs] Update contributing doc for clang-format (#5873) 2023-10-16 22:23:53 +00:00
LICENSE.TXT Inline sub-licenses into root license file (#5569) 2023-08-21 10:05:09 -04:00
LLVMBuild.txt Revert license text in banner comments to original llvm verbage (#33) 2017-01-24 17:54:00 -08:00
README.md [Docs] Update Readme and build instruction docs (#6185) 2024-03-05 15:50:36 -06:00
SECURITY.md Adding Microsoft SECURITY.MD (#4464) 2022-05-19 11:49:07 -07:00
ThirdPartyNotices.txt Add heading text for ThirdPartyNotices.txt 2017-02-24 16:30:31 -08:00
azure-pipelines.yml azure-pipelines: Fix the fact that neither asan+ubsan were not actually enabled (#6428) 2024-03-22 17:49:37 -04:00

README.md

DirectX Shader Compiler

The DirectX Shader Compiler project includes a compiler and related tools used to compile High-Level Shader Language (HLSL) programs into DirectX Intermediate Language (DXIL) representation. Applications that make use of DirectX for graphics, games, and computation can use it to generate shader programs.

For more information, see the Wiki.

Visit the DirectX Landing Page for more resources for DirectX developers.

Features and Goals

The starting point of the project is a fork of the LLVM and Clang projects, modified to accept HLSL and emit a validated container that can be consumed by GPU drivers.

At the moment, the DirectX HLSL Compiler provides the following components:

  • dxc.exe, a command-line tool that can compile HLSL programs for shader model 6.0 or higher

  • dxcompiler.dll, a DLL providing a componentized compiler, assembler, disassembler, and validator

  • dxilconv.dll, a DLL providing a converter from DXBC (older shader bytecode format)

  • various other tools based on the above components

The Microsoft Windows SDK releases include a supported version of the compiler and validator.

The goal of the project is to allow the broader community of shader developers to contribute to the language and representation of shader programs, maintaining the principles of compatibility and supportability for the platform. It's currently in active development across two axes: language evolution (with no impact to DXIL representation), and surfacing hardware capabilities (with impact to DXIL, and thus requiring coordination with GPU implementations).

Pre-built Releases

Development kits containing only the dxc.exe driver app, the dxcompiler.dll, and the dxil.dll signing binary are available here, or in the releases tab.

SPIR-V CodeGen

As an example of community contribution, this project can also target the SPIR-V intermediate representation. Please see the doc for how HLSL features are mapped to SPIR-V, and the wiki page for how to build, use, and contribute to the SPIR-V CodeGen.

Building Sources

See the full documentation for Building and testing DXC for detailed instructions.

Running Shaders

To run shaders compiled as DXIL, you will need support from the operating system as well as from the driver for your graphics adapter. Windows 10 Creators Update is the first version to support DXIL shaders. See the Wiki for information on using experimental support or the software adapter.

Hardware Support

Hardware GPU support for DXIL is provided by the following vendors:

NVIDIA

NVIDIA's r396 drivers (r397.64 and later) provide release mode support for DXIL 1.1 and Shader Model 6.1 on Win10 1709 and later, and experimental mode support for DXIL 1.2 and Shader Model 6.2 on Win10 1803 and later. These drivers also support DXR in experimental mode.

Drivers can be downloaded from geforce.com.

AMD

AMDs driver (Radeon Software Adrenalin Edition 18.4.1 or later) provides release mode support for DXIL 1.1 and Shader Model 6.1. Drivers can be downloaded from AMD's download site.

Intel

Intel's 15.60 drivers (15.60.0.4849 and later) support release mode for DXIL 1.0 and Shader Model 6.0 as well as release mode for DXIL 1.1 and Shader Model 6.1 (View Instancing support only).

Drivers can be downloaded from the following link Intel Graphics Drivers

Direct access to 15.60 driver (latest as of of this update) is provided below:

Installer

Release Notes related to DXIL

Making Changes

To make contributions, see the CONTRIBUTING.md file in this project.

Documentation

You can find documentation for this project in the docs directory. These contain the original LLVM documentation files, as well as two new files worth nothing:

License

DirectX Shader Compiler is distributed under the terms of the University of Illinois Open Source License.

See LICENSE.txt and ThirdPartyNotices.txt for details.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.