Usage of DirectX Shader Compiler

# はじめに

土日を費やして, ひたすらしこしこテーブルにした記録.

# Build

- Repository
    - [GitHub](https://github.com/Microsoft/DirectXShaderCompiler)
- Prerequisites
    - ATL
    - .Net Framework 4.5

# Options

## Common Options

| Common Options | |
|:--|:--|
| -help | Display available options |
| -nologo | Suppress copyright message |
| -Qunused-arguments | Don't emit warning for unused driver arguments |

## Compilation Options

| Compilation Options | |
|:--|:--|
| -all-resources-bound | Enables agressive flattening|
| -auto-binding-space &lt;value&gt; | Set auto binding space - enables auto resource binding in libraries |
| -Cc | Output color coded assembly listings |
| -default-linkage &lt;value&gt; | Set default linkage for non-shader functions when compiling or linking to a library target (internal, external) |
| -denorm &lt;value&gt; | select denormal value options (any, preserve, ftz). any is the default. |
| -D &lt;value&gt; | Define macro |
| -enable-16bit-types | Enable 16bit types and disable min precision types. Available in HLSL 2018 and shader model 6.2 |
| -encoding &lt;value&gt; | Set default encoding for text outputs (utf8|utf16) default=utf8 |
| -export-shaders-only | Only export shaders when compiling a library |
| -exports &lt;value&gt; | Specify exports when compiling a library: export1[[,export1_clone,...]=internal_name][;...] |
| -E &lt;value&gt; | Entry point name |
| -Fc &lt;file&gt; | Output assembly code listing file |
| -fdiagnostics-show-option | Print option name with mappable diagnostics |
| -Fd &lt;file&gt; | Write debug information to the given file, or automatically named file in directory when ending in '\' |
| -Fe &lt;file&gt; | Output warnings and errors to the given file |
| -Fh &lt;file&gt; | Output header file containing object code |
| -flegacy-macro-expansion | Expand the operands before performing token-pasting operation (fxc behavior) |
| -flegacy-resource-reservation | Reserve unused explicit register assignments for compatibility with shader model 5.0 and below |
| -fno-diagnostics-show-option | Do not print option name with mappable diagnostics |
| -force-rootsig-ver &lt;profile&gt; | force root signature version (rootsig_1_1 if omitted) |
| -Fo &lt;file&gt; | Output object file |
| -Fre &lt;file&gt; | Output reflection to the given file |
| -Frs &lt;file&gt; | Output root signature to the given file |
| -Fsh &lt;file&gt; | Output shader hash to the given file |
| -Gec | Enable backward compatibility mode |
| -Ges | Enable strict mode |
| -Gfa | Avoid flow control constructs |
| -Gfp | Prefer flow control constructs |
| -Gis | Force IEEE strictness |
| -HV &lt;value&gt; | HLSL version (2016, 2017, 2018). Default is 2018 |
| -H | Show header includes and nesting depth |
| -ignore-line-directives | Ignore line directives |
| -I &lt;value&gt; | Add directory to include search path |
| -Lx | Output hexadecimal literals
| -Ni | Output instruction numbers in assembly listings
| -no-legacy-cbuf-layout | Do not use legacy cbuffer load
| -no-warnings | Suppress warnings |
| -No | Output instruction byte offsets in assembly listings |
| -Odump | Print the optimizer commands. |
| -Od | Disable optimizations |
| -pack-optimized | Optimize signature packing assuming identical signature provided for each connecting stage |
| -pack-prefix-stable | (default) Pack signatures preserving prefix-stable property - appended elements will not disturb placement of prior elements |
| -recompile | recompile from DXIL container with Debug Info or Debug Info bitcode file |
| -res-may-alias | Assume that UAVs/SRVs may alias |
| -rootsig-define &lt;value&gt; | Read root signature from a #define |
| -T &lt;profile&gt; | Set target profile.  |
| | ps_6_0, ps_6_1, ps_6_2, ps_6_3, ps_6_4, ps_6_5, |
| | vs_6_0, vs_6_1, vs_6_2, vs_6_3, vs_6_4, vs_6_5, |
| | gs_6_0, gs_6_1, gs_6_2, gs_6_3, gs_6_4, gs_6_5, |
| | hs_6_0, hs_6_1, hs_6_2, hs_6_3, hs_6_4, hs_6_5, |
| | ds_6_0, ds_6_1, ds_6_2, ds_6_3, ds_6_4, ds_6_5, |
| | cs_6_0, cs_6_1, cs_6_2, cs_6_3, cs_6_4, cs_6_5, |
| | lib_6_1, lib_6_2, lib_6_3, lib_6_4, lib_6_5, |
| | ms_6_5, |
| | as_6_5, |
| -Vd | Disable validation |
| -Vi | Display details about the include process. |
| -Vn &lt;name&gt; | Use &lt;name&gt; as variable name in header file |
| -WX | Treat warnings as errors |
| -Zi | Enable debug information |
| -Zpc | Pack matrices in column-major order |
| -Zpr | Pack matrices in row-major order |
| -Zsb | Compute Shader Hash considering only output binary |
| -Zss | Compute Shader Hash considering source information |

## Optimization Options

| Optimization Options | |
|:--|:--|
| -O0 | Optimization Level 0 |
| -O1 | Optimization Level 1 |
| -O2 | Optimization Level 2 |
| -O3 | Optimization Level 3 (Default) |

## Rewriter Options

| Rewriter Options | |
|:--|:--|
| -extract-entry-uniforms | Move uniform parameters from entry point to global scope |
| -global-extern-by-default | Set extern on non-static globals |
| -keep-user-macro | Write out user defines after rewritten HLSL
| -line-directive | Add line directive |
| -remove-unused-functions | Remove unused functions and types |
| -remove-unused-globals | Remove unused static globals and functions |
| -skip-fn-body | Translate function definitions to declarations |
| -skip-static | Remove static functions and globals when used with -skip-fn-body |
| -unchanged | Rewrite HLSL, without changes. |

## SPIR-V CodeGen Options

| SPIR-V CodeGen Options| |
|:--|:--|
| -fspv-debug=&lt;value&gt; | Specify whitelist of debug info category (file -&gt; source -&gt; line, tool) |
| -fspv-extension=&lt;value&gt; | Specify SPIR-V extension permitted to use |
| -fspv-flatten-resource-arrays | Flatten arrays of resources so each array element takes one binding number |
| -fspv-reflect | Emit additional SPIR-V instructions to aid reflection |
| -fspv-target-env=&lt;value&gt; | Specify the target environment: vulkan1.0 (default) or vulkan1.1 |
| -fvk-auto-shift-bindings | Apply fvk-&#42;-shift to resources without an explicit register assignment. |
| -fvk-b-shift &lt;shift&gt; &lt;space&gt; | Specify Vulkan binding number shift for b-type register |
| -fvk-bind-globals &lt;binding&gt; &lt;set&gt; | Specify Vulkan binding number and set number for the $Globals cbuffer |
| -fvk-bind-register &lt;type-number&gt; &lt;space&gt; &lt;binding&gt; &lt;set&gt; | Specify Vulkan descriptor set and binding for a specific register |
| -fvk-invert-y | Negate SV_Position.y before writing to stage output in VS/DS/GS to accommodate Vulkan's coordinate system |
| -fvk-s-shift &lt;shift&gt; &lt;space&gt; | Specify Vulkan binding number shift for s-type register |
| -fvk-t-shift &lt;shift&gt; &lt;space&gt; | Specify Vulkan binding number shift for t-type register |
| -fvk-u-shift &lt;shift&gt; &lt;space&gt; | Specify Vulkan binding number shift for u-type register |
| -fvk-use-dx-layout | Use DirectX memory layout for Vulkan resources |
| -fvk-use-dx-position-w | Reciprocate SV_Position.w after reading from stage input in PS to accommodate the difference between Vulkan and DirectX |
| -fvk-use-gl-layout | Use strict OpenGL std140/std430 memory layout for Vulkan resources |
| -fvk-use-scalar-layout | Use scalar memory layout for Vulkan resources
| -Oconfig=&lt;value&gt; | Specify a comma-separated list of SPIRV-Tools passes to customize optimization configuration (see http://khr.io/hlsl2spirv#optimization) |
| -spirv | Generate SPIR-V code |

## Utility Options

| Utility Options | |
|:--|:--|
| -dumpbin | Load a binary file rather than compiling |
| -extractrootsignature | Extract root signature from shader bytecode (must be used with /Fo &lt;file&gt;) |
| -getprivate &lt;file&gt; | Save private data from shader blob |
| -P &lt;value&gt; | Preprocess to file (must be used alone)
| -Qembed_debug | Embed PDB in shader container (must be used with /Zi)
| -Qstrip_debug | Strip debug information from 4_0+ shader bytecode  (must be used with /Fo &lt;file&gt;)
| -Qstrip_priv | Strip private data from shader bytecode  (must be used with /Fo &lt;file&gt;)
| -Qstrip_reflect | Strip reflection data from shader bytecode  (must be used with /Fo &lt;file&gt;)
| -Qstrip_rootsignature | Strip root signature data from shader bytecode  (must be used with /Fo &lt;file&gt;) |
| -setprivate &lt;file&gt; | Private data to add to compiled shader blob |
| -setrootsignature &lt;file&gt; | Attach root signature to shader bytecode |
| -verifyrootsignature &lt;file&gt; | Verify shader bytecode with root signature |

## Warning Options

| Warning Options | |
|:--|:--|
| -W[no-]&lt;warning&gt; | Enable/Disable the specified warning |