Merge remote-tracking branch 'aosp/master-ndk' into shaderc-update
Change-Id: I4b7181e49000dd07bc0cca5d0f2fa848f4018e78
diff --git a/.appveyor.yml b/.appveyor.yml
index 14dfce6..89bb874 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -4,9 +4,9 @@
# version format
version: "{build}"
-image:
- - Visual Studio 2013
+os:
- Visual Studio 2015
+ - Visual Studio 2013
- Visual Studio 2017
platform:
@@ -19,6 +19,14 @@
- Debug
- Release
+matrix:
+ fast_finish: true
+ exclude:
+ - os: Visual Studio 2015
+ configuration: Debug
+ - os: Visual Studio 2013
+ configuration: Debug
+
branches:
only:
- master
@@ -47,18 +55,15 @@
- ctest -C %CONFIGURATION% --output-on-failure
after_test:
- # For debug build, the generated dll has a postfix "d" in its name.
- ps: >-
If ($env:configuration -Match "Debug") {
- $env:SHADERC_DLL="shaderc_sharedd.dll"
$env:ZIP_FILENAME="shaderc-tot-windows-x64-debug.zip"
} Else {
- $env:SHADERC_DLL="shaderc_shared.dll"
$env:ZIP_FILENAME="shaderc-tot-windows-x64-release.zip"
}
- - cp libshaderc\%CONFIGURATION%\%SHADERC_DLL% install\lib\
+ - cp libshaderc\%CONFIGURATION%\shaderc_shared.dll install\lib\
- cd install
- - 7z a %ZIP_FILENAME% bin\glslc.exe include\shaderc\* lib\shaderc_combined.lib lib\%SHADERC_DLL%
+ - 7z a %ZIP_FILENAME% bin\glslc.exe include\shaderc\* lib\shaderc_combined.lib lib\shaderc_shared.dll
artifacts:
- path: build\install\$(ZIP_FILENAME)
diff --git a/.travis.yml b/.travis.yml
index cc98c66..f0b2513 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -36,6 +36,9 @@
cache:
apt: true
+git:
+ depth: 1
+
branches:
only:
- master
@@ -55,6 +58,9 @@
fi
install:
+ - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
+ sudo easy_install pip;
+ fi
- pip install --user nose
- pip install --user cpp-coveralls
diff --git a/CHANGES b/CHANGES
index eda9691..f90eece 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,10 +1,16 @@
Revision history for Shaderc
-v2017.2-dev 2017-03-10
+v2018.0-dev 2018-02-27
+ - Start v2018.0-dev
+ - Support -fhlsl_functionality1 (also -fhlsl-functionality1)
+
+v2017.2 2018-02-27
- Add a shared library version of libshaderc
- Support GLSL 4.6 and ESSL 3.2
- - Add options for automatically set bindings for (uniform) resources that
+ - Fail compilation if a resource does not have a binding.
+ - Add options for automatically setting bindings for (uniform) resources that
don't have bindings set in shader source.
+ - Add options for automatically setting locations for pipline inputs and outputs.
- Add option for using HLSL IO mappings as expressed in source.
- Add options for setting resource binding base numbers.
- Add option to use HLSL resource register numbers for bindings.
@@ -12,8 +18,10 @@
(This change is inherited from Glslang commit 7cca140.)
- HLSL compilation runs SPIR-V "legalization" transforms to reduce
manipulation of opaque handles (e.g. images), to satisfy Vulkan rules.
- - Adapt to Glslang generator version number update to 2, to indicate
- a fix for code generation for atomicCounterDecrement.
+ - Adapt to Glslang generator version numbers:
+ - To 2: a fix for code generation for atomicCounterDecrement.
+ - To 3: change memory barrier semantics masks
+ - To 4: generate more access chains for swizzles
- CMake install rules uses GNUInstallDirs. For example, install to lib64
when that is the norm for the target system.
diff --git a/README.md b/README.md
index cb4b41d..9a4cfef 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,12 @@
[![Windows Build status](https://ci.appveyor.com/api/projects/status/g6c372blna7vnk1l?svg=true)](https://ci.appveyor.com/project/dneto0/shaderc "Windows Build Status")
[![Coverage Status](https://coveralls.io/repos/google/shaderc/badge.svg?branch=master&service=github)](https://coveralls.io/github/google/shaderc?branch=master)
+Latest Build Status by Google:
+
+<img alt="Linux" src="kokoro/img/linux.png" width="20px" height="20px" hspace="2px"/>![Linux Build Status](https://storage.googleapis.com/shaderc/badges/build_status_linux_release.svg)
+<img alt="MacOS" src="kokoro/img/macos.png" width="20px" height="20px" hspace="2px"/>![MacOS Build Status](https://storage.googleapis.com/shaderc/badges/build_status_macos_release.svg)
+<img alt="Windows" src="kokoro/img/windows.png" width="20px" height="20px" hspace="2px"/>![Windows Build Status](https://storage.googleapis.com/shaderc/badges/build_status_windows_release.svg)
+
A collection of tools, libraries and tests for shader compilation.
At the moment it includes:
diff --git a/glslc/README.asciidoc b/glslc/README.asciidoc
index 03f5a56..0716be9 100644
--- a/glslc/README.asciidoc
+++ b/glslc/README.asciidoc
@@ -20,7 +20,9 @@
[-x ...] [-std=standard]
[ ... options for resource bindings ... ]
[-fhlsl-offsets]
- [-fentry-point=...]
+ [-fhlsl-functionality1]
+ [-fentry-point=<name>]
+ [-fauto-map-locations]
[-flimit=...]
[-flimit-file <resource-limits-file>]
[-fshader-stage=...]
@@ -216,16 +218,20 @@
==== `--target-env=`
`--target-env=<value>` lets you specify a target environment on the command line.
-This affects the generation of warnings and errors. ``<value>`` can be one of
+This affects the generation of warnings and errors. The ``<value>`` can be one of
the following:
-* `vulkan`: create SPIR-V under Vulkan semantics.
-* `opengl`: create SPIR-V under OpenGL semantics.
+* `vulkan`: create SPIR-V under Vulkan 1.0 semantics.
+* `vulkan1.0`: create SPIR-V under Vulkan 1.0 semantics.
+* `vulkan1.1`: create SPIR-V under Vulkan 1.1 semantics.
+* `opengl`: create SPIR-V under OpenGL 4.5 semantics.
+* `opengl4.5`: create SPIR-V under OpenGL 4.5 semantics.
* `opengl_compat`: create SPIR-V under OpenGL semantics, including compatibility
profile functions.
-By default, the ``<value>`` is set to `vulkan` and the compiler creates SPIR-V
-under Vulkan semantics.
+Generated code uses SPIR-V 1.0, except that code compiled for Vulkan 1.1 uses SPIR-V 1.3.
+
+If this option is not specified, a default of `vulkan1.0` is used.
==== `-x`
@@ -307,6 +313,7 @@
`-O` specifies which optimization level to use:
* `-O0` means "no optimization". This level generates the most debuggable code.
+* `-O` means the default optimization level for better performance.
* `-Os` enables optimizations to reduce code size.
==== `-mfmt=<format>`
@@ -348,12 +355,53 @@
Use HLSL packing rules instead of GLSL rules when determining offsets of
members of blocks. This option is always on when compiling for HLSL.
+[[option-fhlsl-functionality1]]
+==== `-fhlsl-functionality1`
+
+Enable extension `SPV_GOOGLE_hlsl_functionality1`, and instructs the compiler
+to:
+
+- Annotate HLSL semantic string decorations on interface objects
+- Explicitly record the association of a UAV resource with its companion counter buffer.
+
+This option can also be spelled with an underscore: `-fhlsl_functionality1`.
+
[[option-fentry-point]]
-==== `-fentry-point=`
+==== `-fentry-point=<name>`
`-fentry-point=<name>` lets you specify the entry point name. This is only
significant for HLSL compilation. The default is "main".
+[[option-fauto-map-locations]]
+==== `-fauto-map-locations`
+
+For GLSL compilation, option `-fauto-map-locations` directs the compiler to automatically
+assign location numbers to user-defined stage input and output variables if not explicitly
+specified by the shader source.
+
+For HLSL compilation, this option is on by default.
+
+Client APIs normally require adjacent stages to agree on their I/O interface.
+The compiler only sees one stage at a time, so it is strongly recommended that
+you avoid relying on this option to assign locations.
+
+Instead, an explicit binding number should be specified in the shader source, as follows:
+
+* In a GLSL shader, use a `location` layout qualifier:
+
+----
+layout(location = 1) in vec4 x;
+----
+
+* In an HLSL shader, use a `vk::location` attribute:
+
+----
+[[vk::location(1)]] float4 FooShader(
+ [[vk::location(0)]] float4 a,
+ [[vk::location(2)]] float4 b) : COLOR0 {
+ return a + b;
+}
+----
=== Warning and Error Options
diff --git a/glslc/src/main.cc b/glslc/src/main.cc
index d7a61c9..16f78c9 100644
--- a/glslc/src/main.cc
+++ b/glslc/src/main.cc
@@ -56,7 +56,14 @@
Automatically assign bindings to uniform variables that
don't have an explicit 'binding' layout in the shader
source.
+ -fauto-map-locations
+ Automatically assign locations to uniform variables that
+ don't have an explicit 'location' layout in the shader
+ source.
-fhlsl-iomap Use HLSL IO mappings for bindings.
+ -fhlsl_functionality1, -fhlsl-functionality1
+ Enable extension SPV_GOOGLE_hlsl_functionality1 for HLSL
+ compilation.
-fimage-binding-base [stage] <value>
Sets the lowest automatically assigned binding number for
images. Optionally only set it for a single shader stage.
@@ -131,9 +138,14 @@
generation.
-S Only run preprocess and compilation steps.
--target-env=<environment>
- Set the target shader environment, and the semantics
- of warnings and errors. Valid values are 'opengl',
- 'opengl_compat' and 'vulkan'. The default value is 'vulkan'.
+ Set the target client environment, and the semantics
+ of warnings and errors. An optional suffix can specify
+ the client version. Values are:
+ vulkan1.0 # The default
+ vulkan1.1
+ vulkan # Same as vulkan1.0
+ opengl4.5
+ opengl # Same as opengl4.5
-w Suppresses all warning messages.
-Werror Treat all warnings as errors.
-x <language> Treat subsequent input files as having type <language>.
@@ -321,10 +333,14 @@
}
} else if (arg == "-fauto-bind-uniforms") {
compiler.options().SetAutoBindUniforms(true);
+ } else if (arg == "-fauto-map-locations") {
+ compiler.options().SetAutoMapLocations(true);
} else if (arg == "-fhlsl-iomap") {
compiler.options().SetHlslIoMapping(true);
} else if (arg == "-fhlsl-offsets") {
compiler.options().SetHlslOffsets(true);
+ } else if (arg == "-fhlsl_functionality1" || arg == "-fhlsl-functionality1") {
+ compiler.options().SetHlslFunctionality1(true);
} else if (((u_kind = shaderc_uniform_kind_image),
(arg == "-fimage-binding-base")) ||
((u_kind = shaderc_uniform_kind_texture),
@@ -426,10 +442,20 @@
shaderc_target_env target_env = shaderc_target_env_default;
const string_piece target_env_str =
arg.substr(std::strlen("--target-env="));
+ uint32_t version = 0; // Will default appropriately.
if (target_env_str == "vulkan") {
target_env = shaderc_target_env_vulkan;
+ } else if (target_env_str == "vulkan1.0") {
+ target_env = shaderc_target_env_vulkan;
+ version = shaderc_env_version_vulkan_1_0;
+ } else if (target_env_str == "vulkan1.1") {
+ target_env = shaderc_target_env_vulkan;
+ version = shaderc_env_version_vulkan_1_1;
} else if (target_env_str == "opengl") {
target_env = shaderc_target_env_opengl;
+ } else if (target_env_str == "opengl4.5") {
+ target_env = shaderc_target_env_opengl;
+ version = shaderc_env_version_opengl_4_5;
} else if (target_env_str == "opengl_compat") {
target_env = shaderc_target_env_opengl_compat;
} else {
@@ -438,7 +464,7 @@
<< std::endl;
return 1;
}
- compiler.options().SetTargetEnvironment(target_env, 0);
+ compiler.options().SetTargetEnvironment(target_env, version);
} else if (arg.starts_with("-mfmt=")) {
const string_piece binary_output_format =
arg.substr(std::strlen("-mfmt="));
@@ -571,7 +597,10 @@
} else if (arg == "-g") {
compiler.options().SetGenerateDebugInfo();
} else if (arg.starts_with("-O")) {
- if (arg == "-Os") {
+ if (arg == "-O") {
+ compiler.options().SetOptimizationLevel(
+ shaderc_optimization_level_performance);
+ } else if (arg == "-Os") {
compiler.options().SetOptimizationLevel(
shaderc_optimization_level_size);
} else if (arg == "-O0") {
diff --git a/glslc/test/assembly.py b/glslc/test/assembly.py
index 54b9dce..4deb310 100644
--- a/glslc/test/assembly.py
+++ b/glslc/test/assembly.py
@@ -21,7 +21,7 @@
return """
; SPIR-V
; Version: 1.0
- ; Generator: Google Shaderc over Glslang; 2
+ ; Generator: Google Shaderc over Glslang; 6
; Bound: 6
; Schema: 0"""
diff --git a/glslc/test/expect.py b/glslc/test/expect.py
index 690dd87..366fdec 100644
--- a/glslc/test/expect.py
+++ b/glslc/test/expect.py
@@ -116,7 +116,7 @@
class CorrectObjectFilePreamble(GlslCTest):
"""Provides methods for verifying preamble for a SPV object file."""
- def verify_object_file_preamble(self, filename):
+ def verify_object_file_preamble(self, filename, spv_version = 0x10000):
"""Checks that the given SPIR-V binary file has correct preamble."""
def read_word(binary, index, little_endian):
@@ -163,11 +163,15 @@
return False, 'Incorrect SPV binary: wrong magic number'
# SPIR-V version number
- if read_word(preamble, 1, little_endian) != 0x00010000:
+ version = read_word(preamble, 1, little_endian)
+ # TODO(dneto): Recent Glslang uses version word 0 for opengl_compat
+ # profile
+
+ if version != spv_version and version != 0:
return False, 'Incorrect SPV binary: wrong version number'
# Shaderc-over-Glslang (0x000d....) or
# SPIRV-Tools (0x0007....) generator number
- if read_word(preamble, 2, little_endian) != 0x000d0002 and \
+ if read_word(preamble, 2, little_endian) != 0x000d0006 and \
read_word(preamble, 2, little_endian) != 0x00070000:
return False, ('Incorrect SPV binary: wrong generator magic '
'number')
@@ -193,15 +197,15 @@
if (line1 != '; SPIR-V\n' or
line2 != '; Version: 1.0\n' or
- line3 != '; Generator: Google Shaderc over Glslang; 2\n'):
+ (not line3.startswith('; Generator: Google Shaderc over Glslang;'))):
return False, 'Incorrect SPV assembly'
return True, ''
class ValidObjectFile(SuccessfulReturn, CorrectObjectFilePreamble):
- """Mixin class for checking that every input file generates a valid object
- file following the object file naming rule, and there is no output on
+ """Mixin class for checking that every input file generates a valid SPIR-V 1.0
+ object file following the object file naming rule, and there is no output on
stdout/stderr."""
def check_object_file_preamble(self, status):
@@ -214,6 +218,22 @@
return True, ''
+class ValidObjectFile1_3(SuccessfulReturn, CorrectObjectFilePreamble):
+ """Mixin class for checking that every input file generates a valid SPIR-V 1.3
+ object file following the object file naming rule, and there is no output on
+ stdout/stderr."""
+
+ def check_object_file_preamble(self, status):
+ for input_filename in status.input_filenames:
+ object_filename = get_object_filename(input_filename)
+ success, message = self.verify_object_file_preamble(
+ os.path.join(status.directory, object_filename),
+ 0x10300)
+ if not success:
+ return False, message
+ return True, ''
+
+
class ValidObjectFileWithAssemblySubstr(SuccessfulReturn, CorrectObjectFilePreamble):
"""Mixin class for checking that every input file generates a valid object
file following the object file naming rule, there is no output on
diff --git a/glslc/test/option_dash_cap_O.py b/glslc/test/option_dash_cap_O.py
index 2a5c0cf..6aa88e3 100644
--- a/glslc/test/option_dash_cap_O.py
+++ b/glslc/test/option_dash_cap_O.py
@@ -23,7 +23,7 @@
ASSEMBLY_WITH_DEBUG = [
'; SPIR-V\n',
'; Version: 1.0\n',
- '; Generator: Google Shaderc over Glslang; 2\n',
+ '; Generator: Google Shaderc over Glslang; 6\n',
'; Bound: 6\n',
'; Schema: 0\n',
' OpCapability Shader\n',
@@ -44,7 +44,7 @@
ASSEMBLY_WITHOUT_DEBUG = [
'; SPIR-V\n',
'; Version: 1.0\n',
- '; Generator: Google Shaderc over Glslang; 2\n',
+ '; Generator: Google Shaderc over Glslang; 6\n',
'; Bound: 6\n',
'; Schema: 0\n',
' OpCapability Shader\n',
@@ -68,6 +68,14 @@
target_filename = 'shader.vert.spvasm'
expected_file_contents = ASSEMBLY_WITH_DEBUG
+@inside_glslc_testsuite('OptionDashCapO')
+class TestDashCapOPerformance(expect.ValidFileContents):
+ """Tests -O works."""
+
+ environment = EMPTY_SHADER_IN_CWD
+ glslc_args = ['-S', '-O', 'shader.vert']
+ target_filename = 'shader.vert.spvasm'
+ expected_file_contents = ASSEMBLY_WITHOUT_DEBUG
@inside_glslc_testsuite('OptionDashCapO')
class TestDashCapOs(expect.ValidFileContents):
diff --git a/glslc/test/option_fauto_bind_uniforms.py b/glslc/test/option_fauto_bind_uniforms.py
index ad2f009..0684e46 100644
--- a/glslc/test/option_fauto_bind_uniforms.py
+++ b/glslc/test/option_fauto_bind_uniforms.py
@@ -40,8 +40,8 @@
SamplerState s1 : register(s1);
SamplerComparisonState s2 : register(s2);
-Texture1D <float2> t1 : register(t11);
-Texture2D <float2> t2 : register(t12);
+Texture1D t1 : register(t11);
+Texture2D <float4> t2 : register(t12);
Texture3D <float2> t3 : register(t13);
StructuredBuffer<float4> t4 : register(t14);
ByteAddressBuffer t5 : register(t15);
@@ -75,18 +75,18 @@
u6[2];
u7;
u8;
- return float4(1.0);
+ return float4(u8.Consume() + t2.SampleCmp(s2, 1.0, 2.0)) + t1.Sample(s1, 1.0)
+ + t6.Load(1);
}
"""
@inside_glslc_testsuite('OptionFAutoBindUniforms')
-class UniformBindingsNotCreatedByDefault(expect.ValidAssemblyFileWithoutSubstr):
- """Tests that the compiler does not generate bindings for uniforms by default."""
+class UniformBindingsNotCreatedByDefault(expect.ErrorMessageSubstr):
+ """Tests that compilation fails when uniforms have no binding."""
shader = FileShader(GLSL_SHADER_WITH_UNIFORMS_WITHOUT_BINDINGS, '.vert')
glslc_args = ['-S', shader]
- # Sufficient to just check one of the uniforms.
- unexpected_assembly_substr = "OpDecorate %my_sam Binding"
+ expected_error_substr = "sampler/texture/image requires layout(binding=X)"
@inside_glslc_testsuite('OptionFAutoBindUniforms')
diff --git a/glslc/test/option_fauto_map_locations.py b/glslc/test/option_fauto_map_locations.py
new file mode 100644
index 0000000..24ef496
--- /dev/null
+++ b/glslc/test/option_fauto_map_locations.py
@@ -0,0 +1,87 @@
+# Copyright 2018 The Shaderc Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import expect
+from glslc_test_framework import inside_glslc_testsuite
+from placeholder import FileShader
+
+# A GLSL shader with inputs and outputs explicit locations.
+GLSL_SHADER_IO_WITHOUT_LOCATIONS = """#version 310 es
+ in vec4 m_in;
+ in vec4 m_in1;
+ out vec4 m_out;
+ out vec4 m_out1;
+ void main() {
+ m_out = m_in;
+ m_out1 = m_in1;
+ }"""
+
+
+# An HLSL fragment shader with inputs and outputs explicit locations.
+HLSL_SHADER_IO_WITHOUT_LOCATIONS = """
+ float4 Foo(float4 a, float4 b) : COLOR0 {
+ return a + b;
+ }"""
+
+
+@inside_glslc_testsuite('OptionFAutoMapLocations')
+class MissingLocationsResultsInError(expect.ErrorMessageSubstr):
+ """Tests that compilation fails when inputs or outputs have no location."""
+
+ shader = FileShader(GLSL_SHADER_IO_WITHOUT_LOCATIONS, '.vert')
+ glslc_args = ['-S', shader]
+ expected_error_substr = "SPIR-V requires location for user input/output"
+
+
+@inside_glslc_testsuite('OptionFAutoMapLocations')
+class FAutoMapLocationsGeneratesLocationsCheckInput(expect.ValidAssemblyFileWithSubstr):
+ """Tests that the compiler generates locations upon request: Input 0"""
+
+ shader = FileShader(GLSL_SHADER_IO_WITHOUT_LOCATIONS, '.vert')
+ glslc_args = ['-S', shader, '-fauto-map-locations']
+ expected_assembly_substr = "OpDecorate %m_in Location 0"
+
+
+@inside_glslc_testsuite('OptionFAutoMapLocations')
+class FAutoMapLocationsGeneratesLocationsCheckOutput0(expect.ValidAssemblyFileWithSubstr):
+ """Tests that the compiler generates locations upon request: Output 0"""
+
+ shader = FileShader(GLSL_SHADER_IO_WITHOUT_LOCATIONS, '.vert')
+ glslc_args = ['-S', shader, '-fauto-map-locations']
+ expected_assembly_substr = "OpDecorate %m_out Location 0"
+
+
+# Currently Glslang only generates Location 0.
+# See https://github.com/KhronosGroup/glslang/issues/1261
+# TODO(dneto): Write tests that check Location 1 is generated for inputs and
+# outputs.
+
+
+# Glslang's HLSL compiler automatically assigns locations inptus and outputs.
+@inside_glslc_testsuite('OptionFAutoMapLocations')
+class HLSLCompilerGeneratesLocationsCheckInput0(expect.ValidAssemblyFileWithSubstr):
+ """Tests that the HLSL compiler generates locations automatically: Input 0."""
+
+ shader = FileShader(HLSL_SHADER_IO_WITHOUT_LOCATIONS, '.hlsl')
+ glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Foo', shader]
+ expected_assembly_substr = "OpDecorate %a Location 0"
+
+
+@inside_glslc_testsuite('OptionFAutoMapLocations')
+class HLSLCompilerGeneratesLocationsCheckOutput(expect.ValidAssemblyFileWithSubstr):
+ """Tests that the HLSL compiler generates locations automatically: Output."""
+
+ shader = FileShader(HLSL_SHADER_IO_WITHOUT_LOCATIONS, '.hlsl')
+ glslc_args = ['-S', '-fshader-stage=frag', '-fentry-point=Foo', shader]
+ expected_assembly_substr = "OpDecorate %_entryPointOutput Location 0"
diff --git a/glslc/test/option_fhlsl_functionality1.py b/glslc/test/option_fhlsl_functionality1.py
new file mode 100644
index 0000000..1e7a65e
--- /dev/null
+++ b/glslc/test/option_fhlsl_functionality1.py
@@ -0,0 +1,63 @@
+# Copyright 2018 The Shaderc Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import expect
+from glslc_test_framework import inside_glslc_testsuite
+from placeholder import FileShader
+
+# An HLSL shader with a counter buffer with a counter increment.
+HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER = """
+RWStructuredBuffer<int> Ainc;
+float4 main() : SV_Target0 {
+ return float4(Ainc.IncrementCounter(), 0, 1, 2);
+}
+"""
+
+
+@inside_glslc_testsuite('OptionFHlslFunctionality1')
+class TestHlslFunctionality1MentionsExtension(expect.ValidAssemblyFileWithSubstr):
+ """Tests that -fhlsl_functionality1 enabled SPV_GOOGLE_hlsl_functionality1."""
+
+ shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag')
+ glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1', shader]
+ expected_assembly_substr = 'OpExtension "SPV_GOOGLE_hlsl_functionality1"'
+
+
+@inside_glslc_testsuite('OptionFHlslFunctionality1')
+class TestHlslFunctionality1DecoratesCounter(expect.ValidAssemblyFileWithSubstr):
+ """Tests that -fhlsl_functionality1 decorates the output target"""
+
+ shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag')
+ glslc_args = ['-S', '-x', 'hlsl', '-fhlsl_functionality1', shader]
+ expected_assembly_substr = 'OpDecorateStringGOOGLE'
+
+
+## Next tests use the option with the hypen instead of underscore.
+
+@inside_glslc_testsuite('OptionFHlslFunctionality1')
+class TestHlslHyphenFunctionality1MentionsExtension(expect.ValidAssemblyFileWithSubstr):
+ """Tests that -fhlsl-functionality1 enabled SPV_GOOGLE_hlsl_functionality1."""
+
+ shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag')
+ glslc_args = ['-S', '-x', 'hlsl', '-fhlsl-functionality1', shader]
+ expected_assembly_substr = 'OpExtension "SPV_GOOGLE_hlsl_functionality1"'
+
+
+@inside_glslc_testsuite('OptionFHlslFunctionality1')
+class TestHlslHyphenFunctionality1DecoratesCounter(expect.ValidAssemblyFileWithSubstr):
+ """Tests that -fhlsl-functionality1 decorates the output target"""
+
+ shader = FileShader(HLSL_VERTEX_SHADER_WITH_COUNTER_BUFFER, '.frag')
+ glslc_args = ['-S', '-x', 'hlsl', '-fhlsl-functionality1', shader]
+ expected_assembly_substr = 'OpDecorateStringGOOGLE'
diff --git a/glslc/test/option_flimit.py b/glslc/test/option_flimit.py
index 0fbfd9d..30a0e02 100644
--- a/glslc/test/option_flimit.py
+++ b/glslc/test/option_flimit.py
@@ -21,8 +21,8 @@
def shader_source_with_tex_offset(offset):
"""Returns a vertex shader using a texture access with the given offset."""
- return """#version 150
- uniform sampler1D tex;
+ return """#version 450
+ layout (binding=0) uniform sampler1D tex;
void main() { vec4 x = textureOffset(tex, 1.0, """ + str(offset) + "); }"
diff --git a/glslc/test/option_fresource_set_binding.py b/glslc/test/option_fresource_set_binding.py
index 3059abd..254004e 100644
--- a/glslc/test/option_fresource_set_binding.py
+++ b/glslc/test/option_fresource_set_binding.py
@@ -22,9 +22,7 @@
Buffer<float4> t5 : register(t5);
float4 main() : SV_Target0 {
- t4[2];
- t5[7];
- return float4(1.0);
+ return float4(t4.Load(0) + t5.Load(1));
}
"""
diff --git a/glslc/test/option_target_env.py b/glslc/test/option_target_env.py
index fe8f5fc..d1620d5 100644
--- a/glslc/test/option_target_env.py
+++ b/glslc/test/option_target_env.py
@@ -35,6 +35,13 @@
void main() { int t = gl_VertexIndex; }"""
+def vulkan_compute_subgroup_shader():
+ """Returns a compute shader that requires Vulkan 1.1"""
+ return """#version 450
+ #extension GL_KHR_shader_subgroup_basic : enable
+ void main() { subgroupBarrier(); }"""
+
+
@inside_glslc_testsuite('OptionTargetEnv')
class TestTargetEnvEqOpenglCompatWithOpenGlCompatShader(expect.ValidObjectFile):
"""Tests that compiling OpenGL Compatibility Fragment shader with
@@ -80,13 +87,53 @@
@inside_glslc_testsuite('OptionTargetEnv')
-class TestTargetEnvEqVulkanWithVulkanShader(expect.ValidObjectFile):
- """Tests that compiling a Vulkan-specific shader succeeds with
+class TestTargetEnvEqVulkanWithVulkan1_0ShaderSucceeds(expect.ValidObjectFile):
+ """Tests that compiling a Vulkan-specific Vulkan 1.0 shader succeeds with
--target-env=vulkan"""
shader = FileShader(vulkan_vertex_shader(), '.vert')
glslc_args = ['--target-env=vulkan', '-c', shader]
+@inside_glslc_testsuite('OptionTargetEnv')
+class TestTargetEnvEqVulkan1_0WithVulkan1_0ShaderSucceeds(expect.ValidObjectFile):
+ """Tests that compiling a Vulkan-specific Vulkan 1.0 shader succeeds with
+ --target-env=vulkan1.0"""
+ shader = FileShader(vulkan_vertex_shader(), '.vert')
+ glslc_args = ['--target-env=vulkan1.0', '-c', shader]
+
+
+@inside_glslc_testsuite('OptionTargetEnv')
+class TestTargetEnvEqVulkan1_0WithVulkan1_1ShaderFails(expect.ErrorMessageSubstr):
+ shader = FileShader(vulkan_compute_subgroup_shader(), '.comp')
+ glslc_args = ['--target-env=vulkan1.0', '-c', shader]
+ expected_error_substr = "error: 'subgroup op' : requires SPIR-V 1.3"
+
+
+@inside_glslc_testsuite('OptionTargetEnv')
+class TestTargetEnvEqVulkan1_1WithVulkan1_0ShaderSucceeds(expect.ValidObjectFile1_3):
+ shader = FileShader(vulkan_vertex_shader(), '.vert')
+ glslc_args = ['--target-env=vulkan1.1', '-c', shader]
+
+
+@inside_glslc_testsuite('OptionTargetEnv')
+class TestTargetEnvEqVulkan1_1WithVulkan1_1ShaderSucceeds(expect.ValidObjectFile1_3):
+ shader = FileShader(vulkan_compute_subgroup_shader(), '.comp')
+ glslc_args = ['--target-env=vulkan1.1', '-c', shader]
+
+
+@inside_glslc_testsuite('OptionTargetEnv')
+class TestTargetEnvEqOpenGL4_5WithOpenGLShaderSucceeds(expect.ValidObjectFile):
+ shader = FileShader(opengl_vertex_shader(), '.vert')
+ glslc_args = ['--target-env=opengl4.5', '-c', shader]
+
+
+@inside_glslc_testsuite('OptionTargetEnv')
+class TestTargetEnvEqOpenGL4_6WithOpenGLShaderFailsUnsupported(expect.ErrorMessageSubstr):
+ shader = FileShader(opengl_vertex_shader(), '.vert')
+ glslc_args = ['--target-env=opengl4.6', '-c', shader]
+ expected_error_substr = "invalid value 'opengl4.6' in '--target-env=opengl4.6'"
+
+
# Note: Negative tests are covered in the libshaderc_util unit tests.
# For example, that an OpenGL-specific shader should fail to compile
# for Vulkan, or a Vulkan-specific shader should fail to compile for
diff --git a/glslc/test/parameter_tests.py b/glslc/test/parameter_tests.py
index 21209a8..21015e9 100644
--- a/glslc/test/parameter_tests.py
+++ b/glslc/test/parameter_tests.py
@@ -61,7 +61,14 @@
Automatically assign bindings to uniform variables that
don't have an explicit 'binding' layout in the shader
source.
+ -fauto-map-locations
+ Automatically assign locations to uniform variables that
+ don't have an explicit 'location' layout in the shader
+ source.
-fhlsl-iomap Use HLSL IO mappings for bindings.
+ -fhlsl_functionality1, -fhlsl-functionality1
+ Enable extension SPV_GOOGLE_hlsl_functionality1 for HLSL
+ compilation.
-fimage-binding-base [stage] <value>
Sets the lowest automatically assigned binding number for
images. Optionally only set it for a single shader stage.
@@ -136,9 +143,14 @@
generation.
-S Only run preprocess and compilation steps.
--target-env=<environment>
- Set the target shader environment, and the semantics
- of warnings and errors. Valid values are 'opengl',
- 'opengl_compat' and 'vulkan'. The default value is 'vulkan'.
+ Set the target client environment, and the semantics
+ of warnings and errors. An optional suffix can specify
+ the client version. Values are:
+ vulkan1.0 # The default
+ vulkan1.1
+ vulkan # Same as vulkan1.0
+ opengl4.5
+ opengl # Same as opengl4.5
-w Suppresses all warning messages.
-Werror Treat all warnings as errors.
-x <language> Treat subsequent input files as having type <language>.
diff --git a/kokoro/android-release/build.sh b/kokoro/android-release/build.sh
new file mode 100644
index 0000000..4a59199
--- /dev/null
+++ b/kokoro/android-release/build.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Android Build Script.
+
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+BUILD_ROOT=$PWD
+SRC=$PWD/github/shaderc
+TARGET_ARCH=$1
+
+# Get NINJA.
+wget -q https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-linux.zip
+unzip -q ninja-linux.zip
+export PATH="$PWD:$PATH"
+export BUILD_NDK=ON
+export ANDROID_NDK=/opt/android-ndk-r15c
+git clone --depth=1 https://github.com/taka-no-me/android-cmake.git android-cmake
+export TOOLCHAIN_PATH=$PWD/android-cmake/android.toolchain.cmake
+
+
+cd $SRC/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
+git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers
+
+cd $SRC/
+mkdir build
+cd $SRC/build
+
+# Invoke the build.
+BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
+echo $(date): Starting build...
+cmake -DRE2_BUILD_TESTING=OFF -GNinja -DCMAKE_BUILD_TYPE=Release -DANDROID_NATIVE_API_LEVEL=android-14 -DANDROID_ABI=$TARGET_ARCH -DSHADERC_SKIP_TESTS=ON -DSPIRV_SKIP_TESTS=ON -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_PATH -DANDROID_NDK=$ANDROID_NDK ..
+
+
+echo $(date): Build glslang...
+ninja glslangValidator
+
+echo $(date): Build everything...
+ninja
+
+echo $(date): Check Shaderc for copyright notices...
+ninja check-copyright
+
+echo $(date): Build completed.
diff --git a/kokoro/android-release/build_arm.sh b/kokoro/android-release/build_arm.sh
new file mode 100644
index 0000000..6d43504
--- /dev/null
+++ b/kokoro/android-release/build_arm.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Android Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh "armeabi-v7a with NEON"
diff --git a/kokoro/android-release/build_x86.sh b/kokoro/android-release/build_x86.sh
new file mode 100644
index 0000000..c642ab1
--- /dev/null
+++ b/kokoro/android-release/build_x86.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Android Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh x86
+
diff --git a/kokoro/android-release/continuous_arm.cfg b/kokoro/android-release/continuous_arm.cfg
new file mode 100644
index 0000000..a4f931a
--- /dev/null
+++ b/kokoro/android-release/continuous_arm.cfg
@@ -0,0 +1,17 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+#
+build_file: "shaderc/kokoro/android-release/build_arm.sh"
diff --git a/kokoro/android-release/continuous_x86.cfg b/kokoro/android-release/continuous_x86.cfg
new file mode 100644
index 0000000..a8643d5
--- /dev/null
+++ b/kokoro/android-release/continuous_x86.cfg
@@ -0,0 +1,17 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+#
+build_file: "shaderc/kokoro/android-release/build_x86.sh"
diff --git a/kokoro/android-release/presubmit_arm.cfg b/kokoro/android-release/presubmit_arm.cfg
new file mode 100644
index 0000000..b88294d
--- /dev/null
+++ b/kokoro/android-release/presubmit_arm.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/android-release/build_arm.sh"
diff --git a/kokoro/android-release/presubmit_x86.cfg b/kokoro/android-release/presubmit_x86.cfg
new file mode 100644
index 0000000..590753e
--- /dev/null
+++ b/kokoro/android-release/presubmit_x86.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/android-release/build_x86.sh"
diff --git a/kokoro/img/linux.png b/kokoro/img/linux.png
new file mode 100644
index 0000000..ff066d9
--- /dev/null
+++ b/kokoro/img/linux.png
Binary files differ
diff --git a/kokoro/img/macos.png b/kokoro/img/macos.png
new file mode 100644
index 0000000..d1349c0
--- /dev/null
+++ b/kokoro/img/macos.png
Binary files differ
diff --git a/kokoro/img/windows.png b/kokoro/img/windows.png
new file mode 100644
index 0000000..a378469
--- /dev/null
+++ b/kokoro/img/windows.png
Binary files differ
diff --git a/kokoro/linux/build.sh b/kokoro/linux/build.sh
new file mode 100644
index 0000000..efff2b0
--- /dev/null
+++ b/kokoro/linux/build.sh
@@ -0,0 +1,110 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+BUILD_ROOT=$PWD
+SRC=$PWD/github/shaderc
+CONFIG=$1
+COMPILER=$2
+
+SKIP_TESTS="False"
+BUILD_TYPE="Debug"
+
+CMAKE_C_CXX_COMPILER=""
+if [ $COMPILER = "clang" ]
+then
+ sudo ln -s /usr/bin/clang-3.8 /usr/bin/clang
+ sudo ln -s /usr/bin/clang++-3.8 /usr/bin/clang++
+ CMAKE_C_CXX_COMPILER="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++"
+fi
+
+# Possible configurations are:
+# ASAN, COVERAGE, RELEASE, DEBUG, DEBUG_EXCEPTION, RELEASE_MINGW
+
+if [ $CONFIG = "RELEASE" ] || [ $CONFIG = "RELEASE_MINGW" ]
+then
+ BUILD_TYPE="RelWithDebInfo"
+fi
+
+ADDITIONAL_CMAKE_FLAGS=""
+if [ $CONFIG = "ASAN" ]
+then
+ ADDITIONAL_CMAKE_FLAGS="-DCMAKE_CXX_FLAGS=-fsanitize=address -DCMAKE_C_FLAGS=-fsanitize=address"
+ export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4
+elif [ $CONFIG = "COVERAGE" ]
+then
+ ADDITIONAL_CMAKE_FLAGS="-DENABLE_CODE_COVERAGE=ON"
+ SKIP_TESTS="True"
+elif [ $CONFIG = "DEBUG_EXCEPTION" ]
+then
+ ADDITIONAL_CMAKE_FLAGS="-DDISABLE_EXCEPTIONS=ON -DDISABLE_RTTI=ON"
+elif [ $CONFIG = "RELEASE_MINGW" ]
+then
+ ADDITIONAL_CMAKE_FLAGS="-Dgtest_disable_pthreads=ON -DCMAKE_TOOLCHAIN_FILE=$SRC/cmake/linux-mingw-toolchain.cmake"
+ SKIP_TESTS="True"
+fi
+
+# Get NINJA.
+wget -q https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-linux.zip
+unzip -q ninja-linux.zip
+export PATH="$PWD:$PATH"
+
+cd $SRC/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
+git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers
+
+cd $SRC/
+mkdir build
+cd $SRC/build
+
+# Invoke the build.
+BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
+echo $(date): Starting build...
+cmake -GNinja -DRE2_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=$BUILD_TYPE $ADDITIONAL_CMAKE_FLAGS $CMAKE_C_CXX_COMPILER ..
+
+echo $(date): Build glslang...
+ninja glslangValidator
+
+echo $(date): Build everything...
+ninja
+echo $(date): Build completed.
+
+echo $(date): Check Shaderc for copyright notices...
+ninja check-copyright
+
+if [ $CONFIG = "COVERAGE" ]
+then
+ echo $(date): Check coverage...
+ ninja report-coverage
+ echo $(date): Check coverage completed.
+fi
+
+echo $(date): Starting ctest...
+if [ $SKIP_TESTS = "False" ]
+then
+ ctest --output-on-failure -j4
+fi
+echo $(date): ctest completed.
+
diff --git a/kokoro/linux/build_clang_asan.sh b/kokoro/linux/build_clang_asan.sh
new file mode 100644
index 0000000..dae3173
--- /dev/null
+++ b/kokoro/linux/build_clang_asan.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh ASAN clang
diff --git a/kokoro/linux/build_clang_debug.sh b/kokoro/linux/build_clang_debug.sh
new file mode 100644
index 0000000..6e045ae
--- /dev/null
+++ b/kokoro/linux/build_clang_debug.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh DEBUG clang
diff --git a/kokoro/linux/build_clang_release.sh b/kokoro/linux/build_clang_release.sh
new file mode 100644
index 0000000..de73841
--- /dev/null
+++ b/kokoro/linux/build_clang_release.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh RELEASE clang
diff --git a/kokoro/linux/build_gcc_coverage.sh b/kokoro/linux/build_gcc_coverage.sh
new file mode 100644
index 0000000..4ee1848
--- /dev/null
+++ b/kokoro/linux/build_gcc_coverage.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh COVERAGE gcc
diff --git a/kokoro/linux/build_gcc_debug.sh b/kokoro/linux/build_gcc_debug.sh
new file mode 100644
index 0000000..23f4819
--- /dev/null
+++ b/kokoro/linux/build_gcc_debug.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh DEBUG gcc
diff --git a/kokoro/linux/build_gcc_debug_exception.sh b/kokoro/linux/build_gcc_debug_exception.sh
new file mode 100644
index 0000000..d2c8e9a
--- /dev/null
+++ b/kokoro/linux/build_gcc_debug_exception.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh DEBUG_EXCEPTION gcc
diff --git a/kokoro/linux/build_gcc_release.sh b/kokoro/linux/build_gcc_release.sh
new file mode 100644
index 0000000..fedc393
--- /dev/null
+++ b/kokoro/linux/build_gcc_release.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh RELEASE gcc
diff --git a/kokoro/linux/build_mingw_release.sh b/kokoro/linux/build_mingw_release.sh
new file mode 100644
index 0000000..0b54dc6
--- /dev/null
+++ b/kokoro/linux/build_mingw_release.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh RELEASE_MINGW
diff --git a/kokoro/linux/continuous_clang_asan.cfg b/kokoro/linux/continuous_clang_asan.cfg
new file mode 100644
index 0000000..1291151
--- /dev/null
+++ b/kokoro/linux/continuous_clang_asan.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/linux/build_clang_asan.sh"
diff --git a/kokoro/linux/continuous_clang_debug.cfg b/kokoro/linux/continuous_clang_debug.cfg
new file mode 100644
index 0000000..8d48ddc
--- /dev/null
+++ b/kokoro/linux/continuous_clang_debug.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/linux/build_clang_debug.sh"
diff --git a/kokoro/linux/continuous_clang_release.cfg b/kokoro/linux/continuous_clang_release.cfg
new file mode 100644
index 0000000..6ba10a3
--- /dev/null
+++ b/kokoro/linux/continuous_clang_release.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/linux/build_clang_release.sh"
diff --git a/kokoro/linux/continuous_gcc_coverage.cfg b/kokoro/linux/continuous_gcc_coverage.cfg
new file mode 100644
index 0000000..ab2878c
--- /dev/null
+++ b/kokoro/linux/continuous_gcc_coverage.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/linux/build_gcc_coverage.sh"
diff --git a/kokoro/linux/continuous_gcc_debug.cfg b/kokoro/linux/continuous_gcc_debug.cfg
new file mode 100644
index 0000000..d74ac3b
--- /dev/null
+++ b/kokoro/linux/continuous_gcc_debug.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/linux/build_gcc_debug.sh"
diff --git a/kokoro/linux/continuous_gcc_debug_exception.cfg b/kokoro/linux/continuous_gcc_debug_exception.cfg
new file mode 100644
index 0000000..cecd155
--- /dev/null
+++ b/kokoro/linux/continuous_gcc_debug_exception.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/linux/build_gcc_debug_exception.sh"
diff --git a/kokoro/linux/continuous_gcc_release.cfg b/kokoro/linux/continuous_gcc_release.cfg
new file mode 100644
index 0000000..55fab2a
--- /dev/null
+++ b/kokoro/linux/continuous_gcc_release.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/linux/build_gcc_release.sh"
diff --git a/kokoro/linux/continuous_mingw_release.cfg b/kokoro/linux/continuous_mingw_release.cfg
new file mode 100644
index 0000000..a0d4e76
--- /dev/null
+++ b/kokoro/linux/continuous_mingw_release.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/linux/build_mingw_release.sh"
diff --git a/kokoro/linux/presubmit_clang_debug.cfg b/kokoro/linux/presubmit_clang_debug.cfg
new file mode 100644
index 0000000..87abaf7
--- /dev/null
+++ b/kokoro/linux/presubmit_clang_debug.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/linux/build_clang_debug.sh"
diff --git a/kokoro/linux/presubmit_clang_release.cfg b/kokoro/linux/presubmit_clang_release.cfg
new file mode 100644
index 0000000..81ba77d
--- /dev/null
+++ b/kokoro/linux/presubmit_clang_release.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/linux/build_clang_release.sh"
diff --git a/kokoro/linux/presubmit_gcc_coverage.cfg b/kokoro/linux/presubmit_gcc_coverage.cfg
new file mode 100644
index 0000000..54733b0
--- /dev/null
+++ b/kokoro/linux/presubmit_gcc_coverage.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/linux/build_gcc_coverage.sh"
diff --git a/kokoro/linux/presubmit_gcc_debug.cfg b/kokoro/linux/presubmit_gcc_debug.cfg
new file mode 100644
index 0000000..f0eec27
--- /dev/null
+++ b/kokoro/linux/presubmit_gcc_debug.cfg
@@ -0,0 +1,17 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/linux/build_gcc_debug.sh"
+
diff --git a/kokoro/linux/presubmit_gcc_release.cfg b/kokoro/linux/presubmit_gcc_release.cfg
new file mode 100644
index 0000000..fda4333
--- /dev/null
+++ b/kokoro/linux/presubmit_gcc_release.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/linux/build_gcc_release.sh"
diff --git a/kokoro/macos/build.sh b/kokoro/macos/build.sh
new file mode 100644
index 0000000..c379911
--- /dev/null
+++ b/kokoro/macos/build.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# MacOS Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+BUILD_ROOT=$PWD
+SRC=$PWD/github/shaderc
+BUILD_TYPE=$1
+
+# Get NINJA.
+wget -q https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-mac.zip
+unzip -q ninja-mac.zip
+chmod +x ninja
+export PATH="$PWD:$PATH"
+
+cd $SRC/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
+git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers
+
+cd $SRC/
+mkdir build
+cd $SRC/build
+
+# Invoke the build.
+BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
+echo $(date): Starting build...
+cmake -GNinja -DRE2_BUILD_TESTING=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
+
+echo $(date): Build glslang...
+ninja glslangValidator
+
+echo $(date): Build everything...
+ninja
+
+echo $(date): Check Shaderc for copyright notices...
+ninja check-copyright
+
+echo $(date): Build completed.
+
+echo $(date): Starting ctest...
+ctest --output-on-failure -j4
+echo $(date): ctest completed.
+
diff --git a/kokoro/macos/build_clang_debug.sh b/kokoro/macos/build_clang_debug.sh
new file mode 100644
index 0000000..ed889ff
--- /dev/null
+++ b/kokoro/macos/build_clang_debug.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# MacOS Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh Debug
+
diff --git a/kokoro/macos/build_clang_release.sh b/kokoro/macos/build_clang_release.sh
new file mode 100644
index 0000000..9599bac
--- /dev/null
+++ b/kokoro/macos/build_clang_release.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# MacOS Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh RelWithDebInfo
+
diff --git a/kokoro/macos/continuous_clang_debug.cfg b/kokoro/macos/continuous_clang_debug.cfg
new file mode 100644
index 0000000..7fb261c
--- /dev/null
+++ b/kokoro/macos/continuous_clang_debug.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/macos/build_clang_debug.sh"
diff --git a/kokoro/macos/continuous_clang_release.cfg b/kokoro/macos/continuous_clang_release.cfg
new file mode 100644
index 0000000..85ad377
--- /dev/null
+++ b/kokoro/macos/continuous_clang_release.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/macos/build_clang_release.sh"
diff --git a/kokoro/macos/presubmit_clang_debug.cfg b/kokoro/macos/presubmit_clang_debug.cfg
new file mode 100644
index 0000000..d2748ae
--- /dev/null
+++ b/kokoro/macos/presubmit_clang_debug.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/macos/build_clang_debug.sh"
diff --git a/kokoro/macos/presubmit_clang_release.cfg b/kokoro/macos/presubmit_clang_release.cfg
new file mode 100644
index 0000000..3041155
--- /dev/null
+++ b/kokoro/macos/presubmit_clang_release.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/macos/build_clang_release.sh"
diff --git a/kokoro/ndk-build/build.sh b/kokoro/ndk-build/build.sh
new file mode 100644
index 0000000..4b3b97e
--- /dev/null
+++ b/kokoro/ndk-build/build.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+BUILD_ROOT=$PWD
+SRC=$PWD/github/shaderc
+
+# Set the glslang repo URL.
+GLSLANG_REMOTE=$1
+GLSLANG_REPO_URL="https://github.com/google/glslang.git"
+if [ $GLSLANG_REMOTE = "KHRONOS" ]
+then
+ GLSLANG_REPO_URL="https://github.com/KhronosGroup/glslang.git"
+fi
+
+# Get NINJA.
+wget -q https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-linux.zip
+unzip -q ninja-linux.zip
+export PATH="$PWD:$PATH"
+
+# NDK Path
+export ANDROID_NDK=/opt/android-ndk-r15c
+
+# Get shaderc dependencies.
+cd $SRC/third_party
+git clone $GLSLANG_REPO_URL
+git clone https://github.com/google/googletest.git
+git clone https://github.com/KhronosGroup/SPIRV-Tools.git spirv-tools
+git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-tools/external/spirv-headers
+
+cd $SRC/
+mkdir build
+cd $SRC/build
+
+# Invoke the build.
+BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
+echo $(date): Starting ndk-build ...
+$ANDROID_NDK/ndk-build \
+ -C $SRC/android_test \
+ NDK_APP_OUT=`pwd` \
+ V=1 \
+ SPVTOOLS_LOCAL_PATH=$SRC/third_party/spirv-tools \
+ SPVHEADERS_LOCAL_PATH=$SRC/third_party/spirv-tools/external/spirv-headers \
+ -j 8
+
+echo $(date): ndk-build completed.
+
diff --git a/kokoro/ndk-build/build_google.sh b/kokoro/ndk-build/build_google.sh
new file mode 100644
index 0000000..e2be8eb
--- /dev/null
+++ b/kokoro/ndk-build/build_google.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh GOOGLE
diff --git a/kokoro/ndk-build/build_khronos.sh b/kokoro/ndk-build/build_khronos.sh
new file mode 100644
index 0000000..ce1adf8
--- /dev/null
+++ b/kokoro/ndk-build/build_khronos.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Linux Build Script.
+
+# Fail on any error.
+set -e
+# Display commands being run.
+set -x
+
+SCRIPT_DIR=`dirname "$BASH_SOURCE"`
+source $SCRIPT_DIR/build.sh KHRONOS
diff --git a/kokoro/ndk-build/continuous_google.cfg b/kokoro/ndk-build/continuous_google.cfg
new file mode 100644
index 0000000..ea86d05
--- /dev/null
+++ b/kokoro/ndk-build/continuous_google.cfg
@@ -0,0 +1,17 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+#
+build_file: "shaderc/kokoro/ndk-build/build_google.sh"
diff --git a/kokoro/ndk-build/continuous_khronos.cfg b/kokoro/ndk-build/continuous_khronos.cfg
new file mode 100644
index 0000000..4821383
--- /dev/null
+++ b/kokoro/ndk-build/continuous_khronos.cfg
@@ -0,0 +1,17 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+#
+build_file: "shaderc/kokoro/ndk-build/build_khronos.sh"
diff --git a/kokoro/windows/build.bat b/kokoro/windows/build.bat
new file mode 100644
index 0000000..0358007
--- /dev/null
+++ b/kokoro/windows/build.bat
@@ -0,0 +1,77 @@
+:: Copyright (C) 2017 Google Inc.
+::
+:: Licensed under the Apache License, Version 2.0 (the "License");
+:: you may not use this file except in compliance with the License.
+:: You may obtain a copy of the License at
+::
+:: http://www.apache.org/licenses/LICENSE-2.0
+::
+:: Unless required by applicable law or agreed to in writing, software
+:: distributed under the License is distributed on an "AS IS" BASIS,
+:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+:: See the License for the specific language governing permissions and
+:: limitations under the License.
+::
+:: Windows Build Script.
+
+@echo on
+
+set BUILD_ROOT=%cd%
+set SRC=%cd%\github\shaderc
+set BUILD_TYPE=%1
+
+:: Force usage of python 2.7 rather than 3.6
+set PATH=C:\python27;%PATH%
+
+cd %SRC%\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
+git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers
+
+cd %SRC%
+mkdir build
+cd %SRC%\build
+
+:: set up msvc build env
+call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
+
+:: #########################################
+:: Start building.
+:: #########################################
+echo "Starting build... %DATE% %TIME%"
+if "%KOKORO_GITHUB_COMMIT%." == "." (
+ set BUILD_SHA=%KOKORO_GITHUB_PULL_REQUEST_COMMIT%
+) else (
+ set BUILD_SHA=%KOKORO_GITHUB_COMMIT%
+)
+cmake -DRE2_BUILD_TESTING=OFF -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe" -GNinja -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ..
+if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
+
+echo "Build glslang... %DATE% %TIME%"
+ninja glslangValidator
+if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
+
+echo "Build everything... %DATE% %TIME%"
+ninja
+if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
+
+echo "Check Shaderc for copyright notices... %DATE% %TIME%"
+ninja check-copyright
+if %ERRORLEVEL% GEQ 1 exit /b %ERRORLEVEL%
+echo "Build Completed %DATE% %TIME%"
+
+:: #########################################
+:: Run the tests.
+:: #########################################
+echo "Running Tests... %DATE% %TIME%"
+ctest -C %BUILD_TYPE% --output-on-failure -j4
+echo "Tests Completed %DATE% %TIME%"
+
+:: Clean up some directories.
+rm -rf %SRC%\build
+rm -rf %SRC%\third_party
+
+
+exit /b %ERRORLEVEL%
+
diff --git a/kokoro/windows/build_debug.bat b/kokoro/windows/build_debug.bat
new file mode 100644
index 0000000..2abeaf6
--- /dev/null
+++ b/kokoro/windows/build_debug.bat
@@ -0,0 +1,23 @@
+:: Copyright (C) 2017 Google Inc.
+::
+:: Licensed under the Apache License, Version 2.0 (the "License");
+:: you may not use this file except in compliance with the License.
+:: You may obtain a copy of the License at
+::
+:: http://www.apache.org/licenses/LICENSE-2.0
+::
+:: Unless required by applicable law or agreed to in writing, software
+:: distributed under the License is distributed on an "AS IS" BASIS,
+:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+:: See the License for the specific language governing permissions and
+:: limitations under the License.
+::
+:: Windows Build Script.
+
+@echo on
+
+:: Find out the directory of the common build script.
+set SCRIPT_DIR=%~dp0
+
+:: Call with correct parameter
+call %SCRIPT_DIR%\build.bat Debug
diff --git a/kokoro/windows/build_release.bat b/kokoro/windows/build_release.bat
new file mode 100644
index 0000000..fd528f4
--- /dev/null
+++ b/kokoro/windows/build_release.bat
@@ -0,0 +1,24 @@
+:: Copyright (C) 2017 Google Inc.
+::
+:: Licensed under the Apache License, Version 2.0 (the "License");
+:: you may not use this file except in compliance with the License.
+:: You may obtain a copy of the License at
+::
+:: http://www.apache.org/licenses/LICENSE-2.0
+::
+:: Unless required by applicable law or agreed to in writing, software
+:: distributed under the License is distributed on an "AS IS" BASIS,
+:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+:: See the License for the specific language governing permissions and
+:: limitations under the License.
+::
+:: Windows Build Script.
+
+@echo on
+
+:: Find out the directory of the common build script.
+set SCRIPT_DIR=%~dp0
+
+:: Call with correct parameter
+call %SCRIPT_DIR%\build.bat RelWithDebInfo
+
diff --git a/kokoro/windows/continuous_debug.cfg b/kokoro/windows/continuous_debug.cfg
new file mode 100644
index 0000000..fc04c6b
--- /dev/null
+++ b/kokoro/windows/continuous_debug.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/windows/build_debug.bat"
diff --git a/kokoro/windows/continuous_release.cfg b/kokoro/windows/continuous_release.cfg
new file mode 100644
index 0000000..d086347
--- /dev/null
+++ b/kokoro/windows/continuous_release.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Continuous build configuration.
+build_file: "shaderc/kokoro/windows/build_release.bat"
diff --git a/kokoro/windows/presubmit_debug.cfg b/kokoro/windows/presubmit_debug.cfg
new file mode 100644
index 0000000..853f3cc
--- /dev/null
+++ b/kokoro/windows/presubmit_debug.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/windows/build_debug.bat"
diff --git a/kokoro/windows/presubmit_release.cfg b/kokoro/windows/presubmit_release.cfg
new file mode 100644
index 0000000..d3917d4
--- /dev/null
+++ b/kokoro/windows/presubmit_release.cfg
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Presubmit build configuration.
+build_file: "shaderc/kokoro/windows/build_release.bat"
diff --git a/libshaderc/CMakeLists.txt b/libshaderc/CMakeLists.txt
index 2a5372d..14da8ce 100644
--- a/libshaderc/CMakeLists.txt
+++ b/libshaderc/CMakeLists.txt
@@ -32,6 +32,7 @@
install(TARGETS shaderc shaderc_shared
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(SHADERC_ENABLE_INSTALL)
diff --git a/libshaderc/include/shaderc/shaderc.h b/libshaderc/include/shaderc/shaderc.h
index d24e67d..093bb12 100644
--- a/libshaderc/include/shaderc/shaderc.h
+++ b/libshaderc/include/shaderc/shaderc.h
@@ -80,8 +80,10 @@
} shaderc_shader_kind;
typedef enum {
- shaderc_target_env_vulkan, // create SPIR-V under Vulkan semantics
- shaderc_target_env_opengl, // create SPIR-V under OpenGL semantics
+ shaderc_target_env_vulkan, // create SPIR-V under Vulkan semantics
+ shaderc_target_env_opengl, // create SPIR-V under OpenGL semantics
+ // NOTE: SPIR-V code generation is not supported for shaders under OpenGL
+ // compatibility profile.
shaderc_target_env_opengl_compat, // create SPIR-V under OpenGL semantics,
// including compatibility profile
// functions
@@ -89,6 +91,18 @@
} shaderc_target_env;
typedef enum {
+ // For Vulkan, use Vulkan's mapping of version numbers to integers.
+ // See vulkan.h
+ shaderc_env_version_vulkan_1_0 = (((uint32_t)1 << 22)),
+ shaderc_env_version_vulkan_1_1 = (((uint32_t)1 << 22) | (1 << 12)),
+ // For OpenGL, use the number from #version in shaders.
+ // TODO(dneto): Currently no difference between OpenGL 4.5 and 4.6.
+ // See glslang/Standalone/Standalone.cpp
+ // TODO(dneto): Glslang doesn't accept a OpenGL client version of 460.
+ shaderc_env_version_opengl_4_5 = 450,
+} shaderc_env_version;
+
+typedef enum {
shaderc_profile_none, // Used if and only if GLSL version did not specify
// profiles.
shaderc_profile_core,
@@ -110,6 +124,7 @@
typedef enum {
shaderc_optimization_level_zero, // no optimization
shaderc_optimization_level_size, // optimize towards reducing code size
+ shaderc_optimization_level_performance, // optimize towards performance
} shaderc_optimization_level;
// Resource limits.
@@ -383,7 +398,9 @@
// Sets the target shader environment, affecting which warnings or errors will
// be issued. The version will be for distinguishing between different versions
-// of the target environment. "0" is the only supported version at this point
+// of the target environment. The version value should be either 0 or
+// a value listed in shaderc_env_version. The 0 value maps to Vulkan 1.0 if
+// |target| is Vulkan, and it maps to OpenGL 4.5 if |target| is OpenGL.
SHADERC_EXPORT void shaderc_compile_options_set_target_env(
shaderc_compile_options_t options,
shaderc_target_env target,
@@ -432,6 +449,11 @@
shaderc_compile_options_t options, shaderc_shader_kind shader_kind,
shaderc_uniform_kind kind, uint32_t base);
+// Sets whether the compiler should automatically assign locations to
+// uniform variables that don't have explicit locations in the shader source.
+SHADERC_EXPORT void shaderc_compile_options_set_auto_map_locations(
+ shaderc_compile_options_t options, bool auto_map);
+
// Sets a descriptor set and binding for an HLSL register in the given stage.
// This method keeps a copy of the string data.
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage(
@@ -444,6 +466,11 @@
shaderc_compile_options_t options, const char* reg, const char* set,
const char* binding);
+// Sets whether the compiler should enable extension
+// SPV_GOOGLE_hlsl_functionality1.
+SHADERC_EXPORT void shaderc_compile_options_set_hlsl_functionality1(
+ shaderc_compile_options_t options, bool enable);
+
// An opaque handle to the results of a call to any shaderc_compile_into_*()
// function.
typedef struct shaderc_compilation_result* shaderc_compilation_result_t;
diff --git a/libshaderc/include/shaderc/shaderc.hpp b/libshaderc/include/shaderc/shaderc.hpp
index 1c55743..964d1aa 100644
--- a/libshaderc/include/shaderc/shaderc.hpp
+++ b/libshaderc/include/shaderc/shaderc.hpp
@@ -180,6 +180,8 @@
// Handles shaderc_include_result_release_fn callbacks.
virtual void ReleaseInclude(shaderc_include_result* data) = 0;
+
+ virtual ~IncluderInterface() = default;
};
// Sets the includer instance for libshaderc to call during compilation, as
@@ -227,10 +229,10 @@
}
// Sets the target shader environment, affecting which warnings or errors will
- // be issued.
- // The version will be for distinguishing between different versions of the
- // target environment.
- // "0" is the only supported version at this point
+ // be issued. The version will be for distinguishing between different
+ // versions of the target environment. The version value should be either 0
+ // or a value listed in shaderc_env_version. The 0 value maps to Vulkan 1.0
+ // if |target| is Vulkan, and it maps to OpenGL 4.5 if |target| is OpenGL.
void SetTargetEnvironment(shaderc_target_env target, uint32_t version) {
shaderc_compile_options_set_target_env(options_, target, version);
}
@@ -284,6 +286,12 @@
kind, base);
}
+ // Sets whether the compiler automatically assigns locations to
+ // uniform variables that don't have explicit locations.
+ void SetAutoMapLocations(bool auto_map) {
+ shaderc_compile_options_set_auto_map_locations(options_, auto_map);
+ }
+
// Sets a descriptor set and binding for an HLSL register in the given stage.
// Copies the parameter strings.
void SetHlslRegisterSetAndBindingForStage(shaderc_shader_kind shader_kind,
@@ -303,6 +311,12 @@
options_, reg.c_str(), set.c_str(), binding.c_str());
}
+ // Sets whether the compiler should enable extension
+ // SPV_GOOGLE_hlsl_functionality1.
+ void SetHlslFunctionality1(bool enable) {
+ shaderc_compile_options_set_hlsl_functionality1(options_, enable);
+ }
+
private:
CompileOptions& operator=(const CompileOptions& other) = delete;
shaderc_compile_options_t options_;
diff --git a/libshaderc/src/common_shaders_for_test.h b/libshaderc/src/common_shaders_for_test.h
index 8ecf1f9..b4bccf2 100644
--- a/libshaderc/src/common_shaders_for_test.h
+++ b/libshaderc/src/common_shaders_for_test.h
@@ -189,7 +189,7 @@
const char* kMinimalShaderDisassemblySubstrings[] = {
"; SPIR-V\n"
"; Version: 1.0\n"
- "; Generator: Google Shaderc over Glslang; 2\n"
+ "; Generator: Google Shaderc over Glslang; 6\n"
"; Bound:",
" OpCapability Shader\n",
@@ -201,7 +201,7 @@
const char kMinimalShaderAssembly[] = R"(
; SPIR-V
; Version: 1.0
- ; Generator: Google Shaderc over Glslang; 2
+ ; Generator: Google Shaderc over Glslang; 6
; Bound: 6
; Schema: 0
@@ -245,9 +245,31 @@
R"(Buffer<float> t4 : register(t4);
Buffer<float> t5 : register(t5);
float4 main() : SV_Target0 {
- t4;
- t5;
- return float4(1.0);
+ return float4(t4.Load(0) + t5.Load(1));
+ })";
+
+// A GLSL compute shader using a regular barrier.
+const char kGlslShaderComputeBarrier[] =
+ R"(#version 450
+ void main() { barrier(); })";
+
+// A GLSL compute shader using the Subgroups feature.
+const char kGlslShaderComputeSubgroupBarrier[] =
+ R"(#version 450
+ #extension GL_KHR_shader_subgroup_basic : enable
+ void main() { subgroupBarrier(); })";
+
+const char kGlslMultipleFnShader[] =
+ R"(#version 450
+ layout(location=0) flat in int inVal;
+ layout(location=0) out int outVal;
+ int foo(int a) { return a; }
+ void main() { outVal = foo(inVal); })";
+
+const char kHlslShaderWithCounterBuffer[] =
+ R"(RWStructuredBuffer<uint> Ainc;
+ float4 main() : SV_Target0 {
+ return float4(Ainc.IncrementCounter(), 0, 0, 0);
})";
#ifdef __cplusplus
diff --git a/libshaderc/src/shaderc.cc b/libshaderc/src/shaderc.cc
index 38836b1..17b4c17 100644
--- a/libshaderc/src/shaderc.cc
+++ b/libshaderc/src/shaderc.cc
@@ -240,8 +240,9 @@
// Returns the Compiler::Limit enum for the given shaderc_limit enum.
shaderc_util::Compiler::Limit CompilerLimit(shaderc_limit limit) {
switch (limit) {
-#define RESOURCE(NAME,FIELD,CNAME) \
- case shaderc_limit_##CNAME: return shaderc_util::Compiler::Limit::NAME;
+#define RESOURCE(NAME, FIELD, CNAME) \
+ case shaderc_limit_##CNAME: \
+ return shaderc_util::Compiler::Limit::NAME;
#include "libshaderc_util/resources.inc"
#undef RESOURCE
default:
@@ -293,11 +294,11 @@
return static_cast<shaderc_util::Compiler::Stage>(0);
}
-
} // anonymous namespace
struct shaderc_compile_options {
shaderc_target_env target_env = shaderc_target_env_default;
+ uint32_t target_env_version = 0;
shaderc_util::Compiler compiler;
shaderc_include_resolve_fn include_resolver = nullptr;
shaderc_include_result_release_fn include_result_releaser = nullptr;
@@ -327,8 +328,7 @@
}
void shaderc_compile_options_set_source_language(
- shaderc_compile_options_t options,
- shaderc_source_language set_lang) {
+ shaderc_compile_options_t options, shaderc_source_language set_lang) {
auto lang = shaderc_util::Compiler::SourceLanguage::GLSL;
if (set_lang == shaderc_source_language_hlsl)
lang = shaderc_util::Compiler::SourceLanguage::HLSL;
@@ -347,6 +347,9 @@
case shaderc_optimization_level_size:
opt_level = shaderc_util::Compiler::OptimizationLevel::Size;
break;
+ case shaderc_optimization_level_performance:
+ opt_level = shaderc_util::Compiler::OptimizationLevel::Performance;
+ break;
default:
break;
}
@@ -391,10 +394,8 @@
void shaderc_compile_options_set_target_env(shaderc_compile_options_t options,
shaderc_target_env target,
uint32_t version) {
- // "version" reserved for future use, intended to distinguish between
- // different versions of a target environment
options->target_env = target;
- options->compiler.SetTargetEnv(GetCompilerTargetEnv(target));
+ options->compiler.SetTargetEnv(GetCompilerTargetEnv(target), version);
}
void shaderc_compile_options_set_warnings_as_errors(
@@ -402,8 +403,8 @@
options->compiler.SetWarningsAsErrors();
}
-void shaderc_compile_options_set_limit(
- shaderc_compile_options_t options, shaderc_limit limit, int value) {
+void shaderc_compile_options_set_limit(shaderc_compile_options_t options,
+ shaderc_limit limit, int value) {
options->compiler.SetLimit(CompilerLimit(limit), value);
}
@@ -417,8 +418,8 @@
options->compiler.SetHlslIoMapping(hlsl_iomap);
}
-void shaderc_compile_options_set_hlsl_offsets(
- shaderc_compile_options_t options, bool hlsl_offsets) {
+void shaderc_compile_options_set_hlsl_offsets(shaderc_compile_options_t options,
+ bool hlsl_offsets) {
options->compiler.SetHlslOffsets(hlsl_offsets);
}
@@ -435,6 +436,11 @@
GetUniformKind(kind), base);
}
+void shaderc_compile_options_set_auto_map_locations(
+ shaderc_compile_options_t options, bool auto_map) {
+ options->compiler.SetAutoMapLocations(auto_map);
+}
+
void shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage(
shaderc_compile_options_t options, shaderc_shader_kind shader_kind,
const char* reg, const char* set, const char* binding) {
@@ -448,6 +454,11 @@
options->compiler.SetHlslRegisterSetAndBinding(reg, set, binding);
}
+void shaderc_compile_options_set_hlsl_functionality1(
+ shaderc_compile_options_t options, bool enable) {
+ options->compiler.EnableHlslFunctionality1(enable);
+}
+
shaderc_compiler_t shaderc_compiler_initialize() {
static shaderc_util::GlslangInitializer* initializer =
new shaderc_util::GlslangInitializer;
diff --git a/libshaderc/src/shaderc_cpp_test.cc b/libshaderc/src/shaderc_cpp_test.cc
index 07d3b94..e61c241 100644
--- a/libshaderc/src/shaderc_cpp_test.cc
+++ b/libshaderc/src/shaderc_cpp_test.cc
@@ -27,9 +27,9 @@
namespace {
using shaderc::AssemblyCompilationResult;
+using shaderc::CompileOptions;
using shaderc::PreprocessedSourceCompilationResult;
using shaderc::SpvCompilationResult;
-using shaderc::CompileOptions;
using testing::Each;
using testing::Eq;
using testing::HasSubstr;
@@ -506,6 +506,14 @@
EXPECT_THAT(disassembly_text, HasSubstr("OpSource"));
}
+TEST_F(CppInterface, CompileAndOptimizeWithLevelPerformance) {
+ options_.SetOptimizationLevel(shaderc_optimization_level_performance);
+ const std::string disassembly_text = AssemblyOutput(
+ kGlslMultipleFnShader, shaderc_glsl_fragment_shader, options_);
+ // Check that we do not have function calls anymore.
+ EXPECT_THAT(disassembly_text, Not(HasSubstr("OpFunctionCall")));
+}
+
TEST_F(CppInterface, CompileAndOptimizeWithLevelSize) {
options_.SetOptimizationLevel(shaderc_optimization_level_size);
const std::string disassembly_text =
@@ -980,19 +988,76 @@
Eq("shader: error: version not supported\n"));
}
-TEST_F(CppInterface, TargetEnvCompileOptions) {
- // Test shader compilation which requires opengl compatibility environment
+TEST_F(CppInterface, TargetEnvCompileOptionsOpenGLCompatibilityShadersFail) {
+ // Glslang does not support SPIR-V code generation for OpenGL compatibility
+ // profile.
options_.SetTargetEnvironment(shaderc_target_env_opengl_compat, 0);
const std::string kGlslShader =
- R"(#version 100
+ R"(#version 150 compatibility
uniform highp sampler2D tex;
void main() {
gl_FragColor = texture2D(tex, vec2(0.0,0.0));
}
)";
- EXPECT_TRUE(
- CompilationSuccess(kGlslShader, shaderc_glsl_fragment_shader, options_));
+ EXPECT_THAT(
+ CompilationErrors(kGlslShader, shaderc_glsl_fragment_shader, options_),
+ HasSubstr(
+ "compilation for SPIR-V does not support the compatibility profile"));
+}
+
+std::string BarrierComputeShader() {
+ return R"(#version 450
+ void main() { barrier(); })";
+};
+
+std::string SubgroupBarrierComputeShader() {
+ return R"(#version 450
+ #extension GL_KHR_shader_subgroup_basic : enable
+ void main() { subgroupBarrier(); })";
+};
+
+TEST_F(CppInterface, TargetEnvCompileOptionsVulkanEnvVulkan1_0ShaderSucceeds) {
+ options_.SetTargetEnvironment(shaderc_target_env_vulkan, 0);
+ EXPECT_TRUE(CompilationSuccess(BarrierComputeShader(),
+ shaderc_glsl_compute_shader, options_));
+}
+
+TEST_F(CppInterface, TargetEnvCompileOptionsVulkanEnvVulkan1_0ShaderFails) {
+ options_.SetTargetEnvironment(shaderc_target_env_vulkan, 0);
+ EXPECT_FALSE(CompilationSuccess(SubgroupBarrierComputeShader(),
+ shaderc_glsl_compute_shader, options_));
+}
+
+TEST_F(CppInterface,
+ TargetEnvCompileOptionsVulkan1_0EnvVulkan1_0ShaderSucceeds) {
+ options_.SetTargetEnvironment(shaderc_target_env_vulkan,
+ shaderc_env_version_vulkan_1_0);
+ EXPECT_TRUE(CompilationSuccess(BarrierComputeShader(),
+ shaderc_glsl_compute_shader, options_));
+}
+
+TEST_F(CppInterface, TargetEnvCompileOptionsVulkan1_0EnvVulkan1_1ShaderFails) {
+ options_.SetTargetEnvironment(shaderc_target_env_vulkan,
+ shaderc_env_version_vulkan_1_0);
+ EXPECT_FALSE(CompilationSuccess(SubgroupBarrierComputeShader(),
+ shaderc_glsl_compute_shader, options_));
+}
+
+TEST_F(CppInterface,
+ TargetEnvCompileOptionsVulkan1_1EnvVulkan1_0ShaderSucceeds) {
+ options_.SetTargetEnvironment(shaderc_target_env_vulkan,
+ shaderc_env_version_vulkan_1_1);
+ EXPECT_TRUE(CompilationSuccess(BarrierComputeShader(),
+ shaderc_glsl_compute_shader, options_));
+}
+
+TEST_F(CppInterface,
+ TargetEnvCompileOptionsVulkan1_1EnvVulkan1_1ShaderSucceeds) {
+ options_.SetTargetEnvironment(shaderc_target_env_vulkan,
+ shaderc_env_version_vulkan_1_1);
+ EXPECT_TRUE(CompilationSuccess(SubgroupBarrierComputeShader(),
+ shaderc_glsl_compute_shader, options_));
}
TEST_F(CppInterface, BeginAndEndOnSpvCompilationResult) {
@@ -1121,10 +1186,10 @@
// offset.
std::string ShaderWithTexOffset(int offset) {
std::ostringstream oss;
- oss <<
- "#version 150\n"
- "uniform sampler1D tex;\n"
- "void main() { vec4 x = textureOffset(tex, 1.0, " << offset << "); }\n";
+ oss << "#version 450\n"
+ "layout (binding=0) uniform sampler1D tex;\n"
+ "void main() { vec4 x = textureOffset(tex, 1.0, "
+ << offset << "); }\n";
return oss.str();
}
@@ -1165,24 +1230,12 @@
options_));
}
-TEST_F(CppInterface, UniformsWithoutBindingsHaveNoBindingsByDefault) {
+TEST_F(CppInterface, UniformsWithoutBindingsFailCompilation) {
CompileOptions options;
- const std::string disassembly_text = AssemblyOutput(
+ const std::string errors = CompilationErrors(
kShaderWithUniformsWithoutBindings, shaderc_glsl_vertex_shader, options);
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_tex Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_sam Binding")));
-}
-
-TEST_F(CppInterface, UniformsWithoutBindingsOptionSetNoBindingsHaveNoBindings) {
- CompileOptions options;
- options.SetAutoBindUniforms(false);
- const std::string disassembly_text = AssemblyOutput(
- kShaderWithUniformsWithoutBindings, shaderc_glsl_vertex_shader, options);
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_tex Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_sam Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_img Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_imbuf Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_ubo Binding")));
+ EXPECT_THAT(errors,
+ HasSubstr("sampler/texture/image requires layout(binding=X)"));
}
TEST_F(CppInterface,
@@ -1268,28 +1321,11 @@
EXPECT_THAT(disassembly_text, HasSubstr("OpDecorate %my_ubo Binding 70"));
}
-TEST_F(CppInterface, SetBindingBaseIgnoredWhenNotAutoBinding) {
- CompileOptions options;
- options.SetAutoBindUniforms(false);
- options.SetBindingBase(shaderc_uniform_kind_texture, 40);
- options.SetBindingBase(shaderc_uniform_kind_sampler, 50);
- options.SetBindingBase(shaderc_uniform_kind_image, 60);
- options.SetBindingBase(shaderc_uniform_kind_buffer, 70);
- const std::string disassembly_text = AssemblyOutput(
- kShaderWithUniformsWithoutBindings, shaderc_glsl_vertex_shader, options);
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_tex Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_sam Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_img Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_imbuf Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_ubo Binding")));
-}
-
TEST_F(CppInterface, GlslDefaultPackingUsed) {
CompileOptions options;
const std::string disassembly_text = AssemblyOutput(
kGlslShaderWeirdPacking, shaderc_glsl_vertex_shader, options);
- EXPECT_THAT(disassembly_text,
- HasSubstr("OpMemberDecorate %B 1 Offset 16"));
+ EXPECT_THAT(disassembly_text, HasSubstr("OpMemberDecorate %B 1 Offset 16"));
}
TEST_F(CppInterface, HlslOffsetsOptionDisableRespected) {
@@ -1297,8 +1333,7 @@
options.SetHlslOffsets(false);
const std::string disassembly_text = AssemblyOutput(
kGlslShaderWeirdPacking, shaderc_glsl_vertex_shader, options);
- EXPECT_THAT(disassembly_text,
- HasSubstr("OpMemberDecorate %B 1 Offset 16"));
+ EXPECT_THAT(disassembly_text, HasSubstr("OpMemberDecorate %B 1 Offset 16"));
}
TEST_F(CppInterface, HlslOffsetsOptionEnableRespected) {
@@ -1306,8 +1341,7 @@
options.SetHlslOffsets(true);
const std::string disassembly_text = AssemblyOutput(
kGlslShaderWeirdPacking, shaderc_glsl_vertex_shader, options);
- EXPECT_THAT(disassembly_text,
- HasSubstr("OpMemberDecorate %B 1 Offset 4"));
+ EXPECT_THAT(disassembly_text, HasSubstr("OpMemberDecorate %B 1 Offset 4"));
}
TEST_F(CppInterface, HlslRegSetBindingForFragmentRespected) {
@@ -1342,4 +1376,31 @@
EXPECT_THAT(disassembly_text, HasSubstr("OpDecorate %t4 Binding 16"));
}
+TEST_F(CppInterface, HlslFunctionality1OffByDefault) {
+ CompileOptions options;
+ options.SetSourceLanguage(shaderc_source_language_hlsl);
+ const std::string disassembly_text = AssemblyOutput(
+ kHlslShaderWithCounterBuffer, shaderc_glsl_fragment_shader, options);
+ EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorateStringGOOGLE")));
+}
+
+TEST_F(CppInterface, HlslFunctionality1Respected) {
+ CompileOptions options;
+ options.SetSourceLanguage(shaderc_source_language_hlsl);
+ options.SetHlslFunctionality1(true);
+ const std::string disassembly_text = AssemblyOutput(
+ kHlslShaderWithCounterBuffer, shaderc_glsl_fragment_shader, options);
+ EXPECT_THAT(disassembly_text, HasSubstr("OpDecorateStringGOOGLE"));
+}
+
+TEST_F(CppInterface, HlslFunctionality1SurvivesCloning) {
+ CompileOptions options;
+ options.SetSourceLanguage(shaderc_source_language_hlsl);
+ options.SetHlslFunctionality1(true);
+ CompileOptions cloned_options(options);
+ const std::string disassembly_text = AssemblyOutput(
+ kHlslShaderWithCounterBuffer, shaderc_glsl_fragment_shader, cloned_options);
+ EXPECT_THAT(disassembly_text, HasSubstr("OpDecorateStringGOOGLE"));
+}
+
} // anonymous namespace
diff --git a/libshaderc/src/shaderc_test.cc b/libshaderc/src/shaderc_test.cc
index 38322b0..762b335 100644
--- a/libshaderc/src/shaderc_test.cc
+++ b/libshaderc/src/shaderc_test.cc
@@ -649,6 +649,16 @@
EXPECT_THAT(disassembly_text, HasSubstr("OpSource"));
}
+TEST_F(CompileStringWithOptionsTest, CompileAndOptimizeWithLevelPerformance) {
+ shaderc_compile_options_set_optimization_level(
+ options_.get(), shaderc_optimization_level_performance);
+ const std::string disassembly_text =
+ CompilationOutput(kGlslMultipleFnShader, shaderc_glsl_fragment_shader,
+ options_.get(), OutputType::SpirvAssemblyText);
+ // Check that we do not have function calls anymore.
+ EXPECT_THAT(disassembly_text, Not(HasSubstr("OpFunctionCall")));
+}
+
TEST_F(CompileStringWithOptionsTest, CompileAndOptimizeWithLevelSize) {
shaderc_compile_options_set_optimization_level(
options_.get(), shaderc_optimization_level_size);
@@ -1076,11 +1086,11 @@
shaderc_glsl_vertex_shader, options_.get()));
}
-TEST_F(CompileStringWithOptionsTest,
- TargetEnvRespectedWhenCompilingOpenGLCompatibilityShaderToBinary) {
- // Confirm that kOpenGLCompatibilityFragmentShader compiles with
- // shaderc_target_env_opengl_compat. When targeting OpenGL core profile
- // or Vulkan, it should fail to compile.
+TEST_F(
+ CompileStringWithOptionsTest,
+ TargetEnvRespectedWhenCompilingOpenGLCompatibilityShaderToBinaryAndAlwaysFails) {
+ // Glslang does not support generating SPIR-V for compatibility profile
+ // shaders.
EXPECT_FALSE(CompilesToValidSpv(compiler_, kOpenGLCompatibilityFragmentShader,
shaderc_glsl_fragment_shader,
@@ -1088,8 +1098,9 @@
shaderc_compile_options_set_target_env(options_.get(),
shaderc_target_env_opengl_compat, 0);
- EXPECT_TRUE(CompilesToValidSpv(compiler_, kOpenGLCompatibilityFragmentShader,
- shaderc_glsl_fragment_shader, options_.get()));
+ EXPECT_FALSE(CompilesToValidSpv(compiler_, kOpenGLCompatibilityFragmentShader,
+ shaderc_glsl_fragment_shader,
+ options_.get()));
shaderc_compile_options_set_target_env(options_.get(),
shaderc_target_env_opengl, 0);
@@ -1118,8 +1129,42 @@
shaderc_target_env_opengl, 0);
EXPECT_TRUE(CompilesToValidSpv(compiler_, kOpenGLVertexShader,
shaderc_glsl_vertex_shader, options_.get()));
+}
- // TODO(dneto): Check what happens when targeting Vulkan.
+TEST_F(CompileStringWithOptionsTest,
+ TargetEnvRespectedWhenCompilingVulkan1_0ShaderToVulkan1_0Succeeds) {
+ shaderc_compile_options_set_target_env(options_.get(),
+ shaderc_target_env_vulkan,
+ shaderc_env_version_vulkan_1_0);
+ EXPECT_TRUE(CompilesToValidSpv(compiler_, kGlslShaderComputeBarrier,
+ shaderc_glsl_compute_shader, options_.get()));
+}
+
+TEST_F(CompileStringWithOptionsTest,
+ TargetEnvRespectedWhenCompilingVulkan1_0ShaderToVulkan1_1Succeeds) {
+ shaderc_compile_options_set_target_env(options_.get(),
+ shaderc_target_env_vulkan,
+ shaderc_env_version_vulkan_1_1);
+ EXPECT_TRUE(CompilesToValidSpv(compiler_, kGlslShaderComputeBarrier,
+ shaderc_glsl_compute_shader, options_.get()));
+}
+
+TEST_F(CompileStringWithOptionsTest,
+ TargetEnvRespectedWhenCompilingVulkan1_1ShaderToVulkan1_0Fails) {
+ shaderc_compile_options_set_target_env(options_.get(),
+ shaderc_target_env_vulkan,
+ shaderc_env_version_vulkan_1_0);
+ EXPECT_FALSE(CompilesToValidSpv(compiler_, kGlslShaderComputeSubgroupBarrier,
+ shaderc_glsl_compute_shader, options_.get()));
+}
+
+TEST_F(CompileStringWithOptionsTest,
+ TargetEnvRespectedWhenCompilingVulkan1_1ShaderToVulkan1_1Succeeds) {
+ shaderc_compile_options_set_target_env(options_.get(),
+ shaderc_target_env_vulkan,
+ shaderc_env_version_vulkan_1_1);
+ EXPECT_TRUE(CompilesToValidSpv(compiler_, kGlslShaderComputeSubgroupBarrier,
+ shaderc_glsl_compute_shader, options_.get()));
}
TEST_F(CompileStringWithOptionsTest,
@@ -1392,10 +1437,10 @@
// offset.
std::string ShaderWithTexOffset(int offset) {
std::ostringstream oss;
- oss <<
- "#version 150\n"
- "uniform sampler1D tex;\n"
- "void main() { vec4 x = textureOffset(tex, 1.0, " << offset << "); }\n";
+ oss << "#version 450\n"
+ "layout (binding=0) uniform sampler1D tex;\n"
+ "void main() { vec4 x = textureOffset(tex, 1.0, "
+ << offset << "); }\n";
return oss.str();
}
@@ -1440,29 +1485,12 @@
options_.get()));
}
-TEST_F(CompileStringWithOptionsTest,
- UniformsWithoutBindingsHaveNoBindingsByDefault) {
- const std::string disassembly_text = CompilationOutput(
- kShaderWithUniformsWithoutBindings, shaderc_glsl_vertex_shader,
- options_.get(), OutputType::SpirvAssemblyText);
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_tex Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_sam Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_img Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_imbuf Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_ubo Binding")));
-}
-
-TEST_F(CompileStringWithOptionsTest,
- UniformsWithoutBindingsOptionSetNoBindingsHaveNoBindings) {
- shaderc_compile_options_set_auto_bind_uniforms(options_.get(), false);
- const std::string disassembly_text = CompilationOutput(
- kShaderWithUniformsWithoutBindings, shaderc_glsl_vertex_shader,
- options_.get(), OutputType::SpirvAssemblyText);
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_tex Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_sam Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_img Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_imbuf Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_ubo Binding")));
+TEST_F(CompileStringWithOptionsTest, UniformsWithoutBindingsFailCompilation) {
+ const std::string errors =
+ CompilationErrors(kShaderWithUniformsWithoutBindings,
+ shaderc_glsl_vertex_shader, options_.get());
+ EXPECT_THAT(errors,
+ HasSubstr("sampler/texture/image requires layout(binding=X)"));
}
TEST_F(CompileStringWithOptionsTest,
@@ -1574,26 +1602,6 @@
EXPECT_THAT(disassembly_text, HasSubstr("OpDecorate %my_ubo Binding 70"));
}
-TEST_F(CompileStringWithOptionsTest, SetBindingBaseIgnoredWhenNotAutoBinding) {
- shaderc_compile_options_set_auto_bind_uniforms(options_.get(), false);
- shaderc_compile_options_set_binding_base(options_.get(),
- shaderc_uniform_kind_texture, 40);
- shaderc_compile_options_set_binding_base(options_.get(),
- shaderc_uniform_kind_sampler, 50);
- shaderc_compile_options_set_binding_base(options_.get(),
- shaderc_uniform_kind_image, 60);
- shaderc_compile_options_set_binding_base(options_.get(),
- shaderc_uniform_kind_buffer, 70);
- const std::string disassembly_text = CompilationOutput(
- kShaderWithUniformsWithoutBindings, shaderc_glsl_vertex_shader,
- options_.get(), OutputType::SpirvAssemblyText);
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_tex Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_sam Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_img Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_imbuf Binding")));
- EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorate %my_ubo Binding")));
-}
-
TEST(Compiler, IncludeWithoutOptionsReturnsValidError) {
auto compiler = shaderc_compiler_initialize();
const char source[] = "#version 450\n#include \"no where\"";
@@ -1619,18 +1627,18 @@
const std::string disassembly_text = CompilationOutput(
kShaderWithUniformsWithoutBindings, shaderc_vertex_shader, options_.get(),
OutputType::SpirvAssemblyText);
- EXPECT_THAT(disassembly_text, HasSubstr("OpDecorate %my_tex Binding 100")) << disassembly_text;
+ EXPECT_THAT(disassembly_text, HasSubstr("OpDecorate %my_tex Binding 100"))
+ << disassembly_text;
EXPECT_THAT(disassembly_text, HasSubstr("OpDecorate %my_sam Binding 0"));
EXPECT_THAT(disassembly_text, HasSubstr("OpDecorate %my_img Binding 1"));
EXPECT_THAT(disassembly_text, HasSubstr("OpDecorate %my_imbuf Binding 2"));
EXPECT_THAT(disassembly_text, HasSubstr("OpDecorate %my_ubo Binding 3"));
}
-TEST_F(
- CompileStringWithOptionsTest,
- SetBindingBaseForTextureForVertexIgnoredWhenCompilingAsFragment) {
+TEST_F(CompileStringWithOptionsTest,
+ SetBindingBaseForTextureForVertexIgnoredWhenCompilingAsFragment) {
shaderc_compile_options_set_auto_bind_uniforms(options_.get(), true);
-// This is ignored since we're compiling as a different stage.
+ // This is ignored since we're compiling as a different stage.
shaderc_compile_options_set_binding_base_for_stage(
options_.get(), shaderc_vertex_shader, shaderc_uniform_kind_texture, 100);
const std::string disassembly_text = CompilationOutput(
@@ -1647,8 +1655,7 @@
const std::string disassembly_text =
CompilationOutput(kGlslShaderWeirdPacking, shaderc_vertex_shader,
options_.get(), OutputType::SpirvAssemblyText);
- EXPECT_THAT(disassembly_text,
- HasSubstr("OpMemberDecorate %B 1 Offset 16"));
+ EXPECT_THAT(disassembly_text, HasSubstr("OpMemberDecorate %B 1 Offset 16"));
}
TEST_F(CompileStringWithOptionsTest, HlslOffsetsOptionDisableRespected) {
@@ -1656,8 +1663,7 @@
const std::string disassembly_text =
CompilationOutput(kGlslShaderWeirdPacking, shaderc_vertex_shader,
options_.get(), OutputType::SpirvAssemblyText);
- EXPECT_THAT(disassembly_text,
- HasSubstr("OpMemberDecorate %B 1 Offset 16"));
+ EXPECT_THAT(disassembly_text, HasSubstr("OpMemberDecorate %B 1 Offset 16"));
}
TEST_F(CompileStringWithOptionsTest, HlslOffsetsOptionEnableRespected) {
@@ -1665,8 +1671,38 @@
const std::string disassembly_text =
CompilationOutput(kGlslShaderWeirdPacking, shaderc_vertex_shader,
options_.get(), OutputType::SpirvAssemblyText);
- EXPECT_THAT(disassembly_text,
- HasSubstr("OpMemberDecorate %B 1 Offset 4"));
+ EXPECT_THAT(disassembly_text, HasSubstr("OpMemberDecorate %B 1 Offset 4"));
+}
+
+TEST_F(CompileStringWithOptionsTest, HlslFunctionality1OffByDefault) {
+ shaderc_compile_options_set_source_language(options_.get(),
+ shaderc_source_language_hlsl);
+ const std::string disassembly_text =
+ CompilationOutput(kHlslShaderWithCounterBuffer, shaderc_fragment_shader,
+ options_.get(), OutputType::SpirvAssemblyText);
+ EXPECT_THAT(disassembly_text, Not(HasSubstr("OpDecorateStringGOOGLE"))) << disassembly_text;
+}
+
+TEST_F(CompileStringWithOptionsTest, HlslFunctionality1Respected) {
+ shaderc_compile_options_set_source_language(options_.get(),
+ shaderc_source_language_hlsl);
+ shaderc_compile_options_set_hlsl_functionality1(options_.get(), true);
+ const std::string disassembly_text =
+ CompilationOutput(kHlslShaderWithCounterBuffer, shaderc_fragment_shader,
+ options_.get(), OutputType::SpirvAssemblyText);
+ EXPECT_THAT(disassembly_text, HasSubstr("OpDecorateStringGOOGLE"));
+}
+
+TEST_F(CompileStringWithOptionsTest, HlslFunctionality1SurvivesCloning) {
+ shaderc_compile_options_set_source_language(options_.get(),
+ shaderc_source_language_hlsl);
+ shaderc_compile_options_set_hlsl_functionality1(options_.get(), true);
+ compile_options_ptr cloned_options(
+ shaderc_compile_options_clone(options_.get()));
+ const std::string disassembly_text =
+ CompilationOutput(kHlslShaderWithCounterBuffer, shaderc_fragment_shader,
+ cloned_options.get(), OutputType::SpirvAssemblyText);
+ EXPECT_THAT(disassembly_text, HasSubstr("OpDecorateStringGOOGLE"));
}
} // anonymous namespace
diff --git a/libshaderc_util/include/libshaderc_util/compiler.h b/libshaderc_util/include/libshaderc_util/compiler.h
index 35c74dc..298344e 100644
--- a/libshaderc_util/include/libshaderc_util/compiler.h
+++ b/libshaderc_util/include/libshaderc_util/compiler.h
@@ -31,6 +31,9 @@
#include "resources.h"
#include "string_piece.h"
+// Fix a typo in glslang/Public/ShaderLang.h
+#define EShTargetClientVersion EshTargetClientVersion
+
namespace shaderc_util {
// To break recursive including. This header is already included in
@@ -103,9 +106,18 @@
// Target environment.
enum class TargetEnv {
- Vulkan,
- OpenGL,
- OpenGLCompat,
+ Vulkan, // Default to Vulkan 1.0
+ OpenGL, // Default to OpenGL 4.5
+ OpenGLCompat, // Deprecated.
+ };
+
+ // Target environment versions. These numbers match those used by Glslang.
+ enum class TargetEnvVersion : uint32_t {
+ // For Vulkan, use numbering scheme from vulkan.h
+ Vulkan_1_0 = ((1 << 22)), // Default to Vulkan 1.0
+ Vulkan_1_1 = ((1 << 22) | (1 << 12)), // Default to Vulkan 1.0
+ // For OpenGL, use the numbering from #version in shaders.
+ OpenGL_4_5 = 450,
};
enum class OutputType {
@@ -116,8 +128,9 @@
// Supported optimization levels.
enum class OptimizationLevel {
- Zero, // No optimization.
- Size, // Optimization towards reducing code size.
+ Zero, // No optimization.
+ Size, // Optimization towards reducing code size.
+ Performance, // Optimization towards better performance.
};
// Resource limits. These map to the "max*" fields in glslang::TBuiltInResource.
@@ -180,13 +193,16 @@
generate_debug_info_(false),
enabled_opt_passes_(),
target_env_(TargetEnv::Vulkan),
+ target_env_version_(0), // Resolve default later.
source_language_(SourceLanguage::GLSL),
limits_(kDefaultTBuiltInResource),
auto_bind_uniforms_(false),
auto_binding_base_(),
+ auto_map_locations_(false),
hlsl_iomap_(false),
hlsl_offsets_(false),
hlsl_legalization_enabled_(true),
+ hlsl_functionality1_enabled_(false),
hlsl_explicit_bindings_() {}
// Requests that the compiler place debug information into the object code,
@@ -200,6 +216,9 @@
// Enables or disables HLSL legalization passes.
void EnableHlslLegalization(bool hlsl_legalization_enabled);
+ // Enables or disables extension SPV_GOOGLE_hlsl_functionality1
+ void EnableHlslFunctionality1(bool enable);
+
// When a warning is encountered it treat it as an error.
void SetWarningsAsErrors();
@@ -213,8 +232,11 @@
void AddMacroDefinition(const char* macro, size_t macro_length,
const char* definition, size_t definition_length);
- // Sets the target environment.
- void SetTargetEnv(TargetEnv env);
+ // Sets the target environment, including version. The version value should
+ // be 0 or one of the values from TargetEnvVersion. The 0 version value maps
+ // to Vulkan 1.0 if the target environment is Vulkan, and it maps to OpenGL
+ // 4.5 if the target environment is OpenGL.
+ void SetTargetEnv(TargetEnv env, uint32_t version = 0);
// Sets the souce language.
void SetSourceLanguage(SourceLanguage lang);
@@ -250,6 +272,10 @@
auto_binding_base_[static_cast<int>(stage)][static_cast<int>(kind)] = base;
}
+ // Sets whether the compiler automatically assigns locations to
+ // uniform variables that don't have explicit locations.
+ void SetAutoMapLocations(bool auto_map) { auto_map_locations_ = auto_map; }
+
// Use HLSL IO mapping rules for bindings. Default is false.
void SetHlslIoMapping(bool hlsl_iomap) { hlsl_iomap_ = hlsl_iomap; }
@@ -424,6 +450,12 @@
// implementation of glslang.
TargetEnv target_env_;
+ // The version number of the target environment. The numbering scheme is
+ // particular to each target environment. If this is 0, then use a default
+ // for that particular target environment. See libshaders/shaderc/shaderc.h
+ // for those defaults.
+ uint32_t target_env_version_;
+
// The source language. Defaults to GLSL.
SourceLanguage source_language_;
@@ -439,6 +471,10 @@
// The default is zero.
uint32_t auto_binding_base_[kNumStages][kNumUniformKinds];
+ // True if the compiler should automatically map uniforms that don't
+ // have explicit locations.
+ bool auto_map_locations_;
+
// True if the compiler should use HLSL IO mapping rules when compiling HLSL.
bool hlsl_iomap_;
@@ -450,6 +486,9 @@
// source language is HLSL.
bool hlsl_legalization_enabled_;
+ // True if the compiler should support extension SPV_GOOGLE_hlsl_functionality1.
+ bool hlsl_functionality1_enabled_;
+
// A sequence of triples, each triple representing a specific HLSL register
// name, and the set and binding numbers it should be mapped to, but in
// the form of strings. This is how Glslang wants to consume the data.
diff --git a/libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h b/libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h
index f5b0315..7350fb1 100644
--- a/libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h
+++ b/libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h
@@ -39,26 +39,14 @@
// The ids of a list of supported optimization passes.
enum class PassId {
+ // SPIRV-Tools standard recipes
+ kLegalizationPasses,
+ kPerformancePasses,
+ kSizePasses,
+
+ // SPIRV-Tools specific passes
kNullPass,
kStripDebugInfo,
- kEliminateDeadFunctions,
- kFlattenDecoration,
- kFreezeSpecConstantValue,
- kFoldSpecConstantOpAndComposite,
- kUnifyConstant,
- kEliminateDeadConstant,
- kStrengthReduction,
- kBlockMerge,
- kInlineExhaustive,
- kInlineOpaque,
- kLocalSingleBlockLoadStoreElim,
- kDeadBranchElim,
- kLocalMultiStoreElim,
- kLocalAccessChainConvert,
- kLocalSingleStoreElim,
- kInsertExtractElim,
- kCommonUniformElim,
- kAggressiveDCE,
kCompactIds,
};
diff --git a/libshaderc_util/src/compiler.cc b/libshaderc_util/src/compiler.cc
index da23549..b045768 100644
--- a/libshaderc_util/src/compiler.cc
+++ b/libshaderc_util/src/compiler.cc
@@ -93,6 +93,53 @@
return result;
}
+// A GlslangClientInfo captures target client version and desired SPIR-V
+// version.
+struct GlslangClientInfo {
+ bool valid_client = false;
+ glslang::EShClient client = glslang::EShClientNone;
+ bool valid_client_version = false;
+ glslang::EShTargetClientVersion client_version;
+ glslang::EShTargetLanguage target_language = glslang::EShTargetSpv;
+ glslang::EShTargetLanguageVersion target_language_version =
+ glslang::EShTargetSpv_1_0;
+};
+
+// Returns the mappings to Glslang client, client version, and SPIR-V version.
+// Also indicates whether the input values were valid.
+GlslangClientInfo GetGlslangClientInfo(shaderc_util::Compiler::TargetEnv env,
+ uint32_t version) {
+ GlslangClientInfo result;
+
+ using shaderc_util::Compiler;
+ switch (env) {
+ case Compiler::TargetEnv::Vulkan:
+ result.valid_client = true;
+ result.client = glslang::EShClientVulkan;
+ if (version == 0 ||
+ version == uint32_t(Compiler::TargetEnvVersion::Vulkan_1_0)) {
+ result.client_version = glslang::EShTargetVulkan_1_0;
+ result.valid_client_version = true;
+ } else if (version == uint32_t(Compiler::TargetEnvVersion::Vulkan_1_1)) {
+ result.client_version = glslang::EShTargetVulkan_1_1;
+ result.valid_client_version = true;
+ result.target_language_version = glslang::EShTargetSpv_1_3;
+ }
+ break;
+ case Compiler::TargetEnv::OpenGLCompat: // TODO(dneto): remove this
+ case Compiler::TargetEnv::OpenGL:
+ result.valid_client = true;
+ result.client = glslang::EShClientOpenGL;
+ if (version == 0 ||
+ version == uint32_t(Compiler::TargetEnvVersion::OpenGL_4_5)) {
+ result.client_version = glslang::EShTargetOpenGL_450;
+ result.valid_client_version = true;
+ }
+ break;
+ }
+ return result;
+}
+
} // anonymous namespace
namespace shaderc_util {
@@ -139,6 +186,25 @@
std::vector<uint32_t>& compilation_output_data = std::get<1>(result_tuple);
size_t& compilation_output_data_size_in_bytes = std::get<2>(result_tuple);
+ // Check target environment.
+ const auto target_client_info =
+ GetGlslangClientInfo(target_env_, target_env_version_);
+ if (!target_client_info.valid_client) {
+ *error_stream << "error:" << error_tag
+ << ": Invalid target client environment " << int(target_env_);
+ *total_warnings = 0;
+ *total_errors = 1;
+ return result_tuple;
+ }
+ if (!target_client_info.valid_client_version) {
+ *error_stream << "error:" << error_tag << ": Invalid target client version "
+ << target_env_version_ << " for environment "
+ << int(target_env_);
+ *total_warnings = 0;
+ *total_errors = 1;
+ return result_tuple;
+ }
+
auto token = initializer->Acquire();
EShLanguage used_shader_stage = forced_shader_stage;
const std::string macro_definitions =
@@ -210,16 +276,26 @@
shader.setPreamble(preamble.c_str());
shader.setEntryPoint(entry_point_name);
shader.setAutoMapBindings(auto_bind_uniforms_);
+ shader.setAutoMapLocations(auto_map_locations_);
const auto& bases = auto_binding_base_[static_cast<int>(used_shader_stage)];
shader.setShiftImageBinding(bases[static_cast<int>(UniformKind::Image)]);
shader.setShiftSamplerBinding(bases[static_cast<int>(UniformKind::Sampler)]);
shader.setShiftTextureBinding(bases[static_cast<int>(UniformKind::Texture)]);
shader.setShiftUboBinding(bases[static_cast<int>(UniformKind::Buffer)]);
- shader.setShiftSsboBinding(bases[static_cast<int>(UniformKind::StorageBuffer)]);
- shader.setShiftUavBinding(bases[static_cast<int>(UniformKind::UnorderedAccessView)]);
+ shader.setShiftSsboBinding(
+ bases[static_cast<int>(UniformKind::StorageBuffer)]);
+ shader.setShiftUavBinding(
+ bases[static_cast<int>(UniformKind::UnorderedAccessView)]);
shader.setHlslIoMapping(hlsl_iomap_);
shader.setResourceSetBinding(
hlsl_explicit_bindings_[static_cast<int>(used_shader_stage)]);
+ shader.setEnvClient(target_client_info.client,
+ target_client_info.client_version);
+ shader.setEnvTarget(target_client_info.target_language,
+ target_client_info.target_language_version);
+ if (hlsl_functionality1_enabled_) {
+ shader.setEnvTargetHlslFunctionality1();
+ }
// TODO(dneto): Generate source-level debug info if requested.
bool success = shader.parse(
@@ -249,12 +325,12 @@
options.optimizeSize = false;
// Note the call to GlslangToSpv also populates compilation_output_data.
glslang::GlslangToSpv(*program.getIntermediate(used_shader_stage), spirv,
- &options);
+ &options);
// Set the tool field (the top 16-bits) in the generator word to
// 'Shaderc over Glslang'.
- const uint32_t shaderc_generator_word = 13; // From SPIR-V XML Registry
- const uint32_t generator_word_index = 2; // SPIR-V 2.3: Physical layout
+ const uint32_t shaderc_generator_word = 13; // From SPIR-V XML Registry
+ const uint32_t generator_word_index = 2; // SPIR-V 2.3: Physical layout
assert(spirv.size() > generator_word_index);
spirv[generator_word_index] =
(spirv[generator_word_index] & 0xffff) | (shaderc_generator_word << 16);
@@ -264,27 +340,11 @@
if (hlsl_legalization_enabled_ && source_language_ == SourceLanguage::HLSL) {
// If from HLSL, run this passes to "legalize" the SPIR-V for Vulkan
// eg. forward and remove memory writes of opaque types.
- opt_passes.push_back(PassId::kInlineExhaustive);
- opt_passes.push_back(PassId::kLocalAccessChainConvert);
- opt_passes.push_back(PassId::kLocalSingleBlockLoadStoreElim);
- opt_passes.push_back(PassId::kLocalSingleStoreElim);
- opt_passes.push_back(PassId::kInsertExtractElim);
- opt_passes.push_back(PassId::kAggressiveDCE);
- opt_passes.push_back(PassId::kDeadBranchElim);
- opt_passes.push_back(PassId::kBlockMerge);
- opt_passes.push_back(PassId::kLocalMultiStoreElim);
- opt_passes.push_back(PassId::kInsertExtractElim);
- opt_passes.push_back(PassId::kAggressiveDCE);
- opt_passes.push_back(PassId::kEliminateDeadConstant);
- opt_passes.push_back(PassId::kEliminateDeadFunctions);
-
- // TODO(atgoo, dneto0, greg-lunarg):
- // Add PassId::kCommonUniformElim when AMD driver issues are resolved.
- // Add dead var/type elimination passes when available.
+ opt_passes.push_back(PassId::kLegalizationPasses);
}
- opt_passes.insert(
- opt_passes.end(), enabled_opt_passes_.begin(), enabled_opt_passes_.end());
+ opt_passes.insert(opt_passes.end(), enabled_opt_passes_.begin(),
+ enabled_opt_passes_.end());
if (!opt_passes.empty()) {
std::string opt_errors;
@@ -323,7 +383,10 @@
definition ? std::string(definition, definition_length) : "";
}
-void Compiler::SetTargetEnv(Compiler::TargetEnv env) { target_env_ = env; }
+void Compiler::SetTargetEnv(Compiler::TargetEnv env, uint32_t version) {
+ target_env_ = env;
+ target_env_version_ = version;
+}
void Compiler::SetSourceLanguage(Compiler::SourceLanguage lang) {
source_language_ = lang;
@@ -355,7 +418,13 @@
if (!generate_debug_info_) {
enabled_opt_passes_.push_back(PassId::kStripDebugInfo);
}
- enabled_opt_passes_.push_back(PassId::kUnifyConstant);
+ enabled_opt_passes_.push_back(PassId::kSizePasses);
+ break;
+ case OptimizationLevel::Performance:
+ if (!generate_debug_info_) {
+ enabled_opt_passes_.push_back(PassId::kStripDebugInfo);
+ }
+ enabled_opt_passes_.push_back(PassId::kPerformancePasses);
break;
default:
break;
@@ -366,6 +435,10 @@
hlsl_legalization_enabled_ = hlsl_legalization_enabled;
}
+void Compiler::EnableHlslFunctionality1(bool enable) {
+ hlsl_functionality1_enabled_ = enable;
+}
+
void Compiler::SetSuppressWarnings() { suppress_warnings_ = true; }
std::tuple<bool, std::string, std::string> Compiler::PreprocessShader(
@@ -379,6 +452,25 @@
shader.setStringsWithLengthsAndNames(&shader_strings, &shader_lengths,
&string_names, 1);
shader.setPreamble(shader_preamble.data());
+ auto target_client_info =
+ GetGlslangClientInfo(target_env_, target_env_version_);
+ if (!target_client_info.valid_client) {
+ std::ostringstream os;
+ os << "error:" << error_tag << ": Invalid target client "
+ << int(target_env_);
+ return std::make_tuple(false, "", os.str());
+ }
+ if (!target_client_info.valid_client_version) {
+ std::ostringstream os;
+ os << "error:" << error_tag << ": Invalid target client "
+ << int(target_env_version_) << " for environmnent " << int(target_env_);
+ return std::make_tuple(false, "", os.str());
+ }
+ shader.setEnvClient(target_client_info.client,
+ target_client_info.client_version);
+ if (hlsl_functionality1_enabled_) {
+ shader.setEnvTargetHlslFunctionality1();
+ }
// The preprocessor might be sensitive to the target environment.
// So combine the existing rules with the just-give-me-preprocessor-output
@@ -603,4 +695,4 @@
return result_vec;
}
-} // namesapce shaderc_util
+} // namespace shaderc_util
diff --git a/libshaderc_util/src/compiler_test.cc b/libshaderc_util/src/compiler_test.cc
index fa447d1..9ffa3db 100644
--- a/libshaderc_util/src/compiler_test.cc
+++ b/libshaderc_util/src/compiler_test.cc
@@ -34,8 +34,9 @@
"#version 140\n"
"void main() {}";
-// A shader that compiles under OpenGL compatibility profile rules,
-// but not OpenGL core profile rules.
+// A shader that parses under OpenGL compatibility profile rules.
+// It does not compile because Glslang does not support SPIR-V
+// code generation for OpenGL compatibility profile.
const char kOpenGLCompatibilityFragShader[] =
R"(#version 140
uniform highp sampler2D tex;
@@ -43,16 +44,6 @@
gl_FragColor = texture2D(tex, vec2(0.0,0.0));
})";
-// A shader that compiles under OpenGL compatibility profile rules,
-// but not OpenGL core profile rules, even when deducing the stage.
-const char kOpenGLCompatibilityFragShaderDeducibleStage[] =
- R"(#version 140
- #pragma shader_stage(fragment)
- uniform highp sampler2D tex;
- void main() {
- gl_FragColor = texture2D(tex, vec2(0.0,0.0));
- })";
-
// A shader that compiles under OpenGL core profile rules.
const char kOpenGLVertexShader[] =
R"(#version 330
@@ -104,6 +95,26 @@
float x = my_ubo.x;
})";
+// A GLSL vertex shader with the location defined for its non-opaque uniform
+// variable.
+const char kGlslVertShaderExplicitLocation[] =
+ R"(#version 450
+ layout(location = 10) uniform mat4 my_mat;
+ layout(location = 0) in vec4 my_vec;
+ void main(void) {
+ gl_Position = my_mat * my_vec;
+ })";
+
+// A GLSL vertex shader without the location defined for its non-opaque uniform
+// variable.
+const char kGlslVertShaderNoExplicitLocation[] =
+ R"(#version 450
+ uniform mat4 my_mat;
+ layout(location = 0) in vec4 my_vec;
+ void main(void) {
+ gl_Position = my_mat * my_vec;
+ })";
+
// A GLSL vertex shader with a weirdly packed block.
const char kGlslShaderWeirdPacking[] =
R"(#version 450
@@ -131,6 +142,14 @@
return sampleTexture(cts, loc);
})";
+const char kHlslShaderWithCounterBuffer[] = R"(
+RWStructuredBuffer<float4> Ainc;
+float4 main() : SV_Target0 {
+ return float4(Ainc.IncrementCounter(), 0, 0, 0);
+}
+)";
+
+
// Returns the disassembly of the given SPIR-V binary, as a string.
// Assumes the disassembly will be successful when targeting Vulkan.
std::string Disassemble(const std::vector<uint32_t> binary) {
@@ -235,46 +254,6 @@
EXPECT_TRUE(SimpleCompilationSucceeds(kVulkanVertexShader, EShLangVertex));
}
-TEST_F(CompilerTest, RespectTargetEnvOnOpenGLCompatibilityShader) {
- const EShLanguage stage = EShLangFragment;
-
- compiler_.SetTargetEnv(Compiler::TargetEnv::OpenGLCompat);
- EXPECT_TRUE(SimpleCompilationSucceeds(kOpenGLCompatibilityFragShader, stage));
- compiler_.SetTargetEnv(Compiler::TargetEnv::OpenGL);
- EXPECT_FALSE(
- SimpleCompilationSucceeds(kOpenGLCompatibilityFragShader, stage));
- compiler_.SetTargetEnv(Compiler::TargetEnv::Vulkan);
- EXPECT_FALSE(
- SimpleCompilationSucceeds(kOpenGLCompatibilityFragShader, stage));
- // Default compiler.
- compiler_ = Compiler();
- EXPECT_FALSE(
- SimpleCompilationSucceeds(kOpenGLCompatibilityFragShader, stage));
-}
-
-TEST_F(CompilerTest,
- RespectTargetEnvOnOpenGLCompatibilityShaderWhenDeducingStage) {
- const EShLanguage stage = EShLangCount;
-
- compiler_.SetTargetEnv(Compiler::TargetEnv::OpenGLCompat);
- EXPECT_TRUE(SimpleCompilationSucceeds(
- kOpenGLCompatibilityFragShaderDeducibleStage, stage))
- << errors_;
- compiler_.SetTargetEnv(Compiler::TargetEnv::OpenGL);
- EXPECT_FALSE(SimpleCompilationSucceeds(
- kOpenGLCompatibilityFragShaderDeducibleStage, stage))
- << errors_;
- compiler_.SetTargetEnv(Compiler::TargetEnv::Vulkan);
- EXPECT_FALSE(SimpleCompilationSucceeds(
- kOpenGLCompatibilityFragShaderDeducibleStage, stage))
- << errors_;
- // Default compiler.
- compiler_ = Compiler();
- EXPECT_FALSE(SimpleCompilationSucceeds(
- kOpenGLCompatibilityFragShaderDeducibleStage, stage))
- << errors_;
-}
-
TEST_F(CompilerTest, RespectTargetEnvOnOpenGLShader) {
const EShLanguage stage = EShLangVertex;
@@ -312,15 +291,16 @@
EXPECT_FALSE(SimpleCompilationSucceeds(kVulkanVertexShader, EShLangVertex));
}
-TEST_F(CompilerTest, OpenGLCompatibilitySpecificShaderFailsUnderDefaultRules) {
- EXPECT_FALSE(SimpleCompilationSucceeds(kOpenGLCompatibilityFragShader,
- EShLangFragment));
-}
-
TEST_F(CompilerTest, OpenGLSpecificShaderFailsUnderDefaultRules) {
EXPECT_FALSE(SimpleCompilationSucceeds(kOpenGLVertexShader, EShLangVertex));
}
+TEST_F(CompilerTest, OpenGLCompatibilitySpecificShaderFailsUnderOpenGLRules) {
+ compiler_.SetTargetEnv(Compiler::TargetEnv::OpenGL);
+ EXPECT_FALSE(SimpleCompilationSucceeds(kOpenGLCompatibilityFragShader,
+ EShLangFragment));
+}
+
TEST_F(CompilerTest, OpenGLCompatibilitySpecificShaderFailsUnderVulkanRules) {
compiler_.SetTargetEnv(Compiler::TargetEnv::Vulkan);
EXPECT_FALSE(SimpleCompilationSucceeds(kOpenGLCompatibilityFragShader,
@@ -332,6 +312,19 @@
EXPECT_FALSE(SimpleCompilationSucceeds(kOpenGLVertexShader, EShLangVertex));
}
+TEST_F(CompilerTest, BadTargetEnvFails) {
+ compiler_.SetTargetEnv(static_cast<Compiler::TargetEnv>(32767));
+ EXPECT_FALSE(SimpleCompilationSucceeds(kVulkanVertexShader, EShLangVertex));
+ EXPECT_THAT(errors_, HasSubstr("Invalid target client environment 32767"));
+}
+
+TEST_F(CompilerTest, BadTargetEnvVersionFails) {
+ compiler_.SetTargetEnv(Compiler::TargetEnv::Vulkan, 123);
+ EXPECT_FALSE(SimpleCompilationSucceeds(kVulkanVertexShader, EShLangVertex));
+ EXPECT_THAT(errors_,
+ HasSubstr("Invalid target client version 123 for environment 0"));
+}
+
TEST_F(CompilerTest, AddMacroDefinition) {
const std::string kMinimalExpandedShader = "#version 140\nvoid E(){}";
compiler_.AddMacroDefinition("E", 1u, "main", 4u);
@@ -472,8 +465,8 @@
// offset.
std::string ShaderWithTexOffset(int offset) {
std::ostringstream oss;
- oss << "#version 150\n"
- "uniform sampler1D tex;\n"
+ oss << "#version 450\n"
+ "layout (binding=0) uniform sampler1D tex;\n"
"void main() { vec4 x = textureOffset(tex, 1.0, "
<< offset << "); }\n";
return oss.str();
@@ -511,28 +504,12 @@
EXPECT_EQ(shaderc_over_glslang, words[generator_word_index] >> 16u);
}
-TEST_F(CompilerTest, DefaultsDoNotSetBindings) {
- const auto words = SimpleCompilationBinary(kGlslFragShaderNoExplicitBinding,
- EShLangFragment);
- const auto disassembly = Disassemble(words);
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_tex Binding")));
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_sam Binding")));
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_img Binding")));
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_imbuf Binding")));
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_ubo Binding")));
-}
-
-TEST_F(CompilerTest, NoAutoMapBindingsDoesNotSetBindings) {
+TEST_F(CompilerTest, NoBindingsAndNoAutoMapBindingsFailsCompile) {
compiler_.SetAutoBindUniforms(false);
- const auto words = SimpleCompilationBinary(kGlslFragShaderNoExplicitBinding,
- EShLangFragment);
- const auto disassembly = Disassemble(words);
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_tex Binding")))
- << disassembly;
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_sam Binding")));
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_img Binding")));
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_imbuf Binding")));
- EXPECT_THAT(disassembly, Not(HasSubstr("OpDecorate %my_ubo Binding")));
+ EXPECT_FALSE(SimpleCompilationSucceeds(kGlslFragShaderNoExplicitBinding,
+ EShLangFragment));
+ EXPECT_THAT(errors_,
+ HasSubstr("sampler/texture/image requires layout(binding=X)"));
}
TEST_F(CompilerTest, AutoMapBindingsSetsBindings) {
@@ -636,6 +613,37 @@
EXPECT_THAT(disassembly, HasSubstr("OpDecorate %my_ubo Binding 4"));
}
+TEST_F(CompilerTest, NoAutoMapLocationsFailsCompilationOnOpenGLShader) {
+ compiler_.SetTargetEnv(Compiler::TargetEnv::OpenGL);
+ compiler_.SetAutoMapLocations(false);
+
+ const auto words = SimpleCompilationBinary(kGlslVertShaderExplicitLocation,
+ EShLangVertex);
+ const auto disassembly = Disassemble(words);
+ EXPECT_THAT(disassembly, HasSubstr("OpDecorate %my_mat Location 10"))
+ << disassembly;
+
+ EXPECT_FALSE(
+ SimpleCompilationSucceeds(kGlslVertShaderNoExplicitLocation, EShLangVertex));
+}
+
+TEST_F(CompilerTest, AutoMapLocationsSetsLocationsOnOpenGLShader) {
+ compiler_.SetTargetEnv(Compiler::TargetEnv::OpenGL);
+ compiler_.SetAutoMapLocations(true);
+
+ const auto words_no_auto =
+ SimpleCompilationBinary(kGlslVertShaderExplicitLocation, EShLangVertex);
+ const auto disassembly_no_auto = Disassemble(words_no_auto);
+ EXPECT_THAT(disassembly_no_auto, HasSubstr("OpDecorate %my_mat Location 10"))
+ << disassembly_no_auto;
+
+ const auto words_auto =
+ SimpleCompilationBinary(kGlslVertShaderNoExplicitLocation, EShLangVertex);
+ const auto disassembly_auto = Disassemble(words_auto);
+ EXPECT_THAT(disassembly_auto, HasSubstr("OpDecorate %my_mat Location 0"))
+ << disassembly_auto;
+}
+
TEST_F(CompilerTest, EmitMessageTextOnlyOnce) {
// Emit a warning by compiling a shader without a default entry point name.
// The warning should only be emitted once even though we do parsing, linking,
@@ -711,4 +719,19 @@
EXPECT_THAT(disassembly, HasSubstr("OpFunctionCall")) << disassembly;
}
+TEST_F(CompilerTest, HlslFunctionality1Enabled) {
+ compiler_.SetSourceLanguage(Compiler::SourceLanguage::HLSL);
+ compiler_.EnableHlslFunctionality1(true);
+ const auto words =
+ SimpleCompilationBinary(kHlslShaderWithCounterBuffer, EShLangFragment);
+ const auto disassembly = Disassemble(words);
+ EXPECT_THAT(disassembly,
+ HasSubstr("OpExtension \"SPV_GOOGLE_hlsl_functionality1\""))
+ << disassembly;
+ EXPECT_THAT(disassembly,
+ HasSubstr("OpDecorateStringGOOGLE %_entryPointOutput "
+ "HlslSemanticGOOGLE \"SV_TARGET0\""))
+ << disassembly;
+}
+
} // anonymous namespace
diff --git a/libshaderc_util/src/spirv_tools_wrapper.cc b/libshaderc_util/src/spirv_tools_wrapper.cc
index 87dbfca..0d6b910 100644
--- a/libshaderc_util/src/spirv_tools_wrapper.cc
+++ b/libshaderc_util/src/spirv_tools_wrapper.cc
@@ -43,12 +43,15 @@
std::string* text_or_error) {
spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_0);
std::ostringstream oss;
- tools.SetMessageConsumer([&oss](
- spv_message_level_t, const char*, const spv_position_t& position,
- const char* message) { oss << position.index << ": " << message; });
- const bool success = tools.Disassemble(
- binary, text_or_error, SPV_BINARY_TO_TEXT_OPTION_INDENT |
- SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES);
+ tools.SetMessageConsumer([&oss](spv_message_level_t, const char*,
+ const spv_position_t& position,
+ const char* message) {
+ oss << position.index << ": " << message;
+ });
+ const bool success =
+ tools.Disassemble(binary, text_or_error,
+ SPV_BINARY_TO_TEXT_OPTION_INDENT |
+ SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES);
if (!success) {
*text_or_error = oss.str();
}
@@ -99,66 +102,21 @@
for (const auto& pass : enabled_passes) {
switch (pass) {
+ case PassId::kLegalizationPasses:
+ optimizer.RegisterLegalizationPasses();
+ break;
+ case PassId::kPerformancePasses:
+ optimizer.RegisterPerformancePasses();
+ break;
+ case PassId::kSizePasses:
+ optimizer.RegisterSizePasses();
+ break;
case PassId::kNullPass:
// We actually don't need to do anything for null pass.
break;
case PassId::kStripDebugInfo:
optimizer.RegisterPass(spvtools::CreateStripDebugInfoPass());
break;
- case PassId::kEliminateDeadFunctions:
- optimizer.RegisterPass(spvtools::CreateEliminateDeadFunctionsPass());
- break;
- case PassId::kFlattenDecoration:
- optimizer.RegisterPass(spvtools::CreateFlattenDecorationPass());
- break;
- case PassId::kFreezeSpecConstantValue:
- optimizer.RegisterPass(spvtools::CreateFreezeSpecConstantValuePass());
- break;
- case PassId::kFoldSpecConstantOpAndComposite:
- optimizer.RegisterPass(spvtools::CreateFoldSpecConstantOpAndCompositePass());
- break;
- case PassId::kUnifyConstant:
- optimizer.RegisterPass(spvtools::CreateUnifyConstantPass());
- break;
- case PassId::kEliminateDeadConstant:
- optimizer.RegisterPass(spvtools::CreateEliminateDeadConstantPass());
- break;
- case PassId::kStrengthReduction:
- optimizer.RegisterPass(spvtools::CreateStrengthReductionPass());
- break;
- case PassId::kBlockMerge:
- optimizer.RegisterPass(spvtools::CreateBlockMergePass());
- break;
- case PassId::kInlineExhaustive:
- optimizer.RegisterPass(spvtools::CreateInlineExhaustivePass());
- break;
- case PassId::kInlineOpaque:
- optimizer.RegisterPass(spvtools::CreateInlineOpaquePass());
- break;
- case PassId::kLocalSingleBlockLoadStoreElim:
- optimizer.RegisterPass(spvtools::CreateLocalSingleBlockLoadStoreElimPass());
- break;
- case PassId::kDeadBranchElim:
- optimizer.RegisterPass(spvtools::CreateDeadBranchElimPass());
- break;
- case PassId::kLocalMultiStoreElim:
- optimizer.RegisterPass(spvtools::CreateLocalMultiStoreElimPass());
- break;
- case PassId::kLocalAccessChainConvert:
- optimizer.RegisterPass(spvtools::CreateLocalAccessChainConvertPass());
- break;
- case PassId::kLocalSingleStoreElim:
- optimizer.RegisterPass(spvtools::CreateLocalSingleStoreElimPass());
- break;
- case PassId::kInsertExtractElim:
- optimizer.RegisterPass(spvtools::CreateInsertExtractElimPass());
- break;
- case PassId::kCommonUniformElim:
- optimizer.RegisterPass(spvtools::CreateCommonUniformElimPass());
- break;
- case PassId::kAggressiveDCE:
- optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
- break;
case PassId::kCompactIds:
optimizer.RegisterPass(spvtools::CreateCompactIdsPass());
break;
diff --git a/third_party/Android.mk b/third_party/Android.mk
index 0ce3dba..9e67eb0 100644
--- a/third_party/Android.mk
+++ b/third_party/Android.mk
@@ -71,6 +71,7 @@
LOCAL_SRC_FILES:= \
glslang/GenericCodeGen/CodeGen.cpp \
glslang/GenericCodeGen/Link.cpp \
+ glslang/MachineIndependent/attribute.cpp \
glslang/MachineIndependent/Constant.cpp \
glslang/MachineIndependent/glslang_tab.cpp \
glslang/MachineIndependent/InfoSink.cpp \
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index d00b14a..373d5b4 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -32,18 +32,6 @@
add_subdirectory(${SHADERC_SPIRV_HEADERS_DIR} spirv-headers)
endif()
-# Check SPIRV-Tools before glslang since it is a dependency of glslang.
-if (IS_DIRECTORY ${SHADERC_SPIRV_TOOLS_DIR})
- if ("${SHADERC_SKIP_TESTS}")
- # Also skip building tests in SPIRV-Tools.
- set(SPIRV_SKIP_TESTS ON CACHE BOOL "Skip building SPIRV-Tools tests")
- endif()
- add_subdirectory(${SHADERC_SPIRV_TOOLS_DIR} spirv-tools)
-endif()
-if (NOT TARGET SPIRV-Tools)
- message(FATAL_ERROR "SPIRV-Tools was not found - required for compilation")
-endif()
-
if (IS_DIRECTORY ${SHADERC_GLSLANG_DIR})
add_subdirectory(${SHADERC_GLSLANG_DIR} glslang)
endif()
@@ -58,6 +46,19 @@
"Platform Toolset" FORCE)
endif()
+# Check SPIRV-Tools after glslang so that it is not linked into glslang and
+# we can control optimizations.
+if (IS_DIRECTORY ${SHADERC_SPIRV_TOOLS_DIR})
+ if ("${SHADERC_SKIP_TESTS}")
+ # Also skip building tests in SPIRV-Tools.
+ set(SPIRV_SKIP_TESTS ON CACHE BOOL "Skip building SPIRV-Tools tests")
+ endif()
+ add_subdirectory(${SHADERC_SPIRV_TOOLS_DIR} spirv-tools)
+endif()
+if (NOT TARGET SPIRV-Tools)
+ message(FATAL_ERROR "SPIRV-Tools was not found - required for compilation")
+endif()
+
if(${SHADERC_ENABLE_TESTS})
# Configure out-of-source-directory tests for glslang.
# The glslang project uses a bash script called "runtests" to run tests.
@@ -82,16 +83,23 @@
${GLSLANG_TEST_SRC_DIR} ${GLSLANG_TEST_BIN_DIR} ${GLSLANG_CONFIGURATION_DIR}
COMMENT "Copying and patching glslang tests if needed")
+ # glslang-testsuite runs a bash script on Windows.
+ # Make sure to use '-o igncr' flag to ignore carriage returns (\r).
+ set(IGNORE_CR_FLAG "")
+ if(WIN32)
+ set(IGNORE_CR_FLAG -o igncr)
+ endif()
+
if (CMAKE_CONFIGURATION_TYPES)
# If we are running a multi-configuration project,
# the tests will be in ${Configuration}/Test
add_test(NAME glslang-testsuite
- COMMAND bash runtests
+ COMMAND bash ${IGNORE_CR_FLAG} runtests
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/Test
)
else()
add_test(NAME glslang-testsuite
- COMMAND bash runtests
+ COMMAND bash ${IGNORE_CR_FLAG} runtests
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Test/
)
endif()
diff --git a/utils/add_copyright.py b/utils/add_copyright.py
index 2d3f734..ab5104b 100755
--- a/utils/add_copyright.py
+++ b/utils/add_copyright.py
@@ -63,7 +63,8 @@
def filtered_descendants(glob):
"""Returns glob-matching filenames under the current directory, but skips
some irrelevant paths."""
- return find('.', glob, ['third_party', 'ext', 'build*', 'out*'])
+ return find('.', glob, ['third_party', 'external', 'build*', 'out*',
+ 'CompilerIdCXX'])
def skip(line):