Skip to content

Commit b507034

Browse files
nlordellrukai
authored andcommitted
Use shaderc instead of glsl-to-spirv for shader compilation (#947)
* Use shaderc instead of glsl-to-spirv for shader compilation * added some setup notes
1 parent e3bfe42 commit b507034

File tree

19 files changed

+64
-257
lines changed

19 files changed

+64
-257
lines changed

Diff for: .gitlab-ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ stages:
1313
job1:
1414
stage: test
1515
script:
16-
- cargo test -v --manifest-path glsl-to-spirv/Cargo.toml
1716
- cargo test -v --manifest-path vulkano-shaders/Cargo.toml
1817
- cargo test --no-run -v --manifest-path vulkano/Cargo.toml
1918

Diff for: .gitmodules

-3
This file was deleted.

Diff for: .travis.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ addons:
2222
- cmake-data
2323

2424
script:
25-
- cargo test --all -j 1
25+
- travis_wait cargo test --all -j 1
2626
- cd examples
2727
- cargo build
2828
- cd .. # this is very important or else the below `cargo publish` will fail
@@ -40,10 +40,6 @@ after_success:
4040
[ $TRAVIS_BRANCH = master ] &&
4141
[ $TRAVIS_PULL_REQUEST = false ] &&
4242
cargo publish --token ${CRATESIO_TOKEN} --manifest-path vulkano-win/Cargo.toml
43-
- |
44-
[ $TRAVIS_BRANCH = master ] &&
45-
[ $TRAVIS_PULL_REQUEST = false ] &&
46-
cargo publish --token ${CRATESIO_TOKEN} --manifest-path glsl-to-spirv/Cargo.toml
4743
- |
4844
[ $TRAVIS_BRANCH = master ] &&
4945
[ $TRAVIS_PULL_REQUEST = false ] &&

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Fix instance_count when using draw_index with instance buffers
66
- Added a `reinterpret` function to `BufferSlice`
77

8+
- Use [google/shaderc](https://github.com/google/shaderc-rs) for shader compilation
9+
810
# Version 0.10.0 (2018-08-10)
911

1012
- Use dynamically loaded `libvulkan` like on other platforms instead of linking to MoltenVK on macOS

Diff for: Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[workspace]
22
members = [
33
"examples",
4-
"glsl-to-spirv",
54
"vk-sys",
65
"vulkano",
76
"vulkano-shaders",

Diff for: README.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,17 @@ To get started you are encouraged to use the following resources:
5151
examples in the repo and also a list of projects that use vulkano.
5252
* [docs.rs](https://docs.rs/vulkano) - Full Vulkano API documentation
5353

54-
## macOS and iOS Setup
54+
## Setup
55+
56+
Vulkano uses [shaderc-rs](https://github.com/google/shaderc-rs) for shader compilation. In order to
57+
build the shaderc-rs crate the following tools must be installed and available on `PATH`:
58+
- [CMake](https://cmake.org/)
59+
- [Python](https://www.python.org/) (works with both Python 2.x and 3.x)
60+
61+
These requirements can be either installed with your favourite package manager or with installers
62+
from the projects' websites.
63+
64+
### macOS and iOS Specific Setup
5565

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

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

119125
In order to run tests, run `cargo test --all` at the root of the repository. Make sure your Vulkan
120126
driver is up to date before doing so.

Diff for: glsl-to-spirv/Cargo.toml

-16
This file was deleted.

Diff for: glsl-to-spirv/build/build.rs

-44
This file was deleted.

Diff for: glsl-to-spirv/build/glslangValidator.exe

-3.12 MB
Binary file not shown.

Diff for: glsl-to-spirv/glslang

-1
This file was deleted.

Diff for: glsl-to-spirv/readme.md

-1
This file was deleted.

Diff for: glsl-to-spirv/src/lib.rs

-76
This file was deleted.

Diff for: glsl-to-spirv/tests/test.rs

-25
This file was deleted.

Diff for: vulkano-shader-derive/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ name = "vulkano_shader_derive"
1313
proc-macro = true
1414

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

Diff for: vulkano-shader-derive/src/lib.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@
155155
//! [SpecializationConstants]: https://docs.rs/vulkano/*/vulkano/pipeline/shader/trait.SpecializationConstants.html
156156
//! [pipeline]: https://docs.rs/vulkano/*/vulkano/pipeline/index.html
157157
158-
extern crate glsl_to_spirv;
159158
extern crate proc_macro;
160159
extern crate syn;
161160
extern crate vulkano_shaders;
@@ -235,19 +234,18 @@ pub fn derive(input: TokenStream) -> TokenStream {
235234
}).next().expect("Can't find `ty` attribute ; put #[ty = \"vertex\"] for example.");
236235

237236
let ty = match &ty_str[..] {
238-
"vertex" => glsl_to_spirv::ShaderType::Vertex,
239-
"fragment" => glsl_to_spirv::ShaderType::Fragment,
240-
"geometry" => glsl_to_spirv::ShaderType::Geometry,
241-
"tess_ctrl" => glsl_to_spirv::ShaderType::TessellationControl,
242-
"tess_eval" => glsl_to_spirv::ShaderType::TessellationEvaluation,
243-
"compute" => glsl_to_spirv::ShaderType::Compute,
237+
"vertex" => vulkano_shaders::ShaderKind::Vertex,
238+
"fragment" => vulkano_shaders::ShaderKind::Fragment,
239+
"geometry" => vulkano_shaders::ShaderKind::Geometry,
240+
"tess_ctrl" => vulkano_shaders::ShaderKind::TessControl,
241+
"tess_eval" => vulkano_shaders::ShaderKind::TessEvaluation,
242+
"compute" => vulkano_shaders::ShaderKind::Compute,
244243
_ => panic!("Unexpected shader type ; valid values: vertex, fragment, geometry, tess_ctrl, tess_eval, compute")
245244
};
246-
247-
let spirv_data = match glsl_to_spirv::compile(&source_code, ty) {
248-
Ok(compiled) => compiled,
249-
Err(message) => panic!("{}\nfailed to compile shader", message),
250-
};
251-
252-
vulkano_shaders::reflect("Shader", spirv_data).unwrap().parse().unwrap()
245+
let content = vulkano_shaders::compile(&source_code, ty).unwrap();
246+
247+
vulkano_shaders::reflect("Shader", content.as_binary())
248+
.unwrap()
249+
.parse()
250+
.unwrap()
253251
}

Diff for: vulkano-shaders/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ documentation = "http://tomaka.github.io/vulkano/vulkano/index.html"
99
categories = ["rendering::graphics-api"]
1010

1111
[dependencies]
12-
glsl-to-spirv = { version = "0.1.6", path = "../glsl-to-spirv" }
12+
shaderc = "0.3"

Diff for: vulkano-shaders/examples/example.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// notice may not be copied, modified, or distributed except
88
// according to those terms.
99

10-
extern crate glsl_to_spirv;
1110
extern crate vulkano_shaders;
1211

1312
fn main() {
@@ -40,7 +39,7 @@ void main() {
4039
4140
"#;
4241

43-
let content = glsl_to_spirv::compile(shader, glsl_to_spirv::ShaderType::Fragment).unwrap();
44-
let output = vulkano_shaders::reflect("Shader", content).unwrap();
42+
let content = vulkano_shaders::compile(shader, vulkano_shaders::ShaderKind::Fragment).unwrap();
43+
let output = vulkano_shaders::reflect("Shader", content.as_binary()).unwrap();
4544
println!("{}", output);
4645
}

0 commit comments

Comments
 (0)