Skip to content

Commit

Permalink
pkg: add mach-dxcompiler
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
slimsag committed Feb 10, 2024
1 parent 374570b commit aa133b2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ unsafe = true
name = 'glfw'
url = '/pkg/mach-glfw'
weight = 3400
[[menu.pkg]]
identifier = 'pkg-bind-dxcompiler'
parent = 'pkg-bind'
name = 'dxcompiler'
url = '/pkg/mach-dxcompiler'
weight = 3400
[[menu.pkg]]
identifier = 'pkg-bind-model3d'
parent = 'pkg-bind'
Expand Down
61 changes: 61 additions & 0 deletions content/pkg/mach-dxcompiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: "mach dxcompiler"
description: "The DirectX shader compiler, built better."
draft: false
layout: "docs"
docs_type: "pkg"
rss_ignore: true
---

# mach-dxcompiler
<h4 style="margin-top: 0; margin-bottom: 1rem;">The DirectX shader compiler, built better.</h4>
<span>
<a href="https://github.com/hexops/mach-glfw">GitHub repository</a> | <a href="https://github.com/hexops/mach/issues?q=is%3Aissue+is%3Aopen+label%3Aglfw">Issue tracker</a>
</span>

See ['Building the DirectX shader compiler better than Microsoft?'](https://devlog.hexops.com/2024/building-the-directx-shader-compiler-better-than-microsoft/) for details/background information.

## Features

* Statically linked `dxcompiler` library and `dxc` executables.
* Zero dependency on proprietary `dxil.dll` code-signing blob (see: [Mach Siegbert Vogt DXCSA](https://github.com/hexops/DirectXShaderCompiler/blob/4190bb0c90d374c6b4d0b0f2c7b45b604eda24b6/tools/clang/tools/dxcompiler/MachSiegbertVogtDXCSA.cpp#L178))
* Built using `build.zig` instead of 10k+ LOC CMake build system.
* [Prebuilt binaries](https://github.com/hexops/mach-dxcompiler/releases) provided for many OS/arch.
* Binaries for macOS and aarch64 Linux (first ever in history), among others.
* [Simple C API](https://github.com/hexops/mach-dxcompiler/blob/main/src/mach_dxc.h) bundled into library as an alternative to the traditional COM API.

## Building from source

Specify the `-Dfrom_source` build option to produce a build from source (the default is to fetch a prebuilt binary produced from our CI pipelines):

```
zig build -Dfrom_source -Doptimize=ReleaseFast -Dtarget=aarch64-macos
zig build -Dfrom_source -Doptimize=ReleaseFast -Dtarget=x86_64-windows-gnu -Dcpu=x86_64_v2
zig build -Dfrom_source -Doptimize=ReleaseFast -Dtarget=x86_64-linux-gnu -Dcpu=x86_64_v2
```

## Getting started (Zig package)

First `zig init` to create a new Zig project. Then add the dependency (change `LATEST_COMMIT` to the actual latest commit hash from the repository):

```sh
zig fetch --save https://pkg.machengine.org/mach-dxcompiler/LATEST_COMMIT.tar.gz
```

Then in your `build.zig` file make the module importable in your code using e.g.:

```zig
const dxcompiler_dep = b.dependency("mach_dxcompiler", .{
.target = target,
.optimize = ReleaseFast, // use an optimized compiler
.from_source = false, // use a prebuilt binary
});
exe.root_module.addImport("mach-dxcompiler", dxcompiler_dep.module("mach-dxcompiler"));
```

For usage, see `src/main.zig` tests in the repository.

### Ran into trouble?

Feel free to join the [Mach Discord community](../../discord) for help.

0 comments on commit aa133b2

Please sign in to comment.