2
0

DxcOnUnix.rst 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ======================================
  2. DirectXShaderCompiler on Linux & macOS
  3. ======================================
  4. .. contents::
  5. :local:
  6. :depth: 3
  7. Introduction
  8. ============
  9. DirectXShaderCompiler (DXC) is based on LLVM/Clang, which is originally
  10. cross-platform. However, to support HLSL, certain Windows specific techniques
  11. (like COM, SAL, etc.) are introduced to solve technical issues on the Windows
  12. platform, which also makes DXC not compilable/runnable on non-Windows platforms.
  13. Upon `several <https://github.com/Microsoft/DirectXShaderCompiler/issues/1082>`_
  14. `requests <https://github.com/Microsoft/DirectXShaderCompiler/issues/1236>`_
  15. from the community, we have started the effort to enable compilation and running
  16. of DXC on non-Windows platforms (Linux and macOS).
  17. Current Status
  18. ==============
  19. Up and Running
  20. --------------
  21. We have currently reached the point where we can successfully build and run DXC
  22. on Linux and macOS. Code generation works for both DXIL and SPIR-V, and we are
  23. also able to run the whole SPIR-V and a large portion of DXIL CodeGen test suite
  24. on these platforms.
  25. *Note: This work is currently in experimental phase. How we implement certain
  26. things for Unix platforms may change without considering backward portability.*
  27. Known Limitations
  28. -----------------
  29. The following targets are currently disabled for non-Windows platforms and this
  30. is an area where further contributions can be made:
  31. * d3dcomp
  32. * dxa
  33. * dxopt
  34. * dxl
  35. * dxr
  36. * dxv
  37. * dxlib-sample
  38. Moreover, since the HLSL CodeGen tests were originally written with Windows in
  39. mind, they require the Windows-specific `TAEF Framework <https://docs.microsoft.com/en-us/windows-hardware/drivers/taef/>`_
  40. to run. Besides, some tests also require DirectX to execute. Therefore we are
  41. not able to compile/run all these tests on non-Windows platforms. Note that
  42. it is only the testing infrastructure that has this limitation, and DXIL CodeGen
  43. works as expected by running the DXC executable.
  44. Known Issues
  45. ------------
  46. - Running the SPIR-V CodeGen tests results in opening a large number of file
  47. descriptors, and if the OS limitation on the number of FDs allowed to be opened
  48. by a process is low, it will cause test failures. We have not seen this as an
  49. issue on Windows and Linux. On macOS we currently increase the allowed limit to
  50. get around the problem for the time being.
  51. - The version number of the shared library is currently stuck at 3.7. We need to
  52. fix this once a certain versioning scheme is in place.
  53. Building and Using
  54. ==================
  55. Build Requirements
  56. ------------------
  57. Please make sure you have the following resources before building:
  58. - `Git <https://git-scm.com/downloads>`_
  59. - `Python <https://www.python.org/downloads/>`_. Version 3.x is required.
  60. - `Ninja <https://github.com/ninja-build/ninja/releases>`_ (*Optional* CMake generator)
  61. - Either of gcc/g++ or clang/clang++ compilers. Minimum supported version:
  62. - `GCC <https://gcc.gnu.org/releases.html>`_ version 5.5 or higher.
  63. - `Clang <http://releases.llvm.org/>`_ version 3.8 or higher.
  64. Building DXC
  65. ------------
  66. You can follow these steps to build DXC on Linux/macOS:
  67. .. code:: sh
  68. cd <dxc-build-dir>
  69. cmake <dxc-src-dir> -GNinja -DCMAKE_BUILD_TYPE=Release $(cat <dxc-src-dir>/utils/cmake-predefined-config-params)
  70. ninja
  71. Note that ``cmake-predefined-config-params`` file contains several cmake
  72. configurations that are needed for successful compilation. You can further
  73. customize your build by adding configurations at the end of the cmake command
  74. above.
  75. For instance, you can use
  76. ``-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++``
  77. or
  78. ``-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++``
  79. to choose your desired C/C++ compiler.
  80. You should now have the dxc executable located at ``<dxc-build-dir>/bin/dxc``.
  81. And you should be able to successfully run commands as you would on Windows, e.g:
  82. .. code:: sh
  83. ./bin/dxc -help
  84. ./bin/dxc -T <target> -E <entry-point-name> <input-hlsl-file>
  85. Note that you cannot use slashes (``/``) for specifying command line options as
  86. you would on Windows. You should use dashes as per usual Unix style.
  87. Building and Running Tests
  88. --------------------------
  89. The tests are run using the GoogleTest framework.
  90. You can follow these steps to build and run the tests:
  91. .. code:: sh
  92. cd <dxc-build-dir>
  93. # Use SPIRV_BUILD_TESTS flag to enable building these tests.
  94. cmake <dxc-src-dir> \
  95. $(cat <dxc-src-dir>/utils/cmake-predefined-config-params) \
  96. -DCMAKE_BUILD_TYPE=Release -DSPIRV_BUILD_TESTS=ON \
  97. -GNinja
  98. # Build all targets. Includes 'dxc' and tests.
  99. ninja
  100. # Run all tests
  101. ctest
  102. As described in the `Known Issues`_ section above, you currently need to
  103. increase the maximum per-process open files on macOS using
  104. ``ulimit -Sn 1024`` before running the tests on that platform.
  105. TODO: Add more information about Linux implementation details.