NDK Release 17
Merge remote-tracking branch 'aosp/upstream-master' into update-shaderc

Includes:
b5b08462 Merge pull request #1124 from xorgy/check-inner-implicit-atomic-uint
60209951 Merge pull request #1127 from xorgy/preprocessor-int-min-mod-negative-one
9d4a1b24 Preprocessor: Evaluate INT_MIN % -1 to 0.
047b65f9 Merge pull request #1125 from greg-lunarg/kg1
cc80d80d Update spirv-tools known-good
437911af GLSL: Check for implicit inner dimension in array of atomic_uint.
9cfc1551 Merge pull request #1118 from xorgy/only-swizzle-numbers-and-bools
016e47f7 Merge branch 'only-parse-inf-constant-in-hlsl' of https://github.com/xorgy/glslang into xorgy-only-parse-inf-constant-in-hlsl
6e33b787 Tests: Add test for GLSL +-#INF.
79a40740 Merge pull request #1120 from xorgy/overlong-hex-literal
60312662 GLSL: Only parse [-]1.#INF in HLSL mode.
9028ed20 Check for hexadecimal literals exceeding MaxTokenLength.
07c0bcea Only try swizzles on vectors, numbers, and booleans.
b1eaf82c Merge pull request #1115 from LoopDawg/stdarray-binding-set
2915da30 Nonfunctional: minor: use std::array for per-set shifts, fix warning.
573cc9e9 Merge pull request #1111 from LoopDawg/per-set-binding-offsets
7a9db71f SPV: Don't emit StorageImageMultisample capability for subpass images.
6cfeced8 Non-functional: missing comments from missed git add.
1b46f137 HLSL: Fix #1106. Support shader setting of binding/set for $Global.
08a14422 Add per-descriptor-set IO mapping shift values.
fe4e572c GLSL->SPIR-V: Put precision decorations on imageLoad().
f0e35bf0 GLSL: Make sampling operations have agnostic precision qualifiers for desktop.
3112b568 Merge pull request #1113 from xorgy/preprocessor-int-min-over-negative-one
0b55e0f2 Merge pull request #1102 from KhronosGroup/partially-flatten
dc756a61 Preprocessor: Evaluate INT_MIN / -1 to 0.
a50b107e Build: Fix build warning.
8b555f74 Merge pull request #1109 from xorgy/never-try-to-swizzle-void
5313613d Don't try to swizzle void.
856502cb Update spirv-tools known-good
7d67c6cb PP: Fix #1104: Missing check for #if overflow.
1a4bbc4a HLSL: More clip fix: It is more involved than previous commit. Complete.
4ce5b562 Fix #1103: clip() works on int/uint.
5889fa03 Tests: Add clip(int) tests.
cf571f73 Infrastructure: Add a TShader method to publicly expose the intermediate.
41aa1995 HLSL: Partially flatten hierarchies, instead of all or nothing.
60e91611 Merge pull request #1098 from LoopDawg/attribute-gets
0d1f63ec Merge pull request #1097 from SWIFTingAround/master
ad2bc097 Merge pull request #1094 from LoopDawg/split-shadow-tx
ddb45f8d Merge pull request #1080 from hedejing/master
52c087ff HLSL: add helper access methods to TAttributeMap
aab00012 Set cmake-policy CMP0048 to NEW
fdbd0eba Add getAsLoopNode() method for Loop node
028c5a8d HLSL: nonfunctional: rename setId -> switchId, add comment
bb79abcc HLSL: Validate implicit initializer assignment to opaque members.
07ed11f9 SPV: GeneratorVersion: bump version number because of atomic decrement change.
b27de028 Merge pull request #1090 from tafuri/#1084-fix-segfault
48d6e798 SPV: Correct semantics of atomic-counter decrement.
592e8f04 HLSL: Tests: Add subset of flattened opaque test to legalize results.
4f6865f4 Added test for local structured buffer variable
5133b108 Fixed formatting
908813c2 Merge pull request #1089 from LoopDawg/split-shadow-tx
0a826111 Only track variables in the global scope
73c57bbe HLSL: split textures used for both shadow and non-shadow modes
263986eb Readme: Update with additional Windows build information for SPIRV-tools build.
2c9c2af6 Merge pull request #1085 from KhronosGroup/flatten-assign-subset
700bdeb7 HLSL: Fix #954: Track/access subsets of flattened multi-level aggregates.
86a82bb9 Merge pull request #1081 from xxxbxxx/for-upstream-1
a6085875 HLSL: Fix crash when flattening both side of assignement simultaneously.
24919659 Merge pull request #1075 from LoopDawg/subpass-input
7f93d56e HLSL: add subpass input types and methods
092b7d2e Build: Fix a couple build issues.
77ea30bd HLSL: Additional attribute support: [[]], namespace, parameters:
3693e631 Fix #1060: Could crash if using --source-entry-point with -e; fixed.
5a57ca68 Merge pull request #1078 from greg-lunarg/addopt14
354a54c6 Legalization: Fix tests after workarounds removed
d41993d9 SPV: rationalize parameter handling for "original" and "writable" parameters.
bed4e4f7 HLSL: Pass opaques by local copy, instead of by interface original.
15fa7ef5 HLSL: Remove workarounds for assigning to opaques.
dabd1bf2 Merge pull request #1076 from LoopDawg/shadow-tx-types
195f584e HLSL: force textures to shadow modes from combined samplers
fc7aeaee Merge pull request #1077 from greg-lunarg/addopt12
52fe3d59 Legalization: Fix warnings and disable tests when spirv-tools not present
3ddcd3f1 Merge pull request #1070 from greg-lunarg/addopt8
e2b36163 Advance spirv-opt known-good to hopefully fix travis multithread failure
b56366ab Legalization: Skip spirv-tools tests
741d1f20 Pick up latest spirv-tools in attempt to fix travis failures
87fd7429 Try Python interpreter on update_glslang_sources.py in appveyor
f451756d Fix travis and appveyor calls to update_glslang_sources.py
cd1f169c Enable HLSL legalization
44dd6a00 Merge pull request #1072 from amdrexu/feature
e8fe8b0d Implement extension GL_NV_shader_atomic_int64
f21c173a Merge pull request #1071 from antiagainst/ninja-make
afa128a8 Travis: use make instead of ninja and limit concurrent jobs
9cf5dfbd Merge pull request #1063 from LoopDawg/remapper-error-cleanup
ea5204d1 Build: Merge pull request #1068 from greg-lunarg/addopt4
fd34f0e6 CMake changes for HLSL legalization
8004d365 Remapper: make remapper robust against non-exiting error handlers
5f77d864 HLSL: Fix #1064: Don't include empty structures on OpEntryPoint
31365afa Merge pull request #1044 from dsrbecky/image_external_essl3
ae8af5d3 HLSL: fix array[1] of vec4 constant declaration.
c64a9dd6 Test: Make another test legal HLSL, and rationalize GLSL vs HLSL addConstructor().
bdbbc68e HLSL: Add bounds checking, shared with GLSL. Partially address #1032.
346dd7c7 Merge pull request #1051 from LoopDawg/bug-1049
4a145dbf HLSL: handle split InputPatch templat type in patch constant functions
a5d86164 HLSL: allow mixed user & builtin members in hull shader output structure
ba6a3c29 GLSL: Make gl_Layer and gl_ViewportIndex always be outside blocks.
aab3bcff Merge pull request #1056 from KhronosGroup/glsl-entrypoint-rename
9855bdad GLSL: Promote HLSL entry-point renaming code to be used by GLSL as well.
4f4683d2 Merge pull request #1050 from amdrexu/feature
30ac0525 Merge pull request #1055 from KhronosGroup/strdup
d9bd97d0 Build: Fix strdup -> _strdup warnings.
b3ca4045 Build: Fix build warnings.
5002c26b Fix #1043: set all scan string-locations to have bias, not just the first one.
a25530cc Non-functional: Make usage for entry points more consistent.
e22c11fd Merge pull request #1053 from mchock-nv/mchock-nv-fix-lambda
ea1ea974 Address #1052: Have language-level exits of case statements.
933c10cd Delete unused 'this' capture
05506bb8 Implement the extension GL_AMD_shader_fragment_mask
d004e5ca Merge pull request #1047 from svenstaro/add-stdin-option
0dd1285c Add --stdin
8688e3fb Merge pull request #1048 from LoopDawg/opaque-type-fix
76117921 Fix lvalue check in SPIR-V generation
2c5b3d64 Add support for GL_OES_EGL_image_external_essl3

Test: checkbuild.py on Linux; unit tests on Windows
Change-Id: I58d37c7e7a7fb77751c6a848d43e4957d18e7e84
tree: 7b938045565b18eaca3bf0867e51f16f914d64b7
  1. External/
  2. glslang/
  3. gtests/
  4. hlsl/
  5. OGLCompilersDLL/
  6. SPIRV/
  7. StandAlone/
  8. Test/
  9. .appveyor.yml
  10. .clang-format
  11. .gitattributes
  12. .gitignore
  13. .travis.yml
  14. ChooseMSVCCRT.cmake
  15. CMakeLists.txt
  16. known_good.json
  17. make-revision
  18. README-spirv-remap.txt
  19. README.md
  20. update_glslang_sources.py
README.md

Also see the Khronos landing page for glslang as a reference front end:

https://www.khronos.org/opengles/sdk/tools/Reference-Compiler/

The above page includes where to get binaries, and is kept up to date regarding the feature level of glslang.

glslang

Build Status Build status

An OpenGL and OpenGL ES shader front end and validator.

There are several components:

  1. A GLSL/ESSL front-end for reference validation and translation of GLSL/ESSL into an AST.

  2. An HLSL front-end for translation of a broad generic HLL into the AST. See issue 362 and issue 701 for current status.

  3. A SPIR-V back end for translating the AST to SPIR-V.

  4. A standalone wrapper, glslangValidator, that can be used as a command-line tool for the above.

How to add a feature protected by a version/extension/stage/profile: See the comment in glslang/MachineIndependent/Versions.cpp.

Tasks waiting to be done are documented as GitHub issues.

Execution of Standalone Wrapper

To use the standalone binary form, execute glslangValidator, and it will print a usage statement. Basic operation is to give it a file containing a shader, and it will print out warnings/errors and optionally an AST.

The applied stage-specific rules are based on the file extension:

  • .vert for a vertex shader
  • .tesc for a tessellation control shader
  • .tese for a tessellation evaluation shader
  • .geom for a geometry shader
  • .frag for a fragment shader
  • .comp for a compute shader

There is also a non-shader extension

  • .conf for a configuration file of limits, see usage statement for example

Building

Dependencies

  • CMake: for generating compilation targets.
  • Python 2.7: for executing SPIRV-Tools scripts. (Optional if not using SPIRV-Tools.)
  • bison: optional, but needed when changing the grammar (glslang.y).
  • googletest: optional, but should use if making any changes to glslang.

Build steps

1) Check-Out this project

cd <parent of where you want glslang to be>
# If using SSH
git clone git@github.com:KhronosGroup/glslang.git
# Or if using HTTPS
git clone https://github.com/KhronosGroup/glslang.git

2) Check-Out External Projects

cd <the directory glslang was cloned to, "External" will be a subdirectory>
git clone https://github.com/google/googletest.git External/googletest

If you wish to assure that SPIR-V generated from HLSL is legal for Vulkan, or wish to invoke -Os to reduce SPIR-V size from HLSL or GLSL, install spirv-tools with this:

./update_glslang_sources.py

For running the CMake GUI or Visual Studio with python dependencies, you will, in addition to python within the cygwin environment, need a Windows python installation, including selecting the PATH update.

3) Configure

Assume the source directory is $SOURCE_DIR and the build directory is $BUILD_DIR:

For building on Linux (assuming using the Ninja generator):

cd $BUILD_DIR

cmake -GNinja -DCMAKE_BUILD_TYPE={Debug|Release|RelWithDebInfo} \
      -DCMAKE_INSTALL_PREFIX=`pwd`/install $SOURCE_DIR

For building on Windows:

cmake $SOURCE_DIR -DCMAKE_INSTALL_PREFIX=`pwd`/install
# The CMAKE_INSTALL_PREFIX part is for testing (explained later).

The CMake GUI also works for Windows (version 3.4.1 tested).

4) Build and Install

# for Linux:
ninja install

# for Windows:
cmake --build . --config {Release|Debug|MinSizeRel|RelWithDebInfo} \
      --target install

If using MSVC, after running CMake to configure, use the Configuration Manager to check the INSTALL project.

If you need to change the GLSL grammar

The grammar in glslang/MachineIndependent/glslang.y has to be recompiled with bison if it changes, the output files are committed to the repo to avoid every developer needing to have bison configured to compile the project when grammar changes are quite infrequent. For windows you can get binaries from GnuWin32.

The command to rebuild is:

bison --defines=MachineIndependent/glslang_tab.cpp.h
      -t MachineIndependent/glslang.y
      -o MachineIndependent/glslang_tab.cpp

The above command is also available in the bash script at glslang/updateGrammar.

Testing

Right now, there are two test harnesses existing in glslang: one is Google Test, one is the runtests script. The former runs unit tests and single-shader single-threaded integration tests, while the latter runs multiple-shader linking tests and multi-threaded tests.

Running tests

The runtests script requires compiled binaries to be installed into $BUILD_DIR/install. Please make sure you have supplied the correct configuration to CMake (using -DCMAKE_INSTALL_PREFIX) when building; otherwise, you may want to modify the path in the runtests script.

Running Google Test-backed tests:

cd $BUILD_DIR

# for Linux:
ctest

# for Windows:
ctest -C {Debug|Release|RelWithDebInfo|MinSizeRel}

# or, run the test binary directly
# (which gives more fine-grained control like filtering):
<dir-to-glslangtests-in-build-dir>/glslangtests

Running runtests script-backed tests:

cd $SOURCE_DIR/Test && ./runtests

Contributing tests

Test results should always be included with a pull request that modifies functionality.

If you are writing unit tests, please use the Google Test framework and place the tests under the gtests/ directory.

Integration tests are placed in the Test/ directory. It contains test input and a subdirectory baseResults/ that contains the expected results of the tests. Both the tests and baseResults/ are under source-code control.

Google Test runs those integration tests by reading the test input, compiling them, and then compare against the expected results in baseResults/. The integration tests to run via Google Test is registered in various gtests/*.FromFile.cpp source files. glslangtests provides a command-line option --update-mode, which, if supplied, will overwrite the golden files under the baseResults/ directory with real output from that invocation. For more information, please check gtests/ directory's README.

For the runtests script, it will generate current results in the localResults/ directory and diff them against the baseResults/. When you want to update the tracked test results, they need to be copied from localResults/ to baseResults/. This can be done by the bump shell script.

You can add your own private list of tests, not tracked publicly, by using localtestlist to list non-tracked tests. This is automatically read by runtests and included in the diff and bump process.

Programmatic Interfaces

Another piece of software can programmatically translate shaders to an AST using one of two different interfaces:

  • A new C++ class-oriented interface, or
  • The original C functional interface

The main() in StandAlone/StandAlone.cpp shows examples using both styles.

C++ Class Interface (new, preferred)

This interface is in roughly the last 1/3 of ShaderLang.h. It is in the glslang namespace and contains the following.

const char* GetEsslVersionString();
const char* GetGlslVersionString();
bool InitializeProcess();
void FinalizeProcess();

class TShader
    bool parse(...);
    void setStrings(...);
    const char* getInfoLog();

class TProgram
    void addShader(...);
    bool link(...);
    const char* getInfoLog();
    Reflection queries

See ShaderLang.h and the usage of it in StandAlone/StandAlone.cpp for more details.

C Functional Interface (orignal)

This interface is in roughly the first 2/3 of ShaderLang.h, and referred to as the Sh*() interface, as all the entry points start Sh.

The Sh*() interface takes a “compiler” call-back object, which it calls after building call back that is passed the AST and can then execute a backend on it.

The following is a simplified resulting run-time call stack:

ShCompile(shader, compiler) -> compiler(AST) -> <back end>

In practice, ShCompile() takes shader strings, default version, and warning/error and other options for controlling compilation.

Basic Internal Operation

  • Initial lexical analysis is done by the preprocessor in MachineIndependent/Preprocessor, and then refined by a GLSL scanner in MachineIndependent/Scan.cpp. There is currently no use of flex.

  • Code is parsed using bison on MachineIndependent/glslang.y with the aid of a symbol table and an AST. The symbol table is not passed on to the back-end; the intermediate representation stands on its own. The tree is built by the grammar productions, many of which are offloaded into ParseHelper.cpp, and by Intermediate.cpp.

  • The intermediate representation is very high-level, and represented as an in-memory tree. This serves to lose no information from the original program, and to have efficient transfer of the result from parsing to the back-end. In the AST, constants are propogated and folded, and a very small amount of dead code is eliminated.

    To aid linking and reflection, the last top-level branch in the AST lists all global symbols.

  • The primary algorithm of the back-end compiler is to traverse the tree (high-level intermediate representation), and create an internal object code representation. There is an example of how to do this in MachineIndependent/intermOut.cpp.

  • Reduction of the tree to a linear byte-code style low-level intermediate representation is likely a good way to generate fully optimized code.

  • There is currently some dead old-style linker-type code still lying around.

  • Memory pool: parsing uses types derived from C++ std types, using a custom allocator that puts them in a memory pool. This makes allocation of individual container/contents just few cycles and deallocation free. This pool is popped after the AST is made and processed.

    The use is simple: if you are going to call new, there are three cases:

    • the object comes from the pool (its base class has the macro POOL_ALLOCATOR_NEW_DELETE in it) and you do not have to call delete

    • it is a TString, in which case call NewPoolTString(), which gets it from the pool, and there is no corresponding delete

    • the object does not come from the pool, and you have to do normal C++ memory management of what you new