Skip to content
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

Optimize SPIR-V code #904

Closed
wants to merge 13 commits into from
Closed

Optimize SPIR-V code #904

wants to merge 13 commits into from

Conversation

GabrielMajeri
Copy link
Contributor

@GabrielMajeri GabrielMajeri commented Jan 5, 2018

This pull request adds an additional tool (spirv-opt) to the shader building pipeline. It is used to optimize the shader modules even further.

glslangValidator is good at compiling code, but it is meant to be a reference compiler, not an optimizer, therefore it lacks advanced optimizations.

The SPIRV-Tools repository contains a tool called spirv-opt which can be used to optimize shader binaries. I haven't run any advanced benchmarks, but on the examples, this tool reduces shader code size by about 33% (by eliminating dead / unnecessary code).

This will also open the way to even more advanced optimizations as spirv-opt gets improved.

The pull request includes the x64-Release Windows binary from CI, available here. I understand if you want to remove it and add it yourself since I could've potentialy included malicious code.

In order to enable to use additional tools I had to change glsl-to-spirv. I refactored both the build.rs and the lib.rs files, it should be easier to chain more tools in the future.


To do:

  • Fix building on Linux. CI works now.
  • Test this on more code to make sure it works. The examples seem to be fine, and I enabled no "unsafe" optimizations, but I don't know if everything will still work.
  • I tried adding the --strip-debug flag but it prevents shader reflection from working. @tomaka do you want to investigate or is it alright to merge without it? Won't enable it, unnecessary.

@tomaka
Copy link
Member

tomaka commented Jan 5, 2018

I tried adding the --strip-debug flag but it prevents shader reflection from working. @tomaka do you want to investigate or is it alright to merge without it?

I suppose that --strip-debug does not add any further optimization, so I'm fine with merging without it.

@GabrielMajeri
Copy link
Contributor Author

@tomaka It removes some metadata required for reflection, but I think it's OK, since the driver would throw it away anyway.

There are other options we could enable over time, described in this white paper.

@rukai
Copy link
Member

rukai commented Sep 20, 2018

glsl-to-spirv is no more #947

@rukai rukai closed this Sep 20, 2018
@GabrielMajeri GabrielMajeri deleted the spirv-opt branch September 20, 2018 14:29
@antiagainst
Copy link

Related to this, since we already include the whole copy of SPIRV-Tools in Shaderc, it should be natural to extend the current shaderc-rs API to also expose SPIRV-Tools ones, if there is a need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants