-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new build options and shader file inclusion overrides. #3
Conversation
Added ability to build shared library
Refactored build.zig to ensure format matches more similarly to the original build.zig.
Removed a python build file created by mistake.
@sinnwrig can you rebase onto latest |
.gitignore
Outdated
@@ -18,6 +18,7 @@ zig-out/ | |||
/docgen_tmp/ | |||
|
|||
libs/DirectXShaderCompiler | |||
generated-include/spirv-tools/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the reason for the addition of this? do we end up needing generated spirv-tools stuff?
Can we include it from https://github.com/hexops/spirv-tools instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't know that fork existed! Using that would probably work better than jamming together the SPIR-V headers with everything else. That folder just held the build-generated headers from SPIRV-Tools, so I figured it would be redundant to include them in the repo.
build.zig
Outdated
@@ -138,6 +153,82 @@ pub fn build(b: *Build) !void { | |||
lib_support_c_sources ++ | |||
lib_dxilcompression_c_sources; | |||
|
|||
// Build and link SPIRV-Tools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely think we should be using https://github.com/hexops/spirv-tools here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll definitely be using it instead.
try std.fs.cwd().copyFile(lib_path, std.fs.cwd(), "atls.lib", .{}); | ||
try std.fs.cwd().copyFile(pdb_path, std.fs.cwd(), pdb_name, .{}); | ||
// This is probably a bug in the Zig linker. | ||
if (!skip_executables) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you build spirv support for dxc.exe? or are you not testing that?
curious how I'll be able to test this works if dxc.exe doesn't work with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the option to skip executables since I wanted to clean up the folder output as I was directly copying zig-out in another project. dxc.exe works fine with it.
build.zig
Outdated
|
||
fn ensurePython(allocator: std.mem.Allocator) void | ||
{ | ||
if (!ensureCommandExists(allocator, "python3", "--version")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't have a dependency on python here
This is a bit unfortunate; I am guessing we would need a fork of https://github.com/KhronosGroup/SPIRV-Headers packaged for build.zig with the headers pregenerated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I'm pretty sure hexops/SPIRV-Tools makes the stuff here a bit redundant, and I'll just use that repo instead.
build.zig
Outdated
buildSPIRVVersion(allocator); | ||
} | ||
|
||
const BuildSPIRVGrammarStep = struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a goal to move away from having any custom build steps like this; so this will be a no-go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, this was only meant to generate spirv-headers, so if those are pregenerated it should be unneccesary.
getting this merged upstream here might be a fair bit of work - we can chat about it though |
Looking at the reviews, a lot of problems should be resolved if an external repo of SPIRV-Tools built with zig is used instead. |
spirv compilation now depends on |
why is this not merged yet |
Closing in favor of #7 which I promise I will actually merge soon. |
Description
Multiple new options have been added to the build system in order to build mach-dxcompiler for more various use cases, and an addition to the API has been made in order to override default DXC file inclusion behavior.
Additional Build Features
Four new build options have been added to build.zig:
-Dshared
Build machdxcompiler as a shared library alongside the static library.-Dspirv
Build SPIR-V codegen support for machdxcompiler.-Dskip_executables
Skip building machdxcompiler executable (Implicitly skips tests)-Dskip_tests
Skip building machdxcompiler-tests executableAPI Changes
machDxcCompile
function signature has been changed, accepting aMachDxcCompileOptions
struct.MachDxcCompileOptions
struct typedef has been added, containing the following fields:char const*
code` (UTF-8)size_t code_len
char const* const* args
(UTF-8)size_t args_len
MachDxcIncludeCallbacks* include_callbacks
(null falls back to default behavior)The ability to override the default DXC file includer has been added to the C API.
MachDxcIncludeCallbacks
struct typedef has been added, containing the following fields:MachDxcIncludeFunc* include_func
MachDxcFreeIncludeFunc* free_func
void* context
MachDxcIncludeResult
struct typedef has been added, containing the following fields:const char* header_data
(UTF-8)size_t header_length
MachDxcIncludeFunc
function type definition has been added.void*
as context.const char*
as header name in UTF-8.MachDxcIncludeResult*
.MachDxcFreeIncludeFunc
function type definition has been added.void*
as context.MachDxcIncludeResult*
to free.int
exit code.Implementation details
Shared library building links the static library when compiling a minimal .cpp file.
Executable and test generation are now behind compilation flags.
SPIR-V codegen support builds tools/clang/lib/SPIRV sources in addition to core DXC sources, and links to an external dependency on
hexops/spirv-tools
.DXC inclusion behavior has been routed through the provided function pointers using a minimal class inheriting from IDxcIncludeHandler.
Known Issues