Use statically typed compilation results in C++ API

Class shaderc::CompilationResult is a template over the element type for
the compilation output. It has three specializations: for a SPIR-V
binary module (with uint32_t element type), SPIR-V assembly text (char
element type), and preprocessed source (char element type).

The compilation output is accessed via cbegin(), cend() and begin()
end() iterators.

Test code updates:
- Add 'using' declarations for all three compilation result
  classes.
- Add const to compilation result variables, where possible.
- IsValidSpv should take an SpvCompilationResult, and should not
  be parameterized over compilation result types.
- IsValidSpv should take an SpvCompilationResult
- Test PreprocessingOnlyOption should use a
  PreprocessedSourceCompilationResult variable instead of an
  AssemblyCompilationResult variable.

Remove SetDisassemblyMode and SetPreprocessOnlyMode methods on the
CompileOptions object so we can't get the wrong output by mixing up
options with compilation methods.

Removed FileCompiler members disassemble_ and preprocess_only_

Remove Disassembly and PreprocessOnly options on shaderc_util::Compiler

C API changes:

- Use different compile functions in the C API for different output types.
- Remove disassembly mode and preprocess-only mode calls.
12 files changed
tree: 34e773074ce32adf99e3fb70cba711435560c975
  1. android_test/
  2. cmake/
  3. glslc/
  4. libshaderc/
  5. libshaderc_util/
  6. third_party/
  7. utils/
  8. .appveyor.yml
  9. .gitignore
  10. .travis.yml
  11. Android.mk
  12. AUTHORS
  13. CMakeLists.txt
  14. CONTRIBUTING.md
  15. CONTRIBUTORS
  16. DEVELOPMENT.howto.md
  17. LICENSE
  18. README.md
README.md

Shaderc

Linux Build Status Windows Build status Coverage Status

A collection of tools, libraries and tests for shader compilation. At the moment it includes:

  • glslc, a command line compiler for GLSL to SPIR-V, and
  • libshaderc a library API for doing the same.

Status

Shaderc is experimental, and subject to significant incompatible changes.

For licensing terms, please see the LICENSE file. If interested in contributing to this project, please see CONTRIBUTING.md

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google. That may change if Shaderc gains contributions from others. See the CONTRIBUTING.md file for more information. See also the AUTHORS and CONTRIBUTORS files.

File organization

  • android_test/ : a small Android application to verify compilation
  • cmake/: CMake utility functions and configuration for Shaderc
  • glslc/: an executable to compile GLSL to SPIR-V
  • libshaderc/: a library for compiling shader strings into SPIR-V
  • libshaderc_util/: a utility library used by multiple shaderc components
  • third_party/: third party open source packages; see below
  • utils/: utility scripts for Shaderc

Shaderc depends on glslang, the Khronos reference compiler for GLSL. Sometimes a change updates both Shaderc and glslang. In that case the glslang change will appear in google/glslang before it appears upstream in KhronosGroup/glslang. We intend to upstream all changes to glslang. We maintain the separate copy only to stage those changes for review, and to provide something for Shaderc to build against in the meantime. Please see DEVELOPMENT.howto.md for more details.

Shaderc depends on SPIRV-Tools for assembling and disassembling SPIR-V binaries.

Shaderc depends on the Google Test testing framework.

In the following sections, $SOURCE_DIR is the directory you intend to clone Shaderc into.

Getting and building Shaderc

  1. Check out the source code:
git clone https://github.com/google/shaderc $SOURCE_DIR
cd $SOURCE_DIR/third_party
git clone https://github.com/google/googletest.git
git clone https://github.com/google/glslang.git
git clone https://github.com/KhronosGroup/SPIRV-Tools.git spirv-tools
cd $SOURCE_DIR/
  1. Ensure you have the requisite tools -- see the tools subsection below.

  2. Decide where to place the build output. In the following steps, we'll call it $BUILD_DIR. Any new directory should work. We recommend building outside the source tree, but it is also common to build in a (new) subdirectory of $SOURCE_DIR, such as $SOURCE_DIR/build.

4a) Build (and test) with Ninja on Linux or Windows:

cd $BUILD_DIR
cmake -GNinja -DCMAKE_BUILD_TYPE={Debug|Release|RelWithDebInfo} $SOURCE_DIR
ninja
ctest # optional

4b) Or build (and test) with MSVC on Windows:

cd $BUILD_DIR
cmake $SOURCE_DIR
cmake --build . --config {Release|Debug|MinSizeRel|RelWithDebInfo}
ctest -C {Release|Debug|MinSizeRel|RelWithDebInfo}

After a successful build, you should have a glslc executable somewhere under the $BUILD_DIR/glslc/ directory, as well as a libshaderc library somewhere under the $BUILD_DIR/libshaderc/ directory.

See the libshaderc README for more on using the library API in your project.

Tools you'll need

For building, testing, and profiling Shaderc, the following tools should be installed regardless of your OS:

  • CMake: for generating compilation targets.
  • Python: for utility scripts and running the test suite.

On Linux, the following tools should be installed:

  • gcov: for testing code coverage, provided by the gcc package on Ubuntu.
  • lcov: a graphical frontend for gcov, provided by the lcov package on Ubuntu.
  • genhtml: for creating reports in html format from lcov output, provided by the lcov package on Ubuntu.

On Windows, the following tools should be installed and available on your path:

  • Visual Studio 2013 Update 4 or later. Previous versions of Visual Studio will likely work but are untested.
  • Git - including the associated tools, Bash, diff.

Optionally, the following tools may be installed on any OS:

Bug tracking

We track bugs using GitHub -- click on the “Issues” button on the project's GitHub page.

Test coverage

On Linux, you can obtain test coverage as follows:

cd $BUILD_DIR
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_CODE_COVERAGE=ON $SOURCE_DIR
ninja
ninja report-coverage

Then the coverage report can be found under the $BUILD_DIR/coverage-report directory.