Skip to content

Commit

Permalink
Use shaderc instead of glsl-to-spirv for shader compilation (#947)
Browse files Browse the repository at this point in the history
* Use shaderc instead of glsl-to-spirv for shader compilation
* added some setup notes
  • Loading branch information
nlordell authored and rukai committed Sep 20, 2018
1 parent e3bfe42 commit b507034
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 257 deletions.
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ stages:
job1:
stage: test
script:
- cargo test -v --manifest-path glsl-to-spirv/Cargo.toml
- cargo test -v --manifest-path vulkano-shaders/Cargo.toml
- cargo test --no-run -v --manifest-path vulkano/Cargo.toml

Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ addons:
- cmake-data

script:
- cargo test --all -j 1
- travis_wait cargo test --all -j 1
- cd examples
- cargo build
- cd .. # this is very important or else the below `cargo publish` will fail
Expand All @@ -40,10 +40,6 @@ after_success:
[ $TRAVIS_BRANCH = master ] &&
[ $TRAVIS_PULL_REQUEST = false ] &&
cargo publish --token ${CRATESIO_TOKEN} --manifest-path vulkano-win/Cargo.toml
- |
[ $TRAVIS_BRANCH = master ] &&
[ $TRAVIS_PULL_REQUEST = false ] &&
cargo publish --token ${CRATESIO_TOKEN} --manifest-path glsl-to-spirv/Cargo.toml
- |
[ $TRAVIS_BRANCH = master ] &&
[ $TRAVIS_PULL_REQUEST = false ] &&
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Fix instance_count when using draw_index with instance buffers
- Added a `reinterpret` function to `BufferSlice`

- Use [google/shaderc](/~https://github.com/google/shaderc-rs) for shader compilation

# Version 0.10.0 (2018-08-10)

- Use dynamically loaded `libvulkan` like on other platforms instead of linking to MoltenVK on macOS
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[workspace]
members = [
"examples",
"glsl-to-spirv",
"vk-sys",
"vulkano",
"vulkano-shaders",
Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ To get started you are encouraged to use the following resources:
examples in the repo and also a list of projects that use vulkano.
* [docs.rs](https://docs.rs/vulkano) - Full Vulkano API documentation

## macOS and iOS Setup
## Setup

Vulkano uses [shaderc-rs](/~https://github.com/google/shaderc-rs) for shader compilation. In order to
build the shaderc-rs crate the following tools must be installed and available on `PATH`:
- [CMake](https://cmake.org/)
- [Python](https://www.python.org/) (works with both Python 2.x and 3.x)

These requirements can be either installed with your favourite package manager or with installers
from the projects' websites.

### macOS and iOS Specific Setup

Vulkan is not natively supported by macOS and iOS. However, there exists [MoltenVK](/~https://github.com/KhronosGroup/MoltenVK)
a Vulkan implementation on top of Apple's Metal API. This allows vulkano to build and run on macOS
Expand Down Expand Up @@ -107,14 +117,10 @@ This repository contains six libraries:
easily integrate your GLSL shaders within the rest of your source code.
- `vulkano-win` provides a safe link between vulkano and the `winit` library which can create
a window to render to.
- `glsl-to-spirv` can compile GLSL to SPIR-V by wrapping around `glslang`. `glsl-to-spirv` is an
implementation detail that you don't need to use manually if you use vulkano.
- `vk-sys` contains raw bindings for Vulkan. You can use it even if you don't care about vulkano.

Once procedural macros are stabilized in Rust, the `vulkano-shaders` and `vulkano-shader-derive`
crates will be merged with the `vulkano` crate. The `glsl-to-spirv` crate is an implementation
detail of vulkano and is not supposed to be used directly if you use vulkano. You are, however,
free to use it if you want to write an alternative to vulkano.
crates will be merged with the `vulkano` crate.

In order to run tests, run `cargo test --all` at the root of the repository. Make sure your Vulkan
driver is up to date before doing so.
Expand Down
16 changes: 0 additions & 16 deletions glsl-to-spirv/Cargo.toml

This file was deleted.

44 changes: 0 additions & 44 deletions glsl-to-spirv/build/build.rs

This file was deleted.

Binary file removed glsl-to-spirv/build/glslangValidator.exe
Binary file not shown.
1 change: 0 additions & 1 deletion glsl-to-spirv/glslang
Submodule glslang deleted from 4fbb8c
1 change: 0 additions & 1 deletion glsl-to-spirv/readme.md

This file was deleted.

76 changes: 0 additions & 76 deletions glsl-to-spirv/src/lib.rs

This file was deleted.

25 changes: 0 additions & 25 deletions glsl-to-spirv/tests/test.rs

This file was deleted.

1 change: 0 additions & 1 deletion vulkano-shader-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ name = "vulkano_shader_derive"
proc-macro = true

[dependencies]
glsl-to-spirv = { version = "0.1.6", path = "../glsl-to-spirv" }
syn = "0.14"
vulkano-shaders = { version = "0.10", path = "../vulkano-shaders" }

Expand Down
26 changes: 12 additions & 14 deletions vulkano-shader-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
//! [SpecializationConstants]: https://docs.rs/vulkano/*/vulkano/pipeline/shader/trait.SpecializationConstants.html
//! [pipeline]: https://docs.rs/vulkano/*/vulkano/pipeline/index.html
extern crate glsl_to_spirv;
extern crate proc_macro;
extern crate syn;
extern crate vulkano_shaders;
Expand Down Expand Up @@ -235,19 +234,18 @@ pub fn derive(input: TokenStream) -> TokenStream {
}).next().expect("Can't find `ty` attribute ; put #[ty = \"vertex\"] for example.");

let ty = match &ty_str[..] {
"vertex" => glsl_to_spirv::ShaderType::Vertex,
"fragment" => glsl_to_spirv::ShaderType::Fragment,
"geometry" => glsl_to_spirv::ShaderType::Geometry,
"tess_ctrl" => glsl_to_spirv::ShaderType::TessellationControl,
"tess_eval" => glsl_to_spirv::ShaderType::TessellationEvaluation,
"compute" => glsl_to_spirv::ShaderType::Compute,
"vertex" => vulkano_shaders::ShaderKind::Vertex,
"fragment" => vulkano_shaders::ShaderKind::Fragment,
"geometry" => vulkano_shaders::ShaderKind::Geometry,
"tess_ctrl" => vulkano_shaders::ShaderKind::TessControl,
"tess_eval" => vulkano_shaders::ShaderKind::TessEvaluation,
"compute" => vulkano_shaders::ShaderKind::Compute,
_ => panic!("Unexpected shader type ; valid values: vertex, fragment, geometry, tess_ctrl, tess_eval, compute")
};

let spirv_data = match glsl_to_spirv::compile(&source_code, ty) {
Ok(compiled) => compiled,
Err(message) => panic!("{}\nfailed to compile shader", message),
};

vulkano_shaders::reflect("Shader", spirv_data).unwrap().parse().unwrap()
let content = vulkano_shaders::compile(&source_code, ty).unwrap();

vulkano_shaders::reflect("Shader", content.as_binary())
.unwrap()
.parse()
.unwrap()
}
2 changes: 1 addition & 1 deletion vulkano-shaders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ documentation = "http://tomaka.github.io/vulkano/vulkano/index.html"
categories = ["rendering::graphics-api"]

[dependencies]
glsl-to-spirv = { version = "0.1.6", path = "../glsl-to-spirv" }
shaderc = "0.3"
5 changes: 2 additions & 3 deletions vulkano-shaders/examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// notice may not be copied, modified, or distributed except
// according to those terms.

extern crate glsl_to_spirv;
extern crate vulkano_shaders;

fn main() {
Expand Down Expand Up @@ -40,7 +39,7 @@ void main() {
"#;

let content = glsl_to_spirv::compile(shader, glsl_to_spirv::ShaderType::Fragment).unwrap();
let output = vulkano_shaders::reflect("Shader", content).unwrap();
let content = vulkano_shaders::compile(shader, vulkano_shaders::ShaderKind::Fragment).unwrap();
let output = vulkano_shaders::reflect("Shader", content.as_binary()).unwrap();
println!("{}", output);
}
Loading

0 comments on commit b507034

Please sign in to comment.