-
Notifications
You must be signed in to change notification settings - Fork 250
Replace usage of spirv-* binaries with spirv-tools rust crate #117
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
Conversation
Personally I would prefer if we could avoid submodules, they are a pain to maintain, and I would even say they're anti-pattern. I think it would be a lot better if we could use Subtree docs |
oh no, personally I hate |
+1 to submodules. // The spirv tools use generated code, for now we just replicate the minimum
// generation we need here by calling the *shudders* python script(s) we need
// to in a simple script and commit them to source control, as they only need
// to be regenerated when spirv-headers is updated This deserves a shout-out here (or anywhere) since this adds a new manual step. Is there any way we can keep this SPIRV-Headers and the one used by rspirv in sync easily other then manually checking hashes? |
@khyperia Can I ask the motivation behind that? In my experience submodules are hard to use right, and more work to maintain. Every contributor has to keep their submodules in their local version in sync individually, and you can end up in a state where new changes in the submodule break your code, and vice versa but you don't find out until after you have landed changes. With
|
Yah I will add docs for this. To be clear, all the generated files are in checked in in spirv-tools-sys/generated so they aren't built every time, but yes, if spirv-headers is changed you will need python etc.
Good question, we can at minimum assert in the build script if their commits differ, or maybe, just the files that we read are the same but...yah. |
So good news, spirv-opt and spirv-val are now compiled as crates and can be run without installing spirv-tools, yay! So not sure how we want to handle this.
|
Would prefer to stay with GitHub Actions for now at least, it is more accessible for users and has a wider ecosystem and easier if anyone forks or tries out things and this is a very open project so that is a priority. Still need decent CI build times though (#107) as we are working on a lot of different areas through small PRs here. Think it would be fine to have CI just download the executables, esp. if it saves massive amount of time. Users likely will want to be able to run locally with pre-built or their own tools as well, but good to have a default that builds everything (if it doesn't take forever) |
Long term wanted future: Rust native versions of esp. the parts of spirv-tools we use. Not sure how realistic |
So I think maybe we can make it slightly less terrible but having a feature flag on spirv-tools for "use executables" vs "use compiled sys crate" so the interface would be the same, just internally it would use one or the other, so would greatly lessen the pain of maintenance, at least for a while.
Given the commit frequency (though most of the recent ones seem focused on spirv-fuzz which I don't know if we have any interest in) that might be tough, not necessarily to port what is currently there, but to keep up with features, new versions etc. |
Agreed, that would likely be a decent compromise And yeah also think it would hard to keep up with spirv-tools in general for a Rust port. But if we primarily use it to optimize the spirv that is a much smaller scope. fuzzing and validation are more dev features that are needed now but shouldn't be needed by other devs that are using Rust GPU once it is more mature. I think. |
Yah, I guess the good thing is that right now the way the spirv-tools optimizer is structured in passes, it might not be too bad to port passes as needed, and since we control the build system, pick the rust pass or the c++ pass, though I haven't looked a ton at how much data/state is shared between passes (hopefully little). |
Some context, we decided in #32 to always run spirv-val on user's machines, and have no plans to stop doing so for a long time. |
Ah good to know, and makes sense, esp at this early stage. Would ultimately want users to be able to build shaders without any external C/C++ dependencies or system executables, but that can be a larger target as part of long term design of #48 and potentially other separate issues |
0784c92
to
2a7fc92
Compare
Ok, I've replaced all of the usages of spirv-* binaries, now I just need to add them back behind a feature toggle for the spirv-tools crate so that we can just use those in CI, but make them an optional requirement for users. |
Another potential footgun with submodules that doesn't matter much now, is that having different submodules checked out doesn't count as "dirty" to git/cargo so you could publish accidentally publish the wrong commit. Here's steps how to replicate an example of how to that.
|
f83ea15
to
9d18197
Compare
28f0bcc
to
470ae9a
Compare
I've updated the top of the PR with the one remaining TODO of fixing up documentation, but everything else should be mostly done. |
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.
Holy heck this is a lot, thank you so much for doing this! This is pseudo-approval, but I don't want mergify to shove this in before you have the chance to check optional feedback.
* Splits steps to clearly show how long each part of a longer (eg test) step actually takes * Label all steps
4f193f8
to
fcf5bd2
Compare
Oh, one thing I forgot to ask, should this PR making running the |
In the long-term, I think so, however, it gets a little in-depth - e.g. we want rustc_codegen_spriv tests (currently located at |
Very true! Ok, should I just update the docs in this PR and we'll call it done and merge it in? |
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.
yeah!
9097006
to
52d1f7f
Compare
Encountered an issue with Windows that I had missed because the tests weren't running where either the use of stdin for input or stdout for output of the program caused problems for the spirv-tools, so until I look into that deeper I just returned to using files for the input and output just so I can get this PR landed. |
Making this a draft so that others can leave comments, I think I need to add a wrapper around the Validator as otherwise we will still require having spirv-tools installed which is kind of lame when we are already paying the compile time cost for building spirv-tools
Additions
spirv-tools-sys
which buildsspirv-tools
, including a small generator script that generates some includes based on spirv-headersspirv-tools-sys/src/c/opt.cpp
which is just a thin (and incomplete) C wrapper around Optimizer because C++spirv-tools
crate which provides a slighly nicer API on top ofspirv-tools-sys
Changes
spirv-opt
binary in link.rs withspirv_tools::opt::Optimizer
spirv-val
for validating resulting binaries in link.rs withspirv_tools::val::Validator
spirv-as
in the linker tests withspirv_tools::as::Assembler
use-installed-tools
anduse-compiled-tools
feature flags, whereuse-compiled-tools
is the default feature for optimal user experience.Missing
Assembler
will choke on hexadecimal floats, but we only use theAssembler
in tests and none of them currently use hexadecimal floats, so figured this would be ok for now, the issue is fixable but doing C++ code was making me sad so I punted until it became an actual issue.Resolves: #31